]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWG2/RESONANCES/AliRsnCutPrimaryVertex.cxx
Added check of pileup in event cuts
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnCutPrimaryVertex.cxx
index 694b252f935cd54ce5d7fe099766158ed8f83d86..3837637faffe03d3dcd13bed792b73046cee0022 100644 (file)
 
 ClassImp(AliRsnCutPrimaryVertex)
 
-//_________________________________________________________________________________________________
-AliRsnCutPrimaryVertex::AliRsnCutPrimaryVertex() :
-  AliRsnCut(AliRsnCut::kEvent),
-  fAcceptTPC(kFALSE)
-{
-//
-// Default constructor.
-//
-}
-
 //_________________________________________________________________________________________________
 AliRsnCutPrimaryVertex::AliRsnCutPrimaryVertex
-(const char *name, Int_t nContributors, Bool_t acceptTPC) :
-  AliRsnCut(name, AliRsnCut::kEvent, 0, nContributors - 1),
-  fAcceptTPC(acceptTPC)
+(const char *name, Double_t maxVz, Int_t nContributors, Bool_t acceptTPC) :
+  AliRsnCut(name, AliRsnCut::kEvent, 0, nContributors - 1, 0.0, maxVz),
+  fAcceptTPC(acceptTPC),
+  fCheckPileUp(kFALSE)
 {
 //
 // Main constructor.
@@ -42,55 +33,94 @@ AliRsnCutPrimaryVertex::AliRsnCutPrimaryVertex
 // Since the range check uses the '>=' and '<=', the high edge
 // must be decreased by 1 to get the right behaviour, since this is integer.
 //
+
+  fMinD = 0.0;
+  fMaxD = maxVz + 1E-6;
 }
 
 //_________________________________________________________________________________________________
-Bool_t AliRsnCutPrimaryVertex::IsSelected(TObject *obj1, TObject* /*obj2*/)
+Bool_t AliRsnCutPrimaryVertex::IsSelected(TObject *object)
 {
 //
 // Cut checker
 //
 
+  static Int_t evNum = 0;
+  evNum++;
+  
   // retrieve ESD event
-  AliRsnEvent *rsn = dynamic_cast<AliRsnEvent*>(obj1);
+  AliRsnEvent *rsn = dynamic_cast<AliRsnEvent*>(object);
   if (!rsn) return kFALSE;
-  AliESDEvent *esd = dynamic_cast<AliESDEvent*>(rsn->GetRef());
-  if (!esd) {
-    AliDebug(AliLog::kDebug+2, "NO ESD");
-    return kFALSE;
+  AliESDEvent *esd = rsn->GetRefESD();
+  AliAODEvent *aod = rsn->GetRefAOD();
+  
+  if (esd)
+  {
+    // pile-up check
+    if (fCheckPileUp)
+    {
+      if (esd->IsPileupFromSPD()) return kFALSE;
+    }
+    
+    // get the best primary vertex:
+    // first try the one with tracks
+    const AliESDVertex *vTrk  = esd->GetPrimaryVertexTracks();
+    const AliESDVertex *vSPD  = esd->GetPrimaryVertexSPD();
+    const AliESDVertex *vTPC  = esd->GetPrimaryVertexTPC();
+    Int_t               ncTrk = -1;
+    Int_t               ncSPD = -1;
+    Int_t               ncTPC = -1;
+    Double_t            vzTrk = 2.0 * fMaxD;
+    Double_t            vzSPD = 2.0 * fMaxD;
+    Double_t            vzTPC = 2.0 * fMaxD;
+    if (vTrk) vzTrk = TMath::Abs(vTrk->GetZv());
+    if (vSPD) vzSPD = TMath::Abs(vSPD->GetZv());
+    if (vTPC) vzTPC = TMath::Abs(vTPC->GetZv());
+    if (vTrk) ncTrk = (Int_t)vTrk->GetNContributors();
+    if (vSPD) ncSPD = (Int_t)vSPD->GetNContributors();
+    if (vTPC) ncTPC = (Int_t)vTPC->GetNContributors();
+    if(vTrk && ncTrk > 0)
+    {
+      fCutValueI = ncTrk;
+      fCutValueD = vzTrk;
+    }
+    else if (vSPD && ncSPD > 0)
+    {
+      fCutValueI = ncSPD;
+      fCutValueD = vzSPD;
+    }
+    else if (vTPC && fAcceptTPC && ncTPC > 0)
+    {
+      fCutValueI = ncTPC;
+      fCutValueD = vzTPC;
+    }
+    else
+    {
+      fCutValueI = -1;
+      fCutValueD = 2.0 * fMaxD;
+    }
   }
+  else if (aod)
+  {
+    // pile-up check is not yet available for AODs
+    
+    // lines suggested by Andrea to reject TPC-only events
+    if(!fAcceptTPC)
+    {
+      if (!aod->GetPrimaryVertexSPD()) return kFALSE;
+      else if(aod->GetPrimaryVertexSPD()->GetNContributors() < 1) return kFALSE;
+    }
+    
+    AliAODVertex *prim = (AliAODVertex*)aod->GetPrimaryVertex();
+    if (!prim) return kFALSE;
 
-  // get the three possible primary vertexes of the event:
-  // 0 = default one
-  // 1 = SPD
-  // 2 = TPC
-  // then, if the default vertex is TPC, the event is rejected,
-  // otherwise, the event is rejected only if its vertex status is 'false'
-  // get primary vertexes
-  const AliESDVertex *vert[3];
-  vert[0] = esd->GetPrimaryVertex();
-  vert[1] = esd->GetPrimaryVertexSPD();
-  vert[2] = esd->GetPrimaryVertexTPC();
-
-  // if TPC vertexes are rejected by default do this now
-  if (!fAcceptTPC && (vert[0] == vert[2])) {
-    AliDebug(AliLog::kDebug+2, "Rejecting TPC vertex");
-    return kFALSE;
+    fCutValueI = prim->GetNContributors();
+    fCutValueD = prim->GetZ();
   }
-
-  // if we are here, vert[0] contains the default primary vertex
-  // in case it is with tracks or SPD, its status must be OK
-  // because otherwise the ESD event returns the lower level vertex
-  // then, we can check just the first element in the array
-  if (!vert[0]->GetStatus()) {
-    AliDebug(AliLog::kDebug+2, "Bad vertex status");
+  else
     return kFALSE;
-  }
-
-  // if we are here, the status of default vertex is OK
-  // and then we check the number of contributors:
-  // it must be *outside* the 'allowed' range
-  fCutValueI = vert[0]->GetNContributors();
-  return /*there is a NOT operator */!/*here*/OkRange();
+    
+  // output
+  Bool_t result = ((!OkRangeI()) && OkRangeD());
+  return result;
 }
-