REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestDetectorGainMap.cxx
1
2#include "TRestDetectorGainMap.h"
3
4#include "TGraph2D.h"
5#include "TLegend.h"
6#include "TRandom.h"
7#include "TRestDetectorReadout.h"
8#include "TStyle.h"
9#include "TView.h"
10
11using namespace std;
12
13ClassImp(TRestDetectorGainMap);
14
16 // read config from rml section
17}
18
19void TRestDetectorGainMap::DrawChannelGainMap(TRestDetectorReadoutModule* mod) {
20 if (mod == nullptr) {
21 int min = 1e9;
22 int max = 0;
23 auto iter = fChannelGain.begin();
24 while (iter != fChannelGain.end()) {
25 if (max < iter->first) max = iter->first;
26 if (min > iter->first) min = iter->first;
27 iter++;
28 }
29
30 TH1D* h = new TH1D("GainMap", "GainMap", max - min + 2, min - 1, max + 1);
31 iter = fChannelGain.begin();
32 while (iter != fChannelGain.end()) {
33 h->SetBinContent(h->FindBin(iter->first), iter->second);
34 iter++;
35 }
36 h->Draw();
37 } else {
38 double xmin = 0, xmax = mod->GetSize().X(), ymin = 0, ymax = mod->GetSize().Y();
39 cout << xmin << " " << xmax << " " << ymin << " " << ymax << endl;
40
41 TCanvas* c1 = new TCanvas();
42 gStyle->SetPalette(kBlueYellow);
43 c1->SetTheta(90);
44 c1->SetPhi(0);
45
46 TGraph2D* gr = new TGraph2D();
47 // we throw randomly 1000 points to fill the graph
48 TRandom* r = new TRandom();
49 int N = mod->GetNumberOfChannels() * mod->GetNumberOfChannels() / 4;
50 for (int i = 0; i < N; i++) {
51 double x = xmax * (r->Rndm());
52 double y = ymax * (r->Rndm());
53 gr->SetPoint(i, x, y, 1);
54 }
55
56 for (size_t i = 0; i < mod->GetNumberOfChannels(); i++) {
57 TRestDetectorReadoutChannel* channel = mod->GetChannel(i);
58 int id = channel->GetDaqID();
59 if (fChannelGain.count(id) == 0) fChannelGain[id] = 1;
60
61 auto pos = channel->GetPixel(channel->GetNumberOfPixels() / 2)->GetCenter();
62 gr->SetPoint(i + N, pos.X(), pos.Y(), fChannelGain[id]);
63
64 cout << pos.X() << " " << pos.Y() << " " << fChannelGain[id] << endl;
65
66 // pos = channel->GetPixel(channel->GetNumberOfPixels() - 1)->GetCenter();
67 // gr->SetPoint(2 * i + 1, pos.X(), pos.Y(), 1);
68
69 // cout << pos.X() << " " << pos.Y() << " " << 1 << endl;
70 }
71
72 gr->SetPoint(0, xmin, ymin, 1);
73 gr->SetPoint(1, xmin, ymax, 1);
74 gr->SetPoint(2, xmax, ymin, 1);
75 gr->SetPoint(3, xmax, ymax, 1);
76
77 gr->SetTitle(Form("Channel gain map for readout module%i", mod->GetModuleID()));
78
79 gr->SetNpx(mod->GetNumberOfChannels());
80 gr->SetNpy(mod->GetNumberOfChannels());
81 gr->Draw("colz");
82 }
83}
void InitFromConfigFile() override
To make settings from rml file. This method must be implemented in the derived class.
Int_t GetDaqID() const
Returns the corresponding daq channel id.
Int_t GetNumberOfPixels()
Returns the total number of pixels inside the readout channel.
TRestDetectorReadoutPixel * GetPixel(int n)
Returns a pointer to the pixel n by index.
Int_t GetModuleID() const
Returns the module id.
TVector2 GetSize() const
Returns the module size (x, y) in mm.
TRestDetectorReadoutChannel * GetChannel(size_t n)
Returns a pointer to a readout channel by index.
size_t GetNumberOfChannels() const
Returns the total number of channels defined inside the module.