CMS 3D CMS Logo

ME0GeometryValidate.cc
Go to the documentation of this file.
1 /*
2 //\class ME0GeometryValidate
3 
4  Description: ME0 GeometryValidate for DD4hep
5 
6  //
7 // Author: Sergio Lo Meo (sergio.lo.meo@cern.ch) following what Ianna Osborne made for DTs (DD4HEP migration)
8 // Created: 29 Apr 2020
9 */
10 
17 
23 
25 
28 
29 #include <TFile.h>
30 #include <TH1.h>
31 
32 #include <limits>
33 #include <string>
34 #include <type_traits>
35 #include <algorithm>
36 
37 using namespace std;
38 
39 template <class T>
40 typename enable_if<!numeric_limits<T>::is_integer, bool>::type almost_equal(T x, T y, int ulp) {
41  // the machine epsilon has to be scaled to the magnitude of the values used
42  // and multiplied by the desired precision in ULPs (units in the last place)
43  return abs(x - y) <= numeric_limits<T>::epsilon() * abs(x + y) * ulp
44  // unless the result is subnormal
45  || abs(x - y) < numeric_limits<T>::min();
46 }
47 
48 using namespace edm;
49 
51 public:
52  explicit ME0GeometryValidate(const ParameterSet&);
53  ~ME0GeometryValidate() override {}
54 
55 private:
56  void beginJob() override;
57  void analyze(const edm::Event&, const edm::EventSetup&) override;
58  void endJob() override;
59 
60  void validateME0ChamberGeometry();
61  void validateME0EtaPartitionGeometry();
62  void validateME0EtaPartitionGeometry2();
63 
64  void compareTransform(const GlobalPoint&, const TGeoMatrix*);
65  void compareShape(const GeomDet*, const float*);
66 
67  float getDistance(const GlobalPoint&, const GlobalPoint&);
68  float getDiff(const float, const float);
69 
70  void makeHistograms(const char*);
71  void makeHistograms2(const char*);
72  void makeHistogram(const string&, vector<float>&);
73 
74  void clearData() {
75  globalDistances_.clear();
76  topWidths_.clear();
77  bottomWidths_.clear();
78  lengths_.clear();
79  thicknesses_.clear();
80  }
81 
82  void clearData2() {
83  nstrips_.clear();
84  pitch_.clear();
85  stripslen_.clear();
86  }
87 
90  TFile* outFile_;
91  vector<float> globalDistances_;
92  vector<float> topWidths_;
93  vector<float> bottomWidths_;
94  vector<float> lengths_;
95  vector<float> thicknesses_;
96  vector<float> nstrips_;
97  vector<float> pitch_;
98  vector<float> stripslen_;
99  string infileName_;
100  string outfileName_;
102 };
103 
105  : infileName_(
106  iConfig.getUntrackedParameter<string>("infileName", "cmsRecoGeom-2026.root")), //it was cmsGeom10.root
107  outfileName_(iConfig.getUntrackedParameter<string>("outfileName", "validateME0Geometry.root")),
108  tolerance_(iConfig.getUntrackedParameter<int>("tolerance", 6)) {
110  outFile_ = TFile::Open(outfileName_.c_str(), "RECREATE");
111 }
112 
114  eventSetup.get<MuonGeometryRecord>().get(me0Geometry_);
115  if (me0Geometry_.isValid()) {
116  LogTrace("ME0Geometry") << "Validating ME0 chamber geometry";
120  } else {
121  LogError("ME0Geometry") << "Invalid ME0 geometry";
122  }
123 }
124 
126  clearData();
127 
128  for (auto const& it : me0Geometry_->chambers()) {
129  ME0DetId chId = it->id();
130  GlobalPoint gp = it->surface().toGlobal(LocalPoint(0.0, 0.0, 0.0));
131  const TGeoMatrix* matrix = fwGeometry_.getMatrix(chId.rawId());
132 
133  if (!matrix) {
134  LogTrace("ME0Geometry") << "Failed to get matrix of ME0 chamber with detid: " << chId.rawId();
135  continue;
136  }
138 
139  auto const& shape = fwGeometry_.getShapePars(chId.rawId());
140 
141  if (!shape) {
142  LogTrace("ME0Geometry") << "Failed to get shape of ME0 chamber with detid: " << chId.rawId();
143  continue;
144  }
145  compareShape(it, shape);
146  }
147  makeHistograms("ME0 Chamber");
148 }
149 
151  clearData();
152 
153  for (auto const& it : me0Geometry_->etaPartitions()) {
154  ME0DetId chId = it->id();
155  GlobalPoint gp = it->surface().toGlobal(LocalPoint(0.0, 0.0, 0.0));
156  const TGeoMatrix* matrix = fwGeometry_.getMatrix(chId.rawId());
157 
158  if (!matrix) {
159  LogTrace("ME0Geometry") << "Failed to get matrix of ME0 eta partition 2 with detid: " << chId.rawId();
160  continue;
161  }
163 
164  auto const& shape = fwGeometry_.getShapePars(chId.rawId());
165 
166  if (!shape) {
167  LogTrace("ME0Geometry") << "Failed to get shape of ME0 eta partition 2 with detid: " << chId.rawId();
168  continue;
169  }
170  compareShape(it, shape);
171  }
172  makeHistograms("ME0 Eta Partition");
173 }
174 
176  clearData2();
177 
178  for (auto const& it : me0Geometry_->etaPartitions()) {
179  ME0DetId chId = it->id();
180  const int n_strips = it->nstrips();
181  const float n_pitch = it->pitch();
182  const StripTopology& topo = it->specificTopology();
183  const float stripLen = topo.stripLength();
184  const float* parameters = fwGeometry_.getParameters(chId.rawId());
185  nstrips_.push_back(std::abs(n_strips - parameters[0]));
186 
187  if (n_strips) {
188  for (int istrips = 1; istrips <= n_strips; istrips++) {
189  if (std::abs(n_pitch - parameters[2]) < 1.0e-05)
190  pitch_.push_back(0.0f);
191  else
192  pitch_.push_back(std::abs(n_pitch - parameters[2]));
193  if (std::abs(stripLen - parameters[1]) < 1.0e-05)
194  pitch_.push_back(0.0f);
195  else
196  stripslen_.push_back(std::abs(stripLen - parameters[1]));
197  }
198  } else {
199  LogWarning("ME0Geometry") << "ATTENTION! nStrips == 0";
200  }
201  }
202  makeHistograms2("ME0 Eta Partition");
203 }
204 
206  double local[3] = {0.0, 0.0, 0.0};
207  double global[3];
208 
209  matrix->LocalToMaster(local, global);
210 
211  float distance = getDistance(GlobalPoint(global[0], global[1], global[2]), gp);
212  if (abs(distance) < 1.0e-7)
213  distance = 0.0; // set a tollerance for the distance inside Histos
214  globalDistances_.push_back(distance);
215 }
216 
217 void ME0GeometryValidate::compareShape(const GeomDet* det, const float* shape) {
218  float shapeTopWidth;
219  float shapeBottomWidth;
220  float shapeLength;
221  float shapeThickness;
222 
223  if (shape[0] == 1) {
224  shapeTopWidth = shape[2];
225  shapeBottomWidth = shape[1];
226  shapeLength = shape[4];
227  shapeThickness = shape[3];
228  } else if (shape[0] == 2) {
229  shapeTopWidth = shape[1];
230  shapeBottomWidth = shape[1];
231  shapeLength = shape[2];
232  shapeThickness = shape[3];
233  } else {
234  LogTrace("ME0Geometry") << "Failed to get box or trapezoid from shape";
235 
236  return;
237  }
238 
239  float topWidth, bottomWidth;
240  float length, thickness;
241 
242  const Bounds* bounds = &(det->surface().bounds());
243  if (const TrapezoidalPlaneBounds* tpbs = dynamic_cast<const TrapezoidalPlaneBounds*>(bounds)) {
244  array<const float, 4> const& ps = tpbs->parameters();
245 
246  assert(ps.size() == 4);
247 
248  bottomWidth = ps[0];
249  topWidth = ps[1];
250  thickness = ps[2];
251  length = ps[3];
252 
253  } else if ((dynamic_cast<const RectangularPlaneBounds*>(bounds))) {
254  length = det->surface().bounds().length() * 0.5;
255  topWidth = det->surface().bounds().width() * 0.5;
256  bottomWidth = topWidth;
257  thickness = det->surface().bounds().thickness() * 0.5;
258 
259  } else {
260  LogTrace("ME0Geometry") << "Failed to get bounds";
261 
262  return;
263  }
264  topWidths_.push_back(std::abs(shapeTopWidth - topWidth));
265  bottomWidths_.push_back(std::abs(shapeBottomWidth - bottomWidth));
266  lengths_.push_back(std::abs(shapeLength - length));
267  thicknesses_.push_back(std::abs(shapeThickness - thickness));
268 }
269 
271  return sqrt((p1.x() - p2.x()) * (p1.x() - p2.x()) + (p1.y() - p2.y()) * (p1.y() - p2.y()) +
272  (p1.z() - p2.z()) * (p1.z() - p2.z()));
273 }
274 
275 float ME0GeometryValidate::getDiff(const float val1, const float val2) {
276  if (almost_equal(val1, val2, tolerance_))
277  return 0.0f;
278  else
279  return (val1 - val2);
280 }
281 
283  outFile_->cd();
284 
285  string d(detector);
286 
287  string gdn = d + ": distance between points in global coordinates";
289 
290  string twn = d + ": absolute difference between top widths (along X)";
292 
293  string bwn = d + ": absolute difference between bottom widths (along X)";
295 
296  string ln = d + ": absolute difference between lengths (along Y)";
297  makeHistogram(ln, lengths_);
298 
299  string tn = d + ": absolute difference between thicknesses (along Z)";
301 }
302 
304  outFile_->cd();
305 
306  string d(detector);
307 
308  string ns = d + ": absolute difference between nStrips";
309  makeHistogram(ns, nstrips_);
310 
311  string pi = d + ": absolute difference between Strips Pitch";
313 
314  string pl = d + ": absolute difference between Strips Length";
316 }
317 
318 void ME0GeometryValidate::makeHistogram(const string& name, vector<float>& data) {
319  if (data.empty())
320  return;
321 
322  const auto [minE, maxE] = minmax_element(begin(data), end(data));
323 
324  TH1D hist(name.c_str(), name.c_str(), 100, *minE * (1 + 0.10), *maxE * (1 + 0.10));
325 
326  for (auto const& it : data)
327  hist.Fill(it);
328 
329  hist.GetXaxis()->SetTitle("[cm]");
330  hist.Write();
331 }
332 
334 
336  LogTrace("ME0Geometry") << "Done.";
337  LogTrace("ME0Geometry") << "Results written to " << outfileName_;
338  outFile_->Close();
339 }
340 
ME0Geometry::etaPartitions
const std::vector< ME0EtaPartition const * > & etaPartitions() const
Return a vector of all ME0 eta partitions.
Definition: ME0Geometry.cc:33
ME0GeometryValidate::endJob
void endJob() override
Definition: ME0GeometryValidate.cc:335
ME0GeometryValidate::validateME0ChamberGeometry
void validateME0ChamberGeometry()
Definition: ME0GeometryValidate.cc:125
bk::beginJob
void beginJob()
Definition: Breakpoints.cc:14
HLT_FULL_cff.maxE
maxE
Definition: HLT_FULL_cff.py:13669
BeamSpotPI::parameters
parameters
Definition: BeamSpotPayloadInspectorHelper.h:30
ME0GeometryValidate::infileName_
string infileName_
Definition: ME0GeometryValidate.cc:99
EDAnalyzer.h
FWGeometry
Definition: FWGeometry.h:27
Bounds::width
virtual float width() const =0
MessageLogger.h
GeomDet
Definition: GeomDet.h:27
ME0GeometryValidate::nstrips_
vector< float > nstrips_
Definition: ME0GeometryValidate.cc:96
makeMuonMisalignmentScenario.matrix
list matrix
Definition: makeMuonMisalignmentScenario.py:141
ME0GeometryValidate::~ME0GeometryValidate
~ME0GeometryValidate() override
Definition: ME0GeometryValidate.cc:53
ESHandle.h
FWGeometry::loadMap
void loadMap(const char *fileName)
Definition: FWGeometry.cc:103
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
ME0GeometryValidate
Definition: ME0GeometryValidate.cc:50
ME0GeometryValidate::compareTransform
void compareTransform(const GlobalPoint &, const TGeoMatrix *)
Definition: ME0GeometryValidate.cc:205
min
T min(T a, T b)
Definition: MathUtil.h:58
edm
HLT enums.
Definition: AlignableModifier.h:19
FWGeometry::getShapePars
const float * getShapePars(unsigned int id) const
Definition: FWGeometry.cc:489
Bounds
Definition: Bounds.h:18
cms::cuda::assert
assert(be >=bs)
edm::one::EDAnalyzer
Definition: EDAnalyzer.h:30
StripTopology.h
align::LocalPoint
Point3DBase< Scalar, LocalTag > LocalPoint
Definition: Definitions.h:30
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
ME0GeometryValidate::clearData2
void clearData2()
Definition: ME0GeometryValidate.cc:82
ME0Geometry::chambers
const std::vector< const ME0Chamber * > & chambers() const
Return a vector of all ME0 chambers.
Definition: ME0Geometry.cc:29
ME0GeometryValidate::validateME0EtaPartitionGeometry
void validateME0EtaPartitionGeometry()
Definition: ME0GeometryValidate.cc:175
geometryDiff.epsilon
int epsilon
Definition: geometryDiff.py:26
Bounds::length
virtual float length() const =0
ME0GeometryValidate::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: ME0GeometryValidate.cc:113
ME0GeometryValidate::makeHistograms
void makeHistograms(const char *)
Definition: ME0GeometryValidate.cc:282
GeomDet::surface
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
FWGeometry::getParameters
const float * getParameters(unsigned int id) const
Definition: FWGeometry.cc:478
MakerMacros.h
FWGeometry::getMatrix
const TGeoMatrix * getMatrix(unsigned int id) const
Definition: FWGeometry.cc:225
ME0GeometryValidate::topWidths_
vector< float > topWidths_
Definition: ME0GeometryValidate.cc:92
ME0GeometryValidate::outfileName_
string outfileName_
Definition: ME0GeometryValidate.cc:100
edm::EventSetup::get
T get() const
Definition: EventSetup.h:87
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
TrapezoidalPlaneBounds.h
Calorimetry_cff.thickness
thickness
Definition: Calorimetry_cff.py:115
ME0GeometryValidate::validateME0EtaPartitionGeometry2
void validateME0EtaPartitionGeometry2()
Definition: ME0GeometryValidate.cc:150
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
Surface::bounds
const Bounds & bounds() const
Definition: Surface.h:87
mps_fire.end
end
Definition: mps_fire.py:242
ME0GeometryValidate::ME0GeometryValidate
ME0GeometryValidate(const ParameterSet &)
Definition: ME0GeometryValidate.cc:104
edm::ESHandle< ME0Geometry >
p2
double p2[4]
Definition: TauolaWrapper.h:90
RectangularPlaneBounds.h
ME0GeometryValidate::makeHistograms2
void makeHistograms2(const char *)
Definition: ME0GeometryValidate.cc:303
GlobalPoint
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
Point3DBase< float, GlobalTag >
ME0GeometryValidate::outFile_
TFile * outFile_
Definition: ME0GeometryValidate.cc:90
CSCSkim_cfi.makeHistograms
makeHistograms
Definition: CSCSkim_cfi.py:15
ME0GeometryValidate::getDiff
float getDiff(const float, const float)
Definition: ME0GeometryValidate.cc:275
ME0GeometryValidate::beginJob
void beginJob() override
Definition: ME0GeometryValidate.cc:333
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
runTauDisplay.gp
gp
Definition: runTauDisplay.py:431
FWGeometry.h
Bounds::thickness
virtual float thickness() const =0
StripTopology::stripLength
virtual float stripLength() const =0
ME0GeometryValidate::bottomWidths_
vector< float > bottomWidths_
Definition: ME0GeometryValidate.cc:93
edm::ParameterSet
Definition: ParameterSet.h:47
ME0GeometryValidate::globalDistances_
vector< float > globalDistances_
Definition: ME0GeometryValidate.cc:91
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
gpuVertexFinder::hist
__shared__ Hist hist
Definition: gpuClusterTracksDBSCAN.h:48
ME0GeometryValidate::getDistance
float getDistance(const GlobalPoint &, const GlobalPoint &)
Definition: ME0GeometryValidate.cc:270
ME0GeometryValidate::pitch_
vector< float > pitch_
Definition: ME0GeometryValidate.cc:97
createfilelist.int
int
Definition: createfilelist.py:10
p1
double p1[4]
Definition: TauolaWrapper.h:89
analyze
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
edm::EventSetup
Definition: EventSetup.h:58
ME0DetId
Definition: ME0DetId.h:16
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
ME0GeometryValidate::me0Geometry_
edm::ESHandle< ME0Geometry > me0Geometry_
Definition: ME0GeometryValidate.cc:88
TrapezoidalPlaneBounds
Definition: TrapezoidalPlaneBounds.h:15
get
#define get
edm::ESHandleBase::isValid
bool isValid() const
Definition: ESHandle.h:44
ME0Geometry.h
std
Definition: JetResolutionObject.h:76
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
ME0GeometryValidate::lengths_
vector< float > lengths_
Definition: ME0GeometryValidate.cc:94
T
long double T
Definition: Basic3DVectorLD.h:48
ME0GeometryValidate::clearData
void clearData()
Definition: ME0GeometryValidate.cc:74
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
EventSetup.h
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
ME0GeometryValidate::tolerance_
int tolerance_
Definition: ME0GeometryValidate.cc:101
hgcalTestNeighbor_cfi.detector
detector
Definition: hgcalTestNeighbor_cfi.py:6
ztail.d
d
Definition: ztail.py:151
pi
const Double_t pi
Definition: trackSplitPlot.h:36
DTRecHitClients_cfi.local
local
Definition: DTRecHitClients_cfi.py:10
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:234
ME0GeometryValidate::thicknesses_
vector< float > thicknesses_
Definition: ME0GeometryValidate.cc:95
ParameterSet.h
ME0Chamber.h
MuonGeometryRecord.h
ME0GeometryValidate::makeHistogram
void makeHistogram(const string &, vector< float > &)
Definition: ME0GeometryValidate.cc:318
event
Definition: event.py:1
ME0GeometryValidate::fwGeometry_
FWGeometry fwGeometry_
Definition: ME0GeometryValidate.cc:89
edm::Event
Definition: Event.h:73
ME0GeometryValidate::stripslen_
vector< float > stripslen_
Definition: ME0GeometryValidate.cc:98
HLT_FULL_cff.distance
distance
Definition: HLT_FULL_cff.py:7733
StripTopology
Definition: StripTopology.h:11
MuonGeometryRecord
Definition: MuonGeometryRecord.h:34
almost_equal
enable_if<!numeric_limits< T >::is_integer, bool >::type almost_equal(T x, T y, int ulp)
Definition: ME0GeometryValidate.cc:40
ME0GeometryValidate::compareShape
void compareShape(const GeomDet *, const float *)
Definition: ME0GeometryValidate.cc:217
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
ME0Layer.h