CMS 3D CMS Logo

Classes | Functions
CommonUsefulStuff.h File Reference
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "Geometry/CaloGeometry/interface/CaloGeometry.h"
#include "DataFormats/DetId/interface/DetId.h"
#include "DataFormats/HcalDetId/interface/HcalDetId.h"
#include "DataFormats/EcalDetId/interface/EEDetId.h"
#include "DataFormats/EcalDetId/interface/EBDetId.h"
#include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
#include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
#include "Geometry/Records/interface/CaloGeometryRecord.h"
#include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
#include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "DataFormats/GeometryVector/interface/GlobalPoint.h"
#include "DataFormats/GeometryVector/interface/GlobalVector.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "CommonTools/UtilAlgos/interface/DeltaR.h"
#include "CommonTools/UtilAlgos/interface/TFileService.h"
#include "TROOT.h"
#include "TFile.h"
#include "TTree.h"
#include "TH1F.h"
#include "TString.h"

Go to the source code of this file.

Classes

struct  MaxHit_struct
 

Functions

double ecalEnergyInCone (const GlobalPoint center, double radius, const EcalRecHitCollection ecalCol, const CaloGeometry *geo)
 
double ecalEnergyInCone (const GlobalVector trackMom, const GlobalPoint center, double radius, const EcalRecHitCollection ecalCol, const CaloGeometry *geo)
 
double getDistInPlane (const GlobalVector trackDirection, const GlobalPoint caloPoint, const GlobalPoint rechitPoint, double coneHeight)
 
double getDistInPlaneSimple (const GlobalPoint caloPoint, const GlobalPoint rechitPoint)
 
double getDistInPlaneTrackDir (const GlobalPoint caloPoint, const GlobalVector caloVector, const GlobalPoint rechitPoint)
 

Function Documentation

double ecalEnergyInCone ( const GlobalPoint  center,
double  radius,
const EcalRecHitCollection  ecalCol,
const CaloGeometry geo 
)
inline

Definition at line 220 of file CommonUsefulStuff.h.

References edm::SortedCollection< T, SORT >::begin(), EcalBarrel, EcalEndcap, edm::SortedCollection< T, SORT >::end(), getDistInPlaneSimple(), CaloGeometry::getPosition(), EBDetId::hashedIndex(), EEDetId::hashedIndex(), mps_fire::i, and TCMET_cfi::radius.

221 {
222  double eECALcone = 0;
223  std::vector<int> usedHitsEcal;
224  usedHitsEcal.clear();
225 
226  for (std::vector<EcalRecHit>::const_iterator ehit=ecalCol.begin(); ehit!=ecalCol.end(); ehit++)
227  {
228  //This is a precaution for the case when hitCollection contains duplicats.
229  bool hitIsUsed=false;
230  int hitHashedIndex=-10000;
231  if (ehit->id().subdetId()==EcalBarrel)
232  {
233  EBDetId did(ehit->id());
234  hitHashedIndex=did.hashedIndex();
235  }
236  if (ehit->id().subdetId()==EcalEndcap)
237  {
238  EEDetId did(ehit->id());
239  hitHashedIndex=did.hashedIndex();
240  }
241  for (uint32_t i=0; i<usedHitsEcal.size(); i++)
242  {
243  if (usedHitsEcal[i]==hitHashedIndex) hitIsUsed=true;
244  }
245  if (hitIsUsed) continue;
246  usedHitsEcal.push_back(hitHashedIndex);
247  // -----------------------------------------------
248 
249  GlobalPoint pos = geo->getPosition((*ehit).detid());
250 
251  if (getDistInPlaneSimple(center,pos) < radius)
252  {
253  eECALcone += ehit->energy();
254  }
255  }
256  return eECALcone;
257 }
int hashedIndex() const
get a compact index for arrays
Definition: EBDetId.h:86
const GlobalPoint & getPosition(const DetId &id) const
Get the position of a given detector id.
Definition: CaloGeometry.cc:70
const_iterator end() const
int hashedIndex() const
Definition: EEDetId.h:182
double getDistInPlaneSimple(const GlobalPoint caloPoint, const GlobalPoint rechitPoint)
const_iterator begin() const
double ecalEnergyInCone ( const GlobalVector  trackMom,
const GlobalPoint  center,
double  radius,
const EcalRecHitCollection  ecalCol,
const CaloGeometry geo 
)
inline

Definition at line 260 of file CommonUsefulStuff.h.

References edm::SortedCollection< T, SORT >::begin(), EcalBarrel, EcalEndcap, edm::SortedCollection< T, SORT >::end(), getDistInPlaneTrackDir(), CaloGeometry::getPosition(), EBDetId::hashedIndex(), EEDetId::hashedIndex(), mps_fire::i, and TCMET_cfi::radius.

