Macro is here , which calculates GAIN of a PMT and draws GAIN vs HV, and then fits GAIN vs HV

to run : root -l āBURNINFitforOnePMT.C(2949)ā

```
using namespace std;
char rootfile[200];
Double_t func(Double_t *x, Double_t *par) {
Int_t n = 10;
Double_t f;
f = par[0]*TMath::Power(x[0],(par[1]*n));
return f;
}
void BURNINFitforOnePMT (Int_t runno) {
Double_t Constant;
Double_t k;
Double_t k_mean;
TH1D *kdist = new TH1D("kdist","k distribution",100,0.5,0.9);
TCanvas *c2 = new TCanvas("c2","k distribution",600,800);
TCanvas *c1 = new TCanvas("c1","Gain vs HV",600,800);
TH2D *GAINHV = new TH2D("h1","GAINvsHV",1000,550,800,1000,0,3000000);
TF1 *fit = new TF1("fit1",func,550,800,2);
sprintf(rootfile,"/Users/core/Desktop/!!!THESIS!!!/PMT ANALYSIS /BURNIN Thesis/BURNINat4HVs/LED_4HVs_ROOTFILES/Run_%d.root",runno);
TFile *f = new TFile(rootfile);
TFile *f1 = new TFile("GAINHVFIT.root","RECREATE");
ifstream in;
in.open("/Users/core/Desktop/!!!THESIS!!!/PMT ANALYSIS /BURNIN Thesis/txt/B904/map.txt",ios::in);
Int_t HV[] = {600,650,700,750};
Int_t qie,ieta,depth;
while(in>>qie>>ieta>>depth) {
if(qie==0001 && ieta==33 && depth==1) {
for(Int_t db=0; db<1; db++) {
for(Int_t hv=0; hv<4; hv++) {
stringstream pedname;
stringstream ledname;
TString HFLEDname;
TString HFPEDname;
HFLEDname.Form("/Analyzer/QIEsSumLED%d_QiECh_%d_DBOX_%d_eta_%d_D_%d",HV[hv],qie,db,ieta,depth);
HFPEDname.Form("/Analyzer/QIEsSumPED%d_QiECh_%d_DBOX_%d_eta_%d_D_%d",HV[hv],qie,db,ieta,depth);
pedname<<HFPEDname;
ledname<<HFLEDname;
TH1F *histled = (TH1F*)f->Get(ledname.str().c_str());
TH1F *histped = (TH1F*)f->Get(pedname.str().c_str());
ledname.str("");
pedname.str("");
if(histled && histped) {
Double_t LEDMEAN;
Double_t PEDMEAN;
Double_t LEDRMS;
Double_t PEDRMS;
LEDMEAN = histled->GetMean();
PEDMEAN = histped->GetMean();
LEDRMS = histled->GetRMS();
PEDRMS = histped->GetRMS();
Double_t TRUEMEAN = LEDMEAN - PEDMEAN;
Double_t TRUERMS = sqrt(pow(LEDRMS,2)-pow(PEDRMS,2));
Double_t NPE = 1.15*(pow(TRUEMEAN,2)/pow(TRUERMS,2));// 1.15+-0.05 = ENF(Excess Noise Factor)
//Double_t NPE = 1.15*(pow(LEDMEAN,2)/pow(LEDRMS,2));
Double_t Charge = NPE*1.6*pow(10,(-19));
Double_t GAIN = (TRUEMEAN*2.6)*pow(10,(-15))/Charge;
//Double_t GAIN = LEDMEAN/NPE;
//Double_t GAIN = LEDMEAN;
if(GAIN>0) {
GAINHV->Fill(HV[hv],GAIN);
GAINHV->SetMarkerColor(2);
GAINHV->SetMarkerStyle(8);
fit->SetParameters(0.000000000000001,0.9);
fit->SetParNames("Constant","k value");
}
}
}
}
c1->cd();
GAINHV->Fit("fit1");
// GAINHV->Draw();
TF1 *fitResults = GAINHV->GetFunction("fit1");
Constant = fitResults->GetParameter(0);
k = fitResults->GetParameter(1);
kdist->Fill(k);
}
}
c2->cd();
kdist->Draw();
k_mean = kdist->GetMean();
cout<<k_mean<<endl;
c2->Write();
c1->Write();
}
```

And rootfile is in the attachment.

And I also notice that the fit result changes as āhistogram bin numberā of TH2D changes ,which is 1000 in the script !?

Run_2949.root (774.1 KB)

Cheers,

Ersel