]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - CORRFW/AliCFEventRecCuts.cxx
Revert unwanted changes concerning PID in HLT
[u/mrichter/AliRoot.git] / CORRFW / AliCFEventRecCuts.cxx
index b3db0e68d005e89cc8549761bd1abf1c4395104b..25daa4bff088a8ece1cf03e15bbd8f624657c440 100644 (file)
@@ -22,6 +22,8 @@
 // Author:S.Arcelli Silvia.Arcelli@cern.ch
 //
 //
+#include "TH1F.h"
+#include "TList.h"
 #include "TBits.h"
 #include "AliLog.h"
 #include "AliESDEvent.h"
@@ -43,13 +45,19 @@ AliCFEventRecCuts::AliCFEventRecCuts() :
   fVtxXResMax(1.e99),
   fVtxYResMax(1.e99),
   fVtxZResMax(1.e99),
+  fVtxNCtrbMin(0),
+  fVtxNCtrbMax((Int_t)1.e9),
+  fVtxTPC(0),
+  fVtxSPD(0),
   fBitMap(0x0)
 {
   //
   //ctor
   //
   fBitMap=new TBits(0);
+  Initialise();
 }
+
 //____________________________________________________________________
 AliCFEventRecCuts::AliCFEventRecCuts(Char_t* name, Char_t* title) : 
   AliCFCutBase(name,title),
@@ -65,13 +73,19 @@ AliCFEventRecCuts::AliCFEventRecCuts(Char_t* name, Char_t* title) :
   fVtxXResMax(1.e99),
   fVtxYResMax(1.e99),
   fVtxZResMax(1.e99),
+  fVtxNCtrbMin(0),
+  fVtxNCtrbMax((Int_t)1.e9),
+  fVtxTPC(0),
+  fVtxSPD(0),
   fBitMap(0x0)
  {
   //
   //ctor
   //
   fBitMap=new TBits(0);
+  Initialise();
  }
+
 //____________________________________________________________________
 AliCFEventRecCuts::AliCFEventRecCuts(const AliCFEventRecCuts& c) : 
   AliCFCutBase(c),
@@ -87,21 +101,57 @@ AliCFEventRecCuts::AliCFEventRecCuts(const AliCFEventRecCuts& c) :
   fVtxXResMax(c.fVtxXResMax),
   fVtxYResMax(c.fVtxYResMax),
   fVtxZResMax(c.fVtxZResMax),
+  fVtxNCtrbMin(c.fVtxNCtrbMin),
+  fVtxNCtrbMax(c.fVtxNCtrbMax),
+  fVtxTPC(c.fVtxTPC),
+  fVtxSPD(c.fVtxSPD),
   fBitMap(c.fBitMap)
 {
   //
   //copy constructor
   //
+  for (Int_t i=0; i<c.kNCuts; i++){
+    for (Int_t j=0; j<c.kNStepQA; j++){
+      if(c.fhQA[i][j]) fhQA[i][j] = (TH1F*)c.fhQA[i][j]->Clone();
+    }
+  }
+
 }
+
 //____________________________________________________________________
 AliCFEventRecCuts::~AliCFEventRecCuts() {
   //
   //dtor
   //
 
+  for (Int_t i=0; i<kNCuts; i++){
+    for (Int_t j=0; j<kNStepQA; j++){
+      if(fhQA[i][j]) delete fhQA[i][j];
+    }
+  }
+
   if(fBitMap)delete fBitMap;
+
 }
