CMS 3D CMS Logo

PFRecoTauAlgorithm.cc
Go to the documentation of this file.
2 
3 // Turn off filtering by pt. Min pt is set to zero,
4 // as this functionality is implemented in the underlying
5 // PFTauTagInfo production. Additional pt filters are applied
6 // the discriminators.
7 
8 #define PFTauAlgo_NeutrHadrCand_minPt_ (0.0)
9 #define PFTauAlgo_GammaCand_minPt_ (0.0)
10 #define PFTauAlgo_PFCand_minPt_ (0.0)
11 #define PFTauAlgo_Track_minPt_ (0.0)
12 #define PFTauAlgo_ChargedHadrCand_minPt_ (0.0)
13 
14 using namespace reco;
15 
18  LeadPFCand_minPt_ = iConfig.getParameter<double>("LeadPFCand_minPt");
19 
21  = iConfig.getParameter<bool>("UseChargedHadrCandLeadChargedHadrCand_tksDZconstraint");
22 
24  = iConfig.getParameter<double>("ChargedHadrCandLeadChargedHadrCand_tksmaxDZ");
25 
26  LeadTrack_minPt_ = iConfig.getParameter<double>("LeadTrack_minPt");
27  UseTrackLeadTrackDZconstraint_ = iConfig.getParameter<bool>("UseTrackLeadTrackDZconstraint");
28  TrackLeadTrack_maxDZ_ = iConfig.getParameter<double>("TrackLeadTrack_maxDZ");
29 
30  MatchingConeMetric_ = iConfig.getParameter<std::string>("MatchingConeMetric");
31  MatchingConeSizeFormula_ = iConfig.getParameter<std::string>("MatchingConeSizeFormula");
32  MatchingConeSize_min_ = iConfig.getParameter<double>("MatchingConeSize_min");
33  MatchingConeSize_max_ = iConfig.getParameter<double>("MatchingConeSize_max");
34  TrackerSignalConeMetric_ = iConfig.getParameter<std::string>("TrackerSignalConeMetric");
35  TrackerSignalConeSizeFormula_ = iConfig.getParameter<std::string>("TrackerSignalConeSizeFormula");
36  TrackerSignalConeSize_min_ = iConfig.getParameter<double>("TrackerSignalConeSize_min");
37  TrackerSignalConeSize_max_ = iConfig.getParameter<double>("TrackerSignalConeSize_max");
38  TrackerIsolConeMetric_ = iConfig.getParameter<std::string>("TrackerIsolConeMetric");
39  TrackerIsolConeSizeFormula_ = iConfig.getParameter<std::string>("TrackerIsolConeSizeFormula");
40  TrackerIsolConeSize_min_ = iConfig.getParameter<double>("TrackerIsolConeSize_min");
41  TrackerIsolConeSize_max_ = iConfig.getParameter<double>("TrackerIsolConeSize_max");
42  ECALSignalConeMetric_ = iConfig.getParameter<std::string>("ECALSignalConeMetric");
43  ECALSignalConeSizeFormula_ = iConfig.getParameter<std::string>("ECALSignalConeSizeFormula");
44  ECALSignalConeSize_min_ = iConfig.getParameter<double>("ECALSignalConeSize_min");
45  ECALSignalConeSize_max_ = iConfig.getParameter<double>("ECALSignalConeSize_max");
46  ECALIsolConeMetric_ = iConfig.getParameter<std::string>("ECALIsolConeMetric");
47  ECALIsolConeSizeFormula_ = iConfig.getParameter<std::string>("ECALIsolConeSizeFormula");
48  ECALIsolConeSize_min_ = iConfig.getParameter<double>("ECALIsolConeSize_min");
49  ECALIsolConeSize_max_ = iConfig.getParameter<double>("ECALIsolConeSize_max");
50  HCALSignalConeMetric_ = iConfig.getParameter<std::string>("HCALSignalConeMetric");
51  HCALSignalConeSizeFormula_ = iConfig.getParameter<std::string>("HCALSignalConeSizeFormula");
52  HCALSignalConeSize_min_ = iConfig.getParameter<double>("HCALSignalConeSize_min");
53  HCALSignalConeSize_max_ = iConfig.getParameter<double>("HCALSignalConeSize_max");
54  HCALIsolConeMetric_ = iConfig.getParameter<std::string>("HCALIsolConeMetric");
55  HCALIsolConeSizeFormula_ = iConfig.getParameter<std::string>("HCALIsolConeSizeFormula");
56  HCALIsolConeSize_min_ = iConfig.getParameter<double>("HCALIsolConeSize_min");
57  HCALIsolConeSize_max_ = iConfig.getParameter<double>("HCALIsolConeSize_max");
58 
59  putNeutralHadronsInP4_ = iConfig.exists("putNeutralHadronsInP4") ?
60  iConfig.getParameter<bool>("putNeutralHadronsInP4") : false;
61 
62  // get paramaeters for ellipse EELL
63  Rphi_ = iConfig.getParameter<double>("Rphi");
64  MaxEtInEllipse_ = iConfig.getParameter<double>("MaxEtInEllipse");
65  AddEllipseGammas_ = iConfig.getParameter<bool>("AddEllipseGammas");
66  // EELL
67 
68  AreaMetric_recoElements_maxabsEta_ = iConfig.getParameter<double>("AreaMetric_recoElements_maxabsEta");
69  ChargedHadrCand_IsolAnnulus_minNhits_ = iConfig.getParameter<uint32_t>("ChargedHadrCand_IsolAnnulus_minNhits");
70  Track_IsolAnnulus_minNhits_ = iConfig.getParameter<uint32_t>("Track_IsolAnnulus_minNhits");
71 
72  ElecPreIDLeadTkMatch_maxDR_ = iConfig.getParameter<double>("ElecPreIDLeadTkMatch_maxDR");
73  EcalStripSumE_minClusEnergy_ = iConfig.getParameter<double>("EcalStripSumE_minClusEnergy");
74  EcalStripSumE_deltaEta_ = iConfig.getParameter<double>("EcalStripSumE_deltaEta");
75  EcalStripSumE_deltaPhiOverQ_minValue_ = iConfig.getParameter<double>("EcalStripSumE_deltaPhiOverQ_minValue");
76  EcalStripSumE_deltaPhiOverQ_maxValue_ = iConfig.getParameter<double>("EcalStripSumE_deltaPhiOverQ_maxValue");
77  maximumForElectrionPreIDOutput_ = iConfig.getParameter<double>("maximumForElectrionPreIDOutput");
78 
79  DataType_ = iConfig.getParameter<std::string>("DataType");
80 
81  //TFormula computation
82  myMatchingConeSizeTFormula = TauTagTools::computeConeSizeTFormula(MatchingConeSizeFormula_,"Matching cone size");
83  //Charged particles cones
84  myTrackerSignalConeSizeTFormula = TauTagTools::computeConeSizeTFormula(TrackerSignalConeSizeFormula_,"Tracker signal cone size");
85  myTrackerIsolConeSizeTFormula = TauTagTools::computeConeSizeTFormula(TrackerIsolConeSizeFormula_,"Tracker isolation cone size");
86  //Gamma candidates cones
87  myECALSignalConeSizeTFormula = TauTagTools::computeConeSizeTFormula(ECALSignalConeSizeFormula_,"ECAL signal cone size");
88  myECALIsolConeSizeTFormula = TauTagTools::computeConeSizeTFormula(ECALIsolConeSizeFormula_,"ECAL isolation cone size");
89  //Neutral hadrons cones
90  myHCALSignalConeSizeTFormula = TauTagTools::computeConeSizeTFormula(HCALSignalConeSizeFormula_,"HCAL signal cone size");
91  myHCALIsolConeSizeTFormula = TauTagTools::computeConeSizeTFormula(HCALIsolConeSizeFormula_,"HCAL isolation cone size");
92 }
93 
94 
95 PFTau PFRecoTauAlgorithm::buildPFTau(const PFTauTagInfoRef& myPFTauTagInfoRef, const Vertex& myPV)
96 {
97  JetBaseRef myPFJet=(*myPFTauTagInfoRef).pfjetRef(); // catch a ref to the initial PFJet
98  PFTau myPFTau(std::numeric_limits<int>::quiet_NaN(),myPFJet->p4()); // create the PFTau
99 
100  myPFTau.setpfTauTagInfoRef(myPFTauTagInfoRef);
101 
102  std::vector<CandidatePtr> myPFCands=(*myPFTauTagInfoRef).PFCands();
103 
104  PFTauElementsOperators myPFTauElementsOperators(myPFTau);
105  double myMatchingConeSize=myPFTauElementsOperators.computeConeSize(myMatchingConeSizeTFormula,MatchingConeSize_min_,MatchingConeSize_max_);
106 
107  CandidatePtr myleadPFChargedCand=myPFTauElementsOperators.leadChargedHadrCand(MatchingConeMetric_,myMatchingConeSize,PFTauAlgo_PFCand_minPt_);
108 
109  // These two quantities always taken from the signal cone
110  CandidatePtr myleadPFNeutralCand;
111  CandidatePtr myleadPFCand;
112 
113  bool myleadPFCand_rectkavailable = false;
114  double myleadPFCand_rectkDZ = 0.;
115 
116  // Determine the SIPT of the lead track
117  if(myleadPFChargedCand.isNonnull()) {
118  myPFTau.setleadChargedHadrCand(myleadPFChargedCand);
119  const reco::PFCandidate* pflch = dynamic_cast<const reco::PFCandidate*>(myleadPFChargedCand.get());
120  if (pflch == nullptr)
121  throw cms::Exception("Type Mismatch") << "The PFTau was not made from PFCandidates, and this outdated algorithm was not updated to cope with PFTaus made from other Candidates.\n";
122  TrackRef myleadPFCand_rectk=pflch->trackRef();
123  if(myleadPFCand_rectk.isNonnull()) {
124  myleadPFCand_rectkavailable=true;
125  myleadPFCand_rectkDZ=(*myleadPFCand_rectk).dz(myPV.position());
126  if(TransientTrackBuilder_!=nullptr) {
127  const TransientTrack myleadPFCand_rectransienttk=TransientTrackBuilder_->build(&(*myleadPFCand_rectk));
128  GlobalVector myPFJetdir((*myPFJet).px(),(*myPFJet).py(),(*myPFJet).pz());
129  if(IPTools::signedTransverseImpactParameter(myleadPFCand_rectransienttk,myPFJetdir,myPV).first)
130  myPFTau.setleadPFChargedHadrCandsignedSipt(
131  IPTools::signedTransverseImpactParameter(myleadPFCand_rectransienttk,myPFJetdir,myPV).second.significance());
132  }
133  }
134  }
135 
136  //Building PF Components
137  if (myleadPFChargedCand.isNonnull())
138  {
139  math::XYZVector tauAxis = myleadPFChargedCand->momentum();
140  // Compute energy of the PFTau considering only inner constituents
141  // (inner == pfcandidates inside a cone which is equal to the maximum value of the signal cone)
142  // The axis is built about the lead charged hadron
143  std::vector<CandidatePtr> myTmpPFCandsInSignalCone =
144  myPFTauElementsOperators.PFCandsInCone(tauAxis,TrackerSignalConeMetric_,TrackerSignalConeSize_max_,0.5);
145  math::XYZTLorentzVector tmpLorentzVect(0.,0.,0.,0.);
146 
147  double jetOpeningAngle = 0.0;
148  for (std::vector<CandidatePtr>::const_iterator iCand = myTmpPFCandsInSignalCone.begin();
149  iCand != myTmpPFCandsInSignalCone.end(); iCand++)
150  {
151  //find the maximum opening angle of the jet (now a parameter in available TFormulas)
152  double deltaRToSeed = TauTagTools::computeDeltaR(tauAxis, (**iCand).momentum());
153  if (deltaRToSeed > jetOpeningAngle)
154  jetOpeningAngle = deltaRToSeed;
155 
156  tmpLorentzVect+=(**iCand).p4();
157  }
158 
159  //Setting the myPFTau four momentum as the one made from the signal cone constituents.
160  double energy = tmpLorentzVect.energy();
161  double transverseEnergy = tmpLorentzVect.pt();
162  myPFTau.setP4(tmpLorentzVect);
163 
164  // Compute the cone sizes
165  double myTrackerSignalConeSize = myPFTauElementsOperators.computeConeSize(
166  myTrackerSignalConeSizeTFormula, TrackerSignalConeSize_min_, TrackerSignalConeSize_max_, transverseEnergy, energy, jetOpeningAngle);
167  double myTrackerIsolConeSize = myPFTauElementsOperators.computeConeSize(
168  myTrackerIsolConeSizeTFormula, TrackerIsolConeSize_min_, TrackerIsolConeSize_max_, transverseEnergy, energy, jetOpeningAngle);
169  double myECALSignalConeSize = myPFTauElementsOperators.computeConeSize(
170  myECALSignalConeSizeTFormula, ECALSignalConeSize_min_, ECALSignalConeSize_max_, transverseEnergy, energy, jetOpeningAngle);
171  double myECALIsolConeSize = myPFTauElementsOperators.computeConeSize(
172  myECALIsolConeSizeTFormula, ECALIsolConeSize_min_, ECALIsolConeSize_max_, transverseEnergy, energy, jetOpeningAngle);
173  double myHCALSignalConeSize = myPFTauElementsOperators.computeConeSize(
174  myHCALSignalConeSizeTFormula, HCALSignalConeSize_min_, HCALSignalConeSize_max_, transverseEnergy, energy, jetOpeningAngle);
175  double myHCALIsolConeSize = myPFTauElementsOperators.computeConeSize(
176  myHCALIsolConeSizeTFormula, HCALIsolConeSize_min_, HCALIsolConeSize_max_, transverseEnergy, energy, jetOpeningAngle);
177 
178  // Signal cone collections
179  std::vector<CandidatePtr> mySignalPFChargedHadrCands, mySignalPFNeutrHadrCands, mySignalPFGammaCands, mySignalPFCands;
180 
181  if (UseChargedHadrCandLeadChargedHadrCand_tksDZconstraint_ && myleadPFCand_rectkavailable) {
182  mySignalPFChargedHadrCands=myPFTauElementsOperators.PFChargedHadrCandsInCone(tauAxis,
184  ChargedHadrCandLeadChargedHadrCand_tksmaxDZ_, myleadPFCand_rectkDZ, myPV);
185  }
186  else {
187  mySignalPFChargedHadrCands=myPFTauElementsOperators.PFChargedHadrCandsInCone(tauAxis,
189  }
190 
191  // Set the Charged hadronics that live in the signal cones
192  myPFTau.setsignalChargedHadrCands(mySignalPFChargedHadrCands);
193 
194  // Set the neurtral hadrons that live in the signal cone
195  mySignalPFNeutrHadrCands=myPFTauElementsOperators.PFNeutrHadrCandsInCone(tauAxis,
197 
198  myPFTau.setsignalNeutrHadrCands(mySignalPFNeutrHadrCands);
199 
200  // Compute the gammas that live in the signal cone
201  mySignalPFGammaCands=myPFTauElementsOperators.PFGammaCandsInCone(tauAxis,
203 
204  myPFTau.setsignalGammaCands(mySignalPFGammaCands);
205 
206  // Add charged objects to signal cone, and calculate charge
207  if(!mySignalPFChargedHadrCands.empty()) {
208  int mySignalPFChargedHadrCands_qsum=0;
209  for(size_t i = 0; i < mySignalPFChargedHadrCands.size(); i++) {
210  mySignalPFChargedHadrCands_qsum += mySignalPFChargedHadrCands[i]->charge();
211  mySignalPFCands.push_back(mySignalPFChargedHadrCands[i]);
212  }
213  myPFTau.setCharge(mySignalPFChargedHadrCands_qsum);
214  }
215 
216  //Add neutral objects to signal cone
217  for(size_t i = 0; i < mySignalPFNeutrHadrCands.size(); i++) {
218  mySignalPFCands.push_back(mySignalPFNeutrHadrCands[i]);
219  }
220 
221  // For the signal gammas, keep track of the highest pt object
222  double maxSignalGammaPt = 0.;
223  for(size_t i = 0; i < mySignalPFGammaCands.size(); i++) {
224  if(mySignalPFGammaCands[i]->pt() > maxSignalGammaPt) {
225  myleadPFNeutralCand = mySignalPFGammaCands[i];
226  maxSignalGammaPt = mySignalPFGammaCands[i]->pt();
227  }
228  mySignalPFCands.push_back(mySignalPFGammaCands[i]);
229  }
230  myPFTau.setsignalCands(mySignalPFCands);
231  // Set leading gamma
232  myPFTau.setleadNeutralCand(myleadPFNeutralCand);
233 
234  // Logic to determine lead PFCand. If the lead charged object
235  // is above the threshold, take that. If the lead charged object is less
236  // than the threshold (but exists), AND there exists a gamma above the threshold
237  // take the gamma as the leadPFCand. Otherwise it is null.
238 
239  if(myleadPFChargedCand->pt() > LeadPFCand_minPt_) {
240  myPFTau.setleadCand(myleadPFChargedCand);
241  } else if (maxSignalGammaPt > LeadPFCand_minPt_) {
242  myPFTau.setleadCand(myleadPFNeutralCand);
243  }
244 
245  // Declare isolation collections
246  std::vector<CandidatePtr> myUnfilteredIsolPFChargedHadrCands, myIsolPFNeutrHadrCands, myIsolPFGammaCands, myIsolPFCands;
247 
248  // Build unfiltered isolation collection
249  if(UseChargedHadrCandLeadChargedHadrCand_tksDZconstraint_ && myleadPFCand_rectkavailable) {
250  myUnfilteredIsolPFChargedHadrCands=myPFTauElementsOperators.PFChargedHadrCandsInAnnulus(
251  tauAxis,TrackerSignalConeMetric_,myTrackerSignalConeSize,TrackerIsolConeMetric_,myTrackerIsolConeSize,
253  } else {
254  myUnfilteredIsolPFChargedHadrCands=myPFTauElementsOperators.PFChargedHadrCandsInAnnulus(
255  tauAxis,TrackerSignalConeMetric_,myTrackerSignalConeSize,TrackerIsolConeMetric_,myTrackerIsolConeSize,
257  }
258 
259  // Filter isolation annulus charge dhadrons with additional nHits quality cut
260  // (note that other cuts [pt, chi2, are already cut on])
261  std::vector<CandidatePtr> myIsolPFChargedHadrCands;
262  myIsolPFChargedHadrCands = TauTagTools::filteredPFChargedHadrCandsByNumTrkHits(
263  myUnfilteredIsolPFChargedHadrCands, ChargedHadrCand_IsolAnnulus_minNhits_);
264 
265  myPFTau.setisolationChargedHadrCands(myIsolPFChargedHadrCands);
266 
267  // Fill neutral hadrons
268  myIsolPFNeutrHadrCands = myPFTauElementsOperators.PFNeutrHadrCandsInAnnulus(
269  tauAxis, HCALSignalConeMetric_, myHCALSignalConeSize, HCALIsolConeMetric_,
270  myHCALIsolConeSize, PFTauAlgo_NeutrHadrCand_minPt_);
271  myPFTau.setisolationNeutrHadrCands(myIsolPFNeutrHadrCands);
272 
273  // Fill gamma candidates
274  myIsolPFGammaCands = myPFTauElementsOperators.PFGammaCandsInAnnulus(
275  tauAxis, ECALSignalConeMetric_, myECALSignalConeSize, ECALIsolConeMetric_,
276  myECALIsolConeSize, PFTauAlgo_GammaCand_minPt_);
277  myPFTau.setisolationGammaCands(myIsolPFGammaCands);
278 
279  //Incorporate converted gammas from isolation ellipse into signal ... ELLL
280  //Get pair with in/out elements using the isoPFGammaCandidates set by default
281  if(AddEllipseGammas_) {
282  double rPhi;
283  if(Rphi_ >= 1.)
284  rPhi = Rphi_*myECALSignalConeSize;
285  else
286  rPhi = Rphi_;
287 
288  std::pair<std::vector<CandidatePtr>,std::vector<CandidatePtr>> elementsInOutEllipse =
289  myPFTauElementsOperators.PFGammaCandsInOutEllipse(myIsolPFGammaCands, *myleadPFCand, rPhi, myECALSignalConeSize, MaxEtInEllipse_);
290 
291  std::vector<CandidatePtr> elementsInEllipse = elementsInOutEllipse.first;
292  std::vector<CandidatePtr> elementsOutEllipse = elementsInOutEllipse.second;
293  //add the inside elements to signal PFCandidates and reset signal PFCands
294  for(std::vector<CandidatePtr>::const_iterator inEllipseIt = elementsInEllipse.begin(); inEllipseIt != elementsInEllipse.end(); inEllipseIt++){
295  mySignalPFCands.push_back(*inEllipseIt);
296  mySignalPFGammaCands.push_back(*inEllipseIt);
297  }
298  myPFTau.setsignalCands(mySignalPFCands);
299  //redefine isoPFGammaCandidates to be the outside elements
300  myIsolPFGammaCands=elementsOutEllipse;
301  myPFTau.setisolationGammaCands(myIsolPFGammaCands);
302  }
303 
304 
305  // Fill isolation collections, and calculate pt sum in isolation cone
306  float myIsolPFChargedHadrCands_Ptsum = 0.;
307  float myIsolPFGammaCands_Etsum = 0.;
308  for(size_t i = 0; i < myIsolPFChargedHadrCands.size(); i++) {
309  myIsolPFChargedHadrCands_Ptsum += myIsolPFChargedHadrCands[i]->pt();
310  myIsolPFCands.push_back(myIsolPFChargedHadrCands[i]);
311  }
312  myPFTau.setisolationPFChargedHadrCandsPtSum(myIsolPFChargedHadrCands_Ptsum);
313 
314  // Put neutral hadrons into collection
315  for(size_t i = 0; i < myIsolPFNeutrHadrCands.size(); i++) {
316  myIsolPFCands.push_back(myIsolPFNeutrHadrCands[i]);
317  }
318 
319  for(size_t i = 0; i < myIsolPFGammaCands.size(); i++) {
320  myIsolPFGammaCands_Etsum += myIsolPFGammaCands[i]->et();
321  myIsolPFCands.push_back(myIsolPFGammaCands[i]);
322  }
323  myPFTau.setisolationPFGammaCandsEtSum(myIsolPFGammaCands_Etsum);
324  myPFTau.setisolationCands(myIsolPFCands);
325 
326  //Making the alternateLorentzVector, i.e. direction with only signal components
327  math::XYZTLorentzVector alternatLorentzVect(0.,0.,0.,0.);
328  for (std::vector<CandidatePtr>::const_iterator iGammaCand = mySignalPFGammaCands.begin();
329  iGammaCand != mySignalPFGammaCands.end(); iGammaCand++) {
330  alternatLorentzVect+=(**iGammaCand).p4();
331  }
332 
333  for (std::vector<CandidatePtr>::const_iterator iChargedHadrCand = mySignalPFChargedHadrCands.begin();
334  iChargedHadrCand != mySignalPFChargedHadrCands.end(); iChargedHadrCand++) {
335  alternatLorentzVect+=(**iChargedHadrCand).p4();
336  }
337  // Alternate lorentz std::vector is always charged + gammas
338  myPFTau.setalternatLorentzVect(alternatLorentzVect);
339 
340  // Optionally add the neutral hadrons to the p4
342  for (std::vector<CandidatePtr>::const_iterator iNeutralHadrCand = mySignalPFNeutrHadrCands.begin();
343  iNeutralHadrCand != mySignalPFNeutrHadrCands.end(); iNeutralHadrCand++) {
344  alternatLorentzVect+=(**iNeutralHadrCand).p4();
345  }
346  }
347  myPFTau.setP4(alternatLorentzVect);
348 
349  // Set tau vertex as PV vertex
350  myPFTau.setVertex(math::XYZPoint(myPV.x(), myPV.y(), myPV.z()));
351  }
352 
353  // set the leading, signal cone and isolation annulus Tracks (the initial list of Tracks was catched through a JetTracksAssociation
354  // object, not through the charged hadr. PFCandidates inside the PFJet ;
355  // the motivation for considering these objects is the need for checking that a selection by the
356  // charged hadr. PFCandidates is equivalent to a selection by the rec. Tracks.)
357  TrackRef myleadTk=myPFTauElementsOperators.leadTk(MatchingConeMetric_,myMatchingConeSize,LeadTrack_minPt_);
358  myPFTau.setleadTrack(myleadTk);
359  if(myleadTk.isNonnull()){
360  double myleadTkDZ = (*myleadTk).dz(myPV.position());
361  double myTrackerSignalConeSize=myPFTauElementsOperators.computeConeSize(myTrackerSignalConeSizeTFormula,TrackerSignalConeSize_min_,TrackerSignalConeSize_max_);
362  double myTrackerIsolConeSize=myPFTauElementsOperators.computeConeSize(myTrackerIsolConeSizeTFormula,TrackerIsolConeSize_min_,TrackerIsolConeSize_max_);
364  myPFTau.setsignalTracks(myPFTauElementsOperators.tracksInCone((*myleadTk).momentum(),TrackerSignalConeMetric_,myTrackerSignalConeSize,PFTauAlgo_Track_minPt_,TrackLeadTrack_maxDZ_,myleadTkDZ, myPV));
365 
366  TrackRefVector myUnfilteredTracks = myPFTauElementsOperators.tracksInAnnulus((*myleadTk).momentum(),TrackerSignalConeMetric_,myTrackerSignalConeSize,TrackerIsolConeMetric_,myTrackerIsolConeSize,PFTauAlgo_Track_minPt_,TrackLeadTrack_maxDZ_,myleadTkDZ, myPV);
368  myPFTau.setisolationTracks(myFilteredTracks);
369 
370  }else{
371  myPFTau.setsignalTracks(myPFTauElementsOperators.tracksInCone((*myleadTk).momentum(),TrackerSignalConeMetric_,myTrackerSignalConeSize,PFTauAlgo_Track_minPt_));
372 
373  TrackRefVector myUnfilteredTracks = myPFTauElementsOperators.tracksInAnnulus((*myleadTk).momentum(),TrackerSignalConeMetric_,myTrackerSignalConeSize,TrackerIsolConeMetric_,myTrackerIsolConeSize,PFTauAlgo_Track_minPt_);
375  myPFTau.setisolationTracks(myFilteredTracks);
376  }
377  }
378 
379 
380  /* For elecron rejection */
381  double myECALenergy = 0.;
382  double myHCALenergy = 0.;
383  double myHCALenergy3x3 = 0.;
384  double myMaximumHCALPFClusterE = 0.;
385  double myMaximumHCALPFClusterEt = 0.;
386  double myStripClusterE = 0.;
387  double myEmfrac = -1.;
388  double myElectronPreIDOutput = -1111.;
389  bool myElecPreid = false;
390  reco::TrackRef myElecTrk;
391 
392  typedef std::pair<reco::PFBlockRef, unsigned> ElementInBlock;
393  typedef std::vector< ElementInBlock > ElementsInBlocks;
394 
395  //Use the electron rejection only in case there is a charged leading pion
396  if(myleadPFChargedCand.isNonnull()){
397  const reco::PFCandidate* pflch = dynamic_cast<const reco::PFCandidate*>(myleadPFChargedCand.get());
398  if (pflch == nullptr)
399  throw cms::Exception("Type Mismatch") << "The PFTau was not made from PFCandidates, and this outdated algorithm was not updated to cope with PFTaus made from other Candidates.\n";
400  myElectronPreIDOutput = pflch->mva_e_pi();
401 
402  math::XYZPointF myElecTrkEcalPos = pflch->positionAtECALEntrance();
403  myElecTrk = pflch->trackRef();//Electron candidate
404 
405  if(myElecTrk.isNonnull()) {
406  //FROM AOD
407  if(DataType_ == "AOD"){
408  // Corrected Cluster energies
409  for(int i=0;i<(int)myPFCands.size();i++){
410  const reco::PFCandidate* myPFCand = dynamic_cast<const reco::PFCandidate*>(myPFCands[i].get());
411  if (myPFCand == nullptr)
412  throw cms::Exception("Type Mismatch") << "The PFTau was not made from PFCandidates, and this outdated algorithm was not updated to cope with PFTaus made from other Candidates.\n";
413  myHCALenergy += myPFCand->hcalEnergy();
414  myECALenergy += myPFCand->ecalEnergy();
415 
416  math::XYZPointF candPos;
417  if (myPFCand->particleId()==1 || myPFCand->particleId()==2)//if charged hadron or electron
418  candPos = myPFCand->positionAtECALEntrance();
419  else
420  candPos = math::XYZPointF(myPFCand->px(),myPFCand->py(),myPFCand->pz());
421 
422  double deltaR = ROOT::Math::VectorUtil::DeltaR(myElecTrkEcalPos,candPos);
423  double deltaPhi = ROOT::Math::VectorUtil::DeltaPhi(myElecTrkEcalPos,candPos);
424  double deltaEta = std::abs(myElecTrkEcalPos.eta()-candPos.eta());
425  double deltaPhiOverQ = deltaPhi/(double)myElecTrk->charge();
426 
427  if (myPFCand->ecalEnergy() >= EcalStripSumE_minClusEnergy_ && deltaEta < EcalStripSumE_deltaEta_ &&
429  myStripClusterE += myPFCand->ecalEnergy();
430  }
431  if (deltaR<0.184) {
432  myHCALenergy3x3 += myPFCand->hcalEnergy();
433  }
434  if (myPFCand->hcalEnergy()>myMaximumHCALPFClusterE) {
435  myMaximumHCALPFClusterE = myPFCand->hcalEnergy();
436  }
437  if ((myPFCand->hcalEnergy()*fabs(sin(candPos.Theta())))>myMaximumHCALPFClusterEt) {
438  myMaximumHCALPFClusterEt = (myPFCand->hcalEnergy()*fabs(sin(candPos.Theta())));
439  }
440  }
441 
442  } else if(DataType_ == "RECO"){ //From RECO
443  // Against double counting of clusters
444  std::vector<math::XYZPoint> hcalPosV; hcalPosV.clear();
445  std::vector<math::XYZPoint> ecalPosV; ecalPosV.clear();
446  for(int i=0;i<(int)myPFCands.size();i++){
447  const reco::PFCandidate* myPFCand = dynamic_cast<const reco::PFCandidate*>(myPFCands[i].get());
448  if (myPFCand == nullptr)
449  throw cms::Exception("Type Mismatch") << "The PFTau was not made from PFCandidates, and this outdated algorithm was not updated to cope with PFTaus made from other Candidates.\n";
450  const ElementsInBlocks& elts = myPFCand->elementsInBlocks();
451  for(ElementsInBlocks::const_iterator it=elts.begin(); it!=elts.end(); ++it) {
452  const reco::PFBlock& block = *(it->first);
453  unsigned indexOfElementInBlock = it->second;
455  assert(indexOfElementInBlock<elements.size());
456 
457  const reco::PFBlockElement& element = elements[indexOfElementInBlock];
458 
459  if(element.type()==reco::PFBlockElement::HCAL) {
460  math::XYZPoint clusPos = element.clusterRef()->position();
461  double en = (double)element.clusterRef()->energy();
462  double et = (double)element.clusterRef()->energy()*fabs(sin(clusPos.Theta()));
463  if (en>myMaximumHCALPFClusterE) {
464  myMaximumHCALPFClusterE = en;
465  }
466  if (et>myMaximumHCALPFClusterEt) {
467  myMaximumHCALPFClusterEt = et;
468  }
469  if (!checkPos(hcalPosV,clusPos)) {
470  hcalPosV.push_back(clusPos);
471  myHCALenergy += en;
472  double deltaR = ROOT::Math::VectorUtil::DeltaR(myElecTrkEcalPos,clusPos);
473  if (deltaR<0.184) {
474  myHCALenergy3x3 += en;
475  }
476  }
477  } else if(element.type()==reco::PFBlockElement::ECAL) {
478  double en = (double)element.clusterRef()->energy();
479  math::XYZPoint clusPos = element.clusterRef()->position();
480  if (!checkPos(ecalPosV,clusPos)) {
481  ecalPosV.push_back(clusPos);
482  myECALenergy += en;
483  double deltaPhi = ROOT::Math::VectorUtil::DeltaPhi(myElecTrkEcalPos,clusPos);
484  double deltaEta = std::abs(myElecTrkEcalPos.eta()-clusPos.eta());
485  double deltaPhiOverQ = deltaPhi/(double)myElecTrk->charge();
486  if (en >= EcalStripSumE_minClusEnergy_ && deltaEta<EcalStripSumE_deltaEta_ && deltaPhiOverQ > EcalStripSumE_deltaPhiOverQ_minValue_ && deltaPhiOverQ < EcalStripSumE_deltaPhiOverQ_maxValue_) {
487  myStripClusterE += en;
488  }
489  }
490  }
491  } //end elements in blocks
492  } //end loop over PFcands
493  } //end RECO case
494  } // end check for null electrk
495  } // end check for null pfChargedHadrCand
496 
497  if ((myHCALenergy+myECALenergy)>0.)
498  myEmfrac = myECALenergy/(myHCALenergy+myECALenergy);
499  myPFTau.setemFraction((float)myEmfrac);
500 
501  // scale the appropriate quantities by the momentum of the electron if it exists
502  if (myElecTrk.isNonnull())
503  {
504  float myElectronMomentum = (float)myElecTrk->p();
505  if (myElectronMomentum > 0.)
506  {
507  myHCALenergy /= myElectronMomentum;
508  myMaximumHCALPFClusterE /= myElectronMomentum;
509  myHCALenergy3x3 /= myElectronMomentum;
510  myStripClusterE /= myElectronMomentum;
511  }
512  }
513  myPFTau.sethcalTotOverPLead((float)myHCALenergy);
514  myPFTau.sethcalMaxOverPLead((float)myMaximumHCALPFClusterE);
515  myPFTau.sethcal3x3OverPLead((float)myHCALenergy3x3);
516  myPFTau.setecalStripSumEOverPLead((float)myStripClusterE);
517  myPFTau.setmaximumHCALPFClusterEt(myMaximumHCALPFClusterEt);
518  myPFTau.setelectronPreIDOutput(myElectronPreIDOutput);
519  if (myElecTrk.isNonnull())
520  myPFTau.setelectronPreIDTrack(myElecTrk);
521  if (myElectronPreIDOutput > maximumForElectrionPreIDOutput_)
522  myElecPreid = true;
523  myPFTau.setelectronPreIDDecision(myElecPreid);
524 
525  // These need to be filled!
526  //myPFTau.setbremsRecoveryEOverPLead(my...);
527 
528  /* End elecron rejection */
529 
530  return myPFTau;
531 }
532 
533 bool
534 PFRecoTauAlgorithm::checkPos(const std::vector<math::XYZPoint>& CalPos,const math::XYZPoint& CandPos) const{
535  bool flag = false;
536  for (unsigned int i=0;i<CalPos.size();i++) {
537  if (CalPos[i] == CandPos) {
538  flag = true;
539  break;
540  }
541  }
542  return flag;
543  //return false;
544 }
std::vector< reco::CandidatePtr > PFGammaCandsInCone(const math::XYZVector &myVector, const std::string conemetric, const double conesize, const double minPt) const
double computeConeSize(const TFormula &ConeSizeTFormula, double ConeSizeMin, double ConeSizeMax)
std::string ECALIsolConeSizeFormula_
T getParameter(std::string const &) const
double ecalEnergy() const
return corrected Ecal energy
Definition: PFCandidate.h:222
Abstract base class for a PFBlock element (track, cluster...)
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:251
#define PFTauAlgo_ChargedHadrCand_minPt_
std::vector< reco::CandidatePtr > PFChargedHadrCandsInCone(const math::XYZVector &myVector, const std::string conemetric, const double conesize, const double minPt) const
std::vector< reco::CandidatePtr > PFChargedHadrCandsInAnnulus(const math::XYZVector &myVector, const std::string innercone_metric, const double innercone_size, const std::string outercone_metric, const double outercone_size, const double minPt) const
std::string TrackerIsolConeSizeFormula_
double maximumForElectrionPreIDOutput_
std::string ECALSignalConeSizeFormula_
reco::PFTau buildPFTau(const reco::PFTauTagInfoRef &, const reco::Vertex &) override
const reco::TrackRef leadTk(std::string matchingConeMetric, double matchingConeSize, double ptTrackMin) const
const TransientTrackBuilder * TransientTrackBuilder_
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:159
double y() const
y coordinate
Definition: Vertex.h:113
uint32_t ChargedHadrCand_IsolAnnulus_minNhits_
double px() const final
x coordinate of momentum vector
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
size_type size() const
Definition: OwnVector.h:264
#define PFTauAlgo_Track_minPt_
reco::TransientTrack build(const reco::Track *p) const
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::string HCALSignalConeSizeFormula_
bool UseChargedHadrCandLeadChargedHadrCand_tksDZconstraint_
const edm::OwnVector< reco::PFBlockElement > & elements() const
Definition: PFBlock.h:107
double EcalStripSumE_deltaPhiOverQ_minValue_
TFormula myHCALSignalConeSizeTFormula
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< float > > XYZPointF
point in space with cartesian internal representation
Definition: Point3D.h:10
const Point & position() const
position
Definition: Vertex.h:109
const math::XYZPointF & positionAtECALEntrance() const
Definition: PFCandidate.h:368
static const double deltaEta
Definition: CaloConstants.h:8
double ChargedHadrCandLeadChargedHadrCand_tksmaxDZ_
reco::TrackRef trackRef() const
Definition: PFCandidate.cc:442
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
#define PFTauAlgo_NeutrHadrCand_minPt_
const reco::TrackRefVector tracksInCone(const math::XYZVector &coneAxis, const std::string coneMetric, const double coneSize, const double ptTrackMin) const
TFormula myTrackerSignalConeSizeTFormula
std::string ECALSignalConeMetric_
double pz() const final
z coordinate of momentum vector
std::vector< reco::CandidatePtr > PFCandsInCone(const std::vector< reco::CandidatePtr > &PFCands, const math::XYZVector &myVector, const std::string conemetric, const double conesize, const double minPt) const
std::vector< reco::CandidatePtr > PFNeutrHadrCandsInCone(const math::XYZVector &myVector, const std::string conemetric, const double conesize, const double minPt) const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double z() const
z coordinate
Definition: Vertex.h:115
TFormula myECALSignalConeSizeTFormula
double AreaMetric_recoElements_maxabsEta_
std::vector< reco::CandidatePtr > PFNeutrHadrCandsInAnnulus(const math::XYZVector &myVector, const std::string innercone_metric, const double innercone_size, const std::string outercone_metric, const double outercone_size, const double minPt) const
uint32_t Track_IsolAnnulus_minNhits_
std::vector< reco::CandidatePtr > PFGammaCandsInAnnulus(const math::XYZVector &myVector, const std::string innercone_metric, const double innercone_size, const std::string outercone_metric, const double outercone_size, const double minPt) const
TFormula computeConeSizeTFormula(const std::string &ConeSizeFormula, const char *errorMessage)
std::string ECALIsolConeMetric_
double computeDeltaR(const math::XYZVector &vec1, const math::XYZVector &vec2)
Definition: TauTagTools.cc:8
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:168
std::string TrackerSignalConeMetric_
float mva_e_pi() const
mva for electron-pion discrimination
Definition: PFCandidate.h:314
std::string MatchingConeSizeFormula_
double x() const
x coordinate
Definition: Vertex.h:111
std::vector< ElementInBlock > ElementsInBlocks
TFormula myMatchingConeSizeTFormula
double EcalStripSumE_deltaPhiOverQ_maxValue_
TFormula myHCALIsolConeSizeTFormula
virtual double pt() const =0
transverse momentum
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
bool checkPos(const std::vector< math::XYZPoint > &, const math::XYZPoint &) const
TFormula myTrackerIsolConeSizeTFormula
double py() const final
y coordinate of momentum vector
std::pair< reco::PFBlockRef, unsigned > ElementInBlock
std::string HCALIsolConeSizeFormula_
et
define resolution functions of each parameter
std::pair< std::vector< reco::CandidatePtr >, std::vector< reco::CandidatePtr > > PFGammaCandsInOutEllipse(const std::vector< reco::CandidatePtr > &, const reco::Candidate &, double rPhi, double rEta, double maxPt) const
std::vector< reco::CandidatePtr > filteredPFChargedHadrCandsByNumTrkHits(const std::vector< reco::CandidatePtr > &theInitialPFCands, int ChargedHadrCand_tkminTrackerHitsn)
Definition: TauTagTools.cc:104
virtual Vector momentum() const =0
spatial momentum vector
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
fixed size matrix
reco::TrackRefVector filteredTracksByNumTrkHits(const reco::TrackRefVector &theInitialTracks, int tkminTrackerHitsn)
Definition: TauTagTools.cc:68
#define PFTauAlgo_GammaCand_minPt_
double hcalEnergy() const
return corrected Hcal energy
Definition: PFCandidate.h:232
std::string MatchingConeMetric_
virtual ParticleType particleId() const
Definition: PFCandidate.h:374
const reco::TrackRefVector tracksInAnnulus(const math::XYZVector &coneAxis, const std::string innerconeMetric, const double innerconeSize, const std::string outerconeMetric, const double outerconeSize, const double ptTrackMin) const
const ElementsInBlocks & elementsInBlocks() const
Definition: PFCandidate.cc:691
std::string TrackerIsolConeMetric_
std::string HCALSignalConeMetric_
std::string TrackerSignalConeSizeFormula_
TFormula myECALIsolConeSizeTFormula
#define PFTauAlgo_PFCand_minPt_
void setpfTauTagInfoRef(const PFTauTagInfoRef)
Definition: PFTau.cc:65
Block of elements.
Definition: PFBlock.h:30
std::string HCALIsolConeMetric_
reco::CandidatePtr leadChargedHadrCand(const std::string matchingcone_metric, const double matchingcone_size, const double minPt) const