]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSSDigitizer.cxx
Cosmetic changes, and a new function AliL3Hough::ProcessPatchIter.
[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 "TFile.h"
990119d6 55#include "TTask.h"
56#include "TTree.h"
57#include "TSystem.h"
7acf6008 58#include "TROOT.h"
59#include "TFolder.h"
60#include "TBenchmark.h"
106fc2fa 61#include "TGeometry.h"
62
990119d6 63// --- Standard library ---
7acf6008 64#include <iomanip.h>
990119d6 65
66// --- AliRoot header files ---
7acf6008 67#include "AliRun.h"
106fc2fa 68#include "AliHeader.h"
990119d6 69#include "AliPHOSDigit.h"
a6eedfad 70#include "AliPHOSGeometry.h"
7b7c1533 71#include "AliPHOSGetter.h"
990119d6 72#include "AliPHOSHit.h"
990119d6 73#include "AliPHOSSDigitizer.h"
74
990119d6 75
76ClassImp(AliPHOSSDigitizer)
77
78
79//____________________________________________________________________________
8d0f3f77 80 AliPHOSSDigitizer::AliPHOSSDigitizer():TTask("","") {
990119d6 81 // ctor
92f521a9 82 InitParameters() ;
83 fDefaultInit = kTRUE ;
990119d6 84}
7acf6008 85
990119d6 86//____________________________________________________________________________
7b7c1533 87AliPHOSSDigitizer::AliPHOSSDigitizer(const char * headerFile, const char * sDigitsTitle):TTask(sDigitsTitle, headerFile)
990119d6 88{
89 // ctor
8d0f3f77 90 InitParameters() ;
2bd5457f 91 Init();
92f521a9 92 fDefaultInit = kFALSE ;
990119d6 93}
94
c093f031 95//____________________________________________________________________________
96AliPHOSSDigitizer::~AliPHOSSDigitizer()
97{
79bb1b62 98 // dtor
92f521a9 99 // fDefaultInit = kTRUE if SDigitizer created by default ctor (to get just the parameters)
6f51f90b 100
79bb1b62 101
92f521a9 102 if (!fDefaultInit) {
103 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
104
8d0f3f77 105 // remove the task from the folder list
106 gime->RemoveTask("S",GetName()) ;
107
108 TString name(GetName()) ;
109 if (! name.IsNull() )
110 name.Remove(name.Index(":")) ;
111
112 // remove the Hits from the folder list
113 gime->RemoveObjects("H",name) ;
114
115 // remove the SDigits from the folder list
116 gime->RemoveObjects("S", name) ;
117
118 // Delete gAlice
119 gime->CloseFile() ;
120
121 }
122 fSplitFile = 0 ;
c093f031 123}
7b7c1533 124
7acf6008 125//____________________________________________________________________________
a4e98857 126void AliPHOSSDigitizer::Init()
127{
2bd5457f 128 // Initialization: open root-file, allocate arrays for hits and sdigits,
129 // attach task SDigitizer to the list of PHOS tasks
130 //
a4e98857 131 // Initialization can not be done in the default constructor
7b7c1533 132 //============================================================= YS
133 // The initialisation is now done by AliPHOSGetter
134
135 if( strcmp(GetTitle(), "") == 0 )
136 SetTitle("galice.root") ;
85f78bbc 137
7b7c1533 138 AliPHOSGetter * gime = AliPHOSGetter::GetInstance(GetTitle(), GetName()) ;
139 if ( gime == 0 ) {
140 cerr << "ERROR: AliPHOSSDigitizer::Init -> Could not obtain the Getter object !" << endl ;
141 return ;
142 }
143
5ad40cd6 144 gime->PostSDigits( GetName(), GetTitle() ) ;
145
146 TString sdname(GetName() );
147 sdname.Append(":") ;
148 sdname.Append(GetTitle() ) ;
149 SetName(sdname) ;
150 gime->PostSDigitizer(this) ;
7acf6008 151}
7b7c1533 152
8d0f3f77 153//____________________________________________________________________________
154void AliPHOSSDigitizer::InitParameters()
155{
156 fA = 0;
157 fB = 10000000.;
158 fPrimThreshold = 0.01 ;
159 fSDigitsInRun = 0 ;
160 fSplitFile = 0 ;
161}
162
990119d6 163//____________________________________________________________________________
a4e98857 164void AliPHOSSDigitizer::Exec(Option_t *option)
165{
166 // Collects all hits in the same active volume into digit
7b7c1533 167 if( strcmp(GetName(), "") == 0 )
7acf6008 168 Init() ;
7b7c1533 169
170 if (strstr(option, "print") ) {
171 Print("") ;
172 return ;
173 }
990119d6 174
7acf6008 175 if(strstr(option,"tim"))
176 gBenchmark->Start("PHOSSDigitizer");
7b7c1533 177
178 //Check, if this branch already exits
5ad40cd6 179 gAlice->GetEvent(0) ;
a2d8b8a4 180
181 TString sdname(GetName()) ;
182 sdname.Remove(sdname.Index(GetTitle())-1) ;
183
5ad40cd6 184 if(gAlice->TreeS() ) {
7a9d98f9 185 TObjArray * lob = static_cast<TObjArray*>(gAlice->TreeS()->GetListOfBranches()) ;
5ad40cd6 186 TIter next(lob) ;
187 TBranch * branch = 0 ;
188 Bool_t phosfound = kFALSE, sdigitizerfound = kFALSE ;
7b7c1533 189
7a9d98f9 190 while ( (branch = (static_cast<TBranch*>(next()))) && (!phosfound || !sdigitizerfound) ) {
c093f031 191 TString thisName( GetName() ) ;
192 TString branchName( branch->GetTitle() ) ;
193 branchName.Append(":") ;
194 if ( (strcmp(branch->GetName(), "PHOS")==0) && thisName.BeginsWith(branchName) )
5ad40cd6 195 phosfound = kTRUE ;
c093f031 196 else if ( (strcmp(branch->GetName(), "AliPHOSSDigitizer")==0) && thisName.BeginsWith(branchName) )
5ad40cd6 197 sdigitizerfound = kTRUE ;
198 }
199
200 if ( phosfound || sdigitizerfound ) {
201 cerr << "WARNING: AliPHOSSDigitizer::Exec -> SDigits and/or SDigitizer branch with name " << GetName()
202 << " already exits" << endl ;
203 return ;
204 }
205 }
7b7c1533 206
7b7c1533 207 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
208
7b7c1533 209 Int_t nevents = (Int_t) gAlice->TreeE()->GetEntries() ;
990119d6 210
211 Int_t ievent ;
7b7c1533 212 for(ievent = 0; ievent < nevents; ievent++){
5ad40cd6 213 gime->Event(ievent,"H") ;
017addb3 214 const TClonesArray * hits = gime->Hits() ;
5ad40cd6 215 TClonesArray * sdigits = gime->SDigits(sdname.Data()) ;
7b7c1533 216 sdigits->Clear();
990119d6 217 Int_t nSdigits = 0 ;
218
990119d6 219
7b7c1533 220 //Now make SDigits from hits, for PHOS it is the same, so just copy
c093f031 221
3962b6a1 222 Int_t Nprim = (Int_t) (gAlice->TreeH())->GetEntries();
223 // Attention Nprim is the number of primaries tracked by Geant and this number could be different to the number of Primaries in TreeK;
224 Int_t iprim;
225 for (iprim=0; iprim<Nprim; iprim++) {
226 //=========== Get the PHOS branch from Hits Tree for the Primary iprim
227 gime->Track(iprim) ;
990119d6 228 Int_t i;
7b7c1533 229 for ( i = 0 ; i < hits->GetEntries() ; i++ ) {
7a9d98f9 230 AliPHOSHit * hit = dynamic_cast<AliPHOSHit *>(hits->At(i)) ;
990119d6 231 // Assign primary number only if contribution is significant
9688c1dd 232
990119d6 233 if( hit->GetEnergy() > fPrimThreshold)
9688c1dd 234 new((*sdigits)[nSdigits]) AliPHOSDigit(hit->GetPrimary(),hit->GetId(),
235 Digitize(hit->GetEnergy()), hit->GetTime()) ;
990119d6 236 else
9688c1dd 237 new((*sdigits)[nSdigits]) AliPHOSDigit( -1 , hit->GetId(),
238 Digitize(hit->GetEnergy()), hit->GetTime()) ;
239 nSdigits++ ;
990119d6 240
9688c1dd 241 }
c093f031 242
3962b6a1 243 } // loop over iprim
990119d6 244
7b7c1533 245 sdigits->Sort() ;
990119d6 246
7b7c1533 247 nSdigits = sdigits->GetEntriesFast() ;
69866bef 248 fSDigitsInRun += nSdigits ;
7b7c1533 249 sdigits->Expand(nSdigits) ;
c093f031 250
3962b6a1 251 Int_t i ;
990119d6 252 for (i = 0 ; i < nSdigits ; i++) {
7a9d98f9 253 AliPHOSDigit * digit = dynamic_cast<AliPHOSDigit *>(sdigits->At(i)) ;
990119d6 254 digit->SetIndexInList(i) ;
255 }
3962b6a1 256
106fc2fa 257 if(gAlice->TreeS() == 0)
85f78bbc 258 gAlice->MakeTree("S", fSplitFile);
c093f031 259
7acf6008 260 //First list of sdigits
261 Int_t bufferSize = 32000 ;
7b7c1533 262 TBranch * sdigitsBranch = gAlice->TreeS()->Branch("PHOS",&sdigits,bufferSize);
5ad40cd6 263 sdigitsBranch->SetTitle(sdname);
7acf6008 264
7b7c1533 265 //Next - SDigitizer
7acf6008 266 Int_t splitlevel = 0 ;
267 AliPHOSSDigitizer * sd = this ;
7b7c1533 268 TBranch * sdigitizerBranch = gAlice->TreeS()->Branch("AliPHOSSDigitizer","AliPHOSSDigitizer",
7acf6008 269 &sd,bufferSize,splitlevel);
5ad40cd6 270 sdigitizerBranch->SetTitle(sdname);
c093f031 271
42d2745f 272 sdigitsBranch->Fill() ;
c093f031 273 sdigitizerBranch->Fill() ;
42d2745f 274 gAlice->TreeS()->AutoSave() ;
7acf6008 275
276 if(strstr(option,"deb"))
277 PrintSDigits(option) ;
c093f031 278
990119d6 279 }
c093f031 280
7acf6008 281 if(strstr(option,"tim")){
282 gBenchmark->Stop("PHOSSDigitizer");
283 cout << "AliPHOSSDigitizer:" << endl ;
284 cout << " took " << gBenchmark->GetCpuTime("PHOSSDigitizer") << " seconds for SDigitizing "
7b7c1533 285 << gBenchmark->GetCpuTime("PHOSSDigitizer")/nevents << " seconds per event " << endl ;
7acf6008 286 cout << endl ;
287 }
288
289
990119d6 290}
106fc2fa 291
990119d6 292//__________________________________________________________________
a4e98857 293void AliPHOSSDigitizer::SetSDigitsBranch(const char * title )
294{
295 // Setting title to branch SDigits
7b7c1533 296
297 TString stitle(title) ;
298
299 // check if branch with title already exists
7a9d98f9 300 TBranch * sdigitsBranch =
301 static_cast<TBranch*>(gAlice->TreeS()->GetListOfBranches()->FindObject("PHOS")) ;
302 TBranch * sdigitizerBranch =
303 static_cast<TBranch*>(gAlice->TreeS()->GetListOfBranches()->FindObject("AliPHOSSDigitizer")) ;
7b7c1533 304 const char * sdigitsTitle = sdigitsBranch ->GetTitle() ;
305 const char * sdigitizerTitle = sdigitizerBranch ->GetTitle() ;
306 if ( stitle.CompareTo(sdigitsTitle)==0 || stitle.CompareTo(sdigitizerTitle)==0 ){
307 cerr << "ERROR: AliPHOSSdigitizer::SetSDigitsBranch -> Cannot overwrite existing branch with title " << title << endl ;
308 return ;
309 }
310
311 cout << "AliPHOSSdigitizer::SetSDigitsBranch -> Changing SDigits file from " << GetName() << " to " << title << endl ;
312
313 SetName(title) ;
314
315 // Post to the WhiteBoard
316 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
5ad40cd6 317 gime->PostSDigits( title, GetTitle()) ;
990119d6 318}
7b7c1533 319
106fc2fa 320//__________________________________________________________________
c093f031 321void AliPHOSSDigitizer::SetSplitFile(const TString splitFileName)
106fc2fa 322{
323 // Diverts the SDigits in a file separate from the hits file
324
325 TDirectory * cwd = gDirectory ;
c093f031 326
327 if ( !(gAlice->GetTreeSFileName() == splitFileName) ) {
328 if (gAlice->GetTreeSFile() )
329 gAlice->GetTreeSFile()->Close() ;
330 }
331
332 fSplitFile = gAlice->InitTreeFile("S",splitFileName.Data());
333 fSplitFile->cd() ;
8d0f3f77 334 gAlice->Write(0, TObject::kOverwrite);
106fc2fa 335
336 TTree *treeE = gAlice->TreeE();
337 if (!treeE) {
c093f031 338 cerr << "ERROR: AliPHOSSDigitizer::SetSPlitFile -> No TreeE found "<<endl;
106fc2fa 339 abort() ;
340 }
341
342 // copy TreeE
c093f031 343 AliHeader *header = new AliHeader();
344 treeE->SetBranchAddress("Header", &header);
345 treeE->SetBranchStatus("*",1);
346 TTree *treeENew = treeE->CloneTree();
8d0f3f77 347 treeENew->Write(0, TObject::kOverwrite);
348
c093f031 349
106fc2fa 350 // copy AliceGeom
c093f031 351 TGeometry *AliceGeom = static_cast<TGeometry*>(cwd->Get("AliceGeom"));
352 if (!AliceGeom) {
353 cerr << "ERROR: AliPHOSSDigitizer::SetSPlitFile -> AliceGeom was not found in the input file "<<endl;
354 abort() ;
355 }
8d0f3f77 356 AliceGeom->Write(0, TObject::kOverwrite);
c093f031 357
c093f031 358 gAlice->MakeTree("S",fSplitFile);
85f78bbc 359 cwd->cd() ;
6f51f90b 360 cout << "INFO: AliPHOSSDigitizer::SetSPlitMode -> SDigits will be stored in " << splitFileName.Data() << endl ;
8d0f3f77 361
106fc2fa 362}
363
990119d6 364//__________________________________________________________________
a4e98857 365void AliPHOSSDigitizer::Print(Option_t* option)const
366{
367 // Prints parameters of SDigitizer
990119d6 368 cout << "------------------- "<< GetName() << " -------------" << endl ;
7a9d98f9 369 cout << " Writing SDigits to branch with title " << GetName() << endl ;
7acf6008 370 cout << " with digitization parameters A = " << fA << endl ;
371 cout << " B = " << fB << endl ;
372 cout << " Threshold for Primary assignment= " << fPrimThreshold << endl ;
990119d6 373 cout << "---------------------------------------------------"<<endl ;
7acf6008 374
990119d6 375}
376//__________________________________________________________________
a4e98857 377Bool_t AliPHOSSDigitizer::operator==( AliPHOSSDigitizer const &sd )const
378{
3de072dc 379 // Equal operator.
380 // SDititizers are equal if their pedestal, slope and threshold are equal
381
990119d6 382 if( (fA==sd.fA)&&(fB==sd.fB)&&(fPrimThreshold==sd.fPrimThreshold))
383 return kTRUE ;
384 else
385 return kFALSE ;
386}
7acf6008 387//__________________________________________________________________
a6eedfad 388//__________________________________________________________________
a4e98857 389void AliPHOSSDigitizer::PrintSDigits(Option_t * option)
390{
391 // Prints list of digits produced in the current pass of AliPHOSDigitizer
7b7c1533 392
a6eedfad 393
7b7c1533 394 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
5ad40cd6 395 TString sdname(GetName()) ;
396 sdname.Remove(sdname.Index(GetTitle())-1) ;
017addb3 397 const TClonesArray * sdigits = gime->SDigits(sdname.Data()) ;
7b7c1533 398
a6eedfad 399 cout << "AliPHOSSDigitiser: event " << gAlice->GetEvNumber() << endl ;
400 cout << " Number of entries in SDigits list " << sdigits->GetEntriesFast() << endl ;
7acf6008 401 cout << endl ;
a6eedfad 402 if(strstr(option,"all")||strstr(option,"EMC")){
7acf6008 403
404 //loop over digits
405 AliPHOSDigit * digit;
a6eedfad 406 cout << "EMC sdigits " << endl ;
407 cout << "Digit Id Amplitude Index Nprim Primaries list " << endl;
408 Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
7acf6008 409 Int_t index ;
a6eedfad 410 for (index = 0 ; (index < sdigits->GetEntriesFast()) &&
411 (((AliPHOSDigit * ) sdigits->At(index))->GetId() <= maxEmc) ; index++) {
7b7c1533 412 digit = (AliPHOSDigit * ) sdigits->At(index) ;
a6eedfad 413 if(digit->GetNprimary() == 0) continue;
414 cout << setw(6) << digit->GetId() << " " << setw(10) << digit->GetAmp() << " "
415 << setw(6) << digit->GetIndexInList() << " "
416 << setw(5) << digit->GetNprimary() <<" ";
7acf6008 417
418 Int_t iprimary;
419 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++)
a6eedfad 420 cout << setw(5) << digit->GetPrimary(iprimary+1) << " ";
7acf6008 421 cout << endl;
a6eedfad 422 }
423 cout << endl;
424 }
425
426 if(strstr(option,"all")||strstr(option,"CPV")){
7acf6008 427
a6eedfad 428 //loop over CPV digits
429 AliPHOSDigit * digit;
430 cout << "CPV sdigits " << endl ;
431 cout << "Digit Id Amplitude Index Nprim Primaries list " << endl;
432 Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
433 Int_t index ;
434 for (index = 0 ; index < sdigits->GetEntriesFast(); index++) {
435 digit = (AliPHOSDigit * ) sdigits->At(index) ;
436 if(digit->GetId() > maxEmc){
437 cout << setw(6) << digit->GetId() << " " << setw(10) << digit->GetAmp() << " "
438 << setw(6) << digit->GetIndexInList() << " "
439 << setw(5) << digit->GetNprimary() <<" ";
440
441 Int_t iprimary;
442 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++)
443 cout << setw(5) << digit->GetPrimary(iprimary+1) << " ";
444 cout << endl;
445 }
446 }
7acf6008 447 }
a6eedfad 448
7acf6008 449}
7b7c1533 450
451//____________________________________________________________________________
452void AliPHOSSDigitizer::UseHitsFrom(const char * filename)
453{
454 SetTitle(filename) ;
455 Init() ;
456}