Back to home page

sPhenix code displayed by LXR

 
 

    


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 //#include <sstream>
0014 
0015 #include <string>
0016 
0017 
0018 // cppcheck-suppress unknownMacro
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   //cout << "fillSpaceChargeMaps::InitRun(PHCompositeNode *topNode) Initializing for Run XXX" << endl;
0027   std::vector<int> bXs;
0028   string line;
0029   string txt_file = "./data/timestamps_50kHz_1M.txt";
0030   ifstream InputFile (txt_file);
0031   //std::map<int,int> timestamps;
0032   if (InputFile.is_open()){
0033     int n_line=0;
0034     while ( getline (InputFile,line) )
0035     {
0036         n_line++;
0037       //cout << line << '\n';
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         //_timestamps[n[0]]=n[1];
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   // Make the Server
0063   //////////////////////////////////////////
0064 
0065 
0066   //char fname[100];
0067   //char foutputname[100];
0068   //for (int i=0;i<nFiles;i++){
0069   //int eventsInFileStart = i*1000;
0070   //int eventsInFileEnd = (i+1)*1000;
0071   //sprintf(fname, "/sphenix/sim/sim01/sphnxpro/Micromegas/2/G4Hits_sHijing_0-12fm_%06d_%06d.root",eventsInFileStart,eventsInFileEnd);
0072   //sprintf(foutputname, "/sphenix/user/shulga/Work/IBF/DistortionMap/Files/slim_G4Hits_sHijing_0-12fm_%06d_%06d.root",eventsInFileStart,eventsInFileEnd);
0073   std::vector<int> bXs = readBeamXings();
0074   std::vector<int> bXs_sel;
0075   //std::vector<int> bXs_sel_end;
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     //int n_bX = closest(bXs, bXs[bXN]);
0084     //bXs_sel_end.push_back(n_bX); 
0085     //int id_bX = std::distance(bXs.begin(), it);
0086     //std::vector<int>::iterator it_bX = std::find(bXs.begin(), bXs.end(), n_bX);
0087     cout<<"bX="<<bXs[bXN]<<endl;
0088     //cout<<"bX="<<bXs[bXN]<<"last event:"<<n_bX<<" evt:"<<std::distance(bXs.begin(), it_bX)<<endl;
0089   }
0090   Fun4AllServer *se = Fun4AllServer::instance();
0091   string cd_name = "fillSpaceChargeMaps"+std::to_string(eventsInFileStart);
0092   //cout<<fname_tmp<<endl;
0093   fillSpaceChargeMaps *dist_calc = new fillSpaceChargeMaps(cd_name, foutputname);
0094   dist_calc->SetFrequency(50);
0095   dist_calc->SetEvtStart(eventsInFileStart);
0096   //dist_calc->SetBeamXing(eventsBeamCrossing); // Set beam crosssing bias
0097   dist_calc->SetBeamXing(bXs_sel);// Set beam crosssing bias
0098   //dist_calc->SetBeamXingEnd(bXs_sel_end);// Set last beam crosssing for the biases
0099   //dist_calc->SetAvg(1); //Set average calculation
0100   dist_calc->SetUseIBFMap(false);//false);
0101   //dist_calc->SetGain(2e3*48.7/71.5);
0102   dist_calc->SetGain(1400);
0103   dist_calc->SetIBF(0.004);
0104   dist_calc->UseSliming(0);//Turn off TTree filling and recording
0105 
0106   dist_calc->UseFieldMaps(1);//1); //setting field maps to shift electron position
0107   //Set pp colliding system
0108   dist_calc->SetCollSyst(0); //setting pp with = 1
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   // this (DST) input manager just drives the event loop
0118   Fun4AllInputManager *in = new Fun4AllDstInputManager("DSTin");
0119   in->fileopen(inputFileName);
0120   se->registerInputManager(in);
0121   // events = 0 => run till end of input file
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