CbmRoot
CbmRichDigitizer.cxx
Go to the documentation of this file.
1 
8 #include "CbmRichDigitizer.h"
9 #include "CbmLink.h"
10 #include "CbmMCTrack.h"
11 #include "CbmMatch.h"
12 #include "CbmRichDetectorData.h" // for CbmRichPmtData, CbmRichPixelData
13 #include "CbmRichDigi.h"
14 #include "CbmRichDigiMapManager.h"
15 #include "CbmRichGeoManager.h"
16 #include "CbmRichPoint.h"
17 #include "FairEventHeader.h"
18 #include "FairLogger.h"
19 #include "FairRunAna.h"
20 #include "FairRunSim.h"
21 #include "TClonesArray.h"
22 #include "TGeoManager.h"
23 #include "TRandom.h"
24 #include "TStopwatch.h"
25 #include <cassert>
26 #include <iomanip>
27 #include <iostream>
28 
29 using namespace std;
30 
32  : CbmDigitize<CbmRichDigi>("RichDigitize")
33  , fEventNum(0)
34  , fRichPoints(NULL)
35  , fRichDigis(NULL)
36  , fRichDigiMatches(nullptr)
37  , fMcTracks(NULL)
38  , fNofPoints(0.)
39  , fNofDigis(0.)
40  , fTimeTot(0.)
41  , fPmt()
42  , fCrossTalkProbability(0.02)
43  , fNoiseDigiRate(5.)
44  , fDetectorType(CbmRichPmtTypeCosy17NoWls)
45  , fMaxNofHitsPerPmtCut(65)
46  , fDataMap()
47  , fTimeResolution(1.)
48  , fDarkRatePerPixel(1000)
49  , fPixelDeadTime(30.)
50  , fFiredPixelsMap()
51  , fDoZShift(true) {}
52 
54 
55 
56 InitStatus CbmRichDigitizer::Init() {
57 
58  // Screen output
59  std::cout << std::endl;
60  LOG(info) << "==========================================================";
61  LOG(info) << GetName() << ": Initialisation";
62 
63  //FairTask* daq = FairRun::Instance()->GetTask("Daq");
64  if (!fEventMode) {
65  LOG(info) << "CbmRichDigitizer uses TimeBased mode.";
66  } else {
67  LOG(info) << "CbmRichDigitizer uses Events mode.";
68  }
69 
70  FairRootManager* manager = FairRootManager::Instance();
71 
72  // --- Initialise helper singletons in order not to do it in event
73  // --- processing (spoils timing measurement)
76 
77  fRichPoints = (TClonesArray*) manager->GetObject("RichPoint");
78  if (NULL == fRichPoints) {
79  Fatal("CbmRichDigitizer::Init", "No RichPoint array!");
80  }
81 
82  fMcTracks = (TClonesArray*) manager->GetObject("MCTrack");
83  if (NULL == fMcTracks) {
84  Fatal("CbmRichDigitizer::Init", "No MCTrack array!");
85  }
86 
88 
89 
90  LOG(info) << GetName() << ": Initialisation successful";
91 
92  fFiredPixelsMap.clear();
93 
94  return kSUCCESS;
95 }
96 
97 void CbmRichDigitizer::Exec(Option_t* /*option*/) {
98  TStopwatch timer;
99  timer.Start();
100 
101  fEventNum++;
102  LOG(debug) << fName << ": Event " << fEventNum;
103 
104 
105  // Clear data map
106  for (auto& data : fDataMap) {
107  if (data.second.first) delete data.second.first; // digi
108  if (data.second.second) delete data.second.second; // match
109  }
110  fDataMap.clear();
111 
112  Double_t oldEventTime = fCurrentEventTime;
113  GetEventInfo();
114 
115  LOG(debug) << fName << ": EventNumber: " << fCurrentEvent
116  << ", EventTime: " << fCurrentEventTime;
117 
118  if (fProduceNoise)
120 
121  Int_t nPoints = ProcessMcEvent();
122 
123  Int_t nDigis = AddDigisToOutputArray();
124 
125 
126  // --- Statistics
127  timer.Stop();
128  fNofPoints += nPoints;
129  fNofDigis += nDigis;
130  fTimeTot += timer.RealTime();
131 
132  // --- Event log
133  LOG(info) << "+ " << setw(15) << GetName() << ": Event " << setw(6) << right
134  << fCurrentEvent << " at " << fixed << setprecision(3)
135  << fCurrentEventTime << " ns, points: " << nPoints
136  << ", digis: " << nDigis << ". Exec time " << setprecision(6)
137  << timer.RealTime() << " s.";
138 }
139 
141  Int_t nofRichPoints = fRichPoints->GetEntries();
142  LOG(debug) << fName << ": EventNum:" << fCurrentEvent
143  << " InputNum:" << fCurrentInput
144  << " EventTime:" << fCurrentEventTime
145  << " nofRichPoints:" << nofRichPoints;
146 
147  for (Int_t j = 0; j < nofRichPoints; j++) {
148  CbmRichPoint* point = (CbmRichPoint*) fRichPoints->At(j);
150  }
151  // cout << "nofDigis:" << fRichDigis->GetEntries() << endl;
152 
154 
155  return nofRichPoints;
156 }
157 
159  Double_t newEventTime) {
160  Int_t nofPixels =
162  Double_t dT = newEventTime - oldEventTime;
163  Double_t nofNoisePixels = nofPixels * dT * (fDarkRatePerPixel / 1.e9);
164 
165  LOG(debug) << "CbmRichDigitizer::GenerateNoiseBetweenEvents deltaTime:" << dT
166  << " nofPixels:" << nofPixels
167  << " nofNoisePixels:" << nofNoisePixels;
168 
169  for (Int_t j = 0; j < nofNoisePixels; j++) {
170  Int_t address =
172  CbmLink link(1., -1, -1, -1);
173  Double_t time = gRandom->Uniform(oldEventTime, newEventTime);
174  AddDigi(address, time, link);
175  }
176 }
177 
179  Int_t pointId,
180  Int_t eventNum,
181  Int_t inputNum) {
182  // LOG(info) << "ProcessPoint " << pointId;
183  // TGeoNode* node = gGeoManager->FindNode(point->GetX(), point->GetY(), point->GetZ());
184  // workaround for GEANT4, probably boundary problem
185  Double_t zNew = point->GetZ();
186  if (fDoZShift) zNew = zNew - 0.001;
187  gGeoManager->FindNode(point->GetX(), point->GetY(), zNew);
188  string path(gGeoManager->GetPath());
189  Int_t address =
191 
192  Int_t trackId = point->GetTrackID();
193  if (trackId < 0) return;
194  CbmMCTrack* p = (CbmMCTrack*) fMcTracks->At(trackId);
195  if (p == NULL) return;
196  Int_t gcode = TMath::Abs(p->GetPdgCode());
197 
198  CbmLink link(1., pointId, eventNum, inputNum);
199 
200  Bool_t isDetected = false;
201  // for photons weight with efficiency of PMT
202  if (gcode == 50000050) {
203  TVector3 mom;
204  point->Momentum(mom);
205  Double_t momTotal =
206  sqrt(mom.Px() * mom.Px() + mom.Py() * mom.Py() + mom.Pz() * mom.Pz());
207  isDetected = fPmt.isPhotonDetected(fDetectorType, momTotal);
208  } else { // if not photon
209  // worst case: assume that all charged particles crossing
210  // the PMTplane leave Cherenkov light in the PMTglass which will be detected
211  isDetected = true;
212  }
213 
214  Double_t time = fCurrentEventTime + point->GetTime();
215  Double_t deltaT = gRandom->Gaus(0., fTimeResolution);
216  time += deltaT;
217  if (isDetected) { AddDigi(address, time, link); }
218 }
219 
220 
222  std::cout << std::endl;
223  LOG(info) << "=====================================";
224  LOG(info) << GetName() << ": Run summary";
225  LOG(info) << "Events processed : " << fEventNum;
226  LOG(info) << "RichPoint / event : " << setprecision(1)
227  << fNofPoints / Double_t(fEventNum);
228  LOG(info) << "RichDigi / event : " << fNofDigis / Double_t(fEventNum);
229  LOG(info) << "Digis per point : " << setprecision(6)
230  << fNofDigis / fNofPoints;
231  LOG(info) << "Real time per event : " << fTimeTot / Double_t(fEventNum)
232  << " s";
233  LOG(info) << "=====================================";
234 }
235 
237  Bool_t crosstalkDigiDetected = false;
238  vector<Int_t> directPixels =
240  digi->GetAddress());
241  vector<Int_t> diagonalPixels =
243  digi->GetAddress());
244 
245  for (UInt_t i = 0; i < directPixels.size(); i++) {
246  if (gRandom->Rndm() < fCrossTalkProbability && !crosstalkDigiDetected) {
247  //FindRichHitPositionMAPMT(0., x + r, y, xHit, yHit, pmtID);
248  crosstalkDigiDetected = true;
249  break;
250  }
251  }
252 
253  if (!crosstalkDigiDetected) {
254  for (UInt_t i = 0; i < diagonalPixels.size(); i++) {
255  if (gRandom->Rndm() < fCrossTalkProbability / 4.
256  && !crosstalkDigiDetected) {
257  //FindRichHitPositionMAPMT(0., x + r, y, xHit, yHit, pmtID);
258  crosstalkDigiDetected = true;
259  break;
260  }
261  }
262  }
263 
264  if (crosstalkDigiDetected) {
265  //AddDigi(posHit, posHitErr, RichDetID, pmtID, ampl, pointInd);
266  //fNofCrossTalkDigis++;
267  }
268 }
269 
271  Int_t nofDigis = 0;
272 
273  // fMaxNofHitsPerPmtCut is a maximum number of hits which can be registered per PMT per event.
274  // If more then the whole PMT is skipped
275  map<Int_t, Int_t> digisPerPmtMap;
276  for (auto const& dm : fDataMap) {
277  CbmRichPixelData* pixelData =
279  dm.second.first->GetAddress());
280  if (nullptr == pixelData) continue;
281  Int_t pmtId = pixelData->fPmtId;
282  digisPerPmtMap[pmtId]++;
283  }
284 
285  Int_t nofSkippedPmts = 0;
286  for (auto const& dm : digisPerPmtMap) {
287  if (dm.second > fMaxNofHitsPerPmtCut) nofSkippedPmts++;
288  }
289 
290  Int_t nofSkippedDigis = 0;
291  for (auto const& dm : fDataMap) {
292  CbmRichPixelData* pixelData =
294  dm.second.first->GetAddress());
295  if (nullptr == pixelData) continue;
296  if (digisPerPmtMap[pixelData->fPmtId] > fMaxNofHitsPerPmtCut) {
297  nofSkippedDigis++;
298  continue;
299  }
300 
301  CbmRichDigi* digi = new CbmRichDigi();
302  digi->SetAddress(dm.second.first->GetAddress());
303  CbmMatch* digiMatch = new CbmMatch(*dm.second.second);
304  digi->SetTime(dm.second.first->GetTime());
305  //SendDigi(digi, digiMatch);
306  if (fCreateMatches)
307  SendData(digi, digiMatch);
308  else
309  SendData(digi);
310  nofDigis++;
311  } //# digis in map
312 
313  LOG(debug) << "Number of RICH digis before skip: " << fDataMap.size();
314  LOG(debug) << "Nof skipped PMTs:" << nofSkippedPmts;
315  LOG(debug) << "Nof skipped digis:" << nofSkippedDigis;
316  LOG(debug) << "Number of RICH digis: " << nofDigis;
317  return nofDigis;
318 }
319 
320 void CbmRichDigitizer::AddNoiseDigis(Int_t eventNum, Int_t inputNum) {
321  Int_t nofPixels =
323  Double_t dT = 50.; //ns
324  Double_t nofRichPoints = fRichPoints->GetEntries();
325  Double_t nofNoiseDigis =
326  nofRichPoints * nofPixels * dT * (fNoiseDigiRate / 1.e9);
327 
328  LOG(debug) << "CbmRichDigitizer::AddNoiseDigis NofAllPixels:" << nofPixels
329  << " nofNoiseDigis:" << nofNoiseDigis;
330  for (Int_t j = 0; j < nofNoiseDigis; j++) {
331  Int_t address =
333  CbmLink link(1., -1, eventNum, inputNum);
334  Double_t time = fCurrentEventTime + gRandom->Uniform(0, dT);
335  AddDigi(address, time, link);
336  }
337 }
338 
339 void CbmRichDigitizer::AddDigi(Int_t address,
340  Double_t time,
341  const CbmLink& link) {
342  Bool_t wasFired = fFiredPixelsMap.count(address) > 0;
343  Bool_t isDetected = true;
344  if (!fEventMode && wasFired) {
345  Double_t lastFiredTime = fFiredPixelsMap[address];
346  Double_t dt = std::fabs(time - lastFiredTime);
347  if (dt < fPixelDeadTime) {
348  isDetected = false;
349  // LOG(info) << "CbmRichDigitizer::AddDigi pixel NOT registered: address:" << address << " cur-last=dT: "<< time << "-"
350  // << lastFiredTime << "=" << dt << " fPixelDeadTime:" << fPixelDeadTime
351  // << " fFiredPixelsMap.size():" << fFiredPixelsMap.size() << " link: " << link.GetIndex();
352  } else {
353  isDetected = true;
354  // LOG(info) << "CbmRichDigitizer::AddDigi pixel registered: address:" << address << " cur-last=dT: "<< time << "-"
355  // << lastFiredTime << "=" << dt << " fPixelDeadTime:" << fPixelDeadTime
356  // << " fFiredPixelsMap.size():" << fFiredPixelsMap.size() << " link: " << link.GetIndex();
357  }
358  } else {
359  isDetected = true;
360  // LOG(info) << "CbmRichDigitizer::AddDigi pixel was not fired before: address:" << address << " time:" << time
361  // << " fFiredPixelsMap.size():" << fFiredPixelsMap.size() << " link: " << link.GetIndex();
362  }
363 
364  if (isDetected) {
365  auto it = fDataMap.find(address);
366  if (it == fDataMap.end()) {
367  CbmRichDigi* digi = new CbmRichDigi();
368  digi->SetAddress(address);
369  digi->SetTime(time);
370  CbmMatch* match = new CbmMatch();
371  match->AddLink(link);
372  pair<CbmRichDigi*, CbmMatch*> value(digi, match);
373  fDataMap.insert(
374  pair<Int_t, pair<CbmRichDigi*, CbmMatch*>>(address, value));
375  } else {
376  CbmMatch* match = it->second.second;
377  match->AddLink(link);
378  }
379  }
380 
381  fFiredPixelsMap[address] = time;
382 }
383 
384 
CbmRichPoint.h
CbmRichPixelData
Definition: CbmRichDetectorData.h:17
CbmMatch
Definition: CbmMatch.h:22
CbmRichDigiMapManager::GetPixelAddresses
std::vector< Int_t > GetPixelAddresses()
Definition: CbmRichDigiMapManager.cxx:280
CbmRichDigitizer::fDetectorType
CbmRichPmtTypeEnum fDetectorType
Definition: CbmRichDigitizer.h:142
CbmRichDigitizer::AddNoiseDigis
void AddNoiseDigis(Int_t eventNum, Int_t inputNum)
Definition: CbmRichDigitizer.cxx:320
CbmRichDigitizer::AddDigi
void AddDigi(Int_t address, Double_t time, const CbmLink &link)
Definition: CbmRichDigitizer.cxx:339
CbmRichGeoManager::GetInstance
static CbmRichGeoManager & GetInstance()
Definition: CbmRichGeoManager.h:29
CbmDigitizeBase::GetEventInfo
void GetEventInfo()
Get event information.
Definition: CbmDigitizeBase.cxx:48
CbmRichDigi
Definition: CbmRichDigi.h:25
CbmDigitizeBase::fCreateMatches
Bool_t fCreateMatches
Flag for production of inter-event noise.
Definition: CbmDigitizeBase.h:161
sqrt
friend F32vec4 sqrt(const F32vec4 &a)
Definition: L1/vectors/P4_F32vec4.h:41
CbmRichDigitizer::fPixelDeadTime
Double_t fPixelDeadTime
Definition: CbmRichDigitizer.h:151
CbmMCTrack::GetPdgCode
Int_t GetPdgCode() const
Definition: CbmMCTrack.h:70
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
CbmRichDigiMapManager.h
CbmRichDigitizer::fPmt
CbmRichPmt fPmt
Definition: CbmRichDigitizer.h:136
CbmDigitizeBase::fCurrentMCEntry
Int_t fCurrentMCEntry
Number of current MC event.
Definition: CbmDigitizeBase.h:164
CbmRichDigitizer::fFiredPixelsMap
map< Int_t, Double_t > fFiredPixelsMap
Definition: CbmRichDigitizer.h:153
CbmRichDigitizer::Init
virtual InitStatus Init()
Inherited from FairTask.
Definition: CbmRichDigitizer.cxx:56
CbmRichDigitizer::fMaxNofHitsPerPmtCut
Int_t fMaxNofHitsPerPmtCut
Definition: CbmRichDigitizer.h:144
CbmMatch.h
CbmRichDigitizer::GenerateNoiseBetweenEvents
void GenerateNoiseBetweenEvents(Double_t oldEventTime, Double_t newEventTime)
Definition: CbmRichDigitizer.cxx:158
CbmRichDigitizer::fDataMap
map< Int_t, pair< CbmRichDigi *, CbmMatch * > > fDataMap
Definition: CbmRichDigitizer.h:147
CbmRichDigiMapManager::GetDirectNeighbourPixels
std::vector< Int_t > GetDirectNeighbourPixels(Int_t address)
Definition: CbmRichDigiMapManager.cxx:296
CbmRichDigitizer::fMcTracks
TClonesArray * fMcTracks
Definition: CbmRichDigitizer.h:130
CbmRichPixelData::fPmtId
Int_t fPmtId
Definition: CbmRichDetectorData.h:23
CbmRichGeoManager.h
CbmRichDigi.h
CbmRichDigitizer::fNoiseDigiRate
Double_t fNoiseDigiRate
Definition: CbmRichDigitizer.h:140
CbmRichDigitizer::fNofPoints
Double_t fNofPoints
Definition: CbmRichDigitizer.h:132
CbmRichDigitizer::fTimeResolution
Double_t fTimeResolution
Definition: CbmRichDigitizer.h:149
CbmRichPmt::isPhotonDetected
Bool_t isPhotonDetected(CbmRichPmtTypeEnum detType, Double_t momentum)
Definition: CbmRichPmt.cxx:42
CbmRichDigitizer::Exec
virtual void Exec(Option_t *option)
Inherited from FairTask.
Definition: CbmRichDigitizer.cxx:97
CbmRichDetectorData.h
CbmRichDigitizer::CbmRichDigitizer
CbmRichDigitizer()
Default constructor.
Definition: CbmRichDigitizer.cxx:31
CbmRichDigitizer::fDarkRatePerPixel
Double_t fDarkRatePerPixel
Definition: CbmRichDigitizer.h:150
CbmRichDigitizer::~CbmRichDigitizer
virtual ~CbmRichDigitizer()
Destructor.
Definition: CbmRichDigitizer.cxx:53
CbmDigitizeBase::fProduceNoise
Bool_t fProduceNoise
Flag for event-by-event mode.
Definition: CbmDigitizeBase.h:160
CbmRichDigitizer::fCrossTalkProbability
Double_t fCrossTalkProbability
Definition: CbmRichDigitizer.h:138
CbmDigitize
Base class template for CBM digitisation tasks.
Definition: CbmDigitize.h:39
CbmDigitizeBase::fEventMode
Bool_t fEventMode
Definition: CbmDigitizeBase.h:159
CbmDigitizeBase::fCurrentEvent
Int_t fCurrentEvent
Number of current input.
Definition: CbmDigitizeBase.h:163
CbmRichPmtTypeCosy17NoWls
@ CbmRichPmtTypeCosy17NoWls
Definition: CbmRichPmtType.h:13
CbmMatch::AddLink
void AddLink(const CbmLink &newLink)
Definition: CbmMatch.cxx:42
CbmRichDigitizer::AddCrossTalkDigis
void AddCrossTalkDigis(CbmRichDigi *digi)
Definition: CbmRichDigitizer.cxx:236
CbmDigitizeBase::fCurrentInput
Int_t fCurrentInput
Flag for creation of links to MC.
Definition: CbmDigitizeBase.h:162
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmDigitizeBase::fCurrentEventTime
Double_t fCurrentEventTime
Number of current MC entry.
Definition: CbmDigitizeBase.h:165
CbmRichDigitizer::fEventNum
Int_t fEventNum
Definition: CbmRichDigitizer.h:125
CbmRichDigitizer.h
Class for producing RICH digis from from MCPoints.
CbmRichDigitizer::ProcessPoint
void ProcessPoint(CbmRichPoint *point, Int_t pointId, Int_t eventNum, Int_t inputNum)
Definition: CbmRichDigitizer.cxx:178
CbmRichDigi::SetTime
void SetTime(Double_t time)
Definition: CbmRichDigi.h:77
CbmRichDigiMapManager::GetDiagonalNeighbourPixels
std::vector< Int_t > GetDiagonalNeighbourPixels(Int_t address)
Definition: CbmRichDigiMapManager.cxx:303
CbmRichDigitizer::fDoZShift
Bool_t fDoZShift
Definition: CbmRichDigitizer.h:155
CbmDigitize< CbmRichDigi >::SendData
void SendData(CbmRichDigi *digi, CbmMatch *match=nullptr)
Send a digi and the corresponding match object to the DAQ.
Definition: CbmDigitize.h:219
CbmRichDigi::GetAddress
Int_t GetAddress() const
Definition: CbmRichDigi.h:37
CbmRichDigiMapManager::GetPixelAddressByPath
Int_t GetPixelAddressByPath(const std::string &path)
Definition: CbmRichDigiMapManager.cxx:259
CbmRichDigitizer
Class for producing RICH digis from from MCPoints.
Definition: CbmRichDigitizer.h:36
CbmMCTrack.h
CbmRichDigitizer::Finish
virtual void Finish()
Inherited from FairTask.
Definition: CbmRichDigitizer.cxx:221
CbmRichDigiMapManager::GetRandomPixelAddress
Int_t GetRandomPixelAddress()
Definition: CbmRichDigiMapManager.cxx:274
CbmRichDigitizer::AddDigisToOutputArray
Int_t AddDigisToOutputArray()
Definition: CbmRichDigitizer.cxx:270
CbmMCTrack
Definition: CbmMCTrack.h:34
fabs
friend F32vec4 fabs(const F32vec4 &a)
Definition: L1/vectors/P4_F32vec4.h:60
CbmRichDigitizer::fTimeTot
Double_t fTimeTot
Definition: CbmRichDigitizer.h:134
CbmDigitize< CbmRichDigi >::RegisterOutput
void RegisterOutput()
Register the output arrays.
Definition: CbmDigitize.h:175
CbmRichDigitizer::fRichPoints
TClonesArray * fRichPoints
Definition: CbmRichDigitizer.h:127
CbmRichPoint
Definition: CbmRichPoint.h:24
CbmRichDigiMapManager::GetInstance
static CbmRichDigiMapManager & GetInstance()
Definition: CbmRichDigiMapManager.h:29
CbmRichDigi::SetAddress
void SetAddress(Int_t address)
Definition: CbmRichDigi.h:72
CbmRichDigitizer::fNofDigis
Double_t fNofDigis
Definition: CbmRichDigitizer.h:133
CbmRichDigiMapManager::GetPixelDataByAddress
CbmRichPixelData * GetPixelDataByAddress(Int_t address)
Definition: CbmRichDigiMapManager.cxx:267
CbmRichDigitizer::ProcessMcEvent
Int_t ProcessMcEvent()
Definition: CbmRichDigitizer.cxx:140