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