]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
code refactoring, add track filtering and event selection
authorgconesab <gconesab@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 24 May 2012 03:06:09 +0000 (03:06 +0000)
committergconesab <gconesab@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 24 May 2012 03:06:09 +0000 (03:06 +0000)
PWGGA/CaloTasks/AliAnalysisTaskCaloFilter.cxx
PWGGA/CaloTasks/AliAnalysisTaskCaloFilter.h
PWGGA/CaloTasks/macros/AddTaskCaloFilter.C
PWGGA/CaloTasks/macros/ConfigCaloFilter.C
PWGGA/CaloTasks/macros/anaCaloFilter.C

index 96a9d7dc18073eaa42b9c4d935afa1eeb2b44be1..36bb6c84796c2b05c6377ba580f7b766db370957 100644 (file)
@@ -18,7 +18,7 @@
 // PHOS or both, creating the corresponing AODCaloClusters
 // and AODCaloCells.
 // Keep also the AODHeader information and the vertex.
-// Needed for calorimeter calibration.
+// Keep tracks if requested
 // Copy of AliAnalysisTaskESDfilter.
 // Author: Gustavo Conesa Balbastre (INFN - Frascati)
 //////////////////////////////////////////////////////////
@@ -26,7 +26,6 @@
 //Root
 #include "TGeoManager.h"
 #include "TFile.h"
-#include "TNtuple.h"
 #include "TROOT.h"
 #include "TInterpreter.h"
 
 #include "AliAnalysisTaskCaloFilter.h"
 
 ClassImp(AliAnalysisTaskCaloFilter)
-  
+
 ////////////////////////////////////////////////////////////////////////
 
 AliAnalysisTaskCaloFilter::AliAnalysisTaskCaloFilter():
-  AliAnalysisTaskSE("CaloFilterTask"), //fCuts(0x0),
-  fCaloFilter(0), fCorrect(kFALSE), 
-  fEMCALGeo(0x0),fEMCALGeoName("EMCAL_FIRSTYEARV1"), 
-  fEMCALRecoUtils(new AliEMCALRecoUtils),
-  fESDtrackCuts(0), fTriggerAnalysis (new AliTriggerAnalysis), fTrackMultEtaCut(0.8),
-  fLoadEMCALMatrices(kFALSE), //fLoadPHOSMatrices(kFALSE),
-  fGeoMatrixSet(kFALSE), fEventNtuple(0),fConfigName(""),fFillAODFile(kTRUE)
+AliAnalysisTaskSE("CaloFilterTask"), //fCuts(0x0),
+fCaloFilter(0), fCorrect(kFALSE), 
+fEMCALGeo(0x0),fEMCALGeoName("EMCAL_FIRSTYEARV1"), 
+fEMCALRecoUtils(new AliEMCALRecoUtils),
+fLoadEMCALMatrices(kFALSE), //fLoadPHOSMatrices(kFALSE),
+fGeoMatrixSet(kFALSE),
+fConfigName(""),fFillAODFile(kTRUE), fFillTracks(kFALSE),
+fEnergyCut(0.), fNcellsCut (0), fVzCut(100.)
 {
   // Default constructor
-  fESDtrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010();
+  
   for(Int_t i = 0; i < 12; i++) fEMCALMatrix[i] = 0 ;
   //for(Int_t i = 0; i < 5 ; i++) fPHOSMatrix[i]  = 0 ;
-
-  DefineOutput(1, TNtuple::Class());
   
 }
 
 //__________________________________________________
 AliAnalysisTaskCaloFilter::AliAnalysisTaskCaloFilter(const char* name):
-  AliAnalysisTaskSE(name), //fCuts(0x0),
-  fCaloFilter(0), fCorrect(kFALSE),
-  fEMCALGeo(0x0),fEMCALGeoName("EMCAL_FIRSTYEARV1"), 
-  fEMCALRecoUtils(new AliEMCALRecoUtils),
-  fESDtrackCuts(0), fTriggerAnalysis (new AliTriggerAnalysis), fTrackMultEtaCut(0.8),
-  fLoadEMCALMatrices(kFALSE), //fLoadPHOSMatrices(kFALSE),
-  fGeoMatrixSet(kFALSE), fEventNtuple(0),fConfigName(""),fFillAODFile(kTRUE)
+AliAnalysisTaskSE(name), //fCuts(0x0),
+fCaloFilter(0), fCorrect(kFALSE),
+fEMCALGeo(0x0),fEMCALGeoName("EMCAL_FIRSTYEARV1"), 
+fEMCALRecoUtils(new AliEMCALRecoUtils),
+fLoadEMCALMatrices(kFALSE), //fLoadPHOSMatrices(kFALSE),
+fGeoMatrixSet(kFALSE),
+fConfigName(""),fFillAODFile(kTRUE),fFillTracks(kFALSE),
+fEnergyCut(0.), fNcellsCut (0), fVzCut(100.)
 {
   // Constructor
-  fESDtrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010();
+  
   for(Int_t i = 0; i < 12; i++) fEMCALMatrix[i] = 0 ;
   //for(Int_t i = 0; i < 5 ; i++) fPHOSMatrix[i]  = 0 ;
-
-  DefineOutput(1, TNtuple::Class());
-
+  
 }
 
 //__________________________________________________
@@ -96,10 +93,6 @@ AliAnalysisTaskCaloFilter::~AliAnalysisTaskCaloFilter()
        
   if(fEMCALGeo)        delete fEMCALGeo;       
   if(fEMCALRecoUtils)  delete fEMCALRecoUtils;
-  if(fESDtrackCuts)    delete fESDtrackCuts;
-  if(fTriggerAnalysis) delete fTriggerAnalysis;
-
-  if(fEventNtuple)     delete fEventNtuple;
   
 }
 
@@ -108,18 +101,24 @@ void AliAnalysisTaskCaloFilter::Init()
 {
   //Init analysis with configuration macro if available
   
-  if(gROOT->LoadMacro(fConfigName) >=0){
+  if(gROOT->LoadMacro(fConfigName) >=0)
+  {
     printf("Configure analysis with %s\n",fConfigName.Data());
+    
     AliAnalysisTaskCaloFilter *filter = (AliAnalysisTaskCaloFilter*)gInterpreter->ProcessLine("ConfigCaloFilter()");
+    
     fEMCALGeoName      = filter->fEMCALGeoName; 
     fLoadEMCALMatrices = filter->fLoadEMCALMatrices;
     fFillAODFile       = filter->fFillAODFile;
+    fFillTracks        = filter->fFillTracks;
     fEMCALRecoUtils    = filter->fEMCALRecoUtils; 
     fConfigName        = filter->fConfigName;
     fCaloFilter        = filter->fCaloFilter;
     fCorrect           = filter->fCorrect;
-    fTrackMultEtaCut   = filter->fTrackMultEtaCut;
-    fESDtrackCuts      = filter->fESDtrackCuts;
+    fEnergyCut         = filter->fEnergyCut;
+    fNcellsCut         = filter->fNcellsCut;
+    fVzCut             = filter->fVzCut;
+    
     for(Int_t i = 0; i < 12; i++) fEMCALMatrix[i] = filter->fEMCALMatrix[i] ;
   }
 } 
@@ -131,94 +130,299 @@ void AliAnalysisTaskCaloFilter::UserCreateOutputObjects()
        
   fEMCALGeo =  AliEMCALGeometry::GetInstance(fEMCALGeoName) ;  
   
-  OpenFile(1);
-  
-  fEventNtuple = new TNtuple("EventSelection","EventSelection", "bPileup:bGoodVertex:bV0AND:trackMult");
-  PostData(1, fEventNtuple);
-
 }  
 
