Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:32:26

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // Macro to produce histograms from the GlobalHitsProducer
0003 //
0004 // root -b -q MakePlots.C
0005 ///////////////////////////////////////////////////////////////////////////////
0006 #include "TFile.h"
0007 #include "TTree.h"
0008 #include "TBranch.h"
0009 #include "TString.h"
0010 
0011 void MakePlots(TString filename="GlobalRecHitsHistograms")
0012 {
0013   gROOT->Reset();
0014   //http://root.cern.ch/root/html/src/TStyle.cxx.html#TStyle:SetOptStat
0015   gStyle->SetOptStat("emruo");
0016 
0017   TString srcname = filename+".root";
0018 
0019   // clear memory of file name
0020   delete gROOT->GetListOfFiles()->FindObject(srcname);
0021 
0022   // open source file
0023   TFile *srcfile = new TFile(srcname);
0024   
0025   // create canvas
0026   Int_t cWidth = 928, cHeight = 1218;
0027   //TCanvas *myCanvas = new TCanvas("globalhits","globalhits",cWidth,cHeight);
0028   TCanvas *myCanvas = new TCanvas("globalrechits","globalrechits");  
0029   //myCanvas->Size(21.59, 27.94);
0030 
0031   // open output ps file
0032   //TString filename = "GlobalHitsHistograms";
0033   TString psfile = filename+".ps";
0034   TString psfileopen = filename+".ps[";
0035   TString psfileclose = filename+".ps]";
0036   myCanvas->Print(psfileopen);
0037 
0038   // create label
0039   TLatex *label = new TLatex();
0040   label->SetNDC();
0041   TString labeltitle;
0042 
0043   // create attributes
0044   Int_t srccolor = kBlue;
0045   Int_t linewidth = 2;
0046 
0047   vector<int> histnames;
0048 
0049 
0050 
0051   vector<string> ecalhistname;
0052   ecalhistname.push_back("hEcalRes_EB");
0053   ecalhistname.push_back("hEcalRes_EE");
0054   ecalhistname.push_back("hEcalRes_ES");
0055   ecalhistname.push_back("hEcaln_EB");
0056   ecalhistname.push_back("hEcaln_EE");
0057   ecalhistname.push_back("hEcaln_ES");
0058   histnames.push_back(0);
0059 
0060 
0061   vector<string> hcalhistname;
0062   hcalhistname.push_back("hHcalRes_HB");
0063   hcalhistname.push_back("hHcalRes_HE");
0064   hcalhistname.push_back("hHcalRes_HF");
0065   hcalhistname.push_back("hHcalRes_HO");
0066   hcalhistname.push_back("hHcaln_HB");
0067   hcalhistname.push_back("hHcaln_HE");
0068   hcalhistname.push_back("hHcaln_HF");
0069   hcalhistname.push_back("hHcaln_HO");
0070   histnames.push_back(1);
0071 
0072   vector<string> pxlhistname;
0073   string PxlString[7] = {"BRL1", "BRL2", "BRL3", "FWD1n", "FWD1p", "FWD2n", "FWD2p"};
0074   string ResX[7], ResY[7], Count[7];
0075   for(int j = 0; j < 7; ++j)
0076     {
0077       ResX[j] = "hSiPixelResX_"+PxlString[j];
0078       pxlhistname.push_back(ResX[j]);
0079       pxlhistname.push_back("hSiPixelResY_"+PxlString[j]);
0080       pxlhistname.push_back("hSiPixeln_"+PxlString[j]);
0081     }
0082 
0083   histnames.push_back(2);
0084   vector<string> sihistname;
0085   string SiString[19] = {"TECW1", "TECW2", "TECW3", "TECW4", "TECW5", "TECW6", "TECW7", "TECW8", "TIBL1", "TIBL2", "TIBL3", "TIBL4", "TIDW1", "TIDW2", "TIDW3", "TOBL1", "TOBL2", "TOBL3", "TOBL4"};
0086   for(int i = 0; i < 19; ++i)
0087     {
0088       sihistname.push_back("hSiStripResX_"+SiString[i]);
0089       sihistname.push_back("hSiStripResY_"+SiString[i]);
0090       sihistname.push_back("hSiStripn_"+SiString[i]);
0091     }
0092   histnames.push_back(3);
0093 
0094   vector<string> cschistname;
0095   cschistname.push_back("CSCResRDPhi");
0096   cschistname.push_back("hCSCn");
0097   histnames.push_back(4);
0098 
0099   vector<string> dthistname;
0100   dthistname.push_back("hDtMuonn");
0101   dthistname.push_back("hDtMuonRes");
0102   histnames.push_back(5);
0103 
0104   vector<string> rpchistname;
0105   rpchistname.push_back("hRPCResX");
0106   rpchistname.push_back("hRPCn");
0107   histnames.push_back(6);
0108 
0109   //loop through histograms to prepare output
0110   for (Int_t i = 0; i < histnames.size(); ++i) {
0111     
0112     vector<string> names;
0113     
0114     // setup canvas depending on group of plots
0115     TCanvas *Canvas;
0116 
0117     if (i == 0) {
0118       names = ecalhistname;
0119       //Canvas = new TCanvas("ECalHits","ECalHits",cWidth,cHeight);
0120       Canvas = new TCanvas("ECalHits","ECalHits");
0121       //Canvas->Size(21.59, 27.94);
0122       Canvas->Divide(2,4);
0123       myCanvas = Canvas;
0124       myCanvas->cd(0);
0125       //label->DrawLatex(0.5,1.00,"ECal Information");
0126     }
0127     if (i == 1) {
0128       names = hcalhistname;
0129       //Canvas = new TCanvas("HCalHits","HCalHits",cWidth,cHeight);
0130       Canvas = new TCanvas("HCalHits","HCalHits");
0131       //Canvas->Size(21.59, 27.94);
0132       Canvas->Divide(2,4);
0133       myCanvas = Canvas;
0134       myCanvas->cd(0);
0135       //label->DrawLatex(0.5,1.00,"HCal Information");
0136     }
0137     if (i == 2) {
0138       names = pxlhistname;
0139       //Canvas = new TCanvas("PixelHits","PixelHits",cWidth,cHeight);
0140       Canvas = new TCanvas("PixelHits","PixelHits");
0141       //Canvas->Size(21.59, 27.94);
0142       Canvas->Divide(2,4);
0143       myCanvas = Canvas;
0144       myCanvas->cd(0);
0145       //label->DrawLatex(0.5,1.00,"Pixel Information");
0146     }
0147     if (i == 3) {
0148       names = sihistname;
0149       //Canvas = new TCanvas("StripHits","StripHits",cWidth,cHeight);
0150       Canvas = new TCanvas("StripHits","StripHits");
0151       //Canvas->Size(21.59, 27.94);
0152       Canvas->Divide(2,4);
0153       myCanvas = Canvas;
0154       myCanvas->cd(0);
0155       //label->DrawLatex(0.5,1.00,"Strip Information");
0156     }
0157     if (i == 4) {
0158       names = cschistname;
0159       //Canvas = new TCanvas("MuonCscHits","MuonCscHits",cWidth,cWidth);
0160       Canvas = new TCanvas("MuonCscHits","MuonCscHits");
0161       //Canvas->Size(21.59, 27.94);
0162       Canvas->Divide(2,2);
0163       myCanvas = Canvas;
0164       myCanvas->cd(0);
0165       //label->DrawLatex(0.5,1.00,"Muon CSC Information");
0166     }
0167     if (i == 5) {
0168       names = dthistname;
0169       //Canvas = new TCanvas("MuonDtHits","MuonDtHits",cWidth,cWidth);
0170       Canvas = new TCanvas("MuonDtHits","MuonDtHits");
0171       //Canvas->Size(21.59, 27.94);
0172       Canvas->Divide(2,2);
0173       myCanvas = Canvas;
0174       myCanvas->cd(0);
0175       //label->DrawLatex(0.5,1.00,"Muon DT Information");
0176     }
0177     if (i == 6) {
0178       names = rpchistname;
0179       //Canvas = new TCanvas("MuonRpcHits","MuonRpcHits",cWidth,cWidth);
0180       Canvas = new TCanvas("MuonRpcHits","MuonRpcHits");
0181       //Canvas->Size(21.59, 27.94);
0182       Canvas->Divide(2,3);
0183       myCanvas = Canvas;
0184       myCanvas->cd(0);
0185       //label->DrawLatex(0.5,1.00,"Muon RPC Information");
0186     }
0187 
0188     // loop through plots
0189     for (Int_t j = 0; j < names.size(); ++j) {
0190 
0191       //TH1F *sh = (TH1F*)srcfile->Get(names[j].c_str());
0192       TH1F *sh;
0193 
0194       // set axis info for the histograms
0195    
0196       if (i == 0) {
0197       TString hpath = "DQMData/GlobalRecHitsV/ECals/"+names[j];
0198       sh = (TH1F*)srcfile->Get(hpath);
0199       cout << "i = 0" << "j =  " << j  << endl ; 
0200        
0201       }
0202       if (i == 1) {
0203     TString hpath = "DQMData/GlobalRecHitsV/HCals/"+names[j];
0204     sh = (TH1F*)srcfile->Get(hpath);
0205     cout << "i = 1" << endl;
0206             
0207       }
0208       if (i == 2) {
0209     TString hpath = "DQMData/GlobalRecHitsV/SiPixels/"+names[j];
0210     sh = (TH1F*)srcfile->Get(hpath);
0211      cout << "i = 2" << endl ;
0212 
0213       }
0214       if (i == 3) {
0215     TString hpath = "DQMData/GlobalRecHitsV/SiStrips/"+names[j];
0216     sh = (TH1F*)srcfile->Get(hpath);
0217      cout << "i = 3" << endl ;
0218       }         
0219       if (i == 4) {
0220     TString hpath = "DQMData/GlobalRecHitsV/Muons/"+names[j];
0221     sh = (TH1F*)srcfile->Get(hpath);
0222      cout << "i = 3" << endl ;
0223       }
0224       if (i == 5) {
0225     TString hpath = "DQMData/GlobalRecHitsV/Muons/"+names[j];
0226     sh = (TH1F*)srcfile->Get(hpath);
0227      cout << "i = 5" << endl ;
0228       }
0229       if (i == 6) {
0230     TString hpath = "DQMData/GlobalRecHitsV/Muons/"+names[j];
0231     sh = (TH1F*)srcfile->Get(hpath);
0232      cout << "i = 6" << endl ;
0233       }
0234       cout << "HELP ME!!!! " << endl;
0235       
0236       sh->SetLineColor(srccolor);
0237       sh->SetLineWidth(linewidth);    
0238 
0239       // make plots
0240       myCanvas->cd(j+1);
0241       //gPad->SetLogy();
0242       sh->Draw();
0243 
0244     } // end loop through plots
0245 
0246     myCanvas->Print(psfile);
0247 
0248   } // end loop through histnames
0249 
0250   // close output ps file
0251   //myCanvas->Print(psfileclose);
0252 
0253   srcfile->Close();
0254 
0255   //convert to pdf
0256   TString cmnd;
0257   cmnd = "ps2pdf "+psfile+" "+filename+".pdf";
0258   gSystem->Exec(cmnd);
0259   cmnd = "rm "+psfile;
0260   gSystem->Exec(cmnd);  
0261 
0262   return;
0263 }