]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSSDigitizer.cxx
Printing the energy summary only in debug mode
[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
19//_________________________________________________________________________
7acf6008 20// This is a TTask that makes SDigits out of Hits
7b7c1533 21// The name of the TTask is also the title of the branch that will contain
22// the created SDigits
23// The title of the TTAsk is the name of the file that contains the hits from
24// which the SDigits are created
7acf6008 25// A Summable Digits is the sum of all hits originating
26// from one primary in one active cell
27// A threshold for assignment of the primary to SDigit is applied
28// SDigits are written to TreeS, branch "PHOS"
29// AliPHOSSDigitizer with all current parameters is written
30// to TreeS branch "AliPHOSSDigitizer".
f035f6ce 31// Both branches have the same title. If necessary one can produce
32// another set of SDigits with different parameters. Two versions
33// can be distunguished using titles of the branches.
34// User case:
a4e98857 35// root [0] AliPHOSSDigitizer * s = new AliPHOSSDigitizer("galice.root")
36// Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
37// root [1] s->ExecuteTask()
f035f6ce 38// // Makes SDigitis for all events stored in galice.root
a4e98857 39// root [2] s->SetPedestalParameter(0.001)
f035f6ce 40// // One can change parameters of digitization
3de072dc 41// root [3] s->SetSDigitsBranch("Pedestal 0.001")
f035f6ce 42// // and write them into the new branch
3de072dc 43// root [4] s->ExecuteTask("deb all tim")
f035f6ce 44// // available parameters:
45// deb - print # of produced SDigitis
46// deb all - print # and list of produced SDigits
47// tim - print benchmarking information
990119d6 48//
49//*-- Author : Dmitri Peressounko (SUBATECH & KI)
50//////////////////////////////////////////////////////////////////////////////
51
f035f6ce 52
990119d6 53// --- ROOT system ---
7acf6008 54#include "TBenchmark.h"
e957fea8 55#include "TRandom.h"
106fc2fa 56
990119d6 57// --- Standard library ---
58
59// --- AliRoot header files ---
e957fea8 60#include "AliPHOSGeometry.h"
990119d6 61#include "AliPHOSDigit.h"
7b7c1533 62#include "AliPHOSGetter.h"
990119d6 63#include "AliPHOSHit.h"
990119d6 64#include "AliPHOSSDigitizer.h"
65
990119d6 66ClassImp(AliPHOSSDigitizer)
67
68
69//____________________________________________________________________________
88cb7938 70 AliPHOSSDigitizer::AliPHOSSDigitizer():TTask("","")
548f0134 71{
990119d6 72 // ctor
92f521a9 73 InitParameters() ;
74 fDefaultInit = kTRUE ;
990119d6 75}
7acf6008 76
990119d6 77//____________________________________________________________________________
88cb7938 78AliPHOSSDigitizer::AliPHOSSDigitizer(const char * alirunFileName, const char * eventFolderName):
79 TTask("PHOS"+AliConfig::fgkSDigitizerTaskName, alirunFileName),
80 fEventFolderName(eventFolderName)
990119d6 81{
88cb7938 82
990119d6 83 // ctor
8d0f3f77 84 InitParameters() ;
2bd5457f 85 Init();
92f521a9 86 fDefaultInit = kFALSE ;
990119d6 87}
88
bdc147a9 89//____________________________________________________________________________
a8c47ab6 90AliPHOSSDigitizer::AliPHOSSDigitizer(const AliPHOSSDigitizer & sd)
91 : TTask(sd)
92{
bdc147a9 93 //cpy ctor
94
95 fA = sd.fA ;
96 fB = sd.fB ;
97 fPrimThreshold = sd.fPrimThreshold ;
98 fSDigitsInRun = sd.fSDigitsInRun ;
88cb7938 99 SetName(sd.GetName()) ;
100 SetTitle(sd.GetTitle()) ;
101 fEventFolderName = sd.fEventFolderName;
bdc147a9 102}
103
7b7c1533 104
7acf6008 105//____________________________________________________________________________
797e311f 106AliPHOSSDigitizer::~AliPHOSSDigitizer() {
107 //dtor
108 AliPHOSGetter * gime =
109 AliPHOSGetter::Instance(GetTitle(),fEventFolderName.Data());
110 gime->PhosLoader()->CleanSDigitizer();
111}
112//____________________________________________________________________________
a4e98857 113void AliPHOSSDigitizer::Init()
114{
88cb7938 115 // Uses the getter to access the required files
7b7c1533 116
88cb7938 117 fInit = kTRUE ;
118
119 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName.Data());
7b7c1533 120 if ( gime == 0 ) {
88cb7938 121 Fatal("Init" ,"Could not obtain the Getter object for file %s and event %s !", GetTitle(), fEventFolderName.Data()) ;
7b7c1533 122 return ;
123 }
124
88cb7938 125 TString opt("SDigits") ;
126 if(gime->VersionExists(opt) ) {
127 Error( "Init", "Give a version name different from %s", fEventFolderName.Data() ) ;
128 fInit = kFALSE ;
fbf811ec 129 }
130
88cb7938 131 gime->PostSDigitizer(this);
132 gime->PhosLoader()->GetSDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
133
7acf6008 134}
7b7c1533 135
8d0f3f77 136//____________________________________________________________________________
137void AliPHOSSDigitizer::InitParameters()
138{
88cb7938 139 // initializes the parameters for digitization
8d0f3f77 140 fA = 0;
141 fB = 10000000.;
142 fPrimThreshold = 0.01 ;
143 fSDigitsInRun = 0 ;
8d0f3f77 144}
145
990119d6 146//____________________________________________________________________________
a4e98857 147void AliPHOSSDigitizer::Exec(Option_t *option)
148{
149 // Collects all hits in the same active volume into digit
7b7c1533 150
151 if (strstr(option, "print") ) {
88cb7938 152 Print() ;
7b7c1533 153 return ;
154 }
990119d6 155
7acf6008 156 if(strstr(option,"tim"))
157 gBenchmark->Start("PHOSSDigitizer");
fbf811ec 158
88cb7938 159 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
160
161 //switch off reloading of this task while getting event
162 if (!fInit) { // to prevent overwrite existing file
163 Error( "Exec", "Give a version name different from %s", fEventFolderName.Data() ) ;
164 return ;
165 }
166
167
fbf811ec 168 Int_t nevents = gime->MaxEvent() ;
990119d6 169 Int_t ievent ;
7b7c1533 170 for(ievent = 0; ievent < nevents; ievent++){
88cb7938 171
5ad40cd6 172 gime->Event(ievent,"H") ;
88cb7938 173
174 TTree * treeS = gime->TreeS();
175 TClonesArray * hits = gime->Hits() ;
176 TClonesArray * sdigits = gime->SDigits() ;
7b7c1533 177 sdigits->Clear();
990119d6 178 Int_t nSdigits = 0 ;
7b7c1533 179 //Now make SDigits from hits, for PHOS it is the same, so just copy
88cb7938 180 Int_t nPrim = static_cast<Int_t>((gime->TreeH())->GetEntries()) ;
fbf811ec 181 // Attention nPrim is the number of primaries tracked by Geant
182 // and this number could be different to the number of Primaries in TreeK;
183 Int_t iprim ;
88cb7938 184
fbf811ec 185 for (iprim = 0 ; iprim < nPrim ; iprim ++) {
3962b6a1 186 //=========== Get the PHOS branch from Hits Tree for the Primary iprim
187 gime->Track(iprim) ;
990119d6 188 Int_t i;
7b7c1533 189 for ( i = 0 ; i < hits->GetEntries() ; i++ ) {
7a9d98f9 190 AliPHOSHit * hit = dynamic_cast<AliPHOSHit *>(hits->At(i)) ;
990119d6 191 // Assign primary number only if contribution is significant
9688c1dd 192
990119d6 193 if( hit->GetEnergy() > fPrimThreshold)
9688c1dd 194 new((*sdigits)[nSdigits]) AliPHOSDigit(hit->GetPrimary(),hit->GetId(),
fbf811ec 195 Digitize(hit->GetEnergy()), hit->GetTime()) ;
990119d6 196 else
9688c1dd 197 new((*sdigits)[nSdigits]) AliPHOSDigit( -1 , hit->GetId(),
fbf811ec 198 Digitize(hit->GetEnergy()), hit->GetTime()) ;
9688c1dd 199 nSdigits++ ;
990119d6 200
9688c1dd 201 }
88cb7938 202
3962b6a1 203 } // loop over iprim
88cb7938 204
7b7c1533 205 sdigits->Sort() ;
88cb7938 206
7b7c1533 207 nSdigits = sdigits->GetEntriesFast() ;
88cb7938 208
69866bef 209 fSDigitsInRun += nSdigits ;
7b7c1533 210 sdigits->Expand(nSdigits) ;
88cb7938 211
3962b6a1 212 Int_t i ;
990119d6 213 for (i = 0 ; i < nSdigits ; i++) {
7a9d98f9 214 AliPHOSDigit * digit = dynamic_cast<AliPHOSDigit *>(sdigits->At(i)) ;
990119d6 215 digit->SetIndexInList(i) ;
216 }
3962b6a1 217
fbf811ec 218 //Now write SDigits
fbf811ec 219
88cb7938 220
7acf6008 221 //First list of sdigits
88cb7938 222
fbf811ec 223 Int_t bufferSize = 32000 ;
88cb7938 224 TBranch * sdigitsBranch = treeS->Branch("PHOS",&sdigits,bufferSize);
225
fbf811ec 226 sdigitsBranch->Fill() ;
fbf811ec 227
88cb7938 228 gime->WriteSDigits("OVERWRITE");
229
230 //Next - SDigitizer
231
232 gime->WriteSDigitizer("OVERWRITE");
233
7acf6008 234 if(strstr(option,"deb"))
235 PrintSDigits(option) ;
990119d6 236 }
fbf811ec 237
88cb7938 238 Unload();
239
240 gime->PhosLoader()->GetSDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
241
7acf6008 242 if(strstr(option,"tim")){
243 gBenchmark->Stop("PHOSSDigitizer");
21cd0c07 244 Info("Exec"," took %f seconds for SDigitizing %f seconds per event",
245 gBenchmark->GetCpuTime("PHOSSDigitizer"), gBenchmark->GetCpuTime("PHOSSDigitizer")/nevents) ;
7acf6008 246 }
990119d6 247}
106fc2fa 248
990119d6 249//__________________________________________________________________
88cb7938 250void AliPHOSSDigitizer::Print()const
a4e98857 251{
252 // Prints parameters of SDigitizer
88cb7938 253 Info("Print", "\n------------------- %s -------------", GetName() ) ;
254 printf(" Writing SDigits to branch with title %s\n", fEventFolderName.Data()) ;
255 printf(" with digitization parameters A = %f\n", fA) ;
256 printf(" B = %f\n", fB) ;
257 printf(" Threshold for Primary assignment= %f\n", fPrimThreshold) ;
258 printf("---------------------------------------------------\n") ;
7acf6008 259
990119d6 260}
548f0134 261
990119d6 262//__________________________________________________________________
a4e98857 263Bool_t AliPHOSSDigitizer::operator==( AliPHOSSDigitizer const &sd )const
264{
3de072dc 265 // Equal operator.
266 // SDititizers are equal if their pedestal, slope and threshold are equal
267
990119d6 268 if( (fA==sd.fA)&&(fB==sd.fB)&&(fPrimThreshold==sd.fPrimThreshold))
269 return kTRUE ;
270 else
271 return kFALSE ;
272}
548f0134 273
a6eedfad 274//__________________________________________________________________
a4e98857 275void AliPHOSSDigitizer::PrintSDigits(Option_t * option)
276{
277 // Prints list of digits produced in the current pass of AliPHOSDigitizer
7b7c1533 278
a6eedfad 279
88cb7938 280 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
281 const TClonesArray * sdigits = gime->SDigits() ;
21cd0c07 282
71dfb0d8 283 Info( "\nPrintSDigits", "event # %d %d sdigits", gAlice->GetEvNumber(), sdigits->GetEntriesFast() ) ;
284
a6eedfad 285 if(strstr(option,"all")||strstr(option,"EMC")){
7acf6008 286
287 //loop over digits
288 AliPHOSDigit * digit;
71dfb0d8 289 printf("\nEMC sdigits\n") ;
a6eedfad 290 Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
7acf6008 291 Int_t index ;
a6eedfad 292 for (index = 0 ; (index < sdigits->GetEntriesFast()) &&
fbf811ec 293 ((dynamic_cast<AliPHOSDigit *> (sdigits->At(index)))->GetId() <= maxEmc) ; index++) {
294 digit = dynamic_cast<AliPHOSDigit *>( sdigits->At(index) ) ;
71dfb0d8 295 // if(digit->GetNprimary() == 0)
296 // continue;
297 printf("%6d %8d %6.5e %4d %2d :",
298 digit->GetId(), digit->GetAmp(), digit->GetTime(), digit->GetIndexInList(), digit->GetNprimary()) ;
7acf6008 299 Int_t iprimary;
11f9c5ff 300 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
71dfb0d8 301 printf("%d ",digit->GetPrimary(iprimary+1) ) ;
11f9c5ff 302 }
a6eedfad 303 }
a6eedfad 304 }
305
306 if(strstr(option,"all")||strstr(option,"CPV")){
7acf6008 307
a6eedfad 308 //loop over CPV digits
309 AliPHOSDigit * digit;
71dfb0d8 310 printf("\nCPV sdigits\n") ;
a6eedfad 311 Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
312 Int_t index ;
313 for (index = 0 ; index < sdigits->GetEntriesFast(); index++) {
fbf811ec 314 digit = dynamic_cast<AliPHOSDigit *>( sdigits->At(index) ) ;
a6eedfad 315 if(digit->GetId() > maxEmc){
71dfb0d8 316 printf("\n%6d %8d %4d %2d :",
11f9c5ff 317 digit->GetId(), digit->GetAmp(), digit->GetIndexInList(), digit->GetNprimary()) ;
a6eedfad 318 Int_t iprimary;
21cd0c07 319 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
71dfb0d8 320 printf("%d ",digit->GetPrimary(iprimary+1) ) ;
21cd0c07 321 }
a6eedfad 322 }
323 }
7acf6008 324 }
325}
7b7c1533 326
327//____________________________________________________________________________
88cb7938 328void AliPHOSSDigitizer::Unload() const
7b7c1533 329{
e957fea8 330 // Unloads the objects from the folder
88cb7938 331 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
332 AliPHOSLoader * loader = gime->PhosLoader() ;
333 loader->UnloadHits() ;
334 loader->UnloadSDigits() ;
7b7c1533 335}