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()
91 fDefaultInit = kTRUE ;
95 //____________________________________________________________________________
96 AliEMCALDigitizer::AliEMCALDigitizer(const char *headerFile,const char *name)
99 SetTitle(headerFile) ;
100 fManager = 0 ; // We work in the standalong mode
104 fDefaultInit = kFALSE ;
108 //____________________________________________________________________________
109 AliEMCALDigitizer::AliEMCALDigitizer(AliRunDigitizer * ard):AliDigitizer(ard)
113 SetTitle("aliroot") ;
116 //____________________________________________________________________________
117 AliEMCALDigitizer::~AliEMCALDigitizer()
120 // fDefaultInit = kTRUE if Digitizer created by default ctor (to get just the parameters)
123 AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
125 // remove the task from the folder list
126 gime->RemoveTask("S",GetName()) ;
127 gime->RemoveTask("D",GetName()) ;
129 // remove the Digits from the folder list
130 gime->RemoveObjects("D", GetName()) ;
132 // remove the SDigits from the folder list
133 gime->RemoveSDigits() ;
142 //____________________________________________________________________________
143 void AliEMCALDigitizer::InitParameters()
147 fPinNoise = 0.00001 ;
148 fTowerDigitThreshold = 0.001 ;
149 fTimeResolution = 0.5e-9 ;
150 fTimeSignalLength = 1.0e-9 ;
151 fPreShowerDigitThreshold = fTowerDigitThreshold/25. ;
152 fInitialized = kFALSE ;
153 fADCchannelTower = 0.000220; // width of one ADC channel in GeV
154 fADCpedestalTower = 0.005 ; // GeV
155 fNADCTower = (Int_t) TMath::Power(2,16) ; // number of channels in Tower ADC
157 fADCchannelPreSho = 0.0000300; // width of one ADC channel in Pre Shower
158 fADCpedestalPreSho = 0.005 ; //
159 fNADCPreSho = (Int_t) TMath::Power(2,12); // number of channels in Pre ShowerADC
161 fTimeThreshold = 0.001*10000000 ; //Means 1 MeV in terms of SDigits amplitude
165 //____________________________________________________________________________
166 Bool_t AliEMCALDigitizer::Init()
168 // Makes all memory allocations
170 AliEMCALGetter * gime = AliEMCALGetter::GetInstance(GetTitle(), GetName(), "update") ;
172 cerr << "ERROR: AliEMCALDigitizer::Init -> Could not obtain the Getter object !" << endl ;
176 //const AliEMCALGeometry * geom = gime->EMCALGeometry() ;
177 //fEmcCrystals = geom->GetNModules() * geom->GetNCristalsInModule() ;
179 // Post Digits to the white board
180 gime->PostDigits(GetName() ) ;
182 // Post Digitizer to the white board
183 gime->PostDigitizer(this) ;
185 //Mark that we will use current header file
187 gime->PostSDigits(GetName(),GetTitle()) ;
188 gime->PostSDigitizer(GetName(),GetTitle()) ;
194 //____________________________________________________________________________
195 void AliEMCALDigitizer::Reset() {
196 //sets current event number to the first simulated event
197 if( strcmp(GetName(), "") == 0 )
201 // for(inputs = 0; inputs < fNinputs ;inputs++)
202 // fIevent->AddAt(-1, inputs ) ;
206 //____________________________________________________________________________
207 void AliEMCALDigitizer::Digitize(const Int_t event) {
209 // Makes the digitization of the collected summable digits
210 // for this it first creates the array of all EMCAL modules
211 // filled with noise (different for EMC, CPV and PPSD) and
212 // after that adds contributions from SDigits. This design
213 // helps to avoid scanning over the list of digits to add
214 // contribution of any new SDigit.
216 AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
217 TClonesArray * digits = gime->Digits(GetName()) ;
221 const AliEMCALGeometry *geom = gime->EMCALGeometry() ;
224 //Making digits with noise, first EMC
225 Int_t nEMC = 2*geom->GetNPhi()*geom->GetNZ();
227 TString name = geom->GetName() ;
229 // get first the sdigitizer from the tasks list (must have same name as the digitizer)
230 const AliEMCALSDigitizer * sDigitizer = gime->SDigitizer(GetName());
232 cerr << "ERROR: AliEMCALDigitizer::Digitize -> SDigitizer with name " << GetName() << " not found " << endl ;
235 // loop through the sdigits posted to the White Board and add them to the noise
236 TCollection * folderslist = gime->SDigitsFolder()->GetListOfFolders() ;
237 TIter next(folderslist) ;
238 TFolder * folder = 0 ;
239 TClonesArray * sdigits = 0 ;
241 TObjArray * sdigArray = new TObjArray(2) ;
242 while ( (folder = (TFolder*)next()) ) {
243 if ( (sdigits = (TClonesArray*)folder->FindObject(GetName()) ) ) {
244 TString fileName(folder->GetName()) ;
245 fileName.ReplaceAll("_","/") ;
246 cout << "INFO: AliEMCALDigitizer::Digitize -> Adding SDigits "
247 << GetName() << " from " << fileName << endl ;
248 sdigArray->AddAt(sdigits, input) ;
253 //Find the first tower with signal
254 Int_t nextSig = 200000 ;
256 for(i=0; i<input; i++){
257 sdigits = (TClonesArray *)sdigArray->At(i) ;
258 if ( !sdigits->GetEntriesFast() )
260 Int_t curNext = ((AliEMCALDigit *)sdigits->At(0))->GetId() ;
261 if(curNext < nextSig)
265 TArrayI index(input) ;
266 index.Reset() ; //Set all indexes to zero
268 AliEMCALDigit * digit = 0 ;
269 AliEMCALDigit * curSDigit = 0 ;
271 TClonesArray * ticks = new TClonesArray("AliEMCALTick",1000) ;
273 //Put Noise contribution
274 for(absID = 1; absID <= nEMC; absID++){
275 Float_t noise = gRandom->Gaus(0., fPinNoise);
276 new((*digits)[absID-1]) AliEMCALDigit( -1, -1, absID,sDigitizer->Digitize(noise), TimeOfNoise() ) ;
277 //look if we have to add signal?
278 digit = (AliEMCALDigit *) digits->At(absID-1) ;
280 //Add SDigits from all inputs
283 Float_t a = digit->GetAmp() ;
284 Float_t b = TMath::Abs( a /fTimeSignalLength) ;
285 //Mark the beginnign of the signal
286 new((*ticks)[contrib++]) AliEMCALTick(digit->GetTime(),0, b);
287 //Mark the end of the ignal
288 new((*ticks)[contrib++]) AliEMCALTick(digit->GetTime()+fTimeSignalLength, -a, -b);
292 for(i = 0; i< input ; i++){ //loop over (possible) merge sources
293 if(((TClonesArray *)sdigArray->At(i))->GetEntriesFast() > index[i] )
294 curSDigit = (AliEMCALDigit*)((TClonesArray *)sdigArray->At(i))->At(index[i]) ;
297 //May be several digits will contribute from the same input
298 while(curSDigit && curSDigit->GetId() == absID){
299 //Shift primary to separate primaries belonging different inputs
300 Int_t primaryoffset ;
302 primaryoffset = fManager->GetMask(i) ;
305 curSDigit->ShiftPrimary(primaryoffset) ;
307 a = curSDigit->GetAmp() ;
308 b = a /fTimeSignalLength ;
309 new((*ticks)[contrib++]) AliEMCALTick(curSDigit->GetTime(),0, b);
310 new((*ticks)[contrib++]) AliEMCALTick(curSDigit->GetTime()+fTimeSignalLength, -a, -b);
312 *digit = *digit + *curSDigit ; //add energies
315 if(((TClonesArray *)sdigArray->At(i))->GetEntriesFast() > index[i] )
316 curSDigit = (AliEMCALDigit*)((TClonesArray *)sdigArray->At(i))->At(index[i]) ;
322 //calculate and set time
323 Float_t time = FrontEdgeTime(ticks) ;
324 digit->SetTime(time) ;
326 //Find next signal module
328 for(i=0; i<input; i++){
329 sdigits = ((TClonesArray *)sdigArray->At(i)) ;
330 Int_t curNext = nextSig ;
331 if(sdigits->GetEntriesFast() > index[i] ){
332 curNext = ((AliEMCALDigit *) sdigits->At(index[i]))->GetId() ;
335 if(curNext < nextSig) nextSig = curNext ;
346 //remove digits below thresholds
348 for(absID = 0; absID < nEMC/2 ; absID++){
349 if(sDigitizer->Calibrate(((AliEMCALDigit*)digits->At(absID))->GetAmp()) < fTowerDigitThreshold)
350 digits->RemoveAt(absID) ;
352 digit->SetTime(gRandom->Gaus(digit->GetTime(),fTimeResolution) ) ;
355 for(absID = nEMC/2; absID < nEMC ; absID++){
357 if(sDigitizer->Calibrate(((AliEMCALDigit*)digits->At(absID))->GetAmp()) < fPreShowerDigitThreshold)
358 digits->RemoveAt(absID) ;
360 digit->SetTime(gRandom->Gaus(digit->GetTime(),fTimeResolution) ) ;
365 Int_t ndigits = digits->GetEntriesFast() ;
367 digits->Expand(ndigits) ;
370 //Set indexes in list of digits
372 for (i = 0 ; i < ndigits ; i++) {
373 AliEMCALDigit * digit = (AliEMCALDigit *) digits->At(i) ;
374 digit->SetIndexInList(i) ;
375 Float_t energy = sDigitizer->Calibrate(digit->GetAmp()) ;
376 digit->SetAmp(DigitizeEnergy(energy,digit->GetId()) ) ;
380 //____________________________________________________________________________
382 Int_t AliEMCALDigitizer::DigitizeEnergy(Float_t energy, Int_t absId)
384 Int_t channel = -999;
385 Int_t nphi = AliEMCALGetter::GetInstance()->EMCALGeometry()->GetNPhi() ;
386 Int_t nz = AliEMCALGetter::GetInstance()->EMCALGeometry()->GetNZ() ;
388 if(absId <= nphi*nz){ //digitize as tower
389 channel = static_cast<Int_t> (TMath::Ceil( (energy + fADCpedestalTower)/fADCchannelTower )) ;
390 if(channel > fNADCTower )
391 channel = fNADCTower ;
393 channel = static_cast<Int_t>(TMath::Ceil( (energy + fADCpedestalPreSho)/fADCchannelPreSho )) ;
394 if(channel > fNADCPreSho )
395 channel = fNADCPreSho ;
401 //____________________________________________________________________________
402 void AliEMCALDigitizer::Exec(Option_t *option) {
404 if(strcmp(GetName(), "") == 0 )
407 if (strstr(option,"print")) {
412 if(strstr(option,"tim"))
413 gBenchmark->Start("EMCALDigitizer");
415 AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
422 treeD = fManager->GetTreeD() ;
423 nevents = 1 ; // Will process only one event
426 gAlice->GetEvent(0) ;
427 nevents = (Int_t) gAlice->TreeE()->GetEntries() ;
428 treeD=gAlice->TreeD() ;
432 //Check, if this branch already exits
434 TObjArray * lob = (TObjArray*)treeD->GetListOfBranches() ;
436 TBranch * branch = 0 ;
437 Bool_t emcalfound = kFALSE, digitizerfound = kFALSE ;
439 while ( (branch = (TBranch*)next()) && (!emcalfound || !digitizerfound) ) {
440 if ( (strcmp(branch->GetName(), "EMCAL")==0) &&
441 (strcmp(branch->GetTitle(), GetName())==0) )
444 else if ( (strcmp(branch->GetName(), "AliEMCALDigitizer")==0) &&
445 (strcmp(branch->GetTitle(), GetName())==0) )
446 digitizerfound = kTRUE ;
450 cerr << "WARNING: AliEMCALDigitizer -> Digits branch with name " << GetName()
451 << " already exits" << endl ;
454 if ( digitizerfound ) {
455 cerr << "WARNING: AliEMCALDigitizer -> Digitizer branch with name " << GetName()
456 << " already exits" << endl ;
462 for(ievent = 0; ievent < nevents; ievent++){
466 for(input = 0 ; input < fManager->GetNinputs(); input ++){
467 TTree * treeS = fManager->GetInputTreeS(input) ;
469 cerr << "AliEMCALDigitizer -> No Input " << endl ;
472 gime->ReadTreeS(treeS,input) ;
476 gime->Event(ievent,"S") ;
478 Digitize(ievent) ; //Add prepared SDigits to digits and add the noise
480 WriteDigits(ievent) ;
482 if(strstr(option,"deb"))
485 //increment the total number of Digits per run
486 fDigitsInRun += gime->Digits()->GetEntriesFast() ;
489 if(strstr(option,"tim")){
490 gBenchmark->Stop("EMCALDigitizer");
491 cout << "AliEMCALDigitizer:" << endl ;
492 cout << " took " << gBenchmark->GetCpuTime("EMCALDigitizer") << " seconds for Digitizing "
493 << gBenchmark->GetCpuTime("EMCALDigitizer")/nevents << " seconds per event " << endl ;
501 //__________________________________________________________________
502 void AliEMCALDigitizer::MixWith(char* headerFile){
503 // Alows produce digits by superimposing background and signal event.
504 // It is assumed, that headers file with SIGNAL events is opened in
505 // constructor, and now we set the BACKGROUND event, with which we
506 // will mix. Thus we avoid writing (changing) huge and expencive
507 // backgound files: all output will be writen into SIGNAL, i.e.
508 // opened in constructor file.
510 // One can open as many files to mix with as one wants.
512 if( strcmp(GetName(), "") == 0 )
516 cout << "Can not use this method under AliRunDigitizer " << endl ;
518 } // check if the specified SDigits do not already exist on the White Board:
519 // //Folders/RunMC/Event/Data/EMCAL/SDigits/headerFile/sdigitsname
521 TString path = "Folders/RunMC/Event/Data/EMCAL/SDigits" ;
525 if ( gROOT->FindObjectAny(path.Data()) ) {
526 cerr << "WARNING: AliEMCALDigitizer::MixWith -> Entry already exists, do not add" << endl ;
530 AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
531 gime->PostSDigits(GetName(),headerFile) ;
533 // check if the requested file is already open or exist and if SDigits Branch exist
534 TFile * file = (TFile*)gROOT->FindObject(headerFile);
536 file = new TFile(headerFile, "READ") ;
538 cerr << "ERROR: AliEMCALDigitizer::MixWith -> File " << headerFile << " does not exist!" << endl ;
545 //__________________________________________________________________
546 void AliEMCALDigitizer::Print(Option_t* option)const {
547 if( strcmp(GetName(), "") != 0) {
549 cout << "------------------- "<< GetName() << " -------------" << endl ;
550 cout << "Digitizing sDigits from file(s): " <<endl ;
552 TCollection * folderslist = ((TFolder*)gROOT->FindObjectAny("Folders/RunMC/Event/Data/EMCAL/SDigits"))->GetListOfFolders() ;
553 TIter next(folderslist) ;
554 TFolder * folder = 0 ;
555 while ( (folder = (TFolder*)next()) )
556 if ( folder->FindObject(GetName()) )
558 cout << "Adding SDigits " << GetName() << " from " << folder->GetName() << endl ;
560 cout << "Writing digits to " << GetTitle() << endl ;
563 cout << "With following parameters: " << endl ;
564 cout << " Electronics noise in EMC (fPinNoise) = " << fPinNoise << endl ;
565 cout << " Threshold in EMC (fTowerDigitThreshold) = " << fTowerDigitThreshold << endl;
566 cout << " Threshold in PreShower (fPreShowerDigitThreshold) = " << fPreShowerDigitThreshold << endl ; ;
567 cout << "---------------------------------------------------" << endl ;
570 cout << "AliEMCALDigitizer not initialized " << endl ;
574 //__________________________________________________________________
575 void AliEMCALDigitizer::PrintDigits(Option_t * option){
577 AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
578 TClonesArray * fDigits = gime->Digits() ;
580 cout << "AliEMCALDigitiser:"<< endl ;
581 cout << " Number of entries in Digits list " << fDigits->GetEntriesFast() << endl ;
583 if(strstr(option,"all")){
586 AliEMCALDigit * digit;
587 cout << "Digit Id " << " Amplitude " << " Index " << " Nprim " << " Primaries list " << endl;
589 for (index = 0 ; index < fDigits->GetEntries() ; index++) {
590 digit = (AliEMCALDigit * ) fDigits->At(index) ;
591 cout << setw(8) << digit->GetId() << " " << setw(3) << digit->GetAmp() << " "
592 << setw(6) << digit->GetIndexInList() << " "
593 << setw(5) << digit->GetNprimary() <<" ";
596 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++)
597 cout << setw(5) << digit->GetPrimary(iprimary+1) << " ";
603 //_________________________________________________________________________________________
604 void AliEMCALDigitizer::WriteDigits(Int_t event)
607 // Makes TreeD in the output file.
608 // Check if branch already exists:
609 // if yes, exit without writing: ROOT TTree does not support overwriting/updating of
610 // already existing branches.
611 // else creates branch with Digits, named "EMCAL", title "...",
612 // and branch "AliEMCALDigitizer", with the same title to keep all the parameters
613 // and names of files, from which digits are made.
615 AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
616 const TClonesArray * digits = gime->Digits(GetName()) ;
620 treeD = fManager->GetTreeD() ;
622 if (!gAlice->TreeD() )
623 gAlice->MakeTree("D",fSplitFile);
624 treeD = gAlice->TreeD();
627 // -- create Digits branch
628 Int_t bufferSize = 32000 ;
629 TBranch * digitsBranch = treeD->Branch("EMCAL",&digits,bufferSize);
630 digitsBranch->SetTitle(GetName());
632 // -- Create Digitizer branch
633 Int_t splitlevel = 0 ;
634 AliEMCALDigitizer * d = gime->Digitizer(GetName()) ;
635 TBranch * digitizerBranch = treeD->Branch("AliEMCALDigitizer", "AliEMCALDigitizer", &d,bufferSize,splitlevel);
636 digitizerBranch->SetTitle(GetName());
638 digitsBranch->Fill() ;
639 digitizerBranch->Fill() ;
643 //____________________________________________________________________________
644 Float_t AliEMCALDigitizer::FrontEdgeTime(TClonesArray * ticks)
646 ticks->Sort() ; //Sort in accordance with times of ticks
648 AliEMCALTick * ctick = (AliEMCALTick *) it.Next() ;
649 Float_t time = ctick->CrossingTime(fTimeThreshold) ;
652 while((t=(AliEMCALTick*) it.Next())){
653 if(t->GetTime() < time) //This tick starts before crossing
658 time = ctick->CrossingTime(fTimeThreshold) ;
662 //____________________________________________________________________________
663 Float_t AliEMCALDigitizer::TimeOfNoise(void)
664 { // Calculates the time signal generated by noise
665 //to be rewritten, now returns just big number
669 //____________________________________________________________________________
670 void AliEMCALDigitizer::SetSDigitsBranch(const char* title)
672 // we set title (comment) of the SDigits branch in the first! header file
673 if( strcmp(GetName(), "") == 0 )
676 AliEMCALGetter::GetInstance()->SDigits()->SetName(title) ;
679 //__________________________________________________________________
680 void AliEMCALDigitizer::SetSplitFile(const TString splitFileName)
682 // Diverts the Digits in a file separate from the hits file
684 // I guess it is not going to work if we do merging
686 cerr << "ERROR: AliEMCALDigitizer::SetSplitFile -> Not yet available in case of merging activated " << endl ;
690 TDirectory * cwd = gDirectory ;
691 if ( !(gAlice->GetTreeDFileName() == splitFileName) ) {
692 if (gAlice->GetTreeDFile() )
693 gAlice->GetTreeDFile()->Close() ;
696 fSplitFile = gAlice->InitTreeFile("D",splitFileName.Data());
698 gAlice->Write(0, TObject::kOverwrite);
700 TTree *treeE = gAlice->TreeE();
702 cerr << "ERROR: AliEMCALDigitizer::SetSplitFile -> No TreeE found "<<endl;
707 AliHeader *header = new AliHeader();
708 treeE->SetBranchAddress("Header", &header);
709 treeE->SetBranchStatus("*",1);
710 TTree *treeENew = treeE->CloneTree();
711 treeENew->Write(0, TObject::kOverwrite);
714 TGeometry *AliceGeom = static_cast<TGeometry*>(cwd->Get("AliceGeom"));
716 cerr << "ERROR: AliEMCALDigitizer::SetSplitFile -> AliceGeom was not found in the input file "<<endl;
719 AliceGeom->Write(0, TObject::kOverwrite);
721 gAlice->MakeTree("D",fSplitFile);
723 cout << "INFO: AliEMCALDigitizer::SetSPlitMode -> Digits will be stored in " << splitFileName.Data() << endl ;