1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 /* History of cvs commits:
21 * Revision 1.94 2007/02/01 10:34:47 hristov
22 * Removing warnings on Solaris x86
24 * Revision 1.93 2006/10/17 13:17:01 kharlov
25 * Replace AliInfo by AliDebug
27 * Revision 1.92 2006/08/28 10:01:56 kharlov
28 * Effective C++ warnings fixed (Timur Pocheptsov)
30 * Revision 1.91 2006/04/29 20:25:30 hristov
31 * Decalibration is implemented (Yu.Kharlov)
33 * Revision 1.90 2006/04/22 10:30:17 hristov
34 * Add fEnergy to AliPHOSDigit and operate with EMC amplitude in energy units (Yu.Kharlov)
36 * Revision 1.89 2006/04/11 15:22:59 hristov
37 * run number in query set to -1: forces AliCDBManager to use its run number (A.Colla)
39 * Revision 1.88 2006/03/13 14:05:43 kharlov
40 * Calibration objects for EMC and CPV
42 * Revision 1.87 2005/08/24 15:33:49 kharlov
43 * Calibration data for raw digits
45 * Revision 1.86 2005/07/12 20:07:35 hristov
46 * Changes needed to run simulation and reconstrruction in the same AliRoot session
48 * Revision 1.85 2005/05/28 14:19:04 schutz
49 * Compilation warnings fixed by T.P.
53 //_________________________________________________________________________
54 //*-- Author : Dmitri Peressounko (SUBATECH & Kurchatov Institute)
55 //////////////////////////////////////////////////////////////////////////////
56 // This TTask performs digitization of Summable digits (in the PHOS case it is just
57 // the sum of contributions from all primary particles into a given cell).
58 // In addition it performs mixing of summable digits from different events.
59 // The name of the TTask is also the title of the branch that will contain
60 // the created SDigits
61 // The title of the TTAsk is the name of the file that contains the hits from
62 // which the SDigits are created
64 // For each event two branches are created in TreeD:
65 // "PHOS" - list of digits
66 // "AliPHOSDigitizer" - AliPHOSDigitizer with all parameters used in digitization
68 // Note, that one can set a title for new digits branch, and repeat digitization with
69 // another set of parameters.
72 // root[0] AliPHOSDigitizer * d = new AliPHOSDigitizer() ;
73 // root[1] d->ExecuteTask()
74 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
75 // //Digitizes SDigitis in all events found in file galice.root
77 // root[2] AliPHOSDigitizer * d1 = new AliPHOSDigitizer("galice1.root") ;
78 // // Will read sdigits from galice1.root
79 // root[3] d1->MixWith("galice2.root")
80 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
81 // // Reads another set of sdigits from galice2.root
82 // root[3] d1->MixWith("galice3.root")
83 // // Reads another set of sdigits from galice3.root
84 // root[4] d->ExecuteTask("deb timing")
85 // // Reads SDigits from files galice1.root, galice2.root ....
86 // // mixes them and stores produced Digits in file galice1.root
87 // // deb - prints number of produced digits
88 // // deb all - prints list of produced digits
89 // // timing - prints time used for digitization
92 // --- ROOT system ---
95 #include "TBenchmark.h"
98 // --- Standard library ---
100 // --- AliRoot header files ---
102 #include "AliRunDigitizer.h"
103 #include "AliPHOSDigit.h"
104 #include "AliPHOSGetter.h"
105 #include "AliPHOSDigitizer.h"
106 #include "AliPHOSSDigitizer.h"
107 #include "AliPHOSGeometry.h"
108 #include "AliPHOSTick.h"
110 ClassImp(AliPHOSDigitizer)
113 //____________________________________________________________________________
114 AliPHOSDigitizer::AliPHOSDigitizer() :
120 fInputFileNames(0x0),
124 fEMCDigitThreshold(0.f),
126 fCPVDigitThreshold(0.f),
127 fTimeResolution(0.f),
129 fTimeSignalLength(0.f),
131 fADCpedestalEmc(0.f),
134 fADCpedestalCpv(0.f),
136 fEventFolderName(""),
142 fManager = 0 ; // We work in the standalong mode
145 //____________________________________________________________________________
146 AliPHOSDigitizer::AliPHOSDigitizer(TString alirunFileName,
147 TString eventFolderName):
148 AliDigitizer("PHOS"+AliConfig::Instance()->GetDigitizerTaskName(), alirunFileName),
149 fDefaultInit(kFALSE),
153 fInputFileNames(0x0),
157 fEMCDigitThreshold(0.f),
159 fCPVDigitThreshold(0.f),
160 fTimeResolution(0.f),
162 fTimeSignalLength(0.f),
164 fADCpedestalEmc(0.f),
167 fADCpedestalCpv(0.f),
169 fEventFolderName(eventFolderName),
176 fDefaultInit = kFALSE ;
177 fManager = 0 ; // We work in the standalong mode
180 //____________________________________________________________________________
181 AliPHOSDigitizer::AliPHOSDigitizer(const AliPHOSDigitizer & d) :
183 fDefaultInit(d.fDefaultInit),
184 fDigitsInRun(d.fDigitsInRun),
187 fInputFileNames(0x0),//?
189 fEmcCrystals(d.fEmcCrystals),
190 fPinNoise(d.fPinNoise),
191 fEMCDigitThreshold(d.fEMCDigitThreshold),
192 fCPVNoise(d.fCPVNoise),
193 fCPVDigitThreshold(d.fCPVDigitThreshold),
194 fTimeResolution(d.fTimeResolution),
195 fTimeThreshold(d.fTimeThreshold),
196 fTimeSignalLength(d.fTimeSignalLength),
197 fADCchanelEmc(d.fADCchanelEmc),
198 fADCpedestalEmc(d.fADCpedestalEmc),
199 fNADCemc(d.fNADCemc),
200 fADCchanelCpv(d.fADCchanelCpv),
201 fADCpedestalCpv(d.fADCpedestalCpv),
202 fNADCcpv(d.fNADCcpv),
203 fEventFolderName(d.fEventFolderName),
204 fFirstEvent(d.fFirstEvent),
205 fLastEvent(d.fLastEvent)
208 SetName(d.GetName()) ;
209 SetTitle(d.GetTitle()) ;
212 //____________________________________________________________________________
213 AliPHOSDigitizer::AliPHOSDigitizer(AliRunDigitizer * rd) :
214 AliDigitizer(rd,"PHOS"+AliConfig::Instance()->GetDigitizerTaskName()),
215 fDefaultInit(kFALSE),
219 fInputFileNames(0x0),
223 fEMCDigitThreshold(0.f),
225 fCPVDigitThreshold(0.f),
226 fTimeResolution(0.f),
228 fTimeSignalLength(0.f),
230 fADCpedestalEmc(0.f),
233 fADCpedestalCpv(0.f),
235 fEventFolderName(fManager->GetInputFolderName(0)),
239 // ctor Init() is called by RunDigitizer
241 SetTitle(dynamic_cast<AliStream*>(fManager->GetInputStream(0))->GetFileName(0));
243 fDefaultInit = kFALSE ;
246 //____________________________________________________________________________
247 AliPHOSDigitizer::~AliPHOSDigitizer()
249 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle()) ;
251 // Clean Digitizer from the white board
252 gime->PhosLoader()->CleanDigitizer() ;
254 delete [] fInputFileNames ;
255 delete [] fEventNames ;
259 //____________________________________________________________________________
260 void AliPHOSDigitizer::Digitize(Int_t event)
263 // Makes the digitization of the collected summable digits.
264 // It first creates the array of all PHOS modules
265 // filled with noise (different for EMC, and CPV) and
266 // then adds contributions from SDigits.
267 // This design avoids scanning over the list of digits to add
268 // contribution to new SDigits only.
270 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle()) ;
271 Int_t ReadEvent = event ;
273 ReadEvent = dynamic_cast<AliStream*>(fManager->GetInputStream(0))->GetCurrentEventNumber() ;
274 AliDebug(1,Form("Adding event %d from input stream 0 %s %s",
275 ReadEvent, GetTitle(), fEventFolderName.Data())) ;
276 gime->Event(ReadEvent, "S") ;
277 TClonesArray * digits = gime->Digits() ;
280 const AliPHOSGeometry *geom = gime->PHOSGeometry() ;
281 //Making digits with noise, first EMC
282 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
287 nCPV = nEMC + geom->GetNumberOfCPVPadsZ() * geom->GetNumberOfCPVPadsPhi() * geom->GetNModules() ;
289 digits->Expand(nCPV) ;
291 // get first the sdigitizer from the tasks list
292 if ( !gime->SDigitizer() )
293 gime->LoadSDigitizer();
294 AliPHOSSDigitizer * sDigitizer = gime->SDigitizer();
297 AliFatal(Form("SDigitizer with name %s %s not found",
298 GetTitle(), fEventFolderName.Data() )) ;
300 //take all the inputs to add together and load the SDigits
301 TObjArray * sdigArray = new TObjArray(fInput) ;
302 sdigArray->AddAt(gime->SDigits(), 0) ;
304 for(i = 1 ; i < fInput ; i++){
305 TString tempo(fEventNames[i]) ;
307 AliPHOSGetter * gime1 = AliPHOSGetter::Instance(fInputFileNames[i], tempo) ;
309 ReadEvent = dynamic_cast<AliStream*>(fManager->GetInputStream(i))->GetCurrentEventNumber() ;
310 AliInfo(Form("Adding event %d from input stream %d %s %s",
311 ReadEvent, i, fInputFileNames[i].Data(), tempo.Data())) ;
312 gime1->Event(ReadEvent,"S");
313 sdigArray->AddAt(gime1->SDigits(), i) ;
316 //Find the first crystal with signal
317 Int_t nextSig = 200000 ;
318 TClonesArray * sdigits ;
319 for(i = 0 ; i < fInput ; i++){
320 sdigits = dynamic_cast<TClonesArray *>(sdigArray->At(i)) ;
321 if ( !sdigits->GetEntriesFast() )
323 Int_t curNext = dynamic_cast<AliPHOSDigit *>(sdigits->At(0))->GetId() ;
324 if(curNext < nextSig)
328 TArrayI index(fInput) ;
329 index.Reset() ; //Set all indexes to zero
331 AliPHOSDigit * digit ;
332 AliPHOSDigit * curSDigit ;
334 TClonesArray * ticks = new TClonesArray("AliPHOSTick",1000) ;
336 //Put Noise contribution
337 for(absID = 1 ; absID <= nEMC ; absID++){
338 Float_t noise = gRandom->Gaus(0., fPinNoise) ;
339 // YVK: do not digitize amplitudes for EMC
340 // new((*digits)[absID-1]) AliPHOSDigit( -1, absID, sDigitizer->Digitize(noise), TimeOfNoise() ) ;
341 new((*digits)[absID-1]) AliPHOSDigit( -1, absID, noise, TimeOfNoise() ) ;
342 //look if we have to add signal?
343 digit = dynamic_cast<AliPHOSDigit *>(digits->At(absID-1)) ;
346 //Add SDigits from all inputs
349 Float_t a = digit->GetEnergy() ;
350 Float_t b = TMath::Abs( a / fTimeSignalLength) ;
351 //Mark the beginning of the signal
352 new((*ticks)[contrib++]) AliPHOSTick(digit->GetTime(),0, b);
353 //Mark the end of the signal
354 new((*ticks)[contrib++]) AliPHOSTick(digit->GetTime()+fTimeSignalLength, -a, -b);
357 for(i = 0 ; i < fInput ; i++){
358 if( dynamic_cast<TClonesArray *>(sdigArray->At(i))->GetEntriesFast() > index[i] )
359 curSDigit = dynamic_cast<AliPHOSDigit*>(dynamic_cast<TClonesArray *>(sdigArray->At(i))->At(index[i])) ;
362 //May be several digits will contribute from the same input
363 while(curSDigit && curSDigit->GetId() == absID){
364 //Shift primary to separate primaries belonging different inputs
365 Int_t primaryoffset ;
367 primaryoffset = fManager->GetMask(i) ;
369 primaryoffset = 10000000*i ;
370 curSDigit->ShiftPrimary(primaryoffset) ;
372 a = curSDigit->GetEnergy() ;
373 b = a /fTimeSignalLength ;
374 new((*ticks)[contrib++]) AliPHOSTick(curSDigit->GetTime(),0, b);
375 new((*ticks)[contrib++]) AliPHOSTick(curSDigit->GetTime()+fTimeSignalLength, -a, -b);
377 *digit += *curSDigit ; //add energies
380 if( dynamic_cast<TClonesArray *>(sdigArray->At(i))->GetEntriesFast() > index[i] )
381 curSDigit = dynamic_cast<AliPHOSDigit*>(dynamic_cast<TClonesArray *>(sdigArray->At(i))->At(index[i])) ;
387 //calculate and set time
388 Float_t time = FrontEdgeTime(ticks) ;
389 digit->SetTime(time) ;
391 //Find next signal module
393 for(i = 0 ; i < fInput ; i++){
394 sdigits = dynamic_cast<TClonesArray *>(sdigArray->At(i)) ;
395 Int_t curNext = nextSig ;
396 if(sdigits->GetEntriesFast() > index[i] ){
397 curNext = dynamic_cast<AliPHOSDigit *>(sdigits->At(index[i]))->GetId() ;
399 if(curNext < nextSig) nextSig = curNext ;
407 //Now CPV digits (different noise and no timing)
408 for(absID = nEMC+1; absID <= nCPV; absID++){
409 Float_t noise = gRandom->Gaus(0., fCPVNoise) ;
410 new((*digits)[absID-1]) AliPHOSDigit( -1,absID,sDigitizer->Digitize(noise), TimeOfNoise() ) ;
411 //look if we have to add signal?
413 digit = dynamic_cast<AliPHOSDigit *>(digits->At(absID-1)) ;
414 //Add SDigits from all inputs
415 for(i = 0 ; i < fInput ; i++){
416 if( dynamic_cast<TClonesArray *>(sdigArray->At(i))->GetEntriesFast() > index[i] )
417 curSDigit = dynamic_cast<AliPHOSDigit*>( dynamic_cast<TClonesArray *>(sdigArray->At(i))->At(index[i])) ;
421 //May be several digits will contribute from the same input
422 while(curSDigit && curSDigit->GetId() == absID){
423 //Shift primary to separate primaries belonging different inputs
424 Int_t primaryoffset ;
426 primaryoffset = fManager->GetMask(i) ;
428 primaryoffset = 10000000*i ;
429 curSDigit->ShiftPrimary(primaryoffset) ;
432 *digit += *curSDigit ;
434 if( dynamic_cast<TClonesArray *>(sdigArray->At(i))->GetEntriesFast() > index[i] )
435 curSDigit = dynamic_cast<AliPHOSDigit*>( dynamic_cast<TClonesArray *>(sdigArray->At(i))->At(index[i]) ) ;
441 //Find next signal module
443 for(i = 0 ; i < fInput ; i++){
444 sdigits = dynamic_cast<TClonesArray *>(sdigArray->At(i)) ;
445 Int_t curNext = nextSig ;
446 if(sdigits->GetEntriesFast() > index[i] )
447 curNext = dynamic_cast<AliPHOSDigit *>( sdigits->At(index[i]) )->GetId() ;
448 if(curNext < nextSig) nextSig = curNext ;
454 delete sdigArray ; //We should not delete its contents
456 //remove digits below thresholds
457 for(i = 0 ; i < nEMC ; i++){
458 digit = dynamic_cast<AliPHOSDigit*>( digits->At(i) ) ;
459 DecalibrateEMC(digit);
460 if(digit->GetEnergy() < fEMCDigitThreshold)
461 digits->RemoveAt(i) ;
463 digit->SetTime(gRandom->Gaus(digit->GetTime(),fTimeResolution) ) ;
467 for(i = nEMC; i < nCPV ; i++)
468 // if( sDigitizer->Calibrate( dynamic_cast<AliPHOSDigit*>(digits->At(i))->GetAmp() ) < fCPVDigitThreshold )
469 if( dynamic_cast<AliPHOSDigit*>(digits->At(i))->GetEnergy() < fCPVDigitThreshold )
470 digits->RemoveAt(i) ;
474 Int_t ndigits = digits->GetEntriesFast() ;
475 digits->Expand(ndigits) ;
477 //Set indexes in list of digits and make true digitization of the energy
478 for (i = 0 ; i < ndigits ; i++) {
479 digit = dynamic_cast<AliPHOSDigit*>( digits->At(i) ) ;
480 digit->SetIndexInList(i) ;
481 if(digit->GetId() > fEmcCrystals){ //digitize CPV only
482 digit->SetAmp(DigitizeCPV(digit->GetEnergy(),digit->GetId()) ) ;
487 //____________________________________________________________________________
488 void AliPHOSDigitizer::DecalibrateEMC(AliPHOSDigit *digit)
490 // Decalibrate EMC digit, i.e. change its energy by a factor read from CDB
492 AliPHOSGetter* gime = AliPHOSGetter::Instance();
494 if(!gime->CalibData()) {
495 AliPHOSCalibData* cdb = new AliPHOSCalibData(-1);
496 gime->SetCalibData(cdb);
499 //Determine rel.position of the cell absolute ID
501 gime->PHOSGeometry()->AbsToRelNumbering(digit->GetId(),relId);
502 Int_t module=relId[0];
504 Int_t column=relId[3];
505 Float_t decalibration = gime->CalibData()->GetADCchannelEmc(module,column,row);
506 Float_t energy = digit->GetEnergy() / decalibration;
507 digit->SetEnergy(energy);
509 //____________________________________________________________________________
510 Int_t AliPHOSDigitizer::DigitizeCPV(Float_t charge, Int_t absId)
512 // Returns digitized value of the CPV charge in a pad absId
514 AliPHOSGetter* gime = AliPHOSGetter::Instance();
516 if(!gime->CalibData()) {
517 AliPHOSCalibData* cdb = new AliPHOSCalibData(-1); // use AliCDBManager's run number
518 gime->SetCalibData(cdb);
521 //Determine rel.position of the cell absId
523 gime->PHOSGeometry()->AbsToRelNumbering(absId,relId);
524 Int_t module=relId[0];
526 Int_t column=relId[3];
530 if(absId > fEmcCrystals){ //digitize CPV only
532 //reading calibration data for cell absId.
533 //If no calibration DB found, accept default values.
535 if(gime->CalibData()) {
536 fADCpedestalCpv = gime->CalibData()->GetADCpedestalCpv(module,column,row);
537 fADCchanelCpv = gime->CalibData()->GetADCchannelCpv( module,column,row);
540 channel = (Int_t) TMath::Ceil((charge - fADCpedestalCpv)/fADCchanelCpv) ;
541 if(channel > fNADCcpv ) channel = fNADCcpv ;
546 //____________________________________________________________________________
547 void AliPHOSDigitizer::Exec(Option_t *option)
549 // Steering method to process digitization for events
550 // in the range from fFirstEvent to fLastEvent.
551 // This range is optionally set by SetEventRange().
552 // if fLastEvent=-1, then process events until the end.
553 // by default fLastEvent = fFirstEvent (process only one event)
555 if (!fInit) { // to prevent overwrite existing file
556 AliError(Form("Give a version name different from %s",
557 fEventFolderName.Data() )) ;
561 if (strstr(option,"print")) {
566 if(strstr(option,"tim"))
567 gBenchmark->Start("PHOSDigitizer");
569 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle()) ;
571 // Post Digitizer to the white board
572 gime->PostDigitizer(this) ;
574 if (fLastEvent == -1)
575 fLastEvent = gime->MaxEvent() - 1 ;
577 fLastEvent = fFirstEvent ;
579 Int_t nEvents = fLastEvent - fFirstEvent + 1;
583 for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
585 gime->Event(ievent,"S") ;
587 Digitize(ievent) ; //Add prepared SDigits to digits and add the noise
591 if(strstr(option,"deb"))
594 //increment the total number of Digits per run
595 fDigitsInRun += gime->Digits()->GetEntriesFast() ;
598 gime->PhosLoader()->CleanDigitizer();
600 if(strstr(option,"tim")){
601 gBenchmark->Stop("PHOSDigitizer");
603 message = " took %f seconds for Digitizing %f seconds per event\n" ;
604 AliInfo(Form( message.Data(),
605 gBenchmark->GetCpuTime("PHOSDigitizer"),
606 gBenchmark->GetCpuTime("PHOSDigitizer")/nEvents ));
610 //____________________________________________________________________________
611 Float_t AliPHOSDigitizer::FrontEdgeTime(TClonesArray * ticks) const
613 // Returns the shortest time among all time ticks
615 ticks->Sort() ; //Sort in accordance with times of ticks
617 AliPHOSTick * ctick = (AliPHOSTick *) it.Next() ;
618 Float_t time = ctick->CrossingTime(fTimeThreshold) ;
621 while((t=(AliPHOSTick*) it.Next())){
622 if(t->GetTime() < time) //This tick starts before crossing
627 time = ctick->CrossingTime(fTimeThreshold) ;
632 //____________________________________________________________________________
633 Bool_t AliPHOSDigitizer::Init()
635 // Makes all memory allocations
637 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName) ;
639 AliFatal(Form("Could not obtain the Getter object for file %s and event %s !",
640 GetTitle(), fEventFolderName.Data()));
644 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
646 fEmcCrystals = geom->GetNModules() * geom->GetNCristalsInModule() ;
648 TString opt("Digits") ;
649 if(gime->VersionExists(opt) ) {
650 AliError(Form("Give a version name different from %s",
651 fEventFolderName.Data() )) ;
656 fLastEvent = fFirstEvent ;
658 fInput = fManager->GetNinputs() ;
662 fInputFileNames = new TString[fInput] ;
663 fEventNames = new TString[fInput] ;
664 fInputFileNames[0] = GetTitle() ;
665 fEventNames[0] = fEventFolderName.Data() ;
667 for (index = 1 ; index < fInput ; index++) {
668 fInputFileNames[index] = dynamic_cast<AliStream*>(fManager->GetInputStream(index))->GetFileName(0);
669 TString tempo = fManager->GetInputFolderName(index) ;
670 fEventNames[index] = tempo.Remove(tempo.Length()-1) ; // strip of the stream number added by fManager
673 //to prevent cleaning of this object while GetEvent is called
674 gime->PhosLoader()->GetDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
679 //____________________________________________________________________________
680 void AliPHOSDigitizer::InitParameters()
682 // Set initial parameters Digitizer
684 fPinNoise = 0.004 ; // [GeV]
685 fEMCDigitThreshold = 0.012 ; // [GeV]
686 fCPVNoise = 0.01; // [aux units]
687 fCPVDigitThreshold = 0.09 ; // [aux units]
688 fTimeResolution = 0.5e-9 ; // [sec]
689 fTimeSignalLength = 1.0e-9 ; // [sec]
691 fADCchanelEmc = 1.0; // Coefficient between real and measured energies in EMC
692 fADCpedestalEmc = 0. ; //
693 fNADCemc = (Int_t) TMath::Power(2,16) ; // number of channels in EMC ADC
695 fADCchanelCpv = 0.0012 ; // width of one ADC channel in CPV 'popugais'
696 fADCpedestalCpv = 0.012 ; //
697 fNADCcpv = (Int_t) TMath::Power(2,12); // number of channels in CPV ADC
699 // fTimeThreshold = 0.001*10000000 ; //Means 1 MeV in terms of SDigits amplitude
700 fTimeThreshold = 0.001 ; // [GeV]
701 SetEventRange(0,-1) ;
705 //__________________________________________________________________
706 void AliPHOSDigitizer::MixWith(TString alirunFileName, TString eventFolderName)
708 // Allows to produce digits by superimposing background and signal event.
709 // It is assumed, that headers file with SIGNAL events is opened in
711 // Sets the BACKGROUND event, with which the SIGNAL event is to be mixed
712 // Thus we avoid writing (changing) huge and expensive
713 // backgound files: all output will be writen into SIGNAL, i.e.
714 // opened in constructor file.
716 // One can open as many files to mix with as one needs.
717 // However only Sdigits with the same name (i.e. constructed with the same SDigitizer)
720 if( strcmp(fEventFolderName, "") == 0 )
724 Warning("MixWith", "Cannot use this method with AliRunDigitizer\n" ) ;
727 // looking for file which contains AliRun
728 if (gSystem->AccessPathName(alirunFileName)) {// file does not exist
729 AliError(Form("File %s does not exist!", alirunFileName.Data())) ;
732 // looking for the file which contains SDigits
733 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
734 TString fileName( gime->GetSDigitsFileName() ) ;
735 if ( eventFolderName != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
736 fileName = fileName.ReplaceAll(".root", "") + "_" + eventFolderName + ".root" ;
737 if ( (gSystem->AccessPathName(fileName)) ) {
738 AliError(Form("The file %s does not exist!", fileName.Data())) ;
741 // need to increase the arrays
742 TString tempo = fInputFileNames[fInput-1] ;
743 delete [] fInputFileNames ;
744 fInputFileNames = new TString[fInput+1] ;
745 fInputFileNames[fInput-1] = tempo ;
747 tempo = fEventNames[fInput-1] ;
748 delete [] fEventNames ;
749 fEventNames = new TString[fInput+1] ;
750 fEventNames[fInput-1] = tempo ;
752 fInputFileNames[fInput] = alirunFileName ;
753 fEventNames[fInput] = eventFolderName ;
757 //__________________________________________________________________
758 void AliPHOSDigitizer::Print(const Option_t *)const
760 // Print Digitizer's parameters
761 AliInfo(Form("\n------------------- %s -------------", GetName() )) ;
762 if( strcmp(fEventFolderName.Data(), "") != 0 ){
763 printf(" Writing Digits to branch with title %s\n", fEventFolderName.Data()) ;
767 nStreams = GetNInputStreams() ;
772 for (index = 0 ; index < nStreams ; index++) {
773 TString tempo(fEventNames[index]) ;
775 AliPHOSGetter * gime = AliPHOSGetter::Instance(fInputFileNames[index], tempo) ;
776 TString fileName( gime->GetSDigitsFileName() ) ;
777 if ( fEventNames[index] != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
778 fileName = fileName.ReplaceAll(".root", "") + "_" + fEventNames[index] + ".root" ;
779 printf ("Adding SDigits from %s %s\n", fInputFileNames[index].Data(), fileName.Data()) ;
781 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName) ;
782 printf("\nWriting digits to %s", gime->GetDigitsFileName().Data()) ;
784 printf("\nWith following parameters:\n") ;
785 printf(" Electronics noise in EMC (fPinNoise) = %f GeV\n", fPinNoise ) ;
786 printf(" Threshold in EMC (fEMCDigitThreshold) = %f GeV\n", fEMCDigitThreshold ) ;
787 printf(" Noise in CPV (fCPVNoise) = %f aux units\n", fCPVNoise ) ;
788 printf(" Threshold in CPV (fCPVDigitThreshold) = %f aux units\n",fCPVDigitThreshold ) ;
789 printf(" ---------------------------------------------------\n") ;
792 AliInfo(Form("AliPHOSDigitizer not initialized" )) ;
796 //__________________________________________________________________
797 void AliPHOSDigitizer::PrintDigits(Option_t * option)
799 // Print a table of digits
801 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName) ;
802 TClonesArray * digits = gime->Digits() ;
804 AliInfo(Form("%d", digits->GetEntriesFast())) ;
805 printf("\nevent %d", gAlice->GetEvNumber()) ;
806 printf("\n Number of entries in Digits list %d", digits->GetEntriesFast() ) ;
809 if(strstr(option,"all")||strstr(option,"EMC")){
811 AliPHOSDigit * digit;
812 printf("\nEMC digits (with primaries):\n") ;
813 printf("\n Id Amplitude Time Index Nprim: Primaries list \n") ;
814 Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
816 for (index = 0 ; (index < digits->GetEntriesFast()) &&
817 (dynamic_cast<AliPHOSDigit *>(digits->At(index))->GetId() <= maxEmc) ; index++) {
818 digit = (AliPHOSDigit * ) digits->At(index) ;
819 if(digit->GetNprimary() == 0)
821 // printf("%6d %8d %6.5e %4d %2d :",
822 // digit->GetId(), digit->GetAmp(), digit->GetTime(), digit->GetIndexInList(), digit->GetNprimary()) ; // YVK
823 printf("%6d %.4f %6.5e %4d %2d :",
824 digit->GetId(), digit->GetEnergy(), digit->GetTime(), digit->GetIndexInList(), digit->GetNprimary()) ;
826 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
827 printf("%d ",digit->GetPrimary(iprimary+1) ) ;
833 if(strstr(option,"all")||strstr(option,"CPV")){
835 //loop over CPV digits
836 AliPHOSDigit * digit;
837 printf("\nCPV digits (with primaries):\n") ;
838 printf("\n Id Amplitude Time Index Nprim: Primaries list \n") ;
839 Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
841 for (index = 0 ; index < digits->GetEntriesFast(); index++) {
842 digit = (AliPHOSDigit * ) digits->At(index) ;
843 if(digit->GetId() > maxEmc){
844 printf("%6d %8d %4d %2d :",
845 digit->GetId(), digit->GetAmp(), digit->GetIndexInList(), digit->GetNprimary()) ;
847 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
848 printf("%d ",digit->GetPrimary(iprimary+1) ) ;
857 //__________________________________________________________________
858 Float_t AliPHOSDigitizer::TimeOfNoise(void) const
859 { // Calculates the time signal generated by noise
860 //PH Info("TimeOfNoise", "Change me") ;
861 return gRandom->Rndm() * 1.28E-5;
864 //__________________________________________________________________
865 void AliPHOSDigitizer::Unload()
869 for(i = 1 ; i < fInput ; i++){
870 TString tempo(fEventNames[i]) ;
872 AliPHOSGetter * gime = AliPHOSGetter::Instance(fInputFileNames[i], tempo) ;
873 gime->PhosLoader()->UnloadSDigits() ;
876 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName) ;
877 gime->PhosLoader()->UnloadDigits() ;
880 //____________________________________________________________________________
881 void AliPHOSDigitizer::WriteDigits()
884 // Makes TreeD in the output file.
885 // Check if branch already exists:
886 // if yes, exit without writing: ROOT TTree does not support overwriting/updating of
887 // already existing branches.
888 // else creates branch with Digits, named "PHOS", title "...",
889 // and branch "AliPHOSDigitizer", with the same title to keep all the parameters
890 // and names of files, from which digits are made.
892 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle()) ;
893 const TClonesArray * digits = gime->Digits() ;
894 TTree * treeD = gime->TreeD();
896 // -- create Digits branch
897 Int_t bufferSize = 32000 ;
898 TBranch * digitsBranch = treeD->Branch("PHOS","TClonesArray",&digits,bufferSize);
899 digitsBranch->SetTitle(fEventFolderName);
900 digitsBranch->Fill() ;
902 gime->WriteDigits("OVERWRITE");
903 gime->WriteDigitizer("OVERWRITE");