]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSSDigitizer.cxx
Important changes to the reconstructor classes. Complete elimination of the run-loade...
[u/mrichter/AliRoot.git] / PHOS / AliPHOSSDigitizer.cxx
CommitLineData
990119d6 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 *
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 **************************************************************************/
15
c093f031 16
990119d6 17/* $Id$ */
18
702ab87e 19/* History of cvs commits:
20 *
21 * $Log$
d76c31f4 22 * Revision 1.51 2007/08/07 14:12:03 kharlov
23 * Quality assurance added (Yves Schutz)
24 *
ddd1a39c 25 * Revision 1.50 2006/08/28 10:01:56 kharlov
26 * Effective C++ warnings fixed (Timur Pocheptsov)
27 *
3663622c 28 * Revision 1.49 2006/05/10 06:42:53 kharlov
29 * Remove redundant loop over primaries
30 *
e3310962 31 * Revision 1.48 2006/04/22 10:30:17 hristov
32 * Add fEnergy to AliPHOSDigit and operate with EMC amplitude in energy units (Yu.Kharlov)
33 *
27a73a5d 34 * Revision 1.47 2005/05/28 14:19:04 schutz
35 * Compilation warnings fixed by T.P.
36 *
702ab87e 37 */
38
990119d6 39//_________________________________________________________________________
7acf6008 40// This is a TTask that makes SDigits out of Hits
7b7c1533 41// The name of the TTask is also the title of the branch that will contain
42// the created SDigits
43// The title of the TTAsk is the name of the file that contains the hits from
44// which the SDigits are created
7acf6008 45// A Summable Digits is the sum of all hits originating
46// from one primary in one active cell
47// A threshold for assignment of the primary to SDigit is applied
48// SDigits are written to TreeS, branch "PHOS"
49// AliPHOSSDigitizer with all current parameters is written
50// to TreeS branch "AliPHOSSDigitizer".
f035f6ce 51// Both branches have the same title. If necessary one can produce
52// another set of SDigits with different parameters. Two versions
53// can be distunguished using titles of the branches.
54// User case:
a4e98857 55// root [0] AliPHOSSDigitizer * s = new AliPHOSSDigitizer("galice.root")
56// Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
57// root [1] s->ExecuteTask()
f035f6ce 58// // Makes SDigitis for all events stored in galice.root
a4e98857 59// root [2] s->SetPedestalParameter(0.001)
f035f6ce 60// // One can change parameters of digitization
3de072dc 61// root [3] s->SetSDigitsBranch("Pedestal 0.001")
f035f6ce 62// // and write them into the new branch
3de072dc 63// root [4] s->ExecuteTask("deb all tim")
f035f6ce 64// // available parameters:
65// deb - print # of produced SDigitis
66// deb all - print # and list of produced SDigits
67// tim - print benchmarking information
990119d6 68//
69//*-- Author : Dmitri Peressounko (SUBATECH & KI)
70//////////////////////////////////////////////////////////////////////////////
71
f035f6ce 72
990119d6 73// --- ROOT system ---
7acf6008 74#include "TBenchmark.h"
9d6866ec 75 //#include "TObjectTable.h"
106fc2fa 76
990119d6 77// --- Standard library ---
78
79// --- AliRoot header files ---
9d6866ec 80#include "AliLog.h"
e957fea8 81#include "AliPHOSGeometry.h"
990119d6 82#include "AliPHOSDigit.h"
7b7c1533 83#include "AliPHOSGetter.h"
990119d6 84#include "AliPHOSHit.h"
990119d6 85#include "AliPHOSSDigitizer.h"
ddd1a39c 86#include "AliPHOSQualAssDataMaker.h"
990119d6 87
990119d6 88ClassImp(AliPHOSSDigitizer)
89
90
91//____________________________________________________________________________
3663622c 92AliPHOSSDigitizer::AliPHOSSDigitizer() :
93 TTask("",""),
94 fA(0.f), fB(0.f),
95 fPrimThreshold(0.f),
96 fDefaultInit(kTRUE),
97 fEventFolderName(""),
98 fInit(kFALSE),
99 fSDigitsInRun(0),
100 fFirstEvent(0),
ddd1a39c 101 fLastEvent(0),
102 fQADM (0x0)
548f0134 103{
990119d6 104 // ctor
ddd1a39c 105 // Intialize the quality assurance data maker
990119d6 106}
7acf6008 107
990119d6 108//____________________________________________________________________________
e191bb57 109AliPHOSSDigitizer::AliPHOSSDigitizer(const char * alirunFileName,
110 const char * eventFolderName):
111 TTask("PHOS"+AliConfig::Instance()->GetSDigitizerTaskName(), alirunFileName),
3663622c 112 fA(0.f), fB(0.f),
113 fPrimThreshold(0.f),
114 fDefaultInit(kFALSE),
115 fEventFolderName(eventFolderName),
116 fInit(kFALSE),
117 fSDigitsInRun(0),
118 fFirstEvent(0),
ddd1a39c 119 fLastEvent(0),
120 fQADM (0x0)
990119d6 121{
122 // ctor
8d0f3f77 123 InitParameters() ;
2bd5457f 124 Init();
92f521a9 125 fDefaultInit = kFALSE ;
ddd1a39c 126 // Intialize the quality assurance data maker
127 GetQualAssDataMaker()->Init(AliQualAss::kHITS) ;
128 GetQualAssDataMaker()->Init(AliQualAss::kSDIGITS) ;
129}
130
131//____________________________________________________________________________
132AliPHOSSDigitizer::AliPHOSSDigitizer(const AliPHOSSDigitizer& sd) :
133 TTask(sd.GetName(), sd.GetTitle()),
134 fA(sd.fA), fB(sd.fB),
135 fPrimThreshold(sd.fPrimThreshold),
136 fDefaultInit(kFALSE),
137 fEventFolderName(sd.fEventFolderName),
138 fInit(kFALSE),
139 fSDigitsInRun(sd.fSDigitsInRun),
140 fFirstEvent(sd.fFirstEvent),
141 fLastEvent(sd.fLastEvent),
142 fQADM (sd.fQADM)
143{
144 // cpy ctor
145 // Intialize the quality assurance data maker
146 GetQualAssDataMaker()->Init(AliQualAss::kHITS) ;
147 GetQualAssDataMaker()->Init(AliQualAss::kSDIGITS) ;
148}
149
150
151//_____________________________________________________________________________
152AliPHOSSDigitizer& AliPHOSSDigitizer::operator = (const AliPHOSSDigitizer& qa)
153{
154// assignment operator
155
156 this->~AliPHOSSDigitizer();
157 new(this) AliPHOSSDigitizer(qa);
158 return *this;
990119d6 159}
160
7acf6008 161//____________________________________________________________________________
797e311f 162AliPHOSSDigitizer::~AliPHOSSDigitizer() {
163 //dtor
9d6866ec 164 // AliPHOSGetter * gime =
165 // AliPHOSGetter::Instance(GetTitle(),fEventFolderName.Data());
797e311f 166 AliPHOSGetter * gime =
9d6866ec 167 AliPHOSGetter::Instance();
797e311f 168 gime->PhosLoader()->CleanSDigitizer();
ddd1a39c 169 delete fQADM ;
797e311f 170}
ddd1a39c 171
797e311f 172//____________________________________________________________________________
a4e98857 173void AliPHOSSDigitizer::Init()
174{
88cb7938 175 // Uses the getter to access the required files
7b7c1533 176
88cb7938 177 fInit = kTRUE ;
178
179 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName.Data());
7b7c1533 180 if ( gime == 0 ) {
88cb7938 181 Fatal("Init" ,"Could not obtain the Getter object for file %s and event %s !", GetTitle(), fEventFolderName.Data()) ;
7b7c1533 182 return ;
183 }
184
88cb7938 185 TString opt("SDigits") ;
186 if(gime->VersionExists(opt) ) {
187 Error( "Init", "Give a version name different from %s", fEventFolderName.Data() ) ;
188 fInit = kFALSE ;
fbf811ec 189 }
190
88cb7938 191 gime->PostSDigitizer(this);
192 gime->PhosLoader()->GetSDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
9d6866ec 193
ddd1a39c 194 fQADM = new AliPHOSQualAssDataMaker() ;
195
7acf6008 196}
7b7c1533 197
8d0f3f77 198//____________________________________________________________________________
199void AliPHOSSDigitizer::InitParameters()
200{
88cb7938 201 // initializes the parameters for digitization
8d0f3f77 202 fA = 0;
203 fB = 10000000.;
204 fPrimThreshold = 0.01 ;
205 fSDigitsInRun = 0 ;
8d0f3f77 206}
207
990119d6 208//____________________________________________________________________________
a4e98857 209void AliPHOSSDigitizer::Exec(Option_t *option)
210{
212d1c0f 211 // Steering method to produce summable digits for events
212 // in the range from fFirstEvent to fLastEvent.
213 // This range is optionally set by SetEventRange().
214 // if fLastEvent=-1 (by default), then process events until the end.
215 //
216 // Summable digit is a sum of all hits in the same active
217 // volume into digit
7b7c1533 218
219 if (strstr(option, "print") ) {
88cb7938 220 Print() ;
7b7c1533 221 return ;
222 }
990119d6 223
7acf6008 224 if(strstr(option,"tim"))
225 gBenchmark->Start("PHOSSDigitizer");
fbf811ec 226
9d6866ec 227 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
88cb7938 228
229 //switch off reloading of this task while getting event
230 if (!fInit) { // to prevent overwrite existing file
9d6866ec 231 AliError( Form("Give a version name different from %s", fEventFolderName.Data()) ) ;
88cb7938 232 return ;
233 }
234
212d1c0f 235 if (fLastEvent == -1)
236 fLastEvent = gime->MaxEvent() - 1 ;
237 else
d7d3b67b 238 fLastEvent = TMath::Min(fFirstEvent, gime->MaxEvent()); // only ine event at the time
212d1c0f 239 Int_t nEvents = fLastEvent - fFirstEvent + 1;
240
e3310962 241 Int_t ievent, i;
9d6866ec 242
243 //AliMemoryWatcher memwatcher;
244
245 for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
246 gime->Event(ievent,"H") ;
88cb7938 247 TTree * treeS = gime->TreeS();
248 TClonesArray * hits = gime->Hits() ;
249 TClonesArray * sdigits = gime->SDigits() ;
7b7c1533 250 sdigits->Clear();
990119d6 251 Int_t nSdigits = 0 ;
7b7c1533 252 //Now make SDigits from hits, for PHOS it is the same, so just copy
e3310962 253 for ( i = 0 ; i < hits->GetEntries() ; i++ ) {
254 AliPHOSHit * hit = dynamic_cast<AliPHOSHit *>(hits->At(i)) ;
255 // Assign primary number only if contribution is significant
256
257 if( hit->GetEnergy() > fPrimThreshold)
258 new((*sdigits)[nSdigits]) AliPHOSDigit(hit->GetPrimary(),hit->GetId(),
259 hit->GetEnergy() ,hit->GetTime()) ;
260 else
261 new((*sdigits)[nSdigits]) AliPHOSDigit(-1 ,hit->GetId(),
262 hit->GetEnergy() ,hit->GetTime()) ;
263 nSdigits++ ;
264
265 }
88cb7938 266
7b7c1533 267 sdigits->Sort() ;
88cb7938 268
7b7c1533 269 nSdigits = sdigits->GetEntriesFast() ;
88cb7938 270
69866bef 271 fSDigitsInRun += nSdigits ;
7b7c1533 272 sdigits->Expand(nSdigits) ;
88cb7938 273
990119d6 274 for (i = 0 ; i < nSdigits ; i++) {
7a9d98f9 275 AliPHOSDigit * digit = dynamic_cast<AliPHOSDigit *>(sdigits->At(i)) ;
990119d6 276 digit->SetIndexInList(i) ;
277 }
3962b6a1 278
ddd1a39c 279 // make Quality Assurance data
280
d76c31f4 281 GetQualAssDataMaker()->Exec(AliQualAss::kHITS, hits) ;
282 GetQualAssDataMaker()->Exec(AliQualAss::kSDIGITS, sdigits) ;
ddd1a39c 283
284
fbf811ec 285 //Now write SDigits
fbf811ec 286
88cb7938 287
7acf6008 288 //First list of sdigits
88cb7938 289
fbf811ec 290 Int_t bufferSize = 32000 ;
88cb7938 291 TBranch * sdigitsBranch = treeS->Branch("PHOS",&sdigits,bufferSize);
292
fbf811ec 293 sdigitsBranch->Fill() ;
fbf811ec 294
88cb7938 295 gime->WriteSDigits("OVERWRITE");
296
297 //Next - SDigitizer
298
299 gime->WriteSDigitizer("OVERWRITE");
9d6866ec 300 //gObjectTable->Print() ;
301
7acf6008 302 if(strstr(option,"deb"))
303 PrintSDigits(option) ;
9d6866ec 304
305 //memwatcher.Watch(ievent);
306 }// event loop
fbf811ec 307
ddd1a39c 308 //Write the quality assurance data
309 GetQualAssDataMaker()->Finish(AliQualAss::kHITS) ;
310 GetQualAssDataMaker()->Finish(AliQualAss::kSDIGITS) ;
311
88cb7938 312 Unload();
313
9d6866ec 314 // gime->PhosLoader()->GetSDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
88cb7938 315
7acf6008 316 if(strstr(option,"tim")){
317 gBenchmark->Stop("PHOSSDigitizer");
21cd0c07 318 Info("Exec"," took %f seconds for SDigitizing %f seconds per event",
212d1c0f 319 gBenchmark->GetCpuTime("PHOSSDigitizer"), gBenchmark->GetCpuTime("PHOSSDigitizer")/nEvents) ;
7acf6008 320 }
9d6866ec 321
322 //TFile f("out.root","RECREATE");
323 //memwatcher.WriteToFile();
324 //f.Close();
990119d6 325}
106fc2fa 326
990119d6 327//__________________________________________________________________
702ab87e 328void AliPHOSSDigitizer::Print(const Option_t *)const
a4e98857 329{
330 // Prints parameters of SDigitizer
88cb7938 331 Info("Print", "\n------------------- %s -------------", GetName() ) ;
332 printf(" Writing SDigits to branch with title %s\n", fEventFolderName.Data()) ;
333 printf(" with digitization parameters A = %f\n", fA) ;
334 printf(" B = %f\n", fB) ;
335 printf(" Threshold for Primary assignment= %f\n", fPrimThreshold) ;
336 printf("---------------------------------------------------\n") ;
7acf6008 337
990119d6 338}
548f0134 339
990119d6 340//__________________________________________________________________
a4e98857 341Bool_t AliPHOSSDigitizer::operator==( AliPHOSSDigitizer const &sd )const
342{
3de072dc 343 // Equal operator.
344 // SDititizers are equal if their pedestal, slope and threshold are equal
345
990119d6 346 if( (fA==sd.fA)&&(fB==sd.fB)&&(fPrimThreshold==sd.fPrimThreshold))
347 return kTRUE ;
348 else
349 return kFALSE ;
350}
548f0134 351
a6eedfad 352//__________________________________________________________________
a4e98857 353void AliPHOSSDigitizer::PrintSDigits(Option_t * option)
354{
355 // Prints list of digits produced in the current pass of AliPHOSDigitizer
7b7c1533 356
a6eedfad 357
88cb7938 358 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
359 const TClonesArray * sdigits = gime->SDigits() ;
21cd0c07 360
71dfb0d8 361 Info( "\nPrintSDigits", "event # %d %d sdigits", gAlice->GetEvNumber(), sdigits->GetEntriesFast() ) ;
362
a6eedfad 363 if(strstr(option,"all")||strstr(option,"EMC")){
7acf6008 364
365 //loop over digits
366 AliPHOSDigit * digit;
71dfb0d8 367 printf("\nEMC sdigits\n") ;
a6eedfad 368 Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
7acf6008 369 Int_t index ;
a6eedfad 370 for (index = 0 ; (index < sdigits->GetEntriesFast()) &&
fbf811ec 371 ((dynamic_cast<AliPHOSDigit *> (sdigits->At(index)))->GetId() <= maxEmc) ; index++) {
372 digit = dynamic_cast<AliPHOSDigit *>( sdigits->At(index) ) ;
71dfb0d8 373 // if(digit->GetNprimary() == 0)
374 // continue;
27a73a5d 375// printf("%6d %8d %6.5e %4d %2d :\n", // YVK
376 printf("%6d %.4f %6.5e %4d %2d :\n",
377 digit->GetId(), digit->GetEnergy(), digit->GetTime(), digit->GetIndexInList(), digit->GetNprimary()) ;
7acf6008 378 Int_t iprimary;
11f9c5ff 379 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
71dfb0d8 380 printf("%d ",digit->GetPrimary(iprimary+1) ) ;
11f9c5ff 381 }
a6eedfad 382 }
a6eedfad 383 }
384
385 if(strstr(option,"all")||strstr(option,"CPV")){
7acf6008 386
a6eedfad 387 //loop over CPV digits
388 AliPHOSDigit * digit;
71dfb0d8 389 printf("\nCPV sdigits\n") ;
a6eedfad 390 Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
391 Int_t index ;
392 for (index = 0 ; index < sdigits->GetEntriesFast(); index++) {
fbf811ec 393 digit = dynamic_cast<AliPHOSDigit *>( sdigits->At(index) ) ;
a6eedfad 394 if(digit->GetId() > maxEmc){
71dfb0d8 395 printf("\n%6d %8d %4d %2d :",
11f9c5ff 396 digit->GetId(), digit->GetAmp(), digit->GetIndexInList(), digit->GetNprimary()) ;
a6eedfad 397 Int_t iprimary;
21cd0c07 398 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
71dfb0d8 399 printf("%d ",digit->GetPrimary(iprimary+1) ) ;
21cd0c07 400 }
a6eedfad 401 }
402 }
7acf6008 403 }
404}
7b7c1533 405
406//____________________________________________________________________________
88cb7938 407void AliPHOSSDigitizer::Unload() const
7b7c1533 408{
e957fea8 409 // Unloads the objects from the folder
88cb7938 410 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
411 AliPHOSLoader * loader = gime->PhosLoader() ;
412 loader->UnloadHits() ;
413 loader->UnloadSDigits() ;
7b7c1533 414}