these TTask are posted to the apropriate folders //YSAlice/tasks/(S)Digitizer and...
[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.
bca3b32a 24//
25// For each event two branches are created in TreeD:
26// "PHOS" - list of digits
27// "AliPHOSDigitizer" - AliPHOSDigitizer with all parameters used in digitization
28//
a4e98857 29// Note, that one can set a title for new digits branch, and repeat digitization with
bca3b32a 30// another set of parameters.
31//
a4e98857 32// Use case:
990119d6 33// root[0] AliPHOSDigitizer * d = new AliPHOSDigitizer() ;
34// root[1] d->ExecuteTask()
35// Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
36// //Digitizes SDigitis in all events found in file galice.root
bca3b32a 37//
8cb3533f 38// root[2] AliPHOSDigitizer * d1 = new AliPHOSDigitizer("galice1.root") ;
39// // Will read sdigits from galice1.root
40// root[3] d1->MixWith("galice2.root")
990119d6 41// Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
a4e98857 42// // Reads another set of sdigits from galice2.root
8cb3533f 43// root[3] d1->MixWith("galice3.root")
a4e98857 44// // Reads another set of sdigits from galice3.root
8cb3533f 45// root[4] d->ExecuteTask("deb timing")
46// // Reads SDigits from files galice1.root, galice2.root ....
47// // mixes them and stores produced Digits in file galice1.root
48// // deb - prints number of produced digits
49// // deb all - prints list of produced digits
50// // timing - prints time used for digitization
990119d6 51//
990119d6 52
53// --- ROOT system ---
8cb3533f 54#include "TFile.h"
990119d6 55#include "TTree.h"
56#include "TSystem.h"
8cb3533f 57#include "TROOT.h"
58#include "TFolder.h"
59#include "TObjString.h"
60#include "TBenchmark.h"
990119d6 61// --- Standard library ---
8cb3533f 62#include <iomanip.h>
990119d6 63
64// --- AliRoot header files ---
65
8cb3533f 66#include "AliRun.h"
990119d6 67#include "AliPHOSDigit.h"
dd5c4038 68#include "AliPHOS.h"
990119d6 69#include "AliPHOSDigitizer.h"
70#include "AliPHOSSDigitizer.h"
8cb3533f 71#include "AliPHOSGeometry.h"
990119d6 72
73ClassImp(AliPHOSDigitizer)
74
75
76//____________________________________________________________________________
77 AliPHOSDigitizer::AliPHOSDigitizer():TTask("AliPHOSDigitizer","")
78{
79 // ctor
80
2bd5457f 81 fSDigitizer = 0 ;
82
83 fNinputs = 1 ;
84 fPinNoise = 0.01 ;
85 fEMCDigitThreshold = 0.01 ;
86 fCPVNoise = 0.01;
87 fCPVDigitThreshold = 0.09 ;
88 fPPSDNoise = 0.0000001;
89 fPPSDDigitThreshold = 0.0000002 ;
90 fInitialized = kFALSE ;
91
92 fHeaderFiles = 0;
93 fSDigitsTitles = 0;
94 fSDigits = 0 ;
95 fDigits = 0;
990119d6 96
97}
98//____________________________________________________________________________
a4e98857 99void AliPHOSDigitizer::Init()
100{
101 // Makes all memory allocations
2bd5457f 102 // Adds Digitizer task to the folder of PHOS tasks
a4e98857 103
990119d6 104 if(!fInitialized){
8cb3533f 105
2bd5457f 106 if (fHeaderFiles == 0) {
107 fHeaderFiles = new TClonesArray("TObjString",1) ;
108 new((*fHeaderFiles)[0]) TObjString("galice.root") ;
109 }
8cb3533f 110
111 //Test, if this file already open
112
113 TFile *file = (TFile*) gROOT->GetFile(((TObjString *) fHeaderFiles->At(0))->GetString() ) ;
114
2bd5457f 115 if(file==0){
116 if(((TObjString *) fHeaderFiles->At(0))->GetString().Contains("rfio"))
117 file = TFile::Open(((TObjString *) fHeaderFiles->At(0))->GetString(),"update") ;
118 else
119 file = new TFile(((TObjString *) fHeaderFiles->At(0))->GetString(),"update") ;
120 gAlice = (AliRun *) file->Get("gAlice") ; //If not read yet
8cb3533f 121 }
990119d6 122 else
123 file = new TFile(((TObjString *) fHeaderFiles->At(0))->GetString()) ;
8cb3533f 124
990119d6 125 file->cd() ;
8cb3533f 126
2bd5457f 127 if (fSDigitsTitles == 0) {
128 fSDigitsTitles = new TClonesArray("TObjString",1);
129 new((*fSDigitsTitles)[0]) TObjString("") ;
130 }
990119d6 131
132 fSDigits = new TClonesArray("TClonesArray",1) ;
133 new((*fSDigits)[0]) TClonesArray("AliPHOSDigit",1000) ;
8cb3533f 134
bca3b32a 135 fSDigitizer = 0 ;
136
8cb3533f 137 fDigitsTitle = "" ;
990119d6 138
139 fDigits = new TClonesArray("AliPHOSDigit",200000) ;
140
141 fIevent = new TArrayI(1) ;
142 fIevent->AddAt(-1,0 ) ;
143 fIeventMax = new TArrayI(1) ;
8cb3533f 144
145 fIeventMax->AddAt((Int_t) gAlice->TreeE()->GetEntries(), 0 );
146
2bd5457f 147 //add Task to //YSAlice/tasks/(S)Diditizer/PHOS
148 TFolder * alice = (TFolder*)gROOT->GetListOfBrowsables()->FindObject("YSAlice") ;
149 TTask * aliceSD = (TTask*)alice->FindObject("tasks/(S)Digitizer") ;
150 TTask * phosSD = (TTask*)aliceSD->GetListOfTasks()->FindObject("PHOS") ;
151 phosSD->Add(this) ;
8cb3533f 152
990119d6 153 fInitialized = kTRUE ;
154 }
990119d6 155}
156
990119d6 157//____________________________________________________________________________
f035f6ce 158AliPHOSDigitizer::AliPHOSDigitizer(const char *headerFile,const char *sDigitsTitle):
8cb3533f 159 TTask("AliPHOSDigitizer","")
990119d6 160{
161 // ctor
8cb3533f 162 fHeaderFiles = new TClonesArray("TObjString",1) ;
f035f6ce 163 new((*fHeaderFiles)[0]) TObjString(headerFile) ;
8cb3533f 164
8cb3533f 165 fSDigitsTitles = new TClonesArray("TObjString",1); // Title name of the SDigits branch
166 new((*fSDigitsTitles)[0]) TObjString(sDigitsTitle) ;
990119d6 167
2bd5457f 168 fNinputs = 1 ;
169 fPinNoise = 0.01 ;
170 fEMCDigitThreshold = 0.01 ;
171 fCPVNoise = 0.01;
172 fCPVDigitThreshold = 0.09 ;
173 fPPSDNoise = 0.0000001;
990119d6 174 fPPSDDigitThreshold = 0.0000002 ;
2bd5457f 175 fInitialized = kFALSE ;
176
177 Init() ;
8cb3533f 178
990119d6 179}
180
181//____________________________________________________________________________
182 AliPHOSDigitizer::~AliPHOSDigitizer()
183{
184 // dtor
8cb3533f 185
186 if(fHeaderFiles) delete fHeaderFiles ;
187 if(fSDigitsTitles) delete fSDigitsTitles ;
188 if(fSDigits) delete fSDigits ;
189 if(fDigits) delete fDigits ;
190}
191//____________________________________________________________________________
a4e98857 192void AliPHOSDigitizer::Reset()
193{
194 // sets current event number to the first simulated event
8cb3533f 195
196 if(!fInitialized)
197 Init() ;
198
199 Int_t inputs ;
200 for(inputs = 0; inputs < fNinputs ;inputs++)
201 fIevent->AddAt(-1, inputs ) ;
202
990119d6 203}
204//____________________________________________________________________________
a4e98857 205Bool_t AliPHOSDigitizer::Combinator()
206{
207 // Makes all desirable combinations of Signal+Background,
208 // returns kFALSE when all combinations are made.
209 // May be useful to introduce options like "One-to-One", "All-to-One" and "All-to-All" ?
dd5c4038 210 //realizing "One-to-One" option...
990119d6 211
212 if(!fInitialized)
8cb3533f 213 Init() ;
990119d6 214
215 Int_t inputs ;
216 Bool_t endNotReached = kTRUE ;
217
218 for(inputs = 0; (inputs < fNinputs) && endNotReached ;inputs++){
219 if(fIevent->At(inputs)+1 < fIeventMax->At(inputs))
220 fIevent->AddAt(fIevent->At(inputs)+1, inputs ) ;
221 else
8cb3533f 222 if(inputs == 0)
223 endNotReached = kFALSE ;
224 else //for inputs other than base one start from the beginning
225 fIevent->AddAt(0, inputs ) ;
226
990119d6 227 }
228 return endNotReached ;
8cb3533f 229
990119d6 230}
231
232//____________________________________________________________________________
a4e98857 233void AliPHOSDigitizer::Digitize(Option_t *option)
234{
235
236 // Makes the digitization of the collected summable digits.
237 // It first creates the array of all PHOS modules
238 // filled with noise (different for EMC, CPV and PPSD) and
239 // then adds contributions from SDigits.
240 // This design avoids scanning over the list of digits to add
241 // contribution to new SDigits only.
990119d6 242
243 if(!fInitialized)
8cb3533f 244 Init() ;
990119d6 245
246 fDigits->Clear() ;
247
dd5c4038 248 AliPHOS * phos = (AliPHOS *) gAlice->GetDetector("PHOS") ;
249 AliPHOSGeometry *geom = AliPHOSGeometry::GetInstance( phos->GetGeometry()->GetName(), phos->GetGeometry()->GetTitle() );
990119d6 250
251 //Making digits with noise, first EMC
252 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
253
254 Int_t nCPV ;
255 Int_t nPPSD ;
256 Int_t absID ;
257 TString name = geom->GetName() ;
258
259 if ( name == "IHEP" || name == "MIXT" )
260 nCPV =nEMC + geom->GetNumberOfCPVPadsZ()*geom->GetNumberOfCPVPadsPhi()*
261 geom->GetNCPVModules()*geom->GetNumberOfCPVLayers() ;
262 else
263 nCPV = nEMC;
264
265 if ( name == "GPS2" || name == "MIXT" )
266 nPPSD =nCPV+2*geom->GetNPPSDModules()*geom->GetNumberOfModulesPhi()*geom->GetNumberOfModulesZ()*
267 geom->GetNumberOfPadsPhi()*geom->GetNumberOfPadsZ() ;
268 else
269 nPPSD = nCPV;
8cb3533f 270
271
272 fDigits->Expand(nPPSD) ;
273
990119d6 274
275 for(absID = 1; absID <= nEMC; absID++){
276 Float_t noise = gRandom->Gaus(0., fPinNoise) ;
277 new((*fDigits)[absID-1]) AliPHOSDigit( -1,absID,fSDigitizer->Digitize(noise) ) ;
278 }
279
280 for(absID = nEMC+1; absID <= nCPV; absID++){
281 Float_t noise = gRandom->Gaus(0., fCPVNoise) ;
282 new((*fDigits)[absID-1]) AliPHOSDigit( -1,absID,fSDigitizer->Digitize(noise) ) ;
283 }
284
285 for(absID = nCPV+1; absID <= nPPSD; absID++){
286 Float_t noise = gRandom->Gaus(0., fPPSDNoise) ;
287 new((*fDigits)[absID-1]) AliPHOSDigit( -1,absID,fSDigitizer->Digitize(noise) ) ;
288 }
289
290
291 // Now look throught (unsorted) list of SDigits and add corresponding digits
292 AliPHOSDigit *curSDigit ;
293 AliPHOSDigit *digit ;
294
295 Int_t inputs;
296 for(inputs = 0; inputs< fNinputs ; inputs++){ //loop over (possible) merge sources
297
298 TClonesArray * sdigits= (TClonesArray *)fSDigits->At(inputs) ;
299 Int_t isdigit ;
8cb3533f 300
990119d6 301 Int_t nSDigits = sdigits->GetEntries() ;
302 for(isdigit=0;isdigit< nSDigits; isdigit++){
303 curSDigit = (AliPHOSDigit *)sdigits->At(isdigit) ;
304 if(inputs) //Shift primaries for non-background sdigits
305 curSDigit->ShiftPrimary(inputs) ;
306 digit = (AliPHOSDigit *)fDigits->At(curSDigit->GetId() - 1);
307 *digit = *digit + *curSDigit ;
308 }
309 }
310
311
990119d6 312 //remove digits below thresholds
313 for(absID = 0; absID < nEMC ; absID++)
314 if(fSDigitizer->Calibrate(((AliPHOSDigit*)fDigits->At(absID))->GetAmp()) < fEMCDigitThreshold)
315 fDigits->RemoveAt(absID) ;
316 for(absID = nEMC; absID < nCPV ; absID++)
317 if(fSDigitizer->Calibrate(((AliPHOSDigit*)fDigits->At(absID))->GetAmp()) < fCPVDigitThreshold)
318 fDigits->RemoveAt(absID) ;
319 for(absID = nCPV; absID < nPPSD ; absID++)
320 if(fSDigitizer->Calibrate(((AliPHOSDigit *)fDigits->At(absID))->GetAmp()) < fPPSDDigitThreshold)
321 fDigits->RemoveAt(absID) ;
322
323 fDigits->Compress() ;
324
8cb3533f 325 Int_t ndigits = fDigits->GetEntriesFast() ;
326
990119d6 327 fDigits->Expand(ndigits) ;
328
329
330 //Set indexes in list of digits
331 Int_t i ;
332 for (i = 0 ; i < ndigits ; i++) {
333 AliPHOSDigit * digit = (AliPHOSDigit *) fDigits->At(i) ;
334 digit->SetIndexInList(i) ;
335 }
336}
337//____________________________________________________________________________
a4e98857 338void AliPHOSDigitizer::WriteDigits()
339{
990119d6 340
a4e98857 341 // Makes TreeD in the output file.
342 // Check if branch already exists:
343 // if yes, exit without writing: ROOT TTree does not support overwriting/updating of
344 // already existing branches.
345 // else creates branch with Digits, named "PHOS", title "...",
346 // and branch "AliPHOSDigitizer", with the same title to keep all the parameters
347 // and names of files, from which digits are made.
990119d6 348
8cb3533f 349 gAlice->GetEvent(fIevent->At(0)) ; // Suitable only for One-To-One mixing
350 gAlice->SetEvent(fIevent->At(0)) ; // for all-to-all will produce a lot of branches in TreeD
990119d6 351
352 if(gAlice->TreeD()==0)
761e34c0 353 gAlice->MakeTree("D") ;
990119d6 354
8cb3533f 355 //Check, if this branch already exits?
356 TBranch * digitsBranch = 0;
357 TBranch * digitizerBranch = 0;
358
359 TObjArray * branches = gAlice->TreeD()->GetListOfBranches() ;
360 Int_t ibranch;
361 Bool_t phosNotFound = kTRUE ;
362 Bool_t digitizerNotFound = kTRUE ;
363
364 for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){
365
366 if(phosNotFound){
367 digitsBranch=(TBranch *) branches->At(ibranch) ;
368 if( (strcmp("PHOS",digitsBranch->GetName())==0 ) &&
369 (fDigitsTitle.CompareTo(digitsBranch->GetTitle()) == 0) )
370 phosNotFound = kFALSE ;
990119d6 371 }
8cb3533f 372 if(digitizerNotFound){
373 digitizerBranch = (TBranch *) branches->At(ibranch) ;
374 if( (strcmp(digitizerBranch->GetName(),"AliPHOSDigitizer") == 0) &&
375 (fDigitsTitle.CompareTo(digitizerBranch->GetTitle()) == 0))
376 digitizerNotFound = kFALSE ;
377 }
378 }
990119d6 379
8cb3533f 380
381 if(!(digitizerNotFound && phosNotFound)){
382 cout << "AliPHOSDigitizer error: " << endl ;
383 cout << " can not update/overwrite existing branches "<< endl ;
384 cout << " do not write " << endl ;
385 return ;
386 }
387
388 // create new branches
389
390 //First generate file name
391 char * file =0;
392 if(gSystem->Getenv("CONFIG_SPLIT_FILE")){ //generating file name
393 file = new char[strlen(gAlice->GetBaseFile())+20] ;
394 sprintf(file,"%s/PHOS.Digits.root",gAlice->GetBaseFile()) ;
395 }
396
397 TDirectory *cwd = gDirectory;
398
399 //First create list of sdigits
400 Int_t bufferSize = 32000 ;
401 digitsBranch = gAlice->TreeD()->Branch("PHOS",&fDigits,bufferSize);
402 digitsBranch->SetTitle(fDigitsTitle.Data());
403 if (file) {
404 digitsBranch->SetFile(file);
405 TIter next( digitsBranch->GetListOfBranches());
761e34c0 406 TBranch * sbr ;
407 while ((sbr=(TBranch*)next())) {
408 sbr->SetFile(file);
8cb3533f 409 }
410 cwd->cd();
411 }
412
413 //second - create Digitizer
990119d6 414 Int_t splitlevel = 0 ;
8cb3533f 415 AliPHOSDigitizer * d = this ;
416 digitizerBranch = gAlice->TreeD()->Branch("AliPHOSDigitizer","AliPHOSDigitizer",
417 &d,bufferSize,splitlevel);
418 digitizerBranch->SetTitle(fDigitsTitle.Data());
419 if (file) {
420 digitizerBranch->SetFile(file);
421 TIter next( digitizerBranch->GetListOfBranches());
761e34c0 422 TBranch * sbr;
423 while ((sbr=(TBranch*)next())) {
424 sbr->SetFile(file);
8cb3533f 425 }
426 cwd->cd();
427 }
990119d6 428
dd5c4038 429 digitsBranch->Fill() ;
761e34c0 430 digitizerBranch->Fill() ;
eec3ac52 431
990119d6 432 gAlice->TreeD()->Write(0,kOverwrite) ;
bca3b32a 433
434 //remove fSDigitizer before new event.
435 if(fSDigitizer){
436 delete fSDigitizer ;
437 fSDigitizer = 0 ;
438 }
439
440
990119d6 441}
442
443//____________________________________________________________________________
a4e98857 444void AliPHOSDigitizer::Exec(Option_t *option)
445{
bca3b32a 446 // Managing method
447
8cb3533f 448 if(!fInitialized) Init() ;
990119d6 449
8cb3533f 450 if(strstr(option,"tim"))
451 gBenchmark->Start("PHOSDigitizer");
452
453 //reset events numbers to start from the beginnig
454 Reset() ;
990119d6 455
456 while(Combinator()){
457
458 if(!ReadSDigits()) //read sdigits event(s) evaluated by Combinator() from file(s)
459 return ;
460
461 Digitize(option) ; //Add prepared SDigits to digits and add the noise
462 WriteDigits() ;
8cb3533f 463
464 if(strstr(option,"deb"))
465 PrintDigits(option);
990119d6 466
8cb3533f 467 }
990119d6 468
8cb3533f 469 if(strstr(option,"tim")){
470 gBenchmark->Stop("PHOSDigitizer");
471 cout << "AliPHOSDigitizer:" << endl ;
472 cout << " took " << gBenchmark->GetCpuTime("PHOSDigitizer") << " seconds for SDigitizing "
473 << gBenchmark->GetCpuTime("PHOSDigitizer")/(fIeventMax->At(0)) << " seconds per event " << endl ;
474 cout << endl ;
475 }
990119d6 476
477}
478
479//__________________________________________________________________
a4e98857 480Bool_t AliPHOSDigitizer::ReadSDigits()
481{
482 // Reads summable digits from the opened files for the particular set of events given by fIevent
990119d6 483
8cb3533f 484 if(!fInitialized) Init() ;
990119d6 485
bca3b32a 486
990119d6 487 Int_t inputs ;
488 for(inputs = fNinputs-1; inputs >= 0; inputs --){
489
490 Int_t event = fIevent->At(inputs) ;
491
492 TFile * file = (TFile*) gROOT->GetFile(((TObjString *) fHeaderFiles->At(inputs))->GetString() ) ;
493 file->cd() ;
494
495 // Get SDigits Tree header from file
496 char treeName[20];
497 sprintf(treeName,"TreeS%d",event);
498 TTree * treeS = (TTree*)file->Get(treeName);
499
500 if(treeS==0){
501 cout << "Error at AliPHOSDigitizer: no "<<treeName << " in file " << file->GetName() << endl ;
502 cout << "Do nothing " << endl ;
503 return kFALSE ;
504 }
505
506 TBranch * sdigitsBranch = 0;
507 TBranch * sdigitizerBranch = 0;
508
509 TObjArray * branches = treeS->GetListOfBranches() ;
510 Int_t ibranch;
511 Bool_t phosNotFound = kTRUE ;
512 Bool_t sdigitizerNotFound = kTRUE ;
513
514 for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){
8cb3533f 515
990119d6 516 if(phosNotFound){
517 sdigitsBranch=(TBranch *) branches->At(ibranch) ;
8cb3533f 518 if(( strcmp("PHOS",sdigitsBranch->GetName())==0 ) &&
519 ((TObjString*) fSDigitsTitles->At(inputs))->GetString().CompareTo(sdigitsBranch->GetTitle())== 0 )
520 phosNotFound = kFALSE ;
521
990119d6 522 }
8cb3533f 523
990119d6 524 if(sdigitizerNotFound){
525 sdigitizerBranch = (TBranch *) branches->At(ibranch) ;
8cb3533f 526 if(( strcmp(sdigitizerBranch->GetName(),"AliPHOSSDigitizer") == 0) &&
527 ((TObjString*) fSDigitsTitles->At(inputs))->GetString().CompareTo(sdigitizerBranch->GetTitle())== 0 )
528 sdigitizerNotFound = kFALSE ;
529
990119d6 530 }
990119d6 531 }
8cb3533f 532
990119d6 533 if(sdigitizerNotFound || phosNotFound){
534 cout << "Can't find Branch with sdigits or SDigitizer in the file " ;
8cb3533f 535 if( ((TObjString*)fSDigitsTitles->At(inputs))->GetString().IsNull() )
990119d6 536 cout << file->GetName() << endl ;
537 else
8cb3533f 538 cout << ((TObjString*)fSDigitsTitles->At(inputs))->GetString().Data() << endl ;
990119d6 539 cout << "Do nothing" <<endl ;
540 return kFALSE ;
541 }
8cb3533f 542
990119d6 543 TClonesArray * sdigits = (TClonesArray*) fSDigits->At(inputs) ;
544 sdigitsBranch->SetAddress(&sdigits) ;
545
546 AliPHOSSDigitizer *sDigitizer = new AliPHOSSDigitizer();
547 sdigitizerBranch->SetAddress(&sDigitizer) ;
761e34c0 548
549 sdigitsBranch->GetEntry(0) ;
550 sdigitizerBranch->GetEntry(0) ;
8cb3533f 551
990119d6 552 if(fSDigitizer == 0)
553 fSDigitizer = sDigitizer ;
554 else
555 if(!((*fSDigitizer)==(*sDigitizer)) ){
bca3b32a 556 cout << "AliPHOSDigitizer ERROR:" << endl ;
557 cout << " you are using sdigits made with different SDigitizers" << endl ;
558 cout << "fSD " << fSDigitizer << " SD" << sDigitizer << endl ;
990119d6 559 fSDigitizer->Print("") ;
560 sDigitizer->Print("") ;
561 cout << "Do Nothing " << endl ;
562 return kFALSE ;
563 }
564
565 }
8cb3533f 566 fPedestal = fSDigitizer->GetPedestalParameter() ;
567 fSlope = fSDigitizer->GetCalibrationParameter() ;
990119d6 568
990119d6 569 return kTRUE ;
570
571}
572//__________________________________________________________________
a4e98857 573void AliPHOSDigitizer::MixWith(char* HeaderFile, char* sDigitsTitle)
574{
575 // Alows to produce digits by superimposing background and signal event.
bca3b32a 576 // It is assumed, that headers file with SIGNAL events is opened in
a4e98857 577 // the constructor.
578 // Sets the BACKGROUND event, with which the SIGNAL event is to be mixed
579 // Thus we avoid writing (changing) huge and expensive
bca3b32a 580 // backgound files: all output will be writen into SIGNAL, i.e.
581 // opened in constructor file.
582 //
a4e98857 583 // One can open as many files to mix with as one needs.
bca3b32a 584
990119d6 585
586 if(!fInitialized)
8cb3533f 587 Init() ;
588
990119d6 589
590 if(HeaderFile == 0){
591 cout << "Specify at least header file to merge"<< endl ;
592 return ;
593 }
594
595 Int_t inputs ;
596 for(inputs = 0; inputs < fNinputs ; inputs++){
597 if(strcmp(((TObjString *)fHeaderFiles->At(inputs))->GetString(),HeaderFile) == 0 ){
8cb3533f 598 if(sDigitsTitle == 0){
599 if(((TObjString*)fSDigitsTitles->At(inputs))->GetString().CompareTo("") == 0){
990119d6 600 cout << "Entry already exists, do not add" << endl ;
601 return ;
602 }
603 }
604 else
8cb3533f 605 if(((TObjString*)fSDigitsTitles->At(inputs))->GetString().CompareTo(sDigitsTitle)){
606 cout << "Entry already exists, do not add" << endl ;
607 return;
608 }
990119d6 609 }
610 }
611
612 fHeaderFiles->Expand(fNinputs+1) ;
613 new((*fHeaderFiles)[fNinputs]) TObjString(HeaderFile) ;
990119d6 614
8cb3533f 615
616 TFile * file = new TFile(((TObjString *) fHeaderFiles->At(fNinputs))->GetString()) ;
617
990119d6 618 file->cd() ;
8cb3533f 619
620 fSDigitsTitles->Expand(fNinputs+1) ;
621 new((*fSDigitsTitles)[fNinputs]) TObjString(sDigitsTitle) ;
622
990119d6 623 fSDigits->Expand(fNinputs+1) ;
624 new((*fSDigits)[fNinputs]) TClonesArray("AliPHOSDigit",1000) ;
8cb3533f 625
990119d6 626 fIevent->Set(fNinputs+1) ;
627 fIevent->AddAt(-1, fNinputs) ;
8cb3533f 628
990119d6 629 fIeventMax->Set(fNinputs+1) ;
8cb3533f 630
631 TTree * te = (TTree *) file->Get("TE") ;
632 fIeventMax->AddAt((Int_t) te->GetEntries(), fNinputs );
633
990119d6 634 fNinputs++ ;
8cb3533f 635
990119d6 636}
637//__________________________________________________________________
dd5c4038 638void AliPHOSDigitizer::Print(Option_t* option)const {
639 // Print Digitizer's parameters
8cb3533f 640 if(fInitialized){
641
642 cout << "------------------- "<< GetName() << " -------------" << endl ;
643 cout << "Digitizing sDigits from file(s): " <<endl ;
644 Int_t input ;
645 for(input = 0; input < fNinputs ; input++) {
646 cout << " " << ((TObjString *) fHeaderFiles->At(input))->GetString() <<
647 " Branch title:" << ((TObjString *) fSDigitsTitles->At(input))->GetString() << endl ;
648 }
649 cout << endl ;
650 cout << "Writing digits to " << ((TObjString *) fHeaderFiles->At(0))->GetString() << endl ;
651
652 cout << endl ;
653 cout << "With following parameters: " << endl ;
654 cout << " Electronics noise in EMC (fPinNoise) = " << fPinNoise << endl ;
655 cout << " Threshold in EMC (fEMCDigitThreshold) = " << fEMCDigitThreshold << endl ; ;
656 cout << " Noise in CPV (fCPVNoise) = " << fCPVNoise << endl ;
657 cout << " Threshold in CPV (fCPVDigitThreshold) = " << fCPVDigitThreshold << endl ;
658 cout << " Noise in PPSD (fPPSDNoise) = " << fPPSDNoise << endl ;
659 cout << " Threshold in PPSD (fPPSDDigitThreshold) = " << fPPSDDigitThreshold << endl ;
660 cout << "---------------------------------------------------" << endl ;
990119d6 661 }
8cb3533f 662 else
663 cout << "AliPHOSDigitizer not initialized " << endl ;
664
665}
666//__________________________________________________________________
dd5c4038 667void AliPHOSDigitizer::PrintDigits(Option_t * option){
668 // Print a table of digits
a4e98857 669
8cb3533f 670 cout << "AliPHOSDigitiser:"<< endl ;
671 cout << " Number of entries in Digits list " << fDigits->GetEntriesFast() << endl ;
990119d6 672 cout << endl ;
8cb3533f 673 if(strstr(option,"all")){
674
675 //loop over digits
676 AliPHOSDigit * digit;
677 cout << "Digit Id " << " Amplitude " << " Index " << " Nprim " << " Primaries list " << endl;
678 Int_t index ;
679 for (index = 0 ; index < fDigits->GetEntries() ; index++) {
680 digit = (AliPHOSDigit * ) fDigits->At(index) ;
681 cout << setw(8) << digit->GetId() << " " << setw(3) << digit->GetAmp() << " "
682 << setw(6) << digit->GetIndexInList() << " "
683 << setw(5) << digit->GetNprimary() <<" ";
684
685 Int_t iprimary;
686 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++)
687 cout << setw(5) << digit->GetPrimary(iprimary+1) << " ";
688 cout << endl;
689 }
690
691 }
692}
693//__________________________________________________________________
a4e98857 694void AliPHOSDigitizer::SetSDigitsBranch(const char* title)
695{
bca3b32a 696 // we set title (comment) of the SDigits branch in the first! header file
8cb3533f 697 if(!fInitialized) Init() ;
990119d6 698
8cb3533f 699 ((TObjString*) fSDigitsTitles->At(0) )->SetString((char*)title) ;
990119d6 700
8cb3533f 701}
702//__________________________________________________________________
a4e98857 703void AliPHOSDigitizer::SetDigitsBranch(const char* title)
704{
bca3b32a 705 //Sets the title (comment) of the branch to which Digits branch
8cb3533f 706 if(!fInitialized) Init() ;
707
708 fDigitsTitle = title ;
990119d6 709
710}
dd5c4038 711//__________________________________________________________________
712