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 int etaShifter(const int etaOld) {
0028   if (etaOld < 0)
0029     return etaOld + 85;
0030   else if (etaOld > 0)
0031     return etaOld + 84;
0032   assert(false);
0033 }
0034 
0035 // ------------------------------------------------------------------------

0036 
0037 int main(int argc, char* argv[]) {
0038   std::cout << "parsing cfg file: " << argv[1] << std::endl;
0039   trivialParser configParams(static_cast<std::string>(argv[1]));
0040 
0041   int IMAEBetaStart = static_cast<int>(configParams.getVal("IMAEBetaStart"));
0042   int IMAEBetaEnd = static_cast<int>(configParams.getVal("IMAEBetaEnd"));
0043   int IMAEBetaWidth = static_cast<int>(configParams.getVal("IMAEBetaWidth"));
0044   int IMAEBphiStart = static_cast<int>(configParams.getVal("IMAEBphiStart"));
0045   int IMAEBphiEnd = static_cast<int>(configParams.getVal("IMAEBphiEnd"));
0046 
0047   //  std::cerr << "[PG] IMAEBetaStart = " << IMAEBetaStart << std::endl ;

0048   //  std::cerr << "[PG] IMAEBetaEnd = " << IMAEBetaEnd << std::endl ;

0049   //  std::cerr << "[PG] IMAEBetaWidth = " << IMAEBetaWidth << std::endl ;

0050   //  std::cerr << "[PG] IMAEBphiStart = " << IMAEBphiStart << std::endl ;

0051   //  std::cerr << "[PG] IMAEBphiEnd = " << IMAEBphiEnd << std::endl ;

0052   //  std::cerr << "[PG] IMAEBphiWidth = " << IMAEBphiWidth << std::endl ;

0053 
0054   std::string coeffFolder = argv[2];
0055 
0056   std::map<int, EcalIntercalibConstantMap> recalibrators;
0057   //PG FIXME  c'e' il copy ctor della CaloMiscalibMapEcal?

0058 
0059   int alreadySwitched = 0;
0060   //PG loop on EB eta indexes

0061   for (int etaIndex = IMAEBetaStart; etaIndex < IMAEBetaEnd; etaIndex += IMAEBetaWidth) {
0062     int currentIndex = etaIndex;
0063     int nextIndex = etaIndex + IMAEBetaWidth;
0064 
0065     //PG to cope with the missing 0

0066     if ((alreadySwitched == 0) && (nextIndex * IMAEBetaStart <= 0)) {
0067       nextIndex += 1;
0068       etaIndex += 1;  //PG this is for the next loop

0069       alreadySwitched = 1;
0070     }
0071 
0072     //PG compute the values of the limits

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

0074     //PG FIXME in cui currentIndex e' positivo e effEtaIndex start no

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

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

0077     //      int effEtaIndexStart = currentIndex - IMAEBetaWidth ;

0078     //      if (effEtaIndexStart < -85) { effEtaIndexStart = -85 ; }

0079     //      int effEtaIndexEnd = nextIndex + IMAEBetaWidth ;

0080     //      if (effEtaIndexEnd > 85) { effEtaIndexEnd = 85 ; }

0081 
0082     //PG build the filename

0083     std::stringstream nomeFile;
0084     nomeFile << coeffFolder << "/EBcalibCoeff_" << currentIndex << "-" << nextIndex << ".xml";
0085     std::string fileName = nomeFile.str();
0086     //      std::cerr << "PG nomefile: " << fileName << std::endl ;

0087 
0088     //PG open the XML file

0089     CaloMiscalibMapEcal map;
0090     map.prefillMap();
0091     MiscalibReaderFromXMLEcalBarrel barrelreader(map);
0092     if (!fileName.empty())
0093       barrelreader.parseXMLMiscalibFile(fileName);
0094     EcalIntercalibConstants* constants = new EcalIntercalibConstants(map.get());
0095     recalibrators[currentIndex] = constants->getMap();
0096   }  //PG loop on EB eta indexes

0097 
0098   //PG prepare the XML to be saved

0099 
0100   //PG this command outputs an XML file with a fixed name

0101   calibXMLwriter barrelWriter(EcalBarrel);
0102   //PG loop on EB eta slices

0103   for (std::map<int, EcalIntercalibConstantMap>::const_iterator itMap = recalibrators.begin();
0104        itMap != recalibrators.end();
0105        ++itMap) {
0106     //PG compute the values of the limits

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

0108     //PG FIXME in cui currentIndex e' positivo e effEtaIndex start no

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

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

0111 
0112     //PG non so scegliere da dove partire, questo e' un disastro

0113     //PG il problema e' dei bordi

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

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

0116 
0117     //PG loop over eta

0118     int etaStop = itMap->first + IMAEBetaWidth;
0119     if (etaStop * itMap->first <= 0)
0120       ++etaStop;
0121     for (int ieta = itMap->first; ieta < etaStop; ++ieta)
0122       //PG loop over phi

0123       for (int iphi = IMAEBphiStart; iphi < IMAEBphiEnd; ++iphi) {
0124         if (!EBDetId::validDetId(ieta, iphi)) {
0125           std::cerr << "[WARN] elemento " << ieta << " " << iphi << " scartato" << std::endl;
0126           continue;
0127         }
0128         EBDetId det = EBDetId(ieta, iphi, EBDetId::ETAPHIMODE);
0129         std::cerr << "[INFO] writing " << ieta << " " << iphi << " " << (*itMap->second.find(det.rawId())) << std::endl;
0130         barrelWriter.writeLine(det, *(itMap->second.find(det.rawId())));
0131       }  //PG loop over phi, loop over eta

0132   }
0133 
0134   /* TODOS

0135    - inizio con EB

0136 

0137    - leggi l'intervallo di validita'

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

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

0140       modo, questo e' un punto debole)

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

0142      che serve

0143    - riversalo nel XML finale  

0144    - check the includes

0145   */
0146 }