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