Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:32:50

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="GlobalHitsHistograms")
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("globalhits","globalhits");  
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_t> histnames;
0048 
0049   vector<string> mchistname;
0050   mchistname.push_back("hMCRGP1");
0051   mchistname.push_back("hMCRGP2");
0052   histnames.push_back(0);
0053 
0054   vector<string> vtxhistname;
0055   vtxhistname.push_back("hMCG4Vtx1");
0056   vtxhistname.push_back("hMCG4Vtx2");
0057   vtxhistname.push_back("hGeantVtxX1");
0058   vtxhistname.push_back("hGeantVtxX2");
0059   vtxhistname.push_back("hGeantVtxY1");
0060   vtxhistname.push_back("hGeantVtxY2");
0061   vtxhistname.push_back("hGeantVtxZ1");
0062   vtxhistname.push_back("hGeantVtxZ2");
0063   histnames.push_back(1);
0064 
0065   vector<string> trkhistname;
0066   trkhistname.push_back("hMCG4Trk1");
0067   trkhistname.push_back("hMCG4Trk2");
0068   trkhistname.push_back("hGeantTrkPt");
0069   trkhistname.push_back("hGeantTrkE");
0070   histnames.push_back(2);
0071 
0072   vector<string> ecalhistname;
0073   ecalhistname.push_back("hCaloEcal1");
0074   ecalhistname.push_back("hCaloEcal2");
0075   ecalhistname.push_back("hCaloEcalE1");
0076   ecalhistname.push_back("hCaloEcalE2");
0077   ecalhistname.push_back("hCaloEcalToF1");
0078   ecalhistname.push_back("hCaloEcalToF2");
0079   ecalhistname.push_back("hCaloEcalPhi");
0080   ecalhistname.push_back("hCaloEcalEta");
0081   histnames.push_back(3);
0082 
0083   vector<string> preshhistname;
0084   preshhistname.push_back("hCaloPreSh1");
0085   preshhistname.push_back("hCaloPreSh2");
0086   preshhistname.push_back("hCaloPreShE1");
0087   preshhistname.push_back("hCaloPreShE2");
0088   preshhistname.push_back("hCaloPreShToF1");
0089   preshhistname.push_back("hCaloPreShToF2");
0090   preshhistname.push_back("hCaloPreShPhi");
0091   preshhistname.push_back("hCaloPreShEta");
0092   histnames.push_back(4);
0093 
0094   vector<string> hcalhistname;
0095   hcalhistname.push_back("hCaloHcal1");
0096   hcalhistname.push_back("hCaloHcal2");
0097   hcalhistname.push_back("hCaloHcalE1");
0098   hcalhistname.push_back("hCaloHcalE2");
0099   hcalhistname.push_back("hCaloHcalToF1");
0100   hcalhistname.push_back("hCaloHcalToF2");
0101   hcalhistname.push_back("hCaloHcalPhi");
0102   hcalhistname.push_back("hCaloHcalEta");
0103   histnames.push_back(5);
0104 
0105   vector<string> pxlhistname;
0106   pxlhistname.push_back("hTrackerPx1");
0107   pxlhistname.push_back("hTrackerPx2");
0108   pxlhistname.push_back("hTrackerPxPhi");
0109   pxlhistname.push_back("hTrackerPxEta");
0110   pxlhistname.push_back("hTrackerPxBToF");
0111   pxlhistname.push_back("hTrackerPxBR");
0112   pxlhistname.push_back("hTrackerPxFToF");
0113   pxlhistname.push_back("hTrackerPxFZ");
0114   histnames.push_back(6);
0115 
0116   vector<string> sihistname;
0117   sihistname.push_back("hTrackerSi1");
0118   sihistname.push_back("hTrackerSi2");
0119   sihistname.push_back("hTrackerSiPhi");
0120   sihistname.push_back("hTrackerSiEta");
0121   sihistname.push_back("hTrackerSiBToF");
0122   sihistname.push_back("hTrackerSiBR");
0123   sihistname.push_back("hTrackerSiFToF");
0124   sihistname.push_back("hTrackerSiFZ");
0125   histnames.push_back(7);
0126 
0127   vector<string> muonhistname;
0128   muonhistname.push_back("hMuon1");
0129   muonhistname.push_back("hMuon2");
0130   muonhistname.push_back("hMuonPhi");
0131   muonhistname.push_back("hMuonEta");
0132   histnames.push_back(8);
0133 
0134   vector<string> cschistname;
0135   cschistname.push_back("hMuonCscToF1");
0136   cschistname.push_back("hMuonCscToF2");
0137   cschistname.push_back("hMuonCscZ");
0138   histnames.push_back(9);
0139 
0140   vector<string> dthistname;
0141   dthistname.push_back("hMuonDtToF1");
0142   dthistname.push_back("hMuonDtToF2");
0143   dthistname.push_back("hMuonDtR");
0144   histnames.push_back(10);
0145 
0146   vector<string> rpchistname;
0147   rpchistname.push_back("hMuonRpcFToF1");
0148   rpchistname.push_back("hMuonRpcFToF2");
0149   rpchistname.push_back("hMuonRpcFZ");
0150   rpchistname.push_back("hMuonRpcBToF1");
0151   rpchistname.push_back("hMuonRpcBToF2");
0152   rpchistname.push_back("hMuonRpcBR");
0153   histnames.push_back(11);
0154 
0155   //loop through histograms to prepare output
0156   for (Int_t i = 0; i < histnames.size(); ++i) {
0157     
0158     vector<string> names;
0159     
0160     // setup canvas depending on group of plots
0161     TCanvas *Canvas;
0162     if (i == 0) {
0163       names = mchistname;
0164       //Canvas = new TCanvas("MCRGP","MCRGP",cWidth,cHeight);
0165       Canvas = new TCanvas("MCRGP","MCRGP");
0166       //Canvas->Size(21.59, 27.94);
0167       Canvas->Divide(1,2);
0168       myCanvas = Canvas;
0169       myCanvas->cd(0);
0170       //label->DrawLatex(0.5,1.00,"Monte Carlo RawGenPart");
0171     }
0172     if (i == 1) {
0173       names = vtxhistname;
0174       //Canvas = new TCanvas("G4Vtx","G4Vtx",cWidth,cHeight);
0175       Canvas = new TCanvas("G4Vtx","G4Vtx");
0176       //Canvas->Size(21.59, 27.94);
0177       Canvas->Divide(2,4);
0178       myCanvas = Canvas;
0179       myCanvas->cd(0);
0180       //label->DrawLatex(0.5,1.00,"Geant4 Vertices");
0181     }
0182     if (i == 2) {
0183       names = trkhistname;
0184       //Canvas = new TCanvas("G4Trk","G4Trk",cWidth,cWidth);
0185       Canvas = new TCanvas("G4Trk","G4Trk");
0186       //Canvas->Size(21.59, 27.94);
0187       Canvas->Divide(2,2);
0188       myCanvas = Canvas;
0189       myCanvas->cd(0);
0190       //label->DrawLatex(0.5,1.00,"Geant4 Tracks");
0191     }
0192     if (i == 3) {
0193       names = ecalhistname;
0194       //Canvas = new TCanvas("ECalHits","ECalHits",cWidth,cHeight);
0195       Canvas = new TCanvas("ECalHits","ECalHits");
0196       //Canvas->Size(21.59, 27.94);
0197       Canvas->Divide(2,4);
0198       myCanvas = Canvas;
0199       myCanvas->cd(0);
0200       //label->DrawLatex(0.5,1.00,"ECal Information");
0201     }
0202     if (i == 4) {
0203       names = preshhistname;
0204       //Canvas = new TCanvas("PreShHits","PreShHits",cWidth,cHeight);
0205       Canvas = new TCanvas("PreShHits","PreShHits");
0206       //Canvas->Size(21.59, 27.94);
0207       Canvas->Divide(2,4);
0208       myCanvas = Canvas;
0209       myCanvas->cd(0);
0210       //label->DrawLatex(0.5,1.00,"PreShower Information");
0211     }
0212     if (i == 5) {
0213       names = hcalhistname;
0214       //Canvas = new TCanvas("HCalHits","HCalHits",cWidth,cHeight);
0215       Canvas = new TCanvas("HCalHits","HCalHits");
0216       //Canvas->Size(21.59, 27.94);
0217       Canvas->Divide(2,4);
0218       myCanvas = Canvas;
0219       myCanvas->cd(0);
0220       //label->DrawLatex(0.5,1.00,"HCal Information");
0221     }
0222     if (i == 6) {
0223       names = pxlhistname;
0224       //Canvas = new TCanvas("PixelHits","PixelHits",cWidth,cHeight);
0225       Canvas = new TCanvas("PixelHits","PixelHits");
0226       //Canvas->Size(21.59, 27.94);
0227       Canvas->Divide(2,4);
0228       myCanvas = Canvas;
0229       myCanvas->cd(0);
0230       //label->DrawLatex(0.5,1.00,"Pixel Information");
0231     }
0232     if (i == 7) {
0233       names = sihistname;
0234       //Canvas = new TCanvas("StripHits","StripHits",cWidth,cHeight);
0235       Canvas = new TCanvas("StripHits","StripHits");
0236       //Canvas->Size(21.59, 27.94);
0237       Canvas->Divide(2,4);
0238       myCanvas = Canvas;
0239       myCanvas->cd(0);
0240       //label->DrawLatex(0.5,1.00,"Strip Information");
0241     }
0242     if (i == 8) {
0243       names = muonhistname;
0244       //Canvas = new TCanvas("MuonHits","MuonHits",cWidth,cWidth);
0245       Canvas = new TCanvas("MuonHits","MuonHits");
0246       //Canvas->Size(21.59, 27.94);
0247       Canvas->Divide(2,2);
0248       myCanvas = Canvas;
0249       myCanvas->cd(0);
0250       //label->DrawLatex(0.5,1.00,"Muon Information");
0251     }
0252     if (i == 9) {
0253       names = cschistname;
0254       //Canvas = new TCanvas("MuonCscHits","MuonCscHits",cWidth,cWidth);
0255       Canvas = new TCanvas("MuonCscHits","MuonCscHits");
0256       //Canvas->Size(21.59, 27.94);
0257       Canvas->Divide(2,2);
0258       myCanvas = Canvas;
0259       myCanvas->cd(0);
0260       //label->DrawLatex(0.5,1.00,"Muon CSC Information");
0261     }
0262     if (i == 10) {
0263       names = dthistname;
0264       //Canvas = new TCanvas("MuonDtHits","MuonDtHits",cWidth,cWidth);
0265       Canvas = new TCanvas("MuonDtHits","MuonDtHits");
0266       //Canvas->Size(21.59, 27.94);
0267       Canvas->Divide(2,2);
0268       myCanvas = Canvas;
0269       myCanvas->cd(0);
0270       //label->DrawLatex(0.5,1.00,"Muon DT Information");
0271     }
0272     if (i == 11) {
0273       names = rpchistname;
0274       //Canvas = new TCanvas("MuonRpcHits","MuonRpcHits",cWidth,cWidth);
0275       Canvas = new TCanvas("MuonRpcHits","MuonRpcHits");
0276       //Canvas->Size(21.59, 27.94);
0277       Canvas->Divide(2,3);
0278       myCanvas = Canvas;
0279       myCanvas->cd(0);
0280       //label->DrawLatex(0.5,1.00,"Muon RPC Information");
0281     }
0282 
0283     // loop through plots
0284     for (Int_t j = 0; j < names.size(); ++j) {
0285 
0286       //TH1F *sh = (TH1F*)srcfile->Get(names[j].c_str());
0287       TH1F *sh;
0288 
0289       // set axis info for the histograms
0290       if (i == 0) {
0291     TString hpath = "DQMData/GlobalHitsV/MCGeant/"+names[j];
0292     sh = (TH1F*)srcfile->Get(hpath);
0293       }
0294       if (i == 1) {
0295     TString hpath = "DQMData/GlobalHitsV/MCGeant/"+names[j];
0296     sh = (TH1F*)srcfile->Get(hpath);    
0297       }
0298       if (i == 2) {
0299     TString hpath = "DQMData/GlobalHitsV/MCGeant/"+names[j];
0300     sh = (TH1F*)srcfile->Get(hpath);
0301       }
0302       if (i == 3 || i == 4 || i == 5) {
0303     if (i == 3 || i == 4) {
0304       TString hpath = "DQMData/GlobalHitsV/ECals/"+names[j];
0305       sh = (TH1F*)srcfile->Get(hpath);
0306     }
0307     if (i == 5) {
0308       TString hpath = "DQMData/GlobalHitsV/HCals/"+names[j];
0309       sh = (TH1F*)srcfile->Get(hpath);
0310     }   
0311       }
0312       if (i == 6) {
0313     TString hpath = "DQMData/GlobalHitsV/SiPixels/"+names[j];
0314     sh = (TH1F*)srcfile->Get(hpath);
0315       }
0316       if (i == 7) {
0317     TString hpath = "DQMData/GlobalHitsV/SiStrips/"+names[j];
0318     sh = (TH1F*)srcfile->Get(hpath);
0319       }      
0320       if (i == 8) {
0321     TString hpath = "DQMData/GlobalHitsV/Muons/"+names[j];
0322     sh = (TH1F*)srcfile->Get(hpath);
0323       }
0324       if (i == 9) {
0325     TString hpath = "DQMData/GlobalHitsV/Muons/"+names[j];
0326     sh = (TH1F*)srcfile->Get(hpath);
0327       }
0328       if (i == 10) {
0329     TString hpath = "DQMData/GlobalHitsV/Muons/"+names[j];
0330     sh = (TH1F*)srcfile->Get(hpath);
0331       }
0332       if (i == 11) {
0333     TString hpath = "DQMData/GlobalHitsV/Muon/"+names[j];
0334     sh = (TH1F*)srcfile->Get(hpath);
0335       }
0336       sh->SetLineColor(srccolor);
0337       sh->SetLineWidth(linewidth);    
0338 
0339       // make plots
0340       myCanvas->cd(j+1);
0341       //gPad->SetLogy();
0342       sh->Draw();
0343 
0344     } // end loop through plots
0345 
0346     myCanvas->Print(psfile);
0347 
0348   } // end loop through histnames
0349 
0350   // close output ps file
0351   myCanvas->Print(psfileclose);
0352 
0353   srcfile->Close();
0354 
0355   //convert to pdf
0356   TString cmnd;
0357   cmnd = "ps2pdf "+psfile+" "+filename+".pdf";
0358   gSystem->Exec(cmnd);
0359   cmnd = "rm "+psfile;
0360   gSystem->Exec(cmnd);  
0361 
0362   return;
0363 }