990119d6 |
1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * |
3 | * * |
4 | * Author: The ALICE Off-line Project. * |
5 | * Contributors are mentioned in the code where appropriate. * |
6 | * * |
7 | * Permission to use, copy, modify and distribute this software and its * |
8 | * documentation strictly for non-commercial purposes is hereby granted * |
9 | * without fee, provided that the above copyright notice appears in all * |
10 | * copies and that both the copyright notice and this permission notice * |
11 | * appear in the supporting documentation. The authors make no claims * |
12 | * about the suitability of this software for any purpose. It is * |
13 | * provided "as is" without express or implied warranty. * |
14 | **************************************************************************/ |
15 | |
16 | /* $Id$ */ |
17 | |
18 | //_________________________________________________________________________ |
990119d6 |
19 | //*-- Author : Dmitri Peressounko (SUBATECH & Kurchatov Institute) |
20 | ////////////////////////////////////////////////////////////////////////////// |
a4e98857 |
21 | // This TTask performs digitization of Summable digits (in the PHOS case it is just |
22 | // the sum of contributions from all primary particles into a given cell). |
990119d6 |
23 | // In addition it performs mixing of summable digits from different events. |
7b7c1533 |
24 | // The name of the TTask is also the title of the branch that will contain |
25 | // the created SDigits |
26 | // The title of the TTAsk is the name of the file that contains the hits from |
27 | // which the SDigits are created |
bca3b32a |
28 | // |
29 | // For each event two branches are created in TreeD: |
30 | // "PHOS" - list of digits |
31 | // "AliPHOSDigitizer" - AliPHOSDigitizer with all parameters used in digitization |
32 | // |
a4e98857 |
33 | // Note, that one can set a title for new digits branch, and repeat digitization with |
bca3b32a |
34 | // another set of parameters. |
35 | // |
a4e98857 |
36 | // Use case: |
990119d6 |
37 | // root[0] AliPHOSDigitizer * d = new AliPHOSDigitizer() ; |
38 | // root[1] d->ExecuteTask() |
39 | // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated |
40 | // //Digitizes SDigitis in all events found in file galice.root |
bca3b32a |
41 | // |
8cb3533f |
42 | // root[2] AliPHOSDigitizer * d1 = new AliPHOSDigitizer("galice1.root") ; |
43 | // // Will read sdigits from galice1.root |
44 | // root[3] d1->MixWith("galice2.root") |
990119d6 |
45 | // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated |
a4e98857 |
46 | // // Reads another set of sdigits from galice2.root |
8cb3533f |
47 | // root[3] d1->MixWith("galice3.root") |
a4e98857 |
48 | // // Reads another set of sdigits from galice3.root |
8cb3533f |
49 | // root[4] d->ExecuteTask("deb timing") |
50 | // // Reads SDigits from files galice1.root, galice2.root .... |
51 | // // mixes them and stores produced Digits in file galice1.root |
52 | // // deb - prints number of produced digits |
53 | // // deb all - prints list of produced digits |
54 | // // timing - prints time used for digitization |
990119d6 |
55 | // |
990119d6 |
56 | |
57 | // --- ROOT system --- |
8cb3533f |
58 | #include "TFile.h" |
990119d6 |
59 | #include "TTree.h" |
60 | #include "TSystem.h" |
8cb3533f |
61 | #include "TROOT.h" |
62 | #include "TFolder.h" |
63 | #include "TObjString.h" |
b3690abb |
64 | #include "TGeometry.h" |
8cb3533f |
65 | #include "TBenchmark.h" |
ba54256b |
66 | |
990119d6 |
67 | // --- Standard library --- |
8cb3533f |
68 | #include <iomanip.h> |
990119d6 |
69 | |
70 | // --- AliRoot header files --- |
8cb3533f |
71 | #include "AliRun.h" |
b3690abb |
72 | #include "AliHeader.h" |
ea5f3389 |
73 | #include "AliStream.h" |
3f81a70b |
74 | #include "AliRunDigitizer.h" |
990119d6 |
75 | #include "AliPHOSDigit.h" |
dd5c4038 |
76 | #include "AliPHOS.h" |
7b7c1533 |
77 | #include "AliPHOSGetter.h" |
990119d6 |
78 | #include "AliPHOSDigitizer.h" |
79 | #include "AliPHOSSDigitizer.h" |
8cb3533f |
80 | #include "AliPHOSGeometry.h" |
7437a0f7 |
81 | #include "AliPHOSTick.h" |
990119d6 |
82 | |
83 | ClassImp(AliPHOSDigitizer) |
84 | |
85 | |
86 | //____________________________________________________________________________ |
3f81a70b |
87 | AliPHOSDigitizer::AliPHOSDigitizer() |
990119d6 |
88 | { |
89 | // ctor |
8d0f3f77 |
90 | InitParameters() ; |
9bd3caba |
91 | fDefaultInit = kTRUE ; |
fbf811ec |
92 | fManager = 0 ; // We work in the standalong mode |
548f0134 |
93 | |
9bd3caba |
94 | } |
3f81a70b |
95 | |
96 | //____________________________________________________________________________ |
fbf811ec |
97 | AliPHOSDigitizer::AliPHOSDigitizer(const char *headerFile, const char * name, const Bool_t toSplit) |
3f81a70b |
98 | { |
99 | // ctor |
ea5f3389 |
100 | |
3f81a70b |
101 | SetTitle(headerFile) ; |
38bb0fd5 |
102 | SetName(name) ; |
9891b76e |
103 | fManager = 0 ; // We work in the standalong mode |
64c73770 |
104 | fSplitFile= 0 ; |
8d0f3f77 |
105 | InitParameters() ; |
fbf811ec |
106 | fToSplit = toSplit ; |
3f81a70b |
107 | Init() ; |
92f521a9 |
108 | fDefaultInit = kFALSE ; |
990119d6 |
109 | } |
110 | |
990119d6 |
111 | //____________________________________________________________________________ |
9891b76e |
112 | AliPHOSDigitizer::AliPHOSDigitizer(AliRunDigitizer * ard):AliDigitizer(ard) |
990119d6 |
113 | { |
114 | // ctor |
fbf811ec |
115 | SetTitle(ard->GetInputFileName(0,0)) ; |
b22e4735 |
116 | InitParameters() ; |
fbf811ec |
117 | fDefaultInit = kFALSE ; |
118 | fSplitFile = 0 ; |
119 | |
120 | if (ard->GetOutputFile()) { |
121 | SetName(ard->GetOutputFile().Data()); |
122 | fToSplit = kTRUE ; |
123 | } else { |
124 | SetName("Default") ; |
125 | fToSplit = kFALSE ; |
126 | } |
990119d6 |
127 | } |
128 | |
129 | //____________________________________________________________________________ |
130 | AliPHOSDigitizer::~AliPHOSDigitizer() |
131 | { |
132 | // dtor |
548f0134 |
133 | |
79bb1b62 |
134 | fSplitFile = 0 ; |
990119d6 |
135 | } |
136 | |
137 | //____________________________________________________________________________ |
7b7c1533 |
138 | void AliPHOSDigitizer::Digitize(const Int_t event) |
a4e98857 |
139 | { |
140 | |
141 | // Makes the digitization of the collected summable digits. |
142 | // It first creates the array of all PHOS modules |
143 | // filled with noise (different for EMC, CPV and PPSD) and |
144 | // then adds contributions from SDigits. |
145 | // This design avoids scanning over the list of digits to add |
146 | // contribution to new SDigits only. |
990119d6 |
147 | |
7b7c1533 |
148 | AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ; |
38bb0fd5 |
149 | TClonesArray * digits = gime->Digits(GetName()) ; |
7b7c1533 |
150 | |
151 | digits->Clear() ; |
990119d6 |
152 | |
7b7c1533 |
153 | const AliPHOSGeometry *geom = gime->PHOSGeometry() ; |
990119d6 |
154 | //Making digits with noise, first EMC |
155 | Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ(); |
156 | |
157 | Int_t nCPV ; |
990119d6 |
158 | Int_t absID ; |
159 | TString name = geom->GetName() ; |
160 | |
9688c1dd |
161 | nCPV = nEMC + geom->GetNumberOfCPVPadsZ()*geom->GetNumberOfCPVPadsPhi()* |
162 | geom->GetNModules() ; |
8cb3533f |
163 | |
9688c1dd |
164 | digits->Expand(nCPV) ; |
8cb3533f |
165 | |
7b7c1533 |
166 | // get first the sdigitizer from the tasks list (must have same name as the digitizer) |
92f521a9 |
167 | const AliPHOSSDigitizer * sDigitizer = gime->SDigitizer(GetName()); |
7b7c1533 |
168 | if ( !sDigitizer) { |
169 | cerr << "ERROR: AliPHOSDigitizer::Digitize -> SDigitizer with name " << GetName() << " not found " << endl ; |
170 | abort() ; |
171 | } |
9688c1dd |
172 | |
7b7c1533 |
173 | // loop through the sdigits posted to the White Board and add them to the noise |
7a9d98f9 |
174 | TCollection * folderslist = gime->SDigitsFolder()->GetListOfFolders() ; |
7b7c1533 |
175 | TIter next(folderslist) ; |
176 | TFolder * folder = 0 ; |
3f81a70b |
177 | TClonesArray * sdigits = 0 ; |
178 | Int_t input = 0 ; |
9688c1dd |
179 | TObjArray * sdigArray = new TObjArray(2) ; |
38bb0fd5 |
180 | while ( (folder = (TFolder*)next()) ) { |
3f81a70b |
181 | if ( (sdigits = (TClonesArray*)folder->FindObject(GetName()) ) ) { |
54b82aa4 |
182 | TString fileName(folder->GetName()) ; |
183 | fileName.ReplaceAll("_","/") ; |
fbf811ec |
184 | // cout << "INFO: AliPHOSDigitizer::Digitize -> Adding SDigits " |
185 | // << GetName() << " from " << fileName << endl ; |
9688c1dd |
186 | sdigArray->AddAt(sdigits, input) ; |
187 | input++ ; |
188 | } |
38bb0fd5 |
189 | } |
9688c1dd |
190 | |
7a9d98f9 |
191 | //Find the first crystall with signal |
9688c1dd |
192 | Int_t nextSig = 200000 ; |
193 | Int_t i; |
194 | for(i=0; i<input; i++){ |
195 | sdigits = (TClonesArray *)sdigArray->At(i) ; |
a6eedfad |
196 | if ( !sdigits->GetEntriesFast() ) |
7a9d98f9 |
197 | continue ; |
9688c1dd |
198 | Int_t curNext = ((AliPHOSDigit *)sdigits->At(0))->GetId() ; |
7a9d98f9 |
199 | if(curNext < nextSig) |
200 | nextSig = curNext ; |
9688c1dd |
201 | } |
7437a0f7 |
202 | |
9688c1dd |
203 | TArrayI index(input) ; |
204 | index.Reset() ; //Set all indexes to zero |
205 | |
206 | AliPHOSDigit * digit ; |
207 | AliPHOSDigit * curSDigit ; |
208 | |
7437a0f7 |
209 | TClonesArray * ticks = new TClonesArray("AliPHOSTick",1000) ; |
210 | |
9688c1dd |
211 | //Put Noise contribution |
212 | for(absID = 1; absID <= nEMC; absID++){ |
213 | Float_t noise = gRandom->Gaus(0., fPinNoise) ; |
214 | new((*digits)[absID-1]) AliPHOSDigit( -1,absID,sDigitizer->Digitize(noise), TimeOfNoise() ) ; |
215 | //look if we have to add signal? |
b3690abb |
216 | digit = (AliPHOSDigit *) digits->At(absID-1) ; |
217 | |
9688c1dd |
218 | if(absID==nextSig){ |
219 | //Add SDigits from all inputs |
7437a0f7 |
220 | ticks->Clear() ; |
9688c1dd |
221 | Int_t contrib = 0 ; |
7437a0f7 |
222 | Float_t a = digit->GetAmp() ; |
223 | Float_t b = TMath::Abs( a /fTimeSignalLength) ; |
224 | //Mark the beginnign of the signal |
225 | new((*ticks)[contrib++]) AliPHOSTick(digit->GetTime(),0, b); |
226 | //Mark the end of the ignal |
227 | new((*ticks)[contrib++]) AliPHOSTick(digit->GetTime()+fTimeSignalLength, -a, -b); |
228 | |
9688c1dd |
229 | //loop over inputs |
230 | for(i=0; i<input; i++){ |
5c9dfca0 |
231 | if(((TClonesArray *)sdigArray->At(i))->GetEntriesFast() > index[i] ) |
232 | curSDigit = (AliPHOSDigit*)((TClonesArray *)sdigArray->At(i))->At(index[i]) ; |
233 | else |
234 | curSDigit = 0 ; |
9688c1dd |
235 | //May be several digits will contribute from the same input |
236 | while(curSDigit && curSDigit->GetId() == absID){ |
237 | //Shift primary to separate primaries belonging different inputs |
238 | Int_t primaryoffset ; |
9891b76e |
239 | if(fManager) |
240 | primaryoffset = fManager->GetMask(i) ; |
9688c1dd |
241 | else |
21c293b7 |
242 | primaryoffset = 10000000*i ; |
243 | curSDigit->ShiftPrimary(primaryoffset) ; |
7437a0f7 |
244 | |
245 | a = curSDigit->GetAmp() ; |
246 | b = a /fTimeSignalLength ; |
247 | new((*ticks)[contrib++]) AliPHOSTick(curSDigit->GetTime(),0, b); |
248 | new((*ticks)[contrib++]) AliPHOSTick(curSDigit->GetTime()+fTimeSignalLength, -a, -b); |
9688c1dd |
249 | |
250 | *digit = *digit + *curSDigit ; //add energies |
7437a0f7 |
251 | |
9688c1dd |
252 | index[i]++ ; |
5c9dfca0 |
253 | if(((TClonesArray *)sdigArray->At(i))->GetEntriesFast() > index[i] ) |
254 | curSDigit = (AliPHOSDigit*)((TClonesArray *)sdigArray->At(i))->At(index[i]) ; |
255 | else |
256 | curSDigit = 0 ; |
9688c1dd |
257 | } |
258 | } |
259 | |
260 | //calculate and set time |
7437a0f7 |
261 | Float_t time = FrontEdgeTime(ticks) ; |
9688c1dd |
262 | digit->SetTime(time) ; |
7437a0f7 |
263 | |
9688c1dd |
264 | //Find next signal module |
7437a0f7 |
265 | nextSig = 200000 ; |
9688c1dd |
266 | for(i=0; i<input; i++){ |
267 | sdigits = ((TClonesArray *)sdigArray->At(i)) ; |
5c9dfca0 |
268 | Int_t curNext = nextSig ; |
269 | if(sdigits->GetEntriesFast() > index[i] ){ |
270 | curNext = ((AliPHOSDigit *) sdigits->At(index[i]))->GetId() ; |
271 | |
272 | } |
9688c1dd |
273 | if(curNext < nextSig) nextSig = curNext ; |
7b7c1533 |
274 | } |
275 | } |
990119d6 |
276 | } |
3f81a70b |
277 | |
7437a0f7 |
278 | ticks->Delete() ; |
279 | delete ticks ; |
9688c1dd |
280 | |
281 | |
282 | //Now CPV digits (different noise and no timing) |
283 | for(absID = nEMC+1; absID <= nCPV; absID++){ |
284 | Float_t noise = gRandom->Gaus(0., fCPVNoise) ; |
285 | new((*digits)[absID-1]) AliPHOSDigit( -1,absID,sDigitizer->Digitize(noise), TimeOfNoise() ) ; |
286 | //look if we have to add signal? |
287 | if(absID==nextSig){ |
288 | digit = (AliPHOSDigit *) digits->At(absID-1) ; |
289 | //Add SDigits from all inputs |
290 | for(i=0; i<input; i++){ |
5c9dfca0 |
291 | if(((TClonesArray *)sdigArray->At(i))->GetEntriesFast() > index[i] ) |
292 | curSDigit = (AliPHOSDigit*)((TClonesArray *)sdigArray->At(i))->At(index[i]) ; |
293 | else |
294 | curSDigit = 0 ; |
a6eedfad |
295 | |
9688c1dd |
296 | //May be several digits will contribute from the same input |
297 | while(curSDigit && curSDigit->GetId() == absID){ |
298 | //Shift primary to separate primaries belonging different inputs |
299 | Int_t primaryoffset ; |
9891b76e |
300 | if(fManager) |
301 | primaryoffset = fManager->GetMask(i) ; |
9688c1dd |
302 | else |
303 | primaryoffset = 10000000*i ; |
304 | curSDigit->ShiftPrimary(primaryoffset) ; |
305 | |
306 | //add energies |
307 | *digit = *digit + *curSDigit ; |
308 | index[i]++ ; |
5c9dfca0 |
309 | if(((TClonesArray *)sdigArray->At(i))->GetEntriesFast() > index[i] ) |
310 | curSDigit = (AliPHOSDigit*)((TClonesArray *)sdigArray->At(i))->At(index[i]) ; |
311 | else |
312 | curSDigit = 0 ; |
9688c1dd |
313 | } |
314 | } |
a6eedfad |
315 | |
9688c1dd |
316 | //Find next signal module |
a6eedfad |
317 | nextSig = 200000 ; |
9688c1dd |
318 | for(i=0; i<input; i++){ |
319 | sdigits = (TClonesArray *)sdigArray->At(i) ; |
5c9dfca0 |
320 | Int_t curNext = nextSig ; |
321 | if(sdigits->GetEntriesFast() > index[i] ) |
322 | curNext = ((AliPHOSDigit *) sdigits->At(index[i]))->GetId() ; |
9688c1dd |
323 | if(curNext < nextSig) nextSig = curNext ; |
324 | } |
325 | |
326 | } |
327 | } |
9688c1dd |
328 | delete sdigArray ; //We should not delete its contents |
329 | |
330 | |
331 | |
990119d6 |
332 | //remove digits below thresholds |
a6eedfad |
333 | for(i = 0; i < nEMC ; i++){ |
548f0134 |
334 | digit = dynamic_cast<AliPHOSDigit*>( digits->At(i) ) ; |
aaf8a71c |
335 | if(sDigitizer->Calibrate( digit->GetAmp() ) < fEMCDigitThreshold) |
a6eedfad |
336 | digits->RemoveAt(i) ; |
aaf8a71c |
337 | else |
338 | digit->SetTime(gRandom->Gaus(digit->GetTime(),fTimeResolution) ) ; |
339 | } |
340 | |
a6eedfad |
341 | |
342 | for(i = nEMC; i < nCPV ; i++) |
343 | if(sDigitizer->Calibrate(((AliPHOSDigit*)digits->At(i))->GetAmp()) < fCPVDigitThreshold) |
344 | digits->RemoveAt(i) ; |
9688c1dd |
345 | |
7b7c1533 |
346 | digits->Compress() ; |
990119d6 |
347 | |
7b7c1533 |
348 | Int_t ndigits = digits->GetEntriesFast() ; |
7b7c1533 |
349 | digits->Expand(ndigits) ; |
990119d6 |
350 | |
3758d9fc |
351 | //Set indexes in list of digits and make true digitization of the energy |
990119d6 |
352 | for (i = 0 ; i < ndigits ; i++) { |
548f0134 |
353 | digit = dynamic_cast<AliPHOSDigit*>( digits->At(i) ) ; |
990119d6 |
354 | digit->SetIndexInList(i) ; |
f672adc8 |
355 | Float_t energy = sDigitizer->Calibrate(digit->GetAmp()) ; |
3758d9fc |
356 | digit->SetAmp(DigitizeEnergy(energy,digit->GetId()) ) ; |
990119d6 |
357 | } |
990119d6 |
358 | |
7b7c1533 |
359 | } |
548f0134 |
360 | |
3758d9fc |
361 | //____________________________________________________________________________ |
362 | Int_t AliPHOSDigitizer::DigitizeEnergy(Float_t energy, Int_t absId) |
363 | { |
364 | Int_t chanel ; |
365 | if(absId <= fEmcCrystals){ //digitize as EMC |
366 | chanel = (Int_t) TMath::Ceil((energy - fADCpedestalEmc)/fADCchanelEmc) ; |
367 | if(chanel > fNADCemc ) chanel = fNADCemc ; |
368 | } |
369 | else{ //Digitize as CPV |
370 | chanel = (Int_t) TMath::Ceil((energy - fADCpedestalCpv)/fADCchanelCpv) ; |
371 | if(chanel > fNADCcpv ) chanel = fNADCcpv ; |
372 | } |
373 | return chanel ; |
374 | } |
548f0134 |
375 | |
7b7c1533 |
376 | //____________________________________________________________________________ |
377 | void AliPHOSDigitizer::Exec(Option_t *option) |
378 | { |
379 | // Managing method |
990119d6 |
380 | |
f672adc8 |
381 | if(strcmp(GetName(), "") == 0 ) |
7b7c1533 |
382 | Init() ; |
7b7c1533 |
383 | if (strstr(option,"print")) { |
384 | Print(""); |
385 | return ; |
8cb3533f |
386 | } |
990119d6 |
387 | |
7b7c1533 |
388 | if(strstr(option,"tim")) |
389 | gBenchmark->Start("PHOSDigitizer"); |
8cb3533f |
390 | |
3f81a70b |
391 | AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ; |
392 | |
393 | Int_t nevents ; |
394 | |
395 | TTree * treeD ; |
396 | |
9891b76e |
397 | if(fManager){ |
398 | treeD = fManager->GetTreeD() ; |
3f81a70b |
399 | nevents = 1 ; // Will process only one event |
8cb3533f |
400 | |
fbf811ec |
401 | //Check, if this branch already exits |
402 | if (treeD) { |
403 | TObjArray * lob = (TObjArray*)treeD->GetListOfBranches() ; |
404 | TIter next(lob) ; |
405 | TBranch * branch = 0 ; |
406 | Bool_t phosfound = kFALSE, digitizerfound = kFALSE ; |
b3690abb |
407 | |
fbf811ec |
408 | while ( (branch = (TBranch*)next()) && (!phosfound || !digitizerfound) ) { |
409 | if ( (strcmp(branch->GetName(), "PHOS")==0) && |
410 | (strcmp(branch->GetTitle(), GetName())==0) ) |
411 | phosfound = kTRUE ; |
412 | |
413 | else if ( (strcmp(branch->GetName(), "AliPHOSDigitizer")==0) && |
414 | (strcmp(branch->GetTitle(), GetName())==0) ) |
415 | digitizerfound = kTRUE ; |
416 | } |
417 | |
418 | if ( phosfound ) { |
419 | cerr << "WARNING: AliPHOSDigitizer -> Digits branch with name " << GetName() |
420 | << " already exits" << endl ; |
421 | return ; |
422 | } |
423 | if ( digitizerfound ) { |
424 | cerr << "WARNING: AliPHOSDigitizer -> Digitizer branch with name " << GetName() |
425 | << " already exits" << endl ; |
426 | return ; |
427 | } |
b3690abb |
428 | } |
8cb3533f |
429 | } |
fbf811ec |
430 | else { //PHOS standalone |
431 | if(gime->BranchExists("Digits") ) |
432 | return ; |
433 | nevents=gime->MaxEvent() ; |
434 | } |
435 | |
7b7c1533 |
436 | Int_t ievent ; |
b3690abb |
437 | |
7b7c1533 |
438 | for(ievent = 0; ievent < nevents; ievent++){ |
b3690abb |
439 | |
9891b76e |
440 | if(fManager){ |
b22e4735 |
441 | |
3f81a70b |
442 | Int_t input ; |
9891b76e |
443 | for(input = 0 ; input < fManager->GetNinputs(); input ++){ |
444 | TTree * treeS = fManager->GetInputTreeS(input) ; |
3f81a70b |
445 | if(!treeS){ |
b22e4735 |
446 | cerr << "AliPHOSDigitizer::Exec -> No Input " << endl ; |
3f81a70b |
447 | return ; |
448 | } |
449 | gime->ReadTreeS(treeS,input) ; |
450 | } |
b22e4735 |
451 | |
3f81a70b |
452 | } |
453 | else |
454 | gime->Event(ievent,"S") ; |
990119d6 |
455 | |
7b7c1533 |
456 | Digitize(ievent) ; //Add prepared SDigits to digits and add the noise |
3f81a70b |
457 | |
7b7c1533 |
458 | WriteDigits(ievent) ; |
3f81a70b |
459 | |
01a599c9 |
460 | if(strstr(option,"deb")) |
461 | PrintDigits(option); |
94de8339 |
462 | |
463 | //increment the total number of Digits per run |
464 | fDigitsInRun += gime->Digits()->GetEntriesFast() ; |
01a599c9 |
465 | } |
8d0f3f77 |
466 | |
8cb3533f |
467 | if(strstr(option,"tim")){ |
468 | gBenchmark->Stop("PHOSDigitizer"); |
469 | cout << "AliPHOSDigitizer:" << endl ; |
ba54256b |
470 | cout << " took " << gBenchmark->GetCpuTime("PHOSDigitizer") << " seconds for Digitizing " |
471 | << gBenchmark->GetCpuTime("PHOSDigitizer")/nevents << " seconds per event " << endl ; |
8cb3533f |
472 | cout << endl ; |
473 | } |
990119d6 |
474 | |
475 | } |
476 | |
9688c1dd |
477 | //____________________________________________________________________________ |
7437a0f7 |
478 | Float_t AliPHOSDigitizer::FrontEdgeTime(TClonesArray * ticks) |
9688c1dd |
479 | { // |
7437a0f7 |
480 | ticks->Sort() ; //Sort in accordance with times of ticks |
481 | TIter it(ticks) ; |
482 | AliPHOSTick * ctick = (AliPHOSTick *) it.Next() ; |
483 | Float_t time = ctick->CrossingTime(fTimeThreshold) ; |
484 | |
485 | AliPHOSTick * t ; |
486 | while((t=(AliPHOSTick*) it.Next())){ |
487 | if(t->GetTime() < time) //This tick starts before crossing |
488 | *ctick+=*t ; |
489 | else |
490 | return time ; |
491 | |
492 | time = ctick->CrossingTime(fTimeThreshold) ; |
9688c1dd |
493 | } |
494 | return time ; |
9688c1dd |
495 | } |
8d0f3f77 |
496 | |
7b7c1533 |
497 | //____________________________________________________________________________ |
3f81a70b |
498 | Bool_t AliPHOSDigitizer::Init() |
8d0f3f77 |
499 | { |
fbf811ec |
500 | // Makes all memory allocations |
501 | |
502 | if( strcmp(GetTitle(), "") == 0 ) |
503 | SetTitle("galice.root") ; |
8d0f3f77 |
504 | |
fbf811ec |
505 | AliPHOSGetter * gime = AliPHOSGetter::GetInstance(GetTitle(), GetName(), fToSplit) ; |
8d0f3f77 |
506 | if ( gime == 0 ) { |
507 | cerr << "ERROR: AliPHOSDigitizer::Init -> Could not obtain the Getter object !" << endl ; |
508 | return kFALSE; |
509 | } |
510 | |
511 | const AliPHOSGeometry * geom = gime->PHOSGeometry() ; |
b22e4735 |
512 | |
8d0f3f77 |
513 | fEmcCrystals = geom->GetNModules() * geom->GetNCristalsInModule() ; |
514 | |
515 | // Post Digits to the white board |
516 | gime->PostDigits(GetName() ) ; |
517 | |
518 | // Post Digitizer to the white board |
519 | gime->PostDigitizer(this) ; |
fbf811ec |
520 | |
521 | fSplitFile = 0 ; |
522 | if(fToSplit){ |
523 | // construct the name of the file as /path/PHOS.SDigits.root |
524 | //First - extract full path if necessary |
525 | TString digitsFileName(GetTitle()) ; |
526 | Ssiz_t islash = digitsFileName.Last('/') ; |
527 | if(islash<digitsFileName.Length()) |
528 | digitsFileName.Remove(islash+1,digitsFileName.Length()) ; |
529 | else |
530 | digitsFileName="" ; |
531 | // Next - append the file name |
532 | digitsFileName+="PHOS.Digits." ; |
533 | if((strcmp(GetName(),"Default")!=0)&&(strcmp(GetName(),"")!=0)){ |
534 | digitsFileName+=GetName() ; |
535 | digitsFileName+="." ; |
536 | } |
537 | digitsFileName+="root" ; |
538 | // Finally - check if the file already opened or open the file |
539 | fSplitFile = static_cast<TFile*>(gROOT->GetFile(digitsFileName.Data())); |
540 | if(!fSplitFile) |
541 | fSplitFile = TFile::Open(digitsFileName.Data(),"update") ; |
542 | } |
8d0f3f77 |
543 | |
544 | //Mark that we will use current header file |
545 | if(!fManager){ |
546 | gime->PostSDigits(GetName(),GetTitle()) ; |
547 | gime->PostSDigitizer(GetName(),GetTitle()) ; |
548 | } |
549 | return kTRUE ; |
550 | } |
551 | |
552 | //____________________________________________________________________________ |
553 | void AliPHOSDigitizer::InitParameters() |
a4e98857 |
554 | { |
c74936f1 |
555 | fPinNoise = 0.004 ; |
556 | fEMCDigitThreshold = 0.012 ; |
3758d9fc |
557 | fCPVNoise = 0.01; |
558 | fCPVDigitThreshold = 0.09 ; |
aaf8a71c |
559 | fTimeResolution = 0.5e-9 ; |
3758d9fc |
560 | fTimeSignalLength = 1.0e-9 ; |
561 | fDigitsInRun = 0 ; |
562 | fADCchanelEmc = 0.0015; // width of one ADC channel in GeV |
563 | fADCpedestalEmc = 0.005 ; // |
564 | fNADCemc = (Int_t) TMath::Power(2,16) ; // number of channels in EMC ADC |
565 | |
566 | fADCchanelCpv = 0.0012 ; // width of one ADC channel in CPV 'popugais' |
567 | fADCpedestalCpv = 0.012 ; // |
568 | fNADCcpv = (Int_t) TMath::Power(2,12); // number of channels in CPV ADC |
569 | |
570 | fTimeThreshold = 0.001*10000000 ; //Means 1 MeV in terms of SDigits amplitude |
8cb3533f |
571 | |
990119d6 |
572 | } |
7b7c1533 |
573 | |
990119d6 |
574 | //__________________________________________________________________ |
7b7c1533 |
575 | void AliPHOSDigitizer::MixWith(const char* headerFile) |
a4e98857 |
576 | { |
ba54256b |
577 | // Allows to produce digits by superimposing background and signal event. |
bca3b32a |
578 | // It is assumed, that headers file with SIGNAL events is opened in |
a4e98857 |
579 | // the constructor. |
580 | // Sets the BACKGROUND event, with which the SIGNAL event is to be mixed |
581 | // Thus we avoid writing (changing) huge and expensive |
bca3b32a |
582 | // backgound files: all output will be writen into SIGNAL, i.e. |
583 | // opened in constructor file. |
584 | // |
a4e98857 |
585 | // One can open as many files to mix with as one needs. |
7b7c1533 |
586 | // However only Sdigits with the same name (i.e. constructed with the same SDigitizer) |
587 | // can be mixed. |
bca3b32a |
588 | |
7b7c1533 |
589 | if( strcmp(GetName(), "") == 0 ) |
8cb3533f |
590 | Init() ; |
591 | |
9891b76e |
592 | if(fManager){ |
3f81a70b |
593 | cout << "Can not use this method under AliRunDigitizer " << endl ; |
594 | return ; |
595 | } |
7b7c1533 |
596 | |
597 | // check if the specified SDigits do not already exist on the White Board: |
aad24ee7 |
598 | // //Folders/RunMC/Event/Data/PHOS/SDigits/headerFile/sdigitsname |
990119d6 |
599 | |
548f0134 |
600 | AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ; |
601 | TString path = gime->SDigitsFolder()->GetName() ; |
602 | |
603 | // before it was ???? "Folders/RunMC/Event/Data/PHOS/SDigits" ; |
7b7c1533 |
604 | path += headerFile ; |
605 | path += "/" ; |
3f81a70b |
606 | path += GetName() ; |
7b7c1533 |
607 | if ( gROOT->FindObjectAny(path.Data()) ) { |
608 | cerr << "WARNING: AliPHOSDigitizer::MixWith -> Entry already exists, do not add" << endl ; |
609 | return; |
990119d6 |
610 | } |
3f81a70b |
611 | |
3f81a70b |
612 | gime->PostSDigits(GetName(),headerFile) ; |
613 | |
7b7c1533 |
614 | // check if the requested file is already open or exist and if SDigits Branch exist |
615 | TFile * file = (TFile*)gROOT->FindObject(headerFile); |
616 | if ( !file ) { |
617 | file = new TFile(headerFile, "READ") ; |
618 | if (!file) { |
619 | cerr << "ERROR: AliPHOSDigitizer::MixWith -> File " << headerFile << " does not exist!" << endl ; |
620 | return ; |
621 | } |
622 | } |
3f81a70b |
623 | |
990119d6 |
624 | } |
7b7c1533 |
625 | |
990119d6 |
626 | //__________________________________________________________________ |
dd5c4038 |
627 | void AliPHOSDigitizer::Print(Option_t* option)const { |
628 | // Print Digitizer's parameters |
7b7c1533 |
629 | if( strcmp(GetName(), "") != 0 ){ |
fbf811ec |
630 | |
631 | |
8cb3533f |
632 | cout << "------------------- "<< GetName() << " -------------" << endl ; |
6e89b8da |
633 | |
634 | const Int_t nStreams = GetNInputStreams() ; |
635 | if (nStreams) { |
636 | Int_t index = 0 ; |
637 | for (index = 0 ; index < nStreams ; index++) |
3685cf52 |
638 | cout << "Adding SDigits " << GetName() << " from " << fManager->GetInputFileName(index, 0) << endl ; |
6e89b8da |
639 | |
ea5f3389 |
640 | cout << endl ; |
3685cf52 |
641 | cout << "Writing digits to " << fManager->GetInputFileName(0, 0) << endl ; |
6e89b8da |
642 | } else { |
643 | // AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ; |
644 | // gime->Folder("sdigits") ; |
645 | // cout << "Digitizing sDigits from file(s): " <<endl ; |
646 | // TCollection * folderslist = gime->Folder("sdigits")->GetListOfFolders() ; |
647 | // TIter next(folderslist) ; |
648 | // TFolder * folder = 0 ; |
ea5f3389 |
649 | |
6e89b8da |
650 | // while ( (folder = (TFolder*)next()) ) { |
651 | // if ( folder->FindObject(GetName()) ) |
fbf811ec |
652 | // cout << "Adding SDigits " << GetName() << " from " << GetSDigitsFileName() << endl ; |
6e89b8da |
653 | // } |
ea5f3389 |
654 | cout << endl ; |
655 | cout << "Writing digits to " << GetTitle() << endl ; |
656 | } |
8cb3533f |
657 | cout << endl ; |
658 | cout << "With following parameters: " << endl ; |
659 | cout << " Electronics noise in EMC (fPinNoise) = " << fPinNoise << endl ; |
660 | cout << " Threshold in EMC (fEMCDigitThreshold) = " << fEMCDigitThreshold << endl ; ; |
661 | cout << " Noise in CPV (fCPVNoise) = " << fCPVNoise << endl ; |
662 | cout << " Threshold in CPV (fCPVDigitThreshold) = " << fCPVDigitThreshold << endl ; |
8cb3533f |
663 | cout << "---------------------------------------------------" << endl ; |
990119d6 |
664 | } |
8cb3533f |
665 | else |
666 | cout << "AliPHOSDigitizer not initialized " << endl ; |
667 | |
668 | } |
9688c1dd |
669 | |
8cb3533f |
670 | //__________________________________________________________________ |
dd5c4038 |
671 | void AliPHOSDigitizer::PrintDigits(Option_t * option){ |
672 | // Print a table of digits |
a4e98857 |
673 | |
7b7c1533 |
674 | AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ; |
675 | TClonesArray * digits = gime->Digits() ; |
676 | |
01a599c9 |
677 | cout << "AliPHOSDigitiser: event " << gAlice->GetEvNumber() << endl ; |
7b7c1533 |
678 | cout << " Number of entries in Digits list " << digits->GetEntriesFast() << endl ; |
990119d6 |
679 | cout << endl ; |
9688c1dd |
680 | if(strstr(option,"all")||strstr(option,"EMC")){ |
8cb3533f |
681 | |
682 | //loop over digits |
683 | AliPHOSDigit * digit; |
a6eedfad |
684 | cout << "EMC digits (with primaries): " << endl ; |
685 | cout << "Digit Id Amplitude Index Nprim Primaries list " << endl; |
9688c1dd |
686 | Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ; |
8cb3533f |
687 | Int_t index ; |
a6eedfad |
688 | for (index = 0 ; (index < digits->GetEntriesFast()) && |
9688c1dd |
689 | (((AliPHOSDigit * ) digits->At(index))->GetId() <= maxEmc) ; index++) { |
7b7c1533 |
690 | digit = (AliPHOSDigit * ) digits->At(index) ; |
9688c1dd |
691 | if(digit->GetNprimary() == 0) continue; |
692 | cout << setw(6) << digit->GetId() << " " << setw(10) << digit->GetAmp() << " " |
693 | << setw(6) << digit->GetIndexInList() << " " |
694 | << setw(5) << digit->GetNprimary() <<" "; |
8cb3533f |
695 | |
696 | Int_t iprimary; |
697 | for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) |
9688c1dd |
698 | cout << setw(5) << digit->GetPrimary(iprimary+1) << " "; |
8cb3533f |
699 | cout << endl; |
9688c1dd |
700 | } |
701 | cout << endl; |
702 | } |
703 | |
704 | if(strstr(option,"all")||strstr(option,"CPV")){ |
8cb3533f |
705 | |
9688c1dd |
706 | //loop over CPV digits |
707 | AliPHOSDigit * digit; |
a6eedfad |
708 | cout << "CPV digits: " << endl ; |
709 | cout << "Digit Id Amplitude Index Nprim Primaries list " << endl; |
9688c1dd |
710 | Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ; |
711 | Int_t index ; |
a6eedfad |
712 | for (index = 0 ; index < digits->GetEntriesFast(); index++) { |
9688c1dd |
713 | digit = (AliPHOSDigit * ) digits->At(index) ; |
714 | if(digit->GetId() > maxEmc){ |
715 | cout << setw(6) << digit->GetId() << " " << setw(10) << digit->GetAmp() << " " |
716 | << setw(6) << digit->GetIndexInList() << " " |
717 | << setw(5) << digit->GetNprimary() <<" "; |
718 | |
719 | Int_t iprimary; |
720 | for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) |
721 | cout << setw(5) << digit->GetPrimary(iprimary+1) << " "; |
722 | cout << endl; |
723 | } |
724 | } |
8cb3533f |
725 | } |
9688c1dd |
726 | |
8cb3533f |
727 | } |
7b7c1533 |
728 | |
9688c1dd |
729 | //__________________________________________________________________ |
730 | Float_t AliPHOSDigitizer::TimeOfNoise(void) |
731 | { // Calculates the time signal generated by noise |
732 | //to be rewritten, now returns just big number |
733 | return 1. ; |
734 | |
8cb3533f |
735 | } |
7b7c1533 |
736 | |
737 | //____________________________________________________________________________ |
738 | void AliPHOSDigitizer::WriteDigits(Int_t event) |
739 | { |
740 | |
741 | // Makes TreeD in the output file. |
742 | // Check if branch already exists: |
743 | // if yes, exit without writing: ROOT TTree does not support overwriting/updating of |
744 | // already existing branches. |
745 | // else creates branch with Digits, named "PHOS", title "...", |
746 | // and branch "AliPHOSDigitizer", with the same title to keep all the parameters |
747 | // and names of files, from which digits are made. |
748 | |
749 | AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ; |
aad24ee7 |
750 | const TClonesArray * digits = gime->Digits(GetName()) ; |
8d0f3f77 |
751 | TTree * treeD ; |
fbf811ec |
752 | |
753 | if(fManager) |
754 | treeD = fManager->GetTreeD() ; |
755 | else { |
756 | if((gAlice->TreeD() == 0) || (fSplitFile)) // we should not create TreeD if it is already here |
757 | gAlice->MakeTree("D", fSplitFile); // We overwrite TreeD in split file in the case of second reconstruction |
758 | if(fSplitFile) |
759 | fSplitFile->cd() ; |
760 | treeD = gAlice->TreeD(); |
761 | } |
762 | |
7b7c1533 |
763 | // -- create Digits branch |
764 | Int_t bufferSize = 32000 ; |
ba54256b |
765 | TBranch * digitsBranch = treeD->Branch("PHOS",&digits,bufferSize); |
7b7c1533 |
766 | digitsBranch->SetTitle(GetName()); |
fbf811ec |
767 | |
7b7c1533 |
768 | // -- Create Digitizer branch |
769 | Int_t splitlevel = 0 ; |
c2cd5471 |
770 | const AliPHOSDigitizer * d = dynamic_cast<const AliPHOSDigitizer *>(gime->Digitizer()) ; |
ba54256b |
771 | TBranch * digitizerBranch = treeD->Branch("AliPHOSDigitizer", "AliPHOSDigitizer", &d,bufferSize,splitlevel); |
7b7c1533 |
772 | digitizerBranch->SetTitle(GetName()); |
b3690abb |
773 | |
ec85099a |
774 | digitsBranch->Fill() ; |
64c73770 |
775 | digitizerBranch->Fill() ; |
b3690abb |
776 | treeD->AutoSave() ; |
7b7c1533 |
777 | } |