3#include "CLHEP/Units/PhysicalConstants.h"
4#include "GaudiKernel/Bootstrap.h"
5#include "GaudiKernel/DataSvc.h"
6#include "GaudiKernel/IDataProviderSvc.h"
7#include "GaudiKernel/ISvcLocator.h"
8#include "GaudiKernel/PropertyMgr.h"
9#include "GaudiKernel/SmartDataPtr.h"
11#include "G4DigiManager.hh"
13#include "Randomize.hh"
15#include "CLHEP/Units/PhysicalConstants.h"
37const static int electrons_select_method_threhold = 0;
39const static int _nbins = 2000;
40typedef std::vector<int>
Vint;
42const static double zeros[_nbins] = { 0};
43static void compareMap(
const std::map<int, double> mapQ1[2][2],
const std::map<int, double> mapQ2[2][2]);
44static void DrawToFile(
const double *h,
const char *filename);
45static void checkMemorySize();
49static bool compareVector(
const vector<T> &v1,
const vector<T> &v2,
const char *description,
double threshold = 0,
bool noOutput =
false) {
50 if (threshold < 0) threshold = 0;
53 bool found_mismatch =
false;
54 const vector<T> *vLarger = &v1;
55 char vLargerName[] =
"v1";
57 if (v1.size() != v2.size())
return false;
58 for (
size_t i = 0; i < std::min(v1.size(), v2.size()); i++) {
59 if (max(v1[i], v2[i]) - min(v1[i], v2[i]) > threshold)
return false;
62 if (v1.size() != v2.size()) {
64 if (not found_mismatch) {
65 cout <<
"compareVector:" << description <<
":found mismatch:" <<
'\n';
66 found_mismatch =
true;
69 cout <<
"\t size not match, v1:" << v1.size() <<
" v2:" << v2.size() <<
"\n";
70 if (v1.size() < v2.size()) {
76 for (
size_t i = 0; i < std::min(v1.size(), v2.size()); i++) {
77 if (max(v1[i], v2[i]) - min(v1[i], v2[i]) > threshold) {
79 if (not found_mismatch) {
80 cout <<
"compareVector:" << description <<
":found mismatch:" <<
'\n';
81 found_mismatch =
true;
84 cout <<
"\t at i=" << i <<
" not match, v1[i] = " << v1[i] <<
" v2[i] = " << v2[i] <<
'\n';
88 for (
size_t i = min(v1.size(), v2.size()); i < max(v1.size(), v2.size()); i++) {
90 if (not found_mismatch) {
91 cout <<
"compareVector:" << description <<
":found mismatch:" <<
'\n';
92 found_mismatch =
true;
95 cout <<
"\t at i=" << i <<
", only has " << vLargerName <<
"[i] = " << (*vLarger)[i] <<
'\n';
98 return !found_mismatch;
102static bool compareArray(
const T *v1,
const T *v2,
size_t length,
const char *description,
double threshold = 0,
bool noOutput=
false) {
103 if (threshold < 0) threshold = 0;
106 bool found_mismatch =
false;
108 for (
size_t i = 0; i <
length; i++) {
109 if (max(v1[i], v2[i]) - min(v1[i], v2[i]) > threshold) {
111 if (noOutput)
return false;
112 if (not found_mismatch) {
113 cout <<
"compareArray:" << description <<
":found mismatch:" <<
'\n';
114 found_mismatch =
true;
117 cout <<
"\t at i=" << i <<
" not match, v1[i] = " << v1[i] <<
" v2[i] = " << v2[i] <<
'\n';
120 return !found_mismatch;
125static double rectangle2(
double t,
double *x,
double *y,
int Npx) {
129 for (
int i = 0; i < Npx - 1; i++) {
130 if (
t >= x[i] &&
t < x[i + 1]) {
136 I = y[id] + (y[
id + 1] - y[id]) * (
t - x[
id]) / (
x[
id + 1] -
x[id]);
151static double rectangle2_fast(
double t,
double *x,
const double *y,
int Npx) {
153 const int nbinsx = 2000;
154 const double xmin = 0;
155 const double xmax = 1000;
156 const double binWidth = (xmax - xmin) / nbinsx;
160 if (
t > xmin + binWidth / 2 &&
t < xmax - binWidth / 2) {
161 id = (int)floor((
t - binWidth / 2 - xmin) / binWidth);
163#ifdef INDUCTIONGAR_DEBUG_RECTANGLE2_FAST_TEST
165 for (
int i = 0; i < Npx - 1; i++) {
166 if (
t >= x[i] &&
t < x[i + 1]) {
172 cout <<
"CgemDigitizerSvc::InductionGar2::rectangle2_fast: 2 method calced id doesnot correspond, "
173 <<
"id new : " << id2 <<
" id old : " <<
id <<
" t : " <<
t <<
" x at id old " <<
x[id2] <<
'\n';
177 I = y[id] + (y[
id + 1] - y[id]) * (
t - x[
id]) / (
x[
id + 1] -
x[id]);
183static double rectangle2(
double t, std::vector<double> &x,
const double *y,
int Npx) {
187 for (
int i = 0; i < Npx - 1; i++) {
188 if (
t >= x[i] &&
t < x[i + 1]) {
194 I = y[id] + (y[
id + 1] - y[id]) * (
t - x[
id]) / (
x[
id + 1] -
x[id]);
204 result = 2000. * (0.00181928 *
exp(-
t / 3.) - 0.0147059 *
exp(-
t / 20.) + 0.0128866 *
exp(-
t / 100.));
213 result = 0.000627357 * (1358.7 *
exp(-
t * 0.0385647) *
t + 1358.7 *
exp(-
t * 0.0114353) *
t + 100164. *
exp(-
t * 0.0385647) - 100164. *
exp(-0.0114353 *
t));
218static TH1F
Convolution_Tbranch(
const double *Input_Curr_plot_001,
double xmin,
double xmax,
int Npx = 2000)
221 TH1F h_signalT(
"h_signalT",
"", Npx, xmin, xmax);
222 std::vector<double> Input_Time_plot_001(Npx);
223 for (
int i = 0; i < Npx; i++) Input_Time_plot_001[i] = h_signalT.GetBinCenter(i + 1);
225 double xmin_f1(0.), xmax_f1(1000);
227 double step_f1 = (xmax_f1 - xmin_f1) / nStep_f1;
230 std::vector<double>
x(Npx);
231 std::vector<double> y_001(Npx);
233 for (
int i = 0; i < Npx; i++) {
234 x[i] = xmin + (xmax - xmin) / Npx * (i + 0.5);
235 double fun_001 = 0.0;
237 for (
int j = 0; j < nStep_f1; j++) {
238 x_f1 = xmin_f1 + step_f1 * (j + 0.5);
239 fun_001 +=
rectangle2(x_f1, Input_Time_plot_001, Input_Curr_plot_001, Npx) *
T_branch2(x[i] - x_f1) * step_f1;
244 for (
int init = 0; init < Npx; init++) {
245 h_signalT.SetBinContent(init + 1, -y_001[init]);
253 double xmin(0), xmax(1000);
256 TH1F h_signalT(
"h_signalT",
"", Npx, xmin, xmax);
257 double Input_Time_plot_001[Npx];
258 for (
int i = 0; i < Npx; i++) Input_Time_plot_001[i] = h_signalT.GetBinCenter(i + 1);
260 double xmin_f1(0.), xmax_f1(1000);
262 double step_f1 = (xmax_f1 - xmin_f1) / nStep_f1;
268 for (
int i = 0; i < Npx; i++) {
269 x[i] = xmin + (xmax - xmin) / Npx * (i + 0.5);
270 double fun_001 = 0.0;
272 for (
int j = 0; j < nStep_f1; j++) {
273 x_f1 = xmin_f1 + step_f1 * (j + 0.5);
279 for (
int init = 0; init < Npx; init++) {
280 h_signalT.SetBinContent(init + 1, -y_001[init]);
286static TH1F
Convolution_Ebranch(
const double *Input_Curr_plot_001,
double xmin,
double xmax,
int Npx = 2000)
288 TH1F h_signalE(
"h_signalE",
"", Npx, xmin, xmax);
289 std::vector<double> Input_Time_plot_001(Npx);
290 for (
int i = 0; i < Npx; i++) Input_Time_plot_001[i] = h_signalE.GetBinCenter(i + 1);
292 double xmin_f1(0.), xmax_f1(1000);
294 double step_f1 = (xmax_f1 - xmin_f1) / nStep_f1;
297 std::vector<double>
x(Npx);
298 std::vector<double> y_001(Npx);
300 for (
int i = 0; i < Npx; i++) {
301 x[i] = xmin + (xmax - xmin) / Npx * (i + 0.5);
302 double fun_001 = 0.0;
304 for (
int j = 0; j < nStep_f1; j++) {
305 x_f1 = xmin_f1 + step_f1 * (j + 0.5);
306 fun_001 +=
rectangle2(x_f1, Input_Time_plot_001, Input_Curr_plot_001, Npx) *
E_branch2(x[i] - x_f1) * step_f1;
311 for (
int init = 0; init < Npx; init++) {
312 h_signalE.SetBinContent(init + 1, -y_001[init]);
320 double xmin(0), xmax(1000);
323 TH1F h_signalE(
"h_signalE",
"", Npx, xmin, xmax);
324 double Input_Time_plot_001[Npx];
325 for (
int i = 0; i < Npx; i++) Input_Time_plot_001[i] = h_signalE.GetBinCenter(i + 1);
327 double xmin_f1(0.), xmax_f1(1000);
329 double step_f1 = (xmax_f1 - xmin_f1) / nStep_f1;
335 for (
int i = 0; i < Npx; i++) {
336 x[i] = xmin + (xmax - xmin) / Npx * (i + 0.5);
337 double fun_001 = 0.0;
339 for (
int j = 0; j < nStep_f1; j++) {
340 x_f1 = xmin_f1 + step_f1 * (j + 0.5);
346 for (
int init = 0; init < Npx; init++) {
347 h_signalE.SetBinContent(init + 1, -y_001[init]);
353#ifdef INDUCTIONGAR_DEBUG_CONVOLUTION_TBRANCH_FFT_TEST
360static TH1F Convolution_Tbranch_noskip(
const double *Input_Curr_plot_001)
362 double xmin(0), xmax(1000);
365 TH1F h_signalT(
"h_signalT",
"", Npx, xmin, xmax);
366 double Input_Time_plot_001[Npx];
367 for (
int i = 0; i < Npx; i++) Input_Time_plot_001[i] = h_signalT.GetBinCenter(i + 1);
369 double xmin_f1(0.), xmax_f1(1000);
371 double step_f1 = (xmax_f1 - xmin_f1) / nStep_f1;
377 for (
int i = 0; i < Npx; i++) {
378 x[i] = xmin + (xmax - xmin) / Npx * (i + 0.5);
379 double fun_001 = 0.0;
381 for (
int j = 0; j < nStep_f1; j++) {
382 x_f1 = xmin_f1 + step_f1 * (j + 0.5);
388 for (
int init = 0; init < Npx; init++) {
389 h_signalT.SetBinContent(init + 1, -y_001[init]);
395static TH1F Convolution_Ebranch_noskip(
const double *Input_Curr_plot_001)
397 double xmin(0), xmax(1000);
400 TH1F h_signalE(
"h_signalE",
"", Npx, xmin, xmax);
401 double Input_Time_plot_001[Npx];
402 for (
int i = 0; i < Npx; i++) Input_Time_plot_001[i] = h_signalE.GetBinCenter(i + 1);
404 double xmin_f1(0.), xmax_f1(1000);
406 double step_f1 = (xmax_f1 - xmin_f1) / nStep_f1;
412 for (
int i = 0; i < Npx; i++) {
413 x[i] = xmin + (xmax - xmin) / Npx * (i + 0.5);
414 double fun_001 = 0.0;
416 for (
int j = 0; j < nStep_f1; j++) {
417 x_f1 = xmin_f1 + step_f1 * (j + 0.5);
423 for (
int init = 0; init < Npx; init++) {
424 h_signalE.SetBinContent(init + 1, -y_001[init]);
431 double xmin(0), xmax(1000);
434 double *p_TBranch = &(
TBranch.front());
435 for (
int i = 0; i < Npx; i++) {
436 double x = xmin + (xmax - xmin) * i / Npx;
457 double xmin(0), xmax(1000);
460 TH1D h_signal(
"h_signal",
"", Npx, xmin, xmax);
461 double *p_signal = h_signal.GetArray() + 1;
462 this->
conv->
convolve(p_signal, Input_Curr_plot_001, 0, Npx, -0.5);
464#ifdef INDUCTIONGAR_DEBUG_CONVOLUTION_TBRANCH_FFT_TEST
465 const double dx_abs_threhold = 1e-6;
466 const double dx_ref_threhold = 1e-6;
467 TH1F h_signal_ref = Convolution_Tbranch_noskip(Input_Curr_plot_001);
468 bool found_mismatch =
false;
469 for (
int i = 1; i <= Npx; i++) {
470 if (
abs((h_signal[i] - h_signal_ref[i]) / h_signal_ref[i]) > dx_ref_threhold and
abs(h_signal[i] - h_signal_ref[i]) > dx_abs_threhold) {
471 if (not found_mismatch) {
472 std::cout <<
"CgemDigitizerSvc::InductionGar2::Convolution_Tbranch_fft found results not match: ";
473 found_mismatch =
true;
475 std::cout <<
"ref: " << h_signal_ref[i] <<
"; this: " << h_signal[i] <<
"; at i=" << i <<
";threhold abs=" << dx_abs_threhold <<
"; ref=" << dx_ref_threhold <<
'\n';
484 double xmin(0), xmax(1000);
487 double *p_EBranch = &(
EBranch.front());
488 for (
int i = 0; i < Npx; i++) {
489 double x = xmin + (xmax - xmin) * i / Npx;
510 double xmin(0), xmax(1000);
513 TH1D h_signal(
"h_signalE",
"", Npx, xmin, xmax);
514 double *p_signal = h_signal.GetArray() + 1;
515 this->
conv->
convolve(p_signal, Input_Curr_plot_001, 0, Npx, -0.5);
517#ifdef INDUCTIONGAR_DEBUG_CONVOLUTION_TBRANCH_FFT_TEST
518 const double dx_abs_threhold = 1e-6;
519 const double dx_ref_threhold = 1e-6;
520 TH1F h_signal_ref = Convolution_Ebranch_noskip(Input_Curr_plot_001);
521 bool found_mismatch =
false;
522 for (
int i = 1; i <= Npx; i++) {
523 if (
abs((h_signal[i] - h_signal_ref[i]) / h_signal_ref[i]) > dx_ref_threhold and
abs(h_signal[i] - h_signal_ref[i]) > dx_abs_threhold) {
524 if (not found_mismatch) {
525 std::cout <<
"CgemDigitizerSvc::InductionGar2::Convolution_Ebranch_fft found results not match: ";
526 found_mismatch =
true;
528 std::cout <<
"ref: " << h_signal_ref[i] <<
"; this: " << h_signal[i] <<
"; at i=" << i <<
";threhold abs=" << dx_abs_threhold <<
"; ref=" << dx_ref_threhold <<
'\n';
537 string testPath = getenv(
"CGEMDIGITIZERSVCROOT");
538 m_LUTFilePath =
"/bes3fs/cgemCosmic/data/CGEM_cosmic_look_up_table_from_10_to_17.root";
539 m_V2EfineFile = testPath +
"testFIle/V2Efine.root";
540 sample_delay = 162.5;
554 m_magConfig = magConfig;
555 std::cout <<
"InductionGar2 sampling time : " << sample_delay << std::endl;
557 string filePath_ratio = getenv(
"CGEMDIGITIZERSVCROOT");
559 if (0 == m_magConfig)
560 fileName = filePath_ratio +
"/dat/par_InductionGar_0T.txt";
562 fileName = filePath_ratio +
"/dat/par_InductionGar_1T.txt";
563 ifstream fin(fileName.c_str(), ios::in);
564 cout <<
"InductionGar2 fileName: " << fileName << endl;
568 if (!fin.is_open()) {
569 cout <<
"ERROR: can not open file " << fileName << endl;
572 for (
int m = 0; m < 3; m++) {
573 for (
int l = 0; l < 5; l++) {
574 for (
int k = 0; k < 5; k++) {
575 for (
int i = 0; i < 4; i++) {
576 fin >> RatioX[m][l][k][i];
578 for (
int j = 0; j < 3; j++) {
579 fin >> RatioV[m][l][k][j];
586 string fileName1 = filePath_ratio +
"/dat/VQ_relation.txt";
587 ifstream VQin(fileName1.c_str(), ios::in);
588 VQin >> VQ_slope >> VQ_const;
592 string filePath = getenv(
"CGEMDIGITIZERSVCROOT");
593 for (
int i = 0; i < 3; i++) {
594 for (
int j = 0; j < 5; j++) {
595 for (
int k = 0; k < 5; k++) {
597 sprintf(temp1,
"%i", (i + 1));
599 sprintf(temp2,
"%i", ((j + 1) * 10 + k + 1));
600 if (0 == m_magConfig)
601 fileName = filePath +
"/dat/InducedCurrent_Root_0T/layer" + temp1 +
"_" + temp2 +
".root";
603 fileName = filePath +
"/dat/InducedCurrent_Root_1T/layer" + temp1 +
"_" + temp2 +
".root";
604 TFile *file_00 = TFile::Open(fileName.c_str(),
"read");
605 TH1 *readThis_x3 = 0;
606 TH1 *readThis_x4 = 0;
607 TH1 *readThis_x5 = 0;
608 TH1 *readThis_x6 = 0;
609 TH1 *readThis_v5 = 0;
610 TH1 *readThis_v6 = 0;
611 TH1 *readThis_v7 = 0;
612 file_00->GetObject(
"readThis_x3", readThis_x3);
613 file_00->GetObject(
"readThis_x4", readThis_x4);
614 file_00->GetObject(
"readThis_v5", readThis_v5);
615 file_00->GetObject(
"readThis_x5", readThis_x5);
616 file_00->GetObject(
"readThis_v6", readThis_v6);
617 file_00->GetObject(
"readThis_x6", readThis_x6);
618 file_00->GetObject(
"readThis_v7", readThis_v7);
620 double scaleX=m_ScaleSignalX;
621 double scaleV=(1-scaleX*(RatioX[i][j][k][0]+RatioX[i][j][k][1]+RatioX[i][j][k][2]+RatioX[i][j][k][3]))/(RatioV[i][j][k][0]+RatioV[i][j][k][1]+RatioV[i][j][k][2]);
623 SignalX[i][j][k][0][
init] = scaleX*readThis_x3->GetBinContent(
init + 1);
624 SignalX[i][j][k][1][
init] = scaleX*readThis_x4->GetBinContent(
init + 1);
625 SignalX[i][j][k][2][
init] = scaleX*readThis_x5->GetBinContent(
init + 1);
626 SignalX[i][j][k][3][
init] = scaleX*readThis_x6->GetBinContent(
init + 1);
627 SignalV[i][j][k][0][
init] = scaleV*readThis_v5->GetBinContent(
init + 1);
628 SignalV[i][j][k][1][
init] = scaleV*readThis_v6->GetBinContent(
init + 1);
629 SignalV[i][j][k][2][
init] = scaleV*readThis_v7->GetBinContent(
init + 1);
633 temp[0][
init * 2] = SignalX[i][j][k][0][
init];
634 temp[1][
init * 2] = SignalX[i][j][k][1][
init];
635 temp[2][
init * 2] = SignalX[i][j][k][2][
init];
636 temp[3][
init * 2] = SignalX[i][j][k][3][
init];
637 temp[4][
init * 2] = SignalV[i][j][k][0][
init];
638 temp[5][
init * 2] = SignalV[i][j][k][1][
init];
639 temp[6][
init * 2] = SignalV[i][j][k][2][
init];
640 temp[0][
init * 2 + 1] = SignalX[i][j][k][0][
init];
641 temp[1][
init * 2 + 1] = SignalX[i][j][k][1][
init];
642 temp[2][
init * 2 + 1] = SignalX[i][j][k][2][
init];
643 temp[3][
init * 2 + 1] = SignalX[i][j][k][3][
init];
644 temp[4][
init * 2 + 1] = SignalV[i][j][k][0][
init];
645 temp[5][
init * 2 + 1] = SignalV[i][j][k][1][
init];
646 temp[6][
init * 2 + 1] = SignalV[i][j][k][2][
init];
649 Signal_ConvolverX[i][j][k][0].
init(temp[0] + 2, 160, 2000);
650 Signal_ConvolverX[i][j][k][1].
init(temp[1] + 2, 160, 2000);
651 Signal_ConvolverX[i][j][k][2].
init(temp[2] + 2, 160, 2000);
652 Signal_ConvolverX[i][j][k][3].
init(temp[3] + 2, 160, 2000);
653 Signal_ConvolverV[i][j][k][0].
init(temp[4] + 2, 160, 2000);
654 Signal_ConvolverV[i][j][k][1].
init(temp[5] + 2, 160, 2000);
655 Signal_ConvolverV[i][j][k][2].
init(temp[6] + 2, 160, 2000);
660 TFile *LUTFile = TFile::Open(m_LUTFilePath.c_str(),
"read");
661 TTree *tree = (TTree *)LUTFile->Get(
"tree");
662 Float_t V_th_T, V_th_E, QDC_a, QDC_b, QDC_saturation;
663 Int_t layer, sheet, strip_v, strip_x;
664 tree->SetBranchAddress(
"strip_x_boss", &strip_x);
665 tree->SetBranchAddress(
"strip_v_boss", &strip_v);
666 tree->SetBranchAddress(
"layer", &layer);
667 tree->SetBranchAddress(
"sheet", &sheet);
668 tree->SetBranchAddress(
"calib_QDC_slope", &QDC_a);
669 tree->SetBranchAddress(
"calib_QDC_const", &QDC_b);
670 tree->SetBranchAddress(
"calib_QDC_saturation", &QDC_saturation);
671 tree->SetBranchAddress(
"v_thr_T_mV", &V_th_T);
672 tree->SetBranchAddress(
"v_thr_E_mV", &V_th_E);
674 double thresholdMin_X_T = 999;
675 double thresholdMin_V_T = 999;
676 double thresholdMin_X_Q = 999;
677 double thresholdMin_V_Q = 999;
678 for (
int i = 0; i < tree->GetEntries(); i++) {
681 T_thr_V[layer][sheet][0][strip_x] = V_th_T;
682 if (V_th_T > 0 && V_th_T < thresholdMin_X_T) thresholdMin_X_T = V_th_T;
684 E_thr_V[layer][sheet][0][strip_x] = V_th_E;
685 if (V_th_E > 0 && V_th_E < thresholdMin_X_Q) thresholdMin_X_Q = V_th_E;
687 QDC_slope[layer][sheet][0][strip_x] = QDC_a;
688 QDC_const[layer][sheet][0][strip_x] = QDC_b;
689 Qsaturation[layer][sheet][0][strip_x] = QDC_saturation;
692 T_thr_V[layer][sheet][1][strip_v] = V_th_T;
693 if (V_th_T > 0 && V_th_T < thresholdMin_V_T) thresholdMin_V_T = V_th_T;
695 E_thr_V[layer][sheet][1][strip_v] = V_th_E;
696 if (V_th_E > 0 && V_th_E < thresholdMin_V_Q) thresholdMin_V_Q = V_th_E;
698 QDC_slope[layer][sheet][1][strip_v] = QDC_a;
699 QDC_const[layer][sheet][1][strip_v] = QDC_b;
700 Qsaturation[layer][sheet][1][strip_v] = QDC_saturation;
703 for (
int i = 0; i < tree->GetEntries(); i++) {
706 if (V_th_T <= 0) T_thr_V[layer][sheet][0][strip_x] = thresholdMin_X_T;
707 if (V_th_E <= 0) E_thr_V[layer][sheet][0][strip_x] = thresholdMin_X_Q;
710 if (V_th_T <= 0) T_thr_V[layer][sheet][1][strip_v] = thresholdMin_V_T;
711 if (V_th_E <= 0) E_thr_V[layer][sheet][1][strip_v] = thresholdMin_V_Q;
716 for (
int i = 0; i < 832; i++) {
717 T_thr_V[2][0][0][i] = 12.;
718 E_thr_V[2][0][0][i] = 12.;
719 QDC_slope[2][0][0][i] = -10.47;
720 QDC_const[2][0][0][i] = 482.3;
721 Qsaturation[2][0][0][i] = 45.;
722 T_thr_V[2][1][0][i] = 10.;
723 E_thr_V[2][1][0][i] = 10.;
724 QDC_slope[2][1][0][i] = -10.47;
725 QDC_const[2][1][0][i] = 482.3;
726 Qsaturation[2][1][0][i] = 45.;
729 for (
int i = 0; i < 1395; i++) {
730 T_thr_V[2][0][1][i] = 12.;
731 E_thr_V[2][0][1][i] = 12.;
732 QDC_slope[2][0][1][i] = -10.47;
733 QDC_const[2][0][1][i] = 482.3;
734 Qsaturation[2][0][1][i] = 45.;
735 T_thr_V[2][1][1][i] = 10.;
736 E_thr_V[2][1][1][i] = 10.;
737 QDC_slope[2][1][1][i] = -10.47;
738 QDC_const[2][1][1][i] = 482.3;
739 Qsaturation[2][1][1][i] = 45.;
774 cout<<
"InductionGar: "<<endl;
775 cout<<
"QinGausSigma="<<m_QinGausSigma[0]
776 <<
", "<<m_QinGausSigma[1]
779 m_deadStrip[0][0][0].insert(40);
780 m_deadStrip[0][0][0].insert(189);
781 m_deadStrip[0][0][0].insert(322);
782 m_deadStrip[0][0][0].insert(350);
783 m_deadStrip[0][0][0].insert(457);
784 m_deadStrip[0][0][1].insert(282);
785 m_deadStrip[0][0][1].insert(467);
786 m_deadStrip[0][0][1].insert(715);
787 m_deadStrip[0][0][1].insert(773);
788 m_deadStrip[0][0][1].insert(795);
789 m_deadStrip[0][0][1].insert(803);
790 m_deadStrip[1][0][1].insert(305);
791 m_deadStrip[1][0][1].insert(307);
792 m_deadStrip[1][0][1].insert(381);
793 m_deadStrip[1][0][1].insert(443);
794 m_deadStrip[1][0][1].insert(486);
795 m_deadStrip[1][0][1].insert(550);
796 m_deadStrip[1][0][1].insert(620);
797 m_deadStrip[1][0][1].insert(631);
798 m_deadStrip[1][0][1].insert(660);
799 m_deadStrip[1][0][1].insert(681);
800 m_deadStrip[1][1][1].insert(425);
801 m_deadStrip[1][1][1].insert(455);
802 m_deadStrip[1][1][1].insert(459);
803 m_deadStrip[1][1][1].insert(461);
804 m_deadStrip[1][1][1].insert(535);
805 m_deadStrip[1][1][1].insert(536);
806 m_deadStrip[1][1][1].insert(614);
807 m_deadStrip[1][1][1].insert(672);
812 if (debug_ref_electrons!=0)bShowRef=
true;
815 m_xstripSheet.clear();
817 m_vstripSheet.clear();
821 m_xstripT_Branch.clear();
822 m_vstripT_Branch.clear();
823 m_xstripQ_Branch.clear();
824 m_vstripQ_Branch.clear();
830 std::vector<int> m000_xstripSheet;
831 std::vector<int> m000_xstripID;
832 std::vector<int> m000_vstripSheet;
833 std::vector<int> m000_vstripID;
834 std::vector<double> m000_xstripQ;
835 std::vector<double> m000_vstripQ;
836 std::vector<double> m000_xstripT_Branch;
837 std::vector<double> m000_vstripT_Branch;
838 std::vector<double> m000_xstripQ_Branch;
839 std::vector<double> m000_vstripQ_Branch;
857 Vint Save_Sheetx, Save_Sheetv;
858 Vint Save_FinalstripIDx, Save_FinalstripIDv;
859 Vint Save_Gridx, Save_Gridv;
860 Vint Save_IDx, Save_IDv;
861 Vint Save_Tx, Save_Tv;
872 for (
int i = 0; i < 2; i++) {
873 for (
int k = 0; k < 2; k++) {
874 m_mapQ[i][k].clear();
885 HitHistMap::const_iterator itm = hitmap.begin();
886 for (; itm != hitmap.end(); itm++) {
887 const Vint &hist = itm->second;
888 for (
int num = 0;
num < hist.size();
num++) {
892 if (Nelec != debug_ref_electrons->
x->size()) {
893 cout <<
"oops! given different electrons! map gives " << Nelec <<
" while list gives" << debug_ref_electrons->
x->size() << endl;
899 const vector<float> &
x = *debug_ref_electrons->
x;
900 const vector<float> &y = *debug_ref_electrons->
y;
901 const vector<float> &z = *debug_ref_electrons->
z;
902 const vector<float> &
t = *debug_ref_electrons->
t;
903 const int nElectrons =
x.size();
905 for (
int i = 0; i < nElectrons; i++) {
907 double phi_electron = atan2(y[i],
x[i]);
908 double z_electron = z[i];
909 G4ThreeVector pos(
x[i], y[i], z[i]);
910 for (
int j = 0; j < NSheet; j++) {
912 if (CgemReadoutPlane->
OnThePlane(phi_electron, z_electron)) {
928 double L_XPitch = CgemReadoutPlane->
getXPitch();
929 double L_VPitch = CgemReadoutPlane->
getVPitch();
930 grid_v = floor(distX / L_XPitch * 5. + 2.5);
931 grid_x = floor(distV / L_VPitch * 5. + 2.5);
936 if (xID >= 0 && vID >= 0) {
937 map<int, double>::iterator itx = m_mapQ[j][0].find(xID);
938 map<int, double>::iterator itv = m_mapQ[j][1].find(vID);
939 if (RatioX[layer][grid_x][grid_v][2] != 0) {
940 if (itx == m_mapQ[j][0].end()) {
941 m_mapQ[j][0][xID] = RatioX[layer][grid_x][grid_v][2];
942 Save_Gridx.push_back(grid_x * 100 + grid_v * 10 + 2);
943 Save_IDx.push_back(j * 10000 + xID);
944 Save_Tx.push_back(
t[i]);
947 double Q = (itx->second) + RatioX[layer][grid_x][grid_v][2];
948 m_mapQ[j][0][xID] = Q;
949 Save_Gridx.push_back(grid_x * 100 + grid_v * 10 + 2);
950 Save_IDx.push_back(j * 10000 + xID);
951 Save_Tx.push_back(
t[i]);
954 vector<int>::iterator result_Sheetx = find(Save_Sheetx.begin(), Save_Sheetx.end(), j * 10000 + xID);
955 if (result_Sheetx == Save_Sheetx.end()) {
956 Save_Sheetx.push_back(j * 10000 + xID);
959 if (RatioV[layer][grid_x][grid_v][1] != 0) {
960 if (itv == m_mapQ[j][1].end()) {
961 m_mapQ[j][1][vID] = RatioV[layer][grid_x][grid_v][1];
962 Save_Gridv.push_back(grid_x * 100 + grid_v * 10 + 1);
963 Save_IDv.push_back(j * 10000 + vID);
964 Save_Tv.push_back(
t[i]);
966 double Q = (itv->second) + RatioV[layer][grid_x][grid_v][1];
967 m_mapQ[j][1][vID] = Q;
968 Save_Gridv.push_back(grid_x * 100 + grid_v * 10 + 1);
969 Save_IDv.push_back(j * 10000 + vID);
970 Save_Tv.push_back(
t[i]);
972 vector<int>::iterator result_Sheetv = find(Save_Sheetv.begin(), Save_Sheetv.end(), j * 10000 + vID);
973 if (result_Sheetv == Save_Sheetv.end()) {
974 Save_Sheetv.push_back(j * 10000 + vID);
979 if ((xID >= 0 && vID >= 0) && (xID + 1) < CgemReadoutPlane->
getNXstrips()) {
980 map<int, double>::iterator itx = m_mapQ[j][0].find(xID + 1);
981 if (RatioX[layer][grid_x][grid_v][3] != 0) {
982 if (itx == m_mapQ[j][0].end()) {
983 m_mapQ[j][0][xID + 1] = RatioX[layer][grid_x][grid_v][3];
984 Save_Gridx.push_back(grid_x * 100 + grid_v * 10 + 3);
985 Save_IDx.push_back(j * 10000 + xID + 1);
986 Save_Tx.push_back(
t[i]);
989 double Q = (itx->second) + RatioX[layer][grid_x][grid_v][3];
990 m_mapQ[j][0][xID + 1] = Q;
991 Save_Gridx.push_back(grid_x * 100 + grid_v * 10 + 3);
992 Save_IDx.push_back(j * 10000 + xID + 1);
993 Save_Tx.push_back(
t[i]);
996 vector<int>::iterator result_Sheetx = find(Save_Sheetx.begin(), Save_Sheetx.end(), j * 10000 + xID + 1);
997 if (result_Sheetx == Save_Sheetx.end()) {
998 Save_Sheetx.push_back(j * 10000 + xID + 1);
1003 if ((xID >= 0 && vID >= 0) && (vID + 1) < CgemReadoutPlane->
getNVstrips()) {
1004 map<int, double>::iterator itv = m_mapQ[j][1].find(vID + 1);
1005 if (RatioV[layer][grid_x][grid_v][2] != 0) {
1006 if (itv == m_mapQ[j][1].end()) {
1007 m_mapQ[j][1][vID + 1] = RatioV[layer][grid_x][grid_v][2];
1008 Save_Gridv.push_back(grid_x * 100 + grid_v * 10 + 2);
1009 Save_IDv.push_back(j * 10000 + vID + 1);
1010 Save_Tv.push_back(
t[i]);
1012 double Q = (itv->second) + RatioV[layer][grid_x][grid_v][2];
1013 m_mapQ[j][1][vID + 1] = Q;
1014 Save_Gridv.push_back(grid_x * 100 + grid_v * 10 + 2);
1015 Save_IDv.push_back(j * 10000 + vID + 1);
1016 Save_Tv.push_back(
t[i]);
1019 vector<int>::iterator result_Sheetv = find(Save_Sheetv.begin(), Save_Sheetv.end(), j * 10000 + vID + 1);
1020 if (result_Sheetv == Save_Sheetv.end()) {
1021 Save_Sheetv.push_back(j * 10000 + vID + 1);
1026 if ((xID >= 0 && vID >= 0) && (xID - 2) >= 0) {
1027 map<int, double>::iterator itx = m_mapQ[j][0].find(xID - 2);
1028 if (RatioX[layer][grid_x][grid_v][0] != 0) {
1029 if (itx == m_mapQ[j][0].end()) {
1030 m_mapQ[j][0][xID - 2] = RatioX[layer][grid_x][grid_v][0];
1031 Save_Gridx.push_back(grid_x * 100 + grid_v * 10 + 0);
1032 Save_IDx.push_back(j * 10000 + xID - 2);
1033 Save_Tx.push_back(
t[i]);
1036 double Q = (itx->second) + RatioX[layer][grid_x][grid_v][0];
1037 m_mapQ[j][0][xID - 2] = Q;
1038 Save_Gridx.push_back(grid_x * 100 + grid_v * 10 + 0);
1039 Save_IDx.push_back(j * 10000 + xID - 2);
1040 Save_Tx.push_back(
t[i]);
1043 vector<int>::iterator result_Sheetx = find(Save_Sheetx.begin(), Save_Sheetx.end(), j * 10000 + xID - 2);
1044 if (result_Sheetx == Save_Sheetx.end()) {
1045 Save_Sheetx.push_back(j * 10000 + xID - 2);
1050 if ((xID >= 0 && vID >= 0) && (xID - 1) >= 0) {
1051 map<int, double>::iterator itx = m_mapQ[j][0].find(xID - 1);
1052 if (RatioX[layer][grid_x][grid_v][1] != 0) {
1053 if (itx == m_mapQ[j][0].end()) {
1054 m_mapQ[j][0][xID - 1] = RatioX[layer][grid_x][grid_v][1];
1055 Save_Gridx.push_back(grid_x * 100 + grid_v * 10 + 1);
1056 Save_IDx.push_back(j * 10000 + xID - 1);
1057 Save_Tx.push_back(
t[i]);
1059 double Q = (itx->second) + RatioX[layer][grid_x][grid_v][1];
1060 m_mapQ[j][0][xID - 1] = Q;
1061 Save_Gridx.push_back(grid_x * 100 + grid_v * 10 + 1);
1062 Save_IDx.push_back(j * 10000 + xID - 1);
1063 Save_Tx.push_back(
t[i]);
1066 vector<int>::iterator result_Sheetx = find(Save_Sheetx.begin(), Save_Sheetx.end(), j * 10000 + xID - 1);
1067 if (result_Sheetx == Save_Sheetx.end()) {
1068 Save_Sheetx.push_back(j * 10000 + xID - 1);
1073 if ((xID >= 0 && vID >= 0) && (vID - 1) >= 0) {
1074 map<int, double>::iterator itv = m_mapQ[j][1].find(vID - 1);
1075 if (RatioV[layer][grid_x][grid_v][0] != 0) {
1076 if (itv == m_mapQ[j][1].end()) {
1077 m_mapQ[j][1][vID - 1] = RatioV[layer][grid_x][grid_v][0];
1078 Save_Gridv.push_back(grid_x * 100 + grid_v * 10 + 0);
1079 Save_IDv.push_back(j * 10000 + vID - 1);
1080 Save_Tv.push_back(
t[i]);
1082 double Q = (itv->second) + RatioV[layer][grid_x][grid_v][0];
1083 m_mapQ[j][1][vID - 1] = Q;
1084 Save_Gridv.push_back(grid_x * 100 + grid_v * 10 + 0);
1085 Save_IDv.push_back(j * 10000 + vID - 1);
1086 Save_Tv.push_back(
t[i]);
1089 vector<int>::iterator result_Sheetv = find(Save_Sheetv.begin(), Save_Sheetv.end(), j * 10000 + vID - 1);
1090 if (result_Sheetv == Save_Sheetv.end()) {
1091 Save_Sheetv.push_back(j * 10000 + vID - 1);
1105 std::map<IndexGar,std::vector<double> > hitFFTMap;
1108 std::map<int, double> mapQ[2][2];
1110 calcMapQFromHitHistMap(hitmap, layer, mapQ);
1111 Vint Save_Sheetx2, Save_Sheetv2;
1112 calcSaveSheetXVFromMapQ(Save_Sheetx2, Save_Sheetv2, mapQ);
1114 compareMap(m_mapQ, mapQ);
1117 compareVector(Save_Sheetx, Save_Sheetx2,
"Save_Sheetx", 1e-5);
1118 compareVector(Save_Sheetv, Save_Sheetv2,
"Save_Sheetv", 1e-5);
1121 calcMapQFromHitHistMap(hitmap, layer, m_mapQ);
1122 calcSaveSheetXVFromMapQ(Save_Sheetx, Save_Sheetv, m_mapQ);
1124 calcHitHistFftMap(hitFFTMap, hitmap);
1132 double Q_threshold = 1.5e-15 / 1.602176565e-19;
1133 double Q_saturation = 45.e-15 / 1.602176565e-19;
1134 double Q_resolution = 0.256e-15 / 1.602176565e-19;
1135 double T_threshold = 12;
1146 for (
int i = 0; i < Save_Sheetx.size(); i++) {
1147 int sheetx_id = Save_Sheetx[i] / 10000;
1148 int stripx_id = Save_Sheetx[i] % 10000;
1150 Save_FinalstripIDx.push_back(Save_Sheetx[i]);
1152 m000_xstripSheet.push_back(sheetx_id);
1153 m000_xstripID.push_back(stripx_id);
1154 m000_xstripQ.push_back(m_mapQ[sheetx_id][0][stripx_id]);
1158 for (
int i = 0; i < Save_Sheetv.size(); i++) {
1159 int sheetv_id = Save_Sheetv[i] / 10000;
1160 int stripv_id = Save_Sheetv[i] % 10000;
1162 Save_FinalstripIDv.push_back(Save_Sheetv[i]);
1163 m000_vstripSheet.push_back(sheetv_id);
1164 m000_vstripID.push_back(stripv_id);
1165 m000_vstripQ.push_back(m_mapQ[sheetv_id][1][stripv_id]);
1170 std::vector<double> xTfirst;
1171 std::vector<double> vTfirst;
1173 for (
int h = 0; h < Save_FinalstripIDx.size(); h++) {
1175 std::map<int, std::vector<int> > electron_hit_tmp;
1177 const int _up = 1000;
1178 const int _nbins = 2000;
1179 double binsize = (double)(_up - _low) / _nbins;
1180 int sheetx_id = Save_FinalstripIDx[h] / 10000;
1181 int stripx_id = Save_FinalstripIDx[h] % 10000;
1182 double histX_bin_Content[_nbins] = {0};
1183 double histX_bin_Content2[_nbins] = {0};
1184 Tmin = Tmin2 = 999999;
1185 if (isDeadStrip(layer,sheetx_id,0,stripx_id)) {
1186 xTfirst.push_back(Tmin);
1188 m000_xstripT_Branch.push_back(T_th);
1190 m000_xstripQ_Branch.push_back(Qin);
1197 int original_affected_elec = 0;
1199 for (
int i = 0; i < Save_Gridx.size(); i++) {
1203 int z_IDx = Save_IDx[i];
1204 int start_bin = Save_Tx[i] / binsize;
1207 if (z_IDx == Save_FinalstripIDx[h]) {
1208 if (Save_Tx[i] < Tmin) Tmin = Save_Tx[i];
1209 if (start_bin < _nbins and start_bin >= 0) {
1210 electron_hit_tmp[Save_Gridx[i]].push_back(start_bin);
1212 original_affected_elec++;
1221 for (std::map<
int, std::vector<int> >::iterator it = electron_hit_tmp.begin();
1222 it != electron_hit_tmp.end(); it++) {
1223 std::vector<int> &hitlist = it->second;
1224 const int &Save_Grid = it->first;
1226 if (hitlist.size() < electrons_select_method_threhold) {
1227 conv1PerGrid_legacy(Save_Grid, histX_bin_Content, hitlist, layer, 0);
1229 conv1PerGrid_fft(Save_Grid, histX_bin_Content, hitlist, layer, 0);
1233 cout <<
"original_affected_elec " << original_affected_elec <<
" ";
1234 calcStripCurrent(histX_bin_Content2, Tmin2,hitFFTMap, hitmap, layer, sheetx_id, stripx_id, 0);
1236 if (Tmin != Tmin2) {
1237 cout <<
"at stripX " << stripx_id <<
"Tmin: " << Tmin <<
" Tmin2: " << Tmin2 <<
"\n";
1242 compareArray(histX_bin_Content, histX_bin_Content2, _nbins,
"hist_bin_content", 1e-5);
1243 string emptyStr =
"";
1244 DrawToFile(histX_bin_Content, (emptyStr +
"st" + (
long)stripx_id +
"old").Data());
1245 DrawToFile(histX_bin_Content2, (emptyStr +
"st" + (
long)stripx_id +
"new").Data());
1252 calcStripCurrent(histX_bin_Content2, Tmin,hitFFTMap, hitmap, layer, sheetx_id, stripx_id, 0);
1256 xTfirst.push_back(Tmin);
1264 T_threshold = T_thr_V[layer][sheetx_id][0][stripx_id];
1268 if (flg_xT == 0 && fabs(h_signalT.GetBinContent(
init + 1)) >= fabs(T_threshold)) {
1269 T_th = _low + binsize * (
init - 1) + fabs(T_threshold - h_signalT.GetBinContent(
init)) * binsize / fabs(h_signalT.GetBinContent(
init + 1) - h_signalT.GetBinContent(
init)) + gRandom->Gaus(0, 2);
1270 m000_xstripT_Branch.push_back(T_th);
1276 m000_xstripT_Branch.push_back(T_th);
1278 double V_sampling = 0.;
1285 double T_sample = T_th + sample_delay;
1286 int sample_bin = T_sample / binsize;
1287 double sample_bin_ = T_sample / binsize;
1288 V_sampling = h_signalE.GetBinContent(sample_bin) + (h_signalE.GetBinContent(sample_bin + 1) - h_signalE.GetBinContent(sample_bin)) *
double(sample_bin_ - sample_bin);
1292 if (h_signalE.GetMaximum() > E_thr_V[layer][sheetx_id][0][stripx_id]) over_th = 1;
1295 Qin = V_sampling*VQ_slope + VQ_const+gRandom->Gaus(0,m_QinGausSigma[0]);
1296 if (m_saturation && Qin > Qsaturation[layer][sheetx_id][0][stripx_id])
1297 Qin = Qsaturation[layer][sheetx_id][0][stripx_id];
1306 m000_xstripQ_Branch.push_back(Qin);
1311 for (
int h = 0; h < Save_FinalstripIDv.size(); h++) {
1312 std::map<int, std::vector<int> > electron_hit_tmp;
1314 const int _up = 1000;
1315 const int _nbins = 2000;
1316 double binsize = (double)(_up - _low) / _nbins;
1317 int sheetv_id = Save_FinalstripIDv[h] / 10000;
1318 int stripv_id = Save_FinalstripIDv[h] % 10000;
1319 double histV_bin_Content[_nbins] = {0};
1322 if (isDeadStrip(layer,sheetv_id,1,stripv_id)) {
1323 vTfirst.push_back(Tmin);
1325 m000_vstripT_Branch.push_back(T_th);
1327 m000_vstripQ_Branch.push_back(Qin);
1331 calcStripCurrent(histV_bin_Content, Tmin, hitFFTMap,hitmap, layer, sheetv_id, stripv_id, 1);
1333 vTfirst.push_back(Tmin);
1339 T_threshold = T_thr_V[layer][sheetv_id][1][stripv_id];
1343 if (flg_vT == 0 && fabs(h_signalT.GetBinContent(
init + 1)) >= fabs(T_threshold)) {
1344 T_th = _low + binsize * (
init - 1) + fabs(T_threshold - h_signalT.GetBinContent(
init)) * binsize / fabs(h_signalT.GetBinContent(
init + 1) - h_signalT.GetBinContent(
init)) + gRandom->Gaus(0, 2);
1345 m000_vstripT_Branch.push_back(T_th);
1351 m000_vstripT_Branch.push_back(T_th);
1353 double V_sampling = 0.;
1359 double T_sample = T_th + sample_delay;
1360 int sample_bin = T_sample / binsize;
1361 double sample_bin_ = T_sample / binsize;
1362 V_sampling = h_signalE.GetBinContent(sample_bin) + (h_signalE.GetBinContent(sample_bin + 1) - h_signalE.GetBinContent(sample_bin)) *
double(sample_bin_ - sample_bin);
1365 if (h_signalE.GetMaximum() > E_thr_V[layer][sheetv_id][1][stripv_id]) over_th = 1;
1368 Qin = V_sampling*VQ_slope + VQ_const+gRandom->Gaus(0,m_QinGausSigma[1]);
1369 if (m_saturation && Qin > Qsaturation[layer][sheetv_id][1][stripv_id])
1370 Qin = Qsaturation[layer][sheetv_id][1][stripv_id];
1379 m000_vstripQ_Branch.push_back(Qin);
1393 double q_to_fC_factor = 1.602176565e-4;
1399 for (
int i = 0; i < m000_xstripSheet.size(); i++) {
1400 m_xstripSheet.push_back(m000_xstripSheet[i]);
1401 m_xstripID.push_back(m000_xstripID[i]);
1402 m_xstripQ.push_back(m000_xstripQ[i] * q_to_fC_factor);
1403 m_xstripT_Branch.push_back(m000_xstripT_Branch[i]);
1404 m_xstripQ_Branch.push_back(m000_xstripQ_Branch[i]);
1405 m_xTfirst.push_back(xTfirst[i]);
1410 for (
int i = 0; i < m000_vstripSheet.size(); i++) {
1411 m_vstripSheet.push_back(m000_vstripSheet[i]);
1412 m_vstripID.push_back(m000_vstripID[i]);
1413 m_vstripQ.push_back(m000_vstripQ[i] * q_to_fC_factor);
1414 m_vstripT_Branch.push_back(m000_vstripT_Branch[i]);
1415 m_vstripQ_Branch.push_back(m000_vstripQ_Branch[i]);
1416 m_vTfirst.push_back(vTfirst[i]);
1421 for (
int i = 0; i < m000_xstripSheet.size(); i++) {
1422 if (m000_xstripQ_Branch[i] >= 0) {
1423 m_xstripSheet.push_back(m000_xstripSheet[i]);
1424 m_xstripID.push_back(m000_xstripID[i]);
1425 m_xstripQ.push_back(m000_xstripQ[i] * q_to_fC_factor);
1426 m_xstripT_Branch.push_back(m000_xstripT_Branch[i]);
1427 m_xstripQ_Branch.push_back(m000_xstripQ_Branch[i]);
1428 m_xTfirst.push_back(xTfirst[i]);
1435 for (
int i = 0; i < m000_vstripSheet.size(); i++) {
1436 if (m000_vstripQ_Branch[i] >= 0) {
1437 m_vstripSheet.push_back(m000_vstripSheet[i]);
1438 m_vstripID.push_back(m000_vstripID[i]);
1439 m_vstripQ.push_back(m000_vstripQ[i] * q_to_fC_factor);
1440 m_vstripT_Branch.push_back(m000_vstripT_Branch[i]);
1441 m_vstripQ_Branch.push_back(m000_vstripQ_Branch[i]);
1442 m_vTfirst.push_back(vTfirst[i]);
1459void InductionGar2::calcMapQFromHitHistMap(
const HitHistMap &histmap,
int layer, std::map<int, double> mapQ[2][2])
const {
1460 for (HitHistMap::const_iterator it = histmap.begin(); it != histmap.end(); ++it) {
1462 const Vint &hist = it->second;
1465 int grid_x = index.
gridX;
1466 int grid_v = index.
gridV;
1467 int sheet = index.
sheet;
1468 if (xID < 0 || vID < 0)
continue;
1473 for (
int i = 0; i < _nbins + 1; i++) {
1474 nElectrons += hist[i];
1476 for (
int indexOID = 0; indexOID < 4; indexOID++) {
1477 int dID = indexOID - 2;
1478 if (0 <= xID + dID && xID + dID < nXID) {
1479 mapQ[sheet][0][xID + dID] += RatioX[layer][grid_x][grid_v][indexOID] * nElectrons;
1482 for (
int indexOID = 0; indexOID < 3; indexOID++) {
1483 int dID = indexOID - 1;
1484 if (0 <= vID + dID && vID + dID < nVID) {
1485 mapQ[sheet][1][vID + dID] += RatioV[layer][grid_x][grid_v][indexOID] * nElectrons;
1492void InductionGar2::calcSaveSheetXVFromMapQ(
Vint &Save_Sheetx,
Vint &Save_Sheetv, std::map<int, double>
const mapQ[2][2])
const {
1494 for (
int sheet = 0; sheet < 2; sheet++) {
1495 for (
int xvView = 0; xvView < 2; xvView++) {
1496 Vint &save_sheet = xvView ? Save_Sheetv : Save_Sheetx;
1497 for (std::map<int, double>::const_iterator it = mapQ[sheet][xvView].begin();
1498 it != mapQ[sheet][xvView].end(); it++) {
1499 if (it->second != 0) {
1500 save_sheet.push_back(sheet * 10000 + it->first);
1516void InductionGar2::calcStripCurrent(
double *strip_current,
double &timeFirstHit,
const HitHistMap &histmap,
int layer,
int req_sheetid,
int req_stripid,
int xvaxis)
const {
1519 const int _up = 1000;
1520 const int _nbins = 2000;
1521 double binsize = (double)(_up - _low) / _nbins;
1525 int indexTimeFirstHit = 9999;
1526 int affectedElectron = 0;
1527 for (HitHistMap::const_iterator it = histmap.begin(); it != histmap.end(); ++it) {
1529 const Vint &hist = it->second;
1533 int strip = xvaxis ? vID : xID;
1534 int grid_x = index.
gridX;
1535 int grid_v = index.
gridV;
1536 int sheet = index.
sheet;
1538 if (xID < 0 || vID < 0)
continue;
1540 if (req_sheetid != sheet)
continue;
1543 indexOID = req_stripid - strip + 2;
1544 if (indexOID < 0 || indexOID >= 4)
continue;
1545 if (RatioX[layer][grid_x][grid_v][indexOID] == 0)
continue;
1549 indexOID = req_stripid - strip + 2;
1550 if (indexOID < 0 || indexOID >= 3)
continue;
1551 if (RatioV[layer][grid_x][grid_v][indexOID] == 0)
continue;
1555 double electron_hit_tmp_hist[_nbins] = {0};
1556 for (
int i = 0; i < _nbins; i++) electron_hit_tmp_hist[i] = hist[i];
1558 double strip_current_tmp[_nbins] = {0};
1559 Signal_Convolver[layer][grid_x][grid_v][indexOID].convolve(strip_current_tmp, electron_hit_tmp_hist, 0, _nbins);
1560 for (
int i = 0; i < _nbins; i++) {
1561 strip_current[i] += strip_current_tmp[i];
1565 int indexTimeFirstHitLocal = 9999;
1566 for (
int i = 0; i < _nbins; i++) {
1568 indexTimeFirstHitLocal = i;
1572 if (indexTimeFirstHitLocal < indexTimeFirstHit) indexTimeFirstHit = indexTimeFirstHitLocal;
1575 for (
int i = 0; i < _nbins; i++) {
1576 affectedElectron += hist[i];
1579 timeFirstHit = binsize * (indexTimeFirstHit);
1582void InductionGar2::calcStripCurrent(
double *strip_current,
double &timeFirstHit,
const std::map<
IndexGar,std::vector<double> > &histFFTmap,
const HitHistMap &histmap,
int layer,
int req_sheetid,
int req_stripid,
int xvaxis)
const {
1585 const int _up = 1000;
1586 const int _nbins = 2000;
1587 double binsize = (double)(_up - _low) / _nbins;
1588 const ConvolveWithConst(&Signal_Convolver)[3][5][5][4] = xvaxis ? Signal_ConvolverV : Signal_ConvolverX;
1591 int indexTimeFirstHit = 9999;
1592 int affectedElectron = 0;
1594 const int length_Inner=Signal_ConvolverX[0][0][0][0].
getLength();
1595 const int HalfPlus1=(length_Inner/2+1);
1596 vector<double> stripCurrentFFT ;
1597 stripCurrentFFT.resize(HalfPlus1*2);
1598 double* pStripCurrentFFT=&stripCurrentFFT.front();
1599 for (HitHistMap::const_iterator it = histmap.begin(); it != histmap.end(); ++it) {
1601 const Vint &hist = it->second;
1603 const std::vector<double> &histFft =histFFTmap.at(index);
1604 const double * pHistFft=&histFft.front();
1608 int strip = xvaxis ? vID : xID;
1609 int grid_x = index.
gridX;
1610 int grid_v = index.
gridV;
1611 int sheet = index.
sheet;
1613 if (xID < 0 || vID < 0)
continue;
1615 if (req_sheetid != sheet)
continue;
1618 indexOID = req_stripid - strip + 2;
1619 if (indexOID < 0 || indexOID >= 4)
continue;
1620 if (RatioX[layer][grid_x][grid_v][indexOID] == 0)
continue;
1624 indexOID = req_stripid - strip + 2;
1625 if (indexOID < 0 || indexOID >= 3)
continue;
1626 if (RatioV[layer][grid_x][grid_v][indexOID] == 0)
continue;
1644 int indexTimeFirstHitLocal = 9999;
1645 for (
int i = 0; i < _nbins; i++) {
1647 indexTimeFirstHitLocal = i;
1651 if (indexTimeFirstHitLocal < indexTimeFirstHit) indexTimeFirstHit = indexTimeFirstHitLocal;
1654 for (
int i = 0; i < _nbins; i++) {
1655 affectedElectron += hist[i];
1661 timeFirstHit = binsize * (indexTimeFirstHit);
1665void InductionGar2::calcHitHistFftMap(std::map<
IndexGar,std::vector<double> > &histFFTMap,
const HitHistMap &histmap)
const{
1668 const int length_Inner=Signal_ConvolverX[0][0][0][0].
getLength();
1671 double* pIn=&vIn.front();
1675 for (HitHistMap::const_iterator it = histmap.begin(); it != histmap.end(); ++it){
1677 const Vint &hist=it->second;
1678 histFFTMap[index] .resize((length_Inner/2+1)*2);
1679 double * pOut=&histFFTMap[index].front();
1681 for(
int i=0; i<_nbins; i++){
1705void InductionGar2::conv1PerGrid_legacy(
int Save_Grid,
double *hist_bin_Content,
1706 const std::vector<int> &hitlist,
int layer,
int axis)
const {
1711 double const(&Signal)[3][5][5][4][100] = axis ? SignalV : SignalX;
1715 const int _nbins = 2000;
1716 int z_grid_x = Save_Grid / 100;
1717 int z_grid_v = Save_Grid % 100 / 10;
1718 int z_index = Save_Grid % 10;
1719 for (std::vector<int>::const_iterator it_start_bin = hitlist.begin(); it_start_bin != hitlist.end(); it_start_bin++) {
1720 if (*it_start_bin < 0)
continue;
1721 for (
int addi = *it_start_bin; (addi < *it_start_bin + 160) and (addi < _nbins - 1); addi += 2) {
1722 hist_bin_Content[addi] += Signal[layer][z_grid_x][z_grid_v][z_index][(addi - *it_start_bin) / 2 + 1];
1723 hist_bin_Content[addi + 1] += Signal[layer][z_grid_x][z_grid_v][z_index][(addi - *it_start_bin) / 2 + 1];
1737void InductionGar2::conv1PerGrid_fft(
int Save_Grid,
double *hist_bin_Content,
1738 const std::vector<int> &hitlist,
int layer,
int axis)
const {
1741 const int _nbins = 2000;
1742 double hist_tmp[_nbins] = {0};
1743 int z_grid_x = Save_Grid / 100;
1744 int z_grid_v = Save_Grid % 100 / 10;
1745 int z_index = Save_Grid % 10;
1748 double electron_hit_tmp_hist[_nbins] = {0};
1750 for (std::vector<int>::const_iterator it_start_bin = hitlist.begin(); it_start_bin != hitlist.end(); it_start_bin++) {
1751 if (*it_start_bin < _nbins and *it_start_bin >= 0) electron_hit_tmp_hist[*it_start_bin] += 1;
1753 Signal_Convolver[layer][z_grid_x][z_grid_v][z_index].convolve(hist_tmp, electron_hit_tmp_hist, 0, _nbins);
1755#ifdef INDUCTIONGAR_DEBUG_CONV1PERGRID_FFT_TEST
1757 double hist_tmp2[_nbins] = {0};
1758 bool found_mismatch =
false;
1759 const double Accept_Threshold = 1e-5;
1760 const double Accept_Threshold_ref = 1e-5;
1761 conv1PerGrid_legacy(Save_Grid, hist_tmp2, hitlist, layer, axis);
1762 for (
int i = 0; i < _nbins; i++) {
1763 if (
abs(hist_tmp[i] - hist_tmp2[i]) >= Accept_Threshold and
abs((hist_tmp[i] - hist_tmp2[i]) / hist_tmp2[i]) >= Accept_Threshold_ref) {
1764 if (not found_mismatch) {
1765 std::cout <<
"CgemDigitizerSvc::InductionGar2::conv1PerGrid_fft found results not match: " << endl;
1766 found_mismatch =
true;
1768 std::cout <<
" previous: " << hist_tmp[i] <<
"; new " << hist_tmp2[i] <<
"; at i=" << i <<
'\n'
1775 for (
int i = 0; i < _nbins; i++) {
1776 hist_bin_Content[i] += hist_tmp[i];
1791void InductionGar2::conv1PerGrid_legacy(
int gridX,
int gridV,
int indexOID,
double *hist_bin_Content,
1792 const std::vector<int> &elecHitHist,
int layer,
int axis)
const {
1797 const double(&Signal)[3][5][5][4][100] = axis ? SignalV : SignalX;
1802 const int _nbins = 2000;
1804 for (
int start_bin = 0; start_bin < _nbins; start_bin++) {
1805 int nElec = elecHitHist[start_bin];
1806 for (
int addi = start_bin; (addi < start_bin + 160) and (addi < _nbins - 1); addi += 2) {
1807 hist_bin_Content[addi] += Signal[layer][gridX][gridV][indexOID][(addi - start_bin) / 2 + 1] * nElec;
1808 hist_bin_Content[addi + 1] += Signal[layer][gridX][gridV][indexOID][(addi - start_bin) / 2 + 1] * nElec;
1824void InductionGar2::conv1PerGrid_fft(
int gridX,
int gridV,
int indexOID,
double *hist_bin_Content,
1825 const std::vector<int> &elecHitHist,
int layer,
int axis)
const {
1828 const int _nbins = 2000;
1829 double hist_tmp[_nbins] = {0};
1830 int z_grid_x = gridX;
1831 int z_grid_v = gridV;
1832 int z_index = indexOID;
1835 double electron_hit_tmp_hist[_nbins] = {0};
1836 for (
int i = 0; i < _nbins; i++) {
1837 electron_hit_tmp_hist[i] = elecHitHist[i];
1844 Signal_Convolver[layer][z_grid_x][z_grid_v][z_index].convolve(hist_tmp, electron_hit_tmp_hist, 0, _nbins);
1846#ifdef INDUCTIONGAR_DEBUG_CONV1PERGRID_FFT_TEST
1848 double hist_tmp2[_nbins] = {0};
1849 bool found_mismatch =
false;
1850 const double Accept_Threshold = 1e-10;
1851 const double Accept_Threshold_ref = 1e-5;
1852 conv1PerGrid_legacy(gridX, gridV, indexOID, hist_tmp2, elecHitHist, layer, axis);
1853 for (
int i = 0; i < _nbins; i++) {
1854 if (
abs(hist_tmp[i] - hist_tmp2[i]) >= Accept_Threshold and
abs((hist_tmp[i] - hist_tmp2[i]) / hist_tmp2[i]) >= Accept_Threshold_ref) {
1855 if (not found_mismatch) {
1856 std::cout <<
"CgemDigitizerSvc::InductionGar2::conv1PerGrid_fft found results not match: " << endl;
1857 found_mismatch =
true;
1859 std::cout <<
" previous: " << hist_tmp[i] <<
"; new " << hist_tmp2[i] <<
"; at i=" << i <<
'\n'
1866 for (
int i = 0; i < _nbins; i++) {
1867 hist_bin_Content[i] += hist_tmp[i];
1879static void compareMap(
const std::map<int, double> mapQ1[2][2],
const std::map<int, double> mapQ2[2][2]) {
1881 for (
int sheet = 0; sheet < 2; sheet++) {
1882 for (
int xvView = 0; xvView < 2; xvView++) {
1883 const std::map<int, double> &m1 = mapQ1[sheet][xvView];
1884 const std::map<int, double> &m2 = mapQ2[sheet][xvView];
1885 cout <<
"CgemDigitizerSvc::InductionGar2::compareMap current sheet " << sheet <<
"; xvView " << xvView << endl;
1886 if (m1.size() != m2.size()) {
1887 cout <<
"\tcompareMap: size of maps not match: map1: " << m1.size() <<
";\tmap2: " << m2.size() <<
'\n';
1889 for (std::map<int, double>::const_iterator it = m2.begin(); it != m2.end(); it++) {
1890 int key = it->first;
1891 double value = it->second;
1893 if (value != m1.at(
key)) {
1894 std::cout <<
"\tcompareMap: value at key " <<
key <<
" not match: map1:" << m1.at(
key) <<
"\tmap2:" << m2.at(
key) <<
'\n';
1896 }
catch (
const std::out_of_range &e) {
1897 std::cout <<
"\tcompareMap: key " <<
key <<
"in map2 " << m2.at(
key) <<
" has no coresponding entry in map1 \n";
1904static void DrawToFile(
const double *h,
const char *filename) {
1905 TH1D h1(
"h_InductionGar2",
"", _nbins, 0, 1000);
1906 for (
int i = 0; i < _nbins; i++) {
1907 h1.SetBinContent(i + 1, h[i]);
1909 TCanvas cx1(
"cx1",
"", 1);
1912 string filebase =
"save/";
1913 string fn = filebase + filename +
".png";
1914 cx1.Print(fn.c_str());
1919static void checkMemorySize()
1922 gSystem->GetProcInfo(&info);
1923 double currentMemory = info.fMemResident/1024;
1924 cout<<
"CgemDigitizerSvc::InductionGar2: current memory size "<<currentMemory<<
" MB"<<endl;
1928bool InductionGar2::isDeadStrip(
int layer,
int sheet,
int XVview,
int strip)
1930 std::set<int> &deadStrips= m_deadStrip[layer][sheet][XVview];
1932 if (deadStrips.count(strip)==1){
EvtComplex exp(const EvtComplex &c)
double abs(const EvtComplex &c)
std::map< IndexGar, std::vector< int > > HitHistMap
TH1F Convolution_Tbranch(const double *Input_Curr_plot_001, double xmin, double xmax, int Npx=2000)
double rectangle2(double t, double *x, double *y, int Npx)
TH1F Convolution_Ebranch(const double *Input_Curr_plot_001, double xmin, double xmax, int Npx=2000)
double rectangle2_fast(double t, double *x, const double *y, int Npx)
calc estimate using linear interpolation of curve {x,y} , at point t; mimic rectangle2() but faster v...
double E_branch2(double t)
double T_branch2(double t)
*************DOUBLE PRECISION m_pi *DOUBLE PRECISION m_HvecTau2 DOUBLE PRECISION m_HvClone2 DOUBLE PRECISION m_gamma1 DOUBLE PRECISION m_gamma2 DOUBLE PRECISION m_thet1 DOUBLE PRECISION m_thet2 INTEGER m_IFPHOT *COMMON c_Taupair $ !Spin Polarimeter vector first Tau $ !Spin Polarimeter vector second Tau $ !Clone Spin Polarimeter vector first Tau $ !Clone Spin Polarimeter vector second Tau $ !Random Euler angle for cloning st tau $ !Random Euler angle for cloning st tau $ !Random Euler angle for cloning st tau $ !Random Euler angle for cloning nd tau $ !Random Euler angle for cloning nd tau $ !Random Euler angle for cloning nd tau $ !phi of HvecTau1 $ !theta of HvecTau1 $ !phi of HvecTau2 $ !theta of HvecTau2 $ !super key
std::vector< double > EBranch
TH1D Convolution_Ebranch_fft(const double *Input_Curr_plot_001)
return convolve of Input_Curr_plot_001 and T_Branch2, a function; tries to mimic Convolution_Ebranch ...
TH1D Convolution_Tbranch_fft(const double *Input_Curr_plot_001)
return convolve of Input_Curr_plot_001 and T_Branch2, a function; tries to mimic Convolution_Tbranch ...
std::vector< double > TBranch
int getNumberOfSheet() const
double getDist2ClosestXStripCenter(double phi, int &id)
bool OnThePlane(double phi, double z) const
double getDist2ClosestVStripCenter(G4ThreeVector pos, int &id)
basically, convolve with fft. convolves 1-d. if size of 2 inputs are fixed, it may yield optimal spee...
std::complex< double > Complex
void FFT(Complex *outHalfPlus1, const double *inNormalLength, int LengthOutAsDouble, int LengthIn) const
Do fft with respect of getLength();.
void init(const double *ConstArray, const int ConstArrayLength, const int Blength, TransformOptimOpt opt=opt_EX, TransformLengthOpt optL=opt_AsShortAsPsb)
void convolve(double *output, const double *B, const int leftIndex, const int sizeofOut, double factor=1) const
do a convolve of stored const A and B, and put results to output.
void IFFT(double *outNormalLength, const Complex *inHalfPlus1, int lengthOut, int lengthInAsDouble) const
Do ifft with respect of getLength();.
virtual CgemGeoReadoutPlane * getReadoutPlane(int iLayer, int iSheet) const =0
virtual CgemGeoLayer * getCgemLayer(int i) const =0
void init(ICgemGeomSvc *geomSvc, double magConfig)
void setMultiElectrons(int layer, int nElectrons, const std::vector< Float_t > &x, const std::vector< Float_t > &y, const std::vector< Float_t > &z, const std::vector< Float_t > &t)
const std::vector< Float_t > * z
const std::vector< Float_t > * t
const std::vector< Float_t > * x
const std::vector< Float_t > * y