File indexing completed on 2024-04-06 12:18:53
0001
0002
0003
0004
0005
0006 #include "TFile.h"
0007 #include "TH1.h"
0008 #include "TString.h"
0009 #include "TCanvas.h"
0010 #include "TStyle.h"
0011 #include "TKey.h"
0012 #include "TList.h"
0013 #include "TSystem.h"
0014
0015
0016
0017
0018 TString drawOptions1D("");
0019
0020 TString drawOptions2D("box");
0021
0022
0023 int lineColor = 1;
0024 int lineWidth = 2;
0025 int rebinFactor = 1;
0026
0027 double histoxmin = 0.0;
0028 double histoxmax = 1.2;
0029 double titleSize = 0.03;
0030 double titleOffset = 1.5;
0031
0032 Bool_t displayStatsBox = 0;
0033 Bool_t autoLogYaxis = 0;
0034 Bool_t forceLogYaxis = 0;
0035
0036
0037
0038
0039 void saveDQMHistograms(const TString fileName="histos.root",
0040 TString imageType="pdf",
0041 double outputWidth=600,
0042 double outputHeight=600)
0043 {
0044 TString outputFolder = fileName;
0045 TFile* fin = new TFile(fileName.Data()) ;
0046
0047 TCanvas* canvasDefault;
0048 TString outputType = "."+imageType;
0049 TH1* h = 0;
0050
0051 if (!fin->IsOpen()) {
0052 printf("<E> Cannot open input file %s\n",fileName.Data()) ;
0053 exit(1) ;
0054 }
0055
0056 outputFolder = fileName+"/";
0057
0058
0059 outputFolder.ReplaceAll(".root","");
0060 outputFolder.ReplaceAll("__","_");
0061 gSystem->MakeDirectory(outputFolder);
0062
0063 canvasDefault = new TCanvas("canvasDefault","testCanvas",outputWidth,outputHeight);
0064 canvasDefault->SetGridx();
0065 canvasDefault->SetGridy();
0066
0067
0068 gStyle->SetOptStat(111111);
0069 gStyle->SetHistLineWidth(lineWidth);
0070 gStyle->SetHistLineColor(lineColor);
0071 gStyle->SetTitleSize(titleSize,"X");
0072 gStyle->SetTitleSize(titleSize,"Y");
0073 gStyle->SetTitleXOffset(titleOffset);
0074 gStyle->SetTitleYOffset(titleOffset);
0075
0076
0077 fin->cd("DQMData/Run 1/HLT/Run summary/Exotica");
0078 TDirectory* baseDir = gDirectory;
0079 TDirectory* subDir;
0080
0081 TList* thelist = baseDir->GetListOfKeys() ;
0082 if (!thelist) { printf("<E> No keys found in file\n") ; exit(1) ; }
0083
0084 TIter next(thelist) ;
0085 TKey* key ;
0086 TObject* obj ;
0087
0088 while ( (key = (TKey*)next()) ) {
0089 obj = key->ReadObj() ;
0090 printf("%s\n",obj->IsA()->GetName());
0091
0092 if (strcmp(obj->IsA()->GetName(),"TDirectoryFile")==0) {
0093
0094
0095
0096 printf("<W> Found subdirectory %s\n",obj->GetName()) ;
0097 TString path = outputFolder+"/"+obj->GetName();
0098 gSystem->MakeDirectory(outputFolder+"/"+obj->GetName());
0099 subDir = (TDirectory*)obj;
0100 TList* thesublist = subDir->GetListOfKeys() ;
0101 TIter subnext(thesublist) ;
0102
0103 while ( (key = (TKey*)subnext()) ) {
0104 obj = key->ReadObj();
0105
0106 if ( (strcmp(obj->IsA()->GetName(),"TProfile")==0)
0107 || (!obj->InheritsFrom("TH2"))
0108 || (!obj->InheritsFrom("TH1"))
0109 ) {
0110
0111
0112 printf("Histo name:%s title:%s\n",obj->GetName(),obj->GetTitle());
0113 h = (TH1*)obj;
0114
0115
0116 TString histName = h->GetName();
0117 if(!histName.Contains("Eff")) continue;
0118
0119 h->SetStats(displayStatsBox);
0120 if(rebinFactor!=1)
0121 h->Rebin(rebinFactor);
0122
0123
0124
0125 if (autoLogYaxis) {
0126 Double_t testYvalue = h->GetMaximum();
0127
0128
0129 if (testYvalue > 1.0) {
0130 Double_t maxy = log10(testYvalue);
0131 Double_t miny = log10(h->GetMinimum(1.0));
0132
0133
0134 if ( (maxy-miny) > 2.0 ) {
0135 canvasDefault->SetLogy(1);
0136 }
0137 }
0138 }
0139
0140
0141 if (forceLogYaxis) {
0142 canvasDefault->SetLogy(1);
0143 }
0144
0145
0146
0147 h->Draw(drawOptions1D);
0148 h->GetYaxis()->SetRangeUser(histoxmin, histoxmax);
0149 canvasDefault->Modified();
0150 canvasDefault->Update();
0151
0152 canvasDefault->Print(path+"/"+histName+outputType);
0153 canvasDefault->SetLogy(0);
0154
0155 }
0156 }
0157
0158 }
0159 }
0160
0161 fin->Close();
0162 }