]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSSDigitizer.cxx
Introducing the notion of QA data acquisition cycle (needed by online)
[u/mrichter/AliRoot.git] / PHOS / AliPHOSSDigitizer.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
14
15
16 /* $Id$ */
17
18 /* History of cvs commits:
19  *
20  * $Log$
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.
23  *
24  * Revision 1.51  2007/08/07 14:12:03  kharlov
25  * Quality assurance added (Yves Schutz)
26  *
27  * Revision 1.50  2006/08/28 10:01:56  kharlov
28  * Effective C++ warnings fixed (Timur Pocheptsov)
29  *
30  * Revision 1.49  2006/05/10 06:42:53  kharlov
31  * Remove redundant loop over primaries
32  *
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)
35  *
36  * Revision 1.47  2005/05/28 14:19:04  schutz
37  * Compilation warnings fixed by T.P.
38  *
39  */
40
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.
56 // User case:
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
70 //
71 //*-- Author :  Dmitri Peressounko (SUBATECH & KI) 
72 //////////////////////////////////////////////////////////////////////////////
73
74
75 // --- ROOT system ---
76 #include "TBenchmark.h"
77                 //#include "TObjectTable.h"
78
79 // --- Standard library ---
80
81 // --- AliRoot header files ---
82 #include "AliLog.h"
83 #include "AliPHOSGeometry.h" 
84 #include "AliPHOSDigit.h"
85 #include "AliPHOSGetter.h"
86 #include "AliPHOSHit.h"
87 #include "AliPHOSSDigitizer.h"
88 #include "AliPHOSQualAssDataMaker.h" 
89
90 ClassImp(AliPHOSSDigitizer)
91
92            
93 //____________________________________________________________________________ 
94 AliPHOSSDigitizer::AliPHOSSDigitizer() : 
95   TTask("",""),
96   fA(0.f), fB(0.f),
97   fPrimThreshold(0.f),
98   fDefaultInit(kTRUE),
99   fEventFolderName(""),
100   fInit(kFALSE),
101   fSDigitsInRun(0),
102   fFirstEvent(0),
103   fLastEvent(0), 
104   fQADM (0x0)
105 {
106   // ctor
107   // Intialize the quality assurance data maker         
108 }
109
110 //____________________________________________________________________________ 
111 AliPHOSSDigitizer::AliPHOSSDigitizer(const char * alirunFileName, 
112                                      const char * eventFolderName):
113   TTask("PHOS"+AliConfig::Instance()->GetSDigitizerTaskName(), alirunFileName),
114   fA(0.f), fB(0.f),
115   fPrimThreshold(0.f),
116   fDefaultInit(kFALSE),
117   fEventFolderName(eventFolderName),
118   fInit(kFALSE),
119   fSDigitsInRun(0),
120   fFirstEvent(0),
121   fLastEvent(0), 
122   fQADM (0x0)
123 {
124   // ctor
125   InitParameters() ; 
126   Init();
127   fDefaultInit = kFALSE ; 
128   // Intialize the quality assurance data maker 
129   //FIXME: get the run number
130   Int_t run = 0 ;
131   //EMXIF       
132   GetQualAssDataMaker()->Init(AliQualAss::kHITS, run, fgkCycles) ;
133   GetQualAssDataMaker()->StartOfCycle(AliQualAss::kHITS) ;
134   GetQualAssDataMaker()->Init(AliQualAss::kSDIGITS, run) ; 
135   GetQualAssDataMaker()->StartOfCycle(AliQualAss::kSDIGITS, "same") ;
136 }
137
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),
145   fInit(kFALSE),
146   fSDigitsInRun(sd.fSDigitsInRun),
147   fFirstEvent(sd.fFirstEvent),
148   fLastEvent(sd.fLastEvent), 
149   fQADM (sd.fQADM)
150
151   // cpy ctor
152   // Intialize the quality assurance data maker         
153   //FIXME: get the run number
154   Int_t run = 0 ;
155   //EMXIF       
156   GetQualAssDataMaker()->Init(AliQualAss::kHITS, run, fgkCycles) ;
157   GetQualAssDataMaker()->StartOfCycle(AliQualAss::kHITS) ;
158   GetQualAssDataMaker()->Init(AliQualAss::kSDIGITS, run) ; 
159   GetQualAssDataMaker()->StartOfCycle(AliQualAss::kSDIGITS, "same") ;
160 }
161
162 //_____________________________________________________________________________
163 AliPHOSSDigitizer& AliPHOSSDigitizer::operator = (const AliPHOSSDigitizer& qa)
164 {
165 // assignment operator
166
167   this->~AliPHOSSDigitizer();
168   new(this) AliPHOSSDigitizer(qa);
169   return *this;
170 }
171
172 //____________________________________________________________________________ 
173 AliPHOSSDigitizer::~AliPHOSSDigitizer() {
174   //dtor
175   //  AliPHOSGetter * gime =
176   //  AliPHOSGetter::Instance(GetTitle(),fEventFolderName.Data());  
177   AliPHOSGetter * gime =
178     AliPHOSGetter::Instance();  
179   gime->PhosLoader()->CleanSDigitizer();
180   delete fQADM ; 
181 }
182
183 //____________________________________________________________________________ 
184 void AliPHOSSDigitizer::Init()
185 {
186   // Uses the getter to access the required files
187   
188   fInit = kTRUE ; 
189   
190   AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName.Data());  
191   if ( gime == 0 ) {
192     Fatal("Init" ,"Could not obtain the Getter object for file %s and event %s !", GetTitle(), fEventFolderName.Data()) ;  
193     return ;
194   } 
195   
196   TString opt("SDigits") ; 
197   if(gime->VersionExists(opt) ) { 
198     Error( "Init", "Give a version name different from %s", fEventFolderName.Data() ) ;
199     fInit = kFALSE ; 
200   }
201
202   gime->PostSDigitizer(this);
203   gime->PhosLoader()->GetSDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
204  
205   fQADM = new AliPHOSQualAssDataMaker() ;  
206
207 }
208
209 //____________________________________________________________________________ 
210 void AliPHOSSDigitizer::InitParameters()
211
212   // initializes the parameters for digitization
213   fA             = 0;
214   fB             = 10000000.;
215   fPrimThreshold = 0.01 ;
216   fSDigitsInRun  = 0 ;
217 }
218
219 //____________________________________________________________________________
220 void AliPHOSSDigitizer::Exec(Option_t *option) 
221
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.
226   //
227   // Summable digit is a sum of all hits in the same active
228   // volume into digit
229   
230   if (strstr(option, "print") ) {
231     Print() ; 
232     return ; 
233   }
234
235   if(strstr(option,"tim"))
236     gBenchmark->Start("PHOSSDigitizer");
237   
238   AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
239
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()) ) ;
243     return ;
244   }
245
246   if (fLastEvent == -1) 
247     fLastEvent = gime->MaxEvent() - 1 ;
248   else 
249     fLastEvent = TMath::Min(fFirstEvent, gime->MaxEvent()); // only ine event at the time 
250   Int_t nEvents   = fLastEvent - fFirstEvent + 1;
251   
252   Int_t ievent, i;
253
254   //AliMemoryWatcher memwatcher;
255
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() ;
261     sdigits->Clear();
262     Int_t nSdigits = 0 ;
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
267       
268       if( hit->GetEnergy() > fPrimThreshold)
269         new((*sdigits)[nSdigits]) AliPHOSDigit(hit->GetPrimary(),hit->GetId(),
270                                                hit->GetEnergy() ,hit->GetTime()) ;
271       else
272         new((*sdigits)[nSdigits]) AliPHOSDigit(-1               ,hit->GetId(), 
273                                                hit->GetEnergy() ,hit->GetTime()) ;
274       nSdigits++ ;      
275       
276     }
277  
278     sdigits->Sort() ;
279
280     nSdigits = sdigits->GetEntriesFast() ;
281
282     fSDigitsInRun += nSdigits ;  
283     sdigits->Expand(nSdigits) ;
284
285     for (i = 0 ; i < nSdigits ; i++) { 
286       AliPHOSDigit * digit = dynamic_cast<AliPHOSDigit *>(sdigits->At(i)) ; 
287       digit->SetIndexInList(i) ;     
288     }
289
290     // make Quality Assurance data
291
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") ; 
297    }
298     GetQualAssDataMaker()->Exec(AliQualAss::kHITS, hits) ; 
299     GetQualAssDataMaker()->Exec(AliQualAss::kSDIGITS, sdigits) ; 
300     GetQualAssDataMaker()->Increment() ;
301         
302     //Now write SDigits
303
304     
305     //First list of sdigits
306
307     Int_t bufferSize = 32000 ;
308     TBranch * sdigitsBranch = treeS->Branch("PHOS",&sdigits,bufferSize);
309
310     sdigitsBranch->Fill() ;
311
312     gime->WriteSDigits("OVERWRITE");
313
314     //Next - SDigitizer
315
316     gime->WriteSDigitizer("OVERWRITE");
317     //gObjectTable->Print() ; 
318   
319     if(strstr(option,"deb"))
320       PrintSDigits(option) ;
321       
322     //memwatcher.Watch(ievent); 
323   }// event loop
324   
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) ;
330
331   Unload();
332
333   //  gime->PhosLoader()->GetSDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
334   
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) ;
339   }
340   
341   //TFile f("out.root","RECREATE");
342   //memwatcher.WriteToFile(); 
343   //f.Close();
344 }
345
346 //__________________________________________________________________
347 void AliPHOSSDigitizer::Print(const Option_t *)const
348 {
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") ;
356   
357 }
358
359 //__________________________________________________________________
360 Bool_t AliPHOSSDigitizer::operator==( AliPHOSSDigitizer const &sd )const
361 {
362   // Equal operator.
363   // SDititizers are equal if their pedestal, slope and threshold are equal
364
365   if( (fA==sd.fA)&&(fB==sd.fB)&&(fPrimThreshold==sd.fPrimThreshold))
366     return kTRUE ;
367   else
368     return kFALSE ;
369 }
370
371 //__________________________________________________________________
372 void AliPHOSSDigitizer::PrintSDigits(Option_t * option)
373 {
374   // Prints list of digits produced in the current pass of AliPHOSDigitizer
375
376
377   AliPHOSGetter * gime = AliPHOSGetter::Instance() ; 
378   const TClonesArray * sdigits = gime->SDigits() ;
379   
380   Info( "\nPrintSDigits", "event # %d %d sdigits", gAlice->GetEvNumber(), sdigits->GetEntriesFast() ) ; 
381
382   if(strstr(option,"all")||strstr(option,"EMC")){
383     
384     //loop over digits
385     AliPHOSDigit * digit;
386     printf("\nEMC sdigits\n") ; 
387     Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
388     Int_t index ;
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) 
393       //        continue;
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()) ;  
397       Int_t iprimary;
398       for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
399         printf("%d ",digit->GetPrimary(iprimary+1) ) ; 
400       }  
401     }    
402   }
403
404   if(strstr(option,"all")||strstr(option,"CPV")){
405     
406     //loop over CPV digits
407     AliPHOSDigit * digit;
408     printf("\nCPV sdigits\n") ; 
409     Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
410     Int_t index ;
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()) ;  
416         Int_t iprimary;
417         for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
418           printf("%d ",digit->GetPrimary(iprimary+1) ) ; 
419         }
420       }    
421     }
422   }
423 }
424
425 //____________________________________________________________________________ 
426 void AliPHOSSDigitizer::Unload() const
427 {
428   // Unloads the objects from the folder
429   AliPHOSGetter * gime = AliPHOSGetter::Instance() ; 
430   AliPHOSLoader * loader = gime->PhosLoader() ; 
431   loader->UnloadHits() ; 
432   loader->UnloadSDigits() ; 
433 }