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 
24 //__________________________________________________________________________________________________
26  : // muon alignable IDs are (currently) independent of the geometry
28  theAlignableMuon = dynamic_cast<AlignableMuon*>(alignable);
29 
30  if (!theAlignableMuon)
31  throw cms::Exception("TypeMismatch") << "Argument is not an AlignableMuon";
32 }
33 
34 //__________________________________________________________________________________________________
36  // Apply the scenario to all main components of Muon.
39 
40  // Seed is set at top-level, and is mandatory
41  if (this->hasParameter_("seed", theScenario))
42  theModifier.setSeed(static_cast<long>(theScenario.getParameter<int>("seed")));
43  else
44  throw cms::Exception("BadConfig") << "No generator seed defined!";
45 
46  // DT Barrel
47  const auto& dtBarrel = theAlignableMuon->DTBarrel();
48  this->decodeMovements_(theScenario, dtBarrel, "DTBarrel");
49  // CSC Endcap
50  const auto& cscEndcaps = theAlignableMuon->CSCEndcaps();
51  this->decodeMovements_(theScenario, cscEndcaps, "CSCEndcap");
52 
55  this->moveMuon(theScenario);
56 
57  edm::LogInfo("TrackerScenarioBuilder") << "Applied modifications to " << theModifierCounter << " alignables";
58 }
59 
61  double scale_ = 0, scaleError_ = 0, phiX_ = 0, phiY_ = 0, phiZ_ = 0;
62  double dX_ = 0, dY_ = 0, dZ_ = 0;
63  std::string distribution_;
64  std::ostringstream error;
66  std::vector<std::string> parameterNames = Parameters.getParameterNames();
67  for (std::vector<std::string>::iterator iParam = parameterNames.begin(); iParam != parameterNames.end(); iParam++) {
68  if ((*iParam) == "scale")
69  scale_ = Parameters.getParameter<double>(*iParam);
70  else if ((*iParam) == "distribution")
71  distribution_ = Parameters.getParameter<std::string>(*iParam);
72  else if ((*iParam) == "scaleError")
73  scaleError_ = Parameters.getParameter<double>(*iParam);
74  else if ((*iParam) == "phiX")
75  phiX_ = Parameters.getParameter<double>(*iParam);
76  else if ((*iParam) == "phiY")
77  phiY_ = Parameters.getParameter<double>(*iParam);
78  else if ((*iParam) == "phiZ")
79  phiZ_ = Parameters.getParameter<double>(*iParam);
80  else if ((*iParam) == "dX")
81  dX_ = Parameters.getParameter<double>(*iParam);
82  else if ((*iParam) == "dY")
83  dY_ = Parameters.getParameter<double>(*iParam);
84  else if ((*iParam) == "dZ")
85  dZ_ = Parameters.getParameter<double>(*iParam);
86  else if (Parameters.retrieve(*iParam).typeCode() != 'P') { // Add unknown parameter to list
87  if (!error.str().length())
88  error << "Unknown parameter name(s): ";
89  error << " " << *iParam;
90  }
91  }
92  align::Scalars param;
93  param.push_back(scale_);
94  param.push_back(scaleError_);
95  param.push_back(phiX_);
96  param.push_back(phiY_);
97  param.push_back(phiZ_);
98  param.push_back(dX_);
99  param.push_back(dY_);
100  param.push_back(dZ_);
101  if (distribution_ == "gaussian")
102  param.push_back(0);
103  else if (distribution_ == "flat")
104  param.push_back(1);
105  else if (distribution_ == "fix")
106  param.push_back(2);
107 
108  return param;
109 }
110 
111 //_____________________________________________________________________________________________________
113  const auto& DTchambers = theAlignableMuon->DTChambers();
114  //Take parameters
115  align::Scalars param = this->extractParameters(pSet, "DTSectors");
116  double scale_ = param[0];
117  double scaleError_ = param[1];
118  double phiX_ = param[2];
119  double phiY_ = param[3];
120  double phiZ_ = param[4];
121  double dX_ = param[5];
122  double dY_ = param[6];
123  double dZ_ = param[7];
124  double dist_ = param[8];
125 
126  double dx = scale_ * dX_;
127  double dy = scale_ * dY_;
128  double dz = scale_ * dZ_;
129  double phix = scale_ * phiX_;
130  double phiy = scale_ * phiY_;
131  double phiz = scale_ * phiZ_;
132  double errorx = scaleError_ * dX_;
133  double errory = scaleError_ * dY_;
134  double errorz = scaleError_ * dZ_;
135  double errorphix = scaleError_ * phiX_;
136  double errorphiy = scaleError_ * phiY_;
137  double errorphiz = scaleError_ * phiZ_;
138  align::Scalars errorDisp;
139  errorDisp.push_back(errorx);
140  errorDisp.push_back(errory);
141  errorDisp.push_back(errorz);
142  align::Scalars errorRotation;
143  errorRotation.push_back(errorphix);
144  errorRotation.push_back(errorphiy);
145  errorRotation.push_back(errorphiz);
146 
147  int index[5][4][14];
148  std::fill_n(index[0][0], 5 * 4 * 14, -1); // initialize to -1
149  int counter = 0;
150  //Create and index for the chambers in the Alignable vector
151  for (const auto& iter : DTchambers) {
152  DTChamberId myId(iter->geomDetId().rawId());
153  index[myId.wheel() + 2][myId.station() - 1][myId.sector() - 1] = counter;
154  counter++;
155  }
156  for (int wheel = 0; wheel < 5; wheel++) {
157  for (int sector = 0; sector < 12; sector++) {
158  align::Scalars disp;
160  if (dist_ == 0) {
161  const std::vector<float> disp_ = theMuonModifier.gaussianRandomVector(dx, dy, dz);
162  const std::vector<float> rotation_ = theMuonModifier.gaussianRandomVector(phix, phiy, phiz);
163  disp.push_back(disp_[0]);
164  disp.push_back(disp_[1]);
165  disp.push_back(disp_[2]);
166  rotation.push_back(rotation_[0]);
167  rotation.push_back(rotation_[1]);
168  rotation.push_back(rotation_[2]);
169  } else if (dist_ == 1) {
170  const std::vector<float> disp_ = theMuonModifier.flatRandomVector(dx, dy, dz);
171  const std::vector<float> rotation_ = theMuonModifier.flatRandomVector(phix, phiy, phiz);
172  disp.push_back(disp_[0]);
173  disp.push_back(disp_[1]);
174  disp.push_back(disp_[2]);
175  rotation.push_back(rotation_[0]);
176  rotation.push_back(rotation_[1]);
177  rotation.push_back(rotation_[2]);
178  } else {
179  disp.push_back(dx);
180  disp.push_back(dy);
181  disp.push_back(dz);
182  rotation.push_back(phix);
183  rotation.push_back(phiy);
184  rotation.push_back(phiz);
185  }
186  for (int station = 0; station < 4; station++) {
187  Alignable* myAlign = DTchambers.at(index[wheel][station][sector]);
188  this->moveChamberInSector(myAlign, disp, rotation, errorDisp, errorRotation);
189  if (sector == 3 && station == 3) {
190  Alignable* myAlignD = DTchambers.at(index[wheel][station][12]);
191  this->moveChamberInSector(myAlignD, disp, rotation, errorDisp, errorRotation);
192  } else if (sector == 9 && station == 3) {
193  Alignable* myAlignD = DTchambers.at(index[wheel][station][13]);
194  this->moveChamberInSector(myAlignD, disp, rotation, errorDisp, errorRotation);
195  }
196  }
197  }
198  }
199 }
200 
201 //______________________________________________________________________________________________________
203  const auto& CSCchambers = theAlignableMuon->CSCChambers();
204  //Take Parameters
205  align::Scalars param = this->extractParameters(pSet, "CSCSectors");
206  double scale_ = param[0];
207  double scaleError_ = param[1];
208  double phiX_ = param[2];
209  double phiY_ = param[3];
210  double phiZ_ = param[4];
211  double dX_ = param[5];
212  double dY_ = param[6];
213  double dZ_ = param[7];
214  double dist_ = param[8];
215 
216  double dx = scale_ * dX_;
217  double dy = scale_ * dY_;
218  double dz = scale_ * dZ_;
219  double phix = scale_ * phiX_;
220  double phiy = scale_ * phiY_;
221  double phiz = scale_ * phiZ_;
222  double errorx = scaleError_ * dX_;
223  double errory = scaleError_ * dY_;
224  double errorz = scaleError_ * dZ_;
225  double errorphix = scaleError_ * phiX_;
226  double errorphiy = scaleError_ * phiY_;
227  double errorphiz = scaleError_ * phiZ_;
228  align::Scalars errorDisp;
229  errorDisp.push_back(errorx);
230  errorDisp.push_back(errory);
231  errorDisp.push_back(errorz);
232  align::Scalars errorRotation;
233  errorRotation.push_back(errorphix);
234  errorRotation.push_back(errorphiy);
235  errorRotation.push_back(errorphiz);
236 
237  int index[2][4][4][36];
238  int sector_index[2][4][4][36];
239  std::fill_n(index[0][0][0], 2 * 4 * 4 * 36, -1); // initialize to -1
240  std::fill_n(sector_index[0][0][0], 2 * 4 * 4 * 36, -1); // initialize to -1
241  int counter = 0;
242  //Create an index for the chambers in the alignable vector
243  for (const auto& iter : CSCchambers) {
244  CSCDetId myId(iter->geomDetId().rawId());
245  index[myId.endcap() - 1][myId.station() - 1][myId.ring() - 1][myId.chamber() - 1] = counter;
246  sector_index[myId.endcap() - 1][myId.station() - 1][myId.ring() - 1][myId.chamber() - 1] =
249  myId.station());
250  counter++;
251  }
252  for (int endcap = 0; endcap < 2; endcap++) {
253  for (int ring = 0; ring < 2; ring++) {
254  for (int sector = 1; sector < 7; sector++) {
255  align::Scalars disp;
257  if (dist_ == 0) {
258  const std::vector<float> disp_ = theMuonModifier.gaussianRandomVector(dx, dy, dz);
259  const std::vector<float> rotation_ = theMuonModifier.gaussianRandomVector(phix, phiy, phiz);
260  disp.push_back(disp_[0]);
261  disp.push_back(disp_[1]);
262  disp.push_back(disp_[2]);
263  rotation.push_back(rotation_[0]);
264  rotation.push_back(rotation_[1]);
265  rotation.push_back(rotation_[2]);
266  } else if (dist_ == 1) {
267  const std::vector<float> disp_ = theMuonModifier.flatRandomVector(dx, dy, dz);
268  const std::vector<float> rotation_ = theMuonModifier.flatRandomVector(phix, phiy, phiz);
269  disp.push_back(disp_[0]);
270  disp.push_back(disp_[1]);
271  disp.push_back(disp_[2]);
272  rotation.push_back(rotation_[0]);
273  rotation.push_back(rotation_[1]);
274  rotation.push_back(rotation_[2]);
275  } else {
276  disp.push_back(dx);
277  disp.push_back(dy);
278  disp.push_back(dz);
279  rotation.push_back(phix);
280  rotation.push_back(phiy);
281  rotation.push_back(phiz);
282  }
283  //Different cases are considered in order to fit endcap geometry
284  for (int station = 0; station < 4; station++) {
285  if (station == 0) {
286  int r_ring[2];
287  if (ring == 0) {
288  r_ring[0] = 0;
289  r_ring[1] = 3;
290  } else {
291  r_ring[0] = 1;
292  r_ring[1] = 2;
293  }
294  for (int r_counter = 0; r_counter < 2; r_counter++) {
295  for (int chamber = 0; chamber < 36; chamber++) {
296  if (sector == (sector_index[endcap][station][r_ring[r_counter]][chamber] + 1) / 2) {
297  Alignable* myAlign = CSCchambers.at(index[endcap][station][r_ring[r_counter]][chamber]);
298  this->moveChamberInSector(myAlign, disp, rotation, errorDisp, errorRotation);
299  }
300  }
301  }
302  } else if (station == 3 && ring == 1) {
303  continue;
304  } else {
305  for (int chamber = 0; chamber < 36; chamber++) {
306  if (ring == 0 && chamber > 17)
307  continue;
308  if (sector == sector_index[endcap][station][ring][chamber]) {
309  Alignable* myAlign = CSCchambers.at(index[endcap][station][ring][chamber]);
310  this->moveChamberInSector(myAlign, disp, rotation, errorDisp, errorRotation);
311  }
312  }
313  }
314  }
315  }
316  }
317  }
318 }
319 
320 //______________________________________________________________________________________________________
322  const auto& DTbarrel = theAlignableMuon->DTBarrel();
323  const auto& CSCendcaps = theAlignableMuon->CSCEndcaps();
324  //Take Parameters
325  align::Scalars param = this->extractParameters(pSet, "Muon");
326  double scale_ = param[0];
327  double scaleError_ = param[1];
328  double phiX_ = param[2];
329  double phiY_ = param[3];
330  double phiZ_ = param[4];
331  double dX_ = param[5];
332  double dY_ = param[6];
333  double dZ_ = param[7];
334  double dist_ = param[8];
335  double dx = scale_ * dX_;
336  double dy = scale_ * dY_;
337  double dz = scale_ * dZ_;
338  double phix = scale_ * phiX_;
339  double phiy = scale_ * phiY_;
340  double phiz = scale_ * phiZ_;
341  double errorx = scaleError_ * dX_;
342  double errory = scaleError_ * dY_;
343  double errorz = scaleError_ * dZ_;
344  double errorphix = scaleError_ * phiX_;
345  double errorphiy = scaleError_ * phiY_;
346  double errorphiz = scaleError_ * phiZ_;
347  //Create an index for the chambers in the alignable vector
348  align::Scalars disp;
350  if (dist_ == 0) {
351  const std::vector<float> disp_ = theMuonModifier.gaussianRandomVector(dx, dy, dz);
352  const std::vector<float> rotation_ = theMuonModifier.gaussianRandomVector(phix, phiy, phiz);
353  disp.push_back(disp_[0]);
354  disp.push_back(disp_[1]);
355  disp.push_back(disp_[2]);
356  rotation.push_back(rotation_[0]);
357  rotation.push_back(rotation_[1]);
358  rotation.push_back(rotation_[2]);
359  } else if (dist_ == 1) {
360  const std::vector<float> disp_ = theMuonModifier.flatRandomVector(dx, dy, dz);
361  const std::vector<float> rotation_ = theMuonModifier.flatRandomVector(phix, phiy, phiz);
362  disp.push_back(disp_[0]);
363  disp.push_back(disp_[1]);
364  disp.push_back(disp_[2]);
365  rotation.push_back(rotation_[0]);
366  rotation.push_back(rotation_[1]);
367  rotation.push_back(rotation_[2]);
368  } else {
369  disp.push_back(dx);
370  disp.push_back(dy);
371  disp.push_back(dz);
372  rotation.push_back(phix);
373  rotation.push_back(phiy);
374  rotation.push_back(phiz);
375  }
376  for (const auto& iter : DTbarrel) {
377  theMuonModifier.moveAlignable(iter, false, true, disp[0], disp[1], disp[2]);
378  theMuonModifier.rotateAlignable(iter, false, true, rotation[0], rotation[1], rotation[2]);
379  theMuonModifier.addAlignmentPositionError(iter, errorx, errory, errorz);
380  theMuonModifier.addAlignmentPositionErrorFromRotation(iter, errorphix, errorphiy, errorphiz);
381  }
382  for (const auto& iter : CSCendcaps) {
383  theMuonModifier.moveAlignable(iter, false, true, disp[0], disp[1], disp[2]);
384  theMuonModifier.rotateAlignable(iter, false, true, rotation[0], rotation[1], rotation[2]);
385  theMuonModifier.addAlignmentPositionError(iter, errorx, errory, errorz);
386  theMuonModifier.addAlignmentPositionErrorFromRotation(iter, errorphix, errorphiy, errorphiz);
387  }
388 }
389 
390 //______________________________________________________________________________________________________
392  const align::Scalars& _disp,
393  const align::Scalars& rotation,
394  const align::Scalars& dispError,
395  const align::Scalars& rotationError) {
396  align::Scalars disp = _disp;
397  align::RotationType rotx(Basic3DVector<double>(1.0, 0.0, 0.0), rotation[0]);
398  align::RotationType roty(Basic3DVector<double>(0.0, 1.0, 0.0), rotation[1]);
399  align::RotationType rotz(Basic3DVector<double>(0.0, 0.0, 1.0), rotation[2]);
400  align::RotationType rot = rotz * roty * rotx;
402  align::GlobalPoint dispRot(pos.basicVector() - rot * pos.basicVector());
403  disp[0] += dispRot.x();
404  disp[1] += dispRot.y();
405  disp[2] += dispRot.z();
406  theMuonModifier.moveAlignable(chamber, false, true, disp[0], disp[1], disp[2]);
407  theMuonModifier.rotateAlignable(chamber, false, true, rotation[0], rotation[1], rotation[2]);
408  theMuonModifier.addAlignmentPositionError(chamber, dispError[0], dispError[1], dispError[2]);
409  theMuonModifier.addAlignmentPositionErrorFromRotation(chamber, rotationError[0], rotationError[1], rotationError[2]);
410 }
T getParameter(std::string const &) const
Entry const & retrieve(char const *) const
edm::ParameterSet theScenario
Misalignment scenario to apply (from config file)
void decodeMovements_(const edm::ParameterSet &, const align::Alignables &)
Decode movements defined in given parameter set for given set of alignables.
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()
const std::vector< float > gaussianRandomVector(float sigmaX, float sigmaY, float sigmaZ) const
Return a vector of random numbers (gaussian distribution)
void moveMuon(const edm::ParameterSet &scenario)
this special method allows to move the complete muon system by a same amount
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 *)
align::Alignables CSCEndcaps()
vector< ParameterSet > Parameters
Class Geometry Contains vector for fit parameters (mean, sigma, etc.) obtained from multiple IOVs See...
Definition: DMRtrends.cc:183
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.
std::vector< std::string > getParameterNames() const
const std::vector< float > flatRandomVector(float sigmaX, float sigmaY, float sigmaZ) const
Return a vector of random numbers (flat distribution)
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)
static std::atomic< unsigned int > counter
char typeCode() const
Definition: Entry.h:176
void applyScenario(const edm::ParameterSet &scenario) override
Apply misalignment scenario to the Muon.
const PositionType & globalPosition() const
Return the global position of the object.
Definition: Alignable.h:135
int theModifierCounter
Counter for applied modification.
Constructor of the full muon geometry.
Definition: AlignableMuon.h:33
T x() const
Definition: PV3DBase.h:59
bool hasParameter_(const std::string &name, const edm::ParameterSet &pSet) const
Check if given parameter exists in parameter set.
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:53
edm::ParameterSet getParameterSet_(const std::string &name, const edm::ParameterSet &pSet) const