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