Do not call InitParameters in the default ctor
[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
d7d3b67b 73 fFirstEvent = fLastEvent = 0 ;
92f521a9 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
d7d3b67b 84 fFirstEvent = fLastEvent = 0 ; // runs one event by defaut
8d0f3f77 85 InitParameters() ;
2bd5457f 86 Init();
92f521a9 87 fDefaultInit = kFALSE ;
990119d6 88}
89
c093f031 90//____________________________________________________________________________
a8c47ab6 91AliPHOSSDigitizer::AliPHOSSDigitizer(const AliPHOSSDigitizer & sd)
92 : TTask(sd)
93{
bdc147a9 94 //cpy ctor
95
d7d3b67b 96 fFirstEvent = sd.fFirstEvent ;
97 fLastEvent = sd.fLastEvent ;
bdc147a9 98 fA = sd.fA ;
99 fB = sd.fB ;
100 fPrimThreshold = sd.fPrimThreshold ;
101 fSDigitsInRun = sd.fSDigitsInRun ;
88cb7938 102 SetName(sd.GetName()) ;
103 SetTitle(sd.GetTitle()) ;
104 fEventFolderName = sd.fEventFolderName;
bdc147a9 105}
106
7b7c1533 107
7acf6008 108//____________________________________________________________________________
797e311f 109AliPHOSSDigitizer::~AliPHOSSDigitizer() {
110 //dtor
111 AliPHOSGetter * gime =
112 AliPHOSGetter::Instance(GetTitle(),fEventFolderName.Data());
113 gime->PhosLoader()->CleanSDigitizer();
114}
115//____________________________________________________________________________
a4e98857 116void AliPHOSSDigitizer::Init()
117{
88cb7938 118 // Uses the getter to access the required files
7b7c1533 119
88cb7938 120 fInit = kTRUE ;
121
122 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName.Data());
7b7c1533 123 if ( gime == 0 ) {
88cb7938 124 Fatal("Init" ,"Could not obtain the Getter object for file %s and event %s !", GetTitle(), fEventFolderName.Data()) ;
7b7c1533 125 return ;
126 }
127
88cb7938 128 TString opt("SDigits") ;
129 if(gime->VersionExists(opt) ) {
130 Error( "Init", "Give a version name different from %s", fEventFolderName.Data() ) ;
131 fInit = kFALSE ;
fbf811ec 132 }
133
88cb7938 134 gime->PostSDigitizer(this);
135 gime->PhosLoader()->GetSDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
136
7acf6008 137}
7b7c1533 138
8d0f3f77 139//____________________________________________________________________________
140void AliPHOSSDigitizer::InitParameters()
141{
88cb7938 142 // initializes the parameters for digitization
8d0f3f77 143 fA = 0;
144 fB = 10000000.;
145 fPrimThreshold = 0.01 ;
146 fSDigitsInRun = 0 ;
8d0f3f77 147}
148
990119d6 149//____________________________________________________________________________
a4e98857 150void AliPHOSSDigitizer::Exec(Option_t *option)
151{
212d1c0f 152 // Steering method to produce summable digits for events
153 // in the range from fFirstEvent to fLastEvent.
154 // This range is optionally set by SetEventRange().
155 // if fLastEvent=-1 (by default), then process events until the end.
156 //
157 // Summable digit is a sum of all hits in the same active
158 // volume into digit
7b7c1533 159
160 if (strstr(option, "print") ) {
88cb7938 161 Print() ;
7b7c1533 162 return ;
163 }
990119d6 164
7acf6008 165 if(strstr(option,"tim"))
166 gBenchmark->Start("PHOSSDigitizer");
fbf811ec 167
d7d3b67b 168 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle()) ;
88cb7938 169
170 //switch off reloading of this task while getting event
171 if (!fInit) { // to prevent overwrite existing file
172 Error( "Exec", "Give a version name different from %s", fEventFolderName.Data() ) ;
173 return ;
174 }
175
212d1c0f 176 if (fLastEvent == -1)
177 fLastEvent = gime->MaxEvent() - 1 ;
178 else
d7d3b67b 179 fLastEvent = TMath::Min(fFirstEvent, gime->MaxEvent()); // only ine event at the time
212d1c0f 180 Int_t nEvents = fLastEvent - fFirstEvent + 1;
181
990119d6 182 Int_t ievent ;
212d1c0f 183 for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
5ad40cd6 184 gime->Event(ievent,"H") ;
88cb7938 185 TTree * treeS = gime->TreeS();
186 TClonesArray * hits = gime->Hits() ;
187 TClonesArray * sdigits = gime->SDigits() ;
7b7c1533 188 sdigits->Clear();
990119d6 189 Int_t nSdigits = 0 ;
7b7c1533 190 //Now make SDigits from hits, for PHOS it is the same, so just copy
88cb7938 191 Int_t nPrim = static_cast<Int_t>((gime->TreeH())->GetEntries()) ;
fbf811ec 192 // Attention nPrim is the number of primaries tracked by Geant
193 // and this number could be different to the number of Primaries in TreeK;
194 Int_t iprim ;
88cb7938 195
fbf811ec 196 for (iprim = 0 ; iprim < nPrim ; iprim ++) {
3962b6a1 197 //=========== Get the PHOS branch from Hits Tree for the Primary iprim
198 gime->Track(iprim) ;
990119d6 199 Int_t i;
7b7c1533 200 for ( i = 0 ; i < hits->GetEntries() ; i++ ) {
7a9d98f9 201 AliPHOSHit * hit = dynamic_cast<AliPHOSHit *>(hits->At(i)) ;
990119d6 202 // Assign primary number only if contribution is significant
9688c1dd 203
990119d6 204 if( hit->GetEnergy() > fPrimThreshold)
9688c1dd 205 new((*sdigits)[nSdigits]) AliPHOSDigit(hit->GetPrimary(),hit->GetId(),
fbf811ec 206 Digitize(hit->GetEnergy()), hit->GetTime()) ;
990119d6 207 else
9688c1dd 208 new((*sdigits)[nSdigits]) AliPHOSDigit( -1 , hit->GetId(),
fbf811ec 209 Digitize(hit->GetEnergy()), hit->GetTime()) ;
9688c1dd 210 nSdigits++ ;
990119d6 211
9688c1dd 212 }
88cb7938 213
3962b6a1 214 } // loop over iprim
88cb7938 215
7b7c1533 216 sdigits->Sort() ;
88cb7938 217
7b7c1533 218 nSdigits = sdigits->GetEntriesFast() ;
88cb7938 219
69866bef 220 fSDigitsInRun += nSdigits ;
7b7c1533 221 sdigits->Expand(nSdigits) ;
88cb7938 222
3962b6a1 223 Int_t i ;
990119d6 224 for (i = 0 ; i < nSdigits ; i++) {
7a9d98f9 225 AliPHOSDigit * digit = dynamic_cast<AliPHOSDigit *>(sdigits->At(i)) ;
990119d6 226 digit->SetIndexInList(i) ;
227 }
3962b6a1 228
fbf811ec 229 //Now write SDigits
fbf811ec 230
88cb7938 231
7acf6008 232 //First list of sdigits
88cb7938 233
fbf811ec 234 Int_t bufferSize = 32000 ;
88cb7938 235 TBranch * sdigitsBranch = treeS->Branch("PHOS",&sdigits,bufferSize);
236
fbf811ec 237 sdigitsBranch->Fill() ;
fbf811ec 238
88cb7938 239 gime->WriteSDigits("OVERWRITE");
240
241 //Next - SDigitizer
242
243 gime->WriteSDigitizer("OVERWRITE");
244
7acf6008 245 if(strstr(option,"deb"))
246 PrintSDigits(option) ;
990119d6 247 }
fbf811ec 248
88cb7938 249 Unload();
250
251 gime->PhosLoader()->GetSDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
252
7acf6008 253 if(strstr(option,"tim")){
254 gBenchmark->Stop("PHOSSDigitizer");
21cd0c07 255 Info("Exec"," took %f seconds for SDigitizing %f seconds per event",
212d1c0f 256 gBenchmark->GetCpuTime("PHOSSDigitizer"), gBenchmark->GetCpuTime("PHOSSDigitizer")/nEvents) ;
7acf6008 257 }
990119d6 258}
106fc2fa 259
990119d6 260//__________________________________________________________________
88cb7938 261void AliPHOSSDigitizer::Print()const
a4e98857 262{
263 // Prints parameters of SDigitizer
88cb7938 264 Info("Print", "\n------------------- %s -------------", GetName() ) ;
265 printf(" Writing SDigits to branch with title %s\n", fEventFolderName.Data()) ;
266 printf(" with digitization parameters A = %f\n", fA) ;
267 printf(" B = %f\n", fB) ;
268 printf(" Threshold for Primary assignment= %f\n", fPrimThreshold) ;
269 printf("---------------------------------------------------\n") ;
7acf6008 270
990119d6 271}
548f0134 272
990119d6 273//__________________________________________________________________
a4e98857 274Bool_t AliPHOSSDigitizer::operator==( AliPHOSSDigitizer const &sd )const
275{
3de072dc 276 // Equal operator.
277 // SDititizers are equal if their pedestal, slope and threshold are equal
278
990119d6 279 if( (fA==sd.fA)&&(fB==sd.fB)&&(fPrimThreshold==sd.fPrimThreshold))
280 return kTRUE ;
281 else
282 return kFALSE ;
283}
548f0134 284
a6eedfad 285//__________________________________________________________________
a4e98857 286void AliPHOSSDigitizer::PrintSDigits(Option_t * option)
287{
288 // Prints list of digits produced in the current pass of AliPHOSDigitizer
7b7c1533 289
a6eedfad 290
88cb7938 291 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
292 const TClonesArray * sdigits = gime->SDigits() ;
21cd0c07 293
71dfb0d8 294 Info( "\nPrintSDigits", "event # %d %d sdigits", gAlice->GetEvNumber(), sdigits->GetEntriesFast() ) ;
295
a6eedfad 296 if(strstr(option,"all")||strstr(option,"EMC")){
7acf6008 297
298 //loop over digits
299 AliPHOSDigit * digit;
71dfb0d8 300 printf("\nEMC sdigits\n") ;
a6eedfad 301 Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
7acf6008 302 Int_t index ;
a6eedfad 303 for (index = 0 ; (index < sdigits->GetEntriesFast()) &&
fbf811ec 304 ((dynamic_cast<AliPHOSDigit *> (sdigits->At(index)))->GetId() <= maxEmc) ; index++) {
305 digit = dynamic_cast<AliPHOSDigit *>( sdigits->At(index) ) ;
71dfb0d8 306 // if(digit->GetNprimary() == 0)
307 // continue;
d7d3b67b 308 printf("%6d %8d %6.5e %4d %2d :\n",
71dfb0d8 309 digit->GetId(), digit->GetAmp(), digit->GetTime(), digit->GetIndexInList(), digit->GetNprimary()) ;
7acf6008 310 Int_t iprimary;
11f9c5ff 311 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
71dfb0d8 312 printf("%d ",digit->GetPrimary(iprimary+1) ) ;
11f9c5ff 313 }
a6eedfad 314 }
a6eedfad 315 }
316
317 if(strstr(option,"all")||strstr(option,"CPV")){
7acf6008 318
a6eedfad 319 //loop over CPV digits
320 AliPHOSDigit * digit;
71dfb0d8 321 printf("\nCPV sdigits\n") ;
a6eedfad 322 Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
323 Int_t index ;
324 for (index = 0 ; index < sdigits->GetEntriesFast(); index++) {
fbf811ec 325 digit = dynamic_cast<AliPHOSDigit *>( sdigits->At(index) ) ;
a6eedfad 326 if(digit->GetId() > maxEmc){
71dfb0d8 327 printf("\n%6d %8d %4d %2d :",
11f9c5ff 328 digit->GetId(), digit->GetAmp(), digit->GetIndexInList(), digit->GetNprimary()) ;
a6eedfad 329 Int_t iprimary;
21cd0c07 330 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
71dfb0d8 331 printf("%d ",digit->GetPrimary(iprimary+1) ) ;
21cd0c07 332 }
a6eedfad 333 }
334 }
7acf6008 335 }
336}
7b7c1533 337
338//____________________________________________________________________________
88cb7938 339void AliPHOSSDigitizer::Unload() const
7b7c1533 340{
e957fea8 341 // Unloads the objects from the folder
88cb7938 342 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
343 AliPHOSLoader * loader = gime->PhosLoader() ;
344 loader->UnloadHits() ;
345 loader->UnloadSDigits() ;
7b7c1533 346}