CMS 3D CMS Logo

JetPlusTrackProducerAA.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: JetPlusTrack
4 // Class: JetPlusTrack
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
27 
29 
42 
43 //=>
58 //=>
59 
60 #include <string>
61 
62 using namespace std;
63 using namespace jpt;
64 
65 //
66 // constants, enums and typedefs
67 //
68 
69 //
70 // static data member definitions
71 //
72 
73 //
74 // constructors and destructor
75 //
77  //register your products
78  src = iConfig.getParameter<edm::InputTag>("src");
79  alias = iConfig.getUntrackedParameter<string>("alias");
80  mTracks = iConfig.getParameter<edm::InputTag>("tracks");
81  srcPVs_ = iConfig.getParameter<edm::InputTag>("srcPVs");
82  vectorial_ = iConfig.getParameter<bool>("VectorialCorrection");
83  useZSP = iConfig.getParameter<bool>("UseZSP");
84  std::string tq = iConfig.getParameter<std::string>("TrackQuality");
85  trackQuality_ = reco::TrackBase::qualityByName(tq);
86  mConeSize = iConfig.getParameter<double>("coneSize");
87  //=>
88  mExtrapolations = iConfig.getParameter<edm::InputTag>("extrapolations");
89  //=>
90  mJPTalgo = new JetPlusTrackCorrector(iConfig, consumesCollector());
91  if (useZSP)
92  mZSPalgo = new ZSPJPTJetCorrector(iConfig);
93 
94  produces<reco::JPTJetCollection>().setBranchAlias(alias);
95 
96  input_jets_token_ = consumes<edm::View<reco::CaloJet> >(src);
97  input_vertex_token_ = consumes<reco::VertexCollection>(srcPVs_);
98  input_tracks_token_ = consumes<reco::TrackCollection>(mTracks);
99  input_extrapolations_token_ = consumes<std::vector<reco::TrackExtrapolation> >(mExtrapolations);
100 }
101 
103  // do anything here that needs to be done at desctruction time
104  // (e.g. close files, deallocate resources etc.)
105 }
106 
107 //
108 // member functions
109 //
110 
111 // ------------ method called to produce the data ------------
113  using namespace edm;
114 
115  // get stuff from Event
117  iEvent.getByToken(input_jets_token_, jets_h);
118 
120  iEvent.getByToken(input_tracks_token_, tracks_h);
121 
122  std::vector<reco::TrackRef> fTracks;
123  fTracks.reserve(tracks_h->size());
124  for (unsigned i = 0; i < tracks_h->size(); ++i) {
125  fTracks.push_back(reco::TrackRef(tracks_h, i));
126  }
127 
129  iEvent.getByToken(input_extrapolations_token_, extrapolations_h);
130 
131  auto pOut = std::make_unique<reco::JPTJetCollection>();
132 
133  reco::JPTJetCollection tmpColl;
134 
135  for (unsigned i = 0; i < jets_h->size(); ++i) {
136  const reco::CaloJet* oldjet = &(*(jets_h->refAt(i)));
137 
138  reco::CaloJet corrected = *oldjet;
139 
140  // ZSP corrections
141 
142  double factorZSP = 1.;
143  if (useZSP)
144  factorZSP = mZSPalgo->correction(corrected, iEvent, iSetup);
145 
146  corrected.scaleEnergy(factorZSP);
147 
148  // JPT corrections
149 
150  double scaleJPT = 1.;
151 
153 
154  // Construct JPTJet constituent
155  jpt::MatchedTracks pions;
158  bool ok = false;
159 
160  if (!vectorial_) {
161  scaleJPT = mJPTalgo->correction(corrected, *oldjet, iEvent, iSetup, pions, muons, elecs, ok);
162  p4 = math::XYZTLorentzVector(corrected.px() * scaleJPT,
163  corrected.py() * scaleJPT,
164  corrected.pz() * scaleJPT,
165  corrected.energy() * scaleJPT);
166  } else {
167  scaleJPT = mJPTalgo->correction(corrected, *oldjet, iEvent, iSetup, p4, pions, muons, elecs, ok);
168  }
169 
171 
172  if (ok) {
173  specific.pionsInVertexInCalo = pions.inVertexInCalo_;
174  specific.pionsInVertexOutCalo = pions.inVertexOutOfCalo_;
175  specific.pionsOutVertexInCalo = pions.outOfVertexInCalo_;
176  specific.muonsInVertexInCalo = muons.inVertexInCalo_;
177  specific.muonsInVertexOutCalo = muons.inVertexOutOfCalo_;
178  specific.muonsOutVertexInCalo = muons.outOfVertexInCalo_;
179  specific.elecsInVertexInCalo = elecs.inVertexInCalo_;
180  specific.elecsInVertexOutCalo = elecs.inVertexOutOfCalo_;
181  specific.elecsOutVertexInCalo = elecs.outOfVertexInCalo_;
182  }
183 
184  // Fill JPT Specific
185  edm::RefToBase<reco::Jet> myjet = (edm::RefToBase<reco::Jet>)jets_h->refAt(i);
186  specific.theCaloJetRef = myjet;
187  specific.mZSPCor = factorZSP;
188  specific.mResponseOfChargedWithEff = (float)mJPTalgo->getResponseOfChargedWithEff();
189  specific.mResponseOfChargedWithoutEff = (float)mJPTalgo->getResponseOfChargedWithoutEff();
190  specific.mSumPtOfChargedWithEff = (float)mJPTalgo->getSumPtWithEff();
191  specific.mSumPtOfChargedWithoutEff = (float)mJPTalgo->getSumPtWithoutEff();
192  specific.mSumEnergyOfChargedWithEff = (float)mJPTalgo->getSumEnergyWithEff();
193  specific.mSumEnergyOfChargedWithoutEff = (float)mJPTalgo->getSumEnergyWithoutEff();
194  specific.mChargedHadronEnergy = (float)mJPTalgo->getSumEnergyWithoutEff();
195  // Fill Charged Jet shape parameters
196  double deR2Tr = 0.;
197  double deEta2Tr = 0.;
198  double dePhi2Tr = 0.;
199  double Zch = 0.;
200  double Pout2 = 0.;
201  double Pout = 0.;
202  double denominator_tracks = 0.;
203  int ntracks = 0;
204 
206  it++) {
207  double deR = deltaR((*it)->eta(), (*it)->phi(), p4.eta(), p4.phi());
208  double deEta = (*it)->eta() - p4.eta();
209  double dePhi = deltaPhi((*it)->phi(), p4.phi());
210  if ((**it).ptError() / (**it).pt() < 0.1) {
211  deR2Tr = deR2Tr + deR * deR * (*it)->pt();
212  deEta2Tr = deEta2Tr + deEta * deEta * (*it)->pt();
213  dePhi2Tr = dePhi2Tr + dePhi * dePhi * (*it)->pt();
214  denominator_tracks = denominator_tracks + (*it)->pt();
215  Zch = Zch + (*it)->pt();
216 
217  Pout2 = Pout2 + (**it).p() * (**it).p() - (Zch * p4.P()) * (Zch * p4.P());
218  ntracks++;
219  }
220  }
221  for (reco::TrackRefVector::const_iterator it = muons.inVertexInCalo_.begin(); it != muons.inVertexInCalo_.end();
222  it++) {
223  double deR = deltaR((*it)->eta(), (*it)->phi(), p4.eta(), p4.phi());
224  double deEta = (*it)->eta() - p4.eta();
225  double dePhi = deltaPhi((*it)->phi(), p4.phi());
226  if ((**it).ptError() / (**it).pt() < 0.1) {
227  deR2Tr = deR2Tr + deR * deR * (*it)->pt();
228  deEta2Tr = deEta2Tr + deEta * deEta * (*it)->pt();
229  dePhi2Tr = dePhi2Tr + dePhi * dePhi * (*it)->pt();
230  denominator_tracks = denominator_tracks + (*it)->pt();
231  Zch = Zch + (*it)->pt();
232 
233  Pout2 = Pout2 + (**it).p() * (**it).p() - (Zch * p4.P()) * (Zch * p4.P());
234  ntracks++;
235  }
236  }
237  for (reco::TrackRefVector::const_iterator it = elecs.inVertexInCalo_.begin(); it != elecs.inVertexInCalo_.end();
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  }
254  it != pions.inVertexOutOfCalo_.end();
255  it++) {
256  Zch = Zch + (*it)->pt();
257  }
258  for (reco::TrackRefVector::const_iterator it = muons.inVertexOutOfCalo_.begin();
259  it != muons.inVertexOutOfCalo_.end();
260  it++) {
261  Zch = Zch + (*it)->pt();
262  }
263  for (reco::TrackRefVector::const_iterator it = elecs.inVertexOutOfCalo_.begin();
264  it != elecs.inVertexOutOfCalo_.end();
265  it++) {
266  Zch = Zch + (*it)->pt();
267  }
268 
269  if (mJPTalgo->getSumPtForBeta() > 0.)
270  Zch = Zch / mJPTalgo->getSumPtForBeta();
271 
272  if (ntracks > 0) {
273  Pout = sqrt(fabs(Pout2)) / ntracks;
274  }
275 
276  if (denominator_tracks != 0) {
277  deR2Tr = deR2Tr / denominator_tracks;
278  deEta2Tr = deEta2Tr / denominator_tracks;
279  dePhi2Tr = dePhi2Tr / denominator_tracks;
280  }
281 
282  specific.R2momtr = deR2Tr;
283  specific.Eta2momtr = deEta2Tr;
284  specific.Phi2momtr = dePhi2Tr;
285  specific.Pout = Pout;
286  specific.Zch = Zch;
287 
288  // Create JPT jet
289 
290  reco::Particle::Point vertex_ = reco::Jet::Point(0, 0, 0);
291 
292  // If we add primary vertex
294  iEvent.getByToken(input_vertex_token_, pvCollection);
295  if (pvCollection.isValid() && !pvCollection->empty())
296  vertex_ = pvCollection->begin()->position();
297 
298  reco::JPTJet fJet(p4, vertex_, specific, corrected.getJetConstituents());
299  // fJet.printJet();
300 
301  // Temporarily collection before correction for background
302 
303  tmpColl.push_back(fJet);
304  }
305 
306  //=======================================================================================================>
307  // Correction for background
308 
309  reco::TrackRefVector trBgOutOfCalo;
310  reco::TrackRefVector trBgOutOfVertex = calculateBGtracksJet(tmpColl, fTracks, extrapolations_h, trBgOutOfCalo);
311 
312  //===> Area without Jets
313  std::map<reco::JPTJetCollection::iterator, double> AreaNonJet;
314 
315  for (reco::JPTJetCollection::iterator ij1 = tmpColl.begin(); ij1 != tmpColl.end(); ij1++) {
316  int nj1 = 1;
317  for (reco::JPTJetCollection::iterator ij2 = tmpColl.begin(); ij2 != tmpColl.end(); ij2++) {
318  if (ij2 == ij1)
319  continue;
320  if (fabs((*ij1).eta() - (*ij2).eta()) > 0.5)
321  continue;
322  nj1++;
323  }
324 
325  AreaNonJet[ij1] = 4 * M_PI * mConeSize - nj1 * 4 * mConeSize * mConeSize;
326  }
327 
328  //===>
329 
330  for (reco::JPTJetCollection::iterator ij = tmpColl.begin(); ij != tmpColl.end(); ij++) {
331  // Correct JPTjet for background tracks
332 
333  const reco::TrackRefVector pioninin = (*ij).getPionsInVertexInCalo();
334  const reco::TrackRefVector pioninout = (*ij).getPionsInVertexOutCalo();
335 
336  double ja = (AreaNonJet.find(ij))->second;
337 
338  double factorPU = mJPTalgo->correctAA(*ij, trBgOutOfVertex, mConeSize, pioninin, pioninout, ja, trBgOutOfCalo);
339 
340  (*ij).scaleEnergy(factorPU);
341 
342  // Output module
343  pOut->push_back(*ij);
344  }
345 
346  iEvent.put(std::move(pOut));
347 }
348 // -----------------------------------------------
349 // ------------ calculateBGtracksJet ------------
350 // ------------ Tracks not included in jets ------
351 // -----------------------------------------------
353  reco::JPTJetCollection& fJets,
354  std::vector<reco::TrackRef>& fTracks,
355  edm::Handle<std::vector<reco::TrackExtrapolation> >& extrapolations_h,
356  reco::TrackRefVector& trBgOutOfCalo) {
357  reco::TrackRefVector trBgOutOfVertex;
358 
359  for (unsigned t = 0; t < fTracks.size(); ++t) {
360  int track_bg = 0;
361 
362  const reco::Track* track = &*(fTracks[t]);
363  double trackEta = track->eta();
364  double trackPhi = track->phi();
365 
366  //loop on jets
367  for (unsigned j = 0; j < fJets.size(); ++j) {
368  const reco::Jet* jet = &(fJets[j]);
369  double jetEta = jet->eta();
370  double jetPhi = jet->phi();
371 
372  if (fabs(jetEta - trackEta) < mConeSize) {
373  double dphiTrackJet = deltaPhi(trackPhi, jetPhi);
374  if (dphiTrackJet < mConeSize) {
375  track_bg = 1;
376  }
377  }
378  } //jets
379 
380  if (track_bg == 0) {
381  trBgOutOfVertex.push_back(fTracks[t]);
382  }
383 
384  } //tracks
385 
386  //=====> Propagate BG tracks to calo
387  int nValid = 0;
388  for (std::vector<reco::TrackExtrapolation>::const_iterator xtrpBegin = extrapolations_h->begin(),
389  xtrpEnd = extrapolations_h->end(),
390  ixtrp = xtrpBegin;
391  ixtrp != xtrpEnd;
392  ++ixtrp) {
393  nValid++;
394 
395  reco::TrackRefVector::iterator it = find(trBgOutOfVertex.begin(), trBgOutOfVertex.end(), (*ixtrp).track());
396 
397  if (it != trBgOutOfVertex.end()) {
398  trBgOutOfCalo.push_back(*it);
399  }
400  }
401 
402  return trBgOutOfVertex;
403 }
404 
405 //define this as a plug-in
406 //DEFINE_FWK_MODULE(JetPlusTrackProducerAA);
reco::JPTJet
Jets made from CaloJets corrected for ZSP and tracks.
Definition: JPTJet.h:28
Propagator.h
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
CaloJetCollection.h
reco::CaloJet
Jets made from CaloTowers.
Definition: CaloJet.h:27
TrajectoryStateOnSurface.h
reco::Jet::scaleEnergy
virtual void scaleEnergy(double fScale)
scale energy of the jet
CaloJet.h
mps_fire.i
i
Definition: mps_fire.py:428
reco::Jet
Base class for all types of Jets.
Definition: Jet.h:20
FreeTrajectoryState.h
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11779
GlobalTrajectoryParameters.h
Cylinder.h
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
EDProducer.h
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
Jet.h
JetPlusTrackProducerAA::JetPlusTrackProducerAA
JetPlusTrackProducerAA(const edm::ParameterSet &)
Definition: JetPlusTrackProducerAA.cc:76
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
reco::btau::trackEta
Definition: TaggingVariable.h:42
edm::RefVector< TrackCollection >
vertices_cff.ntracks
ntracks
Definition: vertices_cff.py:34
jpt::MatchedTracks::inVertexInCalo_
reco::TrackRefVector inVertexInCalo_
Definition: JetPlusTrackCorrector.h:149
reco::JPTJetCollection
std::vector< JPTJet > JPTJetCollection
collection of CaloJet objects
Definition: JPTJetCollection.h:13
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
convertSQLiteXML.ok
bool ok
Definition: convertSQLiteXML.py:98
edm::Handle
Definition: AssociativeIterator.h:50
ZSPJPTJetCorrector
Definition: ZSPJPTJetCorrector.h:21
edm::Ref< TrackCollection >
jpt::MatchedTracks
Particles matched to tracks that are in/in, in/out, out/in at Vertex and CaloFace.
Definition: JetPlusTrackCorrector.h:144
Plane.h
MakerMacros.h
edm::RefVector::end
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:228
Track.h
TrackFwd.h
SiPixelRawToDigiRegional_cfi.deltaPhi
deltaPhi
Definition: SiPixelRawToDigiRegional_cfi.py:9
JetPlusTrackProducerAA::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: JetPlusTrackProducerAA.cc:112
reco::LeafCandidate::py
double py() const final
y coordinate of momentum vector
Definition: LeafCandidate.h:142
timingPdfMaker.specific
specific
Definition: timingPdfMaker.py:78
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
reco::Track
Definition: Track.h:27
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
JetTracksAssociationXtrpCalo.h
JPTJetCollection.h
reco::JPTJet::Specific
Definition: JPTJet.h:30
PbPb_ZMuSkimMuonDPG_cff.deltaR
deltaR
Definition: PbPb_ZMuSkimMuonDPG_cff.py:63
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
Vertex.h
EcalSubdetector.h
reco::btau::jetPhi
Definition: TaggingVariable.h:36
reco::btau::jetEta
Definition: TaggingVariable.h:34
CaloSubdetectorGeometry.h
edm::ParameterSet
Definition: ParameterSet.h:47
TrackRefitter_38T_cff.src
src
Definition: TrackRefitter_38T_cff.py:24
Event.h
JetPlusTrackCorrector
Jet energy correction algorithm using tracks.
Definition: JetPlusTrackCorrector.h:171
deltaR.h
reco::btau::trackPhi
Definition: TaggingVariable.h:43
iEvent
int iEvent
Definition: GenABIO.cc:224
p4
double p4[4]
Definition: TauolaWrapper.h:92
M_PI
#define M_PI
Definition: BXVectorInputProducer.cc:49
MagneticField.h
edm::EventSetup
Definition: EventSetup.h:57
JetPlusTrackProducerAA.h
edm::RefVector::push_back
void push_back(value_type const &ref)
Add a Ref<C, T> to the RefVector.
Definition: RefVector.h:67
reco::TrackBase::qualityByName
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:126
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
DetId.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
SiStripOfflineCRack_cfg.alias
alias
Definition: SiStripOfflineCRack_cfg.py:128
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
JetPlusTrackProducerAA::calculateBGtracksJet
reco::TrackRefVector calculateBGtracksJet(reco::JPTJetCollection &, std::vector< reco::TrackRef > &, edm::Handle< std::vector< reco::TrackExtrapolation > > &, reco::TrackRefVector &)
Definition: JetPlusTrackProducerAA.cc:352
ParameterSet.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::Event
Definition: Event.h:73
JetPlusTrackProducerAA::~JetPlusTrackProducerAA
~JetPlusTrackProducerAA() override
Definition: JetPlusTrackProducerAA.cc:102
Vector3D.h
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
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