PulseCandidateFinder Class Reference
[Modules]

Utility class to find pulse candidates on a TPulseIsland. More...

#include <PulseCandidateFinder.h>

List of all members.

Classes

struct  Location
 Location is a struct containing the start and stop location (in terms of sample number) of a candidate pulse. More...

Public Member Functions

 PulseCandidateFinder (std::string detname, modules::options *opts)
 The constructor.
 PulseCandidateFinder ()
 Default constructor, make sure to set the channel name with SetChannel if you use this constructor.
 ~PulseCandidateFinder ()
 Empty destructor.
void SetChannel (const std::string &detname)
void SetSigma (double sigma)
void FindPulseCandidates (const TPulseIsland *pulse)
 Find the pulse candidates on the given TPulseIsland.
int GetNPulseCandidates ()
 Returns the number of pulse candidates that were found.
void GetPulseCandidates (std::vector< TPulseIsland * > &) const
 Returns the actual TPulseIsland of each candidate.
void FillParameterHistogram (TH2D *histogram)
 Takes a histogram and fills it with the parameters (both sample height above pedestals and sample differences between consecutive samples).

Private Member Functions

void FindCandidatePulses_Fast (int rise)
 The algorithm for finding fast pulses.
void FindCandidatePulses_Slow (int threshold)
 The algorithm for finding slow pulses.
void SetDefaultParameterValues ()
 Called in the constructor if fDefaultParameterValues is empty, so that it can be filled.
bool CheckDigitiserOverflow ()
 Check if the pulse is overflowed.

Private Attributes

const TPulseIslandfPulseIsland
 The TPulseIsland that we are looking for candidates on.
std::vector< LocationfPulseCandidateLocations
 The vector that we store the pulse candidate locations in.
IDs::channel fChannel
 The channel that this PulseCandidateFinder works on.
double fParameterValue
 The value of the parameter to start a candidate pulse.
double fNoise
 The noise value for this channel.
double fPedestal
 The pedestal value for this channel.
int fNSigma
 The number of sigma (i.e. noise) that we want the threshold to be set to.

Static Private Attributes

static std::map< IDs::channel,
int > 
fDefaultParameterValues
 The map that stores the default parameter values in case there isn't one specified in the modules file.

Detailed Description

Utility class to find pulse candidates on a TPulseIsland.

Author:
Andrew Edmonds

This utility class stores the location of candidate pulses of a TPulseIsland. These candidate pulses can be retrieved later by the calling module.

Note that there are two algorithms used to find candidate pulses. For slow pulses, we simply look for when a sample has gone above a certain threshold and for fast pulses, we look to see if there's a sudden rise in sample value between consecutive pulses.

The final thing this class does is to fill a given histogram with the relevant parameters (either sample height or sample difference). This ability is used by the PulseCandidateFinder_InvestigateParameters module

Definition at line 29 of file PulseCandidateFinder.h.


Constructor & Destructor Documentation

PulseCandidateFinder::PulseCandidateFinder ( std::string  detname,
modules::options opts 
)

The constructor.

The constructor just sets all the parameter values.

The constructor looks in the opts for any changes to the defailt parameter, "n_sigma" and "debug"

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

Definition at line 37 of file PulseCandidateFinder.cpp.

References fChannel, fDefaultParameterValues, fParameterValue, modules::options::GetDouble(), modules::options::GetFlag(), modules::options::GetInt(), modules::options::HasOption(), SetChannel(), SetDefaultParameterValues(), and SetSigma().

00037                                                                                   {
00038 
00039   // make sure we have default values
00040   if (fDefaultParameterValues.empty()) {
00041     SetDefaultParameterValues();
00042   }
00043 
00044   SetChannel(detname);
00045 
00046   // Check options to set the values cut
00047   if(opts->HasOption("n_sigma")){
00048      SetSigma( opts->GetInt("n_sigma"));
00049   } else if(opts->HasOption(detname+"_param")){
00050     fParameterValue = opts->GetDouble(detname+"_param"); 
00051   }
00052   
00053   // print debugging statements
00054   if (opts->GetFlag("debug")){
00055     std::cout << "Parameter Value for " << fChannel 
00056               << " PulseCandidateFinder is " 
00057               << fParameterValue << std::endl; // would be nice to know which module this is for
00058   }
00059 }

