00001 #include <memory>
00002
00003 #include <FWCore/Framework/interface/EDAnalyzer.h>
00004 #include <FWCore/Framework/interface/EventSetup.h>
00005 #include <FWCore/Framework/interface/ESHandle.h>
00006 #include <FWCore/Framework/interface/MakerMacros.h>
00007
00008 #include <DetectorDescription/Core/interface/DDCompactView.h>
00009 #include <DetectorDescription/Core/interface/DDValue.h>
00010 #include <DetectorDescription/Core/interface/DDExpandedView.h>
00011 #include "DetectorDescription/Core/interface/DDName.h"
00012 #include "DetectorDescription/Core/interface/DDSolid.h"
00013 #include "DetectorDescription/Core/interface/DDMaterial.h"
00014
00015 #include <Geometry/Records/interface/IdealGeometryRecord.h>
00016
00017 #include <iostream>
00018 #include <istream>
00019 #include <fstream>
00020 #include <string>
00021 #include <vector>
00022 #include <algorithm>
00023 #include <utility>
00024
00025 class PhysicalPartsTree : public edm::EDAnalyzer {
00026
00027 public:
00028
00029 explicit PhysicalPartsTree( const edm::ParameterSet& );
00030 ~PhysicalPartsTree();
00031
00032 virtual void analyze( const edm::Event&, const edm::EventSetup& );
00033 virtual void beginJob( const edm::EventSetup& );
00034
00035 private:
00036
00037
00038 };
00039
00040 PhysicalPartsTree::PhysicalPartsTree( const edm::ParameterSet& iConfig )
00041 {
00042
00043 }
00044
00045
00046 PhysicalPartsTree::~PhysicalPartsTree()
00047 {
00048 }
00049
00050 void PhysicalPartsTree::analyze( const edm::Event& iEvent, const edm::EventSetup& iSetup ) {
00051 std::cout << "analyze does nothing" << std::endl;
00052 }
00053
00054 void PhysicalPartsTree::beginJob( const edm::EventSetup& iSetup ) {
00055
00056 double tolerance = 1.0e-3;
00057
00058 std::string physicalPartsTreeFileName("PHYSICALPARTSTREE.dat");
00059 std::string logicalPartTypesFileName("LOGICALPARTTYPES.dat");
00060 std::string nominalPlacementsFileName("NOMINALPLACEMENTS.dat");
00061 std::string detectorPartsFileName("DETECTORPARTS.dat");
00062 std::string pospartsGraphFileName("POSPARTSGRAPH.dat");
00063
00064 std::ofstream physicalPartsTreeOS(physicalPartsTreeFileName.c_str());
00065 std::ofstream logicalPartTypesOS(logicalPartTypesFileName.c_str());
00066 std::ofstream nominalPlacementsOS(nominalPlacementsFileName.c_str());
00067 std::ofstream detectorPartsOS(detectorPartsFileName.c_str());
00068 std::ofstream pospartsGraphOS(pospartsGraphFileName.c_str());
00069
00070
00071 std::string slpname;
00072 std::string scategory;
00073 std::vector<std::string> lpname_vec;
00074
00075
00076 std::cout << "PhysicalPartsTree Analyzer..." << std::endl;
00077 edm::ESHandle<DDCompactView> pDD;
00078
00079 iSetup.get<IdealGeometryRecord>().get( "", pDD );
00080
00081 const DDCompactView & cpv = *pDD;
00082 DDExpandedView epv(cpv);
00083 int pospartid=0;
00084 size_t lastfound;
00085 std::string lgname;
00086 while(epv.next()){
00087
00088
00089 std::ostringstream parent, child,logicalpartid,parentid;
00090 child << epv.logicalPart().name();
00091 const DDGeoHistory & hist = epv.geoHistory();
00092 parent << hist[hist.size()-2].logicalPart().name();
00093 logicalpartid << epv.geoHistory();
00094 parentid<<hist[hist.size()-2];
00095 lgname=logicalpartid.str();
00096 lastfound=lgname.find_last_of("/\\");
00097 lgname=lgname.substr(lastfound+1,lgname.size());
00098 physicalPartsTreeOS<<lgname<<","<< parentid.str() << "," << child.str()<<std::endl;
00099
00100
00101
00102 bool reflection = false;
00103
00104 DD3Vector x, y, z;
00105 epv.rotation().GetComponents(x, y, z);
00106
00107
00108
00109
00110
00111
00112 if ( (1.0 + (x.Cross(y)).Dot(z)) <= tolerance ) {
00113 reflection = true;
00114 }
00115 std::vector<double> comps(9);
00116 epv.rotation().GetComponents(comps.begin(), comps.end());
00117 nominalPlacementsOS<< logicalpartid.str()<<","
00118 << epv.translation().X() << ","
00119 << epv.translation().Y() << ","
00120 << epv.translation().Z()<< ","
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130 << comps[0]<<","
00131 << comps[1]<<","
00132 << comps[2]<<","
00133 << comps[3]<<","
00134 << comps[4]<<","
00135 << comps[5]<<","
00136 << comps[6]<<","
00137 << comps[7]<<","
00138 << comps[8]<<","
00139 << (int)reflection
00140 <<std::endl;
00141
00142
00143
00144 detectorPartsOS <<epv.logicalPart().solid().toString() << ","
00145 <<epv.logicalPart().material().toString() << ","
00146 <<logicalpartid.str()
00147 <<std::endl;
00148
00149
00150
00151 pospartsGraphOS<<++pospartid<< ","<<epv.copyno()<< ","
00152 <<parent.str() << "," << child.str()<<std::endl;
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162 slpname=epv.logicalPart().toString();
00163
00164 std::vector<std::string>::iterator it = find(lpname_vec.begin(), lpname_vec.end(), slpname);
00165
00166 if (it==lpname_vec.end()){
00167 if(DDEnums::categoryName(epv.logicalPart().category())){
00168 std::ostringstream category;
00169 category<<DDEnums::categoryName(epv.logicalPart().category());
00170 scategory=category.str();
00171 std::string unspec="unspecified";
00172 if(scategory==unspec){
00173 lpname_vec.push_back(slpname);
00174 logicalPartTypesOS <<slpname<< ","
00175 <<"DETECTORPARTS"<<std::endl;
00176 }
00177 else{
00178 lpname_vec.push_back(slpname);
00179 logicalPartTypesOS <<slpname<< ","<<scategory<<std::endl;
00180
00181 }
00182 }
00183 else{
00184 lpname_vec.push_back(slpname);
00185 logicalPartTypesOS <<slpname<< ","
00186 <<"DETECTORPARTS"<<std::endl;
00187
00188 }
00189 }
00190
00191
00192
00193 }
00194
00195
00196 physicalPartsTreeOS.close();
00197 logicalPartTypesOS.close();
00198 nominalPlacementsOS.close();
00199 detectorPartsOS.close();
00200 pospartsGraphOS.close();
00201 }
00202
00203
00204 DEFINE_FWK_MODULE(PhysicalPartsTree);