CMS 3D CMS Logo

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