Commit 5dc6f938 authored by Vratislav Chudoba's avatar Vratislav Chudoba

A few macros related to calibration at 4.7 pF added.

parent 430fd149
#include <iostream>
#include <vector> // std::vector
#include <algorithm>
using namespace std;
void calTransition47()
{
//input files
TString inHistFile = "objects/histOutput47.root";
TString inCalParFile = "../parameters/cal1e_HV1000.par";
TString inHalfVoltPosFile = "parameters/halfVoltPositions680.par";
//output file
TString outPosFile = "parameters/threeVoltPositions47.par";
TString outCalFile = "parameters/cal1e_47_HV1000.par";
TFile *fr = new TFile(inHistFile.Data());
if (fr->IsZombie()) {
Error("calTransition47.cxx", "File %s was not open correctly.", inHistFile.Data());
return;
}
ifstream inCalFile;
inCalFile.open(inCalParFile.Data());
if (!inCalFile.is_open()) {
Error("calTransition47.cxx", "File with input parameters %s was not open.", inCalParFile.Data());
return;
}
Info("calTransition47.cxx", "File with 680 pF calpars %s will be loaded.", inCalParFile.Data());
ifstream inHalfVoltFile;
inHalfVoltFile.open(inHalfVoltPosFile.Data());
if (!inHalfVoltFile.is_open()) {
Error("cal1ePeaks.cxx", "File with input parameters %s was not open.", inHalfVoltPosFile.Data());
return;
}
Info("calTransition47.cxx", "File with 0.5 V positions %s will be loaded.", inHalfVoltPosFile.Data());
//output files
ofstream calPosFile;
calPosFile.open(outPosFile.Data());
if (calPosFile.is_open()) {
Info("calTransition47.cxx", "Positions of 0.5V peak will be saved in %s.", outPosFile.Data());
} else {
Error("calTransition47.cxx", "File %s was not open.", outPosFile.Data());
return;
}
ofstream calFile;
calFile.open(outCalFile.Data());
if (calFile.is_open()) {
Info("calTransition47.cxx", "Positions of 0.5V peak will be saved in %s.", outCalFile.Data());
} else {
Error("calTransition47.cxx", "File %s was not open.", outCalFile.Data());
return;
}
TH1D *hch[64];
TGraph *gr[64];
TString hName;
for (Int_t i = 0; i <64; i++) {
hName.Form("ch%d", i);
hch[i] = (TH1D*)fr->Get(hName.Data());
}
TString cName;
TString cTitle;
TCanvas *cWork[11];
for (Int_t i = 0; i < 11; i++) {
cWork[i] = new TCanvas();
cName.Form("can%d", i);
cTitle.Form("canvas %d", i);
cWork[i]->SetName(cName.Data());
cWork[i]->SetTitle(cTitle.Data());
cWork[i]->Divide(2, 3);
cWork[i]->cd(1);
}
Double_t x, y;
Double_t relHight = 0.5;
string line;
Int_t ch = 0;
Double_t calPar = 0.;
Double_t halfVoltPos = 0.;
for (Int_t i = 0; i < 64; i++) {
hch[i]->GetXaxis()->SetRangeUser(100, 800);
Int_t cNumber = i/6;
cWork[cNumber]->cd(i-6*cNumber+1);
hch[i]->Draw();
hch[i]->ShowPeaks(2., "", relHight);
TList *functions = hch[i]->GetListOfFunctions();
TPolyMarker *pm = (TPolyMarker*)functions->FindObject("TPolyMarker");
const Int_t noPeaks = pm->GetN();
if (noPeaks != 1) {
Error("calTransition47.cxx", "%d peaks found in hist %s", noPeaks, hch[i]->GetName());
continue;
}
// Info("calTransition47.cxx", "%d peak found in hist %s", noPeaks, hch[i]->GetName());
Double_t *energy = pm->GetX();
calPosFile << i << "\t" << energy[0] << endl;
std::getline(inCalFile, line);
std::istringstream(line,ios_base::in) >> ch >> calPar;
std::getline(inHalfVoltFile, line);
std::istringstream(line,ios_base::in) >> ch >> halfVoltPos;
// cout << i << "\t" << energy[0] << "\t" << calPar << "\t\t" << halfVoltPos << endl;
cout << energy[0]*calPar / (6*halfVoltPos) << endl;
calFile << i << "\t" << energy[0]*calPar / (6*halfVoltPos) << endl;
}
calFile.close();
inCalFile.close();
inHalfVoltFile.close();
// fr->Close();
return;
}
void extract1DHists47()
{
//output in channel units
TString outputFile = "objects/histOutput47.root";
TString histName = "adcAllWoBaseline";
TString location = "../data/WPT_tests";
// TString suffix = "";
//// TString suffix = "_HV1000";
TString f0, f1;
f0.Form("%s/4.7nF_11okt_chargeCalib/TestTriggerMode_chargeCalib_3V_100ns_4.7nF_11oct_0000.root", location.Data());
f1.Form("%s/4.7nF_11okt_chargeCalib/TestTriggerMode_chargeCalib_3V_100ns_4.7nF_11oct_0001.root", location.Data());
TFile *fr0 = new TFile(f0.Data());
TFile *fr1 = new TFile(f1.Data());
if (fr0->IsZombie() || fr1->IsZombie()) {
Error("extract1DHists47.cxx", "One of files was not open.");
return;
}
TH2D *hraw0 = (TH2D*)fr0->Get(histName.Data());
TH2D *hraw1 = (TH2D*)fr1->Get(histName.Data());
TH2D *hSum = new TH2D(*hraw0);
hSum->Add(hraw1);
TCanvas *c1 = new TCanvas();
c1->Divide(2,2);
c1->cd(1);
hSum->GetXaxis()->SetRangeUser(0, 64);
hSum->Draw();
c1->cd(2);
TFile *fw = new TFile(outputFile.Data(), "RECREATE");
TH1D *hch[64];
for (Int_t i = 0; i < 64; i++) {
hch[i] = extractHist(hSum, i);
fw->cd();
hch[i]->Write();
}
fw->Close();
return;
}
TH1D* extractHist(TH2D *hInput, Int_t channel) {
TH1D *hTemp;
TString hName;
TString hTitle;
hName.Form("ch%d", channel);
hTitle.Form("channel %d", channel);
hTemp = hInput->ProjectionY(hName.Data(), channel+1, channel+1);
hTemp->SetTitle(hTitle.Data());
return hTemp;
}
void figures()
{
Bool_t pedestals = 0;
Bool_t nlCorr = 0;
Bool_t pedCorr = 1;
if (pedestals) {
TFile *frPed = new TFile("../data/WPT_tests/680pF_7okt/raw_data/TestTriggerMode_680pF_10minutes_7okt_0000.root");
TH2D *hPedRaw = (TH2D*)frPed->Get("adcAll");
TH2D *hPedA = (TH2D*)frPed->Get("adcAllWoBaseline");
TCanvas *c1 = new TCanvas("c1", "Pedestals raw");
hPedRaw->GetXaxis()->SetRangeUser(0, 64);
hPedRaw->GetXaxis()->SetTitle("PMT pixel");
hPedRaw->GetYaxis()->SetTitle("A_{raw}");
hPedRaw->GetYaxis()->SetTitleOffset(1.38);
hPedRaw->Draw();
c1->SaveAs("figures/pedestalsRaw.png");
TCanvas *c2 = new TCanvas("c2", "Pedestals");
hPedA->GetXaxis()->SetRangeUser(0, 64);
hPedA->GetXaxis()->SetTitle("PMT pixel");
hPedA->GetYaxis()->SetTitle("A");
hPedA->GetYaxis()->SetTitleOffset(1.38);
hPedA->Draw();
c2->SaveAs("figures/pedestalsCorr.png");
}
if (nlCorr) {
TFile *frCorr = new TFile("objects/histOutput680.root");
TH1D *hPeaks = (TH1D*)frCorr->Get("ch15");
TCanvas *c3 = new TCanvas("c3", "Voltage on 680pF");
hPeaks->SetAxisRange(100, 2000);
hPeaks->SetXTitle("A");
hPeaks->SetTitleSize(0.06);
hPeaks->SetTitleOffset(0.73);
hPeaks->GetXaxis()->CenterTitle();
hPeaks->SetYTitle("Events");
hPeaks->Draw();
c3->SaveAs("figures/voltageAmplitudes.png");
TFile *frGraph = new TFile("objects/calGraphs680.root");
TGraph *gCorr = (TGraph*)frGraph->Get("gcal15");
TCanvas *c4 = new TCanvas("c4", "Dimensionless correction");
gCorr->GetXaxis()->SetRangeUser(-100, 1800);
gCorr->GetXaxis()->CenterTitle();
gCorr->GetXaxis()->SetTitle("A");
gCorr->GetXaxis()->SetTitleSize(0.06);
gCorr->GetXaxis()->SetTitleOffset(0.76);
gCorr->GetYaxis()->CenterTitle();
gCorr->GetYaxis()->SetTitle("A'");
gCorr->GetYaxis()->SetTitleSize(0.06);
gCorr->GetYaxis()->SetTitleOffset(0.76);
gCorr->SetLineColor(kBlue);
gCorr->SetLineWidth(4);
gCorr->Draw();
c4->SaveAs("figures/calGraph.png");
}
if (pedCorr) {
TFile *frPed = new TFile("../data/WPT_tests/680pF_7okt/raw_data/TestTriggerMode_680pF_10minutes_7okt_0000.root");
TH2D *hPedAnl = (TH2D*)frPed->Get("fhAdcAllWoBaselineNonLinear");
TH2D *hPedAnlCorr = (TH2D*)frPed->Get("fhAdcAllWoBaselineNLcorr");
TCanvas *c5 = new TCanvas("c5", "Position of corrected pedestals");
hPedAnl->GetXaxis()->SetRangeUser(0, 64);
hPedAnl->GetXaxis()->SetTitle("PMT pixel");
hPedAnl->GetXaxis()->CenterTitle();
hPedAnl->GetYaxis()->SetRangeUser(-50, 200);
hPedAnl->GetYaxis()->SetTitle("A'");
hPedAnl->GetYaxis()->SetTitleSize(0.06);
hPedAnl->GetYaxis()->SetTitleOffset(0.8);
hPedAnl->GetYaxis()->CenterTitle();
hPedAnl->Draw("col");
c5->SaveAs("figures/pedestalsNL.png");
TCanvas *c6 = new TCanvas("c6", "Corrected non-linear pedestals ");
// hPedAnlCorr->GetXaxis()->SetRangeUser(0, 64);
hPedAnlCorr->GetXaxis()->SetTitle("PMT pixel");
hPedAnlCorr->GetYaxis()->SetRangeUser(-50, 200);
hPedAnlCorr->GetYaxis()->SetTitle("A*");
hPedAnlCorr->GetYaxis()->SetTitleSize(0.06);
hPedAnlCorr->GetYaxis()->SetTitleOffset(0.8);
hPedAnlCorr->GetYaxis()->CenterTitle();
hPedAnlCorr->Draw("col");
c6->SaveAs("figures/pedestalsNLcorr.png");
}
}
#include <iostream>
using namespace std;
void pedestalsCorrection()
{
TString outPosFile = "parameters/correctedPedsPositions.par";
TString histName = "fhAdcAllWoBaselineNonLinear";
TString location = "../data/WPT_tests";
TString fIn;
fIn.Form("%s/680pF_7okt/raw_data/TestTriggerMode_680pF_10minutes_7okt_0000.root", location.Data());
TFile *fr = new TFile(fIn.Data());
if (fr->IsZombie()) {
Error("pedestalsCorrection.cxx", "Files %s was not open.", fIn.Data());
return;
}
//output files
ofstream calPosFile;
calPosFile.open(outPosFile.Data());
if (calPosFile.is_open()) {
Info("calTransition47.cxx", "Positions of 0.5V peak will be saved in %s.", outPosFile.Data());
} else {
Error("calTransition47.cxx", "File %s was not open.", outPosFile.Data());
return;
}
TH2D *hA = (TH2D*)fr->Get(histName.Data());
TCanvas *c1 = new TCanvas();
c1->Divide(2,2);
c1->cd(1);
hA->GetXaxis()->SetRangeUser(0, 64);
hA->Draw();
c1->cd(2);
TString cName;
TString cTitle;
TCanvas *cWork[11];
for (Int_t i = 0; i < 11; i++) {
cWork[i] = new TCanvas();
cName.Form("can%d", i);
cTitle.Form("canvas %d", i);
cWork[i]->SetName(cName.Data());
cWork[i]->SetTitle(cTitle.Data());
cWork[i]->Divide(2, 3);
cWork[i]->cd(1);
}
TH1D *hch[64];
Double_t x, y;
Double_t relHight = 0.5;
for (Int_t i = 0; i < 64; i++) {
hch[i] = extractHist(hA, i);
hch[i]->GetXaxis()->SetRangeUser(-100, 500);
Int_t cNumber = i/6;
cWork[cNumber]->cd(i-6*cNumber+1);
hch[i]->Draw();
hch[i]->ShowPeaks(2., "", relHight);
TList *functions = hch[i]->GetListOfFunctions();
TPolyMarker *pm = (TPolyMarker*)functions->FindObject("TPolyMarker");
const Int_t noPeaks = pm->GetN();
if (noPeaks != 1) {
Error("calTransition47.cxx", "%d peaks found in hist %s", noPeaks, hch[i]->GetName());
continue;
}
Double_t *energy = pm->GetX();
calPosFile << i << "\t" << energy[0] << endl;
}
calPosFile.close();
return;
}
TH1D* extractHist(TH2D *hInput, Int_t channel) {
TH1D *hTemp;
TString hName;
TString hTitle;
hName.Form("ch%d", channel);
hTitle.Form("channel %d", channel);
hTemp = hInput->ProjectionY(hName.Data(), channel+1, channel+1);
hTemp->SetTitle(hTitle.Data());
return hTemp;
}
void rootlogon()
{
Info("rootlogon.c", "This settings are used to make large canvases");
//gStyle choice
// gROOT->SetStyle("Default");
// gROOT->SetStyle("Plain");
// gROOT->SetStyle("Bold");
// gROOT->SetStyle("Video");
gStyle->SetOptStat("n");
gStyle->SetOptStat("ne");
// gStyle->SetOptStat("");
//canvas size and position
//one panel pictures
// gStyle->SetCanvasDefW(900);
// gStyle->SetCanvasDefH(600);
// gStyle->SetCanvasDefX(800);
// gStyle->SetCanvasDefY(300);
gStyle->SetCanvasDefH(700);
gStyle->SetCanvasDefW(960);
gStyle->SetCanvasDefX(0);
gStyle->SetCanvasDefY(0);
//marker attributes
gStyle->SetMarkerStyle(20);
gStyle->SetMarkerSize(0.1);
gStyle->SetMarkerColor(1);
// gStyle->SetTitleFont(62, "X");
//line attributes
gStyle->SetHistLineWidth(1);
// gStyle->SetHistLineWidth(2);
// gStyle->SetHistLineWidth(3);
gStyle->SetTitleBorderSize(0);
return;
gStyle->SetTitleXSize(0.06);
gStyle->SetTitleYSize(0.06);
return;
gStyle->SetTitleFont(132, "X");
gStyle->SetTitleFont(132, "Y");
gStyle->SetLabelFont(132, "X");
gStyle->SetLabelFont(132, "Y");
gStyle->SetPadTopMargin(0.04);
gStyle->SetPadBottomMargin(0.13);
gStyle->SetPadLeftMargin(0.13);
gStyle->SetPadRightMargin(0.03);
// gStyle->SetTitleOffset(1.3, "Y");
// gStyle->SetLabelSize(0.05, "X");
// gStyle->SetLabelSize(0.05, "Y");
// gStyle->SetTitleSize(0.06, "X");
// gStyle->SetTitleSize(0.06, "Y");
return;
//parameters used for pictures in EXON paper
// gStyle->SetStatBorderSize(0);
// gStyle->SetTitleBorderSize(0);
// gStyle->SetTitleAlign(12);
// gStyle->SetTitleX(0.83);
// gStyle->SetTitleY(0.85);
gStyle->SetTitleX(0.83); //for Fig2
gStyle->SetTitleY(0.9); //for Fig2
gStyle->SetTitleFontSize(0.08);
// gStyle->SetTitleFillColor(0);
// gStyle->SetLineWidth(1);
// gStyle->SetHistLineWidth(1);
gStyle->SetHistLineWidth(3);
gStyle->SetPadTopMargin(0.05);
gStyle->SetPadBottomMargin(0.13);
gStyle->SetPadLeftMargin(0.14);
gStyle->SetPadRightMargin(0.05);
gStyle->SetTitleOffset(1.3, "Y");
gStyle->SetLabelSize(0.05, "X");
gStyle->SetLabelSize(0.05, "Y");
gStyle->SetTitleSize(0.06, "X");
gStyle->SetTitleSize(0.06, "Y");
// gStyle->SetAxisColor(1);
gStyle->SetLabelColor(1, "X");
gStyle->SetLabelColor(1, "Y");
}
//#include "TString.h"
void showHists47()
{
TString location = "../data/WPT_tests";
TString f0, f1;
f0.Form("%s/4.7nF_11okt_chargeCalib/TestTriggerMode_chargeCalib_3V_100ns_4.7nF_11oct_0000.root", location.Data());
f1.Form("%s/4.7nF_11okt_chargeCalib/TestTriggerMode_chargeCalib_3V_100ns_4.7nF_11oct_0001.root", location.Data());
TFile *fr0 = new TFile(f0.Data());
TFile *fr1 = new TFile(f1.Data());
// TH2D *hraw0 = (TH2D*)fr0->Get("cal1eAdcAllWoBaseline");
// TH2D *hraw1 = (TH2D*)fr1->Get("cal1eAdcAllWoBaseline");
TH2D *hraw0 = (TH2D*)fr0->Get("adcAllWoBaseline");
TH2D *hraw1 = (TH2D*)fr1->Get("adcAllWoBaseline");
TCanvas *c1 = new TCanvas();
c1->Divide(2,2);
c1->cd(1);
hraw0->GetXaxis()->SetRangeUser(0, 64);
hraw0->Draw();
c1->cd(2);
hraw1->GetXaxis()->SetRangeUser(0, 64);
hraw1->Draw();
c1->cd(3);
TH2D *hSum = new TH2D(*hraw1);
hSum->Add(hraw0);;
hSum->Draw();
}
0 250.224
1 234.803
2 212.7
3 228.989
4 207.828
5 224.488
6 242.961
7 244.58
8 241.896
9 206.945
10 193.228
11 191.32
12 188.937
13 201.941
14 200.874
15 227.183
16 236.455
17 179.004
18 171.202
19 172.143
20 177.724
21 177.79
22 191.61
23 221.702
24 249.257
25 167.18
26 163.221
27 174.419
28 171.764
29 170.55
30 171.808
31 235.391
32 243.463
33 172.731
34 169.331
35 177.392
36 169.903
37 168.754
38 163.863
39 237.992
40 237.303
41 190.115
42 179.871
43 184.84
44 174.743
45 187.286
46 187.371
47 250.739
48 236.477
49 202.113
50 193.959
51 197.986
52 183.895
53 196.057
54 205.173
55 270.846
56 247.799
57 245.399
58 228.826
59 242.476
60 218.873
61 237.101
62 254.529
63 303.237
0 168.213
1 167.066
2 145.451
3 157.991
4 141.739
5 158.667
6 168.177
7 168.755
8 162.544
9 141.519
10 130.707
11 131.491
12 128.49
13 142.168
14 137.331
15 157.019
16 163.181
17 121.835
18 115.362
19 117.457
20 117.81
21 119.746
22 132.532
23 155.034
24 172.359
25 112.462
26 110.662
27 119.862
28 118.738
29 116.875
30 118.622
31 162.08
32 166.008
33 116.133
34 114.867
35 121.561
36 114.808
37 115.922
38 114.838
39 166.183
40 163.388
41 130.816
42 123.951
43 127.703
44 120.02
45 130.232
46 128.395
47 176.005
48 162.068
49 138.907
50 135.335
51 140.091
52 127.922
53 137.763
54 143.362
55 192.877
56 172.495
57 170.495
58 161.366
59 172.769
60 149.291
61 165.546
62 177.779
63 208.267
0 185 370
1 170 370
2 150 370
3 170 370
4 145 370
5 135 370
6 175 370
7 180 370
8 180 370
9 125 330
10 125 310
11 135 300
12 135 330
13 130 330
14 130 325
15 175 400
16 180 400
17 115 300
18 110 300
19 110 300
20 115 300
21 115 300
22 130 310
23 150 330
24 190 400
25 105 270
26 105 280
27 120 300
28 110 300
29 110 300
30 110 300
31 160 400
32 175 400
33 115 280
34 105 300
35 110 300
36 110 300
37 115 300
38 110 300
39 160 350
40 160 340
41 120 310
42 120 300
43 120 300
44 120 310
45 120 350
46 120 310
47 180 400
48 160 360
49 140 330
50 140 320
51 130 350
52 130 350
53 140 350
54 140 340
55 200 400
56 190 400
57 180 400
58 150 350
59 170 360
60 170 330
61 170 350
62 175 400
63 220 450
0 110 250
1 120 250
2 100 250
3 100 250
4 100 250
5 110 250
6 120 250
7 120 250
8 110 250
9 80 250
10 85 230
11 90 230
12 80 220
13 90 250
14 90 230
15 110 230
16 110 250
17 70 210
18 75 200
19 75 200
20 75 200
21 80 200
22 80 200
23 100 250
24 120 250
25 65 200
26 60 200
27 80 200
28 80 200
29 80 200
30 80 200
31 110 250
32 110 250
33 75 200
34 70 200
35 80 200
36 70 200
37 75 200
38 80 180
39 110 250
40 110 250
41 80 200
42 80 200
43 80 200
44 80 200
45 80 210
46 80 210
47 120 270
48 110 260
49 90 230
50 85 230
51 80 220
52 80 220
53 80 240
54 85 240
55 140 280
56 120 260
57 120 260
58 120 260
59 120 260
60 100 240
61 120 240
62 120 260
63 140 300
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment