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