Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:16:41

0001 #pragma once
0002 #include <fun4all/Fun4AllServer.h>
0003 #include <fun4all/Fun4AllInputManager.h>
0004 #include <fun4all/Fun4AllDstInputManager.h>
0005 
0006 #include <readDigitalCurrents.h>
0007 
0008 #include <stdio.h>
0009 #include <frog/FROG.h>
0010 
0011 #include <string>
0012 
0013 // cppcheck-suppress unknownMacro
0014 R__LOAD_LIBRARY(libfun4all.so)
0015 R__LOAD_LIBRARY(libreadDigitalCurrents.so)
0016 R__LOAD_LIBRARY(libg4dst.so)
0017 
0018 std::vector<int> readBeamXings();
0019 
0020 std::vector<int> readBeamXings(){
0021   //cout << "fillSpaceChargeMaps::InitRun(PHCompositeNode *topNode) Initializing for Run XXX" << endl;
0022   std::vector<int> bXs;
0023   string line;
0024   string txt_file = "./data/timestamps_50kHz_1M.txt";
0025   ifstream InputFile (txt_file);
0026   //std::map<int,int> timestamps;
0027   if (InputFile.is_open()){
0028     int n_line=0;
0029     while ( getline (InputFile,line) )
0030     {
0031         n_line++;
0032       //cout << line << '\n';
0033       if(n_line>3){
0034         std::istringstream is( line );
0035         double n[2] = {0,0};
0036         int i = 0;
0037         while( is >> n[i] ) {    
0038             i++;    
0039         }
0040         //_timestamps[n[0]]=n[1];
0041         bXs.push_back(int(n[0]));
0042       }
0043     }
0044     InputFile.close();
0045   }
0046  return bXs;
0047 }
0048 
0049 int closest(std::vector<int> const& vec, int value) {
0050     auto const it = std::lower_bound(vec.begin(), vec.end(), value);
0051     if (it == vec.end()) { return -1; }
0052 
0053     return *it;
0054 }
0055 
0056 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" )
0057 {
0058   // /sphenix/user/frawley/new_macros_april27/macros/detectors/sPHENIX/Reconstructed_DST_Hijing_50kHz_00000.root
0059   
0060   ///////////////////////////////////////////
0061   // Make the Server
0062   //////////////////////////////////////////
0063   std::vector<int> bXs = readBeamXings();
0064   std::vector<int> bXs_sel;
0065 
0066   std::vector<int>::iterator it = std::find(bXs.begin(), bXs.end(), eventsBeamCrossing);
0067   int index=0; 
0068   index = std::distance(bXs.begin(), it);
0069   cout<<"Index="<<index<<endl;
0070   for(int n=0;n<30;n++){
0071     int bXN=index+n*300;
0072     bXs_sel.push_back(bXs[bXN]);
0073     cout<<"bX="<<bXs[bXN]<<endl;
0074   }
0075 
0076   Fun4AllServer *se = Fun4AllServer::instance();
0077   string cd_name = "readDigitalCurrents"+std::to_string(eventsInFileStart);
0078   //cout<<fname_tmp<<endl;
0079   readDigitalCurrents *dist_calc = new readDigitalCurrents(cd_name, foutputname);
0080   //readDigitalCurrents *dist_calc = new readDigitalCurrents();
0081   se->registerSubsystem(dist_calc);
0082   dist_calc->SetEvtStart(eventsInFileStart);
0083   dist_calc->SetBeamXing(bXs_sel);// Set beam crosssing bias
0084   //dist_calc->SetBeamXing(eventsBeamCrossing); // Set beam crosssing bias
0085   dist_calc->SetCollSyst(0); //setting pp with = 1
0086   dist_calc->SetIBF(0.004);
0087   dist_calc->SetCCGC(1);//to use PHG4CylinderCellGeom
0088 
0089   gSystem->Load("libFROG");
0090   FROG *fr = new FROG();
0091   string inputFileName = fr->location(fname);
0092   cout << "Next file:" << inputFileName << endl;
0093   // this (DST) input manager just drives the event loop
0094   Fun4AllInputManager *in = new Fun4AllDstInputManager("DSTin");
0095   in->fileopen(inputFileName);//fname);
0096   se->registerInputManager(in);
0097   // events = 0 => run till end of input file
0098   if (nEvents <= 0)
0099   {
0100     return;
0101   }
0102   cout << endl << "Running over " << nEvents << " Events" << endl;
0103   se->run(nEvents);
0104   //}
0105   cout << endl << "Calling End in Fun4All_readDigitalCurrents.C" << endl;
0106   se->End();
0107 
0108   cout << endl << "All done, calling delete Fun4AllServer" << endl;
0109   delete se;
0110 
0111   cout << endl << "gSystem->Exit(0)" << endl;
0112   gSystem->Exit(0);
0113 }