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
55 //_________________________________________________________________________________
57 // --- ROOT system ---
63 #include "TObjString.h"
64 #include "TGeometry.h"
65 #include "TBenchmark.h"
66 // --- Standard library ---
69 // --- AliRoot header files ---
72 #include "AliHeader.h"
73 #include "AliEMCALDigit.h"
74 #include "AliEMCALHit.h"
75 #include "AliEMCALTick.h"
76 #include "AliEMCALv1.h"
77 #include "AliEMCALDigitizer.h"
78 #include "AliEMCALSDigitizer.h"
79 #include "AliEMCALGeometry.h"
80 #include "AliEMCALGetter.h"
81 #include "AliRunDigitizer.h"
82 ClassImp(AliEMCALDigitizer)
85 //____________________________________________________________________________
86 AliEMCALDigitizer::AliEMCALDigitizer()
93 fTowerDigitThreshold = 0.0 ;
94 fTimeResolution = 0. ;
95 fTimeSignalLength = 0. ;
96 fPreShowerDigitThreshold = 0. ;
97 fADCchannelTower = 0.0; // width of one ADC channel in GeV
98 fADCpedestalTower = 0. ; // pedestal of ADC
99 fNADCTower = 0; // number of channels in Tower ADC
101 fADCchannelPreSho = 0.0; // width of one ADC channel in Pre Shower
102 fADCpedestalPreSho = 0.0 ; // pedestal of ADC
103 fNADCPreSho = 0; // number of channels in Pre Shower ADC
104 fTimeThreshold = 0.0; //Means 1 MeV in terms of SDigits amplitude
111 //____________________________________________________________________________
112 Bool_t AliEMCALDigitizer::Init()
114 // Makes all memory allocations
118 fPinNoise = 0.00001 ;
119 fTowerDigitThreshold = 0.001 ;
120 fTimeResolution = 0.5e-9 ;
121 fTimeSignalLength = 1.0e-9 ;
122 fPreShowerDigitThreshold = fTowerDigitThreshold/25. ;
123 fInitialized = kFALSE ;
124 fADCchannelTower = 0.000220; // width of one ADC channel in GeV
125 fADCpedestalTower = 0.005 ; // GeV
126 fNADCTower = (Int_t) TMath::Power(2,16) ; // number of channels in Tower ADC
128 fADCchannelPreSho = 0.0000300; // width of one ADC channel in Pre Shower
129 fADCpedestalPreSho = 0.005 ; //
130 fNADCPreSho = (Int_t) TMath::Power(2,12); // number of channels in Pre ShowerADC
132 fTimeThreshold = 0.001*10000000 ; //Means 1 MeV in terms of SDigits amplitude
137 SetTitle("aliroot") ;
138 else if (strcmp(GetTitle(),"")==0)
139 SetTitle("galice.root") ;
141 if( strcmp(GetName(), "") == 0 )
144 AliEMCALGetter * gime = AliEMCALGetter::GetInstance(GetTitle(), GetName(), "update") ;
146 cerr << "ERROR: AliEMCALDigitizer::Init -> Could not obtain the Getter object !" << endl ;
150 //const AliEMCALGeometry * geom = gime->EMCALGeometry() ;
151 //fEmcCrystals = geom->GetNModules() * geom->GetNCristalsInModule() ;
153 // Post Digits to the white board
154 gime->PostDigits(GetName() ) ;
156 // Post Digitizer to the white board
157 gime->PostDigitizer(this) ;
159 //Mark that we will use current header file
161 gime->PostSDigits(GetName(),GetTitle()) ;
162 gime->PostSDigitizer(GetName(),GetTitle()) ;
170 //____________________________________________________________________________
171 AliEMCALDigitizer::AliEMCALDigitizer(const char *headerFile,const char *name)
174 SetTitle(headerFile) ;
175 fManager = 0 ; // We work in the standalong mode
182 //____________________________________________________________________________
183 AliEMCALDigitizer::AliEMCALDigitizer(AliRunDigitizer * ard):AliDigitizer(ard)
186 SetName(""); //Will call init in the digitizing
187 SetTitle("aliroot") ;
190 //____________________________________________________________________________
191 AliEMCALDigitizer::~AliEMCALDigitizer()
196 if ( fSplitFile->IsOpen() )
197 fSplitFile->Close() ;
201 //____________________________________________________________________________
202 void AliEMCALDigitizer::Reset() {
203 //sets current event number to the first simulated event
204 if( strcmp(GetName(), "") == 0 )
208 // for(inputs = 0; inputs < fNinputs ;inputs++)
209 // fIevent->AddAt(-1, inputs ) ;
213 //____________________________________________________________________________
214 void AliEMCALDigitizer::Digitize(const Int_t event) {
216 // Makes the digitization of the collected summable digits
217 // for this it first creates the array of all EMCAL modules
218 // filled with noise (different for EMC, CPV and PPSD) and
219 // after that adds contributions from SDigits. This design
220 // helps to avoid scanning over the list of digits to add
221 // contribution of any new SDigit.
223 AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
224 TClonesArray * digits = gime->Digits(GetName()) ;
228 const AliEMCALGeometry *geom = gime->EMCALGeometry() ;
231 //Making digits with noise, first EMC
232 Int_t nEMC = 2*geom->GetNPhi()*geom->GetNZ();
234 TString name = geom->GetName() ;
236 // get first the sdigitizer from the tasks list (must have same name as the digitizer)
237 const AliEMCALSDigitizer * sDigitizer = gime->SDigitizer(GetName());
239 cerr << "ERROR: AliEMCALDigitizer::Digitize -> SDigitizer with name " << GetName() << " not found " << endl ;
242 // loop through the sdigits posted to the White Board and add them to the noise
243 TCollection * folderslist = gime->SDigitsFolder()->GetListOfFolders() ;
244 TIter next(folderslist) ;
245 TFolder * folder = 0 ;
246 TClonesArray * sdigits = 0 ;
248 TObjArray * sdigArray = new TObjArray(2) ;
249 while ( (folder = (TFolder*)next()) )
250 if ( (sdigits = (TClonesArray*)folder->FindObject(GetName()) ) ) {
251 TString fileName(folder->GetName()) ;
252 fileName.ReplaceAll("_","/") ;
253 cout << "INFO: AliEMCALDigitizer::Digitize -> Adding SDigits "
254 << GetName() << " from " << fileName << endl ;
255 sdigArray->AddAt(sdigits, input) ;
260 //Find the first tower with signal
261 Int_t nextSig = 200000 ;
263 for(i=0; i<input; i++){
264 sdigits = (TClonesArray *)sdigArray->At(i) ;
265 if ( !sdigits->GetEntriesFast() )
267 Int_t curNext = ((AliEMCALDigit *)sdigits->At(0))->GetId() ;
268 if(curNext < nextSig)
272 TArrayI index(input) ;
273 index.Reset() ; //Set all indexes to zero
275 AliEMCALDigit * digit = 0 ;
276 AliEMCALDigit * curSDigit = 0 ;
278 TClonesArray * ticks = new TClonesArray("AliEMCALTick",1000) ;
280 //Put Noise contribution
281 for(absID = 1; absID <= nEMC; absID++){
282 Float_t noise = gRandom->Gaus(0., fPinNoise);
283 new((*digits)[absID-1]) AliEMCALDigit( -1, -1, absID,sDigitizer->Digitize(noise), TimeOfNoise() ) ;
284 //look if we have to add signal?
285 digit = (AliEMCALDigit *) digits->At(absID-1) ;
287 //Add SDigits from all inputs
290 Float_t a = digit->GetAmp() ;
291 Float_t b = TMath::Abs( a /fTimeSignalLength) ;
292 //Mark the beginnign of the signal
293 new((*ticks)[contrib++]) AliEMCALTick(digit->GetTime(),0, b);
294 //Mark the end of the ignal
295 new((*ticks)[contrib++]) AliEMCALTick(digit->GetTime()+fTimeSignalLength, -a, -b);
299 for(i = 0; i< input ; i++){ //loop over (possible) merge sources
300 if(((TClonesArray *)sdigArray->At(i))->GetEntriesFast() > index[i] )
301 curSDigit = (AliEMCALDigit*)((TClonesArray *)sdigArray->At(i))->At(index[i]) ;
304 //May be several digits will contribute from the same input
305 while(curSDigit && curSDigit->GetId() == absID){
306 //Shift primary to separate primaries belonging different inputs
307 Int_t primaryoffset ;
309 primaryoffset = fManager->GetMask(i) ;
312 curSDigit->ShiftPrimary(primaryoffset) ;
314 a = curSDigit->GetAmp() ;
315 b = a /fTimeSignalLength ;
316 new((*ticks)[contrib++]) AliEMCALTick(curSDigit->GetTime(),0, b);
317 new((*ticks)[contrib++]) AliEMCALTick(curSDigit->GetTime()+fTimeSignalLength, -a, -b);
319 *digit = *digit + *curSDigit ; //add energies
322 if(((TClonesArray *)sdigArray->At(i))->GetEntriesFast() > index[i] )
323 curSDigit = (AliEMCALDigit*)((TClonesArray *)sdigArray->At(i))->At(index[i]) ;
329 //calculate and set time
330 Float_t time = FrontEdgeTime(ticks) ;
331 digit->SetTime(time) ;
333 //Find next signal module
335 for(i=0; i<input; i++){
336 sdigits = ((TClonesArray *)sdigArray->At(i)) ;
337 Int_t curNext = nextSig ;
338 if(sdigits->GetEntriesFast() > index[i] ){
339 curNext = ((AliEMCALDigit *) sdigits->At(index[i]))->GetId() ;
342 if(curNext < nextSig) nextSig = curNext ;
353 //remove digits below thresholds
354 for(absID = 0; absID < nEMC/2 ; absID++){
356 if(sDigitizer->Calibrate(((AliEMCALDigit*)digits->At(absID))->GetAmp()) < fTowerDigitThreshold)
357 digits->RemoveAt(absID) ;
359 digit->SetTime(gRandom->Gaus(digit->GetTime(),fTimeResolution) ) ;
362 for(absID = nEMC/2; absID < nEMC ; absID++){
364 if(sDigitizer->Calibrate(((AliEMCALDigit*)digits->At(absID))->GetAmp()) < fPreShowerDigitThreshold)
365 digits->RemoveAt(absID) ;
367 digit->SetTime(gRandom->Gaus(digit->GetTime(),fTimeResolution) ) ;
372 Int_t ndigits = digits->GetEntriesFast() ;
374 digits->Expand(ndigits) ;
377 //Set indexes in list of digits
379 for (i = 0 ; i < ndigits ; i++) {
380 AliEMCALDigit * digit = (AliEMCALDigit *) digits->At(i) ;
381 digit->SetIndexInList(i) ;
382 Float_t energy = sDigitizer->Calibrate(digit->GetAmp()) ;
383 digit->SetAmp(DigitizeEnergy(energy,digit->GetId()) ) ;
387 //____________________________________________________________________________
389 Int_t AliEMCALDigitizer::DigitizeEnergy(Float_t energy, Int_t absId)
391 Int_t channel = -999;
392 Int_t nphi = AliEMCALGetter::GetInstance()->EMCALGeometry()->GetNPhi() ;
393 Int_t nz = AliEMCALGetter::GetInstance()->EMCALGeometry()->GetNZ() ;
395 if(absId <= nphi*nz){ //digitize as tower
396 channel = static_cast<Int_t> (TMath::Ceil( (energy + fADCpedestalTower)/fADCchannelTower )) ;
397 if(channel > fNADCTower )
398 channel = fNADCTower ;
400 channel = static_cast<Int_t>(TMath::Ceil( (energy + fADCpedestalPreSho)/fADCchannelPreSho )) ;
401 if(channel > fNADCPreSho )
402 channel = fNADCPreSho ;
408 //____________________________________________________________________________
409 void AliEMCALDigitizer::Exec(Option_t *option) {
411 if(strcmp(GetName(), "") == 0 )
414 if (strstr(option,"print")) {
419 if(strstr(option,"tim"))
420 gBenchmark->Start("EMCALDigitizer");
422 AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
429 treeD = fManager->GetTreeD() ;
430 nevents = 1 ; // Will process only one event
433 gAlice->GetEvent(0) ;
434 nevents = (Int_t) gAlice->TreeE()->GetEntries() ;
435 treeD=gAlice->TreeD() ;
439 //Check, if this branch already exits
441 TObjArray * lob = (TObjArray*)treeD->GetListOfBranches() ;
443 TBranch * branch = 0 ;
444 Bool_t emcalfound = kFALSE, digitizerfound = kFALSE ;
446 while ( (branch = (TBranch*)next()) && (!emcalfound || !digitizerfound) ) {
447 if ( (strcmp(branch->GetName(), "EMCAL")==0) &&
448 (strcmp(branch->GetTitle(), GetName())==0) )
451 else if ( (strcmp(branch->GetName(), "AliEMCALDigitizer")==0) &&
452 (strcmp(branch->GetTitle(), GetName())==0) )
453 digitizerfound = kTRUE ;
457 cerr << "WARNING: AliEMCALDigitizer -> Digits branch with name " << GetName()
458 << " already exits" << endl ;
461 if ( digitizerfound ) {
462 cerr << "WARNING: AliEMCALDigitizer -> Digitizer branch with name " << GetName()
463 << " already exits" << endl ;
469 for(ievent = 0; ievent < nevents; ievent++){
473 for(input = 0 ; input < fManager->GetNinputs(); input ++){
474 TTree * treeS = fManager->GetInputTreeS(input) ;
476 cerr << "AliEMCALDigitizer -> No Input " << endl ;
479 gime->ReadTreeS(treeS,input) ;
483 gime->Event(ievent,"S") ;
485 Digitize(ievent) ; //Add prepared SDigits to digits and add the noise
487 WriteDigits(ievent) ;
489 if(strstr(option,"deb"))
492 //increment the total number of Digits per run
493 fDigitsInRun += gime->Digits()->GetEntriesFast() ;
497 if ( fSplitFile->IsOpen() )
498 fSplitFile->Close() ;
500 if(strstr(option,"tim")){
501 gBenchmark->Stop("EMCALDigitizer");
502 cout << "AliEMCALDigitizer:" << endl ;
503 cout << " took " << gBenchmark->GetCpuTime("EMCALDigitizer") << " seconds for Digitizing "
504 << gBenchmark->GetCpuTime("EMCALDigitizer")/nevents << " seconds per event " << endl ;
512 //__________________________________________________________________
513 void AliEMCALDigitizer::MixWith(char* headerFile){
514 // Alows produce digits by superimposing background and signal event.
515 // It is assumed, that headers file with SIGNAL events is opened in
516 // constructor, and now we set the BACKGROUND event, with which we
517 // will mix. Thus we avoid writing (changing) huge and expencive
518 // backgound files: all output will be writen into SIGNAL, i.e.
519 // opened in constructor file.
521 // One can open as many files to mix with as one wants.
523 if( strcmp(GetName(), "") == 0 )
527 cout << "Can not use this method under AliRunDigitizer " << endl ;
529 } // check if the specified SDigits do not already exist on the White Board:
530 // //Folders/RunMC/Event/Data/EMCAL/SDigits/headerFile/sdigitsname
532 TString path = "Folders/RunMC/Event/Data/EMCAL/SDigits" ;
536 if ( gROOT->FindObjectAny(path.Data()) ) {
537 cerr << "WARNING: AliEMCALDigitizer::MixWith -> Entry already exists, do not add" << endl ;
541 AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
542 gime->PostSDigits(GetName(),headerFile) ;
544 // check if the requested file is already open or exist and if SDigits Branch exist
545 TFile * file = (TFile*)gROOT->FindObject(headerFile);
547 file = new TFile(headerFile, "READ") ;
549 cerr << "ERROR: AliEMCALDigitizer::MixWith -> File " << headerFile << " does not exist!" << endl ;
556 //__________________________________________________________________
557 void AliEMCALDigitizer::Print(Option_t* option)const {
558 if( strcmp(GetName(), "") != 0) {
560 cout << "------------------- "<< GetName() << " -------------" << endl ;
561 cout << "Digitizing sDigits from file(s): " <<endl ;
563 TCollection * folderslist = ((TFolder*)gROOT->FindObjectAny("Folders/RunMC/Event/Data/EMCAL/SDigits"))->GetListOfFolders() ;
564 TIter next(folderslist) ;
565 TFolder * folder = 0 ;
566 while ( (folder = (TFolder*)next()) )
567 if ( folder->FindObject(GetName()) )
569 cout << "Adding SDigits " << GetName() << " from " << folder->GetName() << endl ;
571 cout << "Writing digits to " << GetTitle() << endl ;
574 cout << "With following parameters: " << endl ;
575 cout << " Electronics noise in EMC (fPinNoise) = " << fPinNoise << endl ;
576 cout << " Threshold in EMC (fTowerDigitThreshold) = " << fTowerDigitThreshold << endl;
577 cout << " Threshold in PreShower (fPreShowerDigitThreshold) = " << fPreShowerDigitThreshold << endl ; ;
578 cout << "---------------------------------------------------" << endl ;
581 cout << "AliEMCALDigitizer not initialized " << endl ;
585 //__________________________________________________________________
586 void AliEMCALDigitizer::PrintDigits(Option_t * option){
588 AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
589 TClonesArray * fDigits = gime->Digits() ;
591 cout << "AliEMCALDigitiser:"<< endl ;
592 cout << " Number of entries in Digits list " << fDigits->GetEntriesFast() << endl ;
594 if(strstr(option,"all")){
597 AliEMCALDigit * digit;
598 cout << "Digit Id " << " Amplitude " << " Index " << " Nprim " << " Primaries list " << endl;
600 for (index = 0 ; index < fDigits->GetEntries() ; index++) {
601 digit = (AliEMCALDigit * ) fDigits->At(index) ;
602 cout << setw(8) << digit->GetId() << " " << setw(3) << digit->GetAmp() << " "
603 << setw(6) << digit->GetIndexInList() << " "
604 << setw(5) << digit->GetNprimary() <<" ";
607 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++)
608 cout << setw(5) << digit->GetPrimary(iprimary+1) << " ";
614 //_________________________________________________________________________________________
615 void AliEMCALDigitizer::WriteDigits(Int_t event)
618 // Makes TreeD in the output file.
619 // Check if branch already exists:
620 // if yes, exit without writing: ROOT TTree does not support overwriting/updating of
621 // already existing branches.
622 // else creates branch with Digits, named "EMCAL", title "...",
623 // and branch "AliEMCALDigitizer", with the same title to keep all the parameters
624 // and names of files, from which digits are made.
626 AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
627 const TClonesArray * digits = gime->Digits(GetName()) ;
631 treeD = fManager->GetTreeD() ;
633 if (!gAlice->TreeD() )
634 gAlice->MakeTree("D",fSplitFile);
635 treeD = gAlice->TreeD();
638 // -- create Digits branch
639 Int_t bufferSize = 32000 ;
640 TBranch * digitsBranch = treeD->Branch("EMCAL",&digits,bufferSize);
641 digitsBranch->SetTitle(GetName());
643 // -- Create Digitizer branch
644 Int_t splitlevel = 0 ;
645 AliEMCALDigitizer * d = gime->Digitizer(GetName()) ;
646 TBranch * digitizerBranch = treeD->Branch("AliEMCALDigitizer", "AliEMCALDigitizer", &d,bufferSize,splitlevel);
647 digitizerBranch->SetTitle(GetName());
649 digitsBranch->Fill() ;
650 digitizerBranch->Fill() ;
654 //____________________________________________________________________________
655 Float_t AliEMCALDigitizer::FrontEdgeTime(TClonesArray * ticks)
657 ticks->Sort() ; //Sort in accordance with times of ticks
659 AliEMCALTick * ctick = (AliEMCALTick *) it.Next() ;
660 Float_t time = ctick->CrossingTime(fTimeThreshold) ;
663 while((t=(AliEMCALTick*) it.Next())){
664 if(t->GetTime() < time) //This tick starts before crossing
669 time = ctick->CrossingTime(fTimeThreshold) ;
673 //____________________________________________________________________________
674 Float_t AliEMCALDigitizer::TimeOfNoise(void)
675 { // Calculates the time signal generated by noise
676 //to be rewritten, now returns just big number
680 //____________________________________________________________________________
681 void AliEMCALDigitizer::SetSDigitsBranch(const char* title)
683 // we set title (comment) of the SDigits branch in the first! header file
684 if( strcmp(GetName(), "") == 0 )
687 AliEMCALGetter::GetInstance()->SDigits()->SetName(title) ;
690 //__________________________________________________________________
691 void AliEMCALDigitizer::SetSplitFile(const TString splitFileName)
693 // Diverts the Digits in a file separate from the hits file
695 // I guess it is not going to work if we do merging
697 cerr << "ERROR: AliEMCALDigitizer::SetSplitFile -> Not yet available in case of merging activated " << endl ;
701 TDirectory * cwd = gDirectory ;
702 if ( !(gAlice->GetTreeDFileName() == splitFileName) ) {
703 if (gAlice->GetTreeDFile() )
704 gAlice->GetTreeDFile()->Close() ;
707 fSplitFile = gAlice->InitTreeFile("D",splitFileName.Data());
709 if ( !fSplitFile->Get("gAlice") )
712 TTree *treeE = gAlice->TreeE();
714 cerr << "ERROR: AliEMCALDigitizer::SetSplitFile -> No TreeE found "<<endl;
719 if ( !fSplitFile->Get("TreeE") ) {
720 AliHeader *header = new AliHeader();
721 treeE->SetBranchAddress("Header", &header);
722 treeE->SetBranchStatus("*",1);
723 TTree *treeENew = treeE->CloneTree();
728 if ( !fSplitFile->Get("AliceGeom") ) {
729 TGeometry *AliceGeom = static_cast<TGeometry*>(cwd->Get("AliceGeom"));
731 cerr << "ERROR: AliEMCALDigitizer::SetSplitFile -> AliceGeom was not found in the input file "<<endl;
737 gAlice->MakeTree("D",fSplitFile);
739 cout << "INFO: AliEMCALDigitizer::SetSPlitMode -> Digits will be stored in " << splitFileName.Data() << endl ;