CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/Alignment/MuonAlignment/plugins/MisalignedMuonESProducer.cc

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012  
00013 
00014 // Framework
00015 #include "FWCore/Utilities/interface/Exception.h"
00016 #include "FWCore/Framework/interface/ESHandle.h"
00017 #include "FWCore/Framework/interface/ESTransientHandle.h"
00018 #include "FWCore/Framework/interface/ModuleFactory.h"
00019 #include "FWCore/Framework/interface/ESProducts.h"
00020 #include "FWCore/Framework/interface/ESProducer.h"
00021 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00022 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00023 
00024 // Conditions database
00025 #include "FWCore/ServiceRegistry/interface/Service.h"
00026 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00027 
00028 // Alignment
00029 #include "Alignment/MuonAlignment/interface/AlignableMuon.h"
00030 #include "Geometry/CSCGeometry/interface/CSCGeometry.h" 
00031 #include "Alignment/MuonAlignment/interface/MuonScenarioBuilder.h"
00032 #include "Alignment/CommonAlignment/interface/Alignable.h" 
00033 #include "Geometry/TrackingGeometryAligner/interface/GeometryAligner.h"
00034 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00035 #include "Geometry/DTGeometryBuilder/src/DTGeometryBuilderFromDDD.h"
00036 #include "Geometry/CSCGeometryBuilder/src/CSCGeometryBuilderFromDDD.h"
00037 
00038 #include <boost/shared_ptr.hpp>
00039 #include <memory>
00040 
00041 
00042 class MisalignedMuonESProducer: public edm::ESProducer
00043 {
00044 public:
00045 
00047   MisalignedMuonESProducer( const edm::ParameterSet & p );
00048   
00050   virtual ~MisalignedMuonESProducer(); 
00051   
00053   edm::ESProducts< boost::shared_ptr<DTGeometry>,
00054                                    boost::shared_ptr<CSCGeometry> > produce( const MuonGeometryRecord&  );
00055 
00057   void saveToDB();
00058   
00059 private:
00060   const bool theSaveToDB; 
00061   const edm::ParameterSet theScenario;  
00062 
00063   std::string theDTAlignRecordName, theDTErrorRecordName;
00064   std::string theCSCAlignRecordName, theCSCErrorRecordName;
00065   
00066   boost::shared_ptr<DTGeometry> theDTGeometry;
00067   boost::shared_ptr<CSCGeometry> theCSCGeometry;
00068 
00069   Alignments*      dt_Alignments;
00070   AlignmentErrors* dt_AlignmentErrors;
00071   Alignments*      csc_Alignments;
00072   AlignmentErrors* csc_AlignmentErrors;
00073 
00074 };
00075 
00076 //__________________________________________________________________________________________________
00077 //__________________________________________________________________________________________________
00078 //__________________________________________________________________________________________________
00079 
00080 
00081 //__________________________________________________________________________________________________
00082 MisalignedMuonESProducer::MisalignedMuonESProducer(const edm::ParameterSet& p) :
00083   theSaveToDB(p.getUntrackedParameter<bool>("saveToDbase")),
00084   theScenario(p.getParameter<edm::ParameterSet>("scenario")),
00085   theDTAlignRecordName( "DTAlignmentRcd" ),
00086   theDTErrorRecordName( "DTAlignmentErrorRcd" ),
00087   theCSCAlignRecordName( "CSCAlignmentRcd" ),
00088   theCSCErrorRecordName( "CSCAlignmentErrorRcd" )
00089 {
00090   
00091   setWhatProduced(this);
00092 
00093 }
00094 
00095 
00096 //__________________________________________________________________________________________________
00097 MisalignedMuonESProducer::~MisalignedMuonESProducer() {}
00098 
00099 
00100 //__________________________________________________________________________________________________
00101 edm::ESProducts< boost::shared_ptr<DTGeometry>, boost::shared_ptr<CSCGeometry> >
00102 MisalignedMuonESProducer::produce( const MuonGeometryRecord& iRecord )
00103 { 
00104 
00105   edm::LogInfo("MisalignedMuon") << "Producer called";
00106   
00107 
00108   // Create the Muon geometry from ideal geometry
00109   edm::ESTransientHandle<DDCompactView> cpv;
00110   iRecord.getRecord<IdealGeometryRecord>().get( cpv );
00111 
00112   edm::ESHandle<MuonDDDConstants> mdc;
00113   iRecord.getRecord<MuonNumberingRecord>().get(mdc);
00114 
00115   DTGeometryBuilderFromDDD  DTGeometryBuilder;
00116   CSCGeometryBuilderFromDDD CSCGeometryBuilder;
00117 
00118   theDTGeometry = boost::shared_ptr<DTGeometry>(new DTGeometry );
00119   DTGeometryBuilder.build(theDTGeometry,  &(*cpv), *mdc );
00120   theCSCGeometry  = boost::shared_ptr<CSCGeometry>( new CSCGeometry );
00121   CSCGeometryBuilder.build( theCSCGeometry,  &(*cpv), *mdc );
00122 
00123 
00124   // Create the alignable hierarchy
00125   AlignableMuon* theAlignableMuon = new AlignableMuon( &(*theDTGeometry) , &(*theCSCGeometry) );
00126 
00127   // Create misalignment scenario
00128   MuonScenarioBuilder scenarioBuilder( theAlignableMuon );
00129   scenarioBuilder.applyScenario( theScenario );
00130   
00131   // Get alignments and errors
00132   dt_Alignments = theAlignableMuon->dtAlignments() ;
00133   dt_AlignmentErrors = theAlignableMuon->dtAlignmentErrors();
00134   csc_Alignments = theAlignableMuon->cscAlignments();
00135   csc_AlignmentErrors = theAlignableMuon->cscAlignmentErrors();
00136 
00137  
00138   // Misalign the EventSetup geometry
00139   GeometryAligner aligner;
00140 
00141   aligner.applyAlignments<DTGeometry>( &(*theDTGeometry),
00142                                        dt_Alignments, 
00143                                        dt_AlignmentErrors,
00144                                        AlignTransform() );
00145   aligner.applyAlignments<CSCGeometry>( &(*theCSCGeometry ),
00146                                         csc_Alignments,
00147                                         csc_AlignmentErrors,
00148                                         AlignTransform() );  
00149 
00150   // Write alignments to DB
00151   if (theSaveToDB) this->saveToDB();
00152 
00153   edm::LogInfo("MisalignedMuon") << "Producer done";
00154 
00155   return edm::es::products( theDTGeometry, theCSCGeometry ); 
00156   
00157 }
00158 
00159 
00160 //__________________________________________________________________________________________________
00161 void MisalignedMuonESProducer::saveToDB( void )
00162 {
00163 
00164   // Call service
00165   edm::Service<cond::service::PoolDBOutputService> poolDbService;
00166   if( !poolDbService.isAvailable() ) // Die if not available
00167         throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
00168 
00169   // Store DT alignments and errors
00170   poolDbService->writeOne<Alignments>( &(*dt_Alignments), poolDbService->beginOfTime(), theDTAlignRecordName);
00171   poolDbService->writeOne<AlignmentErrors>( &(*dt_AlignmentErrors), poolDbService->beginOfTime(), theDTErrorRecordName);
00172 
00173   // Store CSC alignments and errors
00174   poolDbService->writeOne<Alignments>( &(*csc_Alignments), poolDbService->beginOfTime(), theCSCAlignRecordName);
00175   poolDbService->writeOne<AlignmentErrors>( &(*csc_AlignmentErrors), poolDbService->beginOfTime(), theCSCErrorRecordName);
00176 
00177 }
00178 //__________________________________________________________________________________________________
00179 
00180 DEFINE_FWK_EVENTSETUP_MODULE(MisalignedMuonESProducer);