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 ///////////////////////////////////////////////////////////////////////////////
50 #include <THashTable.h>
51 #include <TObjString.h>
52 #include "TTreeStream.h"
56 #include "AliTPCCalibPulser.h"
57 #include "AliTPCCalibPedestal.h"
58 #include "AliTPCCalibCE.h"
59 // #include "TObjArray.h"
60 // #include "TObjString.h"
61 // #include "TString.h"
62 // #include "AliTPCCalPad.h"
68 #include "AliTPCCalibViewer.h"
70 ClassImp(AliTPCCalibViewer)
72 AliTPCCalibViewer::AliTPCCalibViewer()
76 fListOfObjectsToBeDeleted(0),
80 // Default constructor
85 //_____________________________________________________________________________
86 AliTPCCalibViewer::AliTPCCalibViewer(const AliTPCCalibViewer &c)
90 fListOfObjectsToBeDeleted(0),
94 // dummy AliTPCCalibViewer copy constructor
98 fTreeMustBeDeleted = c.fTreeMustBeDeleted;
99 //fFile = new TFile(*(c.fFile));
100 fListOfObjectsToBeDeleted = c.fListOfObjectsToBeDeleted;
103 //_____________________________________________________________________________
104 AliTPCCalibViewer::AliTPCCalibViewer(TTree* tree)
108 fListOfObjectsToBeDeleted(0),
109 fTreeMustBeDeleted(0)
112 // Constructor that initializes the calibration viewer
115 fTreeMustBeDeleted = kFALSE;
116 fListOfObjectsToBeDeleted = new TObjArray();
119 //_____________________________________________________________________________
120 AliTPCCalibViewer::AliTPCCalibViewer(char* fileName, char* treeName)
124 fListOfObjectsToBeDeleted(0),
125 fTreeMustBeDeleted(0)
128 // Constructor to initialize the calibration viewer
129 // the file 'fileName' contains the tree 'treeName'
131 fFile = new TFile(fileName, "read");
132 fTree = (TTree*) fFile->Get(treeName);
133 fTreeMustBeDeleted = kTRUE;
134 fListOfObjectsToBeDeleted = new TObjArray();
137 //____________________________________________________________________________
138 AliTPCCalibViewer & AliTPCCalibViewer::operator =(const AliTPCCalibViewer & param)
141 // assignment operator - dummy
142 // not yet working!!!
145 fTreeMustBeDeleted = param.fTreeMustBeDeleted;
146 //fFile = new TFile(*(param.fFile));
147 fListOfObjectsToBeDeleted = param.fListOfObjectsToBeDeleted;
151 //_____________________________________________________________________________
152 AliTPCCalibViewer::~AliTPCCalibViewer()
155 // AliTPCCalibViewer destructor
156 // all objects will be deleted, the file will be closed, the pictures will disappear
158 if (fTree && fTreeMustBeDeleted) {
159 fTree->SetCacheSize(0);
168 for (Int_t i = fListOfObjectsToBeDeleted->GetEntriesFast()-1; i >= 0; i--) {
169 //cout << "Index " << i << " trying to delete the following object: " << fListOfObjectsToBeDeleted->At(i)->GetName() << "..."<< endl;
170 delete fListOfObjectsToBeDeleted->At(i);
172 delete fListOfObjectsToBeDeleted;
175 //_____________________________________________________________________________
176 void AliTPCCalibViewer::Delete(Option_t* option) {
178 // Should be called from AliTPCCalibViewerGUI class only.
179 // If you use Delete() do not call the destructor.
180 // All objects (except those contained in fListOfObjectsToBeDeleted) will be deleted, the file will be closed.
183 option = option; // to avoid warnings on compiling
184 if (fTree && fTreeMustBeDeleted) {
185 fTree->SetCacheSize(0);
190 delete fListOfObjectsToBeDeleted;
193 //_____________________________________________________________________________
194 Int_t AliTPCCalibViewer::EasyDraw(const char* drawCommand, const char* sector, const char* cuts, const char* drawOptions, Bool_t writeDrawCommand) const {
196 // easy drawing of data, use '~' for abbreviation of '.fElements'
197 // example: EasyDraw("CETmean~-CETmean_mean", "A", "(CETmean~-CETmean_mean)>0")
198 // sector: sector-number - only the specified sector will be drwawn
199 // 'A'/'C' or 'a'/'c' - side A/C will be drawn
200 // 'ALL' - whole TPC will be drawn, projected on one side
201 // cuts: specifies cuts
202 // drawOptions: draw options like 'same'
203 // writeDrawCommand: write the command, that is passed to TTree::Draw
206 TString drawStr(drawCommand);
207 TString sectorStr(sector);
210 //TString drawOptionsStr("profcolz ");
211 TString drawOptionsStr("");
213 Int_t rndNumber = rnd.Integer(10000);
215 if (drawOptions && strcmp(drawOptions, "") != 0)
216 drawOptionsStr += drawOptions;
218 drawOptionsStr += "profcolz";
220 if (sectorStr == "A") {
221 drawStr += ":gy.fElements:gx.fElements>>prof";
222 drawStr += rndNumber;
223 drawStr += "(330,-250,250,330,-250,250)";
224 cutStr += "(sector/18)%2==0 ";
226 else if (sectorStr == "C") {
227 drawStr += ":gy.fElements:gx.fElements>>prof";
228 drawStr += rndNumber;
229 drawStr += "(330,-250,250,330,-250,250)";
230 cutStr += "(sector/18)%2==1 ";
232 else if (sectorStr == "ALL") {
233 drawStr += ":gy.fElements:gx.fElements>>prof";
234 drawStr += rndNumber;
235 drawStr += "(330,-250,250,330,-250,250)";
237 else if (sectorStr.IsDigit()) {
238 Int_t isec = sectorStr.Atoi();
239 drawStr += ":rpad.fElements:row.fElements>>prof";
240 drawStr += rndNumber;
241 if (isec < 36 && isec >= 0)
242 drawStr += "(63,0,63,108,-54,54)";
243 else if (isec < 72 && isec >= 36)
244 drawStr += "(96,0,96,140,-70,70)";
246 Error("EasyDraw","The TPC contains only sectors between 0 and 71.");
249 cutStr += "(sector==";
254 if (cuts && cuts[0] != 0) {
255 if (cutStr.Length() != 0) cutStr += "&& ";
260 drawStr.ReplaceAll("~", ".fElements");
261 cutStr.ReplaceAll("~", ".fElements");
262 if (writeDrawCommand) std::cout << "fTree->Draw(\"" << drawStr << "\", \"" << cutStr << "\", \"" << drawOptionsStr << "\");" << std::endl;
263 return fTree->Draw(drawStr.Data(), cutStr.Data(), drawOptionsStr.Data());
267 Int_t AliTPCCalibViewer::EasyDraw(const char* drawCommand, Int_t sector, const char* cuts, const char* drawOptions, Bool_t writeDrawCommand) const {
269 // easy drawing of data, use '~' for abbreviation of '.fElements'
270 // example: EasyDraw("CETmean~-CETmean_mean", 34, "(CETmean~-CETmean_mean)>0")
271 // sector: sector-number - only the specified sector will be drwawn
272 // cuts: specifies cuts
273 // drawOptions: draw options like 'same'
274 // writeDrawCommand: write the command, that is passed to TTree::Draw
276 if (sector >= 0 && sector < 72) {
278 sprintf(sectorChr, "%i", sector);
279 return EasyDraw(drawCommand, sectorChr, cuts, drawOptions, writeDrawCommand);
281 Error("EasyDraw","The TPC contains only sectors between 0 and 71.");
286 //_____________________________________________________________________________
287 Int_t AliTPCCalibViewer::EasyDraw1D(const char* drawCommand, const char* sector, const char* cuts, const char* drawOptions, Bool_t writeDrawCommand) const {
289 // easy drawing of data, use '~' for abbreviation of '.fElements'
290 // example: EasyDraw("CETmean~-CETmean_mean", "A", "(CETmean~-CETmean_mean)>0")
291 // sector: sector-number - the specified sector will be drwawn
292 // 'A'/'C' or 'a'/'c' - side A/C will be drawn
293 // 'ALL' - whole TPC will be drawn, projected on one side
294 // cuts: specifies cuts
295 // drawOptions: draw options like 'same'
296 // writeDrawCommand: write the command, that is passed to TTree::Draw
299 TString drawStr(drawCommand);
300 TString sectorStr(sector);
301 TString drawOptionsStr(drawOptions);
305 if (sectorStr == "A")
306 cutStr += "(sector/18)%2==0 ";
307 else if (sectorStr == "C")
308 cutStr += "(sector/18)%2==1 ";
309 else if (sectorStr.IsDigit()) {
310 Int_t isec = sectorStr.Atoi();
311 if (isec < 0 || isec > 71) {
312 Error("EasyDraw","The TPC contains only sectors between 0 and 71.");
315 cutStr += "(sector==";
320 if (cuts && cuts[0] != 0) {
321 if (cutStr.Length() != 0) cutStr += "&& ";
327 drawStr.ReplaceAll("~", ".fElements");
328 cutStr.ReplaceAll("~", ".fElements");
329 if (writeDrawCommand) std::cout << "fTree->Draw(\"" << drawStr << "\", \"" << cutStr << "\", \"" << drawOptionsStr << "\");" << std::endl;
330 return fTree->Draw(drawStr.Data(), cutStr.Data(), drawOptionsStr.Data());
334 Int_t AliTPCCalibViewer::EasyDraw1D(const char* drawCommand, Int_t sector, const char* cuts, const char* drawOptions, Bool_t writeDrawCommand) const {
336 // easy drawing of data, use '~' for abbreviation of '.fElements'
337 // example: EasyDraw("CETmean~-CETmean_mean", 34, "(CETmean~-CETmean_mean)>0")
338 // sector: sector-number - the specified sector will be drwawn
339 // cuts: specifies cuts
340 // drawOptions: draw options like 'same'
341 // writeDrawCommand: write the command, that is passed to TTree::Draw
344 if (sector >= 0 && sector < 72) {
346 sprintf(sectorChr, "%i", sector);
347 return EasyDraw1D(drawCommand, sectorChr, cuts, drawOptions, writeDrawCommand);
349 Error("EasyDraw","The TPC contains only sectors between 0 and 71.");
354 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 {
356 // Easy drawing of data, in principle the same as EasyDraw1D
357 // Difference: A line for the mean / median / LTM is drawn
358 // in 'sigmas' you can specify in which distance to the mean/median/LTM you want to see a line in sigma-units, separated by ';'
359 // 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.
360 // "plotMean", "plotMedian" and "plotLTM": what kind of lines do you want to see?
362 if (sector >= 0 && sector < 72) {
364 sprintf(sectorChr, "%i", sector);
365 return DrawHisto1D(drawCommand, sectorChr, cuts, sigmas, plotMean, plotMedian, plotLTM);
367 Error("DrawHisto1D","The TPC contains only sectors between 0 and 71.");
372 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 {
374 // Easy drawing of data, in principle the same as EasyDraw1D
375 // Difference: A line for the mean / median / LTM is drawn
376 // in 'sigmas' you can specify in which distance to the mean/median/LTM you want to see a line in sigma-units, separated by ';'
377 // 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.
378 // "plotMean", "plotMedian" and "plotLTM": what kind of lines do you want to see?
380 Int_t oldOptStat = gStyle->GetOptStat();
381 gStyle->SetOptStat(0000000);
382 Double_t ltmFraction = 0.8;
384 TObjArray *sigmasTokens = TString(sigmas).Tokenize(";");
385 TVectorF nsigma(sigmasTokens->GetEntriesFast());
386 for (Int_t i = 0; i < sigmasTokens->GetEntriesFast(); i++) {
387 TString str(((TObjString*)sigmasTokens->At(i))->GetString());
388 Double_t sig = (str.IsFloat()) ? str.Atof() : 0;
392 TString drawStr(drawCommand);
393 drawStr += " >> tempHist";
394 Int_t entries = EasyDraw1D(drawStr.Data(), sector, cuts);
395 TH1F *htemp = (TH1F*)gDirectory->Get("tempHist");
396 // FIXME is this histogram deleted automatically?
397 Double_t *values = fTree->GetV1(); // value is the array containing 'entries' numbers
399 Double_t mean = TMath::Mean(entries, values);
400 Double_t median = TMath::Median(entries, values);
401 Double_t sigma = TMath::RMS(entries, values);
402 Double_t maxY = htemp->GetMaximum();
405 TLegend * legend = new TLegend(.7,.7, .99, .99, "Statistical information");
406 // sprintf(c, "%s, sector: %i", type, sector);
407 fListOfObjectsToBeDeleted->Add(legend);
411 TLine* line = new TLine(mean, 0, mean, maxY);
412 fListOfObjectsToBeDeleted->Add(line);
413 line->SetLineColor(kRed);
414 line->SetLineWidth(2);
415 line->SetLineStyle(1);
417 sprintf(c, "Mean: %f", mean);
418 legend->AddEntry(line, c, "l");
420 for (Int_t i = 0; i < nsigma.GetNoElements(); i++) {
421 TLine* linePlusSigma = new TLine(mean + nsigma[i] * sigma, 0, mean + nsigma[i] * sigma, maxY);
422 fListOfObjectsToBeDeleted->Add(linePlusSigma);
423 linePlusSigma->SetLineColor(kRed);
424 linePlusSigma->SetLineStyle(2 + i);
425 linePlusSigma->Draw();
426 TLine* lineMinusSigma = new TLine(mean - nsigma[i] * sigma, 0, mean - nsigma[i] * sigma, maxY);
427 fListOfObjectsToBeDeleted->Add(lineMinusSigma);
428 lineMinusSigma->SetLineColor(kRed);
429 lineMinusSigma->SetLineStyle(2 + i);
430 lineMinusSigma->Draw();
431 sprintf(c, "%i #sigma = %f",(Int_t)(nsigma[i]), (Float_t)(nsigma[i] * sigma));
432 legend->AddEntry(lineMinusSigma, c, "l");
437 TLine* line = new TLine(median, 0, median, maxY);
438 fListOfObjectsToBeDeleted->Add(line);
439 line->SetLineColor(kBlue);
440 line->SetLineWidth(2);
441 line->SetLineStyle(1);
443 sprintf(c, "Median: %f", median);
444 legend->AddEntry(line, c, "l");
446 for (Int_t i = 0; i < nsigma.GetNoElements(); i++) {
447 TLine* linePlusSigma = new TLine(median + nsigma[i] * sigma, 0, median + nsigma[i]*sigma, maxY);
448 fListOfObjectsToBeDeleted->Add(linePlusSigma);
449 linePlusSigma->SetLineColor(kBlue);
450 linePlusSigma->SetLineStyle(2 + i);
451 linePlusSigma->Draw();
452 TLine* lineMinusSigma = new TLine(median - nsigma[i] * sigma, 0, median - nsigma[i]*sigma, maxY);
453 fListOfObjectsToBeDeleted->Add(lineMinusSigma);
454 lineMinusSigma->SetLineColor(kBlue);
455 lineMinusSigma->SetLineStyle(2 + i);
456 lineMinusSigma->Draw();
457 sprintf(c, "%i #sigma = %f",(Int_t)(nsigma[i]), (Float_t)(nsigma[i] * sigma));
458 legend->AddEntry(lineMinusSigma, c, "l");
464 Double_t ltm = GetLTM(entries, values, <mRms, ltmFraction);
465 TLine* line = new TLine(ltm, 0, ltm, maxY);
466 fListOfObjectsToBeDeleted->Add(line);
467 line->SetLineColor(kGreen+2);
468 line->SetLineWidth(2);
469 line->SetLineStyle(1);
471 sprintf(c, "LTM: %f", ltm);
472 legend->AddEntry(line, c, "l");
474 for (Int_t i = 0; i < nsigma.GetNoElements(); i++) {
475 TLine* linePlusSigma = new TLine(ltm + nsigma[i] * ltmRms, 0, ltm + nsigma[i] * ltmRms, maxY);
476 fListOfObjectsToBeDeleted->Add(linePlusSigma);
477 linePlusSigma->SetLineColor(kGreen+2);
478 linePlusSigma->SetLineStyle(2+i);
479 linePlusSigma->Draw();
481 TLine* lineMinusSigma = new TLine(ltm - nsigma[i] * ltmRms, 0, ltm - nsigma[i] * ltmRms, maxY);
482 fListOfObjectsToBeDeleted->Add(lineMinusSigma);
483 lineMinusSigma->SetLineColor(kGreen+2);
484 lineMinusSigma->SetLineStyle(2+i);
485 lineMinusSigma->Draw();
486 sprintf(c, "%i #sigma = %f", (Int_t)(nsigma[i]), (Float_t)(nsigma[i] * ltmRms));
487 legend->AddEntry(lineMinusSigma, c, "l");
490 if (!plotMean && !plotMedian && !plotLTM) return -1;
492 gStyle->SetOptStat(oldOptStat);
497 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 {
499 // 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
500 // The data of the distribution Begin_Latex f(x, #mu, #sigma) End_Latex are given in 'array', 'n' specifies the length of the array
501 // '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
502 // 'nbins': number of bins, 'binLow': first bin, 'binUp': last bin
503 // sigmaMax: up to which sigma around the mean/median/LTM the histogram is generated (in units of sigma, Begin_Latex t #sigma End_Latex)
504 // sigmaStep: the binsize of the generated histogram
506 // 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 }
510 // Creates a histogram, where you can see, how much of the data are inside sigma-intervals
511 // around the mean/median/LTM
512 // with drawCommand, sector and cuts you specify your input data, see EasyDraw
513 // sigmaMax: up to which sigma around the mean/median/LTM the histogram is generated (in units of sigma)
514 // sigmaStep: the binsize of the generated histogram
515 // plotMean/plotMedian/plotLTM: specifies where to put the center
517 if (sector >= 0 && sector < 72) {
519 sprintf(sectorChr, "%i", sector);
520 return SigmaCut(drawCommand, sectorChr, cuts, sigmaMax, plotMean, plotMedian, plotLTM, pm, sigmas, sigmaStep);
522 Error("SigmaCut","The TPC contains only sectors between 0 and 71.");
527 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 {
529 // Creates a histogram, where you can see, how much of the data are inside sigma-intervals
530 // around the mean/median/LTM
531 // with drawCommand, sector and cuts you specify your input data, see EasyDraw
532 // sigmaMax: up to which sigma around the mean/median/LTM the histogram is generated (in units of sigma)
533 // sigmaStep: the binsize of the generated histogram
534 // plotMean/plotMedian/plotLTM: specifies where to put the center
537 Double_t ltmFraction = 0.8;
539 TString drawStr(drawCommand);
540 drawStr += " >> tempHist";
542 Int_t entries = EasyDraw1D(drawStr.Data(), sector, cuts, "goff");
543 TH1F *htemp = (TH1F*)gDirectory->Get("tempHist");
544 // FIXME is this histogram deleted automatically?
545 Double_t *values = fTree->GetV1(); // value is the array containing 'entries' numbers
547 Double_t mean = TMath::Mean(entries, values);
548 Double_t median = TMath::Median(entries, values);
549 Double_t sigma = TMath::RMS(entries, values);
551 TLegend * legend = new TLegend(.7,.7, .99, .99, "Cumulative");
552 fListOfObjectsToBeDeleted->Add(legend);
553 TH1F *cutHistoMean = 0;
554 TH1F *cutHistoMedian = 0;
555 TH1F *cutHistoLTM = 0;
557 TObjArray *sigmasTokens = TString(sigmas).Tokenize(";");
558 TVectorF nsigma(sigmasTokens->GetEntriesFast());
559 for (Int_t i = 0; i < sigmasTokens->GetEntriesFast(); i++) {
560 TString str(((TObjString*)sigmasTokens->At(i))->GetString());
561 Double_t sig = (str.IsFloat()) ? str.Atof() : 0;
566 cutHistoMean = AliTPCCalibViewer::SigmaCut(htemp, mean, sigma, sigmaMax, sigmaStep, pm);
568 fListOfObjectsToBeDeleted->Add(cutHistoMean);
569 cutHistoMean->SetLineColor(kRed);
570 legend->AddEntry(cutHistoMean, "Mean", "l");
571 cutHistoMean->SetTitle(Form("%s, cumulative; Multiples of #sigma; Fraction of included data", htemp->GetTitle()));
572 cutHistoMean->Draw();
573 DrawLines(cutHistoMean, nsigma, legend, kRed, pm);
574 } // if (cutHistoMean)
578 cutHistoMedian = AliTPCCalibViewer::SigmaCut(htemp, median, sigma, sigmaMax, sigmaStep, pm);
579 if (cutHistoMedian) {
580 fListOfObjectsToBeDeleted->Add(cutHistoMedian);
581 cutHistoMedian->SetLineColor(kBlue);
582 legend->AddEntry(cutHistoMedian, "Median", "l");
583 cutHistoMedian->SetTitle(Form("%s, cumulative; Multiples of #sigma; Fraction of included data", htemp->GetTitle()));
584 if (plotMean && cutHistoMean) cutHistoMedian->Draw("same");
585 else cutHistoMedian->Draw();
586 DrawLines(cutHistoMedian, nsigma, legend, kBlue, pm);
587 } // if (cutHistoMedian)
591 Double_t ltm = GetLTM(entries, values, <mRms, ltmFraction);
592 cutHistoLTM = AliTPCCalibViewer::SigmaCut(htemp, ltm, ltmRms, sigmaMax, sigmaStep, pm);
594 fListOfObjectsToBeDeleted->Add(cutHistoLTM);
595 cutHistoLTM->SetLineColor(kGreen+2);
596 legend->AddEntry(cutHistoLTM, "LTM", "l");
597 cutHistoLTM->SetTitle(Form("%s, cumulative; Multiples of #sigma; Fraction of included data", htemp->GetTitle()));
598 if (plotMean && cutHistoMean || plotMedian && cutHistoMedian) cutHistoLTM->Draw("same");
599 else cutHistoLTM->Draw();
600 DrawLines(cutHistoLTM, nsigma, legend, kGreen+2, pm);
603 if (!plotMean && !plotMedian && !plotLTM) return -1;
608 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 {
610 // Creates a histogram, where you can see, how much of the data are inside sigma-intervals
611 // around the mean/median/LTM
612 // with drawCommand, sector and cuts you specify your input data, see EasyDraw
613 // sigmaMax: up to which sigma around the mean/median/LTM the histogram is generated (in units of sigma)
614 // sigmaStep: the binsize of the generated histogram
615 // plotMean/plotMedian/plotLTM: specifies where to put the center
618 // Double_t ltmFraction = 0.8; //unused
619 // avoid compiler warnings:
622 sigmaStep = sigmaStep;
624 TString drawStr(drawCommand);
625 drawStr += " >> tempHist";
627 Int_t entries = EasyDraw1D(drawStr.Data(), sector, cuts, "goff");
628 TH1F *htemp = (TH1F*)gDirectory->Get("tempHist");
629 TGraph *cutGraphMean = 0;
630 // TGraph *cutGraphMedian = 0;
631 // TGraph *cutGraphLTM = 0;
632 Double_t *values = fTree->GetV1(); // value is the array containing 'entries' numbers
633 Int_t *index = new Int_t[entries];
634 Float_t *xarray = new Float_t[entries];
635 Float_t *yarray = new Float_t[entries];
636 TMath::Sort(entries, values, index, kFALSE);
638 Double_t mean = TMath::Mean(entries, values);
639 // Double_t median = TMath::Median(entries, values);
640 Double_t sigma = TMath::RMS(entries, values);
642 TLegend * legend = new TLegend(.7,.7, .99, .99, "Cumulative");
643 fListOfObjectsToBeDeleted->Add(legend);
645 // parse sigmas string
646 TObjArray *sigmasTokens = TString(sigmas).Tokenize(";");
647 TVectorF nsigma(sigmasTokens->GetEntriesFast());
648 for (Int_t i = 0; i < sigmasTokens->GetEntriesFast(); i++) {
649 TString str(((TObjString*)sigmasTokens->At(i))->GetString());
650 Double_t sig = (str.IsFloat()) ? str.Atof() : 0;
655 for (Int_t i = 0; i < entries; i++) {
656 xarray[i] = TMath::Abs(values[index[i]] - mean) / sigma;
657 yarray[i] = float(i) / float(entries);
659 cutGraphMean = new TGraph(entries, xarray, yarray);
661 fListOfObjectsToBeDeleted->Add(cutGraphMean);
662 cutGraphMean->SetLineColor(kRed);
663 legend->AddEntry(cutGraphMean, "Mean", "l");
664 cutGraphMean->SetTitle(Form("%s, Cumulative; Multiples of #sigma; Fraction of included data", htemp->GetTitle()));
665 cutGraphMean->Draw("alu");
666 DrawLines(cutGraphMean, nsigma, legend, kRed, kTRUE);
671 cutHistoMedian = AliTPCCalibViewer::SigmaCut(htemp, median, sigma, sigmaMax, sigmaStep, pm);
672 if (cutHistoMedian) {
673 fListOfObjectsToBeDeleted->Add(cutHistoMedian);
674 cutHistoMedian->SetLineColor(kBlue);
675 legend->AddEntry(cutHistoMedian, "Median", "l");
676 cutHistoMedian->SetTitle(Form("%s, cumulative; Multiples of #sigma; Fraction of included data", htemp->GetTitle()));
677 if (plotMean && cutHistoMean) cutHistoMedian->Draw("same");
678 else cutHistoMedian->Draw();
679 DrawLines(cutHistoMedian, nsigma, legend, kBlue, pm);
680 } // if (cutHistoMedian)
684 Double_t ltm = GetLTM(entries, values, <mRms, ltmFraction);
685 cutHistoLTM = AliTPCCalibViewer::SigmaCut(htemp, ltm, ltmRms, sigmaMax, sigmaStep, pm);
687 fListOfObjectsToBeDeleted->Add(cutHistoLTM);
688 cutHistoLTM->SetLineColor(kGreen+2);
689 legend->AddEntry(cutHistoLTM, "LTM", "l");
690 cutHistoLTM->SetTitle(Form("%s, cumulative; Multiples of #sigma; Fraction of included data", htemp->GetTitle()));
691 if (plotMean && cutHistoMean || plotMedian && cutHistoMedian) cutHistoLTM->Draw("same");
692 else cutHistoLTM->Draw();
693 DrawLines(cutHistoLTM, nsigma, legend, kGreen+2, pm);
696 if (!plotMean && !plotMedian && !plotLTM) return -1;
704 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 {
706 // 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"
707 // "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
708 // sigmaMax: up to which sigma around the mean/median/LTM you want to integrate
709 // if "igma == 0" and "sigmaMax == 0" the whole histogram is integrated
710 // "sigmaStep": the binsize of the generated histogram, -1 means, that the maximal reasonable stepsize is used
711 // The actual work is done on the array.
713 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 }
716 if (sector >= 0 && sector < 72) {
718 sprintf(sectorChr, "%i", sector);
719 return Integrate(drawCommand, sectorChr, cuts, sigmaMax, plotMean, plotMedian, plotLTM, sigmas, sigmaStep);
721 Error("Integrate","The TPC contains only sectors between 0 and 71.");
727 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 {
729 // 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"
730 // "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
731 // sigmaMax: up to which sigma around the mean/median/LTM you want to integrate
732 // if "igma == 0" and "sigmaMax == 0" the whole histogram is integrated
733 // "sigmaStep": the binsize of the generated histogram, -1 means, that the maximal reasonable stepsize is used
734 // The actual work is done on the array.
736 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 }
740 Double_t ltmFraction = 0.8;
742 TString drawStr(drawCommand);
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 TObjArray *sigmasTokens = TString(sigmas).Tokenize(";");
755 TVectorF nsigma(sigmasTokens->GetEntriesFast());
756 for (Int_t i = 0; i < sigmasTokens->GetEntriesFast(); i++) {
757 TString str(((TObjString*)sigmasTokens->At(i))->GetString());
758 Double_t sig = (str.IsFloat()) ? str.Atof() : 0;
762 TLegend * legend = new TLegend(.7,.7, .99, .99, "Integrated histogram");
763 fListOfObjectsToBeDeleted->Add(legend);
764 TH1F *integralHistoMean = 0;
765 TH1F *integralHistoMedian = 0;
766 TH1F *integralHistoLTM = 0;
769 integralHistoMean = AliTPCCalibViewer::Integrate(htemp, mean, sigma, sigmaMax, sigmaStep);
770 if (integralHistoMean) {
771 fListOfObjectsToBeDeleted->Add(integralHistoMean);
772 integralHistoMean->SetLineColor(kRed);
773 legend->AddEntry(integralHistoMean, "Mean", "l");
774 integralHistoMean->SetTitle(Form("%s, integrated; Multiples of #sigma; Fraction of included data", htemp->GetTitle()));
775 integralHistoMean->Draw();
776 DrawLines(integralHistoMean, nsigma, legend, kRed, kTRUE);
780 integralHistoMedian = AliTPCCalibViewer::Integrate(htemp, median, sigma, sigmaMax, sigmaStep);
781 if (integralHistoMedian) {
782 fListOfObjectsToBeDeleted->Add(integralHistoMedian);
783 integralHistoMedian->SetLineColor(kBlue);
784 legend->AddEntry(integralHistoMedian, "Median", "l");
785 integralHistoMedian->SetTitle(Form("%s, integrated; Multiples of #sigma; Fraction of included data", htemp->GetTitle()));
786 if (plotMean && integralHistoMean) integralHistoMedian->Draw("same");
787 else integralHistoMedian->Draw();
788 DrawLines(integralHistoMedian, nsigma, legend, kBlue, kTRUE);
793 Double_t ltm = GetLTM(entries, values, <mRms, ltmFraction);
794 integralHistoLTM = AliTPCCalibViewer::Integrate(htemp, ltm, ltmRms, sigmaMax, sigmaStep);
795 if (integralHistoLTM) {
796 fListOfObjectsToBeDeleted->Add(integralHistoLTM);
797 integralHistoLTM->SetLineColor(kGreen+2);
798 legend->AddEntry(integralHistoLTM, "LTM", "l");
799 integralHistoLTM->SetTitle(Form("%s, integrated; Multiples of #sigma; Fraction of included data", htemp->GetTitle()));
800 if (plotMean && integralHistoMean || plotMedian && integralHistoMedian) integralHistoLTM->Draw("same");
801 else integralHistoLTM->Draw();
802 DrawLines(integralHistoLTM, nsigma, legend, kGreen+2, kTRUE);
805 if (!plotMean && !plotMedian && !plotLTM) return -1;
811 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 {
813 // 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"
814 // "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
815 // sigmaMax: up to which sigma around the mean/median/LTM you want to integrate
816 // if "igma == 0" and "sigmaMax == 0" the whole histogram is integrated
817 // "sigmaStep": the binsize of the generated histogram, -1 means, that the maximal reasonable stepsize is used
818 // The actual work is done on the array.
820 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 }
824 Double_t ltmFraction = 0.8;
825 // avoid compiler warnings:
827 sigmaStep = sigmaStep;
829 TString drawStr(drawCommand);
830 drawStr += " >> tempHist";
832 Int_t entries = EasyDraw1D(drawStr.Data(), sector, cuts, "goff");
833 TH1F *htemp = (TH1F*)gDirectory->Get("tempHist");
834 TGraph *integralGraphMean = 0;
835 TGraph *integralGraphMedian = 0;
836 TGraph *integralGraphLTM = 0;
837 Double_t *values = fTree->GetV1(); // value is the array containing 'entries' numbers
838 Int_t *index = new Int_t[entries];
839 Float_t *xarray = new Float_t[entries];
840 Float_t *yarray = new Float_t[entries];
841 TMath::Sort(entries, values, index, kFALSE);
843 Double_t mean = TMath::Mean(entries, values);
844 Double_t median = TMath::Median(entries, values);
845 Double_t sigma = TMath::RMS(entries, values);
847 // parse sigmas string
848 TObjArray *sigmasTokens = TString(sigmas).Tokenize(";");
849 TVectorF nsigma(sigmasTokens->GetEntriesFast());
850 for (Int_t i = 0; i < sigmasTokens->GetEntriesFast(); i++) {
851 TString str(((TObjString*)sigmasTokens->At(i))->GetString());
852 Double_t sig = (str.IsFloat()) ? str.Atof() : 0;
856 TLegend * legend = new TLegend(.7,.7, .99, .99, "Integrated histogram");
857 fListOfObjectsToBeDeleted->Add(legend);
860 for (Int_t i = 0; i < entries; i++) {
861 xarray[i] = (values[index[i]] - mean) / sigma;
862 yarray[i] = float(i) / float(entries);
864 integralGraphMean = new TGraph(entries, xarray, yarray);
865 if (integralGraphMean) {
866 fListOfObjectsToBeDeleted->Add(integralGraphMean);
867 integralGraphMean->SetLineColor(kRed);
868 legend->AddEntry(integralGraphMean, "Mean", "l");
869 integralGraphMean->SetTitle(Form("%s, integrated; Multiples of #sigma; Fraction of included data", htemp->GetTitle()));
870 integralGraphMean->Draw("alu");
871 DrawLines(integralGraphMean, nsigma, legend, kRed, kTRUE);
875 for (Int_t i = 0; i < entries; i++) {
876 xarray[i] = (values[index[i]] - median) / sigma;
877 yarray[i] = float(i) / float(entries);
879 integralGraphMedian = new TGraph(entries, xarray, yarray);
880 if (integralGraphMedian) {
881 fListOfObjectsToBeDeleted->Add(integralGraphMedian);
882 integralGraphMedian->SetLineColor(kBlue);
883 legend->AddEntry(integralGraphMedian, "Median", "l");
884 integralGraphMedian->SetTitle(Form("%s, integrated; Multiples of #sigma; Fraction of included data", htemp->GetTitle()));
885 if (plotMean && integralGraphMean) integralGraphMedian->Draw("samelu");
886 else integralGraphMedian->Draw("alu");
887 DrawLines(integralGraphMedian, nsigma, legend, kBlue, kTRUE);
892 Double_t ltm = GetLTM(entries, values, <mRms, ltmFraction);
893 for (Int_t i = 0; i < entries; i++) {
894 xarray[i] = (values[index[i]] - ltm) / ltmRms;
895 yarray[i] = float(i) / float(entries);
897 integralGraphLTM = new TGraph(entries, xarray, yarray);
898 if (integralGraphLTM) {
899 fListOfObjectsToBeDeleted->Add(integralGraphLTM);
900 integralGraphLTM->SetLineColor(kGreen+2);
901 legend->AddEntry(integralGraphLTM, "LTM", "l");
902 integralGraphLTM->SetTitle(Form("%s, integrated; Multiples of #sigma; Fraction of included data", htemp->GetTitle()));
903 if (plotMean && integralGraphMean || plotMedian && integralGraphMedian) integralGraphLTM->Draw("samelu");
904 else integralGraphLTM->Draw("alu");
905 DrawLines(integralGraphLTM, nsigma, legend, kGreen+2, kTRUE);
908 if (!plotMean && !plotMedian && !plotLTM) return -1;
914 void AliTPCCalibViewer::DrawLines(TH1F *histogram, TVectorF nsigma, TLegend *legend, Int_t color, Bool_t pm) const {
916 // Private function for SigmaCut(...) and Integrate(...)
917 // Draws lines into the given histogram, specified by "nsigma", the lines are addeed to the legend
920 // start to draw the lines, loop over requested sigmas
922 for (Int_t i = 0; i < nsigma.GetNoElements(); i++) {
924 Int_t bin = histogram->GetXaxis()->FindBin(nsigma[i]);
925 TLine* lineUp = new TLine(nsigma[i], 0, nsigma[i], histogram->GetBinContent(bin));
926 fListOfObjectsToBeDeleted->Add(lineUp);
927 lineUp->SetLineColor(color);
928 lineUp->SetLineStyle(2 + i);
930 TLine* lineLeft = new TLine(nsigma[i], histogram->GetBinContent(bin), 0, histogram->GetBinContent(bin));
931 fListOfObjectsToBeDeleted->Add(lineLeft);
932 lineLeft->SetLineColor(color);
933 lineLeft->SetLineStyle(2 + i);
935 sprintf(c, "Fraction(%f #sigma) = %f",nsigma[i], histogram->GetBinContent(bin));
936 legend->AddEntry(lineLeft, c, "l");
939 Int_t bin = histogram->GetXaxis()->FindBin(nsigma[i]);
940 TLine* lineUp1 = new TLine(nsigma[i], 0, nsigma[i], histogram->GetBinContent(bin));
941 fListOfObjectsToBeDeleted->Add(lineUp1);
942 lineUp1->SetLineColor(color);
943 lineUp1->SetLineStyle(2 + i);
945 TLine* lineLeft1 = new TLine(nsigma[i], histogram->GetBinContent(bin), histogram->GetBinLowEdge(0)+histogram->GetBinWidth(0), histogram->GetBinContent(bin));
946 fListOfObjectsToBeDeleted->Add(lineLeft1);
947 lineLeft1->SetLineColor(color);
948 lineLeft1->SetLineStyle(2 + i);
950 sprintf(c, "Fraction(+%f #sigma) = %f",nsigma[i], histogram->GetBinContent(bin));
951 legend->AddEntry(lineLeft1, c, "l");
952 bin = histogram->GetXaxis()->FindBin(-nsigma[i]);
953 TLine* lineUp2 = new TLine(-nsigma[i], 0, -nsigma[i], histogram->GetBinContent(bin));
954 fListOfObjectsToBeDeleted->Add(lineUp2);
955 lineUp2->SetLineColor(color);
956 lineUp2->SetLineStyle(2 + i);
958 TLine* lineLeft2 = new TLine(-nsigma[i], histogram->GetBinContent(bin), histogram->GetBinLowEdge(0)+histogram->GetBinWidth(0), histogram->GetBinContent(bin));
959 fListOfObjectsToBeDeleted->Add(lineLeft2);
960 lineLeft2->SetLineColor(color);
961 lineLeft2->SetLineStyle(2 + i);
963 sprintf(c, "Fraction(-%f #sigma) = %f",nsigma[i], histogram->GetBinContent(bin));
964 legend->AddEntry(lineLeft2, c, "l");
966 } // for (Int_t i = 0; i < nsigma.GetNoElements(); i++)
970 void AliTPCCalibViewer::DrawLines(TGraph *graph, TVectorF nsigma, TLegend *legend, Int_t color, Bool_t pm) const {
972 // Private function for SigmaCut(...) and Integrate(...)
973 // Draws lines into the given histogram, specified by "nsigma", the lines are addeed to the legend
976 // start to draw the lines, loop over requested sigmas
978 for (Int_t i = 0; i < nsigma.GetNoElements(); i++) {
980 TLine* lineUp = new TLine(nsigma[i], 0, nsigma[i], graph->Eval(nsigma[i]));
981 fListOfObjectsToBeDeleted->Add(lineUp);
982 lineUp->SetLineColor(color);
983 lineUp->SetLineStyle(2 + i);
985 TLine* lineLeft = new TLine(nsigma[i], graph->Eval(nsigma[i]), 0, graph->Eval(nsigma[i]));
986 fListOfObjectsToBeDeleted->Add(lineLeft);
987 lineLeft->SetLineColor(color);
988 lineLeft->SetLineStyle(2 + i);
990 sprintf(c, "Fraction(%f #sigma) = %f",nsigma[i], graph->Eval(nsigma[i]));
991 legend->AddEntry(lineLeft, c, "l");
994 TLine* lineUp1 = new TLine(nsigma[i], 0, nsigma[i], graph->Eval(nsigma[i]));
995 fListOfObjectsToBeDeleted->Add(lineUp1);
996 lineUp1->SetLineColor(color);
997 lineUp1->SetLineStyle(2 + i);
999 TLine* lineLeft1 = new TLine(nsigma[i], graph->Eval(nsigma[i]), graph->GetHistogram()->GetXaxis()->GetBinLowEdge(0), graph->Eval(nsigma[i]));
1000 fListOfObjectsToBeDeleted->Add(lineLeft1);
1001 lineLeft1->SetLineColor(color);
1002 lineLeft1->SetLineStyle(2 + i);
1004 sprintf(c, "Fraction(+%f #sigma) = %f",nsigma[i], graph->Eval(nsigma[i]));
1005 legend->AddEntry(lineLeft1, c, "l");
1006 TLine* lineUp2 = new TLine(-nsigma[i], 0, -nsigma[i], graph->Eval(-nsigma[i]));
1007 fListOfObjectsToBeDeleted->Add(lineUp2);
1008 lineUp2->SetLineColor(color);
1009 lineUp2->SetLineStyle(2 + i);
1011 TLine* lineLeft2 = new TLine(-nsigma[i], graph->Eval(-nsigma[i]), graph->GetHistogram()->GetXaxis()->GetBinLowEdge(0), graph->Eval(-nsigma[i]));
1012 fListOfObjectsToBeDeleted->Add(lineLeft2);
1013 lineLeft2->SetLineColor(color);
1014 lineLeft2->SetLineStyle(2 + i);
1016 sprintf(c, "Fraction(-%f #sigma) = %f",nsigma[i], graph->Eval(-nsigma[i]));
1017 legend->AddEntry(lineLeft2, c, "l");
1019 } // for (Int_t i = 0; i < nsigma.GetNoElements(); i++)
1031 Int_t AliTPCCalibViewer::GetBin(Float_t value, Int_t nbins, Double_t binLow, Double_t binUp){
1032 // Returns the 'bin' for 'value'
1033 // The interval between 'binLow' and 'binUp' is divided into 'nbins' equidistant bins
1034 // avoid index out of bounds error: 'if (bin < binLow) bin = binLow' and vice versa
1036 GetBin(value) = #frac{nbins - 1}{binUp - binLow} #upoint (value - binLow) +1
1040 Int_t bin = TMath::Nint( (Float_t)(value - binLow) / (Float_t)(binUp - binLow) * (nbins-1) ) + 1;
1041 // avoid index out of bounds:
1042 if (value < binLow) bin = 0;
1043 if (value > binUp) bin = nbins + 1;
1049 Double_t AliTPCCalibViewer::GetLTM(Int_t n, Double_t *array, Double_t *sigma, Double_t fraction){
1051 // returns the LTM and sigma
1053 Double_t *ddata = new Double_t[n];
1054 Double_t mean = 0, lsigma = 0;
1056 for (UInt_t i = 0; i < (UInt_t)n; i++) {
1057 ddata[nPoints]= array[nPoints];
1060 Int_t hh = TMath::Min(TMath::Nint(fraction * nPoints), Int_t(n));
1061 AliMathBase::EvaluateUni(nPoints, ddata, mean, lsigma, hh);
1062 if (sigma) *sigma = lsigma;
1068 TH1F* AliTPCCalibViewer::SigmaCut(TH1F *histogram, Float_t mean, Float_t sigma, Float_t sigmaMax, Float_t sigmaStep, Bool_t pm) {
1070 // 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
1071 // The data of the distribution Begin_Latex f(x, #mu, #sigma) End_Latex are given in 'histogram'
1072 // '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
1073 // sigmaMax: up to which sigma around the mean/median/LTM the histogram is generated (in units of sigma, Begin_Latex t #sigma End_Latex)
1074 // sigmaStep: the binsize of the generated histogram, -1 means, that the maximal reasonable stepsize is used
1075 // pm: Decide weather Begin_Latex t > 0 End_Latex (first case) or Begin_Latex t End_Latex arbitrary (secound case)
1076 // The actual work is done on the array.
1078 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
1080 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 }
1085 Float_t sigma = 1.5;
1086 Float_t sigmaMax = 4;
1087 gROOT->SetStyle("Plain");
1088 TH1F *distribution = new TH1F("Distribution", "Distribution f(x, #mu, #sigma)", 1000,-5,5);
1090 for (Int_t i = 0; i <50000;i++) distribution->Fill(rand.Gaus(mean, sigma));
1091 Float_t *ar = distribution->GetArray();
1093 TCanvas* macro_example_canvas = new TCanvas("macro_example_canvas", "", 350, 350);
1094 macro_example_canvas->Divide(0,3);
1095 TVirtualPad *pad1 = macro_example_canvas->cd(1);
1098 distribution->Draw();
1099 TVirtualPad *pad2 = macro_example_canvas->cd(2);
1103 TH1F *shist = AliTPCCalibViewer::SigmaCut(distribution, mean, sigma, sigmaMax);
1104 shist->SetNameTitle("Cumulative","Cumulative S(t, #mu, #sigma)");
1106 TVirtualPad *pad3 = macro_example_canvas->cd(3);
1109 TH1F *shistPM = AliTPCCalibViewer::SigmaCut(distribution, mean, sigma, sigmaMax, -1, kTRUE);
1111 return macro_example_canvas;
1116 Float_t *array = histogram->GetArray();
1117 Int_t nbins = histogram->GetXaxis()->GetNbins();
1118 Float_t binLow = histogram->GetXaxis()->GetXmin();
1119 Float_t binUp = histogram->GetXaxis()->GetXmax();
1120 return AliTPCCalibViewer::SigmaCut(nbins, array, mean, sigma, nbins, binLow, binUp, sigmaMax, sigmaStep, pm);
1125 TH1F* AliTPCCalibViewer::SigmaCut(Int_t n, 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){
1127 // 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
1128 // The data of the distribution Begin_Latex f(x, #mu, #sigma) End_Latex are given in 'array', 'n' specifies the length of the array
1129 // '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
1130 // 'nbins': number of bins, 'binLow': first bin, 'binUp': last bin
1131 // sigmaMax: up to which sigma around the mean/median/LTM the histogram is generated (in units of sigma, Begin_Latex t #sigma End_Latex)
1132 // sigmaStep: the binsize of the generated histogram
1133 // Here the actual work is done.
1135 if (sigma == 0) return 0;
1136 Float_t binWidth = (binUp-binLow)/(nbins - 1);
1137 if (sigmaStep <= 0) sigmaStep = binWidth;
1138 Int_t kbins = (Int_t)(sigmaMax * sigma / sigmaStep) + 1; // + 1 due to overflow bin in histograms
1139 if (pm) kbins = 2 * (Int_t)(sigmaMax * sigma / sigmaStep) + 1;
1140 Float_t kbinLow = !pm ? 0 : -sigmaMax;
1141 Float_t kbinUp = sigmaMax;
1142 TH1F *hist = new TH1F("sigmaCutHisto","Cumulative; Multiples of #sigma; Fraction of included data", kbins, kbinLow, kbinUp);
1143 hist->SetDirectory(0);
1146 // calculate normalization
1147 Double_t normalization = 0;
1148 for (Int_t i = 0; i <= n; i++) {
1149 normalization += array[i];
1152 // given units: units from given histogram
1153 // sigma units: in units of sigma
1154 // iDelta: integrate in interval (mean +- iDelta), given units
1155 // x: ofset from mean for integration, given units
1158 // printf("nbins: %i, binLow: %f, binUp: %f \n", nbins, binLow, binUp);
1160 for (Float_t iDelta = 0; iDelta <= sigmaMax * sigma; iDelta += sigmaStep) {
1162 Double_t valueP = array[GetBin(mean, nbins, binLow, binUp)];
1163 Double_t valueM = array[GetBin(mean-binWidth, nbins, binLow, binUp)];
1164 // add bin of mean value only once to the histogram
1165 // printf("++ adding bins: ");
1166 for (Float_t x = binWidth; x <= iDelta; x += binWidth) {
1167 valueP += (mean + x <= binUp) ? array[GetBin(mean + x, nbins, binLow, binUp)] : 0;
1168 valueM += (mean-binWidth - x >= binLow) ? array[GetBin(mean-binWidth - x, nbins, binLow, binUp)] : 0;
1169 // printf("%i, ", GetBin(mean + x, nbins, binLow, binUp));
1172 if (valueP / normalization > 100) printf("+++ Error, value to big: %f, normalization with %f will fail +++ \n", valueP, normalization);
1173 if (valueP / normalization > 100) return hist;
1174 if (valueM / normalization > 100) printf("+++ Error, value to big: %f, normalization with %f will fail +++ \n", valueM, normalization);
1175 if (valueM / normalization > 100) return hist;
1176 valueP = (valueP / normalization);
1177 valueM = (valueM / normalization);
1179 Int_t bin = GetBin(iDelta/sigma, kbins, kbinLow, kbinUp);
1180 hist->SetBinContent(bin, valueP);
1181 bin = GetBin(-iDelta/sigma, kbins, kbinLow, kbinUp);
1182 hist->SetBinContent(bin, valueM);
1185 Int_t bin = GetBin(iDelta/sigma, kbins, kbinLow, kbinUp);
1186 hist->SetBinContent(bin, valueP + valueM);
1187 // printf(" first integration bin: %i, last integration bin in + direction: %i \n", GetBin(mean+binWidth, nbins, binLow, binUp), GetBin(iDelta, nbins, binLow, binUp));
1188 // printf(" first integration bin: %i, last integration bin in - direction: %i \n", GetBin(mean+binWidth, nbins, binLow, binUp), GetBin(-iDelta, nbins, binLow, binUp));
1189 // printf(" value: %f, normalization: %f, iDelta: %f, Bin: %i \n", valueP+valueM, normalization, iDelta, bin);
1192 //hist->SetMaximum(0.7);
1193 if (!pm) hist->SetMaximum(1.2);
1198 TH1F* AliTPCCalibViewer::SigmaCut(Int_t n, Double_t *array, Double_t mean, Double_t sigma, Int_t nbins, Double_t *xbins, Double_t sigmaMax){
1200 // SigmaCut for variable binsize
1201 // NOT YET IMPLEMENTED !!!
1203 printf("SigmaCut with variable binsize, Not yet implemented\n");
1204 // avoid compiler warnings:
1217 TH1F* AliTPCCalibViewer::Integrate(TH1F *histogram, Float_t mean, Float_t sigma, Float_t sigmaMax, Float_t sigmaStep){
1219 // 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"
1220 // "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
1221 // sigmaMax: up to which sigma around the mean/median/LTM you want to integrate
1222 // if "igma == 0" and "sigmaMax == 0" the whole histogram is integrated
1223 // "sigmaStep": the binsize of the generated histogram, -1 means, that the maximal reasonable stepsize is used
1224 // The actual work is done on the array.
1226 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 }
1231 Float_t sigma = 1.5;
1232 Float_t sigmaMax = 4;
1233 gROOT->SetStyle("Plain");
1234 TH1F *distribution = new TH1F("Distribution", "Distribution f(x, #mu, #sigma)", 1000,-5,5);
1236 for (Int_t i = 0; i <50000;i++) distribution->Fill(rand.Gaus(mean, sigma));
1237 Float_t *ar = distribution->GetArray();
1239 TCanvas* macro_example_canvas = new TCanvas("macro_example_canvas", "", 350, 350);
1240 macro_example_canvas->Divide(0,2);
1241 TVirtualPad *pad1 = macro_example_canvas->cd(1);
1244 distribution->Draw();
1245 TVirtualPad *pad2 = macro_example_canvas->cd(2);
1248 TH1F *shist = AliTPCCalibViewer::Integrate(distribution, mean, sigma, sigmaMax);
1249 shist->SetNameTitle("Cumulative","Cumulative S(t, #mu, #sigma)");
1252 return macro_example_canvas;
1258 Float_t *array = histogram->GetArray();
1259 Int_t nbins = histogram->GetXaxis()->GetNbins();
1260 Float_t binLow = histogram->GetXaxis()->GetXmin();
1261 Float_t binUp = histogram->GetXaxis()->GetXmax();
1262 return AliTPCCalibViewer::Integrate(nbins, array, nbins, binLow, binUp, mean, sigma, sigmaMax, sigmaStep);
1266 TH1F* AliTPCCalibViewer::Integrate(Int_t n, Float_t *array, Int_t nbins, Float_t binLow, Float_t binUp, Float_t mean, Float_t sigma, Float_t sigmaMax, Float_t sigmaStep){
1267 // 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"
1268 // "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
1269 // sigmaMax: up to which sigma around the mean/median/LTM you want to integrate
1270 // if "igma == 0" and "sigmaMax == 0" the whole histogram is integrated
1271 // "sigmaStep": the binsize of the generated histogram, -1 means, that the maximal reasonable stepsize is used
1272 // Here the actual work is done.
1274 Bool_t givenUnits = kTRUE;
1275 if (sigma != 0 && sigmaMax != 0) givenUnits = kFALSE;
1278 sigmaMax = (binUp - binLow) / 2.;
1281 Float_t binWidth = (binUp-binLow)/(nbins - 1);
1282 if (sigmaStep <= 0) sigmaStep = binWidth;
1283 Int_t kbins = (Int_t)(sigmaMax * sigma / sigmaStep) + 1; // + 1 due to overflow bin in histograms
1284 Float_t kbinLow = givenUnits ? binLow : -sigmaMax;
1285 Float_t kbinUp = givenUnits ? binUp : sigmaMax;
1287 if (givenUnits) hist = new TH1F("integratedHisto","Integrated Histogram; Given x; Fraction of included data", kbins, kbinLow, kbinUp);
1288 if (!givenUnits) hist = new TH1F("integratedHisto","Integrated Histogram; Multiples of #sigma; Fraction of included data", kbins, kbinLow, kbinUp);
1289 hist->SetDirectory(0);
1292 // calculate normalization
1293 // printf("calculating normalization, integrating from bin 1 to %i \n", n);
1294 Double_t normalization = 0;
1295 for (Int_t i = 1; i <= n; i++) {
1296 normalization += array[i];
1298 // printf("normalization: %f \n", normalization);
1300 // given units: units from given histogram
1301 // sigma units: in units of sigma
1302 // iDelta: integrate in interval (mean +- iDelta), given units
1303 // x: ofset from mean for integration, given units
1307 for (Float_t iDelta = mean - sigmaMax * sigma; iDelta <= mean + sigmaMax * sigma; iDelta += sigmaStep) {
1310 for (Float_t x = mean - sigmaMax * sigma; x <= iDelta; x += binWidth) {
1311 value += (x <= binUp && x >= binLow) ? array[GetBin(x, nbins, binLow, binUp)] : 0;
1313 if (value / normalization > 100) printf("+++ Error, value to big: %f, normalization with %f will fail +++ \n", value, normalization);
1314 if (value / normalization > 100) return hist;
1315 Int_t bin = GetBin(iDelta/sigma, kbins, kbinLow, kbinUp);
1316 // printf("first integration bin: %i, last integration bin: %i \n", GetBin(mean - sigmaMax * sigma, nbins, binLow, binUp), GetBin(iDelta, nbins, binLow, binUp));
1317 // printf("value: %f, normalization: %f, normalized value: %f, iDelta: %f, Bin: %i \n", value, normalization, value/normalization, iDelta, bin);
1318 value = (value / normalization);
1319 hist->SetBinContent(bin, value);
1328 ////////////////////////
1329 // end of Array tools //
1330 ////////////////////////
1334 //_____________________________________________________________________________
1335 AliTPCCalPad* AliTPCCalibViewer::GetCalPad(const char* desiredData, char* cuts, char* calPadName) const {
1337 // creates a AliTPCCalPad out of the 'desiredData'
1338 // the functionality of EasyDraw1D is used
1339 // calPadName specifies the name of the created AliTPCCalPad
1340 // - this takes a while -
1342 TString drawStr(desiredData);
1343 drawStr.Append(":channel~");
1344 AliTPCCalPad * createdCalPad = new AliTPCCalPad(calPadName, calPadName);
1346 for (Int_t sec = 0; sec < 72; sec++) {
1347 entries = EasyDraw1D(drawStr.Data(), (Int_t)sec, cuts, "goff");
1348 if (entries == -1) return 0;
1349 for (Int_t i = 0; i < entries; i++)
1350 createdCalPad->GetCalROC(sec)->SetValue((UInt_t)(fTree->GetV2()[i]), (Float_t)(fTree->GetV1()[i]));
1352 return createdCalPad;
1355 //_____________________________________________________________________________
1356 AliTPCCalROC* AliTPCCalibViewer::GetCalROC(const char* desiredData, UInt_t sector, char* cuts) const {
1358 // creates a AliTPCCalROC out of the desiredData
1359 // the functionality of EasyDraw1D is used
1360 // sector specifies the sector of the created AliTPCCalROC
1362 TString drawStr(desiredData);
1363 drawStr.Append(":channel~");
1364 Int_t entries = EasyDraw1D(drawStr.Data(), (Int_t)sector, cuts, "goff");
1365 if (entries == -1) return 0;
1366 AliTPCCalROC * createdROC = new AliTPCCalROC(sector);
1367 for (Int_t i = 0; i < entries; i++)
1368 createdROC->SetValue((UInt_t)(fTree->GetV2()[i]), fTree->GetV1()[i]);
1373 TObjArray* AliTPCCalibViewer::GetListOfVariables(Bool_t printList) {
1375 // scan the tree - produces a list of available variables in the tree
1376 // printList: print the list to the screen, after the scan is done
1378 TObjArray* arr = new TObjArray();
1379 TObjString* str = 0;
1380 Int_t nentries = fTree->GetListOfBranches()->GetEntries();
1381 for (Int_t i = 0; i < nentries; i++) {
1382 str = new TObjString(fTree->GetListOfBranches()->At(i)->GetName());
1383 str->String().ReplaceAll("_Median", "");
1384 str->String().ReplaceAll("_Mean", "");
1385 str->String().ReplaceAll("_RMS", "");
1386 str->String().ReplaceAll("_LTM", "");
1387 str->String().ReplaceAll("_OutlierCutted", "");
1388 str->String().ReplaceAll(".", "");
1389 if (!arr->FindObject(str) &&
1390 !(str->String() == "channel" || str->String() == "gx" || str->String() == "gy" ||
1391 str->String() == "lx" || str->String() == "ly" || str->String() == "pad" ||
1392 str->String() == "row" || str->String() == "rpad" || str->String() == "sector" ))
1398 TIterator* iter = arr->MakeIterator();
1400 TObjString* currentStr = 0;
1401 while ( (currentStr = (TObjString*)(iter->Next())) ) {
1402 std::cout << currentStr->GetString().Data() << std::endl;
1410 TObjArray* AliTPCCalibViewer::GetListOfNormalizationVariables(Bool_t printList) const{
1412 // produces a list of available variables for normalization in the tree
1413 // printList: print the list to the screen, after the scan is done
1415 TObjArray* arr = new TObjArray();
1416 arr->Add(new TObjString("_Mean"));
1417 arr->Add(new TObjString("_Mean_OutlierCutted"));
1418 arr->Add(new TObjString("_Median"));
1419 arr->Add(new TObjString("_Median_OutlierCutted"));
1420 arr->Add(new TObjString("_LTM"));
1421 arr->Add(new TObjString("_LTM_OutlierCutted"));
1422 arr->Add(new TObjString("LFitIntern_4_8.fElements"));
1423 arr->Add(new TObjString("GFitIntern_Lin.fElements"));
1424 arr->Add(new TObjString("GFitIntern_Par.fElements"));
1425 arr->Add(new TObjString("FitLinLocal"));
1426 arr->Add(new TObjString("FitLinGlobal"));
1427 arr->Add(new TObjString("FitParLocal"));
1428 arr->Add(new TObjString("FitParGlobal"));
1431 TIterator* iter = arr->MakeIterator();
1433 TObjString* currentStr = 0;
1434 while ((currentStr = (TObjString*)(iter->Next()))) {
1435 std::cout << currentStr->GetString().Data() << std::endl;
1443 TFriendElement* AliTPCCalibViewer::AddReferenceTree(const char* filename, const char* treename, const char* refname){
1445 // add a reference tree to the current tree
1446 // by default the treename is 'calPads' and the reference treename is 'R'
1448 TFile *file = new TFile(filename);
1449 fListOfObjectsToBeDeleted->Add(file);
1450 TTree * tree = (TTree*)file->Get(treename);
1451 return AddFriend(tree, refname);
1455 TObjArray* AliTPCCalibViewer::GetArrayOfCalPads(){
1457 // Returns a TObjArray with all AliTPCCalPads that are stored in the tree
1458 // - this takes a while -
1460 TObjArray *listOfCalPads = GetListOfVariables();
1461 TObjArray *calPadsArray = new TObjArray();
1462 Int_t numberOfCalPads = listOfCalPads->GetEntries();
1463 for (Int_t i = 0; i < numberOfCalPads; i++) {
1464 std::cout << "Creating calPad " << (i+1) << " of " << numberOfCalPads << "\r" << std::flush;
1465 char* calPadName = (char*)((TObjString*)(listOfCalPads->At(i)))->GetString().Data();
1466 TString drawCommand = ((TObjString*)(listOfCalPads->At(i)))->GetString();
1467 drawCommand.Append("~");
1468 AliTPCCalPad* calPad = GetCalPad(drawCommand.Data(), "", calPadName);
1469 calPadsArray->Add(calPad);
1471 std::cout << std::endl;
1472 listOfCalPads->Delete();
1473 delete listOfCalPads;
1474 return calPadsArray;
1478 TString* AliTPCCalibViewer::Fit(const char* drawCommand, const char* formula, const char* cuts, Double_t & chi2, TVectorD &fitParam, TMatrixD &covMatrix){
1480 // fit an arbitrary function, specified by formula into the data, specified by drawCommand and cuts
1481 // returns chi2, fitParam and covMatrix
1482 // returns TString with fitted formula
1485 TString formulaStr(formula);
1486 TString drawStr(drawCommand);
1487 TString cutStr(cuts);
1490 drawStr.ReplaceAll("~",".fElements");
1491 cutStr.ReplaceAll("~",".fElements");
1492 formulaStr.ReplaceAll("~", ".fElements");
1494 formulaStr.ReplaceAll("++", "~");
1495 TObjArray* formulaTokens = formulaStr.Tokenize("~");
1496 Int_t dim = formulaTokens->GetEntriesFast();
1498 fitParam.ResizeTo(dim);
1499 covMatrix.ResizeTo(dim,dim);
1501 TLinearFitter* fitter = new TLinearFitter(dim+1, Form("hyp%d",dim));
1502 fitter->StoreData(kTRUE);
1503 fitter->ClearPoints();
1505 Int_t entries = Draw(drawStr.Data(), cutStr.Data(), "goff");
1506 if (entries == -1) return new TString("An ERROR has occured during fitting!");
1507 Double_t **values = new Double_t*[dim+1] ;
1509 for (Int_t i = 0; i < dim + 1; i++){
1511 if (i < dim) centries = fTree->Draw(((TObjString*)formulaTokens->At(i))->GetName(), cutStr.Data(), "goff");
1512 else centries = fTree->Draw(drawStr.Data(), cutStr.Data(), "goff");
1514 if (entries != centries) return new TString("An ERROR has occured during fitting!");
1515 values[i] = new Double_t[entries];
1516 memcpy(values[i], fTree->GetV1(), entries*sizeof(Double_t));
1519 // add points to the fitter
1520 for (Int_t i = 0; i < entries; i++){
1522 for (Int_t j=0; j<dim;j++) x[j]=values[j][i];
1523 fitter->AddPoint(x, values[dim][i], 1);
1527 fitter->GetParameters(fitParam);
1528 fitter->GetCovarianceMatrix(covMatrix);
1529 chi2 = fitter->GetChisquare();
1532 TString *preturnFormula = new TString(Form("( %f+",fitParam[0])), &returnFormula = *preturnFormula;
1534 for (Int_t iparam = 0; iparam < dim; iparam++) {
1535 returnFormula.Append(Form("%s*(%f)",((TObjString*)formulaTokens->At(iparam))->GetName(),fitParam[iparam+1]));
1536 if (iparam < dim-1) returnFormula.Append("+");
1538 returnFormula.Append(" )");
1539 delete formulaTokens;
1542 return preturnFormula;
1546 void AliTPCCalibViewer::MakeTreeWithObjects(const char * fileName, TObjArray * array, const char * mapFileName) {
1548 // Write tree with all available information
1549 // im mapFileName is speciefied, the Map information are also written to the tree
1550 // AliTPCCalPad-Objects are written directly to the tree, so that they can be accessd later on
1551 // (does not work!!!)
1553 AliTPCROC* tpcROCinstance = AliTPCROC::Instance();
1555 TObjArray* mapIROCs = 0;
1556 TObjArray* mapOROCs = 0;
1557 TVectorF *mapIROCArray = 0;
1558 TVectorF *mapOROCArray = 0;
1559 Int_t mapEntries = 0;
1560 TString* mapNames = 0;
1563 TFile mapFile(mapFileName, "read");
1565 TList* listOfROCs = mapFile.GetListOfKeys();
1566 mapEntries = listOfROCs->GetEntries()/2;
1567 mapIROCs = new TObjArray(mapEntries*2);
1568 mapOROCs = new TObjArray(mapEntries*2);
1569 mapIROCArray = new TVectorF[mapEntries];
1570 mapOROCArray = new TVectorF[mapEntries];
1572 mapNames = new TString[mapEntries];
1573 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
1574 TString rocName(((TKey*)(listOfROCs->At(ivalue*2)))->GetName());
1575 rocName.Remove(rocName.Length()-4, 4);
1576 mapIROCs->AddAt((AliTPCCalROC*)mapFile.Get((rocName + "IROC").Data()), ivalue);
1577 mapOROCs->AddAt((AliTPCCalROC*)mapFile.Get((rocName + "OROC").Data()), ivalue);
1578 mapNames[ivalue].Append(rocName);
1581 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
1582 mapIROCArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(0));
1583 mapOROCArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(36));
1585 for (UInt_t ichannel = 0; ichannel < tpcROCinstance->GetNChannels(0); ichannel++)
1586 (mapIROCArray[ivalue])[ichannel] = ((AliTPCCalROC*)(mapIROCs->At(ivalue)))->GetValue(ichannel);
1587 for (UInt_t ichannel = 0; ichannel < tpcROCinstance->GetNChannels(36); ichannel++)
1588 (mapOROCArray[ivalue])[ichannel] = ((AliTPCCalROC*)(mapOROCs->At(ivalue)))->GetValue(ichannel);
1591 } // if (mapFileName)
1593 TTreeSRedirector cstream(fileName);
1594 Int_t arrayEntries = array->GetEntries();
1596 // Read names of AliTPCCalPads and save them in names[]
1597 TString* names = new TString[arrayEntries];
1598 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++)
1599 names[ivalue].Append(((AliTPCCalPad*)array->At(ivalue))->GetName());
1601 for (UInt_t isector = 0; isector < tpcROCinstance->GetNSectors(); isector++) {
1603 TVectorF *vectorArray = new TVectorF[arrayEntries];
1604 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++)
1605 vectorArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(isector));
1609 // fill vectors of variable per pad
1611 TVectorF *posArray = new TVectorF[8];
1612 for (Int_t ivalue = 0; ivalue < 8; ivalue++)
1613 posArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(isector));
1615 Float_t posG[3] = {0};
1616 Float_t posL[3] = {0};
1618 for (UInt_t irow = 0; irow < tpcROCinstance->GetNRows(isector); irow++) {
1619 for (UInt_t ipad = 0; ipad < tpcROCinstance->GetNPads(isector, irow); ipad++) {
1620 tpcROCinstance->GetPositionLocal(isector, irow, ipad, posL);
1621 tpcROCinstance->GetPositionGlobal(isector, irow, ipad, posG);
1622 posArray[0][ichannel] = irow;
1623 posArray[1][ichannel] = ipad;
1624 posArray[2][ichannel] = posL[0];
1625 posArray[3][ichannel] = posL[1];
1626 posArray[4][ichannel] = posG[0];
1627 posArray[5][ichannel] = posG[1];
1628 posArray[6][ichannel] = (Int_t)(ipad - (Double_t)(tpcROCinstance->GetNPads(isector, irow))/2);
1629 posArray[7][ichannel] = ichannel;
1631 // loop over array containing AliTPCCalPads
1632 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
1633 AliTPCCalPad* calPad = (AliTPCCalPad*) array->At(ivalue);
1634 AliTPCCalROC* calROC = calPad->GetCalROC(isector);
1636 (vectorArray[ivalue])[ichannel] = calROC->GetValue(irow, ipad);
1638 (vectorArray[ivalue])[ichannel] = 0;
1643 AliTPCCalROC dummyROC(0);
1644 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
1645 AliTPCCalROC *roc = ((AliTPCCalPad*)array->At(ivalue))->GetCalROC(isector);
1646 if (!roc) roc = &dummyROC;
1647 cstream << "calPads" <<
1648 (Char_t*)((names[ivalue] + ".=").Data()) << &vectorArray[ivalue];
1649 cstream << "calPads" <<
1650 (Char_t*)((names[ivalue] + "Pad.=").Data()) << roc;
1654 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
1656 cstream << "calPads" <<
1657 (Char_t*)((mapNames[ivalue] + ".=").Data()) << &mapIROCArray[ivalue];
1659 cstream << "calPads" <<
1660 (Char_t*)((mapNames[ivalue] + ".=").Data()) << &mapOROCArray[ivalue];
1664 cstream << "calPads" <<
1665 "sector=" << isector;
1667 cstream << "calPads" <<
1668 "row.=" << &posArray[0] <<
1669 "pad.=" << &posArray[1] <<
1670 "lx.=" << &posArray[2] <<
1671 "ly.=" << &posArray[3] <<
1672 "gx.=" << &posArray[4] <<
1673 "gy.=" << &posArray[5] <<
1674 "rpad.=" << &posArray[6] <<
1675 "channel.=" << &posArray[7];
1677 cstream << "calPads" <<
1681 delete[] vectorArray;
1682 } //for (UInt_t isector = 0; isector < tpcROCinstance->GetNSectors(); isector++)
1688 delete[] mapIROCArray;
1689 delete[] mapOROCArray;
1695 void AliTPCCalibViewer::MakeTree(const char * fileName, TObjArray * array, const char * mapFileName, AliTPCCalPad* outlierPad, Float_t ltmFraction) {
1697 // Write a tree with all available information
1698 // if mapFileName is speciefied, the Map information are also written to the tree
1699 // pads specified in outlierPad are not used for calculating statistics
1700 // The following statistical information on the basis of a ROC are calculated:
1701 // "_Median", "_Mean", "_LTM", "_RMS_LTM"
1702 // "_Median_OutlierCutted", "_Mean_OutlierCutted", "_RMS_OutlierCutted", "_LTM_OutlierCutted", "_RMS_LTM_OutlierCutted"
1703 // The following position variables are available:
1704 // "row", "pad", "lx", "ly", "gx", "gy", "rpad", "channel"
1706 // The tree out of this function is the basis for the AliTPCCalibViewer and the AliTPCCalibViewerGUI.
1708 AliTPCROC* tpcROCinstance = AliTPCROC::Instance();
1710 TObjArray* mapIROCs = 0;
1711 TObjArray* mapOROCs = 0;
1712 TVectorF *mapIROCArray = 0;
1713 TVectorF *mapOROCArray = 0;
1714 Int_t mapEntries = 0;
1715 TString* mapNames = 0;
1718 TFile mapFile(mapFileName, "read");
1720 TList* listOfROCs = mapFile.GetListOfKeys();
1721 mapEntries = listOfROCs->GetEntries()/2;
1722 mapIROCs = new TObjArray(mapEntries*2);
1723 mapOROCs = new TObjArray(mapEntries*2);
1724 mapIROCArray = new TVectorF[mapEntries];
1725 mapOROCArray = new TVectorF[mapEntries];
1727 mapNames = new TString[mapEntries];
1728 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
1729 TString rocName(((TKey*)(listOfROCs->At(ivalue*2)))->GetName());
1730 rocName.Remove(rocName.Length()-4, 4);
1731 mapIROCs->AddAt((AliTPCCalROC*)mapFile.Get((rocName + "IROC").Data()), ivalue);
1732 mapOROCs->AddAt((AliTPCCalROC*)mapFile.Get((rocName + "OROC").Data()), ivalue);
1733 mapNames[ivalue].Append(rocName);
1736 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
1737 mapIROCArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(0));
1738 mapOROCArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(36));
1740 for (UInt_t ichannel = 0; ichannel < tpcROCinstance->GetNChannels(0); ichannel++)
1741 (mapIROCArray[ivalue])[ichannel] = ((AliTPCCalROC*)(mapIROCs->At(ivalue)))->GetValue(ichannel);
1742 for (UInt_t ichannel = 0; ichannel < tpcROCinstance->GetNChannels(36); ichannel++)
1743 (mapOROCArray[ivalue])[ichannel] = ((AliTPCCalROC*)(mapOROCs->At(ivalue)))->GetValue(ichannel);
1746 } // if (mapFileName)
1748 TTreeSRedirector cstream(fileName);
1749 Int_t arrayEntries = 0;
1750 if (array) arrayEntries = array->GetEntries();
1752 TString* names = new TString[arrayEntries];
1753 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++)
1754 names[ivalue].Append(((AliTPCCalPad*)array->At(ivalue))->GetName());
1756 for (UInt_t isector = 0; isector < tpcROCinstance->GetNSectors(); isector++) {
1758 // get statistic for given sector
1760 TVectorF median(arrayEntries);
1761 TVectorF mean(arrayEntries);
1762 TVectorF rms(arrayEntries);
1763 TVectorF ltm(arrayEntries);
1764 TVectorF ltmrms(arrayEntries);
1765 TVectorF medianWithOut(arrayEntries);
1766 TVectorF meanWithOut(arrayEntries);
1767 TVectorF rmsWithOut(arrayEntries);
1768 TVectorF ltmWithOut(arrayEntries);
1769 TVectorF ltmrmsWithOut(arrayEntries);
1771 TVectorF *vectorArray = new TVectorF[arrayEntries];
1772 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++)
1773 vectorArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(isector));
1775 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
1776 AliTPCCalPad* calPad = (AliTPCCalPad*) array->At(ivalue);
1777 AliTPCCalROC* calROC = calPad->GetCalROC(isector);
1778 AliTPCCalROC* outlierROC = 0;
1779 if (outlierPad) outlierROC = outlierPad->GetCalROC(isector);
1781 median[ivalue] = calROC->GetMedian();
1782 mean[ivalue] = calROC->GetMean();
1783 rms[ivalue] = calROC->GetRMS();
1784 Double_t ltmrmsValue = 0;
1785 ltm[ivalue] = calROC->GetLTM(<mrmsValue, ltmFraction);
1786 ltmrms[ivalue] = ltmrmsValue;
1788 medianWithOut[ivalue] = calROC->GetMedian(outlierROC);
1789 meanWithOut[ivalue] = calROC->GetMean(outlierROC);
1790 rmsWithOut[ivalue] = calROC->GetRMS(outlierROC);
1792 ltmWithOut[ivalue] = calROC->GetLTM(<mrmsValue, ltmFraction, outlierROC);
1793 ltmrmsWithOut[ivalue] = ltmrmsValue;
1797 median[ivalue] = 0.;
1801 ltmrms[ivalue] = 0.;
1802 medianWithOut[ivalue] = 0.;
1803 meanWithOut[ivalue] = 0.;
1804 rmsWithOut[ivalue] = 0.;
1805 ltmWithOut[ivalue] = 0.;
1806 ltmrmsWithOut[ivalue] = 0.;
1811 // fill vectors of variable per pad
1813 TVectorF *posArray = new TVectorF[8];
1814 for (Int_t ivalue = 0; ivalue < 8; ivalue++)
1815 posArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(isector));
1817 Float_t posG[3] = {0};
1818 Float_t posL[3] = {0};
1820 for (UInt_t irow = 0; irow < tpcROCinstance->GetNRows(isector); irow++) {
1821 for (UInt_t ipad = 0; ipad < tpcROCinstance->GetNPads(isector, irow); ipad++) {
1822 tpcROCinstance->GetPositionLocal(isector, irow, ipad, posL);
1823 tpcROCinstance->GetPositionGlobal(isector, irow, ipad, posG);
1824 posArray[0][ichannel] = irow;
1825 posArray[1][ichannel] = ipad;
1826 posArray[2][ichannel] = posL[0];
1827 posArray[3][ichannel] = posL[1];
1828 posArray[4][ichannel] = posG[0];
1829 posArray[5][ichannel] = posG[1];
1830 posArray[6][ichannel] = (Int_t)(ipad - (Double_t)(tpcROCinstance->GetNPads(isector, irow))/2);
1831 posArray[7][ichannel] = ichannel;
1833 // loop over array containing AliTPCCalPads
1834 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
1835 AliTPCCalPad* calPad = (AliTPCCalPad*) array->At(ivalue);
1836 AliTPCCalROC* calROC = calPad->GetCalROC(isector);
1838 (vectorArray[ivalue])[ichannel] = calROC->GetValue(irow, ipad);
1840 (vectorArray[ivalue])[ichannel] = 0;
1846 cstream << "calPads" <<
1847 "sector=" << isector;
1849 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
1850 cstream << "calPads" <<
1851 (Char_t*)((names[ivalue] + "_Median=").Data()) << median[ivalue] <<
1852 (Char_t*)((names[ivalue] + "_Mean=").Data()) << mean[ivalue] <<
1853 (Char_t*)((names[ivalue] + "_RMS=").Data()) << rms[ivalue] <<
1854 (Char_t*)((names[ivalue] + "_LTM=").Data()) << ltm[ivalue] <<
1855 (Char_t*)((names[ivalue] + "_RMS_LTM=").Data()) << ltmrms[ivalue];
1857 cstream << "calPads" <<
1858 (Char_t*)((names[ivalue] + "_Median_OutlierCutted=").Data()) << medianWithOut[ivalue] <<
1859 (Char_t*)((names[ivalue] + "_Mean_OutlierCutted=").Data()) << meanWithOut[ivalue] <<
1860 (Char_t*)((names[ivalue] + "_RMS_OutlierCutted=").Data()) << rmsWithOut[ivalue] <<
1861 (Char_t*)((names[ivalue] + "_LTM_OutlierCutted=").Data()) << ltmWithOut[ivalue] <<
1862 (Char_t*)((names[ivalue] + "_RMS_LTM_OutlierCutted=").Data()) << ltmrmsWithOut[ivalue];
1866 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
1867 cstream << "calPads" <<
1868 (Char_t*)((names[ivalue] + ".=").Data()) << &vectorArray[ivalue];
1872 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
1874 cstream << "calPads" <<
1875 (Char_t*)((mapNames[ivalue] + ".=").Data()) << &mapIROCArray[ivalue];
1877 cstream << "calPads" <<
1878 (Char_t*)((mapNames[ivalue] + ".=").Data()) << &mapOROCArray[ivalue];
1882 cstream << "calPads" <<
1883 "row.=" << &posArray[0] <<
1884 "pad.=" << &posArray[1] <<
1885 "lx.=" << &posArray[2] <<
1886 "ly.=" << &posArray[3] <<
1887 "gx.=" << &posArray[4] <<
1888 "gy.=" << &posArray[5] <<
1889 "rpad.=" << &posArray[6] <<
1890 "channel.=" << &posArray[7];
1892 cstream << "calPads" <<
1896 delete[] vectorArray;
1904 delete[] mapIROCArray;
1905 delete[] mapOROCArray;
1911 void AliTPCCalibViewer::MakeTree(const char *outPutFileName, const Char_t *inputFileName, AliTPCCalPad *outlierPad, Float_t ltmFraction, const char *mapFileName ){
1913 // Function to create a calibration Tree with all available information.
1914 // See also documentation to MakeTree
1915 // the file "inputFileName" must be in the following format (see also CreateObjectList):
1916 // (each colum separated by tabs, "dependingOnType" can have 2 or 3 colums)
1918 // type path dependingOnType
1921 // dependingOnType = CETmean CEQmean CETrms
1923 // type == "Pulser":
1924 // dependingOnType = PulserTmean PulsterQmean PulserTrms
1926 // type == "Pedestals":
1927 // dependingOnType = Pedestals Noise
1929 // type == "CalPad":
1930 // dependingOnType = NameInFile NameToWriteToFile
1934 CreateObjectList(inputFileName, &objArray);
1935 MakeTree(outPutFileName, &objArray, mapFileName, outlierPad, ltmFraction);
1938 void AliTPCCalibViewer::CreateObjectList(const Char_t *filename, TObjArray *calibObjects){
1940 // Function to create a TObjArray out of a given file
1941 // the file must be in the following format:
1942 // (each colum separated by tabs, "dependingOnType" can have 2 or 3 colums)
1945 // type path dependingOnType
1948 // dependingOnType = CETmean CEQmean CETrms
1950 // type == "Pulser":
1951 // dependingOnType = PulserTmean PulsterQmean PulserTrms
1953 // type == "Pedestals":
1954 // dependingOnType = Pedestals Noise
1956 // type == "CalPad":
1957 // dependingOnType = NameInFile NameToWriteToFile
1961 if ( calibObjects == 0x0 ) return;
1964 if ( !in.is_open() ){
1965 fprintf(stderr,"Error: cannot open list file '%s'", filename);
1969 AliTPCCalPad *calPad=0x0;
1975 TObjArray *arrFileLine = sFile.Tokenize("\n");
1976 TIter nextLine(arrFileLine);
1978 TObjString *sObjLine = 0x0;
1979 while ( (sObjLine = (TObjString*)nextLine()) ){
1980 TString sLine(sObjLine->GetString());
1982 TObjArray *arrCol = sLine.Tokenize("\t");
1983 Int_t nCols = arrCol->GetEntriesFast();
1985 TObjString *sObjType = (TObjString*)(arrCol->At(0));
1986 TObjString *sObjFileName = (TObjString*)(arrCol->At(1));
1987 TObjString *sObjName = 0x0;
1989 if ( !sObjType || !sObjFileName ) continue;
1990 TString sType(sObjType->GetString());
1991 TString sFileName(sObjFileName->GetString());
1992 printf("Type %s, opening %s \n", sType.Data(), sFileName.Data());
1993 TFile *fIn = TFile::Open(sFileName);
1995 fprintf(stderr,"File not found: '%s'", sFileName.Data());
1999 if ( sType == "CE" ){ // next three colums are the names for CETmean, CEQmean and CETrms
2000 AliTPCCalibCE *ce = (AliTPCCalibCE*)fIn->Get("AliTPCCalibCE");
2001 calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadT0());
2002 if (nCols > 2) { // check, if the name is provided
2003 sObjName = (TObjString*)(arrCol->At(2));
2004 calPad->SetNameTitle(sObjName->GetString().Data(), sObjName->GetString().Data());
2006 else calPad->SetNameTitle("CETmean","CETmean");
2007 calibObjects->Add(calPad);
2009 calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadQ());
2010 if (nCols > 3) { // check, if the name is provided
2011 sObjName = (TObjString*)(arrCol->At(3));
2012 calPad->SetNameTitle(sObjName->GetString().Data(), sObjName->GetString().Data());
2014 else calPad->SetNameTitle("CEQmean","CEQmean");
2015 calibObjects->Add(calPad);
2017 calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadRMS());
2018 if (nCols > 4) { // check, if the name is provided
2019 sObjName = (TObjString*)(arrCol->At(4));
2020 calPad->SetNameTitle(sObjName->GetString().Data(), sObjName->GetString().Data());
2022 else calPad->SetNameTitle("CETrms","CETrms");
2023 calibObjects->Add(calPad);
2025 } else if ( sType == "Pulser") {
2026 AliTPCCalibPulser *sig = (AliTPCCalibPulser*)fIn->Get("AliTPCCalibPulser");
2028 calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadT0());
2030 sObjName = (TObjString*)(arrCol->At(2));
2031 calPad->SetNameTitle(sObjName->GetString().Data(), sObjName->GetString().Data());
2033 else calPad->SetNameTitle("PulserTmean","PulserTmean");
2034 calibObjects->Add(calPad);
2036 calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadQ());
2038 sObjName = (TObjString*)(arrCol->At(3));
2039 calPad->SetNameTitle(sObjName->GetString().Data(), sObjName->GetString().Data());
2041 else calPad->SetNameTitle("PulserQmean","PulserQmean");
2042 calibObjects->Add(calPad);
2044 calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadRMS());
2046 sObjName = (TObjString*)(arrCol->At(4));
2047 calPad->SetNameTitle(sObjName->GetString().Data(), sObjName->GetString().Data());
2049 else calPad->SetNameTitle("PulserTrms","PulserTrms");
2050 calibObjects->Add(calPad);
2052 } else if ( sType == "Pedestals") {
2053 AliTPCCalibPedestal *ped = (AliTPCCalibPedestal*)fIn->Get("AliTPCCalibPedestal");
2055 calPad = new AliTPCCalPad((TObjArray*)ped->GetCalPadPedestal());
2057 sObjName = (TObjString*)(arrCol->At(2));
2058 calPad->SetNameTitle(sObjName->GetString().Data(), sObjName->GetString().Data());
2060 else calPad->SetNameTitle("Pedestals","Pedestals");
2061 calibObjects->Add(calPad);
2063 calPad = new AliTPCCalPad((TObjArray*)ped->GetCalPadRMS());
2065 sObjName = (TObjString*)(arrCol->At(3));
2066 calPad->SetNameTitle(sObjName->GetString().Data(), sObjName->GetString().Data());
2068 else calPad->SetNameTitle("Noise","Noise");
2069 calibObjects->Add(calPad);
2071 } else if ( sType == "CalPad") {
2072 if (nCols > 2) sObjName = (TObjString*)(arrCol->At(2));
2074 calPad = new AliTPCCalPad(*(AliTPCCalPad*)fIn->Get(sObjName->GetString().Data()));
2076 sObjName = (TObjString*)(arrCol->At(3));
2077 calPad->SetNameTitle(sObjName->GetString().Data(), sObjName->GetString().Data());
2079 calibObjects->Add(calPad);
2081 fprintf(stderr,"Undefined Type: '%s'",sType.Data());