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;
182 AliDebug(2,Form("Print: \n------------------- %s -------------\n",GetName()));
183 AliDebug(2,Form(" fInit %i\n", int(fInit)));
184 AliDebug(2,Form(" fFirstEvent %i\n", fFirstEvent));
185 AliDebug(2,Form(" fLastEvent %i\n", fLastEvent));
186 AliDebug(2,Form(" Writing SDigits to branch with title %s\n", fEventFolderName.Data()));
187 AliDebug(2,Form(" with digitization parameters A = %f\n", fA));
188 AliDebug(2,Form(" B = %f\n", fB));
189 AliDebug(2,Form(" Threshold for EC Primary assignment = %f\n", fECPrimThreshold));
190 AliDebug(2,Form(" Sampling = %f\n", fSampling));
191 AliDebug(2,Form("---------------------------------------------------\n"));
197 //____________________________________________________________________________
198 void AliEMCALSDigitizer::Exec(Option_t *option)
200 // Collects all hit of the same tower into digits
201 TString o(option); o.ToUpper();
202 if (strstr(option, "print") ) {
204 AliDebug(2,Form("Print: \n------------------- %s -------------\n",GetName()));
205 AliDebug(2,Form(" fInit %i\n", int(fInit)));
206 AliDebug(2,Form(" fFirstEvent %i\n", fFirstEvent));
207 AliDebug(2,Form(" fLastEvent %i\n", fLastEvent));
208 AliDebug(2,Form(" Writing SDigits to branch with title %s\n", fEventFolderName.Data()));
209 AliDebug(2,Form(" with digitization parameters A = %f\n", fA));
210 AliDebug(2,Form(" B = %f\n", fB));
211 AliDebug(2,Form(" Threshold for EC Primary assignment = %f\n", fECPrimThreshold));
212 AliDebug(2,Form(" Sampling = %f\n", fSampling));
213 AliDebug(2,Form("---------------------------------------------------\n"));
219 if(strstr(option,"tim"))
220 gBenchmark->Start("EMCALSDigitizer");
222 AliRunLoader *rl = AliRunLoader::GetRunLoader();
223 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(rl->GetDetectorLoader("EMCAL"));
225 //switch off reloading of this task while getting event
226 if (!fInit) { // to prevent overwrite existing file
227 AliError( Form("Give a version name different from %s", fEventFolderName.Data()) ) ;
231 if (fLastEvent == -1)
232 fLastEvent = rl->GetNumberOfEvents() - 1 ;
234 fLastEvent = TMath::Min(fLastEvent, rl->GetNumberOfEvents()-1);
236 Int_t nEvents = fLastEvent - fFirstEvent + 1;
239 Float_t energy=0.; // de * fSampling - 23-nov-04
240 rl->LoadKinematics();
241 rl->LoadHits("EMCAL");
243 for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
244 rl->GetEvent(ievent);
245 TTree * treeS = emcalLoader->TreeS();
247 emcalLoader->MakeSDigitsContainer();
248 treeS = emcalLoader->TreeS();
250 TClonesArray * hits = emcalLoader->Hits() ;
251 TClonesArray * sdigits = emcalLoader->SDigits() ;
256 AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance();
257 for ( i = 0 ; i < hits->GetEntries() ; i++ ) {
258 AliEMCALHit * hit = dynamic_cast<AliEMCALHit*>(hits->At(i)) ;
259 AliEMCALDigit * curSDigit = 0 ;
260 AliEMCALDigit * sdigit = 0 ;
261 Bool_t newsdigit = kTRUE;
263 // hit->GetId() - Absolute Id number EMCAL segment
264 if(geom->CheckAbsCellId(hit->GetId())) { // was IsInECA(hit->GetId())
265 energy = hit->GetEnergy() * fSampling; // 23-nov-04
266 if(energy > fECPrimThreshold )
267 // Assign primary number only if deposited energy is significant
268 curSDigit = new AliEMCALDigit( hit->GetPrimary(),
269 hit->GetIparent(), hit->GetId(),
270 Digitize(energy), hit->GetTime() ) ;
272 curSDigit = new AliEMCALDigit( -1 ,
275 Digitize(energy), hit->GetTime() ) ;
277 Warning("Exec"," abs id %i is bad \n", hit->GetId());
283 for(Int_t check= 0; check < nSdigits ; check++) {
284 sdigit = dynamic_cast<AliEMCALDigit *>(sdigits->At(check)) ;
286 if( sdigit->GetId() == curSDigit->GetId()) { // Are we in the same ECAL tower ?
287 *sdigit = *sdigit + *curSDigit;
293 new((*sdigits)[nSdigits]) AliEMCALDigit(*curSDigit);
297 } // loop over all hits (hit = deposited energy/entering particle)
300 nSdigits = sdigits->GetEntriesFast() ;
301 fSDigitsInRun += nSdigits ;
303 Double_t e=0.,esum=0.;
304 AliEMCALHistoUtilities::FillH1(fHists, 0, double(sdigits->GetEntriesFast()));
305 for (i = 0 ; i < sdigits->GetEntriesFast() ; i++) {
306 AliEMCALDigit * sdigit = dynamic_cast<AliEMCALDigit *>(sdigits->At(i)) ;
307 sdigit->SetIndexInList(i) ;
309 AliEMCALHistoUtilities::FillH1(fHists, 2, double(sdigit->GetAmp()));
310 e = double(Calibrate(sdigit->GetAmp()));
312 AliEMCALHistoUtilities::FillH1(fHists, 3, e);
313 AliEMCALHistoUtilities::FillH1(fHists, 4, double(sdigit->GetId()));
315 if(esum>0.) AliEMCALHistoUtilities::FillH1(fHists, 1, esum);
319 Int_t bufferSize = 32000 ;
320 TBranch * sdigitsBranch = treeS->GetBranch("EMCAL");
322 sdigitsBranch->SetAddress(&sdigits);
324 treeS->Branch("EMCAL",&sdigits,bufferSize);
328 emcalLoader->WriteSDigits("OVERWRITE");
331 emcalLoader->WriteSDigitizer("OVERWRITE"); // why in event cycle ?
333 if(strstr(option,"deb"))
334 PrintSDigits(option) ;
339 emcalLoader->GetSDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
341 if(strstr(option,"tim")){
342 gBenchmark->Stop("EMCALSDigitizer");
343 printf("\n Exec: took %f seconds for SDigitizing %f seconds per event\n",
344 gBenchmark->GetCpuTime("EMCALSDigitizer"), gBenchmark->GetCpuTime("EMCALSDigitizer")/nEvents ) ;
348 //__________________________________________________________________
350 Int_t AliEMCALSDigitizer::Digitize(Float_t energy)const {
351 // Digitize the energy
352 Double_t aSignal = fA + energy*fB;
353 if (TMath::Abs(aSignal)>2147483647.0) {
354 //PH 2147483647 is the max. integer
355 //PH This apparently is a problem which needs investigation
356 AliWarning(Form("Too big or too small energy %f",aSignal));
357 aSignal = TMath::Sign((Double_t)2147483647,aSignal);
359 return (Int_t ) aSignal;
363 //__________________________________________________________________
365 void AliEMCALSDigitizer::Print1(Option_t * option)
368 PrintSDigits(option);
371 //__________________________________________________________________
372 void AliEMCALSDigitizer::Print(Option_t *option) const
374 // Prints parameters of SDigitizer
375 printf("Print: \n------------------- %s ------------- option %s\n", GetName() , option) ;
376 printf(" fInit %i\n", int(fInit));
377 printf(" fFirstEvent %i\n", fFirstEvent);
378 printf(" fLastEvent %i\n", fLastEvent);
379 printf(" Writing SDigits to branch with title %s\n", fEventFolderName.Data()) ;
380 printf(" with digitization parameters A = %f\n", fA) ;
381 printf(" B = %f\n", fB) ;
382 printf(" Threshold for EC Primary assignment = %f\n", fECPrimThreshold) ;
383 printf(" Sampling = %f\n", fSampling);
384 printf("---------------------------------------------------\n") ;
387 //__________________________________________________________________
388 Bool_t AliEMCALSDigitizer::operator==( AliEMCALSDigitizer const &sd )const
391 // SDititizers are equal if their pedestal, slope and threshold are equal
392 if( (fA==sd.fA)&&(fB==sd.fB)&&
393 (fECPrimThreshold==sd.fECPrimThreshold))
399 //__________________________________________________________________
400 void AliEMCALSDigitizer::PrintSDigits(Option_t * option)
402 //Prints list of digits produced at the current pass of AliEMCALDigitizer
405 // AliEMCALGetter * gime = AliEMCALGetter::Instance() ;
406 AliEMCALLoader *rl = dynamic_cast<AliEMCALLoader*>(AliRunLoader::GetRunLoader()->GetDetectorLoader("EMCAL"));
407 const TClonesArray * sdigits = rl->SDigits() ;
410 printf("event %i", rl->GetRunLoader()->GetEventNumber());
411 printf(" Number of entries in SDigits list %i", sdigits->GetEntriesFast());
412 if(strstr(option,"all")||strstr(option,"EMC")){
415 AliEMCALDigit * digit;
416 printf("\n Id Amplitude Time Index Nprim: Primaries list \n") ;
418 char * tempo = new char[8192];
419 for (index = 0 ; index < sdigits->GetEntries() ; index++) {
420 digit = dynamic_cast<AliEMCALDigit *>( sdigits->At(index) ) ;
421 sprintf(tempo, "\n%6d %8d %6.5e %4d %2d :",
422 digit->GetId(), digit->GetAmp(), digit->GetTime(), digit->GetIndexInList(), digit->GetNprimary()) ;
424 isum += digit->GetAmp();
427 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
428 sprintf(tempo, "%d ",digit->GetPrimary(iprimary+1) ) ;
433 printf("\n** Sum %i : %10.3f GeV/c **\n ", isum, double(isum)*1.e-6);
437 //____________________________________________________________________________
438 void AliEMCALSDigitizer::Unload() const
440 // Unload Hits and SDigits from the folder
441 AliEMCALLoader *rl = dynamic_cast<AliEMCALLoader*>(AliRunLoader::GetRunLoader()->GetDetectorLoader("EMCAL"));
443 rl->UnloadSDigits() ;
446 void AliEMCALSDigitizer::Browse(TBrowser* b)
448 if(fHists) b->Add(fHists);
452 TList *AliEMCALSDigitizer::BookControlHists(int var)
454 //book histograms for monitoring sdigitization
457 const AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance() ;
459 printf(" AliEMCALSDigitizer::BookControlHists() in action \n");
460 new TH1F("HSDigiN", "#EMCAL sdigits ", 1001, -0.5, 1000.5);
461 new TH1F("HSDigiSumEnergy","Sum.EMCAL energy", 1000, 0.0, 100.);
462 new TH1F("HSDigiAmp", "EMCAL sdigits amplitude", 1000, 0., 2.e+9);
463 new TH1F("HSDigiEnergy","EMCAL cell energy", 1000, 0.0, 100.);
464 new TH1F("HSDigiAbsId","EMCAL absID for sdigits",
465 geom->GetNCells(), 0.5, Double_t(geom->GetNCells())+0.5);
468 fHists = AliEMCALHistoUtilities::MoveHistsToList("EmcalSDigiControlHists", kFALSE);
474 void AliEMCALSDigitizer::SaveHists(const char* name, Bool_t kSingleKey, const char* opt)
476 AliEMCALHistoUtilities::SaveListOfHists(fHists, name, kSingleKey, opt);