]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - PHOS/AliPHOSDigitizer.cxx
Bug correction
[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 "TTree.h"
60#include "TSystem.h"
61#include "TBenchmark.h"
62#include "TRandom.h"
63
64// --- Standard library ---
65
66// --- AliRoot header files ---
67
68#include "AliRunDigitizer.h"
69#include "AliPHOSDigit.h"
70#include "AliPHOSGetter.h"
71#include "AliPHOSDigitizer.h"
72#include "AliPHOSSDigitizer.h"
73#include "AliPHOSGeometry.h"
74#include "AliPHOSTick.h"
75
76ClassImp(AliPHOSDigitizer)
77
78
79//____________________________________________________________________________
80 AliPHOSDigitizer::AliPHOSDigitizer():AliDigitizer("",""),
81 fInput(0),
82 fInputFileNames(0x0),
83 fEventNames(0x0)
84{
85 // ctor
86 InitParameters() ;
87 fDefaultInit = kTRUE ;
88 fManager = 0 ; // We work in the standalong mode
89 fEventFolderName = "" ;
90}
91
92//____________________________________________________________________________
93AliPHOSDigitizer::AliPHOSDigitizer(TString alirunFileName,
94 TString eventFolderName):
95 AliDigitizer("PHOS"+AliConfig::Instance()->GetDigitizerTaskName(),
96 alirunFileName),
97 fInputFileNames(0), fEventNames(0), fEventFolderName(eventFolderName)
98{
99 // ctor
100 InitParameters() ;
101 Init() ;
102 fDefaultInit = kFALSE ;
103 fManager = 0 ; // We work in the standalong mode
104}
105
106//____________________________________________________________________________
107AliPHOSDigitizer::AliPHOSDigitizer(const AliPHOSDigitizer & d)
108 : AliDigitizer(d)
109{
110 // copyy ctor
111
112 SetName(d.GetName()) ;
113 SetTitle(d.GetTitle()) ;
114 fPinNoise = d.fPinNoise ;
115 fEMCDigitThreshold = d.fEMCDigitThreshold ;
116 fCPVNoise = d.fCPVNoise ;
117 fCPVDigitThreshold = d.fCPVDigitThreshold ;
118 fTimeResolution = d.fTimeResolution ;
119 fTimeThreshold = d.fTimeThreshold ;
120 fTimeSignalLength = d.fTimeSignalLength ;
121 fADCchanelEmc = d.fADCchanelEmc ;
122 fADCpedestalEmc = d.fADCpedestalEmc ;
123 fNADCemc = d.fNADCemc ;
124 fADCchanelCpv = d.fADCchanelCpv ;
125 fADCpedestalCpv = d.fADCpedestalCpv ;
126 fNADCcpv = d.fNADCcpv ;
127 fEventFolderName = d.fEventFolderName;
128}
129
130//____________________________________________________________________________
131AliPHOSDigitizer::AliPHOSDigitizer(AliRunDigitizer * rd):
132 AliDigitizer(rd,"PHOS"+AliConfig::Instance()->GetDigitizerTaskName()),
133 fEventFolderName(0)
134{
135 // ctor Init() is called by RunDigitizer
136 fManager = rd ;
137 fEventFolderName = fManager->GetInputFolderName(0) ;
138 SetTitle(dynamic_cast<AliStream*>(fManager->GetInputStream(0))->GetFileName(0));
139 InitParameters() ;
140 fDefaultInit = kFALSE ;
141}
142
143//____________________________________________________________________________
144 AliPHOSDigitizer::~AliPHOSDigitizer()
145{
146 // dtor
147 delete [] fInputFileNames ;
148 delete [] fEventNames ;
149
150}
151
152//____________________________________________________________________________
153void AliPHOSDigitizer::Digitize(Int_t event)
154{
155
156 // Makes the digitization of the collected summable digits.
157 // It first creates the array of all PHOS modules
158 // filled with noise (different for EMC, and CPV) and
159 // then adds contributions from SDigits.
160 // This design avoids scanning over the list of digits to add
161 // contribution to new SDigits only.
162
163 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName) ;
164 Int_t ReadEvent = event ;
165 if (fManager)
166 ReadEvent = dynamic_cast<AliStream*>(fManager->GetInputStream(0))->GetCurrentEventNumber() ;
167 Info("Digitize", "Adding event %d from input stream 0 %s %s", ReadEvent, GetTitle(), fEventFolderName.Data()) ;
168 gime->Event(ReadEvent, "S") ;
169 TClonesArray * digits = gime->Digits() ;
170 digits->Clear() ;
171
172 const AliPHOSGeometry *geom = gime->PHOSGeometry() ;
173 //Making digits with noise, first EMC
174 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
175
176 Int_t nCPV ;
177 Int_t absID ;
178
179 nCPV = nEMC + geom->GetNumberOfCPVPadsZ() * geom->GetNumberOfCPVPadsPhi() * geom->GetNModules() ;
180
181 digits->Expand(nCPV) ;
182
183 // get first the sdigitizer from the tasks list
184 if ( !gime->SDigitizer() )
185 gime->LoadSDigitizer();
186 AliPHOSSDigitizer * sDigitizer = gime->SDigitizer();
187
188 if ( !sDigitizer )
189 Fatal("Digitize", "SDigitizer with name %s %s not found", GetTitle(), fEventFolderName.Data() ) ;
190
191 //take all the inputs to add together and load the SDigits
192 TObjArray * sdigArray = new TObjArray(fInput) ;
193 sdigArray->AddAt(gime->SDigits(), 0) ;
194 Int_t i ;
195 for(i = 1 ; i < fInput ; i++){
196 TString tempo(fEventNames[i]) ;
197 tempo += i ;
198 AliPHOSGetter * gime = AliPHOSGetter::Instance(fInputFileNames[i], tempo) ;
199 if (fManager)
200 ReadEvent = dynamic_cast<AliStream*>(fManager->GetInputStream(i))->GetCurrentEventNumber() ;
201 Info("Digitize", "Adding event %d from input stream %d %s %s", ReadEvent, i, fInputFileNames[i].Data(), tempo.Data()) ;
202 gime->Event(ReadEvent,"S");
203 sdigArray->AddAt(gime->SDigits(), i) ;
204 }
205
206 //Find the first crystall with signal
207 Int_t nextSig = 200000 ;
208 TClonesArray * sdigits ;
209 for(i = 0 ; i < fInput ; i++){
210 sdigits = dynamic_cast<TClonesArray *>(sdigArray->At(i)) ;
211 if ( !sdigits->GetEntriesFast() )
212 continue ;
213 Int_t curNext = dynamic_cast<AliPHOSDigit *>(sdigits->At(0))->GetId() ;
214 if(curNext < nextSig)
215 nextSig = curNext ;
216 }
217
218 TArrayI index(fInput) ;
219 index.Reset() ; //Set all indexes to zero
220
221 AliPHOSDigit * digit ;
222 AliPHOSDigit * curSDigit ;
223
224 TClonesArray * ticks = new TClonesArray("AliPHOSTick",1000) ;
225
226 //Put Noise contribution
227 for(absID = 1 ; absID <= nEMC ; absID++){
228 Float_t noise = gRandom->Gaus(0., fPinNoise) ;
229 new((*digits)[absID-1]) AliPHOSDigit( -1, absID, sDigitizer->Digitize(noise), TimeOfNoise() ) ;
230 //look if we have to add signal?
231 digit = dynamic_cast<AliPHOSDigit *>(digits->At(absID-1)) ;
232
233 if(absID==nextSig){
234 //Add SDigits from all inputs
235 ticks->Clear() ;
236 Int_t contrib = 0 ;
237 Float_t a = digit->GetAmp() ;
238 Float_t b = TMath::Abs( a / fTimeSignalLength) ;
239 //Mark the beginning of the signal
240 new((*ticks)[contrib++]) AliPHOSTick(digit->GetTime(),0, b);
241 //Mark the end of the ignal
242 new((*ticks)[contrib++]) AliPHOSTick(digit->GetTime()+fTimeSignalLength, -a, -b);
243
244 //loop over inputs
245 for(i = 0 ; i < fInput ; i++){
246 if( dynamic_cast<TClonesArray *>(sdigArray->At(i))->GetEntriesFast() > index[i] )
247 curSDigit = dynamic_cast<AliPHOSDigit*>(dynamic_cast<TClonesArray *>(sdigArray->At(i))->At(index[i])) ;
248 else
249 curSDigit = 0 ;
250 //May be several digits will contribute from the same input
251 while(curSDigit && curSDigit->GetId() == absID){
252 //Shift primary to separate primaries belonging different inputs
253 Int_t primaryoffset ;
254 if(fManager)
255 primaryoffset = fManager->GetMask(i) ;
256 else
257 primaryoffset = 10000000*i ;
258 curSDigit->ShiftPrimary(primaryoffset) ;
259
260 a = curSDigit->GetAmp() ;
261 b = a /fTimeSignalLength ;
262 new((*ticks)[contrib++]) AliPHOSTick(curSDigit->GetTime(),0, b);
263 new((*ticks)[contrib++]) AliPHOSTick(curSDigit->GetTime()+fTimeSignalLength, -a, -b);
264
265 *digit = *digit + *curSDigit ; //add energies
266
267 index[i]++ ;
268 if( dynamic_cast<TClonesArray *>(sdigArray->At(i))->GetEntriesFast() > index[i] )
269 curSDigit = dynamic_cast<AliPHOSDigit*>(dynamic_cast<TClonesArray *>(sdigArray->At(i))->At(index[i])) ;
270 else
271 curSDigit = 0 ;
272 }
273 }
274
275 //calculate and set time
276 Float_t time = FrontEdgeTime(ticks) ;
277 digit->SetTime(time) ;
278
279 //Find next signal module
280 nextSig = 200000 ;
281 for(i = 0 ; i < fInput ; i++){
282 sdigits = dynamic_cast<TClonesArray *>(sdigArray->At(i)) ;
283 Int_t curNext = nextSig ;
284 if(sdigits->GetEntriesFast() > index[i] ){
285 curNext = dynamic_cast<AliPHOSDigit *>(sdigits->At(index[i]))->GetId() ;
286 }
287 if(curNext < nextSig) nextSig = curNext ;
288 }
289 }
290 }
291
292 ticks->Delete() ;
293 delete ticks ;
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 // Steering method to process digitization for events
393 // in the range from fFirstEvent to fLastEvent.
394 // This range is optionally set by SetEventRange().
395 // if fLastEvent=-1, then process events until the end.
396 // by default fLastEvent = fFirstEvent (process only one event)
397
398 if (!fInit) { // to prevent overwrite existing file
399 Error( "Exec", "Give a version name different from %s", fEventFolderName.Data() ) ;
400 return ;
401 }
402
403 if (strstr(option,"print")) {
404 Print();
405 return ;
406 }
407
408 if(strstr(option,"tim"))
409 gBenchmark->Start("PHOSDigitizer");
410
411 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle()) ;
412
413 // Post Digitizer to the white board
414 gime->PostDigitizer(this) ;
415
416 if (fLastEvent == -1)
417 fLastEvent = gime->MaxEvent() - 1 ;
418 else if (fManager)
419 fLastEvent = fFirstEvent ;
420
421 Int_t nEvents = fLastEvent - fFirstEvent + 1;
422
423 Int_t ievent ;
424
425 for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
426
427 gime->Event(ievent,"S") ;
428
429 Digitize(ievent) ; //Add prepared SDigits to digits and add the noise
430
431 WriteDigits() ;
432
433 if(strstr(option,"deb"))
434 PrintDigits(option);
435
436 //increment the total number of Digits per run
437 fDigitsInRun += gime->Digits()->GetEntriesFast() ;
438 }
439
440 gime->PhosLoader()->CleanDigitizer();
441
442 if(strstr(option,"tim")){
443 gBenchmark->Stop("PHOSDigitizer");
444 TString message ;
445 message = " took %f seconds for Digitizing %f seconds per event\n" ;
446 Info("Exec", message.Data(),
447 gBenchmark->GetCpuTime("PHOSDigitizer"),
448 gBenchmark->GetCpuTime("PHOSDigitizer")/nEvents );
449 }
450}
451
452//____________________________________________________________________________
453Float_t AliPHOSDigitizer::FrontEdgeTime(TClonesArray * ticks) const
454{
455 // Returns the shortest time among all time ticks
456
457 ticks->Sort() ; //Sort in accordance with times of ticks
458 TIter it(ticks) ;
459 AliPHOSTick * ctick = (AliPHOSTick *) it.Next() ;
460 Float_t time = ctick->CrossingTime(fTimeThreshold) ;
461
462 AliPHOSTick * t ;
463 while((t=(AliPHOSTick*) it.Next())){
464 if(t->GetTime() < time) //This tick starts before crossing
465 *ctick+=*t ;
466 else
467 return time ;
468
469 time = ctick->CrossingTime(fTimeThreshold) ;
470 }
471 return time ;
472}
473
474//____________________________________________________________________________
475Bool_t AliPHOSDigitizer::Init()
476{
477 // Makes all memory allocations
478 fInit = kTRUE ;
479 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName) ;
480 if ( gime == 0 ) {
481 Fatal("Init" ,"Could not obtain the Getter object for file %s and event %s !", GetTitle(), fEventFolderName.Data()) ;
482 return kFALSE;
483 }
484
485 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
486
487 fEmcCrystals = geom->GetNModules() * geom->GetNCristalsInModule() ;
488
489 TString opt("Digits") ;
490 if(gime->VersionExists(opt) ) {
491 Error( "Init", "Give a version name different from %s", fEventFolderName.Data() ) ;
492 fInit = kFALSE ;
493 }
494
495 fFirstEvent = 0 ;
496 fLastEvent = fFirstEvent ;
497 if (fManager)
498 fInput = fManager->GetNinputs() ;
499 else
500 fInput = 1 ;
501
502 fInputFileNames = new TString[fInput] ;
503 fEventNames = new TString[fInput] ;
504 fInputFileNames[0] = GetTitle() ;
505 fEventNames[0] = fEventFolderName.Data() ;
506 Int_t index ;
507 for (index = 1 ; index < fInput ; index++) {
508 fInputFileNames[index] = dynamic_cast<AliStream*>(fManager->GetInputStream(index))->GetFileName(0);
509 TString tempo = fManager->GetInputFolderName(index) ;
510 fEventNames[index] = tempo.Remove(tempo.Length()-1) ; // strip of the stream number added by fManager
511 }
512
513 //to prevent cleaning of this object while GetEvent is called
514 gime->PhosLoader()->GetDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
515
516 return fInit ;
517}
518
519//____________________________________________________________________________
520void AliPHOSDigitizer::InitParameters()
521{
522 // Set initial parameters Digitizer
523
524 fPinNoise = 0.004 ;
525 fEMCDigitThreshold = 0.012 ;
526 fCPVNoise = 0.01;
527 fCPVDigitThreshold = 0.09 ;
528 fTimeResolution = 0.5e-9 ;
529 fTimeSignalLength = 1.0e-9 ;
530 fDigitsInRun = 0 ;
531 fADCchanelEmc = 0.0015; // width of one ADC channel in GeV
532 fADCpedestalEmc = 0.005 ; //
533 fNADCemc = (Int_t) TMath::Power(2,16) ; // number of channels in EMC ADC
534
535 fADCchanelCpv = 0.0012 ; // width of one ADC channel in CPV 'popugais'
536 fADCpedestalCpv = 0.012 ; //
537 fNADCcpv = (Int_t) TMath::Power(2,12); // number of channels in CPV ADC
538
539 fTimeThreshold = 0.001*10000000 ; //Means 1 MeV in terms of SDigits amplitude
540 SetEventRange(0,-1) ;
541
542}
543
544//__________________________________________________________________
545void AliPHOSDigitizer::MixWith(TString alirunFileName, TString eventFolderName)
546{
547 // Allows to produce digits by superimposing background and signal event.
548 // It is assumed, that headers file with SIGNAL events is opened in
549 // the constructor.
550 // Sets the BACKGROUND event, with which the SIGNAL event is to be mixed
551 // Thus we avoid writing (changing) huge and expensive
552 // backgound files: all output will be writen into SIGNAL, i.e.
553 // opened in constructor file.
554 //
555 // One can open as many files to mix with as one needs.
556 // However only Sdigits with the same name (i.e. constructed with the same SDigitizer)
557 // can be mixed.
558
559 if( strcmp(fEventFolderName, "") == 0 )
560 Init() ;
561
562 if(fManager){
563 Warning("MixWith", "Cannot use this method with AliRunDigitizer\n" ) ;
564 return ;
565 }
566 // looking for file which contains AliRun
567 if (gSystem->AccessPathName(alirunFileName)) {// file does not exist
568 Error("MixWith", "File %s does not exist!", alirunFileName.Data()) ;
569 return ;
570 }
571 // looking for the file which contains SDigits
572 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
573 TString fileName( gime->GetSDigitsFileName() ) ;
574 if ( eventFolderName != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
575 fileName = fileName.ReplaceAll(".root", "") + "_" + eventFolderName + ".root" ;
576 if ( (gSystem->AccessPathName(fileName)) ) {
577 Error("MixWith", "The file %s does not exist!", fileName.Data()) ;
578 return ;
579 }
580 // need to increase the arrays
581 TString tempo = fInputFileNames[fInput-1] ;
582 delete [] fInputFileNames ;
583 fInputFileNames = new TString[fInput+1] ;
584 fInputFileNames[fInput-1] = tempo ;
585
586 tempo = fEventNames[fInput-1] ;
587 delete [] fEventNames ;
588 fEventNames = new TString[fInput+1] ;
589 fEventNames[fInput-1] = tempo ;
590
591 fInputFileNames[fInput] = alirunFileName ;
592 fEventNames[fInput] = eventFolderName ;
593 fInput++ ;
594}
595
596//__________________________________________________________________
597void AliPHOSDigitizer::Print()const
598{
599 // Print Digitizer's parameters
600 Info("Print", "\n------------------- %s -------------", GetName() ) ;
601 if( strcmp(fEventFolderName.Data(), "") != 0 ){
602 printf(" Writing Digits to branch with title %s\n", fEventFolderName.Data()) ;
603
604 Int_t nStreams ;
605 if (fManager)
606 nStreams = GetNInputStreams() ;
607 else
608 nStreams = fInput ;
609
610 Int_t index = 0 ;
611 for (index = 0 ; index < nStreams ; index++) {
612 TString tempo(fEventNames[index]) ;
613 tempo += index ;
614 AliPHOSGetter * gime = AliPHOSGetter::Instance(fInputFileNames[index], tempo) ;
615 TString fileName( gime->GetSDigitsFileName() ) ;
616 if ( fEventNames[index] != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
617 fileName = fileName.ReplaceAll(".root", "") + "_" + fEventNames[index] + ".root" ;
618 printf ("Adding SDigits from %s %s\n", fInputFileNames[index].Data(), fileName.Data()) ;
619 }
620 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName) ;
621 printf("\nWriting digits to %s", gime->GetDigitsFileName().Data()) ;
622
623 printf("\nWith following parameters:\n") ;
624 printf(" Electronics noise in EMC (fPinNoise) = %f\n", fPinNoise ) ;
625 printf(" Threshold in EMC (fEMCDigitThreshold) = %f\n", fEMCDigitThreshold ) ;
626 printf(" Noise in CPV (fCPVNoise) = %f\n", fCPVNoise ) ;
627 printf(" Threshold in CPV (fCPVDigitThreshold) = %f\n",fCPVDigitThreshold ) ;
628 printf(" ---------------------------------------------------\n") ;
629 }
630 else
631 Info("Print", "AliPHOSDigitizer not initialized" ) ;
632
633}
634
635//__________________________________________________________________
636 void AliPHOSDigitizer::PrintDigits(Option_t * option)
637{
638 // Print a table of digits
639
640 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName) ;
641 TClonesArray * digits = gime->Digits() ;
642
643 Info("PrintDigits", "%d", digits->GetEntriesFast()) ;
644 printf("\nevent %d", gAlice->GetEvNumber()) ;
645 printf("\n Number of entries in Digits list %d", digits->GetEntriesFast() ) ;
646
647
648 if(strstr(option,"all")||strstr(option,"EMC")){
649 //loop over digits
650 AliPHOSDigit * digit;
651 printf("\nEMC digits (with primaries):\n") ;
652 printf("\n Id Amplitude Time Index Nprim: Primaries list \n") ;
653 Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
654 Int_t index ;
655 for (index = 0 ; (index < digits->GetEntriesFast()) &&
656 (dynamic_cast<AliPHOSDigit *>(digits->At(index))->GetId() <= maxEmc) ; index++) {
657 digit = (AliPHOSDigit * ) digits->At(index) ;
658 if(digit->GetNprimary() == 0)
659 continue;
660 printf("%6d %8d %6.5e %4d %2d :",
661 digit->GetId(), digit->GetAmp(), digit->GetTime(), digit->GetIndexInList(), digit->GetNprimary()) ;
662 Int_t iprimary;
663 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
664 printf("%d ",digit->GetPrimary(iprimary+1) ) ;
665 }
666 printf("\n") ;
667 }
668 }
669
670 if(strstr(option,"all")||strstr(option,"CPV")){
671
672 //loop over CPV digits
673 AliPHOSDigit * digit;
674 printf("\nCPV digits (with primaries):\n") ;
675 printf("\n Id Amplitude Time Index Nprim: Primaries list \n") ;
676 Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
677 Int_t index ;
678 for (index = 0 ; index < digits->GetEntriesFast(); index++) {
679 digit = (AliPHOSDigit * ) digits->At(index) ;
680 if(digit->GetId() > maxEmc){
681 printf("%6d %8d %4d %2d :",
682 digit->GetId(), digit->GetAmp(), digit->GetIndexInList(), digit->GetNprimary()) ;
683 Int_t iprimary;
684 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
685 printf("%d ",digit->GetPrimary(iprimary+1) ) ;
686 }
687 printf("\n") ;
688 }
689 }
690 }
691
692}
693
694//__________________________________________________________________
695Float_t AliPHOSDigitizer::TimeOfNoise(void) const
696{ // Calculates the time signal generated by noise
697 //PH Info("TimeOfNoise", "Change me") ;
698 return gRandom->Rndm() * 1.28E-5;
699}
700
701//__________________________________________________________________
702void AliPHOSDigitizer::Unload()
703{
704
705 Int_t i ;
706 for(i = 1 ; i < fInput ; i++){
707 TString tempo(fEventNames[i]) ;
708 tempo += i ;
709 AliPHOSGetter * gime = AliPHOSGetter::Instance(fInputFileNames[i], tempo) ;
710 gime->PhosLoader()->UnloadSDigits() ;
711 }
712
713 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName) ;
714 gime->PhosLoader()->UnloadDigits() ;
715}
716
717//____________________________________________________________________________
718void AliPHOSDigitizer::WriteDigits()
719{
720
721 // Makes TreeD in the output file.
722 // Check if branch already exists:
723 // if yes, exit without writing: ROOT TTree does not support overwriting/updating of
724 // already existing branches.
725 // else creates branch with Digits, named "PHOS", title "...",
726 // and branch "AliPHOSDigitizer", with the same title to keep all the parameters
727 // and names of files, from which digits are made.
728
729 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName) ;
730 const TClonesArray * digits = gime->Digits() ;
731 TTree * treeD = gime->TreeD();
732
733 // -- create Digits branch
734 Int_t bufferSize = 32000 ;
735 TBranch * digitsBranch = treeD->Branch("PHOS",&digits,bufferSize);
736 digitsBranch->SetTitle(fEventFolderName);
737 digitsBranch->Fill() ;
738
739 gime->WriteDigits("OVERWRITE");
740 gime->WriteDigitizer("OVERWRITE");
741
742 Unload() ;
743
744}