CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
ME0SegmentMatcher Class Reference
Inheritance diagram for ME0SegmentMatcher:
edm::stream::EDProducer<>

Public Member Functions

void beginRun (edm::Run const &, edm::EventSetup const &) override
 
void getFromFTS (const FreeTrajectoryState &, GlobalVector &, GlobalVector &, int &, AlgebraicSymMatrix66 &)
 
FreeTrajectoryState getFTS (const GlobalVector &, const GlobalVector &, int, const AlgebraicSymMatrix66 &, const MagneticField *)
 
FreeTrajectoryState getFTS (const GlobalVector &, const GlobalVector &, int, const AlgebraicSymMatrix55 &, const MagneticField *)
 
 ME0SegmentMatcher (const edm::ParameterSet &)
 Constructor. More...
 
void produce (edm::Event &, const edm::EventSetup &) override
 Produce the ME0Segment collection. More...
 
 ~ME0SegmentMatcher () override
 Destructor. More...
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndRuns () const final
 

Private Attributes

edm::InputTag generalTracksTag
 
edm::EDGetTokenT< reco::TrackCollectiongeneralTracksToken_
 
edm::InputTag OurSegmentsTag
 
edm::EDGetTokenT< ME0SegmentCollectionOurSegmentsToken_
 
double thePHIDIR_RESIDUAL_CUT
 
double theX_PULL_CUT
 
double theX_RESIDUAL_CUT
 
double theY_PULL_CUT
 
double theY_RESIDUAL_CUT
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 

Detailed Description

Definition at line 32 of file ME0SegmentMatcher.cc.

Constructor & Destructor Documentation

ME0SegmentMatcher::ME0SegmentMatcher ( const edm::ParameterSet pas)
explicit

Constructor.

Definition at line 58 of file ME0SegmentMatcher.cc.

References generalTracksTag, generalTracksToken_, edm::ParameterSet::getParameter(), OurSegmentsTag, OurSegmentsToken_, thePHIDIR_RESIDUAL_CUT, theX_PULL_CUT, theX_RESIDUAL_CUT, theY_PULL_CUT, and theY_RESIDUAL_CUT.

58  {
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 }
T getParameter(std::string const &) const
edm::InputTag generalTracksTag
edm::EDGetTokenT< reco::TrackCollection > generalTracksToken_
edm::InputTag OurSegmentsTag
edm::EDGetTokenT< ME0SegmentCollection > OurSegmentsToken_
ME0SegmentMatcher::~ME0SegmentMatcher ( )
override

Destructor.

Definition at line 72 of file ME0SegmentMatcher.cc.

72 {}

Member Function Documentation

void ME0SegmentMatcher::beginRun ( edm::Run const &  iRun,
edm::EventSetup const &  iSetup 
)
override

Definition at line 271 of file ME0SegmentMatcher.cc.

References DEFINE_FWK_MODULE.

271 {}
void ME0SegmentMatcher::getFromFTS ( const FreeTrajectoryState fts,
GlobalVector p3,
GlobalVector r3,
int &  charge,
AlgebraicSymMatrix66 cov 
)

Definition at line 255 of file ME0SegmentMatcher.cc.

References FreeTrajectoryState::cartesianError(), FreeTrajectoryState::charge(), FreeTrajectoryState::hasError(), CartesianTrajectoryError::matrix(), FreeTrajectoryState::momentum(), FreeTrajectoryState::position(), PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by produce().

256  {
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 }
CartesianTrajectoryError cartesianError() const
T y() const
Definition: PV3DBase.h:60
TrackCharge charge() const
T z() const
Definition: PV3DBase.h:61
GlobalVector momentum() const
const AlgebraicSymMatrix66 & matrix() const
ROOT::Math::SMatrix< double, 6, 6, ROOT::Math::MatRepSym< double, 6 > > AlgebraicSymMatrix66
GlobalPoint position() const
T x() const
Definition: PV3DBase.h:59
FreeTrajectoryState ME0SegmentMatcher::getFTS ( const GlobalVector p3,
const GlobalVector r3,
int  charge,
const AlgebraicSymMatrix66 cov,
const MagneticField field 
)

Definition at line 241 of file ME0SegmentMatcher.cc.

References PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by produce().

245  {
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 }
T y() const
Definition: PV3DBase.h:60
T z() const
Definition: PV3DBase.h:61
T x() const
Definition: PV3DBase.h:59
FreeTrajectoryState ME0SegmentMatcher::getFTS ( const GlobalVector p3,
const GlobalVector r3,
int  charge,
const AlgebraicSymMatrix55 cov,
const MagneticField field 
)
void ME0SegmentMatcher::produce ( edm::Event ev,
const edm::EventSetup setup 
)
override

