00001 #ifndef TEMPLATECREATOR_H_
00002 #define TEMPLATECREATOR_H_
00003
00004 #include "BaseModule.h"
00005 class gTGlobalData;
00006 class gTSetupData;
00007 class gModulesOptions;
00008 class TH1D;
00009
00010 #include "TAPAlgorithms.h"
00011 #include "TemplateArchive.h"
00012 #include "PulseCandidateFinder.h"
00013 #include "TemplateFitter.h"
00014 #include "TTemplate.h"
00015 #include "InterpolatePulse.h"
00016
00017 class TemplateCreator : public BaseModule{
00018 struct ChannelSet{
00019 std::string detname, bankname;
00020
00021 int fit_successes, fit_attempts;
00022 int trigger_polarity;
00023 TTemplate* template_pulse;
00024
00025 TemplateFitter* fitter;
00026 PulseCandidateFinder* pulse_finder;
00027 Algorithm::IntegralRatio *integralRatio;
00028
00029
00030 ChannelSet(const std::string& detname, const std::string& bankname, modules::options* opts,int refine );
00031 void Clear();
00032 };
00033 typedef std::vector<ChannelSet> ChannelList;
00034
00035 public:
00036 TemplateCreator(modules::options* opts);
00037 ~TemplateCreator();
00038
00039 private:
00040 virtual int ProcessEntry(TGlobalData *gData, const TSetupData* gSetup);
00041 virtual int BeforeFirstEntry(TGlobalData* gData, const TSetupData* setup);
00042 virtual int AfterLastEntry(TGlobalData* gData, const TSetupData* setup);
00043
00044 void AddPulseToTemplate(ChannelSet& current, TH1D* & hPulse);
00045
00048 double CorrectSampleValue(double old_value, double template_pedestal);
00049
00052 TH1D* CreateRefinedPulseHistogram(const TPulseIsland* pulse, std::string histname, std::string histtitle, bool interpolate){
00053 return InterpolatePulse(pulse,histname,histtitle, interpolate, fRefineFactor);
00054 }
00055
00059 bool CheckConvergence(ChannelSet& current);
00060
00063 int HasPulseOverflowed(const TPulseIsland* pulse, const std::string& bankname);
00064
00066 TH1D* StartTemplate(int pulseID, const TPulseIsland* pulse,const std::string& detname);
00067
00068
00069 private:
00070
00073 int fRefineFactor;
00074
00075 TemplateFitter* fTemplateFitter;
00076
00077 modules::options* fOpts;
00078
00079 std::string fArchiveName;
00080 TemplateArchive* fTemplateArchive;
00081
00085 bool fPulseDebug;
00086 bool fAnalyseAllChannels;
00087 ChannelList fChannels;
00088 std::vector<std::string> fRequestedChannels;
00089
00090 bool fCutIntegralRatio;
00091 double fIntegralMax, fIntegralMin;
00092 double fIntegralRatioMax, fIntegralRatioMin;
00093 int fStartIntegral, fStopIntegral, fStartTail;
00094
00095 };
00096
00097 #endif //TEMPLATECREATOR_H_