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