CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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( 0 != gzgets( gzed, line, 1023 )) {
110  if( index( line, '#' ) != 0 )*( 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==NULL) 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(std::vector<DetId>::const_iterator detId_itr =vec.begin();
134  detId_itr != vec.end(); detId_itr++){
135  //get detid position
136  const CaloCellGeometry* cellGeometry = geomEE->getGeometry(*detId_itr);
137  const GlobalPoint gp ( cellGeometry->getPosition() ) ;
138 
139  //find closest HE cell
140  const HcalDetId closestCell ( geomHE->getClosestCell( gp ) ) ;
141 
142  //assign to appropriate CaloTower
143  CaloTowerDetId tid(cttopo->convertHcaltoCT(closestCell.ietaAbs(),closestCell.subdet())*closestCell.zside(), closestCell.iphi());
144  theMap.assign(*detId_itr,tid);
145  }
146 }
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:45
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
int convertHcaltoCT(int hcal_ieta, HcalSubdetector subdet) const
CaloTowerConstituentsMapBuilder(const edm::ParameterSet &)
#define NULL
Definition: scimark2.h:8
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
Definition: ESProducer.h:115
void get(HolderT &iHolder) const
void assign(const DetId &cell, const CaloTowerDetId &tower)
set the association between a DetId and a tower
ReturnType produce(const CaloGeometryRecord &)
Definition: DetId.h:18
T const * product() const
Definition: ESHandle.h:86
std::unique_ptr< CaloTowerConstituentsMap > ReturnType
void add(std::string const &label, ParameterSetDescription const &psetDescription)
ESHandle< TrackerGeometry > geometry
tuple filename
Definition: lut2db_cfg.py:20
void assignEEtoHE(const CaloGeometry *geometry, CaloTowerConstituentsMap &theMap, const CaloTowerTopology *cttopo)
volatile std::atomic< bool > shutdown_flag false
std::string fullPath() const
Definition: FileInPath.cc:184
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
void parseTextMap(const std::string &filename, CaloTowerConstituentsMap &theMap)