BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnGemStripDigitizer.cxx
Go to the documentation of this file.
2
3#include "CbmMCTrack.h"
4#include "CbmStsPoint.h"
5#include "FairRootManager.h"
6#include "TSystem.h"
7
8#include <TRandom.h> //AZ-240823
9
10static Float_t workTime = 0.0;
11static int entrys = 0;
12
17{
18
19 fInputBranchName = "StsPoint";
20 fOutputDigitsBranchName = "BmnGemStripDigit";
21 fOutputDigitMatchesBranchName = "BmnGemStripDigitMatch";
22
23 fVerbose = 1;
24
26 StationSet = nullptr;
27 GlobalModTransfSet = nullptr;
28 fField = nullptr;
29
32
33 fSigma = -1; // AZ-240823
34 fThresh = 12; // AZ-240823 - initial value
35 SetName("GemDigitizer"); // AZ-110124
36}
37
40{
41 switch (run_period) {
42 case 6: // BM@N RUN-6
44 break;
45 case 7: // BM@N RUN-7
47 break;
48 case 8: // BM@N RUN-8
50 break;
51 case 9: // BM@N RUN-9
53 break;
54
55 default:
57 }
58}
59
77
79{
80
81 if (fVerbose)
82 cout << "\nBmnGemStripDigitizer::Init()\n ";
83
84 if (fVerbose && fOnlyPrimary)
85 cout << " Only primary particles are processed!!! " << endl;
86
87 if (fVerbose && fStripMatching)
88 cout << " Strip Matching is activated!!! " << endl;
89 else
90 cout << " Strip Matching is deactivated!!! " << endl;
91
92 FairRootManager* ioman = FairRootManager::Instance();
93
96 cout << "BmnGemStripDigitizer::Init(): branch StsPoint not found! Task "
97 "will be deactivated"
98 << endl;
99 SetActive(kFALSE);
100 return kERROR;
101 }
102
103 fMCTracksArray = (TClonesArray*)ioman->GetObject("MCTrack");
104
106 ioman->Register(fOutputDigitsBranchName, "GEM_DIGIT", fBmnGemStripDigitsArray, kTRUE);
107
108 if (fStripMatching) {
111 }
112
113 TString gPathGemConfig = gSystem->Getenv("VMCWORKDIR");
114 gPathGemConfig += "/parameters/gem/XMLConfigs/";
115
116 // Create GEM detector ------------------------------------------------------
117 switch (fCurrentConfig) {
119 XMLConfigFile = gPathGemConfig + "GemRunSpring2017.xml";
120 if (fVerbose)
121 cout << " Current GEM Configuration : RunSpring2017"
122 << "\n";
123 break;
124
126 XMLConfigFile = gPathGemConfig + "GemRunSpring2018.xml";
127 if (fVerbose)
128 cout << " Current GEM Configuration : RunSpring2018"
129 << "\n";
130 break;
131
133
134 XMLConfigFile = gPathGemConfig + "GemRunSRCSpring2018.xml";
135 if (fVerbose)
136 cout << " Current GEM Configuration : GemRunSRCSpring2018"
137 << "\n";
138 break;
139
141 XMLConfigFile = gPathGemConfig + "GemRunSRC2021.xml";
142 if (fVerbose)
143 cout << " Current GEM Configuration : RunSRC2021"
144 << "\n";
145 break;
146
148 XMLConfigFile = gPathGemConfig + "GemRun8.xml";
149 if (fVerbose)
150 cout << " Current GEM Configuration : Run8"
151 << "\n";
152 break;
153
155 XMLConfigFile = gPathGemConfig + "GemRun9.xml";
156 if (fVerbose)
157 cout << " Current GEM Configuration : Run9"
158 << "\n";
159 break;
160
161 default:;
162 }
163
164 if (!gSystem->AccessPathName(XMLConfigFile)) { // returns FALSE if the file exists
165 if (fVerbose)
166 cout << " XMLConfigFile : " << XMLConfigFile << "\n";
169 GlobalModTransfSet->LoadFromXMLFile(XMLConfigFile);
170 } else {
171 Fatal("BmnGemStripDigitizer::Init()", " !!! Current configuration is not set !!! ");
172 }
173
174 if (fUseRealEffects)
175 ;
176
177 //--------------------------------------------------------------------------
178
179 if (fVerbose)
180 cout << "BmnGemStripDigitizer::Init() finished\n\n";
181 return kSUCCESS;
182}
183
185{
186
187 if (!IsActive())
188 return;
189
190 clock_t tStart = clock();
191 fBmnGemStripDigitsArray->Delete();
192
193 if (fStripMatching)
195
197 Error("BmnGemStripDigitizer::Exec()", " !!! Unknown branch name !!! ");
198 return;
199 }
200
201 if (fVerbose) {
202 cout << " BmnGemStripDigitizer::Exec(), Number of BmnGemStripPoints = "
203 << fBmnGemStripPointsArray->GetEntriesFast() << "\n";
204 }
205
207
208 if (fVerbose)
209 cout << " BmnGemStripDigitizer::Exec() finished\n\n";
210 entrys++;
211 clock_t tFinish = clock();
212 workTime += ((Float_t)(tFinish - tStart)) / CLOCKS_PER_SEC;
213}
214
216{
217
218 FairMCPoint* GemStripPoint;
219 // Int_t NNotPrimaries = 0;
220
221 for (Int_t ipoint = 0; ipoint < fBmnGemStripPointsArray->GetEntriesFast(); ipoint++) {
222 GemStripPoint = (FairMCPoint*)fBmnGemStripPointsArray->At(ipoint);
223
224 if (fOnlyPrimary) {
225 CbmMCTrack* track = (CbmMCTrack*)fMCTracksArray->UncheckedAt(GemStripPoint->GetTrackID());
226 if (!track)
227 continue;
228 if (track->GetMotherId() != -1) {
229 // NNotPrimaries++;
230 continue;
231 }
232 }
233
234 Double_t x = -GemStripPoint->GetX(); // invert because in current geometry
235 // +x -left, -x - right
236 Double_t y = GemStripPoint->GetY();
237 Double_t z = GemStripPoint->GetZ();
238
239 Double_t px = -GemStripPoint->GetPx(); // invert because in current geometry
240 // +x -left, -x - right
241 Double_t py = GemStripPoint->GetPy();
242 Double_t pz = GemStripPoint->GetPz();
243
244 Double_t dEloss = GemStripPoint->GetEnergyLoss() * 1e6; // in keV
245 Int_t refId = ipoint;
246
247 Int_t mc_station_num = ((CbmStsPoint*)GemStripPoint)->GetStation();
248 Int_t mc_module_num = ((CbmStsPoint*)GemStripPoint)->GetModule();
249
250 // cout << "mc_station_num = " << mc_station_num << "\n";
251 // cout << "mc_module_num = " << mc_module_num << "\n";
252
253 // Apply inverse global module transforms to MC-point (in right-handed system)
254 if (GlobalModTransfSet && mc_station_num < StationSet->GetNStations()) {
255 if (mc_module_num < StationSet->GetStation(mc_station_num)->GetNModules()) {
256 Plane3D::Point point_transformed =
257 GlobalModTransfSet->ApplyInverseTransforms(Plane3D::Point(-x, y, z), mc_station_num, mc_module_num);
258 Plane3D::Point direction_transformed = GlobalModTransfSet->ApplyInverseTransforms(
259 Plane3D::Point(-(px + x), (py + y), (pz + z)), mc_station_num, mc_module_num);
260 x = -point_transformed.X(); // convert to detector system (x-inverted)
261 y = point_transformed.Y();
262 z = point_transformed.Z();
263
264 px = -(direction_transformed.X() - point_transformed.X()); // convert to detector system (x-inverted)
265 py = direction_transformed.Y() - point_transformed.Y();
266 pz = direction_transformed.Z() - point_transformed.Z();
267 }
268 }
269
270 if (fUseRealEffects)
271 ;
272
273 // AZ-191223 - gain fluctuations
274 Double_t gain = 1;
275 // gain += gRandom->Gaus(0, 0.5);
276 if (gain < 0)
277 gain = 0;
278 dEloss *= gain;
279 //
280 StationSet->AddPointToDetector(x, y, z, px, py, pz, dEloss, refId);
281 }
282
283 Int_t NAddedPoints = StationSet->CountNAddedToDetectorPoints();
284 // if (fVerbose && fOnlyPrimary) cout << " Number of not primaries points :
285 // " << NNotPrimaries << "\n";
286 if (fVerbose)
287 cout << " Processed MC points : " << NAddedPoints << "\n";
288
289 for (Int_t iStation = 0; iStation < StationSet->GetNStations(); ++iStation) {
290 BmnGemStripStation* station = StationSet->GetGemStation(iStation);
291
292 for (Int_t iModule = 0; iModule < station->GetNModules(); ++iModule) {
293 BmnGemStripModule* module = station->GetModule(iModule);
294
295 for (Int_t iLayer = 0; iLayer < module->GetNStripLayers(); ++iLayer) {
296 BmnGemStripLayer layer = module->GetStripLayer(iLayer);
297
298 for (Int_t iStrip = 0; iStrip < layer.GetNStrips(); ++iStrip) {
299 Double_t signal = layer.GetStripSignal(iStrip);
300 if (signal > 0.0) {
301 signal = signal / (120. / 2.0); // el to ADC
302 // AZ-110124 signal /= 2.5; //AZ-110923 - for beam data
303 signal /= 1.3; // AZ-110124
304 // AZ-130923 - gain fluctuations
305 Double_t gain = 1;
306 // AZ-191223 gain += gRandom->Gaus(0, 0.5);
307 if (gain < 0)
308 gain = 0;
309 signal *= gain;
310 // AZ-240823 if (signal <= 12) continue;
311 // AZ-240823
312 if (fSigma > 0) {
313 // Add noise
314 signal += gRandom->Gaus(0, fSigma);
315 }
316 if (signal <= fThresh)
317 continue;
318 // AZ
319 if (signal >= 2048)
320 signal = 2047;
321 new ((*fBmnGemStripDigitsArray)[fBmnGemStripDigitsArray->GetEntriesFast()])
322 BmnGemStripDigit(iStation, iModule, iLayer, iStrip, signal);
323
324 if (fStripMatching) {
325 new ((*fBmnGemStripDigitMatchesArray)[fBmnGemStripDigitMatchesArray->GetEntriesFast()])
326 BmnMatch(layer.GetStripMatch(iStrip));
327 }
328 } else if (fSigma > 0) {
329 // AZ-120923
330 signal += gRandom->Gaus(0, fSigma);
331 // AZ-161223 - gain fluctuations
332 /*
333 Double_t gain = 1;
334 gain += gRandom->Gaus(0, 0.5); //50%
335 if (gain < 0) gain = 0;
336 signal *= gain;
337 */
338 if (signal <= fThresh)
339 continue;
340 if (signal >= 2048)
341 signal = 2047;
342 new ((*fBmnGemStripDigitsArray)[fBmnGemStripDigitsArray->GetEntriesFast()])
343 BmnGemStripDigit(iStation, iModule, iLayer, iStrip, signal);
344 if (fStripMatching) {
345 new ((*fBmnGemStripDigitMatchesArray)[fBmnGemStripDigitMatchesArray->GetEntriesFast()])
346 BmnMatch(layer.GetStripMatch(iStrip));
347 }
348 }
349 }
350 }
351 }
352 }
353 StationSet->Reset();
354}
355
357{
358 if (StationSet) {
359 delete StationSet;
360 StationSet = nullptr;
361 }
362
363 if (GlobalModTransfSet) {
364 delete GlobalModTransfSet;
365 GlobalModTransfSet = nullptr;
366 }
367
368 cout << "Work time of the GEM digitizer: " << workTime << endl;
369}
static int entrys
int Int_t
float Float_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
const char Option_t
void Error(const char *location, const char *msgfmt,...)
void Fatal(const char *location, const char *msgfmt,...)
R__EXTERN TRandom * gRandom
R__EXTERN TSystem * gSystem
BmnGemStripStationSet * StationSet
TClonesArray * fBmnGemStripDigitMatchesArray
Output array of GEM Digit Matches.
virtual InitStatus Init()
virtual void Exec(Option_t *opt)
TClonesArray * fBmnGemStripDigitsArray
Output array of Gem Digits.
BmnGemStripTransform * GlobalModTransfSet
TClonesArray * fBmnGemStripPointsArray
Input array of Gem Points.
BmnGemStripConfiguration::GEM_CONFIG fCurrentConfig
TClonesArray * fMCTracksArray
Input array of MC Tracks.
BmnMatch GetStripMatch(Int_t strip_num)
Double_t GetStripSignal(Int_t strip_num)
BmnGemStripModule * GetModule(Int_t module_num)
CbmMCTrack.h.
Definition CbmMCTrack.h:26
Int_t GetMotherId() const
Definition CbmMCTrack.h:57
PositionVector3D< Cartesian3D< T >, DefaultCoordinateSystemTag > Point