00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00017
00023
00024
00025 #include <stdio.h>
00026 #include <stdlib.h>
00027 #include <string>
00028 #include <map>
00029 #include <utility>
00030 #include <sstream>
00031 #include <cmath>
00032
00033
00034 #include "midas.h"
00035
00036
00037 #include <TH1.h>
00038 #include <TDirectory.h>
00039
00040
00041 #include "TGlobalData.h"
00042 #include "TSetupData.h"
00043 #include "TPulseIsland.h"
00044
00045 using std::string;
00046 using std::map;
00047 using std::vector;
00048 using std::pair;
00049
00050
00051 INT MDQ_IslandRate_init(void);
00052 INT MDQ_IslandRate(EVENT_HEADER*, void*);
00053 INT MDQ_IslandRate_eor(INT);
00054
00055 extern HNDLE hDB;
00056 extern TGlobalData* gData;
00057 extern TSetupData* gSetup;
00058
00059 TH1F* hDQ_IslandRate;
00060 TH1F* hDQ_IslandRate_normalised;
00061
00062 extern TH1F* hDQ_TDCCheck_muSc;
00063
00064 ANA_MODULE MDQ_IslandRate_module =
00065 {
00066 "MDQ_IslandRate",
00067 "Andrew Edmonds",
00068 MDQ_IslandRate,
00069 NULL,
00070 MDQ_IslandRate_eor,
00071 MDQ_IslandRate_init,
00072 NULL,
00073 NULL,
00074 0,
00075 NULL,
00076 };
00077
00080 INT MDQ_IslandRate_init()
00081 {
00082
00083 if (!gDirectory->Cd("DataQuality_LowLevel")) {
00084
00085 std::string dir_name("DataQuality_LowLevel/");
00086 gDirectory->mkdir(dir_name.c_str());
00087 gDirectory->Cd(dir_name.c_str());
00088 }
00089
00090
00091 std::string histname = "hDQ_IslandRate";
00092 std::string histtitle = "The total island rate in each channel";
00093 hDQ_IslandRate = new TH1F(histname.c_str(), histtitle.c_str(), 1,0,1);
00094 hDQ_IslandRate->GetXaxis()->SetTitle("Detector (Bank)");
00095 hDQ_IslandRate->GetYaxis()->SetTitle("Island Rate [TPI per second]");
00096 hDQ_IslandRate->SetBit(TH1::kCanRebin);
00097
00098
00099 histname += "_normalised";
00100 histtitle += " (normalised)";
00101 hDQ_IslandRate_normalised = new TH1F(histname.c_str(), histtitle.c_str(), 1,0,1);
00102 hDQ_IslandRate_normalised->GetXaxis()->SetTitle("Detector (Bank)");
00103 std::string yaxislabel = hDQ_IslandRate->GetYaxis()->GetTitle();
00104 yaxislabel += " per TDC muSc Hit";
00105 hDQ_IslandRate_normalised->GetYaxis()->SetTitle(yaxislabel.c_str());
00106
00107
00108 gDirectory->Cd("/MidasHists/");
00109 return SUCCESS;
00110 }
00111
00114 INT MDQ_IslandRate_eor(INT run_number) {
00115
00116
00117 HNDLE hDB, hKey;
00118 char keyName[200];
00119
00120 if(cm_get_experiment_database(&hDB, NULL) != CM_SUCCESS){
00121 printf("Warning: Could not connect to ODB database!\n");
00122 return false;
00123 }
00124
00125 sprintf(keyName, "/Runinfo/Start time binary");
00126 if(db_find_key(hDB,0,keyName, &hKey) != SUCCESS){
00127 printf("Warning: Could not find key %s\n", keyName);
00128 return false;
00129 }
00130 KEY start_time_key;
00131 if(db_get_key(hDB, hKey, &start_time_key) != DB_SUCCESS){
00132 printf("Warning: Could not find key %s\n", keyName);
00133 return false;
00134 }
00135 DWORD StartTimes[start_time_key.num_values];
00136 int size = sizeof(StartTimes);
00137 if(db_get_value(hDB, 0, keyName, StartTimes, &size, TID_DWORD, 0) != DB_SUCCESS){
00138 printf("Warning: Could not retrieve values for key %s\n", keyName);
00139 return false;
00140 }
00141
00142 sprintf(keyName, "/Runinfo/Stop time binary");
00143 if(db_find_key(hDB,0,keyName, &hKey) != SUCCESS){
00144 printf("Warning: Could not find key %s\n", keyName);
00145 return false;
00146 }
00147 KEY stop_time_key;
00148 if(db_get_key(hDB, hKey, &stop_time_key) != DB_SUCCESS){
00149 printf("Warning: Could not find key %s\n", keyName);
00150 return false;
00151 }
00152 DWORD StopTimes[stop_time_key.num_values];
00153 size = sizeof(StopTimes);
00154 if(db_get_value(hDB, 0, keyName, StopTimes, &size, TID_DWORD, 0) != DB_SUCCESS){
00155 printf("Warning: Could not retrieve values for key %s\n", keyName);
00156 return false;
00157 }
00158
00159 int duration = StopTimes[0] - StartTimes[0];
00160
00161 hDQ_IslandRate->Scale(1.0/duration);
00162 hDQ_IslandRate_normalised->Scale(1.0/duration);
00163
00164 hDQ_IslandRate_normalised->Scale(1.0/hDQ_TDCCheck_muSc->GetEntries());
00165
00166 return SUCCESS;
00167 }
00168
00171 INT MDQ_IslandRate(EVENT_HEADER *pheader, void *pevent)
00172 {
00173
00174 int midas_event_number = pheader->serial_number;
00175
00176
00177 typedef map<string, vector<TPulseIsland*> > TStringPulseIslandMap;
00178 typedef pair<string, vector<TPulseIsland*> > TStringPulseIslandPair;
00179 typedef map<string, vector<TPulseIsland*> >::iterator map_iterator;
00180
00181
00182
00183 TStringPulseIslandMap& pulse_islands_map =
00184 gData->fPulseIslandToChannelMap;
00185
00186
00187 for (map_iterator mapIter = pulse_islands_map.begin(); mapIter != pulse_islands_map.end(); ++mapIter)
00188 {
00189 std::string bankname = mapIter->first;
00190 std::vector<TPulseIsland*> thePulses = mapIter->second;
00191 std::string detname = gSetup->GetDetectorName(bankname);
00192
00193 std::string binname = detname + "(" + bankname + ")";
00194
00195 hDQ_IslandRate->Fill(binname.c_str(), thePulses.size());
00196 hDQ_IslandRate_normalised->Fill(binname.c_str(), thePulses.size());
00197 }
00198 return SUCCESS;
00199 }
00200