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 "TBenchmark.h"
65 // --- Standard library ---
68 // --- AliRoot header files ---
71 #include "AliEMCALDigit.h"
72 #include "AliEMCALHit.h"
73 #include "AliEMCALTick.h"
74 #include "AliEMCALv1.h"
75 #include "AliEMCALDigitizer.h"
76 #include "AliEMCALSDigitizer.h"
77 #include "AliEMCALGeometry.h"
78 #include "AliEMCALGetter.h"
79 #include "AliRunDigitizer.h"
80 ClassImp(AliEMCALDigitizer)
83 //____________________________________________________________________________
84 AliEMCALDigitizer::AliEMCALDigitizer()
91 fTowerDigitThreshold = 0.0 ;
92 fTimeResolution = 0. ;
93 fTimeSignalLength = 0. ;
94 fPreShowerDigitThreshold = 0. ;
95 fADCchannelTower = 0.0; // width of one ADC channel in GeV
96 fADCpedestalTower = 0. ; // pedestal of ADC
97 fNADCTower = 0; // number of channels in Tower ADC
99 fADCchannelPreSho = 0.0; // width of one ADC channel in Pre Shower
100 fADCpedestalPreSho = 0.0 ; // pedestal of ADC
101 fNADCPreSho = 0; // number of channels in Pre Shower ADC
102 fTimeThreshold = 0.0; //Means 1 MeV in terms of SDigits amplitude
108 //____________________________________________________________________________
109 Bool_t AliEMCALDigitizer::Init()
111 // Makes all memory allocations
115 fPinNoise = 0.00001 ;
116 fTowerDigitThreshold = 0.001 ;
117 fTimeResolution = 0.5e-9 ;
118 fTimeSignalLength = 1.0e-9 ;
119 fPreShowerDigitThreshold = fTowerDigitThreshold/25. ;
120 fInitialized = kFALSE ;
121 fADCchannelTower = 0.000220; // width of one ADC channel in GeV
122 fADCpedestalTower = 0.005 ; // GeV
123 fNADCTower = (Int_t) TMath::Power(2,16) ; // number of channels in Tower ADC
125 fADCchannelPreSho = 0.0000300; // width of one ADC channel in Pre Shower
126 fADCpedestalPreSho = 0.005 ; //
127 fNADCPreSho = (Int_t) TMath::Power(2,12); // number of channels in Pre ShowerADC
129 fTimeThreshold = 0.001*10000000 ; //Means 1 MeV in terms of SDigits amplitude
134 SetTitle("aliroot") ;
135 else if (strcmp(GetTitle(),"")==0)
136 SetTitle("galice.root") ;
138 if( strcmp(GetName(), "") == 0 )
141 AliEMCALGetter * gime = AliEMCALGetter::GetInstance(GetTitle(), GetName(), "update") ;
143 cerr << "ERROR: AliEMCALDigitizer::Init -> Could not obtain the Getter object !" << endl ;
147 //const AliEMCALGeometry * geom = gime->EMCALGeometry() ;
148 //fEmcCrystals = geom->GetNModules() * geom->GetNCristalsInModule() ;
150 // Post Digits to the white board
151 gime->PostDigits(GetName() ) ;
153 // Post Digitizer to the white board
154 gime->PostDigitizer(this) ;
156 //Mark that we will use current header file
158 gime->PostSDigits(GetName(),GetTitle()) ;
159 gime->PostSDigitizer(GetName(),GetTitle()) ;
167 //____________________________________________________________________________
168 AliEMCALDigitizer::AliEMCALDigitizer(const char *headerFile,const char *name)
171 SetTitle(headerFile) ;
172 fManager = 0 ; // We work in the standalong mode
178 //____________________________________________________________________________
179 AliEMCALDigitizer::AliEMCALDigitizer(AliRunDigitizer * ard):AliDigitizer(ard)
182 SetName(""); //Will call init in the digitizing
183 SetTitle("aliroot") ;
186 //____________________________________________________________________________
187 AliEMCALDigitizer::~AliEMCALDigitizer()
192 //____________________________________________________________________________
193 void AliEMCALDigitizer::Reset() {
194 //sets current event number to the first simulated event
195 if( strcmp(GetName(), "") == 0 )
199 // for(inputs = 0; inputs < fNinputs ;inputs++)
200 // fIevent->AddAt(-1, inputs ) ;
204 //____________________________________________________________________________
205 void AliEMCALDigitizer::Digitize(const Int_t event) {
207 // Makes the digitization of the collected summable digits
208 // for this it first creates the array of all EMCAL modules
209 // filled with noise (different for EMC, CPV and PPSD) and
210 // after that adds contributions from SDigits. This design
211 // helps to avoid scanning over the list of digits to add
212 // contribution of any new SDigit.
214 AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
215 TClonesArray * digits = gime->Digits(GetName()) ;
219 const AliEMCALGeometry *geom = gime->EMCALGeometry() ;
222 //Making digits with noise, first EMC
223 Int_t nEMC = 2*geom->GetNPhi()*geom->GetNZ();
225 TString name = geom->GetName() ;
227 // get first the sdigitizer from the tasks list (must have same name as the digitizer)
228 const AliEMCALSDigitizer * sDigitizer = gime->SDigitizer(GetName());
230 cerr << "ERROR: AliEMCALDigitizer::Digitize -> SDigitizer with name " << GetName() << " not found " << endl ;
233 // loop through the sdigits posted to the White Board and add them to the noise
234 TCollection * folderslist = gime->SDigitsFolder()->GetListOfFolders() ;
235 TIter next(folderslist) ;
236 TFolder * folder = 0 ;
237 TClonesArray * sdigits = 0 ;
239 TObjArray * sdigArray = new TObjArray(2) ;
240 while ( (folder = (TFolder*)next()) )
241 if ( (sdigits = (TClonesArray*)folder->FindObject(GetName()) ) ) {
242 TString fileName(folder->GetName()) ;
243 fileName.ReplaceAll("_","/") ;
244 cout << "INFO: AliEMCALDigitizer::Digitize -> Adding SDigits "
245 << GetName() << " from " << fileName << endl ;
246 sdigArray->AddAt(sdigits, input) ;
250 //Find the first tower with signal
251 Int_t nextSig = 200000 ;
253 for(i=0; i<input; i++){
254 sdigits = (TClonesArray *)sdigArray->At(i) ;
255 if ( !sdigits->GetEntriesFast() )
257 Int_t curNext = ((AliEMCALDigit *)sdigits->At(0))->GetId() ;
258 if(curNext < nextSig)
262 TArrayI index(input) ;
263 index.Reset() ; //Set all indexes to zero
265 AliEMCALDigit * digit = 0 ;
266 AliEMCALDigit * curSDigit = 0 ;
268 TClonesArray * ticks = new TClonesArray("AliEMCALTick",1000) ;
270 //Put Noise contribution
271 for(absID = 1; absID <= nEMC; absID++){
272 Float_t noise = gRandom->Gaus(0., fPinNoise);
273 new((*digits)[absID-1]) AliEMCALDigit( -1, -1, absID,sDigitizer->Digitize(noise), TimeOfNoise() ) ;
274 //look if we have to add signal?
276 //Add SDigits from all inputs
277 digit = (AliEMCALDigit *) digits->At(absID-1) ;
281 Float_t a = digit->GetAmp() ;
282 Float_t b = TMath::Abs( a /fTimeSignalLength) ;
283 //Mark the beginnign of the signal
284 new((*ticks)[contrib++]) AliEMCALTick(digit->GetTime(),0, b);
285 //Mark the end of the ignal
286 new((*ticks)[contrib++]) AliEMCALTick(digit->GetTime()+fTimeSignalLength, -a, -b);
290 for(i = 0; i< input ; i++){ //loop over (possible) merge sources
291 if(((TClonesArray *)sdigArray->At(i))->GetEntriesFast() > index[i] )
292 curSDigit = (AliEMCALDigit*)((TClonesArray *)sdigArray->At(i))->At(index[i]) ;
295 //May be several digits will contribute from the same input
296 while(curSDigit && curSDigit->GetId() == absID){
297 //Shift primary to separate primaries belonging different inputs
298 Int_t primaryoffset ;
300 primaryoffset = fManager->GetMask(i) ;
303 curSDigit->ShiftPrimary(primaryoffset) ;
305 a = curSDigit->GetAmp() ;
306 b = a /fTimeSignalLength ;
307 new((*ticks)[contrib++]) AliEMCALTick(curSDigit->GetTime(),0, b);
308 new((*ticks)[contrib++]) AliEMCALTick(curSDigit->GetTime()+fTimeSignalLength, -a, -b);
310 *digit = *digit + *curSDigit ; //add energies
313 if(((TClonesArray *)sdigArray->At(i))->GetEntriesFast() > index[i] )
314 curSDigit = (AliEMCALDigit*)((TClonesArray *)sdigArray->At(i))->At(index[i]) ;
320 //calculate and set time
321 Float_t time = FrontEdgeTime(ticks) ;
322 digit->SetTime(time) ;
324 //Find next signal module
326 for(i=0; i<input; i++){
327 sdigits = ((TClonesArray *)sdigArray->At(i)) ;
328 Int_t curNext = nextSig ;
329 if(sdigits->GetEntriesFast() > index[i] ){
330 curNext = ((AliEMCALDigit *) sdigits->At(index[i]))->GetId() ;
333 if(curNext < nextSig) nextSig = curNext ;
344 //remove digits below thresholds
345 for(absID = 0; absID < nEMC/2 ; absID++){
346 if(sDigitizer->Calibrate(((AliEMCALDigit*)digits->At(absID))->GetAmp()) < fTowerDigitThreshold)
347 digits->RemoveAt(absID) ;
349 digit->SetTime(gRandom->Gaus(digit->GetTime(),fTimeResolution) ) ;
352 for(absID = nEMC/2; absID < nEMC ; absID++){
353 if(sDigitizer->Calibrate(((AliEMCALDigit*)digits->At(absID))->GetAmp()) < fPreShowerDigitThreshold)
354 digits->RemoveAt(absID) ;
356 digit->SetTime(gRandom->Gaus(digit->GetTime(),fTimeResolution) ) ;
361 Int_t ndigits = digits->GetEntriesFast() ;
363 digits->Expand(ndigits) ;
366 //Set indexes in list of digits
368 for (i = 0 ; i < ndigits ; i++) {
369 AliEMCALDigit * digit = (AliEMCALDigit *) digits->At(i) ;
370 digit->SetIndexInList(i) ;
371 Float_t energy = sDigitizer->Calibrate(digit->GetAmp()) ;
372 digit->SetAmp(DigitizeEnergy(energy,digit->GetId()) ) ;
376 //____________________________________________________________________________
378 Int_t AliEMCALDigitizer::DigitizeEnergy(Float_t energy, Int_t absId)
380 Int_t channel = -999;
381 Int_t nphi = AliEMCALGetter::GetInstance()->EMCALGeometry()->GetNPhi() ;
382 Int_t nz = AliEMCALGetter::GetInstance()->EMCALGeometry()->GetNZ() ;
384 if(absId <= nphi*nz){ //digitize as tower
385 channel = static_cast<Int_t> (TMath::Ceil( (energy + fADCpedestalTower)/fADCchannelTower )) ;
386 if(channel > fNADCTower )
387 channel = fNADCTower ;
389 channel = static_cast<Int_t>(TMath::Ceil( (energy + fADCpedestalPreSho)/fADCchannelPreSho )) ;
390 if(channel > fNADCPreSho )
391 channel = fNADCPreSho ;
397 //____________________________________________________________________________
398 void AliEMCALDigitizer::Exec(Option_t *option) {
400 if(strcmp(GetName(), "") == 0 )
403 if (strstr(option,"print")) {
408 if(strstr(option,"tim"))
409 gBenchmark->Start("EMCALDigitizer");
411 AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
418 treeD = fManager->GetTreeD() ;
419 nevents = 1 ; // Will process only one event
422 gAlice->GetEvent(0) ;
423 nevents = (Int_t) gAlice->TreeE()->GetEntries() ;
424 treeD=gAlice->TreeD() ;
427 cerr << " AliEMCALDigitizer :: Can not find TreeD " << endl ;
431 //Check, if this branch already exits
432 TObjArray * lob = (TObjArray*)treeD->GetListOfBranches() ;
434 TBranch * branch = 0 ;
435 Bool_t emcalfound = kFALSE, digitizerfound = kFALSE ;
437 while ( (branch = (TBranch*)next()) && (!emcalfound || !digitizerfound) ) {
438 if ( (strcmp(branch->GetName(), "EMCAL")==0) &&
439 (strcmp(branch->GetTitle(), GetName())==0) )
442 else if ( (strcmp(branch->GetName(), "AliEMCALDigitizer")==0) &&
443 (strcmp(branch->GetTitle(), GetName())==0) )
444 digitizerfound = kTRUE ;
448 cerr << "WARNING: AliEMCALDigitizer -> Digits branch with name " << GetName()
449 << " already exits" << endl ;
452 if ( digitizerfound ) {
453 cerr << "WARNING: AliEMCALDigitizer -> Digitizer branch with name " << GetName()
454 << " already exits" << endl ;
460 for(ievent = 0; ievent < nevents; ievent++){
464 for(input = 0 ; input < fManager->GetNinputs(); input ++){
465 TTree * treeS = fManager->GetInputTreeS(input) ;
467 cerr << "AliEMCALDigitizer -> No Input " << endl ;
470 gime->ReadTreeS(treeS,input) ;
474 gime->Event(ievent,"S") ;
476 Digitize(ievent) ; //Add prepared SDigits to digits and add the noise
478 WriteDigits(ievent) ;
480 if(strstr(option,"deb"))
483 //increment the total number of Digits per run
484 fDigitsInRun += gime->Digits()->GetEntriesFast() ;
487 if(strstr(option,"tim")){
488 gBenchmark->Stop("EMCALDigitizer");
489 cout << "AliEMCALDigitizer:" << endl ;
490 cout << " took " << gBenchmark->GetCpuTime("EMCALDigitizer") << " seconds for Digitizing "
491 << gBenchmark->GetCpuTime("EMCALDigitizer")/nevents << " seconds per event " << endl ;
499 //__________________________________________________________________
500 void AliEMCALDigitizer::MixWith(char* headerFile){
501 // Alows produce digits by superimposing background and signal event.
502 // It is assumed, that headers file with SIGNAL events is opened in
503 // constructor, and now we set the BACKGROUND event, with which we
504 // will mix. Thus we avoid writing (changing) huge and expencive
505 // backgound files: all output will be writen into SIGNAL, i.e.
506 // opened in constructor file.
508 // One can open as many files to mix with as one wants.
510 if( strcmp(GetName(), "") == 0 )
514 cout << "Can not use this method under AliRunDigitizer " << endl ;
516 } // check if the specified SDigits do not already exist on the White Board:
517 // //Folders/RunMC/Event/Data/EMCAL/SDigits/headerFile/sdigitsname
519 TString path = "Folders/RunMC/Event/Data/EMCAL/SDigits" ;
523 if ( gROOT->FindObjectAny(path.Data()) ) {
524 cerr << "WARNING: AliEMCALDigitizer::MixWith -> Entry already exists, do not add" << endl ;
528 AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
529 gime->PostSDigits(GetName(),headerFile) ;
531 // check if the requested file is already open or exist and if SDigits Branch exist
532 TFile * file = (TFile*)gROOT->FindObject(headerFile);
534 file = new TFile(headerFile, "READ") ;
536 cerr << "ERROR: AliEMCALDigitizer::MixWith -> File " << headerFile << " does not exist!" << endl ;
543 //__________________________________________________________________
544 void AliEMCALDigitizer::Print(Option_t* option)const {
545 if( strcmp(GetName(), "") != 0) {
547 cout << "------------------- "<< GetName() << " -------------" << endl ;
548 cout << "Digitizing sDigits from file(s): " <<endl ;
550 TCollection * folderslist = ((TFolder*)gROOT->FindObjectAny("Folders/RunMC/Event/Data/EMCAL/SDigits"))->GetListOfFolders() ;
551 TIter next(folderslist) ;
552 TFolder * folder = 0 ;
553 while ( (folder = (TFolder*)next()) )
554 if ( folder->FindObject(GetName()) )
556 cout << "Adding SDigits " << GetName() << " from " << folder->GetName() << endl ;
558 cout << "Writing digits to " << GetTitle() << endl ;
561 cout << "With following parameters: " << endl ;
562 cout << " Electronics noise in EMC (fPinNoise) = " << fPinNoise << endl ;
563 cout << " Threshold in EMC (fTowerDigitThreshold) = " << fTowerDigitThreshold << endl;
564 cout << " Threshold in PreShower (fPreShowerDigitThreshold) = " << fPreShowerDigitThreshold << endl ; ;
565 cout << "---------------------------------------------------" << endl ;
568 cout << "AliEMCALDigitizer not initialized " << endl ;
572 //__________________________________________________________________
573 void AliEMCALDigitizer::PrintDigits(Option_t * option){
575 AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
576 TClonesArray * fDigits = gime->Digits() ;
578 cout << "AliEMCALDigitiser:"<< endl ;
579 cout << " Number of entries in Digits list " << fDigits->GetEntriesFast() << endl ;
581 if(strstr(option,"all")){
584 AliEMCALDigit * digit;
585 cout << "Digit Id " << " Amplitude " << " Index " << " Nprim " << " Primaries list " << endl;
587 for (index = 0 ; index < fDigits->GetEntries() ; index++) {
588 digit = (AliEMCALDigit * ) fDigits->At(index) ;
589 cout << setw(8) << digit->GetId() << " " << setw(3) << digit->GetAmp() << " "
590 << setw(6) << digit->GetIndexInList() << " "
591 << setw(5) << digit->GetNprimary() <<" ";
594 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++)
595 cout << setw(5) << digit->GetPrimary(iprimary+1) << " ";
601 //_________________________________________________________________________________________
602 void AliEMCALDigitizer::WriteDigits(Int_t event)
605 // Makes TreeD in the output file.
606 // Check if branch already exists:
607 // if yes, exit without writing: ROOT TTree does not support overwriting/updating of
608 // already existing branches.
609 // else creates branch with Digits, named "EMCAL", title "...",
610 // and branch "AliEMCALDigitizer", with the same title to keep all the parameters
611 // and names of files, from which digits are made.
613 AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
614 const TClonesArray * digits = gime->Digits(GetName()) ;
618 treeD = fManager->GetTreeD() ;
620 treeD = gAlice->TreeD();
622 // create new branches
623 // -- generate file name if necessary
625 if(gSystem->Getenv("CONFIG_SPLIT_FILE")){ //generating file name
626 file = new char[strlen(gAlice->GetBaseFile())+20] ;
627 sprintf(file,"%s/EMCAL.Digits.root",gAlice->GetBaseFile()) ;
630 TDirectory *cwd = gDirectory;
631 // -- create Digits branch
632 Int_t bufferSize = 32000 ;
633 TBranch * digitsBranch = treeD->Branch("EMCAL",&digits,bufferSize);
634 digitsBranch->SetTitle(GetName());
636 digitsBranch->SetFile(file);
637 TIter next( digitsBranch->GetListOfBranches());
639 while ((sbr=(TBranch*)next())) {
645 // -- Create Digitizer branch
646 Int_t splitlevel = 0 ;
647 AliEMCALDigitizer * d = gime->Digitizer(GetName()) ;
648 TBranch * digitizerBranch = treeD->Branch("AliEMCALDigitizer", "AliEMCALDigitizer", &d,bufferSize,splitlevel);
649 digitizerBranch->SetTitle(GetName());
651 digitizerBranch->SetFile(file);
652 TIter next( digitizerBranch->GetListOfBranches());
654 while ((sbr=(TBranch*)next())) {
661 treeD->Write(0,kOverwrite) ;
664 //____________________________________________________________________________
665 Float_t AliEMCALDigitizer::FrontEdgeTime(TClonesArray * ticks)
667 ticks->Sort() ; //Sort in accordance with times of ticks
669 AliEMCALTick * ctick = (AliEMCALTick *) it.Next() ;
670 Float_t time = ctick->CrossingTime(fTimeThreshold) ;
673 while((t=(AliEMCALTick*) it.Next())){
674 if(t->GetTime() < time) //This tick starts before crossing
679 time = ctick->CrossingTime(fTimeThreshold) ;
683 //____________________________________________________________________________
684 Float_t AliEMCALDigitizer::TimeOfNoise(void)
685 { // Calculates the time signal generated by noise
686 //to be rewritten, now returns just big number
690 //____________________________________________________________________________
691 void AliEMCALDigitizer::SetSDigitsBranch(const char* title)
693 // we set title (comment) of the SDigits branch in the first! header file
694 if( strcmp(GetName(), "") == 0 )
697 AliEMCALGetter::GetInstance()->SDigits()->SetName(title) ;