CMS 3D CMS Logo

HLTDisplacedmumumuVtxProducer.cc
Go to the documentation of this file.
1 #include <iostream>
2 
6 
14 
19 
25 
26 
28 
29 using namespace edm;
30 using namespace reco;
31 using namespace std;
32 using namespace trigger;
33 //
34 // constructors and destructor
35 //
37  srcTag_ (iConfig.getParameter<edm::InputTag>("Src")),
38  srcToken_(consumes<reco::RecoChargedCandidateCollection>(srcTag_)),
39  previousCandTag_(iConfig.getParameter<edm::InputTag>("PreviousCandTag")),
40  previousCandToken_(consumes<trigger::TriggerFilterObjectWithRefs>(previousCandTag_)),
41  maxEta_ (iConfig.getParameter<double>("MaxEta")),
42  minPt_ (iConfig.getParameter<double>("MinPt")),
43  minPtTriplet_ (iConfig.getParameter<double>("MinPtTriplet")),
44  minInvMass_ (iConfig.getParameter<double>("MinInvMass")),
45  maxInvMass_ (iConfig.getParameter<double>("MaxInvMass")),
46  chargeOpt_ (iConfig.getParameter<int>("ChargeOpt"))
47 {
48  produces<VertexCollection>();
49 }
50 
51 
53 
54 void
57  desc.add<edm::InputTag>("Src",edm::InputTag("hltL3MuonCandidates"));
58  desc.add<edm::InputTag>("PreviousCandTag",edm::InputTag(""));
59  desc.add<double>("MaxEta",2.5);
60  desc.add<double>("MinPt",0.0);
61  desc.add<double>("MinPtTriplet",0.0);
62  desc.add<double>("MinInvMass",1.0);
63  desc.add<double>("MaxInvMass",20.0);
64  desc.add<int>("ChargeOpt",-1);
65  descriptions.add("hltDisplacedmumumuVtxProducer", desc);
66 }
67 
68 
69 // ------------ method called once each job just before starting event loop ------------
71 {
72 
73 }
74 
75 // ------------ method called once each job just after ending the event loop ------------
77 {
78 
79 }
80 
81 // ------------ method called on each new Event ------------
83 {
84  double const MuMass = 0.106;
85  double const MuMass2 = MuMass*MuMass;
86 
87 
88  // get hold of muon trks
90  iEvent.getByToken(srcToken_,mucands);
91 
92  //get the transient track builder:
94  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder",theB);
95 
96  std::unique_ptr<VertexCollection> vertexCollection(new VertexCollection());
97 
98  // look at all mucands, check cuts and make vertices
99  double e1,e2,e3;
101 
102  RecoChargedCandidateCollection::const_iterator cand1;
103  RecoChargedCandidateCollection::const_iterator cand2;
104  RecoChargedCandidateCollection::const_iterator cand3;
105 
106  // get the objects passing the previous filter
108  iEvent.getByToken(previousCandToken_,previousCands);
109 
110  vector<RecoChargedCandidateRef> vPrevCands;
111  previousCands->getObjects(TriggerMuon,vPrevCands);
112 
113  for (cand1=mucands->begin(); cand1!=mucands->end(); cand1++) {
114  TrackRef tk1 = cand1->get<TrackRef>();
115  LogDebug("HLTDisplacedMumumuFilter") << " 1st muon in loop: q*pt= " << cand1->charge()*cand1->pt() << ", eta= " << cand1->eta() << ", hits= " << tk1->numberOfValidHits();
116 
117  //first check if this muon passed the previous filter
118  if( ! checkPreviousCand( tk1, vPrevCands) ) continue;
119 
120  // cuts
121  if (fabs(cand1->eta())>maxEta_) continue;
122  if (cand1->pt() < minPt_) continue;
123 
124  cand2 = cand1; cand2++;
125  for (; cand2!=mucands->end(); cand2++) {
126  TrackRef tk2 = cand2->get<TrackRef>();
127 
128  // eta cut
129  LogDebug("HLTMuonDimuonFilter") << " 2nd muon in loop: q*pt= " << cand2->charge()*cand2->pt() << ", eta= " << cand2->eta() << ", hits= " << tk2->numberOfValidHits() << ", d0= " << tk2->d0();
130  //first check if this muon passed the previous filter
131  if( ! checkPreviousCand( tk2, vPrevCands) ) continue;
132 
133  // cuts
134  if (fabs(cand2->eta())>maxEta_) continue;
135  if (cand2->pt() < minPt_) continue;
136 
137  cand3 = cand2; cand3++;
138  for (; cand3!=mucands->end(); cand3++) {
139  TrackRef tk3 = cand3->get<TrackRef>();
140 
141  // eta cut
142  LogDebug("HLTMuonDimuonFilter") << " 3rd muon in loop: q*pt= " << cand3->charge()*cand3->pt() << ", eta= " << cand3->eta() << ", hits= " << tk3->numberOfValidHits() << ", d0= " << tk3->d0();
143  //first check if this muon passed the previous filter
144  if( ! checkPreviousCand( tk3, vPrevCands) ) continue;
145 
146  // cuts
147  if (fabs(cand3->eta())>maxEta_) continue;
148  if (cand3->pt() < minPt_) continue;
149 
150  // opposite sign or same sign
151  if (chargeOpt_>0) {
152  if (fabs (cand1->charge() + cand2->charge() + cand3->charge()) != chargeOpt_) continue;
153  }
154 
155  // Combined dimuon system
156  e1 = sqrt(cand1->momentum().Mag2()+MuMass2);
157  e2 = sqrt(cand2->momentum().Mag2()+MuMass2);
158  e3 = sqrt(cand3->momentum().Mag2()+MuMass2);
159  p1 = Particle::LorentzVector(cand1->px(),cand1->py(),cand1->pz(),e1);
160  p2 = Particle::LorentzVector(cand2->px(),cand2->py(),cand2->pz(),e2);
161  p3 = Particle::LorentzVector(cand3->px(),cand3->py(),cand3->pz(),e3);
162  p = p1+p2+p3;
163 
164 
165  if (p.pt()<minPtTriplet_) continue;
166 
167  double invmass = abs(p.mass());
168  LogDebug("HLTDisplacedMumumuFilter") << " ... 1-2 invmass= " << invmass;
169 
170  if (invmass<minInvMass_) continue;
171  if (invmass>maxInvMass_) continue;
172 
173  // do the vertex fit
174  vector<TransientTrack> t_tks;
175  TransientTrack ttkp1 = (*theB).build(&tk1);
176  TransientTrack ttkp2 = (*theB).build(&tk2);
177  TransientTrack ttkp3 = (*theB).build(&tk3);
178  t_tks.push_back(ttkp1);
179  t_tks.push_back(ttkp2);
180  t_tks.push_back(ttkp3);
181 
182 
183  if (t_tks.size()!=3) continue;
184 
185  KalmanVertexFitter kvf;
186  TransientVertex tv = kvf.vertex(t_tks);
187 
188  if (!tv.isValid()) continue;
189 
190  Vertex vertex = tv;
191 
192  // put vertex in the event
193  vertexCollection->push_back(vertex);
194  }
195  }
196  }
197  iEvent.put(std::move(vertexCollection));
198 }
199 
200 
201 
202 bool HLTDisplacedmumumuVtxProducer::checkPreviousCand(const TrackRef& trackref, vector<RecoChargedCandidateRef> & refVect){
203  bool ok=false;
204  for (auto & i : refVect) {
205  if ( i->get<TrackRef>() == trackref ) {
206  ok=true;
207  break;
208  }
209  }
210  return ok;
211 }
#define LogDebug(id)
edm::EDGetTokenT< reco::RecoChargedCandidateCollection > srcToken_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
void getObjects(Vids &ids, VRphoton &refs) const
various physics-level getters:
HLTDisplacedmumumuVtxProducer(const edm::ParameterSet &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
virtual CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &tracks) const
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
edm::EDGetTokenT< trigger::TriggerFilterObjectWithRefs > previousCandToken_
int iEvent
Definition: GenABIO.cc:230
T sqrt(T t)
Definition: SSEVec.h:18
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool checkPreviousCand(const reco::TrackRef &trackref, std::vector< reco::RecoChargedCandidateRef > &ref2)
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
std::vector< RecoChargedCandidate > RecoChargedCandidateCollection
collectin of RecoChargedCandidate objects
Float e1
Definition: deltaR.h:20
const T & get() const
Definition: EventSetup.h:56
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Float e2
Definition: deltaR.h:21
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
fixed size matrix
HLT enums.
double p1[4]
Definition: TauolaWrapper.h:89
virtual void produce(edm::Event &, const edm::EventSetup &)
bool isValid() const
def move(src, dest)
Definition: eostools.py:510
math::PtEtaPhiELorentzVectorF LorentzVector
double p3[4]
Definition: TauolaWrapper.h:91