]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWGJE/EMCALJetTasks/AliJetEmbeddingFromAODTask.cxx
update histos
[u/mrichter/AliRoot.git] / PWGJE / EMCALJetTasks / AliJetEmbeddingFromAODTask.cxx
index 6c727e8c2688d98b98125c8c4d12b4d478b3435c..8a782d56468581b7ee2f7062b45a989a924b31ed 100644 (file)
@@ -1,4 +1,4 @@
-// $Id: AliJetEmbeddingFromAODTask.cxx $
+// $Id$
 //
 // Jet embedding from AOD task.
 //
@@ -39,6 +39,7 @@
 #include "AliFJWrapper.h"
 #include "AliLog.h"
 #include "AliInputEventHandler.h"
+#include "AliNamedString.h"
 
 ClassImp(AliJetEmbeddingFromAODTask)
 
@@ -54,10 +55,11 @@ AliJetEmbeddingFromAODTask::AliJetEmbeddingFromAODTask() :
   fAODClusName(),
   fAODCellsName(),
   fAODMCParticlesName(),
-  fMinCentrality(0),
-  fMaxCentrality(10),
+  fMinCentrality(-1),
+  fMaxCentrality(-1),
   fTriggerMask(AliVEvent::kAny),
   fZVertexCut(10),
+  fMaxVertexDist(999),
   fJetMinPt(0),
   fJetMinEta(-0.5),
   fJetMaxEta(0.5),
@@ -68,6 +70,9 @@ AliJetEmbeddingFromAODTask::AliJetEmbeddingFromAODTask() :
   fJetType(0),
   fJetAlgo(1),
   fJetParticleLevel(kTRUE),
+  fParticleMinPt(0),
+  fParticleMaxPt(0),
+  fParticleSelection(0),
   fIncludeNoITS(kFALSE),
   fCutMaxFractionSharedTPCClusters(0.4),
   fUseNegativeLabels(kTRUE),
@@ -88,10 +93,13 @@ AliJetEmbeddingFromAODTask::AliJetEmbeddingFromAODTask() :
   fAODCaloCells(0),
   fAODMCParticles(0),
   fCurrentAODEntry(-1),
+  fAODFilePath(0),
   fHistFileMatching(0),
   fHistAODFileError(0),
   fHistNotEmbedded(0),
