ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TPCDaqDefs.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TPCDaqDefs.cc
1 #include "TPCDaqDefs.h"
2 
3 #include <TCanvas.h>
4 #include <TF1.h>
5 #include <TGraph.h>
6 #include <TPaveText.h>
7 #include <TStyle.h>
8 #include <TVirtualFitter.h>
9 
10 #include <cassert>
11 #include <cmath>
12 #include <iostream>
13 #include <limits>
14 #include <string>
15 
16 using namespace std;
17 
18 namespace TPCDaqDefs
19 {
21 namespace FEEv1
22 {
23 SampleFit_PowerLawDoubleExp_PDFMaker::SampleFit_PowerLawDoubleExp_PDFMaker()
24 {
25  gStyle->SetOptFit(1111);
26 
27  m_canvas = new TCanvas("SampleFit_PowerLawDoubleExp_PDFMaker", "SampleFit_PowerLawDoubleExp_PDFMaker");
28  m_pavedtext = new TPaveText(.05, .1, .95, .8);
29 
30  m_pavedtext->AddText("SampleFit_PowerLawDoubleExp Fit output");
31  m_pavedtext->AddText("A double-component power-law exponential fit of time-dependent ADC pulses.");
32  m_pavedtext->AddText("Magenta curve is the sum of the two component, the red and blue curves.");
33  m_pavedtext->AddText("Red dot denote the max points");
34  m_pavedtext->Draw();
35 
36  m_canvas->Print("SampleFit_PowerLawDoubleExp.pdf("); //open multiplage PDF
37 }
38 SampleFit_PowerLawDoubleExp_PDFMaker::~SampleFit_PowerLawDoubleExp_PDFMaker()
39 {
40  if (m_pavedtext) delete m_pavedtext;
41  if (m_canvas) delete m_canvas;
42 
43  m_canvas = new TCanvas("SampleFit_PowerLawDoubleExp_PDFMaker", "SampleFit_PowerLawDoubleExp_PDFMaker");
44  m_pavedtext = new TPaveText(.05, .1, .95, .8);
45 
46  m_pavedtext->AddText("SampleFit_PowerLawDoubleExp Fit output");
47  m_pavedtext->AddText("End of pages");
48  m_pavedtext->Draw();
49 
50  m_canvas->Print("SampleFit_PowerLawDoubleExp.pdf)"); //close multiplage PDF
51 }
52 
53 void SampleFit_PowerLawDoubleExp_PDFMaker::MakeSectionPage(const string &title)
54 {
55  if (m_pavedtext) delete m_pavedtext;
56  if (m_canvas) delete m_canvas;
57 
58  m_canvas = new TCanvas("SampleFit_PowerLawDoubleExp_PDFMaker", "SampleFit_PowerLawDoubleExp_PDFMaker");
59 
60  m_pavedtext = new TPaveText(.05, .1, .95, .8);
61 
62  m_pavedtext->AddText(title.c_str());
63  m_pavedtext->Draw();
64 
65  m_canvas->Print("SampleFit_PowerLawDoubleExp.pdf");
66 }
67 
69  const std::vector<double> &samples, //
70  double &peak, //
71  double &peak_sample, //
72  double &pedestal, //
73  std::map<int, double> &parameters_io,
74  const int verbosity)
75 {
76  static const int n_parameter = 7;
77 
78  // inital guesses
79  int peakPos = 0.;
80 
81  // assert(samples.size() == n_samples);
82  const int n_samples = samples.size();
83 
84  TGraph gpulse(n_samples);
85  for (int i = 0; i < n_samples; i++)
86  {
87  (gpulse.GetX())[i] = i;
88 
89  (gpulse.GetY())[i] = samples[i];
90  }
91 
92  //Saturation correction - Abhisek
93  // for (int ipoint = 0; ipoint < gpulse.GetN(); ipoint++)
94  // if ((gpulse.GetY())[ipoint] >= ((1 << 10) - 10) // drop point if touching max or low limit on ADCs
95  // or (not isnormal((gpulse.GetY())[ipoint])))
96  // {
97  // gpulse.RemovePoint(ipoint);
98  // ipoint--;
99  // }
100 
101  pedestal = gpulse.GetY()[0]; //(double) PEDESTAL;
102  double peakval = pedestal;
103  const double risetime = 1.5;
104 
105  for (int iSample = 0; iSample < n_samples - risetime * 3; iSample++)
106  {
107  if (abs(gpulse.GetY()[iSample] - pedestal) > abs(peakval - pedestal))
108  {
109  peakval = gpulse.GetY()[iSample];
110  peakPos = iSample;
111  }
112  }
113  peakval -= pedestal;
114 
115  if (verbosity)
116  {
117  cout << "SampleFit_PowerLawDoubleExp - "
118  << "pedestal = " << pedestal << ", "
119  << "peakval = " << peakval << ", "
120  << "peakPos = " << peakPos << endl;
121  }
122 
123  // build default value
124  struct default_values_t
125  {
126  default_values_t(double default_value, double min_value, double max_value)
127  : def(default_value)
128  , min(min_value)
129  , max(max_value)
130  {
131  }
132  double def;
133  double min;
134  double max;
135  };
136 
137  vector<default_values_t> default_values(n_parameter, default_values_t(numeric_limits<double>::signaling_NaN(), numeric_limits<double>::signaling_NaN(), numeric_limits<double>::signaling_NaN()));
138 
139  default_values[0] = default_values_t(peakval * .7, peakval * -1.5, peakval * 1.5);
140  default_values[1] = default_values_t(peakPos - risetime, peakPos - 3 * risetime, peakPos + risetime);
141  default_values[2] = default_values_t(5., 1, 10.);
142  default_values[3] = default_values_t(risetime, risetime * .2, risetime * 10);
143  default_values[4] = default_values_t(pedestal, pedestal - abs(peakval), pedestal + abs(peakval));
144  // default_values[5] = default_values_t(0.3, 0, 1);
145  // default_values[6] = default_values_t(5, risetime * .2, risetime * 10);
146  default_values[5] = default_values_t(0, 0, 0); // disable 2nd component
147  default_values[6] = default_values_t(risetime, risetime, risetime);
148 
149  // fit function
150  TF1 fits("f_SignalShape_PowerLawDoubleExp", SignalShape_PowerLawDoubleExp, 0., n_samples, n_parameter);
151  fits.SetParNames("Amplitude", "Sample Start", "Power", "Peak Time 1", "Pedestal", "Amplitude ratio", "Peak Time 2");
152 
153  for (int i = 0; i < n_parameter; ++i)
154  {
155  if (parameters_io.find(i) == parameters_io.end())
156  {
157  fits.SetParameter(i, default_values[i].def);
158 
159  if (default_values[i].min < default_values[i].max)
160  {
161  fits.SetParLimits(i, default_values[i].min, default_values[i].max);
162  }
163  else
164  {
165  fits.FixParameter(i, default_values[i].def);
166  }
167 
168  if (verbosity)
169  {
170  cout << "SampleFit_PowerLawDoubleExp - parameter [" << i << "]: "
171  << "default value = " << default_values[i].def
172  << ", min value = " << default_values[i].min
173  << ", max value = " << default_values[i].max << endl;
174  }
175  }
176  else
177  {
178 // fits.SetParLimits(i, parameters_io[i], parameters_io[i]);
179  fits.SetParameter(i, parameters_io[i]);
180  fits.FixParameter(i, parameters_io[i]);
181 
182  if (verbosity)
183  {
184  cout << "SampleFit_PowerLawDoubleExp - parameter [" << i << "]: fixed to " << parameters_io[i] << endl;
185  }
186  }
187  }
188 
189  if (verbosity <= 1)
190  gpulse.Fit(&fits, "QRN0W", "goff", 0., (double) n_samples);
191  else
192  gpulse.Fit(&fits, "RN0VW+", "goff", 0., (double) n_samples);
193 
194  // store results
195  pedestal = fits.GetParameter(4);
196 
197  const double peakpos1 = fits.GetParameter(3);
198  const double peakpos2 = fits.GetParameter(6);
199  double max_peakpos = fits.GetParameter(1) + (peakpos1 > peakpos2 ? peakpos1 : peakpos2);
200  if (max_peakpos > n_samples - 1) max_peakpos = n_samples - 1;
201 
202  if (fits.GetParameter(0) > 0)
203  peak_sample = fits.GetMaximumX(fits.GetParameter(1), max_peakpos);
204  else
205  peak_sample = fits.GetMinimumX(fits.GetParameter(1), max_peakpos);
206 
207  peak = fits.Eval(peak_sample) - pedestal;
208 
209  if (verbosity)
210  {
211  static int id = 0;
212  ++id;
213 
214  string c_name(string("SampleFit_PowerLawDoubleExp_") + to_string(id));
215 
216  TCanvas *canvas = new TCanvas(
217  c_name.c_str(), c_name.c_str());
218  canvas->Update();
219 
220  TGraph *g_plot = static_cast<TGraph *>(gpulse.DrawClone("ap*l"));
221  g_plot->SetTitle((string("ADC data and fit #") + to_string(id) + string(";Sample number;ADC value")).c_str());
222 
223  fits.SetLineColor(kMagenta);
224  fits.DrawClone("same");
225  fits.Print();
226 
227  TF1 f1("f_SignalShape_PowerLawExp1", SignalShape_PowerLawExp, 0., n_samples, 5);
228  f1.SetParameters(
229  fits.GetParameter(0) * (1 - fits.GetParameter(5)) / pow(fits.GetParameter(3), fits.GetParameter(2)) * exp(fits.GetParameter(2)),
230  fits.GetParameter(1),
231  fits.GetParameter(2),
232  fits.GetParameter(2) / fits.GetParameter(3),
233  fits.GetParameter(4));
234  f1.SetLineColor(kBlue);
235  f1.DrawClone("same");
236 
237  TF1 f2("f_SignalShape_PowerLawExp2", SignalShape_PowerLawExp, 0., n_samples, 5);
238  f2.SetParameters(
239  fits.GetParameter(0) * fits.GetParameter(5) / pow(fits.GetParameter(6), fits.GetParameter(2)) * exp(fits.GetParameter(2)),
240  fits.GetParameter(1),
241  fits.GetParameter(2),
242  fits.GetParameter(2) / fits.GetParameter(6),
243  fits.GetParameter(4));
244  f2.SetLineColor(kRed);
245  f2.DrawClone("same");
246 
247  TGraph g_max(1);
248 
249  g_max.GetX()[0] = peak_sample;
250  g_max.GetY()[0] = peak + pedestal;
251 
252  g_max.SetMarkerStyle(kFullCircle);
253  g_max.SetMarkerSize(2);
254  g_max.SetMarkerColor(kRed);
255 
256  static_cast<TGraph *>(g_max.DrawClone("p"));
257 
258  canvas->Update();
259 
260  // if (id == 1)
261  // {
262  // canvas->Print("SampleFit_PowerLawDoubleExp.pdf(");
263  // }
264  canvas->Print("SampleFit_PowerLawDoubleExp.pdf");
265  }
266 
267  for (int i = 0; i < n_parameter; ++i)
268  {
269  parameters_io[i] = fits.GetParameter(i);
270  }
271 
272  if (verbosity)
273  {
274  cout << "SampleFit_PowerLawDoubleExp - "
275  << "peak_sample = " << peak_sample << ", "
276  << "max_peakpos = " << max_peakpos << ", "
277  << "fits.GetParameter(1) = " << fits.GetParameter(1) << ", "
278  << "peak = " << peak << ", "
279  << "pedestal = " << pedestal << endl;
280  }
281 
282  return true;
283 }
284 
285 double
286 SignalShape_PowerLawExp(double *x, double *par)
287 {
288  double pedestal = par[4];
289  // + ((x[0] - 1.5 * par[1]) > 0) * par[5]; // quick fix on exting tails on the signal function
290  if (x[0] < par[1])
291  return pedestal;
292  //double signal = (-1)*par[0]*pow((x[0]-par[1]),par[2])*exp(-(x[0]-par[1])*par[3]);
293  double signal = par[0] * pow((x[0] - par[1]), par[2]) * exp(-(x[0] - par[1]) * par[3]);
294  return pedestal + signal;
295 }
296 
297 double
298 SignalShape_PowerLawDoubleExp(double *x, double *par)
299 {
300  double pedestal = par[4];
301  // + ((x[0] - 1.5 * par[1]) > 0) * par[5]; // quick fix on exting tails on the signal function
302  if (x[0] < par[1])
303  return pedestal;
304  //double signal = (-1)*par[0]*pow((x[0]-par[1]),par[2])*exp(-(x[0]-par[1])*par[3]);
305  // peak / pow(fits.GetParameter(2) / fits.GetParameter(3), fits.GetParameter(2)) * exp(fits.GetParameter(2)) = fits.GetParameter(0); // exact peak height is (p0*Power(p2/p3,p2))/Power(E,p2)
306  // fits.GetParameter(2) / peak_shift = fits.GetParameter(3); // signal peak time
307 
308  double signal = //
309  par[0] //
310  * pow((x[0] - par[1]), par[2]) //
311  * (((1. - par[5]) / pow(par[3], par[2]) * exp(par[2])) * exp(-(x[0] - par[1]) * (par[2] / par[3])) //
312  + (par[5] / pow(par[6], par[2]) * exp(par[2])) * exp(-(x[0] - par[1]) * (par[2] / par[6])) //
313  );
314  return pedestal + signal;
315 }
316 
317 pair<int, int> SAMPAChan2PadXY(uint32_t fee_channel)
318 {
319  static const int pad_map_to_xy[512][2] = {
320  {-1, 0}, //0
321  {-1, 1}, //1
322  {-1, 2}, //2
323  {1, 2}, //3
324  {1, 1}, //4
325  {1, 4}, //5
326  {1, 3}, //6
327  {2, 1}, //7
328  {1, 5}, //8
329  {2, 3}, //9
330  {2, 2}, //10
331  {2, 5}, //11
332  {2, 4}, //12
333  {3, 2}, //13
334  {3, 1}, //14
335  {3, 4}, //15
336  {3, 3}, //16
337  {4, 1}, //17
338  {3, 5}, //18
339  {4, 3}, //19
340  {4, 2}, //20
341  {4, 5}, //21
342  {4, 4}, //22
343  {5, 2}, //23
344  {5, 1}, //24
345  {5, 4}, //25
346  {5, 3}, //26
347  {6, 1}, //27
348  {5, 5}, //28
349  {6, 3}, //29
350  {6, 2}, //30
351  {6, 5}, //31
352  {6, 4}, //32
353  {7, 2}, //33
354  {7, 1}, //34
355  {7, 4}, //35
356  {7, 3}, //36
357  {8, 1}, //37
358  {7, 5}, //38
359  {8, 3}, //39
360  {8, 2}, //40
361  {8, 5}, //41
362  {8, 4}, //42
363  {9, 2}, //43
364  {9, 1}, //44
365  {9, 4}, //45
366  {9, 3}, //46
367  {10, 1}, //47
368  {9, 5}, //48
369  {10, 3}, //49
370  {10, 2}, //50
371  {10, 5}, //51
372  {10, 4}, //52
373  {11, 2}, //53
374  {11, 1}, //54
375  {11, 4}, //55
376  {11, 3}, //56
377  {12, 1}, //57
378  {11, 5}, //58
379  {12, 3}, //59
380  {12, 2}, //60
381  {12, 5}, //61
382  {12, 4}, //62
383  {13, 2}, //63
384  {13, 1}, //64
385  {13, 4}, //65
386  {13, 3}, //66
387  {14, 1}, //67
388  {13, 5}, //68
389  {14, 3}, //69
390  {14, 2}, //70
391  {14, 5}, //71
392  {14, 4}, //72
393  {15, 2}, //73
394  {15, 1}, //74
395  {15, 4}, //75
396  {15, 3}, //76
397  {16, 1}, //77
398  {15, 5}, //78
399  {16, 3}, //79
400  {16, 2}, //80
401  {16, 5}, //81
402  {16, 4}, //82
403  {17, 2}, //83
404  {17, 1}, //84
405  {17, 4}, //85
406  {17, 3}, //86
407  {18, 1}, //87
408  {17, 5}, //88
409  {18, 3}, //89
410  {18, 2}, //90
411  {18, 5}, //91
412  {18, 4}, //92
413  {19, 2}, //93
414  {19, 1}, //94
415  {19, 4}, //95
416  {19, 3}, //96
417  {20, 1}, //97
418  {19, 5}, //98
419  {20, 3}, //99
420  {20, 2}, //100
421  {20, 5}, //101
422  {20, 4}, //102
423  {21, 2}, //103
424  {21, 1}, //104
425  {21, 4}, //105
426  {21, 3}, //106
427  {22, 1}, //107
428  {21, 5}, //108
429  {22, 3}, //109
430  {22, 2}, //110
431  {22, 5}, //111
432  {22, 4}, //112
433  {23, 2}, //113
434  {23, 1}, //114
435  {23, 4}, //115
436  {23, 3}, //116
437  {24, 1}, //117
438  {23, 5}, //118
439  {24, 3}, //119
440  {24, 2}, //120
441  {24, 5}, //121
442  {24, 4}, //122
443  {-1, 3}, //123
444  {-1, 4}, //124
445  {-1, 5}, //125
446  {-1, 6}, //126
447  {-1, 7}, //127
448  {-9, 2}, //128
449  {-3, 1}, //129
450  {-3, 2}, //130
451  {25, 2}, //131
452  {25, 1}, //132
453  {25, 4}, //133
454  {25, 3}, //134
455  {26, 1}, //135
456  {25, 5}, //136
457  {26, 3}, //137
458  {26, 2}, //138
459  {26, 5}, //139
460  {26, 4}, //140
461  {27, 2}, //141
462  {27, 1}, //142
463  {27, 4}, //143
464  {27, 3}, //144
465  {28, 1}, //145
466  {27, 5}, //146
467  {28, 3}, //147
468  {28, 2}, //148
469  {28, 5}, //149
470  {28, 4}, //150
471  {29, 2}, //151
472  {29, 1}, //152
473  {29, 4}, //153
474  {29, 3}, //154
475  {30, 1}, //155
476  {29, 5}, //156
477  {30, 3}, //157
478  {30, 2}, //158
479  {30, 5}, //159
480  {30, 4}, //160
481  {31, 2}, //161
482  {31, 1}, //162
483  {31, 4}, //163
484  {31, 3}, //164
485  {32, 1}, //165
486  {31, 5}, //166
487  {32, 3}, //167
488  {32, 2}, //168
489  {32, 5}, //169
490  {32, 4}, //170
491  {33, 2}, //171
492  {33, 1}, //172
493  {33, 4}, //173
494  {33, 3}, //174
495  {34, 1}, //175
496  {33, 5}, //176
497  {34, 3}, //177
498  {34, 2}, //178
499  {34, 5}, //179
500  {34, 4}, //180
501  {35, 2}, //181
502  {35, 1}, //182
503  {35, 4}, //183
504  {35, 3}, //184
505  {36, 1}, //185
506  {35, 5}, //186
507  {36, 3}, //187
508  {36, 2}, //188
509  {36, 5}, //189
510  {36, 4}, //190
511  {37, 2}, //191
512  {37, 1}, //192
513  {37, 4}, //193
514  {37, 3}, //194
515  {38, 1}, //195
516  {37, 5}, //196
517  {38, 3}, //197
518  {38, 2}, //198
519  {38, 5}, //199
520  {38, 4}, //200
521  {39, 2}, //201
522  {39, 1}, //202
523  {39, 4}, //203
524  {39, 3}, //204
525  {40, 1}, //205
526  {39, 5}, //206
527  {40, 3}, //207
528  {40, 2}, //208
529  {40, 5}, //209
530  {40, 4}, //210
531  {41, 2}, //211
532  {41, 1}, //212
533  {41, 4}, //213
534  {41, 3}, //214
535  {42, 1}, //215
536  {41, 5}, //216
537  {42, 3}, //217
538  {42, 2}, //218
539  {42, 5}, //219
540  {42, 4}, //220
541  {43, 2}, //221
542  {43, 1}, //222
543  {43, 4}, //223
544  {43, 3}, //224
545  {44, 1}, //225
546  {43, 5}, //226
547  {44, 3}, //227
548  {44, 2}, //228
549  {44, 5}, //229
550  {44, 4}, //230
551  {45, 2}, //231
552  {45, 1}, //232
553  {45, 4}, //233
554  {45, 3}, //234
555  {46, 1}, //235
556  {45, 5}, //236
557  {46, 3}, //237
558  {46, 2}, //238
559  {46, 5}, //239
560  {46, 4}, //240
561  {47, 2}, //241
562  {47, 1}, //242
563  {47, 4}, //243
564  {47, 3}, //244
565  {48, 1}, //245
566  {47, 5}, //246
567  {48, 3}, //247
568  {48, 2}, //248
569  {48, 5}, //249
570  {48, 4}, //250
571  {-3, 3}, //251
572  {-3, 4}, //252
573  {-3, 5}, //253
574  {-3, 6}, //254
575  {-3, 7}, //255
576  {-5, 0}, //256
577  {-5, 1}, //257
578  {-5, 2}, //258
579  {48, 6}, //259
580  {-5, 3}, //260
581  {48, 8}, //261
582  {48, 7}, //262
583  {48, 10}, //263
584  {48, 9}, //264
585  {47, 7}, //265
586  {47, 6}, //266
587  {47, 9}, //267
588  {47, 8}, //268
589  {46, 6}, //269
590  {47, 10}, //270
591  {46, 8}, //271
592  {46, 7}, //272
593  {46, 10}, //273
594  {46, 9}, //274
595  {45, 7}, //275
596  {45, 6}, //276
597  {45, 9}, //277
598  {45, 8}, //278
599  {44, 6}, //279
600  {45, 10}, //280
601  {44, 8}, //281
602  {44, 7}, //282
603  {44, 10}, //283
604  {44, 9}, //284
605  {43, 7}, //285
606  {43, 6}, //286
607  {43, 9}, //287
608  {43, 8}, //288
609  {42, 6}, //289
610  {43, 10}, //290
611  {42, 8}, //291
612  {42, 7}, //292
613  {42, 10}, //293
614  {42, 9}, //294
615  {41, 7}, //295
616  {41, 6}, //296
617  {41, 9}, //297
618  {41, 8}, //298
619  {40, 6}, //299
620  {41, 10}, //300
621  {40, 8}, //301
622  {40, 7}, //302
623  {40, 10}, //303
624  {40, 9}, //304
625  {39, 7}, //305
626  {39, 6}, //306
627  {39, 9}, //307
628  {39, 8}, //308
629  {38, 6}, //309
630  {39, 10}, //310
631  {38, 8}, //311
632  {38, 7}, //312
633  {38, 10}, //313
634  {38, 9}, //314
635  {37, 7}, //315
636  {37, 6}, //316
637  {37, 9}, //317
638  {37, 8}, //318
639  {36, 6}, //319
640  {37, 10}, //320
641  {36, 8}, //321
642  {36, 7}, //322
643  {36, 10}, //323
644  {36, 9}, //324
645  {35, 7}, //325
646  {35, 6}, //326
647  {35, 9}, //327
648  {35, 8}, //328
649  {34, 6}, //329
650  {35, 10}, //330
651  {34, 8}, //331
652  {34, 7}, //332
653  {34, 10}, //333
654  {34, 9}, //334
655  {33, 7}, //335
656  {33, 6}, //336
657  {33, 9}, //337
658  {33, 8}, //338
659  {32, 6}, //339
660  {33, 10}, //340
661  {32, 8}, //341
662  {32, 7}, //342
663  {32, 10}, //343
664  {32, 9}, //344
665  {31, 7}, //345
666  {31, 6}, //346
667  {31, 9}, //347
668  {31, 8}, //348
669  {30, 6}, //349
670  {31, 10}, //350
671  {30, 8}, //351
672  {30, 7}, //352
673  {30, 10}, //353
674  {30, 9}, //354
675  {29, 7}, //355
676  {29, 6}, //356
677  {29, 9}, //357
678  {29, 8}, //358
679  {28, 6}, //359
680  {29, 10}, //360
681  {28, 8}, //361
682  {28, 7}, //362
683  {28, 10}, //363
684  {28, 9}, //364
685  {27, 7}, //365
686  {27, 6}, //366
687  {27, 9}, //367
688  {27, 8}, //368
689  {26, 6}, //369
690  {27, 10}, //370
691  {26, 8}, //371
692  {26, 7}, //372
693  {26, 10}, //373
694  {26, 9}, //374
695  {25, 7}, //375
696  {25, 6}, //376
697  {25, 9}, //377
698  {25, 8}, //378
699  {-9, 0}, //379
700  {25, 10}, //380
701  {-5, 5}, //381
702  {-5, 6}, //382
703  {-5, 7}, //383
704  {-7, 0}, //384
705  {-7, 1}, //385
706  {-7, 2}, //386
707  {24, 6}, //387
708  {-7, 3}, //388
709  {24, 8}, //389
710  {24, 7}, //390
711  {24, 10}, //391
712  {24, 9}, //392
713  {23, 7}, //393
714  {23, 6}, //394
715  {23, 9}, //395
716  {23, 8}, //396
717  {22, 6}, //397
718  {23, 10}, //398
719  {22, 8}, //399
720  {22, 7}, //400
721  {22, 10}, //401
722  {22, 9}, //402
723  {21, 7}, //403
724  {21, 6}, //404
725  {21, 9}, //405
726  {21, 8}, //406
727  {20, 6}, //407
728  {21, 10}, //408
729  {20, 8}, //409
730  {20, 7}, //410
731  {20, 10}, //411
732  {20, 9}, //412
733  {19, 7}, //413
734  {19, 6}, //414
735  {19, 9}, //415
736  {19, 8}, //416
737  {18, 6}, //417
738  {19, 10}, //418
739  {18, 8}, //419
740  {18, 7}, //420
741  {18, 10}, //421
742  {18, 9}, //422
743  {17, 7}, //423
744  {17, 6}, //424
745  {17, 9}, //425
746  {17, 8}, //426
747  {16, 6}, //427
748  {17, 10}, //428
749  {16, 8}, //429
750  {16, 7}, //430
751  {16, 10}, //431
752  {16, 9}, //432
753  {15, 7}, //433
754  {15, 6}, //434
755  {15, 9}, //435
756  {15, 8}, //436
757  {14, 6}, //437
758  {15, 10}, //438
759  {14, 8}, //439
760  {14, 7}, //440
761  {14, 10}, //441
762  {14, 9}, //442
763  {13, 7}, //443
764  {13, 6}, //444
765  {13, 9}, //445
766  {13, 8}, //446
767  {12, 6}, //447
768  {13, 10}, //448
769  {12, 8}, //449
770  {12, 7}, //450
771  {12, 10}, //451
772  {12, 9}, //452
773  {11, 7}, //453
774  {11, 6}, //454
775  {11, 9}, //455
776  {11, 8}, //456
777  {10, 6}, //457
778  {11, 10}, //458
779  {10, 8}, //459
780  {10, 7}, //460
781  {10, 10}, //461
782  {10, 9}, //462
783  {9, 7}, //463
784  {9, 6}, //464
785  {9, 9}, //465
786  {9, 8}, //466
787  {8, 6}, //467
788  {9, 10}, //468
789  {8, 8}, //469
790  {8, 7}, //470
791  {8, 10}, //471
792  {8, 9}, //472
793  {7, 7}, //473
794  {7, 6}, //474
795  {7, 9}, //475
796  {7, 8}, //476
797  {6, 6}, //477
798  {7, 10}, //478
799  {6, 8}, //479
800  {6, 7}, //480
801  {6, 10}, //481
802  {6, 9}, //482
803  {5, 7}, //483
804  {5, 6}, //484
805  {5, 9}, //485
806  {5, 8}, //486
807  {4, 6}, //487
808  {5, 10}, //488
809  {4, 8}, //489
810  {4, 7}, //490
811  {4, 10}, //491
812  {4, 9}, //492
813  {3, 7}, //493
814  {3, 6}, //494
815  {3, 9}, //495
816  {3, 8}, //496
817  {2, 6}, //497
818  {3, 10}, //498
819  {2, 8}, //499
820  {2, 7}, //500
821  {2, 10}, //501
822  {2, 9}, //502
823  {1, 7}, //503
824  {1, 6}, //504
825  {1, 9}, //505
826  {1, 8}, //506
827  {0, 6}, //507
828  {1, 10}, //508
829  {-7, 5}, //509
830  {-7, 6}, //510
831  {-7, 7}};
832 
833  static const int sampa_chan_to_pad[] = {
834  287, //0
835  286, //1
836  285, //2
837  284, //3
838  283, //4
839  282, //5
840  281, //6
841  280, //7
842  279, //8
843  278, //9
844  277, //10
845  276, //11
846  275, //12
847  274, //13
848  273, //14
849  272, //15
850  271, //16
851  270, //17
852  269, //18
853  268, //19
854  267, //20
855  266, //21
856  265, //22
857  264, //23
858  263, //24
859  262, //25
860  261, //26
861  260, //27
862  259, //28
863  258, //29
864  257, //30
865  256, //31
866  319, //32
867  318, //33
868  317, //34
869  316, //35
870  315, //36
871  314, //37
872  313, //38
873  312, //39
874  311, //40
875  310, //41
876  309, //42
877  308, //43
878  307, //44
879  306, //45
880  305, //46
881  304, //47
882  303, //48
883  302, //49
884  301, //50
885  300, //51
886  299, //52
887  298, //53
888  297, //54
889  296, //55
890  295, //56
891  294, //57
892  293, //58
893  292, //59
894  291, //60
895  290, //61
896  289, //62
897  288, //63
898  351, //64
899  350, //65
900  349, //66
901  348, //67
902  347, //68
903  346, //69
904  345, //70
905  344, //71
906  343, //72
907  342, //73
908  341, //74
909  340, //75
910  339, //76
911  338, //77
912  337, //78
913  336, //79
914  335, //80
915  334, //81
916  333, //82
917  332, //83
918  331, //84
919  330, //85
920  329, //86
921  328, //87
922  327, //88
923  326, //89
924  325, //90
925  324, //91
926  323, //92
927  322, //93
928  321, //94
929  320, //95
930  383, //96
931  382, //97
932  381, //98
933  380, //99
934  379, //100
935  378, //101
936  377, //102
937  376, //103
938  375, //104
939  374, //105
940  373, //106
941  372, //107
942  371, //108
943  370, //109
944  369, //110
945  368, //111
946  367, //112
947  366, //113
948  365, //114
949  364, //115
950  363, //116
951  362, //117
952  361, //118
953  360, //119
954  359, //120
955  358, //121
956  357, //122
957  356, //123
958  355, //124
959  354, //125
960  353, //126
961  352, //127
962  415, //128
963  414, //129
964  413, //130
965  412, //131
966  411, //132
967  410, //133
968  409, //134
969  408, //135
970  407, //136
971  406, //137
972  405, //138
973  404, //139
974  403, //140
975  402, //141
976  401, //142
977  400, //143
978  399, //144
979  398, //145
980  397, //146
981  396, //147
982  395, //148
983  394, //149
984  393, //150
985  392, //151
986  391, //152
987  390, //153
988  389, //154
989  388, //155
990  387, //156
991  386, //157
992  385, //158
993  384, //159
994  447, //160
995  446, //161
996  445, //162
997  444, //163
998  443, //164
999  442, //165
1000  441, //166
1001  440, //167
1002  439, //168
1003  438, //169
1004  437, //170
1005  436, //171
1006  435, //172
1007  434, //173
1008  433, //174
1009  432, //175
1010  431, //176
1011  430, //177
1012  429, //178
1013  428, //179
1014  427, //180
1015  426, //181
1016  425, //182
1017  424, //183
1018  423, //184
1019  422, //185
1020  421, //186
1021  420, //187
1022  419, //188
1023  418, //189
1024  417, //190
1025  416, //191
1026  479, //192
1027  478, //193
1028  477, //194
1029  476, //195
1030  475, //196
1031  474, //197
1032  473, //198
1033  472, //199
1034  471, //200
1035  470, //201
1036  469, //202
1037  468, //203
1038  467, //204
1039  466, //205
1040  465, //206
1041  464, //207
1042  463, //208
1043  462, //209
1044  461, //210
1045  460, //211
1046  459, //212
1047  458, //213
1048  457, //214
1049  456, //215
1050  455, //216
1051  454, //217
1052  453, //218
1053  452, //219
1054  451, //220
1055  450, //221
1056  449, //222
1057  448, //223
1058  511, //224
1059  510, //225
1060  509, //226
1061  508, //227
1062  507, //228
1063  506, //229
1064  505, //230
1065  504, //231
1066  503, //232
1067  502, //233
1068  501, //234
1069  500, //235
1070  499, //236
1071  498, //237
1072  497, //238
1073  496, //239
1074  495, //240
1075  494, //241
1076  493, //242
1077  492, //243
1078  491, //244
1079  490, //245
1080  489, //246
1081  488, //247
1082  487, //248
1083  486, //249
1084  485, //250
1085  484, //251
1086  483, //252
1087  482, //253
1088  481, //254
1089  480, //255
1090  0 //256 , the invalid ID
1091  };
1092 
1093  if (fee_channel >= 256)
1094  fee_channel = 256;
1095 
1096  const int pad_number = sampa_chan_to_pad[fee_channel];
1097  const int pad_x = pad_map_to_xy[pad_number][0];
1098  const int pad_y = pad_map_to_xy[pad_number][1];
1099 
1100  return make_pair(pad_x, pad_y);
1101 }
1102 
1103 } // namespace FEEv1
1104 
1105 } // namespace TPCDaqDefs