CMS 3D CMS Logo

FastTimeGeometry.cc
Go to the documentation of this file.
6 
7 #include <cmath>
8 
9 #include <Math/Transform3D.h>
10 #include <Math/EulerAngles.h>
11 
13 typedef std::vector<float> ParmVec;
14 
16  : m_topology(topology_),
17  m_cellVec(topology_.totalGeomModules()),
18  m_validGeomIds(topology_.totalGeomModules()),
19  m_Type(topology_.detectorType()),
20  m_subdet(topology_.subDetector()) {
21  m_validIds.reserve(topology().totalModules());
22 #ifdef EDM_ML_DEBUG
23  std::cout << "Expected total # of Geometry Modules " << topology().totalGeomModules() << std::endl;
24 #endif
25 }
26 
28 
30 
32 
33 void FastTimeGeometry::localCorners(Pt3DVec& lc, const CCGFloat* pv, unsigned int i, Pt3D& ref) {
34  FlatTrd::localCorners(lc, pv, ref);
35 }
36 
38  const GlobalPoint& f1, const GlobalPoint& f2, const GlobalPoint& f3, const CCGFloat* parm, const DetId& detId) {
40  DetId geomId = (DetId)(FastTimeDetId(detId).geometryCell());
41  int nEtaZ = topology().dddConstants().numberEtaZ(m_Type);
43 
44  const uint32_t cellIndex(topology().detId2denseGeomId(detId));
45 
46  m_cellVec.at(cellIndex) = FlatTrd(cornersMgr(), f1, f2, f3, parm);
47  m_validGeomIds.at(cellIndex) = geomId;
48 
49 #ifdef EDM_ML_DEBUG
50  unsigned int nOld = m_validIds.size();
51 #endif
52  for (int etaZ = 1; etaZ <= nEtaZ; ++etaZ) {
53  id.iEtaZ = etaZ;
54  for (int phi = 1; phi <= nPhi; ++phi) {
55  id.iPhi = phi;
56  DetId idc = topology().encode(id);
57  if (topology().valid(idc)) {
58  m_validIds.emplace_back(idc);
59  }
60  }
61  }
62 
63 #ifdef EDM_ML_DEBUG
64  std::cout << "FastTimeGeometry::newCell-> [" << cellIndex << "]"
65  << " front:" << f1.x() << '/' << f1.y() << '/' << f1.z() << " back:" << f2.x() << '/' << f2.y() << '/'
66  << f2.z() << " eta|phi " << m_cellVec[cellIndex].etaPos() << ":" << m_cellVec[cellIndex].phiPos()
67  << " id:" << FastTimeDetId(detId) << " with valid DetId from " << nOld << " to " << m_validIds.size()
68  << std::endl;
69  std::cout << "Cell[" << cellIndex << "] " << std::hex << geomId.rawId() << ":" << m_validGeomIds[cellIndex].rawId()
70  << std::dec << std::endl;
71 #endif
72 }
73 
74 std::shared_ptr<const CaloCellGeometry> FastTimeGeometry::getGeometry(const DetId& id) const {
75  if (id == DetId())
76  return nullptr; // nothing to get
77  DetId geoId = (DetId)(FastTimeDetId(id).geometryCell());
78  const uint32_t cellIndex(topology().detId2denseGeomId(geoId));
79  const GlobalPoint pos = (id != geoId) ? getPosition(id) : GlobalPoint();
80  return cellGeomPtr(cellIndex, pos);
81 }
82 
83 bool FastTimeGeometry::present(const DetId& id) const {
84  if (id == DetId())
85  return false;
86  DetId geoId = (DetId)(FastTimeDetId(id).geometryCell());
87  const uint32_t index(topology().detId2denseGeomId(geoId));
88  return (nullptr != getGeometryRawPtr(index));
89 }
90 
92  FastTimeDetId id_ = FastTimeDetId(id);
93  auto pos = topology().dddConstants().getPosition(m_Type, id_.ieta(), id_.iphi(), id_.zside());
94  return GlobalPoint(0.1 * pos.x(), 0.1 * pos.y(), 0.1 * pos.z());
95 }
96 
98  FastTimeDetId id_ = FastTimeDetId(id);
99  auto corners = topology().dddConstants().getCorners(m_Type, id_.ieta(), id_.iphi(), id_.zside());
101  for (const auto& corner : corners) {
102  out.emplace_back(0.1 * corner.x(), 0.1 * corner.y(), 0.1 * corner.z());
103  }
104  return out;
105 }
106 
108  int zside = (r.z() > 0) ? 1 : -1;
109  std::pair<int, int> etaZPhi;
110  if (m_Type == 1) {
111  double zz = (zside > 0) ? r.z() : -r.z();
112  etaZPhi = topology().dddConstants().getZPhi(zz, r.phi());
113  } else {
114  double phi = (zside > 0) ? static_cast<double>(r.phi()) : atan2(r.y(), -r.x());
115  // Cast needed to resolve compile-time ambiguity of ? operator between
116  // convertible Phi class and atan2 template function.
117 
118  etaZPhi = topology().dddConstants().getEtaPhi(r.perp(), phi);
119  }
120  FastTimeDetId id = FastTimeDetId(m_Type, etaZPhi.first, etaZPhi.second, zside);
121 #ifdef EDM_ML_DEBUG
122  std::cout << "getClosestCell: for (" << r.x() << ", " << r.y() << ", " << r.z() << ") Id " << id.type() << ":"
123  << id.zside() << ":" << id.ieta() << ":" << id.iphi() << std::endl;
124 #endif
125 
126  return (topology().valid(id) ? DetId(id) : DetId());
127 }
128 
131  return dss;
132 }
133 
135  if (m_Type == 1)
136  return "FastTimeBarrel";
137  else if (m_Type == 2)
138  return "FastTimeEndcap";
139  else
140  return "Unknown";
141 }
142 
143 unsigned int FastTimeGeometry::indexFor(const DetId& id) const {
144  unsigned int cellIndex = m_cellVec.size();
145  if (id != DetId()) {
146  DetId geoId = (DetId)(FastTimeDetId(id).geometryCell());
147  cellIndex = topology().detId2denseGeomId(geoId);
148 #ifdef EDM_ML_DEBUG
149  std::cout << "indexFor " << std::hex << id.rawId() << ":" << geoId.rawId() << std::dec << " index " << cellIndex
150  << std::endl;
151 #endif
152  }
153  return cellIndex;
154 }
155 
157 
159  // Modify the RawPtr class
160  const CaloCellGeometry* cell(&m_cellVec[index]);
161  return (m_cellVec.size() < index || nullptr == cell->param() ? nullptr : cell);
162 }
163 
164 std::shared_ptr<const CaloCellGeometry> FastTimeGeometry::cellGeomPtr(uint32_t index) const {
165  if ((index >= m_cellVec.size()) || (m_validGeomIds[index].rawId() == 0))
166  return nullptr;
167  static const auto do_not_delete = [](const void*) {};
168  auto cell = std::shared_ptr<const CaloCellGeometry>(&m_cellVec[index], do_not_delete);
169  if (nullptr == cell->param())
170  return nullptr;
171  return cell;
172 }
173 
174 std::shared_ptr<const CaloCellGeometry> FastTimeGeometry::cellGeomPtr(uint32_t index, const GlobalPoint& pos) const {
175  if ((index >= m_cellVec.size()) || (m_validGeomIds[index].rawId() == 0))
176  return nullptr;
177  if (pos == GlobalPoint())
178  return cellGeomPtr(index);
179  auto cell = std::make_shared<FlatTrd>(m_cellVec[index]);
180  cell->setPosition(pos);
181 #ifdef EDM_ML_DEBUG
182 //std::cout << "cellGeomPtr " << newcell << ":" << cell << std::endl;
183 #endif
184  if (nullptr == cell->param())
185  return nullptr;
186  return cell;
187 }
188 
190  edm::LogError("FastTimeGeom") << "FastTimeGeometry::addValidID is not implemented";
191 }
192 
193 // FIXME: Change sorting algorithm if needed
194 namespace {
195  struct rawIdSort {
196  bool operator()(const DetId& a, const DetId& b) { return (a.rawId() < b.rawId()); }
197  };
198 } // namespace
199 
201  m_validIds.shrink_to_fit();
202  std::sort(m_validIds.begin(), m_validIds.end(), rawIdSort());
203 }
204 
208  CaloSubdetectorGeometry::IVec& dinsVector) const {
209  unsigned int numberOfCells = topology().totalGeomModules(); // total Geom Modules both sides
212 
213  trVector.reserve(numberOfCells * numberOfTransformParms());
214  iVector.reserve(numberOfCells);
215  dimVector.reserve(numberOfShapes * numberOfParametersPerShape);
216  dinsVector.reserve(numberOfCells);
217 
218  for (unsigned int k = 0; k < topology().totalGeomModules(); ++k) {
221  params[1] = params[2] = 0;
225  params[6] = params[10] = 0;
226  params[11] = (k == 0) ? 1.0 : -1.0;
227  dimVector.insert(dimVector.end(), params.begin(), params.end());
228  }
229 
230  for (unsigned int i(0); i < numberOfCells; ++i) {
231  DetId detId = m_validGeomIds[i];
232  dinsVector.emplace_back(topology().detId2denseGeomId(detId));
233  iVector.emplace_back(1);
234 
235  Tr3D tr;
236  auto ptr(cellGeomPtr(i));
237  if (nullptr != ptr) {
238  ptr->getTransform(tr, (Pt3DVec*)nullptr);
239 
240  if (Tr3D() == tr) { // there is no rotation
241  const GlobalPoint& gp(ptr->getPosition());
242  tr = HepGeom::Translate3D(gp.x(), gp.y(), gp.z());
243  }
244 
245  const CLHEP::Hep3Vector tt(tr.getTranslation());
246  trVector.emplace_back(tt.x());
247  trVector.emplace_back(tt.y());
248  trVector.emplace_back(tt.z());
249  if (6 == numberOfTransformParms()) {
250  const CLHEP::HepRotation rr(tr.getRotation());
251  const ROOT::Math::Transform3D rtr(
252  rr.xx(), rr.xy(), rr.xz(), tt.x(), rr.yx(), rr.yy(), rr.yz(), tt.y(), rr.zx(), rr.zy(), rr.zz(), tt.z());
254  rtr.GetRotation(ea);
255  trVector.emplace_back(ea.Phi());
256  trVector.emplace_back(ea.Theta());
257  trVector.emplace_back(ea.Psi());
258  }
259  }
260  }
261 }
262 
264 
CaloCellGeometry::Tr3D
HepGeom::Transform3D Tr3D
Definition: CaloCellGeometry.h:53
FastTimeGeometry::Pt3DVec
CaloCellGeometry::Pt3DVec Pt3DVec
Definition: FastTimeGeometry.h:30
CaloGenericDetId.h
FastTimeDDDConstants::getRout
double getRout(int type) const
Definition: FastTimeDDDConstants.cc:134
CaloSubdetectorGeometry::numberOfParametersPerShape
virtual unsigned int numberOfParametersPerShape() const
Definition: CaloSubdetectorGeometry.h:93
FastTimeDetId::ieta
int ieta() const
get the absolute value of the cell #'s along x-axis (EC) | z-axis (Barel)
Definition: FastTimeDetId.h:41
mps_fire.i
i
Definition: mps_fire.py:428
geometryCSVtoXML.zz
zz
Definition: geometryCSVtoXML.py:19
FlatTrd::localCorners
static void localCorners(Pt3DVec &vec, const CCGFloat *pv, Pt3D &ref)
Definition: FlatTrd.cc:153
groupFilesInBlocks.tt
int tt
Definition: groupFilesInBlocks.py:144
FastTimeGeometry::DetIdSet
std::set< DetId > DetIdSet
Definition: FastTimeGeometry.h:32
FastTimeGeometry::getGeometryRawPtr
const CaloCellGeometry * getGeometryRawPtr(uint32_t index) const override
Definition: FastTimeGeometry.cc:158
CalibrationSummaryClient_cfi.params
params
Definition: CalibrationSummaryClient_cfi.py:14
ecaldqm::zside
int zside(DetId const &)
Definition: EcalDQMCommonUtils.cc:189
CaloSubdetectorGeometry::DimVec
std::vector< CCGFloat > DimVec
Definition: CaloSubdetectorGeometry.h:35
FlatTrd
A base class to handle the particular shape of HGCal volumes.
Definition: FlatTrd.h:19
findQualityFiles.rr
string rr
Definition: findQualityFiles.py:185
FastTimeGeometry::Pt3D
CaloCellGeometry::Pt3D Pt3D
Definition: FastTimeGeometry.h:29
FastTimeGeometry::localCorners
void localCorners(Pt3DVec &lc, const CCGFloat *pv, unsigned int i, Pt3D &ref)
Definition: FastTimeGeometry.cc:33
FastTimeDetId::iphi
int iphi() const
get the absolute value of the cell #'s along y-axis (EC) | phi (Barrel)
Definition: FastTimeDetId.h:45
gather_cfg.cout
cout
Definition: gather_cfg.py:144
pos
Definition: PixelAliasList.h:18
FastTimeGeometry::k_NumberOfParametersPerShape
Definition: FastTimeGeometry.h:38
distTCMET_cfi.corner
corner
Definition: distTCMET_cfi.py:38
FastTimeGeometry::cellGeomPtr
std::shared_ptr< const CaloCellGeometry > cellGeomPtr(uint32_t index) const override
Definition: FastTimeGeometry.cc:164
CaloSubdetectorGeometry::TrVec
std::vector< CCGFloat > TrVec
Definition: CaloSubdetectorGeometry.h:33
typelookup.h
CaloSubdetectorGeometry::numberOfTransformParms
virtual unsigned int numberOfTransformParms() const
Definition: CaloSubdetectorGeometry.h:94
CaloSubdetectorGeometry::IVec
std::vector< unsigned int > IVec
Definition: CaloSubdetectorGeometry.h:34
ParmVec
std::vector< float > ParmVec
Definition: FastTimeGeometry.cc:13
FastTimeGeometry::indexFor
unsigned int indexFor(const DetId &id) const override
Definition: FastTimeGeometry.cc:143
Tr3D
CaloCellGeometry::Tr3D Tr3D
Definition: FastTimeGeometry.cc:12
CaloSubdetectorGeometry::numberOfShapes
virtual unsigned int numberOfShapes() const
Definition: CaloSubdetectorGeometry.h:92
FastTimeTopology::dddConstants
const FastTimeDDDConstants & dddConstants() const
Definition: FastTimeTopology.h:82
FastTimeGeometry::~FastTimeGeometry
~FastTimeGeometry() override
Definition: FastTimeGeometry.cc:27
DetId
Definition: DetId.h:17
CaloSubdetectorGeometry::CCGFloat
CaloCellGeometry::CCGFloat CCGFloat
Definition: CaloSubdetectorGeometry.h:25
FastTimeGeometry::k_NumberOfShapes
Definition: FastTimeGeometry.h:39
FastTimeGeometry::getCorners
CornersVec getCorners(const DetId &id) const
Returns the corner points of this cell's volume.
Definition: FastTimeGeometry.cc:97
FastTimeTopology::decode
DecodedDetId decode(const DetId &id) const
Definition: FastTimeTopology.cc:81
FastTimeDDDConstants::getRin
double getRin(int type) const
Definition: FastTimeDDDConstants.cc:124
FastTimeGeometry::addValidID
void addValidID(const DetId &id)
Definition: FastTimeGeometry.cc:189
TruncatedPyramid.h
FastTimeDDDConstants::getZPhi
std::pair< int, int > getZPhi(double z, double phi) const
Definition: FastTimeDDDConstants.cc:24
CaloSubdetectorGeometry::m_validIds
std::vector< DetId > m_validIds
Definition: CaloSubdetectorGeometry.h:115
FastTimeGeometry::present
bool present(const DetId &id) const override
is this detid present in the geometry?
Definition: FastTimeGeometry.cc:83
Tr3D
CaloCellGeometry::Tr3D Tr3D
Definition: CaloCellGeometry.cc:7
GlobalPoint
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
dqmdumpme.k
k
Definition: dqmdumpme.py:60
Point3DBase< float, GlobalTag >
b
double b
Definition: hdecay.h:118
FastTimeTopology::detId2denseGeomId
virtual uint32_t detId2denseGeomId(const DetId &id) const
Definition: FastTimeTopology.cc:41
FastTimeTopology::totalGeomModules
unsigned int totalGeomModules() const
Definition: FastTimeTopology.h:79
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
runTauDisplay.gp
gp
Definition: runTauDisplay.py:431
FastTimeGeometry::getPosition
GlobalPoint getPosition(const DetId &id) const
Definition: FastTimeGeometry.cc:91
a
double a
Definition: hdecay.h:119
FastTimeGeometry
Definition: FastTimeGeometry.h:24
FastTimeDDDConstants::numberPhi
int numberPhi(int type) const
Definition: FastTimeDDDConstants.cc:184
CaloCellGeometry
Definition: CaloCellGeometry.h:50
DeadROC_duringRun.f2
f2
Definition: DeadROC_duringRun.py:220
FastTimeDetId::zside
int zside() const
get the z-side of the cell (1/-1)
Definition: FastTimeDetId.h:48
CaloCellGeometry::param
const CCGFloat * param() const
Definition: CaloCellGeometry.h:99
HLT_FULL_cff.nPhi
nPhi
Definition: HLT_FULL_cff.py:6597
MetAnalyzer.pv
def pv(vc)
Definition: MetAnalyzer.py:7
FastTimeGeometry::newCell
void newCell(const GlobalPoint &f1, const GlobalPoint &f2, const GlobalPoint &f3, const CCGFloat *parm, const DetId &detId) override
Definition: FastTimeGeometry.cc:37
FastTimeGeometry::initializeParms
void initializeParms() override
Definition: FastTimeGeometry.cc:31
FastTimeGeometry::getCells
DetIdSet getCells(const GlobalPoint &r, double dR) const override
Get a list of all cells within a dR of the given cell.
Definition: FastTimeGeometry.cc:129
FastTimeDDDConstants::numberEtaZ
int numberEtaZ(int type) const
Definition: FastTimeDDDConstants.cc:174
FastTimeDDDConstants::getEtaPhi
std::pair< int, int > getEtaPhi(double r, double phi) const
Definition: FastTimeDDDConstants.cc:40
FastTimeDetId::geometryCell
FastTimeDetId geometryCell() const
Definition: FastTimeDetId.h:32
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
align::EulerAngles
AlgebraicVector EulerAngles
Definition: Definitions.h:34
TYPELOOKUP_DATA_REG
#define TYPELOOKUP_DATA_REG(_dataclass_)
Definition: typelookup.h:102
FastTimeTopology::DecodedDetId
Definition: FastTimeTopology.h:87
FastTimeGeometry::getGeometry
std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const override
Get the cell geometry of a given detector id. Should return false if not found.
Definition: FastTimeGeometry.cc:74
alignCSCRings.r
r
Definition: alignCSCRings.py:93
DDAxes::phi
FastTimeTopology::encode
DetId encode(const DecodedDetId &id_) const
Definition: FastTimeTopology.cc:92
CaloCellGeometry.h
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
FastTimeGeometry::m_validGeomIds
std::vector< DetId > m_validGeomIds
Definition: FastTimeGeometry.h:113
CaloSubdetectorGeometry::cornersMgr
CaloCellGeometry::CornersMgr * cornersMgr()
Definition: CaloSubdetectorGeometry.h:82
FastTimeGeometry::m_Type
int m_Type
Definition: FastTimeGeometry.h:114
FastTimeGeometry::sortDetIds
void sortDetIds()
Definition: FastTimeGeometry.cc:200
FastTimeGeometry::getSummary
void getSummary(CaloSubdetectorGeometry::TrVec &trVector, CaloSubdetectorGeometry::IVec &iVector, CaloSubdetectorGeometry::DimVec &dimVector, CaloSubdetectorGeometry::IVec &dinsVector) const override
Definition: FastTimeGeometry.cc:205
FastTimeGeometry::sizeForDenseIndex
unsigned int sizeForDenseIndex() const
Definition: FastTimeGeometry.cc:156
FastTimeTopology
Definition: FastTimeTopology.h:11
FastTimeGeometry::topology
const FastTimeTopology & topology() const
Definition: FastTimeGeometry.h:93
FastTimeDetId
Definition: FastTimeDetId.h:8
FastTimeGeometry::cellElement
std::string cellElement() const
Definition: FastTimeGeometry.cc:134
Exception.h
FastTimeGeometry.h
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
FastTimeGeometry::m_cellVec
CellVec m_cellVec
Definition: FastTimeGeometry.h:112
DDFilteredView
Definition: DDFilteredView.h:20
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
FastTimeDDDConstants::getZHalf
double getZHalf(int type) const
Definition: FastTimeDDDConstants.cc:144
FastTimeGeometry::getClosestCell
DetId getClosestCell(const GlobalPoint &r) const override
Definition: FastTimeGeometry.cc:107
FastTimeGeometry::FastTimeGeometry
FastTimeGeometry(const FastTimeTopology &topology)
Definition: FastTimeGeometry.cc:15
RunInfoPI::valid
Definition: RunInfoPayloadInspectoHelper.h:16
HGC3DClusterGenMatchSelector_cfi.dR
dR
Definition: HGC3DClusterGenMatchSelector_cfi.py:7
FastTimeDDDConstants::getCorners
std::vector< GlobalPoint > getCorners(int type, int izeta, int iphi, int zside) const
Definition: FastTimeDDDConstants.cc:80
DeadROC_duringRun.f1
f1
Definition: DeadROC_duringRun.py:219
FastTimeDDDConstants::getPosition
GlobalPoint getPosition(int type, int izeta, int iphi, int zside) const
Definition: FastTimeDDDConstants.cc:60
FastTimeGeometry::fillNamedParams
virtual void fillNamedParams(DDFilteredView fv)
Definition: FastTimeGeometry.cc:29
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143
FastTimeGeometry::CornersVec
std::vector< GlobalPoint > CornersVec
Definition: FastTimeGeometry.h:33