00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <stdio.h>
00030 #include <stdlib.h>
00031 #include <string>
00032 #include <map>
00033 #include <utility>
00034 #include <sstream>
00035 #include <cmath>
00036
00037
00038 #include "midas.h"
00039
00040
00041 #include <TH1.h>
00042 #include <TDirectory.h>
00043
00044
00045 #include "TGlobalData.h"
00046 #include "TSetupData.h"
00047 #include "TPulseIsland.h"
00048
00049 using std::string;
00050 using std::map;
00051 using std::vector;
00052 using std::pair;
00053
00054
00055 INT MDQ_Thresholds_init(void);
00056 INT MDQ_Thresholds(EVENT_HEADER*, void*);
00057 INT MDQ_Thresholds_eor(INT);
00058
00059 extern HNDLE hDB;
00060 extern TGlobalData* gData;
00061 extern TSetupData* gSetup;
00062
00063 map <std::string, TH1F*> DQ_Thresholds_histograms_map;
00064
00065 ANA_MODULE MDQ_Thresholds_module =
00066 {
00067 "MDQ_Thresholds",
00068 "Andrew Edmonds",
00069 MDQ_Thresholds,
00070 NULL,
00071 MDQ_Thresholds_eor,
00072 MDQ_Thresholds_init,
00073 NULL,
00074 NULL,
00075 0,
00076 NULL,
00077 };
00078
00081 INT MDQ_Thresholds_init()
00082 {
00083
00084 if (!gDirectory->Cd("DataQuality_LowLevel")) {
00085
00086 std::string dir_name("DataQuality_LowLevel/");
00087 gDirectory->mkdir(dir_name.c_str());
00088 gDirectory->Cd(dir_name.c_str());
00089 }
00090
00091
00092 std::map<std::string, std::string> bank_to_detector_map = gSetup->fBankToDetectorMap;
00093 for(std::map<std::string, std::string>::iterator mapIter = bank_to_detector_map.begin();
00094 mapIter != bank_to_detector_map.end(); mapIter++) {
00095
00096 std::string bankname = mapIter->first;
00097 std::string detname = gSetup->GetDetectorName(bankname);
00098
00099
00100 std::string histname = "hDQ_Thresholds_" + detname + "_" + bankname;
00101 std::string histtitle = "ODB Thresholds in " + bankname;
00102 TH1F* hDQ_Histogram = new TH1F(histname.c_str(), histtitle.c_str(),
00103 2,0,2);
00104 hDQ_Histogram->GetXaxis()->SetTitle("");
00105 hDQ_Histogram->GetYaxis()->SetTitle("Threshold");
00106 DQ_Thresholds_histograms_map[bankname] = hDQ_Histogram;
00107 }
00108
00109 gDirectory->Cd("/MidasHists/");
00110 return SUCCESS;
00111 }
00112
00115 INT MDQ_Thresholds_eor(INT run_number) {
00116
00117
00118 HNDLE hDB, hKey;
00119 char keyName[200];
00120
00121 if(cm_get_experiment_database(&hDB, NULL) != CM_SUCCESS){
00122 printf("Warning: Could not connect to ODB database!\n");
00123 return false;
00124 }
00125
00126
00127 std::map<std::string, std::string> bank_to_detector_map = gSetup->fBankToDetectorMap;
00128 for(std::map<std::string, std::string>::iterator mapIter = bank_to_detector_map.begin();
00129 mapIter != bank_to_detector_map.end(); mapIter++) {
00130
00131 std::string bankname = mapIter->first;
00132
00133 if (TSetupData::Instance()->IsFADC(bankname)) {
00134
00135
00136
00137 int iChn = (int)(bankname[1] - 97);
00138 std::string iAddr = bankname.substr(2, 2);
00139
00140
00141 sprintf(keyName, "/Equipment/Crate 9/Settings/NFADC %s/Channel %d/Lower threshold", iAddr.c_str(), iChn);
00142 if(db_find_key(hDB,0,keyName, &hKey) != SUCCESS){
00143 printf("Warning: Could not find key %s\n", keyName);
00144 return false;
00145 }
00146 KEY lower_threshold_key;
00147 if(db_get_key(hDB, hKey, &lower_threshold_key) != DB_SUCCESS){
00148 printf("Warning: Could not find key %s\n", keyName);
00149 return false;
00150 }
00151 INT LowerThresholds[lower_threshold_key.num_values];
00152 int size = sizeof(LowerThresholds);
00153 if(db_get_value(hDB, 0, keyName, LowerThresholds, &size, TID_INT, 0) != DB_SUCCESS){
00154 printf("Warning: Could not retrieve values for key %s\n", keyName);
00155 return false;
00156 }
00157
00158
00159
00160 sprintf(keyName, "/Equipment/Crate 9/Settings/NFADC %s/Channel %d/Upper threshold", iAddr.c_str(), iChn);
00161 if(db_find_key(hDB,0,keyName, &hKey) != SUCCESS){
00162 printf("Warning: Could not find key %s\n", keyName);
00163 return false;
00164 }
00165 KEY upper_threshold_key;
00166 if(db_get_key(hDB, hKey, &upper_threshold_key) != DB_SUCCESS){
00167 printf("Warning: Could not find key %s\n", keyName);
00168 return false;
00169 }
00170 INT UpperThresholds[upper_threshold_key.num_values];
00171 size = sizeof(UpperThresholds);
00172 if(db_get_value(hDB, 0, keyName, UpperThresholds, &size, TID_INT, 0) != DB_SUCCESS){
00173 printf("Warning: Could not retrieve values for key %s\n", keyName);
00174 return false;
00175 }
00176
00177
00178 DQ_Thresholds_histograms_map[bankname]->Fill("lower threshold", LowerThresholds[0]);
00179 DQ_Thresholds_histograms_map[bankname]->Fill("upper threshold", UpperThresholds[0]);
00180 }
00181 else if (TSetupData::Instance()->IsHoustonCAEN(bankname)) {
00182
00183
00184
00185 int iChn = (int)(bankname[1] - 97);
00186
00187
00188 sprintf(keyName, "/Equipment/Crate 4/Settings/CAEN0/Ch%d/trigger threshhold", iChn);
00189 if(db_find_key(hDB,0,keyName, &hKey) != SUCCESS){
00190 printf("Warning: Could not find key %s\n", keyName);
00191 return false;
00192 }
00193 KEY threshold_key;
00194 if(db_get_key(hDB, hKey, &threshold_key) != DB_SUCCESS){
00195 printf("Warning: Could not find key %s\n", keyName);
00196 return false;
00197 }
00198 DWORD Thresholds[threshold_key.num_values];
00199 int size = sizeof(Thresholds);
00200 if(db_get_value(hDB, 0, keyName, Thresholds, &size, TID_DWORD, 0) != DB_SUCCESS){
00201 printf("Warning: Could not retrieve values for key %s\n", keyName);
00202 return false;
00203 }
00204 DQ_Thresholds_histograms_map[bankname]->Fill("trigger threshold", Thresholds[0]);
00205 }
00206 else if (TSetupData::Instance()->IsBostonCAEN(bankname)) {
00207
00208
00209
00210 int iChn = (int)(bankname[1] - 97);
00211
00212
00213 sprintf(keyName, "/Equipment/Crate 5/Settings/CAEN/Ch0%d/self_trigger_threshhold", iChn);
00214 if(db_find_key(hDB,0,keyName, &hKey) != SUCCESS){
00215 printf("Warning: Could not find key %s\n", keyName);
00216 return false;
00217 }
00218 KEY threshold_key;
00219 if(db_get_key(hDB, hKey, &threshold_key) != DB_SUCCESS){
00220 printf("Warning: Could not find key %s\n", keyName);
00221 return false;
00222 }
00223 float Thresholds[threshold_key.num_values];
00224 int size = sizeof(Thresholds);
00225 if(db_get_value(hDB, 0, keyName, Thresholds, &size, TID_FLOAT, 0) != DB_SUCCESS){
00226 printf("Warning: Could not retrieve values for key %s\n", keyName);
00227 return false;
00228 }
00229 DQ_Thresholds_histograms_map[bankname]->Fill("self_trigger_threshold", Thresholds[0]);
00230 }
00231 }
00232
00233 return SUCCESS;
00234 }
00235
00238 INT MDQ_Thresholds(EVENT_HEADER *pheader, void *pevent)
00239 {
00240
00241 int midas_event_number = pheader->serial_number;
00242
00243
00244 typedef map<string, vector<TPulseIsland*> > TStringPulseIslandMap;
00245 typedef pair<string, vector<TPulseIsland*> > TStringPulseIslandPair;
00246 typedef map<string, vector<TPulseIsland*> >::iterator map_iterator;
00247
00248
00249
00250 return SUCCESS;
00251 }
00252