CMS 3D CMS Logo

Phase1L1TJetCalibrator.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1CaloTrigger
4 // Class: Phase1L1TJetCalibrator
5 //
17 //
18 // Original Author: Simone Bologna
19 // Created: Wed, 19 Dec 2018 12:44:23 GMT
20 //
21 // Rewrite: Vladimir Rekovic, Oct 2020
22 //
23 
24 // system include files
25 #include <memory>
26 
27 #include <algorithm>
28 #include <cmath>
29 
30 // user include files
33 
39 
42 
44 public:
46  ~Phase1L1TJetCalibrator() override;
47 
48  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
49 
50 private:
51  void produce(edm::Event&, const edm::EventSetup&) override;
52 
54  std::vector<double> absEtaBinning_;
55  size_t nBinsEta_;
56  std::vector<edm::ParameterSet> calibration_;
58 
59  std::vector<std::vector<double>> jetCalibrationFactorsBinnedInEta_;
60  std::vector<std::vector<double>> _jetCalibrationFactorsPtBins;
61 
62  // ----------member data ---------------------------
63 };
64 
65 //
66 // constants, enums and typedefs
67 //
68 
69 //
70 // static data member definitions
71 //
72 
73 //
74 // constructors and destructor
75 //
77  : inputCollectionTag_(edm::EDGetTokenT<std::vector<reco::CaloJet>>(
78  consumes<std::vector<reco::CaloJet>>(iConfig.getParameter<edm::InputTag>("inputCollectionTag")))),
79  absEtaBinning_(iConfig.getParameter<std::vector<double>>("absEtaBinning")),
80  nBinsEta_(absEtaBinning_.size() - 1),
81  calibration_(iConfig.getParameter<std::vector<edm::ParameterSet>>("calibration")),
82  outputCollectionName_(iConfig.getParameter<std::string>("outputCollectionName"))
83 
84 {
85  for (const auto& pset : calibration_) {
86  _jetCalibrationFactorsPtBins.emplace_back(pset.getParameter<std::vector<double>>("l1tPtBins"));
87  jetCalibrationFactorsBinnedInEta_.emplace_back(pset.getParameter<std::vector<double>>("l1tCalibrationFactors"));
88  }
89 
90  produces<std::vector<reco::CaloJet>>(outputCollectionName_).setBranchAlias(outputCollectionName_);
91 }
92 
94 
95 //
96 // member functions
97 //
98 
99 // ------------ method called to produce the data ------------
101  edm::Handle<std::vector<reco::CaloJet>> inputCollectionHandle;
102  iEvent.getByToken(inputCollectionTag_, inputCollectionHandle);
103 
104  auto calibratedCollectionPtr = std::make_unique<std::vector<reco::CaloJet>>();
105 
106  // for each candidate:
107  // 1 get pt and eta
108  // 2 run a dicotomic search on the eta vector to find the eta index
109  // 3 fetch the corresponding calibration elements
110  // 4 run a dicotomic search on the pt binning to find the pt index
111  // 5 fetch the calibration factor
112  // 6 update the candidate pt by applying the calibration factor
113  // 7 store calibrated candidate in a new collection
114 
115  calibratedCollectionPtr->reserve(inputCollectionHandle->size());
116 
117  for (const auto& candidate : *inputCollectionHandle) {
118  // 1
119  float pt = candidate.pt();
120  float eta = candidate.eta();
121 
122  //2
123  auto etaBin = upper_bound(absEtaBinning_.begin(), absEtaBinning_.end(), fabs(eta));
124  int etaIndex = etaBin - absEtaBinning_.begin() - 1;
125 
126  //3
127  const std::vector<double>& l1tPtBins = _jetCalibrationFactorsPtBins[etaIndex];
128  const std::vector<double>& l1tCalibrationFactors = jetCalibrationFactorsBinnedInEta_[etaIndex];
129 
130  //4
131  auto ptBin = upper_bound(l1tPtBins.begin(), l1tPtBins.end(), pt);
132  int ptBinIndex = ptBin - l1tPtBins.begin() - 1;
133 
134  //5
135  const double& l1tCalibrationFactor = l1tCalibrationFactors[ptBinIndex];
136 
137  //6 and 7
138  reco::Candidate::PolarLorentzVector candidateP4(candidate.polarP4());
139  candidateP4.SetPt(candidateP4.pt() * l1tCalibrationFactor);
140  calibratedCollectionPtr->emplace_back(candidate);
141  calibratedCollectionPtr->back().setP4(candidateP4);
142 
143 #ifdef DEBUG
144  if (newCandidate->pt() < 0) {
145  LogDebug("Phase1L1TJetCalibrator") << "######################" << std::endl;
146  LogDebug("Phase1L1TJetCalibrator") << "PRE-CALIBRATION " << std::endl;
147  LogDebug("Phase1L1TJetCalibrator") << "\t Jet properties (pt, eta, phi, pile-up): " << candidate.pt() << "\t"
148  << candidate.eta() << "\t" LogDebug("Phase1L1TJetCalibrator")
149  << candidate.phi() << "\t" << candidate.pileup() << std::endl;
150  LogDebug("Phase1L1TJetCalibrator") << "CALIBRATION " << std::endl;
151  LogDebug("Phase1L1TJetCalibrator") << "\t Using eta - pt - factor " << *etaBin << " - " << *ptBin << " - "
152  << l1tCalibrationFactor LogDebug("Phase1L1TJetCalibrator") << std::endl;
153  LogDebug("Phase1L1TJetCalibrator") << "POST-CALIBRATION " << std::endl;
154  LogDebug("Phase1L1TJetCalibrator") << "\t Jet properties (pt, eta, phi, pile-up): " << newCandidate->pt() << "\t"
155  << newCandidate->eta() << "\t" << newCandidate->phi() << "\t"
156  << newCandidate->pileup() << std::endl;
157  }
158 #endif
159  }
160 
161  // finally, sort the collection by pt
162  std::sort(calibratedCollectionPtr->begin(),
163  calibratedCollectionPtr->end(),
164  [](const reco::CaloJet& jet1, const reco::CaloJet& jet2) { return jet1.pt() > jet2.pt(); });
165 
166  iEvent.put(std::move(calibratedCollectionPtr), outputCollectionName_);
167 }
168 
171  desc.add<edm::InputTag>("inputCollectionTag",
172  edm::InputTag("Phase1L1TJetProducer", "UncalibratedPhase1L1TJetFromPfCandidates"));
173  desc.add<std::vector<double>>("absEtaBinning");
174  std::vector<edm::ParameterSet> vDefaults;
176  validator.add<double>("etaMax");
177  validator.add<double>("etaMin");
178  validator.add<std::vector<double>>("l1tCalibrationFactors");
179  validator.add<std::vector<double>>("l1tPtBins");
180  desc.addVPSet("calibration", validator, vDefaults);
181  desc.add<std::string>("outputCollectionName", "Phase1L1TJetFromPfCandidates");
182  descriptions.add("Phase1L1TJetCalibrator", desc);
183 }
184 
185 //define this as a plug-in
pfDeepBoostedJetPreprocessParams_cfi.upper_bound
upper_bound
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:16
reco::CaloJet
Jets made from CaloTowers.
Definition: CaloJet.h:27
CaloJet.h
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
etaBin
int etaBin(const l1t::HGCalMulticluster *cl)
Definition: L1EGammaEEProducer.cc:19
Phase1L1TJetCalibrator_9x9Jets_cfi.l1tCalibrationFactors
l1tCalibrationFactors
Definition: Phase1L1TJetCalibrator_9x9Jets_cfi.py:6
Phase1L1TJetCalibrator::absEtaBinning_
std::vector< double > absEtaBinning_
Definition: Phase1L1TJetCalibrator.cc:54
Phase1L1TJetCalibrator::nBinsEta_
size_t nBinsEta_
Definition: Phase1L1TJetCalibrator.cc:55
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
reco::Candidate::PolarLorentzVector
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Candidate.h:38
Phase1L1TJetCalibrator_9x9Jets_cfi.l1tPtBins
l1tPtBins
Definition: Phase1L1TJetCalibrator_9x9Jets_cfi.py:32
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
btagElecInJet_cfi.CaloJet
CaloJet
Definition: btagElecInJet_cfi.py:4
EDProducer.h
reco::LeafCandidate::pt
double pt() const final
transverse momentum
Definition: LeafCandidate.h:146
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:46
edm::Handle
Definition: AssociativeIterator.h:50
muonRecoAnalyzer_cfi.ptBin
ptBin
Definition: muonRecoAnalyzer_cfi.py:45
Phase1L1TJetCalibrator::jetCalibrationFactorsBinnedInEta_
std::vector< std::vector< double > > jetCalibrationFactorsBinnedInEta_
Definition: Phase1L1TJetCalibrator.cc:59
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
PVValHelper::eta
Definition: PVValidationHelpers.h:70
Phase1L1TJetCalibrator::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: Phase1L1TJetCalibrator.cc:100
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::ParameterSet
Definition: ParameterSet.h:47
Phase1L1TJetCalibrator::inputCollectionTag_
edm::EDGetTokenT< std::vector< reco::CaloJet > > inputCollectionTag_
Definition: Phase1L1TJetCalibrator.cc:53
Event.h
ParameterSet
Definition: Functions.h:16
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
Phase1L1TJetCalibrator
Definition: Phase1L1TJetCalibrator.cc:43
Phase1L1TJetCalibrator::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: Phase1L1TJetCalibrator.cc:169
iEvent
int iEvent
Definition: GenABIO.cc:224
Phase1L1TJetCalibrator::~Phase1L1TJetCalibrator
~Phase1L1TJetCalibrator() override
Definition: Phase1L1TJetCalibrator.cc:93
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::stream::EDProducer
Definition: EDProducer.h:36
edm::EventSetup
Definition: EventSetup.h:58
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
Frameworkfwd.h
Phase1L1TJetCalibrator::calibration_
std::vector< edm::ParameterSet > calibration_
Definition: Phase1L1TJetCalibrator.cc:56
Phase1L1TJetCalibrator::outputCollectionName_
std::string outputCollectionName_
Definition: Phase1L1TJetCalibrator.cc:57
Phase1L1TJetCalibrator::Phase1L1TJetCalibrator
Phase1L1TJetCalibrator(const edm::ParameterSet &)
Definition: Phase1L1TJetCalibrator.cc:76
Candidate.h
View.h
ParameterSet.h
edm::Event
Definition: Event.h:73
StreamID.h
edm::InputTag
Definition: InputTag.h:15
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
Phase1L1TJetCalibrator::_jetCalibrationFactorsPtBins
std::vector< std::vector< double > > _jetCalibrationFactorsPtBins
Definition: Phase1L1TJetCalibrator.cc:60