StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
GenerateVertex.C
1 // Pibero Djawotho <pibero@tamu.edu>
2 // Texas A&M University
3 // 11 Dec 2010
4 
5 
6 class vertexSeed_st;
7 class St_db_Maker;
8 
9 
10 void UpdateBeamline(St_db_Maker* db, vertexSeed_st& beamline)
11 {
12  // get beam line constraint
13  TDataSet *ds = db->GetInputDB("Calibrations/rhic");
14 
15  vertexSeed_st *vs = ds ? ((St_vertexSeed *)ds->FindObject("vertexSeed"))->GetTable() : 0;
16 
17  if (!ds || !vs) {
18  std::cout << "UpdateBeamline: Data from \"Calibrations/rhic/vertexSeed\" not found\n"
19  << "Beamline parameters won't be updated" << std::endl;
20  return;
21  }
22 
23  std::cout << "BeamLine parameters:\n"
24  << "x(z) = (" << vs->x0 << " +/- " << vs->err_x0 << ") + (" << vs->dxdz << " +/- " << vs->err_dxdz << ") * z\n"
25  << "y(z) = (" << vs->y0 << " +/- " << vs->err_y0 << ") + (" << vs->dydz << " +/- " << vs->err_dydz << ") * z" << std::endl;
26 
27  beamline = *vs;
28 }
29 
30 
31 
39 void GenerateVertex(const char *dataFileName = 0,
40  const TVector3 vtxSpread=TVector3(0.03, 0.03, 50), const double vtxZOffset = 0,
41  int nevents = 1000, int seed = 0, const char *daqfile = "@run10179086.list", const char *vertexfile = "vertex.txt", const char *flag = "Jet")
42 {
43  // load generic STAR libraries
44  gSystem->Load("St_base");
45  gSystem->Load("StChain");
46  gSystem->Load("StBFChain");
47  gSystem->Load("StUtilities");
48  gSystem->Load("StIOMaker");
49  gSystem->Load("StarClassLibrary");
50 
51  // load STAR db-related libraries
52  gSystem->Load("St_Tables");
53  gSystem->Load("StDbLib");
54  gSystem->Load("StDbBroker");
55  gSystem->Load("St_db_Maker");
56 
57  // create chain
58  StChain *chain = new StChain;
59 
60  // Read DAQ file to get time stamp
61  StIOMaker *io = new StIOMaker;
62  io->SetFile(daqfile);
63  io->SetIOMode("r");
64  io->SetBranch("*", 0, "0"); // deactivate all branches
65 
66  // create db object
67  St_db_Maker *db = new St_db_Maker("db", "MySQL:StarDb", "$STAR/StarDb");
68 
69  // initialize chain and read first event to get time stamp
70  chain->Init();
71 
72  vertexSeed_st beamline;// =0;
73 
74  // output files
75  FILE *VERTEXFILE = fopen(vertexfile, "w");
76  assert(VERTEXFILE);
77 
78  TString rootfile = vertexfile;
79  rootfile.ReplaceAll(".txt", ".root");
80 
81  TFile *ofile = TFile::Open(rootfile, "recreate");
82  assert(ofile);
83 
84  // histograms
85  TH1F *hVz = new TH1F("hVz ", "; vz [cm]", 100, -50, 50);
86  TH2F *hVxy = new TH2F("hVxy", "; vx [cm]; vy [cm]", 50, -2.5, 2.5, 50, -2.5, 2.5);
87  TH2F *hVzx = new TH2F("hVzx", "; vz [cm]; vx [cm]", 100, -50, 50, 50, -2.5, 2.5);
88  TH2F *hVzy = new TH2F("hVzy", "; vz [cm]; vy [cm]", 100, -50, 50, 50, -2.5, 2.5);
89 
90  // Randomize
91  gRandom->SetSeed(seed);
92 
93  // event loop
94  for (int iEvent = 1; iEvent <= nevents; ++iEvent) {
95  chain->Clear();
96  int iMake = chain->Make(iEvent);
97 
98  if (iMake == kStSkip) continue;
99 
100  if (flag == "Jet" && iMake % 10 == kStEOF) io->Rewind();
101 
102  if (flag == "Jet" && iMake % 10 == kStFatal) break;
103 
104  if (flag == "W" && iMake == kStEOF) break;
105 
106  // new run number?
107  if (chain->GetEvtHddr()->IsNewRun()) {
108  printf("run number = %d\n", chain->GetRunNumber());
109  printf("time stamp = %s\n", chain->GetDateTime().AsSQLString());
110  UpdateBeamline(db, beamline);
111  }
112 
113  double vz = 0;
114 
115  // Set z component based on actual distribution provided by the user
116  if (dataFileName)
117  {
118  tf = new TFile(dataFileName);
119  gDirectory->cd("Event");
120  vz = zVertexOneTofMatch->GetRandom();
121  cout << "Random zVertex Value from Data is: " << vz << endl;
122  } else {
123  vz = gRandom->Gaus(vtxZOffset, vtxSpread.Z());
124  }
125 
126  // Smear beamline parameters extracted from DB
127  double x0 = gRandom->Gaus(beamline.x0, beamline.err_x0);
128  double y0 = gRandom->Gaus(beamline.y0, beamline.err_y0);
129 
130  double dxdz = gRandom->Gaus(beamline.dxdz, beamline.err_dxdz);
131  double dydz = gRandom->Gaus(beamline.dydz, beamline.err_dydz);
132 
133  double vx = gRandom->Gaus(x0 + dxdz * vz, vtxSpread.X() );
134  double vy = gRandom->Gaus(y0 + dydz * vz, vtxSpread.Y() );
135 
136  fprintf(VERTEXFILE, "%14f %14f %14f\n", vx, vy, vz);
137 
138  hVz->Fill(vz);
139  hVxy->Fill(vx, vy);
140  hVzx->Fill(vz, vx);
141  hVzy->Fill(vz, vy);
142  } // end event loop
143 
144  // close vertex file
145  fclose(VERTEXFILE);
146 
147  // write histograms and close ROOT file
148  ofile->Write();
149  ofile->Close();
150 }
151 
152 
156 void GenerateVertex4Jpsi(char *dataFileName = 0, int nevents = 1000, int seed = 0, const char *daqfile = "@run10179086.list",
157  const char *vertexfile = "vertex.txt", const char *flag = "Jet")
158 {
159  const TVector3 vertexSpread(0.055, 0.02, 48.79); // in cm
160  const double vertexZOffset = -2.107; // in cm
161 
162  GenerateVertex(dataFileName, vertexSpread, vertexZOffset, nevents, seed, daqfile, vertexfile, flag);
163 }
164 
165 
169 void GenerateVertex4WBoson(char *dataFileName = 0, int nevents = 1000, int seed = 0, const char *daqfile = "@run10179086.list",
170  const char *vertexfile = "vertex.txt", const char *flag = "Jet")
171 {
172  const TVector3 vertexSpread(0.01, 0.01, 5); // in cm
173  const double vertexZOffset = 0; // in cm
174 
175  GenerateVertex(dataFileName, vertexSpread, vertexZOffset, nevents, seed, daqfile, vertexfile, flag);
176 }
177 
178 
182 void GenerateVertex4VPD(char *dataFileName = 0, int nevents = 1000, int seed = 0, const char *daqfile = "@run10179086.list",
183  const char *vertexfile = "vertex.txt", const char *flag = "Jet")
184 {
185  const TVector3 vertexSpread(0.0372, 0.015, 33.43); // in cm
186  const double vertexZOffset = -1.443; // in cm
187 
188  GenerateVertex(dataFileName, vertexSpread, vertexZOffset, nevents, seed, daqfile, vertexfile, flag);
189 }
virtual void SetIOMode(Option_t *iomode="w")
number of transactions
Definition: StIOInterFace.h:35
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StChain.cxx:77
Definition: Stypes.h:49
Definition: Stypes.h:43
virtual Int_t Make()
Definition: StChain.cxx:110
virtual Int_t GetRunNumber() const
Returns the current RunNumber.
Definition: StMaker.cxx:1054