source: fact/tools/rootmacros/PulseTemplates/csv.C

Last change on this file was 14752, checked in by Jens Buss, 12 years ago
bugfix: ampl and intergral error not yet implemented but writte to csv
  • Property svn:executable set to *
File size: 7.9 KB
Line 
1#include "csv.h"
2
3Csv::Csv(TString path, TString fileName)
4{
5 Csv(path, fileName, "", 0);
6}
7
8Csv::Csv(TString path, TString fileName, int verbLevel)
9{
10 Csv(path, fileName, "", verbLevel);
11}
12
13Csv::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
25Csv::~Csv()
26{
27 CloseCsv();
28}
29
30// ===========================================================================
31// PRIVATE OPERATIONS
32// ===========================================================================
33
34void
35Csv::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
57bool
58Csv::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
81void
82Csv::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
140void
141Csv::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 << "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
170void
171Csv::WritePulseAttributesHeader()
172{
173 //name coulums header
174 mCsvFile << "CHid" << mSeparator;
175 mCsvFile << "OverlayPosition" << mSeparator;
176 mCsvFile << "ModelName" << mSeparator ;
177 mCsvFile << "Order" << mSeparator ;
178 mCsvFile << "Type" << mSeparator ;
179 mCsvFile << "Bsl" << mSeparator;
180 mCsvFile << "BslErr" << mSeparator;
181 mCsvFile << "Height" << mSeparator ;
182 mCsvFile << "HeightErr" << mSeparator ;
183 mCsvFile << "T0" << mSeparator ;
184 mCsvFile << "T0Err" << mSeparator ;
185 mCsvFile << "T1" << mSeparator ;
186 mCsvFile << "T1Err" << mSeparator ;
187 mCsvFile << "Tau1" << mSeparator ;
188 mCsvFile << "Tau1Err" << mSeparator ;
189 mCsvFile << "Tau2" << mSeparator ;
190 mCsvFile << "Tau2Err" << mSeparator ;
191 mCsvFile << "Integral" << mSeparator ;
192// mCsvFile << "IntegralErr" << mSeparator ;
193 mCsvFile << "Amplitude" << mSeparator ;
194// mCsvFile << "AmplitudeErr" << mSeparator ;
195 mCsvFile << "Phe" << mSeparator ;
196 mCsvFile << "PheErr" << mSeparator ;
197 mCsvFile << "FitProb" << mSeparator ;
198 mCsvFile << "FitNCalls" << mSeparator ;
199 mCsvFile << "FitNdf" << mSeparator ;
200 mCsvFile << "Chi2" ;
201 mCsvFile << endl;
202}
203void
204Csv::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(0);
216 mCsvFile << order << mSeparator ;
217 mCsvFile.precision(2);
218 mCsvFile << pulse->GetType() << mSeparator ;
219 mCsvFile.precision(12);
220 mCsvFile << pulse->GetBsl() << mSeparator ;
221 mCsvFile << pulse->GetBslErr() << mSeparator ;
222 mCsvFile << pulse->GetHeight() << mSeparator ;
223 mCsvFile << pulse->GetHeightErr() << mSeparator ;
224 mCsvFile.precision(12);
225 mCsvFile << pulse->GetT0() << mSeparator ;
226 mCsvFile << pulse->GetT0Err() << mSeparator ;
227 mCsvFile << pulse->GetT1() << mSeparator ;
228 mCsvFile << pulse->GetT1Err() << mSeparator ;
229 mCsvFile << pulse->GetTau1() << mSeparator ;
230 mCsvFile << pulse->GetTau1Err() << mSeparator ;
231 mCsvFile << pulse->GetTau2() << mSeparator ;
232 mCsvFile << pulse->GetTau2Err() << mSeparator ;
233 mCsvFile.precision(8);
234 mCsvFile << pulse->GetIntegral() << mSeparator ;
235 mCsvFile << pulse->GetAmplitude() << mSeparator ;
236 mCsvFile.precision(2);
237 mCsvFile << pulse->GetPhE() << mSeparator ;
238 mCsvFile.precision(24);
239 mCsvFile << pulse->GetPhEErr() << mSeparator ;
240 mCsvFile.precision(8);
241 mCsvFile << pulse->GetFitProb() << mSeparator ;
242 mCsvFile.precision(12);
243 mCsvFile << pulse->GetFitNCalls() << mSeparator ;
244 mCsvFile << pulse->GetFitNdf() << mSeparator ;
245 mCsvFile << pulse->GetChi2() << mSeparator ;
246 mCsvFile << endl;
247 mCsvFile.precision(mPrecision);
248}
249
250void
251Csv::OpenCsv(){
252 if (mVerbLevel > 2) cout << "...opening csv file" << endl;
253 mCsvFile.open( mPath );
254 mPrecision = mCsvFile.precision();
255}
256
257void
258Csv::CloseCsv(){
259 mCsvFile.close();
260 if (mVerbLevel > 2) cout << "...csv file closed" << endl;
261}
262
263// ===========================================================================
264// ACCESS
265// ===========================================================================
266
267TString
268Csv::GetFilename(){
269 return mFilename;
270}
271
272TString
273Csv::GetPath(){
274 return mPath;
275}
Note: See TracBrowser for help on using the repository browser.