00001 #include "GeneratorInterface/CosmicMuonGenerator/interface/CosMuoGenSource.h"
00002 #include "FWCore/ServiceRegistry/interface/Service.h"
00003 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00004
00005
00006 edm::CosMuoGenSource::CosMuoGenSource( const ParameterSet & pset, InputSourceDescription const& desc ) :
00007 GeneratedInputSource(pset, desc ) ,
00008
00009 MinP(pset.getParameter<double>("MinP")),
00010 MinP_CMS(pset.getParameter<double>("MinP_CMS")),
00011 MaxP(pset.getParameter<double>("MaxP")),
00012 MinT(pset.getParameter<double>("MinTheta")),
00013 MaxT(pset.getParameter<double>("MaxTheta")),
00014 MinPh(pset.getParameter<double>("MinPhi")),
00015 MaxPh(pset.getParameter<double>("MaxPhi")),
00016 MinS(pset.getParameter<double>("MinT0")),
00017 MaxS(pset.getParameter<double>("MaxT0")),
00018 ELSF(pset.getParameter<double>("ElossScaleFactor")),
00019 RTarget(pset.getParameter<double>("RadiusOfTarget")),
00020 ZTarget(pset.getParameter<double>("ZDistOfTarget")),
00021 ZCTarget(pset.getParameter<double>("ZCentrOfTarget")),
00022 TrackerOnly(pset.getParameter<bool>("TrackerOnly")),
00023 TIFOnly_constant(pset.getParameter<bool>("TIFOnly_constant")),
00024 TIFOnly_linear(pset.getParameter<bool>("TIFOnly_linear")),
00025 MTCCHalf(pset.getParameter<bool>("MTCCHalf")),
00026 PlugVtx(pset.getParameter<double>("PlugVx")),
00027 PlugVtz(pset.getParameter<double>("PlugVz")),
00028 cmVerbosity_(pset.getParameter<bool>("Verbosity"))
00029 {
00030
00031
00032 if(MinP_CMS < 0) MinP_CMS = MinP;
00033
00034
00035 edm::Service<edm::RandomNumberGenerator> rng;
00036 RanS = rng->mySeed();
00037
00038 CosMuoGen = new CosmicMuonGenerator();
00039 CosMuoGen->setNumberOfEvents(numberEventsInRun());
00040 CosMuoGen->setRanSeed(RanS);
00041 CosMuoGen->setMinP(MinP);
00042 CosMuoGen->setMinP_CMS(MinP_CMS);
00043 CosMuoGen->setMaxP(MaxP);
00044 CosMuoGen->setMinTheta(MinT);
00045 CosMuoGen->setMaxTheta(MaxT);
00046 CosMuoGen->setMinPhi(MinPh);
00047 CosMuoGen->setMaxPhi(MaxPh);
00048 CosMuoGen->setMinT0(MinS);
00049 CosMuoGen->setMaxT0(MaxS);
00050 CosMuoGen->setElossScaleFactor(ELSF);
00051 CosMuoGen->setRadiusOfTarget(RTarget);
00052 CosMuoGen->setZDistOfTarget(ZTarget);
00053 CosMuoGen->setZCentrOfTarget(ZCTarget);
00054 CosMuoGen->setTrackerOnly(TrackerOnly);
00055 CosMuoGen->setTIFOnly_constant(TIFOnly_constant);
00056 CosMuoGen->setTIFOnly_linear(TIFOnly_linear);
00057 CosMuoGen->setMTCCHalf(MTCCHalf);
00058 CosMuoGen->setPlugVx(PlugVtx);
00059 CosMuoGen->setPlugVz(PlugVtz);
00060 CosMuoGen->initialize();
00061 produces<HepMCProduct>();
00062
00063 }
00064
00065 edm::CosMuoGenSource::~CosMuoGenSource(){
00066 CosMuoGen->terminate();
00067 delete CosMuoGen;
00068
00069 clear();
00070 }
00071
00072 void edm::CosMuoGenSource::clear(){}
00073
00074 bool edm::CosMuoGenSource::produce(Event &e)
00075 {
00076
00077 CosMuoGen->nextEvent();
00078
00079
00080
00081 fEvt = new HepMC::GenEvent();
00082 HepMC::GenVertex* Vtx = new HepMC::GenVertex(HepMC::FourVector(CosMuoGen->OneMuoEvt.vx(),
00083 CosMuoGen->OneMuoEvt.vy(),
00084 CosMuoGen->OneMuoEvt.vz(),
00085 CosMuoGen->OneMuoEvt.t0()));
00086 HepMC::FourVector p(CosMuoGen->OneMuoEvt.px(),CosMuoGen->OneMuoEvt.py(),CosMuoGen->OneMuoEvt.pz(),CosMuoGen->OneMuoEvt.e());
00087 HepMC::GenParticle* Part =
00088 new HepMC::GenParticle(p,CosMuoGen->OneMuoEvt.id(),1);
00089 Vtx->add_particle_out(Part);
00090 fEvt->add_vertex(Vtx);
00091 fEvt->set_event_number(event());
00092 fEvt->set_signal_process_id(13);
00093
00094 if (cmVerbosity_) fEvt->print();
00095
00096 std::auto_ptr<HepMCProduct> CMProduct(new HepMCProduct());
00097 CMProduct->addHepMCData( fEvt );
00098 e.put(CMProduct);
00099
00100 return true;
00101 }
00102