CMS 3D CMS Logo

FastPrimaryVertexProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: FastPrimaryVertexProducer
4 // Class: FastPrimaryVertexProducer
5 //
13 //
14 // Original Author: Andrea RIZZI
15 // Created: Thu Dec 22 14:51:44 CET 2011
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 #include <vector>
22 // user include files
28 
33 
36 
46 
50 
54 #define HaveMtv
55 #define HaveFsmw
56 #define HaveDivisive
57 #ifdef HaveMtv
59 #endif
60 #ifdef HaveFsmw
62 #endif
63 #ifdef HaveDivisive
65 #endif
66 
67 using namespace std;
68 
69 //
70 // class declaration
71 //
72 
74 public:
76 
77 private:
78  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
79 
85  double m_maxZ;
86  double m_maxSizeX;
87  double m_maxDeltaPhi;
89 };
90 
92  : m_geomToken(esConsumes()),
93  m_pixelCPEToken(esConsumes(edm::ESInputTag("", iConfig.getParameter<std::string>("pixelCPE")))) {
94  m_clusters = consumes<SiPixelClusterCollectionNew>(iConfig.getParameter<edm::InputTag>("clusters"));
95  m_jets = consumes<edm::View<reco::Jet> >(iConfig.getParameter<edm::InputTag>("jets"));
96  m_beamSpot = consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpot"));
97  m_maxZ = iConfig.getParameter<double>("maxZ");
98  m_maxSizeX = iConfig.getParameter<double>("maxSizeX");
99  m_maxDeltaPhi = iConfig.getParameter<double>("maxDeltaPhi");
100  m_clusterLength = iConfig.getParameter<double>("clusterLength");
101  produces<reco::VertexCollection>();
102 }
103 
105  using namespace edm;
106  using namespace reco;
107  using namespace std;
108 
110  iEvent.getByToken(m_clusters, cH);
112 
114  iEvent.getByToken(m_jets, jH);
115  const edm::View<reco::Jet>& jets = *jH.product();
116 
118  for (edm::View<reco::Jet>::const_iterator it = jets.begin(); it != jets.end(); it++) {
119  if (it->pt() > 40 && fabs(it->eta()) < 1.6) {
120  const CaloJet* ca = dynamic_cast<const CaloJet*>(&(*it));
121  if (ca == nullptr)
122  abort();
123  selectedJets.push_back(*ca);
124  // std::cout << "Jet eta,phi,pt: "<< it->eta() << "," << it->phi() << "," << it->pt() << std::endl;
125  }
126  }
127 
129 
131  iEvent.getByToken(m_beamSpot, beamSpot);
132 
133  const TrackerGeometry* trackerGeometry = &iSetup.getData(m_geomToken);
134 
135  float lengthBmodule = 6.66; //cm
136  std::vector<float> zProjections;
137  for (CaloJetCollection::const_iterator jit = selectedJets.begin(); jit != selectedJets.end(); jit++) {
138  float px = jit->px();
139  float py = jit->py();
140  float pz = jit->pz();
141  float pt = jit->pt();
142 
143  float jetZOverRho = jit->momentum().Z() / jit->momentum().Rho();
144  int minSizeY = fabs(2. * jetZOverRho) - 1;
145  int maxSizeY = fabs(2. * jetZOverRho) + 2;
146  if (fabs(jit->eta()) > 1.6) {
147  minSizeY = 1;
148  }
149 
151  it++) //Loop on pixel modules with clusters
152  {
153  DetId id = it->detId();
154  const edmNew::DetSet<SiPixelCluster>& detset = (*it);
155  Point3DBase<float, GlobalTag> modulepos = trackerGeometry->idToDet(id)->position();
156  float zmodule = modulepos.z() -
157  ((modulepos.x() - beamSpot->x0()) * px + (modulepos.y() - beamSpot->y0()) * py) / pt * pz / pt;
158  if ((fabs(deltaPhi(jit->momentum().Phi(), modulepos.phi())) < m_maxDeltaPhi * 2) &&
159  (fabs(zmodule) < (m_maxZ + lengthBmodule / 2))) {
160  for (size_t j = 0; j < detset.size(); j++) // Loop on pixel clusters on this module
161  {
162  const SiPixelCluster& aCluster = detset[j];
163  if (aCluster.sizeX() < m_maxSizeX && aCluster.sizeY() >= minSizeY && aCluster.sizeY() <= maxSizeY) {
164  Point3DBase<float, GlobalTag> v = trackerGeometry->idToDet(id)->surface().toGlobal(
165  pp->localParametersV(aCluster, (*trackerGeometry->idToDetUnit(id)))[0].first);
166  GlobalPoint v_bs(v.x() - beamSpot->x0(), v.y() - beamSpot->y0(), v.z());
167  if (fabs(deltaPhi(jit->momentum().Phi(), v_bs.phi())) < m_maxDeltaPhi) {
168  float z = v.z() - ((v.x() - beamSpot->x0()) * px + (v.y() - beamSpot->y0()) * py) / pt * pz / pt;
169  if (fabs(z) < m_maxZ) {
170  zProjections.push_back(z);
171  }
172  }
173  } //if compatible cluster
174  } // loop on module hits
175  } // if compatible module
176  } // loop on pixel modules
177 
178  } // loop on selected jets
179  std::sort(zProjections.begin(), zProjections.end());
180 
181  std::vector<float>::iterator itCenter = zProjections.begin();
182  std::vector<float>::iterator itLeftSide = zProjections.begin();
183  std::vector<float>::iterator itRightSide = zProjections.begin();
184  std::vector<int> counts;
185  float zCluster = m_clusterLength / 2.0; //cm
186  int max = 0;
187  std::vector<float>::iterator left, right;
188  for (; itCenter != zProjections.end(); itCenter++) {
189  while (itLeftSide != zProjections.end() && (*itCenter - *itLeftSide) > zCluster)
190  itLeftSide++;
191  while (itRightSide != zProjections.end() && (*itRightSide - *itCenter) < zCluster)
192  itRightSide++;
193 
194  int n = itRightSide - itLeftSide;
195  // std::cout << "algo :"<< *itCenter << " " << itCenter-zProjections.begin() << " dists: " << (*itCenter - *itLeftSide) << " " << (*itRightSide - *itCenter) << " count: " << n << std::endl;
196  counts.push_back(n);
197  if (n > max) {
198  max = n;
199  left = itLeftSide;
200  }
201  if (n >= max) {
202  max = n;
203  right = itRightSide;
204  // std::cout << "algo :"<< i << " " << j << " " << *itCenter << " " << itCenter-zProjections.begin() << " dists: " << (*itCenter - *itLeftSide) << " " << (*itRightSide - *itCenter) << " count: " << n << std::endl;
205  }
206  }
207 
208  float res = 0;
209  if (!zProjections.empty()) {
210  res = *(left + (right - left) / 2);
211  // std::cout << "RES " << res << std::endl;
213  e(0, 0) = 0.0015 * 0.0015;
214  e(1, 1) = 0.0015 * 0.0015;
215  e(2, 2) = 1.5 * 1.5;
217  Vertex thePV(p, e, 1, 1, 0);
218  auto pOut = std::make_unique<reco::VertexCollection>();
219  pOut->push_back(thePV);
220  iEvent.put(std::move(pOut));
221  } else {
222  // std::cout << "DUMMY " << res << std::endl;
223 
225  e(0, 0) = 0.0015 * 0.0015;
226  e(1, 1) = 0.0015 * 0.0015;
227  e(2, 2) = 1.5 * 1.5;
229  Vertex thePV(p, e, 0, 0, 0);
230  auto pOut = std::make_unique<reco::VertexCollection>();
231  pOut->push_back(thePV);
232  iEvent.put(std::move(pOut));
233  }
234 }
235 
236 //define this as a plug-in
GeomDet::position
const Surface::PositionType & position() const
The position (origin of the R.F.)
Definition: GeomDet.h:43
TrackerGeometry::idToDet
const TrackerGeomDet * idToDet(DetId) const override
Definition: TrackerGeometry.cc:193
edm::StreamID
Definition: StreamID.h:30
TrivialWeightEstimator.h
PixelClusterParameterEstimator
Definition: PixelClusterParameterEstimator.h:15
CaloJetCollection.h
reco::CaloJet
Jets made from CaloTowers.
Definition: CaloJet.h:27
Cluster1DMerger.h
CaloJet.h
PileupSummaryInfo.h
pwdgSkimBPark_cfi.beamSpot
beamSpot
Definition: pwdgSkimBPark_cfi.py:5
LumiMonitor_cff.pixelClusters
pixelClusters
Definition: LumiMonitor_cff.py:10
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
TrackerGeometry.h
edm::Handle::product
T const * product() const
Definition: Handle.h:70
FastPrimaryVertexProducer::m_clusters
edm::EDGetTokenT< SiPixelClusterCollectionNew > m_clusters
Definition: FastPrimaryVertexProducer.cc:82
ESHandle.h
ESInputTag
FastPrimaryVertexProducer::m_beamSpot
edm::EDGetTokenT< reco::BeamSpot > m_beamSpot
Definition: FastPrimaryVertexProducer.cc:84
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
deltaPhi.h
edm::EDGetTokenT
Definition: EDGetToken.h:33
multPhiCorr_741_25nsDY_cfi.py
py
Definition: multPhiCorr_741_25nsDY_cfi.py:12
edm
HLT enums.
Definition: AlignableModifier.h:19
reco::Vertex::Error
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:44
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
PixelClusterParameterEstimator.h
SiPixelCluster.h
edmNew::DetSetVector::const_iterator
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
Definition: DetSetVectorNew.h:197
TrackingRecHitFwd.h
singleTopDQM_cfi.jets
jets
Definition: singleTopDQM_cfi.py:42
SiPixelCluster
Pixel cluster – collection of neighboring pixels above threshold.
Definition: SiPixelCluster.h:28
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
FastPrimaryVertexProducer::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition: FastPrimaryVertexProducer.cc:104
findQualityFiles.v
v
Definition: findQualityFiles.py:179
FastPrimaryVertexProducer::m_clusterLength
double m_clusterLength
Definition: FastPrimaryVertexProducer.cc:88
MtvClusterizer1D.h
FastPrimaryVertexProducer::m_jets
edm::EDGetTokenT< edm::View< reco::Jet > > m_jets
Definition: FastPrimaryVertexProducer.cc:83
edm::Handle
Definition: AssociativeIterator.h:50
edmNew::DetSet::size
size_type size() const
Definition: DetSetNew.h:68
GenParticle.h
TrackerGeometry::idToDetUnit
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
Definition: TrackerGeometry.cc:183
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
DetId
Definition: DetId.h:17
GeomDet::surface
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
MakerMacros.h
SiPixelCluster::sizeY
int sizeY() const
Definition: SiPixelCluster.h:132
Track.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
BeamSpot.h
SiPixelRawToDigiRegional_cfi.deltaPhi
deltaPhi
Definition: SiPixelRawToDigiRegional_cfi.py:9
Surface::toGlobal
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:79
DDAxes::z
edmNew::DetSet
Definition: DetSetNew.h:22
FastPrimaryVertexProducer::m_maxDeltaPhi
double m_maxDeltaPhi
Definition: FastPrimaryVertexProducer.cc:87
DivisiveClusterizer1D.h
Point3DBase< float, GlobalTag >
SiPixelRecHit.h
edm::global::EDProducer
Definition: EDProducer.h:32
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
Vertex.h
edm::View
Definition: CaloClusterFwd.h:14
TrackerDigiGeometryRecord.h
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
iEvent
int iEvent
Definition: GenABIO.cc:224
reco::CaloJetCollection
std::vector< CaloJet > CaloJetCollection
collection of CaloJet objects
Definition: CaloJetCollection.h:15
edm::EventSetup
Definition: EventSetup.h:58
FastPrimaryVertexProducer
Definition: FastPrimaryVertexProducer.cc:73
FastPrimaryVertexProducer::FastPrimaryVertexProducer
FastPrimaryVertexProducer(const edm::ParameterSet &)
Definition: FastPrimaryVertexProducer.cc:91
res
Definition: Electron.h:6
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord >
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:127
VertexFwd.h
multPhiCorr_741_25nsDY_cfi.px
px
Definition: multPhiCorr_741_25nsDY_cfi.py:10
edmNew::DetSetVector
Definition: DetSetNew.h:13
FastPrimaryVertexProducer::m_maxSizeX
double m_maxSizeX
Definition: FastPrimaryVertexProducer.cc:86
reco::Vertex::Point
math::XYZPoint Point
point in the space
Definition: Vertex.h:40
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
Frameworkfwd.h
FastPrimaryVertexProducer::m_pixelCPEToken
const edm::ESGetToken< PixelClusterParameterEstimator, TkPixelCPERecord > m_pixelCPEToken
Definition: FastPrimaryVertexProducer.cc:81
dqmiodumpmetadata.counts
counts
Definition: dqmiodumpmetadata.py:25
FastPrimaryVertexProducer::m_geomToken
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > m_geomToken
Definition: FastPrimaryVertexProducer.cc:80
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::View::const_iterator
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
TkPixelCPERecord.h
objectSelection_cff.selectedJets
selectedJets
Definition: objectSelection_cff.py:99
FsmwClusterizer1D.h
ParameterSet.h
createTree.pp
pp
Definition: createTree.py:17
Clusterizer1DCommons.h
EDProducer.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
SiPixelCluster::sizeX
int sizeX() const
Definition: SiPixelCluster.h:129
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::Event
Definition: Event.h:73
FastPrimaryVertexProducer::m_maxZ
double m_maxZ
Definition: FastPrimaryVertexProducer.cc:85
edm::InputTag
Definition: InputTag.h:15
PV3DBase::phi
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
reco::Vertex
Definition: Vertex.h:35
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
TrackerGeometry
Definition: TrackerGeometry.h:14