Produce the ME0Segment collection.

Definition at line 74 of file ME0SegmentMatcher.cc.

References funct::abs(), PV3DBase< T, PVType, FrameType >::barePhi(), barePhi(), Calorimetry_cff::bField, Plane::build(), gen::C, ME0Geometry::chamber(), relativeConstraints::chamber, reco::deltaPhi(), reco::deltaR2(), TrajectoryStateOnSurface::freeTrajectoryState(), isolatedTracks_cfi::generalTracks, generalTracksToken_, edm::EventSetup::get(), edm::Event::getByToken(), getFromFTS(), getFTS(), mps_fire::i, TrajectoryStateOnSurface::isValid(), dqmiolumiharvest::j, JacobianCartesianToLocal::jacobian(), eostools::move(), OurSegmentsToken_, Propagator::propagate(), edm::Event::put(), reco::ME0Muon::setGlobalTrackCov(), reco::ME0Muon::setGlobalTrackMomAtSurface(), reco::ME0Muon::setGlobalTrackPosAtSurface(), reco::ME0Muon::setLocalTrackCov(), reco::ME0Muon::setLocalTrackMomAtSurface(), reco::ME0Muon::setLocalTrackPosAtSurface(), mathSSE::sqrt(), thePHIDIR_RESIDUAL_CUT, theX_PULL_CUT, theX_RESIDUAL_CUT, theY_PULL_CUT, theY_RESIDUAL_CUT, PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), z, and PV3DBase< T, PVType, FrameType >::z().

74  {
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 }
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
const AlgebraicMatrix56 & jacobian() 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
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
FreeTrajectoryState getFTS(const GlobalVector &, const GlobalVector &, int, const AlgebraicSymMatrix66 &, const MagneticField *)
T y() const
Definition: PV3DBase.h:60
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepStd< double, 5, 5 > > AlgebraicMatrix55
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
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
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_
void setGlobalTrackCov(const AlgebraicSymMatrix66 &trackCov)
Definition: ME0Muon.h:70
ROOT::Math::SMatrix< double, 6, 6, ROOT::Math::MatRepSym< double, 6 > > AlgebraicSymMatrix66
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
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
def move(src, dest)
Definition: eostools.py:511
Global3DVector GlobalVector
Definition: GlobalVector.h:10
void setLocalTrackPosAtSurface(const LocalPoint &localTrackPosAtSurface)
Definition: ME0Muon.h:63

Member Data Documentation

edm::InputTag ME0SegmentMatcher::generalTracksTag
private

Definition at line 53 of file ME0SegmentMatcher.cc.

Referenced by ME0SegmentMatcher().

edm::EDGetTokenT<reco::TrackCollection> ME0SegmentMatcher::generalTracksToken_
private

Definition at line 55 of file ME0SegmentMatcher.cc.

Referenced by ME0SegmentMatcher(), and produce().

edm::InputTag ME0SegmentMatcher::OurSegmentsTag
private

Definition at line 53 of file ME0SegmentMatcher.cc.

Referenced by ME0SegmentMatcher().

edm::EDGetTokenT<ME0SegmentCollection> ME0SegmentMatcher::OurSegmentsToken_
private

Definition at line 54 of file ME0SegmentMatcher.cc.

Referenced by ME0SegmentMatcher(), and produce().

double ME0SegmentMatcher::thePHIDIR_RESIDUAL_CUT
private

Definition at line 52 of file ME0SegmentMatcher.cc.

Referenced by ME0SegmentMatcher(), and produce().

double ME0SegmentMatcher::theX_PULL_CUT
private

Definition at line 52 of file ME0SegmentMatcher.cc.

Referenced by ME0SegmentMatcher(), and produce().

double ME0SegmentMatcher::theX_RESIDUAL_CUT
private

Definition at line 52 of file ME0SegmentMatcher.cc.

Referenced by ME0SegmentMatcher(), and produce().

double ME0SegmentMatcher::theY_PULL_CUT
private

Definition at line 52 of file ME0SegmentMatcher.cc.

Referenced by ME0SegmentMatcher(), and produce().

double ME0SegmentMatcher::theY_RESIDUAL_CUT
private

Definition at line 52 of file ME0SegmentMatcher.cc.

Referenced by ME0SegmentMatcher(), and produce().