8 TH1I *
Get1DHistogram(
const char * plugin,
const char * directoryName,
const char * name,
bool print =
true){
10 TString fullName = TString(plugin) +
"/" + TString(directoryName) +
"/" + TString(name);
11 thisFile->GetObject(fullName, histogram);
13 if (print) cout <<
"Unable to find histogram " << fullName.Data() << endl;
19 TH2I *
Get2DHistogram(
const char * plugin,
const char * directoryName,
const char * name){
21 TString fullName = TString(plugin) +
"/" + TString(directoryName) +
"/" + TString(name);
22 thisFile->GetObject(fullName, histogram);
24 cout <<
"Unable to find histogram " << fullName.Data() << endl;
31 TCanvas *canvas =
new TCanvas(name,name, 800, 800);
32 TH2D *
axes =
new TH2D(TString(
"axes") + name, title, 1, -65.0, 65.0, 1, -65.0, 65.0);
33 axes->SetBinContent(1,1,-1.0/0.0);
36 axes->GetZaxis()->SetRangeUser(minScale, maxScale);
38 for(
unsigned int iring=1; iring<=28; iring++){
39 histograms[iring]->GetZaxis()->SetRangeUser(minScale, maxScale);
40 histograms[iring]->SetStats(0);
41 histograms[iring]->Draw(
"same col pol");
51 TFile *outputFile = TFile::Open(
"CDCDeformation_Results.root",
"RECREATE");
55 cout <<
"Unable to open file " <<
filename.Data() <<
"...Exiting" << endl;
62 textFile.open(
"CDC_Deformation.txt");
66 int straw_offset[29] = {0,0,42,84,138,192,258,324,404,484,577,670,776,882,1005,1128,1263,1398,1544,1690,1848,2006,2176,2346,2528,2710,2907,3104,3313};
67 int Nstraws[28] = {42, 42, 54, 54, 66, 66, 80, 80, 93, 93, 106, 106, 123, 123, 135, 135, 146, 146, 158, 158, 170, 170, 182, 182, 197, 197, 209, 209};
68 double radius[28] = {10.72134, 12.08024, 13.7795, 15.14602, 18.71726, 20.2438, 22.01672, 23.50008, 25.15616, 26.61158, 28.33624, 29.77388, 31.3817, 32.75838, 34.43478, 35.81146, 38.28542, 39.7002, 41.31564, 42.73042, 44.34078, 45.75302, 47.36084, 48.77054, 50.37582, 51.76012, 53.36286, 54.74716};
69 double phi[28] = {0, 0.074707844, 0.038166294, 0.096247609, 0.05966371, 0.012001551, 0.040721951, 0.001334527, 0.014963808, 0.048683644, 0.002092645, 0.031681749, 0.040719354, 0.015197341, 0.006786058, 0.030005892, 0.019704045, -0.001782064, -0.001306618, 0.018592421, 0.003686784, 0.022132975, 0.019600866, 0.002343723, 0.021301449, 0.005348855, 0.005997358, 0.021018761};
71 TH2D * Amplitude_view[29];
72 TH2D * Direction_view[29];
73 TH2D * Vertical_view[29];
74 TH2D * Horizontal_view[29];
76 outputFile->mkdir(
"PerRing");
77 outputFile->cd(
"PerRing");
78 for(
unsigned int iring=0; iring<28; iring++){
79 double r_start = radius[iring] - 0.8;
80 double r_end = radius[iring] + 0.8;
81 double phi_start = phi[iring];
82 double phi_end = phi_start + TMath::TwoPi();
85 sprintf(hname,
"Amplitude_view_ring[%d]", iring+1);
86 Amplitude_view[iring+1] =
new TH2D(hname,
"", Nstraws[iring], phi_start, phi_end, 1, r_start, r_end);
87 sprintf(hname,
"Direction_view_ring[%d]", iring+1);
88 Direction_view[iring+1] =
new TH2D(hname,
"", Nstraws[iring], phi_start, phi_end, 1, r_start, r_end);
89 sprintf(hname,
"Vertical_view_ring[%d]", iring+1);
90 Vertical_view[iring+1] =
new TH2D(hname,
"", Nstraws[iring], phi_start, phi_end, 1, r_start, r_end);
91 sprintf(hname,
"Horizontal_view_ring[%d]", iring+1);
92 Horizontal_view[iring+1] =
new TH2D(hname,
"", Nstraws[iring], phi_start, phi_end, 1, r_start, r_end);
96 TF1 *
f1 =
new TF1(
"f1",
"[0] + [1] * TMath::Cos(x + [2])", -3.14, 3.14);
97 f1->SetParLimits(0, 0.5, 1.0);
98 f1->SetParLimits(1, 0.0, 0.35);
100 f1->SetParameters(0.78, 0.0, 0.0);
103 outputFile->mkdir(
"FitParameters");
104 outputFile->cd(
"FitParameters");
107 TH1I *h1_c0 =
new TH1I(
"h1_c0",
"Distribution of Constant", 100, 0.5, 1.0);
108 TH1I *h1_c1 =
new TH1I(
"h1_c1",
"Distribution of Amplitude", 100, 0.0, 0.35);
109 TH1I *h1_c2 =
new TH1I(
"h1_c2",
"Direction of Longest Drift Time", 100, -3.14, 3.14);
110 TH1F *h1_c2_weighted =
new TH1F(
"h1_c2_weighted",
"Distribution of Direction weighted by amplitude", 100, -3.14, 3.14);
111 TH2I *h2_c0_c1 =
new TH2I(
"h2_c0_c1",
"c_{1} Vs. c_{0}; c_{0}; c_{1}", 100, 0.5, 1.0, 100, 0, 0.35);
112 TH2I *h2_c0_c2 =
new TH2I(
"h2_c0_c2",
"c_{2} Vs. c_{0}; c_{0}; c_{2}", 100, 0.5, 1.0, 100, -10, 10);
113 TH2I *h2_c1_c2 =
new TH2I(
"h2_c1_c2",
"c_{2} Vs. c_{1}; c_{1}; c_{2}", 100, 0.0, 0.35, 100, -10, 10);
116 outputFile->mkdir(
"Fits");
117 outputFile->cd(
"Fits");
120 int ring = 1, straw = 1;
122 cout <<
"Entering Fit " << endl;
124 sprintf(folder,
"Ring %.2i", ring);
126 sprintf(strawname,
"Straw %.3i Predicted Drift Distance Vs phi_DOCA", straw);
127 TH2I *thisStrawHistogram =
Get2DHistogram(
"CDCPerStrawReco_Middle",folder,strawname);
129 if (thisStrawHistogram != NULL) {
132 double percentile95[16], percentile97[16], percentile99[16];
133 double binCenter[16];
135 sprintf(name,
"Ring %.2i Straw %.3i", ring, straw);
136 TH1D *extractedPoints =
new TH1D(name, name, 16, -3.14, 3.14);
137 for (
int i = 1; i <= thisStrawHistogram->GetNbinsX() ; i++){
138 TH1D *projY = thisStrawHistogram->ProjectionY(
" ", i, i);
139 binCenter[i-1] = thisStrawHistogram->GetXaxis()->GetBinCenter(i);
140 int nbins = projY->GetNbinsX();
142 int nEntries = projY->GetEntries();
143 if (nEntries == 0)
continue;
144 double errorFraction = TMath::Sqrt(nEntries) / nEntries;
145 double perc95 = 0.95*nEntries, perc97 = 0.97 * nEntries, perc99 = 0.99 * nEntries;
148 for (
int j = 0; j <= nbins; j++){
149 total += projY->GetBinContent(j);
150 if (total > perc99) percentile99[i-1] = projY->GetBinCenter(j);
151 else if (total > perc97) {
152 percentile97[i-1] = projY->GetBinCenter(j);
153 extractedPoints->SetBinContent(i, projY->GetBinCenter(j));
154 extractedPoints->SetBinError(i, errorFraction * projY->GetBinCenter(j));
156 else if (total > perc95) percentile95[i-1] = projY->GetBinCenter(j);
159 f1->SetParameters(0.78, 0.0, 0.0);
160 TFitResultPtr fr = extractedPoints->Fit(f1,
"SR");
161 Int_t fitStatus = fr;
163 double c0 = fr->Parameter(0);
164 double c1 = fr->Parameter(1);
165 double c2 = fr->Parameter(2);
167 while (c2 > TMath::Pi()) c2 -= 2 * TMath::Pi();
168 while (c2 < -1* TMath::Pi()) c2 += 2 * TMath::Pi();
169 h1_c0->Fill(c0); h1_c1->Fill(c1); h1_c2->Fill(-1*c2); h1_c2_weighted->Fill(-1*c2,c1);
170 h2_c0_c1->Fill(c0,c1); h2_c0_c2->Fill(c0,c2); h2_c1_c2->Fill(c1,c2);
171 Amplitude_view[ring]->SetBinContent(straw,1,c1);
172 Direction_view[ring]->SetBinContent(straw,1,-1*c2);
173 Vertical_view[ring]->SetBinContent(straw,1,c1*TMath::Sin(-1*c2));
174 Horizontal_view[ring]->SetBinContent(straw,1,c1*TMath::Cos(-1*c2));
175 textFile << c1 <<
" " << c2 << endl;
178 cout <<
"WARNING: Fit Status "<< fitStatus <<
" for ring " << ring <<
" straw " << straw << endl;
179 textFile <<
"0.0 0.0" << endl;
184 textFile <<
"0.0 0.0" << endl;
189 if(straw > Nstraws[ring-1]){
196 outputFile->mkdir(
"2D");
197 outputFile->cd(
"2D");
199 TCanvas *c_Amplitude =
Plot2DCDC(Amplitude_view,
"c_Amplitude",
"Amplitude of Sinusoid", 0.0, 0.3);
200 TCanvas *c_Direction =
Plot2DCDC(Direction_view,
"c_Direction",
"Direction of #delta", -3.14, 3.14);
201 TCanvas *c_Vertical =
Plot2DCDC(Vertical_view,
"c_Vertical",
"Vertical Projection of Delta", -0.3, 0.3);
202 TCanvas *c_Horizontal =
Plot2DCDC(Horizontal_view,
"c_Horizontal",
"Horizontal Projection of Delta", -0.3, 0.3);
204 c_Amplitude->Write();
205 c_Direction->Write();
206 c_Horizontal->Write();
209 cout <<
"Closing Files..." << endl;
sprintf(text,"Post KinFit Cut")