106 std::map<std::string,const MuonGeometrySanityCheckCustomFrame*>
m_frames;
107 std::vector<MuonGeometrySanityCheckPoint>
m_points;
125 throw cms::Exception(
"BadConfig") <<
"Printout must be \"all\" or \"bad\"." << std::endl;
130 throw cms::Exception(
"BadConfig") <<
"Tolerance must be positive." << std::endl;
135 std::vector<edm::ParameterSet> frames = iConfig.
getParameter<std::vector<edm::ParameterSet> >(
"frames");
136 for (std::vector<edm::ParameterSet>::const_iterator frame = frames.begin(); frame != frames.end(); ++frame) {
138 if (m_frames.find(name) != m_frames.end()) {
139 throw cms::Exception(
"BadConfig") <<
"Custom frame \"" << name <<
"\" has been defined twice." << std::endl;
144 std::vector<edm::ParameterSet>
points = iConfig.
getParameter<std::vector<edm::ParameterSet> >(
"points");
145 for (std::vector<edm::ParameterSet>::const_iterator
point = points.begin();
point != points.end(); ++
point) {
151 for (std::map<std::string,const MuonGeometrySanityCheckCustomFrame*>::iterator iter = m_frames.begin(); iter != m_frames.end(); ++iter) {
157 std::vector<double> numbers = iConfig.
getParameter<std::vector<double> >(
"matrix");
158 if (numbers.size() != 9) {
159 throw cms::Exception(
"BadConfig") <<
"Custom frame \"" << name <<
"\" has a matrix which is not 3x3." << std::endl;
163 matrix[0][0] = numbers[0];
164 matrix[0][1] = numbers[1];
165 matrix[0][2] = numbers[2];
166 matrix[1][0] = numbers[3];
167 matrix[1][1] = numbers[4];
168 matrix[1][2] = numbers[5];
169 matrix[2][0] = numbers[6];
170 matrix[2][1] = numbers[7];
171 matrix[2][2] = numbers[8];
177 throw cms::Exception(
"BadConfig") <<
"Could not invert matrix for custom frame \"" << name <<
"\"." << std::endl;
183 input[0] = point.
x();
184 input[1] = point.
x();
185 input[2] = point.
x();
187 return GlobalPoint(output[0], output[1], output[3]);
192 input[0] = point.
x();
193 input[1] = point.
x();
194 input[2] = point.
x();
196 return GlobalPoint(output[0], output[1], output[3]);
221 bool parsing_error =
false;
225 if (!barrel && !endcap) parsing_error =
true;
227 if (!parsing_error && barrel) {
231 if (detName.substr(index, 1) ==
std::string(
"+")) {
235 else if (detName.substr(index, 1) ==
std::string(
"-")) {
241 bool wheel_digit =
false;
242 while (!parsing_error && numeric(detName.substr(index, 1))) {
244 wheel += number(detName.substr(index, 1));
248 if (!plus) wheel *= -1;
249 if (!wheel_digit) parsing_error =
true;
251 if (detName.substr(index, 1) !=
std::string(
"/")) parsing_error =
true;
255 bool station_digit =
false;
256 while (!parsing_error && numeric(detName.substr(index, 1))) {
258 station += number(detName.substr(index, 1));
259 station_digit =
true;
262 if (!station_digit) parsing_error =
true;
264 if (detName.substr(index, 1) !=
std::string(
"/")) parsing_error =
true;
268 bool sector_digit =
false;
269 while (!parsing_error && numeric(detName.substr(index, 1))) {
271 sector += number(detName.substr(index, 1));
275 if (!sector_digit) parsing_error =
true;
279 bool superlayer_digit =
false;
281 if (detName.substr(index, 1) ==
std::string(
"/")) {
283 while (!parsing_error && numeric(detName.substr(index, 1))) {
285 superlayer += number(detName.substr(index, 1));
286 superlayer_digit =
true;
289 if (!superlayer_digit) parsing_error =
true;
291 if (detName.substr(index, 1) ==
std::string(
"/")) {
293 while (!parsing_error && numeric(detName.substr(index, 1))) {
295 layer += number(detName.substr(index, 1));
301 if (!parsing_error) {
302 bool no_such_chamber =
false;
304 if (wheel < -2 || wheel > 2) no_such_chamber =
true;
305 if (station < 1 || station > 4) no_such_chamber =
true;
306 if (station == 4 && (sector < 1 || sector > 14)) no_such_chamber =
true;
307 if (station < 4 && (sector < 1 || sector > 12)) no_such_chamber =
true;
309 if (no_such_chamber) {
310 throw cms::Exception(
"BadConfig") <<
"Chamber doesn't exist: MB" << (plus ?
"+" :
"-") << wheel <<
"/" << station <<
"/" << sector << std::endl;
313 if (superlayer == 0) {
318 bool no_such_superlayer =
false;
319 if (superlayer < 1 || superlayer > 3) no_such_superlayer =
true;
320 if (station == 4 && superlayer == 2) no_such_superlayer =
true;
322 if (no_such_superlayer) {
323 throw cms::Exception(
"BadConfig") <<
"Superlayer doesn't exist: MB" << (plus ?
"+" :
"-") << wheel <<
"/" << station <<
"/" << sector <<
"/" << superlayer << std::endl;
328 type = kDTSuperLayer;
331 bool no_such_layer =
false;
332 if (layer < 1 || layer > 4) no_such_layer =
true;
335 throw cms::Exception(
"BadConfig") <<
"Layer doesn't exist: MB" << (plus ?
"+" :
"-") << wheel <<
"/" << station <<
"/" << sector <<
"/" << superlayer <<
"/" << layer << std::endl;
344 else if (!parsing_error && endcap) {
348 if (detName.substr(index, 1) ==
std::string(
"+")) {
352 else if (detName.substr(index, 1) ==
std::string(
"-")) {
356 else parsing_error =
true;
359 bool station_digit =
false;
360 while (!parsing_error && numeric(detName.substr(index, 1))) {
362 station += number(detName.substr(index, 1));
363 station_digit =
true;
366 if (!plus) station *= -1;
367 if (!station_digit) parsing_error =
true;
369 if (detName.substr(index, 1) !=
std::string(
"/")) parsing_error =
true;
373 bool ring_digit =
false;
374 while (!parsing_error && numeric(detName.substr(index, 1))) {
376 ring += number(detName.substr(index, 1));
380 if (!ring_digit) parsing_error =
true;
382 if (detName.substr(index, 1) !=
std::string(
"/")) parsing_error =
true;
386 bool chamber_digit =
false;
387 while (!parsing_error && numeric(detName.substr(index, 1))) {
389 chamber += number(detName.substr(index, 1));
390 chamber_digit =
true;
393 if (!chamber_digit) parsing_error =
true;
397 bool layer_digit =
false;
398 if (detName.substr(index, 1) ==
std::string(
"/")) {
400 while (!parsing_error && numeric(detName.substr(index, 1))) {
402 layer += number(detName.substr(index, 1));
406 if (!layer_digit) parsing_error =
true;
409 if (!parsing_error) {
410 bool no_such_chamber =
false;
412 int endcap = (station > 0 ? 1 : 2);
413 station =
abs(station);
414 if (station < 1 || station > 4) no_such_chamber =
true;
415 if (station == 1 && (ring < 1 || ring > 4)) no_such_chamber =
true;
416 if (station > 1 && (ring < 1 || ring > 2)) no_such_chamber =
true;
417 if (station == 1 && (chamber < 1 || chamber > 36)) no_such_chamber =
true;
418 if (station > 1 && ring == 1 && (chamber < 1 || chamber > 18)) no_such_chamber =
true;
419 if (station > 1 && ring == 2 && (chamber < 1 || chamber > 36)) no_such_chamber =
true;
421 if (no_such_chamber) {
422 throw cms::Exception(
"BadConfig") <<
"Chamber doesn't exist: ME" << (endcap == 1 ?
"+" :
"-") << station <<
"/" << ring <<
"/" << chamber << std::endl;
430 bool no_such_layer =
false;
431 if (layer < 1 || layer > 6) no_such_layer =
true;
434 throw cms::Exception(
"BadConfig") <<
"Layer doesn't exist: ME" << (endcap == 1 ?
"+" :
"-") << station <<
"/" << ring <<
"/" << chamber <<
"/" << layer << std::endl;
444 throw cms::Exception(
"BadConfig") <<
"Detector name is malformed: " << detName << std::endl;
448 const std::map<std::string,const MuonGeometrySanityCheckCustomFrame*>::const_iterator frameIter = frames.find(frameName);
451 customFrame =
nullptr;
455 customFrame =
nullptr;
459 customFrame =
nullptr;
461 else if (frameIter != frames.end()) {
463 customFrame = frameIter->second;
466 throw cms::Exception(
"BadConfig") <<
"Frame \"" << frameName <<
"\" has not been defined." << std::endl;
469 std::vector<double>
point = iConfig.
getParameter<std::vector<double> >(
"displacement");
470 if (point.size() != 3) {
471 throw cms::Exception(
"BadConfig") <<
"Displacement relative to detector " << detName <<
" doesn't have exactly three components." << std::endl;
474 displacement =
GlobalPoint(point[0], point[1], point[2]);
477 if (entry !=
nullptr) {
478 has_expectation =
true;
480 point = iConfig.
getParameter<std::vector<double> >(
"expectation");
481 if (point.size() != 3) {
482 throw cms::Exception(
"BadConfig") <<
"Expectation for detector " << detName <<
", displacement " << displacement <<
" doesn't have exactly three components." << std::endl;
485 expectation =
GlobalPoint(point[0], point[1], point[2]);
488 has_expectation =
false;
492 if (entry !=
nullptr) {
500 if (entry !=
nullptr) {
502 const std::map<std::string,const MuonGeometrySanityCheckCustomFrame*>::const_iterator frameIter = frames.find(frameName);
504 outputFrame = kGlobal;
505 outputCustomFrame =
nullptr;
508 outputFrame = kLocal;
509 outputCustomFrame =
nullptr;
512 outputFrame = kChamber;
513 outputCustomFrame =
nullptr;
515 else if (frameIter != frames.end()) {
516 outputFrame = kCustom;
517 outputCustomFrame = frameIter->second;
520 throw cms::Exception(
"BadConfig") <<
"Frame \"" << frameName <<
"\" has not been defined." << std::endl;
524 outputFrame = kGlobal;
525 outputCustomFrame =
nullptr;
531 if (
type == kDTChamber) {
533 output <<
"MB" << (
id.wheel() > 0 ?
"+" :
"") <<
id.
wheel() <<
"/" <<
id.station() <<
"/" <<
id.sector();
535 else if (
type == kDTSuperLayer) {
537 output <<
"MB" << (
id.wheel() > 0 ?
"+" :
"") <<
id.
wheel() <<
"/" <<
id.station() <<
"/" <<
id.sector() <<
"/" <<
id.superlayer();
539 else if (
type == kDTLayer) {
541 output <<
"MB" << (
id.wheel() > 0 ?
"+" :
"") <<
id.
wheel() <<
"/" <<
id.station() <<
"/" <<
id.sector() <<
"/" <<
id.superlayer() <<
"/" <<
id.layer();
543 else if (
type == kCSCChamber) {
545 output <<
"ME" << (
id.endcap() == 1 ?
"+" :
"-") <<
id.
station() <<
"/" <<
id.ring() <<
"/" <<
id.chamber();
547 else if (
type == kCSCLayer) {
549 output <<
"ME" << (
id.endcap() == 1 ?
"+" :
"-") <<
id.
station() <<
"/" <<
id.ring() <<
"/" <<
id.chamber() <<
"/" <<
id.layer();
564 int num_transformed = 0;
567 for (std::vector<MuonGeometrySanityCheckPoint>::const_iterator
point = m_points.begin();
point != m_points.end(); ++
point) {
579 result =
GlobalPoint(chamberPos.
x() +
point->displacement.x(), chamberPos.
y() +
point->displacement.y(), chamberPos.
z() +
point->displacement.z());
599 else { assert(
false); }
604 result =
GlobalPoint(chamberPos.
x() + transformed.
x(), chamberPos.
y() + transformed.
y(), chamberPos.
z() + transformed.
z());
607 else { assert(
false); }
616 result =
GlobalPoint(transformed.
x(), transformed.
y(), transformed.
z());
625 result =
GlobalPoint(transformed.
x(), transformed.
y(), transformed.
z());
633 result =
GlobalPoint(transformed.x(), transformed.y(), transformed.z());
635 else { assert(
false); }
639 result =
point->outputCustomFrame->transformInverse(result);
643 output <<
prefix <<
" " <<
point->name <<
" " <<
point->detName() <<
" " << result.
x() <<
" " << result.
y() <<
" " << result.
z();
646 if (
point->has_expectation) {
648 double residx = result.
x() -
point->expectation.x();
649 double residy = result.
y() -
point->expectation.y();
650 double residz = result.
z() -
point->expectation.z();
655 output <<
" BAD " << residx <<
" " << residy <<
" " << residz << std::endl;
658 output <<
" GOOD " << residx <<
" " << residy <<
" " << residz << std::endl;
662 output <<
" UNTESTED 0 0 0" << std::endl;
670 std::cout << std::endl <<
"SUMMARY transformed: " << num_transformed <<
" tested: " << num_tested <<
" bad: " << num_bad <<
" good: " << (num_tested - num_bad) << std::endl;
std::vector< MuonGeometrySanityCheckPoint > m_points
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
T getParameter(std::string const &) const
std::string detName() const
void analyze(const edm::Event &, const edm::EventSetup &iConfig) override
Point3DBase< Scalar, LocalTag > LocalPoint
std::map< std::string, const MuonGeometrySanityCheckCustomFrame * > m_frames
virtual example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
const GeomDet * idToDet(DetId) const override
#define DEFINE_FWK_MODULE(type)
const MuonGeometrySanityCheckCustomFrame * outputCustomFrame
Global3DPoint GlobalPoint
int number(std::string s)
GlobalPoint transform(GlobalPoint point) const
const Plane & surface() const
The nominal surface of the GeomDet.
static std::string const input
AlgebraicMatrix matrixInverse
CLHEP::HepMatrix AlgebraicMatrix
LocalPoint toLocal(const GlobalPoint &gp) const
Abs< T >::type abs(const T &t)
MuonGeometrySanityCheckPoint(const edm::ParameterSet &iConfig, const std::map< std::string, const MuonGeometrySanityCheckCustomFrame * > &frames)
MuonGeometrySanityCheckCustomFrame(const edm::ParameterSet &iConfig, std::string name)
CLHEP::HepVector AlgebraicVector
GlobalPoint transformInverse(GlobalPoint point) const
const GeomDet * idToDet(DetId) const override
MuonGeometrySanityCheck(const edm::ParameterSet &iConfig)
Entry const * retrieveUnknown(char const *) const
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
bool numeric(std::string s)
const MuonGeometrySanityCheckCustomFrame * customFrame
~MuonGeometrySanityCheck() override