FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PixelDigitize.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  * PixelHit.h
10  *
11  * Created on: 16.02.2016
12  * Author: R. Karabowicz
13  */
14 
15 #include "PixelDigitize.h"
16 
17 #include "PixelDigi.h"
18 #include "PixelDigiPar.h"
19 #include "PixelPoint.h"
20 
21 // Includes from base
22 #include "FairLogger.h"
23 #include "FairRootManager.h"
24 #include "FairRun.h"
25 #include "FairRuntimeDb.h"
26 
27 // Includes from ROOT
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 <TString.h>
35 
37  : PixelDigitize("Pixel Digitizer", 0)
38 {}
39 
41  : PixelDigitize("Pixel Digitizer", iVerbose)
42 {}
43 
44 PixelDigitize::PixelDigitize(const char* name, Int_t iVerbose)
45  : FairTask(name, iVerbose)
46  , fDigiPar(nullptr)
47  , fPoints(nullptr)
48  , fDigis(nullptr)
49  , fNPoints(0)
50  , fNDigis(0)
51  , fTNofEvents(0)
52  , fTNofPoints(0)
53  , fTNofDigis(0)
54  , fFeCols(0)
55  , fFeRows(0)
56  , fMaxFEperCol(0)
57  , fPitchX(0.)
58  , fPitchY(0.)
59 {
60  Reset();
61 }
62 
64 {
65  Reset();
66  delete fDigiPar;
67  if (fDigis) {
68  fDigis->Delete();
69  delete fDigis;
70  }
71 }
72 
73 void PixelDigitize::Exec(Option_t* /*opt*/)
74 {
75  Reset();
76 
77  LOG(debug) << "PixelDigitize::Exec() EVENT " << fTNofEvents;
78 
79  fTNofEvents++;
80 
81  fNPoints = fPoints->GetEntriesFast();
82  fTNofPoints += fNPoints;
83 
84  for (Int_t iPoint = 0; iPoint < fNPoints; iPoint++) {
85  PixelPoint* currentPixelPoint = static_cast<PixelPoint*>(fPoints->At(iPoint));
86 
87  Double_t posIn[3] = {currentPixelPoint->GetX(), currentPixelPoint->GetY(), currentPixelPoint->GetZ()};
88 
89  Int_t detId = currentPixelPoint->GetDetectorID();
90  TString nodeName = Form("/cave/Pixel%d_%d", detId / 256, detId % 256);
91 
92  gGeoManager->cd(nodeName.Data());
93  TGeoNode* curNode = gGeoManager->GetCurrentNode();
94 
95  if (!curNode)
96  LOG(fatal) << "PixelDigitize::Exec() node \"" << nodeName.Data() << "\" unknown!";
97 
98  Double_t locPosIn[3];
99 
100  curNode->MasterToLocal(posIn, locPosIn);
101 
102  // The local coordinate system has the origin set to the center of the volume.
103  // To calculate the pixel number, it is necessary to move the origin to the bottom left corner.
104  TGeoVolume* actVolume = gGeoManager->GetCurrentVolume();
105  TGeoBBox* actBox = static_cast<TGeoBBox*>(actVolume->GetShape());
106  // Double_t sensorWidth = 2.*actBox->GetDX();
107  // Double_t sensorHeight = 2.*actBox->GetDY();
108  locPosIn[0] += actBox->GetDX();
109  locPosIn[1] += actBox->GetDY();
110 
111  LOG(debug) << "GLOB PNT " << detId << " POSITION: " << posIn[0] << " / " << posIn[1] << " / " << posIn[2];
112  LOG(debug) << "POINT ON " << detId << " POSITION: " << locPosIn[0] << " / " << locPosIn[1];
113 
114  Int_t col = static_cast<Int_t>(locPosIn[0] / fPitchX);
115  Int_t ocol = col;
116  Int_t row = static_cast<Int_t>(locPosIn[1] / fPitchY);
117  Int_t orow = row;
118  Int_t feCol = col / fFeCols;
119  col = col % fFeCols;
120  Int_t feRow = row / fFeRows;
121  row = row % fFeRows;
122  Int_t feId = 1 + feCol * fMaxFEperCol + feRow;
123 
124  LOG(debug) << "COL = " << feCol << " FE + " << col << " ( " << ocol << " ) /// "
125  << "ROW = " << feRow << " FE + " << row << " ( " << orow << " ) /// "
126  << " /// PIXEL = " << feId;
127 
128  ActivatePixel(iPoint, detId, feId, col, row, 1., 0.);
129  }
130 
131  fTNofDigis += fNDigis;
132 }
133 
134 void PixelDigitize::ActivatePixel(Int_t index,
135  Int_t detId,
136  Int_t feId,
137  Int_t col,
138  Int_t row,
139  Double_t charge,
140  Double_t timestamp)
141 {
142  Bool_t pixelAlreadyFired = kFALSE;
143  PixelDigi* tempPixel = nullptr;
144  for (Int_t ipixel = 0; ipixel < fNDigis; ipixel++) {
145  tempPixel = static_cast<PixelDigi*>(fDigis->At(ipixel));
146  if (tempPixel->GetDetectorID() == detId && tempPixel->GetFeID() == feId && tempPixel->GetCol() == col
147  && tempPixel->GetRow() == row) {
148  pixelAlreadyFired = kTRUE;
149  tempPixel->SetCharge(tempPixel->GetCharge() + charge);
150  }
151  }
152  // TODO: order the PixelDigi in the output array by station, not by track...
153  if (!pixelAlreadyFired) {
154  new ((*fDigis)[fNDigis]) PixelDigi(index, detId, feId, col, row, charge, timestamp);
155  fNDigis++;
156  }
157 }
158 
159 void PixelDigitize::SetParContainers()
160 {
161  // Get run and runtime database
162  FairRun* run = FairRun::Instance();
163  if (!run) {
164  LOG(fatal) << "No analysis run";
165 
166  } else {
167  FairRuntimeDb* db = run->GetRuntimeDb();
168  if (!db) {
169  LOG(fatal) << "No runtime database";
170  } else {
171  // Get GEM digitisation parameter container
172  fDigiPar = static_cast<PixelDigiPar*>(db->getContainer("PixelDigiParameters"));
173  }
174  }
175 }
176 
177 void PixelDigitize::GetParList(TList* tempList)
178 {
179  fDigiPar = new PixelDigiPar("PixelDigiParameters");
180  tempList->Add(fDigiPar);
181 
182  return;
183 }
184 
185 void PixelDigitize::InitMQ(TList* tempList)
186 {
187  LOG(info) << "********************************************** PixelDigitize::InitMQ()";
188  fDigiPar = (PixelDigiPar*)tempList->FindObject("PixelDigiParameters");
189 
190  fFeCols = fDigiPar->GetFECols();
191  fFeRows = fDigiPar->GetFERows();
192  fMaxFEperCol = fDigiPar->GetMaxFEperCol();
193  fPitchX = fDigiPar->GetXPitch();
194  fPitchY = fDigiPar->GetYPitch();
195 
196  LOG(info) << ">> fFeCols = " << fFeCols;
197  LOG(info) << ">> fFeRows = " << fFeRows;
198  LOG(info) << ">> fMaxFEperCol = " << fMaxFEperCol;
199  LOG(info) << ">> fPitchX = " << fPitchX;
200  LOG(info) << ">> fPitchY = " << fPitchY;
201 
202  fDigis = new TClonesArray("PixelDigi", 10000);
203 
204  return;
205 }
206 
207 void PixelDigitize::ExecMQ(TList* inputList, TList* outputList)
208 {
209  // LOG(info) << "********************************************** PixelDigitize::ExecMQ(" << inputList->GetName() <<
210  // "," << outputList->GetName() << "), Event " << fTNofEvents; LOG(info) <<
211  // "********************************************** PixelDigitize::ExecMQ(), Event " << fTNofEvents;
212  fPoints = (TClonesArray*)inputList->FindObject("PixelPoint");
213  outputList->Add(fDigis);
214  Exec("");
215  return;
216 }
217 
218 InitStatus PixelDigitize::Init()
219 {
220  // Get input array
222 
223  if (!ioman)
224  LOG(fatal) << "No FairRootManager";
225  fPoints = static_cast<TClonesArray*>(ioman->GetObject("PixelPoint"));
226 
227  // Register output array StsDigi
228  fDigis = new TClonesArray("PixelDigi", 10000);
229  ioman->Register("PixelDigis", "Pixel", fDigis, kTRUE);
230 
231  LOG(info) << "-I- " << fName.Data() << "::Init(). Initialization succesfull.";
232 
233  fFeCols = fDigiPar->GetFECols();
234  fFeRows = fDigiPar->GetFERows();
235  fMaxFEperCol = fDigiPar->GetMaxFEperCol();
236  fPitchX = fDigiPar->GetXPitch();
237  fPitchY = fDigiPar->GetYPitch();
238 
239  LOG(info) << "PixelDigitize::SetParContainers() Pixel detector with pitch size " << fPitchX << "cm x" << fPitchY
240  << "cm";
241 
242  return kSUCCESS;
243 }
244 
245 InitStatus PixelDigitize::ReInit() { return kSUCCESS; }
246 
247 void PixelDigitize::Reset()
248 {
249  fNPoints = fNDigis = 0;
250  if (fDigis)
251  fDigis->Clear();
252 }
253 
254 void PixelDigitize::Finish()
255 {
256  if (fDigis)
257  fDigis->Delete();
258 
259  LOG(info) << "-------------------- " << fName.Data() << " : Summary ------------------------";
260  LOG(info) << " Events: " << fTNofEvents;
261  LOG(info) << " MC Points: " << fTNofPoints << " ( "
262  << static_cast<Double_t>(fTNofPoints) / (static_cast<Double_t>(fTNofEvents)) << " per event )";
263  LOG(info) << " Digis: " << fTNofDigis << " ( "
264  << static_cast<Double_t>(fTNofDigis) / (static_cast<Double_t>(fTNofEvents)) << " per event )";
265  LOG(info) << "---------------------------------------------------------------------";
266 }
267 
list of container factories
Definition: FairRuntimeDb.h:24
InitStatus
Definition: FairTask.h:33
Double_t GetZ() const
Definition: FairMCPoint.h:69
Double_t GetX() const
Definition: FairMCPoint.h:67
virtual void GetParList(TList *tempList)
void SetCharge(Double_t ch)
Definition: PixelDigi.h:40
Double_t GetYPitch() const
Definition: PixelDigiPar.h:38
Int_t GetRow()
Definition: PixelDigi.h:49
static FairRun * Instance()
Definition: FairRun.cxx:31
Int_t GetFERows() const
Definition: PixelDigiPar.h:43
virtual void Exec(Option_t *opt)
static FairRootManager * Instance()
ClassImp(FairEventBuilder)
Digitization Parameter Class for Pixel detector.
Definition: PixelDigiPar.h:24
TObject * GetObject(const char *BrName)
virtual void InitMQ(TList *tempList)
FairParSet * getContainer(const Text_t *)
Int_t GetFECols() const
Definition: PixelDigiPar.h:42
virtual ~PixelDigitize()
Int_t GetDetectorID()
Definition: PixelDigi.h:45
Int_t GetCol()
Definition: PixelDigi.h:48
Double_t GetCharge()
Definition: PixelDigi.h:47
FairRuntimeDb * GetRuntimeDb(void)
Definition: FairRun.h:80
void Register(const char *name, const char *Foldername, TNamed *obj, Bool_t toFile)
virtual void ExecMQ(TList *inputList, TList *outputList)
Double_t GetY() const
Definition: FairMCPoint.h:68
Int_t GetFeID()
Definition: PixelDigi.h:46
Int_t GetDetectorID() const
Definition: FairMCPoint.h:66
Double_t GetXPitch() const
Definition: PixelDigiPar.h:37
Int_t GetMaxFEperCol() const
Definition: PixelDigiPar.h:44