CMS 3D CMS Logo

AlignmentMuonHIPTrajectorySelector.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: AlignmentMuonHIPTrajectorySelector
4 // Class: AlignmentMuonHIPTrajectorySelector
5 //
13 //
14 // Original Author: Jim Pivarski
15 // Created: Wed Feb 20 10:56:46 CST 2008
16 // $Id: AlignmentMuonHIPTrajectorySelector.cc,v 1.4 2010/01/06 15:26:10 mussgill Exp $
17 //
18 //
19 
20 // system include files
21 #include <memory>
22 #include <map>
23 #include <fstream>
24 
25 // user include files
34 
48 #include "TH1F.h"
49 
50 //
51 // class decleration
52 //
53 
55 public:
58 
59 private:
60  void produce(edm::Event&, const edm::EventSetup&) override;
61 
62  // ---------- member data --------------------------------
64  double m_minPt;
68 
69  bool m_hists;
72 };
73 
74 //
75 // constants, enums and typedefs
76 //
77 
78 //
79 // static data member definitions
80 //
81 
82 //
83 // constructors and destructor
84 //
86  : m_input(iConfig.getParameter<edm::InputTag>("input")),
87  m_minPt(iConfig.getParameter<double>("minPt")),
88  m_maxTrackerForwardRedChi2(iConfig.getParameter<double>("maxTrackerForwardRedChi2")),
89  m_minTrackerDOF(iConfig.getParameter<int>("minTrackerDOF")),
90  m_maxMuonResidual(iConfig.getParameter<double>("maxMuonResidual")),
91  m_hists(iConfig.getParameter<bool>("hists")),
92  m_pt(nullptr),
93  m_tracker_forwardredchi2(nullptr),
94  m_tracker_dof(nullptr) {
95  produces<TrajTrackAssociationCollection>();
96 
97  if (m_hists) {
99  m_pt = fs->make<TH1F>("pt", "Transverse momentum (GeV)", 100, 0., 100.);
101  fs->make<TH1F>("trackerForwardRedChi2", "forward-biased reduced chi2 in tracker", 100, 0., 5.);
102  m_tracker_dof = fs->make<TH1F>("trackerDOF", "DOF in tracker", 61, -0.5, 60.5);
103  m_resid_before = fs->make<TH1F>("residBefore", "muon residuals before cut (cm)", 100, -20, 20);
104  m_resid_after = fs->make<TH1F>("residAfter", "muon residuals after cut (cm)", 100, -20, 20);
105  }
106 }
107 
109 
110 //
111 // member functions
112 //
113 
114 // ------------ method called to produce the data ------------
116  // input
117  edm::Handle<TrajTrackAssociationCollection> originalTrajTrackMap;
118  iEvent.getByLabel(m_input, originalTrajTrackMap);
119 
120  // output
121  auto newTrajTrackMap = std::make_unique<TrajTrackAssociationCollection>();
122 
123  TrajectoryStateCombiner tsoscomb;
124 
125  for (TrajTrackAssociationCollection::const_iterator iPair = originalTrajTrackMap->begin();
126  iPair != originalTrajTrackMap->end();
127  ++iPair) {
128  if (m_hists) {
129  m_pt->Fill((*(*iPair).val).pt());
130  }
131 
132  if ((*(*iPair).val).pt() > m_minPt) {
133  std::vector<TrajectoryMeasurement> measurements = (*(*iPair).key).measurements();
134 
135  bool has_bad_residual = false;
136 
137  double tracker_forwardchi2 = 0.;
138  double tracker_dof = 0.;
139  for (std::vector<TrajectoryMeasurement>::const_iterator im = measurements.begin(); im != measurements.end();
140  ++im) {
141  const TrajectoryMeasurement meas = *im;
142  auto hit = &(*meas.recHit());
143  const DetId id = hit->geographicalId();
144 
145  if (hit->isValid() && id.det() == DetId::Tracker) {
146  if (hit->dimension() == 1) {
147  double residual = meas.forwardPredictedState().localPosition().x() - hit->localPosition().x();
148  double error2 =
149  meas.forwardPredictedState().localError().positionError().xx() + hit->localPositionError().xx();
150 
151  tracker_forwardchi2 += residual * residual / error2;
152  tracker_dof += 1.;
153  } else if (hit->dimension() == 2) {
154  double residualx = meas.forwardPredictedState().localPosition().x() - hit->localPosition().x();
155  double residualy = meas.forwardPredictedState().localPosition().y() - hit->localPosition().y();
156  double errorxx2 =
157  meas.forwardPredictedState().localError().positionError().xx() + hit->localPositionError().xx();
158  double errorxy2 =
159  meas.forwardPredictedState().localError().positionError().xy() + hit->localPositionError().xy();
160  double erroryy2 =
161  meas.forwardPredictedState().localError().positionError().yy() + hit->localPositionError().yy();
162 
163  tracker_forwardchi2 +=
164  (residualx * residualx + residualy * residualy) / (errorxx2 + 2. * errorxy2 + erroryy2);
165  tracker_dof += 2.;
166  }
167  } // end if a tracker hit
168 
169  if (hit->isValid() && id.det() == DetId::Muon &&
170  (id.subdetId() == MuonSubdetId::DT || id.subdetId() == MuonSubdetId::CSC)) {
172  tsoscomb.combine(meas.forwardPredictedState(), meas.backwardPredictedState());
173  double residual = tsosc.localPosition().x() - hit->localPosition().x();
174  m_resid_before->Fill(residual);
175  if (fabs(residual) > m_maxMuonResidual) {
176  has_bad_residual = true;
177  }
178  } // end if a muon hit
179  }
180  tracker_dof -= 5.;
181  double tracker_forwardredchi2 = tracker_forwardchi2 / tracker_dof;
182 
183  if (m_hists) {
184  m_tracker_forwardredchi2->Fill(tracker_forwardredchi2);
185  m_tracker_dof->Fill(tracker_dof);
186 
187  for (std::vector<TrajectoryMeasurement>::const_iterator im = measurements.begin(); im != measurements.end();
188  ++im) {
189  const TrajectoryMeasurement meas = *im;
190  auto hit = &(*meas.recHit());
191  const DetId id = hit->geographicalId();
192 
193  if (!has_bad_residual) {
194  if (hit->isValid() && id.det() == DetId::Muon &&
195  (id.subdetId() == MuonSubdetId::DT || id.subdetId() == MuonSubdetId::CSC)) {
197  tsoscomb.combine(meas.forwardPredictedState(), meas.backwardPredictedState());
198  double residual = tsosc.localPosition().x() - hit->localPosition().x();
199  m_resid_after->Fill(residual);
200  }
201  } // end if residuals pass cut
202  } // end second loop over hits
203  } // end if filling histograms
204 
205  if (tracker_forwardredchi2 < m_maxTrackerForwardRedChi2 && tracker_dof >= m_minTrackerDOF && !has_bad_residual) {
206  newTrajTrackMap->insert((*iPair).key, (*iPair).val);
207  } // end if passes tracker cuts
208  } // end if passes pT cut
209  } // end loop over original trajTrackMap
210 
211  // put it in the Event
212  iEvent.put(std::move(newTrajTrackMap));
213 }
214 
215 //define this as a plug-in
const LocalTrajectoryError & localError() const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
TrajectoryStateOnSurface const & forwardPredictedState() const
Access to forward predicted state (from fitter or builder)
LocalError positionError() const
const_iterator end() const
last iterator over the map (read only)
float yy() const
Definition: LocalError.h:24
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
int iEvent
Definition: GenABIO.cc:224
TrajectoryStateOnSurface const & backwardPredictedState() const
Access to backward predicted state (from smoother)
float xy() const
Definition: LocalError.h:23
Definition: DetId.h:17
const_iterator begin() const
first iterator over the map (read only)
void produce(edm::Event &, const edm::EventSetup &) override
HLT enums.
static constexpr int DT
Definition: MuonSubdetId.h:11
static constexpr int CSC
Definition: MuonSubdetId.h:12
float xx() const
Definition: LocalError.h:22
def move(src, dest)
Definition: eostools.py:511
ConstRecHitPointer const & recHit() const