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