Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Fun4All_FillDCMap.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Fun4All_FillDCMap.C
1 #pragma once
5 
6 #include <readDigitalCurrents.h>
7 
8 #include <stdio.h>
9 #include <frog/FROG.h>
10 
11 #include <string>
12 
13 // cppcheck-suppress unknownMacro
14 R__LOAD_LIBRARY(libfun4all.so)
15 R__LOAD_LIBRARY(libreadDigitalCurrents.so)
16 R__LOAD_LIBRARY(libg4dst.so)
17 
18 std::vector<int> readBeamXings();
19 
20 std::vector<int> readBeamXings(){
21  //cout << "fillSpaceChargeMaps::InitRun(PHCompositeNode *topNode) Initializing for Run XXX" << endl;
22  std::vector<int> bXs;
23  string line;
24  string txt_file = "./data/timestamps_50kHz_1M.txt";
25  ifstream InputFile (txt_file);
26  //std::map<int,int> timestamps;
27  if (InputFile.is_open()){
28  int n_line=0;
29  while ( getline (InputFile,line) )
30  {
31  n_line++;
32  //cout << line << '\n';
33  if(n_line>3){
34  std::istringstream is( line );
35  double n[2] = {0,0};
36  int i = 0;
37  while( is >> n[i] ) {
38  i++;
39  }
40  //_timestamps[n[0]]=n[1];
41  bXs.push_back(int(n[0]));
42  }
43  }
44  InputFile.close();
45  }
46  return bXs;
47 }
48 
49 int closest(std::vector<int> const& vec, int value) {
50  auto const it = std::lower_bound(vec.begin(), vec.end(), value);
51  if (it == vec.end()) { return -1; }
52 
53  return *it;
54 }
55 
56 void Fun4All_FillDCMap( const int nEvents = 1000, const int eventsInFileStart = 0, const int eventsBeamCrossing = 1508071, const string &fname = "/sphenix/user/shulga/Work/IBF/macros/detectors/sPHENIX/Files/DST_G4Hits_sHijing_0-12fm_005000_006000.root", const string &foutputname = "./Files/hists_G4Hits_sHijing_0-12fm_000000_001000.root" )//DST_G4sPHENIX_1000evt.root")//G4sPHENIX.root" )
57 {
58  // /sphenix/user/frawley/new_macros_april27/macros/detectors/sPHENIX/Reconstructed_DST_Hijing_50kHz_00000.root
59 
61  // Make the Server
63  std::vector<int> bXs = readBeamXings();
64  std::vector<int> bXs_sel;
65 
66  std::vector<int>::iterator it = std::find(bXs.begin(), bXs.end(), eventsBeamCrossing);
67  int index=0;
68  index = std::distance(bXs.begin(), it);
69  cout<<"Index="<<index<<endl;
70  for(int n=0;n<30;n++){
71  int bXN=index+n*300;
72  bXs_sel.push_back(bXs[bXN]);
73  cout<<"bX="<<bXs[bXN]<<endl;
74  }
75 
77  string cd_name = "readDigitalCurrents"+std::to_string(eventsInFileStart);
78  //cout<<fname_tmp<<endl;
79  readDigitalCurrents *dist_calc = new readDigitalCurrents(cd_name, foutputname);
80  //readDigitalCurrents *dist_calc = new readDigitalCurrents();
81  se->registerSubsystem(dist_calc);
82  dist_calc->SetEvtStart(eventsInFileStart);
83  dist_calc->SetBeamXing(bXs_sel);// Set beam crosssing bias
84  //dist_calc->SetBeamXing(eventsBeamCrossing); // Set beam crosssing bias
85  dist_calc->SetCollSyst(0); //setting pp with = 1
86  dist_calc->SetIBF(0.004);
87  dist_calc->SetCCGC(1);//to use PHG4CylinderCellGeom
88 
89  gSystem->Load("libFROG");
90  FROG *fr = new FROG();
91  string inputFileName = fr->location(fname);
92  cout << "Next file:" << inputFileName << endl;
93  // this (DST) input manager just drives the event loop
95  in->fileopen(inputFileName);//fname);
96  se->registerInputManager(in);
97  // events = 0 => run till end of input file
98  if (nEvents <= 0)
99  {
100  return;
101  }
102  cout << endl << "Running over " << nEvents << " Events" << endl;
103  se->run(nEvents);
104  //}
105  cout << endl << "Calling End in Fun4All_readDigitalCurrents.C" << endl;
106  se->End();
107 
108  cout << endl << "All done, calling delete Fun4AllServer" << endl;
109  delete se;
110 
111  cout << endl << "gSystem->Exit(0)" << endl;
112  gSystem->Exit(0);
113 }