CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/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         //Retrieve tracker topology from geometry
00110         edm::ESHandle<TrackerTopology> tTopoHandle;
00111         setup.get<IdealGeometryRecord>().get(tTopoHandle);
00112         const TrackerTopology* const tTopo = tTopoHandle.product();
00113         
00114         edm::ESHandle<GeometricDet>  geom;
00115         setup.get<IdealGeometryRecord>().get(geom);      
00116         TrackerGeometry* tracker = TrackerGeomBuilderFromGeometricDet().build(&*geom, theParameterSet);
00117         
00118         //take geometry from DB or randomly generate geometry
00119         if (m_fromDBGeom){
00120                 //build the tracker
00121                 edm::ESHandle<Alignments> alignments;
00122                 edm::ESHandle<AlignmentErrors> alignmentErrors;
00123                 
00124                 setup.get<TrackerAlignmentRcd>().get(alignments);
00125                 setup.get<TrackerAlignmentErrorRcd>().get(alignmentErrors);
00126                 
00127                 //apply the latest alignments
00128                 GeometryAligner aligner;
00129                 aligner.applyAlignments<TrackerGeometry>( &(*tracker), &(*alignments), &(*alignmentErrors), AlignTransform() );
00130                 
00131         }
00132         
00133         theAlignableTracker = new AlignableTracker(&(*tracker), tTopo);
00134         
00135         applySystematicMisalignment( &(*theAlignableTracker) );
00136         
00137         // -------------- writing out to alignment record --------------
00138         Alignments* myAlignments = theAlignableTracker->alignments() ;
00139         AlignmentErrors* myAlignmentErrors = theAlignableTracker->alignmentErrors() ;
00140         
00141         // Store alignment[Error]s to DB
00142         edm::Service<cond::service::PoolDBOutputService> poolDbService;
00143         std::string theAlignRecordName = "TrackerAlignmentRcd";
00144         std::string theErrorRecordName = "TrackerAlignmentErrorRcd";
00145         
00146         // Call service
00147         if( !poolDbService.isAvailable() ) // Die if not available
00148                 throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
00149         
00150         poolDbService->writeOne<Alignments>(&(*myAlignments), poolDbService->beginOfTime(), theAlignRecordName);
00151         poolDbService->writeOne<AlignmentErrors>(&(*myAlignmentErrors), poolDbService->beginOfTime(), theErrorRecordName);
00152 }
00153 
00154 void TrackerSystematicMisalignments::applySystematicMisalignment(Alignable* ali)
00155 {
00156         
00157         const align::Alignables& comp = ali->components();
00158         unsigned int nComp = comp.size();
00159         //move then do for lower level object
00160         //for issue of det vs detunit
00161         bool usecomps = true;
00162         if ((ali->alignableObjectId()==2)&&(nComp>=1)) usecomps = false;
00163         for (unsigned int i = 0; i < nComp; ++i){
00164                 if (usecomps) applySystematicMisalignment(comp[i]);
00165         }
00166 
00167         // if suppression of blind mvmts: check if subdet is blind to a certain mode
00168         bool blindToZ(false), blindToR(false);
00169         if (suppressBlindMvmts)
00170         {
00171                 const int subdetid = ali->geomDetId().subdetId();
00172                 switch(subdetid)
00173                 {
00174                         // TIB/TON blind to z
00175                         case SiStripDetId::TIB: 
00176                         case SiStripDetId::TOB: 
00177                                 blindToZ = true; 
00178                                 break;
00179                         // TID/TEC blind to R
00180                         case SiStripDetId::TID: 
00181                         case SiStripDetId::TEC: 
00182                                 blindToR = true; 
00183                                 break;
00184                         default: 
00185                                 break;
00186                 }
00187         }
00188 
00189         const int level = ali->alignableObjectId();     
00190         if ((level == 1)||(level == 2)){                
00191                 const align::PositionType gP = ali->globalPosition();
00192                 const align::GlobalVector gVec = findSystematicMis( gP, blindToZ, blindToR);
00193                 ali->move( gVec );
00194         }
00195 }        
00196 
00197 align::GlobalVector TrackerSystematicMisalignments::findSystematicMis( align::PositionType globalPos, const bool blindToZ, const bool blindToR ){
00198 //align::GlobalVector TrackerSystematicMisalignments::findSystematicMis( align::PositionType globalPos ){
00199         // calculates shift for the current alignable
00200         // all corrections are calculated w.r.t. the original geometry  
00201         double deltaX = 0.0;
00202         double deltaY = 0.0;
00203         double deltaZ = 0.0;
00204         const double oldX = globalPos.x();
00205         const double oldY = globalPos.y();
00206         const double oldZ = globalPos.z();
00207         const double oldPhi = globalPos.phi();
00208         const double oldR = sqrt(globalPos.x()*globalPos.x() + globalPos.y()*globalPos.y());
00209 
00210         if (m_radialEpsilon > -990.0 && !blindToR){
00211                 deltaX += m_radialEpsilon*oldX;
00212                 deltaY += m_radialEpsilon*oldY;
00213         }
00214         if (m_telescopeEpsilon > -990.0 && !blindToZ){
00215                 deltaZ += m_telescopeEpsilon*oldR;
00216         }
00217         if (m_layerRotEpsilon > -990.0){
00218                 // The following number was chosen such that the Layer Rotation systematic 
00219                 // misalignment would not cause an overall rotation of the tracker.
00220                 const double Roffset = 57.0;
00221                 const double xP = oldR*cos(oldPhi+m_layerRotEpsilon*(oldR-Roffset));
00222                 const double yP = oldR*sin(oldPhi+m_layerRotEpsilon*(oldR-Roffset));
00223                 deltaX += (xP - oldX);
00224                 deltaY += (yP - oldY);
00225         }
00226         if (m_bowingEpsilon > -990.0 && !blindToR){
00227                 const double trackeredgePlusZ=271.846;
00228                 const double bowfactor=m_bowingEpsilon*(trackeredgePlusZ*trackeredgePlusZ-oldZ*oldZ);
00229                 deltaX += oldX*bowfactor;
00230                 deltaY += oldY*bowfactor;
00231         }
00232         if (m_zExpEpsilon > -990.0 && !blindToZ){
00233                 deltaZ += oldZ*m_zExpEpsilon;
00234         }
00235         if (m_twistEpsilon > -990.0){
00236                 const double xP = oldR*cos(oldPhi+m_twistEpsilon*oldZ);
00237                 const double yP = oldR*sin(oldPhi+m_twistEpsilon*oldZ);
00238                 deltaX += (xP - oldX);
00239                 deltaY += (yP - oldY);
00240         }
00241         if (m_ellipticalEpsilon > -990.0 && !blindToR){
00242                 deltaX += oldX*m_ellipticalEpsilon*cos(2.0*oldPhi);
00243                 deltaY += oldY*m_ellipticalEpsilon*cos(2.0*oldPhi);
00244         }
00245         if (m_skewEpsilon > -990.0 && !blindToZ){
00246                 deltaZ += m_skewEpsilon*cos(oldPhi);
00247         }
00248         if (m_saggitaEpsilon > -990.0){
00249                 // deltaX += oldX/fabs(oldX)*m_saggitaEpsilon; // old one...
00250                 deltaY += oldR*m_saggitaEpsilon;
00251         }
00252 
00253         // Compatibility with old version <= 1.5
00254         if (oldMinusZconvention) deltaZ = -deltaZ;
00255         
00256         align::GlobalVector gV( deltaX, deltaY, deltaZ );
00257         return gV;
00258 }
00259 
00260 // Plug in to framework
00261 
00262 #include "FWCore/Framework/interface/MakerMacros.h"
00263 
00264 DEFINE_FWK_MODULE(TrackerSystematicMisalignments);