PowerSpectrum.hh

Go to the documentation of this file.
00001 
00009 #ifndef __POWER_SPECTRUM_HH_
00010 #define __POWER_SPECTRUM_HH_
00011 
00012 
00013 #include <iostream>
00014 #include <iomanip>
00015 #include "rdTXOclass_2.h"
00016 #include <TH1F.h>
00017 #include <TString.h>
00018 
00019 
00020 #define MAXCHANNELS 2048
00021 using namespace std; 
00022 
00023 class PowerSpectrum {
00024   protected: 
00025 
00026     Int_t fNChannels; // Number of channels = number of spectra
00027     Int_t fNPts; // Number of digitized points per spectrum 
00028 
00029     Float_t * fGains; // Array with the detectors' Gains
00030     Float_t fSamplingInterval; // Sampling interval in seconds
00031     Float_t fADCScale; // ADC scale in Volts/ channelADC
00032 
00033 
00034     Float_t fNyquist; // Nyquist frequency for fSamplingInterval
00035     Float_t fDeltaFreq; // delta frequency = fNyquist / (fNPts/2)
00036 
00037     // Histrogram array with the power spectrum of every channel
00038     TH1F ** fPS;
00039 
00040     // Histrogram array with the full power spectrum of every channel (512 bins)
00041     TH1F ** fPSfull;
00042 
00043     // Histrogram array with the pulses of every channel
00044     TH1F ** fPulses;
00045 
00046     // Array with the integral values
00047     Float_t * fIntegral; 
00048 
00049     // Name of the spectrum
00050     TString fName; // File name
00051 
00052     // Measurement number 
00053     Int_t fMeasNumber;
00054 
00055     // Header file name (with path)
00056     TString fHeaderFile;
00057 
00058     // Auxiliar variables
00059     Float_t fAdcChannels; // ADC number of channels
00060     Float_t fFini; // Initial and final frequencies for integral computations
00061     Float_t fFend; 
00062 
00064     // METHODS
00066   public:
00067 
00068     // Default constructor
00069     PowerSpectrum(); 
00070 
00071     //  constructor with configuration file (for the gains)
00072     PowerSpectrum(char * gainFile); 
00073 
00074     //  constructor with number of files 
00075     //  Reserve memory for nf PS
00076     PowerSpectrum(Int_t nf); 
00077     
00078     // Default copy constructor 
00079     PowerSpectrum (const PowerSpectrum & ps);
00080 
00081     // Destructor
00082     virtual ~PowerSpectrum();
00083 
00084     // Set default values
00085     void Initialize(); 
00086  
00087     // Read Gains from Electronic configuration file
00088     Int_t ReadGainsFromConfFile (char * confFile);
00089 
00090     // Read gains from a text file with the structure
00091     // ch gain
00092     // ...
00093     // where ch is the channel number starting from 1
00094     Int_t ReadGainsFromDataFile (char * inFile);
00095  
00096     // Read config parameters from header file
00097     Int_t ReadHeaderFile (char * headFile);
00098  
00099     // Read Power Spectrum from Tasso file 
00100     // Return <0 on error
00101     Int_t ReadTassoPS(char * inputFile);
00102 
00103     // Read pulses from Tasso file and compute PS
00104     // Return <0 on error
00105     Int_t ReadTassoPulses (char * inputFile);
00106 
00107     // Read Power Spectrum from ROOT file 
00108     // Return <0 on error
00109     Int_t ReadROOTPS(char * inputFile);
00110 
00111     // Read pulses from ROOT file and compute PS
00112     // Return <0 on error
00113     Int_t ReadROOTPulses (char * inputFile);
00114 
00115     // Compute PS from the pulses stored if fPulses
00116     Int_t ComputePowerSpectrum();
00117  
00118     // Integrate Power Spectrum between fini and fend
00119     // And save the result int fIntegral array
00120     // By default, integrate between fFini and fFend
00121     // (If they are not set with SetFini, SetFend, it takes fDeltaFreq and fNyquist)
00122     void Integral (Float_t fini = -1, Float_t fend=-1);
00123 
00124     // Integrate Power Spectrum between fini and fend
00125     // and return an histogram with the integral for every channel
00126     // (Starting from 1)
00127     // (The memory for the histogram is reserved here, the user is 
00128     // responsible to delete it)
00129     TH1F * GetHistoIntegral (char * histoName, Float_t fini = -1, Float_t fend= -1);
00130 
00132     // Get methods
00134 
00135     inline TH1F ** GetPS() {return fPS;}
00136     inline TH1F ** GetPSfull() {return fPSfull;}
00137 
00138     // Return histogram with power spectrum of channel i
00139     // Starting from 0
00140     inline TH1F * GetPS (Int_t i) 
00141     {if (i<fNChannels) {if (fPS) return fPS[i]; cout << "Error: Power Spectrum not initialized yet" << endl; return 0;} ; cout << "Error: channel " << i << " out of range " << endl;return 0;} 
00142   
00143     inline TH1F * GetPSfull (Int_t i) 
00144     {if (i<fNChannels) {if (fPSfull) return fPSfull[i]; cout << "Error: Power Spectrum not initialized yet" << endl; return 0;} ; cout << "Error: channel " << i << " out of range " << endl;return 0;} 
00145 
00146     inline TH1F ** GetPulses() {return fPulses;} 
00147     // Return histogram with pulse of channel i
00148     // Starting from 0
00149     inline TH1F * GetPulse (Int_t i) 
00150       {if (i<fNChannels) {if (fPulses) return fPulses[i]; cout << "Error: Pulses not initialized yet" << endl; return 0;} ; cout << "Error: channel " << i << " out of range " << endl; return 0;} 
00151 
00152     inline Int_t GetNChannels () {return fNChannels;}
00153     inline Int_t GetNPts () {return fNPts;}
00154 
00155     // return sampling interval in milliseconds
00156     inline Float_t GetSamplingInterval () {return fSamplingInterval*1e3;}
00157 
00158     // return ADC scale value in mv/ADC channel
00159     inline Float_t GetADCScale () {return fADCScale*1e3;} 
00160 
00161     inline Float_t GetGain(Int_t i) {if (i<fNChannels) {if (fGains) return fGains[i]; cout << "Error: Gains not initialized yet" << endl; return 0;};  cout << "Error: File " << fName.Data() << " channel " << i << " out of range " << endl;return 0;}
00162     inline Float_t GetIntegral(Int_t i) {if (fIntegral && i<fNChannels) return fIntegral[i]; cout << "Error: File " << fName.Data() << " channel " << i << " not integrated yet" << endl; return 0;}
00163     inline Float_t * GetIntegral() {return fIntegral; }
00164     inline Float_t GetNyquist() {return fNyquist;}
00165     inline Float_t GetFini () {return fFini;}; // Get Ffini (in Hz)
00166     inline Float_t GetFend () {return fFend;}; // Get Ffend (in Hz)
00167     inline const char * GetName () {return (fName.Data());}; // Get fName
00168     inline Int_t GetMeasNumber() {return fMeasNumber;}; // Get fMeasNumber
00169 
00171     // Set methods
00173     // Set power spectrum of channel i from TH1F histogram
00174     inline Int_t SetPS (Int_t i, TH1F * histo) 
00175       {if (i<fNChannels && i>=0) {fPS[i]=histo; return 0;} cout << "Error: channel " << i << " out of range " << endl;return 0;} 
00176 
00177     inline Int_t SetPSfull (Int_t i, TH1F * histo) 
00178       {if (i<fNChannels && i>=0) {fPSfull[i]=histo; return 0;} cout << "Error: channel " << i << " out of range " << endl;return 0;}
00179 
00180     // Set pulse of channel i from TH1F histogram
00181     inline Int_t SetPulse (Int_t i, TH1F * histo) 
00182       {if (i<fNChannels && i>=0) {fPulses[i]=histo; return 0;} ; cout << "Error: channel " << i << " out of range " << endl; return 0;} 
00183 
00184 
00185     inline void SetSamplingInterval (Float_t s) // s in milliseconds 
00186       {fSamplingInterval = s*1e-3; fNyquist = 0.5/fSamplingInterval;} 
00187     inline void SetNPts (Int_t npts) {fNPts=npts; fDeltaFreq=fNyquist/(fNPts/2); if (fNyquist==0) cout << "Warning: Set sampling interval first" << endl;}
00188     inline void SetADCScale (Float_t s)  // s in mV/ADC channel
00189       {fADCScale = s*1e-3;} 
00190 
00191     inline void SetFini (Float_t f) {fFini = f;}; // Set Ffini (in Hz)
00192     inline void SetFend (Float_t f) {fFend = f;}; // Set Ffend (in Hz)
00193     inline void SetMeasNumber(Int_t no) {fMeasNumber = no;}; // Set fMeasNumber
00194     inline void SetName(char * name) {fName = name;}; // Set fName
00195     inline void SetNChannels (Int_t nch) {fNChannels=nch;}
00196     
00197 
00198 
00199   private:
00200 
00201 };
00202 
00203 #endif

Generated on Tue Nov 16 10:49:58 2010 for CUORE Software by  doxygen 1.5.6