CMS 3D CMS Logo

HLTDisplacedtktkFilter.cc
Go to the documentation of this file.
1 #include <iostream>
2 
5 
11 
14 
20 
22 
27 
29 
30 #include "HLTDisplacedtktkFilter.h"
31 #include "TMath.h"
32 
33 //
34 // constructors and destructor
35 //
37  HLTFilter(iConfig),
38  fastAccept_ (iConfig.getParameter<bool>("FastAccept")),
39  minLxySignificance_ (iConfig.getParameter<double>("MinLxySignificance")),
40  maxLxySignificance_ (iConfig.getParameter<double>("MaxLxySignificance")),
41  maxNormalisedChi2_ (iConfig.getParameter<double>("MaxNormalisedChi2")),
42  minVtxProbability_ (iConfig.getParameter<double>("MinVtxProbability")),
43  minCosinePointingAngle_ (iConfig.getParameter<double>("MinCosinePointingAngle")),
44  triggerTypeDaughters_(iConfig.getParameter<int>("triggerTypeDaughters")),
45  DisplacedVertexTag_(iConfig.getParameter<edm::InputTag>("DisplacedVertexTag")),
46  DisplacedVertexToken_(consumes<reco::VertexCollection>(DisplacedVertexTag_)),
47  beamSpotTag_ (iConfig.getParameter<edm::InputTag> ("BeamSpotTag")),
48  beamSpotToken_(consumes<reco::BeamSpot>(beamSpotTag_)),
49  TrackTag_ (iConfig.getParameter<edm::InputTag>("TrackTag")),
50  TrackToken_(consumes<reco::RecoChargedCandidateCollection>(TrackTag_))
51 {
52 }
53 
54 
56 
60  desc.add<bool>("FastAccept",false);
61  desc.add<double>("MinLxySignificance",0.0);
62  desc.add<double>("MaxLxySignificance",0.0);
63  desc.add<double>("MaxNormalisedChi2",10.0);
64  desc.add<double>("MinVtxProbability",0.0);
65  desc.add<double>("MinCosinePointingAngle",-2.0);
66  desc.add<int>("triggerTypeDaughters",0);
67  desc.add<edm::InputTag>("DisplacedVertexTag",edm::InputTag("hltDisplacedtktkVtx"));
68  desc.add<edm::InputTag>("BeamSpotTag",edm::InputTag("hltOnlineBeamSpot"));
69  desc.add<edm::InputTag>("TrackTag",edm::InputTag("hltL3MuonCandidates"));
70  descriptions.add("hltDisplacedtktkFilter", desc);
71  }
72 
73 // ------------ method called once each job just before starting event loop ------------
75 {
76 
77 }
78 
79 // ------------ method called once each job just after ending the event loop ------------
81 {
82 
83 }
84 
85 // ------------ method called on each new Event ------------
87 {
88 
89 
90  // get beam spot
91  reco::BeamSpot vertexBeamSpot;
92  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
93  iEvent.getByToken(beamSpotToken_,recoBeamSpotHandle);
94  vertexBeamSpot = *recoBeamSpotHandle;
95 
96 
97  // get displaced vertices
98  reco::VertexCollection displacedVertexColl;
99  edm::Handle<reco::VertexCollection> displacedVertexCollHandle;
100  bool foundVertexColl = iEvent.getByToken(DisplacedVertexToken_, displacedVertexCollHandle);
101  if(foundVertexColl) displacedVertexColl = *displacedVertexCollHandle;
102 
103 
104  // get track collection
106  iEvent.getByToken(TrackToken_,trackcands);
107 
108  // All HLT filters must create and fill an HLT filter object,
109  // recording any reconstructed physics objects satisfying (or not)
110  // this HLT filter, and place it in the Event.
111 
112 
113  // Ref to Candidate object to be recorded in filter object
116 
117  if (saveTags()) filterproduct.addCollectionTag(TrackTag_);
118 
119  bool triggered = false;
120 
121  // loop over vertex collection
122  for(auto displacedVertex : displacedVertexColl){
123  // check if the vertex actually consists of exactly two track tracks, reject the event if not
124  if(displacedVertex.tracksSize() != 2){
125  edm::LogError("HLTDisplacedtktkFilter") << "HLTDisplacedtktkFilter: ERROR: the Jpsi vertex must have exactly two tracks by definition. It now has n tracks = "<< displacedVertex.tracksSize() << std::endl;
126  return false;
127  }
128 
129  float normChi2 = displacedVertex.normalizedChi2();
130  if (normChi2 > maxNormalisedChi2_) continue;
131 
132  double vtxProb = 0.0;
133  if( (displacedVertex.chi2()>=0.0) && (displacedVertex.ndof()>0) ) vtxProb = TMath::Prob(displacedVertex.chi2(), displacedVertex.ndof() );
134  if (vtxProb < minVtxProbability_) continue;
135 
136  // get the two tracks from the vertex
137  auto trackIt = displacedVertex.tracks_begin();
138  reco::TrackRef vertextkRef1 = (*trackIt).castTo<reco::TrackRef>() ;
139  // the second one
140  trackIt++;
141  reco::TrackRef vertextkRef2 = (*trackIt).castTo<reco::TrackRef>();
142 
143  // first find these two tracks in the track collection
144  reco::RecoChargedCandidateCollection::const_iterator cand1;
145  reco::RecoChargedCandidateCollection::const_iterator cand2;
146 
147  int iFoundRefs = 0;
148  for (auto cand=trackcands->begin(); cand!=trackcands->end(); cand++) {
149  reco::TrackRef tkRef = cand->get<reco::TrackRef>();
150  if(tkRef == vertextkRef1) {cand1 = cand; iFoundRefs++;}
151  if(tkRef == vertextkRef2) {cand2 = cand; iFoundRefs++;}
152  }
153 
154  if(iFoundRefs < 2){
155  edm::LogError("HLTDisplacedtktkFilter") << "HLTDisplacedtktkFilter: ERROR: the tracks matched with the Jpsi vertex tracks should be at least two by definition." << std::endl;
156  return false;
157  }
158  // calculate two-track transverse momentum
159  math::XYZVector pperp(cand1->px() + cand2->px(),
160  cand1->py() + cand2->py(),
161  0.);
162 
163 
164  const reco::Vertex::Point& vpoint=displacedVertex.position();
165  //translate to global point, should be improved
166  GlobalPoint secondaryVertex (vpoint.x(), vpoint.y(), vpoint.z());
167 
168  reco::Vertex::Error verr = displacedVertex.error();
169  // translate to global error, should be improved
170  GlobalError err(verr.At(0,0), verr.At(1,0), verr.At(1,1), verr.At(2,0), verr.At(2,1), verr.At(2,2) );
171 
172  GlobalPoint displacementFromBeamspot( -1*((vertexBeamSpot.x0() - secondaryVertex.x()) + (secondaryVertex.z() - vertexBeamSpot.z0()) * vertexBeamSpot.dxdz()),
173  -1*((vertexBeamSpot.y0() - secondaryVertex.y())+ (secondaryVertex.z() - vertexBeamSpot.z0()) * vertexBeamSpot.dydz()), 0);
174 
175  float lxy = displacementFromBeamspot.perp();
176  float lxyerr = sqrt(err.rerr(displacementFromBeamspot));
177 
178 
179  //calculate the angle between the decay length and the tktk momentum
180  reco::Vertex::Point vperp(displacementFromBeamspot.x(),displacementFromBeamspot.y(),0.);
181 
182  float cosAlpha = vperp.Dot(pperp)/(vperp.R()*pperp.R());
183 
184  // check thresholds
185  if (cosAlpha < minCosinePointingAngle_) continue;
186  if (minLxySignificance_ > 0. && lxy/lxyerr < minLxySignificance_) continue;
187  if (maxLxySignificance_ > 0. && lxy/lxyerr > maxLxySignificance_) continue;
188  triggered = true;
189 
190  // now add the tracks that passed to the filter object
191 
192  ref1=reco::RecoChargedCandidateRef( edm::Ref<reco::RecoChargedCandidateCollection> (trackcands,distance(trackcands->begin(), cand1)));
193  filterproduct.addObject(triggerTypeDaughters_,ref1);
194 
195  ref2=reco::RecoChargedCandidateRef( edm::Ref<reco::RecoChargedCandidateCollection> (trackcands,distance(trackcands->begin(),cand2 )));
196  filterproduct.addObject(triggerTypeDaughters_,ref2);
197  }
198 
199  LogDebug("HLTDisplacedtktkFilter") << " >>>>> Result of HLTDisplacedtktkFilter is "<< triggered <<std::endl;
200 
201  return triggered;
202 }
#define LogDebug(id)
double z0() const
z coordinate
Definition: BeamSpot.h:68
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
edm::Ref< RecoChargedCandidateCollection > RecoChargedCandidateRef
reference to an object in a collection of RecoChargedCandidate objects
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:43
bool hltFilter(edm::Event &, const edm::EventSetup &, trigger::TriggerFilterObjectWithRefs &filterproduct) const override
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
edm::EDGetTokenT< reco::VertexCollection > DisplacedVertexToken_
~HLTDisplacedtktkFilter() override
void addObject(int id, const reco::RecoEcalCandidateRef &ref)
setters for L3 collections: (id=physics type, and Ref<C>)
double dydz() const
dydz slope
Definition: BeamSpot.h:84
int iEvent
Definition: GenABIO.cc:224
HLTDisplacedtktkFilter(const edm::ParameterSet &)
T sqrt(T t)
Definition: SSEVec.h:18
math::XYZPoint Point
point in the space
Definition: Vertex.h:39
ParameterDescriptionBase * add(U const &iLabel, T const &value)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
double dxdz() const
dxdz slope
Definition: BeamSpot.h:82
std::vector< RecoChargedCandidate > RecoChargedCandidateCollection
collectin of RecoChargedCandidate objects
static void makeHLTFilterDescription(edm::ParameterSetDescription &desc)
Definition: HLTFilter.cc:29
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
void addCollectionTag(const edm::InputTag &collectionTag)
collectionTags
void add(std::string const &label, ParameterSetDescription const &psetDescription)
fixed size matrix
bool saveTags() const
Definition: HLTFilter.h:45
HLT enums.
double y0() const
y coordinate
Definition: BeamSpot.h:66
edm::EDGetTokenT< reco::RecoChargedCandidateCollection > TrackToken_
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
double x0() const
x coordinate
Definition: BeamSpot.h:64