CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PositionCalc.cc
Go to the documentation of this file.
8 
9 
10 
12  param_LogWeighted_ ( par.getParameter<bool>("LogWeighted")) ,
13  param_T0_barl_ ( par.getParameter<double>("T0_barl")) ,
14  param_T0_endc_ ( par.getParameter<double>("T0_endc")) ,
15  param_T0_endcPresh_ ( par.getParameter<double>("T0_endcPresh")) ,
16  param_W0_ ( par.getParameter<double>("W0")) ,
17  param_X0_ ( par.getParameter<double>("X0")) ,
18  m_esGeom ( 0 ) ,
19  m_esPlus ( false ) ,
20  m_esMinus ( false )
21 {
22 }
23 
25 {
30  param_W0_ = rhs.param_W0_;
31  param_X0_ = rhs.param_X0_;
32 
33  m_esGeom = rhs.m_esGeom ;
34  m_esPlus = rhs.m_esPlus ;
35  m_esMinus = rhs.m_esMinus ;
36  return *this;
37 }
38 
40 PositionCalc::Calculate_Location( const std::vector< std::pair<DetId, float> >& iDetIds ,
41  const EcalRecHitCollection* iRecHits ,
42  const CaloSubdetectorGeometry* iSubGeom ,
43  const CaloSubdetectorGeometry* iESGeom )
44 {
45  math::XYZPoint returnValue ( 0, 0, 0 ) ;
46 
47  // Throw an error if the cluster was not initialized properly
48 
49  if( 0 == iRecHits ||
50  0 == iSubGeom )
51  {
52  throw(std::runtime_error("\n\nPositionCalc::Calculate_Location called uninitialized or wrong initialization.\n\n"));
53  }
54 
55  if( 0 != iDetIds.size() &&
56  0 != iRecHits->size() )
57  {
58  typedef std::vector<DetId> DetIdVec ;
59 
60  DetIdVec detIds ;
61  detIds.reserve( iDetIds.size() ) ;
62 
63  double eTot ( 0 ) ;
64  double eMax ( 0 ) ;
65  DetId maxId ;
66 
67  // Check that DetIds are nonzero
68  EcalRecHitCollection::const_iterator endRecHits ( iRecHits->end() ) ;
69  for( std::vector< std::pair<DetId, float> >::const_iterator n ( iDetIds.begin() ) ; n != iDetIds.end() ; ++n )
70  {
71  const DetId dId ( (*n).first ) ;
72  if( !dId.null() )
73  {
74  EcalRecHitCollection::const_iterator iHit ( iRecHits->find( dId ) ) ;
75  if( iHit != endRecHits )
76  {
77  detIds.push_back( dId );
78 
79  const double energy ( iHit->energy() ) ;
80 
81  if( 0 < energy ) // only save positive energies
82  {
83  if( eMax < energy )
84  {
85  eMax = energy ;
86  maxId = dId ;
87  }
88  eTot += energy ;
89  }
90  }
91  }
92  }
93 
94  if( 0 >= eTot )
95  {
96  LogDebug("ZeroClusterEnergy") << "cluster with 0 energy: " << eTot
97  << ", returning (0,0,0)";
98  }
99  else
100  {
101  // first time or when es geom changes set flags
102  if( 0 != iESGeom &&
103  m_esGeom != iESGeom )
104  {
105  m_esGeom = iESGeom ;
106  for( uint32_t ic ( 0 ) ;
107  ( ic != m_esGeom->getValidDetIds().size() ) &&
108  ( (!m_esPlus) || (!m_esMinus) ) ; ++ic )
109  {
110  const double z ( m_esGeom->getGeometry( m_esGeom->getValidDetIds()[ic] )->getPosition().z() ) ;
111  m_esPlus = m_esPlus || ( 0 < z ) ;
112  m_esMinus = m_esMinus || ( 0 > z ) ;
113  }
114  }
115 
116  //Select the correct value of the T0 parameter depending on subdetector
117 
118  const CaloCellGeometry* center_cell ( iSubGeom->getGeometry( maxId ) ) ;
119  const double ctreta (center_cell->getPosition().eta());
120 
121  // for barrel, use barrel T0;
122  // for endcap: if preshower present && in preshower fiducial,
123  // use preshower T0
124  // else use endcap only T0
125 
126  const double preshowerStartEta = 1.653;
127  const int subdet = maxId.subdetId();
128  const double T0 ( subdet == EcalBarrel ? param_T0_barl_ :
129  ( ( ( preshowerStartEta < fabs( ctreta ) ) &&
130  ( ( ( 0 < ctreta ) &&
131  m_esPlus ) ||
132  ( ( 0 > ctreta ) &&
133  m_esMinus ) ) ) ?
135 
136  // Calculate shower depth
137  const float maxDepth ( param_X0_ * ( T0 + log( eTot ) ) ) ;
138  const float maxToFront ( center_cell->getPosition().mag() ) ; // to front face
139 
140  // Loop over hits and get weights
141  double total_weight = 0;
142 
143  double xw ( 0 ) ;
144  double yw ( 0 ) ;
145  double zw ( 0 ) ;
146 
147  for( DetIdVec::const_iterator j ( detIds.begin() ) ; j != detIds.end() ; ++j )
148  {
149  const DetId dId ( *j ) ;
150  EcalRecHitCollection::const_iterator iR ( iRecHits->find( dId ) ) ;
151  const double e_j ( iR->energy() ) ;
152 
153  double weight = 0;
154  if ( param_LogWeighted_ ) {
155  if ( e_j > 0 ) {
156  weight = std::max( 0., param_W0_ + log(e_j/eTot) );
157  } else {
158  weight = 0;
159  }
160  } else {
161  weight = e_j/eTot;
162  }
163 
164  const CaloCellGeometry* cell ( iSubGeom->getGeometry( dId ) ) ;
165  const float depth ( maxDepth + maxToFront - cell->getPosition().mag() ) ;
166 
167  const GlobalPoint pos (
168  dynamic_cast<const TruncatedPyramid*>( cell )->getPosition( depth ) );
169 
170  xw += weight*pos.x() ;
171  yw += weight*pos.y() ;
172  zw += weight*pos.z() ;
173 
174  total_weight += weight ;
175  }
176  returnValue = math::XYZPoint( xw/total_weight,
177  yw/total_weight,
178  zw/total_weight ) ;
179  }
180  }
181  return returnValue ;
182 }
#define LogDebug(id)
double param_T0_endc_
Definition: PositionCalc.h:48
#define maxDepth
double param_W0_
Definition: PositionCalc.h:50
auto zw(V v) -> Vec2< typenamestd::remove_reference< decltype(v[0])>::type >
Definition: ExtVec.h:36
std::vector< EcalRecHit >::const_iterator const_iterator
double param_X0_
Definition: PositionCalc.h:51
float float float z
const PositionCalc & operator=(const PositionCalc &rhs)
Definition: PositionCalc.cc:24
virtual const std::vector< DetId > & getValidDetIds(DetId::Detector det=DetId::Detector(0), int subdet=0) const
Get a list of valid detector ids (for the given subdetector)
virtual const CaloCellGeometry * getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
bool param_LogWeighted_
Definition: PositionCalc.h:46
double param_T0_endcPresh_
Definition: PositionCalc.h:49
const T & max(const T &a, const T &b)
int j
Definition: DBlmapReader.cc:9
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
const_iterator end() const
Definition: DetId.h:20
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:13
bool null() const
is this a null id ?
Definition: DetId.h:47
double param_T0_barl_
Definition: PositionCalc.h:47
math::XYZPoint Calculate_Location(const std::vector< std::pair< DetId, float > > &iDetIds, const EcalRecHitCollection *iRecHits, const CaloSubdetectorGeometry *iSubGeom, const CaloSubdetectorGeometry *iESGeom=0)
Definition: PositionCalc.cc:40
iterator find(key_type k)
size_type size() const
const CaloSubdetectorGeometry * m_esGeom
Definition: PositionCalc.h:53
int weight
Definition: histoStyle.py:50