CMS 3D CMS Logo

JetPlusTrackCorrector.cc
Go to the documentation of this file.
12 #include <fstream>
13 #include <vector>
14 #include <iomanip>
15 #include <cmath>
16 
17 using namespace std;
18 using namespace jpt;
19 
20 // -----------------------------------------------------------------------------
21 //
23  : verbose_( pset.getParameter<bool>("Verbose") ),
24  vectorial_( pset.getParameter<bool>("VectorialCorrection") ),
25  vecResponse_( pset.getParameter<bool>("UseResponseInVecCorr") ),
26  useInConeTracks_( pset.getParameter<bool>("UseInConeTracks") ),
27  useOutOfConeTracks_( pset.getParameter<bool>("UseOutOfConeTracks") ),
28  useOutOfVertexTracks_( pset.getParameter<bool>("UseOutOfVertexTracks") ),
29  usePions_( pset.getParameter<bool>("UsePions") ),
30  useEff_( pset.getParameter<bool>("UseEfficiency") ),
31  useMuons_( pset.getParameter<bool>("UseMuons") ),
32  useElecs_( pset.getParameter<bool>("UseElectrons") ),
33  useTrackQuality_( pset.getParameter<bool>("UseTrackQuality") ),
34  jetTracksAtVertex_( pset.getParameter<edm::InputTag>("JetTracksAssociationAtVertex") ),
35  jetTracksAtCalo_( pset.getParameter<edm::InputTag>("JetTracksAssociationAtCaloFace") ),
36  jetSplitMerge_( pset.getParameter<int>("JetSplitMerge") ),
37  srcPVs_(pset.getParameter<edm::InputTag>("srcPVs") ),
38  ptErrorQuality_( pset.getParameter<double>("PtErrorQuality") ),
39  dzVertexCut_( pset.getParameter<double>("DzVertexCut") ),
40  muons_( pset.getParameter<edm::InputTag>("Muons") ),
41  electrons_( pset.getParameter<edm::InputTag>("Electrons") ),
42  electronIds_( pset.getParameter<edm::InputTag>("ElectronIds") ),
43  trackQuality_( reco::TrackBase::qualityByName( pset.getParameter<std::string>("TrackQuality") ) ),
44  response_( Map( pset.getParameter<std::string>("ResponseMap"), verbose_ ) ),
45  efficiency_( Map( pset.getParameter<std::string>("EfficiencyMap"), verbose_ ) ),
46  leakage_( Map( pset.getParameter<std::string>("LeakageMap"), verbose_ ) ),
47  pionMass_(0.140),
48  muonMass_(0.105),
49  elecMass_(0.000511),
50  maxEta_( pset.getParameter<double>("MaxJetEta") )
51 {
52 
53  if ( verbose_ ) {
54  std::stringstream ss;
55  ss << "[JetPlusTrackCorrector::" << __func__ << "] Configuration for JPT corrector: " << std::endl
56  << " Particles" << std::endl
57  << " UsePions : " << ( usePions_ ? "true" : "false" ) << std::endl
58  << " UseMuons : " << ( useMuons_ ? "true" : "false" ) << std::endl
59  << " UseElecs : " << ( useElecs_ ? "true" : "false" ) << std::endl
60  << " Corrections" << std::endl
61  << " UseInConeTracks : " << ( useInConeTracks_ ? "true" : "false" ) << std::endl
62  << " UseOutOfConeTracks : " << ( useOutOfConeTracks_ ? "true" : "false" ) << std::endl
63  << " UseOutOfVertexTracks : " << ( useOutOfVertexTracks_ ? "true" : "false" ) << std::endl
64  << " ResponseMap : " << pset.getParameter<std::string>("ResponseMap") << std::endl
65  << " Efficiency" << std::endl
66  << " UsePionEfficiency : " << ( useEff_ ? "true" : "false" ) << std::endl
67  << " EfficiencyMap : " << pset.getParameter<std::string>("EfficiencyMap") << std::endl
68  << " LeakageMap : " << pset.getParameter<std::string>("LeakageMap") << std::endl
69  << " Tracks" << std::endl
70  << " JetTracksAtVertex : " << jetTracksAtVertex_ << std::endl
71  << " JetTracksAtCalo : " << jetTracksAtCalo_ << std::endl
72  << " JetSplitMerge : " << jetSplitMerge_ << std::endl
73  << " UseTrackQuality : " << ( useTrackQuality_ ? "true" : "false" ) << std::endl
74  << " Collections" << std::endl
75  << " Muons : " << muons_ << std::endl
76  << " Electrons : " << electrons_ << std::endl
77  << " Vectorial" << std::endl
78  << " UseTracksAndResponse : " << ( ( vectorial_ && vecResponse_ ) ? "true" : "false" ) << std::endl
79  << " UseTracksOnly : " << ( ( vectorial_ && !vecResponse_ ) ? "true" : "false" );
80  edm::LogInfo("JetPlusTrackCorrector") << ss.str();
81  }
82 
83  if ( !useInConeTracks_ ||
86  std::stringstream ss;
87  ss << "[JetPlusTrackCorrector::" << __func__ << "]"
88  << " You are using JPT algorithm in a non-standard way!" << std::endl
89  << " UseInConeTracks : " << ( useInConeTracks_ ? "true" : "false" ) << std::endl
90  << " UseOutOfConeTracks : " << ( useOutOfConeTracks_ ? "true" : "false" ) << std::endl
91  << " UseOutOfVertexTracks : " << ( useOutOfVertexTracks_ ? "true" : "false" );
92  edm::LogWarning("JetPlusTrackCorrector") << ss.str();
93  }
94 
97  inut_reco_muons_token_ = iC.consumes<RecoMuons> (muons_);
101 
102 
103 }
104 
105 // -----------------------------------------------------------------------------
106 //
108 
109 // -----------------------------------------------------------------------------
110 //
111 double JetPlusTrackCorrector::correction( const reco::Jet& fJet, const reco::Jet& fJetcalo,
112  const edm::Event& event,
113  const edm::EventSetup& setup,
114  P4& corrected,
115  MatchedTracks &pions,
118  bool &validMatches)
119 {
120 
121 // std::cout<<" JetPlusTrackCorrector::correction "<<std::endl;
122 
125  theSumPtWithEff = 0.;
126  theSumPtWithoutEff = 0.;
127  theSumEnergyWithEff = 0.;
129  theSumPtForBeta = 0.;
130 
131  // Corrected 4-momentum for jet
132  corrected = fJet.p4();
133 
134  // Match tracks to different particle types
135  validMatches = matchTracks( fJetcalo, event, setup, pions, muons, elecs );
136  if ( !validMatches ) { return 1.; }
137 
138  // Check if jet can be JPT-corrected
139  if ( !canCorrect(fJet) ) { return 1.; }
140 
141 // std::cout<<" Jet can be corrected "<<std::endl;
142 
143 
144  // std::cout<<" Tracks are matched "<<std::endl;
145 
146  // Debug
147  if ( verbose_ ) {
148  edm::LogInfo("JetPlusTrackCorrector")
149  << "[JetPlusTrackCorrector::" << __func__ << "]"
150  << " Applying JPT corrections...";
151  }
152 
153  // Pion corrections (both scalar and vectorial)
154  if ( usePions_ ) { corrected += pionCorrection( fJet.p4(), pions ); }
155 
156  // Muon corrections (both scalar and vectorial)
157  if ( useMuons_ ) { corrected += muonCorrection( fJet.p4(), muons ); }
158 
159  // Electrons corrections (both scalar and vectorial)
160  if ( useElecs_ ) { corrected += elecCorrection( fJet.p4(), elecs ); }
161 
162  // Define jet direction using total 3-momentum of tracks (overrides above)
163  if ( vectorial_ && !vecResponse_ ) { if( fabs(corrected.eta()) < 2. ) {corrected = jetDirFromTracks( corrected, pions, muons, elecs );} }
164 
165  // Check if corrected 4-momentum gives negative scale
166  double scale = checkScale( fJet.p4(), corrected );
167 
168  // Debug
169  if ( verbose_ ) {
170  std::stringstream ss;
171  ss << "Total correction:" << std::endl
172  << std::fixed << std::setprecision(6)
173  << " Uncorrected (Px,Py,Pz,E) : "
174  << "(" << fJet.px()
175  << "," << fJet.py()
176  << "," << fJet.pz()
177  << "," << fJet.energy()
178  << ")" << std::endl
179  << " Corrected (Px,Py,Pz,E) : "
180  << "(" << corrected.px()
181  << "," << corrected.py()
182  << "," << corrected.pz()
183  << "," << corrected.energy()
184  << ")" << std::endl
185  << " Uncorrected (Pt,Eta,Phi,M) : "
186  << "(" << fJet.pt()
187  << "," << fJet.eta()
188  << "," << fJet.phi()
189  << "," << fJet.mass()
190  << ")" << std::endl
191  << " Corrected (Pt,Eta,Phi,M) : "
192  << "(" << corrected.pt()
193  << "," << corrected.eta()
194  << "," << corrected.phi()
195  << "," << corrected.mass()
196  << ")" << std::endl
197  << " Scalar correction to E : " << scale << std::endl
198  << " Scalar correction to Et : " << ( fJet.et() > 0. ? corrected.Et() / fJet.et() : 1. );// << std::endl
199  edm::LogVerbatim("JetPlusTrackCorrector") << ss.str();
200  }
201 
202 // std::cout << " mScale= " << scale
203 // << " NewResponse " << corrected.energy()
204 // << " Jet energy " << fJet.energy()
205 // << " event " << event.id().event() << std::endl;
206 
207 /*
208  std::cout<<" Correction::Corrections for jet "<< theResponseOfChargedWithEff <<" "<<
209  theResponseOfChargedWithoutEff <<" "<<
210  theSumPtWithEff <<" "<<
211  theSumPtWithoutEff <<" "<<
212  theSumEnergyWithEff <<" "<<
213  theSumEnergyWithoutEff <<std::endl;
214 */
215 
216 
217  // Return energy correction
218  return scale;
219 
220 }
221 
222 // -----------------------------------------------------------------------------
223 //
225  edm::LogError("JetPlusTrackCorrector")
226  << "JetPlusTrackCorrector can be run on entire event only";
227  return 1.;
228 }
229 
230 // -----------------------------------------------------------------------------
231 //
233  edm::LogError("JetPlusTrackCorrector")
234  << "JetPlusTrackCorrector can be run on entire event only";
235  return 1.;
236 }
237 
238 // -----------------------------------------------------------------------------
239 //
241  const edm::Event& event,
242  const edm::EventSetup& setup, //@@ required by method in derived class
243  jpt::MatchedTracks& pions,
246 
247  // Associate tracks to jet at both the Vertex and CaloFace
248  JetTracks jet_tracks;
249  bool ok = jetTrackAssociation( fJet, event, setup, jet_tracks );
250 
251  // std::cout<<"JetPlusTrackCorrector::matchTracks, JetTrackAssociation ok="<<ok<<std::endl;
252 
253  if ( !ok ) { return false; }
254 
255  // Track collections propagated to Vertex and CaloFace for "pions", muons and electrons
256  matchTracks( jet_tracks, event, pions, muons, elecs );
257 
258  // Debug
259  if ( verbose_ ) {
260  std::stringstream ss;
261  ss << "Number of tracks:" << std::endl
262  << " In-cone at Vertex : " << jet_tracks.vertex_.size() << std::endl
263  << " In-cone at CaloFace : " << jet_tracks.caloFace_.size();
264  edm::LogVerbatim("JetPlusTrackCorrector") << ss.str();
265  }
266 
267  return true;
268 
269 }
270 
271 // -----------------------------------------------------------------------------
272 //
274  const edm::Event& event,
275  const edm::EventSetup& setup,
276  JetTracks& trks ) const {
277 
278  // Some init
279  trks.clear();
280 
281  // Check if labels are given
282  if ( !jetTracksAtVertex_.label().empty() && !jetTracksAtCalo_.label().empty() ) {
283 
284  //std::cout<<" Try to associate with splitting "<< std::endl;
285 
286  return jtaUsingEventData( fJet, event, trks );
287  } else {
288 
289  edm::LogWarning("PatJPTCorrector")
290  << "[JetPlusTrackCorrector::" << __func__ << "]"
291  << " Empty label for the reco::JetTracksAssociation::Containers"
292  << std::endl
293  << " InputTag for JTA \"at vertex\" (label:instance:process) \""
294  << jetTracksAtVertex_.label() << ":"
295  << jetTracksAtVertex_.instance() << ":"
296  << jetTracksAtVertex_.process() << "\""
297  << std::endl
298  << " InputTag for JTA \"at calo face\" (label:instance:process) \""
299  << jetTracksAtCalo_.label() << ":"
300  << jetTracksAtCalo_.instance() << ":"
301  << jetTracksAtCalo_.process() << "\"";
302  return false;
303  }
304 
305 }
306 
307 // -----------------------------------------------------------------------------
308 //
310  const edm::Event& event,
311  JetTracks& trks ) const {
312 
313  // Get Jet-track association at Vertex
315  event.getByToken(input_jetTracksAtVertex_token_, jetTracksAtVertex );
316 
317  if ( !jetTracksAtVertex.isValid() || jetTracksAtVertex.failedToGet() ) {
318  if ( verbose_ && edm::isDebugEnabled() ) {
319  edm::LogWarning("JetPlusTrackCorrector")
320  << "[JetPlusTrackCorrector::" << __func__ << "]"
321  << " Invalid handle to reco::JetTracksAssociation::Container (for Vertex)"
322  << " with InputTag (label:instance:process) \""
323  << jetTracksAtVertex_.label() << ":"
324  << jetTracksAtVertex_.instance() << ":"
325  << jetTracksAtVertex_.process() << "\"";
326  }
327  return false;
328  }
329 
330 
331  // std::cout<<" JetPlusTrackCorrector::jtaUsingEventData::here "<<jetSplitMerge_<<std::endl;
332 
333  // Retrieve jet-tracks association for given jet
334  const reco::JetTracksAssociation::Container jtV = *( jetTracksAtVertex.product() );
335  TrackRefs excluded;
336  if ( jetSplitMerge_ < 0 ) { trks.vertex_ = reco::JetTracksAssociation::getValue( jtV, fJet ); }
337  else { rebuildJta( fJet, jtV, trks.vertex_, excluded ); }
338 
339  // Check if any tracks are associated to jet at vertex
340  if ( trks.vertex_.empty() ) { return false; }
341 
342  // Get Jet-track association at Calo
344  event.getByToken(input_jetTracksAtCalo_token_, jetTracksAtCalo );
345 
346  if ( !jetTracksAtCalo.isValid() || jetTracksAtCalo.failedToGet() ) {
347  if ( verbose_ && edm::isDebugEnabled() ) {
348  edm::LogWarning("JetPlusTrackCorrector")
349  << "[JetPlusTrackCorrector::" << __func__ << "]"
350  << " Invalid handle to reco::JetTracksAssociation::Container (for CaloFace)"
351  << " with InputTag (label:instance:process) \""
352  << jetTracksAtCalo_.label() << ":"
353  << jetTracksAtCalo_.instance() << ":"
354  << jetTracksAtCalo_.process() << "\"";
355  }
356  return false;
357  }
358 
359  // Retrieve jet-tracks association for given jet
360  const reco::JetTracksAssociation::Container jtC = *( jetTracksAtCalo.product() );
361  if ( jetSplitMerge_ < 0 ) { trks.caloFace_ = reco::JetTracksAssociation::getValue( jtC, fJet ); }
362  else { excludeJta( fJet, jtC, trks.caloFace_, excluded ); }
363 
364 // std::cout<<" JTA:Tracks in vertex "<<trks.vertex_.size()<<" in calo "<<trks.caloFace_.size()<<std::endl;
365 
366  // Successful
367  return true;
368 
369 }
370 
371 // -----------------------------------------------------------------------------
372 //
374  event.getByToken(inut_reco_muons_token_, reco_muons );
375  if ( !reco_muons.isValid() || reco_muons.failedToGet() ) {
376  edm::LogError("JetPlusTrackCorrector")
377  << "[JetPlusTrackCorrector::" << __func__ << "]"
378  << " Invalid handle to reco::Muon collection"
379  << " with InputTag (label:instance:process) \""
380  << muons_.label() << ":"
381  << muons_.instance() << ":"
382  << muons_.process() << "\"";
383  return false;
384  }
385  return true;
386 }
387 
388 // -----------------------------------------------------------------------------
389 //
391  const edm::Event& event,
392  MatchedTracks& pions,
394  MatchedTracks& elecs ) {
395 
396  // Some init
397  pions.clear();
398  muons.clear();
399  elecs.clear();
400 
401  // Need vertex for track cleaning
402 
405  event.getByToken(input_pvCollection_token_, pvCollection);
406  if ( pvCollection.isValid() && !pvCollection->empty() ) vertex_=pvCollection->begin()->position();
407 
408  // Get RECO muons
409  edm::Handle<RecoMuons> reco_muons;
410  bool found_reco_muons = true;
411  if ( useMuons_ ) { getMuons( event, reco_muons ); }
412 
413  // Get RECO electrons and their ids
414  edm::Handle<RecoElectrons> reco_elecs;
415  edm::Handle<RecoElectronIds> reco_elec_ids;
416  bool found_reco_elecs = true;
417  if ( useElecs_ ) { getElectrons( event, reco_elecs, reco_elec_ids ); }
418 
419  // Check RECO products found
420  if ( !found_reco_muons || !found_reco_elecs ) {
421  edm::LogError("JetPlusTrackCorrector")
422  << "[JetPlusTrackCorrector::" << __func__ << "]"
423  << " Unable to access RECO collections for muons and electrons";
424  return;
425  }
426 
427  // Identify pions/muons/electrons that are "in/in" and "in/out"
428  {
429  TrackRefs::const_iterator itrk = jet_tracks.vertex_.begin();
430  TrackRefs::const_iterator jtrk = jet_tracks.vertex_.end();
431 
432 // std::cout<<" Print theSumPtForBeta "<<theSumPtForBeta<<std::endl;
433 
434  double theSumPtForBetaOld = theSumPtForBeta;
435 
436  for ( ; itrk != jtrk; ++itrk ) {
437 
438  if ( useTrackQuality_ && (*itrk)->quality(trackQuality_) && theSumPtForBetaOld<=0. )
439  theSumPtForBeta += (**itrk).pt();
440 //
441 // Track either belongs to PV or do not belong to any vertex
442 
443  const reco::TrackBaseRef ttr1(*itrk);
444 
445 // std::cout<<" Size of PV "<<pvCollection->size()<<std::endl;
446 
447  int numpv=0;
448 
449  int itrack_belong = -1;
450 
451  for( reco::VertexCollection::const_iterator iv = pvCollection->begin(); iv != pvCollection->end(); iv++) {
452  numpv++;
453  std::vector<reco::TrackBaseRef>::const_iterator rr =
454  find((*iv).tracks_begin(),
455  (*iv).tracks_end(),
456  ttr1);
457  if( rr != (*iv).tracks_end() ) {
458  itrack_belong++;
459  // std::cout<<" Numpv "<<numpv<<std::endl;
460  break;
461  }
462 
463  } // all vertices
464 
465 // std::cout<<" Track in PV "<<itrack_belong<<" "<<numpv<<std::endl;
466 
467  if( numpv > 1 && itrack_belong == 0 ) {
468  // std::cout<<" Drop track "<<std::endl;
469  continue;
470  }
471 
472  // std::cout<<" we take it "<<numpv<<" "<<itrack_belong<<std::endl;
473 
474  if ( failTrackQuality(itrk) ) { continue; }
475 
476 // std::cout<<" Track accepted "<<std::endl;
477 
478  TrackRefs::iterator it = jet_tracks.caloFace_.end();
479  bool found = findTrack( jet_tracks, itrk, it );
480 
481 // std::cout<<"JetPlusTrackCorrector::matchTracks: jet_tracks.caloFace_.size()="<<jet_tracks.caloFace_.size()
482 // <<" found = "<<found<<std::endl;
483 
484  bool is_muon = useMuons_ && matchMuons( itrk, reco_muons );
485  bool is_ele = useElecs_ && matchElectrons( itrk, reco_elecs, reco_elec_ids );
486 
487  if ( found ) {
488  if ( is_muon ) { muons.inVertexInCalo_.push_back(*it); }
489  else if ( is_ele ) { elecs.inVertexInCalo_.push_back(*it); }
490  else { pions.inVertexInCalo_.push_back(*it); }
491  } else {
492  if ( is_muon ) { muons.inVertexOutOfCalo_.push_back(*itrk); }
493  else if ( is_ele ) { elecs.inVertexOutOfCalo_.push_back(*itrk); }
494  else {
495  pions.inVertexOutOfCalo_.push_back(*itrk);
496 // std::cout<<"JetPlusTrackCorrector::matchTracks: pions.inVertexOutOfCalo_.push_back(*itrk), size="
497 // <<pions.inVertexOutOfCalo_.size() <<std::endl;
498  }
499  }
500  }
501  }
502 
503  // Identify pions/muons/electrons that are "out/in"
504  {
505  TrackRefs::iterator itrk = jet_tracks.caloFace_.begin();
506  TrackRefs::iterator jtrk = jet_tracks.caloFace_.end();
507  for ( ; itrk != jtrk; ++itrk ) {
508 
509  if ( failTrackQuality(itrk) ) { continue; }
510 
511  if ( !tracksInCalo( pions, muons, elecs ) ) { continue; }
512 
513  bool found = findTrack( pions, muons, elecs, itrk );
514 
515  if ( !found ) {
516 
517  bool is_muon = useMuons_ && matchMuons( itrk, reco_muons );
518  bool is_ele = useElecs_ && matchElectrons( itrk, reco_elecs, reco_elec_ids );
519 
520  if ( is_muon ) { muons.outOfVertexInCalo_.push_back(*itrk); }
521  else if ( is_ele ) { elecs.outOfVertexInCalo_.push_back(*itrk); }
522  else { pions.outOfVertexInCalo_.push_back(*itrk); }
523 
524  }
525  }
526  }
527 
528  if ( verbose_ && edm::isDebugEnabled() ) {
529  std::stringstream ss;
530  ss << "[JetPlusTrackCorrector::" << __func__ << "] Number of tracks:" << std::endl
531  << " In-cone at Vertex and in-cone at CaloFace:" << std::endl
532  << " Pions : " << pions.inVertexInCalo_.size() << std::endl
533  << " Muons : " << muons.inVertexInCalo_.size() << std::endl
534  << " Electrons : " << elecs.inVertexInCalo_.size() << std::endl
535  << " In-cone at Vertex and out-of-cone at CaloFace:" << std::endl
536  << " Pions : " << pions.inVertexOutOfCalo_.size() << std::endl
537  << " Muons : " << muons.inVertexOutOfCalo_.size() << std::endl
538  << " Electrons : " << elecs.inVertexOutOfCalo_.size() << std::endl
539  << " Out-of-cone at Vertex and in-cone at CaloFace:" << std::endl
540  << " Pions : " << pions.outOfVertexInCalo_.size() << std::endl
541  << " Muons : " << muons.outOfVertexInCalo_.size() << std::endl
542  << " Electrons : " << elecs.outOfVertexInCalo_.size() << std::endl;
543  LogTrace("JetPlusTrackCorrector") << ss.str();
544  }
545 
546 }
547 
548 // -----------------------------------------------------------------------------
549 //
551  edm::Handle<RecoElectrons>& reco_elecs,
552  edm::Handle<RecoElectronIds>& reco_elec_ids ) const {
553  event.getByToken(input_reco_elecs_token_, reco_elecs );
554  if ( !reco_elecs.isValid() || reco_elecs.failedToGet() ) {
555  edm::LogError("JetPlusTrackCorrector")
556  << "[JetPlusTrackCorrector::" << __func__ << "]"
557  << " Invalid handle to reco::GsfElectron collection"
558  << " with InputTag (label:instance:process) \""
559  << electrons_.label() << ":"
560  << electrons_.instance() << ":"
561  << electrons_.process() << "\"";
562  return false;
563  }
564  event.getByToken(input_reco_elec_ids_token_, reco_elec_ids );
565  if ( !reco_elec_ids.isValid() || reco_elec_ids.failedToGet() ) {
566  edm::LogError("JetPlusTrackCorrector")
567  << "[JetPlusTrackCorrector::" << __func__ << "]"
568  << " Invalid handle to reco::GsfElectron collection"
569  << " with InputTag (label:instance:process) \""
570  << electronIds_.label() << ":"
571  << electronIds_.instance() << ":"
572  << electronIds_.process() << "\"";
573  return false;
574  }
575  return true;
576 }
577 
578 // -----------------------------------------------------------------------------
579 //
581 // if ( useTrackQuality_ && !(*itrk)->quality(trackQuality_) ) { return true; }
582 // else { return false; }
583 
584  bool retcode = false;
585 
586  if ( useTrackQuality_ && !(*itrk)->quality(trackQuality_) ) {
587  retcode = true; return retcode;
588  }
589  if(((*itrk)->ptError()/(*itrk)->pt()) > ptErrorQuality_) {
590  retcode = true; return retcode;
591  }
592  if(fabs((*itrk)->dz(vertex_)) > dzVertexCut_) {
593  retcode = true; return retcode;
594  }
595 
596  return retcode;
597 }
598 
599 // -----------------------------------------------------------------------------
600 //
603  TrackRefs::iterator& it ) const {
604  it = find( jet_tracks.caloFace_.begin(),
605  jet_tracks.caloFace_.end(),
606  *itrk );
607  if ( it != jet_tracks.caloFace_.end() ) { return true; }
608  else { return false; }
609 }
610 
611 // -----------------------------------------------------------------------------
612 //
614  const MatchedTracks& muons,
615  const MatchedTracks& elecs,
616  TrackRefs::const_iterator& itrk ) const {
618  pions.inVertexInCalo_.end(),
619  *itrk );
621  muons.inVertexInCalo_.end(),
622  *itrk );
624  elecs.inVertexInCalo_.end(),
625  *itrk );
626  if ( ip == pions.inVertexInCalo_.end() &&
627  im == muons.inVertexInCalo_.end() &&
628  ie == elecs.inVertexInCalo_.end() ) { return false; }
629  else { return true; }
630 }
631 
632 // -----------------------------------------------------------------------------
633 //
635  const MatchedTracks& muons,
636  const MatchedTracks& elecs ) const {
637  if ( !pions.inVertexInCalo_.empty() ||
638  !muons.inVertexInCalo_.empty() ||
639  !elecs.inVertexInCalo_.empty() ) { return true; }
640  else { return false; }
641 }
642 
643 // -----------------------------------------------------------------------------
644 //
646  const MatchedTracks& pions ) {
647 
648  P4 corr_pions;
649 /*
650  std::cout<<" pionCorrection::Corrections for jet "<< theResponseOfChargedWithEff <<" "<<
651  theResponseOfChargedWithoutEff <<" "<<
652  theSumPtWithEff <<" "<<
653  theSumPtWithoutEff <<" "<<
654  theSumEnergyWithEff <<" "<<
655  theSumEnergyWithoutEff <<std::endl;
656 */
657 
658  // In-cone
659 
660  P4 corr_pions_in_cone;
661  P4 corr_pions_eff_in_cone;
662  Efficiency in_cone( responseMap(), efficiencyMap(), leakageMap() );
663 
664  if ( useInConeTracks_ ) {
665  corr_pions_in_cone = pionCorrection( jet, pions.inVertexInCalo_, in_cone, true, true );
666  corr_pions += corr_pions_in_cone;
667  if ( useEff_ ) {
668  corr_pions_eff_in_cone = pionEfficiency( jet, in_cone, true );
669  corr_pions += corr_pions_eff_in_cone;
670  }
671  }
672 
673  // Out-of-cone
674 
675  P4 corr_pions_out_of_cone;
676  P4 corr_pions_eff_out_of_cone;
677  Efficiency out_of_cone( responseMap(), efficiencyMap(), leakageMap() );
678 
679  if ( useOutOfConeTracks_ ) {
680  corr_pions_out_of_cone = pionCorrection( jet, pions.inVertexOutOfCalo_, out_of_cone, true, false );
681  corr_pions += corr_pions_out_of_cone;
682  if ( useEff_ ) {
683  corr_pions_eff_out_of_cone = pionEfficiency( jet, out_of_cone, false );
684  corr_pions += corr_pions_eff_out_of_cone;
685  }
686  }
687 
688  // Out-of-vertex
689 
690  P4 corr_pions_out_of_vertex;
692 
693  if ( useOutOfVertexTracks_ ) {
694  corr_pions_out_of_vertex = pionCorrection( jet, pions.outOfVertexInCalo_, not_used, false, true );
695  corr_pions += corr_pions_out_of_vertex;
696  }
697 
698  if ( verbose_ ) {
699  std::stringstream ss;
700  ss << " Pion corrections:" << std::endl
701  << " In/In : " << "(" << pions.inVertexInCalo_.size() << ") " << corr_pions_in_cone.energy() << std::endl
702  << " In/Out : " << "(" << pions.inVertexOutOfCalo_.size() << ") " << corr_pions_out_of_cone.energy() << std::endl
703  << " Out/In : " << "(" << pions.outOfVertexInCalo_.size() << ") " << corr_pions_out_of_vertex.energy() << std::endl;
704  if ( useEff_ ) {
705  ss << " Pion efficiency corrections:" << std::endl
706  << " In/In : " << "(" << pions.inVertexInCalo_.size() << ") " << corr_pions_eff_in_cone.energy() << std::endl
707  << " In/Out : " << "(" << pions.inVertexOutOfCalo_.size() << ") " << corr_pions_eff_out_of_cone.energy();
708  }
709  edm::LogVerbatim("JetPlusTrackCorrector") << ss.str();
710  }
711 
712  return corr_pions;
713 
714 }
715 
716 // -----------------------------------------------------------------------------
717 //
719  const MatchedTracks& muons ) {
720 
721  P4 corr_muons;
722 
723  P4 corr_muons_in_cone;
724  P4 corr_muons_out_of_cone;
725  P4 corr_muons_out_of_vertex;
726 
727  if ( useInConeTracks_ ) {
728  corr_muons_in_cone = muonCorrection( jet, muons.inVertexInCalo_, true, true );
729  corr_muons += corr_muons_in_cone;
730  }
731 
732  if ( useOutOfConeTracks_ ) {
733  corr_muons_out_of_cone = muonCorrection( jet, muons.inVertexOutOfCalo_, true, false );
734  corr_muons += corr_muons_out_of_cone;
735  }
736 
737  if ( useOutOfVertexTracks_ ) {
738  corr_muons_out_of_vertex = muonCorrection( jet, muons.outOfVertexInCalo_, false, true );
739  corr_muons += corr_muons_out_of_vertex;
740  }
741 
742  if ( verbose_ ) {
743  std::stringstream ss;
744  ss << " Muon corrections:" << std::endl
745  << " In/In : " << "(" << muons.inVertexInCalo_.size() << ") " << corr_muons_in_cone.energy() << std::endl
746  << " In/Out : " << "(" << muons.inVertexOutOfCalo_.size() << ") " << corr_muons_out_of_cone.energy() << std::endl
747  << " Out/In : " << "(" << muons.outOfVertexInCalo_.size() << ") " << corr_muons_out_of_vertex.energy();
748  edm::LogVerbatim("JetPlusTrackCorrector") << ss.str();
749  }
750 
751  return corr_muons;
752 
753 }
754 
755 // -----------------------------------------------------------------------------
756 //
758  const MatchedTracks& elecs ) const {
759 
760  P4 null; //@@ null 4-momentum
761 
762  if ( verbose_ ) {
763  std::stringstream ss;
764  ss << " Electron corrections:" << std::endl
765  << " In/In : " << "(" << elecs.inVertexInCalo_.size() << ") " << null.energy() << std::endl
766  << " In/Out : " << "(" << elecs.inVertexOutOfCalo_.size() << ") " << null.energy() << std::endl
767  << " Out/In : " << "(" << elecs.outOfVertexInCalo_.size() << ") " << null.energy();
768  edm::LogVerbatim("JetPlusTrackCorrector") << ss.str();
769  }
770 
771  return null; //@@ to be implemented
772 
773 }
774 
775 // -----------------------------------------------------------------------------
776 //
778  const MatchedTracks& pions,
779  const MatchedTracks& muons,
780  const MatchedTracks& elecs ) const {
781 
782  // Correction to be applied to jet 4-momentum
783  P4 corr;
784 
785 // bool tracks_present = false;
786  bool tracks_present_inin = false;
787 
788  // Correct using pions in-cone at vertex
789 
790  if ( !pions.inVertexInCalo_.empty() ) {
792  TrackRefs::iterator jtrk = pions.inVertexInCalo_.end();
793  for ( ; itrk != jtrk; ++itrk ) {
794  corr += PtEtaPhiM( (*itrk)->pt(), (*itrk)->eta(), (*itrk)->phi(), 0. );
795 // tracks_present = true;
796  tracks_present_inin = true;
797  }
798  }
799 
800  if ( !pions.inVertexOutOfCalo_.empty() ) {
803  for ( ; itrk != jtrk; ++itrk ) {
804  corr += PtEtaPhiM( (*itrk)->pt(), (*itrk)->eta(), (*itrk)->phi(), 0. );
805 // tracks_present = true;
806  }
807  }
808 
809  // Correct using muons in-cone at vertex
810 
811  if ( !muons.inVertexInCalo_.empty() ) {
813  TrackRefs::iterator jtrk = muons.inVertexInCalo_.end();
814  for ( ; itrk != jtrk; ++itrk ) {
815  corr += PtEtaPhiM( (*itrk)->pt(), (*itrk)->eta(), (*itrk)->phi(), 0. );
816 // tracks_present = true;
817  }
818  }
819 
820  if ( !muons.inVertexOutOfCalo_.empty() ) {
823  for ( ; itrk != jtrk; ++itrk ) {
824  corr += PtEtaPhiM( (*itrk)->pt(), (*itrk)->eta(), (*itrk)->phi(), 0. );
825 // tracks_present = true;
826  }
827  }
828 
829  // Correct using electrons in-cone at vertex
830 
831  if ( !elecs.inVertexInCalo_.empty() ) {
833  TrackRefs::iterator jtrk = elecs.inVertexInCalo_.end();
834  for ( ; itrk != jtrk; ++itrk ) {
835  corr += PtEtaPhiM( (*itrk)->pt(), (*itrk)->eta(), (*itrk)->phi(), 0. );
836 // tracks_present = true;
837  }
838  }
839 
840  if ( !elecs.inVertexOutOfCalo_.empty() ) {
843  for ( ; itrk != jtrk; ++itrk ) {
844  corr += PtEtaPhiM( (*itrk)->pt(), (*itrk)->eta(), (*itrk)->phi(), 0. );
845 // tracks_present = true;
846  }
847  }
848 
849  // Adjust direction if in cone tracks are present
850 
851  if ( !tracks_present_inin ) { corr = corrected; }
852  else {
853  corr *= ( corr.P() > 0. ? corrected.P() / corr.P() : 1. );
854  corr = P4( corr.px(), corr.py(), corr.pz(), corrected.energy() );
855  }
856 
857  return corr;
858 
859 }
860 
861 // -----------------------------------------------------------------------------
862 //
864  const TrackRefs& tracks,
865  jpt::Efficiency& eff,
866  bool in_cone_at_vertex,
867  bool in_cone_at_calo_face,
868  double mass,
869  bool is_pion,
870  double mip ) {
871 
872  // Correction to be applied to jet 4-momentum
873  P4 correction;
874 
875 /*
876  std::cout<<" >>>>> Jet "<<jet.pt()<<" "<<jet.eta()<<" "<<jet.phi()<<" Number of tracks "<<tracks.size()<<" Pions? "<<is_pion<<" InVert "<<in_cone_at_vertex<<
877  " InCalo "<<in_cone_at_calo_face<<std::endl;
878 
879  std::cout<<" calculateCorr Start::Corrections for jet "<< theResponseOfChargedWithEff <<" "<<
880  theResponseOfChargedWithoutEff <<" "<<
881  theSumPtWithEff <<" "<<
882  theSumPtWithoutEff <<" "<<
883  theSumEnergyWithEff <<" "<<
884  theSumEnergyWithoutEff <<std::endl;
885 */
886 
887 
888  // Reset efficiency container
889  eff.reset();
890 
891  double theSumResp = 0;
892  double theSumPt = 0;
893  double theSumEnergy = 0;
894 
895 
896  // Iterate through tracks
897  if ( !tracks.empty() ) {
898  TrackRefs::iterator itrk = tracks.begin();
899  TrackRefs::iterator jtrk = tracks.end();
900 
901  for ( ; itrk != jtrk; ++itrk ) {
902 
903  // Ignore high-pt tracks (only when in-cone and not a mip)
904  if ( in_cone_at_calo_face && is_pion && (*itrk)->pt() >= 50. ) { continue; }
905 
906  // Inner track 4-momentum
907  P4 inner;
908  if ( vectorial_ && vecResponse_ ) {
909  inner = PtEtaPhiM( (*itrk)->pt(), (*itrk)->eta(), (*itrk)->phi(), mass );
910  } else {
911  double energy = sqrt( (*itrk)->px() * (*itrk)->px() +
912  (*itrk)->py() * (*itrk)->py() +
913  (*itrk)->pz() * (*itrk)->pz() +
914  mass * mass );
915  inner = ( jet.energy() > 0. ? energy / jet.energy() : 1. ) * jet;
916  }
917 
918  // Add track momentum (if in-cone at vertex)
919  if ( in_cone_at_vertex ) { correction += inner; }
920 
921  // Find appropriate eta/pt bin for given track
922  double eta = fabs( (*itrk)->eta() );
923  double pt = fabs( (*itrk)->pt() );
924  uint32_t ieta = response_.etaBin( eta );
925  uint32_t ipt = response_.ptBin( pt );
926 
927  // Check bins (not for mips)
928  if ( is_pion && ( ieta == response_.nEtaBins() || ipt == response_.nPtBins() ) ) { continue; }
929 
930  // Outer track 4-momentum
931  P4 outer;
932  if ( in_cone_at_calo_face ) {
933  if ( vectorial_ && vecResponse_ ) {
934  // Build 4-momentum from outer track (SHOULD USE IMPACT POINT?!)
935  double outer_pt = (*itrk)->pt();
936  double outer_eta = (*itrk)->eta();
937  double outer_phi = (*itrk)->phi();
938  if ( (*itrk)->extra().isNonnull() ) {
939  outer_pt = (*itrk)->pt();
940  outer_eta = (*itrk)->outerPosition().eta(); //@@ outerMomentum().eta()
941  outer_phi = (*itrk)->outerPosition().phi(); //@@ outerMomentum().phi()
942  }
943  outer = PtEtaPhiM( outer_pt, outer_eta, outer_phi, mass );
944  // Check if mip or not
945  if ( !is_pion ) { outer *= ( outer.energy() > 0. ? mip / outer.energy() : 1. ); } //@@ Scale to mip energy
946  else { outer *= ( outer.energy() > 0. ? inner.energy() / outer.energy() : 1. ); } //@@ Scale to inner track energy
947  } else {
948  // Check if mip or not
949  if ( !is_pion ) { outer = ( jet.energy() > 0. ? mip / jet.energy() : 1. ) * jet; } //@@ Jet 4-mom scaled by mip energy
950  else { outer = inner; } //@@ Set to inner track 4-momentum
951  }
952  if ( is_pion ) { outer *= response_.value(ieta,ipt); } //@@ Scale by pion response
953  correction -= outer; //@@ Subtract
954 
955 // Calculate the sum of responses
956  theSumResp += response_.value(ieta,ipt);
957  }
958 
959 // Calculate the sum of pt and energies
960  theSumPt += inner.pt();
961  theSumEnergy += inner.energy();
962 
963  // Record inner track energy for pion efficiency correction
964  if ( is_pion ) { eff.addE( ieta, ipt, inner.energy() ); }
965 
966  // Debug
967  if ( verbose_ && edm::isDebugEnabled() ) {
968  std::stringstream temp;
969  temp << " Response[" << ieta << "," << ipt << "]";
970  std::stringstream ss;
971  ss << "[JetPlusTrackCorrector::" << __func__ << "]" << std::endl
972  << " Track eta / pt : " << eta << " / " << pt << std::endl
973  << temp.str() << std::setw(21-temp.str().size()) << " : "
974  << response_.value(ieta,ipt) << std::endl
975  << " Track momentum added : " << inner.energy() << std::endl
976  << " Response subtracted : " << outer.energy() << std::endl
977  << " Energy correction : " << correction.energy();
978  LogDebug("JetPlusTrackCorrector") << ss.str();
979  }
980 
981  } // loop through tracks
982  } // ntracks != 0
983 
984  if( in_cone_at_vertex ) {
985 
986  theResponseOfChargedWithEff += theSumResp;
987  theResponseOfChargedWithoutEff += theSumResp;
988  theSumPtWithEff += theSumPt;
989  theSumPtWithoutEff += theSumPt;
990  theSumEnergyWithEff += theSumEnergy;
991  theSumEnergyWithoutEff += theSumEnergy;
992 
993  }
994 /*
995  std::cout<<" calculateCorr End::Corrections for jet "<< theResponseOfChargedWithEff <<" "<<
996  theResponseOfChargedWithoutEff <<" "<<
997  theSumPtWithEff <<" "<<
998  theSumPtWithoutEff <<" "<<
999  theSumEnergyWithEff <<" "<<
1000  theSumEnergyWithoutEff <<std::endl;
1001 */
1002  return correction;
1003 
1004 }
1005 
1006 // -----------------------------------------------------------------------------
1007 //
1009  const Efficiency& eff,
1010  bool in_cone_at_calo_face ) {
1011 
1012  // Total correction to be applied
1013  P4 correction;
1014 
1015  double theSumResp = 0;
1016  double theSumPt = 0;
1017  double theSumEnergy = 0;
1018 
1019  // Iterate through eta/pt bins
1020  for ( uint32_t ieta = 0; ieta < response_.nEtaBins()-1; ++ieta ) {
1021  for ( uint32_t ipt = 0; ipt < response_.nPtBins()-1; ++ipt ) {
1022 
1023  // Check tracks are found in this eta/pt bin
1024  if ( !eff.nTrks(ieta,ipt) ) { continue; }
1025 
1026  for ( uint16_t ii = 0; ii < 2; ++ii ) {
1027 
1028  // Check which correction should be applied
1029  double corr = 0.;
1030  if ( ii == 0 ) { corr = eff.outOfConeCorr( ieta, ipt );}
1031  else if ( ii == 1 && in_cone_at_calo_face ) { corr = eff.inConeCorr( ieta, ipt );}
1032  else { continue; }
1033 
1034  // Calculate correction to be applied
1035  P4 corr_p4;
1036  if ( vectorial_ && vecResponse_ ) {
1037  double corr_eta = response_.binCenterEta(ieta);
1038  double corr_phi = jet.phi(); //@@ jet phi!
1039  double corr_pt = response_.binCenterPt(ipt);
1040  corr_p4 = PtEtaPhiM( corr_pt, corr_eta, corr_phi, pionMass_ ); //@@ E^2 = p^2 + m_pion^2, |p| calc'ed from pt bin
1041  corr_p4 *= ( corr_p4.energy() > 0. ? corr / corr_p4.energy() : 1. ); //@@ p4 scaled up by mean energy for bin
1042  } else {
1043  corr_p4 = ( jet.energy() > 0. ? corr / jet.energy() : 1. ) * jet;
1044  }
1045 
1046  // Apply correction
1047  if ( ii == 0 ) { correction += corr_p4; theSumPt += corr_p4.pt(); theSumEnergy += corr_p4.energy();} //@@ Add out-of-cone
1048  else if ( ii == 1 ) { correction -= corr_p4; theSumResp += corr_p4.energy();} //@@ Subtract in-cone
1049 
1050  }
1051 
1052  }
1053  }
1054 
1055  theResponseOfChargedWithEff += theSumResp;
1056  theSumPtWithEff += theSumPt;
1057  theSumEnergyWithEff += theSumEnergy;
1058 /*
1059  std::cout<<" Efficiency correction End::Corrections for jet "<< theResponseOfChargedWithEff <<" "<<
1060  theResponseOfChargedWithoutEff <<" "<<
1061  theSumPtWithEff <<" "<<
1062  theSumPtWithoutEff <<" "<<
1063  theSumEnergyWithEff <<" "<<
1064  theSumEnergyWithoutEff <<std::endl;
1065 */
1066  return correction;
1067 
1068 }
1069 
1070 // -----------------------------------------------------------------------------
1071 //
1073  const edm::Handle<RecoMuons>& muons ) const {
1074 
1075  if ( muons->empty() ) { return false; }
1076 
1077  RecoMuons::const_iterator imuon = muons->begin();
1078  RecoMuons::const_iterator jmuon = muons->end();
1079  for ( ; imuon != jmuon; ++imuon ) {
1080 
1081  if ( imuon->innerTrack().isNull() ||
1083  imuon->innerTrack()->pt() < 3.0 ) { continue; }
1084 
1085  if ( itrk->id() != imuon->innerTrack().id() ) {
1086  edm::LogError("JetPlusTrackCorrector")
1087  << "[JetPlusTrackCorrector::" << __func__ << "]"
1088  << "Product id of the tracks associated to the jet " << itrk->id()
1089  <<" is different from the product id of the inner track used for muons " << imuon->innerTrack().id()
1090  << "!" << std::endl
1091  << "Cannot compare tracks from different collection. Configuration Error!";
1092  return false;
1093  }
1094 
1095  if ( *itrk == imuon->innerTrack() ) { return true; }
1096  }
1097 
1098  return false;
1099 
1100 }
1101 
1102 // -----------------------------------------------------------------------------
1103 //
1106  const edm::Handle<RecoElectronIds>& elec_ids ) const {
1107 
1108  if ( elecs->empty() ) { return false; }
1109 
1110  double deltaR = 999.;
1111  double deltaRMIN = 999.;
1112 
1113  uint32_t electron_index = 0;
1114  RecoElectrons::const_iterator ielec = elecs->begin();
1115  RecoElectrons::const_iterator jelec = elecs->end();
1116  for ( ; ielec != jelec; ++ielec ) {
1117 
1118  edm::Ref<RecoElectrons> electron_ref( elecs, electron_index );
1119  electron_index++;
1120 
1121  if ( (*elec_ids)[electron_ref] < 1.e-6 ) { continue; } //@@ Check for null value
1122 
1123  // DR matching b/w electron and track
1124  double deltaphi = fabs( ielec->phi() - (*itrk)->momentum().phi() );
1125  if ( deltaphi > 6.283185308 ) deltaphi -= 6.283185308;
1126  if ( deltaphi > 3.141592654 ) deltaphi = 6.283185308 - deltaphi;
1127  deltaR = abs( sqrt( pow( (ielec->eta() - (*itrk)->momentum().eta()), 2 ) +
1128  pow( deltaphi , 2 ) ) );
1129  if ( deltaR < deltaRMIN ) { deltaRMIN = deltaR; }
1130 
1131  }
1132 
1133  if ( deltaR < 0.02 ) return true;
1134  else return false;
1135 
1136 }
1137 
1138 // -----------------------------------------------------------------------------
1139 //
1141  const JetTracksAssociations& jtV0,
1142  TrackRefs& tracksthis,
1143  TrackRefs& Excl ) const {
1144 
1145  // std::cout<<" NEW1 Merge/Split schema "<<jetSplitMerge_<<std::endl;
1146 
1147  tracksthis = reco::JetTracksAssociation::getValue(jtV0,fJet);
1148 
1149  if(jetSplitMerge_<0) return;
1150 
1151  typedef std::vector<reco::JetBaseRef>::iterator JetBaseRefIterator;
1152  std::vector<reco::JetBaseRef> theJets = reco::JetTracksAssociation::allJets(jtV0);
1153 
1154  TrackRefs tracks = tracksthis;
1155  tracksthis.clear();
1156 
1157 // std::cout<<" Size of initial vector "<<tracks.size()<<" "<<fJet.et()<<" "<<fJet.eta()<<" "<<fJet.phi()<<std::endl;
1158 
1159  int tr=0;
1160 
1161 
1162  double jetEta=fJet.eta();
1163  double jetPhi=fJet.phi();
1164  double jetEtIn=1.0/fJet.et();
1165 
1166  for(TrackRefs::iterator it = tracks.begin(); it != tracks.end(); it++ )
1167  {
1168  double trkEta=(**it).eta();
1169  double trkPhi=(**it).phi();
1170  double dR2this = deltaR2( jetEta, jetPhi, trkEta, trkPhi );
1171  // double dfi = fabs(fJet.phi()-(**it).phi());
1172  // if(dfi>4.*atan(1.))dfi = 8.*atan(1.)-dfi;
1173  // double deta = fJet.eta() - (**it).eta();
1174  // double dR2check = sqrt(dfi*dfi+deta*deta);
1175 
1176  double scalethis = dR2this;
1177  if(jetSplitMerge_ == 0) scalethis = 1.*jetEtIn;
1178  if(jetSplitMerge_ == 2) scalethis = dR2this*jetEtIn;
1179  tr++;
1180  int flag = 1;
1181  for(JetBaseRefIterator ii = theJets.begin(); ii != theJets.end(); ii++)
1182  {
1183  if(&(**ii) == &fJet ) {continue;}
1184  double dR2 = deltaR2( (*ii)->eta(), (*ii)->phi(), trkEta, trkPhi );
1185  double scale = dR2;
1186  if(jetSplitMerge_ == 0) scale = 1./(**ii).et();
1187  if(jetSplitMerge_ == 2) scale = dR2/(**ii).et();
1188  if(scale < scalethis) flag = 0;
1189 
1190  if(flag == 0) {
1191  //std::cout<<" Track belong to another jet also "<<dR2<<" "<<
1192  //(*ii)->et()<<" "<<(*ii)->eta()<<" "<< (*ii)->phi()<<" Track "<<(**it).eta()<<" "<<(**it).phi()<<" "<<scalethis<<" "<<scale<<" "<<flag<<std::endl;
1193  break;
1194  }
1195  }
1196 
1197  //std::cout<<" Track "<<tr<<" "<<flag<<" "<<dR2this<<" "<<dR2check<<" Jet "<<fJet.eta()<<" "<< fJet.phi()<<" Track "<<(**it).eta()<<" "<<(**it).phi()<<std::endl;
1198  if(flag == 1) {tracksthis.push_back (*it);}else{Excl.push_back (*it);}
1199  }
1200 
1201  //std::cout<<" The new size of tracks "<<tracksthis.size()<<" Excludede "<<Excl.size()<<std::endl;
1202  return;
1203 
1204 }
1205 
1206 // -----------------------------------------------------------------------------
1207 //
1209  const JetTracksAssociations& jtV0,
1210  TrackRefs& tracksthis,
1211  const TrackRefs& Excl ) const {
1212 
1213  //std::cout<<" NEW2" << std::endl;
1214 
1215  tracksthis = reco::JetTracksAssociation::getValue(jtV0,fJet);
1216  if(Excl.empty()) return;
1217  if(jetSplitMerge_<0) return;
1218 
1219  TrackRefs tracks = tracksthis;
1220  tracksthis.clear();
1221 
1222  //std::cout<<" Size of initial vector "<<tracks.size()<<" "<<fJet.et()<<" "<<fJet.eta()<<" "<<fJet.phi()<<std::endl;
1223 
1224  for(TrackRefs::iterator it = tracks.begin(); it != tracks.end(); it++ )
1225  {
1226 
1227  //std::cout<<" Track at calo surface "
1228  //<<" Track "<<(**it).eta()<<" "<<(**it).phi()<<std::endl;
1229  TrackRefs::iterator itold = find(Excl.begin(),Excl.end(),(*it));
1230  if(itold == Excl.end()) {
1231  tracksthis.push_back (*it);
1232  }
1233  //else { std::cout<<"Exclude "<<(**it).eta()<<" "<<(**it).phi()<<std::endl; }
1234 
1235  }
1236 
1237  //std::cout<<" Size of calo tracks "<<tracksthis.size()<<std::endl;
1238 
1239  return;
1240 
1241 }
1242 
1243 //================================================================================================
1244 
1246  const reco::TrackRefVector& trBgOutOfVertex,
1247  double& mConeSize,
1248  const reco::TrackRefVector& pioninin,
1249  const reco::TrackRefVector& pioninout,double ja,
1250  const reco::TrackRefVector& trBgOutOfCalo) const {
1251 double mScale = 1.;
1252 double NewResponse = fJet.energy();
1253 
1254 //std::cout<<"---JetPlusTrackCorrector::correctAA, Jet initial: NewResponse="<<NewResponse <<" et = "<<fJet.et()
1255 // <<" pt= "<<fJet.pt()<<" eta="<<fJet.eta()<<" phi="<<fJet.phi() <<" ja="<<ja
1256 // <<" trBgOutOfVertex="<<trBgOutOfVertex.size()<< " trBgOutOfCalo="<<trBgOutOfCalo.size()<<std::endl;
1257 
1258 if( trBgOutOfVertex.empty() ) return mScale;
1259  double EnergyOfBackgroundCharged = 0.;
1260  double ResponseOfBackgroundCharged = 0.;
1261 
1262 //
1263 // calculate the mean response
1264 //
1265 // double MeanResponseOfBackgroundCharged = 0.;
1266 // double MeanEnergyOfBackgroundCharged = 0.;
1267 
1268 //================= EnergyOfBackgroundCharged ==================>
1269  for( reco::TrackRefVector::iterator iBgtV = trBgOutOfVertex.begin(); iBgtV != trBgOutOfVertex.end(); iBgtV++)
1270  {
1271  // Temporary solution>>>>>> Remove tracks with pt>50 GeV
1272  // if( (**iBgtV).pt() >= 50. ) continue;
1273  //response_.value(ieta,ipt);
1274  double eta = fabs( (**iBgtV).eta() );
1275  double pt = fabs( (**iBgtV).pt() );
1276  uint32_t ieta = response_.etaBin( eta );
1277  uint32_t ipt = response_.ptBin( pt );
1278 
1279  if(fabs(fJet.eta() -(**iBgtV).eta()) > mConeSize) continue;
1280 
1281 // // Check bins (not for mips)
1282 // if ( ieta >= response_.nEtaBins() ) { continue; }
1283 // if ( ipt >= response_.nPtBins() ) { ipt = response_.nPtBins() - 1; }
1284 
1285  double echarBg=sqrt((**iBgtV).px()*(**iBgtV).px()+(**iBgtV).py()*(**iBgtV).py()+(**iBgtV).pz()*(**iBgtV).pz()+0.14*0.14);
1286 
1287 // ResponseOfBackgroundCharged += echarBg*response_.value(ieta,ipt)/efficiency_.value(ieta,ipt);
1288 
1289 // std::cout<<" Efficiency of bg tracks "<<efficiency_.value(ieta,ipt)<<std::endl;
1290 
1291  EnergyOfBackgroundCharged += echarBg/efficiency_.value(ieta,ipt);
1292 
1293 
1294  } // Energy BG tracks
1295 
1296 
1297 //============= ResponseOfBackgroundCharged =======================>
1298 
1299  for( reco::TrackRefVector::iterator iBgtC = trBgOutOfCalo.begin(); iBgtC != trBgOutOfCalo.end(); iBgtC++)
1300  {
1301  // Temporary solution>>>>>> Remove tracks with pt>50 GeV
1302  // if( (**iBgtC).pt() >= 50. ) continue;
1303  //response_.value(ieta,ipt);
1304  double eta = fabs( (**iBgtC).eta() );
1305  double pt = fabs( (**iBgtC).pt() );
1306  uint32_t ieta = response_.etaBin( eta );
1307  uint32_t ipt = response_.ptBin( pt );
1308 
1309  if(fabs(fJet.eta() -(**iBgtC).eta()) > mConeSize) continue;
1310 
1311  // Check bins (not for mips)
1312  if ( ieta >= response_.nEtaBins() ) { continue; }
1313  if ( ipt >= response_.nPtBins() ) { ipt = response_.nPtBins() - 1; }
1314 
1315  double echarBg=sqrt((**iBgtC).px()*(**iBgtC).px()+(**iBgtC).py()*(**iBgtC).py()+(**iBgtC).pz()*(**iBgtC).pz()+0.14*0.14);
1316 
1317  ResponseOfBackgroundCharged += echarBg*response_.value(ieta,ipt)/efficiency_.value(ieta,ipt);
1318 
1319 // std::cout<<" Efficiency of bg tracks "<<efficiency_.value(ieta,ipt)<<std::endl;
1320 
1321 
1322 
1323  } // Response of BG tracks
1324 
1325 //=================================================================>
1326 
1327 //=================================================================>
1328 // Look for in-out tracks
1329 
1330  double en = 0.;
1331  double px = 0.;
1332  double py = 0.;
1333  double pz = 0.;
1334 
1335  for(reco::TrackRefVector::const_iterator it = pioninout.begin(); it != pioninout.end(); it++) {
1336 
1337 // std::cout<<" Track in out, size= "<<pioninout.size()<<" p= "<<(*it)->p()<<" pt= "<<(*it)->pt()
1338 // <<" eta= "<<(*it)->eta()<<" phi= "<<(*it)->phi()<<std::endl;
1339 
1340  px+=(*it)->px();
1341  py+=(*it)->py();
1342  pz+=(*it)->pz();
1343  en+=sqrt((*it)->p()*(*it)->p()+0.14*0.14);
1344  }
1345 
1346 // Look for in-in tracks
1347 
1348  double en_in = 0.;
1349  double px_in = 0.;
1350  double py_in = 0.;
1351  double pz_in = 0.;
1352 
1353  for(reco::TrackRefVector::const_iterator it = pioninin.begin(); it != pioninin.end(); it++) {
1354 
1355 // std::cout<<" Track in in, size= "<<pioninin.size()<<" p= "<<(*it)->p()<<" pt= "<<(*it)->pt()
1356 // <<" eta= "<<(*it)->eta()<<" phi= "<<(*it)->phi()<<std::endl;
1357 
1358  px_in+=(*it)->px();
1359  py_in+=(*it)->py();
1360  pz_in+=(*it)->pz();
1361  en_in+=sqrt((*it)->p()*(*it)->p()+0.14*0.14);
1362  }
1363 
1364 
1365 //===================================================================>
1366 
1367 //=>
1368 // double SquareEtaRingWithoutJets = 4*(M_PI*mConeSize - mConeSize*mConeSize);
1369  double SquareEtaRingWithoutJets = ja;
1370 
1371 // std::cout<<"---SquareEtaRingWithoutJets="<<SquareEtaRingWithoutJets<<std::endl;
1372 
1373  EnergyOfBackgroundCharged = EnergyOfBackgroundCharged/SquareEtaRingWithoutJets;
1374  ResponseOfBackgroundCharged = ResponseOfBackgroundCharged/SquareEtaRingWithoutJets;
1375 // NumberOfBackgroundCharged = NumberOfBackgroundCharged/SquareEtaRingWithoutJets;
1376 
1377 
1378  EnergyOfBackgroundCharged = M_PI*mConeSize*mConeSize*EnergyOfBackgroundCharged;
1379  ResponseOfBackgroundCharged = M_PI*mConeSize*mConeSize*ResponseOfBackgroundCharged;
1380 // NumberOfBackgroundCharged = M_PI*mConeSize*mConeSize*NumberOfBackgroundCharged;
1381 
1382 
1383  NewResponse = NewResponse - EnergyOfBackgroundCharged + ResponseOfBackgroundCharged;
1384 
1385 // std::cout<<"====JetPlusTrackCorrector, Old response=fJet.energy()"<<fJet.energy()
1386 // <<" EnergyOfBackgroundCharged="<<EnergyOfBackgroundCharged
1387 // <<" ResponseOfBackgroundCharged="<<ResponseOfBackgroundCharged
1388 
1389  mScale = NewResponse/fJet.energy();
1390  if(mScale <0.) mScale=0.;
1391 return mScale;
1392 }
1393 // -----------------------------------------------------------------------------
1394 //
1395 Map::Map( std::string input, bool verbose )
1396  : eta_(),
1397  pt_(),
1398  data_()
1399 {
1400 
1401  // Some init
1402  clear();
1403  std::vector<Element> data;
1404 
1405  // Parse file
1407  std::ifstream in( file.c_str() );
1408  string line;
1409  uint32_t ieta_old = 0;
1410  while ( std::getline( in, line ) ) {
1411  if ( line.empty() || line[0]=='#' ) { continue; }
1412  std::istringstream ss(line);
1413  Element temp;
1414  ss >> temp.ieta_ >> temp.ipt_ >> temp.eta_ >> temp.pt_ >> temp.val_;
1415  data.push_back(temp);
1416  if ( !ieta_old || temp.ieta_ != ieta_old ) {
1417  if ( eta_.size() < temp.ieta_+1 ) { eta_.resize(temp.ieta_+1,0.); }
1418  eta_[temp.ieta_] = temp.eta_;
1419  ieta_old = temp.ieta_;
1420  }
1421  if ( pt_.size() < temp.ipt_+1 ) { pt_.resize(temp.ipt_+1,0.); }
1422  pt_[temp.ipt_] = temp.pt_;
1423  }
1424 
1425  // Populate container
1426  data_.resize( eta_.size(), VDouble( pt_.size(), 0. ) );
1427  std::vector<Element>::const_iterator idata = data.begin();
1428  std::vector<Element>::const_iterator jdata = data.end();
1429  for ( ; idata != jdata; ++idata ) { data_[idata->ieta_][idata->ipt_] = idata->val_; }
1430 
1431  // Check
1432  if ( data_.empty() || data_[0].empty() ) {
1433  std::stringstream ss;
1434  ss << "[jpt::Map::" << __func__ << "]"
1435  << " Problem parsing map in location \""
1436  << file << "\"! ";
1437  edm::LogError("JetPlusTrackCorrector") << ss.str();
1438  }
1439 
1440  // Check
1441  if ( eta_.size() != data_.size() ||
1442  pt_.size() != ( data_.empty() ? 0 : data_[0].size() ) ) {
1443  std::stringstream ss;
1444  ss << "[jpt::Map::" << __func__ << "]"
1445  << " Discrepancy b/w number of bins!";
1446  edm::LogError("JetPlusTrackCorrector") << ss.str();
1447  }
1448 
1449  // Debug
1450  if ( verbose && edm::isDebugEnabled() ) {
1451  std::stringstream ss;
1452  ss << "[jpt::Map::" << __func__ << "]"
1453  << " Parsed contents of map at location:" << std::endl
1454  << "\"" << file << "\"" << std::endl;
1455  print(ss);
1456  LogTrace("JetPlusTrackCorrector") << ss.str();
1457  }
1458 
1459 }
1460 
1461 // -----------------------------------------------------------------------------
1462 //
1464  : eta_(),
1465  pt_(),
1466  data_()
1467 {
1468  clear();
1469 }
1470 
1471 // -----------------------------------------------------------------------------
1472 //
1474  clear();
1475 }
1476 
1477 // -----------------------------------------------------------------------------
1478 //
1479 void Map::clear() {
1480  eta_.clear();
1481  pt_.clear();
1482  data_.clear();
1483 }
1484 // -----------------------------------------------------------------------------
1485 //
1486 double Map::eta( uint32_t eta_bin ) const {
1487  if ( !eta_.empty() && eta_bin < eta_.size() ) { return eta_[eta_bin]; }
1488  else {
1489 // edm::LogWarning("JetPlusTrackCorrector")
1490 // << "[jpt::Map::" << __func__ << "]"
1491 // << " Trying to access element " << eta_bin
1492 // << " of a vector with size " << eta_.size()
1493 // << "!";
1494  return eta_[eta_.size()-1];
1495  }
1496 }
1497 
1498 // -----------------------------------------------------------------------------
1499 //
1500 double Map::pt( uint32_t pt_bin ) const {
1501  if ( !pt_.empty() && pt_bin < pt_.size() ) { return pt_[pt_bin]; }
1502  else {
1503 // edm::LogWarning("JetPlusTrackCorrector")
1504 // << "[jpt::Map::" << __func__ << "]"
1505 // << " Trying to access element " << pt_bin
1506 // << " of a vector with size " << pt_.size()
1507 // << "!";
1508  return pt_[pt_.size()-1];
1509  }
1510 }
1511 
1512 // -----------------------------------------------------------------------------
1513 //
1514 double Map::binCenterEta( uint32_t eta_bin ) const {
1515  if ( !eta_.empty() && eta_bin+1 < eta_.size() ) {
1516  return eta_[eta_bin] + ( eta_[eta_bin+1] - eta_[eta_bin] ) / 2.;
1517  } else {
1518 // edm::LogWarning("JetPlusTrackCorrector")
1519 // << "[jpt::Map::" << __func__ << "]"
1520 // << " Trying to access element " << eta_bin+1
1521 // << " of a vector with size " << eta_.size()
1522 // << "!";
1523  return eta_[eta_.size()-1];
1524  }
1525 }
1526 
1527 // -----------------------------------------------------------------------------
1528 //
1529 double Map::binCenterPt( uint32_t pt_bin ) const {
1530  if ( !pt_.empty() && pt_bin+1 < pt_.size() ) {
1531  return pt_[pt_bin] + ( pt_[pt_bin+1] - pt_[pt_bin] ) / 2.;
1532  } else {
1533 // edm::LogWarning("JetPlusTrackCorrector")
1534 // << "[jpt::Map::" << __func__ << "]"
1535 // << " Trying to access element " << pt_bin+1
1536 // << " of a vector with size " << pt_.size()
1537 // << "!";
1538  return pt_[pt_.size()-1];
1539  }
1540 }
1541 
1542 // -----------------------------------------------------------------------------
1543 //
1544 uint32_t Map::etaBin( double val ) const {
1545  val = fabs( val );
1546  for ( uint32_t ieta = 0; ieta < nEtaBins()-1; ++ieta ) { //@@ "-1" is bug?
1547  if ( val > eta(ieta) && ( ieta+1 == nEtaBins() || val < eta(ieta+1) ) ) { return ieta; }
1548  }
1549  return nEtaBins();
1550 }
1551 
1552 // -----------------------------------------------------------------------------
1553 //
1554 uint32_t Map::ptBin( double val ) const {
1555  val = fabs( val );
1556  for ( uint32_t ipt = 0; ipt < nPtBins()-1; ++ipt ) { //@@ "-1" is bug?
1557  if ( val > pt(ipt) && ( (ipt+1) == nPtBins() || val < pt(ipt+1) ) ) { return ipt; }
1558  }
1559  return nPtBins();
1560 }
1561 
1562 // -----------------------------------------------------------------------------
1563 //
1564 double Map::value( uint32_t eta_bin, uint32_t pt_bin ) const {
1565  if ( eta_bin < data_.size() &&
1566  pt_bin < ( data_.empty() ? 0 : data_[0].size() ) ) { return data_[eta_bin][pt_bin]; }
1567  else {
1568 // edm::LogWarning("JetPlusTrackCorrector")
1569 // << "[jpt::Map::" << __func__ << "]"
1570 // << " Trying to access element (" << eta_bin << "," << pt_bin << ")"
1571 // << " of a vector with size (" << data_.size() << "," << ( data_.empty() ? 0 : data_[0].size() ) << ")"
1572 // << "!";
1573  return 1.;
1574  }
1575 }
1576 
1577 // -----------------------------------------------------------------------------
1578 //
1579 void Map::print( std::stringstream& ss ) const {
1580  ss << " Number of bins in eta : " << data_.size() << std::endl
1581  << " Number of bins in pt : " << ( data_.empty() ? 0 : data_[0].size() ) << std::endl;
1582  VVDouble::const_iterator ieta = data_.begin();
1583  VVDouble::const_iterator jeta = data_.end();
1584  for ( ; ieta != jeta; ++ieta ) {
1585  VDouble::const_iterator ipt = ieta->begin();
1586  VDouble::const_iterator jpt = ieta->end();
1587  for ( ; ipt != jpt; ++ipt ) {
1588  uint32_t eta_bin = static_cast<uint32_t>( ieta - data_.begin() );
1589  uint32_t pt_bin = static_cast<uint32_t>( ipt - ieta->begin() );
1590  ss << " EtaBinNumber: " << eta_bin
1591  << " PtBinNumber: " << pt_bin
1592  << " EtaValue: " << eta_[ eta_bin ]
1593  << " PtValue: " << pt_[ pt_bin ]
1594  << " Value: " << data_[eta_bin][pt_bin]
1595  << std::endl;
1596  }
1597  }
1598 }
1599 
1600 // -----------------------------------------------------------------------------
1601 //
1603  : inVertexInCalo_(),
1604  outOfVertexInCalo_(),
1605  inVertexOutOfCalo_()
1606 {
1607  clear();
1608 }
1609 
1610 // -----------------------------------------------------------------------------
1611 //
1613  clear();
1614 }
1615 
1616 // -----------------------------------------------------------------------------
1617 //
1622 }
1623 
1624 // -----------------------------------------------------------------------------
1625 //
1627  : vertex_(),
1628  caloFace_()
1629 {
1630  clear();
1631 }
1632 
1633 // -----------------------------------------------------------------------------
1634 //
1636  clear();
1637 }
1638 
1639 // -----------------------------------------------------------------------------
1640 //
1642  vertex_.clear();
1643  caloFace_.clear();
1644 }
1645 
1646 // -----------------------------------------------------------------------------
1647 //
1649  const jpt::Map& efficiency,
1650  const jpt::Map& leakage )
1651  : response_(response),
1652  efficiency_(efficiency),
1653  leakage_(leakage)
1654 {
1655  reset();
1656 }
1657 
1658 // -----------------------------------------------------------------------------
1659 //
1660 double Efficiency::inConeCorr( uint32_t eta_bin, uint32_t pt_bin ) const {
1661  if ( check(eta_bin,pt_bin,__func__) ) {
1662  return ( outOfConeCorr( eta_bin, pt_bin ) *
1663  leakage_.value( eta_bin, pt_bin ) *
1664  response_.value( eta_bin, pt_bin ) );
1665  } else { return 0.; }
1666 }
1667 
1668 // -----------------------------------------------------------------------------
1669 //
1670 double Efficiency::outOfConeCorr( uint32_t eta_bin, uint32_t pt_bin ) const {
1671  if ( check(eta_bin,pt_bin,__func__) ) {
1672  uint16_t ntrks = nTrks( eta_bin, pt_bin );
1673  double mean = meanE( eta_bin, pt_bin );
1674  double eff = ( 1. - efficiency_.value( eta_bin, pt_bin ) ) / efficiency_.value( eta_bin, pt_bin );
1675  if ( !ntrks ) { return 0.; }
1676  return ( ntrks * eff * mean );
1677  } else { return 0.; }
1678 }
1679 
1680 // -----------------------------------------------------------------------------
1681 //
1682 uint16_t Efficiency::nTrks( uint32_t eta_bin, uint32_t pt_bin ) const {
1683  if ( check(eta_bin,pt_bin,__func__) ) {
1684  return data_[eta_bin][pt_bin].first;
1685  } else { return 0; }
1686 }
1687 
1688 // -----------------------------------------------------------------------------
1689 //
1690 double Efficiency::sumE( uint32_t eta_bin, uint32_t pt_bin ) const {
1691  if ( check(eta_bin,pt_bin,__func__) ) {
1692  return data_[eta_bin][pt_bin].second;
1693  } else { return 0.; }
1694 }
1695 
1696 // -----------------------------------------------------------------------------
1697 //
1698 double Efficiency::meanE( uint32_t eta_bin, uint32_t pt_bin ) const {
1699  if ( check(eta_bin,pt_bin,__func__) ) {
1700  Pair tmp = data_[eta_bin][pt_bin];
1701  if ( tmp.first ) { return tmp.second / tmp.first; }
1702  else { return 0.; }
1703  } else { return 0.; }
1704 }
1705 
1706 // -----------------------------------------------------------------------------
1707 //
1708 void Efficiency::addE( uint32_t eta_bin, uint32_t pt_bin, double energy ) {
1709  if ( check(eta_bin,pt_bin,__func__) ) {
1710  data_[eta_bin][pt_bin].first++;
1711  data_[eta_bin][pt_bin].second += energy;
1712  }
1713 }
1714 
1715 // -----------------------------------------------------------------------------
1716 //
1717 bool Efficiency::check( uint32_t eta_bin, uint32_t pt_bin, std::string method ) const {
1718  if ( eta_bin < data_.size() && pt_bin < ( data_.empty() ? 0 : data_[0].size() ) ) { return true; }
1719  else {
1720 // edm::LogWarning("JetPlusTrackCorrector")
1721 // << "[jpt::Efficiency::" << method << "]"
1722 // << " Trying to access element (" << eta_bin << "," << pt_bin << ")"
1723 // << " of a vector with size (" << data_.size() << "," << ( data_.empty() ? 0 : data_[0].size() ) << ")"
1724 // << "!";
1725  return false;
1726  }
1727 }
1728 
1729 // -----------------------------------------------------------------------------
1730 //
1732  data_.clear();
1733  data_.resize( response_.nEtaBins(), VPair( response_.nPtBins(), Pair(0,0.) ) );
1734 }
1735 
1736 // -----------------------------------------------------------------------------
1737 //
1738 void Efficiency::print() const {
1739  if ( edm::isDebugEnabled() ) {
1740  std::stringstream ss;
1741  ss << "[jpt::Efficiency::" << __func__ << "]"
1742  << " Contents of maps:" << std::endl;
1743  ss << "Response map: " << std::endl;
1744  response_.print(ss);
1745  ss << "Efficiency map: " << std::endl;
1746  efficiency_.print(ss);
1747  ss << "Leakage map: " << std::endl;
1748  leakage_.print(ss);
1749  LogTrace("JetPlusTrackCorrector") << ss.str();
1750  }
1751 }
#define LogDebug(id)
math::XYZTLorentzVector P4
T getParameter(std::string const &) const
bool isDebugEnabled()
uint32_t nEtaBins() const
double eta() const final
momentum pseudorapidity
double eta(uint32_t) const
edm::EDGetTokenT< RecoMuons > inut_reco_muons_token_
double meanE(uint32_t eta_bin, uint32_t pt_bin) const
Base class for all types of Jets.
Definition: Jet.h:20
double px() const final
x coordinate of momentum vector
const jpt::Map & responseMap() const
reco::TrackRefVector inVertexInCalo_
bool matchTracks(const reco::Jet &, const edm::Event &, const edm::EventSetup &, jpt::MatchedTracks &pions, jpt::MatchedTracks &muons, jpt::MatchedTracks &elecs)
Matches tracks to different particle types.
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
double pt() const final
transverse momentum
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
reco::TrackRefVector vertex_
void addE(uint32_t eta_bin, uint32_t pt_bin, double energy)
reco::TrackRefVector inVertexOutOfCalo_
P4 calculateCorr(const P4 &jet, const TrackRefs &, jpt::Efficiency &, bool in_cone_at_vertex, bool in_cone_at_calo_face, double mass, bool is_pion, double mip)
Generic method to calculates 4-momentum correction to be applied.
reco::GsfElectronCollection RecoElectrons
std::pair< uint16_t, double > Pair
Container class for response & efficiency maps.
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:20
uint32_t etaBin(double eta) const
bool empty() const
Is the RefVector empty.
Definition: RefVector.h:104
double checkScale(const P4 &jet, P4 &corrected) const
Check corrected 4-momentum does not give negative scale.
const jpt::Map & efficiency_
ProductID id() const
Accessor for product ID.
Definition: Ref.h:257
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:248
P4 pionCorrection(const P4 &jet, const jpt::MatchedTracks &pions)
Calculates corrections to be applied using pions.
edm::EDGetTokenT< RecoElectronIds > input_reco_elec_ids_token_
static std::string const input
Definition: EdmProvDump.cc:48
const jpt::Map & efficiencyMap() const
bool tracksInCalo(const jpt::MatchedTracks &pions, const jpt::MatchedTracks &muons, const jpt::MatchedTracks &elecs) const
Determines if any tracks in cone at CaloFace.
reco::Particle::Point vertex_
Efficiency()=delete
edm::EDGetTokenT< RecoElectrons > input_reco_elecs_token_
bool canCorrect(const reco::Jet &) const
Can jet be JPT-corrected?
const jpt::Map & response_
double et() const final
transverse energy
reco::TrackRefVector caloFace_
double pz() const final
z coordinate of momentum vector
void print(std::stringstream &ss) const
T sqrt(T t)
Definition: SSEVec.h:18
double pt(uint32_t) const
double correction(const reco::Jet &, const reco::Jet &, const edm::Event &, const edm::EventSetup &, P4 &, jpt::MatchedTracks &pions, jpt::MatchedTracks &muons, jpt::MatchedTracks &elecs, bool &validMatches)
Vectorial correction method (corrected 4-momentum passed by reference)
bool findTrack(const jpt::JetTracks &, TrackRefs::const_iterator &, TrackRefs::iterator &) const
Find track in JetTracks collection.
const jpt::Map & leakageMap() const
double energy() const final
energy
double binCenterPt(uint32_t) const
math::XYZPoint Point
point in the space
Definition: Particle.h:25
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
reco::TrackRefVector outOfVertexInCalo_
bool matchMuons(TrackRefs::const_iterator &, const edm::Handle< RecoMuons > &) const
Matches tracks to RECO muons.
P4 pionEfficiency(const P4 &jet, const jpt::Efficiency &, bool in_cone_at_calo_face)
Correction to be applied using tracking efficiency.
bool failTrackQuality(TrackRefs::const_iterator &) const
Check on track quality.
const LorentzVector & p4() const final
four-momentum Lorentz vector
Definition: LeafCandidate.h:99
const reco::TrackRefVector & getValue(const Container &, const reco::JetBaseRef &)
get value for the association. Throw exception if no association found
double outOfConeCorr(uint32_t eta_bin, uint32_t pt_bin) const
double inConeCorr(uint32_t eta_bin, uint32_t pt_bin) const
bool isValid() const
Definition: HandleBase.h:74
double correctAA(const reco::Jet &, const reco::TrackRefVector &, double &, const reco::TrackRefVector &, const reco::TrackRefVector &, double, const reco::TrackRefVector &) const
For AA - correct in tracker.
virtual ~JetPlusTrackCorrector()
Destructor.
void rebuildJta(const reco::Jet &, const JetTracksAssociations &, TrackRefs &included, TrackRefs &excluded) const
Rebuild jet-track association.
#define LogTrace(id)
bool getMuons(const edm::Event &, edm::Handle< RecoMuons > &) const
Get RECO muons.
JetCorrectorParameters corr
Definition: classes.h:5
bool isGoodMuon(const reco::Muon &muon, SelectionType type, reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration)
main GoodMuon wrapper call
ii
Definition: cuy.py:590
#define M_PI
double sumE(uint32_t eta_bin, uint32_t pt_bin) const
bool failedToGet() const
Definition: HandleBase.h:78
std::vector< reco::JetBaseRef > allJets(const Container &)
fill list of all jets associated with values. Return # of jets in the list
P4 elecCorrection(const P4 &jet, const jpt::MatchedTracks &elecs) const
Calculates correction to be applied using electrons.
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
T const * product() const
Definition: Handle.h:74
void clear()
Clear the vector.
Definition: RefVector.h:147
void excludeJta(const reco::Jet &, const JetTracksAssociations &, TrackRefs &included, const TrackRefs &excluded) const
Exclude jet-track association.
Tracks associated to jets that are in-cone at Vertex and CaloFace.
bool getElectrons(const edm::Event &, edm::Handle< RecoElectrons > &, edm::Handle< RecoElectronIds > &) const
Get RECO electrons.
std::vector< double > pt_
double py() const final
y coordinate of momentum vector
reco::TrackBase::TrackQuality trackQuality_
std::vector< Pair > VPair
P4 muonCorrection(const P4 &jet, const jpt::MatchedTracks &muons)
Calculates correction to be applied using muons.
std::string const & label() const
Definition: InputTag.h:36
std::vector< double > eta_
std::string const & process() const
Definition: InputTag.h:40
Particles matched to tracks that are in/in, in/out, out/in at Vertex and CaloFace.
bool check(uint32_t eta_bin, uint32_t pt_bin, std::string name="check") const
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
fixed size matrix
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
uint16_t nTrks(uint32_t eta_bin, uint32_t pt_bin) const
bool jtaUsingEventData(const reco::Jet &, const edm::Event &, jpt::JetTracks &) const
JTA using collections from event.
uint32_t nPtBins() const
uint32_t ptBin(double pt) const
void push_back(value_type const &ref)
Add a Ref<C, T> to the RefVector.
Definition: RefVector.h:69
size_type size() const
Size of the RefVector.
Definition: RefVector.h:107
std::string fullPath() const
Definition: FileInPath.cc:163
JetPlusTrackCorrector()
Default constructor.
edm::EDGetTokenT< reco::JetTracksAssociation::Container > input_jetTracksAtCalo_token_
P4 jetDirFromTracks(const P4 &jet, const jpt::MatchedTracks &pions, const jpt::MatchedTracks &muons, const jpt::MatchedTracks &elecs) const
Calculates vectorial correction using total track 3-momentum.
double value(uint32_t eta_bin, uint32_t pt_bin) const
edm::EDGetTokenT< reco::JetTracksAssociation::Container > input_jetTracksAtVertex_token_
reco::MuonCollection RecoMuons
Get reponses.
edm::EDGetTokenT< reco::VertexCollection > input_pvCollection_token_
double phi() const final
momentum azimuthal angle
double binCenterEta(uint32_t) const
Generic container class.
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:21
std::string const & instance() const
Definition: InputTag.h:37
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
std::vector< double > VDouble
virtual bool jetTrackAssociation(const reco::Jet &, const edm::Event &, const edm::EventSetup &, jpt::JetTracks &) const
Associates tracks to jets (overriden in derived class)
math::PtEtaPhiMLorentzVectorD PtEtaPhiM
Definition: event.py:1
bool matchElectrons(TrackRefs::const_iterator &, const edm::Handle< RecoElectrons > &, const edm::Handle< RecoElectronIds > &) const
Matches tracks to RECO electrons.
double mass() const final
mass
const jpt::Map & leakage_