PulseCandidateFinder::PulseCandidateFinder (  ) 

Default constructor, make sure to set the channel name with SetChannel if you use this constructor.

The constructor just sets all the parameter values.

Definition at line 22 of file PulseCandidateFinder.cpp.

References fDefaultParameterValues, and SetDefaultParameterValues().

00022                                           :
00023     fChannel(IDs::kErrorDetector),
00024     fParameterValue(definitions::DefaultValue),
00025     fNoise(definitions::DefaultValue),
00026     fPedestal(definitions::DefaultValue),
00027     fNSigma(definitions::DefaultValue){
00028 
00029   // make sure we have default values
00030   if (fDefaultParameterValues.empty()) {
00031     SetDefaultParameterValues();
00032   }
00033 
00034 }

PulseCandidateFinder::~PulseCandidateFinder (  ) 

Empty destructor.

Definition at line 113 of file PulseCandidateFinder.cpp.

00113                                             {
00114 }


Member Function Documentation

bool PulseCandidateFinder::CheckDigitiserOverflow (  )  [private]

Check if the pulse is overflowed.

Checks each sample and if the value is equal to the maximum ADC value then we've overflowed the digitiser and can ignore this pulse

Definition at line 345 of file PulseCandidateFinder.cpp.

References fPulseIsland, TPulseIsland::GetBankName(), TSetupData::GetNBits(), TPulseIsland::GetSamples(), and TSetupData::Instance().

00345                                                   {
00346   const std::vector<int>& samples = fPulseIsland->GetSamples();
00347   unsigned int n_samples = samples.size();
00348 
00349   std::string bankname = fPulseIsland->GetBankName();
00350   int n_bits = TSetupData::Instance()->GetNBits(bankname);
00351   double max_adc_value = std::pow(2, n_bits);
00352   bool overflowed = false;
00353 
00354   // Loop through the samples
00355   for (unsigned int i = 0; i < n_samples; ++i) {
00356     if (samples[i] >= max_adc_value) {
00357       overflowed = true;
00358       break;
00359     }
00360   }
00361 
00362   return overflowed;
00363 }

void PulseCandidateFinder::FillParameterHistogram ( TH2D *  histogram  ) 

Takes a histogram and fills it with the parameters (both sample height above pedestals and sample differences between consecutive samples).

FillParameterHistogram Fills the given histogram with the relevant parameter based on the channel

Definition at line 269 of file PulseCandidateFinder.cpp.

References fPedestal, fPulseIsland, TPulseIsland::GetBankName(), TSetupData::GetDetectorName(), SetupNavigator::GetRunNumber(), TPulseIsland::GetSamples(), TPulseIsland::GetTriggerPolarity(), SetupNavigator::Instance(), and TSetupData::Instance().

Referenced by PulseCandidateFinder_InvestigateParameters::ProcessEntry().

00269                                                                  {
00270 
00271   std::string detname = TSetupData::Instance()->GetDetectorName(fPulseIsland->GetBankName());
00272   IDs::channel theChannel = detname;
00273 
00274   // Get some information from the TPI
00275   const std::vector<int>& samples = fPulseIsland->GetSamples();
00276   unsigned int n_samples = samples.size();
00277   int polarity = fPulseIsland->GetTriggerPolarity();
00278 
00279   int s1, s2, ds; // this sample value, the previous sample value and the change in the sample value
00280 
00281   // Loop through the samples and plot the 2D plot
00282   for (unsigned int i = 1; i < n_samples; ++i) {
00283     s1 = polarity * (samples[i-1] - fPedestal);
00284     s2 = polarity * (samples[i] - fPedestal);
00285     ds = s2 - s1;
00286 
00287     histogram->Fill(ds, s1);
00288   }
00289 
00290   std::stringstream histtitle;
00291   histtitle << "Plot of sample differences vs sample heights for " << detname << " for Run " << SetupNavigator::Instance()->GetRunNumber();
00292   histogram->SetTitle(histtitle.str().c_str());
00293   histogram->GetYaxis()->SetTitle("Sample Heights");
00294   histogram->GetXaxis()->SetTitle("Sample Differences");
00295 }

