ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/Morgan/src/VertexAnalyzer.cc
Revision: 1.10
Committed: Tue Oct 13 14:05:58 2009 UTC (15 years, 6 months ago) by lethuill
Content type: text/plain
Branch: MAIN
CVS Tags: all_3_3_2_01, all_3_2_5_02, HEAD
Changes since 1.9: +1 -1 lines
Error occurred while calculating annotation data.
Log Message:
Fix verbosity level

File Contents

# Content
1 #include "../interface/VertexAnalyzer.h"
2
3 using namespace std;
4 using namespace reco;
5 using namespace edm;
6
7 VertexAnalyzer::VertexAnalyzer(const edm::ParameterSet& producersNames):verbosity_(0)
8 {
9 primaryVertexProducer_ = producersNames.getParameter<edm::InputTag>("primaryVertexProducer");
10 beamSpotProducer_ = producersNames.getParameter<edm::InputTag>("beamSpotProducer");
11 allowMissingCollection_ = producersNames.getUntrackedParameter<bool>("allowMissingCollection", false);
12 }
13
14
15 VertexAnalyzer::VertexAnalyzer(const edm::ParameterSet& producersNames, int verbosity):verbosity_(verbosity)
16 {
17 primaryVertexProducer_ = producersNames.getParameter<edm::InputTag>("primaryVertexProducer");
18 beamSpotProducer_ = producersNames.getParameter<edm::InputTag>("beamSpotProducer");
19 allowMissingCollection_ = producersNames.getUntrackedParameter<bool>("allowMissingCollection", false);
20 }
21
22
23 VertexAnalyzer::~VertexAnalyzer()
24 {
25 }
26
27
28 bool VertexAnalyzer::getBeamSpot(const edm::Event& iEvent, TRootBeamSpot* rootBeamSpot)
29 {
30 try
31 {
32 edm::Handle<reco::BeamSpot> recoBeamSpot;
33 iEvent.getByLabel(beamSpotProducer_, recoBeamSpot);
34
35 if ( recoBeamSpot.isValid() )
36 {
37 if(verbosity_>1) std::cout << " Beam Spot - Label: " << beamSpotProducer_.label() << " Instance: " << beamSpotProducer_.instance() << std::endl;
38 rootBeamSpot->fill(
39 recoBeamSpot->x0()
40 ,recoBeamSpot->y0()
41 ,recoBeamSpot->z0()
42 ,recoBeamSpot->x0Error()
43 ,recoBeamSpot->y0Error()
44 ,recoBeamSpot->z0Error()
45 ,recoBeamSpot->sigmaZ()
46 ,recoBeamSpot->sigmaZ0Error()
47 ,recoBeamSpot->BeamWidthX()
48 ,recoBeamSpot->BeamWidthXError()
49 ,recoBeamSpot->BeamWidthY()
50 ,recoBeamSpot->BeamWidthYError()
51 );
52 if(verbosity_>2) cout << " "<< *rootBeamSpot << endl << endl;
53 }
54 else
55 {
56 if(verbosity_>1) cout << " ##### ERROR IN VertexAnalyzer::getBeamSpot => No beam spot available from EventSetup #####"<<endl;
57 return false;
58 }
59 }
60 catch (cms::Exception& exception)
61 {
62 if ( !allowMissingCollection_ )
63 {
64 cout << " ##### ERROR IN VertexAnalyzer::getBeamSpot => No beam spot available from EventSetup #####"<<endl;
65 throw exception;
66 }
67 if(verbosity_>1) cout << " ===> No beam spot available, skip beam spot info" << endl;
68 return false;
69 }
70
71 return true;
72 }
73
74
75 bool VertexAnalyzer::getVertices(const edm::Event& iEvent, TClonesArray* rootVertices)
76 {
77
78 edm::Handle< reco::VertexCollection > recoVertices;
79 try
80 {
81 iEvent.getByLabel(primaryVertexProducer_, recoVertices);
82 int nVertices = recoVertices->size();
83 if(verbosity_>1) std::cout << " Number of primary vertices = " << nVertices << " Label: " << primaryVertexProducer_.label() << " Instance: " << primaryVertexProducer_.instance() << std::endl;
84 }
85 catch (cms::Exception& exception)
86 {
87 if ( !allowMissingCollection_ )
88 {
89 cout << " ##### ERROR IN VertexAnalyzer::getVertices => Vertex collection is missing #####"<<endl;
90 throw exception;
91 }
92 if(verbosity_>1) cout << " ===> No primaryVertex collection, skip vertex info" << endl;
93 return false;
94 }
95
96 int iRootVertex = 0;
97 for (unsigned int j=0; j<recoVertices->size(); j++)
98 {
99 const reco::Vertex* vertex = & ((*recoVertices)[j]);
100
101 // Put your vertex selection here....
102 if (! vertex->isValid() ) continue;
103 if ( vertex->isFake() ) continue;
104
105 Int_t ntracks = 0;
106 Float_t higherPt = 0.;
107 Float_t scalarSumPt = 0.;
108 Float_t vectorSumPt = 0.;
109 math::XYZVector vectorSum(0.,0.,0.);
110
111 for( std::vector< reco::TrackBaseRef >::const_iterator it = vertex->tracks_begin(); it != vertex->tracks_end(); it++)
112 {
113 scalarSumPt += (**it).pt();
114 vectorSum += (**it).momentum();
115 if( (**it).pt()>higherPt ) higherPt=(**it).pt();
116 ntracks++;
117 }
118 vectorSumPt = sqrt(vectorSum.Perp2());
119
120 // No refitted tracks embeded in reco::Vertex....
121 //cout << "vertex->refittedTracks().size()=" << vertex->refittedTracks().size() << endl;
122
123 TRootVertex localVertex(
124 vertex->x()
125 ,vertex->y()
126 ,vertex->z()
127 ,vertex->xError()
128 ,vertex->yError()
129 ,vertex->zError()
130 );
131
132 localVertex.setAlgoName("RECO");
133 localVertex.setChi2( vertex->chi2() );
134 localVertex.setNdof( vertex->ndof() );
135 localVertex.setNtracks( ntracks );
136 localVertex.setHigherTrackPt( higherPt );
137 localVertex.setScalarSumPt( scalarSumPt );
138 localVertex.setVectorSumPt( vectorSumPt );
139
140 new( (*rootVertices)[iRootVertex] ) TRootVertex(localVertex);
141 if(verbosity_>2) cout << " ["<< setw(3) << iRootVertex << "] " << localVertex << endl;
142 iRootVertex++;
143 }
144
145 return true;
146 }
147
148
149 void VertexAnalyzer::selectPrimary(TRootEvent* rootEvent, TClonesArray* rootVertices)
150 {
151
152 int ibestVertex = -1;
153 float highestScalarSumPt = -1.;
154 TRootVertex* localVertex = 0;
155
156 for (int ivtx=0; ivtx<rootVertices->GetEntriesFast(); ivtx++)
157 {
158 localVertex = (TRootVertex*) rootVertices->At(ivtx);
159 // Put you primary vertex selection here...
160 if ( localVertex->scalarSumPt()>highestScalarSumPt )
161 {
162 highestScalarSumPt = localVertex->scalarSumPt();
163 ibestVertex = ivtx;
164 }
165 }
166
167 if ( ibestVertex >= 0)
168 {
169 localVertex = (TRootVertex*) rootVertices->At(ibestVertex);
170 rootEvent->setPrimaryVertexIndex( ibestVertex );
171 rootEvent->setPrimaryVertex( localVertex );
172 }
173
174 if(verbosity_>2) std::cout << " Selected primary vertex: TRootVertex[" << ibestVertex << "]" << std::endl;
175 }