CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/FastSimulation/CaloHitMakers/interface/EcalHitMaker.h

Go to the documentation of this file.
00001 #ifndef FastSimulation_CaloHitMakers_EcalHitMaker_h
00002 #define FastSimulation_CaloHitMakers_EcalHitMaker_h
00003 
00004 #include "Geometry/CaloTopology/interface/CaloDirection.h"
00005 
00006 //#include "FastSimulation/Event/interface/FSimTrack.h"
00007 #include "FastSimulation/CaloHitMakers/interface/CaloHitMaker.h"
00008 #include "FastSimulation/CaloGeometryTools/interface/CaloPoint.h"
00009 #include "FastSimulation/CaloGeometryTools/interface/CaloSegment.h"
00010 #include "FastSimulation/CaloGeometryTools/interface/CrystalPad.h"
00011 #include "FastSimulation/CaloGeometryTools/interface/Crystal.h"
00012 #include "FastSimulation/Utilities/interface/FamosDebug.h"
00013 
00014 //#include <boost/cstdint.hpp>
00015 
00016 #include <vector>
00017 
00018 class CaloGeometryHelper;
00019 class CrystalWindowMap;
00020 class Histos;
00021 class RandomEngine;
00022 class FSimTrack;
00023 
00024 class EcalHitMaker: public CaloHitMaker
00025 {
00026  public:
00027 
00028   typedef math::XYZVector XYZVector;
00029   typedef math::XYZVector XYZPoint;
00030   typedef math::XYZVector XYZNormal;
00031   typedef ROOT::Math::Plane3D Plane3D;
00032 
00033   EcalHitMaker(CaloGeometryHelper * calo,
00034                const XYZPoint& ecalentrance,
00035                const DetId& cell,
00036                int onEcal,
00037                unsigned size,
00038                unsigned showertype,
00039                const RandomEngine* engine);
00040 
00041   ~EcalHitMaker();
00042 
00043   // This is not part of the constructor but it has to be called very early
00044   void setTrackParameters(const XYZNormal& normal,
00045                           double X0depthoffset,
00046                           const FSimTrack& theTrack);
00047   
00048   // The following methods are related to the path of the particle
00049   // through the detector. 
00050 
00051   // Number of X0 "seen" by the track 
00052     //  inline double totalX0() const {return totalX0_-X0depthoffset_;}; 
00053   inline double totalX0() const {return totalX0_;}; 
00054 
00056   inline double totalL0() const {return totalL0_;}; 
00057 
00059   inline double x0DepthOffset() const {return X0depthoffset_;}
00060 
00061   // total number of X0 in the PS (Layer1). 
00062   inline double ps1TotalX0() const {return X0PS1_;}
00063   
00065   inline double ps2TotalX0() const {return X0PS2_;}
00066 
00067   // number of X0 between PS2 and EE
00068   inline double ps2eeTotalX0() const {return X0PS2EE_;}
00069   
00071   inline double ecalTotalX0() const {return X0ECAL_;}
00072 
00074   inline double ecalHcalGapTotalX0() const {  return X0EHGAP_;}
00075 
00077   inline double hcalTotalX0() const {return X0HCAL_;}
00078 
00080   inline double ps1TotalL0() const {return L0PS1_;}
00081   
00083   inline double ps2TotalL0() const {return L0PS2_;}
00084 
00085   // number of X0 between PS2 and EE
00086   inline double ps2eeTotalL0() const {return L0PS2EE_;}
00087   
00089   inline double ecalTotalL0() const {return L0ECAL_;}
00090 
00092   inline double hcalTotalL0() const {return L0HCAL_;}
00093 
00095   inline double ecalHcalGapTotalL0() const {  return L0EHGAP_;}
00096 
00099   inline const std::vector<CaloSegment>& getSegments() const {return segments_;};
00100 
00101 
00102   // The following methods are EM showers specific
00103   
00107   bool getPads(double depth,bool inCm=false) ;
00108 
00109   inline double getX0back() const {return maxX0_;}
00110 
00111   bool addHitDepth(double r,double phi,double depth=-1);
00112    
00113   bool addHit(double r,double phi,unsigned layer=0) ;
00114 
00115   unsigned fastInsideCell(const CLHEP::Hep2Vector & point,double & sp,bool debug=false) ;
00116 
00117   inline void setSpotEnergy(double e) { spotEnergy=e;}
00118   
00121     
00122   const std::map<uint32_t,float>& getHits() ;
00123  
00125   const FSimTrack* getFSimTrack() const {return myTrack_;}
00126 
00128   inline const XYZPoint& ecalEntrance() const {return EcalEntrance_;};
00129 
00130   inline void setRadiusFactor(double r) {radiusCorrectionFactor_ = r;}
00131 
00132   inline void setPulledPadSurvivalProbability(double val) {pulledPadProbability_ = val;};
00133 
00134   inline void setCrackPadSurvivalProbability(double val ) {crackPadProbability_ = val ;};
00135 
00136  // set preshower
00137  inline void setPreshowerPresent(bool ps) {simulatePreshower_=ps;};
00138 
00140   inline const std::vector<Crystal>& getCrystals() const {return regionOfInterest_;}
00141 
00142 
00143 
00144  private:
00145 
00146 
00147 
00148  // Computes the intersections of a track with the different calorimeters 
00149  void cellLine(std::vector<CaloPoint>& cp) ;
00150 
00151  void preshowerCellLine(std::vector<CaloPoint>& cp) const;
00152 
00153  void hcalCellLine(std::vector<CaloPoint>& cp) const;
00154 
00155  void ecalCellLine(const XYZPoint&, const XYZPoint&,std::vector<CaloPoint>& cp); 
00156 
00157  void buildSegments(const std::vector<CaloPoint>& cp);
00158 
00159  // retrieves the 7x7 crystals and builds the map of neighbours
00160  void buildGeometry();
00161 
00162  // depth-dependent geometry operations
00163  void configureGeometry();
00164 
00165  // project fPoint on the plane (origin,normal)
00166  bool pulled(const XYZPoint & origin, const XYZNormal& normal, XYZPoint & fPoint) const ;
00167  
00168  //  the numbering within the grid
00169  void prepareCrystalNumberArray();
00170 
00171  // find approximately the pad corresponding to (x,y)
00172  void convertIntegerCoordinates(double x, double y,unsigned &ix,unsigned &iy) const ;
00173 
00174  // pads reorganization (to lift the gaps)
00175  void reorganizePads();
00176 
00177  // retrieves the coordinates of a corner belonging to the neighbour
00178  typedef std::pair<CaloDirection,unsigned > neighbour;
00179  CLHEP::Hep2Vector & correspondingEdge(neighbour& myneighbour,CaloDirection dir2 ) ;
00180 
00181  // almost the same
00182  bool diagonalEdge(unsigned myPad, CaloDirection dir,CLHEP::Hep2Vector & point);
00183 
00184  // check if there is an unbalanced direction in the input vertor. If the result is true, 
00185  // the cooresponding directions are returned dir1+dir2=unb
00186  bool unbalancedDirection(const std::vector<neighbour>& dirs,unsigned & unb,unsigned & dir1, unsigned & dir2);
00187 
00188  // glue the pads together if there is no crack between them 
00189  void gapsLifting(std::vector<neighbour>& gaps,unsigned iq);
00190 
00191  // creates a crack
00192  void cracksPads(std::vector<neighbour> & cracks, unsigned iq);
00193 
00194 
00195  private:
00196 
00197  bool inside3D(const std::vector<XYZPoint>&, const XYZPoint& p) const;
00198 
00199   // the numbering of the pads
00200   std::vector<std::vector<unsigned > > myCrystalNumberArray_;
00201 
00202   // The following quantities are related to the path of the track through the detector
00203   double totalX0_;
00204   double totalL0_;
00205   double X0depthoffset_;
00206   double X0PS1_;
00207   double X0PS2_;
00208   double X0PS2EE_;
00209   double X0ECAL_;
00210   double X0EHGAP_;
00211   double X0HCAL_;
00212   double L0PS1_;
00213   double L0PS2_;
00214   double L0PS2EE_;
00215   double L0ECAL_;
00216   double L0HCAL_;
00217   double L0EHGAP_;
00218  
00219   double maxX0_;
00220   double rearleakage_ ;
00221   double outsideWindowEnergy_;
00222 
00223   // Grid construction 
00224   Crystal pivot_;
00225   XYZPoint EcalEntrance_;
00226   XYZNormal normal_;
00227   int central_;
00228   int onEcal_;
00229 
00230   bool configuredGeometry_ ;
00231   unsigned ncrystals_ ;
00232   // size of the grid in the(x,y) plane
00233   unsigned nx_,ny_;
00234   double xmin_,xmax_,ymin_,ymax_;
00235 
00236   std::vector<DetId> CellsWindow_;
00237   std::vector<Crystal> regionOfInterest_;
00238   std::vector<float> hits_;
00239   // Validity of the pads. To be valid, the intersection of the crytal with the plane should have 4 corners
00240   std::vector<bool> validPads_;
00241   // Get the index of the crystal (in hits_ or regionOfInterest_) when its CellID is known 
00242   // Needed because the navigation uses DetIds. 
00243   std::map<DetId,unsigned> DetIdMap_;
00244 
00245   CrystalWindowMap * myCrystalWindowMap_;
00246 
00247    // First segment in ECAL
00248   int ecalFirstSegment_;
00249 
00250   // Properties of the crystal window 
00251   unsigned etasize_;
00252   unsigned phisize_;
00253   // is the grid complete ? 
00254   bool truncatedGrid_ ;
00255 
00256 
00257   // shower simulation quantities
00258   // This one is the shower enlargment wrt Grindhammer
00259   double radiusCorrectionFactor_;
00260   // moliere radius  * radiuscorrectionfactor OR interactionlength
00261   double radiusFactor_ ; 
00262   // is it necessary to trigger the detailed simulation of the shower tail ? 
00263   bool detailedShowerTail_;
00264   // current depth
00265   double currentdepth_;
00266   // magnetic field correction factor
00267   double bfactor_;
00268   // simulate preshower
00269   bool simulatePreshower_;
00270   
00271   // pads-depth specific quantities 
00272   unsigned ncrackpadsatdepth_;
00273   unsigned npadsatdepth_;
00274   Plane3D plan_;
00275   // spot survival probability for a pulled pad - corresponding to the front face of a crystal
00276   // on the plan located in front of the crystal - Front leaking
00277   double pulledPadProbability_;
00278   // spot survival probability for the craks
00279   double crackPadProbability_;
00280   // size of the grid in the plane
00281   double sizex_,sizey_;  
00282 
00283  //  int fsimtrack_;
00284   const FSimTrack* myTrack_;
00285   
00286   // vector of the intersection of the track with the dectectors (PS,ECAL,HCAL)
00287   std::vector<CaloPoint> intersections_;
00288   // segments obtained from the intersections
00289   std::vector<CaloSegment> segments_;
00290   // should the pads be reorganized (most of the time YES! )
00291   bool doreorg_;
00292 
00293   // the geometrical objects
00294   std::vector<CrystalPad> padsatdepth_;
00295   std::vector<CrystalPad> crackpadsatdepth_;
00296 
00297   bool hitmaphasbeencalculated_ ;
00298 
00299   // A local vector of corners, to avoid reserving, newing and mallocing
00300   std::vector<CLHEP::Hep2Vector> mycorners;
00301   std::vector<XYZPoint> corners;
00302 
00303 
00304   const RandomEngine* random;
00305 
00306 
00307 #ifdef FAMOSDEBUG
00308   Histos * myHistos;
00309 #endif
00310 
00311   
00312 };
00313 
00314 #endif