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 ---
58 #include "TBenchmark.h"
59 #include "TGeometry.h"
61 // --- Standard library ---
63 // --- AliRoot header files ---
65 #include "AliHeader.h"
66 #include "AliEMCALDigit.h"
67 #include "AliEMCALGeometry.h"
68 #include "AliEMCALGetter.h"
69 #include "AliEMCALHit.h"
70 #include "AliEMCALSDigitizer.h"
72 ClassImp(AliEMCALSDigitizer)
74 //____________________________________________________________________________
75 AliEMCALSDigitizer::AliEMCALSDigitizer():TTask("AliEMCALSDigitizer","")
81 fDefaultInit = kTRUE ;
84 //____________________________________________________________________________
85 AliEMCALSDigitizer::AliEMCALSDigitizer(const char* headerFile, const char *sDigitsTitle, const Bool_t toSplit):
86 TTask(sDigitsTitle, headerFile)
92 fDefaultInit = kFALSE ;
95 //____________________________________________________________________________
96 AliEMCALSDigitizer::~AliEMCALSDigitizer()
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
111 if( strcmp(GetTitle(), "") == 0 )
112 SetTitle("galice.root") ;
114 AliEMCALGetter * gime = AliEMCALGetter::GetInstance(GetTitle(), GetName(), fToSplit) ;
116 Error("Init", "Could not obtain the Getter object !" ) ;
120 gime->PostSDigits( GetName(), GetTitle() ) ;
125 // construct the name of the file as /path/EMCAL.SDigits.root
126 // First - extract full path if necessary
127 TString sDigitsFileName(GetTitle()) ;
128 Ssiz_t islash = sDigitsFileName.Last('/') ;
129 if(islash<sDigitsFileName.Length())
130 sDigitsFileName.Remove(islash+1,sDigitsFileName.Length()) ;
134 // Next - append the file name
135 sDigitsFileName+="EMCAL.SDigits." ;
136 if((strcmp(GetName(),"Default")!=0)&&(strcmp(GetName(),"")!=0)){
137 sDigitsFileName+=GetName() ;
138 sDigitsFileName+="." ;
140 sDigitsFileName+="root" ;
142 // Finally - check if the file already opened or open the file
143 fSplitFile = static_cast<TFile*>(gROOT->GetFile(sDigitsFileName.Data()));
145 fSplitFile = TFile::Open(sDigitsFileName.Data(),"update") ;
148 TString sdname(GetName() );
150 sdname.Append(GetTitle() ) ;
152 gime->PostSDigitizer(this) ;
156 //____________________________________________________________________________
157 void AliEMCALSDigitizer::InitParameters()
162 AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
163 const AliEMCALGeometry * geom = gime->EMCALGeometry() ;
164 if (geom->GetSampling() == 0.) {
165 Error("InitParameters", "Sampling factor not set !") ;
169 Info("InitParameters", "Sampling factor set to %f\n", geom->GetSampling()) ;
171 // this threshold corresponds approximately to 100 MeV
172 fECPrimThreshold = 100E-3 / ( geom->GetSampling() * ( geom->GetNPRLayers() + geom->GetNECLayers()) ) * geom->GetNECLayers() ;
173 fPREPrimThreshold = 100E-3 / ( geom->GetSampling() * ( geom->GetNPRLayers() + geom->GetNECLayers()) ) * geom->GetNPRLayers() ;
174 fHCPrimThreshold = fECPrimThreshold/5. ; // 5 is totally arbitrary
178 //____________________________________________________________________________
179 void AliEMCALSDigitizer::Exec(Option_t *option)
181 // Collects all hits in the section (PRE/ECAL/HCAL) of the same tower into digit
183 if( strcmp(GetName(), "") == 0 )
186 if (strstr(option, "print") ) {
191 if(strstr(option,"tim"))
192 gBenchmark->Start("EMCALSDigitizer");
194 //Check, if this branch already exits
195 AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
196 if(gime->BranchExists("SDigits") )
199 TString sdname(GetName()) ;
200 sdname.Remove(sdname.Index(GetTitle())-1) ;
202 Int_t nevents = gime->MaxEvent() ;
204 for(ievent = 0; ievent < nevents; ievent++){
205 gime->Event(ievent,"H") ;
206 const TClonesArray * hits = gime->Hits() ;
207 TClonesArray * sdigits = gime->SDigits(sdname.Data()) ;
211 //Now make SDigits from hits, for EMCAL it is the same, so just copy
212 Int_t nPrim = static_cast<Int_t>((gAlice->TreeH())->GetEntries()) ;
213 // Attention nPrim is the number of primaries tracked by Geant
214 // and this number could be different to the number of Primaries in TreeK;
216 for ( iprim = 0 ; iprim < nPrim ; iprim++ ) {
217 //=========== Get the EMCAL branch from Hits Tree for the Primary iprim
220 for ( i = 0 ; i < hits->GetEntries() ; i++ ) {
221 AliEMCALHit * hit = dynamic_cast<AliEMCALHit*>(hits->At(i)) ;
222 AliEMCALDigit * curSDigit = 0 ;
223 AliEMCALDigit * sdigit = 0 ;
224 Bool_t newsdigit = kTRUE;
226 // Assign primary number only if deposited energy is significant
228 const AliEMCALGeometry * geom = gime->EMCALGeometry() ;
231 Info("Exec", "id = %d energy = %f thresholdPRE = %f thresholdEC = %f thresholdHC = %f \n",
232 hit->GetId(), hit->GetEnergy(), fPREPrimThreshold, fECPrimThreshold, fHCPrimThreshold) ;
233 Info("Exec", "where PRE/ECAL/HCAL %d, %d, %d", geom->IsInPRE(hit->GetId()), geom->IsInECAL(hit->GetId()), geom->IsInHCAL(hit->GetId()) ) ;
235 if( geom->IsInPRE(hit->GetId()) )
236 if( hit->GetEnergy() > fPREPrimThreshold )
237 curSDigit = new AliEMCALDigit( hit->GetPrimary(),
238 hit->GetIparent(), hit->GetId(),
239 Digitize(hit->GetEnergy()), hit->GetTime() ) ;
241 curSDigit = new AliEMCALDigit( -1 ,
244 Digitize(hit->GetEnergy()), hit->GetTime() ) ;
245 else if( geom->IsInECAL(hit->GetId()) )
246 if( hit->GetEnergy() > fECPrimThreshold )
247 curSDigit = new AliEMCALDigit( hit->GetPrimary(),
248 hit->GetIparent(), hit->GetId(),
249 Digitize(hit->GetEnergy()), hit->GetTime() ) ;
251 curSDigit = new AliEMCALDigit( -1 ,
254 Digitize(hit->GetEnergy()), hit->GetTime() ) ;
255 else if( geom->IsInHCAL(hit->GetId()) )
256 if( hit->GetEnergy() > fHCPrimThreshold )
258 curSDigit = new AliEMCALDigit( hit->GetPrimary(),
259 hit->GetIparent(), hit->GetId(),
260 Digitize(hit->GetEnergy()), hit->GetTime() ) ;
262 curSDigit = new AliEMCALDigit( -1 ,
265 Digitize(hit->GetEnergy()), hit->GetTime() ) ;
268 for(check= 0; check < nSdigits ; check++) {
269 sdigit = dynamic_cast<AliEMCALDigit *>(sdigits->At(check)) ;
270 if( sdigit->GetId() == curSDigit->GetId()) { // Are we in the same ECAL/HCAL/preshower tower ?
271 *sdigit = *sdigit + *curSDigit;
276 new((*sdigits)[nSdigits]) AliEMCALDigit(*curSDigit);
280 } // loop over all hits (hit = deposited energy/layer/entering particle)
285 nSdigits = sdigits->GetEntriesFast() ;
286 fSDigitsInRun += nSdigits ;
287 sdigits->Expand(nSdigits) ;
289 Int_t NPrimarymax = -1 ;
291 for (i = 0 ; i < sdigits->GetEntriesFast() ; i++) {
292 AliEMCALDigit * sdigit = dynamic_cast<AliEMCALDigit *>(sdigits->At(i)) ;
293 sdigit->SetIndexInList(i) ;
296 for (i = 0 ; i < sdigits->GetEntriesFast() ; i++) {
297 if (((dynamic_cast<AliEMCALDigit *>(sdigits->At(i)))->GetNprimary()) > NPrimarymax)
298 NPrimarymax = ((dynamic_cast<AliEMCALDigit *>(sdigits->At(i)))->GetNprimary()) ;
303 if(gAlice->TreeS() == 0 || (fSplitFile)) //<--- To be checked: we should not create TreeS if it is already here
304 gAlice->MakeTree("S",fSplitFile);
309 //First list of sdigits
310 Int_t bufferSize = 32000 ;
311 TBranch * sdigitsBranch = gAlice->TreeS()->Branch("EMCAL",&sdigits,bufferSize);
312 sdigitsBranch->SetTitle(sdname);
315 Int_t splitlevel = 0 ;
316 AliEMCALSDigitizer * sd = this ;
317 TBranch * sdigitizerBranch = gAlice->TreeS()->Branch("AliEMCALSDigitizer","AliEMCALSDigitizer",
318 &sd,bufferSize,splitlevel);
319 sdigitizerBranch->SetTitle(sdname);
321 sdigitsBranch->Fill() ;
322 sdigitizerBranch->Fill() ;
324 gAlice->TreeS()->AutoSave() ;
326 if(strstr(option,"deb"))
327 PrintSDigits(option) ;
330 if(strstr(option,"tim")){
331 gBenchmark->Stop("EMCALSDigitizer");
332 Info("Exec", "took %f seconds for SDigitizing %f seconds per event",
333 gBenchmark->GetCpuTime("EMCALSDigitizer"), gBenchmark->GetCpuTime("EMCALSDigitizer") ) ;
337 //__________________________________________________________________
338 void AliEMCALSDigitizer::SetSDigitsBranch(const char * title ){
340 // Setting title to branch SDigits
342 TString stitle(title) ;
344 // check if branch with title already exists
345 TBranch * sdigitsBranch =
346 static_cast<TBranch*>(gAlice->TreeS()->GetListOfBranches()->FindObject("EMCAL")) ;
347 TBranch * sdigitizerBranch =
348 static_cast<TBranch*>(gAlice->TreeS()->GetListOfBranches()->FindObject("AliEMCALSDigitizer")) ;
349 const char * sdigitsTitle = sdigitsBranch ->GetTitle() ;
350 const char * sdigitizerTitle = sdigitizerBranch ->GetTitle() ;
351 if ( stitle.CompareTo(sdigitsTitle)==0 || stitle.CompareTo(sdigitizerTitle)==0 ){
352 Error("SetSDigitsBranch", "Cannot overwrite existing branch with title %s", title) ;
356 Info("SetSDigitsBranch", "Changing SDigits file from %s to %s", GetName(), title) ;
360 // Post to the WhiteBoard
361 AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
362 gime->PostSDigits( title, GetTitle()) ;
366 //__________________________________________________________________
367 void AliEMCALSDigitizer::Print(Option_t* option)const
369 // Prints parameters of SDigitizer
371 TString message("\n") ;
372 message += "------------------- ";
373 message += GetName() ;
374 message += " -------------\n" ;
375 message += " Writing SDigitis to branch with title " ;
376 message += GetName() ;
377 message += "\n with digitization parameters A = " ;
379 message += "\n B = " ;
381 message += "\n Threshold for Primary assignment in PreShower = " ;
382 message += fPREPrimThreshold ;
383 message += "\n Threshold for Primary assignment in EC section= " ;
384 message += fECPrimThreshold ;
385 message += "\n Threshold for Primary assignment in HC section= " ;
386 message += fHCPrimThreshold ;
387 message += "\n---------------------------------------------------" ;
389 Info("Print", message.Data() ) ;
392 //__________________________________________________________________
393 Bool_t AliEMCALSDigitizer::operator==( AliEMCALSDigitizer const &sd )const
396 // SDititizers are equal if their pedestal, slope and threshold are equal
398 if( (fA==sd.fA)&&(fB==sd.fB)&&
399 (fECPrimThreshold==sd.fECPrimThreshold) &&
400 (fHCPrimThreshold==sd.fHCPrimThreshold) &&
401 (fPREPrimThreshold==sd.fPREPrimThreshold))
407 //__________________________________________________________________
408 void AliEMCALSDigitizer::PrintSDigits(Option_t * option){
409 //Prints list of digits produced at the current pass of AliEMCALDigitizer
411 AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
412 TString sdname(GetName()) ;
413 sdname.Remove(sdname.Index(GetTitle())-1) ;
414 const TClonesArray * sdigits = gime->SDigits(sdname.Data()) ;
416 TString message("\n") ;
417 message += "event " ;
418 message += gAlice->GetEvNumber() ;
419 message += "\n Number of entries in SDigits list " ;
420 message += sdigits->GetEntriesFast() ;
421 if(strstr(option,"all")||strstr(option,"EMC")){
424 AliEMCALDigit * digit;
425 message += "\n Id Amplitude Time Index Nprim: Primaries list \n" ;
427 char * tempo = new char[8192];
428 for (index = 0 ; index < sdigits->GetEntries() ; index++) {
429 digit = dynamic_cast<AliEMCALDigit *>( sdigits->At(index) ) ;
430 sprintf(tempo, "\n%6d %8d %6.5e %4d %2d :",
431 digit->GetId(), digit->GetAmp(), digit->GetTime(), digit->GetIndexInList(), digit->GetNprimary()) ;
435 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
436 sprintf(tempo, "%d ",digit->GetPrimary(iprimary+1) ) ;
442 Info("PrintSDigits", message.Data() ) ;
445 //_______________________________________________________________________________________
446 // void AliEMCALSDigitizer::TestTowerID(void)
450 // Bool_t preshower = kFALSE;
451 // for (j = 0 ; j < 10 ; j++){ // loop over hit id
453 // for (i = 0 ; i <= 2 ; i++){ // loop over
454 // Int_t k = i*96*144+j*144+1;
455 // Info("TestTowerID", " Hit Index = %d %d TOWERID = %d", k, j*10, Layer2TowerID(k, preshower) ) ;
460 //____________________________________________________________________________
461 void AliEMCALSDigitizer::UseHitsFrom(const char * filename)