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