]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSSDigitizer.cxx
GetRandom returning impact parameter bin and flag for hard process added.
[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"
7acf6008 55#include "TROOT.h"
7acf6008 56#include "TBenchmark.h"
106fc2fa 57
990119d6 58// --- Standard library ---
59
60// --- AliRoot header files ---
7acf6008 61#include "AliRun.h"
990119d6 62#include "AliPHOSDigit.h"
7b7c1533 63#include "AliPHOSGetter.h"
990119d6 64#include "AliPHOSHit.h"
990119d6 65#include "AliPHOSSDigitizer.h"
66
990119d6 67ClassImp(AliPHOSSDigitizer)
68
69
70//____________________________________________________________________________
548f0134 71 AliPHOSSDigitizer::AliPHOSSDigitizer():TTask("","")
72{
990119d6 73 // ctor
92f521a9 74 InitParameters() ;
75 fDefaultInit = kTRUE ;
990119d6 76}
7acf6008 77
990119d6 78//____________________________________________________________________________
fbf811ec 79AliPHOSSDigitizer::AliPHOSSDigitizer(const char * headerFile, const char * sDigitsTitle, const Bool_t toSplit):
80TTask(sDigitsTitle, headerFile)
990119d6 81{
82 // ctor
8d0f3f77 83 InitParameters() ;
fbf811ec 84 fToSplit = toSplit ;
2bd5457f 85 Init();
92f521a9 86 fDefaultInit = kFALSE ;
990119d6 87}
88
bdc147a9 89//____________________________________________________________________________
90AliPHOSSDigitizer::AliPHOSSDigitizer(const AliPHOSSDigitizer & sd) {
91 //cpy ctor
92
93 fA = sd.fA ;
94 fB = sd.fB ;
95 fPrimThreshold = sd.fPrimThreshold ;
96 fSDigitsInRun = sd.fSDigitsInRun ;
97 fSplitFile = new TFile( (sd.fSplitFile)->GetName(), "new") ;
98 fToSplit = sd.fToSplit ;
99}
100
c093f031 101//____________________________________________________________________________
102AliPHOSSDigitizer::~AliPHOSSDigitizer()
103{
79bb1b62 104 // dtor
79bb1b62 105
8d0f3f77 106 fSplitFile = 0 ;
c093f031 107}
7b7c1533 108
7acf6008 109//____________________________________________________________________________
a4e98857 110void AliPHOSSDigitizer::Init()
111{
2bd5457f 112 // Initialization: open root-file, allocate arrays for hits and sdigits,
113 // attach task SDigitizer to the list of PHOS tasks
114 //
a4e98857 115 // Initialization can not be done in the default constructor
7b7c1533 116 //============================================================= YS
117 // The initialisation is now done by AliPHOSGetter
118
119 if( strcmp(GetTitle(), "") == 0 )
120 SetTitle("galice.root") ;
85f78bbc 121
fbf811ec 122 AliPHOSGetter * gime = AliPHOSGetter::GetInstance(GetTitle(), GetName(),fToSplit) ;
7b7c1533 123 if ( gime == 0 ) {
21cd0c07 124 Error("Init" ,"Could not obtain the Getter object !") ;
7b7c1533 125 return ;
126 }
127
5ad40cd6 128 gime->PostSDigits( GetName(), GetTitle() ) ;
129
fbf811ec 130 fSplitFile = 0 ;
131 if(fToSplit){
132 // construct the name of the file as /path/PHOS.SDigits.root
133 // First - extract full path if necessary
134 TString sDigitsFileName(GetTitle()) ;
135 Ssiz_t islash = sDigitsFileName.Last('/') ;
136 if(islash<sDigitsFileName.Length())
137 sDigitsFileName.Remove(islash+1,sDigitsFileName.Length()) ;
138 else
139 sDigitsFileName="" ;
140 // Next - append the file name
141 sDigitsFileName+="PHOS.SDigits." ;
142 if((strcmp(GetName(),"Default")!=0)&&(strcmp(GetName(),"")!=0)){
143 sDigitsFileName+=GetName() ;
144 sDigitsFileName+="." ;
145 }
146 sDigitsFileName+="root" ;
147 // Finally - check if the file already opened or open the file
148 fSplitFile = static_cast<TFile*>(gROOT->GetFile(sDigitsFileName.Data()));
149 if(!fSplitFile)
150 fSplitFile = TFile::Open(sDigitsFileName.Data(),"update") ;
151 }
152
5ad40cd6 153 TString sdname(GetName() );
154 sdname.Append(":") ;
155 sdname.Append(GetTitle() ) ;
156 SetName(sdname) ;
157 gime->PostSDigitizer(this) ;
7acf6008 158}
7b7c1533 159
8d0f3f77 160//____________________________________________________________________________
161void AliPHOSSDigitizer::InitParameters()
162{
bdc147a9 163 // initializes the parameters for difitization
8d0f3f77 164 fA = 0;
165 fB = 10000000.;
166 fPrimThreshold = 0.01 ;
167 fSDigitsInRun = 0 ;
168 fSplitFile = 0 ;
fbf811ec 169 fToSplit = kFALSE ;
8d0f3f77 170}
171
990119d6 172//____________________________________________________________________________
a4e98857 173void AliPHOSSDigitizer::Exec(Option_t *option)
174{
175 // Collects all hits in the same active volume into digit
548f0134 176
7b7c1533 177 if( strcmp(GetName(), "") == 0 )
7acf6008 178 Init() ;
7b7c1533 179
180 if (strstr(option, "print") ) {
181 Print("") ;
182 return ;
183 }
990119d6 184
7acf6008 185 if(strstr(option,"tim"))
186 gBenchmark->Start("PHOSSDigitizer");
fbf811ec 187
7b7c1533 188 //Check, if this branch already exits
fbf811ec 189 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
190 if(gime->BranchExists("SDigits") )
191 return;
a2d8b8a4 192
193 TString sdname(GetName()) ;
194 sdname.Remove(sdname.Index(GetTitle())-1) ;
fbf811ec 195
196 Int_t nevents = gime->MaxEvent() ;
990119d6 197 Int_t ievent ;
7b7c1533 198 for(ievent = 0; ievent < nevents; ievent++){
5ad40cd6 199 gime->Event(ievent,"H") ;
017addb3 200 const TClonesArray * hits = gime->Hits() ;
5ad40cd6 201 TClonesArray * sdigits = gime->SDigits(sdname.Data()) ;
7b7c1533 202 sdigits->Clear();
990119d6 203 Int_t nSdigits = 0 ;
204
7b7c1533 205 //Now make SDigits from hits, for PHOS it is the same, so just copy
fbf811ec 206 Int_t nPrim = static_cast<Int_t>((gAlice->TreeH())->GetEntries()) ;
207 // Attention nPrim is the number of primaries tracked by Geant
208 // and this number could be different to the number of Primaries in TreeK;
209 Int_t iprim ;
210 for (iprim = 0 ; iprim < nPrim ; iprim ++) {
3962b6a1 211 //=========== Get the PHOS branch from Hits Tree for the Primary iprim
212 gime->Track(iprim) ;
990119d6 213 Int_t i;
7b7c1533 214 for ( i = 0 ; i < hits->GetEntries() ; i++ ) {
7a9d98f9 215 AliPHOSHit * hit = dynamic_cast<AliPHOSHit *>(hits->At(i)) ;
990119d6 216 // Assign primary number only if contribution is significant
9688c1dd 217
990119d6 218 if( hit->GetEnergy() > fPrimThreshold)
9688c1dd 219 new((*sdigits)[nSdigits]) AliPHOSDigit(hit->GetPrimary(),hit->GetId(),
fbf811ec 220 Digitize(hit->GetEnergy()), hit->GetTime()) ;
990119d6 221 else
9688c1dd 222 new((*sdigits)[nSdigits]) AliPHOSDigit( -1 , hit->GetId(),
fbf811ec 223 Digitize(hit->GetEnergy()), hit->GetTime()) ;
9688c1dd 224 nSdigits++ ;
990119d6 225
9688c1dd 226 }
fbf811ec 227
3962b6a1 228 } // loop over iprim
990119d6 229
7b7c1533 230 sdigits->Sort() ;
990119d6 231
7b7c1533 232 nSdigits = sdigits->GetEntriesFast() ;
69866bef 233 fSDigitsInRun += nSdigits ;
7b7c1533 234 sdigits->Expand(nSdigits) ;
fbf811ec 235
3962b6a1 236 Int_t i ;
990119d6 237 for (i = 0 ; i < nSdigits ; i++) {
7a9d98f9 238 AliPHOSDigit * digit = dynamic_cast<AliPHOSDigit *>(sdigits->At(i)) ;
990119d6 239 digit->SetIndexInList(i) ;
240 }
3962b6a1 241
fbf811ec 242 //Now write SDigits
243
244 if((gAlice->TreeS() == 0)|| (fSplitFile))
85f78bbc 245 gAlice->MakeTree("S", fSplitFile);
c093f031 246
fbf811ec 247 if(fSplitFile)
248 fSplitFile->cd() ;
249
7acf6008 250 //First list of sdigits
fbf811ec 251 Int_t bufferSize = 32000 ;
7b7c1533 252 TBranch * sdigitsBranch = gAlice->TreeS()->Branch("PHOS",&sdigits,bufferSize);
5ad40cd6 253 sdigitsBranch->SetTitle(sdname);
fbf811ec 254
7b7c1533 255 //Next - SDigitizer
7acf6008 256 Int_t splitlevel = 0 ;
257 AliPHOSSDigitizer * sd = this ;
7b7c1533 258 TBranch * sdigitizerBranch = gAlice->TreeS()->Branch("AliPHOSSDigitizer","AliPHOSSDigitizer",
fbf811ec 259 &sd,bufferSize,splitlevel);
5ad40cd6 260 sdigitizerBranch->SetTitle(sdname);
fbf811ec 261
262 sdigitsBranch->Fill() ;
c093f031 263 sdigitizerBranch->Fill() ;
fbf811ec 264
42d2745f 265 gAlice->TreeS()->AutoSave() ;
fbf811ec 266
7acf6008 267 if(strstr(option,"deb"))
268 PrintSDigits(option) ;
990119d6 269 }
fbf811ec 270
7acf6008 271 if(strstr(option,"tim")){
272 gBenchmark->Stop("PHOSSDigitizer");
21cd0c07 273 Info("Exec"," took %f seconds for SDigitizing %f seconds per event",
274 gBenchmark->GetCpuTime("PHOSSDigitizer"), gBenchmark->GetCpuTime("PHOSSDigitizer")/nevents) ;
7acf6008 275 }
990119d6 276}
106fc2fa 277
990119d6 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 ){
21cd0c07 293 Error("SetSDigitsBranch", "Cannot overwrite existing branch with title %s", title) ;
7b7c1533 294 return ;
295 }
296
21cd0c07 297 Info("SetSDigitsBranch", "-> Changing SDigits file from %s to %s", GetName(), title) ;
7b7c1533 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
106fc2fa 306
990119d6 307//__________________________________________________________________
a4e98857 308void AliPHOSSDigitizer::Print(Option_t* option)const
309{
310 // Prints parameters of SDigitizer
21cd0c07 311 TString message ;
312 message = "\n------------------- %s -------------\n" ;
313 message += " Writing SDigits to branch with title %s\n" ;
314 message += " with digitization parameters A = %f\n" ;
315 message += " B = %f\n" ;
316 message += " Threshold for Primary assignment= %f\n" ;
317 message += "---------------------------------------------------\n" ;
318 Info("Print", message.Data(), GetName(), GetName(), fA, fB, fPrimThreshold ) ;
7acf6008 319
990119d6 320}
548f0134 321
990119d6 322//__________________________________________________________________
a4e98857 323Bool_t AliPHOSSDigitizer::operator==( AliPHOSSDigitizer const &sd )const
324{
3de072dc 325 // Equal operator.
326 // SDititizers are equal if their pedestal, slope and threshold are equal
327
990119d6 328 if( (fA==sd.fA)&&(fB==sd.fB)&&(fPrimThreshold==sd.fPrimThreshold))
329 return kTRUE ;
330 else
331 return kFALSE ;
332}
548f0134 333
a6eedfad 334//__________________________________________________________________
a4e98857 335void AliPHOSSDigitizer::PrintSDigits(Option_t * option)
336{
337 // Prints list of digits produced in the current pass of AliPHOSDigitizer
7b7c1533 338
a6eedfad 339
7b7c1533 340 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
5ad40cd6 341 TString sdname(GetName()) ;
342 sdname.Remove(sdname.Index(GetTitle())-1) ;
21cd0c07 343 const TClonesArray * sdigits = gime->SDigits(sdname.Data()) ;
7b7c1533 344
21cd0c07 345 TString message ;
346 message = "\nAliPHOSSDigitiser: event " ;
347 message += gAlice->GetEvNumber();
348 message += "\n Number of entries in SDigits list " ;
349 message += sdigits->GetEntriesFast() ;
11f9c5ff 350 char * tempo = new char[8192];
21cd0c07 351
a6eedfad 352 if(strstr(option,"all")||strstr(option,"EMC")){
7acf6008 353
354 //loop over digits
355 AliPHOSDigit * digit;
21cd0c07 356 message += "\nEMC sdigits\n" ;
11f9c5ff 357 message += "\n Id Amplitude Time Index Nprim: Primaries list \n" ;
a6eedfad 358 Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
7acf6008 359 Int_t index ;
a6eedfad 360 for (index = 0 ; (index < sdigits->GetEntriesFast()) &&
fbf811ec 361 ((dynamic_cast<AliPHOSDigit *> (sdigits->At(index)))->GetId() <= maxEmc) ; index++) {
362 digit = dynamic_cast<AliPHOSDigit *>( sdigits->At(index) ) ;
21cd0c07 363 if(digit->GetNprimary() == 0)
364 continue;
11f9c5ff 365 sprintf(tempo, "\n%6d %8d %6.5e %4d %2d :",
366 digit->GetId(), digit->GetAmp(), digit->GetTime(), digit->GetIndexInList(), digit->GetNprimary()) ;
367 message += tempo ;
7acf6008 368 Int_t iprimary;
11f9c5ff 369 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
370 sprintf(tempo, "%d ",digit->GetPrimary(iprimary+1) ) ;
371 message += tempo ;
372 }
a6eedfad 373 }
a6eedfad 374 }
375
376 if(strstr(option,"all")||strstr(option,"CPV")){
7acf6008 377
a6eedfad 378 //loop over CPV digits
379 AliPHOSDigit * digit;
21cd0c07 380
381 message += "CPV sdigits\n" ;
11f9c5ff 382 message += "\n Id Amplitude Index Nprim: Primaries list \n" ;
a6eedfad 383 Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
384 Int_t index ;
385 for (index = 0 ; index < sdigits->GetEntriesFast(); index++) {
fbf811ec 386 digit = dynamic_cast<AliPHOSDigit *>( sdigits->At(index) ) ;
a6eedfad 387 if(digit->GetId() > maxEmc){
11f9c5ff 388 sprintf(tempo, "\n%6d %8d %4d %2d :",
389 digit->GetId(), digit->GetAmp(), digit->GetIndexInList(), digit->GetNprimary()) ;
390 message += tempo ;
a6eedfad 391 Int_t iprimary;
21cd0c07 392 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
11f9c5ff 393 sprintf(tempo, "%d ",digit->GetPrimary(iprimary+1) ) ;
394 message += tempo ;
21cd0c07 395 }
a6eedfad 396 }
397 }
7acf6008 398 }
11f9c5ff 399 delete tempo ;
21cd0c07 400 Info("PrintSDigits", message.Data() ) ;
7acf6008 401}
7b7c1533 402
403//____________________________________________________________________________
404void AliPHOSSDigitizer::UseHitsFrom(const char * filename)
405{
406 SetTitle(filename) ;
407 Init() ;
408}