26     #define ASSERT(f) assert(f)    37     for(
auto ui=0u;ui<hist.size();ui++)
    39         for(
auto uj=0u;uj<hist[ui].size();uj++)
    40             f << hist[ui][uj] << 
"\t";
    49 void zechCorrect(vector<float> &background, vector<float> &observation, 
float alpha,
    50             vector<float> &corrected)
    54     ASSERT(background.size() == observation.size());
    56     corrected=observation;
    57     const float THRESHOLD=550; 
    58     for(
auto i=0u;i<background.size();i++)
    60         if(observation[i] > THRESHOLD || background[i] > THRESHOLD)
    61             corrected[i]=observation[i]-background[i];
    62         else if(!observation[i])
    72                 corrected[i]=estimate;
    74                 corrected[i]=observation[i]-background[i];
    80 int main(
int argc, 
char *argv[]) 
    86         cerr << 
"USAGE : " << argv[0] << 
" SPECTRUM_FILE [alpha1 alpha2 ....] OUTFILE" << endl;
    88         cerr << 
"In the spectrum file, the columns should be ordered as mass, count, background" << endl;
    94     vector<string> headings;
    95     vector<vector<float > > intensityData;
    98     auto errCode=
loadTextData(argv[1],intensityData,headings,
",\t");
   102         cerr << 
"Error loading text file :" << errCode <<endl;
   106     if(!intensityData.size())
   108         cerr << 
"input data appears to be empty" << endl;
   113     alpha.resize(argc-3,-1);
   117         cerr << 
"Alpha not specified, using 0.5 (most probable corretion) " << endl;
   118         alpha.push_back(0.5);
   122         unsigned int OFFSET=2;
   123         for(
auto ui=0u;ui<alpha.size();ui++)
   128                 cerr << 
"Unable to understand specified alpha :" << argv[ui+OFFSET] << endl;
   140     cerr << 
"Loaded :" << intensityData.size() << 
"Rows" << endl;
   143     vector<float> mass,observed,background;
   144     mass.resize(intensityData.size());
   145     observed.resize(intensityData.size());
   146     background.resize(intensityData.size());
   148     for(
auto ui=0;ui<intensityData.size();ui++)
   150         ASSERT(intensityData[ui].size() > 3);
   153         observed[ui] = intensityData[ui][1];
   154         background[ui] = intensityData[ui][3];
   158     vector<vector<float> > corrected;
   159     corrected.resize(alpha.size());
   160     for(
unsigned int ui=0;ui<alpha.size();ui++)
   162         ASSERT(alpha[ui] > 0 && alpha[ui] < 1.0f);
   163         zechCorrect(background,observed,alpha[ui],corrected[ui]);
   169     const char *outFile=argv[argc-1];
   172         cerr << 
"Unable to write output to file" << endl;
   176     cerr << 
"Complete. output written to  :" << outFile << endl;
 void zechCorrect(vector< float > &background, vector< float > &observation, float alpha, vector< float > &corrected)
int main(int argc, char *argv[])
bool zechConfidenceLimits(float lambdaBack, unsigned int observation, float alpha, float &estimate)
Provides a best estimate for true signal when true signal, background. 
void transposeVector(std::vector< std::vector< T > > &v)
Perform an out-of-place tranposition of a given vector. 
unsigned int loadTextData(const char *cpFilename, std::vector< std::vector< float > > &dataVec, std::vector< std::string > &headerVec, const char *delim="\", bool allowNan=true, bool allowConvFails=false, unsigned int headerCount=-1)
Load a CSV, TSV or similar text file. Assumes "C" Locale for input (ie "." as decimal separator)...
bool dumpHistogramToFile(std::vector< std::vector< T > > &hist, const char *filename)
bool stream_cast(T1 &result, const T2 &obj)
Template function to cast and object to another by the stringstream.