MakeTemplate Class Reference

#include <MakeTemplate.h>

Inheritance diagram for MakeTemplate:
BaseModule

List of all members.

Public Member Functions

 MakeTemplate (char *HistogramDirectoryName)
 ~MakeTemplate ()
int ProcessGenericEntry (TGlobalData *gData, const TSetupData *gSetup)
int Preprocess (TGlobalData *gData, const TSetupData *gSetup)
 Method called by the main pre-process loop.
int Postprocess (TGlobalData *gData, const TSetupData *gSetup)
 Method called by the main pre-process loop.
virtual int BeforeFirstEntry (TGlobalData *gData, const TSetupData *setup)=0
virtual int AfterLastEntry (TGlobalData *gData, const TSetupData *setup)=0
void SetAlias (const std::string &alias)
std::string GetAlias () const
const char * GetName () const
 Get the name of this module as given to the constructor of the base class.

Protected Member Functions

bool Debug () const
TDirectory * GetDirectory () const
 Get the TDirectory for this module.
TDirectory * GetDirectory (const std::string &name="")

Protected Attributes

TDirectory * dir

Private Member Functions

virtual int ProcessEntry (TGlobalData *gData, const TSetupData *gSetup)
 The big kahuna. Overload this in the derived class and it will be called for each event.

Private Attributes

TFile * fTemplateFile
std::map< std::string,
PulseTemplate * > 
fTemplates

Detailed Description

Definition at line 14 of file MakeTemplate.h.


Constructor & Destructor Documentation

MakeTemplate::MakeTemplate ( char *  HistogramDirectoryName  ) 

Definition at line 15 of file MakeTemplate.cpp.

References fTemplateFile.

00015                                                        :
00016         BaseModule(HistogramDirectoryName) 
00017 {
00018   fTemplateFile = new TFile("template.root", "RECREATE");
00019   gDirectory->cd("/");
00020 }

MakeTemplate::~MakeTemplate (  ) 

Definition at line 22 of file MakeTemplate.cpp.

References fTemplateFile, and fTemplates.

00022                            { // Save and destroy templates
00023   std::map<std::string, PulseTemplate*>::iterator iTemplate;
00024   for (iTemplate = fTemplates.begin(); iTemplate != fTemplates.end(); ++iTemplate) {
00025     if (iTemplate->second) {
00026       iTemplate->second->Save(fTemplateFile);
00027       delete iTemplate->second;
00028       iTemplate->second = NULL;
00029     }
00030   }
00031   fTemplates.clear();
00032   fTemplateFile->Close();
00033   delete fTemplateFile;
00034 }


Member Function Documentation

virtual int BaseModule::AfterLastEntry ( TGlobalData gData,
const TSetupData setup 
) [pure virtual, inherited]
virtual int BaseModule::BeforeFirstEntry ( TGlobalData gData,
const TSetupData setup 
) [pure virtual, inherited]
bool BaseModule::Debug (  )  const [inline, protected, inherited]
std::string BaseModule::GetAlias (  )  const [inline, inherited]

Returns a string for the alias of this module. May be empty if no alias was given in the modules file.

Definition at line 63 of file BaseModule.h.

References BaseModule::fAlias.

Referenced by BaseModule::BaseModule().

00063 {return fAlias;};

TDirectory * BaseModule::GetDirectory ( const std::string &  name = ""  )  [protected, inherited]

Definition at line 77 of file BaseModule.cpp.

References BaseModule::dir, and BaseModule::fDirectory.

00077                                                          {
00078   if(name.empty()) return fDirectory;
00079   TDirectory* dir=fDirectory->GetDirectory(name.c_str());
00080   if(dir) return dir;
00081   return fDirectory->mkdir(name.c_str());
00082 }

TDirectory* BaseModule::GetDirectory (  )  const [inline, protected, inherited]
const char* BaseModule::GetName (  )  const [inline, inherited]

Get the name of this module as given to the constructor of the base class.

Definition at line 66 of file BaseModule.h.

References BaseModule::fName.

Referenced by SavePulses::BeforeFirstEntry(), PlotTDPs::BeforeFirstEntry(), PlotTDP_TDiff::BeforeFirstEntry(), PlotTAP_Time::ProcessEntry(), PlotTAP_Energy::ProcessEntry(), PlotTAP_Amplitude::ProcessEntry(), and LoopSequence::Run().

00066 {return fName.c_str();};

int BaseModule::Postprocess ( TGlobalData gData,
const TSetupData gSetup 
) [inherited]

Method called by the main pre-process loop.

Does some simple work, then hooks into the derived class through AfterLastEntry.

Returns:
0 on sucess and non-zero if a problem occurred

Definition at line 66 of file BaseModule.cpp.

References BaseModule::AfterLastEntry(), and BaseModule::fDirectory.

Referenced by LoopSequence::Postprocess().

00066                                                                        {
00067   // This is called by our main routine and would allow later to split into different 
00068   // process routines if we have more than one Tree and hence different tpyes of data input.
00069 
00070   if(fDirectory) fDirectory->cd();
00071   int ret = AfterLastEntry(gData, gSetup);
00072   gDirectory->cd("/");
00073 
00074   return ret;
00075 }

int BaseModule::Preprocess ( TGlobalData gData,
const TSetupData gSetup 
) [inherited]

Method called by the main pre-process loop.

Does some simple work, then hooks into the derived class through BeforeFirstEntry.

Returns:
0 on sucess and non-zero if a problem occurred

Definition at line 55 of file BaseModule.cpp.

References BaseModule::BeforeFirstEntry(), and BaseModule::fDirectory.

Referenced by LoopSequence::Preprocess().

00055                                                                       {
00056   // This is called by our main routine and would allow later to split into different 
00057   // process routines if we have more than one Tree and hence different tpyes of data input.
00058 
00059   if(fDirectory) fDirectory->cd();
00060   int ret = BeforeFirstEntry(gData, gSetup);
00061   gDirectory->cd("/");
00062 
00063   return ret;
00064 }

int MakeTemplate::ProcessEntry ( TGlobalData gData,
const TSetupData gSetup 
) [private, virtual]

The big kahuna. Overload this in the derived class and it will be called for each event.

Parameters:
gData Pointer to current map of all TPIs [ WILL CHANGE SHORTLY ]
gSetup Pointer to TSetupData for this run [ WILL CHANGE SHORTLY ]
Returns:
0 on success and non-zero on failure

Implements BaseModule.

Definition at line 36 of file MakeTemplate.cpp.

References PulseTemplate::AddPulse(), PulseTemplate::Chi2Fit(), PulseTemplate::Converged(), PrePulse::FindPrePulses(), TGlobalData::fPulseIslandToChannelMap, fTemplateFile, fTemplates, TSetupData::GetClockTick(), TSetupData::GetNBits(), PulseTemplate::GetNumberOfPulses(), TSetupData::GetPedestal(), TPulseIsland::GetSamples(), TSetupData::GetTriggerPolarity(), PulseTemplate::Print(), and PulseTemplate::Save().

00036                                                                            {
00037   
00038   std::map< std::string, std::vector<TPulseIsland*> >& detPulses = gData->fPulseIslandToChannelMap;
00039   std::map< std::string, std::vector<TPulseIsland*> >::iterator iDetPulses;
00040 
00041   for (iDetPulses = detPulses.begin(); iDetPulses != detPulses.end(); ++iDetPulses) {
00042     std::string bank = iDetPulses->first;
00043     if (!fTemplates.count(bank))
00044       fTemplates[bank] = new PulseTemplate();
00045     PulseTemplate* pTemplate = fTemplates[bank];
00046     double pDT = gSetup->GetClockTick(bank);
00047     int pPol = gSetup->GetTriggerPolarity(bank);
00048     double pPed = (double)gSetup->GetPedestal(bank);
00049     double pMax = std::pow(2.,(double)(gSetup->GetNBits(bank))) - 1.;
00050     double pThresh = (pPol > 0 ? (pMax - pPed) / 2. : pPed / 2.);
00051     
00052     std::vector<TPulseIsland*>& pulses = iDetPulses->second;
00053     int iPulse = 0;
00054     while (!pTemplate->Converged() && iPulse < pulses.size()) {
00055       TPulseIsland* pulse = pulses[iPulse++];
00056       std::vector<PrePulse> prepulses = PrePulse::FindPrePulses(pulse, pThresh/2., pThresh/4.);
00057       if (prepulses.size() == 1) {
00058         if (pTemplate->GetNumberOfPulses() == 0) {
00059           // If this is the first pulse, first guess at timing is
00060           // weighted based on peak size relative to immediate
00061           // neighbors
00062           std::vector<int> samples = pulse->GetSamples();
00063           int i = prepulses.at(0).GetLocation();
00064           double s1 = (double)samples[i-1];
00065           double s2 = (double)samples[i];
00066           double s3 = (double)samples[i+1];
00067           double t = (s3 - s1) / (s1 + s2 + s3);
00068           pTemplate->AddPulse(pulse, t);
00069           pTemplate->Save(fTemplateFile);
00070         } else {
00071           double p, a, t, t0;
00072           p = pPed;
00073           a = pPol * ((double)prepulses.at(0).GetHeight() - pPed);
00074           t0 = (double)prepulses.at(0).GetLocation();
00075           t = t0;
00076           pTemplate->Chi2Fit(pulse, p, a, t);
00077           pTemplate->AddPulse(pulse, t - t0);
00078         }
00079         prepulses.at(0).Print();
00080         pTemplate->Print();
00081       }
00082     }
00083   }
00084   
00085 
00086   return 0;
00087 }

int BaseModule::ProcessGenericEntry ( TGlobalData gData,
const TSetupData gSetup 
) [inherited]

Method called by the main event loop for each entry in the input root tree. Does some simple work, then hooks into the derived class through ProcessEntry.

Returns:
0 on sucess and non-zero if a problem occurred

Definition at line 44 of file BaseModule.cpp.

References BaseModule::fDirectory, and BaseModule::ProcessEntry().

Referenced by LoopSequence::Process().

00044                                                                                {
00045   // This is called by our main routine and would allow later to split into different 
00046   // process routines if we have more than one Tree and hence different tpyes of data input.
00047 
00048   if(fDirectory) fDirectory->cd();
00049   int ret = ProcessEntry(gData, gSetup);
00050   gDirectory->cd("/");
00051 
00052   return ret;
00053 }

void BaseModule::SetAlias ( const std::string &  alias  )  [inline, inherited]

Sets the alias for this module, which should be provided in the modules file

Definition at line 59 of file BaseModule.h.

References BaseModule::fAlias.

Referenced by BaseModule::BaseModule().

00059 {fAlias=alias;};


Member Data Documentation

TDirectory* BaseModule::dir [protected, inherited]

Many modules use 'dir' still which was the old protected pointer to the modules directory. To prevent things being broken so soon, we keep this pointer available, but be warned that it will be removed shortly...

Definition at line 98 of file BaseModule.h.

Referenced by BaseModule::BaseModule(), FastSlowCompare::FastSlowCompare(), GeSpectrum::GeSpectrum(), BaseModule::GetDirectory(), MakeMuonEvents::MakeMuonEvents(), and PlotAmpVsTDiff::PlotAmpVsTDiff().

TFile* MakeTemplate::fTemplateFile [private]

Definition at line 17 of file MakeTemplate.h.

Referenced by MakeTemplate(), ProcessEntry(), and ~MakeTemplate().

std::map<std::string, PulseTemplate*> MakeTemplate::fTemplates [private]

Definition at line 18 of file MakeTemplate.h.

Referenced by ProcessEntry(), and ~MakeTemplate().


The documentation for this class was generated from the following files:

Generated on 15 Jun 2016 for AlcapDAQ by  doxygen 1.6.1