Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:12:18

0001 // -- c++ includes --
0002 #include <string>
0003 #include <iostream>
0004 #include <iomanip>
0005 #include <fstream>
0006 
0007 // -- root includes --
0008 #include <TH1F.h>
0009 #include <TFile.h>
0010 
0011 // -- Tower Info
0012 #include <calobase/TowerInfoDefs.h>
0013 
0014 using std::cout;
0015 using std::cerr;
0016 using std::endl;
0017 using std::string;
0018 using std::to_string;
0019 using std::vector;
0020 using std::stringstream;
0021 using std::min;
0022 using std::max;
0023 using std::ofstream;
0024 
0025 R__LOAD_LIBRARY(libcalo_io.so)
0026 
0027 namespace myAnalysis {
0028     void analyze(const string& i_input, const string &output, const string &log);
0029 
0030     UInt_t  m_ntowers = 24576;
0031     Float_t m_threshold;
0032     Float_t m_thresholdNoise;
0033     string m_detector = "CEMC";
0034     // string m_detector = "HCAL";
0035 }
0036 
0037 void myAnalysis::analyze(const string& i_input, const string &output, const string &log) {
0038     TFile input(i_input.c_str());
0039 
0040     auto hBadTowersHot  = (TH1F*)input.Get("hBadTowersHot");
0041 
0042     ofstream f(output);
0043     f << "Hot Tower Index,Reference Tower Index" << endl;
0044 
0045     ofstream f_l(log);
0046     f_l << "Hot Phi,Hot Eta,Runs Hot,Ref Phi,Ref Eta,Hot Ref Runs,Phi Distance" << endl;
0047 
0048     for(UInt_t i = 1; i <= m_ntowers; ++i) {
0049         UInt_t towerIndex = i-1;
0050         UInt_t key    = (m_detector == "CEMC") ? TowerInfoDefs::encode_emcal(towerIndex) : TowerInfoDefs::encode_hcal(towerIndex);
0051         UInt_t etabin = TowerInfoDefs::getCaloTowerEtaBin(key);
0052         UInt_t phibin = TowerInfoDefs::getCaloTowerPhiBin(key);
0053 
0054         UInt_t towerIndexRef = 0;
0055         UInt_t nHotRuns = hBadTowersHot->GetBinContent(i);
0056 
0057         if(nHotRuns >= m_threshold) {
0058             UInt_t j = 1;
0059             UInt_t towerIndexRef = 0;
0060             UInt_t nRuns = 0;
0061             while(1) {
0062                 UInt_t towerIndexRight = (m_detector == "CEMC") ? TowerInfoDefs::decode_emcal(TowerInfoDefs::encode_emcal(etabin, phibin+j))
0063                                                                 : TowerInfoDefs::decode_hcal(TowerInfoDefs::encode_hcal(etabin, phibin+j));
0064                 UInt_t towerIndexLeft  = (m_detector == "CEMC") ? TowerInfoDefs::decode_emcal(TowerInfoDefs::encode_emcal(etabin, phibin-j))
0065                                                                 : TowerInfoDefs::decode_hcal(TowerInfoDefs::encode_hcal(etabin, phibin-j));
0066                 UInt_t nRunsRight = hBadTowersHot->GetBinContent(towerIndexRight+1);
0067                 UInt_t nRunsLeft  = hBadTowersHot->GetBinContent(towerIndexLeft+1);
0068 
0069                 nRuns         = nRunsRight;
0070                 towerIndexRef = towerIndexRight;
0071 
0072                 if(nRunsLeft < nRunsRight) {
0073                     nRuns         = nRunsLeft;
0074                     towerIndexRef = towerIndexLeft;
0075                 }
0076 
0077                 if(nRuns < m_thresholdNoise) break;
0078 
0079                 ++j;
0080             }
0081             UInt_t keyRef    = (m_detector == "CEMC") ? TowerInfoDefs::encode_emcal(towerIndexRef)
0082                                                       : TowerInfoDefs::encode_hcal(towerIndexRef);
0083             UInt_t etabinRef = TowerInfoDefs::getCaloTowerEtaBin(keyRef);
0084             UInt_t phibinRef = TowerInfoDefs::getCaloTowerPhiBin(keyRef);
0085 
0086             cout << "Hot: " << phibin << ", " << etabin << ", Runs: " << nHotRuns
0087                  << ", Ref: " << phibinRef << ", " << etabinRef
0088                  << ", j: " << j
0089                  << ", Runs: " << nRuns << endl;
0090 
0091             f_l << phibin << ","
0092                 << etabin << ","
0093                 << nHotRuns << ","
0094                 << phibinRef << ","
0095                 << etabinRef << ","
0096                 << nRuns << ","
0097                 << j << endl;
0098 
0099             f << towerIndex << "," << towerIndexRef << endl;
0100         }
0101     }
0102 
0103     f.close();
0104     f_l.close();
0105 }
0106 
0107 void genHotTowerList(const string &input, Int_t threshold = 400, Int_t thresholdNoise = 20, const string &output="hot.list", const string &log="log.csv") {
0108     cout << "#############################" << endl;
0109     cout << "Run Parameters" << endl;
0110     cout << "input: "  << input << endl;
0111     cout << "output: " << output << endl;
0112     cout << "log: " << log << endl;
0113     cout << "threshold: " << threshold << endl;
0114     cout << "Noise threshold: " << thresholdNoise << endl;
0115     cout << "#############################" << endl;
0116 
0117     myAnalysis::m_threshold      = threshold;
0118     myAnalysis::m_thresholdNoise = thresholdNoise;
0119 
0120     if(myAnalysis::m_detector == "HCAL") {
0121         myAnalysis::m_ntowers = 1536;
0122     }
0123 
0124     myAnalysis::analyze(input, output, log);
0125 }
0126 
0127 # ifndef __CINT__
0128 Int_t main(Int_t argc, char* argv[]) {
0129 if(argc < 2 || argc > 6){
0130         cout << "usage: ./genHotTowerList input [threshold] [thresholdNoise] [output] [log]" << endl;
0131         cout << "input: input root file" << endl;
0132         cout << "threshold: minimum number of runs to be considered frequently hot. Default: 400" << endl;
0133         cout << "thresholdNoise: maximum number of runs to be considered not hot frequently. Default: 20" << endl;
0134         cout << "output: output hot tower list. Default: hot.list" << endl;
0135         cout << "log: processing log. Default: log.txt" << endl;
0136         return 1;
0137     }
0138 
0139     Int_t threshold      = 400;
0140     Int_t thresholdNoise = 20;
0141     string output        = "hot.list";
0142     string log           = "log.csv";
0143 
0144     if(argc >= 3) {
0145         threshold = atoi(argv[2]);
0146     }
0147     if(argc >= 4) {
0148         thresholdNoise = atoi(argv[3]);
0149     }
0150     if(argc >= 5) {
0151         output = argv[4];
0152     }
0153     if(argc >= 5) {
0154         log = argv[5];
0155     }
0156 
0157     genHotTowerList(argv[1], threshold, thresholdNoise, output, log);
0158 
0159     cout << "======================================" << endl;
0160     cout << "done" << endl;
0161     return 0;
0162 }
0163 # endif