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