Hi there,
I am trying to find the definition for the at(0) while accessing a vertex collection.
For instance,
MyVertex& primaryVertex = vertex_coll->at(0);
histosTH1F["prim_vtx_zpos"]->Fill( primaryVertex.z, event_weight );
histosTH1F["prim_vtx_xpos"]->Fill( primaryVertex.x, event_weight );
histosTH1F["prim_vtx_ypos"]->Fill( primaryVertex.y, event_weight );
Does 0 in at(0) mean primary vertex? What about at(1)?
thanks in advance,
Luiz
Axel
October 4, 2019, 8:03am
2
Hi Luiz,
Where does that code come from?
Axel.
It comes from CMS analysis code:
//STANDARD ROOT INCLUDES
#include <TROOT.h>
#include <TH1.h>
#include <TH2.h>
#include <TProfile.h>
#include <TStyle.h>
#include <TCanvas.h>
#include <TTree.h>
#include <TFile.h>
#include <TChain.h>
#include <TChainElement.h>
#include <TDirectory.h>
#include “MyVertex.h”
//STANDARD C++ INCLUDES
#include
#include
#include
#include
#include
#include
#include
map<string,TH1F*> histosTH1F;
// Vertices
int n_vertices_selected = 0;
/int idx_vtx_max_sumpt = -1;
double sumpt_max = 0.; /
for(vector::iterator it_vtx = vertex_coll->begin() ; it_vtx != vertex_coll->end() ; ++it_vtx){
int idx_vtx = it_vtx - vertex_coll->begin();
//if( it_vtx->SumPtTracks > sumpt_max ){ idx_vtx_max_sumpt = idx_vtx; sumpt_max = it_vtx->SumPtTracks; }
if( it_vtx->fake ) continue;
if( !it_vtx->validity ) continue;
++n_vertices_selected;
histosTH1F["vtx_zpos"]->Fill( it_vtx->z, event_weight );
histosTH1F["vtx_xpos"]->Fill( it_vtx->x, event_weight );
histosTH1F["vtx_ypos"]->Fill( it_vtx->y, event_weight );
histosTH1F["vtx_ndof"]->Fill( it_vtx->ndof, event_weight );
histosTH1F["vtx_chi2"]->Fill( it_vtx->chi2, event_weight );
}
//histosTH1F["vtx_sumpt_max"]->Fill( idx_vtx_max_sumpt, event_weight );
histosTH1F["vertex_multiplicity"]->Fill( n_vertices_selected, event_weight );
MyVertex& primaryVertex = vertex_coll->at(0);
histosTH1F["prim_vtx_zpos"]->Fill( primaryVertex.z, event_weight );
histosTH1F["prim_vtx_xpos"]->Fill( primaryVertex.x, event_weight );
histosTH1F["prim_vtx_ypos"]->Fill( primaryVertex.y, event_weight );
But I have just found it:
MyPUSumInfo.cc: cout << " --> zposition : " << zposition.at(ivtx) << endl;
slight_smile:
Thanks,
Luiz
Axel
October 4, 2019, 2:01pm
4
Nonetheless, my answer also for future reference:
The code and the data format use ROOT, but ROOT does not define it. So we cannot possibly tell what’s at index 0, you should instead ask those who provide your data or code!
Cheers, Axel
Dear Axel,
I have found the answer:
std::array ::at
reference at ( size_type n );
const_reference at ( size_type n ) const;
Access element
Returns a reference to the element at position n in the array .
The function automatically checks whether n is within the bounds of valid elements in the container, throwing an out_of_range exception if it is not (i.e., if n is greater than, or equal to, its [size](http://www.cplusplus.com/array::size)
). This is in contrast with member operator[] , that does not check against bounds.
Thanks for your attention,
Luiz
Axel
October 8, 2019, 6:15pm
6
That does not say where the primary vertex is. That would be part of your data model, at I explained.
Cheers, Axel
system
Closed
October 22, 2019, 6:15pm
7
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.