31#include "TClonesArray.h"
36#include "TGeoManager.h"
50#include <boost/assign/list_of.hpp>
61using boost::assign::list_of;
66 : FairTask(
"CbmRichMCbmQaRichOnly")
73 , fNofDrawnRichTofEv(0)
75 , fMaxNofDrawnEvents(100)
77 , fOutputDir(
"result")
83 cout <<
"CbmRichMCbmQaRichOnly::Init" << endl;
85 FairRootManager* ioman = FairRootManager::Instance();
86 if (
nullptr == ioman) {
87 Fatal(
"CbmRichMCbmQaRichOnly::Init",
"RootManager not instantised!");
95 fRichHits = (TClonesArray*) ioman->GetObject(
"RichHit");
97 Fatal(
"CbmRichMCbmQaRichOnly::Init",
"No Rich Hits!");
100 fRichRings = (TClonesArray*) ioman->GetObject(
"RichRing");
102 Fatal(
"CbmRichMCbmQaRichOnly::Init",
"No Rich Rings!");
105 fCbmEvent =
dynamic_cast<TClonesArray*
>(ioman->GetObject(
"CbmEvent"));
107 Fatal(
"CbmRichMCbmQaRichOnly::Init",
"No Event!");
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);
142 fHM->
Create1<TH1D>(
"fhNofBlobEvents",
"fhNofBlobEvents;Entries", 1, 0.5, 1.5);
143 fHM->
Create1<TH1D>(
"fhNofBlobsInEvent",
"fhNofBlobsInEvent;Entries", 36, 0.5, 36.5);
146 fHM->
Create2<TH2D>(
"fhRichHitXY",
"fhRichHitXY;RICH hit X [cm];RICH hit Y [cm];Entries", 67, -20.1 +
fXOffsetHisto,
148 fHM->
Create2<TH2D>(
"fhRichHitXY_fromRing",
"fhRichHitXY_fromRing;RICH hit X [cm];RICH hit Y [cm];Entries", 67,
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);
156 fHM->
Create2<TH2D>(
"fhRichRingXY",
"fhRichRingXY;Ring center X [cm];Ring center Y [cm];Entries", 67,
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);
162 fHM->
Create2<TH2D>(
"fhRichRingRadiusY",
"fhRichRingRadiusY;Ring Radius [cm]; Y position[cm];Entries", 70, -0.05, 6.95,
164 fHM->
Create2<TH2D>(
"fhRichHitsRingRadius",
"fhRichHitsRingRadius;#Rich Hits/Ring; Ring Radius [cm];Entries", 50, -0.5,
165 49.5, 70, -0.05, 6.95);
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);
170 fHM->
Create2<TH2D>(
"fhRichRingCenterXChi2",
"fhRichRingCenterXChi2;Ring Center X [cm];\\Chi^2 ;;Entries", 67,
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);
177 fHM->
Create1<TH1D>(
"fhHitTimeEvent",
"fhHitTimeEvent;time [ns];Entries", 400, -100., 300);
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);
184 fHM->
Create2<TH2D>(
"fhHitsTimeTot",
"fhHitsTimeTot;LE [ns]; ToT [ns];#Digis;", 200, -50., 150., 300, 15.0, 30.0);
191 fHM->
H1(
"fhNofEvents")->Fill(1);
193 cout <<
"CbmRichMCbmQaRichOnly, event No. " <<
fEventNum << endl;
195 std::array<unsigned int, 2304> chnlDigis;
196 for (
auto& c : chnlDigis)
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]++;
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]);
214 uint16_t dirich = i / 32;
215 if (sum != 0)
fHM->
H1(
"fhDigisInDiRICH")->Fill(dirich, sum);
221 int nofRichHits =
fRichHits->GetEntriesFast();
222 for (
int iH = 0; iH < nofRichHits; iH++) {
224 fHM->
H2(
"fhRichHitXY")->Fill(richHit->
GetX(), richHit->
GetY());
230 auto fNCbmEvent =
fCbmEvent->GetEntriesFast();
232 for (
int i = 0; i < fNCbmEvent; i++) {
233 fHM->
H1(
"fhNofCbmEvents")->Fill(1);
239 std::vector<int> ringIndx;
240 std::vector<int> evRichHitIndx;
241 std::array<uint32_t, 36> pmtHits;
242 for (
auto& a : pmtHits)
248 evRichHitIndx.push_back(iRichHit);
254 uint32_t pmtId = (((richHit->
GetAddress()) >> 20) & 0xF) + (((richHit->
GetAddress()) >> 24) & 0xF) * 9;
257 int nofRichRings =
fRichRings->GetEntriesFast();
258 for (
int l = 0; l < nofRichRings; l++) {
262 for (
int m = 0; m < NofRingHits; m++) {
263 auto RingHitIndx = ring->
GetHit(m);
264 if (RingHitIndx == iRichHit) {
266 for (
auto check : ringIndx) {
272 if (used ==
false) ringIndx.push_back(l);
280 for (
auto a : pmtHits) {
286 fHM->
H1(
"fhNofBlobEvents")->Fill(1);
287 fHM->
H1(
"fhNofBlobsInEvent")->Fill(blob);
290 if (ringIndx.size() != 0)
fHM->
H1(
"fhNofCbmEventsRing")->Fill(1);
293 for (
unsigned int k = 0; k < ringIndx.size(); ++k) {
296 if (ring ==
nullptr)
continue;
307 for (
int j = 0; j < ring->
GetNofHits(); ++j) {
308 Int_t hitIndx = ring->
GetHit(j);
310 if (
nullptr == hit)
continue;
311 fHM->
H2(
"fhRichHitXY_fromRing")->Fill(hit->
GetX(), hit->
GetY());
324 int nofRichRings =
fRichRings->GetEntriesFast();
325 for (
int i = 0; i < nofRichRings; i++) {
327 if (ring ==
nullptr)
continue;
329 for (
int j = 1; j < ring->
GetNofHits(); ++j) {
330 Int_t hitIndx = ring->
GetHit(j);
332 if (
nullptr == hit)
continue;
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);
358 double nofEvents =
fHM->
H1(
"fhNofCbmEvents")->GetEntries();
362 fHM->
CreateCanvas(
"rich_mcbm_fhNofCbmEvents",
"rich_mcbm_fhNofCbmEvents", 600, 600);
367 fHM->
CreateCanvas(
"rich_mcbm_fhNofCbmEventsRing",
"rich_mcbm_fhNofCbmEventsRing", 600, 600);
372 fHM->
CreateCanvas(
"rich_mcbm_fhNofEvents",
"rich_mcbm_fhNofEvents", 600, 600);
377 fHM->
CreateCanvas(
"rich_mcbm_fhBlobEvents",
"rich_mcbm_fhBlobEvents", 600, 600);
382 fHM->
CreateCanvas(
"rich_mcbm_fhBlobsInCbmEvent",
"rich_mcbm_fhBlobsInCbmEvent", 600, 600);
387 fHM->
CreateCanvas(
"inner_channel_delay",
"inner_channel_delay", 1200, 600);
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);
450 TCanvas* c =
fHM->
CreateCanvas(
"rich_mcbm_rings",
"rich_mcbm_rings", 1200, 600);
465 fHM->
CreateCanvas(
"RichRingHitsVsRadius",
"RichRingHitsVsRadius", 800, 800);
471 TCanvas* c =
fHM->
CreateCanvas(
"RichRingChi2",
"RichRingChi2", 1600, 800);
481 TCanvas* c =
fHM->
CreateCanvas(
"RichRingCenterChi2",
"RichRingCenterChi2", 1600, 800);
499 TCanvas* c =
nullptr;
506 c->SetGrid(
true,
true);
509 pad =
new TH2D(ss.str().c_str(), (ss.str() +
";X [cm];Y [cm]").c_str(), 1, -15., 10., 1, -5., 20);
512 pad =
new TH2D(ss.str().c_str(), (ss.str() +
";X [cm];Y [cm]").c_str(), 1, -5., 5., 1, -5., 5);
515 pad->SetStats(
false);
520 TLine* line0 =
new TLine(-6.25, 8, -6.25, 15.9);
522 TLine* line1 =
new TLine(-6.25, 15.9, -1.05, 15.9);
524 TLine* line2 =
new TLine(-1.05, 15.9, -1.05, 13.2);
526 TLine* line3 =
new TLine(-1.05, 13.2, +4.25, 13.2);
528 TLine* line4 =
new TLine(4.25, 13.2, +4.25, 8);
530 TLine* line5 =
new TLine(4.25, 8, -6.25, 8);
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);
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();
550 xCur = (xmin + xmax) / 2.;
551 yCur = (ymin + ymax) / 2.;
556 circle->SetFillStyle(0);
557 circle->SetLineWidth(3);
563 uint nofDrawHits = 0;
566 for (
int i = 0; i < ring->
GetNofHits(); i++) {
567 Int_t hitInd = ring->
GetHit(i);
569 if (
nullptr == hit)
continue;
570 TEllipse* hitDr =
new TEllipse(hit->
GetX() - xCur, hit->
GetY() - yCur, .25);
573 hitDr->SetFillColor(kRed);
576 hitDr->SetFillColor(kBlue);
585 ss2 <<
"(x,y,r,n)=(" << setprecision(3) << ring->
GetCenterX() <<
", " << ring->
GetCenterY() <<
", "
587 TLatex* latex =
nullptr;
592 latex =
new TLatex(-4., 4., ss2.str().c_str());
601 for (
unsigned int i = 0; i <
ICD_offset.size(); ++i) {
615 std::cout <<
"Drawing Hists...";
617 std::cout <<
"DONE!" << std::endl;
621 std::cout <<
"Canvas saved to Images!" << std::endl;
626 TFile* oldFile = gFile;
627 TDirectory* oldir = gDirectory;
629 std::string s =
fOutputDir +
"/RecoHists.root";
630 TFile* outFile =
new TFile(s.c_str(),
"RECREATE");
631 if (outFile->IsOpen()) {
633 std::cout <<
"Written to Root-file \"" << s <<
"\" ...";
635 std::cout <<
"Done!" << std::endl;
639 gDirectory->cd(oldir->GetPath());
649 TFile* oldFile = gFile;
650 TDirectory* oldDir = gDirectory;
652 if (
fHM !=
nullptr)
delete fHM;
655 TFile* file =
new TFile(fileName.c_str());
677 std::cout <<
"analyse a Ring" << std::endl;
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);
685 if (
nullptr == hit)
continue;
692 const Float_t tmpHitRadius2 = (diffX * diffX + diffY * diffY);
694 if (tmpHitRadius2 < minRHit2) {
695 minRHit2 = tmpHitRadius2;
698 meanTime = meanTime / hitCnt;
701 for (
int i = 0; i < ring->
GetNofHits(); i++) {
702 Int_t hitInd = ring->
GetHit(i);
704 if (
nullptr == hit)
continue;
706 fHM->
H1(
"fhRingDeltaTime")->Fill(
static_cast<Double_t
>(meanTime - hit->
GetTime()));
714 if ((Tdiff_ring > 20.) && (Tdiff_ring < 30.)) {
723 int InnerHitCnt_cut = 0;
727 if (
nullptr == richHit)
continue;
731 if (diffX * diffX + diffY * diffY < minRHit2) {
734 if ((Tdiff_inner > 20.) && (Tdiff_inner < 30.)) {
737 std::cout << ev->
GetNumber() <<
" Address_inner: " << std::hex
744 fHM->
H1(
"fhInnerRingDeltaTime")->Fill(
static_cast<Double_t
>(meanTime - richHit->
GetTime()));
745 fHM->
H1(
"fhInnerRingToTs")->Fill(richHit->
GetToT());
749 if (InnerHitCnt == 0) {
750 fHM->
H1(
"fhInnerRingFlag")->Fill(1);
753 fHM->
H1(
"fhInnerRingFlag")->Fill(0);
755 fHM->
H1(
"fhNofInnerHits")->Fill(InnerHitCnt);
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) {
773 icd_file << i <<
"\t" << std::setprecision(25) << ICD_offsets.at(i) <<
"\n";
778 std::cout <<
"Unable to open inter channel delay file icd_offset_it_" << iteration <<
".data\n";
784 std::cout << gSystem->pwd() << std::endl;
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;
791 std::istringstream iss(line);
792 unsigned int addr = 0;
794 if (!(iss >> addr >> value)) {
795 std::cout <<
"A Problem accured in line " << lineCnt <<
"\n";
799 ICD_offsets.at(addr) += value;
804 std::cout <<
"Unable to open inter channel delay file icd_offset_it_" << iteration <<
".data\n";
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.
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,...
size_t GetNofData() const
int32_t GetNumber() const
double GetStartTime() const
uint32_t GetIndex(ECbmDataType type, uint32_t iData)
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.
int32_t GetAddress() const
int32_t GetAddress() const
TClonesArray * fRichRings
virtual void Exec(Option_t *option)
Inherited from FairTask.
CbmRichMCbmQaRichOnly()
Standard constructor.
CbmDigiManager * fDigiMan
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
int32_t GetNofHits() const
static uint16_t GetDirichChannel(int Address)
static uint16_t GetDirichId(int Address)