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 
38 
40 {
41 
42 public:
43 
45  ~TwoBodyDecayConstraintProducer() override = default;
46 
47 private:
48 
49  void produce(edm::StreamID streamid, edm::Event&, const edm::EventSetup&) const override;
50 
51  std::pair<bool, TrajectoryStateOnSurface> innermostState( const reco::TransientTrack& ttrack ) const;
52  bool match( const TrajectoryStateOnSurface& newTsos, const TrajectoryStateOnSurface& oldTsos ) const;
53 
56 
58 
59  const double primaryMass_;
60  const double primaryWidth_;
61  const double secondaryMass_;
62 
63  const double sigmaPositionCutValue_;
64  const double chi2CutValue_;
65  const double errorRescaleValue_;
66 
69 
70 // // debug
71 // std::map<std::string, TH1F*> histos_;
72 };
73 
74 
76  srcTag_( iConfig.getParameter<edm::InputTag>( "src" ) ),
77  bsSrcTag_( iConfig.getParameter<edm::InputTag>( "beamSpot" ) ),
78  tbdFitter_( iConfig ),
79  primaryMass_( iConfig.getParameter<double>( "primaryMass" ) ),
80  primaryWidth_( iConfig.getParameter<double>( "primaryWidth" ) ),
81  secondaryMass_( iConfig.getParameter<double>( "secondaryMass" ) ),
82  sigmaPositionCutValue_( iConfig.getParameter<double>( "sigmaPositionCut" ) ),
83  chi2CutValue_( iConfig.getParameter<double>( "chi2Cut" ) ),
84  errorRescaleValue_( iConfig.getParameter<double>( "rescaleError" ) )
85 {
86  trackCollToken_ = consumes<reco::TrackCollection>(edm::InputTag(srcTag_));
87  bsToken_ = consumes<reco::BeamSpot>(edm::InputTag(bsSrcTag_));
88 
89  produces<std::vector<TrackParamConstraint> >();
90  produces<TrackParamConstraintAssociationCollection>();
91 
92 // //debug
93 // histos_["deltaEta1"] = new TH1F( "deltaEta1", "deltaEta1", 200, -1., 1. );
94 // histos_["deltaP1"] = new TH1F( "deltaP1", "deltaP1", 200, -50., 50. );
95 
96 // histos_["deltaEta2"] = new TH1F( "deltaEta2", "deltaEta2", 200, -1., 1. );
97 // histos_["deltaP2"] = new TH1F( "deltaP2", "deltaP2", 200, -50., 50. );
98 }
99 
100 
102 {
103  using namespace edm;
104 
106  iEvent.getByToken(trackCollToken_, trackColl);
107 
109  iEvent.getByToken(bsToken_, beamSpot);
110 
111  ESHandle<MagneticField> magField;
112  iSetup.get<IdealMagneticFieldRecord>().get( magField );
113 
114  edm::RefProd<std::vector<TrackParamConstraint> > rPairs = iEvent.getRefBeforePut<std::vector<TrackParamConstraint> >();
115  std::unique_ptr<std::vector<TrackParamConstraint> > pairs(new std::vector<TrackParamConstraint>);
116  std::unique_ptr<TrackParamConstraintAssociationCollection> output(new TrackParamConstraintAssociationCollection(trackColl, rPairs));
117 
118  if ( trackColl->size() == 2 )
119  {
122 
124  std::vector<reco::TransientTrack> ttracks(2);
125  ttracks[0] = reco::TransientTrack( reco::TrackRef( trackColl, 0 ), magField.product() );
126  ttracks[0].setES( iSetup );
127  ttracks[1] = reco::TransientTrack( reco::TrackRef( trackColl, 1 ), magField.product() );
128  ttracks[1].setES( iSetup );
129 
131  TwoBodyDecay tbd = tbdFitter_.estimate( ttracks, vm );
132 
133  if ( !tbd.isValid() or ( tbd.chi2() > chi2CutValue_ ) ) return;
134 
136  std::pair<bool, TrajectoryStateOnSurface> oldInnermostState1 = innermostState( ttracks[0] );
137  std::pair<bool, TrajectoryStateOnSurface> oldInnermostState2 = innermostState( ttracks[1] );
138  if ( !oldInnermostState1.second.isValid() || !oldInnermostState2.second.isValid() ) return;
139 
141  TwoBodyDecayTrajectoryState::TsosContainer trackTsos( oldInnermostState1.second, oldInnermostState2.second );
142  TwoBodyDecayTrajectoryState tbdTrajState( trackTsos, tbd, secondaryMass_, magField.product(), true );
143  if ( !tbdTrajState.isValid() ) return;
144 
146  bool match1 = match( tbdTrajState.trajectoryStates(true).first, oldInnermostState1.second );
147  bool match2 = match( tbdTrajState.trajectoryStates(true).second, oldInnermostState2.second );
148  if ( !match1 || !match2 ) return;
149 
150  // re-scale error of constraintTsos
151  tbdTrajState.rescaleError( errorRescaleValue_ );
152 
153  // produce constraint for first track
154  pairs->push_back(tbdTrajState.trajectoryStates(true).first);
155  output->insert( reco::TrackRef(trackColl,0), edm::Ref<std::vector<TrackParamConstraint> >(rPairs,0) );
156 
157  // produce constraint for second track
158  pairs->push_back(tbdTrajState.trajectoryStates(true).second);
159  output->insert( reco::TrackRef(trackColl,1), edm::Ref<std::vector<TrackParamConstraint> >(rPairs,1) );
160 
161 // // debug
162 // if ( tbd.isValid() ) {
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 
187 std::pair<bool, TrajectoryStateOnSurface>
189 {
190  double outerR = ttrack.outermostMeasurementState().globalPosition().perp();
191  double innerR = ttrack.innermostMeasurementState().globalPosition().perp();
192  bool insideOut = ( outerR > innerR );
193  return std::make_pair( insideOut, insideOut ? ttrack.innermostMeasurementState() : ttrack.outermostMeasurementState() );
194 }
195 
196 
197 bool
199  const TrajectoryStateOnSurface& oldTsos ) const
200 {
201  LocalPoint lp1 = newTsos.localPosition();
202  LocalPoint lp2 = oldTsos.localPosition();
203 
204  double deltaX = lp1.x() - lp2.x();
205  double deltaY = lp1.y() - lp2.y();
206 
207  return ( ( fabs(deltaX) < sigmaPositionCutValue_ ) && ( fabs(deltaY) < sigmaPositionCutValue_ ) );
208 }
209 
210 
211 //define this as a plug-in
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
T perp() const
Definition: PV3DBase.h:72
~TwoBodyDecayConstraintProducer() override=default
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
void produce(edm::StreamID streamid, edm::Event &, const edm::EventSetup &) const override
T y() const
Definition: PV3DBase.h:63
GlobalPoint globalPosition() const
TrajectoryStateOnSurface innermostMeasurementState() const
virtual const TwoBodyDecay estimate(const std::vector< reco::TransientTrack > &tracks, const TwoBodyDecayVirtualMeasurement &vm) const
std::pair< bool, TrajectoryStateOnSurface > innermostState(const reco::TransientTrack &ttrack) const
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
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
TwoBodyDecayConstraintProducer(const edm::ParameterSet &)
edm::EDGetTokenT< reco::BeamSpot > bsToken_
TrajectoryStateOnSurface outermostMeasurementState() const
RefProd< PROD > getRefBeforePut()
Definition: Event.h:150
void setES(const edm::EventSetup &es)
bool isValid(void) const
Definition: TwoBodyDecay.h:46
T const * product() const
Definition: Handle.h:74
std::pair< TrajectoryStateOnSurface, TrajectoryStateOnSurface > TsosContainer
double chi2(void) const
Definition: TwoBodyDecay.h:44
edm::EDGetTokenT< reco::TrackCollection > trackCollToken_
HLT enums.
T get() const
Definition: EventSetup.h:71
T x() const
Definition: PV3DBase.h:62
T const * product() const
Definition: ESHandle.h:86
bool match(const TrajectoryStateOnSurface &newTsos, const TrajectoryStateOnSurface &oldTsos) const
def move(src, dest)
Definition: eostools.py:511
edm::AssociationMap< edm::OneToOne< reco::TrackCollection, std::vector< TrackParamConstraint > > > TrackParamConstraintAssociationCollection