test
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 
9 
12 
14 
16 
18 
23 
24 
26 
27 
28 #include "TLorentzVector.h"
29 
33 
34 
40 
41 
53 
55 
58 
63 
65 
68 
71 
72 
73 
74 
76 class MagneticField;
78 public:
80  explicit ME0SegmentMatcher(const edm::ParameterSet&);
84  virtual void produce(edm::Event&, const edm::EventSetup&) override;
85 
86 
87  virtual void beginRun(edm::Run const&, edm::EventSetup const&) override;
88 
89 
90 
92  int , const AlgebraicSymMatrix66& ,
93  const MagneticField* );
94 
96  int , const AlgebraicSymMatrix55& ,
97  const MagneticField* );
98 
99  void getFromFTS(const FreeTrajectoryState& ,
101  int& , AlgebraicSymMatrix66& );
102 
103 private:
104 
105 
106 
111 
112 
113 };
114 
115 
117  produces<std::vector<reco::ME0Muon> >();
118  theX_PULL_CUT = pas.getParameter<double>("maxPullX");
119  theX_RESIDUAL_CUT = pas.getParameter<double>("maxDiffX");
120  theY_PULL_CUT = pas.getParameter<double>("maxPullY");
121  theY_RESIDUAL_CUT = pas.getParameter<double>("maxDiffY");
122  thePHIDIR_RESIDUAL_CUT = pas.getParameter<double>("maxDiffPhiDirection");
123  //Might need to replace "OurSegments" with an edm::InputTag of "OurSegments"
124  OurSegmentsTag = pas.getParameter<edm::InputTag>("me0SegmentTag");
125  generalTracksTag = pas.getParameter<edm::InputTag>("tracksTag");
126  OurSegmentsToken_ = consumes<ME0SegmentCollection>(OurSegmentsTag);
127  generalTracksToken_ = consumes<reco::TrackCollection>(generalTracksTag);
128 }
129 
131 
133 
134 
135  //Getting the objects we'll need
136  using namespace edm;
137 
138  ESHandle<ME0Geometry> me0Geom;
139  setup.get<MuonGeometryRecord>().get(me0Geom);
141  setup.get<IdealMagneticFieldRecord>().get(bField);
142  ESHandle<Propagator> ThisshProp;
143  setup.get<TrackingComponentsRecord>().get("SteppingHelixPropagatorAlong", ThisshProp);
144 
145  using namespace reco;
146 
147  Handle<ME0SegmentCollection> OurSegments;
148  //ev.getByLabel("me0Segments","",OurSegments);
149  ev.getByToken(OurSegmentsToken_,OurSegments);
150 
151  std::auto_ptr<std::vector<ME0Muon> > oc( new std::vector<ME0Muon> );
152  std::vector<ME0Muon> TempStore;
153 
155  //ev.getByLabel <TrackCollection> ("generalTracks", generalTracks);
157 
158 
159  int TrackNumber = 0;
160 
161  for (std::vector<Track>::const_iterator thisTrack = generalTracks->begin();
162  thisTrack != generalTracks->end(); ++thisTrack,++TrackNumber){
163  //Initializing our plane
164 
165  //Remove later
166  if (std::abs(thisTrack->eta()) < 1.8) continue;
167 
168  float zSign = thisTrack->pz() > 0 ? 1.0f : -1.0f;
169 
170  const float zValue = 526.75 * zSign;
171 
172  Plane *plane = new Plane(Surface::PositionType(0,0,zValue),Surface::RotationType());
173 
174  //Getting the initial variables for propagation
175 
176  int chargeReco = thisTrack->charge();
177  GlobalVector p3reco, r3reco;
178 
179  p3reco = GlobalVector(thisTrack->outerPx(), thisTrack->outerPy(), thisTrack->outerPz());
180  r3reco = GlobalVector(thisTrack->outerX(), thisTrack->outerY(), thisTrack->outerZ());
181 
182  AlgebraicSymMatrix66 covReco;
183  //This is to fill the cov matrix correctly
184  AlgebraicSymMatrix55 covReco_curv;
185  covReco_curv = thisTrack->outerStateCovariance();
186  FreeTrajectoryState initrecostate = getFTS(p3reco, r3reco, chargeReco, covReco_curv, &*bField);
187  getFromFTS(initrecostate, p3reco, r3reco, chargeReco, covReco);
188 
189  //Now we propagate and get the propagated variables from the propagated state
190  //SteppingHelixStateInfo startrecostate(initrecostate);
191  //SteppingHelixStateInfo lastrecostate;
192  TrajectoryStateOnSurface lastrecostate;
193 
194  //const SteppingHelixPropagator* ThisshProp =
195  //dynamic_cast<const SteppingHelixPropagator*>(&*shProp);
196 
197 
198 
199  //lastrecostate = ThisshProp->propagate(startrecostate, *plane);
200  //lastrecostate = ThisshProp->propagateWithPath(startrecostate, *plane);
201  //ThisshProp->propagate(startrecostate, *plane,lastrecostate);
202  lastrecostate = ThisshProp->propagate(initrecostate,*plane);
203 
204  FreeTrajectoryState finalrecostate(*lastrecostate.freeTrajectoryState());
205  //lastrecostate.getFreeState(finalrecostate);
206  //finalrecostate = lastrecostate.freeTrajectoryState();
207 
208  AlgebraicSymMatrix66 covFinalReco;
209  GlobalVector p3FinalReco_glob, r3FinalReco_globv;
210  getFromFTS(finalrecostate, p3FinalReco_glob, r3FinalReco_globv, chargeReco, covFinalReco);
211 
212 
213  //To transform the global propagated track to local coordinates
214  int SegmentNumber = 0;
215 
217  double ClosestDelR2 = 999.;
218 
219  for (auto thisSegment = OurSegments->begin(); thisSegment != OurSegments->end();
220  ++thisSegment,++SegmentNumber){
221  ME0DetId id = thisSegment->me0DetId();
222 
223  auto roll = me0Geom->etaPartition(id);
224 
225  if ( zSign * roll->toGlobal(thisSegment->localPosition()).z() < 0 ) continue;
226 
227  GlobalPoint r3FinalReco_glob(r3FinalReco_globv.x(),r3FinalReco_globv.y(),r3FinalReco_globv.z());
228 
229  LocalPoint r3FinalReco = roll->toLocal(r3FinalReco_glob);
230  LocalVector p3FinalReco=roll->toLocal(p3FinalReco_glob);
231 
232  LocalPoint thisPosition(thisSegment->localPosition());
233  LocalVector thisDirection(thisSegment->localDirection().x(),thisSegment->localDirection().y(),thisSegment->localDirection().z()); //FIXME
234 
235  //The same goes for the error
236  AlgebraicMatrix thisCov(4,4,0);
237  for (int i = 1; i <=4; i++){
238  for (int j = 1; j <=4; j++){
239  thisCov(i,j) = thisSegment->parametersError()(i,j);
240  }
241  }
242 
244 
245 
246  LocalTrajectoryParameters ltp(r3FinalReco,p3FinalReco,chargeReco);
247  JacobianCartesianToLocal jctl(roll->surface(),ltp);
248  AlgebraicMatrix56 jacobGlbToLoc = jctl.jacobian();
249 
250  AlgebraicMatrix55 Ctmp = (jacobGlbToLoc * covFinalReco) * ROOT::Math::Transpose(jacobGlbToLoc);
251  AlgebraicSymMatrix55 C; // I couldn't find any other way, so I resort to the brute force
252  for(int i=0; i<5; ++i) {
253  for(int j=0; j<5; ++j) {
254  C[i][j] = Ctmp[i][j];
255 
256  }
257  }
258 
259  Double_t sigmax = sqrt(C[3][3]+thisSegment->localPositionError().xx() );
260  Double_t sigmay = sqrt(C[4][4]+thisSegment->localPositionError().yy() );
261 
262  bool X_MatchFound = false, Y_MatchFound = false, Dir_MatchFound = false;
263 
264 
265  // if ( (std::abs(thisPosition.x()-r3FinalReco.x()) < (3.0 * sigmax)) || (std::abs(thisPosition.x()-r3FinalReco.x()) < 2.0 ) ) X_MatchFound = true;
266  // if ( (std::abs(thisPosition.y()-r3FinalReco.y()) < (3.0 * sigmay)) || (std::abs(thisPosition.y()-r3FinalReco.y()) < 2.0 ) ) Y_MatchFound = true;
267 
268  // if ( std::abs(p3FinalReco_glob.phi()-roll->toGlobal(thisSegment->localDirection()).phi()) < 0.15) Dir_MatchFound = true;
269 
270 
271  if ( (std::abs(thisPosition.x()-r3FinalReco.x()) < (theX_PULL_CUT * sigmax)) || (std::abs(thisPosition.x()-r3FinalReco.x()) < theX_RESIDUAL_CUT ) ) X_MatchFound = true;
272  if ( (std::abs(thisPosition.y()-r3FinalReco.y()) < (theY_PULL_CUT * sigmay)) || (std::abs(thisPosition.y()-r3FinalReco.y()) < theY_RESIDUAL_CUT ) ) Y_MatchFound = true;
273 
274  if ( std::abs(reco::deltaPhi(p3FinalReco_glob.phi(),roll->toGlobal(thisSegment->localDirection()).phi())) < thePHIDIR_RESIDUAL_CUT) Dir_MatchFound = true;
275 
276  //Check for a Match, and if there is a match, check the delR from the segment, keeping only the closest in MuonCandidate
277  if (X_MatchFound && Y_MatchFound && Dir_MatchFound) {
278 
279  TrackRef thisTrackRef(generalTracks,TrackNumber);
280 
281  GlobalPoint SegPos(roll->toGlobal(thisSegment->localPosition()));
282  GlobalPoint TkPos(r3FinalReco_globv.x(),r3FinalReco_globv.y(),r3FinalReco_globv.z());
283 
284  double thisDelR2 = reco::deltaR2(SegPos,TkPos);
285  if (thisDelR2 < ClosestDelR2){
286  ClosestDelR2 = thisDelR2;
287  MuonCandidate = reco::ME0Muon(thisTrackRef,(*thisSegment),SegmentNumber,chargeReco);
288 
289  MuonCandidate.setGlobalTrackPosAtSurface(r3FinalReco_glob);
290  MuonCandidate.setGlobalTrackMomAtSurface(p3FinalReco_glob);
291  MuonCandidate.setLocalTrackPosAtSurface(r3FinalReco);
292  MuonCandidate.setLocalTrackMomAtSurface(p3FinalReco);
293  MuonCandidate.setGlobalTrackCov(covFinalReco);
294  MuonCandidate.setLocalTrackCov(C);
295  }
296  }
297  }//End loop for (auto thisSegment = OurSegments->begin(); thisSegment != OurSegments->end(); ++thisSegment,++SegmentNumber)
298 
299  //As long as the delR of the MuonCandidate is sensible, store the track-segment pair
300  if (ClosestDelR2 < 500.) {
301  oc->push_back(MuonCandidate);
302  }
303  }
304 
305  // put collection in event
306 
307  ev.put(oc);
308 }
309 
312  int charge, const AlgebraicSymMatrix55& cov,
313  const MagneticField* field){
314 
315  GlobalVector p3GV(p3.x(), p3.y(), p3.z());
316  GlobalPoint r3GP(r3.x(), r3.y(), r3.z());
317  GlobalTrajectoryParameters tPars(r3GP, p3GV, charge, field);
318 
319  CurvilinearTrajectoryError tCov(cov);
320 
321  return cov.kRows == 5 ? FreeTrajectoryState(tPars, tCov) : FreeTrajectoryState(tPars) ;
322 }
323 
326  int charge, const AlgebraicSymMatrix66& cov,
327  const MagneticField* field){
328 
329  GlobalVector p3GV(p3.x(), p3.y(), p3.z());
330  GlobalPoint r3GP(r3.x(), r3.y(), r3.z());
331  GlobalTrajectoryParameters tPars(r3GP, p3GV, charge, field);
332 
333  CartesianTrajectoryError tCov(cov);
334 
335  return cov.kRows == 6 ? FreeTrajectoryState(tPars, tCov) : FreeTrajectoryState(tPars) ;
336 }
337 
340  int& charge, AlgebraicSymMatrix66& cov){
341  GlobalVector p3GV = fts.momentum();
342  GlobalPoint r3GP = fts.position();
343 
344  GlobalVector p3T(p3GV.x(), p3GV.y(), p3GV.z());
345  GlobalVector r3T(r3GP.x(), r3GP.y(), r3GP.z());
346  p3 = p3T;
347  r3 = r3T;
348  // p3.set(p3GV.x(), p3GV.y(), p3GV.z());
349  // r3.set(r3GP.x(), r3GP.y(), r3GP.z());
350 
351  charge = fts.charge();
352  cov = fts.hasError() ? fts.cartesianError().matrix() : AlgebraicSymMatrix66();
353 
354 }
355 
356 
357 void ME0SegmentMatcher::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup)
358 {
359 
360 }
361 
362 
const AlgebraicMatrix56 & jacobian() const
T getParameter(std::string const &) const
void setLocalTrackMomAtSurface(const LocalVector &localTrackMomAtSurface)
Definition: ME0Muon.h:56
int i
Definition: DBlmapReader.cc:9
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:464
FreeTrajectoryState getFTS(const GlobalVector &, const GlobalVector &, int, const AlgebraicSymMatrix66 &, const MagneticField *)
ME0SegmentMatcher(const edm::ParameterSet &)
Constructor.
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
ROOT::Math::SMatrix< double, 6, 6, ROOT::Math::MatRepSym< double, 6 > > AlgebraicSymMatrix66
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
T y() const
Definition: PV3DBase.h:63
bool ev
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
edm::InputTag generalTracksTag
TrackCharge charge() const
Definition: Plane.h:17
virtual 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_
~ME0SegmentMatcher()
Destructor.
void setLocalTrackCov(const AlgebraicSymMatrix55 &trackCov)
Definition: ME0Muon.h:59
CLHEP::HepMatrix AlgebraicMatrix
FreeTrajectoryState const * freeTrajectoryState(bool withErrors=true) const
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
T sqrt(T t)
Definition: SSEVec.h:48
edm::InputTag OurSegmentsTag
T z() const
Definition: PV3DBase.h:64
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int j
Definition: DBlmapReader.cc:9
double deltaR2(const T1 &t1, const T2 &t2)
Definition: deltaR.h:36
edm::EDGetTokenT< ME0SegmentCollection > OurSegmentsToken_
GlobalVector momentum() const
void setGlobalTrackCov(const AlgebraicSymMatrix66 &trackCov)
Definition: ME0Muon.h:58
const AlgebraicSymMatrix66 & matrix() const
double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:12
GlobalPoint position() const
const T & get() const
Definition: EventSetup.h:56
void getFromFTS(const FreeTrajectoryState &, GlobalVector &, GlobalVector &, int &, AlgebraicSymMatrix66 &)
void setGlobalTrackPosAtSurface(const GlobalPoint &globalTrackPosAtSurface)
Definition: ME0Muon.h:53
T x() const
Definition: PV3DBase.h:62
virtual void beginRun(edm::Run const &, edm::EventSetup const &) override
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepStd< double, 5, 5 > > AlgebraicMatrix55
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
Definition: Run.h:43
Global3DVector GlobalVector
Definition: GlobalVector.h:10
void setLocalTrackPosAtSurface(const LocalPoint &localTrackPosAtSurface)
Definition: ME0Muon.h:55
double p3[4]
Definition: TauolaWrapper.h:91