1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 ///////////////////////////////////////////////////////////////////////////////
19 // Class for viewing/visualizing TPC calibration data //
20 // base on TTree functionality for visualization //
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") //
27 // EasyDraw("CETmean~-CETmean_mean", "A", "(CETmean~-CETmean_mean)>0") //
29 // If you like to click, we recommand you the //
30 // AliTPCCalibViewerGUI //
32 // THE DOCUMENTATION IS STILL NOT COMPLETED !!!! //
34 ///////////////////////////////////////////////////////////////////////////////
44 #include <TFriendElement.h>
48 //#include <TCanvas.h>
54 #include <TObjString.h>
59 #include <TTreeStream.h>
61 #include "AliTPCCalibCE.h"
62 #include "AliMathBase.h"
63 #include "AliTPCCalPad.h"
64 #include "AliTPCCalROC.h"
65 #include "AliTPCCalibPedestal.h"
66 #include "AliTPCCalibPulser.h"
71 #include "AliTPCCalibViewer.h"
73 ClassImp(AliTPCCalibViewer)
76 AliTPCCalibViewer::AliTPCCalibViewer()
80 fListOfObjectsToBeDeleted(0),
81 fTreeMustBeDeleted(0),
86 // Default constructor
91 //_____________________________________________________________________________
92 AliTPCCalibViewer::AliTPCCalibViewer(const AliTPCCalibViewer &c)
96 fListOfObjectsToBeDeleted(0),
97 fTreeMustBeDeleted(0),
102 // dummy AliTPCCalibViewer copy constructor
103 // not yet working!!!
106 fTreeMustBeDeleted = c.fTreeMustBeDeleted;
107 //fFile = new TFile(*(c.fFile));
108 fListOfObjectsToBeDeleted = c.fListOfObjectsToBeDeleted;
109 fAbbreviation = c.fAbbreviation;
110 fAppendString = c.fAppendString;
113 //_____________________________________________________________________________
114 AliTPCCalibViewer::AliTPCCalibViewer(TTree *const tree)
118 fListOfObjectsToBeDeleted(0),
119 fTreeMustBeDeleted(0),
124 // Constructor that initializes the calibration viewer
127 fTreeMustBeDeleted = kFALSE;
128 fListOfObjectsToBeDeleted = new TObjArray();
130 fAppendString = ".fElements";
133 //_____________________________________________________________________________
134 AliTPCCalibViewer::AliTPCCalibViewer(const char* fileName, const char* treeName)
138 fListOfObjectsToBeDeleted(0),
139 fTreeMustBeDeleted(0),
145 // Constructor to initialize the calibration viewer
146 // the file 'fileName' contains the tree 'treeName'
148 fFile = new TFile(fileName, "read");
149 fTree = (TTree*) fFile->Get(treeName);
150 fTreeMustBeDeleted = kTRUE;
151 fListOfObjectsToBeDeleted = new TObjArray();
153 fAppendString = ".fElements";
156 //____________________________________________________________________________
157 AliTPCCalibViewer & AliTPCCalibViewer::operator =(const AliTPCCalibViewer & param)
160 // assignment operator - dummy
161 // not yet working!!!
164 fTreeMustBeDeleted = param.fTreeMustBeDeleted;
165 //fFile = new TFile(*(param.fFile));
166 fListOfObjectsToBeDeleted = param.fListOfObjectsToBeDeleted;
167 fAbbreviation = param.fAbbreviation;
168 fAppendString = param.fAppendString;
172 //_____________________________________________________________________________
173 AliTPCCalibViewer::~AliTPCCalibViewer()
176 // AliTPCCalibViewer destructor
177 // all objects will be deleted, the file will be closed, the pictures will disappear
179 if (fTree && fTreeMustBeDeleted) {
180 fTree->SetCacheSize(0);
189 for (Int_t i = fListOfObjectsToBeDeleted->GetEntriesFast()-1; i >= 0; i--) {
190 //cout << "Index " << i << " trying to delete the following object: " << fListOfObjectsToBeDeleted->At(i)->GetName() << "..."<< endl;
191 delete fListOfObjectsToBeDeleted->At(i);
193 delete fListOfObjectsToBeDeleted;
196 //_____________________________________________________________________________
197 void AliTPCCalibViewer::Delete(Option_t* /*option*/) {
199 // Should be called from AliTPCCalibViewerGUI class only.
200 // If you use Delete() do not call the destructor.
201 // All objects (except those contained in fListOfObjectsToBeDeleted) will be deleted, the file will be closed.
204 if (fTree && fTreeMustBeDeleted) {
205 fTree->SetCacheSize(0);
209 delete fListOfObjectsToBeDeleted;
213 const char* AliTPCCalibViewer::AddAbbreviations(const Char_t *c, Bool_t printDrawCommand){
214 // Replace all "<variable>" with "<variable><fAbbreviation>" (Adds forgotten "~")
215 // but take care on the statistical information, like "CEQmean_Mean"
216 // and also take care on correct given variables, like "CEQmean~"
218 // For each variable out of "listOfVariables":
219 // - 'Save' correct items:
220 // - form <replaceString>, take <variable>'s first char, add <removeString>, add rest of <variable>, e.g. "C!#EQmean" (<removeString> = "!#")
221 // - For each statistical information in "listOfNormalizationVariables":
222 // - ReplaceAll <variable><statistical_Information> with <replaceString><statistical_Information>
223 // - ReplaceAll <variable><abbreviation> with <replaceString><abbreviation>, e.g. "CEQmean~" -> "C!#EQmean~"
224 // - ReplaceAll <variable><appendStr> with <replaceString><appendStr>, e.g. "CEQmean.fElements" -> "C!#EQmean.fElements"
226 // - Do actual replacing:
227 // - ReplaceAll <variable> with <variable><fAbbreviation>, e.g. "CEQmean" -> "CEQmean~"
230 // - For each statistical information in "listOfNormalizationVariables":
231 // - ReplaceAll <replaceString><statistical_Information> with <variable><statistical_Information>
232 // - ReplaceAll <replaceString><abbreviation> with <variable><abbreviation>, e.g. "C!#EQmean~" -> "CEQmean~"
233 // - ReplaceAll <replaceString><appendStr> with <variable><appendStr>, e.g. "C!#EQmean.fElements" -> "CEQmean.fElements"
235 // Now all the missing "~" should be added.
238 TString removeString = "!#"; // very unpropable combination of chars
239 TString replaceString = "";
240 TString searchString = "";
241 TString normString = "";
242 TObjArray *listOfVariables = GetListOfVariables();
243 listOfVariables->Add(new TObjString("channel"));
244 listOfVariables->Add(new TObjString("gx"));
245 listOfVariables->Add(new TObjString("gy"));
246 listOfVariables->Add(new TObjString("lx"));
247 listOfVariables->Add(new TObjString("ly"));
248 listOfVariables->Add(new TObjString("pad"));
249 listOfVariables->Add(new TObjString("row"));
250 listOfVariables->Add(new TObjString("rpad"));
251 listOfVariables->Add(new TObjString("sector"));
252 TObjArray *listOfNormalizationVariables = GetListOfNormalizationVariables();
253 Int_t nVariables = listOfVariables->GetEntriesFast();
254 Int_t nNorm = listOfNormalizationVariables->GetEntriesFast();
256 Int_t *varLengths = new Int_t[nVariables];
257 for (Int_t i = 0; i < nVariables; i++) {
258 varLengths[i] = ((TObjString*)listOfVariables->At(i))->String().Length();
260 Int_t *normLengths = new Int_t[nNorm];
261 for (Int_t i = 0; i < nNorm; i++) {
262 normLengths[i] = ((TObjString*)listOfNormalizationVariables->At(i))->String().Length();
263 // printf("normLengths[%i] (%s) = %i \n", i,((TObjString*)listOfNormalizationVariables->At(i))->String().Data(), normLengths[i]);
265 Int_t *varSort = new Int_t[nVariables];
266 TMath::Sort(nVariables, varLengths, varSort, kTRUE);
267 Int_t *normSort = new Int_t[nNorm];
268 TMath::Sort(nNorm, normLengths, normSort, kTRUE);
269 // for (Int_t i = 0; i<nNorm; i++) printf("normLengths: %i\n", normLengths[normSort[i]]);
270 // for (Int_t i = 0; i<nVariables; i++) printf("varLengths: %i\n", varLengths[varSort[i]]);
272 for (Int_t ivar = 0; ivar < nVariables; ivar++) {
273 // ***** save correct tokens *****
274 // first get the next variable:
275 searchString = ((TObjString*)listOfVariables->At(varSort[ivar]))->String();
276 // printf("searchString: %s ++++++++++++++\n", searchString.Data());
277 // form replaceString:
279 for (Int_t i = 0; i < searchString.Length(); i++) {
280 replaceString.Append(searchString[i]);
281 if (i == 0) replaceString.Append(removeString);
283 // go through normalization:
284 // printf("go through normalization\n");
285 for (Int_t inorm = 0; inorm < nNorm; inorm++) {
286 // printf(" inorm=%i, nNorm=%i, normSort[inorm]=%i \n", inorm, nNorm, normSort[inorm]);
287 normString = ((TObjString*)listOfNormalizationVariables->At(normSort[inorm]))->String();
288 // printf(" walking in normalization, i=%i, normString=%s \n", inorm, normString.Data());
289 str.ReplaceAll(searchString + normString, replaceString + normString);
290 // like: str.ReplaceAll("CEQmean_Mean", "C!EQmean_Mean");
292 str.ReplaceAll(searchString + fAbbreviation, replaceString + fAbbreviation);
293 // like: str.ReplaceAll("CEQmean~", "C!EQmean~");
294 str.ReplaceAll(searchString + fAppendString, replaceString + fAppendString);
295 // like: str.ReplaceAll("CEQmean.fElements", "C!EQmean.fElements");
297 // ***** add missing extensions *****
298 str.ReplaceAll(searchString, replaceString + fAbbreviation);
299 // like: str.ReplaceAll("CEQmean", "C!EQmean~");
302 // ***** undo saving *****
303 str.ReplaceAll(removeString, "");
305 if (printDrawCommand) std::cout << "The string looks now like: " << str.Data() << std::endl;
306 delete [] varLengths;
307 delete [] normLengths;
316 //_____________________________________________________________________________
317 Int_t AliTPCCalibViewer::EasyDraw(const char* drawCommand, const char* sector, const char* cuts, const char* drawOptions, Bool_t writeDrawCommand) const {
319 // easy drawing of data, use '~' for abbreviation of '.fElements'
320 // example: EasyDraw("CETmean~-CETmean_mean", "A", "(CETmean~-CETmean_mean)>0")
321 // sector: sector-number - only the specified sector will be drwawn
322 // 'A'/'C' or 'a'/'c' - side A/C will be drawn
323 // 'ALL' - whole TPC will be drawn, projected on one side
324 // cuts: specifies cuts
325 // drawOptions: draw options like 'same'
326 // writeDrawCommand: write the command, that is passed to TTree::Draw
329 TString drawStr(drawCommand);
330 TString sectorStr(sector);
333 //TString drawOptionsStr("profcolz ");
334 Bool_t dangerousToDraw = drawStr.Contains(":") || drawStr.Contains(">>");
335 if (dangerousToDraw) {
336 Warning("EasyDraw", "The draw string must not contain ':' or '>>'. Using only first variable for drawing!");
338 // drawStr.Resize(drawStr.First(">"));
339 drawStr.Resize(drawStr.First(":"));
342 TString drawOptionsStr("");
344 Int_t rndNumber = rnd.Integer(10000);
346 if (drawOptions && strcmp(drawOptions, "") != 0)
347 drawOptionsStr += drawOptions;
349 drawOptionsStr += "profcolz";
351 if (sectorStr == "A") {
352 drawStr += Form(":gy%s:gx%s>>prof", fAppendString.Data(), fAppendString.Data());
353 drawStr += rndNumber;
354 drawStr += "(330,-250,250,330,-250,250)";
355 cutStr += "(sector/18)%2==0 ";
357 else if (sectorStr == "C") {
358 drawStr += Form(":gy%s:gx%s>>prof", fAppendString.Data(), fAppendString.Data());
359 drawStr += rndNumber;
360 drawStr += "(330,-250,250,330,-250,250)";
361 cutStr += "(sector/18)%2==1 ";
363 else if (sectorStr == "ALL") {
364 drawStr += Form(":gy%s:gx%s>>prof", fAppendString.Data(), fAppendString.Data());
365 drawStr += rndNumber;
366 drawStr += "(330,-250,250,330,-250,250)";
368 else if (sectorStr.Contains("S")) {
369 drawStr += Form(":rpad%s:row%s+(sector>35)*63>>prof", fAppendString.Data(), fAppendString.Data());
370 drawStr += rndNumber;
371 drawStr += "(159,0,159,140,-70,70)";
372 TString sec=sectorStr;
374 cutStr += "sector%36=="+sec+" ";
376 else if (sectorStr.IsDigit()) {
377 Int_t isec = sectorStr.Atoi();
378 drawStr += Form(":rpad%s:row%s>>prof", fAppendString.Data(), fAppendString.Data());
379 drawStr += rndNumber;
380 if (isec < 36 && isec >= 0)
381 drawStr += "(63,0,63,108,-54,54)";
382 else if (isec < 72 && isec >= 36)
383 drawStr += "(96,0,96,140,-70,70)";
385 Error("EasyDraw","The TPC contains only sectors between 0 and 71.");
388 cutStr += "(sector==";
393 if (cuts && cuts[0] != 0) {
394 if (cutStr.Length() != 0) cutStr += "&& ";
399 drawStr.ReplaceAll(fAbbreviation, fAppendString);
400 cutStr.ReplaceAll(fAbbreviation, fAppendString);
401 if (writeDrawCommand) std::cout << "fTree->Draw(\"" << drawStr << "\", \"" << cutStr << "\", \"" << drawOptionsStr << "\");" << std::endl;
402 Int_t returnValue = fTree->Draw(drawStr.Data(), cutStr.Data(), drawOptionsStr.Data());
403 TString profName("prof");
404 profName += rndNumber;
405 TObject *obj = gDirectory->Get(profName.Data());
406 if (obj && obj->InheritsFrom("TH1")) FormatHistoLabels((TH1*)obj);
411 Int_t AliTPCCalibViewer::EasyDraw(const char* drawCommand, Int_t sector, const char* cuts, const char* drawOptions, Bool_t writeDrawCommand) const {
413 // easy drawing of data, use '~' for abbreviation of '.fElements'
414 // example: EasyDraw("CETmean~-CETmean_mean", 34, "(CETmean~-CETmean_mean)>0")
415 // sector: sector-number - only the specified sector will be drwawn
416 // cuts: specifies cuts
417 // drawOptions: draw options like 'same'
418 // writeDrawCommand: write the command, that is passed to TTree::Draw
420 if (sector >= 0 && sector < 72) {
421 return EasyDraw(drawCommand, Form("%i", sector), cuts, drawOptions, writeDrawCommand);
423 Error("EasyDraw","The TPC contains only sectors between 0 and 71.");
428 //_____________________________________________________________________________
429 Int_t AliTPCCalibViewer::EasyDraw1D(const char* drawCommand, const char* sector, const char* cuts, const char* drawOptions, Bool_t writeDrawCommand) const {
431 // easy drawing of data, use '~' for abbreviation of '.fElements'
432 // example: EasyDraw("CETmean~-CETmean_mean", "A", "(CETmean~-CETmean_mean)>0")
433 // sector: sector-number - the specified sector will be drwawn
434 // 'A'/'C' or 'a'/'c' - side A/C will be drawn
435 // 'ALL' - whole TPC will be drawn, projected on one side
436 // cuts: specifies cuts
437 // drawOptions: draw options like 'same'
438 // writeDrawCommand: write the command, that is passed to TTree::Draw
441 TString drawStr(drawCommand);
442 TString sectorStr(sector);
443 TString drawOptionsStr(drawOptions);
447 if (sectorStr == "A")
448 cutStr += "(sector/18)%2==0 ";
449 else if (sectorStr == "C")
450 cutStr += "(sector/18)%2==1 ";
451 else if (sectorStr.IsDigit()) {
452 Int_t isec = sectorStr.Atoi();
453 if (isec < 0 || isec > 71) {
454 Error("EasyDraw","The TPC contains only sectors between 0 and 71.");
457 cutStr += "(sector==";
461 else if (sectorStr.Contains("S")) {
462 TString sec=sectorStr;
464 cutStr += "sector%36=="+sec+" ";
467 if (cuts && cuts[0] != 0) {
468 if (cutStr.Length() != 0) cutStr += "&& ";
474 drawStr.ReplaceAll(fAbbreviation, fAppendString);
475 cutStr.ReplaceAll(fAbbreviation, fAppendString);
476 if (writeDrawCommand) std::cout << "fTree->Draw(\"" << drawStr << "\", \"" << cutStr << "\", \"" << drawOptionsStr << "\");" << std::endl;
477 Int_t returnValue = fTree->Draw(drawStr.Data(), cutStr.Data(), drawOptionsStr.Data());
478 if (returnValue == -1) return -1;
480 TObject *obj = (gPad) ? gPad->GetPrimitive("htemp") : 0;
481 if (!obj) obj = (TH1F*)gDirectory->Get("htemp");
482 if (!obj) obj = gPad->GetPrimitive("tempHist");
483 if (!obj) obj = (TH1F*)gDirectory->Get("tempHist");
484 if (!obj) obj = gPad->GetPrimitive("Graph");
485 if (!obj) obj = (TH1F*)gDirectory->Get("Graph");
486 if (obj && obj->InheritsFrom("TH1")) FormatHistoLabels((TH1*)obj);
491 Int_t AliTPCCalibViewer::EasyDraw1D(const char* drawCommand, Int_t sector, const char* cuts, const char* drawOptions, Bool_t writeDrawCommand) const {
493 // easy drawing of data, use '~' for abbreviation of '.fElements'
494 // example: EasyDraw("CETmean~-CETmean_mean", 34, "(CETmean~-CETmean_mean)>0")
495 // sector: sector-number - the specified sector will be drwawn
496 // cuts: specifies cuts
497 // drawOptions: draw options like 'same'
498 // writeDrawCommand: write the command, that is passed to TTree::Draw
501 if (sector >= 0 && sector < 72) {
502 return EasyDraw1D(drawCommand, Form("%i",sector), cuts, drawOptions, writeDrawCommand);
504 Error("EasyDraw","The TPC contains only sectors between 0 and 71.");
509 void AliTPCCalibViewer::FormatHistoLabels(TH1 *histo) const {
511 // formats title and axis labels of histo
512 // removes '.fElements'
515 TString replaceString(fAppendString.Data());
516 TString *str = new TString(histo->GetTitle());
517 str->ReplaceAll(replaceString, "");
518 histo->SetTitle(str->Data());
520 if (histo->GetXaxis()) {
521 str = new TString(histo->GetXaxis()->GetTitle());
522 str->ReplaceAll(replaceString, "");
523 histo->GetXaxis()->SetTitle(str->Data());
526 if (histo->GetYaxis()) {
527 str = new TString(histo->GetYaxis()->GetTitle());
528 str->ReplaceAll(replaceString, "");
529 histo->GetYaxis()->SetTitle(str->Data());
532 if (histo->GetZaxis()) {
533 str = new TString(histo->GetZaxis()->GetTitle());
534 str->ReplaceAll(replaceString, "");
535 histo->GetZaxis()->SetTitle(str->Data());
541 Int_t AliTPCCalibViewer::DrawHisto1D(const char* drawCommand, Int_t sector, const char* cuts, const char *sigmas, Bool_t plotMean, Bool_t plotMedian, Bool_t plotLTM) const {
543 // Easy drawing of data, in principle the same as EasyDraw1D
544 // Difference: A line for the mean / median / LTM is drawn
545 // in 'sigmas' you can specify in which distance to the mean/median/LTM you want to see a line in sigma-units, separated by ';'
546 // example: sigmas = "2; 4; 6;" at Begin_Latex 2 #sigma End_Latex, Begin_Latex 4 #sigma End_Latex and Begin_Latex 6 #sigma End_Latex a line is drawn.
547 // "plotMean", "plotMedian" and "plotLTM": what kind of lines do you want to see?
549 if (sector >= 0 && sector < 72) {
550 return DrawHisto1D(drawCommand, Form("%i", sector), cuts, sigmas, plotMean, plotMedian, plotLTM);
552 Error("DrawHisto1D","The TPC contains only sectors between 0 and 71.");
557 Int_t AliTPCCalibViewer::DrawHisto1D(const char* drawCommand, const char* sector, const char* cuts, const char *sigmas, Bool_t plotMean, Bool_t plotMedian, Bool_t plotLTM) const {
559 // Easy drawing of data, in principle the same as EasyDraw1D
560 // Difference: A line for the mean / median / LTM is drawn
561 // in 'sigmas' you can specify in which distance to the mean/median/LTM you want to see a line in sigma-units, separated by ';'
562 // 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.
563 // "plotMean", "plotMedian" and "plotLTM": what kind of lines do you want to see?
565 Int_t oldOptStat = gStyle->GetOptStat();
566 gStyle->SetOptStat(0000000);
567 Double_t ltmFraction = 0.8;
569 TObjArray *sigmasTokens = TString(sigmas).Tokenize(";");
570 TVectorF nsigma(sigmasTokens->GetEntriesFast());
571 for (Int_t i = 0; i < sigmasTokens->GetEntriesFast(); i++) {
572 TString str(((TObjString*)sigmasTokens->At(i))->GetString());
573 Double_t sig = (str.IsFloat()) ? str.Atof() : 0;
577 TString drawStr(drawCommand);
578 Bool_t dangerousToDraw = drawStr.Contains(":") || drawStr.Contains(">>");
579 if (dangerousToDraw) {
580 Warning("DrawHisto1D", "The draw string must not contain ':' or '>>'.");
583 drawStr += " >> tempHist";
584 Int_t entries = EasyDraw1D(drawStr.Data(), sector, cuts);
585 TH1F *htemp = (TH1F*)gDirectory->Get("tempHist");
586 // FIXME is this histogram deleted automatically?
587 Double_t *values = fTree->GetV1(); // value is the array containing 'entries' numbers
589 Double_t mean = TMath::Mean(entries, values);
590 Double_t median = TMath::Median(entries, values);
591 Double_t sigma = TMath::RMS(entries, values);
592 Double_t maxY = htemp->GetMaximum();
594 TLegend * legend = new TLegend(.7,.7, .99, .99, "Statistical information");
595 //fListOfObjectsToBeDeleted->Add(legend);
599 TLine* line = new TLine(mean, 0, mean, maxY);
600 //fListOfObjectsToBeDeleted->Add(line);
601 line->SetLineColor(kRed);
602 line->SetLineWidth(2);
603 line->SetLineStyle(1);
605 legend->AddEntry(line, Form("Mean: %f", mean), "l");
607 for (Int_t i = 0; i < nsigma.GetNoElements(); i++) {
608 TLine* linePlusSigma = new TLine(mean + nsigma[i] * sigma, 0, mean + nsigma[i] * sigma, maxY);
609 //fListOfObjectsToBeDeleted->Add(linePlusSigma);
610 linePlusSigma->SetLineColor(kRed);
611 linePlusSigma->SetLineStyle(2 + i);
612 linePlusSigma->Draw();
613 TLine* lineMinusSigma = new TLine(mean - nsigma[i] * sigma, 0, mean - nsigma[i] * sigma, maxY);
614 //fListOfObjectsToBeDeleted->Add(lineMinusSigma);
615 lineMinusSigma->SetLineColor(kRed);
616 lineMinusSigma->SetLineStyle(2 + i);
617 lineMinusSigma->Draw();
618 legend->AddEntry(lineMinusSigma, Form("%i #sigma = %f",(Int_t)(nsigma[i]), (Float_t)(nsigma[i] * sigma)), "l");
623 TLine* line = new TLine(median, 0, median, maxY);
624 //fListOfObjectsToBeDeleted->Add(line);
625 line->SetLineColor(kBlue);
626 line->SetLineWidth(2);
627 line->SetLineStyle(1);
629 legend->AddEntry(line, Form("Median: %f", median), "l");
631 for (Int_t i = 0; i < nsigma.GetNoElements(); i++) {
632 TLine* linePlusSigma = new TLine(median + nsigma[i] * sigma, 0, median + nsigma[i]*sigma, maxY);
633 //fListOfObjectsToBeDeleted->Add(linePlusSigma);
634 linePlusSigma->SetLineColor(kBlue);
635 linePlusSigma->SetLineStyle(2 + i);
636 linePlusSigma->Draw();
637 TLine* lineMinusSigma = new TLine(median - nsigma[i] * sigma, 0, median - nsigma[i]*sigma, maxY);
638 //fListOfObjectsToBeDeleted->Add(lineMinusSigma);
639 lineMinusSigma->SetLineColor(kBlue);
640 lineMinusSigma->SetLineStyle(2 + i);
641 lineMinusSigma->Draw();
642 legend->AddEntry(lineMinusSigma, Form("%i #sigma = %f",(Int_t)(nsigma[i]), (Float_t)(nsigma[i] * sigma)), "l");
648 Double_t ltm = GetLTM(entries, values, <mRms, ltmFraction);
649 TLine* line = new TLine(ltm, 0, ltm, maxY);
650 //fListOfObjectsToBeDeleted->Add(line);
651 line->SetLineColor(kGreen+2);
652 line->SetLineWidth(2);
653 line->SetLineStyle(1);
655 legend->AddEntry(line, Form("LTM: %f", ltm), "l");
657 for (Int_t i = 0; i < nsigma.GetNoElements(); i++) {
658 TLine* linePlusSigma = new TLine(ltm + nsigma[i] * ltmRms, 0, ltm + nsigma[i] * ltmRms, maxY);
659 //fListOfObjectsToBeDeleted->Add(linePlusSigma);
660 linePlusSigma->SetLineColor(kGreen+2);
661 linePlusSigma->SetLineStyle(2+i);
662 linePlusSigma->Draw();
664 TLine* lineMinusSigma = new TLine(ltm - nsigma[i] * ltmRms, 0, ltm - nsigma[i] * ltmRms, maxY);
665 //fListOfObjectsToBeDeleted->Add(lineMinusSigma);
666 lineMinusSigma->SetLineColor(kGreen+2);
667 lineMinusSigma->SetLineStyle(2+i);
668 lineMinusSigma->Draw();
669 legend->AddEntry(lineMinusSigma, Form("%i #sigma = %f", (Int_t)(nsigma[i]), (Float_t)(nsigma[i] * ltmRms)), "l");
672 if (!plotMean && !plotMedian && !plotLTM) return -1;
674 gStyle->SetOptStat(oldOptStat);
679 Int_t AliTPCCalibViewer::SigmaCut(const char* drawCommand, Int_t sector, const char* cuts, Float_t sigmaMax, Bool_t plotMean, Bool_t plotMedian, Bool_t plotLTM, Bool_t pm, const char *sigmas, Float_t sigmaStep) const {
681 // 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
682 // The data of the distribution Begin_Latex f(x, #mu, #sigma) End_Latex are given in 'array', 'n' specifies the length of the array
683 // '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
684 // 'nbins': number of bins, 'binLow': first bin, 'binUp': last bin
685 // sigmaMax: up to which sigma around the mean/median/LTM the histogram is generated (in units of sigma, Begin_Latex t #sigma End_Latex)
686 // sigmaStep: the binsize of the generated histogram
688 // 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)
692 // Creates a histogram, where you can see, how much of the data are inside sigma-intervals
693 // around the mean/median/LTM
694 // with drawCommand, sector and cuts you specify your input data, see EasyDraw
695 // sigmaMax: up to which sigma around the mean/median/LTM the histogram is generated (in units of sigma)
696 // sigmaStep: the binsize of the generated histogram
697 // plotMean/plotMedian/plotLTM: specifies where to put the center
699 if (sector >= 0 && sector < 72) {
700 return SigmaCut(drawCommand, Form("%i", sector), cuts, sigmaMax, plotMean, plotMedian, plotLTM, pm, sigmas, sigmaStep);
702 Error("SigmaCut","The TPC contains only sectors between 0 and 71.");
707 Int_t AliTPCCalibViewer::SigmaCut(const char* drawCommand, const char* sector, const char* cuts, Float_t sigmaMax, Bool_t plotMean, Bool_t plotMedian, Bool_t plotLTM, Bool_t pm, const char *sigmas, Float_t sigmaStep) const {
709 // Creates a histogram, where you can see, how much of the data are inside sigma-intervals
710 // around the mean/median/LTM
711 // with drawCommand, sector and cuts you specify your input data, see EasyDraw
712 // sigmaMax: up to which sigma around the mean/median/LTM the histogram is generated (in units of sigma)
713 // sigmaStep: the binsize of the generated histogram
714 // plotMean/plotMedian/plotLTM: specifies where to put the center
717 Double_t ltmFraction = 0.8;
719 TString drawStr(drawCommand);
720 Bool_t dangerousToDraw = drawStr.Contains(":") || drawStr.Contains(">>");
721 if (dangerousToDraw) {
722 Warning("SigmaCut", "The draw string must not contain ':' or '>>'.");
725 drawStr += " >> tempHist";
727 Int_t entries = EasyDraw1D(drawStr.Data(), sector, cuts, "goff");
728 TH1F *htemp = (TH1F*)gDirectory->Get("tempHist");
729 // FIXME is this histogram deleted automatically?
730 Double_t *values = fTree->GetV1(); // value is the array containing 'entries' numbers
732 Double_t mean = TMath::Mean(entries, values);
733 Double_t median = TMath::Median(entries, values);
734 Double_t sigma = TMath::RMS(entries, values);
736 TLegend * legend = new TLegend(.7,.7, .99, .99, "Cumulative");
737 //fListOfObjectsToBeDeleted->Add(legend);
738 TH1F *cutHistoMean = 0;
739 TH1F *cutHistoMedian = 0;
740 TH1F *cutHistoLTM = 0;
742 TObjArray *sigmasTokens = TString(sigmas).Tokenize(";");
743 TVectorF nsigma(sigmasTokens->GetEntriesFast());
744 for (Int_t i = 0; i < sigmasTokens->GetEntriesFast(); i++) {
745 TString str(((TObjString*)sigmasTokens->At(i))->GetString());
746 Double_t sig = (str.IsFloat()) ? str.Atof() : 0;
751 cutHistoMean = AliTPCCalibViewer::SigmaCut(htemp, mean, sigma, sigmaMax, sigmaStep, pm);
753 //fListOfObjectsToBeDeleted->Add(cutHistoMean);
754 cutHistoMean->SetLineColor(kRed);
755 legend->AddEntry(cutHistoMean, "Mean", "l");
756 cutHistoMean->SetTitle(Form("%s, cumulative; Multiples of #sigma; Fraction of included data", htemp->GetTitle()));
757 cutHistoMean->Draw();
758 DrawLines(cutHistoMean, nsigma, legend, kRed, pm);
759 } // if (cutHistoMean)
763 cutHistoMedian = AliTPCCalibViewer::SigmaCut(htemp, median, sigma, sigmaMax, sigmaStep, pm);
764 if (cutHistoMedian) {
765 //fListOfObjectsToBeDeleted->Add(cutHistoMedian);
766 cutHistoMedian->SetLineColor(kBlue);
767 legend->AddEntry(cutHistoMedian, "Median", "l");
768 cutHistoMedian->SetTitle(Form("%s, cumulative; Multiples of #sigma; Fraction of included data", htemp->GetTitle()));
769 if (plotMean && cutHistoMean) cutHistoMedian->Draw("same");
770 else cutHistoMedian->Draw();
771 DrawLines(cutHistoMedian, nsigma, legend, kBlue, pm);
772 } // if (cutHistoMedian)
776 Double_t ltm = GetLTM(entries, values, <mRms, ltmFraction);
777 cutHistoLTM = AliTPCCalibViewer::SigmaCut(htemp, ltm, ltmRms, sigmaMax, sigmaStep, pm);
779 //fListOfObjectsToBeDeleted->Add(cutHistoLTM);
780 cutHistoLTM->SetLineColor(kGreen+2);
781 legend->AddEntry(cutHistoLTM, "LTM", "l");
782 cutHistoLTM->SetTitle(Form("%s, cumulative; Multiples of #sigma; Fraction of included data", htemp->GetTitle()));
783 if ((plotMean && cutHistoMean) || (plotMedian && cutHistoMedian)) cutHistoLTM->Draw("same");
784 else cutHistoLTM->Draw();
785 DrawLines(cutHistoLTM, nsigma, legend, kGreen+2, pm);
788 if (!plotMean && !plotMedian && !plotLTM) return -1;
794 Int_t AliTPCCalibViewer::SigmaCutNew(const char* drawCommand, const char* sector, const char* cuts, Float_t /*sigmaMax*/, Bool_t plotMean, Bool_t plotMedian, Bool_t plotLTM, Bool_t /*pm*/, const char *sigmas, Float_t /*sigmaStep*/) const {
796 // Creates a histogram, where you can see, how much of the data are inside sigma-intervals
797 // around the mean/median/LTM
798 // with drawCommand, sector and cuts you specify your input data, see EasyDraw
799 // sigmaMax: up to which sigma around the mean/median/LTM the histogram is generated (in units of sigma)
800 // sigmaStep: the binsize of the generated histogram
801 // plotMean/plotMedian/plotLTM: specifies where to put the center
804 // Double_t ltmFraction = 0.8; //unused
806 TString drawStr(drawCommand);
807 drawStr += " >> tempHist";
809 Int_t entries = EasyDraw1D(drawStr.Data(), sector, cuts, "goff");
810 TH1F *htemp = (TH1F*)gDirectory->Get("tempHist");
811 TGraph *cutGraphMean = 0;
812 // TGraph *cutGraphMedian = 0;
813 // TGraph *cutGraphLTM = 0;
814 Double_t *values = fTree->GetV1(); // value is the array containing 'entries' numbers
815 Int_t *index = new Int_t[entries];
816 Float_t *xarray = new Float_t[entries];
817 Float_t *yarray = new Float_t[entries];
818 TMath::Sort(entries, values, index, kFALSE);
820 Double_t mean = TMath::Mean(entries, values);
821 // Double_t median = TMath::Median(entries, values);
822 Double_t sigma = TMath::RMS(entries, values);
824 TLegend * legend = new TLegend(.7,.7, .99, .99, "Cumulative");
825 //fListOfObjectsToBeDeleted->Add(legend);
827 // parse sigmas string
828 TObjArray *sigmasTokens = TString(sigmas).Tokenize(";");
829 TVectorF nsigma(sigmasTokens->GetEntriesFast());
830 for (Int_t i = 0; i < sigmasTokens->GetEntriesFast(); i++) {
831 TString str(((TObjString*)sigmasTokens->At(i))->GetString());
832 Double_t sig = (str.IsFloat()) ? str.Atof() : 0;
837 for (Int_t i = 0; i < entries; i++) {
838 xarray[i] = TMath::Abs(values[index[i]] - mean) / sigma;
839 yarray[i] = float(i) / float(entries);
841 cutGraphMean = new TGraph(entries, xarray, yarray);
843 //fListOfObjectsToBeDeleted->Add(cutGraphMean);
844 cutGraphMean->SetLineColor(kRed);
845 legend->AddEntry(cutGraphMean, "Mean", "l");
846 cutGraphMean->SetTitle(Form("%s, Cumulative; Multiples of #sigma; Fraction of included data", htemp->GetTitle()));
847 cutGraphMean->Draw("alu");
848 DrawLines(cutGraphMean, nsigma, legend, kRed, kTRUE);
856 cutHistoMedian = AliTPCCalibViewer::SigmaCut(htemp, median, sigma, sigmaMax, sigmaStep, pm);
857 if (cutHistoMedian) {
858 fListOfObjectsToBeDeleted->Add(cutHistoMedian);
859 cutHistoMedian->SetLineColor(kBlue);
860 legend->AddEntry(cutHistoMedian, "Median", "l");
861 cutHistoMedian->SetTitle(Form("%s, cumulative; Multiples of #sigma; Fraction of included data", htemp->GetTitle()));
862 if (plotMean && cutHistoMean) cutHistoMedian->Draw("same");
863 else cutHistoMedian->Draw();
864 DrawLines(cutHistoMedian, nsigma, legend, kBlue, pm);
865 } // if (cutHistoMedian)
869 Double_t ltm = GetLTM(entries, values, <mRms, ltmFraction);
870 cutHistoLTM = AliTPCCalibViewer::SigmaCut(htemp, ltm, ltmRms, sigmaMax, sigmaStep, pm);
872 fListOfObjectsToBeDeleted->Add(cutHistoLTM);
873 cutHistoLTM->SetLineColor(kGreen+2);
874 legend->AddEntry(cutHistoLTM, "LTM", "l");
875 cutHistoLTM->SetTitle(Form("%s, cumulative; Multiples of #sigma; Fraction of included data", htemp->GetTitle()));
876 if (plotMean && cutHistoMean || plotMedian && cutHistoMedian) cutHistoLTM->Draw("same");
877 else cutHistoLTM->Draw();
878 DrawLines(cutHistoLTM, nsigma, legend, kGreen+2, pm);
881 if (!plotMean && !plotMedian && !plotLTM) return -1;
887 Int_t AliTPCCalibViewer::Integrate(const char* drawCommand, Int_t sector, const char* cuts, Float_t sigmaMax, Bool_t plotMean, Bool_t plotMedian, Bool_t plotLTM, const char *sigmas, Float_t sigmaStep) const {
889 // 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"
890 // "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
891 // sigmaMax: up to which sigma around the mean/median/LTM you want to integrate
892 // if "igma == 0" and "sigmaMax == 0" the whole histogram is integrated
893 // "sigmaStep": the binsize of the generated histogram, -1 means, that the maximal reasonable stepsize is used
894 // The actual work is done on the array.
896 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
899 if (sector >= 0 && sector < 72) {
900 return Integrate(drawCommand, Form("%i", sector), cuts, sigmaMax, plotMean, plotMedian, plotLTM, sigmas, sigmaStep);
902 Error("Integrate","The TPC contains only sectors between 0 and 71.");
908 Int_t AliTPCCalibViewer::IntegrateOld(const char* drawCommand, const char* sector, const char* cuts, Float_t sigmaMax, Bool_t plotMean, Bool_t plotMedian, Bool_t plotLTM, const char *sigmas, Float_t sigmaStep) const {
910 // 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"
911 // "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
912 // sigmaMax: up to which sigma around the mean/median/LTM you want to integrate
913 // if "igma == 0" and "sigmaMax == 0" the whole histogram is integrated
914 // "sigmaStep": the binsize of the generated histogram, -1 means, that the maximal reasonable stepsize is used
915 // The actual work is done on the array.
917 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
921 Double_t ltmFraction = 0.8;
923 TString drawStr(drawCommand);
924 drawStr += " >> tempHist";
926 Int_t entries = EasyDraw1D(drawStr.Data(), sector, cuts, "goff");
927 TH1F *htemp = (TH1F*)gDirectory->Get("tempHist");
928 // FIXME is this histogram deleted automatically?
929 Double_t *values = fTree->GetV1(); // value is the array containing 'entries' numbers
931 Double_t mean = TMath::Mean(entries, values);
932 Double_t median = TMath::Median(entries, values);
933 Double_t sigma = TMath::RMS(entries, values);
935 TObjArray *sigmasTokens = TString(sigmas).Tokenize(";");
936 TVectorF nsigma(sigmasTokens->GetEntriesFast());
937 for (Int_t i = 0; i < sigmasTokens->GetEntriesFast(); i++) {
938 TString str(((TObjString*)sigmasTokens->At(i))->GetString());
939 Double_t sig = (str.IsFloat()) ? str.Atof() : 0;
943 TLegend * legend = new TLegend(.7,.7, .99, .99, "Integrated histogram");
944 //fListOfObjectsToBeDeleted->Add(legend);
945 TH1F *integralHistoMean = 0;
946 TH1F *integralHistoMedian = 0;
947 TH1F *integralHistoLTM = 0;
950 integralHistoMean = AliTPCCalibViewer::Integrate(htemp, mean, sigma, sigmaMax, sigmaStep);
951 if (integralHistoMean) {
952 //fListOfObjectsToBeDeleted->Add(integralHistoMean);
953 integralHistoMean->SetLineColor(kRed);
954 legend->AddEntry(integralHistoMean, "Mean", "l");
955 integralHistoMean->SetTitle(Form("%s, integrated; Multiples of #sigma; Fraction of included data", htemp->GetTitle()));
956 integralHistoMean->Draw();
957 DrawLines(integralHistoMean, nsigma, legend, kRed, kTRUE);
961 integralHistoMedian = AliTPCCalibViewer::Integrate(htemp, median, sigma, sigmaMax, sigmaStep);
962 if (integralHistoMedian) {
963 //fListOfObjectsToBeDeleted->Add(integralHistoMedian);
964 integralHistoMedian->SetLineColor(kBlue);
965 legend->AddEntry(integralHistoMedian, "Median", "l");
966 integralHistoMedian->SetTitle(Form("%s, integrated; Multiples of #sigma; Fraction of included data", htemp->GetTitle()));
967 if (plotMean && integralHistoMean) integralHistoMedian->Draw("same");
968 else integralHistoMedian->Draw();
969 DrawLines(integralHistoMedian, nsigma, legend, kBlue, kTRUE);
974 Double_t ltm = GetLTM(entries, values, <mRms, ltmFraction);
975 integralHistoLTM = AliTPCCalibViewer::Integrate(htemp, ltm, ltmRms, sigmaMax, sigmaStep);
976 if (integralHistoLTM) {
977 //fListOfObjectsToBeDeleted->Add(integralHistoLTM);
978 integralHistoLTM->SetLineColor(kGreen+2);
979 legend->AddEntry(integralHistoLTM, "LTM", "l");
980 integralHistoLTM->SetTitle(Form("%s, integrated; Multiples of #sigma; Fraction of included data", htemp->GetTitle()));
981 if ((plotMean && integralHistoMean) || (plotMedian && integralHistoMedian)) integralHistoLTM->Draw("same");
982 else integralHistoLTM->Draw();
983 DrawLines(integralHistoLTM, nsigma, legend, kGreen+2, kTRUE);
986 if (!plotMean && !plotMedian && !plotLTM) return -1;
992 Int_t AliTPCCalibViewer::Integrate(const char* drawCommand, const char* sector, const char* cuts, Float_t /*sigmaMax*/, Bool_t plotMean, Bool_t plotMedian, Bool_t plotLTM, const char *sigmas, Float_t /*sigmaStep*/) const {
994 // 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"
995 // "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
996 // sigmaMax: up to which sigma around the mean/median/LTM you want to integrate
997 // if "igma == 0" and "sigmaMax == 0" the whole histogram is integrated
998 // "sigmaStep": the binsize of the generated histogram, -1 means, that the maximal reasonable stepsize is used
999 // The actual work is done on the array.
1001 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
1005 Double_t ltmFraction = 0.8;
1007 TString drawStr(drawCommand);
1008 Bool_t dangerousToDraw = drawStr.Contains(":") || drawStr.Contains(">>");
1009 if (dangerousToDraw) {
1010 Warning("Integrate", "The draw string must not contain ':' or '>>'.");
1013 drawStr += " >> tempHist";
1015 Int_t entries = EasyDraw1D(drawStr.Data(), sector, cuts, "goff");
1016 TH1F *htemp = (TH1F*)gDirectory->Get("tempHist");
1017 TGraph *integralGraphMean = 0;
1018 TGraph *integralGraphMedian = 0;
1019 TGraph *integralGraphLTM = 0;
1020 Double_t *values = fTree->GetV1(); // value is the array containing 'entries' numbers
1021 Int_t *index = new Int_t[entries];
1022 Float_t *xarray = new Float_t[entries];
1023 Float_t *yarray = new Float_t[entries];
1024 TMath::Sort(entries, values, index, kFALSE);
1026 Double_t mean = TMath::Mean(entries, values);
1027 Double_t median = TMath::Median(entries, values);
1028 Double_t sigma = TMath::RMS(entries, values);
1030 // parse sigmas string
1031 TObjArray *sigmasTokens = TString(sigmas).Tokenize(";");
1032 TVectorF nsigma(sigmasTokens->GetEntriesFast());
1033 for (Int_t i = 0; i < sigmasTokens->GetEntriesFast(); i++) {
1034 TString str(((TObjString*)sigmasTokens->At(i))->GetString());
1035 Double_t sig = (str.IsFloat()) ? str.Atof() : 0;
1039 TLegend * legend = new TLegend(.7,.7, .99, .99, "Integrated histogram");
1040 //fListOfObjectsToBeDeleted->Add(legend);
1043 for (Int_t i = 0; i < entries; i++) {
1044 xarray[i] = (values[index[i]] - mean) / sigma;
1045 yarray[i] = float(i) / float(entries);
1047 integralGraphMean = new TGraph(entries, xarray, yarray);
1048 if (integralGraphMean) {
1049 //fListOfObjectsToBeDeleted->Add(integralGraphMean);
1050 integralGraphMean->SetLineColor(kRed);
1051 legend->AddEntry(integralGraphMean, "Mean", "l");
1052 integralGraphMean->SetTitle(Form("%s, integrated; Multiples of #sigma; Fraction of included data", htemp->GetTitle()));
1053 integralGraphMean->Draw("alu");
1054 DrawLines(integralGraphMean, nsigma, legend, kRed, kTRUE);
1058 for (Int_t i = 0; i < entries; i++) {
1059 xarray[i] = (values[index[i]] - median) / sigma;
1060 yarray[i] = float(i) / float(entries);
1062 integralGraphMedian = new TGraph(entries, xarray, yarray);
1063 if (integralGraphMedian) {
1064 //fListOfObjectsToBeDeleted->Add(integralGraphMedian);
1065 integralGraphMedian->SetLineColor(kBlue);
1066 legend->AddEntry(integralGraphMedian, "Median", "l");
1067 integralGraphMedian->SetTitle(Form("%s, integrated; Multiples of #sigma; Fraction of included data", htemp->GetTitle()));
1068 if (plotMean && integralGraphMean) integralGraphMedian->Draw("samelu");
1069 else integralGraphMedian->Draw("alu");
1070 DrawLines(integralGraphMedian, nsigma, legend, kBlue, kTRUE);
1074 Double_t ltmRms = 0;
1075 Double_t ltm = GetLTM(entries, values, <mRms, ltmFraction);
1076 for (Int_t i = 0; i < entries; i++) {
1077 xarray[i] = (values[index[i]] - ltm) / ltmRms;
1078 yarray[i] = float(i) / float(entries);
1080 integralGraphLTM = new TGraph(entries, xarray, yarray);
1081 if (integralGraphLTM) {
1082 //fListOfObjectsToBeDeleted->Add(integralGraphLTM);
1083 integralGraphLTM->SetLineColor(kGreen+2);
1084 legend->AddEntry(integralGraphLTM, "LTM", "l");
1085 integralGraphLTM->SetTitle(Form("%s, integrated; Multiples of #sigma; Fraction of included data", htemp->GetTitle()));
1086 if ((plotMean && integralGraphMean) || (plotMedian && integralGraphMedian)) integralGraphLTM->Draw("samelu");
1087 else integralGraphLTM->Draw("alu");
1088 DrawLines(integralGraphLTM, nsigma, legend, kGreen+2, kTRUE);
1095 if (!plotMean && !plotMedian && !plotLTM) return -1;
1101 void AliTPCCalibViewer::DrawLines(TH1F *histogram, TVectorF nsigma, TLegend *legend, Int_t color, Bool_t pm) const {
1103 // Private function for SigmaCut(...) and Integrate(...)
1104 // Draws lines into the given histogram, specified by "nsigma", the lines are addeed to the legend
1107 // start to draw the lines, loop over requested sigmas
1108 for (Int_t i = 0; i < nsigma.GetNoElements(); i++) {
1110 Int_t bin = histogram->GetXaxis()->FindBin(nsigma[i]);
1111 TLine* lineUp = new TLine(nsigma[i], 0, nsigma[i], histogram->GetBinContent(bin));
1112 //fListOfObjectsToBeDeleted->Add(lineUp);
1113 lineUp->SetLineColor(color);
1114 lineUp->SetLineStyle(2 + i);
1116 TLine* lineLeft = new TLine(nsigma[i], histogram->GetBinContent(bin), 0, histogram->GetBinContent(bin));
1117 //fListOfObjectsToBeDeleted->Add(lineLeft);
1118 lineLeft->SetLineColor(color);
1119 lineLeft->SetLineStyle(2 + i);
1121 legend->AddEntry(lineLeft, Form("Fraction(%f #sigma) = %f",nsigma[i], histogram->GetBinContent(bin)), "l");
1124 Int_t bin = histogram->GetXaxis()->FindBin(nsigma[i]);
1125 TLine* lineUp1 = new TLine(nsigma[i], 0, nsigma[i], histogram->GetBinContent(bin));
1126 //fListOfObjectsToBeDeleted->Add(lineUp1);
1127 lineUp1->SetLineColor(color);
1128 lineUp1->SetLineStyle(2 + i);
1130 TLine* lineLeft1 = new TLine(nsigma[i], histogram->GetBinContent(bin), histogram->GetBinLowEdge(0)+histogram->GetBinWidth(0), histogram->GetBinContent(bin));
1131 //fListOfObjectsToBeDeleted->Add(lineLeft1);
1132 lineLeft1->SetLineColor(color);
1133 lineLeft1->SetLineStyle(2 + i);
1135 legend->AddEntry(lineLeft1, Form("Fraction(+%f #sigma) = %f",nsigma[i], histogram->GetBinContent(bin)), "l");
1136 bin = histogram->GetXaxis()->FindBin(-nsigma[i]);
1137 TLine* lineUp2 = new TLine(-nsigma[i], 0, -nsigma[i], histogram->GetBinContent(bin));
1138 //fListOfObjectsToBeDeleted->Add(lineUp2);
1139 lineUp2->SetLineColor(color);
1140 lineUp2->SetLineStyle(2 + i);
1142 TLine* lineLeft2 = new TLine(-nsigma[i], histogram->GetBinContent(bin), histogram->GetBinLowEdge(0)+histogram->GetBinWidth(0), histogram->GetBinContent(bin));
1143 //fListOfObjectsToBeDeleted->Add(lineLeft2);
1144 lineLeft2->SetLineColor(color);
1145 lineLeft2->SetLineStyle(2 + i);
1147 legend->AddEntry(lineLeft2, Form("Fraction(-%f #sigma) = %f",nsigma[i], histogram->GetBinContent(bin)), "l");
1149 } // for (Int_t i = 0; i < nsigma.GetNoElements(); i++)
1153 void AliTPCCalibViewer::DrawLines(TGraph *graph, TVectorF nsigma, TLegend *legend, Int_t color, Bool_t pm) const {
1155 // Private function for SigmaCut(...) and Integrate(...)
1156 // Draws lines into the given histogram, specified by "nsigma", the lines are addeed to the legend
1159 // start to draw the lines, loop over requested sigmas
1160 for (Int_t i = 0; i < nsigma.GetNoElements(); i++) {
1162 TLine* lineUp = new TLine(nsigma[i], 0, nsigma[i], graph->Eval(nsigma[i]));
1163 //fListOfObjectsToBeDeleted->Add(lineUp);
1164 lineUp->SetLineColor(color);
1165 lineUp->SetLineStyle(2 + i);
1167 TLine* lineLeft = new TLine(nsigma[i], graph->Eval(nsigma[i]), 0, graph->Eval(nsigma[i]));
1168 //fListOfObjectsToBeDeleted->Add(lineLeft);
1169 lineLeft->SetLineColor(color);
1170 lineLeft->SetLineStyle(2 + i);
1172 legend->AddEntry(lineLeft, Form("Fraction(%f #sigma) = %f",nsigma[i], graph->Eval(nsigma[i])), "l");
1175 TLine* lineUp1 = new TLine(nsigma[i], 0, nsigma[i], graph->Eval(nsigma[i]));
1176 //fListOfObjectsToBeDeleted->Add(lineUp1);
1177 lineUp1->SetLineColor(color);
1178 lineUp1->SetLineStyle(2 + i);
1180 TLine* lineLeft1 = new TLine(nsigma[i], graph->Eval(nsigma[i]), graph->GetHistogram()->GetXaxis()->GetBinLowEdge(0), graph->Eval(nsigma[i]));
1181 //fListOfObjectsToBeDeleted->Add(lineLeft1);
1182 lineLeft1->SetLineColor(color);
1183 lineLeft1->SetLineStyle(2 + i);
1185 legend->AddEntry(lineLeft1, Form("Fraction(+%f #sigma) = %f",nsigma[i], graph->Eval(nsigma[i])), "l");
1186 TLine* lineUp2 = new TLine(-nsigma[i], 0, -nsigma[i], graph->Eval(-nsigma[i]));
1187 //fListOfObjectsToBeDeleted->Add(lineUp2);
1188 lineUp2->SetLineColor(color);
1189 lineUp2->SetLineStyle(2 + i);
1191 TLine* lineLeft2 = new TLine(-nsigma[i], graph->Eval(-nsigma[i]), graph->GetHistogram()->GetXaxis()->GetBinLowEdge(0), graph->Eval(-nsigma[i]));
1192 //fListOfObjectsToBeDeleted->Add(lineLeft2);
1193 lineLeft2->SetLineColor(color);
1194 lineLeft2->SetLineStyle(2 + i);
1196 legend->AddEntry(lineLeft2, Form("Fraction(-%f #sigma) = %f",nsigma[i], graph->Eval(-nsigma[i])), "l");
1198 } // for (Int_t i = 0; i < nsigma.GetNoElements(); i++)
1210 Int_t AliTPCCalibViewer::GetBin(Float_t value, Int_t nbins, Double_t binLow, Double_t binUp){
1211 // Returns the 'bin' for 'value'
1212 // The interval between 'binLow' and 'binUp' is divided into 'nbins' equidistant bins
1213 // avoid index out of bounds error: 'if (bin < binLow) bin = binLow' and vice versa
1215 GetBin(value) = #frac{nbins - 1}{binUp - binLow} #upoint (value - binLow) +1
1219 Int_t bin = TMath::Nint( (Float_t)(value - binLow) / (Float_t)(binUp - binLow) * (nbins-1) ) + 1;
1220 // avoid index out of bounds:
1221 if (value < binLow) bin = 0;
1222 if (value > binUp) bin = nbins + 1;
1228 Double_t AliTPCCalibViewer::GetLTM(Int_t n, const Double_t *const array, Double_t *const sigma, Double_t fraction){
1230 // returns the LTM and sigma
1232 Double_t *ddata = new Double_t[n];
1233 Double_t mean = 0, lsigma = 0;
1235 for (UInt_t i = 0; i < (UInt_t)n; i++) {
1236 ddata[nPoints]= array[nPoints];
1239 Int_t hh = TMath::Min(TMath::Nint(fraction * nPoints), Int_t(n));
1240 AliMathBase::EvaluateUni(nPoints, ddata, mean, lsigma, hh);
1241 if (sigma) *sigma = lsigma;
1247 TH1F* AliTPCCalibViewer::SigmaCut(TH1F *const histogram, Float_t mean, Float_t sigma, Float_t sigmaMax, Float_t sigmaStep, Bool_t pm) {
1249 // 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
1250 // The data of the distribution Begin_Latex f(x, #mu, #sigma) End_Latex are given in 'histogram'
1251 // '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
1252 // sigmaMax: up to which sigma around the mean/median/LTM the histogram is generated (in units of sigma, Begin_Latex t #sigma End_Latex)
1253 // sigmaStep: the binsize of the generated histogram, -1 means, that the maximal reasonable stepsize is used
1254 // pm: Decide weather Begin_Latex t > 0 End_Latex (first case) or Begin_Latex t End_Latex arbitrary (secound case)
1255 // The actual work is done on the array.
1257 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
1259 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
1264 Float_t sigma = 1.5;
1265 Float_t sigmaMax = 4;
1266 gROOT->SetStyle("Plain");
1267 TH1F *distribution = new TH1F("Distrib1", "Distribution f(x, #mu, #sigma)", 1000,-5,5);
1269 for (Int_t i = 0; i <50000;i++) distribution->Fill(rand.Gaus(mean, sigma));
1270 Float_t *ar = distribution->GetArray();
1272 TCanvas* macro_example_canvas = new TCanvas("cAliTPCCalibViewer1", "", 350, 350);
1273 macro_example_canvas->Divide(0,3);
1274 TVirtualPad *pad1 = macro_example_canvas->cd(1);
1277 distribution->Draw();
1278 TVirtualPad *pad2 = macro_example_canvas->cd(2);
1282 TH1F *shist = AliTPCCalibViewer::SigmaCut(distribution, mean, sigma, sigmaMax);
1283 shist->SetNameTitle("Cumulative","Cumulative S(t, #mu, #sigma)");
1285 TVirtualPad *pad3 = macro_example_canvas->cd(3);
1288 TH1F *shistPM = AliTPCCalibViewer::SigmaCut(distribution, mean, sigma, sigmaMax, -1, kTRUE);
1290 return macro_example_canvas;
1295 Float_t *array = histogram->GetArray();
1296 Int_t nbins = histogram->GetXaxis()->GetNbins();
1297 Float_t binLow = histogram->GetXaxis()->GetXmin();
1298 Float_t binUp = histogram->GetXaxis()->GetXmax();
1299 return AliTPCCalibViewer::SigmaCut(nbins, array, mean, sigma, nbins, binLow, binUp, sigmaMax, sigmaStep, pm);
1303 TH1F* AliTPCCalibViewer::SigmaCut(Int_t n, const Float_t *array, Float_t mean, Float_t sigma, Int_t nbins, Float_t binLow, Float_t binUp, Float_t sigmaMax, Float_t sigmaStep, Bool_t pm){
1305 // 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
1306 // The data of the distribution Begin_Latex f(x, #mu, #sigma) End_Latex are given in 'array', 'n' specifies the length of the array
1307 // '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
1308 // 'nbins': number of bins, 'binLow': first bin, 'binUp': last bin
1309 // sigmaMax: up to which sigma around the mean/median/LTM the histogram is generated (in units of sigma, Begin_Latex t #sigma End_Latex)
1310 // sigmaStep: the binsize of the generated histogram
1311 // Here the actual work is done.
1313 if (sigma == 0) return 0;
1314 Float_t binWidth = (binUp-binLow)/(nbins - 1);
1315 if (sigmaStep <= 0) sigmaStep = binWidth;
1316 Int_t kbins = (Int_t)(sigmaMax * sigma / sigmaStep) + 1; // + 1 due to overflow bin in histograms
1317 if (pm) kbins = 2 * (Int_t)(sigmaMax * sigma / sigmaStep) + 1;
1318 Float_t kbinLow = !pm ? 0 : -sigmaMax;
1319 Float_t kbinUp = sigmaMax;
1320 TH1F *hist = new TH1F("sigmaCutHisto","Cumulative; Multiples of #sigma; Fraction of included data", kbins, kbinLow, kbinUp);
1321 hist->SetDirectory(0);
1324 // calculate normalization
1325 Double_t normalization = 0;
1326 for (Int_t i = 0; i <= n; i++) {
1327 normalization += array[i];
1330 // given units: units from given histogram
1331 // sigma units: in units of sigma
1332 // iDelta: integrate in interval (mean +- iDelta), given units
1333 // x: ofset from mean for integration, given units
1336 // printf("nbins: %i, binLow: %f, binUp: %f \n", nbins, binLow, binUp);
1338 for (Float_t iDelta = 0; iDelta <= sigmaMax * sigma; iDelta += sigmaStep) {
1340 Double_t valueP = array[GetBin(mean, nbins, binLow, binUp)];
1341 Double_t valueM = array[GetBin(mean-binWidth, nbins, binLow, binUp)];
1342 // add bin of mean value only once to the histogram
1343 // printf("++ adding bins: ");
1344 for (Float_t x = binWidth; x <= iDelta; x += binWidth) {
1345 valueP += (mean + x <= binUp) ? array[GetBin(mean + x, nbins, binLow, binUp)] : 0;
1346 valueM += (mean-binWidth - x >= binLow) ? array[GetBin(mean-binWidth - x, nbins, binLow, binUp)] : 0;
1347 // printf("%i, ", GetBin(mean + x, nbins, binLow, binUp));
1350 if (valueP / normalization > 100) printf("+++ Error, value to big: %f, normalization with %f will fail +++ \n", valueP, normalization);
1351 if (valueP / normalization > 100) return hist;
1352 if (valueM / normalization > 100) printf("+++ Error, value to big: %f, normalization with %f will fail +++ \n", valueM, normalization);
1353 if (valueM / normalization > 100) return hist;
1354 valueP = (valueP / normalization);
1355 valueM = (valueM / normalization);
1357 Int_t bin = GetBin(iDelta/sigma, kbins, kbinLow, kbinUp);
1358 hist->SetBinContent(bin, valueP);
1359 bin = GetBin(-iDelta/sigma, kbins, kbinLow, kbinUp);
1360 hist->SetBinContent(bin, valueM);
1363 Int_t bin = GetBin(iDelta/sigma, kbins, kbinLow, kbinUp);
1364 hist->SetBinContent(bin, valueP + valueM);
1365 // printf(" first integration bin: %i, last integration bin in + direction: %i \n", GetBin(mean+binWidth, nbins, binLow, binUp), GetBin(iDelta, nbins, binLow, binUp));
1366 // printf(" first integration bin: %i, last integration bin in - direction: %i \n", GetBin(mean+binWidth, nbins, binLow, binUp), GetBin(-iDelta, nbins, binLow, binUp));
1367 // printf(" value: %f, normalization: %f, iDelta: %f, Bin: %i \n", valueP+valueM, normalization, iDelta, bin);
1370 //hist->SetMaximum(0.7);
1371 if (!pm) hist->SetMaximum(1.2);
1376 TH1F* AliTPCCalibViewer::SigmaCut(Int_t /*n*/, const Double_t */*array*/, Double_t /*mean*/, Double_t /*sigma*/, Int_t /*nbins*/, const Double_t */*xbins*/, Double_t /*sigmaMax*/){
1378 // SigmaCut for variable binsize
1379 // NOT YET IMPLEMENTED !!!
1381 printf("SigmaCut with variable binsize, Not yet implemented\n");
1387 TH1F* AliTPCCalibViewer::Integrate(TH1F *const histogram, Float_t mean, Float_t sigma, Float_t sigmaMax, Float_t sigmaStep){
1389 // 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"
1390 // "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
1391 // sigmaMax: up to which sigma around the mean/median/LTM you want to integrate
1392 // if "igma == 0" and "sigmaMax == 0" the whole histogram is integrated
1393 // "sigmaStep": the binsize of the generated histogram, -1 means, that the maximal reasonable stepsize is used
1394 // The actual work is done on the array.
1396 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
1401 Float_t sigma = 1.5;
1402 Float_t sigmaMax = 4;
1403 gROOT->SetStyle("Plain");
1404 TH1F *distribution = new TH1F("Distrib2", "Distribution f(x, #mu, #sigma)", 1000,-5,5);
1406 for (Int_t i = 0; i <50000;i++) distribution->Fill(rand.Gaus(mean, sigma));
1407 Float_t *ar = distribution->GetArray();
1409 TCanvas* macro_example_canvas = new TCanvas("cAliTPCCalibViewer2", "", 350, 350);
1410 macro_example_canvas->Divide(0,2);
1411 TVirtualPad *pad1 = macro_example_canvas->cd(1);
1414 distribution->Draw();
1415 TVirtualPad *pad2 = macro_example_canvas->cd(2);
1418 TH1F *shist = AliTPCCalibViewer::Integrate(distribution, mean, sigma, sigmaMax);
1419 shist->SetNameTitle("Cumulative","Cumulative S(t, #mu, #sigma)");
1422 return macro_example_canvas_Integrate;
1428 Float_t *array = histogram->GetArray();
1429 Int_t nbins = histogram->GetXaxis()->GetNbins();
1430 Float_t binLow = histogram->GetXaxis()->GetXmin();
1431 Float_t binUp = histogram->GetXaxis()->GetXmax();
1432 return AliTPCCalibViewer::Integrate(nbins, array, nbins, binLow, binUp, mean, sigma, sigmaMax, sigmaStep);
1436 TH1F* AliTPCCalibViewer::Integrate(Int_t n, const Float_t *const array, Int_t nbins, Float_t binLow, Float_t binUp, Float_t mean, Float_t sigma, Float_t sigmaMax, Float_t sigmaStep){
1437 // 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"
1438 // "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
1439 // sigmaMax: up to which sigma around the mean/median/LTM you want to integrate
1440 // if "igma == 0" and "sigmaMax == 0" the whole histogram is integrated
1441 // "sigmaStep": the binsize of the generated histogram, -1 means, that the maximal reasonable stepsize is used
1442 // Here the actual work is done.
1444 Bool_t givenUnits = kTRUE;
1445 if (sigma != 0 && sigmaMax != 0) givenUnits = kFALSE;
1448 sigmaMax = (binUp - binLow) / 2.;
1451 Float_t binWidth = (binUp-binLow)/(nbins - 1);
1452 if (sigmaStep <= 0) sigmaStep = binWidth;
1453 Int_t kbins = (Int_t)(sigmaMax * sigma / sigmaStep) + 1; // + 1 due to overflow bin in histograms
1454 Float_t kbinLow = givenUnits ? binLow : -sigmaMax;
1455 Float_t kbinUp = givenUnits ? binUp : sigmaMax;
1457 if (givenUnits) hist = new TH1F("integratedHisto","Integrated Histogram; Given x; Fraction of included data", kbins, kbinLow, kbinUp);
1458 if (!givenUnits) hist = new TH1F("integratedHisto","Integrated Histogram; Multiples of #sigma; Fraction of included data", kbins, kbinLow, kbinUp);
1459 hist->SetDirectory(0);
1462 // calculate normalization
1463 // printf("calculating normalization, integrating from bin 1 to %i \n", n);
1464 Double_t normalization = 0;
1465 for (Int_t i = 1; i <= n; i++) {
1466 normalization += array[i];
1468 // printf("normalization: %f \n", normalization);
1470 // given units: units from given histogram
1471 // sigma units: in units of sigma
1472 // iDelta: integrate in interval (mean +- iDelta), given units
1473 // x: ofset from mean for integration, given units
1477 for (Float_t iDelta = mean - sigmaMax * sigma; iDelta <= mean + sigmaMax * sigma; iDelta += sigmaStep) {
1480 for (Float_t x = mean - sigmaMax * sigma; x <= iDelta; x += binWidth) {
1481 value += (x <= binUp && x >= binLow) ? array[GetBin(x, nbins, binLow, binUp)] : 0;
1483 if (value / normalization > 100) printf("+++ Error, value to big: %f, normalization with %f will fail +++ \n", value, normalization);
1484 if (value / normalization > 100) return hist;
1485 Int_t bin = GetBin(iDelta/sigma, kbins, kbinLow, kbinUp);
1486 // printf("first integration bin: %i, last integration bin: %i \n", GetBin(mean - sigmaMax * sigma, nbins, binLow, binUp), GetBin(iDelta, nbins, binLow, binUp));
1487 // printf("value: %f, normalization: %f, normalized value: %f, iDelta: %f, Bin: %i \n", value, normalization, value/normalization, iDelta, bin);
1488 value = (value / normalization);
1489 hist->SetBinContent(bin, value);
1498 ////////////////////////
1499 // end of Array tools //
1500 ////////////////////////
1504 //_____________________________________________________________________________
1505 AliTPCCalPad* AliTPCCalibViewer::GetCalPadOld(const char* desiredData, const char* cuts, const char* calPadName) const {
1507 // creates a AliTPCCalPad out of the 'desiredData'
1508 // the functionality of EasyDraw1D is used
1509 // calPadName specifies the name of the created AliTPCCalPad
1510 // - this takes a while -
1512 TString drawStr(desiredData);
1513 drawStr.Append(":channel");
1514 drawStr.Append(fAbbreviation);
1515 AliTPCCalPad * createdCalPad = new AliTPCCalPad(calPadName, calPadName);
1517 for (Int_t sec = 0; sec < 72; sec++) {
1518 AliTPCCalROC * roc = createdCalPad->GetCalROC(sec);
1519 entries = EasyDraw1D(drawStr.Data(), (Int_t)sec, cuts, "goff");
1520 if (entries == -1) return 0;
1521 const Double_t *pchannel = fTree->GetV2();
1522 const Double_t *pvalue = fTree->GetV1();
1523 for (Int_t i = 0; i < entries; i++)
1524 roc->SetValue((UInt_t)(pchannel[i]), (Float_t)(pvalue[i]));
1526 return createdCalPad;
1530 //_____________________________________________________________________________
1531 AliTPCCalPad* AliTPCCalibViewer::GetCalPad(const char* desiredData, const char* cuts, const char* calPadName) const {
1533 // creates a AliTPCCalPad out of the 'desiredData'
1534 // the functionality of EasyDraw1D is used
1535 // calPadName specifies the name of the created AliTPCCalPad
1536 // - this takes a while -
1538 TString drawStr(desiredData);
1539 drawStr.Append(":channel.fElements:sector");
1540 AliTPCCalPad * createdCalPad = new AliTPCCalPad(calPadName, calPadName);
1542 Int_t entries = fTree->Draw(drawStr, cuts,"goff");
1543 const Double_t *pvalue = fTree->GetV1();
1544 const Double_t *pchannel = fTree->GetV2();
1545 const Double_t *psector = fTree->GetV3();
1547 for (Int_t ientry=0; ientry<entries; ientry++){
1548 Int_t sector= TMath::Nint(psector[ientry]);
1549 AliTPCCalROC * roc = createdCalPad->GetCalROC(sector);
1550 if (roc) roc->SetValue((UInt_t)(pchannel[ientry]), (Float_t)(pvalue[ientry]));
1553 // for (Int_t sec = 0; sec < 72; sec++) {
1554 // AliTPCCalROC * roc = createdCalPad->GetCalROC(sec);
1555 // entries = EasyDraw1D(drawStr.Data(), (Int_t)sec, cuts, "goff");
1556 // if (entries == -1) return 0;
1557 // for (Int_t i = 0; i < entries; i++)
1558 // roc->SetValue((UInt_t)(pchannel[i]), (Float_t)(pvalue[i]));
1560 return createdCalPad;
1563 //_____________________________________________________________________________
1564 AliTPCCalROC* AliTPCCalibViewer::GetCalROC(const char* desiredData, UInt_t sector, const char* cuts) const {
1566 // creates a AliTPCCalROC out of the desiredData
1567 // the functionality of EasyDraw1D is used
1568 // sector specifies the sector of the created AliTPCCalROC
1570 TString drawStr(desiredData);
1571 drawStr.Append(":channel");
1572 drawStr.Append(fAbbreviation);
1573 Int_t entries = EasyDraw1D(drawStr.Data(), (Int_t)sector, cuts, "goff");
1574 if (entries == -1) return 0;
1575 AliTPCCalROC * createdROC = new AliTPCCalROC(sector);
1576 for (Int_t i = 0; i < entries; i++)
1577 createdROC->SetValue((UInt_t)(fTree->GetV2()[i]), fTree->GetV1()[i]);
1582 TObjArray* AliTPCCalibViewer::GetListOfVariables(Bool_t printList) {
1584 // scan the tree - produces a list of available variables in the tree
1585 // printList: print the list to the screen, after the scan is done
1587 TObjArray* arr = new TObjArray();
1588 TObjString* str = 0;
1589 if (!fTree) return 0;
1590 Int_t nentries = fTree->GetListOfBranches()->GetEntries();
1591 for (Int_t i = 0; i < nentries; i++) {
1592 str = new TObjString(fTree->GetListOfBranches()->At(i)->GetName());
1593 str->String().ReplaceAll("_Median", "");
1594 str->String().ReplaceAll("_Mean", "");
1595 str->String().ReplaceAll("_RMS", "");
1596 str->String().ReplaceAll("_LTM", "");
1597 str->String().ReplaceAll("_OutlierCutted", "");
1598 str->String().ReplaceAll(".", "");
1599 if (!arr->FindObject(str) &&
1600 !(str->String() == "channel" || str->String() == "gx" || str->String() == "gy" ||
1601 str->String() == "lx" || str->String() == "ly" || str->String() == "pad" ||
1602 str->String() == "row" || str->String() == "rpad" || str->String() == "sector" ))
1606 // loop over all friends (if there are some) and add them to the list
1607 if (fTree->GetListOfFriends()) {
1608 for (Int_t ifriend = 0; ifriend < fTree->GetListOfFriends()->GetEntries(); ifriend++){
1609 // printf("iterating through friendlist, currently at %i\n", ifriend);
1610 // printf("working with %s\n", fTree->GetListOfFriends()->At(ifriend)->ClassName());
1611 if (TString(fTree->GetListOfFriends()->At(ifriend)->ClassName()) != "TFriendElement") continue; // no friendElement found
1612 TFriendElement *friendElement = (TFriendElement*)fTree->GetListOfFriends()->At(ifriend);
1613 if (friendElement->GetTree() == 0) continue; // no tree found in friendElement
1614 // printf("friend found \n");
1615 for (Int_t i = 0; i < friendElement->GetTree()->GetListOfBranches()->GetEntries(); i++) {
1616 // printf("iterating through friendelement entries, currently at %i\n", i);
1617 str = new TObjString(friendElement->GetTree()->GetListOfBranches()->At(i)->GetName());
1618 str->String().ReplaceAll("_Median", "");
1619 str->String().ReplaceAll("_Mean", "");
1620 str->String().ReplaceAll("_RMS", "");
1621 str->String().ReplaceAll("_LTM", "");
1622 str->String().ReplaceAll("_OutlierCutted", "");
1623 str->String().ReplaceAll(".", "");
1624 if (!(str->String() == "channel" || str->String() == "gx" || str->String() == "gy" ||
1625 str->String() == "lx" || str->String() == "ly" || str->String() == "pad" ||
1626 str->String() == "row" || str->String() == "rpad" || str->String() == "sector" )){
1627 // insert "<friendName>." at the beginning: (<friendName> is per default "R")
1628 str->String().Insert(0, ".");
1629 str->String().Insert(0, friendElement->GetName());
1630 if (!arr->FindObject(str)) arr->Add(str);
1631 // printf("added string %s \n", str->String().Data());
1635 } // if (fTree->GetListOfFriends())
1638 // ((TFriendElement*)gui->GetViewer()->GetTree()->GetListOfFriends()->At(0))->GetTree()->GetListOfBranches()->At(0)->GetName()
1639 // ((TFriendElement*)gui->GetViewer()->GetTree()->GetListOfFriends()->At(0))->GetTree()->GetListOfBranches()
1643 TIterator* iter = arr->MakeIterator();
1645 TObjString* currentStr = 0;
1646 while ( (currentStr = (TObjString*)(iter->Next())) ) {
1647 std::cout << currentStr->GetString().Data() << std::endl;
1655 TObjArray* AliTPCCalibViewer::GetListOfNormalizationVariables(Bool_t printList) const{
1657 // produces a list of available variables for normalization in the tree
1658 // printList: print the list to the screen, after the scan is done
1660 TObjArray* arr = new TObjArray();
1661 arr->Add(new TObjString("_Mean"));
1662 arr->Add(new TObjString("_Mean_OutlierCutted"));
1663 arr->Add(new TObjString("_Median"));
1664 arr->Add(new TObjString("_Median_OutlierCutted"));
1665 arr->Add(new TObjString("_LTM"));
1666 arr->Add(new TObjString("_LTM_OutlierCutted"));
1667 arr->Add(new TObjString(Form("LFitIntern_4_8%s", fAppendString.Data())));
1668 arr->Add(new TObjString(Form("GFitIntern_Lin%s", fAppendString.Data())));
1669 arr->Add(new TObjString(Form("GFitIntern_Par%s", fAppendString.Data())));
1670 arr->Add(new TObjString("FitLinLocal"));
1671 arr->Add(new TObjString("FitLinGlobal"));
1672 arr->Add(new TObjString("FitParLocal"));
1673 arr->Add(new TObjString("FitParGlobal"));
1676 TIterator* iter = arr->MakeIterator();
1678 TObjString* currentStr = 0;
1679 while ((currentStr = (TObjString*)(iter->Next()))) {
1680 std::cout << currentStr->GetString().Data() << std::endl;
1688 TFriendElement* AliTPCCalibViewer::AddReferenceTree(const char* filename, const char* treename, const char* refname){
1690 // add a reference tree to the current tree
1691 // by default the treename is 'calPads' and the reference treename is 'R'
1693 TFile *file = new TFile(filename);
1694 fListOfObjectsToBeDeleted->Add(file);
1695 TTree * tree = (TTree*)file->Get(treename);
1696 return AddFriend(tree, refname);
1700 TObjArray* AliTPCCalibViewer::GetArrayOfCalPads(){
1702 // Returns a TObjArray with all AliTPCCalPads that are stored in the tree
1703 // - this takes a while -
1705 TObjArray *listOfCalPads = GetListOfVariables();
1706 TObjArray *calPadsArray = new TObjArray();
1707 Int_t numberOfCalPads = listOfCalPads->GetEntries();
1708 for (Int_t i = 0; i < numberOfCalPads; i++) {
1709 std::cout << "Creating calPad " << (i+1) << " of " << numberOfCalPads << "\r" << std::flush;
1710 char* calPadName = (char*)((TObjString*)(listOfCalPads->At(i)))->GetString().Data();
1711 TString drawCommand = ((TObjString*)(listOfCalPads->At(i)))->GetString();
1712 drawCommand.Append(fAbbreviation.Data());
1713 AliTPCCalPad* calPad = GetCalPad(drawCommand.Data(), "", calPadName);
1714 calPadsArray->Add(calPad);
1716 std::cout << std::endl;
1717 listOfCalPads->Delete();
1718 delete listOfCalPads;
1719 return calPadsArray;
1723 TString* AliTPCCalibViewer::Fit(const char* drawCommand, const char* formula, const char* cuts, Double_t & chi2, TVectorD &fitParam, TMatrixD &covMatrix){
1725 // fit an arbitrary function, specified by formula into the data, specified by drawCommand and cuts
1726 // returns chi2, fitParam and covMatrix
1727 // returns TString with fitted formula
1730 TString formulaStr(formula);
1731 TString drawStr(drawCommand);
1732 TString cutStr(cuts);
1735 drawStr.ReplaceAll(fAbbreviation, fAppendString);
1736 cutStr.ReplaceAll(fAbbreviation, fAppendString);
1737 formulaStr.ReplaceAll(fAbbreviation, fAppendString);
1739 formulaStr.ReplaceAll("++", fAbbreviation);
1740 TObjArray* formulaTokens = formulaStr.Tokenize(fAbbreviation.Data());
1741 Int_t dim = formulaTokens->GetEntriesFast();
1743 fitParam.ResizeTo(dim);
1744 covMatrix.ResizeTo(dim,dim);
1746 TLinearFitter* fitter = new TLinearFitter(dim+1, Form("hyp%d",dim));
1747 fitter->StoreData(kTRUE);
1748 fitter->ClearPoints();
1750 Int_t entries = Draw(drawStr.Data(), cutStr.Data(), "goff");
1751 if (entries == -1) return new TString("An ERROR has occured during fitting!");
1752 Double_t **values = new Double_t*[dim+1] ;
1754 for (Int_t i = 0; i < dim + 1; i++){
1756 if (i < dim) centries = fTree->Draw(((TObjString*)formulaTokens->At(i))->GetName(), cutStr.Data(), "goff");
1757 else centries = fTree->Draw(drawStr.Data(), cutStr.Data(), "goff");
1759 if (entries != centries) {
1761 return new TString("An ERROR has occured during fitting!");
1763 values[i] = new Double_t[entries];
1764 memcpy(values[i], fTree->GetV1(), entries*sizeof(Double_t));
1767 // add points to the fitter
1768 for (Int_t i = 0; i < entries; i++){
1770 for (Int_t j=0; j<dim;j++) x[j]=values[j][i];
1771 fitter->AddPoint(x, values[dim][i], 1);
1775 fitter->GetParameters(fitParam);
1776 fitter->GetCovarianceMatrix(covMatrix);
1777 chi2 = fitter->GetChisquare();
1780 TString *preturnFormula = new TString(Form("( %e+",fitParam[0])), &returnFormula = *preturnFormula;
1782 for (Int_t iparam = 0; iparam < dim; iparam++) {
1783 returnFormula.Append(Form("%s*(%e)",((TObjString*)formulaTokens->At(iparam))->GetName(),fitParam[iparam+1]));
1784 if (iparam < dim-1) returnFormula.Append("+");
1786 returnFormula.Append(" )");
1787 delete formulaTokens;
1789 for (Int_t i = 0; i < dim + 1; i++){
1790 delete [] values[i];
1793 return preturnFormula;
1797 void AliTPCCalibViewer::MakeTreeWithObjects(const char *fileName, const TObjArray *const array, const char * mapFileName) {
1799 // Write tree with all available information
1800 // im mapFileName is speciefied, the Map information are also written to the tree
1801 // AliTPCCalPad-Objects are written directly to the tree, so that they can be accessd later on
1802 // (does not work!!!)
1804 AliTPCROC* tpcROCinstance = AliTPCROC::Instance();
1806 TObjArray* mapIROCs = 0;
1807 TObjArray* mapOROCs = 0;
1808 TVectorF *mapIROCArray = 0;
1809 TVectorF *mapOROCArray = 0;
1810 Int_t mapEntries = 0;
1811 TString* mapNames = 0;
1814 TFile mapFile(mapFileName, "read");
1816 TList* listOfROCs = mapFile.GetListOfKeys();
1817 mapEntries = listOfROCs->GetEntries()/2;
1818 mapIROCs = new TObjArray(mapEntries*2);
1819 mapOROCs = new TObjArray(mapEntries*2);
1820 mapIROCArray = new TVectorF[mapEntries];
1821 mapOROCArray = new TVectorF[mapEntries];
1823 mapNames = new TString[mapEntries];
1824 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
1825 TString rocName(((TKey*)(listOfROCs->At(ivalue*2)))->GetName());
1826 rocName.Remove(rocName.Length()-4, 4);
1827 mapIROCs->AddAt((AliTPCCalROC*)mapFile.Get((rocName + "IROC").Data()), ivalue);
1828 mapOROCs->AddAt((AliTPCCalROC*)mapFile.Get((rocName + "OROC").Data()), ivalue);
1829 mapNames[ivalue].Append(rocName);
1832 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
1833 mapIROCArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(0));
1834 mapOROCArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(36));
1836 for (UInt_t ichannel = 0; ichannel < tpcROCinstance->GetNChannels(0); ichannel++)
1837 (mapIROCArray[ivalue])[ichannel] = ((AliTPCCalROC*)(mapIROCs->At(ivalue)))->GetValue(ichannel);
1838 for (UInt_t ichannel = 0; ichannel < tpcROCinstance->GetNChannels(36); ichannel++)
1839 (mapOROCArray[ivalue])[ichannel] = ((AliTPCCalROC*)(mapOROCs->At(ivalue)))->GetValue(ichannel);
1842 } // if (mapFileName)
1844 TTreeSRedirector cstream(fileName);
1845 Int_t arrayEntries = array->GetEntries();
1847 // Read names of AliTPCCalPads and save them in names[]
1848 TString* names = new TString[arrayEntries];
1849 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++)
1850 names[ivalue].Append(((AliTPCCalPad*)array->At(ivalue))->GetName());
1852 for (UInt_t isector = 0; isector < tpcROCinstance->GetNSectors(); isector++) {
1854 TVectorF *vectorArray = new TVectorF[arrayEntries];
1855 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++)
1856 vectorArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(isector));
1860 // fill vectors of variable per pad
1862 TVectorF *posArray = new TVectorF[8];
1863 for (Int_t ivalue = 0; ivalue < 8; ivalue++)
1864 posArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(isector));
1866 Float_t posG[3] = {0};
1867 Float_t posL[3] = {0};
1869 for (UInt_t irow = 0; irow < tpcROCinstance->GetNRows(isector); irow++) {
1870 for (UInt_t ipad = 0; ipad < tpcROCinstance->GetNPads(isector, irow); ipad++) {
1871 tpcROCinstance->GetPositionLocal(isector, irow, ipad, posL);
1872 tpcROCinstance->GetPositionGlobal(isector, irow, ipad, posG);
1873 posArray[0][ichannel] = irow;
1874 posArray[1][ichannel] = ipad;
1875 posArray[2][ichannel] = posL[0];
1876 posArray[3][ichannel] = posL[1];
1877 posArray[4][ichannel] = posG[0];
1878 posArray[5][ichannel] = posG[1];
1879 posArray[6][ichannel] = (Int_t)(ipad - (Double_t)(tpcROCinstance->GetNPads(isector, irow))/2);
1880 posArray[7][ichannel] = ichannel;
1882 // loop over array containing AliTPCCalPads
1883 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
1884 AliTPCCalPad* calPad = (AliTPCCalPad*) array->At(ivalue);
1885 AliTPCCalROC* calROC = calPad->GetCalROC(isector);
1887 (vectorArray[ivalue])[ichannel] = calROC->GetValue(irow, ipad);
1889 (vectorArray[ivalue])[ichannel] = 0;
1894 AliTPCCalROC dummyROC(0);
1895 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
1896 AliTPCCalROC *roc = ((AliTPCCalPad*)array->At(ivalue))->GetCalROC(isector);
1897 if (!roc) roc = &dummyROC;
1898 cstream << "calPads" <<
1899 (Char_t*)((names[ivalue] + ".=").Data()) << &vectorArray[ivalue];
1900 cstream << "calPads" <<
1901 (Char_t*)((names[ivalue] + "Pad.=").Data()) << roc;
1905 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
1907 cstream << "calPads" <<
1908 (Char_t*)((mapNames[ivalue] + ".=").Data()) << &mapIROCArray[ivalue];
1910 cstream << "calPads" <<
1911 (Char_t*)((mapNames[ivalue] + ".=").Data()) << &mapOROCArray[ivalue];
1915 cstream << "calPads" <<
1916 "sector=" << isector;
1918 cstream << "calPads" <<
1919 "row.=" << &posArray[0] <<
1920 "pad.=" << &posArray[1] <<
1921 "lx.=" << &posArray[2] <<
1922 "ly.=" << &posArray[3] <<
1923 "gx.=" << &posArray[4] <<
1924 "gy.=" << &posArray[5] <<
1925 "rpad.=" << &posArray[6] <<
1926 "channel.=" << &posArray[7];
1928 cstream << "calPads" <<
1932 delete[] vectorArray;
1933 } //for (UInt_t isector = 0; isector < tpcROCinstance->GetNSectors(); isector++)
1939 delete[] mapIROCArray;
1940 delete[] mapOROCArray;
1946 void AliTPCCalibViewer::MakeTree(const char * fileName, TObjArray * array, const char * mapFileName, AliTPCCalPad *const outlierPad, Float_t ltmFraction) {
1948 // Write a tree with all available information
1949 // if mapFileName is speciefied, the Map information are also written to the tree
1950 // pads specified in outlierPad are not used for calculating statistics
1951 // The following statistical information on the basis of a ROC are calculated:
1952 // "_Median", "_Mean", "_LTM", "_RMS_LTM"
1953 // "_Median_OutlierCutted", "_Mean_OutlierCutted", "_RMS_OutlierCutted", "_LTM_OutlierCutted", "_RMS_LTM_OutlierCutted"
1954 // The following position variables are available:
1955 // "row", "pad", "lx", "ly", "gx", "gy", "rpad", "channel"
1957 // The tree out of this function is the basis for the AliTPCCalibViewer and the AliTPCCalibViewerGUI.
1959 AliTPCROC* tpcROCinstance = AliTPCROC::Instance();
1961 TObjArray* mapIROCs = 0;
1962 TObjArray* mapOROCs = 0;
1963 TVectorF *mapIROCArray = 0;
1964 TVectorF *mapOROCArray = 0;
1965 Int_t mapEntries = 0;
1966 TString* mapNames = 0;
1969 TFile mapFile(mapFileName, "read");
1971 TList* listOfROCs = mapFile.GetListOfKeys();
1972 mapEntries = listOfROCs->GetEntries()/2;
1973 mapIROCs = new TObjArray(mapEntries*2);
1974 mapOROCs = new TObjArray(mapEntries*2);
1975 mapIROCArray = new TVectorF[mapEntries];
1976 mapOROCArray = new TVectorF[mapEntries];
1978 mapNames = new TString[mapEntries];
1979 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
1980 TString rocName(((TKey*)(listOfROCs->At(ivalue*2)))->GetName());
1981 rocName.Remove(rocName.Length()-4, 4);
1982 mapIROCs->AddAt((AliTPCCalROC*)mapFile.Get((rocName + "IROC").Data()), ivalue);
1983 mapOROCs->AddAt((AliTPCCalROC*)mapFile.Get((rocName + "OROC").Data()), ivalue);
1984 mapNames[ivalue].Append(rocName);
1987 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
1988 mapIROCArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(0));
1989 mapOROCArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(36));
1991 for (UInt_t ichannel = 0; ichannel < tpcROCinstance->GetNChannels(0); ichannel++)
1992 (mapIROCArray[ivalue])[ichannel] = ((AliTPCCalROC*)(mapIROCs->At(ivalue)))->GetValue(ichannel);
1993 for (UInt_t ichannel = 0; ichannel < tpcROCinstance->GetNChannels(36); ichannel++)
1994 (mapOROCArray[ivalue])[ichannel] = ((AliTPCCalROC*)(mapOROCs->At(ivalue)))->GetValue(ichannel);
1997 } // if (mapFileName)
1999 TTreeSRedirector cstream(fileName);
2000 Int_t arrayEntries = 0;
2001 if (array) arrayEntries = array->GetEntries();
2003 TString* names = new TString[arrayEntries];
2004 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++)
2005 names[ivalue].Append(((AliTPCCalPad*)array->At(ivalue))->GetName());
2007 for (UInt_t isector = 0; isector < tpcROCinstance->GetNSectors(); isector++) {
2009 // get statistic for given sector
2011 TVectorF median(arrayEntries);
2012 TVectorF mean(arrayEntries);
2013 TVectorF rms(arrayEntries);
2014 TVectorF ltm(arrayEntries);
2015 TVectorF ltmrms(arrayEntries);
2016 TVectorF medianWithOut(arrayEntries);
2017 TVectorF meanWithOut(arrayEntries);
2018 TVectorF rmsWithOut(arrayEntries);
2019 TVectorF ltmWithOut(arrayEntries);
2020 TVectorF ltmrmsWithOut(arrayEntries);
2022 TVectorF *vectorArray = new TVectorF[arrayEntries];
2023 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++){
2024 vectorArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(isector));
2025 vectorArray[ivalue].SetUniqueID(array->UncheckedAt(ivalue)->GetUniqueID());
2026 // printf("UniqueID: %d\n",vectorArray[ivalue].GetUniqueID());
2029 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
2030 AliTPCCalPad* calPad = (AliTPCCalPad*) array->At(ivalue);
2031 AliTPCCalROC* calROC = calPad->GetCalROC(isector);
2032 AliTPCCalROC* outlierROC = 0;
2033 if (outlierPad) outlierROC = outlierPad->GetCalROC(isector);
2035 median[ivalue] = calROC->GetMedian();
2036 mean[ivalue] = calROC->GetMean();
2037 rms[ivalue] = calROC->GetRMS();
2038 Double_t ltmrmsValue = 0;
2039 ltm[ivalue] = calROC->GetLTM(<mrmsValue, ltmFraction);
2040 ltmrms[ivalue] = ltmrmsValue;
2042 medianWithOut[ivalue] = calROC->GetMedian(outlierROC);
2043 meanWithOut[ivalue] = calROC->GetMean(outlierROC);
2044 rmsWithOut[ivalue] = calROC->GetRMS(outlierROC);
2046 ltmWithOut[ivalue] = calROC->GetLTM(<mrmsValue, ltmFraction, outlierROC);
2047 ltmrmsWithOut[ivalue] = ltmrmsValue;
2051 median[ivalue] = 0.;
2055 ltmrms[ivalue] = 0.;
2056 medianWithOut[ivalue] = 0.;
2057 meanWithOut[ivalue] = 0.;
2058 rmsWithOut[ivalue] = 0.;
2059 ltmWithOut[ivalue] = 0.;
2060 ltmrmsWithOut[ivalue] = 0.;
2065 // fill vectors of variable per pad
2067 TVectorF *posArray = new TVectorF[8];
2068 for (Int_t ivalue = 0; ivalue < 8; ivalue++)
2069 posArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(isector));
2071 Float_t posG[3] = {0};
2072 Float_t posL[3] = {0};
2074 for (UInt_t irow = 0; irow < tpcROCinstance->GetNRows(isector); irow++) {
2075 for (UInt_t ipad = 0; ipad < tpcROCinstance->GetNPads(isector, irow); ipad++) {
2076 tpcROCinstance->GetPositionLocal(isector, irow, ipad, posL);
2077 tpcROCinstance->GetPositionGlobal(isector, irow, ipad, posG);
2078 posArray[0][ichannel] = irow;
2079 posArray[1][ichannel] = ipad;
2080 posArray[2][ichannel] = posL[0];
2081 posArray[3][ichannel] = posL[1];
2082 posArray[4][ichannel] = posG[0];
2083 posArray[5][ichannel] = posG[1];
2084 posArray[6][ichannel] = (Int_t)(ipad - (Double_t)(tpcROCinstance->GetNPads(isector, irow))/2);
2085 posArray[7][ichannel] = ichannel;
2087 // loop over array containing AliTPCCalPads
2088 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
2089 AliTPCCalPad* calPad = (AliTPCCalPad*) array->At(ivalue);
2090 AliTPCCalROC* calROC = calPad->GetCalROC(isector);
2092 (vectorArray[ivalue])[ichannel] = calROC->GetValue(irow, ipad);
2094 (vectorArray[ivalue])[ichannel] = 0;
2100 cstream << "calPads" <<
2101 "sector=" << isector;
2103 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
2104 cstream << "calPads" <<
2105 (Char_t*)((names[ivalue] + "_Median=").Data()) << median[ivalue] <<
2106 (Char_t*)((names[ivalue] + "_Mean=").Data()) << mean[ivalue] <<
2107 (Char_t*)((names[ivalue] + "_RMS=").Data()) << rms[ivalue] <<
2108 (Char_t*)((names[ivalue] + "_LTM=").Data()) << ltm[ivalue] <<
2109 (Char_t*)((names[ivalue] + "_RMS_LTM=").Data()) << ltmrms[ivalue];
2111 cstream << "calPads" <<
2112 (Char_t*)((names[ivalue] + "_Median_OutlierCutted=").Data()) << medianWithOut[ivalue] <<
2113 (Char_t*)((names[ivalue] + "_Mean_OutlierCutted=").Data()) << meanWithOut[ivalue] <<
2114 (Char_t*)((names[ivalue] + "_RMS_OutlierCutted=").Data()) << rmsWithOut[ivalue] <<
2115 (Char_t*)((names[ivalue] + "_LTM_OutlierCutted=").Data()) << ltmWithOut[ivalue] <<
2116 (Char_t*)((names[ivalue] + "_RMS_LTM_OutlierCutted=").Data()) << ltmrmsWithOut[ivalue];
2118 //timestamp and run, if given in title
2119 /* TString title(((AliTPCCalPad*) array->At(ivalue))->GetTitle());
2120 TObjArray *arrtitle=title.Tokenize(",");
2123 TIter next(arrtitle);
2125 while ( (o=next()) ){
2126 TString &entry=((TObjString*)o)->GetString();
2127 entry.Remove(TString::kBoth,' ');
2128 entry.Remove(TString::kBoth,'\t');
2129 if (entry.BeginsWith("Run:")) {
2130 run=entry(4,entry.Length()).Atoi();
2131 } else if (entry.BeginsWith("Time:")) {
2132 time=entry(6,entry.Length()).Atoi();
2139 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
2140 cstream << "calPads" <<
2141 (Char_t*)((names[ivalue] + ".=").Data()) << &vectorArray[ivalue];
2145 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
2147 cstream << "calPads" <<
2148 (Char_t*)((mapNames[ivalue] + ".=").Data()) << &mapIROCArray[ivalue];
2150 cstream << "calPads" <<
2151 (Char_t*)((mapNames[ivalue] + ".=").Data()) << &mapOROCArray[ivalue];
2155 cstream << "calPads" <<
2156 "row.=" << &posArray[0] <<
2157 "pad.=" << &posArray[1] <<
2158 "lx.=" << &posArray[2] <<
2159 "ly.=" << &posArray[3] <<
2160 "gx.=" << &posArray[4] <<
2161 "gy.=" << &posArray[5] <<
2162 "rpad.=" << &posArray[6] <<
2163 "channel.=" << &posArray[7];
2165 cstream << "calPads" <<
2169 delete[] vectorArray;
2177 delete[] mapIROCArray;
2178 delete[] mapOROCArray;
2184 void AliTPCCalibViewer::MakeTree(const char *outPutFileName, const Char_t *inputFileName, AliTPCCalPad *outlierPad, Float_t ltmFraction, const char *mapFileName ){
2186 // Function to create a calibration Tree with all available information.
2187 // See also documentation to MakeTree
2188 // the file "inputFileName" must be in the following format (see also CreateObjectList):
2189 // (each colum separated by tabs, "dependingOnType" can have 2 or 3 colums)
2191 // type path dependingOnType
2194 // dependingOnType = CETmean CEQmean CETrms
2196 // type == "Pulser":
2197 // dependingOnType = PulserTmean PulsterQmean PulserTrms
2199 // type == "Pedestals":
2200 // dependingOnType = Pedestals Noise
2202 // type == "CalPad":
2203 // dependingOnType = NameInFile NameToWriteToFile
2207 CreateObjectList(inputFileName, &objArray);
2208 MakeTree(outPutFileName, &objArray, mapFileName, outlierPad, ltmFraction);
2212 void AliTPCCalibViewer::CreateObjectList(const Char_t *filename, TObjArray *calibObjects){
2214 // Function to create a TObjArray out of a given file
2215 // the file must be in the following format:
2216 // (each colum separated by tabs, "dependingOnType" can have 2 or 3 colums)
2219 // type path dependingOnType
2222 // dependingOnType = CETmean CEQmean CETrms
2224 // type == "Pulser":
2225 // dependingOnType = PulserTmean PulsterQmean PulserTrms
2227 // type == "Pedestals":
2228 // dependingOnType = Pedestals Noise
2230 // type == "CalPad":
2231 // dependingOnType = NameInFile NameToWriteToFile
2235 if ( calibObjects == 0x0 ) return;
2238 if ( !in.is_open() ){
2239 fprintf(stderr,"Error: cannot open list file '%s'", filename);
2243 AliTPCCalPad *calPad=0x0;
2249 TObjArray *arrFileLine = sFile.Tokenize("\n");
2250 TIter nextLine(arrFileLine);
2252 TObjString *sObjLine = 0x0;
2253 while ( (sObjLine = (TObjString*)nextLine()) ){
2254 TString sLine(sObjLine->GetString());
2256 TObjArray *arrCol = sLine.Tokenize("\t");
2257 Int_t nCols = arrCol->GetEntriesFast();
2259 TObjString *sObjType = (TObjString*)(arrCol->At(0));
2260 TObjString *sObjFileName = (TObjString*)(arrCol->At(1));
2261 TObjString *sObjName = 0x0;
2263 if ( !sObjType || !sObjFileName ) continue;
2264 TString sType(sObjType->GetString());
2265 TString sFileName(sObjFileName->GetString());
2266 printf("Type %s, opening %s \n", sType.Data(), sFileName.Data());
2267 TFile *fIn = TFile::Open(sFileName);
2269 fprintf(stderr,"File not found: '%s'", sFileName.Data());
2273 if ( sType == "CE" ){ // next three colums are the names for CETmean, CEQmean and CETrms
2274 AliTPCCalibCE *ce = (AliTPCCalibCE*)fIn->Get("AliTPCCalibCE");
2275 calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadT0());
2276 if (nCols > 2) { // check, if the name is provided
2277 sObjName = (TObjString*)(arrCol->At(2));
2278 calPad->SetNameTitle(sObjName->GetString().Data(), sObjName->GetString().Data());
2280 else calPad->SetNameTitle("CETmean","CETmean");
2281 calibObjects->Add(calPad);
2283 calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadQ());
2284 if (nCols > 3) { // check, if the name is provided
2285 sObjName = (TObjString*)(arrCol->At(3));
2286 calPad->SetNameTitle(sObjName->GetString().Data(), sObjName->GetString().Data());
2288 else calPad->SetNameTitle("CEQmean","CEQmean");
2289 calibObjects->Add(calPad);
2291 calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadRMS());
2292 if (nCols > 4) { // check, if the name is provided
2293 sObjName = (TObjString*)(arrCol->At(4));
2294 calPad->SetNameTitle(sObjName->GetString().Data(), sObjName->GetString().Data());
2296 else calPad->SetNameTitle("CETrms","CETrms");
2297 calibObjects->Add(calPad);
2299 } else if ( sType == "Pulser") {
2300 AliTPCCalibPulser *sig = (AliTPCCalibPulser*)fIn->Get("AliTPCCalibPulser");
2302 calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadT0());
2304 sObjName = (TObjString*)(arrCol->At(2));
2305 calPad->SetNameTitle(sObjName->GetString().Data(), sObjName->GetString().Data());
2307 else calPad->SetNameTitle("PulserTmean","PulserTmean");
2308 calibObjects->Add(calPad);
2310 calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadQ());
2312 sObjName = (TObjString*)(arrCol->At(3));
2313 calPad->SetNameTitle(sObjName->GetString().Data(), sObjName->GetString().Data());
2315 else calPad->SetNameTitle("PulserQmean","PulserQmean");
2316 calibObjects->Add(calPad);
2318 calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadRMS());
2320 sObjName = (TObjString*)(arrCol->At(4));
2321 calPad->SetNameTitle(sObjName->GetString().Data(), sObjName->GetString().Data());
2323 else calPad->SetNameTitle("PulserTrms","PulserTrms");
2324 calibObjects->Add(calPad);
2326 } else if ( sType == "Pedestals") {
2327 AliTPCCalibPedestal *ped = (AliTPCCalibPedestal*)fIn->Get("AliTPCCalibPedestal");
2329 calPad = new AliTPCCalPad((TObjArray*)ped->GetCalPadPedestal());
2331 sObjName = (TObjString*)(arrCol->At(2));
2332 calPad->SetNameTitle(sObjName->GetString().Data(), sObjName->GetString().Data());
2334 else calPad->SetNameTitle("Pedestals","Pedestals");
2335 calibObjects->Add(calPad);
2337 calPad = new AliTPCCalPad((TObjArray*)ped->GetCalPadRMS());
2339 sObjName = (TObjString*)(arrCol->At(3));
2340 calPad->SetNameTitle(sObjName->GetString().Data(), sObjName->GetString().Data());
2342 else calPad->SetNameTitle("Noise","Noise");
2343 calibObjects->Add(calPad);
2345 } else if ( sType == "CalPad") {
2346 if (nCols > 2) sObjName = (TObjString*)(arrCol->At(2));
2348 calPad = new AliTPCCalPad(*(AliTPCCalPad*)fIn->Get(sObjName->GetString().Data()));
2350 sObjName = (TObjString*)(arrCol->At(3));
2351 calPad->SetNameTitle(sObjName->GetString().Data(), sObjName->GetString().Data());
2353 calibObjects->Add(calPad);
2355 fprintf(stderr,"Undefined Type: '%s'",sType.Data());