CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Member Functions | Protected Attributes
CaloDetIdAssociator Class Reference

#include <CaloDetIdAssociator.h>

Inheritance diagram for CaloDetIdAssociator:
DetIdAssociator EcalDetIdAssociator HcalDetIdAssociator HODetIdAssociator PreshowerDetIdAssociator

Public Member Functions

 CaloDetIdAssociator ()
 
 CaloDetIdAssociator (const int nPhi, const int nEta, const double etaBinSize, CaloGeometry const *geom)
 
const GeomDetgetGeomDet (const DetId &id) const override
 
const char * name () const override
 
- Public Member Functions inherited from DetIdAssociator
virtual void buildMap ()
 make the look-up map More...
 
 DetIdAssociator (const int nPhi, const int nEta, const double etaBinSize)
 
double etaBinSize () const
 look-up map bin size in eta dimension More...
 
virtual std::vector< DetIdgetCrossedDetIds (const std::set< DetId > &, const std::vector< GlobalPoint > &trajectory) const
 
virtual std::vector< DetIdgetCrossedDetIds (const std::set< DetId > &, const std::vector< SteppingHelixStateInfo > &trajectory, const double toleranceInSigmas=-1) const
 
virtual std::set< DetIdgetDetIdsCloseToAPoint (const GlobalPoint &, const int iN=0) const
 
virtual std::set< DetIdgetDetIdsCloseToAPoint (const GlobalPoint &direction, const unsigned int iNEtaPlus, const unsigned int iNEtaMinus, const unsigned int iNPhiPlus, const unsigned int iNPhiMinus) const
 
virtual std::set< DetIdgetDetIdsCloseToAPoint (const GlobalPoint &direction, const MapRange &mapRange) const
 
virtual std::set< DetIdgetDetIdsCloseToAPoint (const GlobalPoint &point, const double d=0) const
 
virtual std::set< DetIdgetDetIdsCloseToAPoint (const GlobalPoint &point, const double dThetaPlus, const double dThetaMinus, const double dPhiPlus, const double dPhiMinus) const
 
virtual std::set< DetIdgetDetIdsInACone (const std::set< DetId > &, const std::vector< GlobalPoint > &trajectory, const double dR) const
 
virtual int iEta (const GlobalPoint &) const
 look-up map eta index More...
 
virtual int iPhi (const GlobalPoint &) const
 look-up map phi index More...
 
int nEtaBins () const
 number of bins of the look-up map in eta dimension More...
 
int nPhiBins () const
 number of bins of the look-up map in phi dimension More...
 
virtual bool selectAllInACone (const double dR) const
 helper to see if getDetIdsInACone is useful More...
 
const FiducialVolumevolume () const
 get active detector volume More...
 
virtual ~DetIdAssociator ()
 

Protected Member Functions

void check_setup () const override
 
bool crossedElement (const GlobalPoint &, const GlobalPoint &, const DetId &id, const double tolerance=-1, const SteppingHelixStateInfo *=nullptr) const override
 
std::pair< const_iterator, const_iteratorgetDetIdPoints (const DetId &id, std::vector< GlobalPoint > &points) const override
 
GlobalPoint getPosition (const DetId &id) const override
 
void getValidDetIds (unsigned int subDetectorIndex, std::vector< DetId > &) const override
 
bool insideElement (const GlobalPoint &point, const DetId &id) const override
 
- Protected Member Functions inherited from DetIdAssociator
virtual void dumpMapContent (int, int) const
 
virtual void dumpMapContent (int, int, int, int) const
 
void fillSet (std::set< DetId > &set, unsigned int iEta, unsigned int iPhi) const
 
virtual const unsigned int getNumberOfSubdetectors () const
 
unsigned int index (unsigned int iEta, unsigned int iPhi) const
 
virtual bool nearElement (const GlobalPoint &point, const DetId &id, const double distance) const
 

Protected Attributes

std::vector< GlobalPointdummy_
 
const CaloGeometrygeometry_
 
- Protected Attributes inherited from DetIdAssociator
std::vector< DetIdcontainer_
 
const double etaBinSize_
 
std::vector< std::pair< unsigned int, unsigned int > > lookupMap_
 
double maxEta_
 
double minTheta_
 
const int nEta_
 
const int nPhi_
 
bool theMapIsValid_
 
