]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSSDigitizer.cxx
Cosmetics
[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
16/* $Id$ */
17
18//_________________________________________________________________________
7acf6008 19// This is a TTask that makes SDigits out of Hits
7b7c1533 20// The name of the TTask is also the title of the branch that will contain
21// the created SDigits
22// The title of the TTAsk is the name of the file that contains the hits from
23// which the SDigits are created
7acf6008 24// A Summable Digits is the sum of all hits originating
25// from one primary in one active cell
26// A threshold for assignment of the primary to SDigit is applied
27// SDigits are written to TreeS, branch "PHOS"
28// AliPHOSSDigitizer with all current parameters is written
29// to TreeS branch "AliPHOSSDigitizer".
f035f6ce 30// Both branches have the same title. If necessary one can produce
31// another set of SDigits with different parameters. Two versions
32// can be distunguished using titles of the branches.
33// User case:
a4e98857 34// root [0] AliPHOSSDigitizer * s = new AliPHOSSDigitizer("galice.root")
35// Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
36// root [1] s->ExecuteTask()
f035f6ce 37// // Makes SDigitis for all events stored in galice.root
a4e98857 38// root [2] s->SetPedestalParameter(0.001)
f035f6ce 39// // One can change parameters of digitization
3de072dc 40// root [3] s->SetSDigitsBranch("Pedestal 0.001")
f035f6ce 41// // and write them into the new branch
3de072dc 42// root [4] s->ExecuteTask("deb all tim")
f035f6ce 43// // available parameters:
44// deb - print # of produced SDigitis
45// deb all - print # and list of produced SDigits
46// tim - print benchmarking information
990119d6 47//
48//*-- Author : Dmitri Peressounko (SUBATECH & KI)
49//////////////////////////////////////////////////////////////////////////////
50
f035f6ce 51
990119d6 52// --- ROOT system ---
7acf6008 53#include "TFile.h"
990119d6 54#include "TTask.h"
55#include "TTree.h"
56#include "TSystem.h"
7acf6008 57#include "TROOT.h"
58#include "TFolder.h"
59#include "TBenchmark.h"
990119d6 60// --- Standard library ---
7acf6008 61#include <iomanip.h>
990119d6 62
63// --- AliRoot header files ---
7acf6008 64#include "AliRun.h"
990119d6 65#include "AliPHOSDigit.h"
a6eedfad 66#include "AliPHOSGeometry.h"
7b7c1533 67#include "AliPHOSGetter.h"
990119d6 68#include "AliPHOSHit.h"
990119d6 69#include "AliPHOSSDigitizer.h"
70
990119d6 71
72ClassImp(AliPHOSSDigitizer)
73
74
75//____________________________________________________________________________
7b7c1533 76 AliPHOSSDigitizer::AliPHOSSDigitizer():TTask("","")
990119d6 77{
78 // ctor
2bd5457f 79 fA = 0;
80 fB = 10000000.;
990119d6 81 fPrimThreshold = 0.01 ;
2b60655b 82 fSDigitsInRun = 0 ;
990119d6 83}
7acf6008 84
990119d6 85//____________________________________________________________________________
7b7c1533 86AliPHOSSDigitizer::AliPHOSSDigitizer(const char * headerFile, const char * sDigitsTitle):TTask(sDigitsTitle, headerFile)
990119d6 87{
88 // ctor
2bd5457f 89 fA = 0;
90 fB = 10000000.;
990119d6 91 fPrimThreshold = 0.01 ;
2b60655b 92 fSDigitsInRun = 0 ;
2bd5457f 93 Init();
990119d6 94}
95
7b7c1533 96
7acf6008 97//____________________________________________________________________________
a4e98857 98void AliPHOSSDigitizer::Init()
99{
2bd5457f 100 // Initialization: open root-file, allocate arrays for hits and sdigits,
101 // attach task SDigitizer to the list of PHOS tasks
102 //
a4e98857 103 // Initialization can not be done in the default constructor
7b7c1533 104 //============================================================= YS
105 // The initialisation is now done by AliPHOSGetter
106
107 if( strcmp(GetTitle(), "") == 0 )
108 SetTitle("galice.root") ;
109
110 AliPHOSGetter * gime = AliPHOSGetter::GetInstance(GetTitle(), GetName()) ;
111 if ( gime == 0 ) {
112 cerr << "ERROR: AliPHOSSDigitizer::Init -> Could not obtain the Getter object !" << endl ;
113 return ;
114 }
115
5ad40cd6 116 gime->PostSDigits( GetName(), GetTitle() ) ;
117
118 TString sdname(GetName() );
119 sdname.Append(":") ;
120 sdname.Append(GetTitle() ) ;
121 SetName(sdname) ;
122 gime->PostSDigitizer(this) ;
a2d8b8a4 123
7acf6008 124}
7b7c1533 125
990119d6 126//____________________________________________________________________________
a4e98857 127void AliPHOSSDigitizer::Exec(Option_t *option)
128{
129 // Collects all hits in the same active volume into digit
7b7c1533 130 if( strcmp(GetName(), "") == 0 )
7acf6008 131 Init() ;
7b7c1533 132
133 if (strstr(option, "print") ) {
134 Print("") ;
135 return ;
136 }
990119d6 137
7acf6008 138 if(strstr(option,"tim"))
139 gBenchmark->Start("PHOSSDigitizer");
7b7c1533 140
141 //Check, if this branch already exits
5ad40cd6 142 gAlice->GetEvent(0) ;
a2d8b8a4 143
144 TString sdname(GetName()) ;
145 sdname.Remove(sdname.Index(GetTitle())-1) ;
146
5ad40cd6 147 if(gAlice->TreeS() ) {
7a9d98f9 148 TObjArray * lob = static_cast<TObjArray*>(gAlice->TreeS()->GetListOfBranches()) ;
5ad40cd6 149 TIter next(lob) ;
150 TBranch * branch = 0 ;
151 Bool_t phosfound = kFALSE, sdigitizerfound = kFALSE ;
7b7c1533 152
7a9d98f9 153 while ( (branch = (static_cast<TBranch*>(next()))) && (!phosfound || !sdigitizerfound) ) {
5ad40cd6 154 if ( (strcmp(branch->GetName(), "PHOS")==0) && (strcmp(branch->GetTitle(), GetName())==0) )
155 phosfound = kTRUE ;
156
157 else if ( (strcmp(branch->GetName(), "AliPHOSSDigitizer")==0) && (strcmp(branch->GetTitle(), GetName())==0) )
158 sdigitizerfound = kTRUE ;
159 }
160
161 if ( phosfound || sdigitizerfound ) {
162 cerr << "WARNING: AliPHOSSDigitizer::Exec -> SDigits and/or SDigitizer branch with name " << GetName()
163 << " already exits" << endl ;
164 return ;
165 }
166 }
7b7c1533 167
7b7c1533 168 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
169
7b7c1533 170 Int_t nevents = (Int_t) gAlice->TreeE()->GetEntries() ;
990119d6 171
172 Int_t ievent ;
7b7c1533 173 for(ievent = 0; ievent < nevents; ievent++){
5ad40cd6 174 gime->Event(ievent,"H") ;
017addb3 175 const TClonesArray * hits = gime->Hits() ;
5ad40cd6 176 TClonesArray * sdigits = gime->SDigits(sdname.Data()) ;
7b7c1533 177 sdigits->Clear();
990119d6 178 Int_t nSdigits = 0 ;
179
990119d6 180
7b7c1533 181 //Now make SDigits from hits, for PHOS it is the same, so just copy
017addb3 182
183//******************** CHECK HERE
184//YS DOES NOT UNDERSTAND THE NEED FOR THE FOLLOWING LOOP
185// Int_t itrack ;
186// for (itrack=0; itrack < gAlice->GetNtrack(); itrack++){
187// //=========== Get the PHOS branch from Hits Tree for the Primary track itrack
188// gime->Track(itrack) ;
990119d6 189 Int_t i;
7b7c1533 190 for ( i = 0 ; i < hits->GetEntries() ; i++ ) {
7a9d98f9 191 AliPHOSHit * hit = dynamic_cast<AliPHOSHit *>(hits->At(i)) ;
990119d6 192 // Assign primary number only if contribution is significant
9688c1dd 193
990119d6 194 if( hit->GetEnergy() > fPrimThreshold)
9688c1dd 195 new((*sdigits)[nSdigits]) AliPHOSDigit(hit->GetPrimary(),hit->GetId(),
196 Digitize(hit->GetEnergy()), hit->GetTime()) ;
990119d6 197 else
9688c1dd 198 new((*sdigits)[nSdigits]) AliPHOSDigit( -1 , hit->GetId(),
199 Digitize(hit->GetEnergy()), hit->GetTime()) ;
200 nSdigits++ ;
990119d6 201
9688c1dd 202 }
017addb3 203// } // loop over tracks
990119d6 204
7b7c1533 205 sdigits->Sort() ;
990119d6 206
7b7c1533 207 nSdigits = sdigits->GetEntriesFast() ;
69866bef 208 fSDigitsInRun += nSdigits ;
7b7c1533 209 sdigits->Expand(nSdigits) ;
017addb3 210// Int_t i ;
990119d6 211 for (i = 0 ; i < nSdigits ; i++) {
7a9d98f9 212 AliPHOSDigit * digit = dynamic_cast<AliPHOSDigit *>(sdigits->At(i)) ;
990119d6 213 digit->SetIndexInList(i) ;
214 }
7acf6008 215
216 if(gAlice->TreeS() == 0)
217 gAlice->MakeTree("S") ;
218
7acf6008 219 //Make (if necessary) branches
220 char * file =0;
221 if(gSystem->Getenv("CONFIG_SPLIT_FILE")){ //generating file name
222 file = new char[strlen(gAlice->GetBaseFile())+20] ;
223 sprintf(file,"%s/PHOS.SDigits.root",gAlice->GetBaseFile()) ;
224 }
225
226 TDirectory *cwd = gDirectory;
227
228 //First list of sdigits
229 Int_t bufferSize = 32000 ;
7b7c1533 230 TBranch * sdigitsBranch = gAlice->TreeS()->Branch("PHOS",&sdigits,bufferSize);
5ad40cd6 231 sdigitsBranch->SetTitle(sdname);
7acf6008 232 if (file) {
233 sdigitsBranch->SetFile(file);
234 TIter next( sdigitsBranch->GetListOfBranches());
761e34c0 235 TBranch * subbr;
7a9d98f9 236 while ((subbr=static_cast<TBranch*>(next()))) {
761e34c0 237 subbr->SetFile(file);
7acf6008 238 }
239 cwd->cd();
240 }
241
7b7c1533 242 //Next - SDigitizer
7acf6008 243 Int_t splitlevel = 0 ;
244 AliPHOSSDigitizer * sd = this ;
7b7c1533 245 TBranch * sdigitizerBranch = gAlice->TreeS()->Branch("AliPHOSSDigitizer","AliPHOSSDigitizer",
7acf6008 246 &sd,bufferSize,splitlevel);
5ad40cd6 247 sdigitizerBranch->SetTitle(sdname);
7acf6008 248 if (file) {
249 sdigitizerBranch->SetFile(file);
250 TIter next( sdigitizerBranch->GetListOfBranches());
761e34c0 251 TBranch * subbr ;
7a9d98f9 252 while ((subbr=static_cast<TBranch*>(next()))) {
761e34c0 253 subbr->SetFile(file);
7acf6008 254 }
255 cwd->cd();
256 delete file;
257 }
258
761e34c0 259 sdigitsBranch->Fill() ;
260 sdigitizerBranch->Fill() ;
990119d6 261 gAlice->TreeS()->Write(0,TObject::kOverwrite) ;
7acf6008 262
263 if(strstr(option,"deb"))
264 PrintSDigits(option) ;
265
990119d6 266 }
7acf6008 267
268 if(strstr(option,"tim")){
269 gBenchmark->Stop("PHOSSDigitizer");
270 cout << "AliPHOSSDigitizer:" << endl ;
271 cout << " took " << gBenchmark->GetCpuTime("PHOSSDigitizer") << " seconds for SDigitizing "
7b7c1533 272 << gBenchmark->GetCpuTime("PHOSSDigitizer")/nevents << " seconds per event " << endl ;
7acf6008 273 cout << endl ;
274 }
275
276
990119d6 277}
278//__________________________________________________________________
a4e98857 279void AliPHOSSDigitizer::SetSDigitsBranch(const char * title )
280{
281 // Setting title to branch SDigits
7b7c1533 282
283 TString stitle(title) ;
284
285 // check if branch with title already exists
7a9d98f9 286 TBranch * sdigitsBranch =
287 static_cast<TBranch*>(gAlice->TreeS()->GetListOfBranches()->FindObject("PHOS")) ;
288 TBranch * sdigitizerBranch =
289 static_cast<TBranch*>(gAlice->TreeS()->GetListOfBranches()->FindObject("AliPHOSSDigitizer")) ;
7b7c1533 290 const char * sdigitsTitle = sdigitsBranch ->GetTitle() ;
291 const char * sdigitizerTitle = sdigitizerBranch ->GetTitle() ;
292 if ( stitle.CompareTo(sdigitsTitle)==0 || stitle.CompareTo(sdigitizerTitle)==0 ){
293 cerr << "ERROR: AliPHOSSdigitizer::SetSDigitsBranch -> Cannot overwrite existing branch with title " << title << endl ;
294 return ;
295 }
296
297 cout << "AliPHOSSdigitizer::SetSDigitsBranch -> Changing SDigits file from " << GetName() << " to " << title << endl ;
298
299 SetName(title) ;
300
301 // Post to the WhiteBoard
302 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
5ad40cd6 303 gime->PostSDigits( title, GetTitle()) ;
990119d6 304}
7b7c1533 305
990119d6 306//__________________________________________________________________
a4e98857 307void AliPHOSSDigitizer::Print(Option_t* option)const
308{
309 // Prints parameters of SDigitizer
990119d6 310 cout << "------------------- "<< GetName() << " -------------" << endl ;
7a9d98f9 311 cout << " Writing SDigits to branch with title " << GetName() << endl ;
7acf6008 312 cout << " with digitization parameters A = " << fA << endl ;
313 cout << " B = " << fB << endl ;
314 cout << " Threshold for Primary assignment= " << fPrimThreshold << endl ;
990119d6 315 cout << "---------------------------------------------------"<<endl ;
7acf6008 316
990119d6 317}
318//__________________________________________________________________
a4e98857 319Bool_t AliPHOSSDigitizer::operator==( AliPHOSSDigitizer const &sd )const
320{
3de072dc 321 // Equal operator.
322 // SDititizers are equal if their pedestal, slope and threshold are equal
323
990119d6 324 if( (fA==sd.fA)&&(fB==sd.fB)&&(fPrimThreshold==sd.fPrimThreshold))
325 return kTRUE ;
326 else
327 return kFALSE ;
328}
7acf6008 329//__________________________________________________________________
a6eedfad 330//__________________________________________________________________
a4e98857 331void AliPHOSSDigitizer::PrintSDigits(Option_t * option)
332{
333 // Prints list of digits produced in the current pass of AliPHOSDigitizer
7b7c1533 334
a6eedfad 335
7b7c1533 336 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
5ad40cd6 337 TString sdname(GetName()) ;
338 sdname.Remove(sdname.Index(GetTitle())-1) ;
017addb3 339 const TClonesArray * sdigits = gime->SDigits(sdname.Data()) ;
7b7c1533 340
a6eedfad 341 cout << "AliPHOSSDigitiser: event " << gAlice->GetEvNumber() << endl ;
342 cout << " Number of entries in SDigits list " << sdigits->GetEntriesFast() << endl ;
7acf6008 343 cout << endl ;
a6eedfad 344 if(strstr(option,"all")||strstr(option,"EMC")){
7acf6008 345
346 //loop over digits
347 AliPHOSDigit * digit;
a6eedfad 348 cout << "EMC sdigits " << endl ;
349 cout << "Digit Id Amplitude Index Nprim Primaries list " << endl;
350 Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
7acf6008 351 Int_t index ;
a6eedfad 352 for (index = 0 ; (index < sdigits->GetEntriesFast()) &&
353 (((AliPHOSDigit * ) sdigits->At(index))->GetId() <= maxEmc) ; index++) {
7b7c1533 354 digit = (AliPHOSDigit * ) sdigits->At(index) ;
a6eedfad 355 if(digit->GetNprimary() == 0) continue;
356 cout << setw(6) << digit->GetId() << " " << setw(10) << digit->GetAmp() << " "
357 << setw(6) << digit->GetIndexInList() << " "
358 << setw(5) << digit->GetNprimary() <<" ";
7acf6008 359
360 Int_t iprimary;
361 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++)
a6eedfad 362 cout << setw(5) << digit->GetPrimary(iprimary+1) << " ";
7acf6008 363 cout << endl;
a6eedfad 364 }
365 cout << endl;
366 }
367
368 if(strstr(option,"all")||strstr(option,"CPV")){
7acf6008 369
a6eedfad 370 //loop over CPV digits
371 AliPHOSDigit * digit;
372 cout << "CPV sdigits " << endl ;
373 cout << "Digit Id Amplitude Index Nprim Primaries list " << endl;
374 Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
375 Int_t index ;
376 for (index = 0 ; index < sdigits->GetEntriesFast(); index++) {
377 digit = (AliPHOSDigit * ) sdigits->At(index) ;
378 if(digit->GetId() > maxEmc){
379 cout << setw(6) << digit->GetId() << " " << setw(10) << digit->GetAmp() << " "
380 << setw(6) << digit->GetIndexInList() << " "
381 << setw(5) << digit->GetNprimary() <<" ";
382
383 Int_t iprimary;
384 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++)
385 cout << setw(5) << digit->GetPrimary(iprimary+1) << " ";
386 cout << endl;
387 }
388 }
7acf6008 389 }
a6eedfad 390
7acf6008 391}
7b7c1533 392
393//____________________________________________________________________________
394void AliPHOSSDigitizer::UseHitsFrom(const char * filename)
395{
396 SetTitle(filename) ;
397 Init() ;
398}