CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Member Functions | Private Member Functions | Private Attributes
PrimaryVertexAnalyzer Class Reference

#include <Validation/RecoVertex/src/PrimaryVertexAnalyzer.cc>

Inheritance diagram for PrimaryVertexAnalyzer:
edm::EDAnalyzer

Classes

class  simPrimaryVertex
 

Public Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &)
 
virtual void beginJob ()
 
virtual void endJob ()
 
 PrimaryVertexAnalyzer (const edm::ParameterSet &)
 
 ~PrimaryVertexAnalyzer ()
 
- Public Member Functions inherited from edm::EDAnalyzer
 EDAnalyzer ()
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 

Private Member Functions

std::vector< simPrimaryVertexgetSimPVs (const edm::Handle< edm::HepMCProduct > evtMC, std::string suffix)
 
std::vector< simPrimaryVertexgetSimPVs (const edm::Handle< edm::HepMCProduct > evt, const edm::Handle< edm::SimVertexContainer > simVtxs, const edm::Handle< edm::SimTrackContainer > simTrks)
 
bool isCharged (const HepMC::GenParticle *p)
 
bool isFinalstateParticle (const HepMC::GenParticle *p)
 
bool isResonance (const HepMC::GenParticle *p)
 
bool matchVertex (const simPrimaryVertex &vsim, const reco::Vertex &vrec)
 
void printRecVtxs (const edm::Handle< reco::VertexCollection > recVtxs)
 
void printSimTrks (const edm::Handle< edm::SimTrackContainer > simVtrks)
 
void printSimVtxs (const edm::Handle< edm::SimVertexContainer > simVtxs)
 

Private Attributes

std::map< std::string, TH1 * > h
 
std::map< std::string,
TDirectory * > 
hdir
 
std::string outputFile_
 
edm::ESHandle< ParticleDataTablepdt
 
std::string recoTrackProducer_
 
TFile * rootFile_
 
edm::InputTag simG4_
 
double simUnit_
 
std::vector< std::string > suffixSample_
 
bool verbose_
 
std::vector< std::string > vtxSample_
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
typedef WorkerT< EDAnalyzerWorkerType
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
- Protected Member Functions inherited from edm::EDAnalyzer
CurrentProcessingContext const * currentContext () const
 

Detailed Description

Description: simple primary vertex analyzer

Implementation: <Notes on="" implementation>="">

Definition at line 61 of file PrimaryVertexAnalyzer.h.

Constructor & Destructor Documentation

PrimaryVertexAnalyzer::PrimaryVertexAnalyzer ( const edm::ParameterSet iConfig)
explicit

Definition at line 49 of file PrimaryVertexAnalyzer.cc.

References spr::find(), edm::ParameterSet::getParameter(), edm::getReleaseVersion(), and edm::ParameterSet::getUntrackedParameter().

50 {
51  //now do what ever initialization is needed
52  simG4_=iConfig.getParameter<edm::InputTag>( "simG4" );
53  recoTrackProducer_= iConfig.getUntrackedParameter<std::string>("recoTrackProducer");
54  // open output file to store histograms}
55  outputFile_ = iConfig.getUntrackedParameter<std::string>("outputFile");
56  TString tversion(edm::getReleaseVersion());
57  tversion = tversion.Remove(0,1);
58  tversion = tversion.Remove(tversion.Length()-1,tversion.Length());
59  outputFile_ = std::string(tversion)+"_"+outputFile_;
60 
61  vtxSample_ = iConfig.getUntrackedParameter<std::vector< std::string > >("vtxSample");
62  for(std::vector<std::string>::iterator isample = vtxSample_.begin(); isample!=vtxSample_.end(); ++isample) {
63  if ( *isample == "offlinePrimaryVertices" ) suffixSample_.push_back("AVF");
64  if ( *isample == "offlinePrimaryVerticesWithBS" ) suffixSample_.push_back("wBS");
65  }
66  if ( suffixSample_.size() == 0 ) throw cms::Exception("NoVertexSamples") << " no known vertex samples given";
67 
68  rootFile_ = new TFile(outputFile_.c_str(),"RECREATE");
69  verbose_= iConfig.getUntrackedParameter<bool>("verbose", false);
70  simUnit_= 1.0; // starting with CMSSW_1_2_x ??
71  if ( (edm::getReleaseVersion()).find("CMSSW_1_1_",0)!=std::string::npos){
72  simUnit_=0.1; // for use in CMSSW_1_1_1 tutorial
73  }
74 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
std::vector< std::string > vtxSample_
std::string getReleaseVersion()
std::vector< std::string > suffixSample_
PrimaryVertexAnalyzer::~PrimaryVertexAnalyzer ( )

Definition at line 77 of file PrimaryVertexAnalyzer.cc.

78 {
79  // do anything here that needs to be done at desctruction time
80  // (e.g. close files, deallocate resources etc.)
81  delete rootFile_;
82  /*for(std::map<std::string,TH1*>::const_iterator hist=h.begin(); hist!=h.end(); hist++){
83  delete hist->second;
84  }*/
85 
86 }

Member Function Documentation

void PrimaryVertexAnalyzer::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
)
virtual

Implements edm::EDAnalyzer.

