Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-26 03:37:03

0001 #ifndef CSCSegment_CSCSegAlgoRU_h
0002 #define CSCSegment_CSCSegAlgoRU_h
0003 
0004 /**
0005  * \class CSCSegAlgoRU
0006  *
0007  * This is the original algorithm for building endcap muon track segments
0008  * out of the rechit's in a CSCChamber
0009  * 'RU' = 'RUssia' = Road Usage
0010  *
0011  * A CSCSegment is a RecSegment4D, and is built from
0012  * CSCRecHit2D objects, each of which is a RecHit2DLocalPos. <BR>
0013  *
0014  * This class is used by the CSCSegmentAlgorithm. <BR>
0015  * Alternative algorithms can be used for the segment building
0016  * by writing classes like this, and then selecting which one is actually
0017  * used via the CSCSegmentBuilder. <BR>
0018  *
0019  * developed and implemented by Vladimir Palichik <Vladimir.Paltchik@cern.ch>
0020  *                          and Nikolay Voytishin <nikolay.voytishin@cern.ch>
0021  */
0022 
0023 #include <RecoLocalMuon/CSCSegment/src/CSCSegmentAlgorithm.h>
0024 #include <DataFormats/CSCRecHit/interface/CSCRecHit2D.h>
0025 #include "CSCSegFit.h"
0026 
0027 #include <Math/Functions.h>
0028 #include <Math/SVector.h>
0029 #include <Math/SMatrix.h>
0030 
0031 #include <vector>
0032 
0033 class CSCSegFit;
0034 
0035 class CSCSegAlgoRU : public CSCSegmentAlgorithm {
0036 public:
0037   // Tim tried using map as basic container of all (space-point) RecHit's in a chamber:
0038   // The 'key' is a pseudo-layer number (1-6 but with 1 always closest to IP).
0039   // The 'value' is a vector of the RecHit's on that layer.
0040   // Using the layer number like this removes the need to sort in global z.
0041   // Instead we just have to ensure the layer index is correctly adjusted
0042   // to enforce the requirement that 'layer 1' is closest in the chamber
0043   // to the IP.
0044 
0045   /// Typedefs
0046 
0047   // 4-dim vector
0048   typedef ROOT::Math::SVector<double, 6> SVector6;
0049 
0050   typedef std::vector<int> LayerIndex;
0051   typedef std::vector<const CSCRecHit2D*> ChamberHitContainer;
0052   typedef std::vector<const CSCRecHit2D*>::const_iterator ChamberHitContainerCIt;
0053 
0054   // We need to be able to flag a hit as 'used' and so need a container
0055   // of bool's. Naively, this would be vector<bool>... but AVOID that since it's
0056   // non-standard i.e. packed-bit implementation which is not a standard STL container.
0057   // We don't need what it offers and it could lead to unexpected trouble in the future.
0058 
0059   typedef std::vector<bool> BoolContainer;
0060 
0061   /// Constructor
0062   explicit CSCSegAlgoRU(const edm::ParameterSet& ps);
0063   /// Destructor
0064   ~CSCSegAlgoRU() override{};
0065 
0066   /**
0067      * Build track segments in this chamber (this is where the actual
0068      * segment-building algorithm hides.)
0069      */
0070   std::vector<CSCSegment> buildSegments(const CSCChamber* aChamber, const ChamberHitContainer& rechits) const;
0071 
0072   //    std::vector<CSCSegment> assambleRechitsInSegments(const ChamberHitContainer& rechits, int iadd, BoolContainer& used, BoolContainer& used3p, int *recHits_per_layer, const LayerIndex& layerIndex, std::vector<CSCSegment> segments);
0073 
0074   /**
0075      * Here we must implement the algorithm
0076      */
0077   std::vector<CSCSegment> run(const CSCChamber* aChamber, const ChamberHitContainer& rechits) override {
0078     return buildSegments(aChamber, rechits);
0079   }
0080 
0081 private:
0082   struct AlgoState {
0083     const CSCChamber* aChamber = nullptr;
0084     float windowScale = 0;
0085     int strip_iadd = 0;
0086     int chi2D_iadd = 0;
0087     std::unique_ptr<CSCSegFit> sfit = nullptr;
0088     ChamberHitContainer proto_segment;
0089 
0090     //adjustable configuration
0091     bool doCollisions;
0092     float dRMax;
0093     float dPhiMax;
0094     float dRIntMax;
0095     float dPhiIntMax;
0096     float chi2Max;
0097     float chi2_str_;
0098     float chi2Norm_2D_;
0099   };
0100   /// Utility functions
0101   // Could be static at the moment, but in principle one
0102   // might like CSCSegmentizer-specific behaviour?
0103   bool areHitsCloseInR(const AlgoState& aState, const CSCRecHit2D* h1, const CSCRecHit2D* h2) const;
0104   bool areHitsCloseInGlobalPhi(const AlgoState& aState, const CSCRecHit2D* h1, const CSCRecHit2D* h2) const;
0105   bool isHitNearSegment(const AlgoState& aState, const CSCRecHit2D* h) const;
0106 
0107   /**
0108      * Try adding non-used hits to segment
0109      */
0110   void tryAddingHitsToSegment(AlgoState& aState,
0111                               const ChamberHitContainer& rechitsInChamber,
0112                               const BoolContainer& used,
0113                               const LayerIndex& layerIndex,
0114                               const ChamberHitContainerCIt i1,
0115                               const ChamberHitContainerCIt i2) const;
0116 
0117   /**
0118      * Return true if segment is 'good'.
0119      * In this algorithm, 'good' means has sufficient hits
0120      */
0121   bool isSegmentGood(const AlgoState& aState, const ChamberHitContainer& rechitsInChamber) const;
0122 
0123   /**
0124      * Flag hits on segment as used
0125      */
0126   void flagHitsAsUsed(const AlgoState& aState, const ChamberHitContainer& rechitsInChamber, BoolContainer& used) const;
0127 
0128   /// Utility functions
0129   bool addHit(AlgoState& aState, const CSCRecHit2D* hit, int layer) const;
0130   void updateParameters(AlgoState& aState) const;
0131   float fit_r_phi(const AlgoState& aState, const SVector6& points, int layer) const;
0132   float fitX(const AlgoState& aState, SVector6 points, SVector6 errors, int ir, int ir2, float& chi2_str) const;
0133   void baseline(AlgoState& aState, int n_seg_min) const;  //function for arasing bad hits in case of bad chi2/NDOF
0134                                                           /**
0135      * Always enforce direction of segment to point from IP outwards
0136      * (Incorrect for particles not coming from IP, of course.)
0137      */
0138   float phiAtZ(const AlgoState& aState, float z) const;
0139   bool hasHitOnLayer(const AlgoState& aState, int layer) const;
0140   bool replaceHit(AlgoState& aState, const CSCRecHit2D* h, int layer) const;
0141   void compareProtoSegment(AlgoState& aState, const CSCRecHit2D* h, int layer) const;
0142   void increaseProtoSegment(AlgoState& aState, const CSCRecHit2D* h, int layer, int chi2_factor) const;
0143 
0144   // Member variables
0145   // ================
0146 
0147   const std::string myName;
0148 
0149   double theChi2;
0150   LocalPoint theOrigin;
0151   LocalVector theDirection;
0152   float uz, vz;
0153   bool doCollisions;
0154   float dRMax;
0155   float dPhiMax;
0156   float dRIntMax;
0157   float dPhiIntMax;
0158   float chi2Max;
0159   float chi2_str_;
0160   float chi2Norm_2D_;
0161   float wideSeg;
0162   int minLayersApart;
0163   bool debugInfo;
0164 };
0165 
0166 #endif