pid/compact/scripts/cherenkov_xy_plot.cxx
Go to the documentation of this file.
1 R__LOAD_LIBRARY(libfmt.so)
2 #include "fmt/core.h"
3 R__LOAD_LIBRARY(libDDG4IO.so)
4 R__LOAD_LIBRARY(libGenDetectors.so)
5 
6 #include "DD4hep/Detector.h"
7 #include "DDG4/Geant4Data.h"
8 #include "DDRec/CellIDPositionConverter.h"
9 #include "DDRec/SurfaceManager.h"
10 #include "DDRec/Surface.h"
11 #include "ROOT/RDataFrame.hxx"
12 
13 #include "TCanvas.h"
14 #include "TChain.h"
15 #include <random>
16 
17 #include "npdet/PhotoMultiplierHit.h"
18 
19 //#include "lcio2/TrackerRawDataData.h"
20 //#include "lcio2/TrackerRawData.h"
21 
22 using PMHit = npdet::PhotoMultiplierHit;
23 using PMHitRVec = ROOT::VecOps::RVec<npdet::PhotoMultiplierHit*>;
24 using PMTHitVector = std::vector<npdet::PhotoMultiplierHit*>;
25 
26 void cherenkov_xy_plot(const char* fname = "derp.root"){
27 
28  //ROOT::EnableImplicitMT(); // Tell ROOT you want to go parallel
29  //using namespace lcio2;
30  double degree = TMath::Pi()/180.0;
31 
32  //std::random_device rd;
33  //std::mt19937 gen(rd());
34 
35  TChain* t = new TChain("EVENT");
36  t->Add(fname);
37 
38  ROOT::RDataFrame d0(*t);
39  std::cout << t->GetBranch("ForwardRICHHits")->GetClassName() << std::endl;
40 
41  // -------------------------
42  // Get the DD4hep instance
43  // Load the compact XML file
44  // Initialize the position converter tool
45  //dd4hep::Detector& detector = dd4hep::Detector::getInstance();
46  //detector.fromCompact("GenericRICH_example.xml");
47  //dd4hep::rec::CellIDPositionConverter cellid_converter(detector);
48 
51  //dd4hep::rec::SurfaceManager& surfMan = *detector.extension<dd4hep::rec::SurfaceManager>() ;
52  //auto surfMap = surfMan.map( "world" ) ;
53 
54  //auto nhits = [] (std::vector<npdet::sim::Geant4Tracker::Hit*>& hits){ return (int) hits.size(); };
55 
56  auto pmt_x = [&](const PMTHitVector& hits) {
57  //return ROOT::VecOps::Map(hits, [](const PMHit& h) { return h.position.x(); });
58  std::vector<double> res;
59  for(auto h : hits) {
60  if(h->position.z() < 400) {
61  res.push_back(h->position.x());
62  }
63  }
64  return res;
65  };
66  auto pmt_y = [&](const PMTHitVector& hits) {
67  std::vector<double> res;
68  for(auto h : hits) {
69  if(h->position.z() < 400) {
70  res.push_back(h->position.y());
71  }
72  }
73  return res;
74  };
75 
76  //auto pmt_x = [&](const PMTHitVector& hits) {
77  // return ROOT::VecOps::Map(hits, [](const PMHit& h) { return h.position.x(); });
78  //};
79 
80  auto d1 = d0
81  .Define("nhits", [](const PMTHitVector& hits) { return hits.size(); }, {"ForwardRICHHits"})
82  .Define("pmt_x",pmt_x,{"ForwardRICHHits"})
83  .Define("pmt_y",pmt_y,{"ForwardRICHHits"});
84 
85  auto h1 = d1.Histo1D("nhits");
86  auto h1_x = d1.Histo1D("pmt_x");
87  auto h2 = d1.Histo2D({"cerxy", "cer_xy", 100u, -1000, -1000, 100u, -1000, -1000}, "pmt_x", "pmt_y");
88  auto graph = d1.Graph("nhits", "nhits");
89 
90  TCanvas* c = new TCanvas();
91 
92  h2->DrawCopy("colz");
93 
94  //graph->DrawClone("ap");
95  //graph->SetMarkerStyle(20);
96  //c->Update();
97 
98 }
99 
npdet::PhotoMultiplierHit PMHit
void cherenkov_xy_plot(const char *fname="derp.root")
std::vector< npdet::PhotoMultiplierHit * > PMTHitVector
ROOT::VecOps::RVec< npdet::PhotoMultiplierHit * > PMHitRVec