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 
39 
41 {
42 
43 public:
44 
46  ~TwoBodyDecayMomConstraintProducer() override = default;
47 
48 private:
49 
50  void produce(edm::StreamID streamid, edm::Event&, const edm::EventSetup&) const override;
51 
52  std::pair<double, double> momentaAtVertex( const TwoBodyDecay& tbd ) const;
53 
54  std::pair<double, double> momentaAtInnermostSurface( const TwoBodyDecay& tbd,
55  const std::vector<reco::TransientTrack>& ttracks,
56  const MagneticField* magField ) const;
57 
58  std::pair<bool, TrajectoryStateOnSurface> innermostState( const reco::TransientTrack& ttrack ) const;
59  bool match( const TrajectoryStateOnSurface& newTsos, const TrajectoryStateOnSurface& oldTsos ) const;
60 
63 
65 
66  const double primaryMass_;
67  const double primaryWidth_;
68  const double secondaryMass_;
69 
70  const double sigmaPositionCutValue_;
71  const double chi2CutValue_;
72  const double fixedMomentumError_;
73 
76 
77  static MomentumForRefitting momentumForRefittingFromString(std::string momentumForRefittingString);
78 
81 
82 // // debug
83 // std::map<std::string, TH1F*> histos_;
84 };
85 
86 
88  srcTag_( iConfig.getParameter<edm::InputTag>( "src" ) ),
89  bsSrcTag_( iConfig.getParameter<edm::InputTag>( "beamSpot" ) ),
90  tbdFitter_( iConfig ),
91  primaryMass_( iConfig.getParameter<double>( "primaryMass" ) ),
92  primaryWidth_( iConfig.getParameter<double>( "primaryWidth" ) ),
93  secondaryMass_( iConfig.getParameter<double>( "secondaryMass" ) ),
94  sigmaPositionCutValue_( iConfig.getParameter<double>( "sigmaPositionCut" ) ),
95  chi2CutValue_( iConfig.getParameter<double>( "chi2Cut" ) ),
96  fixedMomentumError_( iConfig.getParameter<double>( "fixedMomentumError" ) ),
97  momentumForRefitting_( momentumForRefittingFromString( iConfig.getParameter<std::string>( "momentumForRefitting" ) ) )
98 {
99  trackCollToken_ = consumes<reco::TrackCollection>(edm::InputTag(srcTag_));
100  bsToken_ = consumes<reco::BeamSpot>(edm::InputTag(bsSrcTag_));
101 
102  produces< std::vector<MomentumConstraint> >();
103  produces<TrackMomConstraintAssociationCollection>();
104 
105 // //debug
106 // histos_["deltaEta1"] = new TH1F( "deltaEta1", "deltaEta1", 200, -1., 1. );
107 // histos_["deltaP1"] = new TH1F( "deltaP1", "deltaP1", 200, -50., 50. );
108 
109 // histos_["deltaEta2"] = new TH1F( "deltaEta2", "deltaEta2", 200, -1., 1. );
110 // histos_["deltaP2"] = new TH1F( "deltaP2", "deltaP2", 200, -50., 50. );
111 }
112 
113 
114 
115 
117 {
118  using namespace edm;
119 
121  iEvent.getByToken(trackCollToken_, trackColl);
122 
124  iEvent.getByToken(bsToken_, beamSpot);
125 
126  ESHandle<MagneticField> magField;
127  iSetup.get<IdealMagneticFieldRecord>().get( magField );
128 
129  edm::RefProd<std::vector<MomentumConstraint> > rPairs = iEvent.getRefBeforePut<std::vector<MomentumConstraint> >();
130  std::unique_ptr<std::vector<MomentumConstraint> > pairs(new std::vector<MomentumConstraint>);
131  std::unique_ptr<TrackMomConstraintAssociationCollection> output(new TrackMomConstraintAssociationCollection(trackColl, rPairs));
132 
133  if ( trackColl->size() == 2 )
134  {
137 
139  std::vector<reco::TransientTrack> ttracks(2);
140  ttracks[0] = reco::TransientTrack( reco::TrackRef( trackColl, 0 ), magField.product() );
141  ttracks[0].setES( iSetup );
142  ttracks[1] = reco::TransientTrack( reco::TrackRef( trackColl, 1 ), magField.product() );
143  ttracks[1].setES( iSetup );
144 
146  TwoBodyDecay tbd = tbdFitter_.estimate( ttracks, vm );
147 
148  if ( !tbd.isValid() or ( tbd.chi2() > chi2CutValue_ ) ) return;
149 
150  std::pair<double, double> fitMomenta;
151  if ( momentumForRefitting_ == atVertex ) {
152  fitMomenta = momentaAtVertex( tbd );
153  } else if ( momentumForRefitting_ == atInnermostSurface ) {
154  fitMomenta = momentaAtInnermostSurface( tbd, ttracks, magField.product() );
155  } // no other possibility!!!
156 
157  if ( ( fitMomenta.first > 0. ) and ( fitMomenta.second > 0. ) )
158  {
159  // produce constraint for first track
160  MomentumConstraint constraint1( fitMomenta.first, fixedMomentumError_ );
161  pairs->push_back( constraint1 );
162  output->insert(reco::TrackRef(trackColl, 0), edm::Ref<std::vector<MomentumConstraint> >(rPairs, 0));
163 
164  // produce constraint for second track
165  MomentumConstraint constraint2( fitMomenta.second, fixedMomentumError_ );
166  pairs->push_back( constraint2 );
167  output->insert(reco::TrackRef(trackColl, 1), edm::Ref<std::vector<MomentumConstraint> >(rPairs, 1));
168  }
169 
170 // // debug
171 // if ( tbd.isValid() and ( fitMomenta.first > 0. ) and ( fitMomenta.second > 0. ) ) {
172 // TwoBodyDecayModel model;
173 // const std::pair< AlgebraicVector, AlgebraicVector > fitMomenta = model.cartesianSecondaryMomenta( tbd );
174 
175 // TLorentzVector recoMomentum1( ttracks[0].track().px(), ttracks[0].track().py(), ttracks[0].track().pz(),
176 // sqrt((ttracks[0].track().p()*ttracks[0].track().p())+0.105658*0.105658) );
177 // TLorentzVector fitMomentum1( fitMomenta.first[0], fitMomenta.first[1], fitMomenta.first[2],
178 // sqrt( fitMomenta.first.normsq()+0.105658*0.105658) );
179 // histos_["deltaP1"]->Fill( recoMomentum1.P() - fitMomentum1.P() );
180 // histos_["deltaEta1"]->Fill( recoMomentum1.Eta() - fitMomentum1.Eta() );
181 
182 // TLorentzVector recoMomentum2( ttracks[1].track().px(), ttracks[1].track().py(), ttracks[1].track().pz(),
183 // sqrt((ttracks[1].track().p()*ttracks[1].track().p())+0.105658*0.105658) );
184 // TLorentzVector fitMomentum2( fitMomenta.second[0], fitMomenta.second[1], fitMomenta.second[2],
185 // sqrt( fitMomenta.second.normsq()+0.105658*0.105658) );
186 // histos_["deltaP2"]->Fill( recoMomentum2.P() - fitMomentum2.P() );
187 // histos_["deltaEta2"]->Fill( recoMomentum2.Eta() - fitMomentum2.Eta() );
188 // }
189  }
190 
191  iEvent.put(std::move(pairs));
192  iEvent.put(std::move(output));
193 }
194 
195 
196 std::pair<double, double>
198 {
199  // construct global trajectory parameters at the starting point
201  std::pair< AlgebraicVector, AlgebraicVector > secondaryMomenta = tbdDecayModel.cartesianSecondaryMomenta( tbd );
202 
203  return std::make_pair( secondaryMomenta.first.norm(),
204  secondaryMomenta.second.norm() );
205 }
206 
207 
208 std::pair<double, double>
210  const std::vector<reco::TransientTrack>& ttracks,
211  const MagneticField* magField) const
212 {
213  std::pair<double, double> result = std::make_pair( -1., -1. );
214 
216  std::pair<bool, TrajectoryStateOnSurface> oldInnermostState1 = innermostState( ttracks[0] );
217  std::pair<bool, TrajectoryStateOnSurface> oldInnermostState2 = innermostState( ttracks[1] );
218  if ( !oldInnermostState1.second.isValid() || !oldInnermostState2.second.isValid() ) return result;
219 
221  TwoBodyDecayTrajectoryState::TsosContainer trackTsos( oldInnermostState1.second, oldInnermostState2.second );
222  TwoBodyDecayTrajectoryState tbdTrajState( trackTsos, tbd, secondaryMass_, magField, true );
223  if ( !tbdTrajState.isValid() ) return result;
224 
226  bool match1 = match( tbdTrajState.trajectoryStates(true).first, oldInnermostState1.second );
227  bool match2 = match( tbdTrajState.trajectoryStates(true).second, oldInnermostState2.second );
228  if ( !match1 || !match2 ) return result;
229 
230  result = std::make_pair( fabs( 1./tbdTrajState.trajectoryStates(true).first.localParameters().qbp() ),
231  fabs( 1./tbdTrajState.trajectoryStates(true).second.localParameters().qbp() ) );
232  return result;
233 }
234 
235 
236 std::pair<bool, TrajectoryStateOnSurface>
238 {
239  double outerR = ttrack.outermostMeasurementState().globalPosition().perp();
240  double innerR = ttrack.innermostMeasurementState().globalPosition().perp();
241  bool insideOut = ( outerR > innerR );
242  return std::make_pair( insideOut, insideOut ? ttrack.innermostMeasurementState() : ttrack.outermostMeasurementState() );
243 }
244 
245 
246 bool
248  const TrajectoryStateOnSurface& oldTsos ) const
249 {
250  LocalPoint lp1 = newTsos.localPosition();
251  LocalPoint lp2 = oldTsos.localPosition();
252 
253  double deltaX = lp1.x() - lp2.x();
254  double deltaY = lp1.y() - lp2.y();
255 
256  return ( ( fabs(deltaX) < sigmaPositionCutValue_ ) && ( fabs(deltaY) < sigmaPositionCutValue_ ) );
257 }
258 
261  if ( strMomentumForRefitting == "atVertex" ) {
262  return atVertex;
263  } else if ( strMomentumForRefitting == "atInnermostSurface" ) {
264  return atInnermostSurface;
265  } else {
266  throw cms::Exception("TwoBodyDecayMomConstraintProducer") << "value of config variable 'momentumForRefitting': "
267  << "has to be 'atVertex' or 'atInnermostSurface'";
268  }
269 }
270 
271 
272 
273 //define this as a plug-in
bool match(const TrajectoryStateOnSurface &newTsos, const TrajectoryStateOnSurface &oldTsos) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
T perp() const
Definition: PV3DBase.h:72
std::pair< bool, TrajectoryStateOnSurface > innermostState(const reco::TransientTrack &ttrack) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
~TwoBodyDecayMomConstraintProducer() override=default
T y() const
Definition: PV3DBase.h:63
GlobalPoint globalPosition() const
const TsosContainer & trajectoryStates(bool useRefittedState=true) const
TrajectoryStateOnSurface innermostMeasurementState() const
virtual const TwoBodyDecay estimate(const std::vector< reco::TransientTrack > &tracks, const TwoBodyDecayVirtualMeasurement &vm) const
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< reco::TrackCollection > trackCollToken_
TwoBodyDecayMomConstraintProducer(const edm::ParameterSet &)
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
void produce(edm::StreamID streamid, edm::Event &, const edm::EventSetup &) const override
TrajectoryStateOnSurface outermostMeasurementState() const
std::pair< double, double > momentaAtVertex(const TwoBodyDecay &tbd) const
static MomentumForRefitting momentumForRefittingFromString(std::string momentumForRefittingString)
RefProd< PROD > getRefBeforePut()
Definition: Event.h:150
void setES(const edm::EventSetup &es)
edm::AssociationMap< edm::OneToOne< reco::TrackCollection, std::vector< MomentumConstraint > > > TrackMomConstraintAssociationCollection
bool isValid(void) const
Definition: TwoBodyDecay.h:46
std::pair< double, double > momentaAtInnermostSurface(const TwoBodyDecay &tbd, const std::vector< reco::TransientTrack > &ttracks, const MagneticField *magField) const
T const * product() const
Definition: Handle.h:74
std::pair< TrajectoryStateOnSurface, TrajectoryStateOnSurface > TsosContainer
double chi2(void) const
Definition: TwoBodyDecay.h:44
HLT enums.
T get() const
Definition: EventSetup.h:71
T x() const
Definition: PV3DBase.h:62
T const * product() const
Definition: ESHandle.h:86
edm::EDGetTokenT< reco::BeamSpot > bsToken_
def move(src, dest)
Definition: eostools.py:511
const std::pair< AlgebraicVector, AlgebraicVector > cartesianSecondaryMomenta(const AlgebraicVector &param)