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"
54 // --- Standard library ---
57 // --- AliRoot header files ---
58 #include "AliEMCALDigit.h"
59 #include "AliEMCALGetter.h"
60 #include "AliEMCALHit.h"
61 #include "AliEMCALSDigitizer.h"
62 #include "AliEMCALGeometry.h"
64 ClassImp(AliEMCALSDigitizer)
66 //____________________________________________________________________________
67 AliEMCALSDigitizer::AliEMCALSDigitizer():TTask("","")
71 fDefaultInit = kTRUE ;
74 //____________________________________________________________________________
75 AliEMCALSDigitizer::AliEMCALSDigitizer(const char * alirunFileName, const char * eventFolderName):
76 TTask("EMCAL"+AliConfig::fgkSDigitizerTaskName, alirunFileName),
77 fEventFolderName(eventFolderName)
82 fDefaultInit = kFALSE ;
86 //____________________________________________________________________________
87 AliEMCALSDigitizer::AliEMCALSDigitizer(const AliEMCALSDigitizer & sd) : TTask(sd) {
92 fPREPrimThreshold = sd.fPREPrimThreshold ;
93 fECPrimThreshold = sd.fECPrimThreshold ;
94 fHCPrimThreshold = sd.fHCPrimThreshold ;
95 fSDigitsInRun = sd.fSDigitsInRun ;
96 SetName(sd.GetName()) ;
97 SetTitle(sd.GetTitle()) ;
98 fEventFolderName = sd.fEventFolderName;
102 //____________________________________________________________________________
103 void AliEMCALSDigitizer::Init(){
104 // Initialization: open root-file, allocate arrays for hits and sdigits,
105 // attach task SDigitizer to the list of EMCAL tasks
107 // Initialization can not be done in the default constructor
108 //============================================================= YS
109 // The initialisation is now done by the getter
113 AliEMCALGetter * gime = AliEMCALGetter::Instance(GetTitle(), fEventFolderName.Data());
115 Fatal("Init", "Could not obtain the Getter objectfor file %s and event %s !", GetTitle(), fEventFolderName.Data()) ;
119 TString opt("SDigits") ;
120 if(gime->VersionExists(opt) ) {
121 Error( "Init", "Give a version name different from %s", fEventFolderName.Data() ) ;
125 gime->PostSDigitizer(this);
126 gime->EmcalLoader()->GetSDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
130 //____________________________________________________________________________
131 void AliEMCALSDigitizer::InitParameters()
133 // Initializes parameters
137 AliEMCALGetter * gime = AliEMCALGetter::Instance() ;
138 const AliEMCALGeometry * geom = gime->EMCALGeometry() ;
139 if (geom->GetSampling() == 0.) {
140 Error("InitParameters", "Sampling factor not set !") ;
144 Info("InitParameters", "Sampling factor set to %f\n", geom->GetSampling()) ;
146 // this threshold corresponds approximately to 100 MeV
147 fECPrimThreshold = 100E-3 / ( geom->GetSampling() * ( geom->GetNPRLayers() + geom->GetNECLayers()) ) * geom->GetNECLayers() ;
148 fPREPrimThreshold = 100E-3 / ( geom->GetSampling() * ( geom->GetNPRLayers() + geom->GetNECLayers()) ) * geom->GetNPRLayers() ;
149 fHCPrimThreshold = fECPrimThreshold/5. ; // 5 is totally arbitrary
153 //____________________________________________________________________________
154 void AliEMCALSDigitizer::Exec(Option_t *option)
156 // Collects all hits in the section (PRE/ECAL/HCAL) of the same tower into digit
158 if (strstr(option, "print") ) {
163 if(strstr(option,"tim"))
164 gBenchmark->Start("EMCALSDigitizer");
166 AliEMCALGetter * gime = AliEMCALGetter::Instance() ;
168 //switch off reloading of this task while getting event
169 if (!fInit) { // to prevent overwrite existing file
170 Error( "Exec", "Give a version name different from %s", fEventFolderName.Data() ) ;
174 Int_t nevents = gime->MaxEvent() ;
176 for(ievent = 0; ievent < nevents; ievent++){
178 gime->Event(ievent,"H") ;
180 TTree * treeS = gime->TreeS();
181 TClonesArray * hits = gime->Hits() ;
182 TClonesArray * sdigits = gime->SDigits() ;
185 //Now make SDigits from hits, for EMCAL it is the same, so just copy
186 Int_t nPrim = static_cast<Int_t>((gime->TreeH())->GetEntries()) ;
187 // Attention nPrim is the number of primaries tracked by Geant
188 // and this number could be different to the number of Primaries in TreeK;
191 for ( iprim = 0 ; iprim < nPrim ; iprim++ ) {
192 //=========== Get the EMCAL branch from Hits Tree for the Primary iprim
195 for ( i = 0 ; i < hits->GetEntries() ; i++ ) {
196 AliEMCALHit * hit = dynamic_cast<AliEMCALHit*>(hits->At(i)) ;
197 AliEMCALDigit * curSDigit = 0 ;
198 AliEMCALDigit * sdigit = 0 ;
199 Bool_t newsdigit = kTRUE;
201 // Assign primary number only if deposited energy is significant
203 AliEMCALGeometry * geom = gime->EMCALGeometry() ;
205 if( geom->IsInPRE(hit->GetId()) )
206 if( hit->GetEnergy() > fPREPrimThreshold )
207 curSDigit = new AliEMCALDigit( hit->GetPrimary(),
208 hit->GetIparent(), hit->GetId(),
209 Digitize(hit->GetEnergy()), hit->GetTime() ) ;
211 curSDigit = new AliEMCALDigit( -1 ,
214 Digitize(hit->GetEnergy()), hit->GetTime() ) ;
215 else if( geom->IsInECA(hit->GetId()) )
216 if( hit->GetEnergy() > fECPrimThreshold )
217 curSDigit = new AliEMCALDigit( hit->GetPrimary(),
218 hit->GetIparent(), hit->GetId(),
219 Digitize(hit->GetEnergy()), hit->GetTime() ) ;
221 curSDigit = new AliEMCALDigit( -1 ,
224 Digitize(hit->GetEnergy()), hit->GetTime() ) ;
225 else if( geom->IsInHCA(hit->GetId()) )
226 if( hit->GetEnergy() > fHCPrimThreshold )
228 curSDigit = new AliEMCALDigit( hit->GetPrimary(),
229 hit->GetIparent(), hit->GetId(),
230 Digitize(hit->GetEnergy()), hit->GetTime() ) ;
232 curSDigit = new AliEMCALDigit( -1 ,
235 Digitize(hit->GetEnergy()), hit->GetTime() ) ;
238 for(check= 0; check < nSdigits ; check++) {
239 sdigit = dynamic_cast<AliEMCALDigit *>(sdigits->At(check)) ;
240 if( sdigit->GetId() == curSDigit->GetId()) { // Are we in the same ECAL/HCAL/preshower tower ?
241 *sdigit = *sdigit + *curSDigit;
246 new((*sdigits)[nSdigits]) AliEMCALDigit(*curSDigit);
250 } // loop over all hits (hit = deposited energy/layer/entering particle)
255 nSdigits = sdigits->GetEntriesFast() ;
256 fSDigitsInRun += nSdigits ;
257 sdigits->Expand(nSdigits) ;
259 Int_t nPrimarymax = -1 ;
261 for (i = 0 ; i < sdigits->GetEntriesFast() ; i++) {
262 AliEMCALDigit * sdigit = dynamic_cast<AliEMCALDigit *>(sdigits->At(i)) ;
263 sdigit->SetIndexInList(i) ;
266 for (i = 0 ; i < sdigits->GetEntriesFast() ; i++) {
267 if (((dynamic_cast<AliEMCALDigit *>(sdigits->At(i)))->GetNprimary()) > nPrimarymax)
268 nPrimarymax = ((dynamic_cast<AliEMCALDigit *>(sdigits->At(i)))->GetNprimary()) ;
273 //First list of sdigits
275 Int_t bufferSize = 32000 ;
276 TBranch * sdigitsBranch = treeS->Branch("EMCAL",&sdigits,bufferSize);
278 sdigitsBranch->Fill() ;
280 gime->WriteSDigits("OVERWRITE");
284 gime->WriteSDigitizer("OVERWRITE");
286 if(strstr(option,"deb"))
287 PrintSDigits(option) ;
292 gime->EmcalLoader()->GetSDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
294 if(strstr(option,"tim")){
295 gBenchmark->Stop("EMCALSDigitizer");
296 Info("Exec", "took %f seconds for SDigitizing %f seconds per event",
297 gBenchmark->GetCpuTime("EMCALSDigitizer"), gBenchmark->GetCpuTime("EMCALSDigitizer") ) ;
302 //__________________________________________________________________
303 void AliEMCALSDigitizer::Print()const
305 // Prints parameters of SDigitizer
306 Info("Print", "\n------------------- %s -------------", GetName() ) ;
307 printf(" Writing SDigits to branch with title %s\n", fEventFolderName.Data()) ;
308 printf(" with digitization parameters A = %f\n", fA) ;
309 printf(" B = %f\n", fB) ;
310 printf(" Threshold for PRE Primary assignment= %f\n", fPREPrimThreshold) ;
311 printf(" Threshold for EC Primary assignment= %f\n", fECPrimThreshold) ;
312 printf(" Threshold for HC Primary assignment= %f\n", fHCPrimThreshold) ;
313 printf("---------------------------------------------------\n") ;
317 //__________________________________________________________________
318 Bool_t AliEMCALSDigitizer::operator==( AliEMCALSDigitizer const &sd )const
321 // SDititizers are equal if their pedestal, slope and threshold are equal
323 if( (fA==sd.fA)&&(fB==sd.fB)&&
324 (fECPrimThreshold==sd.fECPrimThreshold) &&
325 (fHCPrimThreshold==sd.fHCPrimThreshold) &&
326 (fPREPrimThreshold==sd.fPREPrimThreshold))
332 //__________________________________________________________________
333 void AliEMCALSDigitizer::PrintSDigits(Option_t * option)
335 //Prints list of digits produced at the current pass of AliEMCALDigitizer
338 AliEMCALGetter * gime = AliEMCALGetter::Instance() ;
339 const TClonesArray * sdigits = gime->SDigits() ;
341 TString message("\n") ;
342 message += "event " ;
343 message += gAlice->GetEvNumber() ;
344 message += "\n Number of entries in SDigits list " ;
345 message += sdigits->GetEntriesFast() ;
346 if(strstr(option,"all")||strstr(option,"EMC")){
349 AliEMCALDigit * digit;
350 message += "\n Id Amplitude Time Index Nprim: Primaries list \n" ;
352 char * tempo = new char[8192];
353 for (index = 0 ; index < sdigits->GetEntries() ; index++) {
354 digit = dynamic_cast<AliEMCALDigit *>( sdigits->At(index) ) ;
355 sprintf(tempo, "\n%6d %8d %6.5e %4d %2d :",
356 digit->GetId(), digit->GetAmp(), digit->GetTime(), digit->GetIndexInList(), digit->GetNprimary()) ;
360 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
361 sprintf(tempo, "%d ",digit->GetPrimary(iprimary+1) ) ;
367 Info("PrintSDigits", message.Data() ) ;
370 //____________________________________________________________________________
371 void AliEMCALSDigitizer::Unload() const
373 // Unload Hits and SDigits from the folder
374 AliEMCALGetter * gime = AliEMCALGetter::Instance() ;
375 AliEMCALLoader * loader = gime->EmcalLoader() ;
376 loader->UnloadHits() ;
377 loader->UnloadSDigits() ;