CbmRoot
CbmRichMCbmHitProducer.cxx
Go to the documentation of this file.
1 
3 
4 #include "CbmDigiManager.h"
5 #include "CbmEvent.h"
6 #include "CbmRichDetectorData.h" // for CbmRichPmtData, CbmRichPixelData
7 #include "CbmRichDigi.h"
9 #include "CbmRichGeoManager.h"
10 #include "CbmRichHit.h"
11 #include "CbmRichPoint.h"
12 #include "FairLogger.h"
13 #include "TClonesArray.h"
14 
15 
16 #include <iostream>
17 
18 using namespace std;
19 
20 
22  : FairTask("CbmRichMCbmHitProducer")
23  , fRichHits(NULL)
24  , fEventNum(0)
25  , fHitError(0.6 / sqrt(12.))
26  ,
27  //fMappingFile("mRICH_Mapping_vert_20190318.geo")
28  fMappingFile("mRICH_Mapping_vert_20190318_elView.geo") {}
29 
31  FairRootManager* manager = FairRootManager::Instance();
32  manager->Write();
33 }
34 
36 
38  FairRootManager* manager = FairRootManager::Instance();
39 
40  fCbmEvents = dynamic_cast<TClonesArray*>(manager->GetObject("CbmEvent"));
41  if (fCbmEvents == nullptr) {
42  LOG(info) << ": CbmEvent NOT found \n \n \n";
43  } else {
44  LOG(info) << ": CbmEvent found \n \n \n";
45  }
46 
48  fDigiMan->Init();
50  Fatal("CbmRichMCbmHitProducer::Init", "No RichDigi array!");
51 
52  fRichHits = new TClonesArray("CbmRichHit");
53  manager->Register(
54  "RichHit", "RICH", fRichHits, IsOutputBranchPersistent("RichHit"));
55 
56  InitMapping();
57 
58  return kSUCCESS;
59 }
60 
62 
63  string line;
64  ifstream file(fMappingFile);
65  if (!file.is_open()) {
66  std::cout
67  << "<CbmRichMCbmHitProducer::InitMapping>: Unable to open mapping file:"
68  << fMappingFile.c_str() << std::endl;
69  }
70 
71  fRichMapping.clear();
72 
73  while (getline(file, line)) {
74 
75  istringstream iss(line);
76  vector<std::string> results(istream_iterator<string> {iss},
77  std::istream_iterator<string>());
78  if (results.size() != 8) continue;
79 
81  data.fTrbId = stoi(results[0], nullptr, 16);
82  data.fChannel = stoi(results[1]);
83  data.fX = stod(results[6]);
84  data.fY = stod(results[7]);
85  data.fZ = 348.;
86 
87  data.fX -= 6.3; //Shift by 1Pmt + PmtGap + 1cm
88 
89  Int_t adr = ((data.fTrbId << 16) | (data.fChannel & 0x00FF));
90 
91  // cout << data.fTrbId << " " << data.fChannel << " " << data.fX << " " << data.fY << " " << adr << endl;
92 
93  fRichMapping[adr] = data;
94  }
95  file.close();
96 
97  //cout << "Mapping size:" << fRichMapping.size() <<endl;
98 }
99 
100 void CbmRichMCbmHitProducer::Exec(Option_t* /*option*/) {
101  fEventNum++;
102  LOG(info) << "CbmRichMCbmHitProducer Event (or TimeSlice) " << fEventNum;
103 
104  fRichHits->Delete();
105 
106  // if CbmEvent does not exist then process standard event.
107  // if CbmEvent exists then proceed all events in time slice.
108  Int_t nUnits = (fCbmEvents != nullptr) ? fCbmEvents->GetEntriesFast() : 1;
109 
110  for (Int_t iUnit = 0; iUnit < nUnits; iUnit++) {
111  CbmEvent* event = (fCbmEvents != nullptr)
112  ? static_cast<CbmEvent*>(fCbmEvents->At(iUnit))
113  : nullptr;
114  ProcessData(event);
115  }
116 }
117 
119  if (event != NULL) {
120  LOG(info) << "CbmRichMCbmHitProducer CbmEvent mode. CbmEvent # "
121  << event->GetNumber();
122  Int_t nofDigis = event->GetNofData(ECbmDataType::kRichDigi);
123  //LOG(info) << "nofDigis: " << nofDigis;
124 
125  fNofHits = 0;
126  for (Int_t iDigi = 0; iDigi < nofDigis; iDigi++) {
127  Int_t digiIndex = event->GetIndex(ECbmDataType::kRichDigi, iDigi);
128  ProcessDigi(event, digiIndex);
129  }
130  LOG(info) << "nofDigis: " << nofDigis << "\t\t "
131  << "nofHits : " << fNofHits;
132  fNofHits = 0;
133  } else {
134  for (Int_t iDigi = 0; iDigi < fDigiMan->GetNofDigis(ECbmModuleId::kRich);
135  iDigi++) {
136  ProcessDigi(event, iDigi);
137  }
138  }
139 }
140 
141 void CbmRichMCbmHitProducer::ProcessDigi(CbmEvent* event, Int_t digiIndex) {
142  const CbmRichDigi* digi = fDigiMan->Get<CbmRichDigi>(digiIndex);
143  if (digi == nullptr) return;
144  if (digi->GetAddress() < 0) return;
145  if (isInToT(digi->GetToT())) {
146  TVector3 posPoint;
147  CbmRichPixelData* data =
149  digi->GetAddress());
150 
151  if (data != nullptr) {
152  posPoint.SetXYZ(data->fX, data->fY, data->fZ);
153  } else {
154  LOG(info) << "CbmRichMCbmHitProducer: No Node for 0x" << std::hex
155  << digi->GetAddress() << std::dec
156  << " found. Using ASCII File! ";
157  CbmRichMCbmMappingData dataAscii = fRichMapping[digi->GetAddress()];
158 
159  /* if (dataAscii == NULL) {
160  LOG(error) << "CbmRichMCbmHitProducer: No Position for "<<digi->GetAddress()<<"found! ";
161  return;
162  }*/
163  posPoint.SetXYZ(dataAscii.fX, dataAscii.fY, dataAscii.fZ);
164  }
165 
166  //std::cout<<std::hex<<digi->GetAddress()<<std::dec<<" "<<data->fX<<" "<<data->fY<<" "<<data->fZ<<std::endl;
167  if (!RestrictToAcc(posPoint)) return;
168  if (!RestrictToFullAcc(posPoint)) return;
169  if (!RestrictToAerogelAccDec2019(posPoint)) return;
170  AddHit(event, posPoint, digi, digiIndex, data->fPmtId);
171  }
172 }
173 
174 
176  TVector3& posHit,
177  const CbmRichDigi* digi,
178  Int_t index,
179  Int_t PmtId) {
180  Int_t nofHits = fRichHits->GetEntriesFast();
181  new ((*fRichHits)[nofHits]) CbmRichHit();
182  CbmRichHit* hit = (CbmRichHit*) fRichHits->At(nofHits);
183  hit->SetPosition(posHit);
184  hit->SetDx(fHitError);
185  hit->SetDy(fHitError);
186  hit->SetRefId(index);
187  hit->SetTime(digi->GetTime());
188  hit->SetToT(digi->GetToT());
189  hit->SetAddress(digi->GetAddress());
190  hit->SetPmtId(PmtId);
191  // Not Implemented in Digi: hit->SetPmtId(digi->GetPmtId());
192 
193  if (event != NULL) {
194  event->AddData(ECbmDataType::kRichHit, nofHits);
195  fNofHits++;
196  }
197 }
198 
199 
201 
202 
203 bool CbmRichMCbmHitProducer::isInToT(const double ToT) {
204 
205  if (!fDoToT) return true;
206 
207  if ((ToT > fToTLimitLow) && (ToT < fToTLimitHigh)) {
208  return true;
209  } else {
210  return false;
211  }
212 }
213 
214 
216  Double_t x = pos.X();
217  Double_t y = pos.Y();
218 
219  return this->RestrictToAcc(x, y);
220 }
221 
223  Double_t x,
224  Double_t y) { //check if Track is in mRICH acceptance
225  if (fRestrictToAcc == false) return true;
226  bool inside = false;
227  if (x >= -6.25 && x <= -1.05) {
228  // left part of mRICH
229  if (y >= 8 && y <= 15.9) { inside = true; }
230  } else if (x > -1.05 && x <= 4.25) {
231  //right part
232  if (y >= 8 && y <= 13.2) { inside = true; }
233  }
234 
235  return inside;
236 }
237 
239  Double_t x = pos.X();
240  Double_t y = pos.Y();
241 
242  return this->RestrictToFullAcc(x, y);
243 }
244 
246  Double_t x,
247  Double_t y) { //check if Track is in mRICH acceptance
248  if (fRestrictToFullAcc == false) return true;
249  bool inside = false;
250  if (x >= -16.85 && x <= 4.25) { //TODO:check values
251  // left part of mRICH
252  if (y >= -23.8 && y <= 23.8) { inside = true; }
253  }
254 
255  return inside;
256 }
257 
259  Double_t x = pos.X();
260  Double_t y = pos.Y();
261 
262  return this->RestrictToAerogelAccDec2019(x, y);
263 }
264 
266  Double_t x,
267  Double_t y) { //check if Track is in mRICH acceptance
268  if (fRestrictToAerogelAccDec2019 == false) return true;
269  //bool inside = false;
270 
271  if (y > 13.5) return false;
272  if (y > 8.0 && x < 12.5) return false;
273 
274  return true;
275 }
276 
CbmRichMCbmHitProducer::CbmRichMCbmHitProducer
CbmRichMCbmHitProducer()
Default constructor.
Definition: CbmRichMCbmHitProducer.cxx:21
CbmRichPoint.h
CbmRichMCbmMappingData::fTrbId
UInt_t fTrbId
Definition: CbmRichMCbmHitProducer.h:17
CbmRichPixelData
Definition: CbmRichDetectorData.h:17
CbmRichMCbmHitProducer::fToTLimitHigh
double fToTLimitHigh
Definition: CbmRichMCbmHitProducer.h:124
ECbmDataType::kRichDigi
@ kRichDigi
CbmRichDigi
Definition: CbmRichDigi.h:25
sqrt
friend F32vec4 sqrt(const F32vec4 &a)
Definition: L1/vectors/P4_F32vec4.h:41
CbmRichMCbmMappingData::fX
Double_t fX
Definition: CbmRichMCbmHitProducer.h:19
CbmRichMCbmHitProducer::fMappingFile
std::string fMappingFile
Definition: CbmRichMCbmHitProducer.h:134
CbmDigiManager::Init
InitStatus Init()
Initialisation.
Definition: CbmDigiManager.cxx:71
CbmRichDigiMapManager.h
CbmRichMCbmHitProducer::fToTLimitLow
double fToTLimitLow
Definition: CbmRichMCbmHitProducer.h:123
CbmRichMCbmHitProducer::fHitError
Double_t fHitError
Definition: CbmRichMCbmHitProducer.h:132
CbmRichMCbmHitProducer::fRichMapping
std::map< Int_t, CbmRichMCbmMappingData > fRichMapping
Definition: CbmRichMCbmHitProducer.h:126
CbmRichMCbmHitProducer::Finish
virtual void Finish()
Inherited from FairTask.
Definition: CbmRichMCbmHitProducer.cxx:200
ECbmDataType::kRichHit
@ kRichHit
CbmHit::SetAddress
void SetAddress(Int_t address)
Definition: CbmHit.h:82
CbmRichMCbmHitProducer::Exec
virtual void Exec(Option_t *option)
Inherited from FairTask.
Definition: CbmRichMCbmHitProducer.cxx:100
CbmDigiManager::GetNofDigis
static Int_t GetNofDigis(ECbmModuleId systemId)
Definition: CbmDigiManager.cxx:62
CbmRichMCbmHitProducer::Init
virtual InitStatus Init()
Inherited from FairTask.
Definition: CbmRichMCbmHitProducer.cxx:37
CbmRichMCbmHitProducer::fRestrictToAcc
bool fRestrictToAcc
Definition: CbmRichMCbmHitProducer.h:120
CbmRichMCbmHitProducer
Definition: CbmRichMCbmHitProducer.h:24
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
CbmPixelHit::SetDy
void SetDy(Double_t dy)
Definition: CbmPixelHit.h:105
CbmHit::SetRefId
void SetRefId(Int_t refId)
Definition: CbmHit.h:81
CbmRichPixelData::fPmtId
Int_t fPmtId
Definition: CbmRichDetectorData.h:23
CbmRichGeoManager.h
CbmRichDigi.h
CbmEvent.h
CbmRichDetectorData.h
CbmRichMCbmHitProducer::AddHit
void AddHit(CbmEvent *event, TVector3 &posHit, const CbmRichDigi *digi, Int_t index, Int_t PmtId)
Add hit to the output array (and) CbmEvent if it is not NULL.
Definition: CbmRichMCbmHitProducer.cxx:175
CbmRichMCbmHitProducer::ProcessData
void ProcessData(CbmEvent *event)
Definition: CbmRichMCbmHitProducer.cxx:118
CbmRichMCbmHitProducer::SetParContainers
virtual void SetParContainers()
Inherited from FairTask.
Definition: CbmRichMCbmHitProducer.cxx:35
CbmRichDigi::GetTime
Double_t GetTime() const
Definition: CbmRichDigi.h:61
CbmDigiManager::Get
const Digi * Get(Int_t index) const
Get a digi object.
Definition: CbmDigiManager.h:52
CbmRichPixelData::fY
Double_t fY
Definition: CbmRichDetectorData.h:21
CbmRichMCbmHitProducer::fRichHits
TClonesArray * fRichHits
Definition: CbmRichMCbmHitProducer.h:117
CbmRichMCbmHitProducer.h
CbmRichMCbmHitProducer::fDoToT
bool fDoToT
Definition: CbmRichMCbmHitProducer.h:119
CbmRichMCbmHitProducer::RestrictToAcc
bool RestrictToAcc(TVector3 &pos)
Definition: CbmRichMCbmHitProducer.cxx:215
CbmRichPixelData::fX
Double_t fX
Definition: CbmRichDetectorData.h:20
ECbmModuleId::kRich
@ kRich
Ring-Imaging Cherenkov Detector.
CbmPixelHit::SetDx
void SetDx(Double_t dx)
Definition: CbmPixelHit.h:104
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmRichMCbmMappingData::fZ
Double_t fZ
Definition: CbmRichMCbmHitProducer.h:21
CbmRichMCbmHitProducer::fDigiMan
CbmDigiManager * fDigiMan
Definition: CbmRichMCbmHitProducer.h:116
CbmRichMCbmHitProducer::RestrictToAerogelAccDec2019
bool RestrictToAerogelAccDec2019(TVector3 &pos)
Definition: CbmRichMCbmHitProducer.cxx:258
CbmRichMCbmHitProducer::isInToT
bool isInToT(const double ToT)
Definition: CbmRichMCbmHitProducer.cxx:203
CbmRichDigi::GetAddress
Int_t GetAddress() const
Definition: CbmRichDigi.h:37
CbmRichMCbmHitProducer::InitMapping
void InitMapping()
Definition: CbmRichMCbmHitProducer.cxx:61
CbmRichMCbmHitProducer::fCbmEvents
TClonesArray * fCbmEvents
Definition: CbmRichMCbmHitProducer.h:118
CbmHit::SetTime
void SetTime(Double_t time)
Definition: CbmHit.h:84
CbmRichMCbmHitProducer::fEventNum
Int_t fEventNum
Definition: CbmRichMCbmHitProducer.h:128
CbmRichMCbmMappingData::fChannel
UInt_t fChannel
Definition: CbmRichMCbmHitProducer.h:18
CbmRichMCbmMappingData::fY
Double_t fY
Definition: CbmRichMCbmHitProducer.h:20
CbmRichMCbmHitProducer::fNofHits
Int_t fNofHits
Definition: CbmRichMCbmHitProducer.h:130
CbmDigiManager.h
x
Double_t x
Definition: CbmMvdSensorDigiToHitTask.cxx:68
CbmRichMCbmHitProducer::~CbmRichMCbmHitProducer
virtual ~CbmRichMCbmHitProducer()
Destructor.
Definition: CbmRichMCbmHitProducer.cxx:30
CbmPixelHit::SetPosition
void SetPosition(const TVector3 &pos)
Sets position of the hit.
Definition: CbmPixelHit.cxx:72
y
Double_t y
Definition: CbmMvdSensorDigiToHitTask.cxx:68
CbmEvent
Class characterising one event by a collection of links (indices) to data objects,...
Definition: CbmEvent.h:30
pos
TVector3 pos
Definition: CbmMvdSensorDigiToHitTask.cxx:60
CbmRichDigi::GetToT
Double_t GetToT() const
Definition: CbmRichDigi.h:67
CbmRichHit.h
CbmRichDigiMapManager::GetInstance
static CbmRichDigiMapManager & GetInstance()
Definition: CbmRichDigiMapManager.h:29
CbmRichMCbmHitProducer::ProcessDigi
void ProcessDigi(CbmEvent *event, Int_t digiIndex)
Definition: CbmRichMCbmHitProducer.cxx:141
CbmRichHit::SetToT
void SetToT(Double_t tot)
Definition: CbmRichHit.h:56
CbmRichMCbmHitProducer::fRestrictToFullAcc
bool fRestrictToFullAcc
Definition: CbmRichMCbmHitProducer.h:121
CbmRichHit
Definition: CbmRichHit.h:19
CbmRichMCbmHitProducer::RestrictToFullAcc
bool RestrictToFullAcc(TVector3 &pos)
Definition: CbmRichMCbmHitProducer.cxx:238
CbmRichHit::SetPmtId
virtual void SetPmtId(Int_t det)
Definition: CbmRichHit.h:53
CbmRichMCbmMappingData
Definition: CbmRichMCbmHitProducer.h:15
CbmRichDigiMapManager::GetPixelDataByAddress
CbmRichPixelData * GetPixelDataByAddress(Int_t address)
Definition: CbmRichDigiMapManager.cxx:267
CbmRichPixelData::fZ
Double_t fZ
Definition: CbmRichDetectorData.h:22
CbmRichMCbmHitProducer::fRestrictToAerogelAccDec2019
bool fRestrictToAerogelAccDec2019
Definition: CbmRichMCbmHitProducer.h:122