-// $Id$
//
// Emcal jet finder task.
//
-// Authors: C.Loizides, S.Aiola
+// Authors: C.Loizides, S.Aiola, M. Verweij
#include <vector>
#include "AliEmcalJetTask.h"
#include <TList.h>
#include <TLorentzVector.h>
#include <TMath.h>
+#include <TRandom3.h>
#include "AliAnalysisManager.h"
#include "AliCentrality.h"
#include "AliVCluster.h"
#include "AliVEvent.h"
#include "AliVParticle.h"
+#include "AliRhoParameter.h"
+using std::cout;
+using std::endl;
+using std::cerr;
ClassImp(AliEmcalJetTask)
fTracksName("Tracks"),
fCaloName("CaloClusters"),
fJetsName("Jets"),
+ fJetsSubName(""),
fJetType(kNone),
- fConstSel(kAllJets),
- fMCConstSel(kAllJets),
+ fConstSel(0),
+ fMCConstSel(0),
fMarkConst(kFALSE),
fRadius(0.4),
fMinJetTrackPt(0.15),
fMinJetClusPt(0.15),
fPhiMin(0),
fPhiMax(TMath::TwoPi()),
- fEtaMin(-1),
- fEtaMax(1),
- fMinJetArea(0.01),
+ fEtaMin(-0.9),
+ fEtaMax(+0.9),
+ fMinJetArea(0.005),
fMinJetPt(1.0),
- fGhostArea(0.01),
+ fJetPhiMin(-10),
+ fJetPhiMax(+10),
+ fJetEtaMin(-1),
+ fJetEtaMax(+1),
+ fGhostArea(0.005),
+ fMinMCLabel(0),
+ fRecombScheme(fastjet::pt_scheme),
+ fTrackEfficiency(1.),
+ fMCFlag(0),
+ fGeneratorIndex(-1),
fIsInit(0),
+ fLocked(0),
fIsPSelSet(0),
fIsMcPart(0),
fIsEmcPart(0),
+ fLegacyMode(kFALSE),
+ fCodeDebug(kFALSE),
+ fDoGenericSubtraction(kFALSE),
+ fDoConstituentSubtraction(kFALSE),
+ fUseExternalBkg(kFALSE),
+ fRhoName(""),
+ fRhomName(""),
+ fRho(0),
+ fRhom(0),
fJets(0),
+ fJetsSub(0),
fEvent(0),
fTracks(0),
- fClus(0)
+ fClus(0),
+ fRhoParam(0),
+ fRhomParam(0)
{
// Default constructor.
}
fTracksName("Tracks"),
fCaloName("CaloClusters"),
fJetsName("Jets"),
+ fJetsSubName(""),
fJetType(kAKT|kFullJet|kRX1Jet),
- fConstSel(kAllJets),
- fMCConstSel(kAllJets),
+ fConstSel(0),
+ fMCConstSel(0),
fMarkConst(kFALSE),
fRadius(0.4),
fMinJetTrackPt(0.15),
fMinJetClusPt(0.15),
fPhiMin(0),
fPhiMax(TMath::TwoPi()),
- fEtaMin(-1),
- fEtaMax(1),
- fMinJetArea(0.01),
+ fEtaMin(-0.9),
+ fEtaMax(+0.9),
+ fMinJetArea(0.001),
fMinJetPt(1.0),
- fGhostArea(0.01),
+ fJetPhiMin(-10),
+ fJetPhiMax(+10),
+ fJetEtaMin(-1),
+ fJetEtaMax(+1),
+ fGhostArea(0.005),
+ fMinMCLabel(0),
+ fRecombScheme(fastjet::pt_scheme),
+ fTrackEfficiency(1.),
+ fMCFlag(0),
+ fGeneratorIndex(-1),
fIsInit(0),
+ fLocked(0),
fIsPSelSet(0),
fIsMcPart(0),
fIsEmcPart(0),
+ fLegacyMode(kFALSE),
+ fCodeDebug(kFALSE),
+ fDoGenericSubtraction(kFALSE),
+ fDoConstituentSubtraction(kFALSE),
+ fUseExternalBkg(kFALSE),
+ fRhoName(""),
+ fRhomName(""),
+ fRho(0),
+ fRhom(0),
fJets(0),
+ fJetsSub(0),
fEvent(0),
fTracks(0),
- fClus(0)
+ fClus(0),
+ fRhoParam(0),
+ fRhomParam(0)
{
// Standard constructor.
fJets = new TClonesArray("AliEmcalJet");
fJets->SetName(fJetsName);
+
+ if(!fJetsSubName.IsNull()) {
+ fJetsSub = new TClonesArray("AliEmcalJet");
+ fJetsSub->SetName(fJetsSubName);
+ }
}
//________________________________________________________________________
void AliEmcalJetTask::UserExec(Option_t *)
{
// Main loop, called for each event.
-
if (!fIsInit) {
if (!DoInit())
return;
fIsInit = kTRUE;
}
+ // clear the jet array (normally a null operation)
+ fJets->Delete();
+ if(fJetsSub) fJetsSub->Delete();
+
FindJets();
}
void AliEmcalJetTask::FindJets()
{
// Find jets.
-
- if (!fTracks && !fClus)
+ if (!fTracks && !fClus){
+ cout << "WARNING NO TRACKS OR CLUSTERS:" <<endl;
return;
+ }
+
+ if (fRhoParam)
+ fRho = fRhoParam->GetVal();
+ if (fRhomParam)
+ fRhom = fRhomParam->GetVal();
TString name("kt");
fastjet::JetAlgorithm jalgo(fastjet::kt_algorithm);
fjw.SetAreaType(fastjet::active_area_explicit_ghosts);
fjw.SetGhostArea(fGhostArea);
fjw.SetR(fRadius);
- fjw.SetAlgorithm(jalgo);
- fjw.SetMaxRap(1);
+ fjw.SetAlgorithm(jalgo);
+ fjw.SetRecombScheme(static_cast<fastjet::RecombinationScheme>(fRecombScheme));
+ fjw.SetMaxRap(fEtaMax);
fjw.Clear();
// get primary vertex
Double_t vertex[3] = {0, 0, 0};
- fEvent->GetPrimaryVertex()->GetXYZ(vertex);
+ if(fEvent->GetPrimaryVertex()) fEvent->GetPrimaryVertex()->GetXYZ(vertex);
AliDebug(2,Form("Jet type = %d", fJetType));
if (!t)
continue;
if (fIsMcPart) {
- if (((fJetType & kChargedJet) != 0) && (t->Charge() == 0))
+ if (((fJetType & kChargedJet) != 0) && (t->Charge() == 0)) {
+ AliDebug(2,Form("Skipping track %d because it is neutral.", iTracks));
continue;
- if (((fJetType & kNeutralJet) != 0) && (t->Charge() != 0))
+ }
+ if (((fJetType & kNeutralJet) != 0) && (t->Charge() != 0)) {
+ AliDebug(2,Form("Skipping track %d because it is charged.", iTracks));
continue;
+ }
}
- if (fIsMcPart || t->GetLabel() != 0) {
- if (fMCConstSel == kNone) {
- AliDebug(2,Form("Skipping track %d because bit mask is 0.", iTracks));
+ if (fIsMcPart || TMath::Abs(t->GetLabel()) > fMinMCLabel) {
+ if (t->TestBits(fMCConstSel) != (Int_t)fMCConstSel) {
+ AliDebug(2,Form("Skipping track %d because it does not match the bit mask (%d, %d)", iTracks, fMCConstSel, t->TestBits(TObject::kBitMask)));
continue;
}
- if (fMCConstSel != kAllJets) {
- if (t->TestBits(fMCConstSel) != (Int_t)fMCConstSel) {
- AliDebug(2,Form("Skipping track %d because it does not match the bit mask (%d, %d)", iTracks, fMCConstSel, t->TestBits(TObject::kBitMask)));
- continue;
- }
- else {
- AliDebug(2,Form("Track %d matches the bit mask (%d, %d)", iTracks, fMCConstSel, t->TestBits(TObject::kBitMask)));
- }
+ else {
+ AliDebug(2,Form("Track %d matches the bit mask (%d, %d)", iTracks, fMCConstSel, t->TestBits(TObject::kBitMask)));
}
}
else {
- if (fConstSel == kNone) {
- AliDebug(2,Form("Skipping track %d because bit mask is 0.", iTracks));
+ if (t->TestBits(fConstSel) != (Int_t)fConstSel) {
+ AliDebug(2,Form("Skipping track %d because it does not match the bit mask (%d, %d)", iTracks, fConstSel, t->TestBits(TObject::kBitMask)));
continue;
}
- if (fConstSel != kAllJets) {
- if (t->TestBits(fConstSel) != (Int_t)fConstSel) {
- AliDebug(2,Form("Skipping track %d because it does not match the bit mask (%d, %d)", iTracks, fConstSel, t->TestBits(TObject::kBitMask)));
- continue;
- }
- else {
- AliDebug(2,Form("Track %d matches the bit mask (%d, %d)", iTracks, fConstSel, t->TestBits(TObject::kBitMask)));
- }
+ else {
+ AliDebug(2,Form("Track %d matches the bit mask (%d, %d)", iTracks, fConstSel, t->TestBits(TObject::kBitMask)));
}
- }
+ }
+ if ((t->GetFlag() & fMCFlag) != fMCFlag) {
+ AliDebug(2,Form("Skipping track %d because it does not match the MC flags", iTracks));
+ continue;
+ }
+ if (fGeneratorIndex >= 0 && t->GetGeneratorIndex() != fGeneratorIndex) {
+ AliDebug(2,Form("Skipping track %d because it does not match the MC generator index", iTracks));
+ continue;
+ }
if (t->Pt() < fMinJetTrackPt)
continue;
Double_t eta = t->Eta();
(phi<fPhiMin) || (phi>fPhiMax))
continue;
+ // artificial inefficiency
+ if (fTrackEfficiency < 1.) {
+ Double_t rnd = gRandom->Rndm();
+ if (fTrackEfficiency < rnd) {
+ AliDebug(2,Form("Track %d rejected due to artificial tracking inefficiency", iTracks));
+ continue;
+ }
+ }
+
// offset of 100 for consistency with cluster ids
AliDebug(2,Form("Track %d accepted (label = %d, pt = %f)", iTracks, t->GetLabel(), t->Pt()));
- fjw.AddInputVector(t->Px(), t->Py(), t->Pz(), t->P(), iTracks + 100);
+ fjw.AddInputVector(t->Px(), t->Py(), t->Pz(), t->E(), iTracks + 100);
}
}
if (!c)
continue;
- if (c->GetLabel() > 0) {
- if (fMCConstSel == kNone) {
- AliDebug(2,Form("Skipping cluster %d because bit mask is 0.", iClus));
+ if (c->GetLabel() > fMinMCLabel) {
+ if (ep->TestBits(fMCConstSel) != (Int_t)fMCConstSel) {
+ AliDebug(2,Form("Skipping cluster %d because it does not match the bit mask (%d, %d)", iClus, fMCConstSel, ep->TestBits(TObject::kBitMask)));
continue;
}
- if (fMCConstSel != kAllJets) {
- if (ep->TestBits(fMCConstSel) != (Int_t)fMCConstSel) {
- AliDebug(2,Form("Skipping cluster %d because it does not match the bit mask (%d, %d)", iClus, fMCConstSel, ep->TestBits(TObject::kBitMask)));
- continue;
- }
- else {
- AliDebug(2,Form("Cluster %d matches the bit mask (%d, %d)", iClus, fMCConstSel, ep->TestBits(TObject::kBitMask)));
- }
+ else {
+ AliDebug(2,Form("Cluster %d matches the bit mask (%d, %d)", iClus, fMCConstSel, ep->TestBits(TObject::kBitMask)));
}
}
else {
- if (fConstSel == kNone) {
- AliDebug(2,Form("Skipping cluster %d because bit mask is 0.", iClus));
+ if (ep->TestBits(fConstSel) != (Int_t)fConstSel) {
+ AliDebug(2,Form("Skipping cluster %d because it does not match the bit mask (%d, %d)", iClus, fConstSel, ep->TestBits(TObject::kBitMask)));
continue;
}
- if (fConstSel != kAllJets) {
- if (ep->TestBits(fConstSel) != (Int_t)fConstSel) {
- AliDebug(2,Form("Skipping cluster %d because it does not match the bit mask (%d, %d)", iClus, fConstSel, ep->TestBits(TObject::kBitMask)));
- continue;
- }
- else {
- AliDebug(2,Form("Cluster %d matches the bit mask (%d, %d)", iClus, fConstSel, ep->TestBits(TObject::kBitMask)));
- }
+ else {
+ AliDebug(2,Form("Cluster %d matches the bit mask (%d, %d)", iClus, fConstSel, ep->TestBits(TObject::kBitMask)));
}
}
if (!c)
continue;
- if (c->GetLabel() > 0) {
- if (fMCConstSel == kNone) {
- AliDebug(2,Form("Skipping cluster %d because bit mask is 0.", iClus));
+ if (c->GetLabel() > fMinMCLabel) {
+ if (c->TestBits(fMCConstSel) != (Int_t)fMCConstSel) {
+ AliDebug(2,Form("Skipping cluster %d because it does not match the bit mask (%d, %d)", iClus, fMCConstSel, c->TestBits(TObject::kBitMask)));
continue;
}
- if (fMCConstSel != kAllJets) {
- if (c->TestBits(fMCConstSel) != (Int_t)fMCConstSel) {
- AliDebug(2,Form("Skipping cluster %d because it does not match the bit mask (%d, %d)", iClus, fMCConstSel, c->TestBits(TObject::kBitMask)));
- continue;
- }
- else {
- AliDebug(2,Form("Cluster %d matches the bit mask (%d, %d)", iClus, fMCConstSel, c->TestBits(TObject::kBitMask)));
- }
+ else {
+ AliDebug(2,Form("Cluster %d matches the bit mask (%d, %d)", iClus, fMCConstSel, c->TestBits(TObject::kBitMask)));
}
}
else {
- if (fConstSel == kNone) {
- AliDebug(2,Form("Skipping cluster %d because bit mask is 0.", iClus));
+ if (c->TestBits(fConstSel) != (Int_t)fConstSel) {
+ AliDebug(2,Form("Skipping cluster %d because it does not match the bit mask (%d, %d)", iClus, fConstSel, c->TestBits(TObject::kBitMask)));
continue;
}
- if (fConstSel != kAllJets) {
- if (c->TestBits(fConstSel) != (Int_t)fConstSel) {
- AliDebug(2,Form("Skipping cluster %d because it does not match the bit mask (%d, %d)", iClus, fConstSel, c->TestBits(TObject::kBitMask)));
- continue;
- }
- else {
- AliDebug(2,Form("Cluster %d matches the bit mask (%d, %d)", iClus, fConstSel, c->TestBits(TObject::kBitMask)));
- }
+ else {
+ AliDebug(2,Form("Cluster %d matches the bit mask (%d, %d)", iClus, fConstSel, c->TestBits(TObject::kBitMask)));
}
}
fjw.AddInputVector(cPx, cPy, cPz, TMath::Sqrt(cPx*cPx+cPy*cPy+cPz*cPz), -iClus - 100);
}
}
-
+
+ // setting legacy mode
+ if (fLegacyMode) {
+ fjw.SetLegacyMode(kTRUE);
+ }
+
// run jet finder
fjw.Run();
+ //run generic subtractor
+ if(fDoGenericSubtraction) {
+ fjw.SetUseExternalBkg(fUseExternalBkg,fRho,fRhom);
+ fjw.DoGenericSubtractionJetMass();
+ }
+
+ //run constituent subtractor
+ if(fDoConstituentSubtraction) {
+ fjw.SetUseExternalBkg(fUseExternalBkg,fRho,fRhom);
+ fjw.DoConstituentSubtraction();
+ }
+
// get geometry
AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance();
if (!geom) {
continue;
if (fjw.GetJetArea(ij)<fMinJetArea)
continue;
+ if ((jets_incl[ij].eta()<fJetEtaMin) || (jets_incl[ij].eta()>fJetEtaMax) ||
+ (jets_incl[ij].phi()<fJetPhiMin) || (jets_incl[ij].phi()>fJetPhiMax))
+ continue;
AliEmcalJet *jet = new ((*fJets)[jetCount])
AliEmcalJet(jets_incl[ij].perp(), jets_incl[ij].eta(), jets_incl[ij].phi(), jets_incl[ij].m());
+ jet->SetLabel(ij);
+
+ //do generic subtraction if requested
+ if(fDoGenericSubtraction) {
+#ifdef FASTJET_CONTRIB
+ std::vector<fastjet::contrib::GenericSubtractorInfo> jetMassInfo = fjw.GetGenSubtractorInfoJetMass();
+ UInt_t n = (UInt_t)jetMassInfo.size();
+ if(n>ij && n>0) {
+ jet->SetFirstDerivative(jetMassInfo[ij].first_derivative());
+ jet->SetSecondDerivative(jetMassInfo[ij].second_derivative());
+ jet->SetFirstOrderSubtracted(jetMassInfo[ij].first_order_subtracted());
+ jet->SetSecondOrderSubtracted(jetMassInfo[ij].second_order_subtracted());
+ }
+#endif
+ }
// loop over constituents
std::vector<fastjet::PseudoJet> constituents(fjw.GetJetConstituents(ij));
for(UInt_t ic = 0; ic < constituents.size(); ++ic) {
Int_t uid = constituents[ic].user_index();
- AliDebug(2,Form("Processing constituent %d", uid));
+ AliDebug(3,Form("Processing constituent %d", uid));
if ((uid == -1) /*&& (constituents[ic].kt2() < 1e-25)*/) { //ghost particle
++gall;
Double_t gphi = constituents[ic].phi();
if (cPt > maxCh)
maxCh = cPt;
}
- if (fIsMcPart || t->GetLabel() != 0) // check if MC particle
+ if (fIsMcPart || TMath::Abs(t->GetLabel()) > fMinMCLabel) // check if MC particle
mcpt += cPt;
if (cPhi<0)
if (cPt > maxNe)
maxNe = cPt;
- if (c->GetLabel() > 0) // MC particle
- mcpt += cPt;
+ if (c->GetLabel() > fMinMCLabel) // MC particle
+ mcpt += c->GetMCEnergyFraction() > 1e-6 ? cPt * c->GetMCEnergyFraction() : cPt;
if (cPhi<0)
cPhi += TMath::TwoPi();
jetCount++;
}
//fJets->Sort();
+
+ //run constituent subtractor if requested
+ if(fDoConstituentSubtraction) {
+#ifdef FASTJET_CONTRIB
+ if(!fJetsSub) AliWarning(Form("No jet branch to write to for subtracted jets. fJetsSubName: %s",fJetsSubName.Data()));
+ else {
+ std::vector<fastjet::PseudoJet> jets_sub;
+ jets_sub = fjw.GetConstituentSubtrJets();
+ AliDebug(1,Form("%d constituent subtracted jets found", (Int_t)jets_sub.size()));
+ for (UInt_t ijet=0, jetCount=0; ijet<jets_sub.size(); ++ijet) {
+ //Only storing 4-vector and jet area of unsubtracted jet
+ AliEmcalJet *jet_sub = new ((*fJetsSub)[jetCount])
+ AliEmcalJet(jets_sub[ijet].perp(), jets_sub[ijet].eta(), jets_sub[ijet].phi(), jets_sub[ijet].m());
+ jet_sub->SetLabel(ijet);
+ fastjet::PseudoJet area(fjw.GetJetAreaVector(ijet));
+ jet_sub->SetArea(area.perp());
+ jet_sub->SetAreaEta(area.eta());
+ jet_sub->SetAreaPhi(area.phi());
+ jet_sub->SetAreaEmc(area.perp());
+ jetCount++;
+ }
+ }
+#endif
+ } //constituent subtraction
}
//________________________________________________________________________
{
// Init. Return true if successful.
+ if (fTrackEfficiency < 1.) {
+ if (gRandom) delete gRandom;
+ gRandom = new TRandom3(0);
+ }
+
// get input collections
AliAnalysisManager *am = AliAnalysisManager::GetAnalysisManager();
}
// add jets to event if not yet there
- fJets->Delete();
if (!(fEvent->FindListObject(fJetsName)))
fEvent->AddObject(fJets);
else {
return 0;
}
+ if (!(fEvent->FindListObject(fJetsSubName)) && fJetsSub)
+ fEvent->AddObject(fJetsSub);
+
if (fTracksName == "Tracks")
am->LoadBranch("Tracks");
if (!fTracks && !fTracksName.IsNull()) {
}
if (fTracks) {
TClass cls(fTracks->GetClass()->GetName());
- if (cls.InheritsFrom("AliMCParticle"))
+ if (cls.InheritsFrom("AliMCParticle") || cls.InheritsFrom("AliAODMCParticle"))
fIsMcPart = 1;
}
fIsEmcPart = 1;
}
+ if (!fRhoName.IsNull() && !fRhoParam) { // get rho from the event
+ fRhoParam = dynamic_cast<AliRhoParameter*>(InputEvent()->FindListObject(fRhoName));
+ if (!fRhoParam) {
+ AliError(Form("%s: Could not retrieve rho %s!", GetName(), fRhoName.Data()));
+ return 0;
+ }
+ }
+ if (!fRhomName.IsNull() && !fRhomParam) { // get rhom from the event
+ fRhomParam = dynamic_cast<AliRhoParameter*>(InputEvent()->FindListObject(fRhomName));
+ if (!fRhomParam) {
+ AliError(Form("%s: Could not retrieve rho %s!", GetName(), fRhomName.Data()));
+ return 0;
+ }
+ }
+
return 1;
}