Definition at line 406 of file PrimaryVertexAnalyzer.cc.

References ChiSquaredProbability(), gather_cfg::cout, data, edm::Event::getByLabel(), edm::EventSetup::getData(), h, i, getHLTprescales::index, edm::isnan(), edm::HandleBase::isValid(), j, m, NULL, lumiQTWidget::t, v, w(), and detailsBasic3DVector::z.

407 {
408 
410  iEvent.getByLabel(recoTrackProducer_, recTrks);
411 
413  iEvent.getByLabel( simG4_, simVtxs);
414 
416  iEvent.getByLabel( simG4_, simTrks);
417 
418  for (int ivtxSample=0; ivtxSample!= (int)vtxSample_.size(); ++ivtxSample) {
419  std::string isuffix = suffixSample_[ivtxSample];
420 
422  iEvent.getByLabel(vtxSample_[ivtxSample], recVtxs);
423 
424  try{
425  iSetup.getData(pdt);
426  }catch(const Exception&){
427  std::cout << "Some problem occurred with the particle data table. This may not work !." <<std::endl;
428  }
429 
430  bool MC=false;
431  Handle<HepMCProduct> evtMC;
432  iEvent.getByLabel("generator",evtMC);
433  if (!evtMC.isValid()) {
434  MC=false;
435  if(verbose_){
436  std::cout << "no HepMCProduct found"<< std::endl;
437  }
438  } else {
439  if(verbose_){
440  std::cout << "generator HepMCProduct found"<< std::endl;
441  }
442  MC=true;
443  }
444 
445 
446  if(verbose_){
447  //evtMC->GetEvent()->print();
448  printRecVtxs(recVtxs);
449  //printSimVtxs(simVtxs);
450  //printSimTrks(simTrks);
451  }
452 
453  if(MC){
454  // make a list of primary vertices:
455  std::vector<simPrimaryVertex> simpv;
456  //simpv=getSimPVs(evtMC, simVtxs, simTrks);
457  simpv=getSimPVs(evtMC,isuffix);
458 
459 
460  // vertex matching and efficiency bookkeeping
461  h["nsimvtx"+isuffix]->Fill(simpv.size());
462  int nsimtrk=0;
463  for(std::vector<simPrimaryVertex>::iterator vsim=simpv.begin();
464  vsim!=simpv.end(); vsim++){
465 
466  hdir[isuffix]->cd();
467 
468  h["nbsimtksinvtx"+isuffix]->Fill(vsim->nGenTrk);
469  h["xsim"+isuffix]->Fill(vsim->x*simUnit_);
470  h["ysim"+isuffix]->Fill(vsim->y*simUnit_);
471  h["zsim"+isuffix]->Fill(vsim->z*simUnit_);
472  nsimtrk+=vsim->nGenTrk;
473  // look for a matching reconstructed vertex
474  vsim->recVtx=NULL;
475  for(reco::VertexCollection::const_iterator vrec=recVtxs->begin();
476  vrec!=recVtxs->end(); ++vrec){
477  if ( matchVertex(*vsim,*vrec) ){
478  // if the matching critera are fulfilled, accept the rec-vertex that is closest in z
479  if( ((vsim->recVtx) && (fabs(vsim->recVtx->position().z()-vsim->z)>fabs(vrec->z()-vsim->z)))
480  || (!vsim->recVtx) )
481  {
482  vsim->recVtx=&(*vrec);
483  }
484  }
485  }
486  h["nsimtrk"+isuffix]->Fill(float(nsimtrk));
487 
488 
489  // histogram properties of matched vertices
490  if (vsim->recVtx){
491 
492  if(verbose_){std::cout <<"primary matched " << vsim->x << " " << vsim->y << " " << vsim->z << std:: endl;}
493 
494  h["resx"+isuffix]->Fill( vsim->recVtx->x()-vsim->x*simUnit_ );
495  h["resy"+isuffix]->Fill( vsim->recVtx->y()-vsim->y*simUnit_ );
496  h["resz"+isuffix]->Fill( vsim->recVtx->z()-vsim->z*simUnit_ );
497  h["pullx"+isuffix]->Fill( (vsim->recVtx->x()-vsim->x*simUnit_)/vsim->recVtx->xError() );
498  h["pully"+isuffix]->Fill( (vsim->recVtx->y()-vsim->y*simUnit_)/vsim->recVtx->yError() );
499  h["pullz"+isuffix]->Fill( (vsim->recVtx->z()-vsim->z*simUnit_)/vsim->recVtx->zError() );
500  h["eff"+isuffix]->Fill( 1.);
501  if(simpv.size()==1){
502  if (vsim->recVtx==&(*recVtxs->begin())){
503  h["efftag"+isuffix]->Fill( 1.);
504  }else{
505  h["efftag"+isuffix]->Fill( 0.);
506  }
507  }
508  h["effvseta"+isuffix]->Fill(vsim->ptot.pseudoRapidity(),1.);
509  h["effvsptsq"+isuffix]->Fill(vsim->ptsq,1.);
510  h["effvsntrk"+isuffix]->Fill(vsim->nGenTrk,1.);
511  h["effvsnrectrk"+isuffix]->Fill(recTrks->size(),1.);
512  h["effvsz"+isuffix]->Fill(vsim->z*simUnit_,1.);
513 
514  }else{ // no rec vertex found for this simvertex
515 
516  if(verbose_){std::cout <<"primary not found " << vsim->x << " " << vsim->y << " " << vsim->z << " nGenTrk=" << vsim->nGenTrk << std::endl;}
517 
518  h["eff"+isuffix]->Fill( 0.);
519  if(simpv.size()==1){ h["efftag"+isuffix]->Fill( 0.); }
520  h["effvseta"+isuffix]->Fill(vsim->ptot.pseudoRapidity(),0.);
521  h["effvsptsq"+isuffix]->Fill(vsim->ptsq,0.);
522  h["effvsntrk"+isuffix]->Fill(float(vsim->nGenTrk),0.);
523  h["effvsnrectrk"+isuffix]->Fill(recTrks->size(),0.);
524  h["effvsz"+isuffix]->Fill(vsim->z*simUnit_,0.);
525  } // no recvertex for this simvertex
526  }//found MC event
527  // end of sim/rec matching
528 
529 
530  // purity of event vertex tags
531  if (recVtxs->size()>0 && simpv.size()>0){
532  Double_t dz=(*recVtxs->begin()).z() - (*simpv.begin()).z*simUnit_;
533  h["zdistancetag"+isuffix]->Fill(dz);
534  if( fabs(dz)<0.0500){
535  h["puritytag"+isuffix]->Fill(1.);
536  }else{
537  // bad tag: the true primary was more than 500 um away from the tagged primary
538  h["puritytag"+isuffix]->Fill(0.);
539  }
540  }
541 
542 
543  }// MC event
544 
545  // test track links, use reconstructed vertices
546 
547  h["nrecvtx"+isuffix]->Fill(recVtxs->size());
548  h["nrectrk"+isuffix]->Fill(recTrks->size());
549  h["nbvtx"+isuffix]->Fill(recVtxs->size()*1.);
550  if((recVtxs->size()==0)||recVtxs->begin()->isFake()) {h["nrectrk0vtx"+isuffix]->Fill(recTrks->size());}
551 
552  for(reco::VertexCollection::const_iterator v=recVtxs->begin();
553  v!=recVtxs->end(); ++v){
554 
555  if(v->isFake()) continue;
556 
557  try {
558  for(reco::Vertex::trackRef_iterator t = v->tracks_begin();
559  t!=v->tracks_end(); t++) {
560  // illegal charge
561  if ( (**t).charge() < -1 || (**t).charge() > 1 ) {
562  h["tklinks"+isuffix]->Fill(0.);
563  }
564  else {
565  h["tklinks"+isuffix]->Fill(1.);
566  }
567  }
568  }
569  catch (...) {
570  // exception thrown when trying to use linked track
571  h["tklinks"+isuffix]->Fill(0.);
572  }
573 
574  h["nbtksinvtx"+isuffix]->Fill(v->tracksSize());
575  h["vtxchi2"+isuffix]->Fill(v->chi2());
576  h["vtxndf"+isuffix]->Fill(v->ndof());
577  h["vtxprob"+isuffix]->Fill(ChiSquaredProbability(v->chi2() ,v->ndof()));
578  h["xrec"+isuffix]->Fill(v->position().x());
579  h["yrec"+isuffix]->Fill(v->position().y());
580  h["zrec"+isuffix]->Fill(v->position().z());
581  if (v==recVtxs->begin()){
582  h["xrectag"+isuffix]->Fill(v->position().x());
583  h["yrectag"+isuffix]->Fill(v->position().y());
584  h["zrectag"+isuffix]->Fill(v->position().z());
585  }
586 
587  bool problem = false;
588  h["nans"+isuffix]->Fill(1.,isnan(v->position().x())*1.);
589  h["nans"+isuffix]->Fill(2.,isnan(v->position().y())*1.);
590  h["nans"+isuffix]->Fill(3.,isnan(v->position().z())*1.);
591 
592  int index = 3;
593  for (int i = 0; i != 3; i++) {
594  for (int j = i; j != 3; j++) {
595  index++;
596  h["nans"+isuffix]->Fill(index*1., isnan(v->covariance(i, j))*1.);
597  if (isnan(v->covariance(i, j))) problem = true;
598  // in addition, diagonal element must be positive
599  if (j == i && v->covariance(i, j) < 0) {
600  h["nans"+isuffix]->Fill(index*1., 1.);
601  problem = true;
602  }
603  }
604  }
605 
606  if (problem) {
607  // analyze track parameter covariance definiteness
608  double data[25];
609  try {
610  int itk = 0;
611  for(reco::Vertex::trackRef_iterator t = v->tracks_begin();
612  t!=v->tracks_end(); t++) {
613  std::cout << "Track " << itk++ << std::endl;
614  int i2 = 0;
615  for (int i = 0; i != 5; i++) {
616  for (int j = 0; j != 5; j++) {
617  data[i2] = (**t).covariance(i, j);
618  std::cout << std:: scientific << data[i2] << " ";
619  i2++;
620  }
621  std::cout << std::endl;
622  }
623  gsl_matrix_view m
624  = gsl_matrix_view_array (data, 5, 5);
625 
626  gsl_vector *eval = gsl_vector_alloc (5);
627  gsl_matrix *evec = gsl_matrix_alloc (5, 5);
628 
629  gsl_eigen_symmv_workspace * w =
630  gsl_eigen_symmv_alloc (5);
631 
632  gsl_eigen_symmv (&m.matrix, eval, evec, w);
633 
634  gsl_eigen_symmv_free (w);
635 
636  gsl_eigen_symmv_sort (eval, evec,
637  GSL_EIGEN_SORT_ABS_ASC);
638 
639  // print sorted eigenvalues
640  {
641  int i;
642  for (i = 0; i < 5; i++) {
643  double eval_i
644  = gsl_vector_get (eval, i);
645  //gsl_vector_view evec_i
646  // = gsl_matrix_column (evec, i);
647 
648  printf ("eigenvalue = %g\n", eval_i);
649  // printf ("eigenvector = \n");
650  // gsl_vector_fprintf (stdout,
651  // &evec_i.vector, "%g");
652  }
653  }
654  }
655  }
656  catch (...) {
657  // exception thrown when trying to use linked track
658  break;
659  }
660  }// if (problem)
661  }
662  } // for vertex loop
663 }
int i
Definition: DBlmapReader.cc:9
std::vector< simPrimaryVertex > getSimPVs(const edm::Handle< edm::HepMCProduct > evtMC, std::string suffix)
std::map< std::string, TDirectory * > hdir
#define NULL
Definition: scimark2.h:8
double double double z
void getData(T &iHolder) const
Definition: EventSetup.h:67
edm::ESHandle< ParticleDataTable > pdt
bool isnan(float x)
Definition: math.h:13
std::vector< std::string > vtxSample_
int j
Definition: DBlmapReader.cc:9
float ChiSquaredProbability(double chiSquared, double nrDOF)
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
std::map< std::string, TH1 * > h
void printRecVtxs(const edm::Handle< reco::VertexCollection > recVtxs)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
std::vector< TrackBaseRef >::const_iterator trackRef_iterator
The iteratator for the vector&lt;TrackRef&gt;
Definition: Vertex.h:38
tuple cout
Definition: gather_cfg.py:121
std::vector< std::string > suffixSample_
bool matchVertex(const simPrimaryVertex &vsim, const reco::Vertex &vrec)
mathSSE::Vec4< T > v
T w() const
void PrimaryVertexAnalyzer::beginJob ( void  )
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 93 of file PrimaryVertexAnalyzer.cc.

