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 //_________________________________________________________________________
19 // This is a TTask that makes SDigits out of Hits
20 // A Summable Digits is the sum of all hits originating
21 // from one in one tower of the EMCAL
22 // A threshold for assignment of the primary to SDigit is applied
23 // SDigits are written to TreeS, branch "EMCAL"
24 // AliEMCALSDigitizer with all current parameters is written
25 // to TreeS branch "AliEMCALSDigitizer".
26 // Both branches have the same title. If necessary one can produce
27 // another set of SDigits with different parameters. Two versions
28 // can be distunguished using titles of the branches.
30 // root [0] AliEMCALSDigitizer * s = new AliEMCALSDigitizer("galice.root")
31 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
32 // root [1] s->ExecuteTask()
33 // // Makes SDigitis for all events stored in galice.root
34 // root [2] s->SetPedestalParameter(0.001)
35 // // One can change parameters of digitization
36 // root [3] s->SetSDigitsBranch("Redestal 0.001")
37 // // and write them into the new branch
38 // root [4] s->ExeciteTask("deb all tim")
39 // // available parameters:
40 // deb - print # of produced SDigitis
41 // deb all - print # and list of produced SDigits
42 // tim - print benchmarking information
44 //*-- Author : Sahal Yacoob (LBL)
45 // based on : AliPHOSSDigitzer
47 // August 2002 Yves Schutz: clone PHOS as closely as possible and intoduction
48 // of new IO (à la PHOS)
49 //////////////////////////////////////////////////////////////////////////////
51 // --- ROOT system ---
52 #include <TBenchmark.h>
55 #include <Riostream.h>
59 // --- Standard library ---
62 // --- AliRoot header files ---
64 #include "AliRunLoader.h"
66 #include "AliEMCALDigit.h"
67 #include "AliEMCALLoader.h"
68 #include "AliEMCALHit.h"
69 #include "AliEMCALSDigitizer.h"
70 #include "AliEMCALGeometry.h"
71 #include "AliEMCALHistoUtilities.h"
73 ClassImp(AliEMCALSDigitizer)
75 //____________________________________________________________________________
76 AliEMCALSDigitizer::AliEMCALSDigitizer()
78 fA(0.),fB(0.),fECPrimThreshold(0.),
93 //____________________________________________________________________________
94 AliEMCALSDigitizer::AliEMCALSDigitizer(const char * alirunFileName,
95 const char * eventFolderName)
96 : TTask("EMCAL"+AliConfig::Instance()->GetSDigitizerTaskName(), alirunFileName),
97 fA(0.),fB(0.),fECPrimThreshold(0.),
99 fEventFolderName(eventFolderName),
111 if(fControlHists) BookControlHists(1);
115 //____________________________________________________________________________
116 AliEMCALSDigitizer::AliEMCALSDigitizer(const AliEMCALSDigitizer & sd)
117 : TTask(sd.GetName(),sd.GetTitle()),
120 fECPrimThreshold(sd.fECPrimThreshold),
121 fDefaultInit(sd.fDefaultInit),
122 fEventFolderName(sd.fEventFolderName),
124 fSDigitsInRun(sd.fSDigitsInRun),
125 fFirstEvent(sd.fFirstEvent),
126 fLastEvent(sd.fLastEvent),
127 fSampling(sd.fSampling),
128 fControlHists(sd.fControlHists),
135 //____________________________________________________________________________
136 AliEMCALSDigitizer::~AliEMCALSDigitizer() {
138 AliLoader *emcalLoader=0;
139 if ((emcalLoader = AliRunLoader::GetRunLoader()->GetDetectorLoader("EMCAL")))
140 emcalLoader->CleanSDigitizer();
143 //____________________________________________________________________________
144 void AliEMCALSDigitizer::Init(){
145 // Initialization: open root-file, allocate arrays for hits and sdigits,
146 // attach task SDigitizer to the list of EMCAL tasks
148 // Initialization can not be done in the default constructor
149 //============================================================= YS
150 // The initialisation is now done by the getter
154 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(AliRunLoader::GetRunLoader()->GetDetectorLoader("EMCAL"));
156 if ( emcalLoader == 0 ) {
157 Fatal("Init", "Could not obtain the AliEMCALLoader");
161 emcalLoader->PostSDigitizer(this);
162 emcalLoader->GetSDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
166 //____________________________________________________________________________
167 void AliEMCALSDigitizer::InitParameters()
169 //initialize parameters for sdigitization
171 const AliEMCALGeometry * geom = AliEMCALGeometry::GetInstance();
172 if (geom->GetSampling() == 0.) {
173 Fatal("InitParameters", "Sampling factor not set !") ;
175 // Initializes parameters
177 fB = 1.e+6; // Changed 24 Apr 2007. Dynamic range now 2 TeV
178 fSampling = geom->GetSampling();
180 // threshold for deposit energy of hit
181 fECPrimThreshold = 0.05;// GeV // 22-may-07 was 0// 24-nov-04 - was 1.e-6;
183 AliDebug(2,Form("Print: \n------------------- %s -------------\n",GetName()));
184 AliDebug(2,Form(" fInit %i\n", int(fInit)));
185 AliDebug(2,Form(" fFirstEvent %i\n", fFirstEvent));
186 AliDebug(2,Form(" fLastEvent %i\n", fLastEvent));
187 AliDebug(2,Form(" Writing SDigits to branch with title %s\n", fEventFolderName.Data()));
188 AliDebug(2,Form(" with digitization parameters A = %f\n", fA));
189 AliDebug(2,Form(" B = %f\n", fB));
190 AliDebug(2,Form(" Threshold for EC Primary assignment = %f\n", fECPrimThreshold));
191 AliDebug(2,Form(" Sampling = %f\n", fSampling));
192 AliDebug(2,Form("---------------------------------------------------\n"));
198 //____________________________________________________________________________
199 void AliEMCALSDigitizer::Exec(Option_t *option)
201 // Collects all hit of the same tower into digits
202 TString o(option); o.ToUpper();
203 if (strstr(option, "print") ) {
205 AliDebug(2,Form("Print: \n------------------- %s -------------\n",GetName()));
206 AliDebug(2,Form(" fInit %i\n", int(fInit)));
207 AliDebug(2,Form(" fFirstEvent %i\n", fFirstEvent));
208 AliDebug(2,Form(" fLastEvent %i\n", fLastEvent));
209 AliDebug(2,Form(" Writing SDigits to branch with title %s\n", fEventFolderName.Data()));
210 AliDebug(2,Form(" with digitization parameters A = %f\n", fA));
211 AliDebug(2,Form(" B = %f\n", fB));
212 AliDebug(2,Form(" Threshold for EC Primary assignment = %f\n", fECPrimThreshold));
213 AliDebug(2,Form(" Sampling = %f\n", fSampling));
214 AliDebug(2,Form("---------------------------------------------------\n"));
220 if(strstr(option,"tim"))
221 gBenchmark->Start("EMCALSDigitizer");
223 AliRunLoader *rl = AliRunLoader::GetRunLoader();
224 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(rl->GetDetectorLoader("EMCAL"));
226 //switch off reloading of this task while getting event
227 if (!fInit) { // to prevent overwrite existing file
228 AliError( Form("Give a version name different from %s", fEventFolderName.Data()) ) ;
232 if (fLastEvent == -1)
233 fLastEvent = rl->GetNumberOfEvents() - 1 ;
235 fLastEvent = TMath::Min(fLastEvent, rl->GetNumberOfEvents()-1);
237 Int_t nEvents = fLastEvent - fFirstEvent + 1;
240 Float_t energy=0.; // de * fSampling - 23-nov-04
241 rl->LoadKinematics();
242 rl->LoadHits("EMCAL");
244 for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
245 rl->GetEvent(ievent);
246 TTree * treeS = emcalLoader->TreeS();
248 emcalLoader->MakeSDigitsContainer();
249 treeS = emcalLoader->TreeS();
251 TClonesArray * hits = emcalLoader->Hits() ;
252 TClonesArray * sdigits = emcalLoader->SDigits() ;
257 AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance();
258 for ( i = 0 ; i < hits->GetEntries() ; i++ ) {
259 AliEMCALHit * hit = dynamic_cast<AliEMCALHit*>(hits->At(i)) ;
260 AliEMCALDigit * curSDigit = 0 ;
261 AliEMCALDigit * sdigit = 0 ;
262 Bool_t newsdigit = kTRUE;
264 // hit->GetId() - Absolute Id number EMCAL segment
265 if(geom->CheckAbsCellId(hit->GetId())) { // was IsInECA(hit->GetId())
266 energy = hit->GetEnergy() * fSampling; // 23-nov-04
267 if(energy > fECPrimThreshold )
268 // Assign primary number only if deposited energy is significant
269 curSDigit = new AliEMCALDigit( hit->GetPrimary(),
270 hit->GetIparent(), hit->GetId(),
271 Digitize(energy), hit->GetTime(),
274 curSDigit = new AliEMCALDigit( -1 ,
277 Digitize(energy), hit->GetTime(),
280 Warning("Exec"," abs id %i is bad \n", hit->GetId());
286 for(Int_t check= 0; check < nSdigits ; check++) {
287 sdigit = dynamic_cast<AliEMCALDigit *>(sdigits->At(check)) ;
289 if( sdigit->GetId() == curSDigit->GetId()) { // Are we in the same ECAL tower ?
290 *sdigit = *sdigit + *curSDigit;
296 new((*sdigits)[nSdigits]) AliEMCALDigit(*curSDigit);
300 } // loop over all hits (hit = deposited energy/entering particle)
303 nSdigits = sdigits->GetEntriesFast() ;
304 fSDigitsInRun += nSdigits ;
306 Double_t e=0.,esum=0.;
307 AliEMCALHistoUtilities::FillH1(fHists, 0, double(sdigits->GetEntriesFast()));
308 for (i = 0 ; i < sdigits->GetEntriesFast() ; i++) {
309 AliEMCALDigit * sdigit = dynamic_cast<AliEMCALDigit *>(sdigits->At(i)) ;
310 sdigit->SetIndexInList(i) ;
312 AliEMCALHistoUtilities::FillH1(fHists, 2, double(sdigit->GetAmp()));
313 e = double(Calibrate(sdigit->GetAmp()));
315 AliEMCALHistoUtilities::FillH1(fHists, 3, e);
316 AliEMCALHistoUtilities::FillH1(fHists, 4, double(sdigit->GetId()));
318 if(esum>0.) AliEMCALHistoUtilities::FillH1(fHists, 1, esum);
322 Int_t bufferSize = 32000 ;
323 TBranch * sdigitsBranch = treeS->GetBranch("EMCAL");
325 sdigitsBranch->SetAddress(&sdigits);
327 treeS->Branch("EMCAL",&sdigits,bufferSize);
331 emcalLoader->WriteSDigits("OVERWRITE");
334 emcalLoader->WriteSDigitizer("OVERWRITE"); // why in event cycle ?
336 if(strstr(option,"deb"))
337 PrintSDigits(option) ;
342 emcalLoader->GetSDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
344 if(strstr(option,"tim")){
345 gBenchmark->Stop("EMCALSDigitizer");
346 printf("\n Exec: took %f seconds for SDigitizing %f seconds per event\n",
347 gBenchmark->GetCpuTime("EMCALSDigitizer"), gBenchmark->GetCpuTime("EMCALSDigitizer")/nEvents ) ;
351 //__________________________________________________________________
353 Int_t AliEMCALSDigitizer::Digitize(Float_t energy)const {
354 // Digitize the energy
355 Double_t aSignal = fA + energy*fB;
356 if (TMath::Abs(aSignal)>2147483647.0) {
357 //PH 2147483647 is the max. integer
358 //PH This apparently is a problem which needs investigation
359 AliWarning(Form("Too big or too small energy %f",aSignal));
360 aSignal = TMath::Sign((Double_t)2147483647,aSignal);
362 return (Int_t ) aSignal;
366 //__________________________________________________________________
368 void AliEMCALSDigitizer::Print1(Option_t * option)
371 PrintSDigits(option);
374 //__________________________________________________________________
375 void AliEMCALSDigitizer::Print(Option_t *option) const
377 // Prints parameters of SDigitizer
378 printf("Print: \n------------------- %s ------------- option %s\n", GetName() , option) ;
379 printf(" fInit %i\n", int(fInit));
380 printf(" fFirstEvent %i\n", fFirstEvent);
381 printf(" fLastEvent %i\n", fLastEvent);
382 printf(" Writing SDigits to branch with title %s\n", fEventFolderName.Data()) ;
383 printf(" with digitization parameters A = %f\n", fA) ;
384 printf(" B = %f\n", fB) ;
385 printf(" Threshold for EC Primary assignment = %f\n", fECPrimThreshold) ;
386 printf(" Sampling = %f\n", fSampling);
387 printf("---------------------------------------------------\n") ;
390 //__________________________________________________________________
391 Bool_t AliEMCALSDigitizer::operator==( AliEMCALSDigitizer const &sd )const
394 // SDititizers are equal if their pedestal, slope and threshold are equal
395 if( (fA==sd.fA)&&(fB==sd.fB)&&
396 (fECPrimThreshold==sd.fECPrimThreshold))
402 //__________________________________________________________________
403 void AliEMCALSDigitizer::PrintSDigits(Option_t * option)
405 //Prints list of digits produced at the current pass of AliEMCALDigitizer
408 // AliEMCALGetter * gime = AliEMCALGetter::Instance() ;
409 AliEMCALLoader *rl = dynamic_cast<AliEMCALLoader*>(AliRunLoader::GetRunLoader()->GetDetectorLoader("EMCAL"));
410 const TClonesArray * sdigits = rl->SDigits() ;
413 printf("event %i", rl->GetRunLoader()->GetEventNumber());
414 printf(" Number of entries in SDigits list %i", sdigits->GetEntriesFast());
415 if(strstr(option,"all")||strstr(option,"EMC")){
418 AliEMCALDigit * digit;
419 printf("\n Id Amplitude Time Index Nprim: Primaries list \n") ;
421 char * tempo = new char[8192];
422 for (index = 0 ; index < sdigits->GetEntries() ; index++) {
423 digit = dynamic_cast<AliEMCALDigit *>( sdigits->At(index) ) ;
424 sprintf(tempo, "\n%6d %8d %6.5e %4d %2d :",
425 digit->GetId(), digit->GetAmp(), digit->GetTime(), digit->GetIndexInList(), digit->GetNprimary()) ;
427 isum += digit->GetAmp();
430 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
431 sprintf(tempo, "%d ",digit->GetPrimary(iprimary+1) ) ;
436 printf("\n** Sum %i : %10.3f GeV/c **\n ", isum, double(isum)*1.e-6);
440 //____________________________________________________________________________
441 void AliEMCALSDigitizer::Unload() const
443 // Unload Hits and SDigits from the folder
444 AliEMCALLoader *rl = dynamic_cast<AliEMCALLoader*>(AliRunLoader::GetRunLoader()->GetDetectorLoader("EMCAL"));
446 rl->UnloadSDigits() ;
449 void AliEMCALSDigitizer::Browse(TBrowser* b)
451 if(fHists) b->Add(fHists);
455 TList *AliEMCALSDigitizer::BookControlHists(int var)
457 //book histograms for monitoring sdigitization
460 const AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance() ;
462 AliDebug(1, " BookControlHists() in action ");
463 new TH1F("HSDigiN", "#EMCAL sdigits ", 1001, -0.5, 1000.5);
464 new TH1F("HSDigiSumEnergy","Sum.EMCAL energy", 1000, 0.0, 100.);
465 new TH1F("HSDigiAmp", "EMCAL sdigits amplitude", 1000, 0., 2.e+9);
466 new TH1F("HSDigiEnergy","EMCAL cell energy", 1000, 0.0, 100.);
467 new TH1F("HSDigiAbsId","EMCAL absID for sdigits",
468 geom->GetNCells(), 0.5, Double_t(geom->GetNCells())+0.5);
471 fHists = AliEMCALHistoUtilities::MoveHistsToList("EmcalSDigiControlHists", kFALSE);
477 void AliEMCALSDigitizer::SaveHists(const char* name, Bool_t kSingleKey, const char* opt)
479 AliEMCALHistoUtilities::SaveListOfHists(fHists, name, kSingleKey, opt);