]>
Commit | Line | Data |
---|---|---|
39bcd65d | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
16 | ||
7d855b04 | 17 | /// \class AliTPCCalibViewer |
18 | /// | |
19 | /// Class for viewing/visualizing TPC calibration data | |
20 | /// base on TTree functionality for visualization | |
21 | /// | |
22 | /// Create a list of AliTPCCalPads, arrange them in an TObjArray. | |
23 | /// Pass this TObjArray to MakeTree and create the calibration Tree | |
24 | /// While craating this tree some statistical information are calculated | |
25 | /// Open the viewer with this Tree: AliTPCCalibViewer v("CalibTree.root") | |
26 | /// Have fun! | |
27 | /// EasyDraw("CETmean~-CETmean_mean", "A", "(CETmean~-CETmean_mean)>0") | |
28 | /// | |
29 | /// If you like to click, we recommand you the | |
30 | /// AliTPCCalibViewerGUI | |
31 | /// | |
32 | /// THE DOCUMENTATION IS STILL NOT COMPLETED !!!! | |
33 | /// | |
34 | /// ROOT includes | |
2811495d | 35 | |
4f3934a1 | 36 | #include <fstream> |
2811495d | 37 | #include <iostream> |
38 | ||
39 | #include <TFile.h> | |
40 | #include <TFriendElement.h> | |
41 | #include <TGraph.h> | |
42 | #include <TKey.h> | |
43 | #include <TPad.h> | |
44 | //#include <TCanvas.h> | |
7d855b04 | 45 | #include <TH1.h> |
39bcd65d | 46 | #include <TH1F.h> |
2811495d | 47 | #include <TLegend.h> |
48 | #include <TLine.h> | |
49 | #include <TMath.h> | |
39bcd65d | 50 | #include <TObjString.h> |
2811495d | 51 | //#include <TROOT.h> |
52 | #include <TRandom.h> | |
53 | #include <TString.h> | |
54 | #include <TStyle.h> | |
55 | #include <TTreeStream.h> | |
39bcd65d | 56 | |
2811495d | 57 | #include "AliTPCCalibCE.h" |
58 | #include "AliMathBase.h" | |
59 | #include "AliTPCCalPad.h" | |
60 | #include "AliTPCCalROC.h" | |
61 | #include "AliTPCCalibPedestal.h" | |
62 | #include "AliTPCCalibPulser.h" | |
39bcd65d | 63 | |
64 | // | |
65 | // AliRoot includes | |
66 | // | |
67 | #include "AliTPCCalibViewer.h" | |
68 | ||
a11596ad | 69 | using std::ifstream; |
7d855b04 | 70 | /// \cond CLASSIMP |
39bcd65d | 71 | ClassImp(AliTPCCalibViewer) |
7d855b04 | 72 | /// \endcond |
39bcd65d | 73 | |
832bb12c | 74 | |
39bcd65d | 75 | AliTPCCalibViewer::AliTPCCalibViewer() |
76 | :TObject(), | |
77 | fTree(0), | |
78 | fFile(0), | |
a6d2bd0c | 79 | fListOfObjectsToBeDeleted(0), |
7d855b04 | 80 | fTreeMustBeDeleted(0), |
81 | fAbbreviation(0), | |
832bb12c | 82 | fAppendString(0) |
39bcd65d | 83 | { |
84 | // | |
85 | // Default constructor | |
86 | // | |
87 | ||
88 | } | |
89 | ||
90 | //_____________________________________________________________________________ | |
91 | AliTPCCalibViewer::AliTPCCalibViewer(const AliTPCCalibViewer &c) | |
92 | :TObject(c), | |
93 | fTree(0), | |
94 | fFile(0), | |
a6d2bd0c | 95 | fListOfObjectsToBeDeleted(0), |
832bb12c | 96 | fTreeMustBeDeleted(0), |
7d855b04 | 97 | fAbbreviation(0), |
832bb12c | 98 | fAppendString(0) |
39bcd65d | 99 | { |
7d855b04 | 100 | /// dummy AliTPCCalibViewer copy constructor |
101 | /// not yet working!!! | |
102 | ||
39bcd65d | 103 | fTree = c.fTree; |
a6d2bd0c | 104 | fTreeMustBeDeleted = c.fTreeMustBeDeleted; |
39bcd65d | 105 | //fFile = new TFile(*(c.fFile)); |
106 | fListOfObjectsToBeDeleted = c.fListOfObjectsToBeDeleted; | |
832bb12c | 107 | fAbbreviation = c.fAbbreviation; |
108 | fAppendString = c.fAppendString; | |
39bcd65d | 109 | } |
110 | ||
111 | //_____________________________________________________________________________ | |
2811495d | 112 | AliTPCCalibViewer::AliTPCCalibViewer(TTree *const tree) |
39bcd65d | 113 | :TObject(), |
114 | fTree(0), | |
115 | fFile(0), | |
a6d2bd0c | 116 | fListOfObjectsToBeDeleted(0), |
832bb12c | 117 | fTreeMustBeDeleted(0), |
7d855b04 | 118 | fAbbreviation(0), |
832bb12c | 119 | fAppendString(0) |
39bcd65d | 120 | { |
7d855b04 | 121 | /// Constructor that initializes the calibration viewer |
122 | ||
39bcd65d | 123 | fTree = tree; |
a6d2bd0c | 124 | fTreeMustBeDeleted = kFALSE; |
39bcd65d | 125 | fListOfObjectsToBeDeleted = new TObjArray(); |
832bb12c | 126 | fAbbreviation = "~"; |
127 | fAppendString = ".fElements"; | |
39bcd65d | 128 | } |
129 | ||
130 | //_____________________________________________________________________________ | |
a6e0ebfe | 131 | AliTPCCalibViewer::AliTPCCalibViewer(const char* fileName, const char* treeName) |
39bcd65d | 132 | :TObject(), |
133 | fTree(0), | |
134 | fFile(0), | |
a6d2bd0c | 135 | fListOfObjectsToBeDeleted(0), |
832bb12c | 136 | fTreeMustBeDeleted(0), |
7d855b04 | 137 | fAbbreviation(0), |
832bb12c | 138 | fAppendString(0) |
7d855b04 | 139 | |
39bcd65d | 140 | { |
7d855b04 | 141 | /// Constructor to initialize the calibration viewer |
142 | /// the file 'fileName' contains the tree 'treeName' | |
143 | ||
39bcd65d | 144 | fFile = new TFile(fileName, "read"); |
145 | fTree = (TTree*) fFile->Get(treeName); | |
a6d2bd0c | 146 | fTreeMustBeDeleted = kTRUE; |
39bcd65d | 147 | fListOfObjectsToBeDeleted = new TObjArray(); |
832bb12c | 148 | fAbbreviation = "~"; |
149 | fAppendString = ".fElements"; | |
39bcd65d | 150 | } |
7d855b04 | 151 | |
39bcd65d | 152 | //____________________________________________________________________________ |
153 | AliTPCCalibViewer & AliTPCCalibViewer::operator =(const AliTPCCalibViewer & param) | |
154 | { | |
7d855b04 | 155 | /// assignment operator - dummy |
156 | /// not yet working!!! | |
157 | ||
04420071 | 158 | if (this == ¶m) return (*this); |
159 | ||
39bcd65d | 160 | fTree = param.fTree; |
a6d2bd0c | 161 | fTreeMustBeDeleted = param.fTreeMustBeDeleted; |
39bcd65d | 162 | //fFile = new TFile(*(param.fFile)); |
163 | fListOfObjectsToBeDeleted = param.fListOfObjectsToBeDeleted; | |
832bb12c | 164 | fAbbreviation = param.fAbbreviation; |
165 | fAppendString = param.fAppendString; | |
39bcd65d | 166 | return (*this); |
167 | } | |
168 | ||
169 | //_____________________________________________________________________________ | |
170 | AliTPCCalibViewer::~AliTPCCalibViewer() | |
171 | { | |
7d855b04 | 172 | /// AliTPCCalibViewer destructor |
173 | /// all objects will be deleted, the file will be closed, the pictures will disappear | |
174 | ||
a6d2bd0c | 175 | if (fTree && fTreeMustBeDeleted) { |
176 | fTree->SetCacheSize(0); | |
177 | fTree->Delete(); | |
178 | //delete fTree; | |
179 | } | |
39bcd65d | 180 | if (fFile) { |
181 | fFile->Close(); | |
182 | fFile = 0; | |
183 | } | |
184 | ||
185 | for (Int_t i = fListOfObjectsToBeDeleted->GetEntriesFast()-1; i >= 0; i--) { | |
186 | //cout << "Index " << i << " trying to delete the following object: " << fListOfObjectsToBeDeleted->At(i)->GetName() << "..."<< endl; | |
187 | delete fListOfObjectsToBeDeleted->At(i); | |
188 | } | |
189 | delete fListOfObjectsToBeDeleted; | |
190 | } | |
191 | ||
a6d2bd0c | 192 | //_____________________________________________________________________________ |
2773a273 | 193 | void AliTPCCalibViewer::Delete(Option_t* /*option*/) { |
7d855b04 | 194 | /// Should be called from AliTPCCalibViewerGUI class only. |
195 | /// If you use Delete() do not call the destructor. | |
196 | /// All objects (except those contained in fListOfObjectsToBeDeleted) will be deleted, the file will be closed. | |
197 | ||
a6d2bd0c | 198 | if (fTree && fTreeMustBeDeleted) { |
199 | fTree->SetCacheSize(0); | |
200 | fTree->Delete(); | |
201 | } | |
2773a273 | 202 | delete fFile; |
a6d2bd0c | 203 | delete fListOfObjectsToBeDeleted; |
204 | } | |
205 | ||
8192627b | 206 | |
7d855b04 | 207 | const char* AliTPCCalibViewer::AddAbbreviations(const Char_t *c, Bool_t printDrawCommand){ |
208 | /// Replace all "<variable>" with "<variable><fAbbreviation>" (Adds forgotten "~") | |
209 | /// but take care on the statistical information, like "CEQmean_Mean" | |
210 | /// and also take care on correct given variables, like "CEQmean~" | |
211 | /// | |
212 | /// For each variable out of "listOfVariables": | |
213 | /// - 'Save' correct items: | |
214 | /// - form <replaceString>, take <variable>'s first char, add <removeString>, add rest of <variable>, e.g. "C!#EQmean" (<removeString> = "!#") | |
215 | /// - For each statistical information in "listOfNormalizationVariables": | |
216 | /// - ReplaceAll <variable><statistical_Information> with <replaceString><statistical_Information> | |
217 | /// - ReplaceAll <variable><abbreviation> with <replaceString><abbreviation>, e.g. "CEQmean~" -> "C!#EQmean~" | |
218 | /// - ReplaceAll <variable><appendStr> with <replaceString><appendStr>, e.g. "CEQmean.fElements" -> "C!#EQmean.fElements" | |
219 | /// | |
220 | /// - Do actual replacing: | |
221 | /// - ReplaceAll <variable> with <variable><fAbbreviation>, e.g. "CEQmean" -> "CEQmean~" | |
222 | /// | |
223 | /// - Undo saving: | |
224 | /// - For each statistical information in "listOfNormalizationVariables": | |
225 | /// - ReplaceAll <replaceString><statistical_Information> with <variable><statistical_Information> | |
226 | /// - ReplaceAll <replaceString><abbreviation> with <variable><abbreviation>, e.g. "C!#EQmean~" -> "CEQmean~" | |
227 | /// - ReplaceAll <replaceString><appendStr> with <variable><appendStr>, e.g. "C!#EQmean.fElements" -> "CEQmean.fElements" | |
228 | /// | |
229 | /// Now all the missing "~" should be added. | |
230 | ||
8192627b | 231 | TString str(c); |
232 | TString removeString = "!#"; // very unpropable combination of chars | |
233 | TString replaceString = ""; | |
234 | TString searchString = ""; | |
235 | TString normString = ""; | |
236 | TObjArray *listOfVariables = GetListOfVariables(); | |
237 | listOfVariables->Add(new TObjString("channel")); | |
238 | listOfVariables->Add(new TObjString("gx")); | |
239 | listOfVariables->Add(new TObjString("gy")); | |
240 | listOfVariables->Add(new TObjString("lx")); | |
241 | listOfVariables->Add(new TObjString("ly")); | |
242 | listOfVariables->Add(new TObjString("pad")); | |
243 | listOfVariables->Add(new TObjString("row")); | |
244 | listOfVariables->Add(new TObjString("rpad")); | |
245 | listOfVariables->Add(new TObjString("sector")); | |
246 | TObjArray *listOfNormalizationVariables = GetListOfNormalizationVariables(); | |
247 | Int_t nVariables = listOfVariables->GetEntriesFast(); | |
248 | Int_t nNorm = listOfNormalizationVariables->GetEntriesFast(); | |
7d855b04 | 249 | |
8192627b | 250 | Int_t *varLengths = new Int_t[nVariables]; |
251 | for (Int_t i = 0; i < nVariables; i++) { | |
252 | varLengths[i] = ((TObjString*)listOfVariables->At(i))->String().Length(); | |
253 | } | |
254 | Int_t *normLengths = new Int_t[nNorm]; | |
255 | for (Int_t i = 0; i < nNorm; i++) { | |
256 | normLengths[i] = ((TObjString*)listOfNormalizationVariables->At(i))->String().Length(); | |
257 | // printf("normLengths[%i] (%s) = %i \n", i,((TObjString*)listOfNormalizationVariables->At(i))->String().Data(), normLengths[i]); | |
258 | } | |
259 | Int_t *varSort = new Int_t[nVariables]; | |
260 | TMath::Sort(nVariables, varLengths, varSort, kTRUE); | |
261 | Int_t *normSort = new Int_t[nNorm]; | |
262 | TMath::Sort(nNorm, normLengths, normSort, kTRUE); | |
263 | // for (Int_t i = 0; i<nNorm; i++) printf("normLengths: %i\n", normLengths[normSort[i]]); | |
264 | // for (Int_t i = 0; i<nVariables; i++) printf("varLengths: %i\n", varLengths[varSort[i]]); | |
7d855b04 | 265 | |
8192627b | 266 | for (Int_t ivar = 0; ivar < nVariables; ivar++) { |
267 | // ***** save correct tokens ***** | |
268 | // first get the next variable: | |
269 | searchString = ((TObjString*)listOfVariables->At(varSort[ivar]))->String(); | |
270 | // printf("searchString: %s ++++++++++++++\n", searchString.Data()); | |
271 | // form replaceString: | |
272 | replaceString = ""; | |
273 | for (Int_t i = 0; i < searchString.Length(); i++) { | |
274 | replaceString.Append(searchString[i]); | |
275 | if (i == 0) replaceString.Append(removeString); | |
276 | } | |
277 | // go through normalization: | |
278 | // printf("go through normalization\n"); | |
279 | for (Int_t inorm = 0; inorm < nNorm; inorm++) { | |
280 | // printf(" inorm=%i, nNorm=%i, normSort[inorm]=%i \n", inorm, nNorm, normSort[inorm]); | |
281 | normString = ((TObjString*)listOfNormalizationVariables->At(normSort[inorm]))->String(); | |
282 | // printf(" walking in normalization, i=%i, normString=%s \n", inorm, normString.Data()); | |
283 | str.ReplaceAll(searchString + normString, replaceString + normString); | |
284 | // like: str.ReplaceAll("CEQmean_Mean", "C!EQmean_Mean"); | |
285 | } | |
286 | str.ReplaceAll(searchString + fAbbreviation, replaceString + fAbbreviation); | |
287 | // like: str.ReplaceAll("CEQmean~", "C!EQmean~"); | |
288 | str.ReplaceAll(searchString + fAppendString, replaceString + fAppendString); | |
289 | // like: str.ReplaceAll("CEQmean.fElements", "C!EQmean.fElements"); | |
7d855b04 | 290 | |
8192627b | 291 | // ***** add missing extensions ***** |
292 | str.ReplaceAll(searchString, replaceString + fAbbreviation); | |
293 | // like: str.ReplaceAll("CEQmean", "C!EQmean~"); | |
294 | } | |
7d855b04 | 295 | |
8192627b | 296 | // ***** undo saving ***** |
297 | str.ReplaceAll(removeString, ""); | |
7d855b04 | 298 | |
8192627b | 299 | if (printDrawCommand) std::cout << "The string looks now like: " << str.Data() << std::endl; |
6fefa5ce | 300 | delete [] varLengths; |
301 | delete [] normLengths; | |
4ce766eb | 302 | delete [] varSort; |
303 | delete [] normSort; | |
8192627b | 304 | return str.Data(); |
305 | } | |
306 | ||
307 | ||
308 | ||
309 | ||
39bcd65d | 310 | //_____________________________________________________________________________ |
311 | Int_t AliTPCCalibViewer::EasyDraw(const char* drawCommand, const char* sector, const char* cuts, const char* drawOptions, Bool_t writeDrawCommand) const { | |
7d855b04 | 312 | /// easy drawing of data, use '~' for abbreviation of '.fElements' |
313 | /// example: EasyDraw("CETmean~-CETmean_mean", "A", "(CETmean~-CETmean_mean)>0") | |
314 | /// sector: sector-number - only the specified sector will be drwawn | |
315 | /// 'A'/'C' or 'a'/'c' - side A/C will be drawn | |
316 | /// 'ALL' - whole TPC will be drawn, projected on one side | |
317 | /// cuts: specifies cuts | |
318 | /// drawOptions: draw options like 'same' | |
319 | /// writeDrawCommand: write the command, that is passed to TTree::Draw | |
72d0ab7e | 320 | |
39bcd65d | 321 | TString drawStr(drawCommand); |
322 | TString sectorStr(sector); | |
323 | sectorStr.ToUpper(); | |
324 | TString cutStr(""); | |
72d0ab7e | 325 | //TString drawOptionsStr("profcolz "); |
8192627b | 326 | Bool_t dangerousToDraw = drawStr.Contains(":") || drawStr.Contains(">>"); |
327 | if (dangerousToDraw) { | |
c4607f01 | 328 | Warning("EasyDraw", "The draw string must not contain ':' or '>>'. Using only first variable for drawing!"); |
329 | // return -1; | |
330 | // drawStr.Resize(drawStr.First(">")); | |
331 | drawStr.Resize(drawStr.First(":")); | |
8192627b | 332 | } |
c4607f01 | 333 | |
72d0ab7e | 334 | TString drawOptionsStr(""); |
39bcd65d | 335 | TRandom rnd(0); |
336 | Int_t rndNumber = rnd.Integer(10000); | |
72d0ab7e | 337 | |
338 | if (drawOptions && strcmp(drawOptions, "") != 0) | |
39bcd65d | 339 | drawOptionsStr += drawOptions; |
72d0ab7e | 340 | else |
341 | drawOptionsStr += "profcolz"; | |
39bcd65d | 342 | |
343 | if (sectorStr == "A") { | |
832bb12c | 344 | drawStr += Form(":gy%s:gx%s>>prof", fAppendString.Data(), fAppendString.Data()); |
39bcd65d | 345 | drawStr += rndNumber; |
346 | drawStr += "(330,-250,250,330,-250,250)"; | |
347 | cutStr += "(sector/18)%2==0 "; | |
348 | } | |
349 | else if (sectorStr == "C") { | |
832bb12c | 350 | drawStr += Form(":gy%s:gx%s>>prof", fAppendString.Data(), fAppendString.Data()); |
39bcd65d | 351 | drawStr += rndNumber; |
352 | drawStr += "(330,-250,250,330,-250,250)"; | |
353 | cutStr += "(sector/18)%2==1 "; | |
354 | } | |
355 | else if (sectorStr == "ALL") { | |
832bb12c | 356 | drawStr += Form(":gy%s:gx%s>>prof", fAppendString.Data(), fAppendString.Data()); |
39bcd65d | 357 | drawStr += rndNumber; |
358 | drawStr += "(330,-250,250,330,-250,250)"; | |
359 | } | |
c4607f01 | 360 | else if (sectorStr.Contains("S")) { |
361 | drawStr += Form(":rpad%s:row%s+(sector>35)*63>>prof", fAppendString.Data(), fAppendString.Data()); | |
362 | drawStr += rndNumber; | |
363 | drawStr += "(159,0,159,140,-70,70)"; | |
364 | TString sec=sectorStr; | |
365 | sec.Remove(0,1); | |
366 | cutStr += "sector%36=="+sec+" "; | |
367 | } | |
39bcd65d | 368 | else if (sectorStr.IsDigit()) { |
369 | Int_t isec = sectorStr.Atoi(); | |
832bb12c | 370 | drawStr += Form(":rpad%s:row%s>>prof", fAppendString.Data(), fAppendString.Data()); |
39bcd65d | 371 | drawStr += rndNumber; |
372 | if (isec < 36 && isec >= 0) | |
373 | drawStr += "(63,0,63,108,-54,54)"; | |
374 | else if (isec < 72 && isec >= 36) | |
375 | drawStr += "(96,0,96,140,-70,70)"; | |
376 | else { | |
377 | Error("EasyDraw","The TPC contains only sectors between 0 and 71."); | |
378 | return -1; | |
379 | } | |
380 | cutStr += "(sector=="; | |
381 | cutStr += isec; | |
382 | cutStr += ") "; | |
383 | } | |
384 | ||
385 | if (cuts && cuts[0] != 0) { | |
386 | if (cutStr.Length() != 0) cutStr += "&& "; | |
387 | cutStr += "("; | |
388 | cutStr += cuts; | |
389 | cutStr += ")"; | |
390 | } | |
832bb12c | 391 | drawStr.ReplaceAll(fAbbreviation, fAppendString); |
392 | cutStr.ReplaceAll(fAbbreviation, fAppendString); | |
39bcd65d | 393 | if (writeDrawCommand) std::cout << "fTree->Draw(\"" << drawStr << "\", \"" << cutStr << "\", \"" << drawOptionsStr << "\");" << std::endl; |
832bb12c | 394 | Int_t returnValue = fTree->Draw(drawStr.Data(), cutStr.Data(), drawOptionsStr.Data()); |
395 | TString profName("prof"); | |
396 | profName += rndNumber; | |
397 | TObject *obj = gDirectory->Get(profName.Data()); | |
398 | if (obj && obj->InheritsFrom("TH1")) FormatHistoLabels((TH1*)obj); | |
399 | return returnValue; | |
39bcd65d | 400 | } |
401 | ||
72d0ab7e | 402 | |
39bcd65d | 403 | Int_t AliTPCCalibViewer::EasyDraw(const char* drawCommand, Int_t sector, const char* cuts, const char* drawOptions, Bool_t writeDrawCommand) const { |
7d855b04 | 404 | /// easy drawing of data, use '~' for abbreviation of '.fElements' |
405 | /// example: EasyDraw("CETmean~-CETmean_mean", 34, "(CETmean~-CETmean_mean)>0") | |
406 | /// sector: sector-number - only the specified sector will be drwawn | |
407 | /// cuts: specifies cuts | |
408 | /// drawOptions: draw options like 'same' | |
409 | /// writeDrawCommand: write the command, that is passed to TTree::Draw | |
410 | ||
39bcd65d | 411 | if (sector >= 0 && sector < 72) { |
df5d3222 | 412 | return EasyDraw(drawCommand, Form("%i", sector), cuts, drawOptions, writeDrawCommand); |
39bcd65d | 413 | } |
414 | Error("EasyDraw","The TPC contains only sectors between 0 and 71."); | |
415 | return -1; | |
416 | } | |
417 | ||
72d0ab7e | 418 | |
39bcd65d | 419 | //_____________________________________________________________________________ |
420 | Int_t AliTPCCalibViewer::EasyDraw1D(const char* drawCommand, const char* sector, const char* cuts, const char* drawOptions, Bool_t writeDrawCommand) const { | |
7d855b04 | 421 | /// easy drawing of data, use '~' for abbreviation of '.fElements' |
422 | /// example: EasyDraw("CETmean~-CETmean_mean", "A", "(CETmean~-CETmean_mean)>0") | |
423 | /// sector: sector-number - the specified sector will be drwawn | |
424 | /// 'A'/'C' or 'a'/'c' - side A/C will be drawn | |
425 | /// 'ALL' - whole TPC will be drawn, projected on one side | |
426 | /// cuts: specifies cuts | |
427 | /// drawOptions: draw options like 'same' | |
428 | /// writeDrawCommand: write the command, that is passed to TTree::Draw | |
39bcd65d | 429 | |
430 | TString drawStr(drawCommand); | |
431 | TString sectorStr(sector); | |
432 | TString drawOptionsStr(drawOptions); | |
433 | sectorStr.ToUpper(); | |
434 | TString cutStr(""); | |
435 | ||
436 | if (sectorStr == "A") | |
437 | cutStr += "(sector/18)%2==0 "; | |
438 | else if (sectorStr == "C") | |
439 | cutStr += "(sector/18)%2==1 "; | |
440 | else if (sectorStr.IsDigit()) { | |
441 | Int_t isec = sectorStr.Atoi(); | |
442 | if (isec < 0 || isec > 71) { | |
443 | Error("EasyDraw","The TPC contains only sectors between 0 and 71."); | |
444 | return -1; | |
445 | } | |
446 | cutStr += "(sector=="; | |
447 | cutStr += isec; | |
448 | cutStr += ") "; | |
449 | } | |
c4607f01 | 450 | else if (sectorStr.Contains("S")) { |
451 | TString sec=sectorStr; | |
452 | sec.Remove(0,1); | |
453 | cutStr += "sector%36=="+sec+" "; | |
454 | } | |
39bcd65d | 455 | |
456 | if (cuts && cuts[0] != 0) { | |
457 | if (cutStr.Length() != 0) cutStr += "&& "; | |
458 | cutStr += "("; | |
459 | cutStr += cuts; | |
460 | cutStr += ")"; | |
461 | } | |
462 | ||
832bb12c | 463 | drawStr.ReplaceAll(fAbbreviation, fAppendString); |
464 | cutStr.ReplaceAll(fAbbreviation, fAppendString); | |
39bcd65d | 465 | if (writeDrawCommand) std::cout << "fTree->Draw(\"" << drawStr << "\", \"" << cutStr << "\", \"" << drawOptionsStr << "\");" << std::endl; |
832bb12c | 466 | Int_t returnValue = fTree->Draw(drawStr.Data(), cutStr.Data(), drawOptionsStr.Data()); |
8192627b | 467 | if (returnValue == -1) return -1; |
7d855b04 | 468 | |
469 | TObject *obj = (gPad) ? gPad->GetPrimitive("htemp") : 0; | |
832bb12c | 470 | if (!obj) obj = (TH1F*)gDirectory->Get("htemp"); |
471 | if (!obj) obj = gPad->GetPrimitive("tempHist"); | |
472 | if (!obj) obj = (TH1F*)gDirectory->Get("tempHist"); | |
473 | if (!obj) obj = gPad->GetPrimitive("Graph"); | |
474 | if (!obj) obj = (TH1F*)gDirectory->Get("Graph"); | |
475 | if (obj && obj->InheritsFrom("TH1")) FormatHistoLabels((TH1*)obj); | |
476 | return returnValue; | |
39bcd65d | 477 | } |
478 | ||
72d0ab7e | 479 | |
39bcd65d | 480 | Int_t AliTPCCalibViewer::EasyDraw1D(const char* drawCommand, Int_t sector, const char* cuts, const char* drawOptions, Bool_t writeDrawCommand) const { |
7d855b04 | 481 | /// easy drawing of data, use '~' for abbreviation of '.fElements' |
482 | /// example: EasyDraw("CETmean~-CETmean_mean", 34, "(CETmean~-CETmean_mean)>0") | |
483 | /// sector: sector-number - the specified sector will be drwawn | |
484 | /// cuts: specifies cuts | |
485 | /// drawOptions: draw options like 'same' | |
486 | /// writeDrawCommand: write the command, that is passed to TTree::Draw | |
39bcd65d | 487 | |
488 | if (sector >= 0 && sector < 72) { | |
df5d3222 | 489 | return EasyDraw1D(drawCommand, Form("%i",sector), cuts, drawOptions, writeDrawCommand); |
39bcd65d | 490 | } |
491 | Error("EasyDraw","The TPC contains only sectors between 0 and 71."); | |
492 | return -1; | |
493 | } | |
494 | ||
39bcd65d | 495 | |
832bb12c | 496 | void AliTPCCalibViewer::FormatHistoLabels(TH1 *histo) const { |
7d855b04 | 497 | /// formats title and axis labels of histo |
498 | /// removes '.fElements' | |
499 | ||
832bb12c | 500 | if (!histo) return; |
501 | TString replaceString(fAppendString.Data()); | |
502 | TString *str = new TString(histo->GetTitle()); | |
503 | str->ReplaceAll(replaceString, ""); | |
504 | histo->SetTitle(str->Data()); | |
505 | delete str; | |
506 | if (histo->GetXaxis()) { | |
507 | str = new TString(histo->GetXaxis()->GetTitle()); | |
508 | str->ReplaceAll(replaceString, ""); | |
509 | histo->GetXaxis()->SetTitle(str->Data()); | |
510 | delete str; | |
511 | } | |
512 | if (histo->GetYaxis()) { | |
513 | str = new TString(histo->GetYaxis()->GetTitle()); | |
514 | str->ReplaceAll(replaceString, ""); | |
515 | histo->GetYaxis()->SetTitle(str->Data()); | |
516 | delete str; | |
517 | } | |
518 | if (histo->GetZaxis()) { | |
519 | str = new TString(histo->GetZaxis()->GetTitle()); | |
520 | str->ReplaceAll(replaceString, ""); | |
521 | histo->GetZaxis()->SetTitle(str->Data()); | |
522 | delete str; | |
523 | } | |
524 | } | |
525 | ||
526 | ||
72d0ab7e | 527 | Int_t AliTPCCalibViewer::DrawHisto1D(const char* drawCommand, Int_t sector, const char* cuts, const char *sigmas, Bool_t plotMean, Bool_t plotMedian, Bool_t plotLTM) const { |
7d855b04 | 528 | /// Easy drawing of data, in principle the same as EasyDraw1D |
529 | /// Difference: A line for the mean / median / LTM is drawn | |
530 | /// in 'sigmas' you can specify in which distance to the mean/median/LTM you want to see a line in sigma-units, separated by ';' | |
531 | /// example: sigmas = "2; 4; 6;" at \f$2 \sigma\f$, \f$4 \sigma\f$ and \f$6 \sigma\f$ a line is drawn. | |
532 | /// "plotMean", "plotMedian" and "plotLTM": what kind of lines do you want to see? | |
533 | ||
72d0ab7e | 534 | if (sector >= 0 && sector < 72) { |
df5d3222 | 535 | return DrawHisto1D(drawCommand, Form("%i", sector), cuts, sigmas, plotMean, plotMedian, plotLTM); |
72d0ab7e | 536 | } |
537 | Error("DrawHisto1D","The TPC contains only sectors between 0 and 71."); | |
538 | return -1; | |
7d855b04 | 539 | } |
39bcd65d | 540 | |
72d0ab7e | 541 | |
542 | Int_t AliTPCCalibViewer::DrawHisto1D(const char* drawCommand, const char* sector, const char* cuts, const char *sigmas, Bool_t plotMean, Bool_t plotMedian, Bool_t plotLTM) const { | |
7d855b04 | 543 | /// Easy drawing of data, in principle the same as EasyDraw1D |
544 | /// Difference: A line for the mean / median / LTM is drawn | |
545 | /// in 'sigmas' you can specify in which distance to the mean/median/LTM you want to see a line in sigma-units, separated by ';' | |
546 | /// example: sigmas = "2; 4; 6;" at \f$2 \sigma\f$, \f$4 \sigma\f$ and \f$6 \sigma\f$ a line is drawn. | |
547 | /// "plotMean", "plotMedian" and "plotLTM": what kind of lines do you want to see? | |
548 | ||
39bcd65d | 549 | Int_t oldOptStat = gStyle->GetOptStat(); |
550 | gStyle->SetOptStat(0000000); | |
72d0ab7e | 551 | Double_t ltmFraction = 0.8; |
7d855b04 | 552 | |
553 | TObjArray *sigmasTokens = TString(sigmas).Tokenize(";"); | |
72d0ab7e | 554 | TVectorF nsigma(sigmasTokens->GetEntriesFast()); |
555 | for (Int_t i = 0; i < sigmasTokens->GetEntriesFast(); i++) { | |
556 | TString str(((TObjString*)sigmasTokens->At(i))->GetString()); | |
557 | Double_t sig = (str.IsFloat()) ? str.Atof() : 0; | |
558 | nsigma[i] = sig; | |
39bcd65d | 559 | } |
09d5920f | 560 | delete sigmasTokens; |
561 | ||
72d0ab7e | 562 | TString drawStr(drawCommand); |
832bb12c | 563 | Bool_t dangerousToDraw = drawStr.Contains(":") || drawStr.Contains(">>"); |
564 | if (dangerousToDraw) { | |
565 | Warning("DrawHisto1D", "The draw string must not contain ':' or '>>'."); | |
566 | return -1; | |
567 | } | |
72d0ab7e | 568 | drawStr += " >> tempHist"; |
569 | Int_t entries = EasyDraw1D(drawStr.Data(), sector, cuts); | |
570 | TH1F *htemp = (TH1F*)gDirectory->Get("tempHist"); | |
571 | // FIXME is this histogram deleted automatically? | |
572 | Double_t *values = fTree->GetV1(); // value is the array containing 'entries' numbers | |
7d855b04 | 573 | |
72d0ab7e | 574 | Double_t mean = TMath::Mean(entries, values); |
575 | Double_t median = TMath::Median(entries, values); | |
576 | Double_t sigma = TMath::RMS(entries, values); | |
577 | Double_t maxY = htemp->GetMaximum(); | |
7d855b04 | 578 | |
72d0ab7e | 579 | TLegend * legend = new TLegend(.7,.7, .99, .99, "Statistical information"); |
832bb12c | 580 | //fListOfObjectsToBeDeleted->Add(legend); |
39bcd65d | 581 | |
39bcd65d | 582 | if (plotMean) { |
72d0ab7e | 583 | // draw Mean |
584 | TLine* line = new TLine(mean, 0, mean, maxY); | |
832bb12c | 585 | //fListOfObjectsToBeDeleted->Add(line); |
39bcd65d | 586 | line->SetLineColor(kRed); |
587 | line->SetLineWidth(2); | |
588 | line->SetLineStyle(1); | |
589 | line->Draw(); | |
df5d3222 | 590 | legend->AddEntry(line, Form("Mean: %f", mean), "l"); |
72d0ab7e | 591 | // draw sigma lines |
39bcd65d | 592 | for (Int_t i = 0; i < nsigma.GetNoElements(); i++) { |
72d0ab7e | 593 | TLine* linePlusSigma = new TLine(mean + nsigma[i] * sigma, 0, mean + nsigma[i] * sigma, maxY); |
832bb12c | 594 | //fListOfObjectsToBeDeleted->Add(linePlusSigma); |
39bcd65d | 595 | linePlusSigma->SetLineColor(kRed); |
72d0ab7e | 596 | linePlusSigma->SetLineStyle(2 + i); |
39bcd65d | 597 | linePlusSigma->Draw(); |
72d0ab7e | 598 | TLine* lineMinusSigma = new TLine(mean - nsigma[i] * sigma, 0, mean - nsigma[i] * sigma, maxY); |
832bb12c | 599 | //fListOfObjectsToBeDeleted->Add(lineMinusSigma); |
39bcd65d | 600 | lineMinusSigma->SetLineColor(kRed); |
72d0ab7e | 601 | lineMinusSigma->SetLineStyle(2 + i); |
39bcd65d | 602 | lineMinusSigma->Draw(); |
df5d3222 | 603 | legend->AddEntry(lineMinusSigma, Form("%i #sigma = %f",(Int_t)(nsigma[i]), (Float_t)(nsigma[i] * sigma)), "l"); |
39bcd65d | 604 | } |
605 | } | |
39bcd65d | 606 | if (plotMedian) { |
72d0ab7e | 607 | // draw median |
608 | TLine* line = new TLine(median, 0, median, maxY); | |
832bb12c | 609 | //fListOfObjectsToBeDeleted->Add(line); |
39bcd65d | 610 | line->SetLineColor(kBlue); |
611 | line->SetLineWidth(2); | |
612 | line->SetLineStyle(1); | |
613 | line->Draw(); | |
df5d3222 | 614 | legend->AddEntry(line, Form("Median: %f", median), "l"); |
72d0ab7e | 615 | // draw sigma lines |
39bcd65d | 616 | for (Int_t i = 0; i < nsigma.GetNoElements(); i++) { |
72d0ab7e | 617 | TLine* linePlusSigma = new TLine(median + nsigma[i] * sigma, 0, median + nsigma[i]*sigma, maxY); |
832bb12c | 618 | //fListOfObjectsToBeDeleted->Add(linePlusSigma); |
39bcd65d | 619 | linePlusSigma->SetLineColor(kBlue); |
72d0ab7e | 620 | linePlusSigma->SetLineStyle(2 + i); |
39bcd65d | 621 | linePlusSigma->Draw(); |
72d0ab7e | 622 | TLine* lineMinusSigma = new TLine(median - nsigma[i] * sigma, 0, median - nsigma[i]*sigma, maxY); |
832bb12c | 623 | //fListOfObjectsToBeDeleted->Add(lineMinusSigma); |
39bcd65d | 624 | lineMinusSigma->SetLineColor(kBlue); |
72d0ab7e | 625 | lineMinusSigma->SetLineStyle(2 + i); |
39bcd65d | 626 | lineMinusSigma->Draw(); |
df5d3222 | 627 | legend->AddEntry(lineMinusSigma, Form("%i #sigma = %f",(Int_t)(nsigma[i]), (Float_t)(nsigma[i] * sigma)), "l"); |
39bcd65d | 628 | } |
629 | } | |
39bcd65d | 630 | if (plotLTM) { |
72d0ab7e | 631 | // draw LTM |
632 | Double_t ltmRms = 0; | |
633 | Double_t ltm = GetLTM(entries, values, <mRms, ltmFraction); | |
634 | TLine* line = new TLine(ltm, 0, ltm, maxY); | |
832bb12c | 635 | //fListOfObjectsToBeDeleted->Add(line); |
39bcd65d | 636 | line->SetLineColor(kGreen+2); |
637 | line->SetLineWidth(2); | |
638 | line->SetLineStyle(1); | |
639 | line->Draw(); | |
df5d3222 | 640 | legend->AddEntry(line, Form("LTM: %f", ltm), "l"); |
72d0ab7e | 641 | // draw sigma lines |
39bcd65d | 642 | for (Int_t i = 0; i < nsigma.GetNoElements(); i++) { |
72d0ab7e | 643 | TLine* linePlusSigma = new TLine(ltm + nsigma[i] * ltmRms, 0, ltm + nsigma[i] * ltmRms, maxY); |
832bb12c | 644 | //fListOfObjectsToBeDeleted->Add(linePlusSigma); |
39bcd65d | 645 | linePlusSigma->SetLineColor(kGreen+2); |
646 | linePlusSigma->SetLineStyle(2+i); | |
647 | linePlusSigma->Draw(); | |
7d855b04 | 648 | |
72d0ab7e | 649 | TLine* lineMinusSigma = new TLine(ltm - nsigma[i] * ltmRms, 0, ltm - nsigma[i] * ltmRms, maxY); |
832bb12c | 650 | //fListOfObjectsToBeDeleted->Add(lineMinusSigma); |
39bcd65d | 651 | lineMinusSigma->SetLineColor(kGreen+2); |
652 | lineMinusSigma->SetLineStyle(2+i); | |
653 | lineMinusSigma->Draw(); | |
df5d3222 | 654 | legend->AddEntry(lineMinusSigma, Form("%i #sigma = %f", (Int_t)(nsigma[i]), (Float_t)(nsigma[i] * ltmRms)), "l"); |
39bcd65d | 655 | } |
656 | } | |
72d0ab7e | 657 | if (!plotMean && !plotMedian && !plotLTM) return -1; |
39bcd65d | 658 | legend->Draw(); |
659 | gStyle->SetOptStat(oldOptStat); | |
72d0ab7e | 660 | return 1; |
39bcd65d | 661 | } |
662 | ||
39bcd65d | 663 | |
72d0ab7e | 664 | Int_t AliTPCCalibViewer::SigmaCut(const char* drawCommand, Int_t sector, const char* cuts, Float_t sigmaMax, Bool_t plotMean, Bool_t plotMedian, Bool_t plotLTM, Bool_t pm, const char *sigmas, Float_t sigmaStep) const { |
7d855b04 | 665 | /// Creates a histogram \f$S(t, \mu, \sigma)\f$, where you can see, how much of the data are inside sigma-intervals around the mean value |
666 | /// The data of the distribution \f$f(x, \mu, \sigma)\f$ are given in 'array', 'n' specifies the length of the array | |
667 | /// 'mean' and 'sigma' are \f$\mu\f$ and \f$\sigma\f$ of the distribution in 'array', to be specified by the user | |
668 | /// 'nbins': number of bins, 'binLow': first bin, 'binUp': last bin | |
669 | /// sigmaMax: up to which sigma around the mean/median/LTM the histogram is generated (in units of sigma, \f$t \sigma\f$) | |
670 | /// sigmaStep: the binsize of the generated histogram | |
671 | /// \f[ | |
672 | /// f(x, \mu, \sigma) \Rightarrow S(t, \mu, \sigma) = (\int_{\mu}^{\mu + t \sigma} f(x, \mu, \sigma) dx + \int_{\mu}^{\mu - t \sigma} f(x, \mu, \sigma) dx) / (\int_{-\infty}^{+\infty} f(x, \mu, \sigma) dx) | |
673 | /// \f] | |
674 | /// | |
675 | /// Creates a histogram, where you can see, how much of the data are inside sigma-intervals | |
676 | /// around the mean/median/LTM | |
677 | /// with drawCommand, sector and cuts you specify your input data, see EasyDraw | |
678 | /// sigmaMax: up to which sigma around the mean/median/LTM the histogram is generated (in units of sigma) | |
679 | /// sigmaStep: the binsize of the generated histogram | |
680 | /// plotMean/plotMedian/plotLTM: specifies where to put the center | |
681 | ||
72d0ab7e | 682 | if (sector >= 0 && sector < 72) { |
df5d3222 | 683 | return SigmaCut(drawCommand, Form("%i", sector), cuts, sigmaMax, plotMean, plotMedian, plotLTM, pm, sigmas, sigmaStep); |
72d0ab7e | 684 | } |
685 | Error("SigmaCut","The TPC contains only sectors between 0 and 71."); | |
686 | return -1; | |
687 | } | |
688 | ||
689 | ||
690 | Int_t AliTPCCalibViewer::SigmaCut(const char* drawCommand, const char* sector, const char* cuts, Float_t sigmaMax, Bool_t plotMean, Bool_t plotMedian, Bool_t plotLTM, Bool_t pm, const char *sigmas, Float_t sigmaStep) const { | |
7d855b04 | 691 | /// Creates a histogram, where you can see, how much of the data are inside sigma-intervals |
692 | /// around the mean/median/LTM | |
693 | /// with drawCommand, sector and cuts you specify your input data, see EasyDraw | |
694 | /// sigmaMax: up to which sigma around the mean/median/LTM the histogram is generated (in units of sigma) | |
695 | /// sigmaStep: the binsize of the generated histogram | |
696 | /// plotMean/plotMedian/plotLTM: specifies where to put the center | |
697 | ||
72d0ab7e | 698 | Double_t ltmFraction = 0.8; |
7d855b04 | 699 | |
72d0ab7e | 700 | TString drawStr(drawCommand); |
832bb12c | 701 | Bool_t dangerousToDraw = drawStr.Contains(":") || drawStr.Contains(">>"); |
702 | if (dangerousToDraw) { | |
703 | Warning("SigmaCut", "The draw string must not contain ':' or '>>'."); | |
704 | return -1; | |
705 | } | |
72d0ab7e | 706 | drawStr += " >> tempHist"; |
7d855b04 | 707 | |
72d0ab7e | 708 | Int_t entries = EasyDraw1D(drawStr.Data(), sector, cuts, "goff"); |
709 | TH1F *htemp = (TH1F*)gDirectory->Get("tempHist"); | |
710 | // FIXME is this histogram deleted automatically? | |
711 | Double_t *values = fTree->GetV1(); // value is the array containing 'entries' numbers | |
7d855b04 | 712 | |
72d0ab7e | 713 | Double_t mean = TMath::Mean(entries, values); |
714 | Double_t median = TMath::Median(entries, values); | |
715 | Double_t sigma = TMath::RMS(entries, values); | |
7d855b04 | 716 | |
72d0ab7e | 717 | TLegend * legend = new TLegend(.7,.7, .99, .99, "Cumulative"); |
832bb12c | 718 | //fListOfObjectsToBeDeleted->Add(legend); |
72d0ab7e | 719 | TH1F *cutHistoMean = 0; |
720 | TH1F *cutHistoMedian = 0; | |
721 | TH1F *cutHistoLTM = 0; | |
7d855b04 | 722 | |
723 | TObjArray *sigmasTokens = TString(sigmas).Tokenize(";"); | |
72d0ab7e | 724 | TVectorF nsigma(sigmasTokens->GetEntriesFast()); |
725 | for (Int_t i = 0; i < sigmasTokens->GetEntriesFast(); i++) { | |
726 | TString str(((TObjString*)sigmasTokens->At(i))->GetString()); | |
727 | Double_t sig = (str.IsFloat()) ? str.Atof() : 0; | |
728 | nsigma[i] = sig; | |
729 | } | |
09d5920f | 730 | delete sigmasTokens; |
731 | ||
72d0ab7e | 732 | if (plotMean) { |
733 | cutHistoMean = AliTPCCalibViewer::SigmaCut(htemp, mean, sigma, sigmaMax, sigmaStep, pm); | |
734 | if (cutHistoMean) { | |
832bb12c | 735 | //fListOfObjectsToBeDeleted->Add(cutHistoMean); |
72d0ab7e | 736 | cutHistoMean->SetLineColor(kRed); |
737 | legend->AddEntry(cutHistoMean, "Mean", "l"); | |
738 | cutHistoMean->SetTitle(Form("%s, cumulative; Multiples of #sigma; Fraction of included data", htemp->GetTitle())); | |
739 | cutHistoMean->Draw(); | |
740 | DrawLines(cutHistoMean, nsigma, legend, kRed, pm); | |
741 | } // if (cutHistoMean) | |
7d855b04 | 742 | |
72d0ab7e | 743 | } |
744 | if (plotMedian) { | |
745 | cutHistoMedian = AliTPCCalibViewer::SigmaCut(htemp, median, sigma, sigmaMax, sigmaStep, pm); | |
746 | if (cutHistoMedian) { | |
832bb12c | 747 | //fListOfObjectsToBeDeleted->Add(cutHistoMedian); |
72d0ab7e | 748 | cutHistoMedian->SetLineColor(kBlue); |
749 | legend->AddEntry(cutHistoMedian, "Median", "l"); | |
750 | cutHistoMedian->SetTitle(Form("%s, cumulative; Multiples of #sigma; Fraction of included data", htemp->GetTitle())); | |
751 | if (plotMean && cutHistoMean) cutHistoMedian->Draw("same"); | |
752 | else cutHistoMedian->Draw(); | |
753 | DrawLines(cutHistoMedian, nsigma, legend, kBlue, pm); | |
754 | } // if (cutHistoMedian) | |
755 | } | |
756 | if (plotLTM) { | |
757 | Double_t ltmRms = 0; | |
758 | Double_t ltm = GetLTM(entries, values, <mRms, ltmFraction); | |
759 | cutHistoLTM = AliTPCCalibViewer::SigmaCut(htemp, ltm, ltmRms, sigmaMax, sigmaStep, pm); | |
760 | if (cutHistoLTM) { | |
832bb12c | 761 | //fListOfObjectsToBeDeleted->Add(cutHistoLTM); |
72d0ab7e | 762 | cutHistoLTM->SetLineColor(kGreen+2); |
763 | legend->AddEntry(cutHistoLTM, "LTM", "l"); | |
764 | cutHistoLTM->SetTitle(Form("%s, cumulative; Multiples of #sigma; Fraction of included data", htemp->GetTitle())); | |
94bf739c | 765 | if ((plotMean && cutHistoMean) || (plotMedian && cutHistoMedian)) cutHistoLTM->Draw("same"); |
72d0ab7e | 766 | else cutHistoLTM->Draw(); |
767 | DrawLines(cutHistoLTM, nsigma, legend, kGreen+2, pm); | |
768 | } | |
769 | } | |
770 | if (!plotMean && !plotMedian && !plotLTM) return -1; | |
771 | legend->Draw(); | |
772 | return 1; | |
773 | } | |
774 | ||
832bb12c | 775 | |
2773a273 | 776 | Int_t AliTPCCalibViewer::SigmaCutNew(const char* drawCommand, const char* sector, const char* cuts, Float_t /*sigmaMax*/, Bool_t plotMean, Bool_t plotMedian, Bool_t plotLTM, Bool_t /*pm*/, const char *sigmas, Float_t /*sigmaStep*/) const { |
7d855b04 | 777 | /// Creates a histogram, where you can see, how much of the data are inside sigma-intervals |
778 | /// around the mean/median/LTM | |
779 | /// with drawCommand, sector and cuts you specify your input data, see EasyDraw | |
780 | /// sigmaMax: up to which sigma around the mean/median/LTM the histogram is generated (in units of sigma) | |
781 | /// sigmaStep: the binsize of the generated histogram | |
782 | /// plotMean/plotMedian/plotLTM: specifies where to put the center | |
783 | ||
4f3934a1 | 784 | // Double_t ltmFraction = 0.8; //unused |
7d855b04 | 785 | |
4f3934a1 | 786 | TString drawStr(drawCommand); |
787 | drawStr += " >> tempHist"; | |
7d855b04 | 788 | |
4f3934a1 | 789 | Int_t entries = EasyDraw1D(drawStr.Data(), sector, cuts, "goff"); |
790 | TH1F *htemp = (TH1F*)gDirectory->Get("tempHist"); | |
791 | TGraph *cutGraphMean = 0; | |
792 | // TGraph *cutGraphMedian = 0; | |
793 | // TGraph *cutGraphLTM = 0; | |
794 | Double_t *values = fTree->GetV1(); // value is the array containing 'entries' numbers | |
795 | Int_t *index = new Int_t[entries]; | |
796 | Float_t *xarray = new Float_t[entries]; | |
797 | Float_t *yarray = new Float_t[entries]; | |
798 | TMath::Sort(entries, values, index, kFALSE); | |
7d855b04 | 799 | |
4f3934a1 | 800 | Double_t mean = TMath::Mean(entries, values); |
801 | // Double_t median = TMath::Median(entries, values); | |
802 | Double_t sigma = TMath::RMS(entries, values); | |
7d855b04 | 803 | |
4f3934a1 | 804 | TLegend * legend = new TLegend(.7,.7, .99, .99, "Cumulative"); |
832bb12c | 805 | //fListOfObjectsToBeDeleted->Add(legend); |
7d855b04 | 806 | |
4f3934a1 | 807 | // parse sigmas string |
7d855b04 | 808 | TObjArray *sigmasTokens = TString(sigmas).Tokenize(";"); |
4f3934a1 | 809 | TVectorF nsigma(sigmasTokens->GetEntriesFast()); |
810 | for (Int_t i = 0; i < sigmasTokens->GetEntriesFast(); i++) { | |
811 | TString str(((TObjString*)sigmasTokens->At(i))->GetString()); | |
812 | Double_t sig = (str.IsFloat()) ? str.Atof() : 0; | |
813 | nsigma[i] = sig; | |
814 | } | |
09d5920f | 815 | delete sigmasTokens; |
7d855b04 | 816 | |
4f3934a1 | 817 | if (plotMean) { |
818 | for (Int_t i = 0; i < entries; i++) { | |
7d855b04 | 819 | xarray[i] = TMath::Abs(values[index[i]] - mean) / sigma; |
4f3934a1 | 820 | yarray[i] = float(i) / float(entries); |
821 | } | |
822 | cutGraphMean = new TGraph(entries, xarray, yarray); | |
823 | if (cutGraphMean) { | |
832bb12c | 824 | //fListOfObjectsToBeDeleted->Add(cutGraphMean); |
4f3934a1 | 825 | cutGraphMean->SetLineColor(kRed); |
826 | legend->AddEntry(cutGraphMean, "Mean", "l"); | |
827 | cutGraphMean->SetTitle(Form("%s, Cumulative; Multiples of #sigma; Fraction of included data", htemp->GetTitle())); | |
828 | cutGraphMean->Draw("alu"); | |
829 | DrawLines(cutGraphMean, nsigma, legend, kRed, kTRUE); | |
830 | } | |
831 | } | |
df5d3222 | 832 | delete [] index; |
833 | delete [] xarray; | |
834 | delete [] yarray; | |
4f3934a1 | 835 | /* |
836 | if (plotMedian) { | |
837 | cutHistoMedian = AliTPCCalibViewer::SigmaCut(htemp, median, sigma, sigmaMax, sigmaStep, pm); | |
838 | if (cutHistoMedian) { | |
839 | fListOfObjectsToBeDeleted->Add(cutHistoMedian); | |
840 | cutHistoMedian->SetLineColor(kBlue); | |
841 | legend->AddEntry(cutHistoMedian, "Median", "l"); | |
842 | cutHistoMedian->SetTitle(Form("%s, cumulative; Multiples of #sigma; Fraction of included data", htemp->GetTitle())); | |
843 | if (plotMean && cutHistoMean) cutHistoMedian->Draw("same"); | |
844 | else cutHistoMedian->Draw(); | |
845 | DrawLines(cutHistoMedian, nsigma, legend, kBlue, pm); | |
846 | } // if (cutHistoMedian) | |
847 | } | |
848 | if (plotLTM) { | |
849 | Double_t ltmRms = 0; | |
850 | Double_t ltm = GetLTM(entries, values, <mRms, ltmFraction); | |
851 | cutHistoLTM = AliTPCCalibViewer::SigmaCut(htemp, ltm, ltmRms, sigmaMax, sigmaStep, pm); | |
852 | if (cutHistoLTM) { | |
853 | fListOfObjectsToBeDeleted->Add(cutHistoLTM); | |
854 | cutHistoLTM->SetLineColor(kGreen+2); | |
855 | legend->AddEntry(cutHistoLTM, "LTM", "l"); | |
856 | cutHistoLTM->SetTitle(Form("%s, cumulative; Multiples of #sigma; Fraction of included data", htemp->GetTitle())); | |
857 | if (plotMean && cutHistoMean || plotMedian && cutHistoMedian) cutHistoLTM->Draw("same"); | |
858 | else cutHistoLTM->Draw(); | |
859 | DrawLines(cutHistoLTM, nsigma, legend, kGreen+2, pm); | |
860 | } | |
861 | }*/ | |
862 | if (!plotMean && !plotMedian && !plotLTM) return -1; | |
863 | legend->Draw(); | |
864 | return 1; | |
865 | } | |
866 | ||
72d0ab7e | 867 | |
72d0ab7e | 868 | Int_t AliTPCCalibViewer::Integrate(const char* drawCommand, Int_t sector, const char* cuts, Float_t sigmaMax, Bool_t plotMean, Bool_t plotMedian, Bool_t plotLTM, const char *sigmas, Float_t sigmaStep) const { |
7d855b04 | 869 | /// Creates an integrated histogram \f$S(t, \mu, \sigma)\f$, out of the input distribution distribution \f$f(x, \mu, \sigma)\f$, given in "histogram" |
870 | /// "mean" and "sigma" are \f$\mu\f$ and \f$\sigma\f$ of the distribution in "histogram", to be specified by the user | |
871 | /// sigmaMax: up to which sigma around the mean/median/LTM you want to integrate | |
872 | /// if "igma == 0" and "sigmaMax == 0" the whole histogram is integrated | |
873 | /// "sigmaStep": the binsize of the generated histogram, -1 means, that the maximal reasonable stepsize is used | |
874 | /// The actual work is done on the array. | |
875 | ||
876 | /* Begin_Latex | |
6a1caa6b | 877 | f(x, #mu, #sigma) #Rightarrow S(t, #mu, #sigma) = #int_{-#infty}^{#mu + t #sigma} f(x, #mu, #sigma) dx / #int_{-#infty}^{+#infty} f(x, #mu, #sigma) dx |
7d855b04 | 878 | End_Latex |
72d0ab7e | 879 | */ |
880 | if (sector >= 0 && sector < 72) { | |
df5d3222 | 881 | return Integrate(drawCommand, Form("%i", sector), cuts, sigmaMax, plotMean, plotMedian, plotLTM, sigmas, sigmaStep); |
72d0ab7e | 882 | } |
883 | Error("Integrate","The TPC contains only sectors between 0 and 71."); | |
884 | return -1; | |
7d855b04 | 885 | |
72d0ab7e | 886 | } |
887 | ||
888 | ||
4f3934a1 | 889 | Int_t AliTPCCalibViewer::IntegrateOld(const char* drawCommand, const char* sector, const char* cuts, Float_t sigmaMax, Bool_t plotMean, Bool_t plotMedian, Bool_t plotLTM, const char *sigmas, Float_t sigmaStep) const { |
7d855b04 | 890 | /// Creates an integrated histogram \f$S(t, \mu, \sigma)\f$, out of the input distribution distribution \f$f(x, \mu, \sigma)\f$, given in "histogram" |
891 | /// "mean" and "sigma" are \f$\mu\f$ and \f$\sigma\f$ of the distribution in "histogram", to be specified by the user | |
892 | /// sigmaMax: up to which sigma around the mean/median/LTM you want to integrate | |
893 | /// if "igma == 0" and "sigmaMax == 0" the whole histogram is integrated | |
894 | /// "sigmaStep": the binsize of the generated histogram, -1 means, that the maximal reasonable stepsize is used | |
895 | /// The actual work is done on the array. | |
896 | ||
897 | /* Begin_Latex | |
6a1caa6b | 898 | f(x, #mu, #sigma) #Rightarrow S(t, #mu, #sigma) = #int_{-#infty}^{#mu + t #sigma} f(x, #mu, #sigma) dx / #int_{-#infty}^{+#infty} f(x, #mu, #sigma) dx |
7d855b04 | 899 | End_Latex |
72d0ab7e | 900 | */ |
7d855b04 | 901 | |
72d0ab7e | 902 | Double_t ltmFraction = 0.8; |
7d855b04 | 903 | |
72d0ab7e | 904 | TString drawStr(drawCommand); |
905 | drawStr += " >> tempHist"; | |
7d855b04 | 906 | |
72d0ab7e | 907 | Int_t entries = EasyDraw1D(drawStr.Data(), sector, cuts, "goff"); |
908 | TH1F *htemp = (TH1F*)gDirectory->Get("tempHist"); | |
909 | // FIXME is this histogram deleted automatically? | |
910 | Double_t *values = fTree->GetV1(); // value is the array containing 'entries' numbers | |
7d855b04 | 911 | |
72d0ab7e | 912 | Double_t mean = TMath::Mean(entries, values); |
913 | Double_t median = TMath::Median(entries, values); | |
914 | Double_t sigma = TMath::RMS(entries, values); | |
7d855b04 | 915 | |
916 | TObjArray *sigmasTokens = TString(sigmas).Tokenize(";"); | |
72d0ab7e | 917 | TVectorF nsigma(sigmasTokens->GetEntriesFast()); |
918 | for (Int_t i = 0; i < sigmasTokens->GetEntriesFast(); i++) { | |
919 | TString str(((TObjString*)sigmasTokens->At(i))->GetString()); | |
920 | Double_t sig = (str.IsFloat()) ? str.Atof() : 0; | |
921 | nsigma[i] = sig; | |
922 | } | |
09d5920f | 923 | delete sigmasTokens; |
924 | ||
72d0ab7e | 925 | TLegend * legend = new TLegend(.7,.7, .99, .99, "Integrated histogram"); |
832bb12c | 926 | //fListOfObjectsToBeDeleted->Add(legend); |
72d0ab7e | 927 | TH1F *integralHistoMean = 0; |
928 | TH1F *integralHistoMedian = 0; | |
929 | TH1F *integralHistoLTM = 0; | |
7d855b04 | 930 | |
72d0ab7e | 931 | if (plotMean) { |
932 | integralHistoMean = AliTPCCalibViewer::Integrate(htemp, mean, sigma, sigmaMax, sigmaStep); | |
933 | if (integralHistoMean) { | |
832bb12c | 934 | //fListOfObjectsToBeDeleted->Add(integralHistoMean); |
72d0ab7e | 935 | integralHistoMean->SetLineColor(kRed); |
936 | legend->AddEntry(integralHistoMean, "Mean", "l"); | |
937 | integralHistoMean->SetTitle(Form("%s, integrated; Multiples of #sigma; Fraction of included data", htemp->GetTitle())); | |
938 | integralHistoMean->Draw(); | |
939 | DrawLines(integralHistoMean, nsigma, legend, kRed, kTRUE); | |
39bcd65d | 940 | } |
72d0ab7e | 941 | } |
942 | if (plotMedian) { | |
943 | integralHistoMedian = AliTPCCalibViewer::Integrate(htemp, median, sigma, sigmaMax, sigmaStep); | |
944 | if (integralHistoMedian) { | |
832bb12c | 945 | //fListOfObjectsToBeDeleted->Add(integralHistoMedian); |
72d0ab7e | 946 | integralHistoMedian->SetLineColor(kBlue); |
947 | legend->AddEntry(integralHistoMedian, "Median", "l"); | |
948 | integralHistoMedian->SetTitle(Form("%s, integrated; Multiples of #sigma; Fraction of included data", htemp->GetTitle())); | |
949 | if (plotMean && integralHistoMean) integralHistoMedian->Draw("same"); | |
950 | else integralHistoMedian->Draw(); | |
951 | DrawLines(integralHistoMedian, nsigma, legend, kBlue, kTRUE); | |
39bcd65d | 952 | } |
72d0ab7e | 953 | } |
954 | if (plotLTM) { | |
955 | Double_t ltmRms = 0; | |
956 | Double_t ltm = GetLTM(entries, values, <mRms, ltmFraction); | |
957 | integralHistoLTM = AliTPCCalibViewer::Integrate(htemp, ltm, ltmRms, sigmaMax, sigmaStep); | |
958 | if (integralHistoLTM) { | |
832bb12c | 959 | //fListOfObjectsToBeDeleted->Add(integralHistoLTM); |
72d0ab7e | 960 | integralHistoLTM->SetLineColor(kGreen+2); |
961 | legend->AddEntry(integralHistoLTM, "LTM", "l"); | |
962 | integralHistoLTM->SetTitle(Form("%s, integrated; Multiples of #sigma; Fraction of included data", htemp->GetTitle())); | |
94bf739c | 963 | if ((plotMean && integralHistoMean) || (plotMedian && integralHistoMedian)) integralHistoLTM->Draw("same"); |
72d0ab7e | 964 | else integralHistoLTM->Draw(); |
965 | DrawLines(integralHistoLTM, nsigma, legend, kGreen+2, kTRUE); | |
39bcd65d | 966 | } |
967 | } | |
72d0ab7e | 968 | if (!plotMean && !plotMedian && !plotLTM) return -1; |
969 | legend->Draw(); | |
970 | return 1; | |
971 | } | |
972 | ||
973 | ||
2773a273 | 974 | Int_t AliTPCCalibViewer::Integrate(const char* drawCommand, const char* sector, const char* cuts, Float_t /*sigmaMax*/, Bool_t plotMean, Bool_t plotMedian, Bool_t plotLTM, const char *sigmas, Float_t /*sigmaStep*/) const { |
7d855b04 | 975 | /// Creates an integrated histogram \f$S(t, \mu, \sigma)\f$, out of the input distribution distribution \f$f(x, \mu, \sigma)\f$, given in "histogram" |
976 | /// "mean" and "sigma" are \f$\mu\f$ and \f$\sigma\f$ of the distribution in "histogram", to be specified by the user | |
977 | /// sigmaMax: up to which sigma around the mean/median/LTM you want to integrate | |
978 | /// if "igma == 0" and "sigmaMax == 0" the whole histogram is integrated | |
979 | /// "sigmaStep": the binsize of the generated histogram, -1 means, that the maximal reasonable stepsize is used | |
980 | /// The actual work is done on the array. | |
981 | ||
982 | /* Begin_Latex | |
6a1caa6b | 983 | f(x, #mu, #sigma) #Rightarrow S(t, #mu, #sigma) = #int_{-#infty}^{#mu + t #sigma} f(x, #mu, #sigma) dx / #int_{-#infty}^{+#infty} f(x, #mu, #sigma) dx |
7d855b04 | 984 | End_Latex |
4f3934a1 | 985 | */ |
7d855b04 | 986 | |
4f3934a1 | 987 | Double_t ltmFraction = 0.8; |
7d855b04 | 988 | |
4f3934a1 | 989 | TString drawStr(drawCommand); |
832bb12c | 990 | Bool_t dangerousToDraw = drawStr.Contains(":") || drawStr.Contains(">>"); |
991 | if (dangerousToDraw) { | |
992 | Warning("Integrate", "The draw string must not contain ':' or '>>'."); | |
993 | return -1; | |
994 | } | |
4f3934a1 | 995 | drawStr += " >> tempHist"; |
7d855b04 | 996 | |
4f3934a1 | 997 | Int_t entries = EasyDraw1D(drawStr.Data(), sector, cuts, "goff"); |
998 | TH1F *htemp = (TH1F*)gDirectory->Get("tempHist"); | |
999 | TGraph *integralGraphMean = 0; | |
1000 | TGraph *integralGraphMedian = 0; | |
1001 | TGraph *integralGraphLTM = 0; | |
1002 | Double_t *values = fTree->GetV1(); // value is the array containing 'entries' numbers | |
1003 | Int_t *index = new Int_t[entries]; | |
1004 | Float_t *xarray = new Float_t[entries]; | |
1005 | Float_t *yarray = new Float_t[entries]; | |
1006 | TMath::Sort(entries, values, index, kFALSE); | |
7d855b04 | 1007 | |
4f3934a1 | 1008 | Double_t mean = TMath::Mean(entries, values); |
1009 | Double_t median = TMath::Median(entries, values); | |
1010 | Double_t sigma = TMath::RMS(entries, values); | |
7d855b04 | 1011 | |
4f3934a1 | 1012 | // parse sigmas string |
7d855b04 | 1013 | TObjArray *sigmasTokens = TString(sigmas).Tokenize(";"); |
4f3934a1 | 1014 | TVectorF nsigma(sigmasTokens->GetEntriesFast()); |
1015 | for (Int_t i = 0; i < sigmasTokens->GetEntriesFast(); i++) { | |
1016 | TString str(((TObjString*)sigmasTokens->At(i))->GetString()); | |
1017 | Double_t sig = (str.IsFloat()) ? str.Atof() : 0; | |
1018 | nsigma[i] = sig; | |
1019 | } | |
09d5920f | 1020 | delete sigmasTokens; |
1021 | ||
4f3934a1 | 1022 | TLegend * legend = new TLegend(.7,.7, .99, .99, "Integrated histogram"); |
832bb12c | 1023 | //fListOfObjectsToBeDeleted->Add(legend); |
7d855b04 | 1024 | |
4f3934a1 | 1025 | if (plotMean) { |
1026 | for (Int_t i = 0; i < entries; i++) { | |
7d855b04 | 1027 | xarray[i] = (values[index[i]] - mean) / sigma; |
4f3934a1 | 1028 | yarray[i] = float(i) / float(entries); |
1029 | } | |
1030 | integralGraphMean = new TGraph(entries, xarray, yarray); | |
1031 | if (integralGraphMean) { | |
832bb12c | 1032 | //fListOfObjectsToBeDeleted->Add(integralGraphMean); |
4f3934a1 | 1033 | integralGraphMean->SetLineColor(kRed); |
1034 | legend->AddEntry(integralGraphMean, "Mean", "l"); | |
1035 | integralGraphMean->SetTitle(Form("%s, integrated; Multiples of #sigma; Fraction of included data", htemp->GetTitle())); | |
1036 | integralGraphMean->Draw("alu"); | |
1037 | DrawLines(integralGraphMean, nsigma, legend, kRed, kTRUE); | |
1038 | } | |
1039 | } | |
1040 | if (plotMedian) { | |
1041 | for (Int_t i = 0; i < entries; i++) { | |
7d855b04 | 1042 | xarray[i] = (values[index[i]] - median) / sigma; |
4f3934a1 | 1043 | yarray[i] = float(i) / float(entries); |
1044 | } | |
1045 | integralGraphMedian = new TGraph(entries, xarray, yarray); | |
1046 | if (integralGraphMedian) { | |
832bb12c | 1047 | //fListOfObjectsToBeDeleted->Add(integralGraphMedian); |
4f3934a1 | 1048 | integralGraphMedian->SetLineColor(kBlue); |
1049 | legend->AddEntry(integralGraphMedian, "Median", "l"); | |
1050 | integralGraphMedian->SetTitle(Form("%s, integrated; Multiples of #sigma; Fraction of included data", htemp->GetTitle())); | |
1051 | if (plotMean && integralGraphMean) integralGraphMedian->Draw("samelu"); | |
1052 | else integralGraphMedian->Draw("alu"); | |
1053 | DrawLines(integralGraphMedian, nsigma, legend, kBlue, kTRUE); | |
1054 | } | |
1055 | } | |
1056 | if (plotLTM) { | |
1057 | Double_t ltmRms = 0; | |
1058 | Double_t ltm = GetLTM(entries, values, <mRms, ltmFraction); | |
1059 | for (Int_t i = 0; i < entries; i++) { | |
7d855b04 | 1060 | xarray[i] = (values[index[i]] - ltm) / ltmRms; |
4f3934a1 | 1061 | yarray[i] = float(i) / float(entries); |
1062 | } | |
1063 | integralGraphLTM = new TGraph(entries, xarray, yarray); | |
1064 | if (integralGraphLTM) { | |
832bb12c | 1065 | //fListOfObjectsToBeDeleted->Add(integralGraphLTM); |
4f3934a1 | 1066 | integralGraphLTM->SetLineColor(kGreen+2); |
1067 | legend->AddEntry(integralGraphLTM, "LTM", "l"); | |
1068 | integralGraphLTM->SetTitle(Form("%s, integrated; Multiples of #sigma; Fraction of included data", htemp->GetTitle())); | |
94bf739c | 1069 | if ((plotMean && integralGraphMean) || (plotMedian && integralGraphMedian)) integralGraphLTM->Draw("samelu"); |
4f3934a1 | 1070 | else integralGraphLTM->Draw("alu"); |
1071 | DrawLines(integralGraphLTM, nsigma, legend, kGreen+2, kTRUE); | |
1072 | } | |
1073 | } | |
df5d3222 | 1074 | delete [] index; |
1075 | delete [] xarray; | |
1076 | delete [] yarray; | |
7d855b04 | 1077 | |
4f3934a1 | 1078 | if (!plotMean && !plotMedian && !plotLTM) return -1; |
1079 | legend->Draw(); | |
1080 | return entries; | |
1081 | } | |
1082 | ||
1083 | ||
72d0ab7e | 1084 | void AliTPCCalibViewer::DrawLines(TH1F *histogram, TVectorF nsigma, TLegend *legend, Int_t color, Bool_t pm) const { |
7d855b04 | 1085 | /// Private function for SigmaCut(...) and Integrate(...) |
1086 | /// Draws lines into the given histogram, specified by "nsigma", the lines are addeed to the legend | |
1087 | ||
72d0ab7e | 1088 | // start to draw the lines, loop over requested sigmas |
72d0ab7e | 1089 | for (Int_t i = 0; i < nsigma.GetNoElements(); i++) { |
7d855b04 | 1090 | if (!pm) { |
72d0ab7e | 1091 | Int_t bin = histogram->GetXaxis()->FindBin(nsigma[i]); |
1092 | TLine* lineUp = new TLine(nsigma[i], 0, nsigma[i], histogram->GetBinContent(bin)); | |
832bb12c | 1093 | //fListOfObjectsToBeDeleted->Add(lineUp); |
72d0ab7e | 1094 | lineUp->SetLineColor(color); |
1095 | lineUp->SetLineStyle(2 + i); | |
1096 | lineUp->Draw(); | |
1097 | TLine* lineLeft = new TLine(nsigma[i], histogram->GetBinContent(bin), 0, histogram->GetBinContent(bin)); | |
832bb12c | 1098 | //fListOfObjectsToBeDeleted->Add(lineLeft); |
72d0ab7e | 1099 | lineLeft->SetLineColor(color); |
1100 | lineLeft->SetLineStyle(2 + i); | |
1101 | lineLeft->Draw(); | |
df5d3222 | 1102 | legend->AddEntry(lineLeft, Form("Fraction(%f #sigma) = %f",nsigma[i], histogram->GetBinContent(bin)), "l"); |
72d0ab7e | 1103 | } |
1104 | else { // if (pm) | |
1105 | Int_t bin = histogram->GetXaxis()->FindBin(nsigma[i]); | |
1106 | TLine* lineUp1 = new TLine(nsigma[i], 0, nsigma[i], histogram->GetBinContent(bin)); | |
832bb12c | 1107 | //fListOfObjectsToBeDeleted->Add(lineUp1); |
72d0ab7e | 1108 | lineUp1->SetLineColor(color); |
1109 | lineUp1->SetLineStyle(2 + i); | |
1110 | lineUp1->Draw(); | |
1111 | TLine* lineLeft1 = new TLine(nsigma[i], histogram->GetBinContent(bin), histogram->GetBinLowEdge(0)+histogram->GetBinWidth(0), histogram->GetBinContent(bin)); | |
832bb12c | 1112 | //fListOfObjectsToBeDeleted->Add(lineLeft1); |
72d0ab7e | 1113 | lineLeft1->SetLineColor(color); |
1114 | lineLeft1->SetLineStyle(2 + i); | |
1115 | lineLeft1->Draw(); | |
df5d3222 | 1116 | legend->AddEntry(lineLeft1, Form("Fraction(+%f #sigma) = %f",nsigma[i], histogram->GetBinContent(bin)), "l"); |
72d0ab7e | 1117 | bin = histogram->GetXaxis()->FindBin(-nsigma[i]); |
1118 | TLine* lineUp2 = new TLine(-nsigma[i], 0, -nsigma[i], histogram->GetBinContent(bin)); | |
832bb12c | 1119 | //fListOfObjectsToBeDeleted->Add(lineUp2); |
72d0ab7e | 1120 | lineUp2->SetLineColor(color); |
1121 | lineUp2->SetLineStyle(2 + i); | |
1122 | lineUp2->Draw(); | |
1123 | TLine* lineLeft2 = new TLine(-nsigma[i], histogram->GetBinContent(bin), histogram->GetBinLowEdge(0)+histogram->GetBinWidth(0), histogram->GetBinContent(bin)); | |
832bb12c | 1124 | //fListOfObjectsToBeDeleted->Add(lineLeft2); |
72d0ab7e | 1125 | lineLeft2->SetLineColor(color); |
1126 | lineLeft2->SetLineStyle(2 + i); | |
1127 | lineLeft2->Draw(); | |
df5d3222 | 1128 | legend->AddEntry(lineLeft2, Form("Fraction(-%f #sigma) = %f",nsigma[i], histogram->GetBinContent(bin)), "l"); |
72d0ab7e | 1129 | } |
7d855b04 | 1130 | } // for (Int_t i = 0; i < nsigma.GetNoElements(); i++) |
72d0ab7e | 1131 | } |
1132 | ||
1133 | ||
4f3934a1 | 1134 | void AliTPCCalibViewer::DrawLines(TGraph *graph, TVectorF nsigma, TLegend *legend, Int_t color, Bool_t pm) const { |
7d855b04 | 1135 | /// Private function for SigmaCut(...) and Integrate(...) |
1136 | /// Draws lines into the given histogram, specified by "nsigma", the lines are addeed to the legend | |
1137 | ||
4f3934a1 | 1138 | // start to draw the lines, loop over requested sigmas |
4f3934a1 | 1139 | for (Int_t i = 0; i < nsigma.GetNoElements(); i++) { |
7d855b04 | 1140 | if (!pm) { |
4f3934a1 | 1141 | TLine* lineUp = new TLine(nsigma[i], 0, nsigma[i], graph->Eval(nsigma[i])); |
832bb12c | 1142 | //fListOfObjectsToBeDeleted->Add(lineUp); |
4f3934a1 | 1143 | lineUp->SetLineColor(color); |
1144 | lineUp->SetLineStyle(2 + i); | |
1145 | lineUp->Draw(); | |
1146 | TLine* lineLeft = new TLine(nsigma[i], graph->Eval(nsigma[i]), 0, graph->Eval(nsigma[i])); | |
832bb12c | 1147 | //fListOfObjectsToBeDeleted->Add(lineLeft); |
4f3934a1 | 1148 | lineLeft->SetLineColor(color); |
1149 | lineLeft->SetLineStyle(2 + i); | |
1150 | lineLeft->Draw(); | |
df5d3222 | 1151 | legend->AddEntry(lineLeft, Form("Fraction(%f #sigma) = %f",nsigma[i], graph->Eval(nsigma[i])), "l"); |
4f3934a1 | 1152 | } |
1153 | else { // if (pm) | |
1154 | TLine* lineUp1 = new TLine(nsigma[i], 0, nsigma[i], graph->Eval(nsigma[i])); | |
832bb12c | 1155 | //fListOfObjectsToBeDeleted->Add(lineUp1); |
4f3934a1 | 1156 | lineUp1->SetLineColor(color); |
1157 | lineUp1->SetLineStyle(2 + i); | |
1158 | lineUp1->Draw(); | |
1159 | TLine* lineLeft1 = new TLine(nsigma[i], graph->Eval(nsigma[i]), graph->GetHistogram()->GetXaxis()->GetBinLowEdge(0), graph->Eval(nsigma[i])); | |
832bb12c | 1160 | //fListOfObjectsToBeDeleted->Add(lineLeft1); |
4f3934a1 | 1161 | lineLeft1->SetLineColor(color); |
1162 | lineLeft1->SetLineStyle(2 + i); | |
1163 | lineLeft1->Draw(); | |
df5d3222 | 1164 | legend->AddEntry(lineLeft1, Form("Fraction(+%f #sigma) = %f",nsigma[i], graph->Eval(nsigma[i])), "l"); |
4f3934a1 | 1165 | TLine* lineUp2 = new TLine(-nsigma[i], 0, -nsigma[i], graph->Eval(-nsigma[i])); |
832bb12c | 1166 | //fListOfObjectsToBeDeleted->Add(lineUp2); |
4f3934a1 | 1167 | lineUp2->SetLineColor(color); |
1168 | lineUp2->SetLineStyle(2 + i); | |
1169 | lineUp2->Draw(); | |
1170 | TLine* lineLeft2 = new TLine(-nsigma[i], graph->Eval(-nsigma[i]), graph->GetHistogram()->GetXaxis()->GetBinLowEdge(0), graph->Eval(-nsigma[i])); | |
832bb12c | 1171 | //fListOfObjectsToBeDeleted->Add(lineLeft2); |
4f3934a1 | 1172 | lineLeft2->SetLineColor(color); |
1173 | lineLeft2->SetLineStyle(2 + i); | |
1174 | lineLeft2->Draw(); | |
df5d3222 | 1175 | legend->AddEntry(lineLeft2, Form("Fraction(-%f #sigma) = %f",nsigma[i], graph->Eval(-nsigma[i])), "l"); |
4f3934a1 | 1176 | } |
7d855b04 | 1177 | } // for (Int_t i = 0; i < nsigma.GetNoElements(); i++) |
4f3934a1 | 1178 | } |
1179 | ||
72d0ab7e | 1180 | |
1181 | ||
1182 | ||
1183 | ||
1184 | ///////////////// | |
1185 | // Array tools // | |
1186 | ///////////////// | |
1187 | ||
1188 | ||
1189 | Int_t AliTPCCalibViewer::GetBin(Float_t value, Int_t nbins, Double_t binLow, Double_t binUp){ | |
7d855b04 | 1190 | /// Returns the 'bin' for 'value' |
1191 | /// The interval between 'binLow' and 'binUp' is divided into 'nbins' equidistant bins | |
1192 | /// avoid index out of bounds error: 'if (bin < binLow) bin = binLow' and vice versa | |
1193 | ||
72d0ab7e | 1194 | /* Begin_Latex |
1195 | GetBin(value) = #frac{nbins - 1}{binUp - binLow} #upoint (value - binLow) +1 | |
1196 | End_Latex | |
1197 | */ | |
7d855b04 | 1198 | |
72d0ab7e | 1199 | Int_t bin = TMath::Nint( (Float_t)(value - binLow) / (Float_t)(binUp - binLow) * (nbins-1) ) + 1; |
7d855b04 | 1200 | // avoid index out of bounds: |
72d0ab7e | 1201 | if (value < binLow) bin = 0; |
1202 | if (value > binUp) bin = nbins + 1; | |
1203 | return bin; | |
7d855b04 | 1204 | |
1205 | } | |
39bcd65d | 1206 | |
72d0ab7e | 1207 | |
2811495d | 1208 | Double_t AliTPCCalibViewer::GetLTM(Int_t n, const Double_t *const array, Double_t *const sigma, Double_t fraction){ |
7d855b04 | 1209 | /// returns the LTM and sigma |
1210 | ||
72d0ab7e | 1211 | Double_t *ddata = new Double_t[n]; |
1212 | Double_t mean = 0, lsigma = 0; | |
1213 | UInt_t nPoints = 0; | |
1214 | for (UInt_t i = 0; i < (UInt_t)n; i++) { | |
1215 | ddata[nPoints]= array[nPoints]; | |
1216 | nPoints++; | |
1217 | } | |
1218 | Int_t hh = TMath::Min(TMath::Nint(fraction * nPoints), Int_t(n)); | |
1219 | AliMathBase::EvaluateUni(nPoints, ddata, mean, lsigma, hh); | |
1220 | if (sigma) *sigma = lsigma; | |
1221 | delete [] ddata; | |
1222 | return mean; | |
39bcd65d | 1223 | } |
1224 | ||
1225 | ||
2811495d | 1226 | TH1F* AliTPCCalibViewer::SigmaCut(TH1F *const histogram, Float_t mean, Float_t sigma, Float_t sigmaMax, Float_t sigmaStep, Bool_t pm) { |
7d855b04 | 1227 | /// Creates a cumulative histogram \f$S(t, \mu, \sigma)\f$, where you can see, how much of the data are inside sigma-intervals around the mean value |
1228 | /// The data of the distribution \f$f(x, \mu, \sigma)\f$ are given in 'histogram' | |
1229 | /// 'mean' and 'sigma' are \f$\mu\f$ and \f$\sigma\f$ of the distribution in 'histogram', to be specified by the user | |
1230 | /// sigmaMax: up to which sigma around the mean/median/LTM the histogram is generated (in units of sigma, \f$t \sigma\f$) | |
1231 | /// sigmaStep: the binsize of the generated histogram, -1 means, that the maximal reasonable stepsize is used | |
1232 | /// pm: Decide weather \f$t > 0\f$ (first case) or \f$t\f$ arbitrary (secound case) | |
1233 | /// The actual work is done on the array. | |
1234 | ||
1235 | /* Begin_Latex | |
1236 | f(x, #mu, #sigma) #Rightarrow S(t, #mu, #sigma) = (#int_{#mu}^{#mu + t #sigma} f(x, #mu, #sigma) dx + #int_{#mu}^{#mu - t #sigma} f(x, #mu, #sigma) dx) / (#int_{-#infty}^{+#infty} f(x, #mu, #sigma) dx), for t > 0 | |
1237 | or | |
6a1caa6b | 1238 | f(x, #mu, #sigma) #Rightarrow S(t, #mu, #sigma) = #int_{#mu}^{#mu + t #sigma} f(x, #mu, #sigma) dx / #int_{-#infty}^{+#infty} f(x, #mu, #sigma) dx |
7d855b04 | 1239 | End_Latex |
6a1caa6b | 1240 | Begin_Macro(source) |
72d0ab7e | 1241 | { |
1242 | Float_t mean = 0; | |
1243 | Float_t sigma = 1.5; | |
1244 | Float_t sigmaMax = 4; | |
1245 | gROOT->SetStyle("Plain"); | |
6a1caa6b | 1246 | TH1F *distribution = new TH1F("Distrib1", "Distribution f(x, #mu, #sigma)", 1000,-5,5); |
72d0ab7e | 1247 | TRandom rand(23); |
1248 | for (Int_t i = 0; i <50000;i++) distribution->Fill(rand.Gaus(mean, sigma)); | |
1249 | Float_t *ar = distribution->GetArray(); | |
7d855b04 | 1250 | |
6a1caa6b | 1251 | TCanvas* macro_example_canvas = new TCanvas("cAliTPCCalibViewer1", "", 350, 350); |
72d0ab7e | 1252 | macro_example_canvas->Divide(0,3); |
1253 | TVirtualPad *pad1 = macro_example_canvas->cd(1); | |
1254 | pad1->SetGridy(); | |
1255 | pad1->SetGridx(); | |
1256 | distribution->Draw(); | |
1257 | TVirtualPad *pad2 = macro_example_canvas->cd(2); | |
1258 | pad2->SetGridy(); | |
1259 | pad2->SetGridx(); | |
7d855b04 | 1260 | |
72d0ab7e | 1261 | TH1F *shist = AliTPCCalibViewer::SigmaCut(distribution, mean, sigma, sigmaMax); |
1262 | shist->SetNameTitle("Cumulative","Cumulative S(t, #mu, #sigma)"); | |
7d855b04 | 1263 | shist->Draw(); |
72d0ab7e | 1264 | TVirtualPad *pad3 = macro_example_canvas->cd(3); |
1265 | pad3->SetGridy(); | |
1266 | pad3->SetGridx(); | |
1267 | TH1F *shistPM = AliTPCCalibViewer::SigmaCut(distribution, mean, sigma, sigmaMax, -1, kTRUE); | |
7d855b04 | 1268 | shistPM->Draw(); |
72d0ab7e | 1269 | return macro_example_canvas; |
7d855b04 | 1270 | } |
6a1caa6b | 1271 | End_Macro |
7d855b04 | 1272 | */ |
1273 | ||
72d0ab7e | 1274 | Float_t *array = histogram->GetArray(); |
1275 | Int_t nbins = histogram->GetXaxis()->GetNbins(); | |
1276 | Float_t binLow = histogram->GetXaxis()->GetXmin(); | |
1277 | Float_t binUp = histogram->GetXaxis()->GetXmax(); | |
1278 | return AliTPCCalibViewer::SigmaCut(nbins, array, mean, sigma, nbins, binLow, binUp, sigmaMax, sigmaStep, pm); | |
7d855b04 | 1279 | } |
1280 | ||
72d0ab7e | 1281 | |
2811495d | 1282 | TH1F* AliTPCCalibViewer::SigmaCut(Int_t n, const Float_t *array, Float_t mean, Float_t sigma, Int_t nbins, Float_t binLow, Float_t binUp, Float_t sigmaMax, Float_t sigmaStep, Bool_t pm){ |
7d855b04 | 1283 | /// Creates a histogram \f$S(t, \mu, \sigma)\f$, where you can see, how much of the data are inside sigma-intervals around the mean value |
1284 | /// The data of the distribution \f$f(x, \mu, \sigma)\f$ are given in 'array', 'n' specifies the length of the array | |
1285 | /// 'mean' and 'sigma' are \f$\mu\f$ and \f$\sigma\f$ of the distribution in 'array', to be specified by the user | |
1286 | /// 'nbins': number of bins, 'binLow': first bin, 'binUp': last bin | |
1287 | /// sigmaMax: up to which sigma around the mean/median/LTM the histogram is generated (in units of sigma, \f$t \sigma\f$) | |
1288 | /// sigmaStep: the binsize of the generated histogram | |
1289 | /// Here the actual work is done. | |
1290 | ||
72d0ab7e | 1291 | if (sigma == 0) return 0; |
1292 | Float_t binWidth = (binUp-binLow)/(nbins - 1); | |
1293 | if (sigmaStep <= 0) sigmaStep = binWidth; | |
1294 | Int_t kbins = (Int_t)(sigmaMax * sigma / sigmaStep) + 1; // + 1 due to overflow bin in histograms | |
1295 | if (pm) kbins = 2 * (Int_t)(sigmaMax * sigma / sigmaStep) + 1; | |
1296 | Float_t kbinLow = !pm ? 0 : -sigmaMax; | |
1297 | Float_t kbinUp = sigmaMax; | |
7d855b04 | 1298 | TH1F *hist = new TH1F("sigmaCutHisto","Cumulative; Multiples of #sigma; Fraction of included data", kbins, kbinLow, kbinUp); |
72d0ab7e | 1299 | hist->SetDirectory(0); |
1300 | hist->Reset(); | |
7d855b04 | 1301 | |
72d0ab7e | 1302 | // calculate normalization |
1303 | Double_t normalization = 0; | |
1304 | for (Int_t i = 0; i <= n; i++) { | |
1305 | normalization += array[i]; | |
1306 | } | |
7d855b04 | 1307 | |
72d0ab7e | 1308 | // given units: units from given histogram |
1309 | // sigma units: in units of sigma | |
1310 | // iDelta: integrate in interval (mean +- iDelta), given units | |
1311 | // x: ofset from mean for integration, given units | |
7d855b04 | 1312 | // hist: needs |
1313 | ||
72d0ab7e | 1314 | // printf("nbins: %i, binLow: %f, binUp: %f \n", nbins, binLow, binUp); |
1315 | // fill histogram | |
1316 | for (Float_t iDelta = 0; iDelta <= sigmaMax * sigma; iDelta += sigmaStep) { | |
1317 | // integrate array | |
1318 | Double_t valueP = array[GetBin(mean, nbins, binLow, binUp)]; | |
1319 | Double_t valueM = array[GetBin(mean-binWidth, nbins, binLow, binUp)]; | |
1320 | // add bin of mean value only once to the histogram | |
1321 | // printf("++ adding bins: "); | |
1322 | for (Float_t x = binWidth; x <= iDelta; x += binWidth) { | |
1323 | valueP += (mean + x <= binUp) ? array[GetBin(mean + x, nbins, binLow, binUp)] : 0; | |
7d855b04 | 1324 | valueM += (mean-binWidth - x >= binLow) ? array[GetBin(mean-binWidth - x, nbins, binLow, binUp)] : 0; |
1325 | // printf("%i, ", GetBin(mean + x, nbins, binLow, binUp)); | |
72d0ab7e | 1326 | } |
1327 | // printf("\n"); | |
1328 | if (valueP / normalization > 100) printf("+++ Error, value to big: %f, normalization with %f will fail +++ \n", valueP, normalization); | |
1329 | if (valueP / normalization > 100) return hist; | |
1330 | if (valueM / normalization > 100) printf("+++ Error, value to big: %f, normalization with %f will fail +++ \n", valueM, normalization); | |
1331 | if (valueM / normalization > 100) return hist; | |
1332 | valueP = (valueP / normalization); | |
1333 | valueM = (valueM / normalization); | |
1334 | if (pm) { | |
1335 | Int_t bin = GetBin(iDelta/sigma, kbins, kbinLow, kbinUp); | |
1336 | hist->SetBinContent(bin, valueP); | |
1337 | bin = GetBin(-iDelta/sigma, kbins, kbinLow, kbinUp); | |
1338 | hist->SetBinContent(bin, valueM); | |
1339 | } | |
1340 | else { // if (!pm) | |
1341 | Int_t bin = GetBin(iDelta/sigma, kbins, kbinLow, kbinUp); | |
1342 | hist->SetBinContent(bin, valueP + valueM); | |
1343 | // printf(" first integration bin: %i, last integration bin in + direction: %i \n", GetBin(mean+binWidth, nbins, binLow, binUp), GetBin(iDelta, nbins, binLow, binUp)); | |
1344 | // printf(" first integration bin: %i, last integration bin in - direction: %i \n", GetBin(mean+binWidth, nbins, binLow, binUp), GetBin(-iDelta, nbins, binLow, binUp)); | |
1345 | // printf(" value: %f, normalization: %f, iDelta: %f, Bin: %i \n", valueP+valueM, normalization, iDelta, bin); | |
1346 | } | |
1347 | } | |
1348 | //hist->SetMaximum(0.7); | |
1349 | if (!pm) hist->SetMaximum(1.2); | |
1350 | return hist; | |
1351 | } | |
1352 | ||
1353 | ||
2773a273 | 1354 | TH1F* AliTPCCalibViewer::SigmaCut(Int_t /*n*/, const Double_t */*array*/, Double_t /*mean*/, Double_t /*sigma*/, Int_t /*nbins*/, const Double_t */*xbins*/, Double_t /*sigmaMax*/){ |
7d855b04 | 1355 | /// SigmaCut for variable binsize |
1356 | /// NOT YET IMPLEMENTED !!! | |
1357 | ||
72d0ab7e | 1358 | printf("SigmaCut with variable binsize, Not yet implemented\n"); |
7d855b04 | 1359 | |
72d0ab7e | 1360 | return 0; |
7d855b04 | 1361 | } |
72d0ab7e | 1362 | |
1363 | ||
2811495d | 1364 | TH1F* AliTPCCalibViewer::Integrate(TH1F *const histogram, Float_t mean, Float_t sigma, Float_t sigmaMax, Float_t sigmaStep){ |
7d855b04 | 1365 | /// Creates an integrated histogram \f$S(t, \mu, \sigma)\f$, out of the input distribution distribution \f$f(x, \mu, \sigma)\f$, given in "histogram" |
1366 | /// "mean" and "sigma" are \f$\mu\f$ and \f$\sigma\f$ of the distribution in "histogram", to be specified by the user | |
1367 | /// sigmaMax: up to which sigma around the mean/median/LTM you want to integrate | |
1368 | /// if "igma == 0" and "sigmaMax == 0" the whole histogram is integrated | |
1369 | /// "sigmaStep": the binsize of the generated histogram, -1 means, that the maximal reasonable stepsize is used | |
1370 | /// The actual work is done on the array. | |
1371 | ||
1372 | /* Begin_Latex | |
6a1caa6b | 1373 | f(x, #mu, #sigma) #Rightarrow S(t, #mu, #sigma) = #int_{-#infty}^{#mu + t #sigma} f(x, #mu, #sigma) dx / #int_{-#infty}^{+#infty} f(x, #mu, #sigma) dx |
7d855b04 | 1374 | End_Latex |
6a1caa6b | 1375 | Begin_Macro(source) |
72d0ab7e | 1376 | { |
1377 | Float_t mean = 0; | |
1378 | Float_t sigma = 1.5; | |
1379 | Float_t sigmaMax = 4; | |
1380 | gROOT->SetStyle("Plain"); | |
6a1caa6b | 1381 | TH1F *distribution = new TH1F("Distrib2", "Distribution f(x, #mu, #sigma)", 1000,-5,5); |
72d0ab7e | 1382 | TRandom rand(23); |
1383 | for (Int_t i = 0; i <50000;i++) distribution->Fill(rand.Gaus(mean, sigma)); | |
1384 | Float_t *ar = distribution->GetArray(); | |
7d855b04 | 1385 | |
6a1caa6b | 1386 | TCanvas* macro_example_canvas = new TCanvas("cAliTPCCalibViewer2", "", 350, 350); |
72d0ab7e | 1387 | macro_example_canvas->Divide(0,2); |
1388 | TVirtualPad *pad1 = macro_example_canvas->cd(1); | |
1389 | pad1->SetGridy(); | |
1390 | pad1->SetGridx(); | |
1391 | distribution->Draw(); | |
1392 | TVirtualPad *pad2 = macro_example_canvas->cd(2); | |
1393 | pad2->SetGridy(); | |
1394 | pad2->SetGridx(); | |
1395 | TH1F *shist = AliTPCCalibViewer::Integrate(distribution, mean, sigma, sigmaMax); | |
1396 | shist->SetNameTitle("Cumulative","Cumulative S(t, #mu, #sigma)"); | |
7d855b04 | 1397 | shist->Draw(); |
1398 | ||
1399 | } | |
6a1caa6b | 1400 | End_Macro |
7d855b04 | 1401 | */ |
1402 | ||
72d0ab7e | 1403 | |
72d0ab7e | 1404 | Float_t *array = histogram->GetArray(); |
1405 | Int_t nbins = histogram->GetXaxis()->GetNbins(); | |
1406 | Float_t binLow = histogram->GetXaxis()->GetXmin(); | |
1407 | Float_t binUp = histogram->GetXaxis()->GetXmax(); | |
1408 | return AliTPCCalibViewer::Integrate(nbins, array, nbins, binLow, binUp, mean, sigma, sigmaMax, sigmaStep); | |
7d855b04 | 1409 | } |
72d0ab7e | 1410 | |
1411 | ||
2811495d | 1412 | TH1F* AliTPCCalibViewer::Integrate(Int_t n, const Float_t *const array, Int_t nbins, Float_t binLow, Float_t binUp, Float_t mean, Float_t sigma, Float_t sigmaMax, Float_t sigmaStep){ |
7d855b04 | 1413 | /// Creates an integrated histogram \f$S(t, \mu, \sigma)\f$, out of the input distribution distribution \f$f(x, \mu, \sigma)\f$, given in "histogram" |
1414 | /// "mean" and "sigma" are \f$\mu\f$ and \f$\sigma\f$ of the distribution in "histogram", to be specified by the user | |
1415 | /// sigmaMax: up to which sigma around the mean/median/LTM you want to integrate | |
1416 | /// if "igma == 0" and "sigmaMax == 0" the whole histogram is integrated | |
1417 | /// "sigmaStep": the binsize of the generated histogram, -1 means, that the maximal reasonable stepsize is used | |
1418 | /// Here the actual work is done. | |
1419 | ||
72d0ab7e | 1420 | Bool_t givenUnits = kTRUE; |
1421 | if (sigma != 0 && sigmaMax != 0) givenUnits = kFALSE; | |
1422 | if (givenUnits) { | |
1423 | sigma = 1; | |
1424 | sigmaMax = (binUp - binLow) / 2.; | |
1425 | } | |
7d855b04 | 1426 | |
72d0ab7e | 1427 | Float_t binWidth = (binUp-binLow)/(nbins - 1); |
1428 | if (sigmaStep <= 0) sigmaStep = binWidth; | |
1429 | Int_t kbins = (Int_t)(sigmaMax * sigma / sigmaStep) + 1; // + 1 due to overflow bin in histograms | |
1430 | Float_t kbinLow = givenUnits ? binLow : -sigmaMax; | |
1431 | Float_t kbinUp = givenUnits ? binUp : sigmaMax; | |
7d855b04 | 1432 | TH1F *hist = 0; |
1433 | if (givenUnits) hist = new TH1F("integratedHisto","Integrated Histogram; Given x; Fraction of included data", kbins, kbinLow, kbinUp); | |
1434 | if (!givenUnits) hist = new TH1F("integratedHisto","Integrated Histogram; Multiples of #sigma; Fraction of included data", kbins, kbinLow, kbinUp); | |
72d0ab7e | 1435 | hist->SetDirectory(0); |
1436 | hist->Reset(); | |
7d855b04 | 1437 | |
72d0ab7e | 1438 | // calculate normalization |
1439 | // printf("calculating normalization, integrating from bin 1 to %i \n", n); | |
1440 | Double_t normalization = 0; | |
1441 | for (Int_t i = 1; i <= n; i++) { | |
1442 | normalization += array[i]; | |
1443 | } | |
1444 | // printf("normalization: %f \n", normalization); | |
7d855b04 | 1445 | |
72d0ab7e | 1446 | // given units: units from given histogram |
1447 | // sigma units: in units of sigma | |
1448 | // iDelta: integrate in interval (mean +- iDelta), given units | |
1449 | // x: ofset from mean for integration, given units | |
7d855b04 | 1450 | // hist: needs |
1451 | ||
72d0ab7e | 1452 | // fill histogram |
1453 | for (Float_t iDelta = mean - sigmaMax * sigma; iDelta <= mean + sigmaMax * sigma; iDelta += sigmaStep) { | |
1454 | // integrate array | |
1455 | Double_t value = 0; | |
1456 | for (Float_t x = mean - sigmaMax * sigma; x <= iDelta; x += binWidth) { | |
1457 | value += (x <= binUp && x >= binLow) ? array[GetBin(x, nbins, binLow, binUp)] : 0; | |
1458 | } | |
1459 | if (value / normalization > 100) printf("+++ Error, value to big: %f, normalization with %f will fail +++ \n", value, normalization); | |
1460 | if (value / normalization > 100) return hist; | |
1461 | Int_t bin = GetBin(iDelta/sigma, kbins, kbinLow, kbinUp); | |
1462 | // printf("first integration bin: %i, last integration bin: %i \n", GetBin(mean - sigmaMax * sigma, nbins, binLow, binUp), GetBin(iDelta, nbins, binLow, binUp)); | |
1463 | // printf("value: %f, normalization: %f, normalized value: %f, iDelta: %f, Bin: %i \n", value, normalization, value/normalization, iDelta, bin); | |
1464 | value = (value / normalization); | |
1465 | hist->SetBinContent(bin, value); | |
1466 | } | |
1467 | return hist; | |
1468 | } | |
1469 | ||
1470 | ||
1471 | ||
1472 | ||
1473 | ||
1474 | //////////////////////// | |
1475 | // end of Array tools // | |
1476 | //////////////////////// | |
1477 | ||
1478 | ||
1479 | ||
39bcd65d | 1480 | //_____________________________________________________________________________ |
a6e0ebfe | 1481 | AliTPCCalPad* AliTPCCalibViewer::GetCalPadOld(const char* desiredData, const char* cuts, const char* calPadName) const { |
7d855b04 | 1482 | /// creates a AliTPCCalPad out of the 'desiredData' |
1483 | /// the functionality of EasyDraw1D is used | |
1484 | /// calPadName specifies the name of the created AliTPCCalPad | |
1485 | /// - this takes a while - | |
1486 | ||
39bcd65d | 1487 | TString drawStr(desiredData); |
832bb12c | 1488 | drawStr.Append(":channel"); |
1489 | drawStr.Append(fAbbreviation); | |
39bcd65d | 1490 | AliTPCCalPad * createdCalPad = new AliTPCCalPad(calPadName, calPadName); |
1491 | Int_t entries = 0; | |
1492 | for (Int_t sec = 0; sec < 72; sec++) { | |
ac7becc3 | 1493 | AliTPCCalROC * roc = createdCalPad->GetCalROC(sec); |
39bcd65d | 1494 | entries = EasyDraw1D(drawStr.Data(), (Int_t)sec, cuts, "goff"); |
a6d2bd0c | 1495 | if (entries == -1) return 0; |
ac7becc3 | 1496 | const Double_t *pchannel = fTree->GetV2(); |
1497 | const Double_t *pvalue = fTree->GetV1(); | |
7d855b04 | 1498 | for (Int_t i = 0; i < entries; i++) |
ac7becc3 | 1499 | roc->SetValue((UInt_t)(pchannel[i]), (Float_t)(pvalue[i])); |
1500 | } | |
7d855b04 | 1501 | return createdCalPad; |
ac7becc3 | 1502 | } |
1503 | ||
1504 | ||
1505 | //_____________________________________________________________________________ | |
a6e0ebfe | 1506 | AliTPCCalPad* AliTPCCalibViewer::GetCalPad(const char* desiredData, const char* cuts, const char* calPadName) const { |
7d855b04 | 1507 | /// creates a AliTPCCalPad out of the 'desiredData' |
1508 | /// the functionality of EasyDraw1D is used | |
1509 | /// calPadName specifies the name of the created AliTPCCalPad | |
1510 | /// - this takes a while - | |
1511 | ||
ac7becc3 | 1512 | TString drawStr(desiredData); |
1513 | drawStr.Append(":channel.fElements:sector"); | |
1514 | AliTPCCalPad * createdCalPad = new AliTPCCalPad(calPadName, calPadName); | |
1515 | // | |
1516 | Int_t entries = fTree->Draw(drawStr, cuts,"goff"); | |
1517 | const Double_t *pvalue = fTree->GetV1(); | |
1518 | const Double_t *pchannel = fTree->GetV2(); | |
1519 | const Double_t *psector = fTree->GetV3(); | |
1520 | ||
1521 | for (Int_t ientry=0; ientry<entries; ientry++){ | |
1522 | Int_t sector= TMath::Nint(psector[ientry]); | |
1523 | AliTPCCalROC * roc = createdCalPad->GetCalROC(sector); | |
1524 | if (roc) roc->SetValue((UInt_t)(pchannel[ientry]), (Float_t)(pvalue[ientry])); | |
39bcd65d | 1525 | } |
ac7becc3 | 1526 | |
1527 | // for (Int_t sec = 0; sec < 72; sec++) { | |
1528 | // AliTPCCalROC * roc = createdCalPad->GetCalROC(sec); | |
1529 | // entries = EasyDraw1D(drawStr.Data(), (Int_t)sec, cuts, "goff"); | |
1530 | // if (entries == -1) return 0; | |
7d855b04 | 1531 | // for (Int_t i = 0; i < entries; i++) |
ac7becc3 | 1532 | // roc->SetValue((UInt_t)(pchannel[i]), (Float_t)(pvalue[i])); |
1533 | // } | |
7d855b04 | 1534 | return createdCalPad; |
39bcd65d | 1535 | } |
1536 | ||
1537 | //_____________________________________________________________________________ | |
f78da5ae | 1538 | AliTPCCalROC* AliTPCCalibViewer::GetCalROC(const char* desiredData, UInt_t sector, const char* cuts) const { |
7d855b04 | 1539 | /// creates a AliTPCCalROC out of the desiredData |
1540 | /// the functionality of EasyDraw1D is used | |
1541 | /// sector specifies the sector of the created AliTPCCalROC | |
1542 | ||
39bcd65d | 1543 | TString drawStr(desiredData); |
8192627b | 1544 | drawStr.Append(":channel"); |
1545 | drawStr.Append(fAbbreviation); | |
39bcd65d | 1546 | Int_t entries = EasyDraw1D(drawStr.Data(), (Int_t)sector, cuts, "goff"); |
a6d2bd0c | 1547 | if (entries == -1) return 0; |
39bcd65d | 1548 | AliTPCCalROC * createdROC = new AliTPCCalROC(sector); |
7d855b04 | 1549 | for (Int_t i = 0; i < entries; i++) |
39bcd65d | 1550 | createdROC->SetValue((UInt_t)(fTree->GetV2()[i]), fTree->GetV1()[i]); |
1551 | return createdROC; | |
1552 | } | |
1553 | ||
1554 | ||
1555 | TObjArray* AliTPCCalibViewer::GetListOfVariables(Bool_t printList) { | |
7d855b04 | 1556 | /// scan the tree - produces a list of available variables in the tree |
1557 | /// printList: print the list to the screen, after the scan is done | |
1558 | ||
39bcd65d | 1559 | TObjArray* arr = new TObjArray(); |
1560 | TObjString* str = 0; | |
596afefb | 1561 | if (!fTree) return 0; |
39bcd65d | 1562 | Int_t nentries = fTree->GetListOfBranches()->GetEntries(); |
1563 | for (Int_t i = 0; i < nentries; i++) { | |
1564 | str = new TObjString(fTree->GetListOfBranches()->At(i)->GetName()); | |
1565 | str->String().ReplaceAll("_Median", ""); | |
1566 | str->String().ReplaceAll("_Mean", ""); | |
1567 | str->String().ReplaceAll("_RMS", ""); | |
1568 | str->String().ReplaceAll("_LTM", ""); | |
1569 | str->String().ReplaceAll("_OutlierCutted", ""); | |
1570 | str->String().ReplaceAll(".", ""); | |
7d855b04 | 1571 | if (!arr->FindObject(str) && |
1572 | !(str->String() == "channel" || str->String() == "gx" || str->String() == "gy" || | |
1573 | str->String() == "lx" || str->String() == "ly" || str->String() == "pad" || | |
39bcd65d | 1574 | str->String() == "row" || str->String() == "rpad" || str->String() == "sector" )) |
1575 | arr->Add(str); | |
1576 | } | |
7d855b04 | 1577 | |
832bb12c | 1578 | // loop over all friends (if there are some) and add them to the list |
1579 | if (fTree->GetListOfFriends()) { | |
1580 | for (Int_t ifriend = 0; ifriend < fTree->GetListOfFriends()->GetEntries(); ifriend++){ | |
1581 | // printf("iterating through friendlist, currently at %i\n", ifriend); | |
1582 | // printf("working with %s\n", fTree->GetListOfFriends()->At(ifriend)->ClassName()); | |
1583 | if (TString(fTree->GetListOfFriends()->At(ifriend)->ClassName()) != "TFriendElement") continue; // no friendElement found | |
1584 | TFriendElement *friendElement = (TFriendElement*)fTree->GetListOfFriends()->At(ifriend); | |
1585 | if (friendElement->GetTree() == 0) continue; // no tree found in friendElement | |
1586 | // printf("friend found \n"); | |
1587 | for (Int_t i = 0; i < friendElement->GetTree()->GetListOfBranches()->GetEntries(); i++) { | |
1588 | // printf("iterating through friendelement entries, currently at %i\n", i); | |
1589 | str = new TObjString(friendElement->GetTree()->GetListOfBranches()->At(i)->GetName()); | |
1590 | str->String().ReplaceAll("_Median", ""); | |
1591 | str->String().ReplaceAll("_Mean", ""); | |
1592 | str->String().ReplaceAll("_RMS", ""); | |
1593 | str->String().ReplaceAll("_LTM", ""); | |
1594 | str->String().ReplaceAll("_OutlierCutted", ""); | |
1595 | str->String().ReplaceAll(".", ""); | |
7d855b04 | 1596 | if (!(str->String() == "channel" || str->String() == "gx" || str->String() == "gy" || |
1597 | str->String() == "lx" || str->String() == "ly" || str->String() == "pad" || | |
832bb12c | 1598 | str->String() == "row" || str->String() == "rpad" || str->String() == "sector" )){ |
1599 | // insert "<friendName>." at the beginning: (<friendName> is per default "R") | |
1600 | str->String().Insert(0, "."); | |
1601 | str->String().Insert(0, friendElement->GetName()); | |
1602 | if (!arr->FindObject(str)) arr->Add(str); | |
1603 | // printf("added string %s \n", str->String().Data()); | |
1604 | } | |
1605 | } | |
1606 | } | |
1607 | } // if (fTree->GetListOfFriends()) | |
7d855b04 | 1608 | |
39bcd65d | 1609 | arr->Sort(); |
832bb12c | 1610 | // ((TFriendElement*)gui->GetViewer()->GetTree()->GetListOfFriends()->At(0))->GetTree()->GetListOfBranches()->At(0)->GetName() |
1611 | // ((TFriendElement*)gui->GetViewer()->GetTree()->GetListOfFriends()->At(0))->GetTree()->GetListOfBranches() | |
1612 | ||
39bcd65d | 1613 | |
1614 | if (printList) { | |
1615 | TIterator* iter = arr->MakeIterator(); | |
1616 | iter->Reset(); | |
1617 | TObjString* currentStr = 0; | |
1618 | while ( (currentStr = (TObjString*)(iter->Next())) ) { | |
1619 | std::cout << currentStr->GetString().Data() << std::endl; | |
1620 | } | |
1621 | delete iter; | |
1622 | } | |
1623 | return arr; | |
1624 | } | |
1625 | ||
1626 | ||
72d0ab7e | 1627 | TObjArray* AliTPCCalibViewer::GetListOfNormalizationVariables(Bool_t printList) const{ |
7d855b04 | 1628 | /// produces a list of available variables for normalization in the tree |
1629 | /// printList: print the list to the screen, after the scan is done | |
1630 | ||
39bcd65d | 1631 | TObjArray* arr = new TObjArray(); |
1632 | arr->Add(new TObjString("_Mean")); | |
1633 | arr->Add(new TObjString("_Mean_OutlierCutted")); | |
1634 | arr->Add(new TObjString("_Median")); | |
1635 | arr->Add(new TObjString("_Median_OutlierCutted")); | |
1636 | arr->Add(new TObjString("_LTM")); | |
1637 | arr->Add(new TObjString("_LTM_OutlierCutted")); | |
832bb12c | 1638 | arr->Add(new TObjString(Form("LFitIntern_4_8%s", fAppendString.Data()))); |
1639 | arr->Add(new TObjString(Form("GFitIntern_Lin%s", fAppendString.Data()))); | |
1640 | arr->Add(new TObjString(Form("GFitIntern_Par%s", fAppendString.Data()))); | |
a6d2bd0c | 1641 | arr->Add(new TObjString("FitLinLocal")); |
1642 | arr->Add(new TObjString("FitLinGlobal")); | |
72d0ab7e | 1643 | arr->Add(new TObjString("FitParLocal")); |
1644 | arr->Add(new TObjString("FitParGlobal")); | |
39bcd65d | 1645 | |
1646 | if (printList) { | |
1647 | TIterator* iter = arr->MakeIterator(); | |
1648 | iter->Reset(); | |
1649 | TObjString* currentStr = 0; | |
1650 | while ((currentStr = (TObjString*)(iter->Next()))) { | |
1651 | std::cout << currentStr->GetString().Data() << std::endl; | |
1652 | } | |
1653 | delete iter; | |
1654 | } | |
1655 | return arr; | |
1656 | } | |
1657 | ||
1658 | ||
1659 | TFriendElement* AliTPCCalibViewer::AddReferenceTree(const char* filename, const char* treename, const char* refname){ | |
7d855b04 | 1660 | /// add a reference tree to the current tree |
1661 | /// by default the treename is 'calPads' and the reference treename is 'R' | |
1662 | ||
39bcd65d | 1663 | TFile *file = new TFile(filename); |
1664 | fListOfObjectsToBeDeleted->Add(file); | |
1665 | TTree * tree = (TTree*)file->Get(treename); | |
1666 | return AddFriend(tree, refname); | |
1667 | } | |
1668 | ||
1669 | ||
1670 | TObjArray* AliTPCCalibViewer::GetArrayOfCalPads(){ | |
7d855b04 | 1671 | /// Returns a TObjArray with all AliTPCCalPads that are stored in the tree |
1672 | /// - this takes a while - | |
1673 | ||
39bcd65d | 1674 | TObjArray *listOfCalPads = GetListOfVariables(); |
1675 | TObjArray *calPadsArray = new TObjArray(); | |
1676 | Int_t numberOfCalPads = listOfCalPads->GetEntries(); | |
1677 | for (Int_t i = 0; i < numberOfCalPads; i++) { | |
832bb12c | 1678 | std::cout << "Creating calPad " << (i+1) << " of " << numberOfCalPads << "\r" << std::flush; |
39bcd65d | 1679 | char* calPadName = (char*)((TObjString*)(listOfCalPads->At(i)))->GetString().Data(); |
1680 | TString drawCommand = ((TObjString*)(listOfCalPads->At(i)))->GetString(); | |
832bb12c | 1681 | drawCommand.Append(fAbbreviation.Data()); |
7d855b04 | 1682 | AliTPCCalPad* calPad = GetCalPad(drawCommand.Data(), "", calPadName); |
1683 | calPadsArray->Add(calPad); | |
39bcd65d | 1684 | } |
1685 | std::cout << std::endl; | |
1686 | listOfCalPads->Delete(); | |
1687 | delete listOfCalPads; | |
1688 | return calPadsArray; | |
1689 | } | |
1690 | ||
1691 | ||
a6d2bd0c | 1692 | TString* AliTPCCalibViewer::Fit(const char* drawCommand, const char* formula, const char* cuts, Double_t & chi2, TVectorD &fitParam, TMatrixD &covMatrix){ |
7d855b04 | 1693 | /// fit an arbitrary function, specified by formula into the data, specified by drawCommand and cuts |
1694 | /// returns chi2, fitParam and covMatrix | |
1695 | /// returns TString with fitted formula | |
1696 | ||
1697 | TString formulaStr(formula); | |
a6d2bd0c | 1698 | TString drawStr(drawCommand); |
1699 | TString cutStr(cuts); | |
7d855b04 | 1700 | |
a6d2bd0c | 1701 | // abbreviations: |
832bb12c | 1702 | drawStr.ReplaceAll(fAbbreviation, fAppendString); |
1703 | cutStr.ReplaceAll(fAbbreviation, fAppendString); | |
1704 | formulaStr.ReplaceAll(fAbbreviation, fAppendString); | |
7d855b04 | 1705 | |
832bb12c | 1706 | formulaStr.ReplaceAll("++", fAbbreviation); |
7d855b04 | 1707 | TObjArray* formulaTokens = formulaStr.Tokenize(fAbbreviation.Data()); |
a6d2bd0c | 1708 | Int_t dim = formulaTokens->GetEntriesFast(); |
7d855b04 | 1709 | |
a6d2bd0c | 1710 | fitParam.ResizeTo(dim); |
1711 | covMatrix.ResizeTo(dim,dim); | |
7d855b04 | 1712 | |
a6d2bd0c | 1713 | TLinearFitter* fitter = new TLinearFitter(dim+1, Form("hyp%d",dim)); |
7d855b04 | 1714 | fitter->StoreData(kTRUE); |
a6d2bd0c | 1715 | fitter->ClearPoints(); |
7d855b04 | 1716 | |
a6d2bd0c | 1717 | Int_t entries = Draw(drawStr.Data(), cutStr.Data(), "goff"); |
09d5920f | 1718 | if (entries == -1) { |
1719 | delete formulaTokens; | |
1720 | return new TString("An ERROR has occured during fitting!"); | |
1721 | } | |
7d855b04 | 1722 | Double_t **values = new Double_t*[dim+1] ; |
1723 | ||
a6d2bd0c | 1724 | for (Int_t i = 0; i < dim + 1; i++){ |
1725 | Int_t centries = 0; | |
1726 | if (i < dim) centries = fTree->Draw(((TObjString*)formulaTokens->At(i))->GetName(), cutStr.Data(), "goff"); | |
1727 | else centries = fTree->Draw(drawStr.Data(), cutStr.Data(), "goff"); | |
7d855b04 | 1728 | |
c60053f6 | 1729 | if (entries != centries) { |
1730 | delete [] values; | |
09d5920f | 1731 | delete formulaTokens; |
c60053f6 | 1732 | return new TString("An ERROR has occured during fitting!"); |
1733 | } | |
a6d2bd0c | 1734 | values[i] = new Double_t[entries]; |
7d855b04 | 1735 | memcpy(values[i], fTree->GetV1(), entries*sizeof(Double_t)); |
a6d2bd0c | 1736 | } |
7d855b04 | 1737 | |
a6d2bd0c | 1738 | // add points to the fitter |
1739 | for (Int_t i = 0; i < entries; i++){ | |
1740 | Double_t x[1000]; | |
1741 | for (Int_t j=0; j<dim;j++) x[j]=values[j][i]; | |
1742 | fitter->AddPoint(x, values[dim][i], 1); | |
1743 | } | |
1744 | ||
1745 | fitter->Eval(); | |
1746 | fitter->GetParameters(fitParam); | |
1747 | fitter->GetCovarianceMatrix(covMatrix); | |
1748 | chi2 = fitter->GetChisquare(); | |
df5d3222 | 1749 | // chi2 = chi2; |
7d855b04 | 1750 | |
7390f655 | 1751 | TString *preturnFormula = new TString(Form("( %e+",fitParam[0])), &returnFormula = *preturnFormula; |
7d855b04 | 1752 | |
a6d2bd0c | 1753 | for (Int_t iparam = 0; iparam < dim; iparam++) { |
7390f655 | 1754 | returnFormula.Append(Form("%s*(%e)",((TObjString*)formulaTokens->At(iparam))->GetName(),fitParam[iparam+1])); |
a6d2bd0c | 1755 | if (iparam < dim-1) returnFormula.Append("+"); |
1756 | } | |
1757 | returnFormula.Append(" )"); | |
1758 | delete formulaTokens; | |
1759 | delete fitter; | |
c60053f6 | 1760 | for (Int_t i = 0; i < dim + 1; i++){ |
1761 | delete [] values[i]; | |
1762 | } | |
1763 | delete [] values; | |
a6d2bd0c | 1764 | return preturnFormula; |
1765 | } | |
1766 | ||
1767 | ||
2811495d | 1768 | void AliTPCCalibViewer::MakeTreeWithObjects(const char *fileName, const TObjArray *const array, const char * mapFileName) { |
7d855b04 | 1769 | /// Write tree with all available information |
1770 | /// im mapFileName is speciefied, the Map information are also written to the tree | |
1771 | /// AliTPCCalPad-Objects are written directly to the tree, so that they can be accessd later on | |
1772 | /// (does not work!!!) | |
1773 | ||
39bcd65d | 1774 | AliTPCROC* tpcROCinstance = AliTPCROC::Instance(); |
1775 | ||
1776 | TObjArray* mapIROCs = 0; | |
1777 | TObjArray* mapOROCs = 0; | |
1778 | TVectorF *mapIROCArray = 0; | |
1779 | TVectorF *mapOROCArray = 0; | |
1780 | Int_t mapEntries = 0; | |
1781 | TString* mapNames = 0; | |
7d855b04 | 1782 | |
39bcd65d | 1783 | if (mapFileName) { |
1784 | TFile mapFile(mapFileName, "read"); | |
7d855b04 | 1785 | |
39bcd65d | 1786 | TList* listOfROCs = mapFile.GetListOfKeys(); |
1787 | mapEntries = listOfROCs->GetEntries()/2; | |
1788 | mapIROCs = new TObjArray(mapEntries*2); | |
1789 | mapOROCs = new TObjArray(mapEntries*2); | |
1790 | mapIROCArray = new TVectorF[mapEntries]; | |
1791 | mapOROCArray = new TVectorF[mapEntries]; | |
7d855b04 | 1792 | |
39bcd65d | 1793 | mapNames = new TString[mapEntries]; |
1794 | for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) { | |
72d0ab7e | 1795 | TString rocName(((TKey*)(listOfROCs->At(ivalue*2)))->GetName()); |
1796 | rocName.Remove(rocName.Length()-4, 4); | |
1797 | mapIROCs->AddAt((AliTPCCalROC*)mapFile.Get((rocName + "IROC").Data()), ivalue); | |
1798 | mapOROCs->AddAt((AliTPCCalROC*)mapFile.Get((rocName + "OROC").Data()), ivalue); | |
1799 | mapNames[ivalue].Append(rocName); | |
39bcd65d | 1800 | } |
7d855b04 | 1801 | |
39bcd65d | 1802 | for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) { |
1803 | mapIROCArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(0)); | |
1804 | mapOROCArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(36)); | |
7d855b04 | 1805 | |
39bcd65d | 1806 | for (UInt_t ichannel = 0; ichannel < tpcROCinstance->GetNChannels(0); ichannel++) |
1807 | (mapIROCArray[ivalue])[ichannel] = ((AliTPCCalROC*)(mapIROCs->At(ivalue)))->GetValue(ichannel); | |
1808 | for (UInt_t ichannel = 0; ichannel < tpcROCinstance->GetNChannels(36); ichannel++) | |
1809 | (mapOROCArray[ivalue])[ichannel] = ((AliTPCCalROC*)(mapOROCs->At(ivalue)))->GetValue(ichannel); | |
1810 | } | |
1811 | ||
1812 | } // if (mapFileName) | |
7d855b04 | 1813 | |
39bcd65d | 1814 | TTreeSRedirector cstream(fileName); |
1815 | Int_t arrayEntries = array->GetEntries(); | |
7d855b04 | 1816 | |
39bcd65d | 1817 | // Read names of AliTPCCalPads and save them in names[] |
1818 | TString* names = new TString[arrayEntries]; | |
1819 | for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) | |
1820 | names[ivalue].Append(((AliTPCCalPad*)array->At(ivalue))->GetName()); | |
1821 | ||
1822 | for (UInt_t isector = 0; isector < tpcROCinstance->GetNSectors(); isector++) { | |
7d855b04 | 1823 | |
39bcd65d | 1824 | TVectorF *vectorArray = new TVectorF[arrayEntries]; |
1825 | for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) | |
1826 | vectorArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(isector)); | |
7d855b04 | 1827 | |
1828 | ||
39bcd65d | 1829 | // |
1830 | // fill vectors of variable per pad | |
1831 | // | |
1832 | TVectorF *posArray = new TVectorF[8]; | |
1833 | for (Int_t ivalue = 0; ivalue < 8; ivalue++) | |
1834 | posArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(isector)); | |
1835 | ||
1836 | Float_t posG[3] = {0}; | |
1837 | Float_t posL[3] = {0}; | |
1838 | Int_t ichannel = 0; | |
1839 | for (UInt_t irow = 0; irow < tpcROCinstance->GetNRows(isector); irow++) { | |
1840 | for (UInt_t ipad = 0; ipad < tpcROCinstance->GetNPads(isector, irow); ipad++) { | |
1841 | tpcROCinstance->GetPositionLocal(isector, irow, ipad, posL); | |
1842 | tpcROCinstance->GetPositionGlobal(isector, irow, ipad, posG); | |
1843 | posArray[0][ichannel] = irow; | |
1844 | posArray[1][ichannel] = ipad; | |
1845 | posArray[2][ichannel] = posL[0]; | |
1846 | posArray[3][ichannel] = posL[1]; | |
1847 | posArray[4][ichannel] = posG[0]; | |
1848 | posArray[5][ichannel] = posG[1]; | |
1849 | posArray[6][ichannel] = (Int_t)(ipad - (Double_t)(tpcROCinstance->GetNPads(isector, irow))/2); | |
1850 | posArray[7][ichannel] = ichannel; | |
7d855b04 | 1851 | |
39bcd65d | 1852 | // loop over array containing AliTPCCalPads |
1853 | for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) { | |
1854 | AliTPCCalPad* calPad = (AliTPCCalPad*) array->At(ivalue); | |
1855 | AliTPCCalROC* calROC = calPad->GetCalROC(isector); | |
1856 | if (calROC) | |
1857 | (vectorArray[ivalue])[ichannel] = calROC->GetValue(irow, ipad); | |
1858 | else | |
1859 | (vectorArray[ivalue])[ichannel] = 0; | |
1860 | } | |
1861 | ichannel++; | |
1862 | } | |
1863 | } | |
1864 | AliTPCCalROC dummyROC(0); | |
1865 | for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) { | |
1866 | AliTPCCalROC *roc = ((AliTPCCalPad*)array->At(ivalue))->GetCalROC(isector); | |
1867 | if (!roc) roc = &dummyROC; | |
1868 | cstream << "calPads" << | |
1869 | (Char_t*)((names[ivalue] + ".=").Data()) << &vectorArray[ivalue]; | |
7d855b04 | 1870 | cstream << "calPads" << |
39bcd65d | 1871 | (Char_t*)((names[ivalue] + "Pad.=").Data()) << roc; |
1872 | } | |
1873 | ||
1874 | if (mapFileName) { | |
1875 | for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) { | |
1876 | if (isector < 36) | |
1877 | cstream << "calPads" << | |
1878 | (Char_t*)((mapNames[ivalue] + ".=").Data()) << &mapIROCArray[ivalue]; | |
1879 | else | |
1880 | cstream << "calPads" << | |
1881 | (Char_t*)((mapNames[ivalue] + ".=").Data()) << &mapOROCArray[ivalue]; | |
1882 | } | |
1883 | } | |
7d855b04 | 1884 | |
39bcd65d | 1885 | cstream << "calPads" << |
1886 | "sector=" << isector; | |
1887 | ||
1888 | cstream << "calPads" << | |
1889 | "row.=" << &posArray[0] << | |
1890 | "pad.=" << &posArray[1] << | |
1891 | "lx.=" << &posArray[2] << | |
1892 | "ly.=" << &posArray[3] << | |
1893 | "gx.=" << &posArray[4] << | |
1894 | "gy.=" << &posArray[5] << | |
1895 | "rpad.=" << &posArray[6] << | |
1896 | "channel.=" << &posArray[7]; | |
1897 | ||
1898 | cstream << "calPads" << | |
1899 | "\n"; | |
1900 | ||
1901 | delete[] posArray; | |
1902 | delete[] vectorArray; | |
1903 | } //for (UInt_t isector = 0; isector < tpcROCinstance->GetNSectors(); isector++) | |
1904 | ||
1905 | delete[] names; | |
1906 | if (mapFileName) { | |
1907 | delete mapIROCs; | |
1908 | delete mapOROCs; | |
1909 | delete[] mapIROCArray; | |
1910 | delete[] mapOROCArray; | |
1911 | delete[] mapNames; | |
1912 | } | |
1913 | } | |
1914 | ||
72d0ab7e | 1915 | |
2811495d | 1916 | void AliTPCCalibViewer::MakeTree(const char * fileName, TObjArray * array, const char * mapFileName, AliTPCCalPad *const outlierPad, Float_t ltmFraction) { |
7d855b04 | 1917 | /// Write a tree with all available information |
1918 | /// if mapFileName is speciefied, the Map information are also written to the tree | |
1919 | /// pads specified in outlierPad are not used for calculating statistics | |
1920 | /// The following statistical information on the basis of a ROC are calculated: | |
1921 | /// "_Median", "_Mean", "_LTM", "_RMS_LTM" | |
1922 | /// "_Median_OutlierCutted", "_Mean_OutlierCutted", "_RMS_OutlierCutted", "_LTM_OutlierCutted", "_RMS_LTM_OutlierCutted" | |
1923 | /// The following position variables are available: | |
1924 | /// "row", "pad", "lx", "ly", "gx", "gy", "rpad", "channel" | |
1925 | /// | |
1926 | /// The tree out of this function is the basis for the AliTPCCalibViewer and the AliTPCCalibViewerGUI. | |
1927 | ||
7390f655 | 1928 | AliTPCROC* tpcROCinstance = AliTPCROC::Instance(); |
39bcd65d | 1929 | |
7390f655 | 1930 | TObjArray* mapIROCs = 0; |
1931 | TObjArray* mapOROCs = 0; | |
1932 | TVectorF *mapIROCArray = 0; | |
1933 | TVectorF *mapOROCArray = 0; | |
1934 | Int_t mapEntries = 0; | |
1935 | TString* mapNames = 0; | |
7d855b04 | 1936 | |
7390f655 | 1937 | if (mapFileName) { |
1938 | TFile mapFile(mapFileName, "read"); | |
7d855b04 | 1939 | |
7390f655 | 1940 | TList* listOfROCs = mapFile.GetListOfKeys(); |
1941 | mapEntries = listOfROCs->GetEntries()/2; | |
1942 | mapIROCs = new TObjArray(mapEntries*2); | |
1943 | mapOROCs = new TObjArray(mapEntries*2); | |
1944 | mapIROCArray = new TVectorF[mapEntries]; | |
1945 | mapOROCArray = new TVectorF[mapEntries]; | |
7d855b04 | 1946 | |
7390f655 | 1947 | mapNames = new TString[mapEntries]; |
1948 | for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) { | |
1949 | TString rocName(((TKey*)(listOfROCs->At(ivalue*2)))->GetName()); | |
1950 | rocName.Remove(rocName.Length()-4, 4); | |
1951 | mapIROCs->AddAt((AliTPCCalROC*)mapFile.Get((rocName + "IROC").Data()), ivalue); | |
1952 | mapOROCs->AddAt((AliTPCCalROC*)mapFile.Get((rocName + "OROC").Data()), ivalue); | |
1953 | mapNames[ivalue].Append(rocName); | |
1954 | } | |
7d855b04 | 1955 | |
7390f655 | 1956 | for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) { |
1957 | mapIROCArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(0)); | |
1958 | mapOROCArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(36)); | |
7d855b04 | 1959 | |
7390f655 | 1960 | for (UInt_t ichannel = 0; ichannel < tpcROCinstance->GetNChannels(0); ichannel++) |
1961 | (mapIROCArray[ivalue])[ichannel] = ((AliTPCCalROC*)(mapIROCs->At(ivalue)))->GetValue(ichannel); | |
1962 | for (UInt_t ichannel = 0; ichannel < tpcROCinstance->GetNChannels(36); ichannel++) | |
1963 | (mapOROCArray[ivalue])[ichannel] = ((AliTPCCalROC*)(mapOROCs->At(ivalue)))->GetValue(ichannel); | |
1964 | } | |
7d855b04 | 1965 | |
7390f655 | 1966 | } // if (mapFileName) |
7d855b04 | 1967 | |
6d49cfb3 | 1968 | TTreeSRedirector cstream(fileName,"recreate"); |
7390f655 | 1969 | Int_t arrayEntries = 0; |
1970 | if (array) arrayEntries = array->GetEntries(); | |
7d855b04 | 1971 | |
7390f655 | 1972 | TString* names = new TString[arrayEntries]; |
1973 | for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) | |
1974 | names[ivalue].Append(((AliTPCCalPad*)array->At(ivalue))->GetName()); | |
7d855b04 | 1975 | |
7390f655 | 1976 | for (UInt_t isector = 0; isector < tpcROCinstance->GetNSectors(); isector++) { |
39bcd65d | 1977 | // |
1978 | // get statistic for given sector | |
1979 | // | |
7390f655 | 1980 | TVectorF median(arrayEntries); |
1981 | TVectorF mean(arrayEntries); | |
1982 | TVectorF rms(arrayEntries); | |
1983 | TVectorF ltm(arrayEntries); | |
1984 | TVectorF ltmrms(arrayEntries); | |
1985 | TVectorF medianWithOut(arrayEntries); | |
1986 | TVectorF meanWithOut(arrayEntries); | |
1987 | TVectorF rmsWithOut(arrayEntries); | |
1988 | TVectorF ltmWithOut(arrayEntries); | |
1989 | TVectorF ltmrmsWithOut(arrayEntries); | |
7d855b04 | 1990 | |
7390f655 | 1991 | TVectorF *vectorArray = new TVectorF[arrayEntries]; |
1992 | for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++){ | |
1993 | vectorArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(isector)); | |
1994 | vectorArray[ivalue].SetUniqueID(array->UncheckedAt(ivalue)->GetUniqueID()); | |
1995 | // printf("UniqueID: %d\n",vectorArray[ivalue].GetUniqueID()); | |
1996 | } | |
7d855b04 | 1997 | |
7390f655 | 1998 | for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) { |
1999 | AliTPCCalPad* calPad = (AliTPCCalPad*) array->At(ivalue); | |
2000 | AliTPCCalROC* calROC = calPad->GetCalROC(isector); | |
2001 | AliTPCCalROC* outlierROC = 0; | |
2002 | if (outlierPad) outlierROC = outlierPad->GetCalROC(isector); | |
2003 | if (calROC) { | |
2004 | median[ivalue] = calROC->GetMedian(); | |
2005 | mean[ivalue] = calROC->GetMean(); | |
2006 | rms[ivalue] = calROC->GetRMS(); | |
2007 | Double_t ltmrmsValue = 0; | |
2008 | ltm[ivalue] = calROC->GetLTM(<mrmsValue, ltmFraction); | |
2009 | ltmrms[ivalue] = ltmrmsValue; | |
2010 | if (outlierROC) { | |
2011 | medianWithOut[ivalue] = calROC->GetMedian(outlierROC); | |
2012 | meanWithOut[ivalue] = calROC->GetMean(outlierROC); | |
2013 | rmsWithOut[ivalue] = calROC->GetRMS(outlierROC); | |
2014 | ltmrmsValue = 0; | |
2015 | ltmWithOut[ivalue] = calROC->GetLTM(<mrmsValue, ltmFraction, outlierROC); | |
2016 | ltmrmsWithOut[ivalue] = ltmrmsValue; | |
2017 | } | |
39bcd65d | 2018 | } |
7390f655 | 2019 | else { |
2020 | median[ivalue] = 0.; | |
2021 | mean[ivalue] = 0.; | |
2022 | rms[ivalue] = 0.; | |
2023 | ltm[ivalue] = 0.; | |
2024 | ltmrms[ivalue] = 0.; | |
2025 | medianWithOut[ivalue] = 0.; | |
2026 | meanWithOut[ivalue] = 0.; | |
2027 | rmsWithOut[ivalue] = 0.; | |
2028 | ltmWithOut[ivalue] = 0.; | |
2029 | ltmrmsWithOut[ivalue] = 0.; | |
2030 | } | |
2031 | } | |
7d855b04 | 2032 | |
39bcd65d | 2033 | // |
2034 | // fill vectors of variable per pad | |
2035 | // | |
7390f655 | 2036 | TVectorF *posArray = new TVectorF[8]; |
2037 | for (Int_t ivalue = 0; ivalue < 8; ivalue++) | |
2038 | posArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(isector)); | |
7d855b04 | 2039 | |
7390f655 | 2040 | Float_t posG[3] = {0}; |
2041 | Float_t posL[3] = {0}; | |
2042 | Int_t ichannel = 0; | |
2043 | for (UInt_t irow = 0; irow < tpcROCinstance->GetNRows(isector); irow++) { | |
2044 | for (UInt_t ipad = 0; ipad < tpcROCinstance->GetNPads(isector, irow); ipad++) { | |
2045 | tpcROCinstance->GetPositionLocal(isector, irow, ipad, posL); | |
2046 | tpcROCinstance->GetPositionGlobal(isector, irow, ipad, posG); | |
2047 | posArray[0][ichannel] = irow; | |
2048 | posArray[1][ichannel] = ipad; | |
2049 | posArray[2][ichannel] = posL[0]; | |
2050 | posArray[3][ichannel] = posL[1]; | |
2051 | posArray[4][ichannel] = posG[0]; | |
2052 | posArray[5][ichannel] = posG[1]; | |
2053 | posArray[6][ichannel] = (Int_t)(ipad - (Double_t)(tpcROCinstance->GetNPads(isector, irow))/2); | |
2054 | posArray[7][ichannel] = ichannel; | |
7d855b04 | 2055 | |
39bcd65d | 2056 | // loop over array containing AliTPCCalPads |
7390f655 | 2057 | for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) { |
2058 | AliTPCCalPad* calPad = (AliTPCCalPad*) array->At(ivalue); | |
2059 | AliTPCCalROC* calROC = calPad->GetCalROC(isector); | |
2060 | if (calROC) | |
39bcd65d | 2061 | (vectorArray[ivalue])[ichannel] = calROC->GetValue(irow, ipad); |
7390f655 | 2062 | else |
2063 | (vectorArray[ivalue])[ichannel] = 0; | |
2064 | } | |
2065 | ichannel++; | |
39bcd65d | 2066 | } |
7390f655 | 2067 | } |
7d855b04 | 2068 | |
7390f655 | 2069 | cstream << "calPads" << |
2070 | "sector=" << isector; | |
7d855b04 | 2071 | |
7390f655 | 2072 | for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) { |
6d49cfb3 | 2073 | if (outlierPad==0) { |
2074 | cstream << "calPads" << | |
2075 | (Char_t*)((names[ivalue] + "_Median=").Data()) << median[ivalue] << | |
2076 | (Char_t*)((names[ivalue] + "_Mean=").Data()) << mean[ivalue] << | |
2077 | (Char_t*)((names[ivalue] + "_RMS=").Data()) << rms[ivalue] << | |
2078 | (Char_t*)((names[ivalue] + "_LTM=").Data()) << ltm[ivalue] << | |
2079 | (Char_t*)((names[ivalue] + "_RMS_LTM=").Data()) << ltmrms[ivalue]; | |
2080 | } | |
7390f655 | 2081 | if (outlierPad) { |
2082 | cstream << "calPads" << | |
6d49cfb3 | 2083 | (Char_t*)((names[ivalue] + "_Median=").Data()) << medianWithOut[ivalue] << |
2084 | (Char_t*)((names[ivalue] + "_Mean").Data()) << meanWithOut[ivalue] << | |
2085 | (Char_t*)((names[ivalue] + "_RMS=").Data()) << rmsWithOut[ivalue] << | |
2086 | (Char_t*)((names[ivalue] + "_LTM=").Data()) << ltmWithOut[ivalue] << | |
2087 | (Char_t*)((names[ivalue] + "_RMS_LTM=").Data()) << ltmrmsWithOut[ivalue]; | |
39bcd65d | 2088 | } |
6d49cfb3 | 2089 | //timestamp and run, if given in title |
2090 | /* TString title(((AliTPCCalPad*) array->At(ivalue))->GetTitle()); | |
2091 | TObjArray *arrtitle=title.Tokenize(","); | |
2092 | Int_t run=-1; | |
2093 | UInt_t time=0; | |
2094 | TIter next(arrtitle); | |
2095 | TObject *o=0; | |
2096 | while ( (o=next()) ){ | |
2097 | TString &entry=((TObjString*)o)->GetString(); | |
2098 | entry.Remove(TString::kBoth,' '); | |
2099 | entry.Remove(TString::kBoth,'\t'); | |
2100 | if (entry.BeginsWith("Run:")) { | |
2101 | run=entry(4,entry.Length()).Atoi(); | |
2102 | } else if (entry.BeginsWith("Time:")) { | |
2103 | time=entry(6,entry.Length()).Atoi(); | |
2104 | } | |
2105 | } | |
2106 | delete arrtitle;*/ | |
7d855b04 | 2107 | |
7390f655 | 2108 | } |
7d855b04 | 2109 | |
7390f655 | 2110 | for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) { |
2111 | cstream << "calPads" << | |
2112 | (Char_t*)((names[ivalue] + ".=").Data()) << &vectorArray[ivalue]; | |
2113 | } | |
7d855b04 | 2114 | |
7390f655 | 2115 | if (mapFileName) { |
2116 | for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) { | |
39bcd65d | 2117 | if (isector < 36) |
7390f655 | 2118 | cstream << "calPads" << |
2119 | (Char_t*)((mapNames[ivalue] + ".=").Data()) << &mapIROCArray[ivalue]; | |
39bcd65d | 2120 | else |
7390f655 | 2121 | cstream << "calPads" << |
2122 | (Char_t*)((mapNames[ivalue] + ".=").Data()) << &mapOROCArray[ivalue]; | |
39bcd65d | 2123 | } |
7390f655 | 2124 | } |
2125 | ||
2126 | cstream << "calPads" << | |
2127 | "row.=" << &posArray[0] << | |
2128 | "pad.=" << &posArray[1] << | |
2129 | "lx.=" << &posArray[2] << | |
2130 | "ly.=" << &posArray[3] << | |
2131 | "gx.=" << &posArray[4] << | |
2132 | "gy.=" << &posArray[5] << | |
2133 | "rpad.=" << &posArray[6] << | |
2134 | "channel.=" << &posArray[7]; | |
7d855b04 | 2135 | |
7390f655 | 2136 | cstream << "calPads" << |
2137 | "\n"; | |
7d855b04 | 2138 | |
7390f655 | 2139 | delete[] posArray; |
2140 | delete[] vectorArray; | |
2141 | } | |
6d49cfb3 | 2142 | TTree * tree = (cstream << "calPads").GetTree(); |
2143 | MakeCalPadAliases(tree); | |
2144 | for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) { | |
2145 | //(Char_t*)((names[ivalue] + "_Median=").Data()) << median[ivalue] << | |
2146 | tree->SetAlias(TString::Format("%s_LTMRatio",names[ivalue].Data()).Data(), TString::Format("%s.fElements/%s_LTM",names[ivalue].Data(),names[ivalue].Data()).Data()); | |
2147 | tree->SetAlias(TString::Format("%s_MeanRatio",names[ivalue].Data()).Data(), TString::Format("%s.fElements/%s_Mean",names[ivalue].Data(),names[ivalue].Data()).Data()); | |
2148 | tree->SetAlias(TString::Format("%s_MedianRatio",names[ivalue].Data()).Data(), TString::Format("%s.fElements/%s_Median",names[ivalue].Data(),names[ivalue].Data()).Data()); | |
2149 | tree->SetAlias(names[ivalue].Data(), TString::Format("%s.fElements",names[ivalue].Data()).Data()); | |
2150 | } | |
7390f655 | 2151 | delete[] names; |
2152 | if (mapFileName) { | |
2153 | delete mapIROCs; | |
2154 | delete mapOROCs; | |
2155 | delete[] mapIROCArray; | |
2156 | delete[] mapOROCArray; | |
2157 | delete[] mapNames; | |
2158 | } | |
39bcd65d | 2159 | } |
6d49cfb3 | 2160 | void AliTPCCalibViewer::MakeCalPadAliases(TTree * tree){ |
7d855b04 | 2161 | /// make standard aliases for standard calibration trees |
2162 | ||
6d49cfb3 | 2163 | tree->SetAlias("Pad0","MapPadLength.fElements==7.5"); // pad types |
2164 | tree->SetAlias("Pad1","MapPadLength.fElements==10.0"); | |
2165 | tree->SetAlias("Pad2","MapPadLength.fElements==15.0"); | |
2166 | tree->SetAlias("ly","(ly.fElements+((sector<36)*(2*((sector%36)<18)-1)*0.2)+((sector>=36)*(2*((sector%36)<18)-1)*0.3))"); // correction for bug in tpcROCinstance->GetPositionLocal(isector, irow, ipad, posL); | |
2167 | tree->SetAlias("dRowNorm0","(row.fElements/32-1)"); // normalized distance to the center of the chamber in lx (-1,1) | |
7d855b04 | 2168 | tree->SetAlias("dRowNorm1","(row.fElements/32-1)"); // |
6d49cfb3 | 2169 | tree->SetAlias("dRowNorm2","((row.fElements-63)/16-1)"); // |
2170 | tree->SetAlias("dRowNorm","(row.fElements<63)*(row.fElements/32-1)+(row.fElements>63)*((row.fElements-63)/16-1)"); | |
2171 | tree->SetAlias("dPhiNorm","(ly/lx.fElements)/(pi/18)"); // normalized distance to the center of the chamber in phi (-1,1) | |
2172 | // | |
2173 | tree->SetAlias("fsector","(sector%36)+(0.5+9*atan2(ly,lx.fElements)/pi)"); // float sector number | |
2174 | tree->SetAlias("posEdge","((pi/18.)-abs(atan(ly/lx.fElements)))*lx.fElements"); //distance to the edge | |
2175 | tree->SetAlias("lphi","atan(ly/lx.fElements)"); //local phi angle | |
2176 | } | |
4f3934a1 | 2177 | |
2178 | void AliTPCCalibViewer::MakeTree(const char *outPutFileName, const Char_t *inputFileName, AliTPCCalPad *outlierPad, Float_t ltmFraction, const char *mapFileName ){ | |
7d855b04 | 2179 | /// Function to create a calibration Tree with all available information. |
2180 | /// See also documentation to MakeTree | |
2181 | /// the file "inputFileName" must be in the following format (see also CreateObjectList): | |
2182 | /// (each colum separated by tabs, "dependingOnType" can have 2 or 3 colums) | |
2183 | /// | |
2184 | /// type path dependingOnType | |
2185 | /// | |
2186 | /// type == "CE": | |
2187 | /// dependingOnType = CETmean CEQmean CETrms | |
2188 | /// | |
2189 | /// type == "Pulser": | |
2190 | /// dependingOnType = PulserTmean PulsterQmean PulserTrms | |
2191 | /// | |
2192 | /// type == "Pedestals": | |
2193 | /// dependingOnType = Pedestals Noise | |
2194 | /// | |
2195 | /// type == "CalPad": | |
2196 | /// dependingOnType = NameInFile NameToWriteToFile | |
2197 | ||
4f3934a1 | 2198 | TObjArray objArray; |
2199 | CreateObjectList(inputFileName, &objArray); | |
7d855b04 | 2200 | MakeTree(outPutFileName, &objArray, mapFileName, outlierPad, ltmFraction); |
4f3934a1 | 2201 | } |
2202 | ||
832bb12c | 2203 | |
4f3934a1 | 2204 | void AliTPCCalibViewer::CreateObjectList(const Char_t *filename, TObjArray *calibObjects){ |
7d855b04 | 2205 | /// Function to create a TObjArray out of a given file |
2206 | /// the file must be in the following format: | |
2207 | /// (each colum separated by tabs, "dependingOnType" can have 2 or 3 colums) | |
2208 | /// | |
2209 | /// type path dependingOnType | |
2210 | /// | |
2211 | /// type == "CE": | |
2212 | /// dependingOnType = CETmean CEQmean CETrms | |
2213 | /// | |
2214 | /// type == "Pulser": | |
2215 | /// dependingOnType = PulserTmean PulsterQmean PulserTrms | |
2216 | /// | |
2217 | /// type == "Pedestals": | |
2218 | /// dependingOnType = Pedestals Noise | |
2219 | /// | |
2220 | /// type == "CalPad": | |
2221 | /// dependingOnType = NameInFile NameToWriteToFile | |
2222 | ||
4f3934a1 | 2223 | if ( calibObjects == 0x0 ) return; |
2224 | ifstream in; | |
2225 | in.open(filename); | |
2226 | if ( !in.is_open() ){ | |
2227 | fprintf(stderr,"Error: cannot open list file '%s'", filename); | |
2228 | return; | |
2229 | } | |
7d855b04 | 2230 | |
4f3934a1 | 2231 | AliTPCCalPad *calPad=0x0; |
7d855b04 | 2232 | |
4f3934a1 | 2233 | TString sFile; |
2234 | sFile.ReadFile(in); | |
2235 | in.close(); | |
7d855b04 | 2236 | |
4f3934a1 | 2237 | TObjArray *arrFileLine = sFile.Tokenize("\n"); |
2238 | TIter nextLine(arrFileLine); | |
7d855b04 | 2239 | |
4f3934a1 | 2240 | TObjString *sObjLine = 0x0; |
2241 | while ( (sObjLine = (TObjString*)nextLine()) ){ | |
2242 | TString sLine(sObjLine->GetString()); | |
7d855b04 | 2243 | |
4f3934a1 | 2244 | TObjArray *arrCol = sLine.Tokenize("\t"); |
2245 | Int_t nCols = arrCol->GetEntriesFast(); | |
7d855b04 | 2246 | |
4f3934a1 | 2247 | TObjString *sObjType = (TObjString*)(arrCol->At(0)); |
2248 | TObjString *sObjFileName = (TObjString*)(arrCol->At(1)); | |
2249 | TObjString *sObjName = 0x0; | |
7d855b04 | 2250 | |
4f3934a1 | 2251 | if ( !sObjType || !sObjFileName ) continue; |
2252 | TString sType(sObjType->GetString()); | |
2253 | TString sFileName(sObjFileName->GetString()); | |
2254 | printf("Type %s, opening %s \n", sType.Data(), sFileName.Data()); | |
2255 | TFile *fIn = TFile::Open(sFileName); | |
2256 | if ( !fIn ){ | |
2257 | fprintf(stderr,"File not found: '%s'", sFileName.Data()); | |
2258 | continue; | |
2259 | } | |
7d855b04 | 2260 | |
4f3934a1 | 2261 | if ( sType == "CE" ){ // next three colums are the names for CETmean, CEQmean and CETrms |
2262 | AliTPCCalibCE *ce = (AliTPCCalibCE*)fIn->Get("AliTPCCalibCE"); | |
7d855b04 | 2263 | calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadT0()); |
4f3934a1 | 2264 | if (nCols > 2) { // check, if the name is provided |
2265 | sObjName = (TObjString*)(arrCol->At(2)); | |
2266 | calPad->SetNameTitle(sObjName->GetString().Data(), sObjName->GetString().Data()); | |
2267 | } | |
2268 | else calPad->SetNameTitle("CETmean","CETmean"); | |
2269 | calibObjects->Add(calPad); | |
7d855b04 | 2270 | |
2271 | calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadQ()); | |
4f3934a1 | 2272 | if (nCols > 3) { // check, if the name is provided |
2273 | sObjName = (TObjString*)(arrCol->At(3)); | |
2274 | calPad->SetNameTitle(sObjName->GetString().Data(), sObjName->GetString().Data()); | |
2275 | } | |
2276 | else calPad->SetNameTitle("CEQmean","CEQmean"); | |
7d855b04 | 2277 | calibObjects->Add(calPad); |
2278 | ||
4f3934a1 | 2279 | calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadRMS()); |
2280 | if (nCols > 4) { // check, if the name is provided | |
2281 | sObjName = (TObjString*)(arrCol->At(4)); | |
2282 | calPad->SetNameTitle(sObjName->GetString().Data(), sObjName->GetString().Data()); | |
2283 | } | |
2284 | else calPad->SetNameTitle("CETrms","CETrms"); | |
7d855b04 | 2285 | calibObjects->Add(calPad); |
2286 | ||
4f3934a1 | 2287 | } else if ( sType == "Pulser") { |
2288 | AliTPCCalibPulser *sig = (AliTPCCalibPulser*)fIn->Get("AliTPCCalibPulser"); | |
7d855b04 | 2289 | |
2290 | calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadT0()); | |
4f3934a1 | 2291 | if (nCols > 2) { |
2292 | sObjName = (TObjString*)(arrCol->At(2)); | |
2293 | calPad->SetNameTitle(sObjName->GetString().Data(), sObjName->GetString().Data()); | |
2294 | } | |
2295 | else calPad->SetNameTitle("PulserTmean","PulserTmean"); | |
2296 | calibObjects->Add(calPad); | |
7d855b04 | 2297 | |
2298 | calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadQ()); | |
4f3934a1 | 2299 | if (nCols > 3) { |
2300 | sObjName = (TObjString*)(arrCol->At(3)); | |
2301 | calPad->SetNameTitle(sObjName->GetString().Data(), sObjName->GetString().Data()); | |
2302 | } | |
2303 | else calPad->SetNameTitle("PulserQmean","PulserQmean"); | |
7d855b04 | 2304 | calibObjects->Add(calPad); |
2305 | ||
4f3934a1 | 2306 | calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadRMS()); |
2307 | if (nCols > 4) { | |
2308 | sObjName = (TObjString*)(arrCol->At(4)); | |
2309 | calPad->SetNameTitle(sObjName->GetString().Data(), sObjName->GetString().Data()); | |
2310 | } | |
2311 | else calPad->SetNameTitle("PulserTrms","PulserTrms"); | |
7d855b04 | 2312 | calibObjects->Add(calPad); |
2313 | ||
4f3934a1 | 2314 | } else if ( sType == "Pedestals") { |
2315 | AliTPCCalibPedestal *ped = (AliTPCCalibPedestal*)fIn->Get("AliTPCCalibPedestal"); | |
7d855b04 | 2316 | |
2317 | calPad = new AliTPCCalPad((TObjArray*)ped->GetCalPadPedestal()); | |
4f3934a1 | 2318 | if (nCols > 2) { |
2319 | sObjName = (TObjString*)(arrCol->At(2)); | |
2320 | calPad->SetNameTitle(sObjName->GetString().Data(), sObjName->GetString().Data()); | |
2321 | } | |
2322 | else calPad->SetNameTitle("Pedestals","Pedestals"); | |
2323 | calibObjects->Add(calPad); | |
7d855b04 | 2324 | |
2325 | calPad = new AliTPCCalPad((TObjArray*)ped->GetCalPadRMS()); | |
4f3934a1 | 2326 | if (nCols > 3) { |
2327 | sObjName = (TObjString*)(arrCol->At(3)); | |
2328 | calPad->SetNameTitle(sObjName->GetString().Data(), sObjName->GetString().Data()); | |
2329 | } | |
2330 | else calPad->SetNameTitle("Noise","Noise"); | |
7d855b04 | 2331 | calibObjects->Add(calPad); |
2332 | ||
4f3934a1 | 2333 | } else if ( sType == "CalPad") { |
2334 | if (nCols > 2) sObjName = (TObjString*)(arrCol->At(2)); | |
2335 | else continue; | |
2336 | calPad = new AliTPCCalPad(*(AliTPCCalPad*)fIn->Get(sObjName->GetString().Data())); | |
2337 | if (nCols > 3) { | |
2338 | sObjName = (TObjString*)(arrCol->At(3)); | |
2339 | calPad->SetNameTitle(sObjName->GetString().Data(), sObjName->GetString().Data()); | |
2340 | } | |
2341 | calibObjects->Add(calPad); | |
2342 | } else { | |
2343 | fprintf(stderr,"Undefined Type: '%s'",sType.Data()); | |
2344 | } | |
2345 | delete fIn; | |
2346 | } | |
09d5920f | 2347 | delete arrFileLine; |
4f3934a1 | 2348 | } |
2349 | ||
2350 | ||
2351 |