load_geo.cxx
Go to the documentation of this file.
1 R__LOAD_LIBRARY(libDDG4IO.so)
2 
3 #include "DD4hep/Detector.h"
4 #include "DDG4/Geant4Data.h"
5 #include "DDRec/CellIDPositionConverter.h"
6 #include "DDRec/SurfaceManager.h"
7 #include "DDRec/Surface.h"
8 #include "ROOT/RDataFrame.hxx"
9 //
10 //#include <vector>
11 //#include <tuple>
12 //#include <algorithm>
13 //#include <iterator>
14 //
21 #include "DD4hep/Detector.h"
22 #include "DDG4/Geant4Data.h"
23 #include "DDRec/CellIDPositionConverter.h"
24 #include "DDRec/SurfaceManager.h"
25 #include "DDRec/Surface.h"
26 #include "ROOT/RDataFrame.hxx"
27 
28 //#include "lcio2/MCParticleData.h"
29 //#include "lcio2/ReconstructedParticleData.h"
30 
31 //#include "Math/Vector3D.h"
32 //#include "Math/Vector4D.h"
33 //#include "Math/VectorUtil.h"
34 #include "TCanvas.h"
35 //#include "TLegend.h"
36 //#include "TMath.h"
37 //#include "TRandom3.h"
38 //#include "TFile.h"
39 //#include "TH1F.h"
40 //#include "TH1D.h"
41 //#include "TTree.h"
42 #include "TChain.h"
43 //#include "TF1.h"
65 void load_geo(const char* fname = "test_tracker_disc.root"){
66 
67  using namespace ROOT::Math;
68 
69  ROOT::EnableImplicitMT(4);
70  TChain* t = new TChain("EVENT");
71  t->Add(fname);
72 
73  ROOT::RDataFrame d0(*t, {"GEMTrackerHits","MCParticles"});
74 
75  //How to get the type of the initial branch: (vector<dd4hep::sim::Geant4Tracker::Hit*>)
76  //std::cout << t->GetBranch("GEMTrackerHits")->GetClassName() << std::endl;
77 
78  // -------------------------
79  // Get the DD4hep instance
80  // Load the compact XML file
81  // Initialize the position converter tool
82  dd4hep::Detector& detector = dd4hep::Detector::getInstance();
83  detector.fromCompact("IRChamber_example.xml");
84  dd4hep::rec::CellIDPositionConverter cellid_converter(detector);
85 
86  // -------------------------
87  // Get the surfaces map
88  //dd4hep::rec::SurfaceManager& surfMan = *detector.extension<dd4hep::rec::SurfaceManager>() ;
89  //auto surfMap = surfMan.map( "world" ) ;
90 
92  //auto nhits = [] (const std::vector<dd4hep::sim::Geant4Tracker::Hit*>& hits){ return hits.size(); };
93 
115 
116  //auto deltax = [&](const std::vector<dd4hep::sim::Geant4Tracker::Hit*>& hits){
117  // std::vector<double> result;
118  // for(const auto& h: hits) {
119  // auto cell = h->cellID;
120  // // The actual hit position:
121  // XYZVector pos0 = (h->position/10.0);
122  // // The segmentation hit postion:
123  // XYZVector pos1 = cellid_converter.position(cell);
124 
125  // auto seg_pos = cellid_converter.position(cell);
126 
127  // //auto context = cellid_converter.findContext( cell ) ;
128  // //dd4hep::Readout r = cellid_converter.findReadout( context->element ) ;
129  // //dd4hep::Segmentation seg = r.segmentation() ;
130  // //auto cell_dim = seg.cellDimensions(cell);
131  // auto cell_dim = cellid_converter.cellDimensions(cell);
132  // std::cout << " dim ";
133  // for(const auto& dim : cell_dim) {
134  // std::cout << dim << ", ";
135  // }
136  // //XYZVector pos1 = pos11;
137  // // Use the cellID to get the VolumeID (VolumeManagerContext.identifier = VolumeID)
138  // const auto si = surfMap->find( cellid_converter.findContext(h->cellID)->identifier );
139  // // Get the Surface (http://test-dd4hep.web.cern.ch/test-dd4hep/doxygen/html/classdd4hep_1_1rec_1_1_i_surface.html)
140  // dd4hep::rec::ISurface* surf = (si != surfMap->end() ? si->second : nullptr);
141  // dd4hep::rec::Vector3D pos2;
142  // // Get the origin of the surface volume
143  // if(!surf) pos2 = surf->origin();
144  // std::cout << " Hit Position : " << pos0 << std::endl;
145  // std::cout << "Segmentation-Cell Position : " << pos1 << std::endl;
146  // std::cout << " Surface Origin Position : " << pos2 << std::endl;
147  // result.push_back( VectorUtil::RotateZ((pos1-pos0), -1.0*pos1.Phi()+TMath::Pi()/2.0).x() );
148  // }
149  // return result;
150  //};
151 
152  //auto deltay = [&](const std::vector<dd4hep::sim::Geant4Tracker::Hit*>& hits){
153  // std::vector<double> result;
154  // for(const auto& h: hits) {
155  // // The actual hit position:
156  // XYZVector pos0 = (h->position/10.0);
157  // // The segmentation hit postion:
158  // XYZVector pos1 = cellid_converter.position(h->cellID);
159  // // Use the cellID to get the VolumeID (VolumeManagerContext.identifier = VolumeID)
160  // const auto si = surfMap->find( cellid_converter.findContext(h->cellID)->identifier );
161  // // Get the Surface (http://test-dd4hep.web.cern.ch/test-dd4hep/doxygen/html/classdd4hep_1_1rec_1_1_i_surface.html)
162  // dd4hep::rec::ISurface* surf = (si != surfMap->end() ? si->second : nullptr);
163  // dd4hep::rec::Vector3D pos2;
164  // // Get the origin of the surface volume
165  // if(!surf) pos2 = surf->origin();
166  // //std::cout << " Hit Position : " << pos0 << std::endl;
167  // //std::cout << "Segmentation-Cell Position : " << pos1 << std::endl;
168  // //std::cout << " Surface Origin Position : " << pos2 << std::endl;
169  // result.push_back( VectorUtil::RotateZ((pos1-pos0), -1.0*pos1.Phi()+TMath::Pi()/2.0).y() );
170  // }
171  // return result;
172  //};
173 
174  //auto d1 = d0
175  // .Define("nhits",nhits, {"GEMTrackerHits"})
176  // .Filter([=](const std::vector<dd4hep::sim::Geant4Tracker::Hit*>& hits) {
177  // for(const auto& h: hits) {
178  // auto pos = h->position/10;
179  // if( TMath::Sqrt(pos.x()*pos.x()+ pos.y()*pos.y()) > 30.0 ){
180  // return true;
181  // }
182  // }
183  // return false;}, {"GEMTrackerHits"})
184  // .Define("deltax", deltax, {"GEMTrackerHits"})
185  // .Define("deltay", deltay, {"GEMTrackerHits"});
195 
196 
198  //auto h0 = d1.Histo2D( TH2D("h0", "nhits; ", 100, -2.0, 2.0, 100, -2.0, 2.0), "deltax", "deltay");
199 
200  //TCanvas* c = new TCanvas();
201  //h0->DrawClone("colz");
202 
203  //d1.Snapshot("EVENT","derp.root");
204 }
void load_geo(const char *fname="test_tracker_disc.root")
Cell size example.
Definition: load_geo.cxx:65
Detector
Definition: DDG4.py:69