Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-04-04 08:10:23

0001 bool get_is15_mrad(int runnumber)
0002 {
0003 
0004 
0005   TSQLServer *db = TSQLServer::Connect("pgsql://sphnxdbreplica:5432/spinDB","phnxrc","");
0006   if(!db)
0007     {
0008       cout << "FAILED TO CONNECT TO DB!" << endl;
0009       throw exception();
0010     }
0011   TSQLRow *row;
0012   TSQLResult *res;
0013   char sql[1000];
0014 
0015 
0016 
0017   sprintf(sql, "select crossingangle, runnumber from spin where runnumber = %d;", runnumber);
0018   res = db->Query(sql);
0019   if(!res) return -1;
0020   row = res->Next();
0021   if(!row) return -1;
0022 
0023 
0024 
0025   string xing(row->GetField(0));
0026   float xingangle = stof(xing);
0027   if(db) delete db;
0028   return fabs(xingangle)>0.75;
0029 }
0030 
0031 int get_luminosity_182630(string rnlist, int zsel, int clt, int checkxing = 0)
0032 {
0033   gStyle->SetOptStat(0);
0034 
0035   if(zsel > 5 || zsel < 0)
0036     {
0037       cout << "z selection must be between 0 and 5 (inclusive) for |zvtx| < 30/60/200/10/1000/none, respectively! Exiting." << endl;
0038       return 2;
0039     }
0040   const int ntrig = 4;
0041   float mbsig = 25.2;
0042   int upperrun = 54000;
0043   int lowerrun = 47200;
0044   ifstream is(rnlist);
0045   string rnstr;
0046   TH1D* mbdrate = new TH1D("mbdrate","",upperrun-lowerrun,lowerrun-.5,upperrun-.5);
0047   TH1D* nSB10 = new TH1D("nSB10","",upperrun-lowerrun,lowerrun-0.5,upperrun-0.5);
0048   TH1D* nSB18 = new TH1D("nSB18","",upperrun-lowerrun,lowerrun-0.5,upperrun-0.5);
0049   TH1D* fsb10l30 = new TH1D("fsb10l30","",upperrun-lowerrun,lowerrun-0.5,upperrun-0.5);
0050   TH1D* fsb18l30 = new TH1D("fsb18l30","",upperrun-lowerrun,lowerrun-0.5,upperrun-0.5);
0051   //int it = 0;
0052   float lumi[ntrig] = {0};
0053   float uclumi[ntrig] = {0};
0054   int trigs[ntrig] = {10,18,22,30};
0055   cout << "RN   Bit"<<to_string(trigs[0])<<"Corr  Bit"<<to_string(trigs[0])<<"UC   Bit"<<to_string(trigs[1])<<"Corr  Bit"<<to_string(trigs[1])<<"UC   Bit"<<to_string(trigs[2])<<"Corr  Bit"<<to_string(trigs[2])<<"UC   Bit"<<to_string(trigs[3])<<"Corr  Bit"<<to_string(trigs[3])<<"UC (units pb^-1)" << endl << endl;
0056   while(getline(is, rnstr))
0057     {
0058       TFile* file;
0059       file = TFile::Open(("output/added_509/triggeroutput_nblair_"+rnstr+(clt?"_clt":"")+".root").c_str(),"READ");
0060       if(checkxing==2 && !get_is15_mrad(stoi(rnstr))) continue;
0061       if(checkxing==1 && get_is15_mrad(stoi(rnstr))) continue;
0062     
0063       if(!file)
0064     {
0065       cerr << "RN " << rnstr << " not found! Continuing." << endl;
0066       cout << rnstr << " " << 0 << " " << 0 << " " << 0 << " " << 0 << " " << 0 << " " << 0 << endl;
0067       continue;
0068     }
0069       long long unsigned int tottrigcounts[6][64];
0070       double avgPS[64];
0071       long long unsigned int sumgoodscaled[64];
0072       long long unsigned int sumgoodraw[64];
0073       long long unsigned int sumgoodlive[64];
0074       float nmbdc;
0075       float nocorN;
0076       float ttseg;
0077       float nblair;
0078       TTree* tree = (TTree*)file->Get("outt");
0079 
0080       if(!tree)
0081     {
0082       cerr << "RN " << rnstr << " does not contain tree outt! Continuing." << endl;
0083       cout << rnstr << " " << 0 << " " << 0 << " " << 0 << " " << 0 << " " << 0 << " " << 0 << " " << 0 << " " << 0 << " " << 0 << endl;
0084       continue;
0085     }
0086       tree->SetBranchAddress("avgPS",avgPS);
0087       tree->SetBranchAddress("sumgoodscaled",sumgoodscaled);
0088       tree->SetBranchAddress("sumgoodlive",sumgoodlive);
0089       tree->SetBranchAddress("sumgoodraw",sumgoodraw);
0090       tree->SetBranchAddress("tottrigcounts",tottrigcounts);
0091       tree->SetBranchAddress("nmbdc",&nmbdc);
0092       tree->SetBranchAddress("nocorN",&nocorN);
0093       tree->SetBranchAddress("ttseg",&ttseg);
0094       tree->SetBranchAddress("nblair",&nblair);
0095       tree->GetEntry(0);
0096 
0097 
0098       if(nmbdc/((double)nocorN) < 1)
0099     {
0100       cerr << rnstr << " " << nmbdc << " " << nocorN << " " << nmbdc / (double)nocorN << endl;
0101       continue;
0102     }
0103       cout << rnstr;
0104 
0105       
0106       
0107       for(int i=0; i<ntrig; ++i)
0108     {
0109       int trigger = trigs[i];
0110       if(avgPS[trigger] > 0 && !isnan(avgPS[trigger]) && !isnan(avgPS[10]) && !isnan((tottrigcounts[zsel][10])) && !isinf(avgPS[10]) && !isinf(avgPS[trigger]) && !isinf((tottrigcounts[zsel][10])) && avgPS[10] > 0)
0111         {
0112           
0113           float clumiseg = (tottrigcounts[zsel][10])*avgPS[10]*((((nmbdc/((double)nocorN)))))/avgPS[trigger]/(mbsig*1e9);
0114           float uclumiseg = (tottrigcounts[zsel][10])*((double)avgPS[10])/avgPS[trigger]/(mbsig*1e9);//((double)(trigger==22?sumgoodscaled[10]:tottrigcounts[zsel][10]))*avgPS[10]/avgPS[trigger]/(mbdsig*1e9;
0115           float blumiseg = (tottrigcounts[zsel][10])*avgPS[10]*((((nblair/((double)nocorN))-1)/2)+1)/avgPS[trigger]/(mbsig*1e9);
0116           uclumi[i] += uclumiseg;
0117           lumi[i] += clumiseg;
0118           cout << " " << fixed << setprecision(7) << clumiseg << " " << uclumiseg;// << " " << blumiseg ;
0119         }
0120       else
0121         {
0122           cout << " " << 0 << " " << 0;// << " " << 0 ;
0123         }
0124     }
0125       cout << endl;
0126       file->Close();
0127     }
0128   cout << "RN   Bit"<<to_string(trigs[0])<<"Corr  Bit"<<to_string(trigs[0])<<"UC   Bit"<<to_string(trigs[1])<<"Corr  Bit"<<to_string(trigs[1])<<"UC   Bit"<<to_string(trigs[2])<<"Corr  Bit"<<to_string(trigs[2])<<"UC (units pb^-1)" << endl << endl;
0129   cout << "Totals: " << fixed << setprecision(5)<<  lumi[0] << " " << uclumi[0] << " " << lumi[1] << " " << uclumi[1] << " " << lumi[2] << " " << uclumi[2] << " " << " pb^-1" << endl;
0130   return 0;
0131 }