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 
29 #include <zlib.h>
30 #include <strings.h>
31 
32 //
33 // constructors and destructor
34 //
36  mapFile_(iConfig.getUntrackedParameter<std::string>("MapFile","")),
37  mapAuto_(iConfig.getUntrackedParameter<bool>("MapAuto",false)),
38  skipHE_(iConfig.getUntrackedParameter<bool>("SkipHE",false)) {
39  //the following line is needed to tell the framework what
40  // data is being produced
41  setWhatProduced(this);
42 
43 //now do what ever other initialization is needed
44 }
45 
46 
48 
49 
50 //
51 // member functions
52 //
53 
54 void
56 {
58  desc.addUntracked<std::string>( "MapFile", "" );
59  desc.addUntracked<bool>( "MapAuto", false );
60  desc.addUntracked<bool>( "SkipHE", false );
61  descriptions.add( "caloTowerConstituents", desc );
62 }
63 
64 // ------------ method called to produce the data ------------
67 {
69  iRecord.getRecord<HcalRecNumberingRecord>().get(hcaltopo);
70 
72  iRecord.getRecord<HcalRecNumberingRecord>().get(cttopo);
73 
74  auto prod = std::make_unique<CaloTowerConstituentsMap>( &*hcaltopo, &*cttopo );
75 
76 //auto prod = std::make_unique<CaloTowerConstituentsMap>( &*hcaltopo );
77 
78  //keep geometry pointer as member for alternate EE->HE mapping
80  iRecord.get(pG);
81  const CaloGeometry* geometry = pG.product();
82 
83  prod->useStandardHB(true);
84  if(!skipHE_) prod->useStandardHE(true);
85  prod->useStandardHF(true);
86  prod->useStandardHO(true);
87  prod->useStandardEB(true);
88 
89  if (!mapFile_.empty()) {
91  } else if (mapAuto_ && !skipHE_) {
92  assignEEtoHE(geometry, *prod, &*cttopo);
93  }
94  prod->sort();
95 
96  return prod;
97 }
98 
99 void
101 
102  edm::FileInPath eff( filename );
103 
104  gzFile gzed = gzopen( eff.fullPath().c_str(), "rb" );
105 
106  while( !gzeof( gzed )) {
107  char line[1024];
108  int ieta, iphi, rawid;
109  if( nullptr != gzgets( gzed, line, 1023 )) {
110  if( index( line, '#' ) != nullptr )*( index( line, '#' )) = 0;
111  int ct = sscanf( line, "%i %d %d", &rawid, &ieta, &iphi );
112  if( ct == 3 ) {
113  DetId detid( rawid );
114  CaloTowerDetId tid( ieta, iphi );
115  theMap.assign( detid, tid );
116  }
117  }
118  }
119  gzclose( gzed );
120 }
121 
122 //algorithm to assign EE cells to HE towers if no text map is provided
124  //get EE and HE geometries
126  if(geomEE==nullptr) return; // if no EE is defined don't know where it is used
127 
129 
130  //get list of EE detids
131  const std::vector<DetId>& vec(geomEE->getValidDetIds());
132  //loop over EE detids
133  for(auto detId_itr : vec){
134  //get detid position
135  auto cellGeometry = geomEE->getGeometry(detId_itr);
136  const GlobalPoint& gp (cellGeometry->getPosition()) ;
137 
138  //find closest HE cell
139  HcalDetId closestCell (geomHE->getClosestCell(gp)) ;
140 
141  //assign to appropriate CaloTower
142  CaloTowerDetId tid(cttopo->convertHcaltoCT(closestCell.ietaAbs(),closestCell.subdet())*closestCell.zside(), closestCell.iphi());
143  theMap.assign(detId_itr,tid);
144  }
145 }
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:49
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:124
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
int convertHcaltoCT(int hcal_ieta, HcalSubdetector subdet) const
CaloTowerConstituentsMapBuilder(const edm::ParameterSet &)
#define nullptr
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)
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const
void assign(const DetId &cell, const CaloTowerDetId &tower)
set the association between a DetId and a tower
ReturnType produce(const CaloGeometryRecord &)
virtual DetId getClosestCell(const GlobalPoint &r) const
Definition: DetId.h:18
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.
std::unique_ptr< CaloTowerConstituentsMap > ReturnType
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::string fullPath() const
Definition: FileInPath.cc:163
void assignEEtoHE(const CaloGeometry *geometry, CaloTowerConstituentsMap &theMap, const CaloTowerTopology *cttopo)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void parseTextMap(const std::string &filename, CaloTowerConstituentsMap &theMap)