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