CbmRoot
Loading...
Searching...
No Matches
CbmRichMCbmToTShifter.cxx
Go to the documentation of this file.
1/* Copyright (C) 2019-2020 Justus-Liebig-Universitaet Giessen, Giessen
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Adrian Amatus Weber [committer] */
4
6
7#include "CbmDigiManager.h"
8#include "CbmDrawHist.h"
9#include "CbmHistManager.h"
10#include "CbmRichConverter.h"
11#include "CbmRichDigi.h"
12#include "CbmRichGeoManager.h"
13#include "CbmRichPoint.h"
14#include "CbmUtils.h"
15#include "TCanvas.h"
16#include "TClonesArray.h"
17#include "TEllipse.h"
18#include "TF1.h"
19#include "TGeoBBox.h"
20#include "TGeoManager.h"
21#include "TGeoNode.h"
22#include "TH1.h"
23#include "TH1D.h"
24#include "TLatex.h"
25#include "TLine.h"
26#include "TMarker.h"
27#include "TMath.h"
28#include "TStyle.h"
29
30#include <TFile.h>
31
32#include <boost/assign/list_of.hpp>
33
34#include <cmath>
35#include <iostream>
36#include <sstream>
37#include <string>
38
39using boost::assign::list_of;
40
42 : FairTask("CbmRichMCbmToTShifter")
43 , fEventNum(0)
44 , fOutputDir("result_ToTOffset")
45 , fhTotMap()
46 , fGeneratePDFs(false)
47 , fShowTdcId(false)
48{
49 std::cout << "CbmRichMCbmToTShifter::Constructor.." << std::endl;
50}
51
53{
54 std::cout << "CbmRichMCbmToTShifter::Init" << std::endl;
55
56 FairRootManager* ioman = FairRootManager::Instance();
57 if (nullptr == ioman) {
58 Fatal("CbmRichMCbmToTShifter::Init", "RootManager not instantised!");
59 }
60
62 fDigiMan->Init();
64 Fatal("CbmRichMCbmToTShifter::Init", "No Rich Digis!");
65 }
66
67 return kSUCCESS;
68}
69
70
71void CbmRichMCbmToTShifter::Exec(Option_t* /*option*/)
72{
73 fEventNum++;
75
76 for (int i = 0; i < nofDigis; ++i) {
77 const CbmRichDigi* digi = fDigiMan->Get<CbmRichDigi>(i);
79 if (h != nullptr) h->Fill(digi->GetToT());
80 }
81}
82
83
85{
86
87 std::cout << "Drawing Hists..." << std::endl;
88 std::stringstream s;
89 Int_t mean_cnt = 0;
90 Double_t mean = 0.;
91 for (auto const& outer : fhTotMap) {
92 for (auto const& inner : outer.second) {
93 mean += static_cast<Double_t>(inner.second->GetEntries());
94 mean_cnt++;
95 }
96 }
97
98 if (mean_cnt != 0) mean /= mean_cnt;
99
100 if (fShowTdcId) s << "TDC 0x" << std::hex << 0xc000 << " " << std::dec << " !";
101 s << printEmpty() << " \\" << std::endl;
102 if (fShowTdcId) s << "TDC 0x" << std::hex << 0xc001 << " " << std::dec << " !";
103 s << printEmpty() << " \\" << std::endl;
104
105 auto it = std::begin(fhTotMap);
106 uint32_t cnt = 0;
107 for (auto const& outer : fhTotMap) {
108 int tdc = outer.first;
109 TCanvas* c = new TCanvas(Form("fhToT_%x", outer.first), Form("fhToT_%x", outer.first), 2000, 2000);
110 c->Divide(6, 6);
111 while (calcDirichAddr(cnt)
112 < static_cast<uint16_t>(tdc)) { // this dirich is not in use; fill up the parameter file with printEmpty
113 if (fShowTdcId) s << "TDC 0x" << std::hex << calcDirichAddr(cnt) << " " << std::dec << " !";
114 s << printEmpty();
115 if (std::next(it) != fhTotMap.end()) s << " \\" << std::endl;
116 cnt++;
117 }
118 if (fShowTdcId) s << "TDC 0x" << std::hex << outer.first << " " << std::dec << " !";
119 s << " 0.00";
120 for (int i = 0; i < 32; ++i) {
121 c->cd(1 + i);
122 TH1* h = GetTotH1(tdc, i + 1);
123 if (h != nullptr) {
124 h->Draw();
125 if (GetMaxH1(h) < 20 || h->GetEntries() < mean * 0.1) {
126 s << " 0.00";
127 }
128 else {
129 s << " " << GetMaxH1(h) - 25.00;
130 }
131 }
132 }
133
134 cnt++;
135
136 if (it == fhTotMap.begin()) {
137 if (fGeneratePDFs) c->Print("ToTs/Tdc_all.pdf(", "pdf");
138 s << " \\" << std::endl;
139 }
140 else if (std::next(it) == fhTotMap.end()) {
141
142 if (fGeneratePDFs) c->Print("ToTs/Tdc_all.pdf)", "pdf");
143 if (cnt == 71) s << std::endl;
144 }
145 else {
146 if (fGeneratePDFs) c->Print("ToTs/Tdc_all.pdf", "pdf");
147 s << " \\" << std::endl;
148 }
149
150 ++it;
151 }
152
153 //fill up till end of SetupSize
154
155 for (uint16_t i = cnt; i < 72; ++i) {
156 s << " \\" << std::endl; // from last output
157
158 if (fShowTdcId) s << "TDC 0x" << std::hex << calcDirichAddr(i) << " " << std::dec << " !";
159 s << printEmpty();
160 }
161
162 std::cout << s.str() << std::endl;
163}
164
165
166TH1* CbmRichMCbmToTShifter::GetTotH1(Int_t tdc, Int_t channel)
167{
168 TH1* h = fhTotMap[tdc][channel];
169 if (h == nullptr) {
170 TString name, title, subFolder;
171 name.Form("ToT_tdc_0x%x_ch%u", tdc, channel);
172 title.Form("%s;ToT [ns];Entries", name.Data());
173 h = new TH1D(name, title, 500, -1., 49.);
174 fhTotMap[tdc][channel] = h;
175 }
176 return h;
177}
178
180{
181 Double_t max = 0.0;
182 Int_t b = 0;
183 for (Int_t i = 1; i < h->GetNbinsX(); ++i) {
184 Double_t val = h->GetBinContent(i);
185 if (val > max) {
186 max = val;
187 b = i;
188 }
189 }
190 return h->GetBinCenter(b);
191}
192
193
195{
196 std::string s = "";
197 for (uint16_t i = 0; i < 33; ++i) {
198 s += " 0.00";
199 }
200 return s;
201}
202
ClassImp(CbmConverterManager)
@ kRich
Ring-Imaging Cherenkov Detector.
Helper functions for drawing 1D and 2D histograms and graphs.
Histogram manager.
Convert internal data classes to cbmroot common data classes.
Generates beam ions for transport simulation.
static Int_t GetNofDigis(ECbmModuleId systemId)
static Bool_t IsPresent(ECbmModuleId systemId)
Presence of a digi branch.
InitStatus Init()
Initialisation.
const Digi * Get(Int_t index) const
Get a digi object.
static CbmDigiManager * Instance()
Static instance.
int32_t GetAddress() const
Definition CbmRichDigi.h:43
double GetToT() const
Definition CbmRichDigi.h:78
TH1 * GetTotH1(Int_t tdc, Int_t channel)
Handler for TH1 Histograms.
std::string printEmpty()
Fill output lines with 0's if DiRICh Address is not in use in input file.
int getDirichAddress(const int dirich)
Extract the Tdc Address from the encoded DiRICH Address.
int getDirichChannel(const int dirich)
Extract the channel Address from the encoded DiRICH Address.
virtual void Exec(Option_t *option)
Inherited from FairTask.
Double_t GetMaxH1(TH1 *h)
Find the Maximum in a TH1 Histogram.
virtual InitStatus Init()
Inherited from FairTask.
std::map< Int_t, std::map< Int_t, TH1 * > > fhTotMap
uint16_t calcDirichAddr(uint32_t cnt)
virtual void Finish()
Inherited from FairTask.
CbmRichMCbmToTShifter()
Standard constructor.