Skip to content
Snippets Groups Projects
Commit 83df5391 authored by Chao's avatar Chao
Browse files

move timing cut to configuration, add LAPPD test configuration

parent e9f9a0b6
No related branches found
No related tags found
No related merge requests found
File moved
# timing information
# Channel name (need to be consistent with channel configuration), tdiff_center, tdiff_sigma
Cer0, -52.9091, 1.83442
Cer1, -59.0365, 9.50290
Cer2, -62.6354, 5.76648
Cer3, -63.0395, 2.02471
Cer4, -63.9112, 1.40395
Cer5, -64.1128, 1.30344
Cer6, -64.2142, 1.14487
Cer7, -60.8445, 1.21787
Cer8, -63.6743, 1.14452
Cer9, -63.1386, 1.47852
Cer10, -63.1737, 1.77535
Cer11, -62.1449, 1.95246
Cer12, -63.4090, 2.22384
Cer13, -64.2145, 2.39562
Cer14, -64.1233, 2.84946
Cer15, -49.5454, 9.40721
# configuration of DAQ modules
# Module { crate, slot, mod_type, Channels { id, name, ch_type } }
Module
{
crate = 1
slot = 6
type = FADC250
Channels
{
0, Cer0, Signal
1, Cer1, Signal
2, Cer2, Signal
3, Cer3, Signal
4, Cer4, Signal
5, Cer5, Signal
6, Cer6, Signal
7, Cer7, Signal
8, Cer8, Signal
9, Cer9, Signal
10, Cer10, Signal
11, Cer11, Signal
12, Cer12, Signal
13, Cer13, Signal
14, Cer14, Signal
15, Cer15, Signal
}
}
Module
{
crate = 1
slot = 7
type = FADC250
Channels
{
0, Calo2, Trigger
1, Calo3, Trigger
2, Calo4, Trigger
3, Calo5, Trigger
4, CaloSum, Trigger
7, LED, Trigger
11, Ref, Reference
12, ScintLR, Trigger
13, ScintLL, Trigger
14, ScintUR, Trigger
15, ScintUL, Trigger
}
}
# timing information
# Channel name (need to be consistent with channel configuration), tdiff_center, tdiff_sigma
Cer0, -13.0577, 1.32406
Cer1, -20.4277, 1.11184
Cer2, -25.8797, 1.45122
Cer3, -23.6766, 1.16813
Cer4, -24.9642, 1.76586
Cer5, -24.9211, 2.03816
Cer6, -17.6479, 1.22267
Cer7, -21.5343, 1.29963
Cer8, -21.1516, 0.849855
Cer9, -23.0179, 1.03700
Cer10, -23.0198, 1.10479
# Cer10, -24.5276, 0.252716
Cer11, -20, 1
Cer12, -22.4998, 1.17782
Cer13, -22.4566, 1.10258
Cer14, -24.4677, 0.766796
# Cer14, -25.0074, 0.299377
Cer15, -23.3521, 1.22068
# Cer15, -24.7613, 0.329350
......@@ -16,8 +16,10 @@
std::vector<Module> read_modules(const std::string &path);
std::unordered_map<std::string, std::vector<float>> read_timing(const std::string &path);
void write_raw_data(const std::string &dpath, const std::string &opath, int nev, const std::vector<Module> &modules);
void process_data(const std::string &dpath, const std::string &opath, int nev, const std::vector<Module> &modules);
void process_data(const std::string &dpath, const std::string &opath, int nev, const std::vector<Module> &modules,
std::unordered_map<std::string, std::vector<float>> timing, float nsig);
int main(int argc, char* argv[])
......@@ -26,13 +28,17 @@ int main(int argc, char* argv[])
ConfigOption conf_opt;
conf_opt.AddOpts(ConfigOption::help_message, 'h', "help");
conf_opt.AddOpt(ConfigOption::arg_require, 'n');
conf_opt.AddOpt(ConfigOption::arg_require, 'c');
conf_opt.AddLongOpt(ConfigOption::arg_require, "config-module", 'm');
conf_opt.AddLongOpt(ConfigOption::arg_require, "config-timing", 't');
conf_opt.AddLongOpt(ConfigOption::arg_none, "raw-output", 'r');
conf_opt.SetDesc("usage: %0 <data_file> <out_dir>");
conf_opt.SetDesc('n', "number of events to process (< 0 means all).");
conf_opt.SetDesc('c', "timing cut factor, default 3 (3 sigmas).");
conf_opt.SetDesc('r', "output raw data instead of processed data.");
conf_opt.SetDesc('m', "configuration file for modules to be read-in, default \"config/module.conf\"");
conf_opt.SetDesc('m', "configuration file for modules to be read-in, default \"config/mapmt_module.conf\"");
conf_opt.SetDesc('t', "configuration file for signal timing to be read-in, default \"config/mapmt_timing.conf\"");
if (!conf_opt.ParseArgs(argc, argv) || conf_opt.NbofArgs() != 2) {
std::cout << conf_opt.GetInstruction() << std::endl;
......@@ -40,18 +46,27 @@ int main(int argc, char* argv[])
}
int nev = -1;
float nsig = 3.;
std::string mconf = "config/mapmt_module.conf";
std::string tconf = "config/mapmt_timing.conf";
bool raw_output = false;
std::string mod_conf = "config/module.conf";
for (auto &opt : conf_opt.GetOptions()) {
switch (opt.mark) {
case 'n':
nev = opt.var.Int();
break;
case 'c':
nsig = opt.var.Float();
break;
case 'r':
raw_output = true;
break;
case 'm':
mod_conf = opt.var.String();
mconf = opt.var.String();
break;
case 't':
tconf = opt.var.String();
break;
default :
std::cout << conf_opt.GetInstruction() << std::endl;
......@@ -59,12 +74,14 @@ int main(int argc, char* argv[])
}
}
auto modules = read_modules(mod_conf);
auto modules = read_modules(mconf);
auto timing = read_timing(tconf);
if (raw_output)
if (raw_output) {
write_raw_data(conf_opt.GetArgument(0), conf_opt.GetArgument(1), nev, modules);
else
process_data(conf_opt.GetArgument(0), conf_opt.GetArgument(1), nev, modules);
} else {
process_data(conf_opt.GetArgument(0), conf_opt.GetArgument(1), nev, modules, timing, nsig);
}
}
......@@ -115,7 +132,7 @@ std::vector<Module> read_modules(const std::string &path)
}
// print out all channels
std::cout << "Read-in modules from \"" << path << "\"." << std::endl;
std::cout << "Read-in " << res.size() << " modules from \"" << path << "\"." << std::endl;
for (auto &mod : res) {
std::cout << "Module: crate = " << mod.crate
<< ", slot = " << mod.slot
......@@ -133,6 +150,28 @@ std::vector<Module> read_modules(const std::string &path)
}
std::unordered_map<std::string, std::vector<float>> read_timing(const std::string &path)
{
std::unordered_map<std::string, std::vector<float>> res;
ConfigParser parser;
std::cout << "Reading channel timing info from \"" << path << "\"." << std::endl;
parser.ReadFile(path);
std::string name;
float center, sigma;
while (parser.ParseLine()) {
parser >> name >> center >> sigma;
if (res.find(name) != res.end()) {
std::cout << "WARNING: Duplicated timing information for channel " << name << std::endl;
}
res[name] = {center, sigma};
std::cout << name << ": (" << center << ", " << sigma << ")" << std::endl;
}
return res;
}
void write_raw_data(const std::string &dpath, const std::string &opath, int nev, const std::vector<Module> &modules)
{
Decoder::THaCodaFile datafile(dpath.c_str());
......@@ -213,46 +252,35 @@ void write_raw_data(const std::string &dpath, const std::string &opath, int nev,
}
std::unordered_map<std::string, std::vector<float>> timing_dist {
{"Cer0", {-13.0577, 1.32406}},
{"Cer1", {-20.4277, 1.11184}},
{"Cer2", {-25.8797, 1.45122}},
{"Cer3", {-23.6766, 1.16813}},
{"Cer4", {-24.9642, 1.76586}},
{"Cer5", {-24.9211, 2.03816}},
{"Cer6", {-17.6479, 1.22267}},
{"Cer7", {-21.5343, 1.29963}},
{"Cer8", {-21.1516, 0.849855}},
{"Cer9", {-23.0179, 1.03700}},
{"Cer10", {-23.0198, 1.10479}},
// {"Cer10", {-24.5276, 0.252716}},
{"Cer11", {-20, 1}},
{"Cer12", {-22.4998, 1.17782}},
{"Cer13", {-22.4566, 1.10258}},
{"Cer14", {-24.4677, 0.766796}},
// {"Cer14", {-25.0074, 0.299377}},
{"Cer15", {-23.3521, 1.22068}},
// {"Cer15", {-24.7613, 0.329350}},
};
void process_data(const std::string &dpath, const std::string &opath, int nev, const std::vector<Module> &modules)
void process_data(const std::string &dpath, const std::string &opath, int nev, const std::vector<Module> &modules,
std::unordered_map<std::string, std::vector<float>> timing, float nsig)
{
Decoder::THaCodaFile datafile(dpath.c_str());
THaEvData *evdata = new Decoder::CodaDecoder();
auto *hfile = new TFile(opath.c_str(), "RECREATE", "MAPMT test results");
std::unordered_map<std::string, std::vector<PulseData>> event;
std::unordered_map<std::string, TH1*> thist, phist;
std::unordered_map<std::string, std::vector<TH1*>> hists;
// initialize histograms and timing
for (auto &mod : modules) {
for (auto &ch : mod.channels) {
if (ch.type != kSignal)
continue;
if (thist.find(ch.name) != thist.end())
if (hists.find(ch.name) != hists.end())
std::cout << "WARNING: Duplicated channel names found! -- " << ch.name << std::endl;
thist[ch.name] = new TH1F((ch.name + "_tdiff").c_str(), (ch.name + "_tdiff").c_str(), 100, -50, -10);
phist[ch.name] = new TH1F((ch.name + "_Pint").c_str(), (ch.name + "_Pint").c_str(), 100, 0, 20000);
hists[ch.name] = {
new TH1F((ch.name + "_tdiff").c_str(), (ch.name + "_tdiff").c_str(), 400, -200, 200),
new TH1F((ch.name + "_tdiff_cut").c_str(), (ch.name + "_tdiff_cut").c_str(), 400, -200, -200),
new TH1F((ch.name + "_Pint").c_str(), (ch.name + "_Pint").c_str(), 100, 0, 20000)
};
if (timing.find(ch.name) == timing.end()) {
std::cout << "WARNING: Cannot find timing information for channel " << ch.name
<< ", using default value (20, 1)" << std::endl;
timing[ch.name] = {20., 1.};
}
}
}
auto trghist = new TH1F("Trigger Timing", "CaloSum Trigger", 100, -200, 200);
......@@ -306,19 +334,23 @@ void process_data(const std::string &dpath, const std::string &opath, int nev, c
int fire = 0;
float sum = 0;
for (auto &it : thist) {
for (auto &it : hists) {
auto hist = it.second;
float integral = 10.;
for (auto &ev : event[it.first]) {
float tdiff = ev.time - trg_time;
// hist->Fill(tdiff);
if ((std::abs(tdiff - timing_dist[it.first][0]) < 3.*timing_dist[it.first][1]) && (ev.integral > integral)) {
// tdiff
hist[0]->Fill(tdiff);
if ((std::abs(tdiff - timing[it.first][0]) < nsig*timing[it.first][1]) &&
(ev.integral > integral)) {
integral = ev.integral;
hist->Fill(tdiff);
// tdiff_cut
hist[1]->Fill(tdiff);
}
}
if (integral > 10.) {
phist[it.first]->Fill(integral);
// pint
hist[2]->Fill(integral);
fire ++;
sum += integral;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment