CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CMSDAS11DijetAnalyzer.cc
Go to the documentation of this file.
1 // CMSDAS11DijetAnalyzer.cc
2 // Description: A basic dijet analyzer for the CMSDAS 2011
3 // Author: John Paul Chou
4 // Date: January 12, 2011
5 
7 
12 
17 
18 #include <TH1D.h>
19 
21  : jetSrc(params.getParameter<edm::InputTag>("jetSrc")),
22  vertexSrc(params.getParameter<edm::InputTag>("vertexSrc")),
23  jetCorrections(params.getParameter<std::string>("jetCorrections")),
24  innerDeltaEta(params.getParameter<double>("innerDeltaEta")),
25  outerDeltaEta(params.getParameter<double>("outerDeltaEta")),
26  JESbias(params.getParameter<double>("JESbias")) {
27  // setup file service
28  usesResource(TFileService::kSharedResource);
30 
31  const int NBINS = 36;
32  Double_t BOUNDARIES[NBINS] = {220, 244, 270, 296, 325, 354, 386, 419, 453, 489, 526, 565,
33  606, 649, 693, 740, 788, 838, 890, 944, 1000, 1058, 1118, 1181,
34  1246, 1313, 1383, 1455, 1530, 1607, 1687, 1770, 1856, 1945, 2037, 2132};
35 
36  // setup histograms
37  hVertexZ = fs->make<TH1D>("hVertexZ", "Z position of the Vertex", 50, -20, 20);
38  hJetRawPt = fs->make<TH1D>("hJetRawPt", "Raw Jet Pt", 50, 0, 1000);
39  hJetCorrPt = fs->make<TH1D>("hJetCorrPt", "Corrected Jet Pt", 50, 0, 1000);
40  hJet1Pt = fs->make<TH1D>("hJet1Pt", "Corrected Jet1 Pt", 50, 0, 1000);
41  hJet2Pt = fs->make<TH1D>("hJet2Pt", "Corrected Jet2 Pt", 50, 0, 1000);
42 
43  hJetEta = fs->make<TH1D>("hJetEta", "Corrected Jet Eta", 10, -5, 5);
44  hJet1Eta = fs->make<TH1D>("hJet1Eta", "Corrected Jet1 Eta", 10, -5, 5);
45  hJet2Eta = fs->make<TH1D>("hJet2Eta", "Corrected Jet2 Eta", 10, -5, 5);
46 
47  hJetPhi = fs->make<TH1D>("hJetPhi", "Corrected Jet Phi", 10, -3.1415, 3.1415);
48  hJet1Phi = fs->make<TH1D>("hJet1Phi", "Corrected Jet1 Phi", 10, -3.1415, 3.1415);
49  hJet2Phi = fs->make<TH1D>("hJet2Phi", "Corrected Jet2 Phi", 10, -3.1415, 3.1415);
50 
51  hJetEMF = fs->make<TH1D>("hJetEMF", "EM Fraction of Jets", 50, 0, 1);
52  hJet1EMF = fs->make<TH1D>("hJet1EMF", "EM Fraction of Jet1", 50, 0, 1);
53  hJet2EMF = fs->make<TH1D>("hJet2EMF", "EM Fraction of Jet2", 50, 0, 1);
54 
55  hCorDijetMass = fs->make<TH1D>("hCorDijetMass", "Corrected Dijet Mass", NBINS - 1, BOUNDARIES);
56  hDijetDeltaPhi = fs->make<TH1D>("hDijetDeltaPhi", "Dijet |#Delta #phi|", 50, 0, 3.1415);
57  hDijetDeltaEta = fs->make<TH1D>("hDijetDeltaEta", "Dijet |#Delta #eta|", 50, 0, 6);
58 
59  hInnerDijetMass = fs->make<TH1D>("hInnerDijetMass", "Corrected Inner Dijet Mass", NBINS - 1, BOUNDARIES);
60  hOuterDijetMass = fs->make<TH1D>("hOuterDijetMass", "Corrected Outer Dijet Mass", NBINS - 1, BOUNDARIES);
61 }
62 
64 
67  double mWeight;
69  iEvent.getByLabel("generator", hEventInfo);
70  if (hEventInfo.isValid())
71  mWeight = hEventInfo->weight();
72  else
73  mWeight = 1.;
74 
76  // Get event ID information
78  //int nrun=iEvent.id().run();
79  //int nlumi=iEvent.luminosityBlock();
80  //int nevent=iEvent.id().event();
81 
83  // Get Primary Vertex Information
85 
86  // magic to get the vertices from EDM
88  iEvent.getByLabel(vertexSrc, vertices_h);
89  if (!vertices_h.isValid()) {
90  std::cout << "Didja hear the one about the empty vertex collection?\n";
91  return;
92  }
93 
94  // require in the event that there is at least one reconstructed vertex
95  if (vertices_h->empty())
96  return;
97 
98  // pick the first (i.e. highest sum pt) verte
99  const reco::Vertex* theVertex = &(vertices_h->front());
100 
101  // require that the vertex meets certain criteria
102  if (theVertex->ndof() < 5)
103  return;
104  if (fabs(theVertex->z()) > 24.0)
105  return;
106  if (fabs(theVertex->position().rho()) > 2.0)
107  return;
108 
110  // Get Jet Information
112 
113  // magic to get the jets from EDM
115  iEvent.getByLabel(jetSrc, jets_h);
116  if (!jets_h.isValid()) {
117  std::cout << "Didja hear the one about the empty jet collection?\n";
118  return;
119  }
120 
121  // magic to get the jet energy corrections
123 
124  // collection of selected jets
125  std::vector<reco::CaloJet> selectedJets;
126 
127  // loop over the jet collection
128  for (reco::CaloJetCollection::const_iterator j_it = jets_h->begin(); j_it != jets_h->end(); j_it++) {
129  reco::CaloJet jet = *j_it;
130 
131  // calculate and apply the correction
132  double scale = corrector->correction(jet.p4());
133 
134  // Introduce a purposeful bias to the correction, to show what happens
135  scale *= JESbias;
136 
137  // fill the histograms
138  hJetRawPt->Fill(jet.pt(), mWeight);
139  hJetEta->Fill(jet.eta(), mWeight);
140  hJetPhi->Fill(jet.phi(), mWeight);
141  hJetEMF->Fill(jet.emEnergyFraction(), mWeight);
142 
143  // correct the jet energy
144  jet.scaleEnergy(scale);
145 
146  // now fill the correct jet pt after the correction
147  hJetCorrPt->Fill(jet.pt(), mWeight);
148 
149  // put the selected jets into a collection
150  selectedJets.push_back(jet);
151  }
152 
153  // require at least two jets to continue
154  if (selectedJets.size() < 2)
155  return;
156 
157  //sort by corrected pt (not the same order as raw pt, sometimes)
158  sort(selectedJets.begin(), selectedJets.end(), compare_JetPt);
159 
160  // select high pt, central, non-noise-like jets
161  if (selectedJets[0].pt() < 50.0)
162  return;
163  if (fabs(selectedJets[0].eta()) > 2.5)
164  return;
165  if (selectedJets[0].emEnergyFraction() < 0.01)
166  return;
167  if (selectedJets[1].pt() < 50.0)
168  return;
169  if (fabs(selectedJets[1].eta()) > 2.5)
170  return;
171  if (selectedJets[1].emEnergyFraction() < 0.01)
172  return;
173 
174  // fill histograms for the jets in our dijets, only
175  hJet1Pt->Fill(selectedJets[0].pt(), mWeight);
176  hJet1Eta->Fill(selectedJets[0].eta(), mWeight);
177  hJet1Phi->Fill(selectedJets[0].phi(), mWeight);
178  hJet1EMF->Fill(selectedJets[0].emEnergyFraction(), mWeight);
179  hJet2Pt->Fill(selectedJets[1].pt(), mWeight);
180  hJet2Eta->Fill(selectedJets[1].eta(), mWeight);
181  hJet2Phi->Fill(selectedJets[1].phi(), mWeight);
182  hJet2EMF->Fill(selectedJets[1].emEnergyFraction(), mWeight);
183 
184  //Get the mass of the two leading jets. Needs their 4-vectors...
185  double corMass = (selectedJets[0].p4() + selectedJets[1].p4()).M();
186  double deltaEta = fabs(selectedJets[0].eta() - selectedJets[1].eta());
187  if (corMass < 489)
188  return;
189  if (deltaEta > 1.3)
190  return;
191  hCorDijetMass->Fill(corMass, mWeight);
192  hDijetDeltaPhi->Fill(fabs(selectedJets[0].phi() - selectedJets[1].phi()), mWeight);
193  hDijetDeltaEta->Fill(deltaEta, mWeight);
194 
195  //Fill the inner and outer dijet mass spectra, to make the ratio from
196  if (deltaEta < innerDeltaEta)
197  hInnerDijetMass->Fill(corMass, mWeight);
198  else if (deltaEta < outerDeltaEta)
199  hOuterDijetMass->Fill(corMass, mWeight);
200 
201  hVertexZ->Fill(theVertex->z(), mWeight);
202  return;
203 }
204 
static const std::string kSharedResource
Definition: TFileService.h:76
Jets made from CaloTowers.
Definition: CaloJet.h:27
virtual void scaleEnergy(double fScale)
scale energy of the jet
double pt() const final
transverse momentum
void endJob(void) override
static bool compare_JetPt(const reco::CaloJet &jet1, const reco::CaloJet &jet2)
virtual double correction(const LorentzVector &fJet) const =0
get correction using Jet information only
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
const Point & position() const
position
Definition: Vertex.h:127
void analyze(const edm::Event &, const edm::EventSetup &) override
CMSDAS11DijetAnalyzer(const edm::ParameterSet &)
const LorentzVector & p4() const final
four-momentum Lorentz vector
static const double deltaEta
Definition: CaloConstants.h:8
int iEvent
Definition: GenABIO.cc:224
double z() const
z coordinate
Definition: Vertex.h:133
bool isValid() const
Definition: HandleBase.h:70
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:500
double ndof() const
Definition: Vertex.h:123
static const JetCorrector * getJetCorrector(const std::string &fName, const edm::EventSetup &fSetup)
retrieve corrector from the event setup. troughs exception if something is missing ...
Definition: JetCorrector.cc:48
tuple cout
Definition: gather_cfg.py:144
double phi() const final
momentum azimuthal angle
const int NBINS
float emEnergyFraction() const
Definition: CaloJet.h:97
double eta() const final
momentum pseudorapidity