Skip to content
Snippets Groups Projects
Commit ee362648 authored by Markus Frank's avatar Markus Frank
Browse files

Helper class to select Subdetectors

parent 846f2194
No related branches found
No related tags found
No related merge requests found
// $Id$
//==========================================================================
// AIDA Detector description implementation for LCD
//--------------------------------------------------------------------------
// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
// All rights reserved.
//
// For the licensing terms see $DD4hepINSTALL/LICENSE.
// For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
//
// Author : M.Frank
//
//==========================================================================
#ifndef DD4HEP_DETECTORSELECTOR_H
#define DD4HEP_DETECTORSELECTOR_H
// Framework include files
#include "DD4hep/LCDD.h"
/// Namespace for the AIDA detector description toolkit
namespace DD4hep {
/// Namespace for the geometry part of the AIDA detector description toolkit
namespace Geometry {
/// View on LCDD to select detectors according to certain criteria
/**
* Usage:
*
* LCDD& lcd = ....;
* DetectorSelector selector(lcdd);
* DetectorSelector::Result r = selector.detectors("tracker");
*
* or multiple types:
* r = selector.detectors("tracker", "calorimeter");
*
* or selections using DetElement flags (DetElement::typeFlag)
* r = selector.detectors(0x15, 0xFF0);
*
* \author M.Frank
* \version 1.0
*/
class DetectorSelector {
public:
/// Result set definition
typedef std::vector<DetElement> Result;
/// Reference to main detector description object
LCDD& lcdd;
public:
/// Default constructor
DetectorSelector(LCDD& _lcdd) : lcdd(_lcdd) {}
/// Default destructor
~DetectorSelector() {}
/// Access a set of subdetectors according to the sensitive type.
/**
Please note:
- The sensitive type of a detector is set in the 'detector constructor'.
- Not sensitive detector structures have the name 'passive'
- Compounds (ie. nested detectors) are of type 'compound'
*/
const Result& detectors(const std::string& type);
/// Access a set of subdetectors according to several sensitive types.
Result detectors(const std::string& type1,
const std::string& type2,
const std::string& type3="",
const std::string& type4="",
const std::string& type5="" );
/** return a vector with all detectors that have all the type properties in
* includeFlag set but none of the properties given in excludeFlag
*/
Result detectors(unsigned int includeFlag,
unsigned int excludeFlag=0 ) const ;
};
} /* End namespace Geometry */
} /* End namespace DD4hep */
#endif /* DD4HEP_DETECTORSELECTOR_H */
// $Id$
//==========================================================================
// AIDA Detector description implementation for LCD
//--------------------------------------------------------------------------
// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
// All rights reserved.
//
// For the licensing terms see $DD4hepINSTALL/LICENSE.
// For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
//
// Author : M.Frank
//
//==========================================================================
// Framework include files
#include "DD4hep/DetectorSelector.h"
#include "DD4hep/LCDD.h"
using namespace std;
using namespace DD4hep::Geometry;
/// Access a set of subdetectors according to the sensitive type.
const DetectorSelector::Result&
DetectorSelector::detectors(const string& type)
{
return lcdd.detectors(type);
}
/// Access a set of subdetectors according to several sensitive types.
DetectorSelector::Result
DetectorSelector::detectors(const string& type1,
const string& type2,
const string& type3,
const string& type4,
const string& type5) {
const string* types[] = { &type1, &type2, &type3, &type4, &type5 };
Result result;
for(size_t i=0; i<sizeof(types)/sizeof(types[0]); ++i) {
try {
if ( !types[i]->empty() ) {
const vector<DetElement>& v = lcdd.detectors(*(types[i]));
result.insert(result.end(),v.begin(),v.end());
}
}
catch(...) {}
}
return result;
}
/** return a vector with all detectors that have all the type properties in
* includeFlag set but none of the properties given in excludeFlag
*/
DetectorSelector::Result
DetectorSelector::detectors(unsigned int includeFlag, unsigned int excludeFlag ) const {
Result result;
const LCDD::HandleMap& entries = lcdd.detectors();
result.reserve( entries.size() ) ;
lcdd.detectors(""); // Just to ensure the geometry is closed....
for(LCDD::HandleMap::const_iterator i=entries.begin(); i!=entries.end(); ++i) {
DetElement det((*i).second);
if ( det.parent().isValid() ) { // Exclude 'world'
//fixme: what to do with compounds - add their daughters ?
// ...
if( ( det.typeFlag() & includeFlag ) == includeFlag &&
( det.typeFlag() & excludeFlag ) == 0 )
result.push_back( det ) ;
}
}
return result;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment