Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:14:42

0001 #include <cmath>
0002 #include <TFile.h>
0003 #include <TString.h>
0004 #include <TLine.h>
0005 #include <TTree.h>
0006 #include <TLatex.h>
0007 #include <TGraphErrors.h>
0008 #include <cassert>
0009 #include "SaveCanvas.C"
0010 #include "SetOKStyle.C"
0011 #include <iostream>
0012 #include <fstream>
0013 #include "TROOT.h"
0014 #include "TH1.h"
0015 #include "TTree.h"
0016 using namespace std;
0017 
0018 
0019 
0020 using std::cout;
0021 using std::endl;
0022 #endif
0023 
0024 
0025 
0026 
0027 void ReadHis3()
0028 {
0029 
0030   gSystem->Load("libg4eval.so");
0031   gSystem->Load("libqa_modules.so");
0032   gSystem->Load("libPrototype3.so");
0033  gStyle->SetOptFit(0);
0034    gStyle->SetOptStat(0);
0035 
0036    double step = 1;
0037 
0038 int Ini = 3543;
0039 int Final = 3579;
0040 
0041 
0042 double Xmin = 170;
0043 double Xmax = 340.0;
0044 
0045 double Ymin = 60;
0046 double Ymax = 245.0;
0047 
0048 
0049 /*
0050 
0051 double Xmin = 150;
0052 double Xmax = 310.0;
0053 
0054 double Ymin = 20;
0055 double Ymax = 200.0;
0056 */
0057 
0058 
0059 double Energy;
0060 double Energy_err;
0061 double Width;
0062 double Width_err;
0063 double Center;
0064 double Center_err;
0065 
0066 double x;
0067 double y;
0068 double xhigh;
0069 double yhigh;
0070 int binxhigh;
0071 int binyhigh;
0072 
0073 int binx;
0074 int biny;
0075 int XBins = (Xmax - Xmin)/step;
0076 int YBins = (Ymax - Ymin)/step;
0077 
0078 //int XBins = 200;
0079 //int YBins = 200;
0080 
0081 
0082 int index = 0;
0083 
0084 int indexmax = XBins * YBins;
0085 char Filename[512];
0086 char inputfile[512];
0087 
0088 //sprintf(inputfile,"Hisfiles130/HisAll.root");
0089 
0090 sprintf(inputfile,"His3.root");
0091 
0092 TFile *fin = new TFile(inputfile);
0093 TH2D *EnPo= new TH2D("EnPo","",XBins,Xmin,Xmax,YBins,Ymin,Ymax);
0094 
0095 
0096 cout << "XBins = " << XBins << endl;
0097 cout << "YBins = " << YBins << endl;
0098 
0099 char hisname[512];
0100 
0101 for(int i = 0; i < XBins; i++)
0102 {
0103 
0104 x = Xmin + step*i;
0105 
0106 xhigh = Xmin + step*(i+1);
0107 
0108 
0109 for(int j = 0; j < YBins; j++)
0110 {
0111 
0112 //  TCanvas *c1 = new TCanvas("c1", "c1",0,0,800,600);
0113     y = Ymin + step*j;
0114 yhigh = Ymin + step*(j+1);
0115 
0116 
0117 
0118 
0119 binx = Energyhis->GetXaxis()->FindBin(x+0.0001);
0120 biny = Energyhis->GetYaxis()->FindBin(y+0.0001);
0121 
0122 //binxhigh = binx +1;
0123 //binyhigh = biny +1;
0124 
0125 
0126 
0127 binxhigh = Energyhis->GetXaxis()->FindBin(xhigh-0.0001);
0128 binyhigh = Energyhis->GetYaxis()->FindBin(yhigh-0.0001);
0129 
0130 
0131 TH1D *h5= new TH1D("h5","",50,6,10);
0132 
0133 
0134 
0135 
0136  Energyhis->ProjectionZ("h5",binx,binxhigh,biny,binyhigh);
0137 
0138 // h5->GetXaxis()->SetRange(6,10);
0139  //h5->Rebin(2);
0140 
0141  //return;
0142 //
0143 /*
0144  h5->Fit("gaus");
0145 
0146 c1->Update();
0147 sprintf(hisname,"pngfiles/Plot%d-%d.png",i,j);
0148 
0149   c1->SaveAs(hisname);
0150 
0151 
0152 Energy = gaus->GetParameter(0);
0153 Energy_err = gaus->GetParError(0);
0154 Center = gaus->GetParameter(1);
0155 Center_err = gaus->GetParError(1);
0156 Width = gaus->GetParameter(2);
0157 Width_err = gaus->GetParError(2);
0158 */
0159 
0160  Center = h5->GetMean();
0161 
0162 // cout << "x = " <<  x << endl;
0163 
0164 //cout << "y = " <<  y << endl;
0165 cout << "Mean =  "  << Center << endl;
0166 
0167 EnPo->SetBinContent(binx,biny,Center);
0168 
0169 
0170 index = index + 1;
0171 
0172 }
0173 
0174 }
0175 
0176 TCanvas *c22 = new TCanvas("c22", "c22",0,0,800,600);
0177 
0178 c22->cd();
0179 
0180 EnPo->Draw();
0181     
0182     c22->Update();
0183 
0184   c22->SaveAs("EnPo.png");
0185 
0186 
0187 //sprintf(Filename,"EnergyPosition.root");
0188 
0189 sprintf(Filename,"EnergyPosition3.root");
0190   TFile *fout = new TFile(Filename,"RECREATE");
0191 EnPo->Write();
0192 
0193 
0194 }