CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/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 RECOVertex::~RECOVertex() {
00029   delete[] VertexCand_x;
00030   delete[] VertexCand_y;
00031   delete[] VertexCand_z;
00032   delete[] VertexCand_tracks;
00033   delete[] VertexCand_chi2;
00034   delete[] VertexCand_ndof;
00035 }
00036 
00037 void RECOVertex::clear() 
00038 {
00039   NVrtx          = 0;
00040   std::memset(VertexCand_x,            '\0', kMaxVrt * sizeof(float));
00041   std::memset(VertexCand_y,            '\0', kMaxVrt * sizeof(float));
00042   std::memset(VertexCand_z,            '\0', kMaxVrt * sizeof(float));
00043   std::memset(VertexCand_tracks,       '\0', kMaxVrt * sizeof(int));
00044   std::memset(VertexCand_chi2,         '\0', kMaxVrt * sizeof(float));
00045   std::memset(VertexCand_ndof,         '\0', kMaxVrt * sizeof(float));
00046 }
00047 
00048 /*  Setup the analysis to put the branch-variables into the tree. */
00049 void RECOVertex::setup(const edm::ParameterSet& pSet, TTree* HltTree, std::string vertexType) {
00050 
00051   edm::ParameterSet myHltParams = pSet.getParameter<edm::ParameterSet>("RunParameters") ;
00052   std::vector<std::string> parameterNames = myHltParams.getParameterNames() ;
00053   
00054   for ( std::vector<std::string>::iterator iParam = parameterNames.begin();
00055         iParam != parameterNames.end(); iParam++ ){
00056     if ( (*iParam) == "Debug" ) _Debug =  myHltParams.getParameter<bool>( *iParam );
00057   }
00058 
00059   TString br_recoNVrt = "recoNVrt";
00060   br_recoNVrt.Append(vertexType);
00061   HltTree->Branch(br_recoNVrt,        & NVrtx,            "NVrtx/I");
00062 
00063   TString br_recoVrtX = "recoVrtX";
00064   br_recoVrtX.Append(vertexType);
00065   HltTree->Branch(br_recoVrtX,     VertexCand_x,          "recoVrtX[NVrtx]/F");
00066 
00067   TString br_recoVrtY = "recoVrtY";
00068   br_recoVrtY.Append(vertexType);
00069   HltTree->Branch(br_recoVrtY,     VertexCand_y,          "recoVrtY[NVrtx]/F");
00070 
00071   TString br_recoVrtZ = "recoVrtZ";
00072   br_recoVrtZ.Append(vertexType);
00073   HltTree->Branch(br_recoVrtZ,     VertexCand_z,          "recoVrtZ[NVrtx]/F");
00074 
00075   TString br_recoVrtNtrk = "recoVrtNtrk";
00076   br_recoVrtNtrk.Append(vertexType);
00077   HltTree->Branch(br_recoVrtNtrk,  VertexCand_tracks,     "recoVrtNtrk[NVrtx]/I");
00078 
00079   TString br_recoVrtChi2 = "recoVrtChi2";
00080   br_recoVrtChi2.Append(vertexType);
00081   HltTree->Branch(br_recoVrtChi2,  VertexCand_chi2,       "recoVrtChi2[NVrtx]/F");
00082 
00083   TString br_recoVrtNdof = "recoVrtNdof";
00084   br_recoVrtNdof.Append(vertexType);
00085   HltTree->Branch(br_recoVrtNdof,  VertexCand_ndof,       "recoVrtNdof[NVrtx]/F");
00086 
00087 
00088 
00089 }
00090 
00091 /* **Analyze the event** */
00092 void RECOVertex::analyze(edm::Handle<reco::VertexCollection> recoVertexs, TTree* HltTree) {
00093 
00094   // reset the tree variables
00095   clear();
00096 
00097   if ( recoVertexs.isValid() ) {
00098     const reco::VertexCollection* vertexs = recoVertexs.product();
00099     reco::VertexCollection::const_iterator vertex_i;
00100 
00101     size_t size = std::min(kMaxVrt, size_t(vertexs->size()) ); 
00102     NVrtx= size;
00103 
00104     int nVertexCand=0;
00105     if (_Debug)  std::cout << "Found " << vertexs->size() << " vertices" << std::endl;  
00106     for (vertex_i = vertexs->begin(); vertex_i != vertexs->end(); vertex_i++){
00107       if (nVertexCand>=NVrtx) break;
00108       VertexCand_x[nVertexCand] = vertex_i->x();
00109       VertexCand_y[nVertexCand] = vertex_i->y();
00110       VertexCand_z[nVertexCand] = vertex_i->z();
00111       VertexCand_tracks[nVertexCand] = vertex_i->tracksSize();
00112       VertexCand_chi2[nVertexCand] = vertex_i->chi2();
00113       VertexCand_ndof[nVertexCand] = vertex_i->ndof();
00114       if (_Debug) { 
00115         std::cout << "RECOVertex -- VX, VY VZ   = " 
00116                   << VertexCand_x[nVertexCand] << " "
00117                   << VertexCand_y[nVertexCand] << " "
00118                   << VertexCand_z[nVertexCand]
00119                   << std::endl;
00120         std::cout << "RECOVertex -- Ntracks, Chi2/Dof   = " 
00121                   << VertexCand_tracks[nVertexCand] << " "
00122                   << VertexCand_chi2[nVertexCand] << " / " << VertexCand_ndof[nVertexCand]
00123                   << std::endl;
00124       }
00125       nVertexCand++;
00126       
00127     }
00128   }
00129 }
00130