BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnSiliconDigitizer.cxx
Go to the documentation of this file.
2
3#include "BmnSiliconPoint.h"
4#include "CbmMCTrack.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 entries = 0;
12
17{
18
19 fInputBranchName = "SiliconPoint";
20 fOutputDigitsBranchName = "BmnSiliconDigit";
21 fOutputDigitMatchesBranchName = "BmnSiliconDigitMatch";
22
23 fVerbose = 1;
24
26 StationSet = nullptr;
27 fField = nullptr;
28 GlobalModTransfSet = nullptr;
29 fBmnSiliconDigitsArray = nullptr;
31
32 fSigma = -1; // AZ-240823
33 fThresh = 12; // AZ-240823 - initial value
34}
35
38{
39 switch (run_period) {
40 case 6: // BM@N RUN-6
42 break;
43 case 7: // BM@N RUN-7
45 break;
46 case 8: // BM@N RUN-8
48 break;
49 case 9: // BM@N RUN-9
51 break;
52
53 default:
55 }
56}
57
76
78{
79 if (fVerbose)
80 cout << "\nBmnSiliconDigitizer::Init()\n ";
81
82 if (fVerbose && fOnlyPrimary)
83 cout << " Only primary particles are processed!!! " << endl;
84
85 if (fVerbose && fStripMatching)
86 cout << " Strip Matching is activated!!! " << endl;
87 else
88 cout << " Strip matching is deactivated!!! " << endl;
89
90 FairRootManager* ioman = FairRootManager::Instance();
91
94 cout << "BmnSiliconDigitizer::Init(): branch SiliconPoint not found! Task "
95 "will be deactivated"
96 << endl;
97 SetActive(kFALSE);
98 return kERROR;
99 }
100
101 fMCTracksArray = (TClonesArray*)ioman->GetObject("MCTrack");
102
104 ioman->Register(fOutputDigitsBranchName, "SILICON", fBmnSiliconDigitsArray, kTRUE);
105
106 if (fStripMatching) {
109 }
110
111 TString gPathSiliconConfig = gSystem->Getenv("VMCWORKDIR");
112 gPathSiliconConfig += "/parameters/silicon/XMLConfigs/";
113
114 // Create SILICON detector -------------------------------------------------
115 switch (fCurrentConfig) {
117 XMLConfigFile = gPathSiliconConfig + "SiliconRunSpring2017.xml";
118 if (fVerbose)
119 cout << " Current SILICON Configuration : RunSpring2017"
120 << "\n";
121 break;
122
124 XMLConfigFile = gPathSiliconConfig + "SiliconRunSpring2018.xml";
125 if (fVerbose)
126 cout << " Current SILICON Configuration : RunSpring2018"
127 << "\n";
128 break;
129
131 XMLConfigFile = gPathSiliconConfig + "SiliconRunSRCSpring2018.xml";
132 if (fVerbose)
133 cout << " Current SILICON Configuration : RunSRCSpring2018"
134 << "\n";
135 break;
136
138 XMLConfigFile = gPathSiliconConfig + "SiliconRun8_3stations.xml";
139 if (fVerbose)
140 cout << " Current SILICON Configuration : SiliconRun8_3stations"
141 << "\n";
142 break;
143
145 XMLConfigFile = gPathSiliconConfig + "SiliconRun8_4stations.xml";
146 if (fVerbose)
147 cout << " Current SILICON Configuration : SiliconRun8_4stations"
148 << "\n";
149 break;
150
152 XMLConfigFile = gPathSiliconConfig + "SiliconRun8_5stations.xml";
153 if (fVerbose)
154 cout << " Current SILICON Configuration : SiliconRun8_5stations"
155 << "\n";
156 break;
157
159 XMLConfigFile = gPathSiliconConfig + "SiliconRun8_mods_6_10_14_18.xml";
160 if (fVerbose)
161 cout << " Current SILICON Configuration : SiliconRun8_mods_6_10_14_18"
162 << "\n";
163 break;
164
166 XMLConfigFile = gPathSiliconConfig + "SiliconRun8_mods_10_14rot_18.xml";
167 if (fVerbose)
168 cout << " Current SILICON Configuration : SiliconRun8_mods_10_14rot_18"
169 << "\n";
170 break;
171
173 XMLConfigFile = gPathSiliconConfig + "SiliconRun8.xml";
174 if (fVerbose)
175 cout << " Current SILICON Configuration : Run8"
176 << "\n";
177 break;
178
180 XMLConfigFile = gPathSiliconConfig + "SiliconRun9.xml";
181 if (fVerbose)
182 cout << " Current SILICON Configuration : Run9"
183 << "\n";
184 break;
185
187 XMLConfigFile = gPathSiliconConfig + "Silicon_5stations_2026.xml";
188 if (fVerbose)
189 cout << " Current SILICON Configuration : 5stations_2026"
190 << "\n";
191 break;
192
193 default:;
194 }
195
196 if (!gSystem->AccessPathName(XMLConfigFile)) { // returns FALSE if the file exists
197 if (fVerbose)
198 cout << " XMLConfigFile : " << XMLConfigFile << "\n";
201 GlobalModTransfSet->LoadFromXMLFile(XMLConfigFile);
202 } else {
203 Fatal("BmnSiliconDigitizer::Init()", " !!! Current configuration is not set !!! ");
204 }
205 //--------------------------------------------------------------------------
206
207 if (fVerbose)
208 cout << "BmnSiliconDigitizer::Init() finished\n\n";
209 return kSUCCESS;
210}
211
213{
214 clock_t tStart = clock();
215 fBmnSiliconDigitsArray->Delete();
216
217 if (fStripMatching) {
219 }
220
222 Error("BmnSiliconDigitizer::Exec()", " !!! Unknown branch name !!! ");
223 return;
224 }
225
226 if (fVerbose) {
227 // cout << " BmnSiliconDigitizer::Exec(), Number of BmnSiliconPoints = " <<
228 // fBmnSiliconPointsArray->GetEntriesFast() << "\n";
229 }
230
232
233 // if (fVerbose) cout << " BmnSiliconDigitizer::Exec() finished\n\n";
234 entries++;
235 clock_t tFinish = clock();
236 workTime += ((Float_t)(tFinish - tStart)) / CLOCKS_PER_SEC;
237}
238
240{
241
242 FairMCPoint* SiliconPoint;
243 Int_t NNotPrimaries = 0;
244
245 for (Int_t ipoint = 0; ipoint < fBmnSiliconPointsArray->GetEntriesFast(); ipoint++) {
246 SiliconPoint = (FairMCPoint*)fBmnSiliconPointsArray->At(ipoint);
247
248 if (fOnlyPrimary) {
249 CbmMCTrack* track = (CbmMCTrack*)fMCTracksArray->UncheckedAt(SiliconPoint->GetTrackID());
250 if (!track)
251 continue;
252 if (track->GetMotherId() != -1) {
253 NNotPrimaries++;
254 continue;
255 }
256 }
257
258 Double_t x = -SiliconPoint->GetX(); // invert because in current geometry +x is left, -x is right
259 Double_t y = SiliconPoint->GetY();
260 Double_t z = SiliconPoint->GetZ();
261
262 Double_t px = -SiliconPoint->GetPx(); // invert because in current geometry +x is left, -x is right
263 Double_t py = SiliconPoint->GetPy();
264 Double_t pz = SiliconPoint->GetPz();
265
266 Double_t dEloss = SiliconPoint->GetEnergyLoss() * 1e6; // in keV
267 Int_t refId = ipoint;
268
269 // Information from MC-points
270 Int_t mc_station_num = ((BmnSiliconPoint*)SiliconPoint)->GetStation();
271 Int_t mc_module_num = ((BmnSiliconPoint*)SiliconPoint)->GetModule();
272
273 // test output
274 // cout << "mc_station_num = " << mc_station_num << "\n";
275 // cout << "mc_module_num = " << mc_module_num << "\n";
276
277 // Apply inverse global module transforms to MC-point (in right-handed system)
278 if (GlobalModTransfSet && mc_station_num < StationSet->GetNStations()) {
279 if (mc_module_num < StationSet->GetStation(mc_station_num)->GetNModules()) {
280 Plane3D::Point point_transformed =
281 GlobalModTransfSet->ApplyInverseTransforms(Plane3D::Point(-x, y, z), mc_station_num, mc_module_num);
282 Plane3D::Point direction_transformed = GlobalModTransfSet->ApplyInverseTransforms(
283 Plane3D::Point(-(px + x), (py + y), (pz + z)), mc_station_num, mc_module_num);
284 x = -point_transformed.X(); // convert to detector system (x-inverted)
285 y = point_transformed.Y();
286 z = point_transformed.Z();
287
288 px = -(direction_transformed.X() - point_transformed.X()); // convert to detector system (x-inverted)
289 py = direction_transformed.Y() - point_transformed.Y();
290 pz = direction_transformed.Z() - point_transformed.Z();
291 }
292 }
293
294 // AZ-191223 - gain fluctuations
295 Double_t gain = 1;
296 // gain += gRandom->Gaus(0, 0.5);
297 if (gain < 0)
298 gain = 0;
299 dEloss *= gain;
300 //
301 StationSet->AddPointToDetector(x, y, z, px, py, pz, dEloss, refId);
302 }
303
304 // Int_t NAddedPoints = StationSet->CountNAddedToDetectorPoints();
305 // if (fVerbose && fOnlyPrimary) cout << " Number of not primaries points : " << NNotPrimaries << "\n";
306 // if (fVerbose) cout << " Processed MC points : " << NAddedPoints << "\n";
307
308 for (Int_t iStation = 0; iStation < StationSet->GetNStations(); ++iStation) {
309 BmnSiliconStation* station = StationSet->GetSiliconStation(iStation);
310
311 for (Int_t iModule = 0; iModule < station->GetNModules(); ++iModule) {
312 BmnSiliconModule* module = station->GetModule(iModule);
313 vector<Int_t> processed_zones;
314
315 for (Int_t iLayer = 0; iLayer < module->GetNStripLayers(); ++iLayer) {
316 BmnSiliconLayer layer = module->GetStripLayer(iLayer);
317
318 Int_t zone_id = layer.GetZoneID();
319
320 Bool_t is_processed_zone = false;
321 for (size_t iz = 0; iz < processed_zones.size(); ++iz)
322 if (zone_id == processed_zones[iz])
323 is_processed_zone = true;
324
325 if (!is_processed_zone) {
326 Int_t first_strip_in_zone = module->GetFirstStripInZone(zone_id);
327 Int_t last_strip_in_zone = module->GetLastStripInZone(zone_id);
328 map<int, int> noiseMap; // AZ-270823 - add noise to strips (including left neighbour)
329
330 for (Int_t iStrip = first_strip_in_zone; iStrip < last_strip_in_zone + 1; ++iStrip) {
331 Double_t signal = module->GetStripSignalInZone(zone_id, iStrip);
332
333 if (signal > 0.0) {
334 signal = signal / (120. / 500.0); // el to ADC
335 signal *= 1.17; // AZ-110923 - for beam data
336 // AZ-130923 - gain fluctuations
337 //*
338 Double_t gain = 1;
339 // AZ-191223 gain += gRandom->Gaus(0, 0.5);
340 if (gain < 0)
341 gain = 0;
342 signal *= gain;
343 // AZ-240823 if (signal <= 12) continue;
344 // AZ-240823--->
345 if (fSigma > 0) {
346 // Add noise
347 signal += gRandom->Gaus(0, fSigma);
348 }
349 // AZ-130923 - gain fluctuations
350 /*
351 Double_t gain = 1;
352 //AZ-161223 gain += gRandom->Gaus(0, 0.2); //20%
353 gain += gRandom->Gaus(0, 0.5); //50%
354 if (gain < 0) gain = 0;
355 signal *= gain;
356 */
357 noiseMap[iStrip] = 1; // noise flag
358 if (signal <= fThresh)
359 continue;
360 //<---AZ
361 if (signal >= 2048)
362 signal = 2047;
363 new ((*fBmnSiliconDigitsArray)[fBmnSiliconDigitsArray->GetEntriesFast()]) BmnSiliconDigit(
364 iStation, iModule, zone_id, iStrip, signal); // zone_id == layer_num !!!!!!
365
366 if (fStripMatching) {
367 new ((*fBmnSiliconDigitMatchesArray)[fBmnSiliconDigitMatchesArray->GetEntriesFast()])
368 BmnMatch(module->GetStripMatchInZone(zone_id, iStrip));
369 }
370 // AZ-270823 - add noise to empty channel to the leht from the active one
371 // if (fSigma > 0 && iStrip > first_strip_in_zone && noiseMap[iStrip-1] < 1) {
372 if (0) {
373 noiseMap[iStrip - 1] = 1;
374 signal = gRandom->Gaus(0, fSigma);
375 if (signal <= fThresh)
376 continue;
377
378 if (signal >= 2048)
379 signal = 2047;
380 new ((*fBmnSiliconDigitsArray)[fBmnSiliconDigitsArray->GetEntriesFast()])
381 BmnSiliconDigit(iStation, iModule, zone_id, iStrip - 1,
382 signal); // zone_id == layer_num !!!!!!
383
384 if (fStripMatching) {
385 new (
386 (*fBmnSiliconDigitMatchesArray)[fBmnSiliconDigitMatchesArray->GetEntriesFast()])
387 BmnMatch(module->GetStripMatchInZone(zone_id, iStrip - 1));
388 }
389 }
390
391 } else if (fSigma > 0) {
392 //} else if (0) {
393 // AZ-270823 - add noise to empty channel to the right from the active one
394 // if (iStrip < last_strip_in_zone && noiseMap[iStrip-1] > 0) {
395 if (1) {
396 signal += gRandom->Gaus(0, fSigma);
397 // AZ-130923 - gain fluctuations
398 /*
399 Double_t gain = 1;
400 //AZ-161223 gain += gRandom->Gaus(0, 0.2);
401 gain += gRandom->Gaus(0, 0.5); //50%
402 if (gain < 0) gain = 0;
403 signal *= gain;
404 */
405 if (signal <= fThresh)
406 continue;
407 if (signal >= 2048)
408 signal = 2047;
409 new ((*fBmnSiliconDigitsArray)[fBmnSiliconDigitsArray->GetEntriesFast()])
410 BmnSiliconDigit(iStation, iModule, zone_id, iStrip,
411 signal); // zone_id == layer_num !!!!!!
412
413 if (fStripMatching) {
414 new (
415 (*fBmnSiliconDigitMatchesArray)[fBmnSiliconDigitMatchesArray->GetEntriesFast()])
416 BmnMatch(module->GetStripMatchInZone(zone_id, iStrip));
417 }
418 }
419 }
420 }
421
422 processed_zones.push_back(zone_id);
423 }
424 }
425 }
426 }
427
428 StationSet->Reset();
429}
430
432{
433 if (StationSet) {
434 delete StationSet;
435 StationSet = nullptr;
436 }
437
438 if (GlobalModTransfSet) {
439 delete GlobalModTransfSet;
440 GlobalModTransfSet = nullptr;
441 }
442
443 cout << "Work time of the Silicon digitizer: " << workTime << endl;
444}
static int entries
bool Bool_t
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
BmnSiliconConfiguration::SILICON_CONFIG fCurrentConfig
virtual InitStatus Init()
virtual void Exec(Option_t *opt)
BmnSiliconTransform * GlobalModTransfSet
TClonesArray * fBmnSiliconDigitsArray
Output array of Silicon Digits.
TClonesArray * fBmnSiliconDigitMatchesArray
Output array of Silicon Digit Matches.
BmnSiliconStationSet * StationSet
TClonesArray * fMCTracksArray
Input array of MC Tracks.
TClonesArray * fBmnSiliconPointsArray
Input array of Silicon Points.
BmnMatch GetStripMatchInZone(Int_t zone_id, Int_t strip_num)
BmnSiliconModule * GetModule(Int_t module_num)
CbmMCTrack.h.
Definition CbmMCTrack.h:26
Int_t GetMotherId() const
Definition CbmMCTrack.h:57
PositionVector3D< Cartesian3D< T >, DefaultCoordinateSystemTag > Point