ANASEN_analysis/sx3cal/EXFit2.C
Sudarsan Balakrishnan eb54b6ab68 Improved sx3 strip range, and added step-ladder correction to PCZ
1) Environment variables allowing flip and offset of anode wires
2) Environment variables allowing for selection of runs' start and stop time positions, to help with phi scanning runs
3) *fix histograms defined that incorporate step-ladder corrections applied to pcz, hard-coded currently in sx3cal/sx3z_vs_pcz/testmodel.h. Will need a better home in the future
4) EXFit2.C has the capability to now gainmatch all sx3 pads, and position along strip is still found from the central three pad edges. Treatment for (backE-missingfrontE) is being considered.
2026-04-14 14:07:18 -04:00

80 lines
3.2 KiB
C

{
int index = 9;
TFile *f = new TFile("../results_run05.root");
TH2F *h2=NULL;
TH1F *h1x=NULL, *h1y=NULL;
//f->cd("evsx");
//f->ls();
double known_xpos[4][2] = {{0,18.75},{-18.75,0}};
std::vector<double> xpos, xposkn; //first = x = known position, second = y = unknown position
std::ofstream ofb(Form("backgains%d.dat",index));
std::ofstream off(Form("frontgains%d.dat",index));
for(int i=0; i<4; i++) {
//do it for pad#2
int backnum=2;
h2 = (TH2F*)(f->Get(Form("evsx/be_vs_x_sx3_id_%d_f%d_b%d",index,i,backnum)));
auto macro = [&]() {
h1x = (TH1F*)(h2->ProjectionX("_px"));
double xleft = h1x->GetBinCenter(h1x->FindFirstBinAbove(h1x->GetMaximum()*0.4));
double xright = h1x->GetBinCenter(h1x->FindLastBinAbove(h1x->GetMaximum()*0.4));
//h1x->GetXaxis()->SetRangeUser(4*xleft, xright*4);
h1x->Draw();
TLine L1(xleft,0,xleft,h1x->GetMaximum()); L1.SetLineColor(kRed); L1.Draw("SAME");
TLine L2(xright,0,xright,h1x->GetMaximum()); L2.SetLineColor(kRed); L2.Draw("SAME");
gPad->Modified();
gPad->Update();
if(backnum==1 || backnum==2) xpos.push_back(xleft); xposkn.push_back(known_xpos[backnum-1][0]);
if(backnum==1 || backnum==2) xpos.push_back(xright); xposkn.push_back(known_xpos[backnum-1][1]);
while(gPad->WaitPrimitive());
h1y = (TH1F*)(h2->ProjectionY("_py"));
double ycenter = h1y->GetBinCenter(h1y->GetMaximumBin());
// std::cout << "front " << i << " back " << backnum << " " << xleft << " " << xright << " " << ycenter << " " << 5486/ycenter << std::endl;
ofb << index <<" front " << i << " back " << backnum << " " << 5486/ycenter << std::endl;
h1y->GetXaxis()->SetRangeUser(ycenter-200,ycenter+200);
h1y->Draw();
TLine L3(ycenter,0,ycenter,h1y->GetMaximum()*1.1); L3.SetLineColor(kRed); L3.Draw("SAME");
gPad->Modified();
gPad->Update();
while(gPad->WaitPrimitive());
};
if(h2)
macro();
//repeat for pad#1
backnum=1;
h2 = (TH2F*)(f->Get(Form("evsx/be_vs_x_sx3_id_%d_f%d_b%d",index,i,backnum)));
if(h2)
macro();
//repeat for pad#2
backnum=3;
h2 = (TH2F*)(f->Get(Form("evsx/be_vs_x_sx3_id_%d_f%d_b%d",index,i,backnum)));
if(h2)
macro();
//repeat for pad3
backnum=0;
h2 = (TH2F*)(f->Get(Form("evsx/be_vs_x_sx3_id_%d_f%d_b%d",index,i,backnum)));
if(h2)
macro();
double xtofit[] = {xpos[0],xpos[3]};
double xktofit[] = {xposkn[0],xposkn[3]};
TGraph G1(xpos.size(),xpos.data(),xposkn.data());
G1.Draw("APL*");
G1.Fit("pol1","Q");
off << index<<" lengthcal front " << i << " " << G1.GetFunction("pol1")->GetParameter(0) << " " << G1.GetFunction("pol1")->GetParameter(1) << std::endl;
gPad->Modified(); gPad->Update();
while(gPad->WaitPrimitive());
xpos.clear();
xposkn.clear();
}
ofb.close();
off.close();
f->Close();
}