Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-22 06:27:21

0001 #include "DataFormats/Common/interface/Handle.h"
0002 #include "FWCore/Framework/interface/ESHandle.h"
0003 #include "FWCore/Framework/interface/EventSetup.h"
0004 #include "SimGeneral/HepPDTESSource/test/HepPDTAnalyzer.h"
0005 #include "SimGeneral/HepPDTRecord/interface/ParticleDataTable.h"
0006 
0007 #include <iomanip>
0008 #include <iostream>
0009 
0010 using namespace edm;
0011 using namespace std;
0012 
0013 HepPDTAnalyzer::HepPDTAnalyzer(const edm::ParameterSet &iConfig)
0014     : particleName_(iConfig.getParameter<std::string>("particleName")),
0015       tok_pdt_(esConsumes<HepPDT::ParticleDataTable, PDTRecord>()) {}
0016 
0017 void HepPDTAnalyzer::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
0018   using namespace edm;
0019 
0020   const auto &pdt = iSetup.getHandle(tok_pdt_);
0021 
0022   if (particleName_ == "all") {
0023     std::cout << " Number of particles in table = " << pdt->size() << std::endl;
0024     printBanner();
0025     for (ParticleDataTable::const_iterator iter = pdt->begin(); iter != pdt->end(); iter++) {
0026       const ParticleData *part = pdt->particle((*iter).first);
0027       printInfo(part);
0028     }
0029   } else if (particleName_ == "names") {
0030     std::cout << " Number of particles in table = " << pdt->size() << std::endl;
0031     printBanner();
0032     for (ParticleDataTable::const_iterator iter = pdt->begin(); iter != pdt->end(); iter++) {
0033       const ParticleData *part = pdt->particle((*iter).first);
0034       std::cout << " " << part->name() << std::endl;
0035     }
0036   } else if (particleName_ == "checkAllowedIDs") {
0037     int maxID = 2000000000;
0038     int minID = -1 * maxID;
0039     int legalcount = 0;
0040     std::cout << " Scanning IDs from " << minID << " to " << maxID << std::endl;
0041     printBanner();
0042     for (int ii = minID; ii <= maxID; ii++) {
0043       const ParticleData *part = pdt->particle(ii);
0044       if (part) {
0045         legalcount++;
0046         printInfo(part);
0047       }
0048       if (abs(ii) >= 1000000000)
0049         ii = ii + 9;
0050     }
0051     std::cout << "  Found " << legalcount << " legal IDs in range." << std::endl;
0052   } else {
0053     printBanner();
0054     const ParticleData *part = pdt->particle(particleName_);
0055     printInfo(part);
0056   }
0057 }
0058 
0059 void HepPDTAnalyzer::printInfo(const ParticleData *&part) {
0060   cout << setfill(' ') << setw(14);
0061   cout << part->name();
0062   cout << setfill(' ') << setw(12);
0063   cout << part->pid();
0064   cout << setfill(' ') << setw(8) << setprecision(3);
0065   cout << part->charge();
0066   cout << setfill(' ') << setw(12) << setprecision(6);
0067   cout << part->mass();
0068   cout << setfill(' ') << setw(14) << setprecision(5);
0069   cout << part->totalWidth();
0070   cout << setfill(' ') << setw(14) << setprecision(5);
0071   cout << part->lifetime() << endl;
0072 }
0073 
0074 void HepPDTAnalyzer::printBanner() {
0075   cout << " Particle name    ID        Charge     Mass       Tot. Width      "
0076           "Lifetime "
0077        << endl;
0078   cout << " -------------------------------------------------------------------"
0079           "------ "
0080        << endl;
0081 }
0082 
0083 #include "FWCore/Framework/interface/MakerMacros.h"
0084 
0085 DEFINE_FWK_MODULE(HepPDTAnalyzer);