Skip to content

Commit

Permalink
save TOF calibration work for future calibrations
Browse files Browse the repository at this point in the history
  • Loading branch information
zihlmann committed Jun 24, 2020
1 parent 1c9672c commit 1aa55fb
Show file tree
Hide file tree
Showing 27 changed files with 3,123 additions and 390 deletions.
4 changes: 3 additions & 1 deletion TOF_calib/DO_CALIB.csh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ set RUN = $1
mkdir calibration$RUN

# do walk correction
root -b -q "src/walk1.C+($RUN)"
root -b -q "src/walk1.C+($RUN)" >& calibration$RUN/walkfit.log
echo "cat walkfit.log:"
cat calibration$RUN/walkfit.log

# do mean time determination
./domeantime.csh $RUN &
Expand Down
53 changes: 53 additions & 0 deletions TOF_calib/findped.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/python


import os,sys,getopt

opts, args = getopt.getopt(sys.argv[1:],"yYP:p:")
OK = 0 # enable actual ccdb command

RunPeriod =0
# check input parameter to verify if you really want to execute the commands
for opt,arg in opts:
if opt in ("-Y","-y"):
OK = 1
if opt in ("-P","-p"):
RunPeriod = int(arg)


if RunPeriod<1:
print "Missing Run Period, has to be specified: -P 7 [6,5,4]"
sys.exit()

# default set to 7
loc = '/cache/halld/home/zihlmann/TOF_calib/fall19/'
loc = '/work/halld2/home/zihlmann/HallD/work/tofcalib/jobs/'

if RunPeriod == 6:
loc = '/cache/halld/home/zihlmann/TOF_calib/spring19/'

if RunPeriod == 5:
loc = '/cache/halld/home/zihlmann/TOF_calib/fall18/'

if RunPeriod == 4:
loc = '/cache/halld/home/zihlmann/TOF_calib/spring18/'

RunList = []
if (RunPeriod<7):
for f in os.listdir(loc):
if f.endswith('.root'):
r = f[11:16]
RunList.append(int(r))
else:
for d in os.listdir(loc):
if d.startswith('Run'):
r = d[3:8]
RunList.append(str(r))

RunList.sort()
for R in RunList:
cmd = 'root -q -b \"src/baseline.C('+str(R)+')\"'
print cmd
if OK:
os.system(cmd)
#sys.exit()
59 changes: 59 additions & 0 deletions TOF_calib/ped2db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/python

# read from directory pedestals/ and create list to write to ccdb

import os,sys,getopt

OK=0

opts, args = getopt.getopt(sys.argv[1:],"yY")
for opt,arg in opts:
if opt in ("-Y","-y"):
OK = 1

loc = 'pedestals/'

R4List = []
R5List = []
R6List = []
R7List = []
for f in os.listdir(loc):
if f.startswith('pedpos_'):
r = int(f[10:15])
if r<50000:
R4List.append(f)
elif r<60000:
R5List.append(f)
elif r<70000:
R6List.append(f)
elif r<80000:
R7List.append(f)

R4List.sort()
R5List.sort()
R6List.sort()
R7List.sort()

Start = 70000
Stop = 79999
cnt = 0
oldf = ''
for f in R7List:
if cnt<1:
oldf = loc+f
cnt += 1
continue
rend = int(f[10:15])
cmd = 'ccdb add -r '+str(Start)+'-'+str(rend)+' TOF2/pedestals '+oldf
print cmd
if OK:
os.system(cmd)
Start = rend
oldf = loc+f
cnt += 1
if cnt == len(R7List):
cmd = 'ccdb add -r '+str(Start)+'-'+str(Stop)+' TOF2/pedestals '+oldf
print cmd
if OK:
os.system(cmd)

99 changes: 99 additions & 0 deletions TOF_calib/src/baseline.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
//
// purpose: determine location of baseline peak to generate a input file
// for ccdb listing the baselines for each PMT of the run being
// analyzed. The input file is tofdata_runXXXXX.root same as
// for the calibration but only using the histogram TOFpedestal

int DEBUG = 0;

void baseline(int R){

string dirloc;
int NPMTS = 176;
string f("tofdata_run");
if (R>69999){
//string s("/cache/halld/home/zihlmann/TOF_calib/fall19/");
string s("/work/halld2/home/zihlmann/HallD/work/tofcalib/jobs/Run");
s += to_string(R)+"/";
dirloc = s;
NPMTS = 184;
} else if (R>56999){
string s("/cache/halld/home/zihlmann/TOF_calib/spring19/");
dirloc = s;
} else if (R>46999){
string s("/cache/halld/home/zihlmann/TOF_calib/fall18/");
dirloc = s;
} else if (R>36999){
string s("/cache/halld/home/zihlmann/TOF_calib/spring18/");
dirloc = s;
} else {
cout<<"run range invalid! BAIL!"<<endl;
return;
}

f += to_string(R)+".root";
if (R>69999){ // special only for this!!!!!
string b("hd_root_tofcalib.root");
f = b;
}
string inf = dirloc+f;
TFile *RF = new TFile(inf.c_str(), "READ");

TH2D *h2d = (TH2D*)RF->Get("TOFcalib/TOFPedestal");
if (!h2d){
cout<<"historgram TOFcalib/TOFPedestal NOT FOUND!"<<endl;
return;
}

double PedPos[200];
for (int n=1; n<(NPMTS+1); n++){

PedPos[n-1] = 100.;

TH1D *h = (TH1D*) h2d->ProjectionY("pj",n,n);
if (h->GetEntries()<1000){
continue;
}
int maxbin = h->GetMaximumBin();
int nbins = h->GetXaxis()->GetNbins();

if ((maxbin>nbins-10)||(maxbin<10)){
continue;
}
double pos,w;
pos = h->GetBinCenter(maxbin);
w = h->GetBinWidth(maxbin);
//cout<<n<<" " << pos<<" "<<w<<" "<<maxbin<<endl;
h->Fit("gaus","Q","R", pos-5*w, pos+3*w);
TF1 *f1 = h->GetFunction("gaus");
pos = f1->GetParameter(1);
w = f1->GetParameter(2);
h->Fit("gaus","Q","R", pos-4.*w, pos+2.*w);
f1 = h->GetFunction("gaus");
pos = f1->GetParameter(1);
w = f1->GetParameter(2);

//cout<<" "<<pos<<" / "<<w<<endl;

PedPos[n-1] = pos/4.;

if (DEBUG>1){
h->Draw();
gPad->SetGrid();
gPad->Update();
sleep(1);
}

}

char of[128];
sprintf(of, "pedestals/pedpos_run%d.dat",R);
ofstream OUTF;
OUTF.open(of,std::ofstream::out);
for (int n=0; n<NPMTS; n++){
OUTF<<PedPos[n]<<endl;
}
OUTF.close();

}

Loading

0 comments on commit 1aa55fb

Please sign in to comment.