Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ATrace.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ATrace.C
1 #include "ATrace.h" //always include class header
2 #include "TF1.h"
3 #include "TH1D.h"
4 #include "TH2D.h"
5 #include <iostream>
6 
7 using namespace std;
8 
10 
11 bool ATrace::FastFits = true;
12 
13 double ATrace::SingleEmean = 0;
14 double ATrace::SingleEsigma = 0;
15 double ATrace::DoubleEmean = 0;
16 double ATrace::DoubleEsigma = 0;
17 
18 TH2D* heightCompare=0;
19 TH2D* timeCompare=0;
20 
21 TH1D* heightDiff=0;
22 TH1D* timeDiff=0;
23 
24 
26 {
27  voltage.clear();
28  height=0;
29  time=0;
30  W=0;
31  dW=0;
32 
33  sprintf (fcn_name, "fermi%d", numtraces);
34  fermi = new TF1(fcn_name, "[0]/(exp(-(x-[1])/[2])+1)+[3]", 0, 1024);
35 
36  sprintf (hst_name, "trace%d", numtraces);
37  trace = new TH1D(hst_name, hst_name, 1024, -0.5, 1023.5);
38 
39  numtraces++;
40 }
41 
43 {
44  fermi->Delete();
45  trace->Delete();
46 }
47 
49 {
50 
51  double MaxSum = 9999;
52  int MaxMid = -1;
53  for (int mid=1+n; mid<voltage.size()-n; mid++)
54  {
55  // We know roughly where true electron pulses should be in time - only look in that range
56  if( mid < 420 || mid > 460 ) continue;
57  double Sum=0;
58  for (int bin=mid-n; bin<mid+n; bin++)
59  {
60  Sum += voltage[bin];
61  }
62  if (Sum < MaxSum)
63  {
64  MaxSum = Sum;
65  MaxMid = mid;
66  }
67  }
68 
69  return MaxSum/(2.0*n+1.0);
70 }
71 
73 {
74 
75  double MaxSum = 9999;
76  int MaxMid = -1;
77  for (int mid=1+n; mid<voltage.size()-n; mid++)
78  {
79  // We know roughly where true electron pulses should be in time -- only look in that range
80  if( mid < 420 || mid > 460 ) continue;
81  double Sum=0;
82  for (int bin=mid-n; bin<mid+n; bin++)
83  {
84  Sum += voltage[bin];
85  }
86  if (Sum < MaxSum)
87  {
88  MaxSum = Sum;
89  MaxMid = mid;
90  }
91  }
92 
93  return MaxMid;
94 }
95 
96 
98 {
99  MakeTrace(+1);
100  int bin = trace->GetMaximumBin();
101  height = trace->GetBinContent(bin);
102  time = 0;
103 
104  // 1) get time and height from histogram
105  if (FastFits)
106  {
107  bool found = false;
108  for(int i=bin;i>0;--i)
109  {
110  if(found) break;
111  if(trace->GetBinContent(i) < height/2.0)
112  {
113  found = true;
114  time = trace->GetBinCenter(i);
115  }
116  }
117  }
118  // 2) get time and height from fit
119  else
120  {
121  if (!heightCompare)
122  {
123  heightCompare = new TH2D("heightCompare", "heightCompare", 1000, -0.5, 999.5, 1000, -0.5, 999.5);
124  timeCompare = new TH2D("timeCompare", "timeCompare", 1000, -0.5, 999.5, 1000, -0.5, 999.5);
125  heightDiff = new TH1D("heightDiff", "heightDiff", 1000, -499.5, 500.5);
126  timeDiff = new TH1D("timeDiff", "timeDiff", 1000, -499.5, 500.5);
127  }
128  double X = trace->GetBinCenter(bin);
129 
130  fermi->SetParameter(0,height);
131  fermi->SetParameter(1,X-2);
132  fermi->SetParameter(2,5);
133  fermi->SetParameter(3,2);
134  fermi->SetRange(5,X+2);
135  trace->Fit(fermi,"WWR","",5,X+2);
136 
137  double ht = trace->GetFunction(fcn_name)->GetParameter(0);
138  double tm = trace->GetFunction(fcn_name)->GetParameter(1);
139 
140  heightCompare->Fill(height, ht);
141  timeCompare->Fill(time, tm);
142  heightDiff->Fill(height-ht);
143  timeDiff->Fill(time-tm);
144 
145  height = trace->GetFunction(fcn_name)->GetParameter(0);
146  time = trace->GetFunction(fcn_name)->GetParameter(1);
147  }
148 }
149 
150 
151 int ATrace::NAboveThreshold( double thrup, double thrdown )
152 {
153 
154  int nAbove = 0;
155 
156  bool belowThreshold = true;
157 
158  for(int i=0; i<voltage.size(); i++)
159  {
160  if ( belowThreshold && -voltage[i] >= thrup )
161  {
162  nAbove++;
163  belowThreshold = false;
164  }
165 
166  else if ( !belowThreshold && -voltage[i] < thrdown )
167  {
168  belowThreshold = true;
169  }
170  }
171 
172  return nAbove;
173 
174 }
175 
176 double ATrace::PulseWidth( double thrup, double thrdown )
177 {
178 
179  // The results of this routine are ONLY valid
180  // if NAbove is one.
181 
182  bool belowThreshold = true;
183 
184  int left = 0;
185  int right = 0;
186 
187  for(int i=0; i<voltage.size(); i++)
188  {
189  if ( belowThreshold && voltage[i] >= thrup )
190  {
191  left = i;
192  belowThreshold = false;
193  }
194 
195  else if ( !belowThreshold && voltage[i] < thrdown )
196  {
197  right = i;
198  belowThreshold = true;
199  }
200  }
201 
202  return right-left;
203 
204 }
205 
207 {
208  for(int i=0; i!=voltage.size(); ++i)
209  {
210  double vol = sign*voltage[i];
211  trace->SetBinContent(i+1,vol);
212  }
213 }