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) |
54 | // based on : AliPHOSDigitizer |
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" |
64 | #include "TBenchmark.h" |
65 | // --- Standard library --- |
66 | #include <iomanip.h> |
67 | |
68 | // --- AliRoot header files --- |
69 | |
70 | #include "AliRun.h" |
71 | #include "AliEMCALDigit.h" |
72 | #include "AliEMCALHit.h" |
73 | #include "AliEMCALv1.h" |
74 | #include "AliEMCALDigitizer.h" |
75 | #include "AliEMCALSDigitizer.h" |
76 | #include "AliEMCALGeometry.h" |
77 | |
78 | ClassImp(AliEMCALDigitizer) |
79 | |
80 | |
81 | //____________________________________________________________________________ |
82 | AliEMCALDigitizer::AliEMCALDigitizer():TTask("AliEMCALDigitizer","") |
83 | { |
84 | // ctor |
85 | |
86 | fSDigitizer = 0 ; |
87 | fNinputs = 1 ; |
ffa6d63b |
88 | fPinNoise = 0.00 ; |
89 | fEMCDigitThreshold = 0.00 ; |
61e0abb5 |
90 | fInitialized = kFALSE ; |
91 | |
92 | fHeaderFiles = 0; |
93 | fSDigitsTitles = 0; |
94 | fSDigits = 0 ; |
95 | fDigits = 0; |
96 | |
97 | } |
98 | //____________________________________________________________________________ |
99 | void AliEMCALDigitizer::Init(){ |
100 | // Makes all memory allocations |
101 | |
102 | if(!fInitialized){ |
103 | |
104 | fHeaderFiles = new TClonesArray("TObjString",1) ; |
105 | new((*fHeaderFiles)[0]) TObjString("galice.root") ; |
106 | |
107 | //Test, if this file already open |
108 | |
109 | TFile *file = (TFile*) gROOT->GetFile(((TObjString *) fHeaderFiles->At(0))->GetString() ) ; |
110 | |
111 | if(file == 0){ |
112 | file = new TFile(((TObjString *) fHeaderFiles->At(0))->GetString(),"update") ; |
113 | gAlice = (AliRun *) file->Get("gAlice") ; |
114 | } |
115 | else |
116 | file = new TFile(((TObjString *) fHeaderFiles->At(0))->GetString()) ; |
117 | |
118 | file->cd() ; |
119 | |
120 | fSDigitsTitles = new TClonesArray("TObjString",1); |
ffa6d63b |
121 | new((*fSDigitsTitles)[0]) TObjString("Default") ; |
61e0abb5 |
122 | |
123 | fSDigits = new TClonesArray("TClonesArray",1) ; |
124 | new((*fSDigits)[0]) TClonesArray("AliEMCALDigit",1000) ; |
125 | |
126 | fSDigitizer = 0 ; |
127 | |
ffa6d63b |
128 | fDigitsTitle = "Default" ; |
61e0abb5 |
129 | |
130 | fDigits = new TClonesArray("AliEMCALDigit",200000) ; |
131 | |
132 | fIevent = new TArrayI(1) ; |
133 | fIevent->AddAt(-1,0 ) ; |
134 | fIeventMax = new TArrayI(1) ; |
135 | |
136 | fIeventMax->AddAt((Int_t) gAlice->TreeE()->GetEntries(), 0 ); |
137 | |
138 | // add Task to //root/Tasks folder |
139 | TTask * roottasks = (TTask*)gROOT->GetRootFolder()->FindObject("Tasks") ; |
140 | roottasks->Add(this) ; |
141 | |
142 | fInitialized = kTRUE ; |
143 | } |
144 | |
145 | } |
146 | |
147 | //____________________________________________________________________________ |
148 | AliEMCALDigitizer::AliEMCALDigitizer(const char *headerFile,const char *sDigitsTitle): |
149 | TTask("AliEMCALDigitizer","") |
150 | { |
151 | // ctor |
152 | fHeaderFiles = new TClonesArray("TObjString",1) ; |
153 | new((*fHeaderFiles)[0]) TObjString(headerFile) ; |
154 | |
155 | // Header file, where result will be stored |
156 | TFile * file = (TFile*) gROOT->GetFile(((TObjString *) fHeaderFiles->At(0))->GetString() ) ; |
157 | if(file==0){ |
158 | if(((TObjString *) fHeaderFiles->At(0))->GetString().Contains("rfio")) |
159 | file = TFile::Open(((TObjString *) fHeaderFiles->At(0))->GetString(),"update") ; |
160 | else |
161 | file = new TFile(((TObjString *) fHeaderFiles->At(0))->GetString(),"update") ; |
162 | gAlice = (AliRun *) file->Get("gAlice") ; //If not read yet |
163 | } |
164 | |
165 | file->cd() ; |
166 | |
167 | fSDigitsTitles = new TClonesArray("TObjString",1); // Title name of the SDigits branch |
168 | new((*fSDigitsTitles)[0]) TObjString(sDigitsTitle) ; |
169 | |
170 | fSDigits = new TClonesArray("TClonesArray",1) ; // here list of SDigits wil be stored |
171 | new((*fSDigits)[0]) TClonesArray("AliEMCALDigit",1000) ; |
172 | |
173 | fDigits = new TClonesArray("AliEMCALDigit",200000) ; |
174 | |
ffa6d63b |
175 | fDigitsTitle = "Default" ; |
61e0abb5 |
176 | |
177 | |
178 | fSDigitizer = 0 ; |
179 | |
180 | fIevent = new TArrayI(1) ; |
181 | fIevent->AddAt(-1,0 ) ; |
182 | fIeventMax = new TArrayI(1) ; |
183 | |
184 | // Get number of events to process |
185 | fIeventMax->AddAt((Int_t) gAlice->TreeE()->GetEntries(), 0 ); |
186 | |
187 | fNinputs = 1 ; |
188 | |
ffa6d63b |
189 | fPinNoise = 0.0001 ; |
190 | fEMCDigitThreshold = 0.001 ; |
61e0abb5 |
191 | |
192 | // add Task to //root/Tasks folder |
193 | TTask * roottasks = (TTask*)gROOT->GetRootFolder()->FindObject("Tasks") ; |
194 | roottasks->Add(this) ; |
195 | fInitialized = kTRUE ; |
196 | |
197 | } |
198 | |
199 | //____________________________________________________________________________ |
200 | AliEMCALDigitizer::~AliEMCALDigitizer() |
201 | { |
202 | // dtor |
203 | |
204 | if(fHeaderFiles) delete fHeaderFiles ; |
205 | if(fSDigitsTitles) delete fSDigitsTitles ; |
206 | if(fSDigits) delete fSDigits ; |
207 | if(fDigits) delete fDigits ; |
208 | } |
209 | //____________________________________________________________________________ |
210 | void AliEMCALDigitizer::Reset() { |
211 | //sets current event number to the first simulated event |
212 | |
213 | if(!fInitialized) |
214 | Init() ; |
215 | |
216 | Int_t inputs ; |
217 | for(inputs = 0; inputs < fNinputs ;inputs++) |
218 | fIevent->AddAt(-1, inputs ) ; |
219 | |
220 | } |
221 | //____________________________________________________________________________ |
222 | Bool_t AliEMCALDigitizer::Combinator() { |
223 | |
224 | //Makes all desirable combinations Signal+Background, |
225 | // returns kFALSE when all combinations are made |
226 | // May be useful to introduce some options like "One-to-One", "All-to-One" and "All-to-All" ? |
227 | |
228 | //realizing "One-to-One" option... |
229 | |
230 | if(!fInitialized) |
231 | Init() ; |
232 | |
233 | Int_t inputs ; |
234 | Bool_t endNotReached = kTRUE ; |
235 | |
236 | for(inputs = 0; (inputs < fNinputs) && endNotReached ;inputs++){ |
237 | if(fIevent->At(inputs)+1 < fIeventMax->At(inputs)) |
238 | fIevent->AddAt(fIevent->At(inputs)+1, inputs ) ; |
239 | else |
240 | if(inputs == 0) |
241 | endNotReached = kFALSE ; |
242 | else //for inputs other than base one start from the beginning |
243 | fIevent->AddAt(0, inputs ) ; |
244 | |
245 | } |
246 | return endNotReached ; |
247 | |
248 | } |
249 | |
250 | //____________________________________________________________________________ |
251 | void AliEMCALDigitizer::Digitize(Option_t *option) { |
252 | |
253 | // Makes the digitization of the collected summable digits |
254 | // for this it first creates the array of all EMCAL modules |
255 | // filled with noise (different for EMC, CPV and PPSD) and |
256 | // after that adds contributions from SDigits. This design |
257 | // helps to avoid scanning over the list of digits to add |
258 | // contribution of any new SDigit. |
259 | |
260 | if(!fInitialized) |
261 | Init() ; |
262 | |
263 | fDigits->Clear() ; |
264 | |
ffa6d63b |
265 | AliEMCALv0 * EMCAL = (AliEMCALv0 *) gAlice->GetDetector("EMCAL") ; |
61e0abb5 |
266 | AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance( EMCAL->GetGeometry()->GetName(), EMCAL->GetGeometry()->GetTitle() ); |
267 | |
268 | //Making digits with noise, first EMC |
ffa6d63b |
269 | Int_t nEMC = 2*geom->GetNPhi()*geom->GetNZ(); |
61e0abb5 |
270 | Int_t absID ; |
271 | TString name = geom->GetName() ; |
272 | |
273 | for(absID = 1; absID <= nEMC; absID++){ |
274 | Float_t noise = gRandom->Gaus(0., fPinNoise) ; |
275 | new((*fDigits)[absID-1]) AliEMCALDigit( -1,-1, absID,fSDigitizer->Digitize(noise) ) ; |
276 | } |
277 | |
278 | |
279 | // Now look throught (unsorted) list of SDigits and add corresponding digits |
280 | AliEMCALDigit *curSDigit ; |
281 | AliEMCALDigit *digit ; |
282 | |
283 | Int_t inputs; |
284 | for(inputs = 0; inputs< fNinputs ; inputs++){ //loop over (possible) merge sources |
285 | |
286 | TClonesArray * sdigits= (TClonesArray *)fSDigits->At(inputs) ; |
287 | Int_t isdigit ; |
288 | |
289 | Int_t nSDigits = sdigits->GetEntries() ; |
290 | for(isdigit=0;isdigit< nSDigits; isdigit++){ |
291 | curSDigit = (AliEMCALDigit *)sdigits->At(isdigit) ; |
ffa6d63b |
292 | if(inputs) //Shift primaries for non-background sdigits |
61e0abb5 |
293 | curSDigit->ShiftPrimary(inputs) ; |
294 | digit = (AliEMCALDigit *)fDigits->At(curSDigit->GetId() - 1); |
ffa6d63b |
295 | cout << curSDigit->GetAmp() << " and " << digit->GetAmp() << endl ; |
61e0abb5 |
296 | *digit = *digit + *curSDigit ; |
297 | } |
298 | } |
299 | |
300 | |
301 | //remove digits below thresholds |
302 | for(absID = 0; absID < nEMC ; absID++) |
ffa6d63b |
303 | if(fSDigitizer->Calibrate(((AliEMCALDigit*)fDigits->At(absID))->GetAmp()) < fEMCDigitThreshold) |
61e0abb5 |
304 | fDigits->RemoveAt(absID) ; |
305 | |
306 | fDigits->Compress() ; |
307 | |
308 | Int_t ndigits = fDigits->GetEntriesFast() ; |
309 | |
310 | fDigits->Expand(ndigits) ; |
311 | |
312 | |
313 | //Set indexes in list of digits |
314 | Int_t i ; |
315 | for (i = 0 ; i < ndigits ; i++) { |
316 | AliEMCALDigit * digit = (AliEMCALDigit *) fDigits->At(i) ; |
317 | digit->SetIndexInList(i) ; |
ffa6d63b |
318 | cout << digit->GetAmp() << "is amp" << endl; |
319 | Float_t energy = fSDigitizer->Calibrate(digit->GetAmp()) ; |
320 | cout << energy << " = energy " << endl; |
321 | energy = energy*1000 ; |
322 | cout << energy << " = energy " << endl; |
323 | digit->SetAmp(DigitizeEnergy(energy,digit->GetId()) ) ; |
324 | cout << digit->GetAmp() << "is amp" << endl; |
325 | cout << 100*energy/12.9 << endl ; |
61e0abb5 |
326 | } |
327 | } |
328 | //____________________________________________________________________________ |
ffa6d63b |
329 | |
330 | Int_t AliEMCALDigitizer::DigitizeEnergy(Float_t energy, Int_t absId) |
331 | { Int_t chanel ; |
332 | //if(absId <= fEmcCrystals){ //digitize as EMC |
333 | chanel = (Int_t) TMath::Ceil(energy) ; |
334 | //if(chanel > fNADCemc ) chanel = fNADCemc ; |
335 | // } |
336 | return chanel ; |
337 | } |
338 | //____________________________________________________________________________ |
339 | |
340 | |
61e0abb5 |
341 | void AliEMCALDigitizer::WriteDigits(){ |
342 | |
343 | // Made TreeD in the output file. Check if branch already exists: if yes, exits |
344 | // without writing: ROOT TTree does not suppert overwriting/updating of the |
345 | // already existing branches. Creates branch with Digits, named "EMCAL", title "...", |
346 | // and branch "AliEMCALDigitizer", with the same title to keep all the parameters |
347 | // and names of files, from which digits are made. |
348 | |
349 | gAlice->GetEvent(fIevent->At(0)) ; // Suitable only for One-To-One mixing |
350 | gAlice->SetEvent(fIevent->At(0)) ; // for all-to-all will produce a lot of branches in TreeD |
351 | |
352 | if(gAlice->TreeD()==0) |
353 | gAlice->MakeTree("D") ; |
354 | |
355 | //Check, if this branch already exits? |
356 | TBranch * digitsBranch = 0; |
357 | TBranch * digitizerBranch = 0; |
358 | |
359 | TObjArray * branches = gAlice->TreeD()->GetListOfBranches() ; |
360 | Int_t ibranch; |
361 | Bool_t emcalNotFound = kTRUE ; |
362 | Bool_t digitizerNotFound = kTRUE ; |
363 | |
364 | for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){ |
365 | |
366 | if(emcalNotFound){ |
367 | digitsBranch=(TBranch *) branches->At(ibranch) ; |
368 | if( (strcmp("EMCAL",digitsBranch->GetName())==0 ) && |
369 | (fDigitsTitle.CompareTo(digitsBranch->GetTitle()) == 0) ) |
370 | emcalNotFound = kFALSE ; |
371 | } |
372 | if(digitizerNotFound){ |
373 | digitizerBranch = (TBranch *) branches->At(ibranch) ; |
374 | if( (strcmp(digitizerBranch->GetName(),"AliEMCALDigitizer") == 0) && |
375 | (fDigitsTitle.CompareTo(digitizerBranch->GetTitle()) == 0)) |
376 | digitizerNotFound = kFALSE ; |
377 | } |
378 | } |
379 | |
380 | |
381 | if(!(digitizerNotFound && emcalNotFound)){ |
382 | cout << "AliEMCALDigitizer error: " << endl ; |
383 | cout << " can not update/overwrite existing branches "<< endl ; |
384 | cout << " do not write " << endl ; |
385 | return ; |
386 | } |
387 | |
388 | // create new branches |
389 | |
390 | //First generate file name |
391 | char * file =0; |
392 | if(gSystem->Getenv("CONFIG_SPLIT_FILE")){ //generating file name |
393 | file = new char[strlen(gAlice->GetBaseFile())+20] ; |
394 | sprintf(file,"%s/EMCAL.Digits.root",gAlice->GetBaseFile()) ; |
395 | } |
396 | |
397 | TDirectory *cwd = gDirectory; |
398 | |
399 | //First create list of sdigits |
400 | Int_t bufferSize = 32000 ; |
401 | digitsBranch = gAlice->TreeD()->Branch("EMCAL",&fDigits,bufferSize); |
402 | digitsBranch->SetTitle(fDigitsTitle.Data()); |
403 | if (file) { |
404 | digitsBranch->SetFile(file); |
405 | TIter next( digitsBranch->GetListOfBranches()); |
406 | TBranch * sbr ; |
407 | while ((sbr=(TBranch*)next())) { |
408 | sbr->SetFile(file); |
409 | } |
410 | cwd->cd(); |
411 | } |
412 | |
413 | //second - create Digitizer |
414 | Int_t splitlevel = 0 ; |
415 | AliEMCALDigitizer * d = this ; |
416 | digitizerBranch = gAlice->TreeD()->Branch("AliEMCALDigitizer","AliEMCALDigitizer", |
417 | &d,bufferSize,splitlevel); |
418 | digitizerBranch->SetTitle(fDigitsTitle.Data()); |
419 | if (file) { |
420 | digitizerBranch->SetFile(file); |
421 | TIter next( digitizerBranch->GetListOfBranches()); |
422 | TBranch * sbr; |
423 | while ((sbr=(TBranch*)next())) { |
424 | sbr->SetFile(file); |
425 | } |
426 | cwd->cd(); |
427 | } |
428 | |
429 | digitsBranch->Fill() ; |
430 | digitizerBranch->Fill() ; |
431 | |
432 | gAlice->TreeD()->Write(0,kOverwrite) ; |
433 | |
434 | //remove fSDigitizer before new event. |
435 | if(fSDigitizer){ |
436 | delete fSDigitizer ; |
437 | fSDigitizer = 0 ; |
438 | } |
439 | |
440 | |
441 | } |
442 | |
443 | //____________________________________________________________________________ |
444 | void AliEMCALDigitizer::Exec(Option_t *option) { |
445 | // Managing method |
446 | |
447 | if(!fInitialized) Init() ; |
448 | |
449 | if(strstr(option,"tim")) |
450 | gBenchmark->Start("EMCALDigitizer"); |
451 | |
452 | //reset events numbers to start from the beginnig |
453 | Reset() ; |
454 | |
455 | while(Combinator()){ |
456 | |
457 | if(!ReadSDigits()) //read sdigits event(s) evaluated by Combinator() from file(s) |
458 | return ; |
459 | |
460 | Digitize(option) ; //Add prepared SDigits to digits and add the noise |
461 | WriteDigits() ; |
462 | |
463 | if(strstr(option,"deb")) |
464 | PrintDigits(option); |
465 | |
466 | } |
467 | |
468 | if(strstr(option,"tim")){ |
469 | gBenchmark->Stop("EMCALDigitizer"); |
470 | cout << "AliEMCALDigitizer:" << endl ; |
471 | cout << " took " << gBenchmark->GetCpuTime("EMCALDigitizer") << " seconds for SDigitizing " |
472 | << gBenchmark->GetCpuTime("EMCALDigitizer")/(fIeventMax->At(0)) << " seconds per event " << endl ; |
473 | cout << endl ; |
474 | } |
475 | |
476 | } |
477 | |
478 | //__________________________________________________________________ |
479 | Bool_t AliEMCALDigitizer::ReadSDigits(){ |
480 | // Reads summable digits from the opened files for the particular set of events given by fIevent |
481 | |
482 | if(!fInitialized) Init() ; |
483 | |
484 | |
485 | Int_t inputs ; |
486 | for(inputs = fNinputs-1; inputs >= 0; inputs --){ |
487 | |
488 | Int_t event = fIevent->At(inputs) ; |
489 | |
490 | TFile * file = (TFile*) gROOT->GetFile(((TObjString *) fHeaderFiles->At(inputs))->GetString() ) ; |
491 | file->cd() ; |
492 | |
493 | // Get SDigits Tree header from file |
494 | char treeName[20]; |
495 | sprintf(treeName,"TreeS%d",event); |
496 | TTree * treeS = (TTree*)file->Get(treeName); |
497 | |
498 | if(treeS==0){ |
499 | cout << "Error at AliEMCALDigitizer: no "<<treeName << " in file " << file->GetName() << endl ; |
500 | cout << "Do nothing " << endl ; |
501 | return kFALSE ; |
502 | } |
503 | |
504 | TBranch * sdigitsBranch = 0; |
505 | TBranch * sdigitizerBranch = 0; |
506 | |
507 | TObjArray * branches = treeS->GetListOfBranches() ; |
508 | Int_t ibranch; |
509 | Bool_t emcalNotFound = kTRUE ; |
510 | Bool_t sdigitizerNotFound = kTRUE ; |
511 | |
512 | for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){ |
513 | |
514 | if(emcalNotFound){ |
515 | sdigitsBranch=(TBranch *) branches->At(ibranch) ; |
516 | if(( strcmp("EMCAL",sdigitsBranch->GetName())==0 ) && |
517 | ((TObjString*) fSDigitsTitles->At(inputs))->GetString().CompareTo(sdigitsBranch->GetTitle())== 0 ) |
518 | emcalNotFound = kFALSE ; |
519 | |
520 | } |
521 | |
522 | if(sdigitizerNotFound){ |
523 | sdigitizerBranch = (TBranch *) branches->At(ibranch) ; |
524 | if(( strcmp(sdigitizerBranch->GetName(),"AliEMCALSDigitizer") == 0) && |
525 | ((TObjString*) fSDigitsTitles->At(inputs))->GetString().CompareTo(sdigitizerBranch->GetTitle())== 0 ) |
526 | sdigitizerNotFound = kFALSE ; |
527 | |
528 | } |
529 | } |
530 | |
531 | if(sdigitizerNotFound || emcalNotFound){ |
532 | cout << "Can't find Branch with sdigits or SDigitizer in the file " ; |
533 | if( ((TObjString*)fSDigitsTitles->At(inputs))->GetString().IsNull() ) |
534 | cout << file->GetName() << endl ; |
535 | else |
536 | cout << ((TObjString*)fSDigitsTitles->At(inputs))->GetString().Data() << endl ; |
537 | cout << "Do nothing" <<endl ; |
538 | return kFALSE ; |
539 | } |
540 | |
541 | TClonesArray * sdigits = (TClonesArray*) fSDigits->At(inputs) ; |
542 | sdigitsBranch->SetAddress(&sdigits) ; |
543 | |
544 | AliEMCALSDigitizer *sDigitizer = new AliEMCALSDigitizer(); |
545 | sdigitizerBranch->SetAddress(&sDigitizer) ; |
546 | |
547 | sdigitsBranch->GetEntry(0) ; |
548 | sdigitizerBranch->GetEntry(0) ; |
549 | |
550 | if(fSDigitizer == 0) |
551 | fSDigitizer = sDigitizer ; |
552 | else |
553 | if(!((*fSDigitizer)==(*sDigitizer)) ){ |
554 | cout << "AliEMCALDigitizer ERROR:" << endl ; |
555 | cout << " you are using sdigits made with different SDigitizers" << endl ; |
556 | cout << "fSD " << fSDigitizer << " SD" << sDigitizer << endl ; |
557 | fSDigitizer->Print("") ; |
558 | sDigitizer->Print("") ; |
559 | cout << "Do Nothing " << endl ; |
560 | return kFALSE ; |
561 | } |
562 | |
563 | } |
564 | fPedestal = fSDigitizer->GetPedestalParameter() ; |
565 | fSlope = fSDigitizer->GetCalibrationParameter() ; |
566 | |
567 | return kTRUE ; |
568 | |
569 | } |
570 | //__________________________________________________________________ |
571 | void AliEMCALDigitizer::MixWith(char* HeaderFile, char* sDigitsTitle){ |
572 | // Alows produce digits by superimposing background and signal event. |
573 | // It is assumed, that headers file with SIGNAL events is opened in |
574 | // constructor, and now we set the BACKGROUND event, with which we |
575 | // will mix. Thus we avoid writing (changing) huge and expencive |
576 | // backgound files: all output will be writen into SIGNAL, i.e. |
577 | // opened in constructor file. |
578 | // |
579 | // One can open as many files to mix with as one wants. |
580 | |
581 | |
582 | if(!fInitialized) |
583 | Init() ; |
584 | |
585 | |
586 | if(HeaderFile == 0){ |
587 | cout << "Specify at least header file to merge"<< endl ; |
588 | return ; |
589 | } |
590 | |
591 | Int_t inputs ; |
592 | for(inputs = 0; inputs < fNinputs ; inputs++){ |
593 | if(strcmp(((TObjString *)fHeaderFiles->At(inputs))->GetString(),HeaderFile) == 0 ){ |
594 | if(sDigitsTitle == 0){ |
595 | if(((TObjString*)fSDigitsTitles->At(inputs))->GetString().CompareTo("") == 0){ |
596 | cout << "Entry already exists, do not add" << endl ; |
597 | return ; |
598 | } |
599 | } |
600 | else |
601 | if(((TObjString*)fSDigitsTitles->At(inputs))->GetString().CompareTo(sDigitsTitle)){ |
602 | cout << "Entry already exists, do not add" << endl ; |
603 | return; |
604 | } |
605 | } |
606 | } |
607 | |
608 | fHeaderFiles->Expand(fNinputs+1) ; |
609 | new((*fHeaderFiles)[fNinputs]) TObjString(HeaderFile) ; |
610 | |
611 | |
612 | TFile * file = new TFile(((TObjString *) fHeaderFiles->At(fNinputs))->GetString()) ; |
613 | |
614 | file->cd() ; |
615 | |
616 | fSDigitsTitles->Expand(fNinputs+1) ; |
617 | new((*fSDigitsTitles)[fNinputs]) TObjString(sDigitsTitle) ; |
618 | |
619 | fSDigits->Expand(fNinputs+1) ; |
620 | new((*fSDigits)[fNinputs]) TClonesArray("AliEMCALDigit",1000) ; |
621 | |
622 | fIevent->Set(fNinputs+1) ; |
623 | fIevent->AddAt(-1, fNinputs) ; |
624 | |
625 | fIeventMax->Set(fNinputs+1) ; |
626 | |
627 | TTree * te = (TTree *) file->Get("TE") ; |
628 | fIeventMax->AddAt((Int_t) te->GetEntries(), fNinputs ); |
629 | |
630 | fNinputs++ ; |
631 | |
632 | } |
633 | //__________________________________________________________________ |
634 | void AliEMCALDigitizer::Print(Option_t* option)const { |
635 | |
636 | if(fInitialized){ |
637 | |
638 | cout << "------------------- "<< GetName() << " -------------" << endl ; |
639 | cout << "Digitizing sDigits from file(s): " <<endl ; |
640 | Int_t input ; |
641 | for(input = 0; input < fNinputs ; input++) { |
642 | cout << " " << ((TObjString *) fHeaderFiles->At(input))->GetString() << |
643 | " Branch title:" << ((TObjString *) fSDigitsTitles->At(input))->GetString() << endl ; |
644 | } |
645 | cout << endl ; |
646 | cout << "Writing digits to " << ((TObjString *) fHeaderFiles->At(0))->GetString() << endl ; |
647 | |
648 | cout << endl ; |
649 | cout << "With following parameters: " << endl ; |
650 | cout << " Electronics noise in EMC (fPinNoise) = " << fPinNoise << endl ; |
651 | cout << " Threshold in EMC (fEMCDigitThreshold) = " << fEMCDigitThreshold << endl ; ; |
652 | cout << "---------------------------------------------------" << endl ; |
653 | } |
654 | else |
655 | cout << "AliEMCALDigitizer not initialized " << endl ; |
656 | |
657 | } |
658 | //__________________________________________________________________ |
659 | void AliEMCALDigitizer::PrintDigits(Option_t * option){ |
660 | |
661 | cout << "AliEMCALDigitiser:"<< endl ; |
662 | cout << " Number of entries in Digits list " << fDigits->GetEntriesFast() << endl ; |
663 | cout << endl ; |
664 | if(strstr(option,"all")){ |
665 | |
666 | //loop over digits |
667 | AliEMCALDigit * digit; |
668 | cout << "Digit Id " << " Amplitude " << " Index " << " Nprim " << " Primaries list " << endl; |
669 | Int_t index ; |
670 | for (index = 0 ; index < fDigits->GetEntries() ; index++) { |
671 | digit = (AliEMCALDigit * ) fDigits->At(index) ; |
672 | cout << setw(8) << digit->GetId() << " " << setw(3) << digit->GetAmp() << " " |
673 | << setw(6) << digit->GetIndexInList() << " " |
674 | << setw(5) << digit->GetNprimary() <<" "; |
675 | |
676 | Int_t iprimary; |
677 | for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) |
678 | cout << setw(5) << digit->GetPrimary(iprimary+1) << " "; |
679 | cout << endl; |
680 | } |
681 | |
682 | } |
683 | } |
684 | //__________________________________________________________________ |
685 | void AliEMCALDigitizer::SetSDigitsBranch(const char* title){ |
686 | // we set title (comment) of the SDigits branch in the first! header file |
687 | if(!fInitialized) Init() ; |
688 | |
689 | ((TObjString*) fSDigitsTitles->At(0) )->SetString((char*)title) ; |
690 | |
691 | } |
692 | //__________________________________________________________________ |
693 | void AliEMCALDigitizer::SetDigitsBranch(const char* title){ |
694 | //Sets the title (comment) of the branch to which Digits branch |
695 | if(!fInitialized) Init() ; |
696 | |
697 | fDigitsTitle = title ; |
698 | |
699 | } |