CMS 3D CMS Logo

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);
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 
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 
Vector3DBase
Definition: Vector3DBase.h:8
JacobianCartesianToLocal.h
Propagator.h
ME0SegmentMatcher::generalTracksTag
edm::InputTag generalTracksTag
Definition: ME0SegmentMatcher.cc:53
TkRotation< float >
FreeTrajectoryState::momentum
GlobalVector momentum() const
Definition: FreeTrajectoryState.h:68
TrajectoryStateOnSurface::freeTrajectoryState
FreeTrajectoryState const * freeTrajectoryState(bool withErrors=true) const
Definition: TrajectoryStateOnSurface.h:60
Handle.h
mps_fire.i
i
Definition: mps_fire.py:355
MessageLogger.h
ME0SegmentMatcher::theX_PULL_CUT
double theX_PULL_CUT
Definition: ME0SegmentMatcher.cc:52
ME0SegmentMatcher::~ME0SegmentMatcher
~ME0SegmentMatcher() override
Destructor.
Definition: ME0SegmentMatcher.cc:72
FreeTrajectoryState::hasError
bool hasError() const
Definition: FreeTrajectoryState.h:77
ESHandle.h
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
edm::Run
Definition: Run.h:45
reco::deltaPhi
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
edm::EDGetTokenT< ME0SegmentCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
ME0DetId.h
FreeTrajectoryState::charge
TrackCharge charge() const
Definition: FreeTrajectoryState.h:69
ME0SegmentCollection.h
ME0SegmentMatcher
Definition: ME0SegmentMatcher.cc:32
EDProducer.h
AlgebraicMatrix56
ROOT::Math::SMatrix< double, 5, 6, ROOT::Math::MatRepStd< double, 5, 6 > > AlgebraicMatrix56
Definition: AlgebraicROOTObjects.h:56
ReferenceCountingPointer< Plane >
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
FreeTrajectoryState::position
GlobalPoint position() const
Definition: FreeTrajectoryState.h:67
GlobalVector
Global3DVector GlobalVector
Definition: GlobalVector.h:10
MuonCandidate
Definition: MuonCandidate.h:15
edm::Handle< ME0SegmentCollection >
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
reco::ME0Muon
Definition: ME0Muon.h:21
ME0SegmentMatcher::getFromFTS
void getFromFTS(const FreeTrajectoryState &, GlobalVector &, GlobalVector &, int &, AlgebraicSymMatrix66 &)
Definition: ME0SegmentMatcher.cc:255
JacobianCartesianToLocal
Definition: JacobianCartesianToLocal.h:15
edm::Ref< TrackCollection >
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
deltaR.h
LocalTrajectoryParameters
Definition: LocalTrajectoryParameters.h:25
ME0Geometry::chamber
const ME0Chamber * chamber(ME0DetId id) const
Return a chamber given its id.
Definition: ME0Geometry.cc:43
IdealMagneticFieldRecord
Definition: IdealMagneticFieldRecord.h:11
LocalTrajectoryParameters.h
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
MakerMacros.h
Track.h
ME0SegmentMatcher::beginRun
void beginRun(edm::Run const &, edm::EventSetup const &) override
Definition: ME0SegmentMatcher.cc:271
TrackFwd.h
FreeTrajectoryState::cartesianError
CartesianTrajectoryError cartesianError() const
Definition: FreeTrajectoryState.h:81
CurvilinearTrajectoryError
Definition: CurvilinearTrajectoryError.h:27
AlgebraicMatrix55
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepStd< double, 5, 5 > > AlgebraicMatrix55
Definition: AlgebraicROOTObjects.h:55
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Service.h
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
AlgebraicSymMatrix66
ROOT::Math::SMatrix< double, 6, 6, ROOT::Math::MatRepSym< double, 6 > > AlgebraicSymMatrix66
Definition: AlgebraicROOTObjects.h:24
DDAxes::z
edm::ESHandle< ME0Geometry >
ME0SegmentMatcher::theX_RESIDUAL_CUT
double theX_RESIDUAL_CUT
Definition: ME0SegmentMatcher.cc:52
ME0SegmentMatcher::theY_PULL_CUT
double theY_PULL_CUT
Definition: ME0SegmentMatcher.cc:52
GlobalTrajectoryParameters
Definition: GlobalTrajectoryParameters.h:15
Point3DBase< float, GlobalTag >
barePhi
T barePhi() const
Definition: Basic3DVectorLD.h:142
Plane::build
static PlanePointer build(Args &&... args)
Definition: Plane.h:33
ALCARECOTkAlJpsiMuMu_cff.charge
charge
Definition: ALCARECOTkAlJpsiMuMu_cff.py:47
JacobianCartesianToLocal::jacobian
const AlgebraicMatrix56 & jacobian() const
Definition: JacobianCartesianToLocal.h:26
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
PV3DBase::barePhi
T barePhi() const
Definition: PV3DBase.h:65
reco::deltaR2
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
ME0SegmentMatcher::ME0SegmentMatcher
ME0SegmentMatcher(const edm::ParameterSet &)
Constructor.
Definition: ME0SegmentMatcher.cc:58
ME0SegmentMatcher::getFTS
FreeTrajectoryState getFTS(const GlobalVector &, const GlobalVector &, int, const AlgebraicSymMatrix66 &, const MagneticField *)
Definition: ME0SegmentMatcher.cc:241
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:57
ME0DetId
Definition: ME0DetId.h:16
Propagator::propagate
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
Definition: Propagator.h:50
ME0SegmentMatcher::thePHIDIR_RESIDUAL_CUT
double thePHIDIR_RESIDUAL_CUT
Definition: ME0SegmentMatcher.cc:52
get
#define get
ME0Muon.h
ME0SegmentMatcher::theY_RESIDUAL_CUT
double theY_RESIDUAL_CUT
Definition: ME0SegmentMatcher.cc:52
CartesianTrajectoryError::matrix
const AlgebraicSymMatrix66 & matrix() const
Definition: CartesianTrajectoryError.h:28
InputTag.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
ME0Geometry.h
CartesianTrajectoryError
Definition: CartesianTrajectoryError.h:15
eostools.move
def move(src, dest)
Definition: eostools.py:511
AlgebraicMatrix
CLHEP::HepMatrix AlgebraicMatrix
Definition: AlgebraicObjects.h:14
FreeTrajectoryState
Definition: FreeTrajectoryState.h:27
Calorimetry_cff.bField
bField
Definition: Calorimetry_cff.py:292
gen::C
C
Definition: PomwigHadronizer.cc:76
ME0SegmentMatcher::produce
void produce(edm::Event &, const edm::EventSetup &) override
Produce the ME0Segment collection.
Definition: ME0SegmentMatcher.cc:74
Frameworkfwd.h
TrackingComponentsRecord.h
ev
bool ev
Definition: Hydjet2Hadronizer.cc:95
relativeConstraints.chamber
chamber
Definition: relativeConstraints.py:53
EventSetup.h
ME0SegmentMatcher::OurSegmentsTag
edm::InputTag OurSegmentsTag
Definition: ME0SegmentMatcher.cc:53
p3
double p3[4]
Definition: TauolaWrapper.h:91
isolatedTracks_cfi.generalTracks
generalTracks
Definition: isolatedTracks_cfi.py:31
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterSet.h
MuonGeometryRecord.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
ME0SegmentMatcher::OurSegmentsToken_
edm::EDGetTokenT< ME0SegmentCollection > OurSegmentsToken_
Definition: ME0SegmentMatcher.cc:54
ME0SegmentMatcher::generalTracksToken_
edm::EDGetTokenT< reco::TrackCollection > generalTracksToken_
Definition: ME0SegmentMatcher.cc:55
edm::Event
Definition: Event.h:73
MagneticField
Definition: MagneticField.h:19
AlgebraicSymMatrix55
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
Definition: AlgebraicROOTObjects.h:23
MuonGeometryRecord
Definition: MuonGeometryRecord.h:34
AlgebraicROOTObjects.h
edm::InputTag
Definition: InputTag.h:15
TrajectoryStateOnSurface::isValid
bool isValid() const
Definition: TrajectoryStateOnSurface.h:54
TrackingComponentsRecord
Definition: TrackingComponentsRecord.h:12