]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWG0/AliPWG0Helper.cxx
Adding example - in comments (Marian)
[u/mrichter/AliRoot.git] / PWG0 / AliPWG0Helper.cxx
index 7377dbb2052e81a668539c192f40b6ed224da9dc..ba01ff76cbd5c226c9736ec136e460d1f5c03634 100644 (file)
 
 #include <AliLog.h>
 #include <AliESD.h>
+#include <AliESDEvent.h>
 #include <AliESDVertex.h>
 
 #include <AliGenEventHeader.h>
 #include <AliGenPythiaEventHeader.h>
 #include <AliGenCocktailEventHeader.h>
+#include <AliGenDPMjetEventHeader.h>
 
 //____________________________________________________________________
 ClassImp(AliPWG0Helper)
 
+Int_t AliPWG0Helper::fgLastProcessType = -1;
+
 //____________________________________________________________________
 Bool_t AliPWG0Helper::IsEventTriggered(const AliESD* aEsd, Trigger trigger)
 {
@@ -43,7 +47,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);
@@ -63,47 +66,70 @@ 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)
-{
-  // see function with AliESDVertex argument
-
-  const AliESDVertex* vtxESD = aEsd->GetVertex();
-  return IsVertexReconstructed(vtxESD);
-}
-
-//____________________________________________________________________
-Bool_t AliPWG0Helper::IsVertexReconstructed(const AliESDVertex* vtxESD)
+const AliESDVertex* AliPWG0Helper::GetVertex(const AliESDEvent* aEsd, AnalysisMode analysisMode, Bool_t debug)
 {
-  // checks if the vertex is reasonable
+  // Get the vertex from the ESD and returns it if the vertex is valid
   //
-  // this function needs the branches fSPDVertex*
+  // Second argument decides which vertex is used (this selects
+  // also the quality criteria that are applied)
 
-  if (!vtxESD)
-    return kFALSE;
+  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) 
+  {
+    vertex = aEsd->GetPrimaryVertexTPC();
+    requiredZResolution = 0.6;
+    if (debug)
+      Printf("AliPWG0Helper::GetVertex: Returning vertex from tracks");
+  }
+  else
+    Printf("AliPWG0Helper::GetVertex: ERROR: Invalid second argument %d", analysisMode);
 
-  // the vertex should be reconstructed
-  if (strcmp(vtxESD->GetName(), "default")==0)
-    return kFALSE;
+  if (!vertex) {
+    if (debug)
+      Printf("AliPWG0Helper::GetVertex: No vertex found in ESD");
+    return 0;
+  }
 
   // check Ncontributors
-  if (vtxESD->GetNContributors() <= 0)
-    return kFALSE;
+  if (vertex->GetNContributors() <= 0) {
+    if (debug)
+      Printf("AliPWG0Helper::GetVertex: NContributors() <= 0");
+    return 0;
+  }
 
-  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)
-    return kFALSE;
+  if (zRes == 0 || zRes > requiredZResolution) {
+    if (debug)
+      Printf("AliPWG0Helper::GetVertex: Resolution too poor %f (required: %f", zRes, requiredZResolution);
+    return 0;
+  }
 
-  return kTRUE;
+  if (debug)
+    Printf("AliPWG0Helper::GetVertex: Returning valid vertex");
+
+  return vertex;
 }
 
 //____________________________________________________________________
@@ -138,8 +164,7 @@ Bool_t AliPWG0Helper::IsPrimaryCharged(TParticle* aParticle, Int_t aTotalPrimari
 
   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;
   }
 
@@ -147,8 +172,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;
   }
 
@@ -272,46 +296,125 @@ const char* AliPWG0Helper::GetAxisTitle(TH3* hist, const char axis)
   return 0;
 }
 
