StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
PlotPythia.C
1 // Author V.Fine 06/12/2001 BNL mailto:fine@bnl.gov
2 // This reads Pythia file created by P2ATest.C macro
3 // Thanks Michael Bussmann <Michael.Bussmann@physik.uni-muenchen.de> for Pythia living example
4 // Thanks Christian Holm Christensen <cholm@nbi.dk> for Pythia histogramming pattern
5 
6 #define HISTNAME "ptSpectra"
7 #define PDGNUMBER 211
8 
9 TH1D* ptSpectra = 0;
10 void PlotPythia(const char *fileName="pythia.root")
11 {
12  struct pythia_particle {
13  Int_t status; // status of particle ( LUJETS K[1] )
14  Int_t pdg_id; // flavour code ( LUJETS K[2] )
15  Int_t parent; // parrent's id ( LUJETS K[3] )
16  Int_t firstChild; // id of first child ( LUJETS K[4] )
17  Int_t lastChild; // id of last child ( LUJETS K[5] )
18  Float_t momentum[4]; // X.Y,Z,energy momenta [GeV/c]( LUJETS P[1]=P[4] )
19  Float_t mass; // Mass [Gev/c^2] ( LUJETS P[5] )
20  Float_t vertex[4]; // X,Y,Z vertex [mm]; time of production [mm/c]( LUJETS V[1]-V[4] )
21  Float_t lifetime; // proper lifetime [mm/c] ( LUJETS V[5] )
22  };
23  // LoadPythia();
24  printf("\nUsage: root LoadPythia.C PlotPythia.C(fileName=\"pythia.root\")\n");
25  printf( "-----\n\n");
26 
27  printf("\n To create \"pythia.root\" input file run first");
28  printf("\n > root LoadPythia.C P2ATest.C\n");
29  printf( "-----\n\n");
30 
31 
32  TFileIter readEvents(fileName);
33  TObject *nextObject = 0;
34  // the number of the object available directly from "MyDataSet.root"
35  Int_t size = readEvents.TotalKeys();
36  printf(" The total number of the events: %d\n",size);
37 
38  //-----------------------------------------------------------------------
39  // Loop over all events, read them in to memory one by one
40  // we may want to do some summary plots:
41  // The historamming was provided thanks Christian Holm Christensen mailto::cholm@nbi.dk
42 
43  ptSpectra = new TH1D(HISTNAME, "p_{#perp} spectrum for #pi^{+}",
44  100, 0, 3);
45  ptSpectra->SetXTitle("p_{#perp}");
46  ptSpectra->SetYTitle("dN/dp_{#perp}");
47  printf(" -- > Loop over all events, read them in to memory one by one < -- \n");
48 
49  for( readEvents = 0; int(readEvents) < size; readEvents.SkipObjects() ){
50  nextObject = *readEvents;
51  printf(" %d bytes of the object \"%s\" of class \"%s\" written with TKey \"%s\" has been read from file\n"
52  ,readEvents.GetObjlen()
53  ,nextObject->GetName()
54  ,nextObject->IsA()->GetName()
55  ,(const char *)readEvents
56  );
57  TDataSet *event = (TDataSet *)nextObject;
58  TGenericTable *particles = (TGenericTable *)event->FindByName("particle");
59  if (particles) particles->Draw(Form("sqrt(pow(momentum[0],2)+pow(momentum[1],2))>>+%s", HISTNAME),
60  Form("pdg_id==%d", PDGNUMBER) );
61  c1->Update();
62  event->ls(9);
63  delete nextObject;
64  }
65  // Normalise to the number of events, and the bin sizes.
66  ptSpectra->SetDirectory(0); // We need this otherwise Rene BRun will kill our histogram shortly
67  ptSpectra->Sumw2();
68  ptSpectra->Scale(3 / 100. / ptSpectra->Integral());
69  ptSpectra->Fit("expo", "QO+", "", .25, 1.75);
70  TF1* func = ptSpectra->GetFunction("expo");
71  func->SetParNames("A", "- 1 / T");
72  c1->Update();
73 }