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>
58 // --- Standard library ---
61 // --- AliRoot header files ---
63 #include "AliRunLoader.h"
65 #include "AliEMCALDigit.h"
66 #include "AliEMCALLoader.h"
67 #include "AliEMCALHit.h"
68 #include "AliEMCALSDigitizer.h"
69 #include "AliEMCALGeometry.h"
70 #include "AliEMCALHistoUtilities.h"
72 ClassImp(AliEMCALSDigitizer)
74 //____________________________________________________________________________
75 AliEMCALSDigitizer::AliEMCALSDigitizer()
77 fA(0.),fB(0.),fECPrimThreshold(0.),
92 //____________________________________________________________________________
93 AliEMCALSDigitizer::AliEMCALSDigitizer(const char * alirunFileName,
94 const char * eventFolderName)
95 : TTask("EMCAL"+AliConfig::Instance()->GetSDigitizerTaskName(), alirunFileName),
96 fA(0.),fB(0.),fECPrimThreshold(0.),
98 fEventFolderName(eventFolderName),
110 if(fControlHists) BookControlHists(1);
114 //____________________________________________________________________________
115 AliEMCALSDigitizer::AliEMCALSDigitizer(const AliEMCALSDigitizer & sd)
116 : TTask(sd.GetName(),sd.GetTitle()),
119 fECPrimThreshold(sd.fECPrimThreshold),
120 fDefaultInit(sd.fDefaultInit),
121 fEventFolderName(sd.fEventFolderName),
123 fSDigitsInRun(sd.fSDigitsInRun),
124 fFirstEvent(sd.fFirstEvent),
125 fLastEvent(sd.fLastEvent),
126 fSampling(sd.fSampling),
127 fControlHists(sd.fControlHists),
134 //____________________________________________________________________________
135 AliEMCALSDigitizer::~AliEMCALSDigitizer() {
137 AliLoader *emcalLoader=0;
138 if ((emcalLoader = AliRunLoader::GetRunLoader()->GetDetectorLoader("EMCAL")))
139 emcalLoader->CleanSDigitizer();
142 //____________________________________________________________________________
143 void AliEMCALSDigitizer::Init(){
144 // Initialization: open root-file, allocate arrays for hits and sdigits,
145 // attach task SDigitizer to the list of EMCAL tasks
147 // Initialization can not be done in the default constructor
148 //============================================================= YS
149 // The initialisation is now done by the getter
153 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(AliRunLoader::GetRunLoader()->GetDetectorLoader("EMCAL"));
155 if ( emcalLoader == 0 ) {
156 Fatal("Init", "Could not obtain the AliEMCALLoader");
160 emcalLoader->PostSDigitizer(this);
161 emcalLoader->GetSDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
165 //____________________________________________________________________________
166 void AliEMCALSDigitizer::InitParameters()
168 //initialize parameters for sdigitization
170 const AliEMCALGeometry * geom = AliEMCALGeometry::GetInstance();
171 if (geom->GetSampling() == 0.) {
172 Fatal("InitParameters", "Sampling factor not set !") ;
174 // Initializes parameters
177 fSampling = geom->GetSampling();
179 // threshold for deposit energy of hit
180 fECPrimThreshold = 0.; // 24-nov-04 - was 1.e-6;
184 //____________________________________________________________________________
185 void AliEMCALSDigitizer::Exec(Option_t *option)
187 // Collects all hit of the same tower into digits
188 TString o(option); o.ToUpper();
189 if (strstr(option, "print") ) {
194 if(strstr(option,"tim"))
195 gBenchmark->Start("EMCALSDigitizer");
197 AliRunLoader *rl = AliRunLoader::GetRunLoader();
198 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(rl->GetDetectorLoader("EMCAL"));
200 //switch off reloading of this task while getting event
201 if (!fInit) { // to prevent overwrite existing file
202 AliError( Form("Give a version name different from %s", fEventFolderName.Data()) ) ;
206 if (fLastEvent == -1)
207 fLastEvent = rl->GetNumberOfEvents() - 1 ;
209 fLastEvent = TMath::Min(fLastEvent, rl->GetNumberOfEvents()-1);
211 Int_t nEvents = fLastEvent - fFirstEvent + 1;
214 Float_t energy=0.; // de * fSampling - 23-nov-04
215 rl->LoadKinematics();
216 rl->LoadHits("EMCAL");
218 for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
219 rl->GetEvent(ievent);
220 TTree * treeS = emcalLoader->TreeS();
222 emcalLoader->MakeSDigitsContainer();
223 treeS = emcalLoader->TreeS();
225 TClonesArray * hits = emcalLoader->Hits() ;
226 TClonesArray * sdigits = emcalLoader->SDigits() ;
231 AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance();
232 for ( i = 0 ; i < hits->GetEntries() ; i++ ) {
233 AliEMCALHit * hit = dynamic_cast<AliEMCALHit*>(hits->At(i)) ;
234 AliEMCALDigit * curSDigit = 0 ;
235 AliEMCALDigit * sdigit = 0 ;
236 Bool_t newsdigit = kTRUE;
238 // hit->GetId() - Absolute Id number EMCAL segment
239 if(geom->CheckAbsCellId(hit->GetId())) { // was IsInECA(hit->GetId())
240 energy = hit->GetEnergy() * fSampling; // 23-nov-04
241 if(energy > fECPrimThreshold )
242 // Assign primary number only if deposited energy is significant
243 curSDigit = new AliEMCALDigit( hit->GetPrimary(),
244 hit->GetIparent(), hit->GetId(),
245 Digitize(energy), hit->GetTime() ) ;
247 curSDigit = new AliEMCALDigit( -1 ,
250 Digitize(energy), hit->GetTime() ) ;
252 Warning("Exec"," abs id %i is bad \n", hit->GetId());
258 for(Int_t check= 0; check < nSdigits ; check++) {
259 sdigit = dynamic_cast<AliEMCALDigit *>(sdigits->At(check)) ;
261 if( sdigit->GetId() == curSDigit->GetId()) { // Are we in the same ECAL tower ?
262 *sdigit = *sdigit + *curSDigit;
268 new((*sdigits)[nSdigits]) AliEMCALDigit(*curSDigit);
272 } // loop over all hits (hit = deposited energy/entering particle)
275 nSdigits = sdigits->GetEntriesFast() ;
276 fSDigitsInRun += nSdigits ;
278 Double_t e=0.,esum=0.;
279 AliEMCALHistoUtilities::FillH1(fHists, 0, double(sdigits->GetEntriesFast()));
280 for (i = 0 ; i < sdigits->GetEntriesFast() ; i++) {
281 AliEMCALDigit * sdigit = dynamic_cast<AliEMCALDigit *>(sdigits->At(i)) ;
282 sdigit->SetIndexInList(i) ;
284 AliEMCALHistoUtilities::FillH1(fHists, 2, double(sdigit->GetAmp()));
285 e = double(Calibrate(sdigit->GetAmp()));
287 AliEMCALHistoUtilities::FillH1(fHists, 3, e);
288 AliEMCALHistoUtilities::FillH1(fHists, 4, double(sdigit->GetId()));
290 if(esum>0.) AliEMCALHistoUtilities::FillH1(fHists, 1, esum);
294 Int_t bufferSize = 32000 ;
295 TBranch * sdigitsBranch = treeS->GetBranch("EMCAL");
297 sdigitsBranch->SetAddress(&sdigits);
299 treeS->Branch("EMCAL",&sdigits,bufferSize);
303 emcalLoader->WriteSDigits("OVERWRITE");
306 emcalLoader->WriteSDigitizer("OVERWRITE"); // why in event cycle ?
308 if(strstr(option,"deb"))
309 PrintSDigits(option) ;
314 emcalLoader->GetSDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
316 if(strstr(option,"tim")){
317 gBenchmark->Stop("EMCALSDigitizer");
318 printf("\n Exec: took %f seconds for SDigitizing %f seconds per event\n",
319 gBenchmark->GetCpuTime("EMCALSDigitizer"), gBenchmark->GetCpuTime("EMCALSDigitizer")/nEvents ) ;
323 //__________________________________________________________________
325 Int_t AliEMCALSDigitizer::Digitize(Float_t energy)const {
326 // Digitize the energy
327 Double_t aSignal = fA + energy*fB;
328 if (TMath::Abs(aSignal)>2147483647.0) {
329 //PH 2147483647 is the max. integer
330 //PH This apparently is a problem which needs investigation
331 AliWarning(Form("Too big or too small energy %f",aSignal));
332 aSignal = TMath::Sign((Double_t)2147483647,aSignal);
334 return (Int_t ) aSignal;
338 //__________________________________________________________________
340 void AliEMCALSDigitizer::Print1(Option_t * option)
343 PrintSDigits(option);
346 //__________________________________________________________________
347 void AliEMCALSDigitizer::Print(Option_t *option) const
349 // Prints parameters of SDigitizer
350 printf("Print: \n------------------- %s ------------- option %s\n", GetName() , option) ;
351 printf(" fInit %i\n", int(fInit));
352 printf(" fFirstEvent %i\n", fFirstEvent);
353 printf(" fLastEvent %i\n", fLastEvent);
354 printf(" Writing SDigits to branch with title %s\n", fEventFolderName.Data()) ;
355 printf(" with digitization parameters A = %f\n", fA) ;
356 printf(" B = %f\n", fB) ;
357 printf(" Threshold for EC Primary assignment = %f\n", fECPrimThreshold) ;
358 printf(" Sampling = %f\n", fSampling);
359 printf("---------------------------------------------------\n") ;
362 //__________________________________________________________________
363 Bool_t AliEMCALSDigitizer::operator==( AliEMCALSDigitizer const &sd )const
366 // SDititizers are equal if their pedestal, slope and threshold are equal
367 if( (fA==sd.fA)&&(fB==sd.fB)&&
368 (fECPrimThreshold==sd.fECPrimThreshold))
374 //__________________________________________________________________
375 void AliEMCALSDigitizer::PrintSDigits(Option_t * option)
377 //Prints list of digits produced at the current pass of AliEMCALDigitizer
380 // AliEMCALGetter * gime = AliEMCALGetter::Instance() ;
381 AliEMCALLoader *rl = dynamic_cast<AliEMCALLoader*>(AliRunLoader::GetRunLoader()->GetDetectorLoader("EMCAL"));
382 const TClonesArray * sdigits = rl->SDigits() ;
385 printf("event %i", rl->GetRunLoader()->GetEventNumber());
386 printf(" Number of entries in SDigits list %i", sdigits->GetEntriesFast());
387 if(strstr(option,"all")||strstr(option,"EMC")){
390 AliEMCALDigit * digit;
391 printf("\n Id Amplitude Time Index Nprim: Primaries list \n") ;
393 char * tempo = new char[8192];
394 for (index = 0 ; index < sdigits->GetEntries() ; index++) {
395 digit = dynamic_cast<AliEMCALDigit *>( sdigits->At(index) ) ;
396 sprintf(tempo, "\n%6d %8d %6.5e %4d %2d :",
397 digit->GetId(), digit->GetAmp(), digit->GetTime(), digit->GetIndexInList(), digit->GetNprimary()) ;
399 isum += digit->GetAmp();
402 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
403 sprintf(tempo, "%d ",digit->GetPrimary(iprimary+1) ) ;
408 printf("\n** Sum %i : %10.3f GeV/c **\n ", isum, double(isum)*1.e-6);
412 //____________________________________________________________________________
413 void AliEMCALSDigitizer::Unload() const
415 // Unload Hits and SDigits from the folder
416 AliEMCALLoader *rl = dynamic_cast<AliEMCALLoader*>(AliRunLoader::GetRunLoader()->GetDetectorLoader("EMCAL"));
418 rl->UnloadSDigits() ;
421 void AliEMCALSDigitizer::Browse(TBrowser* b)
423 if(fHists) b->Add(fHists);
427 TList *AliEMCALSDigitizer::BookControlHists(int var)
429 //book histograms for monitoring sdigitization
432 const AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance() ;
434 printf(" AliEMCALSDigitizer::BookControlHists() in action \n");
435 new TH1F("HSDigiN", "#EMCAL sdigits ", 1001, -0.5, 1000.5);
436 new TH1F("HSDigiSumEnergy","Sum.EMCAL energy", 1000, 0.0, 100.);
437 new TH1F("HSDigiAmp", "EMCAL sdigits amplitude", 1000, 0., 2.e+9);
438 new TH1F("HSDigiEnergy","EMCAL cell energy", 1000, 0.0, 100.);
439 new TH1F("HSDigiAbsId","EMCAL absID for sdigits",
440 geom->GetNCells(), 0.5, Double_t(geom->GetNCells())+0.5);
443 fHists = AliEMCALHistoUtilities::MoveHistsToList("EmcalSDigiControlHists", kFALSE);
449 void AliEMCALSDigitizer::SaveHists(const char* name, Bool_t kSingleKey, const char* opt)
451 AliEMCALHistoUtilities::SaveListOfHists(fHists, name, kSingleKey, opt);