CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
L1ECALPrefiringWeightProducer Class Reference

#include <ProdTutorial/L1ECALPrefiringWeightProducer/plugins/L1ECALPrefiringWeightProducer.cc>

Inheritance diagram for L1ECALPrefiringWeightProducer:
edm::global::EDProducer<> edm::global::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 L1ECALPrefiringWeightProducer (const edm::ParameterSet &)
 
 ~L1ECALPrefiringWeightProducer () override
 
- Public Member Functions inherited from edm::global::EDProducer<>
 EDProducer ()=default
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsStreamLuminosityBlocks () const final
 
bool wantsStreamRuns () const final
 
- Public Member Functions inherited from edm::global::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducerBase () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
 ~ProducerBase () noexcept(false) 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 const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
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
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
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)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
- Static Public Member Functions inherited from edm::global::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Private Member Functions

double getPrefiringRate (double eta, double pt, TH2F *h_prefmap, fluctuations fluctuation) const
 
void produce (edm::StreamID, edm::Event &, const edm::EventSetup &) const override
 

Private Attributes

std::string dataera_
 
TH2F * h_prefmap_jet
 
TH2F * h_prefmap_photon
 
edm::EDGetTokenT< std::vector< pat::Jet > > jets_token_
 
edm::EDGetTokenT< std::vector< pat::Photon > > photons_token_
 
double prefiringRateSystUnc_
 
bool skipwarnings_
 
bool useEMpt_
 

Additional Inherited Members

- Public Types inherited from edm::global::EDProducerBase
typedef EDProducerBase ModuleType
 
- Public Types inherited from edm::ProducerBase
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex >>
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Protected Member Functions inherited from edm::ProducerBase
ProducesCollector producesCollector ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, 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)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Description: [one line class summary]

Implementation: [Notes on implementation]

Definition at line 38 of file L1ECALPrefiringWeightProducer.cc.

Constructor & Destructor Documentation

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

Definition at line 61 of file L1ECALPrefiringWeightProducer.cc.

References gather_cfg::cout, dataera_, alignmentValidation::fname, edm::ParameterSet::getParameter(), h_prefmap_jet, h_prefmap_photon, jets_token_, photons_token_, prefiringRateSystUnc_, skipwarnings_, AlCaHLTBitMon_QueryRunRegistry::string, and useEMpt_.

61  {
62  photons_token_ = consumes<std::vector<pat::Photon> >(iConfig.getParameter<edm::InputTag>("ThePhotons"));
63  jets_token_ = consumes<std::vector<pat::Jet> >(iConfig.getParameter<edm::InputTag>("TheJets"));
64 
65  dataera_ = iConfig.getParameter<std::string>("DataEra");
66  useEMpt_ = iConfig.getParameter<bool>("UseJetEMPt");
67  prefiringRateSystUnc_ = iConfig.getParameter<double>("PrefiringRateSystematicUncty");
68  skipwarnings_ = iConfig.getParameter<bool>("SkipWarnings");
69 
70  TFile* file_prefiringmaps_;
71  std::string fname = iConfig.getParameter<std::string>("L1Maps");
72  edm::FileInPath mapsfilepath("PhysicsTools/PatUtils/data/" + fname);
73  file_prefiringmaps_ = new TFile(mapsfilepath.fullPath().c_str(), "read");
74  if (file_prefiringmaps_ == nullptr && !skipwarnings_)
75  std::cout << "File with maps not found. All prefiring weights set to 0. " << std::endl;
76 
77  TString mapphotonfullname = "L1prefiring_photonptvseta_" + dataera_;
78  if (!file_prefiringmaps_->Get(mapphotonfullname) && !skipwarnings_)
79  std::cout << "Photon map not found. All photons prefiring weights set to 0. " << std::endl;
80  h_prefmap_photon = (TH2F*)file_prefiringmaps_->Get(mapphotonfullname);
81 
82  TString mapjetfullname = (useEMpt_) ? "L1prefiring_jetemptvseta_" + dataera_ : "L1prefiring_jetptvseta_" + dataera_;
83  if (!file_prefiringmaps_->Get(mapjetfullname) && !skipwarnings_)
84  std::cout << "Jet map not found. All jets prefiring weights set to 0. " << std::endl;
85  h_prefmap_jet = (TH2F*)file_prefiringmaps_->Get(mapjetfullname);
86  file_prefiringmaps_->Close();
87  delete file_prefiringmaps_;
88  produces<double>("nonPrefiringProb").setBranchAlias("nonPrefiringProb");
89  produces<double>("nonPrefiringProbUp").setBranchAlias("nonPrefiringProbUp");
90  produces<double>("nonPrefiringProbDown").setBranchAlias("nonPrefiringProbDown");
91 }
T getParameter(std::string const &) const
edm::EDGetTokenT< std::vector< pat::Photon > > photons_token_
edm::EDGetTokenT< std::vector< pat::Jet > > jets_token_
string fname
main script
L1ECALPrefiringWeightProducer::~L1ECALPrefiringWeightProducer ( )
override

