wavecatcher-analysis
Loading...
Searching...
No Matches
CosmicsBox.cc
Go to the documentation of this file.
1#include "CosmicsBox.h"
2
25void CosmicsBox::Print_Phi_ew(vector<int> phi_chx, vector<float> ly_C0, vector<int> SiPMchannels, float windowmin, float windowmax, float maxfrom, float maxto, int nbins, bool corr, bool periodic) {
26 checkData();
27
28 // plotting uncorrected/corrected phi_ew - spectra ; first: map the phi_i to the channels, like Alex did, but with new channel positions
29 // match channel number to channel index (still very specific)
30 int sipmnum = SiPMchannels.size();
31 vector<int> ch_index; // initialize the ch_index vector
32 for (const auto& channel : SiPMchannels) ch_index.push_back(GetChannelIndex(channel));
33
34 // compute correction factor
35 vector<float> ly_corr;
36 if (corr) {
37 float ly_av = 0;
38 // average lightyield of all channels * sipmnum
39 for (int i = 0; i < sipmnum; i++) ly_av += ly_C0[i];
40 // divide ly of one channel by (1/sipmnum)*sipmnum*average ly of all channels
41 for (int i = 0; i < sipmnum; i++) ly_corr.push_back(sipmnum * ly_C0[i] / ly_av);
42 }
43 else for (int i = 0; i < sipmnum; i++) ly_corr.push_back(1); // no correction
44
45 // print correction factors
46 for (int i = 0; i < sipmnum; i++) cout << "Correction factor for channel " << SiPMchannels[i] << ":" << ly_corr[i] << endl;
47
48 // initialize canvas + histograms
49 gStyle->SetOptStat("emr"); gStyle->SetOptFit(1111); //draws a box with some histogram parameters
50 TString his_name(Form("#phi_ew-spectrum_from_ch%d_to_ch%d", SiPMchannels.front(), SiPMchannels.back()));
51 auto hisc = new TCanvas(his_name, his_name, 600, 400);
52
53 double min_angle = -180, max_angle = 180; // 360 deg plot range
54 if (periodic) { min_angle = -540; max_angle = 540; } // 1080 deg plot range
55 auto his = new TH1F(his_name, his_name, nbins, min_angle, max_angle);
56
57 // loop through all events and compute phi_ew
58 for (int i = 0; i < nevents; i++) {
59 float anglevaluex = 0., anglevaluey = 0., phi_ew = 0.;
60 if (!skip_event[i]) {
61 for (int j = 0; j < sipmnum; j++) { //loop through all SiPM-channels
62 int wf_index = GetWaveformIndex(i, ch_index[j]);
63 if (wf_index < 0) continue;
64 float lightyield = GetPeakIntegral(rundata[wf_index], windowmin, windowmax, maxfrom, maxto, 0); //lightyield as the integral around maximum
65 anglevaluex += cos(phi_chx[j] * TMath::Pi() / 180) * lightyield / ly_corr[j]; //x part of vectorial addition
66 anglevaluey += sin(phi_chx[j] * TMath::Pi() / 180) * lightyield / ly_corr[j]; //y part of vectorial addition
67 }
68
69 phi_ew = atan2(anglevaluey, anglevaluex) * 180 / TMath::Pi(); //vectorial addition for phi_ew --> fill in histo
70 his->Fill(phi_ew);
71 if (periodic) {
72 his->Fill(phi_ew + 360);
73 his->Fill(phi_ew - 360);
74 }
75 }
76 }
77
78 //make histogram fancy + printing
79 his->GetXaxis()->SetTitle("#phi_{ew} [#circ]");
80 his->GetYaxis()->SetTitle("#Entries");
81 his->Draw();
82
83 if (periodic) {
85 int n_par = 4;
86 auto f = new TF1("fitf", fitf, min_angle, max_angle, n_par);
87 f->SetLineColor(2);
88 f->SetNpx(1000);
89
90 double max = his->GetMaximum();
91 double min = his->GetMinimum();
92 his->GetXaxis()->SetRangeUser(-180, 180); //only look at one period for starting values
93 double phi_est = his->GetXaxis()->GetBinCenter(his->GetMaximumBin());
94 his->GetXaxis()->SetRangeUser(0, 0); //reset scale
95
96 f->SetParName(0, "A"); f->SetParameter(0, max - min); f->SetParLimits(0, 1, 1e9);
97 f->SetParName(1, "#bar{#phi_{ew}}"); f->SetParameter(1, phi_est); f->SetParLimits(1, -180, 180);
98 f->SetParName(2, "#sigma"); f->SetParameter(2, 40); f->SetParLimits(2, 5, 360);
99 f->SetParName(3, "offset"); f->SetParameter(3, min); f->SetParLimits(3, TMath::Min(min - 1, 0.1), 1e9);
100
101 TFitResultPtr fresults = his->Fit(f, "LRS");
102 fit_results.push_back(fresults);
103 }
104
105 hisc->Update();
106 root_out->WriteObject(hisc, "Phi_ew");
107 root_out->WriteObject(his, "Phi_ew_his");
108
109 string pdf_name = "phi_ew_spectrum";
110 pdf_name += corr ? "_corr.pdf" : "_uncorr.pdf";
111 hisc->SaveAs(pdf_name.c_str()); //write the histogram to a .pdf-file
112}
void Print_Phi_ew(vector< int >, vector< float >, vector< int >, float=1, float=1, float=100, float=140, int=400, bool=true, bool=false)
Angular distribution of passing particles in the cosmics setup.
Definition CosmicsBox.cc:25
Periodic gauss fit function for angular reconstruction of SiPM array signal (SHiP SBT WOM tube)
int nevents
Number of triggered events in data.
Definition ReadRun.h:282
vector< bool > skip_event
Stores the event numbers which should be skipped in the analysis.
Definition ReadRun.h:332
vector< vector< float > > rundata
Stores waveforms.
Definition ReadRun.h:132
float GetPeakIntegral(TH1F *, float, float, float, float, int=0)
Calculate the integral around a peak with several options explained in GetIntWindow().
Definition ReadRun.cc:1660
int GetChannelIndex(int)
Match channel number (wavecatcher input channel) to channel index.
Definition ReadRun.cc:2788
TFile * root_out
Stores results of analysis.
Definition ReadRun.h:360
virtual int GetWaveformIndex(int, int)
Returns index of a certain event number (if data files are read in parallel threads)
Definition ReadRun.cc:2763
virtual void checkData(bool isBaselineCorrection=false) const
Primitive check to see if data has been loaded.
Definition ReadRun.h:119
vector< TFitResultPtr > fit_results
Stores the fit results of PrintChargeSpectrum() for all channels and all function calls in ascending ...
Definition ReadRun.h:324