CbmRoot
Loading...
Searching...
No Matches
CbmStsDigitizePixel.cxx
Go to the documentation of this file.
1/* Copyright (C) 2021 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergey Gorbunov [committer] */
4
10// Include class header
11#include "CbmStsDigitizePixel.h"
12
13// Includes from C++
14#include <cassert>
15#include <cstring>
16#include <fstream>
17#include <iomanip>
18#include <iostream>
19#include <sstream>
20
21// Includes from ROOT
22#include "TClonesArray.h"
23#include "TGeoBBox.h"
24#include "TGeoMatrix.h"
25#include "TGeoPhysicalNode.h"
26#include "TGeoVolume.h"
27#include <TMCProcess.h>
28
29// Includes from FairRoot
30#include "FairEventHeader.h"
31#include "FairField.h"
32#include "FairLink.h"
33#include "FairMCEventHeader.h"
34#include "FairMCPoint.h"
35#include "FairRunAna.h"
36#include "FairRunSim.h"
37#include "FairRuntimeDb.h"
38#include <Logger.h>
39
40#include <TRandom.h>
41
42// Includes from CbmRoot
43#include "CbmStsDigi.h"
44#include "CbmStsParSetModule.h"
45#include "CbmStsPoint.h"
46#include "CbmStsSetup.h"
47
48// Includes from STS
49#include "CbmStsModule.h"
50#include "CbmStsParAsic.h"
51#include "CbmStsParModule.h"
52#include "CbmStsParSensor.h"
53#include "CbmStsParSensorCond.h"
54#include "CbmStsParSetModule.h"
55#include "CbmStsParSetSensor.h"
57#include "CbmStsParSim.h"
58#include "CbmStsPhysics.h"
59#include "CbmStsSensor.h"
60#include "CbmStsSetup.h"
62
63
64using std::fixed;
65using std::left;
66using std::right;
67using std::setprecision;
68using std::setw;
69using std::string;
70using std::stringstream;
71
72using namespace CbmSts;
73
75
76// ----- Standard constructor ------------------------------------------
78// -------------------------------------------------------------------------
79
80// ----- Standard constructor ------------------------------------------
81CbmStsDigitizePixel::CbmStsDigitizePixel(Double_t resolutionXcm, Double_t resolutionYcm, Double_t resolutionTns,
82 int nPixelStations)
83 : CbmDigitize<CbmStsDigi>("StsDigitizePixel")
84 , fPixelNstations(nPixelStations)
85 , fPixelResolutionXcm(resolutionXcm)
86 , fPixelResolutionYcm(resolutionYcm)
87 , fPixelResolutionTns(resolutionTns)
88{
89}
90// -------------------------------------------------------------------------
91
92
93// ----- Destructor ----------------------------------------------------
95// -------------------------------------------------------------------------
96
97
98// ----- Finish run ---------------------------------------------------
100// -------------------------------------------------------------------------
101
102
103// ----- Get parameter container from runtime DB -----------------------
105{
106 assert(FairRunAna::Instance());
107 FairRuntimeDb* rtdb = FairRunAna::Instance()->GetRuntimeDb();
108 fParSim = static_cast<CbmStsParSim*>(rtdb->getContainer("CbmStsParSim"));
109 fParSetModule = static_cast<CbmStsParSetModule*>(rtdb->getContainer("CbmStsParSetModule"));
110 fParSetSensor = static_cast<CbmStsParSetSensor*>(rtdb->getContainer("CbmStsParSetSensor"));
111 fParSetCond = static_cast<CbmStsParSetSensorCond*>(rtdb->getContainer("CbmStsParSetSensorCond"));
112}
113// -------------------------------------------------------------------------
114
115
116// ----- Initialisation -----------------------------------------------
118{
119
120 // --- Instantiate StsPhysics
122
123 // Initialise the STS setup interface from TGeoManager
125 if (!fSetup->IsInit()) { fSetup->Init(nullptr); }
126
127 // --- Initialise parameters
128 InitParams();
129
130 // --- Get FairRootManager instance
131 FairRootManager* ioman = FairRootManager::Instance();
132 assert(ioman);
133
134 // --- Get input array (CbmStsPoint)
135 fPoints = (TClonesArray*) ioman->GetObject("StsPoint");
136 assert(fPoints);
137
138 // always create matches
139
140 SetCreateMatches(kTRUE);
141
143
144 return kSUCCESS;
145}
146// -------------------------------------------------------------------------
147
148
149// ----- Private method ReInit -----------------------------------------
150InitStatus CbmStsDigitizePixel::ReInit() { return Init(); }
151// -------------------------------------------------------------------------
152
153
154// ----- Task execution ------------------------------------------------
155void CbmStsDigitizePixel::Exec(Option_t* /*opt*/)
156{
157 TStopwatch timer;
158
159 // --- Get current event time.
160 GetEventInfo();
161
162 // ----- Process points from MC event ---------------------------------
163
164 assert(fPoints);
165
166 std::vector<std::pair<double, int>> sortedPoints;
167 sortedPoints.reserve(fPoints->GetEntriesFast());
168
169 for (Int_t iPoint = 0; iPoint < fPoints->GetEntriesFast(); iPoint++) {
170 const CbmStsPoint* point = (const CbmStsPoint*) fPoints->At(iPoint);
171 sortedPoints.push_back(std::make_pair(point->GetTime(), iPoint));
172 }
173
174 std::sort(sortedPoints.begin(), sortedPoints.end(),
175 [](std::pair<double, int>& left, std::pair<double, int>& right) { return left.first < right.first; });
176
177 for (UInt_t iSorted = 0; iSorted < sortedPoints.size(); iSorted++) {
178 Int_t iPoint = sortedPoints[iSorted].second;
179 const CbmStsPoint* point = (const CbmStsPoint*) fPoints->At(iPoint);
180
181 UInt_t address = static_cast<UInt_t>(point->GetDetectorID());
182 UShort_t channel = 0;
183 double timef = fCurrentEventTime + point->GetTime();
184
185 if (fSetup->GetStationNumber(address) < fPixelNstations) { timef += gRandom->Gaus(0, fPixelResolutionTns); }
186 else {
187 timef += gRandom->Gaus(0, fStripResolutionTns);
188 }
189
190 Long64_t time = Long64_t(round(timef));
191 if (time < 0) { time = 0; }
192 UShort_t adc = 30;
193 assert(time >= 0);
194
195 // Create digi and (if required) match and send them to DAQ
196 // The time is sent separately from the digi in double precision.
197 // It will be set in the digi later, when creating the timestamp for the time slice.
198
199 CbmStsDigi* digi = new CbmStsDigi(address, channel, 0, adc);
200 CbmMatch* digiMatch = nullptr;
201 if (fCreateMatches) {
202 digiMatch = new CbmMatch;
203 digiMatch->AddLink(CbmLink(1., iPoint, fCurrentMCEntry, fCurrentInput));
204 }
205 SendData(time, digi, digiMatch);
206 }
207
208 timer.Stop();
209
210 // --- Event log
211 LOG(info) << left << setw(15) << GetName() << "[" << fixed << setprecision(3) << timer.RealTime() << " s]"
212 << " Points processed " << fPoints->GetEntriesFast();
213}
214// -------------------------------------------------------------------------
215
216
217// ----- Initialise parameters -----------------------------------------
219{
220
221 // --- The parameter containers are completely initialised here.
222 // --- Any contents possibly obtained from the runtimeDb are ignored
223 // --- and overwritten.
224
225 // --- Simulation settings
226 assert(fParSim);
227
228 // --- Simulation settings
229 {
230 fParSim->SetEventMode(fEventMode); // from CbmDigitizeBase
231 fParSim->SetGenerateNoise(fProduceNoise); // from CbmDigitizeBase
232 if (fEventMode) fParSim->SetGenerateNoise(kFALSE);
233 fParSim->setChanged();
234 fParSim->setInputVersion(-2, 1);
235 LOG(info) << GetName() << "--- Settings: " << fParSim->ToString();
236 }
237
238
239 { // --- Module parameters
240
241 UInt_t nChannels = 2048; // Number of module readout channels
242 UInt_t nAsicChannels = 128; // Number of readout channels per ASIC
243
244 // --- ASIC parameters
245 UShort_t nAdc = 32; // Number of ADC channels (5 bit)
246 Double_t dynRange = 75000.; // Dynamic range [e]
247 Double_t threshold = 3000.; // Threshold [e]
248 Double_t deadTime = 800.; // Channel dead time [ns]
249 Double_t noiseRms = 1000.; // RMS of noise [e]
250 Double_t znr = 3.9789e-3; // Zero-crossing noise rate [1/ns]
251
252 CbmStsParAsic userParAsicStrip(nAsicChannels, nAdc, dynRange, threshold, fStripResolutionTns, deadTime, noiseRms,
253 znr);
254 CbmStsParModule userParModuleStrip(nChannels, nAsicChannels);
255 userParModuleStrip.SetAllAsics(userParAsicStrip);
256
257 CbmStsParAsic userParAsicPixel(nAsicChannels, nAdc, dynRange, threshold, fPixelResolutionTns, deadTime, noiseRms,
258 znr);
259 CbmStsParModule userParModulePixel(nChannels, nAsicChannels);
260 userParModulePixel.SetAllAsics(userParAsicPixel);
261
262 assert(fParSetModule);
264
265 for (Int_t iModule = 0; iModule < fSetup->GetNofModules(); iModule++) {
266 UInt_t address = fSetup->GetModule(iModule)->GetAddress();
267 if (fSetup->GetStationNumber(address) < fPixelNstations) {
268 fParSetModule->SetParModule(address, userParModulePixel);
269 }
270 else {
271 fParSetModule->SetParModule(address, userParModuleStrip);
272 }
273 }
274
275 fParSetModule->setChanged();
276 fParSetModule->setInputVersion(-2, 1);
277 LOG(info) << GetName() << "--- Using global ASIC parameters for Pixels: \n " << userParAsicPixel.ToString();
278 LOG(info) << GetName() << "--- Using global ASIC parameters for Strips: \n " << userParAsicPixel.ToString();
279 LOG(info) << GetName() << "--- Module parameters: " << fParSetModule->ToString();
280 }
281
282 // --- Sensor parameters
283 {
284 assert(fParSetSensor);
286
287 // --- Sensor parameters
288
289 for (Int_t iSensor = 0; iSensor < fSetup->GetNofSensors(); iSensor++) {
290 CbmStsSensor* sensor = fSetup->GetSensor(iSensor);
291 UInt_t address = sensor->GetAddress();
292 TGeoBBox* box = dynamic_cast<TGeoBBox*>(sensor->GetPnode()->GetShape());
293 assert(box);
294 Double_t lX = 2. * box->GetDX();
295 Double_t lY = 2. * box->GetDY();
296 Double_t lZ = 2. * box->GetDZ();
297 Double_t dY = lY;
298
299 // Create a sensor parameter object and add it to the container
301
302 // sensor parameters currently not used by the tracker
303
304 par.SetPar(0, lX); // Extension in x
305 par.SetPar(1, lY); // Extension in y
306 par.SetPar(2, lZ); // Extension in z
307 par.SetPar(3, dY); // Active size in y
308 par.SetPar(4, 1024.); // Number of strips front side
309 par.SetPar(5, 1024.); // Number of strips back side
310
311 // sensor parameters used by the tracker
312
313 if (fSetup->GetStationNumber(address) < fPixelNstations) {
314 par.SetPar(6, fPixelResolutionXcm * sqrt(12.)); // Strip pitch front side
315 par.SetPar(7, fPixelResolutionYcm * sqrt(12.)); // Strip pitch back side
316 }
317 else {
318 par.SetPar(6, fStripResolutionXcm * sqrt(12.)); // Strip pitch front side
319 par.SetPar(7, fStripResolutionYcm * sqrt(12.)); // Strip pitch back side
320 }
321
322 par.SetPar(8, 0.); // Stereo angle front side [deg]
323 par.SetPar(9, 90); // Stereo angle back side [deg]
324
325 fParSetSensor->SetParSensor(address, par);
326 }
327
328 LOG(info) << GetName() << "--- Sensor parameters: " << fParSetSensor->ToString();
329 fParSetSensor->setChanged();
330 fParSetSensor->setInputVersion(-2, 1);
331 fParSetSensor->setDescription("Experimental STS Pixels");
332 }
333}
334// -------------------------------------------------------------------------
ClassImp(CbmStsDigitizePixel)
friend fvec sqrt(const fvec &a)
void GetEventInfo()
Get event information.
Int_t fCurrentInput
Start time of run [ns].
Double_t fCurrentEventTime
Number of current MC entry.
Int_t fCurrentMCEntry
Number of current MC event.
Bool_t fCreateMatches
Flag for production of inter-event noise.
void SetCreateMatches(Bool_t choice=kTRUE)
Set creation of links to MC.
Bool_t fProduceNoise
Flag for event-by-event mode.
Base class template for CBM digitisation tasks.
Definition CbmDigitize.h:44
void SendData(Double_t time, CbmStsDigi *digi, CbmMatch *match=nullptr)
void AddLink(const CbmLink &newLink)
Definition CbmMatch.cxx:47
Data class for a single-channel message in the STS.
Definition CbmStsDigi.h:40
Task class for simulating the detector response of the experimental STS Pixel setup.
virtual InitStatus Init()
CbmStsParSim * fParSim
Simulation settings.
CbmStsParSetSensorCond * fParSetCond
Sensor conditions.
virtual InitStatus ReInit()
TClonesArray * fPoints
STS setup interface.
CbmStsParSetSensor * fParSetSensor
Sensor parameters.
void InitParams()
Initialise the parameters.
virtual void Exec(Option_t *opt)
virtual void SetParContainers()
Inherited from FairTask.
CbmStsParSetModule * fParSetModule
Module parameter.
Int_t GetAddress() const
TGeoPhysicalNode * GetPnode() const
Parameters of the STS readout ASIC.
std::string ToString() const
Info to string.
Parameters for one STS module.
void SetAllAsics(const CbmStsParAsic &asicPar)
Set all ASICs with the same parameter set.
Constructional parameters of a STS sensor.
void SetPar(UInt_t index, Float_t value)
Set a parameter.
Parameters container for CbmStsParModule.
virtual void clear()
Reset all parameters.
void SetParModule(UInt_t address, const CbmStsParModule &par)
Set the parameters for a module.
std::string ToString() const
Info to string.
Parameters container for CbmStsParSensorCond.
Parameters container for CbmStsParSensor.
void SetParSensor(UInt_t address, const CbmStsParSensor &par)
Set the parameters for a sensor.
std::string ToString() const
Info to string.
virtual void clear()
Reset all parameters.
Settings for STS simulation (digitizer)
std::string ToString() const
String output.
void SetGenerateNoise(Bool_t choice=kTRUE)
Activate or de-activate inter-event noise.
void SetEventMode(Bool_t choice=kTRUE)
Set event-by-event simulation mode.
static CbmStsPhysics * Instance()
Accessor to singleton instance.
Class representing an instance of a sensor in the CBM-STS.
Int_t GetNofSensors() const
Definition CbmStsSetup.h:90
Bool_t Init(const char *geometryFile=nullptr)
Initialise the setup.
CbmStsModule * GetModule(Int_t index) const
Get a module from the module array.
Definition CbmStsSetup.h:72
static CbmStsSetup * Instance()
CbmStsSensor * GetSensor(Int_t index) const
Get a sensor from the sensor array.
Definition CbmStsSetup.h:82
Int_t GetStationNumber(Int_t address)
Int_t GetNofModules() const
Definition CbmStsSetup.h:86
Bool_t IsInit() const
Initialisation status for sensor parameters.