Skip to content
Snippets Groups Projects
Commit 17f47008 authored by Yero1990's avatar Yero1990 Committed by Eric Pooser
Browse files

Shms dc calib (#138)

* -added script that will output a parameter file with individual tzero values (NOT per ribbon cable as before)

* -included the execution of 'get_tzero_per_wire.param' in steering script.

* -added precicion to the t0 calculation. Although the calculation involved the ratios of two 'doubles', the t0 came out to be an integer. This imprecision was corrected.

* -add minor fix

* added minor fix to read in corrected t0 values

* minor fix

* most up-to-date shms DC param files
parent 1e5adad8
No related branches found
No related tags found
No related merge requests found
......@@ -62,8 +62,9 @@ void run_Cal()
// gSystem->Exec("root -l -q update_pdcparam.C");
//execute code to update parameter file with new t0 values per wire
gSystem->Exec("root -l -q get_tzero_param.C");
//gSystem->Exec("root -l -q get_tzero_param.C");
gSystem->Exec("root -l -q get_tzero_per_wire_param.C");
//execute code to get t0 corrected drift times
gSystem->Exec("root -l -q get_pdc_time_histo_tzero_corrected.C");
......
......@@ -30,7 +30,7 @@ void get_pdc_time_histo_tzero_corrected()
//open and read tzero data file
ifstream file;
file.open("../data_files/"+run+"/tzero_group.dat");
file.open("../data_files/"+run+"/tzero_wire_NEW.dat");
string line;
int counter;
......@@ -46,11 +46,11 @@ void get_pdc_time_histo_tzero_corrected()
{
sscanf(line.c_str(), "%lf", &value); //pass data in file to variable 'value'
tzero_offset[counter] = value; //write all tzero values for all wires in both DC to an array
// cout << tzero_offset[counter] << endl;
//cout << tzero_offset[counter] << endl;
counter++;
}
}
//***************************************************************
......@@ -154,7 +154,7 @@ void get_pdc_time_histo_tzero_corrected()
shift = tzero[ip][sw-1]; //the shift represents how much the drift time histo needs to be offset
//cout << "sw: " << sw << " :: " << "offset: " << shift << endl;
//cout << "sw: " << sw << " :: " << "offset: " << shift << endl;
//************APPLY TZERO OFFSET ON A WIRE-BY-WIRE BASIS TO ALL WIRES IN ALL PLANES***************
......@@ -200,6 +200,6 @@ void get_pdc_time_histo_tzero_corrected()
}
#include <iostream>
#include <fstream>
#include <math.h>
#include <string>
#define NPLANES 12
void get_tzero_per_wire_param()
{
//read run number from input file
int run_NUM;
TString f0 = "input_RUN.txt";
ifstream infile(f0);
infile >> run_NUM;
TString run = Form("run%d", run_NUM);
TString planes[NPLANES] = {"1u1","1u2","1x1","1x2","1v1","1v2","2v2","2v1","2x2","2x1","2u2","2u1"}; //planes 0, 1, 2, 3, 4, 5 OK ::
int fNWires[NPLANES] = {107, 107, 79, 79, 107, 107, 107, 107, 79, 79, 107, 107};
int sw;
int ip;
Int_t **wire = new Int_t*[NPLANES];
Double_t **t0 = new Double_t*[NPLANES];
//Double_t **t0_err = new Double_t*[NPLANES];
//Int_t **entries = new Int_t*[NPLANES];
for (ip = 0; ip < NPLANES; ip++) {
t0[ip] = new Double_t[fNWires[ip]];
for (sw=0; sw<fNWires[ip]; sw++) {
t0[ip][sw] = 0.0;
}
}
//Loop over each plane
for(ip=0; ip<NPLANES; ip++) {
//write plane headers
Int_t nwire;
Double_t nt0;
Double_t nt0_err;
Int_t nentries;
//open and read each wire tzero file
string line;
ifstream input;
input.open(Form("../data_files/run%d/hdc_"+planes[ip]+"tzero_run%d_updated.txt", run_NUM, run_NUM ) );
sw = 0; //se wire counter to 0
while (getline(input, line))
{
if (line != '#')
{
input >> nwire >> nt0 >> nt0_err >> nentries;
// cout << nwire << " :: " << nt0 << endl;
//cout << ip << " :: " << sw << endl;
t0[ip][nwire-1] = nt0;
sw++;
}
}
input.close();
} //end loop over planes
//create output file stream to write tzero values to a data file
ofstream out;
TString tzero_file = "../data_files/"+run+"/tzero_wire_NEW.dat";
out.open(tzero_file);
//Create an output parameter file to store tzero values
ofstream ofs;
TString wire_tzero = Form("../../../PARAM/SHMS/DC/pdc_tzero_per_wire_run%d_NEW.param", run_NUM);
ofs.open (wire_tzero);
for (ip=0; ip<NPLANES; ip++) {
//write plane headers
ofs << "ptzero"+planes[ip] << "=" << endl;
out << "#PLANE: " << planes[ip] << endl;
for (sw=0; sw<fNWires[ip]; sw++) {
out << setprecision(3) << t0[ip][sw] << endl;
if (sw <= 10)
{
ofs << setprecision(3) << t0[ip][sw] << fixed << ",";
}
else if (sw>10 && sw <(fNWires[ip]-1))
{
ofs << setprecision(3) << t0[ip][sw] << ((sw+1) % 16 ? ", " : "\n") << fixed;
}
else if (sw==78 || sw == 106) {
ofs << setprecision(3) << t0[ip][sw] << fixed << endl;
}
}
}
}
......@@ -29,6 +29,7 @@ void get_wire_tzero()
//Declare plane names to loop over
TString plane_names[NPLANES]={"1u1", "1u2", "1x1", "1x2", "1v1", "1v2", "2v2", "2v1", "2x2", "2x1", "2u2", "2u1"};
int fNWires[NPLANES] = {107, 107, 79, 79, 107, 107, 107, 107, 79, 79, 107, 107};
//Declare a root file array to store individual DC cell drift times
TString root_file;
......@@ -233,9 +234,9 @@ void get_wire_tzero()
t_zero = - y_int/m;
t_zero_err = sqrt(y_int_err*y_int_err/(m*m) + y_int*y_int*m_err*m_err/(m*m*m*m) );
entries = cell_dt[sensewire-1]->GetEntries(); //number of entries (triggers) per wire
//cout << "y_int: " << y_int << " :: " << "m: " << m << " :: " << "t0: " << setprecision(6) << -y_int/m << endl;
//Write "t0" values to file
ofs << sensewire << " " << t_zero << " " << t_zero_err << " " << entries << endl;
ofs << sensewire << " " << setprecision(6) << -y_int/m << " " << t_zero_err << " " << entries << endl;
//Change to output root file and write fitted histos to file
g->cd();
......@@ -243,7 +244,7 @@ void get_wire_tzero()
}
// Make Plot of t0 versus Wire Number
/* // Make Plot of t0 versus Wire Number
TCanvas *t = new TCanvas("t", "", 2000,500);
t->SetGrid();
......@@ -266,12 +267,12 @@ void get_wire_tzero()
t->Write(title); //write to a root file
//close dat file
ofs.close();
//save plots
//TString tzero_plots = "plots/"+run_NUM +"/hdc"+plane_names[ip]+Form("TESTING_tzero_v_wire_%d.eps", run);
//t->SaveAs(tzero_plots);
*/
ofs.close();
//*****************************************************************************************//
// CALCULATE THE "t0s" WEIGHTED AVERAGE FOR WIRE DRIFT TIMES WITH ENTRIES > = 300 //
//*****************************************************************************************//
......@@ -293,6 +294,9 @@ void get_wire_tzero()
double weighted_AVG;
double weighted_AVG_err;
int counter;
double t0_corr;
double t0_corr_err;
//set them to zero to start sum inside while loop
sum_NUM = 0.0;
sum_DEN = 0.0;
......@@ -300,21 +304,27 @@ void get_wire_tzero()
weighted_AVG =0.0 ;
weighted_AVG_err= 0.0;
counter = 0;
//read line bt line the t_zero_file
while(getline(ifs, line)) {
if(!line.length()|| line[0] == '#')
continue;
// sensewire = 0, t_zero = 0.0, t_zero_err = 0.0, entries = 0 ; //set values to zero
sscanf(line.c_str(), "%d %d %lf %d", &sensewire, &t_zero, &t_zero_err, &entries); //assign each of the variables above a data in the t_zero_file
if(line!='#') {
sscanf(line.c_str(), "%d %lf %lf %d", &sensewire, &t0_corr, &t0_corr_err, &entries); //assign each of the variables above a data in the t_zero_file
if(sensewire<=fNWires[ip]){
//Check if entries for each sensewire exceeds a certain number of events
if (entries>300 && t_zero < 30) {
if (entries>300 && t_zero < 30)
{
//Calculate the weighted average of t0s
sum_NUM = sum_NUM + t_zero/(t_zero_err*t_zero_err);
sum_DEN = sum_DEN + 1.0/(t_zero_err*t_zero_err);
sum_NUM = sum_NUM + t0_corr/(t0_corr_err*t0_corr_err);
sum_DEN = sum_DEN + 1.0/(t0_corr_err*t0_corr_err);
//cout << "sum_NUM : " << sum_NUM << endl;
//cout << "sum_DEN : " << sum_DEN << endl;
......@@ -322,14 +332,15 @@ void get_wire_tzero()
ofs << sensewire << " " << t_zero << " " << t_zero_err << " " << entries << endl;
ofs << sensewire << " " << t0_corr << " " << t0_corr_err << " " << entries << endl;
//cout << "TZERO: " << t_zero << endl;
}
else { ofs << sensewire << " " << 0.0 << " " << 0.0 << " " << entries << endl;}
}
} //end if statement
}
......@@ -355,8 +366,8 @@ void get_wire_tzero()
ifs.close();
// Make Plot of t0 versus Wire Number for entries > 300 events
// Make Plot of t0 versus Wire Number for entries > 300 events
/*
TCanvas *t1 = new TCanvas("t1", "", 2000,500);
t1->SetGrid();
......@@ -388,9 +399,9 @@ void get_wire_tzero()
ltx1->DrawLatex(t1->GetUxmax()*0.75,40, Form("Weighted Average = %lf #pm %lf ns", weighted_AVG, weighted_AVG_err) );
t1->Write(title1); //write canvas to a root file
*/
ofs.close(); //close data file
......
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment