CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalShowerProperties.cc
Go to the documentation of this file.
2 
6 
12 
15 
20 
23 
24 using namespace std;
25 
26 const double R_M = 2.2;
27 //const double R_M = 4.;
28 
29 /*****************************************************************************/
31  (const edm::Event & ev, const edm::EventSetup & es)
32 {
33  // Get magnetic field
34  edm::ESHandle<MagneticField> theMagneticFieldHandle;
35  es.get<IdealMagneticFieldRecord>().get(theMagneticFieldHandle);
36  theMagneticField = theMagneticFieldHandle.product();
37 
38  // Get propagator
39  edm::ESHandle<Propagator> thePropagatorHandle;
40  es.get<TrackingComponentsRecord>().get("PropagatorWithMaterial",
41  thePropagatorHandle);
42  thePropagator = thePropagatorHandle.product();
43 
44  // Get calorimetry
45  edm::ESHandle<CaloGeometry> theCaloGeometryHandle;
46  es.get<IdealGeometryRecord>().get(theCaloGeometryHandle);
47  theCaloGeometry = (const CaloGeometry*)theCaloGeometryHandle.product();
48 
49  // Get ecal rechits
50  ev.getByLabel("ecalRecHit", "EcalRecHitsEB", recHitsBarrel);
51  ev.getByLabel("ecalRecHit", "EcalRecHitsEE", recHitsEndcap);
52 }
53 
54 /*****************************************************************************/
56  (const reco::Track & track)
57 {
58  GlobalPoint pos(track.outerX() , track.outerY() , track.outerZ() );
59  GlobalVector mom(track.outerPx(), track.outerPy(), track.outerPz());
60 
61  GlobalTrajectoryParameters gtp(pos,mom, track.charge(), theMagneticField);
62 
63  return FreeTrajectoryState(gtp, track.outerStateCovariance());
64 }
65 
66 /*****************************************************************************/
68  (const CaloCellGeometry* cell, int i)
69 {
70  int j = i * 4;
71 
72  // Get corners
73  const CaloCellGeometry::CornersVec & c(cell->getCorners());
74 
75  // Get center
76  GlobalPoint center( (c[j].x() + c[j+1].x() + c[j+2].x() + c[j+3].x()) / 4,
77  (c[j].y() + c[j+1].y() + c[j+2].y() + c[j+3].y()) / 4,
78  (c[j].z() + c[j+1].z() + c[j+2].z() + c[j+3].z()) / 4);
79 
80  // Get plane
81  Surface::PositionType pos(center);
82  Surface::RotationType rot(c[j+1]-c[j], c[j+3]-c[j]);
83  return Plane::build(pos, rot);
84 }
85 
86 /*****************************************************************************/
87 vector<TrajectoryStateOnSurface> EcalShowerProperties::getEndpoints
88  (const FreeTrajectoryState & ftsAtLastPoint,
89  const TrajectoryStateOnSurface & tsosBeforeEcal, int subDet)
90 {
91  std::vector<TrajectoryStateOnSurface> tsosEnds;
92 
94  theCaloGeometry->getSubdetectorGeometry(DetId::Ecal,subDet);
95 
96  // Get closest cell
97  DetId detId(geom->getClosestCell(ftsAtLastPoint.position()));
98 
99  if(!geom->present(detId)) return tsosEnds;
100 
101  const CaloCellGeometry* cell = geom->getGeometry(detId);
102  const CaloCellGeometry* oldcell;
104 
105  // Front and back
106  for(int i = 0; i < 2; i++)
107  {
108  int step = 0;
109 
110  do
111  {
112  oldcell = cell;
113 
114  Plane::PlanePointer thePlane = getSurface(oldcell, i);
115  tsos = thePropagator->propagate(ftsAtLastPoint,*thePlane);
116 
117  if(!tsos.isValid()) return tsosEnds;
118 
119  detId = geom->getClosestCell(tsos.globalPosition());
120 
121  if(!geom->present(detId)) return tsosEnds;
122  cell = geom->getGeometry(detId);
123  }
124  while(cell != oldcell && step++ < 5);
125 
126  if(step++ < 5)
127  tsosEnds.push_back(tsos);
128  }
129 
130  return tsosEnds;
131 }
132 
133 /*****************************************************************************/
135  (const std::vector<TrajectoryStateOnSurface> & tsosEnds,
136  const CaloCellGeometry* cell)
137 {
138  double dmin = 1e+9;
139  LocalPoint p;
140 
141  // Project to entry surface, 'p1p2' segment
142  p = tsosEnds[0].surface().toLocal(tsosEnds[0].globalPosition());
143  LocalPoint p1(p.x(), p.y(), 0);
144 
145  p = tsosEnds[0].surface().toLocal(tsosEnds[1].globalPosition());
146  LocalPoint p2(p.x(), p.y(), 0);
147 
148  const CaloCellGeometry::CornersVec & c(cell->getCorners());
149 
150  // Project to entry surface, 'c' corners
151  for(int i = 0; i < 4; i++)
152  {
153  p = tsosEnds[0].surface().toLocal(GlobalPoint(c[i].x(),c[i].y(),c[i].z()));
154  LocalPoint c(p.x(), p.y(), 0);
155 
156  // Calculate distance of 'c' from endpoints 'p1' and 'p2'
157  double d1 = (p1 - c).mag2(); // distance from end
158  double d2 = (p2 - c).mag2(); // distance from end
159  double dm = min(d1,d2);
160 
161  // distance from segment
162  double lambda = (c - p1) * (p2 - p1) / (p2 - p1).mag2();
163  if(lambda > 0 && lambda < 1)
164  {
165  double dp = (c - p1 - lambda * (p2 - p1)).mag2();
166  dm = min (dm,dp);
167  }
168 
169  dmin = min(dm, dmin);
170  }
171 
172  return(sqrt(dmin));
173 }
174 
175 /*****************************************************************************/
177  (const std::vector<TrajectoryStateOnSurface> & tsosEnds, int subDet, int & ntime)
178 {
180  theCaloGeometry->getSubdetectorGeometry(DetId::Ecal,subDet);
181 
182  std::vector<DetId> detIds;
183  detIds.push_back(geom->getClosestCell(tsosEnds[0].globalPosition()));
184  detIds.push_back(geom->getClosestCell(tsosEnds[1].globalPosition()));
185 
186  double energy = 0, time = 0;
187  ntime = 0;
188 
189  if(subDet == EcalBarrel)
190  {
191  EBDetId frontId(detIds[0]);
192  EBDetId backId(detIds[1]);
193 
194  double ieta = (frontId.ieta() + backId.ieta())/2.;
195  double weta = fabs(frontId.ieta() - backId.ieta())/2.;
196 
197  double iphi = (frontId.iphi() + backId.iphi())/2.;
198  double wphi = fabs(frontId.iphi() - backId.iphi())/2.;
199 
200  for(EBRecHitCollection::const_iterator recHit = recHitsBarrel->begin();
201  recHit!= recHitsBarrel->end();
202  recHit++)
203  {
204  EBDetId detId(recHit->id());
205  const CaloCellGeometry* cell = geom->getGeometry(detId);
206 
207  if(fabs(detId.ieta() - ieta) < weta + 4 &&
208  fabs(detId.iphi() - iphi) < wphi + 4)
209  if(getDistance(tsosEnds, cell) < R_M)
210  {
211  energy += recHit->energy();
212  time += recHit->energy() * recHit->time();
213  ntime++;
214  }
215  }
216  }
217  else
218  {
219  EEDetId frontId(detIds[0]);
220  EEDetId backId(detIds[1]);
221 
222  double ix = (frontId.ix() + backId.ix())/2.;
223  double wx = fabs(frontId.ix() - backId.ix())/2.;
224 
225  double iy = (frontId.iy() + backId.iy())/2.;
226  double wy = fabs(frontId.iy() - backId.iy())/2.;
227 
228  for(EERecHitCollection::const_iterator recHit = recHitsEndcap->begin();
229  recHit!= recHitsEndcap->end();
230  recHit++)
231  {
232  EEDetId detId(recHit->id());
233  const CaloCellGeometry* cell = geom->getGeometry(detId);
234 
235  if(detId.zside() == frontId.zside() &&
236  detId.zside() == backId.zside())
237  if( fabs(detId.ix() - ix) < wx + 4 &&
238  fabs(detId.iy() - iy) < wy + 4)
239  if(getDistance(tsosEnds, cell) < R_M)
240  {
241  energy += recHit->energy();
242  time += recHit->energy() * recHit->time();
243  ntime++;
244  }
245  }
246  }
247 
248  if(energy > 0) time /= energy;
249 
250  return std::pair<double,double> (energy,time);
251 }
252 
253 /*****************************************************************************/
254 pair<double,double> EcalShowerProperties::processTrack
255  (const reco::Track & track, int & ntime)
256 {
257  // Get trajectory at outer point
258  FreeTrajectoryState ftsAtLastPoint = getTrajectoryAtOuterPoint(track);
259 
260  // Ecal cylinder
261  double radius = 129.0; // cm
262  double z = 320.9; // cm
264 
265  // Subdetector
266  std::vector<int> subDets;
267  subDets.push_back(EcalBarrel);
268  subDets.push_back(EcalEndcap);
269 
270  std::pair<double,double> result(0,0);
271 
272  // Take barrel and endcap
273  for(std::vector<int>::const_iterator subDet = subDets.begin();
274  subDet!= subDets.end(); subDet++)
275  {
276  TrajectoryStateOnSurface tsosBeforeEcal;
277 
278  if(*subDet == EcalBarrel)
279  {
280  Surface::PositionType pos(0,0,0);
281  Cylinder::CylinderPointer theBarrel = Cylinder::build(pos, rot, radius);
282  tsosBeforeEcal = thePropagator->propagate(ftsAtLastPoint, *theBarrel);
283 
284  if(!tsosBeforeEcal.isValid()) continue;
285  if(fabs(tsosBeforeEcal.globalPosition().z()) > z) continue;
286  }
287  else
288  {
289  Surface::PositionType pos(0,0,z);
290  Plane::PlanePointer theEndcap = Plane::build(pos, rot);
291  tsosBeforeEcal = thePropagator->propagate(ftsAtLastPoint, *theEndcap);
292 
293  if(!tsosBeforeEcal.isValid()) continue;
294  if(fabs(tsosBeforeEcal.globalPosition().perp()) > radius) continue;
295  }
296 
297  std::vector<TrajectoryStateOnSurface> tsosEnds =
298  getEndpoints(ftsAtLastPoint, tsosBeforeEcal, *subDet);
299 
300  if(tsosEnds.size() == 2)
301  result = processEcalRecHits(tsosEnds, *subDet, ntime);
302  }
303 
304  return result;
305 }
int i
Definition: DBlmapReader.cc:9
int ix() const
Definition: EEDetId.h:71
T perp() const
Definition: PV3DBase.h:71
double outerPy() const
y coordinate of momentum vector at the outermost hit position
Definition: Track.h:73
list step
Definition: launcher.py:15
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
std::vector< EcalRecHit >::const_iterator const_iterator
FreeTrajectoryState getTrajectoryAtOuterPoint(const reco::Track &track)
T y() const
Definition: PV3DBase.h:62
GlobalPoint globalPosition() const
static PlanePointer build(const PositionType &pos, const RotationType &rot, MediumProperties *mp=0)
Definition: Plane.h:25
Plane::PlanePointer getSurface(const CaloCellGeometry *cell, int i)
#define min(a, b)
Definition: mlp_lapack.h:161
const double R_M
double double double z
virtual const CaloCellGeometry * getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
double outerZ() const
z coordinate of the outermost hit position
Definition: Track.h:81
int iphi() const
get the crystal iphi
Definition: EBDetId.h:46
virtual bool present(const DetId &id) const
is this detid present in the geometry?
double getDistance(const std::vector< TrajectoryStateOnSurface > &tsosEnds, const CaloCellGeometry *cell)
std::pair< double, double > processEcalRecHits(const std::vector< TrajectoryStateOnSurface > &tsosEnds, int subDet, int &ntime)
T sqrt(T t)
Definition: SSEVec.h:46
CovarianceMatrix outerStateCovariance() const
outermost trajectory state curvilinear errors
Definition: Track.h:51
T z() const
Definition: PV3DBase.h:63
tuple result
Definition: query.py:137
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
#define dmin(a, b)
Definition: mlp_lapack.h:163
int zside() const
Definition: EEDetId.h:65
int j
Definition: DBlmapReader.cc:9
int iy() const
Definition: EEDetId.h:77
double outerX() const
x coordinate of the outermost hit position
Definition: Track.h:77
int ieta() const
get the crystal ieta
Definition: EBDetId.h:44
double p2[4]
Definition: TauolaWrapper.h:90
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
double outerPz() const
z coordinate of momentum vector at the outermost hit position
Definition: Track.h:75
virtual DetId getClosestCell(const GlobalPoint &r) const
Definition: DetId.h:20
GlobalPoint position() const
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
EcalShowerProperties(const edm::Event &ev, const edm::EventSetup &es)
static CylinderPointer build(const PositionType &pos, const RotationType &rot, Scalar radius, MediumProperties *mp=0)
Definition: Cylinder.h:29
double p1[4]
Definition: TauolaWrapper.h:89
double outerY() const
y coordinate of the outermost hit position
Definition: Track.h:79
std::vector< TrajectoryStateOnSurface > getEndpoints(const FreeTrajectoryState &ftsAtLastPoint, const TrajectoryStateOnSurface &tsosBeforeEcal, int subDet)
int charge() const
track electric charge
Definition: TrackBase.h:113
std::pair< double, double > processTrack(const reco::Track &track, int &ntime)
x
Definition: VDTMath.h:216
T x() const
Definition: PV3DBase.h:61
double outerPx() const
x coordinate of momentum vector at the outermost hit position
Definition: Track.h:71
virtual const CornersVec & getCorners() const =0
Returns the corner points of this cell&#39;s volume.