CMS 3D CMS Logo

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