File indexing completed on 2023-10-25 09:34:09
0001
0002
0003
0004
0005
0006
0007 #include "DTTimeBoxPlotter.h"
0008 #include "DTTimeBoxFitter.h"
0009
0010 #include <iostream>
0011 #include <cstdio>
0012 #include <sstream>
0013 #include <string>
0014
0015 #include "TFile.h"
0016 #include "TCanvas.h"
0017 #include "TROOT.h"
0018 #include "TCollection.h"
0019 #include "TSystem.h"
0020 #include "TH2F.h"
0021
0022
0023 using namespace std;
0024
0025
0026 DTTimeBoxPlotter::DTTimeBoxPlotter(TFile* file) : theFile(file), theVerbosityLevel(0) {
0027 theFitter = new DTTimeBoxFitter();
0028 theFitter->setVerbosity(1);
0029 }
0030
0031
0032 DTTimeBoxPlotter::~DTTimeBoxPlotter() {}
0033
0034 TH1F* DTTimeBoxPlotter::plotTimeBox(int wheel, int station, int sector, const TString& drawOptions) {
0035 TString histoName = getHistoNameSuffix(wheel, station, sector) + "_hTimeBox";
0036 return plotHisto(histoName, drawOptions);
0037 }
0038
0039 TH1F* DTTimeBoxPlotter::plotTimeBox(int wheel, int station, int sector, int sl, const TString& drawOptions) {
0040 TString histoName = getHistoNameSuffix(wheel, station, sector, sl) + "_hTimeBox";
0041 return plotHisto(histoName, drawOptions);
0042 }
0043
0044 TH1F* DTTimeBoxPlotter::plotTimeBox(int wheel, int station, int sector, int sl, int layer, const TString& drawOptions) {
0045 TString histoName = getHistoNameSuffix(wheel, station, sector, sl, layer) + "_hTimeBox";
0046 return plotHisto(histoName, drawOptions);
0047 }
0048
0049 TH1F* DTTimeBoxPlotter::plotTimeBox(
0050 int wheel, int station, int sector, int sl, int layer, int wire, const TString& drawOptions) {
0051 TString histoName = getHistoNameSuffix(wheel, station, sector, sl, layer, wire) + "_hTimeBox";
0052 return plotHisto(histoName, drawOptions);
0053 }
0054
0055 void DTTimeBoxPlotter::printPDF() {
0056 TIter iter(gROOT->GetListOfCanvases());
0057 TCanvas* c;
0058 while ((c = (TCanvas*)iter())) {
0059 c->Print(0, "ps");
0060 }
0061 gSystem->Exec("ps2pdf *.ps");
0062 }
0063
0064 TString DTTimeBoxPlotter::getHistoNameSuffix(int wheel, int station, int sector) {
0065 string histoName;
0066 stringstream theStream;
0067 theStream << "Ch_" << wheel << "_" << station << "_" << sector << "_SLall_Lall_Wall";
0068 theStream >> histoName;
0069 return TString(histoName.c_str());
0070 }
0071
0072 TString DTTimeBoxPlotter::getHistoNameSuffix(int wheel, int station, int sector, int sl) {
0073 string histoName;
0074 stringstream theStream;
0075 theStream << "Ch_" << wheel << "_" << station << "_" << sector << "_SL" << sl;
0076 theStream >> histoName;
0077 return TString(histoName.c_str());
0078 }
0079
0080 TString DTTimeBoxPlotter::getHistoNameSuffix(int wheel, int station, int sector, int sl, int layer) {
0081 string histoName;
0082 stringstream theStream;
0083 theStream << "Ch_" << wheel << "_" << station << "_" << sector << "_SL" << sl << "_L" << layer << "_Wall";
0084 theStream >> histoName;
0085 return TString(histoName.c_str());
0086 }
0087
0088 TString DTTimeBoxPlotter::getHistoNameSuffix(int wheel, int station, int sector, int sl, int layer, int wire) {
0089 string histoName;
0090 stringstream theStream;
0091 theStream << "Ch_" << wheel << "_" << station << "_" << sector << "_SL" << sl << "_L" << layer << "_W" << wire;
0092 theStream >> histoName;
0093 return TString(histoName.c_str());
0094 }
0095
0096 TH1F* DTTimeBoxPlotter::plotHisto(const TString& histoName, const TString& drawOptions) {
0097 TH1F* histo = (TH1F*)theFile->Get(histoName.Data());
0098 if (histo == 0) {
0099 cout << "***Error: Histogram: " << histoName << " doesn't exist!" << endl;
0100 return 0;
0101 }
0102 static int color;
0103
0104 TCanvas* c;
0105 if (!drawOptions.Contains("same")) {
0106 color = 1;
0107 c = newCanvas("c_" + histoName);
0108 c->cd();
0109 histo->SetLineColor(color);
0110 } else {
0111 color++;
0112 histo->SetLineColor(color);
0113 }
0114 histo->Draw(TString("h" + drawOptions).Data());
0115
0116 if (drawOptions.Contains("fit")) {
0117 theFitter->fitTimeBox(histo);
0118 }
0119
0120 return histo;
0121 }
0122
0123 TH2F* DTTimeBoxPlotter::plotHisto2D(const TString& histoName, const TString& drawOptions) {
0124 TH2F* histo = (TH2F*)theFile->Get(histoName.Data());
0125 if (histo == 0) {
0126 cout << "***Error: Histogram: " << histoName << " doesn't exist!" << endl;
0127 return 0;
0128 }
0129 static int color;
0130
0131 TCanvas* c;
0132 if (!drawOptions.Contains("same")) {
0133 color = 1;
0134 c = newCanvas("c_" + histoName);
0135 c->cd();
0136 histo->SetLineColor(color);
0137 } else {
0138 color++;
0139 histo->SetLineColor(color);
0140 }
0141 histo->Draw(TString("h" + drawOptions).Data());
0142 return histo;
0143 }
0144
0145 TCanvas* DTTimeBoxPlotter::newCanvas(TString name, TString title, int xdiv, int ydiv, int form, int w) {
0146 static int i = 1;
0147 if (name == "") {
0148 name = TString("Canvas ") + TString(i);
0149 i++;
0150 }
0151 TCanvas* c = 0;
0152 if (title == "")
0153 title = name;
0154 if (w < 0) {
0155 c = new TCanvas(name, title, form);
0156 } else {
0157 c = new TCanvas(name, title, form, w);
0158 }
0159 if (xdiv * ydiv != 0)
0160 c->Divide(xdiv, ydiv);
0161 c->cd(1);
0162 return c;
0163 }
0164
0165 TCanvas* DTTimeBoxPlotter::newCanvas(TString name, int xdiv, int ydiv, int form, int w) {
0166 return newCanvas(name, name, xdiv, ydiv, form, w);
0167 }
0168 TCanvas* DTTimeBoxPlotter::newCanvas(int xdiv, int ydiv, int form) { return newCanvas("", "", xdiv, ydiv, form); }
0169 TCanvas* DTTimeBoxPlotter::newCanvas(int form) { return newCanvas(0, 0, form); }
0170
0171 TCanvas* DTTimeBoxPlotter::newCanvas(TString name, int form, int w) { return newCanvas(name, name, 0, 0, form, w); }
0172
0173
0174 void DTTimeBoxPlotter::setVerbosity(unsigned int lvl) {
0175 theVerbosityLevel = lvl;
0176 theFitter->setVerbosity(lvl);
0177 }
0178
0179 void DTTimeBoxPlotter::setInteractiveFit(bool isInteractive) { theFitter->setInteractiveFit(isInteractive); }
0180
0181 void DTTimeBoxPlotter::setRebinning(int rebin) { theFitter->setRebinning(rebin); }