CMS 3D CMS Logo

AlignmentMonitorAsAnalyzer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    AlignmentMonitorAsAnalyzer
00004 // Class:      AlignmentMonitorAsAnalyzer
00005 // 
00013 //
00014 // Original Author:  Jim Pivarski
00015 //         Created:  Sat Apr 26 12:36:13 CDT 2008
00016 // $Id: AlignmentMonitorAsAnalyzer.cc,v 1.1 2008/04/27 01:57:40 pivarski Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 
00024 // user include files
00025 #include "FWCore/Framework/interface/Frameworkfwd.h"
00026 #include "FWCore/Framework/interface/EDAnalyzer.h"
00027 #include "FWCore/Framework/interface/Event.h"
00028 #include "FWCore/Framework/interface/MakerMacros.h"
00029 #include "FWCore/Framework/interface/ESHandle.h"
00030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00031 
00032 #include "Alignment/CommonAlignmentMonitor/interface/AlignmentMonitorBase.h"
00033 #include "Alignment/CommonAlignmentMonitor/interface/AlignmentMonitorPluginFactory.h"
00034 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
00035 #include "Alignment/CommonAlignmentAlgorithm/interface/AlignmentParameterStore.h"
00036 #include "Alignment/CommonAlignment/interface/Alignable.h"
00037 
00038 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00039 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeomBuilderFromGeometricDet.h"
00040 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00041 #include "Geometry/CSCGeometry/interface/CSCGeometry.h"
00042 #include "Geometry/Records/interface/MuonNumberingRecord.h"
00043 #include "Geometry/MuonNumbering/interface/MuonDDDConstants.h"
00044 #include "Geometry/DTGeometryBuilder/src/DTGeometryBuilderFromDDD.h"
00045 #include "Geometry/CSCGeometryBuilder/src/CSCGeometryBuilderFromDDD.h"
00046 #include "Geometry/TrackingGeometryAligner/interface/GeometryAligner.h"
00047 #include "CondFormats/AlignmentRecord/interface/TrackerAlignmentRcd.h"
00048 #include "CondFormats/AlignmentRecord/interface/TrackerAlignmentErrorRcd.h"
00049 #include "CondFormats/AlignmentRecord/interface/DTAlignmentRcd.h"
00050 #include "CondFormats/AlignmentRecord/interface/DTAlignmentErrorRcd.h"
00051 #include "CondFormats/AlignmentRecord/interface/CSCAlignmentRcd.h"
00052 #include "CondFormats/AlignmentRecord/interface/CSCAlignmentErrorRcd.h"
00053 #include "CondFormats/AlignmentRecord/interface/GlobalPositionRcd.h"
00054 #include "CondFormats/Alignment/interface/DetectorGlobalPosition.h"
00055 //
00056 // class decleration
00057 //
00058 
00059 class AlignmentMonitorAsAnalyzer : public edm::EDAnalyzer {
00060    public:
00061       explicit AlignmentMonitorAsAnalyzer(const edm::ParameterSet&);
00062       ~AlignmentMonitorAsAnalyzer();
00063 
00064       typedef std::pair<const Trajectory*, const reco::Track*> ConstTrajTrackPair; 
00065       typedef std::vector<ConstTrajTrackPair> ConstTrajTrackPairCollection;
00066 
00067    private:
00068       virtual void beginJob(const edm::EventSetup&);
00069       virtual void analyze(const edm::Event&, const edm::EventSetup&);
00070       virtual void endJob();
00071 
00072       // ----------member data ---------------------------
00073       edm::InputTag m_tjTag;
00074       edm::ParameterSet m_aliParamStoreCfg;
00075 
00076       AlignableTracker *m_alignableTracker;
00077       AlignableMuon *m_alignableMuon;
00078       AlignmentParameterStore *m_alignmentParameterStore;
00079 
00080       std::vector<AlignmentMonitorBase*> m_monitors;
00081       const edm::EventSetup *m_lastSetup;
00082 };
00083 
00084 //
00085 // constants, enums and typedefs
00086 //
00087 
00088 //
00089 // static data member definitions
00090 //
00091 
00092 //
00093 // constructors and destructor
00094 //
00095 AlignmentMonitorAsAnalyzer::AlignmentMonitorAsAnalyzer(const edm::ParameterSet& iConfig)
00096    : m_tjTag(iConfig.getParameter<edm::InputTag>("tjTkAssociationMapTag"))
00097    , m_aliParamStoreCfg(iConfig.getParameter<edm::ParameterSet>("ParameterStore"))
00098    , m_alignableTracker(NULL)
00099    , m_alignableMuon(NULL)
00100    , m_alignmentParameterStore(NULL)
00101 {
00102    std::vector<std::string> monitors = iConfig.getUntrackedParameter<std::vector<std::string> >( "monitors" );
00103 
00104    for (std::vector<std::string>::const_iterator miter = monitors.begin();  miter != monitors.end();  ++miter) {
00105       AlignmentMonitorBase* newMonitor = AlignmentMonitorPluginFactory::get()->create(*miter, iConfig.getUntrackedParameter<edm::ParameterSet>(*miter));
00106 
00107       if (!newMonitor) throw cms::Exception("BadConfig") << "Couldn't find monitor named " << *miter;
00108 
00109       m_monitors.push_back(newMonitor);
00110    }
00111 }
00112 
00113 
00114 AlignmentMonitorAsAnalyzer::~AlignmentMonitorAsAnalyzer()
00115 {
00116    delete m_alignableTracker;
00117    delete m_alignableMuon;
00118    delete m_alignmentParameterStore;
00119 }
00120 
00121 
00122 //
00123 // member functions
00124 //
00125 
00126 // ------------ method called to for each event  ------------
00127 void
00128 AlignmentMonitorAsAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
00129    // Retrieve trajectories and tracks from the event
00130    edm::Handle<TrajTrackAssociationCollection> trajTracksMap;
00131    iEvent.getByLabel(m_tjTag, trajTracksMap);
00132 
00133    // Form pairs of trajectories and tracks
00134    ConstTrajTrackPairCollection trajTracks;
00135    for (TrajTrackAssociationCollection::const_iterator iPair = trajTracksMap->begin();  iPair != trajTracksMap->end();  ++iPair) {
00136       trajTracks.push_back(ConstTrajTrackPair(&(*(*iPair).key), &(*(*iPair).val)));
00137    }
00138 
00139    // Run the monitors
00140    for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = m_monitors.begin();  monitor != m_monitors.end();  ++monitor) {
00141       (*monitor)->duringLoop(iSetup, trajTracks);
00142    }
00143 
00144    // Keep this for endOfLoop (why does endOfLoop want iSetup???)
00145    m_lastSetup = &iSetup;
00146 }
00147 
00148 
00149 // ------------ method called once each job just before starting event loop  ------------
00150 void 
00151 AlignmentMonitorAsAnalyzer::beginJob(const edm::EventSetup& iSetup) {
00152    GeometryAligner aligner;
00153 
00154    edm::ESHandle<DDCompactView> cpv;
00155    iSetup.get<IdealGeometryRecord>().get( cpv );
00156 
00157    edm::ESHandle<GeometricDet> theGeometricDet;
00158    iSetup.get<IdealGeometryRecord>().get( theGeometricDet );
00159    TrackerGeomBuilderFromGeometricDet trackerBuilder;
00160    boost::shared_ptr<TrackerGeometry> theTracker = boost::shared_ptr<TrackerGeometry>(trackerBuilder.build(&(*theGeometricDet)));
00161 
00162    edm::ESHandle<MuonDDDConstants> mdc;
00163    iSetup.get<MuonNumberingRecord>().get(mdc);
00164    DTGeometryBuilderFromDDD DTGeometryBuilder;
00165    CSCGeometryBuilderFromDDD CSCGeometryBuilder;
00166    boost::shared_ptr<DTGeometry> theMuonDT = boost::shared_ptr<DTGeometry>(DTGeometryBuilder.build(&(*cpv), *mdc));
00167    boost::shared_ptr<CSCGeometry> theMuonCSC = boost::shared_ptr<CSCGeometry>(new CSCGeometry);
00168    CSCGeometryBuilder.build(theMuonCSC, &(*cpv), *mdc);
00169 
00170    edm::ESHandle<Alignments> globalPositionRcd;
00171    iSetup.get<GlobalPositionRcd>().get(globalPositionRcd);
00172 
00173    edm::ESHandle<Alignments> alignments;
00174    iSetup.get<TrackerAlignmentRcd>().get( alignments );
00175    edm::ESHandle<AlignmentErrors> alignmentErrors;
00176    iSetup.get<TrackerAlignmentErrorRcd>().get( alignmentErrors );
00177    aligner.applyAlignments<TrackerGeometry>( &(*theTracker), &(*alignments), &(*alignmentErrors),
00178                                              align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Tracker)) );
00179 
00180    edm::ESHandle<Alignments> dtAlignments;
00181    iSetup.get<DTAlignmentRcd>().get( dtAlignments );
00182    edm::ESHandle<AlignmentErrors> dtAlignmentErrors;
00183    iSetup.get<DTAlignmentErrorRcd>().get( dtAlignmentErrors );
00184    aligner.applyAlignments<DTGeometry>( &(*theMuonDT), &(*dtAlignments), &(*dtAlignmentErrors),
00185                                              align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)) );
00186 
00187    edm::ESHandle<Alignments> cscAlignments;
00188    iSetup.get<CSCAlignmentRcd>().get( cscAlignments );
00189    edm::ESHandle<AlignmentErrors> cscAlignmentErrors;
00190    iSetup.get<CSCAlignmentErrorRcd>().get( cscAlignmentErrors );
00191    aligner.applyAlignments<CSCGeometry>( &(*theMuonCSC), &(*cscAlignments), &(*cscAlignmentErrors),
00192                                              align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)) );
00193 
00194    // within an analyzer, modules can't expect to see any selected alignables!
00195    std::vector<Alignable*> empty_alignables;
00196 
00197    m_alignableTracker = new AlignableTracker( &(*theTracker) );
00198    m_alignableMuon = new AlignableMuon( &(*theMuonDT), &(*theMuonCSC) );
00199    m_alignmentParameterStore = new AlignmentParameterStore(empty_alignables, m_aliParamStoreCfg);
00200 
00201    for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = m_monitors.begin();  monitor != m_monitors.end();  ++monitor) {
00202       (*monitor)->beginOfJob(m_alignableTracker, m_alignableMuon, m_alignmentParameterStore);
00203    }
00204    for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = m_monitors.begin();  monitor != m_monitors.end();  ++monitor) {
00205       (*monitor)->startingNewLoop();
00206    }
00207 }
00208 
00209 // ------------ method called once each job just after ending the event loop  ------------
00210 void 
00211 AlignmentMonitorAsAnalyzer::endJob() {
00212    for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = m_monitors.begin();  monitor != m_monitors.end();  ++monitor) {
00213       (*monitor)->endOfLoop(*m_lastSetup);
00214    }
00215    for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = m_monitors.begin();  monitor != m_monitors.end();  ++monitor) {
00216       (*monitor)->endOfJob();
00217    }
00218 }
00219 
00220 //define this as a plug-in
00221 DEFINE_FWK_MODULE(AlignmentMonitorAsAnalyzer);

Generated on Tue Jun 9 17:23:50 2009 for CMSSW by  doxygen 1.5.4