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 
21 
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 beginJob() override;
61  void produce(edm::Event&, const edm::EventSetup&) override;
62  void endJob() override;
63 
64  //virtual void beginRun(edm::Run&, edm::EventSetup const&);
65 
66  // ----------member data ---------------------------
67 
68  float zMax_; // in cm
69  float DeltaZ; // in cm
70  float chi2Max_;
71  float pTMinTra_; // in GeV
72 
73  float pTMax_; // in GeV, saturation / truncation value
74  int highPtTracks_; // saturate or truncate
75 
76  int nStubsmin_; // minimum number of stubs
77  int nStubsPSmin_; // minimum number of stubs in PS modules
78 
79  int nBinning_; // number of bins used in the temp histogram
80 
82  //const StackedTrackerGeometry* theStackedGeometry;
83 
84  bool doPtComp_;
86 
87  int weight_; // weight (power) of pT 0 , 1, 2
88 
89  TH1F* htmp_;
90  TH1F* htmp_weight_;
91 
95 };
96 
97 //
98 // constants, enums and typedefs
99 //
100 
101 //
102 // static data member definitions
103 //
104 
105 //
106 // constructors and destructor
107 //
109  : hepmcToken(consumes<edm::HepMCProduct>(iConfig.getParameter<edm::InputTag>("HepMCInputTag"))),
110  genparticleToken(
111  consumes<std::vector<reco::GenParticle> >(iConfig.getParameter<edm::InputTag>("GenParticleInputTag"))),
112  trackToken(consumes<std::vector<TTTrack<Ref_Phase2TrackerDigi_> > >(
113  iConfig.getParameter<edm::InputTag>("L1TrackInputTag"))) {
114  zMax_ = (float)iConfig.getParameter<double>("ZMAX");
115  chi2Max_ = (float)iConfig.getParameter<double>("CHI2MAX");
116  pTMinTra_ = (float)iConfig.getParameter<double>("PTMINTRA");
117 
118  pTMax_ = (float)iConfig.getParameter<double>("PTMAX");
119  highPtTracks_ = iConfig.getParameter<int>("HighPtTracks");
120 
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  int nbins = nBinning_; // should be odd
132  float xmin = -30;
133  float xmax = +30;
134 
135  htmp_ = new TH1F("htmp_", ";z (cm); Tracks", nbins, xmin, xmax);
136  htmp_weight_ = new TH1F("htmp_weight_", ";z (cm); Tracks", nbins, xmin, xmax);
137 
138  produces<TkPrimaryVertexCollection>();
139 }
140 
142  // do anything here that needs to be done at desctruction time
143  // (e.g. close files, deallocate resources etc.)
144 }
145 
146 //
147 // member functions
148 //
149 
150 // ------------ method called to produce the data ------------
152  using namespace edm;
153 
154  std::unique_ptr<TkPrimaryVertexCollection> result(new TkPrimaryVertexCollection);
155 
156  // Tracker Topology
157  edm::ESHandle<TrackerTopology> tTopoHandle_;
158  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle_);
159  const TrackerTopology* tTopo = tTopoHandle_.product();
160 
161  htmp_->Reset();
162  htmp_weight_->Reset();
163 
164  // ----------------------------------------------------------------------
165 
166  if (monteCarloVertex_) {
167  // MC info ... retrieve the zvertex
169  iEvent.getByToken(hepmcToken, HepMCEvt);
170 
171  edm::Handle<std::vector<reco::GenParticle> > GenParticleHandle;
172  iEvent.getByToken(genparticleToken, GenParticleHandle);
173 
174  const double mm = 0.1;
175  float zvtx_gen = -999;
176 
177  if (HepMCEvt.isValid()) {
178  // using HepMCEvt
179 
180  const HepMC::GenEvent* MCEvt = HepMCEvt->GetEvent();
181  for (HepMC::GenEvent::vertex_const_iterator ivertex = MCEvt->vertices_begin(); ivertex != MCEvt->vertices_end();
182  ++ivertex) {
183  bool hasParentVertex = false;
184 
185  // Loop over the parents looking to see if they are coming from a production vertex
186  for (HepMC::GenVertex::particle_iterator iparent = (*ivertex)->particles_begin(HepMC::parents);
187  iparent != (*ivertex)->particles_end(HepMC::parents);
188  ++iparent)
189  if ((*iparent)->production_vertex()) {
190  hasParentVertex = true;
191  break;
192  }
193 
194  // Reject those vertices with parent vertices
195  if (hasParentVertex)
196  continue;
197  // Get the position of the vertex
198  HepMC::FourVector pos = (*ivertex)->position();
199  zvtx_gen = pos.z() * mm;
200  break; // there should be one single primary vertex
201  } // end loop over gen vertices
202 
203  } else if (GenParticleHandle.isValid()) {
204  std::vector<reco::GenParticle>::const_iterator genpartIter;
205  for (genpartIter = GenParticleHandle->begin(); genpartIter != GenParticleHandle->end(); ++genpartIter) {
206  int status = genpartIter->status();
207  if (status != 3)
208  continue;
209  if (genpartIter->numberOfMothers() == 0)
210  continue; // the incoming hadrons
211  float part_zvertex = genpartIter->vz();
212  zvtx_gen = part_zvertex;
213  break; //
214  }
215  } else {
216  throw cms::Exception("L1TkFastVertexProducer")
217  << "\nerror: try to retrieve the MC vertex (monteCarloVertex_ = True) "
218  << "\nbut the input file contains neither edm::HepMCProduct> nor vector<reco::GenParticle>. Exit"
219  << std::endl;
220  }
221 
222  // std::cout<<zvtx_gen<<endl;
223 
224  TkPrimaryVertex genvtx(zvtx_gen, -999.);
225 
226  result->push_back(genvtx);
227  iEvent.put(std::move(result));
228  return;
229  }
230 
231  edm::Handle<L1TTTrackCollectionType> L1TTTrackHandle;
232  iEvent.getByToken(trackToken, L1TTTrackHandle);
233 
234  if (!L1TTTrackHandle.isValid()) {
235  throw cms::Exception("L1TkFastVertexProducer")
236  << "\nWarning: L1TkTrackCollection with not found in the event. Exit" << std::endl;
237  return;
238  }
239 
240  L1TTTrackCollectionType::const_iterator trackIter;
241  for (trackIter = L1TTTrackHandle->begin(); trackIter != L1TTTrackHandle->end(); ++trackIter) {
242  float z = trackIter->POCA().z();
243  float chi2 = trackIter->chi2();
244  float pt = trackIter->momentum().perp();
245  float eta = trackIter->momentum().eta();
246 
247  //..............................................................
248  float wt = pow(pt, weight_); // calculating the weight for tks in as pt^0,pt^1 or pt^2 based on weight_
249 
250  if (std::abs(z) > zMax_)
251  continue;
252  if (chi2 > chi2Max_)
253  continue;
254  if (pt < pTMinTra_)
255  continue;
256 
257  // saturation or truncation :
258  if (pTMax_ > 0 && pt > pTMax_) {
259  if (highPtTracks_ == 0)
260  continue; // ignore this track
261  if (highPtTracks_ == 1)
262  pt = pTMax_; // saturate
263  }
264 
265  // get the number of stubs and the number of stubs in PS layers
266  float nPS = 0.; // number of stubs in PS modules
267  float nstubs = 0;
268 
269  // get pointers to stubs associated to the L1 track
270  const std::vector<edm::Ref<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_> >, TTStub<Ref_Phase2TrackerDigi_> > >&
271  theStubs = trackIter->getStubRefs();
272 
273  int tmp_trk_nstub = (int)theStubs.size();
274  if (tmp_trk_nstub < 0) {
275  LogTrace("L1TkFastVertexProducer")
276  << " ... could not retrieve the vector of stubs in L1TkFastVertexProducer::SumPtVertex " << std::endl;
277  continue;
278  }
279 
280  // loop over the stubs
281  for (unsigned int istub = 0; istub < (unsigned int)theStubs.size(); istub++) {
282  nstubs++;
283  bool isPS = false;
284  DetId detId(theStubs.at(istub)->getDetId());
285  if (detId.det() == DetId::Detector::Tracker) {
286  if (detId.subdetId() == StripSubdetector::TOB && tTopo->tobLayer(detId) <= 3)
287  isPS = true;
288  else if (detId.subdetId() == StripSubdetector::TID && tTopo->tidRing(detId) <= 9)
289  isPS = true;
290  }
291  if (isPS)
292  nPS++;
293  } // end loop over stubs
294  if (nstubs < nStubsmin_)
295  continue;
296  if (nPS < nStubsPSmin_)
297  continue;
298 
299  // quality cuts from Louise S, based on the pt-stub compatibility (June 20, 2014)
300  int trk_nstub = (int)trackIter->getStubRefs().size();
301  float chi2dof = chi2 / (2 * trk_nstub - 4);
302 
303  if (doPtComp_) {
304  float trk_consistency = trackIter->stubPtConsistency();
305  //if (trk_nstub < 4) continue; // done earlier
306  //if (chi2 > 100.0) continue; // done earlier
307  if (trk_nstub == 4) {
308  if (std::abs(eta) < 2.2 && trk_consistency > 10)
309  continue;
310  else if (std::abs(eta) > 2.2 && chi2dof > 5.0)
311  continue;
312  }
313  }
314  if (doTightChi2_) {
315  if (pt > 10.0 && chi2dof > 5.0)
316  continue;
317  }
318 
319  htmp_->Fill(z);
320  htmp_weight_->Fill(z, wt); // changed from "pt" to "wt" which is some power of pt (0,1 or 2)
321 
322  } // end loop over tracks
323 
324  // sliding windows... maximize bin i + i-1 + i+1
325 
326  float zvtx_sliding = -999;
327  float sigma_max = -999;
328  int nb = htmp_->GetNbinsX();
329  for (int i = 2; i <= nb - 1; i++) {
330  float a0 = htmp_->GetBinContent(i - 1);
331  float a1 = htmp_->GetBinContent(i);
332  float a2 = htmp_->GetBinContent(i + 1);
333  float sigma = a0 + a1 + a2;
334  if (sigma > sigma_max) {
335  sigma_max = sigma;
336  float z0 = htmp_->GetBinCenter(i - 1);
337  float z1 = htmp_->GetBinCenter(i);
338  float z2 = htmp_->GetBinCenter(i + 1);
339  zvtx_sliding = (a0 * z0 + a1 * z1 + a2 * z2) / sigma;
340  }
341  }
342 
343  zvtx_sliding = -999;
344  sigma_max = -999;
345  for (int i = 2; i <= nb - 1; i++) {
346  float a0 = htmp_weight_->GetBinContent(i - 1);
347  float a1 = htmp_weight_->GetBinContent(i);
348  float a2 = htmp_weight_->GetBinContent(i + 1);
349  float sigma = a0 + a1 + a2;
350  if (sigma > sigma_max) {
351  sigma_max = sigma;
352  float z0 = htmp_weight_->GetBinCenter(i - 1);
353  float z1 = htmp_weight_->GetBinCenter(i);
354  float z2 = htmp_weight_->GetBinCenter(i + 1);
355  zvtx_sliding = (a0 * z0 + a1 * z1 + a2 * z2) / sigma;
356  }
357  }
358 
359  TkPrimaryVertex vtx4(zvtx_sliding, sigma_max);
360 
361  result->push_back(vtx4);
362 
363  iEvent.put(std::move(result));
364 }
365 
366 // ------------ method called once each job just before starting event loop ------------
368 
369 // ------------ method called once each job just after ending the event loop ------------
371 
372 // ------------ method called when starting to processes a run ------------
373 //void L1TkFastVertexProducer::beginRun(edm::Run& iRun, edm::EventSetup const& iSetup) {}
374 
375 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
377  //The following says we do not know what parameters are allowed so do no validation
378  // Please change this to state exactly what you do use, even if it is no parameters
380  desc.setUnknown();
381  descriptions.addDefault(desc);
382 }
383 
384 //define this as a plug-in
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
bk::beginJob
void beginJob()
Definition: Breakpoints.cc:14
L1TkFastVertexProducer::monteCarloVertex_
bool monteCarloVertex_
Definition: L1TkFastVertexProducer.cc:81
mps_fire.i
i
Definition: mps_fire.py:355
TkPrimaryVertex.h
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
EDProducer.h
ESHandle.h
L1TkFastVertexProducer::nStubsPSmin_
int nStubsPSmin_
Definition: L1TkFastVertexProducer.cc:77
TTTypes.h
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
mps_update.status
status
Definition: mps_update.py:69
edm::EDGetTokenT< edm::HepMCProduct >
L1TkFastVertexProducer::beginJob
void beginJob() override
Definition: L1TkFastVertexProducer.cc:367
edm
HLT enums.
Definition: AlignableModifier.h:19
TrackerTopology
Definition: TrackerTopology.h:16
pos
Definition: PixelAliasList.h:18
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
L1TkFastVertexProducer::trackToken
const edm::EDGetTokenT< std::vector< TTTrack< Ref_Phase2TrackerDigi_ > > > trackToken
Definition: L1TkFastVertexProducer.cc:94
TTTrack
Class to store the L1 Track Trigger tracks.
Definition: TTTrack.h:26
L1TkFastVertexProducer::weight_
int weight_
Definition: L1TkFastVertexProducer.cc:87
L1TkFastVertexProducer::L1TkFastVertexProducer
L1TkFastVertexProducer(const edm::ParameterSet &)
Definition: L1TkFastVertexProducer.cc:108
L1TkFastVertexProducer::doTightChi2_
bool doTightChi2_
Definition: L1TkFastVertexProducer.cc:85
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
L1TkFastVertexProducer::hepmcToken
const edm::EDGetTokenT< edm::HepMCProduct > hepmcToken
Definition: L1TkFastVertexProducer.cc:92
hltPixelTracks_cff.chi2
chi2
Definition: hltPixelTracks_cff.py:25
edm::Handle< edm::HepMCProduct >
GenParticle
Definition: GenParticle.py:1
L1TkFastVertexProducer::DeltaZ
float DeltaZ
Definition: L1TkFastVertexProducer.cc:69
L1TkFastVertexProducer::htmp_
TH1F * htmp_
Definition: L1TkFastVertexProducer.cc:89
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
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::htmp_weight_
TH1F * htmp_weight_
Definition: L1TkFastVertexProducer.cc:90
L1TkFastVertexProducer::pTMinTra_
float pTMinTra_
Definition: L1TkFastVertexProducer.cc:71
TrackerTopologyRcd.h
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
L1TkFastVertexProducer::nBinning_
int nBinning_
Definition: L1TkFastVertexProducer.cc:79
l1t::TkPrimaryVertexCollection
std::vector< TkPrimaryVertex > TkPrimaryVertexCollection
Definition: TkPrimaryVertex.h:28
PVValHelper::eta
Definition: PVValidationHelpers.h:69
L1TkFastVertexProducer::nStubsmin_
int nStubsmin_
Definition: L1TkFastVertexProducer.cc:76
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 >
LaserClient_cfi.nbins
nbins
Definition: LaserClient_cfi.py:51
HLTMuonOfflineAnalyzer_cfi.z0
z0
Definition: HLTMuonOfflineAnalyzer_cfi.py:98
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
L1TkFastVertexProducer::L1TTTrackType
TTTrack< Ref_Phase2TrackerDigi_ > L1TTTrackType
Definition: L1TkFastVertexProducer.cc:51
l1t
delete x;
Definition: CaloConfig.h:22
L1TkFastVertexProducer::highPtTracks_
int highPtTracks_
Definition: L1TkFastVertexProducer.cc:74
L1TkFastVertexProducer::endJob
void endJob() override
Definition: L1TkFastVertexProducer.cc:370
L1TkFastVertexProducer::pTMax_
float pTMax_
Definition: L1TkFastVertexProducer.cc:73
L1TkFastVertexProducer::~L1TkFastVertexProducer
~L1TkFastVertexProducer() override
Definition: L1TkFastVertexProducer.cc:141
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::ParameterSetDescription::setUnknown
void setUnknown()
Definition: ParameterSetDescription.cc:39
MagneticField.h
edm::EventSetup
Definition: EventSetup.h:57
edm::HepMCProduct::GetEvent
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:34
get
#define get
L1TkFastVertexProducer::zMax_
float zMax_
Definition: L1TkFastVertexProducer.cc:68
l1t::TkPrimaryVertex
Definition: TkPrimaryVertex.h:12
L1TkFastVertexProducer::genparticleToken
const edm::EDGetTokenT< std::vector< reco::GenParticle > > genparticleToken
Definition: L1TkFastVertexProducer.cc:93
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
TrackerTopology::tobLayer
unsigned int tobLayer(const DetId &id) const
Definition: TrackerTopology.h:147
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
Frameworkfwd.h
TrackerOfflineValidation_Dqm_cff.xmax
xmax
Definition: TrackerOfflineValidation_Dqm_cff.py:11
Exception
Definition: hltDiff.cc:246
L1TkFastVertexProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: L1TkFastVertexProducer.cc:151
StripSubdetector::TOB
static constexpr auto TOB
Definition: StripSubdetector.h:18
EventSetup.h
L1TkFastVertexProducer::chi2Max_
float chi2Max_
Definition: L1TkFastVertexProducer.cc:70
edm::EDProducer
Definition: EDProducer.h:36
L1TkFastVertexProducer::doPtComp_
bool doPtComp_
Definition: L1TkFastVertexProducer.cc:84
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30
HepMCProduct
L1TkFastVertexProducer
Definition: L1TkFastVertexProducer.cc:49
mps_fire.result
result
Definition: mps_fire.py:303
Candidate.h
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:671
TrackerTopologyRcd
Definition: TrackerTopologyRcd.h:10
ParameterSet.h
TrackerOfflineValidation_Dqm_cff.xmin
xmin
Definition: TrackerOfflineValidation_Dqm_cff.py:10
HepMCProduct.h
parents
TPRegexp parents
Definition: eve_filter.cc:21
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
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:81
StripSubdetector::TID
static constexpr auto TID
Definition: StripSubdetector.h:17
L1TkFastVertexProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: L1TkFastVertexProducer.cc:376