CMS 3D CMS Logo

RivetAnalysis.h
Go to the documentation of this file.
1 #ifndef GeneratorInterface_RivetInterface_RivetAnalysis_H
2 #define GeneratorInterface_RivetInterface_RivetAnalysis_H
3 
5 
6 #include "Rivet/Analysis.hh"
7 #include "Rivet/Projections/FinalState.hh"
8 #include "Rivet/Particle.hh"
9 #include "Rivet/Particle.fhh"
10 #include "Rivet/Event.hh"
11 #include "Rivet/Projections/FastJets.hh"
12 #include "Rivet/Projections/JetAlg.hh"
13 #include "Rivet/Projections/ChargedLeptons.hh"
14 #include "Rivet/Projections/PromptFinalState.hh"
15 #include "Rivet/Projections/DressedLeptons.hh"
16 #include "Rivet/Projections/VetoedFinalState.hh"
17 #include "Rivet/Projections/IdentifiedFinalState.hh"
18 #include "Rivet/Projections/MissingMomentum.hh"
19 #include "Rivet/Tools/RivetHepMC.hh"
20 
21 namespace Rivet {
22 
23  class RivetAnalysis : public Analysis {
24  public:
25  Particles leptons() const { return _leptons; }
26  Particles photons() const { return _photons; }
27  Particles neutrinos() const { return _neutrinos; }
28  Jets jets() const { return _jets; }
29  Jets fatjets() const { return _fatjets; }
30  Vector3 met() const { return _met; }
31 
32  private:
37 
42 
44 
47  Vector3 _met;
48 
49  public:
51  : Analysis("RivetAnalysis"),
52  _usePromptFinalStates(pset.getParameter<bool>("usePromptFinalStates")),
53  _excludePromptLeptonsFromJetClustering(pset.getParameter<bool>("excludePromptLeptonsFromJetClustering")),
54  _excludeNeutrinosFromJetClustering(pset.getParameter<bool>("excludeNeutrinosFromJetClustering")),
55  _doJetClustering(pset.getParameter<bool>("doJetClustering")),
56 
57  _particleMinPt(pset.getParameter<double>("particleMinPt")),
58  _particleMaxEta(pset.getParameter<double>("particleMaxEta")),
59 
60  _lepConeSize(pset.getParameter<double>("lepConeSize")),
61  _lepMinPt(pset.getParameter<double>("lepMinPt")),
62  _lepMaxEta(pset.getParameter<double>("lepMaxEta")),
63 
64  _jetConeSize(pset.getParameter<double>("jetConeSize")),
65  _jetMinPt(pset.getParameter<double>("jetMinPt")),
66  _jetMaxEta(pset.getParameter<double>("jetMaxEta")),
67 
68  _fatJetConeSize(pset.getParameter<double>("fatJetConeSize")),
69  _fatJetMinPt(pset.getParameter<double>("fatJetMinPt")),
70  _fatJetMaxEta(pset.getParameter<double>("fatJetMaxEta")),
71 
72  _phoMinPt(pset.getParameter<double>("phoMinPt")),
73  _phoMaxEta(pset.getParameter<double>("phoMaxEta")),
74  _phoIsoConeSize(pset.getParameter<double>("phoIsoConeSize")),
75  _phoMaxRelIso(pset.getParameter<double>("phoMaxRelIso")) {}
76 
77  // Initialize Rivet projections
78  void init() override {
79  // Cuts
80  Cut particle_cut = (Cuts::abseta < _particleMaxEta) and (Cuts::pT > _particleMinPt * GeV);
81  Cut lepton_cut = (Cuts::abseta < _lepMaxEta) and (Cuts::pT > _lepMinPt * GeV);
82 
83  // Generic final state
84  FinalState fs(particle_cut);
85 
86  declare(fs, "FS");
87 
88  // Dressed leptons
89  ChargedLeptons charged_leptons(fs);
90  IdentifiedFinalState photons(fs);
91  photons.acceptIdPair(PID::PHOTON);
92 
93  PromptFinalState prompt_leptons(charged_leptons);
94  prompt_leptons.acceptMuonDecays(true);
95  prompt_leptons.acceptTauDecays(true);
96  declare(prompt_leptons, "PromptLeptons");
97 
98  PromptFinalState prompt_photons(photons);
99  prompt_photons.acceptMuonDecays(true);
100  prompt_photons.acceptTauDecays(true);
101 
102  // useDecayPhotons=true allows for photons with tau ancestor,
103  // photons from hadrons are vetoed by the PromptFinalState;
104  // will be default DressedLeptons behaviour for Rivet >= 2.5.4
105  DressedLeptons dressed_leptons(
106  prompt_photons, prompt_leptons, _lepConeSize, lepton_cut, /*useDecayPhotons*/ true);
107  if (not _usePromptFinalStates)
108  dressed_leptons = DressedLeptons(photons, charged_leptons, _lepConeSize, lepton_cut, /*useDecayPhotons*/ true);
109  declare(dressed_leptons, "DressedLeptons");
110 
111  declare(photons, "Photons");
112 
113  // Jets
114  VetoedFinalState fsForJets(fs);
116  fsForJets.addVetoOnThisFinalState(dressed_leptons);
117  JetAlg::Invisibles invisiblesStrategy = JetAlg::Invisibles::DECAY;
119  invisiblesStrategy = JetAlg::Invisibles::NONE;
120  declare(FastJets(fsForJets, FastJets::ANTIKT, _jetConeSize, JetAlg::Muons::ALL, invisiblesStrategy), "Jets");
121 
122  // FatJets
123  declare(FastJets(fsForJets, FastJets::ANTIKT, _fatJetConeSize), "FatJets");
124 
125  // Neutrinos
126  IdentifiedFinalState neutrinos(fs);
127  neutrinos.acceptNeutrinos();
128  if (_usePromptFinalStates) {
129  PromptFinalState prompt_neutrinos(neutrinos);
130  prompt_neutrinos.acceptMuonDecays(true);
131  prompt_neutrinos.acceptTauDecays(true);
132  declare(prompt_neutrinos, "Neutrinos");
133  } else
134  declare(neutrinos, "Neutrinos");
135 
136  // MET
137  declare(MissingMomentum(fs), "MET");
138  };
139 
140  // Apply Rivet projections
141  void analyze(const Event& event) override {
142  _jets.clear();
143  _fatjets.clear();
144  _leptons.clear();
145  _photons.clear();
146  _neutrinos.clear();
147 
148  // Get analysis objects from projections
149  Cut jet_cut = (Cuts::abseta < _jetMaxEta) and (Cuts::pT > _jetMinPt * GeV);
150  Cut fatjet_cut = (Cuts::abseta < _fatJetMaxEta) and (Cuts::pT > _fatJetMinPt * GeV);
151 
152  _leptons = apply<DressedLeptons>(event, "DressedLeptons").particlesByPt();
153 
154  // search tau ancestors
155  Particles promptleptons = apply<PromptFinalState>(event, "PromptLeptons").particles();
156  for (auto& lepton : _leptons) {
157  const auto& cl = lepton.constituents().front(); // this has no ancestors anymore :(
158  for (auto const& pl : promptleptons) {
159  if (cl.momentum() == pl.momentum()) {
160  for (auto& p : pl.ancestors()) {
161  if (p.abspid() == 15) {
162  p.setMomentum(p.momentum() * 10e-20);
163  lepton.addConstituent(p, false);
164  }
165  }
166  break;
167  }
168  }
169  }
170 
171  // Photons
172  Particles fsparticles = apply<FinalState>(event, "FS").particles();
173 
174  for (auto& photon : apply<FinalState>(event, "Photons").particlesByPt()) {
175  if (photon.pt() < _phoMinPt)
176  continue;
177 
178  if (abs(photon.eta()) > _phoMaxEta)
179  continue;
180 
181  double photonptsum = 0;
182 
183  for (auto& fsparticle : fsparticles) {
184  if (deltaR(fsparticle, photon) == 0)
185  continue;
186 
187  if (deltaR(fsparticle, photon) > _phoIsoConeSize)
188  continue;
189 
190  photonptsum += fsparticle.pt();
191  }
192 
193  if (photonptsum / photon.pt() > _phoMaxRelIso)
194  continue;
195 
196  _photons.push_back(photon);
197  }
198 
199  if (_doJetClustering) {
200  _jets = apply<FastJets>(event, "Jets").jetsByPt(jet_cut);
201  _fatjets = apply<FastJets>(event, "FatJets").jetsByPt(fatjet_cut);
202  }
203  _neutrinos = apply<FinalState>(event, "Neutrinos").particlesByPt();
204  _met = apply<MissingMomentum>(event, "MET").missingMomentum().p3();
205 
206  // check for leptonic decays of tag particles
207  for (auto& jet : _jets) {
208  for (auto& pt : jet.tags()) {
209  for (auto& p : pt.children(isLepton)) {
210  pt.addConstituent(p, false);
211  }
212  }
213  }
214  for (auto& jet : _fatjets) {
215  for (auto& pt : jet.tags()) {
216  for (auto& p : pt.children(isLepton)) {
217  pt.addConstituent(p, false);
218  }
219  }
220  }
221  };
222 
223  // Do nothing here
224  void finalize() override{};
225 
226  std::string status() const override { return "VALIDATED"; }
227  };
228 
229 } // namespace Rivet
230 
231 #endif
pat::PHOTON
4:
Definition: ParticleCode.h:22
muons2muons_cfi.photon
photon
Definition: muons2muons_cfi.py:28
electrons_cff.bool
bool
Definition: electrons_cff.py:366
Rivet::RivetAnalysis::_phoMaxEta
double _phoMaxEta
Definition: RivetAnalysis.h:43
Rivet::RivetAnalysis::_lepMaxEta
double _lepMaxEta
Definition: RivetAnalysis.h:39
Rivet::RivetAnalysis::_fatJetConeSize
double _fatJetConeSize
Definition: RivetAnalysis.h:41
Rivet::RivetAnalysis
Definition: RivetAnalysis.h:23
Rivet::RivetAnalysis::_usePromptFinalStates
bool _usePromptFinalStates
Definition: RivetAnalysis.h:33
Rivet::RivetAnalysis::_fatJetMinPt
double _fatJetMinPt
Definition: RivetAnalysis.h:41
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
Rivet::RivetAnalysis::_neutrinos
Particles _neutrinos
Definition: RivetAnalysis.h:45
Rivet
Definition: RivetAnalysis.h:21
Rivet::RivetAnalysis::leptons
Particles leptons() const
Definition: RivetAnalysis.h:25
Rivet::RivetAnalysis::_excludePromptLeptonsFromJetClustering
bool _excludePromptLeptonsFromJetClustering
Definition: RivetAnalysis.h:34
Rivet::RivetAnalysis::_lepMinPt
double _lepMinPt
Definition: RivetAnalysis.h:39
Rivet::RivetAnalysis::_phoIsoConeSize
double _phoIsoConeSize
Definition: RivetAnalysis.h:43
Rivet::RivetAnalysis::_jetMaxEta
double _jetMaxEta
Definition: RivetAnalysis.h:40
Rivet::RivetAnalysis::_jetConeSize
double _jetConeSize
Definition: RivetAnalysis.h:40
Rivet::RivetAnalysis::_phoMaxRelIso
double _phoMaxRelIso
Definition: RivetAnalysis.h:43
reco::isLepton
bool isLepton(const Candidate &part)
Definition: pdgIdUtils.h:13
Rivet::RivetAnalysis::photons
Particles photons() const
Definition: RivetAnalysis.h:26
GetRecoTauVFromDQM_MC_cff.cl
cl
Definition: GetRecoTauVFromDQM_MC_cff.py:38
Rivet::RivetAnalysis::fatjets
Jets fatjets() const
Definition: RivetAnalysis.h:29
Rivet::RivetAnalysis::_excludeNeutrinosFromJetClustering
bool _excludeNeutrinosFromJetClustering
Definition: RivetAnalysis.h:35
Rivet::RivetAnalysis::init
void init() override
Definition: RivetAnalysis.h:78
Rivet::RivetAnalysis::_particleMaxEta
double _particleMaxEta
Definition: RivetAnalysis.h:38
PVValHelper::pT
Definition: PVValidationHelpers.h:71
Event
PbPb_ZMuSkimMuonDPG_cff.deltaR
deltaR
Definition: PbPb_ZMuSkimMuonDPG_cff.py:63
Rivet::RivetAnalysis::_fatjets
Jets _fatjets
Definition: RivetAnalysis.h:46
Rivet::RivetAnalysis::neutrinos
Particles neutrinos() const
Definition: RivetAnalysis.h:27
Rivet::RivetAnalysis::jets
Jets jets() const
Definition: RivetAnalysis.h:28
edm::ParameterSet
Definition: ParameterSet.h:47
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
GeV
const double GeV
Definition: MathUtil.h:16
diffTwoXMLs.ALL
def ALL(dt, wheel, station, sector)
Definition: diffTwoXMLs.py:28
Rivet::RivetAnalysis::status
std::string status() const override
Definition: RivetAnalysis.h:226
Rivet::RivetAnalysis::RivetAnalysis
RivetAnalysis(const edm::ParameterSet &pset)
Definition: RivetAnalysis.h:50
Rivet::RivetAnalysis::finalize
void finalize() override
Definition: RivetAnalysis.h:224
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
METSkim_cff.Jets
Jets
Definition: METSkim_cff.py:17
Rivet::RivetAnalysis::_photons
Particles _photons
Definition: RivetAnalysis.h:45
Rivet::RivetAnalysis::_lepConeSize
double _lepConeSize
Definition: RivetAnalysis.h:39
Rivet::RivetAnalysis::_met
Vector3 _met
Definition: RivetAnalysis.h:47
metsig::jet
Definition: SignAlgoResolutions.h:47
Rivet::RivetAnalysis::_phoMinPt
double _phoMinPt
Definition: RivetAnalysis.h:43
Rivet::RivetAnalysis::_fatJetMaxEta
double _fatJetMaxEta
Definition: RivetAnalysis.h:41
Rivet::RivetAnalysis::analyze
void analyze(const Event &event) override
Definition: RivetAnalysis.h:141
NONE
Definition: TkAlStyle.cc:47
Rivet::RivetAnalysis::_leptons
Particles _leptons
Definition: RivetAnalysis.h:45
Rivet::RivetAnalysis::_doJetClustering
bool _doJetClustering
Definition: RivetAnalysis.h:36
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterSet.h
Rivet::RivetAnalysis::met
Vector3 met() const
Definition: RivetAnalysis.h:30
event
Definition: event.py:1
Rivet::RivetAnalysis::_jets
Jets _jets
Definition: RivetAnalysis.h:46
Rivet::RivetAnalysis::_jetMinPt
double _jetMinPt
Definition: RivetAnalysis.h:40
Rivet::RivetAnalysis::_particleMinPt
double _particleMinPt
Definition: RivetAnalysis.h:38
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37