CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/Alignment/TrackerAlignment/plugins/TrackerSystematicMisalignments.cc

Go to the documentation of this file.
00001 #include "FWCore/Framework/interface/ESHandle.h"
00002 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00003 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeomBuilderFromGeometricDet.h"
00004 
00005 #include "Alignment/CommonAlignment/interface/SurveyDet.h"
00006 #include "Alignment/TrackerAlignment/interface/AlignableTracker.h"
00007 
00008 #include "CondFormats/Alignment/interface/Alignments.h"
00009 #include "CondFormats/AlignmentRecord/interface/TrackerAlignmentRcd.h"
00010 #include "CondFormats/Alignment/interface/AlignmentErrors.h"
00011 #include "CondFormats/AlignmentRecord/interface/TrackerAlignmentErrorRcd.h"
00012 
00013 #include "FWCore/Framework/interface/EventSetup.h"
00014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00015 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00016 
00017 #include "DataFormats/DetId/interface/DetId.h"
00018 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00019 #include "Geometry/TrackingGeometryAligner/interface/GeometryAligner.h"
00020 #include "CLHEP/Random/RandGauss.h"
00021 
00022 #include "Alignment/TrackerAlignment/plugins/TrackerSystematicMisalignments.h"
00023 
00024 #include "DataFormats/SiStripDetId/interface/SiStripDetId.h"  // for enums TID/TIB/etc.
00025 
00026 // Database
00027 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00028 #include "FWCore/ServiceRegistry/interface/Service.h"
00029 
00030 // -----------------------------------------------------------------
00031 // 2010-05-20 Frank Meier
00032 // Changed sign of z-correction, i.e. z-expansion is now an expansion
00033 // made some variables constant, removed obviously dead code and comments
00034 
00035 TrackerSystematicMisalignments::TrackerSystematicMisalignments(const edm::ParameterSet& cfg)
00036 {
00037         // use existing geometry
00038         m_fromDBGeom = cfg.getUntrackedParameter< bool > ("fromDBGeom");
00039         
00040         // constants
00041         m_radialEpsilon = cfg.getUntrackedParameter< double > ("radialEpsilon");
00042         m_telescopeEpsilon = cfg.getUntrackedParameter< double > ("telescopeEpsilon");
00043         m_layerRotEpsilon = cfg.getUntrackedParameter< double > ("layerRotEpsilon");
00044         m_bowingEpsilon = cfg.getUntrackedParameter< double > ("bowingEpsilon");
00045         m_zExpEpsilon = cfg.getUntrackedParameter< double > ("zExpEpsilon");
00046         m_twistEpsilon = cfg.getUntrackedParameter< double > ("twistEpsilon");
00047         m_ellipticalEpsilon = cfg.getUntrackedParameter< double > ("ellipticalEpsilon");
00048         m_skewEpsilon = cfg.getUntrackedParameter< double > ("skewEpsilon");
00049         m_saggitaEpsilon = cfg.getUntrackedParameter< double > ("saggitaEpsilon");
00050         
00051         if (m_radialEpsilon > -990.0){
00052                 edm::LogWarning("MisalignedTracker") << "Applying radial ...";          
00053         }
00054         if (m_telescopeEpsilon > -990.0){
00055                 edm::LogWarning("MisalignedTracker") << "Applying telescope ...";               
00056         }
00057         if (m_layerRotEpsilon > -990.0){
00058                 edm::LogWarning("MisalignedTracker") << "Applying layer rotation ...";          
00059         }
00060         if (m_bowingEpsilon > -990.0){
00061                 edm::LogWarning("MisalignedTracker") << "Applying bowing ...";          
00062         }
00063         if (m_zExpEpsilon > -990.0){
00064                 edm::LogWarning("MisalignedTracker") << "Applying z-expansion ...";             
00065         }
00066         if (m_twistEpsilon > -990.0){
00067                 edm::LogWarning("MisalignedTracker") << "Applying twist ...";           
00068         }
00069         if (m_ellipticalEpsilon > -990.0){
00070                 edm::LogWarning("MisalignedTracker") << "Applying elliptical ...";              
00071         }
00072         if (m_skewEpsilon > -990.0){
00073                 edm::LogWarning("MisalignedTracker") << "Applying skew ...";            
00074         }
00075         if (m_saggitaEpsilon > -990.0){
00076                 edm::LogWarning("MisalignedTracker") << "Applying saggita ...";         
00077         }
00078 
00079         // get flag for suppression of blind movements
00080         suppressBlindMvmts = cfg.getUntrackedParameter< bool > ("suppressBlindMvmts");
00081         if (suppressBlindMvmts)
00082         {
00083                 edm::LogWarning("MisalignedTracker") << "Blind movements suppressed (TIB/TOB in z, TID/TEC in r)";
00084         }
00085         
00086         // compatibility with old (weird) z convention
00087         oldMinusZconvention = cfg.getUntrackedParameter< bool > ("oldMinusZconvention");
00088         if (oldMinusZconvention)
00089         {
00090                 edm::LogWarning("MisalignedTracker") << "Old z convention: dz --> -dz";
00091         }
00092         else
00093         {
00094                 edm::LogWarning("MisalignedTracker") << "New z convention: dz --> dz";
00095         }
00096 
00097 }
00098 
00099 void TrackerSystematicMisalignments::beginJob()
00100 {
00101                 
00102 }
00103 
00104 
00105 void TrackerSystematicMisalignments::analyze(const edm::Event& event, const edm::EventSetup& setup){
00106         
00107         
00108         edm::ESHandle<GeometricDet>  geom;
00109         setup.get<IdealGeometryRecord>().get(geom);      
00110         TrackerGeometry* tracker = TrackerGeomBuilderFromGeometricDet().build(&*geom);
00111         
00112         //take geometry from DB or randomly generate geometry
00113         if (m_fromDBGeom){
00114                 //build the tracker
00115                 edm::ESHandle<Alignments> alignments;
00116                 edm::ESHandle<AlignmentErrors> alignmentErrors;
00117                 
00118                 setup.get<TrackerAlignmentRcd>().get(alignments);
00119                 setup.get<TrackerAlignmentErrorRcd>().get(alignmentErrors);
00120                 
00121                 //apply the latest alignments
00122                 GeometryAligner aligner;
00123                 aligner.applyAlignments<TrackerGeometry>( &(*tracker), &(*alignments), &(*alignmentErrors), AlignTransform() );
00124                 
00125         }
00126         
00127         theAlignableTracker = new AlignableTracker(&(*tracker));
00128         
00129         applySystematicMisalignment( &(*theAlignableTracker) );
00130         
00131         // -------------- writing out to alignment record --------------
00132         Alignments* myAlignments = theAlignableTracker->alignments() ;
00133         AlignmentErrors* myAlignmentErrors = theAlignableTracker->alignmentErrors() ;
00134         
00135         // Store alignment[Error]s to DB
00136         edm::Service<cond::service::PoolDBOutputService> poolDbService;
00137         std::string theAlignRecordName = "TrackerAlignmentRcd";
00138         std::string theErrorRecordName = "TrackerAlignmentErrorRcd";
00139         
00140         // Call service
00141         if( !poolDbService.isAvailable() ) // Die if not available
00142                 throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
00143         
00144         poolDbService->writeOne<Alignments>(&(*myAlignments), poolDbService->beginOfTime(), theAlignRecordName);
00145         poolDbService->writeOne<AlignmentErrors>(&(*myAlignmentErrors), poolDbService->beginOfTime(), theErrorRecordName);
00146 }
00147 
00148 void TrackerSystematicMisalignments::applySystematicMisalignment(Alignable* ali)
00149 {
00150         
00151         const align::Alignables& comp = ali->components();
00152         unsigned int nComp = comp.size();
00153         //move then do for lower level object
00154         //for issue of det vs detunit
00155         bool usecomps = true;
00156         if ((ali->alignableObjectId()==2)&&(nComp>=1)) usecomps = false;
00157         for (unsigned int i = 0; i < nComp; ++i){
00158                 if (usecomps) applySystematicMisalignment(comp[i]);
00159         }
00160 
00161         // if suppression of blind mvmts: check if subdet is blind to a certain mode
00162         bool blindToZ(false), blindToR(false);
00163         if (suppressBlindMvmts)
00164         {
00165                 const int subdetid = ali->geomDetId().subdetId();
00166                 switch(subdetid)
00167                 {
00168                         // TIB/TON blind to z
00169                         case SiStripDetId::TIB: 
00170                         case SiStripDetId::TOB: 
00171                                 blindToZ = true; 
00172                                 break;
00173                         // TID/TEC blind to R
00174                         case SiStripDetId::TID: 
00175                         case SiStripDetId::TEC: 
00176                                 blindToR = true; 
00177                                 break;
00178                         default: 
00179                                 break;
00180                 }
00181         }
00182 
00183         const int level = ali->alignableObjectId();     
00184         if ((level == 1)||(level == 2)){                
00185                 const align::PositionType gP = ali->globalPosition();
00186                 const align::GlobalVector gVec = findSystematicMis( gP, blindToZ, blindToR);
00187                 ali->move( gVec );
00188         }
00189 }        
00190 
00191 align::GlobalVector TrackerSystematicMisalignments::findSystematicMis( align::PositionType globalPos, const bool blindToZ, const bool blindToR ){
00192 //align::GlobalVector TrackerSystematicMisalignments::findSystematicMis( align::PositionType globalPos ){
00193         // calculates shift for the current alignable
00194         // all corrections are calculated w.r.t. the original geometry  
00195         double deltaX = 0.0;
00196         double deltaY = 0.0;
00197         double deltaZ = 0.0;
00198         const double oldX = globalPos.x();
00199         const double oldY = globalPos.y();
00200         const double oldZ = globalPos.z();
00201         const double oldPhi = globalPos.phi();
00202         const double oldR = sqrt(globalPos.x()*globalPos.x() + globalPos.y()*globalPos.y());
00203 
00204         if (m_radialEpsilon > -990.0 && !blindToR){
00205                 deltaX += m_radialEpsilon*oldX;
00206                 deltaY += m_radialEpsilon*oldY;
00207         }
00208         if (m_telescopeEpsilon > -990.0 && !blindToZ){
00209                 deltaZ += m_telescopeEpsilon*oldR;
00210         }
00211         if (m_layerRotEpsilon > -990.0){
00212                 // The following number was chosen such that the Layer Rotation systematic 
00213                 // misalignment would not cause an overall rotation of the tracker.
00214                 const double Roffset = 57.0;
00215                 const double xP = oldR*cos(oldPhi+m_layerRotEpsilon*(oldR-Roffset));
00216                 const double yP = oldR*sin(oldPhi+m_layerRotEpsilon*(oldR-Roffset));
00217                 deltaX += (xP - oldX);
00218                 deltaY += (yP - oldY);
00219         }
00220         if (m_bowingEpsilon > -990.0 && !blindToR){
00221                 const double trackeredgePlusZ=271.846;
00222                 const double bowfactor=m_bowingEpsilon*(trackeredgePlusZ*trackeredgePlusZ-oldZ*oldZ);
00223                 deltaX += oldX*bowfactor;
00224                 deltaY += oldY*bowfactor;
00225         }
00226         if (m_zExpEpsilon > -990.0 && !blindToZ){
00227                 deltaZ += oldZ*m_zExpEpsilon;
00228         }
00229         if (m_twistEpsilon > -990.0){
00230                 const double xP = oldR*cos(oldPhi+m_twistEpsilon*oldZ);
00231                 const double yP = oldR*sin(oldPhi+m_twistEpsilon*oldZ);
00232                 deltaX += (xP - oldX);
00233                 deltaY += (yP - oldY);
00234         }
00235         if (m_ellipticalEpsilon > -990.0 && !blindToR){
00236                 deltaX += oldX*m_ellipticalEpsilon*cos(2.0*oldPhi);
00237                 deltaY += oldY*m_ellipticalEpsilon*cos(2.0*oldPhi);
00238         }
00239         if (m_skewEpsilon > -990.0 && !blindToZ){
00240                 deltaZ += m_skewEpsilon*cos(oldPhi);
00241         }
00242         if (m_saggitaEpsilon > -990.0){
00243                 // deltaX += oldX/fabs(oldX)*m_saggitaEpsilon; // old one...
00244                 deltaY += oldR*m_saggitaEpsilon;
00245         }
00246 
00247         // Compatibility with old version <= 1.5
00248         if (oldMinusZconvention) deltaZ = -deltaZ;
00249         
00250         align::GlobalVector gV( deltaX, deltaY, deltaZ );
00251         return gV;
00252 }
00253 
00254 // Plug in to framework
00255 
00256 #include "FWCore/Framework/interface/MakerMacros.h"
00257 
00258 DEFINE_FWK_MODULE(TrackerSystematicMisalignments);