15 #include <TClonesArray.h>
16 #include <TObjArray.h>
17 #include <TObjString.h>
21 #include <TStreamerInfo.h>
24 #include <TLorentzVector.h>
27 #include "AliVEvent.h"
28 #include "AliAODTrack.h"
29 #include "AliESDtrack.h"
31 #include "AliVTrack.h"
32 #include "AliVCluster.h"
33 #include "AliVCaloCells.h"
34 #include "AliAODMCParticle.h"
35 #include "AliCentrality.h"
36 #include "AliVHeader.h"
37 #include "AliVVertex.h"
38 #include "AliAODHeader.h"
41 #include "AliInputEventHandler.h"
50 fRandomAccess(kFALSE),
57 fAODMCParticlesName(),
60 fTriggerMask(AliVEvent::kAny),
68 fJetConstituentMinPt(0),
72 fJetParticleLevel(kTRUE),
75 fParticleSelection(0),
76 fIncludeNoITS(kFALSE),
77 fCutMaxFractionSharedTPCClusters(0.4),
78 fUseNegativeLabels(kTRUE),
83 fEmbedCentrality(kFALSE),
100 fHistFileMatching(0),
101 fHistAODFileError(0),
104 fHistRejectedEvents(0),
108 SetSuffix(
"AODEmbedding");
109 fAODfilterBits[0] = -1;
110 fAODfilterBits[1] = -1;
123 fRandomAccess(kFALSE),
124 fAODTreeName(
"aodTree"),
125 fAODHeaderName(
"header"),
126 fAODVertexName(
"vertices"),
127 fAODTrackName(
"tracks"),
129 fAODCellsName(
"emcalCells"),
130 fAODMCParticlesName(AliAODMCParticle::StdBranchName()),
133 fTriggerMask(AliVEvent::kAny),
141 fJetConstituentMinPt(0),
145 fJetParticleLevel(kTRUE),
148 fParticleSelection(0),
149 fIncludeNoITS(kFALSE),
150 fCutMaxFractionSharedTPCClusters(0.4),
151 fUseNegativeLabels(kTRUE),
156 fEmbedCentrality(kFALSE),
157 fEsdTreeMode(kFALSE),
159 fCurrentAODFileID(0),
161 fPicoTrackVersion(0),
169 fCurrentAODEntry(-1),
173 fHistFileMatching(0),
174 fHistAODFileError(0),
177 fHistRejectedEvents(0),
227 fHistEmbeddingQA =
new TH1F(
"fHistEmbeddingQA",
"fHistEmbeddingQA", 2, 0, 2);
234 fHistRejectedEvents =
new TH1F(
"fHistRejectedEvents",
"fHistRejectedEvents", 500, -0.5, 499.5);
245 TString path(fInputHandler->GetTree()->GetCurrentFile()->GetPath());
246 if (path.EndsWith(
"/"))
247 path.Remove(path.Length()-1);
248 path.Remove(path.Last(
'/'));
249 path.Remove(0, path.Last(
'/')+1);
251 AliWarning(Form(
"Could not extract file number from path %s", path.Data()));
273 AliDebug(3,
"Adding AOD embedding file path object to the event list...");
301 AliError(
"Could not open AOD file to embed!");
307 TStreamerInfo *cinfo =
static_cast<TStreamerInfo*
>(clist->FindObject(
"AliPicoTrack"));
366 if (fCurrentAODFileID >=
fFileList->GetEntriesFast()) {
367 AliError(
"No more file in the list!");
371 TObjString *objFileName =
static_cast<TObjString*
>(
fFileList->At(fCurrentAODFileID));
374 if (
fileName.BeginsWith(
"alien://") && !gGrid) {
375 AliInfo(
"Trying to connect to AliEn ...");
376 TGrid::Connect(
"alien://");
380 if (baseFileName.Contains(
".zip#")) {
381 Ssiz_t pos = baseFileName.Last(
'#');
382 baseFileName.Remove(pos);
385 if (
gSystem->AccessPathName(baseFileName)) {
386 AliError(Form(
"File %s does not exist!", baseFileName.Data()));
390 AliDebug(3,Form(
"Trying to open file %s...",
fileName.Data()));
393 if (!file || file->IsZombie()) {
394 AliError(Form(
"Unable to open file: %s!",
fileName.Data()));
414 AliError(
"Could not open the next file!");
420 AliError(
"Could not get the tree!");
428 if (attempts == 1000)
429 AliWarning(
"After 1000 attempts no event has been accepted by the event selection (trigger, centrality...)!");
440 AliAODHeader *aodHeader =
static_cast<AliAODHeader*
>(
fAODHeader);
441 AliAODHeader *evHeader =
static_cast<AliAODHeader*
>(InputEvent()->GetHeader());
443 AliCentrality *cent = aodHeader->GetCentralityP();
444 evHeader->SetCentrality(cent);
459 AliAODHeader *aodHeader =
static_cast<AliAODHeader*
>(
fAODHeader);
463 UInt_t offlineTrigger = aodHeader->GetOfflineTrigger();
465 AliDebug(2,Form(
"Event rejected due to physics selection. Event trigger mask: %d, trigger mask selection: %d.",
466 offlineTrigger, fTriggerMask));
473 AliCentrality *cent = aodHeader->GetCentralityP();
474 Float_t centVal = cent->GetCentralityPercentile(
"V0M");
476 AliDebug(2,Form(
"Event rejected due to centrality selection. Event centrality: %f, centrality range selection: %f to %f",
486 ((AliVVertex*)
fAODVertex->At(0))->GetXYZ(vert);
488 AliDebug(2,Form(
"Event rejected due to Z vertex selection. Event Z vertex: %f, Z vertex cut: %f",
494 AliDebug(2,Form(
"Event rejected because the distance between the current and embedded verteces is > %f. "
495 "Current event vertex (%f, %f, %f), embedded event vertex (%f, %f, %f). Distance = %f",
516 AliWarning(
"Particle level jets selected, but not MC particles found. The jet event selection will be skipped.");
524 AliWarning(
"Detector level jets selected, but not tracks or clusters found. The jet event selection will be skipped.");
529 AliDebug(1, Form(
"Leading jet pt = %f", jet.Pt()));
540 if (!array)
return kFALSE;
542 if (array->GetClass()->InheritsFrom(
"AliVParticle")) {
543 const Int_t nentries = array->GetEntriesFast();
544 for (
Int_t i = 0; i < nentries; i++) {
545 AliVParticle *part =
static_cast<AliVParticle*
>(array->At(i));
550 else if (array->GetClass()->InheritsFrom(
"AliVCluster")) {
551 const Int_t nentries = array->GetEntriesFast();
552 for (
Int_t i = 0; i < nentries; i++) {
553 AliVCluster *clus =
static_cast<AliVCluster*
>(array->At(i));
558 clus->GetMomentum(vect,vert);
564 AliWarning(Form(
"Unable to do event selection based on particle pT: %s class type not recognized.",array->GetClass()->GetName()));
578 AliError(
"Unable to get the AOD event to embed. Nothing will be embedded.");
595 AliDebug(3, Form(
"%d MC particles will be processed for embedding.",
fAODMCParticles->GetEntriesFast()));
597 AliAODMCParticle *part =
static_cast<AliAODMCParticle*
>(
fAODMCParticles->At(i));
603 AliDebug(4, Form(
"Processing MC particle %d with pT = %f, eta = %f, phi = %f", i, part->Pt(), part->Eta(), part->Phi()));
605 if (!part->IsPhysicalPrimary())
614 AliDebug(3,
"Embedded!");
624 AliDebug(3, Form(
"Start embedding with %d tracks.",
fOutTracks->GetEntriesFast()));
627 AliDebug(3, Form(
"%d tracks will be processed for embedding.",
fAODTracks->GetEntriesFast()));
629 AliVTrack *track =
static_cast<AliVTrack*
>(
fAODTracks->At(i));
635 AliDebug(4, Form(
"Processing track %d with pT = %f, eta = %f, phi = %f, label = %d", i, track->Pt(), track->Eta(), track->Phi(), track->GetLabel()));
640 AliAODTrack *aodtrack =
static_cast<AliAODTrack*
>(track);
645 if ((aodtrack->GetStatus()&AliESDtrack::kITSrefit)==0) {
649 AliDebug(3,
"Track not embedded because ITS refit failed.");
658 AliDebug(3,
"Track not embedded because not an hybrid track.");
666 if (TMath::Abs(aodtrack->GetTrackEtaOnEMCal()) < 0.75 &&
667 aodtrack->GetTrackPhiOnEMCal() > 70 * TMath::DegToRad() &&
668 aodtrack->GetTrackPhiOnEMCal() < 190 * TMath::DegToRad())
681 AliDebug(3,
"Track not embedded because ITS refit failed.");
690 AliDebug(3,
"Track not embedded because out of limits.");
697 AliDebug(3,
"Track not embedded because of artificial inefficiency.");
705 label = track->GetLabel();
707 label = TMath::Abs(track->GetLabel());
710 AliDebug(1,Form(
"%s: Track %d with label==0", GetName(), i));
713 AddTrack(track->Pt(), track->Eta(), track->Phi(), type, track->GetTrackEtaOnEMCal(), track->GetTrackPhiOnEMCal(), track->GetTrackPtOnEMCal(), isEmc, label, track->Charge());
714 AliDebug(3,
"Track embedded!");
726 AliVCluster *clus =
static_cast<AliVCluster*
>(
fAODClusters->At(i));
732 if (!clus->IsEMCAL())
737 clus->GetMomentum(vect,vert);
746 label = clus->GetLabel();
748 AliDebug(1,Form(
"%s: Clus %d with label<=0", GetName(), i));
758 Int_t totalCells = 0;
778 fAODCaloCells->GetCell(i, cellNum, amp, time, mclabel, efrac);
782 AliDebug(1,Form(
"%s: Cell %d with label<=0", GetName(), i));
788 AliDebug(2,Form(
"Adding cell with amplitude %f, absolute ID %d, time %f, mc label %d", amp, cellNum, time, mclabel));
789 AddCell(amp, cellNum, time, mclabel);
793 AliDebug(2,Form(
"Added cells = %d (energy = %f), total cells = %d",
fAddedCells, totalEnergy, totalCells));
801 fastjet::JetAlgorithm jalgo(fastjet::kt_algorithm);
804 jalgo = fastjet::antikt_algorithm;
809 fjw.
SetAreaType(fastjet::active_area_explicit_ghosts);
817 const Int_t Ntracks = tracks->GetEntries();
818 for (
Int_t iTracks = 0; iTracks < Ntracks; ++iTracks) {
819 AliVParticle *t =
static_cast<AliVParticle*
>(tracks->At(iTracks));
823 AliAODMCParticle *aodmcpart =
dynamic_cast<AliAODMCParticle*
>(t);
824 if (aodmcpart && !aodmcpart->IsPhysicalPrimary())
827 if ((
fJetType == 1 && t->Charge() == 0) ||
828 (
fJetType == 2 && t->Charge() != 0))
834 fjw.
AddInputVector(t->Px(), t->Py(), t->Pz(), t->P(), iTracks + 100);
841 ((AliVVertex*)
fAODVertex->At(0))->GetXYZ(vert);
843 const Int_t Nclus = clusters->GetEntries();
844 for (
Int_t iClus = 0; iClus < Nclus; ++iClus) {
845 AliVCluster *
c =
static_cast<AliVCluster*
>(clusters->At(iClus));
853 c->GetMomentum(nP, vert);
858 fjw.
AddInputVector(nP.Px(), nP.Py(), nP.Pz(), nP.P(), -iClus - 100);
866 AliDebug(1,Form(
"%d jets found", (
Int_t)jets_incl.size()));
870 Int_t njets = jets_incl.size();
874 for (
Int_t i = 0; i < njets; i++) {
875 if (jet.Pt() >= jets_incl[i].perp())
879 jet.SetPxPyPzE(jets_incl[i].px(), jets_incl[i].py(), jets_incl[i].pz(), jets_incl[i].E());
Bool_t FindParticleInRange(TClonesArray *array)
TClonesArray * fClusters
! cluster collection
Float_t fPtMin
pt minimum value
virtual Bool_t OpenNextFile()
virtual Bool_t IsAODEventSelected()
Int_t fEmbeddingCount
Rejected events.
TH1 * fHistAODFileError
Current file ID vs. AOD file ID (to be embedded)
TList * fOutput
! output list for QA histograms
TClonesArray * fOutClusters
! output cluster collection
TClonesArray * fAODMCParticles
AOD cell collection.
Base class for embedding into an event.
TH1 * fHistEmbeddingQA
File ID not embedded.
void SetMaxRap(Double_t maxrap)
void UserCreateOutputObjects()
TH2 * fHistFileMatching
Current AOD file path being embedded.
Bool_t ExecOnce()
generate a particle with random eta,phi, and correlated pt,mass values
AliVCaloCells * fCaloCells
! cells collection
Float_t fEtaMax
eta maximum value
TString fAODMCParticlesName
Bool_t fUseNegativeLabels
virtual TFile * GetNextFile()
virtual ~AliJetEmbeddingFromAODTask()
TClonesArray * fOutTracks
! output track collection
TClonesArray * fOutMCParticles
! output MC particles collection
const std::vector< fastjet::PseudoJet > & GetInclusiveJets() const
AliVHeader * fAODHeader
Current open tree.
Float_t fPhiMin
phi minimum value
Bool_t fEsdMode
! ESD/AOD mode
Int_t fFirstAODEntry
Current entry in the AOD tree.
void SetAlgorithm(const fastjet::JetAlgorithm &algor)
virtual Bool_t GetNextEntry()
AliAODMCParticle * AddMCParticle(AliAODMCParticle *part, Int_t origIndex)
add a track; if values are -1 generate random parameters
AliVCaloCells * fOutCaloCells
! output cells collection
Bool_t fQAhistos
draw QA histograms
TClonesArray * fAODVertex
AOD header.
Int_t fCurrentAODEntry
AOD MC particles collection.
Byte_t GetTrackType() const
virtual void Clear(const Option_t *="")
Bool_t fCopyArray
whether or not the array will be copied to a new one before modelling
Int_t SetNumberOfOutCells(Int_t n)
TH1 * fHistNotEmbedded
AOD file ID (to be embedded) error.
TClonesArray * fMCParticles
! MC particles collection
Int_t AddCell(Double_t e=-1, Double_t eta=-999, Double_t phi=-1)
set the number of cells
Double_t fCutMaxFractionSharedTPCClusters
TFile * fCurrentAODFile
Current file ID.
void SetGhostArea(Double_t gharea)
AliNamedString * fAODFilePath
Last entry in the AOD tree.
ClassImp(AliJetEmbeddingFromAODTask) AliJetEmbeddingFromAODTask
Byte_t fParticleSelection
Int_t fAddedCells
! number of added cells
AliVCluster * AddCluster(Double_t e=-1, Double_t eta=-999, Double_t phi=-1, Int_t label=0)
add a cell with given energy, position and times
AliVCaloCells * fAODCaloCells
AOD cluster collection.
Float_t fEtaMin
eta minimum value
Int_t fLastAODEntry
First entry in the AOD tree.
Int_t fPicoTrackVersion
Current open file.
Int_t fCurrentAODFileID
Current file being processed (via the event handler)
TClonesArray * fAODTracks
AOD vertex.
void UserCreateOutputObjects()
virtual void AddInputVector(Double_t px, Double_t py, Double_t pz, Double_t E, Int_t index=-99999)
void SetSuffix(const char *s)
Double_t fVertex[3]
! event vertex
AliJetEmbeddingFromAODTask()
AliPicoTrack * AddTrack(Double_t pt=-999, Double_t eta=-999, Double_t phi=-999, Byte_t type=0, Double_t etaemc=0, Double_t phiemc=0, Double_t ptemc=0, Bool_t ise=kFALSE, Int_t label=0, Short_t charge=1, Double_t mass=0.1396)
add a cluster (copy)
TTree * fCurrentAODTree
Version of the PicoTrack class (if any) in fCurrentAODFile.
void SetAreaType(const fastjet::AreaType &atype)
Float_t fPhiMax
phi maximum value
Double_t fJetConstituentMinPt
TClonesArray * fTracks
! track collection
TClonesArray * fAODClusters
AOD track collection.
virtual Bool_t ExecOnce()
generate a particle with random eta,phi, and correlated pt,mass values
Int_t fCurrentFileID
True = embed from ESD (must be a skimmed ESD!)
TLorentzVector GetLeadingJet(TClonesArray *tracks, TClonesArray *clusters=0)
Class for embedding a AOD event into a data event.
TH1 * fHistRejectedEvents
Embedding QA.
Float_t fPtMax
pt maximum value