References gather_cfg::cout, and h.

93  {
94  std::cout << " PrimaryVertexAnalyzer::beginJob conversion from sim units to rec units is " << simUnit_ << std::endl;
95 
96 
97  rootFile_->cd();
98  // release validation histograms used in DoCompare.C
99  for (std::vector<std::string>::iterator isuffix= suffixSample_.begin(); isuffix!=suffixSample_.end(); isuffix++) {
100 
101  hdir[*isuffix] = rootFile_->mkdir(TString(*isuffix));
102  hdir[*isuffix]->cd();
103  h["nbvtx"+ *isuffix] = new TH1F(TString("nbvtx"+ *isuffix),"Reconstructed Vertices in Event",20,-0.5,19.5);
104  h["nbtksinvtx"+ *isuffix] = new TH1F(TString("nbtksinvtx"+ *isuffix),"Reconstructed Tracks in Vertex",200,-0.5,199.5);
105  h["resx"+ *isuffix] = new TH1F(TString("resx"+ *isuffix),"Residual X",100,-0.04,0.04);
106  h["resy"+ *isuffix] = new TH1F(TString("resy"+ *isuffix),"Residual Y",100,-0.04,0.04);
107  h["resz"+ *isuffix] = new TH1F(TString("resz"+ *isuffix),"Residual Z",100,-0.1,0.1);
108  h["pullx"+ *isuffix] = new TH1F(TString("pullx"+ *isuffix),"Pull X",100,-25.,25.);
109  h["pully"+ *isuffix] = new TH1F(TString("pully"+ *isuffix),"Pull Y",100,-25.,25.);
110  h["pullz"+ *isuffix] = new TH1F(TString("pullz"+ *isuffix),"Pull Z",100,-25.,25.);
111  h["vtxchi2"+ *isuffix] = new TH1F(TString("vtxchi2"+ *isuffix),"#chi^{2}",100,0.,100.);
112  h["vtxndf"+ *isuffix] = new TH1F(TString("vtxndf"+ *isuffix),"ndof",100,0.,100.);
113  h["tklinks"+ *isuffix] = new TH1F(TString("tklinks"+ *isuffix),"Usable track links",2,-0.5,1.5);
114  h["nans"+ *isuffix] = new TH1F(TString("nans"+ *isuffix),"Illegal values for x,y,z,xx,xy,xz,yy,yz,zz",9,0.5,9.5);
115  // more histograms
116  h["vtxprob"+ *isuffix] = new TH1F(TString("vtxprob"+ *isuffix),"#chi^{2} probability",100,0.,1.);
117  h["eff"+ *isuffix] = new TH1F(TString("eff"+ *isuffix),"efficiency",2, -0.5, 1.5);
118  h["efftag"+ *isuffix] = new TH1F(TString("efftag"+ *isuffix),"efficiency tagged vertex",2, -0.5, 1.5);
119  h["effvseta"+ *isuffix] = new TProfile(TString("effvseta"+ *isuffix),"efficiency vs eta",20, -2.5, 2.5, 0, 1.);
120  h["effvsptsq"+ *isuffix] = new TProfile(TString("effvsptsq"+ *isuffix),"efficiency vs ptsq",20, 0., 10000., 0, 1.);
121  h["effvsntrk"+ *isuffix] = new TProfile(TString("effvsntrk"+ *isuffix),"efficiency vs # simtracks",200, 0., 200., 0, 1.);
122  h["effvsnrectrk"+ *isuffix] = new TProfile(TString("effvsnrectrk"+ *isuffix),"efficiency vs # rectracks",200, 0., 200., 0, 1.);
123  h["effvsz"+ *isuffix] = new TProfile(TString("effvsz"+ *isuffix),"efficiency vs z",40, -20., 20., 0, 1.);
124  h["nbsimtksinvtx"+ *isuffix]= new TH1F(TString("nbsimtksinvtx"+ *isuffix),"simulated tracks in vertex",100,-0.5,99.5);
125  h["xrec"+ *isuffix] = new TH1F(TString("xrec"+ *isuffix),"reconstructed x",100,-0.1,0.1);
126  h["yrec"+ *isuffix] = new TH1F(TString("yrec"+ *isuffix),"reconstructed y",100,-0.1,0.1);
127  h["zrec"+ *isuffix] = new TH1F(TString("zrec"+ *isuffix),"reconstructed z",100,-20.,20.);
128  h["xsim"+ *isuffix] = new TH1F(TString("xsim"+ *isuffix),"simulated x",100,-0.1,0.1);
129  h["ysim"+ *isuffix] = new TH1F(TString("ysim"+ *isuffix),"simulated y",100,-0.1,0.1);
130  h["zsim"+ *isuffix] = new TH1F(TString("zsim"+ *isuffix),"simulated z",100,-20.,20.);
131  h["nrecvtx"+ *isuffix] = new TH1F(TString("nrecvtx"+ *isuffix),"# of reconstructed vertices", 50, -0.5, 49.5);
132  h["nsimvtx"+ *isuffix] = new TH1F(TString("nsimvtx"+ *isuffix),"# of simulated vertices", 50, -0.5, 49.5);
133  h["nrectrk"+ *isuffix] = new TH1F(TString("nrectrk"+ *isuffix),"# of reconstructed tracks", 200, -0.5, 199.5);
134  h["nsimtrk"+ *isuffix] = new TH1F(TString("nsimtrk"+ *isuffix),"# of simulated tracks", 200, -0.5, 199.5);
135  h["xrectag"+ *isuffix] = new TH1F(TString("xrectag"+ *isuffix),"reconstructed x, signal vtx",100,-0.1,0.1);
136  h["yrectag"+ *isuffix] = new TH1F(TString("yrectag"+ *isuffix),"reconstructed y, signal vtx",100,-0.1,0.1);
137  h["zrectag"+ *isuffix] = new TH1F(TString("zrectag"+ *isuffix),"reconstructed z, signal vtx",100,-20.,20.);
138  h["rapidity"+ *isuffix] = new TH1F(TString("rapidity"+ *isuffix),"rapidity ",100,-10., 10.);
139  h["pt"+ *isuffix] = new TH1F(TString("pt"+ *isuffix),"pt ",100,0., 20.);
140  h["nrectrk0vtx"+ *isuffix] = new TH1F(TString("nrectrk0vtx"+ *isuffix),"# rec tracks no vertex ",200,0., 200.);
141  h["zdistancetag"+ *isuffix] = new TH1F(TString("zdistancetag"+ *isuffix),"z-distance between tagged and generated",100, -0.1, 0.1);
142  h["puritytag"+ *isuffix] = new TH1F(TString("puritytag"+ *isuffix),"purity of primary vertex tags",2, -0.5, 1.5);
143  }
144 
145 }
std::map< std::string, TDirectory * > hdir
std::map< std::string, TH1 * > h
tuple cout
Definition: gather_cfg.py:121
std::vector< std::string > suffixSample_
void PrimaryVertexAnalyzer::endJob ( void  )
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 148 of file PrimaryVertexAnalyzer.cc.

