]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSSDigitizer.cxx
First step for rulechecker -- not working yet
[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 *
c65c502a 10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
990119d6 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$
04236e67 22 * Revision 1.56 2007/10/19 18:04:29 schutz
23 * The standalone QA data maker is called from AliSimulation and AliReconstruction outside the event loop; i.e. re-reading the data. The QA data making in the event loop has been commented out.
24 *
c65c502a 25 * Revision 1.55 2007/10/14 21:08:10 schutz
26 * Introduced the checking of QA results from previous step before entering the event loop
27 *
8661738e 28 * Revision 1.54 2007/10/10 09:05:10 schutz
29 * Changing name QualAss to QA
30 *
b8274834 31 * Revision 1.53 2007/09/30 17:08:20 schutz
32 * Introducing the notion of QA data acquisition cycle (needed by online)
33 *
5b188f2f 34 * Revision 1.52 2007/09/26 14:22:18 cvetan
35 * 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.
36 *
d76c31f4 37 * Revision 1.51 2007/08/07 14:12:03 kharlov
38 * Quality assurance added (Yves Schutz)
702ab87e 39 */
40
990119d6 41//_________________________________________________________________________
7acf6008 42// This is a TTask that makes SDigits out of Hits
7b7c1533 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
7acf6008 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".
f035f6ce 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:
a4e98857 57// root [0] AliPHOSSDigitizer * s = new AliPHOSSDigitizer("galice.root")
58// Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
59// root [1] s->ExecuteTask()
f035f6ce 60// // Makes SDigitis for all events stored in galice.root
a4e98857 61// root [2] s->SetPedestalParameter(0.001)
f035f6ce 62// // One can change parameters of digitization
3de072dc 63// root [3] s->SetSDigitsBranch("Pedestal 0.001")
f035f6ce 64// // and write them into the new branch
3de072dc 65// root [4] s->ExecuteTask("deb all tim")
f035f6ce 66// // available parameters:
67// deb - print # of produced SDigitis
68// deb all - print # and list of produced SDigits
69// tim - print benchmarking information
990119d6 70//
6c8cd883 71//-- Author : Dmitri Peressounko (SUBATECH & KI)
990119d6 72//////////////////////////////////////////////////////////////////////////////
73
f035f6ce 74
990119d6 75// --- ROOT system ---
7acf6008 76#include "TBenchmark.h"
106fc2fa 77
990119d6 78// --- Standard library ---
79
80// --- AliRoot header files ---
9d6866ec 81#include "AliLog.h"
e957fea8 82#include "AliPHOSGeometry.h"
990119d6 83#include "AliPHOSDigit.h"
bfae5a5d 84#include "AliPHOSLoader.h"
990119d6 85#include "AliPHOSHit.h"
990119d6 86#include "AliPHOSSDigitizer.h"
87
990119d6 88ClassImp(AliPHOSSDigitizer)
89
90
91//____________________________________________________________________________
3663622c 92AliPHOSSDigitizer::AliPHOSSDigitizer() :
93 TTask("",""),
3663622c 94 fPrimThreshold(0.f),
95 fDefaultInit(kTRUE),
96 fEventFolderName(""),
97 fInit(kFALSE),
98 fSDigitsInRun(0),
99 fFirstEvent(0),
c65c502a 100 fLastEvent(0)
548f0134 101{
990119d6 102 // ctor
ddd1a39c 103 // Intialize the quality assurance data maker
990119d6 104}
7acf6008 105
990119d6 106//____________________________________________________________________________
e191bb57 107AliPHOSSDigitizer::AliPHOSSDigitizer(const char * alirunFileName,
108 const char * eventFolderName):
109 TTask("PHOS"+AliConfig::Instance()->GetSDigitizerTaskName(), alirunFileName),
3663622c 110 fPrimThreshold(0.f),
111 fDefaultInit(kFALSE),
112 fEventFolderName(eventFolderName),
113 fInit(kFALSE),
114 fSDigitsInRun(0),
115 fFirstEvent(0),
c65c502a 116 fLastEvent(0)
990119d6 117{
118 // ctor
8d0f3f77 119 InitParameters() ;
2bd5457f 120 Init();
92f521a9 121 fDefaultInit = kFALSE ;
ddd1a39c 122}
123
124//____________________________________________________________________________
125AliPHOSSDigitizer::AliPHOSSDigitizer(const AliPHOSSDigitizer& sd) :
126 TTask(sd.GetName(), sd.GetTitle()),
ddd1a39c 127 fPrimThreshold(sd.fPrimThreshold),
128 fDefaultInit(kFALSE),
129 fEventFolderName(sd.fEventFolderName),
130 fInit(kFALSE),
131 fSDigitsInRun(sd.fSDigitsInRun),
132 fFirstEvent(sd.fFirstEvent),
c65c502a 133 fLastEvent(sd.fLastEvent)
ddd1a39c 134{
135 // cpy ctor
ddd1a39c 136}
137
ddd1a39c 138//_____________________________________________________________________________
139AliPHOSSDigitizer& AliPHOSSDigitizer::operator = (const AliPHOSSDigitizer& qa)
140{
141// assignment operator
142
143 this->~AliPHOSSDigitizer();
144 new(this) AliPHOSSDigitizer(qa);
145 return *this;
990119d6 146}
147
7acf6008 148//____________________________________________________________________________
797e311f 149AliPHOSSDigitizer::~AliPHOSSDigitizer() {
150 //dtor
bfae5a5d 151 AliRunLoader* rl = AliRunLoader::GetRunLoader(fEventFolderName) ;
152 if(rl){
153 AliPHOSLoader * phosLoader =
154 dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
6ba1dd81 155 if(phosLoader)
156 phosLoader->CleanSDigitizer() ;
bfae5a5d 157 }
797e311f 158}
ddd1a39c 159
797e311f 160//____________________________________________________________________________
a4e98857 161void AliPHOSSDigitizer::Init()
162{
bfae5a5d 163 // Uses the Loader to access the required files
7b7c1533 164
88cb7938 165 fInit = kTRUE ;
166
bfae5a5d 167 //to prevent cleaning of this object while GetEvent is called
168 AliRunLoader* rl = AliRunLoader::GetRunLoader(fEventFolderName) ;
169 if (!rl)
170 rl = AliRunLoader::Open(GetTitle(), fEventFolderName) ;
171
172 AliPHOSLoader * phosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
173 phosLoader->PostSDigitizer(this);
174 phosLoader->GetSDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
7acf6008 175}
7b7c1533 176
8d0f3f77 177//____________________________________________________________________________
178void AliPHOSSDigitizer::InitParameters()
179{
88cb7938 180 // initializes the parameters for digitization
8d0f3f77 181 fPrimThreshold = 0.01 ;
182 fSDigitsInRun = 0 ;
8d0f3f77 183}
184
990119d6 185//____________________________________________________________________________
a4e98857 186void AliPHOSSDigitizer::Exec(Option_t *option)
187{
212d1c0f 188 // Steering method to produce summable digits for events
189 // in the range from fFirstEvent to fLastEvent.
190 // This range is optionally set by SetEventRange().
191 // if fLastEvent=-1 (by default), then process events until the end.
192 //
193 // Summable digit is a sum of all hits in the same active
194 // volume into digit
7b7c1533 195
196 if (strstr(option, "print") ) {
88cb7938 197 Print() ;
7b7c1533 198 return ;
199 }
990119d6 200
7acf6008 201 if(strstr(option,"tim"))
202 gBenchmark->Start("PHOSSDigitizer");
fbf811ec 203
04236e67 204/*
205 // check the QA result for RAWS
4e25ac79 206 AliQAv1 * qa = AliQAv1::Instance(AliQAv1::kPHOS) ;
207 if ( qa->IsSet(AliQAv1::kPHOS, AliQAv1::kRAW, AliQAv1::kFATAL)) {
8661738e 208 AliFatal("QA status in RAW was Fatal") ;
4e25ac79 209 } else if ( qa->IsSet(AliQAv1::kPHOS, AliQAv1::kRAW, AliQAv1::kERROR)) {
8661738e 210 AliError("QA status in RAW was Error") ;
4e25ac79 211 } else if ( qa->IsSet(AliQAv1::kPHOS, AliQAv1::kRAW, AliQAv1::kWARNING) ) {
8661738e 212 AliWarning("QA status in RAW was Warning") ;
4e25ac79 213 } else if ( qa->IsSet(AliQAv1::kPHOS, AliQAv1::kRAW, AliQAv1::kINFO) ) {
8661738e 214 AliInfo("QA status in RAW was Info") ;
215 }
04236e67 216*/
bfae5a5d 217 AliRunLoader* rl = AliRunLoader::GetRunLoader(fEventFolderName) ;
218 AliPHOSLoader * phosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
88cb7938 219
825dc01a 220 if(!phosLoader)
221 AliFatal("phosLoader is null pointer!!") ;
222
88cb7938 223 //switch off reloading of this task while getting event
224 if (!fInit) { // to prevent overwrite existing file
9d6866ec 225 AliError( Form("Give a version name different from %s", fEventFolderName.Data()) ) ;
88cb7938 226 return ;
227 }
228
212d1c0f 229 if (fLastEvent == -1)
bfae5a5d 230 fLastEvent = rl->GetNumberOfEvents() - 1 ;
212d1c0f 231 else
bfae5a5d 232 fLastEvent = TMath::Min(fFirstEvent, rl->GetNumberOfEvents()); // only one event at the time
212d1c0f 233 Int_t nEvents = fLastEvent - fFirstEvent + 1;
234
e3310962 235 Int_t ievent, i;
9d6866ec 236
9d6866ec 237 for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
bfae5a5d 238 rl->GetEvent(ievent) ;
239 TTree * treeS = phosLoader->TreeS();
240 if(!treeS){
241 phosLoader->MakeTree("S");
242 treeS = phosLoader->TreeS();
243 }
244
245 phosLoader->CleanHits() ;
246 phosLoader->LoadHits("READ") ;
247
248 TClonesArray * hits = phosLoader->Hits() ;
249 TClonesArray * sdigits = phosLoader->SDigits() ;
250 if( !sdigits ) {
251 phosLoader->MakeSDigitsArray() ;
252 sdigits = phosLoader->SDigits() ;
253 }
7b7c1533 254 sdigits->Clear();
990119d6 255 Int_t nSdigits = 0 ;
bfae5a5d 256
7b7c1533 257 //Now make SDigits from hits, for PHOS it is the same, so just copy
e3310962 258 for ( i = 0 ; i < hits->GetEntries() ; i++ ) {
259 AliPHOSHit * hit = dynamic_cast<AliPHOSHit *>(hits->At(i)) ;
260 // Assign primary number only if contribution is significant
261
262 if( hit->GetEnergy() > fPrimThreshold)
263 new((*sdigits)[nSdigits]) AliPHOSDigit(hit->GetPrimary(),hit->GetId(),
264 hit->GetEnergy() ,hit->GetTime()) ;
265 else
266 new((*sdigits)[nSdigits]) AliPHOSDigit(-1 ,hit->GetId(),
267 hit->GetEnergy() ,hit->GetTime()) ;
268 nSdigits++ ;
269
270 }
88cb7938 271
7b7c1533 272 sdigits->Sort() ;
88cb7938 273
7b7c1533 274 nSdigits = sdigits->GetEntriesFast() ;
88cb7938 275
69866bef 276 fSDigitsInRun += nSdigits ;
7b7c1533 277 sdigits->Expand(nSdigits) ;
88cb7938 278
990119d6 279 for (i = 0 ; i < nSdigits ; i++) {
7a9d98f9 280 AliPHOSDigit * digit = dynamic_cast<AliPHOSDigit *>(sdigits->At(i)) ;
990119d6 281 digit->SetIndexInList(i) ;
282 }
3962b6a1 283
c65c502a 284// // make Quality Assurance data
285//
286// if (GetQADataMaker()->IsCycleDone() ) {
4e25ac79 287// GetQADataMaker()->EndOfCycle(AliQAv1::kHITS) ;
288// GetQADataMaker()->EndOfCycle(AliQAv1::kSDIGITS) ;
289// GetQADataMaker()->StartOfCycle(AliQAv1::kHITS) ;
290// GetQADataMaker()->StartOfCycle(AliQAv1::kSDIGITS, kTRUE) ;
c65c502a 291// }
4e25ac79 292// GetQADataMaker()->Exec(AliQAv1::kHITS, hits) ;
293// GetQADataMaker()->Exec(AliQAv1::kSDIGITS, sdigits) ;
c65c502a 294// GetQADataMaker()->Increment() ;
5b188f2f 295
fbf811ec 296 //Now write SDigits
fbf811ec 297
88cb7938 298
7acf6008 299 //First list of sdigits
88cb7938 300
fbf811ec 301 Int_t bufferSize = 32000 ;
88cb7938 302 TBranch * sdigitsBranch = treeS->Branch("PHOS",&sdigits,bufferSize);
fbf811ec 303 sdigitsBranch->Fill() ;
fbf811ec 304
bfae5a5d 305 phosLoader->WriteSDigits("OVERWRITE");
306 phosLoader->WriteSDigitizer("OVERWRITE");
88cb7938 307
7acf6008 308 if(strstr(option,"deb"))
309 PrintSDigits(option) ;
9d6866ec 310
9d6866ec 311 }// event loop
fbf811ec 312
c65c502a 313// //Write the quality assurance data
4e25ac79 314// GetQADataMaker()->EndOfCycle(AliQAv1::kHITS) ;
315// GetQADataMaker()->EndOfCycle(AliQAv1::kSDIGITS) ;
c65c502a 316// GetQADataMaker()->Finish() ;
ddd1a39c 317
88cb7938 318 Unload();
319
7acf6008 320 if(strstr(option,"tim")){
321 gBenchmark->Stop("PHOSSDigitizer");
21cd0c07 322 Info("Exec"," took %f seconds for SDigitizing %f seconds per event",
bfae5a5d 323 gBenchmark->GetCpuTime("PHOSSDigitizer"),
324 gBenchmark->GetCpuTime("PHOSSDigitizer")/nEvents) ;
7acf6008 325 }
9d6866ec 326
990119d6 327}
106fc2fa 328
990119d6 329//__________________________________________________________________
702ab87e 330void AliPHOSSDigitizer::Print(const Option_t *)const
a4e98857 331{
332 // Prints parameters of SDigitizer
88cb7938 333 Info("Print", "\n------------------- %s -------------", GetName() ) ;
334 printf(" Writing SDigits to branch with title %s\n", fEventFolderName.Data()) ;
88cb7938 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
f898e0f3 346 if(fPrimThreshold==sd.fPrimThreshold)
990119d6 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
bfae5a5d 357 AliRunLoader* rl = AliRunLoader::GetRunLoader(fEventFolderName) ;
358 AliPHOSLoader * phosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
6c8cd883 359
360 // Get PHOS Geometry object
361 AliPHOSGeometry *geom;
362 if (!(geom = AliPHOSGeometry::GetInstance()))
363 geom = AliPHOSGeometry::GetInstance("IHEP","");
364
bfae5a5d 365 const TClonesArray * sdigits = phosLoader->SDigits() ;
21cd0c07 366
bfae5a5d 367 Info( "\nPrintSDigits", "event # %d %d sdigits",
368 gAlice->GetEvNumber(), sdigits->GetEntriesFast() ) ;
71dfb0d8 369
a6eedfad 370 if(strstr(option,"all")||strstr(option,"EMC")){
7acf6008 371
372 //loop over digits
373 AliPHOSDigit * digit;
71dfb0d8 374 printf("\nEMC sdigits\n") ;
6c8cd883 375 Int_t maxEmc = geom->GetNModules() * geom->GetNCristalsInModule() ;
7acf6008 376 Int_t index ;
a6eedfad 377 for (index = 0 ; (index < sdigits->GetEntriesFast()) &&
fbf811ec 378 ((dynamic_cast<AliPHOSDigit *> (sdigits->At(index)))->GetId() <= maxEmc) ; index++) {
379 digit = dynamic_cast<AliPHOSDigit *>( sdigits->At(index) ) ;
71dfb0d8 380 // if(digit->GetNprimary() == 0)
381 // continue;
27a73a5d 382// printf("%6d %8d %6.5e %4d %2d :\n", // YVK
383 printf("%6d %.4f %6.5e %4d %2d :\n",
384 digit->GetId(), digit->GetEnergy(), digit->GetTime(), digit->GetIndexInList(), digit->GetNprimary()) ;
7acf6008 385 Int_t iprimary;
11f9c5ff 386 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
71dfb0d8 387 printf("%d ",digit->GetPrimary(iprimary+1) ) ;
11f9c5ff 388 }
a6eedfad 389 }
a6eedfad 390 }
391
392 if(strstr(option,"all")||strstr(option,"CPV")){
7acf6008 393
a6eedfad 394 //loop over CPV digits
395 AliPHOSDigit * digit;
71dfb0d8 396 printf("\nCPV sdigits\n") ;
6c8cd883 397 Int_t maxEmc = geom->GetNModules() * geom->GetNCristalsInModule() ;
a6eedfad 398 Int_t index ;
399 for (index = 0 ; index < sdigits->GetEntriesFast(); index++) {
fbf811ec 400 digit = dynamic_cast<AliPHOSDigit *>( sdigits->At(index) ) ;
a6eedfad 401 if(digit->GetId() > maxEmc){
71dfb0d8 402 printf("\n%6d %8d %4d %2d :",
11f9c5ff 403 digit->GetId(), digit->GetAmp(), digit->GetIndexInList(), digit->GetNprimary()) ;
a6eedfad 404 Int_t iprimary;
21cd0c07 405 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
71dfb0d8 406 printf("%d ",digit->GetPrimary(iprimary+1) ) ;
21cd0c07 407 }
a6eedfad 408 }
409 }
7acf6008 410 }
411}
7b7c1533 412
413//____________________________________________________________________________
88cb7938 414void AliPHOSSDigitizer::Unload() const
7b7c1533 415{
e957fea8 416 // Unloads the objects from the folder
bfae5a5d 417 AliRunLoader* rl = AliRunLoader::GetRunLoader(fEventFolderName) ;
418 AliPHOSLoader * phosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
419 phosLoader->UnloadHits() ;
420 phosLoader->UnloadSDigits() ;
7b7c1533 421}