CMS 3D CMS Logo

TwoBodyDecayMomConstraintProducer.cc
Go to the documentation of this file.
1 
10 #include <memory>
11 
18 
21 
24 
26 
32 
33 // // debug
34 // #include <map>
35 // #include "TH1F.h"
36 // #include "TFile.h"
37 // #include "TLorentzVector.h"
38 // #include "Alignment/TwoBodyDecay/interface/TwoBodyDecayModel.h"
39 
41 public:
43  ~TwoBodyDecayMomConstraintProducer() override = default;
44 
45 private:
46  void produce(edm::StreamID streamid, edm::Event&, const edm::EventSetup&) const override;
47 
48  std::pair<double, double> momentaAtVertex(const TwoBodyDecay& tbd) const;
49 
50  std::pair<double, double> momentaAtInnermostSurface(const TwoBodyDecay& tbd,
51  const std::vector<reco::TransientTrack>& ttracks,
52  const MagneticField* magField) const;
53 
54  std::pair<bool, TrajectoryStateOnSurface> innermostState(const reco::TransientTrack& ttrack) const;
55  bool match(const TrajectoryStateOnSurface& newTsos, const TrajectoryStateOnSurface& oldTsos) const;
56 
59 
61 
62  const double primaryMass_;
63  const double primaryWidth_;
64  const double secondaryMass_;
65 
66  const double sigmaPositionCutValue_;
67  const double chi2CutValue_;
68  const double fixedMomentumError_;
69 
72 
73  static MomentumForRefitting momentumForRefittingFromString(std::string momentumForRefittingString);
74 
77 
80  // // debug
81  // std::map<std::string, TH1F*> histos_;
82 };
83 
85  : srcTag_(iConfig.getParameter<edm::InputTag>("src")),
86  bsSrcTag_(iConfig.getParameter<edm::InputTag>("beamSpot")),
87  tbdFitter_(iConfig),
88  primaryMass_(iConfig.getParameter<double>("primaryMass")),
89  primaryWidth_(iConfig.getParameter<double>("primaryWidth")),
90  secondaryMass_(iConfig.getParameter<double>("secondaryMass")),
91  sigmaPositionCutValue_(iConfig.getParameter<double>("sigmaPositionCut")),
92  chi2CutValue_(iConfig.getParameter<double>("chi2Cut")),
93  fixedMomentumError_(iConfig.getParameter<double>("fixedMomentumError")),
94  momentumForRefitting_(momentumForRefittingFromString(iConfig.getParameter<std::string>("momentumForRefitting"))),
95  magFieldToken_(esConsumes()),
96  trackingGeometryToken_(esConsumes()) {
97  trackCollToken_ = consumes<reco::TrackCollection>(edm::InputTag(srcTag_));
98  bsToken_ = consumes<reco::BeamSpot>(edm::InputTag(bsSrcTag_));
99 
100  produces<std::vector<MomentumConstraint> >();
101  produces<TrackMomConstraintAssociationCollection>();
102 
103  // //debug
104  // histos_["deltaEta1"] = new TH1F( "deltaEta1", "deltaEta1", 200, -1., 1. );
105  // histos_["deltaP1"] = new TH1F( "deltaP1", "deltaP1", 200, -50., 50. );
106 
107  // histos_["deltaEta2"] = new TH1F( "deltaEta2", "deltaEta2", 200, -1., 1. );
108  // histos_["deltaP2"] = new TH1F( "deltaP2", "deltaP2", 200, -50., 50. );
109 }
110 
113  const edm::EventSetup& iSetup) const {
114  using namespace edm;
115 
117  iEvent.getByToken(trackCollToken_, trackColl);
118 
120  iEvent.getByToken(bsToken_, beamSpot);
121 
122  auto const* magField = &iSetup.getData(magFieldToken_);
123 
124  auto trackingGeometry = iSetup.getHandle(trackingGeometryToken_);
125 
126  edm::RefProd<std::vector<MomentumConstraint> > rPairs = iEvent.getRefBeforePut<std::vector<MomentumConstraint> >();
127  std::unique_ptr<std::vector<MomentumConstraint> > pairs(new std::vector<MomentumConstraint>);
128  std::unique_ptr<TrackMomConstraintAssociationCollection> output(
130 
131  if (trackColl->size() == 2) {
134 
136  std::vector<reco::TransientTrack> ttracks(2);
137  ttracks[0] = reco::TransientTrack(reco::TrackRef(trackColl, 0), magField);
138  ttracks[0].setTrackingGeometry(trackingGeometry);
139  ttracks[1] = reco::TransientTrack(reco::TrackRef(trackColl, 1), magField);
140  ttracks[1].setTrackingGeometry(trackingGeometry);
141 
143  TwoBodyDecay tbd = tbdFitter_.estimate(ttracks, vm);
144 
145  if (!tbd.isValid() or (tbd.chi2() > chi2CutValue_))
146  return;
147 
148  std::pair<double, double> fitMomenta;
150  fitMomenta = momentaAtVertex(tbd);
152  fitMomenta = momentaAtInnermostSurface(tbd, ttracks, magField);
153  } // no other possibility!!!
154 
155  if ((fitMomenta.first > 0.) and (fitMomenta.second > 0.)) {
156  // produce constraint for first track
157  MomentumConstraint constraint1(fitMomenta.first, fixedMomentumError_);
158  pairs->push_back(constraint1);
159  output->insert(reco::TrackRef(trackColl, 0), edm::Ref<std::vector<MomentumConstraint> >(rPairs, 0));
160 
161  // produce constraint for second track
162  MomentumConstraint constraint2(fitMomenta.second, fixedMomentumError_);
163  pairs->push_back(constraint2);
164  output->insert(reco::TrackRef(trackColl, 1), edm::Ref<std::vector<MomentumConstraint> >(rPairs, 1));
165  }
166 
167  // // debug
168  // if ( tbd.isValid() and ( fitMomenta.first > 0. ) and ( fitMomenta.second > 0. ) ) {
169  // TwoBodyDecayModel model;
170  // const std::pair< AlgebraicVector, AlgebraicVector > fitMomenta = model.cartesianSecondaryMomenta( tbd );
171 
172  // TLorentzVector recoMomentum1( ttracks[0].track().px(), ttracks[0].track().py(), ttracks[0].track().pz(),
173  // sqrt((ttracks[0].track().p()*ttracks[0].track().p())+0.105658*0.105658) );
174  // TLorentzVector fitMomentum1( fitMomenta.first[0], fitMomenta.first[1], fitMomenta.first[2],
175  // sqrt( fitMomenta.first.normsq()+0.105658*0.105658) );
176  // histos_["deltaP1"]->Fill( recoMomentum1.P() - fitMomentum1.P() );
177  // histos_["deltaEta1"]->Fill( recoMomentum1.Eta() - fitMomentum1.Eta() );
178 
179  // TLorentzVector recoMomentum2( ttracks[1].track().px(), ttracks[1].track().py(), ttracks[1].track().pz(),
180  // sqrt((ttracks[1].track().p()*ttracks[1].track().p())+0.105658*0.105658) );
181  // TLorentzVector fitMomentum2( fitMomenta.second[0], fitMomenta.second[1], fitMomenta.second[2],
182  // sqrt( fitMomenta.second.normsq()+0.105658*0.105658) );
183  // histos_["deltaP2"]->Fill( recoMomentum2.P() - fitMomentum2.P() );
184  // histos_["deltaEta2"]->Fill( recoMomentum2.Eta() - fitMomentum2.Eta() );
185  // }
186  }
187 
188  iEvent.put(std::move(pairs));
189  iEvent.put(std::move(output));
190 }
191 
192 std::pair<double, double> TwoBodyDecayMomConstraintProducer::momentaAtVertex(const TwoBodyDecay& tbd) const {
193  // construct global trajectory parameters at the starting point
195  std::pair<AlgebraicVector, AlgebraicVector> secondaryMomenta = tbdDecayModel.cartesianSecondaryMomenta(tbd);
196 
197  return std::make_pair(secondaryMomenta.first.norm(), secondaryMomenta.second.norm());
198 }
199 
201  const TwoBodyDecay& tbd, const std::vector<reco::TransientTrack>& ttracks, const MagneticField* magField) const {
202  std::pair<double, double> result = std::make_pair(-1., -1.);
203 
205  std::pair<bool, TrajectoryStateOnSurface> oldInnermostState1 = innermostState(ttracks[0]);
206  std::pair<bool, TrajectoryStateOnSurface> oldInnermostState2 = innermostState(ttracks[1]);
207  if (!oldInnermostState1.second.isValid() || !oldInnermostState2.second.isValid())
208  return result;
209 
211  TwoBodyDecayTrajectoryState::TsosContainer trackTsos(oldInnermostState1.second, oldInnermostState2.second);
212  TwoBodyDecayTrajectoryState tbdTrajState(trackTsos, tbd, secondaryMass_, magField, true);
213  if (!tbdTrajState.isValid())
214  return result;
215 
217  bool match1 = match(tbdTrajState.trajectoryStates(true).first, oldInnermostState1.second);
218  bool match2 = match(tbdTrajState.trajectoryStates(true).second, oldInnermostState2.second);
219  if (!match1 || !match2)
220  return result;
221 
222  result = std::make_pair(fabs(1. / tbdTrajState.trajectoryStates(true).first.localParameters().qbp()),
223  fabs(1. / tbdTrajState.trajectoryStates(true).second.localParameters().qbp()));
224  return result;
225 }
226 
227 std::pair<bool, TrajectoryStateOnSurface> TwoBodyDecayMomConstraintProducer::innermostState(
228  const reco::TransientTrack& ttrack) const {
229  double outerR = ttrack.outermostMeasurementState().globalPosition().perp();
230  double innerR = ttrack.innermostMeasurementState().globalPosition().perp();
231  bool insideOut = (outerR > innerR);
232  return std::make_pair(insideOut, insideOut ? ttrack.innermostMeasurementState() : ttrack.outermostMeasurementState());
233 }
234 
236  const TrajectoryStateOnSurface& oldTsos) const {
237  LocalPoint lp1 = newTsos.localPosition();
238  LocalPoint lp2 = oldTsos.localPosition();
239 
240  double deltaX = lp1.x() - lp2.x();
241  double deltaY = lp1.y() - lp2.y();
242 
243  return ((fabs(deltaX) < sigmaPositionCutValue_) && (fabs(deltaY) < sigmaPositionCutValue_));
244 }
245 
248  if (strMomentumForRefitting == "atVertex") {
249  return atVertex;
250  } else if (strMomentumForRefitting == "atInnermostSurface") {
251  return atInnermostSurface;
252  } else {
253  throw cms::Exception("TwoBodyDecayMomConstraintProducer") << "value of config variable 'momentumForRefitting': "
254  << "has to be 'atVertex' or 'atInnermostSurface'";
255  }
256 }
257 
258 //define this as a plug-in
edm::RefProd
Definition: EDProductfwd.h:25
edm::StreamID
Definition: StreamID.h:30
TwoBodyDecayTrajectoryState::TsosContainer
std::pair< TrajectoryStateOnSurface, TrajectoryStateOnSurface > TsosContainer
Definition: TwoBodyDecayTrajectoryState.h:14
pfDisplacedTrackerVertex_cfi.trackColl
trackColl
Definition: pfDisplacedTrackerVertex_cfi.py:6
TwoBodyDecayModel::cartesianSecondaryMomenta
const std::pair< AlgebraicVector, AlgebraicVector > cartesianSecondaryMomenta(const AlgebraicVector &param)
Definition: TwoBodyDecayModel.cc:80
TwoBodyDecayFitter::estimate
virtual const TwoBodyDecay estimate(const std::vector< reco::TransientTrack > &tracks, const TwoBodyDecayVirtualMeasurement &vm) const
Definition: TwoBodyDecayFitter.cc:16
pwdgSkimBPark_cfi.beamSpot
beamSpot
Definition: pwdgSkimBPark_cfi.py:5
TwoBodyDecay::isValid
bool isValid(void) const
Definition: TwoBodyDecay.h:46
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:72
TwoBodyDecayParameters::mass
Definition: TwoBodyDecayParameters.h:17
edm::EDGetTokenT< reco::TrackCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
TwoBodyDecayMomConstraintProducer::primaryMass_
const double primaryMass_
Definition: TwoBodyDecayMomConstraintProducer.cc:62
TrajectoryStateOnSurface::globalPosition
GlobalPoint globalPosition() const
Definition: TrajectoryStateOnSurface.h:65
TwoBodyDecayTrajectoryState::isValid
bool isValid(void) const
Definition: TwoBodyDecayTrajectoryState.h:28
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
TwoBodyDecayMomConstraintProducer::magFieldToken_
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magFieldToken_
Definition: TwoBodyDecayMomConstraintProducer.cc:78
TwoBodyDecayMomConstraintProducer::innermostState
std::pair< bool, TrajectoryStateOnSurface > innermostState(const reco::TransientTrack &ttrack) const
Definition: TwoBodyDecayMomConstraintProducer.cc:227
TwoBodyDecayMomConstraintProducer::bsToken_
edm::EDGetTokenT< reco::BeamSpot > bsToken_
Definition: TwoBodyDecayMomConstraintProducer.cc:76
TwoBodyDecayMomConstraintProducer::~TwoBodyDecayMomConstraintProducer
~TwoBodyDecayMomConstraintProducer() override=default
TwoBodyDecayFitter
Definition: TwoBodyDecayFitter.h:21
edm::Handle< reco::TrackCollection >
TwoBodyDecayMomConstraintProducer::bsSrcTag_
const edm::InputTag bsSrcTag_
Definition: TwoBodyDecayMomConstraintProducer.cc:58
TwoBodyDecayMomConstraintProducer::momentaAtInnermostSurface
std::pair< double, double > momentaAtInnermostSurface(const TwoBodyDecay &tbd, const std::vector< reco::TransientTrack > &ttracks, const MagneticField *magField) const
Definition: TwoBodyDecayMomConstraintProducer.cc:200
edm::Ref< TrackCollection >
TwoBodyDecayMomConstraintProducer::primaryWidth_
const double primaryWidth_
Definition: TwoBodyDecayMomConstraintProducer.cc:63
MomentumConstraint
Definition: TrackConstraintAssociation.h:11
TwoBodyDecayMomConstraintProducer::produce
void produce(edm::StreamID streamid, edm::Event &, const edm::EventSetup &) const override
Definition: TwoBodyDecayMomConstraintProducer.cc:111
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
MakerMacros.h
Track.h
TrackFwd.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
TwoBodyDecayMomConstraintProducer::momentaAtVertex
std::pair< double, double > momentaAtVertex(const TwoBodyDecay &tbd) const
Definition: TwoBodyDecayMomConstraintProducer.cc:192
IdealMagneticFieldRecord.h
TwoBodyDecayMomConstraintProducer::trackCollToken_
edm::EDGetTokenT< reco::TrackCollection > trackCollToken_
Definition: TwoBodyDecayMomConstraintProducer.cc:75
Point3DBase< float, LocalTag >
TwoBodyDecayVirtualMeasurement.h
TwoBodyDecayMomConstraintProducer
Definition: TwoBodyDecayMomConstraintProducer.cc:40
GlobalTrackingGeometryRecord.h
TwoBodyDecayVirtualMeasurement
Definition: TwoBodyDecayVirtualMeasurement.h:19
edm::global::EDProducer
Definition: EDProducer.h:32
TwoBodyDecayMomConstraintProducer::chi2CutValue_
const double chi2CutValue_
Definition: TwoBodyDecayMomConstraintProducer.cc:67
TwoBodyDecayMomConstraintProducer::trackingGeometryToken_
const edm::ESGetToken< GlobalTrackingGeometry, GlobalTrackingGeometryRecord > trackingGeometryToken_
Definition: TwoBodyDecayMomConstraintProducer.cc:79
TrajectoryStateOnSurface::localPosition
LocalPoint localPosition() const
Definition: TrajectoryStateOnSurface.h:74
TwoBodyDecayMomConstraintProducer::atInnermostSurface
Definition: TwoBodyDecayMomConstraintProducer.cc:70
TwoBodyDecayMomConstraintProducer::momentumForRefitting_
const MomentumForRefitting momentumForRefitting_
Definition: TwoBodyDecayMomConstraintProducer.cc:71
edm::ParameterSet
Definition: ParameterSet.h:47
TwoBodyDecayModel
Definition: TwoBodyDecayModel.h:15
TwoBodyDecayTrajectoryState::trajectoryStates
const TsosContainer & trajectoryStates(bool useRefittedState=true) const
Definition: TwoBodyDecayTrajectoryState.h:32
Event.h
TwoBodyDecayMomConstraintProducer::secondaryMass_
const double secondaryMass_
Definition: TwoBodyDecayMomConstraintProducer.cc:64
TwoBodyDecayMomConstraintProducer::TwoBodyDecayMomConstraintProducer
TwoBodyDecayMomConstraintProducer(const edm::ParameterSet &)
Definition: TwoBodyDecayMomConstraintProducer.cc:84
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
iEvent
int iEvent
Definition: GenABIO.cc:224
TwoBodyDecayMomConstraintProducer::match
bool match(const TrajectoryStateOnSurface &newTsos, const TrajectoryStateOnSurface &oldTsos) const
Definition: TwoBodyDecayMomConstraintProducer.cc:235
edm::EventSetup::getHandle
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:155
TwoBodyDecayMomConstraintProducer::fixedMomentumError_
const double fixedMomentumError_
Definition: TwoBodyDecayMomConstraintProducer.cc:68
TwoBodyDecayMomConstraintProducer::tbdFitter_
const TwoBodyDecayFitter tbdFitter_
Definition: TwoBodyDecayMomConstraintProducer.cc:60
edm::EventSetup
Definition: EventSetup.h:58
reco::TransientTrack::outermostMeasurementState
TrajectoryStateOnSurface outermostMeasurementState() const
Definition: TransientTrack.h:84
TwoBodyDecayTrajectoryState
Definition: TwoBodyDecayTrajectoryState.h:12
TwoBodyDecayMomConstraintProducer::atVertex
Definition: TwoBodyDecayMomConstraintProducer.cc:70
edm::ESGetToken< MagneticField, IdealMagneticFieldRecord >
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
InputTag.h
TwoBodyDecayModel.h
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:127
TwoBodyDecayMomConstraintProducer::srcTag_
const edm::InputTag srcTag_
Definition: TwoBodyDecayMomConstraintProducer.cc:57
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
reco::TransientTrack
Definition: TransientTrack.h:19
Frameworkfwd.h
Exception
Definition: hltDiff.cc:245
TwoBodyDecay
Definition: TwoBodyDecay.h:15
TrackMomConstraintAssociationCollection
edm::AssociationMap< edm::OneToOne< reco::TrackCollection, std::vector< MomentumConstraint > > > TrackMomConstraintAssociationCollection
Definition: TrackConstraintAssociation.h:24
or
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
TwoBodyDecayTrajectoryState.h
TwoBodyDecayFitter.h
TwoBodyDecayMomConstraintProducer::momentumForRefittingFromString
static MomentumForRefitting momentumForRefittingFromString(std::string momentumForRefittingString)
Definition: TwoBodyDecayMomConstraintProducer.cc:247
insideOut
Definition: NavigationDirection.h:4
mps_fire.result
result
Definition: mps_fire.py:311
TwoBodyDecay::chi2
double chi2(void) const
Definition: TwoBodyDecay.h:44
ParameterSet.h
EDProducer.h
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
TrackConstraintAssociation.h
edm::Event
Definition: Event.h:73
MagneticField
Definition: MagneticField.h:19
TwoBodyDecayMomConstraintProducer::MomentumForRefitting
MomentumForRefitting
Definition: TwoBodyDecayMomConstraintProducer.cc:70
PV3DBase::perp
T perp() const
Definition: PV3DBase.h:69
edm::InputTag
Definition: InputTag.h:15
TwoBodyDecay.h
TwoBodyDecayMomConstraintProducer::sigmaPositionCutValue_
const double sigmaPositionCutValue_
Definition: TwoBodyDecayMomConstraintProducer.cc:66
reco::TransientTrack::innermostMeasurementState
TrajectoryStateOnSurface innermostMeasurementState() const
Definition: TransientTrack.h:86