PlotTPI_PedestalAndNoise Class Reference
[Modules]

Plots the pedestal and noise of each TPulseIsland and writes these to an SQLite database. More...

#include <PlotTPI_PedestalAndNoise.h>

Inheritance diagram for PlotTPI_PedestalAndNoise:
BaseModule

List of all members.

Public Member Functions

 PlotTPI_PedestalAndNoise (modules::options *opts)
 The constructor.
 ~PlotTPI_PedestalAndNoise ()
 Empty destructor.
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.
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)
 In every event, we loop over all the detectors and all the TPulseIslands and calculate the RMS and mean of the first fNSamples samples in the digitised pulse (i.e. the noise and the pedestal respectively).
virtual int BeforeFirstEntry (TGlobalData *gData, const TSetupData *setup)
 Nothing is done before each run.
virtual int AfterLastEntry (TGlobalData *gData, const TSetupData *setup)
 After each run, we write the mean and RMS of the first fNSamples to an SQLite database via SetupNavigator.

Private Attributes

std::map< std::string, TH2D * > fPedestalVsNoiseHistograms
 The map that we store the pedestal vs. noise histograms for each channel.
const int fNSamples
 The number of samples we will look at in the TPulseIsland to calculate the mean and RMS (opt = "n_samples").
const bool fExportSQL
 A bool to decide whether we export the pedestal and noise to the SQLite database (opt = "export_sql", default = false).

Detailed Description

Plots the pedestal and noise of each TPulseIsland and writes these to an SQLite database.

Author:
Andrew Edmonds

This module loops over TPulseIsland and plots the mean and RMS of the first n_samples into a 2D histogram. At the end of the run, it writes the mean values of each axis to an SQLite database along with the channel and bank names. This SQLite database can then be used by PulseCandidateFinder to set parameter values based on a certain number of sigma.

Definition at line 25 of file PlotTPI_PedestalAndNoise.h.


Constructor & Destructor Documentation

PlotTPI_PedestalAndNoise::PlotTPI_PedestalAndNoise ( modules::options opts  ) 

The constructor.

The constructor looks in the opts for "n_samples" and sets the fNSamples variable (default = 5).

Parameters:
[in] opts Describe the options this module takes.

Definition at line 22 of file PlotTPI_PedestalAndNoise.cpp.

00022                                                                       :
00023   BaseModule("PlotTPI_PedestalAndNoise",opts), 
00024   fNSamples(opts->GetInt("n_samples")),
00025   fExportSQL(opts->GetBool("export_sql", false)) {
00026 }

PlotTPI_PedestalAndNoise::~PlotTPI_PedestalAndNoise (  ) 

Empty destructor.

Definition at line 28 of file PlotTPI_PedestalAndNoise.cpp.

00028                                                    {
00029 }


Member Function Documentation

int PlotTPI_PedestalAndNoise::AfterLastEntry ( TGlobalData gData,
const TSetupData setup 
) [private, virtual]

After each run, we write the mean and RMS of the first fNSamples to an SQLite database via SetupNavigator.

Parameters:
[in] gData See BaseModule::AfterLastEntry
[in] setup See BaseModule::AfterLastEntry
Returns:
Non-zero to indicate a problem.

Implements BaseModule.

Definition at line 118 of file PlotTPI_PedestalAndNoise.cpp.

References BaseModule::Debug(), fExportSQL, fPedestalVsNoiseHistograms, SetupNavigator::Instance(), and SetupNavigator::SetPedestalAndNoise().

00118                                                                                       {
00119 
00120   // Print extra info if we're debugging this module:
00121   if(Debug()){
00122      cout<<"-----PlotTPI_PedestalAndNoise::AfterLastEntry(): I'm debugging!"<<endl;
00123   }
00124 
00125   if (fExportSQL) {
00126       
00127     // Now loop through the histograms and record the channel, mean and RMS of first fNSamples
00128     for (std::map<std::string, TH2D*>::iterator histIter = fPedestalVsNoiseHistograms.begin(); histIter != fPedestalVsNoiseHistograms.end(); ++histIter) {
00129       std::string detname = histIter->first;
00130       IDs::channel channel(detname);
00131 
00132       TH2D* pedestal_vs_noise_histogram = histIter->second;
00133       
00134       double pedestal = pedestal_vs_noise_histogram->GetMean(1);
00135       double noise = pedestal_vs_noise_histogram->GetMean(2);
00136 
00137       SetupNavigator::Instance()->SetPedestalAndNoise(channel, pedestal, noise);
00138     }
00139   }
00140   
00141   return 0;
00142 }

int PlotTPI_PedestalAndNoise::BeforeFirstEntry ( TGlobalData gData,
const TSetupData setup 
) [private, virtual]

Nothing is done before each run.

Parameters:
[in] gData See BaseModule::BeforeFirstEntry
[in] setup See BaseModule::BeforeFirstEntry
Returns:
Non-zero to indicate a problem.

Implements BaseModule.

Definition at line 34 of file PlotTPI_PedestalAndNoise.cpp.

References BaseModule::Debug().