Member Function Documentation

void L1ECALPrefiringWeightProducer::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 213 of file L1ECALPrefiringWeightProducer.cc.

References edm::ConfigurationDescriptions::add(), edm::ParameterSetDescription::add(), DEFINE_FWK_MODULE, HLT_2018_cff::InputTag, and AlCaHLTBitMon_QueryRunRegistry::string.

213  {
215 
216  desc.add<edm::InputTag>("ThePhotons", edm::InputTag("slimmedPhotons"));
217  desc.add<edm::InputTag>("TheJets", edm::InputTag("slimmedJets"));
218  desc.add<std::string>("L1Maps", "L1PrefiringMaps.root");
219  desc.add<std::string>("DataEra", "2017BtoF");
220  desc.add<bool>("UseJetEMPt", false);
221  desc.add<double>("PrefiringRateSystematicUncty", 0.2);
222  desc.add<bool>("SkipWarnings", true);
223  descriptions.add("l1ECALPrefiringWeightProducer", desc);
224 }
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
double L1ECALPrefiringWeightProducer::getPrefiringRate ( double  eta,
double  pt,
TH2F *  h_prefmap,
fluctuations  fluctuation 
) const
private

Definition at line 185 of file L1ECALPrefiringWeightProducer.cc.

References gather_cfg::cout, down, SiStripPI::max, min(), funct::pow(), prefiringRateSystUnc_, skipwarnings_, mathSSE::sqrt(), and up.

Referenced by produce().

188  {
189  if (h_prefmap == nullptr && !skipwarnings_)
190  std::cout << "Prefiring map not found, setting prefiring rate to 0 " << std::endl;
191  if (h_prefmap == nullptr)
192  return 0.;
193  //Check pt is not above map overflow
194  int nbinsy = h_prefmap->GetNbinsY();
195  double maxy = h_prefmap->GetYaxis()->GetBinLowEdge(nbinsy + 1);
196  if (pt >= maxy)
197  pt = maxy - 0.01;
198  int thebin = h_prefmap->FindBin(eta, pt);
199 
200  double prefrate = h_prefmap->GetBinContent(thebin);
201 
202  double statuncty = h_prefmap->GetBinError(thebin);
203  double systuncty = prefiringRateSystUnc_ * prefrate;
204 
205  if (fluctuation == up)
206  prefrate = std::min(1., prefrate + sqrt(pow(statuncty, 2) + pow(systuncty, 2)));
207  if (fluctuation == down)
208  prefrate = std::max(0., prefrate - sqrt(pow(statuncty, 2) + pow(systuncty, 2)));
209  return prefrate;
210 }
T sqrt(T t)
Definition: SSEVec.h:19
T min(T a, T b)
Definition: MathUtil.h:58
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30
void L1ECALPrefiringWeightProducer::produce ( edm::StreamID  ,
edm::Event iEvent,
const edm::EventSetup iSetup 
) const
overrideprivate

Definition at line 98 of file L1ECALPrefiringWeightProducer.cc.

References central, reco::deltaR(), down, HGC3DClusterGenMatchSelector_cfi::dR, edm::Event::getByToken(), getPrefiringRate(), h_prefmap_jet, h_prefmap_photon, metsig::jet, jets_token_, eostools::move(), muons2muons_cfi::photon, photons_token_, edm::Event::put(), up, and useEMpt_.