void PulseCandidateFinder::FindCandidatePulses_Fast ( int  rise  )  [private]

The algorithm for finding fast pulses.

Check the difference between consecutive samples and if it's above a certain value then it's that start of a candidate pulse. The end of the candidate pulse is when the samples go below pedestal

FindCandidatePulses_Fast Finds pulse candidates on fast pulse islands by looking for a sudden rise between consecutive samples

Definition at line 156 of file PulseCandidateFinder.cpp.

References fNoise, fPedestal, fPulseCandidateLocations, fPulseIsland, TPulseIsland::GetBankName(), TPulseIsland::GetSamples(), TPulseIsland::GetTriggerPolarity(), PulseCandidateFinder::Location::start, and PulseCandidateFinder::Location::stop.

Referenced by FindPulseCandidates().

00156                                                             {
00157 
00158   const std::vector<int>& samples = fPulseIsland->GetSamples();
00159   unsigned int n_samples = samples.size();
00160 
00161   std::string bankname = fPulseIsland->GetBankName();
00162   int polarity = fPulseIsland->GetTriggerPolarity();
00163 
00164   int s1, s2, ds; // this sample value, the previous sample value and the change in the sample value
00165   bool found = false;
00166   Location location;
00167 
00168   // Loop through the samples
00169   int n_before_start_samples = 2; // take a few samples from before the official start
00170   for (unsigned int i = 1; i < n_samples; ++i) {
00171     s1 = polarity * (samples[i-1] - fPedestal);
00172     s2 = polarity * (samples[i] - fPedestal);
00173     ds = s2 - s1;
00174 
00175     if (found) {
00176 
00177       if (s2 < fNoise) { // stop if the sample goes below pedestal
00178         location.stop = (int)i;
00179         if (location.stop >= (int)samples.size()) {
00180           location.stop = samples.size() - 1;
00181         }
00182 
00183         fPulseCandidateLocations.push_back(location);
00184         found = false;
00185       }
00186       else if (i == n_samples-1) { // Also stop if we are at the last sample (only do this check if we failed the above one)
00187         location.stop = (int) i;
00188 
00189         fPulseCandidateLocations.push_back(location);
00190         found = false;
00191       }
00192     } else {
00193       if (ds > rise) {
00194         found = true;
00195         location.start = (int)(i - 1) - n_before_start_samples;
00196 
00197         if (location.start < 0) {
00198           location.start = 0;
00199         }
00200       }
00201     }
00202   }
00203 }

void PulseCandidateFinder::FindCandidatePulses_Slow ( int  threshold  )  [private]

The algorithm for finding slow pulses.

Check the height above pedestal of each sample and if it's above a certain value then it's that start of a candidate pulse. The end of the candidate pulse is when the samples go below pedestal

FindCandidatePulses_Slow Finds pulse candidates on slow pulse islands by seeing if a sample goes above a threshold

Definition at line 207 of file PulseCandidateFinder.cpp.

References fNoise, fPedestal, fPulseCandidateLocations, fPulseIsland, TPulseIsland::GetBankName(), TPulseIsland::GetSamples(), TPulseIsland::GetTriggerPolarity(), PulseCandidateFinder::Location::start, and PulseCandidateFinder::Location::stop.

Referenced by FindPulseCandidates().

