Go to the documentation of this file.00001 #include "PixelVertexProducerMedian.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/TrackReco/interface/Track.h"
00009 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00010
00011 #include "DataFormats/VertexReco/interface/Vertex.h"
00012 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00013
00014 #include <fstream>
00015 #include <iostream>
00016 #include <vector>
00017 #include <algorithm>
00018
00019 #include "TROOT.h"
00020 #include "TH1F.h"
00021 #include "TF1.h"
00022
00023
00024 struct ComparePairs
00025 {
00026 bool operator() (const reco::Track * t1,
00027 const reco::Track * t2)
00028 {
00029 return (t1->vz() < t2->vz());
00030 };
00031 };
00032
00033
00034 PixelVertexProducerMedian::PixelVertexProducerMedian
00035 (const edm::ParameterSet& ps) : theConfig(ps)
00036 {
00037 produces<reco::VertexCollection>();
00038 }
00039
00040
00041
00042 PixelVertexProducerMedian::~PixelVertexProducerMedian()
00043 {
00044 }
00045
00046
00047 void PixelVertexProducerMedian::produce
00048 (edm::Event& ev, const edm::EventSetup& es)
00049 {
00050
00051 edm::Handle<reco::TrackCollection> trackCollection;
00052 std::string trackCollectionName =
00053 theConfig.getParameter<std::string>("TrackCollection");
00054 ev.getByLabel(trackCollectionName, trackCollection);
00055 const reco::TrackCollection tracks_ = *(trackCollection.product());
00056
00057 thePtMin = theConfig.getParameter<double>("PtMin");
00058
00059
00060 std::vector<const reco::Track *> tracks;
00061 for (unsigned int i=0; i<tracks_.size(); i++)
00062 {
00063 if (tracks_[i].pt() > thePtMin)
00064 {
00065 reco::TrackRef recTrack(trackCollection, i);
00066 tracks.push_back( &(*recTrack));
00067 }
00068 }
00069
00070 LogTrace("MinBiasTracking")
00071 << " [VertexProducer] selected tracks: "
00072 << tracks.size() << " (out of " << tracks_.size()
00073 << ")";
00074
00075 std::auto_ptr<reco::VertexCollection> vertices(new reco::VertexCollection);
00076
00077 if(tracks.size() > 0)
00078 {
00079
00080 std::sort(tracks.begin(), tracks.end(), ComparePairs());
00081
00082
00083 float med;
00084 if(tracks.size() % 2 == 0)
00085 med = (tracks[tracks.size()/2-1]->vz() + tracks[tracks.size()/2]->vz())/2;
00086 else
00087 med = tracks[tracks.size()/2 ]->vz();
00088
00089 LogTrace("MinBiasTracking")
00090 << " [vertex position] median = " << med << " cm";
00091
00092 if(tracks.size() > 10)
00093 {
00094
00095 int nBin = 100;
00096 float halfWidth = 0.1;
00097
00098
00099 TH1F histo("histo","histo", nBin, -halfWidth,halfWidth);
00100
00101 for(std::vector<const reco::Track *>::const_iterator
00102 track = tracks.begin(); track!= tracks.end(); track++)
00103 if(fabs((*track)->vz() - med) < halfWidth)
00104 histo.Fill((*track)->vz() - med);
00105
00106 LogTrace("MinBiasTracking")
00107 << " [vertex position] most prob = "
00108 << med + histo.GetBinCenter(histo.GetMaximumBin())
00109 << " cm";
00110
00111
00112 histo.Sumw2();
00113
00114 TF1 f1("f1","[0]*exp(-0.5 * ((x-[1])/[2])^2) + [3]");
00115 f1.SetParameters(10.,0.,0.01, 1.);
00116
00117 histo.Fit("f1","QN");
00118
00119 LogTrace("MinBiasTracking")
00120 << " [vertex position] fitted = "
00121 << med + f1.GetParameter(1) << " +- " << f1.GetParError(1)
00122 << " cm";
00123
00124
00125 reco::Vertex::Error err;
00126 err(2,2) = f1.GetParError(1) * f1.GetParError(1);
00127 reco::Vertex ver(reco::Vertex::Point(0,0,med + f1.GetParameter(1)),
00128 err, 0, 1, 1);
00129 vertices->push_back(ver);
00130 }
00131 else
00132 {
00133
00134 reco::Vertex::Error err;
00135 err(2,2) = 0.1 * 0.1;
00136 reco::Vertex ver(reco::Vertex::Point(0,0,med),
00137 err, 0, 1, 1);
00138 vertices->push_back(ver);
00139 }
00140 }
00141 ev.put(vertices);
00142 }
00143