]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EMCAL/AliEMCALReconstructor.cxx
standardizing access to AliEMCALRecParams through AliEMCALReconstructor
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALReconstructor.cxx
index 82be53b17aae1299bc26feb9c069a1f50cf509c2..8f952fdf7e4d9f557a8b3ecedbb1a8bdc865cdc2 100644 (file)
 // Reconstruction class. Redesigned from the old AliReconstructionner class and 
 // derived from STEER/AliReconstructor. 
 // 
+//-- Aleksei Pavlinov : added staf for EMCAL jet trigger 9Apr 25, 2008)
+//                    : fgDigitsArr should read just once at event
+
 // --- ROOT system ---
+#include <TList.h>
+#include <TClonesArray.h>
+#include <TH2.h>
 
 // --- Standard library ---
 
 // --- AliRoot header files ---
 #include "AliEMCALReconstructor.h"
 
+#include "AliCodeTimer.h"
 #include "AliESDEvent.h"
 #include "AliESDCaloCluster.h"
 #include "AliESDCaloCells.h"
 #include "AliCDBEntry.h"
 #include "AliCDBManager.h"
 #include "AliEMCALRecParam.h"
-// to be removed - it is here just because of geom
-#include "AliRun.h"
-#include "AliRunLoader.h"
+#include "AliEMCALGeometry.h"
+#include "AliEMCAL.h"
+#include "AliEMCALHistoUtilities.h"
+#include "AliESDVZERO.h"
 
-ClassImp(AliEMCALReconstructor)
+#include "AliRunLoader.h"
+#include "AliRun.h"
 
-AliEMCALRecParam* AliEMCALReconstructor::fgkRecParam = 0;  // EMCAL rec. parameters
+ClassImp(AliEMCALReconstructor) 
 
+const AliEMCALRecParam* AliEMCALReconstructor::fgkRecParam = 0;  // EMCAL rec. parameters
+AliEMCALRawUtils* AliEMCALReconstructor::fgRawUtils = 0;   // EMCAL raw utilities class
+AliEMCALClusterizer* AliEMCALReconstructor::fgClusterizer = 0;   // EMCAL clusterizer class
+TClonesArray*     AliEMCALReconstructor::fgDigitsArr = 0;  // shoud read just once at event
 //____________________________________________________________________________
 AliEMCALReconstructor::AliEMCALReconstructor() 
