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