CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 
20 // system include files
21 #include <memory>
22 
23 // user include files
26 
29 
31 
44 
45 //=>
60 //=>
61 
62 #include <string>
63 
64 using namespace std;
65 using namespace jpt;
66 
67 //
68 // constants, enums and typedefs
69 //
70 
71 
72 //
73 // static data member definitions
74 //
75 
76 //
77 // constructors and destructor
78 //
80 {
81  //register your products
82  src = iConfig.getParameter<edm::InputTag>("src");
83  alias = iConfig.getUntrackedParameter<string>("alias");
84  mTracks = iConfig.getParameter<edm::InputTag> ("tracks");
85  srcPVs_ = iConfig.getParameter<edm::InputTag>("srcPVs");
86  vectorial_ = iConfig.getParameter<bool>("VectorialCorrection");
87  useZSP = iConfig.getParameter<bool>("UseZSP");
88  std::string tq = iConfig.getParameter<std::string>("TrackQuality");
89  trackQuality_ = reco::TrackBase::qualityByName(tq);
90  mConeSize = iConfig.getParameter<double> ("coneSize");
91 //=>
92  mExtrapolations = iConfig.getParameter<edm::InputTag> ("extrapolations");
93 //=>
94  mJPTalgo = new JetPlusTrackCorrector(iConfig);
95  if(useZSP) mZSPalgo = new ZSPJPTJetCorrector(iConfig);
96 
97  produces<reco::JPTJetCollection>().setBranchAlias(alias);
98 
99 }
100 
101 
103 {
104 
105  // do anything here that needs to be done at desctruction time
106  // (e.g. close files, deallocate resources etc.)
107 
108 }
109 
110 
111 //
112 // member functions
113 //
114 
115 // ------------ method called to produce the data ------------
116 void
118 {
119  using namespace edm;
120 
121 
122 // std::cout<<" RecoJets::JetPlusTrackProducerAA::produce "<<std::endl;
123 
124 // get stuff from Event
126  iEvent.getByLabel (src, jets_h);
127 
129  iEvent.getByLabel (mTracks, tracks_h);
130 
131  std::vector <reco::TrackRef> fTracks;
132  fTracks.reserve (tracks_h->size());
133  for (unsigned i = 0; i < tracks_h->size(); ++i) {
134  fTracks.push_back (reco::TrackRef (tracks_h, i));
135  }
136 
137 //=>
139  iEvent.getByLabel (mExtrapolations, extrapolations_h);
140 
141 // std::cout<<"JetPlusTrackProducerAA::produce, extrapolations_h="<<extrapolations_h->size()<<std::endl;
142 //=>
143 
144  std::auto_ptr<reco::JPTJetCollection> pOut(new reco::JPTJetCollection());
145 
146  reco::JPTJetCollection tmpColl;
147 
148  for (unsigned i = 0; i < jets_h->size(); ++i) {
149 
150  const reco::CaloJet* oldjet = &(*(jets_h->refAt(i)));
151 
152  reco::CaloJet corrected = *oldjet;
153 
154 // ZSP corrections
155 
156  double factorZSP = 1.;
157  if(useZSP) factorZSP = mZSPalgo->correction(corrected, iEvent, iSetup);
158 
159 // std::cout << " UseZSP = "<<useZSP<<std::endl;
160 
161 
162  corrected.scaleEnergy (factorZSP);
163 
164 // JPT corrections
165 
166  double scaleJPT = 1.;
167 
169 
170 // Construct JPTJet constituent
171  jpt::MatchedTracks pions;
173  jpt::MatchedTracks elecs;
174  bool ok=false;
175 
176  if ( !vectorial_ ) {
177 
178  scaleJPT = mJPTalgo->correction ( corrected, *oldjet, iEvent, iSetup, pions, muons, elecs, ok );
179  p4 = math::XYZTLorentzVector( corrected.px()*scaleJPT,
180  corrected.py()*scaleJPT,
181  corrected.pz()*scaleJPT,
182  corrected.energy()*scaleJPT );
183  } else {
184  scaleJPT = mJPTalgo->correction( corrected, *oldjet, iEvent, iSetup, p4, pions, muons, elecs, ok );
185  }
186 
187 
188 
190 
191  if(ok) {
192 // std::cout<<" Size of Pion in-in "<<pions.inVertexInCalo_.size()<<" in-out "<<pions.inVertexOutOfCalo_.size()
193 // <<" out-in "<<pions.outOfVertexInCalo_.size()<<" Oldjet "<<oldjet->et()<<" factorZSP "<<factorZSP
194 // <<" "<<corrected.et()<<" scaleJPT "<<scaleJPT<<" after JPT "<<p4.pt()<<std::endl;
195 
196 
197  specific.pionsInVertexInCalo = pions.inVertexInCalo_;
198  specific.pionsInVertexOutCalo = pions.inVertexOutOfCalo_;
199  specific.pionsOutVertexInCalo = pions.outOfVertexInCalo_;
200  specific.muonsInVertexInCalo = muons.inVertexInCalo_;
201  specific.muonsInVertexOutCalo = muons.inVertexOutOfCalo_;
202  specific.muonsOutVertexInCalo = muons.outOfVertexInCalo_;
203  specific.elecsInVertexInCalo = elecs.inVertexInCalo_;
204  specific.elecsInVertexOutCalo = elecs.inVertexOutOfCalo_;
205  specific.elecsOutVertexInCalo = elecs.outOfVertexInCalo_;
206  }
207 
208 // Fill JPT Specific
209  edm::RefToBase<reco::Jet> myjet = (edm::RefToBase<reco::Jet>)jets_h->refAt(i);
210  specific.theCaloJetRef = myjet;
211  specific.mZSPCor = factorZSP;
212  specific.mResponseOfChargedWithEff = (float)mJPTalgo->getResponseOfChargedWithEff();
213  specific.mResponseOfChargedWithoutEff = (float)mJPTalgo->getResponseOfChargedWithoutEff();
214  specific.mSumPtOfChargedWithEff = (float)mJPTalgo->getSumPtWithEff();
215  specific.mSumPtOfChargedWithoutEff = (float)mJPTalgo->getSumPtWithoutEff();
216  specific.mSumEnergyOfChargedWithEff = (float)mJPTalgo->getSumEnergyWithEff();
217  specific.mSumEnergyOfChargedWithoutEff = (float)mJPTalgo->getSumEnergyWithoutEff();
218  specific.mChargedHadronEnergy = (float)mJPTalgo->getSumEnergyWithoutEff();
219 // Fill Charged Jet shape parameters
220  double deR2Tr = 0.;
221  double deEta2Tr = 0.;
222  double dePhi2Tr = 0.;
223  double Zch = 0.;
224  double Pout2 = 0.;
225  double Pout = 0.;
226  double denominator_tracks = 0.;
227  int ntracks = 0;
228 
229  for( reco::TrackRefVector::const_iterator it = pions.inVertexInCalo_.begin(); it != pions.inVertexInCalo_.end(); it++) {
230  double deR = deltaR((*it)->eta(), (*it)->phi(), p4.eta(), p4.phi());
231  double deEta = (*it)->eta() - p4.eta();
232  double dePhi = deltaPhi((*it)->phi(), p4.phi());
233  if((**it).ptError()/(**it).pt() < 0.1) {
234  deR2Tr = deR2Tr + deR*deR*(*it)->pt();
235  deEta2Tr = deEta2Tr + deEta*deEta*(*it)->pt();
236  dePhi2Tr = dePhi2Tr + dePhi*dePhi*(*it)->pt();
237  denominator_tracks = denominator_tracks + (*it)->pt();
238  Zch = Zch + (*it)->pt();
239 
240  Pout2 = Pout2 + (**it).p()*(**it).p() - (Zch*p4.P())*(Zch*p4.P());
241  ntracks++;
242  }
243  }
244  for( reco::TrackRefVector::const_iterator it = muons.inVertexInCalo_.begin(); it != muons.inVertexInCalo_.end(); 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  for( reco::TrackRefVector::const_iterator it = elecs.inVertexInCalo_.begin(); it != elecs.inVertexInCalo_.end(); 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 = pions.inVertexOutOfCalo_.begin(); it != pions.inVertexOutOfCalo_.end(); it++) {
275  Zch = Zch + (*it)->pt();
276  }
277  for( reco::TrackRefVector::const_iterator it = muons.inVertexOutOfCalo_.begin(); it != muons.inVertexOutOfCalo_.end(); it++) {
278  Zch = Zch + (*it)->pt();
279  }
280  for( reco::TrackRefVector::const_iterator it = elecs.inVertexOutOfCalo_.begin(); it != elecs.inVertexOutOfCalo_.end(); it++) {
281  Zch = Zch + (*it)->pt();
282  }
283 
284  if(mJPTalgo->getSumPtForBeta()> 0.) Zch = Zch/mJPTalgo->getSumPtForBeta();
285 
286  // std::cout<<" Zch "<< Zch<<" "<<mJPTalgo->getSumPtForBeta()<<std::endl;
287 
288  if(ntracks > 0) {
289  Pout = sqrt(fabs(Pout2))/ntracks;
290  }
291 
292 
293  if (denominator_tracks!=0){
294  deR2Tr = deR2Tr/denominator_tracks;
295  deEta2Tr= deEta2Tr/denominator_tracks;
296  dePhi2Tr= dePhi2Tr/denominator_tracks;
297  }
298 
299  specific.R2momtr = deR2Tr;
300  specific.Eta2momtr = deEta2Tr;
301  specific.Phi2momtr = dePhi2Tr;
302  specific.Pout = Pout;
303  specific.Zch = Zch;
304 
305 // Create JPT jet
306 
308 
309 // If we add primary vertex
311  iEvent.getByLabel(srcPVs_,pvCollection);
312  if ( pvCollection.isValid() && pvCollection->size()>0 ) vertex_=pvCollection->begin()->position();
313 
314  reco::JPTJet fJet(p4, vertex_, specific, corrected.getJetConstituents());
315  // fJet.printJet();
316 
317 // Temporarily collection before correction for background
318 
319  tmpColl.push_back(fJet);
320 
321  }
322 
323 //=======================================================================================================>
324 // Correction for background
325 
326  reco::TrackRefVector trBgOutOfCalo;
327  reco::TrackRefVector trBgOutOfVertex = calculateBGtracksJet(tmpColl,fTracks,extrapolations_h,trBgOutOfCalo);
328 
329 //===> Area without Jets
330  std::map<reco::JPTJetCollection::iterator, double> AreaNonJet;
331 
332  for(reco::JPTJetCollection::iterator ij1=tmpColl.begin(); ij1!=tmpColl.end(); ij1++)
333  {
334  int nj1 = 1;
335  for(reco::JPTJetCollection::iterator ij2=tmpColl.begin(); ij2!=tmpColl.end(); ij2++)
336  {
337  if(ij2 == ij1) continue;
338  if(fabs((*ij1).eta() - (*ij2).eta()) > 0.5 ) continue;
339  nj1++;
340 
341  }
342 
343  AreaNonJet[ij1] = 4*M_PI*mConeSize - nj1*4*mConeSize*mConeSize;
344 
345 // std::cout<<"+++AreaNonJet[ij1]="<<AreaNonJet[ij1]<<" nj1="<<nj1<<std::endl;
346  }
347 
348 //===>
349 
350 // std::cout<<" The size of BG tracks: trBgOutOfVertex= "<<trBgOutOfVertex.size()
351 // <<" trBgOutOfCalo= "<<trBgOutOfCalo.size()<<std::endl;
352 //
353 // std::cout<<" The size of JPT jet collection "<<tmpColl.size()<<std::endl;
354 
355  for(reco::JPTJetCollection::iterator ij=tmpColl.begin(); ij!=tmpColl.end(); ij++)
356  {
357 // Correct JPTjet for background tracks
358 
359  const reco::TrackRefVector pioninin = (*ij).getPionsInVertexInCalo();
360  const reco::TrackRefVector pioninout = (*ij).getPionsInVertexOutCalo();
361 
362  double ja = (AreaNonJet.find(ij))->second;
363 
364 // std::cout<<"+++ ja="<<ja<<" pioninout="<<pioninout.size()<<std::endl;
365 
366  double factorPU = mJPTalgo->correctAA(*ij,trBgOutOfVertex,mConeSize,pioninin,pioninout,ja,trBgOutOfCalo);
367 
368  (*ij).scaleEnergy (factorPU);
369 
370 // std::cout<<" FactorPU "<<factorPU<<std::endl;
371 
372 // Output module
373  pOut->push_back(*ij);
374 
375 // std::cout<<" New JPT energy "<<(*ij).et()<<" "<<(*ij).pt()<<" "<<(*ij).eta()<<" "<<(*ij).phi()<<std::endl;
376 
377  }
378 
379  iEvent.put(pOut);
380 
381 }
382 // -----------------------------------------------
383 // ------------ calculateBGtracksJet ------------
384 // ------------ Tracks not included in jets ------
385 // -----------------------------------------------
387  edm::Handle <std::vector<reco::TrackExtrapolation> > & extrapolations_h,
388  reco::TrackRefVector& trBgOutOfCalo){
389 
390 
391  reco::TrackRefVector trBgOutOfVertex;
392 
393  for (unsigned t = 0; t < fTracks.size(); ++t) {
394 
395  int track_bg = 0;
396 
397  // if(!(*fTracks[t]).quality(trackQuality_))
398  // {
399  // cout<<"BG, BAD trackQuality, ptBgV="<<fTracks[t]->pt()<<" etaBgV = "<<fTracks[t]->eta()<<" phiBgV = "<<fTracks[t]->phi()<<endl;
400  // continue;
401  // }
402 
403  const reco::Track* track = &*(fTracks[t]);
404  double trackEta = track->eta();
405  double trackPhi = track->phi();
406 
407  // std::cout<<"++++++++++++++++> track="<<t<<" trackEta="<<trackEta<<" trackPhi="<<trackPhi
408  // <<" coneSize="<<mConeSize<<std::endl;
409 
410  //loop on jets
411  for (unsigned j = 0; j < fJets.size(); ++j) {
412 
413  const reco::Jet* jet = &(fJets[j]);
414  double jetEta = jet->eta();
415  double jetPhi = jet->phi();
416 
417  // std::cout<<"-jet="<<j<<" jetEt ="<<jet->pt()
418  // <<" jetE="<<jet->energy()<<" jetEta="<<jetEta<<" jetPhi="<<jetPhi<<std::endl;
419 
420  if(fabs(jetEta - trackEta) < mConeSize) {
421  double dphiTrackJet = fabs(trackPhi - jetPhi);
422  if(dphiTrackJet > M_PI) dphiTrackJet = 2*M_PI - dphiTrackJet;
423 
424  if(dphiTrackJet < mConeSize)
425  {
426  track_bg = 1;
427  // std::cout<<"===>>>> Track inside jet at vertex, track_bg="<< track_bg <<" track="<<t<<" jet="<<j
428  // <<" trackEta="<<trackEta<<" trackPhi="<<trackPhi
429  // <<" jetEta="<<jetEta<<" jetPhi="<<jetPhi<<std::endl;
430  }
431  }
432  } //jets
433 
434  if( track_bg == 0 )
435  {
436  trBgOutOfVertex.push_back (fTracks[t]);
437 
438 // std::cout<<"------Track outside jet at vertex, track_bg="<< track_bg<<" track="<<t
439 // <<" trackEta="<<trackEta<<" trackPhi="<<trackPhi <<std::endl;
440  }
441 
442  } //tracks
443 
444 //=====> Propagate BG tracks to calo
445  int nValid = 0;
446  for ( std::vector<reco::TrackExtrapolation>::const_iterator xtrpBegin = extrapolations_h->begin(),
447  xtrpEnd = extrapolations_h->end(), ixtrp = xtrpBegin;
448  ixtrp != xtrpEnd; ++ixtrp ) {
449 
450 // std::cout<<"JetPlusTrackProducerAA::calculateBGtracksJet: initial track pt= "<<ixtrp->track()->pt()
451 // <<" eta= "<<ixtrp->track()->eta()<<" phi="<<ixtrp->track()->phi()
452 // <<" Valid? "<<ixtrp->isValid().at(0)<<std::endl;
453 
454  //if( ixtrp->isValid().at(0) == 0 ) continue;
455  //in DF change in 4.2, all entries are valid.
456  nValid++;
457 
458  reco::TrackRefVector::iterator it = find(trBgOutOfVertex.begin(),trBgOutOfVertex.end(),(*ixtrp).track() );
459 
460  if ( it != trBgOutOfVertex.end() ){
461  trBgOutOfCalo.push_back (*it);
462 
463 // std::cout<<"+++trBgOutOfCalo, pt= "<<ixtrp->track()->pt()<<" eta= "<<ixtrp->track()->eta()<<" phi="<<ixtrp->track()->phi()
464 // <<" Valid? "<<ixtrp->isValid().at(0)<<std::endl;
465  }
466 
467  }
468 
469 // std::cout<<"calculateBGtracksJet, trBgOutOfCalo="<<trBgOutOfCalo.size()
470 // <<" trBgOutOfVertex="<<trBgOutOfVertex.size()<<" nValid="<<nValid<<endl;
471 //=====>
472 
473  return trBgOutOfVertex;
474 }
475 // ------------ method called once each job just before starting event loop ------------
476 void
478 {
479 }
480 
481 // ------------ method called once each job just after ending the event loop ------------
482 void
484 }
485 
486 //define this as a plug-in
487 //DEFINE_FWK_MODULE(JetPlusTrackProducerAA);
reco::TrackRefVector muonsInVertexOutCalo
Definition: JPTJet.h:57
virtual double energy() const GCC11_FINAL
energy
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
float mSumEnergyOfChargedWithoutEff
Definition: JPTJet.h:71
dictionary specific
Jets made from CaloTowers.
Definition: CaloJet.h:29
reco::TrackRefVector muonsInVertexInCalo
Definition: JPTJet.h:56
reco::TrackRefVector calculateBGtracksJet(reco::JPTJetCollection &, std::vector< reco::TrackRef > &, edm::Handle< std::vector< reco::TrackExtrapolation > > &, reco::TrackRefVector &)
std::vector< JPTJet > JPTJetCollection
collection of CaloJet objects
Base class for all types of Jets.
Definition: Jet.h:20
float mChargedHadronEnergy
Definition: JPTJet.h:62
float mSumPtOfChargedWithEff
Definition: JPTJet.h:68
reco::TrackRefVector inVertexInCalo_
reco::TrackRefVector muonsOutVertexInCalo
Definition: JPTJet.h:58
JetPlusTrackProducerAA(const edm::ParameterSet &)
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:137
virtual void scaleEnergy(double fScale)
scale energy of the jet
Definition: Jet.cc:444
reco::TrackRefVector inVertexOutOfCalo_
float mResponseOfChargedWithEff
Definition: JPTJet.h:66
reco::TrackRefVector elecsOutVertexInCalo
Definition: JPTJet.h:61
reco::TrackRefVector pionsInVertexOutCalo
Definition: JPTJet.h:54
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:249
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
virtual double pz() const GCC11_FINAL
z coordinate of momentum vector
virtual double py() const GCC11_FINAL
y coordinate of momentum vector
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:244
U second(std::pair< T, U > const &p)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
virtual float phi() const GCC11_FINAL
momentum azimuthal angle
int iEvent
Definition: GenABIO.cc:243
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:139
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
T sqrt(T t)
Definition: SSEVec.h:48
double p4[4]
Definition: TauolaWrapper.h:92
Jets made from CaloJets corrected for ZSP and tracks.
Definition: JPTJet.h:29
reco::TrackRefVector pionsOutVertexInCalo
Definition: JPTJet.h:55
float mSumEnergyOfChargedWithEff
Definition: JPTJet.h:70
virtual double px() const GCC11_FINAL
x coordinate of momentum vector
math::XYZPoint Point
point in the space
Definition: Particle.h:31
int j
Definition: DBlmapReader.cc:9
reco::TrackRefVector outOfVertexInCalo_
reco::TrackRefVector elecsInVertexInCalo
Definition: JPTJet.h:59
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
edm::RefToBase< reco::Jet > theCaloJetRef
Definition: JPTJet.h:52
virtual float eta() const GCC11_FINAL
momentum pseudorapidity
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
float mResponseOfChargedWithoutEff
Definition: JPTJet.h:67
reco::TrackRefVector pionsInVertexInCalo
Definition: JPTJet.h:53
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:46
#define M_PI
Definition: BFit3D.cc:3
float mSumPtOfChargedWithoutEff
Definition: JPTJet.h:69
reco::TrackRefVector elecsInVertexOutCalo
Definition: JPTJet.h:60
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:38
void push_back(value_type const &ref)
Add a Ref&lt;C, T&gt; to the RefVector.
Definition: RefVector.h:64
virtual void produce(edm::Event &, const edm::EventSetup &)
math::XYZPoint Point
point in the space
Definition: LeafCandidate.h:30
virtual Constituents getJetConstituents() const
list of constituents
Definition: Jet.cc:350