+//_____________________________________________________________________________
+void AliCFEventRecCuts::Initialise()
+{
+
+  //
+  //initialization
+  //
+
+  //
+  // sets pointers to histos to zero
+  //
+
+  for(Int_t i=0; i<kNCuts; i++){
+    for(Int_t j =0; j<kNStepQA; j++){
+      fhQA[i][j]=0x0;
+    }
+  }
+}
+
 //____________________________________________________________________
 AliCFEventRecCuts& AliCFEventRecCuts::operator=(const AliCFEventRecCuts& c)
 {
@@ -122,29 +172,45 @@ AliCFEventRecCuts& AliCFEventRecCuts::operator=(const AliCFEventRecCuts& c)
     fVtxXResMax=c.fVtxXResMax;
     fVtxYResMax=c.fVtxYResMax;
     fVtxZResMax=c.fVtxZResMax;
+    fVtxNCtrbMin=c.fVtxNCtrbMin;
+    fVtxNCtrbMax=c.fVtxNCtrbMax;
+    fVtxTPC=c.fVtxTPC;
+    fVtxSPD=c.fVtxSPD;
     fBitMap=c.fBitMap;
   }
+
+  for (Int_t i=0; i<c.kNCuts; i++){
+    for (Int_t j=0; j<c.kNStepQA; j++){
+      if(c.fhQA[i][j]) fhQA[i][j] = (TH1F*)c.fhQA[i][j]->Clone();
+    }
+  }
+
+
   return *this ;
 }
+
 //____________________________________________________________________
 Bool_t AliCFEventRecCuts::IsSelected(TObject* obj) {
   //
   //Check if the requested cuts are passed
   //
 
-  TBits *bitmap = SelectionBitMap(obj);
 
+  SelectionBitMap(obj);
+
+  if (fIsQAOn) FillHistograms(obj,0);
   Bool_t isSelected = kTRUE;
 
-  for (UInt_t icut=0; icut<bitmap->GetNbits();icut++)
-       if(!bitmap->TestBitNumber(icut)) isSelected = kFALSE;
+  for (UInt_t icut=0; icut<fBitMap->GetNbits();icut++)
+       if(!fBitMap->TestBitNumber(icut)) isSelected = kFALSE;
 
-  return isSelected;
+  if (!isSelected) return kFALSE ;
+  if (fIsQAOn) FillHistograms(obj,1);
+  return kTRUE;
 
 }
-
 //____________________________________________________________________
