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  for (auto const& jet : iEvent.get(input_trackjets_token_)) {
111  int icalo = -1;
112  int i = 0;
113  for (auto const& oldjet : addjets_h) {
114  double dr2 = deltaR2(jet, oldjet);
115  if (dr2 <= dRcone_ * dRcone_) {
116  icalo = i;
117  }
118  i++;
119  } // Calojets
120  if (icalo < 0)
121  continue;
122  auto const& mycalo = addjets_h[icalo];
123  std::vector<edm::Ptr<reco::Track> > tracksinjet = jet.tracks();
124  reco::TrackRefVector tracksincalo;
125  reco::TrackRefVector tracksinvert;
126  for (auto const& itrack : tracksinjet) {
127  for (auto const& ixtrp : iExtrapolations) {
128  if (ixtrp.positions().empty())
129  continue;
130  if (usePAT_) {
131  double mydphi = deltaPhi(ixtrp.track()->phi(), itrack->phi());
132  if (fabs(ixtrp.track()->pt() - itrack->pt()) > 0.001 || fabs(ixtrp.track()->eta() - itrack->eta()) > 0.001 ||
133  mydphi > 0.001)
134  continue;
135  } else {
136  if (itrack.id() != ixtrp.track().id() || itrack.key() != ixtrp.track().key())
137  continue;
138  }
139  tracksinvert.push_back(ixtrp.track());
140  reco::TrackBase::Point const& point = ixtrp.positions().at(0);
141  double dr2 = deltaR2(jet, point);
142  if (dr2 <= dRcone_ * dRcone_) {
143  tracksincalo.push_back(ixtrp.track());
144  }
145  } // Track extrapolations
146  } // tracks
147 
148  const reco::TrackJet& corrected = jet;
150  jpt::MatchedTracks pions;
153 
154  mJPTalgo->correction(corrected, mycalo, iEvent, iSetup, tracksinvert, tracksincalo, p4, pions, muons, elecs);
155  if (p4.pt() > ptCUT_) {
156  reco::JPTJet::Specific jptspe;
157  jptspe.pionsInVertexInCalo = pions.inVertexInCalo_;
160  jptspe.muonsInVertexInCalo = muons.inVertexInCalo_;
161  jptspe.muonsInVertexOutCalo = muons.inVertexOutOfCalo_;
162  jptspe.muonsOutVertexInCalo = muons.outOfVertexInCalo_;
163  jptspe.elecsInVertexInCalo = elecs.inVertexInCalo_;
164  jptspe.elecsInVertexOutCalo = elecs.inVertexOutOfCalo_;
165  jptspe.elecsOutVertexInCalo = elecs.outOfVertexInCalo_;
166  reco::CaloJetRef myjet(pOut1RefProd, idxCaloJet++);
168  jptspe.JPTSeed = 1;
169  reco::JPTJet fJet(p4, jet.primaryVertex()->position(), jptspe, mycalo.getJetConstituents());
170  pOut->push_back(fJet);
171  pOut1->push_back(mycalo);
172  }
173  } // trackjets
174 
175  int iJet = 0;
176  for (auto const& oldjet : jets_h) {
177  reco::CaloJet corrected = oldjet;
178 
179  // ZSP corrections
180  double factorZSP = 1.;
181  if (useZSP_)
182  factorZSP = mZSPalgo->correction(corrected, iEvent, iSetup);
183  corrected.scaleEnergy(factorZSP);
184 
186 
187  jpt::MatchedTracks pions;
190  bool validMatches = false;
191 
192  if (!vectorial_) {
193  double scaleJPT = mJPTalgo->correction(corrected, oldjet, iEvent, iSetup, pions, muons, elecs, validMatches);
194  p4 = math::XYZTLorentzVector(corrected.px() * scaleJPT,
195  corrected.py() * scaleJPT,
196  corrected.pz() * scaleJPT,
197  corrected.energy() * scaleJPT);
198  } else {
199  mJPTalgo->correction(corrected, oldjet, iEvent, iSetup, p4, pions, muons, elecs, validMatches);
200  }
201 
203 
204  if (validMatches) {
205  specific.pionsInVertexInCalo = pions.inVertexInCalo_;
206  specific.pionsInVertexOutCalo = pions.inVertexOutOfCalo_;
207  specific.pionsOutVertexInCalo = pions.outOfVertexInCalo_;
208  specific.muonsInVertexInCalo = muons.inVertexInCalo_;
209  specific.muonsInVertexOutCalo = muons.inVertexOutOfCalo_;
210  specific.muonsOutVertexInCalo = muons.outOfVertexInCalo_;
211  specific.elecsInVertexInCalo = elecs.inVertexInCalo_;
212  specific.elecsInVertexOutCalo = elecs.inVertexOutOfCalo_;
213  specific.elecsOutVertexInCalo = elecs.outOfVertexInCalo_;
214  }
215 
216  // Fill JPT Specific
217  specific.theCaloJetRef = edm::RefToBase<reco::Jet>(jets_h.refAt(iJet));
218  specific.mResponseOfChargedWithEff = (float)mJPTalgo->getResponseOfChargedWithEff();
219  specific.mResponseOfChargedWithoutEff = (float)mJPTalgo->getResponseOfChargedWithoutEff();
220  specific.mSumPtOfChargedWithEff = (float)mJPTalgo->getSumPtWithEff();
221  specific.mSumPtOfChargedWithoutEff = (float)mJPTalgo->getSumPtWithoutEff();
222  specific.mSumEnergyOfChargedWithEff = (float)mJPTalgo->getSumEnergyWithEff();
223  specific.mSumEnergyOfChargedWithoutEff = (float)mJPTalgo->getSumEnergyWithoutEff();
224  specific.mChargedHadronEnergy = (float)mJPTalgo->getSumEnergyWithoutEff();
225 
226  // Fill Charged Jet shape parameters
227 
228  double deR2Tr = 0.;
229  double deEta2Tr = 0.;
230  double dePhi2Tr = 0.;
231  double Zch = 0.;
232  double Pout2 = 0.;
233  double Pout = 0.;
234  double denominator_tracks = 0.;
235  int ntracks = 0;
236 
238  it++) {
239  double deR = deltaR((*it)->eta(), (*it)->phi(), p4.eta(), p4.phi());
240  double deEta = (*it)->eta() - p4.eta();
241  double dePhi = deltaPhi((*it)->phi(), p4.phi());
242  if ((**it).ptError() / (**it).pt() < 0.1) {
243  deR2Tr = deR2Tr + deR * deR * (*it)->pt();
244  deEta2Tr = deEta2Tr + deEta * deEta * (*it)->pt();
245  dePhi2Tr = dePhi2Tr + dePhi * dePhi * (*it)->pt();
246  denominator_tracks = denominator_tracks + (*it)->pt();
247  Zch = Zch + (*it)->pt();
248 
249  Pout2 = Pout2 + (**it).p() * (**it).p() - (Zch * p4.P()) * (Zch * p4.P());
250  ntracks++;
251  }
252  }
253  for (reco::TrackRefVector::const_iterator it = muons.inVertexInCalo_.begin(); it != muons.inVertexInCalo_.end();
254  it++) {
255  double deR = deltaR((*it)->eta(), (*it)->phi(), p4.eta(), p4.phi());
256  double deEta = (*it)->eta() - p4.eta();
257  double dePhi = deltaPhi((*it)->phi(), p4.phi());
258  if ((**it).ptError() / (**it).pt() < 0.1) {
259  deR2Tr = deR2Tr + deR * deR * (*it)->pt();
260  deEta2Tr = deEta2Tr + deEta * deEta * (*it)->pt();
261  dePhi2Tr = dePhi2Tr + dePhi * dePhi * (*it)->pt();
262  denominator_tracks = denominator_tracks + (*it)->pt();
263  Zch = Zch + (*it)->pt();
264 
265  Pout2 = Pout2 + (**it).p() * (**it).p() - (Zch * p4.P()) * (Zch * p4.P());
266  ntracks++;
267  }
268  }
269  for (reco::TrackRefVector::const_iterator it = elecs.inVertexInCalo_.begin(); it != elecs.inVertexInCalo_.end();
270  it++) {
271  double deR = deltaR((*it)->eta(), (*it)->phi(), p4.eta(), p4.phi());
272  double deEta = (*it)->eta() - p4.eta();
273  double dePhi = deltaPhi((*it)->phi(), p4.phi());
274  if ((**it).ptError() / (**it).pt() < 0.1) {
275  deR2Tr = deR2Tr + deR * deR * (*it)->pt();
276  deEta2Tr = deEta2Tr + deEta * deEta * (*it)->pt();
277  dePhi2Tr = dePhi2Tr + dePhi * dePhi * (*it)->pt();
278  denominator_tracks = denominator_tracks + (*it)->pt();
279  Zch = Zch + (*it)->pt();
280 
281  Pout2 = Pout2 + (**it).p() * (**it).p() - (Zch * p4.P()) * (Zch * p4.P());
282  ntracks++;
283  }
284  }
285 
287  it != pions.inVertexOutOfCalo_.end();
288  it++) {
289  Zch = Zch + (*it)->pt();
290  }
291  for (reco::TrackRefVector::const_iterator it = muons.inVertexOutOfCalo_.begin();
292  it != muons.inVertexOutOfCalo_.end();
293  it++) {
294  Zch = Zch + (*it)->pt();
295  }
296  for (reco::TrackRefVector::const_iterator it = elecs.inVertexOutOfCalo_.begin();
297  it != elecs.inVertexOutOfCalo_.end();
298  it++) {
299  Zch = Zch + (*it)->pt();
300  }
301 
302  if (mJPTalgo->getSumPtForBeta() > 0.)
303  Zch = Zch / mJPTalgo->getSumPtForBeta();
304 
305  if (ntracks > 0) {
306  Pout = sqrt(fabs(Pout2)) / ntracks;
307  }
308  if (denominator_tracks != 0) {
309  deR2Tr = deR2Tr / denominator_tracks;
310  deEta2Tr = deEta2Tr / denominator_tracks;
311  dePhi2Tr = dePhi2Tr / denominator_tracks;
312  }
313 
314  specific.R2momtr = deR2Tr;
315  specific.Eta2momtr = deEta2Tr;
316  specific.Phi2momtr = dePhi2Tr;
317  specific.Pout = Pout;
318  specific.Zch = Zch;
319 
320  // Create JPT jet
321  reco::Particle::Point vertex_ = reco::Jet::Point(0, 0, 0);
322 
323  // If we add primary vertex
325  iEvent.getByToken(input_vertex_token_, pvCollection);
326  if (pvCollection.isValid() && !pvCollection->empty())
327  vertex_ = pvCollection->begin()->position();
328 
329  reco::JPTJet fJet(p4, vertex_, specific, corrected.getJetConstituents());
330  iJet++;
331 
332  // Output module
333  if (fJet.pt() > ptCUT_)
334  pOut->push_back(fJet);
335  }
336  std::sort(pOut->begin(), pOut->end(), sort_by_pt);
337  iEvent.put(std::move(pOut1));
338  iEvent.put(std::move(pOut));
339 }
340 
341 //define this as a plug-in
342 //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:158
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
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
Definition: DiMuonV_cfg.py:214
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:23
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