CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TauDiscriminationAgainstCaloMuon.cc
Go to the documentation of this file.
1 
2 /*
3  * class TauDiscriminationAgainstCaloMuon
4  * created : Nov 20 2010
5  * revised :
6  * Authors : Christian Veelken (UC Davis)
7  */
8 
10 
13 
16 
24 
29 
34 
37 
39 
40 #include <TVector3.h>
41 #include <TMath.h>
42 
43 #include <string>
44 
45 using namespace reco;
46 
47 // define acess to lead. track for CaloTaus
48 template <typename T>
50 {
51  public:
53  {
54  return tau.leadTrack();
55  }
56  double getTrackPtSum(const T& tau) const
57  {
58  double trackPtSum = 0.;
59  for ( TrackRefVector::const_iterator signalTrack = tau.signalTracks().begin();
60  signalTrack != tau.signalTracks().end(); ++signalTrack ) {
61  trackPtSum += (*signalTrack)->pt();
62  }
63  return trackPtSum;
64  }
65 };
66 
67 // define acess to lead. track for PFTaus
68 template <>
70 {
71  public:
73  {
74  return tau.leadPFChargedHadrCand()->trackRef();
75  }
76  double getTrackPtSum(const reco::PFTau& tau) const
77  {
78  double trackPtSum = 0.;
79  for ( std::vector<PFCandidatePtr>::const_iterator signalTrack = tau.signalPFChargedHadrCands().begin();
80  signalTrack != tau.signalPFChargedHadrCands().end(); ++signalTrack ) {
81  trackPtSum += (*signalTrack)->pt();
82  }
83  return trackPtSum;
84  }
85 };
86 
87 template<class TauType, class TauDiscriminator>
88 class TauDiscriminationAgainstCaloMuon : public TauDiscriminationProducerBase<TauType, TauDiscriminator>
89 {
90  public:
91  // setup framework types for this tautype
92  typedef std::vector<TauType> TauCollection;
94 
97 
98  // called at the beginning of every event
99  void beginEvent(const edm::Event&, const edm::EventSetup&);
100 
101  double discriminate(const TauRef&);
102 
103  private:
110 
113 
116 
118 
121 
122  double drEcal_;
123  double drHcal_;
124 
125  double maxEnEcal_;
126  double maxEnHcal_;
127 
129 };
130 
131 template<class TauType, class TauDiscriminator>
133  : TauDiscriminationProducerBase<TauType, TauDiscriminator>(cfg)
134 {
135  srcEcalRecHitsBarrel_ = cfg.getParameter<edm::InputTag>("srcEcalRecHitsBarrel");
136  srcEcalRecHitsEndcap_ = cfg.getParameter<edm::InputTag>("srcEcalRecHitsEndcap");
137  srcHcalRecHits_ = cfg.getParameter<edm::InputTag>("srcHcalRecHits");
138 
139  srcVertex_ = cfg.getParameter<edm::InputTag>("srcVertex");
140 
141  minLeadTrackPt_ = cfg.getParameter<double>("minLeadTrackPt");
142  minLeadTrackPtFraction_ = cfg.getParameter<double>("minLeadTrackPtFraction");
143 
144  drEcal_ = cfg.getParameter<double>("dRecal");
145  drHcal_ = cfg.getParameter<double>("dRhcal");
146 
147  maxEnEcal_ = cfg.getParameter<double>("maxEnEcal");
148  maxEnHcal_ = cfg.getParameter<double>("maxEnHcal");
149 
150  maxEnToTrackRatio_ = cfg.getParameter<double>("maxEnToTrackRatio");
151 }
152 
153 template<class TauType, class TauDiscriminator>
155 {
156  evt.getByLabel(srcEcalRecHitsBarrel_, ebRecHits_);
157  evt.getByLabel(srcEcalRecHitsEndcap_, eeRecHits_);
158  evt.getByLabel(srcHcalRecHits_, hbheRecHits_);
159 
160  edm::ESHandle<TransientTrackBuilder> trackBuilderHandle;
161  evtSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", trackBuilderHandle);
162  trackBuilder_ = trackBuilderHandle.product();
163  if ( !trackBuilder_ ) {
164  edm::LogError ("TauDiscriminationAgainstCaloMuon::discriminate")
165  << " Failed to access TransientTrackBuilder !!";
166  }
167 
168  edm::ESHandle<CaloGeometry> caloGeometryHandle;
169  evtSetup.get<CaloGeometryRecord>().get(caloGeometryHandle);
170  caloGeometry_ = caloGeometryHandle.product();
171  if ( !caloGeometry_ ) {
172  edm::LogError ("TauDiscriminationAgainstCaloMuon::discriminate")
173  << " Failed to access CaloGeometry !!";
174  }
175 
177  evt.getByLabel(srcVertex_, vertices);
178  eventVertexPosition_ = GlobalPoint(0., 0., 0.);
179  if ( vertices->size() >= 1 ) {
180  const reco::Vertex& thePrimaryEventVertex = (*vertices->begin());
181  eventVertexPosition_ = GlobalPoint(thePrimaryEventVertex.x(), thePrimaryEventVertex.y(), thePrimaryEventVertex.z());
182  }
183 }
184 
185 double compEcalEnergySum(const EcalRecHitCollection& ecalRecHits,
186  const CaloSubdetectorGeometry* detGeometry,
187  const reco::TransientTrack& transientTrack, double dR,
188  const GlobalPoint& eventVertexPosition)
189 {
190  double ecalEnergySum = 0.;
192  ecalRecHit != ecalRecHits.end(); ++ecalRecHit ) {
193  const CaloCellGeometry* cellGeometry = detGeometry->getGeometry(ecalRecHit->detid());
194 
195  if ( !cellGeometry ) {
196  edm::LogError ("compEcalEnergySum")
197  << " Failed to access ECAL geometry for detId = " << ecalRecHit->detid().rawId()
198  << " --> skipping !!";
199  continue;
200  }
201 
202  const GlobalPoint& cellPosition = cellGeometry->getPosition();
203 
204 //--- CV: speed up computation by requiring eta-phi distance
205 // between cell position and track direction to be dR < 0.5
206  Vector3DBase<float, GlobalTag> cellPositionRelVertex = (cellPosition) - eventVertexPosition;
207  if ( deltaR(cellPositionRelVertex.eta(), cellPositionRelVertex.phi(),
208  transientTrack.track().eta(), transientTrack.track().phi()) > 0.5 ) continue;
209 
210  TrajectoryStateClosestToPoint dcaPosition = transientTrack.trajectoryStateClosestToPoint(cellPosition);
211 
212  Vector3DBase<float, GlobalTag> d = (cellPosition - dcaPosition.position());
213 
214  TVector3 d3(d.x(), d.y(), d.z());
215  TVector3 dir(transientTrack.track().px(), transientTrack.track().py(), transientTrack.track().pz());
216 
217  double dPerp = d3.Cross(dir.Unit()).Mag();
218  double dParl = TVector3(cellPosition.x(), cellPosition.y(), cellPosition.z()).Dot(dir.Unit());
219 
220  if ( dPerp < dR && dParl > 100. ) {
221  ecalEnergySum += ecalRecHit->energy();
222  }
223  }
224 
225  return ecalEnergySum;
226 }
227 
228 double compHcalEnergySum(const HBHERecHitCollection& hcalRecHits,
229  const CaloSubdetectorGeometry* hbGeometry, const CaloSubdetectorGeometry* heGeometry,
230  const reco::TransientTrack& transientTrack, double dR,
231  const GlobalPoint& eventVertexPosition)
232 {
233  double hcalEnergySum = 0.;
234  for ( HBHERecHitCollection::const_iterator hcalRecHit = hcalRecHits.begin();
235  hcalRecHit != hcalRecHits.end(); ++hcalRecHit ) {
236  const CaloCellGeometry* hbCellGeometry = hbGeometry->getGeometry(hcalRecHit->detid());
237  const CaloCellGeometry* heCellGeometry = heGeometry->getGeometry(hcalRecHit->detid());
238 
239  const GlobalPoint* cellPosition = 0;
240  if ( hbCellGeometry ) cellPosition = &(hbCellGeometry->getPosition());
241  if ( heCellGeometry ) cellPosition = &(heCellGeometry->getPosition());
242 
243  if ( !cellPosition ) {
244  edm::LogError ("compHcalEnergySum")
245  << " Failed to access HCAL geometry for detId = " << hcalRecHit->detid().rawId()
246  << " --> skipping !!";
247  continue;
248  }
249 
250 //--- CV: speed up computation by requiring eta-phi distance
251 // between cell position and track direction to be dR < 0.5
252  Vector3DBase<float, GlobalTag> cellPositionRelVertex = (*cellPosition) - eventVertexPosition;
253  if ( deltaR(cellPositionRelVertex.eta(), cellPositionRelVertex.phi(),
254  transientTrack.track().eta(), transientTrack.track().phi()) > 0.5 ) continue;
255 
256  TrajectoryStateClosestToPoint dcaPosition = transientTrack.trajectoryStateClosestToPoint(*cellPosition);
257 
258  Vector3DBase<float, GlobalTag> d = ((*cellPosition) - dcaPosition.position());
259 
260  TVector3 d3(d.x(), d.y(), d.z());
261  TVector3 dir(transientTrack.track().px(), transientTrack.track().py(), transientTrack.track().pz());
262 
263  double dPerp = d3.Cross(dir.Unit()).Mag();
264  double dParl = TVector3(cellPosition->x(), cellPosition->y(), cellPosition->z()).Dot(dir.Unit());
265 
266  if ( dPerp < dR && dParl > 100. ) {
267  hcalEnergySum += hcalRecHit->energy();
268  }
269  }
270 
271  return hcalEnergySum;
272 }
273 
274 template<class TauType, class TauDiscriminator>
276 {
277  if ( !(trackBuilder_ && caloGeometry_) ) return 0.;
278 
279  const CaloSubdetectorGeometry* ebGeometry = caloGeometry_->getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
280  const CaloSubdetectorGeometry* eeGeometry = caloGeometry_->getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
281  const CaloSubdetectorGeometry* hbGeometry = caloGeometry_->getSubdetectorGeometry(DetId::Hcal, HcalBarrel);
282  const CaloSubdetectorGeometry* heGeometry = caloGeometry_->getSubdetectorGeometry(DetId::Hcal, HcalEndcap);
283 
284  TrackRef leadTrackRef = leadTrackExtractor_.getLeadTrack(*tau);
285 
286  if ( (leadTrackRef.isAvailable() || leadTrackRef.isTransient()) && leadTrackRef.isNonnull() ) {
287  double leadTrackPt = leadTrackRef->pt();
288  double trackPtSum = leadTrackExtractor_.getTrackPtSum(*tau);
289 
290  double leadTrackPtFraction = ( trackPtSum > 0. ) ? (leadTrackPt/trackPtSum) : -1.;
291 
292  if ( leadTrackPt > minLeadTrackPt_ && leadTrackPtFraction > minLeadTrackPtFraction_ ) {
293  reco::TransientTrack transientTrack = trackBuilder_->build(leadTrackRef);
294 
295  double ebEnergySum = compEcalEnergySum(*ebRecHits_, ebGeometry, transientTrack, drEcal_, eventVertexPosition_);
296  double eeEnergySum = compEcalEnergySum(*eeRecHits_, eeGeometry, transientTrack, drEcal_, eventVertexPosition_);
297  double ecalEnergySum = ebEnergySum + eeEnergySum;
298 
299  double hbheEnergySum = compHcalEnergySum(*hbheRecHits_, hbGeometry, heGeometry, transientTrack, drHcal_, eventVertexPosition_);
300 
301  double caloEnergySum = ecalEnergySum + hbheEnergySum;
302 
303  if ( ecalEnergySum < maxEnEcal_ &&
304  hbheEnergySum < maxEnHcal_ &&
305  caloEnergySum < (maxEnToTrackRatio_*leadTrackPt) ) return 0.;
306  }
307  }
308 
309  return 1.;
310 }
311 
313 
316 
T getParameter(std::string const &) const
TauLeadTrackExtractor< TauType > leadTrackExtractor_
TauDiscriminationAgainstCaloMuon(const edm::ParameterSet &)
const PFCandidatePtr & leadPFChargedHadrCand() const
Definition: PFTau.cc:61
edm::Handle< HBHERecHitCollection > hbheRecHits_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
double y() const
y coordinate
Definition: Vertex.h:110
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
std::vector< EcalRecHit >::const_iterator const_iterator
T y() const
Definition: PV3DBase.h:63
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:137
edm::Ref< TauCollection > TauRef
Definition: Tau.h:40
double px() const
x coordinate of momentum vector
Definition: TrackBase.h:131
bool isAvailable() const
Definition: Ref.h:276
virtual const CaloCellGeometry * getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
double compHcalEnergySum(const HBHERecHitCollection &hcalRecHits, const CaloSubdetectorGeometry *hbGeometry, const CaloSubdetectorGeometry *heGeometry, const reco::TransientTrack &transientTrack, double dR, const GlobalPoint &eventVertexPosition)
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
TauDiscriminationAgainstCaloMuon< PFTau, PFTauDiscriminator > PFRecoTauDiscriminationAgainstCaloMuon
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:139
T z() const
Definition: PV3DBase.h:64
double z() const
y coordinate
Definition: Vertex.h:112
double compEcalEnergySum(const EcalRecHitCollection &ecalRecHits, const CaloSubdetectorGeometry *detGeometry, const reco::TransientTrack &transientTrack, double dR, const GlobalPoint &eventVertexPosition)
TauDiscriminationAgainstCaloMuon< CaloTau, CaloTauDiscriminator > CaloRecoTauDiscriminationAgainstCaloMuon
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
double pz() const
z coordinate of momentum vector
Definition: TrackBase.h:135
void beginEvent(const edm::Event &, const edm::EventSetup &)
const_iterator end() const
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
double x() const
x coordinate
Definition: Vertex.h:108
edm::Handle< EcalRecHitCollection > eeRecHits_
const Track & track() const
TrajectoryStateClosestToPoint trajectoryStateClosestToPoint(const GlobalPoint &point) const
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
reco::TrackRef getLeadTrack(const reco::PFTau &tau) const
double getTrackPtSum(const T &tau) const
T eta() const
Definition: PV3DBase.h:76
double getTrackPtSum(const reco::PFTau &tau) const
dbl *** dir
Definition: mlp_gen.cc:35
reco::TrackRef getLeadTrack(const T &tau) const
edm::Handle< EcalRecHitCollection > ebRecHits_
long double T
const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
T x() const
Definition: PV3DBase.h:62
bool isTransient() const
Checks if this ref is transient (i.e. not persistable).
Definition: Ref.h:279
const std::vector< reco::PFCandidatePtr > & signalPFChargedHadrCands() const
Charged hadrons in signal region.
Definition: PFTau.cc:74
const_iterator begin() const
double py() const
y coordinate of momentum vector
Definition: TrackBase.h:133