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.98 2007/09/26 14:22:17 cvetan
22 * 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.
24 * Revision 1.97 2007/08/07 14:12:03 kharlov
25 * Quality assurance added (Yves Schutz)
27 * Revision 1.96 2007/04/28 10:43:36 policheh
28 * Dead channels simulation: digit energy sets to 0.
30 * Revision 1.95 2007/04/10 07:20:52 kharlov
31 * Decalibration should use the same CDB as calibration in AliPHOSClusterizerv1
33 * Revision 1.94 2007/02/01 10:34:47 hristov
34 * Removing warnings on Solaris x86
36 * Revision 1.93 2006/10/17 13:17:01 kharlov
37 * Replace AliInfo by AliDebug
39 * Revision 1.92 2006/08/28 10:01:56 kharlov
40 * Effective C++ warnings fixed (Timur Pocheptsov)
42 * Revision 1.91 2006/04/29 20:25:30 hristov
43 * Decalibration is implemented (Yu.Kharlov)
45 * Revision 1.90 2006/04/22 10:30:17 hristov
46 * Add fEnergy to AliPHOSDigit and operate with EMC amplitude in energy units (Yu.Kharlov)
48 * Revision 1.89 2006/04/11 15:22:59 hristov
49 * run number in query set to -1: forces AliCDBManager to use its run number (A.Colla)
51 * Revision 1.88 2006/03/13 14:05:43 kharlov
52 * Calibration objects for EMC and CPV
54 * Revision 1.87 2005/08/24 15:33:49 kharlov
55 * Calibration data for raw digits
57 * Revision 1.86 2005/07/12 20:07:35 hristov
58 * Changes needed to run simulation and reconstrruction in the same AliRoot session
60 * Revision 1.85 2005/05/28 14:19:04 schutz
61 * Compilation warnings fixed by T.P.
65 //_________________________________________________________________________
66 //*-- Author : Dmitri Peressounko (SUBATECH & Kurchatov Institute)
67 //////////////////////////////////////////////////////////////////////////////
68 // This TTask performs digitization of Summable digits (in the PHOS case it is just
69 // the sum of contributions from all primary particles into a given cell).
70 // In addition it performs mixing of summable digits from different events.
71 // The name of the TTask is also the title of the branch that will contain
72 // the created SDigits
73 // The title of the TTAsk is the name of the file that contains the hits from
74 // which the SDigits are created
76 // For each event two branches are created in TreeD:
77 // "PHOS" - list of digits
78 // "AliPHOSDigitizer" - AliPHOSDigitizer with all parameters used in digitization
80 // Note, that one can set a title for new digits branch, and repeat digitization with
81 // another set of parameters.
84 // root[0] AliPHOSDigitizer * d = new AliPHOSDigitizer() ;
85 // root[1] d->ExecuteTask()
86 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
87 // //Digitizes SDigitis in all events found in file galice.root
89 // root[2] AliPHOSDigitizer * d1 = new AliPHOSDigitizer("galice1.root") ;
90 // // Will read sdigits from galice1.root
91 // root[3] d1->MixWith("galice2.root")
92 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
93 // // Reads another set of sdigits from galice2.root
94 // root[3] d1->MixWith("galice3.root")
95 // // Reads another set of sdigits from galice3.root
96 // root[4] d->ExecuteTask("deb timing")
97 // // Reads SDigits from files galice1.root, galice2.root ....
98 // // mixes them and stores produced Digits in file galice1.root
99 // // deb - prints number of produced digits
100 // // deb all - prints list of produced digits
101 // // timing - prints time used for digitization
104 // --- ROOT system ---
107 #include "TBenchmark.h"
110 // --- Standard library ---
112 // --- AliRoot header files ---
114 #include "AliRunDigitizer.h"
115 #include "AliPHOSDigit.h"
116 #include "AliPHOSGetter.h"
117 #include "AliPHOSDigitizer.h"
118 #include "AliPHOSSDigitizer.h"
119 #include "AliPHOSGeometry.h"
120 #include "AliPHOSTick.h"
121 #include "AliPHOSQualAssDataMaker.h"
123 ClassImp(AliPHOSDigitizer)
126 //____________________________________________________________________________
127 AliPHOSDigitizer::AliPHOSDigitizer() :
133 fInputFileNames(0x0),
137 fEMCDigitThreshold(0.f),
139 fCPVDigitThreshold(0.f),
140 fTimeResolution(0.f),
142 fTimeSignalLength(0.f),
144 fADCpedestalEmc(0.f),
147 fADCpedestalCpv(0.f),
149 fEventFolderName(""),
157 fManager = 0 ; // We work in the standalong mode
160 //____________________________________________________________________________
161 AliPHOSDigitizer::AliPHOSDigitizer(TString alirunFileName,
162 TString eventFolderName):
163 AliDigitizer("PHOS"+AliConfig::Instance()->GetDigitizerTaskName(), alirunFileName),
164 fDefaultInit(kFALSE),
168 fInputFileNames(0x0),
172 fEMCDigitThreshold(0.f),
174 fCPVDigitThreshold(0.f),
175 fTimeResolution(0.f),
177 fTimeSignalLength(0.f),
179 fADCpedestalEmc(0.f),
182 fADCpedestalCpv(0.f),
184 fEventFolderName(eventFolderName),
193 fDefaultInit = kFALSE ;
194 fManager = 0 ; // We work in the standalong mode
195 //Initialize the quality assurance data maker only once
196 fQADM = new AliPHOSQualAssDataMaker() ;
197 //FIXME: get the run number
200 GetQualAssDataMaker()->Init(AliQualAss::kDIGITS, run, fgkCycles) ;
201 GetQualAssDataMaker()->StartOfCycle(AliQualAss::kDIGITS) ;
204 //____________________________________________________________________________
205 AliPHOSDigitizer::AliPHOSDigitizer(const AliPHOSDigitizer & d) :
207 fDefaultInit(d.fDefaultInit),
208 fDigitsInRun(d.fDigitsInRun),
211 fInputFileNames(0x0),//?
213 fEmcCrystals(d.fEmcCrystals),
214 fPinNoise(d.fPinNoise),
215 fEMCDigitThreshold(d.fEMCDigitThreshold),
216 fCPVNoise(d.fCPVNoise),
217 fCPVDigitThreshold(d.fCPVDigitThreshold),
218 fTimeResolution(d.fTimeResolution),
219 fTimeThreshold(d.fTimeThreshold),
220 fTimeSignalLength(d.fTimeSignalLength),
221 fADCchanelEmc(d.fADCchanelEmc),
222 fADCpedestalEmc(d.fADCpedestalEmc),
223 fNADCemc(d.fNADCemc),
224 fADCchanelCpv(d.fADCchanelCpv),
225 fADCpedestalCpv(d.fADCpedestalCpv),
226 fNADCcpv(d.fNADCcpv),
227 fEventFolderName(d.fEventFolderName),
228 fFirstEvent(d.fFirstEvent),
229 fLastEvent(d.fLastEvent),
235 SetName(d.GetName()) ;
236 SetTitle(d.GetTitle()) ;
237 //Initialize the quality assurance data maker only once
238 //FIXME: get the run number
241 GetQualAssDataMaker()->Init(AliQualAss::kDIGITS, run, fgkCycles) ;
242 GetQualAssDataMaker()->StartOfCycle(AliQualAss::kDIGITS) ;
245 //____________________________________________________________________________
246 AliPHOSDigitizer::AliPHOSDigitizer(AliRunDigitizer * rd) :
247 AliDigitizer(rd,"PHOS"+AliConfig::Instance()->GetDigitizerTaskName()),
248 fDefaultInit(kFALSE),
252 fInputFileNames(0x0),
256 fEMCDigitThreshold(0.f),
258 fCPVDigitThreshold(0.f),
259 fTimeResolution(0.f),
261 fTimeSignalLength(0.f),
263 fADCpedestalEmc(0.f),
266 fADCpedestalCpv(0.f),
268 fEventFolderName(fManager->GetInputFolderName(0)),
275 // ctor Init() is called by RunDigitizer
277 SetTitle(dynamic_cast<AliStream*>(fManager->GetInputStream(0))->GetFileName(0));
279 fDefaultInit = kFALSE ;
280 //Initialize the quality assurance data maker only once
281 fQADM = new AliPHOSQualAssDataMaker() ;
282 //FIXME: get the run number
285 GetQualAssDataMaker()->Init(AliQualAss::kDIGITS, run) ;
286 GetQualAssDataMaker()->StartOfCycle(AliQualAss::kDIGITS) ;
289 //____________________________________________________________________________
290 AliPHOSDigitizer::~AliPHOSDigitizer()
292 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle()) ;
294 // Clean Digitizer from the white board
295 gime->PhosLoader()->CleanDigitizer() ;
297 delete [] fInputFileNames ;
298 delete [] fEventNames ;
304 //____________________________________________________________________________
305 void AliPHOSDigitizer::Digitize(Int_t event)
308 // Makes the digitization of the collected summable digits.
309 // It first creates the array of all PHOS modules
310 // filled with noise (different for EMC, and CPV) and
311 // then adds contributions from SDigits.
312 // This design avoids scanning over the list of digits to add
313 // contribution to new SDigits only.
315 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle()) ;
316 Int_t ReadEvent = event ;
318 ReadEvent = dynamic_cast<AliStream*>(fManager->GetInputStream(0))->GetCurrentEventNumber() ;
319 AliDebug(1,Form("Adding event %d from input stream 0 %s %s",
320 ReadEvent, GetTitle(), fEventFolderName.Data())) ;
321 gime->Event(ReadEvent, "S") ;
322 TClonesArray * digits = gime->Digits() ;
325 const AliPHOSGeometry *geom = gime->PHOSGeometry() ;
326 //Making digits with noise, first EMC
327 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
332 nCPV = nEMC + geom->GetNumberOfCPVPadsZ() * geom->GetNumberOfCPVPadsPhi() * geom->GetNModules() ;
334 digits->Expand(nCPV) ;
336 // get first the sdigitizer from the tasks list
337 if ( !gime->SDigitizer() )
338 gime->LoadSDigitizer();
339 AliPHOSSDigitizer * sDigitizer = gime->SDigitizer();
342 AliFatal(Form("SDigitizer with name %s %s not found",
343 GetTitle(), fEventFolderName.Data() )) ;
345 //take all the inputs to add together and load the SDigits
346 TObjArray * sdigArray = new TObjArray(fInput) ;
347 sdigArray->AddAt(gime->SDigits(), 0) ;
349 for(i = 1 ; i < fInput ; i++){
350 TString tempo(fEventNames[i]) ;
352 AliPHOSGetter * gime1 = AliPHOSGetter::Instance(fInputFileNames[i], tempo) ;
354 ReadEvent = dynamic_cast<AliStream*>(fManager->GetInputStream(i))->GetCurrentEventNumber() ;
355 AliInfo(Form("Adding event %d from input stream %d %s %s",
356 ReadEvent, i, fInputFileNames[i].Data(), tempo.Data())) ;
357 gime1->Event(ReadEvent,"S");
358 sdigArray->AddAt(gime1->SDigits(), i) ;
361 //Find the first crystal with signal
362 Int_t nextSig = 200000 ;
363 TClonesArray * sdigits ;
364 for(i = 0 ; i < fInput ; i++){
365 sdigits = dynamic_cast<TClonesArray *>(sdigArray->At(i)) ;
366 if ( !sdigits->GetEntriesFast() )
368 Int_t curNext = dynamic_cast<AliPHOSDigit *>(sdigits->At(0))->GetId() ;
369 if(curNext < nextSig)
373 TArrayI index(fInput) ;
374 index.Reset() ; //Set all indexes to zero
376 AliPHOSDigit * digit ;
377 AliPHOSDigit * curSDigit ;
379 TClonesArray * ticks = new TClonesArray("AliPHOSTick",1000) ;
381 //Put Noise contribution
382 for(absID = 1 ; absID <= nEMC ; absID++){
383 Float_t noise = gRandom->Gaus(0., fPinNoise) ;
384 // YVK: do not digitize amplitudes for EMC
385 // new((*digits)[absID-1]) AliPHOSDigit( -1, absID, sDigitizer->Digitize(noise), TimeOfNoise() ) ;
386 new((*digits)[absID-1]) AliPHOSDigit( -1, absID, noise, TimeOfNoise() ) ;
387 //look if we have to add signal?
388 digit = dynamic_cast<AliPHOSDigit *>(digits->At(absID-1)) ;
391 //Add SDigits from all inputs
394 Float_t a = digit->GetEnergy() ;
395 Float_t b = TMath::Abs( a / fTimeSignalLength) ;
396 //Mark the beginning of the signal
397 new((*ticks)[contrib++]) AliPHOSTick(digit->GetTime(),0, b);
398 //Mark the end of the signal
399 new((*ticks)[contrib++]) AliPHOSTick(digit->GetTime()+fTimeSignalLength, -a, -b);
402 for(i = 0 ; i < fInput ; i++){
403 if( dynamic_cast<TClonesArray *>(sdigArray->At(i))->GetEntriesFast() > index[i] )
404 curSDigit = dynamic_cast<AliPHOSDigit*>(dynamic_cast<TClonesArray *>(sdigArray->At(i))->At(index[i])) ;
407 //May be several digits will contribute from the same input
408 while(curSDigit && curSDigit->GetId() == absID){
409 //Shift primary to separate primaries belonging different inputs
410 Int_t primaryoffset ;
412 primaryoffset = fManager->GetMask(i) ;
414 primaryoffset = 10000000*i ;
415 curSDigit->ShiftPrimary(primaryoffset) ;
417 a = curSDigit->GetEnergy() ;
418 b = a /fTimeSignalLength ;
419 new((*ticks)[contrib++]) AliPHOSTick(curSDigit->GetTime(),0, b);
420 new((*ticks)[contrib++]) AliPHOSTick(curSDigit->GetTime()+fTimeSignalLength, -a, -b);
422 *digit += *curSDigit ; //add energies
425 if( dynamic_cast<TClonesArray *>(sdigArray->At(i))->GetEntriesFast() > index[i] )
426 curSDigit = dynamic_cast<AliPHOSDigit*>(dynamic_cast<TClonesArray *>(sdigArray->At(i))->At(index[i])) ;
432 //calculate and set time
433 Float_t time = FrontEdgeTime(ticks) ;
434 digit->SetTime(time) ;
436 //Find next signal module
438 for(i = 0 ; i < fInput ; i++){
439 sdigits = dynamic_cast<TClonesArray *>(sdigArray->At(i)) ;
440 Int_t curNext = nextSig ;
441 if(sdigits->GetEntriesFast() > index[i] ){
442 curNext = dynamic_cast<AliPHOSDigit *>(sdigits->At(index[i]))->GetId() ;
444 if(curNext < nextSig) nextSig = curNext ;
452 //Now CPV digits (different noise and no timing)
453 for(absID = nEMC+1; absID <= nCPV; absID++){
454 Float_t noise = gRandom->Gaus(0., fCPVNoise) ;
455 new((*digits)[absID-1]) AliPHOSDigit( -1,absID,sDigitizer->Digitize(noise), TimeOfNoise() ) ;
456 //look if we have to add signal?
458 digit = dynamic_cast<AliPHOSDigit *>(digits->At(absID-1)) ;
459 //Add SDigits from all inputs
460 for(i = 0 ; i < fInput ; i++){
461 if( dynamic_cast<TClonesArray *>(sdigArray->At(i))->GetEntriesFast() > index[i] )
462 curSDigit = dynamic_cast<AliPHOSDigit*>( dynamic_cast<TClonesArray *>(sdigArray->At(i))->At(index[i])) ;
466 //May be several digits will contribute from the same input
467 while(curSDigit && curSDigit->GetId() == absID){
468 //Shift primary to separate primaries belonging different inputs
469 Int_t primaryoffset ;
471 primaryoffset = fManager->GetMask(i) ;
473 primaryoffset = 10000000*i ;
474 curSDigit->ShiftPrimary(primaryoffset) ;
477 *digit += *curSDigit ;
479 if( dynamic_cast<TClonesArray *>(sdigArray->At(i))->GetEntriesFast() > index[i] )
480 curSDigit = dynamic_cast<AliPHOSDigit*>( dynamic_cast<TClonesArray *>(sdigArray->At(i))->At(index[i]) ) ;
486 //Find next signal module
488 for(i = 0 ; i < fInput ; i++){
489 sdigits = dynamic_cast<TClonesArray *>(sdigArray->At(i)) ;
490 Int_t curNext = nextSig ;
491 if(sdigits->GetEntriesFast() > index[i] )
492 curNext = dynamic_cast<AliPHOSDigit *>( sdigits->At(index[i]) )->GetId() ;
493 if(curNext < nextSig) nextSig = curNext ;
499 delete sdigArray ; //We should not delete its contents
501 //remove digits below thresholds
502 for(i = 0 ; i < nEMC ; i++){
503 digit = dynamic_cast<AliPHOSDigit*>( digits->At(i) ) ;
504 DecalibrateEMC(digit);
505 if(digit->GetEnergy() < fEMCDigitThreshold)
506 digits->RemoveAt(i) ;
508 digit->SetTime(gRandom->Gaus(digit->GetTime(),fTimeResolution) ) ;
512 for(i = nEMC; i < nCPV ; i++)
513 // if( sDigitizer->Calibrate( dynamic_cast<AliPHOSDigit*>(digits->At(i))->GetAmp() ) < fCPVDigitThreshold )
514 if( dynamic_cast<AliPHOSDigit*>(digits->At(i))->GetEnergy() < fCPVDigitThreshold )
515 digits->RemoveAt(i) ;
519 Int_t ndigits = digits->GetEntriesFast() ;
520 digits->Expand(ndigits) ;
522 //Set indexes in list of digits and make true digitization of the energy
523 for (i = 0 ; i < ndigits ; i++) {
524 digit = dynamic_cast<AliPHOSDigit*>( digits->At(i) ) ;
525 digit->SetIndexInList(i) ;
526 if(digit->GetId() > fEmcCrystals){ //digitize CPV only
527 digit->SetAmp(DigitizeCPV(digit->GetEnergy(),digit->GetId()) ) ;
533 //set amplitudes in bad channels to zero
534 for(i = 0 ; i <digits->GetEntries(); i++){
535 digit = dynamic_cast<AliPHOSDigit*>( digits->At(i) ) ;
536 gime->PHOSGeometry()->AbsToRelNumbering(digit->GetId(),relId);
537 if(relId[1] == 0) // Emc
538 if(gime->CalibData()->IsBadChannelEmc(relId[0],relId[3],relId[2])) digit->SetEnergy(0.);
543 //____________________________________________________________________________
544 void AliPHOSDigitizer::DecalibrateEMC(AliPHOSDigit *digit)
546 // Decalibrate EMC digit, i.e. change its energy by a factor read from CDB
548 AliPHOSGetter* gime = AliPHOSGetter::Instance();
550 if(!gime->CalibData()) {
551 AliPHOSCalibData* cdb = new AliPHOSCalibData(-1);
552 gime->SetCalibData(cdb);
555 //Determine rel.position of the cell absolute ID
557 gime->PHOSGeometry()->AbsToRelNumbering(digit->GetId(),relId);
558 Int_t module=relId[0];
560 Int_t column=relId[3];
561 Float_t decalibration = gime->CalibData()->GetADCchannelEmc(module,column,row);
562 Float_t energy = digit->GetEnergy() / decalibration;
563 digit->SetEnergy(energy);
565 //____________________________________________________________________________
566 Int_t AliPHOSDigitizer::DigitizeCPV(Float_t charge, Int_t absId)
568 // Returns digitized value of the CPV charge in a pad absId
570 AliPHOSGetter* gime = AliPHOSGetter::Instance();
572 if(!gime->CalibData()) {
573 AliPHOSCalibData* cdb = new AliPHOSCalibData(-1); // use AliCDBManager's run number
574 gime->SetCalibData(cdb);
577 //Determine rel.position of the cell absId
579 gime->PHOSGeometry()->AbsToRelNumbering(absId,relId);
580 Int_t module=relId[0];
582 Int_t column=relId[3];
586 if(absId > fEmcCrystals){ //digitize CPV only
588 //reading calibration data for cell absId.
589 //If no calibration DB found, accept default values.
591 if(gime->CalibData()) {
592 fADCpedestalCpv = gime->CalibData()->GetADCpedestalCpv(module,column,row);
593 fADCchanelCpv = gime->CalibData()->GetADCchannelCpv( module,column,row);
596 channel = (Int_t) TMath::Ceil((charge - fADCpedestalCpv)/fADCchanelCpv) ;
597 if(channel > fNADCcpv ) channel = fNADCcpv ;
602 //____________________________________________________________________________
603 void AliPHOSDigitizer::Exec(Option_t *option)
605 // Steering method to process digitization for events
606 // in the range from fFirstEvent to fLastEvent.
607 // This range is optionally set by SetEventRange().
608 // if fLastEvent=-1, then process events until the end.
609 // by default fLastEvent = fFirstEvent (process only one event)
611 if (!fInit) { // to prevent overwrite existing file
612 AliError(Form("Give a version name different from %s",
613 fEventFolderName.Data() )) ;
617 if (strstr(option,"print")) {
622 if(strstr(option,"tim"))
623 gBenchmark->Start("PHOSDigitizer");
625 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle()) ;
627 // Post Digitizer to the white board
628 gime->PostDigitizer(this) ;
630 if (fLastEvent == -1)
631 fLastEvent = gime->MaxEvent() - 1 ;
633 fLastEvent = fFirstEvent ;
635 Int_t nEvents = fLastEvent - fFirstEvent + 1;
639 for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
641 gime->Event(ievent,"S") ;
643 Digitize(ievent) ; //Add prepared SDigits to digits and add the noise
645 //makes the quality assurance data
646 if (GetQualAssDataMaker()->IsCycleDone() ) {
647 GetQualAssDataMaker()->EndOfCycle(AliQualAss::kDIGITS) ;
648 GetQualAssDataMaker()->StartOfCycle(AliQualAss::kDIGITS) ;
650 GetQualAssDataMaker()->Exec(AliQualAss::kDIGITS, gime->Digits()) ;
651 GetQualAssDataMaker()->Increment() ;
655 if(strstr(option,"deb"))
658 //increment the total number of Digits per run
659 fDigitsInRun += gime->Digits()->GetEntriesFast() ;
662 //Write the quality assurance data only after the last event
663 if ( fEventCounter == gime->MaxEvent() ) {
664 GetQualAssDataMaker()->EndOfCycle(AliQualAss::kDIGITS) ;
665 GetQualAssDataMaker()->Finish(AliQualAss::kDIGITS) ;
668 gime->PhosLoader()->CleanDigitizer();
670 if(strstr(option,"tim")){
671 gBenchmark->Stop("PHOSDigitizer");
673 message = " took %f seconds for Digitizing %f seconds per event\n" ;
674 AliInfo(Form( message.Data(),
675 gBenchmark->GetCpuTime("PHOSDigitizer"),
676 gBenchmark->GetCpuTime("PHOSDigitizer")/nEvents ));
680 //____________________________________________________________________________
681 Float_t AliPHOSDigitizer::FrontEdgeTime(TClonesArray * ticks) const
683 // Returns the shortest time among all time ticks
685 ticks->Sort() ; //Sort in accordance with times of ticks
687 AliPHOSTick * ctick = (AliPHOSTick *) it.Next() ;
688 Float_t time = ctick->CrossingTime(fTimeThreshold) ;
691 while((t=(AliPHOSTick*) it.Next())){
692 if(t->GetTime() < time) //This tick starts before crossing
697 time = ctick->CrossingTime(fTimeThreshold) ;
702 //____________________________________________________________________________
703 Bool_t AliPHOSDigitizer::Init()
705 // Makes all memory allocations
707 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName) ;
709 AliFatal(Form("Could not obtain the Getter object for file %s and event %s !",
710 GetTitle(), fEventFolderName.Data()));
714 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
716 fEmcCrystals = geom->GetNModules() * geom->GetNCristalsInModule() ;
718 TString opt("Digits") ;
719 if(gime->VersionExists(opt) ) {
720 AliError(Form("Give a version name different from %s",
721 fEventFolderName.Data() )) ;
726 fLastEvent = fFirstEvent ;
728 fInput = fManager->GetNinputs() ;
732 fInputFileNames = new TString[fInput] ;
733 fEventNames = new TString[fInput] ;
734 fInputFileNames[0] = GetTitle() ;
735 fEventNames[0] = fEventFolderName.Data() ;
737 for (index = 1 ; index < fInput ; index++) {
738 fInputFileNames[index] = dynamic_cast<AliStream*>(fManager->GetInputStream(index))->GetFileName(0);
739 TString tempo = fManager->GetInputFolderName(index) ;
740 fEventNames[index] = tempo.Remove(tempo.Length()-1) ; // strip of the stream number added by fManager
743 //to prevent cleaning of this object while GetEvent is called
744 gime->PhosLoader()->GetDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
749 //____________________________________________________________________________
750 void AliPHOSDigitizer::InitParameters()
752 // Set initial parameters Digitizer
754 fPinNoise = 0.004 ; // [GeV]
755 fEMCDigitThreshold = 0.012 ; // [GeV]
756 fCPVNoise = 0.01; // [aux units]
757 fCPVDigitThreshold = 0.09 ; // [aux units]
758 fTimeResolution = 0.5e-9 ; // [sec]
759 fTimeSignalLength = 1.0e-9 ; // [sec]
761 fADCchanelEmc = 1.0; // Coefficient between real and measured energies in EMC
762 fADCpedestalEmc = 0. ; //
763 fNADCemc = (Int_t) TMath::Power(2,16) ; // number of channels in EMC ADC
765 fADCchanelCpv = 0.0012 ; // width of one ADC channel in CPV 'popugais'
766 fADCpedestalCpv = 0.012 ; //
767 fNADCcpv = (Int_t) TMath::Power(2,12); // number of channels in CPV ADC
769 // fTimeThreshold = 0.001*10000000 ; //Means 1 MeV in terms of SDigits amplitude
770 fTimeThreshold = 0.001 ; // [GeV]
771 SetEventRange(0,-1) ;
775 //__________________________________________________________________
776 void AliPHOSDigitizer::MixWith(TString alirunFileName, TString eventFolderName)
778 // Allows to produce digits by superimposing background and signal event.
779 // It is assumed, that headers file with SIGNAL events is opened in
781 // Sets the BACKGROUND event, with which the SIGNAL event is to be mixed
782 // Thus we avoid writing (changing) huge and expensive
783 // backgound files: all output will be writen into SIGNAL, i.e.
784 // opened in constructor file.
786 // One can open as many files to mix with as one needs.
787 // However only Sdigits with the same name (i.e. constructed with the same SDigitizer)
790 if( strcmp(fEventFolderName, "") == 0 )
794 Warning("MixWith", "Cannot use this method with AliRunDigitizer\n" ) ;
797 // looking for file which contains AliRun
798 if (gSystem->AccessPathName(alirunFileName)) {// file does not exist
799 AliError(Form("File %s does not exist!", alirunFileName.Data())) ;
802 // looking for the file which contains SDigits
803 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
804 TString fileName( gime->GetSDigitsFileName() ) ;
805 if ( eventFolderName != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
806 fileName = fileName.ReplaceAll(".root", "") + "_" + eventFolderName + ".root" ;
807 if ( (gSystem->AccessPathName(fileName)) ) {
808 AliError(Form("The file %s does not exist!", fileName.Data())) ;
811 // need to increase the arrays
812 TString tempo = fInputFileNames[fInput-1] ;
813 delete [] fInputFileNames ;
814 fInputFileNames = new TString[fInput+1] ;
815 fInputFileNames[fInput-1] = tempo ;
817 tempo = fEventNames[fInput-1] ;
818 delete [] fEventNames ;
819 fEventNames = new TString[fInput+1] ;
820 fEventNames[fInput-1] = tempo ;
822 fInputFileNames[fInput] = alirunFileName ;
823 fEventNames[fInput] = eventFolderName ;
827 //__________________________________________________________________
828 void AliPHOSDigitizer::Print(const Option_t *)const
830 // Print Digitizer's parameters
831 AliInfo(Form("\n------------------- %s -------------", GetName() )) ;
832 if( strcmp(fEventFolderName.Data(), "") != 0 ){
833 printf(" Writing Digits to branch with title %s\n", fEventFolderName.Data()) ;
837 nStreams = GetNInputStreams() ;
842 for (index = 0 ; index < nStreams ; index++) {
843 TString tempo(fEventNames[index]) ;
845 AliPHOSGetter * gime = AliPHOSGetter::Instance(fInputFileNames[index], tempo) ;
846 TString fileName( gime->GetSDigitsFileName() ) ;
847 if ( fEventNames[index] != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
848 fileName = fileName.ReplaceAll(".root", "") + "_" + fEventNames[index] + ".root" ;
849 printf ("Adding SDigits from %s %s\n", fInputFileNames[index].Data(), fileName.Data()) ;
851 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName) ;
852 printf("\nWriting digits to %s", gime->GetDigitsFileName().Data()) ;
854 printf("\nWith following parameters:\n") ;
855 printf(" Electronics noise in EMC (fPinNoise) = %f GeV\n", fPinNoise ) ;
856 printf(" Threshold in EMC (fEMCDigitThreshold) = %f GeV\n", fEMCDigitThreshold ) ;
857 printf(" Noise in CPV (fCPVNoise) = %f aux units\n", fCPVNoise ) ;
858 printf(" Threshold in CPV (fCPVDigitThreshold) = %f aux units\n",fCPVDigitThreshold ) ;
859 printf(" ---------------------------------------------------\n") ;
862 AliInfo(Form("AliPHOSDigitizer not initialized" )) ;
866 //__________________________________________________________________
867 void AliPHOSDigitizer::PrintDigits(Option_t * option)
869 // Print a table of digits
871 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName) ;
872 TClonesArray * digits = gime->Digits() ;
874 AliInfo(Form("%d", digits->GetEntriesFast())) ;
875 printf("\nevent %d", gAlice->GetEvNumber()) ;
876 printf("\n Number of entries in Digits list %d", digits->GetEntriesFast() ) ;
879 if(strstr(option,"all")||strstr(option,"EMC")){
881 AliPHOSDigit * digit;
882 printf("\nEMC digits (with primaries):\n") ;
883 printf("\n Id Amplitude Time Index Nprim: Primaries list \n") ;
884 Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
886 for (index = 0 ; (index < digits->GetEntriesFast()) &&
887 (dynamic_cast<AliPHOSDigit *>(digits->At(index))->GetId() <= maxEmc) ; index++) {
888 digit = (AliPHOSDigit * ) digits->At(index) ;
889 if(digit->GetNprimary() == 0)
891 // printf("%6d %8d %6.5e %4d %2d :",
892 // digit->GetId(), digit->GetAmp(), digit->GetTime(), digit->GetIndexInList(), digit->GetNprimary()) ; // YVK
893 printf("%6d %.4f %6.5e %4d %2d :",
894 digit->GetId(), digit->GetEnergy(), digit->GetTime(), digit->GetIndexInList(), digit->GetNprimary()) ;
896 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
897 printf("%d ",digit->GetPrimary(iprimary+1) ) ;
903 if(strstr(option,"all")||strstr(option,"CPV")){
905 //loop over CPV digits
906 AliPHOSDigit * digit;
907 printf("\nCPV digits (with primaries):\n") ;
908 printf("\n Id Amplitude Time Index Nprim: Primaries list \n") ;
909 Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
911 for (index = 0 ; index < digits->GetEntriesFast(); index++) {
912 digit = (AliPHOSDigit * ) digits->At(index) ;
913 if(digit->GetId() > maxEmc){
914 printf("%6d %8d %4d %2d :",
915 digit->GetId(), digit->GetAmp(), digit->GetIndexInList(), digit->GetNprimary()) ;
917 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
918 printf("%d ",digit->GetPrimary(iprimary+1) ) ;
927 //__________________________________________________________________
928 Float_t AliPHOSDigitizer::TimeOfNoise(void) const
929 { // Calculates the time signal generated by noise
930 //PH Info("TimeOfNoise", "Change me") ;
931 return gRandom->Rndm() * 1.28E-5;
934 //__________________________________________________________________
935 void AliPHOSDigitizer::Unload()
939 for(i = 1 ; i < fInput ; i++){
940 TString tempo(fEventNames[i]) ;
942 AliPHOSGetter * gime = AliPHOSGetter::Instance(fInputFileNames[i], tempo) ;
943 gime->PhosLoader()->UnloadSDigits() ;
946 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName) ;
947 gime->PhosLoader()->UnloadDigits() ;
950 //____________________________________________________________________________
951 void AliPHOSDigitizer::WriteDigits()
954 // Makes TreeD in the output file.
955 // Check if branch already exists:
956 // if yes, exit without writing: ROOT TTree does not support overwriting/updating of
957 // already existing branches.
958 // else creates branch with Digits, named "PHOS", title "...",
959 // and branch "AliPHOSDigitizer", with the same title to keep all the parameters
960 // and names of files, from which digits are made.
962 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle()) ;
963 const TClonesArray * digits = gime->Digits() ;
964 TTree * treeD = gime->TreeD();
966 // -- create Digits branch
967 Int_t bufferSize = 32000 ;
968 TBranch * digitsBranch = treeD->Branch("PHOS","TClonesArray",&digits,bufferSize);
969 digitsBranch->SetTitle(fEventFolderName);
970 digitsBranch->Fill() ;
972 gime->WriteDigits("OVERWRITE");
973 gime->WriteDigitizer("OVERWRITE");