test
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, consumesCollector());
95  if(useZSP) mZSPalgo = new ZSPJPTJetCorrector(iConfig);
96 
97  produces<reco::JPTJetCollection>().setBranchAlias(alias);
98 
99  input_jets_token_ = consumes<edm::View<reco::CaloJet> >(src);
100  input_vertex_token_ = consumes<reco::VertexCollection>(srcPVs_);
101  input_tracks_token_ = consumes<reco::TrackCollection>(mTracks);
102  input_extrapolations_token_ = consumes<std::vector<reco::TrackExtrapolation> >(mExtrapolations);
103 }
104 
105 
107 {
108 
109  // do anything here that needs to be done at desctruction time
110  // (e.g. close files, deallocate resources etc.)
111 
112 }
113 
114 
115 //
116 // member functions
117 //
118 
119 // ------------ method called to produce the data ------------
120 void
122 {
123  using namespace edm;
124 
125 
126 // std::cout<<" RecoJets::JetPlusTrackProducerAA::produce "<<std::endl;
127 
128 // get stuff from Event
130  iEvent.getByToken (input_jets_token_, jets_h);
131 
133  iEvent.getByToken (input_tracks_token_, tracks_h);
134 
135  std::vector <reco::TrackRef> fTracks;
136  fTracks.reserve (tracks_h->size());
137  for (unsigned i = 0; i < tracks_h->size(); ++i) {
138  fTracks.push_back (reco::TrackRef (tracks_h, i));
139  }
140 
141 //=>
143  iEvent.getByToken(input_extrapolations_token_, extrapolations_h);
144 
145 // std::cout<<"JetPlusTrackProducerAA::produce, extrapolations_h="<<extrapolations_h->size()<<std::endl;
146 //=>
147 
148  std::auto_ptr<reco::JPTJetCollection> pOut(new reco::JPTJetCollection());
149 
150  reco::JPTJetCollection tmpColl;
151 
152  for (unsigned i = 0; i < jets_h->size(); ++i) {
153 
154  const reco::CaloJet* oldjet = &(*(jets_h->refAt(i)));
155 
156  reco::CaloJet corrected = *oldjet;
157 
158 // ZSP corrections
159 
160  double factorZSP = 1.;
161  if(useZSP) factorZSP = mZSPalgo->correction(corrected, iEvent, iSetup);
162 
163 // std::cout << " UseZSP = "<<useZSP<<std::endl;
164 
165 
166  corrected.scaleEnergy (factorZSP);
167 
168 // JPT corrections
169 
170  double scaleJPT = 1.;
171 
173 
174 // Construct JPTJet constituent
175  jpt::MatchedTracks pions;
177  jpt::MatchedTracks elecs;
178  bool ok=false;
179 
180  if ( !vectorial_ ) {
181 
182  scaleJPT = mJPTalgo->correction ( corrected, *oldjet, iEvent, iSetup, pions, muons, elecs, ok );
183  p4 = math::XYZTLorentzVector( corrected.px()*scaleJPT,
184  corrected.py()*scaleJPT,
185  corrected.pz()*scaleJPT,
186  corrected.energy()*scaleJPT );
187  } else {
188  scaleJPT = mJPTalgo->correction( corrected, *oldjet, iEvent, iSetup, p4, pions, muons, elecs, ok );
189  }
190 
191 
192 
194 
195  if(ok) {
196 // std::cout<<" Size of Pion in-in "<<pions.inVertexInCalo_.size()<<" in-out "<<pions.inVertexOutOfCalo_.size()
197 // <<" out-in "<<pions.outOfVertexInCalo_.size()<<" Oldjet "<<oldjet->et()<<" factorZSP "<<factorZSP
198 // <<" "<<corrected.et()<<" scaleJPT "<<scaleJPT<<" after JPT "<<p4.pt()<<std::endl;
199 
200 
201  specific.pionsInVertexInCalo = pions.inVertexInCalo_;
202  specific.pionsInVertexOutCalo = pions.inVertexOutOfCalo_;
203  specific.pionsOutVertexInCalo = pions.outOfVertexInCalo_;
204  specific.muonsInVertexInCalo = muons.inVertexInCalo_;
205  specific.muonsInVertexOutCalo = muons.inVertexOutOfCalo_;
206  specific.muonsOutVertexInCalo = muons.outOfVertexInCalo_;
207  specific.elecsInVertexInCalo = elecs.inVertexInCalo_;
208  specific.elecsInVertexOutCalo = elecs.inVertexOutOfCalo_;
209  specific.elecsOutVertexInCalo = elecs.outOfVertexInCalo_;
210  }
211 
212 // Fill JPT Specific
213  edm::RefToBase<reco::Jet> myjet = (edm::RefToBase<reco::Jet>)jets_h->refAt(i);
214  specific.theCaloJetRef = myjet;
215  specific.mZSPCor = factorZSP;
216  specific.mResponseOfChargedWithEff = (float)mJPTalgo->getResponseOfChargedWithEff();
217  specific.mResponseOfChargedWithoutEff = (float)mJPTalgo->getResponseOfChargedWithoutEff();
218  specific.mSumPtOfChargedWithEff = (float)mJPTalgo->getSumPtWithEff();
219  specific.mSumPtOfChargedWithoutEff = (float)mJPTalgo->getSumPtWithoutEff();
220  specific.mSumEnergyOfChargedWithEff = (float)mJPTalgo->getSumEnergyWithEff();
221  specific.mSumEnergyOfChargedWithoutEff = (float)mJPTalgo->getSumEnergyWithoutEff();
222  specific.mChargedHadronEnergy = (float)mJPTalgo->getSumEnergyWithoutEff();
223 // Fill Charged Jet shape parameters
224  double deR2Tr = 0.;
225  double deEta2Tr = 0.;
226  double dePhi2Tr = 0.;
227  double Zch = 0.;
228  double Pout2 = 0.;
229  double Pout = 0.;
230  double denominator_tracks = 0.;
231  int ntracks = 0;
232 
233  for( reco::TrackRefVector::const_iterator it = pions.inVertexInCalo_.begin(); it != pions.inVertexInCalo_.end(); it++) {
234  double deR = deltaR((*it)->eta(), (*it)->phi(), p4.eta(), p4.phi());
235  double deEta = (*it)->eta() - p4.eta();
236  double dePhi = deltaPhi((*it)->phi(), p4.phi());
237  if((**it).ptError()/(**it).pt() < 0.1) {
238  deR2Tr = deR2Tr + deR*deR*(*it)->pt();
239  deEta2Tr = deEta2Tr + deEta*deEta*(*it)->pt();
240  dePhi2Tr = dePhi2Tr + dePhi*dePhi*(*it)->pt();
241  denominator_tracks = denominator_tracks + (*it)->pt();
242  Zch = Zch + (*it)->pt();
243 
244  Pout2 = Pout2 + (**it).p()*(**it).p() - (Zch*p4.P())*(Zch*p4.P());
245  ntracks++;
246  }
247  }
248  for( reco::TrackRefVector::const_iterator it = muons.inVertexInCalo_.begin(); it != muons.inVertexInCalo_.end(); it++) {
249  double deR = deltaR((*it)->eta(), (*it)->phi(), p4.eta(), p4.phi());
250  double deEta = (*it)->eta() - p4.eta();
251  double dePhi = deltaPhi((*it)->phi(), p4.phi());
252  if((**it).ptError()/(**it).pt() < 0.1) {
253  deR2Tr = deR2Tr + deR*deR*(*it)->pt();
254  deEta2Tr = deEta2Tr + deEta*deEta*(*it)->pt();
255  dePhi2Tr = dePhi2Tr + dePhi*dePhi*(*it)->pt();
256  denominator_tracks = denominator_tracks + (*it)->pt();
257  Zch = Zch + (*it)->pt();
258 
259  Pout2 = Pout2 + (**it).p()*(**it).p() - (Zch*p4.P())*(Zch*p4.P());
260  ntracks++;
261  }
262  }
263  for( reco::TrackRefVector::const_iterator it = elecs.inVertexInCalo_.begin(); it != elecs.inVertexInCalo_.end(); it++) {
264  double deR = deltaR((*it)->eta(), (*it)->phi(), p4.eta(), p4.phi());
265  double deEta = (*it)->eta() - p4.eta();
266  double dePhi = deltaPhi((*it)->phi(), p4.phi());
267  if((**it).ptError()/(**it).pt() < 0.1) {
268  deR2Tr = deR2Tr + deR*deR*(*it)->pt();
269  deEta2Tr = deEta2Tr + deEta*deEta*(*it)->pt();
270  dePhi2Tr = dePhi2Tr + dePhi*dePhi*(*it)->pt();
271  denominator_tracks = denominator_tracks + (*it)->pt();
272  Zch = Zch + (*it)->pt();
273 
274  Pout2 = Pout2 + (**it).p()*(**it).p() - (Zch*p4.P())*(Zch*p4.P());
275  ntracks++;
276  }
277  }
278  for( reco::TrackRefVector::const_iterator it = pions.inVertexOutOfCalo_.begin(); it != pions.inVertexOutOfCalo_.end(); it++) {
279  Zch = Zch + (*it)->pt();
280  }
281  for( reco::TrackRefVector::const_iterator it = muons.inVertexOutOfCalo_.begin(); it != muons.inVertexOutOfCalo_.end(); it++) {
282  Zch = Zch + (*it)->pt();
283  }
284  for( reco::TrackRefVector::const_iterator it = elecs.inVertexOutOfCalo_.begin(); it != elecs.inVertexOutOfCalo_.end(); it++) {
285  Zch = Zch + (*it)->pt();
286  }
287 
288  if(mJPTalgo->getSumPtForBeta()> 0.) Zch = Zch/mJPTalgo->getSumPtForBeta();
289 
290  // std::cout<<" Zch "<< Zch<<" "<<mJPTalgo->getSumPtForBeta()<<std::endl;
291 
292  if(ntracks > 0) {
293  Pout = sqrt(fabs(Pout2))/ntracks;
294  }
295 
296 
297  if (denominator_tracks!=0){
298  deR2Tr = deR2Tr/denominator_tracks;
299  deEta2Tr= deEta2Tr/denominator_tracks;
300  dePhi2Tr= dePhi2Tr/denominator_tracks;
301  }
302 
303  specific.R2momtr = deR2Tr;
304  specific.Eta2momtr = deEta2Tr;
305  specific.Phi2momtr = dePhi2Tr;
306  specific.Pout = Pout;
307  specific.Zch = Zch;
308 
309 // Create JPT jet
310 
312 
313 // If we add primary vertex
315  iEvent.getByToken(input_vertex_token_, pvCollection);
316  if ( pvCollection.isValid() && pvCollection->size()>0 ) vertex_=pvCollection->begin()->position();
317 
318  reco::JPTJet fJet(p4, vertex_, specific, corrected.getJetConstituents());
319  // fJet.printJet();
320 
321 // Temporarily collection before correction for background
322 
323  tmpColl.push_back(fJet);
324 
325  }
326 
327 //=======================================================================================================>
328 // Correction for background
329 
330  reco::TrackRefVector trBgOutOfCalo;
331  reco::TrackRefVector trBgOutOfVertex = calculateBGtracksJet(tmpColl,fTracks,extrapolations_h,trBgOutOfCalo);
332 
333 //===> Area without Jets
334  std::map<reco::JPTJetCollection::iterator, double> AreaNonJet;
335 
336  for(reco::JPTJetCollection::iterator ij1=tmpColl.begin(); ij1!=tmpColl.end(); ij1++)
337  {
338  int nj1 = 1;
339  for(reco::JPTJetCollection::iterator ij2=tmpColl.begin(); ij2!=tmpColl.end(); ij2++)
340  {
341  if(ij2 == ij1) continue;
342  if(fabs((*ij1).eta() - (*ij2).eta()) > 0.5 ) continue;
343  nj1++;
344 
345  }
346 
347  AreaNonJet[ij1] = 4*M_PI*mConeSize - nj1*4*mConeSize*mConeSize;
348 
349 // std::cout<<"+++AreaNonJet[ij1]="<<AreaNonJet[ij1]<<" nj1="<<nj1<<std::endl;
350  }
351 
352 //===>
353 
354 // std::cout<<" The size of BG tracks: trBgOutOfVertex= "<<trBgOutOfVertex.size()
355 // <<" trBgOutOfCalo= "<<trBgOutOfCalo.size()<<std::endl;
356 //
357 // std::cout<<" The size of JPT jet collection "<<tmpColl.size()<<std::endl;
358 
359  for(reco::JPTJetCollection::iterator ij=tmpColl.begin(); ij!=tmpColl.end(); ij++)
360  {
361 // Correct JPTjet for background tracks
362 
363  const reco::TrackRefVector pioninin = (*ij).getPionsInVertexInCalo();
364  const reco::TrackRefVector pioninout = (*ij).getPionsInVertexOutCalo();
365 
366  double ja = (AreaNonJet.find(ij))->second;
367 
368 // std::cout<<"+++ ja="<<ja<<" pioninout="<<pioninout.size()<<std::endl;
369 
370  double factorPU = mJPTalgo->correctAA(*ij,trBgOutOfVertex,mConeSize,pioninin,pioninout,ja,trBgOutOfCalo);
371 
372  (*ij).scaleEnergy (factorPU);
373 
374 // std::cout<<" FactorPU "<<factorPU<<std::endl;
375 
376 // Output module
377  pOut->push_back(*ij);
378 
379 // std::cout<<" New JPT energy "<<(*ij).et()<<" "<<(*ij).pt()<<" "<<(*ij).eta()<<" "<<(*ij).phi()<<std::endl;
380 
381  }
382 
383  iEvent.put(pOut);
384 
385 }
386 // -----------------------------------------------
387 // ------------ calculateBGtracksJet ------------
388 // ------------ Tracks not included in jets ------
389 // -----------------------------------------------
391  edm::Handle <std::vector<reco::TrackExtrapolation> > & extrapolations_h,
392  reco::TrackRefVector& trBgOutOfCalo){
393 
394 
395  reco::TrackRefVector trBgOutOfVertex;
396 
397  for (unsigned t = 0; t < fTracks.size(); ++t) {
398 
399  int track_bg = 0;
400 
401  // if(!(*fTracks[t]).quality(trackQuality_))
402  // {
403  // cout<<"BG, BAD trackQuality, ptBgV="<<fTracks[t]->pt()<<" etaBgV = "<<fTracks[t]->eta()<<" phiBgV = "<<fTracks[t]->phi()<<endl;
404  // continue;
405  // }
406 
407  const reco::Track* track = &*(fTracks[t]);
408  double trackEta = track->eta();
409  double trackPhi = track->phi();
410 
411  // std::cout<<"++++++++++++++++> track="<<t<<" trackEta="<<trackEta<<" trackPhi="<<trackPhi
412  // <<" coneSize="<<mConeSize<<std::endl;
413 
414  //loop on jets
415  for (unsigned j = 0; j < fJets.size(); ++j) {
416 
417  const reco::Jet* jet = &(fJets[j]);
418  double jetEta = jet->eta();
419  double jetPhi = jet->phi();
420 
421  // std::cout<<"-jet="<<j<<" jetEt ="<<jet->pt()
422  // <<" jetE="<<jet->energy()<<" jetEta="<<jetEta<<" jetPhi="<<jetPhi<<std::endl;
423 
424  if(fabs(jetEta - trackEta) < mConeSize) {
425  double dphiTrackJet = fabs(trackPhi - jetPhi);
426  if(dphiTrackJet > M_PI) dphiTrackJet = 2*M_PI - dphiTrackJet;
427 
428  if(dphiTrackJet < mConeSize)
429  {
430  track_bg = 1;
431  // std::cout<<"===>>>> Track inside jet at vertex, track_bg="<< track_bg <<" track="<<t<<" jet="<<j
432  // <<" trackEta="<<trackEta<<" trackPhi="<<trackPhi
433  // <<" jetEta="<<jetEta<<" jetPhi="<<jetPhi<<std::endl;
434  }
435  }
436  } //jets
437 
438  if( track_bg == 0 )
439  {
440  trBgOutOfVertex.push_back (fTracks[t]);
441 
442 // std::cout<<"------Track outside jet at vertex, track_bg="<< track_bg<<" track="<<t
443 // <<" trackEta="<<trackEta<<" trackPhi="<<trackPhi <<std::endl;
444  }
445 
446  } //tracks
447 
448 //=====> Propagate BG tracks to calo
449  int nValid = 0;
450  for ( std::vector<reco::TrackExtrapolation>::const_iterator xtrpBegin = extrapolations_h->begin(),
451  xtrpEnd = extrapolations_h->end(), ixtrp = xtrpBegin;
452  ixtrp != xtrpEnd; ++ixtrp ) {
453 
454 // std::cout<<"JetPlusTrackProducerAA::calculateBGtracksJet: initial track pt= "<<ixtrp->track()->pt()
455 // <<" eta= "<<ixtrp->track()->eta()<<" phi="<<ixtrp->track()->phi()
456 // <<" Valid? "<<ixtrp->isValid().at(0)<<std::endl;
457 
458  //if( ixtrp->isValid().at(0) == 0 ) continue;
459  //in DF change in 4.2, all entries are valid.
460  nValid++;
461 
462  reco::TrackRefVector::iterator it = find(trBgOutOfVertex.begin(),trBgOutOfVertex.end(),(*ixtrp).track() );
463 
464  if ( it != trBgOutOfVertex.end() ){
465  trBgOutOfCalo.push_back (*it);
466 
467 // std::cout<<"+++trBgOutOfCalo, pt= "<<ixtrp->track()->pt()<<" eta= "<<ixtrp->track()->eta()<<" phi="<<ixtrp->track()->phi()
468 // <<" Valid? "<<ixtrp->isValid().at(0)<<std::endl;
469  }
470 
471  }
472 
473 // std::cout<<"calculateBGtracksJet, trBgOutOfCalo="<<trBgOutOfCalo.size()
474 // <<" trBgOutOfVertex="<<trBgOutOfVertex.size()<<" nValid="<<nValid<<endl;
475 //=====>
476 
477  return trBgOutOfVertex;
478 }
479 // ------------ method called once each job just before starting event loop ------------
480 void
482 {
483 }
484 
485 // ------------ method called once each job just after ending the event loop ------------
486 void
488 }
489 
490 //define this as a plug-in
491 //DEFINE_FWK_MODULE(JetPlusTrackProducerAA);
reco::TrackRefVector muonsInVertexOutCalo
Definition: JPTJet.h:57
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
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 &)
virtual double energy() const final
energy
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
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 &)
virtual double phi() const final
momentum azimuthal angle
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:640
reco::TrackRefVector inVertexOutOfCalo_
float mResponseOfChargedWithEff
Definition: JPTJet.h:66
reco::TrackRefVector elecsOutVertexInCalo
Definition: JPTJet.h:61
virtual Constituents getJetConstituents() const
list of constituents
reco::TrackRefVector pionsInVertexOutCalo
Definition: JPTJet.h:54
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:253
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:248
U second(std::pair< T, U > const &p)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
int iEvent
Definition: GenABIO.cc:230
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:646
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
T sqrt(T t)
Definition: SSEVec.h:18
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
math::XYZPoint Point
point in the space
Definition: Particle.h:25
int j
Definition: DBlmapReader.cc:9
reco::TrackRefVector outOfVertexInCalo_
virtual double py() const final
y coordinate of momentum vector
reco::TrackRefVector elecsInVertexInCalo
Definition: JPTJet.h:59
bool isValid() const
Definition: HandleBase.h:75
virtual double pz() const final
z coordinate of momentum vector
edm::RefToBase< reco::Jet > theCaloJetRef
Definition: JPTJet.h:52
#define M_PI
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:125
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:69
virtual double px() const final
x coordinate of momentum vector
virtual double eta() const final
momentum pseudorapidity
virtual void produce(edm::Event &, const edm::EventSetup &)
math::XYZPoint Point
point in the space
Definition: LeafCandidate.h:27