Plots the pedestal and noise of each TPulseIsland and writes these to an SQLite database. More...
#include <PlotPedestalAndNoise.h>
Public Member Functions | |
PlotPedestalAndNoise (modules::options *opts) | |
The constructor. | |
~PlotPedestalAndNoise () | |
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. | |
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. | |
Private Attributes | |
std::map< std::string, TH2D * > | fPedestalVsNoiseHistograms |
The map that we store the pedestal vs. noise histograms for each channel. | |
int | fNSamples |
The number of samples we will look at in the TPulseIsland to calculate the mean and RMS (opt = "n_samples", default = 5). | |
bool | fExportSQL |
A bool to decide whether we export the pedestal and noise to the SQLite database (opt = "export_sql", default = false). |
Plots the pedestal and noise of each TPulseIsland and writes these to an SQLite database.
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 PlotPedestalAndNoise.h.
PlotPedestalAndNoise::PlotPedestalAndNoise | ( | modules::options * | opts | ) |
The constructor.
The constructor looks in the opts for "n_samples" and sets the fNSamples variable (default = 5).
[in] | opts | Describe the options this module takes. |
Definition at line 22 of file PlotPedestalAndNoise.cpp.
References fExportSQL, fNSamples, modules::options::GetBool(), and modules::options::GetInt().
00022 : 00023 BaseModule("PlotPedestalAndNoise",opts){ 00024 00025 // Do something with opts here. Has the user specified any 00026 // particular configuration that you want to know? 00027 // For example, perhaps this module wants an axis range: 00028 fNSamples = opts->GetInt("n_samples", 5); 00029 fExportSQL = opts->GetBool("export_sql", false); 00030 }
PlotPedestalAndNoise::~PlotPedestalAndNoise | ( | ) |
int PlotPedestalAndNoise::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.
[in] | gData | See BaseModule::AfterLastEntry |
[in] | setup | See BaseModule::AfterLastEntry |
Implements BaseModule.
Definition at line 122 of file PlotPedestalAndNoise.cpp.
References BaseModule::Debug(), fExportSQL, fPedestalVsNoiseHistograms, TSetupData::GetBankName(), SetupNavigator::GetRunNumber(), and SetupNavigator::Instance().
00122 { 00123 00124 // Print extra info if we're debugging this module: 00125 if(Debug()){ 00126 cout<<"-----PlotPedestalAndNoise::AfterLastEntry(): I'm debugging!"<<endl; 00127 } 00128 00129 if (fExportSQL) { 00130 // Get the SQLite database file 00131 TSQLiteServer* server = new TSQLiteServer("sqlite://pedestals-and-noises.sqlite"); 00132 00133 std::stringstream query; 00134 std::string tablename = "pedestals_and_noises"; 00135 if (server) { 00136 // Create the pedestals_and_noises table if it doesn't already exist 00137 query << "CREATE TABLE IF NOT EXISTS " << tablename << " (run INT, channel STRING, bank STRING, pedestal FLOAT, noise FLOAT)"; 00138 server->Exec(query.str().c_str()); 00139 query.str(""); // clear the stringstream after use 00140 00141 int run_number = SetupNavigator::Instance()->GetRunNumber(); 00142 00143 // Now loop through the histograms and record the run_numberm channel, bank and mean and RMS of first fNSamples to the SQLite table 00144 for (std::map<std::string, TH2D*>::iterator histIter = fPedestalVsNoiseHistograms.begin(); histIter != fPedestalVsNoiseHistograms.end(); ++histIter) { 00145 std::string detname = histIter->first; 00146 std::string bankname = setup->GetBankName(detname); 00147 TH2D* pedestal_vs_noise_histogram = histIter->second; 00148 00149 double pedestal = pedestal_vs_noise_histogram->GetMean(1); 00150 double noise = pedestal_vs_noise_histogram->GetMean(2); 00151 00152 // See if this row already exists (result will equal 1 if it does) 00153 query << "SELECT COUNT(*) FROM " << tablename << " WHERE run=" << run_number << " AND channel=\'" << detname << "\'"; 00154 TSQLiteResult* result = (TSQLiteResult*) server->Query(query.str().c_str()); // get the result of this query 00155 TSQLiteRow* row = (TSQLiteRow*) result->Next(); // get the first row 00156 query.str(""); // clear the stringstream after use 00157 00158 std::string n_table_entries = row->GetField(0); 00159 00160 if (n_table_entries == "0") { 00161 // insert a new set of values 00162 query << "INSERT INTO " << tablename << " VALUES (" << run_number << ", \"" << detname << "\", \"" << bankname << "\", " << pedestal << ", " << noise << ");"; // insert the values 00163 server->Exec(query.str().c_str()); 00164 query.str(""); // clear the stringstream after use 00165 } 00166 else if (n_table_entries == "1") { 00167 // just update the values that are already there 00168 query << "UPDATE " << tablename << " SET run=" << run_number << ", bank=\'" << bankname << "\', pedestal=" << pedestal << ", noise=" << noise << " WHERE channel=\'" << detname << "\';"; 00169 server->Exec(query.str().c_str()); 00170 query.str(""); // clear the stringstream after use 00171 } 00172 00173 // Need to delete the TSQLiteResult and TSQLiteRow like the ROOT documentation says so 00174 delete result; 00175 delete row; 00176 } 00177 } 00178 else { 00179 std::cout << "Error: Couldn't connect to SQLite database" << std::endl; 00180 } 00181 } 00182 00183 return 0; 00184 }
int PlotPedestalAndNoise::BeforeFirstEntry | ( | TGlobalData * | gData, | |
const TSetupData * | setup | |||
) | [private, virtual] |
Nothing is done before each run.
[in] | gData | See BaseModule::BeforeFirstEntry |
[in] | setup | See BaseModule::BeforeFirstEntry |
Implements BaseModule.
Definition at line 38 of file PlotPedestalAndNoise.cpp.
References BaseModule::Debug().
00038 { 00039 // Print extra info if we're debugging this module: 00040 if(Debug()){ 00041 cout<<"-----PlotPedestalAndNoise::BeforeFirstEntry(): I'm debugging!"<<endl; 00042 } 00043 00044 return 0; 00045 }
bool BaseModule::Debug | ( | ) | const [inline, protected, inherited] |
Check whether this module was asked to print extra debug information
Definition at line 71 of file BaseModule.h.
References BaseModule::fDebug.
Referenced by MakeAnalysedPulses::AddGenerator(), TemplateCreator::AddPulseToTemplate(), ExportPulse::AddToExportList(), TemplateCreator::AfterLastEntry(), PulseCandidateFinder_InvestigateParameters::AfterLastEntry(), PlotTDPs::AfterLastEntry(), AfterLastEntry(), IslandLength::AfterLastEntry(), IslandAmplitude::AfterLastEntry(), MakeMuonEvents::BeforeFirstEntry(), MakeDetectorPulses::BeforeFirstEntry(), TemplateCreator::BeforeFirstEntry(), PulseCandidateFinder_InvestigateParameters::BeforeFirstEntry(), PlotTDPs::BeforeFirstEntry(), BeforeFirstEntry(), IslandLength::BeforeFirstEntry(), IslandAmplitude::BeforeFirstEntry(), PulseViewer::ConsiderDrawing(), MakeAnalysedPulses::MakeAnalysedPulses(), MakeDetectorPulses::MakeGenerator(), ExportPulse::PlotTPI(), MakeDetectorPulses::ProcessEntry(), TemplateCreator::ProcessEntry(), PulseCandidateFinder_InvestigateParameters::ProcessEntry(), MakeAnalysedPulses::ProcessEntry(), and PulseViewer::ProcessEntry().
00071 {return fDebug;};
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 [inline, protected, inherited] |
Get the TDirectory for this module.
Definition at line 74 of file BaseModule.h.
References BaseModule::fDirectory.
Referenced by SavePulses::AfterLastEntry(), and PlotTDPs::BeforeFirstEntry().
00074 {return fDirectory;}
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(), PlotTime::ProcessEntry(), PlotAmplitude::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.
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.
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 PlotPedestalAndNoise::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).
[in] | gData | See BaseModule::ProcessEntry |
[in] | gSetup | See BaseModule::ProcessEntry |
Implements BaseModule.
Definition at line 49 of file PlotPedestalAndNoise.cpp.
References fNSamples, fPedestalVsNoiseHistograms, TGlobalData::fPulseIslandToChannelMap, TSetupData::GetDetectorName(), TSetupData::GetNBits(), and TSetupData::Instance().
00049 { 00050 00051 // Prepare a few variables 00052 std::string bankname, detname; 00053 PulseIslandList thePulseIslands; 00054 StringPulseIslandMap::const_iterator it; 00055 00056 00057 // Loop over each detector 00058 for(it = gData->fPulseIslandToChannelMap.begin(); it != gData->fPulseIslandToChannelMap.end(); ++it){ 00059 00060 // Get the bank and detector names for this detector 00061 bankname = it->first; 00062 detname = setup->GetDetectorName(bankname); 00063 00064 // Get the TPIs 00065 thePulseIslands = it->second; 00066 if (thePulseIslands.size() == 0) continue; // no pulses here.. 00067 00068 // Create the histogram that will store all the average RMS noises from each event 00069 if (fPedestalVsNoiseHistograms.find(detname) == fPedestalVsNoiseHistograms.end()) { 00070 int n_bits = TSetupData::Instance()->GetNBits(bankname); 00071 int x_min = 0; 00072 int x_max = std::pow(2, n_bits); 00073 int n_bins_x = 100; 00074 00075 int y_min = 0; 00076 int y_max = 200; 00077 int n_bins_y = (y_max - y_min)*5; 00078 00079 std::string histname = "fPedestalVsNoiseHistogram_" + detname; 00080 std::stringstream histtitle; 00081 histtitle << "Plot of the Pedestal vs Noise (mean and RMS of first " << fNSamples << " samples) in " << detname; 00082 00083 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); 00084 histogram->GetXaxis()->SetTitle("Pedestal [ADC]"); 00085 histogram->GetYaxis()->SetTitle("Noise [ADC]"); 00086 fPedestalVsNoiseHistograms[detname] = histogram; 00087 } 00088 00089 00090 00091 TH2D* pedestal_vs_noise_histogram = fPedestalVsNoiseHistograms[detname]; 00092 00093 // Loop through all the pulses 00094 for (PulseIslandList::iterator pulseIter = thePulseIslands.begin(); pulseIter != thePulseIslands.end(); ++pulseIter) { 00095 00096 const std::vector<int>& theSamples = (*pulseIter)->GetSamples(); 00097 int limit=fNSamples; 00098 if((int)theSamples.size() < fNSamples) limit=theSamples.size(); 00099 00100 double sum = 0; 00101 for (int iSample = 0; iSample < limit; ++iSample) { 00102 sum += theSamples.at(iSample); 00103 } 00104 double mean = sum / limit; 00105 00106 double sum_of_deviations_squared = 0; 00107 for (int iSample = 0; iSample < limit; ++iSample) { 00108 sum_of_deviations_squared += (theSamples.at(iSample) - mean)*(theSamples.at(iSample) - mean); 00109 } 00110 double RMS = std::sqrt(sum_of_deviations_squared / limit); 00111 00112 pedestal_vs_noise_histogram->Fill(mean, RMS); 00113 } // end loop through pulses 00114 } // end loop through detectors 00115 00116 return 0; 00117 }
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.
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;};
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 97 of file BaseModule.h.
Referenced by BaseModule::BaseModule(), ExportPulse::ExportPulse(), FastSlowCompare::FastSlowCompare(), MakeMuonEvents::MakeMuonEvents(), and PlotAmpVsTDiff::PlotAmpVsTDiff().
bool PlotPedestalAndNoise::fExportSQL [private] |
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 PlotPedestalAndNoise.h.
Referenced by AfterLastEntry(), and PlotPedestalAndNoise().
int PlotPedestalAndNoise::fNSamples [private] |
The number of samples we will look at in the TPulseIsland to calculate the mean and RMS (opt = "n_samples", default = 5).
Definition at line 75 of file PlotPedestalAndNoise.h.
Referenced by PlotPedestalAndNoise(), and ProcessEntry().
std::map<std::string, TH2D*> PlotPedestalAndNoise::fPedestalVsNoiseHistograms [private] |
The map that we store the pedestal vs. noise histograms for each channel.
Definition at line 70 of file PlotPedestalAndNoise.h.
Referenced by AfterLastEntry(), and ProcessEntry().