Adapted to PHOS classes using the Getter
authorschutz <schutz@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 16 Jan 2002 04:07:35 +0000 (04:07 +0000)
committerschutz <schutz@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 16 Jan 2002 04:07:35 +0000 (04:07 +0000)
EMCAL/AliEMCALDigit.cxx
EMCAL/AliEMCALDigit.h
EMCAL/AliEMCALDigitizer.cxx
EMCAL/AliEMCALDigitizer.h
EMCAL/AliEMCALSDigitizer.cxx
EMCAL/AliEMCALSDigitizer.h

index b2b890b47f416ba30c65dd54c97a0ac425e5e75f..fbed5e9ab9e8b1b78a966c82835a7dd5607dc7af 100644 (file)
@@ -24,8 +24,7 @@
 //
 //*-- Author: Sahal Yacoob (LBL)
 // based on : AliPHOSDigit
-//__________________________________________________________________________ 
-
+//__________________________________________________________________________
 
 // --- ROOT system ---
 
@@ -36,6 +35,7 @@
 // --- AliRoot header files ---
 
 #include "AliEMCALDigit.h"
+#include "AliEMCALGeometry.h"
 
 
 ClassImp(AliEMCALDigit)
@@ -53,13 +53,14 @@ ClassImp(AliEMCALDigit)
 }
 
 //____________________________________________________________________________
