Go to the documentation of this file.00001
00002
00003
00004
00005
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <memory>
00023 #include <map>
00024 #include <fstream>
00025
00026
00027 #include "FWCore/Framework/interface/Frameworkfwd.h"
00028 #include "FWCore/Framework/interface/EDProducer.h"
00029 #include "FWCore/Framework/interface/Event.h"
00030 #include "FWCore/Framework/interface/MakerMacros.h"
00031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00032 #include "FWCore/Utilities/interface/InputTag.h"
00033 #include "FWCore/Framework/interface/Event.h"
00034 #include "FWCore/Framework/interface/EventSetup.h"
00035
00036 #include "TrackingTools/PatternTools/interface/Trajectory.h"
00037 #include "TrackingTools/TrackFitters/interface/TrajectoryStateCombiner.h"
00038 #include "DataFormats/TrackReco/interface/Track.h"
00039 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00040 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
00041 #include "TrackingTools/PatternTools/interface/Trajectory.h"
00042 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
00043 #include "TrackingTools/PatternTools/interface/TrajectoryMeasurement.h"
00044 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHit.h"
00045 #include "DataFormats/DetId/interface/DetId.h"
00046 #include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
00047 #include "FWCore/ServiceRegistry/interface/Service.h"
00048 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00049 #include "TH1F.h"
00050
00051
00052
00053
00054
00055 class AlignmentMuonHIPTrajectorySelector : public edm::EDProducer {
00056 public:
00057 explicit AlignmentMuonHIPTrajectorySelector(const edm::ParameterSet&);
00058 ~AlignmentMuonHIPTrajectorySelector();
00059
00060 private:
00061 virtual void produce(edm::Event&, const edm::EventSetup&);
00062
00063
00064 edm::InputTag m_input;
00065 double m_minPt;
00066 double m_maxTrackerForwardRedChi2;
00067 int m_minTrackerDOF;
00068 double m_maxMuonResidual;
00069
00070 bool m_hists;
00071 TH1F *m_pt, *m_tracker_forwardredchi2, *m_tracker_dof;
00072 TH1F *m_resid_before, *m_resid_after;
00073 };
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 AlignmentMuonHIPTrajectorySelector::AlignmentMuonHIPTrajectorySelector(const edm::ParameterSet& iConfig)
00088 : m_input(iConfig.getParameter<edm::InputTag>("input"))
00089 , m_minPt(iConfig.getParameter<double>("minPt"))
00090 , m_maxTrackerForwardRedChi2(iConfig.getParameter<double>("maxTrackerForwardRedChi2"))
00091 , m_minTrackerDOF(iConfig.getParameter<int>("minTrackerDOF"))
00092 , m_maxMuonResidual(iConfig.getParameter<double>("maxMuonResidual"))
00093 , m_hists(iConfig.getParameter<bool>("hists"))
00094 , m_pt(NULL), m_tracker_forwardredchi2(NULL), m_tracker_dof(NULL)
00095 {
00096 produces<TrajTrackAssociationCollection>();
00097
00098 if (m_hists) {
00099 edm::Service<TFileService> fs;
00100 m_pt = fs->make<TH1F>("pt", "Transverse momentum (GeV)", 100, 0., 100.);
00101 m_tracker_forwardredchi2 = fs->make<TH1F>("trackerForwardRedChi2", "forward-biased reduced chi2 in tracker", 100, 0., 5.);
00102 m_tracker_dof = fs->make<TH1F>("trackerDOF", "DOF in tracker", 61, -0.5, 60.5);
00103 m_resid_before = fs->make<TH1F>("residBefore", "muon residuals before cut (cm)", 100, -20, 20);
00104 m_resid_after = fs->make<TH1F>("residAfter", "muon residuals after cut (cm)", 100, -20, 20);
00105 }
00106 }
00107
00108
00109 AlignmentMuonHIPTrajectorySelector::~AlignmentMuonHIPTrajectorySelector() {}
00110
00111
00112
00113
00114
00115
00116
00117 void
00118 AlignmentMuonHIPTrajectorySelector::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00119 {
00120
00121 edm::Handle<TrajTrackAssociationCollection> originalTrajTrackMap;
00122 iEvent.getByLabel(m_input, originalTrajTrackMap);
00123
00124
00125 std::auto_ptr<TrajTrackAssociationCollection> newTrajTrackMap(new TrajTrackAssociationCollection());
00126
00127 TrajectoryStateCombiner tsoscomb;
00128
00129 for (TrajTrackAssociationCollection::const_iterator iPair = originalTrajTrackMap->begin(); iPair != originalTrajTrackMap->end(); ++iPair) {
00130 if (m_hists) {
00131 m_pt->Fill((*(*iPair).val).pt());
00132 }
00133
00134 if ((*(*iPair).val).pt() > m_minPt) {
00135
00136 std::vector<TrajectoryMeasurement> measurements = (*(*iPair).key).measurements();
00137
00138 bool has_bad_residual = false;
00139
00140 double tracker_forwardchi2 = 0.;
00141 double tracker_dof = 0.;
00142 for (std::vector<TrajectoryMeasurement>::const_iterator im = measurements.begin(); im != measurements.end(); ++im) {
00143 const TrajectoryMeasurement meas = *im;
00144 const TransientTrackingRecHit* hit = &(*meas.recHit());
00145 const DetId id = hit->geographicalId();
00146
00147 if (hit->isValid() && id.det() == DetId::Tracker) {
00148 if (hit->dimension() == 1) {
00149 double residual = meas.forwardPredictedState().localPosition().x() - hit->localPosition().x();
00150 double error2 = meas.forwardPredictedState().localError().positionError().xx() + hit->localPositionError().xx();
00151
00152 tracker_forwardchi2 += residual * residual / error2;
00153 tracker_dof += 1.;
00154 }
00155 else if (hit->dimension() == 2) {
00156 double residualx = meas.forwardPredictedState().localPosition().x() - hit->localPosition().x();
00157 double residualy = meas.forwardPredictedState().localPosition().y() - hit->localPosition().y();
00158 double errorxx2 = meas.forwardPredictedState().localError().positionError().xx() + hit->localPositionError().xx();
00159 double errorxy2 = meas.forwardPredictedState().localError().positionError().xy() + hit->localPositionError().xy();
00160 double erroryy2 = meas.forwardPredictedState().localError().positionError().yy() + hit->localPositionError().yy();
00161
00162 tracker_forwardchi2 += (residualx * residualx + residualy * residualy) / (errorxx2 + 2.*errorxy2 + erroryy2);
00163 tracker_dof += 2.;
00164 }
00165 }
00166
00167 if (hit->isValid() && id.det() == DetId::Muon && (id.subdetId() == MuonSubdetId::DT || id.subdetId() == MuonSubdetId::CSC)) {
00168 TrajectoryStateOnSurface tsosc = tsoscomb.combine(meas.forwardPredictedState(), meas.backwardPredictedState());
00169 double residual = tsosc.localPosition().x() - hit->localPosition().x();
00170 m_resid_before->Fill(residual);
00171 if (fabs(residual) > m_maxMuonResidual) {
00172 has_bad_residual = true;
00173 }
00174 }
00175
00176 }
00177 tracker_dof -= 5.;
00178 double tracker_forwardredchi2 = tracker_forwardchi2 / tracker_dof;
00179
00180 if (m_hists) {
00181 m_tracker_forwardredchi2->Fill(tracker_forwardredchi2);
00182 m_tracker_dof->Fill(tracker_dof);
00183
00184 for (std::vector<TrajectoryMeasurement>::const_iterator im = measurements.begin(); im != measurements.end(); ++im) {
00185 const TrajectoryMeasurement meas = *im;
00186 const TransientTrackingRecHit* hit = &(*meas.recHit());
00187 const DetId id = hit->geographicalId();
00188
00189 if (!has_bad_residual) {
00190 if (hit->isValid() && id.det() == DetId::Muon && (id.subdetId() == MuonSubdetId::DT || id.subdetId() == MuonSubdetId::CSC)) {
00191 TrajectoryStateOnSurface tsosc = tsoscomb.combine(meas.forwardPredictedState(), meas.backwardPredictedState());
00192 double residual = tsosc.localPosition().x() - hit->localPosition().x();
00193 m_resid_after->Fill(residual);
00194 }
00195 }
00196 }
00197 }
00198
00199 if (tracker_forwardredchi2 < m_maxTrackerForwardRedChi2 && tracker_dof >= m_minTrackerDOF && !has_bad_residual) {
00200 newTrajTrackMap->insert((*iPair).key, (*iPair).val);
00201 }
00202 }
00203 }
00204
00205
00206 iEvent.put(newTrajTrackMap);
00207 }
00208
00209
00210 DEFINE_FWK_MODULE(AlignmentMuonHIPTrajectorySelector);