NtupleWriter13/NtupleWriter13-00-01-00/src/VertexCollector.cxx

00001 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00002 // 18.08.2007, AUTHOR: OLIVER KORTNER
00003 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00004 
00005 //::::::::::::::::::::::::::::::::::::::::::::::::::
00006 //:: METHODS DEFINED IN THE CLASS VertexCollector ::
00007 //::::::::::::::::::::::::::::::::::::::::::::::::::
00008 
00009 //::::::::::::::::::
00010 //:: HEADER FILES ::
00011 //::::::::::::::::::
00012 
00013 // standard C++ //
00014 #include <iostream>
00015 #include <fstream>
00016 
00017 // track particles //
00018 #include "Particle/TrackParticleContainer.h"
00019 
00020 // NtupleWriter13 //
00021 #include "NtupleWriter13/VertexCollector.h"
00022 
00023 //::::::::::::::::::::::::
00024 //:: NAMESPACE SETTINGS ::
00025 //::::::::::::::::::::::::
00026 
00027 using namespace std;
00028 using namespace MPIHiggsAnalysis;
00029 
00030 //*****************************************************************************
00031 
00032 //:::::::::::::::::
00033 //:: CONSTRUCTOR ::
00034 //:::::::::::::::::
00035 
00036 VertexCollector::VertexCollector(const std::string & name,
00037                         ISvcLocator * svcloc) : Algorithm(name, svcloc) {
00038 
00040 // JOB OPTIONS //
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 // RESET POINTERS //
00056 
00057         m_storeGate = 0;
00058         m_log = 0;
00059         m_vert_coll = 0;
00060 
00061 }
00062 
00063 //*****************************************************************************
00064 
00065 //::::::::::::::::
00066 //:: DESTRUCTOR ::
00067 //::::::::::::::::
00068 
00069 VertexCollector::~VertexCollector(void) {
00070 }
00071 
00072 //*****************************************************************************
00073 
00074 //:::::::::::::::::::::::
00075 //:: METHOD initialize ::
00076 //:::::::::::::::::::::::
00077 
00078 StatusCode VertexCollector::initialize(void) {
00079 
00081 // VARIABLES //
00083 
00084         m_log = new MsgStream(msgSvc(), name());
00085 
00087 // MESSAGE //
00089 
00090         *m_log << MSG::INFO << "Initializing tool..." << endl;
00091 
00093 // SET POINTERS //
00095 
00096 // store gate //
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 // VertexCollectionSvc //
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 //:: METHOD execute ::
00122 //::::::::::::::::::::
00123 
00124 StatusCode VertexCollector::execute(void) {
00125 
00127 // VARIABLES //
00129 
00130         const Rec::TrackParticleContainer *track_particle_container(0);
00131                                         // pointer to the track particles
00132         const VxContainer *vertex_container(0); // pointer to the vertices
00133 
00135 // GET A POINTER TO THE VERTEX CONTAINER //
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 // CALCULATE SUM OF TRANSVERSE ENERGIES EMERGING FROM THE VERTICES //
00162 
00163 // retrieve track particles //
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 // loop over the vertices //
00177         vector<double> Et_vert(vertex_container->size(), 0.0); // Et(vertex)
00178         vector<int> nb_tracks(vertex_container->size(), 0); // number of
00179                                                               // tracks(vertex)
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             for (unsigned int l=0; l<vertex_container->size(); l++) {
00187                 
00188                 Trk::RecVertex vert((*vertex_container)[l]->recVertex());
00189                 
00190                 if ((*track_particle_container
00191                         )[k]->reconstructedVertex()->recVertex().position()==
00192                         vert.position()) {
00193                     
00194                     Et_vert[l] += (*track_particle_container)[k]->hlv().et();
00195                     nb_tracks[l]++;
00196                 }
00197             }
00198         }
00199 
00201 // CREATE THE VERTICES AND STORE THEM //
00203 
00204         std::vector<MPIHiggsAnalysis::Vertex> vertices(Et_vert.size());
00205         for (unsigned int k=0; k<vertices.size(); k++) {
00206                 Trk::RecVertex vert((*vertex_container)[k]->recVertex());
00207                 Trk::ErrorMatrix err(vert.errorPosition());
00208                 Hep3Vector error(err.error(Trk::x), err.error(Trk::y),
00209                                                         err.error(Trk::z));
00210                 vertices[k] = MPIHiggsAnalysis::Vertex(vert.position(), error,
00211                                 vert.fitQuality().chiSquared(),
00212                                 vert.fitQuality().numberDoF(), Et_vert[k],
00213                                 nb_tracks[k]);
00214         }
00215 
00216         m_vert_coll->setVertices(vertices);
00217         m_vert_coll->sortVerticesAscendingInEt();
00218 
00219         
00220         return StatusCode::SUCCESS;
00221 
00222 }
00223 
00224 //*****************************************************************************
00225 
00226 //:::::::::::::::::::::
00227 //:: METHOD finalize ::
00228 //:::::::::::::::::::::
00229 
00230 StatusCode VertexCollector::finalize(void) {
00231 
00233 // MESSAGE //
00235 
00236         *m_log << MSG::INFO << "Finalizing tool..." << endl;
00237 
00238         return StatusCode::SUCCESS;
00239 
00240 }

Generated on Tue Oct 21 11:50:43 2008 for NtupleAnalysis by  doxygen 1.5.1