00207                                                                  {
00208 
00209   const std::vector<int>& samples = fPulseIsland->GetSamples();
00210   unsigned int n_samples = samples.size();
00211 
00212   std::string bankname = fPulseIsland->GetBankName();
00213   int polarity = fPulseIsland->GetTriggerPolarity();
00214 
00215   int sample_height; // the sample's height above pedestal
00216   int start, stop; // the start and stop location
00217   bool found = false;
00218   Location location;
00219 
00220   // Loop through the samples
00221   for (unsigned int i = 0; i < n_samples; ++i) {
00222     sample_height = polarity * (samples[i] - fPedestal);
00223 
00224     if (found) {
00225       if (sample_height < fNoise) { // stop if the sample goes below pedestal
00226         location.stop = (int)i;
00227         if (location.stop >=(int) samples.size()) {
00228           location.stop = samples.size() - 1;
00229         }
00230 
00231         start = stop = 0;
00232         fPulseCandidateLocations.push_back(location);
00233         found = false;
00234       }
00235       else if (i == n_samples-1) { // Also stop if we are at the last sample (only do this check if we failed the above one)
00236         location.stop = (int) i;
00237 
00238         fPulseCandidateLocations.push_back(location);
00239         found = false;
00240       }
00241     } else {
00242       if (sample_height > threshold) {
00243         found = true;
00244 
00245         // Track back until we get to the pedestal again so that we get the whole pulse (Ge-S pulses were being cut-off at the start)
00246         location.start = (int)(i);
00247         for (int j = i; j > 0; --j) {
00248 
00249           sample_height = polarity * (samples[j] - fPedestal);
00250           if (sample_height <= 0) {
00251             location.start = (int)(j);
00252             break;
00253           }
00254           else if (j == 1) { // if we are at the last iteration
00255             location.start = 0; // set the location to the start since we haven't gone below pedestal again
00256           }
00257         }
00258         if (location.start < 0) {
00259           location.start = 0;
00260         }
00261       }
00262     }
00263   }
00264 }

void PulseCandidateFinder::FindPulseCandidates ( const TPulseIsland pulse  ) 

Find the pulse candidates on the given TPulseIsland.

FindPulseCandidates() Finds the pulse candidates on the given TPulseIsland

Definition at line 75 of file PulseCandidateFinder.cpp.

References IDs::channel::Detector(), fChannel, FindCandidatePulses_Fast(), FindCandidatePulses_Slow(), fNSigma, fParameterValue, fPulseCandidateLocations, fPulseIsland, IDs::channel::isFast(), IDs::channel::isSlow(), IDs::channel::isValid(), and IDs::kGe.

Referenced by FirstCompleteAPGenerator::MakeTAPsWithPCF(), ExportPulse::PlotTPI(), and PulseCandidateFinder_InvestigateParameters::ProcessEntry().

00075                                                                         {
00076     if(!fChannel.isValid()){
00077         std::cout<<"Channel for PCF is not set, make sure to use "
00078                    "SetChannel() if you used the defualt constructor"<<std::endl;
00079         throw Except::UnspecifiedChannel();
00080     }
00081 
00082   // Clear the vector of pulse candidate locations first since it will still contain them from previous pulses
00083   fPulseCandidateLocations.clear();
00084 
00085   fPulseIsland = pulse;
00086 
00087   // Check if this pulse overflowed the digitiser
00088   //  if (!CheckDigitiserOverflow()) {
00089     // If we are using the "n_sigma" option, then all channels should use the slow pulse algorithm
00090     if (fNSigma != 0) {
00091       FindCandidatePulses_Slow(fParameterValue);
00092     }
00093     else { // We have a different algorithm for fast and slow pulses
00094       if (fChannel.isFast()) {
00095         if (fChannel.Detector() != IDs::kGe) {
00096           FindCandidatePulses_Slow(fParameterValue); // use the slow algorithm for the fast silicon pulses because of the noisy pedestal
00097         }
00098         else {
00099           FindCandidatePulses_Fast(fParameterValue);
00100         }
00101       }
00102       else if (fChannel.isSlow()) {
00103         FindCandidatePulses_Slow(fParameterValue);
00104       }
00105       else {
00106         // this is a scintillator so do the fast pulse analysis
00107         FindCandidatePulses_Fast(fParameterValue);
00108       }
00109     }
00110     //  }
00111 }

int PulseCandidateFinder::GetNPulseCandidates (  )  [inline]

Returns the number of pulse candidates that were found.

Definition at line 76 of file PulseCandidateFinder.h.

