A new (final?) geometry developed
[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"
64#include "TBenchmark.h"
ba54256b 65
990119d6 66// --- Standard library ---
8cb3533f 67#include <iomanip.h>
990119d6 68
69// --- AliRoot header files ---
70
8cb3533f 71#include "AliRun.h"
3f81a70b 72#include "AliRunDigitizer.h"
990119d6 73#include "AliPHOSDigit.h"
dd5c4038 74#include "AliPHOS.h"
7b7c1533 75#include "AliPHOSGetter.h"
990119d6 76#include "AliPHOSDigitizer.h"
77#include "AliPHOSSDigitizer.h"
8cb3533f 78#include "AliPHOSGeometry.h"
990119d6 79
80ClassImp(AliPHOSDigitizer)
81
82
83//____________________________________________________________________________
3f81a70b 84 AliPHOSDigitizer::AliPHOSDigitizer()
990119d6 85{
86 // ctor
87
2bd5457f 88 fPinNoise = 0.01 ;
89 fEMCDigitThreshold = 0.01 ;
90 fCPVNoise = 0.01;
91 fCPVDigitThreshold = 0.09 ;
92 fPPSDNoise = 0.0000001;
93 fPPSDDigitThreshold = 0.0000002 ;
2b60655b 94 fDigitsInRun = 0 ;
3f81a70b 95 fPedestal = 0.; // Calibration parameters
96 fSlope = 10000000. ;
97 fARD = 0 ; // We work in the standalong mode
98}
99
100//____________________________________________________________________________
101AliPHOSDigitizer::AliPHOSDigitizer(const char *headerFile,const char * name)
102{
103 // ctor
104 SetName(name) ;
105 SetTitle(headerFile) ;
106 fPinNoise = 0.01 ;
107 fEMCDigitThreshold = 0.01 ;
108 fCPVNoise = 0.01;
109 fCPVDigitThreshold = 0.09 ;
110 fPPSDNoise = 0.0000001;
111 fPPSDDigitThreshold = 0.0000002 ;
112 fDigitsInRun = 0 ;
113 fPedestal = 0.; // Calibration parameters
114 fSlope = 10000000. ;
115 fARD = 0 ; // We work in the standalong mode
8cb3533f 116
3f81a70b 117 Init() ;
118
990119d6 119}
120
990119d6 121//____________________________________________________________________________
3f81a70b 122AliPHOSDigitizer::AliPHOSDigitizer(AliRunDigitizer * ard)
990119d6 123{
124 // ctor
3f81a70b 125 fARD = ard ;
126 SetName("Default");
127 SetTitle("aliroot") ;
128
2bd5457f 129 fPinNoise = 0.01 ;
130 fEMCDigitThreshold = 0.01 ;
131 fCPVNoise = 0.01;
132 fCPVDigitThreshold = 0.09 ;
133 fPPSDNoise = 0.0000001;
990119d6 134 fPPSDDigitThreshold = 0.0000002 ;
2b60655b 135 fDigitsInRun = 0 ;
3f81a70b 136 fPedestal = 0.; // Calibration parameters
137 fSlope = 10000000. ;
2bd5457f 138
139 Init() ;
8cb3533f 140
990119d6 141}
142
143//____________________________________________________________________________
144 AliPHOSDigitizer::~AliPHOSDigitizer()
145{
146 // dtor
8cb3533f 147
8cb3533f 148
990119d6 149}
150
151//____________________________________________________________________________
7b7c1533 152void AliPHOSDigitizer::Digitize(const Int_t event)
a4e98857 153{
154
155 // Makes the digitization of the collected summable digits.
156 // It first creates the array of all PHOS modules
157 // filled with noise (different for EMC, CPV and PPSD) and
158 // then adds contributions from SDigits.
159 // This design avoids scanning over the list of digits to add
160 // contribution to new SDigits only.
990119d6 161
7b7c1533 162 if( strcmp(GetName(), "") == 0 )
8cb3533f 163 Init() ;
990119d6 164
7b7c1533 165 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
3f81a70b 166 TClonesArray * digits = gime->Digits(GetName()) ;
7b7c1533 167
168 digits->Clear() ;
990119d6 169
7b7c1533 170 const AliPHOSGeometry *geom = gime->PHOSGeometry() ;
990119d6 171
172 //Making digits with noise, first EMC
173 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
174
175 Int_t nCPV ;
176 Int_t nPPSD ;
177 Int_t absID ;
178 TString name = geom->GetName() ;
179
180 if ( name == "IHEP" || name == "MIXT" )
181 nCPV =nEMC + geom->GetNumberOfCPVPadsZ()*geom->GetNumberOfCPVPadsPhi()*
182 geom->GetNCPVModules()*geom->GetNumberOfCPVLayers() ;
183 else
184 nCPV = nEMC;
185
186 if ( name == "GPS2" || name == "MIXT" )
187 nPPSD =nCPV+2*geom->GetNPPSDModules()*geom->GetNumberOfModulesPhi()*geom->GetNumberOfModulesZ()*
188 geom->GetNumberOfPadsPhi()*geom->GetNumberOfPadsZ() ;
189 else
190 nPPSD = nCPV;
8cb3533f 191
192
7b7c1533 193 digits->Expand(nPPSD) ;
8cb3533f 194
7b7c1533 195
196 // sdigitize random gaussian noise and add it to all cells (EMCA+CPV+PPSD)
197 // get first the sdigitizer from the tasks list (must have same name as the digitizer)
198 const AliPHOSSDigitizer * sDigitizer = gime->SDigitizer(GetName());
199 if ( !sDigitizer) {
200 cerr << "ERROR: AliPHOSDigitizer::Digitize -> SDigitizer with name " << GetName() << " not found " << endl ;
201 abort() ;
202 }
990119d6 203 for(absID = 1; absID <= nEMC; absID++){
204 Float_t noise = gRandom->Gaus(0., fPinNoise) ;
7b7c1533 205 new((*digits)[absID-1]) AliPHOSDigit( -1,absID,sDigitizer->Digitize(noise) ) ;
990119d6 206 }
207
208 for(absID = nEMC+1; absID <= nCPV; absID++){
209 Float_t noise = gRandom->Gaus(0., fCPVNoise) ;
7b7c1533 210 new((*digits)[absID-1]) AliPHOSDigit( -1,absID,sDigitizer->Digitize(noise) ) ;
990119d6 211 }
212
213 for(absID = nCPV+1; absID <= nPPSD; absID++){
214 Float_t noise = gRandom->Gaus(0., fPPSDNoise) ;
7b7c1533 215 new((*digits)[absID-1]) AliPHOSDigit( -1,absID,sDigitizer->Digitize(noise) ) ;
990119d6 216 }
217
7b7c1533 218 // loop through the sdigits posted to the White Board and add them to the noise
219 TCollection * folderslist = ((TFolder*)gROOT->FindObjectAny("YSAlice/WhiteBoard/SDigits/PHOS"))->GetListOfFolders() ;
220 TIter next(folderslist) ;
221 TFolder * folder = 0 ;
3f81a70b 222 TClonesArray * sdigits = 0 ;
223 Int_t input = 0 ;
7b7c1533 224 while ( (folder = (TFolder*)next()) ) {
3f81a70b 225 if ( (sdigits = (TClonesArray*)folder->FindObject(GetName()) ) ) {
226 cout << "INFO: AliPHOSDigitizer::Digitize -> Adding SDigits "
227 << GetName() << " from " << folder->GetName() << endl ;
228 Int_t primaryoffset ;
229 if(fARD)
230 primaryoffset = fARD->GetMask(input) ;
231 else
232 primaryoffset = 10000000*input ;
233
234 Int_t index ;
235 AliPHOSDigit * curSDigit ;
236 AliPHOSDigit * digit ;
237 for ( index = 0 ; index < sdigits->GetEntriesFast(); index++) {
238 curSDigit = (AliPHOSDigit*)sdigits->At(index) ;
239 curSDigit->ShiftPrimary(primaryoffset) ;
240 digit = (AliPHOSDigit*)digits->At(curSDigit->GetId() - 1 ) ;
241 *digit = *digit + *curSDigit ;
7b7c1533 242 }
243 }
990119d6 244 }
3f81a70b 245
990119d6 246 //remove digits below thresholds
247 for(absID = 0; absID < nEMC ; absID++)
7b7c1533 248 if(sDigitizer->Calibrate(((AliPHOSDigit*)digits->At(absID))->GetAmp()) < fEMCDigitThreshold)
249 digits->RemoveAt(absID) ;
250
990119d6 251 for(absID = nEMC; absID < nCPV ; absID++)
7b7c1533 252 if(sDigitizer->Calibrate(((AliPHOSDigit*)digits->At(absID))->GetAmp()) < fCPVDigitThreshold)
253 digits->RemoveAt(absID) ;
254
990119d6 255 for(absID = nCPV; absID < nPPSD ; absID++)
7b7c1533 256 if(sDigitizer->Calibrate(((AliPHOSDigit *)digits->At(absID))->GetAmp()) < fPPSDDigitThreshold)
257 digits->RemoveAt(absID) ;
990119d6 258
7b7c1533 259 digits->Compress() ;
990119d6 260
7b7c1533 261 Int_t ndigits = digits->GetEntriesFast() ;
7b7c1533 262 digits->Expand(ndigits) ;
990119d6 263
990119d6 264 //Set indexes in list of digits
265 Int_t i ;
266 for (i = 0 ; i < ndigits ; i++) {
7b7c1533 267 AliPHOSDigit * digit = (AliPHOSDigit *) digits->At(i) ;
990119d6 268 digit->SetIndexInList(i) ;
269 }
990119d6 270
7b7c1533 271}
990119d6 272
7b7c1533 273//____________________________________________________________________________
274void AliPHOSDigitizer::Exec(Option_t *option)
275{
276 // Managing method
990119d6 277
7b7c1533 278 if( strcmp(GetName(), "") == 0 )
279 Init() ;
8cb3533f 280
7b7c1533 281 if (strstr(option,"print")) {
282 Print("");
283 return ;
8cb3533f 284 }
990119d6 285
7b7c1533 286 if(strstr(option,"tim"))
287 gBenchmark->Start("PHOSDigitizer");
8cb3533f 288
3f81a70b 289 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
290
291 Int_t nevents ;
292
293 TTree * treeD ;
294
295 if(fARD){
296 treeD = fARD->GetTreeD() ;
297 nevents = 1 ; // Will process only one event
298 }
299 else {
300 gAlice->GetEvent(0) ;
301 nevents = (Int_t) gAlice->TreeE()->GetEntries() ;
302 treeD=gAlice->TreeD() ;
303 }
304 if(treeD == 0 ){
305 cerr << " AliPHOSDigitizer :: Can not find TreeD " << endl ;
306 return ;
307 }
308
7b7c1533 309 //Check, if this branch already exits
3f81a70b 310 TObjArray * lob = (TObjArray*)treeD->GetListOfBranches() ;
7b7c1533 311 TIter next(lob) ;
312 TBranch * branch = 0 ;
313 Bool_t phosfound = kFALSE, digitizerfound = kFALSE ;
8cb3533f 314
7b7c1533 315 while ( (branch = (TBranch*)next()) && (!phosfound || !digitizerfound) ) {
3f81a70b 316 if ( (strcmp(branch->GetName(), "PHOS")==0) &&
317 (strcmp(branch->GetTitle(), GetName())==0) )
7b7c1533 318 phosfound = kTRUE ;
8cb3533f 319
3f81a70b 320 else if ( (strcmp(branch->GetName(), "AliPHOSDigitizer")==0) &&
321 (strcmp(branch->GetTitle(), GetName())==0) )
7b7c1533 322 digitizerfound = kTRUE ;
8cb3533f 323 }
990119d6 324
3f81a70b 325 if ( phosfound ) {
326 cerr << "WARNING: AliPHOSDigitizer -> Digits branch with name " << GetName()
327 << " already exits" << endl ;
328 return ;
329 }
330 if ( digitizerfound ) {
331 cerr << "WARNING: AliPHOSDigitizer -> Digitizer branch with name " << GetName()
7b7c1533 332 << " already exits" << endl ;
333 return ;
334 }
eec3ac52 335
7b7c1533 336 Int_t ievent ;
bca3b32a 337
7b7c1533 338 for(ievent = 0; ievent < nevents; ievent++){
3f81a70b 339
340 if(fARD){
341 Int_t input ;
342 for(input = 0 ; input < fARD->GetNinputs(); input ++){
343 TTree * treeS = fARD->GetInputTreeS(input) ;
344 if(!treeS){
345 cerr << "AliPHOSDigitizer -> No Input " << endl ;
346 return ;
347 }
348 gime->ReadTreeS(treeS,input) ;
349 }
350 }
351 else
352 gime->Event(ievent,"S") ;
990119d6 353
7b7c1533 354 Digitize(ievent) ; //Add prepared SDigits to digits and add the noise
3f81a70b 355
7b7c1533 356 WriteDigits(ievent) ;
3f81a70b 357
01a599c9 358 if(strstr(option,"deb"))
359 PrintDigits(option);
360 }
3f81a70b 361
8cb3533f 362 if(strstr(option,"tim")){
363 gBenchmark->Stop("PHOSDigitizer");
364 cout << "AliPHOSDigitizer:" << endl ;
ba54256b 365 cout << " took " << gBenchmark->GetCpuTime("PHOSDigitizer") << " seconds for Digitizing "
366 << gBenchmark->GetCpuTime("PHOSDigitizer")/nevents << " seconds per event " << endl ;
8cb3533f 367 cout << endl ;
368 }
990119d6 369
370}
371
7b7c1533 372//____________________________________________________________________________
3f81a70b 373Bool_t AliPHOSDigitizer::Init()
a4e98857 374{
7b7c1533 375 // Makes all memory allocations
376 // Adds Digitizer task to the folder of PHOS tasks
377 //============================================================= YS
378 // The initialisation is now done by AliPHOSGetter
8cb3533f 379
7b7c1533 380 if( strcmp(GetTitle(), "") == 0 )
381 SetTitle("galice.root") ;
382
7b7c1533 383 // the SDigits name is stored by AliPHOSGetter as the name of the TClones Array
384 // //YSAlice/WhiteBoard/SDigits/PHOS/headerFile/branchname and has branchTitle as title.
990119d6 385
7b7c1533 386 AliPHOSGetter * gime = AliPHOSGetter::GetInstance(GetTitle(), GetName()) ;
387 if ( gime == 0 ) {
388 cerr << "ERROR: AliPHOSDigitizer::Init -> Could not obtain the Getter object !" << endl ;
3f81a70b 389 return kFALSE;
7b7c1533 390 }
3f81a70b 391
392 // create a folder on the white board //YSAlice/WhiteBoard/Digits/PHOS/headerFile/digitsTitle
393 gime->PostDigits(GetName() ) ;
7b7c1533 394
395 //add Task to //YSAlice/tasks/Digitizer/PHOS
3f81a70b 396 gime->PostDigitizer(this) ;
397
398 //Mark that we will use current header file
399 if(!fARD){
400 gime->PostSDigits(GetName(),GetTitle()) ;
401 gime->PostSDigitizer(GetName(),GetTitle()) ;
402 }
403 return kTRUE ;
990119d6 404}
7b7c1533 405
990119d6 406//__________________________________________________________________
7b7c1533 407void AliPHOSDigitizer::MixWith(const char* headerFile)
a4e98857 408{
ba54256b 409 // Allows to produce digits by superimposing background and signal event.
bca3b32a 410 // It is assumed, that headers file with SIGNAL events is opened in
a4e98857 411 // the constructor.
412 // Sets the BACKGROUND event, with which the SIGNAL event is to be mixed
413 // Thus we avoid writing (changing) huge and expensive
bca3b32a 414 // backgound files: all output will be writen into SIGNAL, i.e.
415 // opened in constructor file.
416 //
a4e98857 417 // One can open as many files to mix with as one needs.
7b7c1533 418 // However only Sdigits with the same name (i.e. constructed with the same SDigitizer)
419 // can be mixed.
bca3b32a 420
7b7c1533 421 if( strcmp(GetName(), "") == 0 )
8cb3533f 422 Init() ;
423
3f81a70b 424 if(fARD){
425 cout << "Can not use this method under AliRunDigitizer " << endl ;
426 return ;
427 }
7b7c1533 428
429 // check if the specified SDigits do not already exist on the White Board:
430 // //YSAlice/WhiteBoard/SDigits/PHOS/headerFile/sDigitsTitle
990119d6 431
7b7c1533 432 TString path = "YSAlice/WhiteBoard/SDigits/PHOS/" ;
433 path += headerFile ;
434 path += "/" ;
3f81a70b 435 path += GetName() ;
7b7c1533 436 if ( gROOT->FindObjectAny(path.Data()) ) {
437 cerr << "WARNING: AliPHOSDigitizer::MixWith -> Entry already exists, do not add" << endl ;
438 return;
990119d6 439 }
3f81a70b 440
441 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
442 gime->PostSDigits(GetName(),headerFile) ;
443
7b7c1533 444 // check if the requested file is already open or exist and if SDigits Branch exist
445 TFile * file = (TFile*)gROOT->FindObject(headerFile);
446 if ( !file ) {
447 file = new TFile(headerFile, "READ") ;
448 if (!file) {
449 cerr << "ERROR: AliPHOSDigitizer::MixWith -> File " << headerFile << " does not exist!" << endl ;
450 return ;
451 }
452 }
3f81a70b 453
990119d6 454}
7b7c1533 455
990119d6 456//__________________________________________________________________
dd5c4038 457void AliPHOSDigitizer::Print(Option_t* option)const {
458 // Print Digitizer's parameters
7b7c1533 459 if( strcmp(GetName(), "") != 0 ){
8cb3533f 460
461 cout << "------------------- "<< GetName() << " -------------" << endl ;
462 cout << "Digitizing sDigits from file(s): " <<endl ;
7b7c1533 463
464 TCollection * folderslist = ((TFolder*)gROOT->FindObjectAny("YSAlice/WhiteBoard/SDigits/PHOS"))->GetListOfFolders() ;
465 TIter next(folderslist) ;
466 TFolder * folder = 0 ;
467
468 while ( (folder = (TFolder*)next()) ) {
469 if ( folder->FindObject(GetName()) )
470 cout << "Adding SDigits " << GetName() << " from " << folder->GetName() << endl ;
8cb3533f 471 }
472 cout << endl ;
7b7c1533 473 cout << "Writing digits to " << GetTitle() << endl ;
8cb3533f 474
475 cout << endl ;
476 cout << "With following parameters: " << endl ;
477 cout << " Electronics noise in EMC (fPinNoise) = " << fPinNoise << endl ;
478 cout << " Threshold in EMC (fEMCDigitThreshold) = " << fEMCDigitThreshold << endl ; ;
479 cout << " Noise in CPV (fCPVNoise) = " << fCPVNoise << endl ;
480 cout << " Threshold in CPV (fCPVDigitThreshold) = " << fCPVDigitThreshold << endl ;
481 cout << " Noise in PPSD (fPPSDNoise) = " << fPPSDNoise << endl ;
482 cout << " Threshold in PPSD (fPPSDDigitThreshold) = " << fPPSDDigitThreshold << endl ;
483 cout << "---------------------------------------------------" << endl ;
990119d6 484 }
8cb3533f 485 else
486 cout << "AliPHOSDigitizer not initialized " << endl ;
487
488}
489//__________________________________________________________________
dd5c4038 490void AliPHOSDigitizer::PrintDigits(Option_t * option){
491 // Print a table of digits
a4e98857 492
7b7c1533 493 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
494 TClonesArray * digits = gime->Digits() ;
495
01a599c9 496 cout << "AliPHOSDigitiser: event " << gAlice->GetEvNumber() << endl ;
7b7c1533 497 cout << " Number of entries in Digits list " << digits->GetEntriesFast() << endl ;
990119d6 498 cout << endl ;
2b60655b 499
500 fDigitsInRun += digits->GetEntriesFast() ;
501
8cb3533f 502 if(strstr(option,"all")){
503
504 //loop over digits
505 AliPHOSDigit * digit;
506 cout << "Digit Id " << " Amplitude " << " Index " << " Nprim " << " Primaries list " << endl;
507 Int_t index ;
7b7c1533 508 for (index = 0 ; index < digits->GetEntries() ; index++) {
509 digit = (AliPHOSDigit * ) digits->At(index) ;
8cb3533f 510 cout << setw(8) << digit->GetId() << " " << setw(3) << digit->GetAmp() << " "
511 << setw(6) << digit->GetIndexInList() << " "
512 << setw(5) << digit->GetNprimary() <<" ";
513
514 Int_t iprimary;
515 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++)
516 cout << setw(5) << digit->GetPrimary(iprimary+1) << " ";
517 cout << endl;
518 }
519
520 }
521}
7b7c1533 522
8cb3533f 523//__________________________________________________________________
a4e98857 524void AliPHOSDigitizer::SetSDigitsBranch(const char* title)
525{
bca3b32a 526 // we set title (comment) of the SDigits branch in the first! header file
7b7c1533 527 if( strcmp(GetName(), "") == 0 )
528 Init() ;
990119d6 529
7b7c1533 530 AliPHOSGetter::GetInstance()->SDigits()->SetName(title) ;
531
8cb3533f 532}
7b7c1533 533//____________________________________________________________________________
534void AliPHOSDigitizer::Reset()
535{
536 // sets current event number to the first simulated event
537
538 if( strcmp(GetName(), "") == 0 )
539 Init() ;
540
541 // Int_t inputs ;
542// for(inputs = 0; inputs < fNinputs ;inputs++)
543// fIevent->AddAt(-1, inputs ) ;
544
545}
546
547//____________________________________________________________________________
548void AliPHOSDigitizer::WriteDigits(Int_t event)
549{
550
551 // Makes TreeD in the output file.
552 // Check if branch already exists:
553 // if yes, exit without writing: ROOT TTree does not support overwriting/updating of
554 // already existing branches.
555 // else creates branch with Digits, named "PHOS", title "...",
556 // and branch "AliPHOSDigitizer", with the same title to keep all the parameters
557 // and names of files, from which digits are made.
558
559 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
3f81a70b 560 TClonesArray * digits = gime->Digits(GetName()) ;
ba54256b 561
3f81a70b 562 TTree * treeD ;
7b7c1533 563
3f81a70b 564 if(fARD)
565 treeD = fARD->GetTreeD() ;
566 else
567 treeD = gAlice->TreeD();
568
7b7c1533 569 // create new branches
570 // -- generate file name if necessary
571 char * file =0;
572 if(gSystem->Getenv("CONFIG_SPLIT_FILE")){ //generating file name
573 file = new char[strlen(gAlice->GetBaseFile())+20] ;
574 sprintf(file,"%s/PHOS.Digits.root",gAlice->GetBaseFile()) ;
575 }
576
577 TDirectory *cwd = gDirectory;
7b7c1533 578 // -- create Digits branch
579 Int_t bufferSize = 32000 ;
ba54256b 580 TBranch * digitsBranch = treeD->Branch("PHOS",&digits,bufferSize);
7b7c1533 581 digitsBranch->SetTitle(GetName());
582 if (file) {
583 digitsBranch->SetFile(file);
584 TIter next( digitsBranch->GetListOfBranches());
585 TBranch * sbr ;
586 while ((sbr=(TBranch*)next())) {
587 sbr->SetFile(file);
588 }
589 cwd->cd();
590 }
591
592 // -- Create Digitizer branch
593 Int_t splitlevel = 0 ;
594 AliPHOSDigitizer * d = gime->Digitizer(GetName()) ;
ba54256b 595 TBranch * digitizerBranch = treeD->Branch("AliPHOSDigitizer", "AliPHOSDigitizer", &d,bufferSize,splitlevel);
7b7c1533 596 digitizerBranch->SetTitle(GetName());
597 if (file) {
598 digitizerBranch->SetFile(file);
599 TIter next( digitizerBranch->GetListOfBranches());
600 TBranch * sbr;
601 while ((sbr=(TBranch*)next())) {
602 sbr->SetFile(file);
603 }
604 cwd->cd();
605 }
3f81a70b 606
7b7c1533 607 digitsBranch->Fill() ;
608 digitizerBranch->Fill() ;
609
ba54256b 610 treeD->Write(0,kOverwrite) ;
3f81a70b 611
7b7c1533 612}