FiducialVolume volume_
 

Additional Inherited Members

- Public Types inherited from DetIdAssociator
typedef std::vector< GlobalPoint >::const_iterator const_iterator
 
enum  PropagationTarget { Barrel, ForwardEndcap, BackwardEndcap }
 

Detailed Description

Definition at line 27 of file CaloDetIdAssociator.h.

Constructor & Destructor Documentation

◆ CaloDetIdAssociator() [1/2]

CaloDetIdAssociator::CaloDetIdAssociator ( )
inline

Definition at line 29 of file CaloDetIdAssociator.h.

29 : DetIdAssociator(72, 70, 0.087), geometry_(nullptr){};
const CaloGeometry * geometry_
DetIdAssociator(const int nPhi, const int nEta, const double etaBinSize)

◆ CaloDetIdAssociator() [2/2]

CaloDetIdAssociator::CaloDetIdAssociator ( const int  nPhi,
const int  nEta,
const double  etaBinSize,
CaloGeometry const *  geom 
)
inline

Definition at line 30 of file CaloDetIdAssociator.h.

const CaloGeometry * geometry_
DetIdAssociator(const int nPhi, const int nEta, const double etaBinSize)
double etaBinSize() const
look-up map bin size in eta dimension

Member Function Documentation

◆ check_setup()

void CaloDetIdAssociator::check_setup ( ) const
overrideprotectedvirtual

Reimplemented from DetIdAssociator.

Definition at line 197 of file CaloDetIdAssociator.cc.

References DetIdAssociator::check_setup(), Exception, and geometry_.

197  {
199  if (geometry_ == nullptr)
200  throw cms::Exception("CaloGeometry is not set");
201 }
const CaloGeometry * geometry_
virtual void check_setup() const

◆ crossedElement()

bool CaloDetIdAssociator::crossedElement ( const GlobalPoint point1,
const GlobalPoint point2,
const DetId id,
const double  tolerance = -1,
const SteppingHelixStateInfo initialState = nullptr 
) const
overrideprotectedvirtual

Reimplemented from DetIdAssociator.

Definition at line 3 of file CaloDetIdAssociator.cc.

References custom_jme_cff::area, Plane::build(), makePileupJSON::denom, Exception, getDetIdPoints(), SteppingHelixStateInfo::getStateOnSurface(), h, TrajectoryStateOnSurface::hasError(), mps_fire::i, TrajectoryStateOnSurface::isValid(), dqmiolumiharvest::j, TrajectoryStateOnSurface::localError(), M_PI, mag(), SiStripPI::max, HLT_2023v12_cff::maxPhi, HLT_2023v12_cff::minPhi, AlCaHLTBitMon_ParallelJobs::p, LaserDQM_cfg::p1, SiStripOfflineCRack_cfg::p2, phi, PV3DBase< T, PVType, FrameType >::phi(), hiPixelPairStep_cff::points, LocalTrajectoryError::positionError(), conifer::pow(), dttmaxenums::r32, LocalError::rotate(), idealTransformation::rotation, LocalError::scale(), mathSSE::sqrt(), edm::swap(), unit(), trackerHitRTTI::vector, PV3DBase< T, PVType, FrameType >::x(), multiplicitycorr_cfi::xMax, photonAnalyzer_cfi::xMin, geometryCSVtoXML::xx, LocalError::xx(), geometryCSVtoXML::xy, LocalError::xy(), PV3DBase< T, PVType, FrameType >::y(), multiplicitycorr_cfi::yMax, photonAnalyzer_cfi::yMin, geometryCSVtoXML::yy, LocalError::yy(), PV3DBase< T, PVType, FrameType >::z(), photonAnalyzer_cfi::zMax, and photonAnalyzer_cfi::zMin.

