48 const float IDEALMPV=88.5315*2.02/2.59;
50 const float ASCALE=0.176;
52 const bool REBIN_HISTOS=kFALSE;
64 TDirectory *fmain = (TDirectory*)gDirectory->FindObjectAny(
"CDC_amp");
65 if (!fmain)
printf(
"Cannot find directory CDC_amp\n");
70 TH1I *attsum = (TH1I*)fmain->Get(Form(
"a%i_100ns",theta));
71 if (!attsum)
printf(
"Cannot find histogram a%i_100ns\n",theta);
76 TH1I *asum_all= (TH1I*)fmain->Get(
"a");
77 if (!asum_all)
printf(
"Cannot find amplitude (sum over all straws) histogram a\n");
78 if (!asum_all)
return;
82 double highcounts = asum_all->FindLastBinAbove(0);
83 if (highcounts > 512) SCALE_UP = 8;
85 if (SCALE_UP==1) cout <<
"Amp range 0 to 511" << endl;
86 if (SCALE_UP==8) cout <<
"Amp range 0 to 4095" << endl;
94 int INCREMENT_FITSTART;
105 INCREMENT_FITSTART=1;
115 INCREMENT_FITSTART=8;
119 const int MINCOUNTS=1000;
122 gStyle->SetOptFit(1);
123 gStyle->SetFuncWidth(1);
125 TF1 *
f =
new TF1(
"f",
"landau");
128 int a_fitstat,q_fitstat;
136 printf(
"\nattsum fit, tracked hits at 0-100ns, restricted z and theta:\n");
138 a_fitstat = attsum->Fit(f,
"RW");
141 thismpv = f->GetParameter(1);
142 printf(
"\n This mpv: %.3f ideal mpv: %.3f\n",thismpv,IDEALMPV*SCALE_UP);
143 newascale = ASCALE*IDEALMPV*SCALE_UP/thismpv;
144 printf(
"\nnew digi_scales/ascale should be %.3f\n\n",newascale);
147 if (a_fitstat)
printf(
"\nSum histogram fit error, exiting script\n");
148 if (a_fitstat)
return;
151 FILE *
outfile = fopen(
"cdc_new_ascale.txt",
"w");
152 fprintf(outfile,
"%.3f 0.8\n",newascale);
156 TFile *hfile =
new TFile(
"cdc_amphistos.root",
"RECREATE");
161 if (EXIT_EARLY==1) hfile->Write();
162 if (EXIT_EARLY==1) hfile->Close();
163 if (EXIT_EARLY==1)
return;
167 TTree *attstats =
new TTree(
"attstats",
"fit stats for tracked hits with restricted z and theta");
181 attstats->Branch(
"n",&n,
"n/I");
182 attstats->Branch(
"hits",&a_n,
"hits/I");
183 attstats->Branch(
"mean",&a_mean,
"mean/D");
184 attstats->Branch(
"c",&a_c,
"c/D");
185 attstats->Branch(
"mpv",&a_mpv,
"mpv/D");
186 attstats->Branch(
"mpverr",&a_mpverr,
"mpverr/D");
187 attstats->Branch(
"sig",&a_sig,
"sig/D");
188 attstats->Branch(
"chisq",&a_chisq,
"chisq/D");
189 attstats->Branch(
"fitstat",&a_fitstat,
"fitstat/I");
190 attstats->Branch(
"fitlowerlimit",&fitlowerlimit,
"fitlowerlimit/I");
200 int bincont, lastbin, nbins, lastbintocheck;
208 TDirectory *hmain = gDirectory;
210 outfile = fopen(
"cdc_new_wiregains.txt",
"w");
216 gDirectory->mkdir(
"theta")->cd();
218 TDirectory *hsub = gDirectory;
222 anhisto = (TH2I*)fmain->Get(Form(
"an%i_100ns",theta));
229 for (i=1; i<3523; i++) {
234 f->SetRange(fitlowerlimit,AH);
245 ahisto = anhisto->ProjectionY(Form(
"a[%i]",i),i+1,i+1);
247 if (REBIN_HISTOS) ahisto->Rebin(4);
250 sprintf(htitle,
"Amplitude, tracked hits, z=52 to 78 cm, theta=%i to %i degrees, straw %i; amplitude-pedestal",theta_low,theta_high,i);
252 ahisto->SetTitle(htitle);
254 a_n = ahisto->GetEntries();
255 a_mean = ahisto->GetMean();
260 if (a_n > MINCOUNTS) {
261 a_fitstat = ahisto->Fit(f,
"QW",
"",fitlowerlimit,AH);
267 while (a_fitstat==4 && fitlowerlimit<200) {
268 fitlowerlimit += INCREMENT_FITSTART;
269 a_fitstat = ahisto->Fit(f,
"W",
"",fitlowerlimit,AH);
274 a_c = f->GetParameter(0);
275 a_mpv = f->GetParameter(1);
276 a_mpverr = f->GetParError(1);
277 a_sig = f->GetParameter(2);
279 if (f->GetNDF()>0) a_chisq = f->GetChisquare()/f->GetNDF();
281 }
else if (a_fitstat==4){
282 printf(
"straw %i unconverged fit \n",i);
284 }
else if (a_fitstat>0){
285 printf(
"straw %i fitstatus %i fit MPV %f\n",i,a_fitstat,f->GetParameter(1));
287 }
else if (a_fitstat<0){
288 printf(
"straw %i not enough counts \n",i);
296 if (a_fitstat>0) badfit++;
299 if (a_mpv<0)
printf(
"straw %i fit MPV %f\n",i,a_mpv);
300 if (a_mpv>0 && a_mpv<fitlowerlimit)
printf(
"straw %i MPV %f below fit lower limit\n",i,a_mpv);
301 if (a_mpv>0 && a_mean>3.3*a_mpv)
printf(
"straw %i mean %f MPV %f\n",i,a_mean,a_mpv);
307 if (a_mpv>0) wiregain = thismpv/a_mpv;
308 fprintf(outfile,
"%.3f\n",wiregain);
317 printf(
"\nfitstatus 4 count: %i \n",badfit);
318 printf(
"no fit count: %i \n",nofit);
sprintf(text,"Post KinFit Cut")
void CDC_gains(int EXIT_EARLY=0)
printf("string=%s", string)