CMS 3D CMS Logo

TwoBodyDecayMomConstraintProducer.cc
Go to the documentation of this file.
1 
10 #include <memory>
11 
18 
20 
23 
25 
31 
32 // // debug
33 // #include <map>
34 // #include "TH1F.h"
35 // #include "TFile.h"
36 // #include "TLorentzVector.h"
37 // #include "Alignment/TwoBodyDecay/interface/TwoBodyDecayModel.h"
38 
40 public:
42  ~TwoBodyDecayMomConstraintProducer() override = default;
43 
44 private:
45  void produce(edm::StreamID streamid, edm::Event&, const edm::EventSetup&) const override;
46 
47  std::pair<double, double> momentaAtVertex(const TwoBodyDecay& tbd) const;
48 
49  std::pair<double, double> momentaAtInnermostSurface(const TwoBodyDecay& tbd,
50  const std::vector<reco::TransientTrack>& ttracks,
51  const MagneticField* magField) const;
52 
53  std::pair<bool, TrajectoryStateOnSurface> innermostState(const reco::TransientTrack& ttrack) const;
54  bool match(const TrajectoryStateOnSurface& newTsos, const TrajectoryStateOnSurface& oldTsos) const;
55 
58 
60 
61  const double primaryMass_;
62  const double primaryWidth_;
63  const double secondaryMass_;
64 
65  const double sigmaPositionCutValue_;
66  const double chi2CutValue_;
67  const double fixedMomentumError_;
68 
71 
72  static MomentumForRefitting momentumForRefittingFromString(std::string momentumForRefittingString);
73 
76 
77  // // debug
78  // std::map<std::string, TH1F*> histos_;
79 };
80 
82  : srcTag_(iConfig.getParameter<edm::InputTag>("src")),
83  bsSrcTag_(iConfig.getParameter<edm::InputTag>("beamSpot")),
84  tbdFitter_(iConfig),
85  primaryMass_(iConfig.getParameter<double>("primaryMass")),
86  primaryWidth_(iConfig.getParameter<double>("primaryWidth")),
87  secondaryMass_(iConfig.getParameter<double>("secondaryMass")),
88  sigmaPositionCutValue_(iConfig.getParameter<double>("sigmaPositionCut")),
89  chi2CutValue_(iConfig.getParameter<double>("chi2Cut")),
90  fixedMomentumError_(iConfig.getParameter<double>("fixedMomentumError")),
91  momentumForRefitting_(momentumForRefittingFromString(iConfig.getParameter<std::string>("momentumForRefitting"))) {
92  trackCollToken_ = consumes<reco::TrackCollection>(edm::InputTag(srcTag_));
93  bsToken_ = consumes<reco::BeamSpot>(edm::InputTag(bsSrcTag_));
94 
95  produces<std::vector<MomentumConstraint> >();
96  produces<TrackMomConstraintAssociationCollection>();
97 
98  // //debug
99  // histos_["deltaEta1"] = new TH1F( "deltaEta1", "deltaEta1", 200, -1., 1. );
100  // histos_["deltaP1"] = new TH1F( "deltaP1", "deltaP1", 200, -50., 50. );
101 
102  // histos_["deltaEta2"] = new TH1F( "deltaEta2", "deltaEta2", 200, -1., 1. );
103  // histos_["deltaP2"] = new TH1F( "deltaP2", "deltaP2", 200, -50., 50. );
104 }
105 
108  const edm::EventSetup& iSetup) const {
109  using namespace edm;
110 
112  iEvent.getByToken(trackCollToken_, trackColl);
113 
115  iEvent.getByToken(bsToken_, beamSpot);
116 
117  ESHandle<MagneticField> magField;
118  iSetup.get<IdealMagneticFieldRecord>().get(magField);
119 
120  edm::RefProd<std::vector<MomentumConstraint> > rPairs = iEvent.getRefBeforePut<std::vector<MomentumConstraint> >();
121  std::unique_ptr<std::vector<MomentumConstraint> > pairs(new std::vector<MomentumConstraint>);
122  std::unique_ptr<TrackMomConstraintAssociationCollection> output(
124 
125  if (trackColl->size() == 2) {
128 
130  std::vector<reco::TransientTrack> ttracks(2);
131  ttracks[0] = reco::TransientTrack(reco::TrackRef(trackColl, 0), magField.product());
132  ttracks[0].setES(iSetup);
133  ttracks[1] = reco::TransientTrack(reco::TrackRef(trackColl, 1), magField.product());
134  ttracks[1].setES(iSetup);
135 
137  TwoBodyDecay tbd = tbdFitter_.estimate(ttracks, vm);
138 
139  if (!tbd.isValid() or (tbd.chi2() > chi2CutValue_))
140  return;
141 
142  std::pair<double, double> fitMomenta;
144  fitMomenta = momentaAtVertex(tbd);
146  fitMomenta = momentaAtInnermostSurface(tbd, ttracks, magField.product());
147  } // no other possibility!!!
148 
149  if ((fitMomenta.first > 0.) and (fitMomenta.second > 0.)) {
150  // produce constraint for first track
151  MomentumConstraint constraint1(fitMomenta.first, fixedMomentumError_);
152  pairs->push_back(constraint1);
153  output->insert(reco::TrackRef(trackColl, 0), edm::Ref<std::vector<MomentumConstraint> >(rPairs, 0));
154 
155  // produce constraint for second track
156  MomentumConstraint constraint2(fitMomenta.second, fixedMomentumError_);
157  pairs->push_back(constraint2);
158  output->insert(reco::TrackRef(trackColl, 1), edm::Ref<std::vector<MomentumConstraint> >(rPairs, 1));
159  }
160 
161  // // debug
162  // if ( tbd.isValid() and ( fitMomenta.first > 0. ) and ( fitMomenta.second > 0. ) ) {
163  // TwoBodyDecayModel model;
164  // const std::pair< AlgebraicVector, AlgebraicVector > fitMomenta = model.cartesianSecondaryMomenta( tbd );
165 
166  // TLorentzVector recoMomentum1( ttracks[0].track().px(), ttracks[0].track().py(), ttracks[0].track().pz(),
167  // sqrt((ttracks[0].track().p()*ttracks[0].track().p())+0.105658*0.105658) );
168  // TLorentzVector fitMomentum1( fitMomenta.first[0], fitMomenta.first[1], fitMomenta.first[2],
169  // sqrt( fitMomenta.first.normsq()+0.105658*0.105658) );
170  // histos_["deltaP1"]->Fill( recoMomentum1.P() - fitMomentum1.P() );
171  // histos_["deltaEta1"]->Fill( recoMomentum1.Eta() - fitMomentum1.Eta() );
172 
173  // TLorentzVector recoMomentum2( ttracks[1].track().px(), ttracks[1].track().py(), ttracks[1].track().pz(),
174  // sqrt((ttracks[1].track().p()*ttracks[1].track().p())+0.105658*0.105658) );
175  // TLorentzVector fitMomentum2( fitMomenta.second[0], fitMomenta.second[1], fitMomenta.second[2],
176  // sqrt( fitMomenta.second.normsq()+0.105658*0.105658) );
177  // histos_["deltaP2"]->Fill( recoMomentum2.P() - fitMomentum2.P() );
178  // histos_["deltaEta2"]->Fill( recoMomentum2.Eta() - fitMomentum2.Eta() );
179  // }
180  }
181 
182  iEvent.put(std::move(pairs));
183  iEvent.put(std::move(output));
184 }
185 
186 std::pair<double, double> TwoBodyDecayMomConstraintProducer::momentaAtVertex(const TwoBodyDecay& tbd) const {
187  // construct global trajectory parameters at the starting point
189  std::pair<AlgebraicVector, AlgebraicVector> secondaryMomenta = tbdDecayModel.cartesianSecondaryMomenta(tbd);
190 
191  return std::make_pair(secondaryMomenta.first.norm(), secondaryMomenta.second.norm());
192 }
193 
195  const TwoBodyDecay& tbd, const std::vector<reco::TransientTrack>& ttracks, const MagneticField* magField) const {
196  std::pair<double, double> result = std::make_pair(-1., -1.);
197 
199  std::pair<bool, TrajectoryStateOnSurface> oldInnermostState1 = innermostState(ttracks[0]);
200  std::pair<bool, TrajectoryStateOnSurface> oldInnermostState2 = innermostState(ttracks[1]);
201  if (!oldInnermostState1.second.isValid() || !oldInnermostState2.second.isValid())
202  return result;
203 
205  TwoBodyDecayTrajectoryState::TsosContainer trackTsos(oldInnermostState1.second, oldInnermostState2.second);
206  TwoBodyDecayTrajectoryState tbdTrajState(trackTsos, tbd, secondaryMass_, magField, true);
207  if (!tbdTrajState.isValid())
208  return result;
209 
211  bool match1 = match(tbdTrajState.trajectoryStates(true).first, oldInnermostState1.second);
212  bool match2 = match(tbdTrajState.trajectoryStates(true).second, oldInnermostState2.second);
213  if (!match1 || !match2)
214  return result;
215 
216  result = std::make_pair(fabs(1. / tbdTrajState.trajectoryStates(true).first.localParameters().qbp()),
217  fabs(1. / tbdTrajState.trajectoryStates(true).second.localParameters().qbp()));
218  return result;
219 }
220 
221 std::pair<bool, TrajectoryStateOnSurface> TwoBodyDecayMomConstraintProducer::innermostState(
222  const reco::TransientTrack& ttrack) const {
223  double outerR = ttrack.outermostMeasurementState().globalPosition().perp();
224  double innerR = ttrack.innermostMeasurementState().globalPosition().perp();
225  bool insideOut = (outerR > innerR);
226  return std::make_pair(insideOut, insideOut ? ttrack.innermostMeasurementState() : ttrack.outermostMeasurementState());
227 }
228 
230  const TrajectoryStateOnSurface& oldTsos) const {
231  LocalPoint lp1 = newTsos.localPosition();
232  LocalPoint lp2 = oldTsos.localPosition();
233 
234  double deltaX = lp1.x() - lp2.x();
235  double deltaY = lp1.y() - lp2.y();
236 
237  return ((fabs(deltaX) < sigmaPositionCutValue_) && (fabs(deltaY) < sigmaPositionCutValue_));
238 }
239 
242  if (strMomentumForRefitting == "atVertex") {
243  return atVertex;
244  } else if (strMomentumForRefitting == "atInnermostSurface") {
245  return atInnermostSurface;
246  } else {
247  throw cms::Exception("TwoBodyDecayMomConstraintProducer") << "value of config variable 'momentumForRefitting': "
248  << "has to be 'atVertex' or 'atInnermostSurface'";
249  }
250 }
251 
252 //define this as a plug-in
edm::RefProd
Definition: EDProductfwd.h:25
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
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:61
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:89281
TwoBodyDecayMomConstraintProducer::innermostState
std::pair< bool, TrajectoryStateOnSurface > innermostState(const reco::TransientTrack &ttrack) const
Definition: TwoBodyDecayMomConstraintProducer.cc:221
TwoBodyDecayMomConstraintProducer::bsToken_
edm::EDGetTokenT< reco::BeamSpot > bsToken_
Definition: TwoBodyDecayMomConstraintProducer.cc:75
TwoBodyDecayMomConstraintProducer::~TwoBodyDecayMomConstraintProducer
~TwoBodyDecayMomConstraintProducer() override=default
TwoBodyDecayFitter
Definition: TwoBodyDecayFitter.h:21
edm::Handle< reco::TrackCollection >
TwoBodyDecayMomConstraintProducer::bsSrcTag_
const edm::InputTag bsSrcTag_
Definition: TwoBodyDecayMomConstraintProducer.cc:57
TwoBodyDecayMomConstraintProducer::momentaAtInnermostSurface
std::pair< double, double > momentaAtInnermostSurface(const TwoBodyDecay &tbd, const std::vector< reco::TransientTrack > &ttracks, const MagneticField *magField) const
Definition: TwoBodyDecayMomConstraintProducer.cc:194
edm::Ref< TrackCollection >
TwoBodyDecayMomConstraintProducer::primaryWidth_
const double primaryWidth_
Definition: TwoBodyDecayMomConstraintProducer.cc:62
MomentumConstraint
Definition: TrackConstraintAssociation.h:11
TwoBodyDecayMomConstraintProducer::produce
void produce(edm::StreamID streamid, edm::Event &, const edm::EventSetup &) const override
Definition: TwoBodyDecayMomConstraintProducer.cc:106
IdealMagneticFieldRecord
Definition: IdealMagneticFieldRecord.h:11
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
MakerMacros.h
Track.h
edm::EventSetup::get
T get() const
Definition: EventSetup.h:87
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:186
IdealMagneticFieldRecord.h
edm::ESHandle< MagneticField >
TwoBodyDecayMomConstraintProducer::trackCollToken_
edm::EDGetTokenT< reco::TrackCollection > trackCollToken_
Definition: TwoBodyDecayMomConstraintProducer.cc:74
Point3DBase< float, LocalTag >
TwoBodyDecayVirtualMeasurement.h
TwoBodyDecayMomConstraintProducer
Definition: TwoBodyDecayMomConstraintProducer.cc:39
TwoBodyDecayVirtualMeasurement
Definition: TwoBodyDecayVirtualMeasurement.h:19
edm::global::EDProducer
Definition: EDProducer.h:32
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
TwoBodyDecayMomConstraintProducer::chi2CutValue_
const double chi2CutValue_
Definition: TwoBodyDecayMomConstraintProducer.cc:66
TrajectoryStateOnSurface::localPosition
LocalPoint localPosition() const
Definition: TrajectoryStateOnSurface.h:74
TwoBodyDecayMomConstraintProducer::atInnermostSurface
Definition: TwoBodyDecayMomConstraintProducer.cc:69
TwoBodyDecayMomConstraintProducer::momentumForRefitting_
const MomentumForRefitting momentumForRefitting_
Definition: TwoBodyDecayMomConstraintProducer.cc:70
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:63
TwoBodyDecayMomConstraintProducer::TwoBodyDecayMomConstraintProducer
TwoBodyDecayMomConstraintProducer(const edm::ParameterSet &)
Definition: TwoBodyDecayMomConstraintProducer.cc:81
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:229
TwoBodyDecayMomConstraintProducer::fixedMomentumError_
const double fixedMomentumError_
Definition: TwoBodyDecayMomConstraintProducer.cc:67
TwoBodyDecayMomConstraintProducer::tbdFitter_
const TwoBodyDecayFitter tbdFitter_
Definition: TwoBodyDecayMomConstraintProducer.cc:59
edm::EventSetup
Definition: EventSetup.h:58
reco::TransientTrack::outermostMeasurementState
TrajectoryStateOnSurface outermostMeasurementState() const
Definition: TransientTrack.h:86
TwoBodyDecayTrajectoryState
Definition: TwoBodyDecayTrajectoryState.h:12
get
#define get
TwoBodyDecayMomConstraintProducer::atVertex
Definition: TwoBodyDecayMomConstraintProducer.cc:69
InputTag.h
TwoBodyDecayModel.h
reco::TransientTrack::setES
void setES(const edm::EventSetup &es)
Definition: TransientTrack.h:78
TwoBodyDecayMomConstraintProducer::srcTag_
const edm::InputTag srcTag_
Definition: TwoBodyDecayMomConstraintProducer.cc:56
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:241
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
TrackConstraintAssociation.h
edm::Event
Definition: Event.h:73
MagneticField
Definition: MagneticField.h:19
TwoBodyDecayMomConstraintProducer::MomentumForRefitting
MomentumForRefitting
Definition: TwoBodyDecayMomConstraintProducer.cc:69
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:65
reco::TransientTrack::innermostMeasurementState
TrajectoryStateOnSurface innermostMeasurementState() const
Definition: TransientTrack.h:88