References h, and estimatePileup::hist.

148  {
149  rootFile_->cd();
150  // save all histograms created in beginJob()
151  for (std::map<std::string, TDirectory*>::const_iterator idir=hdir.begin(); idir!=hdir.end(); idir++){
152  idir->second->cd();
153  for(std::map<std::string,TH1*>::const_iterator hist=h.begin(); hist!=h.end(); hist++){
154  if (TString(hist->first).Contains(idir->first)) hist->second->Write();
155  }
156  }
157 }
std::map< std::string, TDirectory * > hdir
std::map< std::string, TH1 * > h
std::vector< PrimaryVertexAnalyzer::simPrimaryVertex > PrimaryVertexAnalyzer::getSimPVs ( const edm::Handle< edm::HepMCProduct evtMC,
std::string  suffix = "" 
)
private

Definition at line 240 of file PrimaryVertexAnalyzer.cc.

References gather_cfg::cout, alignCSCRings::e, spr::find(), h, m, NULL, parents, pos, and createPayload::suffix.

242 {
243  std::vector<PrimaryVertexAnalyzer::simPrimaryVertex> simpv;
244  const HepMC::GenEvent* evt=evtMC->GetEvent();
245  if (evt) {
246  if(verbose_) std::cout << "process id " <<evt->signal_process_id()<<std::endl;
247  if(verbose_) std::cout <<"signal process vertex "<< ( evt->signal_process_vertex() ?
248  evt->signal_process_vertex()->barcode() : 0 ) <<std::endl;
249  if(verbose_) std::cout <<"number of vertices " << evt->vertices_size() << std::endl;
250 
251 
252  int idx=0;
253  for(HepMC::GenEvent::vertex_const_iterator vitr= evt->vertices_begin();
254  vitr != evt->vertices_end(); ++vitr )
255  { // loop for vertex ...
256  HepMC::FourVector pos = (*vitr)->position();
257  //HepLorentzVector pos = (*vitr)->position();
258 
259  bool hasMotherVertex=false;
260  if(verbose_) std::cout << "mothers of vertex[" << ++idx << "]: " << std::endl;
261  for ( HepMC::GenVertex::particle_iterator
262  mother = (*vitr)->particles_begin(HepMC::parents);
263  mother != (*vitr)->particles_end(HepMC::parents);
264  ++mother ) {
265  HepMC::GenVertex * mv=(*mother)->production_vertex();
266  if (mv) {
267  hasMotherVertex=true;
268  if(!verbose_) break; //if verbose_, print all particles of gen vertices
269  }
270  if(verbose_)std::cout << "\t";
271  if(verbose_)(*mother)->print();
272  }
273 
274  if(hasMotherVertex) {continue;}
275 
276  // could be a new vertex, check all primaries found so far to avoid multiple entries
277  const double mm=0.1;
278  simPrimaryVertex sv(pos.x()*mm,pos.y()*mm,pos.z()*mm);
279  simPrimaryVertex *vp=NULL; // will become non-NULL if a vertex is found and then point to it
280  for(std::vector<simPrimaryVertex>::iterator v0=simpv.begin();
281  v0!=simpv.end(); v0++){
282  if( (fabs(sv.x-v0->x)<1e-5) && (fabs(sv.y-v0->y)<1e-5) && (fabs(sv.z-v0->z)<1e-5)){
283  vp=&(*v0);
284  break;
285  }
286  }
287 
288  if(!vp){
289  // this is a new vertex
290  if(verbose_)std::cout << "this is a new vertex " << sv.x << " " << sv.y << " " << sv.z << std::endl;
291  simpv.push_back(sv);
292  vp=&simpv.back();
293  }else{
294  if(verbose_)std::cout << "this is not new vertex " << sv.x << " " << sv.y << " " << sv.z << std::endl;
295  }
296  vp->genVertex.push_back((*vitr)->barcode());
297  // collect final state descendants
298  for ( HepMC::GenVertex::particle_iterator
299  daughter = (*vitr)->particles_begin(HepMC::descendants);
300  daughter != (*vitr)->particles_end(HepMC::descendants);
301  ++daughter ) {
302  if (isFinalstateParticle(*daughter)){
303  if ( find(vp->finalstateParticles.begin(), vp->finalstateParticles.end(),(*daughter)->barcode())
304  == vp->finalstateParticles.end()){
305  vp->finalstateParticles.push_back((*daughter)->barcode());
306  HepMC::FourVector m=(*daughter)->momentum();
307  // the next four lines used to be "vp->ptot+=m;" in the days of CLHEP::HepLorentzVector
308  // but adding FourVectors seems not to be foreseen
309  vp->ptot.setPx(vp->ptot.px()+m.px());
310  vp->ptot.setPy(vp->ptot.py()+m.py());
311  vp->ptot.setPz(vp->ptot.pz()+m.pz());
312  vp->ptot.setE(vp->ptot.e()+m.e());
313  vp->ptsq+=(m.perp())*(m.perp());
314  if ( (m.perp()>0.8) && (fabs(m.pseudoRapidity())<2.5) && isCharged( *daughter ) ){
315  vp->nGenTrk++;
316  }
317 
318  h["rapidity"+suffix]->Fill(m.pseudoRapidity());
319  h["pt"+suffix]->Fill(m.perp());
320  }
321  }
322  }
323  }
324  }
325  return simpv;
326 }
TPRegexp parents
Definition: eve_filter.cc:24
bool isCharged(const HepMC::GenParticle *p)
bool isFinalstateParticle(const HepMC::GenParticle *p)
#define NULL
Definition: scimark2.h:8
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
std::map< std::string, TH1 * > h
tuple cout
Definition: gather_cfg.py:121
std::vector< PrimaryVertexAnalyzer::simPrimaryVertex > PrimaryVertexAnalyzer::getSimPVs ( const edm::Handle< edm::HepMCProduct evt,
const edm::Handle< edm::SimVertexContainer simVtxs,
const edm::Handle< edm::SimTrackContainer simTrks 
)
private

