test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HLTmumutktkVtxProducer.cc
Go to the documentation of this file.
1 #include <algorithm>
2 #include <cmath>
3 #include <vector>
4 
8 
21 
24 #include "TMath.h"
25 
26 using namespace edm;
27 using namespace reco;
28 using namespace std;
29 using namespace trigger;
30 
31 // ----------------------------------------------------------------------
33  muCandTag_ (iConfig.getParameter<edm::InputTag>("MuCand")),
34  muCandToken_(consumes<reco::RecoChargedCandidateCollection>(muCandTag_)),
35  trkCandTag_ (iConfig.getParameter<edm::InputTag>("TrackCand")),
36  trkCandToken_(consumes<reco::RecoChargedCandidateCollection>(trkCandTag_)),
37  previousCandTag_(iConfig.getParameter<edm::InputTag>("PreviousCandTag")),
38  previousCandToken_(consumes<trigger::TriggerFilterObjectWithRefs>(previousCandTag_)),
39  mfName_(iConfig.getParameter<std::string>("SimpleMagneticField")),
40  thirdTrackMass_(iConfig.getParameter<double>("ThirdTrackMass")),
41  fourthTrackMass_(iConfig.getParameter<double>("FourthTrackMass")),
42  maxEta_(iConfig.getParameter<double>("MaxEta")),
43  minPt_(iConfig.getParameter<double>("MinPt")),
44  minInvMass_(iConfig.getParameter<double>("MinInvMass")),
45  maxInvMass_(iConfig.getParameter<double>("MaxInvMass")),
46  minTrkTrkMass_(iConfig.getParameter<double>("MinTrkTrkMass")),
47  maxTrkTrkMass_(iConfig.getParameter<double>("MaxTrkTrkMass")),
48  minD0Significance_(iConfig.getParameter<double>("MinD0Significance")),
49  oppositeSign_(iConfig.getParameter<bool>("OppositeSign")),
50  overlapDR_(iConfig.getParameter<double>("OverlapDR")),
51  beamSpotTag_ (iConfig.getParameter<edm::InputTag> ("BeamSpotTag")),
52  beamSpotToken_(consumes<reco::BeamSpot>(beamSpotTag_))
53 {
54  produces<VertexCollection>();
55 }
56 
57 // ----------------------------------------------------------------------
59 
60 void
63  desc.add<edm::InputTag>("MuCand",edm::InputTag("hltMuTracks"));
64  desc.add<edm::InputTag>("TrackCand",edm::InputTag("hltMumukAllConeTracks"));
65  desc.add<edm::InputTag>("PreviousCandTag",edm::InputTag("hltDisplacedmumuFilterDoubleMu4Jpsi"));
66  desc.add<std::string>("SimpleMagneticField","");
67  desc.add<double>("ThirdTrackMass",0.493677);
68  desc.add<double>("FourthTrackMass",0.493677);
69  desc.add<double>("MaxEta",2.5);
70  desc.add<double>("MinPt",0.0);
71  desc.add<double>("MinInvMass",0.0);
72  desc.add<double>("MaxInvMass",99999.);
73  desc.add<double>("MinTrkTrkMass",0.0);
74  desc.add<double>("MaxTrkTrkMass",99999.);
75  desc.add<double>("MinD0Significance",0.0);
76  desc.add<bool>("OppositeSign",false);
77  desc.add<double>("OverlapDR",0.001);
78  desc.add<edm::InputTag>("BeamSpotTag",edm::InputTag("hltOfflineBeamSpot"));
79  descriptions.add("HLTmumutktkVtxProducer",desc);
80 }
81 
82 // ----------------------------------------------------------------------
84 {
85  const double MuMass(0.106);
86  const double MuMass2(MuMass*MuMass);
87  const double thirdTrackMass2 (thirdTrackMass_ *thirdTrackMass_ );
88  const double fourthTrackMass2(fourthTrackMass_*fourthTrackMass_);
89 
90  // get hold of muon trks
92  iEvent.getByToken(muCandToken_,mucands);
93 
94  //get the transient track builder:
96  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder",theB);
97 
98  //get the beamspot position
99  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
100  iEvent.getByToken(beamSpotToken_,recoBeamSpotHandle);
101 
102  //get the b field
103  ESHandle<MagneticField> bFieldHandle;
104  iSetup.get<IdealMagneticFieldRecord>().get(mfName_, bFieldHandle);
105  const MagneticField* magField = bFieldHandle.product();
106  TSCBLBuilderNoMaterial blsBuilder;
107 
108  // get track candidates around displaced muons
110  iEvent.getByToken(trkCandToken_,trkcands);
111 
112  auto_ptr<VertexCollection> vertexCollection( new VertexCollection() );
113 
114  // Ref to Candidate object to be recorded in filter object
115  RecoChargedCandidateRef refMu1 ;
116  RecoChargedCandidateRef refMu2 ;
117  RecoChargedCandidateRef refTrk1;
118  RecoChargedCandidateRef refTrk2;
119 
120  double e1, e2, e3_m3, e3_m4, e4_m3, e4_m4;
121  Particle::LorentzVector p, pBar, p1, p2, p3_m3, p3_m4, p4_m3, p4_m4, p_m3m4, p_m4m3;
122 
123  if ( mucands->size() < 2 ) return;
124  if ( trkcands->size() < 2 ) return;
125 
126  RecoChargedCandidateCollection::const_iterator mucand1 ;
127  RecoChargedCandidateCollection::const_iterator mucand2 ;
128  RecoChargedCandidateCollection::const_iterator trkcand1;
129  RecoChargedCandidateCollection::const_iterator trkcand2;
130 
131  // get the objects passing the previous filter
133  iEvent.getByToken(previousCandToken_,previousCands);
134 
135  vector<RecoChargedCandidateRef> vPrevCands;
136  previousCands->getObjects(TriggerMuon,vPrevCands);
137 
138  for (mucand1=mucands->begin(); mucand1!=mucands->end(); ++mucand1) {
139  TrackRef trk1 = mucand1->get<TrackRef>();
140  LogDebug("HLTmumutktkVtxProducer") << " 1st muon: q*pt= " << trk1->charge()*trk1->pt()
141  << ", eta= " << trk1->eta()
142  << ", hits= " << trk1->numberOfValidHits();
143 
144  //first check if this muon passed the previous filter
145  if( ! checkPreviousCand( trk1, vPrevCands) ) continue;
146  // eta and pt cut
147  if (fabs(trk1->eta()) > maxEta_) continue;
148  if (trk1->pt() < minPt_ ) continue;
149 
150  mucand2 = mucand1; ++mucand2;
151  for (; mucand2!=mucands->end(); mucand2++) {
152  TrackRef trk2 = mucand2->get<TrackRef>();
153  if( overlap( trk1, trk2) ) continue;
154 
155  LogDebug("HLTDisplacedMumukFilter") << " 2nd muon: q*pt= " << trk2->charge()*trk2->pt()
156  << ", eta= " << trk2->eta()
157  << ", hits= " << trk2->numberOfValidHits();
158 
159  //first check if this muon passed the previous filter
160  if( ! checkPreviousCand( trk2, vPrevCands) ) continue;
161  // eta and pt cut
162  if (fabs(trk2->eta()) > maxEta_) continue;
163  if (trk2->pt() < minPt_ ) continue;
164 
165  //loop on track collection - trk1
166  for ( trkcand1 = trkcands->begin(); trkcand1 !=trkcands->end(); ++trkcand1) {
167  TrackRef trk3 = trkcand1->get<TrackRef>();
168 
169  if( overlap( trk1, trk3) ) continue;
170  if( overlap( trk2, trk3) ) continue;
171 
172  LogDebug("HLTDisplacedMumukFilter") << " 3rd track: q*pt= " << trk3->charge()*trk3->pt()
173  << ", eta= " << trk3->eta()
174  << ", hits= " << trk3->numberOfValidHits();
175 
176  // eta and pt cut
177  if (fabs(trk3->eta()) > maxEta_) continue;
178  if (trk3->pt() < minPt_ ) continue;
179 
180  FreeTrajectoryState InitialFTS_Trk3 = initialFreeState(*trk3, magField);
181  TrajectoryStateClosestToBeamLine tscb_Trk3( blsBuilder(InitialFTS_Trk3, *recoBeamSpotHandle) );
182  double d0sigTrk3 = tscb_Trk3.transverseImpactParameter().significance();
183  if (d0sigTrk3 < minD0Significance_) continue;
184 
185  //loop on track collection - trk2
186  for ( trkcand2 = trkcands->begin(); trkcand2 !=trkcands->end(); ++trkcand2) {
187  TrackRef trk4 = trkcand2->get<TrackRef>();
188 
189  if (oppositeSign_) {
190  if (trk3->charge()*trk4->charge() != -1) continue;
191  }
192  if( overlap( trk1, trk4) ) continue;
193  if( overlap( trk2, trk4) ) continue;
194  if( overlap( trk3, trk4) ) continue;
195 
196 
197  LogDebug("HLTDisplacedMumukFilter") << " 4th track: q*pt= " << trk4->charge()*trk4->pt()
198  << ", eta= " << trk4->eta()
199  << ", hits= " << trk4->numberOfValidHits();
200 
201  // eta and pt cut
202  if (fabs(trk4->eta()) > maxEta_) continue;
203  if (trk4->pt() < minPt_ ) continue;
204 
205  FreeTrajectoryState InitialFTS_Trk4 = initialFreeState(*trk4, magField);
206  TrajectoryStateClosestToBeamLine tscb_Trk4( blsBuilder(InitialFTS_Trk4, *recoBeamSpotHandle) );
207  double d0sigTrk4 = tscb_Trk4.transverseImpactParameter().significance();
208  if (d0sigTrk4 < minD0Significance_) continue;
209 
210  // Combined system
211  e1 = sqrt(trk1->momentum().Mag2() + MuMass2 );
212  e2 = sqrt(trk2->momentum().Mag2() + MuMass2 );
213  e3_m3 = sqrt(trk3->momentum().Mag2() + thirdTrackMass2 );
214  e3_m4 = sqrt(trk3->momentum().Mag2() + fourthTrackMass2 );
215  e4_m3 = sqrt(trk4->momentum().Mag2() + thirdTrackMass2 );
216  e4_m4 = sqrt(trk4->momentum().Mag2() + fourthTrackMass2 );
217 
218  p1 = Particle::LorentzVector(trk1->px(),trk1->py(),trk1->pz(),e1 );
219  p2 = Particle::LorentzVector(trk2->px(),trk2->py(),trk2->pz(),e2 );
220  p3_m3 = Particle::LorentzVector(trk3->px(),trk3->py(),trk3->pz(),e3_m3);
221  p3_m4 = Particle::LorentzVector(trk3->px(),trk3->py(),trk3->pz(),e3_m4);
222  p4_m3 = Particle::LorentzVector(trk4->px(),trk4->py(),trk4->pz(),e4_m3);
223  p4_m4 = Particle::LorentzVector(trk4->px(),trk4->py(),trk4->pz(),e4_m4);
224 
225  p = p1 + p2 + p3_m3 + p4_m4;
226  pBar = p1 + p2 + p3_m4 + p4_m3;
227  p_m3m4 = p3_m3 + p4_m4;
228  p_m4m3 = p3_m4 + p4_m3;
229 
230  //invariant mass cut
231  if (!((p_m3m4.mass() > minTrkTrkMass_ && p_m3m4.mass() < maxTrkTrkMass_) || (p_m4m3.mass() > minTrkTrkMass_ && p_m4m3.mass() < maxTrkTrkMass_))) continue;
232  if (!((p.mass() > minInvMass_ && p.mass() < maxInvMass_ ) || (pBar.mass() > minInvMass_ && pBar.mass() < maxInvMass_)) ) continue;
233 
234  // do the vertex fit
235  vector<TransientTrack> t_tks;
236  t_tks.push_back((*theB).build(&trk1));
237  t_tks.push_back((*theB).build(&trk2));
238  t_tks.push_back((*theB).build(&trk3));
239  t_tks.push_back((*theB).build(&trk4));
240  if (t_tks.size()!=4) continue;
241 
242  KalmanVertexFitter kvf;
243  TransientVertex tv = kvf.vertex(t_tks);
244  if (!tv.isValid()) continue;
245  Vertex vertex = tv;
246 
247  vertexCollection -> push_back(vertex);
248  }
249  }
250  }
251  }
252  iEvent.put(vertexCollection);
253 }
254 
256 {
257  Basic3DVector<float> pos( tk.vertex());
258  GlobalPoint gpos( pos);
259  Basic3DVector<float> mom( tk.momentum());
260  GlobalVector gmom( mom);
261  GlobalTrajectoryParameters par( gpos, gmom, tk.charge(), field);
263  return FreeTrajectoryState( par, err);
264 }
265 
266 bool HLTmumutktkVtxProducer::overlap(const TrackRef& trackref1, const TrackRef& trackref2){
267  if (deltaR(trackref1->eta(), trackref1->phi(), trackref2->eta(), trackref2->phi()) < overlapDR_) return 1;
268  return 0;
269 }
270 
271 bool HLTmumutktkVtxProducer::checkPreviousCand(const TrackRef& trackref, vector<RecoChargedCandidateRef> & refVect){
272  bool ok=false;
273  for (unsigned int i=0; i<refVect.size(); i++) {
274  if ( refVect[i]->get<TrackRef>() == trackref ) {
275  ok=true;
276  break;
277  }
278  }
279  return ok;
280 }
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
virtual CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &tracks) const
bool overlap(const reco::TrackRef &trackref1, const reco::TrackRef &trackref2)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
const Vector & momentum() const
track momentum vector
Definition: TrackBase.h:670
static FreeTrajectoryState initialFreeState(const reco::Track &, const MagneticField *)
tuple vertexCollection
const edm::EDGetTokenT< reco::RecoChargedCandidateCollection > trkCandToken_
bool checkPreviousCand(const reco::TrackRef &trackref, std::vector< reco::RecoChargedCandidateRef > &ref2)
const edm::EDGetTokenT< reco::RecoChargedCandidateCollection > muCandToken_
const Point & vertex() const
reference point on the track. This method is DEPRECATED, please use referencePoint() instead ...
Definition: TrackBase.h:682
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
CovarianceMatrix covariance() const
return track covariance matrix
Definition: TrackBase.h:726
T sqrt(T t)
Definition: SSEVec.h:18
const edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:244
ParameterDescriptionBase * add(U const &iLabel, T const &value)
double p2[4]
Definition: TauolaWrapper.h:90
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
std::vector< RecoChargedCandidate > RecoChargedCandidateCollection
collectin of RecoChargedCandidate objects
Float e1
Definition: deltaR.h:20
double significance() const
Definition: Measurement1D.h:32
HLTmumutktkVtxProducer(const edm::ParameterSet &)
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Float e2
Definition: deltaR.h:21
const edm::EDGetTokenT< trigger::TriggerFilterObjectWithRefs > previousCandToken_
double p1[4]
Definition: TauolaWrapper.h:89
int charge() const
track electric charge
Definition: TrackBase.h:562
bool isValid() const
math::PtEtaPhiELorentzVectorF LorentzVector
virtual void produce(edm::Event &, const edm::EventSetup &)