AlcapDAQ  1
MCommonOnlineDisplayPlots.cpp
Go to the documentation of this file.
1 /********************************************************************\
2 
3 Name: MCommonOnlineDisplayPlots
4 Created by: Andrew Edmonds
5 
6 Contents: One module that fills out histograms for the pulse heights, pulse shapes and the raw counts for all digitizer channels. These are all in one module to be more efficient in terms of minimising the number of times we loop through the channels.
7 
8 \********************************************************************/
9 
10 /* Standard includes */
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string>
14 #include <map>
15 #include <utility>
16 #include <sstream>
17 #include <cmath>
18 
19 /* MIDAS includes */
20 #include "midas.h"
21 
22 /* ROOT includes */
23 #include <TH1.h>
24 #include <TH2.h>
25 
26 /* AlCap includes */
27 #include "TGlobalData.h"
28 #include "TSetupData.h"
29 #include "TPulseIsland.h"
30 
31 using std::string;
32 using std::map;
33 using std::vector;
34 using std::pair;
35 
36 /*-- Module declaration --------------------------------------------*/
39 INT MCommonOnlineDisplayPlots(EVENT_HEADER*, void*);
40 
41 extern HNDLE hDB;
42 extern TGlobalData* gData;
43 extern TSetupData* gSetup;
44 
45 map <std::string, TH1I*> height_histograms_map;
46 map <std::string, TH1I*> time_histograms_map;
47 map <std::string, TH2D*> shape_histograms_map;
48 map <std::string, TH1I*> latest_pulse_histograms_map;
49 static TH1I* hPulseRawCount;
50 
52 {
53  "MCommonOnlineDisplayPlots", /* module name */
54  "Andrew Edmonds", /* author */
55  MCommonOnlineDisplayPlots, /* event routine */
56  MCommonOnlineDisplayPlots_bor, /* BOR routine */
57  NULL, /* EOR routine */
58  MCommonOnlineDisplayPlots_init, /* init routine */
59  NULL, /* exit routine */
60  NULL, /* parameter structure */
61  0, /* structure size */
62  NULL, /* initial parameters */
63 };
64 
68 {
69  // The following histograms are created for each channel:
70  // hPulseHeights: ADC value (x-axis) vs number of pulses (y-axis)
71  // hPulseTimes: time stamp (x-axis) vs number of pulses (y-axis)
72  // hPulseRawCount: number of pulses (y-axis) - channels on x-axis?
73  // hPulseShapes: sample number (x-axis) vs ADC value (y-axis) vs pulse (z-axis)
74 
75  std::map<std::string, std::string> bank_to_detector_map = gSetup->fBankToDetectorMap;
76  for(std::map<std::string, std::string>::iterator mapIter = bank_to_detector_map.begin();
77  mapIter != bank_to_detector_map.end(); mapIter++) {
78 
79  std::string bankname = mapIter->first;
80  std::string detname = gSetup->GetDetectorName(bankname);
81 
82  int n_digitizer_bits = 0;
83  if (TSetupData::IsFADC(bankname))
84  n_digitizer_bits = 12;
85  else if (TSetupData::IsHoustonCAEN(bankname))
86  n_digitizer_bits = 14; //?
87  else if (TSetupData::IsBostonCAEN(bankname))
88  n_digitizer_bits = 12;
89 
90  long max_adc_value = std::pow(2, n_digitizer_bits);
91 
92  // hPulseHeights
93  std::string histname = "h" + bankname + "_Heights";
94  std::string histtitle = "Plot of the pulse heights in the " + detname + " channels";
95  TH1I* hPulseHeights = new TH1I(histname.c_str(), histtitle.c_str(), max_adc_value,0,max_adc_value);
96  hPulseHeights->GetXaxis()->SetTitle("Pulse Height [ADC value]");
97  hPulseHeights->GetYaxis()->SetTitle("Number of Pulses");
98  height_histograms_map[bankname] = hPulseHeights;
99 
100  // hPulseTimes
101  histname = "h" + bankname + "_Times";
102  histtitle = "Plot of the pulse times in the " + detname + " channels";
103  TH1I* hPulseTimes = new TH1I(histname.c_str(), histtitle.c_str(), 2000, 0, 2e8);
104  hPulseTimes->GetXaxis()->SetTitle("Time");
105  hPulseTimes->GetYaxis()->SetTitle("Number of Pulses");
106  time_histograms_map[bankname] = hPulseTimes;
107 
108  // hPulseShapes
109  histname = "h" + bankname + "_Shapes";
110  histtitle = "Plot of the pulse shapes in the " + detname + " channels";
111  TH2D* hPulseShapes = new TH2D(histname.c_str(), histtitle.c_str(), 400,-0.5,399.5,max_adc_value+1,0,max_adc_value+1);
112  hPulseShapes->GetXaxis()->SetTitle("Time Stamp");
113  hPulseShapes->GetYaxis()->SetTitle("ADC Value");
114  shape_histograms_map[bankname] = hPulseShapes;
115 
116  //hLatestPulse
117  histname = "h" + bankname + "_LatestPulse";
118  histtitle = "Plot of the latest pulse in the " + detname + " channels";
119  TH1I* hLatestPulse = new TH1I(histname.c_str(), histtitle.c_str(), 64,-0.5,63.5);
120  hLatestPulse->GetXaxis()->SetTitle("Time Stamp");
121  hLatestPulse->GetYaxis()->SetTitle("ADC Value");
122  latest_pulse_histograms_map[bankname] = hLatestPulse;
123 
124  }
125 
126  // hPulseRawCount
127  std::string histname = "hPulseRawCount";
128  std::string histtitle = "Plot of the raw counts in each channels";
129  hPulseRawCount = new TH1I(histname.c_str(), histtitle.c_str(), 1,0,1);
130  hPulseRawCount->GetXaxis()->SetTitle("Channel");
131  hPulseRawCount->GetYaxis()->SetTitle("Number of Pulses");
132  hPulseRawCount->SetBit(TH1::kCanRebin);
133 
134  return SUCCESS;
135 }
136 
137 // Resets the histograms at the beginning of each run so that the online display updates
139 
140  std::map<std::string, std::string> bank_to_detector_map = gSetup->fBankToDetectorMap;
141  for(std::map<std::string, std::string>::iterator mapIter = bank_to_detector_map.begin();
142  mapIter != bank_to_detector_map.end(); mapIter++) {
143 
144  std::string bankname = mapIter->first;
145  height_histograms_map[bankname]->Reset();
146  time_histograms_map[bankname]->Reset();
147  shape_histograms_map[bankname]->Reset();
148  latest_pulse_histograms_map[bankname]->Reset();
149 
150  }
151 
152  hPulseRawCount->Reset();
153 }
154 
158 INT MCommonOnlineDisplayPlots(EVENT_HEADER *pheader, void *pevent)
159 {
160  // Get the event number
161  int midas_event_number = pheader->serial_number;
162 
163  // Some typedefs
164  typedef map<string, vector<TPulseIsland*> > TStringPulseIslandMap;
165  typedef pair<string, vector<TPulseIsland*> > TStringPulseIslandPair;
166  typedef map<string, vector<TPulseIsland*> >::iterator map_iterator;
167 
168  // Fetch a reference to the gData structure that stores a map
169  // of (bank_name, vector<TPulseIsland*>) pairs
170  TStringPulseIslandMap& pulse_islands_map =
172 
173  // Loop over the map and get each bankname, vector pair
174  for (map_iterator theMapIter = pulse_islands_map.begin(); theMapIter != pulse_islands_map.end(); theMapIter++)
175  {
176  std::string bankname = theMapIter->first;
177  std::string detname = gSetup->GetDetectorName(bankname);
178  std::vector<TPulseIsland*> thePulses = theMapIter->second;
179 
180  // Loop over the TPulseIslands and plot the histogram
181  for (std::vector<TPulseIsland*>::iterator pulseIter = thePulses.begin(); pulseIter != thePulses.end(); pulseIter++) {
182 
183  // Make sure the histograms exist and then fill them
184  // Also check that this pulse didn't underflow (i.e. has a sample value at any point of 4096)
185  bool underflow = false;
186  if (shape_histograms_map.find(bankname) != shape_histograms_map.end()) {
187  TH2* shape_histogram = shape_histograms_map[bankname];
188  TH1* latest_pulse_histogram = latest_pulse_histograms_map[bankname];
189 
190  latest_pulse_histogram->Reset();
191 
192  std::vector<int> theSamples = (*pulseIter)->GetSamples();
193  for (std::vector<int>::iterator sampleIter = theSamples.begin(); sampleIter != theSamples.end(); sampleIter++) {
194  int sample_number = sampleIter - theSamples.begin();
195  int sample_value = *sampleIter;
196 
197  if (sample_value == 4096) {
198  underflow = true;
199  break;
200  }
201  shape_histogram->Fill(sample_number, sample_value);
202  latest_pulse_histogram->SetBinContent(sample_number, sample_value);
203  }
204  }
205 
206  if (underflow == false) {
207  if (height_histograms_map.find(bankname) != height_histograms_map.end())
208  height_histograms_map[bankname]->Fill((*pulseIter)->GetPulseHeight());
209 
210  if (time_histograms_map.find(bankname) != time_histograms_map.end())
211  time_histograms_map[bankname]->Fill((*pulseIter)->GetPulseTime());
212  }
213  }
214 
215  hPulseRawCount->Fill(bankname.c_str(), thePulses.size());
216  }
217  return SUCCESS;
218 }