]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWG0/AliPWG0Helper.cxx
clean up so code is less verbose for each event
[u/mrichter/AliRoot.git] / PWG0 / AliPWG0Helper.cxx
index d88376edba23c21b78a45fe2290e3b7fc88e6640..35b3683613a991c30d2f7e95b2a0f94cc07f9218 100644 (file)
@@ -20,6 +20,7 @@
 #include <AliESD.h>
 #include <AliESDEvent.h>
 #include <AliESDVertex.h>
+#include <AliVertexerTracks.h>
 
 #include <AliGenEventHeader.h>
 #include <AliGenPythiaEventHeader.h>
@@ -47,7 +48,6 @@ Bool_t AliPWG0Helper::IsEventTriggered(ULong64_t triggerMask, Trigger trigger)
   //
   // this function needs the branch fTriggerMask
   
-
   // definitions from p-p.cfg
   ULong64_t spdFO = (1 << 14);
   ULong64_t v0left = (1 << 11);
@@ -67,51 +67,44 @@ Bool_t AliPWG0Helper::IsEventTriggered(ULong64_t triggerMask, Trigger trigger)
         return kTRUE;
       break;
     }
+    case kSPDFASTOR:
+    {
+      if (triggerMask & spdFO)
+        return kTRUE;
+      break;
+    }
   }
 
   return kFALSE;
 }
 
 //____________________________________________________________________
-Bool_t AliPWG0Helper::IsVertexReconstructed(const AliESD* aEsd)
+Bool_t AliPWG0Helper::TestVertex(const AliESDVertex* vertex, AnalysisMode analysisMode, Bool_t debug)
 {
-  // see function with AliESDVertex argument
-
-  const AliESDVertex* vtxESD = aEsd->GetVertex();
-  return IsVertexReconstructed(vtxESD);
-}
-
-//____________________________________________________________________
-Bool_t AliPWG0Helper::IsVertexReconstructed(const AliESDVertex* vtxESD)
-{
-  // checks if the vertex is reasonable
-  //
-  // this function needs the branches fSPDVertex*
-
-  if (!vtxESD)
-    return kFALSE;
+    // Checks if a vertex meets the needed quality criteria
 
-  // the vertex should be reconstructed
-  if (strcmp(vtxESD->GetName(), "default")==0)
-    return kFALSE;
-
-  // check Ncontributors
-  if (vtxESD->GetNContributors() <= 0)
-    return kFALSE;
+  Float_t requiredZResolution = -1;
+  if (analysisMode == kSPD || analysisMode == kTPCITS)
+  {
+    requiredZResolution = 0.1;
+  }
+  else if (analysisMode == kTPC)
+    requiredZResolution = 10.;
 
-  Double_t vtx_res[3];
-  vtx_res[0] = vtxESD->GetXRes();
-  vtx_res[1] = vtxESD->GetYRes();
-  vtx_res[2] = vtxESD->GetZRes();
+  // check resolution
+  Double_t zRes = vertex->GetZRes();
 
-  if (vtx_res[2]==0 || vtx_res[2]>0.1)
+  if (zRes > requiredZResolution) {
+    if (debug)
+      Printf("AliPWG0Helper::TestVertex: Resolution too poor %f (required: %f", zRes, requiredZResolution);
     return kFALSE;
+  }
 
   return kTRUE;
 }
 
 //____________________________________________________________________
