Garfield++ v1r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
ViewSignal.cc
Go to the documentation of this file.
1#include <iostream>
2
3#include <TAxis.h>
4
5#include "Plotting.hh"
6#include "Sensor.hh"
7#include "ViewSignal.hh"
8
9namespace Garfield {
10
12 : m_className("ViewSignal"),
13 m_debug(false),
14 m_sensor(0),
15 m_canvas(0),
16 m_hasExternalCanvas(false),
17 m_hSignal(0),
18 m_gCrossings(0) {
19
21}
22
24
25 if (!m_hasExternalCanvas && m_canvas != 0) delete m_canvas;
26 if (m_hSignal != 0) delete m_hSignal;
27 if (m_gCrossings != 0) delete m_gCrossings;
28}
29
31
32 if (s == 0) {
33 std::cerr << m_className << "::SetSensor:\n";
34 std::cerr << " Sensor pointer is null.\n";
35 return;
36 }
37
38 m_sensor = s;
39}
40
41void ViewSignal::SetCanvas(TCanvas* c) {
42
43 if (c == 0) return;
44 if (!m_hasExternalCanvas && m_canvas != 0) {
45 delete m_canvas;
46 m_canvas = 0;
47 }
48 m_canvas = c;
49 m_hasExternalCanvas = true;
50}
51
52void ViewSignal::PlotSignal(const std::string label) {
53
54 if (m_sensor == 0) {
55 std::cerr << m_className << "::PlotSignal:\n";
56 std::cerr << " Sensor is not defined.\n";
57 return;
58 }
59
60 // Setup the canvas
61 if (m_canvas == 0) {
62 m_canvas = new TCanvas();
63 m_canvas->SetTitle("Signal");
64 if (m_hasExternalCanvas) m_hasExternalCanvas = false;
65 }
66 m_canvas->cd();
67
68 int nBins;
69 double t0, dt;
70 m_sensor->GetTimeWindow(t0, dt, nBins);
71
72 if (m_hSignal != 0) {
73 delete m_hSignal;
74 m_hSignal = 0;
75 }
76 m_hSignal = new TH1D("hSignal", label.c_str(), nBins, t0, t0 + nBins * dt);
77 m_hSignal->SetLineColor(plottingEngine.GetRootColorLine1());
78 m_hSignal->GetXaxis()->SetTitle("time [ns]");
79 m_hSignal->GetYaxis()->SetTitle("signal [fC / ns]");
80
81 double sig = 0.;
82 for (int i = nBins; i--;) {
83 sig = m_sensor->GetSignal(label, i);
84 m_hSignal->SetBinContent(i + 1, sig);
85 }
86
87 if (m_gCrossings != 0) {
88 delete m_gCrossings;
89 m_gCrossings = 0;
90 }
91
92 // Get threshold crossings.
93 const int nCrossings = m_sensor->GetNumberOfThresholdCrossings();
94 if (nCrossings > 0) {
95 m_gCrossings = new TGraph(nCrossings);
96 m_gCrossings->SetMarkerStyle(20);
97 m_gCrossings->SetMarkerColor(plottingEngine.GetRootColorLine1());
98 double time = 0., level = 0.;
99 bool rise = true;
100 for (int i = nCrossings; i--;) {
101 if (m_sensor->GetThresholdCrossing(i, time, level, rise)) {
102 m_gCrossings->SetPoint(i, time, level);
103 }
104 }
105 }
106
107 m_hSignal->Draw("");
108 if (nCrossings > 0) m_gCrossings->Draw("psame");
109 m_canvas->Update();
110}
111}
bool GetThresholdCrossing(const int i, double &time, double &level, bool &rise)
Definition: Sensor.cc:961
int GetNumberOfThresholdCrossings()
Definition: Sensor.hh:103
void GetTimeWindow(double &tstart, double &tstep, int &nsteps)
Definition: Sensor.hh:84
double GetSignal(const std::string label, const int bin)
Definition: Sensor.cc:591
void PlotSignal(const std::string label)
Definition: ViewSignal.cc:52
void SetSensor(Sensor *s)
Definition: ViewSignal.cc:30
void SetCanvas(TCanvas *c)
Definition: ViewSignal.cc:41
PlottingEngineRoot plottingEngine