AlcapDAQ  1
MPulseTimeSeparation.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 the pulse times from each channel
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 --------------------------------------------*/
38 INT MPulseTimeSeparation(EVENT_HEADER*, void*);
39 vector<string> GetAllBankNames();
40 double GetClockTickForChannel(string bank_name);
41 
42 extern HNDLE hDB;
43 extern TGlobalData* gData;
44 extern TSetupData* gSetup;
45 
46 static vector<TOctalFADCBankReader*> fadc_bank_readers;
47 static std::map<std::string, TH1*> time_separation_histogram_map;
48 static std::map<std::string, TH1*> time_separation_wrt_first_pulse_histogram_map;
49 
51 {
52  "MPulseTimeSeparation", /* module name */
53  "Joe Grange", /* author */
54  MPulseTimeSeparation, /* event routine */
55  NULL, /* BOR routine */
56  NULL, /* EOR routine */
57  MPulseTimeSeparation_init, /* init routine */
58  NULL, /* exit routine */
59  NULL, /* parameter structure */
60  0, /* structure size */
61  NULL, /* initial parameters */
62 };
63 
67 {
68  // This histogram has the pulse times on the X-axis and the number of pulses on the Y-axis
69  // One histogram is created for each detector
70 
71  std::map<std::string, std::string> bank_to_detector_map = gSetup->fBankToDetectorMap;
72  for(std::map<std::string, std::string>::iterator mapIter = bank_to_detector_map.begin();
73  mapIter != bank_to_detector_map.end(); mapIter++) {
74 
75  std::string detname = gSetup->GetDetectorName(mapIter->first);
76  std::string histname = "h" + detname + "_PulseSeparation";
77  std::string histtitle = "Plot of the time difference between consecutive pulses for the " + detname + " detector";
78  TH1I* hPulseTimeDiff = new TH1I(histname.c_str(),histtitle.c_str(),200,0,200);
79  hPulseTimeDiff->GetXaxis()->SetTitle("Time Difference Between Consecutive Pulses [ms]");
80  hPulseTimeDiff->GetYaxis()->SetTitle("Number of pulse pairs");
81  hPulseTimeDiff->SetBit(TH1::kCanRebin);
82 
83  time_separation_histogram_map[mapIter->first] = hPulseTimeDiff;
84 
85  histname = "h" + detname + "_PulseSeparationWRTFirstPulse";
86  histtitle = "Plot of the time difference wrt the first pulse for the " + detname + " detector";
87  hPulseTimeDiff = new TH1I(histname.c_str(), histtitle.c_str(),200,0,200);
88  hPulseTimeDiff->GetXaxis()->SetTitle("Time Difference Between wrt the First Pulse [ms]");
89  hPulseTimeDiff->GetYaxis()->SetTitle("Number of pulse pairs");
90  hPulseTimeDiff->SetBit(TH1::kCanRebin);
91 
92  time_separation_wrt_first_pulse_histogram_map[mapIter->first] = hPulseTimeDiff;
93  }
94 
95  return SUCCESS;
96 }
97 
101 INT MPulseTimeSeparation(EVENT_HEADER *pheader, void *pevent)
102 {
103  // Get the event number
104  int midas_event_number = pheader->serial_number;
105 
106  // Some typedefs
107  typedef map<string, vector<TPulseIsland*> > TStringPulseIslandMap;
108  typedef pair<string, vector<TPulseIsland*> > TStringPulseIslandPair;
109  typedef map<string, vector<TPulseIsland*> >::iterator map_iterator;
110 
111  // Fetch a reference to the gData structure that stores a map
112  // of (bank_name, vector<TPulseIsland*>) pairs
113  TStringPulseIslandMap& pulse_islands_map =
115 
116  // Loop over the map and get each bankname, vector pair
117  for (map_iterator theMapIter = pulse_islands_map.begin(); theMapIter != pulse_islands_map.end(); theMapIter++)
118  {
119  std::string bankname = theMapIter->first;
120  std::vector<TPulseIsland*> thePulses = theMapIter->second;
121 
122  // Loop over the TPulseIslands and plot the histogram
123  for (std::vector<TPulseIsland*>::iterator thePulseIter = thePulses.begin(); thePulseIter != thePulses.end(); thePulseIter++) {
124 
125  // if ((*thePulseIter)->GetPulseLength() == 4) {
126  if (thePulseIter!=thePulses.begin())
127  time_separation_histogram_map[bankname]->Fill( ((*thePulseIter)->GetTimeStamp() - (*(thePulseIter-1))->GetTimeStamp()) * (*thePulseIter)->GetClockTickInNs() * 1e-6); // ns->ms
128 
129  int initial_time_stamp = (*thePulses.begin())->GetTimeStamp();
130 
131  double pulse_frequency = 65; // Hz
132  double pulse_period = (1 / pulse_frequency) * 1e9; // ns
133 
134  if (initial_time_stamp * (*thePulseIter)->GetClockTickInNs() > pulse_period) {
135  initial_time_stamp += pulse_period / (*thePulseIter)->GetClockTickInNs();
136  }
137 
138  time_separation_wrt_first_pulse_histogram_map[bankname]->Fill( ((*thePulseIter)->GetTimeStamp() - initial_time_stamp) * (*thePulseIter)->GetClockTickInNs() * 1e-6); // ns->ms
139  // }
140  }
141  }
142  return SUCCESS;
143 }