automatically write MC info into the trees when MC available
authormkrzewic <mkrzewic@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 23 Apr 2013 10:20:31 +0000 (10:20 +0000)
committermkrzewic <mkrzewic@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 23 Apr 2013 10:20:31 +0000 (10:20 +0000)
PWGPP/AliAnalysisTaskFilteredTree.cxx
PWGPP/AliAnalysisTaskFilteredTree.h
PWGPP/macros/AddTaskFilteredTree.C

index 56ec566..1e75729 100644 (file)
@@ -110,13 +110,13 @@ AliAnalysisTaskFilteredTree::~AliAnalysisTaskFilteredTree()
 {\r
   //the output trees not to be deleted in case of proof analysis\r
   Bool_t deleteTrees=kTRUE;\r
-  if ((AliAnalysisManager::GetAnalysisManager()))\r
-  {\r
-    if (AliAnalysisManager::GetAnalysisManager()->GetAnalysisType() == \r
-             AliAnalysisManager::kProofAnalysis)\r
-      deleteTrees=kFALSE;\r
-  }\r
-  if (deleteTrees) delete fTreeSRedirector;\r
+  //if ((AliAnalysisManager::GetAnalysisManager()))\r
+  //{\r
+  //  if (AliAnalysisManager::GetAnalysisManager()->GetAnalysisType() == \r
+  //           AliAnalysisManager::kProofAnalysis)\r
+  //    deleteTrees=kFALSE;\r
+  //}\r
+  //if (deleteTrees) delete fTreeSRedirector;\r
 \r
   delete fFilteredTreeEventCuts;\r
   delete fFilteredTreeAcceptanceCuts;\r
@@ -180,14 +180,17 @@ void AliAnalysisTaskFilteredTree::UserExec(Option_t *)
     return;\r
   }\r
 \r
-  // MC event\r
-  if(fUseMCInfo) {\r
-    fMC = MCEvent();\r
-    if (!fMC) {\r
-      Printf("ERROR: MC event not available");\r
-      return;\r
-    }\r
-  }\r
+  //// MC event\r
+  //if(fUseMCInfo) {\r
+  //  fMC = MCEvent();\r
+  //  if (!fMC) {\r
+  //    Printf("ERROR: MC event not available");\r
+  //    return;\r
+  //  }\r
+  //}\r
+  \r
+  //if MC info available - use it.\r
+  fMC = MCEvent();\r
 \r
   if(fUseESDfriends) {\r
     fESDfriend = static_cast<AliESDfriend*>(fESD->FindListObject("AliESDfriend"));\r
@@ -210,7 +213,7 @@ void AliAnalysisTaskFilteredTree::UserExec(Option_t *)
   ProcessdEdx(fESD,fMC,fESDfriend);\r
 \r
   if (fProcessCosmics) { ProcessCosmics(fESD); }\r
-  if(IsUseMCInfo()) { ProcessMCEff(fESD,fMC,fESDfriend); }\r
+  if(IsUseMCInfo()) { ProcessMCEff(fESD,fMC,fESDfriend);}\r
 }\r
 \r
 //_____________________________________________________________________________\r
