diff --git a/Vis/SoEvent/CMakeLists.txt b/Vis/SoEvent/CMakeLists.txt index b7da0d622ec2d672f9791efc8480667e1bfda0c9..092782325e25f0605fa6307b5edbd765d89b465b 100644 --- a/Vis/SoEvent/CMakeLists.txt +++ b/Vis/SoEvent/CMakeLists.txt @@ -40,6 +40,7 @@ gaudi_add_module(SoEvent src/SoVeloClusterCnv.cpp src/SoFTClusterCnv.cpp src/SoSTClusterCnv.cpp + src/SoUTClusterCnv.cpp src/SoOTClusterCnv.cpp src/SoMuonCoordCnv.cpp src/SoL0MuonCoordCnv.cpp diff --git a/Vis/SoEvent/src/SoSTClusterCnv.cpp b/Vis/SoEvent/src/SoSTClusterCnv.cpp index 01cca75224760fd63cec5b43f280a58a8c108027..99a11b188da62e41d66e013cd77dcbd859335007 100755 --- a/Vis/SoEvent/src/SoSTClusterCnv.cpp +++ b/Vis/SoEvent/src/SoSTClusterCnv.cpp @@ -125,7 +125,6 @@ StatusCode SoSTClusterCnv::createRep( DeSTDetector* itracker=0; DeSTDetector* ttracker=0; - DeSTDetector* utracker=0; IToolSvc* toolSvc = 0; StatusCode sc = service( "ToolSvc", toolSvc, true ); if( sc.isFailure() ) { @@ -135,38 +134,29 @@ StatusCode SoSTClusterCnv::createRep( // get position tool ISTClusterPosition* ttPositionTool; ISTClusterPosition* itPositionTool; - ISTClusterPosition* utPositionTool; - utracker=SmartDataPtr<DeSTDetector>(fDetectorDataSvc,DeSTDetLocation::location("UT")); itracker=SmartDataPtr<DeSTDetector>(fDetectorDataSvc,DeSTDetLocation::location("IT")); ttracker=SmartDataPtr<DeSTDetector>(fDetectorDataSvc,DeSTDetLocation::location("TT")); - if (!utracker){ - sc = toolSvc->retrieveTool("STOfflinePosition/ITClusterPosition", itPositionTool); - if ( !itracker ) { + + sc = toolSvc->retrieveTool("STOfflinePosition/ITClusterPosition", itPositionTool); + if ( !itracker ) { log << MSG::ERROR << "Unable to retrieve IT detector element" << " from xml." << endmsg; return StatusCode::FAILURE; - } - if (sc.isFailure()){ + } + if (sc.isFailure()){ log << MSG::FATAL << "Unable to retrieve ITPosition Tool " << endmsg; return sc; - } - sc = toolSvc->retrieveTool("STOfflinePosition", ttPositionTool); - if ( !ttracker ) { + } + sc = toolSvc->retrieveTool("STOfflinePosition", ttPositionTool); + if ( !ttracker ) { log << MSG::ERROR << "Unable to retrieve TT detector element" << " from xml." << endmsg; return StatusCode::FAILURE; - } - if (sc.isFailure()){ + } + if (sc.isFailure()){ log << MSG::FATAL << "Unable to retrieve TTPosition Tool " << endmsg; return sc; - } - }else{ - sc = toolSvc->retrieveTool("STOfflinePosition/UTClusterPosition", utPositionTool); - if (sc.isFailure()){ - log << MSG::FATAL << "Unable to retrieve UTPosition Tool " << endmsg; - return sc; - } } // Representation attributes : @@ -228,15 +218,9 @@ StatusCode SoSTClusterCnv::createRep( DeSTDetector* tdet; ISTClusterPosition* icluspos; const LHCb::STCluster* arg1 = dynamic_cast<const LHCb::STCluster*>(cluster); - if (arg1->isUT() ){ - tdet = utracker; - icluspos = utPositionTool ; - log << MSG::INFO << "STCluster : UT" << endmsg; - }else{ - tdet = arg1->isIT()?itracker:ttracker; - log << MSG::INFO << "STCluster : "<< arg1->isTT() << endmsg; - icluspos = arg1->isIT()?itPositionTool:ttPositionTool ; - } + tdet = arg1->isIT()?itracker:ttracker; + log << MSG::INFO << "STCluster : "<< arg1->isTT() << endmsg; + icluspos = arg1->isIT()?itPositionTool:ttPositionTool ; log << MSG::INFO << "STCluster clusterposition " << arg1 << " " << tdet << " " << icluspos << endmsg; LHCb::STMeasurement meas = LHCb::STMeasurement( *arg1, *tdet, *icluspos ); log << MSG::INFO << "STCluster measurement done " << endmsg; diff --git a/Vis/SoEvent/src/SoUTClusterCnv.cpp b/Vis/SoEvent/src/SoUTClusterCnv.cpp new file mode 100755 index 0000000000000000000000000000000000000000..8df0bd7abf6d7a1e3e6b3362cba0798fe6744cc4 --- /dev/null +++ b/Vis/SoEvent/src/SoUTClusterCnv.cpp @@ -0,0 +1,259 @@ +// To fix clashes between Gaudi and Windows : +#include "OnXSvc/Win32.h" + +// this : +#include "SoUTClusterCnv.h" + +// Inventor : +#include "Inventor/nodes/SoSeparator.h" +#include "Inventor/nodes/SoLightModel.h" +#include "Inventor/nodes/SoDrawStyle.h" +#include "Inventor/nodes/SoCoordinate3.h" +#include "Inventor/nodes/SoTransform.h" +#include "Inventor/nodes/SoIndexedLineSet.h" + +// HEPVis : +#include "HEPVis/nodes/SoSceneGraph.h" +#include "HEPVis/nodes/SoHighlightMaterial.h" +#include "HEPVis/misc/SoStyleCache.h" + +// Lib : +#include "Lib/smanip.h" +#include "Lib/Interfaces/ISession.h" + +// Gaudi : +#include "GaudiKernel/SmartDataPtr.h" +#include "GaudiKernel/MsgStream.h" +#include "Kernel/IParticlePropertySvc.h" +#include "Kernel/ParticleProperty.h" +#include "GaudiKernel/IToolSvc.h" +// LHCb : +#include "Event/UTCluster.h" +#include "UTDet/DeUTDetector.h" +#include "UTDet/DeUTSector.h" +#include "Kernel/Trajectory.h" + +#include "TrackInterfaces/IUTClusterPosition.h" +#include "Event/UTMeasurement.h" +// OnXSvc : +#include "OnXSvc/Filter.h" +#include "OnXSvc/IUserInterfaceSvc.h" +#include "OnXSvc/ClassID.h" +#include "OnXSvc/Helpers.h" + +DECLARE_COMPONENT( SoUTClusterCnv ) + +////////////////////////////////////////////////////////////////////////////// +SoUTClusterCnv::SoUTClusterCnv( + ISvcLocator* aSvcLoc +) +:SoEventConverter(aSvcLoc,SoUTClusterCnv::classID()) +////////////////////////////////////////////////////////////////////////////// +//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// +{ +} +////////////////////////////////////////////////////////////////////////////// +StatusCode SoUTClusterCnv::createRep( + DataObject* aObject +,IOpaqueAddress*& aAddr +) +////////////////////////////////////////////////////////////////////////////// +//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// +{ + MsgStream log(msgSvc(), "SoUTClusterCnv"); + log << MSG::INFO << "UTCluster createReps" << endmsg; + + if(!fUISvc) { + log << MSG::INFO << " UI service not found" << endmsg; + return StatusCode::SUCCESS; + } + + if(!fParticlePropertySvc) { + log << MSG::INFO << " ParticleProperty service not found" << endmsg; + return StatusCode::SUCCESS; + } + + ISession* session = fUISvc->session(); + if(!session) { + log << MSG::INFO << " can't get ISession." << endmsg; + return StatusCode::FAILURE; + } + + SoRegion* region = 0; + if(aAddr) { + // Optimization. + // If having a not null aAddr, we expect a SoRegion. + // See SoEvent/Type.h/SoEvent::Type<>::beginVisualize. + region = (SoRegion*)aAddr; + } else { + region = fUISvc->currentSoRegion(); + } + if(!region) { + log << MSG::INFO << " can't get viewing region." << endmsg; + return StatusCode::FAILURE; + } + + if(!aObject) { + log << MSG::INFO << " NULL object." << endmsg; + return StatusCode::FAILURE; + } + + LHCb::UTClusters* clusters = dynamic_cast<LHCb::UTClusters*>(aObject); + if(!clusters) { + log << MSG::INFO << " bad object type." << endmsg; + return StatusCode::FAILURE; + } + + bool deleteVector = false; + // Filter : + Filter<LHCb::UTCluster> filter(*fUISvc,log); + const std::string& cuts = fUISvc->cuts(); + if(cuts!="") { + log << MSG::INFO << " cuts \"" << cuts << "\"" << endmsg; + clusters = filter.collect(*clusters,"UTCluster",cuts); + if(!clusters) return StatusCode::SUCCESS; + //filter.dump(*clusters,"UTCluster"); + deleteVector = true;; + } + + if(!clusters->size()) { + log << MSG::INFO << " collection is empty." << endmsg; + return StatusCode::SUCCESS; + } + + // get geometry + + DeUTDetector* tdet = SmartDataPtr<DeUTDetector>(fDetectorDataSvc,DeUTDetLocation::UT); + IToolSvc* toolSvc = 0; + StatusCode sc = service( "ToolSvc", toolSvc, true ); + if( sc.isFailure() ) { + log << MSG::FATAL << "Unable to retrieve ToolSvc " << endmsg; + } + + // get position tool + IUTClusterPosition* icluspos = nullptr; + sc = toolSvc->retrieveTool("UTOfflinePosition/UTClusterPosition", icluspos); + if (sc.isFailure()){ + log << MSG::FATAL << "Unable to retrieve UTPosition Tool " << endmsg; + return sc; + } + + // Representation attributes : + // Get color (default is grey (valid on black or white background) ): + double r = 0.5, g = 0.5, b = 0.5; + double hr = 1.0, hg = 1.0, hb = 0.0; + std::string value; + if(session->parameterValue("modeling.color",value)) + Lib::smanip::torgb(value,r,g,b); + if(session->parameterValue("modeling.highlightColor",value)) + Lib::smanip::torgb(value,hr,hg,hb); + double lineWidth = 0; + if(session->parameterValue("modeling.lineWidth",value)) + if(!Lib::smanip::todouble(value,lineWidth)) lineWidth = 0; + + SoStyleCache* styleCache = region->styleCache(); + SoLightModel* lightModel = styleCache->getLightModelBaseColor(); + SoDrawStyle* drawStyle = + styleCache->getLineStyle(SbLinePattern_solid,float(lineWidth)); + SoMaterial* highlightMaterial = + styleCache->getHighlightMaterial(float(r),float(g),float(b), + float(hr),float(hg),float(hb),0,TRUE); + + SoSeparator* separator = new SoSeparator; + + SoCoordinate3* coordinate3 = new SoCoordinate3; + separator->addChild(coordinate3); + int icoord = 0; + int32_t coordIndex[3]; + SbBool empty = TRUE; + + // One scene graph per UTCluster : + + LHCb::UTClusters::iterator it; + for(it = clusters->begin(); it != clusters->end(); it++) { + LHCb::UTCluster* cluster = (*it); + LHCb::UTChannelID chan = cluster->channelID(); + + // Build name : + char sid[64]; + ::sprintf(sid,"UTCluster/0x%lx",(unsigned long)cluster); + + SoSceneGraph* sep = new SoSceneGraph; + sep->setString(sid); + + separator->addChild(sep); + + sep->addChild(highlightMaterial); + + sep->addChild(lightModel); + sep->addChild(drawStyle); + + // find the sector + // only online info + // DeUTSector* sector = tracker->findSector(chan); + // std::auto_ptr<LHCb::Trajectory> traj_online = sector->trajectory(chan,cluster->interStripFraction()); + + // another possibility + const LHCb::UTCluster* arg1 = dynamic_cast<const LHCb::UTCluster*>(cluster); + + LHCb::UTMeasurement meas = LHCb::UTMeasurement( *arg1, *tdet, *icluspos ); + log << MSG::INFO << "UTCluster measurement done " << endmsg; + const LHCb::Trajectory<double>& traj = meas.trajectory(); + + // endpoints of trajectory + Gaudi::XYZPoint start = traj.beginPoint(); + Gaudi::XYZPoint stop = traj.endPoint(); + + int pointn = 2; + SbVec3f points[2]; + points[0].setValue(float(start.x()), float(start.y()), float(start.z())); + points[1].setValue(float(stop.x()), float(stop.y()), float(stop.z())); + coordIndex[0] = icoord + 0; + coordIndex[1] = icoord + 1; + coordIndex[2] = SO_END_LINE_INDEX; + + coordinate3->point.setValues(icoord,pointn,points); + icoord += pointn; + + SoIndexedLineSet* lineSet = new SoIndexedLineSet; + lineSet->coordIndex.setValues(0,pointn+1,coordIndex); + sep->addChild(lineSet); + + empty = FALSE; + } + + if(deleteVector) { + // We have first to empty the vector : + while(clusters->size()) { + clusters->remove(*(clusters->begin())); + } + // Then we can delete it : + delete clusters; + } + + if(empty==TRUE) { + separator->unref(); + } else { + // Send scene graph to the viewing region + // (in the "dynamic" sub-scene graph) : + region_addToDynamicScene(*region,separator); + } + + return StatusCode::SUCCESS; +} +////////////////////////////////////////////////////////////////////////////// +const CLID& SoUTClusterCnv::classID( +) +////////////////////////////////////////////////////////////////////////////// +//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// +{ + return LHCb::UTClusters::classID(); +} +////////////////////////////////////////////////////////////////////////////// +unsigned char SoUTClusterCnv::storageType( +) +////////////////////////////////////////////////////////////////////////////// +//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// +{ + return So_TechnologyType; +} diff --git a/Vis/SoEvent/src/SoUTClusterCnv.h b/Vis/SoEvent/src/SoUTClusterCnv.h new file mode 100755 index 0000000000000000000000000000000000000000..cb14d5e823c85acbd1863ea6df9c4cba5d4577e1 --- /dev/null +++ b/Vis/SoEvent/src/SoUTClusterCnv.h @@ -0,0 +1,15 @@ +#ifndef SoEvent_SoUTClusterCnv_h +#define SoEvent_SoUTClusterCnv_h + +#include "SoEventConverter.h" + +class SoUTClusterCnv : public SoEventConverter { +public: + SoUTClusterCnv(ISvcLocator*); + virtual StatusCode createRep(DataObject*,IOpaqueAddress*&); +public: + static const CLID& classID(); + static unsigned char storageType(); +}; + +#endif