CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PhysicalPartsTree.cc
Go to the documentation of this file.
1 #include <memory>
2 
8 
15 
17 
18 #include <iostream>
19 #include <istream>
20 #include <fstream>
21 #include <string>
22 #include <vector>
23 #include <algorithm>
24 #include <utility>
25 
27 
28 public:
29 
30  explicit PhysicalPartsTree( const edm::ParameterSet& );
32 
33  virtual void analyze( const edm::Event&, const edm::EventSetup& ) override;
34  virtual void beginRun( const edm::Run&, const edm::EventSetup& ) override;
35 
36 private:
37 
38  //std::string filename_;
39 };
40 
42 {
43 
44 }
45 
46 
48 {
49 }
50 
52  std::cout << "analyze does nothing" << std::endl;
53 }
54 
55 void PhysicalPartsTree::beginRun( const edm::Run&, const edm::EventSetup& iSetup ) {
56  //set a tolerance for "near zero"
57  double tolerance = 1.0e-3;
58 
59  std::string physicalPartsTreeFileName("PHYSICALPARTSTREE.dat");
60  std::string logicalPartTypesFileName("LOGICALPARTTYPES.dat");
61  std::string nominalPlacementsFileName("NOMINALPLACEMENTS.dat");
62  std::string detectorPartsFileName("DETECTORPARTS.dat");
63  std::string pospartsGraphFileName("POSPARTSGRAPH.dat");
64 
65  std::ofstream physicalPartsTreeOS(physicalPartsTreeFileName.c_str());
66  std::ofstream logicalPartTypesOS(logicalPartTypesFileName.c_str());
67  std::ofstream nominalPlacementsOS(nominalPlacementsFileName.c_str());
68  std::ofstream detectorPartsOS(detectorPartsFileName.c_str());
69  std::ofstream pospartsGraphOS(pospartsGraphFileName.c_str());
70 
71 
72  std::string slpname;
73  std::string scategory;
74  std::vector<std::string> lpname_vec;
75 
76 
77  std::cout << "PhysicalPartsTree Analyzer..." << std::endl;
79 
80  iSetup.get<IdealGeometryRecord>().get( "", pDD );
81 
82  const DDCompactView & cpv = *pDD;
83  DDExpandedView epv(cpv);
84  int pospartid=0;
85  size_t lastfound;
86  std::string lgname;
87  while(epv.next()){
88 
89  //for table physicalpartstree
90  std::ostringstream parent, child,logicalpartid,parentid;
91  child << epv.logicalPart().name();
92  const DDGeoHistory & hist = epv.geoHistory();
93  parent << hist[hist.size()-2].logicalPart().name();
94  logicalpartid << epv.geoHistory();
95  parentid<<hist[hist.size()-2];
96  lgname=logicalpartid.str();
97  lastfound=lgname.find_last_of("/\\");
98  lgname=lgname.substr(lastfound+1,lgname.size());
99  physicalPartsTreeOS<<lgname<<","<< parentid.str() << "," << child.str()<<std::endl;
100 // std::cout << "Logical Part Name= "<<logicalpartid.str() << std::endl;
101 
102  //for table nominalPlacements
103  bool reflection = false;
104 
105  DD3Vector x, y, z;
106  epv.rotation().GetComponents(x, y, z);
107  //Hep3Vector xv = epv.rotation().colX();
108  //Hep3Vector yv = epv.rotation().colY();
109  //Hep3Vector zv = epv.rotation().colZ();
110  //if ( xv.cross(yv) * zv < 0) {
111  // reflection = true;
112  // }
113  if ( (1.0 + (x.Cross(y)).Dot(z)) <= tolerance ) {
114  reflection = true;
115  }
116  std::vector<double> comps(9);
117  epv.rotation().GetComponents(comps.begin(), comps.end());
118  nominalPlacementsOS<< logicalpartid.str()<<","
119  << epv.translation().X() << ","
120  << epv.translation().Y() << ","
121  << epv.translation().Z()<< ","
122 // << epv.rotation().xx()<< ","
123 // << epv.rotation().xy()<< ","
124 // << epv.rotation().xz()<< ","
125 // << epv.rotation().yx()<< ","
126 // << epv.rotation().yy()<< ","
127 // << epv.rotation().yz()<< ","
128 // << epv.rotation().zx()<< ","
129 // << epv.rotation().zy()<< ","
130 // << epv.rotation().zz()<< ","
131  << comps[0]<<","
132  << comps[1]<<","
133  << comps[2]<<","
134  << comps[3]<<","
135  << comps[4]<<","
136  << comps[5]<<","
137  << comps[6]<<","
138  << comps[7]<<","
139  << comps[8]<<","
140  << (int)reflection
141  <<std::endl;
142 
143 
144  //for table DetectorParts
145  detectorPartsOS <<epv.logicalPart().solid().toString() << ","
146  <<epv.logicalPart().material().toString() << ","
147  <<logicalpartid.str()
148  <<std::endl;
149 
150  //for table PosPartsGraph
151 
152  pospartsGraphOS<<++pospartid<< ","<<epv.copyno()<< ","
153  <<parent.str() << "," << child.str()<<std::endl;
154 
155 
156  //for table logicalPartTypes
157  //this table is special because the DPNAMEs are subset of Physicalpart_id
158  //while we're looping all the Physicalpart_ids in epv, so we just
159  //keep the unique DPNAMEs into a vector and save them in looping epv.
160  // if there's no lpname in lpname_vec
161  //>> the OS file.
162 
163  slpname=epv.logicalPart().toString();
164 
165  std::vector<std::string>::iterator it = find(lpname_vec.begin(), lpname_vec.end(), slpname);
166 
167  if (it==lpname_vec.end()){
169  std::ostringstream category;
170  category<<DDEnums::categoryName(epv.logicalPart().category());
171  scategory=category.str();
172  std::string unspec="unspecified";
173  if(scategory==unspec){
174  lpname_vec.push_back(slpname);
175  logicalPartTypesOS <<slpname<< ","
176  <<"DETECTORPARTS"<<std::endl;
177  }
178  else{
179  lpname_vec.push_back(slpname);
180  logicalPartTypesOS <<slpname<< ","<<scategory<<std::endl;
181 
182  }
183  }
184  else{
185  lpname_vec.push_back(slpname);
186  logicalPartTypesOS <<slpname<< ","
187  <<"DETECTORPARTS"<<std::endl;
188 
189  }
190  }
191 
192 
193 
194  } //finish looping through expanded view.
195 
196 
197  physicalPartsTreeOS.close();
198  logicalPartTypesOS.close();
199  nominalPlacementsOS.close();
200  detectorPartsOS.close();
201  pospartsGraphOS.close();
202 }
203 
204 //define this as a plug-in
bool next()
set current node to the next node in the expanded tree
const DDRotationMatrix & rotation() const
The absolute rotation of the current node.
virtual void beginRun(const edm::Run &, const edm::EventSetup &) override
const N & name() const
Definition: DDBase.h:78
list parent
Definition: dbtoconf.py:74
DDEnums::Category category(void) const
Returns the categorization of the DDLogicalPart (sensitive detector element, cable, ...)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
const DDSolid & solid(void) const
Returns a reference object of the solid being the shape of this LogicalPart.
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
type of data representation of DDCompactView
Definition: DDCompactView.h:76
PhysicalPartsTree(const edm::ParameterSet &)
const DDGeoHistory & geoHistory() const
The list of ancestors up to the root-node of the current node.
int iEvent
Definition: GenABIO.cc:230
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DD3Vector
A DD Translation is currently implemented with Root Vector3D.
Definition: DDTranslation.h:6
const DDTranslation & translation() const
The absolute translation of the current node.
std::vector< DDExpandedNode > DDGeoHistory
Geometrical &#39;path&#39; of the current node up to the root-node.
std::string toString() const
Definition: DDBase.h:82
int copyno() const
Copy number associated with the current node.
const T & get() const
Definition: EventSetup.h:55
tuple cout
Definition: gather_cfg.py:121
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the expanded-view.
Provides an exploded view of the detector (tree-view)
static const char *const categoryName(Category s)
Definition: DDEnums.h:17
const DDMaterial & material(void) const
Returns a reference object of the material this LogicalPart is made of.
Definition: Run.h:41