CMS 3D CMS Logo

TwoBodyDecayTrajectoryFactory.cc
Go to the documentation of this file.
8 
10 
12 
14 
17 
20 
22 
29 public:
33 
36 
40  const reco::BeamSpot &beamSpot) const override;
41 
45  const reco::BeamSpot &beamSpot) const override;
46 
47  TwoBodyDecayTrajectoryFactory *clone() const override { return new TwoBodyDecayTrajectoryFactory(*this); }
48 
49 protected:
51  const TwoBodyDecay &tbd,
52  const MagneticField *magField,
53  const reco::BeamSpot &beamSpot,
54  bool setParameterErrors) const;
55 
57 
59 
63 
68 };
69 
73 
75  : TrajectoryFactoryBase(config, 2), theFitter(config) {
76  const edm::ParameterSet ppc = config.getParameter<edm::ParameterSet>("ParticleProperties");
77  thePrimaryMass = ppc.getParameter<double>("PrimaryMass");
78  thePrimaryWidth = ppc.getParameter<double>("PrimaryWidth");
79  theSecondaryMass = ppc.getParameter<double>("SecondaryMass");
80 
81  theNSigmaCutValue = config.getParameter<double>("NSigmaCut");
82  theChi2CutValue = config.getParameter<double>("Chi2Cut");
83  theUseRefittedStateFlag = config.getParameter<bool>("UseRefittedState");
84  theConstructTsosWithErrorsFlag = config.getParameter<bool>("ConstructTsosWithErrors");
85 }
86 
88 
92 
94  setup.get<IdealMagneticFieldRecord>().get(magneticField);
95 
96  if (tracks.size() == 2) {
97  // produce transient tracks from persistent tracks
98  std::vector<reco::TransientTrack> transientTracks(2);
99 
100  transientTracks[0] = reco::TransientTrack(*tracks[0].second, magneticField.product());
101  transientTracks[0].setES(setup);
102 
103  transientTracks[1] = reco::TransientTrack(*tracks[1].second, magneticField.product());
104  transientTracks[1].setES(setup);
105 
106  // estimate the decay parameters
108  TwoBodyDecay tbd = theFitter.estimate(transientTracks, vm);
109 
110  if (!tbd.isValid() || (tbd.chi2() > theChi2CutValue)) {
111  trajectories.push_back(ReferenceTrajectoryPtr(new TwoBodyDecayTrajectory()));
112  return trajectories;
113  }
114 
115  return constructTrajectories(tracks, tbd, magneticField.product(), beamSpot, false);
116  } else {
117  edm::LogInfo("ReferenceTrajectories") << "@SUB=TwoBodyDecayTrajectoryFactory::trajectories"
118  << "Need 2 tracks, got " << tracks.size() << ".\n";
119  }
120 
121  return trajectories;
122 }
123 
125  const edm::EventSetup &setup,
128  const reco::BeamSpot &beamSpot) const {
130 
132  setup.get<IdealMagneticFieldRecord>().get(magneticField);
133 
134  if (tracks.size() == 2 && external.size() == 2) {
135  if (external[0].isValid() && external[1].isValid()) // Include external estimates
136  {
137  // produce transient tracks from persistent tracks
138  std::vector<reco::TransientTrack> transientTracks(2);
139 
140  transientTracks[0] = reco::TransientTrack(*tracks[0].second, magneticField.product());
141  transientTracks[0].setES(setup);
142 
143  transientTracks[1] = reco::TransientTrack(*tracks[1].second, magneticField.product());
144  transientTracks[1].setES(setup);
145 
146  // estimate the decay parameters. the transient tracks are not really associated to the
147  // the external tsos, but this is o.k., because the only information retrieved from them
148  // is the magnetic field.
150  TwoBodyDecay tbd = theFitter.estimate(transientTracks, external, vm);
151 
152  if (!tbd.isValid() || (tbd.chi2() > theChi2CutValue)) {
153  trajectories.push_back(ReferenceTrajectoryPtr(new TwoBodyDecayTrajectory()));
154  return trajectories;
155  }
156 
157  return constructTrajectories(tracks, tbd, magneticField.product(), beamSpot, true);
158  } else {
159  // Return without external estimate
160  trajectories = this->trajectories(setup, tracks, beamSpot);
161  }
162  } else {
163  edm::LogInfo("ReferenceTrajectories") << "@SUB=TwoBodyDecayTrajectoryFactory::trajectories"
164  << "Need 2 tracks, got " << tracks.size() << ".\n";
165  }
166 
167  return trajectories;
168 }
169 
172  const TwoBodyDecay &tbd,
173  const MagneticField *magField,
174  const reco::BeamSpot &beamSpot,
175  bool setParameterErrors) const {
177 
178  // get innermost valid trajectory state and hits from the tracks
181 
182  if (!(input1.first.isValid() && input2.first.isValid()))
183  return trajectories;
184 
185  // produce TwoBodyDecayTrajectoryState (input for TwoBodyDecayTrajectory)
186  TsosContainer tsos(input1.first, input2.first);
187  ConstRecHitCollection recHits(input1.second, input2.second);
188  TwoBodyDecayTrajectoryState trajectoryState(tsos, tbd, theSecondaryMass, magField);
189 
190  if (!trajectoryState.isValid()) {
191  trajectories.push_back(ReferenceTrajectoryPtr(new TwoBodyDecayTrajectory()));
192  return trajectories;
193  }
194 
195  // always use the refitted trajectory state for matching
196  // FIXME FIXME CLONE
197  //TrackingRecHit::ConstRecHitPointer updatedRecHit1( recHits.first.front()->clone( tsos.first ) );
198  // TrackingRecHit::ConstRecHitPointer updatedRecHit2( recHits.second.front()->clone( tsos.second ) );
199 
200  TrackingRecHit::ConstRecHitPointer updatedRecHit1(recHits.first.front());
201  TrackingRecHit::ConstRecHitPointer updatedRecHit2(recHits.second.front());
202 
203  bool valid1 = match(trajectoryState.trajectoryStates(true).first, updatedRecHit1);
204 
205  bool valid2 = match(trajectoryState.trajectoryStates(true).second, updatedRecHit2);
206 
207  if (!valid1 || !valid2) {
208  trajectories.push_back(ReferenceTrajectoryPtr(new TwoBodyDecayTrajectory()));
209  return trajectories;
210  }
211 
213  config.useBeamSpot = useBeamSpot_;
214  config.includeAPEs = includeAPEs_;
218  // set the flag for reversing the RecHits to false, since they are already in the correct order.
219  config.hitsAreReverse = false;
220  TwoBodyDecayTrajectory *result = new TwoBodyDecayTrajectory(trajectoryState, recHits, magField, beamSpot, config);
221  if (setParameterErrors && tbd.hasError())
222  result->setParameterErrors(tbd.covariance());
223  trajectories.push_back(ReferenceTrajectoryPtr(result));
224  return trajectories;
225 }
226 
229  LocalPoint lp1 = state.localPosition();
230  LocalPoint lp2 = recHit->localPosition();
231 
232  double deltaX = lp1.x() - lp2.x();
233  double deltaY = lp1.y() - lp2.y();
234 
235  LocalError le = recHit->localPositionError();
236 
237  double varX = le.xx();
238  double varY = le.yy();
239 
240  return ((fabs(deltaX) / sqrt(varX) < theNSigmaCutValue) && (fabs(deltaY) / sqrt(varY) < theNSigmaCutValue));
241 }
242 
T getParameter(std::string const &) const
float xx() const
Definition: LocalError.h:22
bool hasError(void) const
Definition: TwoBodyDecay.h:42
const ReferenceTrajectoryCollection trajectories(const edm::EventSetup &setup, const ConstTrajTrackPairCollection &tracks, const reco::BeamSpot &beamSpot) const override
Produce the trajectories.
MaterialEffects materialEffects(void) const
TwoBodyDecayTrajectory::ConstRecHitCollection ConstRecHitCollection
TwoBodyDecayVirtualMeasurement VirtualMeasurement
void setParameterErrors(const AlgebraicSymMatrix &error)
const ReferenceTrajectoryCollection constructTrajectories(const ConstTrajTrackPairCollection &tracks, const TwoBodyDecay &tbd, const MagneticField *magField, const reco::BeamSpot &beamSpot, bool setParameterErrors) const
T y() const
Definition: PV3DBase.h:60
Definition: config.py:1
const TsosContainer & trajectoryStates(bool useRefittedState=true) const
#define input2
Definition: AMPTWrapper.h:159
bool match(const TrajectoryStateOnSurface &state, const TransientTrackingRecHit::ConstRecHitPointer &recHit) const
virtual const TwoBodyDecay estimate(const std::vector< reco::TransientTrack > &tracks, const TwoBodyDecayVirtualMeasurement &vm) const
U second(std::pair< T, U > const &p)
config
Definition: looper.py:291
const AlgebraicSymMatrix & covariance(void) const
Definition: TwoBodyDecay.h:34
float yy() const
Definition: LocalError.h:24
TwoBodyDecayTrajectoryFactory * clone() const override
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
T sqrt(T t)
Definition: SSEVec.h:19
#define input1
Definition: AMPTWrapper.h:139
void setES(const edm::EventSetup &es)
bool isValid(void) const
Definition: TwoBodyDecay.h:46
std::pair< TrajectoryStateOnSurface, TransientTrackingRecHit::ConstRecHitContainer > TrajectoryInput
virtual const TrajectoryInput innermostStateAndRecHits(const ConstTrajTrackPair &track) const
AlignmentAlgorithmBase::ConstTrajTrackPairCollection ConstTrajTrackPairCollection
std::pair< TrajectoryStateOnSurface, TrajectoryStateOnSurface > TsosContainer
double chi2(void) const
Definition: TwoBodyDecay.h:44
TwoBodyDecayTrajectoryFactory(const edm::ParameterSet &config)
T get() const
Definition: EventSetup.h:73
PropagationDirection propagationDirection(void) const
std::vector< TrajectoryStateOnSurface > ExternalPredictionCollection
#define DEFINE_EDM_PLUGIN(factory, type, name)
T x() const
Definition: PV3DBase.h:59
ReferenceTrajectoryBase::ReferenceTrajectoryPtr ReferenceTrajectoryPtr
T const * product() const
Definition: ESHandle.h:86
std::vector< ReferenceTrajectoryPtr > ReferenceTrajectoryCollection
TwoBodyDecayTrajectoryState::TsosContainer TsosContainer
std::pair< ConstRecHitContainer, ConstRecHitContainer > ConstRecHitCollection