10 #include "TSpectrum.h"
11 #include "TPolyLine.h"
20 #include "TPolyLine.h"
54 double minR = *min_element(fPads.r.begin(),fPads.r.end());
55 double maxR = *max_element(fPads.r.begin(),fPads.r.end());
56 double minPhi = *min_element(fPads.phi.begin(),fPads.phi.end());
57 double maxPhi = *max_element(fPads.phi.begin(),fPads.phi.end());
59 myR = (minR+
maxR)/2.0;
60 myPhi = (minPhi+
maxPhi)/2.0;
76 int N = fPads.fX.size();
77 TPolyLine* Ziggy =
new TPolyLine(N, &(fPads.fX[0]), &(fPads.fY[0]));
84 Ziggy->SetFillStyle(1001);
85 Ziggy->SetFillColor(18);
94 Ziggy->SetFillColor(CLR);
97 Ziggy->SetLineStyle(1);
98 Ziggy->SetLineWidth(1);
99 Ziggy->SetLineColor(18);
109 string dir( getenv(
"MYCALIB") );
110 string file(
"ZIGZAG_CALIBRATIONS.TXT");
111 string result = dir +
file;
112 cout <<
"Looking to write Zigzag Calibrations in " << result << endl;
113 ofstream fin(result.c_str());
117 cout <<
"Groot could not open the file ZIGZAG_CALIBRATIONS.TXT." << endl;
124 fin << Pedestals[
i] <<
" " << Sigmas[
i] <<
" " << Gains[
i] << endl;
125 cout << Pedestals[
i] <<
" " << Sigmas[
i] <<
" " << Gains[
i] << endl;
132 cout <<
"Reading ZIGZAG calibrations..." << endl;
134 string dir( getenv(
"MYCALIB") );
135 string file(
"ZIGZAG_CALIBRATIONS.TXT");
136 string result = dir +
file;
137 cout <<
"Looking to read Zigzag Calibrations in " << result << endl;
138 ifstream fin(result.c_str());
142 cout <<
"Groot could not open the file ZIGZAG_CALIBRATIONS.TXT." << endl;
143 cout <<
"Please initialize the variable $MYCALIB in your .login." << endl;
144 cout <<
"Then move the ZIGZAG_CALIBRATIONS.TXT file to there." << endl;
145 cout <<
"Here we will make fake calibrations..." << endl;
152 cout <<
"FAKED!" << endl;
156 cout <<
"FOUND! Reading Calibrations..." << endl;
159 fin >> Pedestals[
i] >> Sigmas[
i] >> Gains[
i];
164 cout <<
"DONE." << endl;
171 string method = CommonModeMethod;
175 CommonMode[
i].clear();
182 for (
int j=0;
j<Raw[0].size();
j++)
184 CommonMode[
i].push_back(0);
188 else if (method ==
"median")
190 vector<double> pedheights[
Nhybrid];
193 for (
int i=0;
i<Raw[0].size();
i++)
199 pedheights[q].clear();
208 pedheights[which].push_back(hit);
216 if (pedheights[q].
size()>10)
219 int index = pedheights[q].size()/2;
220 CommonMode[q].push_back(pedheights[q][index]);
224 CommonMode[q].push_back(0);
230 else if (method ==
"gauss" || method ==
"spectrum")
235 sprintf(name,
"commy%02d",
i);
236 commy[
i] =
new TH1D(name,name,40,-330,70);
239 TF1* gss =
new TF1(
"gss",
"[0]*exp(-((x-[1])*(x-[1])/(2*[2]*[2])))", -100, 100);
240 gss->SetParLimits(0,0,128);
241 gss->SetParLimits(1,-330,70);
242 gss->SetParLimits(2,7,40);
244 for (
int i=0;
i<Raw[0].size();
i++)
256 if (commy[
k]->Integral(1,commy[
k]->GetNbinsX())>64)
258 if ( method ==
"gauss" )
260 int bin = commy[
k]->GetMaximumBin();
262 gss->SetParameter(0,commy[
k]->GetBinContent(bin));
263 gss->SetParameter(1,commy[
k]->GetBinCenter(bin));
264 gss->SetParameter(2,17);
265 commy[
k]->Fit(gss,
"WWQM0");
272 CommonMode[
k].push_back(commy[
k]->GetFunction(
"gss")->
GetParameter(1));
277 sprintf(name,
"cmm%d",
k);
278 commy[
k]->Clone(name);
285 int nPeaks = sspec.Search( commy[
k] , 2 ,
"goff" );
287 float peak_max_x = 0;
288 float peak_max_y = 0;
290 float *xpeaks = sspec.GetPositionX();
291 float *ypeaks = sspec.GetPositionY();
293 for (
int peak_j = 0; peak_j < nPeaks; peak_j++ )
296 if ( ypeaks[peak_j] > peak_max_y )
298 peak_max_x = xpeaks[peak_j];
299 peak_max_y = ypeaks[peak_j];
303 CommonMode[
k].push_back( peak_max_x );
310 CommonMode[
k].push_back(0);
323 cerr <<
"ERROR: AZigzag::DetermineCommonMode -> Unknown method " << method << endl;
337 for(
int j=0;
j<Raw[
i].size();
j++)
340 Cal[
i].push_back(Gains[
i]*(Pedestals[
i]-Raw[
i][
j]-CommonMode[which][
j]));
352 for (
int i=0;
i<Cal[myID].size();
i++)
354 if (Cal[myID][
i] > maxq)
377 Pulse =
new TH1D(
"Pulse",
"Pulse", Cal[myID].
size(), -0.5, (
double)Cal[myID].
size()-0.5);
378 blue =
new TF1(
"blue",
"[0]/(exp(-(x-[1])/[2])+1)*exp(-((x-[1])^2/[3]))", 0, 30);
381 blue->FixParameter(2,0.42);
382 blue->FixParameter(3,53.7);
390 for (
int i=0;
i<Cal[myID].size();
i++)
392 Pulse->SetBinContent(
i+1,Cal[myID][
i]);
393 Pulse->SetBinError(i+1,Sigmas[myID]);
395 double max = Pulse->GetBinContent(Pulse->GetMaximumBin());
396 double min = Pulse->GetBinContent(Pulse->GetMinimumBin());
397 double t0 = Pulse->GetBinCenter(Pulse->GetMaximumBin())-2.0;
399 blue->SetParameter(0,max);
400 blue->SetParameter(1,(Mintime+Maxtime)/2.0);
404 double AFACTOR = 0.933;
405 blue->SetParLimits(0, min/AFACTOR-2.0*Sigmas[myID], max/AFACTOR+2.0*Sigmas[myID]);
406 blue->SetParLimits(1, Mintime, Maxtime);
408 Pulse->Fit(
blue,
"Q0");
410 q =
blue->GetParameter(0)*AFACTOR;
411 t =
blue->GetParameter(1);