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 **************************************************************************/
19 /* History of cvs commits:
22 * Revision 1.50 2006/08/28 10:01:56 kharlov
23 * Effective C++ warnings fixed (Timur Pocheptsov)
25 * Revision 1.49 2006/05/10 06:42:53 kharlov
26 * Remove redundant loop over primaries
28 * Revision 1.48 2006/04/22 10:30:17 hristov
29 * Add fEnergy to AliPHOSDigit and operate with EMC amplitude in energy units (Yu.Kharlov)
31 * Revision 1.47 2005/05/28 14:19:04 schutz
32 * Compilation warnings fixed by T.P.
36 //_________________________________________________________________________
37 // This is a TTask that makes SDigits out of Hits
38 // The name of the TTask is also the title of the branch that will contain
39 // the created SDigits
40 // The title of the TTAsk is the name of the file that contains the hits from
41 // which the SDigits are created
42 // A Summable Digits is the sum of all hits originating
43 // from one primary in one active cell
44 // A threshold for assignment of the primary to SDigit is applied
45 // SDigits are written to TreeS, branch "PHOS"
46 // AliPHOSSDigitizer with all current parameters is written
47 // to TreeS branch "AliPHOSSDigitizer".
48 // Both branches have the same title. If necessary one can produce
49 // another set of SDigits with different parameters. Two versions
50 // can be distunguished using titles of the branches.
52 // root [0] AliPHOSSDigitizer * s = new AliPHOSSDigitizer("galice.root")
53 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
54 // root [1] s->ExecuteTask()
55 // // Makes SDigitis for all events stored in galice.root
56 // root [2] s->SetPedestalParameter(0.001)
57 // // One can change parameters of digitization
58 // root [3] s->SetSDigitsBranch("Pedestal 0.001")
59 // // and write them into the new branch
60 // root [4] s->ExecuteTask("deb all tim")
61 // // available parameters:
62 // deb - print # of produced SDigitis
63 // deb all - print # and list of produced SDigits
64 // tim - print benchmarking information
66 //*-- Author : Dmitri Peressounko (SUBATECH & KI)
67 //////////////////////////////////////////////////////////////////////////////
70 // --- ROOT system ---
71 #include "TBenchmark.h"
72 //#include "TObjectTable.h"
74 // --- Standard library ---
76 // --- AliRoot header files ---
78 #include "AliPHOSGeometry.h"
79 #include "AliPHOSDigit.h"
80 #include "AliPHOSGetter.h"
81 #include "AliPHOSHit.h"
82 #include "AliPHOSSDigitizer.h"
83 #include "AliPHOSQualAssDataMaker.h"
85 ClassImp(AliPHOSSDigitizer)
88 //____________________________________________________________________________
89 AliPHOSSDigitizer::AliPHOSSDigitizer() :
102 // Intialize the quality assurance data maker
105 //____________________________________________________________________________
106 AliPHOSSDigitizer::AliPHOSSDigitizer(const char * alirunFileName,
107 const char * eventFolderName):
108 TTask("PHOS"+AliConfig::Instance()->GetSDigitizerTaskName(), alirunFileName),
111 fDefaultInit(kFALSE),
112 fEventFolderName(eventFolderName),
122 fDefaultInit = kFALSE ;
123 // Intialize the quality assurance data maker
124 GetQualAssDataMaker()->Init(AliQualAss::kHITS) ;
125 GetQualAssDataMaker()->Init(AliQualAss::kSDIGITS) ;
128 //____________________________________________________________________________
129 AliPHOSSDigitizer::AliPHOSSDigitizer(const AliPHOSSDigitizer& sd) :
130 TTask(sd.GetName(), sd.GetTitle()),
131 fA(sd.fA), fB(sd.fB),
132 fPrimThreshold(sd.fPrimThreshold),
133 fDefaultInit(kFALSE),
134 fEventFolderName(sd.fEventFolderName),
136 fSDigitsInRun(sd.fSDigitsInRun),
137 fFirstEvent(sd.fFirstEvent),
138 fLastEvent(sd.fLastEvent),
142 // Intialize the quality assurance data maker
143 GetQualAssDataMaker()->Init(AliQualAss::kHITS) ;
144 GetQualAssDataMaker()->Init(AliQualAss::kSDIGITS) ;
148 //_____________________________________________________________________________
149 AliPHOSSDigitizer& AliPHOSSDigitizer::operator = (const AliPHOSSDigitizer& qa)
151 // assignment operator
153 this->~AliPHOSSDigitizer();
154 new(this) AliPHOSSDigitizer(qa);
158 //____________________________________________________________________________
159 AliPHOSSDigitizer::~AliPHOSSDigitizer() {
161 // AliPHOSGetter * gime =
162 // AliPHOSGetter::Instance(GetTitle(),fEventFolderName.Data());
163 AliPHOSGetter * gime =
164 AliPHOSGetter::Instance();
165 gime->PhosLoader()->CleanSDigitizer();
169 //____________________________________________________________________________
170 void AliPHOSSDigitizer::Init()
172 // Uses the getter to access the required files
176 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName.Data());
178 Fatal("Init" ,"Could not obtain the Getter object for file %s and event %s !", GetTitle(), fEventFolderName.Data()) ;
182 TString opt("SDigits") ;
183 if(gime->VersionExists(opt) ) {
184 Error( "Init", "Give a version name different from %s", fEventFolderName.Data() ) ;
188 gime->PostSDigitizer(this);
189 gime->PhosLoader()->GetSDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
191 fQADM = new AliPHOSQualAssDataMaker() ;
195 //____________________________________________________________________________
196 void AliPHOSSDigitizer::InitParameters()
198 // initializes the parameters for digitization
201 fPrimThreshold = 0.01 ;
205 //____________________________________________________________________________
206 void AliPHOSSDigitizer::Exec(Option_t *option)
208 // Steering method to produce summable digits for events
209 // in the range from fFirstEvent to fLastEvent.
210 // This range is optionally set by SetEventRange().
211 // if fLastEvent=-1 (by default), then process events until the end.
213 // Summable digit is a sum of all hits in the same active
216 if (strstr(option, "print") ) {
221 if(strstr(option,"tim"))
222 gBenchmark->Start("PHOSSDigitizer");
224 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
226 //switch off reloading of this task while getting event
227 if (!fInit) { // to prevent overwrite existing file
228 AliError( Form("Give a version name different from %s", fEventFolderName.Data()) ) ;
232 if (fLastEvent == -1)
233 fLastEvent = gime->MaxEvent() - 1 ;
235 fLastEvent = TMath::Min(fFirstEvent, gime->MaxEvent()); // only ine event at the time
236 Int_t nEvents = fLastEvent - fFirstEvent + 1;
240 //AliMemoryWatcher memwatcher;
242 for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
243 gime->Event(ievent,"H") ;
244 TTree * treeS = gime->TreeS();
245 TClonesArray * hits = gime->Hits() ;
246 TClonesArray * sdigits = gime->SDigits() ;
249 //Now make SDigits from hits, for PHOS it is the same, so just copy
250 for ( i = 0 ; i < hits->GetEntries() ; i++ ) {
251 AliPHOSHit * hit = dynamic_cast<AliPHOSHit *>(hits->At(i)) ;
252 // Assign primary number only if contribution is significant
254 if( hit->GetEnergy() > fPrimThreshold)
255 new((*sdigits)[nSdigits]) AliPHOSDigit(hit->GetPrimary(),hit->GetId(),
256 hit->GetEnergy() ,hit->GetTime()) ;
258 new((*sdigits)[nSdigits]) AliPHOSDigit(-1 ,hit->GetId(),
259 hit->GetEnergy() ,hit->GetTime()) ;
266 nSdigits = sdigits->GetEntriesFast() ;
268 fSDigitsInRun += nSdigits ;
269 sdigits->Expand(nSdigits) ;
271 for (i = 0 ; i < nSdigits ; i++) {
272 AliPHOSDigit * digit = dynamic_cast<AliPHOSDigit *>(sdigits->At(i)) ;
273 digit->SetIndexInList(i) ;
276 // make Quality Assurance data
278 GetQualAssDataMaker()->SetData(hits) ;
279 GetQualAssDataMaker()->Exec(AliQualAss::kHITS) ;
280 GetQualAssDataMaker()->SetData(sdigits) ;
281 GetQualAssDataMaker()->Exec(AliQualAss::kSDIGITS) ;
287 //First list of sdigits
289 Int_t bufferSize = 32000 ;
290 TBranch * sdigitsBranch = treeS->Branch("PHOS",&sdigits,bufferSize);
292 sdigitsBranch->Fill() ;
294 gime->WriteSDigits("OVERWRITE");
298 gime->WriteSDigitizer("OVERWRITE");
299 //gObjectTable->Print() ;
301 if(strstr(option,"deb"))
302 PrintSDigits(option) ;
304 //memwatcher.Watch(ievent);
307 //Write the quality assurance data
308 GetQualAssDataMaker()->Finish(AliQualAss::kHITS) ;
309 GetQualAssDataMaker()->Finish(AliQualAss::kSDIGITS) ;
313 // gime->PhosLoader()->GetSDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
315 if(strstr(option,"tim")){
316 gBenchmark->Stop("PHOSSDigitizer");
317 Info("Exec"," took %f seconds for SDigitizing %f seconds per event",
318 gBenchmark->GetCpuTime("PHOSSDigitizer"), gBenchmark->GetCpuTime("PHOSSDigitizer")/nEvents) ;
321 //TFile f("out.root","RECREATE");
322 //memwatcher.WriteToFile();
326 //__________________________________________________________________
327 void AliPHOSSDigitizer::Print(const Option_t *)const
329 // Prints parameters of SDigitizer
330 Info("Print", "\n------------------- %s -------------", GetName() ) ;
331 printf(" Writing SDigits to branch with title %s\n", fEventFolderName.Data()) ;
332 printf(" with digitization parameters A = %f\n", fA) ;
333 printf(" B = %f\n", fB) ;
334 printf(" Threshold for Primary assignment= %f\n", fPrimThreshold) ;
335 printf("---------------------------------------------------\n") ;
339 //__________________________________________________________________
340 Bool_t AliPHOSSDigitizer::operator==( AliPHOSSDigitizer const &sd )const
343 // SDititizers are equal if their pedestal, slope and threshold are equal
345 if( (fA==sd.fA)&&(fB==sd.fB)&&(fPrimThreshold==sd.fPrimThreshold))
351 //__________________________________________________________________
352 void AliPHOSSDigitizer::PrintSDigits(Option_t * option)
354 // Prints list of digits produced in the current pass of AliPHOSDigitizer
357 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
358 const TClonesArray * sdigits = gime->SDigits() ;
360 Info( "\nPrintSDigits", "event # %d %d sdigits", gAlice->GetEvNumber(), sdigits->GetEntriesFast() ) ;
362 if(strstr(option,"all")||strstr(option,"EMC")){
365 AliPHOSDigit * digit;
366 printf("\nEMC sdigits\n") ;
367 Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
369 for (index = 0 ; (index < sdigits->GetEntriesFast()) &&
370 ((dynamic_cast<AliPHOSDigit *> (sdigits->At(index)))->GetId() <= maxEmc) ; index++) {
371 digit = dynamic_cast<AliPHOSDigit *>( sdigits->At(index) ) ;
372 // if(digit->GetNprimary() == 0)
374 // printf("%6d %8d %6.5e %4d %2d :\n", // YVK
375 printf("%6d %.4f %6.5e %4d %2d :\n",
376 digit->GetId(), digit->GetEnergy(), digit->GetTime(), digit->GetIndexInList(), digit->GetNprimary()) ;
378 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
379 printf("%d ",digit->GetPrimary(iprimary+1) ) ;
384 if(strstr(option,"all")||strstr(option,"CPV")){
386 //loop over CPV digits
387 AliPHOSDigit * digit;
388 printf("\nCPV sdigits\n") ;
389 Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
391 for (index = 0 ; index < sdigits->GetEntriesFast(); index++) {
392 digit = dynamic_cast<AliPHOSDigit *>( sdigits->At(index) ) ;
393 if(digit->GetId() > maxEmc){
394 printf("\n%6d %8d %4d %2d :",
395 digit->GetId(), digit->GetAmp(), digit->GetIndexInList(), digit->GetNprimary()) ;
397 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
398 printf("%d ",digit->GetPrimary(iprimary+1) ) ;
405 //____________________________________________________________________________
406 void AliPHOSSDigitizer::Unload() const
408 // Unloads the objects from the folder
409 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
410 AliPHOSLoader * loader = gime->PhosLoader() ;
411 loader->UnloadHits() ;
412 loader->UnloadSDigits() ;