00001 #include "TAPGeneratorFactory.h"
00002 #include "FirstCompleteAPGenerator.h"
00003 #include "TPulseIsland.h"
00004 #include "TAnalysedPulse.h"
00005 #include "SetupNavigator.h"
00006 #include "EventNavigator.h"
00007 #include "ExportPulse.h"
00008 #include "ModulesParser.h"
00009 #include "debug_tools.h"
00010
00011 #include <iostream>
00012 #include <cmath>
00013 #include <sstream>
00014
00015 FirstCompleteAPGenerator::FirstCompleteAPGenerator(TAPGeneratorOptions* opts):
00016 TVAnalysedPulseGenerator("FirstComplete",opts),
00017 fMaxBinAmplitude(SetupNavigator::Instance()->GetPedestal(GetChannel()),
00018 TSetupData::Instance()->GetTriggerPolarity(TSetupData::Instance()->GetBankName(GetChannel().str()))),
00019 fConstantFractionTime(SetupNavigator::Instance()->GetPedestal(GetChannel()),
00020 TSetupData::Instance()->GetTriggerPolarity(TSetupData::Instance()->GetBankName(GetChannel().str())),
00021 TSetupData::Instance()->GetClockTick(TSetupData::Instance()->GetBankName(GetChannel().str())),
00022 opts->GetBool("no_time_shift", false) ? 0. : SetupNavigator::Instance()->GetCoarseTimeOffset(GetSource()),
00023 opts->GetDouble("constant_fraction")),
00024 fSimpleIntegral(SetupNavigator::Instance()->GetPedestal(GetChannel()),
00025 TSetupData::Instance()->GetTriggerPolarity(TSetupData::Instance()->GetBankName(GetChannel().str()))),
00026 fPulseCandidateFinder(NULL) {
00027 if(opts->GetBool("use_pcf",true)){
00028 if(opts->Debug()) opts->SetOption("debug","true");
00029 fPulseCandidateFinder=new PulseCandidateFinder(GetChannel().str(), opts);
00030 }
00031 }
00032
00033 FirstCompleteAPGenerator::~FirstCompleteAPGenerator(){
00034
00035 for(PulseIslandList::iterator i_tpi=fSubPulses.begin(); i_tpi!=fSubPulses.end(); ++i_tpi){
00036 delete *i_tpi;
00037 }
00038 }
00039
00040 int FirstCompleteAPGenerator::ProcessPulses(
00041 const PulseIslandList& pulseList,
00042 AnalysedPulseList& analysedList){
00043
00044
00045 for (PulseIslandList::const_iterator i_tpi=pulseList.begin();
00046 i_tpi!=pulseList.end(); ++i_tpi){
00047 int tpi_ID = i_tpi - pulseList.begin();
00048 if(fPulseCandidateFinder) MakeTAPsWithPCF(tpi_ID,*i_tpi,analysedList);
00049 else AnalyseOneTpi(tpi_ID, *i_tpi,analysedList);
00050 }
00051 return 0;
00052 }
00053
00054 void FirstCompleteAPGenerator::MakeTAPsWithPCF(int tpi_ID, const TPulseIsland* original_tpi, AnalysedPulseList& analysedList){
00055
00056 fPulseCandidateFinder->FindPulseCandidates(original_tpi);
00057 fPulseCandidateFinder->GetPulseCandidates(fSubPulses);
00058
00059
00060 for(PulseIslandList::const_iterator i_tpi=fSubPulses.begin(); i_tpi!=fSubPulses.end(); ++i_tpi){
00061 AnalyseOneTpi( tpi_ID, *i_tpi,analysedList);
00062 }
00063 }
00064
00065 void FirstCompleteAPGenerator::AnalyseOneTpi(int tpi_ID, const TPulseIsland* tpi, AnalysedPulseList& analysedList){
00066 if(tpi->GetPulseLength() < 14) return;
00067
00068
00069 double amplitude=fMaxBinAmplitude(tpi);
00070 double time=fConstantFractionTime(tpi);
00071 double integral=fSimpleIntegral(tpi);
00072
00073
00074
00075
00076 TAnalysedPulse* tap = MakeNewTAP(tpi_ID);
00077 tap->SetAmplitude(amplitude);
00078 tap->SetTime(time);
00079 tap->SetIntegral(integral);
00080
00081
00082 analysedList.push_back(tap);
00083 }
00084
00085 void FirstCompleteAPGenerator::DrawPulse(int original, int pulse_timestamp, int n_pulse_samples){
00086
00087
00088
00089
00090
00091 for (std::vector<TPulseIsland*>::const_iterator subPulseIter = fSubPulses.begin();
00092 subPulseIter != fSubPulses.end(); ++subPulseIter) {
00093 std::stringstream histname;
00094 histname << "hSubPulse_" << GetChannel() << "_Event"
00095 << EventNavigator::Instance().EntryNo() <<"_Pulse" << original
00096 << "_SubPulse" << subPulseIter - fSubPulses.begin();
00097
00098 const std::vector<int>& sub_pulse_samples = (*subPulseIter)->GetSamples();
00099
00100 TH1D* hPulse = new TH1D(modules::parser::ToCppValid(histname.str()).c_str(),
00101 histname.str().c_str(), n_pulse_samples,0,n_pulse_samples);
00102 hPulse->SetLineColor(kMagenta);
00103
00104 int delay = (*subPulseIter)->GetTimeStamp() - pulse_timestamp;
00105 for (std::vector<int>::const_iterator subPulseSampleIter = sub_pulse_samples.begin();
00106 subPulseSampleIter != sub_pulse_samples.end(); ++subPulseSampleIter) {
00107 hPulse->Fill( (subPulseSampleIter - sub_pulse_samples.begin()) + delay, (*subPulseSampleIter) );
00108 }
00109 }
00110 }
00111
00112 ALCAP_TAP_GENERATOR(FirstComplete,constant_fraction,no_time_shift, use_pcf);