]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EMCAL/AliEMCALReconstructor.cxx
Move AliD0toKpi* and AliBtoJPSI* from libPWG3base to libPWG3 (Andrea)
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALReconstructor.cxx
index 35a36a7d36ec5764ec14f3582eb4be78d267bcd7..32ddad5c7931f0ce7a3c6754d280aa1633533b51 100644 (file)
@@ -16,8 +16,8 @@
 /* $Id$ */
 
 //_________________________________________________________________________
-//*--
-//*-- Yves Schutz (SUBATECH) 
+//--
+//-- Yves Schutz (SUBATECH) 
 // Reconstruction class. Redesigned from the old AliReconstructionner class and 
 // derived from STEER/AliReconstructor. 
 // 
 // --- AliRoot header files ---
 #include "AliEMCALReconstructor.h"
 
+#include "AliCodeTimer.h"
 #include "AliESDEvent.h"
 #include "AliESDCaloCluster.h"
+#include "AliESDCaloCells.h"
 #include "AliESDtrack.h"
 #include "AliEMCALLoader.h"
 #include "AliEMCALRawUtils.h"
+#include "AliEMCALDigit.h"
 #include "AliEMCALClusterizerv1.h"
 #include "AliEMCALRecPoint.h"
 #include "AliEMCALPID.h"
 #include "AliEMCALTrigger.h"
 #include "AliRawReader.h"
-// to be removed - it is here just because of geom
-#include "AliRun.h"
+#include "AliCDBEntry.h"
+#include "AliCDBManager.h"
+#include "AliEMCALRecParam.h"
+#include "AliEMCALGeometry.h"
+
 #include "AliRunLoader.h"
+#include "AliRun.h"
 
 ClassImp(AliEMCALReconstructor)
 
 AliEMCALRecParam* AliEMCALReconstructor::fgkRecParam = 0;  // EMCAL rec. parameters
-
+AliEMCALRawUtils* AliEMCALReconstructor::fgRawUtils = 0;   // EMCAL raw utilities class
 //____________________________________________________________________________
 AliEMCALReconstructor::AliEMCALReconstructor() 
-  : fDebug(kFALSE) 
+  : fDebug(kFALSE),fGeom(0) 
 {
   // ctor
-  if (!fgkRecParam) {
-    AliWarning("The Reconstruction parameters for EMCAL nonitialized - Used default one");
-    fgkRecParam = new AliEMCALRecParam;
+  InitRecParam();
+
+  fgRawUtils = new AliEMCALRawUtils;
+
+  //To make sure we match with the geometry in a simulation file,
+  //let's try to get it first.  If not, take the default geometry
+  AliRunLoader *rl = AliRunLoader::GetRunLoader();
+  if (rl->GetAliRun() && rl->GetAliRun()->GetDetector("EMCAL")) {
+    fGeom = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"))->GetGeometry();
+  } else {
+    AliInfo(Form("Using default geometry in reconstruction"));
+    fGeom =  AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
   }
+
+  if(!fGeom) AliFatal(Form("Could not get geometry!"));
+
 } 
 
 //____________________________________________________________________________
 AliEMCALReconstructor::AliEMCALReconstructor(const AliEMCALReconstructor & rec)
   : AliReconstructor(rec),
-    fDebug(rec.fDebug)
+    fDebug(rec.fDebug),
+    fGeom(rec.fGeom)
 {
   //copy ctor
 }
@@ -69,8 +89,28 @@ AliEMCALReconstructor::AliEMCALReconstructor(const AliEMCALReconstructor & rec)
 AliEMCALReconstructor::~AliEMCALReconstructor()
 {
   // dtor
+  delete fGeom;
+  AliCodeTimer::Instance()->Print();
 } 
 
+//____________________________________________________________________________
+void AliEMCALReconstructor::InitRecParam() const
+{
+  // Check if the instance of AliEMCALRecParam exists, 
+  // if not, get it from OCDB if available, otherwise create a default one
+
+ if (!fgkRecParam  && (AliCDBManager::Instance()->IsDefaultStorageSet())) {
+    AliCDBEntry *entry = (AliCDBEntry*) 
+      AliCDBManager::Instance()->Get("EMCAL/Config/RecParam");
+    if (entry) fgkRecParam =  (AliEMCALRecParam*) entry->GetObject();
+  }
+  
+  if(!fgkRecParam){
+    AliWarning("The Reconstruction parameters for EMCAL nonitialized - Used default one");
+    fgkRecParam = new AliEMCALRecParam;
+  }
+}
+
 //____________________________________________________________________________
 void AliEMCALReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
 {
@@ -79,14 +119,17 @@ void AliEMCALReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree)
   // segment maker needs access to the AliESD object to retrieve the tracks reconstructed by 
   // the global tracking.
   // Works on the current event.
+
+  AliCodeTimerAuto("")
+
   AliEMCALClusterizerv1 clu;
   clu.SetInput(digitsTree);
   clu.SetOutput(clustersTree);
-  if ( Debug() ) 
-    clu.Digits2Clusters("deb all") ; 
-  else 
-    clu.Digits2Clusters("pseudo") ;  
+  if(Debug())
+    clu.Digits2Clusters("deb all") ;
+  else
+    clu.Digits2Clusters("") ;
+  
 }
 
 //____________________________________________________________________________
