CMS 3D CMS Logo

MuonScenarioBuilder.cc
Go to the documentation of this file.
1 
9 #include <string>
10 #include <iostream>
11 #include <sstream>
12 #include <algorithm>
13 
14 // Framework
17 
18 // Alignment
19 
24 
25 //__________________________________________________________________________________________________
27  // muon alignable IDs are (currently) independent of the geometry
29 {
30 
31  theAlignableMuon = dynamic_cast<AlignableMuon*>( alignable );
32 
33  if ( !theAlignableMuon )
34  throw cms::Exception("TypeMismatch") << "Argument is not an AlignableMuon";
35 
36 }
37 
38 
39 //__________________________________________________________________________________________________
41 {
42  // Apply the scenario to all main components of Muon.
45 
46  // Seed is set at top-level, and is mandatory
47  if ( this->hasParameter_( "seed", theScenario ) )
48  theModifier.setSeed( static_cast<long>(theScenario.getParameter<int>("seed")) );
49  else
50  throw cms::Exception("BadConfig") << "No generator seed defined!";
51 
52 
53 
54  // DT Barrel
55  const auto& dtBarrel = theAlignableMuon->DTBarrel();
56  this->decodeMovements_( theScenario, dtBarrel, "DTBarrel" );
57  // CSC Endcap
58  const auto& cscEndcaps = theAlignableMuon->CSCEndcaps();
59  this->decodeMovements_( theScenario, cscEndcaps, "CSCEndcap" );
60 
63  this->moveMuon(theScenario);
64 
65  edm::LogInfo("TrackerScenarioBuilder")
66  << "Applied modifications to " << theModifierCounter << " alignables";
67 }
68 
69 
70 
72 {
73  double scale_ = 0, scaleError_ = 0, phiX_ = 0, phiY_ = 0, phiZ_ = 0;
74  double dX_ = 0, dY_ = 0, dZ_ = 0;
75  std::string distribution_;
76  std::ostringstream error;
78  std::vector<std::string> parameterNames = Parameters.getParameterNames();
79  for ( std::vector<std::string>::iterator iParam = parameterNames.begin(); iParam != parameterNames.end(); iParam++ ) {
80  if ( (*iParam) == "scale" ) scale_ = Parameters.getParameter<double>( *iParam );
81  else if ( (*iParam) == "distribution" ) distribution_ = Parameters.getParameter<std::string>( *iParam );
82  else if ( (*iParam) == "scaleError" ) scaleError_ = Parameters.getParameter<double>( *iParam );
83  else if ( (*iParam) == "phiX" ) phiX_ = Parameters.getParameter<double>( *iParam );
84  else if ( (*iParam) == "phiY" ) phiY_ = Parameters.getParameter<double>( *iParam );
85  else if ( (*iParam) == "phiZ" ) phiZ_ = Parameters.getParameter<double>( *iParam );
86  else if ( (*iParam) == "dX" ) dX_ = Parameters.getParameter<double>( *iParam );
87  else if ( (*iParam) == "dY" ) dY_ = Parameters.getParameter<double>( *iParam );
88  else if ( (*iParam) == "dZ" ) dZ_ = Parameters.getParameter<double>( *iParam );
89  else if ( Parameters.retrieve( *iParam ).typeCode() != 'P' )
90  { // Add unknown parameter to list
91  if ( !error.str().length() ) error << "Unknown parameter name(s): ";
92  error << " " << *iParam;
93  }
94  }
95  align::Scalars param;
96  param.push_back(scale_); param.push_back(scaleError_);
97  param.push_back(phiX_); param.push_back(phiY_);
98  param.push_back(phiZ_); param.push_back(dX_);
99  param.push_back(dY_); param.push_back(dZ_);
100  if( distribution_ == "gaussian" )
101  param.push_back(0);
102  else if ( distribution_ == "flat" )
103  param.push_back(1);
104  else if ( distribution_ == "fix" )
105  param.push_back(2);
106 
107  return param;
108 }
109 
110 //_____________________________________________________________________________________________________
112 {
113  const auto& DTchambers = theAlignableMuon->DTChambers();
114  //Take parameters
115  align::Scalars param = this->extractParameters(pSet, "DTSectors");
116  double scale_ = param[0]; double scaleError_ = param[1];
117  double phiX_ = param[2]; double phiY_ = param[3]; double phiZ_ = param[4];
118  double dX_ = param[5]; double dY_ = param[6]; double dZ_ = param[7];
119  double dist_ = param[8];
120 
121  double dx = scale_*dX_; double dy = scale_*dY_; double dz = scale_*dZ_;
122  double phix = scale_*phiX_; double phiy = scale_*phiY_; double phiz = scale_*phiZ_;
123  double errorx = scaleError_*dX_; double errory = scaleError_*dY_; double errorz = scaleError_*dZ_;
124  double errorphix = scaleError_*phiX_; double errorphiy = scaleError_*phiY_; double errorphiz = scaleError_*phiZ_;
125  align::Scalars errorDisp;
126  errorDisp.push_back(errorx); errorDisp.push_back(errory); errorDisp.push_back(errorz);
127  align::Scalars errorRotation;
128  errorRotation.push_back(errorphix); errorRotation.push_back(errorphiy); errorRotation.push_back(errorphiz);
129 
130  int index[5][4][14];
131  std::fill_n(index[0][0], 5*4*14, -1); // initialize to -1
132  int counter = 0;
133  //Create and index for the chambers in the Alignable vector
134  for(const auto& iter: DTchambers) {
135  DTChamberId myId(iter->geomDetId().rawId());
136  index[myId.wheel()+2][myId.station()-1][myId.sector()-1] = counter;
137  counter++;
138  }
139  for(int wheel = 0; wheel < 5; wheel++) {
140  for(int sector = 0; sector < 12; sector++) {
141  align::Scalars disp;
143  if( dist_ == 0 ) {
144  const std::vector<float> disp_ = theMuonModifier.gaussianRandomVector(dx, dy, dz);
145  const std::vector<float> rotation_ = theMuonModifier.gaussianRandomVector(phix, phiy, phiz);
146  disp.push_back(disp_[0]); disp.push_back(disp_[1]); disp.push_back(disp_[2]);
147  rotation.push_back(rotation_[0]); rotation.push_back(rotation_[1]); rotation.push_back(rotation_[2]);
148  } else if (dist_ == 1) {
149  const std::vector<float> disp_ = theMuonModifier.flatRandomVector(dx, dy, dz);
150  const std::vector<float> rotation_ = theMuonModifier.flatRandomVector(phix, phiy, phiz);
151  disp.push_back(disp_[0]); disp.push_back(disp_[1]); disp.push_back(disp_[2]);
152  rotation.push_back(rotation_[0]); rotation.push_back(rotation_[1]); rotation.push_back(rotation_[2]);
153  } else {
154  disp.push_back(dx); disp.push_back(dy); disp.push_back(dz);
155  rotation.push_back(phix); rotation.push_back(phiy); rotation.push_back(phiz);
156  }
157  for(int station = 0; station < 4; station++) {
158  Alignable *myAlign = DTchambers.at(index[wheel][station][sector]);
159  this->moveChamberInSector(myAlign, disp, rotation, errorDisp, errorRotation);
160  if(sector == 3 && station == 3) {
161  Alignable *myAlignD = DTchambers.at(index[wheel][station][12]);
162  this->moveChamberInSector(myAlignD, disp, rotation, errorDisp, errorRotation);
163  } else if(sector == 9 && station == 3) {
164  Alignable *myAlignD = DTchambers.at(index[wheel][station][13]);
165  this->moveChamberInSector(myAlignD, disp, rotation, errorDisp, errorRotation);
166  }
167  }
168  }
169  }
170 }
171 
172 
173 //______________________________________________________________________________________________________
175 {
176  const auto& CSCchambers = theAlignableMuon->CSCChambers();
177  //Take Parameters
178  align::Scalars param = this->extractParameters(pSet, "CSCSectors");
179  double scale_ = param[0]; double scaleError_ = param[1];
180  double phiX_ = param[2]; double phiY_ = param[3]; double phiZ_ = param[4];
181  double dX_ = param[5]; double dY_ = param[6]; double dZ_ = param[7];
182  double dist_ = param[8];
183 
184  double dx = scale_*dX_; double dy = scale_*dY_; double dz = scale_*dZ_;
185  double phix = scale_*phiX_; double phiy = scale_*phiY_; double phiz = scale_*phiZ_;
186  double errorx = scaleError_*dX_; double errory = scaleError_*dY_; double errorz = scaleError_*dZ_;
187  double errorphix = scaleError_*phiX_; double errorphiy = scaleError_*phiY_; double errorphiz = scaleError_*phiZ_;
188  align::Scalars errorDisp;
189  errorDisp.push_back(errorx); errorDisp.push_back(errory); errorDisp.push_back(errorz);
190  align::Scalars errorRotation;
191  errorRotation.push_back(errorphix); errorRotation.push_back(errorphiy); errorRotation.push_back(errorphiz);
192 
193  int index[2][4][4][36];
194  int sector_index[2][4][4][36];
195  std::fill_n(index[0][0][0], 2*4*4*36, -1); // initialize to -1
196  std::fill_n(sector_index[0][0][0], 2*4*4*36, -1); // initialize to -1
197  int counter = 0;
198  //Create an index for the chambers in the alignable vector
199  for(const auto& iter: CSCchambers) {
200  CSCDetId myId(iter->geomDetId().rawId());
201  index[myId.endcap()-1][myId.station()-1][myId.ring()-1][myId.chamber()-1] = counter;
202  sector_index[myId.endcap()-1][myId.station()-1][myId.ring()-1][myId.chamber()-1] = CSCTriggerNumbering::sectorFromTriggerLabels(CSCTriggerNumbering::triggerSectorFromLabels(myId),CSCTriggerNumbering::triggerSubSectorFromLabels(myId) , myId.station());
203  counter++;
204  }
205  for(int endcap = 0; endcap < 2; endcap++) {
206  for(int ring = 0; ring < 2; ring++) {
207  for(int sector = 1; sector < 7; sector++) {
208  align::Scalars disp;
210  if( dist_ == 0 ) {
211  const std::vector<float> disp_ = theMuonModifier.gaussianRandomVector(dx, dy, dz);
212  const std::vector<float> rotation_ = theMuonModifier.gaussianRandomVector(phix, phiy, phiz);
213  disp.push_back(disp_[0]); disp.push_back(disp_[1]); disp.push_back(disp_[2]);
214  rotation.push_back(rotation_[0]); rotation.push_back(rotation_[1]); rotation.push_back(rotation_[2]);
215  } else if (dist_ == 1) {
216  const std::vector<float> disp_ = theMuonModifier.flatRandomVector(dx, dy, dz);
217  const std::vector<float> rotation_ = theMuonModifier.flatRandomVector(phix, phiy, phiz);
218  disp.push_back(disp_[0]); disp.push_back(disp_[1]); disp.push_back(disp_[2]);
219  rotation.push_back(rotation_[0]); rotation.push_back(rotation_[1]); rotation.push_back(rotation_[2]);
220  } else {
221  disp.push_back(dx); disp.push_back(dy); disp.push_back(dz);
222  rotation.push_back(phix); rotation.push_back(phiy); rotation.push_back(phiz);
223  }
224  //Different cases are considered in order to fit endcap geometry
225  for(int station = 0; station < 4; station++) {
226  if(station == 0) {
227  int r_ring[2];
228  if(ring == 0) {
229  r_ring[0] = 0; r_ring[1] = 3;
230  } else {
231  r_ring[0] = 1; r_ring[1] = 2;
232  }
233  for(int r_counter = 0; r_counter < 2; r_counter++) {
234  for(int chamber = 0; chamber < 36; chamber++) {
235  if(sector == (sector_index[endcap][station][r_ring[r_counter]][chamber]+1)/2) {
236  Alignable *myAlign = CSCchambers.at(index[endcap][station][r_ring[r_counter]][chamber]);
237  this->moveChamberInSector(myAlign, disp, rotation, errorDisp, errorRotation);
238  }
239  }
240  }
241  } else if(station == 3 && ring == 1) {
242  continue;
243  } else {
244  for(int chamber = 0; chamber < 36; chamber++) {
245  if(ring == 0 && chamber > 17) continue;
246  if(sector == sector_index[endcap][station][ring][chamber]) {
247  Alignable *myAlign = CSCchambers.at(index[endcap][station][ring][chamber]);
248  this->moveChamberInSector(myAlign, disp, rotation, errorDisp, errorRotation);
249  }
250  }
251  }
252  }
253  }
254  }
255  }
256 }
257 
258 
259 //______________________________________________________________________________________________________
261 {
262  const auto& DTbarrel = theAlignableMuon->DTBarrel();
263  const auto& CSCendcaps = theAlignableMuon->CSCEndcaps();
264  //Take Parameters
265  align::Scalars param = this->extractParameters(pSet, "Muon");
266  double scale_ = param[0]; double scaleError_ = param[1];
267  double phiX_ = param[2]; double phiY_ = param[3]; double phiZ_ = param[4];
268  double dX_ = param[5]; double dY_ = param[6]; double dZ_ = param[7];
269  double dist_ = param[8];
270  double dx = scale_*dX_; double dy = scale_*dY_; double dz = scale_*dZ_;
271  double phix = scale_*phiX_; double phiy = scale_*phiY_; double phiz = scale_*phiZ_;
272  double errorx = scaleError_*dX_; double errory = scaleError_*dY_; double errorz = scaleError_*dZ_;
273  double errorphix = scaleError_*phiX_; double errorphiy = scaleError_*phiY_; double errorphiz = scaleError_*phiZ_;
274  //Create an index for the chambers in the alignable vector
275  align::Scalars disp;
277  if( dist_ == 0 ) {
278  const std::vector<float> disp_ = theMuonModifier.gaussianRandomVector(dx, dy, dz);
279  const std::vector<float> rotation_ = theMuonModifier.gaussianRandomVector(phix, phiy, phiz);
280  disp.push_back(disp_[0]); disp.push_back(disp_[1]); disp.push_back(disp_[2]);
281  rotation.push_back(rotation_[0]); rotation.push_back(rotation_[1]); rotation.push_back(rotation_[2]);
282  } else if (dist_ == 1) {
283  const std::vector<float> disp_ = theMuonModifier.flatRandomVector(dx, dy, dz);
284  const std::vector<float> rotation_ = theMuonModifier.flatRandomVector(phix, phiy, phiz);
285  disp.push_back(disp_[0]); disp.push_back(disp_[1]); disp.push_back(disp_[2]);
286  rotation.push_back(rotation_[0]); rotation.push_back(rotation_[1]); rotation.push_back(rotation_[2]);
287  } else {
288  disp.push_back(dx); disp.push_back(dy); disp.push_back(dz);
289  rotation.push_back(phix); rotation.push_back(phiy); rotation.push_back(phiz);
290  }
291  for(const auto& iter: DTbarrel) {
292  theMuonModifier.moveAlignable(iter, false, true, disp[0], disp[1], disp[2]);
293  theMuonModifier.rotateAlignable(iter, false, true, rotation[0], rotation[1], rotation[2]);
294  theMuonModifier.addAlignmentPositionError(iter, errorx, errory, errorz);
295  theMuonModifier.addAlignmentPositionErrorFromRotation(iter, errorphix, errorphiy, errorphiz);
296  }
297  for(const auto& iter: CSCendcaps) {
298  theMuonModifier.moveAlignable(iter, false, true, disp[0], disp[1], disp[2]);
299  theMuonModifier.rotateAlignable(iter, false, true, rotation[0], rotation[1], rotation[2]);
300  theMuonModifier.addAlignmentPositionError(iter, errorx, errory, errorz);
301  theMuonModifier.addAlignmentPositionErrorFromRotation(iter, errorphix, errorphiy, errorphiz);
302  }
303 }
304 
305 
306 //______________________________________________________________________________________________________
308 {
309  align::Scalars disp = _disp;
310  align::RotationType rotx( Basic3DVector<double>(1.0, 0.0, 0.0), rotation[0] );
311  align::RotationType roty( Basic3DVector<double>(0.0, 1.0, 0.0), rotation[1] );
312  align::RotationType rotz( Basic3DVector<double>(0.0, 0.0, 1.0), rotation[2] );
313  align::RotationType rot = rotz * roty * rotx;
315  align::GlobalPoint dispRot(pos.basicVector()-rot*pos.basicVector());
316  disp[0] += dispRot.x(); disp[1] += dispRot.y(); disp[2] += dispRot.z();
317  theMuonModifier.moveAlignable( chamber, false, true, disp[0], disp[1], disp[2] );
318  theMuonModifier.rotateAlignable( chamber, false, true, rotation[0], rotation[1], rotation[2] );
319  theMuonModifier.addAlignmentPositionError( chamber, dispError[0], dispError[1], dispError[2] );
320  theMuonModifier.addAlignmentPositionErrorFromRotation( chamber, rotationError[0], rotationError[1], rotationError[2] );
321 }
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:119
static int sectorFromTriggerLabels(int TriggerSector, int TriggerSubSector, int station)
align::Alignables DTChambers()
std::vector< Scalar > Scalars
Definition: Utilities.h:27
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:138
int theModifierCounter
Counter for applied modification.
Constructor of the full muon geometry.
Definition: AlignableMuon.h:37
T x() const
Definition: PV3DBase.h:62
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:56
edm::ParameterSet getParameterSet_(const std::string &name, const edm::ParameterSet &pSet) const