BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnLambdaMisc.cxx
Go to the documentation of this file.
1#include "BmnLambdaMisc.h"
2
3#include <ratio>
4
6 : fDetectorGEM(nullptr)
7 , fDetectorSI(nullptr)
8 , fDetectorCSC(nullptr)
9{
10 TString gPathConfig = gSystem->Getenv("VMCWORKDIR");
11 TString confGem = "GemRunSpring2018.xml";
12 TString gPathGemConfig = gPathConfig + "/parameters/gem/XMLConfigs/";
13 fDetectorGEM = new BmnGemStripStationSet(gPathGemConfig + confGem);
14
15 TString confSi = "SiliconRunSpring2018.xml";
16 TString gPathSiConfig = gPathConfig + "/parameters/silicon/XMLConfigs/";
17 fDetectorSI = new BmnSiliconStationSet(gPathSiConfig + confSi);
18
19 TString confCsc = "CSCRunSpring2018.xml";
20 TString gPathCscConfig = gPathConfig + "/parameters/csc/XMLConfigs/";
21 fDetectorCSC = new BmnCSCStationSet(gPathCscConfig + confCsc);
22
23 GEM();
24 SILICON();
25 CSC();
26}
27
29{
30 if (fDetectorGEM)
31 delete fDetectorGEM;
32
33 if (fDetectorSI)
34 delete fDetectorSI;
35
36 if (fDetectorCSC)
37 delete fDetectorCSC;
38}
39
40// Process GEM mapping ...
41
43{
44 TString gPathConfig = gSystem->Getenv("VMCWORKDIR");
45 TString gPathFull = gPathConfig + "/input/GEM_map_run7.txt";
46
47 Long_t commonSerial = 0x76D08B9;
48
49 // Read GEM mapping (run7)
50 ifstream g(gPathFull.Data());
51
52 TString gemId = "", station = "", module = "", low = "", high = "", serial = "";
53 Int_t linesOmitted = 4;
54
55 Int_t counter = 0;
56 for (string line; getline(g, line);) {
57 counter++;
58 if (counter > linesOmitted) {
59 g >> serial >> low >> high >> gemId >> station >> module;
60 Long_t ser = (Long_t)serial.Atof();
61 if (ser == 0)
62 continue;
63 vector<Int_t> key{station.Atoi(), module.Atoi(), gemId.Atoi()};
64 vector<Long_t> value{low.Atoll(), high.Atoll(), ser};
65 if (ser == commonSerial)
66 corrMapCommonSerial[key] = value;
67 else
68 corrMapNoCommonSerial[key] = value;
69
70 // Fill useful vector to be used outside of the function ...
71 fGemStatModId.push_back(key);
72 }
73 }
74}
75
76// Process SILICON mapping ...
77
79{
80 TString gPathConfig = gSystem->Getenv("VMCWORKDIR");
81 TString gPathFull = gPathConfig + "/input/SILICON_map_run7.txt";
82
83 // Read GEM mapping (run7)
84 ifstream g(gPathFull.Data());
85
86 TString layer = "", station = "", modAdc = "", modGeo = "", low = "", high = "", serial = "";
87 Int_t linesOmitted = 3;
88
89 Int_t counter = 0;
90 for (string line; getline(g, line);) {
91 counter++;
92 if (counter > linesOmitted) {
93 g >> serial >> low >> high >> modAdc >> modGeo >> layer >> station;
94 Long_t ser = (Long_t)serial.Atof();
95 if (ser == 0)
96 continue;
97 vector<Int_t> key{station.Atoi(), modGeo.Atoi(), layer.Atoi(), modAdc.Atoi()};
98 vector<Long_t> value{low.Atoll(), high.Atoll(), ser};
99
100 serialsSilicon[key] = value;
101
102 // Fill useful vector to be used outside of the function ...
103 fSiliconStatModLayId.push_back(key);
104 }
105 }
106}
107
108// Processing CSC mapping ...
109
111{
112 TString gPathConfig = gSystem->Getenv("VMCWORKDIR");
113 TString gPathFull = gPathConfig + "/input/CSC_map_period7.txt";
114
115 // Read CSC mapping (run7)
116 ifstream g(gPathFull.Data());
117
118 TString zone = "", layer = "", station = "", module = "", low = "", high = "", serial = "";
119 Int_t linesOmitted = 1;
120
121 Int_t counter = 0;
122 for (string line; getline(g, line);) {
123 counter++;
124 if (counter > linesOmitted) {
125 g >> serial >> low >> high >> zone >> station >> module >> layer;
126 Long_t ser = (Long_t)serial.Atof();
127 if (ser == 0)
128 continue;
129 vector<Int_t> key{station.Atoi(), module.Atoi(), layer.Atoi()};
130 vector<Long_t> value{low.Atoll(), high.Atoll(), ser};
131
132 serialsCsc[key] = value;
133
134 // Fill useful vector to be used outside of the function ...
135 fCscStatModLay.push_back(key);
136 }
137 }
138}
139
141{
142 TClonesArray* mapInfo = new TClonesArray("MappingInfo");
143
144 // Left and Right part for each station ...
145 const Int_t nParts = 2;
146 TString parts[nParts] = {"Left", "Right"};
147
148 for (Int_t iStat = 0; iStat < fDetectorGEM->GetNStations(); iStat++) {
149
150 for (Int_t iPart = 0; iPart < nParts; iPart++) {
151 TString filename = (iStat == 0 || iStat == 1) ? TString::Format("GEM2_Y1_%s.txt", parts[iPart].Data())
152 : TString::Format("GEM_Y1_Big_%s.txt", parts[iPart].Data());
153
154 map<Int_t, Int_t> stripGlobChan;
155 ParseStripChannelMapping(filename, iStat, stripGlobChan);
156
157 // Trying to find min and max channel numbers ...
158 vector<Int_t> channels;
159 for (auto it : stripGlobChan)
160 channels.push_back(it.second);
161
162 Int_t min = *min_element(channels.begin(), channels.end());
163 Int_t max = *max_element(channels.begin(), channels.end());
164
165 // Create mapping info ...
166 MappingInfo* info = new ((*mapInfo)[mapInfo->GetEntriesFast()]) MappingInfo(iStat, filename, stripGlobChan);
167 info->channels = make_pair(min, max);
168 }
169 }
170
171 // Looking for overlapping channels with main part of big zone ...
172 // FIXME !!!
173 const Int_t nStripsLeft = 1080;
174 const Int_t nStripsRight = 1129;
175 const Int_t addChanStart = 2048;
176
177 TClonesArray* mapInfoMainPart = new TClonesArray("MappingInfo");
178
179 // Loop over stations ..
180 for (Int_t iStat = 0; iStat < fDetectorGEM->GetNStations(); iStat++) {
181
182 // Loop over left and right mappings ...
183 for (Int_t iPart = 0; iPart < nParts; iPart++) {
184 TString filename = (iStat == 0 || iStat == 1) ? TString::Format("GEM2_Y1_%s.txt", parts[iPart].Data())
185 : TString::Format("GEM_Y1_Big_%s.txt", parts[iPart].Data());
186
187 // Loop over strips ...
188 const Int_t nStrips = (filename.Contains("Left")) ? nStripsLeft : nStripsRight;
189
190 for (Int_t iStrip = 0; iStrip < nStrips; iStrip++) {
191
192 // Getting corr. channel ...
193 UInt_t channel = FindChannelByStrip(filename, iStrip);
194
195 // Skipping part that corresponds to common ADC ...
196 if (channel > addChanStart - 1)
197 continue;
198
199 new ((*mapInfoMainPart)[mapInfoMainPart->GetEntriesFast()])
200 MappingInfo(iStat, filename, channel, iStrip);
201 }
202 }
203 }
204
205 // Analyzing what is taken ...
207 qa->DrawHistos6(mapInfoMainPart, mapInfo);
208
209 delete mapInfo;
210 delete mapInfoMainPart;
211
212 delete qa;
213}
214
215void BmnLambdaMisc::ParseStripChannelMapping(TString filename, Int_t stat, map<Int_t, Int_t>& stripsGlobChannels)
216{
217 map<Int_t, Int_t> channelStrip; // channel --> strip correspondence
218
219 TString gPathConfig = gSystem->Getenv("VMCWORKDIR");
220 TString gPathFull = gPathConfig + "/input/" + filename;
221 ifstream f(gPathFull.Data());
222
223 TString channelCur = "";
224
225 Int_t stripCounter = 0;
226 while (!f.eof()) {
227 f >> channelCur;
228 channelStrip[channelCur.Atoi()] = stripCounter;
229 stripCounter++;
230 }
231
232 // Left and Right files
233 // Returns vector of pairs that correspond to blocks of channels connected to common ADC in the global encoding
234 // scheme
235
236 // Channel shift for common ADC as a function of stat / mod number ...
237 Int_t chanShift = 0;
238
239 // <st, mod, id> ---> <low, high, serial>
240 for (auto it : corrMapCommonSerial) {
241 if (it.first[0] != stat)
242 continue;
243
244 // Choosing right or left part of station ...
245 Int_t id = it.first[2]; // Current gemId
246 if (filename.Contains("Left") && (id % 10 == 0))
247 chanShift += it.second[0];
248
249 else if (filename.Contains("Right") && (id % 10 != 0))
250 chanShift += it.second[0];
251 }
252
253 // Trying to locate channels attributed to common ADC ...
254 Int_t addChanStart = 2048;
255
256 for (auto it : channelStrip) {
257 Int_t chan = it.first;
258 if (chan < addChanStart)
259 continue;
260
261 Int_t locChan = chan - addChanStart;
262 Int_t globChan = locChan + chanShift;
263
264 stripsGlobChannels[it.second] = globChan;
265 }
266}
267
269{
270 for (auto it : corrMapNoCommonSerial) {
271
272 if (it.first[0] != stat || it.first[1] != mod || it.first[2] != id)
273 continue;
274
275 if (channel >= it.second[0] && channel <= it.second[1])
276 return it.second[2];
277 }
278 return 0x0;
279}
280
281// Make correspondence <CSC-digi ---> channel(serial)>
282
284{
285 Int_t stat = dig->GetStation();
286 Int_t mod = dig->GetModule();
287 Int_t lay = dig->GetStripLayer();
288 Int_t strip = dig->GetStripNumber();
289
290 TString filename = ""; // mapping with strip -> channel correspondence ...
291
292 for (auto it : serialsCsc) {
293 vector<Int_t> statModLay = it.first;
294
295 if (stat != statModLay[0] || mod != statModLay[1] || lay != statModLay[2])
296 continue;
297
298 ser = it.second[2]; // get corr. serial ...
299
300 filename = TString::Format("CSC_m%dl%d.txt", mod, lay); // get necessary file ...
301
302 break;
303 }
304
305 // Let's get a corresp. chan. number for a current strip ...
306 TString gPathConfig = gSystem->Getenv("VMCWORKDIR");
307 TString gPathFull = gPathConfig + "/input/" + filename;
308
309 ifstream f(gPathFull.Data());
310
311 map<Int_t, Int_t> stripChannels; // Map to store read channel for each strip
312 TString channel = "";
313
314 Int_t stripCounter = 0;
315 while (!f.eof()) {
316 f >> channel;
317 stripChannels[stripCounter] = channel.Atoi();
318 stripCounter++;
319 }
320
321 Int_t chan = stripChannels.find(strip)->second;
322
323 return chan;
324}
325
326// Make correspondence <SILICON-digi ---> channel, sample, serial>
327
329{
330 Int_t stat = dig->GetStation();
331 Int_t mod = dig->GetModule();
332 Int_t lay = dig->GetStripLayer();
333 Int_t strip = dig->GetStripNumber();
334
335 for (auto it : serialsSilicon) {
336 vector<Int_t> statModLay = it.first;
337
338 if (stat != statModLay[0] || mod != statModLay[1] || lay != statModLay[2])
339 continue;
340
341 Int_t chanShift = Int_t(strip / 128);
342 chan = it.second[0] + chanShift;
343 sample = Int_t(strip % 128);
344 serial = it.second[2];
345 }
346}
347
348// Make correspondance GEM-digi ---> corresponding <strip-channel> mapping
349
351{
352 Int_t stat = dig->GetStation();
353 Int_t mod = dig->GetModule();
354 Int_t lay = dig->GetStripLayer();
355 // Int_t strip = dig->GetStripNumber();
356
357 TString layer = (lay == 0 || lay == 2) ? "X" : "Y";
358 Int_t hotOrBig = -1;
359 TString LeftOrRight = "";
360 TString filename = "";
361
362 // Int_t modMakan = -1;
363
364 for (auto it : fGemStatModId) {
365 vector<Int_t> vect = it; // (stat, module, id)
366
367 // Choosing station ...
368 if (vect[0] != stat)
369 continue;
370
371 LeftOrRight = (vect[2] % 10 == 0) ? "Left" : "Right";
372
373 // Defining hot or big zone by layer ...
374 hotOrBig = (lay == 2 || lay == 3) ? 0 : 1;
375
376 // Choosing module ...
377 if (mod == 0) {
378 if (vect[1] == 2 || vect[1] == 3)
379 continue;
380
381 // Skipping rest possible modules ...
382 if (hotOrBig == 0 && vect[1] == 1)
383 continue;
384 else if (hotOrBig == 1 && vect[1] == 0)
385 continue;
386 } else {
387 if (vect[1] == 0 || vect[1] == 1)
388 continue;
389
390 // Skipping rest possible modules ...
391 if (hotOrBig == 0 && vect[1] == 3)
392 continue;
393 else if (hotOrBig == 1 && vect[1] == 2)
394 continue;
395 }
396
397 if (hotOrBig == 0) {
398 if ((stat == 0 || stat == 3 || stat == 5))
399 filename = TString::Format("GEM2_%s%d_%s.txt", layer.Data(), hotOrBig, LeftOrRight.Data());
400
401 else
402 filename = TString::Format("GEM_%s%d_Big_%s.txt", layer.Data(), hotOrBig, LeftOrRight.Data());
403 } else {
404 if ((stat == 0 || stat == 1))
405 filename = TString::Format("GEM2_%s%d_%s.txt", layer.Data(), hotOrBig, LeftOrRight.Data());
406
407 else
408 filename = TString::Format("GEM_%s%d_Big_%s.txt", layer.Data(), hotOrBig, LeftOrRight.Data());
409 }
410
411 // modMakan = vect[1];
412 break;
413 }
414
415 return filename;
416}
417
418// Make correspondence <GEM-digi ---> channel>
419
421{
422 Int_t stat = dig->GetStation();
423 Int_t mod = dig->GetModule();
424 Int_t lay = dig->GetStripLayer();
425 Int_t strip = dig->GetStripNumber();
426
427 // {0 ---> LeftToRight, 1 ---> RightToLeft};
428 // Int_t order = fDetectorGEM->GetStation(stat)->GetModule(mod)->GetStripLayer(lay).GetStripNumberingOrder();
429
430 TString layer = (lay == 0 || lay == 2) ? "X" : "Y";
431 Int_t hotOrBig = -1;
432 TString LeftOrRight = "";
433 TString filename = "";
434
435 Int_t modMakan = -1;
436
437 for (auto it : fGemStatModId) {
438 vector<Int_t> vect = it; // (stat, module, id)
439
440 // Choosing station ...
441 if (vect[0] != stat)
442 continue;
443
444 LeftOrRight = (vect[2] % 10 == 0) ? "Left" : "Right";
445
446 // Defining hot or big zone by layer ...
447 hotOrBig = (lay == 2 || lay == 3) ? 0 : 1;
448
449 // Choosing module ...
450 if (mod == 0) {
451 if (vect[1] == 2 || vect[1] == 3)
452 continue;
453
454 // Skipping rest possible modules ...
455 if (hotOrBig == 0 && vect[1] == 1)
456 continue;
457 else if (hotOrBig == 1 && vect[1] == 0)
458 continue;
459 } else {
460 if (vect[1] == 0 || vect[1] == 1)
461 continue;
462
463 // Skipping rest possible modules ...
464 if (hotOrBig == 0 && vect[1] == 3)
465 continue;
466 else if (hotOrBig == 1 && vect[1] == 2)
467 continue;
468 }
469
470 if (hotOrBig == 0) {
471 if ((stat == 0 || stat == 3 || stat == 5))
472 filename = TString::Format("GEM2_%s%d_%s.txt", layer.Data(), hotOrBig, LeftOrRight.Data());
473
474 else
475 filename = TString::Format("GEM_%s%d_Big_%s.txt", layer.Data(), hotOrBig, LeftOrRight.Data());
476 } else {
477 if ((stat == 0 || stat == 1))
478 filename = TString::Format("GEM2_%s%d_%s.txt", layer.Data(), hotOrBig, LeftOrRight.Data());
479
480 else
481 filename = TString::Format("GEM_%s%d_Big_%s.txt", layer.Data(), hotOrBig, LeftOrRight.Data());
482 }
483
484 modMakan = vect[1];
485 break;
486 }
487
488 TString gPathConfig = gSystem->Getenv("VMCWORKDIR");
489 TString gPathFull = gPathConfig + "/input/" + filename;
490
491 ifstream f(gPathFull.Data());
492
493 map<Int_t, Int_t> stripChannels; // Map to store read channel for each strip
494 TString channel = "";
495
496 Int_t stripCounter = 0;
497 while (!f.eof()) {
498 f >> channel;
499 stripChannels[stripCounter] = channel.Atoi();
500 stripCounter++;
501 }
502
503 UInt_t chan = stripChannels.find(strip)->second;
504
505 // Check if we have a channel greater than 2047 ...
506 UInt_t addChannelsStart = 2048;
507 if (chan >= addChannelsStart) {
508 for (auto it : corrMapCommonSerial) {
509 Int_t station = it.first[0];
510 Int_t module = it.first[1];
511
512 if (station != stat || module != modMakan)
513 continue;
514
515 UInt_t low = it.second[0];
516 UInt_t high = it.second[1];
517
518 chan = chan - addChannelsStart + low;
519
520 // Channel not found correctly ...
521 if (chan > high)
522 return -1;
523
524 // Save this common serial ...
525 for (auto itSerial : corrMapCommonSerial) {
526 serial = itSerial.second[2];
527 break;
528 }
529 }
530 }
531 return chan;
532}
533
535{
536 TString gPathConfig = gSystem->Getenv("VMCWORKDIR");
537 TString gPathFull = gPathConfig + "/input/" + f;
538
539 ifstream file(gPathFull.Data());
540 map<Int_t, Int_t> stripChannels; // Map to store read channel for each strip
541 TString channel = "";
542
543 Int_t stripCounter = 0;
544 while (file >> channel) {
545 stripChannels[stripCounter] = channel.Atoi();
546 stripCounter++;
547 }
548 file.close();
549
550 return stripChannels.find(strip)->second;
551}
552
553Long_t BmnLambdaMisc::GemDigiChannelToSerial(pair<BmnStripDigit, Int_t> digiChannel)
554{
555 // Make correspondence: st, mod, strip, channel --> serial
556 Int_t stat = digiChannel.first.GetStation();
557 Int_t mod = digiChannel.first.GetModule();
558 // Int_t strip = digiChannel.first->GetStripNumber();
559 Int_t channel = digiChannel.second;
560
561 Int_t layer = digiChannel.first.GetStripLayer(); // To define hot or big zone we are considering ...
562
563 // Modules should be redefined in the mapping notation ...
564 Bool_t isBig = (layer == 0 || layer == 1) ? kTRUE : kFALSE;
565 Bool_t isHot = (layer == 2 || layer == 3) ? kTRUE : kFALSE;
566
567 if (isBig && mod == 1)
568 mod = 3;
569 else if (isBig && mod == 0)
570 mod = 1;
571 else if (isHot && mod == 1)
572 mod = 2;
573 else if (isHot && mod == 0)
574 mod = 0;
575
576 Int_t id = -1;
577
578 for (auto it : fGemStatModId) {
579 if (it[0] != stat || it[1] != mod)
580 continue;
581
582 id = it[2];
583
584 break;
585 }
586
587 return GetGemSerial(stat, mod, id, channel);
588}
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
Definition P4_F32vec4.h:30
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
Definition P4_F32vec4.h:31
bool Bool_t
int Int_t
long Long_t
constexpr Bool_t kFALSE
constexpr Bool_t kTRUE
R__EXTERN TSystem * gSystem
map< vector< Int_t >, vector< Long_t > > serialsCsc
vector< vector< Int_t > > fCscStatModLay
TString GemDigiToMapping(BmnStripDigit *)
Int_t GemDigiToChannel(BmnStripDigit *, Long_t &)
UInt_t FindChannelByStrip(TString, Int_t)
void SiliconDigiToChannelSampleSerial(BmnStripDigit *, Int_t &, Int_t &, Long_t &)
void CheckStripOverlaps()
Int_t CscDigiToChannel(BmnStripDigit *, Long_t &)
Long_t GemDigiChannelToSerial(pair< BmnStripDigit, Int_t >)
BmnSiliconStationSet * fDetectorSI
BmnCSCStationSet * fDetectorCSC
map< vector< Int_t >, vector< Long_t > > corrMapCommonSerial
map< vector< Int_t >, vector< Long_t > > corrMapNoCommonSerial
vector< vector< Int_t > > fSiliconStatModLayId
map< vector< Int_t >, vector< Long_t > > serialsSilicon
BmnGemStripStationSet * fDetectorGEM
virtual ~BmnLambdaMisc()
Long_t GetGemSerial(Int_t, Int_t, Int_t, Int_t)
void ParseStripChannelMapping(TString, Int_t, map< Int_t, Int_t > &)
vector< vector< Int_t > > fGemStatModId
Class BmnStripDigit Base class for strip detector digits.
Int_t GetStripNumber()
Int_t GetStripLayer()
Int_t GetStation()
Int_t GetModule()
pair< Int_t, Int_t > channels
Int_t GetEntriesFast() const
friend friend class TClonesArray
Int_t Atoi() const
const char * Data() const
static TString Format(const char *fmt,...)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const