MiniballSort
Loading...
Searching...
No Matches
CDCalibrator.hh
Go to the documentation of this file.
1#ifndef __CDCALIBRATOR_HH
2#define __CDCALIBRATOR_HH
3
4#include <fstream>
5#include <iostream>
6#include <string>
7#include <sstream>
8#include <vector>
9#include <memory>
10
11#include <TFile.h>
12#include <TTree.h>
13#include <TMath.h>
14#include <TChain.h>
15#include <TH1.h>
16#include <TH2.h>
17#include <TProfile.h>
18#include <TVector2.h>
19#include <TVector3.h>
20#include <TGProgressBar.h>
21#include <TSystem.h>
22#include <TKey.h>
23#include <TCanvas.h>
24#include <TF1.h>
25#include <TROOT.h>
26
27// Settings header
28#ifndef __SETTINGS_HH
29# include "Settings.hh"
30#endif
31
32// Calibration header
33#ifndef __CALIBRATION_HH
34# include "Calibration.hh"
35#endif
36
37// Data packets header
38#ifndef __DATAPACKETS_HH
39# include "DataPackets.hh"
40#endif
41
42
43
45
46public:
47
48 MiniballCDCalibrator( std::shared_ptr<MiniballSettings> myset );
50
51 void SetInputFile( std::vector<std::string> input_file_names );
52 void SetInputFile( std::string input_file_name );
53 void SetInputTree( TTree *user_tree );
54 void SetMBSInfoTree( TTree *user_tree );
55 void SetOutput( std::string output_file_name, bool cWrite = false );
56 void StartFile();
57 void Initialise();
58 void MakeHists();
59 void ResetHists();
60
61 inline void AddCalibration( std::shared_ptr<MiniballCalibration> mycal ){
62 cal = mycal;
63 overwrite_cal = true;
64 };
65 inline void AddProgressBar( std::shared_ptr<TGProgressBar> myprog ){
66 prog = myprog;
67 _prog_ = true;
68 };
69
70 inline void SetPsideTagId( unsigned char id ) { ptag = id; };
71 inline void SetNsideTagId( unsigned char id ) { ntag = id; };
72
73 void CalibratePsides();
74 void CalibrateNsides();
75 bool FindCDChannels( int det, int sec, int side, int strip, int &adc, int &ch );
76 bool FindCDChannels( int det, int sec, int side, int strip, int &sfp, int &board, int &ch );
77
78 unsigned long FillHists();
79 void FillPixelHists();
80
81 inline TFile* GetFile(){ return output_file; };
82 inline void CloseOutput(){
83 std::cout << "Writing output file...\r";
84 std::cout.flush();
85 output_file->Write( nullptr, TObject::kOverwrite );
86 std::cout << "Writing output file... Done!" << std::endl << std::endl;
88 output_file->Close();
89 output_cal.close();
90 };
91 inline void PurgeOutput(){
92 input_tree->Reset();
93 mbsinfo_tree->Reset();
94 output_file->Purge(2);
95 }
96
97
98private:
99
102 TChain *input_tree;
106 std::shared_ptr<DgfData> dgf_data;
107 std::shared_ptr<AdcData> adc_data;
108 std::shared_ptr<FebexData> febex_data;
109 std::shared_ptr<InfoData> info_data;
110
113 std::ofstream output_cal;
114
115 // Do calibration
116 std::shared_ptr<MiniballCalibration> cal;
118
119 // Settings file
120 std::shared_ptr<MiniballSettings> set;
121
122 // Progress bar
123 bool _prog_;
124 std::shared_ptr<TGProgressBar> prog;
125
126 // Check if histograms are made
127 bool hists_ready = false;
128
129 // List of histograms for reset later
130 TList *histlist;
131
132 // Flag to know we've opened a file on disk
134
135 // Build window which comes from the settings file
137
138 // Flags
141
142 // Time variables
144 unsigned long long time_prev, time_min, time_max, time_first;
145
146 // Data variables - generic
147 unsigned char mysfp;
148 unsigned char myboard;
149 //unsigned char mydgf; ///< DGF module number
150 unsigned char myadc;
151 unsigned char mych;
152 unsigned long long mytime;
154 unsigned long long myeventid;
155 unsigned long long preveventid;
156 unsigned long long myeventtime;
157 float myenergy;
158 bool mythres;
159 bool mypileup;
161
162
163 // CD detector specific variables
164 std::vector<float> cd_en_list;
165 std::vector<unsigned int> cd_Q_list;
166 std::vector<unsigned long long> cd_ts_list;
167 std::vector<unsigned char> cd_det_list;
168 std::vector<unsigned char> cd_sec_list;
169 std::vector<unsigned char> cd_side_list;
170 std::vector<unsigned char> cd_strip_list;
171
172 // Tag strips for calibration
173 unsigned char ptag = 0;
174 unsigned char ntag = 0;
175
176 // Reference calibration coefficients
177 double noffset = 0.0;
178 double ngain = 1.0;
179 double poffset = 0.0;
180 double pgain = 1.0;
181
182 // Counters
183 unsigned long hit_ctr;
184 unsigned long n_entries;
185 unsigned long n_mbs_entries;
186
187 // CD histograms
188 std::vector<std::vector<std::vector<TH2F*>>> cd_pen_nen;
189 std::vector<std::vector<std::vector<TH2F*>>> cd_nen_pen;
190 std::vector<std::vector<std::vector<TH2F*>>> cd_pen_nQ;
191 std::vector<std::vector<std::vector<TH2F*>>> cd_nQ_pQ;
192
193
194};
195
196#endif
197
unsigned long long myeventid
MBS event id.
unsigned long long mytime
absolute timestamp
std::shared_ptr< TGProgressBar > prog
unsigned long long time_max
void SetOutput(std::string output_file_name, bool cWrite=false)
unsigned char myboard
febex board number
bool mythres
above threshold?
unsigned long hit_ctr
unsigned char mysfp
sfp number
float myenergy
calibrated energy
unsigned long long preveventid
previous MBS event id
std::vector< unsigned int > cd_Q_list
list of CD uncalibrated energies for ParticleFinder
long myhittime
hit time with respect to event time
unsigned long long time_first
std::vector< std::vector< std::vector< TH2F * > > > cd_pen_nQ
std::ofstream output_cal
void SetNsideTagId(unsigned char id)
MBSInfoPackets * mbs_info
unsigned char myadc
ADC module number.
std::shared_ptr< FebexData > febex_data
bool FindCDChannels(int det, int sec, int side, int strip, int &adc, int &ch)
std::vector< unsigned char > cd_side_list
list of CD side IDs; 0 = p, 1 = n
unsigned long long time_prev
std::vector< std::vector< std::vector< TH2F * > > > cd_pen_nen
bool mypileup
pileup flag?
MiniballCDCalibrator(std::shared_ptr< MiniballSettings > myset)
std::shared_ptr< InfoData > info_data
unsigned long n_entries
void PurgeOutput()
Closes the output files from this class.
unsigned long FillHists()
void AddProgressBar(std::shared_ptr< TGProgressBar > myprog)
unsigned char mych
channel number
void Initialise()
called for every event
std::vector< std::vector< std::vector< TH2F * > > > cd_nQ_pQ
std::shared_ptr< MiniballCalibration > cal
std::vector< unsigned char > cd_det_list
list of CD detector IDs
void SetInputFile(std::vector< std::string > input_file_names)
void SetPsideTagId(unsigned char id)
unsigned long n_mbs_entries
std::vector< float > cd_en_list
list of CD energies for ParticleFinder
std::vector< unsigned char > cd_strip_list
list of CD strip IDs
std::vector< unsigned char > cd_sec_list
list of CD sector IDs
void SetInputTree(TTree *user_tree)
void AddCalibration(std::shared_ptr< MiniballCalibration > mycal)
bool myclipped
clipped flag?
void StartFile()
called for every file
unsigned long long myeventtime
MBS event time.
std::vector< unsigned long long > cd_ts_list
list of CD timestamps for ParticleFinder
std::shared_ptr< MiniballSettings > set
std::shared_ptr< DgfData > dgf_data
MiniballDataPackets * in_data
void SetMBSInfoTree(TTree *user_tree)
std::shared_ptr< AdcData > adc_data
std::vector< std::vector< std::vector< TH2F * > > > cd_nen_pen
unsigned long long time_min
TFile * output_file
Outputs.
TFile * input_file
Input tree.
bool flag_close_event
length of build window in ns
std::shared_ptr< MiniballSettings > myset
Definition mb_sort.cc:123
std::shared_ptr< MiniballCalibration > mycal
Definition mb_sort.cc:126