Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:19:02

0001 /*
0002  *  \author Julia Yarba
0003  */
0004 
0005 #include <ostream>
0006 #include <memory>
0007 
0008 #include "FWCore/Framework/interface/EventSetup.h"
0009 #include "FWCore/Framework/interface/Run.h"
0010 #include "FWCore/ServiceRegistry/interface/Service.h"
0011 #include "FWCore/Utilities/interface/Exception.h"
0012 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
0013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0014 
0015 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
0016 #include "SimDataFormats/GeneratorProducts/interface/GenRunInfoProduct.h"
0017 
0018 #include "SimGeneral/HepPDTRecord/interface/ParticleDataTable.h"
0019 
0020 #include "IOMC/ParticleGuns/interface/BaseFlatGunProducer.h"
0021 
0022 #include <iostream>
0023 
0024 using namespace edm;
0025 using namespace std;
0026 using namespace CLHEP;
0027 
0028 BaseFlatGunProducer::BaseFlatGunProducer(const ParameterSet& pset)
0029     : fPDGTableToken(esConsumes<Transition::BeginRun>()),
0030       fEvt(nullptr)
0031 // fPDGTable( new DefaultConfig::ParticleDataTable("PDG Table") )
0032 {
0033   Service<RandomNumberGenerator> rng;
0034   if (!rng.isAvailable()) {
0035     throw cms::Exception("Configuration")
0036         << "The RandomNumberProducer module requires the RandomNumberGeneratorService\n"
0037            "which appears to be absent.  Please add that service to your configuration\n"
0038            "or remove the modules that require it.";
0039   }
0040 
0041   ParameterSet pgun_params = pset.getParameter<ParameterSet>("PGunParameters");
0042 
0043   // although there's the method ParameterSet::empty(),
0044   // it looks like it's NOT even necessary to check if it is,
0045   // before trying to extract parameters - if it is empty,
0046   // the default values seem to be taken
0047   fPartIDs = pgun_params.getParameter<vector<int> >("PartID");
0048   fMinEta = pgun_params.getParameter<double>("MinEta");
0049   fMaxEta = pgun_params.getParameter<double>("MaxEta");
0050   fMinPhi = pgun_params.getParameter<double>("MinPhi");
0051   fMaxPhi = pgun_params.getParameter<double>("MaxPhi");
0052 
0053   //
0054   //fPDGTablePath = "/afs/cern.ch/sw/lcg/external/clhep/1.9.2.1/slc3_ia32_gcc323/data/HepPDT/" ;
0055   /*
0056   string HepPDTBase( std::getenv("HEPPDT_PARAM_PATH") ) ; 
0057   fPDGTablePath = HepPDTBase + "/data/" ;
0058   fPDGTableName = "PDG_mass_width_2004.mc"; // should it be 2004 table ?
0059 
0060   string TableFullName = fPDGTablePath + fPDGTableName ;
0061   std::ifstream PDFile( TableFullName.c_str() ) ;
0062   if( !PDFile ) 
0063   {
0064       throw cms::Exception("FileNotFound", "BaseFlatGunProducer::BaseFlatGunProducer()")
0065     << "File " << TableFullName << " cannot be opened.\n";
0066   }
0067 
0068   HepPDT::TableBuilder tb(*fPDGTable) ;
0069   if ( !addPDGParticles( PDFile, tb ) ) { cout << " Error reading PDG !" << endl; }
0070   // the tb dtor fills fPDGTable
0071 */
0072 
0073   fVerbosity = pset.getUntrackedParameter<int>("Verbosity", 0);
0074 
0075   fAddAntiParticle = pset.getParameter<bool>("AddAntiParticle");
0076 
0077   produces<GenRunInfoProduct, Transition::EndRun>();
0078 }
0079 
0080 BaseFlatGunProducer::~BaseFlatGunProducer() {
0081   // no need to cleanup GenEvent memory - done in HepMCProduct
0082   // if (fEvt != NULL) delete fEvt ; // double check
0083   // delete fPDGTable;
0084 }
0085 
0086 void BaseFlatGunProducer::beginRun(const edm::Run& r, const EventSetup& es) {
0087   fPDGTable = es.getHandle(fPDGTableToken);
0088   return;
0089 }
0090 void BaseFlatGunProducer::endRun(const Run& run, const EventSetup& es) {}
0091 
0092 void BaseFlatGunProducer::endRunProduce(Run& run, const EventSetup& es) {
0093   // just create an empty product
0094   // to keep the EventContent definitions happy
0095   // later on we might put the info into the run info that this is a PGun
0096   unique_ptr<GenRunInfoProduct> genRunInfo(new GenRunInfoProduct());
0097   run.put(std::move(genRunInfo));
0098 }