Definition at line 330 of file PrimaryVertexAnalyzer.cc.

References configurableAnalysis::GenParticle, or, resonance, PrimaryVertexAnalyzer::simPrimaryVertex::simTrackIndex, lumiQTWidget::t, and v.

334 {
335  // simvertices don't have enough information to decide,
336  // genVertices don't have the simulated coordinates ( with VtxSmeared they might)
337  // go through simtracks to get the link between simulated and generated vertices
338  std::vector<PrimaryVertexAnalyzer::simPrimaryVertex> simpv;
339  int idx=0;
340  for(SimTrackContainer::const_iterator t=simTrks->begin();
341  t!=simTrks->end(); ++t){
342  if ( !(t->noVertex()) && !(t->type()==-99) ){
343  double ptsq=0;
344  bool primary=false; // something coming directly from the primary vertex
345  bool resonance=false; // resonance
346  bool track=false; // undecayed, charged particle
347  HepMC::GenParticle* gp=evtMC->GetEvent()->barcode_to_particle( (*t).genpartIndex() );
348  if (gp) {
349  HepMC::GenVertex * gv=gp->production_vertex();
350  if (gv) {
351  for ( HepMC::GenVertex::particle_iterator
352  daughter = gv->particles_begin(HepMC::descendants);
353  daughter != gv->particles_end(HepMC::descendants);
354  ++daughter ) {
355  if (isFinalstateParticle(*daughter)){
356  ptsq+=(*daughter)->momentum().perp()*(*daughter)->momentum().perp();
357  }
358  }
359  primary = ( gv->position().t()==0);
360  //resonance= ( gp->mother() && isResonance(gp->mother())); // in CLHEP/HepMC days
361  // no more mother pointer in the improved HepMC GenParticle
362  resonance= ( isResonance(*(gp->production_vertex()->particles_in_const_begin())));
363  if (gp->status()==1){
364  //track=((pdt->particle(gp->pdg_id()))->charge() != 0);
365  track=not isCharged(gp);
366  }
367  }
368  }
369 
370  const HepMC::FourVector & v=(*simVtxs)[t->vertIndex()].position();
371  //const HepLorentzVector & v=(*simVtxs)[t->vertIndex()].position();
372  if(primary or resonance){
373  {
374  // check all primaries found so far to avoid multiple entries
375  bool newVertex=true;
376  for(std::vector<simPrimaryVertex>::iterator v0=simpv.begin();
377  v0!=simpv.end(); v0++){
378  if( (fabs(v0->x-v.x())<0.001) && (fabs(v0->y-v.y())<0.001) && (fabs(v0->z-v.z())<0.001) ){
379  if (track) {
380  v0->simTrackIndex.push_back(idx);
381  if (ptsq>(*v0).ptsq){(*v0).ptsq=ptsq;}
382  }
383  newVertex=false;
384  }
385  }
386  if(newVertex && !resonance){
387  simPrimaryVertex anotherVertex(v.x(),v.y(),v.z());
388  if (track) anotherVertex.simTrackIndex.push_back(idx);
389  anotherVertex.ptsq=ptsq;
390  simpv.push_back(anotherVertex);
391  }
392  }//
393  }
394 
395  }// simtrack has vertex and valid type
396  idx++;
397  }//simTrack loop
398  return simpv;
399 }
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
bool isCharged(const HepMC::GenParticle *p)
bool isFinalstateParticle(const HepMC::GenParticle *p)
const std::pair< int, int > resonance[nResonances]
Definition: Histograms.cc:75
bool isResonance(const HepMC::GenParticle *p)
mathSSE::Vec4< T > v
bool PrimaryVertexAnalyzer::isCharged ( const HepMC::GenParticle *  p)
private

