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