Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Fun4All_FillChargesMap_300evts_MDC2.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Fun4All_FillChargesMap_300evts_MDC2.C
1 #ifndef FUN4ALL_FILLCHARGESMAP_300EVTS_MDC2_C
2 #define FUN4ALL_FILLCHARGESMAP_300EVTS_MDC2_C
3 
7 
8 #include <frog/FROG.h>
9 
10 #include <fillSpaceChargeMaps.h>
11 
12 #include <stdio.h>
13 //#include <sstream>
14 
15 #include <string>
16 
17 
18 // cppcheck-suppress unknownMacro
19 R__LOAD_LIBRARY(libfun4all.so)
20 R__LOAD_LIBRARY(libfillSpaceChargeMaps.so)
21 R__LOAD_LIBRARY(libg4dst.so)
22 
23 std::vector<int> readBeamXings();
24 
25 std::vector<int> readBeamXings(){
26  //cout << "fillSpaceChargeMaps::InitRun(PHCompositeNode *topNode) Initializing for Run XXX" << endl;
27  std::vector<int> bXs;
28  string line;
29  string txt_file = "./data/timestamps_50kHz_1M.txt";
30  ifstream InputFile (txt_file);
31  //std::map<int,int> timestamps;
32  if (InputFile.is_open()){
33  int n_line=0;
34  while ( getline (InputFile,line) )
35  {
36  n_line++;
37  //cout << line << '\n';
38  if(n_line>3){
39  std::istringstream is( line );
40  double n[2] = {0,0};
41  int i = 0;
42  while( is >> n[i] ) {
43  i++;
44  }
45  //_timestamps[n[0]]=n[1];
46  bXs.push_back(int(n[0]));
47  }
48  }
49  InputFile.close();
50  }
51  return bXs;
52 }
53 int closest(std::vector<int> const& vec, int value) {
54  auto const it = std::lower_bound(vec.begin(), vec.end(), value);
55  if (it == vec.end()) { return -1; }
56 
57  return *it;
58 }
59 void Fun4All_FillChargesMap_300evts_MDC2( const int nEvents = 10, const int eventsInFileStart = 0, const int eventsBeamCrossing = 1508071, const string &fname = "/sphenix/sim/sim01/sphnxpro/Micromegas/2/G4Hits_sHijing_0-12fm_000000_001000.root", const string &foutputname = "/sphenix/user/shulga/Work/IBF/DistortionMap/Files/slim_G4Hits_sHijing_0-12fm_000000_001000.root" )
60 {
62  // Make the Server
64 
65 
66  //char fname[100];
67  //char foutputname[100];
68  //for (int i=0;i<nFiles;i++){
69  //int eventsInFileStart = i*1000;
70  //int eventsInFileEnd = (i+1)*1000;
71  //sprintf(fname, "/sphenix/sim/sim01/sphnxpro/Micromegas/2/G4Hits_sHijing_0-12fm_%06d_%06d.root",eventsInFileStart,eventsInFileEnd);
72  //sprintf(foutputname, "/sphenix/user/shulga/Work/IBF/DistortionMap/Files/slim_G4Hits_sHijing_0-12fm_%06d_%06d.root",eventsInFileStart,eventsInFileEnd);
73  std::vector<int> bXs = readBeamXings();
74  std::vector<int> bXs_sel;
75  //std::vector<int> bXs_sel_end;
76  std::vector<int>::iterator it = std::find(bXs.begin(), bXs.end(), eventsBeamCrossing);
77  int index=0;
78  index = std::distance(bXs.begin(), it);
79  cout<<"Index="<<index<<endl;
80  for(int n=0;n<30;n++){
81  int bXN=index+n*300;
82  bXs_sel.push_back(bXs[bXN]);
83  //int n_bX = closest(bXs, bXs[bXN]);
84  //bXs_sel_end.push_back(n_bX);
85  //int id_bX = std::distance(bXs.begin(), it);
86  //std::vector<int>::iterator it_bX = std::find(bXs.begin(), bXs.end(), n_bX);
87  cout<<"bX="<<bXs[bXN]<<endl;
88  //cout<<"bX="<<bXs[bXN]<<"last event:"<<n_bX<<" evt:"<<std::distance(bXs.begin(), it_bX)<<endl;
89  }
91  string cd_name = "fillSpaceChargeMaps"+std::to_string(eventsInFileStart);
92  //cout<<fname_tmp<<endl;
93  fillSpaceChargeMaps *dist_calc = new fillSpaceChargeMaps(cd_name, foutputname);
94  dist_calc->SetFrequency(50);
95  dist_calc->SetEvtStart(eventsInFileStart);
96  //dist_calc->SetBeamXing(eventsBeamCrossing); // Set beam crosssing bias
97  dist_calc->SetBeamXing(bXs_sel);// Set beam crosssing bias
98  //dist_calc->SetBeamXingEnd(bXs_sel_end);// Set last beam crosssing for the biases
99  //dist_calc->SetAvg(1); //Set average calculation
100  dist_calc->SetUseIBFMap(false);//false);
101  //dist_calc->SetGain(2e3*48.7/71.5);
102  dist_calc->SetGain(1400);
103  dist_calc->SetIBF(0.004);
104  dist_calc->UseSliming(0);//Turn off TTree filling and recording
105 
106  dist_calc->UseFieldMaps(1);//1); //setting field maps to shift electron position
107  //Set pp colliding system
108  dist_calc->SetCollSyst(0); //setting pp with = 1
109 
110  se->registerSubsystem(dist_calc);
111 
112 
113  gSystem->Load("libFROG");
114  FROG *fr = new FROG();
115  string inputFileName = fr->location(fname);
116  cout << "Next file:" << inputFileName << endl;
117  // this (DST) input manager just drives the event loop
119  in->fileopen(inputFileName);
120  se->registerInputManager(in);
121  // events = 0 => run till end of input file
122  if (nEvents <= 0)
123  {
124  return;
125  }
126  cout << endl << "Running over " << nEvents << " Events" << endl;
127  se->run(nEvents);
128 
129  cout << endl << "Calling End in Fun4All_fillSpaceChargeMaps.C" << endl;
130  se->End();
131 
132  cout << endl << "All done, calling delete Fun4AllServer" << endl;
133  delete se;
134 
135  cout << endl << "gSystem->Exit(0)" << endl;
136  gSystem->Exit(0);
137 }
138 
139 #endif