00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00019
00024
00030
00038
00039
00040 #include <stdio.h>
00041 #include <stdlib.h>
00042 #include <string>
00043 #include <map>
00044 #include <utility>
00045 #include <sstream>
00046 #include <cmath>
00047
00048
00049 #include "midas.h"
00050
00051
00052 #include <TH1.h>
00053 #include <TH2.h>
00054 #include <TDirectory.h>
00055
00056
00057 #include "TGlobalData.h"
00058 #include "TSetupData.h"
00059 #include "TPulseIsland.h"
00060
00061 using std::string;
00062 using std::map;
00063 using std::vector;
00064 using std::pair;
00065
00066
00067 INT MDQ_PulseShapes_init(void);
00068 INT MDQ_PulseShapes(EVENT_HEADER*, void*);
00069 INT MDQ_PulseShapes_eor(INT);
00070
00071 extern HNDLE hDB;
00072 extern TGlobalData* gData;
00073 extern TSetupData* gSetup;
00074
00075
00076 #include "TDirectory.h"
00077 #include "TFile.h"
00078 #include "TApplication.h"
00079 #include "TROOT.h"
00080 extern TDirectory * gManaHistsDir;
00081 extern TFile * gManaOutputFile;
00082 extern TApplication * manaApp;
00083 extern TROOT * gROOT;
00084
00085 map <std::string, TH2F*> DQ_PulseShapes_histograms_map;
00086 map <std::string, TH1D*> DQ_PulseShapesProjectionY_histograms_map;
00087 TH1F* hDQ_PulseShapes_Pedestals;
00088 TH1F* hDQ_PulseShapes_Noises;
00089
00090 static int GetLastPresampleBin(std::string bankname);
00091
00092 ANA_MODULE MDQ_PulseShapes_module =
00093 {
00094 "MDQ_PulseShapes",
00095 "Nam Tran",
00096 MDQ_PulseShapes,
00097 NULL,
00098 MDQ_PulseShapes_eor,
00099 MDQ_PulseShapes_init,
00100 NULL,
00101 NULL,
00102 0,
00103 NULL,
00104 };
00105
00108 INT MDQ_PulseShapes_init()
00109 {
00110
00111 std::string dir_name("DataQuality_LowLevel/");
00112 if (!gDirectory->Cd(dir_name.c_str())) {
00113 gDirectory->mkdir(dir_name.c_str());
00114 }
00115 gDirectory->Cd(dir_name.c_str());
00116
00117
00118 std::map<std::string, std::string> Bank2DetMap = gSetup->fBankToDetectorMap;
00119 for(std::map<std::string, std::string>::iterator mapIter = Bank2DetMap.begin();
00120 mapIter != Bank2DetMap.end(); mapIter++) {
00121
00122 std::string bankname = mapIter->first;
00123 std::string detname = gSetup->GetDetectorName(bankname);
00124
00125 int n_bits = gSetup->GetNBits(bankname);
00126 int max_adc_value = std::pow(2, n_bits);
00127
00128
00129 std::string histname = "hDQ_PulseShapes_" + detname + "_" + bankname;
00130 std::string histtitle = "Pulse shape of " + detname;
00131 TH2F* hDQ_Histogram = new TH2F(histname.c_str(), histtitle.c_str(),
00132 400, -0.5, 399.5,
00133 max_adc_value, 0, max_adc_value);
00134 hDQ_Histogram->GetXaxis()->SetTitle("Time Stamp [ns]");
00135 hDQ_Histogram->GetYaxis()->SetTitle("Pulse height [adc]");
00136 DQ_PulseShapes_histograms_map[bankname] = hDQ_Histogram;
00137
00138
00139 histname = "hDQ_PulseShapes_ProjectionY_" + detname + "_" + bankname;
00140 histtitle = "Pulse shape Y-projection of " + detname;
00141 TH1D* hDQ_Histogram_TH1D = new TH1D(histname.c_str(), histtitle.c_str(),
00142 max_adc_value, 0, max_adc_value);
00143 hDQ_Histogram_TH1D->GetXaxis()->SetTitle("ADC");
00144 hDQ_Histogram_TH1D->GetYaxis()->SetTitle("Arbitary unit");
00145 DQ_PulseShapesProjectionY_histograms_map[bankname] = hDQ_Histogram_TH1D;
00146 }
00147
00148
00149 std::string histname = "hDQ_PulseShapes_Pedestals";
00150 std::string histtitle = "Pedestals";
00151 hDQ_PulseShapes_Pedestals = new TH1F(histname.c_str(), histtitle.c_str(),1,0,1);
00152 hDQ_PulseShapes_Pedestals->GetXaxis()->SetTitle("Bank (Detector)");
00153 hDQ_PulseShapes_Pedestals->GetYaxis()->SetTitle("Pedestal [ADC]");
00154 hDQ_PulseShapes_Pedestals->SetBit(TH1::kCanRebin);
00155
00156
00157 histname = "hDQ_PulseShapes_Noises";
00158 histtitle = "Noises";
00159 hDQ_PulseShapes_Noises = new TH1F(histname.c_str(), histtitle.c_str(),1,0,1);
00160 hDQ_PulseShapes_Noises->GetXaxis()->SetTitle("Bank (Detector)");
00161 hDQ_PulseShapes_Noises->GetYaxis()->SetTitle("Noise (FWHM) [ADC]");
00162 hDQ_PulseShapes_Noises->SetBit(TH1::kCanRebin);
00163
00164
00165 gDirectory->Cd("/MidasHists/");
00166 return SUCCESS;
00167 }
00168
00171 INT MDQ_PulseShapes(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();
00188 mapIter != pulse_islands_map.end(); ++mapIter)
00189 {
00190 std::string bankname = mapIter->first;
00191 std::string detname = gSetup->GetDetectorName(bankname);
00192 std::vector<TPulseIsland*> thePulses = mapIter->second;
00193
00194
00195 TH2F* hDQ_PulseShapes = DQ_PulseShapes_histograms_map[bankname];
00196
00197
00198 for (std::vector<TPulseIsland*>::iterator pulseIter = thePulses.begin();
00199 pulseIter != thePulses.end(); ++pulseIter) {
00200
00201
00202 if (DQ_PulseShapes_histograms_map.find(bankname) !=
00203 DQ_PulseShapes_histograms_map.end())
00204 {
00205 const std::vector<int>& theSamples = (*pulseIter)->GetSamples();
00206 for (std::vector<int>::const_iterator sampleIter = theSamples.begin();
00207 sampleIter != theSamples.end(); ++sampleIter)
00208 {
00209 int sample_number = sampleIter - theSamples.begin();
00210
00211 int sample_value = *sampleIter;
00212 hDQ_PulseShapes->Fill(sample_number,sample_value);
00213 }
00214 }
00215 }
00216 }
00217 return SUCCESS;
00218 }
00219
00220 INT MDQ_PulseShapes_eor(INT run_number)
00221 {
00222 typedef std::map<std::string, std::string>::iterator String2StringMapIter;
00223 std::map<std::string, std::string> Bank2DetMap = gSetup->fBankToDetectorMap;
00224
00225 for(String2StringMapIter mapIter = Bank2DetMap.begin();
00226 mapIter != Bank2DetMap.end(); mapIter++)
00227 {
00228 std::string bankname = mapIter->first;
00229 std::string detname = gSetup->GetDetectorName(bankname);
00230
00231 if (DQ_PulseShapes_histograms_map.find(bankname) !=
00232 DQ_PulseShapes_histograms_map.end())
00233 {
00234 TH2F* hPulseShapes = DQ_PulseShapes_histograms_map[bankname];
00235 TH1D* hDQ_Histogram_projY = hPulseShapes->ProjectionY();
00236
00237 DQ_PulseShapesProjectionY_histograms_map[bankname]->Add(
00238 hDQ_Histogram_projY, 1);
00239 hDQ_Histogram_projY->SetDirectory(0);
00240
00241
00242
00243 hDQ_Histogram_projY->GetXaxis()->SetRange(2, hDQ_Histogram_projY->GetNbinsX()-1);
00244 int max_bin = hDQ_Histogram_projY->GetMaximumBin();
00245
00246 double pedestal = hDQ_Histogram_projY->GetBinCenter(max_bin);
00247 double pedestal_value = hDQ_Histogram_projY->GetBinContent(max_bin);
00248 double noise = 0;
00249 for (int iBin = max_bin; iBin < hDQ_Histogram_projY->GetNbinsX(); ++iBin) {
00250 double value = hDQ_Histogram_projY->GetBinContent(iBin);
00251 if (value < 0.5*pedestal_value) {
00252 noise = hDQ_Histogram_projY->GetBinCenter(iBin) - pedestal;
00253 break;
00254 }
00255 }
00256
00257 std::string binlabel = bankname + " (" + detname + ")";
00258 hDQ_PulseShapes_Pedestals->Fill(binlabel.c_str(), pedestal);
00259 hDQ_PulseShapes_Noises->Fill(binlabel.c_str(), 2*noise);
00260 }
00261 }
00262
00263 return SUCCESS;
00264 }
00265