AlcapDAQ  1
Functions | Variables
res_analysis_new.cxx File Reference
#include <stdio.h>
#include <stdlib.h>
#include "midas.h"
#include "../../compress/mucap_compress.h"
#include "TH1.h"
#include "TH2.h"
#include "TCanvas.h"

Go to the source code of this file.

Functions

void process_file (char *input_filename, int addr, int fadc)
 
int process_event (void *pevent, int addr, int fadc)
 
bool get_input_event (FILE *fp, char *pevent, int event_number)
 
double findPulse (int nsamples, int *samples)
 
int processIsland (int t0, int nsamples, int *samples, int channel)
 

Variables

TCanvas * c = 0
 
TH2 * hSamples
 
TH1 * hChannelNSample
 
TH1 * hChannelNIsland
 
TH2 * hMinSample
 
TH2 * hMaxSample
 
TH2 * hPulseEnergy
 
TH2 * hPed0
 
TH1 * hPulseIF
 
TH2 * hPulseIvsEnergy
 
TH2 * hPulseFvsEnergy
 
TH2 * hPulseAvsEnergy
 

Function Documentation

double findPulse ( int  nsamples,
int *  samples 
)

Definition at line 122 of file res_analysis_new.cxx.

References hPulseAvsEnergy, hPulseFvsEnergy, hPulseIF, hPulseIvsEnergy, i, nsamples, and pedestalsigma.

122  {
123  int sig_length_counter = 0;
124  double sig_max_height = 0.;
125  int sig_first_index = 0;
126  double sig_integral = 0.;
127  int sig_over_thr = 0;
128 
129  bool hasOvershoot = false;
130  bool hasUndershoot = false;
131  const int kLengthThreshold = 4;
132 
133  // (Serdar) i increased nsamples to 40 (was 16)
134 
135  if(nsamples < 40 ) return 0.;
136 
137  // Let's first find the pedestal
138 
139  // (Serdar) here i check whether selecting the first 5 sample or 10 sample do change anything
140  // on the pedestal determination, see histograms histPeds0first05bins or 10bins for more info
141  // and i find both can be used, so i select first 10 bins to get more info.
142 
143  const int pedSamples = 10;
144  double pedestalOffset = 0;
145  double sumpedestal2 = 0;
146  double pedestalsigma = 0 ;
147 
148  if(pedSamples > nsamples) return 0.;
149 
150  for(int i = 0; i < pedSamples; i++) {
151  pedestalOffset += samples[i];
152  }
153  pedestalOffset /= pedSamples;
154 
155  for(int i = 0; i < pedSamples; i++) {
156  sumpedestal2 += (pedestalOffset-samples[i])*(pedestalOffset-samples[i]);
157  }
158  pedestalsigma= sqrt(sumpedestal2/pedSamples);
159 
160  // printf("Pedestal = %f\n", pedestalOffset);
161  // Pedestal found, let's look for a pulse now
162 
163  // (Serdar) here i calculated the sigma for pedestal calculation, then i will start
164  // searching the pulse if sample is bigger the 4 pedestal sigma,
165 
166  const int kThreshold = 4*pedestalsigma;
167 
168  for(int i = 0; i < nsamples; i++) {
169  double bin_content = -1.*((double)samples[i] - pedestalOffset);
170 
171  double next_bin_content = 0.;
172  if(i<nsamples-1) next_bin_content = -1.*((double)samples[i+1] - pedestalOffset);
173 
174  if(bin_content >= kThreshold || next_bin_content >= kThreshold){
175  sig_length_counter++;
176  sig_over_thr++;
177 
178  if (sig_length_counter == 1){
179  sig_first_index = i;
180  // inspect left shoulder of this pulse
181  int back;
182  for(back=i-1; back>=0; back--){
183  double cont = -1.*((double)samples[back] - pedestalOffset);
184 
185  // (Serdar) here i made 2 changes, first, instead of 1/4 of the kThreshold
186  // i have 3/4, which equals 3 sigma at the left shoulder
187 
188  if(cont > 3*kThreshold/4 && (i-back)<4){
189  // accept it still as part of the left shoulder
190  sig_length_counter++;
191  sig_first_index = back;
192  }
193  else break;
194  }
195  }
196  }
197  else{
198  if (((bin_content < kThreshold) || (i == nsamples - 1)) &&
199  (sig_over_thr >= kLengthThreshold)){
200  // It's the end of the pulse, so let's include part of the right
201  // shoulder
202  int forw; // index for samples right of momentary position
203  for(forw=i+1;forw<nsamples; forw++){
204  double cont = -1.*((double)samples[forw] - pedestalOffset);
205  if(cont > 3*kThreshold/4 && (forw-i)<4){
206  // accept it still as part of the left shoulder
207  sig_length_counter++;
208  }
209  else break; // probably pedestal so let's stop
210  i = forw;
211  }
212 
213  sig_integral = 0.;
214  sig_max_height = 0.;
215 
216  for(int i = sig_first_index; i < sig_first_index+sig_length_counter; i++){
217  double bin_content = -1.*((double)samples[i] - pedestalOffset);
218  sig_integral += bin_content;
219  if (bin_content > sig_max_height){
220  sig_max_height = bin_content;
221  }
222  }
223 
224  // Let's only deal with one pulse at this time!!!
225  break;
226  }
227  }
228  }
229 
230  // printf("Pulse accepted from sample %d to %d with energy %f\n", sig_first_index,
231  // sig_first_index+sig_length_counter, sig_integral);
232  hPulseIF->Fill(sig_first_index);
233  hPulseIF->Fill(sig_first_index+sig_length_counter);
234  hPulseAvsEnergy->Fill(sig_integral, sig_max_height);
235  hPulseIvsEnergy->Fill(sig_integral, sig_first_index);
236  hPulseFvsEnergy->Fill(sig_integral, sig_first_index+sig_length_counter);
237  return sig_integral;
238 }
bool get_input_event ( FILE *  fp,
char *  pevent,
int  event_number 
)

