#include #include #include #include #include "TROOT.h" #include "TApplication.h" #include "TCanvas.h" #include "TView.h" #include "TGeometry.h" #include "TGeoManager.h" #include "TGeoMatrix.h" #include "TGeoMaterial.h" #include "TGeoMedium.h" #include "TGeoVolume.h" #include "TGeoTube.h" #include "TGeoCone.h" #include "TPaveText.h" #include "JMath/JConstants.hh" #include "JDetector/JDetector.hh" #include "JDetector/JDetectorToolkit.hh" #include "JDetector/JModuleRouter.hh" #include "JDetector/JDetectorAddressMapToolkit.hh" #include "Jeep/JPrint.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" /** * Global variables to handle mouse events. */ TCanvas* c1 = NULL; TPaveText* p1 = NULL; /** */ class JGeoVolume : public TGeoVolume { public: /** * Constructor. * * \param name name * \param shape shape * \param med medium */ JGeoVolume(const char* name, const TGeoShape* shape, const TGeoMedium* med = 0) : TGeoVolume(name, shape, med) {} /** * Mouse events. * * \param event event * \param px x-position of mouse * \param py y-position of mouse */ virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py) { if (event == kMouseEnter) { for (std::vector::const_iterator i = buffer.begin(); i != buffer.end(); ++i) p1->AddText(i->c_str()); p1->Draw(); c1->Update(); } else if (event == kMouseLeave) { p1->Clear(); p1->Draw(); c1->Update(); } else { TGeoVolume::ExecuteEvent(event, px, py); } } /** * Add text to buffer. * * \param text text */ void AddText(const std::string& text) { buffer.push_back(text); } protected: std::vector buffer; }; /** * \file * Auxiliary program to draw a given module in 3D. * \author mdejong */ int main(int argc, char**argv) { using namespace std; string detectorFile; int moduleID; int debug; try { JParser<> zap("Auxiliary program to draw a given module in 3D."); zap['a'] = make_field(detectorFile); zap['M'] = make_field(moduleID) = -1; zap['d'] = make_field(debug) = 1; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } using namespace JPP; JDetector detector; try { load(detectorFile, detector); } catch(const JException& error) { FATAL(error); } if (detector.empty()) { FATAL("Empty detector."); } JModule module; if (moduleID == -1) { module = detector.front(); } else { JModuleRouter router(detector); if (!router.hasModule(moduleID)) { FATAL("Missing module " << moduleID << endl); } else { module = router.getModule(moduleID); } } module -= module.getPosition(); // ~center module const JDetectorAddressMap& demo = getDetectorAddressMap(detector.getID()); const JModuleAddressMap& memo = demo.get(module.getID()); TApplication* app = new TApplication("user", NULL, NULL); c1 = new TCanvas("module", detectorFile.c_str(), 600, 600); p1 = new TPaveText(0.7, 0.9, 1.0, 1.0, "NB"); c1->SetFillColor(0); p1->SetFillColor(0); p1->SetBorderSize(0); p1->SetTextSize(0.03); TGeoManager* gGeoManager = new TGeoManager("geometry", ""); TGeoMaterial* mat = new TGeoMaterial("vacuum", 0, 0, 0); TGeoMedium* med = new TGeoMedium ("vacuum", 1, mat); TGeoVolume* top = gGeoManager->MakeBox("top", med, 30.0, 30.0, 30.0); // PMT // // ->dz<- // // _/| // R1 |_ | R2 // \| // // ->dz<- const double dz = 3.0; // [cm] const double R1 = 2.0; // [cm] const double R2 = 4.0; // [cm] const Int_t color[] = { kRed, kOrange, kYellow, kGreen, kBlue, kMagenta }; for (unsigned int tdc = 0; tdc != module.size(); ++tdc) { const JPMTAddressTranslator& address = memo.getAddressTranslator(tdc); const int index = address.ring - 'A'; ostringstream os[2]; os[0] << "PMT " << setw(1) << address.ring << setw(1) << address.position; os[1] << "TDC " << setw(2) << tdc; TGeoVolumeAssembly* pPMT = new TGeoVolumeAssembly("PMT"); JGeoVolume* pTube = new JGeoVolume("dynode", new TGeoTube("", 0.0, R1, 0.5 * dz), med); JGeoVolume* pCone = new JGeoVolume("cathode", new TGeoCone("", 0.5 * dz, 0.0, R1, 0.0, R2), med); for (int i = 0; i != sizeof(os)/sizeof(os[0]); ++i) { pTube->AddText(os[i].str()); pCone->AddText(os[i].str()); } pTube->SetLineColor(color[index]); pCone->SetLineColor(color[index]); pPMT->AddNode(pTube, 0, new TGeoTranslation(0.0, 0.0, -dz)); pPMT->AddNode(pCone, 1, new TGeoTranslation(0.0, 0.0, 0.0)); const JPMT& pmt = module.getPMT(tdc); const Double_t x = pmt.getX() * 100; // [cm] const Double_t y = pmt.getY() * 100; // [cm] const Double_t z = pmt.getZ() * 100; // [cm] const Double_t theta = pmt.getTheta() * 180.0 / PI; // [deg] const Double_t phi = pmt.getPhi() * 180.0 / PI; // [deg] DEBUG("PMT" << " " << setw(1) << address.ring << setw(1) << address.position << " " << " TDC " << setw(2) << tdc << " " << FIXED(3,0) << x << " [cm] " << FIXED(3,0) << y << " [cm] " << FIXED(3,0) << z << " [cm] " << FIXED(4,0) << theta << " [deg] " << FIXED(4,0) << phi << " [deg] " << endl); TGeoRotation* rot = new TGeoRotation(); rot->RotateY(theta); rot->RotateZ(phi); top->AddNode(pPMT, tdc, new TGeoCombiTrans(x,y,z,rot)); } gGeoManager->SetTopVolume(top); gGeoManager->CloseGeometry(); top->Draw(); c1->GetView()->ShowAxis(); c1->Update(); app->Run(); }