Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:07:35

0001 // -*- C++ -*-
0002 //
0003 // Package:    CaloTowerConstituentsMapBuilder
0004 // Class:      CaloTowerConstituentsMapBuilder
0005 //
0006 /**\class CaloTowerConstituentsMapBuilder CaloTowerConstituentsMapBuilder.h tmp/CaloTowerConstituentsMapBuilder/interface/CaloTowerConstituentsMapBuilder.h
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Jeremiah Mans
0015 //         Created:  Mon Oct  3 11:35:27 CDT 2005
0016 //
0017 //
0018 
0019 #include "Geometry/CaloEventSetup/plugins/CaloTowerConstituentsMapBuilder.h"
0020 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
0021 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
0022 #include "DataFormats/EcalDetId/interface/EEDetId.h"
0023 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
0024 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0025 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0026 #include <zlib.h>
0027 #include <strings.h>
0028 
0029 //
0030 // constructors and destructor
0031 //
0032 CaloTowerConstituentsMapBuilder::CaloTowerConstituentsMapBuilder(const edm::ParameterSet& iConfig)
0033     : mapFile_(iConfig.getUntrackedParameter<std::string>("MapFile", "")),
0034       mapAuto_(iConfig.getUntrackedParameter<bool>("MapAuto", false)),
0035       skipHE_(iConfig.getUntrackedParameter<bool>("SkipHE", false)) {
0036   //the following line is needed to tell the framework what
0037   // data is being produced
0038   auto cc = setWhatProduced(this);
0039 
0040   hcaltopoToken_ = cc.consumesFrom<HcalTopology, HcalRecNumberingRecord>(edm::ESInputTag{});
0041   cttopoToken_ = cc.consumesFrom<CaloTowerTopology, HcalRecNumberingRecord>(edm::ESInputTag{});
0042   geometryToken_ = cc.consumes<CaloGeometry>(edm::ESInputTag{});
0043 
0044   //now do what ever other initialization is needed
0045 }
0046 
0047 CaloTowerConstituentsMapBuilder::~CaloTowerConstituentsMapBuilder() {}
0048 
0049 //
0050 // member functions
0051 //
0052 
0053 void CaloTowerConstituentsMapBuilder::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0054   edm::ParameterSetDescription desc;
0055   desc.addUntracked<std::string>("MapFile", "");
0056   desc.addUntracked<bool>("MapAuto", false);
0057   desc.addUntracked<bool>("SkipHE", false);
0058   descriptions.add("caloTowerConstituents", desc);
0059 }
0060 
0061 // ------------ method called to produce the data  ------------
0062 CaloTowerConstituentsMapBuilder::ReturnType CaloTowerConstituentsMapBuilder::produce(const CaloGeometryRecord& iRecord) {
0063   const auto& hcaltopo = iRecord.get(hcaltopoToken_);
0064   const auto& cttopo = iRecord.get(cttopoToken_);
0065 
0066   auto prod = std::make_unique<CaloTowerConstituentsMap>(&hcaltopo, &cttopo);
0067 
0068   //auto prod = std::make_unique<CaloTowerConstituentsMap>( &hcaltopo );
0069 
0070   //keep geometry pointer as member for alternate EE->HE mapping
0071   const CaloGeometry& geometry = iRecord.get(geometryToken_);
0072 
0073   prod->useStandardHB(true);
0074   if (!skipHE_)
0075     prod->useStandardHE(true);
0076   prod->useStandardHF(true);
0077   prod->useStandardHO(true);
0078   prod->useStandardEB(true);
0079 
0080   if (!mapFile_.empty()) {
0081     parseTextMap(mapFile_, *prod);
0082   } else if (mapAuto_ && !skipHE_) {
0083     assignEEtoHE(&geometry, *prod, &cttopo);
0084   }
0085   prod->sort();
0086 
0087   return prod;
0088 }
0089 
0090 void CaloTowerConstituentsMapBuilder::parseTextMap(const std::string& filename, CaloTowerConstituentsMap& theMap) {
0091   edm::FileInPath eff(filename);
0092 
0093   gzFile gzed = gzopen(eff.fullPath().c_str(), "rb");
0094 
0095   while (!gzeof(gzed)) {
0096     char line[1024];
0097     int ieta, iphi, rawid;
0098     if (nullptr != gzgets(gzed, line, 1023)) {
0099       if (index(line, '#') != nullptr)
0100         *(index(line, '#')) = 0;
0101       int ct = sscanf(line, "%i %d %d", &rawid, &ieta, &iphi);
0102       if (ct == 3) {
0103         DetId detid(rawid);
0104         CaloTowerDetId tid(ieta, iphi);
0105         theMap.assign(detid, tid);
0106       }
0107     }
0108   }
0109   gzclose(gzed);
0110 }
0111 
0112 //algorithm to assign EE cells to HE towers if no text map is provided
0113 void CaloTowerConstituentsMapBuilder::assignEEtoHE(const CaloGeometry* geometry,
0114                                                    CaloTowerConstituentsMap& theMap,
0115                                                    const CaloTowerTopology* cttopo) {
0116   //get EE and HE geometries
0117   const CaloSubdetectorGeometry* geomEE = geometry->getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
0118   if (geomEE == nullptr)
0119     return;  // if no EE is defined don't know where it is used
0120 
0121   const CaloSubdetectorGeometry* geomHE = geometry->getSubdetectorGeometry(DetId::Hcal, HcalEndcap);
0122 
0123   //get list of EE detids
0124   const std::vector<DetId>& vec(geomEE->getValidDetIds());
0125   //loop over EE detids
0126   for (auto detId_itr : vec) {
0127     //get detid position
0128     auto cellGeometry = geomEE->getGeometry(detId_itr);
0129     const GlobalPoint& gp(cellGeometry->getPosition());
0130 
0131     //find closest HE cell
0132     HcalDetId closestCell(geomHE->getClosestCell(gp));
0133 
0134     //assign to appropriate CaloTower
0135     CaloTowerDetId tid(cttopo->convertHcaltoCT(closestCell.ietaAbs(), closestCell.subdet()) * closestCell.zside(),
0136                        closestCell.iphi());
0137     theMap.assign(detId_itr, tid);
0138   }
0139 }