CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
JetPlusTrackCorrector.cc
Go to the documentation of this file.
12 #include <fstream>
13 #include <vector>
14 #include <iomanip>
15 #include <math.h>
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,
117  MatchedTracks &elecs,
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,
245  jpt::MatchedTracks& elecs ) {
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->size()>0 ) 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;
691  Efficiency not_used( responseMap(), efficiencyMap(), leakageMap() );
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 //
1105  const edm::Handle<RecoElectrons>& elecs,
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.size() == 0) 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.size() == 0 ) return mScale;
1259  double EnergyOfBackgroundCharged = 0.;
1260  double ResponseOfBackgroundCharged = 0.;
1261  double NumberOfBackgroundChargedVertex = 0.;
1262  double NumberOfBackgroundChargedCalo = 0.;
1263 
1264 //
1265 // calculate the mean response
1266 //
1267 // double MeanResponseOfBackgroundCharged = 0.;
1268 // double MeanEnergyOfBackgroundCharged = 0.;
1269 
1270 //================= EnergyOfBackgroundCharged ==================>
1271  for( reco::TrackRefVector::iterator iBgtV = trBgOutOfVertex.begin(); iBgtV != trBgOutOfVertex.end(); iBgtV++)
1272  {
1273  // Temporary solution>>>>>> Remove tracks with pt>50 GeV
1274  // if( (**iBgtV).pt() >= 50. ) continue;
1275  //response_.value(ieta,ipt);
1276  double eta = fabs( (**iBgtV).eta() );
1277  double pt = fabs( (**iBgtV).pt() );
1278  uint32_t ieta = response_.etaBin( eta );
1279  uint32_t ipt = response_.ptBin( pt );
1280 
1281  if(fabs(fJet.eta() -(**iBgtV).eta()) > mConeSize) continue;
1282 
1283 // // Check bins (not for mips)
1284 // if ( ieta >= response_.nEtaBins() ) { continue; }
1285 // if ( ipt >= response_.nPtBins() ) { ipt = response_.nPtBins() - 1; }
1286 
1287  double echarBg=sqrt((**iBgtV).px()*(**iBgtV).px()+(**iBgtV).py()*(**iBgtV).py()+(**iBgtV).pz()*(**iBgtV).pz()+0.14*0.14);
1288 
1289 // ResponseOfBackgroundCharged += echarBg*response_.value(ieta,ipt)/efficiency_.value(ieta,ipt);
1290 
1291 // std::cout<<" Efficiency of bg tracks "<<efficiency_.value(ieta,ipt)<<std::endl;
1292 
1293  EnergyOfBackgroundCharged += echarBg/efficiency_.value(ieta,ipt);
1294 
1295  NumberOfBackgroundChargedVertex++;
1296 
1297  } // Energy BG tracks
1298 
1299 // std::cout<<" JetPlusTrackCorrector.cc, NumberOfBackgroundChargedVertex ="<<NumberOfBackgroundChargedVertex<<std::endl;
1300 
1301 //============= ResponseOfBackgroundCharged =======================>
1302 
1303  for( reco::TrackRefVector::iterator iBgtC = trBgOutOfCalo.begin(); iBgtC != trBgOutOfCalo.end(); iBgtC++)
1304  {
1305  // Temporary solution>>>>>> Remove tracks with pt>50 GeV
1306  // if( (**iBgtC).pt() >= 50. ) continue;
1307  //response_.value(ieta,ipt);
1308  double eta = fabs( (**iBgtC).eta() );
1309  double pt = fabs( (**iBgtC).pt() );
1310  uint32_t ieta = response_.etaBin( eta );
1311  uint32_t ipt = response_.ptBin( pt );
1312 
1313  if(fabs(fJet.eta() -(**iBgtC).eta()) > mConeSize) continue;
1314 
1315  // Check bins (not for mips)
1316  if ( ieta >= response_.nEtaBins() ) { continue; }
1317  if ( ipt >= response_.nPtBins() ) { ipt = response_.nPtBins() - 1; }
1318 
1319  double echarBg=sqrt((**iBgtC).px()*(**iBgtC).px()+(**iBgtC).py()*(**iBgtC).py()+(**iBgtC).pz()*(**iBgtC).pz()+0.14*0.14);
1320 
1321  ResponseOfBackgroundCharged += echarBg*response_.value(ieta,ipt)/efficiency_.value(ieta,ipt);
1322 
1323 // std::cout<<" Efficiency of bg tracks "<<efficiency_.value(ieta,ipt)<<std::endl;
1324 
1325 
1326  NumberOfBackgroundChargedCalo++;
1327 
1328  } // Response of BG tracks
1329 
1330 // std::cout<<" JetPlusTrackCorrector.cc, NumberOfBackgroundChargedCalo ="<<NumberOfBackgroundChargedCalo<<std::endl;
1331 //=================================================================>
1332 
1333 //=================================================================>
1334 // Look for in-out tracks
1335 
1336  double en = 0.;
1337  double px = 0.;
1338  double py = 0.;
1339  double pz = 0.;
1340 
1341  for(reco::TrackRefVector::const_iterator it = pioninout.begin(); it != pioninout.end(); it++) {
1342 
1343 // std::cout<<" Track in out, size= "<<pioninout.size()<<" p= "<<(*it)->p()<<" pt= "<<(*it)->pt()
1344 // <<" eta= "<<(*it)->eta()<<" phi= "<<(*it)->phi()<<std::endl;
1345 
1346  px+=(*it)->px();
1347  py+=(*it)->py();
1348  pz+=(*it)->pz();
1349  en+=sqrt((*it)->p()*(*it)->p()+0.14*0.14);
1350  }
1351 
1352 // Look for in-in tracks
1353 
1354  double en_in = 0.;
1355  double px_in = 0.;
1356  double py_in = 0.;
1357  double pz_in = 0.;
1358 
1359  for(reco::TrackRefVector::const_iterator it = pioninin.begin(); it != pioninin.end(); it++) {
1360 
1361 // std::cout<<" Track in in, size= "<<pioninin.size()<<" p= "<<(*it)->p()<<" pt= "<<(*it)->pt()
1362 // <<" eta= "<<(*it)->eta()<<" phi= "<<(*it)->phi()<<std::endl;
1363 
1364  px_in+=(*it)->px();
1365  py_in+=(*it)->py();
1366  pz_in+=(*it)->pz();
1367  en_in+=sqrt((*it)->p()*(*it)->p()+0.14*0.14);
1368  }
1369 
1370 
1371 //===================================================================>
1372 
1373 //=>
1374 // double SquareEtaRingWithoutJets = 4*(M_PI*mConeSize - mConeSize*mConeSize);
1375  double SquareEtaRingWithoutJets = ja;
1376 
1377 // std::cout<<"---SquareEtaRingWithoutJets="<<SquareEtaRingWithoutJets<<std::endl;
1378 
1379  EnergyOfBackgroundCharged = EnergyOfBackgroundCharged/SquareEtaRingWithoutJets;
1380  ResponseOfBackgroundCharged = ResponseOfBackgroundCharged/SquareEtaRingWithoutJets;
1381  NumberOfBackgroundChargedVertex = NumberOfBackgroundChargedVertex/SquareEtaRingWithoutJets;
1382  NumberOfBackgroundChargedCalo = NumberOfBackgroundChargedCalo/SquareEtaRingWithoutJets;
1383 // NumberOfBackgroundCharged = NumberOfBackgroundCharged/SquareEtaRingWithoutJets;
1384 
1385 
1386  EnergyOfBackgroundCharged = M_PI*mConeSize*mConeSize*EnergyOfBackgroundCharged;
1387  ResponseOfBackgroundCharged = M_PI*mConeSize*mConeSize*ResponseOfBackgroundCharged;
1388  NumberOfBackgroundChargedVertex = M_PI*mConeSize*mConeSize*NumberOfBackgroundChargedVertex;
1389  NumberOfBackgroundChargedCalo = M_PI*mConeSize*mConeSize*NumberOfBackgroundChargedCalo;
1390 // NumberOfBackgroundCharged = M_PI*mConeSize*mConeSize*NumberOfBackgroundCharged;
1391 
1392 
1393  NewResponse = NewResponse - EnergyOfBackgroundCharged + ResponseOfBackgroundCharged;
1394 
1395 // std::cout<<"====JetPlusTrackCorrector, Old response=fJet.energy()"<<fJet.energy()
1396 // <<" EnergyOfBackgroundCharged="<<EnergyOfBackgroundCharged
1397 // <<" ResponseOfBackgroundCharged="<<ResponseOfBackgroundCharged
1398 // <<" NewResponse="<<NewResponse<<" NumberOfBackgroundChargedVertex="<<NumberOfBackgroundChargedVertex
1399 // <<" NumberOfBackgroundChargedCalo="<<NumberOfBackgroundChargedCalo<<std::endl;
1400 
1401  mScale = NewResponse/fJet.energy();
1402  if(mScale <0.) mScale=0.;
1403 return mScale;
1404 }
1405 // -----------------------------------------------------------------------------
1406 //
1407 Map::Map( std::string input, bool verbose )
1408  : eta_(),
1409  pt_(),
1410  data_()
1411 {
1412 
1413  // Some init
1414  clear();
1415  std::vector<Element> data;
1416 
1417  // Parse file
1419  std::ifstream in( file.c_str() );
1420  string line;
1421  uint32_t ieta_old = 0;
1422  while ( std::getline( in, line ) ) {
1423  if ( !line.size() || line[0]=='#' ) { continue; }
1424  std::istringstream ss(line);
1425  Element temp;
1426  ss >> temp.ieta_ >> temp.ipt_ >> temp.eta_ >> temp.pt_ >> temp.val_;
1427  data.push_back(temp);
1428  if ( !ieta_old || temp.ieta_ != ieta_old ) {
1429  if ( eta_.size() < temp.ieta_+1 ) { eta_.resize(temp.ieta_+1,0.); }
1430  eta_[temp.ieta_] = temp.eta_;
1431  ieta_old = temp.ieta_;
1432  }
1433  if ( pt_.size() < temp.ipt_+1 ) { pt_.resize(temp.ipt_+1,0.); }
1434  pt_[temp.ipt_] = temp.pt_;
1435  }
1436 
1437  // Populate container
1438  data_.resize( eta_.size(), VDouble( pt_.size(), 0. ) );
1439  std::vector<Element>::const_iterator idata = data.begin();
1440  std::vector<Element>::const_iterator jdata = data.end();
1441  for ( ; idata != jdata; ++idata ) { data_[idata->ieta_][idata->ipt_] = idata->val_; }
1442 
1443  // Check
1444  if ( data_.empty() || data_[0].empty() ) {
1445  std::stringstream ss;
1446  ss << "[jpt::Map::" << __func__ << "]"
1447  << " Problem parsing map in location \""
1448  << file << "\"! ";
1449  edm::LogError("JetPlusTrackCorrector") << ss.str();
1450  }
1451 
1452  // Check
1453  if ( eta_.size() != data_.size() ||
1454  pt_.size() != ( data_.empty() ? 0 : data_[0].size() ) ) {
1455  std::stringstream ss;
1456  ss << "[jpt::Map::" << __func__ << "]"
1457  << " Discrepancy b/w number of bins!";
1458  edm::LogError("JetPlusTrackCorrector") << ss.str();
1459  }
1460 
1461  // Debug
1462  if ( verbose && edm::isDebugEnabled() ) {
1463  std::stringstream ss;
1464  ss << "[jpt::Map::" << __func__ << "]"
1465  << " Parsed contents of map at location:" << std::endl
1466  << "\"" << file << "\"" << std::endl;
1467  print(ss);
1468  LogTrace("JetPlusTrackCorrector") << ss.str();
1469  }
1470 
1471 }
1472 
1473 // -----------------------------------------------------------------------------
1474 //
1476  : eta_(),
1477  pt_(),
1478  data_()
1479 {
1480  clear();
1481 }
1482 
1483 // -----------------------------------------------------------------------------
1484 //
1486  clear();
1487 }
1488 
1489 // -----------------------------------------------------------------------------
1490 //
1491 void Map::clear() {
1492  eta_.clear();
1493  pt_.clear();
1494  data_.clear();
1495 }
1496 // -----------------------------------------------------------------------------
1497 //
1498 double Map::eta( uint32_t eta_bin ) const {
1499  if ( !eta_.empty() && eta_bin < eta_.size() ) { return eta_[eta_bin]; }
1500  else {
1501 // edm::LogWarning("JetPlusTrackCorrector")
1502 // << "[jpt::Map::" << __func__ << "]"
1503 // << " Trying to access element " << eta_bin
1504 // << " of a vector with size " << eta_.size()
1505 // << "!";
1506  return eta_[eta_.size()-1];
1507  }
1508 }
1509 
1510 // -----------------------------------------------------------------------------
1511 //
1512 double Map::pt( uint32_t pt_bin ) const {
1513  if ( !pt_.empty() && pt_bin < pt_.size() ) { return pt_[pt_bin]; }
1514  else {
1515 // edm::LogWarning("JetPlusTrackCorrector")
1516 // << "[jpt::Map::" << __func__ << "]"
1517 // << " Trying to access element " << pt_bin
1518 // << " of a vector with size " << pt_.size()
1519 // << "!";
1520  return pt_[pt_.size()-1];
1521  }
1522 }
1523 
1524 // -----------------------------------------------------------------------------
1525 //
1526 double Map::binCenterEta( uint32_t eta_bin ) const {
1527  if ( !eta_.empty() && eta_bin+1 < eta_.size() ) {
1528  return eta_[eta_bin] + ( eta_[eta_bin+1] - eta_[eta_bin] ) / 2.;
1529  } else {
1530 // edm::LogWarning("JetPlusTrackCorrector")
1531 // << "[jpt::Map::" << __func__ << "]"
1532 // << " Trying to access element " << eta_bin+1
1533 // << " of a vector with size " << eta_.size()
1534 // << "!";
1535  return eta_[eta_.size()-1];
1536  }
1537 }
1538 
1539 // -----------------------------------------------------------------------------
1540 //
1541 double Map::binCenterPt( uint32_t pt_bin ) const {
1542  if ( !pt_.empty() && pt_bin+1 < pt_.size() ) {
1543  return pt_[pt_bin] + ( pt_[pt_bin+1] - pt_[pt_bin] ) / 2.;
1544  } else {
1545 // edm::LogWarning("JetPlusTrackCorrector")
1546 // << "[jpt::Map::" << __func__ << "]"
1547 // << " Trying to access element " << pt_bin+1
1548 // << " of a vector with size " << pt_.size()
1549 // << "!";
1550  return pt_[pt_.size()-1];
1551  }
1552 }
1553 
1554 // -----------------------------------------------------------------------------
1555 //
1556 uint32_t Map::etaBin( double val ) const {
1557  val = fabs( val );
1558  for ( uint32_t ieta = 0; ieta < nEtaBins()-1; ++ieta ) { //@@ "-1" is bug?
1559  if ( val > eta(ieta) && ( ieta+1 == nEtaBins() || val < eta(ieta+1) ) ) { return ieta; }
1560  }
1561  return nEtaBins();
1562 }
1563 
1564 // -----------------------------------------------------------------------------
1565 //
1566 uint32_t Map::ptBin( double val ) const {
1567  val = fabs( val );
1568  for ( uint32_t ipt = 0; ipt < nPtBins()-1; ++ipt ) { //@@ "-1" is bug?
1569  if ( val > pt(ipt) && ( (ipt+1) == nPtBins() || val < pt(ipt+1) ) ) { return ipt; }
1570  }
1571  return nPtBins();
1572 }
1573 
1574 // -----------------------------------------------------------------------------
1575 //
1576 double Map::value( uint32_t eta_bin, uint32_t pt_bin ) const {
1577  if ( eta_bin < data_.size() &&
1578  pt_bin < ( data_.empty() ? 0 : data_[0].size() ) ) { return data_[eta_bin][pt_bin]; }
1579  else {
1580 // edm::LogWarning("JetPlusTrackCorrector")
1581 // << "[jpt::Map::" << __func__ << "]"
1582 // << " Trying to access element (" << eta_bin << "," << pt_bin << ")"
1583 // << " of a vector with size (" << data_.size() << "," << ( data_.empty() ? 0 : data_[0].size() ) << ")"
1584 // << "!";
1585  return 1.;
1586  }
1587 }
1588 
1589 // -----------------------------------------------------------------------------
1590 //
1591 void Map::print( std::stringstream& ss ) const {
1592  ss << " Number of bins in eta : " << data_.size() << std::endl
1593  << " Number of bins in pt : " << ( data_.empty() ? 0 : data_[0].size() ) << std::endl;
1594  VVDouble::const_iterator ieta = data_.begin();
1595  VVDouble::const_iterator jeta = data_.end();
1596  for ( ; ieta != jeta; ++ieta ) {
1597  VDouble::const_iterator ipt = ieta->begin();
1598  VDouble::const_iterator jpt = ieta->end();
1599  for ( ; ipt != jpt; ++ipt ) {
1600  uint32_t eta_bin = static_cast<uint32_t>( ieta - data_.begin() );
1601  uint32_t pt_bin = static_cast<uint32_t>( ipt - ieta->begin() );
1602  ss << " EtaBinNumber: " << eta_bin
1603  << " PtBinNumber: " << pt_bin
1604  << " EtaValue: " << eta_[ eta_bin ]
1605  << " PtValue: " << pt_[ pt_bin ]
1606  << " Value: " << data_[eta_bin][pt_bin]
1607  << std::endl;
1608  }
1609  }
1610 }
1611 
1612 // -----------------------------------------------------------------------------
1613 //
1615  : inVertexInCalo_(),
1616  outOfVertexInCalo_(),
1617  inVertexOutOfCalo_()
1618 {
1619  clear();
1620 }
1621 
1622 // -----------------------------------------------------------------------------
1623 //
1625  clear();
1626 }
1627 
1628 // -----------------------------------------------------------------------------
1629 //
1634 }
1635 
1636 // -----------------------------------------------------------------------------
1637 //
1639  : vertex_(),
1640  caloFace_()
1641 {
1642  clear();
1643 }
1644 
1645 // -----------------------------------------------------------------------------
1646 //
1648  clear();
1649 }
1650 
1651 // -----------------------------------------------------------------------------
1652 //
1654  vertex_.clear();
1655  caloFace_.clear();
1656 }
1657 
1658 // -----------------------------------------------------------------------------
1659 //
1661  const jpt::Map& efficiency,
1662  const jpt::Map& leakage )
1663  : response_(response),
1664  efficiency_(efficiency),
1665  leakage_(leakage)
1666 {
1667  reset();
1668 }
1669 
1670 // -----------------------------------------------------------------------------
1671 //
1672 double Efficiency::inConeCorr( uint32_t eta_bin, uint32_t pt_bin ) const {
1673  if ( check(eta_bin,pt_bin,__func__) ) {
1674  return ( outOfConeCorr( eta_bin, pt_bin ) *
1675  leakage_.value( eta_bin, pt_bin ) *
1676  response_.value( eta_bin, pt_bin ) );
1677  } else { return 0.; }
1678 }
1679 
1680 // -----------------------------------------------------------------------------
1681 //
1682 double Efficiency::outOfConeCorr( uint32_t eta_bin, uint32_t pt_bin ) const {
1683  if ( check(eta_bin,pt_bin,__func__) ) {
1684  uint16_t ntrks = nTrks( eta_bin, pt_bin );
1685  double mean = meanE( eta_bin, pt_bin );
1686  double eff = ( 1. - efficiency_.value( eta_bin, pt_bin ) ) / efficiency_.value( eta_bin, pt_bin );
1687  if ( !ntrks ) { return 0.; }
1688  return ( ntrks * eff * mean );
1689  } else { return 0.; }
1690 }
1691 
1692 // -----------------------------------------------------------------------------
1693 //
1694 uint16_t Efficiency::nTrks( uint32_t eta_bin, uint32_t pt_bin ) const {
1695  if ( check(eta_bin,pt_bin,__func__) ) {
1696  return data_[eta_bin][pt_bin].first;
1697  } else { return 0; }
1698 }
1699 
1700 // -----------------------------------------------------------------------------
1701 //
1702 double Efficiency::sumE( uint32_t eta_bin, uint32_t pt_bin ) const {
1703  if ( check(eta_bin,pt_bin,__func__) ) {
1704  return data_[eta_bin][pt_bin].second;
1705  } else { return 0.; }
1706 }
1707 
1708 // -----------------------------------------------------------------------------
1709 //
1710 double Efficiency::meanE( uint32_t eta_bin, uint32_t pt_bin ) const {
1711  if ( check(eta_bin,pt_bin,__func__) ) {
1712  Pair tmp = data_[eta_bin][pt_bin];
1713  if ( tmp.first ) { return tmp.second / tmp.first; }
1714  else { return 0.; }
1715  } else { return 0.; }
1716 }
1717 
1718 // -----------------------------------------------------------------------------
1719 //
1720 void Efficiency::addE( uint32_t eta_bin, uint32_t pt_bin, double energy ) {
1721  if ( check(eta_bin,pt_bin,__func__) ) {
1722  data_[eta_bin][pt_bin].first++;
1723  data_[eta_bin][pt_bin].second += energy;
1724  }
1725 }
1726 
1727 // -----------------------------------------------------------------------------
1728 //
1729 bool Efficiency::check( uint32_t eta_bin, uint32_t pt_bin, std::string method ) const {
1730  if ( eta_bin < data_.size() && pt_bin < ( data_.empty() ? 0 : data_[0].size() ) ) { return true; }
1731  else {
1732 // edm::LogWarning("JetPlusTrackCorrector")
1733 // << "[jpt::Efficiency::" << method << "]"
1734 // << " Trying to access element (" << eta_bin << "," << pt_bin << ")"
1735 // << " of a vector with size (" << data_.size() << "," << ( data_.empty() ? 0 : data_[0].size() ) << ")"
1736 // << "!";
1737  return false;
1738  }
1739 }
1740 
1741 // -----------------------------------------------------------------------------
1742 //
1744  data_.clear();
1745  data_.resize( response_.nEtaBins(), VPair( response_.nPtBins(), Pair(0,0.) ) );
1746 }
1747 
1748 // -----------------------------------------------------------------------------
1749 //
1750 void Efficiency::print() const {
1751  if ( edm::isDebugEnabled() ) {
1752  std::stringstream ss;
1753  ss << "[jpt::Efficiency::" << __func__ << "]"
1754  << " Contents of maps:" << std::endl;
1755  ss << "Response map: " << std::endl;
1756  response_.print(ss);
1757  ss << "Efficiency map: " << std::endl;
1758  efficiency_.print(ss);
1759  ss << "Leakage map: " << std::endl;
1760  leakage_.print(ss);
1761  LogTrace("JetPlusTrackCorrector") << ss.str();
1762  }
1763 }
#define LogDebug(id)
math::XYZTLorentzVector P4
T getParameter(std::string const &) const
bool isDebugEnabled()
uint32_t nEtaBins() const
double eta(uint32_t) const
virtual double et() const
transverse energy
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
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.
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 &amp; efficiency maps.
int ii
Definition: cuy.py:588
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:255
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
uint32_t etaBin(double eta) const
bool empty() const
Is the RefVector empty.
Definition: RefVector.h:96
double checkScale(const P4 &jet, P4 &corrected) const
Check corrected 4-momentum does not give negative scale.
virtual double eta() const
momentum pseudorapidity
virtual double pt() const
transverse momentum
const jpt::Map & efficiency_
ProductID id() const
Accessor for product ID.
Definition: Ref.h:258
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:250
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:43
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.
virtual double mass() const
mass
virtual double energy() const
energy
reco::Particle::Point vertex_
edm::EDGetTokenT< RecoElectrons > input_reco_elecs_token_
bool canCorrect(const reco::Jet &) const
Can jet be JPT-corrected?
const jpt::Map & response_
reco::TrackRefVector caloFace_
void print(std::stringstream &ss) const
T sqrt(T t)
Definition: SSEVec.h:48
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 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.
double deltaR2(const T1 &t1, const T2 &t2)
Definition: deltaR.h:36
bool failTrackQuality(TrackRefs::const_iterator &) const
Check on track quality.
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
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
bool isValid() const
Definition: HandleBase.h:75
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)
#define M_PI
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
double sumE(uint32_t eta_bin, uint32_t pt_bin) const
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
bool failedToGet() const
Definition: HandleBase.h:79
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.
T const * product() const
Definition: Handle.h:81
void clear()
Clear the vector.
Definition: RefVector.h:139
virtual double px() const
x coordinate of momentum vector
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.
tuple tracks
Definition: testEve_cfg.py:39
bool getElectrons(const edm::Event &, edm::Handle< RecoElectrons > &, edm::Handle< RecoElectronIds > &) const
Get RECO electrons.
std::vector< double > pt_
reco::TrackBase::TrackQuality trackQuality_
virtual double pz() const
z coordinate of momentum vector
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:43
std::vector< double > eta_
std::string const & process() const
Definition: InputTag.h:47
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
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
tuple muons
Definition: patZpeak.py:38
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&lt;C, T&gt; to the RefVector.
Definition: RefVector.h:62
size_type size() const
Size of the RefVector.
Definition: RefVector.h:99
JetPlusTrackCorrector()
Default constructor.
edm::EDGetTokenT< reco::JetTracksAssociation::Container > input_jetTracksAtCalo_token_
std::string fullPath() const
Definition: FileInPath.cc:165
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_
virtual double phi() const
momentum azimuthal angle
virtual const LorentzVector & p4() const
four-momentum Lorentz vector
Definition: LeafCandidate.h:99
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:44
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
virtual double py() const
y coordinate of momentum vector
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
bool matchElectrons(TrackRefs::const_iterator &, const edm::Handle< RecoElectrons > &, const edm::Handle< RecoElectronIds > &) const
Matches tracks to RECO electrons.
const jpt::Map & leakage_