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 hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () 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 64 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.

64  {
65  produces<std::vector<reco::ME0Muon> >();
66  theX_PULL_CUT = pas.getParameter<double>("maxPullX");
67  theX_RESIDUAL_CUT = pas.getParameter<double>("maxDiffX");
68  theY_PULL_CUT = pas.getParameter<double>("maxPullY");
69  theY_RESIDUAL_CUT = pas.getParameter<double>("maxDiffY");
70  thePHIDIR_RESIDUAL_CUT = pas.getParameter<double>("maxDiffPhiDirection");
71  //Might need to replace "OurSegments" with an edm::InputTag of "OurSegments"
72  OurSegmentsTag = pas.getParameter<edm::InputTag>("me0SegmentTag");
73  generalTracksTag = pas.getParameter<edm::InputTag>("tracksTag");
74  OurSegmentsToken_ = consumes<ME0SegmentCollection>(OurSegmentsTag);
75  generalTracksToken_ = consumes<reco::TrackCollection>(generalTracksTag);
76 
77 }
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 79 of file ME0SegmentMatcher.cc.

79 {}

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 254 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
ROOT::Math::SMatrix< double, 6, 6, ROOT::Math::MatRepSym< double, 6 > > AlgebraicSymMatrix66
T y() const
Definition: PV3DBase.h:63
TrackCharge charge() const
T z() const
Definition: PV3DBase.h:64
GlobalVector momentum() const
const AlgebraicSymMatrix66 & matrix() const
GlobalPoint position() const
T x() const
Definition: PV3DBase.h:62
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().

243  {
244 
245  GlobalVector p3GV(p3.x(), p3.y(), p3.z());
246  GlobalPoint r3GP(r3.x(), r3.y(), r3.z());
247  GlobalTrajectoryParameters tPars(r3GP, p3GV, charge, field);
248 
249  CartesianTrajectoryError tCov(cov);
250 
251  return cov.kRows == 6 ? FreeTrajectoryState(tPars, tCov) : FreeTrajectoryState(tPars) ;
252 }
T y() const
Definition: PV3DBase.h:63
T z() const
Definition: PV3DBase.h:64
T x() const
Definition: PV3DBase.h:62
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 81 of file ME0SegmentMatcher.cc.

References funct::abs(), PV3DBase< T, PVType, FrameType >::barePhi(), barePhi(), ecalTB2006H4_GenSimDigiReco_cfg::bField, Plane::build(), patCaloMETCorrections_cff::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(), 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().

