CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ME0SegmentMatcher.cc
Go to the documentation of this file.
1 
15 
25 
31 
33 public:
35  explicit ME0SegmentMatcher(const edm::ParameterSet&);
37  ~ME0SegmentMatcher() override;
39  void produce(edm::Event&, const edm::EventSetup&) override;
40 
41  void beginRun(edm::Run const&, edm::EventSetup const&) override;
42 
44  const GlobalVector&, const GlobalVector&, int, const AlgebraicSymMatrix66&, const MagneticField*);
45 
47  const GlobalVector&, const GlobalVector&, int, const AlgebraicSymMatrix55&, const MagneticField*);
48 
50 
51 private:
56 };
57 
59  produces<std::vector<reco::ME0Muon>>();
60  theX_PULL_CUT = pas.getParameter<double>("maxPullX");
61  theX_RESIDUAL_CUT = pas.getParameter<double>("maxDiffX");
62  theY_PULL_CUT = pas.getParameter<double>("maxPullY");
63  theY_RESIDUAL_CUT = pas.getParameter<double>("maxDiffY");
64  thePHIDIR_RESIDUAL_CUT = pas.getParameter<double>("maxDiffPhiDirection");
65  //Might need to replace "OurSegments" with an edm::InputTag of "OurSegments"
66  OurSegmentsTag = pas.getParameter<edm::InputTag>("me0SegmentTag");
67  generalTracksTag = pas.getParameter<edm::InputTag>("tracksTag");
68  OurSegmentsToken_ = consumes<ME0SegmentCollection>(OurSegmentsTag);
69  generalTracksToken_ = consumes<reco::TrackCollection>(generalTracksTag);
70 }
71 
73 
75  //Getting the objects we'll need
76  using namespace edm;
77 
78  ESHandle<ME0Geometry> me0Geom;
79  setup.get<MuonGeometryRecord>().get(me0Geom);
81  setup.get<IdealMagneticFieldRecord>().get(bField);
82  ESHandle<Propagator> ThisshProp;
83  setup.get<TrackingComponentsRecord>().get("SteppingHelixPropagatorAlong", ThisshProp);
84 
85  using namespace reco;
86 
87  Handle<ME0SegmentCollection> OurSegments;
88  ev.getByToken(OurSegmentsToken_, OurSegments);
89 
90  auto oc = std::make_unique<std::vector<ME0Muon>>();
91  std::vector<ME0Muon> TempStore;
92 
94  ev.getByToken(generalTracksToken_, generalTracks);
95 
96  int TrackNumber = 0;
97 
98  for (std::vector<Track>::const_iterator thisTrack = generalTracks->begin(); thisTrack != generalTracks->end();
99  ++thisTrack, ++TrackNumber) {
100  //Initializing our plane
101 
102  //Remove later
103  if (std::abs(thisTrack->eta()) < 1.8)
104  continue;
105 
106  //Getting the initial variables for propagation
107  float zSign = thisTrack->pz() > 0 ? 1.0f : -1.0f;
108 
110  Plane::build(Surface::PositionType(0, 0, zSign * 526.75), Surface::RotationType());
111 
112  int chargeReco = thisTrack->charge();
113  GlobalVector p3reco, r3reco;
114 
115  p3reco = GlobalVector(thisTrack->outerPx(), thisTrack->outerPy(), thisTrack->outerPz());
116  r3reco = GlobalVector(thisTrack->outerX(), thisTrack->outerY(), thisTrack->outerZ());
117 
118  AlgebraicSymMatrix66 covReco;
119  //This is to fill the cov matrix correctly
120  const AlgebraicSymMatrix55& covReco_curv = thisTrack->outerStateCovariance();
121  FreeTrajectoryState initrecostate = getFTS(p3reco, r3reco, chargeReco, covReco_curv, &*bField);
122  getFromFTS(initrecostate, p3reco, r3reco, chargeReco, covReco);
123 
124  //Now we propagate and get the propagated variables from the propagated state
125  TrajectoryStateOnSurface lastrecostate = ThisshProp->propagate(initrecostate, *plane);
126  if (!lastrecostate.isValid())
127  continue;
128 
129  FreeTrajectoryState finalrecostate(*lastrecostate.freeTrajectoryState());
130 
131  AlgebraicSymMatrix66 covFinalReco;
132  GlobalVector p3FinalReco_glob, r3FinalReco_globv;
133  getFromFTS(finalrecostate, p3FinalReco_glob, r3FinalReco_globv, chargeReco, covFinalReco);
134 
135  //To transform the global propagated track to local coordinates
136  int SegmentNumber = 0;
137 
139  double ClosestDelR2 = 999.;
140 
141  for (auto thisSegment = OurSegments->begin(); thisSegment != OurSegments->end(); ++thisSegment, ++SegmentNumber) {
142  ME0DetId id = thisSegment->me0DetId();
143 
144  auto chamber = me0Geom->chamber(id);
145 
146  if (zSign * chamber->toGlobal(thisSegment->localPosition()).z() < 0)
147  continue;
148 
149  GlobalPoint r3FinalReco_glob(r3FinalReco_globv.x(), r3FinalReco_globv.y(), r3FinalReco_globv.z());
150 
151  LocalPoint r3FinalReco = chamber->toLocal(r3FinalReco_glob);
152  LocalVector p3FinalReco = chamber->toLocal(p3FinalReco_glob);
153 
154  LocalPoint thisPosition(thisSegment->localPosition());
155  LocalVector thisDirection(thisSegment->localDirection().x(),
156  thisSegment->localDirection().y(),
157  thisSegment->localDirection().z()); //FIXME
158 
159  //The same goes for the error
160  AlgebraicMatrix thisCov(4, 4, 0);
161  for (int i = 1; i <= 4; i++) {
162  for (int j = 1; j <= 4; j++) {
163  thisCov(i, j) = thisSegment->parametersError()(i, j);
164  }
165  }
166 
167  LocalTrajectoryParameters ltp(r3FinalReco, p3FinalReco, chargeReco);
168  JacobianCartesianToLocal jctl(chamber->surface(), ltp);
169  const AlgebraicMatrix56& jacobGlbToLoc = jctl.jacobian();
170 
171  AlgebraicMatrix55 Ctmp = (jacobGlbToLoc * covFinalReco) * ROOT::Math::Transpose(jacobGlbToLoc);
172  AlgebraicSymMatrix55 C; // I couldn't find any other way, so I resort to the brute force
173  for (int i = 0; i < 5; ++i) {
174  for (int j = 0; j < 5; ++j) {
175  C[i][j] = Ctmp[i][j];
176  }
177  }
178 
179  Double_t sigmax = sqrt(C[3][3] + thisSegment->localPositionError().xx());
180  Double_t sigmay = sqrt(C[4][4] + thisSegment->localPositionError().yy());
181 
182  bool X_MatchFound = false, Y_MatchFound = false, Dir_MatchFound = false;
183 
184  if ((std::abs(thisPosition.x() - r3FinalReco.x()) < (theX_PULL_CUT * sigmax)) ||
185  (std::abs(thisPosition.x() - r3FinalReco.x()) < theX_RESIDUAL_CUT))
186  X_MatchFound = true;
187  if ((std::abs(thisPosition.y() - r3FinalReco.y()) < (theY_PULL_CUT * sigmay)) ||
188  (std::abs(thisPosition.y() - r3FinalReco.y()) < theY_RESIDUAL_CUT))
189  Y_MatchFound = true;
190 
191  if (std::abs(reco::deltaPhi(p3FinalReco_glob.barePhi(),
192  chamber->toGlobal(thisSegment->localDirection()).barePhi())) < thePHIDIR_RESIDUAL_CUT)
193  Dir_MatchFound = true;
194 
195  //Check for a Match, and if there is a match, check the delR from the segment, keeping only the closest in MuonCandidate
196  if (X_MatchFound && Y_MatchFound && Dir_MatchFound) {
197  TrackRef thisTrackRef(generalTracks, TrackNumber);
198 
199  GlobalPoint SegPos(chamber->toGlobal(thisSegment->localPosition()));
200  GlobalPoint TkPos(r3FinalReco_globv.x(), r3FinalReco_globv.y(), r3FinalReco_globv.z());
201 
202  double thisDelR2 = reco::deltaR2(SegPos, TkPos);
203  if (thisDelR2 < ClosestDelR2) {
204  ClosestDelR2 = thisDelR2;
205  MuonCandidate = reco::ME0Muon(thisTrackRef, (*thisSegment), SegmentNumber, chargeReco);
206 
207  MuonCandidate.setGlobalTrackPosAtSurface(r3FinalReco_glob);
208  MuonCandidate.setGlobalTrackMomAtSurface(p3FinalReco_glob);
209  MuonCandidate.setLocalTrackPosAtSurface(r3FinalReco);
210  MuonCandidate.setLocalTrackMomAtSurface(p3FinalReco);
211  MuonCandidate.setGlobalTrackCov(covFinalReco);
212  MuonCandidate.setLocalTrackCov(C);
213  }
214  }
215  } //End loop for (auto thisSegment = OurSegments->begin(); thisSegment != OurSegments->end(); ++thisSegment,++SegmentNumber)
216 
217  //As long as the delR of the MuonCandidate is sensible, store the track-segment pair
218  if (ClosestDelR2 < 500.) {
219  oc->push_back(MuonCandidate);
220  }
221  }
222 
223  // put collection in event
224  ev.put(std::move(oc));
225 }
226 
228  const GlobalVector& r3,
229  int charge,
230  const AlgebraicSymMatrix55& cov,
231  const MagneticField* field) {
232  GlobalVector p3GV(p3.x(), p3.y(), p3.z());
233  GlobalPoint r3GP(r3.x(), r3.y(), r3.z());
234  GlobalTrajectoryParameters tPars(r3GP, p3GV, charge, field);
235 
236  CurvilinearTrajectoryError tCov(cov);
237 
238  return cov.kRows == 5 ? FreeTrajectoryState(tPars, tCov) : FreeTrajectoryState(tPars);
239 }
240 
242  const GlobalVector& r3,
243  int charge,
244  const AlgebraicSymMatrix66& cov,
245  const MagneticField* field) {
246  GlobalVector p3GV(p3.x(), p3.y(), p3.z());
247  GlobalPoint r3GP(r3.x(), r3.y(), r3.z());
248  GlobalTrajectoryParameters tPars(r3GP, p3GV, charge, field);
249 
250  CartesianTrajectoryError tCov(cov);
251 
252  return cov.kRows == 6 ? FreeTrajectoryState(tPars, tCov) : FreeTrajectoryState(tPars);
253 }
254 
257  GlobalVector p3GV = fts.momentum();
258  GlobalPoint r3GP = fts.position();
259 
260  GlobalVector p3T(p3GV.x(), p3GV.y(), p3GV.z());
261  GlobalVector r3T(r3GP.x(), r3GP.y(), r3GP.z());
262  p3 = p3T;
263  r3 = r3T;
264  // p3.set(p3GV.x(), p3GV.y(), p3GV.z());
265  // r3.set(r3GP.x(), r3GP.y(), r3GP.z());
266 
267  charge = fts.charge();
268  cov = fts.hasError() ? fts.cartesianError().matrix() : AlgebraicSymMatrix66();
269 }
270 
271 void ME0SegmentMatcher::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {}
272 
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
const AlgebraicMatrix56 & jacobian() const
T getParameter(std::string const &) const
T barePhi() const
void setLocalTrackMomAtSurface(const LocalVector &localTrackMomAtSurface)
Definition: ME0Muon.h:66
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
CartesianTrajectoryError cartesianError() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
FreeTrajectoryState getFTS(const GlobalVector &, const GlobalVector &, int, const AlgebraicSymMatrix66 &, const MagneticField *)
ME0SegmentMatcher(const edm::ParameterSet &)
Constructor.
T y() const
Definition: PV3DBase.h:60
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepStd< double, 5, 5 > > AlgebraicMatrix55
bool ev
edm::InputTag generalTracksTag
TrackCharge charge() const
void produce(edm::Event &, const edm::EventSetup &) override
Produce the ME0Segment collection.
void setGlobalTrackMomAtSurface(const GlobalVector &globalTrackMomAtSurface)
Definition: ME0Muon.h:60
edm::EDGetTokenT< reco::TrackCollection > generalTracksToken_
T barePhi() const
Definition: PV3DBase.h:65
ROOT::Math::SMatrix< double, 5, 6, ROOT::Math::MatRepStd< double, 5, 6 > > AlgebraicMatrix56
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void setLocalTrackCov(const AlgebraicSymMatrix55 &trackCov)
Definition: ME0Muon.h:71
CLHEP::HepMatrix AlgebraicMatrix
FreeTrajectoryState const * freeTrajectoryState(bool withErrors=true) const
T sqrt(T t)
Definition: SSEVec.h:19
edm::InputTag OurSegmentsTag
static PlanePointer build(Args &&...args)
Definition: Plane.h:33
T z() const
Definition: PV3DBase.h:61
const ME0Chamber * chamber(ME0DetId id) const
Return a chamber given its id.
Definition: ME0Geometry.cc:43
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::EDGetTokenT< ME0SegmentCollection > OurSegmentsToken_
GlobalVector momentum() const
void setGlobalTrackCov(const AlgebraicSymMatrix66 &trackCov)
Definition: ME0Muon.h:70
const AlgebraicSymMatrix66 & matrix() const
ROOT::Math::SMatrix< double, 6, 6, ROOT::Math::MatRepSym< double, 6 > > AlgebraicSymMatrix66
GlobalPoint position() const
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
~ME0SegmentMatcher() override
Destructor.
void getFromFTS(const FreeTrajectoryState &, GlobalVector &, GlobalVector &, int &, AlgebraicSymMatrix66 &)
void setGlobalTrackPosAtSurface(const GlobalPoint &globalTrackPosAtSurface)
Definition: ME0Muon.h:57
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
Definition: Propagator.h:50
fixed size matrix
HLT enums.
T get() const
Definition: EventSetup.h:73
T x() const
Definition: PV3DBase.h:59
void beginRun(edm::Run const &, edm::EventSetup const &) override
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:45
Global3DVector GlobalVector
Definition: GlobalVector.h:10
void setLocalTrackPosAtSurface(const LocalPoint &localTrackPosAtSurface)
Definition: ME0Muon.h:63
double p3[4]
Definition: TauolaWrapper.h:91