@@ -103,8 +146,21 @@ void AliEMCALReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digits
   Int_t bufsize = 32000;
   digitsTree->Branch("EMCAL", &digitsArr, bufsize);
 
-  static AliEMCALRawUtils rawUtils;
-  rawUtils.Raw2Digits(rawReader,digitsArr);
+  //must be done here because, in constructor, option is not yet known
+  fgRawUtils->SetOption(GetOption());
+
+  fgRawUtils->SetRawFormatHighLowGainFactor(fgkRecParam->GetHighLowGainFactor());
+  fgRawUtils->SetRawFormatOrder(fgkRecParam->GetOrderParameter());
+  fgRawUtils->SetRawFormatTau(fgkRecParam->GetTau());
+  fgRawUtils->SetNoiseThreshold(fgkRecParam->GetNoiseThreshold());
+  fgRawUtils->SetNPedSamples(fgkRecParam->GetNPedSamples());
+
+  fgRawUtils->Raw2Digits(rawReader,digitsArr);
+
+  digitsTree->Fill();
+  digitsArr->Delete();
+  delete digitsArr;
+
 }
 
 //____________________________________________________________________________
@@ -113,24 +169,14 @@ void AliEMCALReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree,
 {
   // Called by AliReconstruct after Reconstruct() and global tracking and vertexing 
   // Works on the current event
-  const double timeScale = 1.e+11; // transition constant from sec to 0.01 ns 
-
   // Creates AliESDCaloCluster from AliEMCALRecPoints 
-
-  TObjArray *clusters = new TObjArray(100);
-  TBranch *branch = clustersTree->GetBranch("EMCALECARP");
-  branch->SetAddress(&clusters);
-  clustersTree->GetEvent(0);
-
-  Int_t nClusters = clusters->GetEntries(), nClustersNew=0;
-  AliDebug(1,Form("%d clusters",nClusters));
-  //  Int_t nRP=0, nPC=0; // in input
-  esd->SetFirstEMCALCluster(esd->GetNumberOfCaloClusters()); // Put after Phos clusters 
+  // and AliESDCaloCells from AliEMCALDigits
+  // Also, fills ESD with calorimeter trigger information
 
   //######################################################
   //#########Calculate trigger and set trigger info###########
   //######################################################
+
   AliEMCALTrigger tr ;
   //   tr.SetPatchSize(1);//create 4x4 patches
   tr.Trigger();
@@ -140,13 +186,6 @@ void AliEMCALReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree,
   Float_t ampOutOfPatch2x2  = tr.Get2x2AmpOutOfPatch() ;
   Float_t ampOutOfPatchnxn  = tr.GetnxnAmpOutOfPatch() ;
 
-  AliEMCALGeometry * geom = 0;
-  AliRunLoader *runLoader = AliRunLoader::GetRunLoader();
-  if (runLoader->GetAliRun() && runLoader->GetAliRun()->GetDetector("EMCAL"))
-    geom = dynamic_cast<AliEMCAL*>(runLoader->GetAliRun()->GetDetector("EMCAL"))->GetGeometry();
-  if (geom == 0) 
-    geom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaulGeometryName());
-
   Int_t iSM2x2      = tr.Get2x2SuperModule();
   Int_t iSMnxn      = tr.GetnxnSuperModule();
   Int_t iCellPhi2x2 = tr.Get2x2CellPhi();
