CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
JetResolutionDemo Class Reference
Inheritance diagram for JetResolutionDemo:
edm::EDAnalyzer edm::EDConsumerBase

Public Member Functions

 JetResolutionDemo (const edm::ParameterSet &)
 
 ~JetResolutionDemo () override
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
SerialTaskQueueglobalLuminosityBlocksQueue ()
 
SerialTaskQueueglobalRunsQueue ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
 ~EDAnalyzer () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase &&)=default
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

void analyze (const edm::Event &, const edm::EventSetup &) override
 
void endJob () override
 

Private Attributes

edm::Service< TFileServicefs
 
bool m_debug = false
 
edm::EDGetTokenT< std::vector< pat::Jet > > m_jets_token
 
std::string m_payload
 
TH2 * m_res_vs_eta = nullptr
 
std::string m_resolutions_file
 
edm::EDGetTokenT< double > m_rho_token
 
std::string m_scale_factors_file
 
bool m_use_conddb = false
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
static bool wantsGlobalLuminosityBlocks ()
 
static bool wantsGlobalRuns ()
 
static bool wantsStreamLuminosityBlocks ()
 
static bool wantsStreamRuns ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 

Detailed Description

Definition at line 25 of file JetResolutionDemo.cc.

Constructor & Destructor Documentation

◆ JetResolutionDemo()

JetResolutionDemo::JetResolutionDemo ( const edm::ParameterSet iConfig)
explicit

Definition at line 52 of file JetResolutionDemo.cc.

52  {
53  m_jets_token = consumes<std::vector<pat::Jet>>(iConfig.getParameter<edm::InputTag>("jets"));
54  m_rho_token = consumes<double>(iConfig.getParameter<edm::InputTag>("rho"));
55  m_debug = iConfig.getUntrackedParameter<bool>("debug", false);
56  m_use_conddb = iConfig.getUntrackedParameter<bool>("useCondDB", false);
57 
58  if (m_use_conddb)
59  m_payload = iConfig.getParameter<std::string>("payload");
60  else {
61  m_resolutions_file = iConfig.getParameter<edm::FileInPath>("resolutionsFile").fullPath();
62  m_scale_factors_file = iConfig.getParameter<edm::FileInPath>("scaleFactorsFile").fullPath();
63  }
64 }

References contentValuesFiles::fullPath, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), m_debug, m_jets_token, m_payload, m_resolutions_file, m_rho_token, m_scale_factors_file, m_use_conddb, and AlCaHLTBitMon_QueryRunRegistry::string.

◆ ~JetResolutionDemo()

JetResolutionDemo::~JetResolutionDemo ( )
override

Definition at line 66 of file JetResolutionDemo.cc.

66 {}

Member Function Documentation

◆ analyze()

void JetResolutionDemo::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivatevirtual

Implements edm::EDAnalyzer.

Definition at line 69 of file JetResolutionDemo.cc.