7  {
8  std::vector<GlobalPoint> pointBuffer;
9  const std::pair<const_iterator, const_iterator>& points = getDetIdPoints(id, pointBuffer);
10  // fast check
11  bool xLess(false), xIn(false), xMore(false);
12  bool yLess(false), yIn(false), yMore(false);
13  bool zLess(false), zIn(false), zMore(false);
14  double xMin(point1.x()), xMax(point2.x());
15  double yMin(point1.y()), yMax(point2.y());
16  double zMin(point1.z()), zMax(point2.z());
17  if (xMin > xMax)
19  if (yMin > yMax)
21  if (zMin > zMax)
23  for (std::vector<GlobalPoint>::const_iterator it = points.first; it != points.second; ++it) {
24  if (it->x() < xMin) {
25  xLess = true;
26  } else {
27  if (it->x() > xMax)
28  xMore = true;
29  else
30  xIn = true;
31  }
32  if (it->y() < yMin) {
33  yLess = true;
34  } else {
35  if (it->y() > yMax)
36  yMore = true;
37  else
38  yIn = true;
39  }
40  if (it->z() < zMin) {
41  zLess = true;
42  } else {
43  if (it->z() > zMax)
44  zMore = true;
45  else
46  zIn = true;
47  }
48  }
49  if (((xLess && !xIn && !xMore) || (!xLess && !xIn && xMore)) ||
50  ((yLess && !yIn && !yMore) || (!yLess && !yIn && yMore)) ||
51  ((zLess && !zIn && !zMore) || (!zLess && !zIn && zMore)))
52  return false;
53 
54  // Define plane normal to the trajectory direction at the first point
55  GlobalVector vector = (point2 - point1).unit();
56  float r21 = 0;
57  float r22 = vector.z() / sqrt(1 - pow(vector.x(), 2));
58  float r23 = -vector.y() / sqrt(1 - pow(vector.x(), 2));
59  float r31 = vector.x();
60  float r32 = vector.y();
61  float r33 = vector.z();
62  float r11 = r22 * r33 - r23 * r32;
63  float r12 = r23 * r31;
64  float r13 = -r22 * r31;
65 
66  Surface::RotationType rotation(r11, r12, r13, r21, r22, r23, r31, r32, r33);
67  Plane::PlanePointer plane = Plane::build(point1, rotation);
68  double absoluteTolerance = -1;
69  if (toleranceInSigmas > 0 && initialState) {
70  TrajectoryStateOnSurface tsos = initialState->getStateOnSurface(*plane);
71  if (tsos.isValid() and tsos.hasError()) {
72  LocalError localErr = tsos.localError().positionError();
73  localErr.scale(toleranceInSigmas);
74  float xx = localErr.xx();
75  float xy = localErr.xy();
76  float yy = localErr.yy();
77 
78  float denom = yy - xx;
79  float phi = 0.;
80  if (xy == 0 && denom == 0)
81  phi = M_PI_4;
82  else
83  phi = 0.5 * atan2(2. * xy, denom); // angle of MAJOR axis
84  // Unrotate the error ellipse to get the semimajor and minor axes. Then place points on
85  // the endpoints of semiminor an seminajor axes on original(rotated) error ellipse.
86  LocalError rotErr = localErr.rotate(-phi); // xy covariance of rotErr should be zero
87  float semi1 = sqrt(rotErr.xx());
88  float semi2 = sqrt(rotErr.yy());
89  absoluteTolerance = std::max(semi1, semi2);
90  }
91  }
92 
93  // distance between the points.
94  double trajectorySegmentLength = (point2 - point1).mag();
95 
96  // we need to find the angle that covers all points.
97  // if it's bigger than 180 degree, we are inside
98  // otherwise we are outside, i.e. the volume is not crossed
99  bool allBehind = true;
100  bool allTooFar = true;
101  std::vector<GlobalPoint>::const_iterator p = points.first;
102  if (p == points.second) {
103  edm::LogWarning("TrackAssociator") << "calo geometry for element " << id.rawId() << "is empty. Ignored";
104  return false;
105  }
106  LocalPoint localPoint = plane->toLocal(*p);
107  double minPhi = localPoint.phi();
108  double maxPhi = localPoint.phi();
109  if (localPoint.z() < 0)
110  allTooFar = false;
111  else {
112  allBehind = false;
113  if (localPoint.z() < trajectorySegmentLength)
114  allTooFar = false;
115  }
116  ++p;
117  for (; p != points.second; ++p) {
118  localPoint = plane->toLocal(*p);
119  double localPhi = localPoint.phi();
120  if (localPoint.z() < 0)
121  allTooFar = false;
122  else {
123  allBehind = false;
124  if (localPoint.z() < trajectorySegmentLength)
125  allTooFar = false;
126  }
127  if (localPhi >= minPhi && localPhi <= maxPhi)
128  continue;
129  if (localPhi + 2 * M_PI >= minPhi && localPhi + 2 * M_PI <= maxPhi)
130  continue;
131  if (localPhi - 2 * M_PI >= minPhi && localPhi - 2 * M_PI <= maxPhi)
132  continue;
133  // find the closest limit
134  if (localPhi > maxPhi) {
135  double delta1 = fabs(localPhi - maxPhi);
136  double delta2 = fabs(localPhi - 2 * M_PI - minPhi);
137  if (delta1 < delta2)
138  maxPhi = localPhi;
139  else
140  minPhi = localPhi - 2 * M_PI;
141  continue;
142  }
143  if (localPhi < minPhi) {
144  double delta1 = fabs(localPhi - minPhi);
145  double delta2 = fabs(localPhi + 2 * M_PI - maxPhi);
146  if (delta1 < delta2)
147  minPhi = localPhi;
148  else
149  maxPhi = localPhi + 2 * M_PI;
150  continue;
151  }
152  cms::Exception("FatalError")
153  << "Algorithm logic error - this should never happen. Problems with trajectory-volume matching.";
154  }
155  if (allBehind)
156  return false;
157  if (allTooFar)
158  return false;
159  if (fabs(maxPhi - minPhi) > M_PI)
160  return true;
161 
162  // now if the tolerance is positive, check how far we are
163  // from the closest line segment
164  if (absoluteTolerance < 0)
165  return false;
166  double distanceToClosestLineSegment = 1e9;
167  std::vector<GlobalPoint>::const_iterator i, j;
168  for (i = points.first; i != points.second; ++i)
169  for (j = i + 1; j != points.second; ++j) {
170  LocalPoint p1(plane->toLocal(*i));
171  LocalPoint p2(plane->toLocal(*j));
172  // now we deal with high school level math to get
173  // the triangle paramaters
174  double side1squared = p1.perp2();
175  double side2squared = p2.perp2();
176  double side3squared = (p2.x() - p1.x()) * (p2.x() - p1.x()) + (p2.y() - p1.y()) * (p2.y() - p1.y());
177  double area = fabs(p1.x() * p2.y() - p2.x() * p1.y()) / 2;
178  // all triangle angles must be smaller than 90 degree
179  // otherwise the projection is out of the line segment
180  if (side1squared + side2squared > side3squared && side2squared + side3squared > side1squared &&
181  side1squared + side3squared > side1squared) {
182  double h(2 * area / sqrt(side3squared));
183  if (h < distanceToClosestLineSegment)
184  distanceToClosestLineSegment = h;
185  } else {
186  if (sqrt(side1squared) < distanceToClosestLineSegment)
187  distanceToClosestLineSegment = sqrt(side1squared);
188  if (sqrt(side2squared) < distanceToClosestLineSegment)
189  distanceToClosestLineSegment = sqrt(side2squared);
190  }
191  }
192  if (distanceToClosestLineSegment < absoluteTolerance)
193  return true;
194  return false;
195 }
LocalError scale(float s) const
Definition: LocalError.h:31
TrajectoryStateOnSurface getStateOnSurface(const Surface &surf, bool returnTangentPlane=false) const
const LocalTrajectoryError & localError() const
LocalError rotate(float x, float y) const
Return a new LocalError, rotated by an angle defined by the direction (x,y)
Definition: LocalError.h:37
T z() const
Definition: PV3DBase.h:61
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
constexpr int pow(int x)
Definition: conifer.h:24
LocalError positionError() const
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:112
static PlanePointer build(Args &&... args)
Definition: Plane.h:33
float yy() const
Definition: LocalError.h:24
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
T sqrt(T t)
Definition: SSEVec.h:19
Basic3DVector unit() const
#define M_PI
float xy() const
Definition: LocalError.h:23
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
std::pair< const_iterator, const_iterator > getDetIdPoints(const DetId &id, std::vector< GlobalPoint > &points) const override
Log< level::Warning, false > LogWarning
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
float xx() const
Definition: LocalError.h:22

