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 ///_________________________________________________________________________________
60 // --- ROOT system ---
66 #include "TObjString.h"
67 #include "TGeometry.h"
68 #include "TBenchmark.h"
70 // --- Standard library ---
72 // --- AliRoot header files ---
74 #include "AliHeader.h"
75 #include "AliStream.h"
76 #include "AliRunDigitizer.h"
77 #include "AliEMCALDigit.h"
79 #include "AliEMCALGetter.h"
80 #include "AliEMCALDigitizer.h"
81 #include "AliEMCALSDigitizer.h"
82 #include "AliEMCALGeometry.h"
83 #include "AliEMCALTick.h"
85 ClassImp(AliEMCALDigitizer)
88 //____________________________________________________________________________
89 AliEMCALDigitizer::AliEMCALDigitizer()
93 fDefaultInit = kTRUE ;
94 fManager = 0 ; // We work in the standalong mode
98 //____________________________________________________________________________
99 AliEMCALDigitizer::AliEMCALDigitizer(const char *headerFile, const char *name, const Bool_t toSplit)
103 SetTitle(headerFile) ;
105 fManager = 0 ; // We work in the standalong mode
110 fDefaultInit = kFALSE ;
113 //____________________________________________________________________________
114 AliEMCALDigitizer::AliEMCALDigitizer(AliRunDigitizer * ard):AliDigitizer(ard)
117 SetTitle(ard->GetInputFileName(0,0)) ;
119 fDefaultInit = kFALSE ;
122 if (ard->GetOutputFile()) {
123 SetName(ard->GetOutputFile().Data());
131 //____________________________________________________________________________
132 AliEMCALDigitizer::~AliEMCALDigitizer()
139 //____________________________________________________________________________
140 void AliEMCALDigitizer::Digitize(const Int_t event)
143 // Makes the digitization of the collected summable digits
144 // for this it first creates the array of all EMCAL modules
145 // filled with noise (different for EMC, CPV and PPSD) and
146 // after that adds contributions from SDigits. This design
147 // helps to avoid scanning over the list of digits to add
148 // contribution of any new SDigit.
150 AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
151 TClonesArray * digits = gime->Digits(GetName()) ;
155 const AliEMCALGeometry *geom = gime->EMCALGeometry() ;
156 //Making digits with noise, first EMC
158 if (geom->GetNHCLayers() > 0 )
159 nEMC = 3*geom->GetNPhi()*geom->GetNZ(); //max number of digits possible (Preshower, ECAL, HCAL)
161 nEMC = 2*geom->GetNPhi()*geom->GetNZ(); //max number of digits possible (Preshower, ECAL)
164 TString name = geom->GetName() ;
166 // get first the sdigitizer from the tasks list (must have same name as the digitizer)
167 const AliEMCALSDigitizer * sDigitizer = gime->SDigitizer(GetName());
169 Fatal("Digitize", "SDigitizer with name %s not found", GetName() );
172 // loop through the sdigits posted to the White Board and add them to the noise
173 TCollection * folderslist = gime->SDigitsFolder()->GetListOfFolders() ;
174 TIter next(folderslist) ;
175 TFolder * folder = 0 ;
176 TClonesArray * sdigits = 0 ;
178 TObjArray * sdigArray = new TObjArray(2) ;
179 while ( (folder = (TFolder*)next()) ) {
180 if ( (sdigits = (TClonesArray*)folder->FindObject(GetName()) ) ) {
181 TString fileName(folder->GetName()) ;
182 fileName.ReplaceAll("_","/") ;
184 Info("Digitize", "Adding SDigits %s from %s", GetName(), fileName.Data()) ;
185 sdigArray->AddAt(sdigits, input) ;
190 //Find the first tower with signal
191 Int_t nextSig = nEMC + 1 ;
193 for(i=0; i<input; i++){
194 sdigits = (TClonesArray *)sdigArray->At(i) ;
195 if ( !sdigits->GetEntriesFast() )
197 Int_t curNext = ((AliEMCALDigit *)sdigits->At(0))->GetId() ;
198 if(curNext < nextSig)
202 TArrayI index(input) ;
203 index.Reset() ; //Set all indexes to zero
205 AliEMCALDigit * digit ;
206 AliEMCALDigit * curSDigit ;
208 TClonesArray * ticks = new TClonesArray("AliEMCALTick",1000) ;
210 //Put Noise contribution
211 for(absID = 1; absID <= nEMC; absID++){
213 // Float_t noise = TMath::Abs(gRandom->Gaus(0., fPinNoise));
214 //new((*digits)[absID-1]) AliEMCALDigit( -1, -1, absID, sDigitizer->Digitize(noise), TimeOfNoise() ) ;
215 // amplitude set to zero, noise will be added later
216 new((*digits)[absID-1]) AliEMCALDigit( -1, -1, absID, 0, TimeOfNoise() ) ;
217 //look if we have to add signal?
218 digit = (AliEMCALDigit *) digits->At(absID-1) ;
220 //Add SDigits from all inputs
223 Float_t a = digit->GetAmp() ;
224 Float_t b = TMath::Abs( a /fTimeSignalLength) ;
225 //Mark the beginnign of the signal
226 new((*ticks)[contrib++]) AliEMCALTick(digit->GetTime(),0, b);
227 //Mark the end of the ignal
228 new((*ticks)[contrib++]) AliEMCALTick(digit->GetTime()+fTimeSignalLength, -a, -b);
231 for(i = 0; i< input ; i++){ //loop over (possible) merge sources
232 if(((TClonesArray *)sdigArray->At(i))->GetEntriesFast() > index[i] )
233 curSDigit = (AliEMCALDigit*)((TClonesArray *)sdigArray->At(i))->At(index[i]) ;
236 //May be several digits will contribute from the same input
237 while(curSDigit && curSDigit->GetId() == absID){
238 //Shift primary to separate primaries belonging different inputs
239 Int_t primaryoffset ;
241 primaryoffset = fManager->GetMask(i) ;
244 curSDigit->ShiftPrimary(primaryoffset) ;
246 a = curSDigit->GetAmp() ;
247 b = a /fTimeSignalLength ;
248 new((*ticks)[contrib++]) AliEMCALTick(curSDigit->GetTime(),0, b);
249 new((*ticks)[contrib++]) AliEMCALTick(curSDigit->GetTime()+fTimeSignalLength, -a, -b);
251 *digit = *digit + *curSDigit ; //add energies
254 if(((TClonesArray *)sdigArray->At(i))->GetEntriesFast() > index[i] )
255 curSDigit = (AliEMCALDigit*)((TClonesArray *)sdigArray->At(i))->At(index[i]) ;
260 // add fluctuations for photo-electron creation
261 amp = sDigitizer->Calibrate(digit->GetAmp()) ; // GeV
263 Info("Digitize", "id = %d BEFORE amp = %f\n", digit->GetId(),amp) ;
264 amp *= static_cast<Float_t>(gRandom->Poisson(fMeanPhotonElectron)) / static_cast<Float_t>(fMeanPhotonElectron) ;
266 Info("Digitize", "After fluctuation amp = %f\n", amp) ;
267 //calculate and set time
268 Float_t time = FrontEdgeTime(ticks) ;
269 digit->SetTime(time) ;
271 //Find next signal module
273 for(i=0; i<input; i++){
274 sdigits = ((TClonesArray *)sdigArray->At(i)) ;
275 Int_t curNext = nextSig ;
276 if(sdigits->GetEntriesFast() > index[i] ){
277 curNext = ((AliEMCALDigit *) sdigits->At(index[i]))->GetId() ;
280 if(curNext < nextSig) nextSig = curNext ;
285 if (geom->IsInECAL(digit->GetId()))
286 amp += TMath::Abs(gRandom->Gaus(0., fPinNoise)) ;
287 else if (geom->IsInPRE(digit->GetId()))
288 amp += TMath::Abs(gRandom->Gaus(0., fPinNoise/100.)) ; // arbitrarely divide by 100, assuming that the gain of APD will be higher
289 else if (geom->IsInHCAL(digit->GetId()))
290 amp += TMath::Abs(gRandom->Gaus(0., fPinNoise/10.)) ; // arbitrarely divide by 10, assuming that the gain of APD will be higher
292 Info("Digitize", "After noise amp = %f \n", amp) ;
293 digit->SetAmp(sDigitizer->Digitize(amp)) ;
299 delete sdigArray ; //We should not delete its contents
301 //remove digits below thresholds
302 for(absID = 0; absID < nEMC; absID++){
303 digit = dynamic_cast<AliEMCALDigit*>( digits->At(absID) ) ;
304 Float_t threshold = 0 ;
306 if (geom->IsInECAL(digit->GetId()))
307 threshold = fDigitThreshold ;
308 else if (geom->IsInPRE(digit->GetId()))
309 threshold = fDigitThreshold / 100. ; // arbitrary see before when noise is added
310 else if (geom->IsInHCAL(digit->GetId()))
311 threshold = fDigitThreshold / 10. ; // arbitrary see before when noise is added
313 if(sDigitizer->Calibrate( digit->GetAmp() ) <= threshold)
314 digits->RemoveAt(absID) ;
317 Info("Digitize", "id = %d, amp = %f, noise = %f", absID, sDigitizer->Calibrate(digit->GetAmp()), fPinNoise) ;
318 digit->SetTime(gRandom->Gaus(digit->GetTime(),fTimeResolution) ) ;
324 Int_t ndigits = digits->GetEntriesFast() ;
325 // digits->Expand(ndigits) ;
327 //Set indexes in list of digits
328 for (i = 0 ; i < ndigits ; i++) {
329 digit = dynamic_cast<AliEMCALDigit *>( digits->At(i) ) ;
330 digit->SetIndexInList(i) ;
331 Float_t energy = sDigitizer->Calibrate(digit->GetAmp()) ;
332 digit->SetAmp(DigitizeEnergy(energy,digit->GetId()) ) ;
336 //____________________________________________________________________________
338 Int_t AliEMCALDigitizer::DigitizeEnergy(Float_t energy, Int_t absId)
340 Int_t channel = -999;
341 AliEMCALGeometry * geom = AliEMCALGetter::GetInstance()->EMCALGeometry() ;
343 if(geom->IsInPRE(absId)){ //digitize as PRE section
344 channel = static_cast<Int_t>(TMath::Ceil( (energy + fADCpedestalPRE)/fADCchannelPRE )) ;
345 if(channel > fNADCPRE )
348 else if(geom->IsInECAL(absId)){ //digitize as ECAL section
349 channel = static_cast<Int_t> (TMath::Ceil( (energy + fADCpedestalEC)/fADCchannelEC )) ;
350 if(channel > fNADCEC )
353 else if(geom->IsInHCAL(absId)){ //digitize as HCAL section
354 channel = static_cast<Int_t> (TMath::Ceil( (energy + fADCpedestalHC)/fADCchannelHC )) ;
355 if(channel > fNADCHC )
362 //____________________________________________________________________________
363 void AliEMCALDigitizer::Exec(Option_t *option)
367 if(strcmp(GetName(), "") == 0 )
369 if (strstr(option,"print")) {
374 if(strstr(option,"tim"))
375 gBenchmark->Start("EMCALDigitizer");
377 AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
384 treeD = fManager->GetTreeD() ;
385 nevents = 1 ; // Will process only one event
387 //Check, if this branch already exits
389 TObjArray * lob = (TObjArray*)treeD->GetListOfBranches() ;
391 TBranch * branch = 0 ;
392 Bool_t emcalfound = kFALSE, digitizerfound = kFALSE ;
394 while ( (branch = (TBranch*)next()) && (!emcalfound || !digitizerfound) ) {
395 if ( (strcmp(branch->GetName(), "EMCAL")==0) &&
396 (strcmp(branch->GetTitle(), GetName())==0) )
399 else if ( (strcmp(branch->GetName(), "AliEMCALDigitizer")==0) &&
400 (strcmp(branch->GetTitle(), GetName())==0) )
401 digitizerfound = kTRUE ;
405 Error( "Exec", "Digits branch with name %s already exits", GetName() ) ;
408 if ( digitizerfound ) {
409 Error( "Exec", "Digitizer branch with name %s already exit", GetName() ) ;
414 else { //EMCAL standalone
415 if(gime->BranchExists("Digits") )
417 nevents=gime->MaxEvent() ;
422 for(ievent = 0; ievent < nevents; ievent++){
427 for(input = 0 ; input < fManager->GetNinputs(); input ++){
428 TTree * treeS = fManager->GetInputTreeS(input) ;
430 Error( "Exec", "No Input") ;
433 gime->ReadTreeS(treeS,input) ;
438 gime->Event(ievent,"S") ;
440 Digitize(ievent) ; //Add prepared SDigits to digits and add the noise
442 WriteDigits(ievent) ;
444 if(strstr(option,"deb"))
447 //increment the total number of Digits per run
448 fDigitsInRun += gime->Digits()->GetEntriesFast() ;
451 if(strstr(option,"tim")){
452 gBenchmark->Stop("EMCALDigitizer");
453 Info("Exec", "took %f seconds for Digitizing %f seconds per event",
454 gBenchmark->GetCpuTime("EMCALDigitizer"), gBenchmark->GetCpuTime("EMCALDigitizer")/nevents ) ;
459 //____________________________________________________________________________
460 Float_t AliEMCALDigitizer::FrontEdgeTime(TClonesArray * ticks)
462 ticks->Sort() ; //Sort in accordance with times of ticks
464 AliEMCALTick * ctick = (AliEMCALTick *) it.Next() ;
465 Float_t time = ctick->CrossingTime(fTimeThreshold) ;
468 while((t=(AliEMCALTick*) it.Next())){
469 if(t->GetTime() < time) //This tick starts before crossing
474 time = ctick->CrossingTime(fTimeThreshold) ;
479 //____________________________________________________________________________
480 Bool_t AliEMCALDigitizer::Init()
482 // Makes all memory allocations
484 if( strcmp(GetTitle(), "") == 0 )
485 SetTitle("galice.root") ;
487 AliEMCALGetter * gime = AliEMCALGetter::GetInstance(GetTitle(), GetName(), fToSplit) ;
489 Error("Init", "Could not obtain the Getter object !" ) ;
493 //const AliEMCALGeometry * geom = gime->EMCALGeometry() ;
495 //fEmcCrystals = geom->GetNModules() * geom->GetNCristalsInModule() ;
497 // Post Digits to the white board
498 gime->PostDigits(GetName() ) ;
500 // Post Digitizer to the white board
501 gime->PostDigitizer(this) ;
505 // construct the name of the file as /path/EMCAL.SDigits.root
506 //First - extract full path if necessary
507 TString digitsFileName(GetTitle()) ;
508 Ssiz_t islash = digitsFileName.Last('/') ;
509 if(islash<digitsFileName.Length())
510 digitsFileName.Remove(islash+1,digitsFileName.Length()) ;
513 // Next - append the file name
514 digitsFileName+="EMCAL.Digits." ;
515 if((strcmp(GetName(),"Default")!=0)&&(strcmp(GetName(),"")!=0)){
516 digitsFileName+=GetName() ;
517 digitsFileName+="." ;
519 digitsFileName+="root" ;
520 // Finally - check if the file already opened or open the file
521 fSplitFile = static_cast<TFile*>(gROOT->GetFile(digitsFileName.Data()));
523 fSplitFile = TFile::Open(digitsFileName.Data(),"update") ;
526 //Mark that we will use current header file
528 gime->PostSDigits(GetName(),GetTitle()) ;
529 gime->PostSDigitizer(GetName(),GetTitle()) ;
534 //____________________________________________________________________________
535 void AliEMCALDigitizer::InitParameters()
537 fMeanPhotonElectron = 1250 ; // electrons per GeV
539 Warning("InitParameters", "No noise added\n") ;
540 fPinNoise = 0. ; // 0.001 ; // noise equivalent GeV (random choice)
541 fDigitThreshold = fPinNoise * 3; //2 sigma
542 fTimeResolution = 0.5e-9 ;
543 fTimeSignalLength = 1.0e-9 ;
545 fADCchannelEC = 0.000220; // width of one ADC channel in GeV
546 fADCpedestalEC = 0.005 ; // GeV
547 fNADCEC = (Int_t) TMath::Power(2,16) ; // number of channels in Tower ADC
549 fADCchannelHC = 0.000220; // width of one ADC channel in GeV
550 fADCpedestalHC = 0.005 ; // GeV
551 fNADCHC = (Int_t) TMath::Power(2,16) ; // number of channels in Tower ADC
553 fADCchannelPRE = 0.0000300; // width of one ADC channel in Pre Shower
554 fADCpedestalPRE = 0.005 ; // GeV
555 fNADCPRE = (Int_t) TMath::Power(2,12); // number of channels in Pre ShowerADC
557 fTimeThreshold = 0.001*10000000 ; //Means 1 MeV in terms of SDigits amplitude
561 //__________________________________________________________________
562 void AliEMCALDigitizer::MixWith(char* headerFile)
564 // Allows to produce digits by superimposing background and signal event.
565 // It is assumed, that headers file with SIGNAL events is opened in
567 // Sets the BACKGROUND event, with which the SIGNAL event is to be mixed
568 // Thus we avoid writing (changing) huge and expensive
569 // backgound files: all output will be writen into SIGNAL, i.e.
570 // opened in constructor file.
572 // One can open as many files to mix with as one needs.
573 // However only Sdigits with the same name (i.e. constructed with the same SDigitizer)
576 if( strcmp(GetName(), "") == 0 )
580 Error("MixWith", "Cannot use this method under AliRunDigitizer") ;
584 // check if the specified SDigits do not already exist on the White Board:
585 // //Folders/RunMC/Event/Data/EMCAL/SDigits/headerFile/sdigitsname
587 AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
588 TString path = gime->SDigitsFolder()->GetName() ;
590 // before it was ???? "Folders/RunMC/Event/Data/EMCAL/SDigits" ;
594 if ( gROOT->FindObjectAny(path.Data()) ) {
595 Error("MixWith", "Entry already exists, do not add" ) ;
599 gime->PostSDigits(GetName(),headerFile) ;
601 // check if the requested file is already open or exist and if SDigits Branch exist
602 TFile * file = (TFile*)gROOT->FindObject(headerFile);
604 file = new TFile(headerFile, "READ") ;
606 Error("MixWith", "File %s does not exist!", headerFile) ;
613 //__________________________________________________________________
614 void AliEMCALDigitizer::Print(Option_t* option)const {
616 TString message("\n") ;
618 if( strcmp(GetName(), "") != 0) {
619 message += "------------------- " ;
620 message += GetName() ;
621 message += " -------------" ;
622 const Int_t nStreams = GetNInputStreams() ;
625 for (index = 0 ; index < nStreams ; index++) {
626 message += "\nAdding SDigits " ;
627 message += GetName() ;
628 message += " from " ;
629 message += fManager->GetInputFileName(index, 0) ;
632 message += "\nWriting digits to " ;
633 message += fManager->GetInputFileName(0, 0) ;
635 message += "\nWriting digits to " ;
636 message += GetTitle() ;
638 message += "\nWith following parameters: " ;
639 message += "\n Electronics noise in EMC (fPinNoise) = " ;
640 message += fPinNoise ;
641 message += "\n Threshold in EMC (fDigitThreshold) = " ;
642 message += fDigitThreshold ;
643 message += "\n---------------------------------------------------" ;
646 message += "\nAliEMCALDigitizer not initialized " ;
648 Info("Print", message.Data() ) ;
651 //__________________________________________________________________
652 void AliEMCALDigitizer::PrintDigits(Option_t * option){
654 AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
655 TClonesArray * fDigits = gime->Digits() ;
657 TString message("\n") ;
658 message += " Number of entries in Digits list " ;
659 message += fDigits->GetEntriesFast() ;
661 if(strstr(option,"all")){
664 AliEMCALDigit * digit;
665 message += "\n Id Amplitude Time Index Nprim: Primaries list \n" ;
667 char * tempo = new char[8192];
668 for (index = 0 ; index < fDigits->GetEntries() ; index++) {
669 digit = (AliEMCALDigit * ) fDigits->At(index) ;
670 sprintf(tempo, "\n%6d %8d %6.5e %4d %2d : ",
671 digit->GetId(), digit->GetAmp(), digit->GetTime(), digit->GetIndexInList(), digit->GetNprimary()) ;
674 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
675 sprintf(tempo, "%d ",digit->GetPrimary(iprimary+1) ) ;
681 Info("PrintDigits", message.Data() ) ;
684 //__________________________________________________________________
685 Float_t AliEMCALDigitizer::TimeOfNoise(void)
686 { // Calculates the time signal generated by noise
687 //to be rewritten, now returns just big number
692 //_________________________________________________________________________________________
693 void AliEMCALDigitizer::WriteDigits(Int_t event)
696 // Makes TreeD in the output file.
697 // Check if branch already exists:
698 // if yes, exit without writing: ROOT TTree does not support overwriting/updating of
699 // already existing branches.
700 // else creates branch with Digits, named "EMCAL", title "...",
701 // and branch "AliEMCALDigitizer", with the same title to keep all the parameters
702 // and names of files, from which digits are made.
704 AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
705 const TClonesArray * digits = gime->Digits(GetName()) ;
709 treeD = fManager->GetTreeD() ;
711 if ((gAlice->TreeD() == 0) || (fSplitFile)) // we should not create TreeD if it is already here
712 gAlice->MakeTree("D", fSplitFile); // We overwrite TreeD in split file in the case of second reconstruction
715 treeD = gAlice->TreeD();
718 // -- create Digits branch
719 Int_t bufferSize = 32000 ;
720 TBranch * digitsBranch = treeD->Branch("EMCAL",&digits,bufferSize);
721 digitsBranch->SetTitle(GetName());
723 // -- Create Digitizer branch
724 Int_t splitlevel = 0 ;
725 const AliEMCALDigitizer * d = gime->Digitizer(GetName()) ;
726 TBranch * digitizerBranch = treeD->Branch("AliEMCALDigitizer", "AliEMCALDigitizer", &d,bufferSize,splitlevel);
727 digitizerBranch->SetTitle(GetName());
729 digitsBranch->Fill() ;
730 digitizerBranch->Fill() ;