CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_4/src/Alignment/MuonAlignment/src/MuonScenarioBuilder.cc

Go to the documentation of this file.
00001 
00009 #include <string>
00010 #include <iostream>
00011 #include <sstream>
00012 
00013 // Framework
00014 #include "FWCore/Utilities/interface/Exception.h"
00015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00016 
00017 // Alignment
00018 
00019 #include "Alignment/MuonAlignment/interface/MuonScenarioBuilder.h"
00020 #include "FWCore/ParameterSet/interface/ParameterSet.h" 
00021 #include "Alignment/CommonAlignment/interface/Alignable.h" 
00022 #include "DataFormats/MuonDetId/interface/CSCTriggerNumbering.h" 
00023 
00024 //__________________________________________________________________________________________________
00025 MuonScenarioBuilder::MuonScenarioBuilder( Alignable* alignable )
00026 {
00027 
00028   theAlignableMuon = dynamic_cast<AlignableMuon*>( alignable );
00029 
00030   if ( !theAlignableMuon )
00031     throw cms::Exception("TypeMismatch") << "Argument is not an AlignableMuon";
00032 
00033 }
00034 
00035 
00036 //__________________________________________________________________________________________________
00037 void MuonScenarioBuilder::applyScenario( const edm::ParameterSet& scenario )
00038 {
00039   // Apply the scenario to all main components of Muon.
00040   theScenario = scenario;
00041   theModifierCounter = 0;
00042 
00043   // Seed is set at top-level, and is mandatory
00044   if ( this->hasParameter_( "seed", theScenario ) )
00045         theModifier.setSeed( static_cast<long>(theScenario.getParameter<int>("seed")) );
00046   else
00047         throw cms::Exception("BadConfig") << "No generator seed defined!";  
00048 
00049 
00050 
00051   // DT Barrel
00052   std::vector<Alignable*> dtBarrel = theAlignableMuon->DTBarrel();
00053   this->decodeMovements_( theScenario, dtBarrel, "DTBarrel" );
00054   // CSC Endcap
00055   std::vector<Alignable*> cscEndcaps = theAlignableMuon->CSCEndcaps();
00056   this->decodeMovements_( theScenario, cscEndcaps, "CSCEndcap" );
00057 
00058   this->moveDTSectors(theScenario);
00059   this->moveCSCSectors(theScenario);
00060   this->moveMuon(theScenario);
00061   
00062   edm::LogInfo("TrackerScenarioBuilder") 
00063         << "Applied modifications to " << theModifierCounter << " alignables";
00064 }
00065 
00066 
00067 
00068 align::Scalars MuonScenarioBuilder::extractParameters(const edm::ParameterSet& pSet, const char *blockId)
00069 {
00070   double scale_ = 0, scaleError_ = 0, phiX_ = 0, phiY_ = 0, phiZ_ = 0;
00071   double dX_ = 0, dY_ = 0, dZ_ = 0;
00072   std::string distribution_;
00073   std::ostringstream error;
00074   edm::ParameterSet Parameters = this->getParameterSet_((std::string)blockId, pSet);
00075   std::vector<std::string> parameterNames = Parameters.getParameterNames();
00076   for ( std::vector<std::string>::iterator iParam = parameterNames.begin(); iParam != parameterNames.end(); iParam++ ) {
00077     if ( (*iParam) == "scale" )    scale_ = Parameters.getParameter<double>( *iParam );
00078     else if ( (*iParam) == "distribution" ) distribution_ = Parameters.getParameter<std::string>( *iParam );
00079     else if ( (*iParam) == "scaleError" ) scaleError_ = Parameters.getParameter<double>( *iParam );
00080     else if ( (*iParam) == "phiX" )     phiX_     = Parameters.getParameter<double>( *iParam );
00081     else if ( (*iParam) == "phiY" )     phiY_     = Parameters.getParameter<double>( *iParam );
00082     else if ( (*iParam) == "phiZ" )     phiZ_     = Parameters.getParameter<double>( *iParam );
00083     else if ( (*iParam) == "dX" )       dX_       = Parameters.getParameter<double>( *iParam );
00084     else if ( (*iParam) == "dY" )       dY_       = Parameters.getParameter<double>( *iParam );
00085     else if ( (*iParam) == "dZ" )       dZ_       = Parameters.getParameter<double>( *iParam );
00086     else if ( Parameters.retrieve( *iParam ).typeCode() != 'P' )
00087       { // Add unknown parameter to list
00088         if ( !error.str().length() ) error << "Unknown parameter name(s): ";
00089         error << " " << *iParam;
00090       }
00091   }
00092   align::Scalars param;
00093   param.push_back(scale_); param.push_back(scaleError_);
00094   param.push_back(phiX_); param.push_back(phiY_);
00095   param.push_back(phiZ_); param.push_back(dX_);
00096   param.push_back(dY_); param.push_back(dZ_);
00097   if( distribution_ == "gaussian" )
00098     param.push_back(0);
00099   else if ( distribution_ == "flat" )
00100     param.push_back(1);
00101   else if ( distribution_ == "fix" )
00102     param.push_back(2);
00103   
00104   return param;
00105 }
00106 
00107 //_____________________________________________________________________________________________________
00108 void MuonScenarioBuilder::moveDTSectors(const edm::ParameterSet& pSet)
00109 {
00110   std::vector<Alignable *> DTchambers = theAlignableMuon->DTChambers();
00111   //Take parameters
00112   align::Scalars param = this->extractParameters(pSet, "DTSectors");
00113   double scale_ = param[0]; double scaleError_ = param[1];
00114   double phiX_ = param[2]; double phiY_ = param[3]; double phiZ_ = param[4];
00115   double dX_ = param[5]; double dY_ = param[6]; double dZ_ = param[7];
00116   double dist_ = param[8];
00117 
00118   double dx = scale_*dX_; double dy = scale_*dY_; double dz = scale_*dZ_;
00119   double phix = scale_*phiX_; double phiy = scale_*phiY_; double phiz = scale_*phiZ_;
00120   double errorx = scaleError_*dX_; double errory = scaleError_*dY_; double errorz = scaleError_*dZ_;
00121   double errorphix = scaleError_*phiX_; double errorphiy = scaleError_*phiY_; double errorphiz = scaleError_*phiZ_;
00122   align::Scalars errorDisp;
00123   errorDisp.push_back(errorx); errorDisp.push_back(errory); errorDisp.push_back(errorz);
00124   align::Scalars errorRotation;
00125   errorRotation.push_back(errorphix); errorRotation.push_back(errorphiy); errorRotation.push_back(errorphiz);
00126  
00127   int index[5][4][14];
00128   int counter = 0;
00129   //Create and index for the chambers in the Alignable vector
00130   for(std::vector<Alignable *>::iterator iter = DTchambers.begin(); iter != DTchambers.end(); ++iter) {
00131     DTChamberId myId((*iter)->geomDetId().rawId());
00132     index[myId.wheel()+2][myId.station()-1][myId.sector()-1] = counter;
00133     counter++;
00134   }
00135   for(int wheel = 0; wheel < 5; wheel++) {
00136     for(int sector = 0; sector < 12; sector++) {
00137       align::Scalars disp;
00138       align::Scalars rotation;
00139       if( dist_ == 0 ) {
00140         const std::vector<float> disp_ = theMuonModifier.gaussianRandomVector(dx, dy, dz);
00141         const std::vector<float> rotation_ = theMuonModifier.gaussianRandomVector(phix, phiy, phiz);
00142         disp.push_back(disp_[0]); disp.push_back(disp_[1]); disp.push_back(disp_[2]);
00143         rotation.push_back(rotation_[0]); rotation.push_back(rotation_[1]); rotation.push_back(rotation_[2]);
00144       } else if (dist_ == 1) {
00145         const std::vector<float> disp_ = theMuonModifier.flatRandomVector(dx, dy, dz);
00146         const std::vector<float> rotation_ = theMuonModifier.flatRandomVector(phix, phiy, phiz);
00147         disp.push_back(disp_[0]); disp.push_back(disp_[1]); disp.push_back(disp_[2]);
00148         rotation.push_back(rotation_[0]); rotation.push_back(rotation_[1]); rotation.push_back(rotation_[2]);
00149       } else {
00150         disp.push_back(dx); disp.push_back(dy); disp.push_back(dz);
00151         rotation.push_back(phix); rotation.push_back(phiy); rotation.push_back(phiz);
00152       }
00153       for(int station = 0; station < 4; station++) {
00154         Alignable *myAlign = DTchambers.at(index[wheel][station][sector]);
00155         this->moveChamberInSector(myAlign, disp, rotation, errorDisp, errorRotation);
00156         if(sector == 3 && station == 3) {
00157           Alignable *myAlignD = DTchambers.at(index[wheel][station][12]);
00158           this->moveChamberInSector(myAlignD, disp, rotation, errorDisp, errorRotation);
00159         } else if(sector == 9 && station == 3) {
00160           Alignable *myAlignD = DTchambers.at(index[wheel][station][13]);
00161           this->moveChamberInSector(myAlignD, disp, rotation, errorDisp, errorRotation);
00162         }
00163       }
00164     }
00165   } 
00166 }
00167 
00168 
00169 //______________________________________________________________________________________________________
00170 void MuonScenarioBuilder::moveCSCSectors(const edm::ParameterSet& pSet)
00171 {
00172   std::vector<Alignable *> CSCchambers = theAlignableMuon->CSCChambers();
00173   //Take Parameters
00174   align::Scalars param = this->extractParameters(pSet, "CSCSectors");
00175   double scale_ = param[0]; double scaleError_ = param[1];
00176   double phiX_ = param[2]; double phiY_ = param[3]; double phiZ_ = param[4];
00177   double dX_ = param[5]; double dY_ = param[6]; double dZ_ = param[7];
00178   double dist_ = param[8];
00179   
00180   double dx = scale_*dX_; double dy = scale_*dY_; double dz = scale_*dZ_;
00181   double phix = scale_*phiX_; double phiy = scale_*phiY_; double phiz = scale_*phiZ_;
00182   double errorx = scaleError_*dX_; double errory = scaleError_*dY_; double errorz = scaleError_*dZ_;
00183   double errorphix = scaleError_*phiX_; double errorphiy = scaleError_*phiY_; double errorphiz = scaleError_*phiZ_;
00184   align::Scalars errorDisp;
00185   errorDisp.push_back(errorx); errorDisp.push_back(errory); errorDisp.push_back(errorz);
00186   align::Scalars errorRotation;
00187   errorRotation.push_back(errorphix); errorRotation.push_back(errorphiy); errorRotation.push_back(errorphiz);
00188   
00189   int index[2][4][4][36];
00190   int sector_index[2][4][4][36];
00191   int counter = 0;
00192   //Create an index for the chambers in the alignable vector
00193   for(std::vector<Alignable *>::iterator iter = CSCchambers.begin(); iter != CSCchambers.end(); ++iter) {
00194     CSCDetId myId((*iter)->geomDetId().rawId());
00195     index[myId.endcap()-1][myId.station()-1][myId.ring()-1][myId.chamber()-1] = counter;
00196     sector_index[myId.endcap()-1][myId.station()-1][myId.ring()-1][myId.chamber()-1] = CSCTriggerNumbering::sectorFromTriggerLabels(CSCTriggerNumbering::triggerSectorFromLabels(myId),CSCTriggerNumbering::triggerSubSectorFromLabels(myId) , myId.station());
00197     counter++;
00198   }
00199   for(int endcap = 0; endcap < 2; endcap++) {
00200     for(int ring = 0; ring < 2; ring++) {
00201       for(int sector = 1; sector < 7; sector++) {
00202         align::Scalars disp;
00203         align::Scalars rotation;
00204         if( dist_ == 0 ) {
00205           const std::vector<float> disp_ = theMuonModifier.gaussianRandomVector(dx, dy, dz);
00206           const std::vector<float> rotation_ = theMuonModifier.gaussianRandomVector(phix, phiy, phiz);
00207           disp.push_back(disp_[0]); disp.push_back(disp_[1]); disp.push_back(disp_[2]);
00208           rotation.push_back(rotation_[0]); rotation.push_back(rotation_[1]); rotation.push_back(rotation_[2]);
00209         } else if (dist_ == 1) {
00210           const std::vector<float> disp_ = theMuonModifier.flatRandomVector(dx, dy, dz);
00211           const std::vector<float> rotation_ = theMuonModifier.flatRandomVector(phix, phiy, phiz);
00212           disp.push_back(disp_[0]); disp.push_back(disp_[1]); disp.push_back(disp_[2]);
00213           rotation.push_back(rotation_[0]); rotation.push_back(rotation_[1]); rotation.push_back(rotation_[2]);
00214         } else {
00215           disp.push_back(dx); disp.push_back(dy); disp.push_back(dz);
00216           rotation.push_back(phix); rotation.push_back(phiy); rotation.push_back(phiz);
00217         }
00218         //Different cases are considered in order to fit endcap geometry
00219         for(int station = 0; station < 4; station++) {
00220           if(station == 0) {
00221             int r_ring[2];
00222             if(ring == 0) {
00223               r_ring[0] = 0; r_ring[1] = 3;
00224             } else {
00225               r_ring[0] = 1; r_ring[1] = 2;
00226             }
00227             for(int r_counter = 0; r_counter < 2; r_counter++) {
00228               for(int chamber = 0; chamber < 36; chamber++) {
00229                 if(sector == (sector_index[endcap][station][r_ring[r_counter]][chamber]+1)/2) {
00230                   Alignable *myAlign = CSCchambers.at(index[endcap][station][r_ring[r_counter]][chamber]);
00231                   this->moveChamberInSector(myAlign, disp, rotation, errorDisp, errorRotation);
00232                 }
00233               }
00234             }
00235           } else if(station == 3 && ring == 1) {
00236             continue;
00237           } else {
00238             for(int chamber = 0; chamber < 36; chamber++) {
00239               if(ring == 0 && chamber > 17) continue;
00240               if(sector == sector_index[endcap][station][ring][chamber]) {
00241                 Alignable *myAlign = CSCchambers.at(index[endcap][station][ring][chamber]);
00242                 this->moveChamberInSector(myAlign, disp, rotation, errorDisp, errorRotation);
00243               }
00244             }
00245           }
00246         }
00247       }
00248     }
00249   }
00250 }
00251 
00252 
00253 //______________________________________________________________________________________________________
00254 void MuonScenarioBuilder::moveMuon(const edm::ParameterSet& pSet)
00255 {
00256   std::vector<Alignable *> DTbarrel = theAlignableMuon->DTBarrel();     
00257   std::vector<Alignable *> CSCendcaps = theAlignableMuon->CSCEndcaps();  
00258   //Take Parameters
00259   align::Scalars param = this->extractParameters(pSet, "Muon");
00260   double scale_ = param[0]; double scaleError_ = param[1];
00261   double phiX_ = param[2]; double phiY_ = param[3]; double phiZ_ = param[4];
00262   double dX_ = param[5]; double dY_ = param[6]; double dZ_ = param[7];
00263   double dist_ = param[8]; 
00264   double dx = scale_*dX_; double dy = scale_*dY_; double dz = scale_*dZ_;
00265   double phix = scale_*phiX_; double phiy = scale_*phiY_; double phiz = scale_*phiZ_;
00266   double errorx = scaleError_*dX_; double errory = scaleError_*dY_; double errorz = scaleError_*dZ_;
00267   double errorphix = scaleError_*phiX_; double errorphiy = scaleError_*phiY_; double errorphiz = scaleError_*phiZ_;
00268   //Create an index for the chambers in the alignable vector
00269   align::Scalars disp;
00270   align::Scalars rotation;
00271   if( dist_ == 0 ) {
00272     const std::vector<float> disp_ = theMuonModifier.gaussianRandomVector(dx, dy, dz);
00273     const std::vector<float> rotation_ = theMuonModifier.gaussianRandomVector(phix, phiy, phiz);
00274     disp.push_back(disp_[0]); disp.push_back(disp_[1]); disp.push_back(disp_[2]);
00275     rotation.push_back(rotation_[0]); rotation.push_back(rotation_[1]); rotation.push_back(rotation_[2]);
00276   } else if (dist_ == 1) {
00277     const std::vector<float> disp_ = theMuonModifier.flatRandomVector(dx, dy, dz);
00278     const std::vector<float> rotation_ = theMuonModifier.flatRandomVector(phix, phiy, phiz);
00279     disp.push_back(disp_[0]); disp.push_back(disp_[1]); disp.push_back(disp_[2]);
00280     rotation.push_back(rotation_[0]); rotation.push_back(rotation_[1]); rotation.push_back(rotation_[2]);
00281   } else {
00282     disp.push_back(dx); disp.push_back(dy); disp.push_back(dz);
00283     rotation.push_back(phix); rotation.push_back(phiy); rotation.push_back(phiz);
00284   }
00285   for(std::vector<Alignable *>::iterator iter = DTbarrel.begin(); iter != DTbarrel.end(); ++iter) {
00286     theMuonModifier.moveAlignable( *iter, false, true, disp[0], disp[1], disp[2] );
00287     theMuonModifier.rotateAlignable( *iter, false, true, rotation[0],  rotation[1], rotation[2] );
00288     theMuonModifier.addAlignmentPositionError( *iter, errorx, errory, errorz );
00289     theMuonModifier.addAlignmentPositionErrorFromRotation( *iter,  errorphix, errorphiy, errorphiz ); 
00290   }
00291   for(std::vector<Alignable *>::iterator iter = CSCendcaps.begin(); iter != CSCendcaps.end(); ++iter) {
00292     theMuonModifier.moveAlignable( *iter, false, true, disp[0], disp[1], disp[2] );
00293     theMuonModifier.rotateAlignable( *iter, false, true, rotation[0],  rotation[1], rotation[2] );
00294     theMuonModifier.addAlignmentPositionError( *iter, errorx, errory, errorz );
00295     theMuonModifier.addAlignmentPositionErrorFromRotation( *iter,  errorphix, errorphiy, errorphiz ); 
00296   }
00297 }
00298 
00299 
00300 //______________________________________________________________________________________________________
00301 void MuonScenarioBuilder::moveChamberInSector(Alignable *chamber, align::Scalars disp, align::Scalars rotation, align::Scalars dispError, align::Scalars rotationError)
00302 {
00303     align::RotationType rotx( Basic3DVector<double>(1.0, 0.0, 0.0), rotation[0] );
00304     align::RotationType roty( Basic3DVector<double>(0.0, 1.0, 0.0), rotation[1] );
00305     align::RotationType rotz( Basic3DVector<double>(0.0, 0.0, 1.0), rotation[2] );
00306     align::RotationType rot = rotz * roty * rotx;
00307     align::GlobalPoint pos = chamber->globalPosition();
00308     align::GlobalPoint dispRot(pos.basicVector()-rot*pos.basicVector());
00309     disp[0] += dispRot.x(); disp[1] += dispRot.y(); disp[2] += dispRot.z();
00310     theMuonModifier.moveAlignable( chamber, false, true, disp[0], disp[1], disp[2] );
00311     theMuonModifier.rotateAlignable( chamber, false, true, rotation[0],  rotation[1], rotation[2] );
00312     theMuonModifier.addAlignmentPositionError( chamber, dispError[0], dispError[1], dispError[2] );
00313     theMuonModifier.addAlignmentPositionErrorFromRotation( chamber,  rotationError[0], rotationError[1], rotationError[2] );
00314 }