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 edm::EDConsumerBase

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
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (const std::string &iProcessName, std::vector< const char * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Member Functions

std::vector< simPrimaryVertexgetSimPVs (const edm::Handle< edm::HepMCProduct > &evtMC, const 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

edm::EDGetTokenT
< edm::HepMCProduct
edmHepMCProductToken_
 
edm::EDGetTokenT
< edm::SimTrackContainer
edmSimTrackContainerToken_
 
edm::EDGetTokenT
< edm::SimVertexContainer
edmSimVertexContainerToken_
 
std::map< std::string, TH1 * > h
 
std::map< std::string,
TDirectory * > 
hdir
 
std::string outputFile_
 
edm::ESHandle< ParticleDataTablepdt
 
edm::EDGetTokenT
< reco::TrackCollection
recoTrackCollectionToken_
 
std::vector< edm::EDGetTokenT
< reco::VertexCollection > > 
recoVertexCollectionTokens_
 
TFile * rootFile_
 
double simUnit_
 
std::vector< std::string > suffixSample_
 
bool verbose_
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
- 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::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Description: simple primary vertex analyzer

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

Definition at line 54 of file PrimaryVertexAnalyzer.h.

Constructor & Destructor Documentation

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

Definition at line 45 of file PrimaryVertexAnalyzer.cc.

References edm::getReleaseVersion(), edm::ParameterSet::getUntrackedParameter(), outputFile_, recoVertexCollectionTokens_, rootFile_, simUnit_, AlCaHLTBitMon_QueryRunRegistry::string, and suffixSample_.

46  : verbose_( iConfig.getUntrackedParameter<bool>( "verbose", false ) )
47  , simUnit_( 1.0 ) // starting with CMSSW_1_2_x ??
48  , recoTrackCollectionToken_( consumes< reco::TrackCollection >( edm::InputTag( iConfig.getUntrackedParameter<std::string>( "recoTrackProducer" ) ) ) )
49  , edmSimVertexContainerToken_( consumes< edm::SimVertexContainer>( iConfig.getParameter<edm::InputTag>( "simG4" ) ) )
50  , edmSimTrackContainerToken_( consumes< edm::SimTrackContainer >( iConfig.getParameter<edm::InputTag>( "simG4" ) ) )
51  , edmHepMCProductToken_( consumes< edm::HepMCProduct >( edm::InputTag( std::string( "generator" ) ) ) )
52 {
53  //now do what ever initialization is needed
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  std::vector<std::string> vtxSample = iConfig.getUntrackedParameter<std::vector< std::string > >("vtxSample");
62  recoVertexCollectionTokens_.reserve( vtxSample.size() );
63  suffixSample_.reserve( vtxSample.size() );
64  auto vtxSampleBegin = vtxSample.begin();
65  auto vtxSampleEnd = vtxSample.end();
66  for( auto isample = vtxSampleBegin; isample != vtxSampleEnd; ++isample ) {
67  recoVertexCollectionTokens_.push_back( consumes< reco::VertexCollection >( edm::InputTag( *isample ) ) );
68  if ( *isample == "offlinePrimaryVertices" ) suffixSample_.push_back("AVF");
69  if ( *isample == "offlinePrimaryVerticesWithBS" ) suffixSample_.push_back("wBS");
70  }
71  if ( suffixSample_.size() == 0 ) throw cms::Exception("NoVertexSamples") << " no known vertex samples given";
72 
73  rootFile_ = new TFile(outputFile_.c_str(),"RECREATE");
74  if ( (edm::getReleaseVersion()).find("CMSSW_1_1_",0)!=std::string::npos){
75  simUnit_=0.1; // for use in CMSSW_1_1_1 tutorial
76  }
77 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
edm::EDGetTokenT< edm::SimTrackContainer > edmSimTrackContainerToken_
std::string getReleaseVersion()
edm::EDGetTokenT< edm::HepMCProduct > edmHepMCProductToken_
std::vector< edm::EDGetTokenT< reco::VertexCollection > > recoVertexCollectionTokens_
edm::EDGetTokenT< reco::TrackCollection > recoTrackCollectionToken_
std::vector< std::string > suffixSample_
edm::EDGetTokenT< edm::SimVertexContainer > edmSimVertexContainerToken_
PrimaryVertexAnalyzer::~PrimaryVertexAnalyzer ( )

Definition at line 80 of file PrimaryVertexAnalyzer.cc.

References rootFile_.

81 {
82  // do anything here that needs to be done at desctruction time
83  // (e.g. close files, deallocate resources etc.)
84  delete rootFile_;
85 }

Member Function Documentation

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

Implements edm::EDAnalyzer.

Definition at line 402 of file PrimaryVertexAnalyzer.cc.

References ChiSquaredProbability(), gather_cfg::cout, data, edmHepMCProductToken_, edmSimTrackContainerToken_, edmSimVertexContainerToken_, edm::Event::getByToken(), edm::EventSetup::getData(), getSimPVs(), h, hdir, i, cmsHarvester::index, edm::detail::isnan(), edm::HandleBase::isValid(), j, visualization-live-secondInstance_cfg::m, matchVertex(), NULL, pdt, printRecVtxs(), recoTrackCollectionToken_, recoVertexCollectionTokens_, simUnit_, AlCaHLTBitMon_QueryRunRegistry::string, suffixSample_, edmStreamStallGrapher::t, findQualityFiles::v, verbose_, w, and detailsBasic3DVector::z.

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

Reimplemented from edm::EDAnalyzer.

Definition at line 91 of file PrimaryVertexAnalyzer.cc.

References gather_cfg::cout, h, hdir, rootFile_, simUnit_, and suffixSample_.

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

References h, hdir, estimatePileup::hist, and rootFile_.

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

Definition at line 237 of file PrimaryVertexAnalyzer.cc.

References gather_cfg::cout, alignCSCRings::e, spr::find(), h, customizeTrackingMonitorSeedNumber::idx, isCharged(), isFinalstateParticle(), visualization-live-secondInstance_cfg::m, NULL, parents, createPayload::suffix, and verbose_.

Referenced by analyze().

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

References GenParticle::GenParticle, customizeTrackingMonitorSeedNumber::idx, isCharged(), isFinalstateParticle(), isResonance(), or, PrimaryVertexAnalyzer::simPrimaryVertex::simTrackIndex, edmStreamStallGrapher::t, and findQualityFiles::v.

332 {
333  // simvertices don't have enough information to decide,
334  // genVertices don't have the simulated coordinates ( with VtxSmeared they might)
335  // go through simtracks to get the link between simulated and generated vertices
336  std::vector<PrimaryVertexAnalyzer::simPrimaryVertex> simpv;
337  int idx=0;
338  for(edm::SimTrackContainer::const_iterator t=simTrks->begin();
339  t!=simTrks->end(); ++t){
340  if ( !(t->noVertex()) && !(t->type()==-99) ){
341  double ptsq=0;
342  bool primary=false; // something coming directly from the primary vertex
343  bool resonance=false; // resonance
344  bool track=false; // undecayed, charged particle
345  HepMC::GenParticle* gp=evtMC->GetEvent()->barcode_to_particle( (*t).genpartIndex() );
346  if (gp) {
347  HepMC::GenVertex * gv=gp->production_vertex();
348  if (gv) {
349  for ( HepMC::GenVertex::particle_iterator
350  daughter = gv->particles_begin(HepMC::descendants);
351  daughter != gv->particles_end(HepMC::descendants);
352  ++daughter ) {
353  if (isFinalstateParticle(*daughter)){
354  ptsq+=(*daughter)->momentum().perp()*(*daughter)->momentum().perp();
355  }
356  }
357  primary = ( gv->position().t()==0);
358  //resonance= ( gp->mother() && isResonance(gp->mother())); // in CLHEP/HepMC days
359  // no more mother pointer in the improved HepMC GenParticle
360  resonance= ( isResonance(*(gp->production_vertex()->particles_in_const_begin())));
361  if (gp->status()==1){
362  //track=((pdt->particle(gp->pdg_id()))->charge() != 0);
363  track=not isCharged(gp);
364  }
365  }
366  }
367 
368  const HepMC::FourVector & v=(*simVtxs)[t->vertIndex()].position();
369  //const HepLorentzVector & v=(*simVtxs)[t->vertIndex()].position();
370  if(primary or resonance){
371  {
372  // check all primaries found so far to avoid multiple entries
373  bool newVertex=true;
374  for(std::vector<simPrimaryVertex>::iterator v0=simpv.begin();
375  v0!=simpv.end(); v0++){
376  if( (fabs(v0->x-v.x())<0.001) && (fabs(v0->y-v.y())<0.001) && (fabs(v0->z-v.z())<0.001) ){
377  if (track) {
378  v0->simTrackIndex.push_back(idx);
379  if (ptsq>(*v0).ptsq){(*v0).ptsq=ptsq;}
380  }
381  newVertex=false;
382  }
383  }
384  if(newVertex && !resonance){
385  simPrimaryVertex anotherVertex(v.x(),v.y(),v.z());
386  if (track) anotherVertex.simTrackIndex.push_back(idx);
387  anotherVertex.ptsq=ptsq;
388  simpv.push_back(anotherVertex);
389  }
390  }//
391  }
392 
393  }// simtrack has vertex and valid type
394  idx++;
395  }//simTrack loop
396  return simpv;
397 }
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)
bool isResonance(const HepMC::GenParticle *p)
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
bool PrimaryVertexAnalyzer::isCharged ( const HepMC::GenParticle *  p)
private

Definition at line 173 of file PrimaryVertexAnalyzer.cc.

References pdt.

Referenced by getSimPVs().

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

Definition at line 169 of file PrimaryVertexAnalyzer.cc.

Referenced by getSimPVs().

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

Definition at line 163 of file PrimaryVertexAnalyzer.cc.

References funct::abs(), gather_cfg::cout, alignCSCRings::e, pdt, and verbose_.

Referenced by getSimPVs().

163  {
164  double ctau=(pdt->particle( abs(p->pdg_id()) ))->lifetime();
165  if(verbose_) std::cout << "isResonance " << p->pdg_id() << " " << ctau << std::endl;
166  return ctau >0 && ctau <1e-6;
167 }
edm::ESHandle< ParticleDataTable > pdt
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
tuple cout
Definition: gather_cfg.py:121
bool PrimaryVertexAnalyzer::matchVertex ( const simPrimaryVertex vsim,
const reco::Vertex vrec 
)
private

Definition at line 158 of file PrimaryVertexAnalyzer.cc.

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

Referenced by analyze().

159  {
160  return (fabs(vsim.z*simUnit_-vrec.z())<0.0500); // =500um
161 }
double z() const
y coordinate
Definition: Vertex.h:112
void PrimaryVertexAnalyzer::printRecVtxs ( const edm::Handle< reco::VertexCollection > &  recVtxs)
private

Definition at line 183 of file PrimaryVertexAnalyzer.cc.

References gather_cfg::cout, and findQualityFiles::v.

Referenced by analyze().

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

Definition at line 218 of file PrimaryVertexAnalyzer.cc.

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

218  {
219  std::cout << " simTrks type, (momentum), vertIndex, genpartIndex" << std::endl;
220  int i=1;
221  for(edm::SimTrackContainer::const_iterator t=simTrks->begin();
222  t!=simTrks->end(); ++t){
223  //HepMC::GenParticle* gp=evtMC->GetEvent()->particle( (*t).genpartIndex() );
224  std::cout << i++ << ")"
225  << (*t)
226  << " index="
227  << (*t).genpartIndex();
228  //if (gp) {
229  // HepMC::GenVertex *gv=gp->production_vertex();
230  // std::cout << " genvertex =" << (*gv);
231  //}
232  std::cout << std::endl;
233  }
234 }
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 202 of file PrimaryVertexAnalyzer.cc.

References gather_cfg::cout, i, and simUnit_.

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

Member Data Documentation

edm::EDGetTokenT< edm::HepMCProduct > PrimaryVertexAnalyzer::edmHepMCProductToken_
private

Definition at line 101 of file PrimaryVertexAnalyzer.h.

Referenced by analyze().

edm::EDGetTokenT< edm::SimTrackContainer > PrimaryVertexAnalyzer::edmSimTrackContainerToken_
private

Definition at line 100 of file PrimaryVertexAnalyzer.h.

Referenced by analyze().

edm::EDGetTokenT< edm::SimVertexContainer > PrimaryVertexAnalyzer::edmSimVertexContainerToken_
private

Definition at line 99 of file PrimaryVertexAnalyzer.h.

Referenced by analyze().

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

Definition at line 106 of file PrimaryVertexAnalyzer.h.

Referenced by analyze(), beginJob(), endJob(), and getSimPVs().

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

Definition at line 107 of file PrimaryVertexAnalyzer.h.

Referenced by analyze(), beginJob(), and endJob().

std::string PrimaryVertexAnalyzer::outputFile_
private

Definition at line 103 of file PrimaryVertexAnalyzer.h.

Referenced by PrimaryVertexAnalyzer().

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

Definition at line 97 of file PrimaryVertexAnalyzer.h.

Referenced by analyze(), isCharged(), and isResonance().

edm::EDGetTokenT< reco::TrackCollection > PrimaryVertexAnalyzer::recoTrackCollectionToken_
private

Definition at line 98 of file PrimaryVertexAnalyzer.h.

Referenced by analyze().

std::vector< edm::EDGetTokenT< reco::VertexCollection > > PrimaryVertexAnalyzer::recoVertexCollectionTokens_
private

Definition at line 102 of file PrimaryVertexAnalyzer.h.

Referenced by analyze(), and PrimaryVertexAnalyzer().

TFile* PrimaryVertexAnalyzer::rootFile_
private
double PrimaryVertexAnalyzer::simUnit_
private
std::vector<std::string> PrimaryVertexAnalyzer::suffixSample_
private

Definition at line 104 of file PrimaryVertexAnalyzer.h.

Referenced by analyze(), beginJob(), and PrimaryVertexAnalyzer().

bool PrimaryVertexAnalyzer::verbose_
private

Definition at line 95 of file PrimaryVertexAnalyzer.h.

Referenced by analyze(), getSimPVs(), and isResonance().