File indexing completed on 2025-12-19 09:18:44
0001 #ifndef MACRO_FUN4ALL_FILLDCMAP_C
0002 #define MACRO_FUN4ALL_FILLDCMAP_C
0003
0004 #include "../readDigitalCurrents.h"
0005
0006 #include <frog/FROG.h>
0007
0008 #include <fun4all/Fun4AllServer.h>
0009 #include <fun4all/Fun4AllInputManager.h>
0010 #include <fun4all/Fun4AllDstInputManager.h>
0011
0012 #include <Rtypes.h>
0013 #include <TSystem.h>
0014
0015 #include <iostream>
0016 #include <string>
0017
0018 R__LOAD_LIBRARY(libfun4all.so)
0019 R__LOAD_LIBRARY(libreadDigitalCurrents.so)
0020 R__LOAD_LIBRARY(libg4dst.so)
0021
0022 std::vector<int> readBeamXings();
0023
0024 std::vector<int> readBeamXings(){
0025
0026 std::vector<int> bXs;
0027 std::string line;
0028 std::string txt_file = "./data/timestamps_50kHz_1M.txt";
0029 std::ifstream InputFile (txt_file);
0030
0031 if (InputFile.is_open()){
0032 int n_line=0;
0033 while ( getline (InputFile,line) )
0034 {
0035 n_line++;
0036
0037 if(n_line>3){
0038 std::istringstream is( line );
0039 double n[2] = {0,0};
0040 int i = 0;
0041 while( is >> n[i] ) {
0042 i++;
0043 }
0044
0045 bXs.push_back(int(n[0]));
0046 }
0047 }
0048 InputFile.close();
0049 }
0050 return bXs;
0051 }
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
0060 void Fun4All_FillDCMap( const int nEvents = 1000, const int eventsInFileStart = 0, const int eventsBeamCrossing = 1508071, const std::string &fname = "/sphenix/user/shulga/Work/IBF/macros/detectors/sPHENIX/Files/DST_G4Hits_sHijing_0-12fm_005000_006000.root", const std::string &foutputname = "./Files/hists_G4Hits_sHijing_0-12fm_000000_001000.root" )
0061 {
0062
0063
0064
0065
0066
0067 std::vector<int> bXs = readBeamXings();
0068 std::vector<int> bXs_sel;
0069
0070 std::vector<int>::iterator it = std::find(bXs.begin(), bXs.end(), eventsBeamCrossing);
0071 int index=0;
0072 index = std::distance(bXs.begin(), it);
0073 std::cout<<"Index="<<index<<std::endl;
0074 for(int n=0;n<30;n++){
0075 int bXN=index+n*300;
0076 bXs_sel.push_back(bXs[bXN]);
0077 std::cout<<"bX="<<bXs[bXN]<<std::endl;
0078 }
0079
0080 Fun4AllServer *se = Fun4AllServer::instance();
0081 std::string cd_name = "readDigitalCurrents"+std::to_string(eventsInFileStart);
0082
0083 readDigitalCurrents *dist_calc = new readDigitalCurrents(cd_name, foutputname);
0084
0085 se->registerSubsystem(dist_calc);
0086 dist_calc->SetEvtStart(eventsInFileStart);
0087 dist_calc->SetBeamXing(bXs_sel);
0088
0089 dist_calc->SetCollSyst(0);
0090 dist_calc->SetIBF(0.004);
0091 dist_calc->SetCCGC(1);
0092
0093 gSystem->Load("libFROG");
0094 FROG *fr = new FROG();
0095 std::string inputFileName = fr->location(fname);
0096 std::cout << "Next file:" << inputFileName << std::endl;
0097
0098 Fun4AllInputManager *in = new Fun4AllDstInputManager("DSTin");
0099 in->fileopen(inputFileName);
0100 se->registerInputManager(in);
0101
0102 if (nEvents <= 0)
0103 {
0104 return;
0105 }
0106 std::cout << std::endl << "Running over " << nEvents << " Events" << std::endl;
0107 se->run(nEvents);
0108
0109 std::cout << std::endl << "Calling End in Fun4All_readDigitalCurrents.C" << std::endl;
0110 se->End();
0111
0112 std::cout << std::endl << "All done, calling delete Fun4AllServer" << std::endl;
0113 delete se;
0114
0115 std::cout << std::endl << "gSystem->Exit(0)" << std::endl;
0116 gSystem->Exit(0);
0117 }
0118
0119 #endif