3 #include <TAlgorithmResult.hxx>
4 #include <TG4PrimaryVertex.hxx>
5 #include <TGeomInfo.hxx>
6 #include <TGeometryId.hxx>
8 #include <THitSelection.hxx>
9 #include <TND280Event.hxx>
10 #include <TND280Log.hxx>
11 #include <TSFGGeom.hxx>
12 #include <TReconNode.hxx>
13 #include <TReconCluster.hxx>
14 #include <TReconShower.hxx>
15 #include <TReconTrack.hxx>
16 #include <TReconVertex.hxx>
17 #include <TReconPID.hxx>
18 #include <TReconState.hxx>
19 #include <TShowerState.hxx>
20 #include <TTrackState.hxx>
21 #include <TVertexState.hxx>
22 #include <TPIDState.hxx>
23 #include "TEventFolder.hxx"
24 #include <TrackTruthInfo.hxx>
26 #if (oaEvent_MAJOR_VERSION>8)
27 #include "TReconStateUtilities.hxx"
28 #include "TShowerState.hxx"
29 #include "TPIDState.hxx"
30 using ND::TReconStateUtilities::GetPosition;
31 using ND::TReconStateUtilities::GetPositionVariance;
32 using ND::TReconStateUtilities::GetPositionIndex;
35 #include <TG4VHit.hxx>
36 #include <TG4HitSegment.hxx>
37 #include <retrieveHitTruthInfo.hxx>
38 #include <TG4Trajectory.hxx>
83 fAlgoResults =
new TClonesArray(
"ND::TSFGReconModule::TSFGAlgoRes");
84 fVertices =
new TClonesArray(
"ND::TSFGReconModule::TSFGVertex");
85 fParticles =
new TClonesArray(
"ND::TSFGReconModule::TSFGParticle");
86 fTracks =
new TClonesArray(
"ND::TSFGReconModule::TSFGTrack");
87 fShowers =
new TClonesArray(
"ND::TSFGReconModule::TSFGShower");
88 fClusters =
new TClonesArray(
"ND::TSFGReconModule::TSFGCluster");
89 fNodes =
new TClonesArray(
"ND::TSFGReconModule::TSFGNode");
90 fHits =
new TClonesArray(
"ND::TSFGReconModule::TSFGHit");
91 fTrueHits =
new TClonesArray(
"ND::TSFGReconModule::TSFGHit");
92 fFibers =
new TClonesArray(
"ND::TSFGReconModule::TSFGHit");
105 branch ->SetTitle(
"The number of Algorithm Results ");
109 branch ->SetTitle(
"The TSFGAlgoRes vector of Algorithm Results");
113 branch->SetTitle(
" The number of added vertices");
117 branch->SetTitle(
" The vector of vertices");
121 branch->SetTitle(
" The number of particles ");
125 branch->SetTitle(
"The vector of particles");
129 branch->SetTitle(
" The number of tracks");
133 branch->SetTitle(
" The vector of tracks");
137 branch->SetTitle(
" The number of showers");
141 branch->SetTitle(
"The vector of showers");
145 branch ->SetTitle(
"The number of clusters ");
149 branch->SetTitle(
"The vector of clusters");
153 branch->SetTitle(
" The number of track nodes");
157 branch->SetTitle(
"The vector of nodes");
161 branch->SetTitle(
"The number of hits that are saved ");
165 branch->SetTitle(
"The vector of reconstructed hits");
169 branch->SetTitle(
"The number of fiber hits");
173 branch->SetTitle(
"The vector of fiber hits");
177 branch->SetTitle(
"The energy deposition from the simulation");
181 branch->SetTitle(
"The vector of true hits");
210 ND::THandle<ND::THitSelection> sfgFibers(event.GetHitSelection(
"sfg"));
212 for (ND::THitSelection::iterator h = sfgFibers->begin();
213 h != sfgFibers->end(); ++h) {
218 ND280Info(
"Missing fiber hits");
221 ND::THandle<ND::THitSelection> sfgTruth(event.GetHitSelection(
"sfg_truth"));
223 for (ND::THitSelection::iterator h = sfgTruth->begin();
224 h != sfgTruth->end(); ++h) {
229 ND280Info(
"Missing truth hits");
233 fTrueTraj =
event.Get<ND::TG4TrajectoryContainer>(
"truth/G4Trajectories");
235 ND280Log(
"Missing truth trajectories");
239 ND::THandle<ND::TAlgorithmResult> sfgRecon =
event.GetFit(
"TSFGRecon");
241 sfgRecon =
event.GetFit(
"sfgRecon");
243 ND280Info(
"No sfgRecon in Event");
258 ND::THandle<ND::TReconBase> baseObject,
261 basePtr->AlgorithmName = baseObject->GetAlgorithmName();
264 ND::THandle<ND::THitSelection> baseHits = baseObject->GetHits();
267 basePtr->NHits = (int)baseHits->size();
270 for (ND::THitSelection::const_iterator hit = baseHits->begin();
271 hit != baseHits->end(); ++hit) {
273 if (hitId < 0)
continue;
274 basePtr->Hits.push_back(hitId);
283 basePtr->UniqueId = baseObject->GetUniqueID();
286 ND::THandle<ND::TReconObjectContainer> objCont =
287 baseObject->GetConstituents();
289 ND::TReconObjectContainer::const_iterator constituent;
290 for (constituent = objCont->begin();
291 constituent != objCont->end();
296 basePtr->Vertices.push_back(conId.
id);
299 basePtr->Particles.push_back(conId.
id);
302 basePtr->Tracks.push_back(conId.
id);
305 basePtr->Showers.push_back(conId.
id);
308 basePtr->Clusters.push_back(conId.
id);
315 const ND::TReconNodeContainer& nodeCont = baseObject->GetNodes();
316 ND::TReconNodeContainer::const_iterator node;
317 for (node = nodeCont.begin();
318 node != nodeCont.end();
321 int nodeId =
FillNode(*node, saveHits);
322 basePtr->Nodes.push_back(nodeId);
329 const ND::THandle<ND::TAlgorithmResult> algoRes,
332 TString fullName = algoRes->GetFullName();
333 TString baseName = fullName;
334 baseName.Remove(0,baseName.Last(
'/') + 1);
343 if (cut->MatchB(fullName,
"", 0, 1)) {
344 ND280Verbose(
"Rejecting: " << baseName
345 <<
" (" << cut->GetPattern() <<
")");
350 ND280Verbose(
"Fill Algorithm Result: " << baseName);
358 sfgAlgoResult->
Parent = parent;
363 ND::THandle<ND::TReconObjectContainer>
final
364 = algoRes->GetResultsContainer(
"final");
366 ND::TReconObjectContainer::const_iterator reconObject;
367 for (reconObject = final->begin();
368 reconObject !=
final->end(); ++reconObject) {
377 sfgAlgoResult->
Tracks.push_back(objId.
id);
380 sfgAlgoResult->
Showers.push_back(objId.
id);
391 ND::THandle<ND::THitSelection> usedHits = algoRes->GetHitSelection(
"used");
392 if (usedHits && (!usedHits->empty())) {
393 ND::THitSelection::const_iterator hit;
395 for (hit = usedHits->begin();
396 hit != usedHits->end(); ++hit) {
398 if (hitId < 0)
continue;
399 sfgAlgoResult->
Hits.push_back(hitId);
401 ND::THandle<ND::TReconCluster> usedCluster(
new ND::TReconCluster);
402 usedCluster->FillFromHits((baseName+
"Used").Data(), *usedHits);
414 ND::THandle<ND::THitSelection> unusedHits
415 = algoRes->GetHitSelection(
"unused");
416 if (unusedHits && (!unusedHits->empty())) {
417 ND::THandle<ND::TReconCluster> unusedCluster(
new ND::TReconCluster);
418 unusedCluster->FillFromHits((baseName+
"Unused").Data(), *unusedHits);
430 for (TDataVector::reverse_iterator d = algoRes->rbegin();
431 d != algoRes->rend(); ++d) {
434 std::string class_name = (*d)->ClassName();
435 if (class_name.find(
"ND::TAlgorithmResult")
436 == std::string::npos)
continue;
438 ND::THandle<ND::TAlgorithmResult>
439 subResult = (*d)->Get<ND::TAlgorithmResult>(
".");
440 if (!subResult)
continue;
444 if (daughterId < 0)
continue;
454 const ND::THandle<ND::TReconBase> reconObject,
455 bool saveHits =
true) {
457 std::string reco_class_name = reconObject->ClassName();
459 if (reco_class_name.find(
"ND::TReconVertex") != std::string::npos) {
462 else if (reco_class_name.find(
"ND::TReconPID") != std::string::npos) {
465 else if (reco_class_name.find(
"ND::TReconTrack") != std::string::npos) {
468 else if (reco_class_name.find(
"ND::TReconShower") != std::string::npos) {
471 else if (reco_class_name.find(
"ND::TReconCluster") != std::string::npos) {
475 ND280Error(
"Unknown object passed to TSFGReconModule");
482 const ND::THandle<ND::TReconVertex> vertex,
483 bool saveHits =
true) {
492 ND::THandle<ND::TVertexState> vertexState = vertex->GetState();
494 sfgVertex->
Status = vertex->GetStatus();
495 sfgVertex->
Quality = vertex->GetQuality();
496 sfgVertex->
NDOF = vertex->GetNDOF();
497 sfgVertex->
Position = vertexState->GetPosition();
498 sfgVertex->
PosVariance = vertexState->GetPositionVariance();
504 ND::THandle<ND::THitSelection> vertexHits = vertex->GetHits();
507 std::map< int, std::pair<int, float> > hitInfo
509 std::map< int, std::pair< int, float > >::iterator parentId;
511 for (parentId = hitInfo.begin();
512 parentId != hitInfo.end(); ++parentId) {
526 const ND::THandle<ND::TReconPID> particle,
527 bool saveHits =
true) {
536 ND::THandle<ND::TPIDState> particleState = particle->GetState();
538 sfgParticle->
Status = particle->GetStatus();
539 sfgParticle->
Quality = particle->GetQuality();
540 sfgParticle->
NDOF = particle->GetNDOF();
541 sfgParticle->
Position = particleState->GetPosition();
542 sfgParticle->
PosVariance = particleState->GetPositionVariance();
543 sfgParticle->
Direction = particleState->GetDirection();
544 sfgParticle->
DirVariance = particleState->GetDirectionVariance();
545 sfgParticle->
Momentum = particle->GetMomentum();
546 sfgParticle->
Charge = particle->GetCharge();
548 const ND::THandle<ND::THitSelection> particleHits = particle->GetHits();
551 std::map< int, std::pair<int, float> > hitInfo
553 std::map< int, std::pair< int, float > >::iterator parentId;
555 for (parentId = hitInfo.begin();
556 parentId != hitInfo.end(); ++parentId) {
568 ND::TReconObjectContainer::const_iterator alternate;
570 for (alternate = particle->GetAlternates().begin();
571 alternate != particle->GetAlternates().end();
574 ND::THandle<ND::TReconPID> alt = (*alternate);
576 sfgParticle->
PID.push_back(alt->GetParticleId());
577 sfgParticle->
PID_weight.push_back(alt->GetPIDWeight());
580 ND280Warn(
"TReconPID alternate is not a TReconPID - Ignored");
586 ND::THandle<ND::TG4Trajectory> G4track =
GetG4Trajectory(*particle, pur, eff);
603 bool saveHits =
true) {
611 ND::THandle<ND::TTrackState> trackState = track->GetState();
613 sfgTrack->
Status = track->GetStatus();
614 sfgTrack->
Quality = track->GetQuality();
615 sfgTrack->
NDOF = track->GetNDOF();
616 sfgTrack->
Position = trackState->GetPosition();
617 sfgTrack->
PosVariance = trackState->GetPositionVariance();
618 sfgTrack->
Direction = trackState->GetDirection();
619 sfgTrack->
DirVariance = trackState->GetDirectionVariance();
620 sfgTrack->
EDeposit = trackState->GetEDeposit();
622 const ND::THandle<ND::THitSelection> trackHits = track->GetHits();
625 std::map< int, std::pair<int, float> > hitInfo
627 std::map< int, std::pair< int, float > >::iterator parentId;
629 for (parentId = hitInfo.begin();
630 parentId != hitInfo.end(); ++parentId) {
639 const ND::TReconNodeContainer& nodeCont = track->GetNodes();
643 if (nodeCont.size() < 1)
return trackId;
645 ND::TReconNodeContainer::const_iterator node = nodeCont.begin();
646 ND::THandle<ND::TTrackState> nodeState = (*node)->GetState();
647 TVector3 frontPos = nodeState->GetPosition().Vect();
650 while (node != nodeCont.end()) {
657 nodeState = (*node)->GetState();
659 sfgTrack->
Length += (frontPos - nodeState->GetPosition().Vect()).Mag();
660 frontPos = nodeState->GetPosition().Vect();
667 ND::THandle<ND::TG4Trajectory> G4track =
GetG4Trajectory(*track, pur, eff);
684 const ND::THandle<ND::TReconShower> shower,
685 bool saveHits =
true) {
701 const ND::TReconNodeContainer& nodeCont = shower->GetNodes();
702 for (ND::TReconNodeContainer::const_iterator node = nodeCont.begin();
703 node != nodeCont.end(); ++node) {
704 ND::THandle<ND::TReconCluster> cluster = (*node)->GetObject();
709 ND::THandle<ND::TShowerState> showerState = shower->GetState();
711 sfgShower->
Status = shower->GetStatus();
712 sfgShower->
Quality = shower->GetQuality();
713 sfgShower->
NDOF = shower->GetNDOF();
714 sfgShower->
Position = showerState->GetPosition();
715 sfgShower->
PosVariance = showerState->GetPositionVariance();
716 sfgShower->
Direction = showerState->GetDirection();
717 sfgShower->
DirVariance = showerState->GetDirectionVariance();
718 sfgShower->
EDeposit = showerState->GetEDeposit();
719 sfgShower->
Cone = showerState->GetCone()[0];
721 sfgShower->
Width = 0.0;
724 const ND::THandle<ND::THitSelection> showerHits = shower->GetHits();
726 double totalCharge = 0.0;
731 std::map< int, std::pair<int, float> > hitInfo
734 for (std::map<
int, std::pair< int, float > >::iterator parentId
736 parentId != hitInfo.end(); ++parentId) {
745 for (ND::THitSelection::const_iterator hit = showerHits->begin();
746 hit != showerHits->end(); ++hit) {
749 TVector3 diff = (*hit)->GetPosition() - sfgShower->
Position.Vect();
755 TVector3 perp = diff - para;
757 float q = (*hit)->GetCharge();
760 sfgShower->
Width += q * perp.Mag();
762 avgLen += q * para.Mag();
763 avgLen2 += q * (para * para);
768 sfgShower->
Width /= std::max(totalCharge,1.0);
770 avgLen /= std::max(totalCharge,1.0);
771 avgLen2 /= std::max(totalCharge,1.0);
772 double len2 = avgLen2 - avgLen*avgLen;
774 sfgShower->
Length = std::sqrt(std::max(0.0, len2));
781 const ND::THandle<ND::TReconCluster> cluster,
782 bool saveHits =
true) {
791 sfgCluster->
EDeposit = cluster->GetEDeposit();
792 sfgCluster->
Position = cluster->GetPosition();
793 sfgCluster->
PosVariance = cluster->GetPositionVariance();
795 TMatrixF moments = cluster->GetMoments();
797 (moments.GetNrows() * moments.GetNcols()) ) {
798 std::copy(moments.GetMatrixArray(),
799 moments.GetMatrixArray()+sfgCluster->
arraySize,
803 const ND::THandle<ND::THitSelection> clusterHits = cluster->GetHits();
805 std::map< int, std::pair<int, float> > hitInfo
807 std::map< int, std::pair< int, float > >::iterator parentId;
809 for (parentId = hitInfo.begin();
810 parentId != hitInfo.end(); ++parentId) {
821 ND::THandle<ND::TG4Trajectory> G4track =
GetG4Trajectory(*cluster, pur, eff);
837 const ND::THandle<ND::TReconNode> node,
850 ND::THandle<ND::TReconState> s1 = node->GetState();
852 #if BEFORE_oaEvent(9,0,0)
853 const ND::TMPositionDirectionState* posDirState = NULL;
855 dynamic_cast<const ND::TMPositionDirectionState*
>(ND::GetPointer(s1));
857 sfgNode->
Position = posDirState->GetPosition();
858 sfgNode->
PosVariance = posDirState->GetPositionVariance();
859 sfgNode->
Direction = posDirState->GetDirection();
860 sfgNode->
DirVariance = posDirState->GetDirectionVariance();
869 sfgNode->
Position = GetPosition(s1);
871 sfgNode->
Direction = ND::TPIDState::GetStateDirection(s1);
872 sfgNode->
DirVariance = ND::TPIDState::GetStateDirectionVariance(s1);
880 ND::THandle<ND::TTrackState> s2 = node->GetState();
886 ND::THandle<ND::TReconBase> nodeObject = node->GetObject();
888 ND::THandle<ND::TReconState> objState = nodeObject->GetState();
890 #if BEFORE_oaEvent(9,0,0)
891 const ND::TMEDepositState* eDepState = NULL;
893 dynamic_cast<const ND::TMEDepositState*
>(ND::GetPointer(s1));
895 sfgNode->
EDeposit = eDepState->GetEDeposit();
900 sfgNode->
EDeposit = ND::TPIDState::GetStateEDeposit(objState);
906 const ND::THandle<ND::THitSelection> nodeHits = nodeObject->GetHits();
908 ND::THitSelection::const_iterator hit;
910 for (hit = nodeHits->begin();
911 hit != nodeHits->end(); ++hit) {
915 sfgNode->
Hits.push_back(hitId);
919 std::map< int, std::pair<int, float> > hitInfo
921 std::map< int, std::pair< int, float > >::iterator parentId;
923 for (parentId = hitInfo.begin();
924 parentId != hitInfo.end(); ++parentId) {
941 ND280Error(
"Trying to handle illegal hit");
947 HitMap::const_iterator mapIter;
950 return mapIter->second;
955 if (hitId < 0)
return hitId;
966 ND280Error(
"Trying to handle illegal hit");
973 sfgHit->
GeomId = hit->GetGeomId().AsInt();
974 sfgHit->
Charge = hit->GetCharge();
975 sfgHit->
Time = hit->GetTime();
976 sfgHit->
Position = hit->GetPosition();
985 std::map< int, std::pair<int, float> >
987 std::map< int, std::pair<int, float> > result;
990 for (ND::THitSelection::const_iterator hit = hits->begin();
991 hit != hits->end(); ++hit) {
993 float hitCharge = (*hit)->GetCharge();
994 std::map< int, int > hitCount;
995 std::map< int, float > chargeShare;
997 std::vector<ND::TG4VHit*> hitContribs
998 = HitTruthInfo::GetHitTruthInfo(*hit);
1000 for (std::vector<ND::TG4VHit*>::const_iterator g4Hit
1001 = hitContribs.begin();
1002 g4Hit != hitContribs.end(); ++g4Hit) {
1004 ND::TG4HitSegment* g4HitCast
1005 =
dynamic_cast<ND::TG4HitSegment*
>(*g4Hit);
1011 std::vector<int>::const_iterator trajIdIter;
1012 for (trajIdIter = g4HitCast->GetContributors().begin();
1013 trajIdIter != g4HitCast->GetContributors().end();
1016 ++hitCount[(*trajIdIter)];
1017 chargeShare[(*trajIdIter)] +=
1018 g4HitCast->GetEnergyDeposit()
1019 / g4HitCast->GetContributors().size();
1023 for (std::map< int, int >::const_iterator hC = hitCount.begin();
1024 hC != hitCount.end(); ++hC) {
1027 if ((*hC).second > 0) {
1028 result[(*hC).first].first;
1034 float totalChargeShare = 0;
1035 for (std::map< int, float >::const_iterator cS = chargeShare.begin();
1036 cS != chargeShare.end(); ++cS) {
1037 totalChargeShare += (*cS).second;
1041 for (std::map< int, float >::const_iterator cS = chargeShare.begin();
1042 cS != chargeShare.end(); ++cS) {
1043 result[(*cS).first].second +=
1044 hitCharge * (*cS).second / totalChargeShare;
1052 const ND::THandle<ND::THitSelection> hits) {
1054 std::vector<int> result;
1056 for (ND::THitSelection::const_iterator hit = hits->begin();
1057 hit != hits->end(); ++hit) {
1058 std::vector<ND::TG4VHit*> hitContribs
1059 = HitTruthInfo::GetHitTruthInfo(*hit);
1061 for (std::vector<ND::TG4VHit*>::const_iterator
1062 g4Hit = hitContribs.begin();
1063 g4Hit != hitContribs.end(); ++g4Hit) {
1064 ND::TG4HitSegment* g4HitCast
1065 =
dynamic_cast<ND::TG4HitSegment*
>(*g4Hit);
1066 result.push_back(g4HitCast->GetPrimaryId());
1071 std::sort(result.begin(), result.end());
1074 std::vector<int>::iterator newEnd =
1075 std::unique(result.begin(), result.end());
1076 result.erase(newEnd, result.end());
1093 int NumContrMPPCs = hit->GetContributorCount();
1096 std::vector<ND::TG4HitSegment*> HitSegXYPlane;
1097 std::vector<ND::TG4HitSegment*> HitSegXZPlane;
1098 std::vector<ND::TG4HitSegment*> HitSegYZPlane;
1101 std::vector<ND::TG4HitSegment*> HitSegAllPlanes;
1104 for (
int MPPCHit = 0; MPPCHit < NumContrMPPCs; MPPCHit++) {
1107 ND::THandle<ND::THit> currContrMPPC = hit->GetContributor(MPPCHit);
1108 std::vector<ND::TG4VHit*> TrueG4Hit = HitTruthInfo::GetHitTruthInfo(currContrMPPC);
1111 for (
auto G4Hit : TrueG4Hit) {
1114 ND::TG4HitSegment* G4HitSeg =
dynamic_cast<ND::TG4HitSegment*
>(G4Hit);
1115 if (G4HitSeg == NULL) {
1116 ND280Log(
"Cast of TG4Hit to TG4HitSegments unsuccessful");
1120 if (MPPCHit == 1) HitSegXZPlane.push_back(G4HitSeg);
1121 if (MPPCHit == 2) HitSegYZPlane.push_back(G4HitSeg);
1122 if (MPPCHit == 3) HitSegXYPlane.push_back(G4HitSeg);
1129 std::vector<int> TrueTrkID;
1130 std::vector<int> TrueTrkParentID;
1131 std::vector<int> InCubeTag;
1133 std::vector<ND::TG4HitSegment*> XZandYZIntersection;
1134 std::vector<ND::TG4HitSegment*> XZandXYIntersection;
1135 std::vector<ND::TG4HitSegment*> XYandYZIntersection;
1139 std::vector<ND::TG4HitSegment*> currContrHitSegV;
1143 std::sort(HitSegXZPlane.begin(), HitSegXZPlane.end());
1144 std::sort(HitSegYZPlane.begin(), HitSegYZPlane.end());
1145 std::sort(HitSegXYPlane.begin(), HitSegXYPlane.end());
1147 std::set_intersection(HitSegXZPlane.begin(), HitSegXZPlane.end(), HitSegYZPlane.begin(), HitSegYZPlane.end(), back_inserter(XZandYZIntersection));
1148 std::sort(XZandYZIntersection.begin(), XZandYZIntersection.end());
1149 std::set_intersection(XZandYZIntersection.begin(), XZandYZIntersection.end(), HitSegXYPlane.begin(), HitSegXYPlane.end(), back_inserter(currContrHitSegV));
1153 for (
auto HitSeg : currContrHitSegV) {
1159 ND::THandle<ND::TG4Trajectory> traj_temp =
fTrueTraj->GetTrajectory(HitSeg->GetPrimaryId());
1160 if(!traj_temp)
continue;
1161 TrueTrkID.push_back(traj_temp->GetTrackId());
1162 TrueTrkParentID.push_back(traj_temp->GetParentId());
1163 InCubeTag.push_back(1);
1169 ND::THandle<ND::TG4Trajectory> traj_temp =
fTrueTraj->GetTrajectory(HitSeg->GetPrimaryId());
1170 if(!traj_temp)
continue;
1171 TrueTrkID.push_back(traj_temp->GetTrackId());
1172 TrueTrkParentID.push_back(traj_temp->GetParentId());
1173 InCubeTag.push_back(0);
1179 if(TrueTrkID.size()==0){
1184 std::vector<int> PassTrkID;
1186 for(
size_t i = 0; i < TrueTrkID.size(); i++){
1187 if(TrueTrkParentID[i]==0) PassTrkID.push_back(TrueTrkID[i]);
1190 if(PassTrkID.size()>=1){
1191 std::sort(PassTrkID.begin(),PassTrkID.end());
1192 int NElement = PassTrkID.size();
1194 if(PassTrkID[0]!=PassTrkID[NElement-1]) sfgHit->
TrkHitTag = 1;
1197 bool trackhit =
false;
1198 for(
size_t i = 0; i < TrueTrkID.size(); i++){
1199 if(InCubeTag[i]==1) trackhit =
true;
1201 if(trackhit==
false) sfgHit->
TrkHitTag = 3;
1206 bool trackhit =
false;
1207 for(
size_t i = 0; i < TrueTrkID.size(); i++){
1208 if(InCubeTag[i]==1) trackhit =
true;
1210 if(trackhit==
false) sfgHit->
TrkHitTag = 3;
1226 bool isInside =
false;
1229 double HitSegPosX = 0.5*(HitSeg->GetStartX() + HitSeg->GetStopX());
1230 double HitSegPosY = 0.5*(HitSeg->GetStartY() + HitSeg->GetStopY());
1231 double HitSegPosZ = 0.5*(HitSeg->GetStartZ() + HitSeg->GetStopZ());
1235 double HitSegDistanceX = hit->GetPosition().X() - HitSegPosX;
1236 double HitSegDistanceY = hit->GetPosition().Y() - HitSegPosY;
1237 double HitSegDistanceZ = hit->GetPosition().Z() - HitSegPosZ;
1239 bool HitSegXIn = HitSegDistanceX > negdist && HitSegDistanceX < dist;
1240 bool HitSegYIn = HitSegDistanceY > negdist && HitSegDistanceY < dist;
1241 bool HitSegZIn = HitSegDistanceZ > negdist && HitSegDistanceZ < dist;
1245 if (HitSegXIn && HitSegYIn && HitSegZIn) {
1254 double cube_posx = hit->GetPosition().X();
1255 double cube_posy = hit->GetPosition().Y();
1256 double cube_posz = hit->GetPosition().Z();
1259 std::vector<int> nearby_trkid;
1260 std::vector<int> nearby_trkparentid;
1265 for (
auto HitSeg : HitSegAllPlanes) {
1268 double hitseg_posx = 0.5*(HitSeg->GetStartX() + HitSeg->GetStopX());
1269 double hitseg_posy = 0.5*(HitSeg->GetStartY() + HitSeg->GetStopY());
1270 double hitseg_posz = 0.5*(HitSeg->GetStartZ() + HitSeg->GetStopZ());
1274 if(TMath::Abs(cube_posx-hitseg_posx)>5 && TMath::Abs(cube_posx-hitseg_posx)<15 &&
1275 TMath::Abs(cube_posy-hitseg_posy)<5 && TMath::Abs(cube_posz-hitseg_posz)<5){
1279 else if(TMath::Abs(cube_posy-hitseg_posy)>5 && TMath::Abs(cube_posy-hitseg_posy)<15 &&
1280 TMath::Abs(cube_posx-hitseg_posx)<5 && TMath::Abs(cube_posz-hitseg_posz)<5){
1284 else if(TMath::Abs(cube_posz-hitseg_posz)>5 && TMath::Abs(cube_posz-hitseg_posz)<15 &&
1285 TMath::Abs(cube_posx-hitseg_posx)<5 && TMath::Abs(cube_posy-hitseg_posy)<5){
1292 if(InAdjacent==
true){
1293 ND::THandle<ND::TG4Trajectory> traj_temp = true_traj->GetTrajectory(HitSeg->GetPrimaryId());
1294 if(!traj_temp)
continue;
1295 nearby_trkid.push_back(traj_temp->GetTrackId());
1296 nearby_trkparentid.push_back(traj_temp->GetParentId());
1302 int N = nearby_trkid.size();
1304 if(N<1)
return false;
1308 std::vector<int> pass_trkid;
1309 for(
int i = 0; i < N; i++){
1310 if(nearby_trkparentid[i]==0) pass_trkid.push_back(nearby_trkid[i]);
1313 int n = pass_trkid.size();
1315 if(n<1)
return false;
1317 std::sort(pass_trkid.begin(),pass_trkid.end());
1319 if(pass_trkid[0]!=pass_trkid[n-1])
return true;
1330 TLorentzVector hitseg_pos;
1331 hitseg_pos.SetXYZT(0.5*(HitSeg->GetStartX() + HitSeg->GetStopX()),
1332 0.5*(HitSeg->GetStartY() + HitSeg->GetStopY()),
1333 0.5*(HitSeg->GetStartZ() + HitSeg->GetStopZ()),
1334 0.5*(HitSeg->GetStartT() + HitSeg->GetStopT()));
1337 TVector3 hitseg_dir;
1338 hitseg_dir.SetXYZ(HitSeg->GetStopX() - HitSeg->GetStartX(),
1339 HitSeg->GetStopY() - HitSeg->GetStartY(),
1340 HitSeg->GetStopZ() - HitSeg->GetStartZ());
1342 if(hitseg_dir.Mag() > 0) hitseg_dir *= (1. / hitseg_dir.Mag());
1345 std::vector<int> traj_ids = HitSeg->GetContributors();
1348 int curr_id = traj_ids[0];
1349 for(
size_t i = 0; i < traj_ids.size(); i++){
1351 if(i != 0 && traj_ids[i] == curr_id)
continue;
1352 curr_id = traj_ids[i];
1354 ND::THandle<ND::TG4Trajectory> traj_temp =
fTrueTraj->GetTrajectory(traj_ids[i]);
1355 if(!traj_temp)
continue;
1364 sfgHit->
HitSegTruePDG.push_back(traj_temp->GetPDGEncoding());
1367 int traj_mom = (traj_temp->GetInitialMomentum().Vect()).Mag();
1379 const T&
object,
double& purity,
double& eff){
1384 ND::TG4Trajectory traj;
1385 ND::THandle<ND::THitSelection> hits =
object.GetHits();
1387 return ND::THandle<ND::TG4Trajectory>();
1389 if (hits->size() < 1) {
1390 return ND::THandle<ND::TG4Trajectory>();
1393 int G4TrkId = TrackTruthInfo::GetG4TrajIDHits(*hits, eff, purity);
1394 const ND::TND280Event&
event = *(ND::TEventFolder::GetCurrentEvent());
1395 ND::THandle<ND::TG4TrajectoryContainer> G4trajectories =
1396 event.Get<ND::TG4TrajectoryContainer>(
"truth/G4Trajectories");
1397 if (!G4trajectories) {
1398 return ND::THandle<ND::TG4Trajectory>();
1400 ND::TG4TrajectoryContainer::iterator trajIter =
fTrueTraj->begin();
1401 ND::TG4TrajectoryContainer::iterator trajEnd =
fTrueTraj->end();
1402 for (; trajIter != trajEnd; ++trajIter) {
1403 ND::TG4Trajectory* trajectory = &(trajIter->second);
1404 if (trajectory->GetTrackId() == G4TrkId) {
1405 ND::THandle<ND::TG4Trajectory> traj(
new ND::TG4Trajectory((*trajectory)));
1410 return ND::THandle<ND::TG4Trajectory>();
std::vector< int > Truth_TrajIds
The vector of primary true trajectory Ids which contribute to the ND::THits which are constituents of...
std::vector< int > Truth_HitCount
The vector of true trajectory Ids which contribute to the ND::THits which are constituents of this ve...
std::vector< int > Truth_TrajIds
True trajectory Ids See the TSFGVertex object for documentation.
virtual int FillNode(const ND::THandle< ND::TReconNode >, bool saveHits)
Fill the next node for any type of object.
virtual std::map< int, std::pair< int, float > > HitTruthInfo(const ND::THandle< ND::THitSelection >)
For each hit, go through and find the energy generated for each trajectory.
float EDeposit
The total reconstructed energy deposit of the corresponding track. This is usually just the sum of th...
float Charge
The reconstructed particle charge of the corresponding TReconPID.
std::vector< float > Truth_ChargeShare
Carge share o true trajectory.
TLorentzVector PosVariance
Variance on the position of the corresponding object.
virtual ObjectId FillParticleObject(const ND::THandle< ND::TReconPID >, bool saveHits)
Fill the next TSFGParticle entry from a TReconPID.
std::vector< float > HitSegTrueEdepo
True energy loss of the current hit segment.
std::vector< float > Truth_ChargeShare
Carge share o true trajectory.
std::vector< int > Truth_HitCount
Nmber of hits contributed by each true trajectory.
bool checkHitSegInCube(ND::THandle< ND::THit > hit, ND::TG4HitSegment *HitSeg)
int FillHit(const ND::THandle< ND::THit >)
Fill the Hits container and return the index of the new hit.
int TrueParticlePur
Purity of Geant4 particle associated to a TSFGTrack.
int fNTracks
The TSFGTrack vector of results.
ClassImp(ND::TBeamSummaryDataModule::TBeamSummaryData)
TSFGClusterContainer * fClusters
The TSFGCluster vector of results.
int NDOF
The Number of Degrees of Freedom in the reconstruction of the corresponding object. Retrieved from ND::TReconBase::GetNDOF.
TVector3 Direction
Direction of the corresponding object.
int fNNodes
The TSFGNode vector of results.
std::vector< int > Truth_TrajIds
True trajectory Ids.
float Quality
ND::TReconBase::StateBits to check the which status flags are set.
std::string fDescription
A longish descrition of the analysis.
TSFGAlgoResContainer * fAlgoResults
The TSFGAlgoRes vector of results.
int TrueParticleID
True Geant4 particle associated to a TSFGTrack.
virtual ~TSFGReconModule()
int fNShowers
The TSFGShower vector of results.
virtual ObjectId FillShowerObject(const ND::THandle< ND::TReconShower >, bool saveHits)
Fill the next TSFGShower entry from a TReconShower.
int TrueParticleID
True Geant4 particle associated to a TSFGTrack.
TVector3 Position
Hit position.
TVector3 Direction
Direction of the corresponding object.
Contains a summary of the reconstruction information in a TReconShower.
int Status
The reported status of the corresponding object. Use ND::TReconBase::StateBits to check the which sta...
TLorentzVector Position
Position of the corresponding object.
static const int arraySize
Size of the TSFGCluster::Moments array.
std::vector< int > Truth_TrajIds
True trajectory Ids.
TSFGHitContainer * fTrueHits
int TrueParticleID
True G4 particle associated to a TSFGParticle.
int TrueParticlePur
Purity of the True G4 particle associated to a TSFGParticle.
int fNAlgoResults
The TSFGAlgoRes vector of results.
void FillTrueTrajInfoForHit(ND::TG4HitSegment *, TSFGHit *)
int fNVertices
The TSFGVertex vector of results.
void FillBaseObject(T basePtr, ND::THandle< ND::TReconBase > baseObject, bool saveHits)
Fill the header for TSFGAlgoRes, TSFGVertex, TSFGParticle, TSFGTrack, TSFGVertex, and TSFGCluster...
TLorentzVector Position
Position of the corresponding object.
std::vector< float > Truth_ChargeShare
Carge share o true trajectory See the TSFGVertex object for documentation.
virtual ObjectId FillClusterObject(const ND::THandle< ND::TReconCluster >, bool saveHits)
Fill the next TSFGCluster entry from a TReconCluster.
ND::THandle< ND::TG4Trajectory > GetG4Trajectory(const T &object, double &pur, double &eff)
bool checkNearbyMultiTrk(ND::THandle< ND::THit > hit, std::vector< ND::TG4HitSegment * > HitSegAllPlanes, ND::THandle< ND::TG4TrajectoryContainer > true_traj)
std::vector< int > Truth_HitCount
Nmber of hits contributed by each true trajectory.
TVector3 Direction
Direction of the corresponding object.
void FillHitInfoNeededForNN(const ND::THandle< ND::THit >, TSFGHit *)
TLorentzVector PosVariance
Variance on the position of the corresponding object.
virtual std::vector< int > HitTruthPrimaryInfo(const ND::THandle< ND::THitSelection >)
For each hit, go through and find the primary particles that are depositing energy.
float Quality
The reported reconstruction 'quality' of the corresponding object. Uses ND::TReconBase::GetQuality.
std::vector< int > Clusters
Holds index of the TSFGShower objects that are pertinent to this algorithm result.
virtual ObjectId FillTrackObject(const ND::THandle< ND::TReconTrack >, bool saveHits)
Fill the next TSFGTrack entry from a TReconTrack.
TLorentzVector Position
Position of the corresponding object.
float Time
Reconstructed hit time from the corresponding TSingleHit.
Int_t fBufferSize
Buffer Size for TBranch.
std::vector< TPRegexp > fRejectAlgoResultList
If an incoming TAlgorithmResult's name matches a pattern within this vector it will not be summarised...
virtual bool FillTree(ND::TND280Event &)
Called by the main loop to fill an event.
float EDeposit
The total reconstructed energy deposit of the corresponding track. This is usually just the sum of th...
int UsedHitCluster
The index of the cluster that contains all of the hits used by this algorithm result. This is -1 if the hits are not saved.
TLorentzVector Position
corresponding object.
std::vector< int > Truth_PrimaryTrajIds
Primary Ids of truth trajectories.
float Quality
The reported reconstruction 'quality' of the vertex. Retrieved from ND::TReconBase::GetQuality.
float EDeposit
The total reconstructed energy deposit of the corresponding track. This is usually just the sum of th...
virtual ObjectId FillVertexObject(const ND::THandle< ND::TReconVertex >, bool saveHits)
Fill the next TSFGVertex entry from a TReconVertex.
TSFGReconModule(const char *name="SFG", const char *title="SFG Recon Module")
TLorentzVector Position
Position of the correspponding object.
TSFGHitContainer * fHits
The TSFGHit vector of hits.
TLorentzVector PosVariance
Variance on the position of the corresponding object.
std::vector< TLorentzVector > HitSegPosition
True hit segments inside the cube position (3D + time)
std::string fCVSID
Defined if an official tagged version.
TLorentzVector PosVariance
Variance on the position of the corresponding object.
std::vector< int > Truth_HitCount
Nmber of hits contributed by each true trajectory.
int fNTrueHits
The TSFGHit vector of hits based on the number of photons generated in each cube. ...
Contains a summary of the reconstruction information for each cube.
virtual ObjectId FillReconObject(const ND::THandle< ND::TReconBase >, bool saveHits)
This is a switch yard to take any sort of reconstruction object, and farm it out to the right specifi...
int Status
The reported Status of the corresponding object. Use ND::TReconBase::StateBits to check the which sta...
std::vector< int > Truth_TrajIds
True trajectory Ids.
std::vector< float > Truth_ChargeShare
Carge share o true trajectory.
int TrueParticleEff
Efficiency of Geant4 particle associated to a TSFGTrack.
TVector3 Direction
Direction of the corresponding object.
void SetNameTitle(char const *name, char const *title)
TVector3 DirVariance
Direction variance of the corresponding object.
std::vector< int > Truth_HitCount
Nmber of hits contributed by each true trajectory.
TVector3 DirVariance
Direction variance of the corresponding object.
float Cone
The opening angle of the TShowerState cone of the corresponding TReconShower.
A summary of the reconstruction information in a TReconPID.
std::string FullName
A unique Id used for reconstruction objects.
virtual void InitializeBranches()
Called to let the module setup the appropriate branches.
Contains a summary of the reconstruction information in a TReconTrack.
int fNClusters
The TSFGCluster vector of results.
std::vector< int > Hits
Holds internal Ids of Hits pertinent to this reconstruction node.
TLorentzVector PosVariance
Variance on the position of the corresponding object.
int Parent
The index of the parent algorithm for this algorithm result. This will be -1 if this doesn't have a p...
TSFGPartContainer * fParticles
The TSFGParticle vector of results.
Contains a summary of the reconstruction information in a TReconNode.
std::vector< int > Clusters
The indices of the clusters contained by the current object.
virtual int FillAlgorithmResult(const ND::THandle< ND::TAlgorithmResult >, int)
Fill an algorithm result and all of it's subsidiary reconstruction objects.
float Width
The 'width' of the shower, the extent perpendicular to the direction.
TSFGNodeContainer * fNodes
The TSFGNode vector of results.
std::vector< int > HitSegTruePDG
True particle PDG of the track contributing to the hit segment.
int id
An internal Id for each Reconstruction object.
int Status
The reported Status of the corresponding ND::TReconPID.
float EDeposit
Holds internal Ids of Hits pertinent to this reconstruction node.
int NDOF
object. Uses ND::TReconBase::GetQuality
Contains a summary of the reconstruction information in a TReconCluster.
std::vector< float > HitSegTrueP
True momentum of the track contributing to the hit segment.
std::vector< float > Truth_ChargeShare
The number of THits that each truth trajectory contributed to.
std::vector< int > Hits
Holds index of the TSFGNode objects that are pertinent to this algorithm result.
The representation of the information store in each SFG TReconVertex object.
std::vector< int > Vertices
Holds index of the TSFGVertex objects that are pertinent to this algorithm result.
ND::THandle< ND::TG4TrajectoryContainer > fTrueTraj
std::vector< int > Particles
Holds index of the TSFGVertex objects that are pertinent to this algorithm result.
std::vector< int > Truth_PrimaryTrajIds
The vector of primary true trajectory Ids which contribute to the ND::THits which are constituents of...
std::vector< float > PID_weight
PID weights for each PID in TSFGParticle::PID.
Int_t fSplitLevel
Split Level for TBranch.
int NDOF
The Number of Degrees of Freedom in the reconstruction of the corresponding object. Retrieved from ND::TReconBase::GetNDOF.
std::string AlgorithmName
The name of the algorithm that generated this object.
int Status
The reported Status of the corresponding object. Use ND::TReconBase::StateBits to check the which sta...
int NDOF
The Number of Degrees of Freedom in the vertex. Retrieved from ND::TReconBase::GetNDOF.
TVector3 DirVariance
Direction variance of the corresponding object.
UInt_t GeomId
Geometry Id of the TSingleHit.
float Quality
The reported reconstruction 'quality' of the corresponding object. Uses ND::TReconBase::GetQuality.
TLorentzVector Position
Position of the corresponding object.
float Charge
Reconstructed hit charge without attenuation correction from thE corresponding TSingleHit.
int TrueParticleEff
Efficiency of Geant4 particle associated to a TSFGTrack.
std::vector< int > PID
Potential PIDs (ND::TReconPID::ParticleId) matching with TSFGParticle::PID_Weight values...
std::vector< TVector3 > HitSegDirection
True hit segments inside the cube direction (3D)
int fNHits
The TSFGHit vector of hits.
TVector3 DirVariance
Direction variance of the corresponding object.
An internal Id and object type for each Reconstruction object.
std::vector< int > Truth_PrimaryTrajIds
Primary Ids of truth trajectories See the TSFGVertex object for documentation.
int TrueParticleEff
Efficiency of the True G4 particle associated to a TSFGParticle.
std::string fCVSTagName
Defined if an official tagged version.
TLorentzVector PosVariance
Variance on the position of the corresponding object.
std::vector< int > Truth_PrimaryTrajIds
Primary Ids of truth trajectories.
std::vector< int > Showers
Holds index of the TSFGTrack objects that are pertinent to this algorithm result. ...
TSFGHitContainer * fFibers
The TSFGHit vector of hits for each fiber.
std::vector< int > Truth_TrajIds
True trajectory Ids.
TSFGTrackContainer * fTracks
The TSFGTrack vector of results.
std::vector< int > AlgoResults
The path to the result inside the event.
int UnusedHitCluster
The index of the cluster that contains all of the hits not used by this algorithm result...
float Moments[arraySize]
Moments of the cluster stored as a flat 3x3 matrix.
std::vector< float > Truth_ChargeShare
Carge share o true trajectory.
TSFGVertexContainer * fVertices
The TSFGVertex vector of results.
std::vector< int > Tracks
Holds index of the TSFGParticle objects that are pertinent to this algorithm result.
std::vector< int > Truth_PrimaryTrajIds
Primary Ids of truth trajectories.
float Length
The 'width' of the shower, the extent perpendicular to the direction.
float Length
The length of the track calculated by summing over the distances between the constituent TReconNodes...
float Momentum
The reconstructed momentum of the corresponding TReconPID.
TClonesArray TSFGHitContainer
int TrkHitTag
Single/multiple track hit tagging Notation: 1 = multiple track hits, 2 = single track hits...
TSFGShowerContainer * fShowers
The TSFGShower vector of results.
int fNFibers
The TSFGHit vector of hits for each fiber.
The representation of the information store in each SFG TAlgorithmResult object.
int AddHit(const ND::THandle< ND::THit >, int &nDest, ND::TSFGReconModule::TSFGHitContainer *dest)
Add a hit to the destination container and return the index.
std::vector< int > Truth_HitCount
Nmber of hits contributed by each true trajectory See the TSFGVertex object for documentation.
std::vector< int > Truth_PrimaryTrajIds
The RMS length of the shower, the extent parallel to the direction.
double EDeposit_fit
Fitted energy deposit for each node.
int fNParticles
The TSFGParticle vector of results.
int TrueParticlePur
Purity of Geant4 particle associated to a TSFGTrack.