Go to the documentation of this file.00001 #include "PixelVertexProducerClusters.h"
00002
00003 #include "FWCore/Framework/interface/MakerMacros.h"
00004 #include "FWCore/Framework/interface/ESHandle.h"
00005 #include "FWCore/Framework/interface/Frameworkfwd.h"
00006 #include "FWCore/Framework/interface/Event.h"
00007
00008 #include "DataFormats/VertexReco/interface/Vertex.h"
00009 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00010
00011 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00012 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h"
00013 #include "Geometry/CommonTopologies/interface/PixelTopology.h"
00014 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00015 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00016
00017 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHitCollection.h"
00018
00019 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
00020 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00021
00022 #include "DataFormats/SiPixelDetId/interface/PXBDetId.h"
00023
00024 #include "SimDataFormats/Vertex/interface/SimVertexContainer.h"
00025
00026 #include <fstream>
00027 #include <iostream>
00028 #include <vector>
00029 #include <algorithm>
00030
00031 using namespace std;
00032
00033 #include "TROOT.h"
00034 #include "TH1F.h"
00035 #include "TF1.h"
00036
00037 class VertexHit
00038 {
00039 public:
00040 float z;
00041 float r;
00042 int w;
00043 };
00044
00045
00046 PixelVertexProducerClusters::PixelVertexProducerClusters
00047 (const edm::ParameterSet& ps) : theConfig(ps)
00048 {
00049
00050 produces<reco::VertexCollection>();
00051 }
00052
00053
00054
00055 PixelVertexProducerClusters::~PixelVertexProducerClusters()
00056 {
00057 }
00058
00059
00060 void PixelVertexProducerClusters::beginRun
00061 (edm::Run const & run, edm::EventSetup const & es)
00062 {
00063
00064 edm::ESHandle<TrackerGeometry> trackerHandle;
00065 es.get<TrackerDigiGeometryRecord>().get(trackerHandle);
00066 theTracker = trackerHandle.product();
00067 }
00068
00069
00070 int PixelVertexProducerClusters::getContainedHits
00071 (vector<VertexHit> hits, float z0, float & chi)
00072 {
00073 int n = 0;
00074 chi = 0.;
00075
00076 for(vector<VertexHit>::const_iterator hit = hits.begin();
00077 hit!= hits.end(); hit++)
00078 {
00079
00080 float p = 2 * fabs(hit->z - z0)/hit->r + 0.5;
00081
00082 if(fabs(p - hit->w) <= 1.)
00083 {
00084 chi += fabs(p - hit->w);
00085 n++;
00086 }
00087 }
00088
00089 return n;
00090 }
00091
00092
00093 void PixelVertexProducerClusters::produce
00094 (edm::Event& ev, const edm::EventSetup& es)
00095 {
00096
00097 edm::Handle<SiPixelRecHitCollection> pixelColl;
00098 ev.getByLabel("siPixelRecHits", pixelColl);
00099
00100 const SiPixelRecHitCollection* thePixelHits = pixelColl.product();
00101
00102 std::auto_ptr<reco::VertexCollection> vertices(new reco::VertexCollection);
00103
00104 if(thePixelHits->size() > 0)
00105 {
00106 vector<VertexHit> hits;
00107
00108 for(SiPixelRecHitCollection::DataContainer::const_iterator
00109 recHit = thePixelHits->data().begin(),
00110 recHitEnd = thePixelHits->data().end();
00111 recHit != recHitEnd; ++recHit)
00112 {
00113 if(recHit->isValid())
00114 {
00115
00116 DetId id = recHit->geographicalId();
00117 const PixelGeomDetUnit* pgdu =
00118 dynamic_cast<const PixelGeomDetUnit*>(theTracker->idToDetUnit(id));
00119 const PixelTopology* theTopol = ( &(pgdu->specificTopology()) );
00120 vector<SiPixelCluster::Pixel> pixels = recHit->cluster()->pixels();
00121
00122 bool pixelOnEdge = false;
00123 for(vector<SiPixelCluster::Pixel>::const_iterator
00124 pixel = pixels.begin(); pixel!= pixels.end(); pixel++)
00125 {
00126 int pos_x = (int)pixel->x;
00127 int pos_y = (int)pixel->y;
00128
00129 if(theTopol->isItEdgePixelInX(pos_x) ||
00130 theTopol->isItEdgePixelInY(pos_y))
00131 { pixelOnEdge = true; break; }
00132 }
00133
00134 if(!pixelOnEdge)
00135 if(id.subdetId() == int(PixelSubdetector::PixelBarrel))
00136 {
00137 PXBDetId pid(id);
00138
00139 LocalPoint lpos = LocalPoint(recHit->localPosition().x(),
00140 recHit->localPosition().y(),
00141 recHit->localPosition().z());
00142
00143 GlobalPoint gpos = theTracker->idToDet(id)->toGlobal(lpos);
00144
00145 VertexHit hit;
00146 hit.z = gpos.z();
00147 hit.r = gpos.perp();
00148 hit.w = recHit->cluster()->sizeY();
00149
00150 hits.push_back(hit);
00151 }
00152 }
00153 }
00154
00155 int nhits; int nhits_max = 0;
00156 float chi; float chi_max = 1e+9;
00157
00158 float zest = 0;
00159
00160 for(float z0 = -15.9; z0 <= 15.95; z0 += 0.1)
00161 {
00162 nhits = getContainedHits(hits, z0, chi);
00163
00164 if(nhits > 0)
00165 {
00166 if(nhits > nhits_max)
00167 { chi_max = 1e+9; nhits_max = nhits; }
00168
00169 if(nhits >= nhits_max)
00170 if(chi < chi_max)
00171 { chi_max = chi; zest = z0; }
00172 }
00173 }
00174
00175 LogTrace("MinBiasTracking")
00176 << " [vertex position] estimated = " << zest
00177 << " | pixel barrel hits = " << thePixelHits->size();
00178
00179 reco::Vertex::Error err;
00180 err(2,2) = 0.6 * 0.6;
00181 reco::Vertex ver(reco::Vertex::Point(0,0,zest), err, 0, 1, 1);
00182 vertices->push_back(ver);
00183 }
00184
00185 ev.put(vertices);
00186 }
00187