Definition at line 176 of file PrimaryVertexAnalyzer.cc.

176  {
177  const ParticleData * part = pdt->particle( p->pdg_id() );
178  if (part){
179  return part->charge()!=0;
180  }else{
181  // the new/improved particle table doesn't know anti-particles
182  return pdt->particle( -p->pdg_id() )!=0;
183  }
184 }
edm::ESHandle< ParticleDataTable > pdt
HepPDT::ParticleData ParticleData
part
Definition: HCALResponse.h:21
bool PrimaryVertexAnalyzer::isFinalstateParticle ( const HepMC::GenParticle *  p)
private

Definition at line 172 of file PrimaryVertexAnalyzer.cc.

172  {
173  return ( !p->end_vertex() && p->status()==1 );
174 }
bool PrimaryVertexAnalyzer::isResonance ( const HepMC::GenParticle *  p)
private

Definition at line 166 of file PrimaryVertexAnalyzer.cc.

References abs, gather_cfg::cout, and alignCSCRings::e.

166  {
167  double ctau=(pdt->particle( abs(p->pdg_id()) ))->lifetime();
168  if(verbose_) std::cout << "isResonance " << p->pdg_id() << " " << ctau << std::endl;
169  return ctau >0 && ctau <1e-6;
170 }
#define abs(x)
Definition: mlp_lapack.h:159
edm::ESHandle< ParticleDataTable > pdt
tuple cout
Definition: gather_cfg.py:121
bool PrimaryVertexAnalyzer::matchVertex ( const simPrimaryVertex vsim,
const reco::Vertex vrec 
)
private

