CMS 3D CMS Logo

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
55  CosMuoGen = std::make_unique<CosmicMuonGenerator>();
56 // Begin JMM change
57 // CosMuoGen->setNumberOfEvents(numberEventsInRun());
58  CosMuoGen->setNumberOfEvents(999999999);
59 // End of JMM change
60  CosMuoGen->setRanSeed(RanS);
61  CosMuoGen->setMinP(MinP);
62  CosMuoGen->setMinP_CMS(MinP_CMS);
63  CosMuoGen->setMaxP(MaxP);
64  CosMuoGen->setMinTheta(MinT);
65  CosMuoGen->setMaxTheta(MaxT);
66  CosMuoGen->setMinPhi(MinPh);
67  CosMuoGen->setMaxPhi(MaxPh);
68  CosMuoGen->setMinT0(MinS);
69  CosMuoGen->setMaxT0(MaxS);
70  CosMuoGen->setElossScaleFactor(ELSF);
71  CosMuoGen->setRadiusOfTarget(RTarget);
72  CosMuoGen->setZDistOfTarget(ZTarget);
73  CosMuoGen->setZCentrOfTarget(ZCTarget);
74  CosMuoGen->setTrackerOnly(TrackerOnly);
75  CosMuoGen->setMultiMuon(MultiMuon);
76  CosMuoGen->setMultiMuonFileName(MultiMuonFileName);
77  CosMuoGen->setMultiMuonFileFirstEvent(MultiMuonFileFirstEvent);
78  CosMuoGen->setMultiMuonNmin(MultiMuonNmin);
79  CosMuoGen->setTIFOnly_constant(TIFOnly_constant);
80  CosMuoGen->setTIFOnly_linear(TIFOnly_linear);
81  CosMuoGen->setMTCCHalf(MTCCHalf);
82  CosMuoGen->setPlugVx(PlugVtx);
83  CosMuoGen->setPlugVz(PlugVtz);
84  CosMuoGen->setRhoAir(VarRhoAir);
85  CosMuoGen->setRhoWall(VarRhoWall);
86  CosMuoGen->setRhoRock(VarRhoRock);
87  CosMuoGen->setRhoClay(VarRhoClay);
88  CosMuoGen->setRhoPlug(VarRhoPlug);
89  CosMuoGen->setClayWidth(ClayLayerWidth);
90  CosMuoGen->setMinEnu(MinEn);
91  CosMuoGen->setMaxEnu(MaxEn);
92  CosMuoGen->setNuProdAlt(NuPrdAlt);
93  CosMuoGen->setAcptAllMu(AllMu);
94  produces<HepMCProduct>("unsmeared");
95  produces<GenEventInfoProduct>();
96  produces<GenRunInfoProduct, edm::Transition::EndRun>();
97  }
98 
100  clear();
101 }
102 
104 {
105  if(!isInitialized_) {
106  isInitialized_ = true;
107  RandomEngineSentry<CosmicMuonGenerator> randomEngineSentry(CosMuoGen.get(), lumi.index());
108  CosMuoGen->initialize(randomEngineSentry.randomEngine());
109  }
110 }
111 
113 {
114  std::unique_ptr<GenRunInfoProduct> genRunInfo(new GenRunInfoProduct());
115 
116  double cs = CosMuoGen->getRate(); // flux in Hz, not s^-1m^-2
117  if (MultiMuon) genRunInfo->setInternalXSec(0.);
118  else genRunInfo->setInternalXSec(cs);
119  genRunInfo->setExternalXSecLO(extCrossSect);
120  genRunInfo->setFilterEfficiency(extFilterEff);
121 
122  run.put(std::move(genRunInfo));
123 
124  CosMuoGen->terminate();
125 }
126 
128 
130 {
131  RandomEngineSentry<CosmicMuonGenerator> randomEngineSentry(CosMuoGen.get(), e.streamID());
132 
133  // generate event
134  if (!MultiMuon) {
135  CosMuoGen->nextEvent();
136  }
137  else {
138  bool success = CosMuoGen->nextMultiEvent();
139  if (!success) std::cout << "CosMuoGenProducer.cc: CosMuoGen->nextMultiEvent() failed!"
140  << std::endl;
141  }
142 
143  if (Debug) {
144  std::cout << "CosMuoGenProducer.cc: CosMuoGen->EventWeight=" << CosMuoGen->EventWeight
145  << " CosMuoGen: Nmuons=" << CosMuoGen->Id_sf.size() << std::endl;
146  std::cout << "CosMuoGen->Id_at=" << CosMuoGen->Id_at
147  << " CosMuoGen->Vx_at=" << CosMuoGen->Vx_at
148  << " CosMuoGen->Vy_at=" << CosMuoGen->Vy_at
149  << " CosMuoGen->Vz_at=" << CosMuoGen->Vz_at
150  << " CosMuoGen->T0_at=" << CosMuoGen->T0_at << std::endl;
151  std::cout << " Px=" << CosMuoGen->Px_at
152  << " Py=" << CosMuoGen->Py_at
153  << " Pz=" << CosMuoGen->Pz_at << std::endl;
154  for (unsigned int i=0; i<CosMuoGen->Id_sf.size(); ++i) {
155  std::cout << "Id_sf[" << i << "]=" << CosMuoGen->Id_sf[i]
156  << " Vx_sf[" << i << "]=" << CosMuoGen->Vx_sf[i]
157  << " Vy_sf=" << CosMuoGen->Vy_sf[i]
158  << " Vz_sf=" << CosMuoGen->Vz_sf[i]
159  << " T0_sf=" << CosMuoGen->T0_sf[i]
160  << " Px_sf=" << CosMuoGen->Px_sf[i]
161  << " Py_sf=" << CosMuoGen->Py_sf[i]
162  << " Pz_sf=" << CosMuoGen->Pz_sf[i] << std::endl;
163  std::cout << "phi_sf=" << atan2(CosMuoGen->Px_sf[i],CosMuoGen->Pz_sf[i]) << std::endl;
164  std::cout << "Id_ug[" << i << "]=" << CosMuoGen->Id_ug[i]
165  << " Vx_ug[" << i << "]=" << CosMuoGen->Vx_ug[i]
166  << " Vy_ug=" << CosMuoGen->Vy_ug[i]
167  << " Vz_ug=" << CosMuoGen->Vz_ug[i]
168  << " T0_ug=" << CosMuoGen->T0_ug[i]
169  << " Px_ug=" << CosMuoGen->Px_ug[i]
170  << " Py_ug=" << CosMuoGen->Py_ug[i]
171  << " Pz_ug=" << CosMuoGen->Pz_ug[i] << std::endl;
172  std::cout << "phi_ug=" << atan2(CosMuoGen->Px_ug[i],CosMuoGen->Pz_ug[i]) << std::endl;;
173  }
174  }
175 
176 
177  auto fEvt = std::make_unique<HepMC::GenEvent>();
178 
179  HepMC::GenVertex* Vtx_at = new HepMC::GenVertex(HepMC::FourVector(CosMuoGen->Vx_at, //[mm]
180  CosMuoGen->Vy_at, //[mm]
181  CosMuoGen->Vz_at, //[mm]
182  CosMuoGen->T0_at)); //[mm]
183  //cout << "CosMuoGenProducer.cc: Vy_at=" << CosMuoGen->Vy_at << endl;
184  HepMC::FourVector p_at(CosMuoGen->Px_at,CosMuoGen->Py_at,CosMuoGen->Pz_at,CosMuoGen->E_at);
185  HepMC::GenParticle* Part_at =
186  new HepMC::GenParticle(p_at,CosMuoGen->Id_at, 3);//Comment mother particle in
187  Vtx_at->add_particle_in(Part_at);
188 
189 
190  //loop here in case of multi muon events (else just one iteration)
191  for (unsigned int i=0; i<CosMuoGen->Id_sf.size(); ++i) {
192 
193  HepMC::FourVector p_sf(CosMuoGen->Px_sf[i],CosMuoGen->Py_sf[i],CosMuoGen->Pz_sf[i],CosMuoGen->E_sf[i]);
194  HepMC::GenParticle* Part_sf_in =
195  new HepMC::GenParticle(p_sf,CosMuoGen->Id_sf[i], 3); //Comment daughter particle
196  Vtx_at->add_particle_out(Part_sf_in);
197 
198  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]
199  HepMC::GenParticle* Part_sf_out =
200  new HepMC::GenParticle(p_sf,CosMuoGen->Id_sf[i], 3); //Comment daughter particle
201 
202  Vtx_sf->add_particle_in(Part_sf_in);
203  Vtx_sf->add_particle_out(Part_sf_out);
204 
205  fEvt->add_vertex(Vtx_sf); //one per muon
206 
207  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]
208 
209  HepMC::FourVector p_ug(CosMuoGen->Px_ug[i],CosMuoGen->Py_ug[i],CosMuoGen->Pz_ug[i],CosMuoGen->E_ug[i]);
210  HepMC::GenParticle* Part_ug =
211  new HepMC::GenParticle(p_ug,CosMuoGen->Id_ug[i], 1);//Final state daughter particle
212 
213  Vtx_ug->add_particle_in(Part_sf_out);
214  Vtx_ug->add_particle_out(Part_ug);
215 
216  fEvt->add_vertex(Vtx_ug); //one per muon
217 
218  }
219 
220  fEvt->add_vertex(Vtx_at);
221  fEvt->set_signal_process_vertex(Vtx_at);
222 
223  fEvt->set_event_number(e.id().event());
224  fEvt->set_signal_process_id(13);
225 
226  fEvt->weights().push_back( CosMuoGen->EventWeight ); // just one event weight
227  fEvt->weights().push_back( CosMuoGen->Trials ); // int Trials number (unweighted)
228 
229 
230  if (cmVerbosity_) fEvt->print();
231 
232  std::unique_ptr<GenEventInfoProduct> genEventInfo(new GenEventInfoProduct( fEvt.get() ));
233  e.put(std::move(genEventInfo));
234 
235  //This causes fEvt to be deleted
236  std::unique_ptr<HepMCProduct> CMProduct(new HepMCProduct());
237  CMProduct->addHepMCData( fEvt.release() );
238  e.put(std::move(CMProduct), "unsmeared");
239 }
EventNumber_t event() const
Definition: EventID.h:41
void endRunProduce(Run &r, const EventSetup &es) override
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
LuminosityBlockIndex index() const
unique_ptr< ClusterSequence > cs
std::unique_ptr< CosmicMuonGenerator > CosMuoGen
CosMuoGenProducer(const ParameterSet &)
void produce(Event &e, const EventSetup &es) override
void beginLuminosityBlock(LuminosityBlock const &, EventSetup const &) override
void put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Run.h:108
edm::EventID id() const
Definition: EventBase.h:59
StreamID streamID() const
Definition: Event.h:95
const bool Debug
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:45