test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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)
 
 CaloDetIdAssociator (const edm::ParameterSet &pSet)
 
virtual const GeomDetgetGeomDet (const DetId &id) const override
 
virtual const char * name () const override
 
virtual void setGeometry (const CaloGeometry *ptr)
 
virtual void setGeometry (const DetIdAssociatorRecord &iRecord) 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...
 
virtual void setConditions (const DetIdAssociatorRecord &)
 
const FiducialVolumevolume () const
 get active detector volume More...
 
virtual ~DetIdAssociator ()
 

Protected Member Functions

virtual void check_setup () const override
 
virtual bool crossedElement (const GlobalPoint &, const GlobalPoint &, const DetId &id, const double tolerance=-1, const SteppingHelixStateInfo *=0) const override
 
virtual std::pair
< const_iterator,
const_iterator
getDetIdPoints (const DetId &id, std::vector< GlobalPoint > &points) const override
 
virtual GlobalPoint getPosition (const DetId &id) const override
 
virtual void getValidDetIds (unsigned int subDetectorIndex, std::vector< DetId > &) const override
 
virtual 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 32 of file CaloDetIdAssociator.h.

Constructor & Destructor Documentation

CaloDetIdAssociator::CaloDetIdAssociator ( )
inline

Definition at line 34 of file CaloDetIdAssociator.h.

34 :DetIdAssociator(72, 70 ,0.087),geometry_(0){};
const CaloGeometry * geometry_
DetIdAssociator(const int nPhi, const int nEta, const double etaBinSize)
CaloDetIdAssociator::CaloDetIdAssociator ( const int  nPhi,
const int  nEta,
const double  etaBinSize 
)
inline

Definition at line 35 of file CaloDetIdAssociator.h.

double etaBinSize() const
look-up map bin size in eta dimension
const CaloGeometry * geometry_
DetIdAssociator(const int nPhi, const int nEta, const double etaBinSize)
CaloDetIdAssociator::CaloDetIdAssociator ( const edm::ParameterSet pSet)
inline

Definition at line 38 of file CaloDetIdAssociator.h.

39  :DetIdAssociator(pSet.getParameter<int>("nPhi"),pSet.getParameter<int>("nEta"),pSet.getParameter<double>("etaBinSize")),geometry_(0){};
T getParameter(std::string const &) const
const CaloGeometry * geometry_
DetIdAssociator(const int nPhi, const int nEta, const double etaBinSize)

Member Function Documentation

void CaloDetIdAssociator::check_setup ( ) const
overrideprotectedvirtual

Reimplemented from DetIdAssociator.

Definition at line 194 of file CaloDetIdAssociator.cc.

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

195 {
197  if (geometry_==0) throw cms::Exception("CaloGeometry is not set");
198 }
virtual void check_setup() const
const CaloGeometry * geometry_
bool CaloDetIdAssociator::crossedElement ( const GlobalPoint point1,
const GlobalPoint point2,
const DetId id,
const double  tolerance = -1,
const SteppingHelixStateInfo initialState = 0 
) const
overrideprotectedvirtual

Reimplemented from DetIdAssociator.

Definition at line 3 of file CaloDetIdAssociator.cc.

References Plane::build(), Exception, getDetIdPoints(), SteppingHelixStateInfo::getStateOnSurface(), h, TrajectoryStateOnSurface::hasError(), i, TrajectoryStateOnSurface::isValid(), j, TrajectoryStateOnSurface::localError(), M_PI, mag(), bookConverter::max, AlCaHLTBitMon_ParallelJobs::p, p1, p2, phi, PV3DBase< T, PVType, FrameType >::phi(), LocalTrajectoryError::positionError(), funct::pow(), dttmaxenums::r32, LocalError::rotate(), idealTransformation::rotation, LocalError::scale(), mathSSE::sqrt(), std::swap(), csvLumiCalc::unit, PV3DBase< T, PVType, FrameType >::x(), LocalError::xx(), LocalError::xy(), create_public_lumi_plots::xy, PV3DBase< T, PVType, FrameType >::y(), HLT_25ns10e33_v2_cff::yMax, HLT_25ns10e33_v2_cff::yMin, LocalError::yy(), and PV3DBase< T, PVType, FrameType >::z().

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