Definition at line 161 of file PrimaryVertexAnalyzer.cc.

References PrimaryVertexAnalyzer::simPrimaryVertex::z, and reco::Vertex::z().

162  {
163  return (fabs(vsim.z*simUnit_-vrec.z())<0.0500); // =500um
164 }
double z() const
y coordinate
Definition: Vertex.h:99
void PrimaryVertexAnalyzer::printRecVtxs ( const edm::Handle< reco::VertexCollection recVtxs)
private

Definition at line 186 of file PrimaryVertexAnalyzer.cc.

References gather_cfg::cout, and v.

186  {
187  int ivtx=0;
188  for(reco::VertexCollection::const_iterator v=recVtxs->begin();
189  v!=recVtxs->end(); ++v){
190  std::cout << "Recvtx "<< std::setw(3) << std::setfill(' ')<<ivtx++
191  << "#trk " << std::setw(3) << v->tracksSize()
192  << " chi2 " << std::setw(4) << v->chi2()
193  << " ndof " << std::setw(3) << v->ndof() << std::endl
194  << " x " << std::setw(8) <<std::fixed << std::setprecision(4) << v->x()
195  << " dx " << std::setw(8) << v->xError()<< std::endl
196  << " y " << std::setw(8) << v->y()
197  << " dy " << std::setw(8) << v->yError()<< std::endl
198  << " z " << std::setw(8) << v->z()
199  << " dz " << std::setw(8) << v->zError()
200  << std::endl;
201  }
202 }
tuple cout
Definition: gather_cfg.py:121
mathSSE::Vec4< T > v
void PrimaryVertexAnalyzer::printSimTrks ( const edm::Handle< edm::SimTrackContainer simVtrks)
private

