CbmRoot
Loading...
Searching...
No Matches
CbmPsdSimpleDigitizer.cxx
Go to the documentation of this file.
1/* Copyright (C) 2012-2020 Institute for Nuclear Research, Moscow
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Alla Maevskaya, Selim Seddiki, Sergey Morozov [committer], Volker Friese, Evgeny Kashirin */
4
5// -------------------------------------------------------------------------
6// ----- CbmPsdSimpleDigitizer source file -----
7// ----- Created 15/05/12 by Alla & SELIM & FLORIAN -----
8// ----- Modified 17/03/18 by Sergey Morozov -----
9// -------------------------------------------------------------------------
11
12#include "CbmLink.h"
13#include "CbmMatch.h"
14#include "CbmPsdDigi.h"
15#include "CbmPsdPoint.h"
16#include "FairRootManager.h"
17#include "TClonesArray.h"
18#include "TMath.h"
19#include "TStopwatch.h"
20
21#include <Logger.h>
22
23#include <cassert>
24#include <iomanip>
25#include <iostream>
26#include <map>
27
28using std::cout;
29using std::endl;
30using std::fixed;
31using std::right;
32using std::setprecision;
33using std::setw;
34
35using std::map;
36using std::pair;
37
38
39// ----- Default constructor -------------------------------------------
41 : CbmDigitize<CbmPsdDigi>("PsdDigitize")
42 , fNofEvents(0)
43 , fNofPoints(0.)
44 , fNofDigis(0.)
45 , fTimeTot(0.)
46 , fPointArray(NULL)
47{
48}
49// -------------------------------------------------------------------------
50
51
52// ----- Destructor ----------------------------------------------------
54// -------------------------------------------------------------------------
55
56
57// ----- Public method Init --------------------------------------------
59{
60
61 // Get RootManager
62 FairRootManager* ioman = FairRootManager::Instance();
63 assert(ioman),
64
65 // Get input array
66 fPointArray = (TClonesArray*) ioman->GetObject("PsdPoint");
67 assert(fPointArray);
68
69 // Create and register output array
71
72 // --- Read list of inactive channels
73 if (!fInactiveChannelFileName.IsNull()) {
74 LOG(info) << GetName() << ": Reading inactive channels from " << fInactiveChannelFileName;
75 auto result = ReadInactiveChannels();
76 if (!result.second) {
77 LOG(error) << GetName() << ": Error in reading from file! Task will be inactive.";
78 return kFATAL;
79 }
80 LOG(info) << GetName() << ": " << std::get<0>(result) << " lines read from file, " << fInactiveChannels.size()
81 << " channels set inactive";
82 }
83
84 // Statistics
85 fNofEvents = 0;
86 fNofPoints = 0;
87 fNofDigis = 0.;
88 fTimeTot = 0.;
89
90 LOG(info) << fName << ": Initialisation successful " << kSUCCESS;
91 return kSUCCESS;
92}
93// -------------------------------------------------------------------------
94
95
96// ----- Public method Exec --------------------------------------------
98{
99 // Event info (for event time)
100 GetEventInfo();
101
102 TStopwatch timer;
103 timer.Start();
104
105 // Loop over PsdPoints
106 Int_t nPoints = fPointArray->GetEntriesFast();
107 LOG(debug) << fName << ": processing event " << fCurrentEvent << " at t = " << fCurrentEventTime << " ns";
108
109 // Declare some variables
110 CbmPsdPoint* point = nullptr;
111 Int_t modID = -1; // module ID
112 Int_t scinID = -1; // #sciillator
113 Int_t sec;
114 std::map<UInt_t, std::pair<CbmPsdDigi, CbmMatch*>> fired_digis_map; //store Digis and Matches for each module
115
116 for (Int_t iPoint = 0; iPoint < nPoints; iPoint++) {
117 point = (CbmPsdPoint*) fPointArray->At(iPoint);
118 if (!point) continue;
119
120 CbmLink link(1., iPoint, fCurrentMCEntry, fCurrentInput);
121
122 modID = point->GetModuleID(); //marina 1-44 (45)
123 scinID = point->GetDetectorID(); //1-60
124 Double_t eLoss = point->GetEnergyLoss();
125 Double_t pTime = point->GetTime();
126 sec = (Int_t)((scinID - 1) / 6) + 1; //marina 1-10
127 UInt_t uAddress = CbmPsdAddress::GetAddress(modID, sec);
128
129 auto it = fired_digis_map.find(uAddress);
130 if (it != fired_digis_map.end()) {
131 //this key exists
132 it->second.first.SetEdep(it->second.first.GetEdep() + eLoss);
133 if (pTime < it->second.first.GetTime()) it->second.first.SetTime(pTime);
134 it->second.second->AddLink(link);
135 }
136 else {
137 //this key is new
138 CbmPsdDigi digi = CbmPsdDigi(uAddress, pTime, eLoss);
139 CbmMatch* match = new CbmMatch();
140 match->AddLink(link);
141 fired_digis_map.insert(std::make_pair(uAddress, std::make_pair(digi, match)));
142 }
143 } // Loop over MCPoints
144
145 Int_t nDigis = 0;
146 for (auto entry : fired_digis_map) {
147 Double_t eDep = entry.second.first.GetEdep();
148 Double_t eLossMIP = eDep / 0.005; // 5MeV per MIP
149 Double_t pixPerMIP = 15.; // 15 pix per MIP
150 Double_t eLossMIPSmeared = gRandom->Gaus(eLossMIP * pixPerMIP, sqrt(eLossMIP * pixPerMIP)) / pixPerMIP;
151 Double_t eLossSmeared = eLossMIPSmeared * 0.005;
152 Double_t eNoise = gRandom->Gaus(0, 15) / 50. * 0.005;
153 eLossSmeared += eNoise;
154 CbmPsdDigi* digi =
155 new CbmPsdDigi(entry.second.first.GetAddress(), entry.second.first.GetTime() + fCurrentEventTime, eLossSmeared);
156 if (fCreateMatches) {
157 SendData(digi->GetTime(), digi, entry.second.second);
158 }
159 else {
160 SendData(digi->GetTime(), digi);
161 }
162 nDigis++;
163 LOG(debug1) << fName << ": Digi " << nDigis << " Time " << entry.second.first.GetTime() + fCurrentEventTime
164 << " Section " << entry.second.first.GetSectionID() << " Module " << entry.second.first.GetModuleID()
165 << " energy " << eLossSmeared;
166 }
167
168 // --- Event log
169 timer.Stop();
170 LOG(info) << "+ " << setw(15) << GetName() << ": Event " << setw(6) << right << fCurrentEvent << " at " << fixed
171 << setprecision(3) << fCurrentEventTime << " ns, points: " << nPoints << ", digis: " << nDigis
172 << ". Exec time " << setprecision(6) << timer.RealTime() << " s.";
173
174 // --- Run statistics
175 fNofEvents++;
176 fNofPoints += nPoints;
177 fNofDigis += nDigis;
178 fTimeTot += timer.RealTime();
179}
180// -------------------------------------------------------------------------
181
182
183// ----- End-of-run ----------------------------------------------------
185{
186 std::cout << std::endl;
187 LOG(info) << "=====================================";
188 LOG(info) << GetName() << ": Run summary";
189 LOG(info) << "Events processed : " << fNofEvents;
190 LOG(info) << "PsdPoint / event : " << setprecision(1) << fNofPoints / Double_t(fNofEvents);
191 LOG(info) << "PsdDigi / event : " << fNofDigis / Double_t(fNofEvents);
192 LOG(info) << "Digis per point : " << setprecision(6) << fNofDigis / fNofPoints;
193 LOG(info) << "Real time per event : " << fTimeTot / Double_t(fNofEvents) << " s";
194 LOG(info) << "=====================================";
195}
196// -------------------------------------------------------------------------
197
198
ClassImp(CbmConverterManager)
friend fvec sqrt(const fvec &a)
int Int_t
virtual std::pair< size_t, bool > ReadInactiveChannels()
std::set< uint32_t > fInactiveChannels
void SendData(Double_t time, CbmPsdDigi *digi, CbmMatch *match=nullptr)
void AddLink(const CbmLink &newLink)
Definition CbmMatch.cxx:47
static uint32_t GetAddress(int32_t moduleId, int32_t sectionId)
Return address from system ID, module, Section.
Data class for PSD digital information.
Definition CbmPsdDigi.h:36
double GetTime() const
Time.
Definition CbmPsdDigi.h:105
int32_t GetModuleID() const
Definition CbmPsdPoint.h:61
virtual void Exec(Option_t *opt)
virtual void Finish()
End-of-run action.