CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HLTDisplacedtktkVtxProducer.cc
Go to the documentation of this file.
1 #include <iostream>
2 
20 
21 using namespace edm;
22 using namespace reco;
23 using namespace std;
24 using namespace trigger;
25 //
26 // constructors and destructor
27 //
29  : transientTrackRecordToken_(esConsumes(edm::ESInputTag("", "TransientTrackBuilder"))),
30  srcTag_(iConfig.getParameter<edm::InputTag>("Src")),
31  srcToken_(consumes<reco::RecoChargedCandidateCollection>(srcTag_)),
32  previousCandTag_(iConfig.getParameter<edm::InputTag>("PreviousCandTag")),
33  previousCandToken_(consumes<trigger::TriggerFilterObjectWithRefs>(previousCandTag_)),
34  maxEta_(iConfig.getParameter<double>("MaxEta")),
35  minPt_(iConfig.getParameter<double>("MinPt")),
36  minPtPair_(iConfig.getParameter<double>("MinPtPair")),
37  minInvMass_(iConfig.getParameter<double>("MinInvMass")),
38  maxInvMass_(iConfig.getParameter<double>("MaxInvMass")),
39  massParticle1_(iConfig.getParameter<double>("massParticle1")),
40  massParticle2_(iConfig.getParameter<double>("massParticle2")),
41  chargeOpt_(iConfig.getParameter<int>("ChargeOpt")),
42  triggerTypeDaughters_(iConfig.getParameter<int>("triggerTypeDaughters")) {
43  produces<VertexCollection>();
44 }
45 
47 
50  desc.add<edm::InputTag>("Src", edm::InputTag("hltL3MuonCandidates"));
51  desc.add<edm::InputTag>("PreviousCandTag", edm::InputTag(""));
52  desc.add<double>("MaxEta", 2.5);
53  desc.add<double>("MinPt", 0.0);
54  desc.add<double>("MinPtPair", 0.0);
55  desc.add<double>("MinInvMass", 1.0);
56  desc.add<double>("MaxInvMass", 20.0);
57  desc.add<double>("massParticle1", 0.1396);
58  desc.add<double>("massParticle2", 0.4937);
59  desc.add<int>("ChargeOpt", -1);
60  desc.add<int>("triggerTypeDaughters", 0);
61 
62  descriptions.add("hltDisplacedtktkVtxProducer", desc);
63 }
64 
65 // ------------ method called on each new Event ------------
67  double const firstTrackMass = massParticle1_;
68  double const firstTrackMass2 = firstTrackMass * firstTrackMass;
69  double const secondTrackMass = massParticle2_;
70  double const secondTrackMass2 = secondTrackMass * secondTrackMass;
71 
72  // get hold of track trks
74  iEvent.getByToken(srcToken_, trackcands);
75 
76  // get the transient track builder
77  auto const& theB = iSetup.getHandle(transientTrackRecordToken_);
78 
79  std::unique_ptr<VertexCollection> vertexCollection(new VertexCollection());
80 
81  // look at all trackcands, check cuts and make vertices
82  double e1, e2;
84 
85  RecoChargedCandidateCollection::const_iterator cand1;
86  RecoChargedCandidateCollection::const_iterator cand2;
87 
88  // get the objects passing the previous filter
90  iEvent.getByToken(previousCandToken_, previousCands);
91 
92  vector<RecoChargedCandidateRef> vPrevCands;
93  previousCands->getObjects(triggerTypeDaughters_, vPrevCands);
94 
95  std::vector<bool> candComp;
96  for (cand1 = trackcands->begin(); cand1 != trackcands->end(); cand1++)
97  candComp.push_back(checkPreviousCand(cand1->get<TrackRef>(), vPrevCands));
98 
99  for (cand1 = trackcands->begin(); cand1 != trackcands->end(); cand1++) {
100  TrackRef tk1 = cand1->get<TrackRef>();
101  LogDebug("HLTDisplacedtktkVtxProducer") << " 1st track in loop: q*pt= " << cand1->charge() * cand1->pt()
102  << ", eta= " << cand1->eta() << ", hits= " << tk1->numberOfValidHits();
103 
104  //first check if this track passed the previous filter
105  if (!candComp[cand1 - trackcands->begin()])
106  continue;
107  // if( ! checkPreviousCand( tk1, vPrevCands) ) continue;
108 
109  // cuts
110  if (abs(cand1->eta()) > maxEta_)
111  continue;
112  if (cand1->pt() < minPt_)
113  continue;
114 
115  cand2 = trackcands->begin();
117  cand2 = cand1 + 1;
118  }
119 
120  for (; cand2 != trackcands->end(); cand2++) {
121  TrackRef tk2 = cand2->get<TrackRef>();
122  if (tk1 == tk2)
123  continue;
124 
125  // eta cut
126  LogDebug("HLTDisplacedtktkVtxProducer")
127  << " 2nd track in loop: q*pt= " << cand2->charge() * cand2->pt() << ", eta= " << cand2->eta()
128  << ", hits= " << tk2->numberOfValidHits() << ", d0= " << tk2->d0();
129  //first check if this track passed the previous filter
130  if (!candComp[cand2 - trackcands->begin()])
131  continue;
132  // if( ! checkPreviousCand( tk2, vPrevCands) ) continue;
133 
134  // cuts
135  if (abs(cand2->eta()) > maxEta_)
136  continue;
137  if (cand2->pt() < minPt_)
138  continue;
139 
140  // opposite sign or same sign
141  if (chargeOpt_ < 0) {
142  if (cand1->charge() * cand2->charge() > 0)
143  continue;
144  } else if (chargeOpt_ > 0) {
145  if (cand1->charge() * cand2->charge() < 0)
146  continue;
147  }
148 
149  // Combined ditrack system
150  e1 = sqrt(cand1->momentum().Mag2() + firstTrackMass2);
151  e2 = sqrt(cand2->momentum().Mag2() + secondTrackMass2);
152  p1 = Particle::LorentzVector(cand1->px(), cand1->py(), cand1->pz(), e1);
153  p2 = Particle::LorentzVector(cand2->px(), cand2->py(), cand2->pz(), e2);
154  p = p1 + p2;
155 
156  if (p.pt() < minPtPair_)
157  continue;
158 
159  double invmass = abs(p.mass());
160  LogDebug("HLTDisplacedtktkVtxProducer") << " ... 1-2 invmass= " << invmass;
161 
162  if (invmass < minInvMass_)
163  continue;
164  if (invmass > maxInvMass_)
165  continue;
166 
167  // do the vertex fit
168  vector<TransientTrack> t_tks;
169  TransientTrack ttkp1 = (*theB).build(&tk1);
170  TransientTrack ttkp2 = (*theB).build(&tk2);
171  t_tks.push_back(ttkp1);
172  t_tks.push_back(ttkp2);
173 
174  if (t_tks.size() != 2)
175  continue;
176 
177  KalmanVertexFitter kvf;
178  TransientVertex tv = kvf.vertex(t_tks);
179 
180  if (!tv.isValid())
181  continue;
182 
183  Vertex vertex = tv;
184 
185  // put vertex in the event
186  vertexCollection->push_back(vertex);
187  }
188  }
189  iEvent.put(std::move(vertexCollection));
190 }
191 
193  const vector<RecoChargedCandidateRef>& refVect) const {
194  bool ok = false;
195  for (auto& i : refVect) {
196  if (i->get<TrackRef>() == trackref) {
197  ok = true;
198  break;
199  }
200  }
201  return ok;
202 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
const edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > transientTrackRecordToken_
~HLTDisplacedtktkVtxProducer() override
const TString p2
Definition: fwPaths.cc:13
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
void produce(edm::Event &, const edm::EventSetup &) override
std::vector< Vertex > VertexCollection
Definition: Vertex.h:12
tuple vertexCollection
CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &tracks) const override
int iEvent
Definition: GenABIO.cc:224
T sqrt(T t)
Definition: SSEVec.h:19
def move
Definition: eostools.py:511
const TString p1
Definition: fwPaths.cc:12
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:232
ParameterDescriptionBase * add(U const &iLabel, T const &value)
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)
const edm::EDGetTokenT< trigger::TriggerFilterObjectWithRefs > previousCandToken_
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:157
const edm::EDGetTokenT< reco::RecoChargedCandidateCollection > srcToken_
bool isValid() const
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
bool checkPreviousCand(const reco::TrackRef &trackref, const std::vector< reco::RecoChargedCandidateRef > &ref2) const
math::PtEtaPhiELorentzVectorF LorentzVector
#define LogDebug(id)