CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
58 }
59 
60 void
63  desc.add<edm::InputTag>("Src",edm::InputTag("hltL3MuonCandidates"));
64  desc.add<edm::InputTag>("PreviousCandTag",edm::InputTag(""));
65  desc.add<double>("MaxEta",2.5);
66  desc.add<double>("MinPt",0.0);
67  desc.add<double>("MinPtPair",0.0);
68  desc.add<double>("MinInvMass",1.0);
69  desc.add<double>("MaxInvMass",20.0);
70  desc.add<double>("massParticle1",0.1396);
71  desc.add<double>("massParticle2",0.4937);
72  desc.add<int>("ChargeOpt",-1);
73  desc.add<int>("triggerTypeDaughters",0);
74 
75  descriptions.add("hltDisplacedtktkVtxProducer", desc);
76 }
77 
78 // ------------ method called once each job just before starting event loop ------------
80 {
81 
82 }
83 
84 // ------------ method called once each job just after ending the event loop ------------
86 {
87 
88 }
89 
90 // ------------ method called on each new Event ------------
92 {
93  double const firstTrackMass = massParticle1_;
94  double const firstTrackMass2 = firstTrackMass*firstTrackMass;
95  double const secondTrackMass = massParticle2_;
96  double const secondTrackMass2 = secondTrackMass*secondTrackMass;
97 
98  // get hold of track trks
100  iEvent.getByToken(srcToken_,trackcands);
101 
102  //get the transient track builder:
104  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder",theB);
105 
106  std::auto_ptr<VertexCollection> vertexCollection(new VertexCollection());
107 
108  // look at all trackcands, check cuts and make vertices
109  double e1,e2;
111 
112  RecoChargedCandidateCollection::const_iterator cand1;
113  RecoChargedCandidateCollection::const_iterator cand2;
114 
115  // get the objects passing the previous filter
117  iEvent.getByToken(previousCandToken_,previousCands);
118 
119  vector<RecoChargedCandidateRef> vPrevCands;
120  previousCands->getObjects(triggerTypeDaughters_,vPrevCands);
121 
122  for (cand1=trackcands->begin(); cand1!=trackcands->end(); cand1++) {
123  TrackRef tk1 = cand1->get<TrackRef>();
124  LogDebug("HLTDisplacedtktkVtxProducer") << " 1st track in loop: q*pt= " << cand1->charge()*cand1->pt() << ", eta= " << cand1->eta() << ", hits= " << tk1->numberOfValidHits();
125 
126  //first check if this track passed the previous filter
127  if( ! checkPreviousCand( tk1, vPrevCands) ) continue;
128 
129  // cuts
130  if (abs(cand1->eta())>maxEta_) continue;
131  if (cand1->pt() < minPt_) continue;
132 
133 
134  cand2=trackcands->begin();
135  if(massParticle1_==massParticle2_){cand2 = cand1+1;}
136 
137  for (; cand2!=trackcands->end(); cand2++) {
138 
139  TrackRef tk2 = cand2->get<TrackRef>();
140  if(tk1==tk2) continue;
141 
142  // eta cut
143  LogDebug("HLTDisplacedtktkVtxProducer") << " 2nd track in loop: q*pt= " << cand2->charge()*cand2->pt() << ", eta= " << cand2->eta() << ", hits= " << tk2->numberOfValidHits() << ", d0= " << tk2->d0();
144  //first check if this track passed the previous filter
145  if( ! checkPreviousCand( tk2, vPrevCands) ) continue;
146 
147  // cuts
148  if (abs(cand2->eta())>maxEta_) continue;
149  if (cand2->pt() < minPt_) continue;
150 
151  // opposite sign or same sign
152  if (chargeOpt_<0) {
153  if (cand1->charge()*cand2->charge()>0) continue;
154  } else if (chargeOpt_>0) {
155  if (cand1->charge()*cand2->charge()<0) continue;
156  }
157 
158  // Combined ditrack system
159  e1 = sqrt(cand1->momentum().Mag2()+firstTrackMass2);
160  e2 = sqrt(cand2->momentum().Mag2()+secondTrackMass2);
161  p1 = Particle::LorentzVector(cand1->px(),cand1->py(),cand1->pz(),e1);
162  p2 = Particle::LorentzVector(cand2->px(),cand2->py(),cand2->pz(),e2);
163  p = p1+p2;
164 
165 
166  if (p.pt()<minPtPair_) continue;
167 
168  double invmass = abs(p.mass());
169  LogDebug("HLTDisplacedtktkVtxProducer") << " ... 1-2 invmass= " << invmass;
170 
171  if (invmass<minInvMass_) continue;
172  if (invmass>maxInvMass_) continue;
173 
174  // do the vertex fit
175  vector<TransientTrack> t_tks;
176  TransientTrack ttkp1 = (*theB).build(&tk1);
177  TransientTrack ttkp2 = (*theB).build(&tk2);
178  t_tks.push_back(ttkp1);
179  t_tks.push_back(ttkp2);
180 
181 
182  if (t_tks.size()!=2) continue;
183 
184  KalmanVertexFitter kvf;
185  TransientVertex tv = kvf.vertex(t_tks);
186 
187  if (!tv.isValid()) continue;
188 
189  Vertex vertex = tv;
190 
191  // put vertex in the event
192  vertexCollection->push_back(vertex);
193  }
194  }
195  iEvent.put(vertexCollection);
196 }
197 
198 
199 
200 bool HLTDisplacedtktkVtxProducer::checkPreviousCand(const TrackRef& trackref, vector<RecoChargedCandidateRef> & refVect){
201  bool ok=false;
202  for (unsigned int i=0; i<refVect.size(); i++) {
203  if ( refVect[i]->get<TrackRef>() == trackref ) {
204  ok=true;
205  break;
206  }
207  }
208  return ok;
209 }
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
virtual CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &tracks) const
virtual void produce(edm::Event &, const edm::EventSetup &)
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
tuple vertexCollection
bool checkPreviousCand(const reco::TrackRef &trackref, std::vector< reco::RecoChargedCandidateRef > &ref2)
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
T sqrt(T t)
Definition: SSEVec.h:48
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:242
ParameterDescriptionBase * add(U const &iLabel, T const &value)
double p2[4]
Definition: TauolaWrapper.h:90
std::vector< RecoChargedCandidate > RecoChargedCandidateCollection
collectin of RecoChargedCandidate objects
const T & get() const
Definition: EventSetup.h:55
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HLTDisplacedtktkVtxProducer(const edm::ParameterSet &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
double p1[4]
Definition: TauolaWrapper.h:89
const edm::EDGetTokenT< trigger::TriggerFilterObjectWithRefs > previousCandToken_
const edm::EDGetTokenT< reco::RecoChargedCandidateCollection > srcToken_
bool isValid() const
math::PtEtaPhiELorentzVectorF LorentzVector