98  {
99  using namespace edm;
100 
101  //Photons
103  iEvent.getByToken(photons_token_, thePhotons);
104 
105  //Jets
107  iEvent.getByToken(jets_token_, theJets);
108 
109  //Probability for the event NOT to prefire, computed with the prefiring maps per object.
110  //Up and down values correspond to the resulting value when shifting up/down all prefiring rates in prefiring maps.
111  double nonPrefiringProba[3] = {1., 1., 1.}; //0: central, 1: up, 2: down
112 
113  for (const auto fluct : {fluctuations::central, fluctuations::up, fluctuations::down}) {
114  for (const auto& photon : *thePhotons) {
115  double pt_gam = photon.pt();
116  double eta_gam = photon.eta();
117  if (pt_gam < 20.)
118  continue;
119  if (fabs(eta_gam) < 2.)
120  continue;
121  if (fabs(eta_gam) > 3.)
122  continue;
123  double prefiringprob_gam = getPrefiringRate(eta_gam, pt_gam, h_prefmap_photon, fluct);
124  nonPrefiringProba[fluct] *= (1. - prefiringprob_gam);
125  }
126 
127  //Now applying the prefiring maps to jets in the affected regions.
128  for (const auto& jet : *theJets) {
129  double pt_jet = jet.pt();
130  double eta_jet = jet.eta();
131  double phi_jet = jet.phi();
132  if (pt_jet < 20.)
133  continue;
134  if (fabs(eta_jet) < 2.)
135  continue;
136  if (fabs(eta_jet) > 3.)
137  continue;
138 
139  //Loop over photons to remove overlap
140  double nonprefiringprobfromoverlappingphotons = 1.;
141  for (const auto& photon : *thePhotons) {
142  double pt_gam = photon.pt();
143  double eta_gam = photon.eta();
144  double phi_gam = photon.phi();
145  if (pt_gam < 20.)
146  continue;
147  if (fabs(eta_gam) < 2.)
148  continue;
149  if (fabs(eta_gam) > 3.)
150  continue;
151  double dR = reco::deltaR(eta_jet, phi_jet, eta_gam, phi_gam);
152  if (dR > 0.4)
153  continue;
154  double prefiringprob_gam = getPrefiringRate(eta_gam, pt_gam, h_prefmap_photon, fluct);
155  nonprefiringprobfromoverlappingphotons *= (1. - prefiringprob_gam);
156  }
157  //useEMpt =true if one wants to use maps parametrized vs Jet EM pt instead of pt.
158  if (useEMpt_)
159  pt_jet *= (jet.neutralEmEnergyFraction() + jet.chargedEmEnergyFraction());
160  double nonprefiringprobfromoverlappingjet = 1. - getPrefiringRate(eta_jet, pt_jet, h_prefmap_jet, fluct);
161 
162  if (nonprefiringprobfromoverlappingphotons == 1.) {
163  nonPrefiringProba[fluct] *= nonprefiringprobfromoverlappingjet;
164  }
165  //If overlapping photons have a non prefiring rate larger than the jet, then replace these weights by the jet one
166  else if (nonprefiringprobfromoverlappingphotons > nonprefiringprobfromoverlappingjet) {
167  if (nonprefiringprobfromoverlappingphotons != 0.) {
168  nonPrefiringProba[fluct] *= nonprefiringprobfromoverlappingjet / nonprefiringprobfromoverlappingphotons;
169  } else {
170  nonPrefiringProba[fluct] = 0.;
171  }
172  }
173  //Last case: if overlapping photons have a non prefiring rate smaller than the jet, don't consider the jet in the event weight, and do nothing.
174  }
175  }
176 
177  auto nonPrefiringProb = std::make_unique<double>(nonPrefiringProba[0]);
178  auto nonPrefiringProbUp = std::make_unique<double>(nonPrefiringProba[1]);
179  auto nonPrefiringProbDown = std::make_unique<double>(nonPrefiringProba[2]);
180  iEvent.put(std::move(nonPrefiringProb), "nonPrefiringProb");
181  iEvent.put(std::move(nonPrefiringProbUp), "nonPrefiringProbUp");
182  iEvent.put(std::move(nonPrefiringProbDown), "nonPrefiringProbDown");
183 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
edm::EDGetTokenT< std::vector< pat::Photon > > photons_token_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
double getPrefiringRate(double eta, double pt, TH2F *h_prefmap, fluctuations fluctuation) const
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
edm::EDGetTokenT< std::vector< pat::Jet > > jets_token_
HLT enums.
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

std::string L1ECALPrefiringWeightProducer::dataera_
private

Definition at line 55 of file L1ECALPrefiringWeightProducer.cc.

Referenced by L1ECALPrefiringWeightProducer().

TH2F* L1ECALPrefiringWeightProducer::h_prefmap_jet
private
TH2F* L1ECALPrefiringWeightProducer::h_prefmap_photon
private
edm::EDGetTokenT<std::vector<pat::Jet> > L1ECALPrefiringWeightProducer::jets_token_
private

Definition at line 51 of file L1ECALPrefiringWeightProducer.cc.

Referenced by L1ECALPrefiringWeightProducer(), and produce().

edm::EDGetTokenT<std::vector<pat::Photon> > L1ECALPrefiringWeightProducer::photons_token_
private

Definition at line 50 of file L1ECALPrefiringWeightProducer.cc.

Referenced by L1ECALPrefiringWeightProducer(), and produce().

double L1ECALPrefiringWeightProducer::prefiringRateSystUnc_
private
bool L1ECALPrefiringWeightProducer::skipwarnings_
private
bool L1ECALPrefiringWeightProducer::useEMpt_
private

Definition at line 56 of file L1ECALPrefiringWeightProducer.cc.

Referenced by L1ECALPrefiringWeightProducer(), and produce().