Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 09:36:49

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