69  {
71  iEvent.getByToken(m_jets_token, jets);
72 
74  iEvent.getByToken(m_rho_token, rho);
75 
76  // Access jet resolution and scale factor from the condition database
77  // or from text files
80 
81  // Two differents way to create a class instance
82  if (m_use_conddb) {
83  // First way, using the get() static method
86  } else {
87  // Second way, using the constructor
90  }
91 
92  if (m_debug) {
93  // Dump resolution
94  resolution.dump();
95  }
96 
97  if (!m_res_vs_eta) {
98  // Advanced usage. Create the histogram by retriving the eta binning directly from the JetResolutionObject. This suppose you need that the parametrization only depends on eta.
99 
100  // Get the list of bins of this object
101  const std::vector<JME::Binning>& bins = resolution.getResolutionObject()->getDefinition().getBins();
102 
103  // Check that the first bin is eta
104  if ((bins.size()) && (bins[0] == JME::Binning::JetEta)) {
105  const std::vector<JME::JetResolutionObject::Record> records = resolution.getResolutionObject()->getRecords();
106  // Get all records from the object. Each record correspond to a different binning and different parameters
107 
108  std::vector<float> etas;
109  for (const auto& record : records) {
110  if (etas.empty()) {
111  etas.push_back(record.getBinsRange()[0].min);
112  etas.push_back(record.getBinsRange()[0].max);
113  } else {
114  etas.push_back(record.getBinsRange()[0].max);
115  }
116  }
117 
118  std::vector<float> res;
119  for (std::size_t i = 0; i < 40; i++) {
120  res.push_back(i * 0.005);
121  }
122 
123  m_res_vs_eta = fs->make<TH2F>("res_vs_eta", "res_vs_eta", etas.size() - 1, &etas[0], res.size() - 1, &res[0]);
124  }
125  }
126 
127  for (const auto& jet : *jets) {
128  if (m_debug) {
129  std::cout << "New jet; pt=" << jet.pt() << " eta=" << jet.eta() << " phi=" << jet.phi()
130  << " e=" << jet.energy() << " rho=" << *rho << std::endl;
131  }
132 
133  // Get resolution for this jet
134  // The method to use is getResolution(const JME::JetParameters& parameters) from a JetResolution object
135 
136  // You *must* now in advance which variables are needed for getting the resolution. For the moment, only pt and eta are needed, but this will
137  // probably change in the futur when PU dependency is added. Please keep an eye on the twiki page
138  // https://twiki.cern.ch/twiki/bin/view/CMSPublic/WorkBookJetEnergyResolution
139  // to stay up-to-date. All currently supported parameters (ie, 'set' functions) are available here:
140  // https://twiki.cern.ch/twiki/bin/view/CMSPublic/WorkBookJetEnergyResolution#List_of_supported_parameters
141 
142  // Three way to create a JetParameters object
143 
144  // First, using 'set' functions
145  JME::JetParameters parameters_1;
146  parameters_1.setJetPt(jet.pt());
147  parameters_1.setJetEta(jet.eta());
148  parameters_1.setRho(*rho);
149 
150  // You can also chain calls
151 
152  JME::JetParameters parameters_2;
153  parameters_2.setJetPt(jet.pt()).setJetEta(jet.eta()).setRho(*rho);
154 
155  // Second, using the set() function
156  JME::JetParameters parameters_3;
157  parameters_3.set(JME::Binning::JetPt, jet.pt());
158  parameters_3.set({JME::Binning::JetEta, jet.eta()});
159  parameters_3.set({JME::Binning::Rho, *rho});
160 
161  // Or
162 
163  JME::JetParameters parameters_4;
164  parameters_4.set(JME::Binning::JetPt, jet.pt()).set(JME::Binning::JetEta, jet.eta()).set(JME::Binning::Rho, *rho);
165 
166  // Third, using a initializer_list
167  JME::JetParameters parameters_5 = {
169 
170  // Now, get the resolution
171 
172  float r = resolution.getResolution(parameters_1);
173  if (m_debug) {
174  std::cout << "Resolution with parameters_1: " << r << std::endl;
175  std::cout << "Resolution with parameters_2: " << resolution.getResolution(parameters_2) << std::endl;
176  std::cout << "Resolution with parameters_3: " << resolution.getResolution(parameters_3) << std::endl;
177  std::cout << "Resolution with parameters_4: " << resolution.getResolution(parameters_4) << std::endl;
178  std::cout << "Resolution with parameters_5: " << resolution.getResolution(parameters_5) << std::endl;
179 
180  // You can also use a shortcut to get the resolution
181  float r2 = resolution.getResolution(
183  std::cout << "Resolution using shortcut : " << r2 << std::endl;
184  }
185 
186  m_res_vs_eta->Fill(jet.eta(), r);
187 
188  // We do the same thing to access the scale factors
189  float sf = res_sf.getScaleFactor({{JME::Binning::JetPt, jet.pt()}, {JME::Binning::JetEta, jet.eta()}});
190 
191  // Access up and down variation of the scale factor
192  float sf_up =
194  float sf_down =
196 
197  if (m_debug) {
198  std::cout << "Scale factors (Nominal / Up / Down) : " << sf << " / " << sf_up << " / " << sf_down << std::endl;
199  }
200  }
201 }

References trigObjTnPSource_cfi::bins, gather_cfg::cout, DOWN, EnergyCorrector::etas, fs, JME::JetResolution::get(), JME::JetResolutionScaleFactor::get(), JME::JetResolutionScaleFactor::getScaleFactor(), mps_fire::i, iEvent, metsig::jet, JME::JetEta, JME::JetPt, singleTopDQM_cfi::jets, m_debug, m_jets_token, m_payload, m_res_vs_eta, m_resolutions_file, m_rho_token, m_scale_factors_file, m_use_conddb, TFileService::make(), alignCSCRings::r, diffTwoXMLs::r2, GlobalPosition_Frontier_DevDB_cff::record, L1TObjectsTimingClient_cff::resolution, rho, JME::Rho, JME::JetParameters::set(), JME::JetParameters::setJetEta(), JME::JetParameters::setJetPt(), JME::JetParameters::setRho(), and UP.

◆ endJob()

void JetResolutionDemo::endJob ( void  )
overrideprivatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 203 of file JetResolutionDemo.cc.

203 {}

Member Data Documentation

◆ fs

edm::Service<TFileService> JetResolutionDemo::fs
private

Definition at line 44 of file JetResolutionDemo.cc.

Referenced by analyze().

◆ m_debug

bool JetResolutionDemo::m_debug = false
private

Definition at line 37 of file JetResolutionDemo.cc.

Referenced by analyze(), and JetResolutionDemo().

◆ m_jets_token

edm::EDGetTokenT<std::vector<pat::Jet> > JetResolutionDemo::m_jets_token
private

Definition at line 34 of file JetResolutionDemo.cc.

Referenced by analyze(), and JetResolutionDemo().

◆ m_payload

std::string JetResolutionDemo::m_payload
private

Definition at line 40 of file JetResolutionDemo.cc.

Referenced by analyze(), and JetResolutionDemo().

◆ m_res_vs_eta

TH2* JetResolutionDemo::m_res_vs_eta = nullptr
private

Definition at line 46 of file JetResolutionDemo.cc.

Referenced by analyze().

◆ m_resolutions_file

std::string JetResolutionDemo::m_resolutions_file
private

Definition at line 41 of file JetResolutionDemo.cc.

Referenced by analyze(), and JetResolutionDemo().

◆ m_rho_token

edm::EDGetTokenT<double> JetResolutionDemo::m_rho_token
private

Definition at line 35 of file JetResolutionDemo.cc.

Referenced by analyze(), and JetResolutionDemo().

◆ m_scale_factors_file

std::string JetResolutionDemo::m_scale_factors_file
private

Definition at line 42 of file JetResolutionDemo.cc.

Referenced by analyze(), and JetResolutionDemo().

◆ m_use_conddb

bool JetResolutionDemo::m_use_conddb = false
private

Definition at line 38 of file JetResolutionDemo.cc.

Referenced by analyze(), and JetResolutionDemo().

JME::JetResolution
Definition: JetResolution.h:17
JME::JetParameters::setJetEta
JetParameters & setJetEta(float eta)
Definition: JetResolutionObject.cc:69
JME::JetResolutionScaleFactor::getScaleFactor
float getScaleFactor(const JetParameters &parameters, Variation variation=Variation::NOMINAL, std::string uncertaintySource="") const
Definition: JetResolution.cc:56
mps_fire.i
i
Definition: mps_fire.py:355
JME::Binning::JetEta
contentValuesFiles.fullPath
fullPath
Definition: contentValuesFiles.py:64
gather_cfg.cout
cout
Definition: gather_cfg.py:144
GlobalPosition_Frontier_DevDB_cff.record
record
Definition: GlobalPosition_Frontier_DevDB_cff.py:10
JME::JetParameters
Definition: JetResolutionObject.h:90
Variation::UP
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
singleTopDQM_cfi.jets
jets
Definition: singleTopDQM_cfi.py:42
edm::Handle
Definition: AssociativeIterator.h:50
JME::JetParameters::set
JetParameters & set(const Binning &bin, float value)
Definition: JetResolutionObject.cc:100
edm::FileInPath
Definition: FileInPath.h:64
JetResolutionDemo::m_res_vs_eta
TH2 * m_res_vs_eta
Definition: JetResolutionDemo.cc:46
JME::JetParameters::setJetPt
JetParameters & setJetPt(float pt)
Definition: JetResolutionObject.cc:64
EnergyCorrector.etas
etas
Definition: EnergyCorrector.py:45
L1TObjectsTimingClient_cff.resolution
resolution
Definition: L1TObjectsTimingClient_cff.py:52
JetResolutionDemo::m_payload
std::string m_payload
Definition: JetResolutionDemo.cc:40
JetResolutionDemo::m_rho_token
edm::EDGetTokenT< double > m_rho_token
Definition: JetResolutionDemo.cc:35
DDAxes::rho
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
JME::JetParameters::setRho
JetParameters & setRho(float rho)
Definition: JetResolutionObject.cc:95
diffTwoXMLs.r2
r2
Definition: diffTwoXMLs.py:73
JetResolutionDemo::m_resolutions_file
std::string m_resolutions_file
Definition: JetResolutionDemo.cc:41
iEvent
int iEvent
Definition: GenABIO.cc:224
JetResolutionDemo::m_debug
bool m_debug
Definition: JetResolutionDemo.cc:37
res
Definition: Electron.h:6
JetResolutionDemo::m_use_conddb
bool m_use_conddb
Definition: JetResolutionDemo.cc:38
JME::JetResolutionScaleFactor
Definition: JetResolution.h:40
alignCSCRings.r
r
Definition: alignCSCRings.py:93
JetResolutionDemo::m_jets_token
edm::EDGetTokenT< std::vector< pat::Jet > > m_jets_token
Definition: JetResolutionDemo.cc:34
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
JME::Binning::Rho
JME::JetResolutionScaleFactor::get
static const JetResolutionScaleFactor get(const edm::EventSetup &, const std::string &)
Definition: JetResolution.cc:48
metsig::jet
Definition: SignAlgoResolutions.h:47
Variation::DOWN
JME::Binning::JetPt
JME::JetResolution::get
static const JetResolution get(const edm::EventSetup &, const std::string &)
Definition: JetResolution.cc:23
trigObjTnPSource_cfi.bins
bins
Definition: trigObjTnPSource_cfi.py:20
edm::InputTag
Definition: InputTag.h:15
TFileService::make
T * make(const Args &... args) const
make new ROOT object
Definition: TFileService.h:64
JetResolutionDemo::fs
edm::Service< TFileService > fs
Definition: JetResolutionDemo.cc:44
JetResolutionDemo::m_scale_factors_file
std::string m_scale_factors_file
Definition: JetResolutionDemo.cc:42