From ab9ea06e0e5235576c5b16c78ad6ee4ebd5562b3 Mon Sep 17 00:00:00 2001 From: Riccardo Maria Bianchi <riccardo.maria.bianchi@cern.ch> Date: Wed, 26 Mar 2014 14:25:06 +0100 Subject: [PATCH] migration to Eigen (VP1SimHitSystems-00-04-00) --- .../VP1SimHitSystems/VP1SimHitSystem.h | 34 ++ .../VP1SimHitSystems/cmt/requirements | 22 + .../VP1SimHitSystems/src/VP1SimHitSystem.cxx | 392 ++++++++++++++++++ .../src/simhitcontrollerform.ui | 236 +++++++++++ 4 files changed, 684 insertions(+) create mode 100755 graphics/VP1/VP1Systems/VP1SimHitSystems/VP1SimHitSystems/VP1SimHitSystem.h create mode 100755 graphics/VP1/VP1Systems/VP1SimHitSystems/cmt/requirements create mode 100755 graphics/VP1/VP1Systems/VP1SimHitSystems/src/VP1SimHitSystem.cxx create mode 100755 graphics/VP1/VP1Systems/VP1SimHitSystems/src/simhitcontrollerform.ui diff --git a/graphics/VP1/VP1Systems/VP1SimHitSystems/VP1SimHitSystems/VP1SimHitSystem.h b/graphics/VP1/VP1Systems/VP1SimHitSystems/VP1SimHitSystems/VP1SimHitSystem.h new file mode 100755 index 00000000000..5aabf694009 --- /dev/null +++ b/graphics/VP1/VP1Systems/VP1SimHitSystems/VP1SimHitSystems/VP1SimHitSystem.h @@ -0,0 +1,34 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef VP1SIMHITSYSTEM_H +#define VP1SIMHITSYSTEM_H + +#include "VP1Base/IVP13DSystemSimple.h" + +class VP1SimHitSystem: public IVP13DSystemSimple +{ + Q_OBJECT + + public: + VP1SimHitSystem(); + ~VP1SimHitSystem(); + + QWidget* buildController(); + + void systemcreate(StoreGateSvc* detstore); + void buildEventSceneGraph(StoreGateSvc* sg, SoSeparator *root); + + protected slots: + void checkboxChanged(); + + private: + class Clockwork; + Clockwork* _clockwork; + + void buildHitTree(const QString& detector); + +}; + +#endif diff --git a/graphics/VP1/VP1Systems/VP1SimHitSystems/cmt/requirements b/graphics/VP1/VP1Systems/VP1SimHitSystems/cmt/requirements new file mode 100755 index 00000000000..ca76df6569d --- /dev/null +++ b/graphics/VP1/VP1Systems/VP1SimHitSystems/cmt/requirements @@ -0,0 +1,22 @@ +package VP1SimHitSystems + +author Vakho Tsulaia <Vakhtang.Tsulaia@cern.ch> +manager Vakho Tsulaia <Vakhtang.Tsulaia@cern.ch> + +public +use AtlasPolicy AtlasPolicy-* +use VP1Base VP1Base-* graphics/VP1 + +private +use AtlasCoinInventor AtlasCoinInventor-* External +use GeoAdaptors GeoAdaptors-* DetectorDescription/GeoModel +use InDetSimEvent InDetSimEvent-* InnerDetector +use MuonSimEvent MuonSimEvent-* MuonSpectrometer +use ForwardRegion_SimEv ForwardRegion_SimEv-* ForwardDetectors/ForwardSimulation +use StoreGate StoreGate-* Control +use VP1Qt VP1Qt-* graphics/VP1 +use VP1Utils VP1Utils-* graphics/VP1 +use GeoPrimitives GeoPrimitives-* DetectorDescription +end_private + +apply_pattern qt4based_library diff --git a/graphics/VP1/VP1Systems/VP1SimHitSystems/src/VP1SimHitSystem.cxx b/graphics/VP1/VP1Systems/VP1SimHitSystems/src/VP1SimHitSystem.cxx new file mode 100755 index 00000000000..a0f848928b3 --- /dev/null +++ b/graphics/VP1/VP1Systems/VP1SimHitSystems/src/VP1SimHitSystem.cxx @@ -0,0 +1,392 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "VP1SimHitSystems/VP1SimHitSystem.h" +#include "ui_simhitcontrollerform.h" + +#include "StoreGate/StoreGateSvc.h" + +#include <QMap> +#include <QSet> + +#include <Inventor/nodes/SoDrawStyle.h> +#include <Inventor/nodes/SoMaterial.h> +#include <Inventor/nodes/SoSeparator.h> +#include <Inventor/nodes/SoSwitch.h> +#include <Inventor/nodes/SoVertexProperty.h> +#include <Inventor/nodes/SoPointSet.h> +#include <Inventor/SbColor.h> + + +#include "InDetSimEvent/SiHitCollection.h" +#include "InDetSimEvent/TRTUncompressedHitCollection.h" +#include "GeoAdaptors/GeoTRTUncompressedHit.h" +#include "GeoAdaptors/GeoSiHit.h" +#include "GeoAdaptors/GeoMuonHits.h" + +#include "MuonSimEvent/MDTSimHitCollection.h" +#include "MuonSimEvent/RPCSimHitCollection.h" +#include "MuonSimEvent/TGCSimHitCollection.h" +#include "MuonSimEvent/CSCSimHitCollection.h" +#include "MuonSimEvent/GenericMuonSimHitCollection.h" + +#include "ForwardRegion_SimEv/SimulationHitCollection.h" + +#include "VP1Utils/VP1SGContentsHelper.h" + +#include "GeoPrimitives/GeoPrimitives.h" + +class VP1SimHitSystem::Clockwork +{ +public: + QMap<QString,SoSwitch*> switchMap; + QMap<QString,SbColor> colorMap; + QMap<QCheckBox*,QString> checkBoxNamesMap; + QMap<QString,QCheckBox*> checkBoxMap; + QSet<QString> hitsThisEvent; + StoreGateSvc * sg; +}; + +VP1SimHitSystem::VP1SimHitSystem() + :IVP13DSystemSimple("Sim Hits","Display simulation hits from trackers","Vakho Tsulaia <Vakhtang.Tsulaia@cern.ch>"), + _clockwork(new Clockwork()) +{ +} + +VP1SimHitSystem::~VP1SimHitSystem() +{ + delete _clockwork; + _clockwork = 0; +} + +QWidget* VP1SimHitSystem::buildController() +{ + QWidget* controller = new QWidget(0); + Ui::SimHitControllerForm ui; + ui.setupUi(controller); + + // Populate Check Box Names Map + _clockwork->checkBoxNamesMap.insert(ui.chbxPixelHits,"Pixel"); + _clockwork->checkBoxNamesMap.insert(ui.chbxSCTHits,"SCT"); + _clockwork->checkBoxNamesMap.insert(ui.chbxTRTHits,"TRT"); + _clockwork->checkBoxNamesMap.insert(ui.chbxMDTHits,"MDT"); + _clockwork->checkBoxNamesMap.insert(ui.chbxRPCHits,"RPC"); + _clockwork->checkBoxNamesMap.insert(ui.chbxTGCHits,"TGC"); + _clockwork->checkBoxNamesMap.insert(ui.chbxCSCHits,"CSC"); + _clockwork->checkBoxNamesMap.insert(ui.chbxGenericMuonHits,"Generic Muon"); + _clockwork->checkBoxNamesMap.insert(ui.chbxForwardRegionHits,"Forward Region"); + + // Populate Check Box Map and connect slots + foreach(QCheckBox* cb,_clockwork->checkBoxNamesMap.keys()) + { + connect(cb,SIGNAL(toggled(bool)),this,SLOT(checkboxChanged())); + _clockwork->checkBoxMap.insert(_clockwork->checkBoxNamesMap[cb],cb); + } + + return controller; +} + +void VP1SimHitSystem::systemcreate(StoreGateSvc* /*detstore*/) +{ + // Populate Color Map + _clockwork->colorMap.insert("Pixel",SbColor(0,0,1)); + _clockwork->colorMap.insert("SCT",SbColor(1,1,1)); + _clockwork->colorMap.insert("TRT",SbColor(1,0,0)); + _clockwork->colorMap.insert("MDT",SbColor(.98,.8,.21)); + _clockwork->colorMap.insert("RPC",SbColor(0,.44,.28)); + _clockwork->colorMap.insert("TGC",SbColor(0,.631244,.748016)); + _clockwork->colorMap.insert("CSC",SbColor(.21,.64,1.)); + _clockwork->colorMap.insert("Generic Muon",SbColor(.21,.64,1.)); + _clockwork->colorMap.insert("Forward Region",SbColor(.21,.64,1.)); +} + +void VP1SimHitSystem::buildEventSceneGraph(StoreGateSvc* sg, SoSeparator *root) +{ + // --- Draw style: POINTS + SoDrawStyle* ds = new SoDrawStyle(); + ds->style.setValue(SoDrawStyle::POINTS); + ds->pointSize=4; + root->addChild(ds); + + // Keep SG pointer + _clockwork->sg = sg; + + // clean up + _clockwork->switchMap.clear(); + _clockwork->hitsThisEvent.clear(); + + if(!sg) + { + message("0 pointer to the Store Gate!"); + return; + } + + foreach(QString detector,_clockwork->checkBoxMap.keys()) + { + // Add switch, off by default + SoSwitch* _switch = new SoSwitch(); + _switch->whichChild = SO_SWITCH_NONE; + root->addChild(_switch); + _clockwork->switchMap.insert(detector,_switch); + + // Build subtree if the check box is ON + if(_clockwork->checkBoxMap.contains(detector) && + _clockwork->checkBoxMap[detector]->isChecked()) + { + buildHitTree(detector); + _switch->whichChild = SO_SWITCH_ALL; + } + updateGUI(); + } +} + +void VP1SimHitSystem::checkboxChanged() +{ + // Get ChB pointer + QCheckBox* cb = dynamic_cast<QCheckBox*>(sender()); + if(cb && _clockwork->checkBoxNamesMap.contains(cb)) + { + // Get detector name + QString detector = _clockwork->checkBoxNamesMap[cb]; + if(_clockwork->switchMap.contains(detector)) + { + // Get swtich + SoSwitch* _switch = _clockwork->switchMap[detector]; + if(cb->isChecked()){ + // Build subtree if necessary + if(!_clockwork->hitsThisEvent.contains(detector)) + buildHitTree(detector); + _switch->whichChild = SO_SWITCH_ALL; + } + else + _switch->whichChild = SO_SWITCH_NONE; + } else { + message("WARNING: Unknown detector:"+detector); + } + } +} + + +void VP1SimHitSystem::buildHitTree(const QString& detector) +{ + messageVerbose("buildHitTree for "+detector); + if(_clockwork->hitsThisEvent.contains(detector)) { + messageVerbose(" in hitsThisEvent"); return; + } + if(!_clockwork->colorMap.contains(detector)) { + messageVerbose("not in colorMap"); return; + } + if(!_clockwork->switchMap.contains(detector)) { + messageVerbose("not in switchMap"); return; + } + + // -- Initializations + StoreGateSvc* sg = _clockwork->sg; + SoSwitch* _switch = _clockwork->switchMap[detector]; + unsigned int hitCount = 0; + + SoVertexProperty* hitVtxProperty = new SoVertexProperty(); + SoPointSet* hitPointSet = new SoPointSet(); + + hitVtxProperty->enableNotify(FALSE); + hitPointSet->enableNotify(FALSE); + + // -- COLOR + SoMaterial* material = new SoMaterial(); + material->diffuseColor.setValue(_clockwork->colorMap[detector]); + + _switch->addChild(material); + + // Take hits from SG + if(detector=="Pixel") + { + // + // Pixel: + // + const DataHandle<SiHitCollection> p_collection; + if(sg->retrieve(p_collection,"PixelHits")==StatusCode::SUCCESS) + { + for(SiHitConstIterator i_hit=p_collection->begin(); i_hit!=p_collection->end(); ++i_hit) + { + GeoSiHit ghit(*i_hit); + if(!ghit) continue; + HepGeom::Point3D<double> u = ghit.getGlobalPosition(); + hitVtxProperty->vertex.set1Value(hitCount++,u.x(),u.y(),u.z()); + } + } + else + message("Unable to retrieve Pixel Hits"); + } + else if(detector=="SCT") + { + // + // SCT: + // + const DataHandle<SiHitCollection> s_collection; + if(sg->retrieve(s_collection,"SCT_Hits")==StatusCode::SUCCESS) + { + for(SiHitConstIterator i_hit=s_collection->begin();i_hit!=s_collection->end();++i_hit) + { + GeoSiHit ghit(*i_hit); + if (!ghit) continue; + HepGeom::Point3D<double> u = ghit.getGlobalPosition(); + hitVtxProperty->vertex.set1Value(hitCount++,u.x(),u.y(),u.z()); + } + } + else + message("Unable to retrieve SCT Hits"); + } + else if(detector=="TRT") + { + // + // TRT: + // + const DataHandle<TRTUncompressedHitCollection> t_collection; + if(sg->retrieve(t_collection,"TRTUncompressedHits")==StatusCode::SUCCESS) + { + for(TRTUncompressedHitConstIter i_hit=t_collection->begin();i_hit!=t_collection->end();++i_hit) + { + GeoTRTUncompressedHit ghit(*i_hit); + if(!ghit) continue; + Amg::Vector3D u = Amg::Hep3VectorToEigen(ghit.getGlobalPosition()); + hitVtxProperty->vertex.set1Value(hitCount++,u.x(),u.y(), u.z() ); + } + } + else + message("Unable to retrieve TRT Hits"); + } + else if(detector=="MDT") + { + // + // MDT: + // + const DataHandle<MDTSimHitCollection> mdt_collection; + if(sg->retrieve(mdt_collection)==StatusCode::SUCCESS) + { + for(MDTSimHitConstIterator i_hit=mdt_collection->begin();i_hit!=mdt_collection->end();++i_hit) + { + GeoMDTHit ghit(*i_hit); + if(!ghit) continue; + Amg::Vector3D u = ghit.getGlobalPosition(); + hitVtxProperty->vertex.set1Value(hitCount++,u.x(),u.y(),u.z()); + } + } + else + message("Unable to retrieve MDT Hits"); + } + else if(detector=="RPC") + { + // + // RPC: + // + const DataHandle<RPCSimHitCollection> rpc_collection; + if(sg->retrieve(rpc_collection)==StatusCode::SUCCESS) { + for(RPCSimHitConstIterator i_hit=rpc_collection->begin();i_hit!=rpc_collection->end();++i_hit) + { + GeoRPCHit ghit(*i_hit); + if(!ghit) continue; + Amg::Vector3D u = ghit.getGlobalPosition(); + hitVtxProperty->vertex.set1Value(hitCount++,u.x(),u.y(),u.z()); + } + } + else + message("Unable to retrieve RPC Hits"); + } + else if(detector=="TGC") + { + // + // TGC: + // + const DataHandle<TGCSimHitCollection> tgc_collection; + if (sg->retrieve(tgc_collection)==StatusCode::SUCCESS) + { + for(TGCSimHitConstIterator i_hit=tgc_collection->begin();i_hit!=tgc_collection->end();++i_hit) + { + GeoTGCHit ghit(*i_hit); + if(!ghit) continue; + Amg::Vector3D u = ghit.getGlobalPosition(); + hitVtxProperty->vertex.set1Value(hitCount++,u.x(),u.y(),u.z()); + } + } + else + message("Unable to retrieve TGC Hits"); + } + else if(detector=="CSC") + { + // + // CSC: + // + const DataHandle<CSCSimHitCollection> csc_collection; + if(sg->retrieve(csc_collection)==StatusCode::SUCCESS) + { + for(CSCSimHitConstIterator i_hit=csc_collection->begin();i_hit!=csc_collection->end();++i_hit) + { + GeoCSCHit ghit(*i_hit); + if (!ghit) continue; + Amg::Vector3D u = ghit.getGlobalPosition(); + hitVtxProperty->vertex.set1Value(hitCount++,u.x(),u.y(),u.z()); + } + } + else + message("Unable to retrieve CSC Hits"); + }else if(detector=="Generic Muon") + { + // + // Generic: + // + message("Trying for Generic Muon (as many collections as can be found)"); + foreach(QString key,VP1SGContentsHelper(this).getKeys<GenericMuonSimHitCollection>()) { + const DataHandle<GenericMuonSimHitCollection> generic_collection; + if(sg->retrieve( generic_collection,key.toStdString().c_str() )==StatusCode::SUCCESS) + { + messageVerbose("Retrieved"+key+"with size: "+str(generic_collection->size())); + std::cout<<"Got collection with size: "<<generic_collection->size()<<std::endl; + + //unsigned int i=0; // for DEBUG only + for(GenericMuonSimHitConstIterator i_hit=generic_collection->begin();i_hit!=generic_collection->end();++i_hit) + { + // std::cout << "Got hit number: " << i++ << std::endl; // for DEBUG only + const GenericMuonSimHit ghit(*i_hit); + const Amg::Vector3D& u = ghit.globalPosition(); + hitVtxProperty->vertex.set1Value(hitCount++,u.x(),u.y(),u.z()); + } + } + else + message("Unable to retrieve Generic Muon Hits from "+key); + } + } else if(detector=="Forward Region") + { + // + // Generic: + // + message("Trying for ForwardRegion (as many collections as can be found)"); + foreach(QString key,VP1SGContentsHelper(this).getKeys<SimulationHitCollection>()) { + const DataHandle<SimulationHitCollection> generic_collection; + if(sg->retrieve( generic_collection,key.toStdString().c_str() )==StatusCode::SUCCESS) + { + messageVerbose("Retrieved"+key+"with size: "+str(generic_collection->size())); + std::cout<<"Got collection with size: "<<generic_collection->size()<<std::endl; + + //unsigned int i=0; // for DEBUG only + for(SimulationHitConstIter i_hit=generic_collection->begin();i_hit!=generic_collection->end();++i_hit) + { + // std::cout << "Got hit number: " << i++ << std::endl; // for DEBUG only + const SimulationHit ghit(*i_hit); + const Amg::Vector3D& u = Amg::Hep3VectorToEigen(ghit.pre().position); + hitVtxProperty->vertex.set1Value(hitCount++,u.x(),u.y(),u.z()); + } + } + else + message("Unable to retrieve Simulation Hits from "+key); + } + } + + // Add to the switch + hitPointSet->numPoints=hitCount; + hitPointSet->vertexProperty.setValue(hitVtxProperty); + _switch->addChild(hitPointSet); + hitPointSet->enableNotify(TRUE); + hitVtxProperty->enableNotify(TRUE); +} + diff --git a/graphics/VP1/VP1Systems/VP1SimHitSystems/src/simhitcontrollerform.ui b/graphics/VP1/VP1Systems/VP1SimHitSystems/src/simhitcontrollerform.ui new file mode 100755 index 00000000000..219980ef13d --- /dev/null +++ b/graphics/VP1/VP1Systems/VP1SimHitSystems/src/simhitcontrollerform.ui @@ -0,0 +1,236 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>SimHitControllerForm</class> + <widget class="QWidget" name="SimHitControllerForm"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>454</width> + <height>310</height> + </rect> + </property> + <property name="windowTitle"> + <string>Sim Hits</string> + </property> + <layout class="QHBoxLayout"> + <property name="spacing"> + <number>6</number> + </property> + <property name="margin"> + <number>9</number> + </property> + <item> + <layout class="QVBoxLayout"> + <property name="spacing"> + <number>6</number> + </property> + <property name="margin"> + <number>0</number> + </property> + <item> + <layout class="QVBoxLayout"> + <property name="spacing"> + <number>6</number> + </property> + <property name="margin"> + <number>0</number> + </property> + <item> + <layout class="QHBoxLayout"> + <property name="spacing"> + <number>6</number> + </property> + <property name="margin"> + <number>0</number> + </property> + <item> + <widget class="QLabel" name="lblGeneral"> + <property name="text"> + <string>Select hits to show</string> + </property> + </widget> + </item> + <item> + <spacer> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>71</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout"> + <property name="spacing"> + <number>6</number> + </property> + <property name="margin"> + <number>0</number> + </property> + <item> + <layout class="QVBoxLayout"> + <property name="spacing"> + <number>6</number> + </property> + <property name="margin"> + <number>0</number> + </property> + </layout> + </item> + <item> + <widget class="QGroupBox" name="groupBox"> + <property name="title"> + <string>Inner Detector</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QCheckBox" name="chbxPixelHits"> + <property name="text"> + <string>Pixel Hits</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="chbxSCTHits"> + <property name="text"> + <string>SCT Hits</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="chbxTRTHits"> + <property name="text"> + <string>TRT Hits</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <spacer> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QGroupBox" name="groupBox_2"> + <property name="title"> + <string>MuonSpectrometer</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <widget class="QCheckBox" name="chbxMDTHits"> + <property name="text"> + <string>MDT Hits</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="chbxRPCHits"> + <property name="text"> + <string>RPC Hits</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="chbxTGCHits"> + <property name="text"> + <string>TGC Hits</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="chbxCSCHits"> + <property name="text"> + <string>CSC Hits</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="chbxGenericMuonHits"> + <property name="text"> + <string>Generic</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <layout class="QVBoxLayout"> + <property name="spacing"> + <number>6</number> + </property> + <property name="margin"> + <number>0</number> + </property> + </layout> + </item> + </layout> + </item> + </layout> + </item> + <item> + <widget class="QGroupBox" name="groupBox_3"> + <property name="title"> + <string>Forward Region</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_3"> + <item> + <widget class="QCheckBox" name="chbxForwardRegionHits"> + <property name="text"> + <string>Forward Region</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <spacer> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>111</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + <item> + <spacer> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>111</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> -- GitLab