Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-03-12 06:21:57

0001 #ifndef RecoVertex_PrimaryVertexProducer_DAClusterizerInZT_vect_h
0002 #define RecoVertex_PrimaryVertexProducer_DAClusterizerInZT_vect_h
0003 
0004 /**\class DAClusterizerInZT_vect
0005 
0006  Description: separates event tracks into clusters along the beam line
0007 
0008     Version which auto-vectorizes with gcc 4.6 or newer
0009 
0010  */
0011 
0012 #include "RecoVertex/PrimaryVertexProducer/interface/TrackClusterizerInZ.h"
0013 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
0014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0015 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0016 #include <vector>
0017 #include "DataFormats/Math/interface/Error.h"
0018 #include "RecoVertex/VertexTools/interface/VertexDistanceXY.h"
0019 #include "RecoVertex/VertexPrimitives/interface/TransientVertex.h"
0020 
0021 #include <memory>
0022 
0023 //#define USEVTXDT2
0024 
0025 class DAClusterizerInZT_vect final : public TrackClusterizerInZ {
0026 public:
0027   // internal data structure for tracks
0028   struct track_t {
0029     std::vector<double> zpca_vec;                  // z-coordinate at point of closest approach to the beamline
0030     std::vector<double> tpca_vec;                  // t-coordinate at point of closest approach to the beamline
0031     std::vector<double> dz2_vec;                   // square of the error of z(pca)
0032     std::vector<double> dt2_vec;                   // square of the error of t(pca)
0033     std::vector<double> sum_Z_vec;                 // track contribution to the partition function, Z
0034     std::vector<double> tkwt_vec;                  // track weight, close to 1.0 for most tracks
0035     std::vector<unsigned int> kmin;                // index of the first cluster within zrange
0036     std::vector<unsigned int> kmax;                // 1 + index of the last cluster within zrange
0037     std::vector<const reco::TransientTrack *> tt;  // a pointer to the Transient Track
0038 
0039     double osumtkwt;  // 1. / (sum of all track weights)
0040 
0041     void addItem(double new_zpca,
0042                  double new_tpca,
0043                  double new_dz2,
0044                  double new_dt2,
0045                  const reco::TransientTrack *new_tt,
0046                  double new_tkwt) {
0047       zpca_vec.push_back(new_zpca);
0048       tpca_vec.push_back(new_tpca);
0049       dz2_vec.push_back(new_dz2);
0050       dt2_vec.push_back(new_dt2);
0051       tt.push_back(new_tt);
0052       tkwt_vec.push_back(new_tkwt);
0053       sum_Z_vec.push_back(1.0);
0054       kmin.push_back(0);
0055       kmax.push_back(0);
0056     }
0057 
0058     void insertItem(unsigned int i,
0059                     double new_zpca,
0060                     double new_tpca,
0061                     double new_dz2,
0062                     double new_dt2,
0063                     const reco::TransientTrack *new_tt,
0064                     double new_tkwt) {
0065       zpca_vec.insert(zpca_vec.begin() + i, new_zpca);
0066       tpca_vec.insert(tpca_vec.begin() + i, new_tpca);
0067       dz2_vec.insert(dz2_vec.begin() + i, new_dz2);
0068       dt2_vec.insert(dt2_vec.begin() + i, new_dt2);
0069       tt.insert(tt.begin() + i, new_tt);
0070       tkwt_vec.insert(tkwt_vec.begin() + i, new_tkwt);
0071       sum_Z_vec.insert(sum_Z_vec.begin() + i, 1.0);
0072       kmin.insert(kmin.begin() + i, 0);
0073       kmax.insert(kmax.begin() + i, 0);
0074     }
0075 
0076     unsigned int getSize() const { return zpca_vec.size(); }
0077 
0078     // has to be called everytime the items are modified
0079     void extractRaw() {
0080       zpca = &zpca_vec.front();
0081       tpca = &tpca_vec.front();
0082       dz2 = &dz2_vec.front();
0083       dt2 = &dt2_vec.front();
0084       tkwt = &tkwt_vec.front();
0085       sum_Z = &sum_Z_vec.front();
0086     }
0087 
0088     // pointers to the first element of vectors, needed for vectorized code
0089     double *__restrict__ zpca;
0090     double *__restrict__ tpca;
0091     double *__restrict__ dz2;
0092     double *__restrict__ dt2;
0093     double *__restrict__ tkwt;
0094     double *__restrict__ sum_Z;
0095   };
0096 
0097   // internal data structure for clusters
0098   struct vertex_t {
0099     std::vector<double> zvtx_vec;  // z coordinate
0100     std::vector<double> tvtx_vec;  // t coordinate
0101     std::vector<double> rho_vec;   //  vertex "mass" for mass-constrained clustering
0102 #ifdef USEVTXDT2
0103     std::vector<double> dt2_vec;   // only used with vertex time uncertainties
0104     std::vector<double> sumw_vec;  // only used with vertex time uncertainties
0105 #endif
0106     // --- temporary numbers, used during update
0107     std::vector<double> exp_arg_vec;
0108     std::vector<double> exp_vec;
0109     std::vector<double> sw_vec;
0110     std::vector<double> swz_vec;
0111     std::vector<double> swt_vec;
0112     std::vector<double> se_vec;
0113     std::vector<double> nuz_vec;
0114     std::vector<double> nut_vec;
0115     std::vector<double> szz_vec;
0116     std::vector<double> stt_vec;
0117     std::vector<double> szt_vec;
0118 
0119     unsigned int getSize() const { return zvtx_vec.size(); }
0120 
0121     void addItem(double new_zvtx, double new_tvtx, double new_rho) {
0122       zvtx_vec.push_back(new_zvtx);
0123       tvtx_vec.push_back(new_tvtx);
0124       rho_vec.push_back(new_rho);
0125       exp_arg_vec.push_back(0.0);
0126       exp_vec.push_back(0.0);
0127       swz_vec.push_back(0.0);
0128       swt_vec.push_back(0.0);
0129       se_vec.push_back(0.0);
0130       nuz_vec.push_back(0.0);
0131       nut_vec.push_back(0.0);
0132       szz_vec.push_back(0.0);
0133       stt_vec.push_back(0.0);
0134       szt_vec.push_back(0.0);
0135 #ifdef USEVTXDT2
0136       dt2_vec.push_back(0.0);
0137       sumw_vec.push_back(0.0);
0138 #endif
0139 
0140       extractRaw();
0141     }
0142 
0143     void insertItem(unsigned int k, double new_zvtx, double new_tvtx, double new_rho, track_t &tks) {
0144       zvtx_vec.insert(zvtx_vec.begin() + k, new_zvtx);
0145       tvtx_vec.insert(tvtx_vec.begin() + k, new_tvtx);
0146       rho_vec.insert(rho_vec.begin() + k, new_rho);
0147       exp_arg_vec.insert(exp_arg_vec.begin() + k, 0.0);
0148       exp_vec.insert(exp_vec.begin() + k, 0.0);
0149       swz_vec.insert(swz_vec.begin() + k, 0.0);
0150       swt_vec.insert(swt_vec.begin() + k, 0.0);
0151       se_vec.insert(se_vec.begin() + k, 0.0);
0152       nuz_vec.insert(nuz_vec.begin() + k, 0.0);
0153       nut_vec.insert(nut_vec.begin() + k, 0.0);
0154       szz_vec.insert(szz_vec.begin() + k, 0.0);
0155       stt_vec.insert(stt_vec.begin() + k, 0.0);
0156       szt_vec.insert(szt_vec.begin() + k, 0.0);
0157 #ifdef USEVTXDT2
0158       dt2_vec.insert(dt2_vec.begin() + k, 0.0);
0159       sumw_vec.insert(sumw_vec.begin() + k, 0.0);
0160 #endif
0161 
0162       // adjust vertex lists of tracks
0163       for (unsigned int i = 0; i < tks.getSize(); i++) {
0164         if (tks.kmin[i] > k) {
0165           tks.kmin[i]++;
0166         }
0167         if ((tks.kmax[i] >= k) || (tks.kmax[i] == tks.kmin[i])) {
0168           tks.kmax[i]++;
0169         }
0170       }
0171 
0172       extractRaw();
0173     }
0174 
0175     void removeItem(unsigned int k, track_t &tks) {
0176       zvtx_vec.erase(zvtx_vec.begin() + k);
0177       tvtx_vec.erase(tvtx_vec.begin() + k);
0178       rho_vec.erase(rho_vec.begin() + k);
0179       exp_arg_vec.erase(exp_arg_vec.begin() + k);
0180       exp_vec.erase(exp_vec.begin() + k);
0181       swz_vec.erase(swz_vec.begin() + k);
0182       swt_vec.erase(swt_vec.begin() + k);
0183       se_vec.erase(se_vec.begin() + k);
0184       nuz_vec.erase(nuz_vec.begin() + k);
0185       nut_vec.erase(nut_vec.begin() + k);
0186       szz_vec.erase(szz_vec.begin() + k);
0187       stt_vec.erase(stt_vec.begin() + k);
0188       szt_vec.erase(szt_vec.begin() + k);
0189 #ifdef USEVTXDT2
0190       dt2_vec.erase(dt2_vec.begin() + k);
0191       sumw_vec.erase(sumw_vec.begin() + k);
0192 #endif
0193 
0194       // adjust vertex lists of tracks
0195       for (unsigned int i = 0; i < tks.getSize(); i++) {
0196         if (tks.kmax[i] > k) {
0197           tks.kmax[i]--;
0198         }
0199         if ((tks.kmin[i] > k) || (((tks.kmax[i] < (tks.kmin[i] + 1)) && (tks.kmin[i] > 0)))) {
0200           tks.kmin[i]--;
0201         }
0202       }
0203 
0204       extractRaw();
0205     }
0206 
0207     unsigned int insertOrdered(double zvtx, double tvtx, double rho, track_t &tks) {
0208       // insert a new cluster according to it's z-position, return the index at which it was inserted
0209 
0210       unsigned int k = 0;
0211       for (; k < getSize(); k++) {
0212         if (zvtx < zvtx_vec[k])
0213           break;
0214       }
0215       insertItem(k, zvtx, tvtx, rho, tks);
0216       return k;
0217     }
0218 
0219     // pointers to the first element of vectors, needed for vectorized code
0220     double *__restrict__ zvtx;
0221     double *__restrict__ tvtx;
0222     double *__restrict__ rho;
0223     double *__restrict__ exp_arg;
0224     double *__restrict__ exp;
0225     double *__restrict__ swt;
0226     double *__restrict__ swz;
0227     double *__restrict__ se;
0228     double *__restrict__ nuz;
0229     double *__restrict__ nut;
0230     double *__restrict__ szz;
0231     double *__restrict__ stt;
0232     double *__restrict__ szt;
0233 #ifdef USEVTXDT2
0234     double *__restrict__ dt2;
0235     double *__restrict__ sumw;
0236 #endif
0237 
0238     // has to be called everytime the items are modified
0239     void extractRaw() {
0240       zvtx = &zvtx_vec.front();
0241       tvtx = &tvtx_vec.front();
0242       rho = &rho_vec.front();
0243       exp_arg = &exp_arg_vec.front();
0244       exp = &exp_vec.front();
0245       swz = &swz_vec.front();
0246       swt = &swt_vec.front();
0247       se = &se_vec.front();
0248       nuz = &nuz_vec.front();
0249       nut = &nut_vec.front();
0250       szz = &szz_vec.front();
0251       stt = &stt_vec.front();
0252       szt = &szt_vec.front();
0253 #ifdef USEVTXDT2
0254       dt2 = &dt2_vec.front();
0255       sumw = &sumw_vec.front();
0256 #endif
0257     }
0258   };
0259 
0260   DAClusterizerInZT_vect(const edm::ParameterSet &conf);
0261 
0262   static void fillPSetDescription(edm::ParameterSetDescription &desc);
0263 
0264   std::vector<std::vector<reco::TransientTrack> > clusterize(
0265       const std::vector<reco::TransientTrack> &tracks) const override;
0266 
0267   std::vector<TransientVertex> vertices(const std::vector<reco::TransientTrack> &tracks) const;
0268 
0269   track_t fill(const std::vector<reco::TransientTrack> &tracks) const;
0270 
0271   void set_vtx_range(double beta, track_t &gtracks, vertex_t &gvertices) const;
0272 
0273   void clear_vtx_range(track_t &gtracks, vertex_t &gvertices) const;
0274 
0275   unsigned int thermalize(
0276       double beta, track_t &gtracks, vertex_t &gvertices, const double delta_max, const double rho0 = 0.) const;
0277 
0278   double update(
0279       double beta, track_t &gtracks, vertex_t &gvertices, const double rho0 = 0, const bool updateTc = false) const;
0280 
0281   void dump(const double beta, const vertex_t &y, const track_t &tks, const int verbosity = 0) const;
0282   bool zorder(vertex_t &y) const;
0283   bool find_nearest(double z, double t, vertex_t &y, unsigned int &k_min, double dz, double dt) const;
0284   bool merge(vertex_t &, track_t &, double &beta) const;
0285   bool purge(vertex_t &, track_t &, double &, const double) const;
0286   bool split(const double beta, track_t &t, vertex_t &y, double threshold = 1.) const;
0287 
0288   double beta0(const double betamax, track_t const &tks, vertex_t const &y) const;
0289 
0290   double get_Tc(const vertex_t &y, int k) const;
0291   void verify(const vertex_t &v, const track_t &tks, unsigned int nv = 999999, unsigned int nt = 999999) const;
0292 
0293 private:
0294   double zdumpcenter_;
0295   double zdumpwidth_;
0296 
0297   double vertexSize_;
0298   double vertexSizeTime_;
0299   unsigned int maxIterations_;
0300   double coolingFactor_;
0301   double betamax_;
0302   double betastop_;
0303   double dzCutOff_;
0304   double d0CutOff_;
0305   double dtCutOff_;
0306   double t0Max_;
0307 
0308   double mintrkweight_;
0309   double uniquetrkweight_;
0310   double uniquetrkminp_;
0311   double zmerge_;
0312   double tmerge_;
0313   double betapurge_;
0314 
0315   unsigned int convergence_mode_;
0316   double delta_highT_;
0317   double delta_lowT_;
0318 
0319   double sel_zrange_;
0320   const double zrange_min_ = 0.1;  // smallest z-range to be included in a tracks cluster list
0321 };
0322 
0323 //#ifndef DAClusterizerInZT_vect_h
0324 #endif