#include "TH1.h" #include "TF1.h" #include "iostream.h" #include "fstream.h" #include "iomanip" #include #include "stdio.h" #include #include #include "math.h" #include #include using namespace std; using std::ofstream; const int size = 8192; float eff1(float x) //x is energy { float a0=6.; float a1=-0.471494; float a2=-0.126186; float a3=-0.261277; float lne, eff; if (x<=1022) lne=a0+a1*log(x); if (x>1022) lne=a0+a1*log(x)+a2*log(x/1022)+a3*log(x/1022)*log(x/1022); eff=exp(lne); return eff; } float eff2(float x) //x is energy { float a0=6.; float a1=-0.521824; float a2=-0.077314; float a3=-0.240241; float lne, eff; if (x<=1022) lne=a0+a1*log(x); if (x>1022) lne=a0+a1*log(x)+a2*log(x/1022)+a3*log(x/1022)*log(x/1022); eff=exp(lne); return eff; } float CtE(float C) { float a = 1.0006; float b = 18.5; return a*C+b; } void read() { ifstream if1; if1.open("Yb.dat"); int E1, E2; TH2F *h2 = new TH2F("h2","",size,0,size+.5,size,0,size+.5); while (if1 >> E1 >> E2) { h2->Fill(E1,E2); } if1.close(); cout<<"Read file to histogram is done!"<Integral(); cout<<"Nbefore = "<GetBinContent(i,j); value = value / (eff1(CtE(i))*eff2(CtE(j))); h2->SetBinContent(i,j,value); } } cout<<"Normalizing ..."<Integral(); cout<<"Nafter ="<GetBinContent(i,j); h2->SetBinContent(i,j,value*Nbefore/Nafter); } cout<<"h2 entries = "<Integral()<Write(); f->Close(); } void det(string spename) { TFile f("Yb.root"); TH2F *h = (TH2F*)f.Get("h2"); h->SetDirectory(gROOT); f.Close(); TH1D *px = h->ProjectionX(); TH1D *py = h->ProjectionY(); //px->Draw(); string s1, s2; s1 = spename+"_det1.asc"; s2 = spename+"_det2.asc"; ofstream of1, of2; of1.open(s1.c_str()); of2.open(s2.c_str()); for (int i =1; i<=8192; i++) { of1 << i <<" "<< px->GetBinContent(i)<GetBinContent(i)<SetDirectory(gROOT); f.Close(); string s1, s2, s3; s1 = name + "d.coin"; s2 = name + "b.coin"; TH1D *b11 = h->ProjectionX("b11",BL1,BR1); TH1D *b12 = h->ProjectionY("b12",BL1,BR1); TH1D *b21 = h->ProjectionX("b21",BL2,BR2); TH1D *b22 = h->ProjectionY("b22",BL2,BR2); TH1D *d1 = h->ProjectionX("d1",L,R); TH1D *d2 = h->ProjectionY("d2",L,R); TH1D *d = d1; TH1D *b = b11; d->Add(d2); b->Add(b12); b->Add(b21); b->Add(b22); // d->Draw(); // b->SetLineColor(kRed); // b->Draw("SAME"); ofstream of1, of2; of1.open(s1.c_str()); of2.open(s2.c_str()); for (int i=1; i<=size; i++) { of1<GetBinContent(i)<GetBinContent(i)<