81  {
82 
83  //Getting the objects we'll need
84  using namespace edm;
85 
86  ESHandle<ME0Geometry> me0Geom;
87  setup.get<MuonGeometryRecord>().get(me0Geom);
89  setup.get<IdealMagneticFieldRecord>().get(bField);
90  ESHandle<Propagator> ThisshProp;
91  setup.get<TrackingComponentsRecord>().get("SteppingHelixPropagatorAlong", ThisshProp);
92 
93  using namespace reco;
94 
95  Handle<ME0SegmentCollection> OurSegments;
96  ev.getByToken(OurSegmentsToken_,OurSegments);
97 
98  auto oc = std::make_unique<std::vector<ME0Muon>>();
99  std::vector<ME0Muon> TempStore;
100 
102  ev.getByToken(generalTracksToken_,generalTracks);
103 
104  int TrackNumber = 0;
105 
106  for (std::vector<Track>::const_iterator thisTrack = generalTracks->begin();
107  thisTrack != generalTracks->end(); ++thisTrack,++TrackNumber){
108  //Initializing our plane
109 
110  //Remove later
111  if (std::abs(thisTrack->eta()) < 1.8) continue;
112 
113  //Getting the initial variables for propagation
114  float zSign = thisTrack->pz() > 0 ? 1.0f : -1.0f;
115 
117 
118  int chargeReco = thisTrack->charge();
119  GlobalVector p3reco, r3reco;
120 
121  p3reco = GlobalVector(thisTrack->outerPx(), thisTrack->outerPy(), thisTrack->outerPz());
122  r3reco = GlobalVector(thisTrack->outerX(), thisTrack->outerY(), thisTrack->outerZ());
123 
124  AlgebraicSymMatrix66 covReco;
125  //This is to fill the cov matrix correctly
126  const AlgebraicSymMatrix55 & covReco_curv = thisTrack->outerStateCovariance();
127  FreeTrajectoryState initrecostate = getFTS(p3reco, r3reco, chargeReco, covReco_curv, &*bField);
128  getFromFTS(initrecostate, p3reco, r3reco, chargeReco, covReco);
129 
130  //Now we propagate and get the propagated variables from the propagated state
131  TrajectoryStateOnSurface lastrecostate = ThisshProp->propagate(initrecostate,*plane);
132  if (!lastrecostate.isValid()) continue;
133 
134  FreeTrajectoryState finalrecostate(*lastrecostate.freeTrajectoryState());
135 
136  AlgebraicSymMatrix66 covFinalReco;
137  GlobalVector p3FinalReco_glob, r3FinalReco_globv;
138  getFromFTS(finalrecostate, p3FinalReco_glob, r3FinalReco_globv, chargeReco, covFinalReco);
139 
140  //To transform the global propagated track to local coordinates
141  int SegmentNumber = 0;
142 
144  double ClosestDelR2 = 999.;
145 
146  for (auto thisSegment = OurSegments->begin(); thisSegment != OurSegments->end();
147  ++thisSegment,++SegmentNumber){
148  ME0DetId id = thisSegment->me0DetId();
149 
150  auto chamber = me0Geom->chamber(id);
151 
152  if ( zSign * chamber->toGlobal(thisSegment->localPosition()).z() < 0 ) continue;
153 
154  GlobalPoint r3FinalReco_glob(r3FinalReco_globv.x(),r3FinalReco_globv.y(),r3FinalReco_globv.z());
155 
156  LocalPoint r3FinalReco = chamber->toLocal(r3FinalReco_glob);
157  LocalVector p3FinalReco=chamber->toLocal(p3FinalReco_glob);
158 
159  LocalPoint thisPosition(thisSegment->localPosition());
160  LocalVector thisDirection(thisSegment->localDirection().x(),thisSegment->localDirection().y(),thisSegment->localDirection().z()); //FIXME
161 
162  //The same goes for the error
163  AlgebraicMatrix thisCov(4,4,0);
164  for (int i = 1; i <=4; i++){
165  for (int j = 1; j <=4; j++){
166  thisCov(i,j) = thisSegment->parametersError()(i,j);
167  }
168  }
169 
170  LocalTrajectoryParameters ltp(r3FinalReco,p3FinalReco,chargeReco);
171  JacobianCartesianToLocal jctl(chamber->surface(),ltp);
172  const AlgebraicMatrix56& jacobGlbToLoc = jctl.jacobian();
173 
174  AlgebraicMatrix55 Ctmp = (jacobGlbToLoc * covFinalReco) * ROOT::Math::Transpose(jacobGlbToLoc);
175  AlgebraicSymMatrix55 C; // I couldn't find any other way, so I resort to the brute force
176  for(int i=0; i<5; ++i) {
177  for(int j=0; j<5; ++j) {
178  C[i][j] = Ctmp[i][j];
179 
180  }
181  }
182 
183  Double_t sigmax = sqrt(C[3][3]+thisSegment->localPositionError().xx() );
184  Double_t sigmay = sqrt(C[4][4]+thisSegment->localPositionError().yy() );
185 
186  bool X_MatchFound = false, Y_MatchFound = false, Dir_MatchFound = false;
187 
188  if ( (std::abs(thisPosition.x()-r3FinalReco.x()) < (theX_PULL_CUT * sigmax)) || (std::abs(thisPosition.x()-r3FinalReco.x()) < theX_RESIDUAL_CUT ) ) X_MatchFound = true;
189  if ( (std::abs(thisPosition.y()-r3FinalReco.y()) < (theY_PULL_CUT * sigmay)) || (std::abs(thisPosition.y()-r3FinalReco.y()) < theY_RESIDUAL_CUT ) ) Y_MatchFound = true;
190 
191  if ( std::abs(reco::deltaPhi(p3FinalReco_glob.barePhi(),chamber->toGlobal(thisSegment->localDirection()).barePhi())) < thePHIDIR_RESIDUAL_CUT) Dir_MatchFound = true;
192 
193  //Check for a Match, and if there is a match, check the delR from the segment, keeping only the closest in MuonCandidate
194  if (X_MatchFound && Y_MatchFound && Dir_MatchFound) {
195 
196  TrackRef thisTrackRef(generalTracks,TrackNumber);
197 
198  GlobalPoint SegPos(chamber->toGlobal(thisSegment->localPosition()));
199  GlobalPoint TkPos(r3FinalReco_globv.x(),r3FinalReco_globv.y(),r3FinalReco_globv.z());
200 
201  double thisDelR2 = reco::deltaR2(SegPos,TkPos);
202  if (thisDelR2 < ClosestDelR2){
203  ClosestDelR2 = thisDelR2;
204  MuonCandidate = reco::ME0Muon(thisTrackRef,(*thisSegment),SegmentNumber,chargeReco);
205 
206  MuonCandidate.setGlobalTrackPosAtSurface(r3FinalReco_glob);
207  MuonCandidate.setGlobalTrackMomAtSurface(p3FinalReco_glob);
208  MuonCandidate.setLocalTrackPosAtSurface(r3FinalReco);
209  MuonCandidate.setLocalTrackMomAtSurface(p3FinalReco);
210  MuonCandidate.setGlobalTrackCov(covFinalReco);
211  MuonCandidate.setLocalTrackCov(C);
212  }
213  }
214  }//End loop for (auto thisSegment = OurSegments->begin(); thisSegment != OurSegments->end(); ++thisSegment,++SegmentNumber)
215 
216  //As long as the delR of the MuonCandidate is sensible, store the track-segment pair
217  if (ClosestDelR2 < 500.) {
218  oc->push_back(MuonCandidate);
219  }
220  }
221 
222  // put collection in event
223  ev.put(std::move(oc));
224 }
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:22
const AlgebraicMatrix56 & jacobian() const
T barePhi() const
void setLocalTrackMomAtSurface(const LocalVector &localTrackMomAtSurface)
Definition: ME0Muon.h:56
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
ROOT::Math::SMatrix< double, 5, 6, ROOT::Math::MatRepStd< double, 5, 6 > > AlgebraicMatrix56
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
FreeTrajectoryState getFTS(const GlobalVector &, const GlobalVector &, int, const AlgebraicSymMatrix66 &, const MagneticField *)
ROOT::Math::SMatrix< double, 6, 6, ROOT::Math::MatRepSym< double, 6 > > AlgebraicSymMatrix66
T y() const
Definition: PV3DBase.h:63
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
void setGlobalTrackMomAtSurface(const GlobalVector &globalTrackMomAtSurface)
Definition: ME0Muon.h:54
edm::EDGetTokenT< reco::TrackCollection > generalTracksToken_
T barePhi() const
Definition: PV3DBase.h:68
void setLocalTrackCov(const AlgebraicSymMatrix55 &trackCov)
Definition: ME0Muon.h:59
CLHEP::HepMatrix AlgebraicMatrix
FreeTrajectoryState const * freeTrajectoryState(bool withErrors=true) const
T sqrt(T t)
Definition: SSEVec.h:18
static PlanePointer build(Args &&...args)
Definition: Plane.h:33
T z() const
Definition: PV3DBase.h:64
const ME0Chamber * chamber(ME0DetId id) const
Return a chamber given its id.
Definition: ME0Geometry.cc:73
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::EDGetTokenT< ME0SegmentCollection > OurSegmentsToken_
void setGlobalTrackCov(const AlgebraicSymMatrix66 &trackCov)
Definition: ME0Muon.h:58
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
void getFromFTS(const FreeTrajectoryState &, GlobalVector &, GlobalVector &, int &, AlgebraicSymMatrix66 &)
void setGlobalTrackPosAtSurface(const GlobalPoint &globalTrackPosAtSurface)
Definition: ME0Muon.h:53
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
Definition: Propagator.h:53
fixed size matrix
HLT enums.
T get() const
Definition: EventSetup.h:62
T x() const
Definition: PV3DBase.h:62
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepStd< double, 5, 5 > > AlgebraicMatrix55
def move(src, dest)
Definition: eostools.py:511
Global3DVector GlobalVector
Definition: GlobalVector.h:10
void setLocalTrackPosAtSurface(const LocalPoint &localTrackPosAtSurface)
Definition: ME0Muon.h:55

