CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CosMuoGenProducer.cc
Go to the documentation of this file.
1 
4 
8 
10 
12  //RanS(pset.getParameter<int>("RanSeed", 123456)), //get seed now from Framework
13  MinP(pset.getParameter<double>("MinP")),
14  MinP_CMS(pset.getParameter<double>("MinP_CMS")),
15  MaxP(pset.getParameter<double>("MaxP")),
16  MinT(pset.getParameter<double>("MinTheta")),
17  MaxT(pset.getParameter<double>("MaxTheta")),
18  MinPh(pset.getParameter<double>("MinPhi")),
19  MaxPh(pset.getParameter<double>("MaxPhi")),
20  MinS(pset.getParameter<double>("MinT0")),
21  MaxS(pset.getParameter<double>("MaxT0")),
22  ELSF(pset.getParameter<double>("ElossScaleFactor")),
23  RTarget(pset.getParameter<double>("RadiusOfTarget")),
24  ZTarget(pset.getParameter<double>("ZDistOfTarget")),
25  ZCTarget(pset.getParameter<double>("ZCentrOfTarget")),
26  TrackerOnly(pset.getParameter<bool>("TrackerOnly")),
27  MultiMuon(pset.getParameter<bool>("MultiMuon")),
28  MultiMuonFileName(pset.getParameter<std::string>("MultiMuonFileName")),
29  MultiMuonFileFirstEvent(pset.getParameter<int>("MultiMuonFileFirstEvent")),
30  MultiMuonNmin(pset.getParameter<int>("MultiMuonNmin")),
31  TIFOnly_constant(pset.getParameter<bool>("TIFOnly_constant")),
32  TIFOnly_linear(pset.getParameter<bool>("TIFOnly_linear")),
33  MTCCHalf(pset.getParameter<bool>("MTCCHalf")),
34  PlugVtx(pset.getParameter<double>("PlugVx")),
35  PlugVtz(pset.getParameter<double>("PlugVz")),
36  VarRhoAir(pset.getParameter<double>("RhoAir")),
37  VarRhoWall(pset.getParameter<double>("RhoWall")),
38  VarRhoRock(pset.getParameter<double>("RhoRock")),
39  VarRhoClay(pset.getParameter<double>("RhoClay")),
40  VarRhoPlug(pset.getParameter<double>("RhoPlug")),
41  ClayLayerWidth(pset.getParameter<double>("ClayWidth")),
42  MinEn(pset.getParameter<double>("MinEnu")),
43  MaxEn(pset.getParameter<double>("MaxEnu")),
44  NuPrdAlt(pset.getParameter<double>("NuProdAlt")),
45  AllMu(pset.getParameter<bool>("AcptAllMu")),
46  extCrossSect(pset.getUntrackedParameter<double>("crossSection", -1.)),
47  extFilterEff(pset.getUntrackedParameter<double>("filterEfficiency", -1.)),
48  cmVerbosity_(pset.getParameter<bool>("Verbosity")),
49  isInitialized_(false)
50  {
51  //if not specified (i.e. negative) then use MinP also for MinP_CMS
52  if(MinP_CMS < 0) MinP_CMS = MinP;
53 
54  // set up the generator
56 // Begin JMM change
57 // CosMuoGen->setNumberOfEvents(numberEventsInRun());
58  CosMuoGen->setNumberOfEvents(999999999);
59 // End of JMM change
94  produces<HepMCProduct>();
95  produces<GenEventInfoProduct>();
96  produces<GenRunInfoProduct, edm::InRun>();
97  }
98 
100  //CosMuoGen->terminate();
101  delete CosMuoGen;
102  // delete fEvt;
103  clear();
104 }
105 
107 {
108  if(!isInitialized_) {
109  isInitialized_ = true;
110  RandomEngineSentry<CosmicMuonGenerator> randomEngineSentry(CosMuoGen, lumi.index());
111  CosMuoGen->initialize(randomEngineSentry.randomEngine());
112  }
113 }
114 
116 {
117  std::auto_ptr<GenRunInfoProduct> genRunInfo(new GenRunInfoProduct());
118 
119  double cs = CosMuoGen->getRate(); // flux in Hz, not s^-1m^-2
120  if (MultiMuon) genRunInfo->setInternalXSec(0.);
121  else genRunInfo->setInternalXSec(cs);
122  genRunInfo->setExternalXSecLO(extCrossSect);
123  genRunInfo->setFilterEfficiency(extFilterEff);
124 
125  run.put(genRunInfo);
126 
127  CosMuoGen->terminate();
128 }
129 
131 
133 {
134  RandomEngineSentry<CosmicMuonGenerator> randomEngineSentry(CosMuoGen, e.streamID());
135 
136  // generate event
137  if (!MultiMuon) {
138  CosMuoGen->nextEvent();
139  }
140  else {
141  bool success = CosMuoGen->nextMultiEvent();
142  if (!success) std::cout << "CosMuoGenProducer.cc: CosMuoGen->nextMultiEvent() failed!"
143  << std::endl;
144  }
145 
146  if (Debug) {
147  std::cout << "CosMuoGenSource.cc: CosMuoGen->EventWeight=" << CosMuoGen->EventWeight
148  << " CosMuoGen: Nmuons=" << CosMuoGen->Id_sf.size() << std::endl;
149  std::cout << "CosMuoGen->Id_at=" << CosMuoGen->Id_at
150  << " CosMuoGen->Vx_at=" << CosMuoGen->Vx_at
151  << " CosMuoGen->Vy_at=" << CosMuoGen->Vy_at
152  << " CosMuoGen->Vz_at=" << CosMuoGen->Vz_at
153  << " CosMuoGen->T0_at=" << CosMuoGen->T0_at << std::endl;
154  std::cout << " Px=" << CosMuoGen->Px_at
155  << " Py=" << CosMuoGen->Py_at
156  << " Pz=" << CosMuoGen->Pz_at << std::endl;
157  for (unsigned int i=0; i<CosMuoGen->Id_sf.size(); ++i) {
158  std::cout << "Id_sf[" << i << "]=" << CosMuoGen->Id_sf[i]
159  << " Vx_sf[" << i << "]=" << CosMuoGen->Vx_sf[i]
160  << " Vy_sf=" << CosMuoGen->Vy_sf[i]
161  << " Vz_sf=" << CosMuoGen->Vz_sf[i]
162  << " T0_sf=" << CosMuoGen->T0_sf[i]
163  << " Px_sf=" << CosMuoGen->Px_sf[i]
164  << " Py_sf=" << CosMuoGen->Py_sf[i]
165  << " Pz_sf=" << CosMuoGen->Pz_sf[i] << std::endl;
166  std::cout << "phi_sf=" << atan2(CosMuoGen->Px_sf[i],CosMuoGen->Pz_sf[i]) << std::endl;
167  std::cout << "Id_ug[" << i << "]=" << CosMuoGen->Id_ug[i]
168  << " Vx_ug[" << i << "]=" << CosMuoGen->Vx_ug[i]
169  << " Vy_ug=" << CosMuoGen->Vy_ug[i]
170  << " Vz_ug=" << CosMuoGen->Vz_ug[i]
171  << " T0_ug=" << CosMuoGen->T0_ug[i]
172  << " Px_ug=" << CosMuoGen->Px_ug[i]
173  << " Py_ug=" << CosMuoGen->Py_ug[i]
174  << " Pz_ug=" << CosMuoGen->Pz_ug[i] << std::endl;
175  std::cout << "phi_ug=" << atan2(CosMuoGen->Px_ug[i],CosMuoGen->Pz_ug[i]) << std::endl;;
176  }
177  }
178 
179 
180  fEvt = new HepMC::GenEvent();
181 
182  HepMC::GenVertex* Vtx_at = new HepMC::GenVertex(HepMC::FourVector(CosMuoGen->Vx_at, //[mm]
183  CosMuoGen->Vy_at, //[mm]
184  CosMuoGen->Vz_at, //[mm]
185  CosMuoGen->T0_at)); //[mm]
186  //cout << "CosMuoGenSource.cc: Vy_at=" << CosMuoGen->Vy_at << endl;
187  HepMC::FourVector p_at(CosMuoGen->Px_at,CosMuoGen->Py_at,CosMuoGen->Pz_at,CosMuoGen->E_at);
188  HepMC::GenParticle* Part_at =
189  new HepMC::GenParticle(p_at,CosMuoGen->Id_at, 3);//Comment mother particle in
190  Vtx_at->add_particle_in(Part_at);
191 
192 
193  //loop here in case of multi muon events (else just one iteration)
194  for (unsigned int i=0; i<CosMuoGen->Id_sf.size(); ++i) {
195 
196  HepMC::FourVector p_sf(CosMuoGen->Px_sf[i],CosMuoGen->Py_sf[i],CosMuoGen->Pz_sf[i],CosMuoGen->E_sf[i]);
197  HepMC::GenParticle* Part_sf_in =
198  new HepMC::GenParticle(p_sf,CosMuoGen->Id_sf[i], 3); //Comment daughter particle
199  Vtx_at->add_particle_out(Part_sf_in);
200 
201  HepMC::GenVertex* Vtx_sf = new HepMC::GenVertex(HepMC::FourVector(CosMuoGen->Vx_sf[i], CosMuoGen->Vy_sf[i], CosMuoGen->Vz_sf[i], CosMuoGen->T0_sf[i])); //[mm]
202  HepMC::GenParticle* Part_sf_out =
203  new HepMC::GenParticle(p_sf,CosMuoGen->Id_sf[i], 3); //Comment daughter particle
204 
205  Vtx_sf->add_particle_in(Part_sf_in);
206  Vtx_sf->add_particle_out(Part_sf_out);
207 
208  fEvt->add_vertex(Vtx_sf); //one per muon
209 
210  HepMC::GenVertex* Vtx_ug = new HepMC::GenVertex(HepMC::FourVector(CosMuoGen->Vx_ug[i], CosMuoGen->Vy_ug[i], CosMuoGen->Vz_ug[i], CosMuoGen->T0_ug[i])); //[mm]
211 
212  HepMC::FourVector p_ug(CosMuoGen->Px_ug[i],CosMuoGen->Py_ug[i],CosMuoGen->Pz_ug[i],CosMuoGen->E_ug[i]);
213  HepMC::GenParticle* Part_ug =
214  new HepMC::GenParticle(p_ug,CosMuoGen->Id_ug[i], 1);//Final state daughter particle
215 
216  Vtx_ug->add_particle_in(Part_sf_out);
217  Vtx_ug->add_particle_out(Part_ug);
218 
219  fEvt->add_vertex(Vtx_ug); //one per muon
220 
221  }
222 
223  fEvt->add_vertex(Vtx_at);
224  fEvt->set_signal_process_vertex(Vtx_at);
225 
226  fEvt->set_event_number(e.id().event());
227  fEvt->set_signal_process_id(13);
228 
229  fEvt->weights().push_back( CosMuoGen->EventWeight ); // just one event weight
230  fEvt->weights().push_back( CosMuoGen->Trials ); // int Trials number (unweighted)
231 
232 
233  if (cmVerbosity_) fEvt->print();
234 
235  std::auto_ptr<HepMCProduct> CMProduct(new HepMCProduct());
236  CMProduct->addHepMCData( fEvt );
237  e.put(CMProduct);
238 
239  std::auto_ptr<GenEventInfoProduct> genEventInfo(new GenEventInfoProduct( fEvt ));
240  e.put(genEventInfo);
241 
242 }
void setZDistOfTarget(double Z)
EventNumber_t event() const
Definition: EventID.h:41
int i
Definition: DBlmapReader.cc:9
virtual void endRunProduce(Run &r, const EventSetup &es) override
void setMinEnu(double MinEn)
auto_ptr< ClusterSequence > cs
void setTIFOnly_constant(bool TIF)
void setNuProdAlt(double NuPrdAlt)
void setZCentrOfTarget(double Z)
LuminosityBlockIndex index() const
void setRhoAir(double VarRhoAir)
tuple lumi
Definition: fjr2json.py:35
CosMuoGenProducer(const ParameterSet &)
void setRadiusOfTarget(double R)
void setNumberOfEvents(unsigned int N)
void setMultiMuonFileFirstEvent(int MultiMuFile1stEvt)
void setRhoPlug(double VarRhoPlug)
void setMinPhi(double Phi)
void setMaxPhi(double Phi)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
Definition: matutil.cc:167
void setMultiMuonNmin(int MultiMuNmin)
void setMinTheta(double Theta)
void setMaxEnu(double MaxEn)
virtual void produce(Event &e, const EventSetup &es) override
virtual void beginLuminosityBlock(LuminosityBlock const &, EventSetup const &) override
void setMultiMuon(bool MultiMu)
CosmicMuonGenerator * CosMuoGen
void setClayWidth(double ClayLaeyrWidth)
void setAcptAllMu(bool AllMu)
void setPlugVz(double PlugVtz)
void setTIFOnly_linear(bool TIF)
edm::EventID id() const
Definition: EventBase.h:56
void setMultiMuonFileName(std::string MultiMuonFileName)
StreamID streamID() const
Definition: Event.h:72
void setElossScaleFactor(double ElossScaleFact)
void setMaxTheta(double Theta)
tuple cout
Definition: gather_cfg.py:121
void put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Run.h:107
void setRhoWall(double VarRhoSWall)
void setPlugVx(double PlugVtx)
volatile std::atomic< bool > shutdown_flag false
void setRhoRock(double VarRhoRock)
const bool Debug
void setRhoClay(double VarRhoClay)
Definition: Run.h:41
void setTrackerOnly(bool Tracker)