Back to home page

sPhenix code displayed by LXR

 
 

    


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

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 ReadHis()
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 = 310.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+1;
0076 int YBins = (Ymax - Ymin)/step+1;
0077 int index = 0;
0078 
0079 int indexmax = XBins * YBins;
0080 char Filename[512];
0081 char inputfile[512];
0082 
0083 sprintf(inputfile,"Hisfiles130/HisAll.root");
0084 
0085 //sprintf(inputfile,"His2.root");
0086 
0087 
0088 TFile *fin = new TFile(inputfile);
0089 TH2D *EnPo= new TH2D("EnPo","",XBins,Xmin,Xmax,YBins,Ymin,Ymax);
0090 
0091 
0092 cout << "XBins = " << XBins << endl;
0093 cout << "YBins = " << YBins << endl;
0094 
0095 char hisname[512];
0096 
0097 for(int i = 0; i < XBins; i++)
0098 {
0099 
0100 x = Xmin + step*i;
0101 
0102 xhigh = Xmin + step*(i+1);
0103 
0104 
0105 for(int j = 0; j < YBins; j++)
0106 {
0107 
0108 //  TCanvas *c1 = new TCanvas("c1", "c1",0,0,800,600);
0109     y = Ymin + step*j;
0110 yhigh = Ymin + step*(j+1);
0111 
0112 
0113 binxhigh = Energyhis->GetZaxis()->FindBin(xhigh);
0114 binyhigh = Energyhis->GetYaxis()->FindBin(yhigh);
0115 
0116 
0117 
0118 binx = Energyhis->GetZaxis()->FindBin(x);
0119 biny = Energyhis->GetYaxis()->FindBin(y);
0120 
0121 //binxhigh = binx +1;
0122 //binyhigh = biny +1;
0123 
0124 
0125 TH1D *h5= new TH1D("h5","",50,6,10);
0126 
0127  Energyhis->ProjectionX("h5",biny,binyhigh,binx,binxhigh);
0128 
0129 // h5->GetXaxis()->SetRange(6,10);
0130  //h5->Rebin(2);
0131 
0132  //return;
0133 //
0134 /*
0135  h5->Fit("gaus");
0136 
0137 c1->Update();
0138 sprintf(hisname,"pngfiles/Plot%d-%d.png",i,j);
0139 
0140   c1->SaveAs(hisname);
0141 
0142 
0143 Energy = gaus->GetParameter(0);
0144 Energy_err = gaus->GetParError(0);
0145 Center = gaus->GetParameter(1);
0146 Center_err = gaus->GetParError(1);
0147 Width = gaus->GetParameter(2);
0148 Width_err = gaus->GetParError(2);
0149 */
0150 
0151  Center = h5->GetMean();
0152 
0153 cout << "Mean =  "  << Center << endl;
0154 
0155 EnPo->SetBinContent(binx,biny,Center);
0156 
0157 
0158 index = index + 1;
0159 
0160 }
0161 
0162 }
0163 
0164 TCanvas *c22 = new TCanvas("c22", "c22",0,0,800,600);
0165 
0166 c22->cd();
0167 
0168 EnPo->Draw();
0169     
0170     c22->Update();
0171 
0172   c22->SaveAs("EnPo.png");
0173 
0174 
0175 sprintf(Filename,"EnergyPosition.root");
0176 
0177 //sprintf(Filename,"EnergyPosition2.root");
0178   TFile *fout = new TFile(Filename,"RECREATE");
0179 EnPo->Write();
0180 
0181 
0182 }