CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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;
157  jpt::MatchedTracks elecs;
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  }
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  }
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  }
259  it != muons.inVertexOutOfCalo_.end();
260  it++) {
261  Zch = Zch + (*it)->pt();
262  }
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::TrackRefVector muonsInVertexOutCalo
Definition: JPTJet.h:54
T getUntrackedParameter(std::string const &, T const &) const
float mSumEnergyOfChargedWithoutEff
Definition: JPTJet.h:68
dictionary specific
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
double pz() const final
z coordinate of momentum vector
Jets made from CaloTowers.
Definition: CaloJet.h:27
reco::TrackRefVector muonsInVertexInCalo
Definition: JPTJet.h:53
virtual void scaleEnergy(double fScale)
scale energy of the jet
reco::TrackRefVector calculateBGtracksJet(reco::JPTJetCollection &, std::vector< reco::TrackRef > &, edm::Handle< std::vector< reco::TrackExtrapolation > > &, reco::TrackRefVector &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
std::vector< JPTJet > JPTJetCollection
collection of CaloJet objects
Base class for all types of Jets.
Definition: Jet.h:20
float mChargedHadronEnergy
Definition: JPTJet.h:59
float mSumPtOfChargedWithEff
Definition: JPTJet.h:65
reco::TrackRefVector inVertexInCalo_
reco::TrackRefVector muonsOutVertexInCalo
Definition: JPTJet.h:55
JetPlusTrackProducerAA(const edm::ParameterSet &)
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:649
reco::TrackRefVector inVertexOutOfCalo_
float mResponseOfChargedWithEff
Definition: JPTJet.h:63
reco::TrackRefVector elecsOutVertexInCalo
Definition: JPTJet.h:58
virtual Constituents getJetConstituents() const
list of constituents
reco::TrackRefVector pionsInVertexOutCalo
Definition: JPTJet.h:51
void produce(edm::Event &, const edm::EventSetup &) override
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:228
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:223
U second(std::pair< T, U > const &p)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
double px() const final
x coordinate of momentum vector
int iEvent
Definition: GenABIO.cc:224
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:652
T sqrt(T t)
Definition: SSEVec.h:19
Jets made from CaloJets corrected for ZSP and tracks.
Definition: JPTJet.h:28
def move
Definition: eostools.py:511
reco::TrackRefVector pionsOutVertexInCalo
Definition: JPTJet.h:52
float mSumEnergyOfChargedWithEff
Definition: JPTJet.h:67
math::XYZPoint Point
point in the space
Definition: Particle.h:25
reco::TrackRefVector outOfVertexInCalo_
reco::TrackRefVector elecsInVertexInCalo
Definition: JPTJet.h:56
double py() const final
y coordinate of momentum vector
bool isValid() const
Definition: HandleBase.h:70
edm::RefToBase< reco::Jet > theCaloJetRef
Definition: JPTJet.h:49
#define M_PI
float mResponseOfChargedWithoutEff
Definition: JPTJet.h:64
reco::TrackRefVector pionsInVertexInCalo
Definition: JPTJet.h:50
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:126
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
float mSumPtOfChargedWithoutEff
Definition: JPTJet.h:66
reco::TrackRefVector elecsInVertexOutCalo
Definition: JPTJet.h:57
Particles matched to tracks that are in/in, in/out, out/in at Vertex and CaloFace.
Jet energy correction algorithm using tracks.
tuple muons
Definition: patZpeak.py:39
void push_back(value_type const &ref)
Add a Ref&lt;C, T&gt; to the RefVector.
Definition: RefVector.h:67
double phi() const final
momentum azimuthal angle
math::XYZPoint Point
point in the space
Definition: LeafCandidate.h:27
double energy() const final
energy
double eta() const final
momentum pseudorapidity