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:
20 * $Log: AliPHOSDigitizer.cxx,v $
21 * Revision 1.104 2007/12/18 09:08:18 hristov
22 * Splitting of the QA maker into simulation and reconstruction dependent parts (Yves)
24 * Revision 1.103 2007/11/07 11:25:06 schutz
25 * Comment out the QA checking before starting digitization
27 * Revision 1.102 2007/10/19 18:04:29 schutz
28 * The standalone QA data maker is called from AliSimulation and AliReconstruction outside the event loop; i.e. re-reading the data. The QA data making in the event loop has been commented out.
30 * Revision 1.101 2007/10/14 21:08:10 schutz
31 * Introduced the checking of QA results from previous step before entering the event loop
33 * Revision 1.100 2007/10/10 09:05:10 schutz
34 * Changing name QualAss to QA
36 * Revision 1.99 2007/09/30 17:08:20 schutz
37 * Introducing the notion of QA data acquisition cycle (needed by online)
39 * Revision 1.98 2007/09/26 14:22:17 cvetan
40 * Important changes to the reconstructor classes. Complete elimination of the run-loaders, which are now steered only from AliReconstruction. Removal of the corresponding Reconstruct() and FillESD() methods.
42 * Revision 1.97 2007/08/07 14:12:03 kharlov
43 * Quality assurance added (Yves Schutz)
45 * Revision 1.96 2007/04/28 10:43:36 policheh
46 * Dead channels simulation: digit energy sets to 0.
48 * Revision 1.95 2007/04/10 07:20:52 kharlov
49 * Decalibration should use the same CDB as calibration in AliPHOSClusterizerv1
51 * Revision 1.94 2007/02/01 10:34:47 hristov
52 * Removing warnings on Solaris x86
54 * Revision 1.93 2006/10/17 13:17:01 kharlov
55 * Replace AliInfo by AliDebug
57 * Revision 1.92 2006/08/28 10:01:56 kharlov
58 * Effective C++ warnings fixed (Timur Pocheptsov)
60 * Revision 1.91 2006/04/29 20:25:30 hristov
61 * Decalibration is implemented (Yu.Kharlov)
63 * Revision 1.90 2006/04/22 10:30:17 hristov
64 * Add fEnergy to AliPHOSDigit and operate with EMC amplitude in energy units (Yu.Kharlov)
66 * Revision 1.89 2006/04/11 15:22:59 hristov
67 * run number in query set to -1: forces AliCDBManager to use its run number (A.Colla)
69 * Revision 1.88 2006/03/13 14:05:43 kharlov
70 * Calibration objects for EMC and CPV
72 * Revision 1.87 2005/08/24 15:33:49 kharlov
73 * Calibration data for raw digits
75 * Revision 1.86 2005/07/12 20:07:35 hristov
76 * Changes needed to run simulation and reconstrruction in the same AliRoot session
78 * Revision 1.85 2005/05/28 14:19:04 schutz
79 * Compilation warnings fixed by T.P.
83 //_________________________________________________________________________
84 //*-- Author : Dmitri Peressounko (SUBATECH & Kurchatov Institute)
85 //////////////////////////////////////////////////////////////////////////////
86 // This TTask performs digitization of Summable digits (in the PHOS case it is just
87 // the sum of contributions from all primary particles into a given cell).
88 // In addition it performs mixing of summable digits from different events.
89 // The name of the TTask is also the title of the branch that will contain
90 // the created SDigits
91 // The title of the TTAsk is the name of the file that contains the hits from
92 // which the SDigits are created
94 // For each event two branches are created in TreeD:
95 // "PHOS" - list of digits
96 // "AliPHOSDigitizer" - AliPHOSDigitizer with all parameters used in digitization
98 // Note, that one can set a title for new digits branch, and repeat digitization with
99 // another set of parameters.
102 // root[0] AliPHOSDigitizer * d = new AliPHOSDigitizer() ;
103 // root[1] d->ExecuteTask()
104 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
105 // //Digitizes SDigitis in all events found in file galice.root
107 // root[2] AliPHOSDigitizer * d1 = new AliPHOSDigitizer("galice1.root") ;
108 // // Will read sdigits from galice1.root
109 // root[3] d1->MixWith("galice2.root")
110 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
111 // // Reads another set of sdigits from galice2.root
112 // root[3] d1->MixWith("galice3.root")
113 // // Reads another set of sdigits from galice3.root
114 // root[4] d->ExecuteTask("deb timing")
115 // // Reads SDigits from files galice1.root, galice2.root ....
116 // // mixes them and stores produced Digits in file galice1.root
117 // // deb - prints number of produced digits
118 // // deb all - prints list of produced digits
119 // // timing - prints time used for digitization
122 // --- ROOT system ---
125 #include "TBenchmark.h"
129 // --- Standard library ---
131 // --- AliRoot header files ---
132 #include <TGeoManager.h>
134 #include "AliRunDigitizer.h"
135 #include "AliPHOSDigit.h"
136 #include "AliPHOSDigitizer.h"
137 #include "AliPHOSGeometry.h"
138 #include "AliPHOSTick.h"
139 #include "AliPHOSSimParam.h"
140 #include "AliPHOSCalibData.h"
141 #include "AliRunLoader.h"
142 #include "AliPHOSLoader.h"
143 #include "AliPHOSPulseGenerator.h"
145 ClassImp(AliPHOSDigitizer)
148 //____________________________________________________________________________
149 AliPHOSDigitizer::AliPHOSDigitizer() :
155 fInputFileNames(0x0),
158 fEventFolderName(""),
169 fManager = 0 ; // We work in the standalong mode
172 //____________________________________________________________________________
173 AliPHOSDigitizer::AliPHOSDigitizer(TString alirunFileName,
174 TString eventFolderName):
175 AliDigitizer("PHOS"+AliConfig::Instance()->GetDigitizerTaskName(), alirunFileName),
176 fDefaultInit(kFALSE),
180 fInputFileNames(0x0),
183 fEventFolderName(eventFolderName),
195 fDefaultInit = kFALSE ;
196 fManager = 0 ; // We work in the standalone mode
197 fcdb = new AliPHOSCalibData(-1);
200 //____________________________________________________________________________
201 AliPHOSDigitizer::AliPHOSDigitizer(const AliPHOSDigitizer & d) :
203 fDefaultInit(d.fDefaultInit),
204 fDigitsInRun(d.fDigitsInRun),
207 fInputFileNames(0x0),//?
209 fEmcCrystals(d.fEmcCrystals),
210 fEventFolderName(d.fEventFolderName),
211 fFirstEvent(d.fFirstEvent),
212 fLastEvent(d.fLastEvent),
220 SetName(d.GetName()) ;
221 SetTitle(d.GetTitle()) ;
222 fcdb = new AliPHOSCalibData(-1);
225 //____________________________________________________________________________
226 AliPHOSDigitizer::AliPHOSDigitizer(AliRunDigitizer * rd) :
227 AliDigitizer(rd,"PHOS"+AliConfig::Instance()->GetDigitizerTaskName()),
228 fDefaultInit(kFALSE),
232 fInputFileNames(0x0),
235 fEventFolderName(fManager->GetInputFolderName(0)),
245 // ctor Init() is called by RunDigitizer
247 SetTitle(dynamic_cast<AliStream*>(fManager->GetInputStream(0))->GetFileName(0));
249 fDefaultInit = kFALSE ;
250 fcdb = new AliPHOSCalibData(-1);
253 //____________________________________________________________________________
254 AliPHOSDigitizer::~AliPHOSDigitizer()
257 AliRunLoader* rl = AliRunLoader::GetRunLoader(fEventFolderName) ;
259 AliPHOSLoader * phosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
260 phosLoader->CleanDigitizer() ;
263 delete [] fInputFileNames ;
264 delete [] fEventNames ;
267 delete [] fADCValuesLG;
268 delete [] fADCValuesHG;
270 if(fcdb){ delete fcdb ; fcdb=0;}
274 //____________________________________________________________________________
275 void AliPHOSDigitizer::Digitize(Int_t event)
278 // Makes the digitization of the collected summable digits.
279 // It first creates the array of all PHOS modules
280 // filled with noise (different for EMC, and CPV) and
281 // then adds contributions from SDigits.
282 // This design avoids scanning over the list of digits to add
283 // contribution to new SDigits only.
285 Bool_t toMakeNoise = kTRUE ; //Do not create noisy digits if merge with real data
288 AliRunLoader* rl = AliRunLoader::GetRunLoader(fEventFolderName) ;
289 AliPHOSLoader * phosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
291 Int_t readEvent = event ;
293 readEvent = dynamic_cast<AliStream*>(fManager->GetInputStream(0))->GetCurrentEventNumber() ;
294 AliDebug(1,Form("Adding event %d from input stream 0 %s %s",
295 readEvent, GetTitle(), fEventFolderName.Data())) ;
296 rl->GetEvent(readEvent) ;
297 phosLoader->CleanSDigits() ;
298 phosLoader->LoadSDigits("READ") ;
301 TClonesArray * digits = phosLoader->Digits() ;
303 phosLoader->MakeDigitsArray() ;
304 digits = phosLoader->Digits() ;
310 const AliPHOSGeometry *geom = AliPHOSGeometry::GetInstance() ;
311 //Making digits with noise, first EMC
312 //Check which PHOS modules are present
313 Bool_t isPresent[5] ;
316 for(Int_t i=0; i<5; i++){
317 volpath = "/ALIC_1/PHOS_";
319 if (gGeoManager->CheckPath(volpath.Data())) {
328 Int_t nEMC = nmod*geom->GetNPhi()*geom->GetNZ();
333 //check if CPV exists
334 Bool_t isCPVpresent=0 ;
335 for(Int_t i=1; i<=5 && !isCPVpresent; i++){
336 volpath = "/ALIC_1/PHOS_";
338 volpath += "/PCPV_1";
339 if (gGeoManager->CheckPath(volpath.Data()))
344 nCPV = nEMC + geom->GetNumberOfCPVPadsZ() * geom->GetNumberOfCPVPadsPhi() * nmod ;
350 digits->Expand(nCPV) ;
352 //take all the inputs to add together and load the SDigits
353 TObjArray * sdigArray = new TObjArray(fInput) ;
354 sdigArray->AddAt(phosLoader->SDigits(), 0) ;
356 for(Int_t i = 1 ; i < fInput ; i++){
357 TString tempo(fEventNames[i]) ;
359 AliRunLoader* rl2 = AliRunLoader::GetRunLoader(tempo) ;
361 rl2 = AliRunLoader::Open(fInputFileNames[i], tempo) ;
363 Fatal("AliPHOSDigitizer", "Could not find the Run Loader for %s - %s",fInputFileNames[i].Data(), tempo.Data()) ;
368 AliPHOSLoader * phosLoader2 = dynamic_cast<AliPHOSLoader*>(rl2->GetLoader("PHOSLoader"));
371 readEvent = dynamic_cast<AliStream*>(fManager->GetInputStream(i))->GetCurrentEventNumber() ;
373 TClonesArray * digs ;
374 if(AliPHOSSimParam::GetInstance()->IsStreamDigits(i)){ //This is Digits Stream
375 AliInfo(Form("Adding event %d from input stream %d %s %s",
376 readEvent, i, fInputFileNames[i].Data(), tempo.Data())) ;
377 rl2->GetEvent(readEvent) ;
378 phosLoader2->CleanDigits() ;
379 phosLoader2->LoadDigits("READ") ;
380 digs = phosLoader2->Digits() ;
381 toMakeNoise=0 ; //Do not add noise, it is already in stream
384 AliInfo(Form("Adding event %d (SDigits) from input stream %d %s %s",
385 readEvent, i, fInputFileNames[i].Data(), tempo.Data())) ;
386 rl2->GetEvent(readEvent) ;
387 phosLoader2->CleanSDigits() ;
388 phosLoader2->LoadSDigits("READ") ;
389 digs = phosLoader2->SDigits() ;
391 sdigArray->AddAt(digs, i) ;
394 //Find the first crystal with signal
395 Int_t nextSig = 200000 ;
396 TClonesArray * sdigits ;
397 for(Int_t i = 0 ; i < fInput ; i++){
398 sdigits = dynamic_cast<TClonesArray *>(sdigArray->At(i)) ;
399 if ( !sdigits->GetEntriesFast() )
401 Int_t curNext = dynamic_cast<AliPHOSDigit *>(sdigits->At(0))->GetId() ;
402 if(curNext < nextSig)
406 TArrayI index(fInput) ;
407 index.Reset() ; //Set all indexes to zero
409 AliPHOSDigit * digit ;
410 AliPHOSDigit * curSDigit ;
412 // TClonesArray * ticks = new TClonesArray("AliPHOSTick",1000) ;
414 //Put Noise contribution
415 Double_t apdNoise = 0. ;
417 apdNoise = AliPHOSSimParam::GetInstance()->GetAPDNoise() ;
419 Int_t emcpermod=geom->GetNPhi()*geom->GetNZ();
421 for(Int_t imod=0; imod<5; imod++){
424 Int_t firstAbsId=imod*emcpermod+1 ;
425 Int_t lastAbsId =(imod+1)*emcpermod ;
426 for(absID = firstAbsId ; absID <= lastAbsId ; absID++){
427 Float_t noise = gRandom->Gaus(0.,apdNoise) ;
428 new((*digits)[idigit]) AliPHOSDigit( -1, absID, noise, TimeOfNoise() ) ;
429 //look if we have to add signal?
430 digit = dynamic_cast<AliPHOSDigit *>(digits->At(idigit)) ;
434 //Add SDigits from all inputs
436 // Int_t contrib = 0 ;
438 //New Timing model is necessary
439 // Float_t a = digit->GetEnergy() ;
440 // Float_t b = TMath::Abs( a / fTimeSignalLength) ;
441 // //Mark the beginning of the signal
442 // new((*ticks)[contrib++]) AliPHOSTick(digit->GetTime(),0, b);
443 // //Mark the end of the signal
444 // new((*ticks)[contrib++]) AliPHOSTick(digit->GetTime()+fTimeSignalLength, -a, -b);
446 // Calculate time as time of the largest digit
447 Float_t time = digit->GetTime() ;
448 Float_t eTime= digit->GetEnergy() ;
451 for(Int_t i = 0 ; i < fInput ; i++){
452 if( dynamic_cast<TClonesArray *>(sdigArray->At(i))->GetEntriesFast() > index[i] ){
453 curSDigit = dynamic_cast<AliPHOSDigit*>(dynamic_cast<TClonesArray *>(sdigArray->At(i))->At(index[i])) ;
454 if(AliPHOSSimParam::GetInstance()->IsStreamDigits(i)){ //This is Digits Stream
455 curSDigit->SetEnergy(Calibrate(curSDigit->GetEnergy(),curSDigit->GetId())) ;
456 curSDigit->SetTime(CalibrateT(curSDigit->GetTime(),curSDigit->GetId())) ;
461 //May be several digits will contribute from the same input
462 while(curSDigit && curSDigit->GetId() == absID){
463 //Shift primary to separate primaries belonging different inputs
464 Int_t primaryoffset ;
466 primaryoffset = fManager->GetMask(i) ;
468 primaryoffset = 10000000*i ;
469 curSDigit->ShiftPrimary(primaryoffset) ;
471 //New Timing model is necessary
472 // a = curSDigit->GetEnergy() ;
473 // b = a /fTimeSignalLength ;
474 // new((*ticks)[contrib++]) AliPHOSTick(curSDigit->GetTime(),0, b);
475 // new((*ticks)[contrib++]) AliPHOSTick(curSDigit->GetTime()+fTimeSignalLength, -a, -b);
476 if(curSDigit->GetEnergy()>eTime){
477 eTime=curSDigit->GetEnergy() ;
478 time=curSDigit->GetTime() ;
480 *digit += *curSDigit ; //add energies
483 if( dynamic_cast<TClonesArray *>(sdigArray->At(i))->GetEntriesFast() > index[i] )
484 curSDigit = dynamic_cast<AliPHOSDigit*>(dynamic_cast<TClonesArray *>(sdigArray->At(i))->At(index[i])) ;
490 //calculate and set time
491 //New Timing model is necessary
492 // Float_t time = FrontEdgeTime(ticks) ;
493 digit->SetTime(time) ;
495 //Find next signal module
497 for(Int_t i = 0 ; i < fInput ; i++){
498 sdigits = dynamic_cast<TClonesArray *>(sdigArray->At(i)) ;
499 Int_t curNext = nextSig ;
500 if(sdigits->GetEntriesFast() > index[i] ){
501 curNext = dynamic_cast<AliPHOSDigit *>(sdigits->At(index[i]))->GetId() ;
503 if(curNext < nextSig) nextSig = curNext ;
509 //distretize energy if necessary
510 if(AliPHOSSimParam::GetInstance()->IsEDigitizationOn()){
511 Float_t adcW=AliPHOSSimParam::GetInstance()->GetADCchannelW() ;
512 for(Int_t i = 0 ; i < nEMC ; i++){
513 digit = dynamic_cast<AliPHOSDigit*>( digits->At(i) ) ;
514 digit->SetEnergy(adcW*ceil(digit->GetEnergy()/adcW)) ;
517 //Apply decalibration if necessary
518 for(Int_t i = 0 ; i < nEMC ; i++){
519 digit = dynamic_cast<AliPHOSDigit*>( digits->At(i) ) ;
527 //Now CPV digits (different noise and no timing)
528 Int_t cpvpermod = geom->GetNumberOfCPVPadsZ() * geom->GetNumberOfCPVPadsPhi() ;
529 Int_t nEMCtotal=emcpermod*5 ;
530 Float_t cpvNoise = AliPHOSSimParam::GetInstance()->GetCPVNoise() ;
531 if(isCPVpresent){ //CPV is present in current geometry
532 for(Int_t imod=0; imod<5; imod++){ //module is present in current geometry
535 Int_t firstAbsId=nEMCtotal+imod*cpvpermod+1 ;
536 Int_t lastAbsId =nEMCtotal+(imod+1)*cpvpermod ;
537 for(absID = firstAbsId; absID <= lastAbsId; absID++){
538 Float_t noise = gRandom->Gaus(0., cpvNoise) ;
539 new((*digits)[idigit]) AliPHOSDigit( -1,absID,noise, TimeOfNoise() ) ;
541 //look if we have to add signal?
543 digit = dynamic_cast<AliPHOSDigit *>(digits->At(idigit-1)) ;
544 //Add SDigits from all inputs
545 for(Int_t i = 0 ; i < fInput ; i++){
546 if( dynamic_cast<TClonesArray *>(sdigArray->At(i))->GetEntriesFast() > index[i] )
547 curSDigit = dynamic_cast<AliPHOSDigit*>( dynamic_cast<TClonesArray *>(sdigArray->At(i))->At(index[i])) ;
551 //May be several digits will contribute from the same input
552 while(curSDigit && curSDigit->GetId() == absID){
553 //Shift primary to separate primaries belonging different inputs
554 Int_t primaryoffset ;
556 primaryoffset = fManager->GetMask(i) ;
558 primaryoffset = 10000000*i ;
559 curSDigit->ShiftPrimary(primaryoffset) ;
562 *digit += *curSDigit ;
564 if( dynamic_cast<TClonesArray *>(sdigArray->At(i))->GetEntriesFast() > index[i] )
565 curSDigit = dynamic_cast<AliPHOSDigit*>( dynamic_cast<TClonesArray *>(sdigArray->At(i))->At(index[i]) ) ;
571 //Find next signal module
573 for(Int_t i = 0 ; i < fInput ; i++){
574 sdigits = dynamic_cast<TClonesArray *>(sdigArray->At(i)) ;
575 Int_t curNext = nextSig ;
576 if(sdigits->GetEntriesFast() > index[i] )
577 curNext = dynamic_cast<AliPHOSDigit *>( sdigits->At(index[i]) )->GetId() ;
578 if(curNext < nextSig) nextSig = curNext ;
586 delete sdigArray ; //We should not delete its contents
590 //set amplitudes in bad channels to zero
592 for(Int_t i = 0 ; i <digits->GetEntriesFast(); i++){
593 digit = dynamic_cast<AliPHOSDigit*>( digits->At(i) ) ;
594 geom->AbsToRelNumbering(digit->GetId(),relId);
595 if(relId[1] == 0) // Emc
596 if(fcdb->IsBadChannelEmc(relId[0],relId[3],relId[2])) digit->SetEnergy(0.);
599 //remove digits below thresholds
600 Float_t emcThreshold = AliPHOSSimParam::GetInstance()->GetEmcDigitsThreshold() ;
601 for(Int_t i = 0 ; i < nEMC ; i++){
602 digit = dynamic_cast<AliPHOSDigit*>( digits->At(i) ) ;
604 if(digit->GetEnergy() < emcThreshold){
605 digits->RemoveAt(i) ;
609 geom->AbsToRelNumbering(digit->GetId(),relId);
611 digit->SetEnergy(TMath::Ceil(digit->GetEnergy())-0.9999) ;
613 Float_t tres = TimeResolution(digit->GetEnergy()) ;
614 digit->SetTime(gRandom->Gaus(digit->GetTime(), tres) ) ;
617 fPulse->SetAmplitude(digit->GetEnergy()/
618 fcdb->GetADCchannelEmc(relId[0],relId[3],relId[2]));
619 fPulse->SetTZero(digit->GetTimeR());
620 fPulse->MakeSamples();
621 fPulse->GetSamples(fADCValuesHG, fADCValuesLG) ;
622 Int_t nSamples = fPulse->GetRawFormatTimeBins();
623 digit->SetALTROSamplesHG(nSamples,fADCValuesHG);
624 digit->SetALTROSamplesLG(nSamples,fADCValuesLG);
627 Float_t cpvDigitThreshold = AliPHOSSimParam::GetInstance()->GetCpvDigitsThreshold() ;
628 for(Int_t i = nEMC; i < nCPV ; i++){
629 if( dynamic_cast<AliPHOSDigit*>(digits->At(i))->GetEnergy() < cpvDigitThreshold )
630 digits->RemoveAt(i) ;
634 Int_t ndigits = digits->GetEntriesFast() ;
636 //Set indexes in list of digits and make true digitization of the energy
637 for (Int_t i = 0 ; i < ndigits ; i++) {
638 digit = dynamic_cast<AliPHOSDigit*>( digits->At(i) ) ;
639 digit->SetIndexInList(i) ;
640 if(digit->GetId() > fEmcCrystals){ //digitize CPV only
641 digit->SetAmp(DigitizeCPV(digit->GetEnergy(),digit->GetId()) ) ;
646 //____________________________________________________________________________
647 Float_t AliPHOSDigitizer::Calibrate(Float_t amp,Int_t absId){
649 const AliPHOSGeometry *geom = AliPHOSGeometry::GetInstance() ;
651 //Determine rel.position of the cell absolute ID
653 geom->AbsToRelNumbering(absId,relId);
654 Int_t module=relId[0];
656 Int_t column=relId[3];
657 if(relId[1]==0){ //This Is EMC
658 Float_t calibration = fcdb->GetADCchannelEmc(module,column,row);
659 return amp*calibration ;
663 //____________________________________________________________________________
664 void AliPHOSDigitizer::Decalibrate(AliPHOSDigit *digit)
666 // Decalibrate EMC digit, i.e. change its energy by a factor read from CDB
668 const AliPHOSGeometry *geom = AliPHOSGeometry::GetInstance() ;
670 //Determine rel.position of the cell absolute ID
672 geom->AbsToRelNumbering(digit->GetId(),relId);
673 Int_t module=relId[0];
675 Int_t column=relId[3];
676 if(relId[1]==0){ //This Is EMC
677 Float_t calibration = fcdb->GetADCchannelEmc(module,column,row);
678 Float_t energy = digit->GetEnergy()/calibration;
679 digit->SetEnergy(energy); //Now digit measures E in ADC counts
680 Float_t time = digit->GetTime() ;
681 time-=fcdb->GetTimeShiftEmc(module,column,row);
682 digit->SetTime(time) ;
685 //____________________________________________________________________________
686 Float_t AliPHOSDigitizer::CalibrateT(Float_t time,Int_t absId){
687 //Apply time calibration
688 const AliPHOSGeometry *geom = AliPHOSGeometry::GetInstance() ;
690 //Determine rel.position of the cell absolute ID
692 geom->AbsToRelNumbering(absId,relId);
693 Int_t module=relId[0];
695 Int_t column=relId[3];
696 time += fcdb->GetTimeShiftEmc(module,column,row);
699 //____________________________________________________________________________
700 Int_t AliPHOSDigitizer::DigitizeCPV(Float_t charge, Int_t absId)
702 // Returns digitized value of the CPV charge in a pad absId
704 const AliPHOSGeometry *geom = AliPHOSGeometry::GetInstance() ;
706 //Determine rel.position of the cell absId
708 geom->AbsToRelNumbering(absId,relId);
709 Int_t module=relId[0];
711 Int_t column=relId[3];
715 if(absId > fEmcCrystals){ //digitize CPV only
717 //reading calibration data for cell absId.
718 Float_t adcPedestalCpv = fcdb->GetADCpedestalCpv(module,column,row);
719 Float_t adcChanelCpv = fcdb->GetADCchannelCpv( module,column,row);
721 channel = (Int_t) TMath::Ceil((charge - adcPedestalCpv)/adcChanelCpv) ;
722 Int_t nMax = AliPHOSSimParam::GetInstance()->GetNADCcpv() ;
723 if(channel > nMax ) channel = nMax ;
728 //____________________________________________________________________________
729 void AliPHOSDigitizer::Exec(Option_t *option)
731 // Steering method to process digitization for events
732 // in the range from fFirstEvent to fLastEvent.
733 // This range is optionally set by SetEventRange().
734 // if fLastEvent=-1, then process events until the end.
735 // by default fLastEvent = fFirstEvent (process only one event)
737 if (!fInit) { // to prevent overwrite existing file
738 AliError(Form("Give a version name different from %s",
739 fEventFolderName.Data() )) ;
743 if (strstr(option,"print")) {
748 if(strstr(option,"tim"))
749 gBenchmark->Start("PHOSDigitizer");
751 AliRunLoader* rl = AliRunLoader::GetRunLoader(fEventFolderName) ;
752 AliPHOSLoader * phosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
754 // Post Digitizer to the white board
755 phosLoader->PostDigitizer(this) ;
757 if (fLastEvent == -1)
758 fLastEvent = rl->GetNumberOfEvents() - 1 ;
760 fLastEvent = fFirstEvent ;
762 Int_t nEvents = fLastEvent - fFirstEvent + 1;
766 for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
769 Digitize(ievent) ; //Add prepared SDigits to digits and add the noise
773 if(strstr(option,"deb"))
776 //increment the total number of Digits per run
777 fDigitsInRun += phosLoader->Digits()->GetEntriesFast() ;
780 phosLoader->CleanDigitizer();
782 if(strstr(option,"tim")){
783 gBenchmark->Stop("PHOSDigitizer");
785 message = " took %f seconds for Digitizing %f seconds per event\n" ;
786 AliInfo(Form( message.Data(),
787 gBenchmark->GetCpuTime("PHOSDigitizer"),
788 gBenchmark->GetCpuTime("PHOSDigitizer")/nEvents ));
791 //____________________________________________________________________________
792 Float_t AliPHOSDigitizer::TimeResolution(Float_t e){
793 //calculate TOF resolution using beam-test resutls
794 Float_t a=AliPHOSSimParam::GetInstance()->GetTOFa() ;
795 Float_t b=AliPHOSSimParam::GetInstance()->GetTOFb() ;
796 return TMath::Sqrt(a*a+b*b/e) ;
799 ////____________________________________________________________________________
800 //Float_t AliPHOSDigitizer::FrontEdgeTime(TClonesArray * ticks) const
802 // // Returns the shortest time among all time ticks
804 // ticks->Sort() ; //Sort in accordance with times of ticks
806 // AliPHOSTick * ctick = (AliPHOSTick *) it.Next() ;
807 // Float_t time = ctick->CrossingTime(fTimeThreshold) ;
810 // while((t=(AliPHOSTick*) it.Next())){
811 // if(t->GetTime() < time) //This tick starts before crossing
816 // time = ctick->CrossingTime(fTimeThreshold) ;
821 //____________________________________________________________________________
822 Bool_t AliPHOSDigitizer::Init()
824 // Makes all memory allocations
827 AliPHOSGeometry *geom;
828 if (!(geom = AliPHOSGeometry::GetInstance()))
829 geom = AliPHOSGeometry::GetInstance("IHEP","");
830 // const AliPHOSGeometry *geom = AliPHOSGeometry::GetInstance() ;
832 fEmcCrystals = geom->GetNModules() * geom->GetNCristalsInModule() ;
835 fLastEvent = fFirstEvent ;
837 fInput = fManager->GetNinputs() ;
841 fInputFileNames = new TString[fInput] ;
842 fEventNames = new TString[fInput] ;
843 fInputFileNames[0] = GetTitle() ;
844 fEventNames[0] = fEventFolderName.Data() ;
846 for (index = 1 ; index < fInput ; index++) {
847 fInputFileNames[index] = dynamic_cast<AliStream*>(fManager->GetInputStream(index))->GetFileName(0);
848 TString tempo = fManager->GetInputFolderName(index) ;
849 fEventNames[index] = tempo.Remove(tempo.Length()-1) ; // strip of the stream number added by fManager
852 //to prevent cleaning of this object while GetEvent is called
853 AliRunLoader* rl = AliRunLoader::GetRunLoader(fEventFolderName) ;
855 rl = AliRunLoader::Open(GetTitle(), fEventFolderName) ;
857 AliPHOSLoader * phosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
858 phosLoader->GetDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
863 //____________________________________________________________________________
864 void AliPHOSDigitizer::InitParameters()
866 // Set initial parameters Digitizer
869 SetEventRange(0,-1) ;
870 fPulse = new AliPHOSPulseGenerator();
871 fADCValuesLG = new Int_t[fPulse->GetRawFormatTimeBins()];
872 fADCValuesHG = new Int_t[fPulse->GetRawFormatTimeBins()];
876 //__________________________________________________________________
877 void AliPHOSDigitizer::Print(const Option_t *)const
879 // Print Digitizer's parameters
880 AliInfo(Form("\n------------------- %s -------------", GetName() )) ;
881 if( strcmp(fEventFolderName.Data(), "") != 0 ){
882 printf(" Writing Digits to branch with title %s\n", fEventFolderName.Data()) ;
886 nStreams = GetNInputStreams() ;
891 for (index = 0 ; index < nStreams ; index++) {
892 TString tempo(fEventNames[index]) ;
894 printf ("Adding SDigits from %s \n", fInputFileNames[index].Data()) ;
897 // printf("\nWith following parameters:\n") ;
898 // printf(" Electronics noise in EMC (fPinNoise) = %f GeV\n", fPinNoise ) ;
899 // printf(" Threshold in EMC (fEMCDigitThreshold) = %f GeV\n", fEMCDigitThreshold ) ;
900 // printf(" Noise in CPV (fCPVNoise) = %f aux units\n", fCPVNoise ) ;
901 // printf(" Threshold in CPV (fCPVDigitThreshold) = %f aux units\n",fCPVDigitThreshold ) ;
902 printf(" ---------------------------------------------------\n") ;
905 AliInfo(Form("AliPHOSDigitizer not initialized" )) ;
909 //__________________________________________________________________
910 void AliPHOSDigitizer::PrintDigits(Option_t * option)
912 // Print a table of digits
915 AliRunLoader* rl = AliRunLoader::GetRunLoader(fEventFolderName) ;
916 AliPHOSLoader * phosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
917 TClonesArray * digits = phosLoader->Digits() ;
918 const AliPHOSGeometry *geom = AliPHOSGeometry::GetInstance() ;
920 AliInfo(Form("%d", digits->GetEntriesFast())) ;
921 printf("\nevent %d", gAlice->GetEvNumber()) ;
922 printf("\n Number of entries in Digits list %d", digits->GetEntriesFast() ) ;
925 if(strstr(option,"all")||strstr(option,"EMC")){
927 AliPHOSDigit * digit;
928 printf("\nEMC digits (with primaries):\n") ;
929 printf("\n Id Amplitude Time Index Nprim: Primaries list \n") ;
930 Int_t maxEmc = geom->GetNModules()*geom->GetNCristalsInModule() ;
932 for (index = 0 ; (index < digits->GetEntriesFast()) &&
933 (dynamic_cast<AliPHOSDigit *>(digits->At(index))->GetId() <= maxEmc) ; index++) {
934 digit = (AliPHOSDigit * ) digits->At(index) ;
935 if(digit->GetNprimary() == 0)
937 // printf("%6d %8d %6.5e %4d %2d :",
938 // digit->GetId(), digit->GetAmp(), digit->GetTime(), digit->GetIndexInList(), digit->GetNprimary()) ; // YVK
939 printf("%6d %.4f %6.5e %4d %2d :",
940 digit->GetId(), digit->GetEnergy(), digit->GetTime(), digit->GetIndexInList(), digit->GetNprimary()) ;
942 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
943 printf("%d ",digit->GetPrimary(iprimary+1) ) ;
949 if(strstr(option,"all")||strstr(option,"CPV")){
951 //loop over CPV digits
952 AliPHOSDigit * digit;
953 printf("\nCPV digits (with primaries):\n") ;
954 printf("\n Id Amplitude Time Index Nprim: Primaries list \n") ;
955 Int_t maxEmc = geom->GetNModules()*geom->GetNCristalsInModule() ;
957 for (index = 0 ; index < digits->GetEntriesFast(); index++) {
958 digit = (AliPHOSDigit * ) digits->At(index) ;
959 if(digit->GetId() > maxEmc){
960 printf("%6d %8d %4d %2d :",
961 digit->GetId(), digit->GetAmp(), digit->GetIndexInList(), digit->GetNprimary()) ;
963 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
964 printf("%d ",digit->GetPrimary(iprimary+1) ) ;
973 //__________________________________________________________________
974 Float_t AliPHOSDigitizer::TimeOfNoise(void) const
975 { // Calculates the time signal generated by noise
976 //PH Info("TimeOfNoise", "Change me") ;
977 return gRandom->Rndm() * 1.28E-5;
980 //__________________________________________________________________
981 void AliPHOSDigitizer::Unload()
985 for(i = 1 ; i < fInput ; i++){
986 TString tempo(fEventNames[i]) ;
988 AliRunLoader* rl = AliRunLoader::GetRunLoader(tempo) ;
989 AliPHOSLoader * phosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
990 phosLoader->UnloadSDigits() ;
993 AliRunLoader* rl = AliRunLoader::GetRunLoader(fEventFolderName) ;
994 AliPHOSLoader * phosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
995 phosLoader->UnloadDigits() ;
998 //____________________________________________________________________________
999 void AliPHOSDigitizer::WriteDigits()
1002 // Makes TreeD in the output file.
1003 // Check if branch already exists:
1004 // if yes, exit without writing: ROOT TTree does not support overwriting/updating of
1005 // already existing branches.
1006 // else creates branch with Digits, named "PHOS", title "...",
1007 // and branch "AliPHOSDigitizer", with the same title to keep all the parameters
1008 // and names of files, from which digits are made.
1010 AliRunLoader* rl = AliRunLoader::GetRunLoader(fEventFolderName) ;
1011 AliPHOSLoader * phosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
1013 const TClonesArray * digits = phosLoader->Digits() ;
1014 TTree * treeD = phosLoader->TreeD();
1016 phosLoader->MakeTree("D");
1017 treeD = phosLoader->TreeD();
1020 // -- create Digits branch
1021 Int_t bufferSize = 32000 ;
1022 TBranch * digitsBranch = treeD->Branch("PHOS","TClonesArray",&digits,bufferSize);
1023 digitsBranch->SetTitle(fEventFolderName);
1024 digitsBranch->Fill() ;
1026 phosLoader->WriteDigits("OVERWRITE");
1027 phosLoader->WriteDigitizer("OVERWRITE");