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 "TDirectoryFile.h"
0009 #include "TCanvas.h"
0010
0011 #define NOISEPREFIX "Profile_NoiseFromCondDB__det__"
0012 #define PEDESTALPREFIX "Profile_PedestalFromCondDB__det__"
0013 #define OCCUPANCYPREFIX "ClusterDigiPosition__det__"
0014
0015 void printPlot(TH1D* hist, char* prefix, char* postfix);
0016 int getChannelNumber(int ival);
0017
0018 int main(int argc, char* argv[]) {
0019 char* rootfilename;
0020 char* modulelistname;
0021 int pnbits;
0022 char* prefix;
0023 char* postfix;
0024
0025 bool debugPrint = false;
0026 bool imagePrint = false;
0027
0028 if (argc == 6) {
0029 rootfilename = argv[1];
0030 modulelistname = argv[2];
0031 pnbits = atoi(argv[3]);
0032 prefix = argv[4];
0033 postfix = argv[5];
0034 } else {
0035 std::cout << "Wrong number of parameters " << argc << std::endl;
0036 return 1;
0037 }
0038
0039 if (debugPrint)
0040 std::cout << "ready to go " << rootfilename << ' ' << modulelistname << std::endl;
0041
0042 TFile* rootfile = TFile::Open(rootfilename, "READ");
0043 if (!rootfile) {
0044 std::cout << "Problems with input root file" << std::endl;
0045 return 2;
0046 }
0047 int detid;
0048 std::ifstream modulelist(modulelistname);
0049
0050 std::stringstream outrootfilename;
0051 outrootfilename << prefix << "SummaryFile" << postfix << ".root";
0052 TFile* outrootfile = TFile::Open(outrootfilename.str().c_str(), "RECREATE");
0053
0054 TH1D* th_summary = nullptr;
0055 Double_t TotalEvents = 0.0;
0056 Double_t TotalDigis = 0.0;
0057
0058 TH1D* TotEvents = new TH1D("TotEvents", "TotEvents", 1, 0, 1);
0059
0060 if (pnbits & 4) {
0061 TDirectoryFile* tdir = (TDirectoryFile*)rootfile->FindObjectAny("AlCaReco");
0062 TH1D* hist = (TH1D*)tdir->FindObjectAny("TotalNumberOfCluster__TIB");
0063 if (hist) {
0064 TotalEvents = hist->GetEntries();
0065 TotEvents->SetBinContent(1, TotalEvents);
0066 TotEvents->Write();
0067 }
0068 }
0069 while (modulelist >> detid) {
0070 if (debugPrint)
0071 std::cout << " ready to go with detid " << detid << " " << pnbits << std::endl;
0072
0073 if (pnbits & 1) {
0074 std::stringstream histoname;
0075 histoname << NOISEPREFIX << detid;
0076 if (debugPrint)
0077 std::cout << " ready to go with histogram " << histoname.str() << std::endl;
0078 TH1D* hist = (TH1D*)rootfile->FindObjectAny(histoname.str().c_str());
0079 if (hist) {
0080 if (debugPrint)
0081 std::cout << histoname.str() << " found!" << std::endl;
0082 if (imagePrint)
0083 printPlot(hist, prefix, postfix);
0084 hist->Write();
0085 } else {
0086 std::cout << histoname.str() << " NOT found..." << std::endl;
0087 }
0088 }
0089
0090 if (pnbits & 2) {
0091 std::stringstream histoname;
0092 histoname << PEDESTALPREFIX << detid;
0093 if (debugPrint)
0094 std::cout << " ready to go with histogram " << histoname.str() << std::endl;
0095 TH1D* hist = (TH1D*)rootfile->FindObjectAny(histoname.str().c_str());
0096 if (hist) {
0097 if (debugPrint)
0098 std::cout << histoname.str() << " found!" << std::endl;
0099 if (imagePrint)
0100 printPlot(hist, prefix, postfix);
0101 hist->Write();
0102 } else {
0103 std::cout << histoname.str() << " NOT found..." << std::endl;
0104 }
0105 }
0106
0107 if (pnbits & 4) {
0108 std::stringstream histoname;
0109 histoname << OCCUPANCYPREFIX << detid;
0110 std::string SummaryName = "ClusterDigiPosition__det__Summary";
0111
0112 if (debugPrint)
0113 std::cout << " ready to go with histogram " << histoname.str() << std::endl;
0114 if (th_summary == nullptr)
0115 th_summary = new TH1D(SummaryName.c_str(), SummaryName.c_str(), 768, 0.5, 768.5);
0116 TH1D* hist = (TH1D*)rootfile->FindObjectAny(histoname.str().c_str());
0117 if (hist) {
0118 if (debugPrint)
0119 std::cout << histoname.str() << " found!" << hist->GetEntries() << std::endl;
0120 for (int i = 1; i < hist->GetNbinsX() + 1; i++) {
0121 th_summary->AddBinContent(i, hist->GetBinContent(i));
0122 TotalDigis += hist->GetBinContent(i);
0123 }
0124 hist->SetLineColor(2);
0125 if (imagePrint)
0126 printPlot(hist, prefix, postfix);
0127 hist->Write();
0128 } else {
0129 std::cout << histoname.str() << " NOT found..." << std::endl;
0130 }
0131 }
0132
0133 if (pnbits & 8) {
0134 std::stringstream histoname;
0135 histoname << OCCUPANCYPREFIX << detid;
0136 if (debugPrint)
0137 std::cout << " ready to go with histogram " << histoname.str() << std::endl;
0138 TH1D* hist = (TH1D*)rootfile->FindObjectAny(histoname.str().c_str());
0139 if (hist) {
0140 if (debugPrint)
0141 std::cout << histoname.str() << " found!" << std::endl;
0142 std::stringstream histoname_reorder;
0143 histoname_reorder << OCCUPANCYPREFIX << "_reorder_" << detid;
0144 TH1D* hist_reorder = new TH1D(histoname_reorder.str().c_str(),
0145 histoname_reorder.str().c_str(),
0146 hist->GetXaxis()->GetNbins(),
0147 hist->GetXaxis()->GetXmin(),
0148 hist->GetXaxis()->GetXmax());
0149 for (int i = 0; i < hist_reorder->GetNbinsX(); i++) {
0150 int chan = getChannelNumber(i);
0151 hist_reorder->SetBinContent(i + 1, hist->GetBinContent(chan));
0152 }
0153 hist->Write();
0154 hist_reorder->Write();
0155 } else {
0156 std::cout << histoname.str() << " NOT found..." << std::endl;
0157 }
0158 }
0159 }
0160 if (th_summary) {
0161 std::string fname = rootfilename;
0162 std::string run = fname.substr(fname.find("R000") + 4, 6);
0163 if (TotalEvents) {
0164 Double_t fac = 1.0 / TotalEvents;
0165 th_summary->Scale(fac);
0166 std::cout << " Run Number " << run << " Events " << TotalEvents << " Total # of Digis " << TotalDigis
0167 << " Av. Digis " << TotalDigis * fac << std::endl;
0168 th_summary->SetEntries(TotalDigis * fac);
0169 }
0170 th_summary->Write();
0171 printPlot(th_summary, prefix, postfix);
0172 }
0173
0174 outrootfile->Close();
0175
0176 return 0;
0177 }
0178
0179 void printPlot(TH1D* hist, char* prefix, char* postfix) {
0180 TCanvas* cc = new TCanvas;
0181 hist->Draw();
0182 std::stringstream filename;
0183 filename << prefix << hist->GetName() << postfix << ".png";
0184 cc->Print(filename.str().c_str());
0185 delete cc;
0186 }
0187 int getChannelNumber(int ival) {
0188 int chan = int(32 * fmod(int(fmod(ival, 256.) / 2.), 4.) + 8 * int(int(fmod(ival, 256.) / 2.) / 4.) -
0189 31 * int(int(fmod(ival, 256.) / 2.) / 16.) + fmod(fmod(ival, 256.), 2.) * 128 + int(ival / 256) * 256);
0190 return chan;
0191 }