References fPulseCandidateLocations.

Referenced by PulseCandidateFinder_InvestigateParameters::ProcessEntry().

00076 { return fPulseCandidateLocations.size(); }

void PulseCandidateFinder::GetPulseCandidates ( std::vector< TPulseIsland * > &  pulse_candidates  )  const

Returns the actual TPulseIsland of each candidate.

GetPulseCandidates() Fills a vector of the TPulseIslands of the pulse candidates that have been found

Definition at line 118 of file PulseCandidateFinder.cpp.

References fPulseCandidateLocations, fPulseIsland, TPulseIsland::GetBankName(), TPulseIsland::GetSamples(), TPulseIsland::GetTimeStamp(), TPulseIsland::SetBankName(), TPulseIsland::SetSamples(), and TPulseIsland::SetTimeStamp().

Referenced by FirstCompleteAPGenerator::MakeTAPsWithPCF(), and ExportPulse::PlotTPI().

00118                                                                                              {
00119 
00120   // Loop through the pulse candidate locations
00121   std::vector<int>::const_iterator start_new, stop_new;
00122   for (std::vector<Location>::const_iterator locationIter = fPulseCandidateLocations.begin();
00123           locationIter != fPulseCandidateLocations.end(); ++locationIter) {
00124     
00125     // Get iterator to the start locations
00126     start_new=fPulseIsland->GetSamples().begin();
00127     std::advance(start_new,locationIter->start);
00128 
00129     // Get iterator to the stop locations
00130     stop_new=fPulseIsland->GetSamples().begin();
00131     std::advance(stop_new,locationIter->stop);
00132 
00133     // Get the bank name and work out what the new timestamp will be
00134     std::string bankname = fPulseIsland->GetBankName();
00135     int new_timestamp = fPulseIsland->GetTimeStamp() + locationIter->start;
00136 
00137     // Make the new TPI
00138     int index=locationIter-fPulseCandidateLocations.begin();
00139     if((int)pulse_candidates.size() <= index || !pulse_candidates.at(index)){
00140         TPulseIsland* pulse_island = new TPulseIsland(new_timestamp, start_new, stop_new, bankname);
00141         pulse_candidates.push_back(pulse_island);
00142     }else{
00143         TPulseIsland* pulse_island=pulse_candidates.at(index);
00144         pulse_island->SetSamples(start_new,stop_new);
00145         pulse_island->SetTimeStamp(new_timestamp);
00146         pulse_island->SetBankName(bankname);
00147     }
00148   }
00149   for(unsigned int i=fPulseCandidateLocations.size();i< pulse_candidates.size();++i){
00150       pulse_candidates.at(i)->Reset();
00151   }
00152 }

void PulseCandidateFinder::SetChannel ( const std::string &  detname  ) 
void PulseCandidateFinder::SetDefaultParameterValues (  )  [private]

Called in the constructor if fDefaultParameterValues is empty, so that it can be filled.

SetDefaultParameterValues Sets the default parameter values

Definition at line 302 of file PulseCandidateFinder.cpp.

References fDefaultParameterValues.

Referenced by PulseCandidateFinder().