00034                                                                                         {
00035   // Print extra info if we're debugging this module:
00036   if(Debug()){
00037      cout<<"-----PlotTPI_PedestalAndNoise::BeforeFirstEntry(): I'm debugging!"<<endl;
00038   }
00039 
00040   return 0;
00041 }

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 PlotTPI_PedestalAndNoise::ProcessEntry ( TGlobalData gData,
const TSetupData gSetup 
) [private, virtual]

In every event, we loop over all the detectors and all the TPulseIslands and calculate the RMS and mean of the first fNSamples samples in the digitised pulse (i.e. the noise and the pedestal respectively).

Parameters:
[in] gData See BaseModule::ProcessEntry
[in] gSetup See BaseModule::ProcessEntry
Returns:
Non-zero to indicate a problem.

Implements BaseModule.

Definition at line 45 of file PlotTPI_PedestalAndNoise.cpp.

References fNSamples, fPedestalVsNoiseHistograms, TGlobalData::fPulseIslandToChannelMap, TSetupData::GetDetectorName(), TSetupData::GetNBits(), and TSetupData::Instance().

00045                                                                                     {
00046 
00047   // Prepare a few variables
00048   std::string bankname, detname;
00049   PulseIslandList thePulseIslands;
00050   StringPulseIslandMap::const_iterator it;
00051 
00052 
00053   // Loop over each detector
00054   for(it = gData->fPulseIslandToChannelMap.begin(); it != gData->fPulseIslandToChannelMap.end(); ++it){
00055     
00056     // Get the bank and detector names for this detector
00057     bankname = it->first;
00058     detname = setup->GetDetectorName(bankname);
00059 
00060     // Get the TPIs
00061     thePulseIslands = it->second;
00062     if (thePulseIslands.size() == 0) continue; // no pulses here..
00063 
00064     // Create the histogram that will store all the average RMS noises from each event
00065     if (fPedestalVsNoiseHistograms.find(detname) == fPedestalVsNoiseHistograms.end()) {
00066       int n_bits = TSetupData::Instance()->GetNBits(bankname);
00067       int x_min = 0;
00068       int x_max = std::pow(2, n_bits);
00069       int n_bins_x = 100;
00070 
00071       int y_min = 0;
00072       int y_max = 200;
00073       int n_bins_y = (y_max - y_min)*5;
00074 
00075       std::string histname = "fPedestalVsNoiseHistogram_" + detname;
00076       std::stringstream histtitle;
00077       histtitle << "Plot of the Pedestal vs Noise (mean and RMS of first " << fNSamples << " samples) in " << detname;
00078 
00079       TH2D* histogram = new TH2D(histname.c_str(), histtitle.str().c_str(), n_bins_x,x_min,x_max, n_bins_y,y_min,y_max);
00080       histogram->GetXaxis()->SetTitle("Pedestal [ADC]");
00081       histogram->GetYaxis()->SetTitle("Noise [ADC]");
00082       fPedestalVsNoiseHistograms[detname] = histogram;
00083     }
00084 
00085 
00086 
00087     TH2D* pedestal_vs_noise_histogram = fPedestalVsNoiseHistograms[detname];
00088 
00089     // Loop through all the pulses
00090     for (PulseIslandList::iterator pulseIter = thePulseIslands.begin(); pulseIter != thePulseIslands.end(); ++pulseIter) {
00091 
00092       const std::vector<int>& theSamples = (*pulseIter)->GetSamples();
00093       int limit=fNSamples;
00094       if((int)theSamples.size() < fNSamples) limit=theSamples.size();
00095 
00096       double sum = 0;
00097       for (int iSample = 0; iSample < limit; ++iSample) {
00098           sum += theSamples.at(iSample);
00099       }
00100       double mean = sum / limit;
00101       
00102       double sum_of_deviations_squared = 0;
00103       for (int iSample = 0; iSample < limit; ++iSample) {
00104           sum_of_deviations_squared += (theSamples.at(iSample) - mean)*(theSamples.at(iSample) - mean);
00105       }
00106       double stdev = std::sqrt(sum_of_deviations_squared / limit);
00107 
00108       pedestal_vs_noise_histogram->Fill(mean, stdev);
00109     } // end loop through pulses
00110   } // end loop through detectors
00111 
00112   return 0;
00113 }

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().

A bool to decide whether we export the pedestal and noise to the SQLite database (opt = "export_sql", default = false).

Definition at line 80 of file PlotTPI_PedestalAndNoise.h.

Referenced by AfterLastEntry().

The number of samples we will look at in the TPulseIsland to calculate the mean and RMS (opt = "n_samples").

Definition at line 75 of file PlotTPI_PedestalAndNoise.h.

Referenced by ProcessEntry().

std::map<std::string, TH2D*> PlotTPI_PedestalAndNoise::fPedestalVsNoiseHistograms [private]

The map that we store the pedestal vs. noise histograms for each channel.

Definition at line 70 of file PlotTPI_PedestalAndNoise.h.

Referenced by AfterLastEntry(), and ProcessEntry().


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

Generated on 15 Jun 2016 for AlcapDAQ by  doxygen 1.6.1