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) {
137 std::string
name = frame->getParameter<std::string>(
"name");
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]);
200 return (s == std::string(
"0") || s == std::string(
"1") || s == std::string(
"2") || s == std::string(
"3") || s == std::string(
"4") ||
201 s == std::string(
"5") || s == std::string(
"6") || s == std::string(
"7") || s == std::string(
"8") || s == std::string(
"9"));
205 if (s == std::string(
"0"))
return 0;
206 else if (s == std::string(
"1"))
return 1;
207 else if (s == std::string(
"2"))
return 2;
208 else if (s == std::string(
"3"))
return 3;
209 else if (s == std::string(
"4"))
return 4;
210 else if (s == std::string(
"5"))
return 5;
211 else if (s == std::string(
"6"))
return 6;
212 else if (s == std::string(
"7"))
return 7;
213 else if (s == std::string(
"8"))
return 8;
214 else if (s == std::string(
"9"))
return 9;
221 bool parsing_error =
false;
223 bool barrel = (detName.substr(0, 2) == std::string(
"MB"));
224 bool endcap = (detName.substr(0, 2) == std::string(
"ME"));
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 bool layer_digit =
false;
282 if (detName.substr(index, 1) == std::string(
"/")) {
284 while (!parsing_error &&
numeric(detName.substr(index, 1))) {
286 superlayer +=
number(detName.substr(index, 1));
287 superlayer_digit =
true;
290 if (!superlayer_digit) parsing_error =
true;
292 if (detName.substr(index, 1) == std::string(
"/")) {
294 while (!parsing_error &&
numeric(detName.substr(index, 1))) {
296 layer +=
number(detName.substr(index, 1));
303 if (!parsing_error) {
304 bool no_such_chamber =
false;
306 if (wheel < -2 || wheel > 2) no_such_chamber =
true;
307 if (station < 1 || station > 4) no_such_chamber =
true;
308 if (station == 4 && (sector < 1 || sector > 14)) no_such_chamber =
true;
309 if (station < 4 && (sector < 1 || sector > 12)) no_such_chamber =
true;
311 if (no_such_chamber) {
312 throw cms::Exception(
"BadConfig") <<
"Chamber doesn't exist: MB" << (plus ?
"+" :
"-") << wheel <<
"/" << station <<
"/" << sector << std::endl;
315 if (superlayer == 0) {
320 bool no_such_superlayer =
false;
321 if (superlayer < 1 || superlayer > 3) no_such_superlayer =
true;
322 if (station == 4 && superlayer == 2) no_such_superlayer =
true;
324 if (no_such_superlayer) {
325 throw cms::Exception(
"BadConfig") <<
"Superlayer doesn't exist: MB" << (plus ?
"+" :
"-") << wheel <<
"/" << station <<
"/" << sector <<
"/" << superlayer << std::endl;
333 bool no_such_layer =
false;
334 if (layer < 1 || layer > 4) no_such_layer =
true;
337 throw cms::Exception(
"BadConfig") <<
"Layer doesn't exist: MB" << (plus ?
"+" :
"-") << wheel <<
"/" << station <<
"/" << sector <<
"/" << superlayer <<
"/" << layer << std::endl;
346 else if (!parsing_error && endcap) {
350 if (detName.substr(index, 1) == std::string(
"+")) {
354 else if (detName.substr(index, 1) == std::string(
"-")) {
358 else parsing_error =
true;
361 bool station_digit =
false;
362 while (!parsing_error &&
numeric(detName.substr(index, 1))) {
364 station +=
number(detName.substr(index, 1));
365 station_digit =
true;
368 if (!plus) station *= -1;
369 if (!station_digit) parsing_error =
true;
371 if (detName.substr(index, 1) != std::string(
"/")) parsing_error =
true;
375 bool ring_digit =
false;
376 while (!parsing_error &&
numeric(detName.substr(index, 1))) {
378 ring +=
number(detName.substr(index, 1));
382 if (!ring_digit) parsing_error =
true;
384 if (detName.substr(index, 1) != std::string(
"/")) parsing_error =
true;
388 bool chamber_digit =
false;
389 while (!parsing_error &&
numeric(detName.substr(index, 1))) {
391 chamber +=
number(detName.substr(index, 1));
392 chamber_digit =
true;
395 if (!chamber_digit) parsing_error =
true;
399 bool layer_digit =
false;
400 if (detName.substr(index, 1) == std::string(
"/")) {
402 while (!parsing_error &&
numeric(detName.substr(index, 1))) {
404 layer +=
number(detName.substr(index, 1));
408 if (!layer_digit) parsing_error =
true;
411 if (!parsing_error) {
412 bool no_such_chamber =
false;
414 int endcap = (station > 0 ? 1 : 2);
415 station =
abs(station);
416 if (station < 1 || station > 4) no_such_chamber =
true;
417 if (station == 1 && (ring < 1 || ring > 4)) no_such_chamber =
true;
418 if (station > 1 && (ring < 1 || ring > 2)) no_such_chamber =
true;
419 if (station == 1 && (chamber < 1 || chamber > 36)) no_such_chamber =
true;
420 if (station > 1 && ring == 1 && (chamber < 1 || chamber > 18)) no_such_chamber =
true;
421 if (station > 1 && ring == 2 && (chamber < 1 || chamber > 36)) no_such_chamber =
true;
423 if (no_such_chamber) {
424 throw cms::Exception(
"BadConfig") <<
"Chamber doesn't exist: ME" << (endcap == 1 ?
"+" :
"-") << station <<
"/" << ring <<
"/" << chamber << std::endl;
432 bool no_such_layer =
false;
433 if (layer < 1 || layer > 6) no_such_layer =
true;
436 throw cms::Exception(
"BadConfig") <<
"Layer doesn't exist: ME" << (endcap == 1 ?
"+" :
"-") << station <<
"/" << ring <<
"/" << chamber <<
"/" << layer << std::endl;
446 throw cms::Exception(
"BadConfig") <<
"Detector name is malformed: " << detName << std::endl;
450 const std::map<std::string,const MuonGeometrySanityCheckCustomFrame*>::const_iterator frameIter = frames.find(frameName);
451 if (frameName == std::string(
"global")) {
455 else if (frameName == std::string(
"local")) {
459 else if (frameName == std::string(
"chamber")) {
463 else if (frameIter != frames.end()) {
468 throw cms::Exception(
"BadConfig") <<
"Frame \"" << frameName <<
"\" has not been defined." << std::endl;
471 std::vector<double>
point = iConfig.
getParameter<std::vector<double> >(
"displacement");
472 if (point.size() != 3) {
473 throw cms::Exception(
"BadConfig") <<
"Displacement relative to detector " << detName <<
" doesn't have exactly three components." << std::endl;
482 point = iConfig.
getParameter<std::vector<double> >(
"expectation");
483 if (point.size() != 3) {
484 throw cms::Exception(
"BadConfig") <<
"Expectation for detector " << detName <<
", displacement " <<
displacement <<
" doesn't have exactly three components." << std::endl;
498 name = std::string(
"anonymous");
503 frameName = iConfig.
getParameter<std::string>(
"outputFrame");
504 const std::map<std::string,const MuonGeometrySanityCheckCustomFrame*>::const_iterator frameIter = frames.find(frameName);
505 if (frameName == std::string(
"global")) {
509 else if (frameName == std::string(
"local")) {
513 else if (frameName == std::string(
"chamber")) {
517 else if (frameIter != frames.end()) {
522 throw cms::Exception(
"BadConfig") <<
"Frame \"" << frameName <<
"\" has not been defined." << std::endl;
535 output <<
"MB" << (
id.wheel() > 0 ?
"+" :
"") <<
id.wheel() <<
"/" <<
id.station() <<
"/" <<
id.sector();
539 output <<
"MB" << (
id.wheel() > 0 ?
"+" :
"") <<
id.wheel() <<
"/" <<
id.station() <<
"/" <<
id.sector() <<
"/" <<
id.superlayer();
543 output <<
"MB" << (
id.wheel() > 0 ?
"+" :
"") <<
id.wheel() <<
"/" <<
id.station() <<
"/" <<
id.sector() <<
"/" <<
id.superlayer() <<
"/" <<
id.layer();
547 output <<
"ME" << (
id.endcap() == 1 ?
"+" :
"-") <<
id.
station() <<
"/" <<
id.ring() <<
"/" <<
id.chamber();
551 output <<
"ME" << (
id.endcap() == 1 ?
"+" :
"-") <<
id.
station() <<
"/" <<
id.ring() <<
"/" <<
id.chamber() <<
"/" <<
id.layer();
566 int num_transformed = 0;
576 if (dt) chamberPos = dtGeometry->idToDet(
point->detector)->surface().toGlobal(
LocalPoint(0., 0., 0.));
577 else chamberPos = cscGeometry->idToDet(
point->detector)->surface().toGlobal(
LocalPoint(0., 0., 0.));
581 result =
GlobalPoint(chamberPos.
x() +
point->displacement.x(), chamberPos.
y() +
point->displacement.y(), chamberPos.
z() +
point->displacement.z());
585 if (dt) result = dtGeometry->idToDet(
point->detector)->surface().toGlobal(
LocalPoint(
point->displacement.x(),
point->displacement.y(),
point->displacement.z()));
586 else result = cscGeometry->idToDet(
point->detector)->surface().toGlobal(
LocalPoint(
point->displacement.x(),
point->displacement.y(),
point->displacement.z()));
592 if (dt) result = dtGeometry->idToDet(
id)->surface().toGlobal(
LocalPoint(
point->displacement.x(),
point->displacement.y(),
point->displacement.z()));
593 else result = cscGeometry->idToDet(
id)->surface().toGlobal(
LocalPoint(
point->displacement.x(),
point->displacement.y(),
point->displacement.z()));
598 if (dt) result = dtGeometry->idToDet(
id)->surface().toGlobal(
LocalPoint(
point->displacement.x(),
point->displacement.y(),
point->displacement.z()));
599 else result = cscGeometry->idToDet(
id)->surface().toGlobal(
LocalPoint(
point->displacement.x(),
point->displacement.y(),
point->displacement.z()));
601 else { assert(
false); }
606 result =
GlobalPoint(chamberPos.
x() + transformed.
x(), chamberPos.
y() + transformed.
y(), chamberPos.
z() + transformed.
z());
609 else { assert(
false); }
616 if (dt) transformed = dtGeometry->idToDet(
point->detector)->surface().toLocal(result);
617 else transformed = cscGeometry->idToDet(
point->detector)->surface().toLocal(result);
618 result =
GlobalPoint(transformed.
x(), transformed.
y(), transformed.
z());
625 if (dt) transformed = dtGeometry->idToDet(
id)->surface().toLocal(result);
626 else transformed = cscGeometry->idToDet(
id)->surface().toLocal(result);
627 result =
GlobalPoint(transformed.
x(), transformed.
y(), transformed.
z());
633 if (dt) transformed = dtGeometry->idToDet(
id)->surface().toLocal(result);
634 else transformed = cscGeometry->idToDet(
id)->surface().toLocal(result);
635 result =
GlobalPoint(transformed.x(), transformed.y(), transformed.z());
637 else { assert(
false); }
641 result =
point->outputCustomFrame->transformInverse(result);
645 output <<
prefix <<
" " <<
point->name <<
" " <<
point->detName() <<
" " << result.
x() <<
" " << result.
y() <<
" " << result.
z();
648 if (
point->has_expectation) {
650 double residx = result.
x() -
point->expectation.x();
651 double residy = result.
y() -
point->expectation.y();
652 double residz = result.
z() -
point->expectation.z();
657 output <<
" BAD " << residx <<
" " << residy <<
" " << residz << std::endl;
660 output <<
" GOOD " << residx <<
" " << residy <<
" " << residz << std::endl;
664 output <<
" UNTESTED 0 0 0" << std::endl;
667 if (
printout == std::string(
"all") || (
printout == std::string(
"bad") && bad)) {
672 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
T getParameter(std::string const &) const
std::string detName() const
std::map< std::string, const MuonGeometrySanityCheckCustomFrame * > m_frames
#define DEFINE_FWK_MODULE(type)
Entry const *const retrieveUnknown(char const *) const
const MuonGeometrySanityCheckCustomFrame * outputCustomFrame
Global3DPoint GlobalPoint
int number(std::string s)
GlobalPoint transform(GlobalPoint point) const
virtual void analyze(const edm::Event &, const edm::EventSetup &iConfig)
int bad(Items const &cont)
AlgebraicMatrix matrixInverse
~MuonGeometrySanityCheck()
CLHEP::HepMatrix AlgebraicMatrix
std::pair< std::string, MonitorElement * > entry
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
MuonGeometrySanityCheck(const edm::ParameterSet &iConfig)
*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