-TBits *AliCFEventRecCuts::SelectionBitMap(TObject* obj) {
+void AliCFEventRecCuts::SelectionBitMap(TObject* obj) {
   //
   //cut on the number of charged tracks and on the event vertex.
   //so far specific to AliESDEvents
@@ -153,7 +219,7 @@ TBits *AliCFEventRecCuts::SelectionBitMap(TObject* obj) {
   //Check if the requested cuts are passed and return a bitmap
   for(Int_t j=0;j<kNCuts;j++)fBitMap->SetBitNumber(j,kFALSE);
   AliESDEvent* esd = dynamic_cast<AliESDEvent *>(obj);
-  if ( !esd ) return fBitMap ;
+  if ( !esd ) return;
 
   //now start checking the cuts,
   //first assume the event will be accepted: 
@@ -165,16 +231,20 @@ TBits *AliCFEventRecCuts::SelectionBitMap(TObject* obj) {
     fBitMap->SetBitNumber(0,kFALSE); 
   
   if(fRequireVtxCuts){
-    const AliESDVertex* vtxESD = esd->GetVertex();
+    const AliESDVertex* vtxESD = 0x0;
+    if      (fVtxTPC) vtxESD = esd->GetPrimaryVertexTPC() ;
+    else if (fVtxSPD) vtxESD = esd->GetPrimaryVertexSPD() ;
+    else              vtxESD = esd->GetPrimaryVertexTracks() ;
     if(!vtxESD){
       for(Int_t j=1;j<kNCuts;j++)fBitMap->SetBitNumber(j,kFALSE); 
-      return fBitMap;
+      AliWarning("Cannot get vertex, skipping event");
+      return;
     }
     // Require the vertex to have been reconstructed successfully
     if (strcmp(vtxESD->GetName(), "default")==0){
-      AliWarning(Form(" No reconstructed vertex found, skip event"));    
+      AliWarning(Form(" No reconstructed vertex found, skipping event"));    
       for(Int_t j=1;j<kNCuts;j++)fBitMap->SetBitNumber(j,kFALSE); 
-      return fBitMap;
+      return;
     }    
     // Pick up the position and uncertainties
     
@@ -188,6 +258,8 @@ TBits *AliCFEventRecCuts::SelectionBitMap(TObject* obj) {
     vtxRes[1] = vtxESD->GetYRes();
     vtxRes[2] = vtxESD->GetZRes();
  
+    Int_t nCtrb = vtxESD->GetNContributors();
+
     // Apply the cut
     
     if (vtxPos[0]>fVtxXMax || vtxPos[0]<fVtxXMin)
@@ -202,14 +274,135 @@ TBits *AliCFEventRecCuts::SelectionBitMap(TObject* obj) {
       fBitMap->SetBitNumber(5,kFALSE); 
     if (vtxRes[2]==0 || vtxRes[2]>fVtxZResMax)
       fBitMap->SetBitNumber(6,kFALSE); 
+    if (nCtrb<fVtxNCtrbMin || nCtrb>fVtxNCtrbMax)
+      fBitMap->SetBitNumber(7,kFALSE);
+
   }  
-  return fBitMap;
+  return;
 }
-//__________________________________________________________________________________
-void AliCFEventRecCuts::GetBitMap(TObject* obj, TBits *bitmap) {
+
+//_____________________________________________________________________________
+void AliCFEventRecCuts::FillHistograms(TObject* obj, Bool_t b)
+{
   //
-  // retrieve the pointer to the bitmap
+  // fill the QA histograms
   //
-  bitmap = SelectionBitMap(obj);
 
+  if(!fIsQAOn) return;
+  // cast TObject into VParticle
+  AliESDEvent* esd = dynamic_cast<AliESDEvent *>(obj);
+  if (!esd ) return  ;
+
+  // index = 0: fill histograms before cuts
+  // index = 1: fill histograms after cuts
+  Int_t index = -1;
+  index = ((b) ? 1 : 0);
+
+
+  //number of charged tracks:
+  Int_t nTracks = esd->GetNumberOfTracks();
+  fhQA[kNTracks][index]->Fill(nTracks);
+
+  //look at vertex parameters:
+  const AliESDVertex* vtxESD = 0x0;
+  if      (fVtxTPC) vtxESD = esd->GetPrimaryVertexTPC() ;
+  else if (fVtxSPD) vtxESD = esd->GetPrimaryVertexSPD() ;
+  else              vtxESD = esd->GetPrimaryVertexTracks() ;
+  if(!vtxESD)return;
+  // Require the vertex to have been reconstructed successfully
+  if (strcmp(vtxESD->GetName(), "default")==0)return;
+  // vertex position and uncertainties
+  fhQA[kVtxPosX] [index]->Fill(vtxESD->GetXv());
+  fhQA[kVtxPosY] [index]->Fill(vtxESD->GetYv());
+  fhQA[kVtxPosZ] [index]->Fill(vtxESD->GetZv());
+  fhQA[kVtxResX] [index]->Fill(vtxESD->GetXRes());
+  fhQA[kVtxResY] [index]->Fill(vtxESD->GetYRes());
+  fhQA[kVtxResZ] [index]->Fill(vtxESD->GetZRes());
+  fhQA[kVtxNCtrb][index]->Fill(vtxESD->GetNContributors());
+  
+}
+
+//____________________________________________________________________
+void AliCFEventRecCuts::SetHistogramBins(Int_t index, Int_t nbins, Double_t *bins)
+{
+  //
+  //setting x-axis bin limits of QA histogram fhQA[index] 
+  // 
+
+  for(Int_t i=0;i<kNStepQA;i++){
+    if(!fhQA[index][i]){AliWarning("non-existing histogram!");
+    return;
+    }
+    fhQA[index][i]->GetXaxis()->Set(nbins,bins);
+  }
+}
+//____________________________________________________________________
+void AliCFEventRecCuts::SetHistogramBins(Int_t index, Int_t nbins, Double_t xmin, Double_t xmax)
+{
+  //
+  //setting x-axis bins and range of QA histogram fhQA[index] 
+  // 
+
+  for(Int_t i=0;i<kNStepQA;i++){
+    if(!fhQA[index][i]){AliWarning("non-existing histogram!");
+    return;
+    }
+    fhQA[index][i]->GetXaxis()->Set(nbins,xmin,xmax);
+  }
+}
+
+//_____________________________________________________________________________
+ void AliCFEventRecCuts::DefineHistograms() {
+  //
+  // histograms for cut variables
+  //
+  Int_t color = 2;
+
+  if(!fIsQAOn) {
+    AliInfo(Form("No QA histos requested, Please first set the QA flag on!"));
+    return;
+  }  
+  
+  // book QA histograms
+
+  Char_t str[256];
+  for (Int_t i=0; i<kNStepQA; i++) {
+    if (i==0) sprintf(str," ");
+    else sprintf(str,"_cut");
+
+    fhQA[kNTracks][i]  = new  TH1F(Form("%s_NTracks%s",GetName(),str),                 "",501,-0.5,500.5);
+    fhQA[kVtxPosX][i]  = new  TH1F(Form("%s_Vtx_Pos_X%s",GetName(),str),               "",100,-5.,5.);
+    fhQA[kVtxPosY][i]  = new  TH1F(Form("%s_Vtx_Pos_Y%s",GetName(),str),               "",100,-5.,5.);
+    fhQA[kVtxPosZ][i]  = new  TH1F(Form("%s_Vtx_Pos_Z%s",GetName(),str),               "",200,-50.,50.);
+    fhQA[kVtxResX][i]  = new  TH1F(Form("%s_Vtx_Res_X%s",GetName(),str),               "",100,-1.,1.);
+    fhQA[kVtxResY][i]  = new  TH1F(Form("%s_Vtx_Res_Y%s",GetName(),str),               "",100,-1.,1.);
+    fhQA[kVtxResZ][i]  = new  TH1F(Form("%s_Vtx_Res_Z%s",GetName(),str),               "",100,-1.,1.);
+    fhQA[kVtxNCtrb][i] = new  TH1F(Form("%s_Vtx_N_Ctrb%s",GetName(),str),              "",1000,0.,1000.);
+    fhQA[kNTracks][i]  ->SetXTitle("Number of ESD tracks");
+    fhQA[kVtxPosX][i]  ->SetXTitle("Vertex Position X (cm)");
+    fhQA[kVtxPosY][i]  ->SetXTitle("Vertex Position Y (cm)");
+    fhQA[kVtxPosZ][i]  ->SetXTitle("Vertex Position Z (cm)");
+    fhQA[kVtxResX][i]  ->SetXTitle("Vertex Resolution X (cm)");
+    fhQA[kVtxResY][i]  ->SetXTitle("Vertex Resolution Y (cm)");
+    fhQA[kVtxResZ][i]  ->SetXTitle("Vertex Resolution Z (cm)");
+    fhQA[kVtxNCtrb][i] ->SetXTitle("Number of contributors");
+  }
+
+  for(Int_t i=0; i<kNCuts; i++) fhQA[i][1]->SetLineColor(color);
+
+}
+
+//_____________________________________________________________________________
+void AliCFEventRecCuts::AddQAHistograms(TList *qaList) {
+  //
+  // saves the histograms in a TList
+  //
+
+  DefineHistograms();
+
+  for (Int_t j=0; j<kNStepQA; j++) {
+    for(Int_t i=0; i<kNCuts; i++)
+       qaList->Add(fhQA[i][j]);
+  }
 }