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