00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <iostream>
00015 #include <fstream>
00016
00017
00018 #include "Particle/TrackParticleContainer.h"
00019
00020
00021 #include "HiggsAnalysis/VertexCollector.h"
00022
00023
00024
00025
00026
00027 using namespace std;
00028 using namespace MPIHiggsAnalysis;
00029
00030
00031
00032
00033
00034
00035
00036 VertexCollector::VertexCollector(const std::string & name,
00037 ISvcLocator * svcloc) : Algorithm(name, svcloc) {
00038
00040
00042
00043 m_track_particle_container_name = string("TrackParticleCandidate");
00044 declareProperty("TrackParticleContainer",
00045 m_track_particle_container_name);
00046
00047 m_primary_vertex_container = string("VxPrimaryCandidate");
00048 declareProperty("vertexContainer", m_primary_vertex_container);
00049
00050 m_vert_coll_svc_name = string("MPIHiggsAnalysis::VertexCollectionSvc");
00051 declareProperty("VertexCollectionSvc", m_vert_coll_svc_name);
00052
00054
00056
00057 m_storeGate = 0;
00058 m_log = 0;
00059 m_vert_coll = 0;
00060
00061 }
00062
00063
00064
00065
00066
00067
00068
00069 VertexCollector::~VertexCollector(void) {
00070 }
00071
00072
00073
00074
00075
00076
00077
00078 StatusCode VertexCollector::initialize(void) {
00079
00081
00083
00084 m_log = new MsgStream(msgSvc(), name());
00085
00087
00089
00090 *m_log << MSG::INFO << "Initializing tool..." << endl;
00091
00093
00095
00096
00097 StatusCode sc(service("StoreGateSvc", m_storeGate));
00098 if (!sc.isSuccess()) {
00099 *m_log << MSG::FATAL << "Cannot retrieve StoreGateSvc!"
00100 << endreq;
00101 return sc;
00102 }
00103
00104
00105 sc = service(m_vert_coll_svc_name, m_vert_coll);
00106 if (!sc.isSuccess()) {
00107 *m_log << MSG::FATAL << "Cannot retrieve "
00108 << m_vert_coll_svc_name
00109 << "!"
00110 << endreq;
00111 return sc;
00112 }
00113
00114 return StatusCode::SUCCESS;
00115
00116 }
00117
00118
00119
00120
00121
00122
00123
00124 StatusCode VertexCollector::execute(void) {
00125
00127
00129
00130 const Rec::TrackParticleContainer *track_particle_container(0);
00131
00132 const VxContainer *vertex_container(0);
00133
00135
00137
00138 StatusCode sc(m_storeGate->retrieve(vertex_container,
00139 m_primary_vertex_container));
00140 if (sc.isFailure() || vertex_container==0) {
00141 *m_log << MSG::ERROR
00142 << "No vertex container "
00143 << m_primary_vertex_container
00144 << " found in the store gate!"
00145 << endreq;
00146 return StatusCode::FAILURE;
00147 }
00148
00149 *m_log << MSG::DEBUG
00150 << "Vertex container "
00151 << m_primary_vertex_container
00152 << " retrieved successfully!"
00153 << endreq;
00154
00155 if (vertex_container->size()==0) {
00156 return StatusCode::FAILURE;
00157 }
00158
00160
00162
00163
00164 sc = (m_storeGate->retrieve(track_particle_container,
00165 m_track_particle_container_name));
00166 if (sc.isFailure() || track_particle_container==0) {
00167 *m_log << MSG::WARNING
00168 << "No track particle container found in store gate!"
00169 << endreq;
00170 return StatusCode::FAILURE;
00171 }
00172 *m_log << MSG::DEBUG
00173 << "Track particle container retrieved successfully!"
00174 << endreq;
00175
00176
00177 vector<double> Et_vert(vertex_container->size(), 0.0);
00178 vector<int> nb_tracks(vertex_container->size(), 0);
00179
00180 for (unsigned int k=0; k<track_particle_container->size(); k++) {
00181
00182 if((*track_particle_container)[k]->reconstructedVertex() == NULL){
00183 continue;
00184 }
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199 for (unsigned int l=0; l<vertex_container->size(); l++) {
00200
00201 Trk::RecVertex vert((*vertex_container)[l]->recVertex());
00202
00203 if ((*track_particle_container)[k]->reconstructedVertex()->position()
00204 ==vert.position()) {
00205
00206 Et_vert[l] += (*track_particle_container)[k]->hlv().et();
00207 nb_tracks[l]++;
00208 }
00209 }
00210 }
00211
00213
00215
00216 std::vector<MPIHiggsAnalysis::Vertex> vertices(Et_vert.size());
00217 for (unsigned int k=0; k<vertices.size(); k++) {
00218 Trk::RecVertex vert((*vertex_container)[k]->recVertex());
00219 Trk::ErrorMatrix err(vert.errorPosition());
00220 Hep3Vector error(err.error(Trk::x), err.error(Trk::y),
00221 err.error(Trk::z));
00222 vertices[k] = MPIHiggsAnalysis::Vertex(vert.position(), error,
00223 vert.chi2(), vert.ndf(), Et_vert[k],
00224 nb_tracks[k]);
00225 }
00226
00227 m_vert_coll->setVertices(vertices);
00228 m_vert_coll->sortVerticesAscendingInEt();
00229
00230
00231 return StatusCode::SUCCESS;
00232
00233 }
00234
00235
00236
00237
00238
00239
00240
00241 StatusCode VertexCollector::finalize(void) {
00242
00244
00246
00247 *m_log << MSG::INFO << "Finalizing tool..." << endl;
00248
00249 return StatusCode::SUCCESS;
00250
00251 }