CbmRoot
Loading...
Searching...
No Matches
CbmRichHitProducer.cxx
Go to the documentation of this file.
1/* Copyright (C) 2004-2021 GSI/JINR-LIT, Darmstadt/Dubna
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Boris Polichtchouk, Andrey Lebedev [committer], Volker Friese */
4
12#include "CbmRichHitProducer.h"
13
14#include "CbmDigiManager.h"
15#include "CbmEvent.h"
16#include "CbmRichDetectorData.h" // for CbmRichPmtData, CbmRichPixelData
17#include "CbmRichDigi.h"
19#include "CbmRichGeoManager.h"
20#include "CbmRichHit.h"
21
22#include <FairRootManager.h>
23#include <Logger.h>
24
25#include <TClonesArray.h>
26#include <TStopwatch.h>
27
28#include <iomanip>
29#include <iostream>
30
31using namespace std;
32
33
34CbmRichHitProducer::CbmRichHitProducer() : FairTask("CbmRichHitProducer") {}
35
37{
38 FairRootManager* manager = FairRootManager::Instance();
39 manager->Write();
40}
41
43
45{
46 FairRootManager* manager = FairRootManager::Instance();
47
48 fCbmEvents = dynamic_cast<TClonesArray*>(manager->GetObject("CbmEvent"));
49 if (!fCbmEvents) {
50 LOG(info) << ": CbmEvent NOT found \n \n \n";
51 }
52 else {
53 LOG(info) << ": CbmEvent found \n \n \n";
54 }
55
57 fDigiMan->Init();
59 LOG(fatal) << "CbmRichHitProducer::Init: No RichDigi array!";
60 }
61
62 fRichHits = new TClonesArray("CbmRichHit");
63 manager->Register("RichHit", "RICH", fRichHits, IsOutputBranchPersistent("RichHit"));
64
66
67 return kSUCCESS;
68}
69
70void CbmRichHitProducer::Exec(Option_t* /*option*/)
71{
72
73 TStopwatch timer;
74 timer.Start();
75 Int_t nDigisAll = fDigiMan->GetNofDigis(ECbmModuleId::kRich);
76 Int_t nDigisUsed = 0;
77 Int_t nHits = 0;
78 Int_t nEvents = 0;
79 Int_t result = 0;
80 fRichHits->Delete();
81
82 // Time-slice processing
83 if (!fCbmEvents) nDigisUsed = ProcessData(nullptr);
84
85 // Event processing
86 else {
87 nEvents = fCbmEvents->GetEntriesFast();
88 for (Int_t iEvent = 0; iEvent < nEvents; iEvent++) {
89 CbmEvent* event = static_cast<CbmEvent*>(fCbmEvents->At(iEvent));
90 result = ProcessData(event);
91 nDigisUsed += result;
92 }
93 }
94
95 timer.Stop();
96 nHits = fRichHits->GetEntriesFast();
97 stringstream logOut;
98 logOut << setw(20) << left << GetName() << " [";
99 logOut << fixed << setw(8) << setprecision(1) << right << timer.RealTime() * 1000. << " ms] ";
100 logOut << "TS " << fNofTs;
101 if (fCbmEvents) logOut << ", events " << nEvents;
102 logOut << ", digis " << nDigisUsed << " / " << nDigisAll << ", hits " << nHits;
103 LOG(info) << logOut.str();
104 fNofTs++;
105 fNofEvents += nEvents;
106 fNofDigisAll += nDigisAll;
107 fNofDigisUsed += nDigisUsed;
108 fNofHitsAll += nHits;
109 fTime += timer.RealTime();
110}
111
113{
114 Int_t nDigis = 0;
115 if (event) {
116 Int_t nofDigis = static_cast<Int_t>(event->GetNofData(ECbmDataType::kRichDigi));
117 LOG(debug) << GetName() << ": Event mode. Event # " << event->GetNumber() << ", digis: " << nofDigis;
118 for (Int_t iDigi = 0; iDigi < nofDigis; iDigi++) {
119 Int_t digiIndex = static_cast<Int_t>(event->GetIndex(ECbmDataType::kRichDigi, iDigi));
120 ProcessDigi(event, digiIndex);
121 }
122 nDigis = nofDigis;
123 }
124 else {
126 for (Int_t iDigi = 0; iDigi < fDigiMan->GetNofDigis(ECbmModuleId::kRich); iDigi++) {
127 ProcessDigi(event, iDigi);
128 }
129 }
130 return nDigis;
131}
132
133void CbmRichHitProducer::ProcessDigi(CbmEvent* event, Int_t digiIndex)
134{
135 const CbmRichDigi* digi = fDigiMan->Get<CbmRichDigi>(digiIndex);
136 if (!digi) return;
137 if (digi->GetAddress() < 0) return;
139 TVector3 posPoint;
140 posPoint.SetXYZ(data->fX, data->fY, data->fZ);
141 TVector3 detPoint;
142
144 AddHit(event, detPoint, digi->GetTime(), digiIndex);
145}
146
147
148void CbmRichHitProducer::AddHit(CbmEvent* event, TVector3& posHit, Double_t time, Int_t index)
149{
150 Int_t nofHits = fRichHits->GetEntriesFast();
151 new ((*fRichHits)[nofHits]) CbmRichHit();
152 CbmRichHit* hit = static_cast<CbmRichHit*>(fRichHits->At(nofHits));
153 hit->SetPosition(posHit);
154 hit->SetDx(fHitError);
155 hit->SetDy(fHitError);
156 hit->SetRefId(index);
157 hit->SetTime(time);
158
159 if (event) {
160 event->AddData(ECbmDataType::kRichHit, nofHits);
161 }
162}
163
165{
166 fRichHits->Clear();
167 std::cout << std::endl;
168 LOG(info) << "=====================================";
169 LOG(info) << GetName() << ": Run summary";
170 LOG(info) << "Time slices : " << fNofTs;
171 LOG(info) << "Digis / TS : " << fixed << setprecision(2) << Double_t(fNofDigisAll) / Double_t(fNofTs);
172 LOG(info) << "Used digis / TS : " << fixed << setprecision(2) << Double_t(fNofDigisUsed) / Double_t(fNofTs);
173 LOG(info) << "Time / TS : " << fixed << setprecision(2) << 1000. * fTime / Double_t(fNofTs) << " ms";
174 if (fCbmEvents) {
175 LOG(info) << "Events : " << fNofEvents;
176 LOG(info) << "Events / TS : " << fixed << setprecision(2) << fNofEvents / (Double_t) fNofTs;
177 if (fNofEvents > 0) {
178 LOG(info) << "Digis / Ev : " << fixed << setprecision(2) << Double_t(fNofDigisAll) / Double_t(fNofEvents);
179 LOG(info) << "Used digis / Ev : " << fixed << setprecision(2) << Double_t(fNofDigisUsed) / Double_t(fNofEvents);
180 LOG(info) << "Time / Ev : " << fixed << setprecision(2) << 1000. * fTime / Double_t(fNofEvents) << " ms";
181 }
182 }
183 LOG(info) << "=====================================\n";
184}
185
186
ClassImp(CbmConverterManager)
@ kRich
Ring-Imaging Cherenkov Detector.
Class for producing RICH hits directly from MCPoints.
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
void SetRefId(int32_t refId)
Definition CbmHit.h:82
void SetTime(double time)
Definition CbmHit.h:85
void SetDx(double dx)
Definition CbmPixelHit.h:94
void SetDy(double dy)
Definition CbmPixelHit.h:95
void SetPosition(const TVector3 &pos)
Sets position of the hit.
static CbmRichDigiMapManager & GetInstance()
Return Instance of CbmRichGeoManager.
CbmRichPixelData * GetPixelDataByAddress(Int_t address)
Return CbmRichDataPixel by digi address.
int32_t GetAddress() const
Definition CbmRichDigi.h:43
double GetTime() const
Definition CbmRichDigi.h:72
void RotatePoint(TVector3 *inPos, TVector3 *outPos, Bool_t noTilting=false)
static CbmRichGeoManager & GetInstance()
Class for producing RICH hits directly from MCPoints.
CbmRichHitProducer()
Default constructor.
void AddHit(CbmEvent *event, TVector3 &posHit, Double_t time, Int_t index)
Add hit to the output array (and) CbmEvent if it is not NULL.
virtual ~CbmRichHitProducer()
Destructor.
virtual void SetParContainers()
Inherited from FairTask.
CbmDigiManager * fDigiMan
TClonesArray * fRichHits
virtual InitStatus Init()
Inherited from FairTask.
void ProcessDigi(CbmEvent *event, Int_t digiIndex)
TClonesArray * fCbmEvents
virtual void Exec(Option_t *option)
Inherited from FairTask.
virtual void Finish()
Inherited from FairTask.
Int_t ProcessData(CbmEvent *event)
Hash for CbmL1LinkKey.