-  fHistEmbeddingQA(0)
+  fHistEmbeddingQA(0),
+  fHistRejectedEvents(0),
+  fEmbeddingCount(0)
 {
   // Default constructor.
   SetSuffix("AODEmbedding");
@@ -117,10 +125,11 @@ AliJetEmbeddingFromAODTask::AliJetEmbeddingFromAODTask(const char *name, Bool_t
   fAODClusName(""),
   fAODCellsName("emcalCells"),
   fAODMCParticlesName(AliAODMCParticle::StdBranchName()),
-  fMinCentrality(0),
-  fMaxCentrality(10),
+  fMinCentrality(-1),
+  fMaxCentrality(-1),
   fTriggerMask(AliVEvent::kAny),
   fZVertexCut(10),
+  fMaxVertexDist(999),
   fJetMinPt(0),
   fJetMinEta(-0.5),
   fJetMaxEta(0.5),
@@ -131,6 +140,9 @@ AliJetEmbeddingFromAODTask::AliJetEmbeddingFromAODTask(const char *name, Bool_t
   fJetType(0),
   fJetAlgo(1),
   fJetParticleLevel(kTRUE),
+  fParticleMinPt(0),
+  fParticleMaxPt(0),
+  fParticleSelection(0),
   fIncludeNoITS(kFALSE),
   fCutMaxFractionSharedTPCClusters(0.4),
   fUseNegativeLabels(kTRUE),
@@ -151,10 +163,13 @@ AliJetEmbeddingFromAODTask::AliJetEmbeddingFromAODTask(const char *name, Bool_t
   fAODCaloCells(0),  
   fAODMCParticles(0),
   fCurrentAODEntry(-1),
+  fAODFilePath(0),
   fHistFileMatching(0),
   fHistAODFileError(0),
   fHistNotEmbedded(0),
-  fHistEmbeddingQA(0)
+  fHistEmbeddingQA(0),
+  fHistRejectedEvents(0),
+  fEmbeddingCount(0)
 {
   // Standard constructor.
   SetSuffix("AODEmbedding");
@@ -210,6 +225,11 @@ void AliJetEmbeddingFromAODTask::UserCreateOutputObjects()
   fHistEmbeddingQA->GetXaxis()->SetBinLabel(2, "Not embedded");
   fOutput->Add(fHistEmbeddingQA);
 
+  fHistRejectedEvents = new TH1F("fHistRejectedEvents", "fHistRejectedEvents", 500, -0.5, 499.5);
+  fHistRejectedEvents->GetXaxis()->SetTitle("# of rejected events");
+  fHistRejectedEvents->GetYaxis()->SetTitle("counts");
+  fOutput->Add(fHistRejectedEvents);
+
   PostData(1, fOutput);
 }
 
@@ -241,6 +261,13 @@ Bool_t AliJetEmbeddingFromAODTask::ExecOnce()
   else
     fEsdTreeMode = kTRUE;
 
+  fAODFilePath = static_cast<AliNamedString*>(InputEvent()->FindListObject("AODEmbeddingFile"));
+  if (!fAODFilePath) {
+    fAODFilePath = new AliNamedString("AODEmbeddingFile", "");
+    AliDebug(3,"Adding AOD embedding file path object to the event list...");
+    InputEvent()->AddObject(fAODFilePath);
+  }
+
   return AliJetModelBaseTask::ExecOnce();
 }
 
@@ -305,12 +332,14 @@ Bool_t AliJetEmbeddingFromAODTask::OpenNextFile()
   if (fRandomAccess)
     fCurrentAODEntry = TMath::Nint(gRandom->Rndm()*fCurrentAODTree->GetEntries());
   else
-    fCurrentAODEntry = 0;
+    fCurrentAODEntry = -1;
 
-  AliDebug(3,Form("Will start embedding from entry %d", fCurrentAODEntry));
+  AliDebug(3,Form("Will start embedding from entry %d", fCurrentAODEntry+1));
   
   if (fHistFileMatching)
     fHistFileMatching->Fill(fCurrentFileID, fCurrentAODFileID-1);
+
+  fEmbeddingCount = 0;
   
   return kTRUE;
 }
@@ -361,33 +390,46 @@ TFile* AliJetEmbeddingFromAODTask::GetNextFile()
 //________________________________________________________________________
 Bool_t AliJetEmbeddingFromAODTask::GetNextEntry() 
 {
-  Int_t attempts = 0;
+  Int_t attempts = -1;
 
   do {
-    if (!fCurrentAODFile || !fCurrentAODTree || fCurrentAODEntry >= fCurrentAODTree->GetEntries()) {
+    if (!fCurrentAODFile || !fCurrentAODTree || fCurrentAODEntry+1 >= fCurrentAODTree->GetEntries()) {
       if (!OpenNextFile()) {
        AliError("Could not open the next file!");
        return kFALSE;
       }
     }
+
+    if (!fCurrentAODTree) {
+      AliError("Could not get the tree!");
+      return kFALSE;
+    }
     
-    fCurrentAODTree->GetEntry(fCurrentAODEntry);
     fCurrentAODEntry++;
-    attempts++;
+    fCurrentAODTree->GetEntry(fCurrentAODEntry);
 
+    attempts++;
     if (attempts == 1000) 
       AliWarning("After 1000 attempts no event has been accepted by the event selection (trigger, centrality...)!");
 
-  } while (!IsAODEventSelected() && fCurrentAODTree);
+  } while (!IsAODEventSelected());
+
+  if (fHistRejectedEvents)
+    fHistRejectedEvents->Fill(attempts);
+
+  if (!fCurrentAODTree)
+    return kFALSE;
+
+  fEmbeddingCount++;
 
-  return (fCurrentAODTree!=0);
+  return kTRUE;
 }
 
 //________________________________________________________________________
 Bool_t AliJetEmbeddingFromAODTask::IsAODEventSelected()
 {
   // AOD event selection.
-  
+
   if (!fEsdTreeMode && fAODHeader) {
     AliAODHeader *aodHeader = static_cast<AliAODHeader*>(fAODHeader);
 
@@ -423,8 +465,22 @@ Bool_t AliJetEmbeddingFromAODTask::IsAODEventSelected()
                      vert[2], fZVertexCut));
       return kFALSE;
     }
+    Double_t dist = TMath::Sqrt((vert[0]-fVertex[0])*(vert[0]-fVertex[0])+(vert[1]-fVertex[1])*(vert[1]-fVertex[1])+(vert[2]-fVertex[2])*(vert[2]-fVertex[2]));
+    if (dist > fMaxVertexDist) {
+      AliDebug(2,Form("Event rejected because the distance between the current and embedded verteces is > %f. "
+                     "Current event vertex (%f, %f, %f), embedded event vertex (%f, %f, %f). Distance = %f", 
+                     fMaxVertexDist, fVertex[0], fVertex[1], fVertex[2], vert[0], vert[1], vert[2], dist));
+      return kFALSE;
+    }
+      
   }
 
