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.52 2007/09/26 14:22:18 cvetan
22 * 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.
24 * Revision 1.51 2007/08/07 14:12:03 kharlov
25 * Quality assurance added (Yves Schutz)
27 * Revision 1.50 2006/08/28 10:01:56 kharlov
28 * Effective C++ warnings fixed (Timur Pocheptsov)
30 * Revision 1.49 2006/05/10 06:42:53 kharlov
31 * Remove redundant loop over primaries
33 * Revision 1.48 2006/04/22 10:30:17 hristov
34 * Add fEnergy to AliPHOSDigit and operate with EMC amplitude in energy units (Yu.Kharlov)
36 * Revision 1.47 2005/05/28 14:19:04 schutz
37 * Compilation warnings fixed by T.P.
41 //_________________________________________________________________________
42 // This is a TTask that makes SDigits out of Hits
43 // The name of the TTask is also the title of the branch that will contain
44 // the created SDigits
45 // The title of the TTAsk is the name of the file that contains the hits from
46 // which the SDigits are created
47 // A Summable Digits is the sum of all hits originating
48 // from one primary in one active cell
49 // A threshold for assignment of the primary to SDigit is applied
50 // SDigits are written to TreeS, branch "PHOS"
51 // AliPHOSSDigitizer with all current parameters is written
52 // to TreeS branch "AliPHOSSDigitizer".
53 // Both branches have the same title. If necessary one can produce
54 // another set of SDigits with different parameters. Two versions
55 // can be distunguished using titles of the branches.
57 // root [0] AliPHOSSDigitizer * s = new AliPHOSSDigitizer("galice.root")
58 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
59 // root [1] s->ExecuteTask()
60 // // Makes SDigitis for all events stored in galice.root
61 // root [2] s->SetPedestalParameter(0.001)
62 // // One can change parameters of digitization
63 // root [3] s->SetSDigitsBranch("Pedestal 0.001")
64 // // and write them into the new branch
65 // root [4] s->ExecuteTask("deb all tim")
66 // // available parameters:
67 // deb - print # of produced SDigitis
68 // deb all - print # and list of produced SDigits
69 // tim - print benchmarking information
71 //*-- Author : Dmitri Peressounko (SUBATECH & KI)
72 //////////////////////////////////////////////////////////////////////////////
75 // --- ROOT system ---
76 #include "TBenchmark.h"
77 //#include "TObjectTable.h"
79 // --- Standard library ---
81 // --- AliRoot header files ---
83 #include "AliPHOSGeometry.h"
84 #include "AliPHOSDigit.h"
85 #include "AliPHOSGetter.h"
86 #include "AliPHOSHit.h"
87 #include "AliPHOSSDigitizer.h"
88 #include "AliPHOSQualAssDataMaker.h"
90 ClassImp(AliPHOSSDigitizer)
93 //____________________________________________________________________________
94 AliPHOSSDigitizer::AliPHOSSDigitizer() :
107 // Intialize the quality assurance data maker
110 //____________________________________________________________________________
111 AliPHOSSDigitizer::AliPHOSSDigitizer(const char * alirunFileName,
112 const char * eventFolderName):
113 TTask("PHOS"+AliConfig::Instance()->GetSDigitizerTaskName(), alirunFileName),
116 fDefaultInit(kFALSE),
117 fEventFolderName(eventFolderName),
127 fDefaultInit = kFALSE ;
128 // Intialize the quality assurance data maker
129 //FIXME: get the run number
132 GetQualAssDataMaker()->Init(AliQualAss::kHITS, run, fgkCycles) ;
133 GetQualAssDataMaker()->StartOfCycle(AliQualAss::kHITS) ;
134 GetQualAssDataMaker()->Init(AliQualAss::kSDIGITS, run) ;
135 GetQualAssDataMaker()->StartOfCycle(AliQualAss::kSDIGITS, "same") ;
138 //____________________________________________________________________________
139 AliPHOSSDigitizer::AliPHOSSDigitizer(const AliPHOSSDigitizer& sd) :
140 TTask(sd.GetName(), sd.GetTitle()),
141 fA(sd.fA), fB(sd.fB),
142 fPrimThreshold(sd.fPrimThreshold),
143 fDefaultInit(kFALSE),
144 fEventFolderName(sd.fEventFolderName),
146 fSDigitsInRun(sd.fSDigitsInRun),
147 fFirstEvent(sd.fFirstEvent),
148 fLastEvent(sd.fLastEvent),
152 // Intialize the quality assurance data maker
153 //FIXME: get the run number
156 GetQualAssDataMaker()->Init(AliQualAss::kHITS, run, fgkCycles) ;
157 GetQualAssDataMaker()->StartOfCycle(AliQualAss::kHITS) ;
158 GetQualAssDataMaker()->Init(AliQualAss::kSDIGITS, run) ;
159 GetQualAssDataMaker()->StartOfCycle(AliQualAss::kSDIGITS, "same") ;
162 //_____________________________________________________________________________
163 AliPHOSSDigitizer& AliPHOSSDigitizer::operator = (const AliPHOSSDigitizer& qa)
165 // assignment operator
167 this->~AliPHOSSDigitizer();
168 new(this) AliPHOSSDigitizer(qa);
172 //____________________________________________________________________________
173 AliPHOSSDigitizer::~AliPHOSSDigitizer() {
175 // AliPHOSGetter * gime =
176 // AliPHOSGetter::Instance(GetTitle(),fEventFolderName.Data());
177 AliPHOSGetter * gime =
178 AliPHOSGetter::Instance();
179 gime->PhosLoader()->CleanSDigitizer();
183 //____________________________________________________________________________
184 void AliPHOSSDigitizer::Init()
186 // Uses the getter to access the required files
190 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName.Data());
192 Fatal("Init" ,"Could not obtain the Getter object for file %s and event %s !", GetTitle(), fEventFolderName.Data()) ;
196 TString opt("SDigits") ;
197 if(gime->VersionExists(opt) ) {
198 Error( "Init", "Give a version name different from %s", fEventFolderName.Data() ) ;
202 gime->PostSDigitizer(this);
203 gime->PhosLoader()->GetSDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
205 fQADM = new AliPHOSQualAssDataMaker() ;
209 //____________________________________________________________________________
210 void AliPHOSSDigitizer::InitParameters()
212 // initializes the parameters for digitization
215 fPrimThreshold = 0.01 ;
219 //____________________________________________________________________________
220 void AliPHOSSDigitizer::Exec(Option_t *option)
222 // Steering method to produce summable digits for events
223 // in the range from fFirstEvent to fLastEvent.
224 // This range is optionally set by SetEventRange().
225 // if fLastEvent=-1 (by default), then process events until the end.
227 // Summable digit is a sum of all hits in the same active
230 if (strstr(option, "print") ) {
235 if(strstr(option,"tim"))
236 gBenchmark->Start("PHOSSDigitizer");
238 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
240 //switch off reloading of this task while getting event
241 if (!fInit) { // to prevent overwrite existing file
242 AliError( Form("Give a version name different from %s", fEventFolderName.Data()) ) ;
246 if (fLastEvent == -1)
247 fLastEvent = gime->MaxEvent() - 1 ;
249 fLastEvent = TMath::Min(fFirstEvent, gime->MaxEvent()); // only ine event at the time
250 Int_t nEvents = fLastEvent - fFirstEvent + 1;
254 //AliMemoryWatcher memwatcher;
256 for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
257 gime->Event(ievent,"H") ;
258 TTree * treeS = gime->TreeS();
259 TClonesArray * hits = gime->Hits() ;
260 TClonesArray * sdigits = gime->SDigits() ;
263 //Now make SDigits from hits, for PHOS it is the same, so just copy
264 for ( i = 0 ; i < hits->GetEntries() ; i++ ) {
265 AliPHOSHit * hit = dynamic_cast<AliPHOSHit *>(hits->At(i)) ;
266 // Assign primary number only if contribution is significant
268 if( hit->GetEnergy() > fPrimThreshold)
269 new((*sdigits)[nSdigits]) AliPHOSDigit(hit->GetPrimary(),hit->GetId(),
270 hit->GetEnergy() ,hit->GetTime()) ;
272 new((*sdigits)[nSdigits]) AliPHOSDigit(-1 ,hit->GetId(),
273 hit->GetEnergy() ,hit->GetTime()) ;
280 nSdigits = sdigits->GetEntriesFast() ;
282 fSDigitsInRun += nSdigits ;
283 sdigits->Expand(nSdigits) ;
285 for (i = 0 ; i < nSdigits ; i++) {
286 AliPHOSDigit * digit = dynamic_cast<AliPHOSDigit *>(sdigits->At(i)) ;
287 digit->SetIndexInList(i) ;
290 // make Quality Assurance data
292 if (GetQualAssDataMaker()->IsCycleDone() ) {
293 GetQualAssDataMaker()->EndOfCycle(AliQualAss::kHITS) ;
294 GetQualAssDataMaker()->EndOfCycle(AliQualAss::kSDIGITS) ;
295 GetQualAssDataMaker()->StartOfCycle(AliQualAss::kHITS) ;
296 GetQualAssDataMaker()->StartOfCycle(AliQualAss::kSDIGITS, "same") ;
298 GetQualAssDataMaker()->Exec(AliQualAss::kHITS, hits) ;
299 GetQualAssDataMaker()->Exec(AliQualAss::kSDIGITS, sdigits) ;
300 GetQualAssDataMaker()->Increment() ;
305 //First list of sdigits
307 Int_t bufferSize = 32000 ;
308 TBranch * sdigitsBranch = treeS->Branch("PHOS",&sdigits,bufferSize);
310 sdigitsBranch->Fill() ;
312 gime->WriteSDigits("OVERWRITE");
316 gime->WriteSDigitizer("OVERWRITE");
317 //gObjectTable->Print() ;
319 if(strstr(option,"deb"))
320 PrintSDigits(option) ;
322 //memwatcher.Watch(ievent);
325 //Write the quality assurance data
326 GetQualAssDataMaker()->EndOfCycle(AliQualAss::kHITS) ;
327 GetQualAssDataMaker()->EndOfCycle(AliQualAss::kSDIGITS) ;
328 GetQualAssDataMaker()->Finish(AliQualAss::kHITS) ;
329 GetQualAssDataMaker()->Finish(AliQualAss::kSDIGITS) ;
333 // gime->PhosLoader()->GetSDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
335 if(strstr(option,"tim")){
336 gBenchmark->Stop("PHOSSDigitizer");
337 Info("Exec"," took %f seconds for SDigitizing %f seconds per event",
338 gBenchmark->GetCpuTime("PHOSSDigitizer"), gBenchmark->GetCpuTime("PHOSSDigitizer")/nEvents) ;
341 //TFile f("out.root","RECREATE");
342 //memwatcher.WriteToFile();
346 //__________________________________________________________________
347 void AliPHOSSDigitizer::Print(const Option_t *)const
349 // Prints parameters of SDigitizer
350 Info("Print", "\n------------------- %s -------------", GetName() ) ;
351 printf(" Writing SDigits to branch with title %s\n", fEventFolderName.Data()) ;
352 printf(" with digitization parameters A = %f\n", fA) ;
353 printf(" B = %f\n", fB) ;
354 printf(" Threshold for Primary assignment= %f\n", fPrimThreshold) ;
355 printf("---------------------------------------------------\n") ;
359 //__________________________________________________________________
360 Bool_t AliPHOSSDigitizer::operator==( AliPHOSSDigitizer const &sd )const
363 // SDititizers are equal if their pedestal, slope and threshold are equal
365 if( (fA==sd.fA)&&(fB==sd.fB)&&(fPrimThreshold==sd.fPrimThreshold))
371 //__________________________________________________________________
372 void AliPHOSSDigitizer::PrintSDigits(Option_t * option)
374 // Prints list of digits produced in the current pass of AliPHOSDigitizer
377 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
378 const TClonesArray * sdigits = gime->SDigits() ;
380 Info( "\nPrintSDigits", "event # %d %d sdigits", gAlice->GetEvNumber(), sdigits->GetEntriesFast() ) ;
382 if(strstr(option,"all")||strstr(option,"EMC")){
385 AliPHOSDigit * digit;
386 printf("\nEMC sdigits\n") ;
387 Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
389 for (index = 0 ; (index < sdigits->GetEntriesFast()) &&
390 ((dynamic_cast<AliPHOSDigit *> (sdigits->At(index)))->GetId() <= maxEmc) ; index++) {
391 digit = dynamic_cast<AliPHOSDigit *>( sdigits->At(index) ) ;
392 // if(digit->GetNprimary() == 0)
394 // printf("%6d %8d %6.5e %4d %2d :\n", // YVK
395 printf("%6d %.4f %6.5e %4d %2d :\n",
396 digit->GetId(), digit->GetEnergy(), digit->GetTime(), digit->GetIndexInList(), digit->GetNprimary()) ;
398 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
399 printf("%d ",digit->GetPrimary(iprimary+1) ) ;
404 if(strstr(option,"all")||strstr(option,"CPV")){
406 //loop over CPV digits
407 AliPHOSDigit * digit;
408 printf("\nCPV sdigits\n") ;
409 Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
411 for (index = 0 ; index < sdigits->GetEntriesFast(); index++) {
412 digit = dynamic_cast<AliPHOSDigit *>( sdigits->At(index) ) ;
413 if(digit->GetId() > maxEmc){
414 printf("\n%6d %8d %4d %2d :",
415 digit->GetId(), digit->GetAmp(), digit->GetIndexInList(), digit->GetNprimary()) ;
417 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
418 printf("%d ",digit->GetPrimary(iprimary+1) ) ;
425 //____________________________________________________________________________
426 void AliPHOSSDigitizer::Unload() const
428 // Unloads the objects from the folder
429 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
430 AliPHOSLoader * loader = gime->PhosLoader() ;
431 loader->UnloadHits() ;
432 loader->UnloadSDigits() ;