@@ -160,10 +199,10 @@ void AliEMCALReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree,
   TVector3    pos2x2(-1,-1,-1);
   TVector3    posnxn(-1,-1,-1);
 
-  Int_t iAbsId2x2 = geom->GetAbsCellIdFromCellIndexes( iSM2x2, iCellPhi2x2, iCellEta2x2) ;
-  Int_t iAbsIdnxn = geom->GetAbsCellIdFromCellIndexes( iSMnxn, iCellPhinxn, iCellEtanxn) ;
-  geom->GetGlobal(iAbsId2x2, pos2x2);
-  geom->GetGlobal(iAbsIdnxn, posnxn);
+  Int_t iAbsId2x2 = fGeom->GetAbsCellIdFromCellIndexes( iSM2x2, iCellPhi2x2, iCellEta2x2) ;
+  Int_t iAbsIdnxn = fGeom->GetAbsCellIdFromCellIndexes( iSMnxn, iCellPhinxn, iCellEtanxn) ;
+  fGeom->GetGlobal(iAbsId2x2, pos2x2);
+  fGeom->GetGlobal(iAbsIdnxn, posnxn);
   
   TArrayF triggerPosition(6);
   triggerPosition[0] = pos2x2(0) ;   
@@ -181,7 +220,47 @@ void AliEMCALReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree,
 
   esd->AddEMCALTriggerPosition(triggerPosition);
   esd->AddEMCALTriggerAmplitudes(triggerAmplitudes);
-  
+
+  //########################################
+  //##############Fill CaloCells###############
+  //########################################
+
+  TClonesArray *digits = new TClonesArray("AliEMCALDigit",1000);
+  TBranch *branchdig = digitsTree->GetBranch("EMCAL");
+  if (!branchdig) { 
+    AliError("can't get the branch with the PHOS digits !");
+    return;
+  }
+  branchdig->SetAddress(&digits);
+  digitsTree->GetEvent(0);
+  Int_t nDigits = digits->GetEntries(), idignew = 0 ;
+  AliDebug(1,Form("%d digits",nDigits));
+
+  AliESDCaloCells &emcCells = *(esd->GetEMCALCells());
+  emcCells.CreateContainer(nDigits);
+  emcCells.SetType(AliESDCaloCells::kEMCALCell);
+  for (Int_t idig = 0 ; idig < nDigits ; idig++) {
+    const AliEMCALDigit * dig = (const AliEMCALDigit*)digits->At(idig);
+    if(dig->GetAmp() > 0 ){
+      emcCells.SetCell(idignew,dig->GetId(),dig->GetAmp(), dig->GetTime());   
+      idignew++;
+    }
+  }
+  emcCells.SetNumberOfCells(idignew);
+  emcCells.Sort();
+
+  //------------------------------------------------------------
+  //-----------------CLUSTERS-----------------------------
+  //------------------------------------------------------------
+  TObjArray *clusters = new TObjArray(100);
+  TBranch *branch = clustersTree->GetBranch("EMCALECARP");
+  branch->SetAddress(&clusters);
+  clustersTree->GetEvent(0);
+
+  Int_t nClusters = clusters->GetEntries(),  nClustersNew=0;
+  AliDebug(1,Form("%d clusters",nClusters));
+  esd->SetFirstEMCALCluster(esd->GetNumberOfCaloClusters()); // Put after Phos clusters 
+
   //######################################################
   //#######################TRACK MATCHING###############
   //######################################################
@@ -200,15 +279,15 @@ void AliEMCALReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree,
     iemcalMatch = track->GetEMCALcluster();
     if(iemcalMatch >= 0) matchedTrack[iemcalMatch] = itrack;
   } 
-  
+
   //########################################
-  //##############Fill CaloClusters#############
+  //##############Fill CaloClusters############
   //########################################
 
