Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-10 02:54:23

0001 // -*- C++ -*-
0002 //
0003 // Package:    ProdTutorial/L1PrefiringWeightProducer
0004 // Class:      L1PrefiringWeightProducer
0005 //
0006 /**\class L1PrefiringWeightProducer L1PrefiringWeightProducer.cc ProdTutorial/L1ECALPrefiringWeightProducer/plugins/L1ECALPrefiringWeightProducer.cc
0007 
0008  Description: [one line class summary]
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  localusers user
0015 //         Created:  Thu, 08 Nov 2018 16:16:00 GMT
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 #include "FWCore/Framework/interface/Frameworkfwd.h"
0023 #include "FWCore/Framework/interface/stream/EDProducer.h"
0024 
0025 #include "FWCore/Framework/interface/Event.h"
0026 #include "FWCore/Framework/interface/MakerMacros.h"
0027 
0028 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0029 #include "FWCore/Utilities/interface/StreamID.h"
0030 
0031 #include "DataFormats/PatCandidates/interface/Jet.h"
0032 #include "DataFormats/PatCandidates/interface/Photon.h"
0033 #include "DataFormats/PatCandidates/interface/Muon.h"
0034 
0035 #include "TFile.h"
0036 #include "TF1.h"
0037 #include "TH2.h"
0038 
0039 #include <iostream>
0040 enum fluctuations { central = 0, up, down, upStat, downStat, upSyst, downSyst };
0041 
0042 class L1PrefiringWeightProducer : public edm::stream::EDProducer<> {
0043 public:
0044   explicit L1PrefiringWeightProducer(const edm::ParameterSet&);
0045   ~L1PrefiringWeightProducer() override;
0046 
0047   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0048 
0049 private:
0050   void produce(edm::Event&, const edm::EventSetup&) override;
0051 
0052   double getPrefiringRateEcal(double eta, double pt, TH2F* h_prefmap, fluctuations fluctuation) const;
0053   double getPrefiringRateMuon(double eta, double phi, double pt, fluctuations fluctuation) const;
0054 
0055   const edm::EDGetTokenT<std::vector<pat::Photon> > photons_token_;
0056   const edm::EDGetTokenT<std::vector<pat::Jet> > jets_token_;
0057   const edm::EDGetTokenT<std::vector<pat::Muon> > muon_token_;
0058 
0059   const edm::EDPutTokenT<float> nonPrefiringProbToken_;
0060   const edm::EDPutTokenT<float> nonPrefiringProbUpToken_;
0061   const edm::EDPutTokenT<float> nonPrefiringProbDownToken_;
0062 
0063   const edm::EDPutTokenT<float> nonPrefiringProbECALToken_;
0064   const edm::EDPutTokenT<float> nonPrefiringProbECALUpToken_;
0065   const edm::EDPutTokenT<float> nonPrefiringProbECALDownToken_;
0066 
0067   const edm::EDPutTokenT<float> nonPrefiringProbMuonToken_;
0068   const edm::EDPutTokenT<float> nonPrefiringProbMuonUpToken_;
0069   const edm::EDPutTokenT<float> nonPrefiringProbMuonDownToken_;
0070   const edm::EDPutTokenT<float> nonPrefiringProbMuonUpSystToken_;
0071   const edm::EDPutTokenT<float> nonPrefiringProbMuonDownSystToken_;
0072   const edm::EDPutTokenT<float> nonPrefiringProbMuonUpStatToken_;
0073   const edm::EDPutTokenT<float> nonPrefiringProbMuonDownStatToken_;
0074 
0075   std::unique_ptr<TFile> file_prefiringmaps_;
0076   std::unique_ptr<TFile> file_prefiringparams_;
0077 
0078   TF1* parametrization0p0To0p2_;
0079   TF1* parametrization0p2To0p3_;
0080   TF1* parametrization0p3To0p55_;
0081   TF1* parametrization0p55To0p83_;
0082   TF1* parametrization0p83To1p24_;
0083   TF1* parametrization1p24To1p4_;
0084   TF1* parametrization1p4To1p6_;
0085   TF1* parametrization1p6To1p8_;
0086   TF1* parametrization1p8To2p1_;
0087   TF1* parametrization2p1To2p25_;
0088   TF1* parametrization2p25To2p4_;
0089   TF1* parametrizationHotSpot_;
0090 
0091   TH2F* h_prefmap_photon_;
0092   TH2F* h_prefmap_jet_;
0093   const std::string dataeraEcal_;
0094   const std::string dataeraMuon_;
0095   const bool useEMpt_;
0096   const double prefiringRateSystUncEcal_;
0097   const double prefiringRateSystUncMuon_;
0098   const double jetMaxMuonFraction_;
0099   bool missingInputEcal_;
0100   bool missingInputMuon_;
0101 };
0102 
0103 L1PrefiringWeightProducer::L1PrefiringWeightProducer(const edm::ParameterSet& iConfig)
0104     : photons_token_(consumes<std::vector<pat::Photon> >(iConfig.getParameter<edm::InputTag>("ThePhotons"))),
0105       jets_token_(consumes<std::vector<pat::Jet> >(iConfig.getParameter<edm::InputTag>("TheJets"))),
0106       muon_token_(consumes<std::vector<pat::Muon> >(iConfig.getParameter<edm::InputTag>("TheMuons"))),
0107       nonPrefiringProbToken_(produces<float>("nonPrefiringProb")),
0108       nonPrefiringProbUpToken_(produces<float>("nonPrefiringProbUp")),
0109       nonPrefiringProbDownToken_(produces<float>("nonPrefiringProbDown")),
0110       nonPrefiringProbECALToken_(produces<float>("nonPrefiringProbECAL")),
0111       nonPrefiringProbECALUpToken_(produces<float>("nonPrefiringProbECALUp")),
0112       nonPrefiringProbECALDownToken_(produces<float>("nonPrefiringProbECALDown")),
0113       nonPrefiringProbMuonToken_(produces<float>("nonPrefiringProbMuon")),
0114       nonPrefiringProbMuonUpToken_(produces<float>("nonPrefiringProbMuonUp")),
0115       nonPrefiringProbMuonDownToken_(produces<float>("nonPrefiringProbMuonDown")),
0116       nonPrefiringProbMuonUpSystToken_(produces<float>("nonPrefiringProbMuonSystUp")),
0117       nonPrefiringProbMuonDownSystToken_(produces<float>("nonPrefiringProbMuonSystDown")),
0118       nonPrefiringProbMuonUpStatToken_(produces<float>("nonPrefiringProbMuonStatUp")),
0119       nonPrefiringProbMuonDownStatToken_(produces<float>("nonPrefiringProbMuonStatDown")),
0120       dataeraEcal_(iConfig.getParameter<std::string>("DataEraECAL")),
0121       dataeraMuon_(iConfig.getParameter<std::string>("DataEraMuon")),
0122       useEMpt_(iConfig.getParameter<bool>("UseJetEMPt")),
0123       prefiringRateSystUncEcal_(iConfig.getParameter<double>("PrefiringRateSystematicUnctyECAL")),
0124       prefiringRateSystUncMuon_(iConfig.getParameter<double>("PrefiringRateSystematicUnctyMuon")),
0125       jetMaxMuonFraction_(iConfig.getParameter<double>("JetMaxMuonFraction")) {
0126   missingInputEcal_ = false;
0127   missingInputMuon_ = false;
0128 
0129   std::string fname = iConfig.getParameter<std::string>("L1Maps");
0130   edm::FileInPath mapsfilepath("PhysicsTools/PatUtils/data/" + fname);
0131   file_prefiringmaps_ = std::make_unique<TFile>(mapsfilepath.fullPath().c_str(), "read");
0132   if (file_prefiringmaps_ == nullptr) {
0133     missingInputEcal_ = true;
0134     edm::LogError("L1PrefireWeightProducer")
0135         << "File with maps not found. All prefiring weights set to 0. " << std::endl;
0136   }
0137   TString mapphotonfullname = "L1prefiring_photonptvseta_" + dataeraEcal_;
0138   if (!file_prefiringmaps_->Get(mapphotonfullname)) {
0139     missingInputEcal_ = true;
0140     edm::LogError("L1PrefireWeightProducer")
0141         << "Photon map not found. All photons prefiring weights set to 0. " << std::endl;
0142   }
0143   h_prefmap_photon_ = file_prefiringmaps_->Get<TH2F>(mapphotonfullname);
0144   TString mapjetfullname =
0145       (useEMpt_) ? "L1prefiring_jetemptvseta_" + dataeraEcal_ : "L1prefiring_jetptvseta_" + dataeraEcal_;
0146   if (!file_prefiringmaps_->Get(mapjetfullname)) {
0147     missingInputEcal_ = true;
0148     edm::LogError("L1PrefireWeightProducer") << "Jet map not found. All jets prefiring weights set to 0. " << std::endl;
0149   }
0150   h_prefmap_jet_ = file_prefiringmaps_->Get<TH2F>(mapjetfullname);
0151   file_prefiringmaps_->Close();
0152 
0153   std::string fnameMuon = iConfig.getParameter<std::string>("L1MuonParametrizations");
0154   edm::FileInPath paramsfilepath("PhysicsTools/PatUtils/data/" + fnameMuon);
0155   file_prefiringparams_ = std::make_unique<TFile>(paramsfilepath.fullPath().c_str(), "read");
0156   if (file_prefiringparams_ == nullptr) {
0157     missingInputMuon_ = true;
0158     edm::LogError("L1PrefireWeightProducer")
0159         << "File with muon parametrizations not found. All prefiring weights set to 0." << std::endl;
0160   }
0161   TString paramName = "L1prefiring_muonparam_0.0To0.2_" + dataeraMuon_;
0162   parametrization0p0To0p2_ = file_prefiringparams_->Get<TF1>(paramName);
0163   paramName = "L1prefiring_muonparam_0.2To0.3_" + dataeraMuon_;
0164   parametrization0p2To0p3_ = file_prefiringparams_->Get<TF1>(paramName);
0165   paramName = "L1prefiring_muonparam_0.3To0.55_" + dataeraMuon_;
0166   parametrization0p3To0p55_ = file_prefiringparams_->Get<TF1>(paramName);
0167   paramName = "L1prefiring_muonparam_0.55To0.83_" + dataeraMuon_;
0168   parametrization0p55To0p83_ = file_prefiringparams_->Get<TF1>(paramName);
0169   paramName = "L1prefiring_muonparam_0.83To1.24_" + dataeraMuon_;
0170   parametrization0p83To1p24_ = file_prefiringparams_->Get<TF1>(paramName);
0171   paramName = "L1prefiring_muonparam_1.24To1.4_" + dataeraMuon_;
0172   parametrization1p24To1p4_ = file_prefiringparams_->Get<TF1>(paramName);
0173   paramName = "L1prefiring_muonparam_1.4To1.6_" + dataeraMuon_;
0174   parametrization1p4To1p6_ = file_prefiringparams_->Get<TF1>(paramName);
0175   paramName = "L1prefiring_muonparam_1.6To1.8_" + dataeraMuon_;
0176   parametrization1p6To1p8_ = file_prefiringparams_->Get<TF1>(paramName);
0177   paramName = "L1prefiring_muonparam_1.8To2.1_" + dataeraMuon_;
0178   parametrization1p8To2p1_ = file_prefiringparams_->Get<TF1>(paramName);
0179   paramName = "L1prefiring_muonparam_2.1To2.25_" + dataeraMuon_;
0180   parametrization2p1To2p25_ = file_prefiringparams_->Get<TF1>(paramName);
0181   paramName = "L1prefiring_muonparam_2.25To2.4_" + dataeraMuon_;
0182   parametrization2p25To2p4_ = file_prefiringparams_->Get<TF1>(paramName);
0183 
0184   if (parametrization0p0To0p2_ == nullptr || parametrization0p2To0p3_ == nullptr ||
0185       parametrization0p3To0p55_ == nullptr || parametrization0p55To0p83_ == nullptr ||
0186       parametrization0p83To1p24_ == nullptr || parametrization1p24To1p4_ == nullptr ||
0187       parametrization1p4To1p6_ == nullptr || parametrization1p6To1p8_ == nullptr ||
0188       parametrization1p8To2p1_ == nullptr || parametrization2p1To2p25_ == nullptr ||
0189       parametrization2p25To2p4_ == nullptr) {
0190     missingInputMuon_ = true;
0191     edm::LogError("L1PrefireWeightProducer")
0192         << "Muon parametrization not found for at least one bin. All prefiring weights set to 0." << std::endl;
0193   }
0194 
0195   paramName = "L1prefiring_muonparam_HotSpot_" + dataeraMuon_;
0196   parametrizationHotSpot_ = file_prefiringparams_->Get<TF1>(paramName);
0197   file_prefiringparams_->Close();
0198   if ((dataeraMuon_.find("2016") != std::string::npos) && parametrizationHotSpot_ == nullptr) {
0199     missingInputMuon_ = true;
0200     edm::LogError("L1PrefireWeightProducer")
0201         << "Year is 2016 and no Muon parametrization is found for hot spot. All prefiring weights set to 0."
0202         << std::endl;
0203   }
0204 }
0205 
0206 L1PrefiringWeightProducer::~L1PrefiringWeightProducer() {}
0207 
0208 void L1PrefiringWeightProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0209   using namespace edm;
0210 
0211   //Photons
0212   const std::vector<pat::Photon>& thePhotons = iEvent.get(photons_token_);
0213 
0214   //Jets
0215   const std::vector<pat::Jet>& theJets = iEvent.get(jets_token_);
0216 
0217   //Muons
0218   const std::vector<pat::Muon>& theMuons = iEvent.get(muon_token_);
0219 
0220   //Probability for the event NOT to prefire, computed with the prefiring maps per object.
0221   //Up and down values correspond to the resulting value when shifting up/down all prefiring rates in prefiring maps.
0222   double nonPrefiringProba[3] = {1., 1., 1.};      //0: central, 1: up, 2: down
0223   double nonPrefiringProbaECAL[3] = {1., 1., 1.};  //0: central, 1: up, 2: down
0224   double nonPrefiringProbaMuon[7] = {
0225       1., 1., 1., 1., 1., 1., 1.};  //0: central, 1: up, 2: down, 3: up stat, 4: down stat, 5: up syst, 6: down syst
0226 
0227   for (const auto fluct : {fluctuations::central, fluctuations::up, fluctuations::down}) {
0228     if (!missingInputEcal_) {
0229       for (const auto& photon : thePhotons) {
0230         double pt_gam = photon.pt();
0231         double eta_gam = photon.eta();
0232         if (pt_gam < 20.)
0233           continue;
0234         if (fabs(eta_gam) < 2.)
0235           continue;
0236         if (fabs(eta_gam) > 3.)
0237           continue;
0238         double prefiringprob_gam = getPrefiringRateEcal(eta_gam, pt_gam, h_prefmap_photon_, fluct);
0239         nonPrefiringProbaECAL[fluct] *= (1. - prefiringprob_gam);
0240       }
0241 
0242       //Now applying the prefiring maps to jets in the affected regions.
0243       for (const auto& jet : theJets) {
0244         double pt_jet = jet.pt();
0245         double eta_jet = jet.eta();
0246         double phi_jet = jet.phi();
0247         if (pt_jet < 20.)
0248           continue;
0249         if (fabs(eta_jet) < 2.)
0250           continue;
0251         if (fabs(eta_jet) > 3.)
0252           continue;
0253         if (jetMaxMuonFraction_ > 0 && jet.muonEnergyFraction() > jetMaxMuonFraction_)
0254           continue;
0255         //Loop over photons to remove overlap
0256         double nonprefiringprobfromoverlappingphotons = 1.;
0257         bool foundOverlappingPhotons = false;
0258         for (const auto& photon : thePhotons) {
0259           double pt_gam = photon.pt();
0260           double eta_gam = photon.eta();
0261           double phi_gam = photon.phi();
0262           if (pt_gam < 20.)
0263             continue;
0264           if (fabs(eta_gam) < 2.)
0265             continue;
0266           if (fabs(eta_gam) > 3.)
0267             continue;
0268           double dR2 = reco::deltaR2(eta_jet, phi_jet, eta_gam, phi_gam);
0269           if (dR2 > 0.16)
0270             continue;
0271           double prefiringprob_gam = getPrefiringRateEcal(eta_gam, pt_gam, h_prefmap_photon_, fluct);
0272           nonprefiringprobfromoverlappingphotons *= (1. - prefiringprob_gam);
0273           foundOverlappingPhotons = true;
0274         }
0275         //useEMpt =true if one wants to use maps parametrized vs Jet EM pt instead of pt.
0276         if (useEMpt_)
0277           pt_jet *= (jet.neutralEmEnergyFraction() + jet.chargedEmEnergyFraction());
0278         double nonprefiringprobfromoverlappingjet = 1. - getPrefiringRateEcal(eta_jet, pt_jet, h_prefmap_jet_, fluct);
0279 
0280         if (!foundOverlappingPhotons) {
0281           nonPrefiringProbaECAL[fluct] *= nonprefiringprobfromoverlappingjet;
0282         }
0283         //If overlapping photons have a non prefiring rate larger than the jet, then replace these weights by the jet one
0284         else if (nonprefiringprobfromoverlappingphotons > nonprefiringprobfromoverlappingjet) {
0285           if (nonprefiringprobfromoverlappingphotons > 0.) {
0286             nonPrefiringProbaECAL[fluct] *= nonprefiringprobfromoverlappingjet / nonprefiringprobfromoverlappingphotons;
0287           } else {
0288             nonPrefiringProbaECAL[fluct] = 0.;
0289           }
0290         }
0291         //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.
0292       }
0293     }
0294     //Now calculate prefiring weights for muons
0295     if (!missingInputMuon_) {
0296       for (const auto& muon : theMuons) {
0297         double pt = muon.pt();
0298         double phi = muon.phi();
0299         double eta = muon.eta();
0300         // Remove crappy tracker muons which would not have prefired the L1 trigger
0301         if (pt < 5 || !muon.isLooseMuon())
0302           continue;
0303         double prefiringprob_mu = getPrefiringRateMuon(eta, phi, pt, fluct);
0304         nonPrefiringProbaMuon[fluct] *= (1. - prefiringprob_mu);
0305       }
0306     }
0307   }
0308   // Calculate combined weight as product of the weight for individual objects
0309   for (const auto fluct : {fluctuations::central, fluctuations::up, fluctuations::down}) {
0310     nonPrefiringProba[fluct] = nonPrefiringProbaECAL[fluct] * nonPrefiringProbaMuon[fluct];
0311   }
0312   // Calculate statistical and systematic uncertainty separately in the muon case
0313   for (const auto fluct :
0314        {fluctuations::upSyst, fluctuations::downSyst, fluctuations::upStat, fluctuations::downStat}) {
0315     if (!missingInputMuon_) {
0316       for (const auto& muon : theMuons) {
0317         double pt = muon.pt();
0318         double phi = muon.phi();
0319         double eta = muon.eta();
0320         // Remove crappy tracker muons which would not have prefired the L1 trigger
0321         if (pt < 5 || !muon.isLooseMuon())
0322           continue;
0323         double prefiringprob_mu = getPrefiringRateMuon(eta, phi, pt, fluct);
0324         nonPrefiringProbaMuon[fluct] *= (1. - prefiringprob_mu);
0325       }
0326     }
0327   }
0328   //Move global prefire weights, as well as those for muons, photons, and jets, to the event
0329   iEvent.emplace(nonPrefiringProbToken_, nonPrefiringProba[0]);
0330   iEvent.emplace(nonPrefiringProbUpToken_, nonPrefiringProba[1]);
0331   iEvent.emplace(nonPrefiringProbDownToken_, nonPrefiringProba[2]);
0332 
0333   iEvent.emplace(nonPrefiringProbECALToken_, nonPrefiringProbaECAL[0]);
0334   iEvent.emplace(nonPrefiringProbECALUpToken_, nonPrefiringProbaECAL[1]);
0335   iEvent.emplace(nonPrefiringProbECALDownToken_, nonPrefiringProbaECAL[2]);
0336 
0337   iEvent.emplace(nonPrefiringProbMuonToken_, nonPrefiringProbaMuon[0]);
0338   iEvent.emplace(nonPrefiringProbMuonUpToken_, nonPrefiringProbaMuon[1]);
0339   iEvent.emplace(nonPrefiringProbMuonDownToken_, nonPrefiringProbaMuon[2]);
0340   iEvent.emplace(nonPrefiringProbMuonUpStatToken_, nonPrefiringProbaMuon[3]);
0341   iEvent.emplace(nonPrefiringProbMuonDownStatToken_, nonPrefiringProbaMuon[4]);
0342   iEvent.emplace(nonPrefiringProbMuonUpSystToken_, nonPrefiringProbaMuon[5]);
0343   iEvent.emplace(nonPrefiringProbMuonDownSystToken_, nonPrefiringProbaMuon[6]);
0344 }
0345 
0346 double L1PrefiringWeightProducer::getPrefiringRateEcal(double eta,
0347                                                        double pt,
0348                                                        TH2F* h_prefmap,
0349                                                        fluctuations fluctuation) const {
0350   //Check pt is not above map overflow
0351   int nbinsy = h_prefmap->GetNbinsY();
0352   double maxy = h_prefmap->GetYaxis()->GetBinLowEdge(nbinsy + 1);
0353   if (pt >= maxy)
0354     pt = maxy - 0.01;
0355   int thebin = h_prefmap->FindBin(eta, pt);
0356 
0357   double prefrate = h_prefmap->GetBinContent(thebin);
0358 
0359   double statuncty = h_prefmap->GetBinError(thebin);
0360   double systuncty = prefiringRateSystUncEcal_ * prefrate;
0361 
0362   if (fluctuation == up)
0363     prefrate = std::min(1., prefrate + sqrt(pow(statuncty, 2) + pow(systuncty, 2)));
0364   else if (fluctuation == down)
0365     prefrate = std::max(0., prefrate - sqrt(pow(statuncty, 2) + pow(systuncty, 2)));
0366   if (prefrate > 1.) {
0367     edm::LogWarning("L1PrefireWeightProducer") << "Found a prefiring probability > 1. Setting to 1." << std::endl;
0368     return 1.;
0369   }
0370   return prefrate;
0371 }
0372 
0373 double L1PrefiringWeightProducer::getPrefiringRateMuon(double eta,
0374                                                        double phi,
0375                                                        double pt,
0376                                                        fluctuations fluctuation) const {
0377   double prefrate;
0378   double statuncty;
0379   if ((dataeraMuon_.find("2016") != std::string::npos) && (eta > 1.24 && eta < 1.6) &&
0380       (phi > 2.44346 && phi < 2.79253)) {
0381     prefrate = parametrizationHotSpot_->Eval(pt);
0382     statuncty = parametrizationHotSpot_->GetParError(2);
0383   } else if (std::abs(eta) < 0.2) {
0384     prefrate = parametrization0p0To0p2_->Eval(pt);
0385     statuncty = parametrization0p0To0p2_->GetParError(2);
0386   } else if (std::abs(eta) < 0.3) {
0387     prefrate = parametrization0p2To0p3_->Eval(pt);
0388     statuncty = parametrization0p2To0p3_->GetParError(2);
0389   } else if (std::abs(eta) < 0.55) {
0390     prefrate = parametrization0p3To0p55_->Eval(pt);
0391     statuncty = parametrization0p3To0p55_->GetParError(2);
0392   } else if (std::abs(eta) < 0.83) {
0393     prefrate = parametrization0p55To0p83_->Eval(pt);
0394     statuncty = parametrization0p55To0p83_->GetParError(2);
0395   } else if (std::abs(eta) < 1.24) {
0396     prefrate = parametrization0p83To1p24_->Eval(pt);
0397     statuncty = parametrization0p83To1p24_->GetParError(2);
0398   } else if (std::abs(eta) < 1.4) {
0399     prefrate = parametrization1p24To1p4_->Eval(pt);
0400     statuncty = parametrization1p24To1p4_->GetParError(2);
0401   } else if (std::abs(eta) < 1.6) {
0402     prefrate = parametrization1p4To1p6_->Eval(pt);
0403     statuncty = parametrization1p4To1p6_->GetParError(2);
0404   } else if (std::abs(eta) < 1.8) {
0405     prefrate = parametrization1p6To1p8_->Eval(pt);
0406     statuncty = parametrization1p6To1p8_->GetParError(2);
0407   } else if (std::abs(eta) < 2.1) {
0408     prefrate = parametrization1p8To2p1_->Eval(pt);
0409     statuncty = parametrization1p8To2p1_->GetParError(2);
0410   } else if (std::abs(eta) < 2.25) {
0411     prefrate = parametrization2p1To2p25_->Eval(pt);
0412     statuncty = parametrization2p1To2p25_->GetParError(2);
0413   } else if (std::abs(eta) < 2.4) {
0414     prefrate = parametrization2p25To2p4_->Eval(pt);
0415     statuncty = parametrization2p25To2p4_->GetParError(2);
0416   } else {
0417     LogDebug("L1PrefireWeightProducer") << "Muon outside of |eta| <= 2.4. Prefiring weight set to 0." << std::endl;
0418     return 0.;
0419   }
0420   double systuncty = prefiringRateSystUncMuon_ * prefrate;
0421 
0422   if (fluctuation == up)
0423     prefrate = std::min(1., prefrate + sqrt(pow(statuncty, 2) + pow(systuncty, 2)));
0424   else if (fluctuation == down)
0425     prefrate = std::max(0., prefrate - sqrt(pow(statuncty, 2) + pow(systuncty, 2)));
0426   else if (fluctuation == upSyst)
0427     prefrate = std::min(1., prefrate + systuncty);
0428   else if (fluctuation == downSyst)
0429     prefrate = std::max(0., prefrate - systuncty);
0430   else if (fluctuation == upStat)
0431     prefrate = std::min(1., prefrate + statuncty);
0432   else if (fluctuation == downStat)
0433     prefrate = std::max(0., prefrate - statuncty);
0434 
0435   if (prefrate > 1.) {
0436     edm::LogWarning("L1PrefireWeightProducer") << "Found a prefiring probability > 1. Setting to 1." << std::endl;
0437     return 1.;
0438   }
0439   return prefrate;
0440 }
0441 
0442 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0443 void L1PrefiringWeightProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0444   edm::ParameterSetDescription desc;
0445   desc.add<edm::InputTag>("TheMuons", edm::InputTag("slimmedMuons"));
0446   desc.add<edm::InputTag>("ThePhotons", edm::InputTag("slimmedPhotons"));
0447   desc.add<edm::InputTag>("TheJets", edm::InputTag("slimmedJets"));
0448   desc.add<std::string>("L1Maps", "L1PrefiringMaps.root");
0449   desc.add<std::string>("L1MuonParametrizations", "L1MuonPrefiringParametriations.root");
0450   desc.add<std::string>("DataEraECAL", "2017BtoF");
0451   desc.add<std::string>("DataEraMuon", "2016");
0452   desc.add<bool>("UseJetEMPt", false);
0453   desc.add<double>("PrefiringRateSystematicUnctyECAL", 0.2);
0454   desc.add<double>("PrefiringRateSystematicUnctyMuon", 0.2);
0455   desc.add<double>("JetMaxMuonFraction", 0.5);
0456   descriptions.add("l1PrefiringWeightProducer", desc);
0457 }
0458 
0459 //define this as a plug-in
0460 DEFINE_FWK_MODULE(L1PrefiringWeightProducer);