Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:17:11

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 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 
0014 /// Framework include files
0015 #include <DD4hep/Printout.h>
0016 #include <DD4hep/detail/SegmentationsInterna.h>
0017 #include <DDDigi/segmentations/CartesianGridXY.h>
0018 #include <DDDigi/segmentations/SegmentationScanner.h>
0019 
0020 #if 0
0021 /// Namespace for the AIDA detector description toolkit
0022 namespace dd4hep {
0023   
0024   /// Namespace for the Digitization part of the AIDA detector description toolkit
0025   namespace digi {
0026 
0027     template <>
0028     void init_segmentation_data<CartesianGridXY>(segmentation_data<CartesianGridXY>& data,
0029                                                  const Segmentation& seg)
0030     {
0031       CartesianGridXYHandle xy_seg = seg;
0032       const auto& x_f = (*seg.decoder())["x"];
0033       const auto& y_f = (*seg.decoder())["y"];
0034       data.segmentation_xy = xy_seg->implementation;
0035       data.x_grid_size     = data.segmentation_xy->gridSizeX();
0036       data.y_grid_size     = data.segmentation_xy->gridSizeY();
0037       data.x_offset        = data.segmentation_xy->offsetX();
0038       data.y_offset        = data.segmentation_xy->offsetY();
0039       data.x_f_offset      = x_f.offset();
0040       data.y_f_offset      = y_f.offset();
0041       data.x_mask          = x_f.mask();
0042       data.y_mask          = y_f.mask();
0043     }
0044     
0045     template <typename SEGMENTATION, typename SOLID> void
0046     CellScanner<SEGMENTATION,SOLID>::operator()(DigiContext& context,
0047                                                 PlacedVolume pv,
0048                                                 VolumeID vid,
0049                                                 const cell_handler_t& cell_handler)
0050     {
0051       typename self_t::cell_data_t e;
0052       e.placement     = pv;
0053       e.volume        = pv.volume();
0054       e.solid         = e.volume.solid();
0055       Box           b = e.solid;
0056       double   pos[3] = {0e0, 0e0, 0e0};
0057       typename self_t::solid_t sol = e.solid;
0058       long nx = 2e0 * b->GetDX() / segment.x_grid_size;
0059       long ny = 2e0 * b->GetDY() / segment.y_grid_size;
0060       for ( e.x_bin = 0; e.x_bin < nx; ++e.x_bin )   {
0061         pos[0] = (e.x_bin + 0.5) * segment.x_grid_size;
0062         e.x_cid = (e.x_bin << segment.x_f_offset) & segment.x_mask;
0063         for ( e.y_bin = 0; e.y_bin < ny; ++e.y_bin )   {
0064           pos[1] = (e.x_bin + 0.5) * segment.x_grid_size;
0065           if ( !sol->Contains(pos) ) continue;
0066           e.y_cid = (e.y_bin << segment.y_f_offset) & segment.y_mask;
0067           e.cell_id = vid | e.x_cid | e.y_cid;
0068           cell_handler(context, *this, e);
0069         }
0070       }
0071     }
0072   }    // End namespace digi
0073 }      // End namespace dd4hep
0074 
0075 
0076 /// Namespace for the AIDA detector description toolkit
0077 namespace dd4hep {  
0078   /// Namespace for the Digitization part of the AIDA detector description toolkit
0079   namespace digi {
0080 
0081     template <> void
0082     CellScanner<CartesianGridXY,Box>::operator()(DigiContext& context,
0083                                                  PlacedVolume pv,
0084                                                  VolumeID vid,
0085                                                  const cell_handler_t& cell_handler)
0086     {
0087       cell_data_t e;
0088       e.placement = pv;
0089       e.volume    = pv.volume();
0090       e.solid     = e.volume.solid();
0091       Box       b = e.solid;
0092       long nx = 2e0 * b->GetDX() / segment.x_grid_size;
0093       long ny = 2e0 * b->GetDY() / segment.y_grid_size;
0094       for ( e.x_bin = 0; e.x_bin < nx; ++e.x_bin )   {
0095         e.x_cid = (e.x_bin << segment.x_f_offset) & segment.x_mask;
0096         for ( e.y_bin = 0; e.y_bin < ny; ++e.y_bin )   {
0097           e.y_cid = (e.y_bin << segment.y_f_offset) & segment.y_mask;
0098           e.cell_id = vid | e.x_cid | e.y_cid;
0099           cell_handler(context, *this, e);
0100         }
0101       }
0102     }
0103   }    // End namespace digi
0104 }      // End namespace dd4hep
0105 
0106 DECLARE_DIGICELLSCANNER(DigiCellScanner,CartesianGridXY,Box)
0107 
0108 /// Namespace for the AIDA detector description toolkit
0109 namespace dd4hep {
0110   /// Namespace for the Digitization part of the AIDA detector description toolkit
0111   namespace digi {
0112 
0113     template <typename self_t> void
0114     scan_poly(DigiContext& context,
0115               PlacedVolume pv,
0116               VolumeID vid,
0117               const typename self_t::cell_handler_t& cell_handler,
0118               const self_t& scanner)
0119     {
0120       typename self_t::cell_data_t e;
0121       const auto& segment = scanner.segment;
0122       e.placement     = pv;
0123       e.volume        = pv.volume();
0124       e.solid         = e.volume.solid();
0125       Box           b = e.solid;
0126       typename self_t::solid_t h = e.solid;
0127       long   nx     = 2e0 * b->GetDX() / segment.x_grid_size;
0128       long   ny     = 2e0 * b->GetDY() / segment.y_grid_size;
0129       double pos[3] = {0e0, 0e0, 0e0}, r;
0130       double rmin   = h->GetRmin(0) * h->GetRmin(0);
0131       double rmax   = h->GetRmax(0) * h->GetRmax(0);
0132 
0133       for ( e.x_bin = 0; e.x_bin < nx; ++e.x_bin )   {
0134         pos[0] = (e.x_bin + 0.5) * segment.x_grid_size;
0135         pos[0] *= pos[0];
0136         if ( pos[0] > rmax ) continue;
0137         e.x_cid = (e.x_bin << segment.x_f_offset) & segment.x_mask;
0138         for ( e.y_bin = 0; e.y_bin < ny; ++e.y_bin )   {
0139           pos[1] = (e.x_bin + 0.5) * segment.x_grid_size;
0140           r = pos[0]*pos[0] + pos[1]*pos[1];
0141           if ( r < rmin || r > rmax ) continue;
0142           if ( !h->Contains(pos)    ) continue;
0143           e.y_cid = (e.y_bin << segment.y_f_offset) & segment.y_mask;
0144           e.cell_id = vid | e.x_cid | e.y_cid;
0145           cell_handler(context, scanner, e);
0146         }
0147       }
0148     }
0149 
0150     template <> void
0151     CellScanner<CartesianGridXY,PolyhedraRegular>::operator()(DigiContext& ct, PlacedVolume pv,
0152                                                               VolumeID vid, const cell_handler_t& cell_handler) {
0153       scan_poly<self_t>(ct, pv, vid, cell_handler, *this);
0154     }
0155     template <> void
0156     CellScanner<CartesianGridXY,Polyhedra>::operator()(DigiContext& ct, PlacedVolume pv, VolumeID vid,
0157                                                        const cell_handler_t& cell_handler) {
0158       scan_poly<self_t>(ct, pv, vid, cell_handler, *this);
0159     }
0160     template <> void
0161     CellScanner<CartesianGridXY,Polycone>::operator()(DigiContext& ct, PlacedVolume pv, VolumeID vid,
0162                                                       const cell_handler_t& cell_handler) {
0163       scan_poly<self_t>(ct, pv, vid, cell_handler, *this);
0164     }
0165   }    // End namespace digi
0166 }      // End namespace dd4hep
0167 
0168 DECLARE_DIGICELLSCANNER(DigiCellScanner,CartesianGridXY,PolyhedraRegular)
0169 DECLARE_DIGICELLSCANNER(DigiCellScanner,CartesianGridXY,Polyhedra)
0170 DECLARE_DIGICELLSCANNER(DigiCellScanner,CartesianGridXY,Polycone)
0171 
0172 DECLARE_DIGICELLSCANNER(DigiCellScanner,CartesianGridXY,Polycone)
0173 namespace dd4hep  {
0174   typedef IntersectionSolid Intersection;
0175   typedef SubtractionSolid Subtraction;
0176   typedef UnionSolid Union;
0177 }
0178 DECLARE_DIGICELLSCANNER(DigiCellScanner,CartesianGridXY,Intersection)
0179 DECLARE_DIGICELLSCANNER(DigiCellScanner,CartesianGridXY,Subtraction)
0180 DECLARE_DIGICELLSCANNER(DigiCellScanner,CartesianGridXY,Union)
0181 
0182 #endif