CMS 3D CMS Logo

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