Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-04-05 08:12:09

0001 
0002 #include <uspin/SpinDBInput.h>
0003 #include <uspin/SpinDBOutput.h>
0004 #include <uspin/SpinDBContentv1.h>
0005 #include <TFile.h>
0006 #include "sPhenixStyle.C"
0007 R__LOAD_LIBRARY(libuspin.so)
0008 
0009 float ZDC1CUT = 100;  // keep above (nominal 65)
0010 float ZDC2CUT = 15;   // keep above (nominal 25)
0011 float VETOCUT = 150;  // keep below (nominal 150)
0012 bool ismerged = true;
0013 bool isflipON = true;
0014 void drawBunchBunch(const std::string infile = "47972/0/zdcneutronlocpol_47972_all.root", int storenumber = 34782, int runnumber = 47972)
0015 {
0016   SetsPhenixStyle();
0017   TFile *f = new TFile(infile.c_str());
0018   //========================== Hists/Graphs ==============================//
0019 
0020   TH1D *n_smd_L = new TH1D("n_smd_L", "n_smd_L", 128, 0, 128);
0021   TH1D *n_smd_R = new TH1D("n_smd_R", "n_smd_R", 128, 0, 128);
0022   TH1D *s_smd_L = new TH1D("s_smd_L", "s_smd_L", 128, 0, 128);
0023   TH1D *s_smd_R = new TH1D("s_smd_R", "s_smd_R", 128, 0, 128);
0024 
0025   TH1D *n_smd_U = new TH1D("n_smd_U", "n_smd_U", 128, 0, 128);
0026   TH1D *n_smd_D = new TH1D("n_smd_D", "n_smd_D", 128, 0, 128);
0027   TH1D *s_smd_U = new TH1D("s_smd_U", "s_smd_U", 128, 0, 128);
0028   TH1D *s_smd_D = new TH1D("s_smd_D", "s_smd_D", 128, 0, 128);
0029 
0030   //======================================================================//
0031 
0032   //========================== SMD Hit Tree ==============================//
0033   TTree *smdHits = (TTree *) f->Get("smdHits");
0034   int bunchnumber, showerCutN, showerCutS;
0035   float n_x, n_y, s_x, s_y;
0036   float zdcN1_adc, zdcN2_adc, veto_NF, veto_NB;
0037   float zdcS1_adc, zdcS2_adc, veto_SF, veto_SB;
0038   float smdS1_adc, smdS2_adc, smdS6_adc, smdS7_adc;
0039   float smdN1_adc, smdN2_adc, smdN6_adc, smdN7_adc;
0040   float smdS1_v_adc, smdS2_v_adc, smdS7_v_adc, smdS8_v_adc;
0041   float smdN1_v_adc, smdN2_v_adc, smdN7_v_adc, smdN8_v_adc;
0042   smdHits->SetBranchAddress("bunchnumber", &bunchnumber);
0043   smdHits->SetBranchAddress("showerCutN", &showerCutN);
0044   smdHits->SetBranchAddress("showerCutS", &showerCutS);
0045   smdHits->SetBranchAddress("n_x", &n_x);
0046   smdHits->SetBranchAddress("n_y", &n_y);
0047   smdHits->SetBranchAddress("s_x", &s_x);
0048   smdHits->SetBranchAddress("s_y", &s_y);
0049   smdHits->SetBranchAddress("zdcN1_adc", &zdcN1_adc);
0050   smdHits->SetBranchAddress("zdcN2_adc", &zdcN2_adc);
0051   smdHits->SetBranchAddress("zdcS1_adc", &zdcS1_adc);
0052   smdHits->SetBranchAddress("zdcS2_adc", &zdcS2_adc);
0053   smdHits->SetBranchAddress("veto_NF", &veto_NF);
0054   smdHits->SetBranchAddress("veto_NB", &veto_NB);
0055   smdHits->SetBranchAddress("veto_SF", &veto_SF);
0056   smdHits->SetBranchAddress("veto_SB", &veto_SB);
0057   // smdHits->SetBranchStatus("n_x",0);
0058   // smdHits->SetBranchStatus("s_y",0);
0059   
0060   smdHits -> SetBranchAddress ("smdN1_adc",       &smdN1_adc);
0061   smdHits -> SetBranchAddress ("smdN2_adc",       &smdN2_adc);
0062   smdHits -> SetBranchAddress ("smdN6_adc",       &smdN6_adc);
0063   smdHits -> SetBranchAddress ("smdN7_adc",       &smdN7_adc);
0064   smdHits -> SetBranchAddress ("smdS1_adc",       &smdS1_adc);
0065   smdHits -> SetBranchAddress ("smdS2_adc",       &smdS2_adc);
0066   smdHits -> SetBranchAddress ("smdS6_adc",       &smdS6_adc);
0067   smdHits -> SetBranchAddress ("smdS7_adc",       &smdS7_adc);
0068   smdHits -> SetBranchAddress ("smdN1_v_adc",       &smdN1_v_adc);
0069   smdHits -> SetBranchAddress ("smdN2_v_adc",       &smdN2_v_adc);
0070   smdHits -> SetBranchAddress ("smdN7_v_adc",       &smdN7_v_adc);
0071   smdHits -> SetBranchAddress ("smdN8_v_adc",       &smdN8_v_adc);
0072   smdHits -> SetBranchAddress ("smdS1_v_adc",       &smdS1_v_adc);
0073   smdHits -> SetBranchAddress ("smdS2_v_adc",       &smdS2_v_adc);
0074   smdHits -> SetBranchAddress ("smdS7_v_adc",       &smdS7_v_adc);
0075   smdHits -> SetBranchAddress ("smdS8_v_adc",       &smdS8_v_adc);
0076 
0077 
0078 
0079 
0080   smdHits->SetBranchStatus("zdcN3_adc",0);
0081   smdHits->SetBranchStatus("zdcS3_adc",0);
0082   int nentries = smdHits->GetEntries();
0083   //======================================================================//
0084 
0085   //============================= Option A: Spin DB ================================//
0086   unsigned int qa_level = 0xffff;
0087   SpinDBOutput spin_out("phnxrc");
0088   SpinDBContentv1 spin_cont;
0089   spin_out.StoreDBContent(runnumber, runnumber, qa_level);
0090   SpinDBContent* spin_ptr = &spin_cont;
0091   spin_out.GetDBContentStore(spin_ptr, runnumber);
0092 
0093   int crossingshift = spin_cont.GetCrossingShift();
0094   // crossingshift = 0;
0095   // crossingshift = ixs;
0096   // if (ixs < 0){crossingshift = 120+ixs;}
0097   std::cout << crossingshift << std::endl;
0098 
0099   int bspinpat[120] = {0};
0100   int yspinpat[120] = {0};
0101   for (int i = 0; i < 120; i++)
0102   {
0103     bspinpat[i] = spin_cont.GetSpinPatternBlue(i);
0104     yspinpat[i] = spin_cont.GetSpinPatternYellow(i);
0105     if(isflipON)
0106     {
0107       bspinpat[i]*=-1;
0108       yspinpat[i]*=-1;
0109     }
0110   }
0111   //======================================================================//
0112 
0113   //============================= Option B: Get spin pattern manually ================================//
0114   int bpat[120] = {0};
0115   int ypat[120] = {0};
0116   std::string preset_pattern_blue[8];
0117   std::string preset_pattern_yellow[8];
0118   preset_pattern_blue[0] = "+-+--+-+-+-++-+--+-++-+-+-+--+-+-+-++-+--+-++-+-+-+--+-+-+-++-+--+-++-+-+-+--+-+-+-++-+--+-++-+-+-+--+-+-+-++-+*********";
0119   preset_pattern_blue[1] = "-+-++-+-+-+--+-++-+--+-+-+-++-+-+-+--+-++-+--+-+-+-++-+-+-+--+-++-+--+-+-+-++-+-+-+--+-++-+--+-+-+-++-+-+-+--+-*********";
0120   preset_pattern_blue[2] = "+-+--+-+-+-++-+--+-++-+-+-+--+-+-+-++-+--+-++-+-+-+--+-+-+-++-+--+-++-+-+-+--+-+-+-++-+--+-++-+-+-+--+-+-+-++-+*********";
0121   preset_pattern_blue[3] = "-+-++-+-+-+--+-++-+--+-+-+-++-+-+-+--+-++-+--+-+-+-++-+-+-+--+-++-+--+-+-+-++-+-+-+--+-++-+--+-+-+-++-+-+-+--+-*********";
0122   preset_pattern_blue[4] = "++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++-*********";
0123   preset_pattern_blue[5] = "--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--+*********";
0124   preset_pattern_blue[6] = "++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++-*********";
0125   preset_pattern_blue[7] = "--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--+*********";
0126 
0127   preset_pattern_yellow[0] = "++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++-*********";
0128   preset_pattern_yellow[1] = "++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++-*********";
0129   preset_pattern_yellow[2] = "--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--+*********";
0130   preset_pattern_yellow[3] = "--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--+*********";
0131   preset_pattern_yellow[4] = "+-+--+-+-+-++-+--+-++-+-+-+--+-+-+-++-+--+-++-+-+-+--+-+-+-++-+--+-++-+-+-+--+-+-+-++-+--+-++-+-+-+--+-+-+-++-+*********";
0132   preset_pattern_yellow[5] = "+-+--+-+-+-++-+--+-++-+-+-+--+-+-+-++-+--+-++-+-+-+--+-+-+-++-+--+-++-+-+-+--+-+-+-++-+--+-++-+-+-+--+-+-+-++-+*********";
0133   preset_pattern_yellow[6] = "-+-++-+-+-+--+-++-+--+-+-+-++-+-+-+--+-++-+--+-+-+-++-+-+-+--+-++-+--+-+-+-++-+-+-+--+-++-+--+-+-+-++-+-+-+--+-*********";
0134   preset_pattern_yellow[7] = "-+-++-+-+-+--+-++-+--+-+-+-++-+-+-+--+-++-+--+-+-+-++-+-+-+--+-++-+--+-+-+-++-+-+-+--+-++-+--+-+-+-++-+-+-+--+-*********";
0135 
0136   int spinpatternNo = 3;
0137   if (storenumber == 34485)
0138   {
0139     spinpatternNo = 3;
0140   }  // pattern names start at '111x111_P1' so index 3  means '111x111_P4' and so on
0141   if(storenumber == 34782)
0142   {
0143     spinpatternNo = 5;
0144   }
0145   for (int i = 0; i < 120; i++)
0146   {
0147     if (preset_pattern_blue[spinpatternNo].at(i) == '+')
0148     {
0149       bpat[i] = 1;
0150     }
0151     else if (preset_pattern_blue[spinpatternNo].at(i) == '-')
0152     {
0153       bpat[i] = -1;
0154     }
0155     else if (preset_pattern_blue[spinpatternNo].at(i) == '*')
0156     {
0157       bpat[i] = 10;
0158     }
0159 
0160     if (preset_pattern_yellow[spinpatternNo].at(i) == '+')
0161     {
0162       ypat[i] = 1;
0163     }
0164     else if (preset_pattern_yellow[spinpatternNo].at(i) == '-')
0165     {
0166       ypat[i] = -1;
0167     }
0168     else if (preset_pattern_yellow[spinpatternNo].at(i) == '*')
0169     {
0170       ypat[i] = 10;
0171     }
0172   }
0173   //=====================================================================================//
0174 
0175   //======================= process event ==================================//
0176   std::cout << nentries << std::endl;
0177 
0178   int clockOffset = 0;  // this is the offset between GL1 and ZDC events
0179 
0180 //for (int i = 0; i <1000000; i++)
0181   for (int i = 0; i < nentries - clockOffset; i++)
0182   {
0183     if (i % 1000000 == 0)
0184     {
0185       std::cout << "Entry: " << i << std::endl;
0186     }
0187     smdHits->GetEntry(i + clockOffset);
0188 
0189     int sphenix_cross = (bunchnumber + crossingshift) % 120;
0190 
0191     smdHits->GetEntry(i);
0192 
0193     int bspin = bspinpat[sphenix_cross];  // option A: spinDB
0194     int yspin = yspinpat[sphenix_cross];  // option A: spinDB
0195     // int bspin = bpat[sphenix_cross]; //option B: preset patterns
0196     // int yspin = ypat[sphenix_cross]; //option B: preset patterns
0197 
0198     if (zdcN1_adc > ZDC1CUT && zdcN2_adc > ZDC2CUT && veto_NF < VETOCUT && veto_NB < VETOCUT && showerCutN == 1)
0199     {
0200       if (smdN1_adc > 100. && smdN2_adc > 100.)
0201       {
0202         n_smd_L->Fill(sphenix_cross);
0203       }
0204       if (smdN6_adc > 100. && smdN7_adc > 100.)
0205         n_smd_R->Fill(sphenix_cross);
0206       if (smdN1_v_adc > 100. && smdN2_v_adc > 100.)
0207       {
0208         n_smd_D->Fill(sphenix_cross);
0209       }
0210       if (smdN7_v_adc > 100. && smdN8_v_adc > 100.)
0211       {
0212         n_smd_U->Fill(sphenix_cross);
0213       }
0214       //////////// OLD //////////////////
0215       // if (n_x < -3)
0216       // {
0217       //   n_smd_L->Fill(sphenix_cross);
0218       // }
0219       // else if (n_x > 3)
0220       //   n_smd_R->Fill(sphenix_cross);
0221 
0222       // if (n_y > 3)
0223       // {
0224       //   n_smd_U->Fill(sphenix_cross);
0225       // }
0226       // else if (n_y < -3)
0227       // {
0228       //   n_smd_D->Fill(sphenix_cross);
0229       // }
0230       //////////// OLD ////////////////
0231     }
0232 
0233     if (zdcS1_adc > ZDC1CUT && zdcS2_adc > ZDC2CUT && veto_SF < VETOCUT && veto_SB < VETOCUT && showerCutS == 1)
0234     {
0235       if (smdS1_adc > 100. && smdS2_adc > 100.)
0236       {
0237         s_smd_L->Fill(sphenix_cross);
0238       }
0239       if (smdS6_adc > 100. && smdS7_adc > 100.)
0240         s_smd_R->Fill(sphenix_cross);
0241       if (smdS1_v_adc > 100. && smdS2_v_adc > 100.)
0242       {
0243         s_smd_D->Fill(sphenix_cross);
0244       }
0245       if (smdS7_v_adc > 100. && smdS8_v_adc > 100.)
0246       {
0247         s_smd_U->Fill(sphenix_cross);
0248       }
0249 
0250       /////////////// OLD ///////////////
0251       // if (s_x < -3)
0252       // {
0253       //   s_smd_L->Fill(sphenix_cross);
0254       // }
0255       // else if (s_x > 3)
0256       //   s_smd_R->Fill(sphenix_cross);
0257       // if (s_y > 3)
0258       // {
0259       //   s_smd_U->Fill(sphenix_cross);
0260       // }
0261       // else if (s_y < -3)
0262       // {
0263       //   s_smd_D->Fill(sphenix_cross);
0264       // }
0265       ///////////// OLD //////////////////
0266     }
0267   }
0268   //=====================================================================================//
0269 
0270   std::vector<double> x_spinup_blueUD, y_spinup_blueUD, ex_spinup_blueUD, ey_spinup_blueUD;
0271   std::vector<double> x_spindown_blueUD, y_spindown_blueUD, ex_spindown_blueUD, ey_spindown_blueUD;
0272   std::vector<double> x_spinup_yellowUD, y_spinup_yellowUD, ex_spinup_yellowUD, ey_spinup_yellowUD;
0273   std::vector<double> x_spindown_yellowUD, y_spindown_yellowUD, ex_spindown_yellowUD, ey_spindown_yellowUD;
0274 
0275   for (int i = 1; i <= 115; ++i)
0276   {
0277     double A = n_smd_U->GetBinContent(i);
0278     double B = n_smd_D->GetBinContent(i);
0279     double A_y = s_smd_U->GetBinContent(i);
0280     double B_y = s_smd_D->GetBinContent(i);
0281     std::cout << "A : " << A << " //// B : " << B << std::endl;
0282     int nbunch = i - 1;
0283     int b_spin = bspinpat[nbunch];
0284     int y_spin = yspinpat[nbunch];
0285     if (b_spin != 1 && b_spin != -1)
0286       continue;
0287     if (A != 0 || B != 0)
0288     {
0289       double aym = (A - B) / (A + B);
0290       double error = TMath::Sqrt(4 * (A * B) / ((A + B) * (A + B) * (A + B)));
0291       if (b_spin == 1)
0292       {  // spinup_blueUD bin
0293         x_spinup_blueUD.push_back(nbunch);
0294         y_spinup_blueUD.push_back(aym);
0295         ex_spinup_blueUD.push_back(0);  // No error on x
0296         ey_spinup_blueUD.push_back(error);
0297       }
0298       else if (b_spin == -1)
0299       {  // spindown_blueUD bin
0300         x_spindown_blueUD.push_back(nbunch);
0301         y_spindown_blueUD.push_back(aym);
0302         ex_spindown_blueUD.push_back(0);  // No error on x
0303         ey_spindown_blueUD.push_back(error);
0304       }
0305     }
0306     if (A_y != 0 || B_y != 0)
0307     {
0308       double aym = (A_y - B_y) / (A_y + B_y);
0309       double error = TMath::Sqrt(4 * (A_y * B_y) / ((A_y + B_y) * (A_y + B_y) * (A_y + B_y)));
0310       if (y_spin == 1)
0311       {  // spinup_blueUD bin
0312         x_spinup_yellowUD.push_back(nbunch);
0313         y_spinup_yellowUD.push_back(aym);
0314         ex_spinup_yellowUD.push_back(0);  // No error on x
0315         ey_spinup_yellowUD.push_back(error);
0316       }
0317       else if (y_spin == -1)
0318       {  // spindown_yellowUD bin
0319         x_spindown_yellowUD.push_back(nbunch);
0320         y_spindown_yellowUD.push_back(aym);
0321         ex_spindown_yellowUD.push_back(0);  // No error on x
0322         ey_spindown_yellowUD.push_back(error);
0323       }
0324     }
0325   }
0326 
0327   std::vector<double> x_spinup_blue, y_spinup_blue, ex_spinup_blue, ey_spinup_blue;
0328   std::vector<double> x_spindown_blue, y_spindown_blue, ex_spindown_blue, ey_spindown_blue;
0329   std::vector<double> x_spinup_yellow, y_spinup_yellow, ex_spinup_yellow, ey_spinup_yellow;
0330   std::vector<double> x_spindown_yellow, y_spindown_yellow, ex_spindown_yellow, ey_spindown_yellow;
0331 
0332   int nBins = n_smd_L->GetNbinsX();
0333   for (int i = 1; i <= 115; ++i)
0334   {
0335     double A = n_smd_L->GetBinContent(i);
0336     double B = n_smd_R->GetBinContent(i);
0337     double A_y = s_smd_L->GetBinContent(i);
0338     double B_y = s_smd_R->GetBinContent(i);
0339     std::cout << "A : " << A << " //// B : " << B << std::endl;
0340     int nbunch = i - 1;
0341     int b_spin = bspinpat[nbunch];
0342     int y_spin = yspinpat[nbunch];
0343     if (b_spin != 1 && b_spin != -1)
0344       continue;
0345     if (A != 0 || B != 0)
0346     {
0347       double aym = (A - B) / (A + B);
0348       double error = TMath::Sqrt(4 * (A * B) / ((A + B) * (A + B) * (A + B)));
0349       if (b_spin == 1)
0350       {  // spinup_blue bin
0351         x_spinup_blue.push_back(nbunch);
0352         y_spinup_blue.push_back(aym);
0353         ex_spinup_blue.push_back(0);  // No error on x
0354         ey_spinup_blue.push_back(error);
0355       }
0356       else if (b_spin == -1)
0357       {  // spindown_blue bin
0358         x_spindown_blue.push_back(nbunch);
0359         y_spindown_blue.push_back(aym);
0360         ex_spindown_blue.push_back(0);  // No error on x
0361         ey_spindown_blue.push_back(error);
0362       }
0363     }
0364     if (A_y != 0 || B_y != 0)
0365     {
0366       double aym = (A_y - B_y) / (A_y + B_y);
0367       double error = TMath::Sqrt(4 * (A_y * B_y) / ((A_y + B_y) * (A_y + B_y) * (A_y + B_y)));
0368       if (y_spin == 1)
0369       {  // spinup_blue bin
0370         x_spinup_yellow.push_back(nbunch);
0371         y_spinup_yellow.push_back(aym);
0372         ex_spinup_yellow.push_back(0);  // No error on x
0373         ey_spinup_yellow.push_back(error);
0374       }
0375       else if (y_spin == -1)
0376       {  // spindown_yellow bin
0377         x_spindown_yellow.push_back(nbunch);
0378         y_spindown_yellow.push_back(aym);
0379         ex_spindown_yellow.push_back(0);  // No error on x
0380         ey_spindown_yellow.push_back(error);
0381       }
0382     }
0383   }
0384 
0385   // Create the TGraphErrors for spinup_blueUD bins
0386   TGraphErrors *graph_spinup_blueUD = new TGraphErrors(x_spinup_blueUD.size(), x_spinup_blueUD.data(), y_spinup_blueUD.data(), ex_spinup_blueUD.data(), ey_spinup_blueUD.data());
0387   graph_spinup_blueUD->SetMarkerStyle(21);
0388   graph_spinup_blueUD->SetTitle("SMD North Up Down asymmetry");
0389   graph_spinup_blueUD->SetMarkerColor(kRed);
0390   graph_spinup_blueUD->SetLineColor(kRed);
0391 
0392   // Create the TGraphErrors for spindown_blueUD bins
0393   TGraphErrors *graph_spindown_blueUD = new TGraphErrors(x_spindown_blueUD.size(), x_spindown_blueUD.data(), y_spindown_blueUD.data(), ex_spindown_blueUD.data(), ey_spindown_blueUD.data());
0394   graph_spindown_blueUD->SetMarkerStyle(21);
0395   graph_spindown_blueUD->SetTitle("SMD North Up Down asymmetry");
0396   graph_spindown_blueUD->SetMarkerColor(kBlue);
0397   graph_spindown_blueUD->SetLineColor(kBlue);
0398 
0399   // Create the TGraphErrors for spinup_yellowUD bins
0400   TGraphErrors *graph_spinup_yellowUD = new TGraphErrors(x_spinup_yellowUD.size(), x_spinup_yellowUD.data(), y_spinup_yellowUD.data(), ex_spinup_yellowUD.data(), ey_spinup_yellowUD.data());
0401   graph_spinup_yellowUD->SetMarkerStyle(21);
0402   graph_spinup_yellowUD->SetTitle("SMD South Up Down asymmetry");
0403   graph_spinup_yellowUD->SetMarkerColor(kRed);
0404   graph_spinup_yellowUD->SetLineColor(kRed);
0405 
0406   // Create the TGraphErrors for spindown_yellowUD bins
0407   TGraphErrors *graph_spindown_yellowUD = new TGraphErrors(x_spindown_yellowUD.size(), x_spindown_yellowUD.data(), y_spindown_yellowUD.data(), ex_spindown_yellowUD.data(), ey_spindown_yellowUD.data());
0408   graph_spindown_yellowUD->SetMarkerStyle(21);
0409   graph_spindown_yellowUD->SetTitle("SMD South Up Down asymmetry ");
0410   graph_spindown_yellowUD->SetMarkerColor(kBlue);
0411   graph_spindown_yellowUD->SetLineColor(kBlue);
0412 
0413   // Create the TGraphErrors for spinup_blue bins
0414   TGraphErrors *graph_spinup_blue = new TGraphErrors(x_spinup_blue.size(), x_spinup_blue.data(), y_spinup_blue.data(), ex_spinup_blue.data(), ey_spinup_blue.data());
0415   graph_spinup_blue->SetMarkerStyle(21);
0416   graph_spinup_blue->SetTitle("SMD North Left Right asymmetry");
0417   graph_spinup_blue->SetMarkerColor(kRed);
0418   graph_spinup_blue->SetLineColor(kRed);
0419 
0420   // Create the TGraphErrors for spindown_blue bins
0421   TGraphErrors *graph_spindown_blue = new TGraphErrors(x_spindown_blue.size(), x_spindown_blue.data(), y_spindown_blue.data(), ex_spindown_blue.data(), ey_spindown_blue.data());
0422   graph_spindown_blue->SetMarkerStyle(21);
0423   graph_spindown_blue->SetTitle("SMD North Left Right asymmetry");
0424   graph_spindown_blue->SetMarkerColor(kBlue);
0425   graph_spindown_blue->SetLineColor(kBlue);
0426 
0427   // Create the TGraphErrors for spinup_yellow bins
0428   TGraphErrors *graph_spinup_yellow = new TGraphErrors(x_spinup_yellow.size(), x_spinup_yellow.data(), y_spinup_yellow.data(), ex_spinup_yellow.data(), ey_spinup_yellow.data());
0429   graph_spinup_yellow->SetMarkerStyle(21);
0430   graph_spinup_yellow->SetTitle("SMD South Left Right asymmetry");
0431   graph_spinup_yellow->SetMarkerColor(kRed);
0432   graph_spinup_yellow->SetLineColor(kRed);
0433 
0434   // Create the TGraphErrors for spindown_yellow bins
0435   TGraphErrors *graph_spindown_yellow = new TGraphErrors(x_spindown_yellow.size(), x_spindown_yellow.data(), y_spindown_yellow.data(), ex_spindown_yellow.data(), ey_spindown_yellow.data());
0436   graph_spindown_yellow->SetMarkerStyle(21);
0437   graph_spindown_yellow->SetTitle("SMD South Left Right asymmetry ");
0438   graph_spindown_yellow->SetMarkerColor(kBlue);
0439   graph_spindown_yellow->SetLineColor(kBlue);
0440 
0441   TLatex *latex = new TLatex();
0442   latex->SetNDC();
0443   latex->SetTextSize(0.045);
0444   latex->SetTextAlign(31);
0445   TCanvas *canvas = new TCanvas("canvas_blue", "North SMD", 950, 800);
0446   graph_spinup_blue->GetXaxis()->SetLimits(0, 111);
0447   graph_spinup_blue->GetYaxis()->SetTitle("(L-R)/(L+R)");
0448   graph_spinup_blue->GetXaxis()->SetTitle("Bunch number");
0449   graph_spinup_blue->SetMinimum(-0.08);
0450   graph_spinup_blue->SetMaximum(0.02);
0451   canvas->cd();
0452   graph_spinup_blue->Draw("AP");
0453   graph_spindown_blue->Draw("P SAME");
0454   TFitResultPtr fit_spinup_blue = graph_spinup_blue->Fit("pol0", "S");
0455   TFitResultPtr fit_spindown_blue = graph_spindown_blue->Fit("pol0", "S");
0456   // Add legend
0457   TLegend leg1(.20, .70, .60, .90);
0458   leg1.AddEntry((TObject *) 0, Form("SMD North / Run %d", runnumber), "");
0459   leg1.AddEntry(graph_spinup_blue, Form("blue #uparrow :  %.5f #pm %.5f", fit_spinup_blue->Parameter(0), fit_spinup_blue->ParError(0)), "LP");
0460   leg1.AddEntry(graph_spindown_blue, Form("blue #downarrow : %.5f #pm %.5f", fit_spindown_blue->Parameter(0), fit_spindown_blue->ParError(0)), "LP");
0461   leg1.SetTextSize(0.03);
0462   leg1.Draw();
0463   latex->DrawLatex(1 - gPad->GetRightMargin(), 1 - gPad->GetTopMargin() + 0.01, Form("#it{p+p}, 200 GeV, Run %d #it{#bf{sPHENIX}} internal", runnumber));
0464 
0465   TCanvas *canvas2 = new TCanvas("canvas_blueUD", "North SMD UD", 950, 800);
0466   graph_spinup_blueUD->GetXaxis()->SetLimits(0, 111);
0467   graph_spinup_blueUD->GetYaxis()->SetTitle("(U-D)/(U+D)");
0468   graph_spinup_blueUD->GetXaxis()->SetTitle("Bunch number");
0469   graph_spinup_blueUD->SetMinimum(0.18);
0470   graph_spinup_blueUD->SetMaximum(0.18+0.1);
0471   canvas2->cd();
0472   graph_spinup_blueUD->Draw("AP");
0473   graph_spindown_blueUD->Draw("P SAME");
0474   // Add legend
0475   TFitResultPtr fit_spinup_blueUD = graph_spinup_blueUD->Fit("pol0", "S");
0476   TFitResultPtr fit_spindown_blueUD = graph_spindown_blueUD->Fit("pol0", "S");
0477   TLegend leg2(.20, .70, .60, .90);
0478   leg2.AddEntry((TObject *) 0, Form("SMD North / Run %d", runnumber), "");
0479   leg2.AddEntry(graph_spinup_blueUD, Form("blue #uparrow :  %.5f #pm %.5f", fit_spinup_blueUD->Parameter(0), fit_spinup_blueUD->ParError(0)), "LP");
0480   leg2.AddEntry(graph_spindown_blueUD, Form("blue #downarrow : %.5f #pm %.5f", fit_spindown_blueUD->Parameter(0), fit_spindown_blueUD->ParError(0)), "LP");
0481   leg2.SetTextSize(0.03);
0482   leg2.Draw();
0483   latex->DrawLatex(1 - gPad->GetRightMargin(), 1 - gPad->GetTopMargin() + 0.01, Form("#it{p+p}, 200 GeV, Run %d #it{#bf{sPHENIX}} internal", runnumber));
0484 
0485   TCanvas *canvas3 = new TCanvas("canvas_yellow", "South SMD", 950, 800);
0486   graph_spinup_yellow->GetXaxis()->SetLimits(0, 111);
0487   graph_spinup_yellow->GetYaxis()->SetTitle("(L-R)/(L+R)");
0488   graph_spinup_yellow->GetXaxis()->SetTitle("Bunch number");
0489   graph_spinup_yellow->SetMaximum(0.07);
0490   graph_spinup_yellow->SetMinimum(-0.03);
0491   canvas3->cd();
0492   graph_spinup_yellow->Draw("AP");
0493   graph_spindown_yellow->Draw("P SAME");
0494   // Add legend
0495   TFitResultPtr fit_spinup_yellow = graph_spinup_yellow->Fit("pol0", "S");
0496   TFitResultPtr fit_spindown_yellow = graph_spindown_yellow->Fit("pol0", "S");
0497   TLegend leg3(.20, .70, .60, .90);
0498   leg3.AddEntry((TObject *) 0, Form("SMD South / Run %d", runnumber), "");
0499   leg3.AddEntry(graph_spinup_yellow, Form("yellow #uparrow :  %.5f #pm %.5f", fit_spinup_yellow->Parameter(0), fit_spinup_yellow->ParError(0)), "LP");
0500   leg3.AddEntry(graph_spindown_yellow, Form("yellow #downarrow : %.5f #pm %.5f", fit_spindown_yellow->Parameter(0), fit_spindown_yellow->ParError(0)), "LP");
0501   leg3.SetTextSize(0.03);
0502   leg3.Draw();
0503   latex->DrawLatex(1 - gPad->GetRightMargin(), 1 - gPad->GetTopMargin() + 0.01, Form("#it{p+p}, 200 GeV, Run %d #it{#bf{sPHENIX}} internal", runnumber));
0504 
0505   TCanvas *canvas4 = new TCanvas("canvas_yellow_UD", "South SMD", 950, 800);
0506   graph_spinup_yellowUD->GetXaxis()->SetLimits(0, 111);
0507   graph_spinup_yellowUD->GetYaxis()->SetTitle("(U-D)/(U+D)");
0508   graph_spinup_yellowUD->GetXaxis()->SetTitle("Bunch number");
0509   graph_spinup_yellowUD->SetMaximum(-0.04 + 0.1);
0510   graph_spinup_yellowUD->SetMinimum(-0.04);
0511   canvas4->cd();
0512   graph_spinup_yellowUD->Draw("AP");
0513   graph_spindown_yellowUD->Draw("P SAME");
0514   // Add legend
0515   // TLegend *legend4 = new TLegend(0.7, 0.9, 0.8, 0.95);
0516   // legend4->AddEntry(graph_spinup_yellowUD, "yellow spin up Bunches", "p");
0517   // legend4->AddEntry(graph_spindown_yellowUD, "yellow spin down Bunches", "p");
0518   // legend4->Draw();
0519   // latex->DrawLatexNDC(0.65, 0.8, "#bf{sPHENIX} internal");
0520   // if (!ismerged)
0521   //   latex->DrawLatexNDC(0.65, 0.75, Form("Run %d", runnumber));
0522   // else
0523   //   latex->DrawLatexNDC(0.65, 0.75, Form("Store %d", storenumber));
0524   TFitResultPtr fit_spinup_yellowUD = graph_spinup_yellowUD->Fit("pol0", "S");
0525   TFitResultPtr fit_spindown_yellowUD = graph_spindown_yellowUD->Fit("pol0", "S");
0526   TLegend leg4(.20, .70, .60, .90);
0527   leg4.AddEntry((TObject *) 0, Form("SMD South / Run %d", runnumber), "");
0528   leg4.AddEntry(graph_spinup_yellowUD, Form("yellow #uparrow :  %.5f #pm %.5f", fit_spinup_yellowUD->Parameter(0), fit_spinup_yellowUD->ParError(0)), "LP");
0529   leg4.AddEntry(graph_spindown_yellowUD, Form("yellow #downarrow : %.5f #pm %.5f", fit_spindown_yellowUD->Parameter(0), fit_spindown_yellowUD->ParError(0)), "LP");
0530   leg4.SetTextSize(0.03);
0531   leg4.Draw();
0532   latex->DrawLatex(1 - gPad->GetRightMargin(), 1 - gPad->GetTopMargin() + 0.01, Form("#it{p+p}, 200 GeV, Run %d #it{#bf{sPHENIX}} internal", runnumber));
0533 
0534   TCanvas *canvas5 = new TCanvas("canvas5", "canvas5", 950, 800);
0535   canvas5->cd();
0536   canvas5->SetLogy();
0537   // n_smd_L->SetLineWidth(1.5);
0538   n_smd_L->SetXTitle("bunch number");
0539   // n_smd_L->SetMarkerStyle(kFullCircle);
0540   n_smd_L->Draw("E");
0541   latex->DrawLatex(1 - gPad->GetRightMargin(), 1 - gPad->GetTopMargin() + 0.01, Form("#it{p+p}, 200 GeV #it{#bf{sPHENIX}} internal"));
0542 
0543   canvas5->SaveAs(Form("north_smd1_run%d.pdf", runnumber));
0544   TCanvas *canvas6 = new TCanvas("canvas6", "canvas6", 950, 800);
0545   canvas6->cd();
0546   canvas6->SetLogy();
0547   // n_smd_L->SetLineWidth(1.5);
0548   n_smd_R->SetXTitle("bunch number");
0549   // n_smd_R->SetMarkerStyle(kFullCircle);
0550   n_smd_R->Draw("E");
0551   latex->DrawLatex(1 - gPad->GetRightMargin(), 1 - gPad->GetTopMargin() + 0.01, Form("#it{p+p}, 200 GeV #it{#bf{sPHENIX}} internal"));
0552   canvas6->SaveAs(Form("north_smd2_run%d.pdf", runnumber));
0553 
0554   std::string outname = Form("bunch_run%d.root", runnumber);
0555   TFile *sfile = new TFile(outname.c_str(), "RECREATE");
0556   TString pdfName;
0557   TString fileName;
0558   sfile->cd();
0559   canvas->Write();
0560   pdfName = canvas->GetName();
0561   fileName = pdfName + ".pdf";
0562   canvas->SaveAs(fileName);
0563   canvas->Update();
0564   canvas2->Write();
0565   pdfName = canvas2->GetName();
0566   fileName = pdfName + ".pdf";
0567   canvas2->SaveAs(fileName);
0568   canvas2->Update();
0569   canvas3->Write();
0570   pdfName = canvas3->GetName();
0571   fileName = pdfName + ".pdf";
0572   canvas3->SaveAs(fileName);
0573   canvas3->Update();
0574   canvas4->Write();
0575   pdfName = canvas4->GetName();
0576   fileName = pdfName + ".pdf";
0577   canvas4->SaveAs(fileName);
0578   canvas4->Update();
0579 
0580   n_smd_L->Write();
0581   n_smd_R->Write();
0582   s_smd_L->Write();
0583   s_smd_R->Write();
0584   n_smd_U->Write();
0585   n_smd_D->Write();
0586   s_smd_U->Write();
0587   s_smd_D->Write();
0588   sfile->Close();
0589 }