AlcapDAQ  1
MShortPulseTimes.cpp
Go to the documentation of this file.
1 /********************************************************************\
2 
3 Name: MPulseTimeSeparation
4 Created by: Joe Grange
5 
6 Contents: A module to fill a histogram of any pulses with only 4 samples
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 
18 /* MIDAS includes */
19 #include "midas.h"
20 
21 /* ROOT includes */
22 #include <TH1.h>
23 
24 /* AlCap includes */
25 #include "TOctalFADCIsland.h"
26 #include "TOctalFADCBankReader.h"
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 --------------------------------------------*/
37 INT MShortPulseTimes_init(void);
38 INT MShortPulseTimes(EVENT_HEADER*, void*);
39 vector<string> GetAllBankNames();
40 double GetClockTickForChannel(string bank_name);
41 
42 string testname = "CaenCh0";
43 extern HNDLE hDB;
44 extern TGlobalData* gData;
45 extern TSetupData* gSetup;
46 
47 static vector<TOctalFADCBankReader*> fadc_bank_readers;
48 
49 static std::map<std::string, TH1*> time_short_pulse_histogram_map;
50 static std::map<std::string, TH1*> time_nshort_pulse_histogram_map;
51 
53 {
54  "MShortPulseTimes", /* module name */
55  "Joe Grange", /* author */
56  MShortPulseTimes, /* event routine */
57  NULL, /* BOR routine */
58  NULL, /* EOR routine */
59  MShortPulseTimes_init, /* init routine */
60  NULL, /* exit routine */
61  NULL, /* parameter structure */
62  0, /* structure size */
63  NULL, /* initial parameters */
64 };
65 
69 {
70  // This histogram has the pulse times on the X-axis and the number of pulses on the Y-axis
71  // One histogram is created for each detector
72  // This uses the TH1::kCanRebin mechanism to expand automatically to the
73  // number of FADC banks.
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 detname = gSetup->GetDetectorName(mapIter->first);
80  std::string histname = "h" + detname + "_ShortPulseTimes";
81  std::string histtitle = "Plot of the short pulse times for the " + detname + " detector";
82  TH1D* hShortPulseTime = new TH1D(histname.c_str(),histtitle.c_str(),240,0,120e6);
83  hShortPulseTime->GetXaxis()->SetTitle("Pulse time (ns)");
84  hShortPulseTime->GetXaxis()->CenterTitle(1);
85  hShortPulseTime->GetYaxis()->SetTitle("Number of 4-sample pulses");
86  hShortPulseTime->GetYaxis()->CenterTitle(1);
87  //hShortPulseTime->SetBit(TH1::kCanRebin);
88 
89  std::string histname2 = "h" + detname + "_NonShortPulseTimes";
90  std::string histtitle2 = "Plot of the non-short pulse times for the " + detname + " detector";
91  TH1D* hNonShortPulseTime = new TH1D(histname2.c_str(),histtitle2.c_str(),240,0,120e6);
92  hNonShortPulseTime->GetXaxis()->SetTitle("Pulse time (ns)");
93  hNonShortPulseTime->GetXaxis()->CenterTitle(1);
94  hNonShortPulseTime->GetYaxis()->SetTitle("Number of all other pulses");
95  hNonShortPulseTime->GetYaxis()->CenterTitle(1);
96  //hNonShortPulseTime->SetBit(TH1::kCanRebin);
97 
98  time_short_pulse_histogram_map[mapIter->first] = hShortPulseTime;
99  time_nshort_pulse_histogram_map[mapIter->first] = hNonShortPulseTime;
100 
101  }
102 
103  return SUCCESS;
104 }
105 
109 INT MShortPulseTimes(EVENT_HEADER *pheader, void *pevent)
110 {
111  // Get the event number
112  int midas_event_number = pheader->serial_number;
113 
114  // Some typedefs
115  typedef map<string, vector<TPulseIsland*> > TStringPulseIslandMap;
116  typedef pair<string, vector<TPulseIsland*> > TStringPulseIslandPair;
117  typedef map<string, vector<TPulseIsland*> >::iterator map_iterator;
118 
119  // Fetch a reference to the gData structure that stores a map
120  // of (bank_name, vector<TPulseIsland*>) pairs
121  TStringPulseIslandMap& pulse_islands_map =
123 
124  // Loop over the map and get each bankname, vector pair
125  for (map_iterator theMapIter = pulse_islands_map.begin(); theMapIter != pulse_islands_map.end(); theMapIter++)
126  {
127  std::string bankname = theMapIter->first;
128  std::vector<TPulseIsland*> thePulses = theMapIter->second;
129 
130  // Loop over the TPulseIslands and plot the histogram
131  for (std::vector<TPulseIsland*>::iterator thePulseIter = thePulses.begin(); thePulseIter != thePulses.end(); thePulseIter++) {
132  if (gSetup->GetDetectorName(theMapIter->first)=="CDG0" && ((*thePulseIter)->GetSamples().size()>0)) printf("\nfound caen\n");
133 
134  //samples = (*thePulseIter)->GetSamples();
135  if ((*thePulseIter)->GetSamples().size()==4) time_short_pulse_histogram_map[bankname]->Fill((*thePulseIter)->GetPulseTime());
136  else time_nshort_pulse_histogram_map[bankname]->Fill((*thePulseIter)->GetPulseTime());
137 
138  }
139 
140  }
141  return SUCCESS;
142 }