| 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 | mSeparator = ";";
|
|---|
| 20 |
|
|---|
| 21 | BuildPath();
|
|---|
| 22 | OpenCsv();
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | Csv::~Csv()
|
|---|
| 26 | {
|
|---|
| 27 | CloseCsv();
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | // ===========================================================================
|
|---|
| 31 | // PRIVATE OPERATIONS
|
|---|
| 32 | // ===========================================================================
|
|---|
| 33 |
|
|---|
| 34 | void
|
|---|
| 35 | Csv::BuildPath()
|
|---|
| 36 | {
|
|---|
| 37 | mPath = mDirectory;
|
|---|
| 38 | mPath.Append(mFilename);
|
|---|
| 39 |
|
|---|
| 40 | if (!mSuffix.IsNull()){
|
|---|
| 41 |
|
|---|
| 42 | if (mSuffix.Contains("-1"))
|
|---|
| 43 | mSuffix = "AllPixel";
|
|---|
| 44 |
|
|---|
| 45 | mSuffix.Prepend("_");
|
|---|
| 46 | mPath.Append(mSuffix);
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | mPath.Append(".csv");
|
|---|
| 50 | return;
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | // ===========================================================================
|
|---|
| 54 | // PUBLIC OPERATIONS
|
|---|
| 55 | // ===========================================================================
|
|---|
| 56 |
|
|---|
| 57 | bool
|
|---|
| 58 | Csv::WritePointSetToCsv(
|
|---|
| 59 | Pixel* pixel,
|
|---|
| 60 | TString overlayMethod,
|
|---|
| 61 | int order
|
|---|
| 62 | )
|
|---|
| 63 | {
|
|---|
| 64 | if ( !overlayMethod.Contains("Edge") && !overlayMethod.Contains("Maximum") )
|
|---|
| 65 | {
|
|---|
| 66 | cout << endl << "Unknown Overlay Method-->aborting" << endl;
|
|---|
| 67 | return 0;
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | WritePointSetHeader();
|
|---|
| 71 |
|
|---|
| 72 | WritePointSet(
|
|---|
| 73 | pixel,
|
|---|
| 74 | overlayMethod,
|
|---|
| 75 | order
|
|---|
| 76 | );
|
|---|
| 77 |
|
|---|
| 78 | return 1;
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | void
|
|---|
| 82 | Csv::WritePointSet(
|
|---|
| 83 | Pixel* pixel,
|
|---|
| 84 | TString overlayMethod,
|
|---|
| 85 | int order
|
|---|
| 86 | )
|
|---|
| 87 | {
|
|---|
| 88 | TH1F* Max_histo = NULL;
|
|---|
| 89 | TH1F* Median_histo = NULL;
|
|---|
| 90 | TH1F* Mean_histo = NULL;
|
|---|
| 91 | int overlayPos = 0;
|
|---|
| 92 |
|
|---|
| 93 | if (overlayMethod.Contains("Maximum"))
|
|---|
| 94 | {
|
|---|
| 95 | Max_histo = pixel->hPixelMax[order];
|
|---|
| 96 | Median_histo = pixel->hPixelMedian[order];
|
|---|
| 97 | Mean_histo = pixel->hPixelMean[order];
|
|---|
| 98 | overlayPos = 1;
|
|---|
| 99 | }
|
|---|
| 100 | else if (overlayMethod.Contains("Edge"))
|
|---|
| 101 | {
|
|---|
| 102 | Max_histo = pixel->hPixelMax[order];
|
|---|
| 103 | Median_histo = pixel->hPixelMedian[order];
|
|---|
| 104 | Mean_histo = pixel->hPixelMean[order];
|
|---|
| 105 | overlayPos = 2;
|
|---|
| 106 | }
|
|---|
| 107 | else
|
|---|
| 108 | {
|
|---|
| 109 | cout << endl << "Unknown Overlay Method-->aborting" << endl;
|
|---|
| 110 | return ;
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 | Int_t nbins = Max_histo->GetXaxis()->GetNbins();
|
|---|
| 115 |
|
|---|
| 116 | if (mVerbLevel > 2)
|
|---|
| 117 | {
|
|---|
| 118 | cout << "writing point-set to csv file: " ;
|
|---|
| 119 | cout << mPath << endl;
|
|---|
| 120 | }
|
|---|
| 121 | if (mVerbLevel > 2) cout << "...number of bins " << nbins << endl;
|
|---|
| 122 |
|
|---|
| 123 | //fill coulums
|
|---|
| 124 | for (int TimeSlice=1;TimeSlice<=nbins;TimeSlice++)
|
|---|
| 125 | {
|
|---|
| 126 | mCsvFile << TimeSlice << mSeparator ;
|
|---|
| 127 | mCsvFile << pixel->mChid << mSeparator ;
|
|---|
| 128 | mCsvFile << order << mSeparator ;
|
|---|
| 129 | mCsvFile << overlayPos << mSeparator ;
|
|---|
| 130 | mCsvFile.precision(8);
|
|---|
| 131 | mCsvFile << Max_histo->GetBinContent(TimeSlice) << mSeparator;
|
|---|
| 132 | mCsvFile << Mean_histo->GetBinContent(TimeSlice) << mSeparator;
|
|---|
| 133 | mCsvFile << Median_histo->GetBinContent(TimeSlice) << endl;
|
|---|
| 134 | mCsvFile.precision(mPrecision);
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | return ;
|
|---|
| 138 | }
|
|---|
| 139 |
|
|---|
| 140 | void
|
|---|
| 141 | Csv::WritePointSetHeader()
|
|---|
| 142 | {
|
|---|
| 143 | mCsvFile << "### point-set of a single photon pulse template"
|
|---|
| 144 | << endl
|
|---|
| 145 | << "### Slice's Amplitude determined by calculating the "
|
|---|
| 146 | << endl
|
|---|
| 147 | << "### value of maximum propability of slice -> AmplitudeMax "
|
|---|
| 148 | << endl
|
|---|
| 149 | << "### mean of slice -> AmplitudeMean "
|
|---|
| 150 | << endl
|
|---|
| 151 | << "### median of slice -> AmplitudeMedian "
|
|---|
| 152 | << endl
|
|---|
| 153 | << "### for each slice"
|
|---|
| 154 | << endl
|
|---|
| 155 | << "### "
|
|---|
| 156 | << endl
|
|---|
| 157 | << "### OverlayMethods (1) at Maximum, (2) at rising Edge" << endl;
|
|---|
| 158 |
|
|---|
| 159 | //name coulums header
|
|---|
| 160 | mCsvFile << "TimeSlice [a.u.]" << mSeparator;
|
|---|
| 161 | mCsvFile << "pixel [CHid]" << mSeparator;
|
|---|
| 162 | mCsvFile << "Pulseorder [PhE]" << mSeparator;
|
|---|
| 163 | mCsvFile << "OverlayPosition" << mSeparator;
|
|---|
| 164 | mCsvFile << "AmplitudeMax [mV]" << mSeparator;
|
|---|
| 165 | mCsvFile << "AmplitudeMean [mV]" << mSeparator;
|
|---|
| 166 | mCsvFile << "AmplitudeMedian [mV]";
|
|---|
| 167 | mCsvFile << endl;
|
|---|
| 168 | }
|
|---|
| 169 |
|
|---|
| 170 | void
|
|---|
| 171 | Csv::WritePulseAttributesHeader()
|
|---|
| 172 | {
|
|---|
| 173 | //name coulums header
|
|---|
| 174 | mCsvFile << "pixel [CHid]" << mSeparator;
|
|---|
| 175 | mCsvFile << "OverlayPosition" << mSeparator;
|
|---|
| 176 | mCsvFile << "ModelName" << mSeparator ;
|
|---|
| 177 | mCsvFile << "Bsl" << mSeparator;
|
|---|
| 178 | mCsvFile << "BslErr" << mSeparator;
|
|---|
| 179 | mCsvFile << "Height" << mSeparator ;
|
|---|
| 180 | mCsvFile << "HeightErr" << mSeparator ;
|
|---|
| 181 | mCsvFile << "T0" << mSeparator ;
|
|---|
| 182 | mCsvFile << "T0Err" << mSeparator ;
|
|---|
| 183 | mCsvFile << "T1" << mSeparator ;
|
|---|
| 184 | mCsvFile << "T1Err" << mSeparator ;
|
|---|
| 185 | mCsvFile << "Tau1" << mSeparator ;
|
|---|
| 186 | mCsvFile << "Tau1Err" << mSeparator ;
|
|---|
| 187 | mCsvFile << "Tau2" << mSeparator ;
|
|---|
| 188 | mCsvFile << "Tau2Err" << mSeparator ;
|
|---|
| 189 | mCsvFile << "Integral" << mSeparator ;
|
|---|
| 190 | mCsvFile << "IntegralErr" << mSeparator ;
|
|---|
| 191 | mCsvFile << "Amplitude" << mSeparator ;
|
|---|
| 192 | mCsvFile << "AmplitudeErr" << mSeparator ;
|
|---|
| 193 | mCsvFile << "Phe" << mSeparator ;
|
|---|
| 194 | mCsvFile << "PheErr" << mSeparator ;
|
|---|
| 195 | mCsvFile << "Order" << mSeparator ;
|
|---|
| 196 | mCsvFile << "Type" << mSeparator ;
|
|---|
| 197 | mCsvFile << "FitProb" << mSeparator ;
|
|---|
| 198 | mCsvFile << "FitNCalls" << mSeparator ;
|
|---|
| 199 | mCsvFile << "FitNdf" << mSeparator ;
|
|---|
| 200 | mCsvFile << "Chi2" ;
|
|---|
| 201 | mCsvFile << endl;
|
|---|
| 202 | }
|
|---|
| 203 | void
|
|---|
| 204 | Csv::WritePulseAttributes(
|
|---|
| 205 | Pixel* pixel,
|
|---|
| 206 | Pulse* pulse,
|
|---|
| 207 | TString overlayMethod,
|
|---|
| 208 | int order
|
|---|
| 209 | )
|
|---|
| 210 | {
|
|---|
| 211 | //fill coulums
|
|---|
| 212 | mCsvFile << pixel->mChid << mSeparator ;
|
|---|
| 213 | mCsvFile << overlayMethod << mSeparator ;
|
|---|
| 214 | mCsvFile << pulse->GetName() << mSeparator ;
|
|---|
| 215 | mCsvFile.precision(12);
|
|---|
| 216 | mCsvFile << pulse->GetBsl() << mSeparator ;
|
|---|
| 217 | mCsvFile << pulse->GetBslErr() << mSeparator ;
|
|---|
| 218 | mCsvFile << pulse->GetHeight() << mSeparator ;
|
|---|
| 219 | mCsvFile << pulse->GetHeightErr() << mSeparator ;
|
|---|
| 220 | mCsvFile.precision(12);
|
|---|
| 221 | mCsvFile << pulse->GetT0() << mSeparator ;
|
|---|
| 222 | mCsvFile << pulse->GetT0Err() << mSeparator ;
|
|---|
| 223 | mCsvFile << pulse->GetT1() << mSeparator ;
|
|---|
| 224 | mCsvFile << pulse->GetT1Err() << mSeparator ;
|
|---|
| 225 | mCsvFile << pulse->GetTau1() << mSeparator ;
|
|---|
| 226 | mCsvFile << pulse->GetTau1Err() << mSeparator ;
|
|---|
| 227 | mCsvFile << pulse->GetTau2() << mSeparator ;
|
|---|
| 228 | mCsvFile << pulse->GetTau2Err() << mSeparator ;
|
|---|
| 229 | mCsvFile.precision(8);
|
|---|
| 230 | mCsvFile << pulse->GetIntegral() << mSeparator ;
|
|---|
| 231 | mCsvFile << pulse->GetAmplitude() << mSeparator ;
|
|---|
| 232 | mCsvFile.precision(2);
|
|---|
| 233 | mCsvFile << pulse->GetPhE() << mSeparator ;
|
|---|
| 234 | mCsvFile << pulse->GetPhEErr() << mSeparator ;
|
|---|
| 235 | mCsvFile << order << mSeparator ;
|
|---|
| 236 | mCsvFile << pulse->GetType() << mSeparator ;
|
|---|
| 237 | mCsvFile << pulse->GetFitProb() << mSeparator ;
|
|---|
| 238 | mCsvFile.precision(12);
|
|---|
| 239 | mCsvFile << pulse->GetFitNCalls() << mSeparator ;
|
|---|
| 240 | mCsvFile << pulse->GetFitNdf() << mSeparator ;
|
|---|
| 241 | mCsvFile << pulse->GetChi2() << mSeparator ;
|
|---|
| 242 | mCsvFile << endl;
|
|---|
| 243 | mCsvFile.precision(mPrecision);
|
|---|
| 244 | }
|
|---|
| 245 |
|
|---|
| 246 | void
|
|---|
| 247 | Csv::OpenCsv(){
|
|---|
| 248 | if (mVerbLevel > 2) cout << "...opening csv file" << endl;
|
|---|
| 249 | mCsvFile.open( mPath );
|
|---|
| 250 | mPrecision = mCsvFile.precision();
|
|---|
| 251 | }
|
|---|
| 252 |
|
|---|
| 253 | void
|
|---|
| 254 | Csv::CloseCsv(){
|
|---|
| 255 | mCsvFile.close();
|
|---|
| 256 | if (mVerbLevel > 2) cout << "...csv file closed" << endl;
|
|---|
| 257 | }
|
|---|
| 258 |
|
|---|
| 259 | // ===========================================================================
|
|---|
| 260 | // ACCESS
|
|---|
| 261 | // ===========================================================================
|
|---|
| 262 |
|
|---|
| 263 | TString
|
|---|
| 264 | Csv::GetFilename(){
|
|---|
| 265 | return mFilename;
|
|---|
| 266 | }
|
|---|
| 267 |
|
|---|
| 268 | TString
|
|---|
| 269 | Csv::GetPath(){
|
|---|
| 270 | return mPath;
|
|---|
| 271 | }
|
|---|