]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ANALYSIS/AliAnalysisTaskMCParticleFilter.cxx
Obsolete.
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisTaskMCParticleFilter.cxx
index 5d5233a97902db77f48b7b03e70aaf3095aa3271..aba20f8cdfe927e2c9ead2862f561c3e6fa84cd0 100644 (file)
 #include "AliAODHandler.h"
 #include "AliAODVertex.h"
 #include "AliAODMCParticle.h"
-
+#include "AliCollisionGeometry.h"
+#include "AliGenDPMjetEventHeader.h"
+#include "AliGenHijingEventHeader.h"
+#include "AliGenPythiaEventHeader.h"
+#include "AliGenCocktailEventHeader.h"
 
 #include "AliLog.h"
 
@@ -62,7 +66,7 @@ Bool_t AliAnalysisTaskMCParticleFilter::Notify()
 {
   //
   // Implemented Notify() to read the cross sections
-  // and number of trials from pyxsec.root
+  // from pyxsec.root
   // 
   TTree *tree = AliAnalysisManager::GetAnalysisManager()->GetTree();
   Double_t xsection = 0;
@@ -95,15 +99,13 @@ Bool_t AliAnalysisTaskMCParticleFilter::Notify()
     }
     TTree *xtree = (TTree*)fxsec->Get("Xsection");
     if(!xtree){
-      Printf("%s:%d tree not found in the pyxsec.root",(char*)__FILE__,__LINE__);
+      AliWarning(Form("%s:%d tree not found in the pyxsec.root",(char*)__FILE__,__LINE__));
       return kTRUE;
     }
     xtree->SetBranchAddress("xsection",&xsection);
     xtree->SetBranchAddress("ntrials",&ntrials);
     xtree->GetEntry(0);
     ((TProfile*)(fHistList->FindObject("h1Xsec")))->Fill("<#sigma>",xsection);
-    ((TH1F*)(fHistList->FindObject("h1Trials")))->Fill("#sum{ntrials}",ntrials); 
-
   }
   return kTRUE;
 }
@@ -117,7 +119,7 @@ AliAnalysisTaskMCParticleFilter::AliAnalysisTaskMCParticleFilter(const char* nam
     fHistList(0x0)
 {
   // Default constructor
-  DefineOutput(1,TList::Class());  
+  DefineOutput(1, TList::Class());  
 }
 
 /*
@@ -178,7 +180,7 @@ void AliAnalysisTaskMCParticleFilter::UserCreateOutputObjects()
     AliMCEventHandler *mcH = (AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler()); 
     AliAODHandler *aodH = dynamic_cast<AliAODHandler*> ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
     if(!aodH){
-      Printf("%s:&d Could not get AODHandler",(char*)__FILE__,__LINE__);
+      AliWarning("Could not get AODHandler");
       return;
     }
     aodH->SetMCEventHandler(mcH);
@@ -195,7 +197,7 @@ void AliAnalysisTaskMCParticleFilter::UserCreateOutputObjects()
     TProfile *h1Xsec = new TProfile("h1Xsec","xsec from pyxsec.root",1,0,1);
     h1Xsec->GetXaxis()->SetBinLabel(1,"<#sigma>");
     fHistList->Add(h1Xsec);
-    TH1F* h1Trials = new TH1F("h1Trials","trials from pyxsec.root",1,0,1);
+    TH1F* h1Trials = new TH1F("h1Trials","trials from MC header",1,0,1);
     h1Trials->GetXaxis()->SetBinLabel(1,"#sum{ntrials}");
     fHistList->Add(h1Trials);
 
@@ -222,6 +224,13 @@ void AliAnalysisTaskMCParticleFilter::UserExec(Option_t */*option*/)
     AliWarning("No MC handler Found");
     return;
   }
+  
+  AliAODHandler *aodH = dynamic_cast<AliAODHandler*> ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
+  if(!aodH){
+    AliWarning("Could not get AODHandler");
+    return;
+  }
+
 
 
   // fetch the output 
@@ -241,13 +250,69 @@ void AliAnalysisTaskMCParticleFilter::UserExec(Option_t */*option*/)
   Int_t np    = mcE->GetNumberOfTracks();
   Int_t nprim = mcE->GetNumberOfPrimaries();
   // TODO ADD MC VERTEX