+  // Particle selection
+  if ((fParticleSelection == 1 && FindParticleInRange(fAODTracks)==kFALSE) ||
+      (fParticleSelection == 2 && FindParticleInRange(fAODClusters)==kFALSE) ||
+      (fParticleSelection == 3 && FindParticleInRange(fAODMCParticles)==kFALSE))
+    return kFALSE;
+
   // Jet selection
   if (fJetMinPt > 0) {
     TLorentzVector jet;
@@ -454,6 +510,39 @@ Bool_t AliJetEmbeddingFromAODTask::IsAODEventSelected()
   return kTRUE;
 }
 
+//________________________________________________________________________
+Bool_t AliJetEmbeddingFromAODTask::FindParticleInRange(TClonesArray *array)
+{
+  if (!array) return kFALSE;
+
+  if (array->GetClass()->InheritsFrom("AliVParticle")) {
+    const Int_t nentries = array->GetEntriesFast();
+    for (Int_t i = 0; i < nentries; i++) {
+      AliVParticle *part = static_cast<AliVParticle*>(array->At(i));
+      if (!part) continue;
+      if (part->Pt() > fParticleMinPt && part->Pt() < fParticleMaxPt) return kTRUE;
+    }
+  }
+  else if (array->GetClass()->InheritsFrom("AliVCluster")) {
+    const Int_t nentries = array->GetEntriesFast();
+    for (Int_t i = 0; i < nentries; i++) {
+      AliVCluster *clus = static_cast<AliVCluster*>(array->At(i));
+      if (!clus) continue;
+      
+      TLorentzVector vect;
+      Double_t vert[3] = {0,0,0};
+      clus->GetMomentum(vect,vert);
+
+      if (vect.Pt() > fParticleMinPt && vect.Pt() < fParticleMaxPt) return kTRUE;
+    }
+  }
+  else {
+    AliWarning(Form("Unable to do event selection based on particle pT: %s class type not recognized.",array->GetClass()->GetName()));
+  }
+
+  return kFALSE;
+}
+
 //________________________________________________________________________
 void AliJetEmbeddingFromAODTask::Run() 
 {
@@ -469,6 +558,8 @@ void AliJetEmbeddingFromAODTask::Run()
   if (fHistEmbeddingQA)
     fHistEmbeddingQA->Fill("OK", 1);
 
+  fAODFilePath->SetString(fCurrentAODFile->GetName());
+
   if (fOutMCParticles) {
 
     if (fCopyArray && fMCParticles)
@@ -531,7 +622,7 @@ void AliJetEmbeddingFromAODTask::Run()
              else {
                AliDebug(3, "Track not embedded because ITS refit failed.");
                continue;
-           }
+             }
            }
            else {
              type = 1;
@@ -559,6 +650,11 @@ void AliJetEmbeddingFromAODTask::Run()
            else
              type = ptrack->GetLabel();
            isEmc = ptrack->IsEMCAL();
+
+           if (!fIncludeNoITS && type==2) {
+             AliDebug(3, "Track not embedded because ITS refit failed.");
+             continue;
+           }
          }
        }
        
@@ -588,7 +684,7 @@ void AliJetEmbeddingFromAODTask::Run()
            AliDebug(1,Form("%s: Track %d with label==0", GetName(), i));
        }
 
-       AddTrack(track->Pt(), track->Eta(), track->Phi(), type, track->GetTrackEtaOnEMCal(), track->GetTrackPhiOnEMCal(), isEmc, label);
+       AddTrack(track->Pt(), track->Eta(), track->Phi(), type, track->GetTrackEtaOnEMCal(), track->GetTrackPhiOnEMCal(), track->GetTrackPtOnEMCal(), isEmc, label, track->Charge());
        AliDebug(3, "Track embedded!");
       }
     }