FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PixelFindTracks.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 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  ********************************************************************************/
8 /*
9  * PixelFindTracks.cxx
10  *
11  * Created on: 23.02.2016
12  * Author: R. Karabowicz
13  */
14 
15 #include "PixelFindTracks.h"
16 
17 #include "PixelDigiPar.h"
18 #include "PixelHit.h"
19 #include "PixelTrack.h"
20 
21 // Includes from base
22 #include "FairLogger.h"
23 #include "FairRootManager.h"
24 #include "FairRun.h" // for FairRun
25 #include "FairRuntimeDb.h"
26 
27 // Includes from ROOT
28 #include <TClonesArray.h>
29 #include <TH2.h> // for TH2F
30 #include <TList.h> // for TList
31 #include <TMathBase.h> // for Abs
32 
34  : PixelFindTracks("Pixel Track Finder", 0)
35 {}
36 
38  : PixelFindTracks("Pixel Track Finder", iVerbose)
39 {}
40 
41 PixelFindTracks::PixelFindTracks(const char* name, Int_t iVerbose)
42  : FairTask(name, iVerbose)
43  , fDigiPar(nullptr)
44  , fHits(nullptr)
45  , fTracks(nullptr)
46  , fTNofEvents(0)
47  , fNHits(0)
48  , fTNofHits(0)
49  , fNTracks(0)
50  , fTNofTracks(0)
51  , fhDist2D(nullptr)
52 {
53  Reset();
54 }
55 
57 {
58  Reset();
59  delete fDigiPar;
60  if (fTracks) {
61  fTracks->Delete();
62  delete fTracks;
63  }
64 }
65 
66 void PixelFindTracks::Exec(Option_t* /*opt*/)
67 {
68  Reset();
69 
70  fNHits = fHits->GetEntriesFast();
71 
72  LOG(debug) << "PixelFindTracks::Exec() EVENT " << fTNofEvents << " with " << fNHits << " HITS";
73 
74  PixelHit* curHit1;
75  PixelHit* curHit2;
76  PixelHit* curHit3;
77 
78  Double_t parX0 = 0.;
79  Double_t parY0 = 0.;
80  Double_t parAX = 0.;
81  Double_t parAY = 0.;
82  Double_t expX = 0.;
83  Double_t expY = 0.;
84 
85  for (Int_t ihit1 = 0; ihit1 < fNHits; ihit1++) {
86  curHit1 = static_cast<PixelHit*>(fHits->At(ihit1));
87  LOG(debug) << "hit1 at " << curHit1->GetX() << " , " << curHit1->GetY() << " , " << curHit1->GetZ() << " / "
88  << curHit1->GetDetectorID();
89  if ((curHit1->GetDetectorID()) / 256 != 1)
90  continue;
91  for (Int_t ihit2 = 0; ihit2 < fNHits; ihit2++) {
92  curHit2 = static_cast<PixelHit*>(fHits->At(ihit2));
93  LOG(debug) << "hit2 at " << curHit2->GetX() << " , " << curHit2->GetY() << " , " << curHit2->GetZ() << " / "
94  << curHit2->GetDetectorID();
95  if ((curHit2->GetDetectorID()) / 256 != 2)
96  continue;
97 
98  parAX = (curHit2->GetX() - curHit1->GetX()) / (curHit2->GetZ() - curHit1->GetZ());
99  parAY = (curHit2->GetY() - curHit1->GetY()) / (curHit2->GetZ() - curHit1->GetZ());
100  parX0 = curHit1->GetX() - parAX * curHit1->GetZ();
101  parY0 = curHit1->GetY() - parAY * curHit1->GetZ();
102 
103  for (Int_t ihit3 = 0; ihit3 < fNHits; ihit3++) {
104  curHit3 = static_cast<PixelHit*>(fHits->At(ihit3));
105  LOG(debug) << "hit3 at " << curHit3->GetX() << " , " << curHit3->GetY() << " , " << curHit3->GetZ()
106  << " / " << curHit3->GetDetectorID();
107  if ((curHit3->GetDetectorID()) / 256 != 3)
108  continue;
109  expX = parX0 + parAX * curHit3->GetZ();
110  expY = parY0 + parAY * curHit3->GetZ();
111 
112  fhDist2D->Fill(expX - curHit3->GetX(), expY - curHit3->GetY());
113 
114  if (TMath::Abs(expX - curHit3->GetX()) < 0.03 && TMath::Abs(expY - curHit3->GetY()) < 0.03) {
115  LOG(debug) << "should create track...";
116  PixelTrack* tempTrack =
117  new ((*fTracks)[fNTracks]) PixelTrack(parX0, parAX, parY0, parAY, 0., 0., 0., 0.);
118  tempTrack->AddHitIndex(ihit1);
119  tempTrack->AddHitIndex(ihit2);
120  tempTrack->AddHitIndex(ihit3);
121  LOG(debug) << "--> " << fNTracks;
122  fNTracks++;
123  }
124  // LOG(debug) << ">>>>>> " << curHit3->GetX() << " / " << curHit3->GetY();
125  // LOG(debug) << " " << expX << " / " << expY;
126  }
127  }
128  }
129 
130  fTNofEvents += 1;
131  fTNofHits += fNHits;
132  fTNofTracks += fNTracks;
133 }
134 
135 void PixelFindTracks::SetParContainers()
136 {
137  // Get run and runtime database
138  FairRun* run = FairRun::Instance();
139  if (!run)
140  LOG(fatal) << "No analysis run";
141 
142  FairRuntimeDb* db = run->GetRuntimeDb();
143  if (!db)
144  LOG(fatal) << "No runtime database";
145 
146  // Get GEM digitisation parameter container
147  fDigiPar = static_cast<PixelDigiPar*>(db->getContainer("PixelDigiParameters"));
148 }
149 
150 void PixelFindTracks::GetParList(TList* tempList)
151 {
152  fDigiPar = new PixelDigiPar("PixelDigiParameters");
153  tempList->Add(fDigiPar);
154 
155  return;
156 }
157 
158 void PixelFindTracks::InitMQ(TList* tempList)
159 {
160  LOG(info) << "********************************************** PixelFindTracks::InitMQ()";
161  fDigiPar = (PixelDigiPar*)tempList->FindObject("PixelDigiParameters");
162 
163  fTracks = new TClonesArray("PixelTrack", 10000);
164  fhDist2D = new TH2F("fhDist2D", "Distance between hit and expected track", 400, -1., 1., 400, -1., 1.);
165 
166  return;
167 }
168 
169 void PixelFindTracks::ExecMQ(TList* inputList, TList* outputList)
170 {
171  // LOG(info) << "********************************************** PixelFindTracks::ExecMQ(" << inputList->GetName()
172  // << "," << outputList->GetName() << "), Event " << fTNofEvents; LOG(info) <<
173  // "********************************************** PixelFindTracks::ExecMQ(), Event " << fTNofEvents; LOG(info) <<
174  // "t" << FairLogger::flush;
175  fHits = (TClonesArray*)inputList->FindObject("PixelHits");
176  outputList->Add(fTracks);
177  Exec("");
178  return;
179 }
180 
181 InitStatus PixelFindTracks::Init()
182 {
183  // Get input array
185 
186  if (!ioman)
187  LOG(fatal) << "No FairRootManager";
188  fHits = static_cast<TClonesArray*>(ioman->GetObject("PixelHits"));
189 
190  if (!fHits)
191  LOG(warn) << "PixelFindTracks::Init() No input PixelHit array!";
192 
193  // Register output array PixelHit
194  fTracks = new TClonesArray("PixelTrack", 10000);
195  ioman->Register("PixelTracks", "Pixel", fTracks, kTRUE);
196 
197  fhDist2D = new TH2F("fhDist2D", "Distance between hit and expected track", 400, -1., 1., 400, -1., 1.);
198 
199  return kSUCCESS;
200 }
201 
202 InitStatus PixelFindTracks::ReInit() { return kSUCCESS; }
203 
204 void PixelFindTracks::Reset()
205 {
206  fNTracks = fNHits = 0;
207  if (fTracks)
208  fTracks->Clear();
209 }
210 
211 void PixelFindTracks::Finish()
212 {
213  if (fTracks)
214  fTracks->Delete();
215 
216  fhDist2D->Draw("colz");
217 
218  LOG(info) << "-------------------- " << fName.Data() << " : Summary ------------------------";
219  LOG(info) << " Events: " << fTNofEvents;
220  LOG(info) << " Hits: " << fTNofHits << " ( "
221  << static_cast<Double_t>(fTNofHits) / (static_cast<Double_t>(fTNofEvents)) << " per event )";
222  LOG(info) << " Tracks: " << fTNofTracks << " ( "
223  << static_cast<Double_t>(fTNofTracks) / (static_cast<Double_t>(fTNofEvents)) << " per event )";
224  LOG(info) << "---------------------------------------------------------------------";
225 }
226 
list of container factories
Definition: FairRuntimeDb.h:24
Double_t GetZ() const
Definition: FairHit.h:50
void AddHitIndex(Int_t hitIndex)
Definition: PixelTrack.h:64
InitStatus
Definition: FairTask.h:33
virtual ~PixelFindTracks()
virtual void Exec(Option_t *opt)
static FairRun * Instance()
Definition: FairRun.cxx:31
virtual void GetParList(TList *tempList)
static FairRootManager * Instance()
ClassImp(FairEventBuilder)
Double_t GetX() const
Definition: FairHit.h:48
Digitization Parameter Class for Pixel detector.
Definition: PixelDigiPar.h:24
TObject * GetObject(const char *BrName)
FairParSet * getContainer(const Text_t *)
Int_t GetDetectorID() const
Definition: FairHit.h:47
virtual void InitMQ(TList *tempList)
FairRuntimeDb * GetRuntimeDb(void)
Definition: FairRun.h:80
Double_t GetY() const
Definition: FairHit.h:49
void Register(const char *name, const char *Foldername, TNamed *obj, Bool_t toFile)
virtual void ExecMQ(TList *inputList, TList *outputList)