00302                                                      {
00303 
00304   // Set all the default values for the fast channels
00305   fDefaultParameterValues[IDs::channel("muSc")] = 230;
00306   fDefaultParameterValues[IDs::channel("muScA")] = 100;
00307   fDefaultParameterValues[IDs::channel("NDet")] = 100;
00308   fDefaultParameterValues[IDs::channel("NDet2")] = 100;
00309 
00310   fDefaultParameterValues[IDs::channel("Ge-F")] = 40;
00311 
00312   fDefaultParameterValues[IDs::channel("ScL")] = 100;
00313   fDefaultParameterValues[IDs::channel("ScR")] = 100;
00314   fDefaultParameterValues[IDs::channel("ScGe")] = 20;
00315   fDefaultParameterValues[IDs::channel("ScVe")] = 100;
00316 
00317   fDefaultParameterValues[IDs::channel("SiL2-F")] = 300;
00318   fDefaultParameterValues[IDs::channel("SiL1-1-F")] = 130;
00319   fDefaultParameterValues[IDs::channel("SiL1-2-F")] = 500;
00320   fDefaultParameterValues[IDs::channel("SiL1-3-F")] = 135;
00321   fDefaultParameterValues[IDs::channel("SiL1-4-F")] = 140;
00322 
00323   fDefaultParameterValues[IDs::channel("SiR2-F")] = 300;
00324   fDefaultParameterValues[IDs::channel("SiR1-1-F")] = 135;
00325   fDefaultParameterValues[IDs::channel("SiR1-2-F")] = 140;
00326   fDefaultParameterValues[IDs::channel("SiR1-3-F")] = 140;
00327   fDefaultParameterValues[IDs::channel("SiR1-4-F")] = 150;
00328 
00329   // Set all the default values for the slow parameters
00330   fDefaultParameterValues[IDs::channel("Ge-S")] = 500;
00331 
00332   fDefaultParameterValues[IDs::channel("SiL2-S")] = 100;
00333   fDefaultParameterValues[IDs::channel("SiL1-1-S")] = 50;
00334   fDefaultParameterValues[IDs::channel("SiL1-2-S")] = 80;
00335   fDefaultParameterValues[IDs::channel("SiL1-3-S")] = 120;
00336   fDefaultParameterValues[IDs::channel("SiL1-4-S")] = 80;
00337 
00338   fDefaultParameterValues[IDs::channel("SiR2-S")] = 100;
00339   fDefaultParameterValues[IDs::channel("SiR1-1-S")] = 50;
00340   fDefaultParameterValues[IDs::channel("SiR1-2-S")] = 65;
00341   fDefaultParameterValues[IDs::channel("SiR1-3-S")] = 65;
00342   fDefaultParameterValues[IDs::channel("SiR1-4-S")] = 62;
00343 }

void PulseCandidateFinder::SetSigma ( double  sigma  ) 

Definition at line 61 of file PulseCandidateFinder.cpp.

References fNoise, fNSigma, and fParameterValue.

Referenced by PulseCandidateFinder().

00061                                                 {
00062     fNSigma=sigma;
00063     fParameterValue=fNSigma*fNoise;
00064 }


Member Data Documentation

The channel that this PulseCandidateFinder works on.

Definition at line 110 of file PulseCandidateFinder.h.

Referenced by FindPulseCandidates(), PulseCandidateFinder(), and SetChannel().

std::map< IDs::channel, int > PulseCandidateFinder::fDefaultParameterValues [static, private]

The map that stores the default parameter values in case there isn't one specified in the modules file.

Need to declare this outside of any method.

Definition at line 123 of file PulseCandidateFinder.h.

Referenced by PulseCandidateFinder(), SetChannel(), and SetDefaultParameterValues().

double PulseCandidateFinder::fNoise [private]

The noise value for this channel.

Definition at line 116 of file PulseCandidateFinder.h.

Referenced by FindCandidatePulses_Fast(), FindCandidatePulses_Slow(), SetChannel(), and SetSigma().

The number of sigma (i.e. noise) that we want the threshold to be set to.

Definition at line 130 of file PulseCandidateFinder.h.

Referenced by FindPulseCandidates(), and SetSigma().

The value of the parameter to start a candidate pulse.

Definition at line 113 of file PulseCandidateFinder.h.

Referenced by FindPulseCandidates(), PulseCandidateFinder(), SetChannel(), and SetSigma().

The pedestal value for this channel.

Definition at line 119 of file PulseCandidateFinder.h.

Referenced by FillParameterHistogram(), FindCandidatePulses_Fast(), FindCandidatePulses_Slow(), and SetChannel().

The vector that we store the pulse candidate locations in.

Definition at line 67 of file PulseCandidateFinder.h.

Referenced by FindCandidatePulses_Fast(), FindCandidatePulses_Slow(), FindPulseCandidates(), GetNPulseCandidates(), and GetPulseCandidates().


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

Generated on 15 Jun 2016 for AlcapDAQ by  doxygen 1.6.1