@@ -1123,7 +1126,7 @@ void AliAnalysisTaskFilteredTree::ProcessAll(AliESDEvent *const esdEvent, AliMCE
       \r
       if(isOKtpcInnerC  && isOKtrackInnerC) dumpToTree = kTRUE;\r
       if(fUseESDfriends && isOKtrackInnerC2 && isOKouterITSc) dumpToTree = kTRUE;\r
-      if(fUseMCInfo     && isOKtrackInnerC3) dumpToTree = kTRUE;\r
+      if(fMC && isOKtrackInnerC3) dumpToTree = kTRUE;\r
       TObjString triggerClass = esdEvent->GetFiredTriggerClasses().Data();\r
       if (fReducePileUp){  \r
        //\r
@@ -1178,7 +1181,7 @@ void AliAnalysisTaskFilteredTree::ProcessAll(AliESDEvent *const esdEvent, AliMCE
       if (!trackInnerC2) {trackInnerC2=new AliExternalTrackParam();newtrackInnerC2=kTRUE;}\r
       if (!outerITSc) {outerITSc=new AliExternalTrackParam();newouterITSc=kTRUE;}\r
       if (!trackInnerC3) {trackInnerC3=new AliExternalTrackParam();newtrackInnerC3=kTRUE;}\r
-      if (fUseMCInfo)\r
+      if (fMC)\r
       {\r
         if (!refTPCIn) {refTPCIn=new AliTrackReference(); newrefTPCIn=kTRUE;}\r
         if (!refITS) {refITS=new AliTrackReference();newrefITS=kTRUE;}\r
@@ -1232,7 +1235,7 @@ void AliAnalysisTaskFilteredTree::ProcessAll(AliESDEvent *const esdEvent, AliMCE
          "chi2InnerC="<<chi2trackC(0,0)<<        // chi2s  of tracks TPCinner to the combined\r
          "chi2OuterITS="<<chi2OuterITS(0,0)<<    // chi2s  of tracks TPC at inner wall to the ITSout\r
          "centralityF="<<centralityF;\r
-        if (fUseMCInfo)\r
+        if (fMC)\r
         {\r
           (*fTreeSRedirector)<<"highPt"<<\r
           "refTPCIn.="<<refTPCIn<<\r
@@ -1306,13 +1309,14 @@ void AliAnalysisTaskFilteredTree::ProcessMCEff(AliESDEvent *const esdEvent, AliM
 {\r
   //\r
   // Fill tree for efficiency studies MC only\r
+  AliInfo("we start!");\r
 \r
   if(!esdEvent) {\r
     AliDebug(AliLog::kError, "esdEvent not available");\r
     return;\r
   }\r
 \r
-   if(!mcEvent) {\r
+  if(!mcEvent) {\r
     AliDebug(AliLog::kError, "mcEvent not available");\r
     return;\r
   }\r
@@ -1339,7 +1343,7 @@ void AliAnalysisTaskFilteredTree::ProcessMCEff(AliESDEvent *const esdEvent, AliM
     Printf("ERROR: Could not receive input handler");\r
     return;\r
   }\r
-   \r
+\r
   // get file name\r
   TTree *chain = (TChain*)GetInputData(0);\r
   if(!chain) { \r
@@ -1377,51 +1381,48 @@ void AliAnalysisTaskFilteredTree::ProcessMCEff(AliESDEvent *const esdEvent, AliM
   TArrayF vtxMC(3);\r
 \r
   Int_t multMCTrueTracks = 0;\r
-  if(IsUseMCInfo())\r
-  {\r
-    //\r
-    if(!mcEvent) {\r
-      AliDebug(AliLog::kError, "mcEvent not available");\r
-      return;\r
-    }\r
-    // get MC event header\r
-    header = mcEvent->Header();\r
-    if (!header) {\r
-      AliDebug(AliLog::kError, "Header not available");\r
-      return;\r
-    }\r
-    // MC particle stack\r
-    stack = mcEvent->Stack();\r
-    if (!stack) {\r
-      AliDebug(AliLog::kError, "Stack not available");\r
-      return;\r
-    }\r
+  //\r
+  if(!mcEvent) {\r
+    AliDebug(AliLog::kError, "mcEvent not available");\r
+    return;\r
+  }\r
+  // get MC event header\r
+  header = mcEvent->Header();\r
+  if (!header) {\r
+    AliDebug(AliLog::kError, "Header not available");\r
+    return;\r
+  }\r
+  // MC particle stack\r
+  stack = mcEvent->Stack();\r
+  if (!stack) {\r
+    AliDebug(AliLog::kError, "Stack not available");\r
+    return;\r
+  }\r
 \r
-    // get MC vertex\r
-    genHeader = header->GenEventHeader();\r
-    if (!genHeader) {\r
-      AliDebug(AliLog::kError, "Could not retrieve genHeader from Header");\r
-      return;\r
-    }\r
-    genHeader->PrimaryVertex(vtxMC);\r
+  // get MC vertex\r
+  genHeader = header->GenEventHeader();\r
+  if (!genHeader) {\r
+    AliDebug(AliLog::kError, "Could not retrieve genHeader from Header");\r
+    return;\r
+  }\r
+  genHeader->PrimaryVertex(vtxMC);\r
 \r
-    // multipliticy of all MC primary tracks\r
-    // in Zv, pt and eta ranges)\r
-    multMCTrueTracks = GetMCTrueTrackMult(mcEvent,evtCuts,accCuts);\r
+  // multipliticy of all MC primary tracks\r
+  // in Zv, pt and eta ranges)\r
+  multMCTrueTracks = GetMCTrueTrackMult(mcEvent,evtCuts,accCuts);\r
 \r
-  } // end bUseMC\r
 \r
   // get reconstructed vertex  \r
   //const AliESDVertex* vtxESD = 0; \r
   AliESDVertex* vtxESD = 0; \r
   if(GetAnalysisMode() == kTPCAnalysisMode) {\r
-        vtxESD = (AliESDVertex*)esdEvent->GetPrimaryVertexTPC();\r
+    vtxESD = (AliESDVertex*)esdEvent->GetPrimaryVertexTPC();\r
   }\r
   else if(GetAnalysisMode() == kTPCITSAnalysisMode) {\r
-     vtxESD = (AliESDVertex*)esdEvent->GetPrimaryVertexTracks();\r
+    vtxESD = (AliESDVertex*)esdEvent->GetPrimaryVertexTracks();\r
   }\r
   else {\r
-       return;\r
+    return;\r
   }\r
 \r
   if(!vtxESD) return;\r
@@ -1435,119 +1436,116 @@ void AliAnalysisTaskFilteredTree::ProcessMCEff(AliESDEvent *const esdEvent, AliM
   // check event cuts\r
   if(isEventOK && isEventTriggered)\r
   {\r
-    if(IsUseMCInfo()) \r
+    if(!stack) return;\r
+\r
+    //\r
+    // MC info\r
+    //\r
+    TParticle *particle=NULL;\r
+    TParticle *particleMother=NULL;\r
+    Int_t mech=-1;\r
+\r
+    // reco event info\r
+    Double_t vert[3] = {0}; \r
+    vert[0] = vtxESD->GetXv();\r
+    vert[1] = vtxESD->GetYv();\r
+    vert[2] = vtxESD->GetZv();\r
+    Int_t mult = vtxESD->GetNContributors();\r
+    Double_t bz = esdEvent->GetMagneticField();\r
+    Double_t runNumber = esdEvent->GetRunNumber();\r
+    Double_t evtTimeStamp = esdEvent->GetTimeStamp();\r
+    Int_t evtNumberInFile = esdEvent->GetEventNumberInFile();\r
+\r
+    // loop over MC stack\r
+    for (Int_t iMc = 0; iMc < stack->GetNtrack(); ++iMc) \r
     {\r
-      if(!stack) return;\r
+      particle = stack->Particle(iMc);\r
+      if (!particle)\r
+        continue;\r
+\r
+      // only charged particles\r
+      if(!particle->GetPDG()) continue;\r
+      Double_t charge = particle->GetPDG()->Charge()/3.;\r
+      if (TMath::Abs(charge) < 0.001)\r
+        continue;\r
+\r
+      // only primary particles\r
+      Bool_t prim = stack->IsPhysicalPrimary(iMc);\r
+      if(!prim) continue;\r
+\r
+      // downscale low-pT particles\r
+      Double_t scalempt= TMath::Min(particle->Pt(),10.);\r
+      Double_t downscaleF = gRandom->Rndm();\r
+      downscaleF *= fLowPtTrackDownscaligF;\r
+      if(TMath::Exp(2*scalempt)<downscaleF) continue;\r
 \r
-      //\r
-      // MC info\r
-      //\r
-      TParticle *particle=NULL;\r
-      TParticle *particleMother=NULL;\r
-      Int_t mech=-1;\r
-\r
-      // reco event info\r
-      Double_t vert[3] = {0}; \r
-      vert[0] = vtxESD->GetXv();\r
-      vert[1] = vtxESD->GetYv();\r
-      vert[2] = vtxESD->GetZv();\r
-      Int_t mult = vtxESD->GetNContributors();\r
-      Double_t bz = esdEvent->GetMagneticField();\r
-      Double_t runNumber = esdEvent->GetRunNumber();\r
-      Double_t evtTimeStamp = esdEvent->GetTimeStamp();\r
-      Int_t evtNumberInFile = esdEvent->GetEventNumberInFile();\r
+      // is particle in acceptance\r
+      if(!accCuts->AcceptTrack(particle)) continue;\r
 \r
-      // loop over MC stack\r
-      for (Int_t iMc = 0; iMc < stack->GetNtrack(); ++iMc) \r
+      // check if particle reconstructed\r
+      Bool_t isRec = kFALSE;\r
+      Int_t  trackIndex = -1;\r
+      for (Int_t iTrack = 0; iTrack < esdEvent->GetNumberOfTracks(); iTrack++)\r
       {\r
-         particle = stack->Particle(iMc);\r
-         if (!particle)\r
-         continue;\r
-\r
-         // only charged particles\r
-         if(!particle->GetPDG()) continue;\r
-         Double_t charge = particle->GetPDG()->Charge()/3.;\r
-         if (TMath::Abs(charge) < 0.001)\r
-         continue;\r
-\r
-         // only primary particles\r
-         Bool_t prim = stack->IsPhysicalPrimary(iMc);\r
-         if(!prim) continue;\r
-\r
-         // downscale low-pT particles\r
-         Double_t scalempt= TMath::Min(particle->Pt(),10.);\r
-         Double_t downscaleF = gRandom->Rndm();\r
-         downscaleF *= fLowPtTrackDownscaligF;\r
-         if(TMath::Exp(2*scalempt)<downscaleF) continue;\r
-\r
-         // is particle in acceptance\r
-         if(!accCuts->AcceptTrack(particle)) continue;\r
-       \r
-         // check if particle reconstructed\r
-         Bool_t isRec = kFALSE;\r
-         Int_t  trackIndex = -1;\r
-         for (Int_t iTrack = 0; iTrack < esdEvent->GetNumberOfTracks(); iTrack++)\r
-         {\r
-           \r
-           AliESDtrack *track = esdEvent->GetTrack(iTrack);\r
-           if(!track) continue;\r
-           if(track->Charge()==0) continue;\r
-           if(esdTrackCuts->AcceptTrack(track) && accCuts->AcceptTrack(track)) \r
-           {\r
-             Int_t label =  TMath::Abs(track->GetLabel());\r
-             if(label == iMc) {\r
-               isRec = kTRUE;\r
-               trackIndex = iTrack;\r
-               break;\r
-             }\r
-           } \r
-         }\r
-\r
-         // Store information in the output tree\r
-         AliESDtrack *recTrack = NULL; \r
-         if(trackIndex>-1)  { \r
-           recTrack = esdEvent->GetTrack(trackIndex); \r
-         } else {\r
-           recTrack = new AliESDtrack(); \r
-         } \r
-\r
-        particleMother = GetMother(particle,stack);\r
-         mech = particle->GetUniqueID();\r
-\r
-         //MC particle track length\r
-         Double_t tpcTrackLength = 0.;\r
-         AliMCParticle *mcParticle = (AliMCParticle*) mcEvent->GetTrack(iMc);\r
-         if(mcParticle) {\r
-           Int_t counter;\r
-           tpcTrackLength = mcParticle->GetTPCTrackLength(bz,0.05,counter,3.0);\r
-         } \r
-\r
-\r
-         //\r
-         if(fTreeSRedirector) {\r
-           (*fTreeSRedirector)<<"MCEffTree"<<\r
-           "fileName.="<<&fileName<<\r
-           "triggerClass.="<<&triggerClass<<\r
-           "runNumber="<<runNumber<<\r
-           "evtTimeStamp="<<evtTimeStamp<<\r
-           "evtNumberInFile="<<evtNumberInFile<<\r
-           "Bz="<<bz<<\r
-           "vtxESD.="<<vtxESD<<\r
-           "mult="<<mult<<\r
-           "esdTrack.="<<recTrack<<\r
-           "isRec="<<isRec<<\r
-           "tpcTrackLength="<<tpcTrackLength<<\r
-           "particle.="<<particle<<\r
-                  "particleMother.="<<particleMother<<\r
-           "mech="<<mech<<\r
-           "\n";\r
-         }\r
-\r
-         if(trackIndex <0 && recTrack) delete recTrack; recTrack=0;\r
+\r
+        AliESDtrack *track = esdEvent->GetTrack(iTrack);\r
+        if(!track) continue;\r
+        if(track->Charge()==0) continue;\r
+        if(esdTrackCuts->AcceptTrack(track) && accCuts->AcceptTrack(track)) \r
+        {\r
+          Int_t label =  TMath::Abs(track->GetLabel());\r
+          if(label == iMc) {\r
+            isRec = kTRUE;\r
+            trackIndex = iTrack;\r
+            break;\r
+          }\r
+        } \r
       }\r
+\r
+      // Store information in the output tree\r
+      AliESDtrack *recTrack = NULL; \r
+      if(trackIndex>-1)  { \r
+        recTrack = esdEvent->GetTrack(trackIndex); \r
+      } else {\r
+        recTrack = new AliESDtrack(); \r
+      } \r
+\r
+      particleMother = GetMother(particle,stack);\r
+      mech = particle->GetUniqueID();\r
+\r
+      //MC particle track length\r
+      Double_t tpcTrackLength = 0.;\r
+      AliMCParticle *mcParticle = (AliMCParticle*) mcEvent->GetTrack(iMc);\r
+      if(mcParticle) {\r
+        Int_t counter;\r
+        tpcTrackLength = mcParticle->GetTPCTrackLength(bz,0.05,counter,3.0);\r
+      } \r
+\r
+\r
+      //\r
+      if(fTreeSRedirector) {\r
+        (*fTreeSRedirector)<<"MCEffTree"<<\r
+          "fileName.="<<&fileName<<\r
+          "triggerClass.="<<&triggerClass<<\r
+          "runNumber="<<runNumber<<\r
+          "evtTimeStamp="<<evtTimeStamp<<\r
+          "evtNumberInFile="<<evtNumberInFile<<\r
+          "Bz="<<bz<<\r
+          "vtxESD.="<<vtxESD<<\r
+          "mult="<<mult<<\r
+          "esdTrack.="<<recTrack<<\r
+          "isRec="<<isRec<<\r
+          "tpcTrackLength="<<tpcTrackLength<<\r
+          "particle.="<<particle<<\r
+          "particleMother.="<<particleMother<<\r
+          "mech="<<mech<<\r
+          "\n";\r
+      }\r
+\r
+      if(trackIndex <0 && recTrack) delete recTrack; recTrack=0;\r
     }\r
   }\r
-  \r
+\r
 }\r
 \r
 //_____________________________________________________________________________\r
@@ -2246,6 +2244,16 @@ void AliAnalysisTaskFilteredTree::Terminate(Option_t *)
     return;\r
   }\r
   */\r
+  \r
+  Bool_t deleteTrees=kTRUE;\r
+  if ((AliAnalysisManager::GetAnalysisManager()))\r
+  {\r
+    if (AliAnalysisManager::GetAnalysisManager()->GetAnalysisType() == \r
+             AliAnalysisManager::kProofAnalysis)\r
+      deleteTrees=kFALSE;\r
+  }\r
+  if (deleteTrees) delete fTreeSRedirector;\r
+  fTreeSRedirector=NULL;\r
 }\r
 \r
 //_____________________________________________________________________________\r
index feecc63..4530b3e 100644 (file)
@@ -48,7 +48,7 @@ class AliAnalysisTaskFilteredTree : public AliAnalysisTaskSE {
   virtual Bool_t Notify();
   virtual void   FinishTaskOutput();
   void SetUseMCInfo(Bool_t info)           { fUseMCInfo = info; }
-  Bool_t IsUseMCInfo() const               { return fUseMCInfo; }
+  Bool_t IsUseMCInfo() const               { return (fMC)?kTRUE:kFALSE; }
   void SetUseESDfriends(Bool_t friends)    { fUseESDfriends = friends; }
   Bool_t IsUseESDfriends() const              { return fUseESDfriends; }
   
index b2b0937..221803d 100644 (file)
@@ -72,7 +72,7 @@ AliAnalysisTask* AddTaskFilteredTree(TString outputFile="")
   // Create task
   //
   AliAnalysisTaskFilteredTree *task = new AliAnalysisTaskFilteredTree("AliAnalysisTaskFilteredTree");
-  task->SetUseMCInfo(hasMC);
+  //task->SetUseMCInfo(hasMC);
   //task->SetLowPtTrackDownscaligF(1.e4);
   //task->SetLowPtV0DownscaligF(1.e2);
   task->SetLowPtTrackDownscaligF(1.e7);
@@ -91,7 +91,6 @@ AliAnalysisTask* AddTaskFilteredTree(TString outputFile="")
   // AlidNdPtHelper::ParticleMode particleMode = AlidNdPtHelper::kAllPart ;
   //AlidNdPtHelper::AnalysisMode analysisMode = AlidNdPtHelper::kTPCITS;
 
-  task->SetUseMCInfo(hasMC);
   task->SetEventCuts(evtCuts);
   task->SetAcceptanceCuts(accCuts);
   task->SetTrackCuts(esdTrackCuts);