eventAnalysis  7.0-49-g0ac7482
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
TSmrdReconModule.cxx
Go to the documentation of this file.
1 #include <cmath>
2 #include <string>
3 
4 #include <TGeomInfo.hxx>
5 #include <TRecPackManager.hxx>
6 #include <TReconTrack.hxx>
7 #include <TTrackState.hxx>
8 
9 #include <TrackTruthInfo.hxx>
10 
11 #include "TSmrdReconModule.hxx"
12 
13 #include "TTFBChannelId.hxx"
14 #include "TTFBDigit.hxx"
15 
16 #include <TRealDatum.hxx>
17 
18 #include <TrackingUtils.hxx>
19 
24 
25 #define CVSTAG \
26  "\
27 $Name: 7.0$"
28 #define CVSID \
29  "\
30  $Id: eventAnalysis TSmrdReconModule.cxx,2024/03/20:09:46:11,Alexander_J_Finch,lapw.lancs.ac.uk $"
31 
32 ND::TSmrdReconModule::TSmrdReconModule(const char *name, const char *title) {
33  SetNameTitle(name, title);
34 
35  fIsEnabled = kTRUE;
36  fDescription = "SMRD Recon Output";
38  fCVSID = CVSID;
39 
40  fNSmrdReconHits = 0;
41  fSmrdReconHits = new TClonesArray("ND::TSmrdReconModule::TSmrdReconHit", 200);
42  fNSmrdIsoTracks = 0;
43  fSmrdIsoTracks = new TClonesArray("ND::TSmrdReconModule::TSmrdIsoTrack", 200);
44 }
45 
47 
48 Bool_t ND::TSmrdReconModule::ProcessFirstEvent(ND::TND280Event &event) {
49  return true;
50 }
51 
53 
55  fOutputTree->Branch("NSmrdReconHits", &fNSmrdReconHits, "NSmrdReconHits/I",
57  ->SetTitle("The number of SMRD TReconHits.");
58  fOutputTree->Branch("NSmrdIsoTracks", &fNSmrdIsoTracks, "NSmrdIsoTracks/I",
60  ->SetTitle("The SMRD TReconHits.");
61  fOutputTree->Branch("SmrdReconHits", &fSmrdReconHits, fBufferSize,
63  ->SetTitle("The number of SMRD isolated tracks.");
64  fOutputTree->Branch("SmrdIsoTracks", &fSmrdIsoTracks, fBufferSize,
66  ->SetTitle("The SMRD isolated tracks.");
67 }
68 
69 bool ND::TSmrdReconModule::FillTree(ND::TND280Event &event) {
70  fNSmrdReconHits = 0;
71  fSmrdReconHits->Clear();
72 
73  fNSmrdIsoTracks = 0;
74  fSmrdIsoTracks->Clear();
75 
76  ND::THandle<ND::TAlgorithmResult> SmrdResult = event.GetFit("smrdRecon");
77  ND::THandle<ND::THitSelection> smrdReconHitsMatched;
78  ND::THandle<ND::THitSelection> smrdReconHitsUnused;
79  ND::THandle<ND::THitSelection> smrdReconHitsUsed;
80  ND::THandle<ND::TReconObjectContainer> xyzReconTracks;
81 
82  if (SmrdResult) {
83  smrdReconHitsUnused = SmrdResult->GetHitSelection("unused");
84  smrdReconHitsMatched = SmrdResult->GetHitSelection("matchedSmrdReconHits");
85  smrdReconHitsUsed = SmrdResult->GetHitSelection("used");
86  xyzReconTracks = SmrdResult->GetResultsContainer("final");
87  }
88 
89  //----------------------------------------------------------------------------
90  // Fill hits information
91  //----------------------------------------------------------------------------
92  // smrdReconHitsUnused
93  if (smrdReconHitsUnused) {
94  for (ND::THitSelection::iterator h = smrdReconHitsUnused->begin();
95  h != smrdReconHitsUnused->end(); ++h) {
96  ND::THandle<ND::THit> hit = *h;
97  if (!hit) {
98  continue;
99  }
100 
101  // get hit contributors
102  // only deal with "fully-calibrated" two-sided hits
103  if ((*h)->GetContributorCount() != 2) {
104  ND280Warn("warning: more or less than two smrd single hits contributed"
105  << " to this TReconHit; skipping this TReconHit");
106  continue;
107  }
108 
109  //******************get two single hits-contributors
110  ND::THandle<ND::THit> contrhit1 = (*h)->GetContributor(0);
111  ND::THandle<ND::THit> contrhit2 = (*h)->GetContributor(1);
112 
113  if ((!contrhit1) || (!contrhit2)) {
114  ND280Warn("warning: failed get constituents for SMRD TRecon hit; skip "
115  << "this TReconHit");
116  continue;
117  }
118 
119  TSmrdReconHit *reconHit =
120  new ((*fSmrdReconHits)[fNSmrdReconHits++]) TSmrdReconHit;
121 
122  reconHit->Position = TLorentzVector(hit->GetPosition(), hit->GetTime());
123  reconHit->PositionUncertainty =
124  TLorentzVector(hit->GetUncertainty(), hit->GetTimeUncertainty());
125  reconHit->Charge = hit->GetCharge();
126 
127  reconHit->dZ = (*h)->GetPosition().Z() - contrhit1->GetPosition().Z();
128  reconHit->dT = contrhit1->GetTime() - contrhit2->GetTime();
129  reconHit->ContribCharge[0] = contrhit1->GetCharge();
130  reconHit->ContribCharge[1] = contrhit2->GetCharge();
131 
132  bool isTopWall = ND::TGeomInfo::SMRD().IsSMRDTopWall(hit);
133  bool isBottomWall = ND::TGeomInfo::SMRD().IsSMRDBottomWall(hit);
134  bool isRightWall = ND::TGeomInfo::SMRD().IsSMRDRightWall(hit);
135  bool isLeftWall = ND::TGeomInfo::SMRD().IsSMRDLeftWall(hit);
136 
137  if (isTopWall) {
138  reconHit->Wall = kTop;
139  }
140  if (isBottomWall) {
141  reconHit->Wall = kBottom;
142  }
143  if (isRightWall) {
144  reconHit->Wall = kRight;
145  }
146  if (isLeftWall) {
147  reconHit->Wall = kLeft;
148  }
149 
150  reconHit->Yoke = ND::TGeomInfo::SMRD().GetYokeRingNumber(hit);
151  reconHit->Layer = ND::TGeomInfo::SMRD().GetSMRDRingNumber(hit);
152  reconHit->Tower = ND::TGeomInfo::SMRD().GetSMRDTowerNumber(hit);
153  reconHit->Counter = ND::TGeomInfo::SMRD().GetSMRDScintNumber(hit);
154 
155  // fill tfb and rmm info
156  ND::TChannelId chan = contrhit1->GetChannelId();
157  ND::TTFBChannelId tfbid(chan);
158 
159  reconHit->RMM = tfbid.GetRMM();
160  reconHit->TFB = tfbid.GetTFB();
161 
162  reconHit->IsUsed = false;
163 
164  reconHit->IsInnerMatched = false;
165 
166  // should be always unmatched but let`s double check
167  if (smrdReconHitsMatched) {
168  if (std::find(smrdReconHitsMatched->begin(),
169  smrdReconHitsMatched->end(),
170  *h) != smrdReconHitsMatched->end()) {
171  reconHit->IsInnerMatched = true;
172  }
173  }
174  } // end of hits loop
175  } // end of if(smrdReconHitsUnused)
176 
177  // smrdReconHitsUsed
178  if (smrdReconHitsUsed) {
179  for (ND::THitSelection::iterator h = smrdReconHitsUsed->begin();
180  h != smrdReconHitsUsed->end(); h++) {
181  ND::THandle<ND::THit> hit = *h;
182  if (!hit) {
183  continue;
184  }
185 
186  // get hit contributors
187  // only deal with "fully-calibrated" two-sided hits
188  if ((*h)->GetContributorCount() != 2) {
189  ND280Warn("warning: more or less than two smrd single hits contributed"
190  << " to this TReconHit; skipping this TReconHit");
191  continue;
192  }
193 
194  //******************get two single hits-contributors
195  ND::THandle<ND::THit> contrhit1 = (*h)->GetContributor(0);
196  ND::THandle<ND::THit> contrhit2 = (*h)->GetContributor(1);
197 
198  if (!contrhit1 || !contrhit2) {
199  ND280Warn("warning: failed get constituents for SMRD TRecon hit; "
200  << "skip this TReconHit");
201  continue;
202  }
203 
204  TSmrdReconHit *reconHit =
205  new ((*fSmrdReconHits)[fNSmrdReconHits++]) TSmrdReconHit;
206 
207  reconHit->Position = TLorentzVector(hit->GetPosition(), hit->GetTime());
208  reconHit->PositionUncertainty =
209  TLorentzVector(hit->GetUncertainty(), hit->GetTimeUncertainty());
210  reconHit->Charge = hit->GetCharge();
211 
212  reconHit->dZ = (*h)->GetPosition().Z() - contrhit1->GetPosition().Z();
213  reconHit->dT = contrhit1->GetTime() - contrhit2->GetTime();
214 
215  reconHit->ContribCharge[0] = contrhit1->GetCharge();
216  reconHit->ContribCharge[1] = contrhit2->GetCharge();
217 
218  bool isTopWall = ND::TGeomInfo::SMRD().IsSMRDTopWall(hit);
219  bool isBottomWall = ND::TGeomInfo::SMRD().IsSMRDBottomWall(hit);
220  bool isRightWall = ND::TGeomInfo::SMRD().IsSMRDRightWall(hit);
221  bool isLeftWall = ND::TGeomInfo::SMRD().IsSMRDLeftWall(hit);
222 
223  if (isTopWall) {
224  reconHit->Wall = kTop;
225  }
226  if (isBottomWall) {
227  reconHit->Wall = kBottom;
228  }
229  if (isRightWall) {
230  reconHit->Wall = kRight;
231  }
232  if (isLeftWall) {
233  reconHit->Wall = kLeft;
234  }
235 
236  reconHit->Yoke = ND::TGeomInfo::SMRD().GetYokeRingNumber(hit);
237  reconHit->Layer = ND::TGeomInfo::SMRD().GetSMRDRingNumber(hit);
238  reconHit->Tower = ND::TGeomInfo::SMRD().GetSMRDTowerNumber(hit);
239  reconHit->Counter = ND::TGeomInfo::SMRD().GetSMRDScintNumber(hit);
240 
241  // fill tfb and rmm info
242  ND::TChannelId chan = contrhit1->GetChannelId();
243  ND::TTFBChannelId tfbid(chan);
244 
245  reconHit->RMM = tfbid.GetRMM();
246  reconHit->TFB = tfbid.GetTFB();
247 
248  reconHit->IsUsed = true;
249 
250  reconHit->IsInnerMatched = false;
251 
252  if (smrdReconHitsMatched) {
253  if (std::find(smrdReconHitsMatched->begin(),
254  smrdReconHitsMatched->end(),
255  *h) != smrdReconHitsMatched->end()) {
256  reconHit->IsInnerMatched = true;
257  }
258  }
259  } // end of hits loop
260  } // end of if(smrdReconHitsUsed)
261 
262  //----------------------------------------------------------------------------
263  // Fill tracks information
264  //----------------------------------------------------------------------------
265  if (xyzReconTracks) {
266  bool isMC = event.GetContext().IsMC();
267 
268  for (ND::TReconObjectContainer::iterator t = xyzReconTracks->begin();
269  t != xyzReconTracks->end(); t++) {
270  ND::THandle<ND::TReconTrack> track = *t;
271  if (!track) {
272  continue;
273  }
274 
275  ND::THandle<ND::TTrackState> trackState = track->GetState();
276  if (!trackState) {
277  continue;
278  }
279 
280  TSmrdIsoTrack *isoTrack =
281  new ((*fSmrdIsoTracks)[fNSmrdIsoTracks++]) TSmrdIsoTrack;
282 
283  ND::TReconNodeContainer &nodes = track->GetNodes();
284 
285  ND::THandle<ND::TTrackState> frontState =
286  TrackingUtils::GetFirstState(*track);
287  if (!frontState) {
288  continue;
289  }
290 
291  ND::THandle<ND::TTrackState> backState =
292  TrackingUtils::GetLastState(*track);
293  if (!backState) {
294  continue;
295  }
296 
297  ND::THandle<ND::THitSelection> hits = track->GetHits();
298 
299  if (!hits) {
300  continue;
301  }
302 
303  isoTrack->AlgorithmName = track->GetAlgorithmName();
304  isoTrack->Chi2 = track->GetQuality();
305 
306  // some of all contributed hits charges
307  isoTrack->EDeposit = -9999.0;
308  ND::THandle<ND::TRealDatum> totalCharge =
309  track->Get<ND::TRealDatum>("totalCharge");
310  if (totalCharge) {
311  isoTrack->EDeposit =
312  track->Get<ND::TRealDatum>("totalCharge")->GetValue();
313  }
314 
315  // hits averaged time
316  isoTrack->avgtime = -9999.0;
317  ND::THandle<ND::TRealDatum> smrdTimeRD =
318  track->Get<ND::TRealDatum>("averageHitTime");
319  if (smrdTimeRD) {
320  isoTrack->avgtime =
321  track->Get<ND::TRealDatum>("averageHitTime")->GetValue();
322  }
323 
324  isoTrack->NHits = hits->size();
325  isoTrack->NNodes = nodes.size();
326  isoTrack->Status = track->CheckStatus(track->kSuccess);
327  isoTrack->NDOF = track->GetNDOF();
328  isoTrack->UniqueID = track->GetUniqueID();
329 
330  // Check the Kalman refitting status
331  std::string name("RECPACK_KalmanFilter");
332  if ((track->GetAlgorithmName().find(name) != std::string::npos) &&
333  (track->CheckStatus(track->kSuccess))) {
334  isoTrack->KalmanStatus = 1;
335  } else {
336  isoTrack->KalmanStatus = 0;
337  }
338 
339  isoTrack->FrontPos = frontState->GetPosition();
340  isoTrack->FrontPosVariance = frontState->GetPositionVariance();
341 
342  isoTrack->BackPos = backState->GetPosition();
343  isoTrack->BackPosVariance = backState->GetPositionVariance();
344 
345  TVector3 backpos = backState->GetPosition().Vect();
346  TVector3 frontpos = frontState->GetPosition().Vect();
347 
348  // isoTrack->Direction = (backpos - frontpos).Unit();
349  isoTrack->Direction = trackState->GetDirection();
350  isoTrack->DirectionVariance = trackState->GetDirectionVariance();
351 
352  // Calculate length of the track assuming straight line
353  TVector3 diff = backpos - frontpos;
354  isoTrack->Range = diff.Mag();
355 
356  // Angles...
357  isoTrack->ThetaAngle = trackState->GetDirection().Theta();
358  isoTrack->PhiAngle = trackState->GetDirection().Phi();
359 
360  // Set truth info
361  int trueId = -999;
362  TLorentzVector trueInitPos(-9999, -9999, -9999, -9999);
363  TLorentzVector trueFinalPos(-9999, -9999, -9999, -9999);
364  TLorentzVector trueInitMom(-9999, -9999, -9999, -9999);
365  int truePDG = 0;
366  int trueParentId = -999;
367  double truePurity = -9999.0;
368  double trueEff = -9999.0;
369 
370  if (isMC) {
371  trueId = TrackTruthInfo::GetG4TrajIDHits(*hits, trueEff, truePurity);
372 
373  ND::THandle<ND::TG4TrajectoryContainer> trajectoryContainer =
374  event.Get<ND::TG4TrajectoryContainer>("truth/G4Trajectories");
375  ND::THandle<ND::TG4Trajectory> g4traj(0);
376  if (trajectoryContainer)
377  g4traj = trajectoryContainer->GetTrajectory(trueId);
378 
379  if (g4traj) {
380  trueInitPos = g4traj->GetInitialPosition();
381  trueFinalPos = g4traj->GetFinalPosition();
382  trueInitMom = g4traj->GetInitialMomentum();
383  truePDG = g4traj->GetPDGEncoding();
384  trueParentId = g4traj->GetParentId();
385  }
386  }
387 
388  isoTrack->TrueInitPos = trueInitPos;
389 
390  gGeoManager->FindNode(trueInitPos.X(), trueInitPos.Y(), trueInitPos.Z());
391  gGeoManager->GetCurrentNodeId();
392  isoTrack->TrueInitDet =
393  eventAnalysisEnums::PathToSubdetector(gGeoManager->GetPath());
394 
395  isoTrack->TrueFinalPos = trueFinalPos;
396 
397  gGeoManager->FindNode(trueFinalPos.X(), trueFinalPos.Y(),
398  trueFinalPos.Z());
399  gGeoManager->GetCurrentNodeId();
400  isoTrack->TrueFinalDet =
401  eventAnalysisEnums::PathToSubdetector(gGeoManager->GetPath());
402 
403  isoTrack->TrueInitMom = trueInitMom;
404  isoTrack->TrueId = trueId;
405  isoTrack->TruePDG = truePDG;
406  isoTrack->TrueParentId = trueParentId;
407  // isoTrack->TrueParentPDG =;
408  isoTrack->TrueHitPurity = truePurity;
409  isoTrack->TrueHitEff = trueEff;
410 
411  } // end of tracks loop
412  } // end of if(xyzTracks)
413  return true;
414 }
TLorentzVector FrontPosVariance
Variance on the position of the &#39;first&#39; TTrackState of the corresponding ND::TReconTrack.
#define CVSID
double dT
The difference between the reconstructed ND::THit times between the two contributors.
double avgtime
Average hit time of the corresponding ND::TReconTrack.
virtual void InitializeModule()
Initialize Module, override if necessary.
UInt_t UniqueID
The Unique ID of the corresponding ND::TReconTrack, used for global-subdetector matching.
int NHits
Number of ND::THits which are associated with the corresponding ND::TReconTrack.
int Status
The reported Status of the corresponding ND::TReconTrack.
double EDeposit
The total reconstructed charge of the corresponding ND::TReconTrack.
TLorentzVector PositionUncertainty
The uncertainty on the reconstructed 4-position of the corresponding double ended ND::THit...
ClassImp(ND::TBeamSummaryDataModule::TBeamSummaryData)
Int_t fNSmrdReconHits
The number of SMRD TReconHits.
std::string fDescription
A longish descrition of the analysis.
Both-sided SMRD TReconHit that isn&#39;t included in any reconstructed track.
virtual bool FillTree(ND::TND280Event &)
Fill all the stuff that goes in the output tree.
TVector3 DirectionVariance
Variance on the direction the TTrackState which is the state of the corresponding ND::TReconTrack...
virtual Bool_t ProcessFirstEvent(ND::TND280Event &event)
Is called after the first event is loaded in.
TLorentzVector TrueInitMom
For MC events: The true initial momentum of the corresponding ND::TG4Trajectory.
double PhiAngle
Polar coordinate phi of the TSmrdIsoTrack::Direction.
double TrueHitPurity
For MC events: The &#39;cleanliness&#39; of the ND::THits which make up the corresponding ND::TReconTrack...
double dZ
The difference in Z between the combined ND::THit(double ended bars) and the first contributor ND::T...
TLorentzVector TrueFinalPos
For MC events: The true final position of the corresponding ND::TG4Trajectory.
int TrueInitDet
For MC events: The subdetector in which TSmrdIsoTrack::TrueInitPos lies.
bool IsUsed
Designates if the corresponding ND::THit was used in a reconstructed object.
TLorentzVector TrueInitPos
For MC events: The true initial position of the corresponding ND::TG4Trajectory.
Int_t fBufferSize
Buffer Size for TBranch.
int Tower
The SMRD tower number.
int TrueFinalDet
For MC events: The subdetector in which TSmrdIsoTrack::TrueFinalPos lies.
int KalmanStatus
Kalman filter refit result for the corresponding ND::TReconTrack.
Int_t fNSmrdIsoTracks
The number of SMRD isolated tracks.
std::string fCVSID
Defined if an official tagged version.
TClonesArray * fSmrdReconHits
The SMRD TReconHits.
TLorentzVector BackPosVariance
Variance on the position of the &#39;last&#39; TTrackState of the corresponding ND::TReconTrack.
int NNodes
Number of TReconNodes which are constituents of the corresponding ND::TReconTrack.
UInt_t RMM
The RMM Id of the channel corresponding to the first contributor hit.
#define CVSTAG
void SetNameTitle(char const *name, char const *title)
double Range
The spacial distance between TSmrdIsoTrack::FrontPos and TSmrdIsoTrack::BackPos.
double ThetaAngle
Polar coordinate theta of the TSmrdIsoTrack::Direction.
UInt_t TFB
The TFB Id of the channel corresponding to the first contributor hit.
TLorentzVector Position
The reconstructed 4-position of the corresponding double ended ND::THit.
double TrueHitEff
For MC events: The &#39;completeness&#39; of the ND::THits which make up the corresponding ND::TReconTrack...
int NDOF
The Number of Degrees of Freedom in the reconstruction of the corresponding ND::TReconTrack.
double Chi2
The reported reconstruction &#39;quality&#39; of the corresponding ND::TReconTrack.
TLorentzVector FrontPos
Position of the &#39;first&#39; TTrackState of the corresponding ND::TReconTrack.
double ContribCharge[2]
The reconstructed charges from each contributor of the double ended bar.
TSmrdReconModule(const char *name="SMRD", const char *title="SMRD Recon Module")
int Wall
The SMRD wall in which this the corresponding ND::THit resides. Is assigned a value from TSmrdReconMo...
Int_t fSplitLevel
Split Level for TBranch.
std::string AlgorithmName
Name of the reconstruction algorithm.
int TrueId
For MC events: The Id of the corresponding ND::TG4Trajectory.
int TruePDG
For MC events: The PDG code of the true particle.
std::string fCVSTagName
Defined if an official tagged version.
double Charge
The reconstructed charge of the corresponding double ended ND::THit.
int Counter
The SMRD scintillator number.
ESubdetector PathToSubdetector(const std::string path)
TVector3 Direction
Direction of the TTrackState which is the state of the corresponding ND::TReconTrack.
bool IsInnerMatched
Designates if the corresponding ND::THit was matched.
int TrueParentId
For MC events: The Id of the true trajectory&#39;s parent ND::TG4Trajectory.
TLorentzVector BackPos
Position of the &#39;last&#39; TTrackState of the corresponding ND::TReconTrack.
virtual void InitializeBranches()
Initialize Branches. Don&#39;t do anything else in this function.
TClonesArray * fSmrdIsoTracks
The SMRD isolated tracks.

Package Summary
Package Name: eventAnalysis
Package Version: 7.0-49-g0ac7482
Package Manager:

Generated on Mon Mar 25 2024 14:43:59 for eventAnalysis by doxygen 1.8.5