Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PROTOTYPE2_FEM.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PROTOTYPE2_FEM.cc
1 // $Id: $
2 
11 #include "PROTOTYPE2_FEM.h"
12 
13 #include <TCanvas.h>
14 #include <TF1.h>
15 #include <TGraph.h>
16 
17 #include <unistd.h> // for sleep
18 #include <cassert>
19 #include <cmath>
20 #include <cstdlib> // for exit
21 #include <iostream>
22 
23 using namespace std;
24 
25 int PROTOTYPE2_FEM::GetHBDCh(const std::string &caloname, int i_column,
26  int i_row)
27 {
28  if (caloname == "HCALIN")
29  {
30  return 64 + 8 * i_column + 2 * i_row;
31  }
32  else if (caloname == "HCALOUT")
33  {
34  return 112 + 8 * i_column + 2 * i_row;
35  }
36  else if (caloname == "EMCAL")
37  {
38  // EMcal cable mapping from John haggerty
39  assert(i_column >= 0);
40  assert(i_column < NCH_EMCAL_COLUMNS);
41  assert(i_row >= 0);
42  assert(i_row < NCH_EMCAL_ROWS);
43 
44  static int canmap[NCH_EMCAL_ROWS * NCH_EMCAL_COLUMNS] = {
45  // 1 ... 15
46  10 + 48, 11 + 48, 8 + 48, 9 + 48, 14 + 48, 15 + 48, 12 + 48, 13 + 48,
47  // 9 ... 16
48  2 + 48, 3 + 48, 0 + 48, 1 + 48, 6 + 48, 7 + 48, 4 + 48, 5 + 48,
49 
50  // 17 ... 24
51  10 + 32, 11 + 32, 8 + 32, 9 + 32, 14 + 32, 15 + 32, 12 + 32, 13 + 32,
52  // 25 ... 32
53  2 + 32, 3 + 32, 0 + 32, 1 + 32, 6 + 32, 7 + 32, 4 + 32, 5 + 32,
54 
55  // 33 ... 40
56  10 + 16, 11 + 16, 8 + 16, 9 + 16, 14 + 16, 15 + 16, 12 + 16, 13 + 16,
57  // 41 42 43 44 45 46 47 48
58  2 + 16, 3 + 16, 0 + 16, 1 + 16, 6 + 16, 7 + 16, 4 + 16, 5 + 16,
59 
60  // 49 50 51 52 53 54 55 56
61  10, 11, 8, 9, 14, 15, 12, 13,
62  // 57 58 59 60 61 62 63 64
63  2, 3, 0, 1, 6, 7, 4, 5};
64 
65  const int tower_index =
66  i_column + NCH_EMCAL_COLUMNS * (NCH_EMCAL_ROWS - 1 - i_row);
67 
68  assert(tower_index >= 0);
69  assert(tower_index < NCH_EMCAL_ROWS * NCH_EMCAL_COLUMNS);
70 
71  return canmap[tower_index];
72  }
73 
74  std::cout << "PROTOTYPE2_FEM::GetHBDCh - invalid input caloname " << caloname
75  << " i_column " << i_column << " i_row " << i_row << std::endl;
76  exit(1);
77  return -9999;
78 }
79 
81  const std::vector<double> &samples, //
82  double &peak, //
83  double &peak_sample, //
84  double &pedstal, //
85  const int verbosity)
86 {
87  int peakPos = 0.;
88 
89  assert(samples.size() == NSAMPLES);
90 
91  TGraph gpulse(NSAMPLES);
92  for (int i = 0; i < NSAMPLES; i++)
93  {
94  (gpulse.GetX())[i] = i;
95 
96  (gpulse.GetY())[i] = samples[i];
97  }
98 
99  double pedestal = gpulse.GetY()[0]; //(double) PEDESTAL;
100  double peakval = pedestal;
101  const double risetime = 4;
102 
103  for (int iSample = 0; iSample < NSAMPLES; iSample++)
104  {
105  if (abs(gpulse.GetY()[iSample] - pedestal) > abs(peakval - pedestal))
106  {
107  peakval = gpulse.GetY()[iSample];
108  peakPos = iSample;
109  }
110  }
111  peakval -= pedestal;
112 
113  // fit function
114  TF1 fits("f_SignalShape_PowerLawExp", SignalShape_PowerLawExp, 0., 24., 6);
115 
116  double par[6] = {0};
117  par[0] = peakval; // /3.;
118  par[1] = peakPos - risetime;
119  if (par[1] < 0.)
120  par[1] = 0.;
121  par[2] = 4.;
122  par[3] = 1.5;
123  par[4] = pedestal;
124  par[5] = 0;
125  fits.SetParameters(par);
126  fits.SetParLimits(0, peakval * 0.9, peakval * 1.1);
127  fits.SetParLimits(1, 0, 24);
128  fits.SetParLimits(2, 2, 4.);
129  fits.SetParLimits(3, 1., 2.);
130  fits.SetParLimits(4, pedestal - abs(peakval), pedestal + abs(peakval));
131  // fits.SetParLimits(5, - abs(peakval), + abs(peakval));
132  fits.FixParameter(5, 0);
133 
134  // Saturation correction - Abhisek
135  for (int ipoint = 0; ipoint < gpulse.GetN(); ipoint++)
136  if ((gpulse.GetY())[ipoint] == 0)
137  {
138  gpulse.RemovePoint(ipoint);
139  ipoint--;
140  }
141 
142  gpulse.Fit(&fits, "MQRN0", "goff", 0., (double) NSAMPLES);
143 
144  if (verbosity)
145  {
146  TCanvas *canvas = new TCanvas("PROTOTYPE2_FEM_SampleFit_PowerLawExp",
147  "PROTOTYPE2_FEM::SampleFit_PowerLawExp");
148  gpulse.DrawClone("ap*l");
149  fits.DrawClone("same");
150  fits.Print();
151  canvas->Update();
152  sleep(1);
153  }
154 
155  // peak = fits.GetParameter(0); // not exactly peak height
156  peak =
157  (fits.GetParameter(0) *
158  pow(fits.GetParameter(2) / fits.GetParameter(3), fits.GetParameter(2))) /
159  exp(fits.GetParameter(
160  2)); // exact peak height is (p0*Power(p2/p3,p2))/Power(E,p2)
161 
162  // peak_sample = fits.GetParameter(1); // signal start time
163  peak_sample = fits.GetParameter(1) +
164  fits.GetParameter(2) / fits.GetParameter(3); // signal peak time
165 
166  // peak integral = p0*Power(p3,-1 - p2)*Gamma(1 + p2). Note yet used in output
167 
168  pedstal = fits.GetParameter(4);
169 
170  return true;
171 }
172 
173 double PROTOTYPE2_FEM::SignalShape_PowerLawExp(double *x, double *par)
174 {
175  double pedestal =
176  par[4] + ((x[0] - 1.5 * par[1]) > 0) *
177  par[5]; // quick fix on exting tails on the signal function
178  if (x[0] < par[1])
179  return pedestal;
180  // double signal =
181  // (-1)*par[0]*pow((x[0]-par[1]),par[2])*exp(-(x[0]-par[1])*par[3]);
182  double signal =
183  par[0] * pow((x[0] - par[1]), par[2]) * exp(-(x[0] - par[1]) * par[3]);
184  return pedestal + signal;
185 }