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