FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairTutPropTrackFinder.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2020 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
9 
10 #include "FairLogger.h" // for FairLogger, MESSAGE_ORIGIN
11 #include "FairRootManager.h" // for FairRootManager
12 #include "FairTutPropHit.h" // for FairTutPropHit
13 #include "FairTutPropTrack.h" // for FairTutPropTrack
14 
15 #include <TClonesArray.h> // for TClonesArray
16 #include <TRandom.h> // for TRandom, gRandom
17 #include <TVector3.h> // for TVector3
18 
20  : FairTask("FairTutPropTrackFinder")
21  , fHitsArray1Name("FairTutPropHits")
22  , fHitsArray2Name("FairTutPropHits2")
23  , fHitsArray1(nullptr)
24  , fHitsArray2(nullptr)
25  , fTracksArray(new TClonesArray("FairTutPropTrack", 100))
26 {
27  LOG(debug) << "Default Constructor of FairTutPropTrackFinder";
28 }
29 
31 {
32  LOG(debug) << "Destructor of FairTutPropTrackFinder";
33  fTracksArray->Delete();
34  delete fTracksArray;
35 }
36 
38 {
39  LOG(debug) << "SetParContainers of FairTutPropTrackFinder";
40  // Load all necessary parameter containers from the runtime data base
41  /*
42  FairRunAna* ana = FairRunAna::Instance();
43  FairRuntimeDb* rtdb=ana->GetRuntimeDb();
44 
45  <FairTutPropTrackFinderDataMember> = (<ClassPointer>*)
46  (rtdb->getContainer("<ContainerName>"));
47  */
48 }
49 
51 {
52  LOG(debug) << "Initilization of FairTutPropTrackFinder";
53 
54  // Get a handle from the IO manager
56 
57  // Get a pointer to the previous already existing data level
58  fHitsArray1 = static_cast<TClonesArray*>(ioman->GetObject(fHitsArray1Name.data()));
59  fHitsArray2 = static_cast<TClonesArray*>(ioman->GetObject(fHitsArray2Name.data()));
60  if (!fHitsArray1 || !fHitsArray2) {
61  LOG(error) << "No InputData array!";
62  LOG(error) << "FairTutPropTrackFinder will be inactive";
63  return kERROR;
64  }
65 
66  // Create the TClonesArray for the output data and register
67  // it in the IO manager
68  ioman->Register("FairTutPropTracks", "TutProp", fTracksArray, kTRUE);
69 
70  // Do whatever else is needed at the initilization stage
71  // Create histograms to be filled
72  // initialize variables
73 
74  return kSUCCESS;
75 }
76 
78 {
79  LOG(debug) << "Reinitilization of FairTutPropTrackFinder";
80  return kSUCCESS;
81 }
82 
83 void FairTutPropTrackFinder::Exec(Option_t* /*option*/)
84 {
85  fTracksArray->Delete();
86 
87  std::map<int, int> trackNofHitsMap;
88 
89  int nofHits1 = fHitsArray1->GetEntries();
90  int nofHits2 = fHitsArray2->GetEntries();
91 
92  for (int ihit1 = 0; ihit1 < nofHits1; ihit1++) {
93  FairTutPropHit* hit1 = static_cast<FairTutPropHit*>(fHitsArray1->At(ihit1));
94  auto trackFromMap = trackNofHitsMap.find(hit1->GetTrackID());
95  if (trackFromMap != trackNofHitsMap.end()) {
96  trackFromMap->second = trackFromMap->second + 1;
97  } else {
98  trackNofHitsMap.insert(std::pair<int, int>{hit1->GetTrackID(), 1});
99  }
100  }
101  for (int ihit2 = 0; ihit2 < nofHits2; ihit2++) {
102  FairTutPropHit* hit2 = static_cast<FairTutPropHit*>(fHitsArray2->At(ihit2));
103  auto trackFromMap = trackNofHitsMap.find(hit2->GetTrackID());
104  if (trackFromMap != trackNofHitsMap.end()) {
105  trackFromMap->second = trackFromMap->second + 1;
106  } else {
107  trackNofHitsMap.insert(std::pair<int, int>{hit2->GetTrackID(), 2});
108  }
109  }
110 
111  std::map<int, int>::iterator it;
112 
113  for (it = trackNofHitsMap.begin(); it != trackNofHitsMap.end(); it++) {
114  if (it->second < 3) { // make a cut on the number of hits: 3
115  continue;
116  }
117 
118  bool trackCreated = false;
119  for (int ihit1 = 0; ihit1 < nofHits1; ihit1++) {
120  FairTutPropHit* hit1 = static_cast<FairTutPropHit*>(fHitsArray1->At(ihit1));
121  if (it->first != hit1->GetTrackID())
122  continue;
123  std::vector<std::pair<int, int>> trackHits;
124  for (int jhit1 = 0; jhit1 < nofHits1; jhit1++) {
125  FairTutPropHit* hit1Ind = static_cast<FairTutPropHit*>(fHitsArray1->At(jhit1));
126  if (hit1Ind->GetTrackID() == hit1->GetTrackID())
127  trackHits.push_back(std::make_pair(1, jhit1));
128  }
129  for (int jhit2 = 0; jhit2 < nofHits2; jhit2++) {
130  FairTutPropHit* hit2Ind = static_cast<FairTutPropHit*>(fHitsArray2->At(jhit2));
131  if (hit2Ind->GetTrackID() == hit1->GetTrackID())
132  trackHits.push_back(std::make_pair(2, jhit2));
133  }
134  FairTrackParP firstTrackPar(TVector3(hit1->GetX(), hit1->GetY(), hit1->GetZ()),
135  TVector3(hit1->GetPx(), hit1->GetPy(), hit1->GetPz()),
136  TVector3(hit1->GetDx(), hit1->GetDy(), hit1->GetDz()),
137  TVector3(hit1->GetDPx(), hit1->GetDPy(), hit1->GetDPz()),
138  hit1->GetCharge(),
139  TVector3(0., 0., hit1->GetZ()),
140  TVector3(1., 0., 0.),
141  TVector3(0., 1., 0.));
142  new ((*fTracksArray)[fTracksArray->GetEntries()])
143  FairTutPropTrack(hit1->GetPdgCode(), firstTrackPar, trackHits, hit1->GetTrackID());
144  trackCreated = true;
145  break;
146  }
147  if (trackCreated)
148  continue;
149  for (int ihit2 = 0; ihit2 < nofHits2; ihit2++) {
150  FairTutPropHit* hit2 = static_cast<FairTutPropHit*>(fHitsArray2->At(ihit2));
151  if (it->first != hit2->GetTrackID())
152  continue;
153  std::vector<std::pair<int, int>> trackHits;
154  for (int jhit1 = 0; jhit1 < nofHits1; jhit1++) {
155  FairTutPropHit* hit1Ind = static_cast<FairTutPropHit*>(fHitsArray1->At(jhit1));
156  if (hit1Ind->GetTrackID() == hit2->GetTrackID())
157  trackHits.push_back(std::make_pair(1, jhit1));
158  }
159  for (int jhit2 = 0; jhit2 < nofHits2; jhit2++) {
160  FairTutPropHit* hit2Ind = static_cast<FairTutPropHit*>(fHitsArray2->At(jhit2));
161  if (hit2Ind->GetTrackID() == hit2->GetTrackID())
162  trackHits.push_back(std::make_pair(2, jhit2));
163  }
164  FairTrackParP firstTrackPar(TVector3(hit2->GetX(), hit2->GetY(), hit2->GetZ()),
165  TVector3(hit2->GetPx(), hit2->GetPy(), hit2->GetPz()),
166  TVector3(hit2->GetDx(), hit2->GetDy(), hit2->GetDz()),
167  TVector3(hit2->GetDPx(), hit2->GetDPy(), hit2->GetDPz()),
168  hit2->GetCharge(),
169  TVector3(0., 0., hit2->GetZ()),
170  TVector3(1., 0., 0.),
171  TVector3(0., 1., 0.));
172  new ((*fTracksArray)[fTracksArray->GetEntries()])
173  FairTutPropTrack(hit2->GetPdgCode(), firstTrackPar, trackHits, hit2->GetTrackID());
174  trackCreated = true;
175  break;
176  }
177 
178  }
179 }
180 
181 void FairTutPropTrackFinder::Finish() { LOG(debug) << "Finish of FairTutPropTrackFinder"; }
182 
Double_t GetDz() const
Definition: FairHit.h:44
Double_t GetZ() const
Definition: FairHit.h:50
InitStatus
Definition: FairTask.h:33
static FairRootManager * Instance()
virtual void Exec(Option_t *opt)
ClassImp(FairEventBuilder)
Double_t GetX() const
Definition: FairHit.h:48
TObject * GetObject(const char *BrName)
Double_t GetDy() const
Definition: FairHit.h:43
Double_t GetY() const
Definition: FairHit.h:49
void Register(const char *name, const char *Foldername, TNamed *obj, Bool_t toFile)
Double_t GetDx() const
Definition: FairHit.h:42
double GetCharge()