CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PatJetAnalyzer.cc
Go to the documentation of this file.
1 #include <map>
2 #include <string>
3 #include <iomanip>
4 #include <sstream>
5 #include <iostream>
6 
7 #include "TH1.h"
8 
15 
18 
19 
22 static const unsigned int MAXBIN=8;
26 static const float BINS[]={30., 40., 50., 60., 70., 80., 100., 125., 150.};
27 
44 
45 public:
47  explicit PatJetAnalyzer(const edm::ParameterSet& cfg);
50 
51 private:
53  virtual void analyze(const edm::Event& event, const edm::EventSetup& setup);
54 
56  bool booked(const std::string histName) const { return hists_.find(histName.c_str())!=hists_.end(); };
58  void fill(const std::string histName, double value) const { if(booked(histName.c_str())) hists_.find(histName.c_str())->second->Fill(value); };
59  // print jet pt for each level of energy corrections
60  void print(edm::View<pat::Jet>::const_iterator& jet, unsigned int idx);
61 
62 private:
64  std::string corrLevel_;
68  std::map<std::string,TH1F*> hists_;
69 };
70 
71 
73  corrLevel_(cfg.getParameter<std::string>("corrLevel")),
74  jets_(cfg.getParameter<edm::InputTag>("src"))
75 {
76  // register TFileService
78 
79  // jet multiplicity
80  hists_["mult" ]=fs->make<TH1F>("mult" , "N_{Jet}" , 15, 0., 15.);
81  // jet pt (for all jets)
82  hists_["pt" ]=fs->make<TH1F>("pt" , "p_{T}(Jet) [GeV]" , 60, 0., 300.);
83  // jet eta (for all jets)
84  hists_["eta" ]=fs->make<TH1F>("eta" , "#eta (Jet)" , 60, -3., 3.);
85  // jet phi (for all jets)
86  hists_["phi" ]=fs->make<TH1F>("phi" , "#phi (Jet)" , 60, 3.2, 3.2);
87  // dijet mass (if available)
88  hists_["mass" ]=fs->make<TH1F>("mass" , "M_{jj} [GeV]" , 50, 0., 500.);
89  // basic histograms for jet energy response
90  for(unsigned int idx=0; idx<MAXBIN; ++idx){
91  char buffer [10]; sprintf (buffer, "jes_%i", idx);
92  char title [50]; sprintf (title , "p_{T}^{rec}/p_{T}^{gen} [%i GeV - %i GeV]", (int)BINS[idx], (int)BINS[idx+1]);
93  hists_[buffer]=fs->make<TH1F>(buffer, title, 100, 0., 2.);
94  }
95 }
96 
97 void
99 {
100  // recieve jet collection label
102  event.getByLabel(jets_,jets);
103 
104  // loop jets
105  for(edm::View<pat::Jet>::const_iterator jet=jets->begin(); jet!=jets->end(); ++jet){
106  // print jec factors
107  // print(jet, jet-jets->begin());
108 
109  // fill basic kinematics
110  fill( "pt" , jet->correctedJet(corrLevel_).pt());
111  fill( "eta", jet->eta());
112  fill( "phi", jet->phi());
113  // basic plots for jet responds plot as a function of pt
114  if( jet->genJet() ){
115  double resp=jet->correctedJet(corrLevel_).pt()/jet->genJet()->pt();
116  for(unsigned int idx=0; idx<MAXBIN; ++idx){
117  if(BINS[idx]<=jet->genJet()->pt() && jet->genJet()->pt()<BINS[idx+1]){
118  char buffer [10]; sprintf (buffer, "jes_%i", idx);
119  fill( buffer, resp );
120  }
121  }
122  }
123  }
124  // jet multiplicity
125  fill( "mult" , jets->size());
126  // invariant dijet mass for first two leading jets
127  if(jets->size()>1){ fill( "mass", ((*jets)[0].p4()+(*jets)[1].p4()).mass());}
128 }
129 
130 void
132 {
133  //edm::LogInfo log("JEC");
134  std::cout << "[" << idx << "] :: eta=" << std::setw(10) << jet->eta() << " phi=" << std::setw(10) << jet->phi() << " size: " << jet->availableJECLevels().size() << std::endl;
135  for(unsigned int idx=0; idx<jet->availableJECLevels().size(); ++idx){
136  pat::Jet correctedJet;
137  if(jet->availableJECLevels()[idx].find("L5Flavor")!=std::string::npos||
138  jet->availableJECLevels()[idx].find("L7Parton")!=std::string::npos ){
139  correctedJet=jet->correctedJet(idx, pat::JetCorrFactors::UDS);
140  }
141  else{
142  correctedJet=jet->correctedJet(idx, pat::JetCorrFactors::NONE );
143  }
144  std::cout << std::setw(10) << correctedJet.currentJECLevel() << " pt=" << std::setw(10) << correctedJet.pt() << std::endl;
145  }
146 }
147 
std::string corrLevel_
correction level for pat jet
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
PatJetAnalyzer(const edm::ParameterSet &cfg)
default contructor
void fill(const std::string histName, double value) const
fill histogram if it had been booked before
U second(std::pair< T, U > const &p)
std::map< std::string, TH1F * > hists_
management of 1d histograms
double p4[4]
Definition: TauolaWrapper.h:92
static const float BINS[]
virtual void analyze(const edm::Event &event, const edm::EventSetup &setup)
everything that needs to be done during the even loop
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
virtual double pt() const
transverse momentum
std::string currentJECLevel() const
return the name of the current step of jet energy corrections
Definition: Jet.h:118
size_type size() const
Analysis-level calorimeter jet class.
Definition: Jet.h:67
Module to analyze pat::Jets in the context of a more complex exercise.
bool booked(const std::string histName) const
check if histogram was booked
static const unsigned int MAXBIN
~PatJetAnalyzer()
default destructor
T * make() const
make new ROOT object
tuple cout
Definition: gather_cfg.py:41
edm::InputTag jets_
pat jets
void print(edm::View< pat::Jet >::const_iterator &jet, unsigned int idx)