BmnRoot
Loading...
Searching...
No Matches
BmnProfQa.cxx
Go to the documentation of this file.
1#include "BmnProfQa.h"
2
3#include <fstream>
4#include <iostream>
5
7#include "BmnDchHit.h"
8#include "BmnDchTrack.h"
9#include "BmnEnums.h"
10#include "BmnGemStripHit.h"
11#include "BmnMath.h"
12#include "BmnSiliconHit.h"
13#include "BmnUtils.h"
14#include "CbmBaseHit.h"
15#include "BmnGlobalTrack.h"
16#include "CbmStsTrack.h"
17#include "CbmVertex.h"
18#include "FairRunAna.h"
19#include "TClonesArray.h"
20#include "TF1.h"
21#include "TH1.h"
22#include "TH2F.h"
23#include "BmnHistManager.h"
24#include "BmnSiBTHit.h"
25
27using lit::Split;
28
29BmnProfQa::BmnProfQa(TString name, TString gemConf)
30: BmnQaBase(name, 1),
31 fProfHits(nullptr),
32 fProfDigits(nullptr),
33 fDstEventHeader(nullptr),
34 fConfigProf(gemConf),
35 fNItersSinceUpdate(0)
36{}
37
40
41InitStatus BmnProfQa::Init() {
42 printf("BmnProfQa::Init()");
43 fHM = new BmnHistManager();
44 if (fMonitorMode) {
49 fTicksLastUpdate = chrono::system_clock::now();
51 } else {
52
53 }
54 ReadDataBranches();
55 CreateHistograms();
56 if (fMonitorMode) {
58 fReport->Register("/");
60 // fServer->SetTimer(50, kFALSE);
61 } else {
62
63 }
64 printf("BmnProfQa::Init() finish");
65 return kSUCCESS;
66}
67
68void BmnProfQa::Exec(Option_t* opt) {
69 if (fEventNo % 1000 == 0) printf("EventCnt: %8d EventId: %8d RunId: %6u\n", fEventNo, fEventId, fRunId);
70 fEventNo++;
71 ProcessGlobal();
72 if (fMonitorMode) {
73 fNItersSinceUpdate++;
74 fServer->ProcessRequests();
75 chrono::time_point<chrono::system_clock> now = chrono::system_clock::now();
76 chrono::seconds time = chrono::duration_cast<chrono::seconds>(now - fTicksLastUpdate);
77 //time_t tt = chrono::system_clock::to_time_t(now);
78 // printf("\ntime %s\n", ctime(&tt));
79 if ((time > fTimeToUpdate) || (fNItersSinceUpdate > fNItersToUpdate)) {
81 if (fVerbose)
82 printf("Draw! iters %d\n", fNItersSinceUpdate);
83 fTicksLastUpdate = now;
84 fNItersSinceUpdate = 0;
85 }
86 }
88}
89
91 // fHM->WriteToFile();
92 if (!fMonitorMode) {
95 } else
97 // fServer->SetTimer(50, kFALSE);
98}
99
100void BmnProfQa::ReadDataBranches() {
101 FairRootManager* ioman = FairRootManager::Instance();
102 if (nullptr == ioman) Fatal("Init", "BmnRootManager is not instantiated");
103 fDstEventHeader = static_cast<DstEventHeader*> (ioman->GetObject("DstEventHeader."));
104
105 if (fInnerTrackerSetup[kSiProf]) {
106 // fProfHits = (TClonesArray*) ioman->GetObject("BmnProfHit");
107 fProfDigits = (TClonesArray*) ioman->GetObject("BmnProfDigit");
108 printf("fProfDigits %p\n", fProfDigits);
109 fProfDetector = make_unique<BmnSiProfStationSet>(fConfigProf);
111 kSiProf, static_cast<void*> (fProfDetector.get()));
112 }
113
114 printf("\nBRANCHES READ\n\n");
115}
116
117void BmnProfQa::CreateHistograms() {
118 Int_t MaxSig = 2500;
119 const Int_t n_strips(32);
120 TString detName;
122 for (Short_t iSt = 0; iSt < fProfDetector->GetNStations(); ++iSt) {
123 auto* st = fProfDetector->GetStation(iSt);
124 for (Int_t iModule = 0; iModule < st->GetNModules(); iModule++) {
125 auto* mod = st->GetModule(iModule);
126 for (Int_t iLayer = 0; iLayer < mod->GetNStripLayers(); iLayer++) {
127 //auto &lay = mod->GetStripLayer(iLayer);
128 string name(BmnProfQaReport::HistNameProfDigit(detName, iSt, iModule, iLayer));
129 // CreateH1(BmnSimulationReport::HistNameStripDigit(name, iSt, iModule, iLayer), "Strip #", "Count", "",
130 CreateH1(name, "Strip #", "Count", n_strips, 0, n_strips); //lay.GetNStrips(), 0, lay.GetNStrips());
131 if (iLayer) {
132 CreateH1(name + "_sig", "Signal", "Count", MaxSig, -MaxSig, 0);
133 CreateH2(name + "_pedestals", "Strip #", "Signal", "", n_strips, 0, n_strips, MaxSig, -MaxSig, 0);
134 } else {
135 CreateH1(name + "_sig", "Signal", "Count", MaxSig, 0, MaxSig);
136 CreateH2(name + "_pedestals", "Strip #", "Signal", "", n_strips, 0, n_strips, MaxSig, 0, MaxSig);
137 }
138 CreateH1(name + "_mean", "Strip #", "Count", n_strips, 0, n_strips); //lay.GetNStrips(), 0, lay.GetNStrips());
139 // BmnHist::SetHistStyleTH1(h);
140 }
141 string name2d(BmnProfQaReport::HistNameProfHits(detName, iSt));
142 CreateH2(name2d, "Strip X", "Strip Y", "", n_strips, 0, n_strips, n_strips, 0, n_strips);
143 }
144 }
145
146 // for (Int_t iMap = 0; iMap < NChars; ++iMap) {
147 // auto & map = channel_maps[iMap];
148 // TString detName;
149 //
150 // TH1 *h = new TH1F(
151 // Form("h%c_strips", map.LayerType),
152 // Form("%c side", map.LayerType), ASIC_channel, 0, ASIC_channel);
153 // TH1 *hMean = new TH1F(
154 // Form("h%c_strips_mean", map.LayerType),
155 // Form("%c side mean", map.LayerType), ASIC_channel, 0, ASIC_channel);
156 // TH1 *hSig = new TH1F(
157 // Form("h%c_sig", map.LayerType),
158 // Form("%c side signals", map.LayerType), 2 * ADCLimit + 1, -ADCLimit, ADCLimit);
159 // TH1 *hPed = new TH2F(
160 // Form("h%c_ped", map.LayerType),
161 // Form("%c side pedestals", map.LayerType), ASIC_channel, 0, ASIC_channel, NBins, -ADCLimit, ADCLimit);
162 // hVec[NCols * 0 + iMap] = h;
163 // hVec[NCols * 1 + iMap] = hSig;
164 // hVecOpt[NCols * 1 + iMap] = "logy";
165 // hVec[NCols * 2 + iMap] = hMean;
166 // hVec[NCols * 3 + iMap] = hPed;
167 // hVecOpt[NCols * 3 + iMap] = "colz";
168 // }
169
170 // if (fInnerTrackerSetup[kSiProf])
171 // CreateStripHits(fProfDetector, kSiProf);
172
173 printf("\nHISTOGRAMS CREATED!\n\n");
174
175}
176
177void BmnProfQa::ProcessGlobal() {
178 // fRunId = fDstEventHeader->GetRunId();
179 // fEventId = fDstEventHeader->GetEventId();
180 // if (fRunId != fPrevRunId) {
181 // printf("run id change %u -> %u\n", fPrevRunId, fRunId);
182 // fHM->ResetHists();
183 // }
184 TString detName;
186
187 // for "hit making"
188 const Int_t n_strips(32);
189 // vector<bitset < n_strips >> x_hit(fProfDetector->GetNStations(), 0);
190 // vector<bitset < n_strips >> y_hit(fProfDetector->GetNStations(), 0);
191 vector<vector < Int_t >> x_hit(fProfDetector->GetNStations(), vector(n_strips, 0));
192 vector<vector < Int_t >> y_hit(fProfDetector->GetNStations(), vector(n_strips, 0));
193
194 for (Int_t iDig = 0; iDig < fProfDigits->GetEntriesFast(); ++iDig) {
195 BmnSiProfDigit* dig = dynamic_cast<BmnSiProfDigit*> (fProfDigits->At(iDig));
196 Int_t iSt = dig->GetStation();
197 Int_t iMod = dig->GetModule();
198 Int_t iLayer = dig->GetStripLayer();
199 Int_t strip = dig->GetStripNumber();
200 Double_t signal = dig->GetStripSignal();
201 string name(BmnProfQaReport::HistNameProfDigit(detName, iSt, iMod, iLayer));
202 fHM->H1(name)->Fill(strip, abs(signal));
203 fHM->H1(name)->SetBinError(strip, 0);
204 fHM->H1(name + "_sig")->Fill(signal);
205 // fHM->H1(name + "_mean")->Fill(signal);
206 fHM->H2(name + "_pedestals")->Fill(strip, signal);
207
208 // temp crutches to make hits
209 if (iLayer)
210 y_hit[iSt][strip] = -signal;
211 else
212 x_hit[iSt][strip] = signal;
213 }
214 for (Short_t iSt = 0; iSt < fProfDetector->GetNStations(); ++iSt) {
215 string name2d(BmnProfQaReport::HistNameProfHits(detName, iSt));
216 for (size_t iX = 0; iX < n_strips; iX++)
217 for (size_t iY = 0; iY < n_strips; iY++)
218 if (x_hit[iSt][iX] && y_hit[iSt][iY])
219 fHM->H2(name2d)->Fill(iX, iY, abs(x_hit[iSt][iX]) + abs(y_hit[iSt][iY]));
220 }
221 // if (fProfHits) {
222 // FillStripHits(kSiProf, fProfHits);
223 // }
224}
225
226//void BmnProfQa::FillProfHits(TClonesArray* hits) {
227// TString detName;
228// BmnDetectorList::GetSystemNameCaps(detId, detName);
229// for (Int_t iHit = 0; iHit < hits->GetEntriesFast(); ++iHit) {
230// BmnHit* hit = static_cast<BmnHit*> (hits->At(iHit));
231// Short_t iSt = hit->GetStation();
232// // if (detId==kCSC)
233// // printf("hit! station %d {%2.3f, %2.3f}\n", iSt, hit->GetX(), hit->GetY());
234// fHM->H2(BmnSimulationReport::HistNameHits(detName, iSt))->Fill(hit->GetX(), hit->GetY());
235// }
236//}
237
239 printf("Reset Prof QA\n");
240 fHM->ResetHists();
241}
242
244 fServer->Register("/", this);
245 // TString path = "/" + fTitle + "/";
246 string path = string("/") + fName.Data() + "_cmd/";
247 string cmd = string("/") + fName.Data() + "/->ResetProf()";
248 string cmdTitle = path + "ResetProf";
249 fServer->RegisterCommand(cmdTitle.data(), cmd.data(), "button;");
250}
@ iX
@ iY
Global function to define the track acceptance. Used in QA.
@ kSiProf
static void GetSystemNameCaps(DetectorId det, TString &name)
Histogram manager.
void ResetHists()
Reset all histograms.
TH2 * H2(const TString &name) const
Return pointer to TH2 histogram.
TH1 * H1(const TString &name) const
Return pointer to TH1 histogram.
Profilometer Report QA.
static char * HistNameProfDigit(TString &detName, Short_t iSt, Short_t iMod, Short_t iLayer)
static char * HistNameProfHits(TString &detName, Short_t iSt)
void ResetProf()
virtual void Exec(Option_t *opt)
Derived from FairTask.
Definition BmnProfQa.cxx:68
void RegisterCommands()
virtual ~BmnProfQa()
Destructor.
Definition BmnProfQa.cxx:38
virtual void Finish()
Derived from FairTask.
Definition BmnProfQa.cxx:90
virtual InitStatus Init()
Derived from FairTask.
Definition BmnProfQa.cxx:41
BmnProfQa()
Constructor.
Definition BmnProfQa.h:35
Bool_t fMonitorMode
Definition BmnQaBase.h:157
UInt_t fRunId
Definition BmnQaBase.h:159
Int_t fEventId
Definition BmnQaBase.h:162
void CreateH1(const string &name, const string &xTitle, const string &yTitle, Int_t nofBins, Double_t minBin, Double_t maxBin)
BmnSimulationReport * fReport
Definition BmnQaBase.h:155
void CreateH2(const string &name, const string &xTitle, const string &yTitle, const string &zTitle, Int_t nofBinsX, Double_t minBinX, Double_t maxBinX, Int_t nofBinsY, Double_t minBinY, Double_t maxBinY)
TString fOutName
Definition BmnQaBase.h:150
string fOutputDir
Definition BmnQaBase.h:153
BmnHistManager * fHM
Definition BmnQaBase.h:152
UInt_t fPrevRunId
Definition BmnQaBase.h:160
THttpServer * fServer
Definition BmnQaBase.h:149
Int_t fEventNo
Definition BmnQaBase.h:161
void SetMonitorMode(const Bool_t mm)
Definition BmnReport.h:69
void CallDraw()
Definition BmnReport.h:53
void SetObjServer(THttpServer *s)
Definition BmnReport.h:70
void Register(string path)
void SetHM(BmnHistManager *hm)
void Create(BmnHistManager *histManager, const string &outputDir)
Main function which creates report data.
void AddStationSet(DetectorId id, void *ss)
Int_t GetStripNumber()
Int_t GetStripLayer()
Int_t GetStation()
Double_t GetStripSignal()
Int_t GetModule()
void SetDefaultDrawStyle()
string FindAndReplace(const string &name, const string &oldSubstr, const string &newSubstr)
Definition BmnUtils.cxx:20
vector< string > Split(const string &name, char delimiter)
Definition BmnUtils.cxx:27
name
Definition setup.py:7