File indexing completed on 2025-08-05 08:12:18
0001
0002 #include <string>
0003 #include <iostream>
0004 #include <iomanip>
0005 #include <fstream>
0006 #include <filesystem>
0007
0008
0009 #include <TH2F.h>
0010 #include <TFile.h>
0011
0012
0013 #include <cdbobjects/CDBTTree.h>
0014
0015
0016 #include <calobase/TowerInfoDefs.h>
0017
0018 using std::cout;
0019 using std::cerr;
0020 using std::endl;
0021 using std::string;
0022 using std::to_string;
0023 using std::vector;
0024 using std::stringstream;
0025 using std::min;
0026 using std::max;
0027 using std::ofstream;
0028
0029 namespace myAnalysis {
0030 void analyze(const string& inputFile, const string &output);
0031
0032 UInt_t ntowers = 24576;
0033 Float_t threshold;
0034 string fieldName = "status";
0035 }
0036
0037 void myAnalysis::analyze(const string& inputFile, const string &output) {
0038 TFile input(inputFile.c_str());
0039
0040 auto hRunStatus = (TH1F *) input.Get("hRunStatus");
0041
0042 Float_t norm = hRunStatus->GetBinContent(1);
0043 Float_t norm_chi2 = hRunStatus->GetBinContent(2);
0044
0045 auto hBadTowersDead = (TH1F *) input.Get("hBadTowersDead");
0046 auto hBadTowersHot = (TH1F *) input.Get("hBadTowersHot");
0047 auto hBadTowersCold = (TH1F *) input.Get("hBadTowersCold");
0048 auto hBadTowersHotChi2 = (TH1F *) input.Get("hBadTowersHotChi2");
0049
0050 auto cdbttree = new CDBTTree(output);
0051
0052 if (norm != 0)
0053 {
0054 hBadTowersDead->Scale(1. / norm);
0055 hBadTowersHot->Scale(1. / norm);
0056 hBadTowersCold->Scale(1. / norm);
0057 }
0058
0059 if (norm_chi2 != 0)
0060 {
0061 hBadTowersHotChi2->Scale(1. / norm_chi2);
0062 }
0063
0064 UInt_t ctr[5] = {0};
0065 for (UInt_t i = 0; i < ntowers; ++i)
0066 {
0067 UInt_t key = TowerInfoDefs::encode_emcal(i);
0068 Int_t val = 0;
0069 if (hBadTowersDead->GetBinContent(i+1) >= threshold)
0070 {
0071 val = 1;
0072 ++ctr[1];
0073 }
0074 else if (hBadTowersHot->GetBinContent(i+1) >= threshold)
0075 {
0076 val = 2;
0077 ++ctr[2];
0078 }
0079 else if (hBadTowersCold->GetBinContent(i+1) >= threshold)
0080 {
0081 val = 3;
0082 ++ctr[3];
0083 }
0084 else if (hBadTowersHotChi2->GetBinContent(i+1) >= threshold)
0085 {
0086 val = 4;
0087 ++ctr[4];
0088 }
0089 else {
0090 ++ctr[0];
0091 }
0092
0093 cdbttree->SetIntValue(key, fieldName, val);
0094 }
0095
0096 cdbttree->Commit();
0097 cdbttree->WriteCDBTTree();
0098
0099 delete cdbttree;
0100
0101 cout << "=======" << endl;
0102 cout << "Stats" << endl;
0103 cout << "Good: " << ctr[0] << ", " << ctr[0]*100./ntowers << " %" << endl;
0104 cout << "Dead: " << ctr[1] << ", " << ctr[1]*100./ntowers << " %" << endl;
0105 cout << "Hot: " << ctr[2] << ", " << ctr[2]*100./ntowers << " %" << endl;
0106 cout << "Cold: " << ctr[3] << ", " << ctr[3]*100./ntowers << " %" << endl;
0107 cout << "Bad Chi2: " << ctr[4] << ", " << ctr[4]*100./ntowers << " %" << endl;
0108
0109 input.Close();
0110 }
0111
0112 void genCDBTTree(const string &input, const Float_t threshold = 0.5, const string &output="test.root") {
0113 cout << "#############################" << endl;
0114 cout << "Run Parameters" << endl;
0115 cout << "input: " << input << endl;
0116 cout << "threshold: " << threshold << endl;
0117 cout << "output: " << output << endl;
0118 cout << "#############################" << endl;
0119
0120 myAnalysis::threshold = threshold;
0121
0122 myAnalysis::analyze(input, output);
0123 }
0124
0125 # ifndef __CINT__
0126 Int_t main(Int_t argc, char* argv[]) {
0127 if(argc < 2 || argc > 4){
0128 cout << "usage: ./genCDBTTree.C input [threshold] [output]" << endl;
0129 cout << "input: input root file" << endl;
0130 cout << "threshold: frequently bad threshold. Default: 0.5" << endl;
0131 cout << "output: output file. Default: test.root " << endl;
0132 return 1;
0133 }
0134
0135 Float_t threshold = 0.5;
0136 string output = "test.root";
0137
0138 if(argc >= 3) {
0139 threshold = atof(argv[2]);
0140 }
0141 if(argc >= 4) {
0142 output = argv[3];
0143 }
0144
0145 genCDBTTree(argv[1], threshold, output);
0146
0147 cout << "======================================" << endl;
0148 cout << "done" << endl;
0149 return 0;
0150 }
0151 # endif