-  : fDebug(kFALSE) 
+  : fDebug(kFALSE), fList(0), fGeom(0) 
 {
   // ctor
+  InitRecParam();
+
+  fgRawUtils = new AliEMCALRawUtils;
+  fgClusterizer = new AliEMCALClusterizerv1;
+
+  //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),
+    fList(rec.fList),
+    fGeom(rec.fGeom)
 {
   //copy ctor
 }
@@ -71,24 +102,40 @@ AliEMCALReconstructor::AliEMCALReconstructor(const AliEMCALReconstructor & rec)
 AliEMCALReconstructor::~AliEMCALReconstructor()
 {
   // dtor
+  delete fGeom;
+  AliCodeTimer::Instance()->Print();
 } 
 
+//____________________________________________________________________________
+void AliEMCALReconstructor::Init()
+{
+  // Trigger hists - Oct 24, 2007
+  fList = AliEMCALHistoUtilities::GetTriggersListOfHists(kTRUE);
+}
+
 //____________________________________________________________________________
 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) {
+    fgkRecParam = dynamic_cast<const AliEMCALRecParam*>(AliReconstructor::GetRecoParam(6));
+  }
+
+  /*
  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;
+    fgkRecParam = new AliEMCALRecParam();
   }
+
 }
 
 //____________________________________________________________________________
@@ -100,15 +147,25 @@ void AliEMCALReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree)
   // the global tracking.
   // Works on the current event.
 
-  InitRecParam();
-  AliEMCALClusterizerv1 clu;
-  clu.SetInput(digitsTree);
-  clu.SetOutput(clustersTree);
-  if(Debug())
-    clu.Digits2Clusters("deb all") ;
-  else
-    clu.Digits2Clusters("") ;
-  
+  AliCodeTimerAuto("")
+
+  ReadDigitsArrayFromTree(digitsTree);
+
+  fgClusterizer->SetOutput(clustersTree);
+
+  if(fgDigitsArr && fgDigitsArr->GetEntries()) {
+
+    fgClusterizer->SetInput(digitsTree);
+    
+    if(Debug())
+      fgClusterizer->Digits2Clusters("deb all") ;
+    else
+      fgClusterizer->Digits2Clusters("");
+    
+    fgClusterizer->Clear();
+
+  }
+
 }
 
 //____________________________________________________________________________
@@ -121,22 +178,20 @@ void AliEMCALReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digits
 
   rawReader->Reset() ; 
 
-  TClonesArray *digitsArr = new TClonesArray("AliEMCALDigit",100);
+  TClonesArray *digitsArr = new TClonesArray("AliEMCALDigit",200);
   Int_t bufsize = 32000;
   digitsTree->Branch("EMCAL", &digitsArr, bufsize);
 
-  //Get Mapping RCU files from the AliEMCALRecParam                                                          
-  const TObjArray* maps = AliEMCALRecParam::GetMappings();
-  if(!maps) AliFatal("Cannot retrieve ALTRO mappings!!");
+  //must be done here because, in constructor, option is not yet known
+  fgRawUtils->SetOption(GetOption());
 
-  AliAltroMapping * mapping[2] ; // For the moment only 2                                                    
-  for(Int_t i = 0; i < 2; i++) {
-    mapping[i] = (AliAltroMapping*)maps->At(i);
-  }
+  fgRawUtils->SetRawFormatHighLowGainFactor(fgkRecParam->GetHighLowGainFactor());
+  fgRawUtils->SetRawFormatOrder(fgkRecParam->GetOrderParameter());
+  fgRawUtils->SetRawFormatTau(fgkRecParam->GetTau());
+  fgRawUtils->SetNoiseThreshold(fgkRecParam->GetNoiseThreshold());
+  fgRawUtils->SetNPedSamples(fgkRecParam->GetNPedSamples());
 
-  static AliEMCALRawUtils rawUtils;
-  rawUtils.SetOption(GetOption());
-  rawUtils.Raw2Digits(rawReader,digitsArr,mapping);
+  fgRawUtils->Raw2Digits(rawReader,digitsArr);
 
   digitsTree->Fill();
   digitsArr->Delete();
@@ -144,53 +199,58 @@ void AliEMCALReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digits
 
 }
 
+
 //____________________________________________________________________________
 void AliEMCALReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree, 
                                    AliESDEvent* esd) const
 {
   // Called by AliReconstruct after Reconstruct() and global tracking and vertexing 
+  // and V0 
   // Works on the current event
-  // Creates AliESDCaloCluster from AliEMCALRecPoints 
-  // and AliESDCaloCells from AliEMCALDigits
-  // Also, fills ESD with calorimeter trigger information
+  //  printf(" ## AliEMCALReconstructor::FillESD() is started ### \n ");
+  //return;
 
   //######################################################
   //#########Calculate trigger and set trigger info###########
   //######################################################
  
-  AliEMCALTrigger tr ;
-  //   tr.SetPatchSize(1);//create 4x4 patches
+  AliEMCALTrigger tr;
+  //   tr.SetPatchSize(1);  // create 4x4 patches
+  tr.SetSimulation(kFALSE); // Reconstruction mode
+  tr.SetDigitsList(fgDigitsArr);
+  // Get VZERO total multiplicity for jet trigger simulation 
+  // The simulation of jey trigger will be incorrect if no VZERO data 
+  // at ESD
+  AliESDVZERO* vZero = esd->GetVZEROData();
+  if(vZero) {
+    tr.SetVZER0Multiplicity(vZero->GetMTotV0A() + vZero->GetMTotV0C());
+  }
+  //
   tr.Trigger();
-  
+
   Float_t maxAmp2x2  = tr.Get2x2MaxAmplitude();
   Float_t maxAmpnxn  = tr.GetnxnMaxAmplitude();
   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();
-  Int_t iCellPhinxn = tr.GetnxnCellPhi();
-  Int_t iCellEta2x2 = tr.Get2x2CellEta();
-  Int_t iCellEtanxn = tr.GetnxnCellEta();
+  Int_t iModulePhi2x2 = tr.Get2x2ModulePhi();
+  Int_t iModulePhinxn = tr.GetnxnModulePhi();
+  Int_t iModuleEta2x2 = tr.Get2x2ModuleEta();
+  Int_t iModuleEtanxn = tr.GetnxnModuleEta();
 
-  AliDebug(2, Form("Trigger 2x2 max amp %f, out amp %f, SM %d, iphi %d ieta %d",  maxAmp2x2, ampOutOfPatch2x2, iSM2x2,iCellPhi2x2, iCellEta2x2));
-  AliDebug(2, Form("Trigger 4x4 max amp %f , out amp %f, SM %d, iphi %d, ieta %d",  maxAmpnxn, ampOutOfPatchnxn, iSMnxn,iCellPhinxn, iCellEtanxn));
+  AliDebug(2, Form("Trigger 2x2 max amp %f, out amp %f, SM %d, iphi %d ieta %d",  maxAmp2x2, ampOutOfPatch2x2, iSM2x2,iModulePhi2x2, iModuleEta2x2));
+  AliDebug(2, Form("Trigger 4x4 max amp %f , out amp %f, SM %d, iphi %d, ieta %d",  maxAmpnxn, ampOutOfPatchnxn, iSMnxn,iModulePhinxn, iModuleEtanxn));
 
   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, iModulePhi2x2, iModuleEta2x2) ; // should be changed to Module
+  Int_t iAbsIdnxn = fGeom->GetAbsCellIdFromCellIndexes( iSMnxn, iModulePhinxn, iModuleEtanxn) ;
+  fGeom->GetGlobal(iAbsId2x2, pos2x2);
+  fGeom->GetGlobal(iAbsIdnxn, posnxn);
+  //printf(" iAbsId2x2 %i iAbsIdnxn %i \n", iAbsId2x2, iAbsIdnxn);
   
   TArrayF triggerPosition(6);
   triggerPosition[0] = pos2x2(0) ;   
@@ -198,21 +258,45 @@ void AliEMCALReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree,
   triggerPosition[2] = pos2x2(2) ;  
   triggerPosition[3] = posnxn(0) ;   
   triggerPosition[4] = posnxn(1) ;   
-  triggerPosition[5] = posnxn(2) ;  
+  triggerPosition[5] = posnxn(2) ;
+  //printf(" triggerPosition ");
+  //for(int i=0; i<6; i++) printf(" %i %f : ", i, triggerPosition[i]);
 
   TArrayF triggerAmplitudes(4);
   triggerAmplitudes[0] = maxAmp2x2 ;   
   triggerAmplitudes[1] = ampOutOfPatch2x2 ;    
   triggerAmplitudes[2] = maxAmpnxn ;   
   triggerAmplitudes[3] = ampOutOfPatchnxn ;   
-
+  //printf("\n triggerAmplitudes ");
+  //for(int i=0; i<4; i++) printf(" %i %f : ", i, triggerAmplitudes[i]);
+  //printf("\n");
+  //tr.Print("");
+  //
+  // Trigger jet staff
+  //
+  if(tr.GetNJetThreshold()>0) {
+    // Jet phi/eta
+    Int_t n0 = triggerPosition.GetSize();
+    const TH2F *hpatch = tr.GetJetMatrixE();
+    triggerPosition.Set(n0 + 2);
+    for(Int_t i=0; i<2; i++) triggerPosition[n0+i] = hpatch->GetMean(i+1);   
+    // Add jet ampitudes
+    n0 = triggerAmplitudes.GetSize();
+    triggerAmplitudes.Set(n0 + tr.GetNJetThreshold());
+    Double_t *ampJet = tr.GetL1JetThresholds();
+    for(Int_t i=0; i<tr.GetNJetThreshold(); i++){
+      triggerAmplitudes[n0 + i] = Float_t(ampJet[i]);
+    }
+  }
   esd->AddEMCALTriggerPosition(triggerPosition);
   esd->AddEMCALTriggerAmplitudes(triggerAmplitudes);
-  
+  // Fill trigger hists
+  AliEMCALHistoUtilities::FillTriggersListOfHists(fList,&triggerPosition,&triggerAmplitudes);
+
   //########################################
   //##############Fill CaloCells###############
   //########################################
-  
+
   TClonesArray *digits = new TClonesArray("AliEMCALDigit",1000);
   TBranch *branchdig = digitsTree->GetBranch("EMCAL");
   if (!branchdig) { 
@@ -249,6 +333,7 @@ void AliEMCALReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree,
   AliDebug(1,Form("%d clusters",nClusters));
   esd->SetFirstEMCALCluster(esd->GetNumberOfCaloClusters()); // Put after Phos clusters 
 
+
   //######################################################
   //#######################TRACK MATCHING###############
   //######################################################
@@ -267,11 +352,10 @@ 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);
@@ -281,12 +365,11 @@ void AliEMCALReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree,
     Float_t xyz[3];
     TVector3 gpos;
     clust->GetGlobalPosition(gpos);
-    for (Int_t ixyz=0; ixyz<3; ixyz++) 
+    for (Int_t ixyz=0; ixyz<3; ixyz++)
       xyz[ixyz] = gpos[ixyz];
     Float_t elipAxis[2];
     clust->GetElipsAxis(elipAxis);
-    
-     //Create digits lists
+       //Create digits lists
     Int_t cellMult = clust->GetMultiplicity();
     //TArrayS digiList(digitMult);
     Float_t *amplFloat = clust->GetEnergiesList();
@@ -295,27 +378,26 @@ void AliEMCALReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree,
     //Uncomment when unfolding is done
     //TArrayD fracList(cellMult);
 
-    Int_t newCellMult = 0; 
+    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++;
+      absIdList[newCellMult] = (UShort_t)(digitInts[iCell]);
+    //Uncomment when unfolding is done
+    //fracList[newCellMult] = amplFloat[iCell]/emcCells.GetCellAmplitude(digitInts[iCell]);
+      newCellMult++;
       }
     }
     absIdList.Set(newCellMult);
     //Uncomment when unfolding is done
     //fracList.Set(newCellMult);
+
     if(newCellMult > 0) { // accept cluster if it has some digit
       nClustersNew++;
       //Primaries
       Int_t  parentMult  = 0;
       Int_t *parentList =  clust->GetParents(parentMult);
-      
       // fills the ESDCaloCluster
-      AliESDCaloCluster * ec = new AliESDCaloCluster() ; 
+      AliESDCaloCluster * ec = new AliESDCaloCluster() ;
       ec->SetClusterType(AliESDCaloCluster::kEMCALClusterv1);
       ec->SetPosition(xyz);
       ec->SetE(clust->GetEnergy());
@@ -325,49 +407,70 @@ void AliEMCALReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree,
       //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
+        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->SetTOF(clust->GetTime()) ; //time-of-fligh
+      ec->SetNExMax(clust->GetNExMax());          //number of local maxima
+      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);
+     esd->AddCaloCluster(ec);
       delete ec;
-      //delete [] newAbsIdList ;
+      delete [] newAbsIdList ;
       //delete [] newFracList ;
-    }
-  } // 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;
-  
+   }
+ } // 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;
+
+  delete digits;
+  delete clusters;
+
+  // printf(" ## AliEMCALReconstructor::FillESD() is ended : ncl %i -> %i ### \n ",nClusters, nClustersNew); 
 }
 
+//__________________________________________________________________________
+void AliEMCALReconstructor::ReadDigitsArrayFromTree(TTree *digitsTree) const
+{
+  // See AliEMCALClusterizer::SetInput(TTree *digitsTree);
+  if(fgDigitsArr) {
+    // Clear previous digits 
+    fgDigitsArr->Delete();
+    delete fgDigitsArr;
+  }
+  // Read the digits from the input tree
+  TBranch *branch = digitsTree->GetBranch("EMCAL");
+  if (!branch) { 
+    AliError("can't get the branch with the EMCAL digits !");
+    return;
+  }
+  fgDigitsArr = new TClonesArray("AliEMCALDigit",100);
+  branch->SetAddress(&fgDigitsArr);
+  branch->GetEntry(0);
+}