]>
Commit | Line | Data |
---|---|---|
61e0abb5 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
16 | /* $Id$ */ | |
17 | ||
18 | //_________________________________________________________________________ | |
ffa6d63b | 19 | // |
61e0abb5 | 20 | ////////////////////////////////////////////////////////////////////////////// |
ffa6d63b | 21 | // Class performs digitization of Summable digits |
22 | // | |
61e0abb5 | 23 | // In addition it performs mixing of summable digits from different events. |
24 | // | |
25 | // For each event two branches are created in TreeD: | |
26 | // "EMCAL" - list of digits | |
27 | // "AliEMCALDigitizer" - AliEMCALDigitizer with all parameters used in digitization | |
28 | // | |
29 | // Note, that one cset title for new digits branch, and repeat digitization with | |
30 | // another set of parameters. | |
31 | // | |
32 | // Examples of use: | |
33 | // root[0] AliEMCALDigitizer * d = new AliEMCALDigitizer() ; | |
34 | // root[1] d->ExecuteTask() | |
35 | // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated | |
36 | // //Digitizes SDigitis in all events found in file galice.root | |
37 | // | |
38 | // root[2] AliEMCALDigitizer * d1 = new AliEMCALDigitizer("galice1.root") ; | |
39 | // // Will read sdigits from galice1.root | |
40 | // root[3] d1->MixWith("galice2.root") | |
41 | // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated | |
42 | // // Reads another portion of sdigits from galice2.root | |
43 | // root[3] d1->MixWith("galice3.root") | |
44 | // // Reads another portion of sdigits from galice3.root | |
45 | // root[4] d->ExecuteTask("deb timing") | |
46 | // // Reads SDigits from files galice1.root, galice2.root .... | |
47 | // // mixes them and stores produced Digits in file galice1.root | |
48 | // // deb - prints number of produced digits | |
49 | // // deb all - prints list of produced digits | |
50 | // // timing - prints time used for digitization | |
ffa6d63b | 51 | //////////////////////////////////////////////////////////////////////////////////// |
61e0abb5 | 52 | // |
ffa6d63b | 53 | //*-- Author: Sahal Yacoob (LBL) |
814ad4bf | 54 | // based on : AliEMCALDigitizer |
ffa6d63b | 55 | //_________________________________________________________________________________ |
61e0abb5 | 56 | |
57 | // --- ROOT system --- | |
58 | #include "TFile.h" | |
59 | #include "TTree.h" | |
60 | #include "TSystem.h" | |
61 | #include "TROOT.h" | |
62 | #include "TFolder.h" | |
63 | #include "TObjString.h" | |
54cbf5a6 | 64 | #include "TGeometry.h" |
61e0abb5 | 65 | #include "TBenchmark.h" |
66 | // --- Standard library --- | |
67 | #include <iomanip.h> | |
68 | ||
69 | // --- AliRoot header files --- | |
70 | ||
71 | #include "AliRun.h" | |
54cbf5a6 | 72 | #include "AliHeader.h" |
61e0abb5 | 73 | #include "AliEMCALDigit.h" |
74 | #include "AliEMCALHit.h" | |
814ad4bf | 75 | #include "AliEMCALTick.h" |
61e0abb5 | 76 | #include "AliEMCALv1.h" |
77 | #include "AliEMCALDigitizer.h" | |
78 | #include "AliEMCALSDigitizer.h" | |
79 | #include "AliEMCALGeometry.h" | |
814ad4bf | 80 | #include "AliEMCALGetter.h" |
81 | #include "AliRunDigitizer.h" | |
61e0abb5 | 82 | ClassImp(AliEMCALDigitizer) |
83 | ||
84 | ||
85 | //____________________________________________________________________________ | |
814ad4bf | 86 | AliEMCALDigitizer::AliEMCALDigitizer() |
61e0abb5 | 87 | { |
88 | // ctor | |
89 | ||
839828a6 | 90 | InitParameters() ; |
61e0abb5 | 91 | |
839828a6 | 92 | } |
61e0abb5 | 93 | |
839828a6 | 94 | //____________________________________________________________________________ |
95 | AliEMCALDigitizer::AliEMCALDigitizer(const char *headerFile,const char *name) | |
96 | { | |
97 | SetName(name) ; | |
98 | SetTitle(headerFile) ; | |
99 | fManager = 0 ; // We work in the standalong mode | |
100 | fSplitFile= 0 ; | |
101 | InitParameters() ; | |
102 | Init() ; | |
61e0abb5 | 103 | |
61e0abb5 | 104 | } |
839828a6 | 105 | |
61e0abb5 | 106 | //____________________________________________________________________________ |
839828a6 | 107 | AliEMCALDigitizer::AliEMCALDigitizer(AliRunDigitizer * ard):AliDigitizer(ard) |
61e0abb5 | 108 | { |
839828a6 | 109 | // ctor |
110 | SetName(""); //Will call init in the digitizing | |
111 | SetTitle("aliroot") ; | |
112 | } | |
814ad4bf | 113 | |
839828a6 | 114 | //____________________________________________________________________________ |
115 | AliEMCALDigitizer::~AliEMCALDigitizer() | |
116 | { | |
117 | // dtor | |
118 | ||
119 | AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ; | |
120 | ||
121 | // remove the task from the folder list | |
122 | gime->RemoveTask("S",GetName()) ; | |
123 | gime->RemoveTask("D",GetName()) ; | |
124 | ||
125 | // remove the Digits from the folder list | |
126 | gime->RemoveObjects("D", GetName()) ; | |
127 | ||
128 | // remove the SDigits from the folder list | |
129 | gime->RemoveSDigits() ; | |
130 | ||
131 | // Delete gAlice | |
132 | gime->CloseFile() ; | |
133 | ||
134 | fSplitFile = 0 ; | |
135 | } | |
136 | ||
137 | //____________________________________________________________________________ | |
138 | void AliEMCALDigitizer::InitParameters() | |
139 | { | |
814ad4bf | 140 | fSDigitizer = 0 ; |
141 | fNinputs = 1 ; | |
d968cee0 | 142 | fPinNoise = 0.00001 ; |
143 | fTowerDigitThreshold = 0.001 ; | |
814ad4bf | 144 | fTimeResolution = 0.5e-9 ; |
145 | fTimeSignalLength = 1.0e-9 ; | |
d968cee0 | 146 | fPreShowerDigitThreshold = fTowerDigitThreshold/25. ; |
814ad4bf | 147 | fInitialized = kFALSE ; |
b66c1acf | 148 | fADCchannelTower = 0.000220; // width of one ADC channel in GeV |
d968cee0 | 149 | fADCpedestalTower = 0.005 ; // GeV |
814ad4bf | 150 | fNADCTower = (Int_t) TMath::Power(2,16) ; // number of channels in Tower ADC |
151 | ||
556fa06b | 152 | fADCchannelPreSho = 0.0000300; // width of one ADC channel in Pre Shower |
814ad4bf | 153 | fADCpedestalPreSho = 0.005 ; // |
d968cee0 | 154 | fNADCPreSho = (Int_t) TMath::Power(2,12); // number of channels in Pre ShowerADC |
814ad4bf | 155 | |
e41b8233 | 156 | fTimeThreshold = 0.001*10000000 ; //Means 1 MeV in terms of SDigits amplitude |
157 | ||
556fa06b | 158 | |
159 | ||
54b82aa4 | 160 | if(fManager) |
814ad4bf | 161 | SetTitle("aliroot") ; |
162 | else if (strcmp(GetTitle(),"")==0) | |
54b82aa4 | 163 | SetTitle("galice.root") ; |
164 | ||
814ad4bf | 165 | if( strcmp(GetName(), "") == 0 ) |
166 | SetName("Default") ; | |
61e0abb5 | 167 | |
839828a6 | 168 | } |
169 | ||
170 | //____________________________________________________________________________ | |
171 | Bool_t AliEMCALDigitizer::Init() | |
172 | { | |
173 | // Makes all memory allocations | |
174 | ||
814ad4bf | 175 | AliEMCALGetter * gime = AliEMCALGetter::GetInstance(GetTitle(), GetName(), "update") ; |
176 | if ( gime == 0 ) { | |
177 | cerr << "ERROR: AliEMCALDigitizer::Init -> Could not obtain the Getter object !" << endl ; | |
178 | return kFALSE; | |
179 | } | |
61e0abb5 | 180 | |
814ad4bf | 181 | //const AliEMCALGeometry * geom = gime->EMCALGeometry() ; |
182 | //fEmcCrystals = geom->GetNModules() * geom->GetNCristalsInModule() ; | |
61e0abb5 | 183 | |
814ad4bf | 184 | // Post Digits to the white board |
185 | gime->PostDigits(GetName() ) ; | |
61e0abb5 | 186 | |
814ad4bf | 187 | // Post Digitizer to the white board |
188 | gime->PostDigitizer(this) ; | |
61e0abb5 | 189 | |
814ad4bf | 190 | //Mark that we will use current header file |
191 | if(!fManager){ | |
192 | gime->PostSDigits(GetName(),GetTitle()) ; | |
193 | gime->PostSDigitizer(GetName(),GetTitle()) ; | |
194 | } | |
195 | return kTRUE ; | |
839828a6 | 196 | |
61e0abb5 | 197 | } |
64c73770 | 198 | |
61e0abb5 | 199 | //____________________________________________________________________________ |
200 | void AliEMCALDigitizer::Reset() { | |
201 | //sets current event number to the first simulated event | |
814ad4bf | 202 | if( strcmp(GetName(), "") == 0 ) |
203 | Init() ; | |
61e0abb5 | 204 | |
814ad4bf | 205 | // Int_t inputs ; |
206 | // for(inputs = 0; inputs < fNinputs ;inputs++) | |
207 | // fIevent->AddAt(-1, inputs ) ; | |
61e0abb5 | 208 | |
209 | } | |
210 | ||
211 | //____________________________________________________________________________ | |
814ad4bf | 212 | void AliEMCALDigitizer::Digitize(const Int_t event) { |
61e0abb5 | 213 | |
214 | // Makes the digitization of the collected summable digits | |
215 | // for this it first creates the array of all EMCAL modules | |
216 | // filled with noise (different for EMC, CPV and PPSD) and | |
217 | // after that adds contributions from SDigits. This design | |
218 | // helps to avoid scanning over the list of digits to add | |
219 | // contribution of any new SDigit. | |
220 | ||
814ad4bf | 221 | AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ; |
222 | TClonesArray * digits = gime->Digits(GetName()) ; | |
223 | ||
224 | digits->Clear() ; | |
61e0abb5 | 225 | |
814ad4bf | 226 | const AliEMCALGeometry *geom = gime->EMCALGeometry() ; |
61e0abb5 | 227 | |
61e0abb5 | 228 | |
229 | //Making digits with noise, first EMC | |
ffa6d63b | 230 | Int_t nEMC = 2*geom->GetNPhi()*geom->GetNZ(); |
61e0abb5 | 231 | Int_t absID ; |
232 | TString name = geom->GetName() ; | |
61e0abb5 | 233 | |
814ad4bf | 234 | // get first the sdigitizer from the tasks list (must have same name as the digitizer) |
235 | const AliEMCALSDigitizer * sDigitizer = gime->SDigitizer(GetName()); | |
236 | if ( !sDigitizer) { | |
237 | cerr << "ERROR: AliEMCALDigitizer::Digitize -> SDigitizer with name " << GetName() << " not found " << endl ; | |
238 | abort() ; | |
61e0abb5 | 239 | } |
814ad4bf | 240 | // loop through the sdigits posted to the White Board and add them to the noise |
241 | TCollection * folderslist = gime->SDigitsFolder()->GetListOfFolders() ; | |
242 | TIter next(folderslist) ; | |
243 | TFolder * folder = 0 ; | |
244 | TClonesArray * sdigits = 0 ; | |
245 | Int_t input = 0 ; | |
246 | TObjArray * sdigArray = new TObjArray(2) ; | |
247 | while ( (folder = (TFolder*)next()) ) | |
248 | if ( (sdigits = (TClonesArray*)folder->FindObject(GetName()) ) ) { | |
54b82aa4 | 249 | TString fileName(folder->GetName()) ; |
250 | fileName.ReplaceAll("_","/") ; | |
814ad4bf | 251 | cout << "INFO: AliEMCALDigitizer::Digitize -> Adding SDigits " |
54b82aa4 | 252 | << GetName() << " from " << fileName << endl ; |
814ad4bf | 253 | sdigArray->AddAt(sdigits, input) ; |
254 | input++ ; | |
255 | } | |
61e0abb5 | 256 | |
54cbf5a6 | 257 | |
d968cee0 | 258 | //Find the first tower with signal |
814ad4bf | 259 | Int_t nextSig = 200000 ; |
260 | Int_t i; | |
261 | for(i=0; i<input; i++){ | |
262 | sdigits = (TClonesArray *)sdigArray->At(i) ; | |
263 | if ( !sdigits->GetEntriesFast() ) | |
264 | continue ; | |
265 | Int_t curNext = ((AliEMCALDigit *)sdigits->At(0))->GetId() ; | |
266 | if(curNext < nextSig) | |
267 | nextSig = curNext ; | |
268 | } | |
61e0abb5 | 269 | |
814ad4bf | 270 | TArrayI index(input) ; |
271 | index.Reset() ; //Set all indexes to zero | |
61e0abb5 | 272 | |
814ad4bf | 273 | AliEMCALDigit * digit = 0 ; |
274 | AliEMCALDigit * curSDigit = 0 ; | |
ffa6d63b | 275 | |
814ad4bf | 276 | TClonesArray * ticks = new TClonesArray("AliEMCALTick",1000) ; |
ffa6d63b | 277 | |
814ad4bf | 278 | //Put Noise contribution |
279 | for(absID = 1; absID <= nEMC; absID++){ | |
d968cee0 | 280 | Float_t noise = gRandom->Gaus(0., fPinNoise); |
814ad4bf | 281 | new((*digits)[absID-1]) AliEMCALDigit( -1, -1, absID,sDigitizer->Digitize(noise), TimeOfNoise() ) ; |
282 | //look if we have to add signal? | |
54cbf5a6 | 283 | digit = (AliEMCALDigit *) digits->At(absID-1) ; |
814ad4bf | 284 | if(absID==nextSig){ |
54cbf5a6 | 285 | //Add SDigits from all inputs |
814ad4bf | 286 | ticks->Clear() ; |
287 | Int_t contrib = 0 ; | |
288 | Float_t a = digit->GetAmp() ; | |
289 | Float_t b = TMath::Abs( a /fTimeSignalLength) ; | |
290 | //Mark the beginnign of the signal | |
291 | new((*ticks)[contrib++]) AliEMCALTick(digit->GetTime(),0, b); | |
292 | //Mark the end of the ignal | |
293 | new((*ticks)[contrib++]) AliEMCALTick(digit->GetTime()+fTimeSignalLength, -a, -b); | |
294 | ||
295 | // loop over input | |
296 | ||
297 | for(i = 0; i< input ; i++){ //loop over (possible) merge sources | |
298 | if(((TClonesArray *)sdigArray->At(i))->GetEntriesFast() > index[i] ) | |
299 | curSDigit = (AliEMCALDigit*)((TClonesArray *)sdigArray->At(i))->At(index[i]) ; | |
300 | else | |
301 | curSDigit = 0 ; | |
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 ; | |
306 | if(fManager) | |
307 | primaryoffset = fManager->GetMask(i) ; | |
308 | else | |
309 | primaryoffset = i ; | |
310 | curSDigit->ShiftPrimary(primaryoffset) ; | |
311 | ||
312 | a = curSDigit->GetAmp() ; | |
313 | b = a /fTimeSignalLength ; | |
314 | new((*ticks)[contrib++]) AliEMCALTick(curSDigit->GetTime(),0, b); | |
315 | new((*ticks)[contrib++]) AliEMCALTick(curSDigit->GetTime()+fTimeSignalLength, -a, -b); | |
316 | ||
317 | *digit = *digit + *curSDigit ; //add energies | |
318 | ||
319 | index[i]++ ; | |
320 | if(((TClonesArray *)sdigArray->At(i))->GetEntriesFast() > index[i] ) | |
321 | curSDigit = (AliEMCALDigit*)((TClonesArray *)sdigArray->At(i))->At(index[i]) ; | |
322 | else | |
323 | curSDigit = 0 ; | |
e41b8233 | 324 | } |
325 | } | |
556fa06b | 326 | |
814ad4bf | 327 | //calculate and set time |
328 | Float_t time = FrontEdgeTime(ticks) ; | |
329 | digit->SetTime(time) ; | |
330 | ||
331 | //Find next signal module | |
332 | nextSig = 200000 ; | |
333 | for(i=0; i<input; i++){ | |
334 | sdigits = ((TClonesArray *)sdigArray->At(i)) ; | |
335 | Int_t curNext = nextSig ; | |
336 | if(sdigits->GetEntriesFast() > index[i] ){ | |
337 | curNext = ((AliEMCALDigit *) sdigits->At(index[i]))->GetId() ; | |
338 | ||
339 | } | |
340 | if(curNext < nextSig) nextSig = curNext ; | |
341 | } | |
342 | } | |
343 | } | |
344 | ||
345 | ticks->Delete() ; | |
346 | delete ticks ; | |
61e0abb5 | 347 | |
61e0abb5 | 348 | |
61e0abb5 | 349 | |
61e0abb5 | 350 | |
814ad4bf | 351 | //remove digits below thresholds |
839828a6 | 352 | |
814ad4bf | 353 | for(absID = 0; absID < nEMC/2 ; absID++){ |
839828a6 | 354 | if(sDigitizer->Calibrate(((AliEMCALDigit*)digits->At(absID))->GetAmp()) < fTowerDigitThreshold) |
814ad4bf | 355 | digits->RemoveAt(absID) ; |
356 | else | |
357 | digit->SetTime(gRandom->Gaus(digit->GetTime(),fTimeResolution) ) ; | |
358 | } | |
61e0abb5 | 359 | |
814ad4bf | 360 | for(absID = nEMC/2; absID < nEMC ; absID++){ |
54cbf5a6 | 361 | |
814ad4bf | 362 | if(sDigitizer->Calibrate(((AliEMCALDigit*)digits->At(absID))->GetAmp()) < fPreShowerDigitThreshold) |
363 | digits->RemoveAt(absID) ; | |
364 | else | |
365 | digit->SetTime(gRandom->Gaus(digit->GetTime(),fTimeResolution) ) ; | |
61e0abb5 | 366 | } |
367 | ||
814ad4bf | 368 | digits->Compress() ; |
61e0abb5 | 369 | |
814ad4bf | 370 | Int_t ndigits = digits->GetEntriesFast() ; |
61e0abb5 | 371 | |
814ad4bf | 372 | digits->Expand(ndigits) ; |
61e0abb5 | 373 | |
61e0abb5 | 374 | |
814ad4bf | 375 | //Set indexes in list of digits |
376 | //Int_t i ; | |
ec803232 | 377 | for (i = 0 ; i < ndigits ; i++) { |
814ad4bf | 378 | AliEMCALDigit * digit = (AliEMCALDigit *) digits->At(i) ; |
379 | digit->SetIndexInList(i) ; | |
380 | Float_t energy = sDigitizer->Calibrate(digit->GetAmp()) ; | |
381 | digit->SetAmp(DigitizeEnergy(energy,digit->GetId()) ) ; | |
61e0abb5 | 382 | } |
814ad4bf | 383 | } |
61e0abb5 | 384 | |
814ad4bf | 385 | //____________________________________________________________________________ |
61e0abb5 | 386 | |
814ad4bf | 387 | Int_t AliEMCALDigitizer::DigitizeEnergy(Float_t energy, Int_t absId) |
388 | { | |
389 | Int_t channel = -999; | |
390 | Int_t nphi = AliEMCALGetter::GetInstance()->EMCALGeometry()->GetNPhi() ; | |
391 | Int_t nz = AliEMCALGetter::GetInstance()->EMCALGeometry()->GetNZ() ; | |
392 | ||
ec803232 | 393 | if(absId <= nphi*nz){ //digitize as tower |
394 | channel = static_cast<Int_t> (TMath::Ceil( (energy + fADCpedestalTower)/fADCchannelTower )) ; | |
395 | if(channel > fNADCTower ) | |
396 | channel = fNADCTower ; | |
397 | } else { | |
398 | channel = static_cast<Int_t>(TMath::Ceil( (energy + fADCpedestalPreSho)/fADCchannelPreSho )) ; | |
399 | if(channel > fNADCPreSho ) | |
400 | channel = fNADCPreSho ; | |
401 | } | |
814ad4bf | 402 | |
403 | return channel ; | |
61e0abb5 | 404 | } |
405 | ||
406 | //____________________________________________________________________________ | |
407 | void AliEMCALDigitizer::Exec(Option_t *option) { | |
408 | // Managing method | |
814ad4bf | 409 | if(strcmp(GetName(), "") == 0 ) |
410 | Init() ; | |
411 | ||
412 | if (strstr(option,"print")) { | |
413 | Print(""); | |
414 | return ; | |
415 | } | |
416 | ||
61e0abb5 | 417 | if(strstr(option,"tim")) |
418 | gBenchmark->Start("EMCALDigitizer"); | |
419 | ||
814ad4bf | 420 | AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ; |
421 | ||
422 | Int_t nevents ; | |
423 | ||
424 | TTree * treeD ; | |
425 | ||
426 | if(fManager){ | |
427 | treeD = fManager->GetTreeD() ; | |
428 | nevents = 1 ; // Will process only one event | |
429 | } | |
430 | else { | |
431 | gAlice->GetEvent(0) ; | |
432 | nevents = (Int_t) gAlice->TreeE()->GetEntries() ; | |
433 | treeD=gAlice->TreeD() ; | |
434 | } | |
54cbf5a6 | 435 | |
814ad4bf | 436 | |
437 | //Check, if this branch already exits | |
54cbf5a6 | 438 | if (treeD) { |
439 | TObjArray * lob = (TObjArray*)treeD->GetListOfBranches() ; | |
440 | TIter next(lob) ; | |
441 | TBranch * branch = 0 ; | |
442 | Bool_t emcalfound = kFALSE, digitizerfound = kFALSE ; | |
443 | ||
444 | while ( (branch = (TBranch*)next()) && (!emcalfound || !digitizerfound) ) { | |
445 | if ( (strcmp(branch->GetName(), "EMCAL")==0) && | |
446 | (strcmp(branch->GetTitle(), GetName())==0) ) | |
447 | emcalfound = kTRUE ; | |
448 | ||
449 | else if ( (strcmp(branch->GetName(), "AliEMCALDigitizer")==0) && | |
450 | (strcmp(branch->GetTitle(), GetName())==0) ) | |
451 | digitizerfound = kTRUE ; | |
452 | } | |
814ad4bf | 453 | |
54cbf5a6 | 454 | if ( emcalfound ) { |
455 | cerr << "WARNING: AliEMCALDigitizer -> Digits branch with name " << GetName() | |
456 | << " already exits" << endl ; | |
457 | return ; | |
458 | } | |
459 | if ( digitizerfound ) { | |
460 | cerr << "WARNING: AliEMCALDigitizer -> Digitizer branch with name " << GetName() | |
461 | << " already exits" << endl ; | |
462 | return ; | |
463 | } | |
814ad4bf | 464 | } |
814ad4bf | 465 | Int_t ievent ; |
466 | ||
467 | for(ievent = 0; ievent < nevents; ievent++){ | |
468 | ||
469 | if(fManager){ | |
470 | Int_t input ; | |
471 | for(input = 0 ; input < fManager->GetNinputs(); input ++){ | |
472 | TTree * treeS = fManager->GetInputTreeS(input) ; | |
473 | if(!treeS){ | |
474 | cerr << "AliEMCALDigitizer -> No Input " << endl ; | |
475 | return ; | |
476 | } | |
477 | gime->ReadTreeS(treeS,input) ; | |
478 | } | |
479 | } | |
54b82aa4 | 480 | else |
481 | gime->Event(ievent,"S") ; | |
61e0abb5 | 482 | |
814ad4bf | 483 | Digitize(ievent) ; //Add prepared SDigits to digits and add the noise |
61e0abb5 | 484 | |
814ad4bf | 485 | WriteDigits(ievent) ; |
61e0abb5 | 486 | |
487 | if(strstr(option,"deb")) | |
488 | PrintDigits(option); | |
814ad4bf | 489 | |
490 | //increment the total number of Digits per run | |
491 | fDigitsInRun += gime->Digits()->GetEntriesFast() ; | |
61e0abb5 | 492 | } |
814ad4bf | 493 | |
61e0abb5 | 494 | if(strstr(option,"tim")){ |
495 | gBenchmark->Stop("EMCALDigitizer"); | |
496 | cout << "AliEMCALDigitizer:" << endl ; | |
814ad4bf | 497 | cout << " took " << gBenchmark->GetCpuTime("EMCALDigitizer") << " seconds for Digitizing " |
498 | << gBenchmark->GetCpuTime("EMCALDigitizer")/nevents << " seconds per event " << endl ; | |
61e0abb5 | 499 | cout << endl ; |
500 | } | |
501 | ||
502 | } | |
503 | ||
61e0abb5 | 504 | |
61e0abb5 | 505 | |
61e0abb5 | 506 | //__________________________________________________________________ |
814ad4bf | 507 | void AliEMCALDigitizer::MixWith(char* headerFile){ |
61e0abb5 | 508 | // Alows produce digits by superimposing background and signal event. |
509 | // It is assumed, that headers file with SIGNAL events is opened in | |
510 | // constructor, and now we set the BACKGROUND event, with which we | |
511 | // will mix. Thus we avoid writing (changing) huge and expencive | |
512 | // backgound files: all output will be writen into SIGNAL, i.e. | |
513 | // opened in constructor file. | |
514 | // | |
515 | // One can open as many files to mix with as one wants. | |
516 | ||
814ad4bf | 517 | if( strcmp(GetName(), "") == 0 ) |
61e0abb5 | 518 | Init() ; |
814ad4bf | 519 | |
520 | if(fManager){ | |
521 | cout << "Can not use this method under AliRunDigitizer " << endl ; | |
61e0abb5 | 522 | return ; |
814ad4bf | 523 | } // check if the specified SDigits do not already exist on the White Board: |
524 | // //Folders/RunMC/Event/Data/EMCAL/SDigits/headerFile/sdigitsname | |
525 | ||
526 | TString path = "Folders/RunMC/Event/Data/EMCAL/SDigits" ; | |
527 | path += headerFile ; | |
528 | path += "/" ; | |
529 | path += GetName() ; | |
530 | if ( gROOT->FindObjectAny(path.Data()) ) { | |
531 | cerr << "WARNING: AliEMCALDigitizer::MixWith -> Entry already exists, do not add" << endl ; | |
532 | return; | |
61e0abb5 | 533 | } |
814ad4bf | 534 | |
535 | AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ; | |
536 | gime->PostSDigits(GetName(),headerFile) ; | |
61e0abb5 | 537 | |
814ad4bf | 538 | // check if the requested file is already open or exist and if SDigits Branch exist |
539 | TFile * file = (TFile*)gROOT->FindObject(headerFile); | |
540 | if ( !file ) { | |
541 | file = new TFile(headerFile, "READ") ; | |
542 | if (!file) { | |
543 | cerr << "ERROR: AliEMCALDigitizer::MixWith -> File " << headerFile << " does not exist!" << endl ; | |
544 | return ; | |
545 | } | |
546 | } | |
61e0abb5 | 547 | |
548 | } | |
814ad4bf | 549 | |
61e0abb5 | 550 | //__________________________________________________________________ |
551 | void AliEMCALDigitizer::Print(Option_t* option)const { | |
814ad4bf | 552 | if( strcmp(GetName(), "") != 0) { |
61e0abb5 | 553 | |
554 | cout << "------------------- "<< GetName() << " -------------" << endl ; | |
555 | cout << "Digitizing sDigits from file(s): " <<endl ; | |
61e0abb5 | 556 | |
814ad4bf | 557 | TCollection * folderslist = ((TFolder*)gROOT->FindObjectAny("Folders/RunMC/Event/Data/EMCAL/SDigits"))->GetListOfFolders() ; |
558 | TIter next(folderslist) ; | |
559 | TFolder * folder = 0 ; | |
560 | while ( (folder = (TFolder*)next()) ) | |
561 | if ( folder->FindObject(GetName()) ) | |
562 | { | |
563 | cout << "Adding SDigits " << GetName() << " from " << folder->GetName() << endl ; | |
564 | cout << endl ; | |
565 | cout << "Writing digits to " << GetTitle() << endl ; | |
566 | ||
567 | cout << endl ; | |
568 | cout << "With following parameters: " << endl ; | |
569 | cout << " Electronics noise in EMC (fPinNoise) = " << fPinNoise << endl ; | |
d968cee0 | 570 | cout << " Threshold in EMC (fTowerDigitThreshold) = " << fTowerDigitThreshold << endl; |
814ad4bf | 571 | cout << " Threshold in PreShower (fPreShowerDigitThreshold) = " << fPreShowerDigitThreshold << endl ; ; |
572 | cout << "---------------------------------------------------" << endl ; | |
573 | } | |
574 | else | |
575 | cout << "AliEMCALDigitizer not initialized " << endl ; | |
576 | } | |
61e0abb5 | 577 | } |
814ad4bf | 578 | |
e41b8233 | 579 | //__________________________________________________________________ |
580 | void AliEMCALDigitizer::PrintDigits(Option_t * option){ | |
61e0abb5 | 581 | |
814ad4bf | 582 | AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ; |
583 | TClonesArray * fDigits = gime->Digits() ; | |
584 | ||
61e0abb5 | 585 | cout << "AliEMCALDigitiser:"<< endl ; |
586 | cout << " Number of entries in Digits list " << fDigits->GetEntriesFast() << endl ; | |
587 | cout << endl ; | |
588 | if(strstr(option,"all")){ | |
589 | ||
590 | //loop over digits | |
591 | AliEMCALDigit * digit; | |
592 | cout << "Digit Id " << " Amplitude " << " Index " << " Nprim " << " Primaries list " << endl; | |
593 | Int_t index ; | |
594 | for (index = 0 ; index < fDigits->GetEntries() ; index++) { | |
595 | digit = (AliEMCALDigit * ) fDigits->At(index) ; | |
596 | cout << setw(8) << digit->GetId() << " " << setw(3) << digit->GetAmp() << " " | |
597 | << setw(6) << digit->GetIndexInList() << " " | |
598 | << setw(5) << digit->GetNprimary() <<" "; | |
599 | ||
600 | Int_t iprimary; | |
601 | for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) | |
602 | cout << setw(5) << digit->GetPrimary(iprimary+1) << " "; | |
603 | cout << endl; | |
604 | } | |
605 | ||
606 | } | |
607 | } | |
814ad4bf | 608 | //_________________________________________________________________________________________ |
609 | void AliEMCALDigitizer::WriteDigits(Int_t event) | |
610 | { | |
61e0abb5 | 611 | |
814ad4bf | 612 | // Makes TreeD in the output file. |
613 | // Check if branch already exists: | |
614 | // if yes, exit without writing: ROOT TTree does not support overwriting/updating of | |
615 | // already existing branches. | |
616 | // else creates branch with Digits, named "EMCAL", title "...", | |
617 | // and branch "AliEMCALDigitizer", with the same title to keep all the parameters | |
618 | // and names of files, from which digits are made. | |
61e0abb5 | 619 | |
814ad4bf | 620 | AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ; |
621 | const TClonesArray * digits = gime->Digits(GetName()) ; | |
622 | TTree * treeD ; | |
623 | ||
54cbf5a6 | 624 | if(fManager) |
625 | treeD = fManager->GetTreeD() ; | |
626 | else { | |
627 | if (!gAlice->TreeD() ) | |
64c73770 | 628 | gAlice->MakeTree("D",fSplitFile); |
54cbf5a6 | 629 | treeD = gAlice->TreeD(); |
630 | } | |
631 | ||
632 | // -- create Digits branch | |
633 | Int_t bufferSize = 32000 ; | |
634 | TBranch * digitsBranch = treeD->Branch("EMCAL",&digits,bufferSize); | |
635 | digitsBranch->SetTitle(GetName()); | |
636 | ||
637 | // -- Create Digitizer branch | |
638 | Int_t splitlevel = 0 ; | |
639 | AliEMCALDigitizer * d = gime->Digitizer(GetName()) ; | |
640 | TBranch * digitizerBranch = treeD->Branch("AliEMCALDigitizer", "AliEMCALDigitizer", &d,bufferSize,splitlevel); | |
641 | digitizerBranch->SetTitle(GetName()); | |
642 | ||
64c73770 | 643 | digitsBranch->Fill() ; |
644 | digitizerBranch->Fill() ; | |
54cbf5a6 | 645 | treeD->AutoSave() ; |
814ad4bf | 646 | |
647 | } | |
648 | //____________________________________________________________________________ | |
649 | Float_t AliEMCALDigitizer::FrontEdgeTime(TClonesArray * ticks) | |
650 | { // | |
651 | ticks->Sort() ; //Sort in accordance with times of ticks | |
652 | TIter it(ticks) ; | |
653 | AliEMCALTick * ctick = (AliEMCALTick *) it.Next() ; | |
654 | Float_t time = ctick->CrossingTime(fTimeThreshold) ; | |
655 | ||
656 | AliEMCALTick * t ; | |
657 | while((t=(AliEMCALTick*) it.Next())){ | |
658 | if(t->GetTime() < time) //This tick starts before crossing | |
659 | *ctick+=*t ; | |
660 | else | |
661 | return time ; | |
662 | ||
663 | time = ctick->CrossingTime(fTimeThreshold) ; | |
664 | } | |
665 | return time ; | |
666 | } | |
667 | //____________________________________________________________________________ | |
668 | Float_t AliEMCALDigitizer::TimeOfNoise(void) | |
669 | { // Calculates the time signal generated by noise | |
670 | //to be rewritten, now returns just big number | |
671 | return 1. ; | |
672 | ||
673 | } | |
674 | //____________________________________________________________________________ | |
675 | void AliEMCALDigitizer::SetSDigitsBranch(const char* title) | |
676 | { | |
677 | // we set title (comment) of the SDigits branch in the first! header file | |
678 | if( strcmp(GetName(), "") == 0 ) | |
679 | Init() ; | |
61e0abb5 | 680 | |
814ad4bf | 681 | AliEMCALGetter::GetInstance()->SDigits()->SetName(title) ; |
61e0abb5 | 682 | } |
54cbf5a6 | 683 | |
684 | //__________________________________________________________________ | |
64c73770 | 685 | void AliEMCALDigitizer::SetSplitFile(const TString splitFileName) |
54cbf5a6 | 686 | { |
687 | // Diverts the Digits in a file separate from the hits file | |
688 | ||
689 | // I guess it is not going to work if we do merging | |
690 | if (fManager) { | |
691 | cerr << "ERROR: AliEMCALDigitizer::SetSplitFile -> Not yet available in case of merging activated " << endl ; | |
692 | return ; | |
693 | } | |
694 | ||
695 | TDirectory * cwd = gDirectory ; | |
64c73770 | 696 | if ( !(gAlice->GetTreeDFileName() == splitFileName) ) { |
697 | if (gAlice->GetTreeDFile() ) | |
698 | gAlice->GetTreeDFile()->Close() ; | |
699 | } | |
700 | ||
701 | fSplitFile = gAlice->InitTreeFile("D",splitFileName.Data()); | |
702 | fSplitFile->cd() ; | |
839828a6 | 703 | gAlice->Write(0, TObject::kOverwrite); |
54cbf5a6 | 704 | |
705 | TTree *treeE = gAlice->TreeE(); | |
706 | if (!treeE) { | |
707 | cerr << "ERROR: AliEMCALDigitizer::SetSplitFile -> No TreeE found "<<endl; | |
708 | abort() ; | |
709 | } | |
710 | ||
711 | // copy TreeE | |
839828a6 | 712 | AliHeader *header = new AliHeader(); |
713 | treeE->SetBranchAddress("Header", &header); | |
714 | treeE->SetBranchStatus("*",1); | |
715 | TTree *treeENew = treeE->CloneTree(); | |
716 | treeENew->Write(0, TObject::kOverwrite); | |
64c73770 | 717 | |
54cbf5a6 | 718 | // copy AliceGeom |
839828a6 | 719 | TGeometry *AliceGeom = static_cast<TGeometry*>(cwd->Get("AliceGeom")); |
720 | if (!AliceGeom) { | |
721 | cerr << "ERROR: AliEMCALDigitizer::SetSplitFile -> AliceGeom was not found in the input file "<<endl; | |
722 | abort() ; | |
54cbf5a6 | 723 | } |
839828a6 | 724 | AliceGeom->Write(0, TObject::kOverwrite); |
64c73770 | 725 | |
726 | gAlice->MakeTree("D",fSplitFile); | |
54cbf5a6 | 727 | cwd->cd() ; |
54cbf5a6 | 728 | cout << "INFO: AliEMCALDigitizer::SetSPlitMode -> Digits will be stored in " << splitFileName.Data() << endl ; |
729 | } |