Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-01 07:54:55

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 //  Created: Jun 28, 2013
0011 //  Author:  Christian Grefe, CERN
0012 //
0013 //==========================================================================
0014 
0015 /// Framework include files
0016 #include <DDSegmentation/MultiSegmentation.h>
0017 #include <DD4hep/Printout.h>
0018 
0019 /// C/C++ include files
0020 #include <string>
0021 
0022 namespace dd4hep {
0023 
0024   namespace DDSegmentation {
0025 
0026     /// default constructor using an encoding string
0027     MultiSegmentation::MultiSegmentation(const std::string& cellEncoding)
0028       : Segmentation(cellEncoding), m_discriminator(0), m_debug(0)
0029     {
0030       // define type and description
0031       _type        = "MultiSegmentation";
0032       _description = "Multi-segmenation wrapper segmentation";
0033       //registerParameter<int>("debug", "Debug flag", m_debug, 0);
0034       registerParameter<std::string>("key", "Diskriminating field", m_discriminatorId, "");
0035     }
0036 
0037     /// Default constructor used by derived classes passing an existing decoder
0038     MultiSegmentation::MultiSegmentation(const BitFieldCoder* decode)
0039       : Segmentation(decode), m_discriminator(0), m_debug(0)
0040     {
0041       // define type and description
0042       _type        = "MultiSegmentation";
0043       _description = "Multi-segmenation wrapper segmentation";
0044       //registerParameter<int>("debug", "Debug flag", m_debug, 0);
0045       registerParameter<std::string>("key", "Diskriminating field", m_discriminatorId, "");
0046     }
0047 
0048     /// destructor
0049     MultiSegmentation::~MultiSegmentation() {
0050       for(Segmentations::iterator i=m_segmentations.begin(); i!=m_segmentations.end(); ++i)
0051         delete (*i).segmentation;
0052       m_segmentations.clear();
0053     }
0054 
0055     /// Add subsegmentation. Call only valid for Multi-segmentations. Default implementation throws an exception
0056     void MultiSegmentation::addSubsegmentation(long key_min, long key_max, Segmentation* entry)  {
0057       Entry e;
0058       e.key_min = key_min;
0059       e.key_max = key_max;
0060       e.segmentation = entry;
0061       m_segmentations.emplace_back(e);
0062     }
0063 
0064     /// Set the underlying decoder
0065     void MultiSegmentation::setDecoder(const BitFieldCoder* newDecoder) {
0066       this->Segmentation::setDecoder(newDecoder);
0067       for(Segmentations::iterator i=m_segmentations.begin(); i != m_segmentations.end(); ++i)
0068         (*i).segmentation->setDecoder(newDecoder);
0069       m_discriminator = &((*_decoder)[m_discriminatorId]);
0070     }
0071 
0072     /// 
0073     const Segmentation& MultiSegmentation::subsegmentation(const CellID& cID)   const  {
0074       if ( m_discriminator )  {
0075         long seg_id = m_discriminator->value(cID);
0076         for(Segmentations::const_iterator i=m_segmentations.begin(); i != m_segmentations.end(); ++i)  {
0077           const Entry& e = *i; 
0078           if ( e.key_min<= seg_id && e.key_max >= seg_id )  {
0079             Segmentation* s = e.segmentation;
0080             if ( m_debug > 0 )  {
0081               printout(ALWAYS,"MultiSegmentation","Id: %04X %s", seg_id, s->name().c_str());
0082               const Parameters& pars = s->parameters();
0083               for( const auto* p : pars )  {
0084                 printout(ALWAYS,"MultiSegmentation"," Param  %s = %s",
0085                          p->name().c_str(), p->value().c_str());
0086               }
0087             }
0088             return *s;
0089           }
0090         }
0091       }
0092       except("MultiSegmentation", "Invalid sub-segmentation identifier!");
0093       throw std::string("Invalid sub-segmentation identifier!");
0094     }
0095      
0096     /// determine the position based on the cell ID
0097     Vector3D MultiSegmentation::position(const CellID& cID) const {
0098       return subsegmentation(cID).position(cID);
0099     }
0100 
0101     /// determine the cell ID based on the position
0102     CellID MultiSegmentation::cellID(const Vector3D& localPosition, const Vector3D& globalPosition, const VolumeID& vID) const {
0103       return subsegmentation(vID).cellID(localPosition, globalPosition, vID);
0104     }
0105 
0106     std::vector<double> MultiSegmentation::cellDimensions(const CellID& cID) const {
0107       return subsegmentation(cID).cellDimensions(cID);
0108     }
0109 
0110   } /* namespace DDSegmentation */
0111 } /* namespace dd4hep */