Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:14:50

0001 //==============================================================================
0002 //  AIDA Detector description implementation for LHCb
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   Markus Frank
0011 //  \date     2018-03-08
0012 //  \version  1.0
0013 //
0014 //==============================================================================
0015 #ifndef DETECTOR_DEVELOSENSOR_H 
0016 #define DETECTOR_DEVELOSENSOR_H 1
0017 
0018 // C/C++ include files
0019 #include <array>
0020 
0021 // Framework include files
0022 #include "Detector/DetectorElement.h"
0023 #include "Detector/DeStatic.h"
0024 #include "Detector/DeIOV.h"
0025 #include "DD4hep/DD4hepUnits.h"
0026 
0027 /// Gaudi namespace declaration
0028 namespace gaudi   {
0029 
0030   namespace DeVeloConst  {
0031   }
0032   namespace DeVeloFlags  {
0033     enum {
0034       // DeVelo specific
0035       ALL        =    2,
0036 
0037       // de_flags flags(static/dynamic): ALL objects
0038       RIGHT      =    0,
0039       LEFT       = 1<<0,
0040       MAIN       = 1<<2,
0041       SIDE       = 1<<3,
0042       SUPPORT    = 1<<4,
0043       MODULE     = 1<<5,
0044       LADDER     = 1<<6,
0045       SENSOR     = 1<<7,
0046 
0047       // de_user flags(static): DeVeloSensorStatic specific
0048       TOP        = 1<<8,  // 4
0049       DOWNSTREAM = 1<<9,
0050       R_TYPE     = 1<<10,
0051       PHI_TYPE   = 1<<11,
0052       PU_TYPE    = 1<<12,
0053 
0054       // de_user flags(dynamic): DeVeloSensorIOV specific
0055       READOUT    = 1<<7,
0056       T1NOSENS   = 1<<8
0057     };
0058   }
0059     
0060   /// Gaudi::detail namespace declaration
0061   namespace detail   {
0062 
0063     /// Generic VP static detector element 
0064     /**
0065      *
0066      *  \author  Markus Frank
0067      *  \date    2018-03-08
0068      *  \version  1.0
0069      */
0070     class DeVeloSensorStaticObject : public detail::DeStaticObject  {
0071     public:
0072       /// Unique classID
0073       enum { classID = 1008101  };
0074 
0075       static const unsigned int     minRoutingLine = 1;
0076       static const unsigned int     maxRoutingLine = 2048;
0077       static const unsigned int     numberOfStrips = 2048;
0078 
0079       std::string   moduleName;
0080       std::string   typeName;
0081       std::string   fullType;
0082       int           moduleId;//<Liverpool database module id
0083       unsigned int  sensorNumber;
0084       double        siliconThickness;
0085       double          innerRadius;
0086       double          outerRadius;
0087       
0088       /// Un-inited - still
0089       unsigned int  numberOfZones;
0090       std::map< unsigned int, unsigned int >    mapRoutingLineToStrip;
0091       std::map< unsigned int, unsigned int >    mapStripToRoutingLine;
0092       std::vector< std::pair< XYZPoint, XYZPoint > >    stripLimits;
0093 
0094     public:
0095       /// Standard constructors and assignment
0096       DE_CTORS_DEFAULT(DeVeloSensorStaticObject);
0097 
0098       /// Initialization of sub-classes
0099       virtual void initialize()  override;
0100       /// Printout method to stdout
0101       virtual void print(int indent, int flags)  const  override;
0102     };
0103   }    // End namespace detail
0104 
0105   /// Handle definition to an instance of VP static detector element data
0106   /**
0107    *  This object defines the behaviour of the objects's data.
0108    *  We implement here only the behaviour of the object specific
0109    *  stuff. The geometry interactions are then combined with this
0110    *  implementation and the specialized detector element
0111    *  DetectorElementStatic<TYPE> to the real data accessor.
0112    *  The DetectorElementStatic<TYPE> by non-virtual inheritance
0113    *  automatically exposes the specific stuff here.
0114    *
0115    *  See the corresponding typedef below.
0116    *
0117    *  Note: in this class the is no big deal of specialization!
0118    *        this for the time being is only for illustration about the mechanism.
0119    *
0120    *  \author  Markus Frank
0121    *  \date    2018-03-08
0122    *  \version  1.0
0123    */
0124   class DeVeloSensorStaticElement : public dd4hep::Handle<detail::DeVeloSensorStaticObject>   {
0125     DE_CONDITIONS_TYPEDEFS;
0126     /// This is needed by the DetectorElement<TYPE> to properly forward requests.
0127     typedef Object static_t;
0128   public:
0129     /// Standard constructors and assignment
0130     DE_CTORS_HANDLE(DeVeloSensorStaticElement,Base);
0131   };
0132 
0133   /// For the full sensor object, we have to combine it with the geometry stuff:
0134   typedef  DetectorStaticElement<DeVeloSensorStaticElement>  DeVeloSensorStatic;
0135   
0136   
0137   /// Gaudi::detail namespace declaration
0138   namespace detail   {
0139 
0140     /// Generic VP iov dependent detector element 
0141     /**
0142      *
0143      *  \author  Markus Frank
0144      *  \date    2018-03-08
0145      *  \version  1.0
0146      */
0147     class DeVeloSensorObject : public DeIOVObject  {
0148       DE_CONDITIONS_TYPEDEFS;
0149       typedef DeVeloSensorStatic::Object static_t;
0150       
0151       /// The static part of the detector element. Cached for optimizations to avoid casts
0152       DeVeloSensorStatic sensor_static;
0153       
0154       /** For ref only: values are taken from the RUN-II conditions information  */
0155       /// Reference to time-dependent sensor information
0156       Condition        info;
0157       /// Reference to time-dependent noise
0158       Condition        noise;
0159       /// Reference to time-dependent readout configuration parameters
0160       Condition        readout;
0161 
0162       DeIOV            halfBoxGeom;      
0163       Condition          stripNoiseCondition;
0164       Condition          stripInfoCondition;
0165       Condition          readoutCondition;
0166       
0167       std::vector< double > stripNoise;
0168       std::vector< int >    stripInfos;
0169 
0170       double          z = 0.0;
0171       
0172     public:
0173       /// Standard constructors and assignment
0174       DE_CTORS_DEFAULT(DeVeloSensorObject);
0175 
0176       /// Initialization of sub-classes
0177       virtual void initialize()  override;
0178       /// Printout method to stdout
0179       virtual void print(int indent, int flags)  const  override;
0180     };
0181   }    // End namespace detail
0182 
0183   
0184   /// Handle defintiion to an instance of VP IOV dependent data
0185   /**
0186    *  This object defines the behaviour of the objects's data.
0187    *  We implement here only the behaviour of the object specific
0188    *  stuff. The geometry interactions are then combined with this
0189    *  implementation and the specialized detector element
0190    *  DetectorElement<TYPE> to the real data accessor.
0191    *  The DetectorElement<TYPE> by non-virtual inheritance
0192    *  automatically exposes the specific stuff here.
0193    *
0194    *  See the corresponding typedef below.
0195    *
0196    *  \author  Markus Frank
0197    *  \date    2018-03-08
0198    *  \version  1.0
0199    */
0200   class DeVeloSensorElement : public dd4hep::Handle<detail::DeVeloSensorObject>  {    
0201     DE_CONDITIONS_TYPEDEFS;
0202     /// These two are needed by the DetectorElement<TYPE> to properly forward requests.
0203     typedef Object::static_t static_t;
0204     typedef Object           iov_t;
0205 
0206   public:
0207     /** Define conditions access keys for optimization     */
0208     static const itemkey_type key_info;
0209     static const itemkey_type key_noise;
0210     static const itemkey_type key_readout;
0211 
0212     /** @class DeVeloSensor::StripInfo DeVeloSensor.h VeloDet/DeVeloSensor.h
0213      *
0214      *  Encodes strip information.
0215      *  From construction information states are :
0216      *  OK, Low gain, Noisy, Dead, Open, Pinhole and Short
0217      *
0218      *  @author Kurt Rinnert
0219      *  @date   2006-01-18
0220      */
0221     class StripInfo
0222     {
0223     public:
0224       StripInfo() : m_info(0) { ; }
0225       StripInfo(int i) : m_info(i) { ; }
0226 
0227     private:
0228       enum {
0229         LOWGAIN=  2,
0230         NOISY= 1,
0231         STRIPOK = 0,
0232         DEAD=    -1,
0233         OPEN=    -2,
0234         PINHOLE= -3,
0235         SHORT=   -4
0236       };
0237 
0238     public:
0239       /// No problems with this strip
0240       bool stripIsOK() const { return m_info==STRIPOK; }
0241       /// Lower gain strip
0242       bool stripIsLowGain() const { return m_info==LOWGAIN; }
0243       /// higher noise strip
0244       bool stripIsNoisy() const { return m_info==NOISY; }
0245       /// very low gain strip
0246       bool stripIsDead() const { return m_info==DEAD; }
0247       /// Did not bond strip to beetle
0248       bool stripIsOpen() const { return m_info==OPEN; }
0249       /// pinhole in sensor
0250       bool stripIsPinhole() const { return m_info==PINHOLE; }
0251       /// Strip shorted to another (may not be next neighbour)
0252       bool stripIsShort() const { return m_info==SHORT; }
0253       /// StripInfo as integer
0254       int asInt() const{ return m_info; }
0255 
0256     private:
0257       int m_info;
0258     };
0259 
0260     /// Standard constructors and assignment
0261     DE_CTORS_HANDLE(DeVeloSensorElement,Base);
0262     /// Access to the static data. Does this need to be optionized???
0263     static_t& staticData()  const
0264     {  return access()->sensor_static;                              }
0265     /// Access the time dependent data block. Used internally - may be specialized for optimization.
0266     const iov_t& iovData()  const
0267     {  return *access();                                            }
0268 
0269     /// Return station number, station contains 2 modules (right and left) 
0270     unsigned int station () const
0271     {  return (staticData().sensorNumber&0x3E) >> 1;                }
0272     /// Returns the sensor number.
0273     unsigned int    sensorNumber () const
0274     {  return staticData().sensorNumber;                            }
0275     /// Returns the hardware module number. 
0276     unsigned int    moduleId () const
0277     {  return staticData().moduleId;                                }
0278     /// Return the number of strips.
0279     unsigned int numberOfStrips () const
0280     {  return staticData().numberOfStrips;                          }
0281     /// Access the strip info object
0282     StripInfo stripInfo(size_t which)  const
0283     {  return iovData().stripInfos[which];                          }
0284     /// The number of zones in the detector.
0285     unsigned int    numberOfZones () const
0286     {  return staticData().numberOfZones;                           }
0287     /// Return the z position of the sensor in the global frame. 
0288     double z () const
0289     {  return iovData().z;                                          }
0290     /// The minimum radius for the sensitive area of the sensor. 
0291     double  innerRadius () const
0292     {  return staticData().innerRadius;                             }
0293     /// The maximum radius for the sensitive area of the sensor. 
0294     double  outerRadius () const
0295     {  return staticData().outerRadius;                             }
0296     /// The thickness of the sensor in mm. 
0297     double  siliconThickness () const
0298     {  return staticData().siliconThickness;                        }
0299     /// Return true for X<0 side of the detector (-ve x is Right) 
0300     bool    isRight () const
0301     {  return 0 == (staticData().de_user&DeVeloFlags::LEFT);        }
0302     /// Return true for X>0 side of the detector (+ve x is Left) 
0303     bool      isLeft () const
0304     {  return 0 != (staticData().de_user&DeVeloFlags::LEFT);        }
0305     /// Returns true if sensor is downstream. 
0306     bool      isDownstream () const
0307     {  return 0 != (staticData().de_user&DeVeloFlags::DOWNSTREAM);  }
0308     /// Returns true if pile up Sensor. 
0309     bool      isPileUp () const
0310     {  return 0 != (staticData().de_user&DeVeloFlags::PU_TYPE);     }
0311     /// Returns true if R Sensor. 
0312     bool    isR () const
0313     {  return 0 != (staticData().de_user&DeVeloFlags::R_TYPE);      }
0314     /// Returns true if Phi Sensor. 
0315     bool      isPhi () const
0316     {  return 0 != (staticData().de_user&DeVeloFlags::PHI_TYPE);    }
0317     /// Returns true if sensor is top cabled. 
0318     bool      isTop () const
0319     {  return 0 != (staticData().de_user&DeVeloFlags::TOP);         }
0320     /// Returns true if sensor is bottom cabled. 
0321     bool      isBottom () const
0322     {  return 0 == (staticData().de_user&DeVeloFlags::TOP);         }
0323     /** Check whether this sensor is read out at all (cached condition).
0324      *  This information is based on CondDB, i.e. it can change
0325      *  with time.
0326      */
0327     bool isReadOut() const
0328     { return 0 != (staticData().de_user&DeVeloFlags::READOUT);      }
0329     /** Check whether this sensor exists or is TELL1 w/o sensor (cached condition).
0330      *  This information is based on CondDB, i.e. it can change
0331      *  with time.
0332      */
0333     bool tell1WithoutSensor() const
0334     { return 0 != (staticData().de_user&DeVeloFlags::T1NOSENS);     }
0335 
0336 
0337     unsigned int globalZoneOfStrip(const unsigned int strip) const {
0338       int flg = staticData().de_user;
0339       return (flg&DeVeloFlags::PHI_TYPE)
0340         ? static_cast<unsigned int>(strip>682)
0341         : ((flg&DeVeloFlags::DOWNSTREAM) ? 3-strip/512 : strip/512);
0342     }
0343     /** The Noise of a strip (cached condition).
0344      *  This information is based on CondDB, i.e. it can change
0345      *  with time.
0346      */
0347     double stripNoise(unsigned int strip) const { return iovData().stripNoise[strip];            }
0348 
0349     /** Get info for this strip (cached condition).
0350      *  This information is based on CondDB, i.e. it can change
0351      *  with time.
0352      *  @see StripInfo
0353      */
0354     StripInfo stripInfo(unsigned int strip) const { return iovData().stripInfos[strip];          }
0355 
0356     /// Convert position inside Velo half Box (one per side) into local position
0357     /// Local from is +ve x and Upstream
0358     XYZPoint veloHalfBoxToLocal(const XYZPoint& boxPos) const  {
0359       XYZPoint globalPos = iovData().halfBoxGeom.toGlobal(boxPos);
0360       return DeIOV(ptr()).toLocal(globalPos);
0361     }
0362     /// Convert position inside Velo half Box (one per side) to global
0363     XYZPoint veloHalfBoxToGlobal(const XYZPoint& boxPos) const {
0364       return iovData().halfBoxGeom.toGlobal(boxPos);
0365     }
0366     /// Convert global position to inside Velo half Box (one per side)
0367     XYZPoint globalToVeloHalfBox(const XYZPoint& globalPos) const {
0368       return iovData().halfBoxGeom.toLocal(globalPos);
0369     }
0370 
0371     /// Returns a pair of points which define the begin and end points of a strip in the local frame
0372     std::pair<XYZPoint,XYZPoint> localStripLimits(unsigned int strip) const {
0373       return staticData().stripLimits[strip];
0374     }
0375 
0376     /// Returns a pair of points which define the begin and end points of a strip in the global frame
0377     std::pair<XYZPoint,XYZPoint> globalStripLimits(unsigned int strip) const {
0378       const DeIOV iov(ptr());
0379       const static_t& s = staticData();
0380       XYZPoint begin = iov.toGlobal(s.stripLimits[strip].first);
0381       XYZPoint end   = iov.toGlobal(s.stripLimits[strip].second);
0382       return std::pair<XYZPoint,XYZPoint>(begin,end);
0383     }
0384     /// Convert local phi to ideal global phi
0385     double localPhiToGlobal(double phiLocal) const {
0386       int flg = staticData().de_user;
0387       if(  flg&DeVeloFlags::DOWNSTREAM ) phiLocal = -phiLocal;
0388       if( 0 == (flg&DeVeloFlags::LEFT) ) phiLocal += dd4hep::pi;  // if ( isRight() ) ....
0389       return phiLocal;
0390     }
0391     /// Convert routing line to chip channel (1234 -> 0213)
0392     unsigned int RoutingLineToChipChannel(unsigned int routLine) const {
0393       routLine = detail::DeVeloSensorStaticObject::maxRoutingLine-routLine;
0394       if(1 == routLine%4){
0395         routLine++;
0396       }else if(2 == routLine%4){
0397         routLine--;
0398       }
0399       return routLine;
0400     }
0401     /// Convert chip channel to routing line (0213 -> 1234)
0402     unsigned int ChipChannelToRoutingLine(unsigned int chipChan) const {
0403       if(1 == chipChan%4){
0404         chipChan++;
0405       } else if(2 == chipChan%4) {
0406         chipChan--;
0407       }
0408       return (detail::DeVeloSensorStaticObject::numberOfStrips-chipChan);
0409     }
0410     /// Convert chip channel to strip number
0411     unsigned int ChipChannelToStrip(unsigned int chipChan) const {
0412       return RoutingLineToStrip(ChipChannelToRoutingLine(chipChan));
0413     }
0414     /// Convert strip number to chip channel
0415     unsigned int StripToChipChannel(unsigned int strip) const {
0416       return RoutingLineToChipChannel(StripToRoutingLine(strip));
0417     }
0418     /// Convert routing line to strip number
0419     unsigned int RoutingLineToStrip(unsigned int routLine) const {
0420       return staticData().mapRoutingLineToStrip.at(routLine);
0421     }
0422     /// Convert strip number to routing line
0423     unsigned int StripToRoutingLine(unsigned int strip) const {
0424       return staticData().mapStripToRoutingLine.at(strip);
0425     }
0426     /// Get the chip number from the routing line
0427     unsigned int ChipFromRoutingLine(unsigned int routLine) const {
0428       return ChipFromChipChannel(RoutingLineToChipChannel(routLine));
0429     }
0430     /// Get the chip number from the chip channel
0431     unsigned int ChipFromChipChannel(unsigned int chipChan) const {
0432       return static_cast<int>(chipChan/128);
0433     }
0434     /// Get the Chip from the strip
0435     unsigned int ChipFromStrip(unsigned int strip) const {
0436       return ChipFromChipChannel(StripToChipChannel(strip));
0437     }
0438     /**  Return the validity of a strip
0439      *   Since this method uses the condition cache, the result
0440      *   depends on CondDB.
0441      */
0442     bool OKStrip(unsigned int strip) const {
0443       return (strip<staticData().numberOfStrips && stripInfo(strip).stripIsOK());
0444     }
0445     /// Returns the validity of a given channel
0446     bool OKChipChannel(unsigned int chipChan) const {
0447       return (chipChan<staticData().numberOfStrips && OKStrip(ChipChannelToStrip(chipChan)));
0448     } 
0449   };
0450   
0451   /// For the full sensor object, we have to combine it with the geometry stuff:
0452   typedef  DetectorElement<DeVeloSensorElement>  DeVeloSensor;
0453 
0454   
0455   /// Handle defintiion to an instance of VP IOV dependent data
0456   /**
0457    *  This object defines the behaviour of the objects's data
0458    *
0459    *  \author  Markus Frank
0460    *  \date    2018-03-08
0461    *  \version  1.0
0462    */
0463   class DeVeloRSensor : public DeVeloSensorElement   {
0464     enum { classID = 1008101  };
0465 
0466   public:
0467     /// Standard constructors and assignment
0468     DE_CTORS_HANDLE(DeVeloRSensor,DeVeloSensorElement);
0469   };
0470 
0471   
0472   /// Handle defintiion to an instance of VP IOV dependent data
0473   /**
0474    *  This object defines the behaviour of the objects's data
0475    *
0476    *  \author  Markus Frank
0477    *  \date    2018-03-08
0478    *  \version  1.0
0479    */
0480   class DeVeloPhiSensor : public DeVeloSensorElement   {
0481     enum { classID = 1008101  };
0482 
0483   public:
0484     /// Standard constructors and assignment
0485     DE_CTORS_HANDLE(DeVeloPhiSensor,DeVeloSensorElement);
0486   };
0487   
0488 }      // End namespace gaudi
0489 #endif // DETECTOR_DEVELOSENSOR_H