CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/HLTrigger/HLTanalyzers/src/RECOVertex.cc

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <sstream>
00003 #include <istream>
00004 #include <fstream>
00005 #include <iomanip>
00006 #include <stdlib.h>
00007 #include <string.h>
00008 
00009 #include "HLTrigger/HLTanalyzers/interface/RECOVertex.h"
00010 #include "HLTMessages.h"
00011 
00012 static const size_t kMaxVrt = 50; 
00013 
00014 RECOVertex::RECOVertex() {
00015 
00016   //set parameter defaults 
00017   _Debug=false;
00018 
00019   NVrtx                 = 0;
00020   VertexCand_x          = new float[kMaxVrt];
00021   VertexCand_y          = new float[kMaxVrt];
00022   VertexCand_z          = new float[kMaxVrt];
00023   VertexCand_tracks     = new int[kMaxVrt];
00024   VertexCand_chi2       = new float[kMaxVrt];
00025   VertexCand_ndof       = new float[kMaxVrt];
00026 
00027 }
00028 
00029 RECOVertex::~RECOVertex() {
00030 
00031 }
00032 
00033 void RECOVertex::clear() 
00034 {
00035   NVrtx          = 0;
00036   std::memset(VertexCand_x,            '\0', kMaxVrt * sizeof(float));
00037   std::memset(VertexCand_y,            '\0', kMaxVrt * sizeof(float));
00038   std::memset(VertexCand_z,            '\0', kMaxVrt * sizeof(float));
00039   std::memset(VertexCand_tracks,       '\0', kMaxVrt * sizeof(int));
00040   std::memset(VertexCand_chi2,         '\0', kMaxVrt * sizeof(float));
00041   std::memset(VertexCand_ndof,         '\0', kMaxVrt * sizeof(float));
00042 }
00043 
00044 /*  Setup the analysis to put the branch-variables into the tree. */
00045 void RECOVertex::setup(const edm::ParameterSet& pSet, TTree* HltTree) {
00046 
00047   edm::ParameterSet myHltParams = pSet.getParameter<edm::ParameterSet>("RunParameters") ;
00048   std::vector<std::string> parameterNames = myHltParams.getParameterNames() ;
00049   
00050   for ( std::vector<std::string>::iterator iParam = parameterNames.begin();
00051         iParam != parameterNames.end(); iParam++ ){
00052     if ( (*iParam) == "Debug" ) _Debug =  myHltParams.getParameter<bool>( *iParam );
00053   }
00054 
00055   HltTree->Branch("recoNVrt",        & NVrtx,            "NVrtx/I");
00056   HltTree->Branch("recoVrtX",     VertexCand_x,          "recoVrtX[NVrtx]/F");
00057   HltTree->Branch("recoVrtY",     VertexCand_y,          "recoVrtY[NVrtx]/F");
00058   HltTree->Branch("recoVrtZ",     VertexCand_z,          "recoVrtZ[NVrtx]/F");
00059   HltTree->Branch("recoVrtNtrk",  VertexCand_tracks,     "recoVrtNtrk[NVrtx]/I");
00060   HltTree->Branch("recoVrtChi2",  VertexCand_chi2,       "recoVrtChi2[NVrtx]/F");
00061   HltTree->Branch("recoVrtNdof",  VertexCand_ndof,       "recoVrtNdof[NVrtx]/F");
00062 
00063 }
00064 
00065 /* **Analyze the event** */
00066 void RECOVertex::analyze(edm::Handle<reco::VertexCollection> recoVertexs, TTree* HltTree) {
00067 
00068   // reset the tree variables
00069   clear();
00070 
00071   if ( recoVertexs.isValid() ) {
00072     const reco::VertexCollection* vertexs = recoVertexs.product();
00073     reco::VertexCollection::const_iterator vertex_i;
00074 
00075     size_t size = std::min(kMaxVrt, size_t(vertexs->size()) ); 
00076     NVrtx= size;
00077 
00078     int nVertexCand=0;
00079     if (_Debug)  std::cout << "Found " << vertexs->size() << " vertices" << std::endl;  
00080     for (vertex_i = vertexs->begin(); vertex_i != vertexs->end(); vertex_i++){
00081       if (nVertexCand>=NVrtx) break;
00082       VertexCand_x[nVertexCand] = vertex_i->x();
00083       VertexCand_y[nVertexCand] = vertex_i->y();
00084       VertexCand_z[nVertexCand] = vertex_i->z();
00085       VertexCand_tracks[nVertexCand] = vertex_i->tracksSize();
00086       VertexCand_chi2[nVertexCand] = vertex_i->chi2();
00087       VertexCand_ndof[nVertexCand] = vertex_i->ndof();
00088       if (_Debug) { 
00089         std::cout << "RECOVertex -- VX, VY VZ   = " 
00090                   << VertexCand_x[nVertexCand] << " "
00091                   << VertexCand_y[nVertexCand] << " "
00092                   << VertexCand_z[nVertexCand]
00093                   << std::endl;
00094         std::cout << "RECOVertex -- Ntracks, Chi2/Dof   = " 
00095                   << VertexCand_tracks[nVertexCand] << " "
00096                   << VertexCand_chi2[nVertexCand] << " / " << VertexCand_ndof[nVertexCand]
00097                   << std::endl;
00098       }
00099       nVertexCand++;
00100       
00101     }
00102   }
00103 }
00104