| 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 | // ===========================================================================
|
|---|
| 30 | // PRIVATE OPERATIONS
|
|---|
| 31 | // ===========================================================================
|
|---|
| 32 |
|
|---|
| 33 | void
|
|---|
| 34 | Csv::BuildPath()
|
|---|
| 35 | {
|
|---|
| 36 | mPath = mDirectory;
|
|---|
| 37 | mPath.Append(mFilename);
|
|---|
| 38 |
|
|---|
| 39 | if (!mSuffix.IsNull()){
|
|---|
| 40 |
|
|---|
| 41 | if (mSuffix = -1)
|
|---|
| 42 | mSuffix = "AllPixel";
|
|---|
| 43 |
|
|---|
| 44 | mSuffix.Append("_");
|
|---|
| 45 | mPath.Append(mSuffix);
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | mPath.Append(".csv");
|
|---|
| 49 | return;
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | // ===========================================================================
|
|---|
| 53 | // PUBLIC OPERATIONS
|
|---|
| 54 | // ===========================================================================
|
|---|
| 55 |
|
|---|
| 56 | bool
|
|---|
| 57 | Csv::WritePixelToCsv(
|
|---|
| 58 | Pixel* pixel,
|
|---|
| 59 | TString overlayMethod,
|
|---|
| 60 | int order
|
|---|
| 61 | )
|
|---|
| 62 | {
|
|---|
| 63 | if ( !overlayMethod.Contains("Edge") && !overlayMethod.Contains("Maximum") )
|
|---|
| 64 | {
|
|---|
| 65 | cout << endl << "Unknown Overlay Method-->aborting" << endl;
|
|---|
| 66 | return 0;
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | WritePointsetExplain();
|
|---|
| 70 |
|
|---|
| 71 | WritePointSetToCsv(
|
|---|
| 72 | pixel,
|
|---|
| 73 | overlayMethod,
|
|---|
| 74 | order
|
|---|
| 75 | );
|
|---|
| 76 |
|
|---|
| 77 | return 1;
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | void
|
|---|
| 81 | Csv::WritePointSet(
|
|---|
| 82 | Pixel* pixel,
|
|---|
| 83 | TString overlayMethod,
|
|---|
| 84 | int order
|
|---|
| 85 | )
|
|---|
| 86 | {
|
|---|
| 87 | TH1F* Max_histo = NULL;
|
|---|
| 88 | TH1F* Median_histo = NULL;
|
|---|
| 89 | TH1F* Mean_histo = NULL;
|
|---|
| 90 |
|
|---|
| 91 | if (overlayMethod.Contains("Maximum"))
|
|---|
| 92 | {
|
|---|
| 93 | Max_histo = pixel->hPixelMax[order];
|
|---|
| 94 | Median_histo = pixel->hPixelMedian[order];
|
|---|
| 95 | Mean_histo = pixel->hPixelMean[order];
|
|---|
| 96 | }
|
|---|
| 97 | else if (overlayMethod.Contains("Edge"))
|
|---|
| 98 | {
|
|---|
| 99 | Max_histo = pixel->hPixelMax[order];
|
|---|
| 100 | Median_histo = pixel->hPixelMedian[order];
|
|---|
| 101 | Mean_histo = pixel->hPixelMean[order];
|
|---|
| 102 | }
|
|---|
| 103 | else
|
|---|
| 104 | {
|
|---|
| 105 | cout << endl << "Unknown Overlay Method-->aborting" << endl;
|
|---|
| 106 | return 1;
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 | Int_t nbins = Max_histo->GetXaxis()->GetNbins();
|
|---|
| 111 |
|
|---|
| 112 | if (mVerbLevel > 2)
|
|---|
| 113 | {
|
|---|
| 114 | cout << "writing point-set to csv file: " ;
|
|---|
| 115 | cout << mPath << endl;
|
|---|
| 116 | }
|
|---|
| 117 | if (mVerbLevel > 2) cout << "...number of bins " << nbins << endl;
|
|---|
| 118 |
|
|---|
| 119 | //name coulums header
|
|---|
| 120 | mCsvFile << "pixel [CHid]" << ",";
|
|---|
| 121 | mCsvFile << "OverlayPosition" << ",";
|
|---|
| 122 | mCsvFile << "AmplitudeMax [mV]" << ",";
|
|---|
| 123 | mCsvFile << "AmplitudeMean [mV]" << ",";
|
|---|
| 124 | mCsvFile << "AmplitudeMedian [mV]";
|
|---|
| 125 | mCsvFile << endl;
|
|---|
| 126 |
|
|---|
| 127 | //fill coulums
|
|---|
| 128 | for (int TimeSlice=1;TimeSlice<=nbins;TimeSlice++)
|
|---|
| 129 | {
|
|---|
| 130 | mCsvFile << pixel->mChid << "," ;
|
|---|
| 131 | mCsvFile << overlayMethod << "," ;
|
|---|
| 132 | mCsvFile << TimeSlice << "," ;
|
|---|
| 133 | mCsvFile << Max_histo->GetBinContent(TimeSlice) << ",";
|
|---|
| 134 | mCsvFile << Mean_histo->GetBinContent(TimeSlice) << ",";
|
|---|
| 135 | mCsvFile << Median_histo->GetBinContent(TimeSlice) << endl;
|
|---|
| 136 | }
|
|---|
| 137 | return 0;
|
|---|
| 138 | }
|
|---|
| 139 |
|
|---|
| 140 | void
|
|---|
| 141 | Csv::WritePointSetExplain()
|
|---|
| 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 | << "### " << endl;
|
|---|
| 156 | }
|
|---|
| 157 |
|
|---|
| 158 | void
|
|---|
| 159 | Csv::WritePulseAttributes(
|
|---|
| 160 | Pixel* pixel,
|
|---|
| 161 | Pulse* pulse,
|
|---|
| 162 | TString overlayMethod
|
|---|
| 163 | )
|
|---|
| 164 | {
|
|---|
| 165 | //name coulums header
|
|---|
| 166 | mCsvFile << "pixel [CHid]" << ",";
|
|---|
| 167 | mCsvFile << "OverlayPosition" << ",";
|
|---|
| 168 | mCsvFile << "ModelName" << "," ;
|
|---|
| 169 | mCsvFile << "Bsl" << ",";
|
|---|
| 170 | mCsvFile << "Height" << "," ;
|
|---|
| 171 | mCsvFile << "T0" << "," ;
|
|---|
| 172 | mCsvFile << "T1" << "," ;
|
|---|
| 173 | mCsvFile << "Tau1" << "," ;
|
|---|
| 174 | mCsvFile << "Tau2" << "," ;
|
|---|
| 175 | mCsvFile << "Integral" << "," ;
|
|---|
| 176 | mCsvFile << "Amplitude" << "," ;
|
|---|
| 177 | mCsvFile << "PhE" << "," ;
|
|---|
| 178 | mCsvFile << "Type" << "," ;
|
|---|
| 179 | mCsvFile << "FitProb" << "," ;
|
|---|
| 180 | mCsvFile << "FitNCalls" << "," ;
|
|---|
| 181 | mCsvFile << "FitNdf" << "," ;
|
|---|
| 182 | mCsvFile << "Chi2" ;
|
|---|
| 183 | mCsvFile << endl;
|
|---|
| 184 |
|
|---|
| 185 | //fill coulums
|
|---|
| 186 | for (int TimeSlice=1;TimeSlice<=nbins;TimeSlice++)
|
|---|
| 187 | {
|
|---|
| 188 | mCsvFile << pixel->mChid << "," ;
|
|---|
| 189 | mCsvFile << overlayMethod << "," ;
|
|---|
| 190 | mCsvFile << pulse->GetName() << "," ;
|
|---|
| 191 | mCsvFile << pulse->GetBsl() << "," ;
|
|---|
| 192 | mCsvFile << pulse->GetHeight() << "," ;
|
|---|
| 193 | mCsvFile << pulse->GetT0() << "," ;
|
|---|
| 194 | mCsvFile << pulse->GetT1() << "," ;
|
|---|
| 195 | mCsvFile << pulse->GetTau1() << "," ;
|
|---|
| 196 | mCsvFile << pulse->GetTau2() << "," ;
|
|---|
| 197 | mCsvFile << pulse->GetIntegral() << "," ;
|
|---|
| 198 | mCsvFile << pulse->GetAmplitude() << "," ;
|
|---|
| 199 | mCsvFile << pulse->GetPhE() << "," ;
|
|---|
| 200 | mCsvFile << pulse->GetType() << "," ;
|
|---|
| 201 | mCsvFile << pulse->GetFitProb() << "," ;
|
|---|
| 202 | mCsvFile << pulse->GetFitNCalls() << "," ;
|
|---|
| 203 | mCsvFile << pulse->GetFitNdf() << "," ;
|
|---|
| 204 | mCsvFile << pulse->GetChi2() << "," ;
|
|---|
| 205 | mCsvFile << endl;
|
|---|
| 206 | }
|
|---|
| 207 | }
|
|---|
| 208 |
|
|---|
| 209 | void
|
|---|
| 210 | Csv::OpenCsv(){
|
|---|
| 211 | if (mVerbLevel > 2) cout << "...opening csv file" << endl;
|
|---|
| 212 | mCsvFile.open( mPath );
|
|---|
| 213 | }
|
|---|
| 214 |
|
|---|
| 215 | void
|
|---|
| 216 | Csv::CloseCsv(){
|
|---|
| 217 | mCsvFile.close();
|
|---|
| 218 | if (mVerbLevel > 2) cout << "...csv file closed" << endl;
|
|---|
| 219 | }
|
|---|
| 220 |
|
|---|
| 221 | // ===========================================================================
|
|---|
| 222 | // ACCESS
|
|---|
| 223 | // ===========================================================================
|
|---|
| 224 |
|
|---|
| 225 | void
|
|---|
| 226 | Csv::GetFilename(){
|
|---|
| 227 | return mFilename;
|
|---|
| 228 | }
|
|---|
| 229 |
|
|---|
| 230 | void
|
|---|
| 231 | Csv::GetPath(){
|
|---|
| 232 | return mPath;
|
|---|
| 233 | }
|
|---|