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
 
virtual const char * name () const
 
virtual void setGeometry (const CaloGeometry *ptr)
 
virtual void setGeometry (const DetIdAssociatorRecord &iRecord)
 
- 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 void setConditions (const DetIdAssociatorRecord &)
 
virtual void setPropagator (Propagator *ptr)
 set a specific track propagator to be used More...
 
const FiducialVolumevolume () const
 get active detector volume More...
 
virtual ~DetIdAssociator ()
 

Protected Member Functions

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

Constructor & Destructor Documentation

CaloDetIdAssociator::CaloDetIdAssociator ( )
inline

Definition at line 35 of file CaloDetIdAssociator.h.

35 :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 36 of file CaloDetIdAssociator.h.

37  :DetIdAssociator(nPhi, nEta, etaBinSize),geometry_(0){};
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 39 of file CaloDetIdAssociator.h.

40  :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
protectedvirtual

Reimplemented from DetIdAssociator.

Definition at line 193 of file CaloDetIdAssociator.cc.

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

194 {
196  if (geometry_==0) throw cms::Exception("CaloGeometry is not set");
197 }
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
protectedvirtual

Reimplemented from DetIdAssociator.

Definition at line 3 of file CaloDetIdAssociator.cc.

References Plane::build(), edm::hlt::Exception, getDetIdPoints(), SteppingHelixStateInfo::getStateOnSurface(), h, TrajectoryStateOnSurface::hasError(), i, TrajectoryStateOnSurface::isValid(), j, TrajectoryStateOnSurface::localError(), M_PI, mag(), 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(), LocalError::yy(), and PV3DBase< T, PVType, FrameType >::z().

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

Implements DetIdAssociator.

Definition at line 210 of file CaloDetIdAssociator.cc.

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

Referenced by crossedElement().

211 {
213  if(! subDetGeom){
214  LogDebug("TrackAssociator") << "Cannot find sub-detector geometry for " << id.rawId() <<"\n";
215  return std::pair<const_iterator,const_iterator>(dummy_.end(),dummy_.end());
216  }
217  const CaloCellGeometry* cellGeom = subDetGeom->getGeometry(id);
218  if(! cellGeom) {
219  LogDebug("TrackAssociator") << "Cannot find CaloCell geometry for " << id.rawId() <<"\n";
220  return std::pair<const_iterator,const_iterator>(dummy_.end(),dummy_.end());
221  }
222  const CaloCellGeometry::CornersVec& cor (cellGeom->getCorners() ) ;
223  return std::pair<const_iterator,const_iterator>( cor.begin(), cor.end() ) ;
224 }
#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_
virtual const CornersVec & getCorners() const =0
Returns the corner points of this cell&#39;s volume.
virtual const GeomDet* CaloDetIdAssociator::getGeomDet ( const DetId id) const
inlinevirtual

Implements DetIdAssociator.

Definition at line 46 of file CaloDetIdAssociator.h.

46 { return 0; };
GlobalPoint CaloDetIdAssociator::getPosition ( const DetId id) const
protectedvirtual

Implements DetIdAssociator.

Definition at line 199 of file CaloDetIdAssociator.cc.

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

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

Implements DetIdAssociator.

Reimplemented in EcalDetIdAssociator, HcalDetIdAssociator, HODetIdAssociator, and PreshowerDetIdAssociator.

Definition at line 203 of file CaloDetIdAssociator.cc.

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

204 {
205  if ( subDectorIndex!=0 ) cms::Exception("FatalError") << "Calo sub-dectors are all handle as one sub-system, but subDetectorIndex is not zero.\n";
207 }
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
inlineprotectedvirtual

Implements DetIdAssociator.

Definition at line 59 of file CaloDetIdAssociator.h.

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

59  {
60  return geometry_->getSubdetectorGeometry(id)->getGeometry(id)->inside(point);
61  };
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
inlinevirtual

Implements DetIdAssociator.

Reimplemented in EcalDetIdAssociator, HcalDetIdAssociator, HODetIdAssociator, and PreshowerDetIdAssociator.

Definition at line 48 of file CaloDetIdAssociator.h.

48 { return "CaloTowers"; }
virtual void CaloDetIdAssociator::setGeometry ( const CaloGeometry ptr)
inlinevirtual

Definition at line 42 of file CaloDetIdAssociator.h.

References geometry_.

Referenced by setGeometry().

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

Member Data Documentation

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

Definition at line 69 of file CaloDetIdAssociator.h.

Referenced by getDetIdPoints().

const CaloGeometry* CaloDetIdAssociator::geometry_
protected