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