CMS 3D CMS Logo

L1TkFastVertexProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 //
4 // Original Author: Emmanuelle Perez,40 1-A28,+41227671915,
5 // Created: Tue Nov 12 17:03:19 CET 2013
6 // $Id$
7 //
8 //
9 // system include files
10 #include <memory>
11 #include <string>
12 
13 // user include files
16 
23 
25 
27 // DETECTOR GEOMETRY HEADERS
29 
32 
34 
36 // HepMC products
40 
41 #include "TH1F.h"
42 
43 using namespace l1t;
44 
45 //
46 // class declaration
47 //
48 
50 public:
52  typedef std::vector<L1TTTrackType> L1TTTrackCollectionType;
53 
55  ~L1TkFastVertexProducer() override;
56 
57  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
58 
59 private:
60  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
61 
62  // ----------member data ---------------------------
63 
64  float zMax_; // in cm
65  float DeltaZ; // in cm
66  float chi2Max_;
67  float pTMinTra_; // in GeV
68 
69  float pTMax_; // in GeV, saturation / truncation value
70  int highPtTracks_; // saturate or truncate
71 
72  int nVtx_; // the number of vertices to return
73  int nStubsmin_; // minimum number of stubs
74  int nStubsPSmin_; // minimum number of stubs in PS modules
75 
76  int nBinning_; // number of bins used in the temp histogram
77 
79  //const StackedTrackerGeometry* theStackedGeometry;
80 
81  bool doPtComp_;
83 
84  int weight_; // weight (power) of pT 0 , 1, 2
85 
86  constexpr static float xmin_ = -30;
87  constexpr static float xmax_ = +30;
88 
93 };
94 
95 //
96 // constants, enums and typedefs
97 //
98 
99 //
100 // static data member definitions
101 //
102 
103 //
104 // constructors and destructor
105 //
107  : hepmcToken_(consumes<edm::HepMCProduct>(iConfig.getParameter<edm::InputTag>("HepMCInputTag"))),
108  genparticleToken_(
109  consumes<std::vector<reco::GenParticle> >(iConfig.getParameter<edm::InputTag>("GenParticleInputTag"))),
110  trackToken_(consumes<std::vector<TTTrack<Ref_Phase2TrackerDigi_> > >(
111  iConfig.getParameter<edm::InputTag>("L1TrackInputTag"))),
113  zMax_ = (float)iConfig.getParameter<double>("ZMAX");
114  chi2Max_ = (float)iConfig.getParameter<double>("CHI2MAX");
115  pTMinTra_ = (float)iConfig.getParameter<double>("PTMINTRA");
116 
117  pTMax_ = (float)iConfig.getParameter<double>("PTMAX");
118  highPtTracks_ = iConfig.getParameter<int>("HighPtTracks");
119 
120  nVtx_ = iConfig.getParameter<int>("nVtx");
121  nStubsmin_ = iConfig.getParameter<int>("nStubsmin");
122  nStubsPSmin_ = iConfig.getParameter<int>("nStubsPSmin");
123  nBinning_ = iConfig.getParameter<int>("nBinning");
124 
125  monteCarloVertex_ = iConfig.getParameter<bool>("MonteCarloVertex");
126  doPtComp_ = iConfig.getParameter<bool>("doPtComp");
127  doTightChi2_ = iConfig.getParameter<bool>("doTightChi2");
128 
129  weight_ = iConfig.getParameter<int>("WEIGHT");
130 
131  produces<TkPrimaryVertexCollection>();
132 }
133 
135  // do anything here that needs to be done at desctruction time
136  // (e.g. close files, deallocate resources etc.)
137 }
138 
139 //
140 // member functions
141 //
142 
143 // ------------ method called to produce the data ------------
145  using namespace edm;
146 
147  auto result = std::make_unique<TkPrimaryVertexCollection>();
148 
149  // Tracker Topology
151  const TrackerTopology* tTopo = tTopoHandle.product();
152 
153  TH1F htmp("htmp", ";z (cm); Tracks", nBinning_, xmin_, xmax_);
154  TH1F htmp_weight("htmp_weight", ";z (cm); Tracks", nBinning_, xmin_, xmax_);
155 
156  // ----------------------------------------------------------------------
157 
158  if (monteCarloVertex_) {
159  // MC info ... retrieve the zvertex
161  iEvent.getByToken(hepmcToken_, HepMCEvt);
162 
163  edm::Handle<std::vector<reco::GenParticle> > GenParticleHandle;
164  iEvent.getByToken(genparticleToken_, GenParticleHandle);
165 
166  const double mm = 0.1;
167  float zvtx_gen = -999;
168 
169  if (HepMCEvt.isValid()) {
170  // using HepMCEvt
171 
172  const HepMC::GenEvent* MCEvt = HepMCEvt->GetEvent();
173  for (HepMC::GenEvent::vertex_const_iterator ivertex = MCEvt->vertices_begin(); ivertex != MCEvt->vertices_end();
174  ++ivertex) {
175  bool hasParentVertex = false;
176 
177  // Loop over the parents looking to see if they are coming from a production vertex
178  for (HepMC::GenVertex::particle_iterator iparent = (*ivertex)->particles_begin(HepMC::parents);
179  iparent != (*ivertex)->particles_end(HepMC::parents);
180  ++iparent)
181  if ((*iparent)->production_vertex()) {
182  hasParentVertex = true;
183  break;
184  }
185 
186  // Reject those vertices with parent vertices
187  if (hasParentVertex)
188  continue;
189  // Get the position of the vertex
190  HepMC::FourVector pos = (*ivertex)->position();
191  zvtx_gen = pos.z() * mm;
192  break; // there should be one single primary vertex
193  } // end loop over gen vertices
194 
195  } else if (GenParticleHandle.isValid()) {
196  for (const auto& genpart : *GenParticleHandle) {
197  int status = genpart.status();
198  if (status != 3)
199  continue;
200  if (genpart.numberOfMothers() == 0)
201  continue; // the incoming hadrons
202  float part_zvertex = genpart.vz();
203  zvtx_gen = part_zvertex;
204  break; //
205  }
206  } else {
207  throw cms::Exception("L1TkFastVertexProducer")
208  << "\nerror: try to retrieve the MC vertex (monteCarloVertex_ = True) "
209  << "\nbut the input file contains neither edm::HepMCProduct> nor vector<reco::GenParticle>. Exit"
210  << std::endl;
211  }
212 
213  TkPrimaryVertex genvtx(zvtx_gen, -999.);
214 
215  result->push_back(genvtx);
216  iEvent.put(std::move(result));
217  return;
218  }
219 
220  edm::Handle<L1TTTrackCollectionType> L1TTTrackHandle;
221  iEvent.getByToken(trackToken_, L1TTTrackHandle);
222 
223  if (!L1TTTrackHandle.isValid()) {
224  throw cms::Exception("L1TkFastVertexProducer")
225  << "\nWarning: L1TkTrackCollection with not found in the event. Exit" << std::endl;
226  return;
227  }
228 
229  for (const auto& track : *L1TTTrackHandle) {
230  float z = track.POCA().z();
231  float chi2 = track.chi2();
232  float pt = track.momentum().perp();
233  float eta = track.momentum().eta();
234 
235  //..............................................................
236  float wt = pow(pt, weight_); // calculating the weight for tks in as pt^0,pt^1 or pt^2 based on weight_
237 
238  if (std::abs(z) > zMax_)
239  continue;
240  if (chi2 > chi2Max_)
241  continue;
242  if (pt < pTMinTra_)
243  continue;
244 
245  // saturation or truncation :
246  if (pTMax_ > 0 && pt > pTMax_) {
247  if (highPtTracks_ == 0)
248  continue; // ignore this track
249  if (highPtTracks_ == 1)
250  pt = pTMax_; // saturate
251  }
252 
253  // get the number of stubs and the number of stubs in PS layers
254  float nPS = 0.; // number of stubs in PS modules
255  float nstubs = 0;
256 
257  // get pointers to stubs associated to the L1 track
258  const std::vector<edm::Ref<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_> >, TTStub<Ref_Phase2TrackerDigi_> > >&
259  theStubs = track.getStubRefs();
260 
261  int tmp_trk_nstub = (int)theStubs.size();
262  if (tmp_trk_nstub < 0) {
263  LogTrace("L1TkFastVertexProducer")
264  << " ... could not retrieve the vector of stubs in L1TkFastVertexProducer::SumPtVertex " << std::endl;
265  continue;
266  }
267 
268  // loop over the stubs
269  for (const auto& stub : theStubs) {
270  nstubs++;
271  bool isPS = false;
272  DetId detId(stub->getDetId());
273  if (detId.det() == DetId::Detector::Tracker) {
274  if (detId.subdetId() == StripSubdetector::TOB && tTopo->tobLayer(detId) <= 3)
275  isPS = true;
276  else if (detId.subdetId() == StripSubdetector::TID && tTopo->tidRing(detId) <= 9)
277  isPS = true;
278  }
279  if (isPS)
280  nPS++;
281  } // end loop over stubs
282  if (nstubs < nStubsmin_)
283  continue;
284  if (nPS < nStubsPSmin_)
285  continue;
286 
287  // quality cuts from Louise S, based on the pt-stub compatibility (June 20, 2014)
288  int trk_nstub = (int)track.getStubRefs().size();
289  float chi2dof = chi2 / (2 * trk_nstub - 4);
290 
291  if (doPtComp_) {
292  float trk_consistency = track.stubPtConsistency();
293  if (trk_nstub == 4) {
294  if (std::abs(eta) < 2.2 && trk_consistency > 10)
295  continue;
296  else if (std::abs(eta) > 2.2 && chi2dof > 5.0)
297  continue;
298  }
299  }
300  if (doTightChi2_) {
301  if (pt > 10.0 && chi2dof > 5.0)
302  continue;
303  }
304 
305  htmp.Fill(z);
306  htmp_weight.Fill(z, wt); // changed from "pt" to "wt" which is some power of pt (0,1 or 2)
307 
308  } // end loop over tracks
309 
310  // sliding windows... maximize bin i + i-1 + i+1
311 
312  float zvtx_sliding = -999;
313  float sigma_max = -999;
314  int imax = -999;
315  int nb = htmp.GetNbinsX();
316  for (int i = 2; i <= nb - 1; i++) {
317  float a0 = htmp.GetBinContent(i - 1);
318  float a1 = htmp.GetBinContent(i);
319  float a2 = htmp.GetBinContent(i + 1);
320  float sigma = a0 + a1 + a2;
321  if (sigma > sigma_max) {
322  sigma_max = sigma;
323  imax = i;
324  float z0 = htmp.GetBinCenter(i - 1);
325  float z1 = htmp.GetBinCenter(i);
326  float z2 = htmp.GetBinCenter(i + 1);
327  zvtx_sliding = (a0 * z0 + a1 * z1 + a2 * z2) / sigma;
328  }
329  }
330 
331  std::vector<int> found;
332  found.reserve(nVtx_);
333  for (int ivtx = 0; ivtx < nVtx_; ivtx++) {
334  zvtx_sliding = -999;
335  sigma_max = -999;
336  imax = -999;
337  for (int i = 2; i <= nb - 1; i++) {
338  float a0 = htmp_weight.GetBinContent(i - 1);
339  float a1 = htmp_weight.GetBinContent(i);
340  float a2 = htmp_weight.GetBinContent(i + 1);
341  float sigma = a0 + a1 + a2;
342  if ((sigma > sigma_max) && (find(found.begin(), found.end(), i) == found.end())) {
343  sigma_max = sigma;
344  imax = i;
345  float z0 = htmp_weight.GetBinCenter(i - 1);
346  float z1 = htmp_weight.GetBinCenter(i);
347  float z2 = htmp_weight.GetBinCenter(i + 1);
348  zvtx_sliding = (a0 * z0 + a1 * z1 + a2 * z2) / sigma;
349  }
350  }
351  found.push_back(imax);
352  TkPrimaryVertex vtx4(zvtx_sliding, sigma_max);
353  result->push_back(vtx4);
354  }
355 
356  iEvent.put(std::move(result));
357 }
358 
359 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
361  //The following says we do not know what parameters are allowed so do no validation
362  // Please change this to state exactly what you do use, even if it is no parameters
364  desc.setUnknown();
365  descriptions.addDefault(desc);
366 }
367 
368 //define this as a plug-in
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
edm::StreamID
Definition: StreamID.h:30
L1TkFastVertexProducer::monteCarloVertex_
bool monteCarloVertex_
Definition: L1TkFastVertexProducer.cc:78
mps_fire.i
i
Definition: mps_fire.py:428
TkPrimaryVertex.h
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11713
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
ESHandle.h
L1TkFastVertexProducer::nStubsPSmin_
int nStubsPSmin_
Definition: L1TkFastVertexProducer.cc:74
TTTypes.h
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
mps_update.status
status
Definition: mps_update.py:69
edm::EDGetTokenT< edm::HepMCProduct >
edm
HLT enums.
Definition: AlignableModifier.h:19
TrackerTopology
Definition: TrackerTopology.h:16
pos
Definition: PixelAliasList.h:18
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89281
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
TTTrack
Class to store the L1 Track Trigger tracks.
Definition: TTTrack.h:29
L1TkFastVertexProducer::weight_
int weight_
Definition: L1TkFastVertexProducer.cc:84
L1TkFastVertexProducer::topoToken_
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > topoToken_
Definition: L1TkFastVertexProducer.cc:92
L1TkFastVertexProducer::L1TkFastVertexProducer
L1TkFastVertexProducer(const edm::ParameterSet &)
Definition: L1TkFastVertexProducer.cc:106
L1TkFastVertexProducer::doTightChi2_
bool doTightChi2_
Definition: L1TkFastVertexProducer.cc:82
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
hltPixelTracks_cff.chi2
chi2
Definition: hltPixelTracks_cff.py:25
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
edm::Handle< edm::HepMCProduct >
GenParticle
Definition: GenParticle.py:1
ESGetToken.h
L1TkFastVertexProducer::DeltaZ
float DeltaZ
Definition: L1TkFastVertexProducer.cc:65
TrackerTopology::tidRing
unsigned int tidRing(const DetId &id) const
Definition: TrackerTopology.h:218
HepMC::GenEvent
Definition: hepmc_rootio.cc:9
edm::Ref
Definition: AssociativeIterator.h:58
L1TkFastVertexProducer::xmin_
constexpr static float xmin_
Definition: L1TkFastVertexProducer.cc:86
testProducerWithPsetDescEmpty_cfi.a2
a2
Definition: testProducerWithPsetDescEmpty_cfi.py:35
align::Tracker
Definition: StructureType.h:70
GenParticle.h
testProducerWithPsetDescEmpty_cfi.z2
z2
Definition: testProducerWithPsetDescEmpty_cfi.py:41
DetId
Definition: DetId.h:17
MakerMacros.h
TrackerTopology.h
L1TkFastVertexProducer::pTMinTra_
float pTMinTra_
Definition: L1TkFastVertexProducer.cc:67
TrackerTopologyRcd.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
L1TkFastVertexProducer::nBinning_
int nBinning_
Definition: L1TkFastVertexProducer.cc:76
PVValHelper::eta
Definition: PVValidationHelpers.h:70
L1TkFastVertexProducer::nStubsmin_
int nStubsmin_
Definition: L1TkFastVertexProducer.cc:73
fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
TTStub
Class to store the L1 Track Trigger stubs.
Definition: TTStub.h:22
DDAxes::z
edm::ESHandle< TrackerTopology >
L1TkFastVertexProducer::trackToken_
const edm::EDGetTokenT< std::vector< TTTrack< Ref_Phase2TrackerDigi_ > > > trackToken_
Definition: L1TkFastVertexProducer.cc:91
HLTMuonOfflineAnalyzer_cfi.z0
z0
Definition: HLTMuonOfflineAnalyzer_cfi.py:98
edm::global::EDProducer
Definition: EDProducer.h:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
edm::ParameterSet
Definition: ParameterSet.h:47
L1TkFastVertexProducer::genparticleToken_
const edm::EDGetTokenT< std::vector< reco::GenParticle > > genparticleToken_
Definition: L1TkFastVertexProducer.cc:90
Event.h
L1TkFastVertexProducer::nVtx_
int nVtx_
Definition: L1TkFastVertexProducer.cc:72
L1TkFastVertexProducer::L1TTTrackType
TTTrack< Ref_Phase2TrackerDigi_ > L1TTTrackType
Definition: L1TkFastVertexProducer.cc:51
l1t
delete x;
Definition: CaloConfig.h:22
L1TkFastVertexProducer::highPtTracks_
int highPtTracks_
Definition: L1TkFastVertexProducer.cc:70
L1TkFastVertexProducer::pTMax_
float pTMax_
Definition: L1TkFastVertexProducer.cc:69
L1TkFastVertexProducer::~L1TkFastVertexProducer
~L1TkFastVertexProducer() override
Definition: L1TkFastVertexProducer.cc:134
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::EventSetup::getHandle
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:155
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
MagneticField.h
edm::EventSetup
Definition: EventSetup.h:58
edm::HepMCProduct::GetEvent
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:37
L1TkFastVertexProducer::xmax_
constexpr static float xmax_
Definition: L1TkFastVertexProducer.cc:87
L1TkFastVertexProducer::zMax_
float zMax_
Definition: L1TkFastVertexProducer.cc:64
l1t::TkPrimaryVertex
Definition: TkPrimaryVertex.h:14
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd >
TrackerTopology::tobLayer
unsigned int tobLayer(const DetId &id) const
Definition: TrackerTopology.h:147
L1TkFastVertexProducer::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition: L1TkFastVertexProducer.cc:144
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
L1TkFastVertexProducer::hepmcToken_
const edm::EDGetTokenT< edm::HepMCProduct > hepmcToken_
Definition: L1TkFastVertexProducer.cc:89
Frameworkfwd.h
Exception
Definition: hltDiff.cc:245
StripSubdetector::TOB
static constexpr auto TOB
Definition: StripSubdetector.h:18
EventSetup.h
L1TkFastVertexProducer::chi2Max_
float chi2Max_
Definition: L1TkFastVertexProducer.cc:66
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
L1TkFastVertexProducer::doPtComp_
bool doPtComp_
Definition: L1TkFastVertexProducer.cc:81
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
HepMCProduct
L1TkFastVertexProducer
Definition: L1TkFastVertexProducer.cc:49
mps_fire.result
result
Definition: mps_fire.py:311
Candidate.h
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:234
TrackerTopologyRcd
Definition: TrackerTopologyRcd.h:10
ParameterSet.h
HepMCProduct.h
EDProducer.h
parents
TPRegexp parents
Definition: eve_filter.cc:21
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::Event
Definition: Event.h:73
L1TkFastVertexProducer::L1TTTrackCollectionType
std::vector< L1TTTrackType > L1TTTrackCollectionType
Definition: L1TkFastVertexProducer.cc:52
edm::ConfigurationDescriptions::addDefault
void addDefault(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:99
a0
static constexpr float a0
Definition: L1EGammaCrystalsEmulatorProducer.cc:82
StripSubdetector::TID
static constexpr auto TID
Definition: StripSubdetector.h:17
L1TkFastVertexProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: L1TkFastVertexProducer.cc:360