File indexing completed on 2025-08-05 08:12:17
0001
0002 #include <string>
0003 #include <iostream>
0004 #include <iomanip>
0005 #include <fstream>
0006 #include <unordered_set>
0007
0008
0009 #include <TSystem.h>
0010 #include <TROOT.h>
0011 #include <TH2F.h>
0012 #include <TFile.h>
0013 #include <TMath.h>
0014 #include <TDatime.h>
0015 #include <TGraph.h>
0016
0017 #include <calobase/TowerInfoDefs.h>
0018
0019 using std::cout;
0020 using std::cerr;
0021 using std::endl;
0022 using std::string;
0023 using std::stringstream;
0024 using std::ofstream;
0025 using std::vector;
0026 using std::pair;
0027 using std::min;
0028 using std::max;
0029 using std::unordered_set;
0030
0031 R__LOAD_LIBRARY(libcalo_io.so)
0032
0033 namespace myAnalysis {
0034 Int_t process(const string &input, const string &output);
0035
0036 string m_detector = "CEMC";
0037 }
0038
0039 Int_t myAnalysis::process(const string &input, const string &output) {
0040 std::ifstream file(input);
0041 ofstream f(output);
0042
0043 f << "Hot Tower Index,Reference Tower Index" << endl;
0044
0045
0046 if (!file.is_open()) {
0047 cerr << "Failed to open file: " << input << endl;
0048 return 1;
0049 }
0050
0051 string line;
0052
0053
0054 std::getline(file, line);
0055
0056
0057 while (std::getline(file, line)) {
0058 std::istringstream lineStream(line);
0059
0060 UInt_t phibin;
0061 UInt_t etabin;
0062 char comma;
0063
0064 if (lineStream >> phibin >> comma >> etabin) {
0065 UInt_t towerIndex = (m_detector == "CEMC") ? TowerInfoDefs::decode_emcal(TowerInfoDefs::encode_emcal(etabin, phibin)) :
0066 TowerInfoDefs::decode_hcal(TowerInfoDefs::encode_hcal(etabin, phibin));
0067 cout << "iphi: " << phibin << ", ieta: " << etabin << ", towerIndex: " << towerIndex << endl;
0068
0069 f << towerIndex << "," << towerIndex << endl;
0070 }
0071 else {
0072 cerr << "Failed to parse line: " << line << endl;
0073 return 1;
0074 }
0075 }
0076
0077
0078 file.close();
0079 f.close();
0080
0081 return 0;
0082 }
0083
0084 void convertHotList(const string &input,
0085 const string &output="hot.list") {
0086
0087 cout << "#############################" << endl;
0088 cout << "Input Parameters" << endl;
0089 cout << "input: " << input << endl;
0090 cout << "output: " << output << endl;
0091
0092 cout << "Detector: " << myAnalysis::m_detector << endl;
0093
0094 Int_t ret = myAnalysis::process(input, output);
0095 if(ret) return;
0096
0097 cout << "======================================" << endl;
0098 cout << "done" << endl;
0099 std::quick_exit(0);
0100 }
0101
0102 # ifndef __CINT__
0103 Int_t main(Int_t argc, char* argv[]) {
0104 if(argc < 2 || argc > 3) {
0105 cout << "usage: ./hotAna inputFile hotList [outputFile]" << endl;
0106 cout << "inputFile: containing list of hot towers" << endl;
0107 cout << "outputFile: hot tower list by tower index." << endl;
0108 return 1;
0109 }
0110
0111 string outputFile = "hotIndex.list";
0112
0113 if (argc >= 3) {
0114 outputFile = argv[2];
0115 }
0116
0117 convertHotList(argv[1], outputFile);
0118
0119 return 0;
0120 }
0121 # endif