CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Pythia6Gun.cc
Go to the documentation of this file.
1 /*
2  * \author Julia Yarba
3  */
4 
5 #include <iostream>
6 
7 #include "Pythia6Gun.h"
8 
9 //#include "SimGeneral/HepPDTRecord/interface/ParticleDataTable.h"
12 
18 
20 
21 using namespace edm;
22 using namespace gen;
23 
24 
25 Pythia6Gun::Pythia6Gun( const ParameterSet& pset ) :
26  fPy6Service( new Pythia6Service(pset) ),
27  fEvt(0)
28  // fPDGTable( new DefaultConfig::ParticleDataTable("PDG Table") )
29 {
30 
31  ParameterSet pgun_params =
32  pset.getParameter<ParameterSet>("PGunParameters");
33 
34  // although there's the method ParameterSet::empty(),
35  // it looks like it's NOT even necessary to check if it is,
36  // before trying to extract parameters - if it is empty,
37  // the default values seem to be taken
38  //
39  fMinPhi = pgun_params.getParameter<double>("MinPhi"); // ,-3.14159265358979323846);
40  fMaxPhi = pgun_params.getParameter<double>("MaxPhi"); // , 3.14159265358979323846);
41 
42  fHepMCVerbosity = pset.getUntrackedParameter<bool>("pythiaHepMCVerbosity", false ) ;
43  fPylistVerbosity = pset.getUntrackedParameter<int>( "pythiaPylistVerbosity", 0 ) ;
44  fMaxEventsToPrint = pset.getUntrackedParameter<int>( "maxEventsToPrint", 0 );
45 
46 // Turn off banner printout
47  if (!call_pygive("MSTU(12)=12345"))
48  {
49  throw edm::Exception(edm::errors::Configuration,"PythiaError")
50  <<" pythia did not accept MSTU(12)=12345";
51  }
52 
53  produces<HepMCProduct>("unsmeared");
54 
55 }
56 
58 {
59  if ( fPy6Service ) delete fPy6Service;
60  //
61  // note that GenEvent or any undelaying (GenVertex, GenParticle) do NOT
62  // need to be cleaned, as it'll be done automatically by HepMCProduct
63  //
64 }
65 
66 
68 {
69  // es.getData( fPDGTable ) ;
70  return ;
71 
72 }
73 
74 void Pythia6Gun::beginRun( Run const&, EventSetup const& es )
75 {
76  std::cout << " FYI: MSTU(10)=1 is ENFORCED in Py6-PGuns, for technical reasons"
77  << std::endl;
78  return;
79 }
80 
82 
83  assert ( fPy6Service ) ;
84 
86 
87  Pythia6Service::InstanceWrapper guard(fPy6Service); // grab Py6 instance
88 
92 
93  call_pygive("MSTU(10)=1");
94 
95  call_pyinit("NONE", "", "", 0.0);
96 }
97 
98 void Pythia6Gun::endRun( Run const&, EventSetup const& es )
99 {
100 
101  // here put in GenRunInfoProduct
102 
103  call_pystat(1);
104 
105  return;
106 }
107 
109 {
110 
111  for ( int iprt=fPartIDs.size(); iprt<pyjets.n; iprt++ ) // the pointer is shifted by -1, c++ style
112  {
113  int parent = pyjets.k[2][iprt];
114  if ( parent != 0 )
115  {
116  // pull up parent particle
117  //
118  HepMC::GenParticle* parentPart = fEvt->barcode_to_particle( parent );
119  parentPart->set_status( 2 ); // reset status, to mark that it's decayed
120 
121  HepMC::GenVertex* DecVtx = new HepMC::GenVertex(HepMC::FourVector(pyjets.v[0][iprt],
122  pyjets.v[1][iprt],
123  pyjets.v[2][iprt],
124  pyjets.v[3][iprt]));
125  DecVtx->add_particle_in( parentPart ); // this will cleanup end_vertex if exists,
126  // and replace with the new one
127  // I presume barcode will be given automatically
128 
129  HepMC::FourVector pmom(pyjets.p[0][iprt],pyjets.p[1][iprt],
130  pyjets.p[2][iprt],pyjets.p[3][iprt] );
131 
132  int dstatus = 0;
133  if ( pyjets.k[0][iprt] >= 1 && pyjets.k[0][iprt] <= 10 )
134  {
135  dstatus = 1;
136  }
137  else if ( pyjets.k[0][iprt] >= 11 && pyjets.k[0][iprt] <= 20 )
138  {
139  dstatus = 2;
140  }
141  else if ( pyjets.k[0][iprt] >= 21 && pyjets.k[0][iprt] <= 30 )
142  {
143  dstatus = 3;
144  }
145  else if ( pyjets.k[0][iprt] >= 31 && pyjets.k[0][iprt] <= 100 )
146  {
147  dstatus = pyjets.k[0][iprt];
148  }
149  HepMC::GenParticle* daughter =
150  new HepMC::GenParticle(pmom,
151  HepPID::translatePythiatoPDT( pyjets.k[1][iprt] ),
152  dstatus);
153  daughter->suggest_barcode( iprt+1 );
154  DecVtx->add_particle_out( daughter );
155  // give particle barcode as well !
156 
157  int iprt1;
158  for ( iprt1=iprt+1; iprt1<pyjets.n; iprt1++ ) // the pointer is shifted by -1, c++ style
159  {
160  if ( pyjets.k[2][iprt1] != parent ) break; // another parent particle, break the loop
161 
162  HepMC::FourVector pmomN(pyjets.p[0][iprt1],pyjets.p[1][iprt1],
163  pyjets.p[2][iprt1],pyjets.p[3][iprt1] );
164 
165  dstatus = 0;
166  if ( pyjets.k[0][iprt1] >= 1 && pyjets.k[0][iprt1] <= 10 )
167  {
168  dstatus = 1;
169  }
170  else if ( pyjets.k[0][iprt1] >= 11 && pyjets.k[0][iprt1] <= 20 )
171  {
172  dstatus = 2;
173  }
174  else if ( pyjets.k[0][iprt1] >= 21 && pyjets.k[0][iprt1] <= 30 )
175  {
176  dstatus = 3;
177  }
178  else if ( pyjets.k[0][iprt1] >= 31 && pyjets.k[0][iprt1] <= 100 )
179  {
180  dstatus = pyjets.k[0][iprt1];
181  }
182  HepMC::GenParticle* daughterN =
183  new HepMC::GenParticle(pmomN,
184  HepPID::translatePythiatoPDT( pyjets.k[1][iprt1] ),
185  dstatus);
186  daughterN->suggest_barcode( iprt1+1 );
187  DecVtx->add_particle_out( daughterN );
188  }
189 
190  iprt = iprt1-1; // reset counter such that it doesn't go over the same child more than once
191  // don't forget to offset back into c++ counting, as it's already +1 forward
192 
193  fEvt->add_vertex( DecVtx );
194 
195  }
196  }
197 
198  return;
199 
200 }
201 
203 {
205 
207 
208  fEvt->set_beam_particles(0,0);
209  fEvt->set_event_number(evt.id().event()) ;
210  fEvt->set_signal_process_id(pypars.msti[0]) ;
211 
213 
214  int evtN = evt.id().event();
215  if ( evtN <= fMaxEventsToPrint )
216  {
217  if ( fPylistVerbosity )
218  {
220  }
221  if ( fHepMCVerbosity )
222  {
223  if ( fEvt ) fEvt->print();
224  }
225  }
226 
227  loadEvent( evt );
228 }
229 
231 {
232 
233  std::unique_ptr<HepMCProduct> bare_product(new HepMCProduct());
234 
235  if(fEvt) bare_product->addHepMCData( fEvt );
236 
237  evt.put(std::move(bare_product), "unsmeared");
238 
239 
240  return;
241 
242 }
243 
245  double& ee, double& eta, double& phi )
246 {
247 
248  if ( ip < 2 ) return 0;
249 
250 // translate PDG to Py6
251  int py6PID = HepPID::translatePDTtoPythia( particleID );
252 // Check if particle is its own anti-particle.
253  int pythiaCode = pycomp_(py6PID); // this is py6 internal validity check, it takes Pythia6 pid
254  // so actually I'll need to convert
255  int has_antipart = pydat2.kchg[3-1][pythiaCode-1];
256  int particleID2 = has_antipart ? -1 * particleID : particleID; // this is PDG, for HepMC::GenEvent
257  int py6PID2 = has_antipart ? -1 * py6PID : py6PID; // this py6 id, for py1ent
258  double the = 2.*atan(exp(eta));
259  phi = phi + M_PI;
260  if (phi > 2.* M_PI) {phi = phi - 2.* M_PI;}
261 
262  // copy over mass of the previous one, because then py6 will pick it up
263  pyjets.p[4][ip-1] = pyjets.p[4][ip-2];
264 
265  py1ent_(ip, py6PID2, ee, the, phi);
266 
267  double px = pyjets.p[0][ip-1]; // pt*cos(phi) ;
268  double py = pyjets.p[1][ip-1]; // pt*sin(phi) ;
269  double pz = pyjets.p[2][ip-1]; // mom*cos(the) ;
270  HepMC::FourVector ap(px,py,pz,ee) ;
271  HepMC::GenParticle* APart =
272  new HepMC::GenParticle(ap,particleID2,1);
273  APart->suggest_barcode( ip ) ;
274 
275  return APart;
276 
277 }
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
T getUntrackedParameter(std::string const &, T const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
void beginJob() override
Definition: Pythia6Gun.cc:67
void endRun(edm::Run const &, edm::EventSetup const &) override
Definition: Pythia6Gun.cc:98
CLHEP::HepRandomEngine * randomEngine() const
LuminosityBlockIndex index() const
void produce(edm::Event &, const edm::EventSetup &) override
Definition: Pythia6Gun.cc:202
void beginRun(edm::Run const &, edm::EventSetup const &) override
Definition: Pythia6Gun.cc:74
tuple lumi
Definition: fjr2json.py:35
void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
Definition: Pythia6Gun.cc:81
assert(m_qm.get())
bool call_pygive(const std::string &line)
HepMC::GenParticle * addAntiParticle(int &, int &, double &, double &, double &)
Definition: Pythia6Gun.cc:244
HepMC::GenEvent * fEvt
Definition: Pythia6Gun.h:71
bool fHepMCVerbosity
Definition: Pythia6Gun.h:78
int fPylistVerbosity
Definition: Pythia6Gun.h:79
virtual void generateEvent(CLHEP::HepRandomEngine *)=0
def gen
run2 Cosmic #### Run 256259 @ 0T 2015C### Run 272133 @ 3.8T 2016B###
void call_pylist(int mode)
virtual ~Pythia6Gun()
Definition: Pythia6Gun.cc:57
void attachPy6DecaysToGenEvent()
Definition: Pythia6Gun.cc:108
double fMinPhi
Definition: Pythia6Gun.h:66
int fMaxEventsToPrint
Definition: Pythia6Gun.h:80
def move
Definition: eostools.py:510
void loadEvent(edm::Event &)
Definition: Pythia6Gun.cc:230
#define M_PI
int pycomp_(int &)
#define pypars
double fMaxPhi
Definition: Pythia6Gun.h:67
return(e1-e2)*(e1-e2)+dp *dp
void py1ent_(int &ip, int &kf, double &pe, double &the, double &phi)
edm::EventID id() const
Definition: EventBase.h:58
Pythia6Service * fPy6Service
Definition: Pythia6Gun.h:61
StreamID streamID() const
Definition: Event.h:81
tuple cout
Definition: gather_cfg.py:145
volatile std::atomic< bool > shutdown_flag false
std::vector< int > fPartIDs
Definition: Pythia6Gun.h:65
Definition: Run.h:42