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