StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
P2ATest.C
1 // Author V.Fine 06/12/2001 BNL mailto:fine@bnl.gov
2 // This run Pythia using ROOT TPythia6 interface
3 // Thanks Michael Bussmann <Michael.Bussmann@physik.uni-muenchen.de> for Pythia living example
4 #ifndef __CINT__
5 # include <stdlib.h>
6 # include <ostream.h>
7 # include <TROOT.h>
8 # include <TRint.h>
9 # include <TApplication.h>
10 # include <TFile.h>
11 # include <TMCParticle.h>
12 # include <TObjArray.h>
13 # include <TPythia6.h>
14 # include <TTree.h>
15 
16 #endif
17 
18  // From $include $ROOTSYS/include/TPythia6Calls.h
19  struct Pyjets_t {
20  int N;
21  int NPAD;
22  int K[5][4000];
23  double P[5][4000];
24  double V[5][4000];
25  };
26 
27  struct pythia_particle {
28  Int_t status; // status of particle ( LUJETS K[1] )
29  Int_t pdg_id; // flavour code ( LUJETS K[2] )
30  Int_t parent; // parrent's id ( LUJETS K[3] )
31  Int_t firstChild; // id of first child ( LUJETS K[4] )
32  Int_t lastChild; // id of last child ( LUJETS K[5] )
33  Float_t momentum[4]; // X,Y,Z,energy momenta [GeV/c]( LUJETS P[1]=P[4] )
34  Float_t mass; // Mass [Gev/c^2] ( LUJETS P[5] )
35  Float_t vertex[4]; // X,Y,Z vertex [mm]; time of procuction [mm/c]( LUJETS V[1]-V[4] )
36  Float_t lifetime; // proper lifetime [mm/c] ( LUJETS V[5] )
37  };
38 
39 TDataSet *fillathenaEvent(TPythia6 &pythia);
40 int P2ATest(int nEvent=5, int compress=1);
41 //____________________________________________________________________________
42 int P2ATest(int nEvent, int compress)
43 {
44 
45  // LoadPythia();
46  printf("\nUsage: root LoadPythia.C 'P2ATest.C(nEvent)'\n");
47  printf( "----- where nEvent - the total number of the events to generate\n");
48  TStopwatch fulltime;
49  Int_t i;
50  Int_t NEvents;
51  Int_t startdecay;
52  Int_t enddecay;
53 
54  NEvents = nEvent;
55 
56  // Open an output file
57  TFileIter MCFile("pythia.root","RECREATE","pythia.root", compress);
58  TPythia6 Pythia;
59 
60  //pythia switches
61 
62  Pythia.SetMSEL(0); //set subprocesses by hand
63  Pythia.SetMSTP(48, 1); //t->W+b
64  Pythia.SetMSTJ(11, 3); //select fragmentation function "Bowler"
65  Pythia.SetPARJ(50+4, -0.07); //peterson parameter for charm
66  Pythia.SetPARJ(50+5, -0.006); //peterson parameter for bottom
67  Pythia.SetPARJ(50+5, -0.000001); //peterson parameter for top
68  Pythia.SetPMAS(6, 1, 174.3); //top mass
69  Pythia.SetPMAS(25, 1, 120.0); //higgs mass
70  Pythia.SetMSTP(61, 1); //ISR "on"
71  Pythia.SetMSTP(71, 1); //FSR "on"
72  Pythia.SetMSTP(81, 1); //multiple interactions "on"
73  Pythia.SetMSTP(111, 1); //fragmentation "on"
74  Pythia.SetMSTP(82, 3); //multiple interaction "vary impact param"
75  Pythia.SetPARP(82, 2.41); //cut-off pt for multiple interaction
76  Pythia.SetMRPY(1, 88158204); //random seed number
77 
78  Pythia.SetMSUB(26, 1); //set subprocess WH
79  Pythia.SetMDCY(24, 1, 1); //W decaying
80  Pythia.SetMDCY(25, 1, 1); //H decaying
81 
82  //close all W decay channels
83 
84  startdecay = Pythia.GetMDCY(24, 2);
85  enddecay = Pythia.GetMDCY(24, 2) + Pythia.GetMDCY(24, 3);
86  for ( i=startdecay; i<enddecay; i++ ) Pythia.SetMDME(i, 1, 0);
87 
88  //close all H decay channels
89 
90  startdecay = Pythia.GetMDCY(25, 2);
91  enddecay = Pythia.GetMDCY(25, 2) + Pythia.GetMDCY(25, 3);
92  for ( i=startdecay; i<enddecay; i++ ) Pythia.SetMDME(i, 1, 0);
93 
94  //open wanted W decay channels
95 
96  Pythia.SetMDME(206, 1, 1); //W->e+nu
97  Pythia.SetMDME(207, 1, 1); //W->mu+nu
98  Pythia.SetMDME(208, 1, 1); //W->tau+nu
99 
100  //open wanted W decay channels
101 
102  Pythia.SetMDME(214, 1, 1); //H->b+bbar
103 
104  //initialize Pythia for D0
105 
106  Pythia.Initialize("CMS", "p", "pbar", 2000.0);
107 
108 // --
109 // Initilaise athena-compliant ROOT I/O
110 // --
111 
112  //generate events
113 
114  TStopwatch ioTime;
115  ioTime.Stop();
116  for ( i=0; i<NEvents; i++ ) {
117 
118  if ( i%10 == 0 ) cout << "Event No.: " << i << endl;
119 
120  Pythia.GenerateEvent();
121 // --
122 // -- Conversion Pythia event to Athena/Root event
123 // --
124 
125 // Create "MCEvent" object
126  ioTime.Start(kFALSE);
127  TDataSet *mcEvent = fillathenaEvent(Pythia);
128 
129 // Write the "whole" event into ROOT file
130  int runNumber = 777;
131  int eventNumber = i;
132  MCFile.NextEventPut(mcEvent,runNumber,eventNumber);
133 
134 // delete this "event"
135  delete mcEvent;
136  ioTime.Stop();
137  }
138  printf(" Full time: "); fulltime.Print();
139  printf(" I/O time: "); ioTime.Print();
140  printf("\nUsage: root LoadPythia.C 'P2ATest.C(nEvent)'\n");
141  printf( "----- where nEvent - the total number of the events to generate\n");
142 }
143 
144 //____________________________________________________________________________
145 TDataSet *fillathenaEvent(TPythia6 &pythia)
146 {
147  //Create a TPythia6* object Pythia and do some settings for Pythia
148 
149  Pyjets_t* pythiaParticle = pythia.GetPyjets();
150  Int_t nParticle = pythia.GetN();
151  TGenericTable *particles = new TGenericTable("pythia_particle","particle",nParticle);
152  for (int i=0;i<nParticle;i++)
153  {
154  pythia_particle particle;
155  memset(&particle,0,sizeof(particle));
156  particle.momentum[0] = pythiaParticle->P[0][i]; // px
157  particle.momentum[1] = pythiaParticle->P[1][i]; // px
158  particle.momentum[2] = pythiaParticle->P[2][i]; // px
159  particle.momentum[3] = pythiaParticle->P[3][i]; // energy
160  particle.mass = pythiaParticle->P[4][i]; // mass
161 
162  particle.status = pythiaParticle->K[0][i]; // kS
163  particle.pdg_id = pythiaParticle->K[1][i]; // kF
164  particle.parent = pythiaParticle->K[2][i]; // parent
165  particle.firstChild = pythiaParticle->K[3][i]; // firstchild
166  particle.lastChild = pythiaParticle->K[4][i]; // lastchild
167 
168  particle.vertex[0] = pythiaParticle->V[0][i]; // vx
169  particle.vertex[1] = pythiaParticle->V[1][i]; // vy
170  particle.vertex[2] = pythiaParticle->V[2][i]; // vz
171  particle.vertex[3] = pythiaParticle->V[3][i]; // time
172 
173  particle.lifetime = pythiaParticle->V[4][i]; // lifetime
174  particles->AddAt(&particle);
175  }
176  TDataSet *mcEvent = new TDataSet("MCEvent");
177  mcEvent->Add(particles);
178  return mcEvent; // caller has to delete this object;
179 }
virtual Int_t AddAt(const void *c)
Definition: TTable.cxx:1122