CMS 3D CMS Logo

TwoBodyDecayConstraintProducer.cc
Go to the documentation of this file.
1 
10 #include <memory>
11 
18 
21 
24 
26 
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  ~TwoBodyDecayConstraintProducer() override = default;
43 
44 private:
45  void produce(edm::StreamID streamid, edm::Event&, const edm::EventSetup&) const override;
46 
47  std::pair<bool, TrajectoryStateOnSurface> innermostState(const reco::TransientTrack& ttrack) const;
48  bool match(const TrajectoryStateOnSurface& newTsos, const TrajectoryStateOnSurface& oldTsos) const;
49 
52 
54 
55  const double primaryMass_;
56  const double primaryWidth_;
57  const double secondaryMass_;
58 
59  const double sigmaPositionCutValue_;
60  const double chi2CutValue_;
61  const double errorRescaleValue_;
62 
65 
68  // // debug
69  // std::map<std::string, TH1F*> histos_;
70 };
71 
73  : srcTag_(iConfig.getParameter<edm::InputTag>("src")),
74  bsSrcTag_(iConfig.getParameter<edm::InputTag>("beamSpot")),
75  tbdFitter_(iConfig),
76  primaryMass_(iConfig.getParameter<double>("primaryMass")),
77  primaryWidth_(iConfig.getParameter<double>("primaryWidth")),
78  secondaryMass_(iConfig.getParameter<double>("secondaryMass")),
79  sigmaPositionCutValue_(iConfig.getParameter<double>("sigmaPositionCut")),
80  chi2CutValue_(iConfig.getParameter<double>("chi2Cut")),
81  errorRescaleValue_(iConfig.getParameter<double>("rescaleError")),
82  magFieldToken_(esConsumes()),
83  trackingGeometryToken_(esConsumes()) {
84  trackCollToken_ = consumes<reco::TrackCollection>(edm::InputTag(srcTag_));
85  bsToken_ = consumes<reco::BeamSpot>(edm::InputTag(bsSrcTag_));
86 
87  produces<std::vector<TrackParamConstraint> >();
88  produces<TrackParamConstraintAssociationCollection>();
89 
90  // //debug
91  // histos_["deltaEta1"] = new TH1F( "deltaEta1", "deltaEta1", 200, -1., 1. );
92  // histos_["deltaP1"] = new TH1F( "deltaP1", "deltaP1", 200, -50., 50. );
93 
94  // histos_["deltaEta2"] = new TH1F( "deltaEta2", "deltaEta2", 200, -1., 1. );
95  // histos_["deltaP2"] = new TH1F( "deltaP2", "deltaP2", 200, -50., 50. );
96 }
97 
100  const edm::EventSetup& iSetup) const {
101  using namespace edm;
102 
104  iEvent.getByToken(trackCollToken_, trackColl);
105 
107  iEvent.getByToken(bsToken_, beamSpot);
108 
109  auto const* magField = &iSetup.getData(magFieldToken_);
110 
111  auto trackingGeometry = iSetup.getHandle(trackingGeometryToken_);
112 
114  iEvent.getRefBeforePut<std::vector<TrackParamConstraint> >();
115  std::unique_ptr<std::vector<TrackParamConstraint> > pairs(new std::vector<TrackParamConstraint>);
116  std::unique_ptr<TrackParamConstraintAssociationCollection> output(
118 
119  if (trackColl->size() == 2) {
122 
124  std::vector<reco::TransientTrack> ttracks(2);
125  ttracks[0] = reco::TransientTrack(reco::TrackRef(trackColl, 0), magField);
126  ttracks[0].setTrackingGeometry(trackingGeometry);
127  ttracks[1] = reco::TransientTrack(reco::TrackRef(trackColl, 1), magField);
128  ttracks[1].setTrackingGeometry(trackingGeometry);
129 
131  TwoBodyDecay tbd = tbdFitter_.estimate(ttracks, vm);
132 
133  if (!tbd.isValid() or (tbd.chi2() > chi2CutValue_))
134  return;
135 
137  std::pair<bool, TrajectoryStateOnSurface> oldInnermostState1 = innermostState(ttracks[0]);
138  std::pair<bool, TrajectoryStateOnSurface> oldInnermostState2 = innermostState(ttracks[1]);
139  if (!oldInnermostState1.second.isValid() || !oldInnermostState2.second.isValid())
140  return;
141 
143  TwoBodyDecayTrajectoryState::TsosContainer trackTsos(oldInnermostState1.second, oldInnermostState2.second);
144  TwoBodyDecayTrajectoryState tbdTrajState(trackTsos, tbd, secondaryMass_, magField, true);
145  if (!tbdTrajState.isValid())
146  return;
147 
149  bool match1 = match(tbdTrajState.trajectoryStates(true).first, oldInnermostState1.second);
150  bool match2 = match(tbdTrajState.trajectoryStates(true).second, oldInnermostState2.second);
151  if (!match1 || !match2)
152  return;
153 
154  // re-scale error of constraintTsos
155  tbdTrajState.rescaleError(errorRescaleValue_);
156 
157  // produce constraint for first track
158  pairs->push_back(tbdTrajState.trajectoryStates(true).first);
159  output->insert(reco::TrackRef(trackColl, 0), edm::Ref<std::vector<TrackParamConstraint> >(rPairs, 0));
160 
161  // produce constraint for second track
162  pairs->push_back(tbdTrajState.trajectoryStates(true).second);
163  output->insert(reco::TrackRef(trackColl, 1), edm::Ref<std::vector<TrackParamConstraint> >(rPairs, 1));
164 
165  // // debug
166  // if ( tbd.isValid() ) {
167  // TwoBodyDecayModel model;
168  // const std::pair< AlgebraicVector, AlgebraicVector > fitMomenta = model.cartesianSecondaryMomenta( tbd );
169 
170  // TLorentzVector recoMomentum1( ttracks[0].track().px(), ttracks[0].track().py(), ttracks[0].track().pz(),
171  // sqrt((ttracks[0].track().p()*ttracks[0].track().p())+0.105658*0.105658) );
172  // TLorentzVector fitMomentum1( fitMomenta.first[0], fitMomenta.first[1], fitMomenta.first[2],
173  // sqrt( fitMomenta.first.normsq()+0.105658*0.105658) );
174  // histos_["deltaP1"]->Fill( recoMomentum1.P() - fitMomentum1.P() );
175  // histos_["deltaEta1"]->Fill( recoMomentum1.Eta() - fitMomentum1.Eta() );
176 
177  // TLorentzVector recoMomentum2( ttracks[1].track().px(), ttracks[1].track().py(), ttracks[1].track().pz(),
178  // sqrt((ttracks[1].track().p()*ttracks[1].track().p())+0.105658*0.105658) );
179  // TLorentzVector fitMomentum2( fitMomenta.second[0], fitMomenta.second[1], fitMomenta.second[2],
180  // sqrt( fitMomenta.second.normsq()+0.105658*0.105658) );
181  // histos_["deltaP2"]->Fill( recoMomentum2.P() - fitMomentum2.P() );
182  // histos_["deltaEta2"]->Fill( recoMomentum2.Eta() - fitMomentum2.Eta() );
183  // }
184  }
185 
186  iEvent.put(std::move(pairs));
187  iEvent.put(std::move(output));
188 }
189 
190 std::pair<bool, TrajectoryStateOnSurface> TwoBodyDecayConstraintProducer::innermostState(
191  const reco::TransientTrack& ttrack) const {
192  double outerR = ttrack.outermostMeasurementState().globalPosition().perp();
193  double innerR = ttrack.innermostMeasurementState().globalPosition().perp();
194  bool insideOut = (outerR > innerR);
195  return std::make_pair(insideOut, insideOut ? ttrack.innermostMeasurementState() : ttrack.outermostMeasurementState());
196 }
197 
199  const TrajectoryStateOnSurface& oldTsos) const {
200  LocalPoint lp1 = newTsos.localPosition();
201  LocalPoint lp2 = oldTsos.localPosition();
202 
203  double deltaX = lp1.x() - lp2.x();
204  double deltaY = lp1.y() - lp2.y();
205 
206  return ((fabs(deltaX) < sigmaPositionCutValue_) && (fabs(deltaY) < sigmaPositionCutValue_));
207 }
208 
209 //define this as a plug-in
edm::RefProd
Definition: EDProductfwd.h:25
edm::StreamID
Definition: StreamID.h:30
TwoBodyDecayConstraintProducer::errorRescaleValue_
const double errorRescaleValue_
Definition: TwoBodyDecayConstraintProducer.cc:61
TwoBodyDecayConstraintProducer::primaryWidth_
const double primaryWidth_
Definition: TwoBodyDecayConstraintProducer.cc:56
TwoBodyDecayTrajectoryState::TsosContainer
std::pair< TrajectoryStateOnSurface, TrajectoryStateOnSurface > TsosContainer
Definition: TwoBodyDecayTrajectoryState.h:14
TwoBodyDecayConstraintProducer::match
bool match(const TrajectoryStateOnSurface &newTsos, const TrajectoryStateOnSurface &oldTsos) const
Definition: TwoBodyDecayConstraintProducer.cc:198
TwoBodyDecayConstraintProducer::innermostState
std::pair< bool, TrajectoryStateOnSurface > innermostState(const reco::TransientTrack &ttrack) const
Definition: TwoBodyDecayConstraintProducer.cc:190
pfDisplacedTrackerVertex_cfi.trackColl
trackColl
Definition: pfDisplacedTrackerVertex_cfi.py:6
TwoBodyDecayFitter::estimate
virtual const TwoBodyDecay estimate(const std::vector< reco::TransientTrack > &tracks, const TwoBodyDecayVirtualMeasurement &vm) const
Definition: TwoBodyDecayFitter.cc:16
TwoBodyDecayTrajectoryState::rescaleError
void rescaleError(double scale)
Definition: TwoBodyDecayTrajectoryState.cc:35
pwdgSkimBPark_cfi.beamSpot
beamSpot
Definition: pwdgSkimBPark_cfi.py:5
TwoBodyDecay::isValid
bool isValid(void) const
Definition: TwoBodyDecay.h:46
TwoBodyDecayConstraintProducer::TwoBodyDecayConstraintProducer
TwoBodyDecayConstraintProducer(const edm::ParameterSet &)
Definition: TwoBodyDecayConstraintProducer.cc:72
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:72
edm::EDGetTokenT< reco::TrackCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
TwoBodyDecayConstraintProducer::trackCollToken_
edm::EDGetTokenT< reco::TrackCollection > trackCollToken_
Definition: TwoBodyDecayConstraintProducer.cc:63
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
TwoBodyDecayFitter
Definition: TwoBodyDecayFitter.h:21
TwoBodyDecayConstraintProducer::sigmaPositionCutValue_
const double sigmaPositionCutValue_
Definition: TwoBodyDecayConstraintProducer.cc:59
TwoBodyDecayConstraintProducer::~TwoBodyDecayConstraintProducer
~TwoBodyDecayConstraintProducer() override=default
TwoBodyDecayConstraintProducer::bsSrcTag_
const edm::InputTag bsSrcTag_
Definition: TwoBodyDecayConstraintProducer.cc:51
edm::Handle< reco::TrackCollection >
edm::Ref< TrackCollection >
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
MakerMacros.h
Track.h
TrackFwd.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
TwoBodyDecayConstraintProducer::magFieldToken_
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magFieldToken_
Definition: TwoBodyDecayConstraintProducer.cc:66
TwoBodyDecayConstraintProducer::produce
void produce(edm::StreamID streamid, edm::Event &, const edm::EventSetup &) const override
Definition: TwoBodyDecayConstraintProducer.cc:98
IdealMagneticFieldRecord.h
TwoBodyDecayConstraintProducer::bsToken_
edm::EDGetTokenT< reco::BeamSpot > bsToken_
Definition: TwoBodyDecayConstraintProducer.cc:64
Point3DBase< float, LocalTag >
TwoBodyDecayVirtualMeasurement.h
GlobalTrackingGeometryRecord.h
TwoBodyDecayVirtualMeasurement
Definition: TwoBodyDecayVirtualMeasurement.h:19
edm::global::EDProducer
Definition: EDProducer.h:32
TwoBodyDecayConstraintProducer
Definition: TwoBodyDecayConstraintProducer.cc:39
TrajectoryStateOnSurface::localPosition
LocalPoint localPosition() const
Definition: TrajectoryStateOnSurface.h:74
edm::ParameterSet
Definition: ParameterSet.h:47
TwoBodyDecayTrajectoryState::trajectoryStates
const TsosContainer & trajectoryStates(bool useRefittedState=true) const
Definition: TwoBodyDecayTrajectoryState.h:32
Event.h
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::EventSetup::getHandle
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:155
edm::EventSetup
Definition: EventSetup.h:58
reco::TransientTrack::outermostMeasurementState
TrajectoryStateOnSurface outermostMeasurementState() const
Definition: TransientTrack.h:84
TwoBodyDecayTrajectoryState
Definition: TwoBodyDecayTrajectoryState.h:12
edm::ESGetToken< MagneticField, IdealMagneticFieldRecord >
InputTag.h
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:127
TrackParamConstraintAssociationCollection
edm::AssociationMap< edm::OneToOne< reco::TrackCollection, std::vector< TrackParamConstraint > > > TrackParamConstraintAssociationCollection
Definition: TrackConstraintAssociation.h:38
eostools.move
def move(src, dest)
Definition: eostools.py:511
TwoBodyDecayConstraintProducer::secondaryMass_
const double secondaryMass_
Definition: TwoBodyDecayConstraintProducer.cc:57
reco::TransientTrack
Definition: TransientTrack.h:19
Frameworkfwd.h
TwoBodyDecayConstraintProducer::primaryMass_
const double primaryMass_
Definition: TwoBodyDecayConstraintProducer.cc:55
TwoBodyDecay
Definition: TwoBodyDecay.h:15
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
insideOut
Definition: NavigationDirection.h:4
TwoBodyDecay::chi2
double chi2(void) const
Definition: TwoBodyDecay.h:44
ParameterSet.h
EDProducer.h
TwoBodyDecayConstraintProducer::chi2CutValue_
const double chi2CutValue_
Definition: TwoBodyDecayConstraintProducer.cc:60
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
TrackConstraintAssociation.h
edm::Event
Definition: Event.h:73
TwoBodyDecayConstraintProducer::tbdFitter_
const TwoBodyDecayFitter tbdFitter_
Definition: TwoBodyDecayConstraintProducer.cc:53
TwoBodyDecayConstraintProducer::srcTag_
const edm::InputTag srcTag_
Definition: TwoBodyDecayConstraintProducer.cc:50
PV3DBase::perp
T perp() const
Definition: PV3DBase.h:69
edm::InputTag
Definition: InputTag.h:15
TwoBodyDecay.h
TwoBodyDecayConstraintProducer::trackingGeometryToken_
const edm::ESGetToken< GlobalTrackingGeometry, GlobalTrackingGeometryRecord > trackingGeometryToken_
Definition: TwoBodyDecayConstraintProducer.cc:67
reco::TransientTrack::innermostMeasurementState
TrajectoryStateOnSurface innermostMeasurementState() const
Definition: TransientTrack.h:86