Definition at line 221 of file PrimaryVertexAnalyzer.cc.

References gather_cfg::cout, i, and lumiQTWidget::t.

221  {
222  std::cout << " simTrks type, (momentum), vertIndex, genpartIndex" << std::endl;
223  int i=1;
224  for(SimTrackContainer::const_iterator t=simTrks->begin();
225  t!=simTrks->end(); ++t){
226  //HepMC::GenParticle* gp=evtMC->GetEvent()->particle( (*t).genpartIndex() );
227  std::cout << i++ << ")"
228  << (*t)
229  << " index="
230  << (*t).genpartIndex();
231  //if (gp) {
232  // HepMC::GenVertex *gv=gp->production_vertex();
233  // std::cout << " genvertex =" << (*gv);
234  //}
235  std::cout << std::endl;
236  }
237 }
int i
Definition: DBlmapReader.cc:9
tuple cout
Definition: gather_cfg.py:121
void PrimaryVertexAnalyzer::printSimVtxs ( const edm::Handle< edm::SimVertexContainer simVtxs)
private

Definition at line 205 of file PrimaryVertexAnalyzer.cc.

References gather_cfg::cout, and i.

205  {
206  int i=0;
207  for(SimVertexContainer::const_iterator vsim=simVtxs->begin();
208  vsim!=simVtxs->end(); ++vsim){
209  std::cout << i++ << ")" << std::scientific
210  << " evtid=" << vsim->eventId().event()
211  << " sim x=" << vsim->position().x()*simUnit_
212  << " sim y=" << vsim->position().y()*simUnit_
213  << " sim z=" << vsim->position().z()*simUnit_
214  << " sim t=" << vsim->position().t()
215  << " parent=" << vsim->parentIndex()
216  << std::endl;
217  }
218 }
int i
Definition: DBlmapReader.cc:9
tuple cout
Definition: gather_cfg.py:121

Member Data Documentation

std::map<std::string, TH1*> PrimaryVertexAnalyzer::h
private

Definition at line 116 of file PrimaryVertexAnalyzer.h.

std::map<std::string, TDirectory*> PrimaryVertexAnalyzer::hdir
private

Definition at line 117 of file PrimaryVertexAnalyzer.h.

std::string PrimaryVertexAnalyzer::outputFile_
private

Definition at line 106 of file PrimaryVertexAnalyzer.h.

edm::ESHandle< ParticleDataTable > PrimaryVertexAnalyzer::pdt
private

Definition at line 113 of file PrimaryVertexAnalyzer.h.

std::string PrimaryVertexAnalyzer::recoTrackProducer_
private

Definition at line 105 of file PrimaryVertexAnalyzer.h.

TFile* PrimaryVertexAnalyzer::rootFile_
private

Definition at line 109 of file PrimaryVertexAnalyzer.h.

edm::InputTag PrimaryVertexAnalyzer::simG4_
private

Definition at line 111 of file PrimaryVertexAnalyzer.h.

double PrimaryVertexAnalyzer::simUnit_
private

Definition at line 112 of file PrimaryVertexAnalyzer.h.

std::vector<std::string> PrimaryVertexAnalyzer::suffixSample_
private

Definition at line 108 of file PrimaryVertexAnalyzer.h.

bool PrimaryVertexAnalyzer::verbose_
private

Definition at line 110 of file PrimaryVertexAnalyzer.h.

std::vector<std::string> PrimaryVertexAnalyzer::vtxSample_
private

Definition at line 107 of file PrimaryVertexAnalyzer.h.