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