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