CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/RecoPixelVertexing/PixelLowPtUtilities/plugins/PixelVertexProducerClusters.cc

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