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 #include <CLHEP/Random/RandomEngine.h>
2 
6 
10 
12 
14  //RanS(pset.getParameter<int>("RanSeed", 123456)), //get seed now from Framework
15  MinP(pset.getParameter<double>("MinP")),
16  MinP_CMS(pset.getParameter<double>("MinP_CMS")),
17  MaxP(pset.getParameter<double>("MaxP")),
18  MinT(pset.getParameter<double>("MinTheta")),
19  MaxT(pset.getParameter<double>("MaxTheta")),
20  MinPh(pset.getParameter<double>("MinPhi")),
21  MaxPh(pset.getParameter<double>("MaxPhi")),
22  MinS(pset.getParameter<double>("MinT0")),
23  MaxS(pset.getParameter<double>("MaxT0")),
24  ELSF(pset.getParameter<double>("ElossScaleFactor")),
25  RTarget(pset.getParameter<double>("RadiusOfTarget")),
26  ZTarget(pset.getParameter<double>("ZDistOfTarget")),
27  ZCTarget(pset.getParameter<double>("ZCentrOfTarget")),
28  TrackerOnly(pset.getParameter<bool>("TrackerOnly")),
29  MultiMuon(pset.getParameter<bool>("MultiMuon")),
30  MultiMuonFileName(pset.getParameter<std::string>("MultiMuonFileName")),
31  MultiMuonFileFirstEvent(pset.getParameter<int>("MultiMuonFileFirstEvent")),
32  MultiMuonNmin(pset.getParameter<int>("MultiMuonNmin")),
33  TIFOnly_constant(pset.getParameter<bool>("TIFOnly_constant")),
34  TIFOnly_linear(pset.getParameter<bool>("TIFOnly_linear")),
35  MTCCHalf(pset.getParameter<bool>("MTCCHalf")),
36  PlugVtx(pset.getParameter<double>("PlugVx")),
37  PlugVtz(pset.getParameter<double>("PlugVz")),
38  VarRhoAir(pset.getParameter<double>("RhoAir")),
39  VarRhoWall(pset.getParameter<double>("RhoWall")),
40  VarRhoRock(pset.getParameter<double>("RhoRock")),
41  VarRhoClay(pset.getParameter<double>("RhoClay")),
42  VarRhoPlug(pset.getParameter<double>("RhoPlug")),
43  ClayLayerWidth(pset.getParameter<double>("ClayWidth")),
44  MinEn(pset.getParameter<double>("MinEnu")),
45  MaxEn(pset.getParameter<double>("MaxEnu")),
46  NuPrdAlt(pset.getParameter<double>("NuProdAlt")),
47  AllMu(pset.getParameter<bool>("AcptAllMu")),
48  extCrossSect(pset.getUntrackedParameter<double>("crossSection", -1.)),
49  extFilterEff(pset.getUntrackedParameter<double>("filterEfficiency", -1.)),
50  cmVerbosity_(pset.getParameter<bool>("Verbosity"))
51  {
52  //if not specified (i.e. negative) then use MinP also for MinP_CMS
53  if(MinP_CMS < 0) MinP_CMS = MinP;
54 
56  if (!rng.isAvailable())
57  throw cms::Exception("Configuration")
58  << "The RandomNumberProducer module requires the RandomNumberGeneratorService\n"
59  "which appears to be absent. Please add that service to your configuration\n"
60  "or remove the modules that require it." << std::endl;
61 
62  // set up the generator
64 // Begin JMM change
65 // CosMuoGen->setNumberOfEvents(numberEventsInRun());
66  CosMuoGen->setNumberOfEvents(999999999);
67 // End of JMM change
102  CosMuoGen->initialize(&rng->getEngine());
103  produces<HepMCProduct>();
104  produces<GenEventInfoProduct>();
105  produces<GenRunInfoProduct, edm::InRun>();
106  }
107 
109  //CosMuoGen->terminate();
110  delete CosMuoGen;
111  // delete fEvt;
112  clear();
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  // generate event
135  if (!MultiMuon) {
136  CosMuoGen->nextEvent();
137  }
138  else {
139  bool success = CosMuoGen->nextMultiEvent();
140  if (!success) std::cout << "CosMuoGenProducer.cc: CosMuoGen->nextMultiEvent() failed!"
141  << std::endl;
142  }
143 
144  if (Debug) {
145  std::cout << "CosMuoGenSource.cc: CosMuoGen->EventWeight=" << CosMuoGen->EventWeight
146  << " CosMuoGen: Nmuons=" << CosMuoGen->Id_sf.size() << std::endl;
147  std::cout << "CosMuoGen->Id_at=" << CosMuoGen->Id_at
148  << " CosMuoGen->Vx_at=" << CosMuoGen->Vx_at
149  << " CosMuoGen->Vy_at=" << CosMuoGen->Vy_at
150  << " CosMuoGen->Vz_at=" << CosMuoGen->Vz_at
151  << " CosMuoGen->T0_at=" << CosMuoGen->T0_at << std::endl;
152  std::cout << " Px=" << CosMuoGen->Px_at
153  << " Py=" << CosMuoGen->Py_at
154  << " Pz=" << CosMuoGen->Pz_at << std::endl;
155  for (unsigned int i=0; i<CosMuoGen->Id_sf.size(); ++i) {
156  std::cout << "Id_sf[" << i << "]=" << CosMuoGen->Id_sf[i]
157  << " Vx_sf[" << i << "]=" << CosMuoGen->Vx_sf[i]
158  << " Vy_sf=" << CosMuoGen->Vy_sf[i]
159  << " Vz_sf=" << CosMuoGen->Vz_sf[i]
160  << " T0_sf=" << CosMuoGen->T0_sf[i]
161  << " Px_sf=" << CosMuoGen->Px_sf[i]
162  << " Py_sf=" << CosMuoGen->Py_sf[i]
163  << " Pz_sf=" << CosMuoGen->Pz_sf[i] << std::endl;
164  std::cout << "phi_sf=" << atan2(CosMuoGen->Px_sf[i],CosMuoGen->Pz_sf[i]) << std::endl;
165  std::cout << "Id_ug[" << i << "]=" << CosMuoGen->Id_ug[i]
166  << " Vx_ug[" << i << "]=" << CosMuoGen->Vx_ug[i]
167  << " Vy_ug=" << CosMuoGen->Vy_ug[i]
168  << " Vz_ug=" << CosMuoGen->Vz_ug[i]
169  << " T0_ug=" << CosMuoGen->T0_ug[i]
170  << " Px_ug=" << CosMuoGen->Px_ug[i]
171  << " Py_ug=" << CosMuoGen->Py_ug[i]
172  << " Pz_ug=" << CosMuoGen->Pz_ug[i] << std::endl;
173  std::cout << "phi_ug=" << atan2(CosMuoGen->Px_ug[i],CosMuoGen->Pz_ug[i]) << std::endl;;
174  }
175  }
176 
177 
178  fEvt = new HepMC::GenEvent();
179 
180  HepMC::GenVertex* Vtx_at = new HepMC::GenVertex(HepMC::FourVector(CosMuoGen->Vx_at, //[mm]
181  CosMuoGen->Vy_at, //[mm]
182  CosMuoGen->Vz_at, //[mm]
183  CosMuoGen->T0_at)); //[mm]
184  //cout << "CosMuoGenSource.cc: Vy_at=" << CosMuoGen->Vy_at << endl;
185  HepMC::FourVector p_at(CosMuoGen->Px_at,CosMuoGen->Py_at,CosMuoGen->Pz_at,CosMuoGen->E_at);
186  HepMC::GenParticle* Part_at =
187  new HepMC::GenParticle(p_at,CosMuoGen->Id_at, 3);//Comment mother particle in
188  Vtx_at->add_particle_in(Part_at);
189 
190 
191  //loop here in case of multi muon events (else just one iteration)
192  for (unsigned int i=0; i<CosMuoGen->Id_sf.size(); ++i) {
193 
194  HepMC::FourVector p_sf(CosMuoGen->Px_sf[i],CosMuoGen->Py_sf[i],CosMuoGen->Pz_sf[i],CosMuoGen->E_sf[i]);
195  HepMC::GenParticle* Part_sf_in =
196  new HepMC::GenParticle(p_sf,CosMuoGen->Id_sf[i], 3); //Comment daughter particle
197  Vtx_at->add_particle_out(Part_sf_in);
198 
199  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]
200  HepMC::GenParticle* Part_sf_out =
201  new HepMC::GenParticle(p_sf,CosMuoGen->Id_sf[i], 3); //Comment daughter particle
202 
203  Vtx_sf->add_particle_in(Part_sf_in);
204  Vtx_sf->add_particle_out(Part_sf_out);
205 
206  fEvt->add_vertex(Vtx_sf); //one per muon
207 
208  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]
209 
210  HepMC::FourVector p_ug(CosMuoGen->Px_ug[i],CosMuoGen->Py_ug[i],CosMuoGen->Pz_ug[i],CosMuoGen->E_ug[i]);
211  HepMC::GenParticle* Part_ug =
212  new HepMC::GenParticle(p_ug,CosMuoGen->Id_ug[i], 1);//Final state daughter particle
213 
214  Vtx_ug->add_particle_in(Part_sf_out);
215  Vtx_ug->add_particle_out(Part_ug);
216 
217  fEvt->add_vertex(Vtx_ug); //one per muon
218 
219  }
220 
221  fEvt->add_vertex(Vtx_at);
222  fEvt->set_signal_process_vertex(Vtx_at);
223 
224  fEvt->set_event_number(e.id().event());
225  fEvt->set_signal_process_id(13);
226 
227  fEvt->weights().push_back( CosMuoGen->EventWeight ); // just one event weight
228  fEvt->weights().push_back( CosMuoGen->Trials ); // int Trials number (unweighted)
229 
230 
231  if (cmVerbosity_) fEvt->print();
232 
233  std::auto_ptr<HepMCProduct> CMProduct(new HepMCProduct());
234  CMProduct->addHepMCData( fEvt );
235  e.put(CMProduct);
236 
237  std::auto_ptr<GenEventInfoProduct> genEventInfo(new GenEventInfoProduct( fEvt ));
238  e.put(genEventInfo);
239 
240 }
void setZDistOfTarget(double Z)
EventNumber_t event() const
Definition: EventID.h:44
int i
Definition: DBlmapReader.cc:9
void initialize(CLHEP::HepRandomEngine *rng=0)
virtual void produce(Event &e, const EventSetup &es)
void setMinEnu(double MinEn)
auto_ptr< ClusterSequence > cs
void setTIFOnly_constant(bool TIF)
void setNuProdAlt(double NuPrdAlt)
void setZCentrOfTarget(double Z)
void setRhoAir(double VarRhoAir)
virtual void endRun(Run &r, const EventSetup &es)
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:85
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
Definition: matutil.cc:168
void setMultiMuonNmin(int MultiMuNmin)
bool isAvailable() const
Definition: Service.h:47
void setMinTheta(double Theta)
void setMaxEnu(double MaxEn)
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)
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:81
void setRhoWall(double VarRhoSWall)
void setPlugVx(double PlugVtx)
void setRhoRock(double VarRhoRock)
const bool Debug
void setRhoClay(double VarRhoClay)
Definition: Run.h:33
void setTrackerOnly(bool Tracker)