CMS 3D CMS Logo

HLTDisplacedmumuVtxProducer.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  minPtPair_ (iConfig.getParameter<double>("MinPtPair")),
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>("MinPtPair",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("hltDisplacedmumuVtxProducer", desc);
66 }
67 
68 // ------------ method called once each job just before starting event loop ------------
70 {
71 
72 }
73 
74 // ------------ method called once each job just after ending the event loop ------------
76 {
77 
78 }
79 
80 // ------------ method called on each new Event ------------
82 {
83  double const MuMass = 0.106;
84  double const MuMass2 = MuMass*MuMass;
85 
86 
87  // get hold of muon trks
89  iEvent.getByToken(srcToken_,mucands);
90 
91  //get the transient track builder:
93  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder",theB);
94 
95  std::unique_ptr<VertexCollection> vertexCollection(new VertexCollection());
96 
97  // look at all mucands, check cuts and make vertices
98  double e1,e2;
100 
101  RecoChargedCandidateCollection::const_iterator cand1;
102  RecoChargedCandidateCollection::const_iterator cand2;
103 
104  // get the objects passing the previous filter
106  iEvent.getByToken(previousCandToken_,previousCands);
107 
108  vector<RecoChargedCandidateRef> vPrevCands;
109  previousCands->getObjects(TriggerMuon,vPrevCands);
110 
111  for (cand1=mucands->begin(); cand1!=mucands->end(); cand1++) {
112  TrackRef tk1 = cand1->get<TrackRef>();
113  LogDebug("HLTDisplacedMumuFilter") << " 1st muon in loop: q*pt= " << cand1->charge()*cand1->pt() << ", eta= " << cand1->eta() << ", hits= " << tk1->numberOfValidHits();
114 
115  //first check if this muon passed the previous filter
116  if( ! checkPreviousCand( tk1, vPrevCands) ) continue;
117 
118  // cuts
119  if (fabs(cand1->eta())>maxEta_) continue;
120  if (cand1->pt() < minPt_) continue;
121 
122  cand2 = cand1; cand2++;
123  for (; cand2!=mucands->end(); cand2++) {
124  TrackRef tk2 = cand2->get<TrackRef>();
125 
126  // eta cut
127  LogDebug("HLTDisplacedmumuVtxProducer") << " 2nd muon in loop: q*pt= " << cand2->charge()*cand2->pt() << ", eta= " << cand2->eta() << ", hits= " << tk2->numberOfValidHits() << ", d0= " << tk2->d0();
128  //first check if this muon passed the previous filter
129  if( ! checkPreviousCand( tk2, vPrevCands) ) continue;
130 
131  // cuts
132  if (fabs(cand2->eta())>maxEta_) continue;
133  if (cand2->pt() < minPt_) continue;
134 
135  // opposite sign or same sign
136  if (chargeOpt_<0) {
137  if (cand1->charge()*cand2->charge()>0) continue;
138  } else if (chargeOpt_>0) {
139  if (cand1->charge()*cand2->charge()<0) continue;
140  }
141 
142  // Combined dimuon system
143  e1 = sqrt(cand1->momentum().Mag2()+MuMass2);
144  e2 = sqrt(cand2->momentum().Mag2()+MuMass2);
145  p1 = Particle::LorentzVector(cand1->px(),cand1->py(),cand1->pz(),e1);
146  p2 = Particle::LorentzVector(cand2->px(),cand2->py(),cand2->pz(),e2);
147  p = p1+p2;
148 
149 
150  if (p.pt()<minPtPair_) continue;
151 
152  double invmass = abs(p.mass());
153  LogDebug("HLTDisplacedMumuFilter") << " ... 1-2 invmass= " << invmass;
154 
155  if (invmass<minInvMass_) continue;
156  if (invmass>maxInvMass_) continue;
157 
158  // do the vertex fit
159  vector<TransientTrack> t_tks;
160  TransientTrack ttkp1 = (*theB).build(&tk1);
161  TransientTrack ttkp2 = (*theB).build(&tk2);
162  t_tks.push_back(ttkp1);
163  t_tks.push_back(ttkp2);
164 
165 
166  if (t_tks.size()!=2) continue;
167 
168  KalmanVertexFitter kvf;
169  TransientVertex tv = kvf.vertex(t_tks);
170 
171  if (!tv.isValid()) continue;
172 
173  Vertex vertex = tv;
174 
175  // put vertex in the event
176  vertexCollection->push_back(vertex);
177  }
178  }
179  iEvent.put(std::move(vertexCollection));
180 }
181 
182 
183 
184 bool HLTDisplacedmumuVtxProducer::checkPreviousCand(const TrackRef& trackref, vector<RecoChargedCandidateRef> & refVect){
185  bool ok=false;
186  for (auto & i : refVect) {
187  if ( i->get<TrackRef>() == trackref ) {
188  ok=true;
189  break;
190  }
191  }
192  return ok;
193 }
#define LogDebug(id)
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:
bool checkPreviousCand(const reco::TrackRef &trackref, std::vector< reco::RecoChargedCandidateRef > &ref2)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
HLTDisplacedmumuVtxProducer(const edm::ParameterSet &)
virtual CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &tracks) const
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
int iEvent
Definition: GenABIO.cc:230
T sqrt(T t)
Definition: SSEVec.h:18
const edm::EDGetTokenT< trigger::TriggerFilterObjectWithRefs > previousCandToken_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const edm::EDGetTokenT< reco::RecoChargedCandidateCollection > srcToken_
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:245
virtual void produce(edm::Event &, const edm::EventSetup &)
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
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const T & get() const
Definition: EventSetup.h:55
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Float e2
Definition: deltaR.h:21
fixed size matrix
HLT enums.
double p1[4]
Definition: TauolaWrapper.h:89
bool isValid() const
def move(src, dest)
Definition: eostools.py:510
math::PtEtaPhiELorentzVectorF LorentzVector