◆ getDetIdPoints()

std::pair< DetIdAssociator::const_iterator, DetIdAssociator::const_iterator > CaloDetIdAssociator::getDetIdPoints ( const DetId id,
std::vector< GlobalPoint > &  points 
) const
overrideprotectedvirtual

Implements DetIdAssociator.

Definition at line 214 of file CaloDetIdAssociator.cc.

References dummy_, geometry_, CaloGeometry::getSubdetectorGeometry(), LogDebug, and GeomDetEnumerators::subDetGeom.

Referenced by crossedElement().

215  {
217  if (!subDetGeom) {
218  LogDebug("TrackAssociator") << "Cannot find sub-detector geometry for " << id.rawId() << "\n";
219  return std::pair<const_iterator, const_iterator>(dummy_.end(), dummy_.end());
220  }
221  auto cellGeom = subDetGeom->getGeometry(id);
222  if (!cellGeom) {
223  LogDebug("TrackAssociator") << "Cannot find CaloCell geometry for " << id.rawId() << "\n";
224  return std::pair<const_iterator, const_iterator>(dummy_.end(), dummy_.end());
225  }
226  const CaloCellGeometry::CornersVec& cor(cellGeom->getCorners());
227  return std::pair<const_iterator, const_iterator>(cor.begin(), cor.end());
228 }
constexpr SubDetector subDetGeom[21]
std::vector< GlobalPoint > dummy_
const CaloGeometry * geometry_
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34
#define LogDebug(id)

