CMS 3D CMS Logo

RecoTauElectronRejectionPlugin.cc
Go to the documentation of this file.
1 /*
2  * ===========================================================================
3  *
4  * Filename: RecoTauElectronRejectionPlugin.cc
5  *
6  * Description: Add electron rejection information to PFTau
7  *
8  * Authors: Chi Nhan Nguyen, Simone Gennai, Evan Friis
9  *
10  * ===========================================================================
11  */
12 
19 #include <Math/VectorUtil.h>
20 #include <algorithm>
21 
22 namespace reco { namespace tau {
23 
25  public:
28  void operator()(PFTau&) const override;
29  private:
37 };
38 
41  // Load parameters
43  pset.getParameter<double>("ElecPreIDLeadTkMatch_maxDR");
45  pset.getParameter<double>("EcalStripSumE_minClusEnergy");
47  pset.getParameter<double>("EcalStripSumE_deltaEta");
49  pset.getParameter<double>("EcalStripSumE_deltaPhiOverQ_minValue");
51  pset.getParameter<double>("EcalStripSumE_deltaPhiOverQ_maxValue");
53  pset.getParameter<double>("maximumForElectrionPreIDOutput");
54  DataType_ = pset.getParameter<std::string>("DataType");
55 }
56 
57 namespace {
58 bool checkPos(std::vector<math::XYZPoint> CalPos,math::XYZPoint CandPos) {
59  bool flag = false;
60  for (unsigned int i=0;i<CalPos.size();i++) {
61  if (CalPos[i] == CandPos) {
62  flag = true;
63  break;
64  }
65  }
66  return flag;
67 }
68 }
69 
71  // copy pasted from PFRecoTauAlgorithm...
72  double myECALenergy = 0.;
73  double myHCALenergy = 0.;
74  double myHCALenergy3x3 = 0.;
75  double myMaximumHCALPFClusterE = 0.;
76  double myMaximumHCALPFClusterEt = 0.;
77  double myStripClusterE = 0.;
78  double myEmfrac = -1.;
79  double myElectronPreIDOutput = -1111.;
80  bool myElecPreid = false;
81  reco::TrackRef myElecTrk;
82 
83  typedef std::pair<reco::PFBlockRef, unsigned> ElementInBlock;
84  typedef std::vector< ElementInBlock > ElementsInBlocks;
85 
86  PFCandidatePtr myleadPFChargedCand = tau.leadPFChargedHadrCand();
87  // Build list of PFCands in tau
88  std::vector<PFCandidatePtr> myPFCands;
89  myPFCands.reserve(tau.isolationPFCands().size()+tau.signalPFCands().size());
90 
91  std::copy(tau.isolationPFCands().begin(), tau.isolationPFCands().end(),
92  std::back_inserter(myPFCands));
93  std::copy(tau.signalPFCands().begin(), tau.signalPFCands().end(),
94  std::back_inserter(myPFCands));
95 
96  //Use the electron rejection only in case there is a charged leading pion
97  if(myleadPFChargedCand.isNonnull()){
98  myElectronPreIDOutput = myleadPFChargedCand->mva_e_pi();
99 
100  math::XYZPointF myElecTrkEcalPos = myleadPFChargedCand->positionAtECALEntrance();
101  myElecTrk = myleadPFChargedCand->trackRef();//Electron candidate
102 
103  if(myElecTrk.isNonnull()) {
104  //FROM AOD
105  if(DataType_ == "AOD"){
106  // Corrected Cluster energies
107  for(int i=0;i<(int)myPFCands.size();i++){
108  myHCALenergy += myPFCands[i]->hcalEnergy();
109  myECALenergy += myPFCands[i]->ecalEnergy();
110 
111  math::XYZPointF candPos;
112  if (myPFCands[i]->particleId()==1 || myPFCands[i]->particleId()==2)//if charged hadron or electron
113  candPos = myPFCands[i]->positionAtECALEntrance();
114  else
115  candPos = math::XYZPointF(myPFCands[i]->px(),myPFCands[i]->py(),myPFCands[i]->pz());
116 
117  double deltaR = ROOT::Math::VectorUtil::DeltaR(myElecTrkEcalPos,candPos);
118  double deltaPhi = ROOT::Math::VectorUtil::DeltaPhi(myElecTrkEcalPos,candPos);
119  double deltaEta = std::abs(myElecTrkEcalPos.eta()-candPos.eta());
120  double deltaPhiOverQ = deltaPhi/(double)myElecTrk->charge();
121 
122  if (myPFCands[i]->ecalEnergy() >= EcalStripSumE_minClusEnergy_ && deltaEta < EcalStripSumE_deltaEta_ &&
124  myStripClusterE += myPFCands[i]->ecalEnergy();
125  }
126  if (deltaR<0.184) {
127  myHCALenergy3x3 += myPFCands[i]->hcalEnergy();
128  }
129  if (myPFCands[i]->hcalEnergy()>myMaximumHCALPFClusterE) {
130  myMaximumHCALPFClusterE = myPFCands[i]->hcalEnergy();
131  }
132  if ((myPFCands[i]->hcalEnergy()*fabs(sin(candPos.Theta())))>myMaximumHCALPFClusterEt) {
133  myMaximumHCALPFClusterEt = (myPFCands[i]->hcalEnergy()*fabs(sin(candPos.Theta())));
134  }
135  }
136 
137  } else if(DataType_ == "RECO"){ //From RECO
138  // Against double counting of clusters
139  std::vector<math::XYZPoint> hcalPosV; hcalPosV.clear();
140  std::vector<math::XYZPoint> ecalPosV; ecalPosV.clear();
141  for(int i=0;i<(int)myPFCands.size();i++){
142  const ElementsInBlocks& elts = myPFCands[i]->elementsInBlocks();
143  for(ElementsInBlocks::const_iterator it=elts.begin(); it!=elts.end(); ++it) {
144  const reco::PFBlock& block = *(it->first);
145  unsigned indexOfElementInBlock = it->second;
147  assert(indexOfElementInBlock<elements.size());
148 
149  const reco::PFBlockElement& element = elements[indexOfElementInBlock];
150 
151  if(element.type()==reco::PFBlockElement::HCAL) {
152  math::XYZPoint clusPos = element.clusterRef()->position();
153  double en = (double)element.clusterRef()->energy();
154  double et = (double)element.clusterRef()->energy()*fabs(sin(clusPos.Theta()));
155  if (en>myMaximumHCALPFClusterE) {
156  myMaximumHCALPFClusterE = en;
157  }
158  if (et>myMaximumHCALPFClusterEt) {
159  myMaximumHCALPFClusterEt = et;
160  }
161  if (!checkPos(hcalPosV,clusPos)) {
162  hcalPosV.push_back(clusPos);
163  myHCALenergy += en;
164  double deltaR = ROOT::Math::VectorUtil::DeltaR(myElecTrkEcalPos,clusPos);
165  if (deltaR<0.184) {
166  myHCALenergy3x3 += en;
167  }
168  }
169  } else if(element.type()==reco::PFBlockElement::ECAL) {
170  double en = (double)element.clusterRef()->energy();
171  math::XYZPoint clusPos = element.clusterRef()->position();
172  if (!checkPos(ecalPosV,clusPos)) {
173  ecalPosV.push_back(clusPos);
174  myECALenergy += en;
175  double deltaPhi = ROOT::Math::VectorUtil::DeltaPhi(myElecTrkEcalPos,clusPos);
176  double deltaEta = std::abs(myElecTrkEcalPos.eta()-clusPos.eta());
177  double deltaPhiOverQ = deltaPhi/(double)myElecTrk->charge();
178  if (en >= EcalStripSumE_minClusEnergy_ && deltaEta<EcalStripSumE_deltaEta_ && deltaPhiOverQ > EcalStripSumE_deltaPhiOverQ_minValue_ && deltaPhiOverQ < EcalStripSumE_deltaPhiOverQ_maxValue_) {
179  myStripClusterE += en;
180  }
181  }
182  }
183  } //end elements in blocks
184  } //end loop over PFcands
185  } //end RECO case
186  } // end check for null electrk
187  } // end check for null pfChargedHadrCand
188 
189  if ((myHCALenergy+myECALenergy)>0.)
190  myEmfrac = myECALenergy/(myHCALenergy+myECALenergy);
191  tau.setemFraction((float)myEmfrac);
192 
193  // scale the appropriate quantities by the momentum of the electron if it exists
194  if (myElecTrk.isNonnull())
195  {
196  float myElectronMomentum = (float)myElecTrk->p();
197  if (myElectronMomentum > 0.)
198  {
199  myHCALenergy /= myElectronMomentum;
200  myMaximumHCALPFClusterE /= myElectronMomentum;
201  myHCALenergy3x3 /= myElectronMomentum;
202  myStripClusterE /= myElectronMomentum;
203  }
204  }
205  tau.sethcalTotOverPLead((float)myHCALenergy);
206  tau.sethcalMaxOverPLead((float)myMaximumHCALPFClusterE);
207  tau.sethcal3x3OverPLead((float)myHCALenergy3x3);
208  tau.setecalStripSumEOverPLead((float)myStripClusterE);
209  tau.setmaximumHCALPFClusterEt(myMaximumHCALPFClusterEt);
210  tau.setelectronPreIDOutput(myElectronPreIDOutput);
211  if (myElecTrk.isNonnull())
212  tau.setelectronPreIDTrack(myElecTrk);
213  if (myElectronPreIDOutput > maximumForElectrionPreIDOutput_)
214  myElecPreid = true;
215  tau.setelectronPreIDDecision(myElecPreid);
216 
217  // These need to be filled!
218  //tau.setbremsRecoveryEOverPLead(my...);
219 
220  /* End elecron rejection */
221 }
222 }} // end namespace reco::tau
226  "RecoTauElectronRejectionPlugin");
T getParameter(std::string const &) const
Abstract base class for a PFBlock element (track, cluster...)
void setelectronPreIDOutput(const float &)
Definition: PFTau.cc:244
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:253
const std::vector< reco::PFCandidatePtr > & isolationPFCands() const
PFCandidates in isolation region.
Definition: PFTau.cc:87
const PFCandidatePtr & leadPFChargedHadrCand() const
Definition: PFTau.cc:67
void setelectronPreIDDecision(const bool &)
Definition: PFTau.cc:245
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
size_type size() const
Definition: OwnVector.h:264
const edm::OwnVector< reco::PFBlockElement > & elements() const
Definition: PFBlock.h:107
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< float > > XYZPointF
point in space with cartesian internal representation
Definition: Point3D.h:10
void sethcal3x3OverPLead(const float &)
Definition: PFTau.cc:240
void setemFraction(const float &)
Definition: PFTau.cc:237
const std::vector< reco::PFCandidatePtr > & signalPFCands() const
PFCandidates in signal region.
Definition: PFTau.cc:78
static const double deltaEta
Definition: CaloConstants.h:8
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:28
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:168
double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:22
void sethcalMaxOverPLead(const float &)
Definition: PFTau.cc:239
std::vector< ElementInBlock > ElementsInBlocks
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
std::pair< reco::PFBlockRef, unsigned > ElementInBlock
et
define resolution functions of each parameter
RecoTauElectronRejectionPlugin(const edm::ParameterSet &pset, edm::ConsumesCollector &&iC)
fixed size matrix
void setmaximumHCALPFClusterEt(const float &)
Definition: PFTau.cc:224
void setecalStripSumEOverPLead(const float &)
Definition: PFTau.cc:241
#define DEFINE_EDM_PLUGIN(factory, type, name)
void sethcalTotOverPLead(const float &)
Definition: PFTau.cc:238
void setelectronPreIDTrack(const reco::TrackRef &)
Definition: PFTau.cc:243
def move(src, dest)
Definition: eostools.py:510
Block of elements.
Definition: PFBlock.h:30