+
+  AliAODMCHeader *aodMCHo = (AliAODMCHeader *) aod->FindListObject("mcHeader");
+  // Get the proper MC Collision Geometry
+  AliGenEventHeader* mcEH = mcE->GenEventHeader();
+
+  AliGenPythiaEventHeader *pyH  = dynamic_cast<AliGenPythiaEventHeader*>(mcEH);
+  AliGenHijingEventHeader *hiH  = 0;
+  AliCollisionGeometry    *colG = 0;
+  AliGenDPMjetEventHeader *dpmH = 0;
+  // it can be only one save some casts
+  // assuming PYTHIA and HIJING are the most likely ones...
+  if(!pyH){
+      hiH = dynamic_cast<AliGenHijingEventHeader*>(mcEH);
+      if(!hiH){
+         dpmH = dynamic_cast<AliGenDPMjetEventHeader*>(mcEH);
+      }
+  }
   
-  // We take all real primaries
+  if (hiH || dpmH) colG = dynamic_cast<AliCollisionGeometry*>(mcEH);
+
+  // fetch the trials on a event by event basis, not from pyxsec.root otherwise 
+  // we will get a problem when running on proof since Notify may be called 
+  // more than once per file
+  // consider storing this information in the AOD output via AliAODHandler
+  Float_t ntrials = 0;
+  if (!colG) {
+    AliGenCocktailEventHeader *ccEH = dynamic_cast<AliGenCocktailEventHeader *>(mcEH);
+    if (ccEH) {
+      TList *genHeaders = ccEH->GetHeaders();
+      for (int imch=0; imch<genHeaders->GetEntries(); imch++) {
+       if(!pyH)dynamic_cast<AliGenPythiaEventHeader*>(genHeaders->At(imch));
+       if(!hiH)dynamic_cast<AliGenHijingEventHeader*>(genHeaders->At(imch));
+       if(!colG)colG = dynamic_cast<AliCollisionGeometry *>(genHeaders->At(imch));
+       if(!dpmH)dynamic_cast<AliGenDPMjetEventHeader*>(genHeaders->At(imch));
+      }
+    }
+  }
+
+  // take the trials from the p+p event
+  if(hiH)ntrials = hiH->Trials();
+  if(dpmH)ntrials = dpmH->Trials();
+  if(pyH)ntrials = pyH->Trials();
+  if(ntrials)((TH1F*)(fHistList->FindObject("h1Trials")))->Fill("#sum{ntrials}",ntrials); 
+  
+
+
+
+  if (colG) {
+    aodMCHo->SetReactionPlaneAngle(colG->ReactionPlaneAngle());
+    AliInfo(Form("Found Collision Geometry. Got Reaction Plane %lf\n", colG->ReactionPlaneAngle()));
+  }
+
+
+
+  // check varibales for charm need all daughters
+  static int  iTaken = 0;
+  static int  iAll = 0;
+  static int  iCharm = 0;
 
 
   Int_t j=0;
   for (Int_t ip = 0; ip < np; ip++){
-    AliMCParticle* mcpart =  mcE->GetTrack(ip);
+    AliMCParticle* mcpart = (AliMCParticle*) mcE->GetTrack(ip);
     TParticle* part = mcpart->Particle();
     Float_t xv = part->Vx();
     Float_t yv = part->Vy();
@@ -265,11 +330,11 @@ void AliAnalysisTaskMCParticleFilter::UserExec(Option_t */*option*/)
       AliMCParticle* mother = mcpart;
       Int_t imo = mcpart->GetMother();
       while((imo >= nprim) && (mother->GetUniqueID() == 4)) {
-       mother = mcE->GetTrack(imo);
+       mother =  (AliMCParticle*) mcE->GetTrack(imo);
        imo =  mother->GetMother();
       }
       // Select according to pseudorapidity and production point of primary ancestor
-      if (imo < nprim && Select(mcE->GetTrack(imo)->Particle(), rv, zv))write = kTRUE;         
+      if (imo < nprim && Select(((AliMCParticle*) mcE->GetTrack(imo))->Particle(), rv, zv))write = kTRUE;         
     } else if (part->GetUniqueID() == 5) {
       // Now look for pair production
       Int_t imo = mcpart->GetMother();
@@ -278,10 +343,10 @@ void AliAnalysisTaskMCParticleFilter::UserExec(Option_t */*option*/)
        write = kTRUE;
       } else {
        // Check if the gamma comes from the decay chain of a primary particle
-       AliMCParticle* mother = mcE->GetTrack(imo);
+       AliMCParticle* mother =  (AliMCParticle*) mcE->GetTrack(imo);
        imo = mother->GetMother();
        while((imo >= nprim) && (mother->GetUniqueID() == 4)) {
-         mother =  mcE->GetTrack(imo);
+         mother =   (AliMCParticle*) mcE->GetTrack(imo);
          imo =  mother->GetMother();
        }
        // Select according to pseudorapidity and production point 
@@ -307,36 +372,25 @@ void AliAnalysisTaskMCParticleFilter::UserExec(Option_t */*option*/)
     if (write) {
       if(mcH)mcH->SelectParticle(ip);
       j++;
-    }
-  }
-
-
-    // check for charm daughters
-  static int  iTaken = 0;
-  static int  iAll = 0;
-  static int  iCharm = 0;
-  for (Int_t ip = 0; ip < np; ip++){
-    AliMCParticle* mcpart =  mcE->GetTrack(ip);
-    TParticle* part = mcpart->Particle();
-
-    //    if((TMath::Abs(part->GetPdgCode())/400)==1){
-    if((TMath::Abs(part->GetPdgCode()))==411){
-      // cases 
-      iCharm++;
-      Int_t d0 =  mcpart->GetFirstDaughter();
-      Int_t d1 =  mcpart->GetLastDaughter();
-      if(d0>0&&d1>0){
-       for(int id = d0;id <= d1;id++){
-         // AliMCParticle* daughter =  mcE->GetTrack(id);
-         iAll++;
-         if(mcH->IsParticleSelected(id))iTaken++;
+      
+      // debug info to check fro charm daugthers
+      if((TMath::Abs(part->GetPdgCode()))==411){
+       iCharm++;
+       Int_t d0 =  mcpart->GetFirstDaughter();
+       Int_t d1 =  mcpart->GetLastDaughter();
+       if(d0>0&&d1>0){
+         for(int id = d0;id <= d1;id++){
+           iAll++;
+           if(mcH->IsParticleSelected(id))iTaken++;
+         }
        }
-      }
+      }// if charm
     }
   }
 
   AliInfo(Form("Taken daughters %d/%d of %d charm",iTaken,iAll,iCharm));
 
+  aodH->StoreMCParticles();
   PostData(1,fHistList);
 
   return;
@@ -348,18 +402,12 @@ void AliAnalysisTaskMCParticleFilter::Terminate(Option_t */*option*/){
   //
 
 
-  TTree *tree = (TTree*)GetOutputData(0);
   fHistList = (TList*)GetOutputData(1);
   if(!fHistList){
     Printf("%s:%d Output list not found",(char*)__FILE__,__LINE__);
     return;
   }
 
-  if(!tree){
-    Printf("%s:%d Output tree not found",(char*)__FILE__,__LINE__);
-    return;
-  }
-
   TProfile *hXsec = ((TProfile*)(fHistList->FindObject("h1Xsec")));
   TH1F* hTrials  = ((TH1F*)(fHistList->FindObject("h1Trials")));
   if(!hXsec)return;
@@ -368,16 +416,6 @@ void AliAnalysisTaskMCParticleFilter::Terminate(Option_t */*option*/){
   Float_t xsec = hXsec->GetBinContent(1);
   Float_t trials = hTrials->Integral();
   AliInfo(Form("Average -section %.4E and total number of trials %E",xsec,trials));
-  
-  // This only works if the tree is not a special output
-  // in this case it is already written
-  /*
-  TParameter<float> *x = new TParameter<float>("xsection",xsec);
-  tree->GetUserInfo()->Add(x);
-  TParameter<float> *t = new TParameter<float>("trials",trials);
-  tree->GetUserInfo()->Add(t);
-  */
-  
 
 }