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