CMS 3D CMS Logo

HPSPFRecoTauAlgorithm.cc
Go to the documentation of this file.
2 #include "Math/GenVector/VectorUtil.h"
4 using namespace reco;
5 
8 {
9 }
10 
13 {
14  configure(config);
15 }
16 
18 {
19  if(candidateMerger_ !=nullptr ) delete candidateMerger_;
20 }
21 
22 PFTau
24 {
25  PFTau pfTau;
26 
27  pfTaus_.clear();
28  //make the strips globally.
29  std::vector<std::vector<CandidatePtr> > strips = candidateMerger_->mergeCandidates(tagInfo->PFCands());
30 
31 
32  //Sort the hadrons globally and once!
33  std::vector<CandidatePtr> hadrons = tagInfo->PFChargedHadrCands();
34  if(hadrons.size()>1)
36 
37 
38  //OK For this Tau Tag Info we should create all the possible taus
39 
40  //One Prongs
41  if(doOneProngs_)
42  buildOneProng(tagInfo,hadrons);
43 
44  //One Prong Strips
46  buildOneProngStrip(tagInfo,strips,hadrons);
47 
48  //One Prong TwoStrips
50  buildOneProngTwoStrips(tagInfo,strips,hadrons);
51 
52  //Three Prong
53  if(doThreeProngs_)
54  buildThreeProngs(tagInfo,hadrons);
55 
56 
57  //Lets see if we created any taus
58  if(!pfTaus_.empty()) {
59 
61 
62  //Set the IP for the leading track
65  if(pfTau.pfTauTagInfoRef().isNonnull())
66  if(pfTau.pfTauTagInfoRef()->pfjetRef().isNonnull()) {
67  JetBaseRef jet = pfTau.pfTauTagInfoRef()->pfjetRef();
68  GlobalVector jetDir(jet->px(),jet->py(),jet->pz());
69  if(IPTools::signedTransverseImpactParameter(leadTrack,jetDir,vertex).first)
70  pfTau.setleadPFChargedHadrCandsignedSipt(IPTools::signedTransverseImpactParameter(leadTrack,jetDir,vertex).second.significance());
71  }
72  }
73  }
74  else { //null PFTau
75  //Simone asked that in case there is no tau returned make a tau
76  //without refs and the LV of the jet
77  pfTau.setpfTauTagInfoRef(tagInfo);
78  pfTau.setP4(tagInfo->pfjetRef()->p4());
79  }
80 
81  return pfTau;
82 }
83 
84 
85 
86 //Create one prong tau
87 void
88 HPSPFRecoTauAlgorithm::buildOneProng(const reco::PFTauTagInfoRef& tagInfo,const std::vector<reco::CandidatePtr>& hadrons)
89 {
91 
92  if(!hadrons.empty())
93  for(unsigned int h=0;h<hadrons.size();++h) {
94  CandidatePtr hadron = hadrons[h];
95 
96  //In the one prong case the lead Track pt should be above the tau Threshold!
97  //since all the tau is just one track!
98  if(hadron->pt()>tauThreshold_)
99  if(hadron->pt()>leadPionThreshold_)
100  //The track should be within the matching cone
101  if(ROOT::Math::VectorUtil::DeltaR(hadron->p4(),tagInfo->pfjetRef()->p4())<matchingCone_) {
102  //OK Lets create a Particle Flow Tau!
103  PFTau tau = PFTau(hadron->charge(),hadron->p4(),hadron->vertex());
104 
105  //Associate the Tag Info to the tau
106  tau.setpfTauTagInfoRef(tagInfo);
107 
108  //Put the Hadron in the signal Constituents
109  std::vector<CandidatePtr> signal;
110  signal.push_back(hadron);
111 
112  //Set The signal candidates of the PF Tau
113  tau.setsignalChargedHadrCands(signal);
114  tau.setsignalCands(signal);
115  tau.setleadChargedHadrCand(hadron);
116  tau.setleadCand(hadron);
117 
118  //Fill isolation variables
120 
121  //Apply Muon rejection algorithms
122  applyMuonRejection(tau);
123  applyElectronRejection(tau,0.0);
124 
125  //Save this candidate
126  taus.push_back(tau);
127  }
128  }
129  if(!taus.empty()) {
130  pfTaus_.push_back(getBestTauCandidate(taus));
131  }
132 
133 }
134 
135 //Build one Prong + Strip
136 
137 void
138 HPSPFRecoTauAlgorithm::buildOneProngStrip(const reco::PFTauTagInfoRef& tagInfo,const std::vector<std::vector<CandidatePtr> >& strips,const std::vector<reco::CandidatePtr> & hadrons)
139 
140 {
141  //Create output Collection
143 
144 
145 
146 
147  //make taus like this only if there is at least one hadron+ 1 strip
148  if(!hadrons.empty()&&!strips.empty()){
149  //Combinatorics between strips and clusters
150  for(std::vector<std::vector<CandidatePtr>>::const_iterator candVector=strips.begin();candVector!=strips.end();++candVector)
151  for(std::vector<CandidatePtr>::const_iterator hadron=hadrons.begin();hadron!=hadrons.end();++hadron) {
152 
153  //First Cross cleaning ! If you asked to clusterize the candidates
154  //with tracks too then you should not double count the track
155  std::vector<CandidatePtr> emConstituents = *candVector;
156  removeCandidateFromRefVector(*hadron,emConstituents);
157 
158  //Create a LorentzVector for the strip
160 
161  //TEST: Apply Strip Constraint
162  applyMassConstraint(strip,0.1349);
163 
164  //create the Particle Flow Tau: Hadron plus Strip
165  PFTau tau((*hadron)->charge(),
166  (*hadron)->p4()+strip,
167  (*hadron)->vertex());
168 
169  //Check tau threshold, mass, Matching Cone window
170  if(tau.pt()>tauThreshold_&&strip.pt()>stripPtThreshold_)
171  if(tau.mass()>oneProngStripMassWindow_[0]&&tau.mass()<oneProngStripMassWindow_[1])//Apply mass window
172  if(ROOT::Math::VectorUtil::DeltaR(tau.p4(),tagInfo->pfjetRef()->p4())<matchingCone_) { //Apply matching cone
173  //Set The Tag Infor ref
174  tau.setpfTauTagInfoRef(tagInfo);
175 
176  //Create the signal vectors
177  std::vector<CandidatePtr> signal;
178  std::vector<CandidatePtr> signalH;
179  std::vector<CandidatePtr> signalG;
180 
181  //Store the hadron in the PFTau
182  signalH.push_back(*hadron);
183  signal.push_back(*hadron);
184 
185  //calculate the cone size : For the strip use it as one candidate !
186  double tauCone=0.0;
187  if(coneMetric_ =="angle")
188  tauCone=std::max(fabs(ROOT::Math::VectorUtil::Angle(tau.p4(),(*hadron)->p4())),
189  fabs(ROOT::Math::VectorUtil::Angle(tau.p4(),strip)));
190  else if(coneMetric_ == "DR")
191  tauCone=std::max(ROOT::Math::VectorUtil::DeltaR(tau.p4(),(*hadron)->p4()),
193 
194  if(!emConstituents.empty())
195  for(std::vector<CandidatePtr>::const_iterator j=emConstituents.begin();j!=emConstituents.end();++j) {
196  signal.push_back(*j);
197  signalG.push_back(*j);
198  }
199 
200  //Set the PFTau
201  tau.setsignalChargedHadrCands(signalH);
202  tau.setsignalGammaCands(signalG);
203  tau.setsignalCands(signal);
204  tau.setleadChargedHadrCand(*hadron);
205  tau.setleadNeutralCand(emConstituents[0]);
206 
207  //Set the lead Candidate->Can be the hadron or the leading PFGamma(When we clear the Dataformat we will put the strip)
208  if((*hadron)->pt()>emConstituents[0]->pt())
209  tau.setleadCand(*hadron);
210  else
211  tau.setleadCand(emConstituents[0]);
212 
213  //Apply the signal cone size formula
214  if(isNarrowTau(tau,tauCone)) {
215  //calculate the isolation Deposits
217  //Set Muon Rejection
219  applyElectronRejection(tau,strip.energy());
220 
221  taus.push_back(tau);
222  }
223  }
224  }
225  }
226 
227  if(!taus.empty()) {
228  pfTaus_.push_back(getBestTauCandidate(taus));
229  }
230 
231 }
232 
233 void
234 HPSPFRecoTauAlgorithm::buildOneProngTwoStrips(const reco::PFTauTagInfoRef& tagInfo,const std::vector<std::vector<CandidatePtr> >& strips,const std::vector<reco::CandidatePtr>& hadrons)
235 {
236 
237 
239 
240  //make taus like this only if there is at least one hadron+ 2 strips
241  if(!hadrons.empty()&&strips.size()>1){
242  //Combinatorics between strips and clusters
243  for(unsigned int Nstrip1=0;Nstrip1<strips.size()-1;++Nstrip1)
244  for(unsigned int Nstrip2=Nstrip1+1;Nstrip2<strips.size();++Nstrip2)
245  for(std::vector<CandidatePtr>::const_iterator hadron=hadrons.begin();hadron!=hadrons.end();++hadron) {
246 
247 
248 
249  //Create the strips and the vectors .Again cross clean the track if associated
250  std::vector<CandidatePtr> emConstituents1 = strips[Nstrip1];
251  std::vector<CandidatePtr> emConstituents2 = strips[Nstrip2];
252  removeCandidateFromRefVector(*hadron,emConstituents1);
253  removeCandidateFromRefVector(*hadron,emConstituents2);
254 
255 
256  //Create a LorentzVector for the strip
257  math::XYZTLorentzVector strip1 = createMergedLorentzVector(emConstituents1);
258  math::XYZTLorentzVector strip2 = createMergedLorentzVector(emConstituents2);
259 
260 
261 
262  //Apply Mass Constraints
263  applyMassConstraint(strip1,0.0);
264  applyMassConstraint(strip2,0.0);
265 
266 
267  PFTau tau((*hadron)->charge(),
268  (*hadron)->p4()+strip1+strip2,
269  (*hadron)->vertex());
270 
271 
272  if(tau.pt()>tauThreshold_&&strip1.pt()>stripPtThreshold_&&strip2.pt()>stripPtThreshold_)
273  if((strip1+strip2).M() >oneProngTwoStripsPi0MassWindow_[0] &&(strip1+strip2).M() <oneProngTwoStripsPi0MassWindow_[1] )//pi0 conmstraint for two strips
274  if(tau.mass()>oneProngTwoStripsMassWindow_[0]&&tau.mass()<oneProngTwoStripsMassWindow_[1] )//Apply mass window
275  if(ROOT::Math::VectorUtil::DeltaR(tau.p4(),tagInfo->pfjetRef()->p4())<matchingCone_) { //Apply matching cone
276  //create the PFTau
277  tau.setpfTauTagInfoRef(tagInfo);
278 
279 
280  //Create the signal vectors
281  std::vector<CandidatePtr> signal;
282  std::vector<CandidatePtr> signalH;
283  std::vector<CandidatePtr> signalG;
284 
285  //Store the hadron in the PFTau
286  signalH.push_back(*hadron);
287  signal.push_back(*hadron);
288 
289  //calculate the cone size from the reconstructed Objects
290  double tauCone=1000.0;
291  if(coneMetric_ =="angle") {
292  tauCone=std::max(std::max(fabs(ROOT::Math::VectorUtil::Angle(tau.p4(),(*hadron)->p4())),
293  fabs(ROOT::Math::VectorUtil::Angle(tau.p4(),strip1))),
294  fabs(ROOT::Math::VectorUtil::Angle(tau.p4(),strip2)));
295  }
296  else if(coneMetric_ =="DR") {
297  tauCone=std::max(std::max((ROOT::Math::VectorUtil::DeltaR(tau.p4(),(*hadron)->p4())),
298  (ROOT::Math::VectorUtil::DeltaR(tau.p4(),strip1))),
299  (ROOT::Math::VectorUtil::DeltaR(tau.p4(),strip2)));
300 
301  }
302 
303  for(std::vector<CandidatePtr>::const_iterator j=emConstituents1.begin();j!=emConstituents1.end();++j) {
304  signal.push_back(*j);
305  signalG.push_back(*j);
306  }
307 
308  for(std::vector<CandidatePtr>::const_iterator j=emConstituents2.begin();j!=emConstituents2.end();++j) {
309  signal.push_back(*j);
310  signalG.push_back(*j);
311  }
312 
313  //Set the PFTau
314  tau.setsignalChargedHadrCands(signalH);
315  tau.setsignalGammaCands(signalG);
316  tau.setsignalCands(signal);
317  tau.setleadChargedHadrCand(*hadron);
318 
319  //Set the lead Candidate->Can be the hadron or the leading PFGamma(When we clear the Dataformat we will put the strip)
320  if((*hadron)->pt()>emConstituents1[0]->pt())
321  tau.setleadCand(*hadron);
322  else
323  tau.setleadCand(emConstituents1[0]);
324 
325  //Apply the cone size formula
326  if(isNarrowTau(tau,tauCone)) {
327 
328  //calculate the isolation Deposits
330 
332 
333  //For two strips take the nearest strip to the track
334  if(ROOT::Math::VectorUtil::DeltaR(strip1,(*hadron)->p4())<
335  ROOT::Math::VectorUtil::DeltaR(strip2,(*hadron)->p4()))
336  applyElectronRejection(tau,strip1.energy());
337  else
338  applyElectronRejection(tau,strip2.energy());
339 
340  taus.push_back(tau);
341  }
342  }
343  }
344  }
345 
346  if(!taus.empty()) {
347  pfTaus_.push_back(getBestTauCandidate(taus));
348  }
349 }
350 
351 
352 
353 void
354 HPSPFRecoTauAlgorithm::buildThreeProngs(const reco::PFTauTagInfoRef& tagInfo,const std::vector<reco::CandidatePtr>& hadrons)
355 {
357  //get Hadrons
358 
359 
360  //Require at least three hadrons
361  if(hadrons.size()>2)
362  for(unsigned int a=0;a<hadrons.size()-2;++a)
363  for(unsigned int b=a+1;b<hadrons.size()-1;++b)
364  for(unsigned int c=b+1;c<hadrons.size();++c) {
365 
366  CandidatePtr c_h1 = hadrons[a];
367  CandidatePtr c_h2 = hadrons[b];
368  CandidatePtr c_h3 = hadrons[c];
369 
370  const reco::PFCandidate* h1 = dynamic_cast<const reco::PFCandidate*>(c_h1.get());
371  const reco::PFCandidate* h2 = dynamic_cast<const reco::PFCandidate*>(c_h2.get());
372  const reco::PFCandidate* h3 = dynamic_cast<const reco::PFCandidate*>(c_h3.get());
373  if (h1 == nullptr || h2 == nullptr || h3 == nullptr) {
374  throw cms::Exception("Type Mismatch") << "The PFTau was not made from PFCandidates, and this outdated algorithm as not updated to cope with PFTaus made from other Candidates.\n";
375  }
376 
377  //check charge Compatibility and lead track
378  int charge=h1->charge()+h2->charge()+h3->charge();
379  if(std::abs(charge)==1 && h1->pt()>leadPionThreshold_)
380  //check the track refs
381  if(h1->trackRef()!=h2->trackRef()&&h1->trackRef()!=h3->trackRef()&&h2->trackRef()!=h3->trackRef())
382  {
383 
384  //create the tau
385  PFTau tau = PFTau(charge,h1->p4()+h2->p4()+h3->p4(),h1->vertex());
386  tau.setpfTauTagInfoRef(tagInfo);
387 
388  if(tau.pt()>tauThreshold_)//Threshold
389  if(ROOT::Math::VectorUtil::DeltaR(tau.p4(),tagInfo->pfjetRef()->p4())<matchingCone_) {//Matching Cone
390 
391  std::vector<CandidatePtr> signal;
392  signal.push_back(c_h1);
393  signal.push_back(c_h2);
394  signal.push_back(c_h3);
395  //calculate the tau cone by getting the maximum distance
396  double tauCone = 10000.0;
397  if(coneMetric_=="DR")
398  {
399  tauCone = std::max(ROOT::Math::VectorUtil::DeltaR(tau.p4(),h1->p4()),
401  ROOT::Math::VectorUtil::DeltaR(tau.p4(),h3->p4())));
402  }
403  else if(coneMetric_=="angle")
404  {
405  tauCone =std::max(fabs(ROOT::Math::VectorUtil::Angle(tau.p4(),h1->p4())),
406  std::max(fabs(ROOT::Math::VectorUtil::Angle(tau.p4(),h2->p4())),
407  fabs(ROOT::Math::VectorUtil::Angle(tau.p4(),h3->p4()))));
408  }
409 
410  //Set The PFTau
411  tau.setsignalChargedHadrCands(signal);
412  tau.setsignalCands(signal);
413  tau.setleadChargedHadrCand(c_h1);
414  tau.setleadCand(c_h1);
415 
416  if(isNarrowTau(tau,tauCone)) {
417  //calculate the isolation Deposits
418  associateIsolationCandidates(tau,tauCone);
419  applyMuonRejection(tau);
420  applyElectronRejection(tau,0.0);
421  taus.push_back(tau);
422 
423  }
424  }
425  }
426  }
427 
428  if(!taus.empty()) {
429  PFTau bestTau = getBestTauCandidate(taus);
430  if(refitThreeProng(bestTau))
431  //Apply mass constraint
432  if ( bestTau.mass() > threeProngMassWindow_[0] && bestTau.mass() < threeProngMassWindow_[1] )//MassWindow
433  pfTaus_.push_back(bestTau);
434  }
435 
436 }
437 
438 
439 bool
441 {
442  double allowedConeSize=coneSizeFormula.Eval(tau.energy(),tau.et());
443  if (allowedConeSize<minSignalCone_) allowedConeSize=minSignalCone_;
444  if (allowedConeSize>maxSignalCone_) allowedConeSize=maxSignalCone_;
445 
446  if(cone<allowedConeSize)
447  return true;
448  else
449  return false;
450 }
451 
452 
453 void
455  double tauCone)
456 {
457 
458 
459  using namespace reco;
460 
461  //Information to get filled
462  double sumPT=0;
463  double sumET=0;
464 
465  if(tau.pfTauTagInfoRef().isNull()) return;
466 
467  std::vector<CandidatePtr> hadrons;
468  std::vector<CandidatePtr> gammas;
469  std::vector<CandidatePtr> neutral;
470 
471  //Remove candidates outside the cones
473  {
474  const std::vector<reco::CandidatePtr>& pfChargedHadrCands = tau.pfTauTagInfoRef()->PFChargedHadrCands();
475  double tauEta=tau.eta();
476  double tauPhi=tau.phi();
477  for ( std::vector<reco::CandidatePtr>::const_iterator pfChargedHadrCand = pfChargedHadrCands.begin();
478  pfChargedHadrCand != pfChargedHadrCands.end(); ++pfChargedHadrCand ) {
479  double dR = reco::deltaR(tauEta, tauPhi, (*pfChargedHadrCand)->eta(), (*pfChargedHadrCand)->phi());
480  if ( dR > tauCone && dR < chargeIsolationCone_ ) hadrons.push_back(*pfChargedHadrCand);
481  }
482 
483  const std::vector<reco::CandidatePtr>& pfGammaCands = tau.pfTauTagInfoRef()->PFGammaCands();
484  for ( std::vector<reco::CandidatePtr>::const_iterator pfGammaCand = pfGammaCands.begin();
485  pfGammaCand != pfGammaCands.end(); ++pfGammaCand ) {
486  double dR = reco::deltaR(tauEta, tauPhi, (*pfGammaCand)->eta(), (*pfGammaCand)->phi());
487  if ( dR > tauCone && dR < gammaIsolationCone_ ) gammas.push_back(*pfGammaCand);
488  }
489 
490  const std::vector<reco::CandidatePtr>& pfNeutralHadrCands = tau.pfTauTagInfoRef()->PFNeutrHadrCands();
491  for ( std::vector<reco::CandidatePtr>::const_iterator pfNeutralHadrCand = pfNeutralHadrCands.begin();
492  pfNeutralHadrCand != pfNeutralHadrCands.end(); ++pfNeutralHadrCand ) {
493  double dR = reco::deltaR(tauEta, tauPhi, (*pfNeutralHadrCand)->eta(), (*pfNeutralHadrCand)->phi());
494  if ( dR > tauCone && dR < neutrHadrIsolationCone_ ) hadrons.push_back(*pfNeutralHadrCand);
495  }
496  } else {
497  double tauEta=tau.eta();
498  double tauPhi=tau.phi();
499  const std::vector<reco::CandidatePtr>& pfChargedHadrCands = tau.pfTauTagInfoRef()->PFChargedHadrCands();
500  for ( std::vector<reco::CandidatePtr>::const_iterator pfChargedHadrCand = pfChargedHadrCands.begin();
501  pfChargedHadrCand != pfChargedHadrCands.end(); ++pfChargedHadrCand ) {
502  double dR = reco::deltaR(tauEta, tauPhi, (*pfChargedHadrCand)->eta(), (*pfChargedHadrCand)->phi());
503  if ( dR < chargeIsolationCone_ ) hadrons.push_back(*pfChargedHadrCand);
504  }
505 
506  const std::vector<reco::CandidatePtr>& pfGammaCands = tau.pfTauTagInfoRef()->PFGammaCands();
507  for ( std::vector<reco::CandidatePtr>::const_iterator pfGammaCand = pfGammaCands.begin();
508  pfGammaCand != pfGammaCands.end(); ++pfGammaCand ) {
509  double dR = reco::deltaR(tauEta, tauPhi, (*pfGammaCand)->eta(), (*pfGammaCand)->phi());
510  if ( dR < gammaIsolationCone_ ) gammas.push_back(*pfGammaCand);
511  }
512 
513  const std::vector<reco::CandidatePtr>& pfNeutralHadrCands = tau.pfTauTagInfoRef()->PFNeutrHadrCands();
514  for ( std::vector<reco::CandidatePtr>::const_iterator pfNeutralHadrCand = pfNeutralHadrCands.begin();
515  pfNeutralHadrCand != pfNeutralHadrCands.end(); ++pfNeutralHadrCand ) {
516  double dR = reco::deltaR(tauEta, tauPhi, (*pfNeutralHadrCand)->eta(), (*pfNeutralHadrCand)->phi());
517  if ( dR < neutrHadrIsolationCone_ ) hadrons.push_back(*pfNeutralHadrCand);
518  }
519  }
520 
521  //remove the signal Constituents from the collections
522  for(std::vector<CandidatePtr>::const_iterator i=tau.signalChargedHadrCands().begin();i!=tau.signalChargedHadrCands().end();++i)
523  {
525  }
526 
527  for(std::vector<CandidatePtr>::const_iterator i=tau.signalGammaCands().begin();i!=tau.signalGammaCands().end();++i)
528  {
530  removeCandidateFromRefVector(*i,hadrons);//special case where we included a hadron if the strip!
531  }
532 
533 
534  //calculate isolation deposits
535  for(unsigned int i=0;i<hadrons.size();++i)
536  {
537  sumPT+=hadrons[i]->pt();
538  }
539 
540  for(unsigned int i=0;i<gammas.size();++i)
541  {
542  sumET+=gammas[i]->pt();
543  }
544 
545 
548  tau.setisolationChargedHadrCands(hadrons);
549  tau.setisolationNeutrHadrCands(neutral);
550  tau.setisolationGammaCands(gammas);
551 
552  std::vector<CandidatePtr> isoAll = hadrons;
553  for(unsigned int i=0;i<gammas.size();++i)
554  isoAll.push_back(gammas[i]);
555 
556  for(unsigned int i=0;i<neutral.size();++i)
557  isoAll.push_back(neutral[i]);
558 
559  tau.setisolationCands(isoAll);
560 }
561 
562 void
564 {
565 
566  // Require that no signal track has segment matches
567 
568  //Also:
569  //The segment compatibility is the number of matched Muon Segments
570  //the old available does not exist in the muons anymore so i will fill the data format with that
571  bool decision=true;
572  float caloComp=0.0;
573  float segComp=0.0;
574 
575  if(tau.leadPFChargedHadrCand().isNonnull()) {
577  if(mu.isNonnull()){
578  segComp=(float)(mu->matches().size());
579  if(mu->caloCompatibility()>caloComp)
580  caloComp = mu->caloCompatibility();
581 
582  if(segComp<1.0)
583  decision=false;
584 
585  tau.setCaloComp(caloComp);
586  tau.setSegComp(segComp);
587  tau.setMuonDecision(decision);
588  }
589 
590  }
591 }
592 
593 
594 void
596 {
597  //Here we apply the common electron rejection variables.
598  //The only not common is the E/P that is applied in the decay mode
599  //construction
600 
601 
602  if(tau.leadPFChargedHadrCand().isNonnull()) {
603  PFCandidatePtr leadCharged = tau.leadPFChargedHadrCand();
604  math::XYZVector caloDir(leadCharged->positionAtECALEntrance().x(),
605  leadCharged->positionAtECALEntrance().y(),
606  leadCharged->positionAtECALEntrance().z());
607 
608  tau.setmaximumHCALPFClusterEt(leadCharged->hcalEnergy()*sin(caloDir.theta()));
609 
610 
611 
612  if(leadCharged->trackRef().isNonnull()) {
613  TrackRef track = leadCharged->trackRef();
614  tau.setemFraction(leadCharged->ecalEnergy()/(leadCharged->ecalEnergy()+leadCharged->hcalEnergy()));
615  //For H/P trust particle Flow ! :Just take HCAL energy of the candidate
616  //end of story
617  tau.sethcalTotOverPLead(leadCharged->hcalEnergy()/track->p());
618  tau.sethcalMaxOverPLead(leadCharged->hcalEnergy()/track->p());
619  tau.sethcal3x3OverPLead(leadCharged->hcalEnergy()/track->p());
620  tau.setelectronPreIDTrack(track);
621  tau.setelectronPreIDOutput(leadCharged->mva_e_pi());
622  //Since PF uses brem recovery we will store the default ecal energy here
623  tau.setbremsRecoveryEOverPLead(leadCharged->ecalEnergy()/track->p());
624  tau.setecalStripSumEOverPLead((leadCharged->ecalEnergy()-stripEnergy)/track->p());
625  bool electronDecision;
626  if(std::abs(leadCharged->pdgId())==11)
627  electronDecision=true;
628  else
629  electronDecision=false;
630  tau.setelectronPreIDDecision(electronDecision);
631  }
632  }
633 }
634 
635 
636 
637 
638 void
640 {
641  emMerger_ = p.getParameter<std::string>("emMergingAlgorithm");
642  overlapCriterion_ = p.getParameter<std::string>("candOverlapCriterion");
643  doOneProngs_ = p.getParameter<bool>("doOneProng");
644  doOneProngStrips_ = p.getParameter<bool>("doOneProngStrip");
645  doOneProngTwoStrips_ = p.getParameter<bool>("doOneProngTwoStrips");
646  doThreeProngs_ = p.getParameter<bool>("doThreeProng");
647  tauThreshold_ = p.getParameter<double>("tauPtThreshold");
648  leadPionThreshold_ = p.getParameter<double>("leadPionThreshold");
649  stripPtThreshold_ = p.getParameter<double>("stripPtThreshold");
650  chargeIsolationCone_ = p.getParameter<double>("chargeHadrIsolationConeSize");
651  gammaIsolationCone_ = p.getParameter<double>("gammaIsolationConeSize");
652  neutrHadrIsolationCone_ = p.getParameter<double>("neutrHadrIsolationConeSize");
653  useIsolationAnnulus_ = p.getParameter<bool>("useIsolationAnnulus");
654  oneProngStripMassWindow_ = p.getParameter<std::vector<double> >("oneProngStripMassWindow");
655  oneProngTwoStripsMassWindow_ = p.getParameter<std::vector<double> >("oneProngTwoStripsMassWindow");
656  oneProngTwoStripsPi0MassWindow_= p.getParameter<std::vector<double> >("oneProngTwoStripsPi0MassWindow");
657  threeProngMassWindow_ = p.getParameter<std::vector<double> >("threeProngMassWindow");
658  matchingCone_ = p.getParameter<double>("matchingCone");
659  coneMetric_ = p.getParameter<std::string>("coneMetric");
660  coneSizeFormula_ = p.getParameter<std::string>("coneSizeFormula");
661  minSignalCone_ = p.getParameter<double>("minimumSignalCone");
662  maxSignalCone_ = p.getParameter<double>("maximumSignalCone");
663 
664 
665 
666  //Initialize The Merging Algorithm!
667  if(emMerger_ =="StripBased")
669  //Add the Pi0 Merger from Evan here
670 
671 
672  if(oneProngStripMassWindow_.size()!=2)
673  throw cms::Exception("") << "OneProngStripMassWindow must be a vector of size 2 [min,max] " << std::endl;
674  if(oneProngTwoStripsMassWindow_.size()!=2)
675  throw cms::Exception("") << "OneProngTwoStripsMassWindow must be a vector of size 2 [min,max] " << std::endl;
676  if(threeProngMassWindow_.size()!=2)
677  throw cms::Exception("") << "ThreeProngMassWindow must be a vector of size 2 [min,max] " << std::endl;
678  if(coneMetric_!= "angle" && coneMetric_ != "DR")
679  throw cms::Exception("") << "Cone Metric should be angle or DR " << std::endl;
680 
681  coneSizeFormula = TauTagTools::computeConeSizeTFormula(coneSizeFormula_,"Signal cone size Formula");
682 
683 
684 }
685 
686 
687 
689 HPSPFRecoTauAlgorithm::createMergedLorentzVector(const std::vector<reco::CandidatePtr>& cands)
690 {
692  for(unsigned int i=0;i<cands.size();++i) {
693  sum+=cands[i]->p4();
694  }
695  return sum;
696 }
697 
698 void
700 {
701  std::vector<CandidatePtr> newVec;
702 
703  std::vector<CandidatePtr>::iterator it;
704  it = std::find(vec.begin(),vec.end(),cand);
705  if(it!=vec.end())
706  vec.erase(it);
707 }
708 
709 void
711 {
712  double factor = sqrt(vec.energy()*vec.energy()-mass*mass)/vec.P();
713  vec.SetCoordinates(vec.px()*factor,vec.py()*factor,vec.pz()*factor,vec.energy());
714 }
715 
716 
717 
718 
719 bool
721 {
722  bool response=false;
723  //Get Hadrons
724  std::vector<reco::PFCandidatePtr> hadrons = tau.signalPFChargedHadrCands();
725  PFCandidatePtr h1 = hadrons[0];
726  PFCandidatePtr h2 = hadrons[1];
727  PFCandidatePtr h3 = hadrons[2];
728 
729  //Make transient tracks
730  std::vector<TransientTrack> transientTracks;
731  transientTracks.push_back(TransientTrackBuilder_->build(h1->trackRef()));
732  transientTracks.push_back(TransientTrackBuilder_->build(h2->trackRef()));
733  transientTracks.push_back(TransientTrackBuilder_->build(h3->trackRef()));
734 
735  //Apply the Vertex Fit
736  KalmanVertexFitter fitter(true);
737  TransientVertex myVertex = fitter.vertex(transientTracks);
738 
739  //Just require a valid vertex+ 3 refitted tracks
740  if(myVertex.isValid()&&
741  myVertex.hasRefittedTracks()&&
742  myVertex.refittedTracks().size()==3) {
743 
744  response=true;
745  math::XYZPoint vtx(myVertex.position().x(),myVertex.position().y(),myVertex.position().z());
746 
747  //Create a LV for each refitted track
748  const std::vector<reco::TransientTrack>& refittedTracks = myVertex.refittedTracks();
749  const reco::Track& track1 = refittedTracks.at(0).track();
750  math::XYZTLorentzVector p1(track1.px(), track1.py(), track1.pz(), sqrt(track1.momentum().mag2() + 0.139*0.139));
751  const reco::Track& track2 = refittedTracks.at(1).track();
752  math::XYZTLorentzVector p2(track2.px(), track2.py(), track2.pz(), sqrt(track2.momentum().mag2() + 0.139*0.139));
753  const reco::Track& track3 = refittedTracks.at(2).track();
754  math::XYZTLorentzVector p3(track3.px(), track3.py(), track3.pz(), sqrt(track3.momentum().mag2() + 0.139*0.139));
755 
756  //Update the tau p4
757  tau.setP4(p1+p2+p3);
758  //Update the vertex
759  tau.setVertex(vtx);
760  }
761  return response;
762 
763 }
764 
767 {
768  reco::PFTauCollection::iterator it;
769  if(overlapCriterion_ =="Isolation"){
771  it = std::min_element(taus.begin(),taus.end(),sorter);
772 
773  }
774  else if(overlapCriterion_ =="Pt"){
776  it = std::min_element(taus.begin(),taus.end(),sorter);
777  }
778 
779  return *it;
780 }
T getParameter(std::string const &) const
double ecalEnergy() const
return corrected Ecal energy
Definition: PFCandidate.h:222
int pdgId() const final
PDG identifier.
math::XYZTLorentzVector createMergedLorentzVector(const std::vector< reco::CandidatePtr > &)
void setsignalChargedHadrCands(const std::vector< reco::CandidatePtr > &)
Definition: PFTau.cc:81
void setMuonDecision(const bool &)
Definition: PFTau.cc:369
void setelectronPreIDOutput(const float &)
Definition: PFTau.cc:347
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:251
std::vector< PFTau > PFTauCollection
collection of PFTau objects
Definition: PFTauFwd.h:9
double eta() const final
momentum pseudorapidity
void removeCandidateFromRefVector(const reco::CandidatePtr &, std::vector< reco::CandidatePtr > &)
void buildOneProng(const reco::PFTauTagInfoRef &, const std::vector< reco::CandidatePtr > &)
void setisolationNeutrHadrCands(const std::vector< reco::CandidatePtr > &)
Definition: PFTau.cc:92
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
virtual std::vector< std::vector< reco::CandidatePtr > > mergeCandidates(const std::vector< reco::CandidatePtr > &)=0
void setelectronPreIDDecision(const bool &)
Definition: PFTau.cc:348
const TransientTrackBuilder * TransientTrackBuilder_
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:159
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
std::pair< bool, Measurement1D > signedTransverseImpactParameter(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:50
reco::TransientTrack build(const reco::Track *p) const
T y() const
Definition: PV3DBase.h:63
double pt() const final
transverse momentum
int charge() const final
electric charge
Definition: LeafCandidate.h:91
const std::vector< reco::CandidatePtr > & signalGammaCands() const
Gamma candidates in signal region.
Definition: PFTau.cc:84
Definition: config.py:1
bool hasRefittedTracks() const
std::vector< double > threeProngMassWindow_
double px() const
x coordinate of momentum vector
Definition: TrackBase.h:666
void sethcal3x3OverPLead(const float &)
Definition: PFTau.cc:343
void setleadCand(const CandidatePtr &)
Definition: PFTau.cc:73
const Vector & momentum() const
track momentum vector
Definition: TrackBase.h:714
reco::PFTauCollection pfTaus_
void setisolationPFGammaCandsEtSum(const float &)
Definition: PFTau.cc:324
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
void setemFraction(const float &)
Definition: PFTau.cc:340
const math::XYZPointF & positionAtECALEntrance() const
Definition: PFCandidate.h:368
void setisolationChargedHadrCands(const std::vector< reco::CandidatePtr > &)
Definition: PFTau.cc:90
void setVertex(const Point &vertex) override
set vertex
void buildThreeProngs(const reco::PFTauTagInfoRef &, const std::vector< reco::CandidatePtr > &)
reco::TrackRef trackRef() const
Definition: PFCandidate.cc:442
void setleadChargedHadrCand(const CandidatePtr &)
Definition: PFTau.cc:71
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
const Point & vertex() const override
vertex position (overwritten by PF...)
Definition: PFCandidate.cc:656
reco::PFTau getBestTauCandidate(reco::PFTauCollection &)
void setisolationCands(const std::vector< reco::CandidatePtr > &)
Definition: PFTau.cc:88
double et() const final
transverse energy
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector
T sqrt(T t)
Definition: SSEVec.h:18
GlobalPoint position() const
void buildOneProngStrip(const reco::PFTauTagInfoRef &, const std::vector< std::vector< reco::CandidatePtr >> &, const std::vector< reco::CandidatePtr > &)
T z() const
Definition: PV3DBase.h:64
void setCaloComp(const float &)
Definition: PFTau.cc:367
void applyElectronRejection(reco::PFTau &, double)
double energy() const final
energy
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &tracks) const override
void setisolationPFChargedHadrCandsPtSum(const float &)
Definition: PFTau.cc:321
void setleadPFChargedHadrCandsignedSipt(const float &)
Definition: PFTau.cc:76
const LorentzVector & p4() const final
four-momentum Lorentz vector
Definition: LeafCandidate.h:99
const int mu
Definition: Constants.h:22
reco::PFTau buildPFTau(const reco::PFTauTagInfoRef &, const reco::Vertex &) override
double p2[4]
Definition: TauolaWrapper.h:90
TFormula computeConeSizeTFormula(const std::string &ConeSizeFormula, const char *errorMessage)
bool isNull() const
Checks for null.
Definition: Ref.h:248
void setsignalCands(const std::vector< reco::CandidatePtr > &)
Definition: PFTau.cc:79
void setbremsRecoveryEOverPLead(const float &)
Definition: PFTau.cc:345
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:459
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:168
double pz() const
z coordinate of momentum vector
Definition: TrackBase.h:678
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:28
const std::vector< reco::PFCandidatePtr > & signalPFChargedHadrCands() const
Definition: PFTau.cc:179
float mva_e_pi() const
mva for electron-pion discrimination
Definition: PFCandidate.h:314
void sortRefVectorByPt(std::vector< reco::CandidatePtr > &)
Definition: TauTagTools.cc:242
const PFTauTagInfoRef & pfTauTagInfoRef() const
Definition: PFTau.cc:61
void sethcalMaxOverPLead(const float &)
Definition: PFTau.cc:342
std::vector< double > oneProngTwoStripsMassWindow_
virtual double pt() const =0
transverse momentum
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
void setSegComp(const float &)
Definition: PFTau.cc:368
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
double b
Definition: hdecay.h:120
const std::vector< reco::CandidatePtr > & signalChargedHadrCands() const
Charged hadrons in signal region.
Definition: PFTau.cc:80
void setisolationGammaCands(const std::vector< reco::CandidatePtr > &)
Definition: PFTau.cc:94
virtual int charge() const =0
electric charge
std::vector< double > oneProngStripMassWindow_
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
fixed size matrix
double p1[4]
Definition: TauolaWrapper.h:89
double a
Definition: hdecay.h:121
void setmaximumHCALPFClusterEt(const float &)
Definition: PFTau.cc:327
void applyMuonRejection(reco::PFTau &)
double hcalEnergy() const
return corrected Hcal energy
Definition: PFCandidate.h:232
void setecalStripSumEOverPLead(const float &)
Definition: PFTau.cc:344
virtual const Point & vertex() const =0
vertex position
std::vector< double > oneProngTwoStripsPi0MassWindow_
std::vector< reco::TransientTrack > const & refittedTracks() const
void sethcalTotOverPLead(const float &)
Definition: PFTau.cc:341
void applyMassConstraint(math::XYZTLorentzVector &, double)
const PFCandidatePtr leadPFChargedHadrCand() const
Getters for different PFCandidates for PFTaus made from PFCandidates.
Definition: PFTau.cc:154
void setelectronPreIDTrack(const reco::TrackRef &)
Definition: PFTau.cc:346
void configure(const edm::ParameterSet &)
T x() const
Definition: PV3DBase.h:62
bool refitThreeProng(reco::PFTau &)
PFCandidateMergerBase * candidateMerger_
double phi() const final
momentum azimuthal angle
bool isNarrowTau(const reco::PFTau &, double)
bool isValid() const
void setP4(const LorentzVector &p4) final
set 4-momentum
void associateIsolationCandidates(reco::PFTau &, double)
double py() const
y coordinate of momentum vector
Definition: TrackBase.h:672
void buildOneProngTwoStrips(const reco::PFTauTagInfoRef &, const std::vector< std::vector< reco::CandidatePtr >> &, const std::vector< reco::CandidatePtr > &)
double mass() const final
mass
double p3[4]
Definition: TauolaWrapper.h:91
void setpfTauTagInfoRef(const PFTauTagInfoRef)
Definition: PFTau.cc:65