1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //_________________________________________________________________________
20 //////////////////////////////////////////////////////////////////////////////
21 // Class performs digitization of Summable digits
23 // In addition it performs mixing of summable digits from different events.
25 // For each event two branches are created in TreeD:
26 // "EMCAL" - list of digits
27 // "AliEMCALDigitizer" - AliEMCALDigitizer with all parameters used in digitization
29 // Note, that one cset title for new digits branch, and repeat digitization with
30 // another set of parameters.
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
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
51 ////////////////////////////////////////////////////////////////////////////////////
53 //*-- Author: Sahal Yacoob (LBL)
54 // based on : AliEMCALDigitizer
56 // August 2002 Yves Schutz: clone PHOS as closely as possible and intoduction
57 // of new IO (à la PHOS)
58 // November 2003 Aleksei Pavlinov : adopted for Shish-Kebab geometry
59 //_________________________________________________________________________________
61 // --- ROOT system ---
65 #include <TBenchmark.h>
69 #include <TObjectTable.h>
73 // --- AliRoot header files ---
76 #include "AliRunDigitizer.h"
77 #include "AliRunLoader.h"
78 #include "AliCDBManager.h"
79 #include "AliCDBEntry.h"
80 #include "AliEMCALDigit.h"
82 #include "AliEMCALLoader.h"
83 #include "AliEMCALDigitizer.h"
84 #include "AliEMCALSDigitizer.h"
85 #include "AliEMCALGeometry.h"
86 #include "AliEMCALTick.h"
87 #include "AliEMCALHistoUtilities.h"
89 ClassImp(AliEMCALDigitizer)
92 //____________________________________________________________________________
93 AliEMCALDigitizer::AliEMCALDigitizer()
94 : AliDigitizer("",""),
102 fMeanPhotonElectron(0),
108 fTimeSignalLength(0),
112 fEventFolderName(""),
116 fHists(0),fCalibData(0x0)
120 fManager = 0 ; // We work in the standalong mode
123 //____________________________________________________________________________
124 AliEMCALDigitizer::AliEMCALDigitizer(TString alirunFileName, TString eventFolderName)
125 : AliDigitizer("EMCAL"+AliConfig::Instance()->GetDigitizerTaskName(), alirunFileName),
126 fDefaultInit(kFALSE),
133 fMeanPhotonElectron(0),
139 fTimeSignalLength(0),
143 fEventFolderName(eventFolderName),
147 fHists(0),fCalibData(0x0)
152 fManager = 0 ; // We work in the standalong mode
155 //____________________________________________________________________________
156 AliEMCALDigitizer::AliEMCALDigitizer(const AliEMCALDigitizer & d)
157 : AliDigitizer(d.GetName(),d.GetTitle()),
158 fDefaultInit(d.fDefaultInit),
159 fDigitsInRun(d.fDigitsInRun),
162 fInputFileNames(d.fInputFileNames),
163 fEventNames(d.fEventNames),
164 fDigitThreshold(d.fDigitThreshold),
165 fMeanPhotonElectron(d.fMeanPhotonElectron),
166 fPedestal(d.fPedestal),
168 fPinNoise(d.fPinNoise),
169 fTimeResolution(d.fTimeResolution),
170 fTimeThreshold(d.fTimeThreshold),
171 fTimeSignalLength(d.fTimeSignalLength),
172 fADCchannelEC(d.fADCchannelEC),
173 fADCpedestalEC(d.fADCpedestalEC),
175 fEventFolderName(d.fEventFolderName),
176 fFirstEvent(d.fFirstEvent),
177 fLastEvent(d.fLastEvent),
178 fControlHists(d.fControlHists),
179 fHists(d.fHists),fCalibData(d.fCalibData)
184 //____________________________________________________________________________
185 AliEMCALDigitizer::AliEMCALDigitizer(AliRunDigitizer * rd)
186 : AliDigitizer(rd,"EMCAL"+AliConfig::Instance()->GetDigitizerTaskName()),
187 fDefaultInit(kFALSE),
194 fMeanPhotonElectron(0),
200 fTimeSignalLength(0),
208 fHists(0),fCalibData(0x0)
210 // ctor Init() is called by RunDigitizer
212 fEventFolderName = fManager->GetInputFolderName(0) ;
213 SetTitle(dynamic_cast<AliStream*>(fManager->GetInputStream(0))->GetFileName(0));
217 //____________________________________________________________________________
218 AliEMCALDigitizer::~AliEMCALDigitizer()
221 if (AliRunLoader::GetRunLoader()) {
222 AliLoader *emcalLoader=0;
223 if ((emcalLoader = AliRunLoader::GetRunLoader()->GetDetectorLoader("EMCAL")))
224 emcalLoader->CleanDigitizer();
227 AliDebug(1," no runloader present");
228 delete [] fInputFileNames ;
229 delete [] fEventNames ;
231 if(fHists) delete fHists;
234 //____________________________________________________________________________
235 void AliEMCALDigitizer::Digitize(Int_t event)
238 // Makes the digitization of the collected summable digits
239 // for this it first creates the array of all EMCAL modules
240 // filled with noise (different for EMC, CPV and PPSD) and
241 // after that adds contributions from SDigits. This design
242 // helps to avoid scanning over the list of digits to add
243 // contribution of any new SDigit.
244 static int nEMC=0; //max number of digits possible
246 AliRunLoader *rl = AliRunLoader::GetRunLoader();
247 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(rl->GetDetectorLoader("EMCAL"));
248 Int_t readEvent = event ;
249 // fManager is data member from AliDigitizer
251 readEvent = dynamic_cast<AliStream*>(fManager->GetInputStream(0))->GetCurrentEventNumber() ;
252 AliDebug(1,Form("Adding event %d from input stream 0 %s %s",
253 readEvent, GetTitle(), fEventFolderName.Data())) ;
254 rl->GetEvent(readEvent);
256 TClonesArray * digits = emcalLoader->Digits() ;
257 digits->Delete() ; //JLK why is this created then deleted?
260 AliEMCALGeometry *geom = 0;
261 if (rl->GetAliRun()) {
262 AliEMCAL * emcal = (AliEMCAL*)rl->GetAliRun()->GetDetector("EMCAL");
263 geom = emcal->GetGeometry();
266 AliFatal("Could not get AliRun from runLoader");
268 nEMC = geom->GetNCells();
269 AliDebug(1,Form("nEMC %i (number cells in EMCAL) | %s \n", nEMC, geom->GetName()));
273 digits->Expand(nEMC) ;
275 // get first the sdigitizer from the tasks list (must have same name as the digitizer)
276 if ( !emcalLoader->SDigitizer() )
277 emcalLoader->LoadSDigitizer();
278 AliEMCALSDigitizer * sDigitizer = dynamic_cast<AliEMCALSDigitizer*>(emcalLoader->SDigitizer());
281 Fatal("Digitize", "SDigitizer with name %s %s not found", fEventFolderName.Data(), GetTitle() ) ;
283 //take all the inputs to add together and load the SDigits
284 TObjArray * sdigArray = new TObjArray(fInput) ;
285 sdigArray->AddAt(emcalLoader->SDigits(), 0) ;
288 for(i = 1 ; i < fInput ; i++){
289 TString tempo(fEventNames[i]) ;
292 AliRunLoader * rl2 = AliRunLoader::GetRunLoader(tempo) ;
295 rl2 = AliRunLoader::Open(fInputFileNames[i], tempo) ;
298 readEvent = dynamic_cast<AliStream*>(fManager->GetInputStream(i))->GetCurrentEventNumber() ;
299 Info("Digitize", "Adding event %d from input stream %d %s %s", readEvent, i, fInputFileNames[i].Data(), tempo.Data()) ;
301 rl2->GetEvent(readEvent);
302 AliEMCALLoader *emcalLoader2 = dynamic_cast<AliEMCALLoader*>(rl2->GetDetectorLoader("EMCAL"));
303 sdigArray->AddAt(emcalLoader2->SDigits(), i) ;
306 //Find the first tower with signal
307 Int_t nextSig = nEMC + 1 ;
308 TClonesArray * sdigits ;
309 for(i = 0 ; i < fInput ; i++){
310 sdigits = dynamic_cast<TClonesArray *>(sdigArray->At(i)) ;
311 if ( !sdigits->GetEntriesFast() )
313 Int_t curNext = dynamic_cast<AliEMCALDigit *>(sdigits->At(0))->GetId() ;
314 if(curNext < nextSig)
316 AliDebug(1,Form("input %i : #sdigits %i \n",
317 i, sdigits->GetEntriesFast()));
319 AliDebug(1,Form("FIRST tower with signal %i \n", nextSig));
321 TArrayI index(fInput) ;
322 index.Reset() ; //Set all indexes to zero
324 AliEMCALDigit * digit ;
325 AliEMCALDigit * curSDigit ;
327 // TClonesArray * ticks = new TClonesArray("AliEMCALTick",1000) ;
329 //Put Noise contribution
330 for(absID = 0; absID < nEMC; absID++){ // Nov 30, 2006 by PAI; was from 1 to nEMC
332 // amplitude set to zero, noise will be added later
333 new((*digits)[absID]) AliEMCALDigit( -1, -1, absID, 0, TimeOfNoise() ); // absID-1->absID
334 //look if we have to add signal?
335 digit = dynamic_cast<AliEMCALDigit *>(digits->At(absID)); // absID-1->absID
338 //Add SDigits from all inputs
340 //Int_t contrib = 0 ;
342 //Follow PHOS and comment out this timing model til a better one
343 //can be developed - JLK 28-Apr-2008
345 //Float_t a = digit->GetAmp() ;
346 //Float_t b = TMath::Abs( a /fTimeSignalLength) ;
347 //Mark the beginning of the signal
348 //new((*ticks)[contrib++]) AliEMCALTick(digit->GetTime(),0, b);
349 //Mark the end of the signal
350 //new((*ticks)[contrib++]) AliEMCALTick(digit->GetTime()+fTimeSignalLength, -a, -b);
352 // Calculate time as time of the largest digit
353 Float_t time = digit->GetTime() ;
354 Float_t eTime= digit->GetAmp() ;
357 for(i = 0; i< fInput ; i++){ //loop over (possible) merge sources
358 if(dynamic_cast<TClonesArray *>(sdigArray->At(i))->GetEntriesFast() > index[i] )
359 curSDigit = dynamic_cast<AliEMCALDigit*>(dynamic_cast<TClonesArray *>(sdigArray->At(i))->At(index[i])) ;
362 //May be several digits will contribute from the same input
363 while(curSDigit && (curSDigit->GetId() == absID)){
364 //Shift primary to separate primaries belonging different inputs
365 Int_t primaryoffset ;
367 primaryoffset = fManager->GetMask(i) ;
370 curSDigit->ShiftPrimary(primaryoffset) ;
372 //Remove old timing model - JLK 28-April-2008
373 //a = curSDigit->GetAmp() ;
374 //b = a /fTimeSignalLength ;
375 //new((*ticks)[contrib++]) AliEMCALTick(curSDigit->GetTime(),0, b);
376 //new((*ticks)[contrib++]) AliEMCALTick(curSDigit->GetTime()+fTimeSignalLength, -a, -b);
377 if(curSDigit->GetAmp()>eTime) {
378 eTime = curSDigit->GetAmp();
379 time = curSDigit->GetTime();
382 *digit = *digit + *curSDigit ; //add energies
385 if( dynamic_cast<TClonesArray *>(sdigArray->At(i))->GetEntriesFast() > index[i] )
386 curSDigit = dynamic_cast<AliEMCALDigit*>(dynamic_cast<TClonesArray *>(sdigArray->At(i))->At(index[i])) ;
391 // add fluctuations for photo-electron creation
392 amp = sDigitizer->Calibrate(digit->GetAmp()) ; // GeV
393 amp *= static_cast<Float_t>(gRandom->Poisson(fMeanPhotonElectron)) / static_cast<Float_t>(fMeanPhotonElectron) ;
395 //calculate and set time
396 //New timing model needed - JLK 28-April-2008
397 //Float_t time = FrontEdgeTime(ticks) ;
398 digit->SetTime(time) ;
400 //Find next signal module
402 for(i = 0 ; i < fInput ; i++){
403 sdigits = dynamic_cast<TClonesArray *>(sdigArray->At(i)) ;
404 Int_t curNext = nextSig ;
405 if(sdigits->GetEntriesFast() > index[i] ){
406 curNext = dynamic_cast<AliEMCALDigit *>(sdigits->At(index[i]))->GetId() ;
408 if(curNext < nextSig) nextSig = curNext ;
412 amp += TMath::Abs(gRandom->Gaus(0., fPinNoise)) ;
413 digit->SetAmp(sDigitizer->Digitize(amp)) ;
414 AliDebug(10,Form(" absID %5i amp %f nextSig %5i\n",
415 absID, amp, nextSig));
416 } // for(absID = 1; absID <= nEMC; absID++)
421 delete sdigArray ; //We should not delete its contents
423 //remove digits below thresholds
424 for(i = 0 ; i < nEMC ; i++){
425 digit = dynamic_cast<AliEMCALDigit*>( digits->At(i) ) ;
426 Float_t threshold = fDigitThreshold ;
427 if(sDigitizer->Calibrate( digit->GetAmp() ) < threshold)
428 digits->RemoveAt(i) ;
430 digit->SetTime(gRandom->Gaus(digit->GetTime(),fTimeResolution) ) ;
435 Int_t ndigits = digits->GetEntriesFast() ;
437 //Set indexes in list of digits and fill hists.
438 AliEMCALHistoUtilities::FillH1(fHists, 0, Double_t(ndigits));
439 Float_t energy=0., esum=0.;
440 for (i = 0 ; i < ndigits ; i++) {
441 digit = dynamic_cast<AliEMCALDigit *>( digits->At(i) ) ;
442 digit->SetIndexInList(i) ;
443 energy = sDigitizer->Calibrate(digit->GetAmp()) ;
445 digit->SetAmp(DigitizeEnergy(energy, digit->GetId()) ) ; // for what ??
446 AliEMCALHistoUtilities::FillH1(fHists, 2, double(digit->GetAmp()));
447 AliEMCALHistoUtilities::FillH1(fHists, 3, double(energy));
448 AliEMCALHistoUtilities::FillH1(fHists, 4, double(digit->GetId()));
449 // if(digit->GetId() == nEMC) {
450 // printf(" i %i \n", i );
455 AliEMCALHistoUtilities::FillH1(fHists, 1, esum);
458 // //_____________________________________________________________________
459 Int_t AliEMCALDigitizer::DigitizeEnergy(Float_t energy, Int_t AbsId)
461 // Returns digitized value of the energy in a cell absId
464 const AliEMCALGeometry * geom = AliEMCALGeometry::GetInstance();
467 AliFatal("Did not get geometry from EMCALLoader");
475 Int_t channel = -999;
477 Bool_t bCell = geom->GetCellIndex(AbsId, iSupMod, nModule, nIphi, nIeta) ;
479 Error("DigitizeEnergy","Wrong cell id number : AbsId %i ", AbsId) ;
480 geom->GetCellPhiEtaIndexInSModule(iSupMod,nModule,nIphi, nIeta,iphi,ieta);
483 fADCpedestalEC = fCalibData->GetADCpedestal(iSupMod,ieta,iphi);
484 fADCchannelEC = fCalibData->GetADCchannel(iSupMod,ieta,iphi);
487 channel = static_cast<Int_t> (TMath::Ceil( (energy + fADCpedestalEC)/fADCchannelEC )) ;
489 if(channel > fNADCEC )
495 //____________________________________________________________________________
496 void AliEMCALDigitizer::Exec(Option_t *option)
498 // Steering method to process digitization for events
499 // in the range from fFirstEvent to fLastEvent.
500 // This range is optionally set by SetEventRange().
501 // if fLastEvent=-1, then process events until the end.
502 // by default fLastEvent = fFirstEvent (process only one event)
504 if (!fInit) { // to prevent overwrite existing file
505 Error( "Exec", "Give a version name different from %s", fEventFolderName.Data() ) ;
509 if (strstr(option,"print")) {
515 if(strstr(option,"tim"))
516 gBenchmark->Start("EMCALDigitizer");
518 AliRunLoader *rl = AliRunLoader::GetRunLoader();
519 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(rl->GetDetectorLoader("EMCAL"));
521 // Post Digitizer to the white board
522 emcalLoader->PostDigitizer(this) ;
524 if (fLastEvent == -1) {
525 fLastEvent = rl->GetNumberOfEvents() - 1 ;
528 fLastEvent = fFirstEvent ; // what is this ??
530 Int_t nEvents = fLastEvent - fFirstEvent + 1;
533 rl->LoadSDigits("EMCAL");
534 for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
536 rl->GetEvent(ievent);
538 Digitize(ievent) ; //Add prepared SDigits to digits and add the noise
542 if(strstr(option,"deb"))
544 if(strstr(option,"table")) gObjectTable->Print();
546 //increment the total number of Digits per run
547 fDigitsInRun += emcalLoader->Digits()->GetEntriesFast() ;
550 emcalLoader->CleanDigitizer() ;
552 if(strstr(option,"tim")){
553 gBenchmark->Stop("EMCALDigitizer");
554 AliInfo(Form("Exec: took %f seconds for Digitizing %f seconds per event",
555 gBenchmark->GetCpuTime("EMCALDigitizer"), gBenchmark->GetCpuTime("EMCALDigitizer")/nEvents )) ;
559 //____________________________________________________________________________
560 Float_t AliEMCALDigitizer::FrontEdgeTime(TClonesArray * ticks)
562 // Returns the shortest time among all time ticks
564 ticks->Sort() ; //Sort in accordance with times of ticks
566 AliEMCALTick * ctick = (AliEMCALTick *) it.Next() ;
567 Float_t time = ctick->CrossingTime(fTimeThreshold) ;
570 while((t=(AliEMCALTick*) it.Next())){
571 if(t->GetTime() < time) //This tick starts before crossing
576 time = ctick->CrossingTime(fTimeThreshold) ;
581 //____________________________________________________________________________
582 Bool_t AliEMCALDigitizer::Init()
584 // Makes all memory allocations
586 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(AliRunLoader::GetRunLoader()->GetDetectorLoader("EMCAL"));
588 if ( emcalLoader == 0 ) {
589 Fatal("Init", "Could not obtain the AliEMCALLoader");
594 fLastEvent = fFirstEvent ;
597 fInput = fManager->GetNinputs() ;
601 fInputFileNames = new TString[fInput] ;
602 fEventNames = new TString[fInput] ;
603 fInputFileNames[0] = GetTitle() ;
604 fEventNames[0] = fEventFolderName.Data() ;
606 for (index = 1 ; index < fInput ; index++) {
607 fInputFileNames[index] = dynamic_cast<AliStream*>(fManager->GetInputStream(index))->GetFileName(0);
608 TString tempo = fManager->GetInputFolderName(index) ;
609 fEventNames[index] = tempo.Remove(tempo.Length()-1) ; // strip of the stream number added bt fManager
612 //to prevent cleaning of this object while GetEvent is called
613 emcalLoader->GetDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
616 //Calibration instance
617 fCalibData = emcalLoader->CalibData();
621 //____________________________________________________________________________
622 void AliEMCALDigitizer::InitParameters()
624 // Parameter initialization for digitizer
625 // Tune parameters - 24-nov-04; Apr 29, 2007
626 // New parameters JLK 14-Apr-2008
628 fMeanPhotonElectron = 4400; // electrons per GeV
629 fPinNoise = 0.037; // pin noise in GEV from analysis test beam data
630 if (fPinNoise == 0. )
631 Warning("InitParameters", "No noise added\n") ;
632 fDigitThreshold = fPinNoise * 3; // 3 * sigma
633 fTimeResolution = 0.3e-9 ; // 300 psc
634 fTimeSignalLength = 1.0e-9 ;
636 // These defaults are normally not used.
637 // Values are read from calibration database instead
638 fADCchannelEC = 0.0153; // Update 24 Apr 2007: 250./16/1024 - width of one ADC channel in GeV
639 fADCpedestalEC = 0.0 ; // GeV
640 fNADCEC = (Int_t) TMath::Power(2,16) ; // number of channels in Tower ADC - 65536
642 fTimeThreshold = 0.001*10000000 ; // Means 1 MeV in terms of SDigits amplitude ??
643 // hists. for control; no hists on default
648 //__________________________________________________________________
649 void AliEMCALDigitizer::MixWith(TString alirunFileName, TString eventFolderName)
651 // Allows to produce digits by superimposing background and signal event.
652 // It is assumed, that headers file with SIGNAL events is opened in
654 // Sets the BACKGROUND event, with which the SIGNAL event is to be mixed
655 // Thus we avoid writing (changing) huge and expensive
656 // backgound files: all output will be writen into SIGNAL, i.e.
657 // opened in constructor file.
659 // One can open as many files to mix with as one needs.
660 // However only Sdigits with the same name (i.e. constructed with the same SDigitizer)
663 if( strcmp(GetName(), "") == 0 )
667 Error("MixWith", "Cannot use this method under AliRunDigitizer") ;
670 // looking for file which contains AliRun
671 if (gSystem->AccessPathName(alirunFileName)) {// file does not exist
672 Error("MixWith", "File %s does not exist!", alirunFileName.Data()) ;
675 // looking for the file which contains SDigits
676 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(AliRunLoader::GetRunLoader()->GetDetectorLoader("EMCAL"));
677 TString fileName( emcalLoader->GetSDigitsFileName() ) ;
678 if ( eventFolderName != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
679 fileName = fileName.ReplaceAll(".root", "") + "_" + eventFolderName + ".root" ;
680 if ( (gSystem->AccessPathName(fileName)) ) {
681 Error("MixWith", "The file %s does not exist!", fileName.Data()) ;
684 // need to increase the arrays
685 // MvL: This code only works when fInput == 1, I think.
686 TString tempo = fInputFileNames[fInput-1] ;
687 delete [] fInputFileNames ;
688 fInputFileNames = new TString[fInput+1] ;
689 fInputFileNames[fInput-1] = tempo ;
691 tempo = fEventNames[fInput-1] ;
692 delete [] fEventNames ;
693 fEventNames = new TString[fInput+1] ;
694 fEventNames[fInput-1] = tempo ;
696 fInputFileNames[fInput] = alirunFileName ;
697 fEventNames[fInput] = eventFolderName ;
701 //__________________________________________________________________
702 void AliEMCALDigitizer::Print1(Option_t * option)
703 { // 19-nov-04 - just for convinience
708 //__________________________________________________________________
709 void AliEMCALDigitizer::Print(Option_t*)const
711 // Print Digitizer's parameters
712 printf("Print: \n------------------- %s -------------", GetName() ) ;
713 if( strcmp(fEventFolderName.Data(), "") != 0 ){
714 printf(" Writing Digits to branch with title %s\n", fEventFolderName.Data()) ;
718 nStreams = GetNInputStreams() ;
726 for (index = 0 ; index < nStreams ; index++) {
727 TString tempo(fEventNames[index]) ;
729 if ((rl = AliRunLoader::GetRunLoader(tempo)) == 0)
730 rl = AliRunLoader::Open(fInputFileNames[index], tempo) ;
731 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(rl->GetDetectorLoader("EMCAL"));
732 TString fileName( emcalLoader->GetSDigitsFileName() ) ;
733 if ( fEventNames[index] != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
734 fileName = fileName.ReplaceAll(".root", "") + "_" + fEventNames[index] + ".root" ;
735 printf ("Adding SDigits from %s %s\n", fInputFileNames[index].Data(), fileName.Data()) ;
738 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(AliRunLoader::GetRunLoader()->GetDetectorLoader("EMCAL"));
740 printf("\nWriting digits to %s", emcalLoader->GetDigitsFileName().Data()) ;
742 printf("\nWith following parameters:\n") ;
744 printf(" Electronics noise in EMC (fPinNoise) = %f\n", fPinNoise) ;
745 printf(" Threshold in EMC (fDigitThreshold) = %f\n", fDigitThreshold) ;
746 printf("---------------------------------------------------\n") ;
749 printf("Print: AliEMCALDigitizer not initialized") ;
752 //__________________________________________________________________
753 void AliEMCALDigitizer::PrintDigits(Option_t * option)
755 //utility method for printing digit information
757 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(AliRunLoader::GetRunLoader()->GetDetectorLoader("EMCAL"));
758 TClonesArray * digits = emcalLoader->Digits() ;
759 TClonesArray * sdigits = emcalLoader->SDigits() ;
761 printf("\n #Digits: %d : sdigits %d ", digits->GetEntriesFast(), sdigits->GetEntriesFast()) ;
762 printf("\n event %d", emcalLoader->GetRunLoader()->GetEventNumber());
764 if(strstr(option,"all")){
766 AliEMCALDigit * digit;
767 printf("\nEMC digits (with primaries):\n") ;
768 printf("\n Id Amplitude Time Index Nprim: Primaries list \n") ;
770 for (index = 0 ; index < digits->GetEntries() ; index++) {
771 digit = dynamic_cast<AliEMCALDigit *>(digits->At(index)) ;
772 printf("\n%6d %8d %6.5e %4d %2d : ",
773 digit->GetId(), digit->GetAmp(), digit->GetTime(), digit->GetIndexInList(), digit->GetNprimary()) ;
775 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
776 printf("%d ",digit->GetPrimary(iprimary+1) ) ;
783 //__________________________________________________________________
784 Float_t AliEMCALDigitizer::TimeOfNoise(void)
786 // Calculates the time signal generated by noise
787 //PH Info("TimeOfNoise", "Change me") ;
788 return gRandom->Rndm() * 1.28E-5;
791 //__________________________________________________________________
792 void AliEMCALDigitizer::Unload()
794 // Unloads the SDigits and Digits
798 for(i = 1 ; i < fInput ; i++){
799 TString tempo(fEventNames[i]) ;
801 if ((rl = AliRunLoader::GetRunLoader(tempo)))
802 rl->GetDetectorLoader("EMCAL")->UnloadSDigits() ;
804 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(AliRunLoader::GetRunLoader()->GetDetectorLoader("EMCAL"));
805 emcalLoader->UnloadDigits() ;
808 //_________________________________________________________________________________________
809 void AliEMCALDigitizer::WriteDigits()
812 // Makes TreeD in the output file.
813 // Check if branch already exists:
814 // if yes, exit without writing: ROOT TTree does not support overwriting/updating of
815 // already existing branches.
816 // else creates branch with Digits, named "EMCAL", title "...",
817 // and branch "AliEMCALDigitizer", with the same title to keep all the parameters
818 // and names of files, from which digits are made.
820 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(AliRunLoader::GetRunLoader()->GetDetectorLoader("EMCAL"));
822 const TClonesArray * digits = emcalLoader->Digits() ;
823 TTree * treeD = emcalLoader->TreeD();
825 emcalLoader->MakeDigitsContainer();
826 treeD = emcalLoader->TreeD();
829 // -- create Digits branch
830 Int_t bufferSize = 32000 ;
831 TBranch * digitsBranch = 0;
832 if ((digitsBranch = treeD->GetBranch("EMCAL"))) {
833 digitsBranch->SetAddress(&digits);
834 AliWarning("Digits Branch already exists. Not all digits will be visible");
837 treeD->Branch("EMCAL","TClonesArray",&digits,bufferSize);
838 //digitsBranch->SetTitle(fEventFolderName);
841 emcalLoader->WriteDigits("OVERWRITE");
842 emcalLoader->WriteDigitizer("OVERWRITE");
848 //__________________________________________________________________
849 void AliEMCALDigitizer::Browse(TBrowser* b)
851 if(fHists) b->Add(fHists);
855 //__________________________________________________________________
856 TList *AliEMCALDigitizer::BookControlHists(int var)
859 // histograms for monitoring digitizer performance
861 Info("BookControlHists"," started ");
863 const AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance();
865 new TH1F("hDigiN", "#EMCAL digits with fAmp > fDigitThreshold",
866 fNADCEC+1, -0.5, Double_t(fNADCEC));
867 new TH1F("HDigiSumEnergy","Sum.EMCAL energy from digi", 1000, 0.0, 200.);
868 new TH1F("hDigiAmp", "EMCAL digital amplitude", fNADCEC+1, -0.5, Double_t(fNADCEC));
869 new TH1F("hDigiEnergy","EMCAL cell energy", 2000, 0.0, 200.);
870 new TH1F("hDigiAbsId","EMCAL absId cells with fAmp > fDigitThreshold ",
871 geom->GetNCells(), 0.5, Double_t(geom->GetNCells())+0.5);
874 fHists = AliEMCALHistoUtilities::MoveHistsToList("EmcalDigiControlHists", kFALSE);
875 fHists = 0; //huh? JLK 03-Mar-2006
879 //__________________________________________________________________
880 void AliEMCALDigitizer::SaveHists(const char* name, Bool_t kSingleKey, const char* opt)
882 AliEMCALHistoUtilities::SaveListOfHists(fHists, name, kSingleKey, opt);