CMS 3D CMS Logo

TwoBodyDecayConstraintProducer.cc
Go to the documentation of this file.
1 
10 #include <memory>
11 
18 
20 
23 
25 
30 
31 // // debug
32 // #include <map>
33 // #include "TH1F.h"
34 // #include "TFile.h"
35 // #include "TLorentzVector.h"
36 // #include "Alignment/TwoBodyDecay/interface/TwoBodyDecayModel.h"
37 
39 public:
41  ~TwoBodyDecayConstraintProducer() override = default;
42 
43 private:
44  void produce(edm::StreamID streamid, edm::Event&, const edm::EventSetup&) const override;
45 
46  std::pair<bool, TrajectoryStateOnSurface> innermostState(const reco::TransientTrack& ttrack) const;
47  bool match(const TrajectoryStateOnSurface& newTsos, const TrajectoryStateOnSurface& oldTsos) const;
48 
51 
53 
54  const double primaryMass_;
55  const double primaryWidth_;
56  const double secondaryMass_;
57 
58  const double sigmaPositionCutValue_;
59  const double chi2CutValue_;
60  const double errorRescaleValue_;
61 
64 
65  // // debug
66  // std::map<std::string, TH1F*> histos_;
67 };
68 
70  : srcTag_(iConfig.getParameter<edm::InputTag>("src")),
71  bsSrcTag_(iConfig.getParameter<edm::InputTag>("beamSpot")),
72  tbdFitter_(iConfig),
73  primaryMass_(iConfig.getParameter<double>("primaryMass")),
74  primaryWidth_(iConfig.getParameter<double>("primaryWidth")),
75  secondaryMass_(iConfig.getParameter<double>("secondaryMass")),
76  sigmaPositionCutValue_(iConfig.getParameter<double>("sigmaPositionCut")),
77  chi2CutValue_(iConfig.getParameter<double>("chi2Cut")),
78  errorRescaleValue_(iConfig.getParameter<double>("rescaleError")) {
79  trackCollToken_ = consumes<reco::TrackCollection>(edm::InputTag(srcTag_));
80  bsToken_ = consumes<reco::BeamSpot>(edm::InputTag(bsSrcTag_));
81 
82  produces<std::vector<TrackParamConstraint> >();
83  produces<TrackParamConstraintAssociationCollection>();
84 
85  // //debug
86  // histos_["deltaEta1"] = new TH1F( "deltaEta1", "deltaEta1", 200, -1., 1. );
87  // histos_["deltaP1"] = new TH1F( "deltaP1", "deltaP1", 200, -50., 50. );
88 
89  // histos_["deltaEta2"] = new TH1F( "deltaEta2", "deltaEta2", 200, -1., 1. );
90  // histos_["deltaP2"] = new TH1F( "deltaP2", "deltaP2", 200, -50., 50. );
91 }
92 
95  const edm::EventSetup& iSetup) const {
96  using namespace edm;
97 
99  iEvent.getByToken(trackCollToken_, trackColl);
100 
102  iEvent.getByToken(bsToken_, beamSpot);
103 
104  ESHandle<MagneticField> magField;
105  iSetup.get<IdealMagneticFieldRecord>().get(magField);
106 
108  iEvent.getRefBeforePut<std::vector<TrackParamConstraint> >();
109  std::unique_ptr<std::vector<TrackParamConstraint> > pairs(new std::vector<TrackParamConstraint>);
110  std::unique_ptr<TrackParamConstraintAssociationCollection> output(
112 
113  if (trackColl->size() == 2) {
116 
118  std::vector<reco::TransientTrack> ttracks(2);
119  ttracks[0] = reco::TransientTrack(reco::TrackRef(trackColl, 0), magField.product());
120  ttracks[0].setES(iSetup);
121  ttracks[1] = reco::TransientTrack(reco::TrackRef(trackColl, 1), magField.product());
122  ttracks[1].setES(iSetup);
123 
125  TwoBodyDecay tbd = tbdFitter_.estimate(ttracks, vm);
126 
127  if (!tbd.isValid() or (tbd.chi2() > chi2CutValue_))
128  return;
129 
131  std::pair<bool, TrajectoryStateOnSurface> oldInnermostState1 = innermostState(ttracks[0]);
132  std::pair<bool, TrajectoryStateOnSurface> oldInnermostState2 = innermostState(ttracks[1]);
133  if (!oldInnermostState1.second.isValid() || !oldInnermostState2.second.isValid())
134  return;
135 
137  TwoBodyDecayTrajectoryState::TsosContainer trackTsos(oldInnermostState1.second, oldInnermostState2.second);
138  TwoBodyDecayTrajectoryState tbdTrajState(trackTsos, tbd, secondaryMass_, magField.product(), true);
139  if (!tbdTrajState.isValid())
140  return;
141 
143  bool match1 = match(tbdTrajState.trajectoryStates(true).first, oldInnermostState1.second);
144  bool match2 = match(tbdTrajState.trajectoryStates(true).second, oldInnermostState2.second);
145  if (!match1 || !match2)
146  return;
147 
148  // re-scale error of constraintTsos
149  tbdTrajState.rescaleError(errorRescaleValue_);
150 
151  // produce constraint for first track
152  pairs->push_back(tbdTrajState.trajectoryStates(true).first);
153  output->insert(reco::TrackRef(trackColl, 0), edm::Ref<std::vector<TrackParamConstraint> >(rPairs, 0));
154 
155  // produce constraint for second track
156  pairs->push_back(tbdTrajState.trajectoryStates(true).second);
157  output->insert(reco::TrackRef(trackColl, 1), edm::Ref<std::vector<TrackParamConstraint> >(rPairs, 1));
158 
159  // // debug
160  // if ( tbd.isValid() ) {
161  // TwoBodyDecayModel model;
162  // const std::pair< AlgebraicVector, AlgebraicVector > fitMomenta = model.cartesianSecondaryMomenta( tbd );
163 
164  // TLorentzVector recoMomentum1( ttracks[0].track().px(), ttracks[0].track().py(), ttracks[0].track().pz(),
165  // sqrt((ttracks[0].track().p()*ttracks[0].track().p())+0.105658*0.105658) );
166  // TLorentzVector fitMomentum1( fitMomenta.first[0], fitMomenta.first[1], fitMomenta.first[2],
167  // sqrt( fitMomenta.first.normsq()+0.105658*0.105658) );
168  // histos_["deltaP1"]->Fill( recoMomentum1.P() - fitMomentum1.P() );
169  // histos_["deltaEta1"]->Fill( recoMomentum1.Eta() - fitMomentum1.Eta() );
170 
171  // TLorentzVector recoMomentum2( ttracks[1].track().px(), ttracks[1].track().py(), ttracks[1].track().pz(),
172  // sqrt((ttracks[1].track().p()*ttracks[1].track().p())+0.105658*0.105658) );
173  // TLorentzVector fitMomentum2( fitMomenta.second[0], fitMomenta.second[1], fitMomenta.second[2],
174  // sqrt( fitMomenta.second.normsq()+0.105658*0.105658) );
175  // histos_["deltaP2"]->Fill( recoMomentum2.P() - fitMomentum2.P() );
176  // histos_["deltaEta2"]->Fill( recoMomentum2.Eta() - fitMomentum2.Eta() );
177  // }
178  }
179 
180  iEvent.put(std::move(pairs));
181  iEvent.put(std::move(output));
182 }
183 
184 std::pair<bool, TrajectoryStateOnSurface> TwoBodyDecayConstraintProducer::innermostState(
185  const reco::TransientTrack& ttrack) const {
186  double outerR = ttrack.outermostMeasurementState().globalPosition().perp();
187  double innerR = ttrack.innermostMeasurementState().globalPosition().perp();
188  bool insideOut = (outerR > innerR);
189  return std::make_pair(insideOut, insideOut ? ttrack.innermostMeasurementState() : ttrack.outermostMeasurementState());
190 }
191 
193  const TrajectoryStateOnSurface& oldTsos) const {
194  LocalPoint lp1 = newTsos.localPosition();
195  LocalPoint lp2 = oldTsos.localPosition();
196 
197  double deltaX = lp1.x() - lp2.x();
198  double deltaY = lp1.y() - lp2.y();
199 
200  return ((fabs(deltaX) < sigmaPositionCutValue_) && (fabs(deltaY) < sigmaPositionCutValue_));
201 }
202 
203 //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
TwoBodyDecayConstraintProducer::errorRescaleValue_
const double errorRescaleValue_
Definition: TwoBodyDecayConstraintProducer.cc:60
TwoBodyDecayConstraintProducer::primaryWidth_
const double primaryWidth_
Definition: TwoBodyDecayConstraintProducer.cc:55
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:192
TwoBodyDecayConstraintProducer::innermostState
std::pair< bool, TrajectoryStateOnSurface > innermostState(const reco::TransientTrack &ttrack) const
Definition: TwoBodyDecayConstraintProducer.cc:184
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
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:69
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:62
TrajectoryStateOnSurface::globalPosition
GlobalPoint globalPosition() const
Definition: TrajectoryStateOnSurface.h:65
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89285
TwoBodyDecayFitter
Definition: TwoBodyDecayFitter.h:21
TwoBodyDecayConstraintProducer::sigmaPositionCutValue_
const double sigmaPositionCutValue_
Definition: TwoBodyDecayConstraintProducer.cc:58
TwoBodyDecayConstraintProducer::~TwoBodyDecayConstraintProducer
~TwoBodyDecayConstraintProducer() override=default
TwoBodyDecayConstraintProducer::bsSrcTag_
const edm::InputTag bsSrcTag_
Definition: TwoBodyDecayConstraintProducer.cc:50
edm::Handle< reco::TrackCollection >
edm::Ref< TrackCollection >
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
TwoBodyDecayConstraintProducer::produce
void produce(edm::StreamID streamid, edm::Event &, const edm::EventSetup &) const override
Definition: TwoBodyDecayConstraintProducer.cc:93
IdealMagneticFieldRecord.h
edm::ESHandle< MagneticField >
TwoBodyDecayConstraintProducer::bsToken_
edm::EDGetTokenT< reco::BeamSpot > bsToken_
Definition: TwoBodyDecayConstraintProducer.cc:63
Point3DBase< float, LocalTag >
TwoBodyDecayVirtualMeasurement.h
TwoBodyDecayVirtualMeasurement
Definition: TwoBodyDecayVirtualMeasurement.h:19
edm::global::EDProducer
Definition: EDProducer.h:32
TwoBodyDecayConstraintProducer
Definition: TwoBodyDecayConstraintProducer.cc:38
TrajectoryStateOnSurface::localPosition
LocalPoint localPosition() const
Definition: TrajectoryStateOnSurface.h:74
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::EventSetup
Definition: EventSetup.h:58
reco::TransientTrack::outermostMeasurementState
TrajectoryStateOnSurface outermostMeasurementState() const
Definition: TransientTrack.h:86
TwoBodyDecayTrajectoryState
Definition: TwoBodyDecayTrajectoryState.h:12
get
#define get
InputTag.h
reco::TransientTrack::setES
void setES(const edm::EventSetup &es)
Definition: TransientTrack.h:78
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:56
reco::TransientTrack
Definition: TransientTrack.h:19
Frameworkfwd.h
TwoBodyDecayConstraintProducer::primaryMass_
const double primaryMass_
Definition: TwoBodyDecayConstraintProducer.cc:54
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:59
TrackConstraintAssociation.h
edm::Event
Definition: Event.h:73
TwoBodyDecayConstraintProducer::tbdFitter_
const TwoBodyDecayFitter tbdFitter_
Definition: TwoBodyDecayConstraintProducer.cc:52
TwoBodyDecayConstraintProducer::srcTag_
const edm::InputTag srcTag_
Definition: TwoBodyDecayConstraintProducer.cc:49
PV3DBase::perp
T perp() const
Definition: PV3DBase.h:69
edm::InputTag
Definition: InputTag.h:15
TwoBodyDecay.h
reco::TransientTrack::innermostMeasurementState
TrajectoryStateOnSurface innermostMeasurementState() const
Definition: TransientTrack.h:88