File indexing completed on 2025-08-06 08:16:41
0001 #ifndef FUN4ALL_FILLCHARGESMAP_300EVTS_MDC2_C
0002 #define FUN4ALL_FILLCHARGESMAP_300EVTS_MDC2_C
0003
0004 #include <fun4all/Fun4AllServer.h>
0005 #include <fun4all/Fun4AllInputManager.h>
0006 #include <fun4all/Fun4AllDstInputManager.h>
0007
0008 #include <frog/FROG.h>
0009
0010 #include <fillSpaceChargeMaps.h>
0011
0012 #include <stdio.h>
0013
0014
0015 #include <string>
0016
0017
0018
0019 R__LOAD_LIBRARY(libfun4all.so)
0020 R__LOAD_LIBRARY(libfillSpaceChargeMaps.so)
0021 R__LOAD_LIBRARY(libg4dst.so)
0022
0023 std::vector<int> readBeamXings();
0024
0025 std::vector<int> readBeamXings(){
0026
0027 std::vector<int> bXs;
0028 string line;
0029 string txt_file = "./data/timestamps_50kHz_1M.txt";
0030 ifstream InputFile (txt_file);
0031
0032 if (InputFile.is_open()){
0033 int n_line=0;
0034 while ( getline (InputFile,line) )
0035 {
0036 n_line++;
0037
0038 if(n_line>3){
0039 std::istringstream is( line );
0040 double n[2] = {0,0};
0041 int i = 0;
0042 while( is >> n[i] ) {
0043 i++;
0044 }
0045
0046 bXs.push_back(int(n[0]));
0047 }
0048 }
0049 InputFile.close();
0050 }
0051 return bXs;
0052 }
0053 int closest(std::vector<int> const& vec, int value) {
0054 auto const it = std::lower_bound(vec.begin(), vec.end(), value);
0055 if (it == vec.end()) { return -1; }
0056
0057 return *it;
0058 }
0059 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" )
0060 {
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073 std::vector<int> bXs = readBeamXings();
0074 std::vector<int> bXs_sel;
0075
0076 std::vector<int>::iterator it = std::find(bXs.begin(), bXs.end(), eventsBeamCrossing);
0077 int index=0;
0078 index = std::distance(bXs.begin(), it);
0079 cout<<"Index="<<index<<endl;
0080 for(int n=0;n<30;n++){
0081 int bXN=index+n*300;
0082 bXs_sel.push_back(bXs[bXN]);
0083
0084
0085
0086
0087 cout<<"bX="<<bXs[bXN]<<endl;
0088
0089 }
0090 Fun4AllServer *se = Fun4AllServer::instance();
0091 string cd_name = "fillSpaceChargeMaps"+std::to_string(eventsInFileStart);
0092
0093 fillSpaceChargeMaps *dist_calc = new fillSpaceChargeMaps(cd_name, foutputname);
0094 dist_calc->SetFrequency(50);
0095 dist_calc->SetEvtStart(eventsInFileStart);
0096
0097 dist_calc->SetBeamXing(bXs_sel);
0098
0099
0100 dist_calc->SetUseIBFMap(false);
0101
0102 dist_calc->SetGain(1400);
0103 dist_calc->SetIBF(0.004);
0104 dist_calc->UseSliming(0);
0105
0106 dist_calc->UseFieldMaps(1);
0107
0108 dist_calc->SetCollSyst(0);
0109
0110 se->registerSubsystem(dist_calc);
0111
0112
0113 gSystem->Load("libFROG");
0114 FROG *fr = new FROG();
0115 string inputFileName = fr->location(fname);
0116 cout << "Next file:" << inputFileName << endl;
0117
0118 Fun4AllInputManager *in = new Fun4AllDstInputManager("DSTin");
0119 in->fileopen(inputFileName);
0120 se->registerInputManager(in);
0121
0122 if (nEvents <= 0)
0123 {
0124 return;
0125 }
0126 cout << endl << "Running over " << nEvents << " Events" << endl;
0127 se->run(nEvents);
0128
0129 cout << endl << "Calling End in Fun4All_fillSpaceChargeMaps.C" << endl;
0130 se->End();
0131
0132 cout << endl << "All done, calling delete Fun4AllServer" << endl;
0133 delete se;
0134
0135 cout << endl << "gSystem->Exit(0)" << endl;
0136 gSystem->Exit(0);
0137 }
0138
0139 #endif