]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSDigitizer.cxx
assert removed
[u/mrichter/AliRoot.git] / PHOS / AliPHOSDigitizer.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//_________________________________________________________________________
990119d6 19//*-- Author : Dmitri Peressounko (SUBATECH & Kurchatov Institute)
20//////////////////////////////////////////////////////////////////////////////
a4e98857 21// This TTask performs digitization of Summable digits (in the PHOS case it is just
22// the sum of contributions from all primary particles into a given cell).
990119d6 23// In addition it performs mixing of summable digits from different events.
7b7c1533 24// The name of the TTask is also the title of the branch that will contain
25// the created SDigits
26// The title of the TTAsk is the name of the file that contains the hits from
27// which the SDigits are created
bca3b32a 28//
29// For each event two branches are created in TreeD:
30// "PHOS" - list of digits
31// "AliPHOSDigitizer" - AliPHOSDigitizer with all parameters used in digitization
32//
a4e98857 33// Note, that one can set a title for new digits branch, and repeat digitization with
bca3b32a 34// another set of parameters.
35//
a4e98857 36// Use case:
990119d6 37// root[0] AliPHOSDigitizer * d = new AliPHOSDigitizer() ;
38// root[1] d->ExecuteTask()
39// Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
40// //Digitizes SDigitis in all events found in file galice.root
bca3b32a 41//
8cb3533f 42// root[2] AliPHOSDigitizer * d1 = new AliPHOSDigitizer("galice1.root") ;
43// // Will read sdigits from galice1.root
44// root[3] d1->MixWith("galice2.root")
990119d6 45// Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
a4e98857 46// // Reads another set of sdigits from galice2.root
8cb3533f 47// root[3] d1->MixWith("galice3.root")
a4e98857 48// // Reads another set of sdigits from galice3.root
8cb3533f 49// root[4] d->ExecuteTask("deb timing")
50// // Reads SDigits from files galice1.root, galice2.root ....
51// // mixes them and stores produced Digits in file galice1.root
52// // deb - prints number of produced digits
53// // deb all - prints list of produced digits
54// // timing - prints time used for digitization
990119d6 55//
990119d6 56
57// --- ROOT system ---
8cb3533f 58#include "TFile.h"
990119d6 59#include "TTree.h"
60#include "TSystem.h"
8cb3533f 61#include "TROOT.h"
62#include "TFolder.h"
63#include "TObjString.h"
b3690abb 64#include "TGeometry.h"
8cb3533f 65#include "TBenchmark.h"
ba54256b 66
990119d6 67// --- Standard library ---
68
69// --- AliRoot header files ---
8cb3533f 70#include "AliRun.h"
b3690abb 71#include "AliHeader.h"
ea5f3389 72#include "AliStream.h"
3f81a70b 73#include "AliRunDigitizer.h"
990119d6 74#include "AliPHOSDigit.h"
dd5c4038 75#include "AliPHOS.h"
7b7c1533 76#include "AliPHOSGetter.h"
990119d6 77#include "AliPHOSDigitizer.h"
78#include "AliPHOSSDigitizer.h"
8cb3533f 79#include "AliPHOSGeometry.h"
7437a0f7 80#include "AliPHOSTick.h"
990119d6 81
82ClassImp(AliPHOSDigitizer)
83
84
85//____________________________________________________________________________
3f81a70b 86 AliPHOSDigitizer::AliPHOSDigitizer()
990119d6 87{
88 // ctor
8d0f3f77 89 InitParameters() ;
9bd3caba 90 fDefaultInit = kTRUE ;
fbf811ec 91 fManager = 0 ; // We work in the standalong mode
548f0134 92
9bd3caba 93 }
3f81a70b 94
95//____________________________________________________________________________
fbf811ec 96AliPHOSDigitizer::AliPHOSDigitizer(const char *headerFile, const char * name, const Bool_t toSplit)
3f81a70b 97{
98 // ctor
ea5f3389 99
3f81a70b 100 SetTitle(headerFile) ;
38bb0fd5 101 SetName(name) ;
9891b76e 102 fManager = 0 ; // We work in the standalong mode
64c73770 103 fSplitFile= 0 ;
8d0f3f77 104 InitParameters() ;
fbf811ec 105 fToSplit = toSplit ;
3f81a70b 106 Init() ;
92f521a9 107 fDefaultInit = kFALSE ;
990119d6 108}
109
990119d6 110//____________________________________________________________________________
9891b76e 111AliPHOSDigitizer::AliPHOSDigitizer(AliRunDigitizer * ard):AliDigitizer(ard)
990119d6 112{
113 // ctor
fbf811ec 114 SetTitle(ard->GetInputFileName(0,0)) ;
b22e4735 115 InitParameters() ;
fbf811ec 116 fDefaultInit = kFALSE ;
117 fSplitFile = 0 ;
118
119 if (ard->GetOutputFile()) {
120 SetName(ard->GetOutputFile().Data());
121 fToSplit = kTRUE ;
122 } else {
123 SetName("Default") ;
124 fToSplit = kFALSE ;
125 }
990119d6 126}
127
128//____________________________________________________________________________
129 AliPHOSDigitizer::~AliPHOSDigitizer()
130{
131 // dtor
548f0134 132
79bb1b62 133 fSplitFile = 0 ;
990119d6 134}
135
136//____________________________________________________________________________
7b7c1533 137void AliPHOSDigitizer::Digitize(const Int_t event)
a4e98857 138{
139
140 // Makes the digitization of the collected summable digits.
141 // It first creates the array of all PHOS modules
142 // filled with noise (different for EMC, CPV and PPSD) and
143 // then adds contributions from SDigits.
144 // This design avoids scanning over the list of digits to add
145 // contribution to new SDigits only.
990119d6 146
7b7c1533 147 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
38bb0fd5 148 TClonesArray * digits = gime->Digits(GetName()) ;
7b7c1533 149
150 digits->Clear() ;
990119d6 151
7b7c1533 152 const AliPHOSGeometry *geom = gime->PHOSGeometry() ;
990119d6 153 //Making digits with noise, first EMC
154 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
155
156 Int_t nCPV ;
990119d6 157 Int_t absID ;
158 TString name = geom->GetName() ;
159
9688c1dd 160 nCPV = nEMC + geom->GetNumberOfCPVPadsZ()*geom->GetNumberOfCPVPadsPhi()*
161 geom->GetNModules() ;
8cb3533f 162
9688c1dd 163 digits->Expand(nCPV) ;
8cb3533f 164
7b7c1533 165 // get first the sdigitizer from the tasks list (must have same name as the digitizer)
92f521a9 166 const AliPHOSSDigitizer * sDigitizer = gime->SDigitizer(GetName());
7b7c1533 167 if ( !sDigitizer) {
f1611b7c 168 Fatal("Digitize", "SDigitizer with name %s not found", GetName() ) ;
7b7c1533 169 }
9688c1dd 170
7b7c1533 171 // loop through the sdigits posted to the White Board and add them to the noise
7a9d98f9 172 TCollection * folderslist = gime->SDigitsFolder()->GetListOfFolders() ;
7b7c1533 173 TIter next(folderslist) ;
174 TFolder * folder = 0 ;
3f81a70b 175 TClonesArray * sdigits = 0 ;
176 Int_t input = 0 ;
9688c1dd 177 TObjArray * sdigArray = new TObjArray(2) ;
38bb0fd5 178 while ( (folder = (TFolder*)next()) ) {
3f81a70b 179 if ( (sdigits = (TClonesArray*)folder->FindObject(GetName()) ) ) {
54b82aa4 180 TString fileName(folder->GetName()) ;
181 fileName.ReplaceAll("_","/") ;
21cd0c07 182// Info("Digitize", "Adding SDigits %s from %s", GetName(), fileName() ) ;
9688c1dd 183 sdigArray->AddAt(sdigits, input) ;
184 input++ ;
185 }
38bb0fd5 186 }
9688c1dd 187
7a9d98f9 188 //Find the first crystall with signal
9688c1dd 189 Int_t nextSig = 200000 ;
190 Int_t i;
191 for(i=0; i<input; i++){
192 sdigits = (TClonesArray *)sdigArray->At(i) ;
a6eedfad 193 if ( !sdigits->GetEntriesFast() )
7a9d98f9 194 continue ;
9688c1dd 195 Int_t curNext = ((AliPHOSDigit *)sdigits->At(0))->GetId() ;
7a9d98f9 196 if(curNext < nextSig)
197 nextSig = curNext ;
9688c1dd 198 }
7437a0f7 199
9688c1dd 200 TArrayI index(input) ;
201 index.Reset() ; //Set all indexes to zero
202
203 AliPHOSDigit * digit ;
204 AliPHOSDigit * curSDigit ;
205
7437a0f7 206 TClonesArray * ticks = new TClonesArray("AliPHOSTick",1000) ;
207
9688c1dd 208 //Put Noise contribution
209 for(absID = 1; absID <= nEMC; absID++){
210 Float_t noise = gRandom->Gaus(0., fPinNoise) ;
211 new((*digits)[absID-1]) AliPHOSDigit( -1,absID,sDigitizer->Digitize(noise), TimeOfNoise() ) ;
212 //look if we have to add signal?
b3690abb 213 digit = (AliPHOSDigit *) digits->At(absID-1) ;
214
9688c1dd 215 if(absID==nextSig){
216 //Add SDigits from all inputs
7437a0f7 217 ticks->Clear() ;
9688c1dd 218 Int_t contrib = 0 ;
7437a0f7 219 Float_t a = digit->GetAmp() ;
220 Float_t b = TMath::Abs( a /fTimeSignalLength) ;
221 //Mark the beginnign of the signal
222 new((*ticks)[contrib++]) AliPHOSTick(digit->GetTime(),0, b);
223 //Mark the end of the ignal
224 new((*ticks)[contrib++]) AliPHOSTick(digit->GetTime()+fTimeSignalLength, -a, -b);
225
9688c1dd 226 //loop over inputs
227 for(i=0; i<input; i++){
5c9dfca0 228 if(((TClonesArray *)sdigArray->At(i))->GetEntriesFast() > index[i] )
229 curSDigit = (AliPHOSDigit*)((TClonesArray *)sdigArray->At(i))->At(index[i]) ;
230 else
231 curSDigit = 0 ;
9688c1dd 232 //May be several digits will contribute from the same input
233 while(curSDigit && curSDigit->GetId() == absID){
234 //Shift primary to separate primaries belonging different inputs
235 Int_t primaryoffset ;
9891b76e 236 if(fManager)
237 primaryoffset = fManager->GetMask(i) ;
9688c1dd 238 else
21c293b7 239 primaryoffset = 10000000*i ;
240 curSDigit->ShiftPrimary(primaryoffset) ;
7437a0f7 241
242 a = curSDigit->GetAmp() ;
243 b = a /fTimeSignalLength ;
244 new((*ticks)[contrib++]) AliPHOSTick(curSDigit->GetTime(),0, b);
245 new((*ticks)[contrib++]) AliPHOSTick(curSDigit->GetTime()+fTimeSignalLength, -a, -b);
9688c1dd 246
247 *digit = *digit + *curSDigit ; //add energies
7437a0f7 248
9688c1dd 249 index[i]++ ;
5c9dfca0 250 if(((TClonesArray *)sdigArray->At(i))->GetEntriesFast() > index[i] )
251 curSDigit = (AliPHOSDigit*)((TClonesArray *)sdigArray->At(i))->At(index[i]) ;
252 else
253 curSDigit = 0 ;
9688c1dd 254 }
255 }
256
257 //calculate and set time
7437a0f7 258 Float_t time = FrontEdgeTime(ticks) ;
9688c1dd 259 digit->SetTime(time) ;
7437a0f7 260
9688c1dd 261 //Find next signal module
7437a0f7 262 nextSig = 200000 ;
9688c1dd 263 for(i=0; i<input; i++){
264 sdigits = ((TClonesArray *)sdigArray->At(i)) ;
5c9dfca0 265 Int_t curNext = nextSig ;
266 if(sdigits->GetEntriesFast() > index[i] ){
267 curNext = ((AliPHOSDigit *) sdigits->At(index[i]))->GetId() ;
268
269 }
9688c1dd 270 if(curNext < nextSig) nextSig = curNext ;
7b7c1533 271 }
272 }
990119d6 273 }
3f81a70b 274
7437a0f7 275 ticks->Delete() ;
276 delete ticks ;
9688c1dd 277
278
279 //Now CPV digits (different noise and no timing)
280 for(absID = nEMC+1; absID <= nCPV; absID++){
281 Float_t noise = gRandom->Gaus(0., fCPVNoise) ;
282 new((*digits)[absID-1]) AliPHOSDigit( -1,absID,sDigitizer->Digitize(noise), TimeOfNoise() ) ;
283 //look if we have to add signal?
284 if(absID==nextSig){
285 digit = (AliPHOSDigit *) digits->At(absID-1) ;
286 //Add SDigits from all inputs
287 for(i=0; i<input; i++){
5c9dfca0 288 if(((TClonesArray *)sdigArray->At(i))->GetEntriesFast() > index[i] )
289 curSDigit = (AliPHOSDigit*)((TClonesArray *)sdigArray->At(i))->At(index[i]) ;
290 else
291 curSDigit = 0 ;
a6eedfad 292
9688c1dd 293 //May be several digits will contribute from the same input
294 while(curSDigit && curSDigit->GetId() == absID){
295 //Shift primary to separate primaries belonging different inputs
296 Int_t primaryoffset ;
9891b76e 297 if(fManager)
298 primaryoffset = fManager->GetMask(i) ;
9688c1dd 299 else
300 primaryoffset = 10000000*i ;
301 curSDigit->ShiftPrimary(primaryoffset) ;
302
303 //add energies
304 *digit = *digit + *curSDigit ;
305 index[i]++ ;
5c9dfca0 306 if(((TClonesArray *)sdigArray->At(i))->GetEntriesFast() > index[i] )
307 curSDigit = (AliPHOSDigit*)((TClonesArray *)sdigArray->At(i))->At(index[i]) ;
308 else
309 curSDigit = 0 ;
9688c1dd 310 }
311 }
a6eedfad 312
9688c1dd 313 //Find next signal module
a6eedfad 314 nextSig = 200000 ;
9688c1dd 315 for(i=0; i<input; i++){
316 sdigits = (TClonesArray *)sdigArray->At(i) ;
5c9dfca0 317 Int_t curNext = nextSig ;
318 if(sdigits->GetEntriesFast() > index[i] )
319 curNext = ((AliPHOSDigit *) sdigits->At(index[i]))->GetId() ;
9688c1dd 320 if(curNext < nextSig) nextSig = curNext ;
321 }
322
323 }
324 }
9688c1dd 325 delete sdigArray ; //We should not delete its contents
326
327
328
990119d6 329 //remove digits below thresholds
a6eedfad 330 for(i = 0; i < nEMC ; i++){
548f0134 331 digit = dynamic_cast<AliPHOSDigit*>( digits->At(i) ) ;
aaf8a71c 332 if(sDigitizer->Calibrate( digit->GetAmp() ) < fEMCDigitThreshold)
a6eedfad 333 digits->RemoveAt(i) ;
aaf8a71c 334 else
335 digit->SetTime(gRandom->Gaus(digit->GetTime(),fTimeResolution) ) ;
336 }
337
a6eedfad 338
339 for(i = nEMC; i < nCPV ; i++)
340 if(sDigitizer->Calibrate(((AliPHOSDigit*)digits->At(i))->GetAmp()) < fCPVDigitThreshold)
341 digits->RemoveAt(i) ;
9688c1dd 342
7b7c1533 343 digits->Compress() ;
990119d6 344
7b7c1533 345 Int_t ndigits = digits->GetEntriesFast() ;
7b7c1533 346 digits->Expand(ndigits) ;
990119d6 347
3758d9fc 348 //Set indexes in list of digits and make true digitization of the energy
990119d6 349 for (i = 0 ; i < ndigits ; i++) {
548f0134 350 digit = dynamic_cast<AliPHOSDigit*>( digits->At(i) ) ;
990119d6 351 digit->SetIndexInList(i) ;
f672adc8 352 Float_t energy = sDigitizer->Calibrate(digit->GetAmp()) ;
3758d9fc 353 digit->SetAmp(DigitizeEnergy(energy,digit->GetId()) ) ;
990119d6 354 }
990119d6 355
7b7c1533 356}
548f0134 357
3758d9fc 358//____________________________________________________________________________
359Int_t AliPHOSDigitizer::DigitizeEnergy(Float_t energy, Int_t absId)
360{
0bc3b8ed 361 // Returns digitized value of the energy in a cell absId
362
3758d9fc 363 Int_t chanel ;
364 if(absId <= fEmcCrystals){ //digitize as EMC
365 chanel = (Int_t) TMath::Ceil((energy - fADCpedestalEmc)/fADCchanelEmc) ;
366 if(chanel > fNADCemc ) chanel = fNADCemc ;
367 }
368 else{ //Digitize as CPV
369 chanel = (Int_t) TMath::Ceil((energy - fADCpedestalCpv)/fADCchanelCpv) ;
370 if(chanel > fNADCcpv ) chanel = fNADCcpv ;
371 }
372 return chanel ;
373}
548f0134 374
7b7c1533 375//____________________________________________________________________________
376void AliPHOSDigitizer::Exec(Option_t *option)
377{
378 // Managing method
990119d6 379
f672adc8 380 if(strcmp(GetName(), "") == 0 )
7b7c1533 381 Init() ;
7b7c1533 382 if (strstr(option,"print")) {
383 Print("");
384 return ;
8cb3533f 385 }
990119d6 386
7b7c1533 387 if(strstr(option,"tim"))
388 gBenchmark->Start("PHOSDigitizer");
8cb3533f 389
3f81a70b 390 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
391
392 Int_t nevents ;
393
394 TTree * treeD ;
395
9891b76e 396 if(fManager){
397 treeD = fManager->GetTreeD() ;
3f81a70b 398 nevents = 1 ; // Will process only one event
8cb3533f 399
fbf811ec 400 //Check, if this branch already exits
401 if (treeD) {
402 TObjArray * lob = (TObjArray*)treeD->GetListOfBranches() ;
403 TIter next(lob) ;
404 TBranch * branch = 0 ;
405 Bool_t phosfound = kFALSE, digitizerfound = kFALSE ;
b3690abb 406
fbf811ec 407 while ( (branch = (TBranch*)next()) && (!phosfound || !digitizerfound) ) {
408 if ( (strcmp(branch->GetName(), "PHOS")==0) &&
409 (strcmp(branch->GetTitle(), GetName())==0) )
410 phosfound = kTRUE ;
411
412 else if ( (strcmp(branch->GetName(), "AliPHOSDigitizer")==0) &&
413 (strcmp(branch->GetTitle(), GetName())==0) )
414 digitizerfound = kTRUE ;
415 }
416
417 if ( phosfound ) {
21cd0c07 418 Error("Exec", "Digits branch with name %s already exists", GetName() ) ;
fbf811ec 419 return ;
420 }
421 if ( digitizerfound ) {
21cd0c07 422 Error("Exec", "Digitizer branch with name %s already exists", GetName() );
fbf811ec 423 return ;
424 }
b3690abb 425 }
8cb3533f 426 }
fbf811ec 427 else { //PHOS standalone
428 if(gime->BranchExists("Digits") )
429 return ;
430 nevents=gime->MaxEvent() ;
431 }
432
7b7c1533 433 Int_t ievent ;
b3690abb 434
7b7c1533 435 for(ievent = 0; ievent < nevents; ievent++){
b3690abb 436
9891b76e 437 if(fManager){
b22e4735 438
3f81a70b 439 Int_t input ;
9891b76e 440 for(input = 0 ; input < fManager->GetNinputs(); input ++){
441 TTree * treeS = fManager->GetInputTreeS(input) ;
3f81a70b 442 if(!treeS){
21cd0c07 443 Error("Exec", "No Input") ;
3f81a70b 444 return ;
445 }
446 gime->ReadTreeS(treeS,input) ;
447 }
b22e4735 448
3f81a70b 449 }
450 else
451 gime->Event(ievent,"S") ;
990119d6 452
7b7c1533 453 Digitize(ievent) ; //Add prepared SDigits to digits and add the noise
3f81a70b 454
7b7c1533 455 WriteDigits(ievent) ;
3f81a70b 456
01a599c9 457 if(strstr(option,"deb"))
458 PrintDigits(option);
94de8339 459
460 //increment the total number of Digits per run
461 fDigitsInRun += gime->Digits()->GetEntriesFast() ;
01a599c9 462 }
8d0f3f77 463
8cb3533f 464 if(strstr(option,"tim")){
465 gBenchmark->Stop("PHOSDigitizer");
21cd0c07 466 TString message ;
467 message = " took %f seconds for Digitizing %f seconds per event\n" ;
468 Info("Exec", message.Data(),
469 gBenchmark->GetCpuTime("PHOSDigitizer"),
470 gBenchmark->GetCpuTime("PHOSDigitizer")/nevents );
471 }
990119d6 472}
473
9688c1dd 474//____________________________________________________________________________
0bc3b8ed 475Float_t AliPHOSDigitizer::FrontEdgeTime(TClonesArray * ticks) const
476{
477 // Returns the shortest time among all time ticks
478
7437a0f7 479 ticks->Sort() ; //Sort in accordance with times of ticks
480 TIter it(ticks) ;
481 AliPHOSTick * ctick = (AliPHOSTick *) it.Next() ;
482 Float_t time = ctick->CrossingTime(fTimeThreshold) ;
483
484 AliPHOSTick * t ;
485 while((t=(AliPHOSTick*) it.Next())){
486 if(t->GetTime() < time) //This tick starts before crossing
487 *ctick+=*t ;
488 else
489 return time ;
490
491 time = ctick->CrossingTime(fTimeThreshold) ;
9688c1dd 492 }
493 return time ;
9688c1dd 494}
8d0f3f77 495
7b7c1533 496//____________________________________________________________________________
3f81a70b 497Bool_t AliPHOSDigitizer::Init()
8d0f3f77 498{
fbf811ec 499 // Makes all memory allocations
500
501 if( strcmp(GetTitle(), "") == 0 )
502 SetTitle("galice.root") ;
3bf72d32 503
fbf811ec 504 AliPHOSGetter * gime = AliPHOSGetter::GetInstance(GetTitle(), GetName(), fToSplit) ;
8d0f3f77 505 if ( gime == 0 ) {
21cd0c07 506 Error("Init", "Could not obtain the Getter object !") ;
8d0f3f77 507 return kFALSE;
508 }
509
510 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
b22e4735 511
8d0f3f77 512 fEmcCrystals = geom->GetNModules() * geom->GetNCristalsInModule() ;
513
514 // Post Digits to the white board
515 gime->PostDigits(GetName() ) ;
516
517 // Post Digitizer to the white board
518 gime->PostDigitizer(this) ;
fbf811ec 519
520 fSplitFile = 0 ;
521 if(fToSplit){
522 // construct the name of the file as /path/PHOS.SDigits.root
523 //First - extract full path if necessary
524 TString digitsFileName(GetTitle()) ;
525 Ssiz_t islash = digitsFileName.Last('/') ;
526 if(islash<digitsFileName.Length())
527 digitsFileName.Remove(islash+1,digitsFileName.Length()) ;
528 else
529 digitsFileName="" ;
530 // Next - append the file name
531 digitsFileName+="PHOS.Digits." ;
532 if((strcmp(GetName(),"Default")!=0)&&(strcmp(GetName(),"")!=0)){
533 digitsFileName+=GetName() ;
534 digitsFileName+="." ;
535 }
536 digitsFileName+="root" ;
537 // Finally - check if the file already opened or open the file
538 fSplitFile = static_cast<TFile*>(gROOT->GetFile(digitsFileName.Data()));
539 if(!fSplitFile)
540 fSplitFile = TFile::Open(digitsFileName.Data(),"update") ;
541 }
8d0f3f77 542
543 //Mark that we will use current header file
544 if(!fManager){
545 gime->PostSDigits(GetName(),GetTitle()) ;
546 gime->PostSDigitizer(GetName(),GetTitle()) ;
547 }
548 return kTRUE ;
549}
550
551//____________________________________________________________________________
552void AliPHOSDigitizer::InitParameters()
a4e98857 553{
0bc3b8ed 554 // Set initial parameters for Digitizer
555
c74936f1 556 fPinNoise = 0.004 ;
557 fEMCDigitThreshold = 0.012 ;
3758d9fc 558 fCPVNoise = 0.01;
559 fCPVDigitThreshold = 0.09 ;
aaf8a71c 560 fTimeResolution = 0.5e-9 ;
3758d9fc 561 fTimeSignalLength = 1.0e-9 ;
562 fDigitsInRun = 0 ;
563 fADCchanelEmc = 0.0015; // width of one ADC channel in GeV
564 fADCpedestalEmc = 0.005 ; //
565 fNADCemc = (Int_t) TMath::Power(2,16) ; // number of channels in EMC ADC
566
567 fADCchanelCpv = 0.0012 ; // width of one ADC channel in CPV 'popugais'
568 fADCpedestalCpv = 0.012 ; //
569 fNADCcpv = (Int_t) TMath::Power(2,12); // number of channels in CPV ADC
570
571 fTimeThreshold = 0.001*10000000 ; //Means 1 MeV in terms of SDigits amplitude
8cb3533f 572
990119d6 573}
7b7c1533 574
990119d6 575//__________________________________________________________________
58649d9d 576void AliPHOSDigitizer::MixWith(const char* headerFile,const char* brname)
a4e98857 577{
ba54256b 578 // Allows to produce digits by superimposing background and signal event.
bca3b32a 579 // It is assumed, that headers file with SIGNAL events is opened in
a4e98857 580 // the constructor.
581 // Sets the BACKGROUND event, with which the SIGNAL event is to be mixed
582 // Thus we avoid writing (changing) huge and expensive
bca3b32a 583 // backgound files: all output will be writen into SIGNAL, i.e.
584 // opened in constructor file.
585 //
a4e98857 586 // One can open as many files to mix with as one needs.
7b7c1533 587 // However only Sdigits with the same name (i.e. constructed with the same SDigitizer)
588 // can be mixed.
bca3b32a 589
7b7c1533 590 if( strcmp(GetName(), "") == 0 )
8cb3533f 591 Init() ;
592
9891b76e 593 if(fManager){
21cd0c07 594 Warning("MixWith", "Can not use this method under AliRunDigitizer\n" ) ;
3f81a70b 595 return ;
596 }
7b7c1533 597
598 // check if the specified SDigits do not already exist on the White Board:
aad24ee7 599 // //Folders/RunMC/Event/Data/PHOS/SDigits/headerFile/sdigitsname
990119d6 600
548f0134 601 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
602 TString path = gime->SDigitsFolder()->GetName() ;
603
604 // before it was ???? "Folders/RunMC/Event/Data/PHOS/SDigits" ;
7b7c1533 605 path += headerFile ;
606 path += "/" ;
58649d9d 607 if(brname)
608 path += brname ;
609 else
610 path += GetName() ;
7b7c1533 611 if ( gROOT->FindObjectAny(path.Data()) ) {
21cd0c07 612 Warning("MixWith", "Entry already exists, do not add\n" ) ;
7b7c1533 613 return;
990119d6 614 }
3f81a70b 615 gime->PostSDigits(GetName(),headerFile) ;
7b7c1533 616 // check if the requested file is already open or exist and if SDigits Branch exist
58649d9d 617 TFile * file = (TFile*)gROOT->GetFile(headerFile);
7b7c1533 618 if ( !file ) {
619 file = new TFile(headerFile, "READ") ;
620 if (!file) {
21cd0c07 621 Error("MixWith", "File %s does not exist\n", headerFile );
7b7c1533 622 return ;
623 }
624 }
990119d6 625}
7b7c1533 626
990119d6 627//__________________________________________________________________
21cd0c07 628void AliPHOSDigitizer::Print(Option_t* option)const
629{
dd5c4038 630 // Print Digitizer's parameters
7b7c1533 631 if( strcmp(GetName(), "") != 0 ){
fbf811ec 632
21cd0c07 633 TString message("\n-------------------") ;
634 message += GetName() ;
635 message += "-------------\n" ;
6e89b8da 636
0bc3b8ed 637 const Int_t kNStreams = GetNInputStreams() ;
638 if (kNStreams) {
6e89b8da 639 Int_t index = 0 ;
0bc3b8ed 640 for (index = 0 ; index < kNStreams ; index++) {
21cd0c07 641 message += "Adding SDigits " ;
642 message += GetName() ;
643 message += "from " ;
644 message += fManager->GetInputFileName(index, 0) ;
645 }
646 message += "\nWriting digits to " ;
647 message += fManager->GetInputFileName(0, 0) ;
6e89b8da 648 } else {
21cd0c07 649 // AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
650 // gime->Folder("sdigits") ;
651 // TCollection * folderslist = gime->Folder("sdigits")->GetListOfFolders() ;
652 // TIter next(folderslist) ;
653 // TFolder * folder = 0 ;
ea5f3389 654
21cd0c07 655 // while ( (folder = (TFolder*)next()) ) {
656 // if ( folder->FindObject(GetName()) )
657 // }
658 message += "\nWriting digits to " ;
659 message += GetTitle() ;
ea5f3389 660 }
21cd0c07 661 message += "\nWith following parameters:\n" ;
662 message += " Electronics noise in EMC (fPinNoise) = %f\n" ;
663 message += " Threshold in EMC (fEMCDigitThreshold) = %f\n" ;
664 message += " Noise in CPV (fCPVNoise) = %f\n" ;
665 message += " Threshold in CPV (fCPVDigitThreshold) = %f\n" ;
666 message += "---------------------------------------------------\n" ;
667 Info("Print", message.Data(),
668 fPinNoise,
669 fEMCDigitThreshold,
670 fCPVNoise,
671 fCPVDigitThreshold ) ;
990119d6 672 }
8cb3533f 673 else
21cd0c07 674 Info("Print", "AliPHOSDigitizer not initialized\n" ) ;
8cb3533f 675
676}
21cd0c07 677
8cb3533f 678//__________________________________________________________________
21cd0c07 679 void AliPHOSDigitizer::PrintDigits(Option_t * option)
680{
3bf72d32 681 // Print a table of digits
21cd0c07 682
3bf72d32 683 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
684 TClonesArray * digits = gime->Digits() ;
685
686 TString message ;
687 message = "\nevent " ;
688 message += gAlice->GetEvNumber() ;
689 message += "\n Number of entries in Digits list " ;
690 message += digits->GetEntriesFast() ;
11f9c5ff 691 char * tempo = new char[8192];
692
3bf72d32 693 if(strstr(option,"all")||strstr(option,"EMC")){
8cb3533f 694 //loop over digits
695 AliPHOSDigit * digit;
3bf72d32 696 message += "\nEMC digits (with primaries):\n" ;
11f9c5ff 697 message += "\n Id Amplitude Time Index Nprim: Primaries list \n" ;
9688c1dd 698 Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
8cb3533f 699 Int_t index ;
a6eedfad 700 for (index = 0 ; (index < digits->GetEntriesFast()) &&
3bf72d32 701 (((AliPHOSDigit * ) digits->At(index))->GetId() <= maxEmc) ; index++) {
7b7c1533 702 digit = (AliPHOSDigit * ) digits->At(index) ;
21cd0c07 703 if(digit->GetNprimary() == 0)
704 continue;
11f9c5ff 705 sprintf(tempo, "\n%6d %8d %6.5e %4d %2d :",
706 digit->GetId(), digit->GetAmp(), digit->GetTime(), digit->GetIndexInList(), digit->GetNprimary()) ;
707 message += tempo ;
8cb3533f 708 Int_t iprimary;
21cd0c07 709 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
11f9c5ff 710 sprintf(tempo, "%d ",digit->GetPrimary(iprimary+1) ) ;
711 message += tempo ;
21cd0c07 712 }
713 }
9688c1dd 714 }
3bf72d32 715
9688c1dd 716 if(strstr(option,"all")||strstr(option,"CPV")){
8cb3533f 717
9688c1dd 718 //loop over CPV digits
719 AliPHOSDigit * digit;
3bf72d32 720 message += "\nCPV digits:\n" ;
11f9c5ff 721 message += "\n Id Amplitude Index Nprim: Primaries list \n" ;
3bf72d32 722
9688c1dd 723 Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
724 Int_t index ;
a6eedfad 725 for (index = 0 ; index < digits->GetEntriesFast(); index++) {
9688c1dd 726 digit = (AliPHOSDigit * ) digits->At(index) ;
727 if(digit->GetId() > maxEmc){
11f9c5ff 728 sprintf(tempo, "\n%6d %8d %4d %2d :",
729 digit->GetId(), digit->GetAmp(), digit->GetIndexInList(), digit->GetNprimary()) ;
730 message += tempo ;
9688c1dd 731 Int_t iprimary;
21cd0c07 732 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
11f9c5ff 733 sprintf(tempo, "%d ",digit->GetPrimary(iprimary+1) ) ;
734 message += tempo ;
21cd0c07 735 }
736 }
9688c1dd 737 }
8cb3533f 738 }
11f9c5ff 739 delete tempo ;
3bf72d32 740 Info("Print", message.Data() ) ;
8cb3533f 741}
7b7c1533 742
9688c1dd 743//__________________________________________________________________
0bc3b8ed 744Float_t AliPHOSDigitizer::TimeOfNoise(void) const
9688c1dd 745{ // Calculates the time signal generated by noise
746 //to be rewritten, now returns just big number
747 return 1. ;
748
8cb3533f 749}
7b7c1533 750
751//____________________________________________________________________________
752void AliPHOSDigitizer::WriteDigits(Int_t event)
753{
754
755 // Makes TreeD in the output file.
756 // Check if branch already exists:
757 // if yes, exit without writing: ROOT TTree does not support overwriting/updating of
758 // already existing branches.
759 // else creates branch with Digits, named "PHOS", title "...",
760 // and branch "AliPHOSDigitizer", with the same title to keep all the parameters
761 // and names of files, from which digits are made.
762
763 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
aad24ee7 764 const TClonesArray * digits = gime->Digits(GetName()) ;
8d0f3f77 765 TTree * treeD ;
fbf811ec 766
767 if(fManager)
768 treeD = fManager->GetTreeD() ;
769 else {
770 if((gAlice->TreeD() == 0) || (fSplitFile)) // we should not create TreeD if it is already here
771 gAlice->MakeTree("D", fSplitFile); // We overwrite TreeD in split file in the case of second reconstruction
772 if(fSplitFile)
773 fSplitFile->cd() ;
774 treeD = gAlice->TreeD();
775 }
776
7b7c1533 777 // -- create Digits branch
778 Int_t bufferSize = 32000 ;
ba54256b 779 TBranch * digitsBranch = treeD->Branch("PHOS",&digits,bufferSize);
7b7c1533 780 digitsBranch->SetTitle(GetName());
fbf811ec 781
7b7c1533 782 // -- Create Digitizer branch
783 Int_t splitlevel = 0 ;
c2cd5471 784 const AliPHOSDigitizer * d = dynamic_cast<const AliPHOSDigitizer *>(gime->Digitizer()) ;
ba54256b 785 TBranch * digitizerBranch = treeD->Branch("AliPHOSDigitizer", "AliPHOSDigitizer", &d,bufferSize,splitlevel);
7b7c1533 786 digitizerBranch->SetTitle(GetName());
b3690abb 787
ec85099a 788 digitsBranch->Fill() ;
64c73770 789 digitizerBranch->Fill() ;
b3690abb 790 treeD->AutoSave() ;
7b7c1533 791}