setter to assume pion mass for clusters
[u/mrichter/AliRoot.git] / PWGJE / EMCALJetTasks / AliJetEmbeddingFromGenTask.cxx
index 6bfff1b..beb9614 100644 (file)
@@ -1,4 +1,4 @@
-// $Id: AliJetEmbeddingFromGenTask.cxx 57324 2012-06-21 04:33:52Z loizides $
+// $Id$
 //
 // Jet embedding task.
 //
@@ -12,6 +12,7 @@
 #include <TParticle.h>
 #include <TParticlePDG.h>
 #include <TRandom3.h>
+#include <TProfile.h>
 #include "AliAnalysisManager.h"
 #include "AliEMCALDigit.h"
 #include "AliEMCALGeometry.h"
 #include "AliStack.h"
 #include "AliVCluster.h"
 #include "AliVEvent.h"
+#include "AliGenPythiaEventHeader.h"
 
 ClassImp(AliJetEmbeddingFromGenTask)
 
 //________________________________________________________________________
 AliJetEmbeddingFromGenTask::AliJetEmbeddingFromGenTask() : 
   AliJetModelBaseTask("AliJetEmbeddingFromGenTask"),
-  fGen(0)
+  fGen(0),
+  fMassless(kFALSE),
+  fChargedOnly(kFALSE),
+  fHistPt(0),
+  fHistEtaPhi(0),
+  fHistTrials(0),
+  fHistXsection(0),
+  fHistPtHard(0)
 {
   // Default constructor.
   SetSuffix("EmbeddedFromGen");
 }
 
 //________________________________________________________________________
-AliJetEmbeddingFromGenTask::AliJetEmbeddingFromGenTask(const char *name) : 
-  AliJetModelBaseTask(name),
-  fGen(0)
+AliJetEmbeddingFromGenTask::AliJetEmbeddingFromGenTask(const char *name, Bool_t drawqa) :
+  AliJetModelBaseTask(name,drawqa),
+  fGen(0),
+  fMassless(kFALSE),
+  fChargedOnly(kFALSE),
+  fHistPt(0),
+  fHistEtaPhi(0),
+  fHistTrials(0),
+  fHistXsection(0),
+  fHistPtHard(0)
 {
   // Standard constructor.
   SetSuffix("EmbeddedFromGen");
@@ -54,11 +70,42 @@ AliJetEmbeddingFromGenTask::~AliJetEmbeddingFromGenTask()
 }
 
 //________________________________________________________________________
-void AliJetEmbeddingFromGenTask::ExecOnce() 
+void AliJetEmbeddingFromGenTask::UserCreateOutputObjects()
+{
+  // Create user output.
+
+  if (!fQAhistos)
+    return;
+
+  AliJetModelBaseTask::UserCreateOutputObjects();
+
+  fHistPt = new TH1F("fHistpt","fHistPt;#it{p}_{T};N",100,0.,100.);
+  fOutput->Add(fHistPt);
+
+  fHistEtaPhi = new TH2F("fHistEtaPhi","fHistEtaPhi;#eta;#varphi",100,-3.,3.,100.,0.,TMath::TwoPi());
+  fOutput->Add(fHistEtaPhi);
+
+  fHistTrials = new TH1F("fHistTrials", "fHistTrials", 1, 0, 1);
+  fHistTrials->GetYaxis()->SetTitle("trials");
+  fOutput->Add(fHistTrials);
+
+  fHistXsection = new TProfile("fHistXsection", "fHistXsection", 1, 0, 1);
+  fHistXsection->GetYaxis()->SetTitle("xsection");
+  fOutput->Add(fHistXsection);
+
+  fHistPtHard = new TH1F("fHistPtHard", "fHistPtHard", 500, 0., 500.);
+  fHistPtHard->GetXaxis()->SetTitle("p_{T,hard} (GeV/c)");
+  fHistPtHard->GetYaxis()->SetTitle("counts");
+  fOutput->Add(fHistPtHard);
+
+  PostData(1, fOutput);
+}
+
+//________________________________________________________________________
+Bool_t AliJetEmbeddingFromGenTask::ExecOnce() 
 {
   // Exec only once.
 
-  cout << "afjalfja " <<endl;
   if (!gAlice) {
     new AliRun("gAlice","The ALICE Off-line Simulation Framework");
     delete gRandom;
@@ -73,11 +120,14 @@ void AliJetEmbeddingFromGenTask::ExecOnce()
   fGen->SetStack(stack);
   fGen->Init();
 
-  if (InputEvent()->FindListObject(fTracksName) == 0) {
+  if (!(InputEvent()->FindListObject(fTracksName))) {
     fOutTracks = new TClonesArray("AliPicoTrack", 1000);
     fOutTracks->SetName(fTracksName);
+    InputEvent()->AddObject(fOutTracks);
     fNTracks = 0;
   }
+  
+  return kTRUE;
 }
 
 //________________________________________________________________________
@@ -100,8 +150,7 @@ void AliJetEmbeddingFromGenTask::Run()
     if (!pdg) 
       continue;
     Int_t c = (Int_t)(TMath::Abs(pdg->Charge()));
-    if (c==0) 
-      continue;
+    if (fChargedOnly && c==0)  continue;
     Double_t pt = part->Pt();
     Double_t eta = part->Eta();
     Double_t phi = part->Phi();
@@ -117,6 +166,32 @@ void AliJetEmbeddingFromGenTask::Run()
       continue;
     if (pt>fPtMax)
       continue;
-    AddTrack(pt, eta, phi);
+    Double_t mass = part->GetMass();
+    if(fMassless) mass = 0.;
+    fHistPt->Fill(pt);
+    fHistEtaPhi->Fill(eta,phi);
+    AddTrack(pt, eta, phi,0,0,0,0,0,0,c,mass);
+  }
+
+  FillPythiaHistograms();
+}
+
+//________________________________________________________________________
+void AliJetEmbeddingFromGenTask::FillPythiaHistograms() {
+  //Get PYTHIA info: pt-hard, x-section, trials
+
+  if (!fQAhistos)
+    return;
+
+  AliRunLoader *rl = AliRunLoader::Instance();
+  AliGenPythiaEventHeader *genPH = dynamic_cast<AliGenPythiaEventHeader*>(rl->GetHeader()->GenEventHeader());
+  if(genPH) {
+    Float_t xsec = genPH->GetXsection();
+    Int_t trials = genPH->Trials();
+    Float_t pthard = genPH->GetPtHard();
+
+    fHistXsection->Fill(0.5,xsec);
+    fHistTrials->Fill(0.5,trials);
+    fHistPtHard->Fill(pthard);
   }
 }