Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-01-29 01:30:47

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