Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:12:40

0001 destdir=/afs/cern.ch/cms/Physics/egamma/www/validation/312PreProd/Photons/DQMOffline/
0002 echo Destination for plots is $destdir
0003 fixedname=`echo $1 | sed 's/\/$//'`
0004 inputdir=`echo $fixedname`
0005 echo Input directory is $inputdir
0006 shortname=`echo $fixedname | sed 's/.*\///'`
0007 echo Nickname is $shortname
0008 rootfile=`echo $shortname.root`
0009 echo ROOT file containing plots will be $rootfile
0010 
0011 rfdir $inputdir | grep 'root' | awk '{print $9}' | sed "s,^,$inputdir/," | xargs hadd -f $rootfile
0012 
0013 #rm ../python/photonOfflineClient_cfi.py
0014 rm photonOfflineClient_cfi.template
0015 #    InputFileName = cms.untracked.string("file:__FILENAME__"),
0016 sed "s%InputFileName = cms\.untracked\.string(\".*\")%InputFileName = cms.untracked.string(\"$rootfile\")%" ../python/photonOfflineClient_cfi.py > photonOfflineClient_cfi.template
0017 mv -f photonOfflineClient_cfi.template ../python/photonOfflineClient_cfi.py
0018 cmsRun PhotonOfflineClient_cfg.py
0019 
0020 rm plotlist.txt
0021 cat >> plotlist.txt << EOF
0022 /DQMData/Egamma/PhotonAnalyzer/AllPhotons/Et above 0 GeV
0023 /DQMData/Egamma/PhotonAnalyzer/AllPhotons/Et above 0 GeV/Conversions
0024 /DQMData/Egamma/PhotonAnalyzer/BackgroundPhotons/Et above 0 GeV
0025 /DQMData/Egamma/PhotonAnalyzer/BackgroundPhotons/Et above 0 GeV/Conversions
0026 /DQMData/Egamma/PhotonAnalyzer/GoodCandidatePhotons/Et above 0 GeV
0027 /DQMData/Egamma/PhotonAnalyzer/GoodCandidatePhotons/Et above 0 GeV/Conversions
0028 /DQMData/Egamma/PhotonAnalyzer/InvMass
0029 /DQMData/Egamma/PhotonAnalyzer/Efficiencies
0030 EOF
0031 
0032 rm plotScript.C
0033 cat >> plotScript.C << EOF
0034 #include "TFile.h"
0035 #include "TH1.h"
0036 #include "TKey.h"
0037 #include "TClass.h"
0038 #include "TList.h"
0039 #include "THStack.h"
0040 #include "TLegend.h"
0041 #include "TCanvas.h"
0042 #include "TPaveStats.h"
0043 #include "TSystem.h"
0044 
0045 #include <fstream>
0046 #include <iostream>
0047 
0048 
0049 void plotScript(string file1) {
0050 
0051     ifstream infile("plotlist.txt");
0052 
0053     vector<string> plotDirectories;
0054 
0055     string s;
0056     
0057     while (getline(infile,s)) {
0058         plotDirectories.push_back(s);
0059     }
0060 
0061     
0062     ofstream outfile;
0063 
0064     string ofname = file1;
0065 
0066     while (ofname.find("/") != string::npos) {
0067         ofname.replace(ofname.find("/"), 1, "_");
0068     }
0069     while (ofname.find(".") != string::npos) {
0070         ofname.replace(ofname.find("."), 1, "_");
0071     }
0072     
0073     cout << ofname << endl;
0074     string prefix = ofname;
0075     ofname += ".html";
0076 
0077     outfile.open(ofname.c_str());
0078     outfile << "<!DOCTYPE html> <html> <head> <title>\n";
0079     outfile << file1 << "\n";
0080     outfile << "</title> </head>\n";
0081     outfile << "<body>\n";
0082     outfile << "<h1>\n";
0083     outfile << "<span style=\"color:#0404B4\">" << file1 << "</span>";
0084     outfile << "</h1>\n";
0085     outfile << "<a name=\"top\">Directory listing:</a><br>\n";
0086     int anchor = 0;
0087     for (vector<string>::iterator vecIt = plotDirectories.begin();
0088             vecIt != plotDirectories.end(); ++vecIt) {
0089         outfile << "<a href=\"#" << anchor << "\">" << *vecIt << "</a><br>\n";
0090         ++anchor;
0091     }
0092     
0093     TFile * f1 = new TFile(file1.c_str(), "READ");
0094     
0095     TDirectory * mydir; 
0096     TObject * obj;
0097     TCanvas * c0 = new TCanvas("c0","c0");
0098     anchor = 0;
0099     TLegend * leg = new TLegend(0.78,0.9,0.98,0.98);
0100     TH1F * firstH = new TH1F();
0101     firstH->SetLineWidth(2);
0102     firstH->SetLineColor(4);
0103     leg->AddEntry(firstH,file1.c_str(),"l");
0104     for (vector<string>::iterator vecIt = plotDirectories.begin();
0105             vecIt != plotDirectories.end(); ++vecIt) {
0106         outfile << "<br><a name=\"" << anchor << "\"><h2>" << *vecIt << "</h2></a> <a href=\"#top\">[Back to top]</a><br>\n";
0107         ++anchor;
0108         TH1 *h;
0109         TKey *key;
0110         mydir = f1->GetDirectory((*vecIt).c_str());
0111         TIter nextkey(mydir->GetListOfKeys());
0112         float scale = 1.;
0113         while (key = (TKey*)nextkey()) {
0114             obj = key->ReadObj();
0115             if (obj->IsA()->InheritsFrom("TH1")) {
0116                 h = (TH1*)obj; 
0117 
0118                 if (string(h->GetName()).find("convVtxYvsX") != string::npos ||
0119                        string(h->GetName()).find("convVtxRvsZ") != string::npos) {
0120                     h->Draw();
0121                     c0->Modified();
0122                     c0->Update(); 
0123                     string filename = prefix + "_" + *vecIt + "_" + h->GetName() + ".png";
0124                     while (filename.find("/") != string::npos) {
0125                         filename.replace(filename.find("/"), 1, "_");
0126                     }
0127                     while (filename.find(" ") != string::npos) {
0128                         filename.replace(filename.find(" "), 1, "_");
0129                     }
0130                     c0->SaveAs(filename.c_str());
0131                     outfile << "<a href=\"" << filename << "\"><img height=\"200\" width=\"324\" src=\"" << filename << "\"></a>\n";
0132                     continue;
0133                 }
0134 
0135                 bool is1D = true;
0136                 
0137                 if (obj->IsA()->InheritsFrom("TH2")) {
0138                     h->SetMarkerColor(4);
0139                     is1D = false;
0140                 } 
0141 
0142                 int firstBin = 1;
0143                 int lastBin  = h->GetNbinsX();
0144                     
0145                 if (h->GetEntries() == 0) {
0146                 } else {
0147                     if (is1D) {
0148                         while (h->GetBinContent(firstBin) == 0. && firstBin < lastBin) ++firstBin;
0149                         while (h->GetBinContent(lastBin)  == 0. && firstBin < lastBin) --lastBin;
0150                     }
0151 
0152 
0153                     h->SetFillStyle(0);
0154                     h->SetLineColor(4);
0155                     h->SetLineWidth(2);
0156                     scale = 1./h->GetEntries();
0157                 }
0158 
0159                 if (vecIt->find("Efficiencies") == string::npos && 
0160                         !(obj->IsA()->InheritsFrom("TProfile"))) {
0161                 }
0162                 THStack * stack = new THStack("stack",h->GetTitle());
0163                 stack->Add(h);
0164 
0165 
0166 
0167                 stack->Draw("nostack");
0168                 if (is1D) stack->GetXaxis()->SetRange(firstBin, lastBin);
0169                 stack->GetXaxis()->SetTitle(h->GetXaxis()->GetTitle());
0170                 stack->GetYaxis()->SetTitle(h->GetYaxis()->GetTitle());
0171                 stack->Draw("nostack");
0172                 leg->Draw("same");
0173                 c0->Modified();
0174                 c0->Update(); 
0175                 string filename = prefix + "_" + *vecIt + "_" + h->GetName() + ".png";
0176                 while (filename.find("/") != string::npos) {
0177                     filename.replace(filename.find("/"), 1, "_");
0178                 }
0179                 while (filename.find(" ") != string::npos) {
0180                     filename.replace(filename.find(" "), 1, "_");
0181                 }
0182                 c0->SaveAs(filename.c_str());
0183                 outfile << "<a href=\"" << filename << "\"><img height=\"200\" width=\"324\" src=\"" << filename << "\"></a>\n";
0184             }
0185         }
0186 
0187     }
0188 
0189     outfile << "</body>\n";
0190     outfile << "</html>\n";
0191     outfile.close();
0192 
0193     cout << "DONE!  HTML file created:" << endl;
0194     cout << ofname << endl;
0195 }
0196 
0197 EOF
0198 
0199 root -b -q plotScript.C++\(\"$rootfile\"\)
0200 mkdir -p $destdir/$shortname
0201 /bin/mv ${shortname}_root.html $destdir/$shortname/index.html 
0202 /bin/mv ${shortname}_root* $destdir/$shortname