-AliEMCALDigit::AliEMCALDigit(Int_t primary, Int_t iparent, Int_t id, Int_t DigEnergy, Int_t index) 
+AliEMCALDigit::AliEMCALDigit(Int_t primary, Int_t iparent, Int_t id, Int_t DigEnergy, Float_t time, Int_t index) 
 {  
   // ctor with all data 
 
   fNMaxPrimary = 21 ; 
   fNMaxiparent = fNMaxPrimary*10;
   fAmp         = DigEnergy ;
+  fTime        = time ;
   fId          = id ;
   fIndexInList = index ; 
   if( primary != -1){
@@ -99,6 +100,7 @@ AliEMCALDigit::AliEMCALDigit(const AliEMCALDigit & digit)
   for (j = 0; j< fNMaxiparent ; j++)
   fIparent[j]  = digit.fIparent[j] ;
   fAmp         = digit.fAmp ;
+  fTime        = digit.fTime ;
   fId          = digit.fId;
   fIndexInList = digit.fIndexInList ; 
   fNprimary    = digit.fNprimary ;
@@ -135,12 +137,28 @@ Int_t AliEMCALDigit::Compare(const TObject * obj) const
 
 }
 
+//____________________________________________________________________________
+const Float_t AliEMCALDigit::GetEta() const
+{
+  Float_t eta=-10., phi=-10.;
+  AliEMCALGeometry::GetInstance()->EtaPhiFromIndex(fId,eta,phi);
+  return eta ;
+}
+
+//____________________________________________________________________________
+const Float_t AliEMCALDigit::GetPhi() const
+{
+  Float_t eta=-10., phi=-10.;
+  AliEMCALGeometry::GetInstance()->EtaPhiFromIndex(fId,eta,phi);
+  return phi ;
+}
+
 //____________________________________________________________________________
 Int_t AliEMCALDigit::GetPrimary(Int_t index) const
 {
   // retrieves the primary particle number given its index in the list 
   Int_t rv = -1 ;
-  if ( index <= fNprimary ){
+  if ( index <= fNprimary && index > 0){
     rv = fPrimary[index-1] ;
   } 
 
@@ -189,6 +207,8 @@ AliEMCALDigit& AliEMCALDigit::operator+(AliEMCALDigit const & digit)
   // if amplitude is larger than 
   
   fAmp += digit.fAmp ;
+  if(fTime > digit.fTime)
+    fTime = digit.fTime ;
   
   Int_t max1 = fNprimary ; 
   Int_t max2 = fNiparent ;  
@@ -235,7 +255,7 @@ ostream& operator << ( ostream& out , const AliEMCALDigit & digit)
 {
   // Prints the data of the digit
   
-  out << "ID " << digit.fId << " Energy = " << digit.fAmp << endl ; 
+  out << "ID " << digit.fId << " Energy = " << digit.fAmp <<  " Time = " << digit.fTime << endl ; 
   Int_t i,j ;
   for(i=0;i<digit.fNprimary;i++)
     out << "Primary " << i+1 << " = " << digit.fPrimary[i] << endl ;
index f7c58b9876134e16edcc0fb1dcec881744ae1716..f46d0ac80ff84b1727cfca06f061dbd674335b6d 100644 (file)
@@ -22,7 +22,6 @@
 // --- Standard library ---
 
 // --- AliRoot header files ---
-
 #include "AliDigitNew.h"
 
 class AliEMCALDigit : public AliDigitNew {
@@ -32,7 +31,7 @@ class AliEMCALDigit : public AliDigitNew {
  public:
   
   AliEMCALDigit() ;
-  AliEMCALDigit(Int_t primary, Int_t iparent, Int_t id, Int_t DigEnergy, Int_t index = -1) ;
+  AliEMCALDigit(Int_t primary, Int_t iparent, Int_t id, Int_t DigEnergy, Float_t Time, Int_t index = -1) ;
   AliEMCALDigit(const AliEMCALDigit & digit) ;
   virtual ~AliEMCALDigit() ;
 
@@ -40,20 +39,25 @@ class AliEMCALDigit : public AliDigitNew {
   AliEMCALDigit& operator+(AliEMCALDigit const &rValue) ;
     
   Int_t   Compare(const TObject * obj) const ;  
+  const Float_t GetEta() const ; 
   Int_t   GetNprimary() const { 
     // returns the number of primaries
     return fNprimary ; }
   Int_t   GetPrimary(Int_t index) const ; 
   Int_t   GetNiparent() const {return fNiparent;}
   Int_t   GetIparent(Int_t index) const ;
+  const Float_t GetPhi() const;
+  Float_t GetTime(void) const {return fTime ;}
+
   Bool_t  IsSortable() const { 
     // says that AliEMCALDigits are sortable (needed for Sort method
     return kTRUE ; }
   void    SetAmp(Int_t Amp) { 
     // sets the amplitude data member 
     fAmp= Amp ; } 
+  void SetTime(Float_t Time) {fTime = Time ;}
   void ShiftPrimary(Int_t shift); // shift to semarate different TreeK in merging
-  
  private:
 
   Int_t fNprimary ;     // Number of primaries
@@ -62,8 +66,9 @@ class AliEMCALDigit : public AliDigitNew {
     
   Int_t fNiparent ;     // Number of initial parents 
   Int_t fNMaxiparent ;  //! Max Number of parents 
-  Int_t fIparent[50] ;   // Array of parents       
-    
+  Int_t fIparent[50] ;  // Array of parents       
+  Float_t fTime ;       // Calculated time  
+
   ClassDef(AliEMCALDigit,1)   // Digit in EMCAL 
 
 } ;
index 21dd58d9d8ebeed28849b9fa0f05a1082b0882b6..29b670c55b1f453a9cc0061da9961257cc02e14a 100644 (file)
@@ -51,7 +51,7 @@
 ////////////////////////////////////////////////////////////////////////////////////
 //
 //*-- Author: Sahal Yacoob (LBL)
-// based on : AliPHOSDigitizer
+// based on : AliEMCALDigitizer
 //_________________________________________________________________________________
 
 // --- ROOT system ---
 #include "AliRun.h"
 #include "AliEMCALDigit.h"
 #include "AliEMCALHit.h"
+#include "AliEMCALTick.h"
 #include "AliEMCALv1.h"
 #include "AliEMCALDigitizer.h"
 #include "AliEMCALSDigitizer.h"
 #include "AliEMCALGeometry.h"
-
+#include "AliEMCALGetter.h"
+#include "AliRunDigitizer.h"
 ClassImp(AliEMCALDigitizer)
 
 
 //____________________________________________________________________________ 
-  AliEMCALDigitizer::AliEMCALDigitizer():TTask("AliEMCALDigitizer","") 
+  AliEMCALDigitizer::AliEMCALDigitizer()
 {
   // ctor
 
   fSDigitizer = 0 ;
   fNinputs = 1 ;
-  fPinNoise = 0.00 ;
-  fEMCDigitThreshold = 0.00 ;
-  fInitialized = kFALSE ;
+  fPinNoise = 0.01 ;
+  fEMCDigitThreshold = 0.01 ;
+  fTimeResolution     = 0.5e-9 ;
+  fTimeSignalLength   = 1.0e-9 ;
+  fPreShowerDigitThreshold = fEMCDigitThreshold/100. ;
+  fADCchannelTower = 0.0015;        // width of one ADC channel in GeV
+  fADCpedestalTower = 0.005 ;      // pedestal of ADC
+  fNADCTower = (Int_t) TMath::Power(2,16) ;  // number of channels in Tower ADC
 
-  fHeaderFiles = 0;
-  fSDigitsTitles = 0;
-  fSDigits  = 0 ;
-  fDigits = 0;
+  fADCchannelPreSho = 0.0015 ;          // width of one ADC channel in Pre Shower
+  fADCpedestalPreSho = 0.005 ;         // pedestal of ADC
+  fNADCPreSho = (Int_t) TMath::Power(2,16);      // number of channels in Pre Shower ADC
+  fTimeThreshold = 0.001*10000000 ; //Means 1 MeV in terms of SDigits amplitude
+  fManager = 0 ;
 
-}
-//____________________________________________________________________________ 
-void AliEMCALDigitizer::Init(){
-// Makes all memory allocations
 
-  if(!fInitialized){
-    
-    fHeaderFiles  = new TClonesArray("TObjString",1) ;
-    new((*fHeaderFiles)[0]) TObjString("galice.root") ;
-    
-    //Test, if this file already open
-    
-    TFile *file = (TFile*) gROOT->GetFile(((TObjString *) fHeaderFiles->At(0))->GetString() ) ;
-    
-    if(file == 0){
-      file = new TFile(((TObjString *) fHeaderFiles->At(0))->GetString(),"update") ;
-      gAlice = (AliRun *) file->Get("gAlice") ;
-    }
-    else
-      file = new TFile(((TObjString *) fHeaderFiles->At(0))->GetString()) ;
-    
-    file->cd() ;
-    
-    fSDigitsTitles = new TClonesArray("TObjString",1);
-    new((*fSDigitsTitles)[0]) TObjString("Default") ;   
-    
-    fSDigits      = new TClonesArray("TClonesArray",1) ;
-    new((*fSDigits)[0]) TClonesArray("AliEMCALDigit",1000) ;
 
-    fSDigitizer = 0 ;
-    
-    fDigitsTitle = "Default" ;
-    
-    fDigits = new TClonesArray("AliEMCALDigit",200000) ;
-    
-    fIevent    = new TArrayI(1) ;
-    fIevent->AddAt(-1,0 ) ; 
-    fIeventMax = new TArrayI(1) ;
-    
-    fIeventMax->AddAt((Int_t) gAlice->TreeE()->GetEntries(), 0 );
-    
-    // add Task to //root/Tasks folder
-    TTask * roottasks = (TTask*)gROOT->GetRootFolder()->FindObject("Tasks") ; 
-    roottasks->Add(this) ; 
-    
-    fInitialized = kTRUE ;
-  }
-  
 }
-
 //____________________________________________________________________________ 
-AliEMCALDigitizer::AliEMCALDigitizer(const char *headerFile,const char *sDigitsTitle):
-  TTask("AliEMCALDigitizer","")
+Bool_t AliEMCALDigitizer::Init()
 {
-  // ctor
-  fHeaderFiles  = new TClonesArray("TObjString",1) ;          
-  new((*fHeaderFiles)[0]) TObjString(headerFile) ;
-  
-  // Header file, where result will be stored
-  TFile * file = (TFile*) gROOT->GetFile(((TObjString *) fHeaderFiles->At(0))->GetString() ) ;
-  if(file==0){
-      if(((TObjString *) fHeaderFiles->At(0))->GetString().Contains("rfio"))
-       file =  TFile::Open(((TObjString *) fHeaderFiles->At(0))->GetString(),"update") ;
-      else
-       file = new TFile(((TObjString *) fHeaderFiles->At(0))->GetString(),"update") ;      
-    gAlice = (AliRun *) file->Get("gAlice") ;  //If not read yet
-  }
-  
-  file->cd() ;
+  // Makes all memory allocations
+
+  fSDigitizer = 0 ;
+  fNinputs = 1 ;
+  fPinNoise = 0.01 ;
+  fEMCDigitThreshold = 0.01 ;
+  fTimeResolution     = 0.5e-9 ;
+  fTimeSignalLength   = 1.0e-9 ;
+  fPreShowerDigitThreshold = fEMCDigitThreshold/100. ;
+  fInitialized = kFALSE ;
+  fADCchannelTower = 0.0015;        // width of one ADC channel in GeV
+  fADCpedestalTower = 0.005 ;      //
+  fNADCTower = (Int_t) TMath::Power(2,16) ;  // number of channels in Tower ADC
+
+  fADCchannelPreSho = 0.0015 ;          // width of one ADC channel in Pre Shower
+  fADCpedestalPreSho = 0.005 ;         // 
+  fNADCPreSho = (Int_t) TMath::Power(2,16);      // number of channels in Pre ShowerADC
+
+  fTimeThreshold = 0.001*10000000 ; //Means 1 MeV in terms of SDigits amplitude
+
+
+if(fManager)
+    SetTitle("aliroot") ;
+  else if (strcmp(GetTitle(),"")==0) 
+   SetTitle("galice.root") ;
+
+  if( strcmp(GetName(), "") == 0 )
+    SetName("Default") ;
   
-  fSDigitsTitles = new TClonesArray("TObjString",1);         // Title name of the SDigits branch
-  new((*fSDigitsTitles)[0]) TObjString(sDigitsTitle) ;  
-    
-  fSDigits      = new TClonesArray("TClonesArray",1) ;      // here list of SDigits wil be stored
-  new((*fSDigits)[0]) TClonesArray("AliEMCALDigit",1000) ;
-    
-  fDigits = new TClonesArray("AliEMCALDigit",200000) ;
+  AliEMCALGetter * gime = AliEMCALGetter::GetInstance(GetTitle(), GetName(), "update") ; 
+  if ( gime == 0 ) {
+    cerr << "ERROR: AliEMCALDigitizer::Init -> Could not obtain the Getter object !" << endl ; 
+    return kFALSE;
+  } 
   
-  fDigitsTitle = "Default" ; 
-
+  //const AliEMCALGeometry * geom = gime->EMCALGeometry() ;
+  //fEmcCrystals = geom->GetNModules() *  geom->GetNCristalsInModule() ;
   
-  fSDigitizer = 0 ;
+  // Post Digits to the white board
+  gime->PostDigits(GetName() ) ;   
   
-  fIevent    = new TArrayI(1) ;
-  fIevent->AddAt(-1,0 ) ; 
-  fIeventMax = new TArrayI(1) ;
+  // Post Digitizer to the white board
+  gime->PostDigitizer(this) ;
   
-  // Get number of events to process
-  fIeventMax->AddAt((Int_t) gAlice->TreeE()->GetEntries(), 0 );
+  //Mark that we will use current header file
+  if(!fManager){
+    gime->PostSDigits(GetName(),GetTitle()) ;
+    gime->PostSDigitizer(GetName(),GetTitle()) ;
+  }
+  return kTRUE ;
   
-  fNinputs = 1 ;
   
-  fPinNoise = 0.0001 ;
-  fEMCDigitThreshold = 0.001 ;
+}
+
+//____________________________________________________________________________ 
+AliEMCALDigitizer::AliEMCALDigitizer(const char *headerFile,const char *name)
+{
+   SetName(name) ;
+  SetTitle(headerFile) ;
+  fManager = 0 ;                     // We work in the standalong mode
+  Init() ;
   
-  // add Task to //root/Tasks folder
-  TTask * roottasks = (TTask*)gROOT->GetRootFolder()->FindObject("Tasks") ; 
-  roottasks->Add(this) ; 
-  fInitialized = kTRUE ;
+
   
+}
+//____________________________________________________________________________ 
+AliEMCALDigitizer::AliEMCALDigitizer(AliRunDigitizer * ard):AliDigitizer(ard)
+{
+  // ctor
+  SetName("");     //Will call init in the digitizing
+  SetTitle("aliroot") ;  
 }
 
 //____________________________________________________________________________ 
@@ -201,54 +188,21 @@ AliEMCALDigitizer::AliEMCALDigitizer(const char *headerFile,const char *sDigitsT
 {
   // dtor
 
-  if(fHeaderFiles)  delete fHeaderFiles ;
-  if(fSDigitsTitles) delete fSDigitsTitles ;
-  if(fSDigits)      delete fSDigits ;
-  if(fDigits)       delete fDigits ;
 }
 //____________________________________________________________________________
 void AliEMCALDigitizer::Reset() { 
   //sets current event number to the first simulated event
+if( strcmp(GetName(), "") == 0 )
+  Init() ;
 
-  if(!fInitialized)
-    Init() ;
-
-  Int_t inputs ;
-  for(inputs = 0; inputs < fNinputs ;inputs++)
-      fIevent->AddAt(-1, inputs ) ;
-  
-}
-//____________________________________________________________________________
-Bool_t AliEMCALDigitizer::Combinator() { 
-
-  //Makes all desirable combinations Signal+Background,
-  // returns kFALSE when all combinations are made
-  // May be useful to introduce some options like "One-to-One", "All-to-One" and "All-to-All" ?
-
-  //realizing "One-to-One" option...
-
-  if(!fInitialized)
-    Init() ;
-
-  Int_t inputs ;
-  Bool_t endNotReached = kTRUE ;
-
-  for(inputs = 0; (inputs < fNinputs) && endNotReached ;inputs++){
-    if(fIevent->At(inputs)+1 < fIeventMax->At(inputs))
-      fIevent->AddAt(fIevent->At(inputs)+1, inputs ) ;
-    else
-      if(inputs == 0)
-       endNotReached = kFALSE ;
-      else //for inputs other than base one start from the beginning
-       fIevent->AddAt(0, inputs ) ;
-    
-  }
-  return endNotReached ;
+      // Int_t inputs ;
+      // for(inputs = 0; inputs < fNinputs ;inputs++)
+      //  fIevent->AddAt(-1, inputs ) ;
   
 }
 
 //____________________________________________________________________________
-void AliEMCALDigitizer::Digitize(Option_t *option) { 
+void AliEMCALDigitizer::Digitize(const Int_t event) { 
 
   // Makes the digitization of the collected summable digits
   // for this it first creates the array of all EMCAL modules
@@ -257,318 +211,289 @@ void AliEMCALDigitizer::Digitize(Option_t *option) {
   // helps to avoid scanning over the list of digits to add 
   // contribution of any new SDigit.
 
-  if(!fInitialized)
-    Init() ;
+  AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ; 
+  TClonesArray * digits = gime->Digits(GetName()) ; 
+  
+  digits->Clear() ;
 
-  fDigits->Clear() ;
+    const AliEMCALGeometry *geom = gime->EMCALGeometry() ; 
 
-  AliEMCALv0 * EMCAL = (AliEMCALv0 *) gAlice->GetDetector("EMCAL") ;   
-  AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance( EMCAL->GetGeometry()->GetName(), EMCAL->GetGeometry()->GetTitle() );
 
   //Making digits with noise, first EMC
   Int_t nEMC = 2*geom->GetNPhi()*geom->GetNZ();
   Int_t absID ;
   TString name      =  geom->GetName() ;
-  
-  for(absID = 1; absID <= nEMC; absID++){
-    Float_t noise = gRandom->Gaus(0., fPinNoise) ; 
-    new((*fDigits)[absID-1]) AliEMCALDigit( -1,-1, absID,fSDigitizer->Digitize(noise) ) ;
-  }
-  
 
-  // Now look throught (unsorted) list of SDigits and add corresponding digits  
-  AliEMCALDigit *curSDigit ;
-  AliEMCALDigit *digit ;
-    
-  Int_t inputs;
-  for(inputs = 0; inputs< fNinputs ; inputs++){  //loop over (possible) merge sources
-    
-    TClonesArray * sdigits= (TClonesArray *)fSDigits->At(inputs) ;
-    Int_t isdigit ;
-
-    Int_t nSDigits = sdigits->GetEntries() ;     
-    for(isdigit=0;isdigit< nSDigits; isdigit++){
-      curSDigit = (AliEMCALDigit *)sdigits->At(isdigit) ;
-     if(inputs)                                       //Shift primaries for non-background sdigits
-       curSDigit->ShiftPrimary(inputs) ;
-      digit = (AliEMCALDigit *)fDigits->At(curSDigit->GetId() - 1);
-     cout << curSDigit->GetAmp() << "   and   "  << digit->GetAmp() << endl ; 
-      *digit = *digit + *curSDigit ;
-    }  
+ // get first the sdigitizer from the tasks list (must have same name as the digitizer)
+  const AliEMCALSDigitizer * sDigitizer = gime->SDigitizer(GetName()); 
+  if ( !sDigitizer) {
+    cerr << "ERROR: AliEMCALDigitizer::Digitize -> SDigitizer with name " << GetName() << " not found " << endl ; 
+    abort() ; 
   }
 
+// loop through the sdigits posted to the White Board and add them to the noise
+  TCollection * folderslist = gime->SDigitsFolder()->GetListOfFolders() ; 
+  TIter next(folderslist) ; 
+  TFolder * folder = 0 ; 
+  TClonesArray * sdigits = 0 ;
+  Int_t input = 0 ;
+  TObjArray * sdigArray = new TObjArray(2) ;
+  while ( (folder = (TFolder*)next()) ) 
+    if ( (sdigits = (TClonesArray*)folder->FindObject(GetName()) ) ) {
+      cout << "INFO: AliEMCALDigitizer::Digitize -> Adding SDigits " 
+          << GetName() << " from " << folder->GetName() << endl ; 
+      sdigArray->AddAt(sdigits, input) ;
+      input++ ;
+    }
 
-  //remove digits below thresholds
-  for(absID = 0; absID < nEMC ; absID++)
-   if(fSDigitizer->Calibrate(((AliEMCALDigit*)fDigits->At(absID))->GetAmp()) < fEMCDigitThreshold)
-      fDigits->RemoveAt(absID) ;
-  
-  fDigits->Compress() ;  
-  
-  Int_t ndigits = fDigits->GetEntriesFast() ;
-
-  fDigits->Expand(ndigits) ;
+  //Find the first crystall with signal
+  Int_t nextSig = 200000 ; 
+  Int_t i;
+  for(i=0; i<input; i++){
+    sdigits = (TClonesArray *)sdigArray->At(i) ;
+    if ( !sdigits->GetEntriesFast() )
+      continue ; 
+    Int_t curNext = ((AliEMCALDigit *)sdigits->At(0))->GetId() ;
+     if(curNext < nextSig) 
+       nextSig = curNext ;
+  }
 
+  TArrayI index(input) ;
+  index.Reset() ;  //Set all indexes to zero
 
-  //Set indexes in list of digits
-  Int_t i ;
-  for (i = 0 ; i < ndigits ; i++) { 
-    AliEMCALDigit * digit = (AliEMCALDigit *) fDigits->At(i) ; 
-    digit->SetIndexInList(i) ;     
-    cout << digit->GetAmp() << "is amp" << endl;    
-    Float_t energy = fSDigitizer->Calibrate(digit->GetAmp()) ;
-    cout << energy << " = energy " << endl;
-    energy = energy*1000 ;
-    cout << energy << " = energy " << endl;
-    digit->SetAmp(DigitizeEnergy(energy,digit->GetId()) ) ;
-    cout << digit->GetAmp() << "is amp" << endl;    
-    cout << 100*energy/12.9 << endl ;
-  }
-}
-//____________________________________________________________________________
+  AliEMCALDigit * digit = 0 ;
+  AliEMCALDigit * curSDigit = 0 ;
 
-Int_t AliEMCALDigitizer::DigitizeEnergy(Float_t energy, Int_t absId)
- { Int_t chanel ;
-  //if(absId <= fEmcCrystals){ //digitize as EMC
-    chanel = (Int_t) TMath::Ceil(energy) ;
-    //if(chanel > fNADCemc ) chanel =  fNADCemc ;
- // }
-  return chanel ;
-}
-//____________________________________________________________________________
+  TClonesArray * ticks = new TClonesArray("AliEMCALTick",1000) ;
 
+  //Put Noise contribution
+  for(absID = 1; absID <= nEMC; absID++){
+    Float_t noise = gRandom->Gaus(0., fPinNoise) ; 
+    new((*digits)[absID-1]) AliEMCALDigit( -1, -1, absID,sDigitizer->Digitize(noise), TimeOfNoise() ) ;
+    //look if we have to add signal?
+    if(absID==nextSig){
+      //Add SDigits from all inputs 
+      digit = (AliEMCALDigit *) digits->At(absID-1) ;
+      
+      ticks->Clear() ;
+      Int_t contrib = 0 ;
+      Float_t a = digit->GetAmp() ;
+      Float_t b = TMath::Abs( a /fTimeSignalLength) ;
+      //Mark the beginnign of the signal
+      new((*ticks)[contrib++]) AliEMCALTick(digit->GetTime(),0, b);  
+      //Mark the end of the ignal     
+      new((*ticks)[contrib++]) AliEMCALTick(digit->GetTime()+fTimeSignalLength, -a, -b);
+      
+ // loop over input
+  
+      for(i = 0; i< input ; i++){  //loop over (possible) merge sources
+       if(((TClonesArray *)sdigArray->At(i))->GetEntriesFast() > index[i] )
+         curSDigit = (AliEMCALDigit*)((TClonesArray *)sdigArray->At(i))->At(index[i]) ;        
+       else
+         curSDigit = 0 ;
+       //May be several digits will contribute from the same input
+       while(curSDigit && curSDigit->GetId() == absID){           
+         //Shift primary to separate primaries belonging different inputs
+         Int_t primaryoffset ;
+         if(fManager)
+           primaryoffset = fManager->GetMask(i) ; 
+         else
+           primaryoffset = i ;
+         curSDigit->ShiftPrimary(primaryoffset) ;
+         
+         a = curSDigit->GetAmp() ;
+         b = a /fTimeSignalLength ;
+         new((*ticks)[contrib++]) AliEMCALTick(curSDigit->GetTime(),0, b);  
+         new((*ticks)[contrib++]) AliEMCALTick(curSDigit->GetTime()+fTimeSignalLength, -a, -b); 
+
+         *digit = *digit + *curSDigit ;  //add energies
+
+         index[i]++ ;
+         if(((TClonesArray *)sdigArray->At(i))->GetEntriesFast() > index[i] )
+           curSDigit = (AliEMCALDigit*)((TClonesArray *)sdigArray->At(i))->At(index[i]) ;      
+         else
+           curSDigit = 0 ;
+       }
+      }
 
-void AliEMCALDigitizer::WriteDigits(){
+//calculate and set time
+      Float_t time = FrontEdgeTime(ticks) ;
+      digit->SetTime(time) ;
+
+      //Find next signal module
+      nextSig = 200000 ;
+      for(i=0; i<input; i++){
+       sdigits = ((TClonesArray *)sdigArray->At(i)) ;
+       Int_t curNext = nextSig ;
+       if(sdigits->GetEntriesFast() > index[i] ){
+         curNext = ((AliEMCALDigit *) sdigits->At(index[i]))->GetId() ;
+         
+       }
+       if(curNext < nextSig) nextSig = curNext ;
+      }
+    }
+  }
+  
+  ticks->Delete() ;
+  delete ticks ;
 
-  // Made TreeD in the output file. Check if branch already exists: if yes, exits 
-  // without writing: ROOT TTree does not suppert overwriting/updating of the 
-  // already existing branches. Creates branch with Digits, named "EMCAL", title "...",
-  // and branch "AliEMCALDigitizer", with the same title to keep all the parameters
-  // and names of files, from which digits are made.
 
-  gAlice->GetEvent(fIevent->At(0)) ;  // Suitable only for One-To-One mixing
-  gAlice->SetEvent(fIevent->At(0)) ;  // for all-to-all will produce a lot of branches in TreeD
 
-  if(gAlice->TreeD()==0)
-    gAlice->MakeTree("D") ;  
 
-  //Check, if this branch already exits?
-  TBranch * digitsBranch = 0;
-  TBranch * digitizerBranch = 0;
-  
-  TObjArray * branches = gAlice->TreeD()->GetListOfBranches() ;
-  Int_t ibranch;
-  Bool_t emcalNotFound = kTRUE ;
-  Bool_t digitizerNotFound = kTRUE ;
+  //remove digits below thresholds
+  for(absID = 0; absID < nEMC/2 ; absID++){
+    if(sDigitizer->Calibrate(((AliEMCALDigit*)digits->At(absID))->GetAmp()) < fEMCDigitThreshold)
+      digits->RemoveAt(absID) ;
+    else
+      digit->SetTime(gRandom->Gaus(digit->GetTime(),fTimeResolution) ) ;
+  }
   
-  for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){
-    
-    if(emcalNotFound){
-      digitsBranch=(TBranch *) branches->At(ibranch) ;
-      if( (strcmp("EMCAL",digitsBranch->GetName())==0 ) &&
-         (fDigitsTitle.CompareTo(digitsBranch->GetTitle()) == 0) )
-       emcalNotFound = kFALSE ;
-    }
-    if(digitizerNotFound){
-      digitizerBranch = (TBranch *) branches->At(ibranch) ;
-      if( (strcmp(digitizerBranch->GetName(),"AliEMCALDigitizer") == 0) &&
-         (fDigitsTitle.CompareTo(digitizerBranch->GetTitle()) == 0))
-       digitizerNotFound = kFALSE ;
-    }
+  for(absID = nEMC/2; absID < nEMC ; absID++){
+    if(sDigitizer->Calibrate(((AliEMCALDigit*)digits->At(absID))->GetAmp()) < fPreShowerDigitThreshold)
+      digits->RemoveAt(absID) ;
+    else
+      digit->SetTime(gRandom->Gaus(digit->GetTime(),fTimeResolution) ) ;
   }
   
+  digits->Compress() ;  
   
-  if(!(digitizerNotFound && emcalNotFound)){ 
-    cout << "AliEMCALDigitizer error: " << endl ;
-    cout << "       can not update/overwrite existing branches "<< endl ;
-    cout << "       do not write " << endl ;
-    return ;
-  }
-
-  // create new branches
-
-  //First generate file name
-  char * file =0;
-  if(gSystem->Getenv("CONFIG_SPLIT_FILE")){ //generating file name
-    file = new char[strlen(gAlice->GetBaseFile())+20] ;
-    sprintf(file,"%s/EMCAL.Digits.root",gAlice->GetBaseFile()) ;
-  }
+  Int_t ndigits = digits->GetEntriesFast() ;
   
-  TDirectory *cwd = gDirectory;
+  digits->Expand(ndigits) ;
   
-  //First create list of sdigits
-  Int_t bufferSize = 32000 ;    
-  digitsBranch = gAlice->TreeD()->Branch("EMCAL",&fDigits,bufferSize);
-  digitsBranch->SetTitle(fDigitsTitle.Data());
-  if (file) {
-    digitsBranch->SetFile(file);
-    TIter next( digitsBranch->GetListOfBranches());
-    TBranch * sbr ;
-    while ((sbr=(TBranch*)next())) {
-      sbr->SetFile(file);
-    }   
-    cwd->cd();
-  } 
-    
-  //second - create Digitizer
-  Int_t splitlevel = 0 ;
-  AliEMCALDigitizer * d = this ;
-  digitizerBranch = gAlice->TreeD()->Branch("AliEMCALDigitizer","AliEMCALDigitizer",
-                                           &d,bufferSize,splitlevel); 
-  digitizerBranch->SetTitle(fDigitsTitle.Data());
-  if (file) {
-    digitizerBranch->SetFile(file);
-    TIter next( digitizerBranch->GetListOfBranches());
-    TBranch * sbr;
-    while ((sbr=(TBranch*)next())) {
-      sbr->SetFile(file);
-    }   
-    cwd->cd();
-  }
-
-  digitsBranch->Fill() ;
-  digitizerBranch->Fill() ;
   
-  gAlice->TreeD()->Write(0,kOverwrite) ;  
-
-  //remove fSDigitizer before new event.  
-  if(fSDigitizer){
-    delete fSDigitizer ;
-    fSDigitizer = 0 ;
+  //Set indexes in list of digits
+  //Int_t i ;
+  for (i = 0 ; i < ndigits ; i++) { 
+    AliEMCALDigit * digit = (AliEMCALDigit *) digits->At(i) ; 
+    digit->SetIndexInList(i) ; 
+    Float_t energy = sDigitizer->Calibrate(digit->GetAmp()) ;
+    digit->SetAmp(DigitizeEnergy(energy,digit->GetId()) ) ;
   }
+}
 
+//____________________________________________________________________________
 
+Int_t AliEMCALDigitizer::DigitizeEnergy(Float_t energy, Int_t absId)
+{ 
+  Int_t channel = -999;
+  Int_t nphi = AliEMCALGetter::GetInstance()->EMCALGeometry()->GetNPhi() ; 
+  Int_t nz   = AliEMCALGetter::GetInstance()->EMCALGeometry()->GetNZ() ;
+  
+  if(absId <= nphi*nz) //digitize as tower
+    channel = (Int_t) TMath::Ceil( (energy + fADCpedestalTower)/fADCchannelTower )  ;
+  if(channel > fNADCTower ) channel =  fNADCTower ;
+  else 
+    channel =  (Int_t) TMath::Ceil( (energy + fADCpedestalPreSho)/fADCchannelPreSho )  ;
+  if(channel > fNADCPreSho ) channel =  fNADCPreSho ;
+  
+  return channel ;
 }
 
 //____________________________________________________________________________
 void AliEMCALDigitizer::Exec(Option_t *option) { 
   // Managing method
-
-  if(!fInitialized)    Init() ;
-
+if(strcmp(GetName(), "") == 0 )   
+    Init() ;
+  
+  if (strstr(option,"print")) {
+    Print("");
+    return ; 
+  }
+  
   if(strstr(option,"tim"))
     gBenchmark->Start("EMCALDigitizer");
 
-  //reset events numbers to start from the beginnig
-  Reset() ;
+  AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
+  
+  Int_t nevents ;
+  
+  TTree * treeD ;
+  
+  if(fManager){
+    treeD = fManager->GetTreeD() ;
+    nevents = 1 ;    // Will process only one event
+  }
+  else {
+    gAlice->GetEvent(0) ;
+    nevents = (Int_t) gAlice->TreeE()->GetEntries() ;
+    treeD=gAlice->TreeD() ;
+  }
+  if(treeD == 0 ){
+    cerr << " AliEMCALDigitizer :: Can not find TreeD " << endl ;
+    return ;
+  }
+
+  //Check, if this branch already exits
+  TObjArray * lob = (TObjArray*)treeD->GetListOfBranches() ;
+  TIter next(lob) ; 
+  TBranch * branch = 0 ;  
+  Bool_t emcalfound = kFALSE, digitizerfound = kFALSE ; 
   
-  while(Combinator()){  
+  while ( (branch = (TBranch*)next()) && (!emcalfound || !digitizerfound) ) {
+    if ( (strcmp(branch->GetName(), "EMCAL")==0) && 
+        (strcmp(branch->GetTitle(), GetName())==0) ) 
+      emcalfound = kTRUE ;
+    
+    else if ( (strcmp(branch->GetName(), "AliEMCALDigitizer")==0) && 
+             (strcmp(branch->GetTitle(), GetName())==0) ) 
+      digitizerfound = kTRUE ; 
+  }
+
+  if ( emcalfound ) {
+    cerr << "WARNING: AliEMCALDigitizer -> Digits branch with name " << GetName() 
+        << " already exits" << endl ;
+    return ; 
+  }   
+  if ( digitizerfound ) {
+    cerr << "WARNING: AliEMCALDigitizer -> Digitizer branch with name " << GetName() 
+        << " already exits" << endl ;
+    return ; 
+  }   
+
+  Int_t ievent ;
+
+  for(ievent = 0; ievent < nevents; ievent++){
+    
+    if(fManager){
+      Int_t input ;
+      for(input = 0 ; input < fManager->GetNinputs(); input ++){
+       TTree * treeS = fManager->GetInputTreeS(input) ;
+       if(!treeS){
+         cerr << "AliEMCALDigitizer -> No Input " << endl ;
+         return ;
+       }
+       gime->ReadTreeS(treeS,input) ;
+      }
+    }
+    else
+      gime->Event(ievent,"S") ;
     
-    if(!ReadSDigits()) //read sdigits event(s) evaluated by Combinator() from file(s)
-      return ;    
+    Digitize(ievent) ; //Add prepared SDigits to digits and add the noise
     
-    Digitize(option) ; //Add prepared SDigits to digits and add the noise
-    WriteDigits() ;
+    WriteDigits(ievent) ;
     
     if(strstr(option,"deb"))
       PrintDigits(option);
-
+    
+    //increment the total number of Digits per run 
+    fDigitsInRun += gime->Digits()->GetEntriesFast() ;  
   }
-
+  
   if(strstr(option,"tim")){
     gBenchmark->Stop("EMCALDigitizer");
     cout << "AliEMCALDigitizer:" << endl ;
-    cout << "  took " << gBenchmark->GetCpuTime("EMCALDigitizer") << " seconds for SDigitizing " 
-        <<  gBenchmark->GetCpuTime("EMCALDigitizer")/(fIeventMax->At(0)) << " seconds per event " << endl ;
+    cout << "  took " << gBenchmark->GetCpuTime("EMCALDigitizer") << " seconds for Digitizing " 
+        <<  gBenchmark->GetCpuTime("EMCALDigitizer")/nevents << " seconds per event " << endl ;
     cout << endl ;
   }
   
 }
 
-//__________________________________________________________________
-Bool_t AliEMCALDigitizer::ReadSDigits(){
-// Reads summable digits from the opened files for the particular set of events given by fIevent
-
-  if(!fInitialized)    Init() ;
-
 
-  Int_t inputs ;
-  for(inputs = fNinputs-1; inputs >= 0; inputs --){
 
-    Int_t event = fIevent->At(inputs) ;
-
-    TFile * file = (TFile*) gROOT->GetFile(((TObjString *) fHeaderFiles->At(inputs))->GetString() ) ;
-    file->cd() ;
-
-    // Get SDigits Tree header from file
-    char treeName[20]; 
-    sprintf(treeName,"TreeS%d",event);
-    TTree * treeS = (TTree*)file->Get(treeName);
-   
-    if(treeS==0){
-      cout << "Error at AliEMCALDigitizer: no "<<treeName << "   in file " << file->GetName() << endl ;
-      cout << "Do nothing " << endl ;
-      return kFALSE ;
-    }
-
-    TBranch * sdigitsBranch = 0;
-    TBranch * sdigitizerBranch = 0;
-
-    TObjArray * branches = treeS->GetListOfBranches() ;
-    Int_t ibranch;
-    Bool_t emcalNotFound = kTRUE ;
-    Bool_t sdigitizerNotFound = kTRUE ;
-  
-    for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){
-            
-      if(emcalNotFound){
-       sdigitsBranch=(TBranch *) branches->At(ibranch) ;
-       if(( strcmp("EMCAL",sdigitsBranch->GetName())==0 ) &&
-          ((TObjString*) fSDigitsTitles->At(inputs))->GetString().CompareTo(sdigitsBranch->GetTitle())== 0 )
-             emcalNotFound = kFALSE ;
-       
-      }
-      
-      if(sdigitizerNotFound){
-       sdigitizerBranch = (TBranch *) branches->At(ibranch) ;
-       if(( strcmp(sdigitizerBranch->GetName(),"AliEMCALSDigitizer") == 0) &&
-          ((TObjString*) fSDigitsTitles->At(inputs))->GetString().CompareTo(sdigitizerBranch->GetTitle())== 0 )
-             sdigitizerNotFound = kFALSE ;
-       
-      }
-    }
-    
-    if(sdigitizerNotFound || emcalNotFound){
-      cout << "Can't find Branch with sdigits or SDigitizer in the file " ;
-      if( ((TObjString*)fSDigitsTitles->At(inputs))->GetString().IsNull() )
-       cout << file->GetName() << endl ;       
-      else
-       cout << ((TObjString*)fSDigitsTitles->At(inputs))->GetString().Data() << endl ;
-      cout << "Do nothing" <<endl  ;
-      return kFALSE ;
-    }
-    
-    TClonesArray * sdigits = (TClonesArray*) fSDigits->At(inputs) ;  
-    sdigitsBranch->SetAddress(&sdigits) ;
-    
-    AliEMCALSDigitizer *sDigitizer = new AliEMCALSDigitizer();
-    sdigitizerBranch->SetAddress(&sDigitizer) ;
-
-    sdigitsBranch->GetEntry(0) ;
-    sdigitizerBranch->GetEntry(0) ;
-    
-    if(fSDigitizer == 0)
-      fSDigitizer = sDigitizer ;
-    else
-      if(!((*fSDigitizer)==(*sDigitizer)) ){
-       cout << "AliEMCALDigitizer ERROR:" << endl ;
-       cout << "       you are using sdigits made with different SDigitizers" << endl ;
-       cout << "fSD " << fSDigitizer << "  SD" << sDigitizer << endl ;
-       fSDigitizer->Print("") ;
-       sDigitizer->Print("") ;
-       cout << "Do Nothing " << endl ;
-       return kFALSE ;
-      }
-    
-  }
-  fPedestal = fSDigitizer->GetPedestalParameter() ;
-  fSlope    = fSDigitizer->GetCalibrationParameter() ;
-  
-  return kTRUE ;
-
-}
 //__________________________________________________________________
-void AliEMCALDigitizer::MixWith(char* HeaderFile, char* sDigitsTitle){
+void AliEMCALDigitizer::MixWith(char* headerFile){
   // Alows produce digits by superimposing background and signal event.
   // It is assumed, that headers file with SIGNAL events is opened in 
   // constructor, and now we set the BACKGROUND event, with which we 
@@ -578,86 +503,74 @@ void AliEMCALDigitizer::MixWith(char* HeaderFile, char* sDigitsTitle){
   //
   // One can open as many files to mix with as one wants.
 
-
-  if(!fInitialized)
+if( strcmp(GetName(), "") == 0 )
     Init() ;
-
-
-  if(HeaderFile == 0){
-    cout << "Specify at least header file to merge"<< endl ;
+  
+ if(fManager){
+    cout << "Can not use this method under AliRunDigitizer " << endl ;
     return ;
+  } // check if the specified SDigits do not already exist on the White Board:
+  // //Folders/RunMC/Event/Data/EMCAL/SDigits/headerFile/sdigitsname
+
+  TString path = "Folders/RunMC/Event/Data/EMCAL/SDigits" ; 
+  path += headerFile ; 
+  path += "/" ; 
+  path += GetName() ;
+  if ( gROOT->FindObjectAny(path.Data()) ) {
+    cerr << "WARNING: AliEMCALDigitizer::MixWith -> Entry already exists, do not add" << endl ;
+    return;
   }
+
+  AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
+  gime->PostSDigits(GetName(),headerFile) ;
   
-  Int_t inputs ;
-  for(inputs = 0; inputs < fNinputs ; inputs++){
-    if(strcmp(((TObjString *)fHeaderFiles->At(inputs))->GetString(),HeaderFile) == 0 ){
-      if(sDigitsTitle == 0){ 
-       if(((TObjString*)fSDigitsTitles->At(inputs))->GetString().CompareTo("")  == 0){
-         cout << "Entry already exists, do not add" << endl ;
-         return ;
-       }
-      }
-      else
-       if(((TObjString*)fSDigitsTitles->At(inputs))->GetString().CompareTo(sDigitsTitle)){
-         cout << "Entry already exists, do not add" << endl ;
-         return;
-       }
-    }  
-  }  
-  
-  fHeaderFiles->Expand(fNinputs+1) ;
-  new((*fHeaderFiles)[fNinputs]) TObjString(HeaderFile) ;
-  
-  
-  TFile * file = new TFile(((TObjString *) fHeaderFiles->At(fNinputs))->GetString()) ;  
-  
-  file->cd() ;
-  
-  fSDigitsTitles->Expand(fNinputs+1) ;
-  new((*fSDigitsTitles)[fNinputs]) TObjString(sDigitsTitle) ;
-  
-  fSDigits->Expand(fNinputs+1) ;
-  new((*fSDigits)[fNinputs]) TClonesArray("AliEMCALDigit",1000) ;
-  
-  fIevent->Set(fNinputs+1) ;
-  fIevent->AddAt(-1, fNinputs) ;
-  
-  fIeventMax->Set(fNinputs+1) ;  
-  
-  TTree * te = (TTree *) file->Get("TE") ;
-  fIeventMax->AddAt((Int_t) te->GetEntries(), fNinputs );
-  
-  fNinputs++ ;
+  // check if the requested file is already open or exist and if SDigits Branch exist
+  TFile * file = (TFile*)gROOT->FindObject(headerFile); 
+  if ( !file ) { 
+    file = new TFile(headerFile, "READ") ; 
+    if (!file) { 
+      cerr << "ERROR: AliEMCALDigitizer::MixWith -> File " << headerFile << " does not exist!" << endl ; 
+      return ; 
+    }
+  }
   
 }
 //__________________________________________________________________
 void AliEMCALDigitizer::Print(Option_t* option)const {
-  
-  if(fInitialized){
+  if( strcmp(GetName(), "") != 0) {
     
     cout << "------------------- "<< GetName() << " -------------" << endl ;
     cout << "Digitizing sDigits from file(s): " <<endl ;
-    Int_t input ;
-    for(input = 0; input < fNinputs ; input++) {
-      cout << "          " << ((TObjString *) fHeaderFiles->At(input))->GetString() << 
-       "   Branch title:" << ((TObjString *) fSDigitsTitles->At(input))->GetString() << endl ;
-    }
-    cout << endl ;
-    cout << "Writing digits to " << ((TObjString *) fHeaderFiles->At(0))->GetString() << endl ;
     
-    cout << endl ;
-    cout << "With following parameters: " << endl ;
-    cout << "     Electronics noise in EMC (fPinNoise) = " << fPinNoise << endl ;
-    cout << "  Threshold  in EMC  (fEMCDigitThreshold) = " << fEMCDigitThreshold  << endl ; ;
-    cout << "---------------------------------------------------" << endl ;
-  }
-  else
-    cout << "AliEMCALDigitizer not initialized " << endl ;
-  
+  TCollection * folderslist = ((TFolder*)gROOT->FindObjectAny("Folders/RunMC/Event/Data/EMCAL/SDigits"))->GetListOfFolders() ; 
+    TIter next(folderslist) ; 
+    TFolder * folder = 0 ;
+    while ( (folder = (TFolder*)next()) ) 
+      if ( folder->FindObject(GetName())  ) 
+       {
+       cout << "Adding SDigits " << GetName() << " from " << folder->GetName() << endl ; 
+      cout << endl ;
+      cout << "Writing digits to " << GetTitle() << endl ;
+      
+      cout << endl ;
+      cout << "With following parameters: " << endl ;
+      cout << "     Electronics noise in EMC (fPinNoise) = " << fPinNoise << endl ;
+      cout << "  Threshold  in EMC  (fEMCDigitThreshold) = " << fEMCDigitThreshold  << endl;
+      cout << "  Threshold  in PreShower  (fPreShowerDigitThreshold) = " << fPreShowerDigitThreshold  << endl ; ;
+      cout << "---------------------------------------------------" << endl ;
+    }
+    else
+      cout << "AliEMCALDigitizer not initialized " << endl ;
+    }
 }
+
 //__________________________________________________________________
 void AliEMCALDigitizer::PrintDigits(Option_t * option){
     
+  AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ; 
+  TClonesArray * fDigits = gime->Digits() ;
+
   cout << "AliEMCALDigitiser:"<< endl ;
   cout << "       Number of entries in Digits list " << fDigits->GetEntriesFast() << endl ;
   cout << endl ;
@@ -681,19 +594,103 @@ void AliEMCALDigitizer::PrintDigits(Option_t * option){
     
   }
 }
-//__________________________________________________________________
-void AliEMCALDigitizer::SetSDigitsBranch(const char* title){
-  // we set title (comment) of the SDigits branch in the first! header file
-  if(!fInitialized)    Init() ;
+//_________________________________________________________________________________________
+void AliEMCALDigitizer::WriteDigits(Int_t event)
+{
 
-  ((TObjString*) fSDigitsTitles->At(0) )->SetString((char*)title) ;
+  // Makes TreeD in the output file. 
+  // Check if branch already exists: 
+  //   if yes, exit without writing: ROOT TTree does not support overwriting/updating of 
+  //      already existing branches. 
+  //   else creates branch with Digits, named "EMCAL", title "...",
+  //      and branch "AliEMCALDigitizer", with the same title to keep all the parameters
+  //      and names of files, from which digits are made.
 
-}
-//__________________________________________________________________
-void AliEMCALDigitizer::SetDigitsBranch(const char* title){
-  //Sets the title (comment) of the branch to which Digits branch
-  if(!fInitialized)    Init() ;
+  AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ; 
+  const TClonesArray * digits = gime->Digits(GetName()) ; 
+ TTree * treeD ;
+
+  if(fManager)
+    treeD = fManager->GetTreeD() ;
+ else
+    treeD = gAlice->TreeD();
   
-  fDigitsTitle = title ;
+  // create new branches
+  // -- generate file name if necessary
+  char * file =0;
+  if(gSystem->Getenv("CONFIG_SPLIT_FILE")){ //generating file name
+    file = new char[strlen(gAlice->GetBaseFile())+20] ;
+    sprintf(file,"%s/EMCAL.Digits.root",gAlice->GetBaseFile()) ;
+  }
+
+  TDirectory *cwd = gDirectory;
+  // -- create Digits branch
+  Int_t bufferSize = 32000 ;    
+  TBranch * digitsBranch = treeD->Branch("EMCAL",&digits,bufferSize);
+  digitsBranch->SetTitle(GetName());
+  if (file) {
+    digitsBranch->SetFile(file);
+    TIter next( digitsBranch->GetListOfBranches());
+    TBranch * sbr ;
+    while ((sbr=(TBranch*)next())) {
+      sbr->SetFile(file);
+    }   
+    cwd->cd();
+  } 
+    
+  // -- Create Digitizer branch
+  Int_t splitlevel = 0 ;
+  AliEMCALDigitizer * d = gime->Digitizer(GetName()) ;
+  TBranch * digitizerBranch = treeD->Branch("AliEMCALDigitizer", "AliEMCALDigitizer", &d,bufferSize,splitlevel); 
+  digitizerBranch->SetTitle(GetName());
+  if (file) {
+    digitizerBranch->SetFile(file);
+    TIter next( digitizerBranch->GetListOfBranches());
+    TBranch * sbr;
+    while ((sbr=(TBranch*)next())) {
+      sbr->SetFile(file);
+    }   
+    cwd->cd();
+  }
+  
+  digitsBranch->Fill() ;      
+  digitizerBranch->Fill() ;
+
+  treeD->Write(0,kOverwrite) ;  
+}
+//____________________________________________________________________________ 
+Float_t AliEMCALDigitizer::FrontEdgeTime(TClonesArray * ticks) 
+{ // 
+  ticks->Sort() ; //Sort in accordance with times of ticks
+  TIter it(ticks) ;
+  AliEMCALTick * ctick = (AliEMCALTick *) it.Next() ;
+  Float_t time = ctick->CrossingTime(fTimeThreshold) ;    
+  
+  AliEMCALTick * t ;  
+  while((t=(AliEMCALTick*) it.Next())){
+    if(t->GetTime() < time)  //This tick starts before crossing
+      *ctick+=*t ;
+    else
+      return time ;
+    
+    time = ctick->CrossingTime(fTimeThreshold) ;    
+  }
+  return time ;
+}
+//____________________________________________________________________________ 
+Float_t AliEMCALDigitizer::TimeOfNoise(void)
+{  // Calculates the time signal generated by noise
+  //to be rewritten, now returns just big number
+  return 1. ;
+
+}
+//____________________________________________________________________________
+void AliEMCALDigitizer::SetSDigitsBranch(const char* title)
+{
+  // we set title (comment) of the SDigits branch in the first! header file
+  if( strcmp(GetName(), "") == 0 )
+    Init() ;
 
+  AliEMCALGetter::GetInstance()->SDigits()->SetName(title) ; 
 }
index 3acd700932e9ab0851b5c3ecc5db156f211aebfc..e5f67451a24f60a397f81aa11ee6c5488224e62b 100644 (file)
 
 
 // --- ROOT system ---
-#include "TTask.h"
+
 #include "TObjString.h"
 class TArrayI ;
 // --- Standard library ---
 
 // --- AliRoot header files ---
 class AliEMCALSDigitizer ;
+#include "AliRunDigitizer.h"
+#include "AliDigitizer.h"
 
 
-class AliEMCALDigitizer: public TTask {
+class AliEMCALDigitizer: public AliDigitizer {
 
 public:
   AliEMCALDigitizer() ;          // ctor
   AliEMCALDigitizer(const char *headerFile,const char * sDigitsBranchTitle = "Default") ; 
+  AliEMCALDigitizer(AliRunDigitizer * ard) ;
+  AliEMCALDigitizer(const AliEMCALDigitizer & dtizer) 
+                  {( (AliEMCALDigitizer &)dtizer ).Copy(*this) ;} 
   virtual ~AliEMCALDigitizer() ;       
 
-  void    Digitize(Option_t *option);            // Make Digits from SDigits stored in fSDigits
+  void    Digitize(const Int_t);            // Make Digits from SDigits stored in fSDigits
   void    Exec(Option_t *option);                // Supervising method
 
   Float_t GetEMCThreshold() const { return fEMCDigitThreshold;}
   Float_t GetPedestal()     const { return fPedestal; }
   Float_t GetPinNoise()     const { return fPinNoise;}
   Float_t GetSlope()        const { return fSlope; }
-  char *  GetDigitsBranch ()const { return (char*)fDigitsTitle.Data() ;}
-  TClonesArray * GetHeadersFiles(){ return fHeaderFiles ;}
-  TArrayI*    GetCurrentEvents()  { return fIevent ;}
-  Int_t   DigitizeEnergy(Float_t energy, Int_t absId) ;
-  void    MixWith(char* HeaderFile, char* SDigitsTitle =0) ; // Add another one file to mix
+  char *  GetDigitsBranch () ;
+  const Float_t GetTimeResolution() const { return fTimeResolution ; }
+
+  void    MixWith(char* HeaderFile) ; // Add another one file to mix
   virtual void    Print(Option_t* option)const ;
   void    Reset() ;   //restarts starts event processing from 0 event(s)
-
+  const Int_t   GetDigitsInRun()  const { return fDigitsInRun; } ;
   void    SetEMCThreshold(Float_t EMCThreshold)  {fEMCDigitThreshold = EMCThreshold;}
   void    SetPinNoise(Float_t PinNoise )         {fPinNoise = PinNoise;}
 
-  void    SetDigitsBranch (const char* file) ;
   void    SetSDigitsBranch(const char* file) ;
+
+ AliEMCALDigitizer & operator = (const AliEMCALDigitizer & rvalue)  {
+    // assignement operator requested by coding convention but not needed
+    abort() ;
+    return *this ; 
+  }
+
 
 private:
-  Bool_t  Combinator() ;                         // makes all desirable combination sig+Bg
-  void    Init();                   
+
+  Bool_t    Init();                   
   Bool_t  ReadSDigits() ;            // Read sdigits for particular events
-  void    WriteDigits() ;            // Writes Digits for particular event
+  void    WriteDigits(Int_t evt) ;            // Writes Digits for particular event
   void    PrintDigits(Option_t * option) ;
+  Float_t TimeOfNoise(void) ;                 // Calculate time signal generated by noise
+  Float_t FrontEdgeTime(TClonesArray * ticks) ;
+ Int_t   DigitizeEnergy(Float_t energy, Int_t absId) ;
 
 private:
-  TClonesArray * fSDigitsTitles ;   // Titles of sdigits branches 
-  TClonesArray * fHeaderFiles ;     // Names of files with headers to merge 
-  TString        fDigitsTitle ;     // Title of the Digits Branch  
-  TClonesArray * fSDigits ;         // ! Lists of SDigits 
-  TClonesArray * fDigits ;          // ! Final list of digits
+  
   AliEMCALSDigitizer * fSDigitizer ; // ! SDigitizer to extract some sdigitizing parameters
   Int_t   fNinputs ;                // Number of input files
   Bool_t  fInitialized ;            // 
-  TArrayI * fIevent ;               // events to read at the next ReadSDigits() call
-  TArrayI * fIeventMax ;            // Maximal number of events in each input file
-
+  Int_t fDigitsInRun ;              //! Total number of digits in one run
   Float_t fPedestal ;                // Calibration parameters 
   Float_t fSlope ;                   // read from SDigitizer
 
   Float_t fPinNoise ;               // Electronics noise in EMC
   Float_t fEMCDigitThreshold  ;     // Threshold for storing digits in EMC
+  Float_t fPreShowerDigitThreshold ; // Threshold for Preshower digits
+
+  Float_t fTimeResolution ;         // Time resolution of FEE electronics
+  Float_t fTimeThreshold ;          // Threshold to start timing for given crystall
+  Float_t fTimeSignalLength ;       // Length of the timing signal 
+
+  Float_t fADCchannelTower ;           // width of one ADC channel in Tower (GeV)
+  Float_t fADCpedestalTower ;         //
+  Int_t fNADCTower ;                // number of channels in Tower ADC
 
+  Float_t fADCchannelPreSho ;           // width of one ADC channel in Pre Shower (GeV)
+  Float_t fADCpedestalPreSho ;                   // 
+  Int_t fNADCPreSho ;                // number of channels in Pre Shower ADC
 
   ClassDef(AliEMCALDigitizer,1)  // description 
 
index 2c212a9d7cc6cea47b7d4c87cc2ef3f7420e08a8..e8d01e5af2683f9a2d2e7976976cc2033de0f172 100644 (file)
@@ -64,6 +64,7 @@
 #include "AliEMCALSDigitizer.h"
 #include "AliEMCALGeometry.h"
 #include "AliEMCALv1.h"
+#include "AliEMCALGetter.h"
 
 ClassImp(AliEMCALSDigitizer)
 
@@ -83,34 +84,14 @@ ClassImp(AliEMCALSDigitizer)
 }
 
 //____________________________________________________________________________ 
-AliEMCALSDigitizer::AliEMCALSDigitizer(const char* headerFile, const char *sDigitsTitle):TTask("AliEMCALSDigitizer","")
+AliEMCALSDigitizer::AliEMCALSDigitizer(const char* headerFile, const char *sDigitsTitle):TTask(sDigitsTitle, headerFile)
 {
   // ctor
   fA = 0;
   fB = 10000000.;
   fPrimThreshold = 0.01 ;
-  fNevents = 0 ;      
-  fSDigitsTitle = sDigitsTitle ;
-  fHeadersFile = headerFile ;
-  fSDigits = new TClonesArray("AliEMCALDigit",30000);
-  fHits    = new TClonesArray("AliEMCALHit",1000);
-
-  TFile * file = (TFile*) gROOT->GetFile(fHeadersFile.Data() ) ;
-  
-  //File was not opened yet
-  if(file == 0){
-    if(fHeadersFile.Contains("rfio"))
-      file =   TFile::Open(fHeadersFile,"update") ;
-    else
-      file = new TFile(fHeadersFile.Data(),"update") ;
-    gAlice = (AliRun *) file->Get("gAlice") ;
-  }
-  
-  //add Task to //root/Tasks folder
-  TTask * roottasks = (TTask*)gROOT->GetRootFolder()->FindObject("Tasks") ; 
-  roottasks->Add(this) ; 
-  
-  fIsInitialized = kTRUE ;
+  fNevents = 0 ; 
+  Init();
 }
 
 //____________________________________________________________________________ 
@@ -124,76 +105,98 @@ AliEMCALSDigitizer::~AliEMCALSDigitizer()
 }
 //____________________________________________________________________________ 
 void AliEMCALSDigitizer::Init(){
-  //Initialization can not be done in the default constructor
 
-  if(!fIsInitialized){
+  // Initialization: open root-file, allocate arrays for hits and sdigits,
+  // attach task SDigitizer to the list of PHOS tasks
+  // 
+  // Initialization can not be done in the default constructor
+  //============================================================= YS
+  //  The initialisation is now done by the getter
 
-    if(fHeadersFile.IsNull())
-      fHeadersFile="galice.root" ;
+if( strcmp(GetTitle(), "") == 0 )
+    SetTitle("galice.root") ;
+  
+  AliEMCALGetter * gime = AliEMCALGetter::GetInstance(GetTitle(), GetName(), "update") ;     
+  if ( gime == 0 ) {
+    cerr << "ERROR: AliEMCALSDigitizer::Init -> Could not obtain the Getter object !" << endl ; 
+    return ;
+  } 
+  
+  gime->PostSDigits( GetName(), GetTitle() ) ; 
 
-    TFile * file = (TFile*) gROOT->GetFile(fHeadersFile.Data() ) ;
-    
-    //if file was not opened yet, read gAlice
-    if(file == 0){
-      file = new TFile(fHeadersFile.Data(),"update") ;
-      gAlice = (AliRun *) file->Get("gAlice") ;
-    }
-    
-    fHits    = new TClonesArray("AliEMCALHit",1000);
-    fSDigits = new TClonesArray("AliEMCALDigit",30000);
-    
-    // add Task to //root/Tasks folder
-    TTask * roottasks = (TTask*)gROOT->GetRootFolder()->FindObject("Tasks") ; 
-    roottasks->Add(this) ; 
-    
-    fIsInitialized = kTRUE ;
-  }
-}
+  TString sdname(GetName() );
+  sdname.Append(":") ;
+  sdname.Append(GetTitle() ) ;
+  SetName(sdname) ;
+  gime->PostSDigitizer(this) ;
+  // create a folder on the white board //YSAlice/WhiteBoard/SDigits/EMCAL/headerFile/sdigitsTitle
+ }
 //____________________________________________________________________________
 void AliEMCALSDigitizer::Exec(Option_t *option) { 
-  //Collects all hits in the same active volume into digit
-  
-  if(!fIsInitialized)
-    Init() ;
 
-  if(strstr(option,"tim"))
-    gBenchmark->Start("EMCALSDigitizer");
+// Collects all hits in the same active volume into digit
+  if( strcmp(GetName(), "") == 0 )
+    Init() ;
   
-  fNevents = (Int_t) gAlice->TreeE()->GetEntries() ; 
+  if (strstr(option, "print") ) {
+    Print("") ; 
+    return ; 
+  }
   
-  Int_t ievent ;
-  for(ievent = 0; ievent < fNevents; ievent++){
-    gAlice->GetEvent(ievent) ;
-    gAlice->SetEvent(ievent) ;
-    
-    if(gAlice->TreeH()==0){
-      cout << "AliEMCALSDigitizer: There is no Hit Tree" << endl;
-      return ;
-    }
+  if(strstr(option,"tim"))
+    gBenchmark->Start("EMCALSDigitizer");
+  //Check, if this branch already exits
+  gAlice->GetEvent(0) ;
+  if(gAlice->TreeS() ) {
+    TObjArray * lob = static_cast<TObjArray*>(gAlice->TreeS()->GetListOfBranches()) ;
+    TIter next(lob) ; 
+    TBranch * branch = 0 ;  
+    Bool_t emcalfound = kFALSE, sdigitizerfound = kFALSE ; 
     
-    //set address of the hits 
-    TBranch * branch = gAlice->TreeH()->GetBranch("EMCAL");
-    if (branch) 
-      branch->SetAddress(&fHits);
-    else{
-      cout << "ERROR in AliEMCALSDigitizer: "<< endl ;
-      cout << "      no branch EMCAL in TreeH"<< endl ;
-      cout << "      do nothing " << endl ;
-      return ;
+    while ( (branch = (static_cast<TBranch*>(next()))) && (!emcalfound || !sdigitizerfound) ) {
+      if ( (strcmp(branch->GetName(), "EMCAL")==0) && (strcmp(branch->GetTitle(), GetName())==0) ) 
+       emcalfound = kTRUE ;
+      
+      else if ( (strcmp(branch->GetName(), "AliEMCALSDigitizer")==0) && (strcmp(branch->GetTitle(), GetName())==0) ) 
+       sdigitizerfound = kTRUE ; 
     }
     
-    fSDigits->Clear();
+    if ( emcalfound || sdigitizerfound ) {
+      cerr << "WARNING: AliEMCALSDigitizer::Exec -> SDigits and/or SDigitizer branch with name " << GetName() 
+          << " already exits" << endl ;
+      return ; 
+    }   
+  }  
+  TString sdname(GetName()) ;
+  sdname.Remove(sdname.Index(GetTitle())-1) ;
+  AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;  
+  const AliEMCALGeometry *geom = gime->EMCALGeometry();
+  Int_t nevents = (Int_t) gAlice->TreeE()->GetEntries() ; 
+  
+  Int_t ievent ;
+  for(ievent = 0; ievent < nevents; ievent++){
+    gime->Event(ievent,"H") ;
+    const TClonesArray * fHits = gime->Hits() ;
+    TClonesArray * sdigits = gime->SDigits(sdname.Data()) ;
+    sdigits->Clear();
     Int_t nSdigits = 0 ;
+
+  //Collects all hits in the same active volume into digit
+  
+  
     
     
     //Now made SDigits from hits, for EMCAL it is the same, so just copy    
-    Int_t itrack ;
-    for (itrack=0; itrack < gAlice->GetNtrack(); itrack++){
-      
+    //  Int_t itrack ;
+    // for (itrack=0; itrack < gAlice->GetNtrack(); itrack++){
+    //gime->Track(itrack);  
       //=========== Get the EMCAL branch from Hits Tree for the Primary track itrack
-      branch->GetEntry(itrack,0);
-      AliEMCALv0 * EMCAL = (AliEMCALv0 *) gAlice->GetDetector("EMCAL") ;
-      AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance( EMCAL->GetGeometry()->GetName(), EMCAL->GetGeometry()->GetTitle() );
+      
+      
+
  
       Int_t i;
       for ( i = 0 ; i < fHits->GetEntries() ; i++ ) {
@@ -201,147 +204,136 @@ void AliEMCALSDigitizer::Exec(Option_t *option) {
         AliEMCALDigit  * curSDigit = 0  ;
         AliEMCALDigit * sdigit ;
         Bool_t newsdigit = kTRUE; 
-// Assign primary number only if contribution is significant
+       // Assign primary number only if contribution is significant
         if( hit->GetEnergy() > fPrimThreshold)
-   curSDigit =  new AliEMCALDigit( hit->GetPrimary(), hit->GetIparent(), (((hit->GetId()/geom->GetNPhi())%geom->GetNZ()+1 ) * ((hit->GetId()-1)%(geom->GetNPhi())+1)), Digitize( hit->GetEnergy() ) ) ;
+         curSDigit =  new AliEMCALDigit( hit->GetPrimary(),
+                                         hit->GetIparent(),Layer2TowerID(hit->GetId(),kFALSE), 
+                                         Digitize( hit->GetEnergy() ) , 
+                                         hit->GetTime()) ;
         else
-   curSDigit =  new AliEMCALDigit( -1               , -1               ,(((hit->GetId()/geom->GetNPhi())%geom->GetNZ() + 1 ) * ((hit->GetId()-1)%(geom->GetNPhi())+1)), Digitize( hit->GetEnergy() ) ) ;
-     //cout << "Hit ID = " <<hit->GetId() << endl ; 
-     //cout << "ID for detector = " << curSDigit->GetId() << endl ;  
-         //  cout << hit->GetEnergy() << " - hit energy   -   Digit Energy - " << curSDigit->GetAmp() << endl;
-      for(Int_t check= 0; check < nSdigits ; check++) {
-          sdigit = (AliEMCALDigit *)fSDigits->At(check);
+         curSDigit =  new AliEMCALDigit( -1               , 
+                                         -1               ,
+                                         Layer2TowerID(hit->GetId(),kFALSE), 
+                                         Digitize( hit->GetEnergy() ) , 
+                                         hit->GetTime() ) ;
+       //cout << "Hit ID = " <<hit->GetId() << endl ; 
+       //cout << "ID for detector = " << curSDigit->GetId() << endl ;  
+       //  cout << hit->GetEnergy() << " - hit energy   -   Digit Energy - " << curSDigit->GetAmp() << endl;
+       for(Int_t check= 0; check < nSdigits ; check++) {
+          sdigit = (AliEMCALDigit *)sdigits->At(check);
           if( sdigit->GetId() == curSDigit->GetId())   
             {// cout << "SDigit - Get Amp  " << sdigit->GetAmp() << endl ; 
-             *sdigit = *sdigit + *curSDigit ;
+             *sdigit = *sdigit + *curSDigit ;
               newsdigit = kFALSE;
-          //  cout << " and after addition " << sdigit->GetAmp() << endl ; 
-           }
-          }
-     if (newsdigit) 
-         { new((*fSDigits)[nSdigits])  AliEMCALDigit(*curSDigit);
+             //  cout << " and after addition " << sdigit->GetAmp() << endl ; 
+           }
+       }
+       if (newsdigit) 
+         { new((*sdigits)[nSdigits])  AliEMCALDigit(*curSDigit);
          nSdigits++ ;  
-       //cout << "Detector nsdigits = " << nSdigits << endl ;
-             }
+         //cout << "Detector nsdigits = " << nSdigits << endl ;
+         }
         newsdigit = kTRUE;  
-         
-
+       
+       
         if( hit->GetEnergy() > fPrimThreshold)
-      curSDigit =  new AliEMCALDigit( hit->GetPrimary(), hit->GetIparent(), ((geom->GetNZ() * geom->GetNPhi()) + ((hit->GetId()/geom->GetNPhi())%geom->GetNZ() + 1) * ((hit->GetId()-1)%(geom->GetNPhi())+1)), Digitize( hit->GetEnergy() ) ) ;
+         curSDigit =  new AliEMCALDigit( hit->GetPrimary(), 
+                                         hit->GetIparent(),
+                                         Layer2TowerID(hit->GetId(),kTRUE) , 
+                                         Digitize( hit->GetEnergy() ), 
+                                         hit->GetTime( ) ) ;
         else
-    curSDigit =  new AliEMCALDigit( -1               , -1               ,((geom->GetNZ() * geom->GetNPhi()) + ((hit->GetId()/geom->GetNPhi())%geom->GetNZ()+1) * ((hit->GetId()-1)%(geom->GetNPhi())+1)), Digitize( hit->GetEnergy() ) ) ;
-      if((hit->GetId()/geom->GetNPhi()) < (2*geom->GetNZ())) 
-       { //cout << "ID for Preshower = " << curSDigit->GetId()  << endl ;
-        for(Int_t check= 0; check < nSdigits; check++) {
-          sdigit = (AliEMCALDigit *)fSDigits->At(check);
-          if( sdigit->GetId() == curSDigit->GetId())   
-           { 
-             *sdigit = *sdigit + *curSDigit ;
-             newsdigit = kFALSE ;
-            }
-           }
-     if (newsdigit) 
-         { new((*fSDigits)[nSdigits])  AliEMCALDigit(*curSDigit);
-         nSdigits++ ;  
-       //cout << "Preshower nsdigits = " << nSdigits << endl ;
-           }
-        newsdigit=kTRUE;       
+         curSDigit =  new AliEMCALDigit( -1               , 
+                                         -1               ,
+                                         Layer2TowerID(hit->GetId(),kTRUE), 
+                                         Digitize( hit->GetEnergy() ), 
+                                         hit->GetTime() ) ;
+       
+       if((hit->GetId()/geom->GetNPhi()) < (2*geom->GetNZ())) 
+         { //cout << "ID for Preshower = " << curSDigit->GetId()  << endl ;
+           for(Int_t check= 0; check < nSdigits; check++) {
+             sdigit = (AliEMCALDigit *)sdigits->At(check);
+             if( sdigit->GetId() == curSDigit->GetId())   
+               { 
+                 *sdigit = *sdigit + *curSDigit ;
+                 newsdigit = kFALSE ;
+               }
+           }
+           if (newsdigit) 
+             { new((*sdigits)[nSdigits])  AliEMCALDigit(*curSDigit);
+             nSdigits++ ;  
+             //cout << "Preshower nsdigits = " << nSdigits << endl ;
+             }
+           newsdigit=kTRUE;    
+         } 
       } 
-     } 
-    } // loop over tracks
-    fSDigits->Sort() ;
-    
-    nSdigits = fSDigits->GetEntriesFast() ;
-    fSDigits->Expand(nSdigits) ;
-    
-    Int_t i ;
-    for (i = 0 ; i < nSdigits ; i++) { 
-      AliEMCALDigit * digit = (AliEMCALDigit *) fSDigits->At(i) ; 
-      digit->SetIndexInList(i) ;     
-    }
-
-    if(gAlice->TreeS() == 0)
-      gAlice->MakeTree("S") ;
-    
-    //check, if this branch already exits?
-    TBranch * sdigitsBranch = 0;
-    TBranch * sdigitizerBranch = 0;
-    
-    TObjArray * branches = gAlice->TreeS()->GetListOfBranches() ;
-    Int_t ibranch;
-    Bool_t emcalNotFound = kTRUE ;
-    Bool_t sdigitizerNotFound = kTRUE ;
-    
-    for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){
+      //    } // loop over tracks
+      sdigits->Sort() ;
       
-      if(emcalNotFound){
-       sdigitsBranch=(TBranch *) branches->At(ibranch) ;
-       if( (strcmp("EMCAL",sdigitsBranch->GetName())==0 ) &&
-           (fSDigitsTitle.CompareTo(sdigitsBranch->GetTitle()) == 0) )
-         emcalNotFound = kFALSE ;
+      nSdigits = sdigits->GetEntriesFast() ;
+      sdigits->Expand(nSdigits) ;
+      
+      //  Int_t i ;
+      for (i = 0 ; i < nSdigits ; i++) { 
+       AliEMCALDigit * digit = (AliEMCALDigit *) sdigits->At(i) ; 
+       digit->SetIndexInList(i) ;     
       }
-      if(sdigitizerNotFound){
-       sdigitizerBranch = (TBranch *) branches->At(ibranch) ;
-       if( (strcmp(sdigitizerBranch->GetName(),"AliEMCALSDigitizer") == 0)&&
-           (fSDigitsTitle.CompareTo(sdigitizerBranch->GetTitle()) == 0) )
-         sdigitizerNotFound = kFALSE ;
+      
+      if(gAlice->TreeS() == 0)
+       gAlice->MakeTree("S") ;
+      
+      
+      
+      
+      //Make (if necessary) branches    
+      char * file =0;
+      if(gSystem->Getenv("CONFIG_SPLIT_FILE")){ //generating file name
+       file = new char[strlen(gAlice->GetBaseFile())+20] ;
+       sprintf(file,"%s/EMCAL.SDigits.root",gAlice->GetBaseFile()) ;
       }
-    }
-
-    if(!(sdigitizerNotFound && emcalNotFound)){
-      cout << "AliEMCALSdigitizer error:" << endl ;
-      cout << "Can not overwrite existing branches: do not write" << endl ;
-      return ;
-    }
-    
-    //Make (if necessary) branches    
-    char * file =0;
-    if(gSystem->Getenv("CONFIG_SPLIT_FILE")){ //generating file name
-      file = new char[strlen(gAlice->GetBaseFile())+20] ;
-      sprintf(file,"%s/EMCAL.SDigits.root",gAlice->GetBaseFile()) ;
-    }
-    
-    TDirectory *cwd = gDirectory;
-    
-    //First list of sdigits
-    Int_t bufferSize = 32000 ;    
-    sdigitsBranch = gAlice->TreeS()->Branch("EMCAL",&fSDigits,bufferSize);
-    sdigitsBranch->SetTitle(fSDigitsTitle.Data());
-    if (file) {
-      sdigitsBranch->SetFile(file);
-      TIter next( sdigitsBranch->GetListOfBranches());
-      TBranch * subbr;
-      while ((subbr=(TBranch*)next())) {
-       subbr->SetFile(file);
-      }   
-      cwd->cd();
-    } 
       
-    //second - SDigitizer
-    Int_t splitlevel = 0 ;
-    AliEMCALSDigitizer * sd = this ;
-    sdigitizerBranch = gAlice->TreeS()->Branch("AliEMCALSDigitizer","AliEMCALSDigitizer",
-                                              &sd,bufferSize,splitlevel); 
-    sdigitizerBranch->SetTitle(fSDigitsTitle.Data());
-    if (file) {
-      sdigitizerBranch->SetFile(file);
-      TIter next( sdigitizerBranch->GetListOfBranches());
-      TBranch * subbr ;
-      while ((subbr=(TBranch*)next())) {
-       subbr->SetFile(file);
-      }   
-      cwd->cd();
-      delete file;
-    }
-
-    sdigitsBranch->Fill() ;
-    sdigitizerBranch->Fill() ;
-    gAlice->TreeS()->Write(0,TObject::kOverwrite) ;
-    
-    if(strstr(option,"deb"))
-      PrintSDigits(option) ;
-    
+      TDirectory *cwd = gDirectory;
+      
+      //First list of sdigits
+      Int_t bufferSize = 32000 ;    
+      TBranch * sdigitsBranch = gAlice->TreeS()->Branch("EMCAL",&sdigits,bufferSize);
+      sdigitsBranch->SetTitle(sdname);
+      cout << " AliEMCALSDigitizer::Exec sdname " << sdname << endl ; 
+      
+      if (file) {
+       sdigitsBranch->SetFile(file);
+       TIter next( sdigitsBranch->GetListOfBranches());
+       TBranch * subbr;
+       while ((subbr=(TBranch*)next())) {
+         subbr->SetFile(file);
+       }   
+       cwd->cd();
+      } 
+      
+      //second - SDigitizer
+      Int_t splitlevel = 0 ;
+      AliEMCALSDigitizer * sd = this ;
+      TBranch * sdigitizerBranch = gAlice->TreeS()->Branch("AliEMCALSDigitizer","AliEMCALSDigitizer",
+                                                          &sd,bufferSize,splitlevel); 
+      sdigitizerBranch->SetTitle(sdname);
+      if (file) {
+       sdigitizerBranch->SetFile(file);
+       TIter next( sdigitizerBranch->GetListOfBranches());
+       TBranch * subbr ;
+       while ((subbr=(TBranch*)next())) {
+         subbr->SetFile(file);
+       }   
+       cwd->cd();
+       delete file;
+      }
+      
+      sdigitsBranch->Fill() ;
+      sdigitizerBranch->Fill() ;
+      gAlice->TreeS()->Write(0,TObject::kOverwrite) ;
+      
+      if(strstr(option,"deb"))
+       PrintSDigits(option) ;
+      
   }
   
   if(strstr(option,"tim")){
@@ -356,15 +348,37 @@ void AliEMCALSDigitizer::Exec(Option_t *option) {
 }
 //__________________________________________________________________
 void AliEMCALSDigitizer::SetSDigitsBranch(const char * title ){
-  //Seting title to branch SDigits 
-  if(!fSDigitsTitle.IsNull())
-    cout << "AliEMCALSdigitizer: changing SDigits file from " <<fSDigitsTitle.Data() << " to " << title << endl ;
-  fSDigitsTitle=title ;
+  // Setting title to branch SDigits 
+
+  TString stitle(title) ;
+
+  // check if branch with title already exists
+  TBranch * sdigitsBranch    = 
+    static_cast<TBranch*>(gAlice->TreeS()->GetListOfBranches()->FindObject("EMCAL")) ; 
+  TBranch * sdigitizerBranch =  
+    static_cast<TBranch*>(gAlice->TreeS()->GetListOfBranches()->FindObject("AliEMCALSDigitizer")) ;
+  const char * sdigitsTitle    = sdigitsBranch ->GetTitle() ;  
+  const char * sdigitizerTitle = sdigitizerBranch ->GetTitle() ;
+  if ( stitle.CompareTo(sdigitsTitle)==0 || stitle.CompareTo(sdigitizerTitle)==0 ){
+    cerr << "ERROR: AliEMCALSdigitizer::SetSDigitsBranch -> Cannot overwrite existing branch with title " << title << endl ;
+    return ;
+  }
+  
+  cout << "AliEMCALSdigitizer::SetSDigitsBranch -> Changing SDigits file from " << GetName() << " to " << title << endl ;
+
+  SetName(title) ; 
+    
+  // Post to the WhiteBoard
+  AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ; 
+  gime->PostSDigits( title, GetTitle()) ; 
+
+
 }
 //__________________________________________________________________
 void AliEMCALSDigitizer::Print(Option_t* option)const{
   cout << "------------------- "<< GetName() << " -------------" << endl ;
-  cout << "   Writing SDigitis to branch with title  " << fSDigitsTitle.Data() << endl ;
+  cout << "   Writing SDigitis to branch with title  " << GetName() << endl ;
   cout << "   with digitization parameters  A = " << fA << endl ;
   cout << "                                 B = " << fB << endl ;
   cout << "   Threshold for Primary assignment= " << fPrimThreshold << endl ; 
@@ -382,27 +396,50 @@ Bool_t AliEMCALSDigitizer::operator==( AliEMCALSDigitizer const &sd )const{
 void AliEMCALSDigitizer::PrintSDigits(Option_t * option){
   //Prints list of digits produced at the current pass of AliEMCALDigitizer
   
-  cout << "AliEMCALSDigitizer: " << endl ;
-  cout << "       Number of entries in SDigits list  " << fSDigits->GetEntriesFast() << endl ;
-  cout << endl ;
+  AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ; 
+  TString sdname(GetName()) ;
+  sdname.Remove(sdname.Index(GetTitle())-1) ;
+  const TClonesArray * sdigits = gime->SDigits(sdname.Data()) ; 
   
-  if(strstr(option,"all")){// print all digits
-    
+  cout << "AliEMCALSDigitiser: event " << gAlice->GetEvNumber() << endl ;
+  cout << "      Number of entries in SDigits list " << sdigits->GetEntriesFast() << endl ;
+  cout << endl ;
+  if(strstr(option,"all")||strstr(option,"EMC")){
+
     //loop over digits
     AliEMCALDigit * digit;
-    cout << "SDigit Id " << " Amplitude " <<  " Index "  <<  " Nprim " << " Primaries list " <<  endl;    
+    cout << "SDigit Id " << " Amplitude " <<  " Time " << " Index "  <<  " Nprim " << " Primaries list " <<  endl;    
     Int_t index ;
-    for (index = 0 ; index < fSDigits->GetEntries() ; index++) {
-      digit = (AliEMCALDigit * )  fSDigits->At(index) ;
-      cout << setw(8)  <<  digit->GetId() << " "  <<   setw(3)  <<  digit->GetAmp() <<   "  "  
-          << setw(6)  <<  digit->GetIndexInList() << "  "   
-          << setw(5)  <<  digit->GetNprimary() <<"  ";
+    for (index = 0 ; index < sdigits->GetEntries() ; index++) {
+      digit = (AliEMCALDigit * )  sdigits->At(index) ;
+      cout << setw(6)  <<  digit->GetId() << "   "  <<         setw(10)  <<  digit->GetAmp() <<   "    "  << digit->GetTime()
+          << setw(6)  <<  digit->GetIndexInList() << "    "   
+          << setw(5)  <<  digit->GetNprimary() <<"    ";
       
       Int_t iprimary;
       for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++)
-       cout << setw(5)  <<  digit->GetPrimary(iprimary+1) << "  ";
+       cout << " "  <<  digit->GetPrimary(iprimary+1) << "  ";
       cout << endl;     
     }
-    
+    cout <<endl;
   }
 }
+//________________________________________________________________________
+Int_t AliEMCALSDigitizer::Layer2TowerID(Int_t s, Bool_t preshower)
+{
+  AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
+  const AliEMCALGeometry * geom = gime->EMCALGeometry();
+  Int_t a  = (s/geom->GetNPhi())%geom->GetNZ()+1; // Phi Tower Index
+  Int_t b = (s-1)%(geom->GetNPhi())+1; //Eta Tower Index
+  Int_t t = -10;
+
+if (a > 0 && b > 0)
+{
+  t = a*b + preshower*geom->GetNPhi()*geom->GetNZ();
+  return t;
+}
+else
+{cerr << " AliEMCALSDigitizer::Layer2TowerID() -- there is an error "<< endl << "Phi number = "
+      << b << "Eta number = " << a << endl ;
+return t;}
+}
index 51f7936df26f2f0dd578b4ba679079a15640588f..b0daf13f998944c0245697502904aa21ec917888 100644 (file)
@@ -47,12 +47,12 @@ public:
 private:
   void     Init() ;
   void     PrintSDigits(Option_t * option) ;
-
+  Int_t    Layer2TowerID(Int_t,Bool_t) ;
 private:
   Float_t fA ;              //Pedestal parameter
   Float_t fB ;              //Slope Digitizition parameters
   Int_t   fNevents ;        // Number of events to digitize
-  Float_t fPrimThreshold ;  // To store primari if Elos > threshold
+  Float_t fPrimThreshold ;  // To store primary if Elos > threshold
   TString fSDigitsTitle ;   // title of SDigits branch
   TString fHeadersFile ;    //input file
   Bool_t         fIsInitialized ;