CMS 3D CMS Logo

MuonScenarioBuilder.cc
Go to the documentation of this file.
1 
8 #include <string>
9 #include <iostream>
10 #include <sstream>
11 #include <algorithm>
12 
13 // Framework
16 
17 // Alignment
18 
23 
25 
26 //__________________________________________________________________________________________________
28  : // muon alignable IDs are (currently) independent of the geometry
30  theAlignableMuon = dynamic_cast<AlignableMuon*>(alignable);
31 
32  if (!theAlignableMuon)
33  throw cms::Exception("TypeMismatch") << "Argument is not an AlignableMuon";
34 }
35 
36 //__________________________________________________________________________________________________
38  // Apply the scenario to all main components of Muon.
41 
42  // Seed is set at top-level, and is mandatory
43  if (this->hasParameter_("seed", theScenario))
44  theModifier.setSeed(static_cast<long>(theScenario.getParameter<int>("seed")));
45  else
46  throw cms::Exception("BadConfig") << "No generator seed defined!";
47 
48  // DT Barrel
49  const auto& dtBarrel = theAlignableMuon->DTBarrel();
50  this->decodeMovements_(theScenario, dtBarrel, "DTBarrel");
51  // Endcap
52  const auto& cscEndcaps = theAlignableMuon->CSCEndcaps();
53  this->decodeMovements_(theScenario, cscEndcaps, "CSCEndcap");
54  const auto& gemEndcaps = theAlignableMuon->GEMEndcaps();
55  this->decodeMovements_(theScenario, gemEndcaps, "GEMEndcap");
56 
60  this->moveMuon(theScenario);
61 
62  edm::LogInfo("TrackerScenarioBuilder") << "Applied modifications to " << theModifierCounter << " alignables";
63 }
64 
66  double scale_ = 0, scaleError_ = 0, phiX_ = 0, phiY_ = 0, phiZ_ = 0;
67  double dX_ = 0, dY_ = 0, dZ_ = 0;
68  std::string distribution_;
69  std::ostringstream error;
71  std::vector<std::string> parameterNames = Parameters.getParameterNames();
72  for (std::vector<std::string>::iterator iParam = parameterNames.begin(); iParam != parameterNames.end(); iParam++) {
73  if ((*iParam) == "scale")
74  scale_ = Parameters.getParameter<double>(*iParam);
75  else if ((*iParam) == "distribution")
76  distribution_ = Parameters.getParameter<std::string>(*iParam);
77  else if ((*iParam) == "scaleError")
78  scaleError_ = Parameters.getParameter<double>(*iParam);
79  else if ((*iParam) == "phiX")
80  phiX_ = Parameters.getParameter<double>(*iParam);
81  else if ((*iParam) == "phiY")
82  phiY_ = Parameters.getParameter<double>(*iParam);
83  else if ((*iParam) == "phiZ")
84  phiZ_ = Parameters.getParameter<double>(*iParam);
85  else if ((*iParam) == "dX")
86  dX_ = Parameters.getParameter<double>(*iParam);
87  else if ((*iParam) == "dY")
88  dY_ = Parameters.getParameter<double>(*iParam);
89  else if ((*iParam) == "dZ")
90  dZ_ = Parameters.getParameter<double>(*iParam);
91  else if (Parameters.retrieve(*iParam).typeCode() != 'P') { // Add unknown parameter to list
92  if (!error.str().length())
93  error << "Unknown parameter name(s): ";
94  error << " " << *iParam;
95  }
96  }
97  align::Scalars param;
98  param.push_back(scale_);
99  param.push_back(scaleError_);
100  param.push_back(phiX_);
101  param.push_back(phiY_);
102  param.push_back(phiZ_);
103  param.push_back(dX_);
104  param.push_back(dY_);
105  param.push_back(dZ_);
106  if (distribution_ == "gaussian")
107  param.push_back(0);
108  else if (distribution_ == "flat")
109  param.push_back(1);
110  else if (distribution_ == "fix")
111  param.push_back(2);
112 
113  return param;
114 }
115 
116 //_____________________________________________________________________________________________________
118  const auto& DTchambers = theAlignableMuon->DTChambers();
119  //Take parameters
120  align::Scalars param = this->extractParameters(pSet, "DTSectors");
121  double scale_ = param[0];
122  double scaleError_ = param[1];
123  double phiX_ = param[2];
124  double phiY_ = param[3];
125  double phiZ_ = param[4];
126  double dX_ = param[5];
127  double dY_ = param[6];
128  double dZ_ = param[7];
129  double dist_ = param[8];
130 
131  double dx = scale_ * dX_;
132  double dy = scale_ * dY_;
133  double dz = scale_ * dZ_;
134  double phix = scale_ * phiX_;
135  double phiy = scale_ * phiY_;
136  double phiz = scale_ * phiZ_;
137  double errorx = scaleError_ * dX_;
138  double errory = scaleError_ * dY_;
139  double errorz = scaleError_ * dZ_;
140  double errorphix = scaleError_ * phiX_;
141  double errorphiy = scaleError_ * phiY_;
142  double errorphiz = scaleError_ * phiZ_;
143  align::Scalars errorDisp;
144  errorDisp.push_back(errorx);
145  errorDisp.push_back(errory);
146  errorDisp.push_back(errorz);
147  align::Scalars errorRotation;
148  errorRotation.push_back(errorphix);
149  errorRotation.push_back(errorphiy);
150  errorRotation.push_back(errorphiz);
151 
152  int index[5][4][14];
153  std::fill_n(index[0][0], 5 * 4 * 14, -1); // initialize to -1
154  int counter = 0;
155  //Create and index for the chambers in the Alignable vector
156  for (const auto& iter : DTchambers) {
157  DTChamberId myId(iter->geomDetId().rawId());
158  index[myId.wheel() + 2][myId.station() - 1][myId.sector() - 1] = counter;
159  counter++;
160  }
161  for (int wheel = 0; wheel < 5; wheel++) {
162  for (int sector = 0; sector < 12; sector++) {
163  align::Scalars disp;
165  if (dist_ == 0) {
166  const std::vector<float> disp_ = theMuonModifier.gaussianRandomVector(dx, dy, dz);
167  const std::vector<float> rotation_ = theMuonModifier.gaussianRandomVector(phix, phiy, phiz);
168  disp.push_back(disp_[0]);
169  disp.push_back(disp_[1]);
170  disp.push_back(disp_[2]);
171  rotation.push_back(rotation_[0]);
172  rotation.push_back(rotation_[1]);
173  rotation.push_back(rotation_[2]);
174  } else if (dist_ == 1) {
175  const std::vector<float> disp_ = theMuonModifier.flatRandomVector(dx, dy, dz);
176  const std::vector<float> rotation_ = theMuonModifier.flatRandomVector(phix, phiy, phiz);
177  disp.push_back(disp_[0]);
178  disp.push_back(disp_[1]);
179  disp.push_back(disp_[2]);
180  rotation.push_back(rotation_[0]);
181  rotation.push_back(rotation_[1]);
182  rotation.push_back(rotation_[2]);
183  } else {
184  disp.push_back(dx);
185  disp.push_back(dy);
186  disp.push_back(dz);
187  rotation.push_back(phix);
188  rotation.push_back(phiy);
189  rotation.push_back(phiz);
190  }
191  for (int station = 0; station < 4; station++) {
192  Alignable* myAlign = DTchambers.at(index[wheel][station][sector]);
193  this->moveChamberInSector(myAlign, disp, rotation, errorDisp, errorRotation);
194  if (sector == 3 && station == 3) {
195  Alignable* myAlignD = DTchambers.at(index[wheel][station][12]);
196  this->moveChamberInSector(myAlignD, disp, rotation, errorDisp, errorRotation);
197  } else if (sector == 9 && station == 3) {
198  Alignable* myAlignD = DTchambers.at(index[wheel][station][13]);
199  this->moveChamberInSector(myAlignD, disp, rotation, errorDisp, errorRotation);
200  }
201  }
202  }
203  }
204 }
205 
206 //______________________________________________________________________________________________________
208  const auto& CSCchambers = theAlignableMuon->CSCChambers();
209  //Take Parameters
210  align::Scalars param = this->extractParameters(pSet, "CSCSectors");
211  double scale_ = param[0];
212  double scaleError_ = param[1];
213  double phiX_ = param[2];
214  double phiY_ = param[3];
215  double phiZ_ = param[4];
216  double dX_ = param[5];
217  double dY_ = param[6];
218  double dZ_ = param[7];
219  double dist_ = param[8];
220 
221  double dx = scale_ * dX_;
222  double dy = scale_ * dY_;
223  double dz = scale_ * dZ_;
224  double phix = scale_ * phiX_;
225  double phiy = scale_ * phiY_;
226  double phiz = scale_ * phiZ_;
227  double errorx = scaleError_ * dX_;
228  double errory = scaleError_ * dY_;
229  double errorz = scaleError_ * dZ_;
230  double errorphix = scaleError_ * phiX_;
231  double errorphiy = scaleError_ * phiY_;
232  double errorphiz = scaleError_ * phiZ_;
233  align::Scalars errorDisp;
234  errorDisp.push_back(errorx);
235  errorDisp.push_back(errory);
236  errorDisp.push_back(errorz);
237  align::Scalars errorRotation;
238  errorRotation.push_back(errorphix);
239  errorRotation.push_back(errorphiy);
240  errorRotation.push_back(errorphiz);
241 
242  int index[2][4][4][36];
243  int sector_index[2][4][4][36];
244  std::fill_n(index[0][0][0], 2 * 4 * 4 * 36, -1); // initialize to -1
245  std::fill_n(sector_index[0][0][0], 2 * 4 * 4 * 36, -1); // initialize to -1
246  int counter = 0;
247  //Create an index for the chambers in the alignable vector
248  for (const auto& iter : CSCchambers) {
249  CSCDetId myId(iter->geomDetId().rawId());
250  index[myId.endcap() - 1][myId.station() - 1][myId.ring() - 1][myId.chamber() - 1] = counter;
251  sector_index[myId.endcap() - 1][myId.station() - 1][myId.ring() - 1][myId.chamber() - 1] =
254  myId.station());
255  counter++;
256  }
257  for (int endcap = 0; endcap < 2; endcap++) {
258  for (int ring = 0; ring < 2; ring++) {
259  for (int sector = 1; sector < 7; sector++) {
260  align::Scalars disp;
262  if (dist_ == 0) {
263  const std::vector<float> disp_ = theMuonModifier.gaussianRandomVector(dx, dy, dz);
264  const std::vector<float> rotation_ = theMuonModifier.gaussianRandomVector(phix, phiy, phiz);
265  disp.push_back(disp_[0]);
266  disp.push_back(disp_[1]);
267  disp.push_back(disp_[2]);
268  rotation.push_back(rotation_[0]);
269  rotation.push_back(rotation_[1]);
270  rotation.push_back(rotation_[2]);
271  } else if (dist_ == 1) {
272  const std::vector<float> disp_ = theMuonModifier.flatRandomVector(dx, dy, dz);
273  const std::vector<float> rotation_ = theMuonModifier.flatRandomVector(phix, phiy, phiz);
274  disp.push_back(disp_[0]);
275  disp.push_back(disp_[1]);
276  disp.push_back(disp_[2]);
277  rotation.push_back(rotation_[0]);
278  rotation.push_back(rotation_[1]);
279  rotation.push_back(rotation_[2]);
280  } else {
281  disp.push_back(dx);
282  disp.push_back(dy);
283  disp.push_back(dz);
284  rotation.push_back(phix);
285  rotation.push_back(phiy);
286  rotation.push_back(phiz);
287  }
288  //Different cases are considered in order to fit endcap geometry
289  for (int station = 0; station < 4; station++) {
290  if (station == 0) {
291  int r_ring[2];
292  if (ring == 0) {
293  r_ring[0] = 0;
294  r_ring[1] = 3;
295  } else {
296  r_ring[0] = 1;
297  r_ring[1] = 2;
298  }
299  for (int r_counter = 0; r_counter < 2; r_counter++) {
300  for (int chamber = 0; chamber < 36; chamber++) {
301  if (sector == (sector_index[endcap][station][r_ring[r_counter]][chamber] + 1) / 2) {
302  Alignable* myAlign = CSCchambers.at(index[endcap][station][r_ring[r_counter]][chamber]);
303  this->moveChamberInSector(myAlign, disp, rotation, errorDisp, errorRotation);
304  }
305  }
306  }
307  } else if (station == 3 && ring == 1) {
308  continue;
309  } else {
310  for (int chamber = 0; chamber < 36; chamber++) {
311  if (ring == 0 && chamber > 17)
312  continue;
313  if (sector == sector_index[endcap][station][ring][chamber]) {
314  Alignable* myAlign = CSCchambers.at(index[endcap][station][ring][chamber]);
315  this->moveChamberInSector(myAlign, disp, rotation, errorDisp, errorRotation);
316  }
317  }
318  }
319  }
320  }
321  }
322  }
323 }
324 
325 //______________________________________________________________________________________________________
327  const auto& GEMSuperChambers = theAlignableMuon->GEMSuperChambers();
328  //Take Parameters
329  align::Scalars param = this->extractParameters(pSet, "GEMSectors");
330  double scale_ = param[0];
331  double scaleError_ = param[1];
332  double phiX_ = param[2];
333  double phiY_ = param[3];
334  double phiZ_ = param[4];
335  double dX_ = param[5];
336  double dY_ = param[6];
337  double dZ_ = param[7];
338 
339  double dx = scale_ * dX_;
340  double dy = scale_ * dY_;
341  double dz = scale_ * dZ_;
342  double phix = scale_ * phiX_;
343  double phiy = scale_ * phiY_;
344  double phiz = scale_ * phiZ_;
345  double errorx = scaleError_ * dX_;
346  double errory = scaleError_ * dY_;
347  double errorz = scaleError_ * dZ_;
348  double errorphix = scaleError_ * phiX_;
349  double errorphiy = scaleError_ * phiY_;
350  double errorphiz = scaleError_ * phiZ_;
351  align::Scalars errorDisp;
352  errorDisp.push_back(errorx);
353  errorDisp.push_back(errory);
354  errorDisp.push_back(errorz);
355  align::Scalars errorRotation;
356  errorRotation.push_back(errorphix);
357  errorRotation.push_back(errorphiy);
358  errorRotation.push_back(errorphiz);
359 
360  //Create an index for the chambers in the alignable vector
361  for (const auto& iter : GEMSuperChambers) {
362  align::Scalars disp;
364  const std::vector<float> disp_ = theMuonModifier.gaussianRandomVector(dx, dy, dz);
365  disp.push_back(disp_[0]);
366  disp.push_back(disp_[1]);
367  disp.push_back(disp_[2]);
368  const std::vector<float> rotation_ = theMuonModifier.flatRandomVector(phix, phiy, phiz);
369  rotation.push_back(rotation_[0]);
370  rotation.push_back(rotation_[1]);
371  rotation.push_back(rotation_[2]);
372  this->moveChamberInSector(iter, disp, rotation, errorDisp, errorRotation);
373  }
374 }
375 
377  const auto& DTbarrel = theAlignableMuon->DTBarrel();
378  const auto& CSCendcaps = theAlignableMuon->CSCEndcaps();
379  const auto& GEMendcaps = theAlignableMuon->GEMEndcaps();
380  //Take Parameters
381  align::Scalars param = this->extractParameters(pSet, "Muon");
382  double scale_ = param[0];
383  double scaleError_ = param[1];
384  double phiX_ = param[2];
385  double phiY_ = param[3];
386  double phiZ_ = param[4];
387  double dX_ = param[5];
388  double dY_ = param[6];
389  double dZ_ = param[7];
390  double dist_ = param[8];
391  double dx = scale_ * dX_;
392  double dy = scale_ * dY_;
393  double dz = scale_ * dZ_;
394  double phix = scale_ * phiX_;
395  double phiy = scale_ * phiY_;
396  double phiz = scale_ * phiZ_;
397  double errorx = scaleError_ * dX_;
398  double errory = scaleError_ * dY_;
399  double errorz = scaleError_ * dZ_;
400  double errorphix = scaleError_ * phiX_;
401  double errorphiy = scaleError_ * phiY_;
402  double errorphiz = scaleError_ * phiZ_;
403  //Create an index for the chambers in the alignable vector
404  align::Scalars disp;
406  if (dist_ == 0) {
407  const std::vector<float> disp_ = theMuonModifier.gaussianRandomVector(dx, dy, dz);
408  const std::vector<float> rotation_ = theMuonModifier.gaussianRandomVector(phix, phiy, phiz);
409  disp.push_back(disp_[0]);
410  disp.push_back(disp_[1]);
411  disp.push_back(disp_[2]);
412  rotation.push_back(rotation_[0]);
413  rotation.push_back(rotation_[1]);
414  rotation.push_back(rotation_[2]);
415  } else if (dist_ == 1) {
416  const std::vector<float> disp_ = theMuonModifier.flatRandomVector(dx, dy, dz);
417  const std::vector<float> rotation_ = theMuonModifier.flatRandomVector(phix, phiy, phiz);
418  disp.push_back(disp_[0]);
419  disp.push_back(disp_[1]);
420  disp.push_back(disp_[2]);
421  rotation.push_back(rotation_[0]);
422  rotation.push_back(rotation_[1]);
423  rotation.push_back(rotation_[2]);
424  } else {
425  disp.push_back(dx);
426  disp.push_back(dy);
427  disp.push_back(dz);
428  rotation.push_back(phix);
429  rotation.push_back(phiy);
430  rotation.push_back(phiz);
431  }
432  for (const auto& iter : DTbarrel) {
433  theMuonModifier.moveAlignable(iter, false, true, disp[0], disp[1], disp[2]);
434  theMuonModifier.rotateAlignable(iter, false, true, rotation[0], rotation[1], rotation[2]);
435  theMuonModifier.addAlignmentPositionError(iter, errorx, errory, errorz);
436  theMuonModifier.addAlignmentPositionErrorFromRotation(iter, errorphix, errorphiy, errorphiz);
437  }
438  for (const auto& iter : CSCendcaps) {
439  theMuonModifier.moveAlignable(iter, false, true, disp[0], disp[1], disp[2]);
440  theMuonModifier.rotateAlignable(iter, false, true, rotation[0], rotation[1], rotation[2]);
441  theMuonModifier.addAlignmentPositionError(iter, errorx, errory, errorz);
442  theMuonModifier.addAlignmentPositionErrorFromRotation(iter, errorphix, errorphiy, errorphiz);
443  }
444  for (const auto& iter : GEMendcaps) {
445  theMuonModifier.moveAlignable(iter, false, true, disp[0], disp[1], disp[2]);
446  theMuonModifier.rotateAlignable(iter, false, true, rotation[0], rotation[1], rotation[2]);
447  theMuonModifier.addAlignmentPositionError(iter, errorx, errory, errorz);
448  theMuonModifier.addAlignmentPositionErrorFromRotation(iter, errorphix, errorphiy, errorphiz);
449  }
450 }
451 
452 //______________________________________________________________________________________________________
454  const align::Scalars& _disp,
455  const align::Scalars& rotation,
456  const align::Scalars& dispError,
457  const align::Scalars& rotationError) {
458  align::Scalars disp = _disp;
459  align::RotationType rotx(Basic3DVector<double>(1.0, 0.0, 0.0), rotation[0]);
460  align::RotationType roty(Basic3DVector<double>(0.0, 1.0, 0.0), rotation[1]);
461  align::RotationType rotz(Basic3DVector<double>(0.0, 0.0, 1.0), rotation[2]);
462  align::RotationType rot = rotz * roty * rotx;
463  align::GlobalPoint pos = chamber->globalPosition();
464  align::GlobalPoint dispRot(pos.basicVector() - rot * pos.basicVector());
465  disp[0] += dispRot.x();
466  disp[1] += dispRot.y();
467  disp[2] += dispRot.z();
468  theMuonModifier.moveAlignable(chamber, false, true, disp[0], disp[1], disp[2]);
470  theMuonModifier.addAlignmentPositionError(chamber, dispError[0], dispError[1], dispError[2]);
471  theMuonModifier.addAlignmentPositionErrorFromRotation(chamber, rotationError[0], rotationError[1], rotationError[2]);
472 }
edm::ParameterSet theScenario
Misalignment scenario to apply (from config file)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
void decodeMovements_(const edm::ParameterSet &, const align::Alignables &)
Decode movements defined in given parameter set for given set of alignables.
void moveGEMSectors(const edm::ParameterSet &scenario)
AlignableModifier theMuonModifier
void setSeed(long seed)
Resets the generator seed according to the argument.
align::Alignables CSCChambers()
void moveCSCSectors(const edm::ParameterSet &scenario)
this special method allows to move a CSCsector by a same amount
void addAlignmentPositionError(Alignable *alignable, float dx, float dy, float dz)
Add the AlignmentPositionError (in global frame) to Alignable.
AlignableMuon * theAlignableMuon
Pointer to alignable Muon object.
align::Alignables DTBarrel()
bool hasParameter_(const std::string &name, const edm::ParameterSet &pSet) const
Check if given parameter exists in parameter set.
scenario
Definition: constants.h:173
void moveMuon(const edm::ParameterSet &scenario)
this special method allows to move the complete muon system by a same amount
const std::vector< float > flatRandomVector(float sigmaX, float sigmaY, float sigmaZ) const
Return a vector of random numbers (flat distribution)
align::Alignables GEMSuperChambers()
void moveChamberInSector(Alignable *, const align::Scalars &, const align::Scalars &, const align::Scalars &, const align::Scalars &)
void moveAlignable(Alignable *alignable, bool random, bool gaussian, float sigmaX, float sigmaY, float sigmaZ)
Move alignable in global space according to parameters.
align::Scalars extractParameters(const edm::ParameterSet &, const char *)
T x() const
Definition: PV3DBase.h:59
edm::ParameterSet getParameterSet_(const std::string &name, const edm::ParameterSet &pSet) const
align::Alignables CSCEndcaps()
Class Geometry Contains vector for fit parameters (mean, sigma, etc.) obtained from multiple IOVs See...
static int sectorFromTriggerLabels(int TriggerSector, int TriggerSubSector, int station)
align::Alignables DTChambers()
std::vector< Scalar > Scalars
Definition: Utilities.h:26
MuonScenarioBuilder(Alignable *alignable)
Constructor.
Allows conversion between type and name, and vice-versa.
const std::vector< float > gaussianRandomVector(float sigmaX, float sigmaY, float sigmaZ) const
Return a vector of random numbers (gaussian distribution)
Log< level::Info, false > LogInfo
void moveDTSectors(const edm::ParameterSet &scenario)
This special method allows to move a DTsector by a same amount.
void rotateAlignable(Alignable *alignable, bool random, bool gaussian, float sigmaPhiX, float sigmaPhiY, float sigmaPhiZ)
Rotate alignable in global space according to parameters.
AlignableModifier theModifier
Helper class for random movements.
Base class to build a scenario from configuration and apply to either tracker or muon.
static int triggerSectorFromLabels(int station, int ring, int chamber)
void addAlignmentPositionErrorFromRotation(Alignable *alignable, float phiX, float phiY, float phiZ)
Add alignment position error resulting from rotation in global frame.
static int triggerSubSectorFromLabels(int station, int chamber)
std::vector< AlignmentParameters * > Parameters
Definition: Utilities.h:32
align::Alignables GEMEndcaps()
static std::atomic< unsigned int > counter
void applyScenario(const edm::ParameterSet &scenario) override
Apply misalignment scenario to the Muon.
int theModifierCounter
Counter for applied modification.
Constructor of the full muon geometry.
Definition: AlignableMuon.h:38