CMS 3D CMS Logo

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