File indexing completed on 2024-04-06 11:59:28
0001 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0003 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0004 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
0005 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0006 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
0007 #include "CondFormats/DataRecord/interface/EcalIntercalibConstantsRcd.h"
0008 #include "Calibration/Tools/interface/calibXMLwriter.h"
0009 #include "CalibCalorimetry/CaloMiscalibTools/interface/CaloMiscalibTools.h"
0010 #include "CalibCalorimetry/CaloMiscalibTools/interface/CaloMiscalibMapEcal.h"
0011 #include "CalibCalorimetry/CaloMiscalibTools/interface/MiscalibReaderFromXMLEcalBarrel.h"
0012 #include "CalibCalorimetry/CaloMiscalibTools/interface/MiscalibReaderFromXMLEcalEndcap.h"
0013 #include "CondFormats/EcalObjects/interface/EcalIntercalibConstants.h"
0014 #include "FWCore/Framework/interface/EventSetup.h"
0015 #include "FWCore/Framework/interface/ESHandle.h"
0016
0017
0018 #include "Calibration/Tools/bin/trivialParser.h"
0019
0020 #include "TH2.h"
0021 #include "TH1.h"
0022 #include "TFile.h"
0023
0024 #include <sstream>
0025 #include <string>
0026
0027 inline double degrees(double radiants) { return radiants * 180 * (1 / M_PI); }
0028
0029
0030
0031 int EEregionCheck(int ics, int ips, int radStart, int radEnd, int phiStart, int phiEnd) {
0032 int x = ics - 50;
0033 int y = ips - 50;
0034 double radius2 = x * x + y * y;
0035 if (radius2 < 10 * 10)
0036 return 1;
0037 if (radius2 > 50 * 50)
0038 return 1;
0039 if (radius2 < radStart * radStart)
0040 return 2;
0041 if (radius2 >= radEnd * radEnd)
0042 return 2;
0043 double phi = atan2(static_cast<double>(y), static_cast<double>(x));
0044 phi = degrees(phi);
0045 if (phi < 0)
0046 phi += 360;
0047 if (phiStart < phiEnd && phi > phiStart && phi < phiEnd)
0048 return 0;
0049 if (phiStart > phiEnd && (phi > phiStart || phi < phiEnd))
0050 return 0;
0051 return 3;
0052 }
0053
0054
0055
0056 inline int radShifter(const int radOld) {
0057 if (radOld < 0)
0058 return radOld + 85;
0059 else if (radOld > 0)
0060 return radOld + 84;
0061 assert(false);
0062 }
0063
0064
0065
0066 int main(int argc, char* argv[]) {
0067 std::cout << "parsing cfg file: " << argv[1] << std::endl;
0068 trivialParser configParams(static_cast<std::string>(argv[1]));
0069
0070 int IMAEEradStart = static_cast<int>(configParams.getVal("IMAEEradStart"));
0071 int IMAEEradEnd = static_cast<int>(configParams.getVal("IMAEEradEnd"));
0072 int IMAEEradWidth = static_cast<int>(configParams.getVal("IMAEEradWidth"));
0073 int IMAEEphiStart = static_cast<int>(configParams.getVal("IMAEEphiStart"));
0074 int IMAEEphiEnd = static_cast<int>(configParams.getVal("IMAEEphiEnd"));
0075
0076
0077
0078
0079
0080
0081
0082
0083 std::string coeffFolder = argv[2];
0084
0085 std::map<int, EcalIntercalibConstantMap> recalibrators;
0086
0087
0088
0089 for (int radIndex = IMAEEradStart; radIndex < IMAEEradEnd; radIndex += IMAEEradWidth) {
0090 int currentIndex = radIndex;
0091 int nextIndex = radIndex + IMAEEradWidth;
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104 std::stringstream nomeFile;
0105 nomeFile << coeffFolder << "/EEcalibCoeff_" << currentIndex << "-" << nextIndex << ".xml";
0106 std::string fileName = nomeFile.str();
0107
0108
0109
0110 CaloMiscalibMapEcal map;
0111 map.prefillMap();
0112 MiscalibReaderFromXMLEcalEndcap endcapreader(map);
0113 if (!fileName.empty())
0114 endcapreader.parseXMLMiscalibFile(fileName);
0115 EcalIntercalibConstants* constants = new EcalIntercalibConstants(map.get());
0116 recalibrators[currentIndex] = constants->getMap();
0117 }
0118
0119
0120
0121
0122 calibXMLwriter endcapWriter(EcalEndcap);
0123
0124 for (std::map<int, EcalIntercalibConstantMap>::const_iterator itMap = recalibrators.begin();
0125 itMap != recalibrators.end();
0126 ++itMap) {
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139 for (int ix = 0; ix < 100; ++ix)
0140
0141 for (int iy = 0; iy < 100; ++iy) {
0142
0143 if (EEregionCheck(ix, iy, itMap->first, itMap->first + IMAEEradWidth, IMAEEphiStart, IMAEEphiEnd))
0144 continue;
0145
0146 if (!EEDetId::validDetId(ix, iy, 1)) {
0147 std::cerr << "[WARN] elemento " << ix << " " << iy << " 1"
0148 << " scartato" << std::endl;
0149 continue;
0150 }
0151 EEDetId det = EEDetId(ix, iy, 1, EEDetId::XYMODE);
0152 std::cerr << "[INFO] writing " << ix << " " << iy << " 1"
0153 << " " << *(itMap->second.find(det.rawId())) << std::endl;
0154 endcapWriter.writeLine(det, *(itMap->second.find(det.rawId())));
0155
0156 }
0157 }
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171 }