CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PixelVertexProducerMedian.cc
Go to the documentation of this file.
2 
7 
10 
13 
14 #include <fstream>
15 #include <iostream>
16 #include <vector>
17 #include <algorithm>
18 
19 #include "TROOT.h"
20 #include "TH1F.h"
21 #include "TF1.h"
22 
23 /*****************************************************************************/
24 struct ComparePairs
25 {
26  bool operator() (const reco::Track * t1,
27  const reco::Track * t2)
28  {
29  return (t1->vz() < t2->vz());
30  };
31 };
32 
33 /*****************************************************************************/
35  (const edm::ParameterSet& ps) : theConfig(ps)
36 {
37  produces<reco::VertexCollection>();
38 }
39 
40 
41 /*****************************************************************************/
43 {
44 }
45 
46 /*****************************************************************************/
49 {
50  // Get pixel tracks
52  std::string trackCollectionName =
53  theConfig.getParameter<std::string>("TrackCollection");
54  ev.getByLabel(trackCollectionName, trackCollection);
55  const reco::TrackCollection tracks_ = *(trackCollection.product());
56 
57  thePtMin = theConfig.getParameter<double>("PtMin");
58 
59  // Select tracks
60  std::vector<const reco::Track *> tracks;
61  for (unsigned int i=0; i<tracks_.size(); i++)
62  {
63  if (tracks_[i].pt() > thePtMin)
64  {
65  reco::TrackRef recTrack(trackCollection, i);
66  tracks.push_back( &(*recTrack));
67  }
68  }
69 
70  LogTrace("MinBiasTracking")
71  << " [VertexProducer] selected tracks: "
72  << tracks.size() << " (out of " << tracks_.size()
73  << ")";
74 
75  std::auto_ptr<reco::VertexCollection> vertices(new reco::VertexCollection);
76 
77  if(tracks.size() > 0)
78  {
79  // Sort along vertex z position
80  std::sort(tracks.begin(), tracks.end(), ComparePairs());
81 
82  // Median
83  float med;
84  if(tracks.size() % 2 == 0)
85  med = (tracks[tracks.size()/2-1]->vz() + tracks[tracks.size()/2]->vz())/2;
86  else
87  med = tracks[tracks.size()/2 ]->vz();
88 
89  LogTrace("MinBiasTracking")
90  << " [vertex position] median = " << med << " cm";
91 
92  if(tracks.size() > 10)
93  {
94  // Binning around med, halfWidth
95  int nBin = 100;
96  float halfWidth = 0.1; // cm
97 
98  // Most probable
99  TH1F histo("histo","histo", nBin, -halfWidth,halfWidth);
100 
101  for(std::vector<const reco::Track *>::const_iterator
102  track = tracks.begin(); track!= tracks.end(); track++)
103  if(fabs((*track)->vz() - med) < halfWidth)
104  histo.Fill((*track)->vz() - med);
105 
106  LogTrace("MinBiasTracking")
107  << " [vertex position] most prob = "
108  << med + histo.GetBinCenter(histo.GetMaximumBin())
109  << " cm";
110 
111  // Fit above max/2
112  histo.Sumw2();
113 
114  TF1 f1("f1","[0]*exp(-0.5 * ((x-[1])/[2])^2) + [3]");
115  f1.SetParameters(10.,0.,0.01, 1.);
116 
117  histo.Fit(&f1,"QN");
118 
119  LogTrace("MinBiasTracking")
120  << " [vertex position] fitted = "
121  << med + f1.GetParameter(1) << " +- " << f1.GetParError(1)
122  << " cm";
123 
124  // Store
126  err(2,2) = f1.GetParError(1) * f1.GetParError(1);
127  reco::Vertex ver(reco::Vertex::Point(0,0,med + f1.GetParameter(1)),
128  err, 0, 1, 1);
129  vertices->push_back(ver);
130  }
131  else
132  {
133  // Store
135  err(2,2) = 0.1 * 0.1;
136  reco::Vertex ver(reco::Vertex::Point(0,0,med),
137  err, 0, 1, 1);
138  vertices->push_back(ver);
139  }
140  }
141  ev.put(vertices);
142 }
143 
int i
Definition: DBlmapReader.cc:9
const std::vector< reco::PFCandidatePtr > & tracks_
virtual void produce(edm::Event &ev, const edm::EventSetup &es)
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:43
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
bool ev
PixelVertexProducerMedian(const edm::ParameterSet &ps)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
math::XYZPoint Point
point in the space
Definition: Vertex.h:39
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:420
#define LogTrace(id)
double vz() const
z coordinate of the reference point on track
Definition: TrackBase.h:656
T const * product() const
Definition: Handle.h:81
tuple tracks
Definition: testEve_cfg.py:39
bool operator()(const reco::Track *t1, const reco::Track *t2)