-//__________________________________________________
+//____________________________________________________________
 void AliAnalysisTaskCaloFilter::UserExec(Option_t */*option*/)
 {
   // Execute analysis for current event
   // Copy input ESD or AOD header, vertex, CaloClusters and CaloCells to output AOD
-
+  
   if (fDebug > 0)  
     printf("CaloFilter: Analysing event # %d\n", (Int_t)Entry());
   
   AliVEvent* event = InputEvent();
-  if(!event) {
+  if(!event) 
+  {
     printf("AliAnalysisTaskCaloFilter::UserExec - This event does not contain Input?");
     return;
   }
-
+  
+  // Select the event
+  
+  if(!AcceptEventVertex()) return;
+  if(!AcceptEventEMCAL())  return;
+  
   //Magic line to write events to file
   AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()->SetFillAOD(fFillAODFile);
-   
-  // cast event, depending on input we will have to use one or the other type of event
-  AliAODEvent* aodevent = dynamic_cast<AliAODEvent*> (event);  
-  AliESDEvent* esdevent = dynamic_cast<AliESDEvent*> (event);
   
-  //-------------------------------------------
-  //Event selection parameters
-  //-------------------------------------------
-  //Is it a pileup event?
-  Bool_t bPileup = event->IsPileupFromSPD(3, 0.8, 3., 2., 5.); //Default values, if not it does not compile
-  //Bool_t bPileup = event->IsPileupFromSPD(); 
-  //if(bPileup) return kFALSE;
-  Int_t  trackMult    = 0;
-  Bool_t bV0AND       = kFALSE;
-  Bool_t bGoodVertex  = kFALSE;
-  if(esdevent){
-    //Get track multiplicity
-    Int_t nTracks   = InputEvent()->GetNumberOfTracks() ;
-    for (Int_t itrack =  0; itrack <  nTracks; itrack++) {////////////// track loop
-      AliVTrack * track = (AliVTrack*)InputEvent()->GetTrack(itrack) ; // retrieve track from esd
-      if(!fESDtrackCuts->AcceptTrack((AliESDtrack*)track)) continue;
-      //Count the tracks in eta < 0.8
-      if(TMath::Abs(track->Eta())< fTrackMultEtaCut) trackMult++;
-    }  
-    //V0AND?   
-    bV0AND = fTriggerAnalysis->IsOfflineTriggerFired(esdevent, AliTriggerAnalysis::kV0AND);
-    //if(!bV0AND) return kFALSE;
-    //Well reconstructed vertex
-    bGoodVertex = CheckForPrimaryVertex();
-    //if(!bGoodVertex) return kFALSE;
+  Int_t nVertices = event->GetNumberOfV0s()+event->GetNumberOfCascades();;
+  Int_t nCaloClus = event->GetNumberOfCaloClusters();
+  Int_t nTracks   = event->GetNumberOfTracks();
+  
+  AODEvent()->ResetStd(nTracks, nVertices, 0, 0, 0, nCaloClus, 0, 0);
+  
+  //
+  FillAODHeader();
+  
+  //
+  FillAODVertices();
+  
+  //
+  FillAODTracks();
+  
+  //
+  CorrectionsInEMCAL();
+  
+  //
+  FillAODCaloClusters();
+  
+  //
+  FillAODCaloCells();
+  
+}
+
+//___________________________________________________
+Bool_t AliAnalysisTaskCaloFilter::AcceptEventVertex()
+{
+  // Accept event with good vertex
+  
+  Double_t v[3];
+  InputEvent()->GetPrimaryVertex()->GetXYZ(v) ;
+  
+  if(TMath::Abs(v[2]) > fVzCut) return kFALSE ;
+  
+  return CheckForPrimaryVertex();
+}  
+
+//__________________________________________________
+Bool_t AliAnalysisTaskCaloFilter::AcceptEventEMCAL()
+{
+  // Accept event given there is a cluster with enough energy
+  
+  if(fCaloFilter!=kEMCAL) return kTRUE; // accept all
+  
+  Int_t           nCluster = InputEvent() -> GetNumberOfCaloClusters();
+  AliVCaloCells * caloCell = InputEvent() -> GetEMCALCells();
+  Int_t           bc       = InputEvent() -> GetBunchCrossNumber();
+  
+  for(Int_t icalo = 0; icalo < nCluster; icalo++)
+  {
+    AliESDCaloCluster *clus = (AliESDCaloCluster*) (InputEvent()->GetCaloCluster(icalo));
+    
+    if( ( clus->IsEMCAL() ) && ( clus->GetNCells() > fNcellsCut ) && ( clus->E() > fEnergyCut ) &&
+       fEMCALRecoUtils->IsGoodCluster(clus,fEMCALGeo,caloCell,bc))
+    { 
+      
+      // printf("Accept event %d, E %2.2f > %2.2f, nCells %d > %d \n", 
+      //        (Int_t) Entry(),clus->E(), fEnergyCut, clus->GetNCells(), fNcellsCut);
+      
+      return kTRUE;
+    }
     
-  }//ESDs
+  }// loop
   
-  if(fDebug > 0)
-    printf("AliAnalysisTaskCaloFilter::UserExec() - PileUp %d, Good Vertex %d, v0AND %d, Track Mult in |eta| < %2.1f = %d\n",
-           bPileup,bGoodVertex,bV0AND, fTrackMultEtaCut, trackMult);
+  return kFALSE;
   
-  //Put bools with event selection parameters in a TNtuple
-  //Int_t eventSelection[] = {bPileup,bGoodVertex,bV0AND,trackMult};
-  fEventNtuple->Fill(bPileup,bGoodVertex,bV0AND,trackMult);
+}  
+
+//________________________________________________
+void AliAnalysisTaskCaloFilter::FillAODCaloCells()
+{  
+  // Fill EMCAL/PHOS cell info
   
-  //--------------------------------------------------------------------
-  //Set in AOD General Event Parameters, vertex, runnumber, trigger, etc 
-  //-------------------------------------------------------------------
+  AliVEvent * event = InputEvent();
   
-  // set arrays and pointers
+  // EMCAL
+  if ((fCaloFilter==kBoth ||  fCaloFilter==kEMCAL) && event->GetEMCALCells()) 
+  { // protection against missing ESD information
+    AliVCaloCells &eventEMcells = *(event->GetEMCALCells());
+    Int_t nEMcell = eventEMcells.GetNumberOfCells() ;
+    
+    AliAODCaloCells &aodEMcells = *(AODEvent()->GetEMCALCells());
+    aodEMcells.CreateContainer(nEMcell);
+    aodEMcells.SetType(AliVCaloCells::kEMCALCell);
+    Double_t calibFactor = 1.;   
+    for (Int_t iCell = 0; iCell < nEMcell; iCell++) 
+    { 
+      Int_t imod = -1, iphi =-1, ieta=-1,iTower = -1, iIphi = -1, iIeta = -1; 
+      fEMCALGeo->GetCellIndex(eventEMcells.GetCellNumber(iCell),imod,iTower,iIphi,iIeta); 
+      fEMCALGeo->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,iphi,ieta);      
+      
+      if(fCorrect && fEMCALRecoUtils->IsRecalibrationOn())
+      { 
+        calibFactor = fEMCALRecoUtils->GetEMCALChannelRecalibrationFactor(imod,ieta,iphi);
+      }
+      
+      if(!fEMCALRecoUtils->GetEMCALChannelStatus(imod, ieta, iphi))
+      { //Channel is not declared as bad
+        aodEMcells.SetCell(iCell,eventEMcells.GetCellNumber(iCell),eventEMcells.GetAmplitude(iCell)*calibFactor,
+                           eventEMcells.GetTime(iCell),eventEMcells.GetMCLabel(iCell),eventEMcells.GetEFraction(iCell));
+        //printf("GOOD channel\n");
+      }
+      else 
+      {
+        aodEMcells.SetCell(iCell,eventEMcells.GetCellNumber(iCell),0,-1,-1,0);
+        //printf("BAD channel\n");
+      }
+    }
+    aodEMcells.Sort();
+  }
+  
+  // PHOS 
+  if ((fCaloFilter==kBoth ||  fCaloFilter==kPHOS) && event->GetPHOSCells()) 
+  { // protection against missing ESD information
+    AliVCaloCells &eventPHcells = *(event->GetPHOSCells());
+    Int_t nPHcell = eventPHcells.GetNumberOfCells() ;
+    
+    AliAODCaloCells &aodPHcells = *(AODEvent()->GetPHOSCells());
+    aodPHcells.CreateContainer(nPHcell);
+    aodPHcells.SetType(AliVCaloCells::kPHOSCell);
+    
+    for (Int_t iCell = 0; iCell < nPHcell; iCell++) 
+    {      
+      aodPHcells.SetCell(iCell,eventPHcells.GetCellNumber(iCell),eventPHcells.GetAmplitude(iCell),
+                         eventPHcells.GetTime(iCell),eventPHcells.GetMCLabel(iCell),eventPHcells.GetEFraction(iCell));
+    }
+    
+    aodPHcells.Sort();
+  }
+}
+
+
+//___________________________________________________
+void AliAnalysisTaskCaloFilter::FillAODCaloClusters()
+{
+  // Fill the AOD with caloclusters
+  
+  AliVEvent * event = InputEvent();
+  
+  // Access to the AOD container of clusters
+  
+  TClonesArray &caloClusters = *(AODEvent()->GetCaloClusters());
+  Int_t jClusters=0;
   Float_t  posF[3]  ;
-  Double_t pos[3]   ;
-  Double_t covVtx[6];
-  for (Int_t i = 0; i < 6; i++)  covVtx[i] = 0.;
+  
+  Int_t nCaloClus = event->GetNumberOfCaloClusters();
+  for (Int_t iClust=0; iClust<nCaloClus; ++iClust) 
+  {
+    
+    AliVCluster * cluster = event->GetCaloCluster(iClust);
+    
+    //Check which calorimeter information we want to keep.
+    
+    if(fCaloFilter!=kBoth)
+    {
+      if     (fCaloFilter==kPHOS  && cluster->IsEMCAL()) continue ;
+      else if(fCaloFilter==kEMCAL && cluster->IsPHOS())  continue ;
+    }  
+    
+    // Get original residuals, in case of previous recalculation, reset them 
+    Float_t dR = cluster->GetTrackDx();
+    Float_t dZ = cluster->GetTrackDz();
+    
+    if(DebugLevel() > 2)
+      printf("Original residuals : dZ %f, dR %f\n ",dZ, dR);
+    
+    //--------------------------------------------------------------
+    //If EMCAL and corrections done, get the new matching parameters, do not copy noisy clusters
+    if(cluster->IsEMCAL() && fCorrect)
+    {
+      if(DebugLevel() > 2)
+        printf("Check cluster %d for bad channels and close to border\n",cluster->GetID());
+      
+      if(fEMCALRecoUtils->ClusterContainsBadChannel(fEMCALGeo,cluster->GetCellsAbsId(), cluster->GetNCells())) continue;       
+      
+      if(fEMCALRecoUtils->IsExoticCluster(cluster, InputEvent()->GetEMCALCells(),InputEvent()->GetBunchCrossNumber())) continue;       
       
+      fEMCALRecoUtils->GetMatchedResiduals(cluster->GetID(),dR,dZ);
+      cluster->SetTrackDistance(dR,dZ);
+    }
+    
+    if(DebugLevel() > 2)
+    {
+      if(cluster->IsEMCAL()) printf("EMCAL Track-Cluster Residuals : dZ %f, dR %f\n ",dZ, dR);
+      if(cluster->IsPHOS())  printf("PHOS  Track-Cluster Residuals : dZ %f, dR %f\n ",dZ, dR);
+    }
+    
+    //--------------------------------------------------------------
+    
+    //Now fill AODs
+    
+    Int_t id       = cluster->GetID();
+    Float_t energy = cluster->E();
+    cluster->GetPosition(posF);
+    
+    AliAODCaloCluster *caloCluster = new(caloClusters[jClusters++]) 
+    AliAODCaloCluster(id,
+                      cluster->GetNLabels(),
+                      cluster->GetLabels(),
+                      energy,
+                      posF,
+                      NULL,
+                      cluster->GetType());
+    
+    caloCluster->SetCaloCluster(cluster->GetDistanceToBadChannel(),
+                                cluster->GetDispersion(),
+                                cluster->GetM20(), cluster->GetM02(),
+                                -1,  
+                                cluster->GetNExMax(),cluster->GetTOF()) ;
+    
+    caloCluster->SetPIDFromESD(cluster->GetPID());
+    caloCluster->SetNCells(cluster->GetNCells());
+    caloCluster->SetCellsAbsId(cluster->GetCellsAbsId());
+    caloCluster->SetCellsAmplitudeFraction(cluster->GetCellsAmplitudeFraction());
+    caloCluster->SetTrackDistance(dR, dZ);
+    
+    if(DebugLevel() > 2)
+    { 
+      printf("Filter, aod     : i %d, E %f, dispersion %f, m02 %f, m20 %f\n",caloCluster->GetID(),caloCluster->E(),
+             caloCluster->GetDispersion(),caloCluster->GetM02(),caloCluster->GetM20());
+      caloCluster->GetPosition(posF);
+      printf("Filter, aod     : i %d, x %f, y %f, z %f\n",caloCluster->GetID(), posF[0], posF[1], posF[2]);
+    }    
+    
+    //Matched tracks, just to know if there was any match, the track pointer is useless if tracks not stored
+    if(TMath::Abs(dR) < 990 && TMath::Abs(dZ) < 990) 
+    { //Default value in PHOS 999, in EMCAL 1024, why?
+      caloCluster->AddTrackMatched(new AliAODTrack); 
+    }
+    // TO DO, in case Tracks available, think how to put the matched track in AOD
+  }
+  
+  caloClusters.Expand(jClusters); // resize TObjArray to 'remove' slots  
+  
+}
+
+
+//______________________________________________
+void AliAnalysisTaskCaloFilter::FillAODHeader()
+{
+  // AOD header copy
+  
+  AliVEvent* event = InputEvent();
+  AliAODEvent* aodevent = dynamic_cast<AliAODEvent*> (event);  
+  AliESDEvent* esdevent = dynamic_cast<AliESDEvent*> (event);
+  
   AliAODHeader* header = AODEvent()->GetHeader();
   
+  // Copy from AODs
+  if(aodevent)
+  {
+    *header = *(aodevent->GetHeader());
+    return;
+  }
+  
+  // Copy from ESDs
+  
   header->SetRunNumber(event->GetRunNumber());
   
-  if(esdevent){
-    TTree* tree = fInputHandler->GetTree();
-    if (tree) {
-      TFile* file = tree->GetCurrentFile();
-      if (file) header->SetESDFileName(file->GetName());
-    }
+  TTree* tree = fInputHandler->GetTree();
+  if (tree) 
+  {
+    TFile* file = tree->GetCurrentFile();
+    if (file) header->SetESDFileName(file->GetName());
   }
-  else if (aodevent) header->SetESDFileName(aodevent->GetHeader()->GetESDFileName());
   
   header->SetBunchCrossNumber(event->GetBunchCrossNumber());
   header->SetOrbitNumber(event->GetOrbitNumber());
@@ -226,7 +430,8 @@ void AliAnalysisTaskCaloFilter::UserExec(Option_t */*option*/)
   header->SetEventType(event->GetEventType());
   
   //Centrality
-  if(event->GetCentrality()){
+  if(event->GetCentrality())
+  {
     header->SetCentrality(new AliCentrality(*(event->GetCentrality())));
   }
   else{
@@ -235,24 +440,16 @@ void AliAnalysisTaskCaloFilter::UserExec(Option_t */*option*/)
   
   //Trigger  
   header->SetOfflineTrigger(fInputHandler->IsEventSelected()); // propagate the decision of the physics selection
-  if      (esdevent) header->SetFiredTriggerClasses(esdevent->GetFiredTriggerClasses());
-  else if (aodevent) header->SetFiredTriggerClasses(aodevent->GetFiredTriggerClasses());
+  header->SetFiredTriggerClasses(esdevent->GetFiredTriggerClasses());
   header->SetTriggerMask(event->GetTriggerMask()); 
   header->SetTriggerCluster(event->GetTriggerCluster());
-  if(esdevent){
-    header->SetL0TriggerInputs(esdevent->GetHeader()->GetL0TriggerInputs());    
-    header->SetL1TriggerInputs(esdevent->GetHeader()->GetL1TriggerInputs());    
-    header->SetL2TriggerInputs(esdevent->GetHeader()->GetL2TriggerInputs());    
-  }
-  else if (aodevent){
-    header->SetL0TriggerInputs(aodevent->GetHeader()->GetL0TriggerInputs());    
-    header->SetL1TriggerInputs(aodevent->GetHeader()->GetL1TriggerInputs());    
-    header->SetL2TriggerInputs(aodevent->GetHeader()->GetL2TriggerInputs());    
-  }
-
+  header->SetL0TriggerInputs(esdevent->GetHeader()->GetL0TriggerInputs());    
+  header->SetL1TriggerInputs(esdevent->GetHeader()->GetL1TriggerInputs());    
+  header->SetL2TriggerInputs(esdevent->GetHeader()->GetL2TriggerInputs());    
+  
   header->SetMagneticField(event->GetMagneticField());
   //header->SetMuonMagFieldScale(esdevent->GetCurrentDip()/6000.); 
-
+  
   header->SetZDCN1Energy(event->GetZDCN1Energy());
   header->SetZDCP1Energy(event->GetZDCP1Energy());
   header->SetZDCN2Energy(event->GetZDCN2Energy());
@@ -263,19 +460,63 @@ void AliAnalysisTaskCaloFilter::UserExec(Option_t */*option*/)
   Float_t diamcov[3];
   event->GetDiamondCovXY(diamcov);
   header->SetDiamond(diamxy,diamcov);
-  if      (esdevent) header->SetDiamondZ(esdevent->GetDiamondZ(),esdevent->GetSigma2DiamondZ());
-  else if (aodevent) header->SetDiamondZ(aodevent->GetDiamondZ(),aodevent->GetSigma2DiamondZ());
+  header->SetDiamondZ(esdevent->GetDiamondZ(),esdevent->GetSigma2DiamondZ());
   
-  //
-  //
-  Int_t nVertices = 1 ;/* = prim. vtx*/;
-  Int_t nCaloClus = event->GetNumberOfCaloClusters();
+}
+
+//_____________________________________________
+void AliAnalysisTaskCaloFilter::FillAODTracks()
+{
+  // AOD track copy
+  
+  if(!fFillTracks) return;
+  
+  AliVEvent* event = InputEvent();
+  AliAODEvent* aodevent = dynamic_cast<AliAODEvent*> (event);  
+  //AliESDEvent* esdevent = dynamic_cast<AliESDEvent*> (event);
+  
+  // Copy from AODs
+  if(aodevent)
+  {
+    TClonesArray* inTracks = aodevent  ->GetTracks();
+    TClonesArray* ouTracks = AODEvent()->GetTracks();
+    
+               new (ouTracks) TClonesArray(*inTracks);
+    
+    return;
+  }
+  
+}  
+
+//_______________________________________________
+void AliAnalysisTaskCaloFilter::FillAODVertices()
+{
+  // Copy vertices
+  
+  AliVEvent* event = InputEvent();
+  AliAODEvent* aodevent = dynamic_cast<AliAODEvent*> (event);  
+  AliESDEvent* esdevent = dynamic_cast<AliESDEvent*> (event);
+  
+  // set arrays and pointers
+  Double_t pos[3]   ;
+  Double_t covVtx[6];
+  for (Int_t i = 0; i < 6; i++)  covVtx[i] = 0.;
+  
+  // Copy from AODs
+  if(aodevent)
+  {
+    TClonesArray* inVertices = aodevent  ->GetVertices();
+    TClonesArray* ouVertices = AODEvent()->GetVertices();
+    
+               new (ouVertices) TClonesArray(*inVertices);
+    return;
+  }
   
-  AODEvent()->ResetStd(0, nVertices, 0, 0, 0, nCaloClus, 0, 0);
+  // Copy from ESDs
   
   // Access to the AOD container of vertices
-  TClonesArray &vertices = *(AODEvent()->GetVertices());
   Int_t jVertices=0;
+  TClonesArray &vertices = *(AODEvent()->GetVertices());
   
   // Add primary vertex. The primary tracks will be defined
   // after the loops on the composite objects (V0, cascades, kinks)
@@ -291,23 +532,25 @@ void AliAnalysisTaskCaloFilter::UserExec(Option_t */*option*/)
   }
   
   AliAODVertex * primary = new(vertices[jVertices++])
-    AliAODVertex(pos, covVtx, chi, NULL, -1, AliAODVertex::kPrimary);
+  AliAODVertex(pos, covVtx, chi, NULL, -1, AliAODVertex::kPrimary);
   primary->SetName(event->GetPrimaryVertex()->GetName());
   primary->SetTitle(event->GetPrimaryVertex()->GetTitle());
   
-  // Access to the AOD container of clusters
-  TClonesArray &caloClusters = *(AODEvent()->GetCaloClusters());
-  Int_t jClusters=0;
-  
-  //-------------------------------------------
-  //Do Corrections in EMCAL 
-  //-------------------------------------------
+}
+
+//__________________________________________________
+void AliAnalysisTaskCaloFilter::CorrectionsInEMCAL()
+{
   //If EMCAL, and requested, correct energy, position ...
+  
   //Need to do this in a separate loop before filling the ESDs because of the track matching recalculations
-  if(fCorrect && (fCaloFilter==kEMCAL || fCaloFilter==kBoth) ) {
-    
-    if(!fGeoMatrixSet){
-      if(fLoadEMCALMatrices){
+  
+  if(fCorrect && (fCaloFilter==kEMCAL || fCaloFilter==kBoth) ) 
+  {
+    if(!fGeoMatrixSet)
+    {
+      if(fLoadEMCALMatrices)
+      {
         printf("AliAnalysisTaskCaloFilter::UserExec() - Load user defined EMCAL geometry matrices\n");
         for(Int_t mod=0; mod < (fEMCALGeo->GetEMCGeometry())->GetNumberOfSuperModules(); mod++){
           if(fEMCALMatrix[mod]){
@@ -318,21 +561,26 @@ void AliAnalysisTaskCaloFilter::UserExec(Option_t */*option*/)
           fGeoMatrixSet=kTRUE;
         }//SM loop
       }//Load matrices
-      else if(!gGeoManager){
+      else if(!gGeoManager)
+      {
         printf("AliAnalysisTaskCaloFilter::UserExec() - Get geo matrices from data\n");
         //Still not implemented in AOD, just a workaround to be able to work at least with ESDs        
-        if(!strcmp(event->GetName(),"AliAODEvent")) {
+        if(!strcmp(InputEvent()->GetName(),"AliAODEvent")) 
+        {
           if(DebugLevel() > 1) 
             printf("AliAnalysisTaskCaloFilter Use ideal geometry, values geometry matrix not kept in AODs.\n");
         }//AOD
-        else { 
+        else 
+        {      
           if(DebugLevel() > 1) printf("AliAnalysisTaskCaloFilter Load Misaligned matrices. \n");
-          AliESDEvent* esd = dynamic_cast<AliESDEvent*>(event) ;
-          if(!esd) {
+          AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent()) ;
+          if(!esd) 
+          {
             printf("AliAnalysisTaskCaloFilter::UserExec() - This event does not contain ESDs?");
             return;
           }
-          for(Int_t mod=0; mod < (fEMCALGeo->GetEMCGeometry())->GetNumberOfSuperModules(); mod++){
+          for(Int_t mod=0; mod < (fEMCALGeo->GetEMCGeometry())->GetNumberOfSuperModules(); mod++)
+          {
             //if(DebugLevel() > 1) 
             esd->GetEMCALMatrix(mod)->Print();
             if(esd->GetEMCALMatrix(mod)) fEMCALGeo->SetMisalMatrix(esd->GetEMCALMatrix(mod),mod) ;
@@ -340,23 +588,23 @@ void AliAnalysisTaskCaloFilter::UserExec(Option_t */*option*/)
           fGeoMatrixSet=kTRUE;
         }//ESD
       }//Load matrices from Data 
-
+      
     }//first event
     
     //Cluster Loop
-    for (Int_t iClust=0; iClust<nCaloClus; ++iClust) {
+    Int_t nCaloClus = InputEvent()->GetNumberOfCaloClusters();
+    
+    for (Int_t iClust=0; iClust<nCaloClus; ++iClust) 
+    {
+      AliVCluster * cluster = InputEvent()->GetCaloCluster(iClust);
       
-      AliVCluster * cluster = event->GetCaloCluster(iClust);
       if(cluster->IsPHOS()) continue ;
-
+      
       Float_t position[]={0,0,0};
       if(DebugLevel() > 2)
         printf("Check cluster %d for bad channels and close to border\n",cluster->GetID());
       if(fEMCALRecoUtils->ClusterContainsBadChannel(fEMCALGeo,cluster->GetCellsAbsId(), cluster->GetNCells())) continue;       
-      //      if(!fEMCALRecoUtils->CheckCellFiducialRegion(fEMCALGeo, cluster, event->GetEMCALCells())) {
-      //        printf("Finally reject\n");
-      //        continue;
-      //      }
+      
       if(DebugLevel() > 2)
       { 
         printf("Filter, before  : i %d, E %f, dispersion %f, m02 %f, m20 %f, distToBad %f\n",iClust,cluster->E(),
@@ -366,15 +614,16 @@ void AliAnalysisTaskCaloFilter::UserExec(Option_t */*option*/)
       }
       
       //Recalculate distance to bad channels, if new list of bad channels provided
-      fEMCALRecoUtils->RecalculateClusterDistanceToBadChannel(fEMCALGeo, event->GetEMCALCells(), cluster);
-
-      if(fEMCALRecoUtils->IsRecalibrationOn()) {
-        fEMCALRecoUtils->RecalibrateClusterEnergy(fEMCALGeo, cluster, event->GetEMCALCells());
-        fEMCALRecoUtils->RecalculateClusterShowerShapeParameters(fEMCALGeo, event->GetEMCALCells(),cluster);
+      fEMCALRecoUtils->RecalculateClusterDistanceToBadChannel(fEMCALGeo, InputEvent()->GetEMCALCells(), cluster);
+      
+      if(fEMCALRecoUtils->IsRecalibrationOn()) 
+      {
+        fEMCALRecoUtils->RecalibrateClusterEnergy(fEMCALGeo, cluster, InputEvent()->GetEMCALCells());
+        fEMCALRecoUtils->RecalculateClusterShowerShapeParameters(fEMCALGeo, InputEvent()->GetEMCALCells(),cluster);
         fEMCALRecoUtils->RecalculateClusterPID(cluster);
       }
-            
-      fEMCALRecoUtils->RecalculateClusterPosition(fEMCALGeo, event->GetEMCALCells(),cluster);
+      
+      fEMCALRecoUtils->RecalculateClusterPosition(fEMCALGeo, InputEvent()->GetEMCALCells(),cluster);
       
       if(DebugLevel() > 2)
       { 
@@ -387,230 +636,72 @@ void AliAnalysisTaskCaloFilter::UserExec(Option_t */*option*/)
       cluster->SetE(fEMCALRecoUtils->CorrectClusterEnergyLinearity(cluster));
       
     }
+    
     //Recalculate track-matching
-    fEMCALRecoUtils->FindMatches(event,0,fEMCALGeo);
+    fEMCALRecoUtils->FindMatches(InputEvent(),0,fEMCALGeo);
     
   } // corrections in EMCAL
-  
-  //-------------------------------------------
-  // Now loop on clusters to fill AODs
-  //-------------------------------------------
-  for (Int_t iClust=0; iClust<nCaloClus; ++iClust) {
-    
-    AliVCluster * cluster = event->GetCaloCluster(iClust);
-    
-    //Check which calorimeter information we want to keep.
-    
-    if(fCaloFilter!=kBoth){
-      if     (fCaloFilter==kPHOS  && cluster->IsEMCAL()) continue ;
-      else if(fCaloFilter==kEMCAL && cluster->IsPHOS())  continue ;
-    }  
-    
-    //Temporary trick, FIXME
-    Float_t dR = cluster->GetTrackDx();
-    Float_t dZ = cluster->GetTrackDz();
-    if(DebugLevel() > 2)
-      printf("Original residuals : dZ %f, dR %f\n ",dZ, dR);
-    //--------------------------------------------------------------
-    //If EMCAL and corrections done, get the new matching parameters, do not copy noisy clusters
-    if(cluster->IsEMCAL() && fCorrect && esdevent){
-      if(DebugLevel() > 2)
-        printf("Check cluster %d for bad channels and close to border\n",cluster->GetID());
-      if(fEMCALRecoUtils->ClusterContainsBadChannel(fEMCALGeo,cluster->GetCellsAbsId(), cluster->GetNCells())) continue;       
-      
-      //      if(!fEMCALRecoUtils->CheckCellFiducialRegion(fEMCALGeo, cluster, event->GetEMCALCells())) {
-      //        printf("Finally reject\n");
-      //        continue;
-      //      }
-
-      if(fEMCALRecoUtils->IsExoticCluster(cluster, InputEvent()->GetEMCALCells(),InputEvent()->GetBunchCrossNumber())) continue;       
-
-      fEMCALRecoUtils->GetMatchedResiduals(cluster->GetID(),dR,dZ);
-      cluster->SetTrackDistance(dR,dZ);
-    }
-    
-    if(DebugLevel() > 2){
-      if(cluster->IsEMCAL()) printf("EMCAL Track-Cluster Residuals : dZ %f, dR %f\n ",dZ, dR);
-      if(cluster->IsPHOS())  printf("PHOS  Track-Cluster Residuals : dZ %f, dR %f\n ",dZ, dR);
-    }
-    
-    //--------------------------------------------------------------
-
-    //Now fill AODs
-    
-    Int_t id       = cluster->GetID();
-    Float_t energy = cluster->E();
-    cluster->GetPosition(posF);
-    
-    AliAODCaloCluster *caloCluster = new(caloClusters[jClusters++]) 
-      AliAODCaloCluster(id,
-                       cluster->GetNLabels(),
-                       cluster->GetLabels(),
-                       energy,
-                       posF,
-                       NULL,
-                       cluster->GetType());
-    
-    caloCluster->SetChi2(dZ);//Temporary trick, FIXME
-    caloCluster->SetCaloCluster(cluster->GetDistanceToBadChannel(),
-                               cluster->GetDispersion(),
-                               cluster->GetM20(), cluster->GetM02(),
-                               dR,  //Temporary trick, FIXME
-                               cluster->GetNExMax(),cluster->GetTOF()) ;
-    
-    caloCluster->SetPIDFromESD(cluster->GetPID());
-    caloCluster->SetNCells(cluster->GetNCells());
-    caloCluster->SetCellsAbsId(cluster->GetCellsAbsId());
-    caloCluster->SetCellsAmplitudeFraction(cluster->GetCellsAmplitudeFraction());
-    
-    if(DebugLevel() > 2)
-    { 
-      printf("Filter, aod     : i %d, E %f, dispersion %f, m02 %f, m20 %f\n",caloCluster->GetID(),caloCluster->E(),
-             caloCluster->GetDispersion(),caloCluster->GetM02(),caloCluster->GetM20());
-      caloCluster->GetPosition(posF);
-      printf("Filter, aod     : i %d, x %f, y %f, z %f\n",caloCluster->GetID(), posF[0], posF[1], posF[2]);
-    }    
-    
-    //Matched tracks, just to know if there was any match, the track pointer is useless.
-    //Temporary trick, FIXME
-    if(esdevent){
-      if(TMath::Abs(dR) < 990 && TMath::Abs(dZ) < 990) { //Default value in PHOS 999, in EMCAL 1024, why?
-        if(DebugLevel() > 2) 
-          printf("*** Cluster Track-Matched *** dR %f, dZ %f\n",caloCluster->GetEmcCpvDistance(),caloCluster->Chi2());
-        caloCluster->AddTrackMatched(new AliAODTrack); 
-      }// fill the array with one entry to signal a possible match
-      //TArrayI* matchedT =    ((AliESDCaloCluster*)cluster)->GetTracksMatched();
-      //if (InputEvent()->GetNumberOfTracks() > 0 && matchedT && cluster->GetTrackMatchedIndex() >= 0) {       
-      //  for (Int_t im = 0; im < matchedT->GetSize(); im++) {
-      //    Int_t iESDtrack = matchedT->At(im);;
-      //    if ((AliVTrack*)InputEvent()->GetTrack(iESDtrack) != 0) {
-      //      caloCluster->AddTrackMatched((AliVTrack*)InputEvent()->GetTrack(iESDtrack));
-      //    }
-      //  }
-      //}// There is at least a match with a track
-    }
-  } 
-  caloClusters.Expand(jClusters); // resize TObjArray to 'remove' slots for pseudo clusters     
-  // end of loop on calo clusters
-  
-  // fill EMCAL cell info
-  if ((fCaloFilter==kBoth ||  fCaloFilter==kEMCAL) && event->GetEMCALCells()) { // protection against missing ESD information
-    AliVCaloCells &eventEMcells = *(event->GetEMCALCells());
-    Int_t nEMcell = eventEMcells.GetNumberOfCells() ;
-    
-    AliAODCaloCells &aodEMcells = *(AODEvent()->GetEMCALCells());
-    aodEMcells.CreateContainer(nEMcell);
-    aodEMcells.SetType(AliVCaloCells::kEMCALCell);
-    Double_t calibFactor = 1.;   
-    for (Int_t iCell = 0; iCell < nEMcell; iCell++) { 
-      Int_t imod = -1, iphi =-1, ieta=-1,iTower = -1, iIphi = -1, iIeta = -1; 
-      fEMCALGeo->GetCellIndex(eventEMcells.GetCellNumber(iCell),imod,iTower,iIphi,iIeta); 
-      fEMCALGeo->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,iphi,ieta);      
-      
-      if(fCorrect && fEMCALRecoUtils->IsRecalibrationOn()){ 
-        calibFactor = fEMCALRecoUtils->GetEMCALChannelRecalibrationFactor(imod,ieta,iphi);
-      }
-      
-      if(!fEMCALRecoUtils->GetEMCALChannelStatus(imod, ieta, iphi)){ //Channel is not declared as bad
-        aodEMcells.SetCell(iCell,eventEMcells.GetCellNumber(iCell),eventEMcells.GetAmplitude(iCell)*calibFactor,
-                           eventEMcells.GetTime(iCell),eventEMcells.GetMCLabel(iCell),eventEMcells.GetEFraction(iCell));
-        //printf("GOOD channel\n");
-      }
-      else {
-        aodEMcells.SetCell(iCell,eventEMcells.GetCellNumber(iCell),0,-1,-1,0);
-        //printf("BAD channel\n");
-      }
-    }
-    aodEMcells.Sort();
-  }
-  
-  // fill PHOS cell info
-  if ((fCaloFilter==kBoth ||  fCaloFilter==kPHOS) && event->GetPHOSCells()) { // protection against missing ESD information
-    AliVCaloCells &eventPHcells = *(event->GetPHOSCells());
-    Int_t nPHcell = eventPHcells.GetNumberOfCells() ;
-    
-    AliAODCaloCells &aodPHcells = *(AODEvent()->GetPHOSCells());
-    aodPHcells.CreateContainer(nPHcell);
-    aodPHcells.SetType(AliVCaloCells::kPHOSCell);
-    for (Int_t iCell = 0; iCell < nPHcell; iCell++) {      
-      aodPHcells.SetCell(iCell,eventPHcells.GetCellNumber(iCell),eventPHcells.GetAmplitude(iCell),
-                         eventPHcells.GetTime(iCell),eventPHcells.GetMCLabel(iCell),eventPHcells.GetEFraction(iCell));
-    }
-    aodPHcells.Sort();
-  }
-  
-   PostData(1, fEventNtuple);
-  
-  //return;
 }
 
-//____________________________________________________________________________
-Bool_t AliAnalysisTaskCaloFilter::CheckForPrimaryVertex(){
+//_______________________________________________________
+Bool_t AliAnalysisTaskCaloFilter::CheckForPrimaryVertex()
+{
   //Check if the vertex was well reconstructed, copy from V0Reader of conversion group
   //It only works for ESDs
   
   AliESDEvent * event = dynamic_cast<AliESDEvent*> (InputEvent());
-  if(!event) return kFALSE;
   
-  if(event->GetPrimaryVertexTracks()->GetNContributors() > 0) {
+  // AODs
+  if(!event) 
+  {
+    // Check that the vertex is not (0,0,0)
+    Double_t v[3];
+    InputEvent()->GetPrimaryVertex()->GetXYZ(v) ;
+    
+    if(TMath::Abs(v[2]) < 1e-6 && 
+       TMath::Abs(v[1]) < 1e-6 && 
+       TMath::Abs(v[0]) < 1e-6 ) return kFALSE ;
+    
+    return kTRUE;
+  }
+  
+  // ESDs
+  if(event->GetPrimaryVertexTracks()->GetNContributors() > 0)
+  {
     return kTRUE;
   }
   
-  if(event->GetPrimaryVertexTracks()->GetNContributors() < 1) {
+  if(event->GetPrimaryVertexTracks()->GetNContributors() < 1) 
+  {
     // SPD vertex
-    if(event->GetPrimaryVertexSPD()->GetNContributors() > 0) {
+    if(event->GetPrimaryVertexSPD()->GetNContributors() > 0) 
+    {
       //cout<<"spd vertex type::"<< fESDEvent->GetPrimaryVertex()->GetName() << endl;
       return kTRUE;
       
     }
-    if(event->GetPrimaryVertexSPD()->GetNContributors() < 1) {
+    if(event->GetPrimaryVertexSPD()->GetNContributors() < 1) 
+    {
       //      cout<<"bad vertex type::"<< fESDEvent->GetPrimaryVertex()->GetName() << endl;
       return kFALSE;
     }
   }
   return kFALSE;
-
+  
 }
 
-
-//_____________________________________________________
-void AliAnalysisTaskCaloFilter::PrintInfo(){
-
+//_________________________________________
+void AliAnalysisTaskCaloFilter::PrintInfo()
+{
   //Print settings
-
+  
   printf("TASK: AnalysisCaloFilter \n");
   printf("\t Not only filter, correct Clusters? %d\n",fCorrect);
   printf("\t Calorimeter Filtering Option     ? %d\n",fCaloFilter);
   //printf("\t Use handmade geo matrices?   EMCAL %d, PHOS %d\n",fLoadEMCALMatrices, fLoadPHOSMatrices);
   printf("\t Use handmade geo matrices?   EMCAL %d, PHOS 0\n",fLoadEMCALMatrices);
-}
-
-//_____________________________________________________
-//void AliAnalysisTaskCaloFilter::LocalInit()
-//{
-//     // Local Initialization
-//     
-//     // Create cuts/param objects and publish to slot
-//     const Int_t buffersize = 255;
-//     char onePar[buffersize] ;
-//     fCuts = new TList();
-//  
-//     snprintf(onePar,buffersize, "Calorimeter Filtering Option %d", fCaloFilter) ;
-//     fCuts->Add(new TObjString(onePar));
-//     snprintf(onePar,buffersize, "Not only filter but correct? %d cells;", fCorrect) ;
-//     fCuts->Add(new TObjString(onePar));
-//  
-//     // Post Data
-//     PostData(2, fCuts);
-//     
-//}
-
-
-//__________________________________________________
-void AliAnalysisTaskCaloFilter::Terminate(Option_t */*option*/)
-{
-  // Terminate analysis
-  //
-    if (fDebug > 1) printf("AnalysisCaloFilter: Terminate() \n");
+  printf("\t Fill AOD file? %d\n", fFillAODFile);
+  printf("\t Fill Tracks? %d\n"  , fFillTracks);
+  printf("Event Selection : EMCAL min E %f, EMCAL NCells %d, Vertex %f\n",fEnergyCut,fNcellsCut,fVzCut);
 }
 
index 04f886c992d8b31d018710600b289dd17bfe2ee5..ab575f7b6a74a636d8ff5627eea3bb9cf00f0dde 100644 (file)
@@ -9,19 +9,15 @@
 // PHOS or both, creating the corresponing AODCaloClusters
 // and AODCaloCells.
 // Keep also the AODHeader information and the vertex.
-// Needed for calorimeter calibration.
+// Keep tracks if requested
 // Copy of AliAnalysisTaskESDfilter.
 // Author: Gustavo Conesa Balbastre (INFN - Frascati)
 //////////////////////////////////////////////////////////
 
-class TList;
-
 #include "AliAnalysisTaskSE.h"
 class AliEMCALRecoUtils;
 class AliEMCALGeometry;
-class AliESDtrackCuts;
-class AliTriggerAnalysis;
-class TNtuple;
+
 class AliAnalysisTaskCaloFilter : public AliAnalysisTaskSE
 {
  public:
@@ -35,53 +31,70 @@ class AliAnalysisTaskCaloFilter : public AliAnalysisTaskSE
   virtual void   Init();
   virtual void   LocalInit() { Init() ; }
   virtual void   UserExec(Option_t *option);
-  virtual void   Terminate(Option_t *option);
-      
-  //Geometry methods
+        
+  Bool_t  AcceptEventEMCAL();
+  
+  Bool_t  AcceptEventVertex();
+  
+  Bool_t  CheckForPrimaryVertex();
+  
+  void    CorrectionsInEMCAL();
+  
+  void    FillAODHeader();
+
+  void    FillAODCaloCells();
+  
+  void    FillAODCaloClusters();
   
-  void SetEMCALGeometryName(TString name)                  { fEMCALGeoName = name        ; }
-  TString EMCALGeometryName()                       const  { return fEMCALGeoName        ; }
+  void    FillAODTracks();
   
-  void SwitchOnLoadOwnEMCALGeometryMatrices()              { fLoadEMCALMatrices = kTRUE  ; }
-  void SwitchOffLoadOwnEMCALGeometryMatrices()             { fLoadEMCALMatrices = kFALSE ; }
-  void SetEMCALGeometryMatrixInSM(TGeoHMatrix* m, Int_t i) { fEMCALMatrix[i]    = m      ; }
+  void    FillAODVertices();
+  
+  void    PrintInfo();
   
-  //void SwitchOnLoadOwnPHOSGeometryMatrices()               { fLoadPHOSMatrices = kTRUE  ; }
-  //void SwitchOffLoadOwnPHOSGeometryMatrices()              { fLoadPHOSMatrices = kFALSE ; }
-  //void SetPHOSGeometryMatrixInSM(TGeoHMatrix* m, Int_t i)  { fPHOSMatrix[i]    = m      ; }
+  // * Task settings *
   
-  //Task settings
+  // Geometry methods
   
-  void    FillAODFile(Bool_t yesno)               { fFillAODFile = yesno    ; }
+  void    SetEMCALGeometryName(TString name)                  { fEMCALGeoName = name        ; }
+  TString    EMCALGeometryName()                       const  { return fEMCALGeoName        ; }
+  
+  void    SwitchOnLoadOwnEMCALGeometryMatrices()              { fLoadEMCALMatrices = kTRUE  ; }
+  void    SwitchOffLoadOwnEMCALGeometryMatrices()             { fLoadEMCALMatrices = kFALSE ; }
+  void    SetEMCALGeometryMatrixInSM(TGeoHMatrix* m, Int_t i) { fEMCALMatrix[i]    = m      ; }
+  
+  //void    SwitchOnLoadOwnPHOSGeometryMatrices()               { fLoadPHOSMatrices = kTRUE  ; }
+  //void    SwitchOffLoadOwnPHOSGeometryMatrices()              { fLoadPHOSMatrices = kFALSE ; }
+  //void    SetPHOSGeometryMatrixInSM(TGeoHMatrix* m, Int_t i)  { fPHOSMatrix[i]    = m      ; }
+    
+  void    SwitchOnFillAODFile()                   { fFillAODFile = kTRUE    ; }
+  void    SwitchOffFillAODFile()                  { fFillAODFile = kFALSE   ; }
+
+  void    SwitchOnFillTracks()                    { fFillTracks  = kTRUE    ; }
+  void    SwitchOffFillTracks()                   { fFillTracks  = kFALSE   ; }
   
   enum    caloFilter {kBoth = 0, kEMCAL = 1, kPHOS=2};
   void    SetCaloFilter(Int_t calo)               { fCaloFilter = calo      ; }
   TString GetCaloFilter()                  const  { return fCaloFilter      ; }  
   
-  void   SetEMCALRecoUtils(AliEMCALRecoUtils* ru) { fEMCALRecoUtils = ru    ; }
+  void    SetEMCALRecoUtils(AliEMCALRecoUtils* ru){ fEMCALRecoUtils = ru    ; }
   AliEMCALRecoUtils* GetEMCALRecoUtils()   const  { return fEMCALRecoUtils  ; }
 
   void    SwitchOnClusterCorrection()             { fCorrect = kTRUE        ; }
   void    SwitchOffClusterCorrection()            { fCorrect = kFALSE       ; }
   
-  //Event selection
-  AliESDtrackCuts* GetTrackCuts()          const  { return fESDtrackCuts    ; }
-  void    SetTrackCuts(AliESDtrackCuts * cuts)    { //if (fESDtrackCuts) delete fESDtrackCuts ;
-                                                    fESDtrackCuts = cuts    ; }                
-  
-  Float_t GetTrackMultiplicityEtaCut()     const  { return fTrackMultEtaCut ; }
-  void    SetTrackMultiplicityEtaCut(Float_t eta) { fTrackMultEtaCut = eta  ; }                
-  
-  Bool_t  CheckForPrimaryVertex();
-
-  void    PrintInfo();
-  
   void    SetConfigFileName(TString name)         { fConfigName = name      ; }
   
-private:
+  void    SetEnergyCut(Float_t cut)               { fEnergyCut = cut        ; }
+  Float_t GetEnergyCut()                    const { return fEnergyCut       ; }
+  void    SetNcellsCut(Int_t cut)                 { fNcellsCut = cut        ; }
+  Int_t   GetNcellsCut()                    const { return fNcellsCut       ; }
+  void    SetVzCut(Float_t cut)                   { fVzCut = cut            ; }
+  Int_t   GetVzCut()                        const { return fVzCut           ; }
   
-  //TList* fCuts ;      //! List with analysis cuts
   
+private:
+    
   Int_t               fCaloFilter;        // Calorimeter to filter
   Int_t               fCorrect;           // Recalibrate or recalculate different cluster parameters
   
@@ -89,10 +102,6 @@ private:
   AliEMCALGeometry  * fEMCALGeo;          //! EMCAL geometry
   TString             fEMCALGeoName;      // Name of geometry to use.
   AliEMCALRecoUtils * fEMCALRecoUtils;    // Pointer to EMCAL utilities for clusterization
-
-  AliESDtrackCuts   * fESDtrackCuts;      // Track cut  
-  AliTriggerAnalysis* fTriggerAnalysis;   // Access to trigger selection algorithm for V0AND calculation
-  Float_t             fTrackMultEtaCut;   // Track multiplicity eta cut
   
   //Geometry
   Bool_t              fLoadEMCALMatrices; // Matrices set from configuration, not get from geometry.root or from ESDs/AODs
@@ -100,16 +109,19 @@ private:
   //Bool_t            fLoadPHOSMatrices;  // Matrices set from configuration, not get from geometry.root or from ESDs/AODs
   //TGeoHMatrix *     fPHOSMatrix[5];     // Geometry matrices with alignments
   Bool_t              fGeoMatrixSet;      // Set geometry matrices only once, for the first event.   
-
-  TNtuple           * fEventNtuple;       // NTuple with event parameters 
   
   TString             fConfigName;        // Name of analysis configuration file
   Bool_t              fFillAODFile;       // Fill the output AOD file with clusters 
+  Bool_t              fFillTracks;        // Fill tracks
+  
+  Float_t             fEnergyCut;         //  At least a cluster with this energy in the event
+  Int_t               fNcellsCut;         //  At least a cluster with fNCellsCut cells over fEnergyCut
+  Float_t             fVzCut;             //  At least events with vertex within cut
   
   AliAnalysisTaskCaloFilter(           const AliAnalysisTaskCaloFilter&);
   AliAnalysisTaskCaloFilter& operator=(const AliAnalysisTaskCaloFilter&);
   
-  ClassDef(AliAnalysisTaskCaloFilter, 7); // Analysis task for standard ESD filtering
+  ClassDef(AliAnalysisTaskCaloFilter, 8); // Analysis task for standard ESD filtering
   
 };
 
index df83050b8736f181f09b70533f55b610e2859db3..46d0c4819fd04cffeecd8f453abc6e085cd54508 100644 (file)
@@ -4,102 +4,37 @@ AliAnalysisTaskCaloFilter * AddTaskCaloFilter(){
   //==============================================================================
   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
   if (!mgr) {
-    ::Error("AddTaskPi0", "No analysis manager to connect to.");
+    ::Error("AddTaskCaloFilter", "No analysis manager to connect to.");
     return NULL;
   }  
   
   // Check the analysis type using the event handlers connected to the analysis manager.
   //==============================================================================
   if (!mgr->GetInputEventHandler()) {
-    ::Error("AddTaskEMCALClusterize", "This task requires an input event handler");
+    ::Error("AddTaskCaloFilter", "This task requires an input event handler");
     return NULL;
   }
   
   AliAnalysisTaskCaloFilter * filter = new AliAnalysisTaskCaloFilter("CaloFilter");
-  filter->SelectCollisionCandidates(); 
-  filter->SetCaloFilter(AliAnalysisTaskCaloFilter::kBoth); //kPHOS or kBoth
-  filter->SwitchOnClusterCorrection();
-  //filter->SetDebugLevel(10);
-  AliEMCALRecoUtils * reco = filter->GetEMCALRecoUtils();
-  reco->SetParticleType(AliEMCALRecoUtils::kPhoton);
-  reco->SetW0(4.5);
+  filter->SetCaloFilter(AliAnalysisTaskCaloFilter::kBoth); //kPHOS, kEMCAL or kBoth
+  filter->SwitchOffClusterCorrection();
   
-  reco->SetPositionAlgorithm(AliEMCALRecoUtils::kPosTowerGlobal);
+  filter->SetVzCut(10.);
+  filter->SetEnergyCut(10.);
+  filter->SetNcellsCut(2);
   
-  TGeoHMatrix *matrix[4];
+  filter->SwitchOnFillTracks();
+  filter->SwitchOnFillAODFile();
   
-  double rotationMatrix[4][9] = {-0.014587, -0.999892, -0.002031, 0.999892, -0.014591,  0.001979, -0.002009, -0.002002,  0.999996,
-    -0.014587,  0.999892,  0.002031, 0.999892,  0.014591, -0.001979, -0.002009,  0.002002, -0.999996,
-    -0.345864, -0.938278, -0.003412, 0.938276, -0.345874,  0.003010, -0.004004, -0.002161,  0.999990,
-    -0.345861,  0.938280,  0.003412, 0.938276,  0.345874, -0.003010, -0.004004,  0.002161, -0.999990};
-  
-  double translationMatrix[4][3] = {0.351659,    447.576446,  176.269742,
-    1.062577,    446.893974, -173.728870,
-    -154.213287, 419.306156,  176.753692,
-    -153.018950, 418.623681, -173.243605};
-  for(int j=0; j<4; j++)
-  {
-    matrix[j] = new TGeoHMatrix();
-    matrix[j]->SetRotation(rotationMatrix[j]);
-    matrix[j]->SetTranslation(translationMatrix[j]);
-    matrix[j]->Print();
-    filter->SetEMCALGeometryMatrixInSM(matrix[j],j);
-  }
-  
-  filter->SwitchOnLoadOwnEMCALGeometryMatrices();
-  
-  reco->SetNonLinearityFunction(AliEMCALRecoUtils::kNoCorrection);
-  
-  //Time dependent corrections    
-  //Recover file from alien  /alice/cern.ch/user/g/gconesab/TimeDepCorrectionDB
-//  reco->SwitchOnTimeDepCorrection();
-//  char cmd[200] ;
-//  sprintf(cmd, ".!tar xvfz CorrectionFiles.tgz") ;
-//  gROOT->ProcessLine(cmd) ;
-  
-  //Recalibration factors
-  //Recover the file from alien  /alice/cern.ch/user/g/gconesab/RecalDB
-//  reco->SwitchOnRecalibration();
-//  TFile * f = new TFile("RecalibrationFactors.root","read");
-//  TH2F * h0 = (TH2F*)f->Get("EMCALRecalFactors_SM0");
-//  TH2F * h1 = (TH2F*)f->Get("EMCALRecalFactors_SM1");
-//  TH2F * h2 = (TH2F*)f->Get("EMCALRecalFactors_SM2");
-//  TH2F * h3 = (TH2F*)f->Get("EMCALRecalFactors_SM3");
-//  
-//  reco->SetEMCALChannelRecalibrationFactors(0,h0);
-//  reco->SetEMCALChannelRecalibrationFactors(1,h1);
-//  reco->SetEMCALChannelRecalibrationFactors(2,h2);
-//  reco->SetEMCALChannelRecalibrationFactors(3,h3);
-//  
-//  //Bad channels
-//  //Recover the file from alien  /alice/cern.ch/user/g/gconesab/BadChannelsDB
-//  reco->SwitchOnBadChannelsRemoval();
-//  reco->SwitchOnDistToBadChannelRecalculation();
-//  TFile * fbad = new TFile("BadChannels.root","read");
-//  TH2I * hbad0 = (TH2I*)fbad->Get("EMCALBadChannelMap_Mod0");
-//  TH2I * hbad1 = (TH2I*)fbad->Get("EMCALBadChannelMap_Mod1");
-//  TH2I * hbad2 = (TH2I*)fbad->Get("EMCALBadChannelMap_Mod2");
-//  TH2I * hbad3 = (TH2I*)fbad->Get("EMCALBadChannelMap_Mod3");
-//  reco->SetEMCALChannelStatusMap(0,hbad0);
-//  reco->SetEMCALChannelStatusMap(1,hbad1);
-//  reco->SetEMCALChannelStatusMap(2,hbad2);
-//  reco->SetEMCALChannelStatusMap(3,hbad3);
-//  
-  //reco->Print("");
   filter->PrintInfo(); 
   mgr->AddTask(filter);
   
-
   // Create containers for input/output
   AliAnalysisDataContainer *cinput1  = mgr->GetCommonInputContainer();
   AliAnalysisDataContainer *coutput1 = mgr->GetCommonOutputContainer();
     
-  AliAnalysisDataContainer *coutntuple = mgr->CreateContainer("EventNtuple", TNtuple::Class(), 
-                                                              AliAnalysisManager::kOutputContainer, "eventselection.root");
-  
   mgr->ConnectInput  (filter, 0, cinput1);
   mgr->ConnectOutput (filter, 0, coutput1 );
-  mgr->ConnectOutput (filter, 1, coutntuple );
   
   return filter;
 
index 1784bc958aee42262e9baed57c1d598dd31b5f92..0209b9f692e066b313b2d5dc48417857e5f3356b 100644 (file)
@@ -1,76 +1,19 @@
-AliAnalysisTaskCaloFilter * ConfigCaloFilter(){
-  
+AliAnalysisTaskCaloFilter * ConfigCaloFilter()
+{
+  // Configure calorimeter filter analysis
   AliAnalysisTaskCaloFilter * filter = new AliAnalysisTaskCaloFilter("EMCALFilter");
   filter->SelectCollisionCandidates(); 
   filter->SetCaloFilter(AliAnalysisTaskCaloFilter::kBoth); //kPHOS or kBoth
-  filter->SwitchOnClusterCorrection();
+  filter->SwitchOffClusterCorrection();
   //filter->SetDebugLevel(10);
-  AliEMCALRecoUtils * reco = filter->GetEMCALRecoUtils();
-  reco->SetParticleType(AliEMCALRecoUtils::kPhoton);
-  reco->SetW0(4.5);
-  
-  reco->SetPositionAlgorithm(AliEMCALRecoUtils::kPosTowerGlobal);
-  
-  TGeoHMatrix *matrix[4];
-  
-  double rotationMatrix[4][9] = {-0.014587, -0.999892, -0.002031, 0.999892, -0.014591,  0.001979, -0.002009, -0.002002,  0.999996,
-    -0.014587,  0.999892,  0.002031, 0.999892,  0.014591, -0.001979, -0.002009,  0.002002, -0.999996,
-    -0.345864, -0.938278, -0.003412, 0.938276, -0.345874,  0.003010, -0.004004, -0.002161,  0.999990,
-    -0.345861,  0.938280,  0.003412, 0.938276,  0.345874, -0.003010, -0.004004,  0.002161, -0.999990};
-  
-  double translationMatrix[4][3] = {0.351659,    447.576446,  176.269742,
-    1.062577,    446.893974, -173.728870,
-    -154.213287, 419.306156,  176.753692,
-    -153.018950, 418.623681, -173.243605};
-  for(int j=0; j<4; j++)
-  {
-    matrix[j] = new TGeoHMatrix();
-    matrix[j]->SetRotation(rotationMatrix[j]);
-    matrix[j]->SetTranslation(translationMatrix[j]);
-    matrix[j]->Print();
-    filter->SetEMCALGeometryMatrixInSM(matrix[j],j);
-  }
-  
-  filter->SwitchOnLoadOwnEMCALGeometryMatrices();
-  
-  reco->SetNonLinearityFunction(AliEMCALRecoUtils::kNoCorrection);
   
-  //Time dependent corrections    
-  //Recover file from alien  /alice/cern.ch/user/g/gconesab/TimeDepCorrectionDB
-//  reco->SwitchOnTimeDepCorrection();
-//  char cmd[200] ;
-//  sprintf(cmd, ".!tar xvfz CorrectionFiles.tgz") ;
-//  gROOT->ProcessLine(cmd) ;
+  filter->SetVzCut(10.);
+  filter->SetEnergyCut(10.);
+  filter->SetNcellsCut(2);
   
-  //Recalibration factors
-  //Recover the file from alien  /alice/cern.ch/user/g/gconesab/RecalDB
-//  reco->SwitchOnRecalibration();
-//  TFile * f = new TFile("RecalibrationFactors.root","read");
-//  TH2F * h0 = (TH2F*)f->Get("EMCALRecalFactors_SM0");
-//  TH2F * h1 = (TH2F*)f->Get("EMCALRecalFactors_SM1");
-//  TH2F * h2 = (TH2F*)f->Get("EMCALRecalFactors_SM2");
-//  TH2F * h3 = (TH2F*)f->Get("EMCALRecalFactors_SM3");
-//  
-//  reco->SetEMCALChannelRecalibrationFactors(0,h0);
-//  reco->SetEMCALChannelRecalibrationFactors(1,h1);
-//  reco->SetEMCALChannelRecalibrationFactors(2,h2);
-//  reco->SetEMCALChannelRecalibrationFactors(3,h3);
-//  
-//  //Bad channels
-//  //Recover the file from alien  /alice/cern.ch/user/g/gconesab/BadChannelsDB
-//  reco->SwitchOnBadChannelsRemoval();
-//  reco->SwitchOnDistToBadChannelRecalculation();
-//  TFile * fbad = new TFile("BadChannels.root","read");
-//  TH2I * hbad0 = (TH2I*)fbad->Get("EMCALBadChannelMap_Mod0");
-//  TH2I * hbad1 = (TH2I*)fbad->Get("EMCALBadChannelMap_Mod1");
-//  TH2I * hbad2 = (TH2I*)fbad->Get("EMCALBadChannelMap_Mod2");
-//  TH2I * hbad3 = (TH2I*)fbad->Get("EMCALBadChannelMap_Mod3");
-//  reco->SetEMCALChannelStatusMap(0,hbad0);
-//  reco->SetEMCALChannelStatusMap(1,hbad1);
-//  reco->SetEMCALChannelStatusMap(2,hbad2);
-//  reco->SetEMCALChannelStatusMap(3,hbad3);
+  filter->SwitchOnFillTracks();
+  filter->SwitchOnFillAODFile();
   
-  //reco->Print("");
   filter->PrintInfo();   
 
   return filter;
index 9892f5b81db5826db9c6b077398de059854c574d..633c12f8aa03fd5820f0737118a54e7fb222ff65 100644 (file)
@@ -94,17 +94,18 @@ void anaCaloFilter(Int_t mode=mLocal)
     //Define task, put here any other task that you want to use.
     //-------------------------------------------------------------------------    
     // ESD physics selection task
-    if(kInputData == "ESD" && kUsePhysSel){
+    if(kInputData == "ESD" && kUsePhysSel)
+    {
       gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
       AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection();
     }
     
-    //gROOT->LoadMacro("AddTaskCaloFilter.C");
-    //AliAnalysisTaskCaloFilter* filter = AddTaskCaloFilter();
+    gROOT->LoadMacro("AddTaskCaloFilter.C");
+    AliAnalysisTaskCaloFilter* filter = AddTaskCaloFilter();
             
-    AliAnalysisTaskCaloFilter * filter = new AliAnalysisTaskCaloFilter();
-    filter->SetConfigFileName("ConfigCaloFilter.C");
-    mgr->AddTask(filter);
+    //AliAnalysisTaskCaloFilter * filter = new AliAnalysisTaskCaloFilter();
+    //filter->SetConfigFileName("ConfigCaloFilter.C");
+    //mgr->AddTask(filter);
       
     // Create containers for input/output
     AliAnalysisDataContainer *cinput1    = mgr->GetCommonInputContainer();