00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <stdio.h>
00012 #include <stdlib.h>
00013 #include <string>
00014 #include <map>
00015 #include <utility>
00016 #include <sstream>
00017
00018
00019 #include "midas.h"
00020
00021
00022 #include <TH2.h>
00023
00024
00025 #include "TOctalFADCIsland.h"
00026 #include "TOctalFADCBankReader.h"
00027 #include "TGlobalData.h"
00028 #include "TSetupData.h"
00029 #include "TPulseIsland.h"
00030
00031 using std::string;
00032 using std::map;
00033 using std::vector;
00034 using std::pair;
00035
00036
00037 INT MPulseLengths_init(void);
00038 INT MPulseLengths(EVENT_HEADER*, void*);
00039 double GetClockTickForChannel(string bank_name);
00040
00041 extern HNDLE hDB;
00042 extern TGlobalData* gData;
00043 extern TSetupData* gSetup;
00044
00045 static vector<TOctalFADCBankReader*> fadc_bank_readers;
00046 static TH2I* average_length_histogram;
00047 map <std::string, TH1I*> length_histograms_map;
00048
00049 ANA_MODULE MPulseLengths_module =
00050 {
00051 "MPulseLengths",
00052 "Andrew Edmonds",
00053 MPulseLengths,
00054 NULL,
00055 NULL,
00056 MPulseLengths_init,
00057 NULL,
00058 NULL,
00059 0,
00060 NULL,
00061 };
00062
00065 INT MPulseLengths_init()
00066 {
00067
00068
00069
00070 std::map<std::string, std::string> bank_to_detector_map = gSetup->fBankToDetectorMap;
00071 for(std::map<std::string, std::string>::iterator mapIter = bank_to_detector_map.begin();
00072 mapIter != bank_to_detector_map.end(); mapIter++) {
00073
00074 std::string bankname = mapIter->first;
00075 std::string detname = gSetup->GetDetectorName(bankname);
00076 std::string histname = "h" + detname + "_Lengths";
00077 std::string histtitle = "Plot of the pulse lengths for the " + detname + " detector";
00078 TH1I* hDetLengths = new TH1I(histname.c_str(), histtitle.c_str(), 100,0,100);
00079 hDetLengths->GetXaxis()->SetTitle("Pulse Lengths [N Samples]");
00080 hDetLengths->GetYaxis()->SetTitle("Arbitrary Unit");
00081 hDetLengths->SetBit(TH1::kCanRebin);
00082
00083 length_histograms_map[bankname] = hDetLengths;
00084 }
00085
00086 std::string histname = "hAvgPulseLengthsPerChannel";
00087 std::string histtitle = "Plot of the average pulse lengths per event for the each channel";
00088 average_length_histogram = new TH2I(histname.c_str(), histtitle.c_str(), 1,0,1, 5000,0,5000);
00089 average_length_histogram->GetXaxis()->SetTitle("Bank Name");
00090 average_length_histogram->GetYaxis()->SetTitle("MIDAS Event Number");
00091 average_length_histogram->SetBit(TH1::kCanRebin);
00092
00093 return SUCCESS;
00094 }
00095
00099 INT MPulseLengths(EVENT_HEADER *pheader, void *pevent)
00100 {
00101
00102 int midas_event_number = pheader->serial_number;
00103
00104
00105 typedef map<string, vector<TPulseIsland*> > TStringPulseIslandMap;
00106 typedef pair<string, vector<TPulseIsland*> > TStringPulseIslandPair;
00107 typedef map<string, vector<TPulseIsland*> >::iterator map_iterator;
00108
00109
00110
00111 TStringPulseIslandMap& pulse_islands_map =
00112 gData->fPulseIslandToChannelMap;
00113
00114
00115 for (map_iterator theMapIter = pulse_islands_map.begin(); theMapIter != pulse_islands_map.end(); theMapIter++)
00116 {
00117 std::string bankname = theMapIter->first;
00118 std::vector<TPulseIsland*> thePulses = theMapIter->second;
00119
00120 if (thePulses.size() != 0) {
00121
00122 double total_length_of_pulses = 0;
00123 for (std::vector<TPulseIsland*>::iterator thePulseIter = thePulses.begin(); thePulseIter != thePulses.end(); thePulseIter++) {
00124 length_histograms_map[bankname]->Fill((*thePulseIter)->GetPulseLength());
00125 total_length_of_pulses += (*thePulseIter)->GetPulseLength();
00126 }
00127
00128 average_length_histogram->Fill(bankname.c_str(), midas_event_number, total_length_of_pulses / thePulses.size());
00129 }
00130 }
00131 return SUCCESS;
00132 }