261 {
262 
263  double eECALcone = 0;
264  std::vector<int> usedHitsEcal;
265  usedHitsEcal.clear();
266  for (std::vector<EcalRecHit>::const_iterator ehit=ecalCol.begin(); ehit!=ecalCol.end(); ehit++)
267  {
268  //This is a precaution for the case when hitCollection contains duplicats.
269  bool hitIsUsed=false;
270  int hitHashedIndex=-10000;
271  if (ehit->id().subdetId()==EcalBarrel)
272  {
273  EBDetId did(ehit->id());
274  hitHashedIndex=did.hashedIndex();
275  }
276  if (ehit->id().subdetId()==EcalEndcap)
277  {
278  EEDetId did(ehit->id());
279  hitHashedIndex=did.hashedIndex();
280  }
281  for (uint32_t i=0; i<usedHitsEcal.size(); i++)
282  {
283  if (usedHitsEcal[i]==hitHashedIndex) hitIsUsed=true;
284  }
285  if (hitIsUsed) continue;
286  usedHitsEcal.push_back(hitHashedIndex);
287  // -----------------------------------------------
288 
289  GlobalPoint pos = geo->getPosition((*ehit).detid());
290 
291  if (getDistInPlaneTrackDir(center, trackMom ,pos) < radius)
292  {
293  eECALcone += ehit->energy();
294  }
295  }
296  return eECALcone;
297 }
int hashedIndex() const
get a compact index for arrays
Definition: EBDetId.h:86
double getDistInPlaneTrackDir(const GlobalPoint caloPoint, const GlobalVector caloVector, const GlobalPoint rechitPoint)
const GlobalPoint & getPosition(const DetId &id) const
Get the position of a given detector id.
Definition: CaloGeometry.cc:70
const_iterator end() const
int hashedIndex() const
Definition: EEDetId.h:182
const_iterator begin() const
double getDistInPlane ( const GlobalVector  trackDirection,
const GlobalPoint  caloPoint,
const GlobalPoint  rechitPoint,
double  coneHeight 
)
inline

Definition at line 138 of file CommonUsefulStuff.h.

References Vector3DBase< T, FrameTag >::dot(), PV3DBase< T, PVType, FrameType >::mag(), Vector3DBase< T, FrameTag >::unit(), PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

142 {
143 
144  // The iso track candidate hits the Calo (Ecal or Hcal) at "caloPoint"
145  // with direction "trackDirection".
146 
147  // "rechitPoint" is the position of the rechit. We only care about
148  // the direction of the rechit.
149 
150  // Consider the rechitPoint as characterized by angles theta and phi
151  // wrt the origin which points at the calo cell of the rechit. In
152  // some sense the distance along the line theta/phi is arbitrary. A
153  // simplified choice might be to put the rechit at the surface of
154  // the Hcal. Our approach is to see whether/where this line
155  // intersects a cone of height "coneHeight" with vertex at caloPoint
156  // aligned with trackDirection.
157  // To that end, this function returns the distance between the
158  // center of the base of the cone and the intersection of the rechit
159  // line and the plane that contains the base of the cone. This
160  // distance is compared with the radius of the cone outside this
161  // function.
162 
163 
164  // Make vector of length cone height along track direction
165  const GlobalVector heightVector = trackDirection*coneHeight;
166 
167  // Make vector from origin to point where iso track intersects the
168  // calorimeter.
169  const GlobalVector caloIntersectVector(caloPoint.x(),
170  caloPoint.y(),
171  caloPoint.z());
172 
173  // Make vector from origin to point in center of base of cone
174  const GlobalVector coneBaseVector = heightVector+caloIntersectVector;
175 
176 // Make point in center of base of cone
177  const GlobalPoint coneBasePoint(coneBaseVector.x(),
178  coneBaseVector.y(),
179  coneBaseVector.z());
180 
181  // Make unit vector pointing at rechit.
182  const GlobalVector rechitVector(rechitPoint.x(),
183  rechitPoint.y(),
184  rechitPoint.z());
185  const GlobalVector rechitDirection = rechitVector.unit();
186 
187  // Find distance "r" along "rechit line" (with angles theta2 and
188  // phi2) where line intersects plane defined by base of cone.
189 
190  // Definition plane of that contains base of cone:
191  // trackDirection.x() (x - coneBaseVector.x()) +
192  // trackDirection.y() (y - coneBaseVector.y()) +
193  // trackDirection.z() (z - coneBaseVector.z()) = 0
194 
195  // Point P_{rh} where rechit line intersects plane:
196  // (rechitdist sin(theta2) cos(phi2),
197  // rechitdist sin(theta2) cos(phi2),
198  // rechitdist cos(theta2))
199 
200  // Substitute P_{rh} into equation for plane and solve for rechitdist.
201  // rechitDist turns out to be the ratio of dot products:
202 
203  double rechitdist = trackDirection.dot(coneBaseVector)/trackDirection.dot(rechitDirection);
204 
205  // Now find distance between point at center of cone base and point
206  // where the "rechit line" intersects the plane defined by the base
207  // of the cone; i.e. the effectiveRecHitPoint.
208  const GlobalVector effectiveRechitVector = rechitdist*rechitDirection;
209  const GlobalPoint effectiveRechitPoint(effectiveRechitVector.x(),
210  effectiveRechitVector.y(),
211  effectiveRechitVector.z());
212 
213 
214  GlobalVector distance_vector = effectiveRechitPoint-coneBasePoint;
215  return distance_vector.mag();
216 }
T y() const
Definition: PV3DBase.h:63
PreciseFloatType< T, U >::Type dot(const Vector3DBase< U, FrameTag > &v) const
Definition: Vector3DBase.h:107
T mag() const
Definition: PV3DBase.h:67
T z() const
Definition: PV3DBase.h:64
Vector3DBase unit() const
Definition: Vector3DBase.h:57
T x() const
Definition: PV3DBase.h:62
double getDistInPlaneSimple ( const GlobalPoint  caloPoint,
const GlobalPoint  rechitPoint 
)
inline

