test
CMS 3D CMS Logo

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