Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
wire-cell-build
root
test
test_perchanresp.cxx
Go to the documentation of this file.
1
#include "
WireCellUtil/Units.h
"
2
#include "
WireCellUtil/Testing.h
"
3
#include "
WireCellUtil/Exceptions.h
"
4
5
/// needed to pretend like we are doing WCT internals
6
#include "
WireCellUtil/PluginManager.h
"
7
#include "
WireCellUtil/NamedFactory.h
"
8
#include "
WireCellIface/IChannelResponse.h
"
9
#include "
WireCellIface/IAnodePlane.h
"
10
#include "
WireCellIface/IConfigurable.h
"
11
12
13
#include "TCanvas.h"
14
#include "TStyle.h"
15
#include "TH2F.h"
16
#include "TAxis.h"
17
#include "TFile.h"
18
19
#include <vector>
20
#include <string>
21
#include <algorithm>
22
#include <iostream>
23
24
#include "
anode_loader.h
"
// do not use this
25
26
using namespace
WireCell
;
27
using
WireCell::units::mV
;
28
using
WireCell::units::fC
;
29
using
WireCell::units::us
;
30
31
using namespace
std
;
32
33
int
main
(
int
argc
,
char
*
argv
[])
34
{
35
std::string
detector =
"uboone"
;
36
if
(argc > 1) {
37
detector = argv[1];
38
}
39
auto
anode_tns =
anode_loader
(detector);
40
41
42
// Real component code would get this info from its
43
// configuration.
44
const
std::string
cr_tn =
"PerChannelResponse"
;
45
const
std::string
ap_tn = anode_tns[0];
46
const
std::string
pcr_filename =
"microboone-channel-responses-v1.json.bz2"
;
47
48
49
{
// User code should never do this.
50
auto
icfg = Factory::lookup<IConfigurable>(cr_tn);
51
auto
cfg
= icfg->default_configuration();
52
cfg[
"filename"
] = pcr_filename;
53
icfg->configure(cfg);
54
}
55
56
57
/// Finally, we now pretend to be real component code.
58
auto
cr = Factory::find_tn<IChannelResponse>(cr_tn);
59
auto
ap = Factory::find_tn<IAnodePlane>(ap_tn);
60
61
auto
bins = cr->channel_response_binning();
62
cerr <<
"PerChannelResponse with binning: "
<< bins.nbins() <<
" bins "
63
<<
" with sample period "
<< bins.binsize()/
units::us
<<
" us and bounds:"
64
<<
"["
<< bins.min()/
units::us
<<
","
<< bins.max()/
units::us
<<
"]us\n"
;
65
66
std::vector<int> planechans[3];
// fixme: will break with DUNE
67
for
(
auto
ch : ap->channels()) {
68
auto
wpid = ap->resolve(ch);
69
planechans[wpid.index()].push_back(ch);
70
}
71
72
auto
outfile = TFile::Open(Form(
"%s.root"
, argv[0]),
"RECREATE"
);
73
74
gStyle->SetOptStat(0);
75
TCanvas
c
(
"c"
,
"c"
,500,500);
76
c.Divide(3,1);
77
78
// Desired gain units for showing in the plot
79
const
double
GU =
units::mV
/
units::fC
;
80
81
for
(
int
iplane=0; iplane<3; ++iplane) {
82
auto
&
channels
= planechans[iplane];
83
std::sort(
channels
.begin(),
channels
.end());
84
85
/// assume all responses in a plane are the same size.
86
const
int
nsamps = bins.nbins();
87
const
double
mintus = bins.min()/
units::us
;
88
const
double
maxtus = bins.max()/
units::us
;
89
const
int
nchans =
channels
.size();
90
91
Assert
(nsamps>0);
92
Assert
(nchans>0);
93
94
95
TH2F*
hist
=
new
TH2F(Form(
"hist%d"
, iplane),
96
Form(
"Per Channel Response Plane %d [mV/fC]"
, iplane),
97
nsamps, mintus, maxtus,
98
nchans, 0, nchans
99
);
100
hist->GetXaxis()->SetTitle(
"sample time (us)"
);
101
hist->GetYaxis()->SetTitle(
"channel indices"
);
102
103
for
(
int
ich=0; ich<nchans; ++ich) {
104
const
auto
& resp = cr->channel_response(
channels
[ich]);
105
for
(
int
isamp=0; isamp<nsamps; ++isamp) {
106
const
double
Tus = bins.center(isamp)/
units::us
;
107
hist->Fill(Tus, ich+0.5, resp[isamp]/GU);
108
}
109
}
110
111
c.cd(iplane+1);
112
hist->Draw(
"colz"
);
113
hist->Write();
114
}
115
116
cerr <<
"Now ROOT makes the PDF"
<<
endl
;
117
c.Print(Form(
"%s.pdf"
, argv[0]),
"pdf"
);
118
119
outfile->Close();
120
121
return
0;
122
}
ValidateOpDetSimulation.channels
dictionary channels
Definition:
ValidateOpDetSimulation.py:178
NamedFactory.h
Exceptions.h
string
std::string string
Definition:
nybbler.cc:12
ValidateOpDetSimulation.hist
hist
Definition:
ValidateOpDetSimulation.py:133
std
STL namespace.
IConfigurable.h
IChannelResponse.h
WireCell::units::mV
static const double mV
Definition:
Units.h:180
dbjson.cfg
cfg
Definition:
dbjson.py:29
freeze_graph.argv
argv
Definition:
freeze_graph.py:218
anode_loader
std::vector< std::string > anode_loader(std::string detector)
Definition:
anode_loader.h:35
Assert
#define Assert
Definition:
Testing.h:7
ValidateOpDetSimulation.c
dictionary c
Definition:
ValidateOpDetSimulation.py:53
Testing.h
anode_loader.h
WireCell::units::fC
static const double fC
Definition:
Units.h:113
WireCell
Definition:
Main.h:22
IAnodePlane.h
PluginManager.h
WireCell::units::us
static const double us
Definition:
Units.h:105
test_gen_rays_pdsp.argc
argc
Definition:
test_gen_rays_pdsp.py:6
main
int main(int argc, char *argv[])
Definition:
test_perchanresp.cxx:33
endl
QTextStream & endl(QTextStream &s)
Definition:
qtextstream.cpp:2030
Units.h
Generated by
1.8.11