-const AliESDVertex* AliPWG0Helper::GetVertex(const AliESDEvent* aEsd, AnalysisMode analysisMode, Bool_t debug)
+const AliESDVertex* AliPWG0Helper::GetVertex(AliESDEvent* aEsd, AnalysisMode analysisMode, Bool_t debug,Bool_t bRedoTPC)
 {
   // Get the vertex from the ESD and returns it if the vertex is valid
   //
@@ -119,18 +112,28 @@ const AliESDVertex* AliPWG0Helper::GetVertex(const AliESDEvent* aEsd, AnalysisMo
   // also the quality criteria that are applied)
 
   const AliESDVertex* vertex = 0;
-  Float_t requiredZResolution = -1;
   if (analysisMode == kSPD || analysisMode == kTPCITS)
   {
     vertex = aEsd->GetPrimaryVertexSPD();
-    requiredZResolution = 0.1;
     if (debug)
       Printf("AliPWG0Helper::GetVertex: Returning SPD vertex");
   }
-  else if (analysisMode == kTPC) 
+  else if (analysisMode == kTPC)
   {
+    if(bRedoTPC){
+      Double_t kBz = aEsd->GetMagneticField();
+      AliVertexerTracks vertexer(kBz);
+      vertexer.SetTPCMode();
+      AliESDVertex *vTPC = vertexer.FindPrimaryVertex(aEsd);
+      aEsd->SetPrimaryVertexTPC(vTPC);
+      for (Int_t i=0; i<aEsd->GetNumberOfTracks(); i++) {
+       AliESDtrack *t = aEsd->GetTrack(i);
+       t->RelateToVertexTPC(vTPC, kBz, kVeryBig);
+      }
+      delete vTPC;
+    }
+
     vertex = aEsd->GetPrimaryVertexTPC();
-    requiredZResolution = 0.6;
     if (debug)
       Printf("AliPWG0Helper::GetVertex: Returning vertex from tracks");
   }
@@ -145,22 +148,26 @@ const AliESDVertex* AliPWG0Helper::GetVertex(const AliESDEvent* aEsd, AnalysisMo
 
   // check Ncontributors
   if (vertex->GetNContributors() <= 0) {
-    if (debug)
-      Printf("AliPWG0Helper::GetVertex: NContributors() <= 0");
+    if (debug){
+      Printf("AliPWG0Helper::GetVertex: NContributors() <= 0: %d",vertex->GetNContributors());
+      Printf("AliPWG0Helper::GetVertex: NIndices(): %d",vertex->GetNIndices());
+      vertex->Print();
+    }
     return 0;
   }
 
   // check resolution
   Double_t zRes = vertex->GetZRes();
-
-  if (zRes == 0 || zRes > requiredZResolution) {
-    if (debug)
-      Printf("AliPWG0Helper::GetVertex: Resolution too poor %f (required: %f", zRes, requiredZResolution);
+  if (zRes == 0) {
+    Printf("AliPWG0Helper::GetVertex: UNEXPECTED: resolution is 0.");
     return 0;
   }
 
   if (debug)
-    Printf("AliPWG0Helper::GetVertex: Returning valid vertex");
+  {
+    Printf("AliPWG0Helper::GetVertex: Returning valid vertex: %s", vertex->GetTitle());
+    vertex->Print();
+  }
 
   return vertex;
 }
@@ -186,6 +193,7 @@ Bool_t AliPWG0Helper::IsPrimaryCharged(TParticle* aParticle, Int_t aTotalPrimari
   }
 
   Int_t pdgCode = TMath::Abs(aParticle->GetPdgCode());
+  
 
   // skip quarks and gluon
   if (pdgCode <= 10 || pdgCode == 21)
@@ -195,10 +203,17 @@ Bool_t AliPWG0Helper::IsPrimaryCharged(TParticle* aParticle, Int_t aTotalPrimari
     return kFALSE;
   }
 
+  Int_t status = aParticle->GetStatusCode();
+  // skip non final state particles..
+  if(status!=1){
+    if (adebug)
+      printf("Dropping particle because it is not a final state particle.\n");
+    return kFALSE;
+  }
+
   if (strcmp(aParticle->GetName(),"XXX") == 0)
   {
-    if (adebug)
-      printf("WARNING: There is a particle named XXX.\n");
+    Printf("WARNING: There is a particle named XXX (pdg code %d).", pdgCode);
     return kFALSE;
   }
 
@@ -206,8 +221,7 @@ Bool_t AliPWG0Helper::IsPrimaryCharged(TParticle* aParticle, Int_t aTotalPrimari
 
   if (strcmp(pdgPart->ParticleClass(),"Unknown") == 0)
   {
-    if (adebug)
-      printf("WARNING: There is a particle with an unknown particle class (pdg code %d).\n", pdgCode);
+    Printf("WARNING: There is a particle with an unknown particle class (pdg code %d).", pdgCode);
     return kFALSE;
   }
 
@@ -332,7 +346,7 @@ const char* AliPWG0Helper::GetAxisTitle(TH3* hist, const char axis)
 }
 
 
-Int_t AliPWG0Helper::GetPythiaEventProcessType(AliGenEventHeader* aHeader, Bool_t adebug) {
+AliPWG0Helper::MCProcessType AliPWG0Helper::GetPythiaEventProcessType(AliGenEventHeader* aHeader, Bool_t adebug) {
 
   AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(aHeader);
 
@@ -366,7 +380,7 @@ Int_t AliPWG0Helper::GetPythiaEventProcessType(AliGenEventHeader* aHeader, Bool_
 }
 
 
-Int_t AliPWG0Helper::GetDPMjetEventProcessType(AliGenEventHeader* aHeader, Bool_t adebug) {
+AliPWG0Helper::MCProcessType AliPWG0Helper::GetDPMjetEventProcessType(AliGenEventHeader* aHeader, Bool_t adebug) {
   //
   // get the process type of the event.
   //
@@ -402,7 +416,7 @@ Int_t AliPWG0Helper::GetDPMjetEventProcessType(AliGenEventHeader* aHeader, Bool_
 }
 
 
-Int_t AliPWG0Helper::GetEventProcessType(AliHeader* aHeader, Bool_t adebug) {
+AliPWG0Helper::MCProcessType AliPWG0Helper::GetEventProcessType(AliHeader* aHeader, Bool_t adebug) {
   //
   // get the process type of the event.
   //
@@ -502,45 +516,6 @@ Int_t AliPWG0Helper::FindPrimaryMotherLabel(AliStack* stack, Int_t label)
   return label;
 }
 
-void AliPWG0Helper::SetBranchStatusRecursive(TTree* tree, char *bname, Bool_t status, Bool_t debug)
-{
-  // Function  to switch on/off all data members of a top level branch
-  // this is needed for branches without a trailing dot ".", for those
-  // the root functionality with regular expressions does not work.
-  // Usage e.g.
-  // chain->SetBranchStatus("*", 0); 
-  // SetBranchStatusRecursive(chain,"SPDVertex",1);
-  // You need to give the full name of the top level branch zou want to access
-  //==========================================================================
-  // Author Christian.Klein-Boesing@cern.ch
-
-  if (!tree)
-    return;
-
-  TBranch *br = tree->GetBranch(bname);
-  if(!br) {
-    Printf("AliPWG0Helper::SetBranchStatusRecursive: Branch %s not found", bname);
-  }
-
-  TObjArray *leaves = tree->GetListOfLeaves();
-  Int_t nleaves = leaves->GetEntries();
-  TLeaf *leaf = 0;
-  TBranch *branch = 0;
-  TBranch *mother = 0;
-  for (Int_t i=0;i<nleaves;i++)  {
-    // the matched entry e.g. SPDVertex is its own Mother
-    leaf = (TLeaf*)leaves->UncheckedAt(i);
-    branch = (TBranch*)leaf->GetBranch();
-    mother = branch->GetMother();
-    if (mother==br){
-      if (debug)
-        Printf(">>>> AliPWG0Helper::SetBranchStatusRecursive: Setting status %s %s to %d", mother->GetName(), leaf->GetName(), status);
-      if (status) branch->ResetBit(kDoNotProcess);
-      else        branch->SetBit(kDoNotProcess);
-    }
-  }
-}
-
 //____________________________________________________________________
 void AliPWG0Helper::NormalizeToBinWidth(TH1* hist)
 {
@@ -594,6 +569,7 @@ void AliPWG0Helper::PrintConf(AnalysisMode analysisMode, Trigger trigger)
   {
     case kMB1 : str += "MB1"; break;
     case kMB2 : str += "MB2"; break;
+    case kSPDFASTOR : str += "SPD FASTOR"; break;
   }
 
   str += " <<<<";