]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EMCAL/AliEMCALGetter.cxx
Logging message with AliLog
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALGetter.cxx
index 66bb000368aeab975f7ba2e9ce73d492eb03be34..7543cda1bfdad762fcb9504f5ed878c1e63e78ba 100644 (file)
 
 // --- ROOT system ---
 
-#include "TSystem.h"
-#include "TFile.h"
-// #include "TTree.h"
-#include "TROOT.h"
-// #include "TObjString.h"
-// #include "TFolder.h"
-// #include "TParticle.h"
+#include <TFile.h>
+#include <TROOT.h>
+#include <TSystem.h>
+#include <TF1.h>
+#include <TGraph.h>
+//#include <TCanvas.h>
+//#include <TFrame.h>
 
 // --- Standard library ---
 
 // --- AliRoot header files ---
-// #include "AliRun.h"
-// #include "AliConfig.h"
+
+#include "AliEMCAL.h"
 #include "AliEMCALGetter.h"
+#include "AliEMCALLoader.h"
+#include "AliHeader.h"  
+#include "AliMC.h"
 #include "AliRunLoader.h"
 #include "AliStack.h"  
-#include "AliEMCALLoader.h"
+#include "AliEMCALRawStream.h"
+#include "AliRawReaderFile.h"
 
 ClassImp(AliEMCALGetter)
   
@@ -67,10 +71,7 @@ Int_t AliEMCALGetter::fgDebug = 0;
 //  TFile * AliEMCALGetter::fgFile = 0 ; 
 
 //____________________________________________________________________________ 
