CMS 3D CMS Logo

RPCGeometryValidate.cc
Go to the documentation of this file.
1 /*
2 //\class RPCGeometryValidate
3 
4  Description: RPC 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: Fri, 20 Sep 2019
9 */
10 
16 
22 
24 
27 
28 #include <TFile.h>
29 #include <TH1.h>
30 
31 #include <limits>
32 #include <string>
33 #include <type_traits>
34 #include <algorithm>
35 
36 using namespace std;
37 
38 template <class T>
39 typename enable_if<!numeric_limits<T>::is_integer, bool>::type almost_equal(T x, T y, int ulp) {
40  // the machine epsilon has to be scaled to the magnitude of the values used
41  // and multiplied by the desired precision in ULPs (units in the last place)
42  return abs(x - y) <= numeric_limits<T>::epsilon() * abs(x + y) * ulp
43  // unless the result is subnormal
44  || abs(x - y) < numeric_limits<T>::min();
45 }
46 
47 using namespace edm;
48 
50 public:
51  explicit RPCGeometryValidate(const ParameterSet&);
52  ~RPCGeometryValidate() override {}
53 
54 private:
55  void beginJob() override;
56  void analyze(const edm::Event&, const edm::EventSetup&) override;
57  void endJob() override;
58 
59  void validateRPCChamberGeometry();
60  void validateRPCStripsGeometry();
61 
62  void compareTransform(const GlobalPoint&, const TGeoMatrix*);
63  void compareShape(const GeomDet*, const float*);
64 
65  float getDistance(const GlobalPoint&, const GlobalPoint&);
66  float getDiff(const float, const float);
67 
68  void makeHistograms(const char*);
69  void makeHistograms2(const char*);
70  void makeHistogram(const string&, vector<float>&);
71 
72  void clearData() {
73  globalDistances_.clear();
74  topWidths_.clear();
75  bottomWidths_.clear();
76  lengths_.clear();
77  thicknesses_.clear();
78  }
79 
80  void clearData2() {
81  nstrips_.clear();
82  pitch_.clear();
83  stripslen_.clear();
84  }
85 
89  TFile* outFile_;
90  vector<float> globalDistances_;
91  vector<float> topWidths_;
92  vector<float> bottomWidths_;
93  vector<float> lengths_;
94  vector<float> thicknesses_;
95  vector<float> nstrips_;
96  vector<float> pitch_;
97  vector<float> stripslen_;
98  string infileName_;
99  string outfileName_;
101 };
102 
104  : tokRPC_{esConsumes<RPCGeometry, MuonGeometryRecord>(edm::ESInputTag{})},
105  infileName_(iConfig.getUntrackedParameter<string>("infileName", "cmsGeom10.root")),
106  outfileName_(iConfig.getUntrackedParameter<string>("outfileName", "validateRPCGeometry.root")),
107  tolerance_(iConfig.getUntrackedParameter<int>("tolerance", 6)) {
108  fwGeometry_.loadMap(infileName_.c_str());
109  outFile_ = new TFile(outfileName_.c_str(), "RECREATE");
110 }
111 
113  rpcGeometry_ = &eventSetup.getData(tokRPC_);
114  LogVerbatim("RPCGeometry") << "Validating RPC chamber geometry";
117 }
118 
120  clearData();
121 
122  for (auto const& it : rpcGeometry_->rolls()) {
123  RPCDetId chId = it->id();
124  GlobalPoint gp = it->surface().toGlobal(LocalPoint(0.0, 0.0, 0.0));
125 
126  const TGeoMatrix* matrix = fwGeometry_.getMatrix(chId.rawId());
127 
128  if (!matrix) {
129  LogVerbatim("RPCGeometry") << "Failed to get matrix of RPC chamber with detid: " << chId.rawId();
130  continue;
131  }
133 
134  auto const& shape = fwGeometry_.getShapePars(chId.rawId());
135 
136  if (!shape) {
137  LogVerbatim("RPCGeometry") << "Failed to get shape of RPC chamber with detid: " << chId.rawId();
138  continue;
139  }
140  compareShape(it, shape);
141  }
142  makeHistograms("RPC Chamber");
143 }
144 
146  clearData2();
147 
148  for (auto const& it : rpcGeometry_->rolls()) {
149  RPCDetId chId = it->id();
150  const int n_strips = it->nstrips();
151  const float n_pitch = it->pitch();
152  const StripTopology& topo = it->specificTopology();
153  const float stripLen = topo.stripLength();
154  const float* parameters = fwGeometry_.getParameters(chId.rawId());
155 
156  if (n_strips) {
157  for (int istrips = 1; istrips <= n_strips; istrips++) {
158  nstrips_.push_back(fabs(n_strips - parameters[0]));
159  pitch_.push_back(fabs(n_pitch - parameters[2]));
160  stripslen_.push_back(fabs(stripLen - parameters[1]));
161  }
162  } else {
163  LogVerbatim("RPCGeometry") << "ATTENTION! nStrips == 0";
164  }
165  }
166  makeHistograms2("RPC Strips");
167 }
168 
170  double local[3] = {0.0, 0.0, 0.0};
171  double global[3];
172 
173  matrix->LocalToMaster(local, global);
174 
175  float distance = getDistance(GlobalPoint(global[0], global[1], global[2]), gp);
176  if ((distance >= 0.0) && (distance < 1.0e-7))
177  distance = 0.0; // set a tollerance for the distance inside Histos
178  globalDistances_.push_back(distance);
179 }
180 
181 void RPCGeometryValidate::compareShape(const GeomDet* det, const float* shape) {
182  float shapeTopWidth;
183  float shapeBottomWidth;
184  float shapeLength;
185  float shapeThickness;
186 
187  if (shape[0] == 1) {
188  shapeTopWidth = shape[2];
189  shapeBottomWidth = shape[1];
190  shapeLength = shape[4];
191  shapeThickness = shape[3];
192  } else if (shape[0] == 2) {
193  shapeTopWidth = shape[1];
194  shapeBottomWidth = shape[1];
195  shapeLength = shape[2];
196  shapeThickness = shape[3];
197  } else {
198  LogVerbatim("RPCGeometry") << "Failed to get box or trapezoid from shape";
199 
200  return;
201  }
202 
203  float topWidth, bottomWidth;
204  float length, thickness;
205 
206  const Bounds* bounds = &(det->surface().bounds());
207  if (const TrapezoidalPlaneBounds* tpbs = dynamic_cast<const TrapezoidalPlaneBounds*>(bounds)) {
208  array<const float, 4> const& ps = tpbs->parameters();
209 
210  assert(ps.size() == 4);
211 
212  bottomWidth = ps[0];
213  topWidth = ps[1];
214  thickness = ps[2];
215  length = ps[3];
216  } else if ((dynamic_cast<const RectangularPlaneBounds*>(bounds))) {
217  length = det->surface().bounds().length() * 0.5;
218  topWidth = det->surface().bounds().width() * 0.5;
219  bottomWidth = topWidth;
220  thickness = det->surface().bounds().thickness() * 0.5;
221  } else {
222  LogVerbatim("RPCGeometry") << "Failed to get bounds";
223 
224  return;
225  }
226  topWidths_.push_back(fabs(shapeTopWidth - topWidth));
227  bottomWidths_.push_back(fabs(shapeBottomWidth - bottomWidth));
228  lengths_.push_back(fabs(shapeLength - length));
229  thicknesses_.push_back(fabs(shapeThickness - thickness));
230 }
231 
233  return sqrt((p1.x() - p2.x()) * (p1.x() - p2.x()) + (p1.y() - p2.y()) * (p1.y() - p2.y()) +
234  (p1.z() - p2.z()) * (p1.z() - p2.z()));
235 }
236 
237 float RPCGeometryValidate::getDiff(const float val1, const float val2) {
238  if (almost_equal(val1, val2, tolerance_))
239  return 0.0f;
240  else
241  return (val1 - val2);
242 }
243 
245  outFile_->cd();
246 
247  string d(detector);
248 
249  string gdn = d + ": distance between points in global coordinates";
251 
252  string twn = d + ": absolute difference between top widths (along X)";
254 
255  string bwn = d + ": absolute difference between bottom widths (along X)";
257 
258  string ln = d + ": absolute difference between lengths (along Y)";
259  makeHistogram(ln, lengths_);
260 
261  string tn = d + ": absolute difference between thicknesses (along Z)";
263 }
264 
266  outFile_->cd();
267 
268  string d(detector);
269 
270  string ns = d + ": absolute difference between nStrips";
271  makeHistogram(ns, nstrips_);
272 
273  string pi = d + ": absolute difference between Strips Pitch";
275 
276  string pl = d + ": absolute difference between Strips Length";
278 }
279 
280 void RPCGeometryValidate::makeHistogram(const string& name, vector<float>& data) {
281  if (data.empty())
282  return;
283 
284  const auto [minE, maxE] = minmax_element(begin(data), end(data));
285 
286  TH1D hist(name.c_str(), name.c_str(), 100, *minE * (1 + 0.10), *maxE * (1 + 0.10));
287 
288  for (auto const& it : data)
289  hist.Fill(it);
290 
291  hist.GetXaxis()->SetTitle("[cm]");
292  hist.Write();
293 }
294 
296 
298  LogVerbatim("RPCGeometry") << "Done.";
299  LogVerbatim("RPCGeometry") << "Results written to " << outfileName_;
300  outFile_->Close();
301 }
302 
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
RPCGeometryValidate::pitch_
vector< float > pitch_
Definition: RPCGeometryValidate.cc:96
EDAnalyzer.h
edm::ESInputTag
Definition: ESInputTag.h:87
RPCGeometryValidate::outFile_
TFile * outFile_
Definition: RPCGeometryValidate.cc:89
RPCGeometryValidate::endJob
void endJob() override
Definition: RPCGeometryValidate.cc:297
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
min
T min(T a, T b)
Definition: MathUtil.h:58
edm
HLT enums.
Definition: AlignableModifier.h:19
RPCDetId
Definition: RPCDetId.h:16
RPCChamber.h
RPCGeometryValidate::clearData
void clearData()
Definition: RPCGeometryValidate.cc:72
RPCGeometryValidate::compareTransform
void compareTransform(const GlobalPoint &, const TGeoMatrix *)
Definition: RPCGeometryValidate.cc:169
FWGeometry::getShapePars
const float * getShapePars(unsigned int id) const
Definition: FWGeometry.cc:489
Bounds
Definition: Bounds.h:18
cms::cuda::assert
assert(be >=bs)
RPCRoll.h
edm::one::EDAnalyzer
Definition: EDAnalyzer.h:30
StripTopology.h
align::LocalPoint
Point3DBase< Scalar, LocalTag > LocalPoint
Definition: Definitions.h:30
RPCGeometryValidate::tolerance_
int tolerance_
Definition: RPCGeometryValidate.cc:100
RPCGeometryValidate::outfileName_
string outfileName_
Definition: RPCGeometryValidate.cc:99
geometryDiff.epsilon
int epsilon
Definition: geometryDiff.py:26
Bounds::length
virtual float length() const =0
RPCGeometryValidate::clearData2
void clearData2()
Definition: RPCGeometryValidate.cc:80
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
RPCGeometryValidate::nstrips_
vector< float > nstrips_
Definition: RPCGeometryValidate.cc:95
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
TrapezoidalPlaneBounds.h
Calorimetry_cff.thickness
thickness
Definition: Calorimetry_cff.py:115
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
Surface::bounds
const Bounds & bounds() const
Definition: Surface.h:87
RPCGeometryValidate::topWidths_
vector< float > topWidths_
Definition: RPCGeometryValidate.cc:91
mps_fire.end
end
Definition: mps_fire.py:242
p2
double p2[4]
Definition: TauolaWrapper.h:90
RectangularPlaneBounds.h
GlobalPoint
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
RPCGeometryValidate::lengths_
vector< float > lengths_
Definition: RPCGeometryValidate.cc:93
RPCGeometryValidate::compareShape
void compareShape(const GeomDet *, const float *)
Definition: RPCGeometryValidate.cc:181
Point3DBase< float, GlobalTag >
RPCGeometryValidate::~RPCGeometryValidate
~RPCGeometryValidate() override
Definition: RPCGeometryValidate.cc:52
CSCSkim_cfi.makeHistograms
makeHistograms
Definition: CSCSkim_cfi.py:15
RPCGeometryValidate::fwGeometry_
FWGeometry fwGeometry_
Definition: RPCGeometryValidate.cc:88
runTauDisplay.gp
gp
Definition: runTauDisplay.py:431
FWGeometry.h
Bounds::thickness
virtual float thickness() const =0
StripTopology::stripLength
virtual float stripLength() const =0
RPCGeometryValidate::rpcGeometry_
const RPCGeometry * rpcGeometry_
Definition: RPCGeometryValidate.cc:87
edm::ParameterSet
Definition: ParameterSet.h:47
RPCGeometryValidate::makeHistogram
void makeHistogram(const string &, vector< float > &)
Definition: RPCGeometryValidate.cc:280
type
type
Definition: SiPixelVCal_PayloadInspector.cc:39
gpuVertexFinder::hist
__shared__ Hist hist
Definition: gpuClusterTracksDBSCAN.h:48
RPCGeometryValidate::validateRPCStripsGeometry
void validateRPCStripsGeometry()
Definition: RPCGeometryValidate.cc:145
RPCGeometryValidate::globalDistances_
vector< float > globalDistances_
Definition: RPCGeometryValidate.cc:90
p1
double p1[4]
Definition: TauolaWrapper.h:89
analyze
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
RPCGeometryValidate::stripslen_
vector< float > stripslen_
Definition: RPCGeometryValidate.cc:97
edm::EventSetup
Definition: EventSetup.h:58
TrapezoidalPlaneBounds
Definition: TrapezoidalPlaneBounds.h:15
edm::ESGetToken< RPCGeometry, MuonGeometryRecord >
RPCGeometryValidate::bottomWidths_
vector< float > bottomWidths_
Definition: RPCGeometryValidate.cc:92
RPCGeometryValidate::getDistance
float getDistance(const GlobalPoint &, const GlobalPoint &)
Definition: RPCGeometryValidate.cc:232
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:127
std
Definition: JetResolutionObject.h:76
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
RPCGeometryValidate::validateRPCChamberGeometry
void validateRPCChamberGeometry()
Definition: RPCGeometryValidate.cc:119
RPCGeometryValidate::RPCGeometryValidate
RPCGeometryValidate(const ParameterSet &)
Definition: RPCGeometryValidate.cc:103
RPCGeometryValidate::makeHistograms2
void makeHistograms2(const char *)
Definition: RPCGeometryValidate.cc:265
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
T
long double T
Definition: Basic3DVectorLD.h:48
RPCGeometryValidate::infileName_
string infileName_
Definition: RPCGeometryValidate.cc:98
RPCGeometryValidate::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: RPCGeometryValidate.cc:112
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
EventSetup.h
RPCGeometryValidate::beginJob
void beginJob() override
Definition: RPCGeometryValidate.cc:295
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
RPCGeometryValidate
Definition: RPCGeometryValidate.cc:49
RPCGeometryValidate::tokRPC_
const edm::ESGetToken< RPCGeometry, MuonGeometryRecord > tokRPC_
Definition: RPCGeometryValidate.cc:86
hgcalTestNeighbor_cfi.detector
detector
Definition: hgcalTestNeighbor_cfi.py:6
ztail.d
d
Definition: ztail.py:151
RPCGeometry
Definition: RPCGeometry.h:20
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
RPCGeometryValidate::getDiff
float getDiff(const float, const float)
Definition: RPCGeometryValidate.cc:237
RPCGeometry::rolls
const std::vector< const RPCRoll * > & rolls() const
Return a vector of all RPC rolls.
Definition: RPCGeometry.cc:44
ParameterSet.h
MuonGeometryRecord.h
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
HLT_FULL_cff.distance
distance
Definition: HLT_FULL_cff.py:7746
RPCGeometryValidate::makeHistograms
void makeHistograms(const char *)
Definition: RPCGeometryValidate.cc:244
StripTopology
Definition: StripTopology.h:11
RPCGeometry.h
almost_equal
enable_if<!numeric_limits< T >::is_integer, bool >::type almost_equal(T x, T y, int ulp)
Definition: RPCGeometryValidate.cc:39
RPCGeometryValidate::thicknesses_
vector< float > thicknesses_
Definition: RPCGeometryValidate.cc:94
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37