CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/SimTracker/TrackerMaterialAnalysis/plugins/ListIds.cc

Go to the documentation of this file.
00001 #include <string>
00002 #include <vector>
00003 #include <iostream>
00004 
00005 #include "FWCore/Framework/interface/EDAnalyzer.h"
00006 #include "FWCore/Framework/interface/Event.h"
00007 #include "FWCore/Framework/interface/EventSetup.h"
00008 #include "FWCore/Framework/interface/ESHandle.h"
00009 #include "FWCore/Framework/interface/ESTransientHandle.h"
00010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00011 #include "FWCore/Utilities/interface/InputTag.h"
00012 #include "FWCore/ParameterSet/interface/types.h"
00013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00014 
00015 #include "DataFormats/DetId/interface/DetId.h"
00016 #include "DataFormats/Math/interface/Vector3D.h"
00017 #include "DetectorDescription/Core/interface/DDFilteredView.h"
00018 #include "DetectorDescription/Core/interface/DDCompactView.h"
00019 #include "DetectorDescription/Core/interface/DDMaterial.h"
00020 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00021 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00022 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00023 #include "Geometry/TrackerNumberingBuilder/interface/CmsTrackerStringToEnum.h"
00024 #include "Geometry/TrackerNumberingBuilder/interface/GeometricDet.h"
00025 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00026 
00027 static
00028 bool dddGetStringRaw(const DDFilteredView & view, const std::string & name, std::string & value) {
00029   DDValue parameter(name);
00030   std::vector<const DDsvalues_type *> result;
00031   view.specificsV(result);
00032   for (std::vector<const DDsvalues_type *>::iterator it = result.begin(); it != result.end(); ++it) {
00033     if (DDfetch(*it,parameter)) {
00034       if (parameter.strings().size() == 1) {
00035         value = parameter.strings().front();
00036         return true;
00037       } else {
00038         return false;
00039       }
00040     }
00041   }
00042   return false;
00043 }
00044 
00045 static inline
00046 double dddGetDouble(const std::string & s, const DDFilteredView & view) {
00047   std::string value;
00048   if (dddGetStringRaw(view, s, value))
00049     return double(::atof(value.c_str()));
00050   else
00051     return NAN;
00052 }
00053 
00054 static inline
00055 std::string dddGetString(const std::string & s, const DDFilteredView & view) {
00056   std::string value;
00057   if (dddGetStringRaw(view, s, value))
00058     return value;
00059   else
00060     return std::string();
00061 }
00062 
00063 static inline 
00064 std::ostream & operator<<(std::ostream & out, const math::XYZVector & v) {
00065   return out << "(" << v.rho() << ", " << v.z() << ", " << v.phi() << ")";
00066 }
00067 
00068 class ListIds : public edm::EDAnalyzer
00069 {
00070 public:
00071   ListIds(const edm::ParameterSet &);
00072   virtual ~ListIds();
00073   
00074 private:
00075   void analyze(const edm::Event &, const edm::EventSetup &);
00076   void beginJob() {}
00077   void endJob();
00078 };
00079 
00080 ListIds::ListIds(const edm::ParameterSet &) {
00081 }
00082 
00083 ListIds::~ListIds() {
00084 }
00085 
00086 void
00087 ListIds::analyze(const edm::Event& evt, const edm::EventSetup& setup){
00088   std::cout << "______________________________ DDD ______________________________" << std::endl;
00089   edm::ESTransientHandle<DDCompactView> hDdd;
00090   setup.get<IdealGeometryRecord>().get( hDdd );
00091 
00092   std::string attribute = "TkDDDStructure";
00093   CmsTrackerStringToEnum theCmsTrackerStringToEnum;
00094   DDSpecificsFilter filter;
00095   filter.setCriteria(DDValue(attribute, "any", 0), DDSpecificsFilter::not_equals);
00096   DDFilteredView fv(*hDdd); 
00097   fv.addFilter(filter);
00098   if (theCmsTrackerStringToEnum.type(dddGetString(attribute, fv)) != GeometricDet::Tracker) {
00099     fv.firstChild();
00100     if (theCmsTrackerStringToEnum.type(dddGetString(attribute, fv)) != GeometricDet::Tracker)
00101       throw cms::Exception("Configuration") << "The first child of the DDFilteredView is not what is expected \n"
00102                                             << dddGetString(attribute, fv);
00103   }
00104    
00105   std::cout << std::fixed << std::setprecision(3);
00106   do {
00107     // print the full hierarchy of all Silicon items
00108     if (fv.logicalPart().material().name() == "materials:Silicon") {
00109   
00110       // start from 2 to skip the leading /OCMS[0]/CMSE[1] part
00111       const DDGeoHistory & history = fv.geoHistory();
00112       std::cout << '/';
00113       for (unsigned int h = 2; h < history.size(); ++h) {
00114         std::cout << '/' << history[h].logicalPart().name().name() << '[' << history[h].copyno() << ']';
00115       }
00116 
00117       // DD3Vector and DDTranslation are the same type as math::XYZVector
00118       math::XYZVector position = fv.translation() / 10.;  // mm -> cm
00119       std::cout << "\t" << position << std::endl;
00120     }
00121   } while (fv.next());
00122   std::cout << std::endl;
00123   
00124   std::cout << "______________________________ std::vector<GeomDet*> from TrackerGeometry::dets() ______________________________" << std::endl;
00125   edm::ESHandle<TrackerGeometry> hGeo;
00126   setup.get<TrackerDigiGeometryRecord>().get( hGeo );
00127 
00128   std::cout << std::fixed << std::setprecision(3);
00129   const std::vector<GeomDet*> & dets = hGeo->dets();
00130   for (unsigned int i = 0; i < dets.size(); ++i) {
00131     const GeomDet & det = *dets[i];
00132 
00133     // Surface::PositionType is a typedef for Point3DBase<float,GlobalTag> a.k.a. GlobalPoint
00134     const Surface::PositionType & p = det.position();
00135     math::XYZVector position(p.x(), p.y(), p.z());
00136 
00137     std::cout << det.subDetector() << '\t' 
00138               << det.geographicalId().det() << '\t' 
00139               << det.geographicalId().subdetId() << '\t'
00140               << det.geographicalId().rawId() << "\t"
00141               << position;
00142     const std::vector<const GeomDet*> & parts = det.components();
00143     if (parts.size()) {
00144       std::cout << "\t[" << parts[0]->geographicalId().rawId();
00145       for (unsigned int j = 1; j < parts.size(); ++j)
00146         std::cout << '\t' << parts[j]->geographicalId().rawId();
00147       std::cout << ']';
00148     }
00149     std::cout << std::endl;
00150   }
00151     
00152 }
00153 
00154 void
00155 ListIds::endJob() {
00156 }
00157 
00158 //-------------------------------------------------------------------------
00159 // define as a plugin
00160 #include "FWCore/PluginManager/interface/ModuleDef.h"
00161 #include "FWCore/Framework/interface/MakerMacros.h"
00162 DEFINE_FWK_MODULE(ListIds);