Definition at line 58 of file CommonUsefulStuff.h.

References Vector3DBase< T, FrameTag >::dot(), PV3DBase< T, PVType, FrameType >::mag(), Vector3DBase< T, FrameTag >::unit(), PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by ecalEnergyInCone().

60 {
61 
62  // Simplified version of getDistInPlane
63  // Assume track direction is origin -> point of hcal intersection
64 
65  const GlobalVector caloIntersectVector(caloPoint.x(),
66  caloPoint.y(),
67  caloPoint.z());
68 
69  const GlobalVector caloIntersectUnitVector = caloIntersectVector.unit();
70 
71  const GlobalVector rechitVector(rechitPoint.x(),
72  rechitPoint.y(),
73  rechitPoint.z());
74 
75  const GlobalVector rechitUnitVector = rechitVector.unit();
76  double dotprod = caloIntersectUnitVector.dot(rechitUnitVector);
77  double rechitdist = caloIntersectVector.mag()/dotprod;
78 
79 
80  const GlobalVector effectiveRechitVector = rechitdist*rechitUnitVector;
81  const GlobalPoint effectiveRechitPoint(effectiveRechitVector.x(),
82  effectiveRechitVector.y(),
83  effectiveRechitVector.z());
84 
85 
86  GlobalVector distance_vector = effectiveRechitPoint-caloPoint;
87 
88  if (dotprod > 0.)
89  {
90  return distance_vector.mag();
91  }
92  else
93  {
94  return 999999.;
95 
96  }
97 
98 }
T y() const
Definition: PV3DBase.h:63
PreciseFloatType< T, U >::Type dot(const Vector3DBase< U, FrameTag > &v) const
Definition: Vector3DBase.h:107
T mag() const
Definition: PV3DBase.h:67
T z() const
Definition: PV3DBase.h:64
Vector3DBase unit() const
Definition: Vector3DBase.h:57
T x() const
Definition: PV3DBase.h:62
double getDistInPlaneTrackDir ( const GlobalPoint  caloPoint,
const GlobalVector  caloVector,
const GlobalPoint  rechitPoint 
)
inline

Definition at line 100 of file CommonUsefulStuff.h.

References Vector3DBase< T, FrameTag >::dot(), PV3DBase< T, PVType, FrameType >::mag(), Vector3DBase< T, FrameTag >::unit(), PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by ecalEnergyInCone().

103 {
104 
105  // Simplified version of getDistInPlane : no cone "within" Hcal, but
106  // don't assume track direction is origin -> point of hcal
107  // intersection.
108  const GlobalVector caloIntersectVector(caloPoint.x(),
109  caloPoint.y(),
110  caloPoint.z()); //p
111 
112  const GlobalVector caloUnitVector = caloVector.unit();
113  const GlobalVector rechitVector(rechitPoint.x(),
114  rechitPoint.y(),
115  rechitPoint.z());
116  const GlobalVector rechitUnitVector = rechitVector.unit();
117  double dotprod_denominator = caloUnitVector.dot(rechitUnitVector);
118  double dotprod_numerator = caloUnitVector.dot(caloIntersectVector);
119  double rechitdist = dotprod_numerator/dotprod_denominator;
120  const GlobalVector effectiveRechitVector = rechitdist*rechitUnitVector;
121  const GlobalPoint effectiveRechitPoint(effectiveRechitVector.x(),
122  effectiveRechitVector.y(),
123  effectiveRechitVector.z());
124  GlobalVector distance_vector = effectiveRechitPoint-caloPoint;
125  if (dotprod_denominator > 0. && dotprod_numerator > 0.)
126  {
127 
128  return distance_vector.mag();
129  }
130  else
131  {
132  return 999999.;
133  }
134 }
T y() const
Definition: PV3DBase.h:63
PreciseFloatType< T, U >::Type dot(const Vector3DBase< U, FrameTag > &v) const
Definition: Vector3DBase.h:107
T mag() const
Definition: PV3DBase.h:67
T z() const
Definition: PV3DBase.h:64
Vector3DBase unit() const
Definition: Vector3DBase.h:57
T x() const
Definition: PV3DBase.h:62