]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSSDigitizer.cxx
Default branch name set to Default; Reading of hits delegated to AliPHOSGetter
[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"
7b7c1533 66#include "AliPHOSGetter.h"
990119d6 67#include "AliPHOSHit.h"
990119d6 68#include "AliPHOSSDigitizer.h"
69
990119d6 70
71ClassImp(AliPHOSSDigitizer)
72
73
74//____________________________________________________________________________
7b7c1533 75 AliPHOSSDigitizer::AliPHOSSDigitizer():TTask("","")
990119d6 76{
77 // ctor
2bd5457f 78 fA = 0;
79 fB = 10000000.;
990119d6 80 fPrimThreshold = 0.01 ;
2b60655b 81 fSDigitsInRun = 0 ;
990119d6 82}
7acf6008 83
990119d6 84//____________________________________________________________________________
7b7c1533 85AliPHOSSDigitizer::AliPHOSSDigitizer(const char * headerFile, const char * sDigitsTitle):TTask(sDigitsTitle, headerFile)
990119d6 86{
87 // ctor
2bd5457f 88 fA = 0;
89 fB = 10000000.;
990119d6 90 fPrimThreshold = 0.01 ;
2b60655b 91 fSDigitsInRun = 0 ;
2bd5457f 92 Init();
990119d6 93}
94
7b7c1533 95
7acf6008 96//____________________________________________________________________________
a4e98857 97void AliPHOSSDigitizer::Init()
98{
2bd5457f 99 // Initialization: open root-file, allocate arrays for hits and sdigits,
100 // attach task SDigitizer to the list of PHOS tasks
101 //
a4e98857 102 // Initialization can not be done in the default constructor
7b7c1533 103 //============================================================= YS
104 // The initialisation is now done by AliPHOSGetter
105
106 if( strcmp(GetTitle(), "") == 0 )
107 SetTitle("galice.root") ;
108
109 AliPHOSGetter * gime = AliPHOSGetter::GetInstance(GetTitle(), GetName()) ;
110 if ( gime == 0 ) {
111 cerr << "ERROR: AliPHOSSDigitizer::Init -> Could not obtain the Getter object !" << endl ;
112 return ;
113 }
114
5ad40cd6 115 // //add Task to //YSAlice/tasks/SDiditizer/PHOS
116 // TTask * aliceSD = (TTask*)gROOT->FindObjectAny("YSAlice/tasks/SDigitizer") ;
117 // TTask * phosSD = (TTask*)aliceSD->GetListOfTasks()->FindObject("PHOS") ;
118 // if ( ! phosSD->GetListOfTasks()->FindObject(GetName()) )
119 // phosSD->Add(this) ;
120
121 gime->PostSDigits( GetName(), GetTitle() ) ;
122
123 TString sdname(GetName() );
124 sdname.Append(":") ;
125 sdname.Append(GetTitle() ) ;
126 SetName(sdname) ;
127 gime->PostSDigitizer(this) ;
128
7b7c1533 129 // create a folder on the white board //YSAlice/WhiteBoard/SDigits/PHOS/headerFile/sdigitsTitle
7acf6008 130
7acf6008 131}
7b7c1533 132
990119d6 133//____________________________________________________________________________
a4e98857 134void AliPHOSSDigitizer::Exec(Option_t *option)
135{
136 // Collects all hits in the same active volume into digit
7b7c1533 137 if( strcmp(GetName(), "") == 0 )
7acf6008 138 Init() ;
7b7c1533 139
140 if (strstr(option, "print") ) {
141 Print("") ;
142 return ;
143 }
990119d6 144
7acf6008 145 if(strstr(option,"tim"))
146 gBenchmark->Start("PHOSSDigitizer");
7b7c1533 147
148 //Check, if this branch already exits
5ad40cd6 149 gAlice->GetEvent(0) ;
150 if(gAlice->TreeS() ) {
151 TObjArray * lob = (TObjArray*)gAlice->TreeS()->GetListOfBranches() ;
152 TIter next(lob) ;
153 TBranch * branch = 0 ;
154 Bool_t phosfound = kFALSE, sdigitizerfound = kFALSE ;
7b7c1533 155
5ad40cd6 156 while ( (branch = (TBranch*)next()) && (!phosfound || !sdigitizerfound) ) {
157 if ( (strcmp(branch->GetName(), "PHOS")==0) && (strcmp(branch->GetTitle(), GetName())==0) )
158 phosfound = kTRUE ;
159
160 else if ( (strcmp(branch->GetName(), "AliPHOSSDigitizer")==0) && (strcmp(branch->GetTitle(), GetName())==0) )
161 sdigitizerfound = kTRUE ;
162 }
163
164 if ( phosfound || sdigitizerfound ) {
165 cerr << "WARNING: AliPHOSSDigitizer::Exec -> SDigits and/or SDigitizer branch with name " << GetName()
166 << " already exits" << endl ;
167 return ;
168 }
169 }
7b7c1533 170
5ad40cd6 171 TString sdname(GetName()) ;
172 sdname.Remove(sdname.Index(GetTitle())-1) ;
7b7c1533 173
174 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
175
7b7c1533 176 Int_t nevents = (Int_t) gAlice->TreeE()->GetEntries() ;
990119d6 177
178 Int_t ievent ;
7b7c1533 179 for(ievent = 0; ievent < nevents; ievent++){
5ad40cd6 180 gime->Event(ievent,"H") ;
7b7c1533 181
5ad40cd6 182 TClonesArray * sdigits = gime->SDigits(sdname.Data()) ;
7b7c1533 183 sdigits->Clear();
990119d6 184 Int_t nSdigits = 0 ;
185
990119d6 186
7b7c1533 187 //Now make SDigits from hits, for PHOS it is the same, so just copy
990119d6 188 Int_t itrack ;
077397f6 189 for (itrack=0; itrack < gAlice->GetNtrack(); itrack++){
7b7c1533 190
077397f6 191 //=========== Get the PHOS branch from Hits Tree for the Primary track itrack
5ad40cd6 192 gime->Track(itrack) ;
193 TClonesArray * hits = gime->Hits() ;
990119d6 194 Int_t i;
7b7c1533 195 for ( i = 0 ; i < hits->GetEntries() ; i++ ) {
5ad40cd6 196 AliPHOSHit * hit = (AliPHOSHit *) hits->At(i) ;
990119d6 197 // Assign primary number only if contribution is significant
7b7c1533 198
990119d6 199 if( hit->GetEnergy() > fPrimThreshold)
7b7c1533 200 new((*sdigits)[nSdigits]) AliPHOSDigit( hit->GetPrimary(), hit->GetId(), Digitize( hit->GetEnergy() ) ) ;
990119d6 201 else
7b7c1533 202 new((*sdigits)[nSdigits]) AliPHOSDigit( -1 , hit->GetId(), Digitize( hit->GetEnergy() ) ) ;
990119d6 203
990119d6 204 nSdigits++ ;
205
990119d6 206 }
7b7c1533 207
990119d6 208 } // loop over tracks
209
7b7c1533 210 sdigits->Sort() ;
990119d6 211
7b7c1533 212 nSdigits = sdigits->GetEntriesFast() ;
5ad40cd6 213
7b7c1533 214 sdigits->Expand(nSdigits) ;
990119d6 215 Int_t i ;
216 for (i = 0 ; i < nSdigits ; i++) {
7b7c1533 217 AliPHOSDigit * digit = (AliPHOSDigit *) sdigits->At(i) ;
990119d6 218 digit->SetIndexInList(i) ;
219 }
7acf6008 220
221 if(gAlice->TreeS() == 0)
222 gAlice->MakeTree("S") ;
223
7acf6008 224 //Make (if necessary) branches
225 char * file =0;
226 if(gSystem->Getenv("CONFIG_SPLIT_FILE")){ //generating file name
227 file = new char[strlen(gAlice->GetBaseFile())+20] ;
228 sprintf(file,"%s/PHOS.SDigits.root",gAlice->GetBaseFile()) ;
229 }
230
231 TDirectory *cwd = gDirectory;
232
233 //First list of sdigits
234 Int_t bufferSize = 32000 ;
7b7c1533 235 TBranch * sdigitsBranch = gAlice->TreeS()->Branch("PHOS",&sdigits,bufferSize);
5ad40cd6 236 sdigitsBranch->SetTitle(sdname);
7acf6008 237 if (file) {
238 sdigitsBranch->SetFile(file);
239 TIter next( sdigitsBranch->GetListOfBranches());
761e34c0 240 TBranch * subbr;
241 while ((subbr=(TBranch*)next())) {
242 subbr->SetFile(file);
7acf6008 243 }
244 cwd->cd();
245 }
246
7b7c1533 247 //Next - SDigitizer
7acf6008 248 Int_t splitlevel = 0 ;
249 AliPHOSSDigitizer * sd = this ;
7b7c1533 250 TBranch * sdigitizerBranch = gAlice->TreeS()->Branch("AliPHOSSDigitizer","AliPHOSSDigitizer",
7acf6008 251 &sd,bufferSize,splitlevel);
5ad40cd6 252 sdigitizerBranch->SetTitle(sdname);
7acf6008 253 if (file) {
254 sdigitizerBranch->SetFile(file);
255 TIter next( sdigitizerBranch->GetListOfBranches());
761e34c0 256 TBranch * subbr ;
257 while ((subbr=(TBranch*)next())) {
258 subbr->SetFile(file);
7acf6008 259 }
260 cwd->cd();
261 delete file;
262 }
263
761e34c0 264 sdigitsBranch->Fill() ;
265 sdigitizerBranch->Fill() ;
990119d6 266 gAlice->TreeS()->Write(0,TObject::kOverwrite) ;
7acf6008 267
268 if(strstr(option,"deb"))
269 PrintSDigits(option) ;
270
990119d6 271 }
7acf6008 272
273 if(strstr(option,"tim")){
274 gBenchmark->Stop("PHOSSDigitizer");
275 cout << "AliPHOSSDigitizer:" << endl ;
276 cout << " took " << gBenchmark->GetCpuTime("PHOSSDigitizer") << " seconds for SDigitizing "
7b7c1533 277 << gBenchmark->GetCpuTime("PHOSSDigitizer")/nevents << " seconds per event " << endl ;
7acf6008 278 cout << endl ;
279 }
280
281
990119d6 282}
283//__________________________________________________________________
a4e98857 284void AliPHOSSDigitizer::SetSDigitsBranch(const char * title )
285{
286 // Setting title to branch SDigits
7b7c1533 287
288 TString stitle(title) ;
289
290 // check if branch with title already exists
291 TBranch * sdigitsBranch = (TBranch*)gAlice->TreeS()->GetListOfBranches()->FindObject("PHOS") ;
292 TBranch * sdigitizerBranch = (TBranch*)gAlice->TreeS()->GetListOfBranches()->FindObject("AliPHOSSDigitizer") ;
293 const char * sdigitsTitle = sdigitsBranch ->GetTitle() ;
294 const char * sdigitizerTitle = sdigitizerBranch ->GetTitle() ;
295 if ( stitle.CompareTo(sdigitsTitle)==0 || stitle.CompareTo(sdigitizerTitle)==0 ){
296 cerr << "ERROR: AliPHOSSdigitizer::SetSDigitsBranch -> Cannot overwrite existing branch with title " << title << endl ;
297 return ;
298 }
299
300 cout << "AliPHOSSdigitizer::SetSDigitsBranch -> Changing SDigits file from " << GetName() << " to " << title << endl ;
301
302 SetName(title) ;
303
304 // Post to the WhiteBoard
305 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
5ad40cd6 306 gime->PostSDigits( title, GetTitle()) ;
990119d6 307}
7b7c1533 308
990119d6 309//__________________________________________________________________
a4e98857 310void AliPHOSSDigitizer::Print(Option_t* option)const
311{
312 // Prints parameters of SDigitizer
990119d6 313 cout << "------------------- "<< GetName() << " -------------" << endl ;
7b7c1533 314 cout << " Writing SDigitis to branch with title " << GetName() << endl ;
7acf6008 315 cout << " with digitization parameters A = " << fA << endl ;
316 cout << " B = " << fB << endl ;
317 cout << " Threshold for Primary assignment= " << fPrimThreshold << endl ;
990119d6 318 cout << "---------------------------------------------------"<<endl ;
7acf6008 319
990119d6 320}
321//__________________________________________________________________
a4e98857 322Bool_t AliPHOSSDigitizer::operator==( AliPHOSSDigitizer const &sd )const
323{
3de072dc 324 // Equal operator.
325 // SDititizers are equal if their pedestal, slope and threshold are equal
326
990119d6 327 if( (fA==sd.fA)&&(fB==sd.fB)&&(fPrimThreshold==sd.fPrimThreshold))
328 return kTRUE ;
329 else
330 return kFALSE ;
331}
7acf6008 332//__________________________________________________________________
a4e98857 333void AliPHOSSDigitizer::PrintSDigits(Option_t * option)
334{
335 // Prints list of digits produced in the current pass of AliPHOSDigitizer
7b7c1533 336
337 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
5ad40cd6 338 TString sdname(GetName()) ;
339 sdname.Remove(sdname.Index(GetTitle())-1) ;
340 TClonesArray * sdigits = gime->SDigits(sdname.Data()) ;
7b7c1533 341
01a599c9 342 cout << "AliPHOSSDigitizer: event "<<gAlice->GetEvNumber() << endl ;
7b7c1533 343 cout << " Number of entries in SDigits list " << sdigits->GetEntriesFast() << endl ;
7acf6008 344 cout << endl ;
2b60655b 345
346 fSDigitsInRun += sdigits->GetEntriesFast() ;
7acf6008 347
348 if(strstr(option,"all")){// print all digits
349
350 //loop over digits
351 AliPHOSDigit * digit;
352 cout << "SDigit Id " << " Amplitude " << " Index " << " Nprim " << " Primaries list " << endl;
353 Int_t index ;
7b7c1533 354 for (index = 0 ; index < sdigits->GetEntries() ; index++) {
355 digit = (AliPHOSDigit * ) sdigits->At(index) ;
7acf6008 356 cout << setw(8) << digit->GetId() << " " << setw(3) << digit->GetAmp() << " "
357 << setw(6) << digit->GetIndexInList() << " "
358 << setw(5) << digit->GetNprimary() <<" ";
359
360 Int_t iprimary;
361 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++)
362 cout << setw(5) << digit->GetPrimary(iprimary+1) << " ";
363 cout << endl;
364 }
365
366 }
367}
7b7c1533 368
369//____________________________________________________________________________
370void AliPHOSSDigitizer::UseHitsFrom(const char * filename)
371{
372 SetTitle(filename) ;
373 Init() ;
374}