Member Data Documentation

edm::InputTag ME0SegmentMatcher::generalTracksTag
private

Definition at line 58 of file ME0SegmentMatcher.cc.

Referenced by ME0SegmentMatcher().

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

Definition at line 60 of file ME0SegmentMatcher.cc.

Referenced by ME0SegmentMatcher(), and produce().

edm::InputTag ME0SegmentMatcher::OurSegmentsTag
private

Definition at line 58 of file ME0SegmentMatcher.cc.

Referenced by ME0SegmentMatcher().

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

Definition at line 59 of file ME0SegmentMatcher.cc.

Referenced by ME0SegmentMatcher(), and produce().

double ME0SegmentMatcher::thePHIDIR_RESIDUAL_CUT
private

Definition at line 57 of file ME0SegmentMatcher.cc.

Referenced by ME0SegmentMatcher(), and produce().

double ME0SegmentMatcher::theX_PULL_CUT
private

Definition at line 57 of file ME0SegmentMatcher.cc.

Referenced by ME0SegmentMatcher(), and produce().

double ME0SegmentMatcher::theX_RESIDUAL_CUT
private

Definition at line 57 of file ME0SegmentMatcher.cc.

Referenced by ME0SegmentMatcher(), and produce().

double ME0SegmentMatcher::theY_PULL_CUT
private

Definition at line 57 of file ME0SegmentMatcher.cc.

Referenced by ME0SegmentMatcher(), and produce().

double ME0SegmentMatcher::theY_RESIDUAL_CUT
private

Definition at line 57 of file ME0SegmentMatcher.cc.

Referenced by ME0SegmentMatcher(), and produce().