00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00018
00023
00030
00031
00032 #include <stdio.h>
00033 #include <stdlib.h>
00034 #include <string>
00035 #include <map>
00036 #include <utility>
00037 #include <sstream>
00038 #include <cmath>
00039
00040
00041 #include "midas.h"
00042
00043
00044 #include <TH1.h>
00045 #include <TDirectory.h>
00046
00047
00048 #include "TGlobalData.h"
00049 #include "TSetupData.h"
00050 #include "TPulseIsland.h"
00051
00052 using std::string;
00053 using std::map;
00054 using std::vector;
00055 using std::pair;
00056
00057
00058 INT MDQ_muScTDiff_init(void);
00059 INT MDQ_muScTDiff(EVENT_HEADER*, void*);
00060 INT MDQ_muScTDiff_eor(INT);
00061
00062 extern HNDLE hDB;
00063 extern TGlobalData* gData;
00064 extern TSetupData* gSetup;
00065
00066 map <std::string, TH1F*> DQ_muScTDiff_histograms_map;
00067 map <std::string, TH1F*> DQ_muScTDiff_histograms_normalised_map;
00068 map <std::string, TH1F*> DQ_muScTDiff_histograms_with_time_shift_map;
00069 float axis_limit = 50000;
00070
00071 extern TH1F* hDQ_TDCCheck_muSc;
00072
00073 ANA_MODULE MDQ_muScTDiff_module =
00074 {
00075 "MDQ_muScTDiff",
00076 "Andrew Edmonds",
00077 MDQ_muScTDiff,
00078 NULL,
00079 MDQ_muScTDiff_eor,
00080 MDQ_muScTDiff_init,
00081 NULL,
00082 NULL,
00083 0,
00084 NULL,
00085 };
00086
00089 INT MDQ_muScTDiff_init()
00090 {
00091
00092 if (!gDirectory->Cd("DataQuality_LowLevel")) {
00093
00094 std::string dir_name("DataQuality_LowLevel/");
00095 gDirectory->mkdir(dir_name.c_str());
00096 gDirectory->Cd(dir_name.c_str());
00097 }
00098
00099
00100 std::map<std::string, std::string> bank_to_detector_map = gSetup->fBankToDetectorMap;
00101 for(std::map<std::string, std::string>::iterator mapIter = bank_to_detector_map.begin();
00102 mapIter != bank_to_detector_map.end(); mapIter++) {
00103
00104 std::string bankname = mapIter->first;
00105 std::string detname = gSetup->GetDetectorName(bankname);
00106
00107
00108 std::string histname = "hDQ_muScTDiff_" + detname + "_" + bankname;
00109 std::string histtitle = "Time differences between muSc and " + detname;
00110 TH1F* hDQ_Histogram = new TH1F(histname.c_str(), histtitle.c_str(), 20000, -axis_limit, axis_limit);
00111 std::string axislabel = "Time Difference (muSc - " + detname + ") [ns]";
00112 hDQ_Histogram->GetXaxis()->SetTitle(axislabel.c_str());
00113 hDQ_Histogram->GetYaxis()->SetTitle("Number of TPulseIslands");
00114 DQ_muScTDiff_histograms_map[bankname] = hDQ_Histogram;
00115
00116
00117 std::string normhistname = histname + "_normalised";
00118 std::string normhisttitle = histtitle + " (normalised)";
00119 TH1F* hDQ_Histogram_Normalised = new TH1F(normhistname.c_str(), normhisttitle.c_str(), 20000, -axis_limit, axis_limit);
00120 hDQ_Histogram_Normalised->GetXaxis()->SetTitle(axislabel.c_str());
00121 std::string yaxislabel = hDQ_Histogram->GetYaxis()->GetTitle();
00122 yaxislabel += " per TDC muSc Hit";
00123 hDQ_Histogram_Normalised->GetYaxis()->SetTitle(yaxislabel.c_str());
00124 DQ_muScTDiff_histograms_normalised_map[bankname] = hDQ_Histogram_Normalised;
00125
00126
00127 std::string timeshift_histname = histname + "_with-time-shift";
00128 std::string timeshift_histtitle = histtitle + " (with time shift)";
00129 TH1F* hDQ_Histogram_TimeShift = new TH1F(timeshift_histname.c_str(), timeshift_histtitle.c_str(), 20000, -axis_limit, axis_limit);
00130 hDQ_Histogram_TimeShift->GetXaxis()->SetTitle(axislabel.c_str());
00131 yaxislabel = hDQ_Histogram->GetYaxis()->GetTitle();
00132 hDQ_Histogram_Normalised->GetYaxis()->SetTitle(yaxislabel.c_str());
00133 DQ_muScTDiff_histograms_with_time_shift_map[bankname] = hDQ_Histogram_TimeShift;
00134 }
00135
00136 gDirectory->Cd("/MidasHists/");
00137 return SUCCESS;
00138 }
00139
00142 INT MDQ_muScTDiff_eor(INT run_number) {
00143
00144
00145 typedef map<string, vector<TPulseIsland*> > TStringPulseIslandMap;
00146 typedef pair<string, vector<TPulseIsland*> > TStringPulseIslandPair;
00147 typedef map<string, vector<TPulseIsland*> >::iterator map_iterator;
00148
00149
00150
00151 TStringPulseIslandMap& pulse_islands_map =
00152 gData->fPulseIslandToChannelMap;
00153
00154
00155 for (map_iterator mapIter = pulse_islands_map.begin(); mapIter != pulse_islands_map.end(); ++mapIter) {
00156
00157 std::string bankname = mapIter->first;
00158 std::string detname = gSetup->GetDetectorName(bankname);
00159
00160 if (DQ_muScTDiff_histograms_normalised_map.find(bankname) != DQ_muScTDiff_histograms_normalised_map.end()) {
00161
00162
00163 DQ_muScTDiff_histograms_normalised_map[bankname]->Scale(1./hDQ_TDCCheck_muSc->GetEntries());
00164 }
00165 }
00166
00167 return SUCCESS;
00168 }
00169
00172 INT MDQ_muScTDiff(EVENT_HEADER *pheader, void *pevent)
00173 {
00174
00175 int midas_event_number = pheader->serial_number;
00176
00177
00178 typedef map<string, vector<TPulseIsland*> > TStringPulseIslandMap;
00179 typedef pair<string, vector<TPulseIsland*> > TStringPulseIslandPair;
00180 typedef map<string, vector<TPulseIsland*> >::iterator map_iterator;
00181
00182
00183
00184 TStringPulseIslandMap& pulse_islands_map =
00185 gData->fPulseIslandToChannelMap;
00186
00187
00188 std::string muSc_bankname = gSetup->GetBankName("muSc");
00189 std::vector<TPulseIsland*> theMuScPulses = pulse_islands_map[muSc_bankname];
00190
00191
00192 for (map_iterator mapIter = pulse_islands_map.begin(); mapIter != pulse_islands_map.end(); ++mapIter)
00193 {
00194 std::string bankname = mapIter->first;
00195 std::string detname = gSetup->GetDetectorName(bankname);
00196
00197
00198 if (detname == "muSc")
00199 continue;
00200
00201 std::vector<TPulseIsland*> thePulses = mapIter->second;
00202
00203
00204 if (DQ_muScTDiff_histograms_map.find(bankname) != DQ_muScTDiff_histograms_map.end()) {
00205
00206
00207 TH1F* hDQ_muScTDiff = DQ_muScTDiff_histograms_map[bankname];
00208 TH1F* hDQ_muScTDiff_Norm = DQ_muScTDiff_histograms_normalised_map[bankname];
00209 TH1F* hDQ_muScTDiff_TimeShift = DQ_muScTDiff_histograms_with_time_shift_map[bankname];
00210 double time_shift = TSetupData::Instance()->GetTimeShift(bankname);
00211
00212
00213 for (std::vector<TPulseIsland*>::iterator muScPulseIter = theMuScPulses.begin(); muScPulseIter != theMuScPulses.end(); ++muScPulseIter) {
00214
00215
00216 for (std::vector<TPulseIsland*>::iterator pulseIter = thePulses.begin(); pulseIter != thePulses.end(); ++pulseIter) {
00217
00218
00219 double muSc_time = (*muScPulseIter)->GetPulseTime();
00220 double det_time = (*pulseIter)->GetPulseTime();
00221 double tdiff = muSc_time - det_time;
00222
00223
00224 if (std::fabs(tdiff) > 2*axis_limit)
00225 break;
00226
00227
00228 hDQ_muScTDiff->Fill(tdiff);
00229 hDQ_muScTDiff_Norm->Fill(tdiff);
00230 hDQ_muScTDiff_TimeShift->Fill(tdiff+time_shift);
00231 }
00232 }
00233 }
00234 }
00235 return SUCCESS;
00236 }
00237