CMS 3D CMS Logo

CaloTowerConstituentsMapBuilder.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: CaloTowerConstituentsMapBuilder
4 // Class: CaloTowerConstituentsMapBuilder
5 //
13 //
14 // Original Author: Jeremiah Mans
15 // Created: Mon Oct 3 11:35:27 CDT 2005
16 //
17 //
18 
26 #include <zlib.h>
27 #include <strings.h>
28 
29 //
30 // constructors and destructor
31 //
33  : mapFile_(iConfig.getUntrackedParameter<std::string>("MapFile", "")),
34  mapAuto_(iConfig.getUntrackedParameter<bool>("MapAuto", false)),
35  skipHE_(iConfig.getUntrackedParameter<bool>("SkipHE", false)) {
36  //the following line is needed to tell the framework what
37  // data is being produced
38  auto cc = setWhatProduced(this);
39 
43 
44  //now do what ever other initialization is needed
45 }
46 
48 
49 //
50 // member functions
51 //
52 
55  desc.addUntracked<std::string>("MapFile", "");
56  desc.addUntracked<bool>("MapAuto", false);
57  desc.addUntracked<bool>("SkipHE", false);
58  descriptions.add("caloTowerConstituents", desc);
59 }
60 
61 // ------------ method called to produce the data ------------
63  const auto& hcaltopo = iRecord.get(hcaltopoToken_);
64  const auto& cttopo = iRecord.get(cttopoToken_);
65 
66  auto prod = std::make_unique<CaloTowerConstituentsMap>(&hcaltopo, &cttopo);
67 
68  //auto prod = std::make_unique<CaloTowerConstituentsMap>( &hcaltopo );
69 
70  //keep geometry pointer as member for alternate EE->HE mapping
71  const CaloGeometry& geometry = iRecord.get(geometryToken_);
72 
73  prod->useStandardHB(true);
74  if (!skipHE_)
75  prod->useStandardHE(true);
76  prod->useStandardHF(true);
77  prod->useStandardHO(true);
78  prod->useStandardEB(true);
79 
80  if (!mapFile_.empty()) {
82  } else if (mapAuto_ && !skipHE_) {
83  assignEEtoHE(&geometry, *prod, &cttopo);
84  }
85  prod->sort();
86 
87  return prod;
88 }
89 
92 
93  gzFile gzed = gzopen(eff.fullPath().c_str(), "rb");
94 
95  while (!gzeof(gzed)) {
96  char line[1024];
97  int ieta, iphi, rawid;
98  if (nullptr != gzgets(gzed, line, 1023)) {
99  if (index(line, '#') != nullptr)
100  *(index(line, '#')) = 0;
101  int ct = sscanf(line, "%i %d %d", &rawid, &ieta, &iphi);
102  if (ct == 3) {
103  DetId detid(rawid);
104  CaloTowerDetId tid(ieta, iphi);
105  theMap.assign(detid, tid);
106  }
107  }
108  }
109  gzclose(gzed);
110 }
111 
112 //algorithm to assign EE cells to HE towers if no text map is provided
114  CaloTowerConstituentsMap& theMap,
115  const CaloTowerTopology* cttopo) {
116  //get EE and HE geometries
117  const CaloSubdetectorGeometry* geomEE = geometry->getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
118  if (geomEE == nullptr)
119  return; // if no EE is defined don't know where it is used
120 
121  const CaloSubdetectorGeometry* geomHE = geometry->getSubdetectorGeometry(DetId::Hcal, HcalEndcap);
122 
123  //get list of EE detids
124  const std::vector<DetId>& vec(geomEE->getValidDetIds());
125  //loop over EE detids
126  for (auto detId_itr : vec) {
127  //get detid position
128  auto cellGeometry = geomEE->getGeometry(detId_itr);
129  const GlobalPoint& gp(cellGeometry->getPosition());
130 
131  //find closest HE cell
132  HcalDetId closestCell(geomHE->getClosestCell(gp));
133 
134  //assign to appropriate CaloTower
135  CaloTowerDetId tid(cttopo->convertHcaltoCT(closestCell.ietaAbs(), closestCell.subdet()) * closestCell.zside(),
136  closestCell.iphi());
137  theMap.assign(detId_itr, tid);
138  }
139 }
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:163
std::string fullPath() const
Definition: FileInPath.cc:161
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > geometryToken_
CaloTowerConstituentsMapBuilder(const edm::ParameterSet &)
edm::ESGetToken< CaloTowerTopology, HcalRecNumberingRecord > cttopoToken_
int convertHcaltoCT(int hcal_ieta, HcalSubdetector subdet) const
virtual const std::vector< DetId > & getValidDetIds(DetId::Detector det=DetId::Detector(0), int subdet=0) const
Get a list of valid detector ids (for the given subdetector)
edm::ESGetToken< HcalTopology, HcalRecNumberingRecord > hcaltopoToken_
void assign(const DetId &cell, const CaloTowerDetId &tower)
set the association between a DetId and a tower
ReturnType produce(const CaloGeometryRecord &)
virtual std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
virtual DetId getClosestCell(const GlobalPoint &r) const
Definition: DetId.h:17
std::unique_ptr< CaloTowerConstituentsMap > ReturnType
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void assignEEtoHE(const CaloGeometry *geometry, CaloTowerConstituentsMap &theMap, const CaloTowerTopology *cttopo)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const
void parseTextMap(const std::string &filename, CaloTowerConstituentsMap &theMap)