CMS 3D CMS Logo

HFJetShowerShape.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: HFJetShowerShape/HFJetShowerShape
4 // Class: HFJetShowerShape
5 //
13 //
14 // Original Author: Laurent Thomas
15 // Created: Tue, 25 Aug 2020 09:17:42 GMT
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
25 
28 
31 
34 
36 
37 #include <iostream>
38 
39 //
40 // class declaration
41 //
42 
44 public:
45  explicit HFJetShowerShape(const edm::ParameterSet&);
46 
47  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
48 
49 private:
50  void produce(edm::Event&, const edm::EventSetup&) override;
51  template <typename T>
52  void putInEvent(const std::string&, const edm::Handle<edm::View<reco::Jet>>&, std::vector<T>, edm::Event&) const;
53 
56 
57  //Jet pt/eta thresholds
59  //HF geometry
61  //Variables for PU subtraction
63  //Pt thresholds for showershape variable calculation
65 };
66 
67 //
68 // constants, enums and typedefs
69 //
70 
71 //
72 // static data member definitions
73 //
74 
75 //
76 // constructors and destructor
77 //
79  : jets_token_(consumes<edm::View<reco::Jet>>(iConfig.getParameter<edm::InputTag>("jets"))),
80  vertices_token_(consumes<std::vector<reco::Vertex>>(iConfig.getParameter<edm::InputTag>("vertices"))),
81  jetPtThreshold_(iConfig.getParameter<double>("jetPtThreshold")),
82  jetEtaThreshold_(iConfig.getParameter<double>("jetEtaThreshold")),
83  hfTowerEtaWidth_(iConfig.getParameter<double>("hfTowerEtaWidth")),
84  hfTowerPhiWidth_(iConfig.getParameter<double>("hfTowerPhiWidth")),
85  vertexRecoEffcy_(iConfig.getParameter<double>("vertexRecoEffcy")),
86  offsetPerPU_(iConfig.getParameter<double>("offsetPerPU")),
87  jetReferenceRadius_(iConfig.getParameter<double>("jetReferenceRadius")),
88  stripPtThreshold_(iConfig.getParameter<double>("stripPtThreshold")),
89  widthPtThreshold_(iConfig.getParameter<double>("widthPtThreshold")) {
90  produces<edm::ValueMap<float>>("sigmaEtaEta");
91  produces<edm::ValueMap<float>>("sigmaPhiPhi");
92  produces<edm::ValueMap<int>>("centralEtaStripSize");
93  produces<edm::ValueMap<int>>("adjacentEtaStripsSize");
94 }
95 
96 //
97 // member functions
98 //
99 
100 // ------------ method called to produce the data ------------
102  using namespace edm;
103 
104  //Jets
105  auto theJets = iEvent.getHandle(jets_token_);
106 
107  //Vertices
108  int nPV = iEvent.get(vertices_token_).size();
109 
110  //Products
111  std::vector<float> v_sigmaEtaEta, v_sigmaPhiPhi;
112  v_sigmaEtaEta.reserve(theJets->size());
113  v_sigmaPhiPhi.reserve(theJets->size());
114  std::vector<int> v_size_CentralEtaStrip, v_size_AdjacentEtaStrips;
115  v_size_CentralEtaStrip.reserve(theJets->size());
116  v_size_AdjacentEtaStrips.reserve(theJets->size());
117 
118  //Et offset for HF PF candidates
121 
122  for (auto const& jet : *theJets) {
123  double pt_jet = jet.pt();
124  double eta_jet = jet.eta();
125 
126  //If central or low pt jets, fill with dummy variables
127  if (pt_jet <= jetPtThreshold_ || std::abs(eta_jet) <= jetEtaThreshold_) {
128  v_sigmaEtaEta.push_back(-1.);
129  v_sigmaPhiPhi.push_back(-1.);
130  v_size_CentralEtaStrip.push_back(0);
131  v_size_AdjacentEtaStrips.push_back(0);
132  } else {
133  //First loop over PF candidates to compute some global variables needed for shower shape calculations
134  double sumptPFcands = 0.;
135 
136  for (unsigned i = 0; i < jet.numberOfSourceCandidatePtrs(); ++i) {
137  const reco::Candidate* icand = jet.sourceCandidatePtr(i).get();
138  //Only look at pdgId =1,2 (HF PF cands)
139  if (std::abs(icand->pdgId()) > 2)
140  continue;
141  double pt_PUsub = icand->pt() - puoffset;
142  if (pt_PUsub < widthPtThreshold_)
143  continue;
144  sumptPFcands += pt_PUsub;
145  }
146 
147  //Second loop to compute the various shower shape variables
148  int size_CentralEtaStrip(0.), size_AdjacentEtaStrips(0.);
149  double sigmaEtaEtaSq(0.), sigmaPhiPhiSq(0.);
150  double sumweightsPFcands = 0;
151  for (unsigned i = 0; i < jet.numberOfSourceCandidatePtrs(); ++i) {
152  const reco::Candidate* icand = jet.sourceCandidatePtr(i).get();
153  //Only look at pdgId =1,2 (HF PF cands)
154  if (std::abs(icand->pdgId()) > 2)
155  continue;
156 
157  double deta = std::abs(icand->eta() - jet.eta());
158  double dphi = std::abs(deltaPhi(icand->phi(), jet.phi()));
159  double pt_PUsub = icand->pt() - puoffset;
160 
161  //This is simply the size of the central eta strip and the adjacent strips
162  if (pt_PUsub >= stripPtThreshold_) {
163  if (dphi <= hfTowerPhiWidth_ * 0.5)
164  size_CentralEtaStrip++;
165  else if (dphi <= hfTowerPhiWidth_ * 1.5)
166  size_AdjacentEtaStrips++;
167  }
168 
169  //Now computing sigmaEtaEta/PhiPhi
170  if (pt_PUsub >= widthPtThreshold_ && sumptPFcands > 0) {
171  double weight = pt_PUsub / sumptPFcands;
172  sigmaEtaEtaSq += deta * deta * weight;
173  sigmaPhiPhiSq += dphi * dphi * weight;
174  sumweightsPFcands += weight;
175  }
176  }
177 
178  v_size_CentralEtaStrip.push_back(size_CentralEtaStrip);
179  v_size_AdjacentEtaStrips.push_back(size_AdjacentEtaStrips);
180 
181  if (sumweightsPFcands > 0 && sigmaEtaEtaSq > 0 && sigmaPhiPhiSq > 0) {
182  v_sigmaEtaEta.push_back(sqrt(sigmaEtaEtaSq / sumweightsPFcands));
183  v_sigmaPhiPhi.push_back(sqrt(sigmaPhiPhiSq / sumweightsPFcands));
184  } else {
185  v_sigmaEtaEta.push_back(-1.);
186  v_sigmaPhiPhi.push_back(-1.);
187  }
188 
189  } //End loop over jets
190  }
191 
192  putInEvent("sigmaEtaEta", theJets, v_sigmaEtaEta, iEvent);
193  putInEvent("sigmaPhiPhi", theJets, v_sigmaPhiPhi, iEvent);
194  putInEvent("centralEtaStripSize", theJets, v_size_CentralEtaStrip, iEvent);
195  putInEvent("adjacentEtaStripsSize", theJets, v_size_AdjacentEtaStrips, iEvent);
196 }
197 
199 template <typename T>
202  std::vector<T> product,
203  edm::Event& iEvent) const {
204  auto out = std::make_unique<edm::ValueMap<T>>();
206  filler.insert(jets, product.begin(), product.end());
207  filler.fill();
208  iEvent.put(std::move(out), name);
209 }
210 
211 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
214  desc.add<edm::InputTag>("jets", edm::InputTag("ak4PFJetsCHS"));
215  desc.add<edm::InputTag>("vertices", edm::InputTag("offlineSlimmedPrimaryVertices"));
216  desc.add<double>("jetPtThreshold", 25.);
217  desc.add<double>("jetEtaThreshold", 2.9);
218  desc.add<double>("hfTowerEtaWidth", 0.175);
219  desc.add<double>("hfTowerPhiWidth", 0.175);
220  desc.add<double>("vertexRecoEffcy", 0.7);
221  desc.add<double>("offsetPerPU", 0.4);
222  desc.add<double>("jetReferenceRadius", 0.4);
223  desc.add<double>("stripPtThreshold", 10.);
224  desc.add<double>("widthPtThreshold", 3.);
225  descriptions.add("hfJetShowerShape", desc);
226 }
227 
228 //define this as a plug-in
const double jetReferenceRadius_
const double vertexRecoEffcy_
virtual double pt() const =0
transverse momentum
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Definition: weight.py:1
void produce(edm::Event &, const edm::EventSetup &) override
const double widthPtThreshold_
void putInEvent(const std::string &, const edm::Handle< edm::View< reco::Jet >> &, std::vector< T >, edm::Event &) const
Function to put product into event.
int iEvent
Definition: GenABIO.cc:224
Definition: Jet.py:1
T sqrt(T t)
Definition: SSEVec.h:19
const double hfTowerPhiWidth_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const double jetPtThreshold_
const edm::EDGetTokenT< std::vector< reco::Vertex > > vertices_token_
const edm::EDGetTokenT< edm::View< reco::Jet > > jets_token_
const double offsetPerPU_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
#define M_PI
virtual int pdgId() const =0
PDG identifier.
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HFJetShowerShape(const edm::ParameterSet &)
fixed size matrix
HLT enums.
const double stripPtThreshold_
const double jetEtaThreshold_
const double hfTowerEtaWidth_
def move(src, dest)
Definition: eostools.py:511
virtual double phi() const =0
momentum azimuthal angle
virtual double eta() const =0
momentum pseudorapidity