3 TFile *file = TFile::Open(inputFile);
4 TFile *
outFile =
new TFile(
"result.root",
"RECREATE");
8 TH1D * constantsHist = (TH1D *) file->Get(
"FDC_InternalAlignment/CathodeAlignmentConstants");
11 TF2 *
f =
new TF2(
"plane",
"[0]+[1]*x+[2]*y", -50.,50.,-50.,50.);
12 ofstream constantsFile;
13 constantsFile.open(
"CathodeAlignment.txt");
15 for(
int i=1; i<=24; i++){
16 double i_deltaPhiU = constantsHist->GetBinContent((i-1)*4+1);
17 double i_deltaU = constantsHist->GetBinContent((i-1)*4+2);
18 double i_deltaPhiV = constantsHist->GetBinContent((i-1)*4+3);
19 double i_deltaV = constantsHist->GetBinContent((i-1)*4+4);
21 double phi_u = 75.0*TMath::DegToRad() + i_deltaPhiU;
22 double phi_v = (TMath::Pi() - 75.0*TMath::DegToRad()) + i_deltaPhiV;
24 double sinPhiU =
sin(phi_u);
25 double cosPhiU = cos(phi_u);
26 double sinPhiV =
sin(phi_v);
27 double cosPhiV = cos(phi_v);
28 double sinPhiUmPhiV =
sin(phi_u-phi_v);
29 double sinPhiUmPhiV2 = sinPhiUmPhiV*sinPhiUmPhiV;
30 double cosPhiUmPhiV = cos(phi_u-phi_v);
33 sprintf(name,
"FDC_InternalAlignment/Plane %.2i Wire Position Vs XY",i);
35 TH3I *
h = (TH3I *)file->Get(name);
37 TF1 *g =
new TF1(
"g",
"gaus", -0.5, 0.5);
38 TH2D *result =
new TH2D(Form(
"Plane %.2i residual", i),
"residual", 100, -50., 50., 100, -50., 50.);
39 resultHists[i-1]=result;
40 for (
int iX=2; iX <= h->GetNbinsX(); iX++){
41 for (
int iY=2; iY <= h->GetNbinsY(); iY++){
43 if (iX > 45 && iX < 55 && iY > 42 && iY < 58) {
44 result->SetBinContent(iX,iY, -1./0.0);
48 if(iY==25 && iX%5 ==0) name = Form(
"Proj bin (%i,%i)",iY,iX);
50 TH1D * zProj = h->ProjectionZ(name,iX-1, iX, iY-1, iY);
51 if (zProj->GetEntries() < 5) {
52 result->SetBinContent(iX,iY, -1./0.0);
55 double max = zProj->GetBinCenter(zProj->GetMaximumBin());
56 g->SetParameter(1, max);
57 TFitResultPtr r = zProj->Fit(
"g",
"Q",
"", max - 0.02, max + 0.02 );
59 double mean = g->GetParameter(1);
60 double err = g->GetParError(1);
61 result->SetBinContent(iX,iY,mean);
62 result->SetBinError(iX,iY,err);
64 else result->SetBinContent(iX,iY, -1./0.0);
69 result->Fit(
"plane",
"M+rob=0.90");
71 double c0 = f->GetParameter(0);
72 double c1 = f->GetParameter(1);
73 double c2 = f->GetParameter(2);
76 double deltaU = sinPhiUmPhiV*c0/sinPhiV;
77 double deltaV = -sinPhiUmPhiV*c0/sinPhiU;
78 double a = -sinPhiU*sinPhiV/sinPhiUmPhiV;
80 double c = cosPhiU*sinPhiV/sinPhiUmPhiV;
81 double d = -cosPhiV*sinPhiU/sinPhiUmPhiV;
83 double deltaPhiU = (c1/b-c2/d)/(a/b-c/d);
84 double deltaPhiV = (c1/a-c2/
c)/(b/a-d/c);
86 cout <<
" Current Iteration shift plane " << i <<
" deltaU " << -deltaU <<
" deltaPhiU " << -deltaPhiU <<
" deltaPhiV " << -deltaPhiV << endl;
87 constantsFile << i_deltaPhiU - deltaPhiU <<
" " << i_deltaU - deltaU <<
" " << i_deltaPhiV - deltaPhiV <<
" " << i_deltaV << endl;
91 TCanvas *cResult =
new TCanvas(
"cResult",
"cResult",1200,900);
94 for (
int i=0; i<24; i++){
96 resultHists[i]->Draw(
"colz");
97 resultHists[i]->SetMinimum(-0.025);
98 resultHists[i]->SetMaximum(0.025);
101 cResult->SaveAs(
"Result.png");
102 cResult->SaveAs(
"Result.pdf");
107 constantsFile.close();
sprintf(text,"Post KinFit Cut")
void FitCathodeAlignment(TString inputFile="hd_root.root")