Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-10-08 05:11:29

0001 #include <iostream>
0002 #include <fstream>
0003 #include <sstream>
0004 #include <string>
0005 
0006 #include "TFile.h"
0007 #include "TH1D.h"
0008 #include "TCanvas.h"
0009 
0010 #define NOISEPREFIX "Profile_NoiseFromCondDB__det__"
0011 #define PEDESTALPREFIX "Profile_PedestalFromCondDB__det__"
0012 
0013 void printPlot(TH1D* hist, char* prefix, char* postfix);
0014 
0015 int main(int argc, char* argv[]) {
0016   char* rootfilename;
0017   char* modulelistname;
0018   int pnbits;
0019   char* prefix;
0020   char* postfix;
0021 
0022   if (argc == 6) {
0023     rootfilename = argv[1];
0024     modulelistname = argv[2];
0025     pnbits = atoi(argv[3]);
0026     prefix = argv[4];
0027     postfix = argv[5];
0028   } else {
0029     std::cout << "Wrong number of parameters " << argc << std::endl;
0030     return 1;
0031   }
0032 
0033   std::cout << "ready to go " << rootfilename << ' ' << modulelistname << std::endl;
0034 
0035   TFile* rootfile = new TFile(rootfilename, "READ");
0036   if (!rootfile) {
0037     std::cout << "Problems with input root file" << std::endl;
0038     return 2;
0039   }
0040   int detid;
0041   std::ifstream modulelist(modulelistname);
0042 
0043   while (modulelist >> detid) {
0044     std::cout << " ready to go with detid " << detid << " " << pnbits << std::endl;
0045     // bit 0: noise
0046     if (pnbits & 1) {
0047       std::stringstream histoname;
0048       histoname << NOISEPREFIX << detid;
0049       std::cout << " ready to go with histogram " << histoname.str() << std::endl;
0050       TH1D* hist = (TH1D*)rootfile->FindObjectAny(histoname.str().c_str());
0051       if (hist) {
0052         std::cout << histoname.str() << " found!" << std::endl;
0053         printPlot(hist, prefix, postfix);
0054       } else {
0055         std::cout << histoname.str() << " NOT found..." << std::endl;
0056       }
0057     }
0058     // bit 1: pedestal
0059     if (pnbits & 2) {
0060       std::stringstream histoname;
0061       histoname << PEDESTALPREFIX << detid;
0062       std::cout << " ready to go with histogram " << histoname.str() << std::endl;
0063       TH1D* hist = (TH1D*)rootfile->FindObjectAny(histoname.str().c_str());
0064       if (hist) {
0065         std::cout << histoname.str() << " found!" << std::endl;
0066         printPlot(hist, prefix, postfix);
0067       } else {
0068         std::cout << histoname.str() << " NOT found..." << std::endl;
0069       }
0070     }
0071   }
0072 
0073   return 0;
0074 }
0075 
0076 void printPlot(TH1D* hist, char* prefix, char* postfix) {
0077   TCanvas* cc = new TCanvas;
0078   hist->Draw("hist");
0079   std::stringstream filename;
0080   filename << prefix << hist->GetName() << postfix << ".png";
0081   cc->Print(filename.str().c_str());
0082   delete cc;
0083 }