-AliEMCALGetter::AliEMCALGetter(const char* headerFile, const char* version, Option_t * openingOption)
-{
-  // ctor only called by Instance()
-
+AliEMCALGetter::AliEMCALGetter(const char* headerFile, const char* version, Option_t * openingOption) {
   AliRunLoader* rl = AliRunLoader::GetRunLoader(version) ; 
   if (!rl) {
     rl = AliRunLoader::Open(headerFile, version, openingOption);
@@ -82,36 +83,44 @@ AliEMCALGetter::AliEMCALGetter(const char* headerFile, const char* version, Opti
       rl->LoadgAlice();
       gAlice = rl->GetAliRun(); // should be removed
     }
-  }
+  } 
   fgEmcalLoader = dynamic_cast<AliEMCALLoader*>(rl->GetLoader("EMCALLoader"));
   if ( !fgEmcalLoader ) 
     Error("AliEMCALGetter", "Could not find EMCALLoader") ; 
   else 
     fgEmcalLoader->SetTitle(version);
-  
-  
-  // initialize data members
+
+   // initialize data members
   SetDebug(0) ; 
-  //fBTE = 0 ; 
-  fPrimaries = 0 ; 
   fLoadingStatus = "" ; 
+
 }
 
 //____________________________________________________________________________ 
 AliEMCALGetter::~AliEMCALGetter()
 {
-  // dtor
-  delete fgEmcalLoader ;
-  fgEmcalLoader = 0 ;
-  //delete fBTE ; 
-  // fBTE = 0 ; 
-  fPrimaries->Delete() ; 
-  delete fPrimaries ; 
+  if (fgEmcalLoader) {
+    delete fgEmcalLoader;
+    fgEmcalLoader = 0 ;
+  }
+  fgObjGetter = 0;
+}
+
+
+//____________________________________________________________________________ 
+void AliEMCALGetter::Reset()
+{
+  // resets things in case the getter is called consecutively with different files
+  // the EMCAL Loader is already deleted by the Run Loader
+  fgEmcalLoader = 0;
+  fgObjGetter = 0;
+
 }
 
 //____________________________________________________________________________ 
 AliEMCALClusterizer * AliEMCALGetter::Clusterizer()
 { 
+  // return pointer to Clusterizer Tree
   AliEMCALClusterizer * rv ; 
   rv =  dynamic_cast<AliEMCALClusterizer *>(EmcalLoader()->Reconstructioner()) ;
   if (!rv) {
@@ -123,7 +132,7 @@ AliEMCALClusterizer * AliEMCALGetter::Clusterizer()
 
 
 //____________________________________________________________________________ 
-TClonesArray * AliEMCALGetter::Digits() 
+TClonesArray * AliEMCALGetter::Digits() const  
 {
   // asks the Loader to return the Digits container 
 
@@ -140,6 +149,7 @@ TClonesArray * AliEMCALGetter::Digits()
 //____________________________________________________________________________ 
 AliEMCALDigitizer * AliEMCALGetter::Digitizer() 
 { 
+  // return pointer to Digitizer Tree
   AliEMCALDigitizer * rv ; 
   rv =  dynamic_cast<AliEMCALDigitizer *>(EmcalLoader()->Digitizer()) ;
   if (!rv) {
@@ -149,24 +159,8 @@ AliEMCALDigitizer * AliEMCALGetter::Digitizer()
   return rv ; 
 }
 
-
 //____________________________________________________________________________ 
-TObjArray * AliEMCALGetter::PRERecPoints() 
-{
-  // asks the Loader to return the EMC RecPoints container 
-
-  TObjArray * rv = 0 ; 
-  
-  rv = EmcalLoader()->PRERecPoints() ; 
-  if (!rv) {
-    EmcalLoader()->MakeRecPointsArray() ;
-    rv = EmcalLoader()->PRERecPoints() ; 
-  }
-  return rv ; 
-}
-
-//____________________________________________________________________________ 
-TObjArray * AliEMCALGetter::ECARecPoints() 
+TObjArray * AliEMCALGetter::ECARecPoints() const 
 {
   // asks the Loader to return the EMC RecPoints container 
 
@@ -181,22 +175,7 @@ TObjArray * AliEMCALGetter::ECARecPoints()
 }
 
 //____________________________________________________________________________ 
-TObjArray * AliEMCALGetter::HCARecPoints() 
-{
-  // asks the Loader to return the EMC RecPoints container 
-
-  TObjArray * rv = 0 ; 
-  
-  rv = EmcalLoader()->HCARecPoints() ; 
-  if (!rv) {
-    EmcalLoader()->MakeRecPointsArray() ;
-    rv = EmcalLoader()->HCARecPoints() ; 
-  }
-  return rv ; 
-}
-
-//____________________________________________________________________________ 
-TClonesArray * AliEMCALGetter::TrackSegments() 
+TClonesArray * AliEMCALGetter::TrackSegments() const 
 {
   // asks the Loader to return the TrackSegments container 
 
@@ -213,6 +192,7 @@ TClonesArray * AliEMCALGetter::TrackSegments()
 //____________________________________________________________________________ 
 AliEMCALTrackSegmentMaker * AliEMCALGetter::TrackSegmentMaker() 
 { 
+  // return pointer to TrackSegmentMaker Tree
   AliEMCALTrackSegmentMaker * rv ; 
   rv =  dynamic_cast<AliEMCALTrackSegmentMaker *>(EmcalLoader()->TrackSegmentMaker()) ;
   if (!rv) {
@@ -223,7 +203,7 @@ AliEMCALTrackSegmentMaker * AliEMCALGetter::TrackSegmentMaker()
 }
 
 //____________________________________________________________________________ 
-TClonesArray * AliEMCALGetter::RecParticles() 
+TClonesArray * AliEMCALGetter::RecParticles() const  
 {
   // asks the Loader to return the TrackSegments container 
 
@@ -237,17 +217,16 @@ TClonesArray * AliEMCALGetter::RecParticles()
   return rv ; 
 }
 //____________________________________________________________________________ 
-void AliEMCALGetter::Event(const Int_t event, const char* opt) 
+void AliEMCALGetter::Event(Int_t event, const char* opt) 
 {
   // Reads the content of all Tree's S, D and R
 
-  if ( event >= MaxEvent() ) {
-    Error("Event", "%d not found in TreeE !", event) ; 
-    return ; 
-  }
+//   if ( event >= MaxEvent() ) {
+//     Error("Event", "%d not found in TreeE !", event) ; 
+//     return ; 
+//   }
 
   AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
-
   // checks if we are dealing with test-beam data
 //   TBranch * btb = rl->TreeE()->GetBranch("AliEMCALBeamTestEvent") ;
 //   if(btb){
@@ -288,9 +267,9 @@ void AliEMCALGetter::Event(const Int_t event, const char* opt)
   if( strstr(opt,"P") )
     ReadTreeP() ;
 
-//   if( strstr(opt,"Q") )
-//     ReadTreeQA() ;
+  if( strstr(opt,"W") )
+    ReadRaw(event) ;
+  
 }
 
 
@@ -303,7 +282,7 @@ Int_t AliEMCALGetter::EventNumber() const
 }
 
 //____________________________________________________________________________ 
-  TClonesArray * AliEMCALGetter::Hits()  
+  TClonesArray * AliEMCALGetter::Hits() const   
 {
   // asks the loader to return  the Hits container 
   
@@ -322,9 +301,7 @@ AliEMCALGetter * AliEMCALGetter::Instance(const char* alirunFileName, const char
 {
   // Creates and returns the pointer of the unique instance
   // Must be called only when the environment has changed
-  
-  //::Info("Instance","alirunFileName=%s version=%s openingOption=%s",alirunFileName,version,openingOption);
-  
+
   if(!fgObjGetter){ // first time the getter is called 
     fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
   }
@@ -335,7 +312,7 @@ AliEMCALGetter * AliEMCALGetter::Instance(const char* alirunFileName, const char
       TFile * galiceFile = dynamic_cast<TFile *>(gROOT->FindObject(rl->GetFileName()) ) ; 
       
       if ( !galiceFile ) 
-       fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
+       fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption);
       
       else {  // the file is already open check the version name
        TString currentVersionName = rl->GetEventFolder()->GetName() ; 
@@ -343,20 +320,24 @@ AliEMCALGetter * AliEMCALGetter::Instance(const char* alirunFileName, const char
        if (currentVersionName == newVersionName) 
          if(fgDebug)
            ::Warning( "Instance", "Files with version %s already open", currentVersionName.Data() ) ;  
-       else {
-         fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;      
+       else {    
+         fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ; 
        }
       }
     }
-    else 
+    else { 
+      AliRunLoader * rl = AliRunLoader::GetRunLoader(fgEmcalLoader->GetTitle());
+      if ( strstr(version, AliConfig::GetDefaultEventFolderName()) ) // false in case of merging
+       delete rl ; 
       fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;      
+    }
   }
   if (!fgObjGetter) 
-    ::Error("Instance", "Failed to create the EMCAL Getter object") ;
+    ::Error("AliEMCALGetter::Instance", "Failed to create the EMCAL Getter object") ;
   else 
     if (fgDebug)
       Print() ;
-  
+
   return fgObjGetter ;
 }
 
@@ -365,8 +346,8 @@ AliEMCALGetter *  AliEMCALGetter::Instance()
 {
   // Returns the pointer of the unique instance already defined
   
-  if(!fgObjGetter)
-     ::Error("Instance", "Getter not initialized") ;
+  if(!fgObjGetter && fgDebug)
+     ::Warning("AliEMCALGetter::Instance", "Getter not initialized") ;
 
    return fgObjGetter ;
            
@@ -388,11 +369,27 @@ TParticle * AliEMCALGetter::Primary(Int_t index) const
   return rl->Stack()->Particle(index) ; 
 } 
 
+//____________________________________________________________________________ 
+Int_t AliEMCALGetter::NPrimaries() const
+{
+  AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
+  return (rl->GetHeader())->GetNtrack(); 
+} 
+
 //____________________________________________________________________________ 
 AliEMCAL * AliEMCALGetter:: EMCAL() const  
 {
   // returns the EMCAL object 
-  AliEMCAL * emcal = dynamic_cast<AliEMCAL*>(EmcalLoader()->GetModulesFolder()->FindObject("EMCAL")) ;  
+  AliEMCALLoader *    loader = 0;
+  static AliEMCALLoader * oldloader = 0;
+  static AliEMCAL * emcal = 0;
+
+  loader = EmcalLoader();
+
+  if (loader != oldloader ) {
+    emcal = dynamic_cast<AliEMCAL*>(loader->GetModulesFolder()->FindObject("EMCAL")) ;  
+    oldloader = loader;
+  }
   if (!emcal) 
     if (fgDebug)
       Warning("EMCAL", "EMCAL module not found in module folders: %s", EmcalLoader()->GetModulesFolder()->GetName() ) ; 
@@ -404,6 +401,7 @@ AliEMCAL * AliEMCALGetter:: EMCAL() const
 //____________________________________________________________________________ 
 AliEMCALPID * AliEMCALGetter::PID() 
 { 
+  // return pointer to PID Tree
   AliEMCALPID * rv ; 
   rv =  dynamic_cast<AliEMCALPID *>(EmcalLoader()->PIDTask()) ;
   if (!rv) {
@@ -424,25 +422,13 @@ AliEMCALGeometry * AliEMCALGetter::EMCALGeometry() const
   return rv ; 
 } 
 
-//____________________________________________________________________________ 
-TClonesArray * AliEMCALGetter::Primaries()  
-{
-  // creates the Primaries container if needed
-  if ( !fPrimaries ) {
-    if (fgDebug) 
-      Info("Primaries", "Creating a new TClonesArray for primaries") ; 
-    fPrimaries = new TClonesArray("TParticle", 1000) ;
-  } 
-  return fPrimaries ; 
-}
-
 //____________________________________________________________________________ 
 void  AliEMCALGetter::Print() 
 {
   // Print usefull information about the getter
     
   AliRunLoader * rl = AliRunLoader::GetRunLoader(fgEmcalLoader->GetTitle());
-  ::Info( "Print", "gAlice file is %s -- version name is %s", (rl->GetFileName()).Data(), rl->GetEventFolder()->GetName() ) ; 
+  ::Info("Print", "gAlice file is %s -- version name is %s", (rl->GetFileName()).Data(), rl->GetEventFolder()->GetName() ) ; 
 }
 
 //____________________________________________________________________________ 
@@ -456,47 +442,202 @@ void AliEMCALGetter::ReadPrimaries()
   if ( ! rl->TreeK() )  // load treeK the first time
     rl->LoadKinematics() ;
   
-  fNPrimaries = rl->Stack()->GetNtrack() ; 
-
   if (fgDebug) 
-    Info( "ReadTreeK", "Found %d particles in event # %d", fNPrimaries, EventNumber() ) ; 
+    Info("ReadTreeK", "Found %d particles in event # %d", NPrimaries(), EventNumber() ) ; 
+}
+
+//____________________________________________________________________________ 
+void AliEMCALGetter::FitRaw(Bool_t lowGainFlag, TGraph * gLowGain, TGraph * gHighGain, TF1* signalF, Int_t & amp, Double_t & time)
+{
+  // Fits the raw signal time distribution 
 
+  const Int_t kNoiseThreshold = 0 ;
+  Double_t timezero1 = 0., timezero2 = 0., timemax = 0. ;
+  Double_t signal = 0., signalmax = 0. ;       
+  Double_t energy = time = 0. ; 
 
-  // first time creates the container
-  if ( Primaries() ) 
-    fPrimaries->Clear() ; 
+  if (lowGainFlag) {
+    timezero1 = timezero2 = signalmax = timemax = 0. ;
+    signalF->FixParameter(0, EMCAL()->GetRawFormatLowCharge()) ; 
+    signalF->FixParameter(1, EMCAL()->GetRawFormatLowGain()) ; 
+    Int_t index ; 
+    for (index = 0; index < EMCAL()->GetRawFormatTimeBins(); index++) {
+      gLowGain->GetPoint(index, time, signal) ; 
+      if (signal > kNoiseThreshold && timezero1 == 0.) 
+       timezero1 = time ;
+      if (signal <= kNoiseThreshold && timezero1 > 0. && timezero2 == 0.)
+       timezero2 = time ; 
+      if (signal > signalmax) {
+       signalmax = signal ; 
+       timemax   = time ; 
+      }
+    }
+    signalmax /= EMCAL()->RawResponseFunctionMax(EMCAL()->GetRawFormatLowCharge(), 
+                                               EMCAL()->GetRawFormatLowGain()) ;
+    if ( timezero1 + EMCAL()->GetRawFormatTimePeak() < EMCAL()->GetRawFormatTimeMax() * 0.4 ) { // else its noise 
+      signalF->SetParameter(2, signalmax) ; 
+      signalF->SetParameter(3, timezero1) ;                
+      gLowGain->Fit(signalF, "QRON", "", 0., timezero2); //, "QRON") ; 
+      energy = signalF->GetParameter(2) ; 
+      time   = signalF->GetMaximumX() - EMCAL()->GetRawFormatTimePeak() - EMCAL()->GetRawFormatTimeTrigger() ;
+    }
+  } else {
+    timezero1 = timezero2 = signalmax = timemax = 0. ;
+    signalF->FixParameter(0, EMCAL()->GetRawFormatHighCharge()) ; 
+    signalF->FixParameter(1, EMCAL()->GetRawFormatHighGain()) ; 
+    Int_t index ; 
+    for (index = 0; index < EMCAL()->GetRawFormatTimeBins(); index++) {
+      gHighGain->GetPoint(index, time, signal) ;               
+      if (signal > kNoiseThreshold && timezero1 == 0.) 
+       timezero1 = time ;
+      if (signal <= kNoiseThreshold && timezero1 > 0. && timezero2 == 0.)
+       timezero2 = time ; 
+      if (signal > signalmax) {
+       signalmax = signal ;   
+       timemax   = time ; 
+      }
+    }
+    signalmax /= EMCAL()->RawResponseFunctionMax(EMCAL()->GetRawFormatHighCharge(), 
+                                               EMCAL()->GetRawFormatHighGain()) ;;
+    if ( timezero1 + EMCAL()->GetRawFormatTimePeak() < EMCAL()->GetRawFormatTimeMax() * 0.4 ) { // else its noise  
+      signalF->SetParameter(2, signalmax) ; 
+      signalF->SetParameter(3, timezero1) ;               
+      gHighGain->Fit(signalF, "QRON", "", 0., timezero2) ; 
+      energy = signalF->GetParameter(2) ; 
+      time   = signalF->GetMaximumX() - EMCAL()->GetRawFormatTimePeak() - EMCAL()->GetRawFormatTimeTrigger() ;
+    }
+  }
   
-  Int_t index = 0 ; 
-  for (index = 0 ; index < fNPrimaries; index++) { 
-    new ((*fPrimaries)[index]) TParticle(*(Primary(index)));
+  if (time == 0. && energy == 0.) 
+    amp = 0 ; 
+  else {
+  AliEMCALDigitizer * digitizer = Digitizer() ; 
+  amp = static_cast<Int_t>( (energy - digitizer->GetECApedestal()) / digitizer->GetECAchannel() + 0.5 ) ; 
   }
-}
+  // dessin
+//   TCanvas * c1 = new TCanvas("c1","A Simple Graph Example",200,10,700,500);
+//   c1->SetFillColor(42);
+//   c1->SetGrid();
+//   gLowGain->SetLineColor(2);
+//   gLowGain->SetLineWidth(4);
+//   gLowGain->SetMarkerColor(4);
+//   gLowGain->SetMarkerStyle(21);
+//   gLowGain->SetTitle("Lowgain");
+//   gLowGain->GetXaxis()->SetTitle("X title");
+//   gLowGain->GetYaxis()->SetTitle("Y title");
+//   gLowGain->Draw("ACP");
+  
+//   c1->Update();
+//   c1->GetFrame()->SetFillColor(21);
+//   c1->GetFrame()->SetBorderSize(12);
+//   c1->Modified();
+  
+//   TCanvas * c2 = new TCanvas("c2","A Simple Graph Example",200,10,700,500);
+//   c2->SetFillColor(42);
+//   c2->SetGrid();
+//   gHighGain->SetLineColor(2);
+//   gHighGain->SetLineWidth(4);
+//   gHighGain->SetMarkerColor(4);
+//   gHighGain->SetMarkerStyle(21);
+//   gHighGain->SetTitle("Highgain");
+//   gHighGain->GetXaxis()->SetTitle("X title");
+//   gHighGain->GetYaxis()->SetTitle("Y title");
+//     gHighGain->Draw("ACP");
+  
+//   c2->Update();
+//   c2->GetFrame()->SetFillColor(21);
+//   c2->GetFrame()->SetBorderSize(12);
+//   c2->Modified();
+}
+
+//____________________________________________________________________________ 
+Int_t AliEMCALGetter::ReadRaw(Int_t event)
+{
+  // reads the raw format data, converts it into digits format and store digits in Digits()
+  // container.
+  
+  AliRawReaderFile rawReader(event) ; 
+  AliEMCALRawStream in(&rawReader);
+  
+  Bool_t first = kTRUE ;
+  TF1 * signalF = new TF1("signal", AliEMCAL::RawResponseFunction, 0, EMCAL()->GetRawFormatTimeMax(), 4);
+  signalF->SetParNames("Charge", "Gain", "Amplitude", "TimeZero") ; 
+  
+  Int_t id = -1;
+  Bool_t lowGainFlag = kFALSE ; 
+
+  TClonesArray * digits = Digits() ;
+  digits->Clear() ; 
+  Int_t idigit = 0 ; 
+  Int_t amp = 0 ; 
+  Double_t time = 0. ; 
+
+  TGraph * gLowGain = new TGraph(EMCAL()->GetRawFormatTimeBins()) ; 
+  TGraph * gHighGain= new TGraph(EMCAL()->GetRawFormatTimeBins()) ;  
+
+  while ( in.Next() ) { // EMCAL entries loop 
+    if ( in.IsNewId() ) {
+      if (!first) {
+       FitRaw(lowGainFlag, gLowGain, gHighGain, signalF, amp, time) ; 
+       if (amp > 0) {
+         new((*digits)[idigit]) AliEMCALDigit( -1, -1, id, amp, time) ;        
+         idigit++ ; 
+       }
+       Int_t index ; 
+       for (index = 0; index < EMCAL()->GetRawFormatTimeBins(); index++) {
+         gLowGain->SetPoint(index, index * EMCAL()->GetRawFormatTimeMax() / EMCAL()->GetRawFormatTimeBins(), 0) ;  
+         gHighGain->SetPoint(index, index * EMCAL()->GetRawFormatTimeMax() / EMCAL()->GetRawFormatTimeBins(), 0) ; 
+       } 
+      }  
+      first = kFALSE ; 
+      id = in.GetId() ; 
+      if (in.GetModule() == EMCAL()->GetRawFormatLowGainOffset() ) 
+       lowGainFlag = kTRUE ; 
+      else 
+       lowGainFlag = kFALSE ; 
+    }
+    if (lowGainFlag)
+      gLowGain->SetPoint(in.GetTime(), 
+                        in.GetTime()* EMCAL()->GetRawFormatTimeMax() / EMCAL()->GetRawFormatTimeBins(), 
+                        in.GetSignal()) ;
+    else 
+      gHighGain->SetPoint(in.GetTime(), 
+                         in.GetTime() * EMCAL()->GetRawFormatTimeMax() / EMCAL()->GetRawFormatTimeBins(), 
+                         in.GetSignal() ) ;
+    
+  } // EMCAL entries loop
+  digits->Sort() ; 
 
-//____________________________________________________________________________ 
+  delete signalF ; 
+  delete gLowGain;
+  delete gHighGain ; 
+    
+  return Digits()->GetEntriesFast() ; 
+}
+  
+  //____________________________________________________________________________ 
 Int_t AliEMCALGetter::ReadTreeD()
 {
   // Read the Digits
   
-  
-  // gets TreeD from the root file (EMCAL.SDigits.root)
-  if ( !IsLoaded("D") ) {
-    EmcalLoader()->LoadDigits("UPDATE") ;
-    EmcalLoader()->LoadDigitizer("UPDATE") ;
-    SetLoaded("D") ; 
-  } 
-  return Digits()->GetEntries() ; 
+   EmcalLoader()->CleanDigits() ; 
+   EmcalLoader()->LoadDigits("UPDATE") ;
+   EmcalLoader()->LoadDigitizer("UPDATE") ;
+   return Digits()->GetEntries() ; 
 }
 
 //____________________________________________________________________________ 
 Int_t AliEMCALGetter::ReadTreeH()
 {
   // Read the Hits
-    
+  EmcalLoader()->CleanHits() ; 
   // gets TreeH from the root file (EMCAL.Hit.root)
-  if ( !IsLoaded("H") ) {
+  //if ( !IsLoaded("H") ) {
     EmcalLoader()->LoadHits("UPDATE") ;
-    SetLoaded("H") ; 
-  }  
+    //SetLoaded("H") ; 
+    //}  
   return Hits()->GetEntries() ; 
 }
 
@@ -504,14 +645,14 @@ Int_t AliEMCALGetter::ReadTreeH()
 Int_t AliEMCALGetter::ReadTreeR()
 {
   // Read the RecPoints
-  
-  
+
+   EmcalLoader()->CleanRecPoints() ; 
   // gets TreeR from the root file (EMCAL.RecPoints.root)
-  if ( !IsLoaded("R") ) {
+  //if ( !IsLoaded("R") ) {
     EmcalLoader()->LoadRecPoints("UPDATE") ;
     EmcalLoader()->LoadClusterizer("UPDATE") ;
-    SetLoaded("R") ; 
-  }
+    //  SetLoaded("R") ; 
+    //}
 
   return ECARecPoints()->GetEntries() ; 
 }
@@ -521,28 +662,28 @@ Int_t AliEMCALGetter::ReadTreeT()
 {
   // Read the TrackSegments
   
-  
+  EmcalLoader()->CleanTracks() ; 
   // gets TreeT from the root file (EMCAL.TrackSegments.root)
-  if ( !IsLoaded("T") ) {
+  //if ( !IsLoaded("T") ) {
     EmcalLoader()->LoadTracks("UPDATE") ;
     EmcalLoader()->LoadTrackSegmentMaker("UPDATE") ;
-    SetLoaded("T") ; 
-  }
+    //  SetLoaded("T") ; 
+    //}
 
   return TrackSegments()->GetEntries() ; 
 }
 //____________________________________________________________________________ 
 Int_t AliEMCALGetter::ReadTreeP()
 {
-  // Read the TrackSegments
-  
+  // Read the RecParticles
   
-  // gets TreeT from the root file (EMCAL.TrackSegments.root)
-  if ( !IsLoaded("P") ) {
+  EmcalLoader()->CleanRecParticles() ; 
+  // gets TreeP from the root file (EMCAL.RecParticles.root)
+  //  if ( !IsLoaded("P") ) {
     EmcalLoader()->LoadRecParticles("UPDATE") ;
     EmcalLoader()->LoadPID("UPDATE") ;
-    SetLoaded("P") ; 
-  }
+    //  SetLoaded("P") ; 
+    // }
 
   return RecParticles()->GetEntries() ; 
 }
@@ -551,19 +692,19 @@ Int_t AliEMCALGetter::ReadTreeS()
 {
   // Read the SDigits
   
-  
+  //  EmcalLoader()->CleanSDigits() ; 
   // gets TreeS from the root file (EMCAL.SDigits.root)
-  if ( !IsLoaded("S") ) {
-    EmcalLoader()->LoadSDigits("UPDATE") ;
-    EmcalLoader()->LoadSDigitizer("UPDATE") ;
-    SetLoaded("S") ; 
-  }
+  // if ( !IsLoaded("S") ) {
+    EmcalLoader()->LoadSDigits("READ") ;
+    EmcalLoader()->LoadSDigitizer("READ") ;
+    //  SetLoaded("S") ; 
+    //}
 
   return SDigits()->GetEntries() ; 
 }
 
 //____________________________________________________________________________ 
-TClonesArray * AliEMCALGetter::SDigits() 
+TClonesArray * AliEMCALGetter::SDigits() const  
 {
   // asks the Loader to return the Digits container 
 
@@ -580,6 +721,7 @@ TClonesArray * AliEMCALGetter::SDigits()
 //____________________________________________________________________________ 
 AliEMCALSDigitizer * AliEMCALGetter::SDigitizer() 
 { 
+  // Return pointer to SDigitizer task
   AliEMCALSDigitizer * rv ; 
   rv =  dynamic_cast<AliEMCALSDigitizer *>(EmcalLoader()->SDigitizer()) ;
   if (!rv) {
@@ -590,7 +732,7 @@ AliEMCALSDigitizer * AliEMCALGetter::SDigitizer()
 }
 
 //____________________________________________________________________________ 
-TParticle * AliEMCALGetter::Secondary(const TParticle* p, const Int_t index) const
+TParticle * AliEMCALGetter::Secondary(const TParticle* p, Int_t index) const
 {
   // Return first (index=1) or second (index=2) secondary particle of primary particle p 
 
@@ -602,14 +744,14 @@ TParticle * AliEMCALGetter::Secondary(const TParticle* p, const Int_t index) con
   if(p) {
   Int_t daughterIndex = p->GetDaughter(index-1) ; 
   AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
-  return  rl->GetAliRun()->Particle(daughterIndex) ; 
+  return  rl->GetAliRun()->GetMCApp()->Particle(daughterIndex) ; 
   }
   else
     return 0 ;
 }
 
 //____________________________________________________________________________ 
-void AliEMCALGetter::Track(const Int_t itrack) 
+void AliEMCALGetter::Track(Int_t itrack) 
 {
   // Read the first entry of EMCAL branch in hit tree gAlice->TreeH()
  
@@ -631,6 +773,7 @@ void AliEMCALGetter::Track(const Int_t itrack)
 //____________________________________________________________________________ 
 TTree * AliEMCALGetter::TreeD() const 
 {
+  // return pointer to Digits Tree
   TTree * rv = 0 ; 
   rv = EmcalLoader()->TreeD() ; 
   if ( !rv ) {
@@ -644,6 +787,7 @@ TTree * AliEMCALGetter::TreeD() const
 //____________________________________________________________________________ 
 TTree * AliEMCALGetter::TreeH() const 
 {
+  // return pointer to Hits Tree
   TTree * rv = 0 ; 
   rv = EmcalLoader()->TreeH() ; 
   if ( !rv ) {
@@ -657,6 +801,8 @@ TTree * AliEMCALGetter::TreeH() const
 //____________________________________________________________________________ 
 TTree * AliEMCALGetter::TreeR() const 
 {
+  // return pointer to RecPoints Tree
+
   TTree * rv = 0 ; 
   rv = EmcalLoader()->TreeR() ; 
   if ( !rv ) {
@@ -669,7 +815,8 @@ TTree * AliEMCALGetter::TreeR() const
 
 //____________________________________________________________________________ 
 TTree * AliEMCALGetter::TreeT() const 
-{
+{  
+  // return pointer to TrackSegments Tree
   TTree * rv = 0 ; 
   rv = EmcalLoader()->TreeT() ; 
   if ( !rv ) {
@@ -682,6 +829,7 @@ TTree * AliEMCALGetter::TreeT() const
 //____________________________________________________________________________ 
 TTree * AliEMCALGetter::TreeP() const 
 {
+  // return pointer to RecParticles Tree
   TTree * rv = 0 ; 
   rv = EmcalLoader()->TreeP() ; 
   if ( !rv ) {
@@ -695,6 +843,7 @@ TTree * AliEMCALGetter::TreeP() const
 //____________________________________________________________________________ 
 TTree * AliEMCALGetter::TreeS() const 
 {
+  // return pointer to SDigits Tree
   TTree * rv = 0 ; 
   rv = EmcalLoader()->TreeS() ; 
   if ( !rv ) {
@@ -720,7 +869,7 @@ Bool_t AliEMCALGetter::VersionExists(TString & opt) const
   if ( opt == "sdigits") {
     // add the version name to the root file name
     TString fileName( EmcalLoader()->GetSDigitsFileName() ) ; 
-    if (version != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name 
+    if (version != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name 
       fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
     if ( !(gSystem->AccessPathName(fileName)) ) { 
       Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
@@ -732,13 +881,12 @@ Bool_t AliEMCALGetter::VersionExists(TString & opt) const
   if ( opt == "digits") {
     // add the version name to the root file name
     TString fileName( EmcalLoader()->GetDigitsFileName() ) ; 
-    if (version != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name 
+    if (version != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name 
       fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
     if ( !(gSystem->AccessPathName(fileName)) ) {
       Warning("VersionExists", "The file %s already exists", fileName.Data()) ;  
       rv = kTRUE ; 
     }
-    EmcalLoader()->SetDigitsFileName(fileName) ;
   }
 
   return rv ;