Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:12

0001 #ifndef FastSimulation_CaloHitMakers_EcalHitMaker_h
0002 #define FastSimulation_CaloHitMakers_EcalHitMaker_h
0003 
0004 #include "Geometry/CaloTopology/interface/CaloDirection.h"
0005 
0006 //#include "FastSimulation/Event/interface/FSimTrack.h"
0007 #include "FastSimulation/CaloHitMakers/interface/CaloHitMaker.h"
0008 #include "FastSimulation/CaloGeometryTools/interface/CaloPoint.h"
0009 #include "FastSimulation/CaloGeometryTools/interface/CaloSegment.h"
0010 #include "FastSimulation/CaloGeometryTools/interface/CrystalPad.h"
0011 #include "FastSimulation/CaloGeometryTools/interface/Crystal.h"
0012 #include "FastSimulation/Utilities/interface/FamosDebug.h"
0013 
0014 //#include <boost/cstdint.hpp>
0015 
0016 #include <vector>
0017 
0018 class CaloGeometryHelper;
0019 class CrystalWindowMap;
0020 class Histos;
0021 class RandomEngineAndDistribution;
0022 class FSimTrack;
0023 
0024 class EcalHitMaker : public CaloHitMaker {
0025 public:
0026   typedef math::XYZVector XYZVector;
0027   typedef math::XYZVector XYZPoint;
0028   typedef math::XYZVector XYZNormal;
0029   typedef ROOT::Math::Plane3D Plane3D;
0030 
0031   EcalHitMaker(CaloGeometryHelper* calo,
0032                const XYZPoint& ecalentrance,
0033                const DetId& cell,
0034                int onEcal,
0035                unsigned size,
0036                unsigned showertype,
0037                const RandomEngineAndDistribution* engine);
0038 
0039   ~EcalHitMaker() override;
0040 
0041   // This is not part of the constructor but it has to be called very early
0042   void setTrackParameters(const XYZNormal& normal, double X0depthoffset, const FSimTrack& theTrack);
0043 
0044   // The following methods are related to the path of the particle
0045   // through the detector.
0046 
0047   // Number of X0 "seen" by the track
0048   //  inline double totalX0() const {return totalX0_-X0depthoffset_;};
0049   inline double totalX0() const { return totalX0_; };
0050 
0051   /// Number of interaction length "seen" by the track
0052   inline double totalL0() const { return totalL0_; };
0053 
0054   /// get the offset (e.g the number of X0 after which the shower starts)
0055   inline double x0DepthOffset() const { return X0depthoffset_; }
0056 
0057   // total number of X0 in the PS (Layer1).
0058   inline double ps1TotalX0() const { return X0PS1_; }
0059 
0060   /// total number of X0 in the PS (Layer2).
0061   inline double ps2TotalX0() const { return X0PS2_; }
0062 
0063   // number of X0 between PS2 and EE
0064   inline double ps2eeTotalX0() const { return X0PS2EE_; }
0065 
0066   /// in the ECAL
0067   inline double ecalTotalX0() const { return X0ECAL_; }
0068 
0069   /// ECAL-HCAL transition
0070   inline double ecalHcalGapTotalX0() const { return X0EHGAP_; }
0071 
0072   /// in the HCAL
0073   inline double hcalTotalX0() const { return X0HCAL_; }
0074 
0075   /// total number of L0 in the PS (Layer1).
0076   inline double ps1TotalL0() const { return L0PS1_; }
0077 
0078   /// total number of L0 in the PS (Layer2).
0079   inline double ps2TotalL0() const { return L0PS2_; }
0080 
0081   // number of X0 between PS2 and EE
0082   inline double ps2eeTotalL0() const { return L0PS2EE_; }
0083 
0084   /// in the ECAL
0085   inline double ecalTotalL0() const { return L0ECAL_; }
0086 
0087   /// in the HCAL
0088   inline double hcalTotalL0() const { return L0HCAL_; }
0089 
0090   /// ECAL-HCAL transition
0091   inline double ecalHcalGapTotalL0() const { return L0EHGAP_; }
0092 
0093   /// retrieve the segments (the path in the crystal crossed by the extrapolation
0094   /// of the track. Debugging only
0095   inline const std::vector<CaloSegment>& getSegments() const { return segments_; };
0096 
0097   // The following methods are EM showers specific
0098 
0099   /// computes the crystals-plan intersection at depth (in X0 or L0 depending on the
0100   ///shower type)
0101   /// if it is not possible to go at such a depth, the result is false
0102   bool getPads(double depth, bool inCm = false);
0103 
0104   inline double getX0back() const { return maxX0_; }
0105 
0106   bool addHitDepth(double r, double phi, double depth = -1);
0107 
0108   bool addHit(double r, double phi, unsigned layer = 0) override;
0109 
0110   unsigned fastInsideCell(const CLHEP::Hep2Vector& point, double& sp, bool debug = false);
0111 
0112   inline void setSpotEnergy(double e) override { spotEnergy = e; }
0113 
0114   /// get the map of the stored hits. Triggers the calculation of the grid if it has
0115   /// not been done.
0116 
0117   const std::map<CaloHitID, float>& getHits() override;
0118 
0119   /// To retrieve the track
0120   const FSimTrack* getFSimTrack() const { return myTrack_; }
0121 
0122   ///   used in FamosHcalHitMaker
0123   inline const XYZPoint& ecalEntrance() const { return EcalEntrance_; };
0124 
0125   inline void setRadiusFactor(double r) { radiusCorrectionFactor_ = r; }
0126 
0127   inline void setPulledPadSurvivalProbability(double val) { pulledPadProbability_ = val; };
0128 
0129   inline void setCrackPadSurvivalProbability(double val) { crackPadProbability_ = val; };
0130 
0131   // set preshower
0132   inline void setPreshowerPresent(bool ps) { simulatePreshower_ = ps; };
0133 
0134   /// for debugging
0135   inline const std::vector<Crystal>& getCrystals() const { return regionOfInterest_; }
0136 
0137 private:
0138   // Computes the intersections of a track with the different calorimeters
0139   void cellLine(std::vector<CaloPoint>& cp);
0140 
0141   void preshowerCellLine(std::vector<CaloPoint>& cp) const;
0142 
0143   void hcalCellLine(std::vector<CaloPoint>& cp) const;
0144 
0145   void ecalCellLine(const XYZPoint&, const XYZPoint&, std::vector<CaloPoint>& cp);
0146 
0147   void buildSegments(const std::vector<CaloPoint>& cp);
0148 
0149   // retrieves the 7x7 crystals and builds the map of neighbours
0150   void buildGeometry();
0151 
0152   // depth-dependent geometry operations
0153   void configureGeometry();
0154 
0155   // project fPoint on the plane (origin,normal)
0156   bool pulled(const XYZPoint& origin, const XYZNormal& normal, XYZPoint& fPoint) const;
0157 
0158   //  the numbering within the grid
0159   void prepareCrystalNumberArray();
0160 
0161   // find approximately the pad corresponding to (x,y)
0162   void convertIntegerCoordinates(double x, double y, unsigned& ix, unsigned& iy) const;
0163 
0164   // pads reorganization (to lift the gaps)
0165   void reorganizePads();
0166 
0167   // retrieves the coordinates of a corner belonging to the neighbour
0168   typedef std::pair<CaloDirection, unsigned> neighbour;
0169   CLHEP::Hep2Vector& correspondingEdge(neighbour& myneighbour, CaloDirection dir2);
0170 
0171   // almost the same
0172   bool diagonalEdge(unsigned myPad, CaloDirection dir, CLHEP::Hep2Vector& point);
0173 
0174   // check if there is an unbalanced direction in the input vertor. If the result is true,
0175   // the cooresponding directions are returned dir1+dir2=unb
0176   bool unbalancedDirection(const std::vector<neighbour>& dirs, unsigned& unb, unsigned& dir1, unsigned& dir2);
0177 
0178   // glue the pads together if there is no crack between them
0179   void gapsLifting(std::vector<neighbour>& gaps, unsigned iq);
0180 
0181   // creates a crack
0182   void cracksPads(std::vector<neighbour>& cracks, unsigned iq);
0183 
0184 private:
0185   bool inside3D(const std::vector<XYZPoint>&, const XYZPoint& p) const;
0186 
0187   // the numbering of the pads
0188   std::vector<std::vector<unsigned> > myCrystalNumberArray_;
0189 
0190   // The following quantities are related to the path of the track through the detector
0191   double totalX0_;
0192   double totalL0_;
0193   double X0depthoffset_;
0194   double X0PS1_;
0195   double X0PS2_;
0196   double X0PS2EE_;
0197   double X0ECAL_;
0198   double X0EHGAP_;
0199   double X0HCAL_;
0200   double L0PS1_;
0201   double L0PS2_;
0202   double L0PS2EE_;
0203   double L0ECAL_;
0204   double L0HCAL_;
0205   double L0EHGAP_;
0206 
0207   double maxX0_;
0208   double rearleakage_;
0209   double outsideWindowEnergy_;
0210 
0211   // Grid construction
0212   Crystal pivot_;
0213   XYZPoint EcalEntrance_;
0214   XYZNormal normal_;
0215   int central_;
0216   int onEcal_;
0217 
0218   bool configuredGeometry_;
0219   unsigned ncrystals_;
0220   // size of the grid in the(x,y) plane
0221   unsigned nx_, ny_;
0222   double xmin_, xmax_, ymin_, ymax_;
0223 
0224   std::vector<DetId> CellsWindow_;
0225   std::vector<Crystal> regionOfInterest_;
0226   std::vector<float> hits_;
0227   // Validity of the pads. To be valid, the intersection of the crytal with the plane should have 4 corners
0228   std::vector<bool> validPads_;
0229   // Get the index of the crystal (in hits_ or regionOfInterest_) when its CellID is known
0230   // Needed because the navigation uses DetIds.
0231   std::map<DetId, unsigned> DetIdMap_;
0232 
0233   CrystalWindowMap* myCrystalWindowMap_;
0234 
0235   // First segment in ECAL
0236   int ecalFirstSegment_;
0237 
0238   // Properties of the crystal window
0239   unsigned etasize_;
0240   unsigned phisize_;
0241   // is the grid complete ?
0242   bool truncatedGrid_;
0243 
0244   // shower simulation quantities
0245   // This one is the shower enlargment wrt Grindhammer
0246   double radiusCorrectionFactor_;
0247   // moliere radius  * radiuscorrectionfactor OR interactionlength
0248   double radiusFactor_;
0249   // is it necessary to trigger the detailed simulation of the shower tail ?
0250   bool detailedShowerTail_;
0251   // current depth
0252   double currentdepth_;
0253   // magnetic field correction factor
0254   double bfactor_;
0255   // simulate preshower
0256   bool simulatePreshower_;
0257 
0258   // pads-depth specific quantities
0259   unsigned ncrackpadsatdepth_;
0260   unsigned npadsatdepth_;
0261   Plane3D plan_;
0262   // spot survival probability for a pulled pad - corresponding to the front face of a crystal
0263   // on the plan located in front of the crystal - Front leaking
0264   double pulledPadProbability_;
0265   // spot survival probability for the craks
0266   double crackPadProbability_;
0267   // size of the grid in the plane
0268   double sizex_, sizey_;
0269 
0270   //  int fsimtrack_;
0271   const FSimTrack* myTrack_;
0272 
0273   // vector of the intersection of the track with the dectectors (PS,ECAL,HCAL)
0274   std::vector<CaloPoint> intersections_;
0275   // segments obtained from the intersections
0276   std::vector<CaloSegment> segments_;
0277   // should the pads be reorganized (most of the time YES! )
0278   bool doreorg_;
0279 
0280   // the geometrical objects
0281   std::vector<CrystalPad> padsatdepth_;
0282   std::vector<CrystalPad> crackpadsatdepth_;
0283 
0284   bool hitmaphasbeencalculated_;
0285 
0286   // A local vector of corners, to avoid reserving, newing and mallocing
0287   std::vector<CLHEP::Hep2Vector> mycorners;
0288   std::vector<XYZPoint> corners;
0289 
0290   const RandomEngineAndDistribution* random;
0291 
0292 #ifdef FAMOSDEBUG
0293   Histos* myHistos;
0294 #endif
0295 };
0296 
0297 #endif