CMS 3D CMS Logo

CSCGeometryValidate.cc
Go to the documentation of this file.
1 /*
2 //\class CSCGeometryValidate
3 
4  Description: CSC GeometryValidate from DD & DD4hep
5 
6 //
7 // Author: Sergio Lo Meo (sergio.lo.meo@cern.ch) following what Ianna Osburne made for DTs (DD4HEP migration)
8 // Created: Thu, 05 March 2020
9 */
10 
16 
25 
27 
30 
31 #include <TFile.h>
32 #include <TH1.h>
33 
34 #include <limits>
35 #include <string>
36 #include <type_traits>
37 #include <algorithm>
38 
39 using namespace std;
40 
41 template <class T>
42 typename enable_if<!numeric_limits<T>::is_integer, bool>::type almost_equal(T x, T y, int ulp) {
43  // the machine epsilon has to be scaled to the magnitude of the values used
44  // and multiplied by the desired precision in ULPs (units in the last place)
45  return abs(x - y) <= numeric_limits<T>::epsilon() * abs(x + y) * ulp
46  // unless the result is subnormal
47  || abs(x - y) < numeric_limits<T>::min();
48 }
49 
50 using namespace edm;
51 
53 public:
54  explicit CSCGeometryValidate(const ParameterSet&);
55  ~CSCGeometryValidate() override {}
56 
57 private:
58  void beginJob() override;
59  void analyze(const edm::Event&, const edm::EventSetup&) override;
60  void endJob() override;
61 
62  void validateCSCChamberGeometry();
63  void validateCSCLayerGeometry();
64 
65  void compareTransform(const GlobalPoint&, const TGeoMatrix*);
66  void compareShape(const GeomDet*, const float*);
67 
68  float getDistance(const GlobalPoint&, const GlobalPoint&);
69  float getDiff(const float, const float);
70 
71  void makeHistograms(const char*);
72  void makeHistograms2(const char*);
73  void makeHistogram(const string&, vector<float>&);
74 
75  void clearData() {
76  globalDistances_.clear();
77  topWidths_.clear();
78  bottomWidths_.clear();
79  lengths_.clear();
80  thicknesses_.clear();
81  }
82 
83  void clearData2() {
84  yAxisOrientation_.clear();
85  sOffset_.clear();
86  yCentreOfStripPlane_.clear();
87  angularWidth_.clear();
88  centreToIntersection_.clear();
89  phiOfOneEdge_.clear();
90  wireSpacing_.clear();
91  wireAngle_.clear();
92  }
93 
97  TFile* outFile_;
98  //chambers
99  vector<float> globalDistances_;
100  vector<float> topWidths_;
101  vector<float> bottomWidths_;
102  vector<float> lengths_;
103  vector<float> thicknesses_;
104  // strips
105  vector<float> yAxisOrientation_;
106  vector<float> sOffset_;
107  vector<float> yCentreOfStripPlane_;
108  vector<float> angularWidth_;
109  vector<float> centreToIntersection_;
110  vector<float> phiOfOneEdge_;
111  //wires
112  vector<float> wireSpacing_;
113  vector<float> wireAngle_;
114  //files
115  string infileName_;
116  string outfileName_;
118 };
119 
121  : tokCSC_{esConsumes<CSCGeometry, MuonGeometryRecord>(edm::ESInputTag{})},
122  infileName_(iConfig.getUntrackedParameter<string>("infileName", "cmsGeom10.root")),
123  outfileName_(iConfig.getUntrackedParameter<string>("outfileName", "validateCSCGeometry.root")),
124  tolerance_(iConfig.getUntrackedParameter<int>("tolerance", 6)) {
125  fwGeometry_.loadMap(infileName_.c_str());
126  outFile_ = TFile::Open(outfileName_.c_str(), "RECREATE");
127 }
128 
130  cscGeometry_ = &eventSetup.getData(tokCSC_);
131  LogVerbatim("CSCGeometry") << "Validating CSC chamber geometry";
134 }
135 
137  clearData();
138 
139  for (auto const& it : cscGeometry_->chambers()) {
140  CSCDetId chId = it->id();
141  GlobalPoint gp = it->surface().toGlobal(LocalPoint(0.0, 0.0, 0.0));
142 
143  const TGeoMatrix* matrix = fwGeometry_.getMatrix(chId.rawId());
144 
145  if (!matrix) {
146  LogVerbatim("CSCGeometry") << "Failed to get matrix of CSC chamber with detid: " << chId.rawId();
147  continue;
148  }
150 
151  auto const& shape = fwGeometry_.getShapePars(chId.rawId());
152 
153  if (!shape) {
154  LogVerbatim("CSCGeometry") << "Failed to get shape of CSC chamber with detid: " << chId.rawId();
155  continue;
156  }
157  compareShape(it, shape);
158  }
159  makeHistograms("CSC Chamber");
160 }
161 
163  clearData2();
164 
165  for (auto const& it : cscGeometry_->layers()) {
166  CSCDetId chId = it->id();
167  const CSCLayerGeometry* laygeo = it->geometry();
168  const int n_strips = laygeo->numberOfStrips();
169  const int n_wire = laygeo->numberOfWires();
170  const float strips_offset = laygeo->stripOffset();
171  const CSCStripTopology* stopo = laygeo->topology();
172  const float ycentre_of_strip_plane = stopo->yCentreOfStripPlane();
173  const float angular_width = stopo->angularWidth();
174  const float y_axis_orientation = stopo->yAxisOrientation();
175  const float centre_to_intersection = stopo->centreToIntersection();
176  const float phi_of_one_edge = stopo->phiOfOneEdge();
177  const float* parameters = fwGeometry_.getParameters(chId.rawId());
178  const CSCWireTopology* wiretopo = laygeo->wireTopology();
179  const double wire_spacing = wiretopo->wireSpacing();
180  const float wire_angle = wiretopo->wireAngle();
181 
182  if (n_strips) {
183  for (int istrips = 1; istrips <= n_strips; istrips++) {
184  yAxisOrientation_.push_back(fabs(y_axis_orientation - parameters[0]));
185  sOffset_.push_back(fabs(strips_offset - parameters[4]));
186  yCentreOfStripPlane_.push_back(fabs(ycentre_of_strip_plane - parameters[2]));
187  angularWidth_.push_back(fabs(angular_width - parameters[5]));
188  centreToIntersection_.push_back(fabs(centre_to_intersection - parameters[1]));
189  phiOfOneEdge_.push_back(fabs(phi_of_one_edge - parameters[3]));
190  }
191  } else {
192  LogVerbatim("CSCGeometry") << "ATTENTION! nStrips == 0";
193  }
194 
195  if (n_wire) {
196  for (int iwires = 1; iwires <= n_wire; iwires++) {
197  wireSpacing_.push_back(fabs(wire_spacing - parameters[6]));
198  wireAngle_.push_back(fabs(wire_angle - parameters[7]));
199  }
200  } else {
201  LogVerbatim("CSCGeometry") << "ATTENTION! nWires == 0";
202  }
203  }
204  makeHistograms2("CSC Layer");
205 }
206 
208  double local[3] = {0.0, 0.0, 0.0};
209  double global[3];
210 
211  matrix->LocalToMaster(local, global);
212 
213  float distance = getDistance(GlobalPoint(global[0], global[1], global[2]), gp);
214  if ((distance >= 0.0) && (distance < 1.0e-7))
215  distance = 0.0; // set a tollerance for the distance inside Histos
216  globalDistances_.push_back(distance);
217 }
218 
219 void CSCGeometryValidate::compareShape(const GeomDet* det, const float* shape) {
220  float shapeTopWidth;
221  float shapeBottomWidth;
222  float shapeLength;
223  float shapeThickness;
224 
225  if (shape[0] == 1) {
226  shapeTopWidth = shape[2];
227  shapeBottomWidth = shape[1];
228  shapeLength = shape[4];
229  shapeThickness = shape[3];
230  } else if (shape[0] == 2) {
231  shapeTopWidth = shape[1];
232  shapeBottomWidth = shape[1];
233  shapeLength = shape[2];
234  shapeThickness = shape[3];
235  } else {
236  LogVerbatim("CSCGeometry") << "Failed to get box or trapezoid from shape";
237 
238  return;
239  }
240 
241  float topWidth, bottomWidth;
242  float length, thickness;
243 
244  const Bounds* bounds = &(det->surface().bounds());
245  if (const TrapezoidalPlaneBounds* tpbs = dynamic_cast<const TrapezoidalPlaneBounds*>(bounds)) {
246  array<const float, 4> const& ps = tpbs->parameters();
247 
248  assert(ps.size() == 4);
249 
250  bottomWidth = ps[0];
251  topWidth = ps[1];
252  thickness = ps[2];
253  length = ps[3];
254  } else if ((dynamic_cast<const RectangularPlaneBounds*>(bounds))) {
255  length = det->surface().bounds().length() * 0.5;
256  topWidth = det->surface().bounds().width() * 0.5;
257  bottomWidth = topWidth;
258  thickness = det->surface().bounds().thickness() * 0.5;
259  } else {
260  LogVerbatim("CSCGeometry") << "Failed to get bounds";
261 
262  return;
263  }
264  topWidths_.push_back(fabs(shapeTopWidth - topWidth));
265  bottomWidths_.push_back(fabs(shapeBottomWidth - bottomWidth));
266  lengths_.push_back(fabs(shapeLength - length));
267  thicknesses_.push_back(fabs(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 CSCGeometryValidate::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 Y Axis Orientation of the Strips";
310 
311  string pi = d + ": absolute difference between Strips Offset";
313 
314  string pl = d + ": absolute difference between 'Y centre' of the Strips Planes";
316 
317  string aw = d + ": absolute difference between 'angular width' of the Strips ";
319 
320  string ci = d + ": absolute difference between 'centre to intersection' of the Strips ";
322 
323  string po = d + ": absolute difference between 'phi of one edge' of the Strips ";
325 
326  string ws = d + ": absolute difference between 'wire spacing' of the Wires ";
328 
329  string wa = d + ": absolute difference between 'wire angle' of the Wires ";
331 }
332 
333 void CSCGeometryValidate::makeHistogram(const string& name, vector<float>& data) {
334  if (data.empty())
335  return;
336 
337  const auto [minE, maxE] = minmax_element(begin(data), end(data));
338 
339  TH1D hist(name.c_str(), name.c_str(), 100, *minE * (1 + 0.10), *maxE * (1 + 0.10));
340 
341  for (auto const& it : data)
342  hist.Fill(it);
343 
344  hist.GetXaxis()->SetTitle("[cm]");
345  hist.Write();
346 }
347 
349 
351  LogVerbatim("CSCGeometry") << "Done.";
352  LogVerbatim("CSCGeometry") << "Results written to " << outfileName_;
353  outFile_->Close();
354 }
355 
CSCGeometryValidate::yAxisOrientation_
vector< float > yAxisOrientation_
Definition: CSCGeometryValidate.cc:105
CSCGeometryValidate::wireSpacing_
vector< float > wireSpacing_
Definition: CSCGeometryValidate.cc:112
bk::beginJob
void beginJob()
Definition: Breakpoints.cc:14
HLT_FULL_cff.maxE
maxE
Definition: HLT_FULL_cff.py:13661
BeamSpotPI::parameters
parameters
Definition: BeamSpotPayloadInspectorHelper.h:30
EDAnalyzer.h
CSCGeometryValidate::phiOfOneEdge_
vector< float > phiOfOneEdge_
Definition: CSCGeometryValidate.cc:110
edm::ESInputTag
Definition: ESInputTag.h:87
CSCGeometryValidate::globalDistances_
vector< float > globalDistances_
Definition: CSCGeometryValidate.cc:99
FWGeometry
Definition: FWGeometry.h:27
Bounds::width
virtual float width() const =0
MessageLogger.h
GeomDet
Definition: GeomDet.h:27
makeMuonMisalignmentScenario.matrix
list matrix
Definition: makeMuonMisalignmentScenario.py:141
CSCWireTopology::wireAngle
float wireAngle() const override
Definition: CSCWireTopology.h:70
CSCLayerGeometry::numberOfWires
int numberOfWires() const
Definition: CSCLayerGeometry.h:71
min
T min(T a, T b)
Definition: MathUtil.h:58
edm
HLT enums.
Definition: AlignableModifier.h:19
CSCGeometryValidate::infileName_
string infileName_
Definition: CSCGeometryValidate.cc:115
CSCRadialStripTopology::angularWidth
float angularWidth() const override
Definition: CSCRadialStripTopology.h:159
FWGeometry::getShapePars
const float * getShapePars(unsigned int id) const
Definition: FWGeometry.cc:489
CSCGeometryValidate::validateCSCLayerGeometry
void validateCSCLayerGeometry()
Definition: CSCGeometryValidate.cc:162
Bounds
Definition: Bounds.h:18
cms::cuda::assert
assert(be >=bs)
CSCGeometryValidate::makeHistograms2
void makeHistograms2(const char *)
Definition: CSCGeometryValidate.cc:303
CSCGeometryValidate::compareTransform
void compareTransform(const GlobalPoint &, const TGeoMatrix *)
Definition: CSCGeometryValidate.cc:207
CSCGeometryValidate::bottomWidths_
vector< float > bottomWidths_
Definition: CSCGeometryValidate.cc:101
gpuVertexFinder::ws
auto &__restrict__ ws
Definition: gpuClusterTracksDBSCAN.h:32
edm::one::EDAnalyzer
Definition: EDAnalyzer.h:30
StripTopology.h
align::LocalPoint
Point3DBase< Scalar, LocalTag > LocalPoint
Definition: Definitions.h:30
CSCGeometryValidate::fwGeometry_
FWGeometry fwGeometry_
Definition: CSCGeometryValidate.cc:96
CSCGeometryValidate::~CSCGeometryValidate
~CSCGeometryValidate() override
Definition: CSCGeometryValidate.cc:55
CSCGeometryValidate::outfileName_
string outfileName_
Definition: CSCGeometryValidate.cc:116
CSCGeometryValidate::thicknesses_
vector< float > thicknesses_
Definition: CSCGeometryValidate.cc:103
CSCRadialStripTopology::centreToIntersection
float centreToIntersection() const override
Definition: CSCRadialStripTopology.h:181
CSCGeometryValidate::outFile_
TFile * outFile_
Definition: CSCGeometryValidate.cc:97
geometryDiff.epsilon
int epsilon
Definition: geometryDiff.py:26
Bounds::length
virtual float length() const =0
CSCRadialStripTopology::yCentreOfStripPlane
float yCentreOfStripPlane() const override
Definition: CSCRadialStripTopology.h:223
CSCGeometryValidate::compareShape
void compareShape(const GeomDet *, const float *)
Definition: CSCGeometryValidate.cc:219
CSCGeometry
Definition: CSCGeometry.h:24
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
CSCGeometryValidate::lengths_
vector< float > lengths_
Definition: CSCGeometryValidate.cc:102
CSCGeometryValidate::centreToIntersection_
vector< float > centreToIntersection_
Definition: CSCGeometryValidate.cc:109
FWGeometry::getMatrix
const TGeoMatrix * getMatrix(unsigned int id) const
Definition: FWGeometry.cc:225
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
CSCGeometryValidate::topWidths_
vector< float > topWidths_
Definition: CSCGeometryValidate.cc:100
TrapezoidalPlaneBounds.h
Calorimetry_cff.thickness
thickness
Definition: Calorimetry_cff.py:115
CSCLayerGeometry
Definition: CSCLayerGeometry.h:25
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
CSCGeometryValidate::tolerance_
int tolerance_
Definition: CSCGeometryValidate.cc:117
Surface::bounds
const Bounds & bounds() const
Definition: Surface.h:87
mps_fire.end
end
Definition: mps_fire.py:242
CSCLayerGeometry::topology
const CSCStripTopology * topology() const
Definition: CSCLayerGeometry.h:272
CSCGeometryValidate::clearData2
void clearData2()
Definition: CSCGeometryValidate.cc:83
p2
double p2[4]
Definition: TauolaWrapper.h:90
CSCLayerGeometry.h
RectangularPlaneBounds.h
CSCGeometryValidate::cscGeometry_
const CSCGeometry * cscGeometry_
Definition: CSCGeometryValidate.cc:95
CSCGeometryValidate::yCentreOfStripPlane_
vector< float > yCentreOfStripPlane_
Definition: CSCGeometryValidate.cc:107
GlobalPoint
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
Point3DBase< float, GlobalTag >
CSCSkim_cfi.makeHistograms
makeHistograms
Definition: CSCSkim_cfi.py:15
CSCGeometryValidate
Definition: CSCGeometryValidate.cc:52
runTauDisplay.gp
gp
Definition: runTauDisplay.py:431
FWGeometry.h
Bounds::thickness
virtual float thickness() const =0
edm::ParameterSet
Definition: ParameterSet.h:47
almost_equal
enable_if<!numeric_limits< T >::is_integer, bool >::type almost_equal(T x, T y, int ulp)
Definition: CSCGeometryValidate.cc:42
CSCGeometryValidate::angularWidth_
vector< float > angularWidth_
Definition: CSCGeometryValidate.cc:108
CSCGeometryValidate::endJob
void endJob() override
Definition: CSCGeometryValidate.cc:350
CSCWireTopology.h
type
type
Definition: SiPixelVCal_PayloadInspector.cc:39
gpuVertexFinder::hist
__shared__ Hist hist
Definition: gpuClusterTracksDBSCAN.h:48
CSCDetId
Definition: CSCDetId.h:26
CSCGeometryValidate::clearData
void clearData()
Definition: CSCGeometryValidate.cc:75
CSCRadialStripTopology::yAxisOrientation
float yAxisOrientation() const override
Definition: CSCRadialStripTopology.h:218
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
CSCGeometryValidate::makeHistograms
void makeHistograms(const char *)
Definition: CSCGeometryValidate.cc:282
TrapezoidalPlaneBounds
Definition: TrapezoidalPlaneBounds.h:15
edm::ESGetToken< CSCGeometry, MuonGeometryRecord >
CSCGeometryValidate::getDistance
float getDistance(const GlobalPoint &, const GlobalPoint &)
Definition: CSCGeometryValidate.cc:270
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:127
CSCGeometryValidate::validateCSCChamberGeometry
void validateCSCChamberGeometry()
Definition: CSCGeometryValidate.cc:136
CSCGeometryValidate::sOffset_
vector< float > sOffset_
Definition: CSCGeometryValidate.cc:106
CSCStripTopology
Definition: CSCStripTopology.h:28
CSCGeometryValidate::makeHistogram
void makeHistogram(const string &, vector< float > &)
Definition: CSCGeometryValidate.cc:333
CSCGeometryValidate::getDiff
float getDiff(const float, const float)
Definition: CSCGeometryValidate.cc:275
std
Definition: JetResolutionObject.h:76
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
CSCGeometryValidate::tokCSC_
const edm::ESGetToken< CSCGeometry, MuonGeometryRecord > tokCSC_
Definition: CSCGeometryValidate.cc:94
CSCLayerGeometry::wireTopology
const CSCWireTopology * wireTopology() const
Definition: CSCLayerGeometry.h:282
CSCLayer.h
CSCStripTopology.h
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
T
long double T
Definition: Basic3DVectorLD.h:48
CSCGeometryValidate::CSCGeometryValidate
CSCGeometryValidate(const ParameterSet &)
Definition: CSCGeometryValidate.cc:120
CSCLayerGeometry::stripOffset
float stripOffset(void) const
Definition: CSCLayerGeometry.h:118
CSCWireTopology
Definition: CSCWireTopology.h:18
CSCGeometry::layers
const LayerContainer & layers() const
Return a vector of all layers.
Definition: CSCGeometry.cc:98
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
EventSetup.h
CSCRadialStripTopology::phiOfOneEdge
float phiOfOneEdge() const override
Definition: CSCRadialStripTopology.h:202
CSCGeometry::chambers
const ChamberContainer & chambers() const
Return a vector of all chambers.
Definition: CSCGeometry.cc:96
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
hgcalTestNeighbor_cfi.detector
detector
Definition: hgcalTestNeighbor_cfi.py:6
ztail.d
d
Definition: ztail.py:151
CSCGeometryValidate::wireAngle_
vector< float > wireAngle_
Definition: CSCGeometryValidate.cc:113
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
ParameterSet.h
MuonGeometryRecord.h
CSCGeometryValidate::beginJob
void beginJob() override
Definition: CSCGeometryValidate.cc:348
CSCLayerGeometry::numberOfStrips
int numberOfStrips() const
Definition: CSCLayerGeometry.h:66
CSCChamber.h
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
HLT_FULL_cff.distance
distance
Definition: HLT_FULL_cff.py:7746
CSCWireTopology::wireSpacing
double wireSpacing() const
Definition: CSCWireTopology.h:59
CSCGeometryValidate::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: CSCGeometryValidate.cc:129
CSCGeometry.h
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37