Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:01:35

0001 /*
0002  * Make some convenient Ecal function available in python
0003  * 
0004  * \author Stefano Argiro
0005  * \version $Id: EcalPyUtils.cc,v 1.6 2012/07/17 09:17:11 davidlt Exp $
0006  */
0007 
0008 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0009 #include "DataFormats/EcalDetId/interface/EEDetId.h"
0010 #include "CondTools/Ecal/interface/EcalFloatCondObjectContainerXMLTranslator.h"
0011 #include <pybind11/pybind11.h>
0012 namespace py = pybind11;
0013 
0014 namespace ecalpyutils {
0015 
0016   std::vector<int> hashedIndexToEtaPhi(int hashedindex) {
0017     int ieta = EBDetId::unhashIndex(hashedindex).ieta();
0018     int iphi = EBDetId::unhashIndex(hashedindex).iphi();
0019     std::vector<int> ret;
0020     ret.push_back(ieta);
0021     ret.push_back(iphi);
0022     return ret;
0023   }
0024 
0025   std::vector<int> hashedIndexToXY(int hashedindex) {
0026     int ix = EEDetId::unhashIndex(hashedindex).ix();
0027     int iy = EEDetId::unhashIndex(hashedindex).iy();
0028     int zside = EEDetId::unhashIndex(hashedindex).zside();
0029     std::vector<int> ret;
0030     ret.push_back(ix);
0031     ret.push_back(iy);
0032     ret.push_back(zside);
0033     return ret;
0034   }
0035 
0036   int hashedIndex(int ieta, int iphi) {
0037     EBDetId d(ieta, iphi);
0038     return d.hashedIndex();
0039   }
0040 
0041   int hashedIndexEE(int ix, int iy, int iz) {
0042     if (EEDetId::validDetId(ix, iy, iz)) {
0043       EEDetId d(ix, iy, iz);
0044       return d.hashedIndex();
0045     }
0046     return 0;
0047   }
0048 
0049   int ism(int ieta, int iphi) {
0050     EBDetId d(ieta, iphi);
0051     return d.ism();
0052   }
0053 
0054   std::string arraystoXML(const std::vector<float>& eb, const std::vector<float>& ee) {
0055     EcalCondHeader h;
0056     return EcalFloatCondObjectContainerXMLTranslator::dumpXML(h, eb, ee);
0057   }
0058 }  // namespace ecalpyutils
0059 
0060 PYBIND11_MODULE(pluginEcalPyUtils, m) {
0061   //   looks like these are already defined somewhere
0062 
0063   //   python access to stl integer vectors
0064   //   class_< std::vector<int> >("vectorInt")
0065   //     .def(vector_indexing_suite<std::vector<int> >())
0066   //   ;
0067 
0068   //   class_< std::vector<float> >("vectorFloat")
0069   //     .def(vector_indexing_suite<std::vector<float> >())
0070   //   ;
0071 
0072   m.def("hashedIndexToEtaPhi", &ecalpyutils::hashedIndexToEtaPhi);
0073   m.def("hashedIndexToXY", &ecalpyutils::hashedIndexToXY);
0074   m.def("hashedIndex", &ecalpyutils::hashedIndex);
0075   m.def("hashedIndexEE", &ecalpyutils::hashedIndexEE);
0076   m.def("ism", &ecalpyutils::ism);
0077   m.def("barrelfromXML", &EcalFloatCondObjectContainerXMLTranslator::barrelfromXML);
0078   m.def("endcapfromXML", &EcalFloatCondObjectContainerXMLTranslator::endcapfromXML);
0079   m.def("arraystoXML", &ecalpyutils::arraystoXML);
0080 }