| 1 | #include "csv.h"
|
|---|
| 2 |
|
|---|
| 3 | Csv::Csv(TString path, TString fileName)
|
|---|
| 4 | {
|
|---|
| 5 | Csv(path, fileName, "", 0);
|
|---|
| 6 | }
|
|---|
| 7 |
|
|---|
| 8 | Csv::Csv(TString path, TString fileName, int verbLevel)
|
|---|
| 9 | {
|
|---|
| 10 | Csv(path, fileName, "", verbLevel);
|
|---|
| 11 | }
|
|---|
| 12 |
|
|---|
| 13 | Csv::Csv(TString path, TString fileName, TString suffix, int verbLevel)
|
|---|
| 14 | {
|
|---|
| 15 | mDirectory = path;
|
|---|
| 16 | mFilename = fileName;
|
|---|
| 17 | mSuffix = suffix;
|
|---|
| 18 | mVerbLevel = verbLevel;
|
|---|
| 19 |
|
|---|
| 20 | BuildPath();
|
|---|
| 21 | OpenCsv();
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 | Csv::~Csv()
|
|---|
| 25 | {
|
|---|
| 26 | CloseCsv();
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | void
|
|---|
| 30 | Csv::BuildPath()
|
|---|
| 31 | {
|
|---|
| 32 | mPath = mDirectory;
|
|---|
| 33 | mPath.Append(mFilename);
|
|---|
| 34 |
|
|---|
| 35 | if (!mSuffix.IsNull()){
|
|---|
| 36 |
|
|---|
| 37 | if (mSuffix = -1)
|
|---|
| 38 | mSuffix = "AllPixel";
|
|---|
| 39 |
|
|---|
| 40 | mSuffix.Append("_");
|
|---|
| 41 | mPath.Append(mSuffix);
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | mPath.Append(".csv");
|
|---|
| 45 | return;
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | bool
|
|---|
| 49 | Csv::WritePixelToCsv(
|
|---|
| 50 | Pixel* pixel,
|
|---|
| 51 | TString overlayMethod,
|
|---|
| 52 | int order
|
|---|
| 53 | )
|
|---|
| 54 | {
|
|---|
| 55 | if ( !overlayMethod.Contains("Edge") && !overlayMethod.Contains("Maximum") )
|
|---|
| 56 | {
|
|---|
| 57 | cout << endl << "Unknown Overlay Method-->aborting" << endl;
|
|---|
| 58 | return 0;
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | WritePointsetExplain();
|
|---|
| 62 |
|
|---|
| 63 | WritePointSetToCsv(
|
|---|
| 64 | pixel,
|
|---|
| 65 | overlayMethod,
|
|---|
| 66 | order
|
|---|
| 67 | );
|
|---|
| 68 |
|
|---|
| 69 | return 1;
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | void
|
|---|
| 73 | Csv::WritePointSet(
|
|---|
| 74 | Pixel* pixel,
|
|---|
| 75 | TString overlayMethod,
|
|---|
| 76 | int order
|
|---|
| 77 | )
|
|---|
| 78 | {
|
|---|
| 79 | TH1F* Max_histo = NULL;
|
|---|
| 80 | TH1F* Median_histo = NULL;
|
|---|
| 81 | TH1F* Mean_histo = NULL;
|
|---|
| 82 |
|
|---|
| 83 | if (overlayMethod.Contains("Maximum"))
|
|---|
| 84 | {
|
|---|
| 85 | Max_histo = pixel->hPixelMax[order];
|
|---|
| 86 | Median_histo = pixel->hPixelMedian[order];
|
|---|
| 87 | Mean_histo = pixel->hPixelMean[order];
|
|---|
| 88 | }
|
|---|
| 89 | else if (overlayMethod.Contains("Edge"))
|
|---|
| 90 | {
|
|---|
| 91 | Max_histo = pixel->hPixelMax[order];
|
|---|
| 92 | Median_histo = pixel->hPixelMedian[order];
|
|---|
| 93 | Mean_histo = pixel->hPixelMean[order];
|
|---|
| 94 | }
|
|---|
| 95 | else
|
|---|
| 96 | {
|
|---|
| 97 | cout << endl << "Unknown Overlay Method-->aborting" << endl;
|
|---|
| 98 | return 1;
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 | Int_t nbins = Max_histo->GetXaxis()->GetNbins();
|
|---|
| 103 |
|
|---|
| 104 | if (mVerbLevel > 2)
|
|---|
| 105 | {
|
|---|
| 106 | cout << "writing point-set to csv file: " ;
|
|---|
| 107 | cout << mPath << endl;
|
|---|
| 108 | }
|
|---|
| 109 | if (mVerbLevel > 2) cout << "...number of bins " << nbins << endl;
|
|---|
| 110 |
|
|---|
| 111 | //name coulums header
|
|---|
| 112 | mCsvFile << "pixel [CHid]" << ",";
|
|---|
| 113 | mCsvFile << "OverlayPosition" << ",";
|
|---|
| 114 | mCsvFile << "AmplitudeMax [mV]" << ",";
|
|---|
| 115 | mCsvFile << "AmplitudeMean [mV]" << ",";
|
|---|
| 116 | mCsvFile << "AmplitudeMedian [mV]";
|
|---|
| 117 | mCsvFile << endl;
|
|---|
| 118 |
|
|---|
| 119 | //fill coulums
|
|---|
| 120 | for (int TimeSlice=1;TimeSlice<=nbins;TimeSlice++)
|
|---|
| 121 | {
|
|---|
| 122 | mCsvFile << pixel->mChid << "," ;
|
|---|
| 123 | mCsvFile << overlayMethod << "," ;
|
|---|
| 124 | mCsvFile << TimeSlice << "," ;
|
|---|
| 125 | mCsvFile << Max_histo->GetBinContent(TimeSlice) << ",";
|
|---|
| 126 | mCsvFile << Mean_histo->GetBinContent(TimeSlice) << ",";
|
|---|
| 127 | mCsvFile << Median_histo->GetBinContent(TimeSlice) << endl;
|
|---|
| 128 | }
|
|---|
| 129 | return 0;
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
| 132 | void
|
|---|
| 133 | Csv::WritePointSetExplain()
|
|---|
| 134 | {
|
|---|
| 135 | mCsvFile << "### point-set of a single photon pulse template"
|
|---|
| 136 | << endl;
|
|---|
| 137 | << "### Slice's Amplitude determined by calculating the "
|
|---|
| 138 | << endl
|
|---|
| 139 | << "### value of maximum propability of slice -> AmplitudeMax "
|
|---|
| 140 | << endl
|
|---|
| 141 | << "### mean of slice -> AmplitudeMean "
|
|---|
| 142 | << endl
|
|---|
| 143 | << "### median of slice -> AmplitudeMedian "
|
|---|
| 144 | << endl
|
|---|
| 145 | << "### for each slice"
|
|---|
| 146 | << endl
|
|---|
| 147 | << "### " << endl;
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | void
|
|---|
| 151 | Csv::WritePulseAttributes(
|
|---|
| 152 | Pixel* pixel,
|
|---|
| 153 | Pulse* pulse,
|
|---|
| 154 | TString overlayMethod
|
|---|
| 155 | )
|
|---|
| 156 | {
|
|---|
| 157 | //name coulums header
|
|---|
| 158 | mCsvFile << "pixel [CHid]" << ",";
|
|---|
| 159 | mCsvFile << "OverlayPosition" << ",";
|
|---|
| 160 | mCsvFile << "ModelName" << "," ;
|
|---|
| 161 | mCsvFile << "Bsl" << ",";
|
|---|
| 162 | mCsvFile << "Height" << "," ;
|
|---|
| 163 | mCsvFile << "T0" << "," ;
|
|---|
| 164 | mCsvFile << "T1" << "," ;
|
|---|
| 165 | mCsvFile << "Tau1" << "," ;
|
|---|
| 166 | mCsvFile << "Tau2" << "," ;
|
|---|
| 167 | mCsvFile << "Integral" << "," ;
|
|---|
| 168 | mCsvFile << "Amplitude" << "," ;
|
|---|
| 169 | mCsvFile << "PhE" << "," ;
|
|---|
| 170 | mCsvFile << "Type" << "," ;
|
|---|
| 171 | mCsvFile << "FitMin" << "," ;
|
|---|
| 172 | mCsvFile << "FitMax" << "," ;
|
|---|
| 173 | mCsvFile << "FitProb" << "," ;
|
|---|
| 174 | mCsvFile << "FitNCalls" << "," ;
|
|---|
| 175 | mCsvFile << "FitNdf" << "," ;
|
|---|
| 176 | mCsvFile << "Chi2" ;
|
|---|
| 177 | mCsvFile << endl;
|
|---|
| 178 |
|
|---|
| 179 | //fill coulums
|
|---|
| 180 | for (int TimeSlice=1;TimeSlice<=nbins;TimeSlice++)
|
|---|
| 181 | {
|
|---|
| 182 | mCsvFile << pixel->mChid << "," ;
|
|---|
| 183 | mCsvFile << overlayMethod << "," ;
|
|---|
| 184 | mCsvFile << pulse->mName << "," ;
|
|---|
| 185 | mCsvFile << pulse->mBsl << "," ;
|
|---|
| 186 | mCsvFile << pulse->mHeight << "," ;
|
|---|
| 187 | mCsvFile << pulse->mT0 << "," ;
|
|---|
| 188 | mCsvFile << pulse->mT1 << "," ;
|
|---|
| 189 | mCsvFile << pulse->mTau1 << "," ;
|
|---|
| 190 | mCsvFile << pulse->mTau2 << "," ;
|
|---|
| 191 | mCsvFile << pulse->mIntegral << "," ;
|
|---|
| 192 | mCsvFile << pulse->mAmplitude << "," ;
|
|---|
| 193 | mCsvFile << pulse->mPhE << "," ;
|
|---|
| 194 | mCsvFile << pulse->mType << "," ;
|
|---|
| 195 | mCsvFile << pulse->mFitMin << "," ;
|
|---|
| 196 | mCsvFile << pulse->mFitMax << "," ;
|
|---|
| 197 | mCsvFile << pulse->mFitProb << "," ;
|
|---|
| 198 | mCsvFile << pulse->mFitNCalls << "," ;
|
|---|
| 199 | mCsvFile << pulse->mFitNdf << "," ;
|
|---|
| 200 | mCsvFile << pulse->mChi2 << "," ;
|
|---|
| 201 | mCsvFile << endl;
|
|---|
| 202 | }
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 205 | void
|
|---|
| 206 | Csv::OpenCsv(){
|
|---|
| 207 | if (mVerbLevel > 2) cout << "...opening csv file" << endl;
|
|---|
| 208 | mCsvFile.open( mPath );
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 | void
|
|---|
| 212 | Csv::CloseCsv(){
|
|---|
| 213 | mCsvFile.close();
|
|---|
| 214 | if (mVerbLevel > 2) cout << "...csv file closed" << endl;
|
|---|
| 215 | }
|
|---|
| 216 |
|
|---|
| 217 | void
|
|---|
| 218 | Csv::GetFilename(){
|
|---|
| 219 | return mFilename;
|
|---|
| 220 | }
|
|---|
| 221 |
|
|---|
| 222 | void
|
|---|
| 223 | Csv::GetPath(){
|
|---|
| 224 | return mPath;
|
|---|
| 225 | }
|
|---|