-
+  esd->SetNumberOfEMCALClusters(nClusters);
   for (Int_t iClust = 0 ; iClust < nClusters ; iClust++) {
     const AliEMCALRecPoint * clust = (const AliEMCALRecPoint*)clusters->At(iClust);
-    //if(clust->GetClusterType()== AliESDCaloCluster::kClusterv1) nRP++; else nPC++;
+    //if(clust->GetClusterType()== AliESDCaloCluster::kEMCALClusterv1) nRP++; else nPC++;
     if (Debug()) clust->Print();
     // Get information from EMCAL reconstruction points
     Float_t xyz[3];
@@ -216,118 +295,91 @@ void AliEMCALReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree,
     clust->GetGlobalPosition(gpos);
     for (Int_t ixyz=0; ixyz<3; ixyz++) 
       xyz[ixyz] = gpos[ixyz];
-    
-    Int_t digitMult = clust->GetMultiplicity();
-    Short_t *amplList = new Short_t[digitMult];
-    Short_t *timeList = new Short_t[digitMult];
-    Short_t *digiList = new Short_t[digitMult];
-    Float_t *amplFloat = clust->GetEnergiesList();
-    Float_t *timeFloat = clust->GetTimeList();
-    Int_t   *digitInts = clust->GetAbsId();
     Float_t elipAxis[2];
     clust->GetElipsAxis(elipAxis);
     
-    // Convert Float_t* and Int_t* to Short_t* to save memory
-    // Problem : we should recalculate a cluster characteristics when discard digit(s)
-    Int_t newdigitMult = 0; 
-    for (Int_t iDigit=0; iDigit<digitMult; iDigit++) {
-      if (amplFloat[iDigit] > 0) {
-       amplList[newdigitMult] = (UShort_t)(amplFloat[iDigit]*500);
-        // Time in units of 0.01 ns = 10 ps
-        if(timeFloat[iDigit] < 65536./timeScale) 
-         timeList[newdigitMult] = (UShort_t)(timeFloat[iDigit]*timeScale);
-        else
-          timeList[newdigitMult] = 65535;
-       digiList[newdigitMult] = (UShort_t)(digitInts[iDigit]);
-        newdigitMult++;
+     //Create digits lists
+    Int_t cellMult = clust->GetMultiplicity();
+    //TArrayS digiList(digitMult);
+    Float_t *amplFloat = clust->GetEnergiesList();
+    Int_t   *digitInts = clust->GetAbsId();
+    TArrayS absIdList(cellMult);
+    //Uncomment when unfolding is done
+    //TArrayD fracList(cellMult);
+
+    Int_t newCellMult = 0; 
+    for (Int_t iCell=0; iCell<cellMult; iCell++) {
+      if (amplFloat[iCell] > 0) {
+       absIdList[newCellMult] = (UShort_t)(digitInts[iCell]);
+       //Uncomment when unfolding is done
+       //fracList[newCellMult] = amplFloat[iCell]/emcCells.GetCellAmplitude(digitInts[iCell]);
+       newCellMult++;
       }
-      else if (clust->GetClusterType() != AliESDCaloCluster::kPseudoCluster)
-        Warning("FillESD()","Negative or 0 digit amplitude in cluster");
     }
-    
-    if(newdigitMult > 0) { // accept cluster if it has some digit
+    absIdList.Set(newCellMult);
+    //Uncomment when unfolding is done
+    //fracList.Set(newCellMult);
+    if(newCellMult > 0) { // accept cluster if it has some digit
       nClustersNew++;
-      if(newdigitMult != digitMult) { // some digits were deleted
-        Short_t *amplListNew = new Short_t[newdigitMult];
-        Short_t *timeListNew = new Short_t[newdigitMult];
-        Short_t *digiListNew = new Short_t[newdigitMult];
-        for (Int_t iDigit=0; iDigit<newdigitMult; iDigit++) {
-          amplListNew[iDigit] = amplList[iDigit];
-          timeListNew[iDigit] = timeList[iDigit];
-          digiListNew[iDigit] = digiList[iDigit];
-        }
-       
-        delete [] amplList;
-        delete [] timeList;
-        delete [] digiList;
-       
-        amplList = amplListNew;
-        timeList = timeListNew;
-        digiList = digiListNew;
-      }
-      
       //Primaries
       Int_t  parentMult  = 0;
-      Int_t *parentInts =  clust->GetParents(parentMult);
-      Short_t *parentList = new Short_t[parentMult];
-      for (Int_t ipr=0; ipr<parentMult; ipr++) 
-       parentList[ipr] = (Short_t)(parentInts[ipr]);    
+      Int_t *parentList =  clust->GetParents(parentMult);
       
-    
       // fills the ESDCaloCluster
       AliESDCaloCluster * ec = new AliESDCaloCluster() ; 
-      ec->SetEMCAL(kTRUE);
-      ec->SetClusterType(clust->GetClusterType());
+      ec->SetClusterType(AliESDCaloCluster::kEMCALClusterv1);
       ec->SetPosition(xyz);
       ec->SetE(clust->GetEnergy());
-      TArrayS arrayAmpList(newdigitMult,amplList);
-      TArrayS arrayTimeList(newdigitMult,timeList);
-      TArrayS arrayIndexList(newdigitMult,digiList);
-      ec->AddDigitAmplitude(arrayAmpList);
-      ec->AddDigitTime(arrayTimeList);
-      ec->AddDigitIndex(arrayIndexList);
-    
-      if(clust->GetClusterType()== AliESDCaloCluster::kClusterv1){
-
-        ec->SetClusterDisp(clust->GetDispersion());
-        ec->SetClusterChi2(-1); //not yet implemented
-        ec->SetM02(elipAxis[0]*elipAxis[0]) ;
-        ec->SetM20(elipAxis[1]*elipAxis[1]) ;
-        ec->SetM11(-1) ;        //not yet implemented
-       
-       TArrayS arrayTrackMatched(1);// Only one track, temporal solution.
-       arrayTrackMatched[0]= (Short_t)(matchedTrack[iClust]);
-       ec->AddTracksMatched(arrayTrackMatched);
-       
-       TArrayS arrayParents(parentMult,parentList);
-       ec->AddLabels(arrayParents);
-      } 
+      ec->SetNCells(newCellMult);
+      //Change type of list from short to ushort
+      UShort_t *newAbsIdList  = new UShort_t[newCellMult];
+      //Uncomment when unfolding is done
+      //Double_t *newFracList  = new Double_t[newCellMult];
+      for(Int_t i = 0; i < newCellMult ; i++) {
+       newAbsIdList[i]=absIdList[i];
+       //Uncomment when unfolding is done
+      //newFracList[i]=fracList[i];
+      }
+      ec->SetCellsAbsId(newAbsIdList);
+      //Uncomment when unfolding is done
+      //ec->SetCellsAmplitudeFraction(newFracList);
+      
+      ec->SetClusterDisp(clust->GetDispersion());
+      ec->SetClusterChi2(-1); //not yet implemented
+      ec->SetM02(elipAxis[0]*elipAxis[0]) ;
+      ec->SetM20(elipAxis[1]*elipAxis[1]) ;
+      ec->SetM11(-1) ;        //not yet implemented
+      
+      TArrayI arrayTrackMatched(1);// Only one track, temporal solution. 
+      arrayTrackMatched[0]= matchedTrack[iClust]; 
+      ec->AddTracksMatched(arrayTrackMatched); 
+      
+      TArrayI arrayParents(parentMult,parentList); 
+      ec->AddLabels(arrayParents);
+      
       
       // add the cluster to the esd object
       esd->AddCaloCluster(ec);
       delete ec;
-      delete [] parentList;
-    } else { // no new ESD cluster
-      
+      //delete [] newAbsIdList ;
+      //delete [] newFracList ;
     }
-    delete [] amplList;
-    delete [] timeList;
-    delete [] digiList;
-
   } // cycle on clusters
-
+  
   delete [] matchedTrack;
-
+  
   esd->SetNumberOfEMCALClusters(nClustersNew);
   //if(nClustersNew != nClusters) 
   //printf(" ##### nClusters %i -> new %i ##### \n", nClusters, nClustersNew );
   
   //Fill ESDCaloCluster with PID weights
-  AliEMCALPID *pid = new AliEMCALPID;
-  //pid->SetPrintInfo(kTRUE);
-  pid->SetReconstructor(kTRUE);
-  pid->RunPID(esd);
-  delete pid;
+   AliEMCALPID *pid = new AliEMCALPID;
+   //pid->SetPrintInfo(kTRUE);
+   pid->SetReconstructor(kTRUE);
+   pid->RunPID(esd);
+   delete pid;
+
 }