00001 #include "PlotTAP_TDiff.h"
00002 #include <iostream>
00003 #include <string>
00004 #include <sstream>
00005 #include "TGlobalData.h"
00006 #include "TSetupData.h"
00007
00008 #include "TAnalysedPulse.h"
00009 #include "TDetectorPulse.h"
00010 #include "RegisterModule.inc"
00011 #include "definitions.h"
00012 #include "SetupNavigator.h"
00013 #include "ModulesOptions.h"
00014 #include "AlcapExcept.h"
00015
00016
00017 #include <cmath>
00018 #include <TH1F.h>
00019 #include <TH2F.h>
00020
00021
00022 MAKE_EXCEPTION(ModulesOptionError, Base)
00023
00024 extern SourceAnalPulseMap gAnalysedPulseMap;
00025
00026 PlotTAP_TDiff::PlotTAP_TDiff(modules::options* opts) :
00027 BaseModule("PlotTAP_TDiff",opts),
00028 fDetNameA(opts->GetString("det1")), fDetNameB(opts->GetString("det2")),
00029 fTimeLow(opts->GetDouble("time_low",-1.e5)), fTimeHigh(opts->GetDouble("time_high",1.e5)),
00030 fExportSQL(opts->GetBool("export_sql", false)) {
00031 if (fDetNameA == std::string("") || fDetNameB == std::string(""))
00032 throw Except::ModulesOptionError("Two detectors must be provided");
00033
00034
00035 else if (fExportSQL && fDetNameB != "muSc")
00036 throw Except::ModulesOptionError("If exporting to calibration DB, second detector must be muSc");
00037 }
00038
00039
00040
00041 PlotTAP_TDiff::~PlotTAP_TDiff() {
00042 }
00043
00045
00046 int PlotTAP_TDiff::BeforeFirstEntry(TGlobalData* gData,const TSetupData *setup){
00047
00048 for(SourceAnalPulseMap::const_iterator sourceIt = gAnalysedPulseMap.begin();
00049 sourceIt != gAnalysedPulseMap.end(); sourceIt++) {
00050
00051 if( sourceIt->first.Channel() != fDetNameA)
00052 continue;
00053
00054 for(SourceAnalPulseMap::const_iterator sourceIt2 = gAnalysedPulseMap.begin(); sourceIt2 != gAnalysedPulseMap.end(); ++sourceIt2)
00055 {
00056 if(sourceIt2->first.Channel() != fDetNameB)
00057 continue;
00058
00059
00060 fDetASources.push_back(sourceIt->first);
00061 fDetBSources.push_back(sourceIt2->first);
00062 break;
00063 }
00064 }
00065 BookHistograms(setup);
00066 return 0;
00067 }
00068
00069
00070
00071 int PlotTAP_TDiff::ProcessEntry(TGlobalData* gData,const TSetupData *setup) {
00072
00073 for(unsigned int i = 0; i < fDetASources.size(); ++i) {
00074 const AnalysedPulseList& detAPulses = gAnalysedPulseMap[fDetASources[i]];
00075 const AnalysedPulseList& detBPulses = gAnalysedPulseMap[fDetBSources[i]];
00076 const std::vector<TH2F*>& hists = fHists[fDetASources[i].str()];
00077
00078 for(AnalysedPulseList::const_iterator pulseIt = detAPulses.begin();
00079 pulseIt != detAPulses.end(); ++pulseIt) {
00080
00081 for(AnalysedPulseList::const_iterator pulseIt2 = detBPulses.begin();
00082 pulseIt2 != detBPulses.end(); ++pulseIt2) {
00083 double tDiff = (*pulseIt)->GetTime() - (*pulseIt2)->GetTime();
00084
00085 hists[0]->Fill(tDiff, (*pulseIt)->GetAmplitude());
00086 hists[1]->Fill(tDiff, (*pulseIt2)->GetAmplitude());
00087 hists[2]->Fill(tDiff, (*pulseIt)->GetIntegral());
00088 hists[3]->Fill(tDiff, (*pulseIt2)->GetIntegral());
00089
00090 }
00091 }
00092 }
00093
00094 return 0;
00095 }
00096
00097
00098
00099
00100 int PlotTAP_TDiff::AfterLastEntry(TGlobalData* gData,const TSetupData *setup){
00101 if (fExportSQL) {
00102 for (unsigned int i = 0; i < fDetASources.size(); ++i) {
00103 TH1D* h = fHists[fDetASources[i].str()][0]->ProjectionX();
00104 SetupNavigator::Instance()->SetCoarseTimeOffset(fDetASources[i], h->GetBinCenter(h->GetMaximumBin()));
00105 }
00106 }
00107 return 0;
00108 }
00109
00110 void PlotTAP_TDiff::BookHistograms(const TSetupData* setup) {
00111 for (unsigned int i = 0; i < fDetASources.size(); ++i) {
00112 const std::string gen = fDetASources.at(i).Generator().str();
00113 const int maxAmpA = std::pow(2, setup->GetNBits(setup->GetBankName(fDetNameA)));
00114 const int maxAmpB = std::pow(2, setup->GetNBits(setup->GetBankName(fDetNameB)));
00115 std::vector<TH2F*>& hists = fHists[fDetASources.at(i).str()];
00116
00117
00118 std::string histname("h" + fDetNameB + "_" + fDetASources.at(i).str() + "TDiff_AmpA");
00119 std::string histtitle("Amplitude of " + fDetNameA + " vs time difference with " + fDetNameB + " detectors with the " + gen + " generator;Time Difference (ns);Amplitude (ADC counts)");
00120 hists.push_back(new TH2F(histname.c_str(), histtitle.c_str(), 200, fTimeLow, fTimeHigh, 200, 0, maxAmpA));
00121
00122
00123 histname = "h" + fDetNameB + "_" + fDetASources.at(i).str() + " TDiff_AmpB";
00124 histtitle = "Amplitude of " + fDetNameB + " vs time difference with " + fDetNameA + " detectors with the " + gen + " generator;Time Difference (ns);Amplitude (ADC counts)";
00125 hists.push_back(new TH2F(histname.c_str(), histtitle.c_str(), 200, fTimeLow, fTimeHigh, 200, 0, maxAmpB));
00126
00127
00128 histname = "h" + fDetNameB + "_" + fDetASources.at(i).str() + " TDiff_IntA";
00129 histtitle = "Integral of " + fDetNameA + " vs time difference with " + fDetNameB + " detectors with the " + gen + " generator;Time Difference (ns);Integral (ADC counts)";
00130 hists.push_back(new TH2F(histname.c_str(), histtitle.c_str(), 200, fTimeLow, fTimeHigh, 200, 0, 5*maxAmpA));
00131
00132
00133 histname = "h" + fDetNameB + "_" + fDetASources.at(i).str() + " TDiff_IntB";
00134 histtitle = "Integral of " + fDetNameB + " vs time difference with " + fDetNameA + " detectors with the " + gen + " generator;Time Difference (ns);Integral (ADC counts)";
00135 hists.push_back(new TH2F(histname.c_str(), histtitle.c_str(), 200, fTimeLow, fTimeHigh, 200, 0, 5*maxAmpB));
00136
00137 }
00138 }
00139
00140
00141
00142
00143
00144 ALCAP_REGISTER_MODULE(PlotTAP_TDiff,det1,det2,time_low,time_high,export_sql);