9 #include "TAlgorithmResult.hxx"
11 #include "TG4PrimaryVertex.hxx"
12 #include "TGeomInfo.hxx"
13 #include "TGeometryId.hxx"
14 #include "THandle.hxx"
15 #include "THitSelection.hxx"
16 #include "TND280Event.hxx"
17 #include "TND280Log.hxx"
18 #include "TPIDState.hxx"
19 #include "TP0DGeom.hxx"
20 #include "TRealDatum.hxx"
21 #include "TIntegerDatum.hxx"
22 #include "TReconCluster.hxx"
23 #include "TReconNode.hxx"
24 #include "TReconPID.hxx"
25 #include "TReconShower.hxx"
26 #include "TReconTrack.hxx"
27 #include "TReconVertex.hxx"
28 #include "TReconState.hxx"
29 #include "TShowerState.hxx"
30 #include "TTrackState.hxx"
31 #include "TVertexState.hxx"
32 #include "TG4HitSegment.hxx"
33 #include "TTFBChannelId.hxx"
34 #include "retrieveHitTruthInfo.hxx"
37 #include "oaEvent_version.h"
39 #if (oaEvent_MAJOR_VERSION>8)
40 #include "TReconStateUtilities.hxx"
41 #include "TShowerState.hxx"
42 #include "TPIDState.hxx"
43 using ND::TReconStateUtilities::GetPosition;
44 using ND::TReconStateUtilities::GetPositionVariance;
45 using ND::TReconStateUtilities::GetPositionIndex;
75 $Id: eventAnalysis TP0DReconModule.cxx,2024/03/20:09:46:10,Alexander_J_Finch,lapw.lancs.ac.uk $"
79 SetNameTitle(name, title);
83 fDescription =
"P0D Recon Output";
99 fAlgoResults =
new TClonesArray(
"ND::TP0DReconModule::TP0DAlgoRes", 200);
100 fVertices =
new TClonesArray(
"ND::TP0DReconModule::TP0DVertex", 200);
101 fParticles =
new TClonesArray(
"ND::TP0DReconModule::TP0DParticle", 200);
102 fShowers =
new TClonesArray(
"ND::TP0DReconModule::TP0DShower", 200);
103 fTracks =
new TClonesArray(
"ND::TP0DReconModule::TP0DTrack", 200);
104 fNodes =
new TClonesArray(
"ND::TP0DReconModule::TP0DNode", 200);
105 fHits =
new TClonesArray(
"ND::TP0DReconModule::TP0DHit", 200);
106 fClusters =
new TClonesArray(
"ND::TP0DReconModule::TP0DCluster", 200);
108 fRejectAlgoResultList.clear();
109 fRejectAlgoResultList.push_back(TPRegexp(
"TP0DTrack$"));
110 fRejectAlgoResultList.push_back(TPRegexp(
"TP0DExpandSeeds$"));
111 fRejectAlgoResultList.push_back(TPRegexp(
"TP0D3DTrackMatching$"));
112 fRejectAlgoResultList.push_back(TPRegexp(
"TP0DPairwiseVertex$"));
113 fRejectAlgoResultList.push_back(TPRegexp(
"TP0D3DShowerMatching$"));
114 fRejectAlgoResultList.push_back(TPRegexp(
"TP0DShareCharge$"));
115 fRejectAlgoResultList.push_back(TPRegexp(
"-Expand$"));
116 fRejectAlgoResultList.push_back(TPRegexp(
"TP0DPairwiseVertexSingle$"));
117 fRejectAlgoResultList.push_back(TPRegexp(
"TP0DTrackVertex$"));
118 fRejectAlgoResultList.push_back(TPRegexp(
"TP0DTrackPID$"));
119 fRejectAlgoResultList.push_back(TPRegexp(
"TP0DShowerInputs$"));
120 fRejectAlgoResultList.push_back(TPRegexp(
"TP0DShowerVertex$"));
121 fRejectAlgoResultList.push_back(TPRegexp(
"TP0DShowerPID$"));
137 fOutputTree->Branch(
"NAlgoResults", &fNAlgoResults,
138 "NAlgoResults/S", fBufferSize)
139 ->SetTitle(
"The number of Algorithm Results ");
140 fOutputTree->Branch(
"NVertices", &fNVertices,
141 "NVertices/S", fBufferSize)
142 ->SetTitle(
" The number of added vertices");
143 fOutputTree->Branch(
"NParticles", &fNParticles,
144 "NParticles/S", fBufferSize)
145 ->SetTitle(
" The number of particles ");
146 fOutputTree->Branch(
"NShowers", &fNShowers,
147 "NShowers/S", fBufferSize)
148 ->SetTitle(
" The number of showers");
149 fOutputTree->Branch(
"NTracks", &fNTracks,
150 "NTracks/S", fBufferSize)
151 ->SetTitle(
" The number of tracks");
152 fOutputTree->Branch(
"NNodes", &fNNodes,
153 "NNodes/S", fBufferSize)
154 ->SetTitle(
" The number of track nodes");
155 fOutputTree->Branch(
"NHits", &fNHits,
156 "NHits/S", fBufferSize)
157 ->SetTitle(
"The number of hits that are saved ");
158 fOutputTree->Branch(
"NClusters", &fNClusters,
159 "NClusters/S", fBufferSize)
160 ->SetTitle(
"The number of clusters ");
163 fOutputTree->Branch(
"AlgoResults", &fAlgoResults,
164 fBufferSize, fSplitLevel)
165 ->SetTitle(
"The TP0DAlgoRes vector of Algorithm Results. ");
166 fOutputTree->Branch(
"Vertices", &fVertices,
167 fBufferSize, fSplitLevel)
168 ->SetTitle(
" The TP0DVertex vector of vertices.");
169 fOutputTree->Branch(
"Particles", &fParticles,
170 fBufferSize, fSplitLevel)
171 ->SetTitle(
"The TP0DParticle vector of particles. ");
172 fOutputTree->Branch(
"Showers", &fShowers,
173 fBufferSize, fSplitLevel)
174 ->SetTitle(
"The TP0DShower vector of showers. ");
175 fOutputTree->Branch(
"Tracks", &fTracks,
176 fBufferSize, fSplitLevel)
177 ->SetTitle(
" The TP0DTrack vector of tracks.");
178 fOutputTree->Branch(
"Nodes", &fNodes,
179 fBufferSize, fSplitLevel)
180 ->SetTitle(
" The TP0DNode vector of nodes.");
181 fOutputTree->Branch(
"Hits", &fHits,
182 fBufferSize, fSplitLevel)
183 ->SetTitle(
"The TP0DHit vector of hits. ");
184 fOutputTree->Branch(
"Clusters", &fClusters,
185 fBufferSize, fSplitLevel)
186 ->SetTitle(
"The TP0DCluster vector of clusters ");
201 fAlgoResults->Clear();
215 ND::THandle<ND::TAlgorithmResult> p0dRecon =
event.GetFit(
"p0dRecon");
218 ND280Info(
"No p0dRecon in Event");
222 FillAlgorithmResult(p0dRecon, -1);
229 ND::THandle<ND::TReconBase> baseObject,
232 basePtr->AlgorithmName = baseObject->GetAlgorithmName();
235 ND::THandle<ND::THitSelection> baseHits = baseObject->GetHits();
239 basePtr->NHits = (short)baseHits->size();
242 ND::THitSelection::const_iterator hit;
243 for(hit = baseHits->begin();
244 hit != baseHits->end(); ++hit){
247 basePtr->Hits.push_back(hitId);
255 basePtr->UniqueID = baseObject->GetUniqueID();
258 ND::THandle<ND::TReconObjectContainer> objCont =
259 baseObject->GetConstituents();
261 ND::TReconObjectContainer::const_iterator constituent;
262 for (constituent = objCont->begin();
263 constituent != objCont->end();
268 basePtr->Vertices.push_back(conID.
id);
271 basePtr->Particles.push_back(conID.
id);
274 basePtr->Tracks.push_back(conID.
id);
277 basePtr->Showers.push_back(conID.
id);
280 basePtr->Clusters.push_back(conID.
id);
287 const ND::TReconNodeContainer& nodeCont = baseObject->GetNodes();
288 ND::TReconNodeContainer::const_iterator node;
289 for (node = nodeCont.begin();
290 node != nodeCont.end();
293 int nodeID =
FillNode(*node, saveHits);
294 basePtr->Nodes.push_back(nodeID);
298 for (TDataVector::iterator d = baseObject->begin();
299 d != baseObject->end(); ++d) {
301 if ( !(*d) ){
continue;}
302 std::string sub_class_name = (*d)->ClassName();
303 std::string fullname = (*d)->GetFullName().Data();
305 if ( (sub_class_name.find(
"ND::TReconObjectContainer") !=
306 std::string::npos) &&
307 (fullname.find(
"//unnamed/decays") != std::string::npos) ) {
309 ND::THandle<ND::TReconObjectContainer> clusters
310 = (*d)->Get<ND::TReconObjectContainer>(
".");
311 if(!clusters){
continue;}
313 ND::TReconObjectContainer::const_iterator clus;
314 for (clus = clusters->begin();
315 clus != clusters->end();
320 basePtr->Clusters.push_back(conID.
id);
323 ND280Error(
"Muon Decay object not a cluster");
332 const ND::THandle<ND::TAlgorithmResult> algoRes,
335 TString fullName = algoRes->GetFullName();
336 TString baseName = fullName;
337 baseName.Remove(0,baseName.Last(
'/') + 1);
343 for(std::vector<TPRegexp>::iterator cut = fRejectAlgoResultList.begin();
344 cut != fRejectAlgoResultList.end(); ++cut){
346 if(cut->MatchB(fullName,
"", 0, 1)){
347 ND280Verbose(
"Rejecting:\t" << baseName
348 <<
" (" << cut->GetPattern() <<
")");
353 ND280Verbose(
"Fill Algorithm Result:\t" << baseName);
355 int algoResID = fNAlgoResults;
358 new ((*fAlgoResults)[fNAlgoResults++])
TP0DAlgoRes;
362 p0dAlgoResult->
Parent = parent;
365 ND::THandle<ND::THitSelection> usedHits = algoRes->GetHitSelection(
"used");
368 if(usedHits && (!usedHits->empty())){
369 ND::THitSelection::const_iterator hit;
371 for(hit = usedHits->begin();
372 hit != usedHits->end(); ++hit){
374 short hitId = FillHit(*hit);
376 p0dAlgoResult->
Hits.push_back(hitId);
379 ND::THandle<ND::TReconCluster> usedCluster(
new ND::TReconCluster);
380 usedCluster->FillFromHits((baseName+
"Used").Data(), *usedHits);
382 ObjectID clusterID = FillReconObject(usedCluster,
true);
388 ND::THandle<ND::THitSelection> unusedHits
389 = algoRes->GetHitSelection(
"unused");
392 if(unusedHits && (!unusedHits->empty())){
393 ND::THandle<ND::TReconCluster> unusedCluster(
new ND::TReconCluster);
394 unusedCluster->FillFromHits((baseName+
"Unused").Data(), *unusedHits);
397 ObjectID clusterID = FillReconObject(unusedCluster,
false);
403 ND::THandle<ND::TReconObjectContainer>
final
404 = algoRes->GetResultsContainer(
"final");
406 ND::TReconObjectContainer::const_iterator reconObject;
407 for (reconObject = final->begin();
408 reconObject !=
final->end(); reconObject++){
410 ObjectID objID = FillReconObject(*reconObject,
true);
411 if(objID.
type == ObjectID::kVertex){
414 else if(objID.
type == ObjectID::kParticle){
417 else if(objID.
type == ObjectID::kTrack){
418 p0dAlgoResult->
Tracks.push_back(objID.
id);
420 else if(objID.
type == ObjectID::kShower){
421 p0dAlgoResult->
Showers.push_back(objID.
id);
423 else if(objID.
type == ObjectID::kCluster){
431 ND::THandle<ND::TReconObjectContainer> clusters
432 = algoRes->GetResultsContainer(
"clusters");
434 ND::TReconObjectContainer::const_iterator reconObject;
435 for (reconObject = clusters->begin();
436 reconObject != clusters->end(); reconObject++){
438 ObjectID objID = FillReconObject(*reconObject,
true);
439 if (objID.
type == ObjectID::kVertex) {
442 else if (objID.
type == ObjectID::kParticle) {
445 else if (objID.
type == ObjectID::kTrack) {
446 p0dAlgoResult->
Tracks.push_back(objID.
id);
448 else if (objID.
type == ObjectID::kShower) {
449 p0dAlgoResult->
Showers.push_back(objID.
id);
451 else if (objID.
type == ObjectID::kCluster) {
457 for (TDataVector::iterator d = algoRes->begin();
458 d != algoRes->end(); ++d) {
459 if (!(*d)){
continue;}
460 std::string class_name = (*d)->ClassName();
462 if (class_name.find(
"ND::TAlgorithmResult") != std::string::npos) {
463 ND::THandle<ND::TAlgorithmResult> subResult =
464 (*d)->Get<ND::TAlgorithmResult>(
".");
465 if(!subResult){
continue;}
466 int daughterID = FillAlgorithmResult(subResult, algoResID);
467 if(daughterID != -1){
477 const ND::THandle<ND::TReconBase> reconObject,
478 bool saveHits =
true){
480 std::string reco_class_name = reconObject->ClassName();
482 if(reco_class_name.find(
"ND::TReconVertex") != std::string::npos){
483 ND280Verbose(
"Fill Vertex");
484 return FillVertexObject(reconObject, saveHits);
486 else if(reco_class_name.find(
"ND::TReconPID") != std::string::npos){
487 ND280Verbose(
"Fill PID");
488 return FillParticleObject(reconObject, saveHits);
490 else if(reco_class_name.find(
"ND::TReconTrack") != std::string::npos){
491 ND280Verbose(
"Fill Track");
492 return FillTrackObject(reconObject, saveHits);
494 else if(reco_class_name.find(
"ND::TReconShower") != std::string::npos){
495 ND280Verbose(
"Fill Shower");
496 return FillShowerObject(reconObject, saveHits);
498 else if(reco_class_name.find(
"ND::TReconCluster") != std::string::npos){
499 ND280Verbose(
"Fill Cluster");
500 return FillClusterObject(reconObject, saveHits);
503 ND280Error(
"Unknown object passed to TP0DReconModule");
510 const ND::THandle<ND::TReconVertex> vertex,
511 bool saveHits =
true){
514 vertexID.
id = fNVertices;
515 vertexID.
type = ObjectID::kVertex;
520 FillBaseObject(p0dVertex, vertex, saveHits);
522 ND::THandle<ND::TVertexState> vertexState = vertex->GetState();
524 p0dVertex->
Status = vertex->GetStatus();
525 p0dVertex->
Quality = vertex->GetQuality();
526 p0dVertex->
NDOF = vertex->GetNDOF();
527 p0dVertex->
Position = vertexState->GetPosition();
528 p0dVertex->
PosVariance = vertexState->GetPositionVariance();
530 ND::TGeomInfo::P0D().WaterFiducialDistance(p0dVertex->
Position.X(),
535 CountValidDimensions(p0dVertex->
PosVariance.Vect());
541 ND::THandle<ND::THitSelection> vertexHits = vertex->GetHits();
544 std::map< int, std::pair<int, float> > hitInfo = HitTruthInfo(vertexHits);
545 std::map< int, std::pair< int, float > >::iterator parentID;
547 for(parentID = hitInfo.begin(); parentID != hitInfo.end(); ++parentID){
561 const ND::THandle<ND::TReconPID> particle,
562 bool saveHits =
true){
565 particleID.
id = fNParticles;
566 particleID.
type = ObjectID::kParticle;
571 FillBaseObject(p0dParticle, particle, saveHits);
573 ND::THandle<ND::TPIDState> particleState = particle->GetState();
575 p0dParticle->
Status = particle->GetStatus();
576 p0dParticle->
Quality = particle->GetQuality();
577 p0dParticle->
NDOF = particle->GetNDOF();
578 p0dParticle->
Position = particleState->GetPosition();
579 p0dParticle->
PosVariance = particleState->GetPositionVariance();
580 p0dParticle->
Direction = particleState->GetDirection();
581 p0dParticle->
DirVariance = particleState->GetDirectionVariance();
582 p0dParticle->
Momentum = particle->GetMomentum();
583 p0dParticle->
Charge = particle->GetCharge();
586 CountValidDimensions(p0dParticle->
PosVariance.Vect());
588 const ND::THandle<ND::THitSelection> particleHits = particle->GetHits();
591 std::map< int, std::pair<int, float> > hitInfo = HitTruthInfo(particleHits);
592 std::map< int, std::pair< int, float > >::iterator parentID;
594 for(parentID = hitInfo.begin(); parentID != hitInfo.end(); ++parentID){
606 ND::THitSelection::const_iterator hit;
607 for (hit = particleHits->begin();
608 hit != particleHits->end();
611 ND::TGeometryId geomid = (*hit)->GetGeomId();
612 if (!ND::GeomId::P0D::IsP0D(geomid))
continue;
613 int p0dule = ND::TGeomInfo::P0D().GetBar(geomid).GetP0Dule();
614 int layer = ND::TGeomInfo::P0D().GetBar(geomid).GetLayer();
615 int bar = ND::TGeomInfo::P0D().GetBar(geomid).GetNumber();
618 p0dParticle->
EndDeposit += (*hit)->GetCharge();
621 if(bar < 4 || (layer == 0 && bar > 121) || (layer == 1 && bar > 129)){
638 for(ND::TDataVector::iterator dvIter = particle->begin();
639 dvIter != particle->end(); ++dvIter){
640 ND::TRealDatum *rDatum =
dynamic_cast<ND::TRealDatum*
>(*dvIter);
643 TString datumName = rDatum->GetFullName();
644 Ssiz_t lastSlash = datumName.Last(
'/');
645 TSubString pidAlgoName = datumName(lastSlash + 1, datumName.Length());
647 std::vector<float> tempVector;
648 std::copy(rDatum->begin(),
650 std::back_inserter(tempVector));
652 p0dParticle->
realPIDNames.push_back(pidAlgoName.Data());
657 ND::TIntegerDatum *iDatum =
dynamic_cast<ND::TIntegerDatum*
>(*dvIter);
660 TString datumName = iDatum->GetFullName();
661 Ssiz_t lastSlash = datumName.Last(
'/');
662 TSubString pidAlgoName = datumName(lastSlash + 1, datumName.Length());
664 std::vector<short> tempVector;
665 std::copy(iDatum->begin(),
667 std::back_inserter(tempVector));
677 ND::TReconObjectContainer::const_iterator alternate;
679 for(alternate = particle->GetAlternates().begin();
680 alternate != particle->GetAlternates().end();
683 ND::THandle<ND::TReconPID> alt = (*alternate);
685 p0dParticle->
PID.push_back(alt->GetParticleId());
686 p0dParticle->
PID_weight.push_back(alt->GetPIDWeight());
688 else {ND280Warn(
"TReconPID alternate is not a TReconPID - Ignored");}
696 bool saveHits =
true){
698 trackID.
id = fNTracks;
699 trackID.
type = ObjectID::kTrack;
704 FillBaseObject(p0dTrack, track, saveHits);
706 ND::THandle<ND::TTrackState> trackState = track->GetState();
708 p0dTrack->
Status = track->GetStatus();
709 p0dTrack->
Quality = track->GetQuality();
710 p0dTrack->
NDOF = track->GetNDOF();
711 p0dTrack->
Position = trackState->GetPosition();
712 p0dTrack->
PosVariance = trackState->GetPositionVariance();
713 p0dTrack->
Direction = trackState->GetDirection();
714 p0dTrack->
DirVariance = trackState->GetDirectionVariance();
715 p0dTrack->
EDeposit = trackState->GetEDeposit();
718 CountValidDimensions(p0dTrack->
PosVariance.Vect());
720 const ND::THandle<ND::THitSelection> trackHits = track->GetHits();
723 std::map< int, std::pair<int, float> > hitInfo = HitTruthInfo(trackHits);
724 std::map< int, std::pair< int, float > >::iterator parentID;
726 for(parentID = hitInfo.begin(); parentID != hitInfo.end(); ++parentID){
738 ND::THitSelection::const_iterator hit;
739 for (hit = trackHits->begin();
740 hit != trackHits->end();
743 ND::TGeometryId geomid = (*hit)->GetGeomId();
744 if (!ND::GeomId::P0D::IsP0D(geomid))
continue;
745 int p0dule = ND::TGeomInfo::P0D().GetBar(geomid).GetP0Dule();
746 int layer = ND::TGeomInfo::P0D().GetBar(geomid).GetLayer();
747 int bar = ND::TGeomInfo::P0D().GetBar(geomid).GetNumber();
751 if(bar < 4 || (layer == 0 && bar > 121) || (layer == 1 && bar > 129)){
757 const ND::TReconNodeContainer& nodeCont = track->GetNodes();
761 if (nodeCont.size() < 1)
return trackID;
763 ND::TReconNodeContainer::const_iterator node = nodeCont.begin();
764 ND::THandle<ND::TTrackState> nodeState = (*node)->GetState();
765 TVector3 frontPos = nodeState->GetPosition().Vect();
768 while(node != nodeCont.end()){
775 nodeState = (*node)->GetState();
777 p0dTrack->
Length += (frontPos - nodeState->GetPosition().Vect()).Mag();
778 frontPos = nodeState->GetPosition().Vect();
788 const ND::THandle<ND::TReconShower> shower,
789 bool saveHits =
true){
792 showerID.
id = fNShowers;
793 showerID.
type = ObjectID::kShower;
798 FillBaseObject(p0dShower, shower, saveHits);
807 const ND::TReconNodeContainer& nodeCont = shower->GetNodes();
808 ND::TReconNodeContainer::const_iterator node;
809 for (node = nodeCont.begin();
810 node != nodeCont.end();
812 ND::THandle<ND::TReconCluster> cluster = (*node)->GetObject();
813 ND280Verbose(
"Fill Cluster - Shower");
814 ObjectID clusterID = FillClusterObject(cluster, saveHits);
818 ND::THandle<ND::TShowerState> showerState = shower->GetState();
820 p0dShower->
Status = shower->GetStatus();
821 p0dShower->
Quality = shower->GetQuality();
822 p0dShower->
NDOF = shower->GetNDOF();
823 p0dShower->
Position = showerState->GetPosition();
824 p0dShower->
PosVariance = showerState->GetPositionVariance();
825 p0dShower->
Direction = showerState->GetDirection();
826 p0dShower->
DirVariance = showerState->GetDirectionVariance();
827 p0dShower->
EDeposit = showerState->GetEDeposit();
828 p0dShower->
Cone = showerState->GetCone()[0];
831 CountValidDimensions(p0dShower->
PosVariance.Vect());
833 p0dShower->
Width = 0.0;
838 const ND::THandle<ND::THitSelection> showerHits = shower->GetHits();
840 double totalCharge = 0.0;
845 std::map< int, std::pair<int, float> > hitInfo = HitTruthInfo(showerHits);
847 std::map< int, std::pair< int, float > >::iterator parentID;
848 for(parentID = hitInfo.begin(); parentID != hitInfo.end(); ++parentID){
856 ND::THitSelection::const_iterator hit;
858 for (hit = showerHits->begin();
859 hit != showerHits->end();
863 TVector3 diff = (*hit)->GetPosition() - p0dShower->
Position.Vect();
869 TVector3 perp = diff - para;
871 if ((*hit)->IsXHit()) {
880 float q = (*hit)->GetCharge();
883 p0dShower->
Width += q * perp.Mag();
885 avgLen += q * para.Mag();
886 avgLen2 += q * (para * para);
889 ND::TGeometryId geomid = (*hit)->GetGeomId();
890 if (!ND::GeomId::P0D::IsP0D(geomid)) {
continue;}
891 int p0dule = ND::TGeomInfo::P0D().GetBar(geomid).GetP0Dule();
892 int layer = ND::TGeomInfo::P0D().GetBar(geomid).GetLayer();
893 int bar = ND::TGeomInfo::P0D().GetBar(geomid).GetNumber();
898 if(bar < 4 || (layer == 0 && bar > 121) || (layer == 1 && bar > 129)){
905 p0dShower->
Width /= std::max(totalCharge,1.0);
907 avgLen /= std::max(totalCharge,1.0);
908 avgLen2 /= std::max(totalCharge,1.0);
909 double len2 = avgLen2 - avgLen*avgLen;
911 p0dShower->
Length = std::sqrt(std::max(0.0, len2));
918 const ND::THandle<ND::TReconCluster> cluster,
919 bool saveHits =
true){
922 clusterID.
id = fNClusters;
923 clusterID.
type = ObjectID::kCluster;
928 FillBaseObject(p0dCluster,cluster, saveHits);
931 p0dCluster->
EDeposit = cluster->GetEDeposit();
932 p0dCluster->
Position = cluster->GetPosition();
933 p0dCluster->
PosVariance = cluster->GetPositionVariance();
936 CountValidDimensions(p0dCluster->
PosVariance.Vect());
938 TMatrixF moments = cluster->GetMoments();
940 (moments.GetNrows() * moments.GetNcols()) ){
941 std::copy(moments.GetMatrixArray(),
942 moments.GetMatrixArray()+p0dCluster->
arraySize,
946 const ND::THandle<ND::THitSelection> clusterHits = cluster->GetHits();
949 std::map< int, std::pair<int, float> > hitInfo = HitTruthInfo(clusterHits);
950 std::map< int, std::pair< int, float > >::iterator parentID;
952 for(parentID = hitInfo.begin(); parentID != hitInfo.end(); ++parentID){
961 for (ND::THitSelection::const_iterator hit = clusterHits->begin();
962 hit != clusterHits->end(); ++hit){
963 TVector3 hitPosition = (*hit)->GetPosition();
965 ND::TGeomInfo::P0D().WaterFiducialDistance(hitPosition.X(),
976 const ND::THandle<ND::TReconNode> node,
979 short nodeID = fNNodes;
980 ND280Verbose(
"Fill Node");
983 new ((*fNodes)[fNNodes++])
TP0DNode;
988 ND::THandle<ND::TReconState> s1 = node->GetState();
990 #if BEFORE_oaEvent(9,0,0)
991 const ND::TMPositionDirectionState* posDirState = NULL;
993 dynamic_cast<const ND::TMPositionDirectionState*
>(ND::GetPointer(s1));
995 p0dNode->
Position = posDirState->GetPosition();
996 p0dNode->
PosVariance = posDirState->GetPositionVariance();
997 p0dNode->
Direction = posDirState->GetDirection();
998 p0dNode->
DirVariance = posDirState->GetDirectionVariance();
1000 p0dNode->
Position = GetPosition(s1);
1002 p0dNode->
Direction = ND::TPIDState::GetStateDirection(s1);
1003 p0dNode->
DirVariance = ND::TPIDState::GetStateDirectionVariance(s1);
1006 CountValidDimensions(p0dNode->
PosVariance.Vect());
1007 #if BEFORE_oaEvent(9,0,0)
1014 ND::THandle<ND::TReconBase> nodeObject = node->GetObject();
1016 ND::THandle<ND::TReconState> objState = nodeObject->GetState();
1018 #if BEFORE_oaEvent(9,0,0)
1019 const ND::TMEDepositState* eDepState = NULL;
1021 dynamic_cast<const ND::TMEDepositState*
>(ND::GetPointer(s1));
1023 p0dNode->
EDeposit = eDepState->GetEDeposit();
1026 p0dNode->
EDeposit = ND::TPIDState::GetStateEDeposit(objState);
1030 const ND::THandle<ND::THitSelection> nodeHits = nodeObject->GetHits();
1032 ND::THitSelection::const_iterator hit;
1034 for(hit = nodeHits->begin();
1035 hit != nodeHits->end(); ++hit){
1037 short hitId = FillHit(*hit);
1039 p0dNode->
Hits.push_back(hitId);
1043 std::map< int, std::pair<int, float> > hitInfo = HitTruthInfo(nodeHits);
1044 std::map< int, std::pair< int, float > >::iterator parentID;
1046 for(parentID = hitInfo.begin(); parentID != hitInfo.end(); ++parentID){
1060 if (!hit) {
return -1;}
1061 ND::THandle<ND::TSingleHit> sh = hit;
1062 if (!sh) {
return -1;}
1066 UInt_t chanIdUInt = sh->GetChannelId().AsUInt();
1067 std::map<UInt_t, short>::const_iterator mapIter;
1068 mapIter = fTempHitMap.find(chanIdUInt);
1069 if( mapIter != fTempHitMap.end() ){
1070 return mapIter->second;
1080 short hitID = fNHits;
1081 fTempHitMap[chanIdUInt] = hitID;
1084 new ((*fHits)[fNHits++])
TP0DHit;
1086 p0dHit->
ChanID = sh->GetChannelId().AsUInt();
1087 p0dHit->
GeomID = sh->GetGeomId().AsInt();
1088 p0dHit->
Charge = sh->GetCharge();
1089 p0dHit->
Time = sh->GetTime();
1094 std::map< int, std::pair<int, float> >
1097 std::map< int, std::pair<int, float> > result;
1100 for (ND::THitSelection::const_iterator hit = hits->begin();
1101 hit != hits->end(); hit++) {
1103 float hitCharge = (*hit)->GetCharge();
1104 std::map< int, int > hitCount;
1105 std::map< int, float > chargeShare;
1107 std::vector<ND::TG4VHit*> hitContribs = HitTruthInfo::GetHitTruthInfo(*hit);
1109 for (std::vector<ND::TG4VHit*>::const_iterator g4Hit = hitContribs.begin();
1110 g4Hit != hitContribs.end(); g4Hit++) {
1112 ND::TG4HitSegment* g4HitCast =
dynamic_cast<ND::TG4HitSegment*
>(*g4Hit);
1118 std::vector<int>::const_iterator trajIDIter;
1119 for (trajIDIter = g4HitCast->GetContributors().begin();
1120 trajIDIter != g4HitCast->GetContributors().end();
1123 hitCount[(*trajIDIter)]++;
1124 chargeShare[(*trajIDIter)] +=
1125 g4HitCast->GetEnergyDeposit() / g4HitCast->GetContributors().size();
1129 for (std::map< int, int >::const_iterator hC = hitCount.begin();
1130 hC != hitCount.end(); ++hC){
1133 if( (*hC).second > 0) {result[(*hC).first].first++;}
1138 float totalChargeShare = 0;
1139 for (std::map< int, float >::const_iterator cS = chargeShare.begin();
1140 cS != chargeShare.end(); ++cS){
1141 totalChargeShare += (*cS).second;
1145 for (std::map< int, float >::const_iterator cS = chargeShare.begin();
1146 cS != chargeShare.end(); ++cS){
1147 result[(*cS).first].second += hitCharge * (*cS).second / totalChargeShare;
1155 const ND::THandle<ND::THitSelection> hits){
1157 std::vector<int> result;
1159 for (ND::THitSelection::const_iterator hit = hits->begin();
1160 hit != hits->end(); hit++) {
1161 std::vector<ND::TG4VHit*> hitContribs = HitTruthInfo::GetHitTruthInfo(*hit);
1163 for (std::vector<ND::TG4VHit*>::const_iterator g4Hit = hitContribs.begin();
1164 g4Hit != hitContribs.end(); g4Hit++) {
1165 ND::TG4HitSegment* g4HitCast =
dynamic_cast<ND::TG4HitSegment*
>(*g4Hit);
1167 result.push_back(g4HitCast->GetPrimaryId());
1172 std::sort(result.begin(), result.end());
1175 std::vector<int>::iterator newEnd =
1176 std::unique(result.begin(), result.end());
1177 result.erase(newEnd, result.end());
1190 ND::TTFBChannelId chanID;
1191 ND::THitSelection::const_iterator hit;
1193 for(hit = hits->begin(); hit != hits->end(); ++hit){
1194 ND::THandle<ND::TSingleHit> sh = (*hit);
1196 chanID = ND::TTFBChannelId(sh->GetChannelId());
1197 if( chanID.IsValid() && chanID.IsTFBChannel() &&
1204 if(!chanID.IsValid() || !chanID.IsTFBChannel()){
1210 short cycle = (short) chanID.GetCapacitor();
1217 if (std::abs(posVar.X()) < 1E+6) {valid += 1;}
1218 if (std::abs(posVar.Y()) < 1E+6) {valid += 2;}
1219 if (std::abs(posVar.Z()) < 1E+6) {valid += 4;}
std::vector< short > Truth_HitCount
The number of THits that each truth trajectory contributed to.
virtual ObjectID FillTrackObject(const ND::THandle< ND::TReconTrack >, bool saveHits)
float Width
The 'width' of the shower, the extent perpendicular to the direction.
std::vector< short > Clusters
Holds internal Ids of Clusters pertinent to this algorithm result.
UInt_t GeomID
Geometry Id of the TSingleHit.
float Moments[arraySize]
Moments of the cluster stored as a flat 3x3 matrix.
std::vector< float > Truth_ChargeShare
The weighted reconstructed charge deposited by each truth trajectory.
TLorentzVector Position
Position of the TMPositionDirectionState of the corresponding ND::TReconNode.
Contains a summary of the reconstruction information in a TSingleHit.
short Parent
The internal Id of the parent algorithm result of this one.
virtual ObjectID FillShowerObject(const ND::THandle< ND::TReconShower >, bool saveHits)
std::vector< short > Tracks
Holds internal Ids of Tracks 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...
int NDOF
The Number of Degrees of Freedom in the reconstruction of the.
std::vector< short > Truth_HitCount
The number of THits that each truth trajectory contributed to.
float Fiducial
The distance to the outside of the fiducial volume.
std::vector< short > Vertices
Holds internal Ids of Vertices pertinent to this algorithm result.
ClassImp(ND::TBeamSummaryDataModule::TBeamSummaryData)
float Quality
The reported reconstruction 'quality' of the corresponding ND::TReconShower.
short ValidDimensions
Bit flag demarkating valid dimensions for this cluster's positon.
TVector3 DirVariance
Variance on the TP0DParticle::Direction of the TPIDState of the corresponding ND::TReconPID.
virtual ObjectID FillParticleObject(const ND::THandle< ND::TReconPID >, bool saveHits)
short id
An internal Id for each Reconstruction object.
std::string AlgorithmName
The name of the p0dRecon algorithm that created this object.
std::vector< std::vector< float > > realPIDValues
Holds the PID variable values from ND::TRealDatum stored in the TReconPID.
float EndDeposit
The deposited charge in the end p0dules.
TVector3 Direction
Direction of the TPIDState of the corresponding ND::TReconPID.
std::vector< short > Truth_HitCount
The number of THits that each truth trajectory contributed to.
Contains a summary of the reconstruction information in a TReconShower.
std::vector< int > Truth_TrajIDs
The vector of true trajectory IDs which contribute to the ND::THits which are constituents of this sh...
TVector3 Direction
Direction of the TShowerState of the corresponding ND::TReconShower.
float EndDeposit
The deposited charge in the end p0dules.
float Charge
The reconstructed charge of the corresponding TReconPID.
TLorentzVector PosVariance
Variance on the position of the TPIDState of the corresponding ND::TReconPID.
float Quality
The reported reconstruction 'quality' of the corresponding ND::TReconPID.
std::vector< std::string > integerPIDNames
Holds the variable names of ND::TIntegerDatum stored in the TReconPID.
float SideDeposit
The deposited charge in the side bars.
TVector3 DirVariance
Variance on the TP0DShower::Direction of the TShowerState of the corresponding ND::TReconShower.
TLorentzVector PosVariance
Variance on the position of the TTrackState of the corresponding ND::TReconTrack. ...
std::vector< std::string > realPIDNames
Holds the variable names of ND::TRealDatum stored in the TReconPID.
TVector3 DirVariance
Variance on the TP0DTrack::Direction of the TTrackState of the corresponding ND::TReconTrack.
int NDOF
The Number of Degrees of Freedom in the reconstruction of the.
int NDOF
The Number of Degrees of Freedom in the reconstruction of the corresponding ND::TReconShower.
virtual void InitializeModule()
Initialize Module, override if necessary.
virtual std::map< int, std::pair< int, float > > HitTruthInfo(const ND::THandle< ND::THitSelection >)
int Status
The reported Status of the corresponding ND::TReconPID.
std::vector< int > Truth_TrajIDs
The vector of true trajectory IDs which contribute to the ND::THits which are constituents of this ve...
TLorentzVector PosVariance
Variance on the position of the corresponding ND::TReconCluster.
std::vector< short > Hits
Holds internal Ids of Hits pertinent to this algorithm result.
std::vector< int > Truth_TrajIDs
The vector of true trajectory IDs which contribute to the ND::THits which are constituents of this ve...
TLorentzVector PosVariance
Variance on the position of the TShowerState of the corresponding ND::TReconShower.
std::vector< float > PID_weight
PID weights for each PID in TP0DParticle::PID.
Used to summarise the various reconstruction algorithm results that p0dRecon employs.
TVector3 Direction
Direction of the TTrackState of the corresponding ND::TReconTrack.
A summary of the reconstruction information in a TReconPID.
float SideDeposit
The deposited charge in the side bars.
TLorentzVector PosVariance
Variance on the position of the TMPositionDirectionState of the corresponding ND::TReconPID.
int Status
The reported Status of the corresponding ND::TReconShower.
short ValidDimensions
Bit flag demarkating valid dimensions for this track's position.
virtual ObjectID FillVertexObject(const ND::THandle< ND::TReconVertex >, bool saveHits)
float EDeposit
The total reconstructed energy deposit of the ND::TMEDepositState of the relevant ND::TReconNode...
virtual std::vector< int > HitTruthPrimaryInfo(const ND::THandle< ND::THitSelection >)
float Length
The length of the track calculated by summing over the distances.
std::vector< short > Truth_HitCount
The number of THits that each truth trajectory contributed to.
std::vector< int > Truth_PrimaryTrajIDs
The vector of primary true trajectory IDs which contribute to the ND::THits which are constituents of...
float SideDeposit
The deposited charge in the side bars.
virtual bool FillTree(ND::TND280Event &)
Fill all the stuff that goes in the output tree.
Contains a summary of the reconstruction information in a TReconVertex.
float Time
Reconstructed hit time from the corresponding TSingleHit.
Contains a summary of the reconstruction information in a TReconNode.
float Length
The RMS length of the shower, the extent parallel to the direction.
short ValidDimensions
Bit flag demarkating valid dimensions for this shower's position.
std::vector< float > Truth_ChargeShare
The weighted reconstructed charge deposited by each truth trajectory.
std::vector< short > Truth_HitCount
The number of THits that each truth trajectory contributed to.
static const int arraySize
Size of the TP0DCluster::Moments array.
std::vector< int > Truth_PrimaryTrajIDs
The vector of primary true trajectory IDs which contribute to the ND::THits which are constituents of...
std::vector< short > Hits
Holds internal Ids of Hits pertinent to this reconstruction node.
std::vector< int > Truth_PrimaryTrajIDs
The vector of primary true trajectory IDs which contribute to the ND::THits which are constituents of...
OType_t type
The reconstruction object type that this internal Id refers to.
std::vector< int > Truth_PrimaryTrajIDs
The vector of primary true trajectory IDs which contribute to the ND::THits which are constituents of...
virtual ObjectID FillClusterObject(const ND::THandle< ND::TReconCluster >, bool saveHits)
float EDeposit
The total reconstructed energy deposit of the corresponding ND::TReconTrack.
short ValidDimensions
Bit flag demarkating valid dimensions for this vertex's position.
float EndDeposit
The deposited charge in the end p0dules.
std::vector< short > Particles
Holds internal Ids of Particles pertinent to this algorithm result.
int NDOF
The Number of Degrees of Freedom in the reconstruction of the corresponding ND::TReconTrack.
std::string FullName
The name of the p0dRecon algorithm that corresponds to this.
std::vector< short > Truth_HitCount
The number of THits that each truth trajectory contributed to.
int Status
The reported Status of the corresponding ND::TReconTrack.
short ValidDimensions
Bit flag demarkating valid dimensions for this particle's position.
TLorentzVector PosVariance
Variance on the position of the TVertexState of the corresponding ND::TReconVertex.
Contains a summary of the reconstruction information in a TReconCluster. Contains a summary of the re...
std::vector< std::vector< short > > integerPIDValues
Holds the PID variable values from ND::TIntegerDatum stored in the TReconPID.
virtual Bool_t ProcessFirstEvent(ND::TND280Event &)
Is called after the first event is loaded in.
TP0DReconModule(const char *name="P0D", const char *title="P0D Recon Module")
TLorentzVector Position
Position of the TPIDState of the corresponding ND::TReconPID.
short FillHit(const ND::THandle< ND::THit >)
void FillBaseObject(T basePtr, ND::THandle< ND::TReconBase > baseObject, bool saveHits)
float Charge
Reconstructed hit charge without attenuation correction from the corresponding TSingleHit.
std::vector< short > Clusters
Holds internal Ids of Clusters pertinent to this reconstructed shower.
float EDeposit
The total reconstructed energy deposit of the corresponding ND::TReconShower.
short GetCycle(const ND::THandle< ND::THitSelection >)
float Quality
The reported reconstruction 'quality' of the corresponding ND::TReconTrack.
std::vector< int > Truth_TrajIDs
The vector of true trajectory IDs which contribute to the ND::THits which are constituents of this ve...
TLorentzVector Position
Position of the corresponding ND::TReconCluster.
std::vector< float > Truth_ChargeShare
The weighted reconstructed charge deposited by each truth trajectory.
TVector3 DirVariance
Variance on the TP0DNode::Direction of the TMPositionDirectionState of the corresponding ND::TReconNo...
std::vector< float > Truth_ChargeShare
The weighted reconstructed charge deposited by each truth trajectory.
std::vector< float > Truth_ChargeShare
The weighted reconstructed charge deposited by each truth trajectory.
virtual ObjectID FillReconObject(const ND::THandle< ND::TReconBase >, bool saveHits)
std::vector< int > Truth_TrajIDs
The vector of true trajectory IDs which contribute to the ND::THits which are constituents of this tr...
short UsedHitCluster
The internal Id of the cluster of hits which were used in a.
float Momentum
The reconstructed momentum of the corresponding TReconPID.
float Cone
The opening angle of the TShowerState cone of the corresponding TReconShower.
short CountValidDimensions(TVector3 posVar)
short UnusedHitCluster
The internal Id of the cluster of hits which were not used in a.
virtual short FillNode(const ND::THandle< ND::TReconNode >, bool saveHits)
TLorentzVector Position
Position of the TShowerState of the corresponding ND::TReconShower.
short NFiducialHits
The number of THits in the cluster which are within the fiducial volume.
virtual short FillAlgorithmResult(const ND::THandle< ND::TAlgorithmResult >, short)
std::vector< float > Truth_ChargeShare
The weighted reconstructed charge deposited by each truth trajectory.
TLorentzVector Position
Position of the TVertexState of the corresponding ND::TReconVertex.
float Quality
The reported reconstruction 'quality' of the corresponding ND::TReconVertex.
TLorentzVector Position
Position of the TTrackState of the corresponding ND::TReconTrack.
UInt_t ChanID
Channel Id of the TSingleHit.
virtual void InitializeBranches()
Initialize Branches. Don't do anything else in this function.
std::vector< short > AlgoResults
Holds internal Ids of daughter algorithm results to this one.
virtual ~TP0DReconModule()
int Status
The reported Status of the corresponding ND::TReconVertex.
short ValidDimensions
Bit flag demarkating valid dimensions for this node's position.
TVector3 Direction
Direction of the TMPositionDirectionState of the corresponding ND::TReconNode.
std::vector< short > PID
Potential PIDs (ND::TReconPID::ParticleId) matching with.
An internal Id and object type for each Reconstruction object.
std::vector< short > Showers
Holds internal Ids of Showers 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< int > Truth_TrajIDs
The vector of true trajectory IDs which contribute to the ND::THits which are constituents of this ve...
float EDeposit
The total reconstructed energy deposit of the corresponding ND::TReconCluster.