CMS 3D CMS Logo

JetPlusTrackProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: JetPlusTracks
4 // Class: JetPlusTrackProducer
5 //
13 //
14 // Original Author: Olga Kodolova,40 R-A12,+41227671273,
15 // Created: Fri Feb 19 10:14:02 CET 2010
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
23 
29 
44 #include <string>
45 
46 using namespace std;
47 using namespace jpt;
48 
49 //
50 // constants, enums and typedefs
51 //
52 
53 //
54 // static data member definitions
55 //
56 
57 //
58 // constructors and destructor
59 //
61  //register your products
62  src_ = iConfig.getParameter<edm::InputTag>("src");
63  srcTrackJets_ = iConfig.getParameter<edm::InputTag>("srcTrackJets");
64  alias_ = iConfig.getUntrackedParameter<string>("alias");
65  srcPVs_ = iConfig.getParameter<edm::InputTag>("srcPVs");
66  vectorial_ = iConfig.getParameter<bool>("VectorialCorrection");
67  useZSP_ = iConfig.getParameter<bool>("UseZSP");
68  ptCUT_ = iConfig.getParameter<double>("ptCUT");
69  dRcone_ = iConfig.getParameter<double>("dRcone");
70  usePAT_ = iConfig.getParameter<bool>("UsePAT");
71 
72  mJPTalgo = new JetPlusTrackCorrector(iConfig, consumesCollector());
73  if (useZSP_)
74  mZSPalgo = new ZSPJPTJetCorrector(iConfig);
75 
76  produces<reco::JPTJetCollection>().setBranchAlias(alias_);
77  produces<reco::CaloJetCollection>().setBranchAlias("ak4CaloJetsJPT");
78 
79  input_jets_token_ = consumes<edm::View<reco::CaloJet> >(src_);
80  input_addjets_token_ = consumes<edm::View<reco::CaloJet> >(iConfig.getParameter<edm::InputTag>("srcAddCaloJets"));
81  input_trackjets_token_ = consumes<edm::View<reco::TrackJet> >(srcTrackJets_);
82  input_vertex_token_ = consumes<reco::VertexCollection>(srcPVs_);
83  mExtrapolations_ =
84  consumes<std::vector<reco::TrackExtrapolation> >(iConfig.getParameter<edm::InputTag>("extrapolations"));
85 }
86 
88  // do anything here that needs to be done at desctruction time
89  // (e.g. close files, deallocate resources etc.)
90 }
91 
92 //
93 // member functions
94 //
95 bool sort_by_pt(const reco::JPTJet& a, const reco::JPTJet& b) { return (a.pt() > b.pt()); }
96 
97 // ------------ method called to produce the data ------------
99  using namespace edm;
100 
101  auto const& jets_h = iEvent.get(input_jets_token_);
102  auto const& addjets_h = iEvent.get(input_addjets_token_);
103  auto const& iExtrapolations = iEvent.get(mExtrapolations_);
104  edm::RefProd<reco::CaloJetCollection> pOut1RefProd = iEvent.getRefBeforePut<reco::CaloJetCollection>();
106 
107  auto pOut = std::make_unique<reco::JPTJetCollection>();
108  auto pOut1 = std::make_unique<reco::CaloJetCollection>();
109 
110  double scaleJPT = 1.;
111  for (auto const& jet : iEvent.get(input_trackjets_token_)) {
112  int icalo = -1;
113  int i = 0;
114  for (auto const& oldjet : addjets_h) {
115  double dr2 = deltaR2(jet, oldjet);
116  if (dr2 <= dRcone_ * dRcone_) {
117  icalo = i;
118  }
119  i++;
120  } // Calojets
121  if (icalo < 0)
122  continue;
123  auto const& mycalo = addjets_h[icalo];
124  std::vector<edm::Ptr<reco::Track> > tracksinjet = jet.tracks();
125  reco::TrackRefVector tracksincalo;
126  reco::TrackRefVector tracksinvert;
127  for (auto const& itrack : tracksinjet) {
128  for (auto const& ixtrp : iExtrapolations) {
129  if (ixtrp.positions().empty())
130  continue;
131  if (usePAT_) {
132  double mydphi = deltaPhi(ixtrp.track()->phi(), itrack->phi());
133  if (fabs(ixtrp.track()->pt() - itrack->pt()) > 0.001 || fabs(ixtrp.track()->eta() - itrack->eta()) > 0.001 ||
134  mydphi > 0.001)
135  continue;
136  } else {
137  if (itrack.id() != ixtrp.track().id() || itrack.key() != ixtrp.track().key())
138  continue;
139  }
140  tracksinvert.push_back(ixtrp.track());
141  reco::TrackBase::Point const& point = ixtrp.positions().at(0);
142  double dr2 = deltaR2(jet, point);
143  if (dr2 <= dRcone_ * dRcone_) {
144  tracksincalo.push_back(ixtrp.track());
145  }
146  } // Track extrapolations
147  } // tracks
148 
149  const reco::TrackJet& corrected = jet;
151  jpt::MatchedTracks pions;
154 
155  scaleJPT =
156  mJPTalgo->correction(corrected, mycalo, iEvent, iSetup, tracksinvert, tracksincalo, p4, pions, muons, elecs);
157  if (p4.pt() > ptCUT_) {
158  reco::JPTJet::Specific jptspe;
159  jptspe.pionsInVertexInCalo = pions.inVertexInCalo_;
162  jptspe.muonsInVertexInCalo = muons.inVertexInCalo_;
163  jptspe.muonsInVertexOutCalo = muons.inVertexOutOfCalo_;
164  jptspe.muonsOutVertexInCalo = muons.outOfVertexInCalo_;
165  jptspe.elecsInVertexInCalo = elecs.inVertexInCalo_;
166  jptspe.elecsInVertexOutCalo = elecs.inVertexOutOfCalo_;
167  jptspe.elecsOutVertexInCalo = elecs.outOfVertexInCalo_;
168  reco::CaloJetRef myjet(pOut1RefProd, idxCaloJet++);
170  jptspe.JPTSeed = 1;
171  reco::JPTJet fJet(p4, jet.primaryVertex()->position(), jptspe, mycalo.getJetConstituents());
172  pOut->push_back(fJet);
173  pOut1->push_back(mycalo);
174  }
175  } // trackjets
176 
177  int iJet = 0;
178  for (auto const& oldjet : jets_h) {
179  reco::CaloJet corrected = oldjet;
180 
181  // ZSP corrections
182  double factorZSP = 1.;
183  if (useZSP_)
184  factorZSP = mZSPalgo->correction(corrected, iEvent, iSetup);
185  corrected.scaleEnergy(factorZSP);
186 
187  // JPT corrections
188  scaleJPT = 1.;
189 
191 
192  jpt::MatchedTracks pions;
195  bool validMatches = false;
196 
197  if (!vectorial_) {
198  scaleJPT = mJPTalgo->correction(corrected, oldjet, iEvent, iSetup, pions, muons, elecs, validMatches);
199  p4 = math::XYZTLorentzVector(corrected.px() * scaleJPT,
200  corrected.py() * scaleJPT,
201  corrected.pz() * scaleJPT,
202  corrected.energy() * scaleJPT);
203  } else {
204  scaleJPT = mJPTalgo->correction(corrected, oldjet, iEvent, iSetup, p4, pions, muons, elecs, validMatches);
205  }
206 
208 
209  if (validMatches) {
210  specific.pionsInVertexInCalo = pions.inVertexInCalo_;
211  specific.pionsInVertexOutCalo = pions.inVertexOutOfCalo_;
212  specific.pionsOutVertexInCalo = pions.outOfVertexInCalo_;
213  specific.muonsInVertexInCalo = muons.inVertexInCalo_;
214  specific.muonsInVertexOutCalo = muons.inVertexOutOfCalo_;
215  specific.muonsOutVertexInCalo = muons.outOfVertexInCalo_;
216  specific.elecsInVertexInCalo = elecs.inVertexInCalo_;
217  specific.elecsInVertexOutCalo = elecs.inVertexOutOfCalo_;
218  specific.elecsOutVertexInCalo = elecs.outOfVertexInCalo_;
219  }
220 
221  // Fill JPT Specific
222  specific.theCaloJetRef = edm::RefToBase<reco::Jet>(jets_h.refAt(iJet));
223  specific.mResponseOfChargedWithEff = (float)mJPTalgo->getResponseOfChargedWithEff();
224  specific.mResponseOfChargedWithoutEff = (float)mJPTalgo->getResponseOfChargedWithoutEff();
225  specific.mSumPtOfChargedWithEff = (float)mJPTalgo->getSumPtWithEff();
226  specific.mSumPtOfChargedWithoutEff = (float)mJPTalgo->getSumPtWithoutEff();
227  specific.mSumEnergyOfChargedWithEff = (float)mJPTalgo->getSumEnergyWithEff();
228  specific.mSumEnergyOfChargedWithoutEff = (float)mJPTalgo->getSumEnergyWithoutEff();
229  specific.mChargedHadronEnergy = (float)mJPTalgo->getSumEnergyWithoutEff();
230 
231  // Fill Charged Jet shape parameters
232 
233  double deR2Tr = 0.;
234  double deEta2Tr = 0.;
235  double dePhi2Tr = 0.;
236  double Zch = 0.;
237  double Pout2 = 0.;
238  double Pout = 0.;
239  double denominator_tracks = 0.;
240  int ntracks = 0;
241 
243  it++) {
244  double deR = deltaR((*it)->eta(), (*it)->phi(), p4.eta(), p4.phi());
245  double deEta = (*it)->eta() - p4.eta();
246  double dePhi = deltaPhi((*it)->phi(), p4.phi());
247  if ((**it).ptError() / (**it).pt() < 0.1) {
248  deR2Tr = deR2Tr + deR * deR * (*it)->pt();
249  deEta2Tr = deEta2Tr + deEta * deEta * (*it)->pt();
250  dePhi2Tr = dePhi2Tr + dePhi * dePhi * (*it)->pt();
251  denominator_tracks = denominator_tracks + (*it)->pt();
252  Zch = Zch + (*it)->pt();
253 
254  Pout2 = Pout2 + (**it).p() * (**it).p() - (Zch * p4.P()) * (Zch * p4.P());
255  ntracks++;
256  }
257  }
258  for (reco::TrackRefVector::const_iterator it = muons.inVertexInCalo_.begin(); it != muons.inVertexInCalo_.end();
259  it++) {
260  double deR = deltaR((*it)->eta(), (*it)->phi(), p4.eta(), p4.phi());
261  double deEta = (*it)->eta() - p4.eta();
262  double dePhi = deltaPhi((*it)->phi(), p4.phi());
263  if ((**it).ptError() / (**it).pt() < 0.1) {
264  deR2Tr = deR2Tr + deR * deR * (*it)->pt();
265  deEta2Tr = deEta2Tr + deEta * deEta * (*it)->pt();
266  dePhi2Tr = dePhi2Tr + dePhi * dePhi * (*it)->pt();
267  denominator_tracks = denominator_tracks + (*it)->pt();
268  Zch = Zch + (*it)->pt();
269 
270  Pout2 = Pout2 + (**it).p() * (**it).p() - (Zch * p4.P()) * (Zch * p4.P());
271  ntracks++;
272  }
273  }
274  for (reco::TrackRefVector::const_iterator it = elecs.inVertexInCalo_.begin(); it != elecs.inVertexInCalo_.end();
275  it++) {
276  double deR = deltaR((*it)->eta(), (*it)->phi(), p4.eta(), p4.phi());
277  double deEta = (*it)->eta() - p4.eta();
278  double dePhi = deltaPhi((*it)->phi(), p4.phi());
279  if ((**it).ptError() / (**it).pt() < 0.1) {
280  deR2Tr = deR2Tr + deR * deR * (*it)->pt();
281  deEta2Tr = deEta2Tr + deEta * deEta * (*it)->pt();
282  dePhi2Tr = dePhi2Tr + dePhi * dePhi * (*it)->pt();
283  denominator_tracks = denominator_tracks + (*it)->pt();
284  Zch = Zch + (*it)->pt();
285 
286  Pout2 = Pout2 + (**it).p() * (**it).p() - (Zch * p4.P()) * (Zch * p4.P());
287  ntracks++;
288  }
289  }
290 
292  it != pions.inVertexOutOfCalo_.end();
293  it++) {
294  Zch = Zch + (*it)->pt();
295  }
296  for (reco::TrackRefVector::const_iterator it = muons.inVertexOutOfCalo_.begin();
297  it != muons.inVertexOutOfCalo_.end();
298  it++) {
299  Zch = Zch + (*it)->pt();
300  }
301  for (reco::TrackRefVector::const_iterator it = elecs.inVertexOutOfCalo_.begin();
302  it != elecs.inVertexOutOfCalo_.end();
303  it++) {
304  Zch = Zch + (*it)->pt();
305  }
306 
307  if (mJPTalgo->getSumPtForBeta() > 0.)
308  Zch = Zch / mJPTalgo->getSumPtForBeta();
309 
310  if (ntracks > 0) {
311  Pout = sqrt(fabs(Pout2)) / ntracks;
312  }
313  if (denominator_tracks != 0) {
314  deR2Tr = deR2Tr / denominator_tracks;
315  deEta2Tr = deEta2Tr / denominator_tracks;
316  dePhi2Tr = dePhi2Tr / denominator_tracks;
317  }
318 
319  specific.R2momtr = deR2Tr;
320  specific.Eta2momtr = deEta2Tr;
321  specific.Phi2momtr = dePhi2Tr;
322  specific.Pout = Pout;
323  specific.Zch = Zch;
324 
325  // Create JPT jet
326  reco::Particle::Point vertex_ = reco::Jet::Point(0, 0, 0);
327 
328  // If we add primary vertex
330  iEvent.getByToken(input_vertex_token_, pvCollection);
331  if (pvCollection.isValid() && !pvCollection->empty())
332  vertex_ = pvCollection->begin()->position();
333 
334  reco::JPTJet fJet(p4, vertex_, specific, corrected.getJetConstituents());
335  iJet++;
336 
337  // Output module
338  if (fJet.pt() > ptCUT_)
339  pOut->push_back(fJet);
340  }
341  std::sort(pOut->begin(), pOut->end(), sort_by_pt);
342  iEvent.put(std::move(pOut1));
343  iEvent.put(std::move(pOut));
344 }
345 
346 //define this as a plug-in
347 //DEFINE_FWK_MODULE(JetPlusTrackProducer);
reco::TrackRefVector muonsInVertexOutCalo
Definition: JPTJet.h:51
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
std::remove_cv< typename std::remove_reference< argument_type >::type >::type key_type
Definition: Ref.h:164
double pz() const final
z coordinate of momentum vector
Jets made from CaloTowers.
Definition: CaloJet.h:27
reco::TrackRefVector muonsInVertexInCalo
Definition: JPTJet.h:50
virtual void scaleEnergy(double fScale)
scale energy of the jet
reco::TrackRefVector inVertexInCalo_
reco::TrackRefVector muonsOutVertexInCalo
Definition: JPTJet.h:52
reco::TrackRefVector inVertexOutOfCalo_
void produce(edm::Event &, const edm::EventSetup &) override
reco::TrackRefVector elecsOutVertexInCalo
Definition: JPTJet.h:55
reco::TrackRefVector pionsInVertexOutCalo
Definition: JPTJet.h:48
T getUntrackedParameter(std::string const &, T const &) const
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
virtual Constituents getJetConstituents() const
list of constituents
double px() const final
x coordinate of momentum vector
int iEvent
Definition: GenABIO.cc:224
T sqrt(T t)
Definition: SSEVec.h:19
Jets made from CaloJets corrected for ZSP and tracks.
Definition: JPTJet.h:28
reco::TrackRefVector pionsOutVertexInCalo
Definition: JPTJet.h:49
math::XYZPoint Point
point in the space
Definition: Particle.h:25
bool sort_by_pt(const reco::JPTJet &a, const reco::JPTJet &b)
reco::TrackRefVector outOfVertexInCalo_
reco::TrackRefVector elecsInVertexInCalo
Definition: JPTJet.h:53
math::XYZPoint Point
point in the space
Definition: TrackBase.h:80
double py() const final
y coordinate of momentum vector
Jets made out of tracks.
Definition: TrackJet.h:24
edm::RefToBase< reco::Jet > theCaloJetRef
Definition: JPTJet.h:46
JetPlusTrackProducer(const edm::ParameterSet &)
reco::TrackRefVector pionsInVertexInCalo
Definition: JPTJet.h:47
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:228
double b
Definition: hdecay.h:120
reco::TrackRefVector elecsInVertexOutCalo
Definition: JPTJet.h:54
Particles matched to tracks that are in/in, in/out, out/in at Vertex and CaloFace.
HLT enums.
Jet energy correction algorithm using tracks.
double a
Definition: hdecay.h:121
void push_back(value_type const &ref)
Add a Ref<C, T> to the RefVector.
Definition: RefVector.h:67
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:223
def move(src, dest)
Definition: eostools.py:511
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5
std::vector< CaloJet > CaloJetCollection
collection of CaloJet objects
math::XYZPoint Point
point in the space
Definition: LeafCandidate.h:27
double energy() const final
energy