CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 221 of file CommonUsefulStuff.h.

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

Referenced by HcalCorrPFCalculation::analyze(), and HcalIsoTrkAnalyzer::analyze().

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

Definition at line 261 of file CommonUsefulStuff.h.

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

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

Definition at line 139 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().

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

61 {
62 
63  // Simplified version of getDistInPlane
64  // Assume track direction is origin -> point of hcal intersection
65 
66  const GlobalVector caloIntersectVector(caloPoint.x(),
67  caloPoint.y(),
68  caloPoint.z());
69 
70  const GlobalVector caloIntersectUnitVector = caloIntersectVector.unit();
71 
72  const GlobalVector rechitVector(rechitPoint.x(),
73  rechitPoint.y(),
74  rechitPoint.z());
75 
76  const GlobalVector rechitUnitVector = rechitVector.unit();
77  double dotprod = caloIntersectUnitVector.dot(rechitUnitVector);
78  double rechitdist = caloIntersectVector.mag()/dotprod;
79 
80 
81  const GlobalVector effectiveRechitVector = rechitdist*rechitUnitVector;
82  const GlobalPoint effectiveRechitPoint(effectiveRechitVector.x(),
83  effectiveRechitVector.y(),
84  effectiveRechitVector.z());
85 
86 
87  GlobalVector distance_vector = effectiveRechitPoint-caloPoint;
88 
89  if (dotprod > 0.)
90  {
91  return distance_vector.mag();
92  }
93  else
94  {
95  return 999999.;
96 
97  }
98 
99 }
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 101 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().

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