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 *Ă„Qual * appear in the supporting documentation. The authors make no claims *
11 * about the suitability of this software for any purpose. It is *
12 * provided "as is" without express or implied warranty. *
13 **************************************************************************/
18 /* History of cvs commits:
21 * Revision 1.53 2007/09/30 17:08:20 schutz
22 * Introducing the notion of QA data acquisition cycle (needed by online)
24 * Revision 1.52 2007/09/26 14:22:18 cvetan
25 * Important changes to the reconstructor classes. Complete elimination of the run-loaders, which are now steered only from AliReconstruction. Removal of the corresponding Reconstruct() and FillESD() methods.
27 * Revision 1.51 2007/08/07 14:12:03 kharlov
28 * Quality assurance added (Yves Schutz)
30 * Revision 1.50 2006/08/28 10:01:56 kharlov
31 * Effective C++ warnings fixed (Timur Pocheptsov)
33 * Revision 1.49 2006/05/10 06:42:53 kharlov
34 * Remove redundant loop over primaries
36 * Revision 1.48 2006/04/22 10:30:17 hristov
37 * Add fEnergy to AliPHOSDigit and operate with EMC amplitude in energy units (Yu.Kharlov)
39 * Revision 1.47 2005/05/28 14:19:04 schutz
40 * Compilation warnings fixed by T.P.
44 //_________________________________________________________________________
45 // This is a TTask that makes SDigits out of Hits
46 // The name of the TTask is also the title of the branch that will contain
47 // the created SDigits
48 // The title of the TTAsk is the name of the file that contains the hits from
49 // which the SDigits are created
50 // A Summable Digits is the sum of all hits originating
51 // from one primary in one active cell
52 // A threshold for assignment of the primary to SDigit is applied
53 // SDigits are written to TreeS, branch "PHOS"
54 // AliPHOSSDigitizer with all current parameters is written
55 // to TreeS branch "AliPHOSSDigitizer".
56 // Both branches have the same title. If necessary one can produce
57 // another set of SDigits with different parameters. Two versions
58 // can be distunguished using titles of the branches.
60 // root [0] AliPHOSSDigitizer * s = new AliPHOSSDigitizer("galice.root")
61 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
62 // root [1] s->ExecuteTask()
63 // // Makes SDigitis for all events stored in galice.root
64 // root [2] s->SetPedestalParameter(0.001)
65 // // One can change parameters of digitization
66 // root [3] s->SetSDigitsBranch("Pedestal 0.001")
67 // // and write them into the new branch
68 // root [4] s->ExecuteTask("deb all tim")
69 // // available parameters:
70 // deb - print # of produced SDigitis
71 // deb all - print # and list of produced SDigits
72 // tim - print benchmarking information
74 //*-- Author : Dmitri Peressounko (SUBATECH & KI)
75 //////////////////////////////////////////////////////////////////////////////
78 // --- ROOT system ---
79 #include "TBenchmark.h"
80 //#include "TObjectTable.h"
82 // --- Standard library ---
84 // --- AliRoot header files ---
86 #include "AliPHOSGeometry.h"
87 #include "AliPHOSDigit.h"
88 #include "AliPHOSGetter.h"
89 #include "AliPHOSHit.h"
90 #include "AliPHOSSDigitizer.h"
91 #include "AliPHOSQADataMaker.h"
93 ClassImp(AliPHOSSDigitizer)
96 //____________________________________________________________________________
97 AliPHOSSDigitizer::AliPHOSSDigitizer() :
102 fEventFolderName(""),
110 // Intialize the quality assurance data maker
113 //____________________________________________________________________________
114 AliPHOSSDigitizer::AliPHOSSDigitizer(const char * alirunFileName,
115 const char * eventFolderName):
116 TTask("PHOS"+AliConfig::Instance()->GetSDigitizerTaskName(), alirunFileName),
119 fDefaultInit(kFALSE),
120 fEventFolderName(eventFolderName),
130 fDefaultInit = kFALSE ;
131 // Intialize the quality assurance data maker
132 //FIXME: get the run number
135 GetQADataMaker()->Init(AliQA::kHITS, run, fgkCycles) ;
136 GetQADataMaker()->StartOfCycle(AliQA::kHITS) ;
137 GetQADataMaker()->Init(AliQA::kSDIGITS, run) ;
138 GetQADataMaker()->StartOfCycle(AliQA::kSDIGITS, "same") ;
141 //____________________________________________________________________________
142 AliPHOSSDigitizer::AliPHOSSDigitizer(const AliPHOSSDigitizer& sd) :
143 TTask(sd.GetName(), sd.GetTitle()),
144 fA(sd.fA), fB(sd.fB),
145 fPrimThreshold(sd.fPrimThreshold),
146 fDefaultInit(kFALSE),
147 fEventFolderName(sd.fEventFolderName),
149 fSDigitsInRun(sd.fSDigitsInRun),
150 fFirstEvent(sd.fFirstEvent),
151 fLastEvent(sd.fLastEvent),
155 // Intialize the quality assurance data maker
156 //FIXME: get the run number
159 GetQADataMaker()->Init(AliQA::kHITS, run, fgkCycles) ;
160 GetQADataMaker()->StartOfCycle(AliQA::kHITS) ;
161 GetQADataMaker()->Init(AliQA::kSDIGITS, run) ;
162 GetQADataMaker()->StartOfCycle(AliQA::kSDIGITS, "same") ;
165 //_____________________________________________________________________________
166 AliPHOSSDigitizer& AliPHOSSDigitizer::operator = (const AliPHOSSDigitizer& qa)
168 // assignment operator
170 this->~AliPHOSSDigitizer();
171 new(this) AliPHOSSDigitizer(qa);
175 //____________________________________________________________________________
176 AliPHOSSDigitizer::~AliPHOSSDigitizer() {
178 // AliPHOSGetter * gime =
179 // AliPHOSGetter::Instance(GetTitle(),fEventFolderName.Data());
180 AliPHOSGetter * gime =
181 AliPHOSGetter::Instance();
182 gime->PhosLoader()->CleanSDigitizer();
186 //____________________________________________________________________________
187 void AliPHOSSDigitizer::Init()
189 // Uses the getter to access the required files
193 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName.Data());
195 Fatal("Init" ,"Could not obtain the Getter object for file %s and event %s !", GetTitle(), fEventFolderName.Data()) ;
199 TString opt("SDigits") ;
200 if(gime->VersionExists(opt) ) {
201 Error( "Init", "Give a version name different from %s", fEventFolderName.Data() ) ;
205 gime->PostSDigitizer(this);
206 gime->PhosLoader()->GetSDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
208 fQADM = new AliPHOSQADataMaker() ;
212 //____________________________________________________________________________
213 void AliPHOSSDigitizer::InitParameters()
215 // initializes the parameters for digitization
218 fPrimThreshold = 0.01 ;
222 //____________________________________________________________________________
223 void AliPHOSSDigitizer::Exec(Option_t *option)
225 // Steering method to produce summable digits for events
226 // in the range from fFirstEvent to fLastEvent.
227 // This range is optionally set by SetEventRange().
228 // if fLastEvent=-1 (by default), then process events until the end.
230 // Summable digit is a sum of all hits in the same active
233 if (strstr(option, "print") ) {
238 if(strstr(option,"tim"))
239 gBenchmark->Start("PHOSSDigitizer");
241 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
243 //switch off reloading of this task while getting event
244 if (!fInit) { // to prevent overwrite existing file
245 AliError( Form("Give a version name different from %s", fEventFolderName.Data()) ) ;
249 if (fLastEvent == -1)
250 fLastEvent = gime->MaxEvent() - 1 ;
252 fLastEvent = TMath::Min(fFirstEvent, gime->MaxEvent()); // only ine event at the time
253 Int_t nEvents = fLastEvent - fFirstEvent + 1;
257 //AliMemoryWatcher memwatcher;
259 for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
260 gime->Event(ievent,"H") ;
261 TTree * treeS = gime->TreeS();
262 TClonesArray * hits = gime->Hits() ;
263 TClonesArray * sdigits = gime->SDigits() ;
266 //Now make SDigits from hits, for PHOS it is the same, so just copy
267 for ( i = 0 ; i < hits->GetEntries() ; i++ ) {
268 AliPHOSHit * hit = dynamic_cast<AliPHOSHit *>(hits->At(i)) ;
269 // Assign primary number only if contribution is significant
271 if( hit->GetEnergy() > fPrimThreshold)
272 new((*sdigits)[nSdigits]) AliPHOSDigit(hit->GetPrimary(),hit->GetId(),
273 hit->GetEnergy() ,hit->GetTime()) ;
275 new((*sdigits)[nSdigits]) AliPHOSDigit(-1 ,hit->GetId(),
276 hit->GetEnergy() ,hit->GetTime()) ;
283 nSdigits = sdigits->GetEntriesFast() ;
285 fSDigitsInRun += nSdigits ;
286 sdigits->Expand(nSdigits) ;
288 for (i = 0 ; i < nSdigits ; i++) {
289 AliPHOSDigit * digit = dynamic_cast<AliPHOSDigit *>(sdigits->At(i)) ;
290 digit->SetIndexInList(i) ;
293 // make Quality Assurance data
295 if (GetQADataMaker()->IsCycleDone() ) {
296 GetQADataMaker()->EndOfCycle(AliQA::kHITS) ;
297 GetQADataMaker()->EndOfCycle(AliQA::kSDIGITS) ;
298 GetQADataMaker()->StartOfCycle(AliQA::kHITS) ;
299 GetQADataMaker()->StartOfCycle(AliQA::kSDIGITS, "same") ;
301 GetQADataMaker()->Exec(AliQA::kHITS, hits) ;
302 GetQADataMaker()->Exec(AliQA::kSDIGITS, sdigits) ;
303 GetQADataMaker()->Increment() ;
308 //First list of sdigits
310 Int_t bufferSize = 32000 ;
311 TBranch * sdigitsBranch = treeS->Branch("PHOS",&sdigits,bufferSize);
313 sdigitsBranch->Fill() ;
315 gime->WriteSDigits("OVERWRITE");
319 gime->WriteSDigitizer("OVERWRITE");
320 //gObjectTable->Print() ;
322 if(strstr(option,"deb"))
323 PrintSDigits(option) ;
325 //memwatcher.Watch(ievent);
328 //Write the quality assurance data
329 GetQADataMaker()->EndOfCycle(AliQA::kHITS) ;
330 GetQADataMaker()->EndOfCycle(AliQA::kSDIGITS) ;
331 GetQADataMaker()->Finish(AliQA::kHITS) ;
332 GetQADataMaker()->Finish(AliQA::kSDIGITS) ;
336 // gime->PhosLoader()->GetSDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
338 if(strstr(option,"tim")){
339 gBenchmark->Stop("PHOSSDigitizer");
340 Info("Exec"," took %f seconds for SDigitizing %f seconds per event",
341 gBenchmark->GetCpuTime("PHOSSDigitizer"), gBenchmark->GetCpuTime("PHOSSDigitizer")/nEvents) ;
344 //TFile f("out.root","RECREATE");
345 //memwatcher.WriteToFile();
349 //__________________________________________________________________
350 void AliPHOSSDigitizer::Print(const Option_t *)const
352 // Prints parameters of SDigitizer
353 Info("Print", "\n------------------- %s -------------", GetName() ) ;
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 Primary assignment= %f\n", fPrimThreshold) ;
358 printf("---------------------------------------------------\n") ;
362 //__________________________________________________________________
363 Bool_t AliPHOSSDigitizer::operator==( AliPHOSSDigitizer const &sd )const
366 // SDititizers are equal if their pedestal, slope and threshold are equal
368 if( (fA==sd.fA)&&(fB==sd.fB)&&(fPrimThreshold==sd.fPrimThreshold))
374 //__________________________________________________________________
375 void AliPHOSSDigitizer::PrintSDigits(Option_t * option)
377 // Prints list of digits produced in the current pass of AliPHOSDigitizer
380 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
381 const TClonesArray * sdigits = gime->SDigits() ;
383 Info( "\nPrintSDigits", "event # %d %d sdigits", gAlice->GetEvNumber(), sdigits->GetEntriesFast() ) ;
385 if(strstr(option,"all")||strstr(option,"EMC")){
388 AliPHOSDigit * digit;
389 printf("\nEMC sdigits\n") ;
390 Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
392 for (index = 0 ; (index < sdigits->GetEntriesFast()) &&
393 ((dynamic_cast<AliPHOSDigit *> (sdigits->At(index)))->GetId() <= maxEmc) ; index++) {
394 digit = dynamic_cast<AliPHOSDigit *>( sdigits->At(index) ) ;
395 // if(digit->GetNprimary() == 0)
397 // printf("%6d %8d %6.5e %4d %2d :\n", // YVK
398 printf("%6d %.4f %6.5e %4d %2d :\n",
399 digit->GetId(), digit->GetEnergy(), digit->GetTime(), digit->GetIndexInList(), digit->GetNprimary()) ;
401 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
402 printf("%d ",digit->GetPrimary(iprimary+1) ) ;
407 if(strstr(option,"all")||strstr(option,"CPV")){
409 //loop over CPV digits
410 AliPHOSDigit * digit;
411 printf("\nCPV sdigits\n") ;
412 Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
414 for (index = 0 ; index < sdigits->GetEntriesFast(); index++) {
415 digit = dynamic_cast<AliPHOSDigit *>( sdigits->At(index) ) ;
416 if(digit->GetId() > maxEmc){
417 printf("\n%6d %8d %4d %2d :",
418 digit->GetId(), digit->GetAmp(), digit->GetIndexInList(), digit->GetNprimary()) ;
420 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
421 printf("%d ",digit->GetPrimary(iprimary+1) ) ;
428 //____________________________________________________________________________
429 void AliPHOSSDigitizer::Unload() const
431 // Unloads the objects from the folder
432 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
433 AliPHOSLoader * loader = gime->PhosLoader() ;
434 loader->UnloadHits() ;
435 loader->UnloadSDigits() ;