CbmRoot
Loading...
Searching...
No Matches
CbmRichMCbmQaRichOnly.cxx
Go to the documentation of this file.
1/* Copyright (C) 2020-2021 Justus-Liebig-Universitaet Giessen, Giessen
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Adrian Weber [committer] */
4
6
7#include "CbmDigiManager.h"
8#include "CbmDrawHist.h"
9#include "CbmEvent.h"
10#include "CbmGlobalTrack.h"
11#include "CbmHistManager.h"
12#include "CbmMatchRecoToMC.h"
13#include "CbmRichConverter.h"
14#include "CbmRichDigi.h"
15#include "CbmRichDraw.h"
16#include "CbmRichGeoManager.h"
17#include "CbmRichHit.h"
19#include "CbmRichPoint.h"
20#include "CbmRichRing.h"
22#include "CbmRichUtil.h"
23#include "CbmStsDigi.h"
24#include "CbmTofDigi.h"
25#include "CbmTofHit.h"
26#include "CbmTofTracklet.h"
27#include "CbmTrackMatchNew.h"
28#include "CbmTrdTrack.h"
29#include "CbmUtils.h"
30#include "TCanvas.h"
31#include "TClonesArray.h"
32#include "TEllipse.h"
33#include "TF1.h"
34#include "TFile.h"
35#include "TGeoBBox.h"
36#include "TGeoManager.h"
37#include "TGeoNode.h"
38#include "TH1.h"
39#include "TH1D.h"
40#include "TLatex.h"
41#include "TLine.h"
42#include "TMarker.h"
43#include "TMath.h"
44#include "TStyle.h"
45#include "TSystem.h"
46
47#include <TBox.h>
48#include <TLegend.h>
49
50#include <boost/assign/list_of.hpp>
51
52#include <cmath>
53#include <fstream>
54#include <iomanip>
55#include <iostream>
56#include <sstream>
57#include <string>
58
59
60using namespace std;
61using boost::assign::list_of;
62
63#define RichZPos 348.
64
66 : FairTask("CbmRichMCbmQaRichOnly")
67 , fRichHits(nullptr)
68 , fRichRings(nullptr)
69 , fCbmEvent(nullptr)
70 , fHM(nullptr)
71 , fEventNum(0)
72 , fNofDrawnRings(0)
73 , fNofDrawnRichTofEv(0)
74 , fNofDrawnEvents(0)
75 , fMaxNofDrawnEvents(100)
76 , fTriggerRichHits(0)
77 , fOutputDir("result")
78{
79}
80
82{
83 cout << "CbmRichMCbmQaRichOnly::Init" << endl;
84
85 FairRootManager* ioman = FairRootManager::Instance();
86 if (nullptr == ioman) {
87 Fatal("CbmRichMCbmQaRichOnly::Init", "RootManager not instantised!");
88 }
89
91 fDigiMan->Init();
92
93 if (!fDigiMan->IsPresent(ECbmModuleId::kRich)) Fatal("CbmRichMCbmQaReal::Init", "No Rich Digis!");
94
95 fRichHits = (TClonesArray*) ioman->GetObject("RichHit");
96 if (nullptr == fRichHits) {
97 Fatal("CbmRichMCbmQaRichOnly::Init", "No Rich Hits!");
98 }
99
100 fRichRings = (TClonesArray*) ioman->GetObject("RichRing");
101 if (nullptr == fRichRings) {
102 Fatal("CbmRichMCbmQaRichOnly::Init", "No Rich Rings!");
103 }
104
105 fCbmEvent = dynamic_cast<TClonesArray*>(ioman->GetObject("CbmEvent"));
106 if (nullptr == fCbmEvent) {
107 Fatal("CbmRichMCbmQaRichOnly::Init", "No Event!");
108 }
109
111
112
121
122 //Init OffsetCorrection ICD
123 for (auto& a : ICD_offset_read)
124 a = 0.;
125 for (auto& a : ICD_offset)
126 a = 0.;
127 for (auto& a : ICD_offset_cnt)
128 a = 0;
130
131 return kSUCCESS;
132}
133
135{
136 fHM = new CbmHistManager();
137
138 fHM->Create1<TH1D>("fhNofEvents", "fhNofEvents;Entries", 1, 0.5, 1.5);
139 fHM->Create1<TH1D>("fhNofCbmEvents", "fhNofCbmEvents;Entries", 1, 0.5, 1.5);
140 fHM->Create1<TH1D>("fhNofCbmEventsRing", "fhNofCbmEventsRing;Entries", 1, 0.5, 1.5);
141
142 fHM->Create1<TH1D>("fhNofBlobEvents", "fhNofBlobEvents;Entries", 1, 0.5, 1.5);
143 fHM->Create1<TH1D>("fhNofBlobsInEvent", "fhNofBlobsInEvent;Entries", 36, 0.5, 36.5);
144
145 // RICH hits
146 fHM->Create2<TH2D>("fhRichHitXY", "fhRichHitXY;RICH hit X [cm];RICH hit Y [cm];Entries", 67, -20.1 + fXOffsetHisto,
147 20.1 + fXOffsetHisto, 84, -25.2, 25.2);
148 fHM->Create2<TH2D>("fhRichHitXY_fromRing", "fhRichHitXY_fromRing;RICH hit X [cm];RICH hit Y [cm];Entries", 67,
149 -20.1 + fXOffsetHisto, 20.1 + fXOffsetHisto, 84, -25.2, 25.2);
150
151 //ToT
152 fHM->Create1<TH1D>("fhRichDigisToT", "fhRichDigisToT;ToT [ns];Entries", 601, 9.975, 40.025);
153 fHM->Create1<TH1D>("fhRichHitToT", "fhRichHitToT;ToT [ns];Entries", 601, 9.975, 40.025);
154
155 // RICH rings
156 fHM->Create2<TH2D>("fhRichRingXY", "fhRichRingXY;Ring center X [cm];Ring center Y [cm];Entries", 67,
157 -20.1 + fXOffsetHisto, 20.1 + fXOffsetHisto, 84, -25.2, 25.2);
158 fHM->Create1<TH1D>("fhRichRingRadius", "fhRichRingRadius;Ring radius [cm];Entries", 100, 0., 7.);
159 fHM->Create1<TH1D>("fhNofHitsInRing", "fhNofHitsInRing;# hits in ring;Entries", 50, -0.5, 49.5);
160 fHM->Create2<TH2D>("fhICD", "fhICD;channel;DeltaTime", 2305, -0.5, 2304.5, 130, -6.5, 6.5);
161
162 fHM->Create2<TH2D>("fhRichRingRadiusY", "fhRichRingRadiusY;Ring Radius [cm]; Y position[cm];Entries", 70, -0.05, 6.95,
163 84, -25.2, 25.2);
164 fHM->Create2<TH2D>("fhRichHitsRingRadius", "fhRichHitsRingRadius;#Rich Hits/Ring; Ring Radius [cm];Entries", 50, -0.5,
165 49.5, 70, -0.05, 6.95);
166
167 fHM->Create1<TH1D>("fhRingDeltaTime", "fhRingDeltaTime; \\Delta Time/ns;Entries", 101, -10.1, 10.1);
168 fHM->Create1<TH1D>("fhRingChi2", "fhRingChi2; \\Chi^2 ;Entries", 101, 0.0, 10.1);
169
170 fHM->Create2<TH2D>("fhRichRingCenterXChi2", "fhRichRingCenterXChi2;Ring Center X [cm];\\Chi^2 ;;Entries", 67,
171 -20.1 + fXOffsetHisto, 20.1 + fXOffsetHisto, 101, 0.0, 10.1);
172 fHM->Create2<TH2D>("fhRichRingCenterYChi2", "fhRichRingCenterYChi2;Ring Center Y [cm];\\Chi^2 ;;Entries", 84, -25.2,
173 25.2, 101, 0.0, 10.1);
174 fHM->Create2<TH2D>("fhRichRingRadiusChi2", "fhRichRingRadiusChi2; Ring Radius [cm];\\Chi^2 ;;Entries", 70, -0.05,
175 6.95, 101, 0.0, 10.1);
176
177 fHM->Create1<TH1D>("fhHitTimeEvent", "fhHitTimeEvent;time [ns];Entries", 400, -100., 300);
178
179 // Digis
180 fHM->Create2<TH2D>("fhDigisInChnl", "fhDigisInChnl;channel;#Digis;", 2304, -0.5, 2303.5, 500, -0.5, 499.5);
181 fHM->Create2<TH2D>("fhDigisInDiRICH", "fhDigisInDiRICH;DiRICH;#Digis;", 72, -0.5, 71.5, 3000, -0.5, 2999.5);
182
183 //fHM->Create2<TH2D>("fhDigisTimeTot", "fhDigisTimeTot;LE [ns]; ToT [ns];#Digis;", 200, -50., 150., 300, 15.0, 30.0);
184 fHM->Create2<TH2D>("fhHitsTimeTot", "fhHitsTimeTot;LE [ns]; ToT [ns];#Digis;", 200, -50., 150., 300, 15.0, 30.0);
185}
186
187
188void CbmRichMCbmQaRichOnly::Exec(Option_t* /*option*/)
189{
190 fEventNum++;
191 fHM->H1("fhNofEvents")->Fill(1);
192
193 cout << "CbmRichMCbmQaRichOnly, event No. " << fEventNum << endl;
194
195 std::array<unsigned int, 2304> chnlDigis;
196 for (auto& c : chnlDigis)
197 c = 0;
198 for (int i = 0; i < fDigiMan->GetNofDigis(ECbmModuleId::kRich); i++) {
199 const CbmRichDigi* richDigi = fDigiMan->Get<CbmRichDigi>(i);
200 fHM->H1("fhRichDigisToT")->Fill(richDigi->GetToT());
201 uint16_t addrDiRICH = (richDigi->GetAddress() >> 16) & 0xFFFF;
202 uint16_t addrChnl = richDigi->GetAddress() & 0xFFFF;
203 uint16_t dirichNmbr = ((addrDiRICH >> 8) & 0xF) * 18 + ((addrDiRICH >> 4) & 0xF) * 2 + ((addrDiRICH >> 0) & 0xF);
204 uint32_t fullNmbr = (dirichNmbr << 5) | (addrChnl - 1);
205 chnlDigis[fullNmbr]++;
206 }
207
208 {
209 unsigned int sum = 0;
210 for (uint16_t i = 0; i < 2304; ++i) {
211 if (chnlDigis[i] != 0) fHM->H1("fhDigisInChnl")->Fill(i, chnlDigis[i]);
212 sum += chnlDigis[i];
213 if (i % 32 == 31) {
214 uint16_t dirich = i / 32;
215 if (sum != 0) fHM->H1("fhDigisInDiRICH")->Fill(dirich, sum);
216 sum = 0;
217 }
218 }
219 }
220
221 int nofRichHits = fRichHits->GetEntriesFast();
222 for (int iH = 0; iH < nofRichHits; iH++) {
223 CbmRichHit* richHit = static_cast<CbmRichHit*>(fRichHits->At(iH));
224 fHM->H2("fhRichHitXY")->Fill(richHit->GetX(), richHit->GetY());
225 fHM->H1("fhRichHitToT")->Fill(richHit->GetToT());
226 }
227
228
229 //CBMEVENT
230 auto fNCbmEvent = fCbmEvent->GetEntriesFast();
231
232 for (int i = 0; i < fNCbmEvent; i++) {
233 fHM->H1("fhNofCbmEvents")->Fill(1);
234 CbmEvent* ev = static_cast<CbmEvent*>(fCbmEvent->At(i));
235
236 if (fTriggerRichHits != 0 && (Int_t(ev->GetNofData(ECbmDataType::kRichHit)) < fTriggerRichHits)) continue;
237
238
239 std::vector<int> ringIndx;
240 std::vector<int> evRichHitIndx;
241 std::array<uint32_t, 36> pmtHits;
242 for (auto& a : pmtHits)
243 a = 0;
244
245 // Map Rings to CbmEvent
246 for (size_t j = 0; j < ev->GetNofData(ECbmDataType::kRichHit); j++) {
247 auto iRichHit = ev->GetIndex(ECbmDataType::kRichHit, j);
248 evRichHitIndx.push_back(iRichHit);
249 CbmRichHit* richHit = static_cast<CbmRichHit*>(fRichHits->At(iRichHit));
250
251 fHM->H1("fhHitTimeEvent")->Fill(richHit->GetTime() - ev->GetStartTime());
252 fHM->H2("fhHitsTimeTot")->Fill(richHit->GetTime() - ev->GetStartTime(), richHit->GetToT());
253
254 uint32_t pmtId = (((richHit->GetAddress()) >> 20) & 0xF) + (((richHit->GetAddress()) >> 24) & 0xF) * 9;
255 pmtHits[pmtId]++;
256
257 int nofRichRings = fRichRings->GetEntriesFast();
258 for (int l = 0; l < nofRichRings; l++) {
259 CbmRichRing* ring = static_cast<CbmRichRing*>(fRichRings->At(l));
260
261 auto NofRingHits = ring->GetNofHits();
262 for (int m = 0; m < NofRingHits; m++) {
263 auto RingHitIndx = ring->GetHit(m);
264 if (RingHitIndx == iRichHit) {
265 Bool_t used = false;
266 for (auto check : ringIndx) {
267 if (check == l) {
268 used = true;
269 break;
270 }
271 }
272 if (used == false) ringIndx.push_back(l);
273 break;
274 }
275 }
276 }
277 }
278
279 uint16_t blob = 0;
280 for (auto a : pmtHits) {
281 if (a > 30) {
282 blob++;
283 }
284 }
285 if (blob > 0) {
286 fHM->H1("fhNofBlobEvents")->Fill(1);
287 fHM->H1("fhNofBlobsInEvent")->Fill(blob);
288 }
289
290 if (ringIndx.size() != 0) fHM->H1("fhNofCbmEventsRing")->Fill(1);
291
292 //Ring Loop
293 for (unsigned int k = 0; k < ringIndx.size(); ++k) {
294 //Rigs in this CbmEvent
295 CbmRichRing* ring = static_cast<CbmRichRing*>(fRichRings->At(ringIndx[k]));
296 if (ring == nullptr) continue;
297 fHM->H1("fhRingChi2")->Fill(ring->GetChi2());
298 fHM->H2("fhRichRingCenterXChi2")->Fill(ring->GetCenterX(), ring->GetChi2());
299 fHM->H2("fhRichRingCenterYChi2")->Fill(ring->GetCenterY(), ring->GetChi2());
300 fHM->H2("fhRichRingRadiusChi2")->Fill(ring->GetRadius(), ring->GetChi2());
301
302 fHM->H2("fhRichRingXY")->Fill(ring->GetCenterX(), ring->GetCenterY());
303 fHM->H1("fhRichRingRadius")->Fill(ring->GetRadius());
304 fHM->H1("fhNofHitsInRing")->Fill(ring->GetNofHits());
305 fHM->H2("fhRichRingRadiusY")->Fill(ring->GetRadius(), ring->GetCenterY());
306 fHM->H2("fhRichHitsRingRadius")->Fill(ring->GetNofHits(), ring->GetRadius());
307 for (int j = 0; j < ring->GetNofHits(); ++j) {
308 Int_t hitIndx = ring->GetHit(j);
309 CbmRichHit* hit = (CbmRichHit*) fRichHits->At(hitIndx);
310 if (nullptr == hit) continue;
311 fHM->H2("fhRichHitXY_fromRing")->Fill(hit->GetX(), hit->GetY());
312 }
313 }
314 fSeDisplay->DrawEvent(static_cast<CbmEvent*>(fCbmEvent->At(i)), ringIndx, 1);
315
316 } //End CbmEvent loop
317
318 // Loop over all Rings
319 RichRings();
320}
321
323{
324 int nofRichRings = fRichRings->GetEntriesFast();
325 for (int i = 0; i < nofRichRings; i++) {
326 CbmRichRing* ring = static_cast<CbmRichRing*>(fRichRings->At(i));
327 if (ring == nullptr) continue;
328
329 for (int j = 1; j < ring->GetNofHits(); ++j) {
330 Int_t hitIndx = ring->GetHit(j);
331 CbmRichHit* hit = (CbmRichHit*) fRichHits->At(hitIndx);
332 if (nullptr == hit) continue;
333
334 //Read Address
335 uint32_t DiRICH_Addr = hit->GetAddress();
336 unsigned int addr = (((DiRICH_Addr >> 24) & 0xF) * 18 * 32) + (((DiRICH_Addr >> 20) & 0xF) * 2 * 32)
337 + (((DiRICH_Addr >> 16) & 0xF) * 32) + ((DiRICH_Addr & 0xFFFF) - 0x1);
338 ICD_offset.at(addr) += hit->GetTime() - ring->GetTime() - ICD_offset_read.at(addr);
339 fHM->H2("fhICD")->Fill(addr, hit->GetTime() - ring->GetTime() - ICD_offset_read.at(addr));
340 fHM->H1("fhRingDeltaTime")->Fill(hit->GetTime() - ring->GetTime() - ICD_offset_read.at(addr));
341 ICD_offset_cnt.at(addr)++;
342 }
343
344 //DrawRing(ring);
345 /*fHM->H2("fhRichRingXY")->Fill(ring->GetCenterX(), ring->GetCenterY());
346 fHM->H1("fhRichRingRadius")->Fill(ring->GetRadius());
347 fHM->H1("fhNofHitsInRing")->Fill(ring->GetNofHits());
348 */
349 }
350}
351
352
354{
355 cout.precision(4);
356
357 //SetDefaultDrawStyle();
358 double nofEvents = fHM->H1("fhNofCbmEvents")->GetEntries();
359 fHM->ScaleByPattern("fh_.*", 1. / nofEvents);
360
361 {
362 fHM->CreateCanvas("rich_mcbm_fhNofCbmEvents", "rich_mcbm_fhNofCbmEvents", 600, 600);
363 DrawH1(fHM->H1("fhNofCbmEvents"));
364 }
365
366 {
367 fHM->CreateCanvas("rich_mcbm_fhNofCbmEventsRing", "rich_mcbm_fhNofCbmEventsRing", 600, 600);
368 DrawH1(fHM->H1("fhNofCbmEventsRing"));
369 }
370
371 {
372 fHM->CreateCanvas("rich_mcbm_fhNofEvents", "rich_mcbm_fhNofEvents", 600, 600);
373 DrawH1(fHM->H1("fhNofEvents"));
374 }
375
376 {
377 fHM->CreateCanvas("rich_mcbm_fhBlobEvents", "rich_mcbm_fhBlobEvents", 600, 600);
378 DrawH1(fHM->H1("fhNofBlobEvents"));
379 }
380
381 {
382 fHM->CreateCanvas("rich_mcbm_fhBlobsInCbmEvent", "rich_mcbm_fhBlobsInCbmEvent", 600, 600);
383 DrawH1(fHM->H1("fhNofBlobsInEvent"));
384 }
385
386 {
387 fHM->CreateCanvas("inner_channel_delay", "inner_channel_delay", 1200, 600);
388 DrawH2(fHM->H2("fhICD"));
389 }
390
391
392 {
393 fHM->CreateCanvas("RingDelta", "RingDelta", 600, 600);
394 DrawH1(fHM->H1("fhRingDeltaTime"));
395 }
396
397 {
398 TCanvas* c = fHM->CreateCanvas("rich_ToT", "rich_ToT", 1200, 600);
399 c->Divide(2, 1);
400 c->cd(1);
401 DrawH1(fHM->H1("fhRichDigisToT"));
402 c->cd(2);
403 DrawH1(fHM->H1("fhRichHitToT"));
404 }
405
406 {
407 fHM->CreateCanvas("DigisInChnl", "DigisInChnl", 1200, 600);
408 DrawH2(fHM->H2("fhDigisInChnl"));
409 }
410
411 // {
412 // fHM->CreateCanvas("DigisTimeTot", "DigisTimeTot", 600, 600);
413 // DrawH2(fHM->H2("fhDigisTimeTot"));
414 // }
415
416 {
417 fHM->CreateCanvas("HitsTimeTot", "HitsTimeTot", 600, 600);
418 DrawH2(fHM->H2("fhHitsTimeTot"));
419 }
420
421 {
422 fHM->CreateCanvas("DigisInDiRICH", "DigisInDiRICH", 1200, 600);
423 DrawH2(fHM->H2("fhDigisInDiRICH"));
424 }
425
426 {
427 fHM->CreateCanvas("HitTimeEvent", "HitTimeEvent", 1200, 1200);
428 DrawH1(fHM->H1("fhHitTimeEvent"));
429 }
430
431 {
432 TCanvas* c = fHM->CreateCanvas("rich_Hits", "rich_Hits", 1200, 1200);
433 c->Divide(2, 2);
434 c->cd(1);
435 DrawH2(fHM->H2("fhRichHitXY"));
436 c->cd(2);
437 DrawH2(fHM->H2("fhRichHitXY_fromRing"));
438 c->cd(3);
439 TH2F* hitsBg = (TH2F*) fHM->H2("fhRichHitXY")->Clone();
440 hitsBg->SetName("fhRichHitXY_bg");
441 hitsBg->SetTitle("fhRichHitXY_bg");
442 hitsBg->Add(fHM->H2("fhRichHitXY_fromRing"), -1);
443 //hitsBg->Draw("colz");
444 DrawH2(hitsBg);
445 c->cd(4);
446 DrawH2(fHM->H2("fhRichRingXY"));
447 }
448
449 {
450 TCanvas* c = fHM->CreateCanvas("rich_mcbm_rings", "rich_mcbm_rings", 1200, 600);
451 c->Divide(2, 1);
452 c->cd(1);
453 DrawH1(fHM->H1("fhRichRingRadius"));
454 c->cd(2);
455 DrawH1(fHM->H1("fhNofHitsInRing"));
456 }
457
458 {
459 fHM->CreateCanvas("RichRingRadiusVsY", "RichRingRadiusVsY", 800, 800);
460 //c->SetLogy();
461 DrawH2(fHM->H2("fhRichRingRadiusY"));
462 }
463
464 {
465 fHM->CreateCanvas("RichRingHitsVsRadius", "RichRingHitsVsRadius", 800, 800);
466 //c->SetLogy();
467 DrawH2(fHM->H2("fhRichHitsRingRadius"));
468 }
469
470 {
471 TCanvas* c = fHM->CreateCanvas("RichRingChi2", "RichRingChi2", 1600, 800);
472 //c->SetLogy();
473 c->Divide(2, 1);
474 c->cd(1);
475 DrawH1(fHM->H1("fhRingChi2"));
476 c->cd(2);
477 DrawH2(fHM->H2("fhRichRingRadiusChi2"));
478 }
479
480 {
481 TCanvas* c = fHM->CreateCanvas("RichRingCenterChi2", "RichRingCenterChi2", 1600, 800);
482 //c->SetLogy();
483 c->Divide(2, 1);
484 c->cd(1);
485 DrawH2(fHM->H2("fhRichRingCenterXChi2"));
486 c->cd(2);
487 DrawH2(fHM->H2("fhRichRingCenterYChi2"));
488 }
489}
490
492{
493 //std::cout<<"#!#DRAW!!!"<<std::endl;
494 if (fNofDrawnRings > 20) return;
496 stringstream ss;
497 ss << "Event" << fNofDrawnRings;
498 //fNofDrawnRings++;
499 TCanvas* c = nullptr;
500 if (full == true) {
501 c = fHM->CreateCanvas(ss.str().c_str(), ss.str().c_str(), 800, 800);
502 }
503 else {
504 c = fHM->CreateCanvas(ss.str().c_str(), ss.str().c_str(), 500, 500);
505 }
506 c->SetGrid(true, true);
507 TH2D* pad = nullptr;
508 if (full == true) {
509 pad = new TH2D(ss.str().c_str(), (ss.str() + ";X [cm];Y [cm]").c_str(), 1, -15., 10., 1, -5., 20);
510 }
511 else {
512 pad = new TH2D(ss.str().c_str(), (ss.str() + ";X [cm];Y [cm]").c_str(), 1, -5., 5., 1, -5., 5);
513 }
514
515 pad->SetStats(false);
516 pad->Draw();
517
518 if (full == true) {
519 //rough Drawing of RichDetectorAcceptance
520 TLine* line0 = new TLine(-6.25, 8, -6.25, 15.9);
521 line0->Draw();
522 TLine* line1 = new TLine(-6.25, 15.9, -1.05, 15.9);
523 line1->Draw();
524 TLine* line2 = new TLine(-1.05, 15.9, -1.05, 13.2);
525 line2->Draw();
526 TLine* line3 = new TLine(-1.05, 13.2, +4.25, 13.2);
527 line3->Draw();
528 TLine* line4 = new TLine(4.25, 13.2, +4.25, 8);
529 line4->Draw();
530 TLine* line5 = new TLine(4.25, 8, -6.25, 8);
531 line5->Draw();
532 }
533
534 // find min and max x and y positions of the hits
535 // in order to shift drawing
536 double xCur = 0.;
537 double yCur = 0.;
538
539 if (full == false) {
540 double xmin = 99999., xmax = -99999., ymin = 99999., ymax = -99999.;
541 for (int i = 0; i < ring->GetNofHits(); i++) {
542 Int_t hitInd = ring->GetHit(i);
543 CbmRichHit* hit = (CbmRichHit*) fRichHits->At(hitInd);
544 if (nullptr == hit) continue;
545 if (xmin > hit->GetX()) xmin = hit->GetX();
546 if (xmax < hit->GetX()) xmax = hit->GetX();
547 if (ymin > hit->GetY()) ymin = hit->GetY();
548 if (ymax < hit->GetY()) ymax = hit->GetY();
549 }
550 xCur = (xmin + xmax) / 2.;
551 yCur = (ymin + ymax) / 2.;
552 }
553
554 //Draw circle and center
555 TEllipse* circle = new TEllipse(ring->GetCenterX() - xCur, ring->GetCenterY() - yCur, ring->GetRadius());
556 circle->SetFillStyle(0);
557 circle->SetLineWidth(3);
558 circle->Draw();
559 TEllipse* center = new TEllipse(ring->GetCenterX() - xCur, ring->GetCenterY() - yCur, .1);
560 center->Draw();
561
562
563 uint nofDrawHits = 0;
564
565 // Draw hits
566 for (int i = 0; i < ring->GetNofHits(); i++) {
567 Int_t hitInd = ring->GetHit(i);
568 CbmRichHit* hit = (CbmRichHit*) fRichHits->At(hitInd);
569 if (nullptr == hit) continue;
570 TEllipse* hitDr = new TEllipse(hit->GetX() - xCur, hit->GetY() - yCur, .25);
571 //std::cout<<"LE of Hit: "<< hit->GetTime()- fCbmEventStartTime << "\t" << hit->GetTime() << "\t" << fCbmEventStartTime <<std::endl;
572 if (doToT(hit)) { // Good ToT selection
573 hitDr->SetFillColor(kRed);
574 }
575 else {
576 hitDr->SetFillColor(kBlue);
577 }
578 nofDrawHits++;
579 hitDr->Draw();
580 }
581
582
583 //Draw information
584 stringstream ss2;
585 ss2 << "(x,y,r,n)=(" << setprecision(3) << ring->GetCenterX() << ", " << ring->GetCenterY() << ", "
586 << ring->GetRadius() << ", " << ring->GetNofHits() << ")";
587 TLatex* latex = nullptr;
588 if (full == true) {
589 latex = new TLatex(ring->GetCenterX() - 13., ring->GetCenterY() + 5., ss2.str().c_str());
590 }
591 else {
592 latex = new TLatex(-4., 4., ss2.str().c_str());
593 }
594 latex->Draw();
595}
596
597
599{
600
601 for (unsigned int i = 0; i < ICD_offset.size(); ++i) {
602 if (ICD_offset_cnt.at(i) == 0) {
603 ICD_offset.at(i) = 0.0;
604 }
605 else {
606 ICD_offset.at(i) /= ICD_offset_cnt.at(i);
607 }
608 ICD_offset.at(i) += ICD_offset_read.at(i);
609 }
610
612
613 //std::cout<<"Address: "<<InterChannel[0].first << std::endl;
614 //std::cout<<"Tracks: "<< fTofTracks->GetEntriesFast() <<std::endl;
615 std::cout << "Drawing Hists...";
616 DrawHist();
617 std::cout << "DONE!" << std::endl;
618
619 if (this->fDoDrawCanvas) {
621 std::cout << "Canvas saved to Images!" << std::endl;
622 }
623
624 if (this->fDoWriteHistToFile) {
626 TFile* oldFile = gFile;
627 TDirectory* oldir = gDirectory;
628
629 std::string s = fOutputDir + "/RecoHists.root";
630 TFile* outFile = new TFile(s.c_str(), "RECREATE");
631 if (outFile->IsOpen()) {
632 fHM->WriteToFile();
633 std::cout << "Written to Root-file \"" << s << "\" ...";
634 outFile->Close();
635 std::cout << "Done!" << std::endl;
636 }
638 gFile = oldFile;
639 gDirectory->cd(oldir->GetPath());
640 }
641}
642
643
644void CbmRichMCbmQaRichOnly::DrawFromFile(const string& fileName, const string& outputDir)
645{
646 fOutputDir = outputDir;
647
649 TFile* oldFile = gFile;
650 TDirectory* oldDir = gDirectory;
651
652 if (fHM != nullptr) delete fHM;
653
654 fHM = new CbmHistManager();
655 TFile* file = new TFile(fileName.c_str());
656 fHM->ReadFromFile(file);
657 DrawHist();
658
660
662 gFile = oldFile;
663 gDirectory = oldDir;
664}
665
667{
668 bool check = false;
669 if ((hit->GetToT() > fTotMin) && (hit->GetToT() < fTotMax)) check = true;
670
671 return check;
672}
673
675{
676
677 std::cout << "analyse a Ring" << std::endl;
678
679 Double_t meanTime = 0.;
680 unsigned int hitCnt = 0;
681 Double_t minRHit2 = std::numeric_limits<Double_t>::max();
682 for (int i = 0; i < ring->GetNofHits(); i++) {
683 Int_t hitInd = ring->GetHit(i);
684 CbmRichHit* hit = (CbmRichHit*) fRichHits->At(hitInd);
685 if (nullptr == hit) continue;
686
687 meanTime += hit->GetTime();
688 hitCnt++;
689
690 const Float_t diffX = hit->GetX() - ring->GetCenterX();
691 const Float_t diffY = hit->GetY() - ring->GetCenterY();
692 const Float_t tmpHitRadius2 = (diffX * diffX + diffY * diffY);
693
694 if (tmpHitRadius2 < minRHit2) {
695 minRHit2 = tmpHitRadius2;
696 }
697 }
698 meanTime = meanTime / hitCnt;
699
700 //std::cout<<"mean: "<<meanTime<<std::endl;
701 for (int i = 0; i < ring->GetNofHits(); i++) {
702 Int_t hitInd = ring->GetHit(i);
703 CbmRichHit* hit = (CbmRichHit*) fRichHits->At(hitInd);
704 if (nullptr == hit) continue;
705 //std::cout<<"DeltatTime: "<< meanTime - hit->GetTime()<<std::endl;
706 fHM->H1("fhRingDeltaTime")->Fill(static_cast<Double_t>(meanTime - hit->GetTime()));
707
708 fHM->H1("fhRingToTs")->Fill(hit->GetToT());
709 fHM->H1("fhRingLE")->Fill(static_cast<Double_t>(hit->GetTime() - ev->GetStartTime()));
710 fHM->H2("fhRingLEvsToT")->Fill(static_cast<Double_t>(hit->GetTime() - ev->GetStartTime()), hit->GetToT());
711 //std::vector<int> tmpRingIndx;
712 //tmpRingIndx.push_back(ring->GetIndex);
713 const Double_t Tdiff_ring = (hit->GetTime() - ev->GetStartTime());
714 if ((Tdiff_ring > 20.) && (Tdiff_ring < 30.)) {
715 std::cout << ev->GetNumber() << " Address_ring: " << std::hex << CbmRichUtil::GetDirichId(hit->GetAddress())
716 << std::dec << " " << CbmRichUtil::GetDirichChannel(hit->GetAddress()) << " " << hit->GetToT() << " "
717 << ring->GetRadius() << std::endl;
718 //fHM->H1("fhDiRICHsInRegion")->Fill(CbmRichUtil::GetDirichId(hit->GetAddress()));
719 }
720 }
721
722 int InnerHitCnt = 0;
723 int InnerHitCnt_cut = 0;
724 for (size_t j = 0; j < ev->GetNofData(ECbmDataType::kRichHit); j++) {
725 auto iRichHit = ev->GetIndex(ECbmDataType::kRichHit, j);
726 CbmRichHit* richHit = static_cast<CbmRichHit*>(fRichHits->At(iRichHit));
727 if (nullptr == richHit) continue;
728 const Float_t diffX = richHit->GetX() - ring->GetCenterX();
729 const Float_t diffY = richHit->GetY() - ring->GetCenterY();
730 //select inner Part of Ring
731 if (diffX * diffX + diffY * diffY < minRHit2) {
732 InnerHitCnt++;
733 const Double_t Tdiff_inner = (richHit->GetTime() - ev->GetStartTime());
734 if ((Tdiff_inner > 20.) && (Tdiff_inner < 30.)) {
735 InnerHitCnt_cut++;
736 //if (InnerHitCnt_cut == 1) {DrawRing(ring);}
737 std::cout << ev->GetNumber() << " Address_inner: " << std::hex
738 << CbmRichUtil::GetDirichId(richHit->GetAddress()) << std::dec << " "
739 << CbmRichUtil::GetDirichChannel(richHit->GetAddress()) << " " << richHit->GetToT() << " "
740 << ring->GetRadius() << std::endl;
741 fHM->H1("fhDiRICHsInRegion")->Fill(CbmRichUtil::GetDirichId(richHit->GetAddress()));
742 }
743
744 fHM->H1("fhInnerRingDeltaTime")->Fill(static_cast<Double_t>(meanTime - richHit->GetTime()));
745 fHM->H1("fhInnerRingToTs")->Fill(richHit->GetToT());
746 fHM->H1("fhInnerRingLE")->Fill(static_cast<Double_t>(richHit->GetTime() - ev->GetStartTime()));
747 }
748 }
749 if (InnerHitCnt == 0) {
750 fHM->H1("fhInnerRingFlag")->Fill(1);
751 }
752 else {
753 fHM->H1("fhInnerRingFlag")->Fill(0);
754 }
755 fHM->H1("fhNofInnerHits")->Fill(InnerHitCnt);
756}
757
758
760{
761 if (ring->GetRadius() > 2. && ring->GetRadius() < 4.2) return true;
762
763 return false;
764}
765
766void CbmRichMCbmQaRichOnly::save_ICD(std::array<Double_t, 2304>& ICD_offsets, unsigned int iteration)
767{
768 std::ofstream icd_file;
769 icd_file.open(Form("icd_offset_it_%u.data", iteration));
770 if (icd_file.is_open()) {
771 for (unsigned int i = 0; i < ICD_offsets.size(); ++i) {
772 //loop over all Offsets
773 icd_file << i << "\t" << std::setprecision(25) << ICD_offsets.at(i) << "\n";
774 }
775 icd_file.close();
776 }
777 else
778 std::cout << "Unable to open inter channel delay file icd_offset_it_" << iteration << ".data\n";
779}
780
781
782void CbmRichMCbmQaRichOnly::read_ICD(std::array<Double_t, 2304>& ICD_offsets, unsigned int iteration)
783{
784 std::cout << gSystem->pwd() << std::endl;
785 std::string line;
786 std::ifstream icd_file(Form("icd_offset_it_%u.data", iteration));
787 unsigned int lineCnt = 0;
788 if (icd_file.is_open()) {
789 while (getline(icd_file, line)) {
790 if (line[0] == '#') continue; // just a comment
791 std::istringstream iss(line);
792 unsigned int addr = 0;
793 Double_t value;
794 if (!(iss >> addr >> value)) {
795 std::cout << "A Problem accured in line " << lineCnt << "\n";
796 break;
797 } // error
798 lineCnt++;
799 ICD_offsets.at(addr) += value;
800 }
801 icd_file.close();
802 }
803 else
804 std::cout << "Unable to open inter channel delay file icd_offset_it_" << iteration << ".data\n";
805}
806
ClassImp(CbmConverterManager)
@ kRich
Ring-Imaging Cherenkov Detector.
void DrawH1(TH1 *hist, HistScale logx, HistScale logy, const string &drawOpt, Int_t color, Int_t lineWidth, Int_t lineStyle, Int_t markerSize, Int_t markerStyle)
void DrawH2(TH2 *hist, HistScale logx, HistScale logy, HistScale logz, const string &drawOpt)
Helper functions for drawing 1D and 2D histograms and graphs.
Histogram manager.
FairTask for matching RECO data to MC.
Convert internal data classes to cbmroot common data classes.
Ring finder implementation based on Hough Transform method.
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.
Class characterising one event by a collection of links (indices) to data objects,...
Definition CbmEvent.h:34
size_t GetNofData() const
Definition CbmEvent.cxx:53
int32_t GetNumber() const
Definition CbmEvent.h:121
double GetStartTime() const
Definition CbmEvent.h:140
uint32_t GetIndex(ECbmDataType type, uint32_t iData)
Definition CbmEvent.cxx:42
Histogram manager.
TCanvas * CreateCanvas(const std::string &name, const std::string &title, Int_t width, Int_t height)
Create and draw TCanvas and store pointer to it.
void SaveCanvasToImage(const std::string &outputDir, const std::string &options="png,eps")
Save all stored canvases to images.
TH2 * H2(const std::string &name) const
Return pointer to TH2 histogram.
void Create2(const std::string &name, const std::string &title, Int_t nofBinsX, Double_t minBinX, Double_t maxBinX, Int_t nofBinsY, Double_t minBinY, Double_t maxBinY)
Helper function for creation of 2-dimensional histograms and profiles. Template argument is a real ob...
void ReadFromFile(TFile *file)
Read histograms from file.
void ScaleByPattern(const std::string &pattern, Double_t scale)
Scale histograms which name matches specified pattern.
void WriteToFile()
Write all objects to current opened file.
void Create1(const std::string &name, const std::string &title, Int_t nofBins, Double_t minBin, Double_t maxBin)
Helper function for creation of 1-dimensional histograms and profiles. Template argument is a real ob...
TH1 * H1(const std::string &name) const
Return pointer to TH1 histogram.
double GetTime() const
Definition CbmHit.h:76
int32_t GetAddress() const
Definition CbmHit.h:74
double GetY() const
Definition CbmPixelHit.h:74
double GetX() const
Definition CbmPixelHit.h:73
int32_t GetAddress() const
Definition CbmRichDigi.h:43
double GetToT() const
Definition CbmRichDigi.h:78
double GetToT() const
Definition CbmRichHit.h:67
virtual void Exec(Option_t *option)
Inherited from FairTask.
CbmRichMCbmQaRichOnly()
Standard constructor.
CbmRichMCbmSEDisplay * fSeDisplay
bool doToT(CbmRichHit *hit)
std::array< Double_t, 2304 > ICD_offset
void InitHistograms()
Initialize histograms.
void DrawRing(CbmRichRing *ring)
std::array< Double_t, 2304 > ICD_offset_read
void DrawFromFile(const string &fileName, const string &outputDir)
Draw histogram from file.
void read_ICD(std::array< Double_t, 2304 > &offsets, unsigned int iteration)
virtual void Finish()
Inherited from FairTask.
virtual InitStatus Init()
Inherited from FairTask.
void save_ICD(std::array< Double_t, 2304 > &offsets, unsigned int iteration)
void analyseRing(CbmRichRing *ring, CbmEvent *ev)
std::array< uint32_t, 2304 > ICD_offset_cnt
Bool_t cutRadius(CbmRichRing *ring)
void DrawHist()
Draw histograms.
void SetOutDir(std::string dir)
void DrawEvent(CbmEvent *ev, std::vector< int > &ringIndx, bool full)
Draw histograms.
void SetRichRings(TClonesArray *ring=nullptr)
void SetMaxNofDrawnEvents(Int_t val=100)
void SetRichHits(TClonesArray *hits=nullptr)
void SetTotRich(Double_t min, Double_t max)
void XOffsetHistos(Double_t val=0.)
uint32_t GetHit(int32_t i) const
Definition CbmRichRing.h:39
float GetRadius() const
Definition CbmRichRing.h:79
double GetTime() const
Definition CbmRichRing.h:99
int32_t GetNofHits() const
Definition CbmRichRing.h:37
float GetCenterX() const
Definition CbmRichRing.h:77
double GetChi2() const
Definition CbmRichRing.h:92
float GetCenterY() const
Definition CbmRichRing.h:78
static uint16_t GetDirichChannel(int Address)
Definition CbmRichUtil.h:33
static uint16_t GetDirichId(int Address)
Definition CbmRichUtil.h:31
Hash for CbmL1LinkKey.