-//____________________________________________________________________
-Int_t AliPWG0Helper::GetPythiaEventProcessType(AliHeader* aHeader, Bool_t adebug) {
+
+AliPWG0Helper::MCProcessType AliPWG0Helper::GetPythiaEventProcessType(AliGenEventHeader* aHeader, Bool_t adebug) {
+
+  AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(aHeader);
+
+  if (!pythiaGenHeader) {
+    printf("AliPWG0Helper::GetProcessType : Unknown gen Header type). \n");
+    return kInvalidProcess;
+  }
+
+
+  Int_t pythiaType = pythiaGenHeader->ProcessType();
+  fgLastProcessType = pythiaType;
+  MCProcessType globalType = kInvalidProcess;  
+
+
+  if (adebug) {
+    printf("AliPWG0Helper::GetProcessType : Pythia process type found: %d \n",pythiaType);
+  }
+
+
+  if(pythiaType==92||pythiaType==93){
+    globalType = kSD;
+  }
+  else if(pythiaType==94){
+    globalType = kDD;
+  }
+  //else if(pythiaType != 91){ // also exclude elastic to be sure... CKB??
+  else {
+    globalType = kND;
+  }
+  return globalType;
+}
+
+
+AliPWG0Helper::MCProcessType AliPWG0Helper::GetDPMjetEventProcessType(AliGenEventHeader* aHeader, Bool_t adebug) {
   //
   // get the process type of the event.
   //
 
   // can only read pythia headers, either directly or from cocktalil header
+  AliGenDPMjetEventHeader* dpmJetGenHeader = dynamic_cast<AliGenDPMjetEventHeader*>(aHeader);
+
+  if (!dpmJetGenHeader) {
+    printf("AliPWG0Helper::GetDPMjetProcessType : Unknown header type (not DPMjet or). \n");
+    return kInvalidProcess;
+  }
+
+  Int_t dpmJetType = dpmJetGenHeader->ProcessType();
+  fgLastProcessType = dpmJetType;
+  MCProcessType globalType = kInvalidProcess;  
+
+
+  if (adebug) {
+    printf("AliPWG0Helper::GetDPMJetProcessType : DPMJet process type found: %d \n",dpmJetType);
+  }
+
+
+  if(dpmJetType == 1){ // this is explicitly inelastic
+    globalType = kND;
+  }  
+  else if(dpmJetType==5||dpmJetType==6){
+    globalType = kSD;
+  }
+  else if(dpmJetType==7||dpmJetType==4){// DD and double pomeron
+    globalType = kDD;
+  }
+  return globalType;
+}
+
+
+AliPWG0Helper::MCProcessType AliPWG0Helper::GetEventProcessType(AliHeader* aHeader, Bool_t adebug) {
+  //
+  // get the process type of the event.
+  //
+
+
+  // Check for simple headers first
+
   AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(aHeader->GenEventHeader());
+  if (pythiaGenHeader) {
+    return GetPythiaEventProcessType(pythiaGenHeader,adebug);
+  }
 
-  if (!pythiaGenHeader) {
+  AliGenDPMjetEventHeader* dpmJetGenHeader = dynamic_cast<AliGenDPMjetEventHeader*>(aHeader->GenEventHeader());
+  if (dpmJetGenHeader) {
+    return GetDPMjetEventProcessType(dpmJetGenHeader,adebug);
+  }
+  
 
-    AliGenCocktailEventHeader* genCocktailHeader = dynamic_cast<AliGenCocktailEventHeader*>(aHeader->GenEventHeader());
-    if (!genCocktailHeader) {
-      printf("AliPWG0Helper::GetProcessType : Unknown header type (not Pythia or Cocktail). \n");
-      return -1;
-    }
+  // check for cocktail
 
-    TList* headerList = genCocktailHeader->GetHeaders();
-    if (!headerList) {
-      return -1;
-    }
+  AliGenCocktailEventHeader* genCocktailHeader = dynamic_cast<AliGenCocktailEventHeader*>(aHeader->GenEventHeader());
+  if (!genCocktailHeader) {
+    printf("AliPWG0Helper::GetProcessType : Unknown header type (not Pythia or Cocktail). \n");
+    return kInvalidProcess;
+  }
+
+  TList* headerList = genCocktailHeader->GetHeaders();
+  if (!headerList) {
+    return kInvalidProcess;
+  }
+
+  for (Int_t i=0; i<headerList->GetEntries(); i++) {
 
-    for (Int_t i=0; i<headerList->GetEntries(); i++) {
-      pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(headerList->At(i));
-      if (pythiaGenHeader)
-        break;
+    pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(headerList->At(i));
+    if (pythiaGenHeader) {
+      return GetPythiaEventProcessType(pythiaGenHeader,adebug);
     }
 
-    if (!pythiaGenHeader) {
-      printf("AliPWG0Helper::GetProcessType : Could not find Pythia header. \n");
-      return -1;
+    dpmJetGenHeader = dynamic_cast<AliGenDPMjetEventHeader*>(headerList->At(i));
+    if (dpmJetGenHeader) {
+      return GetDPMjetEventProcessType(dpmJetGenHeader,adebug);
     }
   }
+  return kInvalidProcess;
+}
 
-  if (adebug) {
-    printf("AliPWG0Helper::GetProcessType : Pythia process type found: %d \n",pythiaGenHeader->ProcessType());
-  }
 
-  return pythiaGenHeader->ProcessType();
-}
 
 //____________________________________________________________________
 TParticle* AliPWG0Helper::FindPrimaryMother(AliStack* stack, Int_t label)
@@ -364,45 +467,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)
 {
@@ -432,3 +496,35 @@ void AliPWG0Helper::NormalizeToBinWidth(TH2* hist)
       hist->SetBinError(i, j, hist->GetBinError(i, j) / factor);
     }
 }
+
+//____________________________________________________________________
+void AliPWG0Helper::PrintConf(AnalysisMode analysisMode, Trigger trigger)
+{
+  //
+  // Prints the given configuration
+  //
+
+  TString str(">>>> Running with ");
+
+  switch (analysisMode)
+  {
+    case kInvalid: str += "invalid setting"; break;
+    case kSPD : str += "SPD-only"; break;
+    case kTPC : str += "TPC-only"; break;
+    case kTPCITS : str += "Global tracking"; break;
+  }
+
+  str += " and trigger ";
+
+  switch (trigger)
+  {
+    case kMB1 : str += "MB1"; break;
+    case kMB2 : str += "MB2"; break;
+    case kSPDFASTOR : str += "SPD FASTOR"; break;
+  }
+
+  str += " <<<<";
+
+  Printf("%s", str.Data());
+}
+