Skip to content

Commit 1d492d5

Browse files
committed
feat: fit for the clock frequency
1 parent 38bf9e4 commit 1d492d5

2 files changed

Lines changed: 81 additions & 9 deletions

File tree

bin/qtl-xcharge

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ case $mtd in
7676
clock)
7777
$TIMELINESRC/libexec/run-groovy-timeline.sh $TIMELINESRC/qa-physics/charge_analysis/analyze_clock.groovy $inputFile $outputDir rollover_corr_disabled_$suffix 0
7878
$TIMELINESRC/libexec/run-groovy-timeline.sh $TIMELINESRC/qa-physics/charge_analysis/analyze_clock.groovy $inputFile $outputDir rollover_corr_enabled_$suffix 1
79-
root -b -q $TIMELINESRC/qa-physics/charge_analysis/plot_clock.C'("'$outputDir'", "'rollover_corr_disabled_$suffix'")'
80-
root -b -q $TIMELINESRC/qa-physics/charge_analysis/plot_clock.C'("'$outputDir'", "'rollover_corr_enabled_$suffix'")'
79+
root -b -q $TIMELINESRC/qa-physics/charge_analysis/plot_clock.C'("'$outputDir'", "'rollover_corr_disabled_$suffix'",0)'
80+
root -b -q $TIMELINESRC/qa-physics/charge_analysis/plot_clock.C'("'$outputDir'", "'rollover_corr_enabled_$suffix'",1)'
8181
;;
8282
*)
8383
echo "ERROR: unknown method '$mtd'" >&2
Lines changed: 79 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,84 @@
1-
void plot_clock(TString out_dir, TString suffix) {
1+
void plot_clock(TString out_dir, TString suffix, Int_t do_fit) {
2+
23
TString basename = out_dir + "/clock_" + suffix;
3-
TFile* o = new TFile(basename+".root", "RECREATE");
4+
TFile* out_file = new TFile(basename+".root", "RECREATE");
5+
46
TTree* tr = new TTree("tr", "tr");
57
tr->ReadFile(basename+".dat");
6-
tr->Write();
7-
o->Close();
8+
Long64_t clock_gated, clock_ungated, timestamp;
9+
tr->SetBranchAddress("clock_gated", &clock_gated);
10+
tr->SetBranchAddress("clock_ungated", &clock_ungated);
11+
tr->SetBranchAddress("timestamp", &timestamp);
12+
13+
Long64_t timestamp_max = 0;
14+
Long64_t timestamp_min = 1000e9;
15+
16+
TGraph* gr_g = new TGraph();
17+
TGraph* gr_u = new TGraph();
18+
gr_g->SetName("clock_gated");
19+
gr_u->SetName("clock_ungated");
20+
gr_g->SetTitle("gated clock vs. timestamp");
21+
gr_u->SetTitle("ungated clock vs. timestamp");
22+
gr_g->SetMarkerStyle(kFullCircle);
23+
gr_u->SetMarkerStyle(kFullCircle);
24+
gr_g->SetMarkerColor(kRed);
25+
gr_u->SetMarkerColor(kMagenta);
26+
27+
for(Long64_t e = 0; e < tr->GetEntries(); e++) {
28+
tr->GetEntry(e);
29+
gr_g->AddPoint(timestamp, clock_gated);
30+
gr_u->AddPoint(timestamp, clock_ungated);
31+
timestamp_max = std::max(timestamp, timestamp_max);
32+
timestamp_min = std::min(timestamp, timestamp_min);
33+
}
34+
35+
if(do_fit == 1) {
36+
gr_g->Fit("pol1", "", "", timestamp_min, timestamp_max);
37+
gr_u->Fit("pol1", "", "", timestamp_min, timestamp_max);
38+
39+
auto fun_g = gr_g->GetFunction("pol1");
40+
auto fun_u = gr_u->GetFunction("pol1");
41+
auto slp_g = fun_g->GetParameter(1);
42+
auto slp_u = fun_u->GetParameter(1);
43+
44+
fun_g->SetLineColor(kBlack);
45+
fun_u->SetLineColor(kBlack);
46+
47+
TCanvas* canv = new TCanvas("canv", "canv", 800, 2*600);
48+
canv->Divide(1,2);
49+
canv->GetPad(1)->SetGrid(1,1);
50+
canv->GetPad(2)->SetGrid(1,1);
51+
canv->cd(1);
52+
gr_g->Draw("APE");
53+
fun_g->Draw("SAME");
54+
canv->cd(2);
55+
gr_u->Draw("APE");
56+
fun_u->Draw("SAME");
57+
canv->Write("canv");
58+
59+
auto slp2freq = [] (auto slp) {
60+
auto freq_hz = slp / 4e-9; // convert denominator of `slp` from `timestamp` to `duration [s]`
61+
return freq_hz / 1e6; // convert `Hz` -> `MHz`
62+
};
63+
auto freq_g = slp2freq(slp_g);
64+
auto freq_u = slp2freq(slp_u);
65+
66+
std::cout << "[clock_freq_result]: " << suffix << " " << freq_g << " " << freq_u << "\n";
67+
68+
std::cout << "\n";
69+
std::cout << "===========================\n";
70+
std::cout << "estimated clock frequencies\n";
71+
std::cout << "===========================\n";
72+
std::cout << " gated: " << freq_g << " MHz\n";
73+
std::cout << " ungated: " << freq_u << " MHz\n";
74+
std::cout << "===========================\n";
75+
std::cout << "\n";
76+
}
77+
78+
gr_g->Write("gr_g");
79+
gr_u->Write("gr_u");
80+
tr->Write("tr");
81+
82+
out_file->Close();
883
std::cout << "WROTE " << basename << ".root\n";
9-
std::cout << "Recommended plot commands:" << std::endl;
10-
std::cout << " tr->Draw(\"clock_ungated:timestamp\")" << std::endl;
11-
std::cout << " tr->Draw(\"clock_gated:timestamp\")" << std::endl;
1284
}

0 commit comments

Comments
 (0)