00001 #include "TAPGeneratorFactory.h"
00002 #include "TAPAlgorithms.h"
00003 #include "SetupNavigator.h"
00004 #include "IntegralRatioAPGenerator.h"
00005 #include "TPulseIsland.h"
00006 #include "TIntegralRatioAnalysedPulse.h"
00007
00008 #include <iostream>
00009 #include <algorithm>
00010 #include <stdexcept>
00011 using std::cout;
00012 using std::endl;
00013 #include "debug_tools.h"
00014
00015 IntegralRatioAPGenerator::IntegralRatioAPGenerator(TAPGeneratorOptions* opts):
00016 TVAnalysedPulseGenerator("IntegralRatio",opts),
00017 fStartTailAsFraction(opts->GetBool("start_tail_as_fraction",false)),
00018 fStartIntegral(opts->GetInt("start_int","x>=0")),
00019 fStopIntegral(opts->GetInt("stop_int","x>=0")),
00020 fStartTail(opts->GetDouble("start_tail",
00021 fStartTailAsFraction?
00022 "x<1 && x>0":
00023 Form("x>%g",fStartIntegral))),
00024
00025 fPedestal(SetupNavigator::Instance()->GetPedestal(GetChannel())),
00026
00027 fPolarity(TSetupData::Instance()->GetTriggerPolarity(TSetupData::Instance()->GetBankName(GetChannel().str()))),
00028 fIntegralRatioAlgo( fStartIntegral, fStartTail, fStopIntegral, fPolarity,fPedestal),
00029 fMaxBinAmplitude(fPedestal,fPolarity)
00030 {
00031 }
00032
00033 IntegralRatioAPGenerator::~IntegralRatioAPGenerator(){}
00034
00035 int IntegralRatioAPGenerator::ProcessPulses(
00036 const PulseIslandList& pulseList,
00037 AnalysedPulseList& analysedList){
00038
00039
00040 int start_tail;
00041 TIntegralRatioAnalysedPulse* tap;
00042 for (PulseIslandList::const_iterator tpi=pulseList.begin();
00043 tpi!=pulseList.end(); tpi++){
00044
00045 if(fStartTailAsFraction){
00046 start_tail=fStartTail*(*tpi)->GetPulseLength();
00047 fIntegralRatioAlgo.SetTailStart(start_tail);
00048 }
00049
00050
00051 try{
00052 fIntegralRatioAlgo.SetPedestalToMinimum(*tpi);
00053 fIntegralRatioAlgo(*tpi);
00054 }catch(std::out_of_range& e){
00055 continue;
00056 }
00057 fMaxBinAmplitude(*tpi);
00058
00059
00060
00061
00062 tap = MakeNewTAP<TIntegralRatioAnalysedPulse>(tpi-pulseList.begin());
00063 tap->SetIntegral(fIntegralRatioAlgo.GetTotal());
00064 tap->SetIntegralSmall(fIntegralRatioAlgo.GetTail());
00065 tap->SetIntegralRatio(fIntegralRatioAlgo.GetRatio());
00066 tap->SetAmplitude(fMaxBinAmplitude.GetAmplitude());
00067 tap->SetTime(fMaxBinAmplitude.GetTime());
00068
00069
00070 analysedList.push_back(tap);
00071 }
00072
00073
00074 if(Debug()){
00075
00076
00077 cout<<"Now running source: "<<GetSource().str()<<" which looks for TAPs on "
00078 "channel: "<<GetChannel().str()<<'\n';
00079 }
00080
00081
00082 return 0;
00083 }
00084
00085 const char* IntegralRatioAPGenerator::TapType() {
00086 return TIntegralRatioAnalysedPulse::Class()->GetName();
00087 }
00088
00089 ALCAP_TAP_GENERATOR(IntegralRatio,start_int,start_tail,stop_int,start_tail_as_fraction);