2222#include " lardataobj/RawData/raw.h"
2323#include " larcore/Geometry/Geometry.h"
2424
25+ #include " sbndcode/ChannelMaps/TPC/TPCChannelMapService.h"
26+
2527#include " TH2D.h"
2628#include " TStyle.h"
2729#include " TCanvas.h"
2830#include " TLatex.h"
2931#include " TTimeStamp.h"
32+ #include " TLine.h"
33+
34+ #include " hep_hpc/hdf5/File.hpp"
35+ #include " hep_hpc/hdf5/Ntuple.hpp"
36+
37+ using wire_nt_t = hep_hpc::hdf5::Ntuple<float >;
3038
3139using namespace std ;
3240
41+ double calcrms (const vector<short > & adcs){
42+
43+ if (adcs.empty ()) return -100 ;
44+ double x = 0 , x2 = 0 ;
45+ for (auto const & adc: adcs){
46+ x += adc;
47+ x2 += adc*adc;
48+ }
49+ return sqrt (x2/adcs.size () - pow (x/adcs.size (),2 ));
50+ }
51+
3352namespace sbnd {
3453 class OnlineEvd ;
3554}
3655
37-
3856class sbnd ::OnlineEvd : public art::EDAnalyzer {
3957public:
4058 explicit OnlineEvd (fhicl::ParameterSet const & p);
@@ -52,7 +70,7 @@ class sbnd::OnlineEvd : public art::EDAnalyzer {
5270
5371 // Selected optional functions.
5472 void beginJob () override ;
55-
73+ virtual ~OnlineEvd () noexcept ;
5674private:
5775
5876 // Declare member data here.
@@ -61,18 +79,27 @@ class sbnd::OnlineEvd : public art::EDAnalyzer {
6179 int padx;
6280 int pady;
6381 int palette;
82+ TH2D *wibplot;
83+ TH2D *femplot;
84+ bool saveh5;
85+ hep_hpc::hdf5::File hdffile;
86+
6487};
6588
6689
6790sbnd::OnlineEvd::OnlineEvd (fhicl::ParameterSet const & p)
6891 : EDAnalyzer{p}
6992 , fRawDigitModuleLabel {p.get <art::InputTag>(" RawDigitModuleLabel" )}
70- , padx{p.get <int >(" padx" , 1000 )}
71- , pady{p.get <int >(" pady" , 618 )}
93+ , padx{p.get <int >(" padx" , 1000 * 1.1 )}
94+ , pady{p.get <int >(" pady" , 618 * 1.1 )}
7295 , palette{p.get <int >(" palette" , 87 )}
96+ , saveh5{p.get <bool >(" saveh5" , true )}
7397{
7498 // Call appropriate consumes<>() for any products to be retrieved by this module.
7599}
100+ sbnd::OnlineEvd::~OnlineEvd () noexcept
101+ {
102+ }
76103
77104void sbnd::OnlineEvd::analyze (art::Event const & e)
78105{
@@ -84,7 +111,9 @@ void sbnd::OnlineEvd::analyze(art::Event const& e)
84111 TTimeStamp tts (ts.timeHigh (), ts.timeLow ());
85112
86113 // art::ServiceHandle<art::TFileService> tfs;
87-
114+ if (saveh5){
115+ hdffile = hep_hpc::hdf5::File (Form (" r%d_e%d.h5" ,run,event), H5F_ACC_TRUNC );
116+ }
88117 int nbins[3 ] = {1984 , 1984 , 1664 };
89118 for (int i = 0 ; i<6 ; ++i){
90119 int tpc = i/3 ;
@@ -96,7 +125,33 @@ void sbnd::OnlineEvd::analyze(art::Event const& e)
96125 hrawadc[i]->GetYaxis ()->CenterTitle (true );
97126 hrawadc[i]->GetZaxis ()->CenterTitle (true );
98127 }
128+
129+ wibplot = new TH2D (" wibplot" , Form (" Run %d Event %d;FEMB;WIB;RMS" , run, event), 8 *128 , 0 , 8 *128 , 12 , 0 , 12 );
130+ wibplot->SetMaximum (10 );
131+ wibplot->SetMinimum (-1 );
132+ wibplot->GetXaxis ()->CenterTitle (true );
133+ wibplot->GetYaxis ()->CenterTitle (true );
134+ wibplot->GetZaxis ()->CenterTitle (true );
135+ for (int i = 1 ; i<=wibplot->GetNbinsX (); ++i){
136+ for (int j = 1 ; j<=wibplot->GetNbinsY (); ++j){
137+ wibplot->SetBinContent (i, j, -100 );
138+ }
139+ }
140+
141+ femplot = new TH2D (" femplot" , Form (" Run %d Event %d;FEM;TPC Crate;RMS" , run, event), 16 *64 , 0 , 16 *64 , 11 , 0 , 11 );
142+ femplot->SetMaximum (10 );
143+ femplot->SetMinimum (-1 );
144+ femplot->GetXaxis ()->CenterTitle (true );
145+ femplot->GetYaxis ()->CenterTitle (true );
146+ femplot->GetZaxis ()->CenterTitle (true );
147+ for (int i = 1 ; i<=femplot->GetNbinsX (); ++i){
148+ for (int j = 1 ; j<=femplot->GetNbinsY (); ++j){
149+ femplot->SetBinContent (i, j, -100 );
150+ }
151+ }
152+
99153 art::ServiceHandle<geo::Geometry> geo;
154+ art::ServiceHandle<SBND ::TPCChannelMapService> channelMap;
100155
101156 // Get raw digits
102157 auto const & rawdigts = e.getProduct <std::vector<raw::RawDigit>>(fRawDigitModuleLabel );
@@ -109,10 +164,39 @@ void sbnd::OnlineEvd::analyze(art::Event const& e)
109164 int tpc = chids[0 ].TPC ;
110165 int plane = chids[0 ].Plane ;
111166 int wire = chids[0 ].Wire ;
112- // cout<<tpc<<" "<<plane<<" "<<wire<<endl;
167+ // Fill event display
113168 for (unsigned short i = 0 ; i<rawadc.size (); ++i){
114169 hrawadc[plane + 3 *tpc]->Fill (wire, i, rawadc[i] - rd.GetPedestal ());
115170 }
171+ // Calculate rms
172+ double rms = calcrms (rawadc);
173+ if (rms >10 ) rms = 10 ;
174+ auto const & chaninfo = channelMap->GetChanInfoFromOfflChan (ch);
175+ // Fill wib plot
176+ int binx = (chaninfo.WIBCrate -1 )%2 *128 *4 +
177+ chaninfo.FEMBOnWIB * 128 +
178+ chaninfo.FEMBCh + 1 ;
179+ int biny = (1 -(chaninfo.WIBCrate -1 )/2 )*6 +
180+ 5 - (chaninfo.WIB -1 ) + 1 ;
181+ wibplot->SetBinContent (binx, biny, rms);
182+ // Fill fem plot
183+ binx = (chaninfo.FEM -1 )*64 + chaninfo.FEMCh + 1 ;
184+ biny = 11 -chaninfo.FEMCrate + 1 ;
185+ femplot->SetBinContent (binx, biny, rms);
186+ // if (ch == 7163 || ch == 8372){
187+ // cout<<ch<<" "<<binx<<" "<<biny<<" "<<rms<<" "<<chaninfo.FEMCrate<<" "<<chaninfo.FEM<<" "<<chaninfo.FEMCh<<endl;
188+ // }
189+ }
190+
191+ if (saveh5){
192+ wire_nt_t rawwf (hdffile, " rawwf" , {" adc" });
193+ for (int i = 0 ; i<6 ; ++i){
194+ for (int j = 1 ; j<=hrawadc[i]->GetNbinsX (); ++j){
195+ for (int k = 1 ; k<=hrawadc[i]->GetNbinsY (); ++k){
196+ rawwf.insert (hrawadc[i]->GetBinContent (j,k));
197+ }
198+ }
199+ }
116200 }
117201
118202 TLatex t;
@@ -126,17 +210,118 @@ void sbnd::OnlineEvd::analyze(art::Event const& e)
126210 int plane = i%3 ;
127211 hrawadc[i]->Draw (" colz" );
128212 t.DrawLatex (0.01 ,0.01 ,Form (" %d/%d/%d %d:%d:%d UTC" ,
213+ tts.GetDate ()/10000 ,
214+ tts.GetDate ()%10000 /100 ,
215+ tts.GetDate ()%10000 %100 ,
216+ tts.GetTime ()/10000 ,
217+ tts.GetTime ()%10000 /100 ,
218+ tts.GetTime ()%10000 %100 ));
219+ can->Print (Form (" sbnd_run%d_event%d_tpc%d_plane%d.png" ,run,event,tpc,plane));
220+ delete hrawadc[i];
221+ }
222+
223+ wibplot->Draw (" colz" );
224+ wibplot->GetXaxis ()->SetNdivisions (408 ,false );
225+ wibplot->GetYaxis ()->SetNdivisions (112 ,false );
226+ wibplot->GetXaxis ()->SetLabelSize (0 );
227+ wibplot->GetYaxis ()->SetLabelSize (0 );
228+ TLine l1 (0 ,6 ,128 *8 ,6 );
229+ l1.SetLineWidth (2 );
230+ l1.Draw ();
231+ TLine l2 (128 *4 ,0 ,128 *4 ,12 );
232+ l2.SetLineWidth (2 );
233+ l2.Draw ();
234+
235+ TLine *l3[5 ];
236+ TLine *l4[5 ];
237+ for (int i = 0 ; i<5 ; ++i){
238+ l3[i] = new TLine (0 , i+1 , 128 *8 , i+1 );
239+ l3[i]->SetLineWidth (1 );
240+ l3[i]->Draw ();
241+ l4[i] = new TLine (0 , i+7 , 128 *8 , i+7 );
242+ l4[i]->SetLineWidth (1 );
243+ l4[i]->Draw ();
244+ }
245+ TLine *l5[8 ];
246+ for (int i = 0 ; i<8 ; ++i){
247+ if (i%4 ==3 ) continue ;
248+ l5[i] = new TLine ((i+1 )*128 ,0 ,(i+1 )*128 ,12 );
249+ l5[i]->SetLineColor (0 );
250+ l5[i]->SetLineStyle (2 );
251+ l5[i]->SetLineWidth (1 );
252+ l5[i]->Draw ();
253+ }
254+
255+ TLine *l6[32 ];
256+ for (int i = 0 ; i<32 ; ++i){
257+ if (i%4 ==3 ) continue ;
258+ l6[i] = new TLine ((i+1 )*32 ,0 ,(i+1 )*32 ,12 );
259+ l6[i]->SetLineColor (0 );
260+ l6[i]->SetLineStyle (3 );
261+ l6[i]->SetLineWidth (1 );
262+ l6[i]->Draw ();
263+ }
264+
265+ TLatex t2;
266+ // t2.SetTextFont(132);
267+ t2.SetTextSize (0.03 );
268+ for (int i = 0 ; i<8 ; ++i){
269+ t2.DrawLatex (128 *i+60 ,-0.4 ,Form (" %d" ,i%4 ));
270+ }
271+ for (int i = 0 ; i<12 ; ++i){
272+ t2.DrawLatex (-30 ,i+0.4 ,Form (" %d" ,6 -i%6 ));
273+ }
274+ t2.DrawLatex (10 ,11.5 ," SW1" );
275+ t2.DrawLatex (10 +128 *4 ,11.5 ," NW2" );
276+ t2.DrawLatex (10 ,5.5 ," SE3" );
277+ t2.DrawLatex (10 +128 *4 ,5.5 ," NE4" );
278+ t.DrawLatex (0.01 ,0.01 ,Form (" %d/%d/%d %d:%d:%d UTC" ,
129279 tts.GetDate ()/10000 ,
130280 tts.GetDate ()%10000 /100 ,
131281 tts.GetDate ()%10000 %100 ,
132282 tts.GetTime ()/10000 ,
133283 tts.GetTime ()%10000 /100 ,
134284 tts.GetTime ()%10000 %100 ));
135- can->Print (Form (" sbnd_run%d_event%d_tpc%d_plane%d.png" ,run,event,tpc,plane));
136- delete hrawadc[i];
285+ can->Print (" wibrms.png" );
286+
287+ femplot->Draw (" colz" );
288+ femplot->GetXaxis ()->SetNdivisions (116 ,false );
289+ femplot->GetYaxis ()->SetNdivisions (111 ,false );
290+ femplot->GetXaxis ()->SetLabelSize (0 );
291+ femplot->GetYaxis ()->SetLabelSize (0 );
292+ TLine *l7[11 ];
293+ for (int i = 0 ; i<11 ; ++i){
294+ l7[i] = new TLine (0 , i+1 , 16 *64 , i+1 );
295+ l7[i]->SetLineWidth (1 );
296+ l7[i]->Draw ();
137297 }
138-
298+ TLine *l8[15 ];
299+ for (int i = 0 ; i<15 ; ++i){
300+ l8[i] = new TLine ((i+1 )*64 , 0 , (i+1 )*64 , 11 );
301+ l8[i]->SetLineWidth (1 );
302+ l8[i]->SetLineColor (0 );
303+ l8[i]->SetLineStyle (3 );
304+ l8[i]->Draw ();
305+ }
306+ for (int i = 0 ; i<16 ; ++i){
307+ t2.DrawLatex (64 *i+28 ,-0.4 ,Form (" %d" ,i+1 ));
308+ }
309+ for (int i = 0 ; i<11 ; ++i){
310+ t2.DrawLatex (-30 ,i+0.4 ,Form (" %d" ,11 -i));
311+ }
312+ t.DrawLatex (0.01 ,0.01 ,Form (" %d/%d/%d %d:%d:%d UTC" ,
313+ tts.GetDate ()/10000 ,
314+ tts.GetDate ()%10000 /100 ,
315+ tts.GetDate ()%10000 %100 ,
316+ tts.GetTime ()/10000 ,
317+ tts.GetTime ()%10000 /100 ,
318+ tts.GetTime ()%10000 %100 ));
319+ can->Print (" femrms.png" );
320+
321+ delete wibplot;
322+ delete femplot;
139323 delete can;
324+
140325}
141326
142327void sbnd::OnlineEvd::beginJob ()
0 commit comments