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 option = option; // to avoid warnings on compiling
205 if (fTree && fTreeMustBeDeleted) {
206 fTree->SetCacheSize(0);
211 delete fListOfObjectsToBeDeleted;
215 const char* AliTPCCalibViewer::AddAbbreviations(const Char_t *c, Bool_t printDrawCommand){
216 // Replace all "<variable>" with "<variable><fAbbreviation>" (Adds forgotten "~")
217 // but take care on the statistical information, like "CEQmean_Mean"
218 // and also take care on correct given variables, like "CEQmean~"
220 // For each variable out of "listOfVariables":
221 // - 'Save' correct items:
222 // - form <replaceString>, take <variable>'s first char, add <removeString>, add rest of <variable>, e.g. "C!#EQmean" (<removeString> = "!#")
223 // - For each statistical information in "listOfNormalizationVariables":
224 // - ReplaceAll <variable><statistical_Information> with <replaceString><statistical_Information>
225 // - ReplaceAll <variable><abbreviation> with <replaceString><abbreviation>, e.g. "CEQmean~" -> "C!#EQmean~"
226 // - ReplaceAll <variable><appendStr> with <replaceString><appendStr>, e.g. "CEQmean.fElements" -> "C!#EQmean.fElements"
228 // - Do actual replacing:
229 // - ReplaceAll <variable> with <variable><fAbbreviation>, e.g. "CEQmean" -> "CEQmean~"
232 // - For each statistical information in "listOfNormalizationVariables":
233 // - ReplaceAll <replaceString><statistical_Information> with <variable><statistical_Information>
234 // - ReplaceAll <replaceString><abbreviation> with <variable><abbreviation>, e.g. "C!#EQmean~" -> "CEQmean~"
235 // - ReplaceAll <replaceString><appendStr> with <variable><appendStr>, e.g. "C!#EQmean.fElements" -> "CEQmean.fElements"
237 // Now all the missing "~" should be added.
240 TString removeString = "!#"; // very unpropable combination of chars
241 TString replaceString = "";
242 TString searchString = "";
243 TString normString = "";
244 TObjArray *listOfVariables = GetListOfVariables();
245 listOfVariables->Add(new TObjString("channel"));
246 listOfVariables->Add(new TObjString("gx"));
247 listOfVariables->Add(new TObjString("gy"));
248 listOfVariables->Add(new TObjString("lx"));
249 listOfVariables->Add(new TObjString("ly"));
250 listOfVariables->Add(new TObjString("pad"));
251 listOfVariables->Add(new TObjString("row"));
252 listOfVariables->Add(new TObjString("rpad"));
253 listOfVariables->Add(new TObjString("sector"));
254 TObjArray *listOfNormalizationVariables = GetListOfNormalizationVariables();
255 Int_t nVariables = listOfVariables->GetEntriesFast();
256 Int_t nNorm = listOfNormalizationVariables->GetEntriesFast();
258 Int_t *varLengths = new Int_t[nVariables];
259 for (Int_t i = 0; i < nVariables; i++) {
260 varLengths[i] = ((TObjString*)listOfVariables->At(i))->String().Length();
262 Int_t *normLengths = new Int_t[nNorm];
263 for (Int_t i = 0; i < nNorm; i++) {
264 normLengths[i] = ((TObjString*)listOfNormalizationVariables->At(i))->String().Length();
265 // printf("normLengths[%i] (%s) = %i \n", i,((TObjString*)listOfNormalizationVariables->At(i))->String().Data(), normLengths[i]);
267 Int_t *varSort = new Int_t[nVariables];
268 TMath::Sort(nVariables, varLengths, varSort, kTRUE);
269 Int_t *normSort = new Int_t[nNorm];
270 TMath::Sort(nNorm, normLengths, normSort, kTRUE);
271 // for (Int_t i = 0; i<nNorm; i++) printf("normLengths: %i\n", normLengths[normSort[i]]);
272 // for (Int_t i = 0; i<nVariables; i++) printf("varLengths: %i\n", varLengths[varSort[i]]);
274 for (Int_t ivar = 0; ivar < nVariables; ivar++) {
275 // ***** save correct tokens *****
276 // first get the next variable:
277 searchString = ((TObjString*)listOfVariables->At(varSort[ivar]))->String();
278 // printf("searchString: %s ++++++++++++++\n", searchString.Data());
279 // form replaceString:
281 for (Int_t i = 0; i < searchString.Length(); i++) {
282 replaceString.Append(searchString[i]);
283 if (i == 0) replaceString.Append(removeString);
285 // go through normalization:
286 // printf("go through normalization\n");
287 for (Int_t inorm = 0; inorm < nNorm; inorm++) {
288 // printf(" inorm=%i, nNorm=%i, normSort[inorm]=%i \n", inorm, nNorm, normSort[inorm]);
289 normString = ((TObjString*)listOfNormalizationVariables->At(normSort[inorm]))->String();
290 // printf(" walking in normalization, i=%i, normString=%s \n", inorm, normString.Data());
291 str.ReplaceAll(searchString + normString, replaceString + normString);
292 // like: str.ReplaceAll("CEQmean_Mean", "C!EQmean_Mean");
294 str.ReplaceAll(searchString + fAbbreviation, replaceString + fAbbreviation);
295 // like: str.ReplaceAll("CEQmean~", "C!EQmean~");
296 str.ReplaceAll(searchString + fAppendString, replaceString + fAppendString);
297 // like: str.ReplaceAll("CEQmean.fElements", "C!EQmean.fElements");
299 // ***** add missing extensions *****
300 str.ReplaceAll(searchString, replaceString + fAbbreviation);
301 // like: str.ReplaceAll("CEQmean", "C!EQmean~");
304 // ***** undo saving *****
305 str.ReplaceAll(removeString, "");
307 if (printDrawCommand) std::cout << "The string looks now like: " << str.Data() << std::endl;
308 delete [] varLengths;
309 delete [] normLengths;
318 //_____________________________________________________________________________
319 Int_t AliTPCCalibViewer::EasyDraw(const char* drawCommand, const char* sector, const char* cuts, const char* drawOptions, Bool_t writeDrawCommand) const {
321 // easy drawing of data, use '~' for abbreviation of '.fElements'
322 // example: EasyDraw("CETmean~-CETmean_mean", "A", "(CETmean~-CETmean_mean)>0")
323 // sector: sector-number - only the specified sector will be drwawn
324 // 'A'/'C' or 'a'/'c' - side A/C will be drawn
325 // 'ALL' - whole TPC will be drawn, projected on one side
326 // cuts: specifies cuts
327 // drawOptions: draw options like 'same'
328 // writeDrawCommand: write the command, that is passed to TTree::Draw
331 TString drawStr(drawCommand);
332 TString sectorStr(sector);
335 //TString drawOptionsStr("profcolz ");
336 Bool_t dangerousToDraw = drawStr.Contains(":") || drawStr.Contains(">>");
337 if (dangerousToDraw) {
338 Warning("EasyDraw", "The draw string must not contain ':' or '>>'. Using only first variable for drawing!");
340 // drawStr.Resize(drawStr.First(">"));
341 drawStr.Resize(drawStr.First(":"));
344 TString drawOptionsStr("");
346 Int_t rndNumber = rnd.Integer(10000);
348 if (drawOptions && strcmp(drawOptions, "") != 0)
349 drawOptionsStr += drawOptions;
351 drawOptionsStr += "profcolz";
353 if (sectorStr == "A") {
354 drawStr += Form(":gy%s:gx%s>>prof", fAppendString.Data(), fAppendString.Data());
355 drawStr += rndNumber;
356 drawStr += "(330,-250,250,330,-250,250)";
357 cutStr += "(sector/18)%2==0 ";
359 else if (sectorStr == "C") {
360 drawStr += Form(":gy%s:gx%s>>prof", fAppendString.Data(), fAppendString.Data());
361 drawStr += rndNumber;
362 drawStr += "(330,-250,250,330,-250,250)";
363 cutStr += "(sector/18)%2==1 ";
365 else if (sectorStr == "ALL") {
366 drawStr += Form(":gy%s:gx%s>>prof", fAppendString.Data(), fAppendString.Data());
367 drawStr += rndNumber;
368 drawStr += "(330,-250,250,330,-250,250)";
370 else if (sectorStr.Contains("S")) {
371 drawStr += Form(":rpad%s:row%s+(sector>35)*63>>prof", fAppendString.Data(), fAppendString.Data());
372 drawStr += rndNumber;
373 drawStr += "(159,0,159,140,-70,70)";
374 TString sec=sectorStr;
376 cutStr += "sector%36=="+sec+" ";
378 else if (sectorStr.IsDigit()) {
379 Int_t isec = sectorStr.Atoi();
380 drawStr += Form(":rpad%s:row%s>>prof", fAppendString.Data(), fAppendString.Data());
381 drawStr += rndNumber;
382 if (isec < 36 && isec >= 0)
383 drawStr += "(63,0,63,108,-54,54)";
384 else if (isec < 72 && isec >= 36)
385 drawStr += "(96,0,96,140,-70,70)";
387 Error("EasyDraw","The TPC contains only sectors between 0 and 71.");
390 cutStr += "(sector==";
395 if (cuts && cuts[0] != 0) {
396 if (cutStr.Length() != 0) cutStr += "&& ";
401 drawStr.ReplaceAll(fAbbreviation, fAppendString);
402 cutStr.ReplaceAll(fAbbreviation, fAppendString);
403 if (writeDrawCommand) std::cout << "fTree->Draw(\"" << drawStr << "\", \"" << cutStr << "\", \"" << drawOptionsStr << "\");" << std::endl;
404 Int_t returnValue = fTree->Draw(drawStr.Data(), cutStr.Data(), drawOptionsStr.Data());
405 TString profName("prof");
406 profName += rndNumber;
407 TObject *obj = gDirectory->Get(profName.Data());
408 if (obj && obj->InheritsFrom("TH1")) FormatHistoLabels((TH1*)obj);
413 Int_t AliTPCCalibViewer::EasyDraw(const char* drawCommand, Int_t sector, const char* cuts, const char* drawOptions, Bool_t writeDrawCommand) const {
415 // easy drawing of data, use '~' for abbreviation of '.fElements'
416 // example: EasyDraw("CETmean~-CETmean_mean", 34, "(CETmean~-CETmean_mean)>0")
417 // sector: sector-number - only the specified sector will be drwawn
418 // cuts: specifies cuts
419 // drawOptions: draw options like 'same'
420 // writeDrawCommand: write the command, that is passed to TTree::Draw
422 if (sector >= 0 && sector < 72) {
424 sprintf(sectorChr, "%i", sector);
425 return EasyDraw(drawCommand, sectorChr, cuts, drawOptions, writeDrawCommand);
427 Error("EasyDraw","The TPC contains only sectors between 0 and 71.");
432 //_____________________________________________________________________________
433 Int_t AliTPCCalibViewer::EasyDraw1D(const char* drawCommand, const char* sector, const char* cuts, const char* drawOptions, Bool_t writeDrawCommand) const {
435 // easy drawing of data, use '~' for abbreviation of '.fElements'
436 // example: EasyDraw("CETmean~-CETmean_mean", "A", "(CETmean~-CETmean_mean)>0")
437 // sector: sector-number - the specified sector will be drwawn
438 // 'A'/'C' or 'a'/'c' - side A/C will be drawn
439 // 'ALL' - whole TPC will be drawn, projected on one side
440 // cuts: specifies cuts
441 // drawOptions: draw options like 'same'
442 // writeDrawCommand: write the command, that is passed to TTree::Draw
445 TString drawStr(drawCommand);
446 TString sectorStr(sector);
447 TString drawOptionsStr(drawOptions);
451 if (sectorStr == "A")
452 cutStr += "(sector/18)%2==0 ";
453 else if (sectorStr == "C")
454 cutStr += "(sector/18)%2==1 ";
455 else if (sectorStr.IsDigit()) {
456 Int_t isec = sectorStr.Atoi();
457 if (isec < 0 || isec > 71) {
458 Error("EasyDraw","The TPC contains only sectors between 0 and 71.");
461 cutStr += "(sector==";
465 else if (sectorStr.Contains("S")) {
466 TString sec=sectorStr;
468 cutStr += "sector%36=="+sec+" ";
471 if (cuts && cuts[0] != 0) {
472 if (cutStr.Length() != 0) cutStr += "&& ";
478 drawStr.ReplaceAll(fAbbreviation, fAppendString);
479 cutStr.ReplaceAll(fAbbreviation, fAppendString);
480 if (writeDrawCommand) std::cout << "fTree->Draw(\"" << drawStr << "\", \"" << cutStr << "\", \"" << drawOptionsStr << "\");" << std::endl;
481 Int_t returnValue = fTree->Draw(drawStr.Data(), cutStr.Data(), drawOptionsStr.Data());
482 if (returnValue == -1) return -1;
484 TObject *obj = (gPad) ? gPad->GetPrimitive("htemp") : 0;
485 if (!obj) obj = (TH1F*)gDirectory->Get("htemp");
486 if (!obj) obj = gPad->GetPrimitive("tempHist");
487 if (!obj) obj = (TH1F*)gDirectory->Get("tempHist");
488 if (!obj) obj = gPad->GetPrimitive("Graph");
489 if (!obj) obj = (TH1F*)gDirectory->Get("Graph");
490 if (obj && obj->InheritsFrom("TH1")) FormatHistoLabels((TH1*)obj);
495 Int_t AliTPCCalibViewer::EasyDraw1D(const char* drawCommand, Int_t sector, const char* cuts, const char* drawOptions, Bool_t writeDrawCommand) const {
497 // easy drawing of data, use '~' for abbreviation of '.fElements'
498 // example: EasyDraw("CETmean~-CETmean_mean", 34, "(CETmean~-CETmean_mean)>0")
499 // sector: sector-number - the specified sector will be drwawn
500 // cuts: specifies cuts
501 // drawOptions: draw options like 'same'
502 // writeDrawCommand: write the command, that is passed to TTree::Draw
505 if (sector >= 0 && sector < 72) {
507 sprintf(sectorChr, "%i", sector);
508 return EasyDraw1D(drawCommand, sectorChr, cuts, drawOptions, writeDrawCommand);
510 Error("EasyDraw","The TPC contains only sectors between 0 and 71.");
515 void AliTPCCalibViewer::FormatHistoLabels(TH1 *histo) const {
517 // formats title and axis labels of histo
518 // removes '.fElements'
521 TString replaceString(fAppendString.Data());
522 TString *str = new TString(histo->GetTitle());
523 str->ReplaceAll(replaceString, "");
524 histo->SetTitle(str->Data());
526 if (histo->GetXaxis()) {
527 str = new TString(histo->GetXaxis()->GetTitle());
528 str->ReplaceAll(replaceString, "");
529 histo->GetXaxis()->SetTitle(str->Data());
532 if (histo->GetYaxis()) {
533 str = new TString(histo->GetYaxis()->GetTitle());
534 str->ReplaceAll(replaceString, "");
535 histo->GetYaxis()->SetTitle(str->Data());
538 if (histo->GetZaxis()) {
539 str = new TString(histo->GetZaxis()->GetTitle());
540 str->ReplaceAll(replaceString, "");
541 histo->GetZaxis()->SetTitle(str->Data());
547 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 {
549 // Easy drawing of data, in principle the same as EasyDraw1D
550 // Difference: A line for the mean / median / LTM is drawn
551 // in 'sigmas' you can specify in which distance to the mean/median/LTM you want to see a line in sigma-units, separated by ';'
552 // 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.
553 // "plotMean", "plotMedian" and "plotLTM": what kind of lines do you want to see?
555 if (sector >= 0 && sector < 72) {
557 sprintf(sectorChr, "%i", sector);
558 return DrawHisto1D(drawCommand, sectorChr, cuts, sigmas, plotMean, plotMedian, plotLTM);
560 Error("DrawHisto1D","The TPC contains only sectors between 0 and 71.");
565 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 {
567 // Easy drawing of data, in principle the same as EasyDraw1D
568 // Difference: A line for the mean / median / LTM is drawn
569 // in 'sigmas' you can specify in which distance to the mean/median/LTM you want to see a line in sigma-units, separated by ';'
570 // 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.
571 // "plotMean", "plotMedian" and "plotLTM": what kind of lines do you want to see?
573 Int_t oldOptStat = gStyle->GetOptStat();
574 gStyle->SetOptStat(0000000);
575 Double_t ltmFraction = 0.8;
577 TObjArray *sigmasTokens = TString(sigmas).Tokenize(";");
578 TVectorF nsigma(sigmasTokens->GetEntriesFast());
579 for (Int_t i = 0; i < sigmasTokens->GetEntriesFast(); i++) {
580 TString str(((TObjString*)sigmasTokens->At(i))->GetString());
581 Double_t sig = (str.IsFloat()) ? str.Atof() : 0;
585 TString drawStr(drawCommand);
586 Bool_t dangerousToDraw = drawStr.Contains(":") || drawStr.Contains(">>");
587 if (dangerousToDraw) {
588 Warning("DrawHisto1D", "The draw string must not contain ':' or '>>'.");
591 drawStr += " >> tempHist";
592 Int_t entries = EasyDraw1D(drawStr.Data(), sector, cuts);
593 TH1F *htemp = (TH1F*)gDirectory->Get("tempHist");
594 // FIXME is this histogram deleted automatically?
595 Double_t *values = fTree->GetV1(); // value is the array containing 'entries' numbers
597 Double_t mean = TMath::Mean(entries, values);
598 Double_t median = TMath::Median(entries, values);
599 Double_t sigma = TMath::RMS(entries, values);
600 Double_t maxY = htemp->GetMaximum();
603 TLegend * legend = new TLegend(.7,.7, .99, .99, "Statistical information");
604 // sprintf(c, "%s, sector: %i", type, sector);
605 //fListOfObjectsToBeDeleted->Add(legend);
609 TLine* line = new TLine(mean, 0, mean, maxY);
610 //fListOfObjectsToBeDeleted->Add(line);
611 line->SetLineColor(kRed);
612 line->SetLineWidth(2);
613 line->SetLineStyle(1);
615 sprintf(c, "Mean: %f", mean);
616 legend->AddEntry(line, c, "l");
618 for (Int_t i = 0; i < nsigma.GetNoElements(); i++) {
619 TLine* linePlusSigma = new TLine(mean + nsigma[i] * sigma, 0, mean + nsigma[i] * sigma, maxY);
620 //fListOfObjectsToBeDeleted->Add(linePlusSigma);
621 linePlusSigma->SetLineColor(kRed);
622 linePlusSigma->SetLineStyle(2 + i);
623 linePlusSigma->Draw();
624 TLine* lineMinusSigma = new TLine(mean - nsigma[i] * sigma, 0, mean - nsigma[i] * sigma, maxY);
625 //fListOfObjectsToBeDeleted->Add(lineMinusSigma);
626 lineMinusSigma->SetLineColor(kRed);
627 lineMinusSigma->SetLineStyle(2 + i);
628 lineMinusSigma->Draw();
629 sprintf(c, "%i #sigma = %f",(Int_t)(nsigma[i]), (Float_t)(nsigma[i] * sigma));
630 legend->AddEntry(lineMinusSigma, c, "l");
635 TLine* line = new TLine(median, 0, median, maxY);
636 //fListOfObjectsToBeDeleted->Add(line);
637 line->SetLineColor(kBlue);
638 line->SetLineWidth(2);
639 line->SetLineStyle(1);
641 sprintf(c, "Median: %f", median);
642 legend->AddEntry(line, c, "l");
644 for (Int_t i = 0; i < nsigma.GetNoElements(); i++) {
645 TLine* linePlusSigma = new TLine(median + nsigma[i] * sigma, 0, median + nsigma[i]*sigma, maxY);
646 //fListOfObjectsToBeDeleted->Add(linePlusSigma);
647 linePlusSigma->SetLineColor(kBlue);
648 linePlusSigma->SetLineStyle(2 + i);
649 linePlusSigma->Draw();
650 TLine* lineMinusSigma = new TLine(median - nsigma[i] * sigma, 0, median - nsigma[i]*sigma, maxY);
651 //fListOfObjectsToBeDeleted->Add(lineMinusSigma);
652 lineMinusSigma->SetLineColor(kBlue);
653 lineMinusSigma->SetLineStyle(2 + i);
654 lineMinusSigma->Draw();
655 sprintf(c, "%i #sigma = %f",(Int_t)(nsigma[i]), (Float_t)(nsigma[i] * sigma));
656 legend->AddEntry(lineMinusSigma, c, "l");
662 Double_t ltm = GetLTM(entries, values, <mRms, ltmFraction);
663 TLine* line = new TLine(ltm, 0, ltm, maxY);
664 //fListOfObjectsToBeDeleted->Add(line);
665 line->SetLineColor(kGreen+2);
666 line->SetLineWidth(2);
667 line->SetLineStyle(1);
669 sprintf(c, "LTM: %f", ltm);
670 legend->AddEntry(line, c, "l");
672 for (Int_t i = 0; i < nsigma.GetNoElements(); i++) {
673 TLine* linePlusSigma = new TLine(ltm + nsigma[i] * ltmRms, 0, ltm + nsigma[i] * ltmRms, maxY);
674 //fListOfObjectsToBeDeleted->Add(linePlusSigma);
675 linePlusSigma->SetLineColor(kGreen+2);
676 linePlusSigma->SetLineStyle(2+i);
677 linePlusSigma->Draw();
679 TLine* lineMinusSigma = new TLine(ltm - nsigma[i] * ltmRms, 0, ltm - nsigma[i] * ltmRms, maxY);
680 //fListOfObjectsToBeDeleted->Add(lineMinusSigma);
681 lineMinusSigma->SetLineColor(kGreen+2);
682 lineMinusSigma->SetLineStyle(2+i);
683 lineMinusSigma->Draw();
684 sprintf(c, "%i #sigma = %f", (Int_t)(nsigma[i]), (Float_t)(nsigma[i] * ltmRms));
685 legend->AddEntry(lineMinusSigma, c, "l");
688 if (!plotMean && !plotMedian && !plotLTM) return -1;
690 gStyle->SetOptStat(oldOptStat);
695 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 {
697 // 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
698 // The data of the distribution Begin_Latex f(x, #mu, #sigma) End_Latex are given in 'array', 'n' specifies the length of the array
699 // '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
700 // 'nbins': number of bins, 'binLow': first bin, 'binUp': last bin
701 // sigmaMax: up to which sigma around the mean/median/LTM the histogram is generated (in units of sigma, Begin_Latex t #sigma End_Latex)
702 // sigmaStep: the binsize of the generated histogram
704 // f(x, #mu, #sigma) #Rightarrow S(t, #mu, #sigma) = #frac{#int_{#mu}^{#mu + t #sigma} f(x, #mu, #sigma) dx + #int_{#mu}^{#mu - t #sigma} f(x, #mu, #sigma) dx }{ #int_{-#infty}^{+#infty} f(x, #mu, #sigma) dx }
708 // Creates a histogram, where you can see, how much of the data are inside sigma-intervals
709 // around the mean/median/LTM
710 // with drawCommand, sector and cuts you specify your input data, see EasyDraw
711 // sigmaMax: up to which sigma around the mean/median/LTM the histogram is generated (in units of sigma)
712 // sigmaStep: the binsize of the generated histogram
713 // plotMean/plotMedian/plotLTM: specifies where to put the center
715 if (sector >= 0 && sector < 72) {
717 sprintf(sectorChr, "%i", sector);
718 return SigmaCut(drawCommand, sectorChr, cuts, sigmaMax, plotMean, plotMedian, plotLTM, pm, sigmas, sigmaStep);
720 Error("SigmaCut","The TPC contains only sectors between 0 and 71.");
725 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 {
727 // Creates a histogram, where you can see, how much of the data are inside sigma-intervals
728 // around the mean/median/LTM
729 // with drawCommand, sector and cuts you specify your input data, see EasyDraw
730 // sigmaMax: up to which sigma around the mean/median/LTM the histogram is generated (in units of sigma)
731 // sigmaStep: the binsize of the generated histogram
732 // plotMean/plotMedian/plotLTM: specifies where to put the center
735 Double_t ltmFraction = 0.8;
737 TString drawStr(drawCommand);
738 Bool_t dangerousToDraw = drawStr.Contains(":") || drawStr.Contains(">>");
739 if (dangerousToDraw) {
740 Warning("SigmaCut", "The draw string must not contain ':' or '>>'.");
743 drawStr += " >> tempHist";
745 Int_t entries = EasyDraw1D(drawStr.Data(), sector, cuts, "goff");
746 TH1F *htemp = (TH1F*)gDirectory->Get("tempHist");
747 // FIXME is this histogram deleted automatically?
748 Double_t *values = fTree->GetV1(); // value is the array containing 'entries' numbers
750 Double_t mean = TMath::Mean(entries, values);
751 Double_t median = TMath::Median(entries, values);
752 Double_t sigma = TMath::RMS(entries, values);
754 TLegend * legend = new TLegend(.7,.7, .99, .99, "Cumulative");
755 //fListOfObjectsToBeDeleted->Add(legend);
756 TH1F *cutHistoMean = 0;
757 TH1F *cutHistoMedian = 0;
758 TH1F *cutHistoLTM = 0;
760 TObjArray *sigmasTokens = TString(sigmas).Tokenize(";");
761 TVectorF nsigma(sigmasTokens->GetEntriesFast());
762 for (Int_t i = 0; i < sigmasTokens->GetEntriesFast(); i++) {
763 TString str(((TObjString*)sigmasTokens->At(i))->GetString());
764 Double_t sig = (str.IsFloat()) ? str.Atof() : 0;
769 cutHistoMean = AliTPCCalibViewer::SigmaCut(htemp, mean, sigma, sigmaMax, sigmaStep, pm);
771 //fListOfObjectsToBeDeleted->Add(cutHistoMean);
772 cutHistoMean->SetLineColor(kRed);
773 legend->AddEntry(cutHistoMean, "Mean", "l");
774 cutHistoMean->SetTitle(Form("%s, cumulative; Multiples of #sigma; Fraction of included data", htemp->GetTitle()));
775 cutHistoMean->Draw();
776 DrawLines(cutHistoMean, nsigma, legend, kRed, pm);
777 } // if (cutHistoMean)
781 cutHistoMedian = AliTPCCalibViewer::SigmaCut(htemp, median, sigma, sigmaMax, sigmaStep, pm);
782 if (cutHistoMedian) {
783 //fListOfObjectsToBeDeleted->Add(cutHistoMedian);
784 cutHistoMedian->SetLineColor(kBlue);
785 legend->AddEntry(cutHistoMedian, "Median", "l");
786 cutHistoMedian->SetTitle(Form("%s, cumulative; Multiples of #sigma; Fraction of included data", htemp->GetTitle()));
787 if (plotMean && cutHistoMean) cutHistoMedian->Draw("same");
788 else cutHistoMedian->Draw();
789 DrawLines(cutHistoMedian, nsigma, legend, kBlue, pm);
790 } // if (cutHistoMedian)
794 Double_t ltm = GetLTM(entries, values, <mRms, ltmFraction);
795 cutHistoLTM = AliTPCCalibViewer::SigmaCut(htemp, ltm, ltmRms, sigmaMax, sigmaStep, pm);
797 //fListOfObjectsToBeDeleted->Add(cutHistoLTM);
798 cutHistoLTM->SetLineColor(kGreen+2);
799 legend->AddEntry(cutHistoLTM, "LTM", "l");
800 cutHistoLTM->SetTitle(Form("%s, cumulative; Multiples of #sigma; Fraction of included data", htemp->GetTitle()));
801 if ((plotMean && cutHistoMean) || (plotMedian && cutHistoMedian)) cutHistoLTM->Draw("same");
802 else cutHistoLTM->Draw();
803 DrawLines(cutHistoLTM, nsigma, legend, kGreen+2, pm);
806 if (!plotMean && !plotMedian && !plotLTM) return -1;
812 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 {
814 // Creates a histogram, where you can see, how much of the data are inside sigma-intervals
815 // around the mean/median/LTM
816 // with drawCommand, sector and cuts you specify your input data, see EasyDraw
817 // sigmaMax: up to which sigma around the mean/median/LTM the histogram is generated (in units of sigma)
818 // sigmaStep: the binsize of the generated histogram
819 // plotMean/plotMedian/plotLTM: specifies where to put the center
822 // Double_t ltmFraction = 0.8; //unused
823 // avoid compiler warnings:
826 sigmaStep = sigmaStep;
828 TString drawStr(drawCommand);
829 drawStr += " >> tempHist";
831 Int_t entries = EasyDraw1D(drawStr.Data(), sector, cuts, "goff");
832 TH1F *htemp = (TH1F*)gDirectory->Get("tempHist");
833 TGraph *cutGraphMean = 0;
834 // TGraph *cutGraphMedian = 0;
835 // TGraph *cutGraphLTM = 0;
836 Double_t *values = fTree->GetV1(); // value is the array containing 'entries' numbers
837 Int_t *index = new Int_t[entries];
838 Float_t *xarray = new Float_t[entries];
839 Float_t *yarray = new Float_t[entries];
840 TMath::Sort(entries, values, index, kFALSE);
842 Double_t mean = TMath::Mean(entries, values);
843 // Double_t median = TMath::Median(entries, values);
844 Double_t sigma = TMath::RMS(entries, values);
846 TLegend * legend = new TLegend(.7,.7, .99, .99, "Cumulative");
847 //fListOfObjectsToBeDeleted->Add(legend);
849 // parse sigmas string
850 TObjArray *sigmasTokens = TString(sigmas).Tokenize(";");
851 TVectorF nsigma(sigmasTokens->GetEntriesFast());
852 for (Int_t i = 0; i < sigmasTokens->GetEntriesFast(); i++) {
853 TString str(((TObjString*)sigmasTokens->At(i))->GetString());
854 Double_t sig = (str.IsFloat()) ? str.Atof() : 0;
859 for (Int_t i = 0; i < entries; i++) {
860 xarray[i] = TMath::Abs(values[index[i]] - mean) / sigma;
861 yarray[i] = float(i) / float(entries);
863 cutGraphMean = new TGraph(entries, xarray, yarray);
865 //fListOfObjectsToBeDeleted->Add(cutGraphMean);
866 cutGraphMean->SetLineColor(kRed);
867 legend->AddEntry(cutGraphMean, "Mean", "l");
868 cutGraphMean->SetTitle(Form("%s, Cumulative; Multiples of #sigma; Fraction of included data", htemp->GetTitle()));
869 cutGraphMean->Draw("alu");
870 DrawLines(cutGraphMean, nsigma, legend, kRed, kTRUE);
875 cutHistoMedian = AliTPCCalibViewer::SigmaCut(htemp, median, sigma, sigmaMax, sigmaStep, pm);
876 if (cutHistoMedian) {
877 fListOfObjectsToBeDeleted->Add(cutHistoMedian);
878 cutHistoMedian->SetLineColor(kBlue);
879 legend->AddEntry(cutHistoMedian, "Median", "l");
880 cutHistoMedian->SetTitle(Form("%s, cumulative; Multiples of #sigma; Fraction of included data", htemp->GetTitle()));
881 if (plotMean && cutHistoMean) cutHistoMedian->Draw("same");
882 else cutHistoMedian->Draw();
883 DrawLines(cutHistoMedian, nsigma, legend, kBlue, pm);
884 } // if (cutHistoMedian)
888 Double_t ltm = GetLTM(entries, values, <mRms, ltmFraction);
889 cutHistoLTM = AliTPCCalibViewer::SigmaCut(htemp, ltm, ltmRms, sigmaMax, sigmaStep, pm);
891 fListOfObjectsToBeDeleted->Add(cutHistoLTM);
892 cutHistoLTM->SetLineColor(kGreen+2);
893 legend->AddEntry(cutHistoLTM, "LTM", "l");
894 cutHistoLTM->SetTitle(Form("%s, cumulative; Multiples of #sigma; Fraction of included data", htemp->GetTitle()));
895 if (plotMean && cutHistoMean || plotMedian && cutHistoMedian) cutHistoLTM->Draw("same");
896 else cutHistoLTM->Draw();
897 DrawLines(cutHistoLTM, nsigma, legend, kGreen+2, pm);
900 if (!plotMean && !plotMedian && !plotLTM) return -1;
906 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 {
908 // 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"
909 // "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
910 // sigmaMax: up to which sigma around the mean/median/LTM you want to integrate
911 // if "igma == 0" and "sigmaMax == 0" the whole histogram is integrated
912 // "sigmaStep": the binsize of the generated histogram, -1 means, that the maximal reasonable stepsize is used
913 // The actual work is done on the array.
915 f(x, #mu, #sigma) #Rightarrow S(t, #mu, #sigma) = #frac{#int_{-#infty}^{#mu + t #sigma} f(x, #mu, #sigma) dx}{ #int_{-#infty}^{+#infty} f(x, #mu, #sigma) dx }
918 if (sector >= 0 && sector < 72) {
920 sprintf(sectorChr, "%i", sector);
921 return Integrate(drawCommand, sectorChr, cuts, sigmaMax, plotMean, plotMedian, plotLTM, sigmas, sigmaStep);
923 Error("Integrate","The TPC contains only sectors between 0 and 71.");
929 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 {
931 // 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"
932 // "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
933 // sigmaMax: up to which sigma around the mean/median/LTM you want to integrate
934 // if "igma == 0" and "sigmaMax == 0" the whole histogram is integrated
935 // "sigmaStep": the binsize of the generated histogram, -1 means, that the maximal reasonable stepsize is used
936 // The actual work is done on the array.
938 f(x, #mu, #sigma) #Rightarrow S(t, #mu, #sigma) = #frac{#int_{-#infty}^{#mu + t #sigma} f(x, #mu, #sigma) dx}{ #int_{-#infty}^{+#infty} f(x, #mu, #sigma) dx }
942 Double_t ltmFraction = 0.8;
944 TString drawStr(drawCommand);
945 drawStr += " >> tempHist";
947 Int_t entries = EasyDraw1D(drawStr.Data(), sector, cuts, "goff");
948 TH1F *htemp = (TH1F*)gDirectory->Get("tempHist");
949 // FIXME is this histogram deleted automatically?
950 Double_t *values = fTree->GetV1(); // value is the array containing 'entries' numbers
952 Double_t mean = TMath::Mean(entries, values);
953 Double_t median = TMath::Median(entries, values);
954 Double_t sigma = TMath::RMS(entries, values);
956 TObjArray *sigmasTokens = TString(sigmas).Tokenize(";");
957 TVectorF nsigma(sigmasTokens->GetEntriesFast());
958 for (Int_t i = 0; i < sigmasTokens->GetEntriesFast(); i++) {
959 TString str(((TObjString*)sigmasTokens->At(i))->GetString());
960 Double_t sig = (str.IsFloat()) ? str.Atof() : 0;
964 TLegend * legend = new TLegend(.7,.7, .99, .99, "Integrated histogram");
965 //fListOfObjectsToBeDeleted->Add(legend);
966 TH1F *integralHistoMean = 0;
967 TH1F *integralHistoMedian = 0;
968 TH1F *integralHistoLTM = 0;
971 integralHistoMean = AliTPCCalibViewer::Integrate(htemp, mean, sigma, sigmaMax, sigmaStep);
972 if (integralHistoMean) {
973 //fListOfObjectsToBeDeleted->Add(integralHistoMean);
974 integralHistoMean->SetLineColor(kRed);
975 legend->AddEntry(integralHistoMean, "Mean", "l");
976 integralHistoMean->SetTitle(Form("%s, integrated; Multiples of #sigma; Fraction of included data", htemp->GetTitle()));
977 integralHistoMean->Draw();
978 DrawLines(integralHistoMean, nsigma, legend, kRed, kTRUE);
982 integralHistoMedian = AliTPCCalibViewer::Integrate(htemp, median, sigma, sigmaMax, sigmaStep);
983 if (integralHistoMedian) {
984 //fListOfObjectsToBeDeleted->Add(integralHistoMedian);
985 integralHistoMedian->SetLineColor(kBlue);
986 legend->AddEntry(integralHistoMedian, "Median", "l");
987 integralHistoMedian->SetTitle(Form("%s, integrated; Multiples of #sigma; Fraction of included data", htemp->GetTitle()));
988 if (plotMean && integralHistoMean) integralHistoMedian->Draw("same");
989 else integralHistoMedian->Draw();
990 DrawLines(integralHistoMedian, nsigma, legend, kBlue, kTRUE);
995 Double_t ltm = GetLTM(entries, values, <mRms, ltmFraction);
996 integralHistoLTM = AliTPCCalibViewer::Integrate(htemp, ltm, ltmRms, sigmaMax, sigmaStep);
997 if (integralHistoLTM) {
998 //fListOfObjectsToBeDeleted->Add(integralHistoLTM);
999 integralHistoLTM->SetLineColor(kGreen+2);
1000 legend->AddEntry(integralHistoLTM, "LTM", "l");
1001 integralHistoLTM->SetTitle(Form("%s, integrated; Multiples of #sigma; Fraction of included data", htemp->GetTitle()));
1002 if ((plotMean && integralHistoMean) || (plotMedian && integralHistoMedian)) integralHistoLTM->Draw("same");
1003 else integralHistoLTM->Draw();
1004 DrawLines(integralHistoLTM, nsigma, legend, kGreen+2, kTRUE);
1007 if (!plotMean && !plotMedian && !plotLTM) return -1;
1013 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 {
1015 // 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"
1016 // "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
1017 // sigmaMax: up to which sigma around the mean/median/LTM you want to integrate
1018 // if "igma == 0" and "sigmaMax == 0" the whole histogram is integrated
1019 // "sigmaStep": the binsize of the generated histogram, -1 means, that the maximal reasonable stepsize is used
1020 // The actual work is done on the array.
1022 f(x, #mu, #sigma) #Rightarrow S(t, #mu, #sigma) = #frac{#int_{-#infty}^{#mu + t #sigma} f(x, #mu, #sigma) dx}{ #int_{-#infty}^{+#infty} f(x, #mu, #sigma) dx }
1026 Double_t ltmFraction = 0.8;
1027 // avoid compiler warnings:
1028 sigmaMax = sigmaMax;
1029 sigmaStep = sigmaStep;
1031 TString drawStr(drawCommand);
1032 Bool_t dangerousToDraw = drawStr.Contains(":") || drawStr.Contains(">>");
1033 if (dangerousToDraw) {
1034 Warning("Integrate", "The draw string must not contain ':' or '>>'.");
1037 drawStr += " >> tempHist";
1039 Int_t entries = EasyDraw1D(drawStr.Data(), sector, cuts, "goff");
1040 TH1F *htemp = (TH1F*)gDirectory->Get("tempHist");
1041 TGraph *integralGraphMean = 0;
1042 TGraph *integralGraphMedian = 0;
1043 TGraph *integralGraphLTM = 0;
1044 Double_t *values = fTree->GetV1(); // value is the array containing 'entries' numbers
1045 Int_t *index = new Int_t[entries];
1046 Float_t *xarray = new Float_t[entries];
1047 Float_t *yarray = new Float_t[entries];
1048 TMath::Sort(entries, values, index, kFALSE);
1050 Double_t mean = TMath::Mean(entries, values);
1051 Double_t median = TMath::Median(entries, values);
1052 Double_t sigma = TMath::RMS(entries, values);
1054 // parse sigmas string
1055 TObjArray *sigmasTokens = TString(sigmas).Tokenize(";");
1056 TVectorF nsigma(sigmasTokens->GetEntriesFast());
1057 for (Int_t i = 0; i < sigmasTokens->GetEntriesFast(); i++) {
1058 TString str(((TObjString*)sigmasTokens->At(i))->GetString());
1059 Double_t sig = (str.IsFloat()) ? str.Atof() : 0;
1063 TLegend * legend = new TLegend(.7,.7, .99, .99, "Integrated histogram");
1064 //fListOfObjectsToBeDeleted->Add(legend);
1067 for (Int_t i = 0; i < entries; i++) {
1068 xarray[i] = (values[index[i]] - mean) / sigma;
1069 yarray[i] = float(i) / float(entries);
1071 integralGraphMean = new TGraph(entries, xarray, yarray);
1072 if (integralGraphMean) {
1073 //fListOfObjectsToBeDeleted->Add(integralGraphMean);
1074 integralGraphMean->SetLineColor(kRed);
1075 legend->AddEntry(integralGraphMean, "Mean", "l");
1076 integralGraphMean->SetTitle(Form("%s, integrated; Multiples of #sigma; Fraction of included data", htemp->GetTitle()));
1077 integralGraphMean->Draw("alu");
1078 DrawLines(integralGraphMean, nsigma, legend, kRed, kTRUE);
1082 for (Int_t i = 0; i < entries; i++) {
1083 xarray[i] = (values[index[i]] - median) / sigma;
1084 yarray[i] = float(i) / float(entries);
1086 integralGraphMedian = new TGraph(entries, xarray, yarray);
1087 if (integralGraphMedian) {
1088 //fListOfObjectsToBeDeleted->Add(integralGraphMedian);
1089 integralGraphMedian->SetLineColor(kBlue);
1090 legend->AddEntry(integralGraphMedian, "Median", "l");
1091 integralGraphMedian->SetTitle(Form("%s, integrated; Multiples of #sigma; Fraction of included data", htemp->GetTitle()));
1092 if (plotMean && integralGraphMean) integralGraphMedian->Draw("samelu");
1093 else integralGraphMedian->Draw("alu");
1094 DrawLines(integralGraphMedian, nsigma, legend, kBlue, kTRUE);
1098 Double_t ltmRms = 0;
1099 Double_t ltm = GetLTM(entries, values, <mRms, ltmFraction);
1100 for (Int_t i = 0; i < entries; i++) {
1101 xarray[i] = (values[index[i]] - ltm) / ltmRms;
1102 yarray[i] = float(i) / float(entries);
1104 integralGraphLTM = new TGraph(entries, xarray, yarray);
1105 if (integralGraphLTM) {
1106 //fListOfObjectsToBeDeleted->Add(integralGraphLTM);
1107 integralGraphLTM->SetLineColor(kGreen+2);
1108 legend->AddEntry(integralGraphLTM, "LTM", "l");
1109 integralGraphLTM->SetTitle(Form("%s, integrated; Multiples of #sigma; Fraction of included data", htemp->GetTitle()));
1110 if ((plotMean && integralGraphMean) || (plotMedian && integralGraphMedian)) integralGraphLTM->Draw("samelu");
1111 else integralGraphLTM->Draw("alu");
1112 DrawLines(integralGraphLTM, nsigma, legend, kGreen+2, kTRUE);
1115 if (!plotMean && !plotMedian && !plotLTM) return -1;
1121 void AliTPCCalibViewer::DrawLines(TH1F *histogram, TVectorF nsigma, TLegend *legend, Int_t color, Bool_t pm) const {
1123 // Private function for SigmaCut(...) and Integrate(...)
1124 // Draws lines into the given histogram, specified by "nsigma", the lines are addeed to the legend
1127 // start to draw the lines, loop over requested sigmas
1129 for (Int_t i = 0; i < nsigma.GetNoElements(); i++) {
1131 Int_t bin = histogram->GetXaxis()->FindBin(nsigma[i]);
1132 TLine* lineUp = new TLine(nsigma[i], 0, nsigma[i], histogram->GetBinContent(bin));
1133 //fListOfObjectsToBeDeleted->Add(lineUp);
1134 lineUp->SetLineColor(color);
1135 lineUp->SetLineStyle(2 + i);
1137 TLine* lineLeft = new TLine(nsigma[i], histogram->GetBinContent(bin), 0, histogram->GetBinContent(bin));
1138 //fListOfObjectsToBeDeleted->Add(lineLeft);
1139 lineLeft->SetLineColor(color);
1140 lineLeft->SetLineStyle(2 + i);
1142 sprintf(c, "Fraction(%f #sigma) = %f",nsigma[i], histogram->GetBinContent(bin));
1143 legend->AddEntry(lineLeft, c, "l");
1146 Int_t bin = histogram->GetXaxis()->FindBin(nsigma[i]);
1147 TLine* lineUp1 = new TLine(nsigma[i], 0, nsigma[i], histogram->GetBinContent(bin));
1148 //fListOfObjectsToBeDeleted->Add(lineUp1);
1149 lineUp1->SetLineColor(color);
1150 lineUp1->SetLineStyle(2 + i);
1152 TLine* lineLeft1 = new TLine(nsigma[i], histogram->GetBinContent(bin), histogram->GetBinLowEdge(0)+histogram->GetBinWidth(0), histogram->GetBinContent(bin));
1153 //fListOfObjectsToBeDeleted->Add(lineLeft1);
1154 lineLeft1->SetLineColor(color);
1155 lineLeft1->SetLineStyle(2 + i);
1157 sprintf(c, "Fraction(+%f #sigma) = %f",nsigma[i], histogram->GetBinContent(bin));
1158 legend->AddEntry(lineLeft1, c, "l");
1159 bin = histogram->GetXaxis()->FindBin(-nsigma[i]);
1160 TLine* lineUp2 = new TLine(-nsigma[i], 0, -nsigma[i], histogram->GetBinContent(bin));
1161 //fListOfObjectsToBeDeleted->Add(lineUp2);
1162 lineUp2->SetLineColor(color);
1163 lineUp2->SetLineStyle(2 + i);
1165 TLine* lineLeft2 = new TLine(-nsigma[i], histogram->GetBinContent(bin), histogram->GetBinLowEdge(0)+histogram->GetBinWidth(0), histogram->GetBinContent(bin));
1166 //fListOfObjectsToBeDeleted->Add(lineLeft2);
1167 lineLeft2->SetLineColor(color);
1168 lineLeft2->SetLineStyle(2 + i);
1170 sprintf(c, "Fraction(-%f #sigma) = %f",nsigma[i], histogram->GetBinContent(bin));
1171 legend->AddEntry(lineLeft2, c, "l");
1173 } // for (Int_t i = 0; i < nsigma.GetNoElements(); i++)
1177 void AliTPCCalibViewer::DrawLines(TGraph *graph, TVectorF nsigma, TLegend *legend, Int_t color, Bool_t pm) const {
1179 // Private function for SigmaCut(...) and Integrate(...)
1180 // Draws lines into the given histogram, specified by "nsigma", the lines are addeed to the legend
1183 // start to draw the lines, loop over requested sigmas
1185 for (Int_t i = 0; i < nsigma.GetNoElements(); i++) {
1187 TLine* lineUp = new TLine(nsigma[i], 0, nsigma[i], graph->Eval(nsigma[i]));
1188 //fListOfObjectsToBeDeleted->Add(lineUp);
1189 lineUp->SetLineColor(color);
1190 lineUp->SetLineStyle(2 + i);
1192 TLine* lineLeft = new TLine(nsigma[i], graph->Eval(nsigma[i]), 0, graph->Eval(nsigma[i]));
1193 //fListOfObjectsToBeDeleted->Add(lineLeft);
1194 lineLeft->SetLineColor(color);
1195 lineLeft->SetLineStyle(2 + i);
1197 sprintf(c, "Fraction(%f #sigma) = %f",nsigma[i], graph->Eval(nsigma[i]));
1198 legend->AddEntry(lineLeft, c, "l");
1201 TLine* lineUp1 = new TLine(nsigma[i], 0, nsigma[i], graph->Eval(nsigma[i]));
1202 //fListOfObjectsToBeDeleted->Add(lineUp1);
1203 lineUp1->SetLineColor(color);
1204 lineUp1->SetLineStyle(2 + i);
1206 TLine* lineLeft1 = new TLine(nsigma[i], graph->Eval(nsigma[i]), graph->GetHistogram()->GetXaxis()->GetBinLowEdge(0), graph->Eval(nsigma[i]));
1207 //fListOfObjectsToBeDeleted->Add(lineLeft1);
1208 lineLeft1->SetLineColor(color);
1209 lineLeft1->SetLineStyle(2 + i);
1211 sprintf(c, "Fraction(+%f #sigma) = %f",nsigma[i], graph->Eval(nsigma[i]));
1212 legend->AddEntry(lineLeft1, c, "l");
1213 TLine* lineUp2 = new TLine(-nsigma[i], 0, -nsigma[i], graph->Eval(-nsigma[i]));
1214 //fListOfObjectsToBeDeleted->Add(lineUp2);
1215 lineUp2->SetLineColor(color);
1216 lineUp2->SetLineStyle(2 + i);
1218 TLine* lineLeft2 = new TLine(-nsigma[i], graph->Eval(-nsigma[i]), graph->GetHistogram()->GetXaxis()->GetBinLowEdge(0), graph->Eval(-nsigma[i]));
1219 //fListOfObjectsToBeDeleted->Add(lineLeft2);
1220 lineLeft2->SetLineColor(color);
1221 lineLeft2->SetLineStyle(2 + i);
1223 sprintf(c, "Fraction(-%f #sigma) = %f",nsigma[i], graph->Eval(-nsigma[i]));
1224 legend->AddEntry(lineLeft2, c, "l");
1226 } // for (Int_t i = 0; i < nsigma.GetNoElements(); i++)
1238 Int_t AliTPCCalibViewer::GetBin(Float_t value, Int_t nbins, Double_t binLow, Double_t binUp){
1239 // Returns the 'bin' for 'value'
1240 // The interval between 'binLow' and 'binUp' is divided into 'nbins' equidistant bins
1241 // avoid index out of bounds error: 'if (bin < binLow) bin = binLow' and vice versa
1243 GetBin(value) = #frac{nbins - 1}{binUp - binLow} #upoint (value - binLow) +1
1247 Int_t bin = TMath::Nint( (Float_t)(value - binLow) / (Float_t)(binUp - binLow) * (nbins-1) ) + 1;
1248 // avoid index out of bounds:
1249 if (value < binLow) bin = 0;
1250 if (value > binUp) bin = nbins + 1;
1256 Double_t AliTPCCalibViewer::GetLTM(Int_t n, const Double_t *const array, Double_t *const sigma, Double_t fraction){
1258 // returns the LTM and sigma
1260 Double_t *ddata = new Double_t[n];
1261 Double_t mean = 0, lsigma = 0;
1263 for (UInt_t i = 0; i < (UInt_t)n; i++) {
1264 ddata[nPoints]= array[nPoints];
1267 Int_t hh = TMath::Min(TMath::Nint(fraction * nPoints), Int_t(n));
1268 AliMathBase::EvaluateUni(nPoints, ddata, mean, lsigma, hh);
1269 if (sigma) *sigma = lsigma;
1275 TH1F* AliTPCCalibViewer::SigmaCut(TH1F *const histogram, Float_t mean, Float_t sigma, Float_t sigmaMax, Float_t sigmaStep, Bool_t pm) {
1277 // 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
1278 // The data of the distribution Begin_Latex f(x, #mu, #sigma) End_Latex are given in 'histogram'
1279 // '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
1280 // sigmaMax: up to which sigma around the mean/median/LTM the histogram is generated (in units of sigma, Begin_Latex t #sigma End_Latex)
1281 // sigmaStep: the binsize of the generated histogram, -1 means, that the maximal reasonable stepsize is used
1282 // pm: Decide weather Begin_Latex t > 0 End_Latex (first case) or Begin_Latex t End_Latex arbitrary (secound case)
1283 // The actual work is done on the array.
1285 f(x, #mu, #sigma) #Rightarrow S(t, #mu, #sigma) = #frac{#int_{#mu}^{#mu + t #sigma} f(x, #mu, #sigma) dx + #int_{#mu}^{#mu - t #sigma} f(x, #mu, #sigma) dx }{ #int_{-#infty}^{+#infty} f(x, #mu, #sigma) dx } , for t > 0
1287 f(x, #mu, #sigma) #Rightarrow S(t, #mu, #sigma) = #frac{#int_{#mu}^{#mu + t #sigma} f(x, #mu, #sigma) dx}{ #int_{-#infty}^{+#infty} f(x, #mu, #sigma) dx }
1292 Float_t sigma = 1.5;
1293 Float_t sigmaMax = 4;
1294 gROOT->SetStyle("Plain");
1295 TH1F *distribution = new TH1F("Distribution1", "Distribution f(x, #mu, #sigma)", 1000,-5,5);
1297 for (Int_t i = 0; i <50000;i++) distribution->Fill(rand.Gaus(mean, sigma));
1298 Float_t *ar = distribution->GetArray();
1300 TCanvas* macro_example_canvas = new TCanvas("macro_example_canvas_SigmaCut", "", 350, 350);
1301 macro_example_canvas->Divide(0,3);
1302 TVirtualPad *pad1 = macro_example_canvas->cd(1);
1305 distribution->Draw();
1306 TVirtualPad *pad2 = macro_example_canvas->cd(2);
1310 TH1F *shist = AliTPCCalibViewer::SigmaCut(distribution, mean, sigma, sigmaMax);
1311 shist->SetNameTitle("Cumulative","Cumulative S(t, #mu, #sigma)");
1313 TVirtualPad *pad3 = macro_example_canvas->cd(3);
1316 TH1F *shistPM = AliTPCCalibViewer::SigmaCut(distribution, mean, sigma, sigmaMax, -1, kTRUE);
1318 return macro_example_canvas;
1323 Float_t *array = histogram->GetArray();
1324 Int_t nbins = histogram->GetXaxis()->GetNbins();
1325 Float_t binLow = histogram->GetXaxis()->GetXmin();
1326 Float_t binUp = histogram->GetXaxis()->GetXmax();
1327 return AliTPCCalibViewer::SigmaCut(nbins, array, mean, sigma, nbins, binLow, binUp, sigmaMax, sigmaStep, pm);
1331 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){
1333 // 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
1334 // The data of the distribution Begin_Latex f(x, #mu, #sigma) End_Latex are given in 'array', 'n' specifies the length of the array
1335 // '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
1336 // 'nbins': number of bins, 'binLow': first bin, 'binUp': last bin
1337 // sigmaMax: up to which sigma around the mean/median/LTM the histogram is generated (in units of sigma, Begin_Latex t #sigma End_Latex)
1338 // sigmaStep: the binsize of the generated histogram
1339 // Here the actual work is done.
1341 if (sigma == 0) return 0;
1342 Float_t binWidth = (binUp-binLow)/(nbins - 1);
1343 if (sigmaStep <= 0) sigmaStep = binWidth;
1344 Int_t kbins = (Int_t)(sigmaMax * sigma / sigmaStep) + 1; // + 1 due to overflow bin in histograms
1345 if (pm) kbins = 2 * (Int_t)(sigmaMax * sigma / sigmaStep) + 1;
1346 Float_t kbinLow = !pm ? 0 : -sigmaMax;
1347 Float_t kbinUp = sigmaMax;
1348 TH1F *hist = new TH1F("sigmaCutHisto","Cumulative; Multiples of #sigma; Fraction of included data", kbins, kbinLow, kbinUp);
1349 hist->SetDirectory(0);
1352 // calculate normalization
1353 Double_t normalization = 0;
1354 for (Int_t i = 0; i <= n; i++) {
1355 normalization += array[i];
1358 // given units: units from given histogram
1359 // sigma units: in units of sigma
1360 // iDelta: integrate in interval (mean +- iDelta), given units
1361 // x: ofset from mean for integration, given units
1364 // printf("nbins: %i, binLow: %f, binUp: %f \n", nbins, binLow, binUp);
1366 for (Float_t iDelta = 0; iDelta <= sigmaMax * sigma; iDelta += sigmaStep) {
1368 Double_t valueP = array[GetBin(mean, nbins, binLow, binUp)];
1369 Double_t valueM = array[GetBin(mean-binWidth, nbins, binLow, binUp)];
1370 // add bin of mean value only once to the histogram
1371 // printf("++ adding bins: ");
1372 for (Float_t x = binWidth; x <= iDelta; x += binWidth) {
1373 valueP += (mean + x <= binUp) ? array[GetBin(mean + x, nbins, binLow, binUp)] : 0;
1374 valueM += (mean-binWidth - x >= binLow) ? array[GetBin(mean-binWidth - x, nbins, binLow, binUp)] : 0;
1375 // printf("%i, ", GetBin(mean + x, nbins, binLow, binUp));
1378 if (valueP / normalization > 100) printf("+++ Error, value to big: %f, normalization with %f will fail +++ \n", valueP, normalization);
1379 if (valueP / normalization > 100) return hist;
1380 if (valueM / normalization > 100) printf("+++ Error, value to big: %f, normalization with %f will fail +++ \n", valueM, normalization);
1381 if (valueM / normalization > 100) return hist;
1382 valueP = (valueP / normalization);
1383 valueM = (valueM / normalization);
1385 Int_t bin = GetBin(iDelta/sigma, kbins, kbinLow, kbinUp);
1386 hist->SetBinContent(bin, valueP);
1387 bin = GetBin(-iDelta/sigma, kbins, kbinLow, kbinUp);
1388 hist->SetBinContent(bin, valueM);
1391 Int_t bin = GetBin(iDelta/sigma, kbins, kbinLow, kbinUp);
1392 hist->SetBinContent(bin, valueP + valueM);
1393 // printf(" first integration bin: %i, last integration bin in + direction: %i \n", GetBin(mean+binWidth, nbins, binLow, binUp), GetBin(iDelta, nbins, binLow, binUp));
1394 // printf(" first integration bin: %i, last integration bin in - direction: %i \n", GetBin(mean+binWidth, nbins, binLow, binUp), GetBin(-iDelta, nbins, binLow, binUp));
1395 // printf(" value: %f, normalization: %f, iDelta: %f, Bin: %i \n", valueP+valueM, normalization, iDelta, bin);
1398 //hist->SetMaximum(0.7);
1399 if (!pm) hist->SetMaximum(1.2);
1404 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){
1406 // SigmaCut for variable binsize
1407 // NOT YET IMPLEMENTED !!!
1409 printf("SigmaCut with variable binsize, Not yet implemented\n");
1410 // avoid compiler warnings:
1423 TH1F* AliTPCCalibViewer::Integrate(TH1F *const histogram, Float_t mean, Float_t sigma, Float_t sigmaMax, Float_t sigmaStep){
1425 // 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"
1426 // "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
1427 // sigmaMax: up to which sigma around the mean/median/LTM you want to integrate
1428 // if "igma == 0" and "sigmaMax == 0" the whole histogram is integrated
1429 // "sigmaStep": the binsize of the generated histogram, -1 means, that the maximal reasonable stepsize is used
1430 // The actual work is done on the array.
1432 f(x, #mu, #sigma) #Rightarrow S(t, #mu, #sigma) = #frac{#int_{-#infty}^{#mu + t #sigma} f(x, #mu, #sigma) dx}{ #int_{-#infty}^{+#infty} f(x, #mu, #sigma) dx }
1437 Float_t sigma = 1.5;
1438 Float_t sigmaMax = 4;
1439 gROOT->SetStyle("Plain");
1440 TH1F *distribution = new TH1F("Distribution2", "Distribution f(x, #mu, #sigma)", 1000,-5,5);
1442 for (Int_t i = 0; i <50000;i++) distribution->Fill(rand.Gaus(mean, sigma));
1443 Float_t *ar = distribution->GetArray();
1445 TCanvas* macro_example_canvas = new TCanvas("macro_example_canvas_Integrate", "", 350, 350);
1446 macro_example_canvas->Divide(0,2);
1447 TVirtualPad *pad1 = macro_example_canvas->cd(1);
1450 distribution->Draw();
1451 TVirtualPad *pad2 = macro_example_canvas->cd(2);
1454 TH1F *shist = AliTPCCalibViewer::Integrate(distribution, mean, sigma, sigmaMax);
1455 shist->SetNameTitle("Cumulative","Cumulative S(t, #mu, #sigma)");
1458 return macro_example_canvas_Integrate;
1464 Float_t *array = histogram->GetArray();
1465 Int_t nbins = histogram->GetXaxis()->GetNbins();
1466 Float_t binLow = histogram->GetXaxis()->GetXmin();
1467 Float_t binUp = histogram->GetXaxis()->GetXmax();
1468 return AliTPCCalibViewer::Integrate(nbins, array, nbins, binLow, binUp, mean, sigma, sigmaMax, sigmaStep);
1472 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){
1473 // 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"
1474 // "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
1475 // sigmaMax: up to which sigma around the mean/median/LTM you want to integrate
1476 // if "igma == 0" and "sigmaMax == 0" the whole histogram is integrated
1477 // "sigmaStep": the binsize of the generated histogram, -1 means, that the maximal reasonable stepsize is used
1478 // Here the actual work is done.
1480 Bool_t givenUnits = kTRUE;
1481 if (sigma != 0 && sigmaMax != 0) givenUnits = kFALSE;
1484 sigmaMax = (binUp - binLow) / 2.;
1487 Float_t binWidth = (binUp-binLow)/(nbins - 1);
1488 if (sigmaStep <= 0) sigmaStep = binWidth;
1489 Int_t kbins = (Int_t)(sigmaMax * sigma / sigmaStep) + 1; // + 1 due to overflow bin in histograms
1490 Float_t kbinLow = givenUnits ? binLow : -sigmaMax;
1491 Float_t kbinUp = givenUnits ? binUp : sigmaMax;
1493 if (givenUnits) hist = new TH1F("integratedHisto","Integrated Histogram; Given x; Fraction of included data", kbins, kbinLow, kbinUp);
1494 if (!givenUnits) hist = new TH1F("integratedHisto","Integrated Histogram; Multiples of #sigma; Fraction of included data", kbins, kbinLow, kbinUp);
1495 hist->SetDirectory(0);
1498 // calculate normalization
1499 // printf("calculating normalization, integrating from bin 1 to %i \n", n);
1500 Double_t normalization = 0;
1501 for (Int_t i = 1; i <= n; i++) {
1502 normalization += array[i];
1504 // printf("normalization: %f \n", normalization);
1506 // given units: units from given histogram
1507 // sigma units: in units of sigma
1508 // iDelta: integrate in interval (mean +- iDelta), given units
1509 // x: ofset from mean for integration, given units
1513 for (Float_t iDelta = mean - sigmaMax * sigma; iDelta <= mean + sigmaMax * sigma; iDelta += sigmaStep) {
1516 for (Float_t x = mean - sigmaMax * sigma; x <= iDelta; x += binWidth) {
1517 value += (x <= binUp && x >= binLow) ? array[GetBin(x, nbins, binLow, binUp)] : 0;
1519 if (value / normalization > 100) printf("+++ Error, value to big: %f, normalization with %f will fail +++ \n", value, normalization);
1520 if (value / normalization > 100) return hist;
1521 Int_t bin = GetBin(iDelta/sigma, kbins, kbinLow, kbinUp);
1522 // printf("first integration bin: %i, last integration bin: %i \n", GetBin(mean - sigmaMax * sigma, nbins, binLow, binUp), GetBin(iDelta, nbins, binLow, binUp));
1523 // printf("value: %f, normalization: %f, normalized value: %f, iDelta: %f, Bin: %i \n", value, normalization, value/normalization, iDelta, bin);
1524 value = (value / normalization);
1525 hist->SetBinContent(bin, value);
1534 ////////////////////////
1535 // end of Array tools //
1536 ////////////////////////
1540 //_____________________________________________________________________________
1541 AliTPCCalPad* AliTPCCalibViewer::GetCalPadOld(const char* desiredData, const char* cuts, const char* calPadName) const {
1543 // creates a AliTPCCalPad out of the 'desiredData'
1544 // the functionality of EasyDraw1D is used
1545 // calPadName specifies the name of the created AliTPCCalPad
1546 // - this takes a while -
1548 TString drawStr(desiredData);
1549 drawStr.Append(":channel");
1550 drawStr.Append(fAbbreviation);
1551 AliTPCCalPad * createdCalPad = new AliTPCCalPad(calPadName, calPadName);
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 const Double_t *pchannel = fTree->GetV2();
1558 const Double_t *pvalue = fTree->GetV1();
1559 for (Int_t i = 0; i < entries; i++)
1560 roc->SetValue((UInt_t)(pchannel[i]), (Float_t)(pvalue[i]));
1562 return createdCalPad;
1566 //_____________________________________________________________________________
1567 AliTPCCalPad* AliTPCCalibViewer::GetCalPad(const char* desiredData, const char* cuts, const char* calPadName) const {
1569 // creates a AliTPCCalPad out of the 'desiredData'
1570 // the functionality of EasyDraw1D is used
1571 // calPadName specifies the name of the created AliTPCCalPad
1572 // - this takes a while -
1574 TString drawStr(desiredData);
1575 drawStr.Append(":channel.fElements:sector");
1576 AliTPCCalPad * createdCalPad = new AliTPCCalPad(calPadName, calPadName);
1578 Int_t entries = fTree->Draw(drawStr, cuts,"goff");
1579 const Double_t *pvalue = fTree->GetV1();
1580 const Double_t *pchannel = fTree->GetV2();
1581 const Double_t *psector = fTree->GetV3();
1583 for (Int_t ientry=0; ientry<entries; ientry++){
1584 Int_t sector= TMath::Nint(psector[ientry]);
1585 AliTPCCalROC * roc = createdCalPad->GetCalROC(sector);
1586 if (roc) roc->SetValue((UInt_t)(pchannel[ientry]), (Float_t)(pvalue[ientry]));
1589 // for (Int_t sec = 0; sec < 72; sec++) {
1590 // AliTPCCalROC * roc = createdCalPad->GetCalROC(sec);
1591 // entries = EasyDraw1D(drawStr.Data(), (Int_t)sec, cuts, "goff");
1592 // if (entries == -1) return 0;
1593 // for (Int_t i = 0; i < entries; i++)
1594 // roc->SetValue((UInt_t)(pchannel[i]), (Float_t)(pvalue[i]));
1596 return createdCalPad;
1599 //_____________________________________________________________________________
1600 AliTPCCalROC* AliTPCCalibViewer::GetCalROC(const char* desiredData, UInt_t sector, const char* cuts) const {
1602 // creates a AliTPCCalROC out of the desiredData
1603 // the functionality of EasyDraw1D is used
1604 // sector specifies the sector of the created AliTPCCalROC
1606 TString drawStr(desiredData);
1607 drawStr.Append(":channel");
1608 drawStr.Append(fAbbreviation);
1609 Int_t entries = EasyDraw1D(drawStr.Data(), (Int_t)sector, cuts, "goff");
1610 if (entries == -1) return 0;
1611 AliTPCCalROC * createdROC = new AliTPCCalROC(sector);
1612 for (Int_t i = 0; i < entries; i++)
1613 createdROC->SetValue((UInt_t)(fTree->GetV2()[i]), fTree->GetV1()[i]);
1618 TObjArray* AliTPCCalibViewer::GetListOfVariables(Bool_t printList) {
1620 // scan the tree - produces a list of available variables in the tree
1621 // printList: print the list to the screen, after the scan is done
1623 TObjArray* arr = new TObjArray();
1624 TObjString* str = 0;
1625 if (!fTree) return 0;
1626 Int_t nentries = fTree->GetListOfBranches()->GetEntries();
1627 for (Int_t i = 0; i < nentries; i++) {
1628 str = new TObjString(fTree->GetListOfBranches()->At(i)->GetName());
1629 str->String().ReplaceAll("_Median", "");
1630 str->String().ReplaceAll("_Mean", "");
1631 str->String().ReplaceAll("_RMS", "");
1632 str->String().ReplaceAll("_LTM", "");
1633 str->String().ReplaceAll("_OutlierCutted", "");
1634 str->String().ReplaceAll(".", "");
1635 if (!arr->FindObject(str) &&
1636 !(str->String() == "channel" || str->String() == "gx" || str->String() == "gy" ||
1637 str->String() == "lx" || str->String() == "ly" || str->String() == "pad" ||
1638 str->String() == "row" || str->String() == "rpad" || str->String() == "sector" ))
1642 // loop over all friends (if there are some) and add them to the list
1643 if (fTree->GetListOfFriends()) {
1644 for (Int_t ifriend = 0; ifriend < fTree->GetListOfFriends()->GetEntries(); ifriend++){
1645 // printf("iterating through friendlist, currently at %i\n", ifriend);
1646 // printf("working with %s\n", fTree->GetListOfFriends()->At(ifriend)->ClassName());
1647 if (TString(fTree->GetListOfFriends()->At(ifriend)->ClassName()) != "TFriendElement") continue; // no friendElement found
1648 TFriendElement *friendElement = (TFriendElement*)fTree->GetListOfFriends()->At(ifriend);
1649 if (friendElement->GetTree() == 0) continue; // no tree found in friendElement
1650 // printf("friend found \n");
1651 for (Int_t i = 0; i < friendElement->GetTree()->GetListOfBranches()->GetEntries(); i++) {
1652 // printf("iterating through friendelement entries, currently at %i\n", i);
1653 str = new TObjString(friendElement->GetTree()->GetListOfBranches()->At(i)->GetName());
1654 str->String().ReplaceAll("_Median", "");
1655 str->String().ReplaceAll("_Mean", "");
1656 str->String().ReplaceAll("_RMS", "");
1657 str->String().ReplaceAll("_LTM", "");
1658 str->String().ReplaceAll("_OutlierCutted", "");
1659 str->String().ReplaceAll(".", "");
1660 if (!(str->String() == "channel" || str->String() == "gx" || str->String() == "gy" ||
1661 str->String() == "lx" || str->String() == "ly" || str->String() == "pad" ||
1662 str->String() == "row" || str->String() == "rpad" || str->String() == "sector" )){
1663 // insert "<friendName>." at the beginning: (<friendName> is per default "R")
1664 str->String().Insert(0, ".");
1665 str->String().Insert(0, friendElement->GetName());
1666 if (!arr->FindObject(str)) arr->Add(str);
1667 // printf("added string %s \n", str->String().Data());
1671 } // if (fTree->GetListOfFriends())
1674 // ((TFriendElement*)gui->GetViewer()->GetTree()->GetListOfFriends()->At(0))->GetTree()->GetListOfBranches()->At(0)->GetName()
1675 // ((TFriendElement*)gui->GetViewer()->GetTree()->GetListOfFriends()->At(0))->GetTree()->GetListOfBranches()
1679 TIterator* iter = arr->MakeIterator();
1681 TObjString* currentStr = 0;
1682 while ( (currentStr = (TObjString*)(iter->Next())) ) {
1683 std::cout << currentStr->GetString().Data() << std::endl;
1691 TObjArray* AliTPCCalibViewer::GetListOfNormalizationVariables(Bool_t printList) const{
1693 // produces a list of available variables for normalization in the tree
1694 // printList: print the list to the screen, after the scan is done
1696 TObjArray* arr = new TObjArray();
1697 arr->Add(new TObjString("_Mean"));
1698 arr->Add(new TObjString("_Mean_OutlierCutted"));
1699 arr->Add(new TObjString("_Median"));
1700 arr->Add(new TObjString("_Median_OutlierCutted"));
1701 arr->Add(new TObjString("_LTM"));
1702 arr->Add(new TObjString("_LTM_OutlierCutted"));
1703 arr->Add(new TObjString(Form("LFitIntern_4_8%s", fAppendString.Data())));
1704 arr->Add(new TObjString(Form("GFitIntern_Lin%s", fAppendString.Data())));
1705 arr->Add(new TObjString(Form("GFitIntern_Par%s", fAppendString.Data())));
1706 arr->Add(new TObjString("FitLinLocal"));
1707 arr->Add(new TObjString("FitLinGlobal"));
1708 arr->Add(new TObjString("FitParLocal"));
1709 arr->Add(new TObjString("FitParGlobal"));
1712 TIterator* iter = arr->MakeIterator();
1714 TObjString* currentStr = 0;
1715 while ((currentStr = (TObjString*)(iter->Next()))) {
1716 std::cout << currentStr->GetString().Data() << std::endl;
1724 TFriendElement* AliTPCCalibViewer::AddReferenceTree(const char* filename, const char* treename, const char* refname){
1726 // add a reference tree to the current tree
1727 // by default the treename is 'calPads' and the reference treename is 'R'
1729 TFile *file = new TFile(filename);
1730 fListOfObjectsToBeDeleted->Add(file);
1731 TTree * tree = (TTree*)file->Get(treename);
1732 return AddFriend(tree, refname);
1736 TObjArray* AliTPCCalibViewer::GetArrayOfCalPads(){
1738 // Returns a TObjArray with all AliTPCCalPads that are stored in the tree
1739 // - this takes a while -
1741 TObjArray *listOfCalPads = GetListOfVariables();
1742 TObjArray *calPadsArray = new TObjArray();
1743 Int_t numberOfCalPads = listOfCalPads->GetEntries();
1744 for (Int_t i = 0; i < numberOfCalPads; i++) {
1745 std::cout << "Creating calPad " << (i+1) << " of " << numberOfCalPads << "\r" << std::flush;
1746 char* calPadName = (char*)((TObjString*)(listOfCalPads->At(i)))->GetString().Data();
1747 TString drawCommand = ((TObjString*)(listOfCalPads->At(i)))->GetString();
1748 drawCommand.Append(fAbbreviation.Data());
1749 AliTPCCalPad* calPad = GetCalPad(drawCommand.Data(), "", calPadName);
1750 calPadsArray->Add(calPad);
1752 std::cout << std::endl;
1753 listOfCalPads->Delete();
1754 delete listOfCalPads;
1755 return calPadsArray;
1759 TString* AliTPCCalibViewer::Fit(const char* drawCommand, const char* formula, const char* cuts, Double_t & chi2, TVectorD &fitParam, TMatrixD &covMatrix){
1761 // fit an arbitrary function, specified by formula into the data, specified by drawCommand and cuts
1762 // returns chi2, fitParam and covMatrix
1763 // returns TString with fitted formula
1766 TString formulaStr(formula);
1767 TString drawStr(drawCommand);
1768 TString cutStr(cuts);
1771 drawStr.ReplaceAll(fAbbreviation, fAppendString);
1772 cutStr.ReplaceAll(fAbbreviation, fAppendString);
1773 formulaStr.ReplaceAll(fAbbreviation, fAppendString);
1775 formulaStr.ReplaceAll("++", fAbbreviation);
1776 TObjArray* formulaTokens = formulaStr.Tokenize(fAbbreviation.Data());
1777 Int_t dim = formulaTokens->GetEntriesFast();
1779 fitParam.ResizeTo(dim);
1780 covMatrix.ResizeTo(dim,dim);
1782 TLinearFitter* fitter = new TLinearFitter(dim+1, Form("hyp%d",dim));
1783 fitter->StoreData(kTRUE);
1784 fitter->ClearPoints();
1786 Int_t entries = Draw(drawStr.Data(), cutStr.Data(), "goff");
1787 if (entries == -1) return new TString("An ERROR has occured during fitting!");
1788 Double_t **values = new Double_t*[dim+1] ;
1790 for (Int_t i = 0; i < dim + 1; i++){
1792 if (i < dim) centries = fTree->Draw(((TObjString*)formulaTokens->At(i))->GetName(), cutStr.Data(), "goff");
1793 else centries = fTree->Draw(drawStr.Data(), cutStr.Data(), "goff");
1795 if (entries != centries) return new TString("An ERROR has occured during fitting!");
1796 values[i] = new Double_t[entries];
1797 memcpy(values[i], fTree->GetV1(), entries*sizeof(Double_t));
1800 // add points to the fitter
1801 for (Int_t i = 0; i < entries; i++){
1803 for (Int_t j=0; j<dim;j++) x[j]=values[j][i];
1804 fitter->AddPoint(x, values[dim][i], 1);
1808 fitter->GetParameters(fitParam);
1809 fitter->GetCovarianceMatrix(covMatrix);
1810 chi2 = fitter->GetChisquare();
1813 TString *preturnFormula = new TString(Form("( %e+",fitParam[0])), &returnFormula = *preturnFormula;
1815 for (Int_t iparam = 0; iparam < dim; iparam++) {
1816 returnFormula.Append(Form("%s*(%e)",((TObjString*)formulaTokens->At(iparam))->GetName(),fitParam[iparam+1]));
1817 if (iparam < dim-1) returnFormula.Append("+");
1819 returnFormula.Append(" )");
1820 delete formulaTokens;
1823 return preturnFormula;
1827 void AliTPCCalibViewer::MakeTreeWithObjects(const char *fileName, const TObjArray *const array, const char * mapFileName) {
1829 // Write tree with all available information
1830 // im mapFileName is speciefied, the Map information are also written to the tree
1831 // AliTPCCalPad-Objects are written directly to the tree, so that they can be accessd later on
1832 // (does not work!!!)
1834 AliTPCROC* tpcROCinstance = AliTPCROC::Instance();
1836 TObjArray* mapIROCs = 0;
1837 TObjArray* mapOROCs = 0;
1838 TVectorF *mapIROCArray = 0;
1839 TVectorF *mapOROCArray = 0;
1840 Int_t mapEntries = 0;
1841 TString* mapNames = 0;
1844 TFile mapFile(mapFileName, "read");
1846 TList* listOfROCs = mapFile.GetListOfKeys();
1847 mapEntries = listOfROCs->GetEntries()/2;
1848 mapIROCs = new TObjArray(mapEntries*2);
1849 mapOROCs = new TObjArray(mapEntries*2);
1850 mapIROCArray = new TVectorF[mapEntries];
1851 mapOROCArray = new TVectorF[mapEntries];
1853 mapNames = new TString[mapEntries];
1854 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
1855 TString rocName(((TKey*)(listOfROCs->At(ivalue*2)))->GetName());
1856 rocName.Remove(rocName.Length()-4, 4);
1857 mapIROCs->AddAt((AliTPCCalROC*)mapFile.Get((rocName + "IROC").Data()), ivalue);
1858 mapOROCs->AddAt((AliTPCCalROC*)mapFile.Get((rocName + "OROC").Data()), ivalue);
1859 mapNames[ivalue].Append(rocName);
1862 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
1863 mapIROCArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(0));
1864 mapOROCArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(36));
1866 for (UInt_t ichannel = 0; ichannel < tpcROCinstance->GetNChannels(0); ichannel++)
1867 (mapIROCArray[ivalue])[ichannel] = ((AliTPCCalROC*)(mapIROCs->At(ivalue)))->GetValue(ichannel);
1868 for (UInt_t ichannel = 0; ichannel < tpcROCinstance->GetNChannels(36); ichannel++)
1869 (mapOROCArray[ivalue])[ichannel] = ((AliTPCCalROC*)(mapOROCs->At(ivalue)))->GetValue(ichannel);
1872 } // if (mapFileName)
1874 TTreeSRedirector cstream(fileName);
1875 Int_t arrayEntries = array->GetEntries();
1877 // Read names of AliTPCCalPads and save them in names[]
1878 TString* names = new TString[arrayEntries];
1879 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++)
1880 names[ivalue].Append(((AliTPCCalPad*)array->At(ivalue))->GetName());
1882 for (UInt_t isector = 0; isector < tpcROCinstance->GetNSectors(); isector++) {
1884 TVectorF *vectorArray = new TVectorF[arrayEntries];
1885 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++)
1886 vectorArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(isector));
1890 // fill vectors of variable per pad
1892 TVectorF *posArray = new TVectorF[8];
1893 for (Int_t ivalue = 0; ivalue < 8; ivalue++)
1894 posArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(isector));
1896 Float_t posG[3] = {0};
1897 Float_t posL[3] = {0};
1899 for (UInt_t irow = 0; irow < tpcROCinstance->GetNRows(isector); irow++) {
1900 for (UInt_t ipad = 0; ipad < tpcROCinstance->GetNPads(isector, irow); ipad++) {
1901 tpcROCinstance->GetPositionLocal(isector, irow, ipad, posL);
1902 tpcROCinstance->GetPositionGlobal(isector, irow, ipad, posG);
1903 posArray[0][ichannel] = irow;
1904 posArray[1][ichannel] = ipad;
1905 posArray[2][ichannel] = posL[0];
1906 posArray[3][ichannel] = posL[1];
1907 posArray[4][ichannel] = posG[0];
1908 posArray[5][ichannel] = posG[1];
1909 posArray[6][ichannel] = (Int_t)(ipad - (Double_t)(tpcROCinstance->GetNPads(isector, irow))/2);
1910 posArray[7][ichannel] = ichannel;
1912 // loop over array containing AliTPCCalPads
1913 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
1914 AliTPCCalPad* calPad = (AliTPCCalPad*) array->At(ivalue);
1915 AliTPCCalROC* calROC = calPad->GetCalROC(isector);
1917 (vectorArray[ivalue])[ichannel] = calROC->GetValue(irow, ipad);
1919 (vectorArray[ivalue])[ichannel] = 0;
1924 AliTPCCalROC dummyROC(0);
1925 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
1926 AliTPCCalROC *roc = ((AliTPCCalPad*)array->At(ivalue))->GetCalROC(isector);
1927 if (!roc) roc = &dummyROC;
1928 cstream << "calPads" <<
1929 (Char_t*)((names[ivalue] + ".=").Data()) << &vectorArray[ivalue];
1930 cstream << "calPads" <<
1931 (Char_t*)((names[ivalue] + "Pad.=").Data()) << roc;
1935 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
1937 cstream << "calPads" <<
1938 (Char_t*)((mapNames[ivalue] + ".=").Data()) << &mapIROCArray[ivalue];
1940 cstream << "calPads" <<
1941 (Char_t*)((mapNames[ivalue] + ".=").Data()) << &mapOROCArray[ivalue];
1945 cstream << "calPads" <<
1946 "sector=" << isector;
1948 cstream << "calPads" <<
1949 "row.=" << &posArray[0] <<
1950 "pad.=" << &posArray[1] <<
1951 "lx.=" << &posArray[2] <<
1952 "ly.=" << &posArray[3] <<
1953 "gx.=" << &posArray[4] <<
1954 "gy.=" << &posArray[5] <<
1955 "rpad.=" << &posArray[6] <<
1956 "channel.=" << &posArray[7];
1958 cstream << "calPads" <<
1962 delete[] vectorArray;
1963 } //for (UInt_t isector = 0; isector < tpcROCinstance->GetNSectors(); isector++)
1969 delete[] mapIROCArray;
1970 delete[] mapOROCArray;
1976 void AliTPCCalibViewer::MakeTree(const char * fileName, TObjArray * array, const char * mapFileName, AliTPCCalPad *const outlierPad, Float_t ltmFraction) {
1978 // Write a tree with all available information
1979 // if mapFileName is speciefied, the Map information are also written to the tree
1980 // pads specified in outlierPad are not used for calculating statistics
1981 // The following statistical information on the basis of a ROC are calculated:
1982 // "_Median", "_Mean", "_LTM", "_RMS_LTM"
1983 // "_Median_OutlierCutted", "_Mean_OutlierCutted", "_RMS_OutlierCutted", "_LTM_OutlierCutted", "_RMS_LTM_OutlierCutted"
1984 // The following position variables are available:
1985 // "row", "pad", "lx", "ly", "gx", "gy", "rpad", "channel"
1987 // The tree out of this function is the basis for the AliTPCCalibViewer and the AliTPCCalibViewerGUI.
1989 AliTPCROC* tpcROCinstance = AliTPCROC::Instance();
1991 TObjArray* mapIROCs = 0;
1992 TObjArray* mapOROCs = 0;
1993 TVectorF *mapIROCArray = 0;
1994 TVectorF *mapOROCArray = 0;
1995 Int_t mapEntries = 0;
1996 TString* mapNames = 0;
1999 TFile mapFile(mapFileName, "read");
2001 TList* listOfROCs = mapFile.GetListOfKeys();
2002 mapEntries = listOfROCs->GetEntries()/2;
2003 mapIROCs = new TObjArray(mapEntries*2);
2004 mapOROCs = new TObjArray(mapEntries*2);
2005 mapIROCArray = new TVectorF[mapEntries];
2006 mapOROCArray = new TVectorF[mapEntries];
2008 mapNames = new TString[mapEntries];
2009 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
2010 TString rocName(((TKey*)(listOfROCs->At(ivalue*2)))->GetName());
2011 rocName.Remove(rocName.Length()-4, 4);
2012 mapIROCs->AddAt((AliTPCCalROC*)mapFile.Get((rocName + "IROC").Data()), ivalue);
2013 mapOROCs->AddAt((AliTPCCalROC*)mapFile.Get((rocName + "OROC").Data()), ivalue);
2014 mapNames[ivalue].Append(rocName);
2017 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
2018 mapIROCArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(0));
2019 mapOROCArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(36));
2021 for (UInt_t ichannel = 0; ichannel < tpcROCinstance->GetNChannels(0); ichannel++)
2022 (mapIROCArray[ivalue])[ichannel] = ((AliTPCCalROC*)(mapIROCs->At(ivalue)))->GetValue(ichannel);
2023 for (UInt_t ichannel = 0; ichannel < tpcROCinstance->GetNChannels(36); ichannel++)
2024 (mapOROCArray[ivalue])[ichannel] = ((AliTPCCalROC*)(mapOROCs->At(ivalue)))->GetValue(ichannel);
2027 } // if (mapFileName)
2029 TTreeSRedirector cstream(fileName);
2030 Int_t arrayEntries = 0;
2031 if (array) arrayEntries = array->GetEntries();
2033 TString* names = new TString[arrayEntries];
2034 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++)
2035 names[ivalue].Append(((AliTPCCalPad*)array->At(ivalue))->GetName());
2037 for (UInt_t isector = 0; isector < tpcROCinstance->GetNSectors(); isector++) {
2039 // get statistic for given sector
2041 TVectorF median(arrayEntries);
2042 TVectorF mean(arrayEntries);
2043 TVectorF rms(arrayEntries);
2044 TVectorF ltm(arrayEntries);
2045 TVectorF ltmrms(arrayEntries);
2046 TVectorF medianWithOut(arrayEntries);
2047 TVectorF meanWithOut(arrayEntries);
2048 TVectorF rmsWithOut(arrayEntries);
2049 TVectorF ltmWithOut(arrayEntries);
2050 TVectorF ltmrmsWithOut(arrayEntries);
2052 TVectorF *vectorArray = new TVectorF[arrayEntries];
2053 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++){
2054 vectorArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(isector));
2055 vectorArray[ivalue].SetUniqueID(array->UncheckedAt(ivalue)->GetUniqueID());
2056 // printf("UniqueID: %d\n",vectorArray[ivalue].GetUniqueID());
2059 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
2060 AliTPCCalPad* calPad = (AliTPCCalPad*) array->At(ivalue);
2061 AliTPCCalROC* calROC = calPad->GetCalROC(isector);
2062 AliTPCCalROC* outlierROC = 0;
2063 if (outlierPad) outlierROC = outlierPad->GetCalROC(isector);
2065 median[ivalue] = calROC->GetMedian();
2066 mean[ivalue] = calROC->GetMean();
2067 rms[ivalue] = calROC->GetRMS();
2068 Double_t ltmrmsValue = 0;
2069 ltm[ivalue] = calROC->GetLTM(<mrmsValue, ltmFraction);
2070 ltmrms[ivalue] = ltmrmsValue;
2072 medianWithOut[ivalue] = calROC->GetMedian(outlierROC);
2073 meanWithOut[ivalue] = calROC->GetMean(outlierROC);
2074 rmsWithOut[ivalue] = calROC->GetRMS(outlierROC);
2076 ltmWithOut[ivalue] = calROC->GetLTM(<mrmsValue, ltmFraction, outlierROC);
2077 ltmrmsWithOut[ivalue] = ltmrmsValue;
2081 median[ivalue] = 0.;
2085 ltmrms[ivalue] = 0.;
2086 medianWithOut[ivalue] = 0.;
2087 meanWithOut[ivalue] = 0.;
2088 rmsWithOut[ivalue] = 0.;
2089 ltmWithOut[ivalue] = 0.;
2090 ltmrmsWithOut[ivalue] = 0.;
2095 // fill vectors of variable per pad
2097 TVectorF *posArray = new TVectorF[8];
2098 for (Int_t ivalue = 0; ivalue < 8; ivalue++)
2099 posArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(isector));
2101 Float_t posG[3] = {0};
2102 Float_t posL[3] = {0};
2104 for (UInt_t irow = 0; irow < tpcROCinstance->GetNRows(isector); irow++) {
2105 for (UInt_t ipad = 0; ipad < tpcROCinstance->GetNPads(isector, irow); ipad++) {
2106 tpcROCinstance->GetPositionLocal(isector, irow, ipad, posL);
2107 tpcROCinstance->GetPositionGlobal(isector, irow, ipad, posG);
2108 posArray[0][ichannel] = irow;
2109 posArray[1][ichannel] = ipad;
2110 posArray[2][ichannel] = posL[0];
2111 posArray[3][ichannel] = posL[1];
2112 posArray[4][ichannel] = posG[0];
2113 posArray[5][ichannel] = posG[1];
2114 posArray[6][ichannel] = (Int_t)(ipad - (Double_t)(tpcROCinstance->GetNPads(isector, irow))/2);
2115 posArray[7][ichannel] = ichannel;
2117 // loop over array containing AliTPCCalPads
2118 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
2119 AliTPCCalPad* calPad = (AliTPCCalPad*) array->At(ivalue);
2120 AliTPCCalROC* calROC = calPad->GetCalROC(isector);
2122 (vectorArray[ivalue])[ichannel] = calROC->GetValue(irow, ipad);
2124 (vectorArray[ivalue])[ichannel] = 0;
2130 cstream << "calPads" <<
2131 "sector=" << isector;
2133 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
2134 cstream << "calPads" <<
2135 (Char_t*)((names[ivalue] + "_Median=").Data()) << median[ivalue] <<
2136 (Char_t*)((names[ivalue] + "_Mean=").Data()) << mean[ivalue] <<
2137 (Char_t*)((names[ivalue] + "_RMS=").Data()) << rms[ivalue] <<
2138 (Char_t*)((names[ivalue] + "_LTM=").Data()) << ltm[ivalue] <<
2139 (Char_t*)((names[ivalue] + "_RMS_LTM=").Data()) << ltmrms[ivalue];
2141 cstream << "calPads" <<
2142 (Char_t*)((names[ivalue] + "_Median_OutlierCutted=").Data()) << medianWithOut[ivalue] <<
2143 (Char_t*)((names[ivalue] + "_Mean_OutlierCutted=").Data()) << meanWithOut[ivalue] <<
2144 (Char_t*)((names[ivalue] + "_RMS_OutlierCutted=").Data()) << rmsWithOut[ivalue] <<
2145 (Char_t*)((names[ivalue] + "_LTM_OutlierCutted=").Data()) << ltmWithOut[ivalue] <<
2146 (Char_t*)((names[ivalue] + "_RMS_LTM_OutlierCutted=").Data()) << ltmrmsWithOut[ivalue];
2148 //timestamp and run, if given in title
2149 /* TString title(((AliTPCCalPad*) array->At(ivalue))->GetTitle());
2150 TObjArray *arrtitle=title.Tokenize(",");
2153 TIter next(arrtitle);
2155 while ( (o=next()) ){
2156 TString &entry=((TObjString*)o)->GetString();
2157 entry.Remove(TString::kBoth,' ');
2158 entry.Remove(TString::kBoth,'\t');
2159 if (entry.BeginsWith("Run:")) {
2160 run=entry(4,entry.Length()).Atoi();
2161 } else if (entry.BeginsWith("Time:")) {
2162 time=entry(6,entry.Length()).Atoi();
2169 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
2170 cstream << "calPads" <<
2171 (Char_t*)((names[ivalue] + ".=").Data()) << &vectorArray[ivalue];
2175 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
2177 cstream << "calPads" <<
2178 (Char_t*)((mapNames[ivalue] + ".=").Data()) << &mapIROCArray[ivalue];
2180 cstream << "calPads" <<
2181 (Char_t*)((mapNames[ivalue] + ".=").Data()) << &mapOROCArray[ivalue];
2185 cstream << "calPads" <<
2186 "row.=" << &posArray[0] <<
2187 "pad.=" << &posArray[1] <<
2188 "lx.=" << &posArray[2] <<
2189 "ly.=" << &posArray[3] <<
2190 "gx.=" << &posArray[4] <<
2191 "gy.=" << &posArray[5] <<
2192 "rpad.=" << &posArray[6] <<
2193 "channel.=" << &posArray[7];
2195 cstream << "calPads" <<
2199 delete[] vectorArray;
2207 delete[] mapIROCArray;
2208 delete[] mapOROCArray;
2214 void AliTPCCalibViewer::MakeTree(const char *outPutFileName, const Char_t *inputFileName, AliTPCCalPad *outlierPad, Float_t ltmFraction, const char *mapFileName ){
2216 // Function to create a calibration Tree with all available information.
2217 // See also documentation to MakeTree
2218 // the file "inputFileName" must be in the following format (see also CreateObjectList):
2219 // (each colum separated by tabs, "dependingOnType" can have 2 or 3 colums)
2221 // type path dependingOnType
2224 // dependingOnType = CETmean CEQmean CETrms
2226 // type == "Pulser":
2227 // dependingOnType = PulserTmean PulsterQmean PulserTrms
2229 // type == "Pedestals":
2230 // dependingOnType = Pedestals Noise
2232 // type == "CalPad":
2233 // dependingOnType = NameInFile NameToWriteToFile
2237 CreateObjectList(inputFileName, &objArray);
2238 MakeTree(outPutFileName, &objArray, mapFileName, outlierPad, ltmFraction);
2242 void AliTPCCalibViewer::CreateObjectList(const Char_t *filename, TObjArray *calibObjects){
2244 // Function to create a TObjArray out of a given file
2245 // the file must be in the following format:
2246 // (each colum separated by tabs, "dependingOnType" can have 2 or 3 colums)
2249 // type path dependingOnType
2252 // dependingOnType = CETmean CEQmean CETrms
2254 // type == "Pulser":
2255 // dependingOnType = PulserTmean PulsterQmean PulserTrms
2257 // type == "Pedestals":
2258 // dependingOnType = Pedestals Noise
2260 // type == "CalPad":
2261 // dependingOnType = NameInFile NameToWriteToFile
2265 if ( calibObjects == 0x0 ) return;
2268 if ( !in.is_open() ){
2269 fprintf(stderr,"Error: cannot open list file '%s'", filename);
2273 AliTPCCalPad *calPad=0x0;
2279 TObjArray *arrFileLine = sFile.Tokenize("\n");
2280 TIter nextLine(arrFileLine);
2282 TObjString *sObjLine = 0x0;
2283 while ( (sObjLine = (TObjString*)nextLine()) ){
2284 TString sLine(sObjLine->GetString());
2286 TObjArray *arrCol = sLine.Tokenize("\t");
2287 Int_t nCols = arrCol->GetEntriesFast();
2289 TObjString *sObjType = (TObjString*)(arrCol->At(0));
2290 TObjString *sObjFileName = (TObjString*)(arrCol->At(1));
2291 TObjString *sObjName = 0x0;
2293 if ( !sObjType || !sObjFileName ) continue;
2294 TString sType(sObjType->GetString());
2295 TString sFileName(sObjFileName->GetString());
2296 printf("Type %s, opening %s \n", sType.Data(), sFileName.Data());
2297 TFile *fIn = TFile::Open(sFileName);
2299 fprintf(stderr,"File not found: '%s'", sFileName.Data());
2303 if ( sType == "CE" ){ // next three colums are the names for CETmean, CEQmean and CETrms
2304 AliTPCCalibCE *ce = (AliTPCCalibCE*)fIn->Get("AliTPCCalibCE");
2305 calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadT0());
2306 if (nCols > 2) { // check, if the name is provided
2307 sObjName = (TObjString*)(arrCol->At(2));
2308 calPad->SetNameTitle(sObjName->GetString().Data(), sObjName->GetString().Data());
2310 else calPad->SetNameTitle("CETmean","CETmean");
2311 calibObjects->Add(calPad);
2313 calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadQ());
2314 if (nCols > 3) { // check, if the name is provided
2315 sObjName = (TObjString*)(arrCol->At(3));
2316 calPad->SetNameTitle(sObjName->GetString().Data(), sObjName->GetString().Data());
2318 else calPad->SetNameTitle("CEQmean","CEQmean");
2319 calibObjects->Add(calPad);
2321 calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadRMS());
2322 if (nCols > 4) { // check, if the name is provided
2323 sObjName = (TObjString*)(arrCol->At(4));
2324 calPad->SetNameTitle(sObjName->GetString().Data(), sObjName->GetString().Data());
2326 else calPad->SetNameTitle("CETrms","CETrms");
2327 calibObjects->Add(calPad);
2329 } else if ( sType == "Pulser") {
2330 AliTPCCalibPulser *sig = (AliTPCCalibPulser*)fIn->Get("AliTPCCalibPulser");
2332 calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadT0());
2334 sObjName = (TObjString*)(arrCol->At(2));
2335 calPad->SetNameTitle(sObjName->GetString().Data(), sObjName->GetString().Data());
2337 else calPad->SetNameTitle("PulserTmean","PulserTmean");
2338 calibObjects->Add(calPad);
2340 calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadQ());
2342 sObjName = (TObjString*)(arrCol->At(3));
2343 calPad->SetNameTitle(sObjName->GetString().Data(), sObjName->GetString().Data());
2345 else calPad->SetNameTitle("PulserQmean","PulserQmean");
2346 calibObjects->Add(calPad);
2348 calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadRMS());
2350 sObjName = (TObjString*)(arrCol->At(4));
2351 calPad->SetNameTitle(sObjName->GetString().Data(), sObjName->GetString().Data());
2353 else calPad->SetNameTitle("PulserTrms","PulserTrms");
2354 calibObjects->Add(calPad);
2356 } else if ( sType == "Pedestals") {
2357 AliTPCCalibPedestal *ped = (AliTPCCalibPedestal*)fIn->Get("AliTPCCalibPedestal");
2359 calPad = new AliTPCCalPad((TObjArray*)ped->GetCalPadPedestal());
2361 sObjName = (TObjString*)(arrCol->At(2));
2362 calPad->SetNameTitle(sObjName->GetString().Data(), sObjName->GetString().Data());
2364 else calPad->SetNameTitle("Pedestals","Pedestals");
2365 calibObjects->Add(calPad);
2367 calPad = new AliTPCCalPad((TObjArray*)ped->GetCalPadRMS());
2369 sObjName = (TObjString*)(arrCol->At(3));
2370 calPad->SetNameTitle(sObjName->GetString().Data(), sObjName->GetString().Data());
2372 else calPad->SetNameTitle("Noise","Noise");
2373 calibObjects->Add(calPad);
2375 } else if ( sType == "CalPad") {
2376 if (nCols > 2) sObjName = (TObjString*)(arrCol->At(2));
2378 calPad = new AliTPCCalPad(*(AliTPCCalPad*)fIn->Get(sObjName->GetString().Data()));
2380 sObjName = (TObjString*)(arrCol->At(3));
2381 calPad->SetNameTitle(sObjName->GetString().Data(), sObjName->GetString().Data());
2383 calibObjects->Add(calPad);
2385 fprintf(stderr,"Undefined Type: '%s'",sType.Data());