FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PixelAltFindHits.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  * PixelAltFindHits.cxx
10  *
11  * Created on: 18.02.2016
12  * Author: R. Karabowicz
13  */
14 
15 #include "PixelAltFindHits.h"
16 
17 // Includes from base
18 #include "FairLogger.h"
19 #include "FairRootManager.h"
20 #include "FairRun.h"
21 #include "FairRuntimeDb.h"
22 
23 // Includes from ROOT
24 #include "PixelDigi.h"
25 #include "PixelDigiPar.h"
26 #include "PixelHit.h"
27 
28 #include <TClonesArray.h>
29 #include <TGeoBBox.h>
30 #include <TGeoManager.h>
31 #include <TGeoNode.h>
32 #include <TGeoVolume.h>
33 #include <TList.h>
34 #include <TMath.h>
35 #include <TString.h>
36 #include <TVector3.h>
37 
39  : PixelAltFindHits("Pixel Hit Finder", 0)
40 {}
41 
43  : PixelAltFindHits("Pixel Hit Finder", iVerbose)
44 {}
45 
46 PixelAltFindHits::PixelAltFindHits(const char* name, Int_t iVerbose)
47  : FairTask(name, iVerbose)
48  , fDigiPar(nullptr)
49  , fGeoParSet(nullptr)
50  , fDigis(nullptr)
51  , fHits(nullptr)
52  , fNDigis(0)
53  , fNHits(0)
54  , fTNofEvents(0)
55  , fTNofDigis(0)
56  , fTNofHits(0)
57  , fFeCols(0)
58  , fFeRows(0)
59  , fMaxFEperCol(0)
60  , fPitchX(0.)
61  , fPitchY(0.)
62 {
63  LOG(info) << "Created PixelAltFindHits.";
64  Reset();
65 }
66 
68 {
69  Reset();
70  delete fDigiPar;
71  if (fHits) {
72  fHits->Delete();
73  delete fHits;
74  }
75 }
76 
77 void PixelAltFindHits::Exec(Option_t* /*opt*/)
78 {
79  Reset();
80 
81  LOG(debug) << "PixelAltFindHits::Exec() EVENT " << fTNofEvents;
82 
83  fTNofEvents++;
84 
85  fNDigis = fDigis->GetEntriesFast();
86  fTNofDigis += fNDigis;
87 
88  for (Int_t iDigi = 0; iDigi < fNDigis; iDigi++) {
89  PixelDigi* currentDigi = static_cast<PixelDigi*>(fDigis->At(iDigi));
90 
91  Int_t detId = currentDigi->GetDetectorID();
92 
93  Double_t posX, posY, posZ;
94  Double_t errX, errY, errZ;
95  Int_t hitIndex = FindHit(detId,
96  currentDigi->GetFeID(),
97  currentDigi->GetCol(),
98  currentDigi->GetRow(),
99  currentDigi->GetIndex(),
100  posX,
101  posY,
102  posZ,
103  errX,
104  errY,
105  errZ);
106 
107  TVector3 pos(posX, posY, posZ);
108  TVector3 posErr(errX, errY, errZ);
109 
110  if (hitIndex == -666)
111  continue; // hit not found
112 
113  new ((*fHits)[fNHits]) PixelHit(detId, hitIndex, pos, posErr);
114 
115  fNHits++;
116  }
117 
118  fTNofHits += fNHits;
119 }
120 
121 // should return -666 if hit not found
122 Int_t PixelAltFindHits::FindHit(Int_t detId,
123  Int_t feId,
124  Int_t col,
125  Int_t row,
126  Int_t index,
127  Double_t& posX,
128  Double_t& posY,
129  Double_t& posZ,
130  Double_t& errX,
131  Double_t& errY,
132  Double_t& errZ)
133 {
134  TString nodeName = Form("/cave/Pixel%d_%d", detId / 256, detId % 256);
135 
136  gGeoManager->cd(nodeName.Data());
137  TGeoNode* curNode = gGeoManager->GetCurrentNode();
138  TGeoVolume* actVolume = gGeoManager->GetCurrentVolume();
139  TGeoBBox* actBox = static_cast<TGeoBBox*>(actVolume->GetShape());
140 
141  Double_t locPosCalc[3];
142  locPosCalc[0] = (((feId - 1) / fMaxFEperCol) * fFeCols + col + 0.5) * fPitchX;
143  locPosCalc[1] = (((feId - 1) % fMaxFEperCol) * fFeRows + row + 0.5) * fPitchY;
144  locPosCalc[2] = 0.;
145 
146  locPosCalc[0] -= actBox->GetDX();
147  locPosCalc[1] -= actBox->GetDY();
148 
149  Double_t globPos[3];
150 
151  curNode->LocalToMaster(locPosCalc, globPos);
152 
153  LOG(debug) << "HIT ON " << detId << " POSITION: " << locPosCalc[0] << " / " << locPosCalc[1];
154  LOG(debug) << "GLOB HIT " << detId << " POSITION: " << globPos[0] << " / " << globPos[1] << " / " << globPos[2];
155 
156  posX = globPos[0];
157  posY = globPos[1];
158  posZ = globPos[2];
159  errX = fPitchX / TMath::Sqrt(12.);
160  errY = fPitchY / TMath::Sqrt(12.);
161  errZ = actBox->GetDZ();
162 
163  // should return -666 if hit not found
164  return index;
165 }
166 
167 void PixelAltFindHits::SetParContainers()
168 {
169  // Get run and runtime database
170  FairRun* run = FairRun::Instance();
171  if (!run)
172  LOG(fatal) << "No analysis run";
173 
174  FairRuntimeDb* db = run->GetRuntimeDb();
175  if (!db)
176  LOG(fatal) << "No runtime database";
177 
178  // Get GEM digitisation parameter container
179  fDigiPar = static_cast<PixelDigiPar*>(db->getContainer("PixelDigiParameters"));
180 }
181 
182 void PixelAltFindHits::GetParList(TList* tempList)
183 {
184  fDigiPar = new PixelDigiPar("PixelDigiParameters");
185  tempList->Add(fDigiPar);
186 
187  return;
188 }
189 
190 void PixelAltFindHits::InitMQ(TList* tempList)
191 {
192  LOG(info) << "********************************************** PixelAltFindHits::InitMQ()";
193  fDigiPar = (PixelDigiPar*)tempList->FindObject("PixelDigiParameters");
194 
195  fFeCols = fDigiPar->GetFECols();
196  fFeRows = fDigiPar->GetFERows();
197  fMaxFEperCol = fDigiPar->GetMaxFEperCol();
198  fPitchX = fDigiPar->GetXPitch();
199  fPitchY = fDigiPar->GetYPitch();
200 
201  LOG(info) << ">> fFeCols = " << fFeCols;
202  LOG(info) << ">> fFeRows = " << fFeRows;
203  LOG(info) << ">> fMaxFEperCol = " << fMaxFEperCol;
204  LOG(info) << ">> fPitchX = " << fPitchX;
205  LOG(info) << ">> fPitchY = " << fPitchY;
206 
207  fHits = new TClonesArray("PixelHit", 10000);
208 
209  return;
210 }
211 
212 void PixelAltFindHits::ExecMQ(TList* inputList, TList* outputList)
213 {
214  // LOG(info) << "********************************************** PixelAltFindHits::ExecMQ(" << inputList->GetName()
215  // << "," << outputList->GetName() << "), Event " << fTNofEvents; LOG(info) <<
216  // "********************************************** PixelAltFindHits::ExecMQ(), Event " << fTNofEvents; LOG(info) <<
217  // "h" << FairLogger::flush;
218  fDigis = (TClonesArray*)inputList->FindObject("PixelDigis");
219  outputList->Add(fHits);
220  Exec("");
221  return;
222 }
223 
225  int nofDigis,
226  PixelPayload::Hit* hitPalVector,
227  int& nofHits)
228 {
229  for (int idigi = 0; idigi < nofDigis; idigi++) {
230  FindHit(digiPalVector[idigi].fDetectorID,
231  digiPalVector[idigi].fFeID,
232  digiPalVector[idigi].fCol,
233  digiPalVector[idigi].fRow,
234  idigi,
235  hitPalVector[idigi].posX,
236  hitPalVector[idigi].posY,
237  hitPalVector[idigi].posZ,
238  hitPalVector[idigi].dposX,
239  hitPalVector[idigi].dposY,
240  hitPalVector[idigi].dposZ);
241  hitPalVector[idigi].fDetectorID = digiPalVector[idigi].fDetectorID;
242  nofHits++;
243  }
244  return;
245 }
246 
247 InitStatus PixelAltFindHits::Init()
248 {
249  // Get input array
251 
252  if (!ioman)
253  LOG(fatal) << "No FairRootManager";
254  fDigis = static_cast<TClonesArray*>(ioman->GetObject("PixelDigis"));
255 
256  if (!fDigis)
257  LOG(warn) << "PixelAltFindHits::Init() No input PixelDigis array!";
258 
259  // Register output array PixelHit
260  fHits = new TClonesArray("PixelHit", 10000);
261  ioman->Register("PixelHits", "Pixel", fHits, kTRUE);
262 
263  LOG(info) << "-I- " << fName.Data() << "::Init(). Initialization succesfull.";
264 
265  fFeCols = fDigiPar->GetFECols();
266  fFeRows = fDigiPar->GetFERows();
267  fMaxFEperCol = fDigiPar->GetMaxFEperCol();
268  fPitchX = fDigiPar->GetXPitch();
269  fPitchY = fDigiPar->GetYPitch();
270 
271  LOG(info) << "PixelAltFindHits::SetParContainers() Pixel detector with pitch size " << fPitchX << "cm x" << fPitchY
272  << "cm";
273 
274  return kSUCCESS;
275 }
276 
277 InitStatus PixelAltFindHits::ReInit() { return kSUCCESS; }
278 
279 void PixelAltFindHits::Reset()
280 {
281  fNDigis = fNHits = 0;
282  if (fHits)
283  fHits->Clear();
284 }
285 
286 void PixelAltFindHits::Finish()
287 {
288  if (fHits)
289  fHits->Delete();
290 
291  LOG(info) << "-------------------- " << fName.Data() << " : Summary ------------------------";
292  LOG(info) << " Events: " << fTNofEvents;
293  LOG(info) << " Digis: " << fTNofDigis << " ("
294  << static_cast<Double_t>(fTNofDigis) / (static_cast<Double_t>(fTNofEvents)) << " per event)";
295  LOG(info) << " Hits: " << fTNofHits << " ("
296  << static_cast<Double_t>(fTNofHits) / (static_cast<Double_t>(fTNofEvents)) << " per event)";
297  LOG(info) << "---------------------------------------------------------------------";
298 }
299 
Int_t GetIndex()
Definition: PixelDigi.h:44
list of container factories
Definition: FairRuntimeDb.h:24
InitStatus
Definition: FairTask.h:33
Double_t GetYPitch() const
Definition: PixelDigiPar.h:38
Int_t GetRow()
Definition: PixelDigi.h:49
virtual void Exec(Option_t *opt)
static FairRun * Instance()
Definition: FairRun.cxx:31
Int_t GetFERows() const
Definition: PixelDigiPar.h:43
virtual void ExecMQ(TList *inputList, TList *outputList)
static FairRootManager * Instance()
ClassImp(FairEventBuilder)
virtual void GetParList(TList *tempList)
Digitization Parameter Class for Pixel detector.
Definition: PixelDigiPar.h:24
TObject * GetObject(const char *BrName)
FairParSet * getContainer(const Text_t *)
Int_t GetFECols() const
Definition: PixelDigiPar.h:42
Int_t GetDetectorID()
Definition: PixelDigi.h:45
Int_t GetCol()
Definition: PixelDigi.h:48
virtual ~PixelAltFindHits()
FairRuntimeDb * GetRuntimeDb(void)
Definition: FairRun.h:80
void Register(const char *name, const char *Foldername, TNamed *obj, Bool_t toFile)
Int_t GetFeID()
Definition: PixelDigi.h:46
Double_t GetXPitch() const
Definition: PixelDigiPar.h:37
virtual void InitMQ(TList *tempList)
Int_t GetMaxFEperCol() const
Definition: PixelDigiPar.h:44