forked from PMT-Test-Facilities/ptf-analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmpmt_analysis.cpp
More file actions
142 lines (110 loc) · 4.15 KB
/
Copy pathmpmt_analysis.cpp
File metadata and controls
142 lines (110 loc) · 4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/// Analysis of PTF data
///
/// Definitions of terminology used, and associated structures:
///
/// Each input root file has a number of "ScanPoint" events, where each event has
/// several waveforms at a given location.
///
/// class MeanRMSCalc For calculating mean and rms
///
/// class PTFErrorBarAnalysis For calculating the error bar size to use on the waveforms
///
/// struct WaveformFitResult Structure to hold one waveform fit result
///
/// class ScanPoint Holds location of scan point, first entry number in TTree of scan point, and number of waveforms
///
/// class PTFAnalysis For doing analysis of all of the waveforms, and keep track of scan points, store results in TTree
///
///
/// This program takes a PTF scan root file as input.
/// The analysis proceeds in these steps:
/// 1. Determine the uncertainties on the "collected charge" by studying the pedestal
/// of the waveforms in bins 1-20. This part of the analysis produces two kinds of
/// pedestal histograms.
/// 2. Fit the waveforms to gaussians. Each waveform is read in once into a Waveform object,
/// it is then fit to a gaussian using a fitter. Fit results are stored in a TTee that
/// has one entry per scan-point
/// 3. The now filled TTree of fitted waveform parameters is analyzed to make histograms
///
/// Author: Blair Jamieson (Sep. 2019)
/// Update by T. Lindner (June 2020) for mPMT analysis
#include "wrapper.hpp"
#include "WaveformFitResult.hpp"
#include "ScanPoint.hpp"
#include "PTFAnalysis.hpp"
#include "Utilities.hpp"
#include <string>
#include <iostream>
#include <ostream>
#include <fstream>
#include <sstream>
#include <exception>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include "TH1D.h"
#include "TH2D.h"
#include "TFile.h"
#include "TF1.h"
#include "TVirtualFitter.h"
#include "TFitter.h"
#include "TMath.h"
#include "TStyle.h"
#include "Configuration.hpp"
#include "BrbSettingsTree.hxx"
using namespace std;
int main(int argc, char** argv) {
if (argc != 4) {
cerr << "give path to file to read" << endl;
cerr << "usage: ptf_analysis filename.root run_number config_file" << endl;
return 0;
}
std::cout << "Creating utilities " << std::endl;
// Get utilities
Utilities utils;
// Set style
utils.set_style();
// Opening the output root file
string outname = string("mpmt_Analysis_run0") + argv[2] + ".root";
TFile * outFile = new TFile(outname.c_str(), "NEW");
//TFile * outFile = new TFile("ptf_analysis.root", "NEW");
std::cout << "Config file: " << string(argv[3]) << std::endl;
Configuration config;
config.Load(argv[3]);
std::vector<int> active_channels;
std::cout << "Opened config file." << std::endl;
if( !config.Get("mpmt_channel_list", active_channels) ){
cout << "Missing terminal_output parameter from config file." << endl;
exit( EXIT_FAILURE );
}
std::cout << "Number of active channels: " << active_channels.size() << "\nActive channels are: ";
for(unsigned int i = 0; i < active_channels.size(); i++){ std::cout << active_channels[i]<< " ";}
std::cout << std::endl;
vector<int> phidgets = {0, 1, 3};
vector<PTF::PMT> activePMTs;
// Loop over the active channels to do setup.
for(unsigned int i = 0; i < active_channels.size(); i++){
int ch = active_channels[i];
PTF::PMT PMT = {ch,ch,PTF::mPMT_REV0_PMT};
activePMTs.push_back(PMT);
}
vector<PTF::Gantry> gantries = {PTF::Gantry0, PTF::Gantry1};
Wrapper wrapper = Wrapper(1, 1024, activePMTs, phidgets, gantries,mPMT_DIGITIZER);
std::cout << "Open file: " << std::endl;
wrapper.openFile( string(argv[1]), "scan_tree");
cerr << "Num entries: " << wrapper.getNumEntries() << endl << endl;
cout << "Points ready " << endl;
// Open the BRB Settings tree
wrapper.LoadBrbSettingsTree();
for(unsigned int i = 0; i < active_channels.size(); i++){
PTF::PMT pmt = activePMTs[i];
PTFAnalysis *analysis = new PTFAnalysis( outFile, wrapper, 2.1e-3, pmt, string(argv[3]), true );
if(i == 0) analysis->write_scanpoints();
}
outFile->Write();
outFile->Close();
cout << "Done" << endl;
return 0;
}