Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:14:23

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 //#include "Calibration/EcalAlCaRecoProducers/interface/trivialParser.h"

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;  //center of the donut

0037   if (radius2 > 50 * 50)
0038     return 1;  //outer part of the donut

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   //  std::cerr << "[PG] IMAEEradStart = " << IMAEEradStart << std::endl ;

0077   //  std::cerr << "[PG] IMAEEradEnd = " << IMAEEradEnd << std::endl ;

0078   //  std::cerr << "[PG] IMAEEradWidth = " << IMAEEradWidth << std::endl ;

0079   //  std::cerr << "[PG] IMAEEphiStart = " << IMAEEphiStart << std::endl ;

0080   //  std::cerr << "[PG] IMAEEphiEnd = " << IMAEEphiEnd << std::endl ;

0081   //  std::cerr << "[PG] IMAEEphiWidth = " << IMAEEphiWidth << std::endl ;

0082 
0083   std::string coeffFolder = argv[2];
0084 
0085   std::map<int, EcalIntercalibConstantMap> recalibrators;
0086   //PG FIXME  c'e' il copy ctor della CaloMiscalibMapEcal?

0087 
0088   //PG loop on EB rad indexes

0089   for (int radIndex = IMAEEradStart; radIndex < IMAEEradEnd; radIndex += IMAEEradWidth) {
0090     int currentIndex = radIndex;
0091     int nextIndex = radIndex + IMAEEradWidth;
0092 
0093     //PG compute the values of the limits

0094     //PG FIXME questo forse non e' sufficiente, bisogna anche considerare il caso

0095     //PG FIXME in cui currentIndex e' positivo e effradIndex start no

0096     //PG FIXME lo stesso vale per l'end e il nexindex

0097     //PG FIXME lo stesso vale per gli script perl

0098     //      int effradIndexStart = currentIndex - IMAEEradWidth ;

0099     //      if (effradIndexStart < 0) { effradIndexStart = 0 ; }

0100     //      int effradIndexEnd = nextIndex + IMAEEradWidth ;

0101     //      if (effradIndexEnd > 50) { effradIndexEnd = 50 ; }

0102 
0103     //PG build the filename

0104     std::stringstream nomeFile;
0105     nomeFile << coeffFolder << "/EEcalibCoeff_" << currentIndex << "-" << nextIndex << ".xml";
0106     std::string fileName = nomeFile.str();
0107     //      std::cerr << "PG nomefile: " << fileName << std::endl ;

0108 
0109     //PG open the XML file

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   }  //PG loop on EB rad indexes

0118 
0119   //PG prepare the XML to be saved

0120 
0121   //PG this command outputs an XML file with a fixed name

0122   calibXMLwriter endcapWriter(EcalEndcap);
0123   //PG loop on EB rad slices

0124   for (std::map<int, EcalIntercalibConstantMap>::const_iterator itMap = recalibrators.begin();
0125        itMap != recalibrators.end();
0126        ++itMap) {
0127     //PG compute the values of the limits

0128     //PG FIXME questo forse non e' sufficiente, bisogna anche considerare il caso

0129     //PG FIXME in cui currentIndex e' positivo e effradIndex start no

0130     //PG FIXME lo stesso vale per l'end e il nexindex

0131     //PG FIXME lo stesso vale per gli script perl

0132 
0133     //PG non so scegliere da dove partire, questo e' un disastro

0134     //PG il problema e' dei bordi

0135     //PG forse la cosa migliore e' salvare i xml file con un nome che dica dei coeff buoni,

0136     //PG non di quelli calcolati - direi che e' la cosa giusta

0137 
0138     //PG loop over x

0139     for (int ix = 0; ix < 100; ++ix)
0140       //PG loop over y

0141       for (int iy = 0; iy < 100; ++iy) {
0142         //PG select the subregion of interest

0143         if (EEregionCheck(ix, iy, itMap->first, itMap->first + IMAEEradWidth, IMAEEphiStart, IMAEEphiEnd))
0144           continue;
0145         //PG check whether the detid is buildable

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       }  //PG loop over x, loop over y

0157   }
0158 
0159   /* TODOS

0160    - inizio con EB

0161 

0162    - leggi l'intervallo di validita'

0163    - cerca i XML file in funzione di quello che sta scritto nel parser

0164      (qui bisogna conoscere gia' la cartella e costruire i nomi allo stesso

0165       modo, questo e' un punto debole)

0166    - apri un XML interface per ciascun file XML e leggine sono quello

0167      che serve

0168    - riversalo nel XML finale  

0169    - check the includes

0170   */
0171 }