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  int , const AlgebraicSymMatrix66& ,
45  const MagneticField* );
46 
48  int , const AlgebraicSymMatrix55& ,
49  const MagneticField* );
50 
51  void getFromFTS(const FreeTrajectoryState& ,
53  int& , AlgebraicSymMatrix66& );
54 
55 private:
56 
61 
62 };
63 
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 }
78 
80 
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 }
225 
228  int charge, const AlgebraicSymMatrix55& cov,
229  const MagneticField* field){
230 
231  GlobalVector p3GV(p3.x(), p3.y(), p3.z());
232  GlobalPoint r3GP(r3.x(), r3.y(), r3.z());
233  GlobalTrajectoryParameters tPars(r3GP, p3GV, charge, field);
234 
235  CurvilinearTrajectoryError tCov(cov);
236 
237  return cov.kRows == 5 ? FreeTrajectoryState(tPars, tCov) : FreeTrajectoryState(tPars) ;
238 }
239 
242  int charge, const AlgebraicSymMatrix66& cov,
243  const MagneticField* field){
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 }
253 
256  int& charge, AlgebraicSymMatrix66& cov){
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:22
const AlgebraicMatrix56 & jacobian() const
T getParameter(std::string const &) 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:125
CartesianTrajectoryError cartesianError() const
ROOT::Math::SMatrix< double, 5, 6, ROOT::Math::MatRepStd< double, 5, 6 > > AlgebraicMatrix56
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
FreeTrajectoryState getFTS(const GlobalVector &, const GlobalVector &, int, const AlgebraicSymMatrix66 &, const MagneticField *)
ME0SegmentMatcher(const edm::ParameterSet &)
Constructor.
ROOT::Math::SMatrix< double, 6, 6, ROOT::Math::MatRepSym< double, 6 > > AlgebraicSymMatrix66
T y() const
Definition: PV3DBase.h:63
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
bool ev
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
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:54
edm::EDGetTokenT< reco::TrackCollection > generalTracksToken_
T barePhi() const
Definition: PV3DBase.h:68
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
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
edm::InputTag OurSegmentsTag
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_
GlobalVector momentum() const
void setGlobalTrackCov(const AlgebraicSymMatrix66 &trackCov)
Definition: ME0Muon.h:58
const AlgebraicSymMatrix66 & matrix() const
GlobalPoint position() const
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
~ME0SegmentMatcher() override
Destructor.
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:71
T x() const
Definition: PV3DBase.h:62
void beginRun(edm::Run const &, edm::EventSetup const &) override
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepStd< double, 5, 5 > > AlgebraicMatrix55
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:55
double p3[4]
Definition: TauolaWrapper.h:91