CMS 3D CMS Logo

HLTDisplacedtktktkVtxProducer.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>("MaxEtaTk")),
41  minPtTk1_ (iConfig.getParameter<double>("MinPtResTk1")),
42  minPtTk2_ (iConfig.getParameter<double>("MinPtResTk2")),
43  minPtTk3_ (iConfig.getParameter<double>("MinPtThirdTk")),
44  minPtRes_ (iConfig.getParameter<double>("MinPtRes")),
45  minPtTri_ (iConfig.getParameter<double>("MinPtTri")),
46  minInvMassRes_ (iConfig.getParameter<double>("MinInvMassRes")),
47  maxInvMassRes_ (iConfig.getParameter<double>("MaxInvMassRes")),
48  minInvMass_ (iConfig.getParameter<double>("MinInvMass")),
49  maxInvMass_ (iConfig.getParameter<double>("MaxInvMass")),
50  massParticle1_ (iConfig.getParameter<double>("massParticleRes1")),
51  massParticle2_ (iConfig.getParameter<double>("massParticleRes2")),
52  massParticle3_ (iConfig.getParameter<double>("massParticle3")),
53  chargeOpt_ (iConfig.getParameter<int>("ChargeOpt")),
54  resOpt_ (iConfig.getParameter<int>("ResOpt")),
55  triggerTypeDaughters_(iConfig.getParameter<int>("triggerTypeDaughters"))
56 
57 {
58  produces<VertexCollection>();
59 
67  {
69  {
72  }
74  {
75  std::swap(firstTrackMass, thirdTrackMass);
77  }
78  }
79  firstTrackMass2 = firstTrackMass*firstTrackMass;
82 }
83 
85 
86 void
89  desc.add<edm::InputTag>("Src",edm::InputTag("hltL3MuonCandidates"));
90  desc.add<edm::InputTag>("PreviousCandTag",edm::InputTag(""));
91  desc.add<double>("MaxEtaTk",2.5);
92  desc.add<double>("MinPtResTk1",0.0);
93  desc.add<double>("MinPtResTk2",0.0);
94  desc.add<double>("MinPtThirdTk",0.0);
95  desc.add<double>("MinPtRes",0.0);
96  desc.add<double>("MinPtTri",0.0);
97  desc.add<double>("MinInvMassRes",1.0);
98  desc.add<double>("MaxInvMassRes",20.0);
99  desc.add<double>("MinInvMass",1.0);
100  desc.add<double>("MaxInvMass",20.0);
101  desc.add<double>("massParticleRes1",0.4937);
102  desc.add<double>("massParticleRes2",0.4937);
103  desc.add<double>("massParticle3",0.1396);
104  desc.add<int>("ChargeOpt",-1);
105  desc.add<int>("ResOpt",1);
106  desc.add<int>("triggerTypeDaughters",0);
107 
108  descriptions.add("hltDisplacedtktktkVtxProducer", desc);
109 }
110 
111 // ------------ method called once each job just before starting event loop ------------
113 {
114 
115 }
116 
117 // ------------ method called once each job just after ending the event loop ------------
119 {
120 
121 }
122 
123 // ------------ method called on each new Event ------------
125 {
126  // get hold of track trks
128  iEvent.getByToken(srcToken_,trackcands);
129  if ( trackcands->size() < 3 ) return;
130 
131  //get the transient track builder:
133  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder",theB);
134 
135  std::unique_ptr<VertexCollection> vertexCollection(new VertexCollection());
136 
137  // look at all trackcands, check cuts and make vertices
138  double e1,e2,e3;
140 
141  RecoChargedCandidateCollection::const_iterator cand1;
142  RecoChargedCandidateCollection::const_iterator cand2;
143  RecoChargedCandidateCollection::const_iterator cand3;
144 
145  // get the objects passing the previous filter
147  iEvent.getByToken(previousCandToken_,previousCands);
148 
149  vector<RecoChargedCandidateRef> vPrevCands;
150  previousCands->getObjects(triggerTypeDaughters_,vPrevCands);
151 
152  std::vector<bool> candComp;
153  for (cand1=trackcands->begin(); cand1!=trackcands->end(); cand1++)
154  candComp.push_back(checkPreviousCand( cand1->get<TrackRef>(), vPrevCands));
155 
156  for (cand1=trackcands->begin(); cand1!=trackcands->end(); cand1++) {
157 
158  TrackRef tk1 = cand1->get<TrackRef>();
159  LogDebug("HLTDisplacedtktktkVtxProducer") << " 1st track in loop: q*pt= " << cand1->charge()*cand1->pt() << ", eta= " << cand1->eta() << ", hits= " << tk1->numberOfValidHits();
160 
161  //first check if this track passed the previous filter
162  if (!candComp[cand1-trackcands->begin()]) continue;
163  // if( ! checkPreviousCand( tk1, vPrevCands) ) continue;
164 
165  // cuts
166  if (std::abs(cand1->eta())>maxEta_) continue;
167  if (cand1->pt() < firstTrackPt) continue;
168 
169  cand2=trackcands->begin();
170  if(firstTrackMass==secondTrackMass){cand2 = cand1+1;}
171 
172  for (; cand2!=trackcands->end(); cand2++) {
173 
174  TrackRef tk2 = cand2->get<TrackRef>();
175  if(tk1==tk2) continue;
176  LogDebug("HLTDisplacedtktktkVtxProducer") << " 2nd track in loop: q*pt= " << cand2->charge()*cand2->pt() << ", eta= " << cand2->eta() << ", hits= " << tk2->numberOfValidHits() << ", d0= " << tk2->d0();
177 
178  //first check if this track passed the previous filter
179  if (!candComp[cand2-trackcands->begin()]) continue;
180  // if( ! checkPreviousCand( tk2, vPrevCands) ) continue;
181 
182  // cuts
183  if (std::abs(cand2->eta()) > maxEta_) continue;
184  if (cand2->pt() < secondTrackPt) continue;
185 
186  // opposite sign or same sign for resonance
187  if(resOpt_>0)
188  {
189  if (chargeOpt_<0) {
190  if (cand1->charge()*cand2->charge()>0) continue;
191  } else if (chargeOpt_>0) {
192  if (cand1->charge()*cand2->charge()<0) continue;
193  }
194  }
195 
196  //
197  // Combined ditrack system
198  e1 = sqrt(cand1->momentum().Mag2()+firstTrackMass2);
199  e2 = sqrt(cand2->momentum().Mag2()+secondTrackMass2);
200  pres = Particle::LorentzVector(cand1->px(),cand1->py(),cand1->pz(),e1)+Particle::LorentzVector(cand2->px(),cand2->py(),cand2->pz(),e2);
201 
202  if(resOpt_>0)
203  {
204  if (pres.pt()<minPtRes_) continue;
205  double invmassRes = std::abs(pres.mass());
206  LogDebug("HLTDisplacedtktktkVtxProducer") << " ... 1-2 invmass= " << invmassRes;
207  if (invmassRes<minInvMassRes_) continue;
208  if (invmassRes>maxInvMassRes_) continue;
209  }
210 
211  cand3=trackcands->begin();
212  if(firstTrackMass==secondTrackMass && firstTrackMass==thirdTrackMass && resOpt_<=0){cand3 = cand2+1;}
213 
214  for (; cand3!=trackcands->end(); cand3++) {
215 
216  TrackRef tk3 = cand3->get<TrackRef>();
217  if(tk1==tk3 || tk2==tk3) continue;
218  LogDebug("HLTDisplacedtktktkVtxProducer") << " 3rd track in loop: q*pt= " << cand3->charge()*cand3->pt() << ", eta= " << cand3->eta() << ", hits= " << tk3->numberOfValidHits();
219 
220  //first check if this track passed the previous filter
221  if (!candComp[cand3-trackcands->begin()]) continue;
222  // if( ! checkPreviousCand( tk3, vPrevCands) ) continue;
223 
224  // cuts
225  if (std::abs(cand3->eta())>maxEta_) continue;
226  if (cand3->pt() < thirdTrackPt) continue;
227 
228  e3 = sqrt(cand3->momentum().Mag2()+thirdTrackMass2);
229  p = Particle::LorentzVector(cand1->px(),cand1->py(),cand1->pz(),e1)+Particle::LorentzVector(cand2->px(),cand2->py(),cand2->pz(),e2)+Particle::LorentzVector(cand3->px(),cand3->py(),cand3->pz(),e3);
230 
231  if (p.pt()<minPtTri_) continue;
232  double invmass = std::abs(p.mass());
233  LogDebug("HLTDisplacedtktktkVtxProducer") << " ... 1-2-3 invmass= " << invmass;
234  if (invmass<minInvMass_) continue;
235  if (invmass>maxInvMass_) continue;
236 
237  // do the vertex fit
238  vector<TransientTrack> t_tks;
239  TransientTrack ttkp1 = (*theB).build(&tk1);
240  TransientTrack ttkp2 = (*theB).build(&tk2);
241  TransientTrack ttkp3 = (*theB).build(&tk3);
242 
243  t_tks.push_back(ttkp1);
244  t_tks.push_back(ttkp2);
245  t_tks.push_back(ttkp3);
246 
247  if (t_tks.size()!=3) continue;
248 
249  KalmanVertexFitter kvf;
250  TransientVertex tv = kvf.vertex(t_tks);
251 
252  if (!tv.isValid()) continue;
253 
254  Vertex vertex = tv;
255 
256  // put vertex in the event
257  vertexCollection->push_back(vertex);
258  }
259  }
260  }
261  iEvent.put(std::move(vertexCollection));
262 }
263 
264 
265 
266 bool HLTDisplacedtktktkVtxProducer::checkPreviousCand(const TrackRef& trackref, vector<RecoChargedCandidateRef> & refVect){
267  bool ok=false;
268  for (auto & i : refVect) {
269  if ( i->get<TrackRef>() == trackref ) {
270  ok=true;
271  break;
272  }
273  }
274  return ok;
275 }
#define LogDebug(id)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
void getObjects(Vids &ids, VRphoton &refs) const
various physics-level getters:
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
bool checkPreviousCand(const reco::TrackRef &trackref, std::vector< reco::RecoChargedCandidateRef > &ref2)
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
const edm::EDGetTokenT< trigger::TriggerFilterObjectWithRefs > previousCandToken_
const edm::EDGetTokenT< reco::RecoChargedCandidateCollection > srcToken_
int iEvent
Definition: GenABIO.cc:230
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
T sqrt(T t)
Definition: SSEVec.h:18
~HLTDisplacedtktktkVtxProducer() override
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &tracks) const override
HLTDisplacedtktktkVtxProducer(const edm::ParameterSet &)
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:245
ParameterDescriptionBase * add(U const &iLabel, T const &value)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< RecoChargedCandidate > RecoChargedCandidateCollection
collectin of RecoChargedCandidate objects
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void produce(edm::Event &, const edm::EventSetup &) override
fixed size matrix
HLT enums.
T get() const
Definition: EventSetup.h:68
bool isValid() const
def move(src, dest)
Definition: eostools.py:511
math::PtEtaPhiELorentzVectorF LorentzVector