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