00001 #include "PlotTAP_selfCorrelation.h"
00002 #include "RegisterModule.inc"
00003 #include "TGlobalData.h"
00004 #include "TSetupData.h"
00005 #include "ModulesOptions.h"
00006 #include "definitions.h"
00007 #include "TAnalysedPulse.h"
00008 #include <TH2F.h>
00009
00010 #include <iostream>
00011 #include <cmath>
00012 using std::cout;
00013 using std::endl;
00014
00015 extern SourceAnalPulseMap gAnalysedPulseMap;
00016
00017 PlotTAP_selfCorrelation::PlotTAP_selfCorrelation(modules::options* opts):
00018 BaseModule("PlotTAP_selfCorrelation",opts),
00019 fDetNameA(opts->GetString("det1")), fDetNameB(opts->GetString("det2")),
00020 fTimeLow(opts->GetDouble("time_low",-1.e5)),
00021 fTimeHigh(opts->GetDouble("time_high",1.e5)),
00022 fMinAmpA(opts->GetDouble("min_amp",0)),
00023 fMaxAmpA(opts->GetDouble("max_amp",1e20)),
00024 fMuScWindow(opts->GetDouble("musc_window",10)*1e3){
00025 }
00026
00027 PlotTAP_selfCorrelation::~PlotTAP_selfCorrelation(){
00028 }
00029
00030 int PlotTAP_selfCorrelation::BeforeFirstEntry(TGlobalData* gData,const TSetupData *setup){
00031
00032 IDs::channel muSc("muSc");
00033 for(SourceAnalPulseMap::const_iterator sourceIt = gAnalysedPulseMap.begin();
00034 sourceIt != gAnalysedPulseMap.end(); sourceIt++) {
00035
00036
00037 if( sourceIt->first.matches(muSc)) fMuScSource=sourceIt->first;
00038
00039 if( sourceIt->first.Channel() != fDetNameA)
00040 continue;
00041
00042 for(SourceAnalPulseMap::const_iterator sourceIt2 = gAnalysedPulseMap.begin(); sourceIt2 != gAnalysedPulseMap.end(); ++sourceIt2)
00043 {
00044 if(sourceIt2->first.Channel() != fDetNameB)
00045 continue;
00046
00047
00048 fDetASources.push_back(sourceIt->first);
00049 fDetBSources.push_back(sourceIt2->first);
00050 break;
00051 }
00052 }
00053
00054 BookHistograms(setup);
00055 return 0;
00056 }
00057
00058 int PlotTAP_selfCorrelation::ProcessEntry(TGlobalData* gData,const TSetupData *setup){
00059 const AnalysedPulseList& muScPulseList=gAnalysedPulseMap.at(fMuScSource);
00060 for(unsigned int i = 0; i < fDetASources.size(); ++i) {
00061 const AnalysedPulseList& detAPulses = gAnalysedPulseMap[fDetASources[i]];
00062 const AnalysedPulseList& detBPulses = gAnalysedPulseMap[fDetBSources[i]];
00063 const std::vector<TH2F*>& hists = fHists[fDetASources[i].str()];
00064
00065 for(AnalysedPulseList::const_iterator pulseIt = detAPulses.begin();
00066 pulseIt != detAPulses.end(); ++pulseIt) {
00067 if(!PassesCutA(*pulseIt)) continue;
00068 if(!PassesMuScCut(*pulseIt, muScPulseList)) continue;
00069
00070 for(AnalysedPulseList::const_iterator pulseIt2 = detBPulses.begin();
00071 pulseIt2 != detBPulses.end(); ++pulseIt2) {
00072 double tDiff = (*pulseIt)->GetTime() - (*pulseIt2)->GetTime();
00073
00074 hists[0]->Fill(tDiff, (*pulseIt)->GetAmplitude());
00075 hists[1]->Fill(tDiff, (*pulseIt2)->GetAmplitude());
00076 hists[2]->Fill(tDiff, (*pulseIt)->GetIntegral());
00077 hists[3]->Fill(tDiff, (*pulseIt2)->GetIntegral());
00078
00079 }
00080 }
00081 }
00082
00083 return 0;
00084 }
00085
00086 bool PlotTAP_selfCorrelation::PassesCutA(const TAnalysedPulse* tap)const{
00087 const double amp=tap->GetAmplitude();
00088 if(amp < fMinAmpA || amp > fMaxAmpA) return false;
00089 return true;
00090 }
00091
00092 bool PlotTAP_selfCorrelation::PassesMuScCut(const TAnalysedPulse* tap, const AnalysedPulseList& muScPulseList)const{
00093 return true;
00094 }
00095
00096 int PlotTAP_selfCorrelation::AfterLastEntry(TGlobalData* gData,const TSetupData *setup){
00097 return 0;
00098 }
00099
00100 void PlotTAP_selfCorrelation::BookHistograms(const TSetupData* setup) {
00101 for (unsigned int i = 0; i < fDetASources.size(); ++i) {
00102 const std::string gen = fDetASources.at(i).Generator().str();
00103 const int maxAmpA = std::pow(2, setup->GetNBits(setup->GetBankName(fDetNameA)));
00104 const int maxAmpB = std::pow(2, setup->GetNBits(setup->GetBankName(fDetNameB)));
00105 std::vector<TH2F*>& hists = fHists[fDetASources.at(i).str()];
00106
00107
00108 std::string histname("hTDiff_AmpA");
00109 std::string histtitle="Amplitude of " + fDetNameA + " vs time difference with " + fDetNameB
00110 + " detectors with the " + gen + " generator;Time Difference (ns);Amplitude (ADC counts)";
00111 hists.push_back(new TH2F(histname.c_str(), histtitle.c_str(), 200, fTimeLow, fTimeHigh, 200, 0, maxAmpA));
00112
00113
00114 histname = "hTDiff_AmpB";
00115 histtitle = "Amplitude of " + fDetNameB + " vs time difference with " + fDetNameA
00116 + " detectors with the " + gen + " generator;Time Difference (ns);Amplitude (ADC counts)";
00117 hists.push_back(new TH2F(histname.c_str(), histtitle.c_str(), 200, fTimeLow, fTimeHigh, 200, 0, maxAmpB));
00118
00119
00120 histname = "hTDiff_IntA";
00121 histtitle = "Integral of " + fDetNameA + " vs time difference with " + fDetNameB
00122 + " detectors with the " + gen + " generator;Time Difference (ns);Integral (ADC counts)";
00123 hists.push_back(new TH2F(histname.c_str(), histtitle.c_str(), 200, fTimeLow, fTimeHigh, 200, 0, 5*maxAmpA));
00124
00125
00126 histname = "hTDiff_IntB";
00127 histtitle = "Integral of " + fDetNameB + " vs time difference with " + fDetNameA
00128 + " detectors with the " + gen + " generator;Time Difference (ns);Integral (ADC counts)";
00129 hists.push_back(new TH2F(histname.c_str(), histtitle.c_str(), 200, fTimeLow, fTimeHigh, 200, 0, 5*maxAmpB));
00130
00131 }
00132 }
00133
00134 ALCAP_REGISTER_MODULE(PlotTAP_selfCorrelation ,det1,det2,time_low,time_high,min_amp,max_amp);