◆ getGeomDet()

const GeomDet* CaloDetIdAssociator::getGeomDet ( const DetId id) const
inlineoverridevirtual

Implements DetIdAssociator.

Definition at line 33 of file CaloDetIdAssociator.h.

33 { return nullptr; };

◆ getPosition()

GlobalPoint CaloDetIdAssociator::getPosition ( const DetId id) const
overrideprotectedvirtual

Implements DetIdAssociator.

Definition at line 203 of file CaloDetIdAssociator.cc.

References geometry_, CaloSubdetectorGeometry::getGeometry(), and CaloGeometry::getSubdetectorGeometry().

203  {
204  return geometry_->getSubdetectorGeometry(id)->getGeometry(id)->getPosition();
205 }
virtual std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
const CaloGeometry * geometry_
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34

◆ getValidDetIds()

void CaloDetIdAssociator::getValidDetIds ( unsigned int  subDetectorIndex,
std::vector< DetId > &  detIds 
) const
overrideprotectedvirtual

Implements DetIdAssociator.

Reimplemented in HcalDetIdAssociator, EcalDetIdAssociator, HODetIdAssociator, and PreshowerDetIdAssociator.

Definition at line 207 of file CaloDetIdAssociator.cc.

References DetId::Calo, Exception, geometry_, and CaloGeometry::getValidDetIds().

207  {
208  if (subDectorIndex != 0)
209  cms::Exception("FatalError")
210  << "Calo sub-dectors are all handle as one sub-system, but subDetectorIndex is not zero.\n";
211  detIds = geometry_->getValidDetIds(DetId::Calo, 1);
212 }
const CaloGeometry * geometry_
std::vector< DetId > getValidDetIds() const
Get the list of all valid detector ids.
Definition: CaloGeometry.cc:75

◆ insideElement()

bool CaloDetIdAssociator::insideElement ( const GlobalPoint point,
const DetId id 
) const
inlineoverrideprotectedvirtual

Implements DetIdAssociator.

Definition at line 47 of file CaloDetIdAssociator.h.

References geometry_, CaloSubdetectorGeometry::getGeometry(), CaloGeometry::getSubdetectorGeometry(), and point.

47  {
48  return geometry_->getSubdetectorGeometry(id)->getGeometry(id)->inside(point);
49  };
virtual std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
const CaloGeometry * geometry_
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5

◆ name()

const char* CaloDetIdAssociator::name ( void  ) const
inlineoverridevirtual

Implements DetIdAssociator.

Reimplemented in HcalDetIdAssociator, EcalDetIdAssociator, HODetIdAssociator, and PreshowerDetIdAssociator.

Definition at line 35 of file CaloDetIdAssociator.h.

Referenced by config.CFG::__str__(), and validation.Sample::digest().

35 { return "CaloTowers"; }

Member Data Documentation

◆ dummy_

std::vector<GlobalPoint> CaloDetIdAssociator::dummy_
protected

Definition at line 57 of file CaloDetIdAssociator.h.

Referenced by getDetIdPoints().

◆ geometry_

const CaloGeometry* CaloDetIdAssociator::geometry_
protected