Implements DetIdAssociator.

Definition at line 211 of file CaloDetIdAssociator.cc.

References dummy_, geometry_, CaloCellGeometry::getCorners(), CaloSubdetectorGeometry::getGeometry(), CaloGeometry::getSubdetectorGeometry(), LogDebug, and GeomDetEnumerators::subDetGeom.

Referenced by crossedElement().

212 {
214  if(! subDetGeom){
215  LogDebug("TrackAssociator") << "Cannot find sub-detector geometry for " << id.rawId() <<"\n";
216  return std::pair<const_iterator,const_iterator>(dummy_.end(),dummy_.end());
217  }
218  const CaloCellGeometry* cellGeom = subDetGeom->getGeometry(id);
219  if(! cellGeom) {
220  LogDebug("TrackAssociator") << "Cannot find CaloCell geometry for " << id.rawId() <<"\n";
221  return std::pair<const_iterator,const_iterator>(dummy_.end(),dummy_.end());
222  }
223  const CaloCellGeometry::CornersVec& cor (cellGeom->getCorners() ) ;
224  return std::pair<const_iterator,const_iterator>( cor.begin(), cor.end() ) ;
225 }
#define LogDebug(id)
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:43
virtual const CaloCellGeometry * getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
std::vector< GlobalPoint > dummy_
const CaloGeometry * geometry_
SubDetector subDetGeom[18]
const CornersVec & getCorners() const
Returns the corner points of this cell&#39;s volume.
virtual const GeomDet* CaloDetIdAssociator::getGeomDet ( const DetId id) const
inlineoverridevirtual

Implements DetIdAssociator.

Definition at line 45 of file CaloDetIdAssociator.h.

45 { return 0; };
GlobalPoint CaloDetIdAssociator::getPosition ( const DetId id) const
overrideprotectedvirtual

Implements DetIdAssociator.

Definition at line 200 of file CaloDetIdAssociator.cc.

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

200  {
202 }
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:43
virtual 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 GlobalPoint & getPosition() const
Returns the position of reference for this cell.
void CaloDetIdAssociator::getValidDetIds ( unsigned int  subDetectorIndex,
std::vector< DetId > &  detIds 
) const
overrideprotectedvirtual

Implements DetIdAssociator.

Reimplemented in EcalDetIdAssociator, HcalDetIdAssociator, HODetIdAssociator, and PreshowerDetIdAssociator.

Definition at line 204 of file CaloDetIdAssociator.cc.

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

205 {
206  if ( subDectorIndex!=0 ) cms::Exception("FatalError") << "Calo sub-dectors are all handle as one sub-system, but subDetectorIndex is not zero.\n";
207  detIds = geometry_->getValidDetIds(DetId::Calo, 1);
208 }
const CaloGeometry * geometry_
std::vector< DetId > getValidDetIds() const
Get the list of all valid detector ids.
Definition: CaloGeometry.cc:90
virtual bool CaloDetIdAssociator::insideElement ( const GlobalPoint point,
const DetId id 
) const
inlineoverrideprotectedvirtual

Implements DetIdAssociator.

Definition at line 58 of file CaloDetIdAssociator.h.

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

58  {
59  return geometry_->getSubdetectorGeometry(id)->getGeometry(id)->inside(point);
60  };
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:43
virtual 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_
bool inside(const GlobalPoint &point) const
Returns true if the specified point is inside this cell.
virtual const char* CaloDetIdAssociator::name ( void  ) const
inlineoverridevirtual
virtual void CaloDetIdAssociator::setGeometry ( const CaloGeometry ptr)
inlinevirtual

Definition at line 41 of file CaloDetIdAssociator.h.

References geometry_.

Referenced by setGeometry().

41 { geometry_ = ptr; };
const CaloGeometry * geometry_
void CaloDetIdAssociator::setGeometry ( const DetIdAssociatorRecord iRecord)
overridevirtual

Member Data Documentation

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

Definition at line 68 of file CaloDetIdAssociator.h.

Referenced by getDetIdPoints().

const CaloGeometry* CaloDetIdAssociator::geometry_
protected