Definition at line 27 of file res_analysis_new.cxx.

References SUCCESS.

28 {
29  int event_size, size_read;
30  EVENT_HEADER *header;
31 
32  size_read = fread(pevent, 1, sizeof(EVENT_HEADER), fp);
33  if (size_read != sizeof(EVENT_HEADER))
34  return !SUCCESS;
35 
36  header = (EVENT_HEADER *) pevent;
37 
38  if (event_number == 0 && header->trigger_mask != MIDAS_MAGIC) {
39  fprintf(stderr, "Input is not a valid MIDAS file\n");
40  exit(1);
41  }
42 
43  event_size = header->data_size;
44 
45  if ((unsigned int) event_size >= MAX_EVENT_SIZE - sizeof(EVENT_HEADER)) {
46  fprintf(stderr, "Invalid event size %d\n", event_size);
47  exit(1);
48  }
49 
50  size_read = fread(pevent + sizeof(EVENT_HEADER), 1, event_size, fp);
51  if (size_read != event_size)
52  return !SUCCESS;
53 
54  return SUCCESS;
55 }
int process_event ( void *  pevent,
int  addr,
int  fadc 
)
void process_file ( char *  input_filename,
int  addr,
int  fadc 
)
int processIsland ( int  t0,
int  nsamples,
int *  samples,
int  channel 
)

Definition at line 240 of file res_analysis_new.cxx.

References findPulse(), hChannelNIsland, hChannelNSample, hMaxSample, hMinSample, hPed0, hPulseEnergy, hSamples, i, and nsamples.

241 {
242  hChannelNIsland->Fill(channel);
243 
244  if(nsamples < 40) return 0;
245 
246  int minI = -1;
247  int maxI = -1;
248  int minSample = 4097;;
249  int maxSample = -1;
250 
251  double energy = findPulse(nsamples, samples);
252 
253  for(int i = 0; i < nsamples; i++) {
254  hSamples->Fill(channel, samples[i]);
255  hChannelNSample->Fill(channel);
256  if(samples[i] > maxSample) {
257  maxI = i;
258  maxSample = samples[i];
259  }
260  if(samples[i] < minSample) {
261  minI = i;
262  minSample = samples[i];
263  }
264  if(i<10){
265  hPed0->Fill(channel, samples[i]);
266  }
267  }
268 
269  hMinSample->Fill(channel, minSample);
270  hMaxSample->Fill(channel, maxSample);
271  hPulseEnergy->Fill(channel, energy);
272 
273  return 0;
274 }

Variable Documentation

TCanvas* c = 0

Definition at line 22 of file res_analysis_new.cxx.

TH1* hChannelNIsland

Definition at line 59 of file res_analysis_new.cxx.

TH1* hChannelNSample

Definition at line 58 of file res_analysis_new.cxx.

TH2* hMaxSample

Definition at line 61 of file res_analysis_new.cxx.

TH2* hMinSample

Definition at line 60 of file res_analysis_new.cxx.

TH2* hPed0

Definition at line 63 of file res_analysis_new.cxx.

TH2* hPulseAvsEnergy

Definition at line 67 of file res_analysis_new.cxx.

Referenced by findPulse().

TH2* hPulseEnergy

Definition at line 62 of file res_analysis_new.cxx.

TH2* hPulseFvsEnergy

Definition at line 66 of file res_analysis_new.cxx.

Referenced by findPulse().

TH1* hPulseIF

Definition at line 64 of file res_analysis_new.cxx.

Referenced by findPulse().

TH2* hPulseIvsEnergy

Definition at line 65 of file res_analysis_new.cxx.

Referenced by findPulse().

TH2* hSamples

Definition at line 57 of file res_analysis_new.cxx.