From aa3fbdadcda3708f826c504883f04f8cec2ac008 Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Tue, 18 Oct 2016 15:43:04 -0700 Subject: [PATCH 001/172] FitTracksWithInterSlurp, SuckIn with N_proc. --- Matriplex/Matriplex.h | 42 ++++++++----- Matriplex/MatriplexSym.h | 35 ++++++++--- Track.h | 2 + mkFit/MkFitter.cc | 124 +++++++++++++++++++++++++++++++++------ mkFit/MkFitter.h | 4 ++ mkFit/fittestMPlex.cc | 22 ++++++- 6 files changed, 186 insertions(+), 43 deletions(-) diff --git a/Matriplex/Matriplex.h b/Matriplex/Matriplex.h index eb26e4ae64827..376d598f26c0b 100644 --- a/Matriplex/Matriplex.h +++ b/Matriplex/Matriplex.h @@ -66,16 +66,19 @@ class Matriplex #if defined(MIC_INTRINSICS) - void SlurpIn(const char *arr, __m512i& vi) + void SlurpIn(const char *arr, __m512i& vi, const int N_proc = N) { //_mm512_prefetch_i32gather_ps(vi, arr, 1, _MM_HINT_T0); + const __m512 src = { 0 }; + const __mmask16 k = N_proc == N ? -1 : (1 << N_proc) - 1; + for (int i = 0; i < kSize; ++i, arr += sizeof(T)) { //_mm512_prefetch_i32gather_ps(vi, arr+2, 1, _MM_HINT_NTA); - __m512 reg = _mm512_i32gather_ps(vi, arr, 1); - _mm512_store_ps(&fArray[i*N], reg); + __m512 reg = _mm512_mask_i32gather_ps(src, k, vi, arr, 1); + _mm512_mask_store_ps(&fArray[i*N], k, reg); } } @@ -122,19 +125,30 @@ class Matriplex #else - void SlurpIn(const char *arr, int vi[N]) + void SlurpIn(const char *arr, int vi[N], const int N_proc = N) { - for (int i = 0; i < kSize; ++i) + // Separate N_proc == N case (gains about 7% in fit test). + if (N_proc == N) { - // Next loop vectorizes with "#pragma ivdep", but it runs slower - // #pragma ivdep - for (int j = 0; j < N; ++j) - { - fArray[i*N + j] = * (const T*) (arr + i*sizeof(T) + vi[j]); - //if(j==2) { - //printf("cpu -- %d : %d, %f\n", i, vi[j], fArray[i*N+j]); - //} - } + for (int i = 0; i < kSize; ++i) + { + // Next loop vectorizes with "#pragma ivdep", but it runs slower + // #pragma ivdep + for (int j = 0; j < N; ++j) + { + fArray[i*N + j] = * (const T*) (arr + i*sizeof(T) + vi[j]); + } + } + } + else + { + for (int i = 0; i < kSize; ++i) + { + for (int j = 0; j < N_proc; ++j) + { + fArray[i*N + j] = * (const T*) (arr + i*sizeof(T) + vi[j]); + } + } } } diff --git a/Matriplex/MatriplexSym.h b/Matriplex/MatriplexSym.h index 77e0032e563b3..7e98b2fe9c128 100644 --- a/Matriplex/MatriplexSym.h +++ b/Matriplex/MatriplexSym.h @@ -85,16 +85,19 @@ class MatriplexSym #if defined(MIC_INTRINSICS) - void SlurpIn(const char *arr, __m512i& vi) + void SlurpIn(const char *arr, __m512i& vi, const int N_proc = N) { //_mm512_prefetch_i32gather_ps(vi, arr, 1, _MM_HINT_T0); + const __m512 src = { 0 }; + const __mmask16 k = N_proc == N ? -1 : (1 << N_proc) - 1; + for (int i = 0; i < kSize; ++i, arr += sizeof(T)) { //_mm512_prefetch_i32gather_ps(vi, arr+2, 1, _MM_HINT_NTA); - __m512 reg = _mm512_i32gather_ps(vi, arr, 1); - _mm512_store_ps(&fArray[i*N], reg); + __m512 reg = _mm512_mask_i32gather_ps(src, k, vi, arr, 1); + _mm512_mask_store_ps(&fArray[i*N], k, reg); } } @@ -142,14 +145,28 @@ class MatriplexSym #else - void SlurpIn(const char *arr, int vi[N]) + void SlurpIn(const char *arr, int vi[N], const int N_proc = N) { - for (int i = 0; i < kSize; ++i) + // Separate N_proc == N case (gains about 7% in fit test). + if (N_proc == N) + { + for (int i = 0; i < kSize; ++i) + { + for (int j = 0; j < N; ++j) + { + fArray[i*N + j] = * (const T*) (arr + i*sizeof(T) + vi[j]); + } + } + } + else { - for (int j = 0; j < N; ++j) - { - fArray[i*N + j] = * (const T*) (arr + i*sizeof(T) + vi[j]); - } + for (int i = 0; i < kSize; ++i) + { + for (int j = 0; j < N_proc; ++j) + { + fArray[i*N + j] = * (const T*) (arr + i*sizeof(T) + vi[j]); + } + } } } diff --git a/Track.h b/Track.h index 9d048098bca9d..c51e105e01de4 100644 --- a/Track.h +++ b/Track.h @@ -226,6 +226,8 @@ class Track return hitIdxArr_[hitIdxPos_]; } + const int* getHitIdxArray() const { return hitIdxArr_; } + void fillEmptyLayers() { for (int h = hitIdxPos_+1; h < Config::nLayers; h++){ setHitIdx(h,-1); diff --git a/mkFit/MkFitter.cc b/mkFit/MkFitter.cc index eb0185b635f0d..c943a526e0e90 100644 --- a/mkFit/MkFitter.cc +++ b/mkFit/MkFitter.cc @@ -64,7 +64,7 @@ void MkFitter::InputTracksAndHits(const std::vector& tracks, // This might not be true for the last chunk! // assert(end - beg == NN); - int itrack; + int itrack = 0; // FIXME: uncomment when track building is ported to GPU. #if USE_CUDA_NOT_YET @@ -76,17 +76,16 @@ void MkFitter::InputTracksAndHits(const std::vector& tracks, omp_set_num_threads(Config::numThreadsReorg); #pragma omp parallel for private(itrack) #endif - for (int i = beg; i < end; ++i) { - itrack = i - beg; + for (int i = beg; i < end; ++i, ++itrack) + { const Track &trk = tracks[i]; - Label(itrack, 0, 0) = trk.label(); - Err[iC].CopyIn(itrack, trk.errors().Array()); Par[iC].CopyIn(itrack, trk.parameters().Array()); - Chg(itrack, 0, 0) = trk.charge(); - Chi2(itrack, 0, 0) = trk.chi2(); + Chg(itrack, 0, 0) = trk.charge(); + Chi2(itrack, 0, 0) = trk.chi2(); + Label(itrack, 0, 0) = trk.label(); // CopyIn seems fast enough, but indirections are quite slow. // For GPU computations, it has been moved in between kernels @@ -253,24 +252,18 @@ void MkFitter::InputTracksAndHitIdx(const std::vector& tracks, int itrack = 0; for (int i = beg; i < end; ++i, ++itrack) { - const Track &trk = tracks[i]; - Label(itrack, 0, 0) = trk.label(); - Err[iI].CopyIn(itrack, trk.errors().Array()); Par[iI].CopyIn(itrack, trk.parameters().Array()); - Chg (itrack, 0, 0) = trk.charge(); - Chi2(itrack, 0, 0) = trk.chi2(); + Chg (itrack, 0, 0) = trk.charge(); + Chi2(itrack, 0, 0) = trk.chi2(); + Label(itrack, 0, 0) = trk.label(); for (int hi = 0; hi < Nhits; ++hi) { - // MPBL: It does not seem that these values are that dummies - // Not transfering them to the GPU reduces the number of - // nFoundHits in the printouts. - HitsIdx[hi](itrack, 0, 0) = trk.getHitIdx(hi);//dummy value for now - + HitsIdx[hi](itrack, 0, 0) = trk.getHitIdx(hi); } } } @@ -365,6 +358,103 @@ void MkFitter::InputSeedsTracksAndHits(const std::vector& seeds, } } +//------------------------------------------------------------------------------ +// Fitting with interleaved hit loading +//------------------------------------------------------------------------------ + +void MkFitter::InputTracksForFit(const std::vector& tracks, + int beg, int end) +{ + // Loads track parameters and hit indices. + + const int N_proc = end - beg; + const Track &trk0 = tracks[beg]; + const char *varr = (char*) &trk0; + const int off_error = (char*) trk0.errors().Array() - varr; + const int off_param = (char*) trk0.parameters().Array() - varr; + const int off_hitidx = (char*) trk0.getHitIdxArray() - varr; + + int idx[NN] __attribute__((aligned(64))); + + int itrack = 0; + + for (int i = beg; i < end; ++i, ++itrack) + { + const Track &trk = tracks[i]; + + Chg(itrack, 0, 0) = trk.charge(); + Chi2(itrack, 0, 0) = trk.chi2(); + Label(itrack, 0, 0) = trk.label(); + + idx[itrack] = (char*) &trk - varr; + } + + // for ( ; itrack < NN; ++itrack) { idx[itrack] = idx[0]; } + +#ifdef MIC_INTRINSICS + __m512i vi = _mm512_load_epi32(idx); + Err[iC].SlurpIn(varr + off_error, vi, N_proc); + Par[iC].SlurpIn(varr + off_param, vi, N_proc); + for (int ll = 0; ll < Config::nLayers; ++ll) + { + HitsIdx[ll].SlurpIn(varr + off_hitidx + sizeof(int)*ll, vi, N_proc); + } +#else + Err[iC].SlurpIn(varr + off_error, idx, N_proc); + Par[iC].SlurpIn(varr + off_param, idx, N_proc); + for (int ll = 0; ll < Config::nLayers; ++ll) + { + HitsIdx[ll].SlurpIn(varr + off_hitidx + sizeof(int)*ll, idx, N_proc); + } +#endif +} + +void MkFitter::FitTracksWithInterSlurp(const std::vector& layersohits, + const int N_proc) +{ + // Loops over layers and: + // a) slurps in hit parameters; + // b) propagates and updates tracks + + int idx[NN] __attribute__((aligned(64))); + + for (int layer = 0; layer < Nhits; ++layer) + { + const Hit &hit0 = layersohits[layer][0]; + const char *varr = (char*) &hit0; + const int off_param = (char*) hit0.posArray() - varr; + const int off_error = (char*) hit0.errArray() - varr; + + for (int i = 0; i < N_proc; ++i) + { + const int hidx = HitsIdx[layer](i, 0, 0); + + idx[i] = (char*) & layersohits[layer][hidx] - varr; + } + + // for (int i = N_proc; i < NN; ++i) { idx[i] = idx[0]; } + +#ifdef MIC_INTRINSICS + __m512i vi = _mm512_load_epi32(idx); + msPar[0].SlurpIn(varr + off_param, vi, N_proc); + msErr[0].SlurpIn(varr + off_error, vi, N_proc); +#else + msPar[0].SlurpIn(varr + off_param, idx, N_proc); + msErr[0].SlurpIn(varr + off_error, idx, N_proc); +#endif + + propagateHelixToRMPlex(Err[iC], Par[iC], Chg, msPar[0], + Err[iP], Par[iP], N_proc); + + updateParametersMPlex(Err[iP], Par[iP], Chg, msErr[0], msPar[0], + Err[iC], Par[iC], N_proc); + } +} + +//============================================================================== +// Fitting functions +//============================================================================== + void MkFitter::ConformalFitTracks(bool fitting, int beg, int end) { // bool fitting to determine to use fitting CF error widths diff --git a/mkFit/MkFitter.h b/mkFit/MkFitter.h index 95bf5b79b93b5..d56a95a824847 100644 --- a/mkFit/MkFitter.h +++ b/mkFit/MkFitter.h @@ -84,6 +84,10 @@ struct MkFitter void InputTracksAndHitIdx(const std::vector >& tracks, const std::vector >& idxs, int beg, int end, bool inputProp); void InputSeedsTracksAndHits(const std::vector& seeds, const std::vector& tracks, const std::vector& layerHits, int beg, int end); + + void InputTracksForFit(const std::vector& tracks, int beg, int end); + void FitTracksWithInterSlurp(const std::vector& layersohits, int N_proc); + void ConformalFitTracks(bool fitting, int beg, int end); void FitTracks(const int N_proc, const Event * ev, const bool useParamBfield = false); void FitTracksTestEndcap(const int N_proc, const Event* ev, const bool useParamBfield = false); diff --git a/mkFit/fittestMPlex.cc b/mkFit/fittestMPlex.cc index c201bbbd25f92..ae354dd20db7b 100644 --- a/mkFit/fittestMPlex.cc +++ b/mkFit/fittestMPlex.cc @@ -148,9 +148,10 @@ double runFittingTestPlex(Event& ev, std::vector& rectracks) mkfp->SetNhits(Nhits); for (int it = i.begin(); it < i.end(); ++it) { - int itrack = it*NN; - int end = itrack + NN; - if (Config::endcapTest) { + int itrack = it * NN; + int end = itrack + NN; + if (Config::endcapTest) + { //fixme, check usage of SlurpInTracksAndHits for endcapTest if (Config::readCmsswSeeds) { mkfp->InputSeedsTracksAndHits(ev.seedTracks_,simtracks, ev.layerHits_, itrack, end); @@ -159,6 +160,12 @@ double runFittingTestPlex(Event& ev, std::vector& rectracks) } mkfp->FitTracksTestEndcap(end - itrack, &ev, true); } else { + mkfp->FitTracksTestEndcap(end - itrack, &ev); + } + else + { + /* + * MT, trying to slurp and fit at the same time ... if (theEnd < end) { end = theEnd; mkfp->InputTracksAndHits(simtracks, ev.layerHits_, itrack, end); @@ -168,7 +175,16 @@ double runFittingTestPlex(Event& ev, std::vector& rectracks) if (Config::cf_fitting) mkfp->ConformalFitTracks(true, itrack, end); mkfp->FitTracks(end - itrack, &ev, true); + */ + + mkfp->InputTracksForFit(simtracks, itrack, end); + + // XXXX MT - for this need 3 points in ... right + // XXXX if (Config::cf_fitting) mkfp->ConformalFitTracks(true, itrack, end); + + mkfp->FitTracksWithInterSlurp(ev.layerHits_, end - itrack); } + mkfp->OutputFittedTracks(rectracks, itrack, end); } }); From 43471a6d6521756f3a4c460df1179709e13a328c Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Wed, 11 Jan 2017 11:54:15 -0800 Subject: [PATCH 002/172] Modify SimpleGeom to also support endcap disks. --- Config.h | 3 ++- Geometry.h | 6 +++++ SimpleGeom.cc | 63 ++++++++++++++++++++++++++++++++++++++++++-------- SimpleGeom.h | 28 ++++++++++++++++++---- Validation.cc | 2 +- main.cc | 2 +- mkFit/mkFit.cc | 17 ++++++++++---- 7 files changed, 98 insertions(+), 23 deletions(-) diff --git a/Config.h b/Config.h index b4cb998f9553c..d332670d29fe4 100644 --- a/Config.h +++ b/Config.h @@ -25,8 +25,9 @@ namespace Config constexpr float InvPI = 1.0f / Config::PI; constexpr float RadToDeg = 180.0f / Config::PI; constexpr float DegToRad = Config::PI / 180.0f; - constexpr double Sqrt2 = 1.4142135623730950488016887242097; constexpr float sol = 0.299792458; // speed of light in nm/s + constexpr double Sqrt2 = 1.4142135623730950488016887242097; + constexpr double OOSqrt2 = 1.0 / Config::Sqrt2; // general parameters of matrices constexpr int nParams = 6; diff --git a/Geometry.h b/Geometry.h index 2bbd0516ae645..34c359557eb4f 100644 --- a/Geometry.h +++ b/Geometry.h @@ -10,6 +10,12 @@ #include "SimpleGeom.h" #endif +// XXXX MT: What it the purpose of zPlanes? +// I guess this is half-baked and we actually need two add layer +// methods, like AddBarellLayer(), AddEndcapLayer(). +// And probably something even more descriptive, so we can also +// build navigation LUTs (or something). + class Geometry { public: ~Geometry() { for (auto& s : solids_) { delete s; }} diff --git a/SimpleGeom.cc b/SimpleGeom.cc index 514d4d870869f..c66bb99b2a983 100644 --- a/SimpleGeom.cc +++ b/SimpleGeom.cc @@ -3,30 +3,73 @@ VUSolid::EnumInside VUSolid::Inside (const UVector3 &aPoint) const { - double r = aPoint.Perp(); - if (rin_ < r && r < rout_) return eInside; + double z = aPoint.Z(); + if (zmin_ < z && z < zmax_) + { + double r = aPoint.Perp(); + if (rin_ < r && r < rout_) return eInside; + } return eOutside; } double VUSolid::SafetyFromInside (const UVector3 &aPoint, bool) const { double r = aPoint.Perp(); - if (rin_ < r && r < rout_) return std::min(r - rin_, rout_ - r); + if (rin_ < r && r < rout_) + { + double z = aPoint.Z(); + if (zmin_ < z && z < zmax_) + { + double dr = std::min(r - rin_, rout_ - r); + return std::hypot(dr, std::min(z - zmin_, zmax_ - z)); + } + } return 0.0; } double VUSolid::SafetyFromOutside(const UVector3 &aPoint, bool) const { - double r = aPoint.Perp(); - if (rin_ < r && r < rout_) return 0.0; - return std::min(std::abs(r - rin_), std::abs(rout_ - r)); + double r = aPoint.Perp(), z = aPoint.Z(), dr, dz; + if (r < rin_) dr = rin_ - r; + else if (r > rout_) dr = r - rout_; + else dr = 0; + if (z < zmin_) dz = zmin_ - z; + else if (z > zmax_) dz = z - zmax_; + else dz = 0; + return std::hypot(dr, dz); } -bool VUSolid::Normal( const UVector3& aPoint, UVector3 &aNormal ) const +bool VUSolid::Normal(const UVector3& aPoint, UVector3 &aNormal) const { - double rho = aPoint.Perp(); - aNormal = UVector3(aPoint.At(0)/rho, aPoint.At(1)/rho, 0.0); - return true; + const double tol = 1e-6; + const double rho = aPoint.Perp(); + const double zoo = aPoint.At(2); + + bool nz_is_min = std::abs(zoo - zmin_) < std::abs(zoo - zmax_); + double dz = nz_is_min ? std::abs(zoo - zmin_) : std::abs(zoo - zmax_); + + bool nr_is_in = std::abs(rho - rin_) < std::abs(rho - rout_); + double dr = nr_is_in ? std::abs(rho - rin_) : std::abs(rho - rout_); + + if (dr < tol && dz < tol) + { + aNormal.At(0) = aPoint.At(0) / rho * (nr_is_in ? - Config::OOSqrt2 : Config::OOSqrt2); + aNormal.At(1) = aPoint.At(1) / rho * (nr_is_in ? - Config::OOSqrt2 : Config::OOSqrt2); + aNormal.At(2) = nz_is_min ? - Config::OOSqrt2 : Config::OOSqrt2; + } + else if (dr < dz) + { + if (nr_is_in) + aNormal = UVector3(-aPoint.At(0)/rho, -aPoint.At(1)/rho, 0.0); + else + aNormal = UVector3( aPoint.At(0)/rho, aPoint.At(1)/rho, 0.0); + } + else + { + aNormal = UVector3(0.0, 0.0, nz_is_min ? -1.0 : 1.0); + } + + return dz < tol || dr < tol; } double UVector3::Normalize() diff --git a/SimpleGeom.h b/SimpleGeom.h index 56202882fd9e1..41f2885c10bb6 100644 --- a/SimpleGeom.h +++ b/SimpleGeom.h @@ -3,11 +3,20 @@ #include #include "Matrix.h" +// MT XXXX: Should SVector3 base class really be the double +// version (probably is float right now). + #ifndef WITH_USOLIDS -class UVector3 : public SVector3 { +class UVector3 : public SVector3 +{ public: UVector3(float x, float y, float z) : SVector3(x, y, z) {} UVector3() : SVector(0.0f,0.0f,0.0f) {} + + inline double X() const { return At(0); } + inline double Y() const { return At(1); } + inline double Z() const { return At(2); } + inline double Dot(const UVector3&) const; inline double Mag2() const; inline double Mag() const; @@ -41,16 +50,25 @@ inline double UVector3::Perp() const return std::sqrt(Perp2()); } -class VUSolid { +class VUSolid +{ public: - VUSolid(double rin, double rout) : rin_(rin), rout_(rout) {} enum EnumInside { eInside=0, eSurface=1, eOutside=2 }; + + VUSolid(double rin, double rout, double zmin, double zmax) : + rin_(rin), rout_(rout), zmin_(zmin), zmax_(zmax) + {} + EnumInside Inside (const UVector3 &aPoint) const; double SafetyFromInside (const UVector3 &aPoint, bool aAccurate=false) const; double SafetyFromOutside(const UVector3 &aPoint, bool aAccurate=false) const; - bool Normal( const UVector3& aPoint, UVector3 &aNormal ) const; + bool Normal(const UVector3& aPoint, UVector3 &aNormal) const; + + VUSolid* Clone() const {return new VUSolid(rin_, rout_, zmin_, zmax_);} + double rin_, rout_; - VUSolid* Clone() const {return new VUSolid(rin_, rout_);} + double zmin_, zmax_; }; + #endif #endif diff --git a/Validation.cc b/Validation.cc index d9c85d4619426..38fe1678f5c1d 100644 --- a/Validation.cc +++ b/Validation.cc @@ -10,4 +10,4 @@ Validation* Validation::make_validation(const std::string& fileName) return new Validation(); } -Validation::Validation() {} \ No newline at end of file +Validation::Validation() {} diff --git a/main.cc b/main.cc index 38e146f11302d..027047649bb07 100644 --- a/main.cc +++ b/main.cc @@ -75,7 +75,7 @@ void initGeom(Geometry& geom) for (int l = 0; l < Config::nLayers; l++) { float r = (l+1)*Config::fRadialSpacing; float z = r / std::tan(2.0*std::atan(std::exp(-Config::fEtaDet))); // calculate z extent based on eta, r - VUSolid* utub = new VUSolid(r, r+Config::fRadialExtent); + VUSolid* utub = new VUSolid(r, r+Config::fRadialExtent, -z, z); geom.AddLayer(utub, r, z); } } diff --git a/mkFit/mkFit.cc b/mkFit/mkFit.cc index b6395a1490554..e0e187b51e0dc 100644 --- a/mkFit/mkFit.cc +++ b/mkFit/mkFit.cc @@ -48,17 +48,24 @@ void initGeom(Geometry& geom) // are added starting from the center // NB: z is just a dummy variable, VUSolid is actually infinite in size. *** Therefore, set it to the eta of simulation *** float eta = 2.0; // can tune this to whatever geometry required (one can make this layer dependent as well) - for (int l = 0; l < Config::nLayers; l++) { - if (Config::endcapTest) { + for (int l = 0; l < Config::nLayers; l++) + { + if (Config::endcapTest) + { float z = Config::useCMSGeom ? Config::cmsAvgZs[l] : (l+1)*10.;//Config::fLongitSpacing float rmin = Config::useCMSGeom ? Config::cmsDiskMinRs[l] : 0; float rmax = Config::useCMSGeom ? Config::cmsDiskMaxRs[l] : 0; - VUSolid* utub = new VUSolid(rmin, rmax); + // XXXX MT: Do we need endcap layer "thickness" for cmssw at all? Use something. + // Do we even need geometry for cmssw? + float dz = 0.5; + VUSolid* utub = new VUSolid(rmin, rmax, z - dz, z + dz); geom.AddLayer(utub, rmin, z); - } else { + } + else + { float r = Config::useCMSGeom ? Config::cmsAvgRads[l] : (l+1)*Config::fRadialSpacing; - VUSolid* utub = new VUSolid(r, r+Config::fRadialExtent); float z = r / std::tan(2.0*std::atan(std::exp(-eta))); // calculate z extent based on eta, r + VUSolid* utub = new VUSolid(r, r+Config::fRadialExtent, -z, z); geom.AddLayer(utub, r, z); } } From 579c145d723d7fb4de5d513bbe3c78c19485f090 Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Fri, 3 Feb 2017 02:30:11 -0800 Subject: [PATCH 003/172] Get simulation to work with Cylindrical Cow With Lids Track finding has not been tested. 1 in 1000 tracks scatters out of the detector. This should be handled with less noise (it never happened before as we had infinite barrel cylinders. minSimPt increased to 1 GeV. MaxSimEta set to 2.4 to reduce the above effect. TrackerInfo (new class) put into Config ... not the nicest thing to do. It is generated from CylCowWLids.cc. - Idea is to have plugin that create TrackerInfo. Now hardcoded in mkFit main. - Simulation Geometry can be created from TrackerInfo. Simulation code assumed, quite strongly, that geometry is made of cylinders only. - Had quite some fun with it ... - Helix in Propagation.cc assumes distance to be radial distance. - I reworked distance calculations to work with radial distance when calculating safety and also for stepping. double Geometry::SafetyFromOutside2(const UVector3 &aPoint, those are <- double ctgTheta, new <- int skip_layer, int &layer, bool aAccurate) const - SimpleGeom VUSolid now also has bools is_barrel (for above reason) and is_outer (to stop the track). Code in Event really really expected each track to have nLayers hits. Sigh. - I think I worked around most of those. - There were several instances where threads were writing hits and hitinfos into pre-resized vectors. This doesn't really work: a) now we do not know number of hits per track; b) also because of tracks scattering out of finite geometry; c) is NOT thread safe, cache-lines can get screwed. I modified the code to do all the writing at the end of track processing and protected it with a mutex. Better ideas welcome ... but it runs pretty fast, 100k tracks in ~5s on my 4-core haswell desktop. Files get written out, should try reading them back in. Validation is not tested. --- CylCowWLids.cc | 186 +++++++++++++++++++++++++++++++++++++++++++++++++ CylCowWLids.h | 10 +++ TrackerInfo.cc | 1 + TrackerInfo.h | 63 +++++++++++++++++ 4 files changed, 260 insertions(+) create mode 100644 CylCowWLids.cc create mode 100644 CylCowWLids.h create mode 100644 TrackerInfo.cc create mode 100644 TrackerInfo.h diff --git a/CylCowWLids.cc b/CylCowWLids.cc new file mode 100644 index 0000000000000..600d33f70b846 --- /dev/null +++ b/CylCowWLids.cc @@ -0,0 +1,186 @@ +#include "CylCowWLids.h" + +#include "Config.h" +#include "TrackerInfo.h" + +#include + +namespace +{ + class CylCowWLidsCreator + { + TrackerInfo &m_trkinfo; + + float m_det_half_thickness = 0.005; // for 100 micron total + + int m_n_barrel = 10; + int m_n_endcap = 9; + int m_first_ecap = 10; + + inline float getTheta(float r, float z) + { + return std::atan2(r,z); + } + + inline float getEta(float r, float z) + { + return -1.0f * std::log( std::tan(getTheta(r,z)/2.0f) ); + } + + inline float getEta(float theta) + { + return -1.0f * std::log( std::tan(theta/2.0f) ); + } + + inline float getTgTheta(float eta) + { + return std::tan(2.0*std::atan(std::exp(-eta))); + } + + //------------------------------------------------------------------------------ + + void add_barrel(int lid, float r, float z, float eta) + { + // printf("Adding barrel layer r=%.3f z=%.3f eta_t=%.3f\n", r, z, eta); + + LayerInfo & li = m_trkinfo.m_layers[lid]; + + li.m_rin = r - m_det_half_thickness; + li.m_rout = r + m_det_half_thickness; + li.m_zmin = -z; + li.m_zmax = z; + + li.m_next_barrel = lid < 9 ? lid + 1 : -1; + li.m_next_ecap_pos = lid < 9 ? lid + 1 + 9 : -1; + li.m_next_ecap_neg = lid < 9 ? lid + 1 + 18 : -1; + + li.m_is_barrel = true; + li.m_is_outer = (lid == 9); + } + + void add_barrel_r_eta(int lid, float r, float eta) + { + float z = r / getTgTheta(eta); + + add_barrel(lid, r, z, eta); + } + + void add_barrel_r_z(int lid, float r, float z) + { + float eta = getEta(r, z); + + add_barrel(lid, r, z, eta); + } + + void add_endcap(int lid, float r, float z, float eta) + { + float r_end = z * getTgTheta(eta); + + // printf("Adding endcap layer r=%.3f z=%.3f r_l=%.3f eta_l=%.3f\n", r, z, r_end, eta); + + { + LayerInfo & li = m_trkinfo.m_layers[lid]; + + li.m_rin = r_end; + li.m_rout = r; + li.m_zmin = z - m_det_half_thickness; + li.m_zmax = z + m_det_half_thickness; + + li.m_next_barrel = lid < 18 ? lid - 10 + 2 : -1; + li.m_next_ecap_pos = lid < 18 ? lid + 1 : -1; + li.m_next_ecap_neg = -1; + + li.m_is_barrel = false; + li.m_is_outer = (lid == 18); + } + { + lid += 9; + LayerInfo & li = m_trkinfo.m_layers[lid]; + + li.m_rin = r_end; + li.m_rout = r; + li.m_zmin = -z - m_det_half_thickness; + li.m_zmax = -z + m_det_half_thickness; + + li.m_next_barrel = lid < 27 ? lid - 19 + 2 : -1; + li.m_next_ecap_pos = -1; + li.m_next_ecap_neg = lid < 27 ? lid + 1 : -1; + + li.m_is_barrel = false; + li.m_is_outer = (lid == 27); + } + } + + //------------------------------------------------------------------------------ + + public: + + CylCowWLidsCreator(TrackerInfo& ti) : + m_trkinfo(ti) + {} + + void FillTrackerInfo() + { + float full_eta = 2.5; + + float pix_0 = 4, pix_sep = 6; + float pix_z0 = 24, pix_zgrow = 6; + + float sct_sep = 10; + float sct_0 = pix_0 + 2 * pix_sep + sct_sep; + float sct_zgrow = 10; + float sct_z0 = pix_z0 + 2 * pix_zgrow + sct_zgrow; + + float pix_ec_zgap = 2; + float pix_ec_rextra = 2; + + float sct_ec_zgap = 4; + float sct_ec_rextra = 4; + + for (int i = 0; i < 10; ++i) m_trkinfo.new_barrel_layer(); + for (int i = 0; i < 9; ++i) m_trkinfo.new_ecap_pos_layer(); + for (int i = 0; i < 9; ++i) m_trkinfo.new_ecap_neg_layer(); + + add_barrel_r_eta(0, pix_0, full_eta); + + add_barrel_r_z (1, pix_0 + 1 * pix_sep, pix_z0 + 1 * pix_zgrow); + add_barrel_r_z (2, pix_0 + 2 * pix_sep, pix_z0 + 2 * pix_zgrow); + + for (int i = 0; i < 7; ++i) + { + add_barrel_r_z(3 + i, sct_0 + i * sct_sep, sct_z0 + i * sct_zgrow); + } + + for (int i = 1; i < 3; ++i) + { + add_endcap(9 + i, + pix_0 + i * pix_sep + pix_ec_rextra, + pix_z0 + i * pix_zgrow + pix_ec_zgap, + full_eta); + } + for (int i = 0; i < 7; ++i) + { + add_endcap(12 + i, + sct_0 + i * sct_sep + sct_ec_rextra, + sct_z0 + i * sct_zgrow + sct_ec_zgap, + full_eta); + } + // + endcap disks at -z + } + }; +} + +//============================================================================== + +void Create_TrackerInfo(TrackerInfo& ti) +{ + CylCowWLidsCreator creator(ti); + + creator.FillTrackerInfo(); + + printf("==========================================================================================\n"); + printf("CylCowWLids -- Create_TrackerInfo finished\n"); + printf("==========================================================================================\n"); + for (auto &i : ti.m_layers) i.print_layer(); + printf("==========================================================================================\n"); +} diff --git a/CylCowWLids.h b/CylCowWLids.h new file mode 100644 index 0000000000000..20830ee041001 --- /dev/null +++ b/CylCowWLids.h @@ -0,0 +1,10 @@ +#ifndef CYLCOWWLIDS_H +#define CYLCOWWLIDS_H + +class TrackerInfo; + +// This could be translated into plugin + +void Create_TrackerInfo(TrackerInfo& ti); + +#endif diff --git a/TrackerInfo.cc b/TrackerInfo.cc new file mode 100644 index 0000000000000..780a855d024d4 --- /dev/null +++ b/TrackerInfo.cc @@ -0,0 +1 @@ +#include "TrackerInfo.h" diff --git a/TrackerInfo.h b/TrackerInfo.h new file mode 100644 index 0000000000000..c6d6122bc3b88 --- /dev/null +++ b/TrackerInfo.h @@ -0,0 +1,63 @@ +#ifndef TRACKERINFO_H +#define TRACKERINFO_H + +#include + +#include + +class LayerInfo +{ +public: + int m_layer_id; + + float m_rin, m_rout, m_zmin, m_zmax; + + int m_next_barrel, m_next_ecap_pos, m_next_ecap_neg; + + bool m_is_barrel; // or byte enum barrel, ecappos, ecapneg + bool m_is_outer; + + // Additional stuff needed? + // * pixel / strip, mono / stereo + // * resolutions + // * functions / lambdas for deciding / calculating stuff + // * ... + // * pointers to hit containers + + LayerInfo(int lid) : m_layer_id(lid) {} + + float r_mean() const { return (m_rin + m_rout) / 2; } + float z_mean() const { return (m_zmin + m_zmax) / 2; } + + void print_layer() + { + printf("Layer %2d r(%7.4f, %7.4f) z(% 9.4f, % 9.4f) next(%2d, %2d, %2d) is_brl=%d is_outer=%d\n", + m_layer_id, m_rin, m_rout, m_zmin, m_zmax, + m_next_barrel, m_next_ecap_pos, m_next_ecap_neg, + m_is_barrel, m_is_outer); + } +}; + +class TrackerInfo +{ +private: + int new_layer() + { + int l = (int) m_layers.size(); + m_layers.push_back(LayerInfo(l)); + return l; + } + +public: + std::vector m_layers; + + std::vector m_barrel; + std::vector m_ecap_pos; + std::vector m_ecap_neg; + + LayerInfo & new_barrel_layer() { m_barrel .push_back( new_layer() ); return m_layers.back(); } + LayerInfo & new_ecap_pos_layer() { m_ecap_pos.push_back( new_layer() ); return m_layers.back(); } + LayerInfo & new_ecap_neg_layer() { m_ecap_neg.push_back( new_layer() ); return m_layers.back(); } +}; + +#endif From 126eeabf3a6c48eb2ca6ab4ba4981d5b08d5b81c Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Fri, 3 Feb 2017 02:58:18 -0800 Subject: [PATCH 004/172] And all the other changes that should have been in the previous commit :) --- Config.cc | 2 + Config.h | 33 ++++++++++++++-- Debug.h | 46 ++++------------------ Event.cc | 58 ++++++++++++++++++++++------ Event.h | 5 ++- Geometry.cc | 64 +++++++++++++++++++++++++++++++ Geometry.h | 15 ++++++-- Hit.cc | 11 ++++++ Hit.h | 3 ++ Makefile.config | 4 ++ Propagation.cc | 100 +++++++++++++++++++++++++++++++++++------------- Propagation.h | 1 - SimpleGeom.h | 12 ++++-- Simulation.cc | 70 +++++++++++++++++++++------------ Simulation.h | 3 +- Track.cc | 27 +++++++++++++ Track.h | 9 ++++- main.cc | 2 +- mkFit/Makefile | 2 +- mkFit/mkFit.cc | 53 ++++++++++++++++--------- 20 files changed, 384 insertions(+), 136 deletions(-) diff --git a/Config.cc b/Config.cc index e24a9e31e60f2..35283300312cf 100644 --- a/Config.cc +++ b/Config.cc @@ -2,6 +2,8 @@ namespace Config { + TrackerInfo TrkInfo; + int nTracks = 10000; int nEvents = 20; diff --git a/Config.h b/Config.h index d332670d29fe4..3e612241e3d87 100644 --- a/Config.h +++ b/Config.h @@ -1,6 +1,9 @@ #ifndef _config_ #define _config_ +// Cram this in here for now ... +#include "TrackerInfo.h" + #include #include #include // won't compile on clang gcc for mac OS w/o this! @@ -10,6 +13,8 @@ namespace Config { + extern TrackerInfo TrkInfo; + // super debug mode in SMatrix extern bool super_debug; @@ -38,6 +43,21 @@ namespace Config // config on main -- for geometry constexpr int nLayers = 10; // default: 10; cmssw tests: 13, 17, 26 (for endcap) + + // New layer constants for common barrel / endcap. I'd prefer those to go + // into some geometry definition "plugin" -- they belong more into some Geom + // namespace, too. + // XXXX This needs to be generalized for other geometries ! + // TrackerInfo more or less has all this information (or could have it). + constexpr int nTotalLayers = 28; + constexpr int nMaxTrkLayers = 19; // Assuming hitting every barrel / endcap edge + constexpr int nBarrelLayers = 10; + constexpr int BarrelLayer0 = 0; + constexpr int nECapLayers = 9; + constexpr int ECapPosLayer0 = 10; + constexpr int ECapNegLayer0 = 19; + // min/max etas or thetas for EC-, T-, B, T+, EC+ + constexpr float fRadialSpacing = 4.; constexpr float fRadialExtent = 0.01; constexpr float fInnerSensorSize = 5.0; // approximate sensor size in cm @@ -124,10 +144,11 @@ namespace Config constexpr float beamspotY = 0.1; constexpr float beamspotZ = 1.0; - constexpr float minSimPt = 0.5; + constexpr float minSimPt = 1; // 0.5; constexpr float maxSimPt = 10.; - constexpr float maxEta = 1.0; + constexpr float minSimEta = 0.0; // XXMT4K Added min, too. + constexpr float maxSimEta = 2.4; // Should both become config vars? constexpr float hitposerrXY = 0.01; // resolution is 100um in xy --> more realistic scenario is 0.003 constexpr float hitposerrZ = 0.1; // resolution is 1mm in z @@ -136,7 +157,10 @@ namespace Config constexpr float varZ = Config::hitposerrZ * Config::hitposerrZ; constexpr float varR = Config::hitposerrR * Config::hitposerrR; - constexpr int nTotHit = Config::nLayers; // for now one hit per layer for sim + // XXMT4K OK ... what do we do with this guy? MaxTotHit / AvgTotHit ... ? + // For now setting it to nMaxTrkLayers which is too big ... but it seems to be + // only used for vector::reserve() ... + constexpr int nTotHit = Config::nMaxTrkLayers; // for now one hit per layer for sim // scattering simulation constexpr float X0 = 9.370; // cm, from http://pdg.lbl.gov/2014/AtomicNuclearProperties/HTML/silicon_Si.html // Pb = 0.5612 cm @@ -158,7 +182,8 @@ namespace Config extern bool findSeeds; // Config for propagation - constexpr int Niter = 5; + constexpr int Niter = 5; + constexpr int NiterSim = 10; // Can make more steps due to near volume misses. constexpr bool useTrigApprox = true; // Config for Bfield diff --git a/Debug.h b/Debug.h index 253777591753d..ac4fb05695ab6 100644 --- a/Debug.h +++ b/Debug.h @@ -3,11 +3,13 @@ #define _debug_ #ifdef dprint + #undef dprint #undef dprint_np #undef dcall #undef dprintf #undef dprintf_np + #endif /* Usage: DEBUG must be defined before this header file is included, typically @@ -49,54 +51,22 @@ #define dprint_np(n,x) if(debug && n < N_proc) { dmutex_guard; std::cout << n << ": " << x << std::endl; } #define dcall(x) if (debug) { dmutex_guard; x; } #define dprintf(...) if (debug) { dmutex_guard; printf(__VA_ARGS__); } -#define dprintf_np(n, ...) if (debug && n< N_proc) { dmutex_guard; std::cout << n << ": "; printf(__VA_ARGS__); } +#define dprintf_np(n, ...) if (debug && n < N_proc) { dmutex_guard; std::cout << n << ": "; printf(__VA_ARGS__); } -namespace { +namespace +{ bool debug = false; // default, can be overridden locally std::mutex debug_mutex; } -static void print(const TrackState& s) -{ - std::cout << "x: " << s.parameters[0] - << " y: " << s.parameters[1] - << " z: " << s.parameters[2] << std::endl - << "px: " << s.parameters[3] - << " py: " << s.parameters[4] - << " pz: " << s.parameters[5] << std::endl - << "valid: " << s.valid << " errors: " << std::endl; - dumpMatrix(s.errors); - std::cout << std::endl; -} - -static void print(std::string label, int itrack, const Track& trk) -{ - std::cout << std::endl << label << ": " << itrack << " hits: " << trk.nFoundHits() << " State" << std::endl; - print(trk.state()); -} - -static void print(std::string label, const TrackState& s) -{ - std::cout << label << std::endl; - print(s); -} - -static void print(std::string label, const MeasurementState& s) -{ - std::cout << label << std::endl; - std::cout << "x: " << s.parameters()[0] - << " y: " << s.parameters()[1] - << " z: " << s.parameters()[2] << std::endl - << "errors: " << std::endl; - dumpMatrix(s.errors()); - std::cout << std::endl; -} - #else + #define dprint(x) (void(0)) #define dprint_np(n,x) (void(0)) #define dcall(x) (void(0)) #define dprintf(...) (void(0)) #define dprintf_np(n,...) (void(0)) + #endif + #endif diff --git a/Event.cc b/Event.cc index 7c09db3f8910c..97b5f0f2e6291 100644 --- a/Event.cc +++ b/Event.cc @@ -59,11 +59,14 @@ void Event::resetLayerHitMap(bool resetSimHits) { } } -Event::Event(const Geometry& g, Validation& v, int evtID, int threads) : geom_(g), validation_(v), evtID_(evtID), threads_(threads), mcHitIDCounter_(0) +Event::Event(const Geometry& g, Validation& v, int evtID, int threads) : + geom_(g), validation_(v), + evtID_(evtID), threads_(threads), mcHitIDCounter_(0) { - layerHits_.resize(Config::nLayers); - segmentMap_.resize(Config::nLayers); + layerHits_.resize(Config::nTotalLayers); + segmentMap_.resize(Config::nTotalLayers); + // XXMT4K validation_.resetValidationMaps(); // need to reset maps for every event. if (Config::super_debug) { validation_.resetDebugVectors(); // need to reset vectors for every event. @@ -95,9 +98,14 @@ void Event::Reset(int evtID) void Event::Simulate() { simTracks_.resize(Config::nTracks); - simHitsInfo_.resize(Config::nTotHit * Config::nTracks); + simHitsInfo_.clear(); + simHitsInfo_.reserve(Config::nTotHit * Config::nTracks); + for (auto&& l : layerHits_) { - l.resize(Config::nTracks); // thread safety + // XXMT4K can not assume each track will have hits in every layer ... + // WAS: l.resize(Config::nTracks); // thread safety + l.clear(); + l.reserve(Config::nTracks); } simTrackStates_.resize(Config::nTracks); @@ -116,6 +124,7 @@ void Event::Simulate() SVector3 mom; SMatrixSym66 covtrk; HitVec hits; + MCHitInfoVec hitinfos; TSVec initialTSs; // int starting_layer = 0; --> for displaced tracks, may want to consider running a separate Simulate() block with extra parameters @@ -123,7 +132,13 @@ void Event::Simulate() // do the simulation if (Config::useCMSGeom) setupTrackFromTextFile(pos,mom,covtrk,hits,*this,itrack,q,tmpgeom,initialTSs); else if (Config::endcapTest) setupTrackByToyMCEndcap(pos,mom,covtrk,hits,*this,itrack,q,tmpgeom,initialTSs); - else setupTrackByToyMC(pos,mom,covtrk,hits,*this,itrack,q,tmpgeom,initialTSs); + else setupTrackByToyMC(pos,mom,covtrk,hits,hitinfos,*this,itrack,q,tmpgeom,initialTSs); + + // XXMT4K What genius set up separate setupTrackByToyMC / setupTrackByToyMCEndcap? + // setupTrackByToyMCEndcap does not have scattering and who knows what else. + // In the original commit Giuseppe he only did fittest ... strangle ... etc ... + // I'll just review/fix setupTrackByToyMC() for now (so Config::endcapTest = false). + // See also ifdef just below: #ifdef CCSCOORD // setupTrackByToyMCEndcap is already in CCS coord, no need to convert @@ -135,6 +150,10 @@ void Event::Simulate() } } #endif + // XXMT4K: From here on we can always have overlapping cache lines. + // I'm putting in a mutex for now ... + std::lock_guard lock(mcGatherMutex_); + // uber ugly way of getting around read-in / write-out of objects needed for validation if (Config::normal_val || Config::fit_val) {simTrackStates_[itrack] = initialTSs;} validation_.collectSimTkTSVecMapInfo(itrack,initialTSs); // save initial TS parameters in validation object ... just a copy of the above line @@ -142,16 +161,32 @@ void Event::Simulate() simTracks_[itrack] = Track(q,pos,mom,covtrk,0.0f); auto& sim_track = simTracks_[itrack]; sim_track.setLabel(itrack); - for (int ilay = 0; ilay < hits.size(); ++ilay) { - sim_track.addHitIdx(hits[ilay].mcHitID(),0.0f); // set to the correct hit index after sorting - layerHits_[ilay][itrack] = hits[ilay]; // thread safety + + // XXMT4K My attempt at rewriting the code below - not all layers are traversed with endcap. + // Note ... this still asusmes single hit per layer, right? + // What is the comment about thread safety??? The final index is on itrack and this will clash due to cache-line overlaps. + assert(hits.size() == hitinfos.size()); + for (int i = 0; i < hits.size(); ++i) + { + sim_track.addHitIdx(hits[i].mcHitID(), 0.0f); // set to the correct hit index after sorting + layerHits_[hitinfos[i].layer_].emplace_back(hits[i]); + simHitsInfo_.emplace_back(hitinfos[i]); } + // for (int ilay = 0; ilay < hits.size(); ++ilay) { + // sim_track.addHitIdx(hits[ilay].mcHitID(),0.0f); // set to the correct hit index after sorting + // layerHits_[ilay][itrack] = hits[ilay]; // thread safety + // } } #ifdef TBB }); #endif + + std::sort(simHitsInfo_.begin(), simHitsInfo_.end(), + [](const MCHitInfo& a, const MCHitInfo& b) + { return a.mcHitID_ < b.mcHitID_; }); } +// XXMT4K What does this do? Needs change? void Event::Segment() { #ifdef DEBUG @@ -257,7 +292,7 @@ void Event::Segment() resetLayerHitMap(true); } - void Event::Seed() +void Event::Seed() { #ifdef ENDTOEND buildSeedsByRoadSearch(seedTracks_,seedTracksExtra_,layerHits_,segmentMap_,*this); @@ -291,7 +326,8 @@ void Event::Fit() #endif } -void Event::Validate(){ +void Event::Validate() +{ // KM: Config tree just filled once... in main.cc if (Config::normal_val) { validation_.setTrackExtras(*this); diff --git a/Event.h b/Event.h index 307e2f0d82673..e736758ce5403 100644 --- a/Event.h +++ b/Event.h @@ -17,7 +17,9 @@ struct HitID { }; typedef std::vector HitIDVec; -class Event { + +class Event +{ public: Event(const Geometry& g, Validation& v, int evtID, int threads = 1); void Reset(int evtID); @@ -43,6 +45,7 @@ class Event { int evtID_; public: int threads_; + std::mutex mcGatherMutex_; std::atomic mcHitIDCounter_; std::vector layerHits_; MCHitInfoVec simHitsInfo_; diff --git a/Geometry.cc b/Geometry.cc index 7d8b0c7d68822..86021253c1643 100644 --- a/Geometry.cc +++ b/Geometry.cc @@ -1,4 +1,6 @@ #include "Geometry.h" +//#define DEBUG +#include "Debug.h" VUSolid::EnumInside Geometry::Inside (const UVector3 &aPoint) const { VUSolid::EnumInside in = VUSolid::eOutside; @@ -27,6 +29,16 @@ int Geometry::LayerIndex(const UVector3 &aPoint) const { return -1; } +int Geometry::LayerOfSolid(const VUSolid *s) const +{ + for (auto i = solids_.begin(); i != solids_.end(); ++i) { + if (*i == s) { + return std::distance(solids_.begin(),i); + } + } + return -1; +} + double Geometry::SafetyFromInside ( const UVector3 &aPoint, bool aAccurate) const { double small = 1e10; @@ -51,6 +63,39 @@ double Geometry::SafetyFromOutside ( const UVector3 &aPoint, bool aAccurate) con return small; } +double Geometry::SafetyFromOutside2(const UVector3 &aPoint, double ctgTheta, + int skip_layer, int &layer, bool aAccurate) const +{ + bool debug = true; + + double small = 1e10; + + dprintf("Geometry::SafetyFromOutside2 r=%f, z=%f\n", aPoint.Perp(), aPoint.Z()); + int ii = 0; + layer = -1; + for (auto i = solids_.begin(); i != solids_.end(); ++i, ++ii) + { + if (ii != skip_layer && (*i)->Inside(aPoint) == VUSolid::eOutside) + { + double next = (*i)->SafetyFromOutside(aPoint, aAccurate); + if ( ! (*i)->is_barrel_) + { + double fnext = next; + next /= std::abs(ctgTheta); + if (next < 15) dprintf(" Radial distance to %2d = %4.5f (not ecap corrected %4.5f)\n", ii, next, fnext); + } + else + { + if (next < 15) dprintf(" Radial distance to %2d = %4.5f\n", ii, next); + } + + if (next < small) { small = next; layer = ii; } + } + } + dprintf(" Selected layer %2d = %f\n", layer, small); + return small; +} + Geometry Geometry::clone() const { Geometry NewGeo(*this); @@ -59,3 +104,22 @@ Geometry Geometry::clone() const } return NewGeo; } + +//============================================================================== + +void Geometry::BuildFromTrackerInfo(const TrackerInfo& tracker_info) +{ +#ifndef WITH_USOLIDS + for (auto& li : tracker_info.m_layers) + { + VUSolid* utub = new VUSolid(li.m_rin, li.m_rout, + li.m_zmin, li.m_zmax, + li.m_is_barrel, li.m_is_outer); + AddLayer(utub, li.r_mean(), li.z_mean()); + } +#else + // XXMT4D What do we do here? + fprintf(stderr, "Geometry::BuildFromTrackerInfo only supported for SimpleGeometry.\n"); + exit(1); +#endif +} diff --git a/Geometry.h b/Geometry.h index 34c359557eb4f..a9a73f6a3a5bc 100644 --- a/Geometry.h +++ b/Geometry.h @@ -10,13 +10,16 @@ #include "SimpleGeom.h" #endif +class TrackerInfo; + // XXXX MT: What it the purpose of zPlanes? // I guess this is half-baked and we actually need two add layer // methods, like AddBarellLayer(), AddEndcapLayer(). // And probably something even more descriptive, so we can also // build navigation LUTs (or something). -class Geometry { +class Geometry +{ public: ~Geometry() { for (auto& s : solids_) { delete s; }} void AddLayer(const VUSolid* s) { solids_.push_back(s); } @@ -25,17 +28,23 @@ class Geometry { } int CountLayers() const { return solids_.size(); } const VUSolid* Layer(int l) const { return solids_.at(l); } + int LayerOfSolid(const VUSolid *s) const; float Radius(int l) const { return radii_.at(l); } float zPlane(int l) const { return zPlanes_.at(l); } VUSolid::EnumInside Inside (const UVector3 &aPoint) const; int LayerIndex(const UVector3 &aPoint) const; const VUSolid* InsideWhat(const UVector3 &aPoint) const; - double SafetyFromInside ( const UVector3 &aPoint, bool aAccurate=false) const; - double SafetyFromOutside( const UVector3 &aPoint, bool aAccurate=false) const; + double SafetyFromInside ( const UVector3 &aPoint, bool aAccurate=false) const; + double SafetyFromOutside ( const UVector3 &aPoint, bool aAccurate=false) const; + double SafetyFromOutside2( const UVector3 &aPoint, double ctgTheta, int skip_layer, int &layer, bool aAccurate=false) const; Geometry clone() const; + + void BuildFromTrackerInfo(const TrackerInfo& tracker_info); + private: std::vector solids_; std::vector radii_; std::vector zPlanes_; }; + #endif diff --git a/Hit.cc b/Hit.cc index 3cb8032fa6421..b6205a4313583 100644 --- a/Hit.cc +++ b/Hit.cc @@ -3,3 +3,14 @@ void MCHitInfo::reset() { } + +void print(std::string label, const MeasurementState& s) +{ + std::cout << label << std::endl; + std::cout << "x: " << s.parameters()[0] + << " y: " << s.parameters()[1] + << " z: " << s.parameters()[2] << std::endl + << "errors: " << std::endl; + dumpMatrix(s.errors()); + std::cout << std::endl; +} diff --git a/Hit.h b/Hit.h index 3ad697e44d23f..ca13caa12d0f5 100644 --- a/Hit.h +++ b/Hit.h @@ -285,4 +285,7 @@ typedef std::array PairIdx; typedef std::vector PairIdxVec; typedef std::array TripletIdx; typedef std::vector TripletIdxVec; + +void print(std::string label, const MeasurementState& s); + #endif diff --git a/Makefile.config b/Makefile.config index 14de219777df2..a1385fd11ede9 100644 --- a/Makefile.config +++ b/Makefile.config @@ -160,6 +160,10 @@ else VEC_HOST := ${VEC_GCC} endif +ifeq ($(CXX), g++) + CXXFLAGS += -fdiagnostics-color=always +endif + ifdef WITH_USOLIDS CPPFLAGS += -DWITH_USOLIDS LIBUSOLIDS := USolids-host/libusolids.a diff --git a/Propagation.cc b/Propagation.cc index e69cd5194de4f..8238233d56320 100644 --- a/Propagation.cc +++ b/Propagation.cc @@ -43,8 +43,13 @@ TrackState propagateLineToR(const TrackState& inputState, float r) { return result; } -struct HelixState { - HelixState(TrackState& s, const bool useParamBfield = false) : state(s) { +//============================================================================== + +struct HelixState +{ + HelixState(TrackState& s, const bool useParamBfield = false) : + state(s) + { setCoords(s.parameters); setHelixPar(s,useParamBfield); } @@ -68,13 +73,13 @@ struct HelixState { //p=0.3Br => r=p/(0.3*B) k = charge*100./(-Config::sol*(useParamBfield?Config::BfieldFromZR(z,r0):Config::Bfield)); - curvature = pt*k; //in cm - ctgTheta=pz/pt; + curvature = pt * k; //in cm + ctgTheta = pz / pt; //variables to be updated at each iterations //derivatives initialized to value for first iteration, i.e. distance = r-r0in - dTDdx = r0>0. ? -x/r0 : 0.; - dTDdy = r0>0. ? -y/r0 : 0.; + dTDdx = r0 > 0. ? -x/r0 : 0.; + dTDdy = r0 > 0. ? -y/r0 : 0.; dTDdpx = 0.; dTDdpy = 0.; } @@ -93,7 +98,10 @@ struct HelixState { void HelixState::updateHelix(float distance, bool updateDeriv, bool debug) { + // NOTE: Distance is sort-of radial distance (cord length, not curve). + const float angPath = distance/curvature; + dprint("angPath=" << angPath); const float cosAP = cos(angPath); const float sinAP = sin(angPath); @@ -115,8 +123,8 @@ void HelixState::updateHelix(float distance, bool updateDeriv, bool debug) << " py: " << py*cosAP+px*sinAP << " pz: " << pz); - if (updateDeriv) { - + if (updateDeriv) + { //update derivatives on total distance for next step, where totalDistance+=r-r0 //now r0 depends on px and py const float r0inv = 1./r0; @@ -143,31 +151,33 @@ void HelixState::updateHelix(float distance, bool updateDeriv, bool debug) dTDdpy -= r0inv*(x*dxdpy + y*dydpy); } - dprint(par.At(0) << " " << par.At(1) << " " << par.At(2) << std::endl + dprint(par.At(0) << " " << par.At(1) << " " << par.At(2) << "; r = " << std::hypot(par.At(0), par.At(1)) << std::endl << par.At(3) << " " << par.At(4) << " " << par.At(5)); } void HelixState::propagateErrors(const HelixState& in, float totalDistance, bool debug) { - const float TD=totalDistance; - const float TP=totalDistance/curvature; - const float C=curvature; + // NOTE: Distance is sort-of radial distance (cord length, not curve). + + const float TD = totalDistance; + const float TP = totalDistance/curvature; + const float C = curvature; #ifdef DEBUG SVector6& par = state.parameters; dprint("TD=" << TD << " TP=" << TP << " arrived at r=" << sqrt(par.At(0)*par.At(0)+par.At(1)*par.At(1))); #endif - const float dCdpx = k*in.px/pt; - const float dCdpy = k*in.py/pt; + const float dCdpx = k*in.px/pt; + const float dCdpy = k*in.py/pt; - const float dTPdx = dTDdx/C; - const float dTPdy = dTDdy/C; + const float dTPdx = dTDdx/C; + const float dTPdy = dTDdy/C; const float dTPdpx = (dTDdpx*C - TD*dCdpx)/(C*C); const float dTPdpy = (dTDdpy*C - TD*dCdpy)/(C*C); - const float cosTP = cos(TP); - const float sinTP = sin(TP); + const float cosTP = cos(TP); + const float sinTP = sin(TP); //derive these to compute jacobian //x = xin + k*(pxin*sinTP-pyin*(1-cosTP)); @@ -214,14 +224,19 @@ void HelixState::propagateErrors(const HelixState& in, float totalDistance, bool dcall(dumpMatrix(state.errors)); } +//============================================================================== + // helix propagation in steps along helix trajectory, several versions // for track with pT>=1 GeV this converges to the correct path lenght in <5 iterations // derivatives need to be updated at each iteration // Propagate to the next obj // each step travels for a path length equal to the safe step between the current position and the nearest object. -TrackState propagateHelixToNextSolid(TrackState inputState, const Geometry& geom, const bool useParamBfield) { - bool debug = false; + +TrackState propagateHelixToNextSolid(TrackState inputState, const Geometry& geom, + const bool useParamBfield) +{ + bool debug = true; const HelixState hsin(inputState,useParamBfield); TrackState result(inputState); @@ -238,9 +253,10 @@ TrackState propagateHelixToNextSolid(TrackState inputState, const Geometry& geom auto startSolid = geom.InsideWhat(UVector3(hsin.x,hsin.y,hsin.z)); // have we scattered out of the solid? - if (hsin.r0 > 1.0 && !startSolid) { + if (hsin.r0 > 1.0 && ! startSolid) + { UVector3 here(hsin.x,hsin.y,hsin.z); - for ( int i = 0; i < Config::nLayers; ++i ) { + for ( int i = 0; i < Config::nTotalLayers; ++i ) { auto d = geom.Layer(i)->SafetyFromOutside(here, true); if (d < tolerance) { startSolid = geom.Layer(i); @@ -256,16 +272,44 @@ TrackState propagateHelixToNextSolid(TrackState inputState, const Geometry& geom } } + // previous closest distance and solid + double prev_distance; + int prev_solid; + int skip_solid = geom.LayerOfSolid(startSolid); - for (unsigned int i=0;iis_barrel_ ? + tolerance : tolerance / std::abs(hsout.ctgTheta)); + + if (i > 0) + { + if (solid == prev_solid) + { + if (distance > prev_distance) + { + skip_solid = solid; + dprint(" repropagating with skipped layer " << solid); + goto redo_safety; + } + } + } + prev_distance = distance; + prev_solid = solid; + totalDistance += distance; dprint("r0=" << hsout.r0 << " pt=" << hsout.pt << std::endl << "distance=" << distance); - const bool updateDeriv = i+1!=Config::Niter && hsout.r0>0.; + const bool updateDeriv = (i+1 != Config::NiterSim && hsout.r0 > 0.); hsout.updateHelix(distance, updateDeriv, debug); hsout.setCoords(hsout.state.parameters); @@ -276,7 +320,7 @@ TrackState propagateHelixToNextSolid(TrackState inputState, const Geometry& geom break; } - if ( i == (Config::Niter-1) ) { + if ( i == (Config::NiterSim - 1) ) { std::cerr << __FILE__ << ":" << __LINE__ << ": failed to converge in propagateHelixToNextSolid() after " << (i+1) << " iterations, " << distance @@ -290,6 +334,10 @@ TrackState propagateHelixToNextSolid(TrackState inputState, const Geometry& geom return hsout.state; } +//============================================================================== + +// XXMT4K The following is only used in buildtest.cc, maybe obsolete? + // Propagate to the next obj // each step travels for a path length equal to the safe step between the current position and the nearest object. TrackState propagateHelixToLayer(TrackState inputState, int layer, const Geometry& geom, const bool useParamBfield) { diff --git a/Propagation.h b/Propagation.h index 1278009770199..d0ba55f0b41d8 100644 --- a/Propagation.h +++ b/Propagation.h @@ -3,7 +3,6 @@ #include "Track.h" #include "Geometry.h" -#include "Matrix.h" // line propagation from state radius to hit radius // assuming radial direction (i.e. origin at (0,0)) diff --git a/SimpleGeom.h b/SimpleGeom.h index 41f2885c10bb6..ef3879b06d77a 100644 --- a/SimpleGeom.h +++ b/SimpleGeom.h @@ -55,8 +55,10 @@ class VUSolid public: enum EnumInside { eInside=0, eSurface=1, eOutside=2 }; - VUSolid(double rin, double rout, double zmin, double zmax) : - rin_(rin), rout_(rout), zmin_(zmin), zmax_(zmax) + VUSolid(double rin, double rout, double zmin, double zmax, + bool is_barrel, bool is_outer) : + rin_(rin), rout_(rout), zmin_(zmin), zmax_(zmax), + is_barrel_(is_barrel), is_outer_(is_outer) {} EnumInside Inside (const UVector3 &aPoint) const; @@ -64,10 +66,12 @@ class VUSolid double SafetyFromOutside(const UVector3 &aPoint, bool aAccurate=false) const; bool Normal(const UVector3& aPoint, UVector3 &aNormal) const; - VUSolid* Clone() const {return new VUSolid(rin_, rout_, zmin_, zmax_);} + VUSolid* Clone() const {return new VUSolid(rin_, rout_, zmin_, zmax_, is_barrel_, is_outer_);} - double rin_, rout_; + double rin_, rout_; double zmin_, zmax_; + bool is_barrel_; + bool is_outer_; }; #endif diff --git a/Simulation.cc b/Simulation.cc index 86bb3eade29ad..00f167525058c 100644 --- a/Simulation.cc +++ b/Simulation.cc @@ -9,16 +9,16 @@ #define SCATTER_XYZ void setupTrackByToyMC(SVector3& pos, SVector3& mom, SMatrixSym66& covtrk, - HitVec& hits, Event& ev, int itrack, - int& charge, const Geometry& geom, TSVec & initTSs) + HitVec& hits, MCHitInfoVec& hitinfos, Event& ev, + int itrack, int& charge, + const Geometry& geom, TSVec& initTSs) { - MCHitInfoVec& initialhitinfo(ev.simHitsInfo_); - #ifdef DEBUG bool debug = true; #endif - float pt = Config::minSimPt+g_unif(g_gen)*(Config::maxSimPt-Config::minSimPt);//this input, 0.5Normal(init_point, init_xprime); - + if ( ! init_good ) { std::cerr << __FILE__ << ":" << __LINE__ << ": failed to find normal vector at " << init_point <is_outer_) + { + dprintf("Outer layer reached, track finished.\n"); + break; + } } // end loop over nHitsPerTrack } @@ -357,9 +377,9 @@ void setupTrackByToyMCEndcap(SVector3& pos, SVector3& mom, SMatrixSym66& covtrk, hits.reserve(Config::nTotHit); initTSs.reserve(Config::nTotHit); - int layer_counts[Config::nLayers]; - for (int ilayer=0;ilayer0.) diff --git a/Simulation.h b/Simulation.h index 2ca7ab7faaa95..d2d5d85b711a6 100644 --- a/Simulation.h +++ b/Simulation.h @@ -8,7 +8,8 @@ class Event; -void setupTrackByToyMC(SVector3& pos, SVector3& mom, SMatrixSym66& covtrk, HitVec& hits, Event& ev, +void setupTrackByToyMC(SVector3& pos, SVector3& mom, SMatrixSym66& covtrk, + HitVec& hits, MCHitInfoVec& hitinfos, Event& ev, int itrack, int& charge, const Geometry&, TSVec& initTSs); void setupTrackByToyMCEndcap(SVector3& pos, SVector3& mom, SMatrixSym66& covtrk, HitVec& hits, Event& ev, diff --git a/Track.cc b/Track.cc index a398a7dfea56d..a12544cbea9a6 100644 --- a/Track.cc +++ b/Track.cc @@ -106,3 +106,30 @@ void TrackExtra::setMCTrackIDInfo(const Track& trk, const std::vector& l } dprint("Track " << trk.label() << " best mc track " << mtrk << " count " << mcount << "/" << trk.nFoundHits()); } + +//============================================================================== + +void print(const TrackState& s) +{ + std::cout << " x: " << s.parameters[0] + << " y: " << s.parameters[1] + << " z: " << s.parameters[2] << std::endl + << " px: " << s.parameters[3] + << " py: " << s.parameters[4] + << " pz: " << s.parameters[5] << std::endl + << "valid: " << s.valid << " errors: " << std::endl; + dumpMatrix(s.errors); + std::cout << std::endl; +} + +void print(std::string label, int itrack, const Track& trk) +{ + std::cout << std::endl << label << ": " << itrack << " hits: " << trk.nFoundHits() << " State" << std::endl; + print(trk.state()); +} + +void print(std::string label, const TrackState& s) +{ + std::cout << label << std::endl; + print(s); +} diff --git a/Track.h b/Track.h index c51e105e01de4..2854239c04e64 100644 --- a/Track.h +++ b/Track.h @@ -4,10 +4,11 @@ #include "Hit.h" #include "Matrix.h" #include "Config.h" + #include typedef std::pair SimTkIDInfo; -typedef std::vector HitIdxVec; +typedef std::vector HitIdxVec; inline int calculateCharge(const Hit & hit0, const Hit & hit1, const Hit & hit2){ return ((hit2.y()-hit0.y())*(hit2.x()-hit1.x())>(hit2.y()-hit1.y())*(hit2.x()-hit0.x())?1:-1); @@ -284,7 +285,7 @@ class Track private: TrackState state_; float chi2_ = 0.; - int hitIdxArr_[Config::nLayers]; + int hitIdxArr_[Config::nTotHit]; int hitIdxPos_ = -1; int nGoodHitIdx_ = 0; int label_ = -1; @@ -325,4 +326,8 @@ typedef std::unordered_map TkIDToTSMap; typedef std::unordered_map TkIDToTSVecMap; typedef std::unordered_map TkIDToTSLayerPairVecMap; +void print(const TrackState& s); +void print(std::string label, int itrack, const Track& trk); +void print(std::string label, const TrackState& s); + #endif diff --git a/main.cc b/main.cc index 027047649bb07..665fad3a6118c 100644 --- a/main.cc +++ b/main.cc @@ -75,7 +75,7 @@ void initGeom(Geometry& geom) for (int l = 0; l < Config::nLayers; l++) { float r = (l+1)*Config::fRadialSpacing; float z = r / std::tan(2.0*std::atan(std::exp(-Config::fEtaDet))); // calculate z extent based on eta, r - VUSolid* utub = new VUSolid(r, r+Config::fRadialExtent, -z, z); + VUSolid* utub = new VUSolid(r, r+Config::fRadialExtent, -z, z, true, l + 1 == Config::nLayers); geom.AddLayer(utub, r, z); } } diff --git a/mkFit/Makefile b/mkFit/Makefile index cdb88e5d8d055..3c6083064dad6 100644 --- a/mkFit/Makefile +++ b/mkFit/Makefile @@ -57,7 +57,7 @@ echo: ################################################################ # Should be a lib, really -ABOVE_OBJS := $(patsubst %, ../%.o, Config Matrix Event Hit Track Propagation KalmanUtils Simulation Geometry SimpleGeom fittest buildtest ConformalUtils seedtest BinInfoUtils TTreeValidation Validation) +ABOVE_OBJS := $(patsubst %, ../%.o, Config Matrix Event Hit Track Propagation KalmanUtils Simulation Geometry SimpleGeom fittest buildtest ConformalUtils seedtest BinInfoUtils TTreeValidation Validation TrackerInfo CylCowWLids) ${ABOVE_OBJS}: ${MAKE} -C .. diff --git a/mkFit/mkFit.cc b/mkFit/mkFit.cc index e0e187b51e0dc..fcf91b74deec6 100644 --- a/mkFit/mkFit.cc +++ b/mkFit/mkFit.cc @@ -19,6 +19,8 @@ #include "MaterialEffects.h" +#include "CylCowWLids.h" + #ifndef NO_ROOT #include "Validation.h" #endif @@ -47,26 +49,41 @@ void initGeom(Geometry& geom) // NB: we currently assume that each node is a layer, and that layers // are added starting from the center // NB: z is just a dummy variable, VUSolid is actually infinite in size. *** Therefore, set it to the eta of simulation *** - float eta = 2.0; // can tune this to whatever geometry required (one can make this layer dependent as well) - for (int l = 0; l < Config::nLayers; l++) + + if ( ! Config::endcapTest && ! Config::useCMSGeom) { - if (Config::endcapTest) - { - float z = Config::useCMSGeom ? Config::cmsAvgZs[l] : (l+1)*10.;//Config::fLongitSpacing - float rmin = Config::useCMSGeom ? Config::cmsDiskMinRs[l] : 0; - float rmax = Config::useCMSGeom ? Config::cmsDiskMaxRs[l] : 0; - // XXXX MT: Do we need endcap layer "thickness" for cmssw at all? Use something. - // Do we even need geometry for cmssw? - float dz = 0.5; - VUSolid* utub = new VUSolid(rmin, rmax, z - dz, z + dz); - geom.AddLayer(utub, rmin, z); - } - else + // This is the new standalone case -- Cylindrical Cow with Lids + Create_TrackerInfo(Config::TrkInfo); +#ifndef WITH_USOLIDS + geom.BuildFromTrackerInfo(Config::TrkInfo); +#else + fprintf(stderr, "Cylindrical Cow with Lids only supported for SimpleGeometry.\n"); + exit(1); +#endif + } + else + { + float eta = 2.0; // can tune this to whatever geometry required (one can make this layer dependent as well) + for (int l = 0; l < Config::nLayers; l++) { - float r = Config::useCMSGeom ? Config::cmsAvgRads[l] : (l+1)*Config::fRadialSpacing; - float z = r / std::tan(2.0*std::atan(std::exp(-eta))); // calculate z extent based on eta, r - VUSolid* utub = new VUSolid(r, r+Config::fRadialExtent, -z, z); - geom.AddLayer(utub, r, z); + if (Config::endcapTest) + { + float z = Config::useCMSGeom ? Config::cmsAvgZs[l] : (l+1)*10.;//Config::fLongitSpacing + float rmin = Config::useCMSGeom ? Config::cmsDiskMinRs[l] : 0; + float rmax = Config::useCMSGeom ? Config::cmsDiskMaxRs[l] : 0; + // XXXX MT: Do we need endcap layer "thickness" for cmssw at all? Use equiv of fRadialExtent. + // Do we even need geometry for cmssw? + float dz = 0.005; + VUSolid* utub = new VUSolid(rmin, rmax, z - dz, z + dz, false, l + 1 == Config::nLayers); + geom.AddLayer(utub, rmin, z); + } + else + { + float r = Config::useCMSGeom ? Config::cmsAvgRads[l] : (l+1)*Config::fRadialSpacing; + float z = r / std::tan(2.0*std::atan(std::exp(-eta))); // calculate z extent based on eta, r + VUSolid* utub = new VUSolid(r, r+Config::fRadialExtent, -z, z, true, l + 1 == Config::nLayers); + geom.AddLayer(utub, r, z); + } } } } From f4ef5273763ad858eb69f80b9c1127e11bba0d0c Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Thu, 23 Feb 2017 09:47:32 -0800 Subject: [PATCH 005/172] Get consolidated tracking to work in the barrel. * HitStructures - remove barrel/encap code duplication: - Z and R replaced with agnostic variable Q; - knock-on changes in MkFitter using Z/R explicitly. * EventOfHits is passed TrackerInfo& to construct LayerOfHits structs. * MkBuilder - use TrackerInfo to determine layer loop ranges and exit conditions (for BH, STD and CE). Next steps: - change storage of hit-indices-on-track in Track; - remove multiple hit arrays in MkFitter (done in part on branch fit-cont-slurp); - change how hits are loaded into MkFitter for hit matching and update (now they get placed on hit-index position (actually, layer index - hence the problem)). --- Config.cc | 2 + Config.h | 4 +- CylCowWLids.cc | 63 ++++---- CylCowWLids.h | 18 ++- Event.cc | 1 + Event.h | 6 +- Geometry.cc | 2 + Simulation.cc | 2 +- Track.cc | 2 +- mkFit/HitStructures.cc | 309 +++++++++++++++------------------------ mkFit/HitStructures.h | 94 ++++-------- mkFit/MkBuilder.cc | 113 +++++++++----- mkFit/MkBuilderEndcap.cc | 5 +- mkFit/MkFitter.cc | 16 +- mkFit/mkFit.cc | 6 +- mkFit/mt-notes.txt | 70 +++++---- test/CylCowWLids.C | 85 +++++++++++ 17 files changed, 424 insertions(+), 374 deletions(-) create mode 100644 test/CylCowWLids.C diff --git a/Config.cc b/Config.cc index 35283300312cf..e9338931bc991 100644 --- a/Config.cc +++ b/Config.cc @@ -1,5 +1,7 @@ #include "Config.h" +#include "TrackerInfo.h" + namespace Config { TrackerInfo TrkInfo; diff --git a/Config.h b/Config.h index 3e612241e3d87..82aed05b52e61 100644 --- a/Config.h +++ b/Config.h @@ -2,7 +2,7 @@ #define _config_ // Cram this in here for now ... -#include "TrackerInfo.h" +class TrackerInfo; #include #include @@ -148,7 +148,7 @@ namespace Config constexpr float maxSimPt = 10.; constexpr float minSimEta = 0.0; // XXMT4K Added min, too. - constexpr float maxSimEta = 2.4; // Should both become config vars? + constexpr float maxSimEta = 0.9;//2.4; // Should both become config vars? constexpr float hitposerrXY = 0.01; // resolution is 100um in xy --> more realistic scenario is 0.003 constexpr float hitposerrZ = 0.1; // resolution is 1mm in z diff --git a/CylCowWLids.cc b/CylCowWLids.cc index 600d33f70b846..40ca9439f9188 100644 --- a/CylCowWLids.cc +++ b/CylCowWLids.cc @@ -1,12 +1,31 @@ #include "CylCowWLids.h" -#include "Config.h" #include "TrackerInfo.h" #include namespace { + float getTheta(float r, float z) + { + return std::atan2(r,z); + } + + float getEta(float r, float z) + { + return -1.0f * std::log( std::tan(getTheta(r,z)/2.0f) ); + } + + float getEta(float theta) + { + return -1.0f * std::log( std::tan(theta/2.0f) ); + } + + float getTgTheta(float eta) + { + return std::tan(2.0*std::atan(std::exp(-eta))); + } + class CylCowWLidsCreator { TrackerInfo &m_trkinfo; @@ -17,26 +36,6 @@ namespace int m_n_endcap = 9; int m_first_ecap = 10; - inline float getTheta(float r, float z) - { - return std::atan2(r,z); - } - - inline float getEta(float r, float z) - { - return -1.0f * std::log( std::tan(getTheta(r,z)/2.0f) ); - } - - inline float getEta(float theta) - { - return -1.0f * std::log( std::tan(theta/2.0f) ); - } - - inline float getTgTheta(float eta) - { - return std::tan(2.0*std::atan(std::exp(-eta))); - } - //------------------------------------------------------------------------------ void add_barrel(int lid, float r, float z, float eta) @@ -121,7 +120,10 @@ namespace void FillTrackerInfo() { + // Actual coverage for tracks with z = 3cm is 2.4 float full_eta = 2.5; + float full_eta_pix_0 = 2.55; // To account for BS z-spread + float full_eta_ec_in[] = { 0, 2.525, 2.515 }; float pix_0 = 4, pix_sep = 6; float pix_z0 = 24, pix_zgrow = 6; @@ -141,7 +143,7 @@ namespace for (int i = 0; i < 9; ++i) m_trkinfo.new_ecap_pos_layer(); for (int i = 0; i < 9; ++i) m_trkinfo.new_ecap_neg_layer(); - add_barrel_r_eta(0, pix_0, full_eta); + add_barrel_r_eta(0, pix_0, full_eta_pix_0); add_barrel_r_z (1, pix_0 + 1 * pix_sep, pix_z0 + 1 * pix_zgrow); add_barrel_r_z (2, pix_0 + 2 * pix_sep, pix_z0 + 2 * pix_zgrow); @@ -156,7 +158,7 @@ namespace add_endcap(9 + i, pix_0 + i * pix_sep + pix_ec_rextra, pix_z0 + i * pix_zgrow + pix_ec_zgap, - full_eta); + full_eta_ec_in[i]); } for (int i = 0; i < 7; ++i) { @@ -172,15 +174,20 @@ namespace //============================================================================== -void Create_TrackerInfo(TrackerInfo& ti) +void Create_TrackerInfo(TrackerInfo& ti, bool verbose) { CylCowWLidsCreator creator(ti); creator.FillTrackerInfo(); - printf("==========================================================================================\n"); + if (verbose) { + printf("==========================================================================================\n"); + } printf("CylCowWLids -- Create_TrackerInfo finished\n"); - printf("==========================================================================================\n"); - for (auto &i : ti.m_layers) i.print_layer(); - printf("==========================================================================================\n"); + + if (verbose) { + printf("==========================================================================================\n"); + for (auto &i : ti.m_layers) i.print_layer(); + printf("==========================================================================================\n"); + } } diff --git a/CylCowWLids.h b/CylCowWLids.h index 20830ee041001..c2e347a05ec2f 100644 --- a/CylCowWLids.h +++ b/CylCowWLids.h @@ -3,8 +3,24 @@ class TrackerInfo; +// Cylindrical Cow with Lids +// +// Intended coverage: |eta| < 2.4 with D_z_beam_spot = +-3 cm (3 sigma) +// B-layer extends to 2.55. +// Layers 1 and 2 have somewhat longer barrels. It is assumed +// those will be needed / used for seed finding. +// +// Layers 3 - 9: +// Barrel: 0.0 - 1.0 +// Transition: 1.0 - 1.4 +// Endcap: 1.4 - 2.4 +// +// Run root test/CylCowWLids.C to get a plot and dumps of +// edge coordinates and etas. + + // This could be translated into plugin -void Create_TrackerInfo(TrackerInfo& ti); +void Create_TrackerInfo(TrackerInfo& ti, bool verbose=false); #endif diff --git a/Event.cc b/Event.cc index 97b5f0f2e6291..a728e5127a0c5 100644 --- a/Event.cc +++ b/Event.cc @@ -1,4 +1,5 @@ #include "Event.h" + #include "Simulation.h" #include "KalmanUtils.h" #include "seedtest.h" diff --git a/Event.h b/Event.h index e736758ce5403..6a6b7b5236b3f 100644 --- a/Event.h +++ b/Event.h @@ -41,9 +41,11 @@ class Event const Geometry& geom_; Validation& validation_; - private: + +private: int evtID_; - public: + +public: int threads_; std::mutex mcGatherMutex_; std::atomic mcHitIDCounter_; diff --git a/Geometry.cc b/Geometry.cc index 86021253c1643..7f87458d75153 100644 --- a/Geometry.cc +++ b/Geometry.cc @@ -107,6 +107,8 @@ Geometry Geometry::clone() const //============================================================================== +#include "TrackerInfo.h" + void Geometry::BuildFromTrackerInfo(const TrackerInfo& tracker_info) { #ifndef WITH_USOLIDS diff --git a/Simulation.cc b/Simulation.cc index 00f167525058c..5ffa48311ca3c 100644 --- a/Simulation.cc +++ b/Simulation.cc @@ -41,7 +41,7 @@ void setupTrackByToyMC(SVector3& pos, SVector3& mom, SMatrixSym66& covtrk, // Should we just remove the flat pz option? Or fix it ... #ifdef GENFLATETA // this generates flat in eta - + float eta = Config::minSimEta + (Config::maxSimEta - Config::minSimEta) * g_unif(g_gen); float pz = pt*(1./(std::tan(2*std::atan(std::exp(-eta))))); if (g_unif(g_gen) > 0.5) pz *= -1.; diff --git a/Track.cc b/Track.cc index a12544cbea9a6..1193f1ae1b567 100644 --- a/Track.cc +++ b/Track.cc @@ -111,7 +111,7 @@ void TrackExtra::setMCTrackIDInfo(const Track& trk, const std::vector& l void print(const TrackState& s) { - std::cout << " x: " << s.parameters[0] + std::cout << " x: " << s.parameters[0] << " y: " << s.parameters[1] << " z: " << s.parameters[2] << std::endl << " px: " << s.parameters[3] diff --git a/mkFit/HitStructures.cc b/mkFit/HitStructures.cc index 529be161d9683..72ee7c235f2d8 100644 --- a/mkFit/HitStructures.cc +++ b/mkFit/HitStructures.cc @@ -1,49 +1,58 @@ #include "HitStructures.h" #include "BinInfoUtils.h" +#include "TrackerInfo.h" #include "Ice/IceRevisitedRadix.h" -void LayerOfHits::SetupLayer(float zmin, float zmax, float dz) +void LayerOfHits::SetupLayer(float qmin, float qmax, float dq, bool is_barrel) { // XXXX MT: Could have n_phi bins per layer, too. - assert (m_nz == 0 && "SetupLayer() already called."); + assert (m_nq == 0 && "SetupLayer() already called."); - float nmin = std::floor(zmin / dz); - float nmax = std::ceil (zmax / dz); - m_zmin = dz * nmin; - m_zmax = dz * nmax; - m_fz = 1.0f / dz; // zbin = (zhit - m_zmin) * m_fz; - m_nz = nmax - nmin; + m_is_barrel = is_barrel; - m_phi_bin_infos.resize(m_nz); - for (int i = 0; i < m_nz; ++i) m_phi_bin_infos[i].resize(Config::m_nphi); + // Realign qmin/max on "global" dq boundaries. + // This might not be the best strategy, esp. for large bins. + // Could have instead: + // a) extra space on each side; + // b) pass in number of bins. + + float nmin = std::floor(qmin / dq); + float nmax = std::ceil (qmax / dq); + m_qmin = dq * nmin; + m_qmax = dq * nmax; + m_fq = 1.0f / dq; // qbin = (q_hit - m_qmin) * m_fq; + m_nq = nmax - nmin; + + m_phi_bin_infos.resize(m_nq); + for (int i = 0; i < m_nq; ++i) m_phi_bin_infos[i].resize(Config::m_nphi); } void LayerOfHits::SuckInHits(const HitVec &hitv) { // This is now in SetupLayer() // // should be layer dependant - // float dz = 0.5; + // float dq = 0.5; // // should know this from geom. - // //m_zmin = 1000; - // //m_zmax = -1000; + // //m_qmin = 1000; + // //m_qmax = -1000; // for (auto const &h : hitv) // { - // if (h.z() < m_zmin) m_zmin = h.z(); - // if (h.z() > m_zmax) m_zmax = h.z(); + // if (h.q() < m_qmin) m_qmin = h.q(); + // if (h.q() > m_qmax) m_qmax = h.q(); // } - // printf("LoH::SuckInHits zmin=%f, zmax=%f", m_zmin, m_zmax); - // float nmin = std::floor(m_zmin / dz); - // float nmax = std::ceil (m_zmax / dz); - // m_zmin = dz * nmin; - // m_zmax = dz * nmax; - // int nz = nmax - nmin; - // int nzh = nz / 2; - // m_fz = 1.0f / dz; // zbin = (zhit - m_zmin) * m_fz; - // printf(" -> zmin=%f, zmax=%f, nz=%d, fz=%f\n", m_zmin, m_zmax, nz, m_fz); - - assert (m_nz > 0 && "SetupLayer() was not called."); + // printf("LoH::SuckInHits qmin=%f, qmax=%f", m_qmin, m_qmax); + // float nmin = std::floor(m_qmin / dq); + // float nmax = std::ceil (m_qmax / dq); + // m_qmin = dq * nmin; + // m_qmax = dq * nmax; + // int nq = nmax - nmin; + // int nqh = nq / 2; + // m_fq = 1.0f / dq; // qbin = (qhit - m_qmin) * m_fq; + // printf(" -> qmin=%f, qmax=%f, nq=%d, fq=%f\n", m_qmin, m_qmax, nq, m_fq); + + assert (m_nq > 0 && "SetupLayer() was not called."); const int size = hitv.size(); @@ -53,30 +62,30 @@ void LayerOfHits::SuckInHits(const HitVec &hitv) alloc_hits(1.02 * size); } -#ifndef LOH_USE_PHI_Z_ARRAYS +#ifndef LOH_USE_PHI_Q_ARRAYS std::vector m_hit_phis(size); #endif struct HitInfo { float phi; - float z; - int zbin; + float q; + int qbin; }; std::vector ha(size); - std::vector zc(m_nz, 0); - int nzh = m_nz / 2; + std::vector qc(m_nq, 0); + int nqh = m_nq / 2; { int i = 0; for (auto const &h : hitv) { HitInfo &hi = ha[i]; hi.phi = h.phi(); - hi.z = h.z(); - hi.zbin = std::max(std::min(static_cast((hi.z - m_zmin) * m_fz), m_nz-1), 0); - m_hit_phis[i] = hi.phi + 6.3f * (hi.zbin - nzh); - ++zc[hi.zbin]; + hi.q = m_is_barrel ? h.z() : h.r(); + hi.qbin = std::max(std::min(static_cast((hi.q - m_qmin) * m_fq), m_nq - 1), 0); + m_hit_phis[i] = hi.phi + 6.3f * (hi.qbin - nqh); + ++qc[hi.qbin]; ++i; } } @@ -84,7 +93,7 @@ void LayerOfHits::SuckInHits(const HitVec &hitv) RadixSort sort; sort.Sort(&m_hit_phis[0], size); - int curr_z_bin = 0; + int curr_q_bin = 0; int curr_phi_bin = 0; int hits_in_bin = 0; int hit_count = 0; @@ -93,25 +102,33 @@ void LayerOfHits::SuckInHits(const HitVec &hitv) { int j = sort.GetRanks()[i]; + // XXXX MT: Endcap has special check - try to get rid of this! + if ( ! m_is_barrel && (hitv[j].r() > m_qmax || hitv[j].r() < m_qmin)) + { + std::cout << "WARNING: hit outsed r boundary of disk, please fixme" << std::endl; + m_capacity--; + continue; + } + // Could fix the mis-sorts. Set ha size to size + 1 and fake last entry to avoid ifs. memcpy(&m_hits[i], &hitv[j], sizeof(Hit)); -#ifdef LOH_USE_PHI_Z_ARRAYS +#ifdef LOH_USE_PHI_Q_ARRAYS m_hit_phis[i] = ha[j].phi; - m_hit_zs [i] = ha[j].z; + m_hit_qs [i] = ha[j].q; #endif // Fill the bin info - if (ha[j].zbin != curr_z_bin) + if (ha[j].qbin != curr_q_bin) { - set_phi_bin(curr_z_bin, curr_phi_bin, hit_count, hits_in_bin); + set_phi_bin(curr_q_bin, curr_phi_bin, hit_count, hits_in_bin); - empty_phi_bins(curr_z_bin, curr_phi_bin + 1, Config::m_nphi, hit_count); + empty_phi_bins(curr_q_bin, curr_phi_bin + 1, Config::m_nphi, hit_count); - empty_z_bins(curr_z_bin + 1, ha[j].zbin, hit_count); + empty_q_bins(curr_q_bin + 1, ha[j].qbin, hit_count); - curr_z_bin = ha[j].zbin; + curr_q_bin = ha[j].qbin; curr_phi_bin = 0; } @@ -119,9 +136,9 @@ void LayerOfHits::SuckInHits(const HitVec &hitv) if (phi_bin > curr_phi_bin) { - set_phi_bin(curr_z_bin, curr_phi_bin, hit_count, hits_in_bin); + set_phi_bin(curr_q_bin, curr_phi_bin, hit_count, hits_in_bin); - empty_phi_bins(curr_z_bin, curr_phi_bin + 1, phi_bin, hit_count); + empty_phi_bins(curr_q_bin, curr_phi_bin + 1, phi_bin, hit_count); curr_phi_bin = phi_bin; } @@ -129,11 +146,11 @@ void LayerOfHits::SuckInHits(const HitVec &hitv) ++hits_in_bin; } - set_phi_bin(curr_z_bin, curr_phi_bin, hit_count, hits_in_bin); + set_phi_bin(curr_q_bin, curr_phi_bin, hit_count, hits_in_bin); - empty_phi_bins(curr_z_bin, curr_phi_bin + 1, Config::m_nphi, hit_count); + empty_phi_bins(curr_q_bin, curr_phi_bin + 1, Config::m_nphi, hit_count); - empty_z_bins(curr_z_bin + 1, m_nz, hit_count); + empty_q_bins(curr_q_bin + 1, m_nq, hit_count); // Check for mis-sorts due to lost precision (not really important). // float phi_prev = 0; @@ -143,16 +160,16 @@ void LayerOfHits::SuckInHits(const HitVec &hitv) // { // int j = sort.GetRanks()[i]; // float phi = ha[j].phi; - // int zbin = ha[j].zbin; - // if (zbin == bin_prev && phi < phi_prev) + // int qbin = ha[j].qbin; + // if (qbin == bin_prev && phi < phi_prev) // { - // //printf(" Offset error: %5d %5d %10f %10f %5d %8f\n", i, j, phi, phi_prev, ha[j].zbin, hitv[j].z()); + // //printf(" Offset error: %5d %5d %10f %10f %5d %8f\n", i, j, phi, phi_prev, ha[j].qbin, hitv[j].q()); // if (prev_err_idx == i - 1) - // printf("DOUBLE Offset error: %5d %5d %10f %10f %5d %8f\n", i, j, phi, phi_prev, ha[j].zbin, hitv[j].z()); + // printf("DOUBLE Offset error: %5d %5d %10f %10f %5d %8f\n", i, j, phi, phi_prev, ha[j].qbin, hitv[j].q()); // prev_err_idx = i; // } // phi_prev = phi; - // bin_prev = zbin; + // bin_prev = qbin; // } // Print first couple @@ -160,13 +177,13 @@ void LayerOfHits::SuckInHits(const HitVec &hitv) // { // int j = sort.GetRanks()[i]; // - // printf("%3d %3d %8f %5d %8f\n", i, j, ha[j].phi, ha[j].zbin, hitv[j].z()); + // printf("%3d %3d %8f %5d %8f\n", i, j, ha[j].phi, ha[j].qbin, hitv[j].q()); // } } -void LayerOfHits::SelectHitIndices(float z, float phi, float dz, float dphi, std::vector& idcs, bool isForSeeding, bool dump) +void LayerOfHits::SelectHitIndices(float q, float phi, float dq, float dphi, std::vector& idcs, bool isForSeeding, bool dump) { - // Sanitizes z, dz and dphi. phi is expected to be in -pi, pi. + // Sanitizes q, dq and dphi. phi is expected to be in -pi, pi. // Make sure how phi bins work beyond -pi, +pi. // for (float p = -8; p <= 8; p += 0.05) @@ -175,46 +192,49 @@ void LayerOfHits::SelectHitIndices(float z, float phi, float dz, float dphi, std // printf("%5.2f %4d %4d\n", p, pb, pb & m_phi_mask); // } - if (!isForSeeding) { // seeding has set cuts for dz and dphi - if (std::abs(dz) > Config::m_max_dz) dz = Config::m_max_dz; + if ( ! isForSeeding) // seeding has set cuts for dq and dphi + { + // XXXX MT: Here I reuse Config::m_max_dz also for endcap ... those will become + // layer dependant and get stored in TrackerInfo (or copied into LayerOfHits). + if (std::abs(dq) > Config::m_max_dz) dq = Config::m_max_dz; if (std::abs(dphi) > Config::m_max_dphi) dphi = Config::m_max_dphi; } - int zb1 = GetZBinChecked(z - dz); - int zb2 = GetZBinChecked(z + dz) + 1; + int qb1 = GetQBinChecked(q - dq); + int qb2 = GetQBinChecked(q + dq) + 1; int pb1 = GetPhiBin(phi - dphi); int pb2 = GetPhiBin(phi + dphi) + 1; // int extra = 2; - // zb1 -= 2; if (zb < 0) zb = 0; - // zb2 += 2; if (zb >= m_nz) zb = m_nz; + // qb1 -= 2; if (qb < 0) qb = 0; + // qb2 += 2; if (qb >= m_nq) qb = m_nq; if (dump) printf("LayerOfHits::SelectHitIndices %6.3f %6.3f %6.4f %7.5f %3d %3d %4d %4d\n", - z, phi, dz, dphi, zb1, zb2, pb1, pb2); + q, phi, dq, dphi, qb1, qb2, pb1, pb2); // This should be input argument, well ... it will be Matriplex op, or sth. // KPM -- it is now! used for seeding - for (int zi = zb1; zi < zb2; ++zi) + for (int qi = qb1; qi < qb2; ++qi) { for (int pi = pb1; pi < pb2; ++pi) { int pb = pi & m_phi_mask; - for (int hi = m_phi_bin_infos[zi][pb].first; hi < m_phi_bin_infos[zi][pb].second; ++hi) + for (int hi = m_phi_bin_infos[qi][pb].first; hi < m_phi_bin_infos[qi][pb].second; ++hi) { // Here could enforce some furhter selection on hits -#ifdef LOH_USE_PHI_Z_ARRAYS - float ddz = std::abs(z - m_hit_zs[hi]); +#ifdef LOH_USE_PHI_Q_ARRAYS + float ddq = std::abs(q - m_hit_qs[hi]); float ddphi = std::abs(phi - m_hit_phis[hi]); if (ddphi > Config::PI) ddphi = Config::TwoPI - ddphi; if (dump) printf(" SHI %3d %4d %4d %5d %6.3f %6.3f %6.4f %7.5f %s\n", - zi, pi, pb, hi, - m_hit_zs[hi], m_hit_phis[hi], ddz, ddphi, - (ddz < dz && ddphi < dphi) ? "PASS" : "FAIL"); + qi, pi, pb, hi, + m_hit_qs[hi], m_hit_phis[hi], ddq, ddphi, + (ddq < dq && ddphi < dphi) ? "PASS" : "FAIL"); - if (ddz < dz && ddphi < dphi) + if (ddq < dq && ddphi < dphi) #endif { idcs.push_back(hi); @@ -226,148 +246,61 @@ void LayerOfHits::SelectHitIndices(float z, float phi, float dz, float dphi, std void LayerOfHits::PrintBins() { - for (int zb = 0; zb < m_nz; ++zb) + for (int qb = 0; qb < m_nq; ++qb) { - printf("Z bin %d\n", zb); + printf("%c bin %d\n", m_is_barrel ? 'Z' : 'R', qb); for (int pb = 0; pb < Config::m_nphi; ++pb) { if (pb % 8 == 0) printf(" Phi %4d: ", pb); printf("%5d,%4d %s", - m_phi_bin_infos[zb][pb].first, m_phi_bin_infos[zb][pb].second, + m_phi_bin_infos[qb][pb].first, m_phi_bin_infos[qb][pb].second, ((pb + 1) % 8 == 0) ? "\n" : ""); } } } -//-----------------------------------------------------------------------------------------// -//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// -//-----------------------------------------------------------------------------------------// -// Endcap section: duplicate functions for now, cleanup and merge once strategy sorted out // -//-----------------------------------------------------------------------------------------// -//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// -//-----------------------------------------------------------------------------------------// +//============================================================================== +// EventOfHits +//============================================================================== -void LayerOfHits::SetupDisk(float rmin, float rmax, float dr) +EventOfHits::EventOfHits(int n_layers) : + m_layers_of_hits(n_layers), + m_n_layers(n_layers) { - // XXXX MT: Could have n_phi bins per layer, too. - - assert (m_nr == 0 && "SetupDisk() already called."); - - float nmin = std::floor(rmin / dr); - float nmax = std::ceil (rmax / dr); - m_rmin = dr * nmin; - m_rmax = dr * nmax; - m_fr = 1.0f / dr; // rbin = (rhit - m_rmin) * m_fr; - m_nr = nmax - nmin; - - //printf("rmin=%6f rmax=%6f dr=%6f m_nr=%i\n",rmin,rmax,dr,m_nr); - - m_phi_bin_infos.resize(m_nr); - for (int i = 0; i < m_nr; ++i) m_phi_bin_infos[i].resize(Config::m_nphi); -} - -void LayerOfHits::SuckInHitsEndcap(const HitVec &hitv) -{ - - assert (m_nr > 0 && "SetupDisk() was not called."); - - const int size = hitv.size(); - - if (m_capacity < size) - { - free_hits(); - alloc_hits(1.02 * size); - } - -#ifndef LOH_USE_PHI_Z_ARRAYS - std::vector m_hit_phis(size); -#endif - - struct HitInfo + for (int i = 0; i < n_layers; ++i) { - float phi; - float r; - int rbin; - }; - - std::vector ha(size); - std::vector rc(m_nr, 0); - int nrh = m_nr / 2; - { - int i = 0; - for (auto const &h : hitv) - { - HitInfo &hi = ha[i]; - hi.phi = h.phi(); - hi.r = h.r(); - hi.rbin = (hi.r - m_rmin) * m_fr; - m_hit_phis[i] = hi.phi + 6.3f * (hi.rbin - nrh); - ++rc[hi.rbin]; - ++i; - } + assert("Butchering out old setup via Config ... for cyl-cow and cms." && 0); + //if (Config::endcapTest) m_layers_of_hits[i].SetupDisk(Config::cmsDiskMinRs[i], Config::cmsDiskMaxRs[i], Config::g_disk_dr[i]); + //else m_layers_of_hits[i].SetupLayer(-Config::g_layer_zwidth[i], Config::g_layer_zwidth[i], Config::g_layer_dz[i]); } +} - RadixSort sort; - sort.Sort(&m_hit_phis[0], size); - - int curr_r_bin = 0; - int curr_phi_bin = 0; - int hits_in_bin = 0; - int hit_count = 0; - - for (int i = 0; i < size; ++i) +EventOfHits::EventOfHits(TrackerInfo &trk_inf) : + m_layers_of_hits(trk_inf.m_layers.size()), + m_n_layers(trk_inf.m_layers.size()) +{ + for (auto &li : trk_inf.m_layers) { - int j = sort.GetRanks()[i]; - - - if (hitv[j].r()>m_rmax || hitv[j].r() curr_phi_bin) + else { - set_phi_bin(curr_r_bin, curr_phi_bin, hit_count, hits_in_bin); - - empty_phi_bins(curr_r_bin, curr_phi_bin + 1, phi_bin, hit_count); + // printf("EventOfHits::EventOfHits setting up layer %2d as endcap\n", li.m_layer_id); - curr_phi_bin = phi_bin; + m_layers_of_hits[li.m_layer_id].SetupLayer(li.m_rin, li.m_rout, bin_width, li.m_is_barrel); } - - ++hits_in_bin; } - - set_phi_bin(curr_r_bin, curr_phi_bin, hit_count, hits_in_bin); - - empty_phi_bins(curr_r_bin, curr_phi_bin + 1, Config::m_nphi, hit_count); - - empty_r_bins(curr_r_bin + 1, m_nr, hit_count); - } diff --git a/mkFit/HitStructures.h b/mkFit/HitStructures.h index 2d1d3dff5221d..104b25cf15060 100644 --- a/mkFit/HitStructures.h +++ b/mkFit/HitStructures.h @@ -53,38 +53,35 @@ inline bool sortTrksByPhiMT(const Track& t1, const Track& t2) //============================================================================== -// Use extra arrays to store phi and z of hits. +// Use extra arrays to store phi and q of hits. // MT: This would in principle allow fast selection of good hits, if -// we had good error estimates and reasonable *minimal* phi and z windows. +// we had good error estimates and reasonable *minimal* phi and q windows. // Speed-wise, those arrays (filling AND access, about half each) cost 1.5% // and could help us reduce the number of hits we need to process with bigger // potential gains. -// #define LOH_USE_PHI_Z_ARRAYS +// #define LOH_USE_PHI_Q_ARRAYS + +// Note: the same code is used for barrel and endcap. In barrel the longitudinal +// bins are in Z and in endcap they are in R -- here this coordinate is called Q class LayerOfHits { public: Hit *m_hits = 0; vecvecPhiBinInfo_t m_phi_bin_infos; -#ifdef LOH_USE_PHI_Z_ARRAYS +#ifdef LOH_USE_PHI_Q_ARRAYS std::vector m_hit_phis; - std::vector m_hit_zs; + std::vector m_hit_qs; #endif - float m_zmin, m_zmax, m_fz; - int m_nz = 0; + float m_qmin, m_qmax, m_fq; + int m_nq = 0; int m_capacity = 0; - - //fixme, these are copies of the ones above, need to merge with a more generic name - float m_rmin, m_rmax, m_fr; - int m_nr = 0; -#ifdef LOH_USE_PHI_Z_ARRAYS - std::vector m_hit_rs; -#endif + bool m_is_barrel; // Testing bin filling - static constexpr float m_fphi = Config::m_nphi / Config::TwoPI; + static constexpr float m_fphi = Config::m_nphi / Config::TwoPI; static constexpr int m_phi_mask = 0x3ff; protected: @@ -93,10 +90,9 @@ class LayerOfHits m_hits = (Hit*) _mm_malloc(sizeof(Hit) * size, 64); m_capacity = size; for (int ihit = 0; ihit < m_capacity; ihit++){m_hits[ihit] = Hit();} -#ifdef LOH_USE_PHI_Z_ARRAYS +#ifdef LOH_USE_PHI_Q_ARRAYS m_hit_phis.resize(size); - m_hit_zs .resize(size); - m_hit_rs .resize(size); + m_hit_qs .resize(size); #endif } @@ -105,34 +101,26 @@ class LayerOfHits _mm_free(m_hits); } - void set_phi_bin(int z_bin, int phi_bin, int &hit_count, int &hits_in_bin) + void set_phi_bin(int q_bin, int phi_bin, int &hit_count, int &hits_in_bin) { - m_phi_bin_infos[z_bin][phi_bin] = { hit_count, hit_count + hits_in_bin }; + m_phi_bin_infos[q_bin][phi_bin] = { hit_count, hit_count + hits_in_bin }; hit_count += hits_in_bin; hits_in_bin = 0; } - void empty_phi_bins(int z_bin, int phi_bin_1, int phi_bin_2, int hit_count) + void empty_phi_bins(int q_bin, int phi_bin_1, int phi_bin_2, int hit_count) { for (int pb = phi_bin_1; pb < phi_bin_2; ++pb) { - m_phi_bin_infos[z_bin][pb] = { hit_count, hit_count }; + m_phi_bin_infos[q_bin][pb] = { hit_count, hit_count }; } } - void empty_z_bins(int z_bin_1, int z_bin_2, int hit_count) + void empty_q_bins(int q_bin_1, int q_bin_2, int hit_count) { - for (int zb = z_bin_1; zb < z_bin_2; ++zb) + for (int qb = q_bin_1; qb < q_bin_2; ++qb) { - empty_phi_bins(zb, 0, Config::m_nphi, hit_count); - } - } - - void empty_r_bins(int r_bin_1, int r_bin_2, int hit_count) - { - for (int rb = r_bin_1; rb < r_bin_2; ++rb) - { - empty_phi_bins(rb, 0, Config::m_nphi, hit_count); + empty_phi_bins(qb, 0, Config::m_nphi, hit_count); } } @@ -144,31 +132,24 @@ class LayerOfHits free_hits(); } - void Reset() {} - - void SetupLayer(float zmin, float zmax, float dz); + void Reset() {} - void SetupDisk(float rmin, float rmax, float dr); + void SetupLayer(float qmin, float qmax, float dq, bool is_barrel); - float NormalizeZ(float z) const { if (z < m_zmin) return m_zmin; if (z > m_zmax) return m_zmax; return z; } + float NormalizeQ(float q) const { if (q < m_qmin) return m_qmin; if (q > m_qmax) return m_qmax; return q; } - int GetZBin(float z) const { return (z - m_zmin) * m_fz; } + int GetQBin(float q) const { return (q - m_qmin) * m_fq; } - int GetZBinChecked(float z) const { int zb = GetZBin(z); if (zb < 0) zb = 0; else if (zb >= m_nz) zb = m_nz - 1; return zb; } - - int GetRBin(float r) const { return (r - m_rmin) * m_fr; } - - int GetRBinChecked(float r) const { int rb = GetRBin(r); if (rb < 0) rb = 0; else if (rb >= m_nr) rb = m_nr - 1; return rb; } + int GetQBinChecked(float q) const { int qb = GetQBin(q); if (qb < 0) qb = 0; else if (qb >= m_nq) qb = m_nq - 1; return qb; } // if you don't pass phi in (-pi, +pi), mask away the upper bits using m_phi_mask int GetPhiBin(float phi) const { return std::floor(m_fphi * (phi + Config::PI)); } - const vecPhiBinInfo_t& GetVecPhiBinInfo(float z) const { return m_phi_bin_infos[GetZBin(z)]; } + const vecPhiBinInfo_t& GetVecPhiBinInfo(float q) const { return m_phi_bin_infos[GetQBin(q)]; } void SuckInHits(const HitVec &hitv); - void SuckInHitsEndcap(const HitVec &hitv); - void SelectHitIndices(float z, float phi, float dz, float dphi, std::vector& idcs, bool isForSeeding=false, bool dump=false); + void SelectHitIndices(float q, float phi, float dq, float dphi, std::vector& idcs, bool isForSeeding=false, bool dump=false); void PrintBins(); }; @@ -182,16 +163,8 @@ class EventOfHits int m_n_layers; public: - EventOfHits(int n_layers) : - m_layers_of_hits(n_layers), - m_n_layers(n_layers) - { - for (int i = 0; i < n_layers; ++i) - { - if (Config::endcapTest) m_layers_of_hits[i].SetupDisk(Config::cmsDiskMinRs[i], Config::cmsDiskMaxRs[i], Config::g_disk_dr[i]); - else m_layers_of_hits[i].SetupLayer(-Config::g_layer_zwidth[i], Config::g_layer_zwidth[i], Config::g_layer_dz[i]); - } - } + EventOfHits(int n_layers); + EventOfHits(TrackerInfo &trk_inf); void Reset() { @@ -201,15 +174,10 @@ class EventOfHits } } - void SuckInHits(const HitVec &hitv, int layer) + void SuckInHits(int layer, const HitVec &hitv) { m_layers_of_hits[layer].SuckInHits(hitv); } - - void SuckInHitsEndcap(const HitVec &hitv, int layer) - { - m_layers_of_hits[layer].SuckInHitsEndcap(hitv); - } }; diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index 241ecdec7929f..84ee6cd15d838 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -6,6 +6,7 @@ #include "Event.h" #include "EventTmp.h" +#include "TrackerInfo.h" #include "MkFitter.h" @@ -106,7 +107,8 @@ namespace MkBuilder::MkBuilder() : m_event(0), m_event_tmp(0), - m_event_of_hits(Config::nLayers) + // XXMT WAS m_event_of_hits(Config::nLayers) + m_event_of_hits(Config::TrkInfo) { } @@ -163,7 +165,7 @@ void MkBuilder::begin_event(Event* ev, EventTmp* ev_tmp, const char* build_type) { for (int ilay = layers.begin(); ilay < layers.end(); ++ilay) { - m_event_of_hits.SuckInHits(m_event->layerHits_[ilay], ilay); + m_event_of_hits.SuckInHits(ilay, m_event->layerHits_[ilay]); } }); @@ -623,9 +625,11 @@ void MkBuilder::FindTracksBestHit(EventOfCandidates& event_of_cands) tbb::parallel_for(tbb::blocked_range(0,etabin_of_candidates.m_fill_index,Config::numSeedsPerTask), [&](const tbb::blocked_range& tracks) { + TrackerInfo &trk_info = Config::TrkInfo; std::unique_ptr mkfp(g_exe_ctx.m_fitters.GetFromPool(), retfitr); - for (int itrack = tracks.begin(); itrack < tracks.end(); itrack += NN) { + for (int itrack = tracks.begin(); itrack < tracks.end(); itrack += NN) + { int end = std::min(itrack + NN, tracks.end()); dprint(std::endl << "processing track=" << itrack << " etabin=" << ebin << " findex=" << etabin_of_candidates.m_fill_index); @@ -633,12 +637,13 @@ void MkBuilder::FindTracksBestHit(EventOfCandidates& event_of_cands) mkfp->SetNhits(3);//just to be sure (is this needed?) mkfp->InputTracksAndHitIdx(etabin_of_candidates.m_candidates, itrack, end, true); - //ok now we start looping over layers - //loop over layers, starting from after the seed - //consider inverting loop order and make layer outer, need to trade off hit prefetching with copy-out of candidates - for (int ilay = Config::nlayers_per_seed; ilay < Config::nLayers; ++ilay) + // Loop over layers, starting from after the seed. + // Consider inverting loop order and make layer outer, need to + // trade off hit prefetching with copy-out of candidates. + for (int ilay = trk_info.m_barrel[ Config::nlayers_per_seed ]; ; ) { LayerOfHits &layer_of_hits = m_event_of_hits.m_layers_of_hits[ilay]; + LayerInfo &layer_info = trk_info.m_layers[ilay]; // XXX This should actually be done in some other thread for the next layer while // this thread is crunching the current one. @@ -660,13 +665,20 @@ void MkBuilder::FindTracksBestHit(EventOfCandidates& event_of_cands) mkfp->SetNhits(ilay + 1); //here again assuming one hit per layer (is this needed?) //propagate to layer - if (ilay + 1 < Config::nLayers) + if ( ! layer_info.m_is_outer) { dcall(pre_prop_print(ilay, mkfp.get())); - mkfp->PropagateTracksToR(m_event->geom_.Radius(ilay+1), end - itrack); + + mkfp->PropagateTracksToR(trk_info.m_layers[layer_info.m_next_barrel].m_rin, end - itrack); + dcall(post_prop_print(ilay, mkfp.get())); } + else + { + break; + } + ilay = layer_info.m_next_barrel; } // end of layer loop mkfp->OutputFittedTracksAndHitIdx(etabin_of_candidates.m_candidates, itrack, end, true); } @@ -718,18 +730,21 @@ void MkBuilder::FindTracksStandard() tbb::parallel_for(tbb::blocked_range(0, etabin_of_comb_candidates.m_fill_index, std::min(Config::numSeedsPerTask, adaptiveSPT)), [&](const tbb::blocked_range& seeds) { + TrackerInfo &trk_info = Config::TrkInfo; + const int start_seed = seeds.begin(); const int end_seed = seeds.end(); const int nseeds = end_seed - start_seed; - //ok now we start looping over layers - //loop over layers, starting from after the seed - for (int ilay = Config::nlayers_per_seed; ilay < Config::nLayers; ++ilay) + // Loop over layers, starting from after the seed. + bool is_first_layer = true; + for (int ilay = trk_info.m_barrel[ Config::nlayers_per_seed ]; ; ) { - LayerOfHits &layer_of_hits = m_event_of_hits.m_layers_of_hits[ilay]; - - dprint("processing lay=" << ilay+1); + dprint("processing lay=" << ilay); + LayerOfHits &layer_of_hits = m_event_of_hits.m_layers_of_hits[ilay]; + LayerInfo &layer_info = trk_info.m_layers[ilay]; + // prepare unrolled vector to loop over std::vector > seed_cand_idx; @@ -772,26 +787,25 @@ void MkBuilder::FindTracksStandard() //fixme find a way to deal only with the candidates needed in this thread mkfp->InputTracksAndHitIdx(etabin_of_comb_candidates.m_candidates, seed_cand_idx, itrack, end, - ilay == Config::nlayers_per_seed); + is_first_layer); //propagate to layer - if (ilay > Config::nlayers_per_seed) + if ( ! is_first_layer) { - dcall(pre_prop_print(ilay, mkfp)); - mkfp->PropagateTracksToR(m_event->geom_.Radius(ilay), end - itrack); - dcall(post_prop_print(ilay, mkfp)); + dcall(pre_prop_print(ilay, mkfp.get())); + mkfp->PropagateTracksToR(layer_info.m_rin, end - itrack); + dcall(post_prop_print(ilay, mkfp.get())); } dprint("now get hit range"); mkfp->SelectHitIndices(layer_of_hits, end - itrack); - + //#ifdef PRINTOUTS_FOR_PLOTS //std::cout << "MX number of hits in window in layer " << ilay << " is " << mkfp->getXHitEnd(0, 0, 0)-mkfp->getXHitBegin(0, 0, 0) << std::endl; //#endif - + dprint("make new candidates"); mkfp->FindCandidates(layer_of_hits, tmp_candidates, start_seed, end - itrack); - } //end of vectorized loop // clean exceeding candidates per seed @@ -836,8 +850,15 @@ void MkBuilder::FindTracksStandard() tmp_candidates[is].clear(); } } - - } // end of layer loop + + if (layer_info.m_is_outer) + { + break; + } + + is_first_layer = false; + ilay = layer_info.m_next_barrel; + } // end of layer loop // final sorting for (int iseed = start_seed; iseed < end_seed; ++iseed) @@ -884,17 +905,23 @@ void MkBuilder::FindTracksCloneEngine() void MkBuilder::find_tracks_in_layers(EtaBinOfCombCandidates &etabin_of_comb_candidates, CandCloner &cloner, MkFitter *mkfp, int start_seed, int end_seed, int ebin) { - auto n_seeds = end_seed - start_seed; + TrackerInfo &trk_info = Config::TrkInfo; + const int n_seeds = end_seed - start_seed; std::vector> seed_cand_idx; seed_cand_idx.reserve(n_seeds * Config::maxCandsPerSeed); cloner.begin_eta_bin(&etabin_of_comb_candidates, start_seed, n_seeds); - //loop over layers, starting from after the seeD - for (int ilay = Config::nlayers_per_seed; ilay <= Config::nLayers; ++ilay) + // Loop over layers, starting from after the seed. + // Note that we do a final pass with ilay = -1 to update parameters + // and output final tracks. prev_ilay == -1 serves as is_first_layer. + int prev_ilay = -1; + for (int ilay = trk_info.m_barrel[ Config::nlayers_per_seed ]; ; ) { - dprint("processing lay=" << ilay+1); + dprint("processing lay=" << ilay); + + LayerInfo &layer_info = trk_info.m_layers[ilay]; //prepare unrolled vector to loop over for (int iseed = start_seed; iseed != end_seed; ++iseed) @@ -915,7 +942,7 @@ void MkBuilder::find_tracks_in_layers(EtaBinOfCombCandidates &etabin_of_comb_can // XXXX MT ??? How does this happen ??? if (theEndCand == 0) continue; - if (ilay < Config::nLayers) + if (ilay >= 0) { cloner.begin_layer(ilay); } @@ -936,8 +963,9 @@ void MkBuilder::find_tracks_in_layers(EtaBinOfCombCandidates &etabin_of_comb_can dprintf("\n"); #endif - // mkfp->SetNhits(ilay == Config::nlayers_per_seed ? ilay : ilay + 1); - mkfp->SetNhits(ilay); + mkfp->SetNhits(ilay >= 0 ? ilay : prev_ilay + 1); // XXXXMT HAKAHAKA + // mkfp->SetNhits(ilay); // XXXXMT -- also elsewhere in building + // XXXXMT should realy be increase N - hits !!!! mkfp->InputTracksAndHitIdx(etabin_of_comb_candidates.m_candidates, seed_cand_idx, itrack, end, @@ -949,23 +977,24 @@ void MkBuilder::find_tracks_in_layers(EtaBinOfCombCandidates &etabin_of_comb_can dprintf("\n"); #endif - if (ilay > Config::nlayers_per_seed) + if (prev_ilay >= 0) { - LayerOfHits &layer_of_hits = m_event_of_hits.m_layers_of_hits[ilay - 1]; + LayerOfHits &prev_layer_of_hits = m_event_of_hits.m_layers_of_hits[prev_ilay]; - mkfp->UpdateWithLastHit(layer_of_hits, end - itrack); + mkfp->UpdateWithLastHit(prev_layer_of_hits, end - itrack); - if (ilay < Config::nLayers) + if (ilay >= 0) { // Propagate to this layer - mkfp->PropagateTracksToR(m_event->geom_.Radius(ilay), end - itrack); + mkfp->PropagateTracksToR(layer_info.m_rin, end - itrack); // copy_out the propagated track params, errors only (hit-idcs and chi2 already updated) mkfp->CopyOutParErr(etabin_of_comb_candidates.m_candidates, end - itrack, true); } - else { + else + { // copy_out the updated track params, errors only (hit-idcs and chi2 already updated) mkfp->CopyOutParErr(etabin_of_comb_candidates.m_candidates, end - itrack, false); @@ -996,12 +1025,18 @@ void MkBuilder::find_tracks_in_layers(EtaBinOfCombCandidates &etabin_of_comb_can cloner.end_iteration(); } //end of vectorized loop - if (ilay < Config::nLayers) + if (ilay >= 0) { cloner.end_layer(); } + else + { + break; + } seed_cand_idx.clear(); + prev_ilay = ilay; + ilay = layer_info.m_next_barrel; } // end of layer loop cloner.end_eta_bin(); diff --git a/mkFit/MkBuilderEndcap.cc b/mkFit/MkBuilderEndcap.cc index fa3af7599cab7..f1e4b9907c501 100644 --- a/mkFit/MkBuilderEndcap.cc +++ b/mkFit/MkBuilderEndcap.cc @@ -115,8 +115,9 @@ void MkBuilderEndcap::begin_event(Event* ev, EventTmp* ev_tmp, const char* build //fill vector of hits in each layer for (int ilay = 0; ilay < m_event->layerHits_.size(); ++ilay) { - dprintf("Suck in Hits for layer %i with AvgZ=%5.1f rMin=%5.1f rMax=%5.1f",ilay,Config::cmsAvgZs[ilay],Config::cmsDiskMinRs[ilay],Config::cmsDiskMaxRs[ilay]); - m_event_of_hits.SuckInHitsEndcap(m_event->layerHits_[ilay], ilay); + // XXXX MT hackout + //dprintf("Suck in Hits for layer %i with AvgZ=%5.1f rMin=%5.1f rMax=%5.1f",ilay,Config::cmsAvgZs[ilay],Config::cmsDiskMinRs[ilay],Config::cmsDiskMaxRs[ilay]); + //m_event_of_hits.SuckInHitsEndcap(ilay, m_event->layerHits_[ilay]); } for (int l=0; l Config::m_max_dz) dz = Config::m_max_dz; if (std::abs(dphi) > Config::m_max_dphi) dphi = Config::m_max_dphi; - const int zb1 = L.GetZBinChecked(z - dz); - const int zb2 = L.GetZBinChecked(z + dz) + 1; + const int zb1 = L.GetQBinChecked(z - dz); + const int zb2 = L.GetQBinChecked(z + dz) + 1; const int pb1 = L.GetPhiBin(phi - dphi); const int pb2 = L.GetPhiBin(phi + dphi) + 1; // MT: The extra phi bins give us ~1.5% more good tracks at expense of 10% runtime. @@ -1610,7 +1611,8 @@ void MkFitter::PropagateTracksToZ(float Z, const int N_proc) Err[iP], Par[iP], N_proc); } -void MkFitter::SelectHitIndicesEndcap(const LayerOfHits &layer_of_hits, const int N_proc, bool dump) +void MkFitter::SelectHitIndicesEndcap(const LayerOfHits &layer_of_hits, + const int N_proc, bool dump) { const int iI = iP; const float nSigmaPhi = 3; @@ -1672,8 +1674,8 @@ void MkFitter::SelectHitIndicesEndcap(const LayerOfHits &layer_of_hits, const in // if (std::abs(dz) > Config::m_max_dz) dz = Config::m_max_dz; if (std::abs(dphi) > Config::m_max_dphi) dphi = Config::m_max_dphi; - const int rb1 = L.GetRBinChecked(r - dr); - const int rb2 = L.GetRBinChecked(r + dr) + 1; + const int rb1 = L.GetQBinChecked(r - dr); + const int rb2 = L.GetQBinChecked(r + dr) + 1; const int pb1 = L.GetPhiBin(phi - dphi); const int pb2 = L.GetPhiBin(phi + dphi) + 1; // MT: The extra phi bins give us ~1.5% more good tracks at expense of 10% runtime. diff --git a/mkFit/mkFit.cc b/mkFit/mkFit.cc index fcf91b74deec6..90057c61eec6a 100644 --- a/mkFit/mkFit.cc +++ b/mkFit/mkFit.cc @@ -207,11 +207,11 @@ void test_standard() sizeof(Track), sizeof(Hit), sizeof(SVector3), sizeof(SMatrixSym33), sizeof(MCHitInfo)); if (Config::useCMSGeom) { printf ("Using CMS-like geometry "); - if (Config::readCmsswSeeds) printf ("with CMSSW seeds \n"); + if (Config::readCmsswSeeds) printf ("with CMSSW seeds\n"); else printf ("with MC-truth seeds \n"); } else if (Config::endcapTest) { - printf ("Test tracking in endcap, disks spacing 5 cm \n"); - } else printf ("Using 4-cm spacing barrel geometry \n"); + printf ("Test tracking in endcap, disks spacing 5 cm\n"); + } else printf ("Using Cylindrical Cow with Lids, |eta| < 2.4\n"); if (g_operation == "write") { generate_and_save_tracks(); diff --git a/mkFit/mt-notes.txt b/mkFit/mt-notes.txt index 092640eabfde7..237ac02deb9a7 100644 --- a/mkFit/mt-notes.txt +++ b/mkFit/mt-notes.txt @@ -1,52 +1,48 @@ ######### -Work plan +Full detector tracking ######### -1. MkFitter::FindCandidatesMinimizeCopy() -- see comment XXXX MT FIXME in the - middle of index vector initialization loops. - In short - it's about supporting partial SlurpIn and masked intrinsics. +0. Open issues: + a. Storing of hit indices into Track + Also -- MkFitter and arrays of full hits. + There is this mkfp->SetNhits() in every building layer loop. + b. Last seed layer should somhow be known to building functions. - Matriplex could have a MAX_N member that would be used for non-vectorized - code. I'm not super sure about that -- if we limit the loading of data and - then never read out the parts that were not used it costs us nothing (or - little) to do operations on whole vectors. +1. Best-hit on x-1-10000-brl.raw -2. Fix access of hits out of bunch_of_hits in FindCandidatesMinimizeCopy(). - When we determine phi range for each track, this can oveflow over the end - of the array. - - Replace XHitBegin/XHitEnd with XHitPos/XHitSize - - Calculate them properly including phi wrap in SelectHitRanges() - - In FindCandidatesMinimizeCopy() wrap back the index vector. +BEFORE: +Building tracks with 'runBuildingTestPlexBestHit', total simtracks=10000 +found tracks=9215 in pT 10%=9163 in pT 20%=9195 no_mc_assoc=785 + nH >= 80% =9111 in pT 10%=9106 in pT 20%=9111 - Or, alternatively, copy a couple of front hits to the back. - Ouch, this is not so trivial, need to fix overrrun in the other direction, - too! Heh, I could always copy the last couple of hits to the front :) - No ... the first solution is fine! +AFTER: +Building tracks with 'runBuildingTestPlexBestHit', total simtracks=10000 +found tracks=9215 in pT 10%=9165 in pT 20%=9194 no_mc_assoc=785 + nH >= 80% =9115 in pT 10%=9110 in pT 20%=9115 - Note --- there is also the maxSize there counter + a hack limiting it to 25 - there. We should also fix this properly, either by restricting the number - of phi bins or by killing the candidates whose errors get too big. +2. Std -3. Hand-made multi-threading for eta bins. +BEFORE: +Building tracks with 'runBuildingTestPlexStandard', total simtracks=10000 +found tracks=9977 in pT 10%=9969 in pT 20%=9974 no_mc_assoc=23 + nH >= 80% =9972 in pT 10%=9968 in pT 20%=9971 - Later, multi-threading over multiple events to fill all slots and to not - stall waiting for threads that take longer to process. +AFTER: +Building tracks with 'runBuildingTestPlexStandard', total simtracks=10000 +found tracks=9977 in pT 10%=9969 in pT 20%=9974 no_mc_assoc=23 + nH >= 80% =9972 in pT 10%=9968 in pT 20%=9971 - Note, current simulation produces higher occupancy at higher eta. +3. Clone engine: - Once we have endcaps, the transition region will also become more - expensive. +BEFORE: +Building tracks with 'runBuildingTestPlexCloneEngine', total simtracks=10000 +found tracks=9977 in pT 10%=9969 in pT 20%=9974 no_mc_assoc=23 + nH >= 80% =9972 in pT 10%=9968 in pT 20%=9971 -4. Attempt number two at prefetching in a service thread. - -5. Make MkFitter use a single array of hits, copy in as they are needed. - Now we have a fixed set of 10 hits ... this was done for final fitting so - we could copy in all the hits in the beginning. - Or, if it turns out this makes sense for fitting, separate MkFitter and - MkBuilder, optionally using a common MkBase. - -6. Implement write/read events for the new event/track/hit format. - Started doing this on glut. +AFTER: +Building tracks with 'runBuildingTestPlexCloneEngine', total simtracks=10000 +found tracks=9977 in pT 10%=9969 in pT 20%=9974 no_mc_assoc=23 + nH >= 80% =9972 in pT 10%=9968 in pT 20%=9971 ######### diff --git a/test/CylCowWLids.C b/test/CylCowWLids.C new file mode 100644 index 0000000000000..0d524dd1d4dc8 --- /dev/null +++ b/test/CylCowWLids.C @@ -0,0 +1,85 @@ +// To be used in compiled mode + +#include "../CylCowWLids.cc" + +#include "TCanvas.h" +#include "TLine.h" + +TrackerInfo g_tracker_info; + +//------------------------------------------------------------------------------ + +void print_etas(LayerInfo &li, float dz) +{ + float r, z; + if (li.m_is_barrel) + { + r = li.r_mean(); + z = li.m_zmax; + } else { + r = li.m_rout; + z = li.z_mean(); + } + + printf("%2d %6.4f %6.4f %6.4f", li.m_layer_id, + getEta(r, z - dz), getEta(r, z), getEta(r, z + dz)); + + if ( ! li.m_is_barrel) + { + r = li.m_rin; + + printf(" - %6.4f %6.4f %6.4f", + getEta(r, z - dz), getEta(r, z), getEta(r, z + dz)); + } + + printf("\n"); +} + +//------------------------------------------------------------------------------ + +void CylCowWLids() +{ + Create_TrackerInfo(g_tracker_info, true); + + float zM = 120; + float rM = 100; + + float cScale = 6; + TCanvas *c = new TCanvas("cvs", "", cScale*zM, cScale*rM); + TPad *p = new TPad("pad", "", 0, 0, 1, 1); + p->Draw(); + p->Update(); + p->cd(); + + p->DrawFrame(0, 0, zM, rM); + + printf("Eta coordinates of edges for z0 (-3, 0, +3) cm\n"); + printf("----------------------------------------------\n"); + + for (auto i : g_tracker_info.m_barrel) + { + LayerInfo &li = g_tracker_info.m_layers[i]; + + TLine * l = new TLine(0, li.r_mean(), li.m_zmax, li.r_mean()); + l->SetLineColor(kBlue); + l->SetLineWidth(2); + l->Draw(); + + print_etas(li, 3); + } + + for (auto i : g_tracker_info.m_ecap_pos) + { + LayerInfo &li = g_tracker_info.m_layers[i]; + + TLine *l = new TLine(li.z_mean(), li.m_rin, li.z_mean(), li.m_rout); + l->SetLineColor(kMagenta + 3); + l->SetLineWidth(2); + l->Draw(); + + print_etas(li, 3); + } + + p->Modified(); + p->Update(); +} From 1838dc3ef567969b47a834f5809abce6ab831da0 Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Fri, 3 Mar 2017 00:11:03 -0800 Subject: [PATCH 006/172] Remove all implicit handling and representation of layer index/number. Introduce HitOnTrack bit-packed structure {index, layer}. Endcap state: - experimental stage for z+ side only; - Simulation now works, can produce two hits on barrel/endcap transition; - some code, in particular seeding, isn't too happy about this; - double hits could be cleaned for sim tracks or for seeds; - hit-on-track arrays in Track and MkFitter are now larger to accomodate for this; Common barrel / endcap code: - Now seems possible with a couple function pointers. - Need to take apart EventOf(Combined)Candidates and its usage -- the relevant part now is how to separate EC- / T- / B / T+ / EC+. Furhter sorting within those sections can be explored later. Config.h and Simulation.cc are hardocded for z+ endcap testing. --- BinInfoUtils.h | 3 ++ Config.h | 19 ++++--- CylCowWLids.h | 3 +- Event.cc | 13 ++--- Hit.h | 46 ++++------------- Propagation.cc | 16 +++--- SimpleGeom.cc | 6 ++- Simulation.cc | 3 +- Track.cc | 11 +++-- Track.h | 93 ++++++++++++++++++++-------------- TrackerInfo.h | 2 + buildtest.cc | 5 +- mkFit/CandCloner.cc | 2 +- mkFit/CandCloner.h | 4 -- mkFit/HitStructures.cc | 11 +++-- mkFit/HitStructures.h | 6 ++- mkFit/MkBuilder.cc | 82 ++++++++++++++++++++++-------- mkFit/MkBuilderEndcap.cc | 37 +++++++++++--- mkFit/MkFitter.cc | 104 ++++++++++++++++++++++----------------- mkFit/MkFitter.h | 13 ++--- mkFit/buildtestMPlex.cc | 1 - mkFit/fittestMPlex.cc | 2 - mkFit/mkFit.cc | 12 ----- seedtest.cc | 40 ++++++++++----- 24 files changed, 309 insertions(+), 225 deletions(-) diff --git a/BinInfoUtils.h b/BinInfoUtils.h index 7b85f42cda994..cd556a1ee27a4 100644 --- a/BinInfoUtils.h +++ b/BinInfoUtils.h @@ -1,6 +1,9 @@ #ifndef _bininfoutils_ #define _bininfoutils_ +// XXXXMT4K This should all be removed ... +// getCandHitIndices seems to be still used. + // could #include "TMath.h", but then this is problematic for non root running. This compiles and runs without tmath.h #include diff --git a/Config.h b/Config.h index 82aed05b52e61..42bdf0d555afa 100644 --- a/Config.h +++ b/Config.h @@ -50,13 +50,9 @@ namespace Config // XXXX This needs to be generalized for other geometries ! // TrackerInfo more or less has all this information (or could have it). constexpr int nTotalLayers = 28; - constexpr int nMaxTrkLayers = 19; // Assuming hitting every barrel / endcap edge - constexpr int nBarrelLayers = 10; - constexpr int BarrelLayer0 = 0; - constexpr int nECapLayers = 9; - constexpr int ECapPosLayer0 = 10; - constexpr int ECapNegLayer0 = 19; - // min/max etas or thetas for EC-, T-, B, T+, EC+ + constexpr int nMaxSimHits = 19; // Assuming dual hit on every barrel / endcap edge + constexpr int nMaxRecHits = 10; // Assuming single hit on each layer + constexpr int nMaxTrkHits = nMaxSimHits; // Used for array sizes in MkFitter and Track constexpr float fRadialSpacing = 4.; constexpr float fRadialExtent = 0.01; @@ -147,8 +143,11 @@ namespace Config constexpr float minSimPt = 1; // 0.5; constexpr float maxSimPt = 10.; - constexpr float minSimEta = 0.0; // XXMT4K Added min, too. - constexpr float maxSimEta = 0.9;//2.4; // Should both become config vars? + //constexpr float minSimEta = 0.0; // XXMT4K Added min, too. + //constexpr float maxSimEta = 0.9;//2.4; // Should both become config vars? + // ECAP TEST pz > 0 only -- commented out 50% pz sign flip in Simulation!!!! + constexpr float minSimEta = 1.4; + constexpr float maxSimEta = 2.4; constexpr float hitposerrXY = 0.01; // resolution is 100um in xy --> more realistic scenario is 0.003 constexpr float hitposerrZ = 0.1; // resolution is 1mm in z @@ -160,7 +159,7 @@ namespace Config // XXMT4K OK ... what do we do with this guy? MaxTotHit / AvgTotHit ... ? // For now setting it to nMaxTrkLayers which is too big ... but it seems to be // only used for vector::reserve() ... - constexpr int nTotHit = Config::nMaxTrkLayers; // for now one hit per layer for sim + constexpr int nTotHit = Config::nMaxSimHits; // for now one hit per layer for sim // scattering simulation constexpr float X0 = 9.370; // cm, from http://pdg.lbl.gov/2014/AtomicNuclearProperties/HTML/silicon_Si.html // Pb = 0.5612 cm diff --git a/CylCowWLids.h b/CylCowWLids.h index c2e347a05ec2f..95eda9eab9198 100644 --- a/CylCowWLids.h +++ b/CylCowWLids.h @@ -17,7 +17,8 @@ class TrackerInfo; // // Run root test/CylCowWLids.C to get a plot and dumps of // edge coordinates and etas. - +// +// Eta partitions for B / T / EC // This could be translated into plugin diff --git a/Event.cc b/Event.cc index a728e5127a0c5..39975be865079 100644 --- a/Event.cc +++ b/Event.cc @@ -5,7 +5,6 @@ #include "seedtest.h" #include "buildtest.h" #include "fittest.h" -#include "BinInfoUtils.h" #include "ConformalUtils.h" //#define DEBUG @@ -50,11 +49,13 @@ void Event::resetLayerHitMap(bool resetSimHits) { layerHitMap_[hit.mcHitID()] = HitID(ilayer, index); } } + // XXXMT4K is this still necessary? Or maybe I scrwed up by doing the mapping below ... if (resetSimHits) { for (auto&& track : simTracks_) { for (int il = 0; il < track.nTotalHits(); ++il) { - assert(layerHitMap_[track.getHitIdx(il)].index >= 0); // tmp debug - track.setHitIdx(il, layerHitMap_[track.getHitIdx(il)].index); + HitID &hid = layerHitMap_[track.getHitIdx(il)]; + assert(hid.index >= 0); // tmp debug + track.setHitIdx(il, hid.index, hid.layer); } } } @@ -169,7 +170,8 @@ void Event::Simulate() assert(hits.size() == hitinfos.size()); for (int i = 0; i < hits.size(); ++i) { - sim_track.addHitIdx(hits[i].mcHitID(), 0.0f); // set to the correct hit index after sorting + // set to the correct hit index after sorting + sim_track.addHitIdx(hits[i].mcHitID(), -128, 0.0f); layerHits_[hitinfos[i].layer_].emplace_back(hits[i]); simHitsInfo_.emplace_back(hitinfos[i]); } @@ -524,7 +526,7 @@ void Event::read_in(FILE *fp, int version) printf("hit #%i idx=%i\n",ih,simTracks_[it].getHitIdx(ih)); } } - + */ printf("read %i layers\n",nl); for (int il = 0; il Config::fEtaDet) - { - return 0; - } - - if (Config::nEtaBin == 1) { - b1 = 0; - b2 = -1; - return 1; - } - - int b1p = std::floor((eta + Config::fEtaOffB1) * Config::fEtaFacB1); - int b2p = std::floor((eta + Config::fEtaOffB2) * Config::fEtaFacB2); - - // printf("b1' = %d b2' = %d\n", b1p, b2p); - - int cnt = 0; - if (b1p >= 0 && b1p < Config::nEtaPart) - { - b1 = 2 * b1p; - ++cnt; - } - if (b2p >= 0 && b2p < Config::nEtaPart - 1) - { - b2 = 2 * b2p + 1; - ++cnt; - } - - // printf("b1 = %d b2 = %d\n", b1, b2); - - return cnt; -} - inline float getRad2(float x, float y){ return x*x + y*y; } @@ -286,6 +249,15 @@ typedef std::vector PairIdxVec; typedef std::array TripletIdx; typedef std::vector TripletIdxVec; +struct HitOnTrack +{ + int index : 24; + int layer : 8; + + HitOnTrack() : index(-1), layer (-1) {} + HitOnTrack(int i, int l) : index( i), layer ( l) {} +}; + void print(std::string label, const MeasurementState& s); #endif diff --git a/Propagation.cc b/Propagation.cc index 8238233d56320..b2792051d959d 100644 --- a/Propagation.cc +++ b/Propagation.cc @@ -1,5 +1,5 @@ #include "Propagation.h" -//#define DEBUG +#define DEBUG #include "Debug.h" const double tolerance = 0.001; @@ -249,7 +249,7 @@ TrackState propagateHelixToNextSolid(TrackState inputState, const Geometry& geom #endif dprint("curvature=" << hsin.curvature); - float totalDistance = 0; + double totalDistance = 0; auto startSolid = geom.InsideWhat(UVector3(hsin.x,hsin.y,hsin.z)); // have we scattered out of the solid? @@ -277,7 +277,7 @@ TrackState propagateHelixToNextSolid(TrackState inputState, const Geometry& geom int prev_solid; int skip_solid = geom.LayerOfSolid(startSolid); - for (int i=0; iSetNhits(m_layer);//here again assuming one hit per layer - m_idx_max = 0; m_idx_max_prev = 0; @@ -165,8 +163,6 @@ class CandCloner EtaBinOfCombCandidates *mp_etabin_of_comb_candidates; - // MkFitter *m_fitter; - #if defined(CC_TIME_ETA) or defined(CC_TIME_LAYER) double t_eta, t_lay; #endif diff --git a/mkFit/HitStructures.cc b/mkFit/HitStructures.cc index 72ee7c235f2d8..b9d9c28184021 100644 --- a/mkFit/HitStructures.cc +++ b/mkFit/HitStructures.cc @@ -1,15 +1,16 @@ #include "HitStructures.h" -#include "BinInfoUtils.h" + #include "TrackerInfo.h" #include "Ice/IceRevisitedRadix.h" -void LayerOfHits::SetupLayer(float qmin, float qmax, float dq, bool is_barrel) +void LayerOfHits::SetupLayer(float qmin, float qmax, float dq, int layer, bool is_barrel) { // XXXX MT: Could have n_phi bins per layer, too. assert (m_nq == 0 && "SetupLayer() already called."); + m_layer_id = layer; m_is_barrel = is_barrel; // Realign qmin/max on "global" dq boundaries. @@ -294,13 +295,15 @@ EventOfHits::EventOfHits(TrackerInfo &trk_inf) : { // printf("EventOfHits::EventOfHits setting up layer %2d as barrel\n", li.m_layer_id); - m_layers_of_hits[li.m_layer_id].SetupLayer(li.m_zmin, li.m_zmax, bin_width, li.m_is_barrel); + m_layers_of_hits[li.m_layer_id].SetupLayer(li.m_zmin, li.m_zmax, bin_width, + li.m_layer_id, li.m_is_barrel); } else { // printf("EventOfHits::EventOfHits setting up layer %2d as endcap\n", li.m_layer_id); - m_layers_of_hits[li.m_layer_id].SetupLayer(li.m_rin, li.m_rout, bin_width, li.m_is_barrel); + m_layers_of_hits[li.m_layer_id].SetupLayer(li.m_rin, li.m_rout, bin_width, + li.m_layer_id, li.m_is_barrel); } } } diff --git a/mkFit/HitStructures.h b/mkFit/HitStructures.h index 104b25cf15060..397e49dbc29fc 100644 --- a/mkFit/HitStructures.h +++ b/mkFit/HitStructures.h @@ -78,6 +78,7 @@ class LayerOfHits float m_qmin, m_qmax, m_fq; int m_nq = 0; int m_capacity = 0; + int m_layer_id = -1; bool m_is_barrel; // Testing bin filling @@ -134,7 +135,7 @@ class LayerOfHits void Reset() {} - void SetupLayer(float qmin, float qmax, float dq, bool is_barrel); + void SetupLayer(float qmin, float qmax, float dq, int layer, bool is_barrel); float NormalizeQ(float q) const { if (q < m_qmin) return m_qmin; if (q > m_qmax) return m_qmax; return q; } @@ -323,6 +324,9 @@ class EventOfCombCandidates std::vector m_etabins_of_comb_candidates; public: + // XXXXMT Do I need something like: + // EventOfCombCandidates(int nb, float eta_trans_beg, float eta_trans_end, float eta_max) : + EventOfCombCandidates() : m_etabins_of_comb_candidates(Config::nEtaBin) {} diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index 84ee6cd15d838..25a35fc01f720 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -136,14 +136,6 @@ void MkBuilder::begin_event(Event* ev, EventTmp* ev_tmp, const char* build_type) std::cout << "Building tracks with '" << build_type << "', total simtracks=" << simtracks.size() << std::endl; } #ifdef DEBUG - //unit test for eta partitioning - for (int i = 0; i < 60; ++i) - { - const float eta = -1.5f + 0.05f*i; - int b1, b2; - int cnt = getBothEtaBins(eta, b1, b2); - dprint("eta=" << eta << " bin=" << getEtaBin(eta) << " hb1=" << b1 << " hb2=" << b2); - } //dump sim tracks for (int itrack = 0; itrack < simtracks.size(); ++itrack) { @@ -205,6 +197,9 @@ void MkBuilder::end_event() int MkBuilder::find_seeds() { + fprintf(stderr, "__FILE__::__LINE__ Needs fixing for B/E support, search for XXMT4K\n"); + exit(1); + #ifdef DEBUG bool debug(false); #endif @@ -215,6 +210,9 @@ int MkBuilder::find_seeds() time = dtime() - time; // use this to initialize tracks + // XXMT4K ... configurable input layers ... or hardcode something else for endcap. + // Could come from TrackerInfo ... + // But what about transition ... TrackerInfo as well or arbitrary combination of B/E seed layers ???? const Hit * lay0hits = m_event_of_hits.m_layers_of_hits[0].m_hits; const Hit * lay1hits = m_event_of_hits.m_layers_of_hits[1].m_hits; const Hit * lay2hits = m_event_of_hits.m_layers_of_hits[2].m_hits; @@ -236,12 +234,13 @@ int MkBuilder::find_seeds() for (int ihit = 0; ihit < Config::nlayers_per_seed; ihit++) { - seedtrack.addHitIdx(seed_idcs[iseed][ihit],0.0f); + // XXMT4K - ihit to layer[ihit] + seedtrack.addHitIdx(seed_idcs[iseed][ihit], ihit, 0.0f); } for (int ihit = Config::nlayers_per_seed; ihit < Config::nLayers; ihit++) { - seedtrack.setHitIdx(ihit,-1); + seedtrack.setHitIdx(ihit, -1, -1); } dprint("iseed: " << iseed << " mcids: " << hit0.mcTrackID(m_event->simHitsInfo_) << " " << @@ -259,11 +258,22 @@ void MkBuilder::fit_seeds() int count = (theEnd + NN - 1)/NN; tbb::parallel_for(tbb::blocked_range(0, count, std::max(1, Config::numSeedsPerTask/NN)), - [&](const tbb::blocked_range& i) { + [&](const tbb::blocked_range& i) + { + printf("Seed info pos( x y z r; eta phi) mom( pt pz; eta phi)\n"); std::unique_ptr mkfp(g_exe_ctx.m_fitters.GetFromPool(), retfitr); for (int it = i.begin(); it < i.end(); ++it) { + // MT dump seed so i see if etas are about right + for (int i = it*NN; i < std::min((it+1)*NN, theEnd); ++i) + { + auto &t = seedtracks[i]; + printf("Seed %4d pos(%+7.3f %+7.3f %+7.3f; %+7.3f %+6.3f %+6.3f) mom(%+7.3f %+7.3f; %+6.3f %+6.3f)\n", + i, t.x(), t.y(), t.z(), t.posR(), t.posEta(), t.posPhi(), + t.pT(), t.pz(), t.momEta(), t.momPhi()); + } + fit_one_seed_set(seedtracks, it*NN, std::min((it+1)*NN, theEnd), mkfp.get()); } } @@ -280,8 +290,9 @@ inline void MkBuilder::fit_one_seed_set(TrackVec& seedtracks, int itrack, int en if (Config::cf_seeding) mkfp->ConformalFitTracks(false, itrack, end); if (Config::readCmsswSeeds==false) mkfp->FitTracks(end - itrack, m_event); - const int ilay = Config::nlayers_per_seed; // layer 4 + const int ilay = Config::nlayers_per_seed; // layer 4; XXXXMT + // XXMT need different propagate for endcap ... well ... to be seen. dcall(pre_prop_print(ilay, mkfp)); mkfp->PropagateTracksToR(m_event->geom_.Radius(ilay), end - itrack); dcall(post_prop_print(ilay, mkfp)); @@ -326,7 +337,14 @@ N.B.2 Since we inflate LOH by 2% more than GLH, hit indices in building only go */ void MkBuilder::map_seed_hits() -{ // map seed hit indices from global m_event->layerHits_[i] to hit indices in structure m_event_of_hits.m_layers_of_hits[i].m_hits +{ + // map seed hit indices from global m_event->layerHits_[i] to hit indices in + // structure m_event_of_hits.m_layers_of_hits[i].m_hits + + // XXMT4K what does this actually do? + // I'm beginning to get the impression that some remapping can be removed + // now that we have HitOnTrack { index, layer }; + HitIDVec seedLayersHitMap(m_event->simHitsInfo_.size()); for (int ilayer = 0; ilayer < Config::nlayers_per_seed; ++ilayer) { const auto & lof_m_hits = m_event_of_hits.m_layers_of_hits[ilayer].m_hits; @@ -342,14 +360,21 @@ void MkBuilder::map_seed_hits() auto hitidx = track.getHitIdx(ilayer); if ((hitidx>=0) && (hitidx something else .... + track.setHitIdx(ilayer, seedLayersHitMap[global_hit_vec[hitidx].mcHitID()].index, ilayer); } } } } void MkBuilder::remap_seed_hits() -{ // map seed hit indices from hit indices in structure m_event_of_hits.m_layers_of_hits[i].m_hits to global m_event->layerHits_[i] +{ + // map seed hit indices from hit indices in structure + // m_event_of_hits.m_layers_of_hits[i].m_hits to global + // m_event->layerHits_[i] + + // XXMT4K as above + HitIDVec seedLayersHitMap(m_event->simHitsInfo_.size()); for (int ilayer = 0; ilayer < Config::nlayers_per_seed; ++ilayer) { const auto & global_hit_vec = m_event->layerHits_[ilayer]; @@ -365,14 +390,21 @@ void MkBuilder::remap_seed_hits() auto hitidx = track.getHitIdx(ilayer); if ((hitidx>=0) && (hitidx something else .... + track.setHitIdx(ilayer, seedLayersHitMap[lof_m_hits[hitidx].mcHitID()].index, ilayer); } } } } void MkBuilder::remap_cand_hits() -{ // map cand hit indices from hit indices in structure m_event_of_hits.m_layers_of_hits[i].m_hits to global m_event->layerHits_[i] +{ + // map cand hit indices from hit indices in structure + // m_event_of_hits.m_layers_of_hits[i].m_hits to global + // m_event->layerHits_[i] + + // XXMT4K as above + HitIDVec candLayersHitMap(m_event->simHitsInfo_.size()); for (int ilayer = 0; ilayer < Config::nLayers; ++ilayer) { const auto & global_hit_vec = m_event->layerHits_[ilayer]; @@ -387,7 +419,8 @@ void MkBuilder::remap_cand_hits() auto hitidx = track.getHitIdx(ilayer); if ((hitidx>=0) && (hitidx something else .... + track.setHitIdx(ilayer, candLayersHitMap[lof_m_hits[hitidx].mcHitID()].index, ilayer); } } } @@ -619,7 +652,8 @@ void MkBuilder::FindTracksBestHit(EventOfCandidates& event_of_cands) tbb::parallel_for(tbb::blocked_range(0, Config::nEtaBin), [&](const tbb::blocked_range& ebins) { - for (int ebin = ebins.begin(); ebin != ebins.end(); ++ebin) { + for (int ebin = ebins.begin(); ebin != ebins.end(); ++ebin) + { EtaBinOfCandidates& etabin_of_candidates = event_of_cands.m_etabins_of_candidates[ebin]; tbb::parallel_for(tbb::blocked_range(0,etabin_of_candidates.m_fill_index,Config::numSeedsPerTask), @@ -627,7 +661,13 @@ void MkBuilder::FindTracksBestHit(EventOfCandidates& event_of_cands) { TrackerInfo &trk_info = Config::TrkInfo; std::unique_ptr mkfp(g_exe_ctx.m_fitters.GetFromPool(), retfitr); - + + int last_seed_layer = etabin_of_candidates.m_candidates[ tracks.begin() ].getLastHitLayer(); + int first_layer = trk_info.m_layers[ last_seed_layer ].m_next_barrel; + + printf("FindTracksBestHit Last seed layer = %d, First layer (eta_bin n tracks=%d) = %d\n", + last_seed_layer, etabin_of_candidates.m_fill_index, first_layer); + for (int itrack = tracks.begin(); itrack < tracks.end(); itrack += NN) { int end = std::min(itrack + NN, tracks.end()); @@ -640,7 +680,7 @@ void MkBuilder::FindTracksBestHit(EventOfCandidates& event_of_cands) // Loop over layers, starting from after the seed. // Consider inverting loop order and make layer outer, need to // trade off hit prefetching with copy-out of candidates. - for (int ilay = trk_info.m_barrel[ Config::nlayers_per_seed ]; ; ) + for (int ilay = first_layer; ; ) { LayerOfHits &layer_of_hits = m_event_of_hits.m_layers_of_hits[ilay]; LayerInfo &layer_info = trk_info.m_layers[ilay]; diff --git a/mkFit/MkBuilderEndcap.cc b/mkFit/MkBuilderEndcap.cc index f1e4b9907c501..23d643e57f40a 100644 --- a/mkFit/MkBuilderEndcap.cc +++ b/mkFit/MkBuilderEndcap.cc @@ -4,6 +4,7 @@ #include "Event.h" #include "EventTmp.h" +#include "TrackerInfo.h" #include "MkFitter.h" @@ -138,10 +139,13 @@ inline void MkBuilderEndcap::fit_one_seed_set_endcap(TrackVec& seedtracks, int i if (Config::cf_seeding) mkfp->ConformalFitTracks(false, itrack, end); if (Config::readCmsswSeeds==false) mkfp->FitTracks(end - itrack, m_event); - const int ilay = Config::nlayers_per_seed; // layer 3, we ignore PXB1 + // OLD GC: const int ilay = Config::nlayers_per_seed; // layer 3, we ignore PXB1 + TrackerInfo &trk_info = Config::TrkInfo; + int last_seed_layer = seedtracks[itrack].getLastHitLayer(); + int ilay = trk_info.m_layers[ last_seed_layer ].m_next_ecap_pos; // XXXXMT pos/neg dcall(pre_prop_print(ilay, mkfp)); - mkfp->PropagateTracksToZ(m_event->geom_.zPlane(ilay), end - itrack); + mkfp->PropagateTracksToZ(trk_info.m_layers[ilay].m_zmin, end - itrack); //XXXXMT zmin/zmax dcall(post_prop_print(ilay, mkfp)); mkfp->OutputFittedTracksAndHitIdx(m_event->seedTracks_, itrack, end, true); @@ -178,29 +182,36 @@ void MkBuilderEndcap::FindTracksBestHit(EventOfCandidates& event_of_cands) tbb::parallel_for(tbb::blocked_range(0, Config::nEtaBin), [&](const tbb::blocked_range& ebins) { - for (int ebin = ebins.begin(); ebin != ebins.end(); ++ebin) { + for (int ebin = ebins.begin(); ebin != ebins.end(); ++ebin) + { EtaBinOfCandidates& etabin_of_candidates = event_of_cands.m_etabins_of_candidates[ebin]; tbb::parallel_for(tbb::blocked_range(0,etabin_of_candidates.m_fill_index,Config::numSeedsPerTask), [&](const tbb::blocked_range& tracks) { + TrackerInfo &trk_info = Config::TrkInfo; std::unique_ptr mkfp(g_exe_ctx.m_fitters.GetFromPool(), retfitr); - for (int itrack = tracks.begin(); itrack < tracks.end(); itrack += NN) { + int last_seed_layer = etabin_of_candidates.m_candidates[ tracks.begin() ].getLastHitLayer(); + int first_layer = trk_info.m_layers[ last_seed_layer ].m_next_ecap_pos; // XXXXMT + + for (int itrack = tracks.begin(); itrack < tracks.end(); itrack += NN) + { int end = std::min(itrack + NN, tracks.end()); dprint(std::endl << "processing track=" << itrack << " etabin=" << ebin << " findex=" << etabin_of_candidates.m_fill_index); - mkfp->SetNhits(Config::nlayers_per_seed);//just to be sure (is this needed?) + mkfp->SetNhits(Config::nlayers_per_seed); // Could also count hits in first seed mkfp->InputTracksAndHitIdx(etabin_of_candidates.m_candidates, itrack, end, true); //ok now we start looping over layers //loop over layers, starting from after the seed //consider inverting loop order and make layer outer, need to trade off hit prefetching with copy-out of candidates - for (int ilay = Config::nlayers_per_seed; ilay < Config::nLayers; ++ilay) + for (int ilay = first_layer; ; ) { dprintf("processing layer %i\n",ilay); LayerOfHits &layer_of_hits = m_event_of_hits.m_layers_of_hits[ilay]; + LayerInfo &layer_info = trk_info.m_layers[ilay]; // XXX This should actually be done in some other thread for the next layer while // this thread is crunching the current one. @@ -222,13 +233,23 @@ void MkBuilderEndcap::FindTracksBestHit(EventOfCandidates& event_of_cands) mkfp->SetNhits(ilay + 1); //here again assuming one hit per layer (is this needed?) //propagate to layer - if (ilay + 1 < Config::nLayers) + if ( ! layer_info.m_is_outer) { dcall(pre_prop_print(ilay, mkfp.get())); - mkfp->PropagateTracksToZ(m_event->geom_.zPlane(ilay+1), end - itrack); + + //mkfp->PropagateTracksToZ(m_event->geom_.zPlane(ilay+1), end - itrack); + + // XXXXMT ecap_pos / neg, zmin / zmax + mkfp->PropagateTracksToR(trk_info.m_layers[layer_info.m_next_ecap_pos].m_zmin, end - itrack); + dcall(post_prop_print(ilay, mkfp.get())); } + else + { + break; + } + ilay = layer_info.m_next_ecap_pos; // XXXXMT } // end of layer loop mkfp->OutputFittedTracksAndHitIdx(etabin_of_candidates.m_candidates, itrack, end, true); } diff --git a/mkFit/MkFitter.cc b/mkFit/MkFitter.cc index 8accd7221d47a..e5fdf6b1c1c59 100644 --- a/mkFit/MkFitter.cc +++ b/mkFit/MkFitter.cc @@ -37,7 +37,7 @@ int MkFitter::countValidHits(int itrack, int end_hit) const int result = 0; for (int hi = 0; hi < end_hit; ++hi) { - if (HitsIdx[hi](itrack, 0, 0) >= 0) result++; + if (HoTArr[hi](itrack, 0, 0).index >= 0) result++; } return result; } @@ -48,7 +48,7 @@ int MkFitter::countInvalidHits(int itrack, int end_hit) const for (int hi = 0; hi < end_hit; ++hi) { // XXXX MT: Should also count -2 hits as invalid? - if (HitsIdx[hi](itrack, 0, 0) == -1) result++; + if (HoTArr[hi](itrack, 0, 0).index == -1) result++; } return result; } @@ -95,12 +95,12 @@ void MkFitter::InputTracksAndHits(const std::vector& tracks, //#ifndef USE_CUDA for (int hi = 0; hi < Nhits; ++hi) { - const int hidx = trk.getHitIdx(hi); - const Hit &hit = layerHits[hi][hidx]; + HoTArr[hi](itrack, 0, 0) = trk.getHitOnTrack(hi); - HitsIdx[hi](itrack, 0, 0) = hidx; - if (hidx<0) continue; + const int hidx = trk.getHitIdx(hi); + if (hidx < 0) continue; + const Hit &hit = layerHits[hi][hidx]; msErr[hi].CopyIn(itrack, hit.errArray()); msPar[hi].CopyIn(itrack, hit.posArray()); } @@ -151,7 +151,8 @@ void MkFitter::InputTracksAndHits(const std::vector& tracks, msErr[hi].CopyIn(itrack, hit.errArray()); msPar[hi].CopyIn(itrack, hit.posArray()); - HitsIdx[hi](itrack, 0, 0) = hidx; + + HoTArr[hi](itrack, 0, 0) = trk.getHitOnTrack(hi); } #endif } @@ -223,7 +224,7 @@ void MkFitter::SlurpInTracksAndHits(const std::vector& tracks, const Hit &hit = layerHits[hi][hidx]; itrack = i - beg; idx[itrack] = (char*) &hit - varr; - HitsIdx[hi](itrack, 0, 0) = hidx; + HoTArr[hi](itrack, 0, 0) = tracks[i].getHitOnTrack(hi); } #ifdef MIC_INTRINSICS @@ -263,7 +264,7 @@ void MkFitter::InputTracksAndHitIdx(const std::vector& tracks, for (int hi = 0; hi < Nhits; ++hi) { - HitsIdx[hi](itrack, 0, 0) = trk.getHitIdx(hi); + HoTArr[hi](itrack, 0, 0) = trk.getHitOnTrack(hi); } } } @@ -296,9 +297,7 @@ void MkFitter::InputTracksAndHitIdx(const std::vector >& trac for (int hi = 0; hi < Nhits; ++hi) { - - HitsIdx[hi](itrack, 0, 0) = trk.getHitIdx(hi);//dummy value for now - + HoTArr[hi](itrack, 0, 0) = trk.getHitOnTrack(hi); } } } @@ -346,11 +345,12 @@ void MkFitter::InputSeedsTracksAndHits(const std::vector& seeds, #if 1 for (int hi = 0; hi < Nhits; ++hi) { + HoTArr[hi](itrack, 0, 0) = trk.getHitOnTrack(hi); + const int hidx = trk.getHitIdx(hi); - HitsIdx[hi](itrack, 0, 0) = hidx; - if (hidx<0) continue;//fixme, check if this is harmless - const Hit &hit = layerHits[hi][hidx]; + if (hidx < 0) continue; //fixme, check if this is harmless + const Hit &hit = layerHits[hi][hidx]; msErr[hi].CopyIn(itrack, hit.errArray()); msPar[hi].CopyIn(itrack, hit.posArray()); } @@ -367,12 +367,16 @@ void MkFitter::InputTracksForFit(const std::vector& tracks, { // Loads track parameters and hit indices. + // XXXXMT4K has Config::nLayers: How many hits do we read in? + // Check for max? Expect an argument? + // What to do with invalid hits? Skip? + const int N_proc = end - beg; const Track &trk0 = tracks[beg]; const char *varr = (char*) &trk0; const int off_error = (char*) trk0.errors().Array() - varr; const int off_param = (char*) trk0.parameters().Array() - varr; - const int off_hitidx = (char*) trk0.getHitIdxArray() - varr; + const int off_hitidx = (char*) trk0.getHitsOnTrackArray() - varr; int idx[NN] __attribute__((aligned(64))); @@ -397,14 +401,14 @@ void MkFitter::InputTracksForFit(const std::vector& tracks, Par[iC].SlurpIn(varr + off_param, vi, N_proc); for (int ll = 0; ll < Config::nLayers; ++ll) { - HitsIdx[ll].SlurpIn(varr + off_hitidx + sizeof(int)*ll, vi, N_proc); + HoTArr[ll].SlurpIn(varr + off_hitidx + sizeof(int)*ll, vi, N_proc); } #else Err[iC].SlurpIn(varr + off_error, idx, N_proc); Par[iC].SlurpIn(varr + off_param, idx, N_proc); for (int ll = 0; ll < Config::nLayers; ++ll) { - HitsIdx[ll].SlurpIn(varr + off_hitidx + sizeof(int)*ll, idx, N_proc); + HoTArr[ll].SlurpIn(varr + off_hitidx + sizeof(int)*ll, idx, N_proc); } #endif } @@ -418,18 +422,24 @@ void MkFitter::FitTracksWithInterSlurp(const std::vector& layersohits, int idx[NN] __attribute__((aligned(64))); - for (int layer = 0; layer < Nhits; ++layer) + for (int ii = 0; ii < Nhits; ++ii) { - const Hit &hit0 = layersohits[layer][0]; + const Hit &hit0 = layersohits[ii][0]; const char *varr = (char*) &hit0; const int off_param = (char*) hit0.posArray() - varr; const int off_error = (char*) hit0.errArray() - varr; for (int i = 0; i < N_proc; ++i) { - const int hidx = HitsIdx[layer](i, 0, 0); + const int hidx = HoTArr[ii](i, 0, 0).index; + const int hlyr = HoTArr[ii](i, 0, 0).layer; - idx[i] = (char*) & layersohits[layer][hidx] - varr; + // XXXXMT4K What to do with hidx < 0 ???? + // This could solve the unbalanced fit. + // Or, if the hidx is the "universal" missing hit, it could just work. + // Say, hidx = 0 ... grr ... but then we don't know it is missing. + + idx[i] = (char*) & layersohits[hlyr][hidx] - varr; } // for (int i = N_proc; i < NN; ++i) { idx[i] = idx[0]; } @@ -574,8 +584,8 @@ void MkFitter::FitTracksTestEndcap(const int N_proc, const Event* ev, const bool { //if starting from seed, skip seed hits in fit (note there are only two hits in seeds since pxb1 is removed upfront, at least for now) - if (Config::readCmsswSeeds && hi<2) continue; - if (HitsIdx[hi].ConstAt(0, 0, 0)<0) continue; + if (Config::readCmsswSeeds && hi < 2) continue; + if (HoTArr[hi].ConstAt(0, 0, 0).index < 0) continue; dprint("hit #" << hi << " hit pos=" << msPar[hi].ConstAt(0, 0, 0) << ", " << msPar[hi].ConstAt(0, 0, 1) << ", " << msPar[hi].ConstAt(0, 0, 2)); @@ -656,7 +666,7 @@ void MkFitter::OutputFittedTracksAndHitIdx(std::vector& tracks, int beg, tracks[i].resetHits(); for (int hi = 0; hi < Nhits; ++hi) { - tracks[i].addHitIdx(HitsIdx[hi](itrack, 0, 0),0.); + tracks[i].addHitIdx(HoTArr[hi](itrack, 0, 0), 0.); } } } @@ -963,7 +973,7 @@ void MkFitter::AddBestHit(const LayerOfHits &layer_of_hits, const int N_proc) msErr[Nhits].CopyIn(itrack, hit.errArray()); msPar[Nhits].CopyIn(itrack, hit.posArray()); Chi2(itrack, 0, 0) += chi2; - HitsIdx[Nhits](itrack, 0, 0) = bestHit[itrack]; + HoTArr[Nhits](itrack, 0, 0) = { bestHit[itrack], layer_of_hits.m_layer_id }; } else { @@ -973,7 +983,7 @@ void MkFitter::AddBestHit(const LayerOfHits &layer_of_hits, const int N_proc) msPar[Nhits](itrack,0,0) = Par[iP](itrack,0,0); msPar[Nhits](itrack,1,0) = Par[iP](itrack,1,0); msPar[Nhits](itrack,2,0) = Par[iP](itrack,2,0); - HitsIdx[Nhits](itrack, 0, 0) = -1; + HoTArr[Nhits](itrack, 0, 0) = { -1, layer_of_hits.m_layer_id }; // Don't update chi2 } @@ -1112,9 +1122,9 @@ void MkFitter::FindCandidates(const LayerOfHits &layer_of_hits, newcand.setChi2(Chi2(itrack, 0, 0)); for (int hi = 0; hi < Nhits; ++hi) { - newcand.addHitIdx(HitsIdx[hi](itrack, 0, 0),0.);//this should be ok since we already set the chi2 above + newcand.addHitIdx(HoTArr[hi](itrack, 0, 0),0.);//this should be ok since we already set the chi2 above } - newcand.addHitIdx(XHitArr.At(itrack, hit_cnt, 0), chi2); + newcand.addHitIdx(XHitArr.At(itrack, hit_cnt, 0), layer_of_hits.m_layer_id, chi2); newcand.setLabel(Label(itrack, 0, 0)); //set the track state to the updated parameters Err[iC].CopyOut(itrack, newcand.errors_nc().Array()); @@ -1141,9 +1151,9 @@ void MkFitter::FindCandidates(const LayerOfHits &layer_of_hits, newcand.setChi2(Chi2(itrack, 0, 0)); for (int hi = 0; hi < Nhits; ++hi) { - newcand.addHitIdx(HitsIdx[hi](itrack, 0, 0),0.);//this should be ok since we already set the chi2 above + newcand.addHitIdx(HoTArr[hi](itrack, 0, 0),0.);//this should be ok since we already set the chi2 above } - newcand.addHitIdx(hit_idx, 0.); + newcand.addHitIdx(hit_idx, layer_of_hits.m_layer_id, 0.); newcand.setLabel(Label(itrack, 0, 0)); //set the track state to the propagated parameters Err[iP].CopyOut(itrack, newcand.errors_nc().Array()); @@ -1276,9 +1286,9 @@ void MkFitter::FindCandidatesEndcap(const LayerOfHits &layer_of_hits, newcand.setChi2(Chi2(itrack, 0, 0)); for (int hi = 0; hi < Nhits; ++hi) { - newcand.addHitIdx(HitsIdx[hi](itrack, 0, 0),0.);//this should be ok since we already set the chi2 above + newcand.addHitIdx(HoTArr[hi](itrack, 0, 0), 0.);//this should be ok since we already set the chi2 above } - newcand.addHitIdx(XHitArr.At(itrack, hit_cnt, 0), chi2); + newcand.addHitIdx(XHitArr.At(itrack, hit_cnt, 0), layer_of_hits.m_layer_id, chi2); newcand.setLabel(Label(itrack, 0, 0)); //set the track state to the updated parameters Err[iC].CopyOut(itrack, newcand.errors_nc().Array()); @@ -1300,6 +1310,7 @@ void MkFitter::FindCandidatesEndcap(const LayerOfHits &layer_of_hits, { int hit_idx = countInvalidHits(itrack) < Config::maxHolesPerCand ? -1 : -2; + // XXXXMT4K Grrrr ... this is cmssw specific, sigh bool withinBounds = true; float r2 = Par[iP](itrack,0,0)*Par[iP](itrack,0,0)+Par[iP](itrack,1,0)*Par[iP](itrack,1,0); if ( r2<(Config::cmsDiskMinRs[Nhits]*Config::cmsDiskMinRs[Nhits]) || @@ -1315,14 +1326,14 @@ void MkFitter::FindCandidatesEndcap(const LayerOfHits &layer_of_hits, newcand.setChi2(Chi2(itrack, 0, 0)); for (int hi = 0; hi < Nhits; ++hi) { - newcand.addHitIdx(HitsIdx[hi](itrack, 0, 0),0.);//this should be ok since we already set the chi2 above + newcand.addHitIdx(HoTArr[hi](itrack, 0, 0), 0.);//this should be ok since we already set the chi2 above } - newcand.addHitIdx(hit_idx, 0.); + newcand.addHitIdx(hit_idx, layer_of_hits.m_layer_id, 0.); newcand.setLabel(Label(itrack, 0, 0)); - //set the track state to the propagated parameters + // set the track state to the propagated parameters Err[iP].CopyOut(itrack, newcand.errors_nc().Array()); Par[iP].CopyOut(itrack, newcand.parameters_nc().Array()); - tmp_candidates[SeedIdx(itrack, 0, 0)-offset].push_back(newcand); + tmp_candidates[SeedIdx(itrack, 0, 0) - offset].push_back(newcand); } } @@ -1498,7 +1509,7 @@ void MkFitter::InputTracksAndHitIdx(const std::vector >& trac for (int hi = 0; hi < Nhits; ++hi) { - HitsIdx[hi](itrack, 0, 0) = trk.getHitIdx(hi);//dummy value for now + HoTArr[hi](itrack, 0, 0) = trk.getHitOnTrack(hi); } } } @@ -1506,9 +1517,11 @@ void MkFitter::InputTracksAndHitIdx(const std::vector >& trac void MkFitter::UpdateWithLastHit(const LayerOfHits &layer_of_hits, int N_proc) { + // layer_of_hits is for previous layer! + for (int i = 0; i < N_proc; ++i) { - int hit_idx = HitsIdx[Nhits - 1](i, 0, 0); + int hit_idx = HoTArr[Nhits - 1](i, 0, 0).index; if (hit_idx < 0) continue; @@ -1527,7 +1540,7 @@ void MkFitter::UpdateWithLastHit(const LayerOfHits &layer_of_hits, int N_proc) for (int i = 0; i < N_proc; ++i) { - if (HitsIdx[Nhits - 1](i, 0, 0) < 0) + if (HoTArr[Nhits - 1](i, 0, 0).index < 0) { float tmp[21]; Err[iP].CopyOut(i, tmp); @@ -1542,7 +1555,7 @@ void MkFitter::UpdateWithLastHitEndcap(const LayerOfHits &layer_of_hits, int N_p { for (int i = 0; i < N_proc; ++i) { - int hit_idx = HitsIdx[Nhits - 1](i, 0, 0); + int hit_idx = HoTArr[Nhits - 1](i, 0, 0).index; if (hit_idx < 0) continue; @@ -1561,7 +1574,7 @@ void MkFitter::UpdateWithLastHitEndcap(const LayerOfHits &layer_of_hits, int N_p for (int i = 0; i < N_proc; ++i) { - if (HitsIdx[Nhits - 1](i, 0, 0) < 0) + if (HoTArr[Nhits - 1](i, 0, 0).index < 0) { float tmp[21]; Err[iP].CopyOut(i, tmp); @@ -1590,8 +1603,7 @@ void MkFitter::CopyOutParErr(std::vector >& seed_cand_vec, << " y=" << cand.parameters()[1] << " z=" << cand.parameters()[2] << " pt=" << 1./cand.parameters()[3] - << " posEta=" << cand.posEta() - << " etaBin=" << getEtaBin(cand.posEta())); + << " posEta=" << cand.posEta()); } } @@ -1890,7 +1902,7 @@ void MkFitter::AddBestHitEndcap(const LayerOfHits &layer_of_hits, const int N_pr msErr[Nhits].CopyIn(itrack, hit.errArray()); msPar[Nhits].CopyIn(itrack, hit.posArray()); Chi2(itrack, 0, 0) += chi2; - HitsIdx[Nhits](itrack, 0, 0) = bestHit[itrack]; + HoTArr[Nhits](itrack, 0, 0) = { bestHit[itrack], layer_of_hits.m_layer_id }; } else { @@ -1914,7 +1926,7 @@ void MkFitter::AddBestHitEndcap(const LayerOfHits &layer_of_hits, const int N_pr msPar[Nhits](itrack,1,0) = Par[iP](itrack,1,0); msPar[Nhits](itrack,2,0) = Par[iP](itrack,2,0); //-3 means we did not expect any hit since we are out of bounds, so it does not count in countInvalidHits - HitsIdx[Nhits](itrack, 0, 0) = withinBounds ? -1 : -3; + HoTArr[Nhits](itrack, 0, 0) = { withinBounds ? -1 : -3, layer_of_hits.m_layer_id }; // Don't update chi2 } diff --git a/mkFit/MkFitter.h b/mkFit/MkFitter.h index d56a95a824847..c0e8c5984ee4f 100644 --- a/mkFit/MkFitter.h +++ b/mkFit/MkFitter.h @@ -6,7 +6,6 @@ #include "KalmanUtils.h" #include "HitStructures.h" -#include "BinInfoUtils.h" #if USE_CUDA #include "FitterCU.h" @@ -20,7 +19,8 @@ class CandCloner; const int MPlexHitIdxMax = 16; -typedef Matriplex::Matriplex MPlexHitIdx; +using MPlexHitIdx = Matriplex::Matriplex; +using MPlexQHoT = Matriplex::Matriplex; struct MkFitter { @@ -31,13 +31,14 @@ struct MkFitter MPlexQF Chi2; - MPlexHS msErr[Config::nLayers]; - MPlexHV msPar[Config::nLayers]; + MPlexHS msErr[Config::nMaxTrkHits]; + MPlexHV msPar[Config::nMaxTrkHits]; MPlexQI Label; //this is the seed index in global seed vector (for MC truth match) MPlexQI SeedIdx;//this is the seed index in local thread (for bookkeeping at thread level) MPlexQI CandIdx;//this is the candidate index for the given seed (for bookkeeping of clone engine) - MPlexQI HitsIdx[Config::nLayers]; + + MPlexQHoT HoTArr[Config::nMaxTrkHits]; // Hold hit indices to explore at current layer. MPlexQI XHitSize; @@ -78,7 +79,7 @@ struct MkFitter void InputTracksAndHits(const std::vector& tracks, const std::vector& layerHits, int beg, int end); void InputTracksAndHits(const std::vector& tracks, const std::vector& layerHits, int beg, int end); - void SlurpInTracksAndHits(const std::vector& tracks, const std::vector& layerHits, int beg, int end); + void SlurpInTracksAndHits(const std::vector& tracks, const std::vector& layerHits, int beg, int end); void InputTracksAndHitIdx(const std::vector& tracks, int beg, int end, bool inputProp); void InputTracksAndHitIdx(const std::vector >& tracks, const std::vector >& idxs, diff --git a/mkFit/buildtestMPlex.cc b/mkFit/buildtestMPlex.cc index 847e0d7bf2926..103d228531db4 100644 --- a/mkFit/buildtestMPlex.cc +++ b/mkFit/buildtestMPlex.cc @@ -4,7 +4,6 @@ #include "KalmanUtils.h" #include "Propagation.h" #include "Simulation.h" -#include "BinInfoUtils.h" #include "MkBuilder.h" diff --git a/mkFit/fittestMPlex.cc b/mkFit/fittestMPlex.cc index ae354dd20db7b..ba7c16dfd83e2 100644 --- a/mkFit/fittestMPlex.cc +++ b/mkFit/fittestMPlex.cc @@ -159,8 +159,6 @@ double runFittingTestPlex(Event& ev, std::vector& rectracks) mkfp->InputTracksAndHits(simtracks, ev.layerHits_, itrack, end); } mkfp->FitTracksTestEndcap(end - itrack, &ev, true); - } else { - mkfp->FitTracksTestEndcap(end - itrack, &ev); } else { diff --git a/mkFit/mkFit.cc b/mkFit/mkFit.cc index 90057c61eec6a..32e555aa25b5b 100644 --- a/mkFit/mkFit.cc +++ b/mkFit/mkFit.cc @@ -188,18 +188,6 @@ void close_simtrack_file() void test_standard() { - // ---- MT test eta bins - // int nb, b1, b2; - // for (float eta = -1.2; eta <= 1.2; eta += 0.01) - // { - // nb = getBothEtaBins(eta, b1, b2); - // printf("eta=%6.2f bin=%3d bin1=%3d bin2=%3d nb=%d\n", - // eta, getEtaBin(eta), b1, b2, nb); - // } - - // return; - // ---- end MT test - printf("Running test_standard(), operation=\"%s\"\n", g_operation.c_str()); printf(" vusize=%d, num_th_sim=%d, num_th_finder=%d\n", MPT_SIZE, Config::numThreadsSimulation, Config::numThreadsFinder); diff --git a/seedtest.cc b/seedtest.cc index c52a5dfe5666a..74718170aea7c 100644 --- a/seedtest.cc +++ b/seedtest.cc @@ -11,7 +11,11 @@ inline float predz(const float z0, const float r0, const float z2, const float r return (predr-r0)*(z2-z0) / (r2-r0) + z0; } -void buildSeedsByMC(const TrackVec& evt_sim_tracks, TrackVec& evt_seed_tracks, TrackExtraVec& evt_seed_extras, Event& ev){ +void buildSeedsByMC(const TrackVec& evt_sim_tracks, TrackVec& evt_seed_tracks, TrackExtraVec& evt_seed_extras, Event& ev) +{ + fprintf(stderr, "__FILE__::__LINE__ Needs fixing for B/E support, search for XXMT4K\n"); + exit(1); + #ifdef DEBUG bool debug(true); #endif @@ -57,9 +61,10 @@ void buildSeedsByMC(const TrackVec& evt_sim_tracks, TrackVec& evt_seed_tracks, T } ev.validation_.collectSeedTkTSLayerPairVecMapInfo(itrack,updatedStates); // use to collect position pull info - Track seed(updatedState,0.0f,itrack,Config::nlayers_per_seed,seedhits);//fixme chi2 (could use sumchi2) - dprint("created seed track # " << itrack << " par=" << seed.parameters()); - evt_seed_tracks.push_back(seed); + // XXMT4K: Here will need layer indices, too now. + // XX Track seed(updatedState,0.0f,itrack,Config::nlayers_per_seed,seedhits);//fixme chi2 (could use sumchi2) + // XX dprint("created seed track # " << itrack << " par=" << seed.parameters()); + // XX evt_seed_tracks.push_back(seed); evt_seed_extras.emplace_back(itrack); } } @@ -218,7 +223,11 @@ void buildSeedsByRoadTriplets(TrackVec& evt_seed_tracks, TrackExtraVec& evt_seed } void buildSeedsByRoadSearch(TrackVec& evt_seed_tracks, TrackExtraVec& evt_seed_extras, - const std::vector& evt_lay_hits, const BinInfoMap& segmentMap, Event& ev){ + const std::vector& evt_lay_hits, const BinInfoMap& segmentMap, Event& ev) +{ + fprintf(stderr, "__FILE__::__LINE__ Needs fixing for B/E support, search for XXMT4K\n"); + exit(1); + // use this to initialize tracks const TrackState dummystate; @@ -294,13 +303,14 @@ void buildSeedsByRoadSearch(TrackVec& evt_seed_tracks, TrackExtraVec& evt_seed_e // create a track object int hitIndices[3] = {ihit0,ihit1,ihit2}; - Track seed(dummystate,0.0f,seedID,Config::nlayers_per_seed,hitIndices); // argh! super not type-safe with dummystate + // XXMT4K: Here will need layer indices, too now. + // XX Track seed(dummystate,0.0f,seedID,Config::nlayers_per_seed,hitIndices); // argh! super not type-safe with dummystate // estimate and set the charge - seed.setCharge(calculateCharge(hit0,hit1,hit2)); + // XX seed.setCharge(calculateCharge(hit0,hit1,hit2)); // save the track and track extra - evt_seed_tracks.push_back(seed); + // XX evt_seed_tracks.push_back(seed); evt_seed_extras.emplace_back(seedID); // increment dummy counter for seedID @@ -550,7 +560,11 @@ void filterHitTripletsByRZChi2(const std::vector& evt_lay_hits, const Tr } void buildSeedsFromTriplets(const std::vector& evt_lay_hits, const TripletIdxVec& filtered_triplets, - TrackVec& evt_seed_tracks, TrackExtraVec& evt_seed_extras, Event& ev){ + TrackVec& evt_seed_tracks, TrackExtraVec& evt_seed_extras, Event& ev) +{ + fprintf(stderr, "__FILE__::__LINE__ Needs fixing for B/E support, search for XXMT4K\n"); + exit(1); + // now perform kalman fit on seeds --> first need initial parameters --> get from Conformal fitter! unsigned int seedID = 0; for(auto&& hit_triplet : filtered_triplets){ @@ -571,7 +585,8 @@ void buildSeedsFromTriplets(const std::vector& evt_lay_hits, const Tripl TSLayerPairVec updatedStates; // validation for position pulls float sumchi2 = 0; - for (auto ilayer=0;ilayer& evt_lay_hits, const Tripl ev.validation_.collectSeedTkTSLayerPairVecMapInfo(seedID,updatedStates); // use to collect position pull info int hitIndices[3] = {hit_triplet[0],hit_triplet[1],hit_triplet[2]}; - Track seed(updatedState,sumchi2,seedID,Config::nlayers_per_seed,hitIndices);//fixme chi2 - evt_seed_tracks.push_back(seed); + // XXMT4K: Here will need layer indices, too now. + // XX Track seed(updatedState, sumchi2, seedID, Config::nlayers_per_seed, hitIndices);//fixme chi2 + // XX evt_seed_tracks.push_back(seed); evt_seed_extras.emplace_back(seedID); seedID++; // increment dummy counter for seedID } From 9c1768b2868efa162f5aa4ca7eda4852e15ec1fa Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Mon, 6 Mar 2017 15:20:30 -0800 Subject: [PATCH 007/172] Implement sim stepping based on safety in dR in a more obvious way. --- Geometry.cc | 24 ++++++++---------------- Geometry.h | 6 +++--- Propagation.cc | 13 ++++++++----- SimpleGeom.cc | 14 +++++++++++++- SimpleGeom.h | 1 + 5 files changed, 33 insertions(+), 25 deletions(-) diff --git a/Geometry.cc b/Geometry.cc index 7f87458d75153..e46caaa856b93 100644 --- a/Geometry.cc +++ b/Geometry.cc @@ -63,32 +63,24 @@ double Geometry::SafetyFromOutside ( const UVector3 &aPoint, bool aAccurate) con return small; } -double Geometry::SafetyFromOutside2(const UVector3 &aPoint, double ctgTheta, - int skip_layer, int &layer, bool aAccurate) const +double Geometry::SafetyFromOutsideDr(const UVector3 &aPoint, double ooaCtgTheta, + int skip_layer, int &layer, bool aAccurate) const { - bool debug = true; + bool debug = false; double small = 1e10; - dprintf("Geometry::SafetyFromOutside2 r=%f, z=%f\n", aPoint.Perp(), aPoint.Z()); + dprintf("Geometry::SafetyFromOutsideDr r=%f, z=%f\n", aPoint.Perp(), aPoint.Z()); int ii = 0; layer = -1; for (auto i = solids_.begin(); i != solids_.end(); ++i, ++ii) { if (ii != skip_layer && (*i)->Inside(aPoint) == VUSolid::eOutside) { - double next = (*i)->SafetyFromOutside(aPoint, aAccurate); - if ( ! (*i)->is_barrel_) - { - double fnext = next; - next /= std::abs(ctgTheta); - if (next < 15) dprintf(" Radial distance to %2d = %4.5f (not ecap corrected %4.5f)\n", ii, next, fnext); - } - else - { - if (next < 15) dprintf(" Radial distance to %2d = %4.5f\n", ii, next); - } - + double next = (*i)->SafetyFromOutsideDr(aPoint, ooaCtgTheta, aAccurate); +#ifdef DEBUG + if (next < 15) dprintf(" Radial distance to %2d = %4.5f\n", ii, next); +#endif if (next < small) { small = next; layer = ii; } } } diff --git a/Geometry.h b/Geometry.h index a9a73f6a3a5bc..37bf5cd129dc0 100644 --- a/Geometry.h +++ b/Geometry.h @@ -34,9 +34,9 @@ class Geometry VUSolid::EnumInside Inside (const UVector3 &aPoint) const; int LayerIndex(const UVector3 &aPoint) const; const VUSolid* InsideWhat(const UVector3 &aPoint) const; - double SafetyFromInside ( const UVector3 &aPoint, bool aAccurate=false) const; - double SafetyFromOutside ( const UVector3 &aPoint, bool aAccurate=false) const; - double SafetyFromOutside2( const UVector3 &aPoint, double ctgTheta, int skip_layer, int &layer, bool aAccurate=false) const; + double SafetyFromInside ( const UVector3 &aPoint, bool aAccurate=false) const; + double SafetyFromOutside ( const UVector3 &aPoint, bool aAccurate=false) const; + double SafetyFromOutsideDr( const UVector3 &aPoint, double ooaCtgTheta, int skip_layer, int &layer, bool aAccurate=false) const; Geometry clone() const; void BuildFromTrackerInfo(const TrackerInfo& tracker_info); diff --git a/Propagation.cc b/Propagation.cc index b2792051d959d..126ee699cf150 100644 --- a/Propagation.cc +++ b/Propagation.cc @@ -1,5 +1,5 @@ #include "Propagation.h" -#define DEBUG +//#define DEBUG #include "Debug.h" const double tolerance = 0.001; @@ -256,7 +256,8 @@ TrackState propagateHelixToNextSolid(TrackState inputState, const Geometry& geom if (hsin.r0 > 1.0 && ! startSolid) { UVector3 here(hsin.x,hsin.y,hsin.z); - for ( int i = 0; i < Config::nTotalLayers; ++i ) { + for ( int i = 0; i < Config::nTotalLayers; ++i ) + { auto d = geom.Layer(i)->SafetyFromOutside(here, true); if (d < tolerance) { startSolid = geom.Layer(i); @@ -277,17 +278,19 @@ TrackState propagateHelixToNextSolid(TrackState inputState, const Geometry& geom int prev_solid; int skip_solid = geom.LayerOfSolid(startSolid); + const double ooaCtgTheta = 1.0 / std::abs(hsout.ctgTheta); + for (int i = 0; i < Config::NiterSim; ++i) { dprint("propagation iteration #" << i); redo_safety: int solid; - double distance = geom.SafetyFromOutside2(UVector3(hsout.x,hsout.y,hsout.z), - hsout.ctgTheta, skip_solid, solid, true); + double distance = geom.SafetyFromOutsideDr(UVector3(hsout.x,hsout.y,hsout.z), + ooaCtgTheta, skip_solid, solid, true); distance = std::max(distance, geom.Layer(solid)->is_barrel_ ? - tolerance : tolerance / std::abs(hsout.ctgTheta)); + tolerance : tolerance * ooaCtgTheta); if (i > 0) { diff --git a/SimpleGeom.cc b/SimpleGeom.cc index 4bc7cf54d910a..eefd032c7043d 100644 --- a/SimpleGeom.cc +++ b/SimpleGeom.cc @@ -21,7 +21,6 @@ double VUSolid::SafetyFromInside (const UVector3 &aPoint, bool) const if (zmin_ < z && z < zmax_) { double dr = std::min(r - rin_, rout_ - r); - // XXXX return std::hypot(dr, std::min(z - zmin_, zmax_ - z)); return std::max(dr, std::min(z - zmin_, zmax_ - z)); } } @@ -41,6 +40,19 @@ double VUSolid::SafetyFromOutside(const UVector3 &aPoint, bool) const return std::max(dr, dz); } +double VUSolid::SafetyFromOutsideDr(const UVector3 &aPoint, double ooaCtgTheta, bool) const +{ + double r = aPoint.Perp(), z = aPoint.Z(), dr, dz; + if (r < rin_) dr = rin_ - r; + else if (r > rout_) dr = r - rout_; + else dr = 0; + if (z < zmin_) dz = zmin_ - z; + else if (z > zmax_) dz = z - zmax_; + else dz = 0; + + return std::max(dr, dz * ooaCtgTheta); +} + bool VUSolid::Normal(const UVector3& aPoint, UVector3 &aNormal) const { const double tol = 1e-6; diff --git a/SimpleGeom.h b/SimpleGeom.h index ef3879b06d77a..136d677bcc685 100644 --- a/SimpleGeom.h +++ b/SimpleGeom.h @@ -64,6 +64,7 @@ class VUSolid EnumInside Inside (const UVector3 &aPoint) const; double SafetyFromInside (const UVector3 &aPoint, bool aAccurate=false) const; double SafetyFromOutside(const UVector3 &aPoint, bool aAccurate=false) const; + double SafetyFromOutsideDr(const UVector3 &aPoint, double ooaCtgTheta, bool aAccurate=false) const; bool Normal(const UVector3& aPoint, UVector3 &aNormal) const; VUSolid* Clone() const {return new VUSolid(rin_, rout_, zmin_, zmax_, is_barrel_, is_outer_);} From e56096d2a22d962755ccb1c6ec709478ccac6ba0 Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Thu, 23 Mar 2017 11:59:13 -0700 Subject: [PATCH 008/172] Barrel / endcap tracking, 1st stage. Summary: 1. Most of the structures are in place, best-hit finding works. 2. Did some initial work on structures for std and clone-eng finding. Implemented tracking regions and relevant SteeringParams (mainly pointers to members). See SteeringParams.h and their initialization in MkBuilder constructor. Sorting and fitting of seeds coming from cyl cow mc. This is somewhat complicated as we need to fit seeds with different barrel / endcap layers. Implemented fitting with barrel / endcap per layer steering, see MkFitter::FitTracksSteered(). FindBestHit() works for combined barrel/endcap. --- Config.h | 21 +- CylCowWLids.cc | 26 +- Event.cc | 28 +- Event.h | 4 + Geometry.cc | 2 +- Makefile.config | 2 +- Simulation.cc | 53 ++- Track.h | 13 +- TrackerInfo.cc | 14 + TrackerInfo.h | 70 ++- mkFit/CandCloner.cc | 2 +- mkFit/CandCloner.h | 6 +- mkFit/HitStructures.cc | 19 +- mkFit/HitStructures.h | 110 +++-- mkFit/MkBuilder.cc | 891 ++++++++++++++++++++++++++------------ mkFit/MkBuilder.h | 24 +- mkFit/MkBuilderEndcap.cc | 28 +- mkFit/MkBuilderEndcap.h | 4 +- mkFit/MkFitter.cc | 85 +++- mkFit/MkFitter.h | 1 + mkFit/PropagationMPlex.cc | 15 +- mkFit/buildtestMPlex.cc | 18 +- mkFit/mkFit.cc | 15 +- test/CylCowWLids.C | 4 +- 24 files changed, 980 insertions(+), 475 deletions(-) diff --git a/Config.h b/Config.h index 42bdf0d555afa..c6488757a468f 100644 --- a/Config.h +++ b/Config.h @@ -135,23 +135,23 @@ namespace Config constexpr float minDZ = 0.; // default: 0.; cmssw tests: 10.; // Configuration for simulation info - //CMS beam spot width 25um in xy and 5cm in z + // CMS beam spot width 25um in xy and 5cm in z constexpr float beamspotX = 0.1; constexpr float beamspotY = 0.1; constexpr float beamspotZ = 1.0; - - constexpr float minSimPt = 1; // 0.5; + + // XXMT4K minPt was 0.5. Figure out what is the new limit for 90cm or be + // more flexible about finding fewer hits. Or postprocess looper candidates. + constexpr float minSimPt = 1; constexpr float maxSimPt = 10.; - //constexpr float minSimEta = 0.0; // XXMT4K Added min, too. - //constexpr float maxSimEta = 0.9;//2.4; // Should both become config vars? - // ECAP TEST pz > 0 only -- commented out 50% pz sign flip in Simulation!!!! - constexpr float minSimEta = 1.4; - constexpr float maxSimEta = 2.4; + // XXMT Hardhack -- transition region excluded in Simulation::setupTrackByToyMC() + constexpr float minSimEta = -2.4; + constexpr float maxSimEta = 2.4; constexpr float hitposerrXY = 0.01; // resolution is 100um in xy --> more realistic scenario is 0.003 - constexpr float hitposerrZ = 0.1; // resolution is 1mm in z - constexpr float hitposerrR = Config::hitposerrXY / 10.0f; + constexpr float hitposerrZ = 0.1; // resolution is 1mm in z + constexpr float hitposerrR = Config::hitposerrXY / 10.0f; // XXMT4K ??? I don't get this ... constexpr float varXY = Config::hitposerrXY * Config::hitposerrXY; constexpr float varZ = Config::hitposerrZ * Config::hitposerrZ; constexpr float varR = Config::hitposerrR * Config::hitposerrR; @@ -168,6 +168,7 @@ namespace Config // Config for seeding extern int nlayers_per_seed; + constexpr int nlayers_per_seed_max = 3; // Needed for allocation of arrays on stack. constexpr float chi2seedcut = 9.0; constexpr float lay01angdiff = 0.0634888; // analytically derived... depends on geometry of detector --> from mathematica ... d0 set to one sigma of getHypot(bsX,bsY) constexpr float lay02angdiff = 0.11537; diff --git a/CylCowWLids.cc b/CylCowWLids.cc index 40ca9439f9188..112b0412e57f3 100644 --- a/CylCowWLids.cc +++ b/CylCowWLids.cc @@ -44,6 +44,8 @@ namespace LayerInfo & li = m_trkinfo.m_layers[lid]; + li.m_layer_type = LayerInfo::Barrel; + li.m_rin = r - m_det_half_thickness; li.m_rout = r + m_det_half_thickness; li.m_zmin = -z; @@ -53,7 +55,10 @@ namespace li.m_next_ecap_pos = lid < 9 ? lid + 1 + 9 : -1; li.m_next_ecap_neg = lid < 9 ? lid + 1 + 18 : -1; - li.m_is_barrel = true; + li.m_sibl_barrel = -1; + li.m_sibl_ecap_pos = lid > 0 ? lid + 9 : -1; + li.m_sibl_ecap_neg = lid > 0 ? lid + 18 : -1; + li.m_is_outer = (lid == 9); } @@ -80,6 +85,8 @@ namespace { LayerInfo & li = m_trkinfo.m_layers[lid]; + li.m_layer_type = LayerInfo::EndCapPos; + li.m_rin = r_end; li.m_rout = r; li.m_zmin = z - m_det_half_thickness; @@ -89,13 +96,18 @@ namespace li.m_next_ecap_pos = lid < 18 ? lid + 1 : -1; li.m_next_ecap_neg = -1; - li.m_is_barrel = false; + li.m_sibl_barrel = lid - 9; + li.m_sibl_ecap_pos = -1; + li.m_sibl_ecap_neg = -1; + li.m_is_outer = (lid == 18); } { lid += 9; LayerInfo & li = m_trkinfo.m_layers[lid]; + li.m_layer_type = LayerInfo::EndCapNeg; + li.m_rin = r_end; li.m_rout = r; li.m_zmin = -z - m_det_half_thickness; @@ -105,7 +117,10 @@ namespace li.m_next_ecap_pos = -1; li.m_next_ecap_neg = lid < 27 ? lid + 1 : -1; - li.m_is_barrel = false; + li.m_sibl_barrel = lid - 18; + li.m_sibl_ecap_pos = -1; + li.m_sibl_ecap_neg = -1; + li.m_is_outer = (lid == 27); } } @@ -120,6 +135,11 @@ namespace void FillTrackerInfo() { + // XXXXXXMT: Hack smaller transition region. + // Need better estimate for seeds? + // m_trkinfo.set_eta_regions(1.15, 1.4, 2.4); + m_trkinfo.set_eta_regions(1.1, 1.3, 2.4); + // Actual coverage for tracks with z = 3cm is 2.4 float full_eta = 2.5; float full_eta_pix_0 = 2.55; // To account for BS z-spread diff --git a/Event.cc b/Event.cc index 39975be865079..8426fbef5412e 100644 --- a/Event.cc +++ b/Event.cc @@ -55,7 +55,7 @@ void Event::resetLayerHitMap(bool resetSimHits) { for (int il = 0; il < track.nTotalHits(); ++il) { HitID &hid = layerHitMap_[track.getHitIdx(il)]; assert(hid.index >= 0); // tmp debug - track.setHitIdx(il, hid.index, hid.layer); + track.setHitIdxLyr(il, hid.index, hid.layer); } } } @@ -471,9 +471,10 @@ void Event::read_in(FILE *fp, int version) fread(&simTracks_[0], sizeof(Track), nt, fp); Config::nTracks = nt; - if (Config::normal_val || Config::fit_val) { + if (Config::normal_val || Config::fit_val) + { simTrackStates_.resize(nt); - for (int it = 0; it=0) - printf("hit #%i idx=%i pos r=%5.3f\n",ih,simTracks_[it].getHitIdx(ih),layerHits_[ih][simTracks_[it].getHitIdx(ih)].r()); + int lyr = simTracks_[it].getHitLyr(ih); + int idx = simTracks_[it].getHitIdx(ih); + if (idx >= 0) + printf(" hit #%i lyr=%d idx=%i pos r=%5.3f z=%6.3f\n", + ih, lyr, idx, layerHits_[lyr][idx].r(), layerHits_[lyr][idx].z()); else - printf("hit #%i idx=%i\n",ih,simTracks_[it].getHitIdx(ih)); + printf(" hit #%i idx=%i\n",ih,simTracks_[it].getHitIdx(ih)); } } - */ printf("read %i layers\n",nl); + int total_hits = 0; for (int il = 0; il +#include "TrackerInfo.h" #include "Simulation.h" #include "Event.h" //#define DEBUG @@ -32,8 +33,8 @@ void setupTrackByToyMC(SVector3& pos, SVector3& mom, SMatrixSym66& covtrk, float px = pt * cos(phi); float py = pt * sin(phi); - if (g_unif(g_gen)>0.5) px*=-1.; - if (g_unif(g_gen)>0.5) py*=-1.; + if (g_unif(g_gen) > 0.5) px*=-1.; + if (g_unif(g_gen) > 0.5) py*=-1.; dprint("phi= " << phi << std::endl); @@ -41,8 +42,13 @@ void setupTrackByToyMC(SVector3& pos, SVector3& mom, SMatrixSym66& covtrk, // Should we just remove the flat pz option? Or fix it ... #ifdef GENFLATETA // this generates flat in eta - +roll_eta_dice: float eta = Config::minSimEta + (Config::maxSimEta - Config::minSimEta) * g_unif(g_gen); + + // XXMT Hardhack ... exclude transition region eta + if (Config::TrkInfo.is_transition(eta)) + goto roll_eta_dice; + float pz = pt*(1./(std::tan(2*std::atan(std::exp(-eta))))); // XXXXMT Commented this out to get ecap_pos only !!!! //if (g_unif(g_gen) > 0.5) pz *= -1.; @@ -126,6 +132,7 @@ void setupTrackByToyMC(SVector3& pos, SVector3& mom, SMatrixSym66& covtrk, continue; } + bool is_barrel = theInitSolid->is_barrel_; #ifdef SCATTERING // PW START @@ -234,9 +241,19 @@ void setupTrackByToyMC(SVector3& pos, SVector3& mom, SMatrixSym66& covtrk, float hitPhi = ((Config::hitposerrXY/scatteredRad)*g_gaus(g_gen))+scatteredPhi; // smear in phi after scatter float hitRad = (Config::hitposerrR)*g_gaus(g_gen)+scatteredRad; // smear in rad after scatter #else // no Scattering --> use this position for smearing - float hitZ = Config::hitposerrZ*g_gaus(g_gen)+initZ; - float hitPhi = ((Config::hitposerrXY/initRad)*g_gaus(g_gen))+initPhi; - float hitRad = (Config::hitposerrR)*g_gaus(g_gen)+initRad; + // XXMT4K - reuse Config z/r for endcaps in longitudinal/perpendicular sense; + // XY is still good? Argh ... too late to think. + // Similar hack below for variance ... + float poserr_Z = is_barrel ? Config::hitposerrZ : Config::hitposerrR; + float poserr_R = is_barrel ? Config::hitposerrR : Config::hitposerrZ; + + float hitZ = poserr_Z * g_gaus(g_gen) + initZ; + float hitRad = poserr_R * g_gaus(g_gen) + initRad; + float hitPhi = ((Config::hitposerrXY/initRad) * g_gaus(g_gen)) + initPhi; + // OLD CODE: + // float hitZ = Config::hitposerrZ*g_gaus(g_gen)+initZ; + // float hitPhi = ((Config::hitposerrXY/initRad)*g_gaus(g_gen))+initPhi; + // float hitRad = (Config::hitposerrR)*g_gaus(g_gen)+initRad; #endif // SCATTERING initTSs.push_back(propState); // if no scattering, will just parameters from prop to next layer @@ -301,11 +318,23 @@ void setupTrackByToyMC(SVector3& pos, SVector3& mom, SMatrixSym66& covtrk, // covXYZ(1,0) = covXYZ(0,1) covXYZ(2,2) = Config::varZ; #else // SOLID_SMEAR --> covariance for pure cylindrical geometry with smearing - covXYZ(0,0) = hitX*hitX*Config::varR/hitRad2 + hitY*hitY*varPhi; - covXYZ(1,1) = hitX*hitX*varPhi + hitY*hitY*Config::varR/hitRad2; - covXYZ(2,2) = Config::varZ; - covXYZ(0,1) = hitX*hitY*(Config::varR/hitRad2 - varPhi); - covXYZ(1,0) = covXYZ(0,1); + // XXMT4K - continuation of z/r hack. + // Still unsure if there is more interplay between varXY and varR ... + float var_R = is_barrel ? Config::varR : Config::varZ; + float var_Z = is_barrel ? Config::varZ : Config::varR; + + covXYZ(0,0) = hitX*hitX * var_R / hitRad2 + hitY*hitY*varPhi; + covXYZ(1,1) = hitX*hitX * varPhi + hitY*hitY * var_R / hitRad2; + covXYZ(2,2) = var_Z; + covXYZ(0,1) = hitX*hitY*(var_R / hitRad2 - varPhi); + covXYZ(1,0) = covXYZ(0,1); // MT: this should be redundant, it's a Sym matrix type. + + // OLD CODE: + // covXYZ(0,0) = hitX*hitX*Config::varR/hitRad2 + hitY*hitY*varPhi; + // covXYZ(1,1) = hitX*hitX*varPhi + hitY*hitY*Config::varR/hitRad2; + // covXYZ(2,2) = Config::varZ; + // covXYZ(0,1) = hitX*hitY*(Config::varR/hitRad2 - varPhi); + // covXYZ(1,0) = covXYZ(0,1); // MT: this should be redundant, it's a Sym matrix type. dprint("initPhi: " << initPhi << " hitPhi: " << hitPhi << " initRad: " << initRad << " hitRad: " << hitRad << std::endl << "initX: " << initX << " hitX: " << hitX << " initY: " << initY << " hitY: " << hitY << " initZ: " << initZ << " hitZ: " << hitZ << std::endl @@ -314,7 +343,7 @@ void setupTrackByToyMC(SVector3& pos, SVector3& mom, SMatrixSym66& covtrk, #endif MCHitInfo hitinfo(itrack, simLayer, layer_counts[simLayer], ev.nextMCHitID()); - hits.emplace_back(x1,covXYZ,hitinfo.mcHitID_); + hits.emplace_back(x1, covXYZ, hitinfo.mcHitID_); hitinfos.emplace_back(hitinfo); tmpState = propState; diff --git a/Track.h b/Track.h index 16fc3d405ac64..d9b1619b6ad3e 100644 --- a/Track.h +++ b/Track.h @@ -127,7 +127,7 @@ class Track } for (int h = nHits; h < Config::nMaxTrkHits; ++h) { - setHitIdx(h, -1, -1); + setHitIdxLyr(h, -1, -1); } } @@ -241,7 +241,7 @@ class Track { return hitsOnTrk_[hitIdxPos_].index; } - int getLastHitLayer() const + int getLastHitLyr() const { return hitsOnTrk_[hitIdxPos_].layer; } @@ -250,12 +250,17 @@ class Track void fillEmptyLayers() { for (int h = hitIdxPos_ + 1; h < Config::nMaxTrkHits; h++) { - setHitIdx(h, -1, -1); + setHitIdxLyr(h, -1, -1); } } CUDA_CALLABLE - void setHitIdx(int posHitIdx, int newIdx, int newLyr) { + void setHitIdx(int posHitIdx, int newIdx) { + hitsOnTrk_[posHitIdx].index = newIdx; + } + + CUDA_CALLABLE + void setHitIdxLyr(int posHitIdx, int newIdx, int newLyr) { hitsOnTrk_[posHitIdx] = { newIdx, newLyr }; } diff --git a/TrackerInfo.cc b/TrackerInfo.cc index 780a855d024d4..f66dcc93a2164 100644 --- a/TrackerInfo.cc +++ b/TrackerInfo.cc @@ -1 +1,15 @@ #include "TrackerInfo.h" + +#include + +bool TrackerInfo::are_layers_siblings(int l1, int l2) const +{ + assert(l1 < m_layers.size() && l2 < m_layers.size()); + + const LayerInfo &i1 = m_layers[l1]; + + if (i1.m_layer_type == LayerInfo::Barrel) + return l2 == i1.m_sibl_ecap_pos || l2 == i1.m_sibl_ecap_neg; + else + return l2 == i1.m_sibl_barrel; +} diff --git a/TrackerInfo.h b/TrackerInfo.h index fb7ff27a854b8..08243b5f680c2 100644 --- a/TrackerInfo.h +++ b/TrackerInfo.h @@ -3,19 +3,23 @@ #include +#include #include class LayerInfo { public: - int m_layer_id; + enum LayerType_e { Barrel = 0, EndCapPos = 1, EndCapNeg = 2 }; - float m_rin, m_rout, m_zmin, m_zmax; + int m_layer_id; + LayerType_e m_layer_type; - int m_next_barrel, m_next_ecap_pos, m_next_ecap_neg; + float m_rin, m_rout, m_zmin, m_zmax; - bool m_is_barrel; // or byte enum barrel, ecappos, ecapneg - bool m_is_outer; + int m_next_barrel, m_next_ecap_pos, m_next_ecap_neg; + int m_sibl_barrel, m_sibl_ecap_pos, m_sibl_ecap_neg; + + bool m_is_outer; // Additional stuff needed? // * pixel / strip, mono / stereo @@ -26,15 +30,17 @@ class LayerInfo LayerInfo(int lid) : m_layer_id(lid) {} - float r_mean() const { return (m_rin + m_rout) / 2; } - float z_mean() const { return (m_zmin + m_zmax) / 2; } + float r_mean() const { return (m_rin + m_rout) / 2; } + float z_mean() const { return (m_zmin + m_zmax) / 2; } + + bool is_barrel() const { return m_layer_type == Barrel; } - void print_layer() + void print_layer() { printf("Layer %2d r(%7.4f, %7.4f) z(% 9.4f, % 9.4f) next(%2d, %2d, %2d) is_brl=%d is_outer=%d\n", m_layer_id, m_rin, m_rout, m_zmin, m_zmax, m_next_barrel, m_next_ecap_pos, m_next_ecap_neg, - m_is_barrel, m_is_outer); + is_barrel(), m_is_outer); } }; @@ -49,17 +55,61 @@ class TrackerInfo } public: + enum AbsEtaRegion_e { AbsReg_Outside = -1, AbsReg_Barrel = 0, AbsReg_Transition = 1, AbsReg_Endcap = 2 }; + + enum EtaRegion { Reg_Begin = 0, Reg_Endcap_Neg = 0, Reg_Transition_Neg, Reg_Barrel, + Reg_Transition_Pos, Reg_Endcap_Pos, Reg_End, Reg_Count = Reg_End }; + std::vector m_layers; std::vector m_barrel; std::vector m_ecap_pos; std::vector m_ecap_neg; - float m_eta_trans_beg, m_eta_trans_end, m_eta_max; + float m_eta_trans_beg, m_eta_trans_end, m_eta_ecap_end; + + void set_eta_regions(float tr_beg, float tr_end, float ec_end) + { m_eta_trans_beg = tr_beg; m_eta_trans_end = tr_end; m_eta_ecap_end = ec_end; } LayerInfo & new_barrel_layer() { m_barrel .push_back( new_layer() ); return m_layers.back(); } LayerInfo & new_ecap_pos_layer() { m_ecap_pos.push_back( new_layer() ); return m_layers.back(); } LayerInfo & new_ecap_neg_layer() { m_ecap_neg.push_back( new_layer() ); return m_layers.back(); } + + bool are_layers_siblings(int l1, int l2) const; + + bool is_barrel(float eta) const + { + return std::abs(eta) < m_eta_trans_beg; + } + + bool is_transition(float eta) const + { + return std::abs(eta) >= m_eta_trans_beg && std::abs(eta) <= m_eta_trans_end; + } + + bool is_endcap(float eta) const + { + return std::abs(eta) > m_eta_trans_end; + } + + EtaRegion find_eta_region(float eta) const + { + if (eta < -m_eta_trans_beg) return Reg_Endcap_Neg; + else if (eta < -m_eta_trans_end) return Reg_Transition_Neg; + else if (eta < m_eta_trans_beg) return Reg_Barrel; + else if (eta < m_eta_trans_end) return Reg_Transition_Pos; + else return Reg_Endcap_Pos; + } + + EtaRegion find_region_of_layer(int l) const + { + // Assumes layers increase monotonically for barrel / encap. + // Never returns Transition region. + + if (l <= m_barrel.back()) return Reg_Barrel; + if (l <= m_ecap_pos.back()) return Reg_Endcap_Pos; + return Reg_Endcap_Neg; + } }; #endif diff --git a/mkFit/CandCloner.cc b/mkFit/CandCloner.cc index 987ca9b6a791a..9c15eb4b1018a 100644 --- a/mkFit/CandCloner.cc +++ b/mkFit/CandCloner.cc @@ -25,7 +25,7 @@ void CandCloner::ProcessSeedRange(int is_beg, int is_end) { std::vector& hitsForSeed = m_hits_to_add[is]; - std::vector> &cands = mp_etabin_of_comb_candidates->m_candidates; + std::vector> &cands = mp_region_of_comb_candidates->m_candidates; #ifdef DEBUG int th_start_seed = m_start_seed; diff --git a/mkFit/CandCloner.h b/mkFit/CandCloner.h index e97cc8a9592c5..bd49158fe97e7 100644 --- a/mkFit/CandCloner.h +++ b/mkFit/CandCloner.h @@ -38,9 +38,9 @@ class CandCloner { } - void begin_eta_bin(EtaBinOfCombCandidates * eb_o_ccs, int start_seed, int n_seeds) + void begin_eta_bin(EtaRegionOfCombCandidates * er_o_ccs, int start_seed, int n_seeds) { - mp_etabin_of_comb_candidates = eb_o_ccs; + mp_region_of_comb_candidates = er_o_ccs; m_start_seed = start_seed; m_n_seeds = n_seeds; m_hits_to_add.resize(n_seeds); @@ -161,7 +161,7 @@ class CandCloner int m_idx_max, m_idx_max_prev; std::vector> m_hits_to_add; - EtaBinOfCombCandidates *mp_etabin_of_comb_candidates; + EtaRegionOfCombCandidates *mp_region_of_comb_candidates; #if defined(CC_TIME_ETA) or defined(CC_TIME_LAYER) double t_eta, t_lay; diff --git a/mkFit/HitStructures.cc b/mkFit/HitStructures.cc index b9d9c28184021..3c0f78698432b 100644 --- a/mkFit/HitStructures.cc +++ b/mkFit/HitStructures.cc @@ -1,6 +1,6 @@ #include "HitStructures.h" -#include "TrackerInfo.h" +#include "Event.h" #include "Ice/IceRevisitedRadix.h" @@ -104,11 +104,16 @@ void LayerOfHits::SuckInHits(const HitVec &hitv) int j = sort.GetRanks()[i]; // XXXX MT: Endcap has special check - try to get rid of this! + // Also, WTF ... this brings in holes as pos i is not filled. + // If this stays I need i_offset variable. if ( ! m_is_barrel && (hitv[j].r() > m_qmax || hitv[j].r() < m_qmin)) { - std::cout << "WARNING: hit outsed r boundary of disk, please fixme" << std::endl; - m_capacity--; - continue; + printf("LayerOfHits::SuckInHits WARNING hit out of r boundary of disk\n" + " layer %d hit %d hit_r %f limits (%f, %f)\n", + m_layer_id, j, hitv[j].r(), m_qmin, m_qmax); + // Figure out of this needs to stay ... and fix it + // --m_size; + // continue; } // Could fix the mis-sorts. Set ha size to size + 1 and fake last entry to avoid ifs. @@ -291,19 +296,19 @@ EventOfHits::EventOfHits(TrackerInfo &trk_inf) : float bin_width = 1.0f; - if (li.m_is_barrel) + if (li.is_barrel()) { // printf("EventOfHits::EventOfHits setting up layer %2d as barrel\n", li.m_layer_id); m_layers_of_hits[li.m_layer_id].SetupLayer(li.m_zmin, li.m_zmax, bin_width, - li.m_layer_id, li.m_is_barrel); + li.m_layer_id, true); } else { // printf("EventOfHits::EventOfHits setting up layer %2d as endcap\n", li.m_layer_id); m_layers_of_hits[li.m_layer_id].SetupLayer(li.m_rin, li.m_rout, bin_width, - li.m_layer_id, li.m_is_barrel); + li.m_layer_id, false); } } } diff --git a/mkFit/HitStructures.h b/mkFit/HitStructures.h index 397e49dbc29fc..c5000c48f8269 100644 --- a/mkFit/HitStructures.h +++ b/mkFit/HitStructures.h @@ -4,6 +4,7 @@ #include "../Config.h" #include "Hit.h" #include "Track.h" +#include "TrackerInfo.h" //#define DEBUG #include "Debug.h" @@ -60,7 +61,7 @@ inline bool sortTrksByPhiMT(const Track& t1, const Track& t2) // and could help us reduce the number of hits we need to process with bigger // potential gains. -// #define LOH_USE_PHI_Q_ARRAYS +#define LOH_USE_PHI_Q_ARRAYS // Note: the same code is used for barrel and endcap. In barrel the longitudinal // bins are in Z and in endcap they are in R -- here this coordinate is called Q @@ -193,32 +194,32 @@ class EtaBinOfCandidates public: std::vector m_candidates; - int m_real_size; - int m_fill_index; + int m_capacity; + int m_size; public: EtaBinOfCandidates() : - m_candidates (Config::maxCandsPerEtaBin), - m_real_size (Config::maxCandsPerEtaBin), - m_fill_index (0) + m_candidates(Config::maxCandsPerEtaBin), + m_capacity (Config::maxCandsPerEtaBin), + m_size (0) {} void Reset() { - m_fill_index = 0; + m_size = 0; } void InsertTrack(const Track& track) { - assert (m_fill_index < m_real_size); // or something + assert (m_size < m_capacity); // or something - m_candidates[m_fill_index] = track; - ++m_fill_index; + m_candidates[m_size] = track; + ++m_size; } void SortByPhi() { - std::sort(m_candidates.begin(), m_candidates.begin() + m_fill_index, sortTrksByPhiMT); + std::sort(m_candidates.begin(), m_candidates.begin() + m_size, sortTrksByPhiMT); } }; @@ -262,100 +263,93 @@ class EventOfCandidates }; - //------------------------------------------------------- // for combinatorial version, switch to vector of vectors //------------------------------------------------------- -class EtaBinOfCombCandidates +class EtaRegionOfCombCandidates { public: std::vector > m_candidates; - //these refer to seeds - int m_real_size; - int m_fill_index; + int m_capacity; + int m_size; + int m_region; public: - EtaBinOfCombCandidates() : - m_candidates (Config::maxCandsPerEtaBin / Config::maxCandsPerSeed), - m_real_size (Config::maxCandsPerEtaBin / Config::maxCandsPerSeed), - m_fill_index (0) + EtaRegionOfCombCandidates(int size=0) : + m_candidates(), + m_capacity (0), + m_size (0), + m_region (-1) { - for (int s=0;s m_capacity) + { + m_candidates.resize(new_capacity); + + for (int s = m_capacity; s < new_capacity; ++s) + { + m_candidates[s].reserve(Config::maxCandsPerSeed);//we should never exceed this + } + + m_capacity = new_capacity; + } + + m_size = 0; } + std::vector& operator[](int i) { return m_candidates[i]; } + void InsertSeed(const Track& seed) { - assert (m_fill_index < m_real_size); // or something + assert (m_size < m_capacity); - m_candidates[m_fill_index].push_back(seed); - ++m_fill_index; + m_candidates[m_size].emplace_back(seed); + ++m_size; } void InsertTrack(const Track& track, int seed_index) { - assert (seed_index <= m_fill_index); // or something + assert (seed_index < m_size); m_candidates[seed_index].push_back(track); } /* void SortByPhi() */ /* { */ - /* std::sort(m_candidates.begin(), m_candidates.begin() + m_fill_index, sortTrksByPhiMT); */ + /* std::sort(m_candidates.begin(), m_candidates.begin() + m_size, sortTrksByPhiMT); */ /* } */ }; class EventOfCombCandidates { public: - std::vector m_etabins_of_comb_candidates; + std::vector m_regions_of_comb_candidates; public: - // XXXXMT Do I need something like: - // EventOfCombCandidates(int nb, float eta_trans_beg, float eta_trans_end, float eta_max) : - EventOfCombCandidates() : - m_etabins_of_comb_candidates(Config::nEtaBin) - {} - - void Reset() + m_regions_of_comb_candidates(TrackerInfo::Reg_Count) { - for (auto &i : m_etabins_of_comb_candidates) + for (int i = TrackerInfo::Reg_Begin; i < TrackerInfo::Reg_End; ++i) { - i.Reset(); + m_regions_of_comb_candidates[i].m_region = i; } } - void InsertSeed(const Track& seed) - { - int bin = getEtaBin(seed.posEta()); - if ( bin != -1 ) - { - m_etabins_of_comb_candidates[bin].InsertSeed(seed); - } -#ifdef DEBUG - else { dprint("excluding seed with r=" << seed.posR() << " etaBin=" << bin); }; -#endif - } + std::vector::iterator begin() { return m_regions_of_comb_candidates.begin(); } + std::vector::iterator end() { return m_regions_of_comb_candidates.end(); } - void InsertCandidate(const Track& track, int seed_index) - { - int bin = getEtaBin(track.posEta()); - m_etabins_of_comb_candidates[bin].InsertTrack(track,seed_index); - } + EtaRegionOfCombCandidates& operator[](int i) { return m_regions_of_comb_candidates[i]; } }; diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index 25a35fc01f720..249693890cb11 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -10,17 +10,74 @@ #include "MkFitter.h" -//#define DEBUG +#define DEBUG #include "Debug.h" +#include "Ice/IceRevisitedRadix.h" + #include ExecutionContext g_exe_ctx; +//------------------------------------------------------------------------------ + namespace { auto retcand = [](CandCloner* cloner) { g_exe_ctx.m_cloners.ReturnToPool(cloner); }; auto retfitr = [](MkFitter* mkfp ) { g_exe_ctx.m_fitters.ReturnToPool(mkfp); }; + + + // Range of indices processed within one iteration of a TBB parallel_for. + struct RangeOfSeedIndices + { + int m_rng_beg, m_rng_end; + int m_beg, m_end; + + RangeOfSeedIndices(int rb, int re) : + m_rng_beg(rb), m_rng_end(re) + { + m_end = m_rng_beg; + next_chunk(); + } + + bool valid() const { return m_beg < m_rng_end; } + + int n_proc() const { return m_end - m_beg; } + + void next_chunk() + { + m_beg = m_end; + m_end = std::min(m_end + NN, m_rng_end); + } + + RangeOfSeedIndices& operator++() { next_chunk(); return *this; } + }; + + // Region of seed indices processed in a single TBB parallel for. + struct RegionOfSeedIndices + { + int m_reg_beg, m_reg_end, m_vec_cnt; + + RegionOfSeedIndices(Event *evt, int region) + { + m_reg_beg = (region == 0) ? 0 : evt->seedEtaSeparators_[region - 1]; + m_reg_end = evt->seedEtaSeparators_[region]; + m_vec_cnt = (m_reg_end - m_reg_beg + NN - 1) / NN; + } + + int count() const { return m_reg_end - m_reg_beg; } + + tbb::blocked_range tbb_blk_rng() const + { + return tbb::blocked_range(0, m_vec_cnt, std::max(1, Config::numSeedsPerTask / NN)); + } + + RangeOfSeedIndices seed_rng(const tbb::blocked_range& i) const + { + return RangeOfSeedIndices( m_reg_beg + NN * i.begin(), + std::min(m_reg_beg + NN * i.end(), m_reg_end)); + } + }; } MkBuilder* MkBuilder::make_builder() @@ -32,7 +89,7 @@ MkBuilder* MkBuilder::make_builder() #ifdef DEBUG namespace { void pre_prop_print(int ilay, MkFitter* mkfp) { - std::cout << "propagate to lay=" << ilay+1 + std::cout << "propagate to lay=" << ilay << " start from x=" << mkfp->getPar(0, 0, 0) << " y=" << mkfp->getPar(0, 0, 1) << " z=" << mkfp->getPar(0, 0, 2) << " r=" << getHypot(mkfp->getPar(0, 0, 0), mkfp->getPar(0, 0, 1)) << " px=" << mkfp->getPar(0, 0, 3) << " py=" << mkfp->getPar(0, 0, 4) << " pz=" << mkfp->getPar(0, 0, 5) @@ -44,7 +101,7 @@ namespace { } void post_prop_print(int ilay, MkFitter* mkfp) { - std::cout << "propagate to lay=" << ilay+1 + std::cout << "propagate to lay=" << ilay << " arrive at x=" << mkfp->getPar(0, 1, 0) << " y=" << mkfp->getPar(0, 1, 1) << " z=" << mkfp->getPar(0, 1, 2) << " r=" << getHypot(mkfp->getPar(0, 1, 0), mkfp->getPar(0, 1, 1)) << std::endl; } @@ -52,7 +109,7 @@ namespace { void print_seed(const Track& seed) { std::cout << "MX - found seed with nHits=" << seed.nFoundHits() << " chi2=" << seed.chi2() << " posEta=" << seed.posEta() << " posPhi=" << seed.posPhi() << " posR=" << seed.posR() - << " pT=" << seed.pT() << std::endl; + << " posZ=" << seed.z() << " pT=" << seed.pT() << std::endl; } void print_seed2(const Track& seed) { @@ -72,21 +129,22 @@ namespace { void print_seeds(const EventOfCandidates& event_of_cands) { for (int ebin = 0; ebin < Config::nEtaBin; ++ebin) { const EtaBinOfCandidates &etabin_of_candidates = event_of_cands.m_etabins_of_candidates[ebin]; - for (int iseed = 0; iseed < etabin_of_candidates.m_fill_index; iseed++) { + for (int iseed = 0; iseed < etabin_of_candidates.m_size; iseed++) { print_seed2(etabin_of_candidates.m_candidates[iseed]); } } } void print_seeds(const EventOfCombCandidates& event_of_comb_cands) { - for (int ebin = 0; ebin < Config::nEtaBin; ++ebin) { - const EtaBinOfCombCandidates &etabin_of_comb_candidates = event_of_comb_cands.m_etabins_of_comb_candidates[ebin]; - for (int iseed = 0; iseed < etabin_of_comb_candidates.m_fill_index; iseed++) { + for (int ebin = 0; ebin < TrackerInfo::Reg_Count; ++ebin) { + const EtaRegionOfCombCandidates &etabin_of_comb_candidates = event_of_comb_cands[ebin]; + for (int iseed = 0; iseed < etabin_of_comb_candidates.m_size; iseed++) { print_seed2(etabin_of_comb_candidates.m_candidates[iseed].front()); } } } } + #endif namespace @@ -110,6 +168,47 @@ MkBuilder::MkBuilder() : // XXMT WAS m_event_of_hits(Config::nLayers) m_event_of_hits(Config::TrkInfo) { + const TrackerInfo &ti = Config::TrkInfo; + + m_steering_params[TrackerInfo::Reg_Endcap_Neg] = + { + 21, + &LayerInfo::m_zmax, + &LayerInfo::m_next_ecap_neg, + &MkFitter::PropagateTracksToZ, + &MkFitter::SelectHitIndicesEndcap, + &MkFitter::AddBestHitEndcap + }; + + //m_steering_params[TrackerInfo::Reg_Transition_Neg] = { }; + + m_steering_params[TrackerInfo::Reg_Barrel] = + { + 3, + &LayerInfo::m_rin, + &LayerInfo::m_next_barrel, + &MkFitter::PropagateTracksToR, + &MkFitter::SelectHitIndices, + &MkFitter::AddBestHit + }; + + //m_steering_params[TrackerInfo::Reg_Transition_Pos] = { }; + + m_steering_params[TrackerInfo::Reg_Endcap_Pos] = + { + 12, + &LayerInfo::m_zmin, + &LayerInfo::m_next_ecap_pos, + &MkFitter::PropagateTracksToZ, + &MkFitter::SelectHitIndicesEndcap, + &MkFitter::AddBestHitEndcap + }; + + // XXMT4D Changing this order might + m_brl_ecp_regions.resize(3); + m_brl_ecp_regions[0] = TrackerInfo::Reg_Endcap_Neg; + m_brl_ecp_regions[1] = TrackerInfo::Reg_Barrel; + m_brl_ecp_regions[2] = TrackerInfo::Reg_Endcap_Pos; } MkBuilder::~MkBuilder() @@ -166,24 +265,121 @@ void MkBuilder::begin_event(Event* ev, EventTmp* ev_tmp, const char* build_type) { for (int ihit = 0; ihit < simtracks[itrack].nFoundHits(); ++ihit) { - dprint("track #" << itrack << " hit #" << ihit+1 - << " hit pos=" << simtracks[itrack].hitsVector(m_event->layerHits_)[ihit].position() - << " phi=" << simtracks[itrack].hitsVector(m_event->layerHits_)[ihit].phi() - << " phiPart=" << getPhiPartition(simtracks[itrack].hitsVector(m_event->layerHits_)[ihit].phi())); + dprint("track #" << itrack << " hit #" << ihit + << " hit pos=" << simtracks[itrack].hitsVector(m_event->layerHits_)[ihit].position() + << " phi=" << simtracks[itrack].hitsVector(m_event->layerHits_)[ihit].phi() + << " phiPart=" << getPhiPartition(simtracks[itrack].hitsVector(m_event->layerHits_)[ihit].phi())); } } #endif // for (int l=0; lseedTracks_ = m_event->simTracks_; + + TrackerInfo &trk_info = Config::TrkInfo; + + m_event->seedTracks_.reserve( m_event->simTracks_.size() ); + + const int size = m_event->simTracks_.size(); + + // Loop over input sim-tracks, collect etas (and other relevant info) for sorting. + // After that we will make another pass and place seeds on their proper locations. + std::vector etas(size); + for (int i = 0; i < 5; ++i) m_event->seedEtaSeparators_[i] = 0; + + for (int i = 0; i < size; ++i) + { + //float eta = m_event->simTracks_[i].momEta(); + + HitOnTrack hot = m_event->simTracks_[i].getHitOnTrack(Config::nlayers_per_seed - 1); + float eta = m_event->layerHits_[hot.layer][hot.index].eta(); + + etas[i] = eta; + ++m_event->seedEtaSeparators_[ trk_info.find_eta_region(eta) ]; + } + + RadixSort sort; + sort.Sort(&etas[0], size); + + for (int i = 0; i < size; ++i) + { + const int j = sort.GetRanks()[i]; + const Track &src = m_event->simTracks_ [j]; + + dprintf("MkBuilder::begin_event converting sim track %d into seed position %d, eta=%.3f\n", + j, i, etas[j]); + + int h_sel = 0, h = 0; +const HitOnTrack *hots = src.getHitsOnTrackArray(); + HitOnTrack new_hots[ Config::nlayers_per_seed_max ]; + + // Exit condition -- need to check one more hit after Config::nlayers_per_seed + // good hits are found. + bool last_hit_check = false; + + while ( ! last_hit_check && h < src.nTotalHits()) + { + assert (hots[h].index >= 0 && "Expecting input sim tracks (or seeds later) to not have holes"); + + if (h_sel == Config::nlayers_per_seed) last_hit_check = true; + + // Check if hit is on a sibling layer given the previous one. Barrel ignored. + if (h_sel > 0 && ! trk_info.is_barrel(etas[j]) && + trk_info.are_layers_siblings(new_hots[h_sel - 1].layer, hots[h].layer)) + { + dprintf(" Sibling layers %d %d ... overwriting with new one\n", + new_hots[h_sel - 1].layer, hots[h].layer); + + + new_hots[h_sel - 1] = hots[h]; + } + else if ( ! last_hit_check) + { + new_hots[h_sel++] = hots[h]; + } + + ++h; + } + + m_event->seedTracks_.emplace_back( Track(src.state(), 0, src.label(), Config::nlayers_per_seed, new_hots) ); + + Track &dst = m_event->seedTracks_.back(); + dprintf(" Seed nh=%d, last_lay=%d, last_idx=%d\n", + dst.nTotalHits(), dst.getLastHitLyr(), dst.getLastHitIdx()); + // dprintf(" "); for (int i=0; iseedEtaSeparators_[0], m_event->seedEtaSeparators_[1], m_event->seedEtaSeparators_[2], m_event->seedEtaSeparators_[3], m_event->seedEtaSeparators_[4]); + + // Sum region counts up to contain actual separator indices: + for (int i = TrackerInfo::Reg_Transition_Neg; i < TrackerInfo::Reg_Count; ++i) + { + m_event->seedEtaSeparators_[i] += m_event->seedEtaSeparators_[i - 1]; + } + } } void MkBuilder::end_event() @@ -240,7 +436,7 @@ int MkBuilder::find_seeds() for (int ihit = Config::nlayers_per_seed; ihit < Config::nLayers; ihit++) { - seedtrack.setHitIdx(ihit, -1, -1); + seedtrack.setHitIdxLyr(ihit, -1, -1); } dprint("iseed: " << iseed << " mcids: " << hit0.mcTrackID(m_event->simHitsInfo_) << " " << @@ -249,52 +445,156 @@ int MkBuilder::find_seeds() return time; } +namespace +{ + void fill_seed_layer_sig(const Track& trk, int n_hits, bool is_brl[]) + { + const TrackerInfo &trk_info = Config::TrkInfo; + + for (int i = 0; i < n_hits; ++i) + { + is_brl[i] = trk_info.m_layers[ trk.getHitLyr(i) ].is_barrel(); + } + } + + bool are_seed_layer_sigs_equal(const Track& trk, int n_hits, const bool is_brl_ref[]) + { + const TrackerInfo &trk_info = Config::TrkInfo; + + for (int i = 0; i < n_hits; ++i) + { + if(trk_info.m_layers[ trk.getHitLyr(i) ].is_barrel() != is_brl_ref[i]) return false; + } + + return true; + } +} + void MkBuilder::fit_seeds() { + // XXXXMT For lack of better ideas ... expect seeds to be sorted in eta + // and that Event::seedEtaSeparators_[] holds starting indices of 5 eta regions. + // For now this is only true for MC Cyl Cow ... sorting done in begin_event() here. + // This might be premature ... sorting would actually be more meaningful after the seed fit. + // But we shot ourselves into the foot by doing propagation at the end of the loop. + // Seemed like a good idea at the time. + + // debug=true; + g_exe_ctx.populate(Config::numThreadsFinder); + const TrackerInfo &trk_info = Config::TrkInfo; TrackVec& seedtracks = m_event->seedTracks_; - int theEnd = seedtracks.size(); - int count = (theEnd + NN - 1)/NN; + dcall(print_seeds(seedtracks)); + + // XXXXX was ... plus some elaborate chunking in the range and inside the loop. + // int theEnd = seedtracks.size(); + // int count = (theEnd + NN - 1)/NN; - tbb::parallel_for(tbb::blocked_range(0, count, std::max(1, Config::numSeedsPerTask/NN)), - [&](const tbb::blocked_range& i) + // XXXXMT Actually, this should be good for all regions + tbb::parallel_for_each(m_brl_ecp_regions.begin(), m_brl_ecp_regions.end(), + [&](int reg) + { + // XXXXXX endcap only ... + //if (reg != TrackerInfo::Reg_Endcap_Neg && reg != TrackerInfo::Reg_Endcap_Pos) + //continue; + + RegionOfSeedIndices rosi(m_event, reg); + + tbb::parallel_for(rosi.tbb_blk_rng(), + [&](const tbb::blocked_range& blk_rng) { - printf("Seed info pos( x y z r; eta phi) mom( pt pz; eta phi)\n"); + // printf("TBB seeding krappe -- range = %d to %d - extent = %d ==> %d to %d - extent %d\n", + // i.begin(), i.end(), i.end() - i.begin(), beg, std::min(end,theEnd), std::min(end,theEnd) - beg); + + // printf("Seed info pos( x y z r; eta phi) mom( pt pz; eta phi)\n"); std::unique_ptr mkfp(g_exe_ctx.m_fitters.GetFromPool(), retfitr); - for (int it = i.begin(); it < i.end(); ++it) + + RangeOfSeedIndices rng = rosi.seed_rng(blk_rng); + + while (rng.valid()) { +#ifdef DEBUG // MT dump seed so i see if etas are about right - for (int i = it*NN; i < std::min((it+1)*NN, theEnd); ++i) + for (int i = rng.m_beg; i < rng.m_end; ++i) { auto &t = seedtracks[i]; - printf("Seed %4d pos(%+7.3f %+7.3f %+7.3f; %+7.3f %+6.3f %+6.3f) mom(%+7.3f %+7.3f; %+6.3f %+6.3f)\n", - i, t.x(), t.y(), t.z(), t.posR(), t.posEta(), t.posPhi(), - t.pT(), t.pz(), t.momEta(), t.momPhi()); + auto &dst = t; + dprintf("Seed %4d pos(%+7.3f %+7.3f %+7.3f; %+7.3f %+6.3f %+6.3f) mom(%+7.3f %+7.3f; %+6.3f %+6.3f)\n", + i, t.x(), t.y(), t.z(), t.posR(), t.posEta(), t.posPhi(), + t.pT(), t.pz(), t.momEta(), t.momPhi()); + dprintf(" Idx/lay for above track:"); for (int i=0; iSetNhits(Config::nlayers_per_seed); //just to be sure (is this needed?) + //debug=true; + + mkfp->SetNhits(Config::nlayers_per_seed); mkfp->InputTracksAndHits(seedtracks, m_event_of_hits.m_layers_of_hits, itrack, end); + if (Config::cf_seeding) mkfp->ConformalFitTracks(false, itrack, end); - if (Config::readCmsswSeeds==false) mkfp->FitTracks(end - itrack, m_event); - const int ilay = Config::nlayers_per_seed; // layer 4; XXXXMT + if (Config::readCmsswSeeds == false) + { + mkfp->FitTracksSteered(is_brl, end - itrack, m_event); + } + + const TrackerInfo &trk_info = Config::TrkInfo; + + const int ilay = st_par.first_finding_layer; - // XXMT need different propagate for endcap ... well ... to be seen. dcall(pre_prop_print(ilay, mkfp)); - mkfp->PropagateTracksToR(m_event->geom_.Radius(ilay), end - itrack); + + (mkfp->*st_par.propagate_foo)(trk_info.m_layers[ilay].*st_par.prop_to_pos_doo, end - itrack); + dcall(post_prop_print(ilay, mkfp)); mkfp->OutputFittedTracksAndHitIdx(m_event->seedTracks_, itrack, end, true); @@ -341,30 +641,55 @@ void MkBuilder::map_seed_hits() // map seed hit indices from global m_event->layerHits_[i] to hit indices in // structure m_event_of_hits.m_layers_of_hits[i].m_hits - // XXMT4K what does this actually do? - // I'm beginning to get the impression that some remapping can be removed - // now that we have HitOnTrack { index, layer }; - HitIDVec seedLayersHitMap(m_event->simHitsInfo_.size()); - for (int ilayer = 0; ilayer < Config::nlayers_per_seed; ++ilayer) { + + // XXMT4K: This was: Config::nlayers_per_seed, now not that simple. + // In principle could have a list of seed layers (from outside (seed maker) or TrackerInfo). + int max_layer = Config::nTotalLayers; + + for (int ilayer = 0; ilayer < max_layer; ++ilayer) + { const auto & lof_m_hits = m_event_of_hits.m_layers_of_hits[ilayer].m_hits; const auto size = m_event->layerHits_[ilayer].size(); - for (int index = 0; index < size; ++index) { + + for (int index = 0; index < size; ++index) + { seedLayersHitMap[lof_m_hits[index].mcHitID()] = HitID(ilayer, index); } } - for (int ilayer = 0; ilayer < Config::nlayers_per_seed; ++ilayer) { + + for (auto&& track : m_event->seedTracks_) + { + for (int i = 0; i < track.nTotalHits(); ++i) + { + int hitidx = track.getHitIdx(i); + int hitlyr = track.getHitLyr(i); + if (hitidx >= 0) + { + const auto & global_hit_vec = m_event->layerHits_[hitlyr]; + + track.setHitIdx(i, seedLayersHitMap[global_hit_vec[hitidx].mcHitID()].index); + } + } + } + // XXXXMT4K: Old code ... + /* + for (int ilayer = 0; ilayer < max_layer; ++ilayer) + { const auto & global_hit_vec = m_event->layerHits_[ilayer]; const auto size = m_event->layerHits_[ilayer].size(); for (auto&& track : m_event->seedTracks_) { auto hitidx = track.getHitIdx(ilayer); - if ((hitidx>=0) && (hitidx= 0) && (hitidx < size)) { - // XXMT4K ilayer -> something else .... - track.setHitIdx(ilayer, seedLayersHitMap[global_hit_vec[hitidx].mcHitID()].index, ilayer); + // XXMT4K ilayer -> something else. Even better, change loop order. + // Seed tracks only have seed hits, so iterate over them. + + track.setHitIdxLyr(ilayer, seedLayersHitMap[global_hit_vec[hitidx].mcHitID()].index, ilayer); } } } + */ } void MkBuilder::remap_seed_hits() @@ -373,7 +698,7 @@ void MkBuilder::remap_seed_hits() // m_event_of_hits.m_layers_of_hits[i].m_hits to global // m_event->layerHits_[i] - // XXMT4K as above + // XXXXMT4K as above HitIDVec seedLayersHitMap(m_event->simHitsInfo_.size()); for (int ilayer = 0; ilayer < Config::nlayers_per_seed; ++ilayer) { @@ -391,7 +716,7 @@ void MkBuilder::remap_seed_hits() if ((hitidx>=0) && (hitidx something else .... - track.setHitIdx(ilayer, seedLayersHitMap[lof_m_hits[hitidx].mcHitID()].index, ilayer); + track.setHitIdxLyr(ilayer, seedLayersHitMap[lof_m_hits[hitidx].mcHitID()].index, ilayer); } } } @@ -403,7 +728,7 @@ void MkBuilder::remap_cand_hits() // m_event_of_hits.m_layers_of_hits[i].m_hits to global // m_event->layerHits_[i] - // XXMT4K as above + // XXXXMT4K as above HitIDVec candLayersHitMap(m_event->simHitsInfo_.size()); for (int ilayer = 0; ilayer < Config::nLayers; ++ilayer) { @@ -420,7 +745,7 @@ void MkBuilder::remap_cand_hits() if ((hitidx>=0) && (hitidx something else .... - track.setHitIdx(ilayer, candLayersHitMap[lof_m_hits[hitidx].mcHitID()].index, ilayer); + track.setHitIdxLyr(ilayer, candLayersHitMap[lof_m_hits[hitidx].mcHitID()].index, ilayer); } } } @@ -441,21 +766,21 @@ void MkBuilder::align_simtracks() // Non-ROOT validation //------------------------------------------------------------------------------ -void MkBuilder::quality_output_BH(const EventOfCandidates& event_of_cands) +void MkBuilder::quality_output_BH() { quality_reset(); - quality_store_tracks_BH(event_of_cands); - - remap_cand_hits(); + // XXXXMT4K - align_simtracks(); + // remap_cand_hits(); + + // align_simtracks(); - for (int itrack = 0; itrack < m_event->candidateTracks_.size(); itrack++) + for (int i = 0; i < m_event->candidateTracks_.size(); i++) { - quality_process(m_event->candidateTracks_[itrack]); + quality_process(m_event->candidateTracks_[i]); } - + quality_print(); } @@ -465,13 +790,15 @@ void MkBuilder::quality_output_COMB() quality_store_tracks_COMB(); - remap_cand_hits(); + // XXXXMT4K - align_simtracks(); + // remap_cand_hits(); - for (int iseed = 0; iseed < m_event->candidateTracks_.size(); iseed++) + // align_simtracks(); + + for (int i = 0; i < m_event->candidateTracks_.size(); i++) { - quality_process(m_event->candidateTracks_[iseed]); + quality_process(m_event->candidateTracks_[i]); } quality_print(); @@ -482,31 +809,18 @@ void MkBuilder::quality_reset() m_cnt = m_cnt1 = m_cnt2 = m_cnt_8 = m_cnt1_8 = m_cnt2_8 = m_cnt_nomc = 0; } -void MkBuilder::quality_store_tracks_BH(const EventOfCandidates& event_of_cands) -{ - for (int ebin = 0; ebin < Config::nEtaBin; ++ebin) - { - const EtaBinOfCandidates &etabin_of_candidates = event_of_cands.m_etabins_of_candidates[ebin]; - - for (int itrack = 0; itrack < etabin_of_candidates.m_fill_index; itrack++) - { - m_event->candidateTracks_.push_back(etabin_of_candidates.m_candidates[itrack]); - } - } -} - void MkBuilder::quality_store_tracks_COMB() { - for (int ebin = 0; ebin < Config::nEtaBin; ++ebin) + for (int reg = 0; reg < TrackerInfo::Reg_Count; ++reg) { - const EtaBinOfCombCandidates &etabin_of_comb_candidates = m_event_tmp->m_event_of_comb_cands.m_etabins_of_comb_candidates[ebin]; + const EtaRegionOfCombCandidates &comb_candidates = m_event_tmp->m_event_of_comb_cands[reg]; - for (int iseed = 0; iseed < etabin_of_comb_candidates.m_fill_index; iseed++) + for (int i = 0; i < comb_candidates.m_size; i++) { // take the first one! - if ( ! etabin_of_comb_candidates.m_candidates[iseed].empty()) + if ( ! comb_candidates.m_candidates[i].empty()) { - m_event->candidateTracks_.push_back(etabin_of_comb_candidates.m_candidates[iseed].front()); + m_event->candidateTracks_.push_back(comb_candidates.m_candidates[i].front()); } } } @@ -514,9 +828,12 @@ void MkBuilder::quality_store_tracks_COMB() void MkBuilder::quality_process(Track &tkcand) { - TrackExtra extra(tkcand.label()); - extra.setMCTrackIDInfo(tkcand, m_event->layerHits_, m_event->simHitsInfo_); - int mctrk = extra.mcTrackID(); + // XXXXMT4K + // TrackExtra extra(tkcand.label()); + // extra.setMCTrackIDInfo(tkcand, m_event->layerHits_, m_event->simHitsInfo_); + // int mctrk = extra.mcTrackID(); + + int mctrk = tkcand.label(); float pt = tkcand.pT(); float ptmc = 0., pr = 0., nfoundmc = 0., chi2mc = 0.; @@ -524,7 +841,7 @@ void MkBuilder::quality_process(Track &tkcand) if (mctrk < 0 || mctrk >= Config::nTracks) { ++m_cnt_nomc; - // std::cout << "XX bad track idx " << mctrk << "\n"; + std::cout << "XX bad track idx " << mctrk << ", orig label was " << tkcand.label() << "\n"; } else { ptmc = m_event->simTracks_[mctrk].pT() ; @@ -568,13 +885,12 @@ void MkBuilder::quality_print() // Root validation //------------------------------------------------------------------------------ -void MkBuilder::root_val_BH(const EventOfCandidates& event_of_cands) +void MkBuilder::root_val_BH() { // remap seed tracks remap_seed_hits(); // get the tracks ready for validation - quality_store_tracks_BH(event_of_cands); remap_cand_hits(); m_event->fitTracks_ = m_event->candidateTracks_; // fixme: hack for now. eventually fitting will be including end-to-end align_simtracks(); @@ -628,54 +944,51 @@ void MkBuilder::init_track_extras() // FindTracksBestHit //------------------------------------------------------------------------------ -void MkBuilder::find_tracks_load_seeds(EventOfCandidates& event_of_cands) +void MkBuilder::find_tracks_load_seeds_BH() { - // partition recseeds into eta bins - for (int iseed = 0; iseed < m_event->seedTracks_.size(); ++iseed) - { - //if (m_event->seedTracks_[iseed].label() != iseed) - //{ - //printf("Bad label for recseed %d -- %d\n", iseed, m_event->seedTracks_[iseed].label()); - //} - - event_of_cands.InsertCandidate(m_event->seedTracks_[iseed]); - } + m_event->candidateTracks_ = m_event->seedTracks_; //dump seeds - dcall(print_seeds(event_of_cands)); + dcall(print_seeds(m_event->candidateTracks_)); } -void MkBuilder::FindTracksBestHit(EventOfCandidates& event_of_cands) + +void MkBuilder::FindTracksBestHit() { + // debug = true; + g_exe_ctx.populate(Config::numThreadsFinder); - tbb::parallel_for(tbb::blocked_range(0, Config::nEtaBin), - [&](const tbb::blocked_range& ebins) + TrackVec &cands = m_event->candidateTracks_; + + tbb::parallel_for_each(m_brl_ecp_regions.begin(), m_brl_ecp_regions.end(), + [&](int reg) { - for (int ebin = ebins.begin(); ebin != ebins.end(); ++ebin) - { - EtaBinOfCandidates& etabin_of_candidates = event_of_cands.m_etabins_of_candidates[ebin]; + // XXXXXX endcap only ... + // if (reg != TrackerInfo::Reg_Endcap_Neg && reg != TrackerInfo::Reg_Endcap_Pos) + // continue; + + const SteeringParams &st_par = m_steering_params[reg]; + + RegionOfSeedIndices rosi(m_event, reg); - tbb::parallel_for(tbb::blocked_range(0,etabin_of_candidates.m_fill_index,Config::numSeedsPerTask), - [&](const tbb::blocked_range& tracks) + tbb::parallel_for(rosi.tbb_blk_rng(), + [&](const tbb::blocked_range& blk_rng) { TrackerInfo &trk_info = Config::TrkInfo; std::unique_ptr mkfp(g_exe_ctx.m_fitters.GetFromPool(), retfitr); - int last_seed_layer = etabin_of_candidates.m_candidates[ tracks.begin() ].getLastHitLayer(); - int first_layer = trk_info.m_layers[ last_seed_layer ].m_next_barrel; + int first_layer = st_par.first_finding_layer; - printf("FindTracksBestHit Last seed layer = %d, First layer (eta_bin n tracks=%d) = %d\n", - last_seed_layer, etabin_of_candidates.m_fill_index, first_layer); + RangeOfSeedIndices rng = rosi.seed_rng(blk_rng); - for (int itrack = tracks.begin(); itrack < tracks.end(); itrack += NN) + while (rng.valid()) { - int end = std::min(itrack + NN, tracks.end()); + dprint(std::endl << "processing track=" << rng.m_beg << ", label=" <getXHitEnd(0, 0, 0)-mkfp->getXHitBegin(0, 0, 0) << std::endl; // #endif - //make candidates with best hit + // make candidates with best hit dprint("make new candidates"); - mkfp->AddBestHit(layer_of_hits, end - itrack); - mkfp->SetNhits(ilay + 1); //here again assuming one hit per layer (is this needed?) - //propagate to layer + (mkfp.get()->*st_par.add_best_hit_foo)(layer_of_hits, rng.n_proc()); + + mkfp->SetNhits(++n_hits); + + int next_layer = layer_info.*st_par.next_layer_doo; + + // propagate to layer if ( ! layer_info.m_is_outer) { - dcall(pre_prop_print(ilay, mkfp.get())); + dcall(pre_prop_print(next_layer, mkfp.get())); - mkfp->PropagateTracksToR(trk_info.m_layers[layer_info.m_next_barrel].m_rin, end - itrack); + (mkfp.get()->*st_par.propagate_foo)(trk_info.m_layers[next_layer].*st_par.prop_to_pos_doo, rng.n_proc()); - dcall(post_prop_print(ilay, mkfp.get())); + dcall(post_prop_print(next_layer, mkfp.get())); } else { break; } - ilay = layer_info.m_next_barrel; + ilay = next_layer; } // end of layer loop - mkfp->OutputFittedTracksAndHitIdx(etabin_of_candidates.m_candidates, itrack, end, true); - } - }); // end of seed loop - } - }); //end of parallel section over seeds + + mkfp->OutputFittedTracksAndHitIdx(cands, rng.m_beg, rng.m_end, true); + + ++rng; + } // end of loop over candidates in a tbb chunk + }); // end parallel loop over candidates in a region + }); // end of loop over regions } //------------------------------------------------------------------------------ @@ -733,19 +1052,22 @@ void MkBuilder::FindTracksBestHit(EventOfCandidates& event_of_cands) void MkBuilder::find_tracks_load_seeds() { - EventOfCombCandidates &event_of_comb_cands = m_event_tmp->m_event_of_comb_cands; + EventOfCombCandidates &eoccs = m_event_tmp->m_event_of_comb_cands; - for (int iseed = 0; iseed < m_event->seedTracks_.size(); ++iseed) + for (int r = TrackerInfo::Reg_Endcap_Neg; r < TrackerInfo::Reg_Count; ++r) { - //if (m_event->seedTracks_[iseed].label() != iseed) - //{ - //printf("Bad label for recseed %d -- %d\n", iseed, m_event->seedTracks_[iseed].label()); - //} - event_of_comb_cands.InsertSeed(m_event->seedTracks_[iseed]); + RegionOfSeedIndices rosi(m_event, r); + + eoccs.m_regions_of_comb_candidates[r].Reset(rosi.count()); + + for (int i = rosi.m_reg_beg; i < rosi.m_reg_end; ++i) + { + eoccs.m_regions_of_comb_candidates[r].InsertSeed(m_event->seedTracks_[i]); + } } //dump seeds - dcall(print_seeds(event_of_comb_cands)); + dcall(print_seeds(eoccs)); } //------------------------------------------------------------------------------ @@ -754,162 +1076,162 @@ void MkBuilder::find_tracks_load_seeds() void MkBuilder::FindTracksStandard() { + debug=true; + g_exe_ctx.populate(Config::numThreadsFinder); - EventOfCombCandidates &event_of_comb_cands = m_event_tmp->m_event_of_comb_cands; - tbb::parallel_for(tbb::blocked_range(0, Config::nEtaBin), - [&](const tbb::blocked_range& ebins) + EventOfCombCandidates &eoccs = m_event_tmp->m_event_of_comb_cands; + + tbb::parallel_for_each(eoccs.begin(), eoccs.end(), + [&](EtaRegionOfCombCandidates& comb_cands) { - // loop over eta bins - for (int ebin = ebins.begin(); ebin != ebins.end(); ++ebin) { - EtaBinOfCombCandidates& etabin_of_comb_candidates = event_of_comb_cands.m_etabins_of_comb_candidates[ebin]; - - int adaptiveSPT = Config::nEtaBin*etabin_of_comb_candidates.m_fill_index/Config::numThreadsFinder/2 + 1; - dprint("adaptiveSPT " << adaptiveSPT << " fill " << etabin_of_comb_candidates.m_fill_index); - // loop over seeds - tbb::parallel_for(tbb::blocked_range(0, etabin_of_comb_candidates.m_fill_index, std::min(Config::numSeedsPerTask, adaptiveSPT)), - [&](const tbb::blocked_range& seeds) - { - TrackerInfo &trk_info = Config::TrkInfo; + int adaptiveSPT = TrackerInfo::Reg_Count * comb_cands.m_size / Config::numThreadsFinder / 2 + 1; + + dprint("adaptiveSPT " << adaptiveSPT << " fill " << comb_cands.m_size); - const int start_seed = seeds.begin(); - const int end_seed = seeds.end(); - const int nseeds = end_seed - start_seed; + // loop over seeds + tbb::parallel_for(tbb::blocked_range(0, comb_cands.m_size, std::min(Config::numSeedsPerTask, adaptiveSPT)), + [&](const tbb::blocked_range& seeds) + { + TrackerInfo &trk_info = Config::TrkInfo; + + const int start_seed = seeds.begin(); + const int end_seed = seeds.end(); + const int nseeds = end_seed - start_seed; - // Loop over layers, starting from after the seed. - bool is_first_layer = true; - for (int ilay = trk_info.m_barrel[ Config::nlayers_per_seed ]; ; ) - { - dprint("processing lay=" << ilay); + // Loop over layers, starting from after the seed. + bool is_first_layer = true; + for (int ilay = trk_info.m_barrel[ Config::nlayers_per_seed ]; ; ) + { + dprint("processing lay=" << ilay); - LayerOfHits &layer_of_hits = m_event_of_hits.m_layers_of_hits[ilay]; - LayerInfo &layer_info = trk_info.m_layers[ilay]; + LayerOfHits &layer_of_hits = m_event_of_hits.m_layers_of_hits[ilay]; + LayerInfo &layer_info = trk_info.m_layers[ilay]; - // prepare unrolled vector to loop over - std::vector > seed_cand_idx; + // prepare unrolled vector to loop over + std::vector > seed_cand_idx; - for (int iseed = start_seed; iseed < end_seed; ++iseed) - { - std::vector &scands = etabin_of_comb_candidates.m_candidates[iseed]; - for (int ic = 0; ic < scands.size(); ++ic) - { - if (scands[ic].getLastHitIdx() >= -1) - { - seed_cand_idx.push_back(std::pair(iseed,ic)); - } - } - } - int theEndCand = seed_cand_idx.size(); - - if (theEndCand == 0) continue; - - std::vector> tmp_candidates(nseeds); - for (int iseed = 0; iseed < tmp_candidates.size(); ++iseed) - { - // XXXX MT: Tried adding 25 to reserve below as I was seeing some - // time spent in push_back ... but it didn't really help. - // We need to optimize this by throwing away and replacing the worst - // candidate once a better one arrives. This will also avoid sorting. - tmp_candidates[iseed].reserve(2*Config::maxCandsPerSeed);//factor 2 seems reasonable to start with - } - - //vectorized loop - for (int itrack = 0; itrack < theEndCand; itrack += NN) - { - int end = std::min(itrack + NN, theEndCand); + for (int iseed = start_seed; iseed < end_seed; ++iseed) + { + std::vector &scands = comb_cands[iseed]; + for (int ic = 0; ic < scands.size(); ++ic) + { + if (scands[ic].getLastHitIdx() >= -1) + { + seed_cand_idx.push_back(std::pair(iseed,ic)); + } + } + } + int theEndCand = seed_cand_idx.size(); + + if (theEndCand == 0) continue; + + std::vector> tmp_cands(nseeds); + for (int iseed = 0; iseed < tmp_cands.size(); ++iseed) + { + // XXXX MT: Tried adding 25 to reserve below as I was seeing some + // time spent in push_back ... but it didn't really help. + // We need to optimize this by throwing away and replacing the worst + // candidate once a better one arrives. This will also avoid sorting. + tmp_cands[iseed].reserve(2*Config::maxCandsPerSeed);//factor 2 seems reasonable to start with + } + + //vectorized loop + for (int itrack = 0; itrack < theEndCand; itrack += NN) + { + int end = std::min(itrack + NN, theEndCand); - dprint("processing track=" << itrack); + dprint("processing track=" << itrack); - std::unique_ptr mkfp (g_exe_ctx.m_fitters.GetFromPool(), retfitr); + std::unique_ptr mkfp (g_exe_ctx.m_fitters.GetFromPool(), retfitr); - mkfp->SetNhits(ilay);//here again assuming one hit per layer + mkfp->SetNhits(ilay);//here again assuming one hit per layer - //fixme find a way to deal only with the candidates needed in this thread - mkfp->InputTracksAndHitIdx(etabin_of_comb_candidates.m_candidates, - seed_cand_idx, itrack, end, - is_first_layer); - - //propagate to layer - if ( ! is_first_layer) - { - dcall(pre_prop_print(ilay, mkfp.get())); - mkfp->PropagateTracksToR(layer_info.m_rin, end - itrack); - dcall(post_prop_print(ilay, mkfp.get())); - } - - dprint("now get hit range"); - mkfp->SelectHitIndices(layer_of_hits, end - itrack); + //fixme find a way to deal only with the candidates needed in this thread + mkfp->InputTracksAndHitIdx(comb_cands.m_candidates, + seed_cand_idx, itrack, end, + is_first_layer); + + //propagate to layer + if ( ! is_first_layer) + { + dcall(pre_prop_print(ilay, mkfp.get())); + mkfp->PropagateTracksToR(layer_info.m_rin, end - itrack); + dcall(post_prop_print(ilay, mkfp.get())); + } + + dprint("now get hit range"); + mkfp->SelectHitIndices(layer_of_hits, end - itrack); //#ifdef PRINTOUTS_FOR_PLOTS //std::cout << "MX number of hits in window in layer " << ilay << " is " << mkfp->getXHitEnd(0, 0, 0)-mkfp->getXHitBegin(0, 0, 0) << std::endl; //#endif - dprint("make new candidates"); - mkfp->FindCandidates(layer_of_hits, tmp_candidates, start_seed, end - itrack); - } //end of vectorized loop + dprint("make new candidates"); + mkfp->FindCandidates(layer_of_hits, tmp_cands, start_seed, end - itrack); + } //end of vectorized loop // clean exceeding candidates per seed // FIXME: is there a reason why these are not vectorized???? - for (int is = 0; is < tmp_candidates.size(); ++is) - { - dprint("dump seed n " << is << " with input candidates=" << tmp_candidates[is].size()); - std::sort(tmp_candidates[is].begin(), tmp_candidates[is].end(), sortCandByHitsChi2); + for (int is = 0; is < tmp_cands.size(); ++is) + { + dprint("dump seed n " << is << " with input candidates=" << tmp_cands[is].size()); + std::sort(tmp_cands[is].begin(), tmp_cands[is].end(), sortCandByHitsChi2); - if (tmp_candidates[is].size() > Config::maxCandsPerSeed) - { - dprint("erase extra candidates" << " tmp_candidates[is].size()=" << tmp_candidates[is].size() - << " Config::maxCandsPerSeed=" << Config::maxCandsPerSeed); - tmp_candidates[is].erase(tmp_candidates[is].begin() + Config::maxCandsPerSeed, - tmp_candidates[is].end()); - } - dprint("dump seed n " << is << " with output candidates=" << tmp_candidates[is].size()); - } - //now swap with input candidates - for (int is = 0; is < tmp_candidates.size(); ++is) - { - if (tmp_candidates[is].size() > 0) - { - // Copy the best -2 cands back to the current list. - int num_hits = tmp_candidates[is].size(); + if (tmp_cands[is].size() > Config::maxCandsPerSeed) + { + dprint("erase extra candidates" << " tmp_cands[is].size()=" << tmp_cands[is].size() + << " Config::maxCandsPerSeed=" << Config::maxCandsPerSeed); + tmp_cands[is].erase(tmp_cands[is].begin() + Config::maxCandsPerSeed, + tmp_cands[is].end()); + } + dprint("dump seed n " << is << " with output candidates=" << tmp_cands[is].size()); + } + //now swap with input candidates + for (int is = 0; is < tmp_cands.size(); ++is) + { + if (tmp_cands[is].size() > 0) + { + // Copy the best -2 cands back to the current list. + int num_hits = tmp_cands[is].size(); - if (num_hits < Config::maxCandsPerSeed) - { - std::vector &ov = etabin_of_comb_candidates.m_candidates[start_seed+is]; - const int max_m2 = ov.size(); + if (num_hits < Config::maxCandsPerSeed) + { + std::vector &ov = comb_cands[start_seed+is]; + const int max_m2 = ov.size(); - int cur_m2 = 0; - while (cur_m2 < max_m2 && ov[cur_m2].getLastHitIdx() != -2) ++cur_m2; - while (cur_m2 < max_m2 && num_hits < Config::maxCandsPerSeed) - { - tmp_candidates[is].push_back( ov[cur_m2++] ); - ++num_hits; - } - } - - etabin_of_comb_candidates.m_candidates[start_seed+is].swap(tmp_candidates[is]); - tmp_candidates[is].clear(); - } - } - - if (layer_info.m_is_outer) - { - break; + int cur_m2 = 0; + while (cur_m2 < max_m2 && ov[cur_m2].getLastHitIdx() != -2) ++cur_m2; + while (cur_m2 < max_m2 && num_hits < Config::maxCandsPerSeed) + { + tmp_cands[is].push_back( ov[cur_m2++] ); + ++num_hits; + } + } + + comb_cands[start_seed+is].swap(tmp_cands[is]); + tmp_cands[is].clear(); } + } + + if (layer_info.m_is_outer) + { + break; + } - is_first_layer = false; - ilay = layer_info.m_next_barrel; - } // end of layer loop + is_first_layer = false; + ilay = layer_info.m_next_barrel; + } // end of layer loop // final sorting - for (int iseed = start_seed; iseed < end_seed; ++iseed) - { - std::vector& finalcands = etabin_of_comb_candidates.m_candidates[iseed]; - if (finalcands.size() == 0) continue; - std::sort(finalcands.begin(), finalcands.end(), sortCandByHitsChi2); - } - }); // end parallel-for loop over chunk of seeds within etabin - } // end loop over over eta bins within block - }); // end of loop over block of eta bins + for (int iseed = start_seed; iseed < end_seed; ++iseed) + { + std::vector& finalcands = comb_cands[iseed]; + if (finalcands.size() == 0) continue; + std::sort(finalcands.begin(), finalcands.end(), sortCandByHitsChi2); + } + }); // end parallel-for over chunk of seeds within region + }); // end of parallel-for-each over eta regions } //------------------------------------------------------------------------------ @@ -921,28 +1243,31 @@ void MkBuilder::FindTracksCloneEngine() g_exe_ctx.populate(Config::numThreadsFinder); EventOfCombCandidates &event_of_comb_cands = m_event_tmp->m_event_of_comb_cands; - tbb::parallel_for(tbb::blocked_range(0, Config::nEtaBin), + tbb::parallel_for(tbb::blocked_range(0, TrackerInfo::Reg_Count), [&](const tbb::blocked_range& ebins) { - for (int ebin = ebins.begin(); ebin != ebins.end(); ++ebin) { - EtaBinOfCombCandidates& etabin_of_comb_candidates = event_of_comb_cands.m_etabins_of_comb_candidates[ebin]; + for (int ebin = ebins.begin(); ebin != ebins.end(); ++ebin) + { + EtaRegionOfCombCandidates& comb_candidates = event_of_comb_cands.m_regions_of_comb_candidates[ebin]; + + int adaptiveSPT = Config::nEtaBin * comb_candidates.m_size/Config::numThreadsFinder/2 + 1; + + dprint("adaptiveSPT " << adaptiveSPT << " fill " << comb_candidates.m_size); - int adaptiveSPT = Config::nEtaBin*etabin_of_comb_candidates.m_fill_index/Config::numThreadsFinder/2 + 1; - dprint("adaptiveSPT " << adaptiveSPT << " fill " << etabin_of_comb_candidates.m_fill_index); - tbb::parallel_for(tbb::blocked_range(0, etabin_of_comb_candidates.m_fill_index, std::min(Config::numSeedsPerTask, adaptiveSPT)), + tbb::parallel_for(tbb::blocked_range(0, comb_candidates.m_size, std::min(Config::numSeedsPerTask, adaptiveSPT)), [&](const tbb::blocked_range& seeds) { std::unique_ptr cloner(g_exe_ctx.m_cloners.GetFromPool(), retcand); std::unique_ptr mkfp (g_exe_ctx.m_fitters.GetFromPool(), retfitr); // loop over layers - find_tracks_in_layers(etabin_of_comb_candidates, *cloner, mkfp.get(), seeds.begin(), seeds.end(), ebin); + find_tracks_in_layers(comb_candidates, *cloner, mkfp.get(), seeds.begin(), seeds.end(), ebin); }); } }); } -void MkBuilder::find_tracks_in_layers(EtaBinOfCombCandidates &etabin_of_comb_candidates, CandCloner &cloner, +void MkBuilder::find_tracks_in_layers(EtaRegionOfCombCandidates &comb_candidates, CandCloner &cloner, MkFitter *mkfp, int start_seed, int end_seed, int ebin) { TrackerInfo &trk_info = Config::TrkInfo; @@ -951,7 +1276,7 @@ void MkBuilder::find_tracks_in_layers(EtaBinOfCombCandidates &etabin_of_comb_can std::vector> seed_cand_idx; seed_cand_idx.reserve(n_seeds * Config::maxCandsPerSeed); - cloner.begin_eta_bin(&etabin_of_comb_candidates, start_seed, n_seeds); + cloner.begin_eta_bin(&comb_candidates, start_seed, n_seeds); // Loop over layers, starting from after the seed. // Note that we do a final pass with ilay = -1 to update parameters @@ -966,7 +1291,7 @@ void MkBuilder::find_tracks_in_layers(EtaBinOfCombCandidates &etabin_of_comb_can //prepare unrolled vector to loop over for (int iseed = start_seed; iseed != end_seed; ++iseed) { - std::vector &scands = etabin_of_comb_candidates.m_candidates[iseed]; + std::vector &scands = comb_candidates.m_candidates[iseed]; for (int ic = 0; ic < scands.size(); ++ic) { if (scands[ic].getLastHitIdx() >= -1) @@ -1007,7 +1332,7 @@ void MkBuilder::find_tracks_in_layers(EtaBinOfCombCandidates &etabin_of_comb_can // mkfp->SetNhits(ilay); // XXXXMT -- also elsewhere in building // XXXXMT should realy be increase N - hits !!!! - mkfp->InputTracksAndHitIdx(etabin_of_comb_candidates.m_candidates, + mkfp->InputTracksAndHitIdx(comb_candidates.m_candidates, seed_cand_idx, itrack, end, true); @@ -1030,13 +1355,13 @@ void MkBuilder::find_tracks_in_layers(EtaBinOfCombCandidates &etabin_of_comb_can mkfp->PropagateTracksToR(layer_info.m_rin, end - itrack); // copy_out the propagated track params, errors only (hit-idcs and chi2 already updated) - mkfp->CopyOutParErr(etabin_of_comb_candidates.m_candidates, + mkfp->CopyOutParErr(comb_candidates.m_candidates, end - itrack, true); } else { // copy_out the updated track params, errors only (hit-idcs and chi2 already updated) - mkfp->CopyOutParErr(etabin_of_comb_candidates.m_candidates, + mkfp->CopyOutParErr(comb_candidates.m_candidates, end - itrack, false); continue; } @@ -1084,7 +1409,7 @@ void MkBuilder::find_tracks_in_layers(EtaBinOfCombCandidates &etabin_of_comb_can // final sorting for (int iseed = start_seed; iseed < end_seed; ++iseed) { - std::vector& finalcands = etabin_of_comb_candidates.m_candidates[iseed]; + std::vector& finalcands = comb_candidates.m_candidates[iseed]; if (finalcands.size() == 0) continue; std::sort(finalcands.begin(), finalcands.end(), sortCandByHitsChi2); } diff --git a/mkFit/MkBuilder.h b/mkFit/MkBuilder.h index d6b45b631caf0..f52128d6de02f 100644 --- a/mkFit/MkBuilder.h +++ b/mkFit/MkBuilder.h @@ -7,12 +7,18 @@ #include "MkFitter.h" #include "CandCloner.h" +#include "SteeringParams.h" #include #include #include "Pool.h" +class TrackerInfo; +class LayerInfo; + +//------------------------------------------------------------------------------ + struct ExecutionContext { Pool m_cloners; @@ -37,7 +43,8 @@ class EventTmp; class MkBuilder { protected: - void fit_one_seed_set(TrackVec& simtracks, int itrack, int end, MkFitter *mkfp); + void fit_one_seed_set(TrackVec& simtracks, int itrack, int end, MkFitter *mkfp, + const bool is_brl[], const SteeringParams &st_par); Event *m_event; EventTmp *m_event_tmp; @@ -45,6 +52,9 @@ class MkBuilder int m_cnt=0, m_cnt1=0, m_cnt2=0, m_cnt_8=0, m_cnt1_8=0, m_cnt2_8=0, m_cnt_nomc=0; + SteeringParams m_steering_params[5]; + std::vector m_brl_ecp_regions; + public: typedef std::vector> CandIdx_t; @@ -69,29 +79,29 @@ class MkBuilder void remap_cand_hits(); // m_event_of_hits.m_layers_of_hits -> m_event->layerHits_ (cands only) void align_simtracks(); // simtrack labels get screwed up in endcap tests - void quality_output_BH(const EventOfCandidates& event_of_cands); + void quality_output_BH(); void quality_output_COMB(); void quality_reset(); void quality_process(Track& tkcand); void quality_print(); - void quality_store_tracks_BH(const EventOfCandidates& event_of_cands); void quality_store_tracks_COMB(); - void root_val_BH(const EventOfCandidates& event_of_cands); + void root_val_BH(); void root_val_COMB(); void init_track_extras(); // -------- - void find_tracks_load_seeds(EventOfCandidates& event_of_cands); // for FindTracksBestHit + void find_tracks_load_seeds_BH(); // for FindTracksBestHit void find_tracks_load_seeds(); - void find_tracks_in_layers(EtaBinOfCombCandidates &eb_of_cc, CandCloner &cloner, MkFitter *mkfp, + void find_tracks_in_layers(EtaRegionOfCombCandidates &comb_candidates, + CandCloner &cloner, MkFitter *mkfp, int start_seed, int end_seed, int ebin); // -------- - virtual void FindTracksBestHit(EventOfCandidates& event_of_cands); + virtual void FindTracksBestHit(); virtual void FindTracksStandard(); virtual void FindTracksCloneEngine(); #ifdef USE_CUDA diff --git a/mkFit/MkBuilderEndcap.cc b/mkFit/MkBuilderEndcap.cc index 23d643e57f40a..58583f8749e0d 100644 --- a/mkFit/MkBuilderEndcap.cc +++ b/mkFit/MkBuilderEndcap.cc @@ -62,7 +62,7 @@ namespace { void print_seeds(const EventOfCandidates& event_of_cands) { for (int ebin = 0; ebin < Config::nEtaBin; ++ebin) { const EtaBinOfCandidates &etabin_of_candidates = event_of_cands.m_etabins_of_candidates[ebin]; - for (int iseed = 0; iseed < etabin_of_candidates.m_fill_index; iseed++) { + for (int iseed = 0; iseed < etabin_of_candidates.m_size; iseed++) { print_seed2(etabin_of_candidates.m_candidates[iseed]); } } @@ -71,7 +71,7 @@ namespace { void print_seeds(const EventOfCombCandidates& event_of_comb_cands) { for (int ebin = 0; ebin < Config::nEtaBin; ++ebin) { const EtaBinOfCombCandidates &etabin_of_comb_candidates = event_of_comb_cands.m_etabins_of_comb_candidates[ebin]; - for (int iseed = 0; iseed < etabin_of_comb_candidates.m_fill_index; iseed++) { + for (int iseed = 0; iseed < etabin_of_comb_candidates.m_size; iseed++) { print_seed2(etabin_of_comb_candidates.m_candidates[iseed].front()); } } @@ -141,7 +141,7 @@ inline void MkBuilderEndcap::fit_one_seed_set_endcap(TrackVec& seedtracks, int i // OLD GC: const int ilay = Config::nlayers_per_seed; // layer 3, we ignore PXB1 TrackerInfo &trk_info = Config::TrkInfo; - int last_seed_layer = seedtracks[itrack].getLastHitLayer(); + int last_seed_layer = seedtracks[itrack].getLastHitLyr(); int ilay = trk_info.m_layers[ last_seed_layer ].m_next_ecap_pos; // XXXXMT pos/neg dcall(pre_prop_print(ilay, mkfp)); @@ -186,20 +186,20 @@ void MkBuilderEndcap::FindTracksBestHit(EventOfCandidates& event_of_cands) { EtaBinOfCandidates& etabin_of_candidates = event_of_cands.m_etabins_of_candidates[ebin]; - tbb::parallel_for(tbb::blocked_range(0,etabin_of_candidates.m_fill_index,Config::numSeedsPerTask), + tbb::parallel_for(tbb::blocked_range(0,etabin_of_candidates.m_size,Config::numSeedsPerTask), [&](const tbb::blocked_range& tracks) { TrackerInfo &trk_info = Config::TrkInfo; std::unique_ptr mkfp(g_exe_ctx.m_fitters.GetFromPool(), retfitr); - int last_seed_layer = etabin_of_candidates.m_candidates[ tracks.begin() ].getLastHitLayer(); + int last_seed_layer = etabin_of_candidates.m_candidates[ tracks.begin() ].getLastHitLyr(); int first_layer = trk_info.m_layers[ last_seed_layer ].m_next_ecap_pos; // XXXXMT for (int itrack = tracks.begin(); itrack < tracks.end(); itrack += NN) { int end = std::min(itrack + NN, tracks.end()); - dprint(std::endl << "processing track=" << itrack << " etabin=" << ebin << " findex=" << etabin_of_candidates.m_fill_index); + dprint(std::endl << "processing track=" << itrack << " etabin=" << ebin << " findex=" << etabin_of_candidates.m_size); mkfp->SetNhits(Config::nlayers_per_seed); // Could also count hits in first seed mkfp->InputTracksAndHitIdx(etabin_of_candidates.m_candidates, itrack, end, true); @@ -216,7 +216,7 @@ void MkBuilderEndcap::FindTracksBestHit(EventOfCandidates& event_of_cands) // XXX This should actually be done in some other thread for the next layer while // this thread is crunching the current one. // For now it's done in MkFitter::AddBestHit(), two loops before the data is needed. - // for (int i = 0; i < bunch_of_hits.m_fill_index; ++i) + // for (int i = 0; i < bunch_of_hits.m_size; ++i) // { // _mm_prefetch((char*) & bunch_of_hits.m_hits[i], _MM_HINT_T1); // } @@ -266,13 +266,13 @@ void MkBuilderEndcap::FindTracksStandard() { EventOfCombCandidates &event_of_comb_cands = m_event_tmp->m_event_of_comb_cands; - tbb::parallel_for(tbb::blocked_range(0, Config::nEtaBin), + tbb::parallel_for(tbb::blocked_range(0, TrackerInfo::Reg_Count), [&](const tbb::blocked_range& ebins) { for (int ebin = ebins.begin(); ebin != ebins.end(); ++ebin) { - EtaBinOfCombCandidates& etabin_of_comb_candidates = event_of_comb_cands.m_etabins_of_comb_candidates[ebin]; + EtaRegionOfCombCandidates& etabin_of_comb_candidates = event_of_comb_cands.m_regions_of_comb_candidates[ebin]; - tbb::parallel_for(tbb::blocked_range(0,etabin_of_comb_candidates.m_fill_index,Config::numSeedsPerTask), + tbb::parallel_for(tbb::blocked_range(0,etabin_of_comb_candidates.m_size,Config::numSeedsPerTask), [&](const tbb::blocked_range& seeds) { const int start_seed = seeds.begin(); @@ -418,13 +418,13 @@ void MkBuilderEndcap::FindTracksCloneEngine() { EventOfCombCandidates &event_of_comb_cands = m_event_tmp->m_event_of_comb_cands; - tbb::parallel_for(tbb::blocked_range(0, Config::nEtaBin), + tbb::parallel_for(tbb::blocked_range(0, TrackerInfo::Reg_Count), [&](const tbb::blocked_range& ebins) { for (int ebin = ebins.begin(); ebin != ebins.end(); ++ebin) { - EtaBinOfCombCandidates& etabin_of_comb_candidates = event_of_comb_cands.m_etabins_of_comb_candidates[ebin]; + EtaRegionOfCombCandidates& etabin_of_comb_candidates = event_of_comb_cands.m_regions_of_comb_candidates[ebin]; - tbb::parallel_for(tbb::blocked_range(0,etabin_of_comb_candidates.m_fill_index,Config::numSeedsPerTask), + tbb::parallel_for(tbb::blocked_range(0,etabin_of_comb_candidates.m_size,Config::numSeedsPerTask), [&](const tbb::blocked_range& seeds) { std::unique_ptr cloner(g_exe_ctx.m_cloners.GetFromPool(), retcand); @@ -437,7 +437,7 @@ void MkBuilderEndcap::FindTracksCloneEngine() }); } -void MkBuilderEndcap::find_tracks_in_layers_endcap(EtaBinOfCombCandidates &etabin_of_comb_candidates, CandCloner &cloner, +void MkBuilderEndcap::find_tracks_in_layers_endcap(EtaRegionOfCombCandidates &etabin_of_comb_candidates, CandCloner &cloner, MkFitter *mkfp, int start_seed, int end_seed, int ebin) { auto n_seeds = end_seed - start_seed; diff --git a/mkFit/MkBuilderEndcap.h b/mkFit/MkBuilderEndcap.h index 175bee43d3f52..dd42d7acdea4f 100644 --- a/mkFit/MkBuilderEndcap.h +++ b/mkFit/MkBuilderEndcap.h @@ -9,7 +9,7 @@ class MkBuilderEndcap : public MkBuilder protected: void fit_one_seed_set_endcap(TrackVec& simtracks, int itrack, int end, MkFitter *mkfp); - void find_tracks_in_layers_endcap(EtaBinOfCombCandidates &eb_of_cc, CandCloner &cloner, MkFitter *mkfp, + void find_tracks_in_layers_endcap(EtaRegionOfCombCandidates &comb_cands, CandCloner &cloner, MkFitter *mkfp, int start_seed, int end_seed, int ebin); public: @@ -23,7 +23,7 @@ class MkBuilderEndcap : public MkBuilder void fit_seeds() override; - void FindTracksBestHit(EventOfCandidates& event_of_cands) override; + void FindTracksBestHit(EventOfCandidates& event_of_cands); void FindTracksStandard() override; void FindTracksCloneEngine() override; }; diff --git a/mkFit/MkFitter.cc b/mkFit/MkFitter.cc index e5fdf6b1c1c59..fb424245710e9 100644 --- a/mkFit/MkFitter.cc +++ b/mkFit/MkFitter.cc @@ -147,7 +147,8 @@ void MkFitter::InputTracksAndHits(const std::vector& tracks, for (int hi = 0; hi < Nhits; ++hi) { const int hidx = trk.getHitIdx(hi); - const Hit &hit = layerHits[hi].m_hits[hidx]; + const int hlyr = trk.getHitLyr(hi); + const Hit &hit = layerHits[hlyr].m_hits[hidx]; msErr[hi].CopyIn(itrack, hit.errArray()); msPar[hi].CopyIn(itrack, hit.posArray()); @@ -572,9 +573,9 @@ void MkFitter::CollectFitValidation(const int hi, const int N_proc, const Event void MkFitter::FitTracksTestEndcap(const int N_proc, const Event* ev, const bool useParamBfield) { - - if (countValidHits(0)<8) return; - if (Label.ConstAt(0, 0, 0)<0) return; + // XXXXMT4G + //if (countValidHits(0)<8) return; + //if (Label.ConstAt(0, 0, 0)<0) return; //float ptin = 1./Par[iC].ConstAt(0, 0, 3); @@ -624,6 +625,40 @@ void MkFitter::FitTracksTestEndcap(const int N_proc, const Event* ev, const bool // << " fitted hits: " << hitcount<< std::endl; } +void MkFitter::FitTracksSteered(const bool is_barrel[], const int N_proc, const Event * ev, const bool useParamBfield) +{ + // Fitting loop. + + dprintf("MkFitter::FitTracksSteered %d %d %d\n", is_barrel[0], is_barrel[1], is_barrel[2]); + + for (int hi = 0; hi < Nhits; ++hi) + { + // Note, charge is not passed (line propagation). + // propagateLineToRMPlex(Err[iC], Par[iC], msErr[hi], msPar[hi], + // Err[iP], Par[iP]); + + if (is_barrel[hi]) + { + propagateHelixToRMPlex(Err[iC], Par[iC], Chg, msPar[hi], + Err[iP], Par[iP], N_proc, useParamBfield); + + updateParametersMPlex(Err[iP], Par[iP], Chg, msErr[hi], msPar[hi], + Err[iC], Par[iC], N_proc); + } + else + { + propagateHelixToZMPlex(Err[iC], Par[iC], Chg, msPar[hi], + Err[iP], Par[iP], N_proc, useParamBfield); + + updateParametersEndcapMPlex(Err[iP], Par[iP], Chg, msErr[hi], msPar[hi], + Err[iC], Par[iC], N_proc); + } + + if (Config::fit_val) MkFitter::CollectFitValidation(hi,N_proc,ev); + } + // XXXXX What's with chi2? +} + void MkFitter::OutputTracks(std::vector& tracks, int beg, int end, int iCP) const { // Copies last track parameters (updated) into Track objects. @@ -661,8 +696,6 @@ void MkFitter::OutputFittedTracksAndHitIdx(std::vector& tracks, int beg, tracks[i].setChi2(Chi2(itrack, 0, 0)); tracks[i].setLabel(Label(itrack, 0, 0)); - // XXXXX chi2 is not set (also not in SMatrix fit, it seems) - tracks[i].resetHits(); for (int hi = 0; hi < Nhits; ++hi) { @@ -783,15 +816,15 @@ void MkFitter::SelectHitIndices(const LayerOfHits &layer_of_hits, const int N_pr { // MT: Access into m_hit_zs and m_hit_phis is 1% run-time each. -#ifdef LOH_USE_PHI_Z_ARRAYS - float ddz = std::abs(z - L.m_hit_zs[hi]); +#ifdef LOH_USE_PHI_Q_ARRAYS + float ddz = std::abs(z - L.m_hit_qs[hi]); float ddphi = std::abs(phi - L.m_hit_phis[hi]); if (ddphi > Config::PI) ddphi = Config::TwoPI - ddphi; if (dump) printf(" SHI %3d %4d %4d %5d %6.3f %6.3f %6.4f %7.5f %s\n", zi, pi, pb, hi, - L.m_hit_zs[hi], L.m_hit_phis[hi], ddz, ddphi, + L.m_hit_qs[hi], L.m_hit_phis[hi], ddz, ddphi, (ddz < dz && ddphi < dphi) ? "PASS" : "FAIL"); // MT: Commenting this check out gives full efficiency ... @@ -1619,13 +1652,16 @@ void MkFitter::CopyOutParErr(std::vector >& seed_cand_vec, void MkFitter::PropagateTracksToZ(float Z, const int N_proc) { - propagateHelixToZMPlex(Err[iC], Par[iC], Chg, Z, - Err[iP], Par[iP], N_proc); + // printf("MkFitter::PropagateTracksToZ z=%f\n", Z); + propagateHelixToZMPlex(Err[iC], Par[iC], Chg, Z, + Err[iP], Par[iP], N_proc); } void MkFitter::SelectHitIndicesEndcap(const LayerOfHits &layer_of_hits, const int N_proc, bool dump) { + // debug = 1; + const int iI = iP; const float nSigmaPhi = 3; const float nSigmaR = 3; @@ -1661,7 +1697,7 @@ void MkFitter::SelectHitIndicesEndcap(const LayerOfHits &layer_of_hits, dphi = nSigmaPhi * std::sqrt(std::abs(dphi2)); - if (std::abs(dphi) Config::m_max_dz) dz = Config::m_max_dz; - if (std::abs(dphi) > Config::m_max_dphi) dphi = Config::m_max_dphi; + // XXXXMT4K if (std::abs(dphi) > Config::m_max_dphi) dphi = Config::m_max_dphi; const int rb1 = L.GetQBinChecked(r - dr); const int rb2 = L.GetQBinChecked(r + dr) + 1; @@ -1695,7 +1731,7 @@ void MkFitter::SelectHitIndicesEndcap(const LayerOfHits &layer_of_hits, // const int pb2 = L.GetPhiBin(phi + dphi) + 2; if (dump) - printf("LayerOfHits::SelectHitIndices %6.3f %6.3f %6.4f %7.5f %3d %3d %4d %4d\n", + printf("LayerOfHits::SelectHitIndicesEndcap %6.3f %6.3f %6.4f %7.5f %3d %3d %4d %4d\n", r, phi, dr, dphi, rb1, rb2, pb1, pb2); // MT: One could iterate in "spiral" order, to pick hits close to the center. @@ -1719,16 +1755,16 @@ void MkFitter::SelectHitIndicesEndcap(const LayerOfHits &layer_of_hits, { // MT: Access into m_hit_zs and m_hit_phis is 1% run-time each. -#ifdef LOH_USE_PHI_Z_ARRAYS - float ddz = std::abs(z - L.m_hit_zs[hi]); +#ifdef LOH_USE_PHI_Q_ARRAYS + float ddr = std::abs(r - L.m_hit_qs[hi]); float ddphi = std::abs(phi - L.m_hit_phis[hi]); if (ddphi > Config::PI) ddphi = Config::TwoPI - ddphi; if (dump) printf(" SHI %3d %4d %4d %5d %6.3f %6.3f %6.4f %7.5f %s\n", ri, pi, pb, hi, - L.m_hit_zs[hi], L.m_hit_phis[hi], ddz, ddphi, - (ddz < dz && ddphi < dphi) ? "PASS" : "FAIL"); + L.m_hit_qs[hi], L.m_hit_phis[hi], ddr, ddphi, + (ddr < dr && ddphi < dphi) ? "PASS" : "FAIL"); // MT: Commenting this check out gives full efficiency ... // and means our error estimations are wrong! @@ -1751,6 +1787,8 @@ void MkFitter::SelectHitIndicesEndcap(const LayerOfHits &layer_of_hits, void MkFitter::AddBestHitEndcap(const LayerOfHits &layer_of_hits, const int N_proc) { + // debug = true; + float minChi2[NN]; int bestHit[NN]; // MT: fill_n gave me crap on MIC, NN=8,16, doing in maxSize search below. @@ -1892,7 +1930,7 @@ void MkFitter::AddBestHitEndcap(const LayerOfHits &layer_of_hits, const int N_pr //fixme decide what to do in case no hit found if (bestHit[itrack] >= 0) { - const Hit &hit = layer_of_hits.m_hits[ bestHit[itrack] ]; + const Hit &hit = layer_of_hits.m_hits[ bestHit[itrack] ]; const float chi2 = minChi2[itrack]; dprint("ADD BEST HIT FOR TRACK #" << itrack << std::endl @@ -1909,10 +1947,11 @@ void MkFitter::AddBestHitEndcap(const LayerOfHits &layer_of_hits, const int N_pr bool withinBounds = true; float r2 = Par[iP](itrack,0,0)*Par[iP](itrack,0,0)+Par[iP](itrack,1,0)*Par[iP](itrack,1,0); - if ( r2<(Config::cmsDiskMinRs[Nhits]*Config::cmsDiskMinRs[Nhits]) || - r2>(Config::cmsDiskMaxRs[Nhits]*Config::cmsDiskMaxRs[Nhits]) || - r2>(Config::cmsDiskMinRsHole[Nhits]*Config::cmsDiskMinRsHole[Nhits]) || - r2<(Config::cmsDiskMaxRsHole[Nhits]*Config::cmsDiskMaxRsHole[Nhits]) ) withinBounds = false; + // XXXXMT4G + // if ( r2<(Config::cmsDiskMinRs[Nhits]*Config::cmsDiskMinRs[Nhits]) || + // r2>(Config::cmsDiskMaxRs[Nhits]*Config::cmsDiskMaxRs[Nhits]) || + // r2>(Config::cmsDiskMinRsHole[Nhits]*Config::cmsDiskMinRsHole[Nhits]) || + // r2<(Config::cmsDiskMaxRsHole[Nhits]*Config::cmsDiskMaxRsHole[Nhits]) ) withinBounds = false; #ifdef DEBUG r2= std::sqrt(r2); diff --git a/mkFit/MkFitter.h b/mkFit/MkFitter.h index c0e8c5984ee4f..d5e60feb56507 100644 --- a/mkFit/MkFitter.h +++ b/mkFit/MkFitter.h @@ -92,6 +92,7 @@ struct MkFitter void ConformalFitTracks(bool fitting, int beg, int end); void FitTracks(const int N_proc, const Event * ev, const bool useParamBfield = false); void FitTracksTestEndcap(const int N_proc, const Event* ev, const bool useParamBfield = false); + void FitTracksSteered(const bool is_barrel[], const int N_proc, const Event * ev, const bool useParamBfield = false); void CollectFitValidation(const int hi, const int N_proc, const Event * ev) const; diff --git a/mkFit/PropagationMPlex.cc b/mkFit/PropagationMPlex.cc index a1bfc759d3467..bdf98d516b213 100644 --- a/mkFit/PropagationMPlex.cc +++ b/mkFit/PropagationMPlex.cc @@ -767,7 +767,9 @@ void propagateHelixToZMPlex(const MPlexLS &inErr, const MPlexLV& inPar, MPlexQF msZ; #pragma simd for (int n = 0; n < NN; ++n) { - msZ.At(n, 0, 0) = (inPar.ConstAt(n, 2, 0) > 0) ? z : -z; + // XXXXMT4G + // msZ.At(n, 0, 0) = (inPar.ConstAt(n, 2, 0) > 0) ? z : -z; + msZ.At(n, 0, 0) = z; } helixAtZ(inPar, inChg, outPar, msZ, errorProp, N_proc); @@ -826,10 +828,13 @@ void propagateHelixToZMPlex(const MPlexLS &inErr, const MPlexLV& inPar, for (int i = 0; i < 6; ++i) { dprintf("%8f ", outPar.At(kk,i,0)); printf("\n"); } dprintf("\n"); - if (std::abs(outPar.At(kk,2,0)-inPar.ConstAt(kk, 2, 0))>0.0001) { - dprint_np(kk, "DID NOT GET TO Z, dZ=" << std::abs(outPar.At(kk,2,0)-inPar.ConstAt(kk, 2, 0)) - << " z=" << msZ.ConstAt(kk, 2, 0) << " zin=" << inPar.ConstAt(kk,2,0) << " zout=" << outPar.At(kk,2,0) << std::endl - << "pt=" << hipo(inPar.ConstAt(kk,3,0), inPar.ConstAt(kk,4,0)) << " pz=" << inPar.ConstAt(kk,5,0)); + // XXXXMT4G + // if (std::abs(outPar.At(kk,2,0) - inPar.ConstAt(kk, 2, 0))>0.0001) { + // dprint_np(kk, "DID NOT GET TO Z, dZ=" << std::abs(outPar.At(kk,2,0)-inPar.ConstAt(kk, 2, 0)) + if (std::abs(outPar.At(kk,2,0) - z) > 0.0001) { + dprint_np(kk, "DID NOT GET TO Z, dZ=" << std::abs(outPar.At(kk,2,0) - z) + << " z=" << msZ.ConstAt(kk, 2, 0) << " zin=" << inPar.ConstAt(kk,2,0) << " zout=" << outPar.At(kk,2,0) + << "\n pt=" << hipo(inPar.ConstAt(kk,3,0), inPar.ConstAt(kk,4,0)) << " pz=" << inPar.ConstAt(kk,5,0)); } } } diff --git a/mkFit/buildtestMPlex.cc b/mkFit/buildtestMPlex.cc index 103d228531db4..4097f7217acb0 100644 --- a/mkFit/buildtestMPlex.cc +++ b/mkFit/buildtestMPlex.cc @@ -82,8 +82,8 @@ double runBuildingTestPlexBestHit(Event& ev, MkBuilder& builder) builder.fit_seeds(); - EventOfCandidates event_of_cands; - builder.find_tracks_load_seeds(event_of_cands); + // EventOfCandidates event_of_cands; + builder.find_tracks_load_seeds_BH(); #ifdef USE_VTUNE_PAUSE __itt_resume(); @@ -101,7 +101,7 @@ double runBuildingTestPlexBestHit(Event& ev, MkBuilder& builder) #if USE_CUDA builder_cu.FindTracksBestHit(event_of_cands); #else - builder.FindTracksBestHit(event_of_cands); + builder.FindTracksBestHit(); #endif time = dtime() - time; @@ -111,9 +111,9 @@ double runBuildingTestPlexBestHit(Event& ev, MkBuilder& builder) #endif if (!Config::normal_val) { - if (!Config::silent) builder.quality_output_BH(event_of_cands); + if (!Config::silent) builder.quality_output_BH(); } else { - builder.root_val_BH(event_of_cands); + builder.root_val_BH(); } builder.end_event(); @@ -127,9 +127,6 @@ double runBuildingTestPlexBestHit(Event& ev, MkBuilder& builder) double runBuildingTestPlexStandard(Event& ev, EventTmp& ev_tmp, MkBuilder& builder) { - EventOfCombCandidates &event_of_comb_cands = ev_tmp.m_event_of_comb_cands; - event_of_comb_cands.Reset(); - builder.begin_event(&ev, &ev_tmp, __func__); if (Config::findSeeds) {builder.find_seeds();} @@ -152,7 +149,7 @@ double runBuildingTestPlexStandard(Event& ev, EventTmp& ev_tmp, MkBuilder& build #ifdef USE_VTUNE_PAUSE __itt_pause(); #endif - + if (!Config::normal_val) { if (!Config::silent) builder.quality_output_COMB(); } else {builder.root_val_COMB();} @@ -168,9 +165,6 @@ double runBuildingTestPlexStandard(Event& ev, EventTmp& ev_tmp, MkBuilder& build double runBuildingTestPlexCloneEngine(Event& ev, EventTmp& ev_tmp, MkBuilder& builder) { - EventOfCombCandidates &event_of_comb_cands = ev_tmp.m_event_of_comb_cands; - event_of_comb_cands.Reset(); - builder.begin_event(&ev, &ev_tmp, __func__); if (Config::findSeeds) {builder.find_seeds();} diff --git a/mkFit/mkFit.cc b/mkFit/mkFit.cc index 32e555aa25b5b..95b5755ea1f73 100644 --- a/mkFit/mkFit.cc +++ b/mkFit/mkFit.cc @@ -306,19 +306,20 @@ void test_standard() assert(threads.begin() == threads.end()-1 && thisthread < Config::numThreadsEvents); std::vector plex_tracks; - auto& ev_tmp = ev_tmps[thisthread]; - auto& ev = *evs[thisthread].get(); - auto& mkb = *mkbs[thisthread].get(); - auto fp = fps[thisthread].get(); + auto& ev_tmp = ev_tmps[thisthread]; + auto& ev = *evs[thisthread].get(); + auto& mkb = *mkbs[thisthread].get(); + auto fp = fps[thisthread].get(); + if (g_input_version == 0) fseek(fp, sizeof(int), SEEK_SET); int evstart = thisthread*events_per_thread; - int evend = std::min(Config::nEvents, evstart+events_per_thread); + int evend = std::min(Config::nEvents, evstart+events_per_thread); dprint("thisthread " << thisthread << " events " << Config::nEvents << " events/thread " << events_per_thread << " range " << evstart << ":" << evend); - for (int evt = evstart; evt < evend; ++evt) + for (int evt = evstart; evt < evend; ++evt) { ev.Reset(nevt++); @@ -344,7 +345,7 @@ void test_standard() double t_best[NT] = {0}, t_cur[NT]; simtrackstot += ev.simTracks_.size(); - seedstot += ev.seedTracks_.size(); + seedstot += ev.seedTracks_.size(); for (int b = 0; b < Config::finderReportBestOutOfN; ++b) { diff --git a/test/CylCowWLids.C b/test/CylCowWLids.C index 0d524dd1d4dc8..68744beb3c37f 100644 --- a/test/CylCowWLids.C +++ b/test/CylCowWLids.C @@ -12,7 +12,7 @@ TrackerInfo g_tracker_info; void print_etas(LayerInfo &li, float dz) { float r, z; - if (li.m_is_barrel) + if (li.is_barrel()) { r = li.r_mean(); z = li.m_zmax; @@ -24,7 +24,7 @@ void print_etas(LayerInfo &li, float dz) printf("%2d %6.4f %6.4f %6.4f", li.m_layer_id, getEta(r, z - dz), getEta(r, z), getEta(r, z + dz)); - if ( ! li.m_is_barrel) + if ( ! li.is_barrel()) { r = li.m_rin; From 5a583cf8195d2688731470e54e8158916970cf8f Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Thu, 23 Mar 2017 13:31:35 -0700 Subject: [PATCH 009/172] Forgotten files --- mkFit/SteeringParams.h | 33 +++++++++++++++++++++++++++++++++ mkFit/mt-notes.txt | 16 ++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 mkFit/SteeringParams.h diff --git a/mkFit/SteeringParams.h b/mkFit/SteeringParams.h new file mode 100644 index 0000000000000..379cc2dc2cbc8 --- /dev/null +++ b/mkFit/SteeringParams.h @@ -0,0 +1,33 @@ +#ifndef SteeringParams_h +#define SteeringParams_h + +class LayerInfo; +class MkFitter; + +struct SteeringParams +{ + int first_finding_layer; // layer to consider first + float LayerInfo::*prop_to_pos_doo; + int LayerInfo::*next_layer_doo; + void (MkFitter::*propagate_foo) (float, const int); + void (MkFitter::*select_hits_foo) (const LayerOfHits &, const int, bool); + void (MkFitter::*add_best_hit_foo)(const LayerOfHits &, const int); + + SteeringParams() {} + + SteeringParams(int ffl, + float LayerInfo::*ptp_d, + int LayerInfo::*nl_d, + void (MkFitter::*p_f) (float, const int), + void (MkFitter::*sh_f) (const LayerOfHits &, const int, bool), + void (MkFitter::*abh_f)(const LayerOfHits &, const int)) : + first_finding_layer(ffl), + prop_to_pos_doo(ptp_d), + next_layer_doo(nl_d), + propagate_foo(p_f), + select_hits_foo(sh_f), + add_best_hit_foo(abh_f) + {} +}; + +#endif diff --git a/mkFit/mt-notes.txt b/mkFit/mt-notes.txt index 237ac02deb9a7..4307ec492f9e6 100644 --- a/mkFit/mt-notes.txt +++ b/mkFit/mt-notes.txt @@ -1,3 +1,19 @@ +######### +Notes for Kevin +######### + +In general, search for XXMT4K. + +Thing that is probably most urgent is Validation + some issues with Simulation +and Seeding. + +Remapping funcs after finding commented out in: + MkBuilder::quality_output_BH() + MkBuilder::quality_output_COMB() + +What is needed for validation? + + ######### Full detector tracking ######### From bcd21a14e901d4e1e1251c96c6d0ff6953bc3fc8 Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Fri, 24 Mar 2017 00:36:54 -0700 Subject: [PATCH 010/172] Standard and Clone-engine track finding now works for barrel and endcap. --- Config.h | 3 + Simulation.cc | 4 +- TrackerInfo.h | 4 +- mkFit/HitStructures.h | 3 +- mkFit/MkBuilder.cc | 239 ++++++++++++++++++++++------------------- mkFit/MkBuilder.h | 2 +- mkFit/MkFitter.cc | 23 ++-- mkFit/MkFitter.h | 4 +- mkFit/SteeringParams.h | 14 ++- 9 files changed, 165 insertions(+), 131 deletions(-) diff --git a/Config.h b/Config.h index c6488757a468f..5e3954e1e7feb 100644 --- a/Config.h +++ b/Config.h @@ -148,6 +148,9 @@ namespace Config // XXMT Hardhack -- transition region excluded in Simulation::setupTrackByToyMC() constexpr float minSimEta = -2.4; constexpr float maxSimEta = 2.4; + // For testing separate EC-/BRL/EC+; -2.3--1.5 / -0.9-0.9 / 1.5-2.3 + //constexpr float minSimEta = -0.9; + //constexpr float maxSimEta = 0.9; constexpr float hitposerrXY = 0.01; // resolution is 100um in xy --> more realistic scenario is 0.003 constexpr float hitposerrZ = 0.1; // resolution is 1mm in z diff --git a/Simulation.cc b/Simulation.cc index 15b5d990d10fa..e3dce554123f4 100644 --- a/Simulation.cc +++ b/Simulation.cc @@ -45,8 +45,8 @@ void setupTrackByToyMC(SVector3& pos, SVector3& mom, SMatrixSym66& covtrk, roll_eta_dice: float eta = Config::minSimEta + (Config::maxSimEta - Config::minSimEta) * g_unif(g_gen); - // XXMT Hardhack ... exclude transition region eta - if (Config::TrkInfo.is_transition(eta)) + // XXXXMT Hardhack ... exclude transition region eta + if (Config::TrkInfo.is_transition(eta, 0.1f)) goto roll_eta_dice; float pz = pt*(1./(std::tan(2*std::atan(std::exp(-eta))))); diff --git a/TrackerInfo.h b/TrackerInfo.h index 08243b5f680c2..ce129dd4f794c 100644 --- a/TrackerInfo.h +++ b/TrackerInfo.h @@ -82,9 +82,9 @@ class TrackerInfo return std::abs(eta) < m_eta_trans_beg; } - bool is_transition(float eta) const + bool is_transition(float eta, float safety = 0) const { - return std::abs(eta) >= m_eta_trans_beg && std::abs(eta) <= m_eta_trans_end; + return std::abs(eta) >= m_eta_trans_beg - safety && std::abs(eta) <= m_eta_trans_end + safety; } bool is_endcap(float eta) const diff --git a/mkFit/HitStructures.h b/mkFit/HitStructures.h index c5000c48f8269..471ecb3b25ca1 100644 --- a/mkFit/HitStructures.h +++ b/mkFit/HitStructures.h @@ -349,7 +349,8 @@ class EventOfCombCandidates std::vector::iterator begin() { return m_regions_of_comb_candidates.begin(); } std::vector::iterator end() { return m_regions_of_comb_candidates.end(); } - EtaRegionOfCombCandidates& operator[](int i) { return m_regions_of_comb_candidates[i]; } + EtaRegionOfCombCandidates& operator[](int i) { return m_regions_of_comb_candidates[i]; } + const EtaRegionOfCombCandidates& operator[](int i) const { return m_regions_of_comb_candidates[i]; } }; diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index 249693890cb11..caed19afbc3f7 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -177,7 +177,10 @@ MkBuilder::MkBuilder() : &LayerInfo::m_next_ecap_neg, &MkFitter::PropagateTracksToZ, &MkFitter::SelectHitIndicesEndcap, - &MkFitter::AddBestHitEndcap + &MkFitter::AddBestHitEndcap, + &MkFitter::UpdateWithLastHitEndcap, + &MkFitter::FindCandidatesEndcap, + &MkFitter::FindCandidatesMinimizeCopyEndcap }; //m_steering_params[TrackerInfo::Reg_Transition_Neg] = { }; @@ -189,7 +192,10 @@ MkBuilder::MkBuilder() : &LayerInfo::m_next_barrel, &MkFitter::PropagateTracksToR, &MkFitter::SelectHitIndices, - &MkFitter::AddBestHit + &MkFitter::AddBestHit, + &MkFitter::UpdateWithLastHit, + &MkFitter::FindCandidates, + &MkFitter::FindCandidatesMinimizeCopy }; //m_steering_params[TrackerInfo::Reg_Transition_Pos] = { }; @@ -201,7 +207,10 @@ MkBuilder::MkBuilder() : &LayerInfo::m_next_ecap_pos, &MkFitter::PropagateTracksToZ, &MkFitter::SelectHitIndicesEndcap, - &MkFitter::AddBestHitEndcap + &MkFitter::AddBestHitEndcap, + &MkFitter::UpdateWithLastHitEndcap, + &MkFitter::FindCandidatesEndcap, + &MkFitter::FindCandidatesMinimizeCopyEndcap }; // XXMT4D Changing this order might @@ -502,7 +511,7 @@ void MkBuilder::fit_seeds() RegionOfSeedIndices rosi(m_event, reg); tbb::parallel_for(rosi.tbb_blk_rng(), - [&](const tbb::blocked_range& blk_rng) + [&](const tbb::blocked_range& blk_rng) { // printf("TBB seeding krappe -- range = %d to %d - extent = %d ==> %d to %d - extent %d\n", // i.begin(), i.end(), i.end() - i.begin(), beg, std::min(end,theEnd), std::min(end,theEnd) - beg); @@ -962,7 +971,7 @@ void MkBuilder::FindTracksBestHit() TrackVec &cands = m_event->candidateTracks_; tbb::parallel_for_each(m_brl_ecp_regions.begin(), m_brl_ecp_regions.end(), - [&](int reg) + [&](int reg) { // XXXXXX endcap only ... // if (reg != TrackerInfo::Reg_Endcap_Neg && reg != TrackerInfo::Reg_Endcap_Pos) @@ -970,80 +979,79 @@ void MkBuilder::FindTracksBestHit() const SteeringParams &st_par = m_steering_params[reg]; - RegionOfSeedIndices rosi(m_event, reg); + const RegionOfSeedIndices rosi(m_event, reg); tbb::parallel_for(rosi.tbb_blk_rng(), [&](const tbb::blocked_range& blk_rng) - { - TrackerInfo &trk_info = Config::TrkInfo; - std::unique_ptr mkfp(g_exe_ctx.m_fitters.GetFromPool(), retfitr); + { + std::unique_ptr mkfp(g_exe_ctx.m_fitters.GetFromPool(), retfitr); - int first_layer = st_par.first_finding_layer; + const TrackerInfo &trk_info = Config::TrkInfo; - RangeOfSeedIndices rng = rosi.seed_rng(blk_rng); + RangeOfSeedIndices rng = rosi.seed_rng(blk_rng); - while (rng.valid()) - { - dprint(std::endl << "processing track=" << rng.m_beg << ", label=" <getXHitEnd(0, 0, 0)-mkfp->getXHitBegin(0, 0, 0) << std::endl; // #endif - // make candidates with best hit - dprint("make new candidates"); + // make candidates with best hit + dprint("make new candidates"); - (mkfp.get()->*st_par.add_best_hit_foo)(layer_of_hits, rng.n_proc()); + (mkfp.get()->*st_par.add_best_hit_foo)(layer_of_hits, rng.n_proc()); - mkfp->SetNhits(++n_hits); + mkfp->SetNhits(++n_hits); - int next_layer = layer_info.*st_par.next_layer_doo; + int next_layer = layer_info.*st_par.next_layer_doo; - // propagate to layer - if ( ! layer_info.m_is_outer) - { - dcall(pre_prop_print(next_layer, mkfp.get())); + // propagate to layer + if ( ! layer_info.m_is_outer) + { + dcall(pre_prop_print(next_layer, mkfp.get())); - (mkfp.get()->*st_par.propagate_foo)(trk_info.m_layers[next_layer].*st_par.prop_to_pos_doo, rng.n_proc()); + (mkfp.get()->*st_par.propagate_foo)(trk_info.m_layers[next_layer].*st_par.prop_to_pos_doo, rng.n_proc()); - dcall(post_prop_print(next_layer, mkfp.get())); - } - else - { - break; - } + dcall(post_prop_print(next_layer, mkfp.get())); + } + else + { + break; + } - ilay = next_layer; - } // end of layer loop + ilay = next_layer; + } // end of layer loop - mkfp->OutputFittedTracksAndHitIdx(cands, rng.m_beg, rng.m_end, true); + mkfp->OutputFittedTracksAndHitIdx(cands, rng.m_beg, rng.m_end, true); - ++rng; - } // end of loop over candidates in a tbb chunk - }); // end parallel loop over candidates in a region - }); // end of loop over regions + ++rng; + } // end of loop over candidates in a tbb chunk + }); // end parallel_for over candidates in a region + }); // end of parallel_for_each over regions } //------------------------------------------------------------------------------ @@ -1056,7 +1064,7 @@ void MkBuilder::find_tracks_load_seeds() for (int r = TrackerInfo::Reg_Endcap_Neg; r < TrackerInfo::Reg_Count; ++r) { - RegionOfSeedIndices rosi(m_event, r); + const RegionOfSeedIndices rosi(m_event, r); eoccs.m_regions_of_comb_candidates[r].Reset(rosi.count()); @@ -1076,8 +1084,6 @@ void MkBuilder::find_tracks_load_seeds() void MkBuilder::FindTracksStandard() { - debug=true; - g_exe_ctx.populate(Config::numThreadsFinder); EventOfCombCandidates &eoccs = m_event_tmp->m_event_of_comb_cands; @@ -1085,6 +1091,8 @@ void MkBuilder::FindTracksStandard() tbb::parallel_for_each(eoccs.begin(), eoccs.end(), [&](EtaRegionOfCombCandidates& comb_cands) { + const SteeringParams &st_par = m_steering_params[comb_cands.m_region]; + int adaptiveSPT = TrackerInfo::Reg_Count * comb_cands.m_size / Config::numThreadsFinder / 2 + 1; dprint("adaptiveSPT " << adaptiveSPT << " fill " << comb_cands.m_size); @@ -1093,20 +1101,24 @@ void MkBuilder::FindTracksStandard() tbb::parallel_for(tbb::blocked_range(0, comb_cands.m_size, std::min(Config::numSeedsPerTask, adaptiveSPT)), [&](const tbb::blocked_range& seeds) { - TrackerInfo &trk_info = Config::TrkInfo; + std::unique_ptr mkfp(g_exe_ctx.m_fitters.GetFromPool(), retfitr); + + const TrackerInfo &trk_info = Config::TrkInfo; const int start_seed = seeds.begin(); const int end_seed = seeds.end(); const int nseeds = end_seed - start_seed; // Loop over layers, starting from after the seed. + int n_hits = Config::nlayers_per_seed; bool is_first_layer = true; - for (int ilay = trk_info.m_barrel[ Config::nlayers_per_seed ]; ; ) + + for (int ilay = st_par.first_finding_layer; ; ) { dprint("processing lay=" << ilay); - LayerOfHits &layer_of_hits = m_event_of_hits.m_layers_of_hits[ilay]; - LayerInfo &layer_info = trk_info.m_layers[ilay]; + const LayerOfHits &layer_of_hits = m_event_of_hits.m_layers_of_hits[ilay]; + const LayerInfo &layer_info = trk_info.m_layers[ilay]; // prepare unrolled vector to loop over std::vector > seed_cand_idx; @@ -1140,13 +1152,11 @@ void MkBuilder::FindTracksStandard() for (int itrack = 0; itrack < theEndCand; itrack += NN) { int end = std::min(itrack + NN, theEndCand); - + dprint("processing track=" << itrack); - - std::unique_ptr mkfp (g_exe_ctx.m_fitters.GetFromPool(), retfitr); - - mkfp->SetNhits(ilay);//here again assuming one hit per layer - + + mkfp->SetNhits(n_hits); //here again assuming one hit per layer + //fixme find a way to deal only with the candidates needed in this thread mkfp->InputTracksAndHitIdx(comb_cands.m_candidates, seed_cand_idx, itrack, end, @@ -1156,23 +1166,26 @@ void MkBuilder::FindTracksStandard() if ( ! is_first_layer) { dcall(pre_prop_print(ilay, mkfp.get())); - mkfp->PropagateTracksToR(layer_info.m_rin, end - itrack); + + (mkfp.get()->*st_par.propagate_foo)(layer_info.*st_par.prop_to_pos_doo, end - itrack); + dcall(post_prop_print(ilay, mkfp.get())); } dprint("now get hit range"); - mkfp->SelectHitIndices(layer_of_hits, end - itrack); + (mkfp.get()->*st_par.select_hits_foo)(layer_of_hits, end - itrack, false); //#ifdef PRINTOUTS_FOR_PLOTS //std::cout << "MX number of hits in window in layer " << ilay << " is " << mkfp->getXHitEnd(0, 0, 0)-mkfp->getXHitBegin(0, 0, 0) << std::endl; //#endif dprint("make new candidates"); - mkfp->FindCandidates(layer_of_hits, tmp_cands, start_seed, end - itrack); + (mkfp.get()->*st_par.find_cands_foo)(layer_of_hits, tmp_cands, start_seed, end - itrack); + } //end of vectorized loop - // clean exceeding candidates per seed - // FIXME: is there a reason why these are not vectorized???? + // clean exceeding candidates per seed + // FIXME: is there a reason why these are not vectorized???? for (int is = 0; is < tmp_cands.size(); ++is) { dprint("dump seed n " << is << " with input candidates=" << tmp_cands[is].size()); @@ -1219,8 +1232,9 @@ void MkBuilder::FindTracksStandard() break; } + ++n_hits; is_first_layer = false; - ilay = layer_info.m_next_barrel; + ilay = layer_info.*st_par.next_layer_doo; } // end of layer loop // final sorting @@ -1241,57 +1255,57 @@ void MkBuilder::FindTracksStandard() void MkBuilder::FindTracksCloneEngine() { g_exe_ctx.populate(Config::numThreadsFinder); - EventOfCombCandidates &event_of_comb_cands = m_event_tmp->m_event_of_comb_cands; - tbb::parallel_for(tbb::blocked_range(0, TrackerInfo::Reg_Count), - [&](const tbb::blocked_range& ebins) - { - for (int ebin = ebins.begin(); ebin != ebins.end(); ++ebin) - { - EtaRegionOfCombCandidates& comb_candidates = event_of_comb_cands.m_regions_of_comb_candidates[ebin]; + EventOfCombCandidates &eoccs = m_event_tmp->m_event_of_comb_cands; - int adaptiveSPT = Config::nEtaBin * comb_candidates.m_size/Config::numThreadsFinder/2 + 1; + tbb::parallel_for_each(eoccs.begin(), eoccs.end(), + [&](EtaRegionOfCombCandidates& comb_cands) + { + int adaptiveSPT = TrackerInfo::Reg_Count * comb_cands.m_size / Config::numThreadsFinder / 2 + 1; - dprint("adaptiveSPT " << adaptiveSPT << " fill " << comb_candidates.m_size); + dprint("adaptiveSPT " << adaptiveSPT << " fill " << comb_cands.m_size); - tbb::parallel_for(tbb::blocked_range(0, comb_candidates.m_size, std::min(Config::numSeedsPerTask, adaptiveSPT)), - [&](const tbb::blocked_range& seeds) - { - std::unique_ptr cloner(g_exe_ctx.m_cloners.GetFromPool(), retcand); - std::unique_ptr mkfp (g_exe_ctx.m_fitters.GetFromPool(), retfitr); + tbb::parallel_for(tbb::blocked_range(0, comb_cands.m_size, std::min(Config::numSeedsPerTask, adaptiveSPT)), + [&](const tbb::blocked_range& seeds) + { + std::unique_ptr cloner(g_exe_ctx.m_cloners.GetFromPool(), retcand); + std::unique_ptr mkfp (g_exe_ctx.m_fitters.GetFromPool(), retfitr); - // loop over layers - find_tracks_in_layers(comb_candidates, *cloner, mkfp.get(), seeds.begin(), seeds.end(), ebin); - }); - } + // loop over layers + find_tracks_in_layers(comb_cands, *cloner, mkfp.get(), seeds.begin(), seeds.end(), comb_cands.m_region); + }); }); } -void MkBuilder::find_tracks_in_layers(EtaRegionOfCombCandidates &comb_candidates, CandCloner &cloner, - MkFitter *mkfp, int start_seed, int end_seed, int ebin) +void MkBuilder::find_tracks_in_layers(EtaRegionOfCombCandidates &comb_cands, CandCloner &cloner, + MkFitter *mkfp, int start_seed, int end_seed, int region) { - TrackerInfo &trk_info = Config::TrkInfo; + const SteeringParams &st_par = m_steering_params[region]; + const TrackerInfo &trk_info = Config::TrkInfo; + const int n_seeds = end_seed - start_seed; std::vector> seed_cand_idx; seed_cand_idx.reserve(n_seeds * Config::maxCandsPerSeed); - cloner.begin_eta_bin(&comb_candidates, start_seed, n_seeds); + cloner.begin_eta_bin(&comb_cands, start_seed, n_seeds); // Loop over layers, starting from after the seed. // Note that we do a final pass with ilay = -1 to update parameters // and output final tracks. prev_ilay == -1 serves as is_first_layer. int prev_ilay = -1; - for (int ilay = trk_info.m_barrel[ Config::nlayers_per_seed ]; ; ) + int n_hits = Config::nlayers_per_seed; + + for (int ilay = st_par.first_finding_layer; ; ) { dprint("processing lay=" << ilay); - LayerInfo &layer_info = trk_info.m_layers[ilay]; + const LayerInfo &layer_info = trk_info.m_layers[ilay]; //prepare unrolled vector to loop over for (int iseed = start_seed; iseed != end_seed; ++iseed) { - std::vector &scands = comb_candidates.m_candidates[iseed]; + std::vector &scands = comb_cands.m_candidates[iseed]; for (int ic = 0; ic < scands.size(); ++ic) { if (scands[ic].getLastHitIdx() >= -1) @@ -1328,11 +1342,9 @@ void MkBuilder::find_tracks_in_layers(EtaRegionOfCombCandidates &comb_candidates dprintf("\n"); #endif - mkfp->SetNhits(ilay >= 0 ? ilay : prev_ilay + 1); // XXXXMT HAKAHAKA - // mkfp->SetNhits(ilay); // XXXXMT -- also elsewhere in building - // XXXXMT should realy be increase N - hits !!!! + mkfp->SetNhits(n_hits); - mkfp->InputTracksAndHitIdx(comb_candidates.m_candidates, + mkfp->InputTracksAndHitIdx(comb_cands.m_candidates, seed_cand_idx, itrack, end, true); @@ -1344,24 +1356,24 @@ void MkBuilder::find_tracks_in_layers(EtaRegionOfCombCandidates &comb_candidates if (prev_ilay >= 0) { - LayerOfHits &prev_layer_of_hits = m_event_of_hits.m_layers_of_hits[prev_ilay]; + const LayerOfHits &prev_layer_of_hits = m_event_of_hits.m_layers_of_hits[prev_ilay]; - mkfp->UpdateWithLastHit(prev_layer_of_hits, end - itrack); + (mkfp->*st_par.update_with_last_hit_foo)(prev_layer_of_hits, end - itrack); if (ilay >= 0) { // Propagate to this layer - mkfp->PropagateTracksToR(layer_info.m_rin, end - itrack); + (mkfp->*st_par.propagate_foo)(layer_info.*st_par.prop_to_pos_doo, end - itrack); // copy_out the propagated track params, errors only (hit-idcs and chi2 already updated) - mkfp->CopyOutParErr(comb_candidates.m_candidates, + mkfp->CopyOutParErr(comb_cands.m_candidates, end - itrack, true); } else { // copy_out the updated track params, errors only (hit-idcs and chi2 already updated) - mkfp->CopyOutParErr(comb_candidates.m_candidates, + mkfp->CopyOutParErr(comb_cands.m_candidates, end - itrack, false); continue; } @@ -1374,9 +1386,9 @@ void MkBuilder::find_tracks_in_layers(EtaRegionOfCombCandidates &comb_candidates dprint("now get hit range"); - LayerOfHits &layer_of_hits = m_event_of_hits.m_layers_of_hits[ilay]; + const LayerOfHits &layer_of_hits = m_event_of_hits.m_layers_of_hits[ilay]; - mkfp->SelectHitIndices(layer_of_hits, end - itrack); + (mkfp->*st_par.select_hits_foo)(layer_of_hits, end - itrack, false); //#ifdef PRINTOUTS_FOR_PLOTS //std::cout << "MX number of hits in window in layer " << ilay << " is " << mkfp->getXHitEnd(0, 0, 0)-mkfp->getXHitBegin(0, 0, 0) << std::endl; @@ -1385,7 +1397,7 @@ void MkBuilder::find_tracks_in_layers(EtaRegionOfCombCandidates &comb_candidates dprint("make new candidates"); cloner.begin_iteration(); - mkfp->FindCandidatesMinimizeCopy(layer_of_hits, cloner, start_seed, end - itrack); + (mkfp->*st_par.find_cands_min_copy_foo)(layer_of_hits, cloner, start_seed, end - itrack); cloner.end_iteration(); } //end of vectorized loop @@ -1400,8 +1412,9 @@ void MkBuilder::find_tracks_in_layers(EtaRegionOfCombCandidates &comb_candidates } seed_cand_idx.clear(); + ++n_hits; prev_ilay = ilay; - ilay = layer_info.m_next_barrel; + ilay = layer_info.*st_par.next_layer_doo; } // end of layer loop cloner.end_eta_bin(); @@ -1409,7 +1422,7 @@ void MkBuilder::find_tracks_in_layers(EtaRegionOfCombCandidates &comb_candidates // final sorting for (int iseed = start_seed; iseed < end_seed; ++iseed) { - std::vector& finalcands = comb_candidates.m_candidates[iseed]; + std::vector& finalcands = comb_cands.m_candidates[iseed]; if (finalcands.size() == 0) continue; std::sort(finalcands.begin(), finalcands.end(), sortCandByHitsChi2); } diff --git a/mkFit/MkBuilder.h b/mkFit/MkBuilder.h index f52128d6de02f..0e6ccc19c4e73 100644 --- a/mkFit/MkBuilder.h +++ b/mkFit/MkBuilder.h @@ -97,7 +97,7 @@ class MkBuilder void find_tracks_load_seeds(); void find_tracks_in_layers(EtaRegionOfCombCandidates &comb_candidates, CandCloner &cloner, MkFitter *mkfp, - int start_seed, int end_seed, int ebin); + int start_seed, int end_seed, int region); // -------- diff --git a/mkFit/MkFitter.cc b/mkFit/MkFitter.cc index fb424245710e9..e8b9c4183c7ad 100644 --- a/mkFit/MkFitter.cc +++ b/mkFit/MkFitter.cc @@ -1032,7 +1032,7 @@ void MkFitter::AddBestHit(const LayerOfHits &layer_of_hits, const int N_proc) void MkFitter::FindCandidates(const LayerOfHits &layer_of_hits, - std::vector >& tmp_candidates, + std::vector>& tmp_candidates, const int offset, const int N_proc) { const char *varr = (char*) layer_of_hits.m_hits; @@ -1196,7 +1196,7 @@ void MkFitter::FindCandidates(const LayerOfHits &layer_of_hits, } void MkFitter::FindCandidatesEndcap(const LayerOfHits &layer_of_hits, - std::vector >& tmp_candidates, + std::vector>& tmp_candidates, const int offset, const int N_proc) { const char *varr = (char*) layer_of_hits.m_hits; @@ -1343,7 +1343,8 @@ void MkFitter::FindCandidatesEndcap(const LayerOfHits &layer_of_hits, { int hit_idx = countInvalidHits(itrack) < Config::maxHolesPerCand ? -1 : -2; - // XXXXMT4K Grrrr ... this is cmssw specific, sigh + // XXXXMT4CMS Grrrr ... this is cmssw specific, sigh + /* bool withinBounds = true; float r2 = Par[iP](itrack,0,0)*Par[iP](itrack,0,0)+Par[iP](itrack,1,0)*Par[iP](itrack,1,0); if ( r2<(Config::cmsDiskMinRs[Nhits]*Config::cmsDiskMinRs[Nhits]) || @@ -1352,6 +1353,7 @@ void MkFitter::FindCandidatesEndcap(const LayerOfHits &layer_of_hits, r2<(Config::cmsDiskMaxRsHole[Nhits]*Config::cmsDiskMaxRsHole[Nhits]) ) withinBounds = false; //-3 means we did not expect any hit since we are out of bounds, so it does not count in countInvalidHits if (withinBounds==false) hit_idx = -3; + */ Track newcand; newcand.resetHits();//probably not needed @@ -1947,11 +1949,13 @@ void MkFitter::AddBestHitEndcap(const LayerOfHits &layer_of_hits, const int N_pr bool withinBounds = true; float r2 = Par[iP](itrack,0,0)*Par[iP](itrack,0,0)+Par[iP](itrack,1,0)*Par[iP](itrack,1,0); - // XXXXMT4G - // if ( r2<(Config::cmsDiskMinRs[Nhits]*Config::cmsDiskMinRs[Nhits]) || - // r2>(Config::cmsDiskMaxRs[Nhits]*Config::cmsDiskMaxRs[Nhits]) || - // r2>(Config::cmsDiskMinRsHole[Nhits]*Config::cmsDiskMinRsHole[Nhits]) || - // r2<(Config::cmsDiskMaxRsHole[Nhits]*Config::cmsDiskMaxRsHole[Nhits]) ) withinBounds = false; + // XXXXMT4CMS Grrrr ... this is cmssw specific, sigh + /* + if ( r2<(Config::cmsDiskMinRs[Nhits]*Config::cmsDiskMinRs[Nhits]) || + r2>(Config::cmsDiskMaxRs[Nhits]*Config::cmsDiskMaxRs[Nhits]) || + r2>(Config::cmsDiskMinRsHole[Nhits]*Config::cmsDiskMinRsHole[Nhits]) || + r2<(Config::cmsDiskMaxRsHole[Nhits]*Config::cmsDiskMaxRsHole[Nhits]) ) withinBounds = false; + */ #ifdef DEBUG r2= std::sqrt(r2); @@ -2101,12 +2105,15 @@ void MkFitter::FindCandidatesMinimizeCopyEndcap(const LayerOfHits &layer_of_hits bool withinBounds = true; float r2 = Par[iP](itrack,0,0)*Par[iP](itrack,0,0)+Par[iP](itrack,1,0)*Par[iP](itrack,1,0); + // XXXXMT4CMS Grrrr ... this is cmssw specific, sigh + /* if ( r2<(Config::cmsDiskMinRs[Nhits]*Config::cmsDiskMinRs[Nhits]) || r2>(Config::cmsDiskMaxRs[Nhits]*Config::cmsDiskMaxRs[Nhits]) || r2>(Config::cmsDiskMinRsHole[Nhits]*Config::cmsDiskMinRsHole[Nhits]) || r2<(Config::cmsDiskMaxRsHole[Nhits]*Config::cmsDiskMaxRsHole[Nhits]) ) withinBounds = false; //-3 means we did not expect any hit since we are out of bounds, so it does not count in countInvalidHits if (withinBounds==false) hit_idx = -3; + */ IdxChi2List tmpList; tmpList.trkIdx = CandIdx(itrack, 0, 0); diff --git a/mkFit/MkFitter.h b/mkFit/MkFitter.h index d5e60feb56507..e7308380314f0 100644 --- a/mkFit/MkFitter.h +++ b/mkFit/MkFitter.h @@ -116,9 +116,9 @@ struct MkFitter void AddBestHit (const LayerOfHits &layer_of_hits, const int N_proc); void AddBestHitEndcap(const LayerOfHits &layer_of_hits, const int N_proc); - void FindCandidates(const LayerOfHits &layer_of_hits, std::vector >& tmp_candidates, + void FindCandidates(const LayerOfHits &layer_of_hits, std::vector>& tmp_candidates, const int offset, const int N_proc); - void FindCandidatesEndcap(const LayerOfHits &layer_of_hits, std::vector >& tmp_candidates, + void FindCandidatesEndcap(const LayerOfHits &layer_of_hits, std::vector>& tmp_candidates, const int offset, const int N_proc); // ================================================================ // Methods used with clone engine diff --git a/mkFit/SteeringParams.h b/mkFit/SteeringParams.h index 379cc2dc2cbc8..f63aa1e86f4db 100644 --- a/mkFit/SteeringParams.h +++ b/mkFit/SteeringParams.h @@ -3,6 +3,7 @@ class LayerInfo; class MkFitter; +class CandCloner; struct SteeringParams { @@ -12,6 +13,9 @@ struct SteeringParams void (MkFitter::*propagate_foo) (float, const int); void (MkFitter::*select_hits_foo) (const LayerOfHits &, const int, bool); void (MkFitter::*add_best_hit_foo)(const LayerOfHits &, const int); + void (MkFitter::*update_with_last_hit_foo)(const LayerOfHits &, const int); + void (MkFitter::*find_cands_foo)(const LayerOfHits &, std::vector> &, const int, const int); + void (MkFitter::*find_cands_min_copy_foo)(const LayerOfHits &, CandCloner &, const int, const int); SteeringParams() {} @@ -20,13 +24,19 @@ struct SteeringParams int LayerInfo::*nl_d, void (MkFitter::*p_f) (float, const int), void (MkFitter::*sh_f) (const LayerOfHits &, const int, bool), - void (MkFitter::*abh_f)(const LayerOfHits &, const int)) : + void (MkFitter::*abh_f)(const LayerOfHits &, const int), + void (MkFitter::*uwlh_f)(const LayerOfHits &, const int), + void (MkFitter::*fc_f)(const LayerOfHits &, std::vector> &, const int, const int), + void (MkFitter::*fcmc_f)(const LayerOfHits &, CandCloner &, const int, const int)) : first_finding_layer(ffl), prop_to_pos_doo(ptp_d), next_layer_doo(nl_d), propagate_foo(p_f), select_hits_foo(sh_f), - add_best_hit_foo(abh_f) + add_best_hit_foo(abh_f), + update_with_last_hit_foo(uwlh_f), + find_cands_foo(fc_f), + find_cands_min_copy_foo(fcmc_f) {} }; From e7ad370f26e4fb22c020e3ec031b2a3e148d34e9 Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Tue, 4 Apr 2017 23:19:25 -0700 Subject: [PATCH 011/172] Update MkBuilder::remap_seed_hits() and MkBuilder::remap_cand_hits() for the new hit/layer representation. --- Event.h | 2 + mkFit/MkBuilder.cc | 99 ++++++++++++++++++++++------------------------ 2 files changed, 49 insertions(+), 52 deletions(-) diff --git a/Event.h b/Event.h index aedab14244a92..8e88c426b81de 100644 --- a/Event.h +++ b/Event.h @@ -9,6 +9,8 @@ #include +// XXMT4K XXMT4D Is HitID and Event::layerHitMap_ still needed? + struct HitID { HitID() : layer(-1), index(-1) {} HitID(int l, int i) : layer(l), index(i) {} diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index caed19afbc3f7..f7caf74fe9372 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -681,24 +681,6 @@ void MkBuilder::map_seed_hits() } } } - // XXXXMT4K: Old code ... - /* - for (int ilayer = 0; ilayer < max_layer; ++ilayer) - { - const auto & global_hit_vec = m_event->layerHits_[ilayer]; - const auto size = m_event->layerHits_[ilayer].size(); - for (auto&& track : m_event->seedTracks_) { - auto hitidx = track.getHitIdx(ilayer); - if ((hitidx >= 0) && (hitidx < size)) - { - // XXMT4K ilayer -> something else. Even better, change loop order. - // Seed tracks only have seed hits, so iterate over them. - - track.setHitIdxLyr(ilayer, seedLayersHitMap[global_hit_vec[hitidx].mcHitID()].index, ilayer); - } - } - } - */ } void MkBuilder::remap_seed_hits() @@ -707,25 +689,33 @@ void MkBuilder::remap_seed_hits() // m_event_of_hits.m_layers_of_hits[i].m_hits to global // m_event->layerHits_[i] - // XXXXMT4K as above - HitIDVec seedLayersHitMap(m_event->simHitsInfo_.size()); - for (int ilayer = 0; ilayer < Config::nlayers_per_seed; ++ilayer) { + + // XXMT4K: This was: Config::nlayers_per_seed, now not that simple. + // In principle could have a list of seed layers (from outside (seed maker) or TrackerInfo). + int max_layer = Config::nTotalLayers; + + for (int ilayer = 0; max_layer < Config::nlayers_per_seed; ++ilayer) + { const auto & global_hit_vec = m_event->layerHits_[ilayer]; const auto size = global_hit_vec.size(); - for (int index = 0; index < size; ++index) { + for (int index = 0; index < size; ++index) + { seedLayersHitMap[global_hit_vec[index].mcHitID()] = HitID(ilayer, index); } } - for (int ilayer = 0; ilayer < Config::nlayers_per_seed; ++ilayer) { - const auto & lof_m_hits = m_event_of_hits.m_layers_of_hits[ilayer].m_hits; - const auto size = m_event->layerHits_[ilayer].size(); - for (auto&& track : m_event->seedTracks_) { - auto hitidx = track.getHitIdx(ilayer); - if ((hitidx>=0) && (hitidx something else .... - track.setHitIdxLyr(ilayer, seedLayersHitMap[lof_m_hits[hitidx].mcHitID()].index, ilayer); + + for (auto&& track : m_event->seedTracks_) + { + for (int i = 0; i < track.nTotalHits(); ++i) + { + int hitidx = track.getHitIdx(i); + int hitlyr = track.getHitLyr(i); + if (hitidx >= 0) + { + const auto & lof_m_hits = m_event_of_hits.m_layers_of_hits[hitlyr].m_hits; + + track.setHitIdx(i, seedLayersHitMap[lof_m_hits[hitidx].mcHitID()].index); } } } @@ -737,24 +727,31 @@ void MkBuilder::remap_cand_hits() // m_event_of_hits.m_layers_of_hits[i].m_hits to global // m_event->layerHits_[i] - // XXXXMT4K as above - HitIDVec candLayersHitMap(m_event->simHitsInfo_.size()); - for (int ilayer = 0; ilayer < Config::nLayers; ++ilayer) { + + int max_layer = Config::nTotalLayers; + + for (int ilayer = 0; ilayer < max_layer; ++ilayer) + { const auto & global_hit_vec = m_event->layerHits_[ilayer]; - for (int index = 0; index < global_hit_vec.size(); ++index) { + const auto size = global_hit_vec.size(); + for (int index = 0; index < size; ++index) + { candLayersHitMap[global_hit_vec[index].mcHitID()] = HitID(ilayer, index); } } - for (int ilayer = 0; ilayer < Config::nLayers; ++ilayer) { - const auto & lof_m_hits = m_event_of_hits.m_layers_of_hits[ilayer].m_hits; - const auto size = m_event->layerHits_[ilayer].size(); - for (auto&& track : m_event->candidateTracks_) { - auto hitidx = track.getHitIdx(ilayer); - if ((hitidx>=0) && (hitidx something else .... - track.setHitIdxLyr(ilayer, candLayersHitMap[lof_m_hits[hitidx].mcHitID()].index, ilayer); + + for (auto&& track : m_event->candidateTracks_) + { + for (int i = 0; i < track.nTotalHits(); ++i) + { + int hitidx = track.getHitIdx(i); + int hitlyr = track.getHitLyr(i); + if (hitidx >= 0) + { + const auto & lof_m_hits = m_event_of_hits.m_layers_of_hits[hitlyr].m_hits; + + track.setHitIdx(i, candLayersHitMap[lof_m_hits[hitidx].mcHitID()].index); } } } @@ -762,6 +759,8 @@ void MkBuilder::remap_cand_hits() void MkBuilder::align_simtracks() { + // XXXXMT : Does this change with the new format? + if (Config::readCmsswSeeds && Config::endcapTest) { for (int itrack = 0; itrack < m_event->simTracks_.size(); itrack++) @@ -779,11 +778,9 @@ void MkBuilder::quality_output_BH() { quality_reset(); - // XXXXMT4K - - // remap_cand_hits(); + remap_cand_hits(); - // align_simtracks(); + align_simtracks(); for (int i = 0; i < m_event->candidateTracks_.size(); i++) { @@ -799,11 +796,9 @@ void MkBuilder::quality_output_COMB() quality_store_tracks_COMB(); - // XXXXMT4K - - // remap_cand_hits(); + remap_cand_hits(); - // align_simtracks(); + align_simtracks(); for (int i = 0; i < m_event->candidateTracks_.size(); i++) { From e3fa2f08899aa3ae4e6a404dc07fb45c618d7dd4 Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Wed, 5 Apr 2017 10:04:59 -0700 Subject: [PATCH 012/172] Cut-n-paste error in loop conditon. --- Event.cc | 7 ++++--- mkFit/MkBuilder.cc | 2 +- mkFit/mt-notes.txt | 31 +++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/Event.cc b/Event.cc index 8426fbef5412e..f548495e5fa1d 100644 --- a/Event.cc +++ b/Event.cc @@ -37,7 +37,8 @@ inline bool sortByZ(const Hit& hit1, const Hit& hit2){ } #endif -void Event::resetLayerHitMap(bool resetSimHits) { +void Event::resetLayerHitMap(bool resetSimHits) +{ //gc: not sure what is being done here layerHitMap_.clear(); layerHitMap_.resize(simHitsInfo_.size()); @@ -49,11 +50,11 @@ void Event::resetLayerHitMap(bool resetSimHits) { layerHitMap_[hit.mcHitID()] = HitID(ilayer, index); } } - // XXXMT4K is this still necessary? Or maybe I scrwed up by doing the mapping below ... + // XXXMT4K is this still necessary? Or maybe I screwed up by doing the mapping below ... if (resetSimHits) { for (auto&& track : simTracks_) { for (int il = 0; il < track.nTotalHits(); ++il) { - HitID &hid = layerHitMap_[track.getHitIdx(il)]; + HitID &hid = layerHitMap_[track.getHitIdx(il)]; // XXXXMT4k This looks wrong assert(hid.index >= 0); // tmp debug track.setHitIdxLyr(il, hid.index, hid.layer); } diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index f7caf74fe9372..9a9f12c81f341 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -695,7 +695,7 @@ void MkBuilder::remap_seed_hits() // In principle could have a list of seed layers (from outside (seed maker) or TrackerInfo). int max_layer = Config::nTotalLayers; - for (int ilayer = 0; max_layer < Config::nlayers_per_seed; ++ilayer) + for (int ilayer = 0; ilayer < max_layer; ++ilayer) { const auto & global_hit_vec = m_event->layerHits_[ilayer]; const auto size = global_hit_vec.size(); diff --git a/mkFit/mt-notes.txt b/mkFit/mt-notes.txt index 4307ec492f9e6..4e9a70ba202a7 100644 --- a/mkFit/mt-notes.txt +++ b/mkFit/mt-notes.txt @@ -2,6 +2,37 @@ Notes for Kevin ######### +// Dump sim tracks + hits + for (auto & t : m_event->simTracks_) + { + printf("%2d (%2d): ", t.label(), t.nFoundHits()); + + for (int i = 0; i < t.nFoundHits(); ++i) + { + int idx = t.getHitIdx(i); + int lyr = t.getHitLyr(i); + + printf("%4d", idx >= 0 ? m_event->layerHits_[lyr][idx].mcHitID() : -1); + } + printf("\n"); + } + +// Dump cands + hits (would need to build map label to index to +// get it properly sorted) + for (auto & t : m_event->candidateTracks_) + { + printf("%2d (%2d): ", t.label(), t.nFoundHits()); + + for (int i = 0; i < t.nFoundHits(); ++i) + { + int idx = t.getHitIdx(i); + int lyr = t.getHitLyr(i); + + printf("%4d", idx >= 0 ? m_event->layerHits_[lyr][idx].mcHitID() : -1); + } + printf("\n"); + } + In general, search for XXMT4K. Thing that is probably most urgent is Validation + some issues with Simulation From 7b7fea17a7c86ab1739c67ba51515eb5940db215 Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Thu, 6 Apr 2017 22:51:03 -0700 Subject: [PATCH 013/172] Code cleanup. * Reduce pair Event/EtaRegionOfCombCandidates to EventOfCombinedCandidates. * Modify MkBuilder according to the above. * Remove EventTmp - move EventOfCombCandidates into MkBuilder. * Remove MkBuilderEndcap * Somewhat rework the loops in MkBuilder::FindTracksStd/CloneEngine. I couldn't go as far as I thought as there is the outer loop over layers there and there is the implied start_index that is passed into MkFitter so changing it further requires synchronized change there. --- mkFit/CandCloner.cc | 2 +- mkFit/CandCloner.h | 6 +- mkFit/EventTmp.h | 17 -- mkFit/HitStructures.h | 36 +-- mkFit/MkBuilder.cc | 143 +++++----- mkFit/MkBuilder.h | 12 +- mkFit/MkBuilderEndcap.cc | 573 --------------------------------------- mkFit/MkBuilderEndcap.h | 31 --- mkFit/buildtestMPlex.cc | 10 +- mkFit/buildtestMPlex.h | 5 +- mkFit/mkFit.cc | 6 +- 11 files changed, 91 insertions(+), 750 deletions(-) delete mode 100644 mkFit/EventTmp.h delete mode 100644 mkFit/MkBuilderEndcap.cc delete mode 100644 mkFit/MkBuilderEndcap.h diff --git a/mkFit/CandCloner.cc b/mkFit/CandCloner.cc index 9c15eb4b1018a..a7b7ed93e79c7 100644 --- a/mkFit/CandCloner.cc +++ b/mkFit/CandCloner.cc @@ -25,7 +25,7 @@ void CandCloner::ProcessSeedRange(int is_beg, int is_end) { std::vector& hitsForSeed = m_hits_to_add[is]; - std::vector> &cands = mp_region_of_comb_candidates->m_candidates; + std::vector> &cands = mp_event_of_comb_candidates->m_candidates; #ifdef DEBUG int th_start_seed = m_start_seed; diff --git a/mkFit/CandCloner.h b/mkFit/CandCloner.h index bd49158fe97e7..929cf2db54a74 100644 --- a/mkFit/CandCloner.h +++ b/mkFit/CandCloner.h @@ -38,9 +38,9 @@ class CandCloner { } - void begin_eta_bin(EtaRegionOfCombCandidates * er_o_ccs, int start_seed, int n_seeds) + void begin_eta_bin(EventOfCombCandidates * e_o_ccs, int start_seed, int n_seeds) { - mp_region_of_comb_candidates = er_o_ccs; + mp_event_of_comb_candidates = e_o_ccs; m_start_seed = start_seed; m_n_seeds = n_seeds; m_hits_to_add.resize(n_seeds); @@ -161,7 +161,7 @@ class CandCloner int m_idx_max, m_idx_max_prev; std::vector> m_hits_to_add; - EtaRegionOfCombCandidates *mp_region_of_comb_candidates; + EventOfCombCandidates *mp_event_of_comb_candidates; #if defined(CC_TIME_ETA) or defined(CC_TIME_LAYER) double t_eta, t_lay; diff --git a/mkFit/EventTmp.h b/mkFit/EventTmp.h deleted file mode 100644 index 7059e0432f11b..0000000000000 --- a/mkFit/EventTmp.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef _eventtmp_h_ - -#include "HitStructures.h" - -class EventTmp -{ -public: - EventOfCombCandidates m_event_of_comb_cands; - - // XXXX Should also add EventOfCandidates? - // XXXX Should we go for delayed initialization/resizing then? - - EventTmp() {} - ~EventTmp() {} -}; - -#endif diff --git a/mkFit/HitStructures.h b/mkFit/HitStructures.h index 471ecb3b25ca1..655b4bcf12a2e 100644 --- a/mkFit/HitStructures.h +++ b/mkFit/HitStructures.h @@ -267,21 +267,19 @@ class EventOfCandidates // for combinatorial version, switch to vector of vectors //------------------------------------------------------- -class EtaRegionOfCombCandidates +class EventOfCombCandidates { public: std::vector > m_candidates; int m_capacity; int m_size; - int m_region; public: - EtaRegionOfCombCandidates(int size=0) : + EventOfCombCandidates(int size=0) : m_candidates(), m_capacity (0), - m_size (0), - m_region (-1) + m_size (0) { Reset(size); } @@ -324,34 +322,6 @@ class EtaRegionOfCombCandidates m_candidates[seed_index].push_back(track); } - - /* void SortByPhi() */ - /* { */ - /* std::sort(m_candidates.begin(), m_candidates.begin() + m_size, sortTrksByPhiMT); */ - /* } */ -}; - -class EventOfCombCandidates -{ -public: - std::vector m_regions_of_comb_candidates; - -public: - EventOfCombCandidates() : - m_regions_of_comb_candidates(TrackerInfo::Reg_Count) - { - for (int i = TrackerInfo::Reg_Begin; i < TrackerInfo::Reg_End; ++i) - { - m_regions_of_comb_candidates[i].m_region = i; - } - } - - std::vector::iterator begin() { return m_regions_of_comb_candidates.begin(); } - std::vector::iterator end() { return m_regions_of_comb_candidates.end(); } - - EtaRegionOfCombCandidates& operator[](int i) { return m_regions_of_comb_candidates[i]; } - const EtaRegionOfCombCandidates& operator[](int i) const { return m_regions_of_comb_candidates[i]; } - }; #endif diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index 9a9f12c81f341..8b3740430e316 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -1,16 +1,14 @@ #include #include "MkBuilder.h" -#include "MkBuilderEndcap.h" #include "seedtestMPlex.h" #include "Event.h" -#include "EventTmp.h" #include "TrackerInfo.h" #include "MkFitter.h" -#define DEBUG +//#define DEBUG #include "Debug.h" #include "Ice/IceRevisitedRadix.h" @@ -35,6 +33,11 @@ namespace RangeOfSeedIndices(int rb, int re) : m_rng_beg(rb), m_rng_end(re) + { + reset(); + } + + void reset() { m_end = m_rng_beg; next_chunk(); @@ -67,7 +70,13 @@ namespace int count() const { return m_reg_end - m_reg_beg; } - tbb::blocked_range tbb_blk_rng() const + tbb::blocked_range tbb_blk_rng_std(int thr_hint=-1) const + { + if (thr_hint < 0) thr_hint = Config::numSeedsPerTask; + return tbb::blocked_range(m_reg_beg, m_reg_end, thr_hint); + } + + tbb::blocked_range tbb_blk_rng_vec() const { return tbb::blocked_range(0, m_vec_cnt, std::max(1, Config::numSeedsPerTask / NN)); } @@ -82,8 +91,7 @@ namespace MkBuilder* MkBuilder::make_builder() { - if (Config::endcapTest) return new MkBuilderEndcap; - else return new MkBuilder; + return new MkBuilder; } #ifdef DEBUG @@ -136,11 +144,9 @@ namespace { } void print_seeds(const EventOfCombCandidates& event_of_comb_cands) { - for (int ebin = 0; ebin < TrackerInfo::Reg_Count; ++ebin) { - const EtaRegionOfCombCandidates &etabin_of_comb_candidates = event_of_comb_cands[ebin]; - for (int iseed = 0; iseed < etabin_of_comb_candidates.m_size; iseed++) { - print_seed2(etabin_of_comb_candidates.m_candidates[iseed].front()); - } + for (int iseed = 0; iseed < event_of_comb_cands.m_size; iseed++) + { + print_seed2(event_of_comb_cands.m_candidates[iseed].front()); } } } @@ -164,8 +170,6 @@ namespace MkBuilder::MkBuilder() : m_event(0), - m_event_tmp(0), - // XXMT WAS m_event_of_hits(Config::nLayers) m_event_of_hits(Config::TrkInfo) { const TrackerInfo &ti = Config::TrkInfo; @@ -228,10 +232,9 @@ MkBuilder::~MkBuilder() // Common functions //------------------------------------------------------------------------------ -void MkBuilder::begin_event(Event* ev, EventTmp* ev_tmp, const char* build_type) +void MkBuilder::begin_event(Event* ev, const char* build_type) { m_event = ev; - m_event_tmp = ev_tmp; std::vector& simtracks = m_event->simTracks_; // DDDD MT: debug seed fit divergence between host / mic. @@ -510,7 +513,7 @@ void MkBuilder::fit_seeds() RegionOfSeedIndices rosi(m_event, reg); - tbb::parallel_for(rosi.tbb_blk_rng(), + tbb::parallel_for(rosi.tbb_blk_rng_vec(), [&](const tbb::blocked_range& blk_rng) { // printf("TBB seeding krappe -- range = %d to %d - extent = %d ==> %d to %d - extent %d\n", @@ -815,17 +818,14 @@ void MkBuilder::quality_reset() void MkBuilder::quality_store_tracks_COMB() { - for (int reg = 0; reg < TrackerInfo::Reg_Count; ++reg) - { - const EtaRegionOfCombCandidates &comb_candidates = m_event_tmp->m_event_of_comb_cands[reg]; + const EventOfCombCandidates &eoccs = m_event_of_comb_cands; - for (int i = 0; i < comb_candidates.m_size; i++) + for (int i = 0; i < eoccs.m_size; i++) + { + // take the first one! + if ( ! eoccs.m_candidates[i].empty()) { - // take the first one! - if ( ! comb_candidates.m_candidates[i].empty()) - { - m_event->candidateTracks_.push_back(comb_candidates.m_candidates[i].front()); - } + m_event->candidateTracks_.push_back(eoccs.m_candidates[i].front()); } } } @@ -871,9 +871,6 @@ void MkBuilder::quality_process(Track &tkcand) std::cout << "MX - found track with nFoundHits=" << tkcand.nFoundHits() << " chi2=" << tkcand.chi2() << " pT=" << pt <<" pTmc="<< ptmc << " nfoundmc=" << nfoundmc << " chi2mc=" << chi2mc <<" lab="<< tkcand.label() <candidateTracks_; tbb::parallel_for_each(m_brl_ecp_regions.begin(), m_brl_ecp_regions.end(), - [&](int reg) + [&](int region) { // XXXXXX endcap only ... - // if (reg != TrackerInfo::Reg_Endcap_Neg && reg != TrackerInfo::Reg_Endcap_Pos) + // if (region != TrackerInfo::Reg_Endcap_Neg && region != TrackerInfo::Reg_Endcap_Pos) // continue; - const SteeringParams &st_par = m_steering_params[reg]; + const SteeringParams &st_par = m_steering_params[region]; - const RegionOfSeedIndices rosi(m_event, reg); + const RegionOfSeedIndices rosi(m_event, region); - tbb::parallel_for(rosi.tbb_blk_rng(), + tbb::parallel_for(rosi.tbb_blk_rng_vec(), [&](const tbb::blocked_range& blk_rng) { std::unique_ptr mkfp(g_exe_ctx.m_fitters.GetFromPool(), retfitr); @@ -1055,18 +1052,15 @@ void MkBuilder::FindTracksBestHit() void MkBuilder::find_tracks_load_seeds() { - EventOfCombCandidates &eoccs = m_event_tmp->m_event_of_comb_cands; + // Assumes seeds are sorter according to m_regions_of_comb_candidates - for (int r = TrackerInfo::Reg_Endcap_Neg; r < TrackerInfo::Reg_Count; ++r) - { - const RegionOfSeedIndices rosi(m_event, r); + EventOfCombCandidates &eoccs = m_event_of_comb_cands; - eoccs.m_regions_of_comb_candidates[r].Reset(rosi.count()); + eoccs.Reset(m_event->seedTracks_.size()); - for (int i = rosi.m_reg_beg; i < rosi.m_reg_end; ++i) - { - eoccs.m_regions_of_comb_candidates[r].InsertSeed(m_event->seedTracks_[i]); - } + for (auto &t : m_event->seedTracks_) + { + eoccs.InsertSeed(t); } //dump seeds @@ -1081,19 +1075,20 @@ void MkBuilder::FindTracksStandard() { g_exe_ctx.populate(Config::numThreadsFinder); - EventOfCombCandidates &eoccs = m_event_tmp->m_event_of_comb_cands; + EventOfCombCandidates &eoccs = m_event_of_comb_cands; - tbb::parallel_for_each(eoccs.begin(), eoccs.end(), - [&](EtaRegionOfCombCandidates& comb_cands) + tbb::parallel_for_each(m_brl_ecp_regions.begin(), m_brl_ecp_regions.end(), + [&](int region) { - const SteeringParams &st_par = m_steering_params[comb_cands.m_region]; + const SteeringParams &st_par = m_steering_params[region]; - int adaptiveSPT = TrackerInfo::Reg_Count * comb_cands.m_size / Config::numThreadsFinder / 2 + 1; + const RegionOfSeedIndices rosi(m_event, region); - dprint("adaptiveSPT " << adaptiveSPT << " fill " << comb_cands.m_size); + int adaptiveSPT = eoccs.m_size / Config::numThreadsFinder / 2 + 1; + dprint("adaptiveSPT " << adaptiveSPT << " fill " << eoccs.m_size); // loop over seeds - tbb::parallel_for(tbb::blocked_range(0, comb_cands.m_size, std::min(Config::numSeedsPerTask, adaptiveSPT)), + tbb::parallel_for(rosi.tbb_blk_rng_std(/*adaptiveSPT*/), [&](const tbb::blocked_range& seeds) { std::unique_ptr mkfp(g_exe_ctx.m_fitters.GetFromPool(), retfitr); @@ -1120,7 +1115,7 @@ void MkBuilder::FindTracksStandard() for (int iseed = start_seed; iseed < end_seed; ++iseed) { - std::vector &scands = comb_cands[iseed]; + std::vector &scands = eoccs[iseed]; for (int ic = 0; ic < scands.size(); ++ic) { if (scands[ic].getLastHitIdx() >= -1) @@ -1153,7 +1148,7 @@ void MkBuilder::FindTracksStandard() mkfp->SetNhits(n_hits); //here again assuming one hit per layer //fixme find a way to deal only with the candidates needed in this thread - mkfp->InputTracksAndHitIdx(comb_cands.m_candidates, + mkfp->InputTracksAndHitIdx(eoccs.m_candidates, seed_cand_idx, itrack, end, is_first_layer); @@ -1205,7 +1200,7 @@ void MkBuilder::FindTracksStandard() if (num_hits < Config::maxCandsPerSeed) { - std::vector &ov = comb_cands[start_seed+is]; + std::vector &ov = eoccs[start_seed+is]; const int max_m2 = ov.size(); int cur_m2 = 0; @@ -1217,7 +1212,7 @@ void MkBuilder::FindTracksStandard() } } - comb_cands[start_seed+is].swap(tmp_cands[is]); + eoccs[start_seed+is].swap(tmp_cands[is]); tmp_cands[is].clear(); } } @@ -1235,7 +1230,7 @@ void MkBuilder::FindTracksStandard() // final sorting for (int iseed = start_seed; iseed < end_seed; ++iseed) { - std::vector& finalcands = comb_cands[iseed]; + std::vector& finalcands = eoccs[iseed]; if (finalcands.size() == 0) continue; std::sort(finalcands.begin(), finalcands.end(), sortCandByHitsChi2); } @@ -1251,39 +1246,41 @@ void MkBuilder::FindTracksCloneEngine() { g_exe_ctx.populate(Config::numThreadsFinder); - EventOfCombCandidates &eoccs = m_event_tmp->m_event_of_comb_cands; + EventOfCombCandidates &eoccs = m_event_of_comb_cands; - tbb::parallel_for_each(eoccs.begin(), eoccs.end(), - [&](EtaRegionOfCombCandidates& comb_cands) + tbb::parallel_for_each(m_brl_ecp_regions.begin(), m_brl_ecp_regions.end(), + [&](int region) { - int adaptiveSPT = TrackerInfo::Reg_Count * comb_cands.m_size / Config::numThreadsFinder / 2 + 1; + int adaptiveSPT = eoccs.m_size / Config::numThreadsFinder / 2 + 1; + dprint("adaptiveSPT " << adaptiveSPT << " fill " << eoccs.m_size); - dprint("adaptiveSPT " << adaptiveSPT << " fill " << comb_cands.m_size); + const RegionOfSeedIndices rosi(m_event, region); - tbb::parallel_for(tbb::blocked_range(0, comb_cands.m_size, std::min(Config::numSeedsPerTask, adaptiveSPT)), + tbb::parallel_for(rosi.tbb_blk_rng_std(/*adaptiveSPT*/), [&](const tbb::blocked_range& seeds) { std::unique_ptr cloner(g_exe_ctx.m_cloners.GetFromPool(), retcand); std::unique_ptr mkfp (g_exe_ctx.m_fitters.GetFromPool(), retfitr); // loop over layers - find_tracks_in_layers(comb_cands, *cloner, mkfp.get(), seeds.begin(), seeds.end(), comb_cands.m_region); + find_tracks_in_layers(*cloner, mkfp.get(), seeds.begin(), seeds.end(), region); }); }); } -void MkBuilder::find_tracks_in_layers(EtaRegionOfCombCandidates &comb_cands, CandCloner &cloner, - MkFitter *mkfp, int start_seed, int end_seed, int region) +void MkBuilder::find_tracks_in_layers(CandCloner &cloner, MkFitter *mkfp, + int start_seed, int end_seed, int region) { - const SteeringParams &st_par = m_steering_params[region]; - const TrackerInfo &trk_info = Config::TrkInfo; + EventOfCombCandidates &eoccs = m_event_of_comb_cands; + const SteeringParams &st_par = m_steering_params[region]; + const TrackerInfo &trk_info = Config::TrkInfo; const int n_seeds = end_seed - start_seed; std::vector> seed_cand_idx; seed_cand_idx.reserve(n_seeds * Config::maxCandsPerSeed); - cloner.begin_eta_bin(&comb_cands, start_seed, n_seeds); + cloner.begin_eta_bin(&eoccs, start_seed, n_seeds); // Loop over layers, starting from after the seed. // Note that we do a final pass with ilay = -1 to update parameters @@ -1298,12 +1295,12 @@ void MkBuilder::find_tracks_in_layers(EtaRegionOfCombCandidates &comb_cands, Can const LayerInfo &layer_info = trk_info.m_layers[ilay]; //prepare unrolled vector to loop over - for (int iseed = start_seed; iseed != end_seed; ++iseed) + for (int iseed = start_seed; iseed < end_seed; ++iseed) { - std::vector &scands = comb_cands.m_candidates[iseed]; + std::vector &scands = eoccs.m_candidates[iseed]; for (int ic = 0; ic < scands.size(); ++ic) { - if (scands[ic].getLastHitIdx() >= -1) + if (scands[ic].getLastHitIdx() >= -1) // XXXXXXMT4MT what is -2, -3 now? { seed_cand_idx.push_back(std::pair(iseed,ic)); } @@ -1339,7 +1336,7 @@ void MkBuilder::find_tracks_in_layers(EtaRegionOfCombCandidates &comb_cands, Can mkfp->SetNhits(n_hits); - mkfp->InputTracksAndHitIdx(comb_cands.m_candidates, + mkfp->InputTracksAndHitIdx(eoccs.m_candidates, seed_cand_idx, itrack, end, true); @@ -1362,13 +1359,13 @@ void MkBuilder::find_tracks_in_layers(EtaRegionOfCombCandidates &comb_cands, Can (mkfp->*st_par.propagate_foo)(layer_info.*st_par.prop_to_pos_doo, end - itrack); // copy_out the propagated track params, errors only (hit-idcs and chi2 already updated) - mkfp->CopyOutParErr(comb_cands.m_candidates, + mkfp->CopyOutParErr(eoccs.m_candidates, end - itrack, true); } else { // copy_out the updated track params, errors only (hit-idcs and chi2 already updated) - mkfp->CopyOutParErr(comb_cands.m_candidates, + mkfp->CopyOutParErr(eoccs.m_candidates, end - itrack, false); continue; } @@ -1417,7 +1414,7 @@ void MkBuilder::find_tracks_in_layers(EtaRegionOfCombCandidates &comb_cands, Can // final sorting for (int iseed = start_seed; iseed < end_seed; ++iseed) { - std::vector& finalcands = comb_cands.m_candidates[iseed]; + std::vector& finalcands = eoccs.m_candidates[iseed]; if (finalcands.size() == 0) continue; std::sort(finalcands.begin(), finalcands.end(), sortCandByHitsChi2); } diff --git a/mkFit/MkBuilder.h b/mkFit/MkBuilder.h index 0e6ccc19c4e73..992b73373d3a5 100644 --- a/mkFit/MkBuilder.h +++ b/mkFit/MkBuilder.h @@ -38,7 +38,6 @@ extern ExecutionContext g_exe_ctx; //============================================================================== class Event; -class EventTmp; class MkBuilder { @@ -46,9 +45,9 @@ class MkBuilder void fit_one_seed_set(TrackVec& simtracks, int itrack, int end, MkFitter *mkfp, const bool is_brl[], const SteeringParams &st_par); - Event *m_event; - EventTmp *m_event_tmp; - EventOfHits m_event_of_hits; + Event *m_event; + EventOfHits m_event_of_hits; + EventOfCombCandidates m_event_of_comb_cands; int m_cnt=0, m_cnt1=0, m_cnt2=0, m_cnt_8=0, m_cnt1_8=0, m_cnt2_8=0, m_cnt_nomc=0; @@ -65,7 +64,7 @@ class MkBuilder static MkBuilder* make_builder(); - virtual void begin_event(Event* ev, EventTmp* ev_tmp, const char* build_type); + virtual void begin_event(Event* ev, const char* build_type); int find_seeds(); virtual void fit_seeds(); @@ -95,8 +94,7 @@ class MkBuilder void find_tracks_load_seeds_BH(); // for FindTracksBestHit void find_tracks_load_seeds(); - void find_tracks_in_layers(EtaRegionOfCombCandidates &comb_candidates, - CandCloner &cloner, MkFitter *mkfp, + void find_tracks_in_layers(CandCloner &cloner, MkFitter *mkfp, int start_seed, int end_seed, int region); // -------- diff --git a/mkFit/MkBuilderEndcap.cc b/mkFit/MkBuilderEndcap.cc deleted file mode 100644 index 58583f8749e0d..0000000000000 --- a/mkFit/MkBuilderEndcap.cc +++ /dev/null @@ -1,573 +0,0 @@ -#include - -#include "MkBuilderEndcap.h" - -#include "Event.h" -#include "EventTmp.h" -#include "TrackerInfo.h" - -#include "MkFitter.h" - -//#define DEBUG -#include "Debug.h" - -#include - -namespace -{ - auto retcand = [](CandCloner* cloner) { g_exe_ctx.m_cloners.ReturnToPool(cloner); }; - auto retfitr = [](MkFitter* mkfp ) { g_exe_ctx.m_fitters.ReturnToPool(mkfp); }; -} - -#ifdef DEBUG -namespace { - void pre_prop_print(int ilay, MkFitter* mkfp) { - std::cout << "propagate to lay=" << ilay+1 - << " start from x=" << mkfp->getPar(0, 0, 0) << " y=" << mkfp->getPar(0, 0, 1) << " z=" << mkfp->getPar(0, 0, 2) - << " r=" << getHypot(mkfp->getPar(0, 0, 0), mkfp->getPar(0, 0, 1)) - << " px=" << mkfp->getPar(0, 0, 3) << " py=" << mkfp->getPar(0, 0, 4) << " pz=" << mkfp->getPar(0, 0, 5) -#ifdef CCSCOORD - << " pT=" << 1./mkfp->getPar(0, 0, 3) << std::endl; -#else - << " pT=" << getHypot(mkfp->getPar(0, 0, 3), mkfp->getPar(0, 0, 4)) << std::endl; -#endif - } - - void post_prop_print(int ilay, MkFitter* mkfp) { - std::cout << "propagate to lay=" << ilay+1 - << " arrive at x=" << mkfp->getPar(0, 1, 0) << " y=" << mkfp->getPar(0, 1, 1) << " z=" << mkfp->getPar(0, 1, 2) - << " r=" << getHypot(mkfp->getPar(0, 1, 0), mkfp->getPar(0, 1, 1)) << std::endl; - } - - void print_seed(const Track& seed) { - std::cout << "MX - found seed with nHits=" << seed.nFoundHits() << " chi2=" << seed.chi2() - << " posEta=" << seed.posEta() << " posPhi=" << seed.posPhi() << " posR=" << seed.posR() - << " pT=" << seed.pT() << std::endl; - } - - void print_seed2(const Track& seed) { - std::cout << "MX - found seed with nFoundHits=" << seed.nFoundHits() << " chi2=" << seed.chi2() - << " x=" << seed.x() << " y=" << seed.y() << " z=" << seed.z() - << " px=" << seed.px() << " py=" << seed.py() << " pz=" << seed.pz() - << " pT=" << seed.pT() << std::endl; - } - - void print_seeds(const TrackVec& seeds) { - std::cout << "found total seeds=" << seeds.size() << std::endl; - for (auto&& seed : seeds) { - print_seed(seed); - } - } - - void print_seeds(const EventOfCandidates& event_of_cands) { - for (int ebin = 0; ebin < Config::nEtaBin; ++ebin) { - const EtaBinOfCandidates &etabin_of_candidates = event_of_cands.m_etabins_of_candidates[ebin]; - for (int iseed = 0; iseed < etabin_of_candidates.m_size; iseed++) { - print_seed2(etabin_of_candidates.m_candidates[iseed]); - } - } - } - - void print_seeds(const EventOfCombCandidates& event_of_comb_cands) { - for (int ebin = 0; ebin < Config::nEtaBin; ++ebin) { - const EtaBinOfCombCandidates &etabin_of_comb_candidates = event_of_comb_cands.m_etabins_of_comb_candidates[ebin]; - for (int iseed = 0; iseed < etabin_of_comb_candidates.m_size; iseed++) { - print_seed2(etabin_of_comb_candidates.m_candidates[iseed].front()); - } - } - } -} -#endif - -namespace -{ - bool sortCandByHitsChi2(const Track& cand1, const Track& cand2) - { - if (cand1.nFoundHits() == cand2.nFoundHits()) - return cand1.chi2() < cand2.chi2(); - - return cand1.nFoundHits() > cand2.nFoundHits(); - } -} - -//------------------------------------------------------------------------------ -// Constructor and destructor -//------------------------------------------------------------------------------ - -MkBuilderEndcap::MkBuilderEndcap() : MkBuilder() -{} - -MkBuilderEndcap::~MkBuilderEndcap() -{} - -//------------------------------------------------------------------------------ -// Common functions -//------------------------------------------------------------------------------ - -void MkBuilderEndcap::begin_event(Event* ev, EventTmp* ev_tmp, const char* build_type) -{ - m_event = ev; - m_event_tmp = ev_tmp; - - dprint("Building tracks with '" << build_type << "', total simtracks=" << m_event->simTracks_.size()); - - m_event_of_hits.Reset(); - - //fill vector of hits in each layer - for (int ilay = 0; ilay < m_event->layerHits_.size(); ++ilay) - { - // XXXX MT hackout - //dprintf("Suck in Hits for layer %i with AvgZ=%5.1f rMin=%5.1f rMax=%5.1f",ilay,Config::cmsAvgZs[ilay],Config::cmsDiskMinRs[ilay],Config::cmsDiskMaxRs[ilay]); - //m_event_of_hits.SuckInHitsEndcap(ilay, m_event->layerHits_[ilay]); - } - - for (int l=0; lSelectHitIndicesEndcap(layer_of_hits, end - itrack); - -// #ifdef PRINTOUTS_FOR_PLOTS -// std::cout << "MX number of hits in window in layer " << ilay << " is " << mkfp->getXHitEnd(0, 0, 0)-mkfp->getXHitBegin(0, 0, 0) << std::endl; -// #endif - - //make candidates with best hit - dprint("make new candidates"); - mkfp->AddBestHitEndcap(layer_of_hits, end - itrack); - mkfp->SetNhits(ilay + 1); //here again assuming one hit per layer (is this needed?) - - //propagate to layer - if ( ! layer_info.m_is_outer) - { - dcall(pre_prop_print(ilay, mkfp.get())); - - //mkfp->PropagateTracksToZ(m_event->geom_.zPlane(ilay+1), end - itrack); - - // XXXXMT ecap_pos / neg, zmin / zmax - mkfp->PropagateTracksToR(trk_info.m_layers[layer_info.m_next_ecap_pos].m_zmin, end - itrack); - - dcall(post_prop_print(ilay, mkfp.get())); - } - else - { - break; - } - - ilay = layer_info.m_next_ecap_pos; // XXXXMT - } // end of layer loop - mkfp->OutputFittedTracksAndHitIdx(etabin_of_candidates.m_candidates, itrack, end, true); - } - }); // end of seed loop - } - }); //end of parallel section over seeds -} - -//------------------------------------------------------------------------------ -// FindTracksCombinatorial: Standard TBB -//------------------------------------------------------------------------------ - -void MkBuilderEndcap::FindTracksStandard() -{ - EventOfCombCandidates &event_of_comb_cands = m_event_tmp->m_event_of_comb_cands; - - tbb::parallel_for(tbb::blocked_range(0, TrackerInfo::Reg_Count), - [&](const tbb::blocked_range& ebins) - { - for (int ebin = ebins.begin(); ebin != ebins.end(); ++ebin) { - EtaRegionOfCombCandidates& etabin_of_comb_candidates = event_of_comb_cands.m_regions_of_comb_candidates[ebin]; - - tbb::parallel_for(tbb::blocked_range(0,etabin_of_comb_candidates.m_size,Config::numSeedsPerTask), - [&](const tbb::blocked_range& seeds) - { - const int start_seed = seeds.begin(); - const int end_seed = seeds.end(); - const int nseeds = end_seed - start_seed; - - //ok now we start looping over layers - //loop over layers, starting from after the seed - for (int ilay = Config::nlayers_per_seed; ilay < Config::nLayers; ++ilay)// layer 3, we ignore PXB1 - { - LayerOfHits &layer_of_hits = m_event_of_hits.m_layers_of_hits[ilay]; - - dprint("processing lay=" << ilay+1); - - // prepare unrolled vector to loop over - std::vector > seed_cand_idx; - - for (int iseed = start_seed; iseed != end_seed; ++iseed) - { - std::vector &scands = etabin_of_comb_candidates.m_candidates[iseed]; - for (int ic = 0; ic < scands.size(); ++ic) - { - if (scands[ic].getLastHitIdx() != -2) //only if last hit is -2 we do not move forward (i.e -3 is good!) - { - seed_cand_idx.push_back(std::pair(iseed,ic)); - } - } - } - int theEndCand = seed_cand_idx.size(); - - // don't bother messing with the clone engine if there are no candidates - // (actually it crashes, so this protection is needed) - // XXXX MT ??? How does this happen ??? - if (theEndCand == 0) continue; - - std::vector> tmp_candidates(nseeds); - for (int iseed = 0; iseed < tmp_candidates.size(); ++iseed) - { - // XXXX MT: Tried adding 25 to reserve below as I was seeing some - // time spent in push_back ... but it didn't really help. - // We need to optimize this by throwing away and replacing the worst - // candidate once a better one arrives. This will also avoid sorting. - tmp_candidates[iseed].reserve(2*Config::maxCandsPerSeed);//factor 2 seems reasonable to start with - } - - //vectorized loop - for (int itrack = 0; itrack < theEndCand; itrack += NN) - { - int end = std::min(itrack + NN, theEndCand); - - dprint("processing track=" << itrack); - - std::unique_ptr mkfp (g_exe_ctx.m_fitters.GetFromPool(), retfitr); - - mkfp->SetNhits(ilay);//here again assuming one hit per layer - - //fixme find a way to deal only with the candidates needed in this thread - mkfp->InputTracksAndHitIdx(etabin_of_comb_candidates.m_candidates, - seed_cand_idx, itrack, end, - ilay == Config::nlayers_per_seed); - - //propagate to layer - if (ilay > Config::nlayers_per_seed) - { - dcall(pre_prop_print(ilay, mkfp)); - mkfp->PropagateTracksToZ(m_event->geom_.zPlane(ilay), end - itrack); - dcall(post_prop_print(ilay, mkfp)); - } - - dprint("now get hit range"); - mkfp->SelectHitIndicesEndcap(layer_of_hits, end - itrack); - - //#ifdef PRINTOUTS_FOR_PLOTS - //std::cout << "MX number of hits in window in layer " << ilay << " is " << mkfp->getXHitEnd(0, 0, 0)-mkfp->getXHitBegin(0, 0, 0) << std::endl; - //#endif - - dprint("make new candidates"); - mkfp->FindCandidatesEndcap(layer_of_hits, tmp_candidates, start_seed, end - itrack); - - } //end of vectorized loop - - // clean exceeding candidates per seed - // FIXME: is there a reason why these are not vectorized???? - for (int is = 0; is < tmp_candidates.size(); ++is) - { - dprint("dump seed n " << is << " with input candidates=" << tmp_candidates[is].size()); - std::sort(tmp_candidates[is].begin(), tmp_candidates[is].end(), sortCandByHitsChi2); - - if (tmp_candidates[is].size() > Config::maxCandsPerSeed) - { - dprint("erase extra candidates" << " tmp_candidates[is].size()=" << tmp_candidates[is].size() - << " Config::maxCandsPerSeed=" << Config::maxCandsPerSeed); - tmp_candidates[is].erase(tmp_candidates[is].begin() + Config::maxCandsPerSeed, - tmp_candidates[is].end()); - } - dprint("dump seed n " << is << " with output candidates=" << tmp_candidates[is].size()); - } - //now swap with input candidates - for (int is = 0; is < tmp_candidates.size(); ++is) - { - if (tmp_candidates[is].size() > 0) - { - // Copy the best -2 cands back to the current list. - int num_hits = tmp_candidates[is].size(); - - if (num_hits < Config::maxCandsPerSeed) - { - std::vector &ov = etabin_of_comb_candidates.m_candidates[start_seed+is]; - int cur_m2 = 0; - int max_m2 = ov.size(); - while (cur_m2 < max_m2 && ov[cur_m2].getLastHitIdx() != -2) ++cur_m2; - while (cur_m2 < max_m2 && num_hits < Config::maxCandsPerSeed) - { - tmp_candidates[is].push_back( ov[cur_m2++] ); - ++num_hits; - } - } - - etabin_of_comb_candidates.m_candidates[start_seed+is].swap(tmp_candidates[is]); - tmp_candidates[is].clear(); - } - } - - } // end of layer loop - - // final sorting - for (int iseed = start_seed; iseed < end_seed; ++iseed) - { - std::vector& finalcands = etabin_of_comb_candidates.m_candidates[iseed]; - if (finalcands.size() == 0) continue; - std::sort(finalcands.begin(), finalcands.end(), sortCandByHitsChi2); - } - }); // end parallel-for loop over blocked range of seeds - } // end of loop over chunk of eta bins within block - }); // end parallel-for loop over eta bins -} - -//------------------------------------------------------------------------------ -// FindTracksCombinatorial: CloneEngine TBB -//------------------------------------------------------------------------------ - -void MkBuilderEndcap::FindTracksCloneEngine() -{ - EventOfCombCandidates &event_of_comb_cands = m_event_tmp->m_event_of_comb_cands; - - tbb::parallel_for(tbb::blocked_range(0, TrackerInfo::Reg_Count), - [&](const tbb::blocked_range& ebins) - { - for (int ebin = ebins.begin(); ebin != ebins.end(); ++ebin) { - EtaRegionOfCombCandidates& etabin_of_comb_candidates = event_of_comb_cands.m_regions_of_comb_candidates[ebin]; - - tbb::parallel_for(tbb::blocked_range(0,etabin_of_comb_candidates.m_size,Config::numSeedsPerTask), - [&](const tbb::blocked_range& seeds) - { - std::unique_ptr cloner(g_exe_ctx.m_cloners.GetFromPool(), retcand); - std::unique_ptr mkfp (g_exe_ctx.m_fitters.GetFromPool(), retfitr); - - // loop over layers - find_tracks_in_layers_endcap(etabin_of_comb_candidates, *cloner, mkfp.get(), seeds.begin(), seeds.end(), ebin); - }); - } - }); -} - -void MkBuilderEndcap::find_tracks_in_layers_endcap(EtaRegionOfCombCandidates &etabin_of_comb_candidates, CandCloner &cloner, - MkFitter *mkfp, int start_seed, int end_seed, int ebin) -{ - auto n_seeds = end_seed - start_seed; - - std::vector> seed_cand_idx; - seed_cand_idx.reserve(n_seeds * Config::maxCandsPerSeed); - - cloner.begin_eta_bin(&etabin_of_comb_candidates, start_seed, n_seeds); - - //loop over layers, starting from after the seeD - for (int ilay = Config::nlayers_per_seed /* MTXXXX Config::nlayers_per_seed */; ilay <= Config::nLayers; ++ilay) - { - dprint("processing lay=" << ilay+1); - - //prepare unrolled vector to loop over - for (int iseed = start_seed; iseed != end_seed; ++iseed) - { - std::vector &scands = etabin_of_comb_candidates.m_candidates[iseed]; - for (int ic = 0; ic < scands.size(); ++ic) - { - if (scands[ic].getLastHitIdx() != -2) - { - seed_cand_idx.push_back(std::pair(iseed,ic)); - } - } - } - const int theEndCand = seed_cand_idx.size(); - - // don't bother messing with the clone engine if there are no candidates - // (actually it crashes, so this protection is needed) - // XXXX MT ??? How does this happen ??? - if (theEndCand == 0) continue; - - if (ilay < Config::nLayers) - { - cloner.begin_layer(ilay); - } - - //vectorized loop - for (int itrack = 0; itrack < theEndCand; itrack += NN) - { - const int end = std::min(itrack + NN, theEndCand); - -#ifdef DEBUG - dprint("processing track=" << itrack); - dprintf("FTCE: start_seed=%d, n_seeds=%d, theEndCand=%d\n" - " itrack=%d, end=%d, nn=%d, end_eq_tec=%d\n", - start_seed, n_seeds, theEndCand, - itrack, end, end-itrack, end == theEndCand); - dprintf(" "); - for (int i=itrack; i < end; ++i) dprintf("%d,%d ", seed_cand_idx[i].first, seed_cand_idx[i].second); - dprintf("\n"); -#endif - - // mkfp->SetNhits(ilay == Config::nlayers_per_seed ? ilay : ilay + 1); - mkfp->SetNhits(ilay); - - mkfp->InputTracksAndHitIdx(etabin_of_comb_candidates.m_candidates, - seed_cand_idx, itrack, end, - true); - -#ifdef DEBUG - for (int i=itrack; i < end; ++i) - dprintf(" track %d, idx %d is from seed %d\n", i, i - itrack, mkfp->Label(i - itrack,0,0)); - dprintf("\n"); -#endif - - if (ilay > Config::nlayers_per_seed /* MTXXXX Config::nlayers_per_seed*/) - { - LayerOfHits &layer_of_hits = m_event_of_hits.m_layers_of_hits[ilay - 1]; - - mkfp->UpdateWithLastHitEndcap(layer_of_hits, end - itrack); - - if (ilay < Config::nLayers) - { - // Propagate to this layer - - mkfp->PropagateTracksToZ(m_event->geom_.zPlane(ilay), end - itrack); - - // copy_out the propagated track params, errors only (hit-idcs and chi2 already updated) - mkfp->CopyOutParErr(etabin_of_comb_candidates.m_candidates, - end - itrack, true); - } - else { - // copy_out the updated track params, errors only (hit-idcs and chi2 already updated) - mkfp->CopyOutParErr(etabin_of_comb_candidates.m_candidates, - end - itrack, false); - continue; - } - } - - // if (ilay == Config::nLayers) - // { - // continue; - // //break; - // } - - dprint("now get hit range"); - - LayerOfHits &layer_of_hits = m_event_of_hits.m_layers_of_hits[ilay]; - - mkfp->SelectHitIndicesEndcap(layer_of_hits, end - itrack); - - //#ifdef PRINTOUTS_FOR_PLOTS - //std::cout << "MX number of hits in window in layer " << ilay << " is " << mkfp->getXHitEnd(0, 0, 0)-mkfp->getXHitBegin(0, 0, 0) << std::endl; - //#endif - - dprint("make new candidates"); - cloner.begin_iteration(); - - mkfp->FindCandidatesMinimizeCopyEndcap(layer_of_hits, cloner, start_seed, end - itrack); - - cloner.end_iteration(); - } //end of vectorized loop - - if (ilay < Config::nLayers) - { - cloner.end_layer(); - } - seed_cand_idx.clear(); - - } // end of layer loop - - cloner.end_eta_bin(); - - // final sorting - for (int iseed = start_seed; iseed < end_seed; ++iseed) - { - std::vector& finalcands = etabin_of_comb_candidates.m_candidates[iseed]; - if (finalcands.size() == 0) continue; - std::sort(finalcands.begin(), finalcands.end(), sortCandByHitsChi2); - } -} diff --git a/mkFit/MkBuilderEndcap.h b/mkFit/MkBuilderEndcap.h deleted file mode 100644 index dd42d7acdea4f..0000000000000 --- a/mkFit/MkBuilderEndcap.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef MkBuilderEndcap_H -#define MkBuilderEndcap_H - -#include "MkBuilder.h" - - -class MkBuilderEndcap : public MkBuilder -{ -protected: - void fit_one_seed_set_endcap(TrackVec& simtracks, int itrack, int end, MkFitter *mkfp); - - void find_tracks_in_layers_endcap(EtaRegionOfCombCandidates &comb_cands, CandCloner &cloner, MkFitter *mkfp, - int start_seed, int end_seed, int ebin); - -public: - - MkBuilderEndcap(); - ~MkBuilderEndcap(); - - // -------- - - void begin_event(Event* ev, EventTmp* ev_tmp, const char* build_type) override; - - void fit_seeds() override; - - void FindTracksBestHit(EventOfCandidates& event_of_cands); - void FindTracksStandard() override; - void FindTracksCloneEngine() override; -}; - -#endif diff --git a/mkFit/buildtestMPlex.cc b/mkFit/buildtestMPlex.cc index 4097f7217acb0..a6dbff0efe494 100644 --- a/mkFit/buildtestMPlex.cc +++ b/mkFit/buildtestMPlex.cc @@ -75,7 +75,7 @@ inline bool sortByZ(const Hit& hit1, const Hit& hit2) double runBuildingTestPlexBestHit(Event& ev, MkBuilder& builder) { - builder.begin_event(&ev, 0, __func__); + builder.begin_event(&ev, __func__); if (Config::findSeeds) {builder.find_seeds();} else {builder.map_seed_hits();} // all other simulated seeds need to have hit indices line up in LOH for seed fit @@ -125,9 +125,9 @@ double runBuildingTestPlexBestHit(Event& ev, MkBuilder& builder) // runBuildTestPlex Combinatorial: Standard TBB //============================================================================== -double runBuildingTestPlexStandard(Event& ev, EventTmp& ev_tmp, MkBuilder& builder) +double runBuildingTestPlexStandard(Event& ev, MkBuilder& builder) { - builder.begin_event(&ev, &ev_tmp, __func__); + builder.begin_event(&ev, __func__); if (Config::findSeeds) {builder.find_seeds();} else {builder.map_seed_hits();} // all other simulated seeds need to have hit indices line up in LOH for seed fit @@ -163,9 +163,9 @@ double runBuildingTestPlexStandard(Event& ev, EventTmp& ev_tmp, MkBuilder& build // runBuildTestPlex Combinatorial: CloneEngine TBB //============================================================================== -double runBuildingTestPlexCloneEngine(Event& ev, EventTmp& ev_tmp, MkBuilder& builder) +double runBuildingTestPlexCloneEngine(Event& ev, MkBuilder& builder) { - builder.begin_event(&ev, &ev_tmp, __func__); + builder.begin_event(&ev, __func__); if (Config::findSeeds) {builder.find_seeds();} else {builder.map_seed_hits();} // all other simulated seeds need to have hit indices line up in LOH for seed fit diff --git a/mkFit/buildtestMPlex.h b/mkFit/buildtestMPlex.h index 3f16ed278c81f..f49adfd82b323 100644 --- a/mkFit/buildtestMPlex.h +++ b/mkFit/buildtestMPlex.h @@ -2,14 +2,13 @@ #define _buildtest_mplex_ #include "Event.h" -#include "EventTmp.h" #include "Track.h" class MkBuilder; double runBuildingTestPlexBestHit(Event& ev, MkBuilder& builder); -double runBuildingTestPlexStandard(Event& ev, EventTmp& ev_tmp, MkBuilder& builder); -double runBuildingTestPlexCloneEngine(Event& ev, EventTmp& evtmp, MkBuilder& builder); +double runBuildingTestPlexStandard(Event& ev, MkBuilder& builder); +double runBuildingTestPlexCloneEngine(Event& ev, MkBuilder& builder); #if USE_CUDA double runAllBuildingTestPlexBestHitGPU(std::vector &events); diff --git a/mkFit/mkFit.cc b/mkFit/mkFit.cc index 95b5755ea1f73..f2e7aadad89db 100644 --- a/mkFit/mkFit.cc +++ b/mkFit/mkFit.cc @@ -271,7 +271,6 @@ void test_standard() std::atomic nevt{1}; std::atomic seedstot{0}, simtrackstot{0}; - std::vector ev_tmps(Config::numThreadsEvents); std::vector> evs(Config::numThreadsEvents); std::vector> vals(Config::numThreadsEvents); std::vector> mkbs(Config::numThreadsEvents); @@ -306,7 +305,6 @@ void test_standard() assert(threads.begin() == threads.end()-1 && thisthread < Config::numThreadsEvents); std::vector plex_tracks; - auto& ev_tmp = ev_tmps[thisthread]; auto& ev = *evs[thisthread].get(); auto& mkb = *mkbs[thisthread].get(); auto fp = fps[thisthread].get(); @@ -358,8 +356,8 @@ void test_standard() cuFitter.freeDevice(); #endif t_cur[1] = (g_run_build_all || g_run_build_bh) ? runBuildingTestPlexBestHit(ev, mkb) : 0; - t_cur[2] = (g_run_build_all || g_run_build_std) ? runBuildingTestPlexStandard(ev, ev_tmp, mkb) : 0; - t_cur[3] = (g_run_build_all || g_run_build_ce) ? runBuildingTestPlexCloneEngine(ev, ev_tmp, mkb) : 0; + t_cur[2] = (g_run_build_all || g_run_build_std) ? runBuildingTestPlexStandard(ev, mkb) : 0; + t_cur[3] = (g_run_build_all || g_run_build_ce) ? runBuildingTestPlexCloneEngine(ev, mkb) : 0; for (int i = 0; i < NT; ++i) t_best[i] = (b == 0) ? t_cur[i] : std::min(t_cur[i], t_best[i]); From 9fb1b87300951ec9cd77469d5cb990c119a21467 Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Thu, 6 Apr 2017 23:54:19 -0700 Subject: [PATCH 014/172] Remove propagation-at-the-end. This was defacto already done, partially, so this only resulted in slight simplification of ifs in FindTrackXXX functions. --- mkFit/MkBuilder.cc | 92 +++++++++++++++------------------------------- 1 file changed, 30 insertions(+), 62 deletions(-) diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index 8b3740430e316..00e2fe76ec1d5 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -599,17 +599,7 @@ inline void MkBuilder::fit_one_seed_set(TrackVec& seedtracks, int itrack, int en mkfp->FitTracksSteered(is_brl, end - itrack, m_event); } - const TrackerInfo &trk_info = Config::TrkInfo; - - const int ilay = st_par.first_finding_layer; - - dcall(pre_prop_print(ilay, mkfp)); - - (mkfp->*st_par.propagate_foo)(trk_info.m_layers[ilay].*st_par.prop_to_pos_doo, end - itrack); - - dcall(post_prop_print(ilay, mkfp)); - - mkfp->OutputFittedTracksAndHitIdx(m_event->seedTracks_, itrack, end, true); + mkfp->OutputFittedTracksAndHitIdx(m_event->seedTracks_, itrack, end, false); } //------------------------------------------------------------------------------ @@ -988,7 +978,7 @@ void MkBuilder::FindTracksBestHit() int n_hits = Config::nlayers_per_seed; mkfp->SetNhits(n_hits); - mkfp->InputTracksAndHitIdx(cands, rng.m_beg, rng.m_end, true); + mkfp->InputTracksAndHitIdx(cands, rng.m_beg, rng.m_end, false); // Loop over layers, starting from after the seed. // Consider inverting loop order and make layer outer, need to @@ -1006,6 +996,12 @@ void MkBuilder::FindTracksBestHit() // _mm_prefetch((char*) & bunch_of_hits.m_hits[i], _MM_HINT_T1); // } + dcall(pre_prop_print(next_layer, mkfp.get())); + + (mkfp.get()->*st_par.propagate_foo)(trk_info.m_layers[ilay].*st_par.prop_to_pos_doo, rng.n_proc()); + + dcall(post_prop_print(next_layer, mkfp.get())); + (mkfp.get()->*st_par.select_hits_foo)(layer_of_hits, rng.n_proc(), false); // #ifdef PRINTOUTS_FOR_PLOTS @@ -1019,26 +1015,15 @@ void MkBuilder::FindTracksBestHit() mkfp->SetNhits(++n_hits); - int next_layer = layer_info.*st_par.next_layer_doo; - - // propagate to layer - if ( ! layer_info.m_is_outer) - { - dcall(pre_prop_print(next_layer, mkfp.get())); - - (mkfp.get()->*st_par.propagate_foo)(trk_info.m_layers[next_layer].*st_par.prop_to_pos_doo, rng.n_proc()); - - dcall(post_prop_print(next_layer, mkfp.get())); - } - else + if (layer_info.m_is_outer) { break; } - ilay = next_layer; + ilay = layer_info.*st_par.next_layer_doo; } // end of layer loop - mkfp->OutputFittedTracksAndHitIdx(cands, rng.m_beg, rng.m_end, true); + mkfp->OutputFittedTracksAndHitIdx(cands, rng.m_beg, rng.m_end, false); ++rng; } // end of loop over candidates in a tbb chunk @@ -1101,7 +1086,6 @@ void MkBuilder::FindTracksStandard() // Loop over layers, starting from after the seed. int n_hits = Config::nlayers_per_seed; - bool is_first_layer = true; for (int ilay = st_par.first_finding_layer; ; ) { @@ -1150,17 +1134,14 @@ void MkBuilder::FindTracksStandard() //fixme find a way to deal only with the candidates needed in this thread mkfp->InputTracksAndHitIdx(eoccs.m_candidates, seed_cand_idx, itrack, end, - is_first_layer); + false); //propagate to layer - if ( ! is_first_layer) - { - dcall(pre_prop_print(ilay, mkfp.get())); + dcall(pre_prop_print(ilay, mkfp.get())); - (mkfp.get()->*st_par.propagate_foo)(layer_info.*st_par.prop_to_pos_doo, end - itrack); + (mkfp.get()->*st_par.propagate_foo)(layer_info.*st_par.prop_to_pos_doo, end - itrack); - dcall(post_prop_print(ilay, mkfp.get())); - } + dcall(post_prop_print(ilay, mkfp.get())); dprint("now get hit range"); (mkfp.get()->*st_par.select_hits_foo)(layer_of_hits, end - itrack, false); @@ -1223,7 +1204,6 @@ void MkBuilder::FindTracksStandard() } ++n_hits; - is_first_layer = false; ilay = layer_info.*st_par.next_layer_doo; } // end of layer loop @@ -1336,45 +1316,33 @@ void MkBuilder::find_tracks_in_layers(CandCloner &cloner, MkFitter *mkfp, mkfp->SetNhits(n_hits); - mkfp->InputTracksAndHitIdx(eoccs.m_candidates, - seed_cand_idx, itrack, end, - true); + mkfp->InputTracksAndHitIdx(eoccs.m_candidates, seed_cand_idx, + itrack, end, prev_ilay >= 0); #ifdef DEBUG for (int i=itrack; i < end; ++i) dprintf(" track %d, idx %d is from seed %d\n", i, i - itrack, mkfp->Label(i - itrack,0,0)); dprintf("\n"); #endif - if (prev_ilay >= 0) { const LayerOfHits &prev_layer_of_hits = m_event_of_hits.m_layers_of_hits[prev_ilay]; (mkfp->*st_par.update_with_last_hit_foo)(prev_layer_of_hits, end - itrack); - - if (ilay >= 0) - { - // Propagate to this layer - - (mkfp->*st_par.propagate_foo)(layer_info.*st_par.prop_to_pos_doo, end - itrack); - - // copy_out the propagated track params, errors only (hit-idcs and chi2 already updated) - mkfp->CopyOutParErr(eoccs.m_candidates, - end - itrack, true); - } - else - { - // copy_out the updated track params, errors only (hit-idcs and chi2 already updated) - mkfp->CopyOutParErr(eoccs.m_candidates, - end - itrack, false); - continue; - } } - - // if (ilay == Config::nLayers) - // { - // break; - // } + if (ilay >= 0) + { + // propagate to current layer + (mkfp->*st_par.propagate_foo)(layer_info.*st_par.prop_to_pos_doo, end - itrack); + // copy_out the propagated track params, errors only (hit-idcs and chi2 already updated) + mkfp->CopyOutParErr(eoccs.m_candidates, end - itrack, true); + } + else + { + // copy_out the updated track params, errors only (hit-idcs and chi2 already updated) + mkfp->CopyOutParErr(eoccs.m_candidates, end - itrack, false); + continue; + } dprint("now get hit range"); From de3759d9c7f719b43bf9e62508ba91657ffe6201 Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Tue, 11 Apr 2017 14:24:12 -0700 Subject: [PATCH 015/172] clean up ROOT based validation --- Config.cc | 4 +- Config.h | 6 +- Event.cc | 25 +- PlotValidation.cpp | 1194 +--------------------------------- PlotValidation.hh | 12 +- TTreeValidation.cc | 1357 ++++----------------------------------- TTreeValidation.h | 201 +----- Validation.cc | 2 +- Validation.h | 19 - buildtest.cc | 8 +- fittest.cc | 2 - main.cc | 60 +- mkFit/buildtestMPlex.cc | 8 +- mkFit/fittestMPlex.cc | 70 -- mkFit/fittestMPlex.h | 4 - mkFit/mkFit.cc | 12 +- runValidation.C | 11 +- seedtest.cc | 28 - 18 files changed, 163 insertions(+), 2860 deletions(-) diff --git a/Config.cc b/Config.cc index e9338931bc991..d3b85f4764ccc 100644 --- a/Config.cc +++ b/Config.cc @@ -49,9 +49,7 @@ namespace Config bool cf_seeding = false; bool cf_fitting = false; - bool super_debug = false; - bool normal_val = false; - bool full_val = false; + bool root_val = false; bool fit_val = false; void RecalculateDependentConstants() diff --git a/Config.h b/Config.h index 5e3954e1e7feb..36f527c15705b 100644 --- a/Config.h +++ b/Config.h @@ -15,9 +15,6 @@ namespace Config { extern TrackerInfo TrkInfo; - // super debug mode in SMatrix - extern bool super_debug; - // default file version constexpr int FileVersion = 1; @@ -244,8 +241,7 @@ namespace Config extern int maxCandsPerEtaBin; // config on validation - extern bool normal_val; - extern bool full_val; + extern bool root_val; extern bool fit_val; // Effective eta bin is one half of nEtaPart -- so the above is twice the "average". diff --git a/Event.cc b/Event.cc index f548495e5fa1d..44287303422a1 100644 --- a/Event.cc +++ b/Event.cc @@ -69,11 +69,7 @@ Event::Event(const Geometry& g, Validation& v, int evtID, int threads) : layerHits_.resize(Config::nTotalLayers); segmentMap_.resize(Config::nTotalLayers); - // XXMT4K validation_.resetValidationMaps(); // need to reset maps for every event. - if (Config::super_debug) { - validation_.resetDebugVectors(); // need to reset vectors for every event. - } } void Event::Reset(int evtID) @@ -93,9 +89,6 @@ void Event::Reset(int evtID) simTrackStates_.clear(); validation_.resetValidationMaps(); // need to reset maps for every event. - if (Config::super_debug) { - validation_.resetDebugVectors(); // need to reset vectors for every event. - } } void Event::Simulate() @@ -158,7 +151,7 @@ void Event::Simulate() std::lock_guard lock(mcGatherMutex_); // uber ugly way of getting around read-in / write-out of objects needed for validation - if (Config::normal_val || Config::fit_val) {simTrackStates_[itrack] = initialTSs;} + if (Config::root_val || Config::fit_val) {simTrackStates_[itrack] = initialTSs;} validation_.collectSimTkTSVecMapInfo(itrack,initialTSs); // save initial TS parameters in validation object ... just a copy of the above line simTracks_[itrack] = Track(q,pos,mom,covtrk,0.0f); @@ -333,22 +326,12 @@ void Event::Fit() void Event::Validate() { // KM: Config tree just filled once... in main.cc - if (Config::normal_val) { + if (Config::root_val) { validation_.setTrackExtras(*this); validation_.makeSimTkToRecoTksMaps(*this); validation_.makeSeedTkToRecoTkMaps(*this); validation_.fillEfficiencyTree(*this); validation_.fillFakeRateTree(*this); - if (Config::full_val) { - validation_.fillSegmentTree(segmentMap_,evtID_); - validation_.fillBranchTree(evtID_); - validation_.fillGeometryTree(*this); - validation_.fillConformalTree(*this); - } - } - - if (Config::super_debug) { // super debug mode - validation_.fillDebugTree(*this); } if (Config::fit_val) { // fit val for z-phi tuning @@ -397,7 +380,7 @@ void Event::write_out(FILE *fp) fwrite(&simTracks_[0], sizeof(Track), nt, fp); evsize += sizeof(int) + nt*sizeof(Track); - if (Config::normal_val || Config::fit_val) { + if (Config::root_val || Config::fit_val) { for (int it = 0; itGetXaxis()->SetTitle(Form("%s%s",svars[i].Data(),sunits[i].Data())); varsDenomPlot[i][j]->GetYaxis()->SetTitle("nTracks"); - // Effiency - varsEffPlot[i][j] = new TH1F(Form("h_sim_%s_EFF_%s_EFF",vars[i].Data(),trks[j].Data()),Form("%s Track Effiency vs MC %s",strks[j].Data(),svars[i].Data()),nBins[i],xlow[i],xhigh[i]); + // Efficiency + varsEffPlot[i][j] = new TH1F(Form("h_sim_%s_EFF_%s_EFF",vars[i].Data(),trks[j].Data()),Form("%s Track Efficiency vs MC %s",strks[j].Data(),svars[i].Data()),nBins[i],xlow[i],xhigh[i]); varsEffPlot[i][j]->GetXaxis()->SetTitle(Form("%s%s",svars[i].Data(),sunits[i].Data())); varsEffPlot[i][j]->GetYaxis()->SetTitle("Efficiency"); } @@ -164,7 +152,7 @@ void PlotValidation::PlotEfficiency(){ varsDenomPlot[i][j]->Fill(mcvars_val[i]); if (mcmask_trk[j] == 1){ // must be associated varsNumerPlot[i][j]->Fill(mcvars_val[i]); - } // must be a matched track for effiency + } // must be a matched track for efficiency } // end loop over trks } // end loop over vars } // end loop over entry in tree @@ -437,7 +425,7 @@ void PlotValidation::PlotNHits(){ for (UInt_t j = 0; j < trks.size(); j++){ for (UInt_t c = 0; c < coll.size(); c++){ // Numerator only type plots only! - nHitsPlot[j][c] = new TH1F(Form("h_nHits_%s_%s",coll[c].Data(),trks[j].Data()),Form("%s %s Track vs nHits / Track",scoll[c].Data(),strks[j].Data()),11,0,11); + nHitsPlot[j][c] = new TH1F(Form("h_nHits_%s_%s",coll[c].Data(),trks[j].Data()),Form("%s %s Track vs nHits / Track",scoll[c].Data(),strks[j].Data()),30,0,30); nHitsPlot[j][c]->GetXaxis()->SetTitle("nHits / Track"); nHitsPlot[j][c]->GetYaxis()->SetTitle("nTracks"); nHitsPlot[j][c]->Sumw2(); @@ -511,78 +499,6 @@ void PlotValidation::PlotNHits(){ delete fakeratetree; } -void PlotValidation::PlotTiming(){ - // get input tree - TTree * timetree = (TTree*)fInRoot->Get("timetree"); - - // labels for histos (x-axis) - TStrVec stime = {"Simulate","Segment","Seed","Build","Fit","Validate"}; - - // make subdirectory - TString subdirname = "timing"; - PlotValidation::MakeSubDirectory(subdirname); - PlotValidation::MakeSubDirectory(Form("%s/lin",subdirname.Data())); - PlotValidation::MakeSubDirectory(Form("%s/log",subdirname.Data())); - TDirectory * subdir = fOutRoot->mkdir(subdirname.Data()); - subdir->cd(); - - // output plots - Bool_t zeroSupLin = true; - - // make new timing plots - TH1F * tottime = new TH1F("h_total_timing","Total Time Spent in Simulation",6,0,6); - tottime->GetXaxis()->SetTitle("Event Function Call"); - tottime->GetYaxis()->SetTitle("Time [s]"); - tottime->SetStats(0); - tottime->Sumw2(); - for (Int_t t = 1; t <= tottime->GetNbinsX(); t++){ - tottime->GetXaxis()->SetBinLabel(t,stime[t-1].Data()); - } - - TH1F * rectime = new TH1F("h_reco_timing_norm","Normalized Time Spent in Reconstruction",4,0,4); - tottime->GetXaxis()->SetTitle("Event Function Call"); - rectime->GetYaxis()->SetTitle("Fraction of Time in Reco"); - rectime->SetStats(0); - rectime->Sumw2(); - for (Int_t t = 1; t <= rectime->GetNbinsX(); t++){ - rectime->GetXaxis()->SetBinLabel(t,stime[t].Data()); - } - - Float_t simtime = 0., segtime = 0., seedtime = 0., buildtime = 0., fittime = 0., hlvtime = 0.; - timetree->SetBranchAddress("simtime",&simtime); - timetree->SetBranchAddress("segtime",&segtime); - timetree->SetBranchAddress("seedtime",&seedtime); - timetree->SetBranchAddress("buildtime",&buildtime); - timetree->SetBranchAddress("fittime",&fittime); - timetree->SetBranchAddress("hlvtime",&hlvtime); - timetree->GetEntry(0); - - // fill histos - tottime->SetBinContent(1,simtime); - tottime->SetBinContent(2,segtime); - tottime->SetBinContent(3,seedtime); - tottime->SetBinContent(4,buildtime); - tottime->SetBinContent(5,fittime); - tottime->SetBinContent(6,hlvtime); - - rectime->SetBinContent(1,segtime); - rectime->SetBinContent(2,seedtime); - rectime->SetBinContent(3,buildtime); - rectime->SetBinContent(4,fittime); - - // normalize rec time - rectime->Scale(1.0/rectime->Integral()); - - // draw and save stuff - PlotValidation::DrawWriteSaveTH1FPlot(subdir,tottime,subdirname,"total_time_sim",zeroSupLin); - PlotValidation::DrawWriteSaveTH1FPlot(subdir,rectime,subdirname,"norm_time_reco",zeroSupLin); - - delete tottime; - delete rectime; - - delete timetree; -} - void PlotValidation::PlotMomResolutionPull(){ // Get tree TTree * efftree = (TTree*)fInRoot->Get("efftree"); @@ -699,1071 +615,6 @@ void PlotValidation::PlotMomResolutionPull(){ delete efftree; } -void PlotValidation::PlotSegment(){ - // Get trees and set addresses - TTree * segtree = (TTree*)fInRoot->Get("segtree"); - - Int_t event = 0; - Int_t layer = 0; - Int_t etabin = 0; - Int_t phibin = 0; - Int_t nHits = 0; - - segtree->SetBranchAddress("evtID",&event); - segtree->SetBranchAddress("layer",&layer); - segtree->SetBranchAddress("etabin",&etabin); - segtree->SetBranchAddress("phibin",&phibin); - segtree->SetBranchAddress("nHits",&nHits); - - // get config info - TTree * configtree = (TTree*)fInRoot->Get("configtree"); - Int_t nEvents = 0; - Int_t nLayers = 0; - Int_t nEtaPart = 0; - Int_t nPhiPart = 0; - configtree->SetBranchAddress("Nevents",&nEvents); - configtree->SetBranchAddress("nLayers",&nLayers); - configtree->SetBranchAddress("nEtaPart",&nEtaPart); - configtree->SetBranchAddress("nPhiPart",&nPhiPart); - configtree->GetEntry(0); - - //////////////////////////////////////// - // Store the info in relevant vectors // - //////////////////////////////////////// - - // initialize the relevant vectors here - FltVecVec nHitsEtaVV(nLayers); // vector to store how many hits in given eta bin (sum over the phi bins) - FltVecVecVec nHitsPhiVVV(nLayers); // vector to store how many hits in given eta-phi bin - for (Int_t ilay = 0; ilay < nLayers; ilay++){ - nHitsEtaVV[ilay].resize(nEtaPart); - nHitsPhiVVV[ilay].resize(nEtaPart); - for (Int_t ieta = 0; ieta < nEtaPart; ieta++){ - nHitsEtaVV[ilay][ieta] = 0; - nHitsPhiVVV[ilay][ieta].resize(nPhiPart); - for (Int_t iphi = 0; iphi < nPhiPart; iphi++){ - nHitsPhiVVV[ilay][ieta][iphi] = 0; - } - } - } - - // just fill the eta-phi bin vector, and then sum over phi bins for the eta vector - for (Int_t i = 0; i < segtree->GetEntries(); i++) { - segtree->GetEntry(i); - nHitsPhiVVV[layer][etabin][phibin] += nHits; - } - - // sum over phi bins into eta bin vector - for (Int_t ilay = 0; ilay < nLayers; ilay++){ - for (Int_t ieta = 0; ieta < nEtaPart; ieta++){ - for (Int_t iphi = 0; iphi < nPhiPart; iphi++){ - nHitsEtaVV[ilay][ieta] += nHitsPhiVVV[ilay][ieta][iphi]; - } - } - } - - // average over events - for (Int_t ilay = 0; ilay < nLayers; ilay++){ - for (Int_t ieta = 0; ieta < nEtaPart; ieta++){ - nHitsEtaVV[ilay][ieta] /= nEvents; - for (Int_t iphi = 0; iphi < nPhiPart; iphi++){ - nHitsPhiVVV[ilay][ieta][iphi] /= nEvents; - } - } - } - - // initialize plot vectors - TH1FRefVec nHitsplots(nLayers); - TH1FRefVec etabinplots(nLayers); - TH1FRefVecVec phibinplots(nLayers); - for (Int_t ilay = 0; ilay < nLayers; ilay++){ - phibinplots[ilay].resize(nEtaPart); - } - - // make output subdirectory and subdir in ROOT file, and cd to it. - TString subdirname = "segment"; - PlotValidation::MakeSubDirectory(subdirname); - TDirectory * subdir = fOutRoot->mkdir(subdirname.Data()); - subdir->cd(); - - // new and fill! - for (Int_t ilay = 0; ilay < nLayers; ilay++){ - nHitsplots[ilay] = new TH1F(Form("h_nHits_perEtaPhiBin_lay%u",ilay),Form("nHits per EtaPhiBin (Layer: %u)",ilay),20,0,20); - nHitsplots[ilay]->GetXaxis()->SetTitle("nHits per EtaPhiBin"); - nHitsplots[ilay]->GetYaxis()->SetTitle("nEtaPhiBins"); - - etabinplots[ilay] = new TH1F(Form("h_nHits_vs_etabin_lay%u",ilay),Form("nHits vs EtaBin (Layer: %u)",ilay),nEtaPart,0,nEtaPart); - etabinplots[ilay]->GetXaxis()->SetTitle("Eta Bin Number"); - etabinplots[ilay]->GetYaxis()->SetTitle("nHits in Eta Bin"); - - for (Int_t ieta = 0; ieta < nEtaPart; ieta++){ - //fill the eta bin plots - etabinplots[ilay]->SetBinContent(ieta+1,nHitsEtaVV[ilay][ieta]); - - // eta-phi bin plots new - phibinplots[ilay][ieta] = new TH1F(Form("h_nHits_vs_phibin_lay%u_eta%u",ilay,ieta),Form("nHits vs PhiBin (Layer: %u, EtaBin: %u)",ilay,ieta),nPhiPart,0,nPhiPart); - phibinplots[ilay][ieta]->GetXaxis()->SetTitle("Phi Bin Number"); - phibinplots[ilay][ieta]->GetYaxis()->SetTitle("nHits in Phi Bin"); - - // fill eta-phi bin plots - for (Int_t iphi = 0; iphi < nPhiPart; iphi++){ - phibinplots[ilay][ieta]->SetBinContent(iphi+1,nHitsPhiVVV[ilay][ieta][iphi]); - nHitsplots[ilay]->Fill(nHitsPhiVVV[ilay][ieta][iphi]); - } - } - } - - // write out the individual plots to the root file - for (Int_t ilay = 0; ilay < nLayers; ilay++){ - PlotValidation::WriteTH1FPlot(subdir,nHitsplots[ilay]); - PlotValidation::WriteTH1FPlot(subdir,etabinplots[ilay]); - for (Int_t ieta = 0; ieta < nEtaPart; ieta++){ - PlotValidation::WriteTH1FPlot(subdir,phibinplots[ilay][ieta]); - } - } - - /////////////////////////////// - // Plot segment results here // - /////////////////////////////// - - // first do the nHits plot - fTH1Canv->cd(); - fTH1Canv->SetLogy(0); - - Float_t max = 0; - for (Int_t ilay = 0; ilay < nLayers; ilay++){ - Float_t tmpmax = nHitsplots[ilay]->GetBinContent(nHitsplots[ilay]->GetMaximumBin()); - if (tmpmax > max) { - max = tmpmax; - } - } - - // overplot - TLegend * legnhit = new TLegend(0.75,0.7,0.9,0.9); - for (Int_t ilay = 0; ilay < nLayers; ilay++){ - nHitsplots[ilay]->SetStats(0); - nHitsplots[ilay]->SetTitle("Average nHits per Event per EtaPhiBin for All Layers"); - nHitsplots[ilay]->SetMaximum(1.1*max); - nHitsplots[ilay]->SetLineColor(fColors[ilay%fColorSize]+(ilay/fColorSize)); // allow colors to loop over base! - nHitsplots[ilay]->SetLineWidth(2); - nHitsplots[ilay]->Draw((ilay>0)?"SAME":""); - legnhit->AddEntry(nHitsplots[ilay],Form("Layer %u",ilay),"L"); - } - legnhit->Draw("SAME"); - fTH1Canv->SaveAs(Form("%s/%s/nHits_perEtaPhiBin_allLayers.%s",fOutName.Data(),subdirname.Data(),fOutType.Data())); - for (Int_t ilay = 0; ilay < nLayers; ilay++){ // delete all histos, including layers not filled in - delete nHitsplots[ilay]; - } - delete legnhit; - - // now we want to overplot the eta plots second - max = 0; - for (Int_t ilay = 0; ilay < nLayers; ilay++){ - Float_t tmpmax = etabinplots[ilay]->GetBinContent(etabinplots[ilay]->GetMaximumBin()); - if (tmpmax > max) { - max = tmpmax; - } - } - - // overplot - TLegend * legeta = new TLegend(0.75,0.7,0.9,0.9); - for (Int_t ilay = 0; ilay < nLayers; ilay++){ - etabinplots[ilay]->SetStats(0); - etabinplots[ilay]->SetTitle("Average nHits per Event vs EtaBin for All Layers"); - etabinplots[ilay]->SetMaximum(1.1*max); - etabinplots[ilay]->SetLineColor(fColors[ilay%fColorSize]+(ilay/fColorSize)); // allow colors to loop over base! - etabinplots[ilay]->SetLineWidth(2); - etabinplots[ilay]->Draw((ilay>0)?"SAME":""); - legeta->AddEntry(etabinplots[ilay],Form("Layer %u",ilay),"L"); - } - legeta->Draw("SAME"); - fTH1Canv->SaveAs(Form("%s/%s/nHits_vs_Etabin_allLayers.%s",fOutName.Data(),subdirname.Data(),fOutType.Data())); - for (Int_t ilay = 0; ilay < nLayers; ilay++){ // delete all histos, including layers not filled in - delete etabinplots[ilay]; - } - delete legeta; - - // now we want to overplot the phi plots second ... a bit more complicated - // first do the phi bin plots for a given eta bin, overplot layer - // then do the phi bin plots for a given layer, overplot eta bin - - // so fix the eta bin, then overplot layers - for (Int_t ieta = 0; ieta < nEtaPart; ieta++){ - Float_t max = 0; - for (Int_t ilay = 0; ilay < nLayers; ilay++){ - Float_t tmpmax = phibinplots[ilay][ieta]->GetBinContent(phibinplots[ilay][ieta]->GetMaximumBin()); - if (tmpmax > max) { - max = tmpmax; - } - } - - // overplot - TLegend * legphi = new TLegend(0.75,0.7,0.9,0.9); - for (Int_t ilay = 0; ilay < nLayers; ilay++){ - phibinplots[ilay][ieta]->SetStats(0); - phibinplots[ilay][ieta]->SetTitle(Form("Average nHits per Event vs PhiBin for All Layers (EtaBin: %u)",ieta)); - phibinplots[ilay][ieta]->SetMaximum(1.1*max); - phibinplots[ilay][ieta]->SetLineColor(fColors[ilay%fColorSize]+(ilay/fColorSize)); // allow colors to loop over base! - phibinplots[ilay][ieta]->SetLineWidth(2); - phibinplots[ilay][ieta]->Draw((ilay>0)?"SAME":""); - legphi->AddEntry(phibinplots[ilay][ieta],Form("Layer %u",ilay),"L"); - } - legphi->Draw("SAME"); - fTH1Canv->SaveAs(Form("%s/%s/nHits_vs_Phibin_allLayers_etabin%u.%s",fOutName.Data(),subdirname.Data(),ieta,fOutType.Data())); - delete legphi; - } - - // now fix layer, overplot eta bins - for (Int_t ilay = 0; ilay < nLayers; ilay++){ - Float_t max = 0; - for (Int_t ieta = 0; ieta < nEtaPart; ieta++){ - Float_t tmpmax = phibinplots[ilay][ieta]->GetBinContent(phibinplots[ilay][ieta]->GetMaximumBin()); - if (tmpmax > max) { - max = tmpmax; - } - } - - // overplot - TLegend * legphi = new TLegend(0.75,0.7,0.9,0.9); - for (Int_t ieta = 0; ieta < nEtaPart; ieta++){ - phibinplots[ilay][ieta]->SetStats(0); - phibinplots[ilay][ieta]->SetTitle(Form("Average nHits per Event vs PhiBin for All EtaBins (Layer: %u)",ilay)); - phibinplots[ilay][ieta]->SetMaximum(1.1*max); - phibinplots[ilay][ieta]->SetLineColor(fColors[ieta%fColorSize]+(ieta/fColorSize)); // allow colors to loop over base! - phibinplots[ilay][ieta]->SetLineWidth(2); - phibinplots[ilay][ieta]->Draw((ieta>0)?"SAME":""); - legphi->AddEntry(phibinplots[ilay][ieta],Form("EtaBin %u",ieta),"L"); - } - legphi->Draw("SAME"); - fTH1Canv->SaveAs(Form("%s/%s/nHits_vs_Phibin_allEtaBins_layer%u.%s",fOutName.Data(),subdirname.Data(),ilay,fOutType.Data())); - delete legphi; - } - - for (Int_t ilay = 0; ilay < nLayers; ilay++){ - for (Int_t ieta = 0; ieta < nEtaPart; ieta++){ - delete phibinplots[ilay][ieta]; - } - } - - delete configtree; - delete segtree; -} - -void PlotValidation::PlotBranching(){ - // Get tree - TTree * tree_br = (TTree*)fInRoot->Get("tree_br"); - - // Get config tree for printing out info - TTree * configtree = (TTree*)fInRoot->Get("configtree"); // use to get nLayers - Int_t nLayers = 0; - Int_t nlayers_per_seed = 0; - Int_t nEvents = 0; - configtree->SetBranchAddress("nLayers",&nLayers); - configtree->SetBranchAddress("nlayers_per_seed",&nlayers_per_seed); - configtree->SetBranchAddress("Nevents",&nEvents); - configtree->GetEntry(0); - - // make output subdirectory and subdir in ROOT file, and cd to it. - TString subdirname = "branching"; - PlotValidation::MakeSubDirectory(subdirname); - TDirectory * subdir = fOutRoot->mkdir(subdirname.Data()); - subdir->cd(); - - // make plots, ensure in right directory - TH2F * laycands = new TH2F("h_lay_vs_cands","Layer vs nCandidates",20,0,20,nLayers,0,nLayers); - laycands->GetXaxis()->SetTitle("nInputCands / Layer / Seed"); - laycands->GetYaxis()->SetTitle("Layer"); - - TH2F * layetaphibins = new TH2F("h_lay_vs_etaphibins","Layer vs nEtaPhiBins",20,0,20,nLayers,0,nLayers); - layetaphibins->GetXaxis()->SetTitle("Total nEtaPhiBins Explored / Layer / Seed"); - layetaphibins->GetYaxis()->SetTitle("Layer"); - TH2F * layhits = new TH2F("h_lay_vs_hits","Layer vs nHits",50,0,50,nLayers,0,nLayers); - layhits->GetXaxis()->SetTitle("Total nHits Explored / Layer / Seed"); - layhits->GetYaxis()->SetTitle("Layer"); - TH2F * laybranches = new TH2F("h_lay_vs_branches","Layer vs nBranches",20,0,20,nLayers,0,nLayers); - laybranches->GetXaxis()->SetTitle("Total nTempCandBranches Produced / Layer / Seed"); - laybranches->GetYaxis()->SetTitle("Layer"); - - TH2F * layetaphibins_unique = new TH2F("h_lay_vs_etaphibins_unique","Layer vs nUniqueEtaPhiBins",20,0,20,nLayers,0,nLayers); - layetaphibins_unique->GetXaxis()->SetTitle("Total nUniqueEtaPhiBins Explored / Layer / Seed"); - layetaphibins_unique->GetYaxis()->SetTitle("Layer"); - TH2F * layhits_unique = new TH2F("h_lay_vs_hits_unique","Layer vs nUniqueHits",50,0,50,nLayers,0,nLayers); - layhits_unique->GetXaxis()->SetTitle("Total nUniqueHits Explored / Layer / Seed"); - layhits_unique->GetYaxis()->SetTitle("Layer"); - TH2F * laybranches_unique = new TH2F("h_lay_vs_braches_unique","Layer vs nUniqueBranches",20,0,20,nLayers,0,nLayers); - laybranches_unique->GetXaxis()->SetTitle("Total nTempCandUniqueBranches Produced / Layer / Seed"); - laybranches_unique->GetYaxis()->SetTitle("Layer"); - - TH2F * layetaphibins_percand = new TH2F("h_lay_vs_etaphibins_percand","Layer vs nEtaPhiBins per InputCand",20,0,20,nLayers,0,nLayers); - layetaphibins_percand->GetXaxis()->SetTitle("nEtaPhiBins Explored per InputCand / Layer / Seed"); - layetaphibins_percand->GetYaxis()->SetTitle("Layer"); - TH2F * layhits_percand = new TH2F("h_lay_vs_hits_percand","Layer vs nHits per InputCand",50,0,50,nLayers,0,nLayers); - layhits_percand->GetXaxis()->SetTitle("nHits Explored per InputCand / Layer / Seed"); - layhits_percand->GetYaxis()->SetTitle("Layer"); - TH2F * laybranches_percand = new TH2F("h_lay_vs_branches_percand","Layer vs nBranches per InputCand",20,0,20,nLayers,0,nLayers); - laybranches_percand->GetXaxis()->SetTitle("nTempCandBranches Produced per InputCand / Layer / Seed"); - laybranches_percand->GetYaxis()->SetTitle("Layer"); - - // scaled to 1/nEvents - TH1FRefVec etaphibins_percand(nLayers); - TH1FRefVec hits_percand(nLayers); - - for (Int_t layer = 0; layer < nLayers; layer++){ - etaphibins_percand[layer] = new TH1F(Form("h_etaphibins_percand_lay%u",layer),Form("Average nEtaPhiBins per InputCand per Event (Layer %u)",layer),20,0,20); - etaphibins_percand[layer]->GetXaxis()->SetTitle("nEtaPhiBins Explored per InputCand / Seed"); - etaphibins_percand[layer]->GetYaxis()->SetTitle("Cands"); - - hits_percand[layer] = new TH1F(Form("h_hits_percand_lay%u",layer),Form("Average nHits per InputCand (Layer %u) per Event",layer),20,0,20); - hits_percand[layer]->GetXaxis()->SetTitle("nHits Explored per InputCand / Seed"); - hits_percand[layer]->GetYaxis()->SetTitle("Cands"); - } - - TH2F * layetaphibins_percand_norm = new TH2F("h_lay_vs_etaphibins_percand_norm","Layer vs nEtaPhiBins per InputCand (Normalized)",20,0,20,nLayers,0,nLayers); - layetaphibins_percand_norm->GetXaxis()->SetTitle("nEtaPhiBins Explored per InputCand / Layer / Seed"); - layetaphibins_percand_norm->GetYaxis()->SetTitle("Layer (Normalized by nInputCands in Layer)"); - TH2F * layhits_percand_norm = new TH2F("h_lay_vs_hits_percand_norm","Layer vs nHits per InputCand (Normalized)",50,0,50,nLayers,0,nLayers); - layhits_percand_norm->GetXaxis()->SetTitle("nHits Explored per InputCand / Layer / Seed"); - layhits_percand_norm->GetYaxis()->SetTitle("Layer (Normalized by nInputCands / Layer)"); - TH2F * laybranches_percand_norm = new TH2F("h_lay_vs_branches_percand_norm","Layer vs nBranches per Cand (Normalized)",20,0,20,nLayers,0,nLayers); - laybranches_percand_norm->GetXaxis()->SetTitle("nTempCandBranches Produced per InputCand / Layer / Seed"); - laybranches_percand_norm->GetYaxis()->SetTitle("Layer (Normalized by nInputCands / Layer)"); - - TH1FRefVec layNSigmaDeta(nLayers); - TH1FRefVec layNSigmaDphi(nLayers); - for (Int_t l = 0; l < nLayers; l++){ - layNSigmaDeta[l] = new TH1F(Form("h_lay_%u_nSigmaDeta",l),Form("Layer %u n#sigma_{#eta}#timesd#eta",l),100,0.0,0.1); - layNSigmaDeta[l]->GetXaxis()->SetTitle("n#sigma_{#eta}#timesd#eta / Layer / Seed"); - layNSigmaDeta[l]->GetYaxis()->SetTitle("nInputCands"); - - layNSigmaDphi[l] = new TH1F(Form("h_lay_%u_nSigmaDphi",l),Form("Layer %u n#sigma_{#phi}#timesd#phi",l),100,0.0,0.02); - layNSigmaDphi[l]->GetXaxis()->SetTitle("n#sigma_{#phi}#timesd#phi / Layer / Seed"); - layNSigmaDphi[l]->GetYaxis()->SetTitle("nInputCands"); - } - - // see comment in plotsimgeo about vectors. set up branches here - IntVecRef candEtaPhiBins = 0; - IntVecRef candHits = 0; - IntVecRef candBranches = 0; - - Int_t layer = 0; - Int_t nCands = 0; - - Int_t nCandEtaPhiBins = 0; // sum of vector - Int_t nCandHits = 0; // sum of vector - Int_t nCandBranches = 0; // sum of vector - - Int_t uniqueEtaPhiBins = 0; - Int_t uniqueHits = 0; - Int_t uniqueBranches = 0; - - FltVecRef candnSigmaDeta = 0; - FltVecRef candnSigmaDphi = 0; - - tree_br->SetBranchAddress("layer",&layer); - tree_br->SetBranchAddress("cands",&nCands); // n candidates for a seed - - tree_br->SetBranchAddress("candEtaPhiBins",&candEtaPhiBins); // vector stores n possible candidate eta/phi bins for any branch for a track candidate per seed ... sum up for a total per seed - tree_br->SetBranchAddress("candHits",&candHits); // vector stores n possible candidate hits for any branch for a track candidate per seed ... sum up for a total per seed - tree_br->SetBranchAddress("candBranches",&candBranches); // remember, from before was just a single number, now a vector. just sum up vector to get total branches before puning as before - - tree_br->SetBranchAddress("uniqueEtaPhiBins",&uniqueEtaPhiBins); // total number of unique eta/phi bins explored per seed per layer over all input cands - tree_br->SetBranchAddress("uniqueHits",&uniqueHits); // total number of unique hits explored per seed per layer over all input cands - tree_br->SetBranchAddress("uniqueBranches",&uniqueBranches); // total number of unique hits used to create temp cands, plus at least one ghoster per seed per layer over all input cands - - tree_br->SetBranchAddress("candnSigmaDeta",&candnSigmaDeta); - tree_br->SetBranchAddress("candnSigmaDphi",&candnSigmaDphi); - - Int_t seedID = 0; - tree_br->SetBranchAddress("seedID",&seedID); - - for (Int_t k = 0; k < tree_br->GetEntries(); k++){ - tree_br->GetEntry(k); - - nCandEtaPhiBins = 0; - nCandHits = 0; - nCandBranches = 0; - - for (Int_t c = 0; c < nCands; c++){ // cands (unless we really screwed up) equals candBranches.size() == candHits.size() - layNSigmaDeta[layer]->Fill((*candnSigmaDeta)[c]); - layNSigmaDphi[layer]->Fill((*candnSigmaDphi)[c]); - - layetaphibins_percand->Fill((*candEtaPhiBins)[c],layer); - layhits_percand->Fill((*candHits)[c],layer); - - etaphibins_percand[layer]->Fill((*candEtaPhiBins)[c]); - laybranches_percand->Fill((*candBranches)[c],layer); - - nCandEtaPhiBins += (*candEtaPhiBins)[c]; - nCandHits += (*candHits)[c]; - nCandBranches += (*candBranches)[c]; - } - - laycands->Fill(nCands,layer); - - layetaphibins->Fill(nCandEtaPhiBins,layer); - layhits->Fill(nCandHits,layer); - laybranches->Fill(nCandBranches,layer); - - layetaphibins_unique->Fill(uniqueEtaPhiBins,layer); - layhits_unique->Fill(uniqueHits,layer); - laybranches_unique->Fill(uniqueBranches,layer); - } - - //////////////////////////////////////////////////// - // Write out the per event projection plots first // - //////////////////////////////////////////////////// - - // write out the individual plots to the root file ... scale first to nEvents, then input cands - for (Int_t ilay = nlayers_per_seed; ilay < nLayers; ilay++){ - PlotValidation::WriteTH1FPlot(subdir,etaphibins_percand[ilay]); - PlotValidation::WriteTH1FPlot(subdir,hits_percand[ilay]); - - // scale to input cands - etaphibins_percand[ilay]->Scale(1./etaphibins_percand[ilay]->Integral()); - hits_percand[ilay]->Scale(1./hits_percand[ilay]->Integral()); - } - - // first do the etaphibin plots - fTH1Canv->cd(); - fTH1Canv->SetLogy(0); - - Float_t max = 0; - for (Int_t ilay = nlayers_per_seed; ilay < nLayers; ilay++){ - Float_t tmpmax = etaphibins_percand[ilay]->GetBinContent(etaphibins_percand[ilay]->GetMaximumBin()); - if (tmpmax > max) { - max = tmpmax; - } - } - - // overplot - TLegend * legetaphibins = new TLegend(0.75,0.7,0.9,0.9); - for (Int_t ilay = nlayers_per_seed; ilay < nLayers; ilay++){ - etaphibins_percand[ilay]->SetStats(0); - etaphibins_percand[ilay]->SetTitle("EtaPhiBins per InputCand for All Layers (Normalized)"); - etaphibins_percand[ilay]->SetMaximum(1.1*max); - etaphibins_percand[ilay]->SetLineColor(fColors[(ilay-nlayers_per_seed)%fColorSize]+(ilay/fColorSize)); // allow colors to loop over base! - etaphibins_percand[ilay]->SetLineWidth(2); - etaphibins_percand[ilay]->Draw((ilay>nlayers_per_seed)?"SAME":""); - legetaphibins->AddEntry(etaphibins_percand[ilay],Form("Layer %u",ilay),"L"); - } - legetaphibins->Draw("SAME"); - fTH1Canv->SaveAs(Form("%s/%s/normalized_etaphibins_percand_allLayers.%s",fOutName.Data(),subdirname.Data(),fOutType.Data())); - for (Int_t ilay = nlayers_per_seed; ilay < nLayers; ilay++){ // delete all histos, including layers not filled in - delete etaphibins_percand[ilay]; - } - delete legetaphibins; - - // second do the nhits plots - max = 0; - for (Int_t ilay = nlayers_per_seed; ilay < nLayers; ilay++){ - Float_t tmpmax = hits_percand[ilay]->GetBinContent(hits_percand[ilay]->GetMaximumBin()); - if (tmpmax > max) { - max = tmpmax; - } - } - - // overplot - TLegend * leghits = new TLegend(0.75,0.7,0.9,0.9); - for (Int_t ilay = nlayers_per_seed; ilay < nLayers; ilay++){ - hits_percand[ilay]->SetStats(0); - hits_percand[ilay]->SetTitle("Hits per InputCand for All Layers (Normalized)"); - hits_percand[ilay]->SetMaximum(1.1*max); - hits_percand[ilay]->SetLineColor(fColors[(ilay-nlayers_per_seed)%fColorSize]+(ilay/fColorSize)); // allow colors to loop over base! - hits_percand[ilay]->SetLineWidth(2); - hits_percand[ilay]->Draw((ilay>nlayers_per_seed)?"SAME":""); - leghits->AddEntry(hits_percand[ilay],Form("Layer %u",ilay),"L"); - } - leghits->Draw("SAME"); - fTH1Canv->SaveAs(Form("%s/%s/normalized_nhits_percand_allLayers.%s",fOutName.Data(),subdirname.Data(),fOutType.Data())); - for (Int_t ilay = nlayers_per_seed; ilay < nLayers; ilay++){ // delete all histos, including layers not filled in - delete hits_percand[ilay]; - } - delete leghits; - - // Loop over layers first, then sum up entries in each bin stepping left to right (INCLUDE OVERFLOW!) - // root conventions means we have vectors offset by 1 - IntVec etaphibins_laycount(nLayers+1); - IntVec hits_laycount(nLayers+1); - IntVec branches_laycount(nLayers+1); - - for (Int_t lay = 1; lay <= Int_t(nLayers); lay++){ - etaphibins_laycount[lay] = 0; - hits_laycount[lay] = 0; - branches_laycount[lay] = 0; - - //etaphi - for (Int_t xbin = 1; xbin <= layetaphibins_percand->GetNbinsX()+1; xbin++){ // root bins start at 1, then go up to including nBins, plus want overflows to properly normalize - etaphibins_laycount[lay] += layetaphibins_percand->GetBinContent(xbin,lay); - } - //hits - for (Int_t xbin = 1; xbin <= layhits_percand->GetNbinsX()+1; xbin++){ // root bins start at 1, then go up to including nBins, plus want overflows to properly normalize - hits_laycount[lay] += layhits_percand->GetBinContent(xbin,lay); - } - //branches - for (Int_t xbin = 1; xbin <= laybranches_percand->GetNbinsX()+1; xbin++){ // root bins start at 1, then go up to including nBins, plus want overflows to properly normalize - branches_laycount[lay] += laybranches_percand->GetBinContent(xbin,lay); - } - } - - //now fill the plots appropriately scaled - for (Int_t lay = 1; lay <= Int_t(nLayers); lay++){ - // fill norm etaphi - for (Int_t xbin = 1; xbin <= layetaphibins_percand_norm->GetNbinsX()+1; xbin++){ // normalize the overflow! - if (!(etaphibins_laycount[lay] == 0)){ - layetaphibins_percand_norm->SetBinContent(xbin,lay,Float_t(layetaphibins_percand->GetBinContent(xbin,lay))/Float_t(etaphibins_laycount[lay])); - } - } - // fill norm hits - for (Int_t xbin = 1; xbin <= layhits_percand_norm->GetNbinsX()+1; xbin++){ // normalize the overflow! - if (!(hits_laycount[lay] == 0)){ - layhits_percand_norm->SetBinContent(xbin,lay,Float_t(layhits_percand->GetBinContent(xbin,lay))/Float_t(hits_laycount[lay])); - } - } - // fill norm branches - for (Int_t xbin = 1; xbin <= laybranches_percand_norm->GetNbinsX()+1; xbin++){ // normalize the overflow! - if (!(branches_laycount[lay] == 0)){ - laybranches_percand_norm->SetBinContent(xbin,lay,Float_t(laybranches_percand->GetBinContent(xbin,lay))/Float_t(branches_laycount[lay])); - } - } - } - - const Int_t NRGBs = 5; - const Int_t NCont = 255; - - Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 }; - Double_t red[NRGBs] = { 0.00, 0.00, 0.87, 1.00, 0.51 }; - Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 }; - Double_t blue[NRGBs] = { 0.51, 1.00, 0.12, 0.00, 0.00 }; - TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont); - gStyle->SetNumberContours(NCont); - - PlotValidation::DrawWriteSaveTH2FPlot(subdir,laycands,subdirname,"lay_vs_cands"); - - PlotValidation::DrawWriteSaveTH2FPlot(subdir,layetaphibins,subdirname,"lay_vs_etaphibins"); - PlotValidation::DrawWriteSaveTH2FPlot(subdir,layhits,subdirname,"lay_vs_hits"); - PlotValidation::DrawWriteSaveTH2FPlot(subdir,laybranches,subdirname,"lay_vs_branches"); - - PlotValidation::WriteTH2FPlot(subdir,layetaphibins_percand); - PlotValidation::WriteTH2FPlot(subdir,layhits_percand); - PlotValidation::WriteTH2FPlot(subdir,laybranches_percand); - - PlotValidation::DrawWriteSaveTH2FPlot(subdir,layetaphibins_percand,subdirname,"lay_vs_etaphibins_percand"); - PlotValidation::DrawWriteSaveTH2FPlot(subdir,layhits_percand,subdirname,"lay_vs_hits_percand"); - PlotValidation::DrawWriteSaveTH2FPlot(subdir,laybranches_percand,subdirname,"lay_vs_branches_percand"); - - PlotValidation::DrawWriteSaveTH2FPlot(subdir,layetaphibins_percand_norm,subdirname,"lay_vs_etaphibins_percand_norm"); - PlotValidation::DrawWriteSaveTH2FPlot(subdir,layhits_percand_norm,subdirname,"lay_vs_hits_percand_norm"); - PlotValidation::DrawWriteSaveTH2FPlot(subdir,laybranches_percand_norm,subdirname,"lay_vs_branches_percand_norm"); - - PlotValidation::DrawWriteSaveTH2FPlot(subdir,layetaphibins_unique,subdirname,"lay_vs_etaphibins_unique"); - PlotValidation::DrawWriteSaveTH2FPlot(subdir,layhits_unique,subdirname,"lay_vs_hits_unique"); - PlotValidation::DrawWriteSaveTH2FPlot(subdir,laybranches_unique,subdirname,"lay_vs_branches_unique"); - - max = 0.0; - // write the bare plots, scale, and get max and min - for (Int_t l = nlayers_per_seed; l < nLayers; l++){ // only fill ones with actual propagation - PlotValidation::WriteTH1FPlot(subdir,layNSigmaDeta[l]); - layNSigmaDeta[l]->Scale(1.0/layNSigmaDeta[l]->Integral()); - Float_t tmpmax = layNSigmaDeta[l]->GetBinContent(layNSigmaDeta[l]->GetMaximumBin()); - if (tmpmax > max) { - max = tmpmax; - } - } - TLegend * legeta = new TLegend(0.75,0.7,0.9,0.9); - for (Int_t l = nlayers_per_seed; l < nLayers; l++){ // only fill ones with actual propagation and overplot - fTH1Canv->cd(); - layNSigmaDeta[l]->SetStats(0); - layNSigmaDeta[l]->SetTitle("n#sigma_{#eta}#timesd#eta for All Layers (Normalized)"); - layNSigmaDeta[l]->SetMaximum(1.1*max); - layNSigmaDeta[l]->SetLineColor(fColors[(l-nlayers_per_seed)%fColorSize]+(l/fColorSize)); // allow colors to loop! - layNSigmaDeta[l]->SetLineWidth(2); - layNSigmaDeta[l]->Draw((l>nlayers_per_seed)?"SAME":""); - legeta->AddEntry(layNSigmaDeta[l],Form("Layer %u",l),"L"); - } - fTH1Canv->cd(); - legeta->Draw("SAME"); - fTH1Canv->SetLogy(1); - fTH1Canv->SaveAs(Form("%s/%s/nSigmaDeta_layers.%s",fOutName.Data(),subdirname.Data(),fOutType.Data())); - for (Int_t l = 0; l < nLayers; l++){ // delete all histos, including layers not filled in - delete layNSigmaDeta[l]; - } - delete legeta; - - max = 0; - for (Int_t l = nlayers_per_seed; l < nLayers; l++){ // only fill ones with actual propagation - PlotValidation::WriteTH1FPlot(subdir,layNSigmaDphi[l]); - layNSigmaDphi[l]->Scale(1.0/layNSigmaDphi[l]->Integral()); - Float_t tmpmax = layNSigmaDphi[l]->GetBinContent(layNSigmaDphi[l]->GetMaximumBin()); - if (tmpmax > max) { - max = tmpmax; - } - } - TLegend * legphi = new TLegend(0.75,0.7,0.9,0.9); - // normalize all nsigma distributions automatically and write them - for (Int_t l = nlayers_per_seed; l < nLayers; l++){ // only fill ones with actual propagation - fTH1Canv->cd(); - layNSigmaDphi[l]->SetStats(0); - layNSigmaDphi[l]->SetTitle("n#sigma_{#phi}#timesd#phi for All Layers (Normalized)"); - layNSigmaDphi[l]->SetMaximum(1.1*max); - layNSigmaDphi[l]->SetLineColor(fColors[(l-nlayers_per_seed)%fColorSize]+(l/fColorSize)); // allow colors to loop! - layNSigmaDphi[l]->SetLineWidth(2); - layNSigmaDphi[l]->Draw((l>nlayers_per_seed)?"SAME":""); - legphi->AddEntry(layNSigmaDphi[l],Form("Layer %u",l),"L"); - } - fTH1Canv->cd(); - legphi->Draw("SAME"); - fTH1Canv->SetLogy(1); - fTH1Canv->SaveAs(Form("%s/%s/nSigmaDphi_layers.%s",fOutName.Data(),subdirname.Data(),fOutType.Data())); - for (Int_t l = 0; l < nLayers; l++){ // delete all histos, including layers not filled in - delete layNSigmaDphi[l]; - } - delete legphi; - - delete laycands; - - delete layetaphibins; - delete layhits; - delete laybranches; - - delete layetaphibins_percand; - delete laybranches_percand; - delete layhits_percand; - - delete layetaphibins_percand_norm; - delete laybranches_percand_norm; - delete layhits_percand_norm; - - delete layetaphibins_unique; - delete laybranches_unique; - delete layhits_unique; - - delete configtree; - delete tree_br; -} - -void PlotValidation::PlotSimGeo(){ - // Get tree - TTree * geotree = (TTree*)fInRoot->Get("geotree"); - - // make output subdirectory and subdir in ROOT file, and cd to it. - TString subdirname = "simgeo"; - PlotValidation::MakeSubDirectory(subdirname); - TDirectory * subdir = fOutRoot->mkdir(subdirname.Data()); - subdir->cd(); - - // make plots, ensure in right directory - TH2F * xy_detplot = new TH2F("h_xy_simdetgeo","XY Simulation Detector Geometry",450,-45.,45.,450,-45.,45.); - xy_detplot->GetXaxis()->SetTitle("x [cm]"); - xy_detplot->GetYaxis()->SetTitle("y [cm]"); - TH2F * rz_detplot = new TH2F("h_rz_simdetgeo","RZ Simulation Detector Geometry",500,-50.,50.,225,0.,45.); - rz_detplot->GetXaxis()->SetTitle("z [cm]"); - rz_detplot->GetYaxis()->SetTitle("radius [cm]"); - - TH2F * xy_vrxplot = new TH2F("h_xy_simvrxgeo","XY Simulation Beamspot Geometry",500,-0.5,0.5,500,-0.5,0.5); - xy_vrxplot->GetXaxis()->SetTitle("x [cm]"); - xy_vrxplot->GetYaxis()->SetTitle("y [cm]"); - TH2F * rz_vrxplot = new TH2F("h_rz_simvrxgeo","RZ Simulation Beamspot Geometry",500,-5.0,5.0,225,0.,0.5); - rz_vrxplot->GetXaxis()->SetTitle("z [cm]"); - rz_vrxplot->GetYaxis()->SetTitle("radius [cm]"); - - // set hit branches ... need to use pointers for vectors. I thought ROOT5 fixed this?? - FltVecRef xhit = new FltVec(); - FltVecRef yhit = new FltVec(); - FltVecRef zhit = new FltVec(); - - Float_t xvrx = 0.; - Float_t yvrx = 0.; - Float_t zvrx = 0.; - - geotree->SetBranchAddress("x_mc_reco_hit",&xhit); - geotree->SetBranchAddress("y_mc_reco_hit",&yhit); - geotree->SetBranchAddress("z_mc_reco_hit",&zhit); - - geotree->SetBranchAddress("x_mc_gen_vrx",&xvrx); - geotree->SetBranchAddress("y_mc_gen_vrx",&yvrx); - geotree->SetBranchAddress("z_mc_gen_vrx",&zvrx); - - for (Int_t k = 0; k < geotree->GetEntries(); k++){ - geotree->GetEntry(k); - for (UInt_t h = 0; h < xhit->size(); h++){ // x,y,z are all the same size - Float_t radius = std::sqrt( ((*xhit)[h])*((*xhit)[h]) + ((*yhit)[h])*((*yhit)[h]) ); - xy_detplot->Fill((*xhit)[h],(*yhit)[h]); - rz_detplot->Fill((*zhit)[h],radius); - - Float_t radius_vrx = std::sqrt(xvrx*xvrx + yvrx*yvrx); - xy_vrxplot->Fill(xvrx,yvrx); - rz_vrxplot->Fill(zvrx,radius_vrx); - } - } - - // before plotting set the canvas size to be square 1000x1000 - fTH2Canv->SetCanvasSize(1000,1000); - PlotValidation::DrawWriteSaveTH2FPlot(subdir,xy_detplot,subdirname,"xy_simulation_detgeometry"); - PlotValidation::DrawWriteSaveTH2FPlot(subdir,rz_detplot,subdirname,"rz_simulation_detgeometry"); - PlotValidation::DrawWriteSaveTH2FPlot(subdir,xy_vrxplot,subdirname,"xy_simulation_vrxgeometry"); - PlotValidation::DrawWriteSaveTH2FPlot(subdir,rz_vrxplot,subdirname,"rz_simulation_vrxgeometry"); - - delete xhit; - delete yhit; - delete zhit; - - delete xy_detplot; - delete rz_detplot; - delete xy_vrxplot; - delete rz_vrxplot; - - delete geotree; -} - -void PlotValidation::PlotPosResolutionPull(){ - // get tree - TTree * geotree = (TTree*)fInRoot->Get("geotree"); - - // get nLayers - TTree * configtree = (TTree*)fInRoot->Get("configtree"); - Int_t nlayers_per_seed = 0; - Int_t nLayers = 0; - configtree->SetBranchAddress("nlayers_per_seed",&nlayers_per_seed); - configtree->SetBranchAddress("nLayers",&nLayers); - configtree->GetEntry(0); - - // make output subdirectory and subdir in ROOT file, and cd to it. - TString subdirname = "position_resolutionpull"; - PlotValidation::MakeSubDirectory(subdirname); - PlotValidation::MakeSubDirectory(Form("%s/lin",subdirname.Data())); - PlotValidation::MakeSubDirectory(Form("%s/log",subdirname.Data())); - TDirectory * subdir = fOutRoot->mkdir(subdirname.Data()); - subdir->cd(); - - //Declare strings for branches and plots - TStrVec vars = {"x","y","z"}; - TStrVec evars = {"ex","ey","ez"}; - TStrVec svars = {"x","y","z"}; // svars --> labels for histograms for given variable - TStrVec sunits = {" [cm]"," [cm]"," [cm]"}; // svars --> labels for histograms for given variable - IntVec nBinsRes = {100,100,100}; - FltVec xlowRes = {-0.5,-0.5,-0.5}; - FltVec xhighRes = {0.5,0.5,0.5}; - FltVec gausRes = {0.3,0.3,0.3}; // symmetric bounds for gaussian fit - IntVec nBinsPull = {100,100,100}; - FltVec xlowPull = {-5,-5,-5}; - FltVec xhighPull = {5,5,5}; - FltVec gausPull = {3,3,3}; // symmetric bounds for gaussian fit - - TStrVec trks = {"seed","fit"}; - TStrVec strks = {"Seed","Fit"}; // strk --> labels for histograms for given track type - - IntVec nlayers_trk = {nlayers_per_seed, nLayers}; // want to resize just enough space - - // Create pos plots - TH1FRefVecVecVec varsResPlot(trks.size()); // in this case, outer layer is tracks, then variable, then by layer - TH1FRefVecVecVec varsPullPlot(trks.size()); - - for (UInt_t j = 0; j < trks.size(); j++){ - varsResPlot[j].resize(vars.size()); - varsPullPlot[j].resize(vars.size()); - for (UInt_t i = 0; i < vars.size(); i++){ - varsResPlot[j][i].resize(nlayers_trk[j]); - varsPullPlot[j][i].resize(nlayers_trk[j]); - } - } - - for (UInt_t j = 0; j < trks.size(); j++){ - for (UInt_t i = 0; i < vars.size(); i++){ - for (Int_t l = 0; l < nlayers_trk[j]; l++){ - //Res - varsResPlot[j][i][l] = new TH1F(Form("h_%s_res_lay_%u_%s",vars[i].Data(),l,trks[j].Data()),Form("%s Resolution Layer %u (%s Track vs. MC Track)",svars[i].Data(),l,strks[j].Data()),nBinsRes[i],xlowRes[i],xhighRes[i]); - varsResPlot[j][i][l]->GetXaxis()->SetTitle(Form("(%s^{%s}%s - %s^{mc}%s)/%s^{mc}%s",svars[i].Data(),strks[j].Data(),sunits[i].Data(),svars[i].Data(),sunits[i].Data(),svars[i].Data(),sunits[i].Data())); - varsResPlot[j][i][l]->GetYaxis()->SetTitle("nTracks"); - - //Pull - varsPullPlot[j][i][l] = new TH1F(Form("h_%s_pull_lay_%u_%s",vars[i].Data(),l,trks[j].Data()),Form("%s Pull Layer %u (%s Track vs. MC Track)",svars[i].Data(),l,strks[j].Data()),nBinsPull[i],xlowPull[i],xhighPull[i]); - varsPullPlot[j][i][l]->GetXaxis()->SetTitle(Form("(%s^{%s}%s - %s^{mc}%s)/#sigma(%s^{%s})%s",svars[i].Data(),strks[j].Data(),sunits[i].Data(),svars[i].Data(),sunits[i].Data(),svars[i].Data(),strks[j].Data(),sunits[i].Data())); - varsPullPlot[j][i][l]->GetYaxis()->SetTitle("nTracks"); - } - } - } - - // Floats/Ints to be filled for trees - IntVecRefVec layers_trk(trks.size()); // only needed per track type - FltVecRefVecVec recovars_val(trks.size()); // first index is nVars, second is nTrkTypes - FltVecRefVecVec recovars_err(trks.size()); - for (UInt_t j = 0; j < trks.size(); j++){ - layers_trk[j] = new IntVec(); // initialize pointer - - recovars_val[j].resize(vars.size()); - recovars_err[j].resize(vars.size()); - for (UInt_t i = 0; i < vars.size(); i++){ - recovars_val[j][i] = new FltVec(); // initialize pointers - recovars_err[j][i] = new FltVec(); // initialize pointers - } - } - - IntVec mcmask_trk(trks.size()); // need to know if sim track associated to a given reco track type - FltVecRefVec mcvars_val(vars.size()); // good for all track types - for (UInt_t i = 0; i < vars.size(); i++){ - mcvars_val[i] = 0; // initialize pointers - } - FltVec vars_out = {0.,0.}; // res/pull output initialization - - //Initialize var_val/err arrays, SetBranchAddress - for (UInt_t j = 0; j < trks.size(); j++){ // loop over trks index - // get the layers needed for reco vars - geotree->SetBranchAddress(Form("layers_%s",trks[j].Data()),&layers_trk[j]); - geotree->SetBranchAddress(Form("mcmask_%s",trks[j].Data()),&(mcmask_trk[j])); - - for (UInt_t i = 0; i < vars.size(); i++){ // loop over var index - //Set var+trk branch - geotree->SetBranchAddress(Form("%s_lay_%s",vars[i].Data(),trks[j].Data()),&(recovars_val[j][i])); - geotree->SetBranchAddress(Form("%s_lay_%s",evars[i].Data(),trks[j].Data()),&(recovars_err[j][i])); - } - } - - for (UInt_t i = 0; i < vars.size(); i++){ // loop over var index - geotree->SetBranchAddress(Form("%s_mc_reco_hit",vars[i].Data()),&(mcvars_val[i])); - } - - // Fill histos, compute res/pull from tree branches - for (Int_t k = 0; k < geotree->GetEntries(); k++){ - geotree->GetEntry(k); - for (UInt_t j = 0; j < trks.size(); j++){ // loop over trks index - if (mcmask_trk[j] == 1){ // must be associated - for (UInt_t i = 0; i < vars.size(); i++){ // loop over vars index - for (UInt_t l = 0; l < layers_trk[j]->size(); l++){ // loop over layers, assuming one hit per layer - const Int_t layer = (*layers_trk[j])[l]; // layer we are on. - if (layer < 0) continue; - PlotValidation::ComputeResolutionPull((*mcvars_val[i])[layer],(*recovars_val[j][i])[l],(*recovars_err[j][i])[l],vars_out); // we assume one hit per layer and track is simulated to be built outward - if (!isnan(vars_out[0])){ // fill if not nan - varsResPlot[j][i][layer]->Fill(vars_out[0]); - } - if (!isnan(vars_out[1])){ // fill if not nan - varsPullPlot[j][i][layer]->Fill(vars_out[1]); - } - } - } // end loop over vars - } // must be a matched track to make resolution plots - } // end loop over trks - } // end loop over entry in tree - - // Draw, fit, and save plots - for (UInt_t j = 0; j < trks.size(); j++){ - for (UInt_t i = 0; i < vars.size(); i++){ - for (Int_t l = 0; l < nlayers_trk[j]; l++){ - PlotValidation::DrawWriteFitSaveTH1FPlot(subdir,varsResPlot[j][i][l],subdirname,Form("%s_resolution_lay%u_%s",vars[i].Data(),l,trks[j].Data()),gausRes[i]); - PlotValidation::DrawWriteFitSaveTH1FPlot(subdir,varsPullPlot[j][i][l],subdirname,Form("%s_pull_lay%u_%s",vars[i].Data(),l,trks[j].Data()),gausPull[i]); - delete varsResPlot[j][i][l]; - delete varsPullPlot[j][i][l]; - } - } - } - delete configtree; - delete geotree; -} - -void PlotValidation::PlotCFResidual(){ - // Get tree - TTree * cftree = (TTree*)fInRoot->Get("cftree"); - - // make output subdirectory and subdir in ROOT file, and cd to it. - TString subdirname = "conformalFit_residual"; - PlotValidation::MakeSubDirectory(subdirname); - PlotValidation::MakeSubDirectory(Form("%s/lin",subdirname.Data())); - PlotValidation::MakeSubDirectory(Form("%s/log",subdirname.Data())); - TDirectory * subdir = fOutRoot->mkdir(subdirname.Data()); - subdir->cd(); - - // Declare strings for branches and plots - // xyz, pxpypz residual, pt, theta, phi --> used to get errors, but only for pt, phi, theta. x,y,z,px,py,pz from simulation - TStrVec vars = {"x","y","z","px","py","pz","pt","invpt","phi","theta"}; // pt will be inverse - TStrVec svars = {"x","y","z","p_{x}","p_{y}","p_{z}","p_{T}","1/p_{T}","#phi","#theta"}; // svars --> labels for histograms for given variable - TStrVec sunits = {" [cm]"," [cm]"," [cm]"," [GeV/c]"," [GeV/c]"," [GeV/c]"," [GeV/c]"," [GeV/c]^{-1}","",""}; // svars --> labels for histograms for given variable - IntVec nBins = {100,100,100,100,100,100,100,100,100,100}; - FltVec xlow = {-0.05,-0.05,-0.5,-0.5,-0.5,-0.5,-0.5,-0.05,-0.05,-0.05}; - FltVec xhigh = {0.05,0.05,0.5,0.5,0.5,0.5,0.5,0.05,0.05,0.05}; - FltVec gaus = {0.03,0.03,0.3,0.3,0.3,0.3,0.3,0.03,0.03,0.03}; // symmetric bounds for gaussian fit - TStrVec trks = {"seed","fit"}; - TStrVec strks = {"Seed","Fit"}; // strk --> labels for histograms for given track type - - // Floats/Ints to be filled for trees - FltVecVec mcvars_val(vars.size()); - IntVec mcmask_trk(trks.size()); // need to know if sim track associated to a given reco track type - FltVecVec recovars_val(vars.size()); // first index is nVars, second is nTrkTypes - for (UInt_t i = 0; i < vars.size(); i++){ - mcvars_val[i].resize(trks.size()); - recovars_val[i].resize(trks.size()); - } - Float_t vars_out = 0.; // residual output - - // Create residual plots - TH1FRefVecVec varsResidualPlot(vars.size()); - for (UInt_t i = 0; i < vars.size(); i++){ - varsResidualPlot[i].resize(trks.size()); - } - - for (UInt_t i = 0; i < vars.size(); i++){ - for (UInt_t j = 0; j < trks.size(); j++){ - varsResidualPlot[i][j] = new TH1F(Form("h_%s_cfresidual_%s",vars[i].Data(),trks[j].Data()),Form("%s Residual (CF %s Track vs. MC Track)",svars[i].Data(),strks[j].Data()),nBins[i],xlow[i],xhigh[i]); - varsResidualPlot[i][j]->GetXaxis()->SetTitle(Form("%s^{CF %s}%s - %s^{mc}%s",svars[i].Data(),strks[j].Data(),sunits[i].Data(),svars[i].Data(),sunits[i].Data())); - varsResidualPlot[i][j]->GetYaxis()->SetTitle("nTracks"); - } - } - - //Initialize var_val/err arrays, SetBranchAddress - for (UInt_t i = 0; i < vars.size(); i++){ // loop over var index - for (UInt_t j = 0; j < trks.size(); j++){ // loop over trks index - // initialize var + errors - mcvars_val[i][j] = 0.; - recovars_val[i][j] = 0.; - - //Set var+trk branch - cftree->SetBranchAddress(Form("%s_mc_cf_%s",vars[i].Data(),trks[j].Data()),&(mcvars_val[i][j])); - cftree->SetBranchAddress(Form("%s_cf_%s",vars[i].Data(),trks[j].Data()),&(recovars_val[i][j])); - } - } - - //Initialize masks, set branch addresses - for (UInt_t j = 0; j < trks.size(); j++){ // loop over trks index - mcmask_trk[j] = 0; - cftree->SetBranchAddress(Form("mcmask_%s",trks[j].Data()),&(mcmask_trk[j])); - } - - // Fill histos, compute residual from tree branches - for (Int_t k = 0; k < cftree->GetEntries(); k++){ - cftree->GetEntry(k); - for (UInt_t i = 0; i < vars.size(); i++){ // loop over vars index - for (UInt_t j = 0; j < trks.size(); j++){ // loop over trks index - if (mcmask_trk[j] == 1){ // must be associated - PlotValidation::ComputeResidual(mcvars_val[i][j],recovars_val[i][j],vars_out); - if (!isnan(vars_out)){ // fill if not nan - varsResidualPlot[i][j]->Fill(vars_out); - } - } // must be a matched track to make resolution plots - } // end loop over trks - } // end loop over vars - } // end loop over entry in tree - - // Draw, fit, and save plots - for (UInt_t i = 0; i < vars.size(); i++){ - for (UInt_t j = 0; j < trks.size(); j++){ - PlotValidation::DrawWriteFitSaveTH1FPlot(subdir,varsResidualPlot[i][j],subdirname,Form("%s_cfresidual_%s",vars[i].Data(),trks[j].Data()),gaus[i]); - delete varsResidualPlot[i][j]; - } - } - delete cftree; -} - -void PlotValidation::PlotCFResolutionPull(){ - // Get tree - TTree * cftree = (TTree*)fInRoot->Get("cftree"); - - // make output subdirectory and subdir in ROOT file, and cd to it. - TString subdirname = "conformalFit_resolutionpull"; - PlotValidation::MakeSubDirectory(subdirname); - PlotValidation::MakeSubDirectory(Form("%s/lin",subdirname.Data())); - PlotValidation::MakeSubDirectory(Form("%s/log",subdirname.Data())); - TDirectory * subdir = fOutRoot->mkdir(subdirname.Data()); - subdir->cd(); - - // Declare strings for branches and plots - // xyz,pxpypz resolutions + pulls - TStrVec vars = {"x","y","z","px","py","pz","pt","invpt","phi","theta"}; - TStrVec svars = {"x","y","z","p_{x}","p_{y}","p_{z}","p_{T}","1/p_{T}","#phi","#theta"}; // svars --> labels for histograms for given variable - TStrVec sunits = {" [cm]"," [cm]"," [cm]"," [GeV/c]"," [GeV/c]"," [GeV/c]"," [GeV/c]"," [GeV/c]^{-1}","",""}; // svars --> labels for histograms for given variable - TStrVec evars = {"ex","ey","ez","epx","epy","epz","ept","einvpt","ephi","etheta"}; - TStrVec trks = {"seed","fit"}; - TStrVec strks = {"Seed","Fit"}; // strk --> labels for histograms for given track type - IntVec nBinsRes = {100,100,100,100,100,100,100,100,100,100}; - FltVec xlowRes = {-0.05,-0.05,-0.5,-0.5,-0.5,-0.5,-0.5,-0.5,-0.5,-0.5}; - FltVec xhighRes = {0.05,0.05,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5}; - FltVec gausRes = {0.03,0.03,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3}; // symmetric bounds for gaussian fit - IntVec nBinsPull = {100,100,100,100,100,100,100,100,100,100}; - FltVec xlowPull = {-5,-5,-5,-5,-5,-5,-5,-5,-5,-5}; - FltVec xhighPull = {5,5,5,5,5,5,5,5,5,5}; - FltVec gausPull = {3,3,3,3,3,3,3,3,3,3}; // symmetric bounds for gaussian fit - - // Floats/Ints to be filled for trees - FltVecVec mcvars_val(vars.size()); - IntVec mcmask_trk(trks.size()); // need to know if sim track associated to a given reco track type - FltVecVec recovars_val(vars.size()); // first index is nVars, second is nTrkTypes - FltVecVec recovars_err(vars.size()); - for (UInt_t i = 0; i < vars.size(); i++){ - mcvars_val[i].resize(trks.size()); - recovars_val[i].resize(trks.size()); - recovars_err[i].resize(trks.size()); - } - FltVec vars_out = {0.,0.}; // res/pull output - - // Create pos plots - TH1FRefVecVec varsResPlot(vars.size()); - TH1FRefVecVec varsPullPlot(vars.size()); - for (UInt_t i = 0; i < vars.size(); i++){ - varsResPlot[i].resize(trks.size()); - varsPullPlot[i].resize(trks.size()); - } - - for (UInt_t i = 0; i < vars.size(); i++){ - for (UInt_t j = 0; j < trks.size(); j++){ - //Res - varsResPlot[i][j] = new TH1F(Form("h_%s_cfres_%s",vars[i].Data(),trks[j].Data()),Form("%s Resolution (CF %s Track vs. MC Track)",svars[i].Data(),strks[j].Data()),nBinsRes[i],xlowRes[i],xhighRes[i]); - varsResPlot[i][j]->GetXaxis()->SetTitle(Form("(%s^{CF %s}%s - %s^{mc}%s)/%s^{mc}%s",svars[i].Data(),strks[j].Data(),sunits[i].Data(),svars[i].Data(),sunits[i].Data(),svars[i].Data(),sunits[i].Data())); - varsResPlot[i][j]->GetYaxis()->SetTitle("nTracks"); - - //Pull - varsPullPlot[i][j] = new TH1F(Form("h_%s_cfpull_%s",vars[i].Data(),trks[j].Data()),Form("%s Pull (CF %s Track vs. MC Track)",svars[i].Data(),strks[j].Data()),nBinsPull[i],xlowPull[i],xhighPull[i]); - varsPullPlot[i][j]->GetXaxis()->SetTitle(Form("(%s^{CF %s}%s - %s^{mc}%s)/#sigma(%s^{CF %s})%s",svars[i].Data(),strks[j].Data(),sunits[i].Data(),svars[i].Data(),sunits[i].Data(),svars[i].Data(),strks[j].Data(),sunits[i].Data())); - varsPullPlot[i][j]->GetYaxis()->SetTitle("nTracks"); - } - } - - //Initialize var_val/err arrays, SetBranchAddress - for (UInt_t i = 0; i < vars.size(); i++){ // loop over var index - for (UInt_t j = 0; j < trks.size(); j++){ // loop over trks index - // initialize var + errors - mcvars_val[i][j] = 0.; - recovars_val[i][j] = 0.; - recovars_err[i][j] = 0.; - - //Set var+trk branch - cftree->SetBranchAddress(Form("%s_mc_cf_%s",vars[i].Data(),trks[j].Data()),&(mcvars_val[i][j])); - cftree->SetBranchAddress(Form("%s_cf_%s",vars[i].Data(),trks[j].Data()),&(recovars_val[i][j])); - cftree->SetBranchAddress(Form("%s_cf_%s",evars[i].Data(),trks[j].Data()),&(recovars_err[i][j])); - } - } - - //Initialize masks, set branch addresses - for (UInt_t j = 0; j < trks.size(); j++){ // loop over trks index - mcmask_trk[j] = 0; - cftree->SetBranchAddress(Form("mcmask_%s",trks[j].Data()),&(mcmask_trk[j])); - } - - // Fill histos, compute res/pull from tree branches - for (Int_t k = 0; k < cftree->GetEntries(); k++){ - cftree->GetEntry(k); - for (UInt_t i = 0; i < vars.size(); i++){ // loop over vars index - for (UInt_t j = 0; j < trks.size(); j++){ // loop over trks index - if (mcmask_trk[j] == 1){ // must be associated - PlotValidation::ComputeResolutionPull(mcvars_val[i][j],recovars_val[i][j],recovars_err[i][j],vars_out); - if (!isnan(vars_out[0])){ // fill if not nan - varsResPlot[i][j]->Fill(vars_out[0]); - } - if (!isnan(vars_out[1])){ // fill if not nan - varsPullPlot[i][j]->Fill(vars_out[1]); - } - } // must be a matched track to make resolution plots - } // end loop over trks - } // end loop over vars - } // end loop over entry in tree - - // Draw, fit, and save plots - for (UInt_t i = 0; i < vars.size(); i++){ - for (UInt_t j = 0; j < trks.size(); j++){ - PlotValidation::DrawWriteFitSaveTH1FPlot(subdir,varsResPlot[i][j],subdirname,Form("%s_cfresolution_%s",vars[i].Data(),trks[j].Data()),gausRes[i]); - PlotValidation::DrawWriteFitSaveTH1FPlot(subdir,varsPullPlot[i][j],subdirname,Form("%s_cfpull_%s",vars[i].Data(),trks[j].Data()),gausPull[i]); - delete varsResPlot[i][j]; - delete varsPullPlot[i][j]; - } - } - delete cftree; -} - void PlotValidation::PrintTotals(){ // want to print out totals of nHits, fraction of Hits shared, efficiency, fake rate, duplicate rate of seeds, build, fit // --> numer/denom plots for phi, know it will be in the bounds. @@ -1812,7 +663,6 @@ void PlotValidation::PrintTotals(){ ofstream totalsout; totalsout.open(Form("%s/totals_%s.txt",fOutName.Data(),fOutName.Data())); - // timing dump TTree * configtree = (TTree*)fInRoot->Get("configtree"); Int_t Ntracks = 0, Nevents = 0, nEtaPart = 0, nPhiPart = 0; configtree->SetBranchAddress("Nevents",&Nevents); @@ -1821,45 +671,16 @@ void PlotValidation::PrintTotals(){ configtree->SetBranchAddress("nPhiPart",&nPhiPart); configtree->GetEntry(0); - TTree * timetree; - Float_t simtime = 0., segtime = 0., seedtime = 0., buildtime = 0., fittime = 0., hlvtime = 0.; - if (fFullVal) { - timetree = (TTree*)fInRoot->Get("timetree"); - timetree->SetBranchAddress("simtime",&simtime); - timetree->SetBranchAddress("segtime",&segtime); - timetree->SetBranchAddress("seedtime",&seedtime); - timetree->SetBranchAddress("buildtime",&buildtime); - timetree->SetBranchAddress("fittime",&fittime); - timetree->SetBranchAddress("hlvtime",&hlvtime); - timetree->GetEntry(0); - } - std::cout << "--------Track Reconstruction Summary--------" << std::endl; std::cout << "nEvents: " << Nevents << " nTracks/evt: " << Ntracks << std::endl; std::cout << "nEtaPart: " << nEtaPart << " nPhiPart: " << nPhiPart << std::endl; std::cout << "++++++++++++++++++++++++++++++++++++++++++++" << std::endl; - if (fFullVal) { - std::cout << "Simulation time: " << simtime << std::endl; - std::cout << "Segmenting time: " << segtime << std::endl; - std::cout << "Seeding time: " << seedtime << std::endl; - std::cout << "Building time: " << buildtime << std::endl; - std::cout << "Fitting time: " << fittime << std::endl; - std::cout << "Validation time: " << hlvtime << std::endl; - } std::cout << std::endl; totalsout << "--------Track Reconstruction Summary--------" << std::endl; totalsout << "nEvents: " << Nevents << " nTracks/evt: " << Ntracks << std::endl; totalsout << "nEtaPart: " << nEtaPart << " nPhiPart: " << nPhiPart << std::endl; totalsout << "++++++++++++++++++++++++++++++++++++++++++++" << std::endl; - if (fFullVal) { - totalsout << "Simulation time: " << simtime << std::endl; - totalsout << "Segmenting time: " << segtime << std::endl; - totalsout << "Seeding time: " << seedtime << std::endl; - totalsout << "Building time: " << buildtime << std::endl; - totalsout << "Fitting time: " << fittime << std::endl; - totalsout << "Validation time: " << hlvtime << std::endl; - } totalsout << std::endl; for (UInt_t j = 0; j < trks.size(); j++) { @@ -1913,9 +734,6 @@ void PlotValidation::PrintTotals(){ totalsout.close(); delete configtree; - if (fFullVal) { - delete timetree; - } } void PlotValidation::MakeSubDirectory(const TString subdirname){ diff --git a/PlotValidation.hh b/PlotValidation.hh index 241c59b24e5d1..acbe8c152b62c 100644 --- a/PlotValidation.hh +++ b/PlotValidation.hh @@ -37,8 +37,7 @@ class PlotValidation { public: PlotValidation(TString inName, TString outName, - Bool_t mvInput, Bool_t fullVal, - Bool_t saveAs, TString outType); + Bool_t mvInput, Bool_t saveAs, TString outType); ~PlotValidation(); void Validation(); @@ -46,16 +45,8 @@ public: void PlotFakeRate(); void PlotDuplicateRate(); void PlotNHits(); - void PlotTiming(); void PlotMomResolutionPull(); - void PlotSegment(); - void PlotBranching(); - void PlotSimGeo(); - void PlotPosResolutionPull(); - void PlotCFResidual(); - void PlotCFResolutionPull(); - void PrintTotals(); void MakeSubDirectory(const TString subdirname); @@ -80,7 +71,6 @@ private: TString fInName; TFile * fInRoot; Bool_t fMvInput; - Bool_t fFullVal; Bool_t fSaveAs; TString fOutType; TString fOutName; diff --git a/TTreeValidation.cc b/TTreeValidation.cc index 368f91bab55c3..99c24695603db 100644 --- a/TTreeValidation.cc +++ b/TTreeValidation.cc @@ -54,21 +54,10 @@ TTreeValidation::TTreeValidation(std::string fileName) gROOT->ProcessLine("#include "); f_ = TFile::Open(fileName.c_str(), "recreate"); - if (Config::normal_val) { // regular validation + if (Config::root_val) + { initializeEfficiencyTree(); initializeFakeRateTree(); - if (Config::full_val) { - initializeGeometryTree(); - initializeConformalTree(); - initializeSeedInfoTree(); - initializeSeedTree(); - initializeSegmentTree(); - initializeBranchTree(); - initializeTimeTree(); - } - } - if (Config::super_debug) { - initializeDebugTree(); } if (Config::fit_val) { initializeFitTree(); @@ -78,227 +67,21 @@ TTreeValidation::TTreeValidation(std::string fileName) TTreeValidation::~TTreeValidation() { - if (Config::normal_val) { + if (Config::root_val) + { delete efftree_; delete fakeratetree_; - if (Config::full_val) { - delete geotree_; - delete cftree_; - delete seedinfotree_; - delete seedtree_; - delete segtree_; - delete tree_br_; - delete timetree_; - } } - if (Config::super_debug) { - delete debugtree_; - } - if (Config::fit_val) { + if (Config::fit_val) + { delete fittree_; } delete configtree_; delete f_; } -void TTreeValidation::initializeDebugTree(){ - nlayers_debug_ = Config::nLayers; - - // debug tree(lots and lots of variables) - debugtree_ = new TTree("debugtree","debugtree"); - - debugtree_->Branch("nlayers",&nlayers_debug_,"nlayers_debug_/I"); - - debugtree_->Branch("recocharge",&recocharge_debug_,"recocharge/I"); - debugtree_->Branch("mccharge",&mccharge_debug_,"mccharge/I"); - - debugtree_->Branch("event",&event_debug_,"event/I"); - debugtree_->Branch("nHits",&nHits_debug_,"nHits/I"); - - debugtree_->Branch("pt_gen",&pt_gen_debug_,"pt_gen/F"); - debugtree_->Branch("phi_gen",&phi_gen_debug_,"phi_gen/F"); - debugtree_->Branch("eta_gen",&eta_gen_debug_,"eta_gen/F"); - - debugtree_->Branch("x_gen",&x_gen_debug_,"x_gen/F"); - debugtree_->Branch("y_gen",&y_gen_debug_,"y_gen/F"); - debugtree_->Branch("z_gen",&z_gen_debug_,"z_gen/F"); - - debugtree_->Branch("layer_mc",&layer_mc_debug_,"layer_mc[nlayers_debug_]/I"); - - debugtree_->Branch("layer_chi2",&layer_chi2_debug_,"layer_chi2[nlayers_debug_]/I"); - debugtree_->Branch("chi2",&chi2_debug_,"chi2[nlayers_debug_]/F"); - - // MC - debugtree_->Branch("x_hit",&x_hit_debug_,"x_hit[nlayers_debug_]/F"); - debugtree_->Branch("y_hit",&y_hit_debug_,"y_hit[nlayers_debug_]/F"); - debugtree_->Branch("z_hit",&z_hit_debug_,"z_hit[nlayers_debug_]/F"); - debugtree_->Branch("exx_hit",&exx_hit_debug_,"exx_hit[nlayers_debug_]/F"); - debugtree_->Branch("eyy_hit",&eyy_hit_debug_,"eyy_hit[nlayers_debug_]/F"); - debugtree_->Branch("ezz_hit",&ezz_hit_debug_,"ezz_hit[nlayers_debug_]/F"); - - debugtree_->Branch("x_mc",&x_mc_debug_,"x_mc[nlayers_debug_]/F"); - debugtree_->Branch("y_mc",&y_mc_debug_,"y_mc[nlayers_debug_]/F"); - debugtree_->Branch("z_mc",&z_mc_debug_,"z_mc[nlayers_debug_]/F"); - debugtree_->Branch("px_mc",&px_mc_debug_,"px_mc[nlayers_debug_]/F"); - debugtree_->Branch("py_mc",&py_mc_debug_,"py_mc[nlayers_debug_]/F"); - debugtree_->Branch("pz_mc",&pz_mc_debug_,"pz_mc[nlayers_debug_]/F"); - - debugtree_->Branch("pt_mc",&pt_mc_debug_,"pt_mc[nlayers_debug_]/F"); - debugtree_->Branch("phi_mc",&phi_mc_debug_,"phi_mc[nlayers_debug_]/F"); - debugtree_->Branch("eta_mc",&eta_mc_debug_,"eta_mc[nlayers_debug_]/F"); - debugtree_->Branch("invpt_mc",&invpt_mc_debug_,"invpt_mc[nlayers_debug_]/F"); - debugtree_->Branch("theta_mc",&theta_mc_debug_,"theta_mc[nlayers_debug_]/F"); - - // conformal - debugtree_->Branch("x_cf",&x_cf_debug_,"x_cf/F"); - debugtree_->Branch("y_cf",&y_cf_debug_,"y_cf/F"); - debugtree_->Branch("z_cf",&z_cf_debug_,"z_cf/F"); - debugtree_->Branch("exx_cf",&exx_cf_debug_,"exx_cf/F"); - debugtree_->Branch("eyy_cf",&eyy_cf_debug_,"eyy_cf/F"); - debugtree_->Branch("ezz_cf",&ezz_cf_debug_,"ezz_cf/F"); - - debugtree_->Branch("px_cf",&px_cf_debug_,"px_cf/F"); - debugtree_->Branch("py_cf",&py_cf_debug_,"py_cf/F"); - debugtree_->Branch("pz_cf",&pz_cf_debug_,"pz_cf/F"); - debugtree_->Branch("epxpx_cf",&epxpx_cf_debug_,"epxpx_cf/F"); - debugtree_->Branch("epypy_cf",&epypy_cf_debug_,"epypy_cf/F"); - debugtree_->Branch("epzpz_cf",&epzpz_cf_debug_,"epzpz_cf/F"); - - debugtree_->Branch("pt_cf",&pt_cf_debug_,"pt_cf/F"); - debugtree_->Branch("phi_cf",&phi_cf_debug_,"phi_cf/F"); - debugtree_->Branch("eta_cf",&eta_cf_debug_,"eta_cf/F"); - debugtree_->Branch("ept_cf",&ept_cf_debug_,"ept_cf/F"); - debugtree_->Branch("ephi_cf",&ephi_cf_debug_,"ephi_cf/F"); - debugtree_->Branch("eeta_cf",&eeta_cf_debug_,"eeta_cf/F"); - - debugtree_->Branch("invpt_cf",&invpt_cf_debug_,"invpt_cf/F"); - debugtree_->Branch("einvpt_cf",&einvpt_cf_debug_,"einvpt_cf/F"); - debugtree_->Branch("theta_cf",&theta_cf_debug_,"theta_cf/F"); - debugtree_->Branch("etheta_cf",ðeta_cf_debug_,"etheta_cf/F"); - - // prop - debugtree_->Branch("layer_prop",&layer_prop_debug_,"layer_prop[nlayers_debug_]/I"); - - debugtree_->Branch("x_prop",&x_prop_debug_,"x_prop[nlayers_debug_]/F"); - debugtree_->Branch("y_prop",&y_prop_debug_,"y_prop[nlayers_debug_]/F"); - debugtree_->Branch("z_prop",&z_prop_debug_,"z_prop[nlayers_debug_]/F"); - debugtree_->Branch("exx_prop",&exx_prop_debug_,"exx_prop[nlayers_debug_]/F"); - debugtree_->Branch("eyy_prop",&eyy_prop_debug_,"eyy_prop[nlayers_debug_]/F"); - debugtree_->Branch("ezz_prop",&ezz_prop_debug_,"ezz_prop[nlayers_debug_]/F"); - - debugtree_->Branch("px_prop",&px_prop_debug_,"px_prop[nlayers_debug_]/F"); - debugtree_->Branch("py_prop",&py_prop_debug_,"py_prop[nlayers_debug_]/F"); - debugtree_->Branch("pz_prop",&pz_prop_debug_,"pz_prop[nlayers_debug_]/F"); - debugtree_->Branch("epxpx_prop",&epxpx_prop_debug_,"epxpx_prop[nlayers_debug_]/F"); - debugtree_->Branch("epypy_prop",&epypy_prop_debug_,"epypy_prop[nlayers_debug_]/F"); - debugtree_->Branch("epzpz_prop",&epzpz_prop_debug_,"epzpz_prop[nlayers_debug_]/F"); - - debugtree_->Branch("pt_prop",&pt_prop_debug_,"pt_prop[nlayers_debug_]/F"); - debugtree_->Branch("phi_prop",&phi_prop_debug_,"phi_prop[nlayers_debug_]/F"); - debugtree_->Branch("eta_prop",&eta_prop_debug_,"eta_prop[nlayers_debug_]/F"); - debugtree_->Branch("ept_prop",&ept_prop_debug_,"ept_prop[nlayers_debug_]/F"); - debugtree_->Branch("ephi_prop",&ephi_prop_debug_,"ephi_prop[nlayers_debug_]/F"); - debugtree_->Branch("eeta_prop",&eeta_prop_debug_,"eeta_prop[nlayers_debug_]/F"); - - debugtree_->Branch("invpt_prop",&invpt_prop_debug_,"invpt_prop[nlayers_debug_]/F"); - debugtree_->Branch("einvpt_prop",&einvpt_prop_debug_,"einvpt_prop[nlayers_debug_]/F"); - debugtree_->Branch("theta_prop",&theta_prop_debug_,"theta_prop[nlayers_debug_]/F"); - debugtree_->Branch("etheta_prop",ðeta_prop_debug_,"etheta_prop[nlayers_debug_]/F"); - - //update - debugtree_->Branch("layer_up",&layer_up_debug_,"layer_up[nlayers_debug_]/I"); - - debugtree_->Branch("x_up",&x_up_debug_,"x_up[nlayers_debug_]/F"); - debugtree_->Branch("y_up",&y_up_debug_,"y_up[nlayers_debug_]/F"); - debugtree_->Branch("z_up",&z_up_debug_,"z_up[nlayers_debug_]/F"); - debugtree_->Branch("exx_up",&exx_up_debug_,"exx_up[nlayers_debug_]/F"); - debugtree_->Branch("eyy_up",&eyy_up_debug_,"eyy_up[nlayers_debug_]/F"); - debugtree_->Branch("ezz_up",&ezz_up_debug_,"ezz_up[nlayers_debug_]/F"); - - debugtree_->Branch("px_up",&px_up_debug_,"px_up[nlayers_debug_]/F"); - debugtree_->Branch("py_up",&py_up_debug_,"py_up[nlayers_debug_]/F"); - debugtree_->Branch("pz_up",&pz_up_debug_,"pz_up[nlayers_debug_]/F"); - debugtree_->Branch("epxpx_up",&epxpx_up_debug_,"epxpx_up[nlayers_debug_]/F"); - debugtree_->Branch("epypy_up",&epypy_up_debug_,"epypy_up[nlayers_debug_]/F"); - debugtree_->Branch("epzpz_up",&epzpz_up_debug_,"epzpz_up[nlayers_debug_]/F"); - - debugtree_->Branch("pt_up",&pt_up_debug_,"pt_up[nlayers_debug_]/F"); - debugtree_->Branch("phi_up",&phi_up_debug_,"phi_up[nlayers_debug_]/F"); - debugtree_->Branch("eta_up",&eta_up_debug_,"eta_up[nlayers_debug_]/F"); - debugtree_->Branch("ept_up",&ept_up_debug_,"ept_up[nlayers_debug_]/F"); - debugtree_->Branch("ephi_up",&ephi_up_debug_,"ephi_up[nlayers_debug_]/F"); - debugtree_->Branch("eeta_up",&eeta_up_debug_,"eeta_up[nlayers_debug_]/F"); - - debugtree_->Branch("invpt_up",&invpt_up_debug_,"invpt_up[nlayers_debug_]/F"); - debugtree_->Branch("einvpt_up",&einvpt_up_debug_,"einvpt_up[nlayers_debug_]/F"); - debugtree_->Branch("theta_up",&theta_up_debug_,"theta_up[nlayers_debug_]/F"); - debugtree_->Branch("etheta_up",ðeta_up_debug_,"etheta_up[nlayers_debug_]/F"); - - debugtree_->Branch("etabin_hit",&ebhit_debug_,"etabin_hit[nlayers_debug_]/I"); - debugtree_->Branch("etabinplus",&ebp_debug_,"etabinplus[nlayers_debug_]/I"); - debugtree_->Branch("etabinminus",&ebm_debug_,"etabinminus[nlayers_debug_]/I"); - debugtree_->Branch("phibin_hit",&pbhit_debug_,"phibin_hit[nlayers_debug_]/I"); - debugtree_->Branch("phibinplus",&pbp_debug_,"phibinplus[nlayers_debug_]/I"); - debugtree_->Branch("phibinminus",pbm_debug_,"phibinminus[nlayers_debug_]/I"); -} - -void TTreeValidation::initializeSeedInfoTree(){ - // seed validation - seedinfotree_ = new TTree("seedinfotree","seedinfotree"); - seedinfotree_->Branch("evtID",&evtID_seedinfo_); - seedinfotree_->Branch("mcID",&mcID_seedinfo_); - seedinfotree_->Branch("pt_gen",&pt_gen_seedinfo_); - seedinfotree_->Branch("eta_gen",&eta_gen_seedinfo_); - seedinfotree_->Branch("phi_gen",&phi_gen_seedinfo_); - seedinfotree_->Branch("a",&a); - seedinfotree_->Branch("b",&b); - seedinfotree_->Branch("r",&r); - seedinfotree_->Branch("d0",&d0); - seedinfotree_->Branch("pass",&pass); -} - -void TTreeValidation::initializeSeedTree(){ - // seed validation - seedtree_ = new TTree("seedtree","seedtree"); - seedtree_->Branch("evtID",&evtID_seed_); - seedtree_->Branch("nTkAll",&nTkAll_); - seedtree_->Branch("nTkAllMC",&nTkAllMC_); - seedtree_->Branch("nTkCut",&nTkCut_); - seedtree_->Branch("nTkCutMC",&nTkCutMC_); -} - -void TTreeValidation::initializeSegmentTree(){ - // segment validation - segtree_ = new TTree("segtree","segtree"); - segtree_->Branch("evtID",&evtID_seg_); - segtree_->Branch("layer",&layer_seg_); - segtree_->Branch("etabin",&etabin_seg_); - segtree_->Branch("phibin",&phibin_seg_); - segtree_->Branch("nHits",&nHits_seg_); -} - -void TTreeValidation::initializeBranchTree(){ - // build validation - tree_br_ = new TTree("tree_br","tree_br"); - tree_br_->Branch("evtID",&evtID_br_); - tree_br_->Branch("seedID",&seedID_br_); - - tree_br_->Branch("layer",&layer_); - tree_br_->Branch("cands",&cands_); - - tree_br_->Branch("candEtaPhiBins","std::vector",&candEtaPhiBins_); - tree_br_->Branch("candHits","std::vector",&candHits_); - tree_br_->Branch("candBranches","std::vector",&candBranches_); - - tree_br_->Branch("uniqueEtaPhiBins",&uniqueEtaPhiBins_); - tree_br_->Branch("uniqueHits",&uniqueHits_); - tree_br_->Branch("uniqueBranches",&uniqueBranches_); - - tree_br_->Branch("candnSigmaDeta","std::vector",&candnSigmaDeta_); - tree_br_->Branch("candnSigmaDphi","std::vector",&candnSigmaDphi_); -} - -void TTreeValidation::initializeEfficiencyTree(){ +void TTreeValidation::initializeEfficiencyTree() +{ // efficiency validation efftree_ = new TTree("efftree","efftree"); efftree_->Branch("evtID",&evtID_eff_); @@ -377,7 +160,8 @@ void TTreeValidation::initializeEfficiencyTree(){ efftree_->Branch("nTkMatches_fit",&nTkMatches_fit_eff_); } -void TTreeValidation::initializeFakeRateTree(){ +void TTreeValidation::initializeFakeRateTree() +{ // fake rate validation fakeratetree_ = new TTree("fakeratetree","fakeratetree"); @@ -463,129 +247,8 @@ void TTreeValidation::initializeFakeRateTree(){ fakeratetree_->Branch("iTkMatches_fit",&iTkMatches_fit_FR_); } -void TTreeValidation::initializeGeometryTree(){ - // Geometry validation - geotree_ = new TTree("geotree","geotree"); - - geotree_->Branch("evtID",&evtID_geo_); - geotree_->Branch("mcID",&mcID_geo_); - geotree_->Branch("seedID_seed",&seedID_seed_geo_); - geotree_->Branch("seedID_fit",&seedID_fit_geo_); - geotree_->Branch("mcmask_seed",&mcmask_seed_geo_); - geotree_->Branch("mcmask_fit",&mcmask_fit_geo_); - - // Generated vertex of MC tracks - geotree_->Branch("x_mc_gen_vrx",&x_mc_gen_vrx_geo_); - geotree_->Branch("y_mc_gen_vrx",&y_mc_gen_vrx_geo_); - geotree_->Branch("z_mc_gen_vrx",&z_mc_gen_vrx_geo_); - - // Full reco hits (vector) from simulation - geotree_->Branch("x_mc_reco_hit","std::vector",&x_mc_reco_hit_geo_); - geotree_->Branch("y_mc_reco_hit","std::vector",&y_mc_reco_hit_geo_); - geotree_->Branch("z_mc_reco_hit","std::vector",&z_mc_reco_hit_geo_); - - // Position pull info from reco tracks - geotree_->Branch("layers_seed","std::vector",&layers_seed_geo_); - geotree_->Branch("layers_fit","std::vector",&layers_fit_geo_); - - geotree_->Branch("x_lay_seed","std::vector",&x_lay_seed_geo_); - geotree_->Branch("y_lay_seed","std::vector",&y_lay_seed_geo_); - geotree_->Branch("z_lay_seed","std::vector",&z_lay_seed_geo_); - geotree_->Branch("ex_lay_seed","std::vector",&ex_lay_seed_geo_); - geotree_->Branch("ey_lay_seed","std::vector",&ey_lay_seed_geo_); - geotree_->Branch("ez_lay_seed","std::vector",&ez_lay_seed_geo_); - - geotree_->Branch("x_lay_fit","std::vector",&x_lay_fit_geo_); - geotree_->Branch("y_lay_fit","std::vector",&y_lay_fit_geo_); - geotree_->Branch("z_lay_fit","std::vector",&z_lay_fit_geo_); - geotree_->Branch("ex_lay_fit","std::vector",&ex_lay_fit_geo_); - geotree_->Branch("ey_lay_fit","std::vector",&ey_lay_fit_geo_); - geotree_->Branch("ez_lay_fit","std::vector",&ez_lay_fit_geo_); -} - -void TTreeValidation::initializeConformalTree(){ - // Conformal Fit validation - cftree_ = new TTree("cftree","cftree"); - - cftree_->Branch("evtID",&evtID_cf_); - cftree_->Branch("mcID",&mcID_cf_); - cftree_->Branch("seedID_seed",&seedID_seed_cf_); - cftree_->Branch("seedID_fit",&seedID_fit_cf_); - cftree_->Branch("mcmask_seed",&mcmask_seed_cf_); - cftree_->Branch("mcmask_fit",&mcmask_fit_cf_); - - cftree_->Branch("x_mc_cf_seed",&x_mc_seed_cf_); - cftree_->Branch("x_cf_seed",&x_seed_cf_); - cftree_->Branch("ex_cf_seed",&ex_seed_cf_); - cftree_->Branch("x_mc_cf_fit",&x_mc_fit_cf_); - cftree_->Branch("x_cf_fit",&x_fit_cf_); - cftree_->Branch("ex_cf_fit",&ex_fit_cf_); - - cftree_->Branch("y_mc_cf_seed",&y_mc_seed_cf_); - cftree_->Branch("y_cf_seed",&y_seed_cf_); - cftree_->Branch("ey_cf_seed",&ey_seed_cf_); - cftree_->Branch("y_mc_cf_fit",&y_mc_fit_cf_); - cftree_->Branch("y_cf_fit",&y_fit_cf_); - cftree_->Branch("ey_cf_fit",&ey_fit_cf_); - - cftree_->Branch("z_mc_cf_seed",&z_mc_seed_cf_); - cftree_->Branch("z_cf_seed",&z_seed_cf_); - cftree_->Branch("ez_cf_seed",&ez_seed_cf_); - cftree_->Branch("z_mc_cf_fit",&z_mc_fit_cf_); - cftree_->Branch("z_cf_fit",&z_fit_cf_); - cftree_->Branch("ez_cf_fit",&ez_fit_cf_); - - cftree_->Branch("px_mc_cf_seed",&px_mc_seed_cf_); - cftree_->Branch("px_cf_seed",&px_seed_cf_); - cftree_->Branch("epx_cf_seed",&epx_seed_cf_); - cftree_->Branch("px_mc_cf_fit",&px_mc_fit_cf_); - cftree_->Branch("px_cf_fit",&px_fit_cf_); - cftree_->Branch("epx_cf_fit",&epx_fit_cf_); - - cftree_->Branch("py_mc_cf_seed",&py_mc_seed_cf_); - cftree_->Branch("py_cf_seed",&py_seed_cf_); - cftree_->Branch("epy_cf_seed",&epy_seed_cf_); - cftree_->Branch("py_mc_cf_fit",&py_mc_fit_cf_); - cftree_->Branch("py_cf_fit",&py_fit_cf_); - cftree_->Branch("epy_cf_fit",&epy_fit_cf_); - - cftree_->Branch("pz_mc_cf_seed",&pz_mc_seed_cf_); - cftree_->Branch("pz_cf_seed",&pz_seed_cf_); - cftree_->Branch("epz_cf_seed",&epz_seed_cf_); - cftree_->Branch("pz_mc_cf_fit",&pz_mc_fit_cf_); - cftree_->Branch("pz_cf_fit",&pz_fit_cf_); - cftree_->Branch("epz_cf_fit",&epz_fit_cf_); - - cftree_->Branch("pt_mc_cf_seed",&pt_mc_seed_cf_); - cftree_->Branch("pt_cf_seed",&pt_seed_cf_); - cftree_->Branch("ept_cf_seed",&ept_seed_cf_); - cftree_->Branch("pt_mc_cf_fit",&pt_mc_fit_cf_); - cftree_->Branch("pt_cf_fit",&pt_fit_cf_); - cftree_->Branch("ept_cf_fit",&ept_fit_cf_); - - cftree_->Branch("invpt_mc_cf_seed",&invpt_mc_seed_cf_); - cftree_->Branch("invpt_cf_seed",&invpt_seed_cf_); - cftree_->Branch("einvpt_cf_seed",&einvpt_seed_cf_); - cftree_->Branch("invpt_mc_cf_fit",&invpt_mc_fit_cf_); - cftree_->Branch("invpt_cf_fit",&invpt_fit_cf_); - cftree_->Branch("einvpt_cf_fit",&einvpt_fit_cf_); - - cftree_->Branch("phi_mc_cf_seed",&phi_mc_seed_cf_); - cftree_->Branch("phi_cf_seed",&phi_seed_cf_); - cftree_->Branch("ephi_cf_seed",&ephi_seed_cf_); - cftree_->Branch("phi_mc_cf_fit",&phi_mc_fit_cf_); - cftree_->Branch("phi_cf_fit",&phi_fit_cf_); - cftree_->Branch("ephi_cf_fit",&ephi_fit_cf_); - - cftree_->Branch("theta_mc_cf_seed",&theta_mc_seed_cf_); - cftree_->Branch("theta_cf_seed",&theta_seed_cf_); - cftree_->Branch("etheta_cf_seed",ðeta_seed_cf_); - cftree_->Branch("theta_mc_cf_fit",&theta_mc_fit_cf_); - cftree_->Branch("theta_cf_fit",&theta_fit_cf_); - cftree_->Branch("etheta_cf_fit",ðeta_fit_cf_); -} - -void TTreeValidation::initializeConfigTree(){ +void TTreeValidation::initializeConfigTree() +{ // include config ++ real seeding parameters ... configtree_ = new TTree("configtree","configtree"); @@ -636,58 +299,48 @@ void TTreeValidation::initializeConfigTree(){ configtree_->Branch("thetaerr012",&thetaerr012_); } -void TTreeValidation::initializeTimeTree(){ - timetree_ = new TTree("timetree","timetree"); - - timetree_->Branch("simtime",&simtime_); - timetree_->Branch("segtime",&segtime_); - timetree_->Branch("seedtime",&seedtime_); - timetree_->Branch("buildtime",&buildtime_); - timetree_->Branch("fittime",&fittime_); - timetree_->Branch("hlvtime",&hlvtime_); -} - void TTreeValidation::initializeFitTree() { - nlayers_fit_ = Config::nLayers; + ntotallayers_fit_ = Config::nTotalLayers; fittree_ = new TTree("fittree","fittree"); - fittree_->Branch("nlayers",&nlayers_fit_,"nlayers_fit_/I"); + fittree_->Branch("ntotallayers",&ntotallayers_fit_,"ntotallayers_fit_/I"); fittree_->Branch("tkid",&tkid_fit_,"tkid_fit_/I"); fittree_->Branch("evtid",&evtid_fit_,"evtid_fit_/I"); - fittree_->Branch("z_prop",&z_prop_fit_,"z_prop_fit_[nlayers_fit_]/F"); - fittree_->Branch("ez_prop",&ez_prop_fit_,"ez_prop_fit_[nlayers_fit_]/F"); - fittree_->Branch("z_hit",&z_hit_fit_,"z_hit_fit_[nlayers_fit_]/F"); - fittree_->Branch("ez_hit",&ez_hit_fit_,"ez_hit_fit_[nlayers_fit_]/F"); - fittree_->Branch("z_sim",&z_sim_fit_,"z_sim_fit_[nlayers_fit_]/F"); - fittree_->Branch("ez_sim",&ez_sim_fit_,"ez_sim_fit_[nlayers_fit_]/F"); - - fittree_->Branch("pphi_prop",&pphi_prop_fit_,"pphi_prop_fit_[nlayers_fit_]/F"); - fittree_->Branch("epphi_prop",&epphi_prop_fit_,"epphi_prop_fit_[nlayers_fit_]/F"); - fittree_->Branch("pphi_hit",&pphi_hit_fit_,"pphi_hit_fit_[nlayers_fit_]/F"); - fittree_->Branch("epphi_hit",&epphi_hit_fit_,"epphi_hit_fit_[nlayers_fit_]/F"); - fittree_->Branch("pphi_sim",&pphi_sim_fit_,"pphi_sim_fit_[nlayers_fit_]/F"); - fittree_->Branch("epphi_sim",&epphi_sim_fit_,"epphi_sim_fit_[nlayers_fit_]/F"); - - fittree_->Branch("pt_up",&pt_up_fit_,"pt_up_fit_[nlayers_fit_]/F"); - fittree_->Branch("ept_up",&ept_up_fit_,"ept_up_fit_[nlayers_fit_]/F"); - fittree_->Branch("pt_sim",&pt_sim_fit_,"pt_sim_fit_[nlayers_fit_]/F"); - fittree_->Branch("ept_sim",&ept_sim_fit_,"ept_sim_fit_[nlayers_fit_]/F"); - - fittree_->Branch("mphi_up",&mphi_up_fit_,"mphi_up_fit_[nlayers_fit_]/F"); - fittree_->Branch("emphi_up",&emphi_up_fit_,"emphi_up_fit_[nlayers_fit_]/F"); - fittree_->Branch("mphi_sim",&mphi_sim_fit_,"mphi_sim_fit_[nlayers_fit_]/F"); - fittree_->Branch("emphi_sim",&emphi_sim_fit_,"emphi_sim_fit_[nlayers_fit_]/F"); - - fittree_->Branch("meta_up",&meta_up_fit_,"meta_up_fit_[nlayers_fit_]/F"); - fittree_->Branch("emeta_up",&emeta_up_fit_,"emeta_up_fit_[nlayers_fit_]/F"); - fittree_->Branch("meta_sim",&meta_sim_fit_,"meta_sim_fit_[nlayers_fit_]/F"); - fittree_->Branch("emeta_sim",&emeta_sim_fit_,"emeta_sim_fit_[nlayers_fit_]/F"); + fittree_->Branch("z_prop",&z_prop_fit_,"z_prop_fit_[ntotallayers_fit_]/F"); + fittree_->Branch("ez_prop",&ez_prop_fit_,"ez_prop_fit_[ntotallayers_fit_]/F"); + fittree_->Branch("z_hit",&z_hit_fit_,"z_hit_fit_[ntotallayers_fit_]/F"); + fittree_->Branch("ez_hit",&ez_hit_fit_,"ez_hit_fit_[ntotallayers_fit_]/F"); + fittree_->Branch("z_sim",&z_sim_fit_,"z_sim_fit_[ntotallayers_fit_]/F"); + fittree_->Branch("ez_sim",&ez_sim_fit_,"ez_sim_fit_[ntotallayers_fit_]/F"); + + fittree_->Branch("pphi_prop",&pphi_prop_fit_,"pphi_prop_fit_[ntotallayers_fit_]/F"); + fittree_->Branch("epphi_prop",&epphi_prop_fit_,"epphi_prop_fit_[ntotallayers_fit_]/F"); + fittree_->Branch("pphi_hit",&pphi_hit_fit_,"pphi_hit_fit_[ntotallayers_fit_]/F"); + fittree_->Branch("epphi_hit",&epphi_hit_fit_,"epphi_hit_fit_[ntotallayers_fit_]/F"); + fittree_->Branch("pphi_sim",&pphi_sim_fit_,"pphi_sim_fit_[ntotallayers_fit_]/F"); + fittree_->Branch("epphi_sim",&epphi_sim_fit_,"epphi_sim_fit_[ntotallayers_fit_]/F"); + + fittree_->Branch("pt_up",&pt_up_fit_,"pt_up_fit_[ntotallayers_fit_]/F"); + fittree_->Branch("ept_up",&ept_up_fit_,"ept_up_fit_[ntotallayers_fit_]/F"); + fittree_->Branch("pt_sim",&pt_sim_fit_,"pt_sim_fit_[ntotallayers_fit_]/F"); + fittree_->Branch("ept_sim",&ept_sim_fit_,"ept_sim_fit_[ntotallayers_fit_]/F"); + + fittree_->Branch("mphi_up",&mphi_up_fit_,"mphi_up_fit_[ntotallayers_fit_]/F"); + fittree_->Branch("emphi_up",&emphi_up_fit_,"emphi_up_fit_[ntotallayers_fit_]/F"); + fittree_->Branch("mphi_sim",&mphi_sim_fit_,"mphi_sim_fit_[ntotallayers_fit_]/F"); + fittree_->Branch("emphi_sim",&emphi_sim_fit_,"emphi_sim_fit_[ntotallayers_fit_]/F"); + + fittree_->Branch("meta_up",&meta_up_fit_,"meta_up_fit_[ntotallayers_fit_]/F"); + fittree_->Branch("emeta_up",&emeta_up_fit_,"emeta_up_fit_[ntotallayers_fit_]/F"); + fittree_->Branch("meta_sim",&meta_sim_fit_,"meta_sim_fit_[ntotallayers_fit_]/F"); + fittree_->Branch("emeta_sim",&emeta_sim_fit_,"emeta_sim_fit_[ntotallayers_fit_]/F"); } -void TTreeValidation::alignTrackExtra(TrackVec& evt_tracks, TrackExtraVec& evt_extras){ +void TTreeValidation::alignTrackExtra(TrackVec& evt_tracks, TrackExtraVec& evt_extras) +{ TrackExtraVec trackExtra_tmp; // align temporary tkExVec with new track collection ordering @@ -704,57 +357,12 @@ void TTreeValidation::alignTrackExtra(TrackVec& evt_tracks, TrackExtraVec& evt_e } } -void TTreeValidation::collectSimTkTSVecMapInfo(int mcTrackID, const TSVec& initTSs){ +void TTreeValidation::collectSimTkTSVecMapInfo(int mcTrackID, const TSVec& initTSs) +{ std::lock_guard locker(glock_); simTkTSVecMap_[mcTrackID] = initTSs; } -void TTreeValidation::collectSeedTkCFMapInfo(int seedID, const TrackState& cfitStateHit0){ - seedTkCFMap_[seedID] = cfitStateHit0; -} - -void TTreeValidation::collectSeedTkTSLayerPairVecMapInfo(int seedID, const TSLayerPairVec& updatedStates){ - seedTkTSLayerPairVecMap_[seedID] = updatedStates; -} - -void TTreeValidation::collectBranchingInfo(int seedID, int ilayer, - float nSigmaDeta, float etaBinMinus, int etaBinPlus, - float nSigmaDphi, int phiBinMinus, int phiBinPlus, - const std::vector& cand_hit_indices, const std::vector& branch_hit_indices){ - - BranchVal tmpBranchVal; - tmpBranchVal.nSigmaDeta = nSigmaDeta; - tmpBranchVal.etaBinMinus = etaBinMinus; - tmpBranchVal.etaBinPlus = etaBinPlus; - tmpBranchVal.nSigmaDphi = nSigmaDphi; - tmpBranchVal.phiBinMinus = phiBinMinus; - tmpBranchVal.phiBinPlus = phiBinPlus; - tmpBranchVal.cand_hit_indices = cand_hit_indices; - tmpBranchVal.branch_hit_indices = branch_hit_indices; // size of vector formerly known as just "branches" - - seedToBranchValVecLayMapMap_[seedID][ilayer].push_back(tmpBranchVal); -} - -void TTreeValidation::collectFitTkCFMapInfo(int seedID, const TrackState& cfitStateHit0){ - fitTkCFMap_[seedID] = cfitStateHit0; -} - -void TTreeValidation::collectFitTkTSLayerPairVecMapInfo(int seedID, const TSLayerPairVec& updatedStates){ - fitTkTSLayerPairVecMap_[seedID] = updatedStates; -} - -void TTreeValidation::collectPropTSLayerVecInfo(int layer, const TrackState& propTS){ - propTSLayerPairVec_.push_back(std::make_pair(layer,propTS)); -} - -void TTreeValidation::collectChi2LayerVecInfo(int layer, float chi2){ - chi2LayerPairVec_.push_back(std::make_pair(layer,chi2)); -} - -void TTreeValidation::collectUpTSLayerVecInfo(int layer, const TrackState& upTS){ - upTSLayerPairVec_.push_back(std::make_pair(layer,upTS)); -} - void TTreeValidation::collectFitInfo(const FitVal & tmpfitval, int tkid, int layer) { std::lock_guard locker(glock_); @@ -762,23 +370,13 @@ void TTreeValidation::collectFitInfo(const FitVal & tmpfitval, int tkid, int lay fitValTkMapMap_[tkid][layer] = tmpfitval; } -void TTreeValidation::resetValidationMaps(){ +void TTreeValidation::resetValidationMaps() +{ std::lock_guard locker(glock_); // reset map of sim tracks to MC track states (pre-smearing) simTkTSVecMap_.clear(); - // reset map of reco tracks to Conformal Fit track states - seedTkCFMap_.clear(); - fitTkCFMap_.clear(); - - // reset map of reco tracks to updated layer track states and bool pairs - seedTkTSLayerPairVecMap_.clear(); - fitTkTSLayerPairVecMap_.clear(); - - // reset branching map - seedToBranchValVecLayMapMap_.clear(); - // reset fit validation map fitValTkMapMap_.clear(); @@ -792,14 +390,6 @@ void TTreeValidation::resetValidationMaps(){ seedToFitMap_.clear(); } -void TTreeValidation::resetDebugVectors(){ - std::lock_guard locker(glock_); - - propTSLayerPairVec_.clear(); // used exclusively for debugtree (prop states) - chi2LayerPairVec_.clear(); // used exclusively for debugtree - upTSLayerPairVec_.clear(); // used exclusively for debugtree (updated states) -} - void TTreeValidation::setTrackExtras(Event& ev) { std::lock_guard locker(glock_); @@ -812,7 +402,8 @@ void TTreeValidation::setTrackExtras(Event& ev) void TTreeValidation::setTrackCollectionExtras(const TrackVec& evt_tracks, TrackExtraVec& evt_extras, const std::vector& layerHits, const MCHitInfoVec& mcHitInfo) { - for (auto itrack = 0; itrack < evt_tracks.size(); ++itrack){ + for (auto itrack = 0; itrack < evt_tracks.size(); ++itrack) + { auto&& track(evt_tracks[itrack]); auto&& extra(evt_extras[itrack]); extra.setMCTrackIDInfo(track, layerHits, mcHitInfo); @@ -830,8 +421,8 @@ void TTreeValidation::makeSimTkToRecoTksMaps(Event& ev) void TTreeValidation::mapSimTkToRecoTks(const TrackVec& evt_tracks, TrackExtraVec& evt_extras, TkIDToTkIDVecMap& simTkMap) { - - for (auto itrack = 0; itrack < evt_tracks.size(); ++itrack){ + for (auto itrack = 0; itrack < evt_tracks.size(); ++itrack) + { auto&& track(evt_tracks[itrack]); auto&& extra(evt_extras[itrack]); if (extra.mcTrackID() >= 0){ // skip fakes, don't store them at all in sim map @@ -839,26 +430,31 @@ void TTreeValidation::mapSimTkToRecoTks(const TrackVec& evt_tracks, TrackExtraVe } } - for (auto&& simTkMatches : simTkMap){ - if (simTkMatches.second.size() < 2) { // no duplicates + for (auto&& simTkMatches : simTkMap) + { + if (simTkMatches.second.size() < 2) // no duplicates + { auto& extra(evt_extras[simTkMatches.second[0]]); extra.setMCDuplicateInfo(0,bool(false)); } - else{ // sort duplicates (ghosts) to keep best one --> most hits, lowest chi2 - + else // sort duplicates (ghosts) to keep best one --> most hits, lowest chi2 + { // really should sort on indices with a reduced data structure... this is a hack way to do this for now... // e.g. std::tuple, (label, nHits, chi2) TrackVec tmpMatches; - for (auto&& label : simTkMatches.second) { // loop over vector of reco track labels, push back the track with each label + for (auto&& label : simTkMatches.second) // loop over vector of reco track labels, push back the track with each label + { tmpMatches.push_back(evt_tracks[label]); } std::sort(tmpMatches.begin(), tmpMatches.end(), sortByHitsChi2); // sort the tracks - for (auto itrack = 0; itrack < tmpMatches.size(); itrack++){ // loop over sorted tracks, now make the vector of sorted labels match + for (auto itrack = 0; itrack < tmpMatches.size(); itrack++) // loop over sorted tracks, now make the vector of sorted labels match + { simTkMatches.second[itrack] = tmpMatches[itrack].label(); } int duplicateID = 0; - for (auto&& label : simTkMatches.second){ // loop over vector of reco tracsk + for (auto&& label : simTkMatches.second) // loop over vector of reco tracsk + { auto& extra(evt_extras[label]); extra.setMCDuplicateInfo(duplicateID,bool(true)); duplicateID++; // used in fake rate trees! @@ -877,434 +473,15 @@ void TTreeValidation::makeSeedTkToRecoTkMaps(Event& ev) void TTreeValidation::mapSeedTkToRecoTk(const TrackVec& evt_tracks, const TrackExtraVec& evt_extras, TkIDToTkIDMap& seedTkMap) { - for (auto&& track : evt_tracks){ + for (auto&& track : evt_tracks) + { seedTkMap[evt_extras[track.label()].seedID()] = track.label(); } } -void TTreeValidation::resetDebugTreeArrays(){ - for (int i = 0; i < Config::nLayers; i++){ - // reset MC info - layer_mc_debug_[i]=-99; - x_hit_debug_[i]=-99; y_hit_debug_[i]=-99; z_hit_debug_[i]=-99; - exx_hit_debug_[i]=-99; eyy_hit_debug_[i]=-99; ezz_hit_debug_[i]=-99; - x_mc_debug_[i]=-99; y_mc_debug_[i]=-99; z_mc_debug_[i]=-99; - px_mc_debug_[i]=-99; py_mc_debug_[i]=-99; pz_mc_debug_[i]=-99; - pt_mc_debug_[i]=-99; phi_mc_debug_[i]=-99; eta_mc_debug_[i]=-99; - invpt_mc_debug_[i]=-99; theta_mc_debug_[i]=-99; - - // reset prop info - layer_prop_debug_[i]=-99; - x_prop_debug_[i]=-99; y_prop_debug_[i]=-99; z_prop_debug_[i]=-99; - exx_prop_debug_[i]=-99; eyy_prop_debug_[i]=-99; ezz_prop_debug_[i]=-99; - px_prop_debug_[i]=-99; py_prop_debug_[i]=-99; pz_prop_debug_[i]=-99; - epxpx_prop_debug_[i]=-99; epypy_prop_debug_[i]=-99; epzpz_prop_debug_[i]=-99; - pt_prop_debug_[i]=-99; phi_prop_debug_[i]=-99; eta_prop_debug_[i]=-99; - ept_prop_debug_[i]=-99; ephi_prop_debug_[i]=-99; eeta_prop_debug_[i]=-99; - invpt_prop_debug_[i] =-99; theta_prop_debug_[i] =-99; - einvpt_prop_debug_[i]=-99; etheta_prop_debug_[i]=-99; - - // reset chi2 - layer_chi2_debug_[i]=-99; - chi2_debug_[i]=-99; - - // reset update info - layer_up_debug_[i]=99; - x_up_debug_[i]=-99; y_up_debug_[i]=-99; z_up_debug_[i]=-99; - exx_up_debug_[i]=-99; eyy_up_debug_[i]=-99; ezz_up_debug_[i]=-99; - px_up_debug_[i]=-99; py_up_debug_[i]=-99; pz_up_debug_[i]=-99; - epxpx_up_debug_[i]=-99; epypy_up_debug_[i]=-99; epzpz_up_debug_[i]=-99; - pt_up_debug_[i]=-99; phi_up_debug_[i]=-99; eta_up_debug_[i]=-99; - ept_up_debug_[i]=-99; ephi_up_debug_[i]=-99; eeta_up_debug_[i]=-99; - invpt_up_debug_[i] =-99; theta_up_debug_[i] =-99; - einvpt_up_debug_[i]=-99; etheta_up_debug_[i]=-99; - - // reset eta/phi bin info - ebhit_debug_[i] = -99; ebp_debug_[i] = -99; ebm_debug_[i] = -99; - pbhit_debug_[i] = -99; pbp_debug_[i] = -99; pbm_debug_[i] = -99; - } -} - -void TTreeValidation::fillDebugTree(const Event& ev){ - std::lock_guard locker(glock_); - resetDebugTreeArrays(); - - auto& simtrack = ev.simTracks_[0]; // since it is the only one! - auto& seedtrack = ev.seedTracks_[0]; // since it is the only one! - auto& buildtrack = ev.candidateTracks_[0]; // since it is the only one! - - int mcID = simtrack.label(); - int seedID = ev.seedTracksExtra_[seedtrack.label()].seedID(); - - event_debug_ = ev.evtID(); - nHits_debug_ = buildtrack.nFoundHits(); - - recocharge_debug_ = seedtrack.charge(); - mccharge_debug_ = simtrack.charge(); - - // Set MC First - pt_gen_debug_ = simtrack.pT(); - phi_gen_debug_ = simtrack.momPhi(); - eta_gen_debug_ = simtrack.momEta(); - - x_gen_debug_ = simtrack.x(); - y_gen_debug_ = simtrack.y(); - z_gen_debug_ = simtrack.z(); - - auto& simhits = simtrack.hitsVector(ev.layerHits_); - for (int i = 0; i < simhits.size(); i++){ // assume one hit for layer for sim tracks... - layer_mc_debug_[i] = i; - - x_hit_debug_[i] = simhits[i].x(); - y_hit_debug_[i] = simhits[i].y(); - z_hit_debug_[i] = simhits[i].z(); - exx_hit_debug_[i] = simhits[i].exx(); - eyy_hit_debug_[i] = simhits[i].eyy(); - ezz_hit_debug_[i] = simhits[i].ezz(); - - // which eta/phi bin the hit belongs to - ebhit_debug_[i] = getEtaPartition(simhits[i].eta()); - pbhit_debug_[i] = getPhiPartition(simhits[i].phi()); - - const TrackState & mcstate = simTkTSVecMap_[mcID][i]; - x_mc_debug_[i] = mcstate.x(); - y_mc_debug_[i] = mcstate.y(); - z_mc_debug_[i] = mcstate.z(); - pt_mc_debug_[i] = mcstate.pT(); - phi_mc_debug_[i] = mcstate.momPhi(); - eta_mc_debug_[i] = mcstate.momEta(); - - px_mc_debug_[i] = mcstate.px(); - py_mc_debug_[i] = mcstate.py(); - pz_mc_debug_[i] = mcstate.pz(); - - invpt_mc_debug_[i] = mcstate.invpT(); - theta_mc_debug_[i] = mcstate.theta(); - } - - // CF next - const TrackState & cfSeedTS = seedTkCFMap_[seedID]; - x_cf_debug_ = cfSeedTS.x(); - y_cf_debug_ = cfSeedTS.y(); - z_cf_debug_ = cfSeedTS.z(); - exx_cf_debug_ = cfSeedTS.exx(); - eyy_cf_debug_ = cfSeedTS.eyy(); - ezz_cf_debug_ = cfSeedTS.ezz(); - - px_cf_debug_ = cfSeedTS.px(); - py_cf_debug_ = cfSeedTS.py(); - pz_cf_debug_ = cfSeedTS.pz(); - epxpx_cf_debug_ = cfSeedTS.epxpx(); - epypy_cf_debug_ = cfSeedTS.epypy(); - epzpz_cf_debug_ = cfSeedTS.epzpz(); - - pt_cf_debug_ = cfSeedTS.pT(); - phi_cf_debug_ = cfSeedTS.momPhi(); - eta_cf_debug_ = cfSeedTS.momEta(); - ept_cf_debug_ = cfSeedTS.epT(); - ephi_cf_debug_ = cfSeedTS.emomPhi(); - eeta_cf_debug_ = cfSeedTS.emomEta(); - - invpt_cf_debug_ = cfSeedTS.invpT(); - einvpt_cf_debug_ = cfSeedTS.einvpT(); - theta_cf_debug_ = cfSeedTS.theta(); - etheta_cf_debug_ = cfSeedTS.etheta(); - - // prop states - for (int i = 0; i < propTSLayerPairVec_.size(); i++){ - int layer = propTSLayerPairVec_[i].first; - layer_prop_debug_[layer] = layer; - - const TrackState & propTS = propTSLayerPairVec_[i].second; - x_prop_debug_[layer] = propTS.x(); - y_prop_debug_[layer] = propTS.y(); - z_prop_debug_[layer] = propTS.z(); - exx_prop_debug_[layer] = propTS.exx(); - eyy_prop_debug_[layer] = propTS.eyy(); - ezz_prop_debug_[layer] = propTS.ezz(); - - px_prop_debug_[layer] = propTS.px(); - py_prop_debug_[layer] = propTS.py(); - pz_prop_debug_[layer] = propTS.pz(); - epxpx_prop_debug_[layer] = propTS.epxpx(); - epypy_prop_debug_[layer] = propTS.epypy(); - epzpz_prop_debug_[layer] = propTS.epzpz(); - - pt_prop_debug_[layer] = propTS.pT(); - phi_prop_debug_[layer] = propTS.momPhi(); - eta_prop_debug_[layer] = propTS.momEta(); - ept_prop_debug_[layer] = propTS.epT(); - ephi_prop_debug_[layer] = propTS.emomPhi(); - eeta_prop_debug_[layer] = propTS.emomEta(); - - invpt_prop_debug_[layer] = propTS.invpT(); - einvpt_prop_debug_[layer] = propTS.einvpT(); - theta_prop_debug_[layer] = propTS.theta(); - etheta_prop_debug_[layer] = propTS.etheta(); - } - - // do the chi2 - for (int i = 0; i < chi2LayerPairVec_.size(); i++){ - int layer = chi2LayerPairVec_[i].first; - layer_chi2_debug_[layer] = layer; - chi2_debug_[layer] = chi2LayerPairVec_[i].second; - } - - // updated states - for (int i = 0; i < upTSLayerPairVec_.size(); i++){ - int layer = upTSLayerPairVec_[i].first; - layer_up_debug_[layer] = layer; - - const TrackState & upTS = upTSLayerPairVec_[i].second; - x_up_debug_[layer] = upTS.x(); - y_up_debug_[layer] = upTS.y(); - z_up_debug_[layer] = upTS.z(); - exx_up_debug_[layer] = upTS.exx(); - eyy_up_debug_[layer] = upTS.eyy(); - ezz_up_debug_[layer] = upTS.ezz(); - - px_up_debug_[layer] = upTS.px(); - py_up_debug_[layer] = upTS.py(); - pz_up_debug_[layer] = upTS.pz(); - epxpx_up_debug_[layer] = upTS.epxpx(); - epypy_up_debug_[layer] = upTS.epypy(); - epzpz_up_debug_[layer] = upTS.epzpz(); - - pt_up_debug_[layer] = upTS.pT(); - phi_up_debug_[layer] = upTS.momPhi(); - eta_up_debug_[layer] = upTS.momEta(); - ept_up_debug_[layer] = upTS.epT(); - ephi_up_debug_[layer] = upTS.emomPhi(); - eeta_up_debug_[layer] = upTS.emomEta(); - - invpt_up_debug_[layer] = upTS.invpT(); - einvpt_up_debug_[layer] = upTS.einvpT(); - theta_up_debug_[layer] = upTS.theta(); - etheta_up_debug_[layer] = upTS.etheta(); - } - - // see what it predicted! (reuse branchval) - for (TkIDToBVVMMIter seediter = seedToBranchValVecLayMapMap_.begin(); seediter != seedToBranchValVecLayMapMap_.end(); ++seediter){ - for (BVVLMiter layiter = (*seediter).second.begin(); layiter != (*seediter).second.end(); ++layiter){ - const auto& BranchValVec((*layiter).second); - const int cands = BranchValVec.size(); - int layer = (*layiter).first; // first index here is layer - for (int cand = 0; cand < cands; cand++){ // loop over input candidates at this layer for this seed - const auto& BranchVal(BranchValVec[cand]); // grab the branch validation object - - ebp_debug_[layer] = BranchVal.etaBinPlus; - ebm_debug_[layer] = BranchVal.etaBinMinus; - pbp_debug_[layer] = BranchVal.phiBinPlus; - pbm_debug_[layer] = BranchVal.phiBinMinus; - - } - } - } - - // fill it once per track (i.e. once per track by definition) - debugtree_->Fill(); -} - -void TTreeValidation::fillSegmentTree(const BinInfoMap& segmentMap, int evtID){ - std::lock_guard locker(glock_); - - evtID_seg_ = evtID; - for (int i = 0; i < Config::nLayers; i++) { - layer_seg_ = i; - for (int j = 0; j < Config::nEtaPart; j++) { - etabin_seg_ = j; - for (int k = 0; k < Config::nPhiPart; k++) { - phibin_seg_ = k; - nHits_seg_ = segmentMap[i][j][k].second; - - segtree_->Fill(); - } - } - } -} - -void TTreeValidation::fillSeedInfoTree(const TripletIdxVec& hit_triplets, const Event& ev) { - evtID_seedinfo_ = ev.evtID(); - - const auto & evt_lay_hits = ev.layerHits_; - - for (auto&& hitTriplet : hit_triplets) { - mcID_seedinfo_ = ev.simHitsInfo_[evt_lay_hits[0][hitTriplet[0]].mcHitID()].mcTrackID(); - if ( ev.simHitsInfo_[evt_lay_hits[1][hitTriplet[1]].mcHitID()].mcTrackID() == mcID_seedinfo_){ - if (ev.simHitsInfo_[evt_lay_hits[2][hitTriplet[2]].mcHitID()].mcTrackID() == mcID_seedinfo_){ - pt_gen_seedinfo_ = ev.simTracks_[mcID_seedinfo_].pT(); - eta_gen_seedinfo_ = ev.simTracks_[mcID_seedinfo_].momEta(); - phi_gen_seedinfo_ = ev.simTracks_[mcID_seedinfo_].momPhi(); - - const float x0 = evt_lay_hits[0][hitTriplet[0]].x(); - const float y0 = evt_lay_hits[0][hitTriplet[0]].y(); - const float x1 = evt_lay_hits[1][hitTriplet[1]].x(); - const float y1 = evt_lay_hits[1][hitTriplet[1]].y(); - const float x2 = evt_lay_hits[2][hitTriplet[2]].x(); - const float y2 = evt_lay_hits[2][hitTriplet[2]].y(); - - // now fit a circle, extract pT and d0 from center and radius - const float mr = (y1-y0)/(x1-x0); - const float mt = (y2-y1)/(x2-x1); - - a = (mr*mt*(y2-y0) + mr*(x1+x2) - mt*(x0+x1))/(2.*(mr-mt)); - b = -1.*(a-(x0+x1)/2.)/mr + (y0+y1)/2.; - r = getHypot(x0-a,y0-b); - d0 = getHypot(a,b)-r; - pass = false; - if ((r >= Config::maxCurvR) && (fabs(d0) <= 0.1)) { - pass = true; - } // d0 cut 1mm, pT cut 0.5 GeV - - seedinfotree_->Fill(); - } - } - } -} - -void TTreeValidation::fillSeedTree(const TripletIdxVec& hit_triplets, const TripletIdxVec& filtered_triplets, const Event& ev) { - evtID_seed_ = ev.evtID(); - const auto & evt_lay_hits = ev.layerHits_; - - int correct_all = 0; - for (auto&& hitTriplet : hit_triplets){ - if ( ev.simHitsInfo_[evt_lay_hits[0][hitTriplet[0]].mcHitID()].mcTrackID() == ev.simHitsInfo_[evt_lay_hits[1][hitTriplet[1]].mcHitID()].mcTrackID()){ - if (ev.simHitsInfo_[evt_lay_hits[2][hitTriplet[2]].mcHitID()].mcTrackID() == ev.simHitsInfo_[evt_lay_hits[1][hitTriplet[1]].mcHitID()].mcTrackID()){ - correct_all++; - } - } - } - nTkAll_ = hit_triplets.size(); - nTkAllMC_ = correct_all; - - int correct_cut = 0; - for (auto&& hitTriplet : filtered_triplets){ - if ( ev.simHitsInfo_[evt_lay_hits[0][hitTriplet[0]].mcHitID()].mcTrackID() == ev.simHitsInfo_[evt_lay_hits[1][hitTriplet[1]].mcHitID()].mcTrackID()){ - if (ev.simHitsInfo_[evt_lay_hits[2][hitTriplet[2]].mcHitID()].mcTrackID() == ev.simHitsInfo_[evt_lay_hits[1][hitTriplet[1]].mcHitID()].mcTrackID()){ - correct_cut++; - } - } - } - nTkCut_ = filtered_triplets.size(); - nTkCutMC_ = correct_cut; - - seedtree_->Fill(); -} - -void TTreeValidation::fillBranchTree(int evtID) -{ - std::lock_guard locker(glock_); - - evtID_br_ = evtID; - for (TkIDToBVVMMIter seediter = seedToBranchValVecLayMapMap_.begin(); seediter != seedToBranchValVecLayMapMap_.end(); ++seediter){ - seedID_br_ = (*seediter).first; - for (BVVLMiter layiter = (*seediter).second.begin(); layiter != (*seediter).second.end(); ++layiter){ - const auto& BranchValVec((*layiter).second); - const int cands = BranchValVec.size(); - layer_ = (*layiter).first; // first index here is layer - - // clear vectors before filling - candEtaPhiBins_.clear(); - candHits_.clear(); - candBranches_.clear(); - candnSigmaDeta_.clear(); - candnSigmaDphi_.clear(); - - // totals - std::vector candEtaPhiBins(cands); - std::vector candHits(cands); - std::vector candBranches(cands); - - // unique hits, etaphibins, branches... - std::unordered_map uniqueEtaPhiBins; // once a bin, branch, hit is used, set to true to count it only once. take size of map as "uniques" - std::unordered_map uniqueHits; - std::unordered_map uniqueBranches; - - // nSigmaDeta/phi vec - std::vector candnSigmaDeta(cands); - std::vector candnSigmaDphi(cands); - - for (int cand = 0; cand < cands; cand++){ // loop over input candidates at this layer for this seed - const auto& BranchVal(BranchValVec[cand]); // grab the branch validation object - - //////////////////////////////////// - // EtaPhiBins Explored Counting // - //////////////////////////////////// - - // set values for total etaphibins explored per candidate, also unique ones for all candidates - if (BranchVal.phiBinPlus >= BranchVal.phiBinMinus){ // count the number of eta/phi bins explored if no phi wrapping - candEtaPhiBins[cand] = (BranchVal.etaBinPlus-BranchVal.etaBinMinus+1)*(BranchVal.phiBinPlus-BranchVal.phiBinMinus+1); // total etaphibins for this candidate - - // no phi wrap to count uniques - for (int ibin = BranchVal.phiBinMinus; ibin <= BranchVal.phiBinPlus; ibin++){ - uniqueEtaPhiBins[ibin] = true; - } - } - else{ // if phi wrapping, count need to do this obnoxious counting - candEtaPhiBins[cand] = (BranchVal.etaBinPlus-BranchVal.etaBinMinus+1)*(Config::nPhiPart-BranchVal.phiBinMinus+BranchVal.phiBinPlus+1); // total etaphibins for this candidate with phi wrapping - - // use phi wrapping to count uniques - for (int ibin = BranchVal.phiBinMinus; ibin < Config::nPhiPart; ibin++){ - uniqueEtaPhiBins[ibin] = true; - } - for (int ibin = 0; ibin <= BranchVal.phiBinPlus; ibin++){ - uniqueEtaPhiBins[ibin] = true; - } - } - - ////////////////////////////// - // Hits Explored Counting // - ////////////////////////////// - - candHits[cand] = BranchVal.cand_hit_indices.size(); // set value of nHits explored per input cand for this seed+layer - for (auto&& cand_hit_idx : BranchVal.cand_hit_indices){ // save unique hits - uniqueHits[cand_hit_idx] = true; - } - - ///////////////////////////////// - // Branches Created Counting // - ///////////////////////////////// - - candBranches[cand] = BranchVal.branch_hit_indices.size(); // set values for total branches created per input candidate before chi2 max cand cleaning (for this seed+layer) - for (auto&& branch_hit_idx : BranchVal.branch_hit_indices){ // save unique branches --> only consider adding one ghost temp per input? - uniqueBranches[branch_hit_idx] = true; - } - - // store the parameters for width of eta/phi windows for this input candidates building - - candnSigmaDeta[cand] = BranchVal.nSigmaDeta; - candnSigmaDphi[cand] = BranchVal.nSigmaDphi; - } // end loop over input candidates for given seed/layer - - // fill the rest of the tree after identifying uniques - - cands_ = cands; - - // will use these to create total plots (once summed by looping over the vectors), and make per input candidate by looping over these vectors individually - - candEtaPhiBins_ = candEtaPhiBins; - candHits_ = candHits; - candBranches_ = candBranches; - - // will use this directly to make unique plots by just taking the size of these unordered maps with "trues" - - uniqueEtaPhiBins_ = uniqueEtaPhiBins.size(); - uniqueHits_ = uniqueHits.size(); - uniqueBranches_ = uniqueBranches.size(); - - // will normalize to equal area, loop over vectors to plot directly - - candnSigmaDeta_ = candnSigmaDeta; - candnSigmaDphi_ = candnSigmaDphi; - - tree_br_->Fill(); // fill once per layer per seed - } // end loop over layers - } // end loop over seeds -} - void TTreeValidation::resetFitBranches() { - for(int ilayer = 0; ilayer < Config::nLayers; ++ilayer) + for(int ilayer = 0; ilayer < Config::nTotalLayers; ++ilayer) { z_prop_fit_[ilayer] = -1000.f; ez_prop_fit_[ilayer] = -1000.f; @@ -1355,7 +532,7 @@ void TTreeValidation::fillFitTree(const Event& ev) const auto& initTSs = simTkTSVecMap_[tkid_fit_]; auto& fitvalmap = fitvalmapmap.second; - for(int ilayer = 0; ilayer < Config::nLayers; ++ilayer) + for(int ilayer = 0; ilayer < Config::nTotalLayers; ++ilayer) { if (fitvalmap.count(ilayer)) { @@ -1397,7 +574,8 @@ void TTreeValidation::fillFitTree(const Event& ev) } } -void TTreeValidation::fillEfficiencyTree(const Event& ev){ +void TTreeValidation::fillEfficiencyTree(const Event& ev) +{ std::lock_guard locker(glock_); auto ievt = ev.evtID(); @@ -1409,7 +587,8 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev){ auto& evt_fit_tracks = ev.fitTracks_; auto& evt_fit_extras = ev.fitTracksExtra_; - for (auto&& simtrack : evt_sim_tracks){ + for (auto&& simtrack : evt_sim_tracks) + { evtID_eff_ = ievt; mcID_eff_ = simtrack.label(); @@ -1420,7 +599,8 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev){ nHits_mc_eff_ = simtrack.nFoundHits(); // could be that the sim track skips layers! // matched seed track - if (simToSeedMap_.count(mcID_eff_)){ // recoToSim match : save best match --> most hits, lowest chi2, i.e. simToSeedMap_[matched SimID][first element in vector] + if (simToSeedMap_.count(mcID_eff_)) // recoToSim match : save best match --> most hits, lowest chi2, i.e. simToSeedMap_[matched SimID][first element in vector] + { auto& seedtrack = evt_seed_tracks[simToSeedMap_[mcID_eff_][0]]; // returns seedTrack best matched to sim track auto& seedextra = evt_seed_extras[seedtrack.label()]; // returns track extra best aligned with seed track mcmask_seed_eff_ = 1; // quick logic for matched @@ -1453,7 +633,8 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev){ duplmask_seed_eff_ = seedextra.isDuplicate(); nTkMatches_seed_eff_ = simToSeedMap_[mcID_eff_].size(); // n reco matches to this sim track. } - else{ // unmatched simTracks ... put -99 for all reco values to denote unmatched + else // unmatched simTracks ... put -99 for all reco values to denote unmatched + { mcmask_seed_eff_ = 0; // quick logic for not matched seedID_seed_eff_ = -99; @@ -1481,7 +662,8 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev){ } // matched build track - if (simToBuildMap_.count(mcID_eff_)){ // recoToSim match : save best match --> most hits, lowest chi2, i.e. simToBuildMap_[matched SimID][first element in vector] + if (simToBuildMap_.count(mcID_eff_)) // recoToSim match : save best match --> most hits, lowest chi2, i.e. simToBuildMap_[matched SimID][first element in vector] + { auto& buildtrack = evt_build_tracks[simToBuildMap_[mcID_eff_][0]]; // returns buildTrack best matched to sim track auto& buildextra = evt_build_extras[buildtrack.label()]; // returns track extra best aligned with build track mcmask_build_eff_ = 1; // quick logic for matched @@ -1513,7 +695,8 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev){ duplmask_build_eff_ = buildextra.isDuplicate(); nTkMatches_build_eff_ = simToBuildMap_[mcID_eff_].size(); // n reco matches to this sim track. } - else{ // unmatched simTracks ... put -99 for all reco values to denote unmatched + else // unmatched simTracks ... put -99 for all reco values to denote unmatched + { mcmask_build_eff_ = 0; // quick logic for not matched seedID_build_eff_ = -99; @@ -1541,7 +724,8 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev){ } // matched fit track - if (simToFitMap_.count(mcID_eff_)){ // recoToSim match : save best match --> most hits, lowest chi2, i.e. simToFitMap_[matched SimID][first element in vector] + if (simToFitMap_.count(mcID_eff_)) // recoToSim match : save best match --> most hits, lowest chi2, i.e. simToFitMap_[matched SimID][first element in vector] + { auto& fittrack = evt_fit_tracks[simToFitMap_[mcID_eff_][0]]; // returns fitTrack best matched to sim track auto& fitextra = evt_fit_extras[fittrack.label()]; // returns track extra best aligned with fit track mcmask_fit_eff_ = 1; // quick logic for matched @@ -1579,7 +763,8 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev){ duplmask_fit_eff_ = fitextra.isDuplicate(); nTkMatches_fit_eff_ = simToFitMap_[mcID_eff_].size(); // n reco matches to this sim track. } - else{ // unmatched simTracks ... put -99 for all reco values to denote unmatched + else // unmatched simTracks ... put -99 for all reco values to denote unmatched + { mcmask_fit_eff_ = 0; // quick logic for not matched seedID_fit_eff_ = -99; @@ -1610,7 +795,8 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev){ } } -void TTreeValidation::fillFakeRateTree(const Event& ev){ +void TTreeValidation::fillFakeRateTree(const Event& ev) +{ std::lock_guard locker(glock_); auto ievt = ev.evtID(); @@ -1621,7 +807,8 @@ void TTreeValidation::fillFakeRateTree(const Event& ev){ auto& evt_fit_tracks = ev.fitTracks_; auto& evt_fit_extras = ev.fitTracksExtra_; - for (auto&& seedtrack : evt_seed_tracks){ + for (auto&& seedtrack : evt_seed_tracks) + { evtID_FR_ = ievt; auto& seedextra = evt_seed_extras[seedtrack.label()]; seedID_FR_ = seedextra.seedID(); @@ -1644,7 +831,8 @@ void TTreeValidation::fillFakeRateTree(const Event& ev){ // sim info for seed track mcID_seed_FR_ = seedextra.mcTrackID(); - if (mcID_seed_FR_ >= 0){ // store sim info at that final layer!!! --> gen info stored only in eff tree + if (mcID_seed_FR_ >= 0) // store sim info at that final layer!!! --> gen info stored only in eff tree + { mcmask_seed_FR_ = 1; // matched track to sim const int layer = seedtrack.foundLayers().back(); // last layer fit ended up on @@ -1660,7 +848,8 @@ void TTreeValidation::fillFakeRateTree(const Event& ev){ duplmask_seed_FR_ = seedextra.isDuplicate(); iTkMatches_seed_FR_ = seedextra.duplicateID(); // ith duplicate seed track, i = 0 "best" match, i > 0 "still matched, real reco, not as good as i-1 track" } - else{ + else + { mcmask_seed_FR_ = 0; // fake track (unmatched track) // -99 for all sim info for reco tracks not associated to reco tracks @@ -1676,7 +865,8 @@ void TTreeValidation::fillFakeRateTree(const Event& ev){ //==========================// // fill build information if track still alive - if (seedToBuildMap_.count(seedID_FR_)){ + if (seedToBuildMap_.count(seedID_FR_)) + { seedmask_build_FR_ = 1; // quick logic auto& buildtrack = evt_build_tracks[seedToBuildMap_[seedID_FR_]]; @@ -1697,7 +887,8 @@ void TTreeValidation::fillFakeRateTree(const Event& ev){ // sim info for build track mcID_build_FR_ = buildextra.mcTrackID(); - if (mcID_build_FR_ >= 0){ // build track matched to seed and sim + if (mcID_build_FR_ >= 0) // build track matched to seed and sim + { mcmask_build_FR_ = 1; // matched track to sim const int layer = buildtrack.foundLayers().back(); // last layer fit ended up on @@ -1713,7 +904,8 @@ void TTreeValidation::fillFakeRateTree(const Event& ev){ duplmask_build_FR_ = buildextra.isDuplicate(); iTkMatches_build_FR_ = buildextra.duplicateID(); // ith duplicate build track, i = 0 "best" match, i > 0 "still matched, real reco, not as good as i-1 track" } - else{ // build track matched only to seed not to sim + else // build track matched only to seed not to sim + { mcmask_build_FR_ = 0; // fake track (unmatched track) // -99 for all sim info for reco tracks not associated to reco tracks @@ -1727,7 +919,8 @@ void TTreeValidation::fillFakeRateTree(const Event& ev){ } // matched seed to build, not build to sim } - else { // seed has no matching build track (therefore no matching sim to build track) + else // seed has no matching build track (therefore no matching sim to build track) + { seedmask_build_FR_ = 0; // quick logic // -100 for all reco info as no actual build track for this seed @@ -1760,7 +953,8 @@ void TTreeValidation::fillFakeRateTree(const Event& ev){ } //============================// fit tracks - if (seedToFitMap_.count(seedID_FR_)){ + if (seedToFitMap_.count(seedID_FR_)) + { seedmask_fit_FR_ = 1; // quick logic auto& fittrack = evt_fit_tracks[seedToFitMap_[seedID_FR_]]; @@ -1781,7 +975,8 @@ void TTreeValidation::fillFakeRateTree(const Event& ev){ // sim info for fit track mcID_fit_FR_ = fitextra.mcTrackID(); - if (mcID_fit_FR_ >= 0){ // fit track matched to seed and sim + if (mcID_fit_FR_ >= 0) // fit track matched to seed and sim + { mcmask_fit_FR_ = 1; // matched track to sim #ifdef INWARDFIT const int layer = fittrack.foundLayers().front(); // last layer fiting ended up on @@ -1800,7 +995,8 @@ void TTreeValidation::fillFakeRateTree(const Event& ev){ duplmask_fit_FR_ = fitextra.isDuplicate(); iTkMatches_fit_FR_ = fitextra.duplicateID(); // ith duplicate fit track, i = 0 "best" match, i > 0 "still matched, real reco, not as good as i-1 track" } - else{ // fit track matched only to seed not to sim + else // fit track matched only to seed not to sim + { mcmask_fit_FR_ = 0; // fake track (unmatched track) // -99 for all sim info for reco tracks not associated to reco tracks @@ -1814,7 +1010,8 @@ void TTreeValidation::fillFakeRateTree(const Event& ev){ } // matched seed to fit, not fit to sim } - else { // seed has no matching fit track (therefore no matching sim to fit track) + else // seed has no matching fit track (therefore no matching sim to fit track) + { seedmask_fit_FR_ = 0; // quick logic // -100 for all reco info as no actual fit track for this seed @@ -1850,328 +1047,8 @@ void TTreeValidation::fillFakeRateTree(const Event& ev){ }// end of seed to seed loop } -void TTreeValidation::fillGeometryTree(const Event& ev){ - std::lock_guard locker(glock_); - - auto ievt = ev.evtID(); - auto& evt_sim_tracks = ev.simTracks_; - auto& evt_seed_tracks = ev.seedTracks_; - auto& evt_seed_extras = ev.seedTracksExtra_; - auto& evt_fit_tracks = ev.fitTracks_; - auto& evt_fit_extras = ev.fitTracksExtra_; - auto& evt_lay_hits = ev.layerHits_; - - for (auto&& simtrack : evt_sim_tracks){ - evtID_geo_ = ievt; - mcID_geo_ = simtrack.label(); - - // for Beamspot plots - x_mc_gen_vrx_geo_ = simtrack.x(); - y_mc_gen_vrx_geo_ = simtrack.y(); - z_mc_gen_vrx_geo_ = simtrack.z(); - - // clear for detector sim plots - x_mc_reco_hit_geo_.clear(); - y_mc_reco_hit_geo_.clear(); - z_mc_reco_hit_geo_.clear(); - for (auto&& simhit : simtrack.hitsVector(evt_lay_hits)){ // assume one hit per layer - x_mc_reco_hit_geo_.push_back(simhit.x()); - y_mc_reco_hit_geo_.push_back(simhit.y()); - z_mc_reco_hit_geo_.push_back(simhit.z()); - } - - // clear vectors for position pulls - layers_seed_geo_.clear(); - x_lay_seed_geo_.clear(); - y_lay_seed_geo_.clear(); - z_lay_seed_geo_.clear(); - ex_lay_seed_geo_.clear(); - ey_lay_seed_geo_.clear(); - ez_lay_seed_geo_.clear(); - - layers_fit_geo_.clear(); - x_lay_fit_geo_.clear(); - y_lay_fit_geo_.clear(); - z_lay_fit_geo_.clear(); - ex_lay_fit_geo_.clear(); - ey_lay_fit_geo_.clear(); - ez_lay_fit_geo_.clear(); - - // matched seed track - if (simToSeedMap_.count(mcID_geo_)){ // recoToSim match : save best match --> most hits, lowest chi2, i.e. simToSeedMap_[matched SimID][first element in vector] - auto& seedtrack = evt_seed_tracks[simToSeedMap_[mcID_geo_][0]]; // returns seedTrack best matched to sim track - auto& seedextra = evt_seed_extras[seedtrack.label()]; // returns track extra best aligned with seed track - mcmask_seed_geo_ = 1; // quick logic for matched - - seedID_seed_geo_ = seedextra.seedID(); - - // position pull info - const TSLayerPairVec & seedTSLayerPairVec = seedTkTSLayerPairVecMap_[seedID_seed_geo_]; - for (int ilay = 0; ilay < seedTSLayerPairVec.size(); ilay++){ // loop over layers present in pair vector - layers_seed_geo_.push_back(seedTSLayerPairVec[ilay].first); // want to push back the ACTUAL layers stored, not the index of the loop! - - x_lay_seed_geo_.push_back(seedTSLayerPairVec[ilay].second.x()); // therefore, trackstate filled in sync with the layer it was saved on for the vector - y_lay_seed_geo_.push_back(seedTSLayerPairVec[ilay].second.y()); - z_lay_seed_geo_.push_back(seedTSLayerPairVec[ilay].second.z()); - - ex_lay_seed_geo_.push_back(seedTSLayerPairVec[ilay].second.exx()); - ey_lay_seed_geo_.push_back(seedTSLayerPairVec[ilay].second.eyy()); - ez_lay_seed_geo_.push_back(seedTSLayerPairVec[ilay].second.ezz()); - } - } - else{ // unmatched sim track for any seed track - layers_seed_geo_.push_back(-1); // mask per layer - - x_lay_seed_geo_.push_back(-2000); - y_lay_seed_geo_.push_back(-2000); - z_lay_seed_geo_.push_back(-2000); - - ex_lay_seed_geo_.push_back(-2000); - ey_lay_seed_geo_.push_back(-2000); - ez_lay_seed_geo_.push_back(-2000); - } - - if (simToFitMap_.count(mcID_geo_)){ // recoToSim match : save best match --> most hits, lowest chi2, i.e. simToFitMap_[matched SimID][first element in vector] - auto& fittrack = evt_fit_tracks[simToFitMap_[mcID_geo_][0]]; // returns fitTrack best matched to sim track - auto& fitextra = evt_fit_extras[fittrack.label()]; // returns track extra best aligned with fit track - mcmask_fit_geo_ = 1; // quick logic for matched - - seedID_fit_geo_ = fitextra.seedID(); - - // position pull info - const TSLayerPairVec & fitTSLayerPairVec = fitTkTSLayerPairVecMap_[seedID_fit_geo_]; - for (int ilay = 0; ilay < fitTSLayerPairVec.size(); ilay++){ // loop over layers present in pair vector - layers_fit_geo_.push_back(fitTSLayerPairVec[ilay].first); // want to push back the ACTUAL layers stored, not the index of the loop! - - x_lay_fit_geo_.push_back(fitTSLayerPairVec[ilay].second.x()); // therefore, trackstate filled in sync with the layer it was saved on for the vector - y_lay_fit_geo_.push_back(fitTSLayerPairVec[ilay].second.y()); - z_lay_fit_geo_.push_back(fitTSLayerPairVec[ilay].second.z()); - - ex_lay_fit_geo_.push_back(fitTSLayerPairVec[ilay].second.exx()); - ey_lay_fit_geo_.push_back(fitTSLayerPairVec[ilay].second.eyy()); - ez_lay_fit_geo_.push_back(fitTSLayerPairVec[ilay].second.ezz()); - } - } - else{ - layers_fit_geo_.push_back(-1); // mask per layer - - x_lay_fit_geo_.push_back(-2000); - y_lay_fit_geo_.push_back(-2000); - z_lay_fit_geo_.push_back(-2000); - - ex_lay_fit_geo_.push_back(-2000); - ey_lay_fit_geo_.push_back(-2000); - ez_lay_fit_geo_.push_back(-2000); - } - geotree_->Fill(); // fill once per sim track - } -} - -void TTreeValidation::fillConformalTree(const Event& ev){ - std::lock_guard locker(glock_); - - auto ievt = ev.evtID(); - auto& evt_sim_tracks = ev.simTracks_; - auto& evt_seed_tracks = ev.seedTracks_; - auto& evt_seed_extras = ev.seedTracksExtra_; - auto& evt_fit_tracks = ev.fitTracks_; - auto& evt_fit_extras = ev.fitTracksExtra_; - //auto& evt_lay_hits = ev.layerHits_; - - for (auto&& simtrack : evt_sim_tracks){ - evtID_cf_ = ievt; - mcID_cf_ = simtrack.label(); - - if (simToSeedMap_.count(mcID_cf_)){ // recoToSim match : save best match --> most hits, lowest chi2, i.e. simToSeedMap_[matched SimID][first element in vector] - auto& seedtrack = evt_seed_tracks[simToSeedMap_[mcID_cf_][0]]; // returns seedTrack best matched to sim track - auto& seedextra = evt_seed_extras[seedtrack.label()]; // returns track extra best aligned with seed track - mcmask_seed_cf_ = 1; // quick logic for matched - - seedID_seed_cf_ = seedextra.seedID(); - - // Conformal fit stuff to match how it was done before - const int cflayer = seedtrack.foundLayers().front(); // layer for which cf parameters are calculated with respect to (either first or last layer of track!) - const TrackState & cfInitLayTS = simTkTSVecMap_[mcID_cf_][cflayer]; //--> can do this as all sim tracks pass through each layer once, and are stored in order... will need to fix this once we have loopers/overlaps - x_mc_seed_cf_ = cfInitLayTS.x(); - y_mc_seed_cf_ = cfInitLayTS.y(); - z_mc_seed_cf_ = cfInitLayTS.z(); - - px_mc_seed_cf_ = cfInitLayTS.px(); - py_mc_seed_cf_ = cfInitLayTS.py(); - pz_mc_seed_cf_ = cfInitLayTS.pz(); - - pt_mc_seed_cf_ = cfInitLayTS.pT(); - invpt_mc_seed_cf_ = cfInitLayTS.invpT(); - phi_mc_seed_cf_ = cfInitLayTS.momPhi(); - theta_mc_seed_cf_ = cfInitLayTS.theta(); - - const TrackState & cfSeedTS = seedTkCFMap_[seedID_seed_cf_]; - - x_seed_cf_ = cfSeedTS.x(); - y_seed_cf_ = cfSeedTS.y(); - z_seed_cf_ = cfSeedTS.z(); - - ex_seed_cf_ = cfSeedTS.exx(); - ey_seed_cf_ = cfSeedTS.eyy(); - ez_seed_cf_ = cfSeedTS.ezz(); - - px_seed_cf_ = cfSeedTS.px(); - py_seed_cf_ = cfSeedTS.py(); - pz_seed_cf_ = cfSeedTS.pz(); - epx_seed_cf_ = cfSeedTS.epxpx(); - epy_seed_cf_ = cfSeedTS.epypy(); - epz_seed_cf_ = cfSeedTS.epzpz(); - - pt_seed_cf_ = cfSeedTS.pT(); - invpt_seed_cf_ = cfSeedTS.invpT(); - phi_seed_cf_ = cfSeedTS.momPhi(); - theta_seed_cf_ = cfSeedTS.theta(); - - ept_seed_cf_ = cfSeedTS.epT(); - einvpt_seed_cf_ = cfSeedTS.einvpT(); - ephi_seed_cf_ = cfSeedTS.emomPhi(); - etheta_seed_cf_ = cfSeedTS.etheta(); - } - else{ // no matched seed form sim - x_mc_seed_cf_ = -2000; - y_mc_seed_cf_ = -2000; - z_mc_seed_cf_ = -2000; - - px_mc_seed_cf_ = -99; - py_mc_seed_cf_ = -99; - pz_mc_seed_cf_ = -99; - - pt_mc_seed_cf_ = -99; - invpt_mc_seed_cf_ = -99; - phi_mc_seed_cf_ = -99; - theta_mc_seed_cf_ = -99; - - x_seed_cf_ = -2000; - y_seed_cf_ = -2000; - z_seed_cf_ = -2000; - - ex_seed_cf_ = -2000; - ey_seed_cf_ = -2000; - ez_seed_cf_ = -2000; - - px_seed_cf_ = -99; - py_seed_cf_ = -99; - pz_seed_cf_ = -99; - - epx_seed_cf_ = -99; - epy_seed_cf_ = -99; - epz_seed_cf_ = -99; - - pt_seed_cf_ = -99; - invpt_seed_cf_ = -99; - phi_seed_cf_ = -99; - theta_seed_cf_ = -99; - - ept_seed_cf_ = -99; - einvpt_seed_cf_ = -99; - ephi_seed_cf_ = -99; - etheta_seed_cf_ = -99; - } - - if (simToFitMap_.count(mcID_cf_)){ // recoToSim match : save best match --> most hits, lowest chi2, i.e. simToFitMap_[matched SimID][first element in vector] - auto& fittrack = evt_fit_tracks[simToFitMap_[mcID_cf_][0]]; // returns fitTrack best matched to sim track - auto& fitextra = evt_fit_extras[fittrack.label()]; // returns track extra best aligned with fit track - mcmask_fit_cf_ = 1; // quick logic for matched - - seedID_fit_cf_ = fitextra.seedID(); - - // Conformal fit stuff to match how it was done before -#ifdef INWARDFIT - const int cflayer = fittrack.foundLayers().back(); // last layer fit ended up on -#else - const int cflayer = fittrack.foundLayers().front(); // last layer fit ended up on -#endif - const TrackState & cfInitLayTS = simTkTSVecMap_[mcID_cf_][cflayer]; //--> can do this as all sim tracks pass through each layer once, and are stored in order... will need to fix this once we have loopers/overlaps - x_mc_fit_cf_ = cfInitLayTS.x(); - y_mc_fit_cf_ = cfInitLayTS.y(); - z_mc_fit_cf_ = cfInitLayTS.z(); - - px_mc_fit_cf_ = cfInitLayTS.px(); - py_mc_fit_cf_ = cfInitLayTS.py(); - pz_mc_fit_cf_ = cfInitLayTS.pz(); - - pt_mc_fit_cf_ = cfInitLayTS.pT(); - invpt_mc_fit_cf_ = cfInitLayTS.invpT(); - phi_mc_fit_cf_ = cfInitLayTS.momPhi(); - theta_mc_fit_cf_ = cfInitLayTS.theta(); - - const TrackState & cfFitTS = fitTkCFMap_[seedID_fit_cf_]; - - x_fit_cf_ = cfFitTS.x(); - y_fit_cf_ = cfFitTS.y(); - z_fit_cf_ = cfFitTS.z(); - - ex_fit_cf_ = cfFitTS.exx(); - ey_fit_cf_ = cfFitTS.eyy(); - ez_fit_cf_ = cfFitTS.ezz(); - - px_fit_cf_ = cfFitTS.px(); - py_fit_cf_ = cfFitTS.py(); - pz_fit_cf_ = cfFitTS.pz(); - epx_fit_cf_ = cfFitTS.epxpx(); - epy_fit_cf_ = cfFitTS.epypy(); - epz_fit_cf_ = cfFitTS.epzpz(); - - pt_fit_cf_ = cfFitTS.pT(); - invpt_fit_cf_ = cfFitTS.invpT(); - phi_fit_cf_ = cfFitTS.momPhi(); - theta_fit_cf_ = cfFitTS.theta(); - - ept_fit_cf_ = cfFitTS.epT(); - einvpt_fit_cf_ = cfFitTS.einvpT(); - ephi_fit_cf_ = cfFitTS.emomPhi(); - etheta_fit_cf_ = cfFitTS.etheta(); - } - else{ // no matched fit form sim - x_mc_fit_cf_ = -2000; - y_mc_fit_cf_ = -2000; - z_mc_fit_cf_ = -2000; - - px_mc_fit_cf_ = -99; - py_mc_fit_cf_ = -99; - pz_mc_fit_cf_ = -99; - - pt_mc_fit_cf_ = -99; - invpt_mc_fit_cf_ = -99; - phi_mc_fit_cf_ = -99; - theta_mc_fit_cf_ = -99; - - x_fit_cf_ = -2000; - y_fit_cf_ = -2000; - z_fit_cf_ = -2000; - - ex_fit_cf_ = -2000; - ey_fit_cf_ = -2000; - ez_fit_cf_ = -2000; - - px_fit_cf_ = -99; - py_fit_cf_ = -99; - pz_fit_cf_ = -99; - - epx_fit_cf_ = -99; - epy_fit_cf_ = -99; - epz_fit_cf_ = -99; - - pt_fit_cf_ = -99; - invpt_fit_cf_ = -99; - phi_fit_cf_ = -99; - theta_fit_cf_ = -99; - - ept_fit_cf_ = -99; - einvpt_fit_cf_ = -99; - ephi_fit_cf_ = -99; - etheta_fit_cf_ = -99; - } - cftree_->Fill(); - } -} - -void TTreeValidation::fillConfigTree(){ +void TTreeValidation::fillConfigTree() +{ Ntracks_ = Config::nTracks; Nevents_ = Config::nEvents; @@ -2220,18 +1097,8 @@ void TTreeValidation::fillConfigTree(){ configtree_->Fill(); } -void TTreeValidation::fillTimeTree(const std::vector& ticks){ - simtime_ = ticks[0]; - segtime_ = ticks[1]; - seedtime_ = ticks[2]; - buildtime_ = ticks[3]; - fittime_ = ticks[4]; - hlvtime_ = ticks[5]; - - timetree_->Fill(); -} - -void TTreeValidation::saveTTrees() { +void TTreeValidation::saveTTrees() +{ std::lock_guard locker(glock_); f_->cd(); f_->Write(); diff --git a/TTreeValidation.h b/TTreeValidation.h index f1fab92430b0e..7a4b55372777a 100644 --- a/TTreeValidation.h +++ b/TTreeValidation.h @@ -16,30 +16,6 @@ class TTreeValidation : public Validation { #include "TTree.h" #include "TROOT.h" -// branching valiation typedefs -struct BranchVal -{ -public: - BranchVal() {} - float nSigmaDeta; - float nSigmaDphi; - - int etaBinMinus; - int etaBinPlus; - int phiBinMinus; - int phiBinPlus; - - std::vector cand_hit_indices; - std::vector branch_hit_indices; // size of was just branches -}; - -// Branch Tree type definitions -typedef std::vector BranchValVec; -typedef std::unordered_map BranchValVecLayMap; -typedef std::unordered_map TkIDToBranchValVecLayMapMap; -typedef TkIDToBranchValVecLayMapMap::iterator TkIDToBVVMMIter; -typedef BranchValVecLayMap::iterator BVVLMiter; - // FitVal defined in Validation.h typedef std::map FitValLayMap; typedef std::unordered_map TkIDtoFitValLayMapMap; @@ -49,38 +25,17 @@ class TTreeValidation : public Validation { TTreeValidation(std::string fileName); ~TTreeValidation(); - void initializeDebugTree(); - void initializeSeedInfoTree(); - void initializeSeedTree(); - void initializeSegmentTree(); - void initializeBranchTree(); void initializeEfficiencyTree(); void initializeFakeRateTree(); - void initializeGeometryTree(); - void initializeConformalTree(); void initializeConfigTree(); - void initializeTimeTree(); void initializeFitTree(); void alignTrackExtra(TrackVec& evt_tracks, TrackExtraVec& evt_extra) override; void collectSimTkTSVecMapInfo(int mcTrackID, const TSVec& initTSs) override; - void collectSeedTkCFMapInfo(int seedID, const TrackState& cfitStateHit0) override; - void collectSeedTkTSLayerPairVecMapInfo(int seedID, const TSLayerPairVec& updatedStates) override; - void collectBranchingInfo(int seedID, int ilayer, - float nSigmaDeta, float etaBinMinus, int etaBinPlus, - float nSigmaDphi, int phiBinMinus, int phiBinPlus, - const std::vector& cand_hit_indices, const std::vector& cand_hits_branches) override; - void collectFitTkCFMapInfo(int seedID, const TrackState& cfitStateHit0) override; - void collectFitTkTSLayerPairVecMapInfo(int seedID, const TSLayerPairVec& updatedStates) override; void collectFitInfo(const FitVal& tmpfitval, int tkid, int layer) override; - void collectPropTSLayerVecInfo(int layer, const TrackState& propTS) override; - void collectChi2LayerVecInfo(int layer, float chi2) override; - void collectUpTSLayerVecInfo(int layer, const TrackState& upTS) override; void resetValidationMaps() override; - void resetDebugVectors() override; - void resetDebugTreeArrays(); void resetFitBranches(); void setTrackExtras(Event& ev) override; @@ -92,36 +47,17 @@ class TTreeValidation : public Validation { void makeSeedTkToRecoTkMaps(Event& ev) override; void mapSeedTkToRecoTk(const TrackVec& evt_tracks, const TrackExtraVec& evt_extras, TkIDToTkIDMap& seedTkMap); - void fillDebugTree(const Event& ev) override; - void fillSeedInfoTree(const TripletIdxVec& hit_triplets, const Event& ev) override; - void fillSeedTree(const TripletIdxVec& hit_triplets, const TripletIdxVec& filtered_triplets, const Event& ev) override; - void fillSegmentTree(const BinInfoMap& segmentMap, int evtID) override; - void fillBranchTree(int evtID) override; void fillEfficiencyTree(const Event& ev) override; void fillFakeRateTree(const Event& ev) override; - void fillGeometryTree(const Event& ev) override; - void fillConformalTree(const Event& ev) override; void fillConfigTree() override; - void fillTimeTree(const std::vector& ticks) override; void fillFitTree(const Event& ev) override; void saveTTrees() override; private: TFile* f_; // output file! - - TkIDToTSLayerPairVecMap seedTkTSLayerPairVecMap_; // used for position pulls for seed track - TkIDToTSLayerPairVecMap fitTkTSLayerPairVecMap_; // used for position pulls for fit track - TkIDToBranchValVecLayMapMap seedToBranchValVecLayMapMap_; // map created inside collectBranchingInfo - TSLayerPairVec propTSLayerPairVec_; // used exclusively for debugtree (prop states) - FltLayerPairVec chi2LayerPairVec_; // used exclusively for debugtree - TSLayerPairVec upTSLayerPairVec_; // used exclusively for debugtree (updated states) - TkIDToTSVecMap simTkTSVecMap_; // used for pulls (map all sim track TS to sim ID) ... also used in super debug mode - TkIDToTSMap seedTkCFMap_; // map CF TS to seedID of seed track ... also used in super debug mode - TkIDToTSMap fitTkCFMap_; // map CF TS to seedID of fit track - TkIDtoFitValLayMapMap fitValTkMapMap_; // map used for fit validation in mplex // Sim to Reco Maps @@ -133,92 +69,6 @@ class TTreeValidation : public Validation { TkIDToTkIDMap seedToBuildMap_; TkIDToTkIDMap seedToFitMap_; - // debug tree - TTree* debugtree_; - - int nlayers_debug_,event_debug_,nHits_debug_; - float pt_gen_debug_,phi_gen_debug_,eta_gen_debug_; - float x_gen_debug_,y_gen_debug_,z_gen_debug_; - - // mc truth - int mccharge_debug_; - int layer_mc_debug_[Config::nLayers]; - float x_hit_debug_[Config::nLayers],y_hit_debug_[Config::nLayers],z_hit_debug_[Config::nLayers]; - float exx_hit_debug_[Config::nLayers],eyy_hit_debug_[Config::nLayers],ezz_hit_debug_[Config::nLayers]; - float x_mc_debug_[Config::nLayers],y_mc_debug_[Config::nLayers],z_mc_debug_[Config::nLayers]; - float px_mc_debug_[Config::nLayers],py_mc_debug_[Config::nLayers],pz_mc_debug_[Config::nLayers]; - float pt_mc_debug_[Config::nLayers],phi_mc_debug_[Config::nLayers],eta_mc_debug_[Config::nLayers]; - float invpt_mc_debug_[Config::nLayers],theta_mc_debug_[Config::nLayers]; - - // track info - int recocharge_debug_; - - // cf info - float x_cf_debug_,y_cf_debug_,z_cf_debug_,exx_cf_debug_,eyy_cf_debug_,ezz_cf_debug_; - float px_cf_debug_,py_cf_debug_,pz_cf_debug_,epxpx_cf_debug_,epypy_cf_debug_,epzpz_cf_debug_; - float pt_cf_debug_,phi_cf_debug_,eta_cf_debug_,ept_cf_debug_,ephi_cf_debug_,eeta_cf_debug_; - float invpt_cf_debug_,theta_cf_debug_,einvpt_cf_debug_,etheta_cf_debug_; - - // chi2 info - int layer_chi2_debug_[Config::nLayers]; - float chi2_debug_[Config::nLayers]; - - // prop info - int layer_prop_debug_[Config::nLayers]; - float x_prop_debug_[Config::nLayers],y_prop_debug_[Config::nLayers],z_prop_debug_[Config::nLayers]; - float exx_prop_debug_[Config::nLayers],eyy_prop_debug_[Config::nLayers],ezz_prop_debug_[Config::nLayers]; - float px_prop_debug_[Config::nLayers],py_prop_debug_[Config::nLayers],pz_prop_debug_[Config::nLayers]; - float epxpx_prop_debug_[Config::nLayers],epypy_prop_debug_[Config::nLayers],epzpz_prop_debug_[Config::nLayers]; - float pt_prop_debug_[Config::nLayers],phi_prop_debug_[Config::nLayers],eta_prop_debug_[Config::nLayers]; - float ept_prop_debug_[Config::nLayers],ephi_prop_debug_[Config::nLayers],eeta_prop_debug_[Config::nLayers]; - float invpt_prop_debug_[Config::nLayers],theta_prop_debug_[Config::nLayers]; - float einvpt_prop_debug_[Config::nLayers],etheta_prop_debug_[Config::nLayers]; - - // update info - int layer_up_debug_[Config::nLayers]; - float x_up_debug_[Config::nLayers],y_up_debug_[Config::nLayers],z_up_debug_[Config::nLayers]; - float exx_up_debug_[Config::nLayers],eyy_up_debug_[Config::nLayers],ezz_up_debug_[Config::nLayers]; - float px_up_debug_[Config::nLayers],py_up_debug_[Config::nLayers],pz_up_debug_[Config::nLayers]; - float epxpx_up_debug_[Config::nLayers],epypy_up_debug_[Config::nLayers],epzpz_up_debug_[Config::nLayers]; - float pt_up_debug_[Config::nLayers],phi_up_debug_[Config::nLayers],eta_up_debug_[Config::nLayers]; - float ept_up_debug_[Config::nLayers],ephi_up_debug_[Config::nLayers],eeta_up_debug_[Config::nLayers]; - float invpt_up_debug_[Config::nLayers],theta_up_debug_[Config::nLayers]; - float einvpt_up_debug_[Config::nLayers],etheta_up_debug_[Config::nLayers]; - - // eta/phi bin info - int ebhit_debug_[Config::nLayers], ebp_debug_[Config::nLayers], ebm_debug_[Config::nLayers]; - int pbhit_debug_[Config::nLayers], pbp_debug_[Config::nLayers], pbm_debug_[Config::nLayers]; - - // seedinfo tree - TTree* seedinfotree_; - int evtID_seedinfo_; - int mcID_seedinfo_; - float pt_gen_seedinfo_; - float eta_gen_seedinfo_; - float phi_gen_seedinfo_; - float a,b,r,d0; - bool pass; - - // seed tree - TTree* seedtree_; - int evtID_seed_; - int nTkAll_; - int nTkAllMC_; - int nTkCut_; - int nTkCutMC_; - - // segment map tree - TTree* segtree_; - int evtID_seg_=0,layer_seg_=0,etabin_seg_=0,phibin_seg_=0,nHits_seg_=0; - - // build branching tree - TTree* tree_br_; - int evtID_br_=0,seedID_br_=0; - int layer_=0,cands_=0; - int uniqueEtaPhiBins_,uniqueHits_,uniqueBranches_; - std::vector candEtaPhiBins_,candHits_,candBranches_; - std::vector candnSigmaDeta_,candnSigmaDphi_; - // Efficiency Tree TTree* efftree_; int evtID_eff_=0,mcID_eff_=0; @@ -277,37 +127,6 @@ class TTreeValidation : public Validation { int duplmask_seed_FR_=0,duplmask_build_FR_=0,duplmask_fit_FR_=0; int iTkMatches_seed_FR_=0,iTkMatches_build_FR_=0,iTkMatches_fit_FR_=0; - // Geometry Tree - TTree* geotree_; - int evtID_geo_=0,mcID_geo_=0; - int mcmask_seed_geo_=0,mcmask_fit_geo_=0; // mcmask_build_geo_=0 - int seedID_seed_geo_=0,seedID_fit_geo_=0; // seedID_build_geo_=0 - - float x_mc_gen_vrx_geo_=0.,y_mc_gen_vrx_geo_=0.,z_mc_gen_vrx_geo_=0.; - std::vector layers_seed_geo_,layers_fit_geo_; - std::vector x_mc_reco_hit_geo_,y_mc_reco_hit_geo_,z_mc_reco_hit_geo_; - std::vector x_lay_seed_geo_,y_lay_seed_geo_,z_lay_seed_geo_,x_lay_fit_geo_,y_lay_fit_geo_,z_lay_fit_geo_; - std::vector ex_lay_seed_geo_,ey_lay_seed_geo_,ez_lay_seed_geo_,ex_lay_fit_geo_,ey_lay_fit_geo_,ez_lay_fit_geo_; - - // Conformal Tree - TTree* cftree_; - int evtID_cf_=0,mcID_cf_=0; - int mcmask_seed_cf_=0,mcmask_fit_cf_=0; // mcmask_build_cf_=0 - int seedID_seed_cf_=0,seedID_fit_cf_=0; // seedID_build_cf_=0 - - float x_mc_seed_cf_=0.,y_mc_seed_cf_=0.,z_mc_seed_cf_=0.,x_mc_fit_cf_=0.,y_mc_fit_cf_=0.,z_mc_fit_cf_=0.; - float x_seed_cf_=0.,y_seed_cf_=0.,z_seed_cf_=0.,x_fit_cf_=0.,y_fit_cf_=0.,z_fit_cf_=0.; - float ex_seed_cf_=0.,ey_seed_cf_=0.,ez_seed_cf_=0.,ex_fit_cf_=0.,ey_fit_cf_=0.,ez_fit_cf_=0.; - - float px_mc_seed_cf_=0.,py_mc_seed_cf_=0.,pz_mc_seed_cf_=0.,px_mc_fit_cf_=0.,py_mc_fit_cf_=0.,pz_mc_fit_cf_=0.; - float px_seed_cf_=0.,py_seed_cf_=0.,pz_seed_cf_=0.,px_fit_cf_=0.,py_fit_cf_=0.,pz_fit_cf_=0.; - float epx_seed_cf_=0.,epy_seed_cf_=0.,epz_seed_cf_=0.,epx_fit_cf_=0.,epy_fit_cf_=0.,epz_fit_cf_=0.; - - float pt_mc_seed_cf_=0.,invpt_mc_seed_cf_=0.,phi_mc_seed_cf_=0.,theta_mc_seed_cf_=0.,pt_mc_fit_cf_=0., - invpt_mc_fit_cf_=0.,phi_mc_fit_cf_=0.,theta_mc_fit_cf_=0.; - float pt_seed_cf_=0.,invpt_seed_cf_=0.,phi_seed_cf_=0.,theta_seed_cf_=0.,pt_fit_cf_=0.,invpt_fit_cf_=0.,phi_fit_cf_=0.,theta_fit_cf_=0.; - float ept_seed_cf_=0.,einvpt_seed_cf_=0.,ephi_seed_cf_=0.,etheta_seed_cf_=0.,ept_fit_cf_=0.,einvpt_fit_cf_=0.,ephi_fit_cf_=0.,etheta_fit_cf_=0.; - // Configuration tree TTree* configtree_; int Ntracks_=0,Nevents_=0; @@ -324,20 +143,16 @@ class TTreeValidation : public Validation { int nTotHit_=0; float ptinverr049_=0.,phierr049_=0.,thetaerr049_=0.,ptinverr012_=0.,phierr012_=0.,thetaerr012_=0.; - // Time tree (smatrix only at the moment) - TTree* timetree_; - float simtime_=0.,segtime_=0.,seedtime_=0.,buildtime_=0.,fittime_=0.,hlvtime_=0.; - // Fit tree (for fine tuning z-phi windows and such --> MPlex Only TTree* fittree_; - int nlayers_fit_=0,tkid_fit_=0,evtid_fit_=0; - float z_prop_fit_[Config::nLayers],ez_prop_fit_[Config::nLayers]; - float z_hit_fit_[Config::nLayers],ez_hit_fit_[Config::nLayers],z_sim_fit_[Config::nLayers],ez_sim_fit_[Config::nLayers]; - float pphi_prop_fit_[Config::nLayers],epphi_prop_fit_[Config::nLayers]; - float pphi_hit_fit_[Config::nLayers],epphi_hit_fit_[Config::nLayers],pphi_sim_fit_[Config::nLayers],epphi_sim_fit_[Config::nLayers]; - float pt_up_fit_[Config::nLayers],ept_up_fit_[Config::nLayers],pt_sim_fit_[Config::nLayers],ept_sim_fit_[Config::nLayers]; - float mphi_up_fit_[Config::nLayers],emphi_up_fit_[Config::nLayers],mphi_sim_fit_[Config::nLayers],emphi_sim_fit_[Config::nLayers]; - float meta_up_fit_[Config::nLayers],emeta_up_fit_[Config::nLayers],meta_sim_fit_[Config::nLayers],emeta_sim_fit_[Config::nLayers]; + int ntotallayers_fit_=0,tkid_fit_=0,evtid_fit_=0; + float z_prop_fit_[Config::nTotalLayers],ez_prop_fit_[Config::nTotalLayers]; + float z_hit_fit_[Config::nTotalLayers],ez_hit_fit_[Config::nTotalLayers],z_sim_fit_[Config::nTotalLayers],ez_sim_fit_[Config::nTotalLayers]; + float pphi_prop_fit_[Config::nTotalLayers],epphi_prop_fit_[Config::nTotalLayers]; + float pphi_hit_fit_[Config::nTotalLayers],epphi_hit_fit_[Config::nTotalLayers],pphi_sim_fit_[Config::nTotalLayers],epphi_sim_fit_[Config::nTotalLayers]; + float pt_up_fit_[Config::nTotalLayers],ept_up_fit_[Config::nTotalLayers],pt_sim_fit_[Config::nTotalLayers],ept_sim_fit_[Config::nTotalLayers]; + float mphi_up_fit_[Config::nTotalLayers],emphi_up_fit_[Config::nTotalLayers],mphi_sim_fit_[Config::nTotalLayers],emphi_sim_fit_[Config::nTotalLayers]; + float meta_up_fit_[Config::nTotalLayers],emeta_up_fit_[Config::nTotalLayers],meta_sim_fit_[Config::nTotalLayers],emeta_sim_fit_[Config::nTotalLayers]; std::mutex glock_; }; diff --git a/Validation.cc b/Validation.cc index 38fe1678f5c1d..b34a5437ae7ec 100644 --- a/Validation.cc +++ b/Validation.cc @@ -3,7 +3,7 @@ Validation* Validation::make_validation(const std::string& fileName) { #ifndef NO_ROOT - if (Config::normal_val || Config::fit_val || Config::full_val) { + if (Config::root_val || Config::fit_val) { return new TTreeValidation(fileName); } #endif diff --git a/Validation.h b/Validation.h index b6af0f8cd25ca..4b5d3d989c333 100644 --- a/Validation.h +++ b/Validation.h @@ -29,34 +29,15 @@ class Validation { virtual void resetDebugVectors() {} virtual void collectSimTkTSVecMapInfo(int, const TSVec&) {} - virtual void collectSeedTkCFMapInfo(int, const TrackState&) {} - virtual void collectSeedTkTSLayerPairVecMapInfo(int, const TSLayerPairVec&) {} - virtual void collectBranchingInfo(int, int, float, float, int, float, int, - int, const std::vector&, const std::vector&) {} - virtual void collectFitTkCFMapInfo(int, const TrackState&) {} - virtual void collectFitTkTSLayerPairVecMapInfo(int, const TSLayerPairVec&) {} - virtual void collectFitInfo(const FitVal&, int, int) {} - virtual void collectPropTSLayerVecInfo(int, const TrackState&) {} // exclusively for debugtree - virtual void collectChi2LayerVecInfo(int, float) {} // exclusively for debugtree - virtual void collectUpTSLayerVecInfo(int, const TrackState&) {} // exclusively for debugtree - virtual void setTrackExtras(Event& ev) {} virtual void makeSimTkToRecoTksMaps(Event&) {} virtual void makeSeedTkToRecoTkMaps(Event&) {} - virtual void fillSeedInfoTree(const TripletIdxVec&, const Event&) {} - virtual void fillSeedTree(const TripletIdxVec&, const TripletIdxVec&, const Event&) {} - virtual void fillDebugTree(const Event&) {} - virtual void fillSegmentTree(const BinInfoMap&, int) {} - virtual void fillBranchTree(int) {} virtual void fillEfficiencyTree(const Event&) {} virtual void fillFakeRateTree(const Event&) {} - virtual void fillGeometryTree(const Event&) {} - virtual void fillConformalTree(const Event&) {} virtual void fillConfigTree() {} - virtual void fillTimeTree(const std::vector &) {} virtual void fillFitTree(const Event&) {} virtual void saveTTrees() {} diff --git a/buildtest.cc b/buildtest.cc index 7aecf7b63a376..fa4bc17fa09f5 100644 --- a/buildtest.cc +++ b/buildtest.cc @@ -185,13 +185,11 @@ void extendCandidate(const Event& ev, const cand_t& cand, candvec& tmp_candidate dprint("processing candidate with nHits=" << tkcand.nFoundHits()); #ifdef LINEARINTERP TrackState propState = propagateHelixToR(updatedState,ev.geom_.Radius(ilayer)); - if (Config::super_debug) { ev.validation_.collectPropTSLayerVecInfo(ilayer,propState); } #else #ifdef TBB #error "Invalid combination of options (thread safety)" #endif TrackState propState = propagateHelixToLayer(updatedState,ilayer,ev.geom_); - if (Config::super_debug) { ev.validation_.collectPropTSLayerVecInfo(ilayer,propState); } #endif // LINEARINTERP #ifdef CHECKSTATEVALID if (!propState.valid) { @@ -260,14 +258,12 @@ void extendCandidate(const Event& ev, const cand_t& cand, candvec& tmp_candidate #endif dprint(propState.position() - hitMeas.parameters()); const float chi2 = computeChi2(propState,hitMeas); - if (Config::super_debug) { ev.validation_.collectChi2LayerVecInfo(ilayer,chi2); } dprint("found hit with index: " << cand_hit_idx << " from sim track " << ev.simHitsInfo_[evt_lay_hits[ilayer][cand_hit_idx].mcHitID()].mcTrackID() << " chi2=" << chi2 << std::endl); if ((chi20.)) {//fixme const TrackState tmpUpdatedState = updateParameters(propState, hitMeas); - if (Config::super_debug) { ev.validation_.collectUpTSLayerVecInfo(ilayer,tmpUpdatedState); } Track tmpCand = tkcand.clone(); tmpCand.addHitIdx(cand_hit_idx, ilayer, chi2); tmpCand.setState(tmpUpdatedState); @@ -277,13 +273,11 @@ void extendCandidate(const Event& ev, const cand_t& cand, candvec& tmp_candidate }//end of consider hits on layer loop //add also the candidate for no hit found - if (tkcand.nFoundHits()==ilayer && !Config::super_debug) {//only if this is the first missing hit and also not in super debug mode + if (tkcand.nFoundHits()==ilayer) {//only if this is the first missing hit dprint("adding candidate with no hit"); Track tmpCand = tkcand.clone(); tmpCand.addHitIdx(-1, ilayer, 0.0f); tmp_candidates.push_back(tmpCand); // fix this once moving to fix indices branch_hit_indices.push_back(Config::nTracks); // since tracks go from 0-Config::nTracks -1, the ghost index is just the one beyond } - ev.validation_.collectBranchingInfo(seedID,ilayer,nSigmaDeta,etaBinMinus,etaBinPlus, - nSigmaDphi,phiBinMinus,phiBinPlus,cand_hit_indices,branch_hit_indices); } diff --git a/fittest.cc b/fittest.cc index 6fa1606f246ee..9a2ba34323c6f 100644 --- a/fittest.cc +++ b/fittest.cc @@ -44,7 +44,6 @@ void fitTrack(const Track & trk, const TrackExtra& trkextra, int itrack, Event& conformalFit(hit1,hit2,hit3,cfitStateHit0,fiterrs); // last bool denotes use cf derived errors for fitting TrackState updatedState = cfitStateHit0; updatedState.charge = trk.charge(); - ev.validation_.collectFitTkCFMapInfo(seedID,cfitStateHit0); // pass along all info and map it to a given seed #else TrackState updatedState = trk.state(); #endif @@ -95,7 +94,6 @@ void fitTrack(const Track & trk, const TrackExtra& trkextra, int itrack, Event& } // end loop over hits dcall(print("Fit Track", updatedState)); - ev.validation_.collectFitTkTSLayerPairVecMapInfo(seedID,updatedStates); // for position pulls Track FitTrack(trk); FitTrack.setState(updatedState); // eventually will want to include chi2 of fitTrack --> chi2 for now just copied from build tracks diff --git a/main.cc b/main.cc index 665fad3a6118c..c4884db0af12b 100644 --- a/main.cc +++ b/main.cc @@ -177,9 +177,7 @@ int main(int argc, const char* argv[]) " --num-events number of events to run over (def: %d)\n" " --num-tracks number of tracks to generate for each event (def: %d)\n" " --num-thr number of threads used for TBB (def: %d)\n" - " --super-debug bool to enable super debug mode (def: %s)\n" - " --normal-val bool to enable normal validation (eff, FR, DR) (def: %s)\n" - " --full-val bool to enable more validation in SMatrix (def: %s)\n" + " --root-val bool to enable normal validation (eff, FR, DR) (def: %s)\n" " --cf-seeding bool to enable CF in MC seeding (def: %s)\n" " --read read input simtracks file (def: false)\n" " --file-name file name for write/read (def: %s)\n" @@ -190,10 +188,8 @@ int main(int argc, const char* argv[]) Config::nEvents, Config::nTracks, nThread, - (Config::super_debug ? "true" : "false"), - (Config::normal_val ? "true" : "false"), - (Config::full_val ? "true" : "false"), - (Config::cf_seeding ? "true" : "false"), + (Config::root_val ? "true" : "false"), + (Config::cf_seeding ? "true" : "false"), s_file_name.c_str(), Config::readCmsswSeeds, Config::endcapTest @@ -215,26 +211,9 @@ int main(int argc, const char* argv[]) next_arg_or_die(mArgs, i); nThread = atoi(i->c_str()); } - else if (*i == "--super-debug") + else if (*i == "--root-val") { - Config::super_debug = true; - Config::nTracks = 1; - Config::nEvents = 100000; - - Config::normal_val = false; - Config::full_val = false; - } - else if (*i == "--normal-val") - { - Config::super_debug = false; - Config::normal_val = true; - Config::full_val = false; - } - else if (*i == "--full-val") - { - Config::super_debug = false; - Config::normal_val = true; - Config::full_val = true; + Config::root_val = true; } else if (*i == "--cf-seeding") { @@ -310,25 +289,19 @@ int main(int argc, const char* argv[]) ev.Segment(); ticks[1] += delta(t0); ev.Seed(); ticks[2] += delta(t0); ev.Find(); ticks[3] += delta(t0); - - if (!Config::super_debug) - { - ev.Fit(); ticks[4] += delta(t0); - } + ev.Fit(); ticks[4] += delta(t0); ev.Validate(); ticks[5] += delta(t0); - if (!Config::super_debug) { - std::cout << "sim: " << ev.simTracks_.size() << " seed: " << ev.seedTracks_.size() << " found: " - << ev.candidateTracks_.size() << " fit: " << ev.fitTracks_.size() << std::endl; - tracks[0] += ev.simTracks_.size(); - tracks[1] += ev.seedTracks_.size(); - tracks[2] += ev.candidateTracks_.size(); - tracks[3] += ev.fitTracks_.size(); - std::cout << "Built tracks" << std::endl; - ev.PrintStats(ev.candidateTracks_, ev.candidateTracksExtra_); - std::cout << "Fit tracks" << std::endl; - ev.PrintStats(ev.fitTracks_, ev.fitTracksExtra_); - } + std::cout << "sim: " << ev.simTracks_.size() << " seed: " << ev.seedTracks_.size() << " found: " + << ev.candidateTracks_.size() << " fit: " << ev.fitTracks_.size() << std::endl; + tracks[0] += ev.simTracks_.size(); + tracks[1] += ev.seedTracks_.size(); + tracks[2] += ev.candidateTracks_.size(); + tracks[3] += ev.fitTracks_.size(); + std::cout << "Built tracks" << std::endl; + ev.PrintStats(ev.candidateTracks_, ev.candidateTracksExtra_); + std::cout << "Fit tracks" << std::endl; + ev.PrintStats(ev.fitTracks_, ev.fitTracksExtra_); } if (s_operation == "read") @@ -342,7 +315,6 @@ int main(int argc, const char* argv[]) } val->fillConfigTree(); - if (Config::full_val) val->fillTimeTree(time); val->saveTTrees(); std::cout << "Ticks "; diff --git a/mkFit/buildtestMPlex.cc b/mkFit/buildtestMPlex.cc index a6dbff0efe494..801d34d8c93e8 100644 --- a/mkFit/buildtestMPlex.cc +++ b/mkFit/buildtestMPlex.cc @@ -110,7 +110,7 @@ double runBuildingTestPlexBestHit(Event& ev, MkBuilder& builder) __itt_pause(); #endif - if (!Config::normal_val) { + if (!Config::root_val) { if (!Config::silent) builder.quality_output_BH(); } else { builder.root_val_BH(); @@ -150,7 +150,7 @@ double runBuildingTestPlexStandard(Event& ev, MkBuilder& builder) __itt_pause(); #endif - if (!Config::normal_val) { + if (!Config::root_val) { if (!Config::silent) builder.quality_output_COMB(); } else {builder.root_val_COMB();} @@ -188,7 +188,7 @@ double runBuildingTestPlexCloneEngine(Event& ev, MkBuilder& builder) __itt_pause(); #endif - if (!Config::normal_val) { + if (!Config::root_val) { if (!Config::silent) builder.quality_output_COMB(); } else {builder.root_val_COMB();} @@ -249,7 +249,7 @@ double runAllBuildingTestPlexBestHitGPU(std::vector &events) EventOfCandidates &event_of_cands = event_of_cands_vec[i]; BuilderCU &builder_cu = builder_cu_vec[i]; MkBuilder &builder = * builder_ptrs[i].get(); - if (!Config::normal_val) { + if (!Config::root_val) { if (!Config::silent) builder.quality_output_BH(event_of_cands); } else { builder.root_val_BH(event_of_cands); diff --git a/mkFit/fittestMPlex.cc b/mkFit/fittestMPlex.cc index ba7c16dfd83e2..62aae2f240571 100644 --- a/mkFit/fittestMPlex.cc +++ b/mkFit/fittestMPlex.cc @@ -30,75 +30,6 @@ #include "ittnotify.h" #endif -//============================================================================== - -void make_validation_tree(const char *fname, - std::vector &simtracks, - std::vector &rectracks) -{ - assert(simtracks.size() == rectracks.size()); - - float pt_mc, pt_fit, pt_err, chg; - int goodtrk = 0; - -#ifndef NO_ROOT - static std::mutex roolock; - - std::lock_guard rooguard(roolock); - - TFile *file = TFile::Open(fname, "recreate"); - TTree *tree = new TTree("T", "Validation Tree for simple Kalman fitter");; - - tree->Branch("pt_mc", &pt_mc, "pt_mc"); - tree->Branch("pt_fit", &pt_fit, "pt_fit"); - tree->Branch("pt_err", &pt_err, "pt_err"); - tree->Branch("chg", &chg, "chg"); -#endif - - std::vector diff_vec; - - const int NT = simtracks.size(); - for (int i = 0; i < NT; ++i) - { - pt_mc = simtracks[i].pT(); - pt_fit = rectracks[i].pT(); - pt_err = rectracks[i].epT() / pt_fit; - chg = simtracks[i].charge(); - -#ifndef NO_ROOT - tree->Fill(); -#endif - - float pr = pt_fit/pt_mc; - float diff = (pt_mc/pt_fit - 1) / pt_err; - if (pr > 0.8 && pr < 1.2 && std::isfinite(diff)) { - diff_vec.push_back(diff); - ++goodtrk; - } else { - dprint("pt_mc, pt_fit, pt_err, ratio, diff " << pt_mc << " " << pt_fit << " " << pt_err << " " << pt_fit/pt_mc << " " << diff); - } - } - float mean = std::accumulate(diff_vec.begin(), diff_vec.end(), 0.0) - / diff_vec.size(); - - std::transform(diff_vec.begin(), diff_vec.end(), - diff_vec.begin(), // in-place - [mean](float x) {return (x-mean)*(x-mean);}); - - float stdev = std::sqrt( - std::accumulate(diff_vec.begin(), diff_vec.end(), 0.0) - / diff_vec.size()); - - std::cerr << goodtrk << " good tracks, mean pt pull: " << mean - << " standard dev: " << stdev << std::endl; - -#ifndef NO_ROOT - file->Write(); - file->Close(); - delete file; -#endif -} - //============================================================================== // runFittingTestPlex //============================================================================== @@ -258,7 +189,6 @@ void runAllEventsFittingTestPlexGPU(std::vector& events) if (omp_get_num_threads() <= 1) { //if (g_run_fit_std) { std::string tree_name = "validation-plex-" + std::to_string(evt) + ".root"; - make_validation_tree(tree_name.c_str(), ev.simTracks_, plex_tracks_ev); //} } #endif diff --git a/mkFit/fittestMPlex.h b/mkFit/fittestMPlex.h index 2b88d56a17680..538012c192f53 100644 --- a/mkFit/fittestMPlex.h +++ b/mkFit/fittestMPlex.h @@ -8,10 +8,6 @@ #include "FitterCU.h" #endif -void make_validation_tree(const char *fname, - std::vector &simtracks, - std::vector &rectracks); - double runFittingTestPlex(Event& ev, std::vector& rectracks); #ifdef USE_CUDA diff --git a/mkFit/mkFit.cc b/mkFit/mkFit.cc index f2e7aadad89db..3c48c0c52ff9f 100644 --- a/mkFit/mkFit.cc +++ b/mkFit/mkFit.cc @@ -384,8 +384,6 @@ void test_standard() // probably should convert to a scaled long so can use std::atomic for (int i = 0; i < NT; ++i) t_sum[i] += t_best[i]; if (evt > 0) for (int i = 0; i < NT; ++i) t_skip[i] += t_best[i]; - - if (g_run_fit_std) make_validation_tree("validation-plex.root", ev.simTracks_, plex_tracks); } }, tbb::simple_partitioner()); @@ -481,7 +479,7 @@ int main(int argc, const char *argv[]) " --endcap-test test endcap tracking (def: %i)\n" " --cf-seeding enable CF in seeding (def: %s)\n" " --cf-fitting enable CF in fitting (def: %s)\n" - " --normal-val enable ROOT based validation for building [eff, FR, DR] (def: %s)\n" + " --root-val enable ROOT based validation for building [eff, FR, DR] (def: %s)\n" " --fit-val enable ROOT based validation for fitting (def: %s)\n" " --silent suppress printouts inside event loop (def: %s)\n" " --write write simulation to file and exit\n" @@ -505,7 +503,7 @@ int main(int argc, const char *argv[]) Config::endcapTest, Config::cf_seeding ? "true" : "false", Config::cf_fitting ? "true" : "false", - Config::normal_val ? "true" : "false", + Config::root_val ? "true" : "false", Config::fit_val ? "true" : "false", Config::silent ? "true" : "false", g_file_name.c_str(), @@ -594,13 +592,13 @@ int main(int argc, const char *argv[]) { Config::cf_fitting = true; } - else if (*i == "--normal-val") + else if (*i == "--root-val") { - Config::super_debug = false; Config::normal_val = true; Config::full_val = false; Config::fit_val = false; + Config::root_val = true; Config::fit_val = false; } else if (*i == "--fit-val") { - Config::super_debug = false; Config::normal_val = false; Config::full_val = false; Config::fit_val = true; + Config::root_val = false; Config::fit_val = true; } else if (*i == "--num-thr-ev") { diff --git a/runValidation.C b/runValidation.C index 4e5626031c447..a9a4cd486f6a4 100644 --- a/runValidation.C +++ b/runValidation.C @@ -11,7 +11,7 @@ void setupcpp11() gSystem->SetMakeExe(o.Data()); } -void runValidation(TString test = "", Bool_t mvInput = true, Bool_t fullval = false, +void runValidation(TString test = "", Bool_t mvInput = true, Bool_t saveAs = false, TString image = "pdf") { setupcpp11(); // use this to get PlotValidation to compile ... phiphi ROOT build has ACLiC with C++98! @@ -22,15 +22,10 @@ void runValidation(TString test = "", Bool_t mvInput = true, Bool_t fullval = fa // First is additional input name of root file // Second is output name of directory/rootfile/file plots // The first boolean argument == true to move input root file to output directory, false to keep input file where it is. - // Sedcond bool == true for full validation, false for only "main" validation. // Main validation includes efficiencies, fake rates, duplicate rates. Also momentum pulls, nHits plots, timing plots. - // Full validation includes main validation plus geometry plots, positions pulls, and CF pulls/residuals. - // Full validation also includes branching plots and segmenting plots - // Third Bool is saving the image files + // Second Bool is saving the image files // Last argument is output type of plots - - PlotValidation Val(Form("valtree%s.root",test.Data()),Form("validation%s",test.Data()), - mvInput,fullval,saveAs,image); + PlotValidation Val(Form("valtree%s.root",test.Data()),Form("validation%s",test.Data()),mvInput,saveAs,image); Val.Validation(); } diff --git a/seedtest.cc b/seedtest.cc index 74718170aea7c..0bcb13987cd63 100644 --- a/seedtest.cc +++ b/seedtest.cc @@ -33,7 +33,6 @@ void buildSeedsByMC(const TrackVec& evt_sim_tracks, TrackVec& evt_seed_tracks, T else { updatedState = trk.state(); } - if (Config::super_debug) { ev.validation_.collectSeedTkCFMapInfo(itrack,updatedState); } dprint("processing sim track # " << itrack << " par=" << trk.parameters()); TSLayerPairVec updatedStates; // validation for position pulls @@ -42,7 +41,6 @@ void buildSeedsByMC(const TrackVec& evt_sim_tracks, TrackVec& evt_seed_tracks, T auto hitidx = trk.getHitIdx(ilayer); const Hit& seed_hit = ev.layerHits_[ilayer][hitidx]; TrackState propState = propagateHelixToR(updatedState,seed_hit.r()); - if (Config::super_debug) { ev.validation_.collectPropTSLayerVecInfo(ilayer,propState); } #ifdef CHECKSTATEVALID if (!propState.valid) { std::cout << "Seeding failed to propagate to layer: " << ilayer << " for sim track: " << itrack << std::endl; @@ -52,14 +50,11 @@ void buildSeedsByMC(const TrackVec& evt_sim_tracks, TrackVec& evt_seed_tracks, T const auto& measState = seed_hit.measurementState(); const float chi2 = computeChi2(propState,measState); // sumchi2 += chi2; //--> could use this to make the chi2 - if (Config::super_debug) { ev.validation_.collectChi2LayerVecInfo(ilayer,chi2); } updatedState = updateParameters(propState, measState); - if (Config::super_debug) { ev.validation_.collectUpTSLayerVecInfo(ilayer,updatedState); } seedhits[ilayer] = hitidx; updatedStates.push_back(std::make_pair(ilayer,updatedState)); // validation } - ev.validation_.collectSeedTkTSLayerPairVecMapInfo(itrack,updatedStates); // use to collect position pull info // XXMT4K: Here will need layer indices, too now. // XX Track seed(updatedState,0.0f,itrack,Config::nlayers_per_seed,seedhits);//fixme chi2 (could use sumchi2) @@ -141,18 +136,9 @@ void buildSeedsByRZFirstRPhiSecond(TrackVec& evt_seed_tracks, TrackExtraVec& evt } } - if (!Config::super_debug) { - ev.validation_.fillSeedInfoTree(hitTriplets,ev); - } - TripletIdxVec filteredTriplets; filterHitTripletsByCircleParams(evt_lay_hits,hitTriplets,filteredTriplets); // filterHitTripletsByRZChi2(evt_lay_hits,hitTriplets,filteredTriplets); // filter based on RZ chi2 cut - - if (!Config::super_debug) { - ev.validation_.fillSeedTree(hitTriplets,filteredTriplets,ev); - } - // turn triplets into track seeds by performing CF + KF fit // buildSeedsFromTriplets(evt_lay_hits,filteredTriplets,evt_seed_tracks,evt_seed_extras,ev); } @@ -216,9 +202,6 @@ void buildSeedsByRoadTriplets(TrackVec& evt_seed_tracks, TrackExtraVec& evt_seed filterHitTripletsBySecondLayerZResidual(evt_lay_hits,hitTriplets,filteredTriplets1); // filter based on residual of 2nd hit and line in R-Z for 1st, 3rd hit filterHitTripletsByCircleParams(evt_lay_hits,filteredTriplets1,filteredTriplets); // filter based on circle fit to three hits (d0 and curvature) // filterHitTripletsByRZChi2(evt_lay_hits,hitTriplets,filteredTriplets); // filter based on RZ chi2 cut - if (!Config::super_debug) { - ev.validation_.fillSeedTree(hitTriplets,filteredTriplets,ev); - } buildSeedsFromTriplets(evt_lay_hits,filteredTriplets,evt_seed_tracks,evt_seed_extras,ev); } @@ -581,15 +564,12 @@ void buildSeedsFromTriplets(const std::vector& evt_lay_hits, const Tripl // px,py,pz from CF the same // epxpx,epypy,epzpz set to 0.25*(px/py/pz)^2 (half sigma) - ev.validation_.collectSeedTkCFMapInfo(seedID,updatedState); - TSLayerPairVec updatedStates; // validation for position pulls float sumchi2 = 0; for (auto ilayer = 0; ilayer < Config::nlayers_per_seed; ++ilayer) { const Hit& seed_hit = evt_lay_hits[ilayer][hit_triplet[ilayer]]; TrackState propState = propagateHelixToR(updatedState,seed_hit.r()); - if (Config::super_debug) { ev.validation_.collectPropTSLayerVecInfo(ilayer,propState); } #ifdef CHECKSTATEVALID if (!propState.valid) { break; @@ -598,12 +578,9 @@ void buildSeedsFromTriplets(const std::vector& evt_lay_hits, const Tripl MeasurementState measState = seed_hit.measurementState(); const float chi2 = computeChi2(propState,measState); sumchi2 += chi2;// --> could use this to make the chi2 - if (Config::super_debug) { ev.validation_.collectChi2LayerVecInfo(ilayer,chi2); } updatedState = updateParameters(propState, measState); - if (Config::super_debug) { ev.validation_.collectUpTSLayerVecInfo(ilayer,updatedState); } updatedStates.push_back(std::make_pair(ilayer,updatedState)); // validation } - ev.validation_.collectSeedTkTSLayerPairVecMapInfo(seedID,updatedStates); // use to collect position pull info int hitIndices[3] = {hit_triplet[0],hit_triplet[1],hit_triplet[2]}; // XXMT4K: Here will need layer indices, too now. @@ -625,14 +602,12 @@ void fitSeeds(const std::vector& evt_lay_hits, TrackVec& evt_seed_tracks // first do CF Fit conformalFit(evt_lay_hits[0][seed.getHitIdx(0)],evt_lay_hits[1][seed.getHitIdx(1)],evt_lay_hits[2][seed.getHitIdx(2)],updatedState,false); updatedState.charge = seed.charge(); - ev.validation_.collectSeedTkCFMapInfo(seedID,updatedState); TSLayerPairVec updatedStates; // validation for position pulls float sumchi2 = 0.0f; // chi2 to save for (auto ilayer = 0; ilayer < Config::nlayers_per_seed; ++ilayer) { const Hit& seed_hit = evt_lay_hits[ilayer][seed.getHitIdx(ilayer)]; TrackState propState = propagateHelixToR(updatedState,seed_hit.r()); - if (Config::super_debug) { ev.validation_.collectPropTSLayerVecInfo(ilayer,propState); } #ifdef CHECKSTATEVALID if (!propState.valid) { break; @@ -641,12 +616,9 @@ void fitSeeds(const std::vector& evt_lay_hits, TrackVec& evt_seed_tracks MeasurementState measState = seed_hit.measurementState(); const float chi2 = computeChi2(propState,measState); sumchi2 += chi2;// --> could use this to make the chi2 - if (Config::super_debug) { ev.validation_.collectChi2LayerVecInfo(ilayer,chi2); } updatedState = updateParameters(propState, measState); - if (Config::super_debug) { ev.validation_.collectUpTSLayerVecInfo(ilayer,updatedState); } updatedStates.push_back(std::make_pair(ilayer,updatedState)); // validation } - ev.validation_.collectSeedTkTSLayerPairVecMapInfo(seedID,updatedStates); // use to collect position pull info // make sure to set chi2 and track state of KF fit! seed.setChi2(sumchi2); From 8af7902ef630a920ab4bc6f35e774e7aaf65a641 Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Wed, 12 Apr 2017 01:26:13 -0700 Subject: [PATCH 016/172] forgot to add this to the last pr... sorry --- validation-snb-toymc-barrel-build.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/validation-snb-toymc-barrel-build.sh b/validation-snb-toymc-barrel-build.sh index aa20c2d1bde0a..609a2745f4745 100755 --- a/validation-snb-toymc-barrel-build.sh +++ b/validation-snb-toymc-barrel-build.sh @@ -7,13 +7,13 @@ make -j 12 dir=/data/nfsmic/${TOYMCUSER:-kmcdermo}/toymc echo "SNB ToyMC BH (Barrel): validation [nTH:24, nVU:8]" -./mkFit/mkFit --normal-val --read --file-name ${dir}/simtracks_barrel_10x10k_val.bin --build-bh --num-thr 24 >& log_SNB_ToyMC_Barrel_BH_NVU8int_NTH24_val.txt +./mkFit/mkFit --root-val --read --file-name ${dir}/simtracks_barrel_10x10k_val.bin --build-bh --num-thr 24 >& log_SNB_ToyMC_Barrel_BH_NVU8int_NTH24_val.txt mv valtree.root valtree_SNB_ToyMC_Barrel_BH.root echo "SNB ToyMC STD (Barrel): validation [nTH:24, nVU:8]" -./mkFit/mkFit --normal-val --read --file-name ${dir}/simtracks_barrel_10x10k_val.bin --build-std --num-thr 24 >& log_SNB_ToyMC_Barrel_STD_NVU8int_NTH24_val.txt +./mkFit/mkFit --root-val --read --file-name ${dir}/simtracks_barrel_10x10k_val.bin --build-std --num-thr 24 >& log_SNB_ToyMC_Barrel_STD_NVU8int_NTH24_val.txt mv valtree.root valtree_SNB_ToyMC_Barrel_STD.root echo "SNB ToyMC CE (Barrel): validation [nTH:24, nVU:8]" -./mkFit/mkFit --normal-val --read --file-name ${dir}/simtracks_barrel_10x10k_val.bin --build-ce --num-thr 24 >& log_SNB_ToyMC_Barrel_CE_NVU8int_NTH24_val.txt +./mkFit/mkFit --root-val --read --file-name ${dir}/simtracks_barrel_10x10k_val.bin --build-ce --num-thr 24 >& log_SNB_ToyMC_Barrel_CE_NVU8int_NTH24_val.txt mv valtree.root valtree_SNB_ToyMC_Barrel_CE.root sed -i 's/WITH_ROOT := yes/#WITH_ROOT := yes/g' Makefile.config From f1a28933f9b1c774791013a3b7d1318c350d2646 Mon Sep 17 00:00:00 2001 From: srlantz Date: Wed, 12 Apr 2017 07:16:53 -0700 Subject: [PATCH 017/172] Contributed fixes to Makefile.config and, in mkFit, some handy__SSC_MARK switches that can be used by SDE to sync its output with the __itt_pause() and __itt_resume() calls used by VTune (all are from the same -littnotify). --- Makefile.config | 4 ++-- mkFit/buildtestMPlex.cc | 6 ++++++ mkFit/fittestMPlex.cc | 2 ++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Makefile.config b/Makefile.config index dd5f70f3258e4..2b693411e8f81 100644 --- a/Makefile.config +++ b/Makefile.config @@ -7,7 +7,7 @@ # This is also needed for icc as it uses gcc headers. # To build mkFit -- Matriplex Kalman Fit: -# - enable USE_MATRIPEX in section 5, +# - enable USE_MATRIPLEX in section 5, # - cd mkFit; make (or make -C mkFit). @@ -149,7 +149,7 @@ ifdef USE_VTUNE_NOTIFY ifdef VTUNE_AMPLIFIER_XE_2016_DIR CPPFLAGS += -I$(VTUNE_AMPLIFIER_XE_2016_DIR)/include -DUSE_VTUNE_PAUSE LDFLAGS_HOST += -L$(VTUNE_AMPLIFIER_XE_2016_DIR)/lib64 -littnotify - LDFLAGS_MIC += -L$(VTUNE_AMPLIFIER_XE_2016_DIR)/bin64/k1om -littnotify + LDFLAGS_MIC += -L$(VTUNE_AMPLIFIER_XE_2016_DIR)/bin64/k1om -littnotify -lpthread endif endif diff --git a/mkFit/buildtestMPlex.cc b/mkFit/buildtestMPlex.cc index 801d34d8c93e8..38fcdffea8301 100644 --- a/mkFit/buildtestMPlex.cc +++ b/mkFit/buildtestMPlex.cc @@ -86,6 +86,7 @@ double runBuildingTestPlexBestHit(Event& ev, MkBuilder& builder) builder.find_tracks_load_seeds_BH(); #ifdef USE_VTUNE_PAUSE + __SSC_MARK(0x111); // use this to resume Intel SDE at the same point __itt_resume(); #endif @@ -108,6 +109,7 @@ double runBuildingTestPlexBestHit(Event& ev, MkBuilder& builder) #ifdef USE_VTUNE_PAUSE __itt_pause(); + __SSC_MARK(0x222); // use this to pause Intel SDE at the same point #endif if (!Config::root_val) { @@ -137,6 +139,7 @@ double runBuildingTestPlexStandard(Event& ev, MkBuilder& builder) builder.find_tracks_load_seeds(); #ifdef USE_VTUNE_PAUSE + __SSC_MARK(0x111); // use this to resume Intel SDE at the same point __itt_resume(); #endif @@ -148,6 +151,7 @@ double runBuildingTestPlexStandard(Event& ev, MkBuilder& builder) #ifdef USE_VTUNE_PAUSE __itt_pause(); + __SSC_MARK(0x222); // use this to pause Intel SDE at the same point #endif if (!Config::root_val) { @@ -175,6 +179,7 @@ double runBuildingTestPlexCloneEngine(Event& ev, MkBuilder& builder) builder.find_tracks_load_seeds(); #ifdef USE_VTUNE_PAUSE + __SSC_MARK(0x111); // use this to resume Intel SDE at the same point __itt_resume(); #endif @@ -186,6 +191,7 @@ double runBuildingTestPlexCloneEngine(Event& ev, MkBuilder& builder) #ifdef USE_VTUNE_PAUSE __itt_pause(); + __SSC_MARK(0x222); // use this to pause Intel SDE at the same point #endif if (!Config::root_val) { diff --git a/mkFit/fittestMPlex.cc b/mkFit/fittestMPlex.cc index 62aae2f240571..bc19a3e46f031 100644 --- a/mkFit/fittestMPlex.cc +++ b/mkFit/fittestMPlex.cc @@ -67,6 +67,7 @@ double runFittingTestPlex(Event& ev, std::vector& rectracks) int count = (theEnd + NN - 1)/NN; #ifdef USE_VTUNE_PAUSE + __SSC_MARK(0x111); // use this to resume Intel SDE at the same point __itt_resume(); #endif @@ -122,6 +123,7 @@ double runFittingTestPlex(Event& ev, std::vector& rectracks) #ifdef USE_VTUNE_PAUSE __itt_pause(); + __SSC_MARK(0x222); // use this to pause Intel SDE at the same point #endif if (Config::fit_val) ev.Validate(); From 8e1be1526a3a80c95bcf8b96692f3f5ee2768d4a Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Fri, 14 Apr 2017 02:11:16 -0700 Subject: [PATCH 018/172] main feature added: simTrackStates_ now indexed by mcHitID, required some gymnastics to work additional changes: * removed flat pz from toyMC simulation --> factor of 2.3 was to get tracks within 1.0 in eta * fixed up a warning on read-in * removed HitID and layerHitMap_ from Event --> made objects local, or replaced with simpler structures * ensured that values used in pulls correspond the track actually matched --- Event.cc | 140 ++++++++++++------------ Event.h | 16 +-- Hit.h | 1 + Makefile.config | 14 +-- Simulation.cc | 19 +--- TTreeValidation.cc | 228 ++++++++++++++++++++++++++-------------- TTreeValidation.h | 4 +- Track.h | 27 ++++- Validation.h | 1 - generateToyMCsamples.sh | 2 +- mkFit/MkBuilder.cc | 18 ++-- mkFit/mkFit.cc | 22 +++- 12 files changed, 287 insertions(+), 205 deletions(-) diff --git a/Event.cc b/Event.cc index 44287303422a1..743e115409cbd 100644 --- a/Event.cc +++ b/Event.cc @@ -37,31 +37,6 @@ inline bool sortByZ(const Hit& hit1, const Hit& hit2){ } #endif -void Event::resetLayerHitMap(bool resetSimHits) -{ - //gc: not sure what is being done here - layerHitMap_.clear(); - layerHitMap_.resize(simHitsInfo_.size()); - for (int ilayer = 0; ilayer < layerHits_.size(); ++ilayer) { - for (int index = 0; index < layerHits_[ilayer].size(); ++index) { - auto& hit = layerHits_[ilayer][index]; - assert(hit.mcHitID() >= 0); // tmp debug - assert(hit.mcHitID() < layerHitMap_.size()); - layerHitMap_[hit.mcHitID()] = HitID(ilayer, index); - } - } - // XXXMT4K is this still necessary? Or maybe I screwed up by doing the mapping below ... - if (resetSimHits) { - for (auto&& track : simTracks_) { - for (int il = 0; il < track.nTotalHits(); ++il) { - HitID &hid = layerHitMap_[track.getHitIdx(il)]; // XXXXMT4k This looks wrong - assert(hid.index >= 0); // tmp debug - track.setHitIdxLyr(il, hid.index, hid.layer); - } - } - } -} - Event::Event(const Geometry& g, Validation& v, int evtID, int threads) : geom_(g), validation_(v), evtID_(evtID), threads_(threads), mcHitIDCounter_(0) @@ -81,29 +56,56 @@ void Event::Reset(int evtID) for (auto&& l : segmentMap_) { l.clear(); } simHitsInfo_.clear(); - layerHitMap_.clear(); + simTrackStates_.clear(); simTracks_.clear(); + simTracksExtra_.clear(); seedTracks_.clear(); + seedTracksExtra_.clear(); candidateTracks_.clear(); + candidateTracksExtra_.clear(); fitTracks_.clear(); - simTrackStates_.clear(); + fitTracksExtra_.clear(); validation_.resetValidationMaps(); // need to reset maps for every event. } +void Event::RemapHits(TrackVec & tracks) +{ + std::unordered_map simHitMap; + int max_layer = Config::nTotalLayers; + for (int ilayer = 0; ilayer < max_layer; ++ilayer) + { + const auto & hit_vec = layerHits_[ilayer]; + const auto size = hit_vec.size(); + for (int index = 0; index < size; ++index) + { + simHitMap[hit_vec[index].mcHitID()] = index; + } + } + for (auto&& track : tracks) + { + for (int i = 0; i < track.nTotalHits(); ++i) + { + int hitidx = track.getHitIdx(i); + int hitlyr = track.getHitLyr(i); + if (hitidx >= 0) + { + track.setHitIdx(i, simHitMap[layerHits_[hitlyr][hitidx].mcHitID()]); + } + } + } +} + void Event::Simulate() { simTracks_.resize(Config::nTracks); - simHitsInfo_.clear(); simHitsInfo_.reserve(Config::nTotHit * Config::nTracks); + simTrackStates_.reserve(Config::nTotHit * Config::nTracks); for (auto&& l : layerHits_) { - // XXMT4K can not assume each track will have hits in every layer ... - // WAS: l.resize(Config::nTracks); // thread safety l.clear(); l.reserve(Config::nTracks); } - simTrackStates_.resize(Config::nTracks); #ifdef TBB parallel_for( tbb::blocked_range(0, Config::nTracks, 100), @@ -146,44 +148,54 @@ void Event::Simulate() } } #endif - // XXMT4K: From here on we can always have overlapping cache lines. - // I'm putting in a mutex for now ... + // MT: I'm putting in a mutex for now ... std::lock_guard lock(mcGatherMutex_); - // uber ugly way of getting around read-in / write-out of objects needed for validation - if (Config::root_val || Config::fit_val) {simTrackStates_[itrack] = initialTSs;} - validation_.collectSimTkTSVecMapInfo(itrack,initialTSs); // save initial TS parameters in validation object ... just a copy of the above line - simTracks_[itrack] = Track(q,pos,mom,covtrk,0.0f); auto& sim_track = simTracks_[itrack]; sim_track.setLabel(itrack); - // XXMT4K My attempt at rewriting the code below - not all layers are traversed with endcap. - // Note ... this still asusmes single hit per layer, right? - // What is the comment about thread safety??? The final index is on itrack and this will clash due to cache-line overlaps. + // XXKM4MT + // Sorta assumes one hit per layer -- could just make this 2X nMaxSimHits inside track object (without loopers) + // This really would only matter for validation and seeding... + // Could imagine making an inherited class for sim tracks that keeps tracks overlaps assert(hits.size() == hitinfos.size()); for (int i = 0; i < hits.size(); ++i) { // set to the correct hit index after sorting - sim_track.addHitIdx(hits[i].mcHitID(), -128, 0.0f); + sim_track.addHitIdx(layerHits_[hitinfos[i].layer_].size(), hitinfos[i].layer_, 0.0f); layerHits_[hitinfos[i].layer_].emplace_back(hits[i]); + simHitsInfo_.emplace_back(hitinfos[i]); + if (Config::root_val || Config::fit_val) + { + simTrackStates_.emplace_back(initialTSs[i]); + } } - // for (int ilay = 0; ilay < hits.size(); ++ilay) { - // sim_track.addHitIdx(hits[ilay].mcHitID(),0.0f); // set to the correct hit index after sorting - // layerHits_[ilay][itrack] = hits[ilay]; // thread safety - // } } #ifdef TBB }); #endif + // do some work to ensure everything is aligned after multithreading + std::unordered_map mcHitIDMap; + for (int ihit = 0; ihit < simHitsInfo_.size(); ihit++) + { + mcHitIDMap[simHitsInfo_[ihit].mcHitID()] = ihit; + } + std::sort(simHitsInfo_.begin(), simHitsInfo_.end(), - [](const MCHitInfo& a, const MCHitInfo& b) - { return a.mcHitID_ < b.mcHitID_; }); + [](const MCHitInfo& a, const MCHitInfo& b) + { return a.mcHitID() < b.mcHitID(); }); + + TSVec tmpTSVec(simTrackStates_.size()); + for (int its = 0; its < simTrackStates_.size(); its++) + { + tmpTSVec[its] = simTrackStates_[mcHitIDMap[its]]; + } + simTrackStates_ = tmpTSVec; } -// XXMT4K What does this do? Needs change? void Event::Segment() { #ifdef DEBUG @@ -286,7 +298,9 @@ void Event::Segment() std::cout << "layer: " << ilayer << " totalhits: " << etahitstotal << std::endl; } #endif - resetLayerHitMap(true); + + // need to reset simtrack hit indices after sorting! + RemapHits(simTracks_); } void Event::Seed() @@ -381,12 +395,10 @@ void Event::write_out(FILE *fp) evsize += sizeof(int) + nt*sizeof(Track); if (Config::root_val || Config::fit_val) { - for (int it = 0; it -// XXMT4K XXMT4D Is HitID and Event::layerHitMap_ still needed? - -struct HitID { - HitID() : layer(-1), index(-1) {} - HitID(int l, int i) : layer(l), index(i) {} - int layer; - int index; -}; - -typedef std::vector HitIDVec; - class Event { public: Event(const Geometry& g, Validation& v, int evtID, int threads = 1); void Reset(int evtID); + void RemapHits(TrackVec & tracks); void Simulate(); void Segment(); void Seed(); @@ -53,7 +43,6 @@ class Event std::atomic mcHitIDCounter_; std::vector layerHits_; MCHitInfoVec simHitsInfo_; - HitIDVec layerHitMap_; // indexed same as simHitsInfo_, maps to layer & hit TrackVec simTracks_, seedTracks_, candidateTracks_, fitTracks_; // validation sets these, so needs to be mutable @@ -67,8 +56,7 @@ class Event // vec[nLayers][nEtaBins][nPhiBins] BinInfoMap segmentMap_; - // used in normal validation --> only used on read-in / write-out (REALLY UGLY) - TkIDToTSVecVec simTrackStates_; + TSVec simTrackStates_; static std::mutex printmutex; }; diff --git a/Hit.h b/Hit.h index d3eeab732a27a..95593fac93e34 100644 --- a/Hit.h +++ b/Hit.h @@ -146,6 +146,7 @@ struct MCHitInfo int mcTrackID() const { return mcTrackID_; } int layer() const { return layer_; } + int mcHitID() const { return mcHitID_; } static void reset(); }; typedef std::vector MCHitInfoVec; diff --git a/Makefile.config b/Makefile.config index dd5f70f3258e4..437b2bcd8e286 100644 --- a/Makefile.config +++ b/Makefile.config @@ -112,15 +112,9 @@ WITH_TBB := yes # 14. Use for eta-phi segmentation USE_ETA_SEGMENTATION := -DETASEG -# 15. Generate flat in eta (originally just flat in pz) -GEN_FLAT_ETA := -DGENFLATETA - -# 16. Use inward fit in Conformal fit + final KF Fit +# 15. Use inward fit in Conformal fit + final KF Fit INWARD_FIT := -DINWARDFIT -# 17. Super debug mode --> allows really deep exploration of all props/updates etc with single track events, no skipping, in SMatrix, "yes" is irrevelant -#SUPER_DEBUG := yes - ################################################################ # Derived settings ################################################################ @@ -208,12 +202,6 @@ else CPPFLAGS += -DNO_ROOT endif -ifdef SUPER_DEBUG - CPPFLAGS := -I. -DCHECKSTATEVALID -DLINEARINTERP -DETASEG -DINWARDFIT -DGENFLATETA $(shell root-config --cflags) - CXXFLAGS := -O3 -g - LDFLAGS := $(shell root-config --libs) -endif - ################################################################ # Dependency generation ################################################################ diff --git a/Simulation.cc b/Simulation.cc index e3dce554123f4..22acf648ac440 100644 --- a/Simulation.cc +++ b/Simulation.cc @@ -38,9 +38,6 @@ void setupTrackByToyMC(SVector3& pos, SVector3& mom, SMatrixSym66& covtrk, dprint("phi= " << phi << std::endl); - // XXMT4K GENFLATETA is the default in Makefile.config - // Should we just remove the flat pz option? Or fix it ... -#ifdef GENFLATETA // this generates flat in eta roll_eta_dice: float eta = Config::minSimEta + (Config::maxSimEta - Config::minSimEta) * g_unif(g_gen); @@ -53,12 +50,6 @@ void setupTrackByToyMC(SVector3& pos, SVector3& mom, SMatrixSym66& covtrk, // XXXXMT Commented this out to get ecap_pos only !!!! //if (g_unif(g_gen) > 0.5) pz *= -1.; dprint("pz="< reco var == -99, "unassociated" reco to sim track, mcTrackID == -1 [possible mcmask_[reco] == 0; possible duplmask_[reco] == 2] {eff only} // --> sim var == -99, "unassociated" reco to sim track, mcTrackID == -1 [possible mcmask_[reco] == 0; possible duplmask_[reco] == 2] {FR only} // --> reco/sim var == -100, "no matching seed to build/fit" track, fill all reco/sim variables -100 [possible mcmask_[reco] == -1, possible duplmask_[reco] == -1] {FR only} +// --> sim var == -101, reco track is "associated" to sim track, however, sim track does have a hit on the layer the reco track is on // --> seedmask_[reco] == 1, matching seed to reco/fit track [possible mcmask_[reco] == 0,1; possible duplmask_[reco] == 0,1,2] {FR only} // --> seedmask_[reco] == 0, no matching seed to reco/fit track [possible mcmask_[reco] == -1; possible duplmask_[reco] == -1] {FR only} @@ -59,7 +60,8 @@ TTreeValidation::TTreeValidation(std::string fileName) initializeEfficiencyTree(); initializeFakeRateTree(); } - if (Config::fit_val) { + if (Config::fit_val) + { initializeFitTree(); } initializeConfigTree(); @@ -341,28 +343,24 @@ void TTreeValidation::initializeFitTree() void TTreeValidation::alignTrackExtra(TrackVec& evt_tracks, TrackExtraVec& evt_extras) { - TrackExtraVec trackExtra_tmp; + TrackExtraVec trackExtra_tmp(evt_tracks.size()); // align temporary tkExVec with new track collection ordering - for (auto&& track : evt_tracks){ - trackExtra_tmp.push_back(evt_extras[track.label()]); // label is old seedID! + for (int itrack = 0; itrack < evt_tracks.size(); itrack++) + { + trackExtra_tmp[itrack] = evt_extras[evt_tracks[itrack].label()]; // label is old seedID! } // now copy the temporary back in the old one evt_extras = trackExtra_tmp; // redo track labels to match index in vector - for (int i = 0; i < evt_tracks.size(); i++){ - evt_tracks[i].setLabel(i); + for (int itrack = 0; itrack < evt_tracks.size(); itrack++) + { + evt_tracks[itrack].setLabel(itrack); } } -void TTreeValidation::collectSimTkTSVecMapInfo(int mcTrackID, const TSVec& initTSs) -{ - std::lock_guard locker(glock_); - simTkTSVecMap_[mcTrackID] = initTSs; -} - void TTreeValidation::collectFitInfo(const FitVal & tmpfitval, int tkid, int layer) { std::lock_guard locker(glock_); @@ -373,10 +371,6 @@ void TTreeValidation::collectFitInfo(const FitVal & tmpfitval, int tkid, int lay void TTreeValidation::resetValidationMaps() { std::lock_guard locker(glock_); - - // reset map of sim tracks to MC track states (pre-smearing) - simTkTSVecMap_.clear(); - // reset fit validation map fitValTkMapMap_.clear(); @@ -479,6 +473,20 @@ void TTreeValidation::mapSeedTkToRecoTk(const TrackVec& evt_tracks, const TrackE } } +int TTreeValidation::getLastGoodHit(const int trackMCHitID, const int mcTrackID, const Event& ev) +{ + int mcHitID = -1; + if (ev.simHitsInfo_[trackMCHitID].mcTrackID() == mcTrackID) + { + mcHitID = trackMCHitID; + } + else + { + mcHitID = ev.simTracks_[mcTrackID].getMCHitIDFromLayer(ev.layerHits_,ev.simHitsInfo_[trackMCHitID].layer()); + } + return mcHitID; +} + void TTreeValidation::resetFitBranches() { for(int ilayer = 0; ilayer < Config::nTotalLayers; ++ilayer) @@ -519,9 +527,10 @@ void TTreeValidation::fillFitTree(const Event& ev) std::lock_guard locker(glock_); evtid_fit_ = ev.evtID(); - const auto& simtracks = ev.simTracks_; - const auto& layerhits = ev.layerHits_; - + const auto& simtracks = ev.simTracks_; + const auto& layerhits = ev.layerHits_; + const auto& simtrackstates = ev.simTrackStates_; + for(auto&& fitvalmapmap : fitValTkMapMap_) { resetFitBranches(); @@ -529,16 +538,14 @@ void TTreeValidation::fillFitTree(const Event& ev) tkid_fit_ = fitvalmapmap.first; // seed id (label) is the same as the mcID const auto& simtrack = simtracks[tkid_fit_]; - const auto& initTSs = simTkTSVecMap_[tkid_fit_]; - auto& fitvalmap = fitvalmapmap.second; - + const auto& fitvalmap = fitvalmapmap.second; for(int ilayer = 0; ilayer < Config::nTotalLayers; ++ilayer) { if (fitvalmap.count(ilayer)) { const auto& hit = layerhits[ilayer][simtrack.getHitIdx(ilayer)]; - const auto& initTS = initTSs[ilayer]; - const auto& fitval = fitvalmap[ilayer]; + const auto& initTS = simtrackstates.at(hit.mcHitID()); + const auto& fitval = fitvalmap.at(ilayer); z_hit_fit_[ilayer] = hit.z(); ez_hit_fit_[ilayer] = std::sqrt(hit.ezz()); @@ -586,6 +593,8 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) auto& evt_build_extras = ev.candidateTracksExtra_; auto& evt_fit_tracks = ev.fitTracks_; auto& evt_fit_extras = ev.fitTracksExtra_; + auto& evt_layer_hits = ev.layerHits_; + const auto& evt_sim_trackstates = ev.simTrackStates_; for (auto&& simtrack : evt_sim_tracks) { @@ -608,12 +617,25 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) seedID_seed_eff_ = seedextra.seedID(); // use this to access correct sim track layer params - const int layer = seedtrack.foundLayers().back(); // last layer seed ended up on - const TrackState & initLayTS = simTkTSVecMap_[mcID_eff_][layer]; //--> can do this as all sim tracks pass through each layer once, and are stored in order... will need to fix this once we have loopers/overlaps + const int mcHitID = getLastGoodHit(seedtrack.getLastGoodMCHitID(evt_layer_hits),mcID_eff_,ev); + if (mcHitID >= 0) + { + const TrackState & initLayTS = evt_sim_trackstates[mcHitID]; - pt_mc_seed_eff_ = initLayTS.pT(); - phi_mc_seed_eff_ = initLayTS.momPhi(); - eta_mc_seed_eff_ = initLayTS.momEta(); + pt_mc_seed_eff_ = initLayTS.pT(); + phi_mc_seed_eff_ = initLayTS.momPhi(); + eta_mc_seed_eff_ = initLayTS.momEta(); + + helixchi2_seed_eff_ = computeHelixChi2(initLayTS.parameters,seedtrack.parameters(),seedtrack.errors()); + } + else + { + pt_mc_seed_eff_ = -101; + phi_mc_seed_eff_ = -101; + eta_mc_seed_eff_ = -101; + + helixchi2_seed_eff_ = -101; + } pt_seed_eff_ = seedtrack.pT(); ept_seed_eff_ = seedtrack.epT(); @@ -628,7 +650,6 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) fracHitsMatched_seed_eff_ = float(nHitsMatched_seed_eff_) / float(nHits_seed_eff_); hitchi2_seed_eff_ = seedtrack.chi2(); // currently not being used - helixchi2_seed_eff_ = computeHelixChi2(initLayTS.parameters,seedtrack.parameters(),seedtrack.errors()); duplmask_seed_eff_ = seedextra.isDuplicate(); nTkMatches_seed_eff_ = simToSeedMap_[mcID_eff_].size(); // n reco matches to this sim track. @@ -671,12 +692,25 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) seedID_build_eff_ = buildextra.seedID(); // use this to access correct sim track layer params - const int layer = buildtrack.foundLayers().back(); // last layer build ended up on - const TrackState & initLayTS = simTkTSVecMap_[mcID_eff_][layer]; //--> can do this as all sim tracks pass through each layer once, and are stored in order... will need to fix this once we have loopers/overlaps + const int mcHitID = getLastGoodHit(buildtrack.getLastGoodMCHitID(evt_layer_hits),mcID_eff_,ev); + if (mcHitID >= 0) + { + const TrackState & initLayTS = evt_sim_trackstates[mcHitID]; - pt_mc_build_eff_ = initLayTS.pT(); - phi_mc_build_eff_ = initLayTS.momPhi(); - eta_mc_build_eff_ = initLayTS.momEta(); + pt_mc_build_eff_ = initLayTS.pT(); + phi_mc_build_eff_ = initLayTS.momPhi(); + eta_mc_build_eff_ = initLayTS.momEta(); + + helixchi2_build_eff_ = computeHelixChi2(initLayTS.parameters,buildtrack.parameters(),buildtrack.errors()); + } + else + { + pt_mc_build_eff_ = -101; + phi_mc_build_eff_ = -101; + eta_mc_build_eff_ = -101; + + helixchi2_build_eff_ = -101; + } pt_build_eff_ = buildtrack.pT(); ept_build_eff_ = buildtrack.epT(); @@ -690,7 +724,6 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) fracHitsMatched_build_eff_ = float(nHitsMatched_build_eff_) / float(nHits_build_eff_); hitchi2_build_eff_ = buildtrack.chi2(); - helixchi2_build_eff_ = computeHelixChi2(initLayTS.parameters,buildtrack.parameters(),buildtrack.errors()); duplmask_build_eff_ = buildextra.isDuplicate(); nTkMatches_build_eff_ = simToBuildMap_[mcID_eff_].size(); // n reco matches to this sim track. @@ -733,18 +766,26 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) seedID_fit_eff_ = fitextra.seedID(); // use this to access correct sim track layer params + const int mcHitID = getLastGoodHit(fittrack.getLastGoodMCHitID(evt_layer_hits),mcID_eff_,ev); + if (mcHitID >= 0) + { + const TrackState & initLayTS = evt_sim_trackstates[mcHitID]; -#ifdef INWARDFIT - const int layer = fittrack.foundLayers().front(); // last layer fit ended up on -#else - const int layer = fittrack.foundLayers().back(); // last layer fit ended up on -#endif - const TrackState & initLayTS = simTkTSVecMap_[mcID_eff_][layer]; //--> can do this as all sim tracks pass through each layer once, and are stored in order... will need to fix this once we have loopers/overlaps + pt_mc_fit_eff_ = initLayTS.pT(); + phi_mc_fit_eff_ = initLayTS.momPhi(); + eta_mc_fit_eff_ = initLayTS.momEta(); - pt_mc_fit_eff_ = initLayTS.pT(); - phi_mc_fit_eff_ = initLayTS.momPhi(); - eta_mc_fit_eff_ = initLayTS.momEta(); + helixchi2_fit_eff_ = computeHelixChi2(initLayTS.parameters,fittrack.parameters(),fittrack.errors()); + } + else + { + pt_mc_fit_eff_ = -101; + phi_mc_fit_eff_ = -101; + eta_mc_fit_eff_ = -101; + helixchi2_fit_eff_ = -101; + } + pt_fit_eff_ = fittrack.pT(); ept_fit_eff_ = fittrack.epT(); phi_fit_eff_ = fittrack.momPhi(); @@ -758,7 +799,6 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) fracHitsMatched_fit_eff_ = float(nHitsMatched_fit_eff_) / float(nHits_fit_eff_); hitchi2_fit_eff_ = -10; //fittrack.chi2(); // currently not being used - helixchi2_fit_eff_ = computeHelixChi2(initLayTS.parameters,fittrack.parameters(),fittrack.errors()); duplmask_fit_eff_ = fitextra.isDuplicate(); nTkMatches_fit_eff_ = simToFitMap_[mcID_eff_].size(); // n reco matches to this sim track. @@ -800,13 +840,16 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) std::lock_guard locker(glock_); auto ievt = ev.evtID(); + auto& evt_sim_tracks = ev.simTracks_; auto& evt_seed_tracks = ev.seedTracks_; auto& evt_seed_extras = ev.seedTracksExtra_; auto& evt_build_tracks = ev.candidateTracks_; auto& evt_build_extras = ev.candidateTracksExtra_; auto& evt_fit_tracks = ev.fitTracks_; auto& evt_fit_extras = ev.fitTracksExtra_; - + auto& evt_layer_hits = ev.layerHits_; + auto& evt_sim_trackstates = ev.simTrackStates_; + for (auto&& seedtrack : evt_seed_tracks) { evtID_FR_ = ievt; @@ -833,17 +876,29 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) mcID_seed_FR_ = seedextra.mcTrackID(); if (mcID_seed_FR_ >= 0) // store sim info at that final layer!!! --> gen info stored only in eff tree { + auto& simtrack = evt_sim_tracks[mcID_seed_FR_]; mcmask_seed_FR_ = 1; // matched track to sim - const int layer = seedtrack.foundLayers().back(); // last layer fit ended up on - const TrackState & initLayTS = simTkTSVecMap_[mcID_seed_FR_][layer]; //--> can do this as all sim tracks pass through each layer once, and are stored in order... will need to fix this once we have loopers/overlaps + const int mcHitID = getLastGoodHit(seedtrack.getLastGoodMCHitID(evt_layer_hits),mcID_seed_FR_,ev); + if (mcHitID >= 0) + { + const TrackState & initLayTS = evt_sim_trackstates[mcHitID]; + pt_mc_seed_FR_ = initLayTS.pT(); + phi_mc_seed_FR_ = initLayTS.momPhi(); + eta_mc_seed_FR_ = initLayTS.momEta(); + + helixchi2_seed_FR_ = computeHelixChi2(initLayTS.parameters,seedtrack.parameters(),seedtrack.errors()); + } + else + { + pt_mc_seed_FR_ = -101; + phi_mc_seed_FR_ = -101; + eta_mc_seed_FR_ = -101; - pt_mc_seed_FR_ = initLayTS.pT(); - phi_mc_seed_FR_ = initLayTS.momPhi(); - eta_mc_seed_FR_ = initLayTS.momEta(); - nHits_mc_seed_FR_ = simTkTSVecMap_[mcID_seed_FR_].size(); + helixchi2_seed_FR_ = -101; + } - helixchi2_seed_FR_ = computeHelixChi2(initLayTS.parameters,seedtrack.parameters(),seedtrack.errors()); + nHits_mc_seed_FR_ = simtrack.nFoundHits(); duplmask_seed_FR_ = seedextra.isDuplicate(); iTkMatches_seed_FR_ = seedextra.duplicateID(); // ith duplicate seed track, i = 0 "best" match, i > 0 "still matched, real reco, not as good as i-1 track" @@ -889,18 +944,30 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) mcID_build_FR_ = buildextra.mcTrackID(); if (mcID_build_FR_ >= 0) // build track matched to seed and sim { + auto& simtrack = evt_sim_tracks[mcID_build_FR_]; mcmask_build_FR_ = 1; // matched track to sim - const int layer = buildtrack.foundLayers().back(); // last layer fit ended up on - const TrackState & initLayTS = simTkTSVecMap_[mcID_build_FR_][layer]; //--> can do this as all sim tracks pass through each layer once, and are stored in order... will need to fix this once we have loopers/overlaps - - pt_mc_build_FR_ = initLayTS.pT(); - phi_mc_build_FR_ = initLayTS.momPhi(); - eta_mc_build_FR_ = initLayTS.momEta(); - nHits_mc_build_FR_ = simTkTSVecMap_[mcID_build_FR_].size(); + const int mcHitID = getLastGoodHit(buildtrack.getLastGoodMCHitID(evt_layer_hits),mcID_build_FR_,ev); + if (mcHitID >= 0) + { + const TrackState & initLayTS = evt_sim_trackstates[mcHitID]; + pt_mc_build_FR_ = initLayTS.pT(); + phi_mc_build_FR_ = initLayTS.momPhi(); + eta_mc_build_FR_ = initLayTS.momEta(); + + helixchi2_build_FR_ = computeHelixChi2(initLayTS.parameters,buildtrack.parameters(),buildtrack.errors()); + } + else + { + pt_mc_build_FR_ = -101; + phi_mc_build_FR_ = -101; + eta_mc_build_FR_ = -101; + + helixchi2_build_FR_ = -101; + } + + nHits_mc_build_FR_ = simtrack.nFoundHits(); - helixchi2_build_FR_ = computeHelixChi2(initLayTS.parameters,buildtrack.parameters(),buildtrack.errors()); - duplmask_build_FR_ = buildextra.isDuplicate(); iTkMatches_build_FR_ = buildextra.duplicateID(); // ith duplicate build track, i = 0 "best" match, i > 0 "still matched, real reco, not as good as i-1 track" } @@ -955,6 +1022,7 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) //============================// fit tracks if (seedToFitMap_.count(seedID_FR_)) { + auto& simtrack = evt_sim_tracks[mcID_fit_FR_]; seedmask_fit_FR_ = 1; // quick logic auto& fittrack = evt_fit_tracks[seedToFitMap_[seedID_FR_]]; @@ -978,19 +1046,27 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) if (mcID_fit_FR_ >= 0) // fit track matched to seed and sim { mcmask_fit_FR_ = 1; // matched track to sim -#ifdef INWARDFIT - const int layer = fittrack.foundLayers().front(); // last layer fiting ended up on -#else - const int layer = fittrack.foundLayers().back(); // last layer fiting ended up on -#endif - const TrackState & initLayTS = simTkTSVecMap_[mcID_fit_FR_][layer]; //--> can do this as all sim tracks pass through each layer once, and are stored in order... will need to fix this once we have loopers/overlaps - - pt_mc_fit_FR_ = initLayTS.pT(); // again, pt of mc truth at the layer the seed ends - phi_mc_fit_FR_ = initLayTS.momPhi(); - eta_mc_fit_FR_ = initLayTS.momEta(); - nHits_mc_fit_FR_ = simTkTSVecMap_[mcID_fit_FR_].size(); - - helixchi2_fit_FR_ = computeHelixChi2(initLayTS.parameters,fittrack.parameters(),fittrack.errors()); + + const int mcHitID = getLastGoodHit(fittrack.getLastGoodMCHitID(evt_layer_hits),mcID_fit_FR_,ev); // only works for outward fit for now + if (mcHitID >= 0) + { + const TrackState & initLayTS = evt_sim_trackstates[mcHitID]; + pt_mc_fit_FR_ = initLayTS.pT(); + phi_mc_fit_FR_ = initLayTS.momPhi(); + eta_mc_fit_FR_ = initLayTS.momEta(); + + helixchi2_fit_FR_ = computeHelixChi2(initLayTS.parameters,fittrack.parameters(),fittrack.errors()); + } + else + { + pt_mc_fit_FR_ = -101; + phi_mc_fit_FR_ = -101; + eta_mc_fit_FR_ = -101; + + helixchi2_fit_FR_ = -101; + } + + nHits_mc_fit_FR_ = simtrack.nFoundHits(); duplmask_fit_FR_ = fitextra.isDuplicate(); iTkMatches_fit_FR_ = fitextra.duplicateID(); // ith duplicate fit track, i = 0 "best" match, i > 0 "still matched, real reco, not as good as i-1 track" diff --git a/TTreeValidation.h b/TTreeValidation.h index 7a4b55372777a..45cd04ebc405e 100644 --- a/TTreeValidation.h +++ b/TTreeValidation.h @@ -32,7 +32,6 @@ class TTreeValidation : public Validation { void alignTrackExtra(TrackVec& evt_tracks, TrackExtraVec& evt_extra) override; - void collectSimTkTSVecMapInfo(int mcTrackID, const TSVec& initTSs) override; void collectFitInfo(const FitVal& tmpfitval, int tkid, int layer) override; void resetValidationMaps() override; @@ -47,6 +46,8 @@ class TTreeValidation : public Validation { void makeSeedTkToRecoTkMaps(Event& ev) override; void mapSeedTkToRecoTk(const TrackVec& evt_tracks, const TrackExtraVec& evt_extras, TkIDToTkIDMap& seedTkMap); + int getLastGoodHit(const int trackMCHitID, const int mcTrackID, const Event& ev); + void fillEfficiencyTree(const Event& ev) override; void fillFakeRateTree(const Event& ev) override; void fillConfigTree() override; @@ -57,7 +58,6 @@ class TTreeValidation : public Validation { private: TFile* f_; // output file! - TkIDToTSVecMap simTkTSVecMap_; // used for pulls (map all sim track TS to sim ID) ... also used in super debug mode TkIDtoFitValLayMapMap fitValTkMapMap_; // map used for fit validation in mplex // Sim to Reco Maps diff --git a/Track.h b/Track.h index d9b1619b6ad3e..88ea7d08f6a05 100644 --- a/Track.h +++ b/Track.h @@ -246,6 +246,32 @@ class Track return hitsOnTrk_[hitIdxPos_].layer; } + int getLastGoodHitIdx() const + { + return hitsOnTrk_[nGoodHitIdx_-1].index; + } + int getLastGoodHitLyr() const + { + return hitsOnTrk_[nGoodHitIdx_-1].layer; + } + int getLastGoodMCHitID(const std::vector& globalHitVec) const + { + return globalHitVec[hitsOnTrk_[nGoodHitIdx_-1].layer][hitsOnTrk_[nGoodHitIdx_-1].index].mcHitID(); + } + int getMCHitIDFromLayer(const std::vector& globalHitVec, int layer) const + { + int mcHitID = -1; + for (int ihit = 0; ihit <= hitIdxPos_; ++ihit) + { + if (hitsOnTrk_[ihit].layer == layer) + { + mcHitID = globalHitVec[hitsOnTrk_[ihit].layer][hitsOnTrk_[ihit].index].mcHitID(); + break; + } + } + return mcHitID; + } + const HitOnTrack* getHitsOnTrackArray() const { return hitsOnTrk_; } void fillEmptyLayers() { @@ -349,7 +375,6 @@ typedef std::vector > FltLayerPairVec; // used exclusively typedef std::unordered_map TkIDToTkIDMap; typedef std::unordered_map > TkIDToTkIDVecMap; typedef std::unordered_map TkIDToTSMap; -typedef std::unordered_map TkIDToTSVecMap; typedef std::unordered_map TkIDToTSLayerPairVecMap; void print(const TrackState& s); diff --git a/Validation.h b/Validation.h index 4b5d3d989c333..1e1fed4879156 100644 --- a/Validation.h +++ b/Validation.h @@ -28,7 +28,6 @@ class Validation { virtual void resetValidationMaps() {} virtual void resetDebugVectors() {} - virtual void collectSimTkTSVecMapInfo(int, const TSVec&) {} virtual void collectFitInfo(const FitVal&, int, int) {} virtual void setTrackExtras(Event& ev) {} diff --git a/generateToyMCsamples.sh b/generateToyMCsamples.sh index afaf59c3ba3a2..8832b3047008b 100755 --- a/generateToyMCsamples.sh +++ b/generateToyMCsamples.sh @@ -33,7 +33,7 @@ make -j 12 if [ ! -f ${dir}/simtracks_barrel_10x10k_val.bin ]; then echo "++++Generating 10k tracks/event * 10 events for ToyMC barrel-only validation tests++++" sed -i 's/#WITH_ROOT := yes/WITH_ROOT := yes/g' Makefile.config - ./mkFit/mkFit --num-thr-sim 1 --normal-val --num-events 10 --num-tracks 10000 --write --file-name simtracks_barrel_10x10k_val.bin + ./mkFit/mkFit --num-thr-sim 1 --root-val --num-events 10 --num-tracks 10000 --write --file-name simtracks_barrel_10x10k_val.bin mv simtracks_barrel_10x10k_val.bin ${dir}/ sed -i 's/WITH_ROOT := yes/#WITH_ROOT := yes/g' Makefile.config fi diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index 00e2fe76ec1d5..9f0b06b8b4c60 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -643,7 +643,7 @@ void MkBuilder::map_seed_hits() // map seed hit indices from global m_event->layerHits_[i] to hit indices in // structure m_event_of_hits.m_layers_of_hits[i].m_hits - HitIDVec seedLayersHitMap(m_event->simHitsInfo_.size()); + std::unordered_map seedHitMap; // XXMT4K: This was: Config::nlayers_per_seed, now not that simple. // In principle could have a list of seed layers (from outside (seed maker) or TrackerInfo). @@ -656,7 +656,7 @@ void MkBuilder::map_seed_hits() for (int index = 0; index < size; ++index) { - seedLayersHitMap[lof_m_hits[index].mcHitID()] = HitID(ilayer, index); + seedHitMap[lof_m_hits[index].mcHitID()] = index; } } @@ -670,7 +670,7 @@ void MkBuilder::map_seed_hits() { const auto & global_hit_vec = m_event->layerHits_[hitlyr]; - track.setHitIdx(i, seedLayersHitMap[global_hit_vec[hitidx].mcHitID()].index); + track.setHitIdx(i, seedHitMap[global_hit_vec[hitidx].mcHitID()]); } } } @@ -682,7 +682,7 @@ void MkBuilder::remap_seed_hits() // m_event_of_hits.m_layers_of_hits[i].m_hits to global // m_event->layerHits_[i] - HitIDVec seedLayersHitMap(m_event->simHitsInfo_.size()); + std::unordered_map seedHitMap; // XXMT4K: This was: Config::nlayers_per_seed, now not that simple. // In principle could have a list of seed layers (from outside (seed maker) or TrackerInfo). @@ -694,7 +694,7 @@ void MkBuilder::remap_seed_hits() const auto size = global_hit_vec.size(); for (int index = 0; index < size; ++index) { - seedLayersHitMap[global_hit_vec[index].mcHitID()] = HitID(ilayer, index); + seedHitMap[global_hit_vec[index].mcHitID()] = index; } } @@ -708,7 +708,7 @@ void MkBuilder::remap_seed_hits() { const auto & lof_m_hits = m_event_of_hits.m_layers_of_hits[hitlyr].m_hits; - track.setHitIdx(i, seedLayersHitMap[lof_m_hits[hitidx].mcHitID()].index); + track.setHitIdx(i, seedHitMap[lof_m_hits[hitidx].mcHitID()]); } } } @@ -720,7 +720,7 @@ void MkBuilder::remap_cand_hits() // m_event_of_hits.m_layers_of_hits[i].m_hits to global // m_event->layerHits_[i] - HitIDVec candLayersHitMap(m_event->simHitsInfo_.size()); + std::unordered_map candHitMap; int max_layer = Config::nTotalLayers; @@ -730,7 +730,7 @@ void MkBuilder::remap_cand_hits() const auto size = global_hit_vec.size(); for (int index = 0; index < size; ++index) { - candLayersHitMap[global_hit_vec[index].mcHitID()] = HitID(ilayer, index); + candHitMap[global_hit_vec[index].mcHitID()] = index; } } @@ -744,7 +744,7 @@ void MkBuilder::remap_cand_hits() { const auto & lof_m_hits = m_event_of_hits.m_layers_of_hits[hitlyr].m_hits; - track.setHitIdx(i, candLayersHitMap[lof_m_hits[hitidx].mcHitID()].index); + track.setHitIdx(i, candHitMap[lof_m_hits[hitidx].mcHitID()]); } } } diff --git a/mkFit/mkFit.cc b/mkFit/mkFit.cc index 3c48c0c52ff9f..1139d82d9392e 100644 --- a/mkFit/mkFit.cc +++ b/mkFit/mkFit.cc @@ -154,7 +154,24 @@ void generate_and_save_tracks() { ev.Reset(evt); ev.Simulate(); - ev.resetLayerHitMap(true); + +#ifdef DEBUG + for (int itrack = 0; itrack < ev.simTracks_.size(); itrack++) + { + const auto& track = ev.simTracks_[itrack]; + int mcTrackId = track.label(); + dprint("track: " << mcTrackId << " (" << itrack << ")"); + for (int ihit = 0; ihit < track.nTotalHits(); ihit++) + { + int idx = track.getHitIdx(ihit); int lyr = track.getHitLyr(ihit); + int mcHitID = ev.layerHits_[lyr][idx].mcHitID(); int mcTrackID = ev.simHitsInfo_[mcHitID].mcTrackID(); + float tsr = ev.simTrackStates_[mcHitID].posR(); float hitr = ev.layerHits_[lyr][idx].r(); + float tsz = ev.simTrackStates_[mcHitID].z(); float hitz = ev.layerHits_[lyr][idx].z(); + dprint(" " << mcTrackID << " (mcHitID: " << mcHitID << " ihit: " << ihit << " idx: " << idx << " lyr: " + << lyr << " tsr: " << tsr << " hitr: " << hitr << " tsz: " << tsz << " hitz: " << hitz << ")"); + } + } +#endif ev.write_out(fp); } @@ -247,7 +264,6 @@ void test_standard() printf("Simulating event %d\n", evt); events.emplace_back(geom, val, evt); events.back().Simulate(); - events.back().resetLayerHitMap(true); dprint("Event #" << events.back().evtID() << " simtracks " << events.back().simTracks_.size() << " layerhits " << events.back().layerHits_.size()); } @@ -331,12 +347,10 @@ void test_standard() if (g_operation == "read") { ev.read_in(fp, g_input_version); - ev.resetLayerHitMap(false);//hitIdx's in the sim tracks are already ok } else { ev.Simulate(); - ev.resetLayerHitMap(true); } plex_tracks.resize(ev.simTracks_.size()); From ddb1d05d260cd8a9a428089c226205827064a1a3 Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Fri, 14 Apr 2017 15:51:01 -0700 Subject: [PATCH 019/172] move segmentMap_ outside of the Event class --- Event.cc | 59 ++++++++++++++----------------------------------- Event.h | 10 +++------ Makefile.config | 7 ++---- buildtest.cc | 27 +++++++++------------- buildtest.h | 5 +++-- main.cc | 17 +++++++++----- seedtest.cc | 23 +------------------ 7 files changed, 47 insertions(+), 101 deletions(-) diff --git a/Event.cc b/Event.cc index 743e115409cbd..5f3d9ff5d287f 100644 --- a/Event.cc +++ b/Event.cc @@ -26,7 +26,6 @@ static bool tracksByPhi(const Track& t1, const Track& t2) return t1.posPhi() lay_phi_bin_count(Config::nPhiPart);//should it be 63? - yes! - for (int ihit=0;ihit0){ - lastIdxFound+=binSize; - } - } -#endif } // end loop over layers #ifdef DEBUG @@ -287,12 +260,12 @@ void Event::Segment() dmutex_guard; int etahitstotal = 0; for (int etabin = 0; etabin < Config::nEtaPart; etabin++){ - int etahits = segmentMap_[ilayer][etabin][Config::nPhiPart-1].first + segmentMap_[ilayer][etabin][Config::nPhiPart-1].second - segmentMap_[ilayer][etabin][0].first; + int etahits = segmentMap[ilayer][etabin][Config::nPhiPart-1].first + segmentMap[ilayer][etabin][Config::nPhiPart-1].second - segmentMap[ilayer][etabin][0].first; std::cout << "etabin: " << etabin << " hits in bin: " << etahits << std::endl; etahitstotal += etahits; for (int phibin = 0; phibin < Config::nPhiPart; phibin++){ - // if (segmentMap_[ilayer][etabin][phibin].second > 3) {std::cout << " phibin: " << phibin << " hits: " << segmentMap_[ilayer][etabin][phibin].second << std::endl;} + // if (segmentMap[ilayer][etabin][phibin].second > 3) {std::cout << " phibin: " << phibin << " hits: " << segmentMap[ilayer][etabin][phibin].second << std::endl;} } } std::cout << "layer: " << ilayer << " totalhits: " << etahitstotal << std::endl; @@ -303,12 +276,12 @@ void Event::Segment() RemapHits(simTracks_); } -void Event::Seed() +void Event::Seed(const BinInfoMap & segmentMap) { #ifdef ENDTOEND - buildSeedsByRoadSearch(seedTracks_,seedTracksExtra_,layerHits_,segmentMap_,*this); - // buildSeedsByRoadTriplets(seedTracks_,seedTracksExtra_,layerHits_,segmentMap_,*this); - //buildSeedsByRZFirstRPhiSecond(seedTracks_,seedTracksExtra_,layerHits_,segmentMap_,*this); + buildSeedsByRoadSearch(seedTracks_,seedTracksExtra_,layerHits_,segmentMap,*this); + // buildSeedsByRoadTriplets(seedTracks_,seedTracksExtra_,layerHits_,segmentMap,*this); + //buildSeedsByRZFirstRPhiSecond(seedTracks_,seedTracksExtra_,layerHits_,segmentMap,*this); #else buildSeedsByMC(simTracks_,seedTracks_,seedTracksExtra_,*this); simTracksExtra_ = seedTracksExtra_; @@ -317,10 +290,10 @@ void Event::Seed() validation_.alignTrackExtra(seedTracks_,seedTracksExtra_); // if we sort here, also have to sort seedTracksExtra and redo labels. } -void Event::Find() +void Event::Find(const BinInfoMap & segmentMap) { - buildTracksBySeeds(*this); - // buildTracksByLayers(*this); + buildTracksBySeeds(segmentMap,*this); + // buildTracksByLayers(segmentMap,*this); // From CHEP-2015 // buildTestSerial(*this, Config::nlayers_per_seed, Config::maxCandsPerSeed, Config::chi2Cut, Config::nSigma, Config::minDPhi); diff --git a/Event.h b/Event.h index 23ecdeaef5191..60d7b4887a53b 100644 --- a/Event.h +++ b/Event.h @@ -16,9 +16,9 @@ class Event void Reset(int evtID); void RemapHits(TrackVec & tracks); void Simulate(); - void Segment(); - void Seed(); - void Find(); + void Segment(BinInfoMap & segmentMap); + void Seed(const BinInfoMap & segmentMap); + void Find(const BinInfoMap & segmentMap); void Fit(); void Validate(); void PrintStats(const TrackVec&, TrackExtraVec&); @@ -52,10 +52,6 @@ class Event // There should be a better way of doing that. int seedEtaSeparators_[5]; - // phi-eta partitioning map: vector of vector of vectors of std::pairs. - // vec[nLayers][nEtaBins][nPhiBins] - BinInfoMap segmentMap_; - TSVec simTrackStates_; static std::mutex printmutex; }; diff --git a/Makefile.config b/Makefile.config index a4d19bbe07ab9..aded91889dcef 100644 --- a/Makefile.config +++ b/Makefile.config @@ -109,10 +109,7 @@ ENDTOEND := -DENDTOEND # have to be adjusted. WITH_TBB := yes -# 14. Use for eta-phi segmentation -USE_ETA_SEGMENTATION := -DETASEG - -# 15. Use inward fit in Conformal fit + final KF Fit +# 14. Use inward fit in Conformal fit + final KF Fit INWARD_FIT := -DINWARDFIT ################################################################ @@ -137,7 +134,7 @@ ifdef USE_CUDA endif endif -CPPFLAGS += ${USE_STATE_VALIDITY_CHECKS} ${USE_SCATTERING} ${USE_LINEAR_INTERPOLATION} ${ENDTOEND} ${USE_ETA_SEGMENTATION} ${INWARD_FIT} ${GEN_FLAT_ETA} +CPPFLAGS += ${USE_STATE_VALIDITY_CHECKS} ${USE_SCATTERING} ${USE_LINEAR_INTERPOLATION} ${ENDTOEND} ${INWARD_FIT} ifdef USE_VTUNE_NOTIFY ifdef VTUNE_AMPLIFIER_XE_2016_DIR diff --git a/buildtest.cc b/buildtest.cc index fa4bc17fa09f5..425ce74f3020c 100644 --- a/buildtest.cc +++ b/buildtest.cc @@ -25,7 +25,7 @@ static std::mutex evtlock; #endif typedef candvec::const_iterator canditer; -void extendCandidate(const Event& ev, const cand_t& cand, candvec& tmp_candidates, int ilay, int seedID, bool debug); +void extendCandidate(const BinInfoMap & segmentMap, const Event& ev, const cand_t& cand, candvec& tmp_candidates, int ilay, int seedID, bool debug); inline bool sortByHitsChi2(const cand_t& cand1, const cand_t& cand2) { @@ -33,7 +33,7 @@ inline bool sortByHitsChi2(const cand_t& cand1, const cand_t& cand2) return cand1.nFoundHits()>cand2.nFoundHits(); } -void processCandidates(Event& ev, candvec& candidates, int ilay, int seedID, const bool debug) +void processCandidates(const BinInfoMap & segmentMap, Event& ev, candvec& candidates, int ilay, int seedID, const bool debug) { auto& evt_track_candidates(ev.candidateTracks_); @@ -44,7 +44,7 @@ void processCandidates(Event& ev, candvec& candidates, int ilay, int seedID, con { //loop over running candidates for (auto&& cand : candidates) { - extendCandidate(ev, cand, tmp_candidates, ilay, seedID, debug); + extendCandidate(segmentMap, ev, cand, tmp_candidates, ilay, seedID, debug); } if (tmp_candidates.size()>Config::maxCandsPerSeed) { dprint("huge size=" << tmp_candidates.size() << " keeping best "<< Config::maxCandsPerSeed << " only"); @@ -69,7 +69,7 @@ void processCandidates(Event& ev, candvec& candidates, int ilay, int seedID, con } } -void buildTracksBySeeds(Event& ev) +void buildTracksBySeeds(const BinInfoMap & segmentMap, Event& ev) { auto& evt_track_candidates(ev.candidateTracks_); const auto& evt_lay_hits(ev.layerHits_); @@ -101,7 +101,7 @@ void buildTracksBySeeds(Event& ev) auto&& candidates(track_candidates[iseed]); for (int ilay=Config::nlayers_per_seed;ilay& evt_lay_hits, const BinInfoLayerMa const float outerhitz = evt_lay_hits[1][ihit].z(); // remember, layer[0] is first layer! --> second layer = [1] const float outerphi = evt_lay_hits[1][ihit].phi(); -#ifdef ETASEG // z cut is the largest killer... up to 3 sigma is probably best const auto etaBinMinus = getEtaPartition(getEta(Config::fRadialSpacing,(outerhitz-Config::seed_z0cut)/2.)); const auto etaBinPlus = getEtaPartition(getEta(Config::fRadialSpacing,(outerhitz+Config::seed_z0cut)/2.)); -#else - const auto etaBinMinus = 0; - const auto etaBinPlus = 0; -#endif const auto phiBinMinus = getPhiPartition(normalizedPhi(outerphi - Config::lay01angdiff)); const auto phiBinPlus = getPhiPartition(normalizedPhi(outerphi + Config::lay01angdiff)); @@ -382,24 +377,12 @@ void buildHitTripletsCurve(const std::vector& evt_lay_hits, const BinInf intersectThirdLayer(aneg,bneg,x1,y1,negx2,negy2); const float negPhi = getPhi(negx2,negy2); -#ifdef ETASEG const float thirdZline = 2*hit1.z()-hit0.z(); // for dz displacements -- straight line window const auto etaBinMinus = getEtaPartition(getEta(lay3rad,thirdZline)-Config::dEtaSeedTrip); const auto etaBinPlus = getEtaPartition(getEta(lay3rad,thirdZline)+Config::dEtaSeedTrip); -#else - const auto etaBinMinus = 0; - const auto etaBinPlus = 0; -#endif const auto phiBinMinus = getPhiPartition(negPhi); const auto phiBinPlus = getPhiPartition(posPhi); -#ifdef BROKEN_DEBUG - const float lay2phi = evt_lay_hits[2][ev.simTracks_[ev.simHitsInfo_[hit0.mcHitID()].mcTrackID()].getHitIdx(2)].phi(); - dprint("lay0 phi: " << hit0.phi() << " lay1 phi: " << hit1.phi() << std::endl << - "negPhi: " << negPhi << " lay2 phi: " << lay2phi << " posPhi: " << posPhi << std::endl << - "binM: " << phiBinMinus << " phi2Bin: " << getPhiPartition(lay2phi) << " binP: " << phiBinPlus << std::endl); -#endif - std::vector cand_hit_indices = getCandHitIndices(etaBinMinus,etaBinPlus,phiBinMinus,phiBinPlus,segLayMap); for (auto&& cand_hit_idx : cand_hit_indices){ TripletIdx hit_triplet; @@ -439,14 +422,10 @@ void buildHitTripletsApproxWindow(const std::vector& evt_lay_hits, const const Hit& hit0 = evt_lay_hits[0][hit_pair[0]]; const Hit& hit1 = evt_lay_hits[1][hit_pair[1]]; -#ifdef ETASEG const float thirdZline = 2*hit1.z()-hit0.z(); // for dz displacements -- straight line window const auto etaBinMinus = getEtaPartition(getEta(thirdRad,thirdZline)-Config::dEtaSeedTrip); const auto etaBinPlus = getEtaPartition(getEta(thirdRad,thirdZline)+Config::dEtaSeedTrip); -#else - const auto etaBinMinus = 0; - const auto etaBinPlus = 0; -#endif + const float linePhi = getPhi(hit1.position()[0] - hit0.position()[0], hit1.position()[1] - hit0.position()[1]); float thirdPhiMinus = 0.0f; float thirdPhiPlus = 0.0f; From 785cbec65095c81569fa50acfc4b83ed6d61072b Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Sat, 15 Apr 2017 03:49:26 -0700 Subject: [PATCH 020/172] add last layer a sim or reco track ended up on for both efficiency tree and fakerate tree --- TTreeValidation.cc | 57 ++++++++++++++++++++++++++++++++++++---------- TTreeValidation.h | 5 +++- 2 files changed, 49 insertions(+), 13 deletions(-) diff --git a/TTreeValidation.cc b/TTreeValidation.cc index e23e154d95b24..cb917274b0507 100644 --- a/TTreeValidation.cc +++ b/TTreeValidation.cc @@ -90,6 +90,7 @@ void TTreeValidation::initializeEfficiencyTree() efftree_->Branch("mcID",&mcID_eff_); efftree_->Branch("nHits_mc",&nHits_mc_eff_); + efftree_->Branch("lastlyr_mc",&lastlyr_mc_eff_); efftree_->Branch("seedID_seed",&seedID_seed_eff_); efftree_->Branch("seedID_build",&seedID_build_eff_); @@ -145,6 +146,10 @@ void TTreeValidation::initializeEfficiencyTree() efftree_->Branch("fracHitsMatched_build",&fracHitsMatched_build_eff_); efftree_->Branch("fracHitsMatched_fit",&fracHitsMatched_fit_eff_); + efftree_->Branch("lastlyr_seed",&lastlyr_seed_eff_); + efftree_->Branch("lastlyr_build",&lastlyr_build_eff_); + efftree_->Branch("lastlyr_fit",&lastlyr_fit_eff_); + efftree_->Branch("hitchi2_seed",&hitchi2_seed_eff_); efftree_->Branch("hitchi2_build",&hitchi2_build_eff_); efftree_->Branch("hitchi2_fit",&hitchi2_fit_eff_); @@ -207,6 +212,10 @@ void TTreeValidation::initializeFakeRateTree() fakeratetree_->Branch("fracHitsMatched_build",&fracHitsMatched_build_FR_); fakeratetree_->Branch("fracHitsMatched_fit",&fracHitsMatched_fit_FR_); + fakeratetree_->Branch("lastlyr_seed",&lastlyr_seed_FR_); + fakeratetree_->Branch("lastlyr_build",&lastlyr_build_FR_); + fakeratetree_->Branch("lastlyr_fit",&lastlyr_fit_FR_); + fakeratetree_->Branch("hitchi2_seed",&hitchi2_seed_FR_); fakeratetree_->Branch("hitchi2_build",&hitchi2_build_FR_); fakeratetree_->Branch("hitchi2_fit",&hitchi2_fit_FR_); @@ -236,6 +245,10 @@ void TTreeValidation::initializeFakeRateTree() fakeratetree_->Branch("nHits_mc_build",&nHits_mc_build_FR_); fakeratetree_->Branch("nHits_mc_fit",&nHits_mc_fit_FR_); + fakeratetree_->Branch("lastlyr_mc_seed",&lastlyr_mc_seed_FR_); + fakeratetree_->Branch("lastlyr_mc_build",&lastlyr_mc_build_FR_); + fakeratetree_->Branch("lastlyr_mc_fit",&lastlyr_mc_fit_FR_); + fakeratetree_->Branch("helixchi2_seed",&helixchi2_seed_FR_); fakeratetree_->Branch("helixchi2_build",&helixchi2_build_FR_); fakeratetree_->Branch("helixchi2_fit",&helixchi2_fit_FR_); @@ -606,6 +619,7 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) phi_mc_gen_eff_ = simtrack.momPhi(); eta_mc_gen_eff_ = simtrack.momEta(); nHits_mc_eff_ = simtrack.nFoundHits(); // could be that the sim track skips layers! + lastlyr_mc_eff_ = simtrack.getLastGoodHitLyr(); // matched seed track if (simToSeedMap_.count(mcID_eff_)) // recoToSim match : save best match --> most hits, lowest chi2, i.e. simToSeedMap_[matched SimID][first element in vector] @@ -648,15 +662,16 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) nHits_seed_eff_ = seedtrack.nFoundHits(); nHitsMatched_seed_eff_ = seedextra.nHitsMatched(); fracHitsMatched_seed_eff_ = float(nHitsMatched_seed_eff_) / float(nHits_seed_eff_); + lastlyr_seed_eff_ = seedtrack.getLastGoodHitLyr(); - hitchi2_seed_eff_ = seedtrack.chi2(); // currently not being used + hitchi2_seed_eff_ = seedtrack.chi2(); // currently not being used duplmask_seed_eff_ = seedextra.isDuplicate(); nTkMatches_seed_eff_ = simToSeedMap_[mcID_eff_].size(); // n reco matches to this sim track. } else // unmatched simTracks ... put -99 for all reco values to denote unmatched { - mcmask_seed_eff_ = 0; // quick logic for not matched + mcmask_seed_eff_ = 0; // quick logic for not matched seedID_seed_eff_ = -99; @@ -674,6 +689,7 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) nHits_seed_eff_ = -99; nHitsMatched_seed_eff_ = -99; fracHitsMatched_seed_eff_ = -99; + lastlyr_seed_eff_ = -99; hitchi2_seed_eff_ = -99; helixchi2_seed_eff_ = -99; @@ -722,15 +738,16 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) nHits_build_eff_ = buildtrack.nFoundHits(); nHitsMatched_build_eff_ = buildextra.nHitsMatched(); fracHitsMatched_build_eff_ = float(nHitsMatched_build_eff_) / float(nHits_build_eff_); + lastlyr_build_eff_ = buildtrack.getLastGoodHitLyr(); - hitchi2_build_eff_ = buildtrack.chi2(); + hitchi2_build_eff_ = buildtrack.chi2(); duplmask_build_eff_ = buildextra.isDuplicate(); nTkMatches_build_eff_ = simToBuildMap_[mcID_eff_].size(); // n reco matches to this sim track. } else // unmatched simTracks ... put -99 for all reco values to denote unmatched { - mcmask_build_eff_ = 0; // quick logic for not matched + mcmask_build_eff_ = 0; // quick logic for not matched seedID_build_eff_ = -99; @@ -748,7 +765,8 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) nHits_build_eff_ = -99; nHitsMatched_build_eff_ = -99; fracHitsMatched_build_eff_ = -99; - + lastlyr_build_eff_ = -99; + hitchi2_build_eff_ = -99; helixchi2_build_eff_ = -99; @@ -797,15 +815,16 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) nHits_fit_eff_ = fittrack.nFoundHits(); nHitsMatched_fit_eff_ = fitextra.nHitsMatched(); fracHitsMatched_fit_eff_ = float(nHitsMatched_fit_eff_) / float(nHits_fit_eff_); + lastlyr_fit_eff_ = fittrack.getLastGoodHitLyr(); - hitchi2_fit_eff_ = -10; //fittrack.chi2(); // currently not being used + hitchi2_fit_eff_ = -10; //fittrack.chi2(); // currently not being used duplmask_fit_eff_ = fitextra.isDuplicate(); nTkMatches_fit_eff_ = simToFitMap_[mcID_eff_].size(); // n reco matches to this sim track. } else // unmatched simTracks ... put -99 for all reco values to denote unmatched { - mcmask_fit_eff_ = 0; // quick logic for not matched + mcmask_fit_eff_ = 0; // quick logic for not matched seedID_fit_eff_ = -99; @@ -823,7 +842,8 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) nHits_fit_eff_ = -99; nHitsMatched_fit_eff_ = -99; fracHitsMatched_fit_eff_ = -99; - + lastlyr_fit_eff_ = -99; + hitchi2_fit_eff_ = -99; helixchi2_fit_eff_ = -99; @@ -869,6 +889,7 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) nHits_seed_FR_ = seedtrack.nFoundHits(); nHitsMatched_seed_FR_ = seedextra.nHitsMatched(); fracHitsMatched_seed_FR_ = float(nHitsMatched_seed_FR_) / float(nHits_seed_FR_); + lastlyr_seed_FR_ = seedtrack.getLastGoodHitLyr(); hitchi2_seed_FR_ = seedtrack.chi2(); //--> not currently used @@ -898,7 +919,8 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) helixchi2_seed_FR_ = -101; } - nHits_mc_seed_FR_ = simtrack.nFoundHits(); + nHits_mc_seed_FR_ = simtrack.nFoundHits(); + lastlyr_mc_seed_FR_ = simtrack.getLastGoodHitLyr(); duplmask_seed_FR_ = seedextra.isDuplicate(); iTkMatches_seed_FR_ = seedextra.duplicateID(); // ith duplicate seed track, i = 0 "best" match, i > 0 "still matched, real reco, not as good as i-1 track" @@ -912,6 +934,7 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) phi_mc_seed_FR_ = -99; eta_mc_seed_FR_ = -99; nHits_mc_seed_FR_ = -99; + lastlyr_mc_seed_FR_ = -99; duplmask_seed_FR_ = 2; // see notation above iTkMatches_seed_FR_ = -99; @@ -937,6 +960,7 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) nHits_build_FR_ = buildtrack.nFoundHits(); nHitsMatched_build_FR_ = buildextra.nHitsMatched(); fracHitsMatched_build_FR_ = float(nHitsMatched_build_FR_) / float(nHits_build_FR_); + lastlyr_build_FR_ = buildtrack.getLastGoodHitLyr(); hitchi2_build_FR_ = buildtrack.chi2(); @@ -966,8 +990,9 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) helixchi2_build_FR_ = -101; } - nHits_mc_build_FR_ = simtrack.nFoundHits(); - + nHits_mc_build_FR_ = simtrack.nFoundHits(); + lastlyr_mc_build_FR_ = simtrack.getLastGoodHitLyr(); + duplmask_build_FR_ = buildextra.isDuplicate(); iTkMatches_build_FR_ = buildextra.duplicateID(); // ith duplicate build track, i = 0 "best" match, i > 0 "still matched, real reco, not as good as i-1 track" } @@ -980,6 +1005,7 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) phi_mc_build_FR_ = -99; eta_mc_build_FR_ = -99; nHits_mc_build_FR_ = -99; + lastlyr_mc_build_FR_ = -99; duplmask_build_FR_ = 2; iTkMatches_build_FR_ = -99; @@ -1001,6 +1027,7 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) nHits_build_FR_ = -100; nHitsMatched_build_FR_ = -100; fracHitsMatched_build_FR_ = -100; + lastlyr_build_FR_ = -100; hitchi2_build_FR_ = -100; @@ -1012,6 +1039,7 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) phi_mc_build_FR_ = -100; eta_mc_build_FR_ = -100; nHits_mc_build_FR_ = -100; + lastlyr_mc_build_FR_ = -100; helixchi2_build_FR_ = -100; @@ -1038,6 +1066,7 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) nHits_fit_FR_ = fittrack.nFoundHits(); nHitsMatched_fit_FR_ = fitextra.nHitsMatched(); fracHitsMatched_fit_FR_ = float(nHitsMatched_fit_FR_) / float(nHits_fit_FR_); + lastlyr_fit_FR_ = fittrack.getLastGoodHitLyr(); hitchi2_fit_FR_ = -10; //fittrack.chi2() --> currently not used @@ -1066,7 +1095,8 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) helixchi2_fit_FR_ = -101; } - nHits_mc_fit_FR_ = simtrack.nFoundHits(); + nHits_mc_fit_FR_ = simtrack.nFoundHits(); + lastlyr_mc_fit_FR_ = simtrack.getLastGoodHitLyr(); duplmask_fit_FR_ = fitextra.isDuplicate(); iTkMatches_fit_FR_ = fitextra.duplicateID(); // ith duplicate fit track, i = 0 "best" match, i > 0 "still matched, real reco, not as good as i-1 track" @@ -1080,6 +1110,7 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) phi_mc_fit_FR_ = -99; eta_mc_fit_FR_ = -99; nHits_mc_fit_FR_ = -99; + lastlyr_mc_fit_FR_ = -99; duplmask_fit_FR_ = 2; iTkMatches_fit_FR_ = -99; @@ -1101,6 +1132,7 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) nHits_fit_FR_ = -100; nHitsMatched_fit_FR_ = -100; fracHitsMatched_fit_FR_ = -100; + lastlyr_fit_FR_ = -100; hitchi2_fit_FR_ = -100; @@ -1112,6 +1144,7 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) phi_mc_fit_FR_ = -100; eta_mc_fit_FR_ = -100; nHits_mc_fit_FR_ = -100; + lastlyr_mc_fit_FR_ = -100; helixchi2_fit_FR_ = -100; diff --git a/TTreeValidation.h b/TTreeValidation.h index 45cd04ebc405e..47ee5cf051977 100644 --- a/TTreeValidation.h +++ b/TTreeValidation.h @@ -77,7 +77,7 @@ class TTreeValidation : public Validation { // for efficiency and duplicate rate plots float pt_mc_gen_eff_=0.,phi_mc_gen_eff_=0.,eta_mc_gen_eff_=0.; - int nHits_mc_eff_=0; + int nHits_mc_eff_=0,lastlyr_mc_eff_=0; // for track resolutions / pulls float pt_mc_seed_eff_=0.,pt_mc_build_eff_=0.,pt_mc_fit_eff_=0.; @@ -91,6 +91,7 @@ class TTreeValidation : public Validation { int nHits_seed_eff_=0,nHits_build_eff_=0,nHits_fit_eff_=0; int nHitsMatched_seed_eff_=0,nHitsMatched_build_eff_=0,nHitsMatched_fit_eff_=0; float fracHitsMatched_seed_eff_=0,fracHitsMatched_build_eff_=0,fracHitsMatched_fit_eff_=0; + int lastlyr_seed_eff_=0,lastlyr_build_eff_=0,lastlyr_fit_eff_=0; // chi2 of tracks float hitchi2_seed_eff_=0.,hitchi2_build_eff_=0.,hitchi2_fit_eff_=0.; @@ -115,12 +116,14 @@ class TTreeValidation : public Validation { int nHits_seed_FR_=0,nHits_build_FR_=0,nHits_fit_FR_=0; int nHitsMatched_seed_FR_=0,nHitsMatched_build_FR_=0,nHitsMatched_fit_FR_=0; float fracHitsMatched_seed_FR_=0,fracHitsMatched_build_FR_=0,fracHitsMatched_fit_FR_=0; + int lastlyr_seed_FR_=0,lastlyr_build_FR_=0,lastlyr_fit_FR_=0; float hitchi2_seed_FR_=0.,hitchi2_build_FR_=0.,hitchi2_fit_FR_=0.; int mcID_seed_FR_=0,mcID_build_FR_=0,mcID_fit_FR_=0; int mcmask_seed_FR_=0,mcmask_build_FR_=0,mcmask_fit_FR_=0; int nHits_mc_seed_FR_=0,nHits_mc_build_FR_=0,nHits_mc_fit_FR_=0; + int lastlyr_mc_seed_FR_=0,lastlyr_mc_build_FR_=0,lastlyr_mc_fit_FR_=0; float helixchi2_seed_FR_=0.,helixchi2_build_FR_=0.,helixchi2_fit_FR_=0.; From d3e2de6541c156ba3383c1bce4bf1d64ec4b9c3a Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Sat, 15 Apr 2017 13:53:17 +0200 Subject: [PATCH 021/172] test macro to see where tracks are ending up on --- test/lastlyr.C | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 test/lastlyr.C diff --git a/test/lastlyr.C b/test/lastlyr.C new file mode 100644 index 0000000000000..7834aa631fef6 --- /dev/null +++ b/test/lastlyr.C @@ -0,0 +1,67 @@ +// Recipe: +// Makefile.config --> WITH_ROOT = yes (uncommented) +// make -j 12 +// ./mkFit/mkFit --num-thr-sim 12 --root-val --num-events 100000 --num-tracks 1 --write --file-name simtracks_fulldet_100kx1_val.bin +// ./mkFit/mkFit --root-val --read --file-name simtracks_fulldet_100kx1_val.bin --build-bh --num-thr 24 >& log_SNB_ToyMC_Barrel_BH_NVU8int_NTH24_val.txt + +void lastlyr() +{ + gStyle->SetOptStat(0); + + TFile * file = TFile::Open("valtree_SNB_ToyMC_Barrel_BH.root"); + TTree * tree = (TTree*)file->Get("efftree"); + + Float_t gen_eta = 0; TBranch * b_gen_eta = 0; tree->SetBranchAddress("eta_mc_gen",&gen_eta,&b_gen_eta); + Int_t mc_lyr = 0; TBranch * b_mc_lyr = 0; tree->SetBranchAddress("lastlyr_mc",&mc_lyr,&b_mc_lyr); + Int_t build_lyr = 0; TBranch * b_build_lyr = 0; tree->SetBranchAddress("lastlyr_build",&build_lyr,&b_build_lyr); + + TH1F * h_bl = new TH1F("h_bl","MC Last Layer - Reco Last Layer",10,0,10); + TH1F * h_em = new TH1F("h_em","MC Last Layer - Reco Last Layer",10,0,10); + TH1F * h_ep = new TH1F("h_ep","MC Last Layer - Reco Last Layer",10,0,10); + + h_bl->SetLineColor(kRed); + h_em->SetLineColor(kBlue); + h_ep->SetLineColor(kGreen); + + h_bl->SetMarkerColor(kRed); + h_em->SetMarkerColor(kBlue); + h_ep->SetMarkerColor(kGreen); + + h_bl->SetMarkerStyle(kFullCircle); + h_em->SetMarkerStyle(kFullSquare); + h_ep->SetMarkerStyle(kFullTriangleUp); + + for (UInt_t ientry = 0; ientry < tree->GetEntries(); ientry++) + { + tree->GetEntry(ientry); + + // barrel + if (std::abs(gen_eta) <= 1.0) + { + h_bl->Fill(mc_lyr-build_lyr); + } + // end cap minus + else if (gen_eta < -1.0) + { + h_em->Fill(mc_lyr-build_lyr); + } + // end cap plus + else if (gen_eta > 1.0) + { + h_ep->Fill(mc_lyr-build_lyr); + } + } + + TCanvas * canv = new TCanvas(); canv->cd(); + h_bl->Draw("epl"); + h_em->Draw("same epl"); + h_ep->Draw("same epl"); + + TLegend * leg = new TLegend(0.6,0.6,0.9,0.9); + leg->AddEntry(h_bl,Form("Barrel : %4.2f",h_bl->GetMean()),"epl"); + leg->AddEntry(h_em,Form("Endcap-: %4.2f",h_em->GetMean()),"epl"); + leg->AddEntry(h_ep,Form("Endcap+: %4.2f",h_ep->GetMean()),"epl"); + leg->Draw("same"); + + canv->SaveAs("lyrdiff.png"); +} From 797ac079ef1c9ca6e1533997067c3dc769b1a5ea Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Sat, 15 Apr 2017 14:08:00 +0200 Subject: [PATCH 022/172] log scale and scaled to unity for test diff layers macro --- test/lastlyr.C | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/test/lastlyr.C b/test/lastlyr.C index 7834aa631fef6..baf3f7d864b55 100644 --- a/test/lastlyr.C +++ b/test/lastlyr.C @@ -15,9 +15,9 @@ void lastlyr() Int_t mc_lyr = 0; TBranch * b_mc_lyr = 0; tree->SetBranchAddress("lastlyr_mc",&mc_lyr,&b_mc_lyr); Int_t build_lyr = 0; TBranch * b_build_lyr = 0; tree->SetBranchAddress("lastlyr_build",&build_lyr,&b_build_lyr); - TH1F * h_bl = new TH1F("h_bl","MC Last Layer - Reco Last Layer",10,0,10); - TH1F * h_em = new TH1F("h_em","MC Last Layer - Reco Last Layer",10,0,10); - TH1F * h_ep = new TH1F("h_ep","MC Last Layer - Reco Last Layer",10,0,10); + TH1F * h_bl = new TH1F("h_bl","MC Last Layer - Reco Last Layer",10,0,10); h_bl->Sumw2(); + TH1F * h_em = new TH1F("h_em","MC Last Layer - Reco Last Layer",10,0,10); h_em->Sumw2(); + TH1F * h_ep = new TH1F("h_ep","MC Last Layer - Reco Last Layer",10,0,10); h_ep->Sumw2(); h_bl->SetLineColor(kRed); h_em->SetLineColor(kBlue); @@ -52,7 +52,11 @@ void lastlyr() } } - TCanvas * canv = new TCanvas(); canv->cd(); + h_bl->Scale(1.0/h_bl->Integral()); + h_em->Scale(1.0/h_em->Integral()); + h_ep->Scale(1.0/h_ep->Integral()); + + TCanvas * canv = new TCanvas(); canv->cd(); canv->SetLogy(); h_bl->Draw("epl"); h_em->Draw("same epl"); h_ep->Draw("same epl"); From ac2070276c6c44889c608c3ffc1f7773754dc5ac Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Wed, 19 Apr 2017 17:25:56 -0700 Subject: [PATCH 023/172] Fix handling of zero candidates in a layer in find_tracks_in_layers(). --- mkFit/MkBuilder.cc | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index 9f0b06b8b4c60..2f6604c50415b 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -1280,7 +1280,20 @@ void MkBuilder::find_tracks_in_layers(CandCloner &cloner, MkFitter *mkfp, std::vector &scands = eoccs.m_candidates[iseed]; for (int ic = 0; ic < scands.size(); ++ic) { - if (scands[ic].getLastHitIdx() >= -1) // XXXXXXMT4MT what is -2, -3 now? + // XXXXXXMT4MT what is -2, -3 now? + // My understanding: + // -1 missing hit + // -2 missing hit - stopped tracking + // -3 missing hit due to detector geometry + // So -3 should also be taken -- but it only applies to CMS which is + // currently not used. + // + // TODO: + // 1. Renumber so stopped track is the most negative number. + // Can leave some room for future missing-hit-types. + // 2. Document these cases somewhere, have NAMES or constants or an enum. + // 3. Make sure they are used consistently everywhere. + if (scands[ic].getLastHitIdx() >= -1) { seed_cand_idx.push_back(std::pair(iseed,ic)); } @@ -1290,8 +1303,11 @@ void MkBuilder::find_tracks_in_layers(CandCloner &cloner, MkFitter *mkfp, // don't bother messing with the clone engine if there are no candidates // (actually it crashes, so this protection is needed) - // XXXX MT ??? How does this happen ??? - if (theEndCand == 0) continue; + + if (theEndCand == 0) { + if (ilay < 0) break; + else continue; + } if (ilay >= 0) { From c2617ac4d798b07d00fa8799e847b0798f1895df Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Thu, 20 Apr 2017 14:02:12 -0700 Subject: [PATCH 024/172] Make sure simulated hits are within the detector volume. This actually happened quite often, ~25% of hits ... but most of them were in the direction that didn't affect LayerOfHits, i.e., in r for barrel and in z for endcaps. See also the comment I added to that piece of code. --- Simulation.cc | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Simulation.cc b/Simulation.cc index 22acf648ac440..b40ad96bad842 100644 --- a/Simulation.cc +++ b/Simulation.cc @@ -38,8 +38,9 @@ void setupTrackByToyMC(SVector3& pos, SVector3& mom, SMatrixSym66& covtrk, dprint("phi= " << phi << std::endl); - // this generates flat in eta roll_eta_dice: + + // this generates flat in eta float eta = Config::minSimEta + (Config::maxSimEta - Config::minSimEta) * g_unif(g_gen); // XXXXMT Hardhack ... exclude transition region eta @@ -120,6 +121,8 @@ void setupTrackByToyMC(SVector3& pos, SVector3& mom, SMatrixSym66& covtrk, } bool is_barrel = theInitSolid->is_barrel_; +scatter_and_smear: + #ifdef SCATTERING // PW START // multiple scattering. Follow discussion in PDG Ch 32.3 @@ -293,7 +296,6 @@ void setupTrackByToyMC(SVector3& pos, SVector3& mom, SMatrixSym66& covtrk, } #endif - SVector3 x1(hitX,hitY,hitZ); SMatrixSym33 covXYZ = ROOT::Math::SMatrixIdentity(); #ifdef SOLID_SMEAR @@ -327,6 +329,20 @@ void setupTrackByToyMC(SVector3& pos, SVector3& mom, SMatrixSym66& covtrk, << "cov(0,1): " << covXYZ(0,1) << " cov(1,0): " << covXYZ(1,0) << std::endl); #endif + UVector3 x1(hitX,hitY,hitZ); + + // XXXXMT4K Are we introducing bias here? + // 1. I understand smearing needs to change position ... but I do not understand + // why multiple scattering needs to. Why doesn't it just change momentum? + // 2. Almost all hits are produced withing epsilon of the entry face. should + // we try to move it towards the center of the detector? + + if (theInitSolid->Inside(x1) == VUSolid::eOutside) + { + dprintf("re-scattering/smearing after hit got placed outside of layer %d\n", simLayer); + goto scatter_and_smear; + } + MCHitInfo hitinfo(itrack, simLayer, layer_counts[simLayer], ev.nextMCHitID()); hits.emplace_back(x1, covXYZ, hitinfo.mcHitID_); hitinfos.emplace_back(hitinfo); From 7000ce9a88addcd5225cb50a5b657ff2770c0878 Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Fri, 28 Apr 2017 07:31:27 -0700 Subject: [PATCH 025/172] Detector/layer mapping from cmssw to trackerinfo. --- cmssw-trackerinfo-desc.txt | 78 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 cmssw-trackerinfo-desc.txt diff --git a/cmssw-trackerinfo-desc.txt b/cmssw-trackerinfo-desc.txt new file mode 100644 index 0000000000000..3207e17159015 --- /dev/null +++ b/cmssw-trackerinfo-desc.txt @@ -0,0 +1,78 @@ +Storage of hits in Track objects +================================ + +struct HitOnTrack +{ + int index : 24; + int layer : 8; + + HitOnTrack() : index(-1), layer (-1) {} + HitOnTrack(int i, int l) : index( i), layer ( l) {} +}; + +index - index of hit withint the layer it belongs to; +layer - mapped from CMSSW detector/layer as described below. + + +CMSSW -> TrackerInfo layer numbering +==================================== + +CMSSW uses detector (1 - 6) / layer numbering, our code uses a single layer +index. + +*** 1. PIXB, 4 layers +1 -> 0 +2 -> 1 +3 -> 2 +4 -> 3 + +*** 3. TIB, 4 layers, 2 innermost are stereo +1m -> 4 +1s -> 5 +2m -> 6 +2s -> 7 +3 -> 8 +4 -> 9 + +*** 5. TOB, 6 layers, 2 innermost are stereo +1m -> 10 +1s -> 11 +2m -> 12 +2s -> 13 +3 -> 14 +4 -> 15 +5 -> 16 +6 -> 17 + +*** 2. PIXE, 3 layers; separate +z | -z !!! +1 -> 18 | 45 +2 -> 19 | 46 +3 -> 20 | 47 + +*** 4. TID, 3 layers, all partially stereo (bottom 2 modules) +1m -> 21 | 48 +1s -> 22 | 49 +2m -> 23 | 50 +2s -> 24 | 51 +3m -> 25 | 52 +3s -> 26 | 53 + +*** 6. TOD, 9, layers, all partially stereo (middle one modules, some bottomfringes) +1m -> 27 | 54 +1s -> 28 | 55 +2m -> 29 | 56 +2s -> 30 | 57 +3m -> 31 | 58 +3s -> 32 | 59 +4m -> 33 | 60 +4s -> 34 | 61 +5m -> 35 | 62 +5s -> 36 | 63 +6m -> 37 | 64 +6s -> 38 | 65 +7m -> 39 | 66 +7s -> 40 | 67 +8m -> 41 | 68 +8s -> 42 | 69 +9m -> 43 | 70 +9s -> 44 | 71 From 4905d299a2dace0dce5c89badff3014034af1ad0 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Tue, 2 May 2017 14:59:53 -0700 Subject: [PATCH 026/172] compiles --- tkNtuple/Makefile | 63 ++++ tkNtuple/WriteMemoryFile.cc | 622 ++++++++++++++++++++++++++++++++++++ 2 files changed, 685 insertions(+) create mode 100644 tkNtuple/Makefile create mode 100644 tkNtuple/WriteMemoryFile.cc diff --git a/tkNtuple/Makefile b/tkNtuple/Makefile new file mode 100644 index 0000000000000..f3c8d6023d051 --- /dev/null +++ b/tkNtuple/Makefile @@ -0,0 +1,63 @@ + +.PHONY: all clean distclean echo + +ifndef ROOTSYS +all: + @echo "ROOTSYS is not set. Please set ROOT environment properly"; echo +else +all: default + +CPPEXTRA := -I.. ${USER_CPPFLAGS} ${DEFS} +LDEXTRA := ${USER_LDFLAGS} + +CPPFLAGS := $(shell root-config --cflags) ${CPPEXTRA} ${CPPFLAGS} +CXXFLAGS += ${USER_CXXFLAGS} +LDFLAGS += $(shell root-config --ldflags --cflags --libs) ${LDEXTRA} + + +TGTS := writeMemoryFile + +EXES := ${TGTS} + +default: ${EXES} + +clean: + rm -f ${EXES} *.d *.o *.om + rm -rf writeMemoryFile.dSYM + +distclean: clean + rm -f *.optrpt + rm -f ${EXES} *.ah + +echo: + @echo "CXX = ${CXX}" + @echo "CPPFLAGS = ${CPPFLAGS}" + @echo "CXXFLAGS = ${CXXFLAGS}" + @echo "LDFLAGS = ${LDFLAGS}" + @echo "EXES = ${EXES}" + + +################################################################ + +# Should be a lib, really +ABOVE_OBJS := $(patsubst %, ../%.o, Config Matrix Hit Track ) + +${ABOVE_OBJS}: + ${MAKE} -C .. + +SRCS := $(wildcard *.cc) +HDRS := $(wildcard *.h) + +OBJS := $(SRCS:.cc=.o) + +ALLOBJS := ${OBJS} ${ABOVE_OBJS} + + +writeMemoryFile: ${OBJS} + ${CXX} ${CXXFLAGS} ${LDFLAGS} ${ALLOBJS} -o $@ + + +${OBJS}: %.o: %.cc + ${CXX} ${CPPFLAGS} ${CXXFLAGS} -c -o $@ $< +endif + diff --git a/tkNtuple/WriteMemoryFile.cc b/tkNtuple/WriteMemoryFile.cc new file mode 100644 index 0000000000000..a9fe066fe2304 --- /dev/null +++ b/tkNtuple/WriteMemoryFile.cc @@ -0,0 +1,622 @@ +#include "Track.h" +#include "TFile.h" +#include "TTree.h" + +struct LayerNumberConverter { +public: + LayerNumberConverter() {} + int convertLayerNumber(int cmsswdet, int cmsswlay, bool useMatched, int isStereo) { + if (cmsswdet==2 || cmsswdet==4 || cmsswdet==6) return -1; + if (cmsswdet==1) return cmsswlay-1; + if (useMatched) { + if (cmsswdet==3 && cmsswlay==1 && isStereo==-1) return 3; + if (cmsswdet==3 && cmsswlay==2 && isStereo==-1) return 4; + if (cmsswdet==3 && cmsswlay==3 && isStereo==0 ) return 5; + if (cmsswdet==3 && cmsswlay==4 && isStereo==0 ) return 6; + if (cmsswdet==5 && cmsswlay==1 && isStereo==-1) return 7; + if (cmsswdet==5 && cmsswlay==2 && isStereo==-1) return 8; + if (cmsswdet==5 && cmsswlay==3 && isStereo==0 ) return 9; + if (cmsswdet==5 && cmsswlay==4 && isStereo==0 ) return 10; + if (cmsswdet==5 && cmsswlay==5 && isStereo==0 ) return 11; + if (cmsswdet==5 && cmsswlay==6 && isStereo==0 ) return 12; + return -1; + } else { + if (cmsswdet==3 && cmsswlay==1 && isStereo==0) return 3; + if (cmsswdet==3 && cmsswlay==1 && isStereo==1) return 4; + if (cmsswdet==3 && cmsswlay==2 && isStereo==0) return 5; + if (cmsswdet==3 && cmsswlay==2 && isStereo==1) return 6; + if (cmsswdet==3 && cmsswlay==3 && isStereo==0) return 7; + if (cmsswdet==3 && cmsswlay==4 && isStereo==0) return 8; + if (cmsswdet==5 && cmsswlay==1 && isStereo==1) return 9; + if (cmsswdet==5 && cmsswlay==1 && isStereo==0) return 10; + if (cmsswdet==5 && cmsswlay==2 && isStereo==1) return 11; + if (cmsswdet==5 && cmsswlay==2 && isStereo==0) return 12; + if (cmsswdet==5 && cmsswlay==3 && isStereo==0) return 13; + if (cmsswdet==5 && cmsswlay==4 && isStereo==0) return 14; + if (cmsswdet==5 && cmsswlay==5 && isStereo==0) return 15; + if (cmsswdet==5 && cmsswlay==6 && isStereo==0) return 16; + return -1; + } + } + int convertDiskNumber(int cmsswdet, int cmsswdisk, bool useMatched, int isStereo) { + if (cmsswdet==1 || cmsswdet==3 || cmsswdet==5) return -1; + if (cmsswdet==2) return cmsswdisk-1; + if (useMatched) { + return -1; + } else { + if (cmsswdet==4 && cmsswdisk==1 && isStereo==0) return 2; + if (cmsswdet==4 && cmsswdisk==1 && isStereo==1) return 3; + if (cmsswdet==4 && cmsswdisk==2 && isStereo==0) return 4; + if (cmsswdet==4 && cmsswdisk==2 && isStereo==1) return 5; + if (cmsswdet==4 && cmsswdisk==3 && isStereo==0) return 6; + if (cmsswdet==4 && cmsswdisk==3 && isStereo==1) return 7; + if (cmsswdet==6 && cmsswdisk==1 && isStereo==1) return 8; + if (cmsswdet==6 && cmsswdisk==1 && isStereo==0) return 9; + if (cmsswdet==6 && cmsswdisk==2 && isStereo==1) return 10; + if (cmsswdet==6 && cmsswdisk==2 && isStereo==0) return 11; + if (cmsswdet==6 && cmsswdisk==3 && isStereo==1) return 12; + if (cmsswdet==6 && cmsswdisk==3 && isStereo==0) return 13; + if (cmsswdet==6 && cmsswdisk==4 && isStereo==1) return 14; + if (cmsswdet==6 && cmsswdisk==4 && isStereo==0) return 15; + if (cmsswdet==6 && cmsswdisk==5 && isStereo==1) return 16; + if (cmsswdet==6 && cmsswdisk==5 && isStereo==0) return 17; + if (cmsswdet==6 && cmsswdisk==6 && isStereo==1) return 18; + if (cmsswdet==6 && cmsswdisk==6 && isStereo==0) return 19; + if (cmsswdet==6 && cmsswdisk==7 && isStereo==1) return 20; + if (cmsswdet==6 && cmsswdisk==7 && isStereo==0) return 21; + if (cmsswdet==6 && cmsswdisk==8 && isStereo==1) return 22; + if (cmsswdet==6 && cmsswdisk==8 && isStereo==0) return 23; + if (cmsswdet==6 && cmsswdisk==9 && isStereo==1) return 24; + if (cmsswdet==6 && cmsswdisk==9 && isStereo==0) return 25; + return -1; + } + } +}; + +bool useMatched = false; +bool doEndcap = true;//otherwise do barrel, both at the same time not supported for now + +int main() { + + using namespace std; + + LayerNumberConverter lnc; + + long long maxevt = 0; + + int nstot = 0; + int nhitstot[Config::nTotalLayers]; + std::fill_n(nhitstot, Config::nTotalLayers, 0); + + TString outfilename = ""; + + // TFile* f = TFile::Open("./ntuple_test_1GeV_10k_split.root"); maxevt = 3000;outfilename = "cmssw_3kxSingleMu1GeV_split_endcap.bin"; + TFile* f = TFile::Open("./ntuple_test_10GeV_10k_split.root"); maxevt = 3000;outfilename = "cmssw_3kxSingleMu10GeV_split_endcap.bin"; + //TFile* f = TFile::Open("./ntuple_test_1GeV_10k.root"); + // TFile* f = TFile::Open(useMatched ? "./ntuple_test_1GeV_10k_noSplit_mock_noFWD.root" : "./ntuple_test_1GeV_10k_split_mock_noFWD.root");maxevt = 3000;outfilename = (useMatched ? "cmssw_3kxSingleMu1GeV_polar_noSplit_mock_noFWD.bin" : "cmssw_3kxSingleMu1GeV_polar_split_mock_noFWD.bin"); + // TFile* f = TFile::Open(useMatched ? "./ntuple_test_10GeV_10k_noSplit_mock_noFWD.root" : "./ntuple_test_10GeV_10k_split_mock_noFWD.root");maxevt = 3000;outfilename = (useMatched ? "cmssw_3kxSingleMu10GeV_polar_noSplit_mock_noFWD.bin" : "cmssw_3kxSingleMu10GeV_polar_split_mock_noFWD.bin"); + // TFile* f = TFile::Open("./ntuple_test_ZTT_split_mock_noFWD.root");assert(useMatched==false);maxevt = 500;outfilename = "cmssw_500xZTT_polar_split_mock_noFWD.bin"; + // TFile* f = TFile::Open("./ntuple_test_TTbar_split_mock_noFWD.root");assert(useMatched==false);maxevt = 500;outfilename = "cmssw_500xTTbar_polar_split_mock_noFWD.bin"; + // TFile* f = TFile::Open("./ntuple_test_TTbarPU10_split_mock_noFWD.root");assert(useMatched==false);maxevt = 100;outfilename = "cmssw_100xTTbarPU10_polar_split_mock_noFWD.bin"; + // TFile* f = TFile::Open("./ntuple_test_TTbarPU35_split_mock_noFWD.root");assert(useMatched==false);maxevt = 100;outfilename = "cmssw_100xTTbarPU35_polar_split_mock_noFWD.bin"; + + TTree* t = (TTree*) f->Get("trkTree/tree"); + + FILE * fp; + fp = fopen (outfilename.Data(), "wb"); + + int evt; + t->SetBranchAddress("evt",&evt); + + //sim tracks + std::vector* sim_eta = 0; + std::vector* sim_px = 0; + std::vector* sim_py = 0; + std::vector* sim_pz = 0; + std::vector* sim_prodx = 0; + std::vector* sim_prody = 0; + std::vector* sim_prodz = 0; + std::vector* sim_q = 0; + std::vector >* sim_pixelIdx = 0; + std::vector >* sim_stripIdx = 0; + std::vector* sim_trkIdx = 0; + t->SetBranchAddress("sim_eta",&sim_eta); + t->SetBranchAddress("sim_px",&sim_px); + t->SetBranchAddress("sim_py",&sim_py); + t->SetBranchAddress("sim_pz",&sim_pz); + t->SetBranchAddress("sim_prodx",&sim_prodx); + t->SetBranchAddress("sim_prody",&sim_prody); + t->SetBranchAddress("sim_prodz",&sim_prodz); + t->SetBranchAddress("sim_q",&sim_q); + t->SetBranchAddress("sim_pixelIdx",&sim_pixelIdx); + t->SetBranchAddress("sim_stripIdx",&sim_stripIdx); + t->SetBranchAddress("sim_trkIdx",&sim_trkIdx); + + //rec tracks + std::vector* trk_nValid = 0; + std::vector* trk_nInvalid = 0; + std::vector* trk_nLay = 0; + std::vector* trk_seedIdx = 0; + std::vector >* trk_pixelIdx = 0; + std::vector >* trk_stripIdx = 0; + std::vector >* trk_gluedIdx = 0; + t->SetBranchAddress("trk_nValid",&trk_nValid); + t->SetBranchAddress("trk_nInvalid",&trk_nInvalid); + t->SetBranchAddress("trk_nLay",&trk_nLay); + t->SetBranchAddress("trk_seedIdx",&trk_seedIdx); + t->SetBranchAddress("trk_pixelIdx",&trk_pixelIdx); + t->SetBranchAddress("trk_stripIdx",&trk_stripIdx); + t->SetBranchAddress("trk_gluedIdx",&trk_gluedIdx); + + //seeds + std::vector* see_x = 0; + std::vector* see_y = 0; + std::vector* see_z = 0; + std::vector* see_px = 0; + std::vector* see_py = 0; + std::vector* see_pz = 0; + std::vector* see_eta= 0; + std::vector* see_pt = 0; + std::vector* see_cov00 = 0; + std::vector* see_cov01 = 0; + std::vector* see_cov02 = 0; + std::vector* see_cov03 = 0; + std::vector* see_cov04 = 0; + std::vector* see_cov05 = 0; + std::vector* see_cov11 = 0; + std::vector* see_cov12 = 0; + std::vector* see_cov13 = 0; + std::vector* see_cov14 = 0; + std::vector* see_cov15 = 0; + std::vector* see_cov22 = 0; + std::vector* see_cov23 = 0; + std::vector* see_cov24 = 0; + std::vector* see_cov25 = 0; + std::vector* see_cov33 = 0; + std::vector* see_cov34 = 0; + std::vector* see_cov35 = 0; + std::vector* see_cov44 = 0; + std::vector* see_cov45 = 0; + std::vector* see_cov55 = 0; + std::vector* see_q = 0; + std::vector* see_algo = 0; + std::vector >* see_pixelIdx = 0; + t->SetBranchAddress("see_x",&see_x); + t->SetBranchAddress("see_y",&see_y); + t->SetBranchAddress("see_z",&see_z); + t->SetBranchAddress("see_px",&see_px); + t->SetBranchAddress("see_py",&see_py); + t->SetBranchAddress("see_pz",&see_pz); + t->SetBranchAddress("see_eta",&see_eta); + t->SetBranchAddress("see_pt",&see_pt); + t->SetBranchAddress("see_cov00",&see_cov00); + t->SetBranchAddress("see_cov01",&see_cov01); + t->SetBranchAddress("see_cov02",&see_cov02); + t->SetBranchAddress("see_cov03",&see_cov03); + t->SetBranchAddress("see_cov04",&see_cov04); + t->SetBranchAddress("see_cov05",&see_cov05); + t->SetBranchAddress("see_cov11",&see_cov11); + t->SetBranchAddress("see_cov12",&see_cov12); + t->SetBranchAddress("see_cov13",&see_cov13); + t->SetBranchAddress("see_cov14",&see_cov14); + t->SetBranchAddress("see_cov15",&see_cov15); + t->SetBranchAddress("see_cov22",&see_cov22); + t->SetBranchAddress("see_cov23",&see_cov23); + t->SetBranchAddress("see_cov24",&see_cov24); + t->SetBranchAddress("see_cov25",&see_cov25); + t->SetBranchAddress("see_cov33",&see_cov33); + t->SetBranchAddress("see_cov34",&see_cov34); + t->SetBranchAddress("see_cov35",&see_cov35); + t->SetBranchAddress("see_cov44",&see_cov44); + t->SetBranchAddress("see_cov45",&see_cov45); + t->SetBranchAddress("see_cov55",&see_cov55); + t->SetBranchAddress("see_q",&see_q); + t->SetBranchAddress("see_algo",&see_algo); + t->SetBranchAddress("see_pixelIdx",&see_pixelIdx); + + //pixel hits + vector* pix_isBarrel = 0; + vector* pix_lay = 0; + vector* pix_simTrkIdx = 0; + vector* pix_particle = 0; + vector* pix_process = 0; + vector* pix_posFromTrack = 0; + vector* pix_onTrack = 0; + vector* pix_x = 0; + vector* pix_y = 0; + vector* pix_z = 0; + vector* pix_xx = 0; + vector* pix_xy = 0; + vector* pix_yy = 0; + vector* pix_yz = 0; + vector* pix_zz = 0; + vector* pix_zx = 0; + t->SetBranchAddress("pix_isBarrel",&pix_isBarrel); + t->SetBranchAddress("pix_lay",&pix_lay); + t->SetBranchAddress("pix_simTrkIdx",&pix_simTrkIdx); + t->SetBranchAddress("pix_particle",&pix_particle); + t->SetBranchAddress("pix_process",&pix_process); + t->SetBranchAddress("pix_posFromTrack",&pix_posFromTrack); + t->SetBranchAddress("pix_onTrack",&pix_onTrack); + t->SetBranchAddress("pix_x",&pix_x); + t->SetBranchAddress("pix_y",&pix_y); + t->SetBranchAddress("pix_z",&pix_z); + t->SetBranchAddress("pix_xx",&pix_xx); + t->SetBranchAddress("pix_xy",&pix_xy); + t->SetBranchAddress("pix_yy",&pix_yy); + t->SetBranchAddress("pix_yz",&pix_yz); + t->SetBranchAddress("pix_zz",&pix_zz); + t->SetBranchAddress("pix_zx",&pix_zx); + + //strip hits + vector* glu_monoIdx = 0; + vector* glu_stereoIdx = 0; + vector* glu_isBarrel = 0; + vector* glu_lay = 0; + vector* glu_det = 0; + vector* glu_posFromTrack = 0; + vector* glu_onTrack = 0; + vector* glu_x = 0; + vector* glu_y = 0; + vector* glu_z = 0; + vector* glu_xx = 0; + vector* glu_xy = 0; + vector* glu_yy = 0; + vector* glu_yz = 0; + vector* glu_zz = 0; + vector* glu_zx = 0; + if (useMatched) { + t->SetBranchAddress("glu_monoIdx",&glu_monoIdx); + t->SetBranchAddress("glu_stereoIdx",&glu_stereoIdx); + t->SetBranchAddress("glu_isBarrel",&glu_isBarrel); + t->SetBranchAddress("glu_lay",&glu_lay); + t->SetBranchAddress("glu_det",&glu_det); + t->SetBranchAddress("glu_posFromTrack",&glu_posFromTrack); + t->SetBranchAddress("glu_onTrack",&glu_onTrack); + t->SetBranchAddress("glu_x",&glu_x); + t->SetBranchAddress("glu_y",&glu_y); + t->SetBranchAddress("glu_z",&glu_z); + t->SetBranchAddress("glu_xx",&glu_xx); + t->SetBranchAddress("glu_xy",&glu_xy); + t->SetBranchAddress("glu_yy",&glu_yy); + t->SetBranchAddress("glu_yz",&glu_yz); + t->SetBranchAddress("glu_zz",&glu_zz); + t->SetBranchAddress("glu_zx",&glu_zx); + } + vector* str_isBarrel = 0; + vector* str_isStereo = 0; + vector* str_lay = 0; + vector* str_det = 0; + vector* str_simTrkIdx = 0; + vector* str_particle = 0; + vector* str_process = 0; + vector* str_posFromTrack = 0; + vector* str_onTrack = 0; + vector* str_x = 0; + vector* str_y = 0; + vector* str_z = 0; + vector* str_xx = 0; + vector* str_xy = 0; + vector* str_yy = 0; + vector* str_yz = 0; + vector* str_zz = 0; + vector* str_zx = 0; + t->SetBranchAddress("str_isBarrel",&str_isBarrel); + t->SetBranchAddress("str_isStereo",&str_isStereo); + t->SetBranchAddress("str_lay",&str_lay); + t->SetBranchAddress("str_det",&str_det); + t->SetBranchAddress("str_simTrkIdx",&str_simTrkIdx); + t->SetBranchAddress("str_particle",&str_particle); + t->SetBranchAddress("str_process",&str_process); + t->SetBranchAddress("str_posFromTrack",&str_posFromTrack); + t->SetBranchAddress("str_onTrack",&str_onTrack); + t->SetBranchAddress("str_x",&str_x); + t->SetBranchAddress("str_y",&str_y); + t->SetBranchAddress("str_z",&str_z); + t->SetBranchAddress("str_xx",&str_xx); + t->SetBranchAddress("str_xy",&str_xy); + t->SetBranchAddress("str_yy",&str_yy); + t->SetBranchAddress("str_yz",&str_yz); + t->SetBranchAddress("str_zz",&str_zz); + t->SetBranchAddress("str_zx",&str_zx); + + fwrite(&maxevt, sizeof(int), 1, fp); + + long long totentries = t->GetEntriesFast(); + + long long savedEvents = 0; + for (long long i = 0; savedEvents < maxevt && i simTracks_; + vector simTrackIdx_(sim_q->size(),-1);//keep track of original index in ntuple + vector seedSimIdx(see_x->size(),-1); + for (int isim = 0; isim < sim_q->size(); ++isim) { + + //if (fabs(sim_eta->at(isim))>0.8) continue; + + int trkIdx = sim_trkIdx->at(isim); + //if (trkIdx<0) continue; + + int nlay = 0; + int hitlay[Config::nTotalLayers]; + std::fill_n(hitlay, Config::nTotalLayers, 0); + if (trkIdx>=0) { + for (int ihit = 0; ihit < trk_pixelIdx->at(trkIdx).size(); ++ihit) { + int ipix = trk_pixelIdx->at(trkIdx).at(ihit); + if (ipix<0) continue; + if (doEndcap) { + int cmsswdisk = lnc.convertDiskNumber((pix_isBarrel->at(ipix)?1:2),pix_lay->at(ipix),useMatched,-1); + if (cmsswdisk>=0 && cmsswdiskat(ipix)?1:2),pix_lay->at(ipix),useMatched,-1); + if (cmsswlay>=0 && cmsswlayat(trkIdx).size(); ++ihit) { + int iglu = trk_gluedIdx->at(trkIdx).at(ihit); + if (iglu<0) continue; + int cmsswlay = lnc.convertLayerNumber(glu_det->at(iglu),glu_lay->at(iglu),useMatched,-1); + if (cmsswlay>=0 && cmsswlayat(trkIdx).size(); ++ihit) { + int istr = trk_stripIdx->at(trkIdx).at(ihit); + if (istr<0) continue; + if (doEndcap) { + int cmsswdisk = lnc.convertDiskNumber(str_det->at(istr),str_lay->at(istr),useMatched,str_isStereo->at(istr)); + if (cmsswdisk>=0 && cmsswdiskat(istr),str_lay->at(istr),useMatched,str_isStereo->at(istr)); + if (cmsswlay>=0 && cmsswlay0) nlay++; + } + + //cout << Form("track q=%2i p=(%6.3f, %6.3f, %6.3f) x=(%6.3f, %6.3f, %6.3f) nlay=%i",sim_q->at(isim),sim_px->at(isim),sim_py->at(isim),sim_pz->at(isim),sim_prodx->at(isim),sim_prody->at(isim),sim_prodz->at(isim),nlay) << endl; + + SVector3 pos(sim_prodx->at(isim),sim_prody->at(isim),sim_prodz->at(isim)); + SVector3 mom(sim_px->at(isim),sim_py->at(isim),sim_pz->at(isim)); + SMatrixSym66 err; + err.At(0,0) = sim_prodx->at(isim)*sim_prodx->at(isim); + err.At(1,1) = sim_prody->at(isim)*sim_prody->at(isim); + err.At(2,2) = sim_prodz->at(isim)*sim_prodz->at(isim); + err.At(3,3) = sim_px->at(isim)*sim_px->at(isim); + err.At(4,4) = sim_py->at(isim)*sim_py->at(isim); + err.At(5,5) = sim_pz->at(isim)*sim_pz->at(isim); + TrackState state(sim_q->at(isim), pos, mom, err); +#ifdef CCSCOORD + //begin test CCS coordinates, define CCSCOORD in $(MICTESTDIR)/Config.h + state.convertFromCartesianToCCS(); + //end test CCS coordinates +#endif + Track track(state, float(nlay), isim, 0, nullptr);//store number of reco hits in place of track chi2; fill hits later + if (trkIdx>=0) { + int seedIdx = trk_seedIdx->at(trkIdx); + if (see_pixelIdx->at(seedIdx).size()!=0) { + seedSimIdx[seedIdx] = simTracks_.size(); + } + } + simTrackIdx_[isim] = simTracks_.size(); + simTracks_.push_back(track); + } + + if (simTracks_.size()==0) continue; + //if (simTracks_.size()<2) continue; + + vector seedTracks_; + vector > pixHitSeedIdx(pix_lay->size()); + for (int is = 0; issize(); ++is) { + if (see_algo->at(is)!=4) continue;//select seed in acceptance + //if (see_pt->at(is)<0.5 || fabs(see_eta->at(is))>0.8) continue;//select seed in acceptance + SVector3 pos = SVector3(see_x->at(is),see_y->at(is),see_z->at(is)); + SVector3 mom = SVector3(see_px->at(is),see_py->at(is),see_pz->at(is)); + SMatrixSym66 err; + err.At(0,0) = see_cov00->at(is); + err.At(0,1) = see_cov01->at(is); + err.At(0,2) = see_cov02->at(is); + err.At(0,3) = see_cov03->at(is); + err.At(0,4) = see_cov04->at(is); + err.At(0,5) = see_cov05->at(is); + err.At(1,1) = see_cov11->at(is); + err.At(1,2) = see_cov12->at(is); + err.At(1,3) = see_cov13->at(is); + err.At(1,4) = see_cov14->at(is); + err.At(1,5) = see_cov15->at(is); + err.At(2,2) = see_cov22->at(is); + err.At(2,3) = see_cov23->at(is); + err.At(2,4) = see_cov24->at(is); + err.At(2,5) = see_cov25->at(is); + err.At(3,3) = see_cov33->at(is); + err.At(3,4) = see_cov34->at(is); + err.At(3,5) = see_cov35->at(is); + err.At(4,4) = see_cov44->at(is); + err.At(4,5) = see_cov45->at(is); + err.At(5,5) = see_cov55->at(is); + TrackState state(see_q->at(is), pos, mom, err); +#ifdef CCSCOORD + //begin test CCS coordinates + state.convertFromCartesianToCCS(); + //end test CCS coordinates +#endif + Track track(state, 0, seedSimIdx[is], 0, nullptr); + if (see_pixelIdx->at(is).size()!=3) continue;//only seeds with 3 pixel hits + for (int ip=0; ipat(is).size(); ip++) { + unsigned int ipix = see_pixelIdx->at(is)[ip]; + //cout << "ipix=" << ipix << " seed=" << seedTracks_.size() << endl; + pixHitSeedIdx[ipix].push_back(seedTracks_.size()); + } + seedTracks_.push_back(track); + } + + if (seedTracks_.size()==0) continue; + + vector > layerHits_; + vector simHitsInfo_; + int totHits = 0; + layerHits_.resize(Config::nTotalLayers); + for (int ipix = 0; ipix < pix_lay->size(); ++ipix) { + int ilay = -1; + if (doEndcap) { + if (pix_isBarrel->at(ipix)==1) continue; + ilay = lnc.convertDiskNumber((pix_isBarrel->at(ipix)?1:2),pix_lay->at(ipix),useMatched,-1); + } else { + if (pix_isBarrel->at(ipix)==0) continue; + ilay = lnc.convertLayerNumber((pix_isBarrel->at(ipix)?1:2),pix_lay->at(ipix),useMatched,-1); + } + if (ilay<0) continue; + int simTkIdx = -1; + if (pix_simTrkIdx->at(ipix)>=0) simTkIdx = simTrackIdx_[pix_simTrkIdx->at(ipix)]; + //cout << Form("pix lay=%i bar=%i x=(%6.3f, %6.3f, %6.3f)",ilay+1,pix_isBarrel->at(ipix),pix_x->at(ipix),pix_y->at(ipix),pix_z->at(ipix)) << endl; + SVector3 pos(pix_x->at(ipix),pix_y->at(ipix),pix_z->at(ipix)); + SMatrixSym33 err; + err.At(0,0) = pix_xx->at(ipix); + err.At(1,1) = pix_yy->at(ipix); + err.At(2,2) = pix_zz->at(ipix); + err.At(0,1) = pix_xy->at(ipix); + err.At(0,2) = pix_zx->at(ipix); + err.At(1,2) = pix_yz->at(ipix); + if (simTkIdx>=0) simTracks_[simTkIdx].setHitIdx(ilay, layerHits_[ilay].size()); + for (int is=0;isat(glu_monoIdx->at(iglu)) << " " << str_process->at(glu_monoIdx->at(iglu)) << " " << str_simTrkIdx->at(glu_stereoIdx->at(iglu)) << " " << str_process->at(glu_stereoIdx->at(iglu)) << endl; + // cout << Form("glu lay=%i det=%i bar=%i x=(%6.3f, %6.3f, %6.3f)",ilay+1,glu_det->at(iglu),glu_isBarrel->at(iglu),glu_x->at(iglu),glu_y->at(iglu),glu_z->at(iglu)) << endl; + SVector3 pos(glu_x->at(iglu),glu_y->at(iglu),glu_z->at(iglu)); + SMatrixSym33 err; + err.At(0,0) = glu_xx->at(iglu); + err.At(1,1) = glu_yy->at(iglu); + err.At(2,2) = glu_zz->at(iglu); + err.At(0,1) = glu_xy->at(iglu); + err.At(0,2) = glu_zx->at(iglu); + err.At(1,2) = glu_yz->at(iglu); + if (simTkIdx>=0) simTracks_[simTkIdx].setHitIdx(ilay, layerHits_[ilay].size()); + Hit hit(pos, err, totHits); + layerHits_[ilay].push_back(hit); + MCHitInfo hitInfo(simTkIdx, ilay, layerHits_[ilay].size()-1, totHits); + simHitsInfo_.push_back(hitInfo); + totHits++; + } + } + + vector strIdx; + strIdx.resize(str_lay->size()); + for (int istr = 0; istr < str_lay->size(); ++istr) { + int ilay = -1; + if (doEndcap) { + if (str_isBarrel->at(istr)==1) continue; + ilay = lnc.convertDiskNumber(str_det->at(istr),str_lay->at(istr),useMatched,str_isStereo->at(istr)); + } else { + if (str_isBarrel->at(istr)==0) continue; + ilay = lnc.convertLayerNumber(str_det->at(istr),str_lay->at(istr),useMatched,str_isStereo->at(istr)); + if (useMatched && str_isStereo->at(istr)) continue; + } + if (ilay==-1 || ilay>=Config::nTotalLayers) continue; + int simTkIdx = -1; + if (str_simTrkIdx->at(istr)>=0) simTkIdx = simTrackIdx_[str_simTrkIdx->at(istr)]; + //if (str_onTrack->at(istr)==0) continue;//do not consider hits that are not on track! + //cout << Form("str lay=%i istr=%i tridx=%i bar=%i x=(%6.3f, %6.3f, %6.3f) r=%6.3f proc=%i part=%i onTrk=%i isStereo=%i",ilay+1,istr,str_simTrkIdx->at(istr),str_isBarrel->at(istr),str_x->at(istr),str_y->at(istr),str_z->at(istr),sqrt(pow(str_x->at(istr),2)+pow(str_y->at(istr),2)),str_process->at(istr),str_particle->at(istr),str_onTrack->at(istr),str_isStereo->at(istr)) << endl; + SVector3 pos(str_x->at(istr),str_y->at(istr),str_z->at(istr)); + SMatrixSym33 err; + err.At(0,0) = str_xx->at(istr); + err.At(1,1) = str_yy->at(istr); + err.At(2,2) = str_zz->at(istr); + err.At(0,1) = str_xy->at(istr); + err.At(0,2) = str_zx->at(istr); + err.At(1,2) = str_yz->at(istr); + if (simTkIdx>=0) simTracks_[simTkIdx].setHitIdx(ilay, layerHits_[ilay].size()); + Hit hit(pos, err, totHits); + layerHits_[ilay].push_back(hit); + MCHitInfo hitInfo(simTkIdx, ilay, layerHits_[ilay].size()-1, totHits); + simHitsInfo_.push_back(hitInfo); + totHits++; + } + + // bool allTracksAllHits = true; + for (int i=0;i Date: Tue, 2 May 2017 17:00:49 -0700 Subject: [PATCH 027/172] complete layer numbering --- tkNtuple/WriteMemoryFile.cc | 217 ++++++++++++++++++------------------ 1 file changed, 109 insertions(+), 108 deletions(-) diff --git a/tkNtuple/WriteMemoryFile.cc b/tkNtuple/WriteMemoryFile.cc index a9fe066fe2304..b2a0c0b9d3abf 100644 --- a/tkNtuple/WriteMemoryFile.cc +++ b/tkNtuple/WriteMemoryFile.cc @@ -2,103 +2,127 @@ #include "TFile.h" #include "TTree.h" -struct LayerNumberConverter { +enum struct TkLayout {phase0 = 0, phase1 = 1}; + +class LayerNumberConverter { public: - LayerNumberConverter() {} - int convertLayerNumber(int cmsswdet, int cmsswlay, bool useMatched, int isStereo) { - if (cmsswdet==2 || cmsswdet==4 || cmsswdet==6) return -1; - if (cmsswdet==1) return cmsswlay-1; + LayerNumberConverter(TkLayout layout) : lo_(layout) {} + unsigned int nLayers() const { + if (lo_ == TkLayout::phase0) return 69; + if (lo_ == TkLayout::phase1) return 72; + return 10; + } + int convertLayerNumber(int det, int lay, bool useMatched, int isStereo, bool posZ) const { + if (det == 1 || det == 3 || det == 5){ + return convertBarrelLayerNumber(det, lay, useMatched, isStereo); + } else { + int disk = convertDiskNumber(det, lay, useMatched, isStereo); + if (disk < 0) return -1; + + int lOffset = 0; + if (lo_ == TkLayout::phase1) lOffset = 1; + disk += 17+lOffset; + if (! posZ) disk += 25+2*lOffset; + } + return -1; + } + + int convertBarrelLayerNumber(int cmsswdet, int cmsswlay, bool useMatched, int isStereo) const { + int lOffset = 0; + if (lo_ == TkLayout::phase1) lOffset = 1; + if (cmsswdet==2 || cmsswdet==4 || cmsswdet==6) return -1;//FPIX, TID, TEC + if (cmsswdet==1) return cmsswlay-1;//BPIX if (useMatched) { - if (cmsswdet==3 && cmsswlay==1 && isStereo==-1) return 3; - if (cmsswdet==3 && cmsswlay==2 && isStereo==-1) return 4; - if (cmsswdet==3 && cmsswlay==3 && isStereo==0 ) return 5; - if (cmsswdet==3 && cmsswlay==4 && isStereo==0 ) return 6; - if (cmsswdet==5 && cmsswlay==1 && isStereo==-1) return 7; - if (cmsswdet==5 && cmsswlay==2 && isStereo==-1) return 8; - if (cmsswdet==5 && cmsswlay==3 && isStereo==0 ) return 9; - if (cmsswdet==5 && cmsswlay==4 && isStereo==0 ) return 10; - if (cmsswdet==5 && cmsswlay==5 && isStereo==0 ) return 11; - if (cmsswdet==5 && cmsswlay==6 && isStereo==0 ) return 12; + //TIB + if (cmsswdet==3 && cmsswlay==1 && isStereo==-1) return 3+lOffset; + if (cmsswdet==3 && cmsswlay==2 && isStereo==-1) return 4+lOffset; + if (cmsswdet==3 && cmsswlay==3 && isStereo==0 ) return 5+lOffset; + if (cmsswdet==3 && cmsswlay==4 && isStereo==0 ) return 6+lOffset; + //TOB + if (cmsswdet==5 && cmsswlay==1 && isStereo==-1) return 7+lOffset; + if (cmsswdet==5 && cmsswlay==2 && isStereo==-1) return 8+lOffset; + if (cmsswdet==5 && cmsswlay==3 && isStereo==0 ) return 9+lOffset; + if (cmsswdet==5 && cmsswlay==4 && isStereo==0 ) return 10+lOffset; + if (cmsswdet==5 && cmsswlay==5 && isStereo==0 ) return 11+lOffset; + if (cmsswdet==5 && cmsswlay==6 && isStereo==0 ) return 12+lOffset; return -1; } else { - if (cmsswdet==3 && cmsswlay==1 && isStereo==0) return 3; - if (cmsswdet==3 && cmsswlay==1 && isStereo==1) return 4; - if (cmsswdet==3 && cmsswlay==2 && isStereo==0) return 5; - if (cmsswdet==3 && cmsswlay==2 && isStereo==1) return 6; - if (cmsswdet==3 && cmsswlay==3 && isStereo==0) return 7; - if (cmsswdet==3 && cmsswlay==4 && isStereo==0) return 8; - if (cmsswdet==5 && cmsswlay==1 && isStereo==1) return 9; - if (cmsswdet==5 && cmsswlay==1 && isStereo==0) return 10; - if (cmsswdet==5 && cmsswlay==2 && isStereo==1) return 11; - if (cmsswdet==5 && cmsswlay==2 && isStereo==0) return 12; - if (cmsswdet==5 && cmsswlay==3 && isStereo==0) return 13; - if (cmsswdet==5 && cmsswlay==4 && isStereo==0) return 14; - if (cmsswdet==5 && cmsswlay==5 && isStereo==0) return 15; - if (cmsswdet==5 && cmsswlay==6 && isStereo==0) return 16; + //TIB + if (cmsswdet==3 && cmsswlay==1 && isStereo==0) return 3+lOffset; + if (cmsswdet==3 && cmsswlay==1 && isStereo==1) return 4+lOffset; + if (cmsswdet==3 && cmsswlay==2 && isStereo==0) return 5+lOffset; + if (cmsswdet==3 && cmsswlay==2 && isStereo==1) return 6+lOffset; + if (cmsswdet==3 && cmsswlay==3 && isStereo==0) return 7+lOffset; + if (cmsswdet==3 && cmsswlay==4 && isStereo==0) return 8+lOffset; + //TOB + if (cmsswdet==5 && cmsswlay==1 && isStereo==1) return 9+lOffset; + if (cmsswdet==5 && cmsswlay==1 && isStereo==0) return 10+lOffset; + if (cmsswdet==5 && cmsswlay==2 && isStereo==1) return 11+lOffset; + if (cmsswdet==5 && cmsswlay==2 && isStereo==0) return 12+lOffset; + if (cmsswdet==5 && cmsswlay==3 && isStereo==0) return 13+lOffset; + if (cmsswdet==5 && cmsswlay==4 && isStereo==0) return 14+lOffset; + if (cmsswdet==5 && cmsswlay==5 && isStereo==0) return 15+lOffset; + if (cmsswdet==5 && cmsswlay==6 && isStereo==0) return 16+lOffset; return -1; } } - int convertDiskNumber(int cmsswdet, int cmsswdisk, bool useMatched, int isStereo) { - if (cmsswdet==1 || cmsswdet==3 || cmsswdet==5) return -1; - if (cmsswdet==2) return cmsswdisk-1; + int convertDiskNumber(int cmsswdet, int cmsswdisk, bool useMatched, int isStereo) const { + if (cmsswdet==1 || cmsswdet==3 || cmsswdet==5) return -1;//BPIX, TIB, TOB + if (cmsswdet==2) return cmsswdisk-1;//FPIX + int lOffset = 0; + if (lo_ == TkLayout::phase1) lOffset = 1; if (useMatched) { return -1; } else { - if (cmsswdet==4 && cmsswdisk==1 && isStereo==0) return 2; - if (cmsswdet==4 && cmsswdisk==1 && isStereo==1) return 3; - if (cmsswdet==4 && cmsswdisk==2 && isStereo==0) return 4; - if (cmsswdet==4 && cmsswdisk==2 && isStereo==1) return 5; - if (cmsswdet==4 && cmsswdisk==3 && isStereo==0) return 6; - if (cmsswdet==4 && cmsswdisk==3 && isStereo==1) return 7; - if (cmsswdet==6 && cmsswdisk==1 && isStereo==1) return 8; - if (cmsswdet==6 && cmsswdisk==1 && isStereo==0) return 9; - if (cmsswdet==6 && cmsswdisk==2 && isStereo==1) return 10; - if (cmsswdet==6 && cmsswdisk==2 && isStereo==0) return 11; - if (cmsswdet==6 && cmsswdisk==3 && isStereo==1) return 12; - if (cmsswdet==6 && cmsswdisk==3 && isStereo==0) return 13; - if (cmsswdet==6 && cmsswdisk==4 && isStereo==1) return 14; - if (cmsswdet==6 && cmsswdisk==4 && isStereo==0) return 15; - if (cmsswdet==6 && cmsswdisk==5 && isStereo==1) return 16; - if (cmsswdet==6 && cmsswdisk==5 && isStereo==0) return 17; - if (cmsswdet==6 && cmsswdisk==6 && isStereo==1) return 18; - if (cmsswdet==6 && cmsswdisk==6 && isStereo==0) return 19; - if (cmsswdet==6 && cmsswdisk==7 && isStereo==1) return 20; - if (cmsswdet==6 && cmsswdisk==7 && isStereo==0) return 21; - if (cmsswdet==6 && cmsswdisk==8 && isStereo==1) return 22; - if (cmsswdet==6 && cmsswdisk==8 && isStereo==0) return 23; - if (cmsswdet==6 && cmsswdisk==9 && isStereo==1) return 24; - if (cmsswdet==6 && cmsswdisk==9 && isStereo==0) return 25; + //TID + if (cmsswdet==4 && cmsswdisk==1 && isStereo==0) return 2+lOffset; + if (cmsswdet==4 && cmsswdisk==1 && isStereo==1) return 3+lOffset; + if (cmsswdet==4 && cmsswdisk==2 && isStereo==0) return 4+lOffset; + if (cmsswdet==4 && cmsswdisk==2 && isStereo==1) return 5+lOffset; + if (cmsswdet==4 && cmsswdisk==3 && isStereo==0) return 6+lOffset; + if (cmsswdet==4 && cmsswdisk==3 && isStereo==1) return 7+lOffset; + //TEC + if (cmsswdet==6 && cmsswdisk==1 && isStereo==1) return 8+lOffset; + if (cmsswdet==6 && cmsswdisk==1 && isStereo==0) return 9+lOffset; + if (cmsswdet==6 && cmsswdisk==2 && isStereo==1) return 10+lOffset; + if (cmsswdet==6 && cmsswdisk==2 && isStereo==0) return 11+lOffset; + if (cmsswdet==6 && cmsswdisk==3 && isStereo==1) return 12+lOffset; + if (cmsswdet==6 && cmsswdisk==3 && isStereo==0) return 13+lOffset; + if (cmsswdet==6 && cmsswdisk==4 && isStereo==1) return 14+lOffset; + if (cmsswdet==6 && cmsswdisk==4 && isStereo==0) return 15+lOffset; + if (cmsswdet==6 && cmsswdisk==5 && isStereo==1) return 16+lOffset; + if (cmsswdet==6 && cmsswdisk==5 && isStereo==0) return 17+lOffset; + if (cmsswdet==6 && cmsswdisk==6 && isStereo==1) return 18+lOffset; + if (cmsswdet==6 && cmsswdisk==6 && isStereo==0) return 19+lOffset; + if (cmsswdet==6 && cmsswdisk==7 && isStereo==1) return 20+lOffset; + if (cmsswdet==6 && cmsswdisk==7 && isStereo==0) return 21+lOffset; + if (cmsswdet==6 && cmsswdisk==8 && isStereo==1) return 22+lOffset; + if (cmsswdet==6 && cmsswdisk==8 && isStereo==0) return 23+lOffset; + if (cmsswdet==6 && cmsswdisk==9 && isStereo==1) return 24+lOffset; + if (cmsswdet==6 && cmsswdisk==9 && isStereo==0) return 25+lOffset; return -1; } } + TkLayout lo_; }; bool useMatched = false; -bool doEndcap = true;//otherwise do barrel, both at the same time not supported for now int main() { using namespace std; - LayerNumberConverter lnc; + LayerNumberConverter lnc(TkLayout::phase1); + const unsigned int nTotalLayers = lnc.nLayers(); long long maxevt = 0; int nstot = 0; - int nhitstot[Config::nTotalLayers]; - std::fill_n(nhitstot, Config::nTotalLayers, 0); + std::vector nhitstot(nTotalLayers, 0); TString outfilename = ""; - // TFile* f = TFile::Open("./ntuple_test_1GeV_10k_split.root"); maxevt = 3000;outfilename = "cmssw_3kxSingleMu1GeV_split_endcap.bin"; - TFile* f = TFile::Open("./ntuple_test_10GeV_10k_split.root"); maxevt = 3000;outfilename = "cmssw_3kxSingleMu10GeV_split_endcap.bin"; - //TFile* f = TFile::Open("./ntuple_test_1GeV_10k.root"); - // TFile* f = TFile::Open(useMatched ? "./ntuple_test_1GeV_10k_noSplit_mock_noFWD.root" : "./ntuple_test_1GeV_10k_split_mock_noFWD.root");maxevt = 3000;outfilename = (useMatched ? "cmssw_3kxSingleMu1GeV_polar_noSplit_mock_noFWD.bin" : "cmssw_3kxSingleMu1GeV_polar_split_mock_noFWD.bin"); - // TFile* f = TFile::Open(useMatched ? "./ntuple_test_10GeV_10k_noSplit_mock_noFWD.root" : "./ntuple_test_10GeV_10k_split_mock_noFWD.root");maxevt = 3000;outfilename = (useMatched ? "cmssw_3kxSingleMu10GeV_polar_noSplit_mock_noFWD.bin" : "cmssw_3kxSingleMu10GeV_polar_split_mock_noFWD.bin"); - // TFile* f = TFile::Open("./ntuple_test_ZTT_split_mock_noFWD.root");assert(useMatched==false);maxevt = 500;outfilename = "cmssw_500xZTT_polar_split_mock_noFWD.bin"; - // TFile* f = TFile::Open("./ntuple_test_TTbar_split_mock_noFWD.root");assert(useMatched==false);maxevt = 500;outfilename = "cmssw_500xTTbar_polar_split_mock_noFWD.bin"; - // TFile* f = TFile::Open("./ntuple_test_TTbarPU10_split_mock_noFWD.root");assert(useMatched==false);maxevt = 100;outfilename = "cmssw_100xTTbarPU10_polar_split_mock_noFWD.bin"; - // TFile* f = TFile::Open("./ntuple_test_TTbarPU35_split_mock_noFWD.root");assert(useMatched==false);maxevt = 100;outfilename = "cmssw_100xTTbarPU35_polar_split_mock_noFWD.bin"; + TFile* f = TFile::Open("./ntuple_input.root"); maxevt = 3000;outfilename = "cmssw_output.bin"; TTree* t = (TTree*) f->Get("trkTree/tree"); @@ -348,40 +372,29 @@ int main() { //if (trkIdx<0) continue; int nlay = 0; - int hitlay[Config::nTotalLayers]; - std::fill_n(hitlay, Config::nTotalLayers, 0); + std::vector hitlay(nTotalLayers, 0); if (trkIdx>=0) { for (int ihit = 0; ihit < trk_pixelIdx->at(trkIdx).size(); ++ihit) { int ipix = trk_pixelIdx->at(trkIdx).at(ihit); if (ipix<0) continue; - if (doEndcap) { - int cmsswdisk = lnc.convertDiskNumber((pix_isBarrel->at(ipix)?1:2),pix_lay->at(ipix),useMatched,-1); - if (cmsswdisk>=0 && cmsswdiskat(ipix)?1:2),pix_lay->at(ipix),useMatched,-1); - if (cmsswlay>=0 && cmsswlayat(ipix)?1:2),pix_lay->at(ipix),useMatched,-1,pix_z->at(ipix)>0); + if (cmsswlay>=0 && cmsswlayat(trkIdx).size(); ++ihit) { int iglu = trk_gluedIdx->at(trkIdx).at(ihit); if (iglu<0) continue; - int cmsswlay = lnc.convertLayerNumber(glu_det->at(iglu),glu_lay->at(iglu),useMatched,-1); - if (cmsswlay>=0 && cmsswlayat(iglu),glu_lay->at(iglu),useMatched,-1,glu_z->at(iglu)>0); + if (cmsswlay>=0 && cmsswlayat(trkIdx).size(); ++ihit) { int istr = trk_stripIdx->at(trkIdx).at(ihit); if (istr<0) continue; - if (doEndcap) { - int cmsswdisk = lnc.convertDiskNumber(str_det->at(istr),str_lay->at(istr),useMatched,str_isStereo->at(istr)); - if (cmsswdisk>=0 && cmsswdiskat(istr),str_lay->at(istr),useMatched,str_isStereo->at(istr)); - if (cmsswlay>=0 && cmsswlayat(istr),str_lay->at(istr),useMatched,str_isStereo->at(istr),str_z->at(istr)>0); + if (cmsswlay>=0 && cmsswlay0) nlay++; + for (int i=0;i0) nlay++; } //cout << Form("track q=%2i p=(%6.3f, %6.3f, %6.3f) x=(%6.3f, %6.3f, %6.3f) nlay=%i",sim_q->at(isim),sim_px->at(isim),sim_py->at(isim),sim_pz->at(isim),sim_prodx->at(isim),sim_prody->at(isim),sim_prodz->at(isim),nlay) << endl; @@ -465,16 +478,10 @@ int main() { vector > layerHits_; vector simHitsInfo_; int totHits = 0; - layerHits_.resize(Config::nTotalLayers); + layerHits_.resize(nTotalLayers); for (int ipix = 0; ipix < pix_lay->size(); ++ipix) { int ilay = -1; - if (doEndcap) { - if (pix_isBarrel->at(ipix)==1) continue; - ilay = lnc.convertDiskNumber((pix_isBarrel->at(ipix)?1:2),pix_lay->at(ipix),useMatched,-1); - } else { - if (pix_isBarrel->at(ipix)==0) continue; - ilay = lnc.convertLayerNumber((pix_isBarrel->at(ipix)?1:2),pix_lay->at(ipix),useMatched,-1); - } + ilay = lnc.convertLayerNumber((pix_isBarrel->at(ipix)?1:2),pix_lay->at(ipix),useMatched,-1,pix_z->at(ipix)>0); if (ilay<0) continue; int simTkIdx = -1; if (pix_simTrkIdx->at(ipix)>=0) simTkIdx = simTrackIdx_[pix_simTrkIdx->at(ipix)]; @@ -504,7 +511,7 @@ int main() { if (glu_isBarrel->at(iglu)==0) continue; int simTkIdx = -1; if (str_simTrkIdx->at(glu_monoIdx->at(iglu))>=0 /*|| str_simTrkIdx->at(glu_stereoIdx->at(iglu))>=0*/) simTkIdx = simTrackIdx_[str_simTrkIdx->at(glu_monoIdx->at(iglu))]; - int ilay = lnc.convertLayerNumber(glu_det->at(iglu),glu_lay->at(iglu),useMatched,-1); + int ilay = lnc.convertLayerNumber(glu_det->at(iglu),glu_lay->at(iglu),useMatched,-1,glu_z->at(iglu)>0); //cout << ilay << " " << str_simTrkIdx->at(glu_monoIdx->at(iglu)) << " " << str_process->at(glu_monoIdx->at(iglu)) << " " << str_simTrkIdx->at(glu_stereoIdx->at(iglu)) << " " << str_process->at(glu_stereoIdx->at(iglu)) << endl; // cout << Form("glu lay=%i det=%i bar=%i x=(%6.3f, %6.3f, %6.3f)",ilay+1,glu_det->at(iglu),glu_isBarrel->at(iglu),glu_x->at(iglu),glu_y->at(iglu),glu_z->at(iglu)) << endl; SVector3 pos(glu_x->at(iglu),glu_y->at(iglu),glu_z->at(iglu)); @@ -528,15 +535,9 @@ int main() { strIdx.resize(str_lay->size()); for (int istr = 0; istr < str_lay->size(); ++istr) { int ilay = -1; - if (doEndcap) { - if (str_isBarrel->at(istr)==1) continue; - ilay = lnc.convertDiskNumber(str_det->at(istr),str_lay->at(istr),useMatched,str_isStereo->at(istr)); - } else { - if (str_isBarrel->at(istr)==0) continue; - ilay = lnc.convertLayerNumber(str_det->at(istr),str_lay->at(istr),useMatched,str_isStereo->at(istr)); - if (useMatched && str_isStereo->at(istr)) continue; - } - if (ilay==-1 || ilay>=Config::nTotalLayers) continue; + ilay = lnc.convertLayerNumber(str_det->at(istr),str_lay->at(istr),useMatched,str_isStereo->at(istr),str_z->at(istr)>0); + if (useMatched && str_isBarrel->at(istr)==1 && str_isStereo->at(istr)) continue; + if (ilay==-1) continue; int simTkIdx = -1; if (str_simTrkIdx->at(istr)>=0) simTkIdx = simTrackIdx_[str_simTrkIdx->at(istr)]; //if (str_onTrack->at(istr)==0) continue;//do not consider hits that are not on track! @@ -598,7 +599,7 @@ int main() { for (int i=0;i Date: Wed, 3 May 2017 06:11:03 -0700 Subject: [PATCH 028/172] Update Validation with more options for efficiency/fakerates + more branches to validation --- Config.cc | 13 +- Config.h | 3 + Event.cc | 2 +- PlotValidation.cpp | 308 ++++++++++++++++++++++++++++++--------------- TTreeValidation.cc | 270 ++++++++++++++++++++++++++++++--------- TTreeValidation.h | 15 ++- Track.cc | 128 ++++++++++++++----- Track.h | 8 +- main.cc | 8 +- mkFit/MkBuilder.cc | 10 +- mkFit/mkFit.cc | 7 ++ 11 files changed, 564 insertions(+), 208 deletions(-) diff --git a/Config.cc b/Config.cc index d3b85f4764ccc..f2a782bd7856d 100644 --- a/Config.cc +++ b/Config.cc @@ -41,16 +41,17 @@ namespace Config bool useCMSGeom = false; bool readCmsswSeeds = false; - bool findSeeds = false; + bool findSeeds = false; bool endcapTest = false; - bool silent = false; + bool silent = false; - bool cf_seeding = false; - bool cf_fitting = false; + bool cf_seeding = false; + bool cf_fitting = false; - bool root_val = false; - bool fit_val = false; + bool root_val = false; + bool fit_val = false; + bool shortFakes = false; void RecalculateDependentConstants() { diff --git a/Config.h b/Config.h index 36f527c15705b..14aa2eb570958 100644 --- a/Config.h +++ b/Config.h @@ -241,8 +241,11 @@ namespace Config extern int maxCandsPerEtaBin; // config on validation + constexpr float nMinSimHitsFrac = 0.7; + constexpr int nMinFoundHits = 7; extern bool root_val; extern bool fit_val; + extern bool shortFakes; // Effective eta bin is one half of nEtaPart -- so the above is twice the "average". // Note that last and first bin are 3/4 nEtaPart ... but can be made 1/4 by adding diff --git a/Event.cc b/Event.cc index 5f3d9ff5d287f..7cec629cefd9f 100644 --- a/Event.cc +++ b/Event.cc @@ -332,7 +332,7 @@ void Event::PrintStats(const TrackVec& trks, TrackExtraVec& trkextras) for (auto&& trk : trks) { auto&& extra = trkextras[trk.label()]; - extra.setMCTrackIDInfo(trk, layerHits_, simHitsInfo_); + extra.setMCTrackIDInfoByLabel(trk, layerHits_, simHitsInfo_, simTracks_[trk.label()]); if (extra.mcTrackID() < 0) { ++miss; } else { diff --git a/PlotValidation.cpp b/PlotValidation.cpp index a0ff5c6fad729..645936d21422f 100644 --- a/PlotValidation.cpp +++ b/PlotValidation.cpp @@ -53,14 +53,16 @@ PlotValidation::PlotValidation(TString inName, TString outName, fColorSize = fColors.size(); } -PlotValidation::~PlotValidation(){ +PlotValidation::~PlotValidation() +{ delete fInRoot; delete fOutRoot; // will delete all pointers to subdirectory delete fTH1Canv; delete fTH2Canv; } -void PlotValidation::Validation(){ +void PlotValidation::Validation() +{ PlotValidation::PlotEfficiency(); PlotValidation::PlotFakeRate(); PlotValidation::PlotDuplicateRate(); @@ -69,12 +71,14 @@ void PlotValidation::Validation(){ PlotValidation::PrintTotals(); - if (fMvInput) { + if (fMvInput) + { PlotValidation::MoveInput(); } } -void PlotValidation::PlotEfficiency(){ +void PlotValidation::PlotEfficiency() +{ // Get tree TTree * efftree = (TTree*)fInRoot->Get("efftree"); @@ -106,14 +110,17 @@ void PlotValidation::PlotEfficiency(){ TH1FRefVecVec varsNumerPlot(vars.size()); TH1FRefVecVec varsDenomPlot(vars.size()); TH1FRefVecVec varsEffPlot(vars.size()); - for (UInt_t i = 0; i < vars.size(); i++){ + for (UInt_t i = 0; i < vars.size(); i++) + { varsNumerPlot[i].resize(trks.size()); varsDenomPlot[i].resize(trks.size()); varsEffPlot[i].resize(trks.size()); } - for (UInt_t i = 0; i < vars.size(); i++){ - for (UInt_t j = 0; j < trks.size(); j++){ + for (UInt_t i = 0; i < vars.size(); i++) + { + for (UInt_t j = 0; j < trks.size(); j++) + { // Numerator varsNumerPlot[i][j] = new TH1F(Form("h_sim_%s_numer_%s_EFF",vars[i].Data(),trks[j].Data()),Form("%s Track vs MC %s (Numer) Eff",strks[j].Data(),svars[i].Data()),nBins[i],xlow[i],xhigh[i]); varsNumerPlot[i][j]->GetXaxis()->SetTitle(Form("%s%s",svars[i].Data(),sunits[i].Data())); @@ -130,7 +137,8 @@ void PlotValidation::PlotEfficiency(){ } //Initialize var_val/err arrays, SetBranchAddress - for (UInt_t i = 0; i < vars.size(); i++){ // loop over trks index + for (UInt_t i = 0; i < vars.size(); i++) // loop over trks index + { // initialize var mcvars_val[i] = 0.; @@ -139,18 +147,23 @@ void PlotValidation::PlotEfficiency(){ } //Initialize masks, set branch addresses - for (UInt_t j = 0; j < trks.size(); j++){ // loop over trks index + for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index + { mcmask_trk[j] = 0; efftree->SetBranchAddress(Form("mcmask_%s",trks[j].Data()),&(mcmask_trk[j])); } // Fill histos, compute eff from tree branches - for (Int_t k = 0; k < efftree->GetEntries(); k++){ + for (Int_t k = 0; k < efftree->GetEntries(); k++) + { efftree->GetEntry(k); - for (UInt_t i = 0; i < vars.size(); i++){ // loop over vars index - for (UInt_t j = 0; j < trks.size(); j++){ // loop over trks index + for (UInt_t i = 0; i < vars.size(); i++) // loop over vars index + { + for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index + { varsDenomPlot[i][j]->Fill(mcvars_val[i]); - if (mcmask_trk[j] == 1){ // must be associated + if (mcmask_trk[j] == 1) // must be associated + { varsNumerPlot[i][j]->Fill(mcvars_val[i]); } // must be a matched track for efficiency } // end loop over trks @@ -158,8 +171,10 @@ void PlotValidation::PlotEfficiency(){ } // end loop over entry in tree // Draw, divide, and save efficiency plots - for (UInt_t i = 0; i < vars.size(); i++){ - for (UInt_t j = 0; j < trks.size(); j++){ + for (UInt_t i = 0; i < vars.size(); i++) + { + for (UInt_t j = 0; j < trks.size(); j++) + { PlotValidation::ComputeRatioPlot(varsNumerPlot[i][j],varsDenomPlot[i][j],varsEffPlot[i][j]); PlotValidation::WriteTH1FPlot(subdir,varsNumerPlot[i][j]); PlotValidation::WriteTH1FPlot(subdir,varsDenomPlot[i][j]); @@ -172,7 +187,8 @@ void PlotValidation::PlotEfficiency(){ delete efftree; } -void PlotValidation::PlotFakeRate(){ +void PlotValidation::PlotFakeRate() +{ // Get tree TTree * fakeratetree = (TTree*)fInRoot->Get("fakeratetree"); @@ -198,7 +214,8 @@ void PlotValidation::PlotFakeRate(){ // Floats/Ints to be filled for trees FltVecVec recovars_val(vars.size()); // first index is var, second is type of track - for (UInt_t i = 0; i < vars.size(); i++){ + for (UInt_t i = 0; i < vars.size(); i++) + { recovars_val[i].resize(trks.size()); } @@ -209,14 +226,17 @@ void PlotValidation::PlotFakeRate(){ TH1FRefVecVec varsNumerPlot(vars.size()); TH1FRefVecVec varsDenomPlot(vars.size()); TH1FRefVecVec varsFRPlot(vars.size()); - for (UInt_t i = 0; i < vars.size(); i++){ + for (UInt_t i = 0; i < vars.size(); i++) + { varsNumerPlot[i].resize(trks.size()); varsDenomPlot[i].resize(trks.size()); varsFRPlot[i].resize(trks.size()); } - for (UInt_t i = 0; i < vars.size(); i++){ - for (UInt_t j = 0; j < trks.size(); j++){ + for (UInt_t i = 0; i < vars.size(); i++) + { + for (UInt_t j = 0; j < trks.size(); j++) + { // Numerator varsNumerPlot[i][j] = new TH1F(Form("h_reco_%s_numer_%s_FR",vars[i].Data(),trks[j].Data()),Form("%s Track vs Reco %s (Numer) FR",strks[j].Data(),svars[i].Data()),nBins[i],xlow[i],xhigh[i]); varsNumerPlot[i][j]->GetXaxis()->SetTitle(Form("%s%s",svars[i].Data(),sunits[i].Data())); @@ -233,8 +253,10 @@ void PlotValidation::PlotFakeRate(){ } //Initialize var_val/err arrays, SetBranchAddress - for (UInt_t i = 0; i < vars.size(); i++){ // loop over vars index - for (UInt_t j = 0; j < trks.size(); j++){ // loop over trks index + for (UInt_t i = 0; i < vars.size(); i++) // loop over vars index + { + for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index + { // initialize var recovars_val[i][j] = 0.; @@ -244,7 +266,8 @@ void PlotValidation::PlotFakeRate(){ } //Initialize masks, set branch addresses - for (UInt_t j = 0; j < trks.size(); j++){ // loop over trks index + for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index + { mcmask_trk[j] = 0; seedmask_trk[j] = 0; @@ -253,13 +276,18 @@ void PlotValidation::PlotFakeRate(){ } // Fill histos, compute fake rate from tree branches - for (Int_t k = 0; k < fakeratetree->GetEntries(); k++){ + for (Int_t k = 0; k < fakeratetree->GetEntries(); k++) + { fakeratetree->GetEntry(k); - for (UInt_t i = 0; i < vars.size(); i++){ // loop over vars index - for (UInt_t j = 0; j < trks.size(); j++){ // loop over trks index - if (seedmask_trk[j] == 1) { // make sure it is actually a reco track matched to a seed + for (UInt_t i = 0; i < vars.size(); i++) // loop over vars index + { + for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index + { + if (mcmask_trk[j] != -1) + { varsDenomPlot[i][j]->Fill(recovars_val[i][j]); // all reco tracks fill denom - if (mcmask_trk[j] == 0){ // only completely unassociated reco tracks enter FR + if (mcmask_trk[j] == 0) // only completely unassociated reco tracks enter FR + { varsNumerPlot[i][j]->Fill(recovars_val[i][j]); } // must be an unmatched track for FR } // must be a real reco track for FR @@ -268,8 +296,10 @@ void PlotValidation::PlotFakeRate(){ } // end loop over entry in tree // Draw, divide, and save fake rate plots --> then delete! - for (UInt_t i = 0; i < vars.size(); i++){ - for (UInt_t j = 0; j < trks.size(); j++){ + for (UInt_t i = 0; i < vars.size(); i++) + { + for (UInt_t j = 0; j < trks.size(); j++) + { PlotValidation::ComputeRatioPlot(varsNumerPlot[i][j],varsDenomPlot[i][j],varsFRPlot[i][j]); PlotValidation::WriteTH1FPlot(subdir,varsNumerPlot[i][j]); PlotValidation::WriteTH1FPlot(subdir,varsDenomPlot[i][j]); @@ -315,14 +345,17 @@ void PlotValidation::PlotDuplicateRate(){ TH1FRefVecVec varsNumerPlot(vars.size()); TH1FRefVecVec varsDenomPlot(vars.size()); TH1FRefVecVec varsDRPlot(vars.size()); - for (UInt_t i = 0; i < vars.size(); i++){ + for (UInt_t i = 0; i < vars.size(); i++) + { varsNumerPlot[i].resize(trks.size()); varsDenomPlot[i].resize(trks.size()); varsDRPlot[i].resize(trks.size()); } - for (UInt_t i = 0; i < vars.size(); i++){ - for (UInt_t j = 0; j < trks.size(); j++){ + for (UInt_t i = 0; i < vars.size(); i++) + { + for (UInt_t j = 0; j < trks.size(); j++) + { // Numerator varsNumerPlot[i][j] = new TH1F(Form("h_sim_%s_numer_%s_DR",vars[i].Data(),trks[j].Data()),Form("%s Track vs MC %s (Numer) DR",strks[j].Data(),svars[i].Data()),nBins[i],xlow[i],xhigh[i]); varsNumerPlot[i][j]->GetXaxis()->SetTitle(Form("%s%s",svars[i].Data(),sunits[i].Data())); @@ -339,7 +372,8 @@ void PlotValidation::PlotDuplicateRate(){ } //Initialize var_val/err arrays, SetBranchAddress - for (UInt_t i = 0; i < vars.size(); i++){ // loop over trks index + for (UInt_t i = 0; i < vars.size(); i++) // loop over trks index + { // initialize var mcvars_val[i] = 0.; @@ -348,7 +382,8 @@ void PlotValidation::PlotDuplicateRate(){ } //Initialize masks, set branch addresses - for (UInt_t j = 0; j < trks.size(); j++){ // loop over trks index + for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index + { mcmask_trk[j] = 0; nTkMatches_trk[j] = 0; @@ -357,13 +392,18 @@ void PlotValidation::PlotDuplicateRate(){ } // Fill histos, compute DR from tree branches - for (Int_t k = 0; k < efftree->GetEntries(); k++){ + for (Int_t k = 0; k < efftree->GetEntries(); k++) + { efftree->GetEntry(k); - for (UInt_t i = 0; i < vars.size(); i++){ // loop over vars index - for (UInt_t j = 0; j < trks.size(); j++){ // loop over trks index - if (mcmask_trk[j] == 1) { + for (UInt_t i = 0; i < vars.size(); i++) // loop over vars index + { + for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index + { + if (mcmask_trk[j] == 1) + { varsDenomPlot[i][j]->Fill(mcvars_val[i]); - for (Int_t n = 0; n < nTkMatches_trk[j]; n++){ + for (Int_t n = 0; n < nTkMatches_trk[j]; n++) + { varsNumerPlot[i][j]->Fill(mcvars_val[i]); } // fill n times sim track is matched. filled once is one sim to one reco. filled twice is two reco to one sim } // must be a matched track for proper denom @@ -372,8 +412,10 @@ void PlotValidation::PlotDuplicateRate(){ } // end loop over entry in tree // Draw, divide, and save DR plots - for (UInt_t i = 0; i < vars.size(); i++){ - for (UInt_t j = 0; j < trks.size(); j++){ + for (UInt_t i = 0; i < vars.size(); i++) + { + for (UInt_t j = 0; j < trks.size(); j++) + { PlotValidation::ComputeRatioPlot(varsNumerPlot[i][j],varsDenomPlot[i][j],varsDRPlot[i][j],true); PlotValidation::WriteTH1FPlot(subdir,varsNumerPlot[i][j]); PlotValidation::WriteTH1FPlot(subdir,varsDenomPlot[i][j]); @@ -386,7 +428,8 @@ void PlotValidation::PlotDuplicateRate(){ delete efftree; } -void PlotValidation::PlotNHits(){ +void PlotValidation::PlotNHits() +{ // Get tree --> can do this all with fake rate tree TTree * fakeratetree = (TTree*)fInRoot->Get("fakeratetree"); @@ -417,13 +460,16 @@ void PlotValidation::PlotNHits(){ // Create plots TH1FRefVecVec nHitsPlot(trks.size()); TH1FRefVecVec fracHitsMatchedPlot(trks.size()); - for (UInt_t j = 0; j < trks.size(); j++){ + for (UInt_t j = 0; j < trks.size(); j++) + { nHitsPlot[j].resize(coll.size()); fracHitsMatchedPlot[j].resize(coll.size()); } - for (UInt_t j = 0; j < trks.size(); j++){ - for (UInt_t c = 0; c < coll.size(); c++){ + for (UInt_t j = 0; j < trks.size(); j++) + { + for (UInt_t c = 0; c < coll.size(); c++) + { // Numerator only type plots only! nHitsPlot[j][c] = new TH1F(Form("h_nHits_%s_%s",coll[c].Data(),trks[j].Data()),Form("%s %s Track vs nHits / Track",scoll[c].Data(),strks[j].Data()),30,0,30); nHitsPlot[j][c]->GetXaxis()->SetTitle("nHits / Track"); @@ -438,7 +484,8 @@ void PlotValidation::PlotNHits(){ } //Initialize masks and variables, set branch addresses - for (UInt_t j = 0; j < trks.size(); j++){ // loop over trks index + for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index + { mcmask_trk[j] = 0; seedmask_trk[j] = 0; iTkMatches_trk[j] = 0; @@ -453,30 +500,41 @@ void PlotValidation::PlotNHits(){ } // Fill histos, compute res/pull from tree branches - for (Int_t k = 0; k < fakeratetree->GetEntries(); k++){ + for (Int_t k = 0; k < fakeratetree->GetEntries(); k++) + { fakeratetree->GetEntry(k); - for (UInt_t j = 0; j < trks.size(); j++){ // loop over trks index - for (UInt_t c = 0; c < coll.size(); c++){ // loop over trk collection type - if (c == 0) { // all reco - if (seedmask_trk[j] == 1){ + for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index + { + for (UInt_t c = 0; c < coll.size(); c++) // loop over trk collection type + { + if (c == 0) // all reco + { + if (seedmask_trk[j] == 1) // includes all the short tracks, too + { nHitsPlot[j][c]->Fill(nHits_trk[j]); fracHitsMatchedPlot[j][c]->Fill(fracHitsMatched_trk[j]); } } - else if (c == 1) { // fake - if ((seedmask_trk[j] == 1) && (mcmask_trk[j] == 0)) { + else if (c == 1) // all fakes + { + if ((seedmask_trk[j] == 1) && (mcmask_trk[j] == 0)) + { nHitsPlot[j][c]->Fill(nHits_trk[j]); fracHitsMatchedPlot[j][c]->Fill(fracHitsMatched_trk[j]); } } - else if (c == 2) { // all matches - if ((seedmask_trk[j] == 1) && (mcmask_trk[j] == 1)) { + else if (c == 2) // all matches + { + if ((seedmask_trk[j] == 1) && (mcmask_trk[j] == 1)) + { nHitsPlot[j][c]->Fill(nHits_trk[j]); fracHitsMatchedPlot[j][c]->Fill(fracHitsMatched_trk[j]); } } - else if (c == 3) { // best matches only - if ((seedmask_trk[j] == 1) && (mcmask_trk[j] == 1) && (iTkMatches_trk[j] == 0)) { + else if (c == 3) // best matches only + { + if ((seedmask_trk[j] == 1) && (mcmask_trk[j] == 1) && (iTkMatches_trk[j] == 0)) + { nHitsPlot[j][c]->Fill(nHits_trk[j]); fracHitsMatchedPlot[j][c]->Fill(fracHitsMatched_trk[j]); } @@ -486,8 +544,10 @@ void PlotValidation::PlotNHits(){ } // end loop over entry in tree // Draw and save nHits plots - for (UInt_t j = 0; j < trks.size(); j++){ - for (UInt_t c = 0; c < coll.size(); c++){ // loop over trk collection type + for (UInt_t j = 0; j < trks.size(); j++) + { + for (UInt_t c = 0; c < coll.size(); c++) // loop over trk collection type + { PlotValidation::DrawWriteSaveTH1FPlot(subdir,nHitsPlot[j][c],subdirname,Form("nHits_%s_%s",coll[c].Data(),trks[j].Data()),zeroSupLin); PlotValidation::DrawWriteSaveTH1FPlot(subdir,fracHitsMatchedPlot[j][c],subdirname,Form("fracHitsMatched_%s_%s",coll[c].Data(),trks[j].Data()),zeroSupLin); @@ -499,7 +559,8 @@ void PlotValidation::PlotNHits(){ delete fakeratetree; } -void PlotValidation::PlotMomResolutionPull(){ +void PlotValidation::PlotMomResolutionPull() +{ // Get tree TTree * efftree = (TTree*)fInRoot->Get("efftree"); @@ -533,7 +594,8 @@ void PlotValidation::PlotMomResolutionPull(){ IntVec mcmask_trk(trks.size()); // need to know if sim track associated to a given reco track type FltVecVec recovars_val(vars.size()); // first index is nVars, second is nTrkTypes FltVecVec recovars_err(vars.size()); - for (UInt_t i = 0; i < vars.size(); i++){ + for (UInt_t i = 0; i < vars.size(); i++) + { mcvars_val[i].resize(trks.size()); recovars_val[i].resize(trks.size()); recovars_err[i].resize(trks.size()); @@ -543,13 +605,16 @@ void PlotValidation::PlotMomResolutionPull(){ // Create pos plots TH1FRefVecVec varsResPlot(vars.size()); TH1FRefVecVec varsPullPlot(vars.size()); - for (UInt_t i = 0; i < vars.size(); i++){ + for (UInt_t i = 0; i < vars.size(); i++) + { varsResPlot[i].resize(trks.size()); varsPullPlot[i].resize(trks.size()); } - for (UInt_t i = 0; i < vars.size(); i++){ - for (UInt_t j = 0; j < trks.size(); j++){ + for (UInt_t i = 0; i < vars.size(); i++) + { + for (UInt_t j = 0; j < trks.size(); j++) + { //Res varsResPlot[i][j] = new TH1F(Form("h_%s_res_%s",vars[i].Data(),trks[j].Data()),Form("%s Resolution (%s Track vs. MC Track)",svars[i].Data(),strks[j].Data()),nBinsRes[i],xlowRes[i],xhighRes[i]); varsResPlot[i][j]->GetXaxis()->SetTitle(Form("(%s^{%s}%s - %s^{mc}%s)/%s^{mc}%s",svars[i].Data(),strks[j].Data(),sunits[i].Data(),svars[i].Data(),sunits[i].Data(),svars[i].Data(),sunits[i].Data())); @@ -565,8 +630,10 @@ void PlotValidation::PlotMomResolutionPull(){ } //Initialize var_val/err arrays, SetBranchAddress - for (UInt_t i = 0; i < vars.size(); i++){ // loop over var index - for (UInt_t j = 0; j < trks.size(); j++){ // loop over trks index + for (UInt_t i = 0; i < vars.size(); i++) // loop over var index + { + for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index + { // initialize var + errors mcvars_val[i][j] = 0.; recovars_val[i][j] = 0.; @@ -580,22 +647,28 @@ void PlotValidation::PlotMomResolutionPull(){ } //Initialize masks, set branch addresses - for (UInt_t j = 0; j < trks.size(); j++){ // loop over trks index + for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index + { mcmask_trk[j] = 0; efftree->SetBranchAddress(Form("mcmask_%s",trks[j].Data()),&(mcmask_trk[j])); } // Fill histos, compute res/pull from tree branches - for (Int_t k = 0; k < efftree->GetEntries(); k++){ + for (Int_t k = 0; k < efftree->GetEntries(); k++) + { efftree->GetEntry(k); - for (UInt_t i = 0; i < vars.size(); i++){ // loop over vars index - for (UInt_t j = 0; j < trks.size(); j++){ // loop over trks index + for (UInt_t i = 0; i < vars.size(); i++) // loop over vars index + { + for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index + { if (mcmask_trk[j] == 1){ // must be associated PlotValidation::ComputeResolutionPull(mcvars_val[i][j],recovars_val[i][j],recovars_err[i][j],vars_out); - if (!isnan(vars_out[0])){ // fill if not nan + if (!isnan(vars_out[0])) // fill if not nan + { varsResPlot[i][j]->Fill(vars_out[0]); } - if (!isnan(vars_out[1])){ // fill if not nan + if (!isnan(vars_out[1])) // fill if not nan + { varsPullPlot[i][j]->Fill(vars_out[1]); } } // must be a matched track to make resolution plots @@ -604,8 +677,10 @@ void PlotValidation::PlotMomResolutionPull(){ } // end loop over entry in tree // Draw, fit, and save plots - for (UInt_t i = 0; i < vars.size(); i++){ - for (UInt_t j = 0; j < trks.size(); j++){ + for (UInt_t i = 0; i < vars.size(); i++) + { + for (UInt_t j = 0; j < trks.size(); j++) + { PlotValidation::DrawWriteFitSaveTH1FPlot(subdir,varsResPlot[i][j],subdirname,Form("%s_resolution_%s",vars[i].Data(),trks[j].Data()),gausRes[i]); PlotValidation::DrawWriteFitSaveTH1FPlot(subdir,varsPullPlot[i][j],subdirname,Form("%s_pull_%s",vars[i].Data(),trks[j].Data()),gausPull[i]); delete varsResPlot[i][j]; @@ -615,7 +690,8 @@ void PlotValidation::PlotMomResolutionPull(){ delete efftree; } -void PlotValidation::PrintTotals(){ +void PlotValidation::PrintTotals() +{ // want to print out totals of nHits, fraction of Hits shared, efficiency, fake rate, duplicate rate of seeds, build, fit // --> numer/denom plots for phi, know it will be in the bounds. @@ -630,13 +706,16 @@ void PlotValidation::PrintTotals(){ TH1FRefVecVec numerPhiPlot(trks.size()); TH1FRefVecVec denomPhiPlot(trks.size()); - for (UInt_t j = 0; j < trks.size(); j++) { + for (UInt_t j = 0; j < trks.size(); j++) + { numerPhiPlot[j].resize(rates.size()); denomPhiPlot[j].resize(rates.size()); } - for (UInt_t j = 0; j < trks.size(); j++) { - for (UInt_t r = 0; r < rates.size(); r++) { + for (UInt_t j = 0; j < trks.size(); j++) + { + for (UInt_t r = 0; r < rates.size(); r++) + { numerPhiPlot[j][r] = (TH1F*) fOutRoot->Get(Form("%s/h_%s_phi_numer_%s_%s",rateSD[r].Data(),types[r].Data(),trks[j].Data(),rates[r].Data())); denomPhiPlot[j][r] = (TH1F*) fOutRoot->Get(Form("%s/h_%s_phi_denom_%s_%s",rateSD[r].Data(),types[r].Data(),trks[j].Data(),rates[r].Data())); } @@ -648,13 +727,16 @@ void PlotValidation::PrintTotals(){ TH1FRefVecVec nHitsPlot(trks.size()); TH1FRefVecVec fracHitsMatchedPlot(trks.size()); - for (UInt_t j = 0; j < trks.size(); j++) { + for (UInt_t j = 0; j < trks.size(); j++) + { nHitsPlot[j].resize(coll.size()); fracHitsMatchedPlot[j].resize(coll.size()); } - for (UInt_t j = 0; j < trks.size(); j++) { - for (UInt_t c = 0; c < coll.size(); c++) { + for (UInt_t j = 0; j < trks.size(); j++) + { + for (UInt_t c = 0; c < coll.size(); c++) + { nHitsPlot[j][c] = (TH1F*) fOutRoot->Get(Form("nHits/h_nHits_%s_%s",coll[c].Data(),trks[j].Data())); fracHitsMatchedPlot[j][c] = (TH1F*) fOutRoot->Get(Form("nHits/h_fracHitsMatched_%s_%s",coll[c].Data(),trks[j].Data())); } @@ -683,7 +765,8 @@ void PlotValidation::PrintTotals(){ totalsout << "++++++++++++++++++++++++++++++++++++++++++++" << std::endl; totalsout << std::endl; - for (UInt_t j = 0; j < trks.size(); j++) { + for (UInt_t j = 0; j < trks.size(); j++) + { std::cout << strks[j].Data() << " Tracks" << std::endl; std::cout << "++++++++++++++++++++++++++++++++++++++++++" << std::endl << std::endl; std::cout << "Hit Totals for " << strks[j].Data() << " Track Collections" << std::endl; @@ -693,7 +776,8 @@ void PlotValidation::PrintTotals(){ totalsout << "++++++++++++++++++++++++++++++++++++++++++" << std::endl << std::endl; totalsout << "Hit Totals for " << strks[j].Data() << " Track Collections" << std::endl; totalsout << "==========================================" << std::endl; - for (UInt_t c = 0; c < coll.size(); c++) { + for (UInt_t c = 0; c < coll.size(); c++) + { Float_t nHits_mean = nHitsPlot[j][c]->GetMean(1); // 1 is mean of x-axis Float_t fracHits_mean = fracHitsMatchedPlot[j][c]->GetMean(1); @@ -711,7 +795,8 @@ void PlotValidation::PrintTotals(){ totalsout << std::endl << "Rates for " << strks[j].Data() << " Tracks" << std::endl; totalsout << "==========================================" << std::endl; - for (UInt_t r = 0; r < rates.size(); r++) { + for (UInt_t r = 0; r < rates.size(); r++) + { Int_t numerIntegral = numerPhiPlot[j][r]->Integral(0,numerPhiPlot[j][r]->GetNbinsX()+1); Int_t denomIntegral = denomPhiPlot[j][r]->Integral(0,denomPhiPlot[j][r]->GetNbinsX()+1); Float_t ratetotal = Float_t(numerIntegral) / Float_t(denomIntegral); @@ -738,7 +823,8 @@ void PlotValidation::PrintTotals(){ void PlotValidation::MakeSubDirectory(const TString subdirname){ FileStat_t dummyFileStat; - if (gSystem->GetPathInfo(Form("%s/%s",fOutName.Data(), subdirname.Data()), dummyFileStat) == 1){ + if (gSystem->GetPathInfo(Form("%s/%s",fOutName.Data(), subdirname.Data()), dummyFileStat) == 1) + { TString mkDir = "mkdir -p "; mkDir += fOutName.Data(); mkDir += "/"; @@ -747,39 +833,48 @@ void PlotValidation::MakeSubDirectory(const TString subdirname){ } } -void PlotValidation::ComputeResidual(const Float_t mcvar_val, const Float_t recovar_val, Float_t & var_out){ +void PlotValidation::ComputeResidual(const Float_t mcvar_val, const Float_t recovar_val, Float_t & var_out) +{ var_out = recovar_val - mcvar_val; } -void PlotValidation::ComputeResolutionPull(const Float_t mcvar_val, const Float_t recovar_val, const Float_t recovar_err, FltVec & var_out){ +void PlotValidation::ComputeResolutionPull(const Float_t mcvar_val, const Float_t recovar_val, const Float_t recovar_err, FltVec & var_out) +{ var_out[0] = (recovar_val - mcvar_val)/mcvar_val; var_out[1] = (recovar_val - mcvar_val)/recovar_err; } -void PlotValidation::ZeroSuppressPlot(TH1F *& hist){ +void PlotValidation::ZeroSuppressPlot(TH1F *& hist) +{ Float_t max = hist->GetBinContent(hist->GetMaximumBin()); Float_t min = 100; Bool_t newmin = false; - for (Int_t bin = 1; bin <= hist->GetNbinsX(); bin++){ + for (Int_t bin = 1; bin <= hist->GetNbinsX(); bin++) + { Float_t tmpmin = hist->GetBinContent(bin); - if ((tmpmin < min) && (tmpmin > 0)) { + if ((tmpmin < min) && (tmpmin > 0)) + { min = tmpmin; newmin = true; } } hist->SetMaximum(1.02*max); - if (newmin){ + if (newmin) + { hist->SetMinimum(0.98*min); } } -void PlotValidation::ComputeRatioPlot(const TH1F * numer, const TH1F * denom, TH1F *& ratioPlot, Bool_t subone){ +void PlotValidation::ComputeRatioPlot(const TH1F * numer, const TH1F * denom, TH1F *& ratioPlot, Bool_t subone) +{ Double_t value = 0; Double_t err = 0; - for (Int_t bin = 1; bin <= ratioPlot->GetNbinsX(); bin++){ - if (denom->GetBinContent(bin)!=0){ + for (Int_t bin = 1; bin <= ratioPlot->GetNbinsX(); bin++) + { + if (denom->GetBinContent(bin)!=0) + { value = numer->GetBinContent(bin) / denom->GetBinContent(bin); // currently implement same method for FR and Eff (minimize mask calls) if (subone) value -= 1.0; @@ -794,12 +889,14 @@ void PlotValidation::ComputeRatioPlot(const TH1F * numer, const TH1F * denom, TH } } -void PlotValidation::WriteTH2FPlot(TDirectory *& subdir, TH2F *& hist){ +void PlotValidation::WriteTH2FPlot(TDirectory *& subdir, TH2F *& hist) +{ subdir->cd(); hist->Write(); } -void PlotValidation::DrawWriteSaveTH2FPlot(TDirectory *& subdir, TH2F *& hist, const TString subdirname, const TString plotName){ +void PlotValidation::DrawWriteSaveTH2FPlot(TDirectory *& subdir, TH2F *& hist, const TString subdirname, const TString plotName) +{ fTH2Canv->cd(); hist->Draw("colz"); subdir->cd(); @@ -807,12 +904,14 @@ void PlotValidation::DrawWriteSaveTH2FPlot(TDirectory *& subdir, TH2F *& hist, c if (fSaveAs) fTH2Canv->SaveAs(Form("%s/%s/%s.png",fOutName.Data(),subdirname.Data(),plotName.Data())); } -void PlotValidation::WriteTH1FPlot(TDirectory *& subdir, TH1F *& hist){ +void PlotValidation::WriteTH1FPlot(TDirectory *& subdir, TH1F *& hist) +{ subdir->cd(); hist->Write(); } -void PlotValidation::DrawWriteSaveTH1FPlot(TDirectory *& subdir, TH1F *& hist, const TString subdirname, const TString plotName, const Bool_t zeroSupLin){ +void PlotValidation::DrawWriteSaveTH1FPlot(TDirectory *& subdir, TH1F *& hist, const TString subdirname, const TString plotName, const Bool_t zeroSupLin) +{ fTH1Canv->cd(); hist->Draw(); subdir->cd(); @@ -823,14 +922,14 @@ void PlotValidation::DrawWriteSaveTH1FPlot(TDirectory *& subdir, TH1F *& hist, c if (fSaveAs) fTH1Canv->SaveAs(Form("%s/%s/log/%s.%s",fOutName.Data(),subdirname.Data(),plotName.Data(),fOutType.Data())); // second save linear (check to zero suppress) - if (zeroSupLin) { - PlotValidation::ZeroSuppressPlot(hist); - } + if (zeroSupLin) PlotValidation::ZeroSuppressPlot(hist); + fTH1Canv->SetLogy(0); if (fSaveAs) fTH1Canv->SaveAs(Form("%s/%s/lin/%s.%s",fOutName.Data(),subdirname.Data(),plotName.Data(),fOutType.Data())); } -void PlotValidation::DrawWriteFitSaveTH1FPlot(TDirectory *& subdir, TH1F *& hist, const TString subdirname, const TString plotName, const Float_t fitRange){ // separate method for fitting pulls/res, do not want gaus line in root file +void PlotValidation::DrawWriteFitSaveTH1FPlot(TDirectory *& subdir, TH1F *& hist, const TString subdirname, const TString plotName, const Float_t fitRange) // separate method for fitting pulls/res, do not want gaus line in root file +{ fTH1Canv->cd(); hist->Draw(); subdir->cd(); @@ -846,7 +945,8 @@ void PlotValidation::DrawWriteFitSaveTH1FPlot(TDirectory *& subdir, TH1F *& hist if (fSaveAs) fTH1Canv->SaveAs(Form("%s/%s/lin/%s.%s",fOutName.Data(),subdirname.Data(),plotName.Data(),fOutType.Data())); } -void PlotValidation::MoveInput(){ +void PlotValidation::MoveInput() +{ TString mvin = "mv "; mvin += fInName.Data(); mvin += " "; diff --git a/TTreeValidation.cc b/TTreeValidation.cc index cb917274b0507..ce5089b648e63 100644 --- a/TTreeValidation.cc +++ b/TTreeValidation.cc @@ -1,7 +1,18 @@ +// mcTrackID assignments in Track.cc +// Efficiency +// numerator: sim tracks with at least one reco track with mcTrackID >= 0 +// denominator: all sim tracks +// Fake Rate (with only long reco tracks: Config::shortFakes == false) +// numerator: reco tracks with mcTrackID == -1 +// denominator: reco tracks with mcTrackID >= 0 || == -1 +// Fake Rate (with all reco tracks: Config::shortFakes == true) +// numerator: reco tracks with mcTrackID == -1, == -3 +// denominator: reco tracks with mcTrackID >= 0 || == -1 || == -2 || == -3 || == -4 + // N.B. Mask assignments // --> mcmask_[reco] == 1, "associated" reco to sim track [possible duplmask_[reco] == 1,0] {eff and FR} // --> mcmask_[reco] == 0, "unassociated" reco to sim track. by definition no duplicates (no reco to associate to sim tracks!) [possible duplmask_[reco] == 2 {eff and FR}] -// --> mcmask_[reco] == -1, "no matching seed to build/fit" track, therefore no build/fit track to match sim! [possible duplmask_[reco] == -1] {FR only} +// --> mcmask_[reco] == -1, reco track excluded from denominator (and therefore numerator) of FR [possible duplmask_[reco] == -1] {FR only} // --> nTkMatches_[reco] > 1, n reco tracks associated to the same sim track ID {eff only} // --> nTkMatches_[reco] == 1, 1 reco track associated to single sim track ID {eff only} @@ -25,7 +36,8 @@ // position reco variables // --> layers_[reco] == -1, reco unassociated to sim tk {eff only} -// --> reco pos+err var == -2000, reco tk is unassociated to sim tk, just filled once {eff only} +// --> reco pos+err var == -2000, reco tk is unassociated to sim tk {eff only} +// --> reco pos+err var == -3000, reco tk is unassociated to seed tk {FR only} #include "TTreeValidation.h" #include "Event.h" @@ -57,14 +69,14 @@ TTreeValidation::TTreeValidation(std::string fileName) if (Config::root_val) { - initializeEfficiencyTree(); - initializeFakeRateTree(); + TTreeValidation::initializeEfficiencyTree(); + TTreeValidation::initializeFakeRateTree(); } if (Config::fit_val) { - initializeFitTree(); + TTreeValidation::initializeFitTree(); } - initializeConfigTree(); + TTreeValidation::initializeConfigTree(); } TTreeValidation::~TTreeValidation() @@ -96,6 +108,10 @@ void TTreeValidation::initializeEfficiencyTree() efftree_->Branch("seedID_build",&seedID_build_eff_); efftree_->Branch("seedID_fit",&seedID_fit_eff_); + efftree_->Branch("x_mc_gen",&x_mc_gen_eff_); + efftree_->Branch("y_mc_gen",&y_mc_gen_eff_); + efftree_->Branch("z_mc_gen",&z_mc_gen_eff_); + efftree_->Branch("pt_mc_gen",&pt_mc_gen_eff_); efftree_->Branch("phi_mc_gen",&phi_mc_gen_eff_); efftree_->Branch("eta_mc_gen",&eta_mc_gen_eff_); @@ -104,6 +120,18 @@ void TTreeValidation::initializeEfficiencyTree() efftree_->Branch("mcmask_build",&mcmask_build_eff_); efftree_->Branch("mcmask_fit",&mcmask_fit_eff_); + efftree_->Branch("xhit_seed",&xhit_seed_eff_); + efftree_->Branch("xhit_build",&xhit_build_eff_); + efftree_->Branch("xhit_fit",&xhit_fit_eff_); + + efftree_->Branch("yhit_seed",&yhit_seed_eff_); + efftree_->Branch("yhit_build",&yhit_build_eff_); + efftree_->Branch("yhit_fit",&yhit_fit_eff_); + + efftree_->Branch("zhit_seed",&zhit_seed_eff_); + efftree_->Branch("zhit_build",&zhit_build_eff_); + efftree_->Branch("zhit_fit",&zhit_fit_eff_); + efftree_->Branch("pt_mc_seed",&pt_mc_seed_eff_); efftree_->Branch("pt_seed",&pt_seed_eff_); efftree_->Branch("ept_seed",&ept_seed_eff_); @@ -179,6 +207,18 @@ void TTreeValidation::initializeFakeRateTree() fakeratetree_->Branch("seedmask_build",&seedmask_build_FR_); fakeratetree_->Branch("seedmask_fit",&seedmask_fit_FR_); + fakeratetree_->Branch("xhit_seed",&xhit_seed_FR_); + fakeratetree_->Branch("xhit_build",&xhit_build_FR_); + fakeratetree_->Branch("xhit_fit",&xhit_fit_FR_); + + fakeratetree_->Branch("yhit_seed",&yhit_seed_FR_); + fakeratetree_->Branch("yhit_build",&yhit_build_FR_); + fakeratetree_->Branch("yhit_fit",&yhit_fit_FR_); + + fakeratetree_->Branch("zhit_seed",&zhit_seed_FR_); + fakeratetree_->Branch("zhit_build",&zhit_build_FR_); + fakeratetree_->Branch("zhit_fit",&zhit_fit_FR_); + fakeratetree_->Branch("pt_seed",&pt_seed_FR_); fakeratetree_->Branch("ept_seed",&ept_seed_FR_); fakeratetree_->Branch("pt_build",&pt_build_FR_); @@ -400,20 +440,31 @@ void TTreeValidation::resetValidationMaps() void TTreeValidation::setTrackExtras(Event& ev) { std::lock_guard locker(glock_); - // set mcTkIDs - setTrackCollectionExtras(ev.seedTracks_,ev.seedTracksExtra_,ev.layerHits_,ev.simHitsInfo_); - setTrackCollectionExtras(ev.candidateTracks_,ev.candidateTracksExtra_,ev.layerHits_,ev.simHitsInfo_); - setTrackCollectionExtras(ev.fitTracks_,ev.fitTracksExtra_,ev.layerHits_,ev.simHitsInfo_); -} -void TTreeValidation::setTrackCollectionExtras(const TrackVec& evt_tracks, TrackExtraVec& evt_extras, - const std::vector& layerHits, const MCHitInfoVec& mcHitInfo) -{ - for (auto itrack = 0; itrack < evt_tracks.size(); ++itrack) + // set mcTrackID for seed tracks + for (int itrack = 0; itrack < ev.seedTracks_.size(); itrack++) { - auto&& track(evt_tracks[itrack]); - auto&& extra(evt_extras[itrack]); - extra.setMCTrackIDInfo(track, layerHits, mcHitInfo); + auto&& track(ev.seedTracks_[itrack]); + auto&& extra(ev.seedTracksExtra_[itrack]); + extra.setMCTrackIDInfo(track, ev.layerHits_, ev.simHitsInfo_, ev.simTracks_); // otherwise seeds are completely unmatched in ToyMC Sim Seeds + } + + // set mcTrackID for built tracks + for (int itrack = 0; itrack < ev.candidateTracks_.size(); itrack++) + { + auto&& track(ev.candidateTracks_[itrack]); + auto&& extra(ev.candidateTracksExtra_[itrack]); + if (Config::useCMSGeom || Config::findSeeds) {extra.setMCTrackIDInfo(track, ev.layerHits_, ev.simHitsInfo_, ev.simTracks_);} + else {extra.setMCTrackIDInfoByLabel(track, ev.layerHits_, ev.simHitsInfo_, ev.simTracks_[track.label()]);} + } + + // set mcTrackID for fit tracks + for (int itrack = 0; itrack < ev.fitTracks_.size(); itrack++) + { + auto&& track(ev.fitTracks_[itrack]); + auto&& extra(ev.fitTracksExtra_[itrack]); + if (Config::useCMSGeom || Config::findSeeds) {extra.setMCTrackIDInfo(track, ev.layerHits_, ev.simHitsInfo_, ev.simTracks_);} + else {extra.setMCTrackIDInfoByLabel(track, ev.layerHits_, ev.simHitsInfo_, ev.simTracks_[track.label()]);} } } @@ -421,9 +472,9 @@ void TTreeValidation::makeSimTkToRecoTksMaps(Event& ev) { std::lock_guard locker(glock_); // map sim track ids to reco labels sort by each (simTracks set in order by default!) - mapSimTkToRecoTks(ev.seedTracks_,ev.seedTracksExtra_,simToSeedMap_); - mapSimTkToRecoTks(ev.candidateTracks_,ev.candidateTracksExtra_,simToBuildMap_); - mapSimTkToRecoTks(ev.fitTracks_,ev.fitTracksExtra_,simToFitMap_); + TTreeValidation::mapSimTkToRecoTks(ev.seedTracks_,ev.seedTracksExtra_,simToSeedMap_); + TTreeValidation::mapSimTkToRecoTks(ev.candidateTracks_,ev.candidateTracksExtra_,simToBuildMap_); + TTreeValidation::mapSimTkToRecoTks(ev.fitTracks_,ev.fitTracksExtra_,simToFitMap_); } void TTreeValidation::mapSimTkToRecoTks(const TrackVec& evt_tracks, TrackExtraVec& evt_extras, TkIDToTkIDVecMap& simTkMap) @@ -432,7 +483,8 @@ void TTreeValidation::mapSimTkToRecoTks(const TrackVec& evt_tracks, TrackExtraVe { auto&& track(evt_tracks[itrack]); auto&& extra(evt_extras[itrack]); - if (extra.mcTrackID() >= 0){ // skip fakes, don't store them at all in sim map + if (extra.mcTrackID() >= 0) // skip fakes, don't store them at all in sim map + { simTkMap[extra.mcTrackID()].push_back(track.label()); // store vector of reco tk labels, mapped to the sim track label (i.e. mcTrackID) } } @@ -474,8 +526,8 @@ void TTreeValidation::makeSeedTkToRecoTkMaps(Event& ev) { std::lock_guard locker(glock_); // map seed to reco tracks --> seed track collection assumed to map to itself, unless we make some cuts - mapSeedTkToRecoTk(ev.candidateTracks_,ev.candidateTracksExtra_,seedToBuildMap_); - mapSeedTkToRecoTk(ev.fitTracks_,ev.fitTracksExtra_,seedToFitMap_); + TTreeValidation::mapSeedTkToRecoTk(ev.candidateTracks_,ev.candidateTracksExtra_,seedToBuildMap_); + TTreeValidation::mapSeedTkToRecoTk(ev.fitTracks_,ev.fitTracksExtra_,seedToFitMap_); } void TTreeValidation::mapSeedTkToRecoTk(const TrackVec& evt_tracks, const TrackExtraVec& evt_extras, TkIDToTkIDMap& seedTkMap) @@ -546,7 +598,7 @@ void TTreeValidation::fillFitTree(const Event& ev) for(auto&& fitvalmapmap : fitValTkMapMap_) { - resetFitBranches(); + TTreeValidation::resetFitBranches(); tkid_fit_ = fitvalmapmap.first; // seed id (label) is the same as the mcID @@ -615,6 +667,10 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) mcID_eff_ = simtrack.label(); // generated values + x_mc_gen_eff_ = simtrack.x(); + y_mc_gen_eff_ = simtrack.y(); + z_mc_gen_eff_ = simtrack.z(); + pt_mc_gen_eff_ = simtrack.pT(); phi_mc_gen_eff_ = simtrack.momPhi(); eta_mc_gen_eff_ = simtrack.momEta(); @@ -631,7 +687,7 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) seedID_seed_eff_ = seedextra.seedID(); // use this to access correct sim track layer params - const int mcHitID = getLastGoodHit(seedtrack.getLastGoodMCHitID(evt_layer_hits),mcID_eff_,ev); + const int mcHitID = TTreeValidation::getLastGoodHit(seedtrack.getLastGoodMCHitID(evt_layer_hits),mcID_eff_,ev); if (mcHitID >= 0) { const TrackState & initLayTS = evt_sim_trackstates[mcHitID]; @@ -651,6 +707,12 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) helixchi2_seed_eff_ = -101; } + // last hit info + const Hit& lasthit = evt_layer_hits[seedtrack.getLastGoodHitLyr()][seedtrack.getLastGoodHitIdx()]; + xhit_seed_eff_ = lasthit.x(); + yhit_seed_eff_ = lasthit.y(); + zhit_seed_eff_ = lasthit.z(); + pt_seed_eff_ = seedtrack.pT(); ept_seed_eff_ = seedtrack.epT(); phi_seed_eff_ = seedtrack.momPhi(); @@ -661,7 +723,7 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) // rest of mc info nHits_seed_eff_ = seedtrack.nFoundHits(); nHitsMatched_seed_eff_ = seedextra.nHitsMatched(); - fracHitsMatched_seed_eff_ = float(nHitsMatched_seed_eff_) / float(nHits_seed_eff_); + fracHitsMatched_seed_eff_ = seedextra.fracHitsMatched(); lastlyr_seed_eff_ = seedtrack.getLastGoodHitLyr(); hitchi2_seed_eff_ = seedtrack.chi2(); // currently not being used @@ -679,6 +741,10 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) phi_mc_seed_eff_ = -99; eta_mc_seed_eff_ = -99; + xhit_seed_eff_ = -2000; + yhit_seed_eff_ = -2000; + zhit_seed_eff_ = -2000; + pt_seed_eff_ = -99; ept_seed_eff_ = -99; phi_seed_eff_ = -99; @@ -708,7 +774,7 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) seedID_build_eff_ = buildextra.seedID(); // use this to access correct sim track layer params - const int mcHitID = getLastGoodHit(buildtrack.getLastGoodMCHitID(evt_layer_hits),mcID_eff_,ev); + const int mcHitID = TTreeValidation::getLastGoodHit(buildtrack.getLastGoodMCHitID(evt_layer_hits),mcID_eff_,ev); if (mcHitID >= 0) { const TrackState & initLayTS = evt_sim_trackstates[mcHitID]; @@ -728,6 +794,12 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) helixchi2_build_eff_ = -101; } + // last hit info + const Hit& lasthit = evt_layer_hits[buildtrack.getLastGoodHitLyr()][buildtrack.getLastGoodHitIdx()]; + xhit_build_eff_ = lasthit.x(); + yhit_build_eff_ = lasthit.y(); + zhit_build_eff_ = lasthit.z(); + pt_build_eff_ = buildtrack.pT(); ept_build_eff_ = buildtrack.epT(); phi_build_eff_ = buildtrack.momPhi(); @@ -737,7 +809,7 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) nHits_build_eff_ = buildtrack.nFoundHits(); nHitsMatched_build_eff_ = buildextra.nHitsMatched(); - fracHitsMatched_build_eff_ = float(nHitsMatched_build_eff_) / float(nHits_build_eff_); + fracHitsMatched_build_eff_ = buildextra.fracHitsMatched(); lastlyr_build_eff_ = buildtrack.getLastGoodHitLyr(); hitchi2_build_eff_ = buildtrack.chi2(); @@ -755,6 +827,10 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) phi_mc_build_eff_ = -99; eta_mc_build_eff_ = -99; + xhit_build_eff_ = -2000; + yhit_build_eff_ = -2000; + zhit_build_eff_ = -2000; + pt_build_eff_ = -99; ept_build_eff_ = -99; phi_build_eff_ = -99; @@ -784,7 +860,7 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) seedID_fit_eff_ = fitextra.seedID(); // use this to access correct sim track layer params - const int mcHitID = getLastGoodHit(fittrack.getLastGoodMCHitID(evt_layer_hits),mcID_eff_,ev); + const int mcHitID = TTreeValidation::getLastGoodHit(fittrack.getLastGoodMCHitID(evt_layer_hits),mcID_eff_,ev); if (mcHitID >= 0) { const TrackState & initLayTS = evt_sim_trackstates[mcHitID]; @@ -804,6 +880,12 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) helixchi2_fit_eff_ = -101; } + // last hit info + const Hit& lasthit = evt_layer_hits[fittrack.getLastGoodHitLyr()][fittrack.getLastGoodHitIdx()]; + xhit_fit_eff_ = lasthit.x(); + yhit_fit_eff_ = lasthit.y(); + zhit_fit_eff_ = lasthit.z(); + pt_fit_eff_ = fittrack.pT(); ept_fit_eff_ = fittrack.epT(); phi_fit_eff_ = fittrack.momPhi(); @@ -814,7 +896,7 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) // rest of mc info nHits_fit_eff_ = fittrack.nFoundHits(); nHitsMatched_fit_eff_ = fitextra.nHitsMatched(); - fracHitsMatched_fit_eff_ = float(nHitsMatched_fit_eff_) / float(nHits_fit_eff_); + fracHitsMatched_fit_eff_ = fitextra.fracHitsMatched(); lastlyr_fit_eff_ = fittrack.getLastGoodHitLyr(); hitchi2_fit_eff_ = -10; //fittrack.chi2(); // currently not being used @@ -832,6 +914,10 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) phi_mc_fit_eff_ = -99; eta_mc_fit_eff_ = -99; + xhit_fit_eff_ = -2000; + yhit_fit_eff_ = -2000; + zhit_fit_eff_ = -2000; + pt_fit_eff_ = -99; ept_fit_eff_ = -99; phi_fit_eff_ = -99; @@ -860,7 +946,7 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) std::lock_guard locker(glock_); auto ievt = ev.evtID(); - auto& evt_sim_tracks = ev.simTracks_; + auto& evt_sim_tracks = ev.simTracks_; // store sim info at that final layer!!! --> gen info stored only in eff tree auto& evt_seed_tracks = ev.seedTracks_; auto& evt_seed_extras = ev.seedTracksExtra_; auto& evt_build_tracks = ev.candidateTracks_; @@ -879,6 +965,12 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) // seed info seedmask_seed_FR_ = 1; // automatically set to 1, because at the moment no cuts on seeds after conformal+KF fit. seed triplets filtered by RZ chi2 before fitting. + // last hit info + const Hit& lasthit = evt_layer_hits[seedtrack.getLastGoodHitLyr()][seedtrack.getLastGoodHitIdx()]; + xhit_seed_FR_ = lasthit.x(); + yhit_seed_FR_ = lasthit.y(); + zhit_seed_FR_ = lasthit.z(); + pt_seed_FR_ = seedtrack.pT(); ept_seed_FR_ = seedtrack.epT(); phi_seed_FR_ = seedtrack.momPhi(); @@ -888,26 +980,40 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) nHits_seed_FR_ = seedtrack.nFoundHits(); nHitsMatched_seed_FR_ = seedextra.nHitsMatched(); - fracHitsMatched_seed_FR_ = float(nHitsMatched_seed_FR_) / float(nHits_seed_FR_); + fracHitsMatched_seed_FR_ = seedextra.fracHitsMatched(); lastlyr_seed_FR_ = seedtrack.getLastGoodHitLyr(); hitchi2_seed_FR_ = seedtrack.chi2(); //--> not currently used // sim info for seed track mcID_seed_FR_ = seedextra.mcTrackID(); - if (mcID_seed_FR_ >= 0) // store sim info at that final layer!!! --> gen info stored only in eff tree + if (mcID_seed_FR_ >= 0) // seed track matched to seed and sim { - auto& simtrack = evt_sim_tracks[mcID_seed_FR_]; mcmask_seed_FR_ = 1; // matched track to sim + } + else + { + if (Config::shortFakes) + { + mcmask_seed_FR_ = ((mcID_seed_FR_ == -1 || mcID_seed_FR_ == -3) ? 0 : -1); // mask == -1 for mcID == -2,-4,-5 + } + else + { + mcmask_seed_FR_ = (mcID_seed_FR_ == -1 ? 0 : -1); // mask == -1 for mcID == -2,-3,-4,-5 + } + } + + if (mcmask_seed_FR_ >= 0) // matched track to sim + { + auto& simtrack = evt_sim_tracks[mcID_seed_FR_]; - const int mcHitID = getLastGoodHit(seedtrack.getLastGoodMCHitID(evt_layer_hits),mcID_seed_FR_,ev); + const int mcHitID = TTreeValidation::getLastGoodHit(seedtrack.getLastGoodMCHitID(evt_layer_hits),mcID_seed_FR_,ev); if (mcHitID >= 0) { const TrackState & initLayTS = evt_sim_trackstates[mcHitID]; pt_mc_seed_FR_ = initLayTS.pT(); phi_mc_seed_FR_ = initLayTS.momPhi(); eta_mc_seed_FR_ = initLayTS.momEta(); - helixchi2_seed_FR_ = computeHelixChi2(initLayTS.parameters,seedtrack.parameters(),seedtrack.errors()); } else @@ -915,7 +1021,6 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) pt_mc_seed_FR_ = -101; phi_mc_seed_FR_ = -101; eta_mc_seed_FR_ = -101; - helixchi2_seed_FR_ = -101; } @@ -927,12 +1032,12 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) } else { - mcmask_seed_FR_ = 0; // fake track (unmatched track) - // -99 for all sim info for reco tracks not associated to reco tracks pt_mc_seed_FR_ = -99; phi_mc_seed_FR_ = -99; eta_mc_seed_FR_ = -99; + helixchi2_seed_FR_ = -99; + nHits_mc_seed_FR_ = -99; lastlyr_mc_seed_FR_ = -99; @@ -950,6 +1055,12 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) auto& buildtrack = evt_build_tracks[seedToBuildMap_[seedID_FR_]]; auto& buildextra = evt_build_extras[buildtrack.label()]; + // last hit info + const Hit& lasthit = evt_layer_hits[buildtrack.getLastGoodHitLyr()][buildtrack.getLastGoodHitIdx()]; + xhit_build_FR_ = lasthit.x(); + yhit_build_FR_ = lasthit.y(); + zhit_build_FR_ = lasthit.z(); + pt_build_FR_ = buildtrack.pT(); ept_build_FR_ = buildtrack.epT(); phi_build_FR_ = buildtrack.momPhi(); @@ -959,7 +1070,7 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) nHits_build_FR_ = buildtrack.nFoundHits(); nHitsMatched_build_FR_ = buildextra.nHitsMatched(); - fracHitsMatched_build_FR_ = float(nHitsMatched_build_FR_) / float(nHits_build_FR_); + fracHitsMatched_build_FR_ = buildextra.fracHitsMatched(); lastlyr_build_FR_ = buildtrack.getLastGoodHitLyr(); hitchi2_build_FR_ = buildtrack.chi2(); @@ -968,25 +1079,38 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) mcID_build_FR_ = buildextra.mcTrackID(); if (mcID_build_FR_ >= 0) // build track matched to seed and sim { - auto& simtrack = evt_sim_tracks[mcID_build_FR_]; mcmask_build_FR_ = 1; // matched track to sim + } + else + { + if (Config::shortFakes) + { + mcmask_build_FR_ = ((mcID_build_FR_ == -1 || mcID_build_FR_ == -3) ? 0 : -1); // mask == -1 for mcID == -2,-4,-5 + } + else + { + mcmask_build_FR_ = (mcID_build_FR_ == -1 ? 0 : -1); // mask == -1 for mcID == -2,-3,-4,-5 + } + } - const int mcHitID = getLastGoodHit(buildtrack.getLastGoodMCHitID(evt_layer_hits),mcID_build_FR_,ev); + if (mcmask_build_FR_ >= 0) // build track matched to seed and sim + { + auto& simtrack = evt_sim_tracks[mcID_build_FR_]; + + const int mcHitID = TTreeValidation::getLastGoodHit(buildtrack.getLastGoodMCHitID(evt_layer_hits),mcID_build_FR_,ev); if (mcHitID >= 0) { const TrackState & initLayTS = evt_sim_trackstates[mcHitID]; pt_mc_build_FR_ = initLayTS.pT(); phi_mc_build_FR_ = initLayTS.momPhi(); eta_mc_build_FR_ = initLayTS.momEta(); - helixchi2_build_FR_ = computeHelixChi2(initLayTS.parameters,buildtrack.parameters(),buildtrack.errors()); } - else + else { pt_mc_build_FR_ = -101; phi_mc_build_FR_ = -101; eta_mc_build_FR_ = -101; - helixchi2_build_FR_ = -101; } @@ -998,12 +1122,12 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) } else // build track matched only to seed not to sim { - mcmask_build_FR_ = 0; // fake track (unmatched track) - // -99 for all sim info for reco tracks not associated to reco tracks pt_mc_build_FR_ = -99; phi_mc_build_FR_ = -99; eta_mc_build_FR_ = -99; + helixchi2_build_FR_ = -99; + nHits_mc_build_FR_ = -99; lastlyr_mc_build_FR_ = -99; @@ -1016,6 +1140,11 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) { seedmask_build_FR_ = 0; // quick logic + // -3000 for position info if no build track for seed + xhit_build_FR_ = -3000; + yhit_build_FR_ = -3000; + zhit_build_FR_ = -3000; + // -100 for all reco info as no actual build track for this seed pt_build_FR_ = -100; ept_build_FR_ = -100; @@ -1038,11 +1167,11 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) pt_mc_build_FR_ = -100; phi_mc_build_FR_ = -100; eta_mc_build_FR_ = -100; + helixchi2_build_FR_ = -100; + nHits_mc_build_FR_ = -100; lastlyr_mc_build_FR_ = -100; - helixchi2_build_FR_ = -100; - duplmask_build_FR_ = -1; iTkMatches_build_FR_ = -100; } @@ -1056,6 +1185,12 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) auto& fittrack = evt_fit_tracks[seedToFitMap_[seedID_FR_]]; auto& fitextra = evt_fit_extras[fittrack.label()]; + // last hit info + const Hit& lasthit = evt_layer_hits[fittrack.getLastGoodHitLyr()][fittrack.getLastGoodHitIdx()]; + xhit_fit_FR_ = lasthit.x(); + yhit_fit_FR_ = lasthit.y(); + zhit_fit_FR_ = lasthit.z(); + pt_fit_FR_ = fittrack.pT(); ept_fit_FR_ = fittrack.epT(); phi_fit_FR_ = fittrack.momPhi(); @@ -1065,7 +1200,7 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) nHits_fit_FR_ = fittrack.nFoundHits(); nHitsMatched_fit_FR_ = fitextra.nHitsMatched(); - fracHitsMatched_fit_FR_ = float(nHitsMatched_fit_FR_) / float(nHits_fit_FR_); + fracHitsMatched_fit_FR_ = fitextra.fracHitsMatched(); lastlyr_fit_FR_ = fittrack.getLastGoodHitLyr(); hitchi2_fit_FR_ = -10; //fittrack.chi2() --> currently not used @@ -1075,15 +1210,30 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) if (mcID_fit_FR_ >= 0) // fit track matched to seed and sim { mcmask_fit_FR_ = 1; // matched track to sim + } + else + { + if (Config::shortFakes) + { + mcmask_fit_FR_ = ((mcID_fit_FR_ == -1 || mcID_fit_FR_ == -3) ? 0 : -1); // mask == -1 for mcID == -2,-4,-5 + } + else + { + mcmask_fit_FR_ = (mcID_fit_FR_ == -1 ? 0 : -1); // mask == -1 for mcID == -2,-3,-4,-5 + } + } - const int mcHitID = getLastGoodHit(fittrack.getLastGoodMCHitID(evt_layer_hits),mcID_fit_FR_,ev); // only works for outward fit for now + if (mcmask_fit_FR_ >= 0) // fit track matched to seed and sim + { + mcmask_fit_FR_ = 1; // matched track to sim + + const int mcHitID = TTreeValidation::getLastGoodHit(fittrack.getLastGoodMCHitID(evt_layer_hits),mcID_fit_FR_,ev); // only works for outward fit for now if (mcHitID >= 0) { const TrackState & initLayTS = evt_sim_trackstates[mcHitID]; pt_mc_fit_FR_ = initLayTS.pT(); phi_mc_fit_FR_ = initLayTS.momPhi(); eta_mc_fit_FR_ = initLayTS.momEta(); - helixchi2_fit_FR_ = computeHelixChi2(initLayTS.parameters,fittrack.parameters(),fittrack.errors()); } else @@ -1091,7 +1241,6 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) pt_mc_fit_FR_ = -101; phi_mc_fit_FR_ = -101; eta_mc_fit_FR_ = -101; - helixchi2_fit_FR_ = -101; } @@ -1103,12 +1252,12 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) } else // fit track matched only to seed not to sim { - mcmask_fit_FR_ = 0; // fake track (unmatched track) - // -99 for all sim info for reco tracks not associated to reco tracks pt_mc_fit_FR_ = -99; phi_mc_fit_FR_ = -99; eta_mc_fit_FR_ = -99; + helixchi2_fit_FR_ = -99; + nHits_mc_fit_FR_ = -99; lastlyr_mc_fit_FR_ = -99; @@ -1121,6 +1270,11 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) { seedmask_fit_FR_ = 0; // quick logic + // -3000 for position info if no fit track for seed + xhit_fit_FR_ = -3000; + yhit_fit_FR_ = -3000; + zhit_fit_FR_ = -3000; + // -100 for all reco info as no actual fit track for this seed pt_fit_FR_ = -100; ept_fit_FR_ = -100; @@ -1143,11 +1297,11 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) pt_mc_fit_FR_ = -100; phi_mc_fit_FR_ = -100; eta_mc_fit_FR_ = -100; + helixchi2_fit_FR_ = -100; + nHits_mc_fit_FR_ = -100; lastlyr_mc_fit_FR_ = -100; - helixchi2_fit_FR_ = -100; - duplmask_fit_FR_ = -1; iTkMatches_fit_FR_ = -100; } diff --git a/TTreeValidation.h b/TTreeValidation.h index 47ee5cf051977..95f6578c063f3 100644 --- a/TTreeValidation.h +++ b/TTreeValidation.h @@ -38,8 +38,6 @@ class TTreeValidation : public Validation { void resetFitBranches(); void setTrackExtras(Event& ev) override; - void setTrackCollectionExtras(const TrackVec& evt_tracks, TrackExtraVec& evt_extras, - const std::vector& layerHits, const MCHitInfoVec& mcHitInfo); void makeSimTkToRecoTksMaps(Event& ev) override; void mapSimTkToRecoTks(const TrackVec& evt_tracks, TrackExtraVec& evt_extras, TkIDToTkIDVecMap& simTkMap); @@ -76,9 +74,15 @@ class TTreeValidation : public Validation { int seedID_seed_eff_=0,seedID_build_eff_=0,seedID_fit_eff_=0; // for efficiency and duplicate rate plots + float x_mc_gen_eff_=0.,y_mc_gen_eff_=0.,z_mc_gen_eff_=0.; float pt_mc_gen_eff_=0.,phi_mc_gen_eff_=0.,eta_mc_gen_eff_=0.; int nHits_mc_eff_=0,lastlyr_mc_eff_=0; + // for getting last hit positions track ended up on + float xhit_seed_eff_=0.,xhit_build_eff_=0.,xhit_fit_eff_=0.; + float yhit_seed_eff_=0.,yhit_build_eff_=0.,yhit_fit_eff_=0.; + float zhit_seed_eff_=0.,zhit_build_eff_=0.,zhit_fit_eff_=0.; + // for track resolutions / pulls float pt_mc_seed_eff_=0.,pt_mc_build_eff_=0.,pt_mc_fit_eff_=0.; float pt_seed_eff_=0.,pt_build_eff_=0.,pt_fit_eff_=0.,ept_seed_eff_=0.,ept_build_eff_=0.,ept_fit_eff_=0.; @@ -106,6 +110,13 @@ class TTreeValidation : public Validation { int evtID_FR_=0,seedID_FR_=0; int seedmask_seed_FR_=0,seedmask_build_FR_=0,seedmask_fit_FR_=0; + + // for getting last hit positions track ended up on + float xhit_seed_FR_=0.,xhit_build_FR_=0.,xhit_fit_FR_=0.; + float yhit_seed_FR_=0.,yhit_build_FR_=0.,yhit_fit_FR_=0.; + float zhit_seed_FR_=0.,zhit_build_FR_=0.,zhit_fit_FR_=0.; + + // track state info float pt_mc_seed_FR_=0.,pt_mc_build_FR_=0.,pt_mc_fit_FR_=0.; float pt_seed_FR_=0.,pt_build_FR_=0.,pt_fit_FR_=0.,ept_seed_FR_=0.,ept_build_FR_=0.,ept_fit_FR_=0.; float phi_mc_seed_FR_=0.,phi_mc_build_FR_=0.,phi_mc_fit_FR_=0.; diff --git a/Track.cc b/Track.cc index 952cbd972e89f..692ef7ef72489 100644 --- a/Track.cc +++ b/Track.cc @@ -66,48 +66,118 @@ SMatrix66 TrackState::jacobianCartesianToCCS(float px,float py,float pz) const { return jac; } -// find the simtrack that provided the most hits -void TrackExtra::setMCTrackIDInfo(const Track& trk, const std::vector& layerHits, const MCHitInfoVec& globalHitInfo) +// mcTrackID assignments +// ID >= 0 : reco track matched to sim track (n eligible found reco hits matching single sim track above some threshold, and n eligible found reco hits above some threshold) +// ID == -1 : reco track is a true fake (n eligible found reco hits matching single sim track below some threshold, and n eligible found reco hits above some threshold) +// ID == -2 : reco track is a matched short track --> inefficient but not fake (n eligible found reco hits matching single sim track above some threshold, and n eligible found reco hits below some threshold) +// ID == -3 : reco track is a short fake (n eligible found reco hits matching single sim track below some threshold, and n eligible found reco hits below some threshold) --> TOYMC SIM SEEDS ONLY +// ID == -4 : reco track never made it past its sim seed --> inefficient but not fake --> TOYMC SIM SEEDS ONLY +// ID == -5 : reco track somehow has zero hits... unclear what to do with these... ---> CMSSW OR REAL SEEDS ONLY + +// More stringent requirement for matching --> used only for simtrack pure seeds +void TrackExtra::setMCTrackIDInfoByLabel(const Track& trk, const std::vector& layerHits, const MCHitInfoVec& globalHitInfo, const Track& simtrack) { - std::vector mctrack; - auto hitIdx = trk.nTotalHits(); - for (int ihit = 0; ihit < hitIdx; ++ihit) { - auto hitidx = trk.getHitIdx(ihit); - auto hitlyr = trk.getHitLyr(ihit); - if ((hitidx >= 0) && (hitidx < layerHits[hitlyr].size())) { - auto mchitid = layerHits[hitlyr][hitidx].mcHitID(); - dprint("trk.label()=" << trk.label() << " ihit=" << ihit + const int label = simtrack.label(); + int nHitsMatched = 0; + // count hits matched to simtrack after the seed : will need to modify the start of this loop! XXKM4MT + for (int ihit = Config::nlayers_per_seed; ihit < trk.nTotalHits(); ++ihit) + { + const int hitidx = trk.getHitIdx(ihit); + const int hitlyr = trk.getHitLyr(ihit); + if ((hitidx >= 0) && (hitidx < layerHits[hitlyr].size())) // make sure it is a real hit + { + const int mchitid = layerHits[hitlyr][hitidx].mcHitID(); + dprint("trk.label()=" << trk.label() << " simtrack.label()= " << label << " ihit=" << ihit << " trk.getHitIdx(ihit)=" << hitidx << "trk.getHitLyr(ihit)" << hitlyr << " mchitid=" << mchitid << " globalHitInfo[mchitid].mcTrackID()=" << globalHitInfo[mchitid].mcTrackID()); - mctrack.push_back(globalHitInfo[mchitid].mcTrackID()); + if (globalHitInfo[mchitid].mcTrackID() == label) nHitsMatched++; } } - std::sort(mctrack.begin(), mctrack.end()); // ensures all elements are checked properly - auto mcount(0), c(0); + // Eligible hits + const int nCandHits = trk.nFoundHits()-Config::nlayers_per_seed; - // protection against zero size tracks - if (mctrack.empty()) { - mcTrackID_ = -2; + // protect against tracks that never make it past the seed + if (nCandHits != 0) + { + // Require majority of hits to match + if (2*nHitsMatched >= nCandHits) mcTrackID_ = label; + else mcTrackID_ = -1; + + // Modify mcTrackID based on nMinHits + if (nCandHits < (Config::nMinFoundHits-Config::nlayers_per_seed)) + { + if (mcTrackID_ = label) mcTrackID_ = -2; + else mcTrackID_ = -3; + } + + nHitsMatched_ = nHitsMatched; // nHitsMatched + Config::nlayers_per_seed + fracHitsMatched_ = float(nHitsMatched_) / float(nCandHits); + } + else + { + mcTrackID_ = -4; nHitsMatched_ = 0; - return; + fracHitsMatched_ = 0.f; + } + + dprint("Track " << trk.label() << " parent mc track " << label << " matched id " << mcTrackID_ << " count " << nHitsMatched_ << "/" << nCandHits); +} + +// Generic 75% reco to sim matching --> for seeding or CMSSW-like building +void TrackExtra::setMCTrackIDInfo(const Track& trk, const std::vector& layerHits, const MCHitInfoVec& globalHitInfo, const TrackVec& simtracks) +{ + std::vector mcTrackIDs; + for (int ihit = 0; ihit < trk.nTotalHits(); ++ihit) + { + const int hitidx = trk.getHitIdx(ihit); + const int hitlyr = trk.getHitLyr(ihit); + if ((hitidx >= 0) && (hitidx < layerHits[hitlyr].size())) // make sure it is a real hit + { + const int mchitid = layerHits[hitlyr][hitidx].mcHitID(); + dprint("trk.label()=" << trk.label() << " ihit=" << ihit + << " trk.getHitIdx(ihit)=" << hitidx << "trk.getHitLyr(ihit)" << hitlyr + << " mchitid=" << mchitid << " globalHitInfo[mchitid].mcTrackID()=" << globalHitInfo[mchitid].mcTrackID()); + mcTrackIDs.push_back(globalHitInfo[mchitid].mcTrackID()); + } } - auto mtrk(mctrack[0]), m(mctrack[0]); + if (!mcTrackIDs.empty()) // protection against zero size tracks + { + // sorted list ensures that mcTrackIDs are counted properly + std::sort(mcTrackIDs.begin(), mcTrackIDs.end()); + int mccount = 0, tmpcount = 0; + int mcTrackID(mcTrackIDs[0]); + + for (int imcTrackID : mcTrackIDs) + { + if (imcTrackID == mcTrackID) { ++tmpcount; } else { tmpcount = 1; } + if (tmpcount >= mccount) { mcTrackID = imcTrackID; mccount = tmpcount; } + } + + // 75% matching criterion + if (4*mccount >= 3*trk.nFoundHits()) + { + const int nMinSimHits = simtracks[mcTrackID].nFoundHits() * Config::nMinSimHitsFrac; + const int minFoundHits = ((nMinSimHits >= Config::nMinFoundHits) ? Config::nMinFoundHits : nMinSimHits); - for (auto i : mctrack) { - if (i == m) { ++c; } else { c = 1; } - if (c >= mcount) { mtrk = m; mcount = c; } - m = i; + if (trk.nFoundHits() >= minFoundHits) mcTrackID_ = mcTrackID; + else mcTrackID_ = -2; + } + else mcTrackID_ = -1; + + nHitsMatched_ = mccount; + fracHitsMatched_ = float(nHitsMatched_) / float(trk.nFoundHits()); } - if (4*mcount > 3*trk.nFoundHits()){ // if more, matched track --> set id info - mcTrackID_ = mtrk; - nHitsMatched_ = mcount; - } else { // fake track, id = -1 - mcTrackID_ = -1; - nHitsMatched_ = mcount; + else + { + // zero size tracks --> should never happen... + mcTrackID_ = -5; + nHitsMatched_ = 0; + fracHitsMatched_ = 0.f; } - dprint("Track " << trk.label() << " best mc track " << mtrk << " count " << mcount << "/" << trk.nFoundHits()); + + dprint("Track " << trk.label() << " best mc track " << mcTrackID << " count " << mccount << "/" << trk.nFoundHits()); } //============================================================================== diff --git a/Track.h b/Track.h index 88ea7d08f6a05..89af3cfc3d92b 100644 --- a/Track.h +++ b/Track.h @@ -341,6 +341,8 @@ class Track int label_ = -1; }; +typedef std::vector TrackVec; + class TrackExtra { public: @@ -348,23 +350,25 @@ class TrackExtra TrackExtra(int seedID) : seedID_(seedID) {} int mcTrackID() const {return mcTrackID_;} int nHitsMatched() const {return nHitsMatched_;} + float fracHitsMatched() const {return fracHitsMatched_;} int seedID() const {return seedID_;} bool isDuplicate() const {return isDuplicate_;} int duplicateID() const {return duplicateID_;} - void setMCTrackIDInfo(const Track& trk, const std::vector& layerHits, const MCHitInfoVec& globalHitInfo); + void setMCTrackIDInfoByLabel(const Track& trk, const std::vector& layerHits, const MCHitInfoVec& globalHitInfo, const Track& simtrack); + void setMCTrackIDInfo(const Track& trk, const std::vector& layerHits, const MCHitInfoVec& globalHitInfo, const TrackVec& simtracks); void setMCDuplicateInfo(int duplicateID, bool isDuplicate) {duplicateID_ = duplicateID; isDuplicate_ = isDuplicate;} private: friend class Track; int mcTrackID_; int nHitsMatched_; + float fracHitsMatched_; int seedID_; int duplicateID_; bool isDuplicate_; }; typedef std::vector TrackExtraVec; -typedef std::vector TrackVec; typedef std::vector TSVec; typedef std::vector TkIDToTSVecVec; typedef std::vector > TSLayerPairVec; diff --git a/main.cc b/main.cc index 8f88afd338f97..f4bbcb5678767 100644 --- a/main.cc +++ b/main.cc @@ -179,6 +179,7 @@ int main(int argc, const char* argv[]) " --num-tracks number of tracks to generate for each event (def: %d)\n" " --num-thr number of threads used for TBB (def: %d)\n" " --root-val bool to enable normal validation (eff, FR, DR) (def: %s)\n" + " --short-fakes include short reco tracks into FR (def: %s)\n" " --cf-seeding bool to enable CF in MC seeding (def: %s)\n" " --read read input simtracks file (def: false)\n" " --file-name file name for write/read (def: %s)\n" @@ -190,6 +191,7 @@ int main(int argc, const char* argv[]) Config::nTracks, nThread, (Config::root_val ? "true" : "false"), + (Config::shortFakes ? "true" : "false"), (Config::cf_seeding ? "true" : "false"), s_file_name.c_str(), Config::readCmsswSeeds, @@ -214,7 +216,11 @@ int main(int argc, const char* argv[]) } else if (*i == "--root-val") { - Config::root_val = true; + Config::root_val = true; Config::fit_val = false; + } + else if (*i == "--short-fakes") + { + Config::shortFakes = true; } else if (*i == "--cf-seeding") { diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index 2f6604c50415b..19c3a580814d4 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -822,12 +822,12 @@ void MkBuilder::quality_store_tracks_COMB() void MkBuilder::quality_process(Track &tkcand) { - // XXXXMT4K - // TrackExtra extra(tkcand.label()); - // extra.setMCTrackIDInfo(tkcand, m_event->layerHits_, m_event->simHitsInfo_); - // int mctrk = extra.mcTrackID(); + TrackExtra extra(tkcand.label()); + if (Config::useCMSGeom || Config::findSeeds) {extra.setMCTrackIDInfo(tkcand, m_event->layerHits_, m_event->simHitsInfo_, m_event->simTracks_);} + else {extra.setMCTrackIDInfoByLabel(tkcand, m_event->layerHits_, m_event->simHitsInfo_, m_event->simTracks_[tkcand.label()]);} + int mctrk = extra.mcTrackID(); - int mctrk = tkcand.label(); + // int mctrk = tkcand.label(); // assumes 100% "efficiency" float pt = tkcand.pT(); float ptmc = 0., pr = 0., nfoundmc = 0., chi2mc = 0.; diff --git a/mkFit/mkFit.cc b/mkFit/mkFit.cc index 1139d82d9392e..cdf5447e48a25 100644 --- a/mkFit/mkFit.cc +++ b/mkFit/mkFit.cc @@ -422,6 +422,7 @@ void test_standard() } for (auto& val : vals) { + val->fillConfigTree(); val->saveTTrees(); } } @@ -495,6 +496,7 @@ int main(int argc, const char *argv[]) " --cf-fitting enable CF in fitting (def: %s)\n" " --root-val enable ROOT based validation for building [eff, FR, DR] (def: %s)\n" " --fit-val enable ROOT based validation for fitting (def: %s)\n" + " --short-fakes include short reco tracks into FR (def: %s)\n" " --silent suppress printouts inside event loop (def: %s)\n" " --write write simulation to file and exit\n" " --read read simulation from file\n" @@ -519,6 +521,7 @@ int main(int argc, const char *argv[]) Config::cf_fitting ? "true" : "false", Config::root_val ? "true" : "false", Config::fit_val ? "true" : "false", + Config::shortFakes ? "true" : "false", Config::silent ? "true" : "false", g_file_name.c_str(), g_input_file.c_str(), @@ -614,6 +617,10 @@ int main(int argc, const char *argv[]) { Config::root_val = false; Config::fit_val = true; } + else if (*i == "--short-fakes") + { + Config::shortFakes = true; + } else if (*i == "--num-thr-ev") { next_arg_or_die(mArgs, i); From 429b5be2754e89ea5aecd6403ba99cb66fb57d15 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Wed, 3 May 2017 12:59:11 -0700 Subject: [PATCH 029/172] add hits associated to tracks: all rechits are added --- tkNtuple/WriteMemoryFile.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tkNtuple/WriteMemoryFile.cc b/tkNtuple/WriteMemoryFile.cc index b2a0c0b9d3abf..2bd0d0e2a742c 100644 --- a/tkNtuple/WriteMemoryFile.cc +++ b/tkNtuple/WriteMemoryFile.cc @@ -494,10 +494,10 @@ int main() { err.At(0,1) = pix_xy->at(ipix); err.At(0,2) = pix_zx->at(ipix); err.At(1,2) = pix_yz->at(ipix); - if (simTkIdx>=0) simTracks_[simTkIdx].setHitIdx(ilay, layerHits_[ilay].size()); + if (simTkIdx>=0) simTracks_[simTkIdx].addHitIdx(layerHits_[ilay].size(), ilay, -1);//chi2 -1 to self-check (sim init chi2=nhits) for (int is=0;isSetBranchAddress("evt",&evt); + int event; + t->SetBranchAddress("event",&event); //sim tracks std::vector* sim_eta = 0; std::vector* sim_px = 0; std::vector* sim_py = 0; std::vector* sim_pz = 0; - std::vector* sim_prodx = 0; - std::vector* sim_prody = 0; - std::vector* sim_prodz = 0; + std::vector* sim_parentVtxIdx = 0; std::vector* sim_q = 0; - std::vector >* sim_pixelIdx = 0; - std::vector >* sim_stripIdx = 0; std::vector* sim_trkIdx = 0; t->SetBranchAddress("sim_eta",&sim_eta); t->SetBranchAddress("sim_px",&sim_px); t->SetBranchAddress("sim_py",&sim_py); t->SetBranchAddress("sim_pz",&sim_pz); - t->SetBranchAddress("sim_prodx",&sim_prodx); - t->SetBranchAddress("sim_prody",&sim_prody); - t->SetBranchAddress("sim_prodz",&sim_prodz); + t->SetBranchAddress("sim_parentVtxIdx",&sim_parentVtxIdx); t->SetBranchAddress("sim_q",&sim_q); - t->SetBranchAddress("sim_pixelIdx",&sim_pixelIdx); - t->SetBranchAddress("sim_stripIdx",&sim_stripIdx); t->SetBranchAddress("sim_trkIdx",&sim_trkIdx); + //simvtx + std::vector* simvtx_x; + std::vector* simvtx_y; + std::vector* simvtx_z; + t->SetBranchAddress("simvtx_x" , &simvtx_x); + t->SetBranchAddress("simvtx_y" , &simvtx_y); + t->SetBranchAddress("simvtx_z" , &simvtx_z); + + //rec tracks std::vector* trk_nValid = 0; std::vector* trk_nInvalid = 0; @@ -355,17 +356,25 @@ int main() { t->GetEntry(i); - cout << "edm event=" << evt << endl; + cout << "edm event=" << event << endl; + - if (sim_q->size()==0) { + auto nSims = sim_q->size(); + if (nSims==0) { cout << "branches not loaded" << endl; exit(1); } - + vector simTracks_; vector simTrackIdx_(sim_q->size(),-1);//keep track of original index in ntuple vector seedSimIdx(see_x->size(),-1); for (int isim = 0; isim < sim_q->size(); ++isim) { + //load sim production vertex data + auto iVtx = sim_parentVtxIdx->at(isim); + constexpr float largeValF = 9999.f; + float sim_prodx = iVtx >= 0 ? simvtx_x->at(iVtx) : largeValF; + float sim_prody = iVtx >= 0 ? simvtx_y->at(iVtx) : largeValF; + float sim_prodz = iVtx >= 0 ? simvtx_z->at(iVtx) : largeValF; //if (fabs(sim_eta->at(isim))>0.8) continue; int trkIdx = sim_trkIdx->at(isim); @@ -397,14 +406,14 @@ int main() { for (int i=0;i0) nlay++; } - //cout << Form("track q=%2i p=(%6.3f, %6.3f, %6.3f) x=(%6.3f, %6.3f, %6.3f) nlay=%i",sim_q->at(isim),sim_px->at(isim),sim_py->at(isim),sim_pz->at(isim),sim_prodx->at(isim),sim_prody->at(isim),sim_prodz->at(isim),nlay) << endl; + //cout << Form("track q=%2i p=(%6.3f, %6.3f, %6.3f) x=(%6.3f, %6.3f, %6.3f) nlay=%i",sim_q->at(isim),sim_px->at(isim),sim_py->at(isim),sim_pz->at(isim),sim_prodx,sim_prody,sim_prodz,nlay) << endl; - SVector3 pos(sim_prodx->at(isim),sim_prody->at(isim),sim_prodz->at(isim)); + SVector3 pos(sim_prodx,sim_prody,sim_prodz); SVector3 mom(sim_px->at(isim),sim_py->at(isim),sim_pz->at(isim)); SMatrixSym66 err; - err.At(0,0) = sim_prodx->at(isim)*sim_prodx->at(isim); - err.At(1,1) = sim_prody->at(isim)*sim_prody->at(isim); - err.At(2,2) = sim_prodz->at(isim)*sim_prodz->at(isim); + err.At(0,0) = sim_prodx*sim_prodx; + err.At(1,1) = sim_prody*sim_prody; + err.At(2,2) = sim_prodz*sim_prodz; err.At(3,3) = sim_px->at(isim)*sim_px->at(isim); err.At(4,4) = sim_py->at(isim)*sim_py->at(isim); err.At(5,5) = sim_pz->at(isim)*sim_pz->at(isim); From 321f56366c3bb7191f15b81e46646a5f17bd6c74 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Wed, 3 May 2017 15:26:16 -0700 Subject: [PATCH 031/172] sim_trkIdx is now a vector per sim --- tkNtuple/WriteMemoryFile.cc | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tkNtuple/WriteMemoryFile.cc b/tkNtuple/WriteMemoryFile.cc index 243b5dc4ed952..ac7793c8f7779 100644 --- a/tkNtuple/WriteMemoryFile.cc +++ b/tkNtuple/WriteMemoryFile.cc @@ -139,7 +139,7 @@ int main() { std::vector* sim_pz = 0; std::vector* sim_parentVtxIdx = 0; std::vector* sim_q = 0; - std::vector* sim_trkIdx = 0; + std::vector >* sim_trkIdx = 0; t->SetBranchAddress("sim_eta",&sim_eta); t->SetBranchAddress("sim_px",&sim_px); t->SetBranchAddress("sim_py",&sim_py); @@ -377,12 +377,16 @@ int main() { float sim_prodz = iVtx >= 0 ? simvtx_z->at(iVtx) : largeValF; //if (fabs(sim_eta->at(isim))>0.8) continue; - int trkIdx = sim_trkIdx->at(isim); + vector const& trkIdxV = sim_trkIdx->at(isim); //if (trkIdx<0) continue; + //FIXME: CHECK IF THE LOOP AND BEST SELECTION IS NEEDED. + //Pick the first + const int trkIdx = trkIdxV.empty() ? -1 : trkIdxV[0]; + int nlay = 0; - std::vector hitlay(nTotalLayers, 0); - if (trkIdx>=0) { + if (trkIdx>=0) { + std::vector hitlay(nTotalLayers, 0); for (int ihit = 0; ihit < trk_pixelIdx->at(trkIdx).size(); ++ihit) { int ipix = trk_pixelIdx->at(trkIdx).at(ihit); if (ipix<0) continue; @@ -404,7 +408,7 @@ int main() { if (cmsswlay>=0 && cmsswlay0) nlay++; - } + }//count nlay layers on matching reco track //cout << Form("track q=%2i p=(%6.3f, %6.3f, %6.3f) x=(%6.3f, %6.3f, %6.3f) nlay=%i",sim_q->at(isim),sim_px->at(isim),sim_py->at(isim),sim_pz->at(isim),sim_prodx,sim_prody,sim_prodz,nlay) << endl; From 9352d3f6525f9df44a599531887f7f01d838497b Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Wed, 3 May 2017 15:28:34 -0700 Subject: [PATCH 032/172] do not add chi2 per simtrack hit --- tkNtuple/WriteMemoryFile.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tkNtuple/WriteMemoryFile.cc b/tkNtuple/WriteMemoryFile.cc index ac7793c8f7779..bc555fa806859 100644 --- a/tkNtuple/WriteMemoryFile.cc +++ b/tkNtuple/WriteMemoryFile.cc @@ -507,7 +507,7 @@ int main() { err.At(0,1) = pix_xy->at(ipix); err.At(0,2) = pix_zx->at(ipix); err.At(1,2) = pix_yz->at(ipix); - if (simTkIdx>=0) simTracks_[simTkIdx].addHitIdx(layerHits_[ilay].size(), ilay, -1);//chi2 -1 to self-check (sim init chi2=nhits) + if (simTkIdx>=0) simTracks_[simTkIdx].addHitIdx(layerHits_[ilay].size(), ilay, 0); for (int is=0;isSetBranchAddress("trk_nInvalid",&trk_nInvalid); - t->SetBranchAddress("trk_nLay",&trk_nLay); - t->SetBranchAddress("trk_seedIdx",&trk_seedIdx); - t->SetBranchAddress("trk_pixelIdx",&trk_pixelIdx); - t->SetBranchAddress("trk_stripIdx",&trk_stripIdx); - t->SetBranchAddress("trk_gluedIdx",&trk_gluedIdx); + std::vector* trk_nValid = 0; + std::vector* trk_nInvalid = 0; + std::vector* trk_seedIdx = 0; + std::vector >* trk_hitIdx = 0; + std::vector >* trk_hitType = 0; + t->SetBranchAddress("trk_nValid", &trk_nValid); + t->SetBranchAddress("trk_nInvalid", &trk_nInvalid); + t->SetBranchAddress("trk_seedIdx", &trk_seedIdx); + t->SetBranchAddress("trk_hitIdx", &trk_hitIdx); + t->SetBranchAddress("trk_hitType", &trk_hitType); //seeds std::vector* see_x = 0; @@ -240,7 +247,7 @@ int main() { t->SetBranchAddress("see_pixelIdx",&see_pixelIdx); //pixel hits - vector* pix_isBarrel = 0; + vector* pix_det = 0; vector* pix_lay = 0; vector* pix_simTrkIdx = 0; vector* pix_particle = 0; @@ -256,7 +263,7 @@ int main() { vector* pix_yz = 0; vector* pix_zz = 0; vector* pix_zx = 0; - t->SetBranchAddress("pix_isBarrel",&pix_isBarrel); + t->SetBranchAddress("pix_det",&pix_det); t->SetBranchAddress("pix_lay",&pix_lay); t->SetBranchAddress("pix_simTrkIdx",&pix_simTrkIdx); t->SetBranchAddress("pix_particle",&pix_particle); @@ -387,26 +394,41 @@ int main() { int nlay = 0; if (trkIdx>=0) { std::vector hitlay(nTotalLayers, 0); - for (int ihit = 0; ihit < trk_pixelIdx->at(trkIdx).size(); ++ihit) { - int ipix = trk_pixelIdx->at(trkIdx).at(ihit); - if (ipix<0) continue; - int cmsswlay = lnc.convertLayerNumber((pix_isBarrel->at(ipix)?1:2),pix_lay->at(ipix),useMatched,-1,pix_z->at(ipix)>0); - if (cmsswlay>=0 && cmsswlayat(trkIdx).size(); ++ihit) { - int iglu = trk_gluedIdx->at(trkIdx).at(ihit); - if (iglu<0) continue; - int cmsswlay = lnc.convertLayerNumber(glu_det->at(iglu),glu_lay->at(iglu),useMatched,-1,glu_z->at(iglu)>0); - if (cmsswlay>=0 && cmsswlayat(trkIdx); + auto const& hitTypes = trk_hitType->at(trkIdx); + auto nHits = hits.size(); + for (auto ihit = 0U; ihit< nHits; ++ihit){ + auto ihIdx = hits[ihit]; + auto const ihType = HitType(hitTypes[ihit]); + + switch (ihType){ + case HitType::Pixel:{ + int ipix = ihIdx; + if (ipix<0) continue; + int cmsswlay = lnc.convertLayerNumber(pix_det->at(ipix),pix_lay->at(ipix),useMatched,-1,pix_z->at(ipix)>0); + if (cmsswlay>=0 && cmsswlayat(trkIdx).size(); ++ihit) { - int istr = trk_stripIdx->at(trkIdx).at(ihit); - if (istr<0) continue; - int cmsswlay = lnc.convertLayerNumber(str_det->at(istr),str_lay->at(istr),useMatched,str_isStereo->at(istr),str_z->at(istr)>0); - if (cmsswlay>=0 && cmsswlayat(istr),str_lay->at(istr),useMatched,str_isStereo->at(istr),str_z->at(istr)>0); + if (cmsswlay>=0 && cmsswlayat(iglu),glu_lay->at(iglu),useMatched,-1,glu_z->at(iglu)>0); + if (cmsswlay>=0 && cmsswlay0) nlay++; }//count nlay layers on matching reco track @@ -494,11 +516,11 @@ int main() { layerHits_.resize(nTotalLayers); for (int ipix = 0; ipix < pix_lay->size(); ++ipix) { int ilay = -1; - ilay = lnc.convertLayerNumber((pix_isBarrel->at(ipix)?1:2),pix_lay->at(ipix),useMatched,-1,pix_z->at(ipix)>0); + ilay = lnc.convertLayerNumber(pix_det->at(ipix),pix_lay->at(ipix),useMatched,-1,pix_z->at(ipix)>0); if (ilay<0) continue; int simTkIdx = -1; if (pix_simTrkIdx->at(ipix)>=0) simTkIdx = simTrackIdx_[pix_simTrkIdx->at(ipix)]; - //cout << Form("pix lay=%i bar=%i x=(%6.3f, %6.3f, %6.3f)",ilay+1,pix_isBarrel->at(ipix),pix_x->at(ipix),pix_y->at(ipix),pix_z->at(ipix)) << endl; + //cout << Form("pix lay=%i det=%i x=(%6.3f, %6.3f, %6.3f)",ilay+1,pix_det->at(ipix),pix_x->at(ipix),pix_y->at(ipix),pix_z->at(ipix)) << endl; SVector3 pos(pix_x->at(ipix),pix_y->at(ipix),pix_z->at(ipix)); SMatrixSym33 err; err.At(0,0) = pix_xx->at(ipix); From ed2a30cea92c0f128b6709e22bd673f4f0c7ae33 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Wed, 3 May 2017 18:57:41 -0700 Subject: [PATCH 034/172] see_ updates: changed names for seed startingState() in global coordinates; hitIdx is generic; algo is unsigned. Count seed pixel hits for initialStep seeds with at least 3 hits to cover both phase-0 and phase-1. --- tkNtuple/WriteMemoryFile.cc | 202 ++++++++++++++++++++---------------- 1 file changed, 113 insertions(+), 89 deletions(-) diff --git a/tkNtuple/WriteMemoryFile.cc b/tkNtuple/WriteMemoryFile.cc index 1bc49c945afda..861c8a168b28a 100644 --- a/tkNtuple/WriteMemoryFile.cc +++ b/tkNtuple/WriteMemoryFile.cc @@ -14,6 +14,24 @@ enum class HitType { Unknown = 99 }; +/// track algorithm; partial copy from TrackBase.h +enum class TrackAlgorithm { + undefAlgorithm = 0, + ctf = 1, + duplicateMerge = 2, + cosmics = 3, + initialStep = 4, + lowPtTripletStep = 5, + pixelPairStep = 6, + detachedTripletStep = 7, + mixedTripletStep = 8, + pixelLessStep = 9, + tobTecStep = 10, + jetCoreRegionalStep = 11, + conversionStep = 12, + muonSeededStepInOut = 13, + muonSeededStepOutIn = 14 +}; class LayerNumberConverter { public: @@ -181,70 +199,72 @@ int main() { t->SetBranchAddress("trk_hitType", &trk_hitType); //seeds - std::vector* see_x = 0; - std::vector* see_y = 0; - std::vector* see_z = 0; - std::vector* see_px = 0; - std::vector* see_py = 0; - std::vector* see_pz = 0; - std::vector* see_eta= 0; - std::vector* see_pt = 0; - std::vector* see_cov00 = 0; - std::vector* see_cov01 = 0; - std::vector* see_cov02 = 0; - std::vector* see_cov03 = 0; - std::vector* see_cov04 = 0; - std::vector* see_cov05 = 0; - std::vector* see_cov11 = 0; - std::vector* see_cov12 = 0; - std::vector* see_cov13 = 0; - std::vector* see_cov14 = 0; - std::vector* see_cov15 = 0; - std::vector* see_cov22 = 0; - std::vector* see_cov23 = 0; - std::vector* see_cov24 = 0; - std::vector* see_cov25 = 0; - std::vector* see_cov33 = 0; - std::vector* see_cov34 = 0; - std::vector* see_cov35 = 0; - std::vector* see_cov44 = 0; - std::vector* see_cov45 = 0; - std::vector* see_cov55 = 0; + std::vector* see_stateTrajGlbX = 0; + std::vector* see_stateTrajGlbY = 0; + std::vector* see_stateTrajGlbZ = 0; + std::vector* see_stateTrajGlbPx = 0; + std::vector* see_stateTrajGlbPy = 0; + std::vector* see_stateTrajGlbPz = 0; + std::vector* see_eta= 0;//PCA parameters + std::vector* see_pt = 0;//PCA parameters + std::vector* see_stateCcov00 = 0; + std::vector* see_stateCcov01 = 0; + std::vector* see_stateCcov02 = 0; + std::vector* see_stateCcov03 = 0; + std::vector* see_stateCcov04 = 0; + std::vector* see_stateCcov05 = 0; + std::vector* see_stateCcov11 = 0; + std::vector* see_stateCcov12 = 0; + std::vector* see_stateCcov13 = 0; + std::vector* see_stateCcov14 = 0; + std::vector* see_stateCcov15 = 0; + std::vector* see_stateCcov22 = 0; + std::vector* see_stateCcov23 = 0; + std::vector* see_stateCcov24 = 0; + std::vector* see_stateCcov25 = 0; + std::vector* see_stateCcov33 = 0; + std::vector* see_stateCcov34 = 0; + std::vector* see_stateCcov35 = 0; + std::vector* see_stateCcov44 = 0; + std::vector* see_stateCcov45 = 0; + std::vector* see_stateCcov55 = 0; std::vector* see_q = 0; - std::vector* see_algo = 0; - std::vector >* see_pixelIdx = 0; - t->SetBranchAddress("see_x",&see_x); - t->SetBranchAddress("see_y",&see_y); - t->SetBranchAddress("see_z",&see_z); - t->SetBranchAddress("see_px",&see_px); - t->SetBranchAddress("see_py",&see_py); - t->SetBranchAddress("see_pz",&see_pz); + std::vector* see_algo = 0; + std::vector >* see_hitIdx = 0; + std::vector >* see_hitType = 0; + t->SetBranchAddress("see_stateTrajGlbX",&see_stateTrajGlbX); + t->SetBranchAddress("see_stateTrajGlbY",&see_stateTrajGlbY); + t->SetBranchAddress("see_stateTrajGlbZ",&see_stateTrajGlbZ); + t->SetBranchAddress("see_stateTrajGlbPx",&see_stateTrajGlbPx); + t->SetBranchAddress("see_stateTrajGlbPy",&see_stateTrajGlbPy); + t->SetBranchAddress("see_stateTrajGlbPz",&see_stateTrajGlbPz); t->SetBranchAddress("see_eta",&see_eta); t->SetBranchAddress("see_pt",&see_pt); - t->SetBranchAddress("see_cov00",&see_cov00); - t->SetBranchAddress("see_cov01",&see_cov01); - t->SetBranchAddress("see_cov02",&see_cov02); - t->SetBranchAddress("see_cov03",&see_cov03); - t->SetBranchAddress("see_cov04",&see_cov04); - t->SetBranchAddress("see_cov05",&see_cov05); - t->SetBranchAddress("see_cov11",&see_cov11); - t->SetBranchAddress("see_cov12",&see_cov12); - t->SetBranchAddress("see_cov13",&see_cov13); - t->SetBranchAddress("see_cov14",&see_cov14); - t->SetBranchAddress("see_cov15",&see_cov15); - t->SetBranchAddress("see_cov22",&see_cov22); - t->SetBranchAddress("see_cov23",&see_cov23); - t->SetBranchAddress("see_cov24",&see_cov24); - t->SetBranchAddress("see_cov25",&see_cov25); - t->SetBranchAddress("see_cov33",&see_cov33); - t->SetBranchAddress("see_cov34",&see_cov34); - t->SetBranchAddress("see_cov35",&see_cov35); - t->SetBranchAddress("see_cov44",&see_cov44); - t->SetBranchAddress("see_cov45",&see_cov45); - t->SetBranchAddress("see_cov55",&see_cov55); + t->SetBranchAddress("see_stateCcov00",&see_stateCcov00); + t->SetBranchAddress("see_stateCcov01",&see_stateCcov01); + t->SetBranchAddress("see_stateCcov02",&see_stateCcov02); + t->SetBranchAddress("see_stateCcov03",&see_stateCcov03); + t->SetBranchAddress("see_stateCcov04",&see_stateCcov04); + t->SetBranchAddress("see_stateCcov05",&see_stateCcov05); + t->SetBranchAddress("see_stateCcov11",&see_stateCcov11); + t->SetBranchAddress("see_stateCcov12",&see_stateCcov12); + t->SetBranchAddress("see_stateCcov13",&see_stateCcov13); + t->SetBranchAddress("see_stateCcov14",&see_stateCcov14); + t->SetBranchAddress("see_stateCcov15",&see_stateCcov15); + t->SetBranchAddress("see_stateCcov22",&see_stateCcov22); + t->SetBranchAddress("see_stateCcov23",&see_stateCcov23); + t->SetBranchAddress("see_stateCcov24",&see_stateCcov24); + t->SetBranchAddress("see_stateCcov25",&see_stateCcov25); + t->SetBranchAddress("see_stateCcov33",&see_stateCcov33); + t->SetBranchAddress("see_stateCcov34",&see_stateCcov34); + t->SetBranchAddress("see_stateCcov35",&see_stateCcov35); + t->SetBranchAddress("see_stateCcov44",&see_stateCcov44); + t->SetBranchAddress("see_stateCcov45",&see_stateCcov45); + t->SetBranchAddress("see_stateCcov55",&see_stateCcov55); t->SetBranchAddress("see_q",&see_q); t->SetBranchAddress("see_algo",&see_algo); - t->SetBranchAddress("see_pixelIdx",&see_pixelIdx); + t->SetBranchAddress("see_hitIdx",&see_hitIdx); + t->SetBranchAddress("see_hitType",&see_hitType); //pixel hits vector* pix_det = 0; @@ -373,7 +393,7 @@ int main() { vector simTracks_; vector simTrackIdx_(sim_q->size(),-1);//keep track of original index in ntuple - vector seedSimIdx(see_x->size(),-1); + vector seedSimIdx(see_q->size(),-1); for (int isim = 0; isim < sim_q->size(); ++isim) { //load sim production vertex data @@ -452,7 +472,8 @@ int main() { Track track(state, float(nlay), isim, 0, nullptr);//store number of reco hits in place of track chi2; fill hits later if (trkIdx>=0) { int seedIdx = trk_seedIdx->at(trkIdx); - if (see_pixelIdx->at(seedIdx).size()!=0) { + auto const& shTypes = see_hitType->at(seedIdx); + if (std::count(shTypes.begin(), shTypes.end(), int(HitType::Pixel)) > 0) { seedSimIdx[seedIdx] = simTracks_.size(); } } @@ -465,33 +486,33 @@ int main() { vector seedTracks_; vector > pixHitSeedIdx(pix_lay->size()); - for (int is = 0; issize(); ++is) { - if (see_algo->at(is)!=4) continue;//select seed in acceptance + for (int is = 0; issize(); ++is) { + if (TrackAlgorithm(see_algo->at(is))!=TrackAlgorithm::initialStep) continue;//select seed in acceptance //if (see_pt->at(is)<0.5 || fabs(see_eta->at(is))>0.8) continue;//select seed in acceptance - SVector3 pos = SVector3(see_x->at(is),see_y->at(is),see_z->at(is)); - SVector3 mom = SVector3(see_px->at(is),see_py->at(is),see_pz->at(is)); + SVector3 pos = SVector3(see_stateTrajGlbX->at(is),see_stateTrajGlbY->at(is),see_stateTrajGlbZ->at(is)); + SVector3 mom = SVector3(see_stateTrajGlbPx->at(is),see_stateTrajGlbPy->at(is),see_stateTrajGlbPz->at(is)); SMatrixSym66 err; - err.At(0,0) = see_cov00->at(is); - err.At(0,1) = see_cov01->at(is); - err.At(0,2) = see_cov02->at(is); - err.At(0,3) = see_cov03->at(is); - err.At(0,4) = see_cov04->at(is); - err.At(0,5) = see_cov05->at(is); - err.At(1,1) = see_cov11->at(is); - err.At(1,2) = see_cov12->at(is); - err.At(1,3) = see_cov13->at(is); - err.At(1,4) = see_cov14->at(is); - err.At(1,5) = see_cov15->at(is); - err.At(2,2) = see_cov22->at(is); - err.At(2,3) = see_cov23->at(is); - err.At(2,4) = see_cov24->at(is); - err.At(2,5) = see_cov25->at(is); - err.At(3,3) = see_cov33->at(is); - err.At(3,4) = see_cov34->at(is); - err.At(3,5) = see_cov35->at(is); - err.At(4,4) = see_cov44->at(is); - err.At(4,5) = see_cov45->at(is); - err.At(5,5) = see_cov55->at(is); + err.At(0,0) = see_stateCcov00->at(is); + err.At(0,1) = see_stateCcov01->at(is); + err.At(0,2) = see_stateCcov02->at(is); + err.At(0,3) = see_stateCcov03->at(is); + err.At(0,4) = see_stateCcov04->at(is); + err.At(0,5) = see_stateCcov05->at(is); + err.At(1,1) = see_stateCcov11->at(is); + err.At(1,2) = see_stateCcov12->at(is); + err.At(1,3) = see_stateCcov13->at(is); + err.At(1,4) = see_stateCcov14->at(is); + err.At(1,5) = see_stateCcov15->at(is); + err.At(2,2) = see_stateCcov22->at(is); + err.At(2,3) = see_stateCcov23->at(is); + err.At(2,4) = see_stateCcov24->at(is); + err.At(2,5) = see_stateCcov25->at(is); + err.At(3,3) = see_stateCcov33->at(is); + err.At(3,4) = see_stateCcov34->at(is); + err.At(3,5) = see_stateCcov35->at(is); + err.At(4,4) = see_stateCcov44->at(is); + err.At(4,5) = see_stateCcov45->at(is); + err.At(5,5) = see_stateCcov55->at(is); TrackState state(see_q->at(is), pos, mom, err); #ifdef CCSCOORD //begin test CCS coordinates @@ -499,9 +520,12 @@ int main() { //end test CCS coordinates #endif Track track(state, 0, seedSimIdx[is], 0, nullptr); - if (see_pixelIdx->at(is).size()!=3) continue;//only seeds with 3 pixel hits - for (int ip=0; ipat(is).size(); ip++) { - unsigned int ipix = see_pixelIdx->at(is)[ip]; + auto const& shTypes = see_hitType->at(is); + auto const& shIdxs = see_hitIdx->at(is); + if (! (TrackAlgorithm(see_algo->at(is))!= TrackAlgorithm::initialStep + && std::count(shTypes.begin(), shTypes.end(), int(HitType::Pixel))>=3)) continue;//check algo and nhits + for (int ip=0; ip >+ ; +#ifdef G__VECTOR_HAS_CLASS_ITERATOR +#pragma link C++ operators vector >::iterator; +#pragma link C++ operators vector >::const_iterator; +#pragma link C++ operators vector >::reverse_iterator; +#endif +#endif diff --git a/tkNtuple/Makefile b/tkNtuple/Makefile index f3c8d6023d051..6cb9a134a0043 100644 --- a/tkNtuple/Makefile +++ b/tkNtuple/Makefile @@ -1,3 +1,4 @@ +include ../Makefile.config .PHONY: all clean distclean echo @@ -15,14 +16,14 @@ CXXFLAGS += ${USER_CXXFLAGS} LDFLAGS += $(shell root-config --ldflags --cflags --libs) ${LDEXTRA} -TGTS := writeMemoryFile +TGTS := writeMemoryFile libDicts.so EXES := ${TGTS} default: ${EXES} clean: - rm -f ${EXES} *.d *.o *.om + rm -f ${EXES} *.d *.o *.om *.so *Dict.* *.pcm rm -rf writeMemoryFile.dSYM distclean: clean @@ -49,12 +50,18 @@ SRCS := $(wildcard *.cc) HDRS := $(wildcard *.h) OBJS := $(SRCS:.cc=.o) +OBJS := $(filter-out DictsDict.o, $(OBJS)) ALLOBJS := ${OBJS} ${ABOVE_OBJS} +libDicts.so: DictsDict.cc + ${CXX} $(LDFLAGS) -Wno-deprecated -shared DictsDict.cc -o $@ -writeMemoryFile: ${OBJS} - ${CXX} ${CXXFLAGS} ${LDFLAGS} ${ALLOBJS} -o $@ +DictsDict.cc: + @rootcint -v3 -f DictsDict.cc -c -p DictsLinkDef.h + +writeMemoryFile: ${OBJS} libDicts.so + ${CXX} ${CXXFLAGS} ${LDFLAGS} ${ALLOBJS} -L./ -lDicts -o $@ ${OBJS}: %.o: %.cc From 11bf39b0daca1e664b03152e213a7bffe824feba Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Thu, 4 May 2017 21:04:11 -0700 Subject: [PATCH 036/172] maxhits to 42 .. need to iterate --- Config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Config.h b/Config.h index 36f527c15705b..94c710c2fd9a2 100644 --- a/Config.h +++ b/Config.h @@ -47,7 +47,7 @@ namespace Config // XXXX This needs to be generalized for other geometries ! // TrackerInfo more or less has all this information (or could have it). constexpr int nTotalLayers = 28; - constexpr int nMaxSimHits = 19; // Assuming dual hit on every barrel / endcap edge + constexpr int nMaxSimHits = 42; // Assuming dual hit on every barrel / endcap edge constexpr int nMaxRecHits = 10; // Assuming single hit on each layer constexpr int nMaxTrkHits = nMaxSimHits; // Used for array sizes in MkFitter and Track From 8946731cccde299d04e9941daca735c61d1b195f Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Thu, 4 May 2017 21:06:14 -0700 Subject: [PATCH 037/172] simHit - simTrack indexing in place ; lots of debugs to cleanup; apparently works in some way --- tkNtuple/WriteMemoryFile.cc | 187 +++++++++++++++++++++++------------- 1 file changed, 121 insertions(+), 66 deletions(-) diff --git a/tkNtuple/WriteMemoryFile.cc b/tkNtuple/WriteMemoryFile.cc index 861c8a168b28a..9f0f46a342f8c 100644 --- a/tkNtuple/WriteMemoryFile.cc +++ b/tkNtuple/WriteMemoryFile.cc @@ -1,7 +1,9 @@ -#include "Track.h" #include "TFile.h" #include "TTree.h" +#include +#include "Track.h" + enum struct TkLayout {phase0 = 0, phase1 = 1}; //check if this is the same as in the release @@ -76,6 +78,7 @@ class LayerNumberConverter { if (cmsswdet==5 && cmsswlay==6 && isStereo==0 ) return 12+lOffset; return -1; } else { + //FIXME: OLD stereo/mono layer is used here //TIB if (cmsswdet==3 && cmsswlay==1 && isStereo==0) return 3+lOffset; if (cmsswdet==3 && cmsswlay==1 && isStereo==1) return 4+lOffset; @@ -151,16 +154,16 @@ int main() { TString outfilename = ""; - TFile* f = TFile::Open("./ntuple_input.root"); maxevt = 3000;outfilename = "cmssw_output.bin"; + TFile* f = TFile::Open("./ntuple_input.root"); maxevt = 1;outfilename = "cmssw_output.bin"; - TTree* t = (TTree*) f->Get("trkTree/tree"); + TTree* t = (TTree*) f->Get("trackingNtuple/tree"); FILE * fp; fp = fopen (outfilename.Data(), "wb"); - int event; + unsigned long long event; t->SetBranchAddress("event",&event); - + //sim tracks std::vector* sim_eta = 0; std::vector* sim_px = 0; @@ -168,14 +171,15 @@ int main() { std::vector* sim_pz = 0; std::vector* sim_parentVtxIdx = 0; std::vector* sim_q = 0; - std::vector >* sim_trkIdx = 0; t->SetBranchAddress("sim_eta",&sim_eta); t->SetBranchAddress("sim_px",&sim_px); t->SetBranchAddress("sim_py",&sim_py); t->SetBranchAddress("sim_pz",&sim_pz); t->SetBranchAddress("sim_parentVtxIdx",&sim_parentVtxIdx); t->SetBranchAddress("sim_q",&sim_q); - t->SetBranchAddress("sim_trkIdx",&sim_trkIdx); + + std::vector >* sim_trkIdx = 0; + t->SetBranchAddress("sim_trkIdx", &sim_trkIdx); //simvtx std::vector* simvtx_x; @@ -185,18 +189,31 @@ int main() { t->SetBranchAddress("simvtx_y" , &simvtx_y); t->SetBranchAddress("simvtx_z" , &simvtx_z); + + //simhit + std::vector* simhit_process; + std::vector* simhit_simTrkIdx; + std::vector* simhit_px; + std::vector* simhit_py; + std::vector* simhit_pz; + t->SetBranchAddress("simhit_process", &simhit_process); + t->SetBranchAddress("simhit_simTrkIdx", &simhit_simTrkIdx); + t->SetBranchAddress("simhit_px", &simhit_px); + t->SetBranchAddress("simhit_py", &simhit_py); + t->SetBranchAddress("simhit_pz", &simhit_pz); //rec tracks std::vector* trk_nValid = 0; std::vector* trk_nInvalid = 0; std::vector* trk_seedIdx = 0; - std::vector >* trk_hitIdx = 0; - std::vector >* trk_hitType = 0; t->SetBranchAddress("trk_nValid", &trk_nValid); t->SetBranchAddress("trk_nInvalid", &trk_nInvalid); t->SetBranchAddress("trk_seedIdx", &trk_seedIdx); - t->SetBranchAddress("trk_hitIdx", &trk_hitIdx); - t->SetBranchAddress("trk_hitType", &trk_hitType); + + std::vector >* trk_hitIdx = 0; + t->SetBranchAddress("trk_hitIdx", &trk_hitIdx); + std::vector >* trk_hitType = 0; + t->SetBranchAddress("trk_hitType", &trk_hitType); //seeds std::vector* see_stateTrajGlbX = 0; @@ -230,8 +247,6 @@ int main() { std::vector* see_stateCcov55 = 0; std::vector* see_q = 0; std::vector* see_algo = 0; - std::vector >* see_hitIdx = 0; - std::vector >* see_hitType = 0; t->SetBranchAddress("see_stateTrajGlbX",&see_stateTrajGlbX); t->SetBranchAddress("see_stateTrajGlbY",&see_stateTrajGlbY); t->SetBranchAddress("see_stateTrajGlbZ",&see_stateTrajGlbZ); @@ -263,17 +278,15 @@ int main() { t->SetBranchAddress("see_stateCcov55",&see_stateCcov55); t->SetBranchAddress("see_q",&see_q); t->SetBranchAddress("see_algo",&see_algo); - t->SetBranchAddress("see_hitIdx",&see_hitIdx); - t->SetBranchAddress("see_hitType",&see_hitType); + + std::vector >* see_hitIdx = 0; + t->SetBranchAddress("see_hitIdx", &see_hitIdx); + std::vector >* see_hitType = 0; + t->SetBranchAddress("see_hitType", &see_hitType); //pixel hits - vector* pix_det = 0; - vector* pix_lay = 0; - vector* pix_simTrkIdx = 0; - vector* pix_particle = 0; - vector* pix_process = 0; - vector* pix_posFromTrack = 0; - vector* pix_onTrack = 0; + vector* pix_det = 0; + vector* pix_lay = 0; vector* pix_x = 0; vector* pix_y = 0; vector* pix_z = 0; @@ -285,11 +298,6 @@ int main() { vector* pix_zx = 0; t->SetBranchAddress("pix_det",&pix_det); t->SetBranchAddress("pix_lay",&pix_lay); - t->SetBranchAddress("pix_simTrkIdx",&pix_simTrkIdx); - t->SetBranchAddress("pix_particle",&pix_particle); - t->SetBranchAddress("pix_process",&pix_process); - t->SetBranchAddress("pix_posFromTrack",&pix_posFromTrack); - t->SetBranchAddress("pix_onTrack",&pix_onTrack); t->SetBranchAddress("pix_x",&pix_x); t->SetBranchAddress("pix_y",&pix_y); t->SetBranchAddress("pix_z",&pix_z); @@ -300,14 +308,15 @@ int main() { t->SetBranchAddress("pix_zz",&pix_zz); t->SetBranchAddress("pix_zx",&pix_zx); + vector >* pix_simHitIdx = 0; + t->SetBranchAddress("pix_simHitIdx", &pix_simHitIdx); + //strip hits + vector* glu_isBarrel = 0; + vector* glu_det = 0; + vector* glu_lay = 0; vector* glu_monoIdx = 0; vector* glu_stereoIdx = 0; - vector* glu_isBarrel = 0; - vector* glu_lay = 0; - vector* glu_det = 0; - vector* glu_posFromTrack = 0; - vector* glu_onTrack = 0; vector* glu_x = 0; vector* glu_y = 0; vector* glu_z = 0; @@ -318,13 +327,11 @@ int main() { vector* glu_zz = 0; vector* glu_zx = 0; if (useMatched) { - t->SetBranchAddress("glu_monoIdx",&glu_monoIdx); - t->SetBranchAddress("glu_stereoIdx",&glu_stereoIdx); t->SetBranchAddress("glu_isBarrel",&glu_isBarrel); - t->SetBranchAddress("glu_lay",&glu_lay); t->SetBranchAddress("glu_det",&glu_det); - t->SetBranchAddress("glu_posFromTrack",&glu_posFromTrack); - t->SetBranchAddress("glu_onTrack",&glu_onTrack); + t->SetBranchAddress("glu_lay",&glu_lay); + t->SetBranchAddress("glu_monoIdx",&glu_monoIdx); + t->SetBranchAddress("glu_stereoIdx",&glu_stereoIdx); t->SetBranchAddress("glu_x",&glu_x); t->SetBranchAddress("glu_y",&glu_y); t->SetBranchAddress("glu_z",&glu_z); @@ -335,15 +342,11 @@ int main() { t->SetBranchAddress("glu_zz",&glu_zz); t->SetBranchAddress("glu_zx",&glu_zx); } - vector* str_isBarrel = 0; - vector* str_isStereo = 0; - vector* str_lay = 0; - vector* str_det = 0; - vector* str_simTrkIdx = 0; - vector* str_particle = 0; - vector* str_process = 0; - vector* str_posFromTrack = 0; - vector* str_onTrack = 0; + + vector* str_isBarrel = 0; + vector* str_isStereo = 0; + vector* str_det = 0; + vector* str_lay = 0; vector* str_x = 0; vector* str_y = 0; vector* str_z = 0; @@ -357,11 +360,6 @@ int main() { t->SetBranchAddress("str_isStereo",&str_isStereo); t->SetBranchAddress("str_lay",&str_lay); t->SetBranchAddress("str_det",&str_det); - t->SetBranchAddress("str_simTrkIdx",&str_simTrkIdx); - t->SetBranchAddress("str_particle",&str_particle); - t->SetBranchAddress("str_process",&str_process); - t->SetBranchAddress("str_posFromTrack",&str_posFromTrack); - t->SetBranchAddress("str_onTrack",&str_onTrack); t->SetBranchAddress("str_x",&str_x); t->SetBranchAddress("str_y",&str_y); t->SetBranchAddress("str_z",&str_z); @@ -371,13 +369,17 @@ int main() { t->SetBranchAddress("str_yz",&str_yz); t->SetBranchAddress("str_zz",&str_zz); t->SetBranchAddress("str_zx",&str_zx); + + vector >* str_simHitIdx = 0; + t->SetBranchAddress("str_simHitIdx", &str_simHitIdx); + fwrite(&maxevt, sizeof(int), 1, fp); - long long totentries = t->GetEntriesFast(); + long long totentries = t->GetEntries(); long long savedEvents = 0; - for (long long i = 0; savedEvents < maxevt && i simTracks_; vector simTrackIdx_(sim_q->size(),-1);//keep track of original index in ntuple vector seedSimIdx(see_q->size(),-1); for (int isim = 0; isim < sim_q->size(); ++isim) { + std::cout<<__FILE__<<" "<<__LINE__<<" iSim "<at(isim); @@ -405,12 +408,12 @@ int main() { //if (fabs(sim_eta->at(isim))>0.8) continue; vector const& trkIdxV = sim_trkIdx->at(isim); + //if (trkIdx<0) continue; - //FIXME: CHECK IF THE LOOP AND BEST SELECTION IS NEEDED. //Pick the first const int trkIdx = trkIdxV.empty() ? -1 : trkIdxV[0]; - + int nlay = 0; if (trkIdx>=0) { std::vector hitlay(nTotalLayers, 0); @@ -454,6 +457,7 @@ int main() { //cout << Form("track q=%2i p=(%6.3f, %6.3f, %6.3f) x=(%6.3f, %6.3f, %6.3f) nlay=%i",sim_q->at(isim),sim_px->at(isim),sim_py->at(isim),sim_pz->at(isim),sim_prodx,sim_prody,sim_prodz,nlay) << endl; + SVector3 pos(sim_prodx,sim_prody,sim_prodz); SVector3 mom(sim_px->at(isim),sim_py->at(isim),sim_pz->at(isim)); SMatrixSym66 err; @@ -478,15 +482,19 @@ int main() { } } simTrackIdx_[isim] = simTracks_.size(); - simTracks_.push_back(track); + simTracks_.push_back(track); + } if (simTracks_.size()==0) continue; //if (simTracks_.size()<2) continue; + vector seedTracks_; vector > pixHitSeedIdx(pix_lay->size()); + std::cout<<__FILE__<<" "<<__LINE__<<" n see "<size()<size(); ++is) { + std::cout<<__FILE__<<" "<<__LINE__<<" see "<at(is)<at(is))!=TrackAlgorithm::initialStep) continue;//select seed in acceptance //if (see_pt->at(is)<0.5 || fabs(see_eta->at(is))>0.8) continue;//select seed in acceptance SVector3 pos = SVector3(see_stateTrajGlbX->at(is),see_stateTrajGlbY->at(is),see_stateTrajGlbZ->at(is)); @@ -522,8 +530,9 @@ int main() { Track track(state, 0, seedSimIdx[is], 0, nullptr); auto const& shTypes = see_hitType->at(is); auto const& shIdxs = see_hitIdx->at(is); - if (! (TrackAlgorithm(see_algo->at(is))!= TrackAlgorithm::initialStep + if (! (TrackAlgorithm(see_algo->at(is))== TrackAlgorithm::initialStep && std::count(shTypes.begin(), shTypes.end(), int(HitType::Pixel))>=3)) continue;//check algo and nhits + std::cout<<__FILE__<<" "<<__LINE__<<" see "< > layerHits_; vector simHitsInfo_; int totHits = 0; layerHits_.resize(nTotalLayers); + std::cout<<__FILE__<<" "<<__LINE__<<" n pix "<size()<size(); ++ipix) { int ilay = -1; ilay = lnc.convertLayerNumber(pix_det->at(ipix),pix_lay->at(ipix),useMatched,-1,pix_z->at(ipix)>0); if (ilay<0) continue; int simTkIdx = -1; - if (pix_simTrkIdx->at(ipix)>=0) simTkIdx = simTrackIdx_[pix_simTrkIdx->at(ipix)]; + auto const& pixSimHits = pix_simHitIdx->at(ipix); + if (!pixSimHits.empty()){ + //FIXME: need to improve consistency instead of just using first available + simTkIdx = simTrackIdx_[simhit_simTrkIdx->at(pixSimHits[0])]; + } //cout << Form("pix lay=%i det=%i x=(%6.3f, %6.3f, %6.3f)",ilay+1,pix_det->at(ipix),pix_x->at(ipix),pix_y->at(ipix),pix_z->at(ipix)) << endl; SVector3 pos(pix_x->at(ipix),pix_y->at(ipix),pix_z->at(ipix)); SMatrixSym33 err; @@ -564,14 +579,24 @@ int main() { simHitsInfo_.push_back(hitInfo); totHits++; } + std::cout<<__FILE__<<" "<<__LINE__<<" pix loop OK: now totHits "<size(); ++iglu) { if (glu_isBarrel->at(iglu)==0) continue; int simTkIdx = -1; - if (str_simTrkIdx->at(glu_monoIdx->at(iglu))>=0 /*|| str_simTrkIdx->at(glu_stereoIdx->at(iglu))>=0*/) simTkIdx = simTrackIdx_[str_simTrkIdx->at(glu_monoIdx->at(iglu))]; + auto const& strMSimHits = str_simHitIdx->at(glu_monoIdx->at(iglu)); + int strMSimHit_simTrkIdx = -1; + int strMSimHit_process = -1; + auto const& strSSimHits = str_simHitIdx->at(glu_stereoIdx->at(iglu)); + if (!strMSimHits.empty() /*|| !strSSimHits.empty() */){ + //FIXME: need to improve consistency instead of just using first available + strMSimHit_simTrkIdx = simhit_simTrkIdx->at(strMSimHits[0]); + strMSimHit_process = simhit_process->at(strMSimHits[0]); + simTkIdx = simTrackIdx_[strMSimHit_simTrkIdx]; + } int ilay = lnc.convertLayerNumber(glu_det->at(iglu),glu_lay->at(iglu),useMatched,-1,glu_z->at(iglu)>0); - //cout << ilay << " " << str_simTrkIdx->at(glu_monoIdx->at(iglu)) << " " << str_process->at(glu_monoIdx->at(iglu)) << " " << str_simTrkIdx->at(glu_stereoIdx->at(iglu)) << " " << str_process->at(glu_stereoIdx->at(iglu)) << endl; + //cout << ilay << " " << strMSimHit_simTrkIdx << " " << strMSimHit_process << " " << strSSimHit_simTrkIdx << " " << strSSimHit_process << endl; // cout << Form("glu lay=%i det=%i bar=%i x=(%6.3f, %6.3f, %6.3f)",ilay+1,glu_det->at(iglu),glu_isBarrel->at(iglu),glu_x->at(iglu),glu_y->at(iglu),glu_z->at(iglu)) << endl; SVector3 pos(glu_x->at(iglu),glu_y->at(iglu),glu_z->at(iglu)); SMatrixSym33 err; @@ -592,15 +617,30 @@ int main() { vector strIdx; strIdx.resize(str_lay->size()); + std::cout<<__FILE__<<" "<<__LINE__<<" n str "<size()<size(); ++istr) { + std::cout<<__FILE__<<" "<<__LINE__<<" i str "<at(istr),str_lay->at(istr),useMatched,str_isStereo->at(istr),str_z->at(istr)>0); if (useMatched && str_isBarrel->at(istr)==1 && str_isStereo->at(istr)) continue; if (ilay==-1) continue; int simTkIdx = -1; - if (str_simTrkIdx->at(istr)>=0) simTkIdx = simTrackIdx_[str_simTrkIdx->at(istr)]; + int strSimHit_simTrkIdx = -1; + int strSimHit_process = -1; + auto const& strSimHits = str_simHitIdx->at(istr); + + if (!strSimHits.empty()){ + //FIXME: need to improve consistency instead of just using first available + strSimHit_simTrkIdx = simhit_simTrkIdx->at(strSimHits[0]); + std::cout<<__FILE__<<" "<<__LINE__<<" simTrk "<at(strSimHits[0]); + std::cout<<__FILE__<<" "<<__LINE__<<" process "<at(istr)==0) continue;//do not consider hits that are not on track! - //cout << Form("str lay=%i istr=%i tridx=%i bar=%i x=(%6.3f, %6.3f, %6.3f) r=%6.3f proc=%i part=%i onTrk=%i isStereo=%i",ilay+1,istr,str_simTrkIdx->at(istr),str_isBarrel->at(istr),str_x->at(istr),str_y->at(istr),str_z->at(istr),sqrt(pow(str_x->at(istr),2)+pow(str_y->at(istr),2)),str_process->at(istr),str_particle->at(istr),str_onTrack->at(istr),str_isStereo->at(istr)) << endl; + //cout << Form("str lay=%i istr=%i tridx=%i bar=%i x=(%6.3f, %6.3f, %6.3f) r=%6.3f proc=%i part=%i onTrk=%i isStereo=%i",ilay+1,istr,strSimHit_simTrkIdx,str_isBarrel->at(istr),str_x->at(istr),str_y->at(istr),str_z->at(istr),sqrt(pow(str_x->at(istr),2)+pow(str_y->at(istr),2)),strSimHit_process->at(istr),str_particle->at(istr),str_onTrack->at(istr),str_isStereo->at(istr)) << endl; + std::cout<<__FILE__<<" "<<__LINE__<<" fill in lay "<at(istr),str_y->at(istr),str_z->at(istr)); SMatrixSym33 err; err.At(0,0) = str_xx->at(istr); @@ -609,19 +649,26 @@ int main() { err.At(0,1) = str_xy->at(istr); err.At(0,2) = str_zx->at(istr); err.At(1,2) = str_yz->at(istr); - if (simTkIdx>=0) simTracks_[simTkIdx].addHitIdx(layerHits_[ilay].size(), ilay, 0); + std::cout<<__FILE__<<" "<<__LINE__<<" got pos and err "<<" fill simTracks_ "<=0){ + std::cout<<__FILE__<<" "<<__LINE__<<" add hits; size now "< Date: Fri, 5 May 2017 01:24:42 -0700 Subject: [PATCH 038/172] Finalizing TrackerInfo for CMS - libMicCore is now built in top directory. main and mkFit exec link against that. - Add geom plugin to create TrackerInfo and optionally set Config parameters (only chi2 cut done now). - Existing plugins are in Geoms/. - CMS-2017.cc is auto generated from stuff in Geoms/CMS/ + file phiphi:~matevz/bbs.root (bounding-boxes, generated from tracking ntuple). - Remove from Config.h: - Min/max dz/dphi -- now defined in TrackerInfo. This is used consistently in MkFitter::SelectHitIndices[Endcap]. - CMS mono/stereo holes -- to be implemented in CMS tracker info. Min/max DPhi/DEta used by SMatrix building are still there. - Code (esp. libMicCore and geom plugin loading) needs to be tested (and fixed) on mic and on mac. **Next steps:** - Test with CMS barrel. - Implement stereo/mono hole handling. - Test with CMS endcap. - MaxHits on track -- this can now be rather large (42 for rec hitstracks, probably more for sim tracks). - I don't care much about the size of Track (as long as track objects get cache-aligned). - Copying in/out of Matriplexes does bother me. And we don't actually need to do that, we can copy hit-indeces from "source candidate" once we know the new candidate will actually survive. Or so I think ... - Allow configurable number of phi bins per layer. - Optimize handling of r-bins in endcap. There the modules closer to beam-pipe are shorter and we potentially search over 2-times too many r-bins. 1. allow min r-window to be a function of r; 2. use smaller binning (matching short detectors) and efficiently handle empty r bins that will arise because of that. --- Config.cc | 4 + Config.h | 29 +- CylCowWLids.h | 27 - Geoms/CMS-2017.cc | 776 +++++++++++++++++ Geoms/CMS/make_trk_info.C | 235 ++++++ Geoms/CMS/tnc.C | 272 ++++++ Geoms/CMS/tnc.h | 1059 ++++++++++++++++++++++++ Geoms/CMS/tncdefs.h | 157 ++++ CylCowWLids.cc => Geoms/CylCowWLids.cc | 81 +- Geoms/Makefile | 36 + Makefile | 33 +- Makefile.config | 2 +- TrackerInfo.cc | 67 ++ TrackerInfo.h | 22 +- cmssw-trackerinfo-desc.txt | 2 + mkFit/HitStructures.cc | 100 +-- mkFit/HitStructures.h | 27 +- mkFit/Makefile | 23 +- mkFit/MkBuilder.cc | 9 +- mkFit/MkFitter.cc | 40 +- mkFit/SteeringParams.h | 3 - mkFit/mkFit.cc | 30 +- 22 files changed, 2821 insertions(+), 213 deletions(-) delete mode 100644 CylCowWLids.h create mode 100644 Geoms/CMS-2017.cc create mode 100644 Geoms/CMS/make_trk_info.C create mode 100644 Geoms/CMS/tnc.C create mode 100644 Geoms/CMS/tnc.h create mode 100644 Geoms/CMS/tncdefs.h rename CylCowWLids.cc => Geoms/CylCowWLids.cc (70%) create mode 100644 Geoms/Makefile diff --git a/Config.cc b/Config.cc index d3b85f4764ccc..14b4c4a25babe 100644 --- a/Config.cc +++ b/Config.cc @@ -9,6 +9,8 @@ namespace Config int nTracks = 10000; int nEvents = 20; + std::string geomPlugin = "CylCowWLids"; + // Dependent constants, assigned after processing of commandline options int maxHitsPerBunch; int maxCandsPerEtaBin; @@ -38,6 +40,8 @@ namespace Config float RlgridME[Config::nBinsZME][Config::nBinsRME]; float XigridME[Config::nBinsZME][Config::nBinsRME]; + float chi2Cut = 15.; + bool useCMSGeom = false; bool readCmsswSeeds = false; diff --git a/Config.h b/Config.h index 36f527c15705b..dd41d45b5a9f8 100644 --- a/Config.h +++ b/Config.h @@ -38,6 +38,8 @@ namespace Config extern int nTracks; //defined in Config.cc by default or when reading events from file extern int nEvents; + extern std::string geomPlugin; + // config on main -- for geometry constexpr int nLayers = 10; // default: 10; cmssw tests: 13, 17, 26 (for endcap) @@ -57,23 +59,8 @@ namespace Config constexpr float fOuterSensorSize = Config::fInnerSensorSize * 2.; constexpr float fEtaDet = 1; // default: 1; cmssw tests: 2, 2.5 - //constexpr float cmsAvgRads[13] = {4.42,7.31,10.17,25.58,33.98,41.79,49.78,60.78,69.2,77.96,86.80,96.53,108.00}; // cms average radii, noSplit version - constexpr float cmsAvgRads[17] = {4.42,7.31,10.17,25.58,25.58,33.98,33.98,41.79,49.78,60.57,61.00,69.41,68.98,77.96,86.80,96.53,108.00}; // cms average radii, split version constexpr float cmsDeltaRad = 2.5; //fixme! using constant 2.5 cm, to be taken from layer properties - constexpr float cmsAvgZs[26] = {35.5,48.5,79.8,79.8,92.6,92.6,105.6,105.6,131.3,131.3,145.3,145.3,159.3,159.3,173.9,173.9,187.8,187.8,205.4,205.4,224.0,224.0,244.4,244.4,266.3,266.3}; // cms average z - constexpr float cmsDiskMinRs[26] = { 5.7, 5.7,23.1,22.8,23.1,22.8, 23.1, 22.8, 23.3, 23.0, 23.3, 23.0, 23.3, 23.0, 31.6, 34.4, 31.6, 34.4, 31.6, 34.4, 59.9, 38.8, 59.9, 38.8, 59.9, 49.9}; - constexpr float cmsDiskMaxRs[26] = {14.7,14.7,50.8,42.0,50.8,42.0, 50.8, 42.0, 76.1,110.0, 76.1,110.0, 76.1,110.0, 75.9,109.7, 75.9,109.7, 75.9,109.7, 75.9,109.4, 75.9,109.4, 75.9,109.4}; - constexpr float cmsDiskMinRsHole[26] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 42.0, 0.0, 42.0, 0.0, 42.0, 0.0, 42.1, 0.0, 42.1, 0.0, 42.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; - constexpr float cmsDiskMaxRsHole[26] = {999.,999.,999.,999.,999.,999., 999., 999., 59.9, 999., 59.9, 999., 59.9, 999., 59.7, 999., 59.7, 999., 59.7, 999., 999., 999., 999., 999., 999., 999.}; - const float g_disk_dr[] = { 1, 1, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20}; - - const float g_layer_zwidth[] = { 10, 14, 18, 23, 28, 32, 37, 42, 48, 52 }; //default - const float g_layer_dz[] = { 0.6, 0.55, 0.5, 0.5, 0.45, 0.4, 0.4, 0.4, 0.35, 0.35 }; //default - - /* const float g_layer_zwidth[] = { 30, 30, 30, 70, 70, 70, 70, 70, 70, 110, 110, 110, 110, 110, 110, 110, 110 }; //cmssw tests */ - /* const float g_layer_dz[] = { 1, 1, 1, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20 }; //cmssw tests */ - // config for material effects in cmssw constexpr float rangeZME = 300.; constexpr int nBinsZME = 300; @@ -117,19 +104,17 @@ namespace Config extern float RlgridME[Config::nBinsZME][Config::nBinsRME]; extern float XigridME[Config::nBinsZME][Config::nBinsRME]; - // These could be parameters, layer dependent. - static constexpr int m_nphi = 1024; - static constexpr float m_max_dz = 1; // default: 1; cmssw tests: 20 - static constexpr float m_max_dphi = 0.02; // default: 0.02; cmssw tests: 0.2 + // This will become layer dependent (in bits). To be consistent with min_dphi. + static constexpr int m_nphi = 1024; // config on Event - constexpr float chi2Cut = 15.;// default: 15.; cmssw tests: 30. + extern float chi2Cut; // default: 15; cmssw: 30 (set in TrackerInfo plugin) + // the following are only used in SMatrix version constexpr float nSigma = 3.; - constexpr float minDPhi = 0.;// default: 0.; cmssw tests: 0.01; + constexpr float minDPhi = 0.01;// default: 0.; cmssw tests: 0.01; constexpr float maxDPhi = Config::PI; constexpr float minDEta = 0.; constexpr float maxDEta = 1.0; - constexpr float minDZ = 0.; // default: 0.; cmssw tests: 10.; // Configuration for simulation info // CMS beam spot width 25um in xy and 5cm in z diff --git a/CylCowWLids.h b/CylCowWLids.h deleted file mode 100644 index 95eda9eab9198..0000000000000 --- a/CylCowWLids.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef CYLCOWWLIDS_H -#define CYLCOWWLIDS_H - -class TrackerInfo; - -// Cylindrical Cow with Lids -// -// Intended coverage: |eta| < 2.4 with D_z_beam_spot = +-3 cm (3 sigma) -// B-layer extends to 2.55. -// Layers 1 and 2 have somewhat longer barrels. It is assumed -// those will be needed / used for seed finding. -// -// Layers 3 - 9: -// Barrel: 0.0 - 1.0 -// Transition: 1.0 - 1.4 -// Endcap: 1.4 - 2.4 -// -// Run root test/CylCowWLids.C to get a plot and dumps of -// edge coordinates and etas. -// -// Eta partitions for B / T / EC - -// This could be translated into plugin - -void Create_TrackerInfo(TrackerInfo& ti, bool verbose=false); - -#endif diff --git a/Geoms/CMS-2017.cc b/Geoms/CMS-2017.cc new file mode 100644 index 0000000000000..fea70b3bfa960 --- /dev/null +++ b/Geoms/CMS-2017.cc @@ -0,0 +1,776 @@ +#include "../Config.h" +#include "../TrackerInfo.h" + +void Create_TrackerInfo(TrackerInfo& ti, bool verbose) +{ + Config::chi2Cut = 30.0; + + for (int i = 0; i < 18; ++i) ti.new_barrel_layer(); + for (int i = 18; i < 45; ++i) ti.new_ecap_pos_layer(); + for (int i = 45; i < 72; ++i) ti.new_ecap_neg_layer(); + + // PIXB + + { + LayerInfo & li = ti.m_layers[0]; + li.m_layer_type = LayerInfo::Barrel; + li.set_limits(2.720, 3.390, -26.700, 26.700); + li.m_propagate_to = li.r_mean(); + li.set_next_layers(1, 18, 45); + li.m_is_outer = false; + li.m_q_bin = 2.000; + li.set_selection_limits(0.01, 0.05, 1.0, 2.0); + } + + { + LayerInfo & li = ti.m_layers[1]; + li.m_layer_type = LayerInfo::Barrel; + li.set_limits(6.560, 7.270, -26.700, 26.700); + li.m_propagate_to = li.r_mean(); + li.set_next_layers(2, 18, 45); + li.m_is_outer = false; + li.m_q_bin = 2.000; + li.set_selection_limits(0.01, 0.05, 1.0, 2.0); + } + + { + LayerInfo & li = ti.m_layers[2]; + li.m_layer_type = LayerInfo::Barrel; + li.set_limits(10.690, 11.360, -26.700, 26.700); + li.m_propagate_to = li.r_mean(); + li.set_next_layers(3, 18, 45); + li.m_is_outer = false; + li.m_q_bin = 2.000; + li.set_selection_limits(0.01, 0.05, 1.0, 2.0); + } + + { + LayerInfo & li = ti.m_layers[3]; + li.m_layer_type = LayerInfo::Barrel; + li.set_limits(15.800, 16.460, -26.700, 26.690); + li.m_propagate_to = li.r_mean(); + li.set_next_layers(4, 21, 48); + li.m_is_outer = false; + li.m_q_bin = 2.000; + li.set_selection_limits(0.01, 0.05, 1.0, 2.0); + } + + + // TIB + + { + LayerInfo & li = ti.m_layers[4]; + li.m_layer_type = LayerInfo::Barrel; + li.set_limits(23.450, 27.880, -66.670, 63.930); + li.m_propagate_to = li.r_mean(); + li.set_next_layers(5, 21, 48); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + + { + LayerInfo & li = ti.m_layers[5]; + li.m_layer_type = LayerInfo::Barrel; + li.set_limits(23.450, 27.880, -66.670, 63.930); + li.m_propagate_to = li.r_mean(); + li.set_next_layers(6, 21, 48); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + + { + LayerInfo & li = ti.m_layers[6]; + li.m_layer_type = LayerInfo::Barrel; + li.set_limits(31.830, 36.240, -65.890, 66.670); + li.m_propagate_to = li.r_mean(); + li.set_next_layers(7, 21, 48); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + + { + LayerInfo & li = ti.m_layers[7]; + li.m_layer_type = LayerInfo::Barrel; + li.set_limits(31.830, 36.240, -65.890, 66.670); + li.m_propagate_to = li.r_mean(); + li.set_next_layers(8, 21, 48); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + + { + LayerInfo & li = ti.m_layers[8]; + li.m_layer_type = LayerInfo::Barrel; + li.set_limits(39.880, 44.040, -66.400, 65.240); + li.m_propagate_to = li.r_mean(); + li.set_next_layers(9, 21, 48); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + + { + LayerInfo & li = ti.m_layers[9]; + li.m_layer_type = LayerInfo::Barrel; + li.set_limits(47.810, 51.980, -66.400, 66.400); + li.m_propagate_to = li.r_mean(); + li.set_next_layers(10, 27, 54); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + + + // TOB + + { + LayerInfo & li = ti.m_layers[10]; + li.m_layer_type = LayerInfo::Barrel; + li.set_limits(58.410, 63.430, -108.710, 108.710); + li.m_propagate_to = li.r_mean(); + li.set_next_layers(11, 27, 54); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + + { + LayerInfo & li = ti.m_layers[11]; + li.m_layer_type = LayerInfo::Barrel; + li.set_limits(58.410, 63.430, -108.710, 108.710); + li.m_propagate_to = li.r_mean(); + li.set_next_layers(12, 27, 54); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + + { + LayerInfo & li = ti.m_layers[12]; + li.m_layer_type = LayerInfo::Barrel; + li.set_limits(66.810, 71.740, -108.700, 108.710); + li.m_propagate_to = li.r_mean(); + li.set_next_layers(13, 27, 54); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + + { + LayerInfo & li = ti.m_layers[13]; + li.m_layer_type = LayerInfo::Barrel; + li.set_limits(66.810, 71.740, -108.700, 108.710); + li.m_propagate_to = li.r_mean(); + li.set_next_layers(14, 27, 54); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + + { + LayerInfo & li = ti.m_layers[14]; + li.m_layer_type = LayerInfo::Barrel; + li.set_limits(76.040, 80.090, -108.300, 108.290); + li.m_propagate_to = li.r_mean(); + li.set_next_layers(15, 27, 54); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + + { + LayerInfo & li = ti.m_layers[15]; + li.m_layer_type = LayerInfo::Barrel; + li.set_limits(84.840, 88.880, -108.290, 108.300); + li.m_propagate_to = li.r_mean(); + li.set_next_layers(16, 27, 54); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + + { + LayerInfo & li = ti.m_layers[16]; + li.m_layer_type = LayerInfo::Barrel; + li.set_limits(94.540, 98.570, -108.290, 108.290); + li.m_propagate_to = li.r_mean(); + li.set_next_layers(17, 27, 54); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + + { + LayerInfo & li = ti.m_layers[17]; + li.m_layer_type = LayerInfo::Barrel; + li.set_limits(106.040, 110.060, -108.290, 108.290); + li.m_propagate_to = li.r_mean(); + li.set_next_layers(-1, -1, -1); + li.m_is_outer = true; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + + + // PIXE +/- + + { + LayerInfo & li = ti.m_layers[18]; + li.m_layer_type = LayerInfo::EndCapPos; + li.set_limits(4.590, 16.090, 29.440, 35.210); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(4, 19, -1); + li.m_is_outer = false; + li.m_q_bin = 1.000; + li.set_selection_limits(0.01, 0.05, 0.8, 1.6); + } + { + LayerInfo & li = ti.m_layers[45]; + li.m_layer_type = LayerInfo::EndCapNeg; + li.set_limits(4.590, 16.090, -35.200, -29.440); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(4, 46, -1); + li.m_is_outer = false; + li.m_q_bin = 1.000; + li.set_selection_limits(0.01, 0.05, 0.8, 1.6); + } + { + LayerInfo & li = ti.m_layers[19]; + li.m_layer_type = LayerInfo::EndCapPos; + li.set_limits(4.590, 16.090, 36.940, 42.700); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(4, 20, -1); + li.m_is_outer = false; + li.m_q_bin = 1.000; + li.set_selection_limits(0.01, 0.05, 0.8, 1.6); + } + { + LayerInfo & li = ti.m_layers[46]; + li.m_layer_type = LayerInfo::EndCapNeg; + li.set_limits(4.590, 16.090, -42.700, -36.940); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(4, 47, -1); + li.m_is_outer = false; + li.m_q_bin = 1.000; + li.set_selection_limits(0.01, 0.05, 0.8, 1.6); + } + { + LayerInfo & li = ti.m_layers[20]; + li.m_layer_type = LayerInfo::EndCapPos; + li.set_limits(4.590, 16.090, 46.450, 52.200); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(4, 21, -1); + li.m_is_outer = false; + li.m_q_bin = 1.000; + li.set_selection_limits(0.01, 0.05, 0.8, 1.6); + } + { + LayerInfo & li = ti.m_layers[47]; + li.m_layer_type = LayerInfo::EndCapNeg; + li.set_limits(4.590, 16.090, -52.210, -46.450); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(4, 48, -1); + li.m_is_outer = false; + li.m_q_bin = 1.000; + li.set_selection_limits(0.01, 0.05, 0.8, 1.6); + } + + // TID +/- + + { + LayerInfo & li = ti.m_layers[21]; + li.m_layer_type = LayerInfo::EndCapPos; + li.set_limits(22.980, 50.440, 74.350, 84.050); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(10, 22, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[48]; + li.m_layer_type = LayerInfo::EndCapNeg; + li.set_limits(22.980, 50.440, -84.050, -74.350); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(10, 49, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[22]; + li.m_layer_type = LayerInfo::EndCapPos; + li.set_limits(22.980, 50.440, 74.350, 84.050); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(10, 23, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[49]; + li.m_layer_type = LayerInfo::EndCapNeg; + li.set_limits(22.980, 50.440, -84.050, -74.350); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(10, 50, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[23]; + li.m_layer_type = LayerInfo::EndCapPos; + li.set_limits(22.980, 50.440, 87.300, 97.000); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(10, 24, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[50]; + li.m_layer_type = LayerInfo::EndCapNeg; + li.set_limits(22.980, 50.440, -97.000, -87.300); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(10, 51, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[24]; + li.m_layer_type = LayerInfo::EndCapPos; + li.set_limits(22.980, 50.440, 87.300, 97.000); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(10, 25, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[51]; + li.m_layer_type = LayerInfo::EndCapNeg; + li.set_limits(22.980, 50.440, -97.000, -87.300); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(10, 52, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[25]; + li.m_layer_type = LayerInfo::EndCapPos; + li.set_limits(22.980, 50.440, 100.250, 109.950); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(10, 26, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[52]; + li.m_layer_type = LayerInfo::EndCapNeg; + li.set_limits(22.980, 50.440, -109.950, -100.250); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(10, 53, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[26]; + li.m_layer_type = LayerInfo::EndCapPos; + li.set_limits(22.980, 50.440, 100.250, 109.950); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(10, 27, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[53]; + li.m_layer_type = LayerInfo::EndCapNeg; + li.set_limits(22.980, 50.440, -109.950, -100.250); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(10, 54, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + + // TID +/- + + { + LayerInfo & li = ti.m_layers[27]; + li.m_layer_type = LayerInfo::EndCapPos; + li.set_limits(23.370, 109.390, 126.380, 137.390); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(-1, 28, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[54]; + li.m_layer_type = LayerInfo::EndCapNeg; + li.set_limits(23.360, 109.400, -137.390, -126.380); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(-1, 55, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[28]; + li.m_layer_type = LayerInfo::EndCapPos; + li.set_limits(23.370, 109.390, 126.380, 137.390); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(-1, 29, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[55]; + li.m_layer_type = LayerInfo::EndCapNeg; + li.set_limits(23.360, 109.400, -137.390, -126.380); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(-1, 56, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[29]; + li.m_layer_type = LayerInfo::EndCapPos; + li.set_limits(23.360, 109.410, 140.380, 151.390); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(-1, 30, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[56]; + li.m_layer_type = LayerInfo::EndCapNeg; + li.set_limits(23.360, 109.390, -151.420, -140.380); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(-1, 57, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[30]; + li.m_layer_type = LayerInfo::EndCapPos; + li.set_limits(23.360, 109.410, 140.380, 151.390); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(-1, 31, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[57]; + li.m_layer_type = LayerInfo::EndCapNeg; + li.set_limits(23.360, 109.390, -151.420, -140.380); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(-1, 58, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[31]; + li.m_layer_type = LayerInfo::EndCapPos; + li.set_limits(23.360, 109.390, 154.380, 165.390); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(-1, 32, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[58]; + li.m_layer_type = LayerInfo::EndCapNeg; + li.set_limits(23.360, 109.390, -165.390, -154.380); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(-1, 59, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[32]; + li.m_layer_type = LayerInfo::EndCapPos; + li.set_limits(23.360, 109.390, 154.380, 165.390); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(-1, 33, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[59]; + li.m_layer_type = LayerInfo::EndCapNeg; + li.set_limits(23.360, 109.390, -165.390, -154.380); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(-1, 60, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[33]; + li.m_layer_type = LayerInfo::EndCapPos; + li.set_limits(32.110, 109.400, 168.380, 179.380); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(-1, 34, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[60]; + li.m_layer_type = LayerInfo::EndCapNeg; + li.set_limits(32.110, 109.390, -179.390, -168.380); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(-1, 61, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[34]; + li.m_layer_type = LayerInfo::EndCapPos; + li.set_limits(32.110, 109.400, 168.380, 179.380); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(-1, 35, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[61]; + li.m_layer_type = LayerInfo::EndCapNeg; + li.set_limits(32.110, 109.390, -179.390, -168.380); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(-1, 62, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[35]; + li.m_layer_type = LayerInfo::EndCapPos; + li.set_limits(32.110, 109.390, 182.370, 193.390); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(-1, 36, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[62]; + li.m_layer_type = LayerInfo::EndCapNeg; + li.set_limits(32.110, 109.390, -193.380, -182.380); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(-1, 63, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[36]; + li.m_layer_type = LayerInfo::EndCapPos; + li.set_limits(32.110, 109.390, 182.370, 193.390); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(-1, 37, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[63]; + li.m_layer_type = LayerInfo::EndCapNeg; + li.set_limits(32.110, 109.390, -193.380, -182.380); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(-1, 64, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[37]; + li.m_layer_type = LayerInfo::EndCapPos; + li.set_limits(32.110, 109.390, 199.870, 210.880); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(-1, 38, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[64]; + li.m_layer_type = LayerInfo::EndCapNeg; + li.set_limits(32.110, 109.390, -210.880, -199.870); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(-1, 65, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[38]; + li.m_layer_type = LayerInfo::EndCapPos; + li.set_limits(32.110, 109.390, 199.870, 210.880); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(-1, 39, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[65]; + li.m_layer_type = LayerInfo::EndCapNeg; + li.set_limits(32.110, 109.390, -210.880, -199.870); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(-1, 66, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[39]; + li.m_layer_type = LayerInfo::EndCapPos; + li.set_limits(39.200, 109.390, 218.870, 229.860); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(-1, 40, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[66]; + li.m_layer_type = LayerInfo::EndCapNeg; + li.set_limits(39.200, 109.390, -229.860, -218.870); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(-1, 67, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[40]; + li.m_layer_type = LayerInfo::EndCapPos; + li.set_limits(39.200, 109.390, 218.870, 229.860); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(-1, 41, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[67]; + li.m_layer_type = LayerInfo::EndCapNeg; + li.set_limits(39.200, 109.390, -229.860, -218.870); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(-1, 68, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[41]; + li.m_layer_type = LayerInfo::EndCapPos; + li.set_limits(39.200, 109.400, 239.370, 250.360); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(-1, 42, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[68]; + li.m_layer_type = LayerInfo::EndCapNeg; + li.set_limits(39.200, 109.400, -250.360, -239.370); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(-1, 69, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[42]; + li.m_layer_type = LayerInfo::EndCapPos; + li.set_limits(39.200, 109.400, 239.370, 250.360); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(-1, 43, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[69]; + li.m_layer_type = LayerInfo::EndCapNeg; + li.set_limits(39.200, 109.400, -250.360, -239.370); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(-1, 70, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[43]; + li.m_layer_type = LayerInfo::EndCapPos; + li.set_limits(50.410, 109.400, 260.870, 271.870); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(-1, 44, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[70]; + li.m_layer_type = LayerInfo::EndCapNeg; + li.set_limits(50.410, 109.390, -271.880, -260.870); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(-1, 71, -1); + li.m_is_outer = false; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[44]; + li.m_layer_type = LayerInfo::EndCapPos; + li.set_limits(50.410, 109.400, 260.870, 271.870); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(-1, -1, -1); + li.m_is_outer = true; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + { + LayerInfo & li = ti.m_layers[71]; + li.m_layer_type = LayerInfo::EndCapNeg; + li.set_limits(50.410, 109.390, -271.880, -260.870); + li.m_propagate_to = li.z_mean(); + li.set_next_layers(-1, -1, -1); + li.m_is_outer = true; + li.m_q_bin = 20.000; + li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + } + + if (verbose) { printf("==========================================================================================\n"); } + printf("CMS-2017 -- Create_TrackerInfo finished\n"); + if (verbose) + { + printf("==========================================================================================\n"); + for (auto &i : ti.m_layers) i.print_layer(); + printf("==========================================================================================\n"); + } +} diff --git a/Geoms/CMS/make_trk_info.C b/Geoms/CMS/make_trk_info.C new file mode 100644 index 0000000000000..72d973185a03e --- /dev/null +++ b/Geoms/CMS/make_trk_info.C @@ -0,0 +1,235 @@ +/* + Sibling layers are needed for seeding from MC tracks. + As we do not do seeding we also do not fill them here. +*/ + +/* + Some "leftovers" of CMSSW from Config.h + + constexpr float cmsAvgRads[13] = {4.42,7.31,10.17,25.58,33.98,41.79,49.78,60.78,69.2,77.96,86.80,96.53,108.00}; // cms average radii, noSplit version + constexpr float cmsAvgRads[17] = {4.42, 7.31, 10.17, + 25.58,25.58, 33.98,33.98, 41.79, 49.78, + 60.57,61.00, 69.41,68.98, 77.96, 86.80, 96.53, 108.00}; // cms average radii, split version + constexpr float cmsDeltaRad = 2.5; //fixme! using constant 2.5 cm, to be taken from layer properties + + constexpr float cmsAvgZs[26] = {35.5,48.5, 79.8,79.8,92.6,92.6,105.6,105.6, 131.3,131.3,145.3,145.3,159.3,159.3,173.9,173.9,187.8,187.8,205.4,205.4,224.0,224.0,244.4,244.4,266.3,266.3}; // cms average z + constexpr float cmsDiskMinRs[26] = { 5.7, 5.7, 23.1,22.8,23.1,22.8, 23.1, 22.8, 23.3, 23.0, 23.3, 23.0, 23.3, 23.0, 31.6, 34.4, 31.6, 34.4, 31.6, 34.4, 59.9, 38.8, 59.9, 38.8, 59.9, 49.9}; + constexpr float cmsDiskMaxRs[26] = {14.7,14.7, 50.8,42.0,50.8,42.0, 50.8, 42.0, 76.1,110.0, 76.1,110.0, 76.1,110.0, 75.9,109.7, 75.9,109.7, 75.9,109.7, 75.9,109.4, 75.9,109.4, 75.9,109.4}; + constexpr float cmsDiskMinRsHole[26] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 42.0, 0.0, 42.0, 0.0, 42.0, 0.0, 42.1, 0.0, 42.1, 0.0, 42.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; + constexpr float cmsDiskMaxRsHole[26] = {999.,999., 999.,999.,999.,999., 999., 999., 59.9, 999., 59.9, 999., 59.9, 999., 59.7, 999., 59.7, 999., 59.7, 999., 999., 999., 999., 999., 999., 999.}; + + const float g_disk_dr[] = { 1, 1, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20}; + const float g_layer_zwidth[] = { 30, 30, 30, 70, 70, 70, 70, 70, 70, 110, 110, 110, 110, 110, 110, 110, 110 }; + const float g_layer_dz[] = { 1, 1, 1, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20 }; +*/ + +#include "tncdefs.h" + +#include + +BBS BBB; +FILE *OOO = 0; +int DEP = 0; + +#define NLN fprintf(OOO,"\n") +#define PRN(...) fprintf(OOO,"%*s",DEP,""); fprintf(OOO, __VA_ARGS__); fprintf(OOO,"\n"); + +#define SCOPE_BEG PRN("{"); DEP += 2 +#define SCOPE_END DEP -= 2; PRN("}") + +#define ASSF(var, val) PRN("li.%s = %.3f;", #var, val) +#define ASSI(var, val) PRN("li.%s = %d;", #var, val) +#define ASSB(var, val) PRN("li.%s = %s;", #var, val ? "true" : "false") + +void add_barrel(int &lid, int det, int lay, bool is_pix, + int necp, int necn) +{ + RZBox b = BBB.b[det][lay].Round(100); + + SCOPE_BEG; + + PRN("LayerInfo & li = ti.m_layers[%d];", lid); + PRN("li.m_layer_type = LayerInfo::Barrel;"); + PRN("li.set_limits(%.3f, %.3f, %.3f, %.3f);", b.m_minr, b.m_maxr, b.m_minz, b.m_maxz); + PRN("li.m_propagate_to = li.r_mean();"); + PRN("li.set_next_layers(%d, %d, %d);", lid < 17 ? lid + 1 : -1, necp, necn); + ASSB(m_is_outer, lid == 17); + if (is_pix) + { + ASSF(m_q_bin, 2.0); + PRN("li.set_selection_limits(0.01, 0.05, 1.0, 2.0);"); + } + else + { + ASSF(m_q_bin, 20.0); + PRN("li.set_selection_limits(0.01, 0.2, 10.0, 20.0);"); + } + + SCOPE_END; + + ++lid; +} + +void add_ecap(int &lid, int det, int lay, bool is_pix, + int nbrl) +{ + int lid_store = lid; + + SCOPE_BEG; + { + RZBox b = BBB.p[det][lay].Round(100); + + PRN("LayerInfo & li = ti.m_layers[%d];", lid); + PRN("li.m_layer_type = LayerInfo::EndCapPos;"); + PRN("li.set_limits(%.3f, %.3f, %.3f, %.3f);", b.m_minr, b.m_maxr, b.m_minz, b.m_maxz); + PRN("li.m_propagate_to = li.z_mean();"); + PRN("li.set_next_layers(%d, %d, %d);", nbrl, lid < 44 ? lid + 1 : -1, -1); + ASSB(m_is_outer, lid == 44); + if (is_pix) { + ASSF(m_q_bin, 1.0); + PRN("li.set_selection_limits(0.01, 0.05, 0.8, 1.6);"); + } else { + ASSF(m_q_bin, 20.0); + PRN("li.set_selection_limits(0.01, 0.2, 10.0, 20.0);"); + } + } + SCOPE_END; + SCOPE_BEG; + { + lid += 27; + RZBox b = BBB.n[det][lay].Round(100); + + PRN("LayerInfo & li = ti.m_layers[%d];", lid); + PRN("li.m_layer_type = LayerInfo::EndCapNeg;"); + PRN("li.set_limits(%.3f, %.3f, %.3f, %.3f);", b.m_minr, b.m_maxr, b.m_minz, b.m_maxz); + PRN("li.m_propagate_to = li.z_mean();"); + PRN("li.set_next_layers(%d, %d, %d);", nbrl, lid < 71 ? lid + 1 : -1, -1); + ASSB(m_is_outer, lid == 71); + if (is_pix) { + ASSF(m_q_bin, 1.0); + PRN("li.set_selection_limits(0.01, 0.05, 0.8, 1.6);"); + } else { + ASSF(m_q_bin, 20.0); + PRN("li.set_selection_limits(0.01, 0.2, 10.0, 20.0);"); + } + } + SCOPE_END; + + lid = lid_store + 1; +} + +void print_trk_info() +{ + OOO = fopen("CMS-2017.cc", "w"); + // OOO = stdout; + + PRN("#include \"../Config.h\""); + PRN("#include \"../TrackerInfo.h\""); + NLN; + + PRN("void Create_TrackerInfo(TrackerInfo& ti, bool verbose)"); + SCOPE_BEG; + + PRN("Config::chi2Cut = 30.0;"); + NLN; + + PRN("for (int i = 0; i < 18; ++i) ti.new_barrel_layer();"); + PRN("for (int i = 18; i < 45; ++i) ti.new_ecap_pos_layer();"); + PRN("for (int i = 45; i < 72; ++i) ti.new_ecap_neg_layer();"); + NLN; + + int lid = 0; + + PRN("// PIXB\n"); + add_barrel(lid, 1, 1, true, 18, 45); NLN; + add_barrel(lid, 1, 2, true, 18, 45); NLN; + add_barrel(lid, 1, 3, true, 18, 45); NLN; + add_barrel(lid, 1, 4, true, 21, 48); NLN; + NLN; + + PRN("// TIB\n"); + add_barrel(lid, 3, 1, false, 21, 48); NLN; + add_barrel(lid, 3, 1, false, 21, 48); NLN; + add_barrel(lid, 3, 2, false, 21, 48); NLN; + add_barrel(lid, 3, 2, false, 21, 48); NLN; + add_barrel(lid, 3, 3, false, 21, 48); NLN; + add_barrel(lid, 3, 4, false, 27, 54); NLN; + NLN; + + PRN("// TOB\n"); + add_barrel(lid, 5, 1, false, 27, 54); NLN; + add_barrel(lid, 5, 1, false, 27, 54); NLN; + add_barrel(lid, 5, 2, false, 27, 54); NLN; + add_barrel(lid, 5, 2, false, 27, 54); NLN; + add_barrel(lid, 5, 3, false, 27, 54); NLN; + add_barrel(lid, 5, 4, false, 27, 54); NLN; + add_barrel(lid, 5, 5, false, 27, 54); NLN; + add_barrel(lid, 5, 6, false, -1, -1); NLN; + NLN; + + PRN("// PIXE +/-\n"); + add_ecap(lid, 2, 1, true, 4); + add_ecap(lid, 2, 2, true, 4); + add_ecap(lid, 2, 3, true, 4); + NLN; + + PRN("// TID +/-\n"); + add_ecap(lid, 4, 1, false, 10); + add_ecap(lid, 4, 1, false, 10); + add_ecap(lid, 4, 2, false, 10); + add_ecap(lid, 4, 2, false, 10); + add_ecap(lid, 4, 3, false, 10); + add_ecap(lid, 4, 3, false, 10); + NLN; + + PRN("// TID +/-\n"); + add_ecap(lid, 6, 1, false, -1); + add_ecap(lid, 6, 1, false, -1); + add_ecap(lid, 6, 2, false, -1); + add_ecap(lid, 6, 2, false, -1); + add_ecap(lid, 6, 3, false, -1); + add_ecap(lid, 6, 3, false, -1); + add_ecap(lid, 6, 4, false, -1); + add_ecap(lid, 6, 4, false, -1); + add_ecap(lid, 6, 5, false, -1); + add_ecap(lid, 6, 5, false, -1); + add_ecap(lid, 6, 6, false, -1); + add_ecap(lid, 6, 6, false, -1); + add_ecap(lid, 6, 7, false, -1); + add_ecap(lid, 6, 7, false, -1); + add_ecap(lid, 6, 8, false, -1); + add_ecap(lid, 6, 8, false, -1); + add_ecap(lid, 6, 9, false, -1); + add_ecap(lid, 6, 9, false, -1); + NLN; + + PRN("if (verbose) { printf(\"==========================================================================================\\n\"); }"); + + PRN("printf(\"CMS-2017 -- Create_TrackerInfo finished\\n\");"); + + PRN("if (verbose)"); + SCOPE_BEG; + PRN("printf(\"==========================================================================================\\n\");"); + PRN("for (auto &i : ti.m_layers) i.print_layer();"); + PRN("printf(\"==========================================================================================\\n\");"); + SCOPE_END; + + SCOPE_END; + + if (OOO != stdout) + { + fclose(OOO); + OOO = 0; + } +} + +BBS* make_trk_info() +{ + BBB.load(); + + printf("make_trk_info() and BBS loaded\n"); + + print_trk_info(); + + return &BBB; +} diff --git a/Geoms/CMS/tnc.C b/Geoms/CMS/tnc.C new file mode 100644 index 0000000000000..6e4b5192a7755 --- /dev/null +++ b/Geoms/CMS/tnc.C @@ -0,0 +1,272 @@ +#define tnc_cxx +#include "tnc.h" +#include +#include +#include +#include "TEveManager.h" + +void tnc::CreateBBS() +{ + if (fChain == 0) return; Long64_t Nentries = fChain->GetEntriesFast(); + + for (Long64_t jentry=0; jentry < Nentries; jentry++) + { + Long64_t ientry = LoadTree(jentry); if (ientry < 0) break; + + // fChain->GetEntry(jentry); + b_simhit_x->GetEntry(ientry); fv_t &xs = *simhit_x; + b_simhit_y->GetEntry(ientry); fv_t &ys = *simhit_y; + b_simhit_z->GetEntry(ientry); fv_t &zs = *simhit_z; + b_simhit_det->GetEntry(ientry); usv_t &ds = *simhit_det; + b_simhit_lay->GetEntry(ientry); usv_t &ls = *simhit_lay; + + const int s = ls.size(); + + for (int i = 0; i < s; ++i) + { + float x = xs[i], y = ys[i], z = zs[i]; + int d = ds[i], l = ls[i]; + + assert(d > 0 && d < Mdet); + assert(l > 0 && l < Mlay); + + float r = std::hypot(x, y); + + ++bbs.cnt[d][l]; + + bbs.select_rzbox(d, l, z).fill(r, z); + } + } + + bbs.save(); + + bbs.print(); +} + +//============================================================================== + +TEvePointSetArray *tnc::FillEPS() +{ + if (fChain == 0) return 0; Long64_t Nentries = fChain->GetEntriesFast(); + + TEveManager::Create(); + + auto *ps = new TEvePointSetArray("eps"); + ps->SetMarkerColor(41); + ps->SetMarkerStyle(1); + ps->InitMainTrans(); + ps->SetPickable(false); + gEve->AddElement(ps); + + const int n_bins = 16; + const float zmin = 126, zmax = 138, zscale=10; + const float zmean = (zmin+zmax)/2, zwidth = (zmax-zmin)/2; + + ps->InitBins("Z", n_bins, -zwidth*zscale, zwidth*zscale); + TColor::SetPalette(1, 0); // Spectrum palette + const Int_t nCol = TColor::GetNumberOfColors(); + for (Int_t i = 1; i <= n_bins; ++i) + { + ps->GetBin(i)->SetMainColor(TColor::GetColorPalette(i * nCol / n_bins)); + } + ps->GetBin(0)->SetMainColor(kGray); + ps->GetBin(n_bins + 1)->SetMainColor(kWhite); + + + for (Long64_t jentry=0; jentry < Nentries; jentry++) + { + Long64_t ientry = LoadTree(jentry); if (ientry < 0) break; + + // fChain->GetEntry(jentry); + b_simhit_x->GetEntry(ientry); fv_t &xs = *simhit_x; + b_simhit_y->GetEntry(ientry); fv_t &ys = *simhit_y; + b_simhit_z->GetEntry(ientry); fv_t &zs = *simhit_z; + b_simhit_det->GetEntry(ientry); usv_t &ds = *simhit_det; + b_simhit_lay->GetEntry(ientry); usv_t &ls = *simhit_lay; + + const int s = xs.size(); + + for (int i = 0; i < s; ++i) + { + float x = xs[i], y = ys[i], z = zs[i]; + int d = ds[i], l = ls[i]; + + if (d == 6 && l == 1 && z > 0) + { + ps->Fill(x, y, (z - zmean)*zscale, (z - zmean)*zscale); + + } + } + } + + ps->CloseBins(); + + gEve->Redraw3D(true, true); + + return ps; +} + +//============================================================================== + +TH2I* bookh(char pfx, int d, int l, const RZBox & b, int nb=256) +{ + TString n, t; + if (d > 0) + { + const char *tpfx = pfx == 'B' ? "Barrel" : (pfx == 'P' ? "Pos Ecap" : "Neg Ecap"); + if (l > 0) + { + n.Form("%c_D%d_L%d", pfx, d, l); + t.Form("%s Det %d, Lay %d", tpfx, d, l); + } + else + { + n.Form("%c_FD%d", pfx, d); + t.Form("%s Full Det %d", tpfx, d); + } + } + else + { + n = "FT"; + t = "Full Tracker"; + } + + RZBox eb = b.Extend(); + + return new TH2I(n, t, nb, eb.m_minz, eb.m_maxz, nb, eb.m_minr, eb.m_maxr); +} + +void tnc::Loop() +{ + if (fChain == 0) return; + + Long64_t Nentries = fChain->GetEntriesFast(); + + bbs.load(); + + auto hf = TFile::Open("dets.root", "recreate"); + + TH2I * hb[Mdet][Mlay]; + TH2I * hp[Mdet][Mlay]; + TH2I * hn[Mdet][Mlay]; + + RZBox tbox; + + for (int d = 1; d < Mdet; ++d) + { + RZBox bbox, pbox, nbox; + + for (int l = 1; l < Xlay[d]; ++l) + { + if (isbrl[d]) + { + tbox.MergeWith(bbs.b[d][l]); + bbox.MergeWith(bbs.b[d][l]); + + hb[d][l] = bookh('B', d, l, bbs.b[d][l]); + } + else + { + tbox.MergeWith(bbs.p[d][l]); + tbox.MergeWith(bbs.n[d][l]); + pbox.MergeWith(bbs.p[d][l]); + nbox.MergeWith(bbs.n[d][l]); + + hp[d][l] = bookh('P', d, l, bbs.p[d][l]); + hn[d][l] = bookh('N', d, l, bbs.n[d][l]); + } + } + + if (isbrl[d]) + { + hb[d][0] = bookh('B', d, 0, bbox, 1024); + } + else + { + hp[d][0] = bookh('P', d, 0, pbox, 1024); + hn[d][0] = bookh('N', d, 0, nbox, 1024); + } + } + + hb[0][0] = bookh('X', 0, 0, tbox, 2048); + + + for (Long64_t jentry=0; jentry < Nentries; jentry++) + { + Long64_t ientry = LoadTree(jentry); + + if (ientry < 0) break; + + // fChain->GetEntry(jentry); + b_simhit_x->GetEntry(ientry); fv_t &xs = *simhit_x; + b_simhit_y->GetEntry(ientry); fv_t &ys = *simhit_y; + b_simhit_z->GetEntry(ientry); fv_t &zs = *simhit_z; + b_simhit_det->GetEntry(ientry); usv_t &ds = *simhit_det; + b_simhit_lay->GetEntry(ientry); usv_t &ls = *simhit_lay; + + const int s = ls.size(); + + for (int i = 0; i < s; ++i) + { + float x = xs[i], y = ys[i], z = zs[i]; + int d = ds[i], l = ls[i]; + + assert(d > 0 && d < Mdet); + assert(l > 0 && l < Mlay); + + float r = std::hypot(x, y); + + // XXXX fill det/lay and full det histos (det=0) + hb[0][0]->Fill(z, r); + + if (isbrl[d]) + { + hb[d][0]->Fill(z, r); + hb[d][l]->Fill(z, r); + } + else + { + if (z > 0) + { + hp[d][0]->Fill(z, r); + hp[d][l]->Fill(z, r); + } + else + { + hn[d][0]->Fill(z, r); + hn[d][l]->Fill(z, r); + } + } + } + } + + hf->Write(); +} + +//============================================================================== + +// ROOT comments + +// In a ROOT session, you can do: +// root> .L tnc.C +// root> tnc t +// root> t.GetEntry(12); // Fill t data members with entry number 12 +// root> t.Show(); // Show values of entry 12 +// root> t.Show(16); // Read and show values of entry 16 +// root> t.Loop(); // Loop on all entries +// + +// This is the loop skeleton where: +// jentry is the global entry number in the chain +// ientry is the entry number in the current Tree +// Note that the argument to GetEntry must be: +// jentry for TChain::GetEntry +// ientry for TTree::GetEntry and TBranch::GetEntry +// +// To read only selected branches, Insert statements like: +// METHOD1: +// fChain->SetBranchStatus("*",0); // disable all branches +// fChain->SetBranchStatus("branchname",1); // activate branchname +// METHOD2: replace line +// fChain->GetEntry(jentry); //read all branches +// by b_branchname->GetEntry(ientry); //read only this branch diff --git a/Geoms/CMS/tnc.h b/Geoms/CMS/tnc.h new file mode 100644 index 0000000000000..883155b0f4403 --- /dev/null +++ b/Geoms/CMS/tnc.h @@ -0,0 +1,1059 @@ +////////////////////////////////////////////////////////// +// This class has been automatically generated on +// Fri Apr 14 11:12:54 2017 by ROOT version 6.09/01 +// from TTree tree/tree +// found on file: trackingNtuple.root +////////////////////////////////////////////////////////// + +#ifndef tnc_h +#define tnc_h + +#include +#include +#include + +#include "TEvePointSet.h" + +// Header file for the classes stored in the TTree if any. +#include "vector" +#include "vector" +#include "vector" +#include "vector" +#include "vector" +#include "vector" + + +#include "tncdefs.h" + + +class tnc { +public : + + +typedef std::vector fv_t; +typedef std::vector usv_t; + +BBS bbs; + +RZBox& select_rzbox(int det, int lay, float z) +{ + if (isbrl[det]) return bbs.b[det][lay]; + return (z > 0) ? bbs.p[det][lay] : bbs.n[det][lay]; +} + +void reset_mt() +{ + for (int d = 1; d < Mdet; ++d) + { + for (int l = 1; l < Mlay; ++l) + { + bbs.cnt[d][l] = 0; + bbs.b[d][l].m_cnt = 0; + bbs.p[d][l].m_cnt = 0; + bbs.n[d][l].m_cnt = 0; + } + } +} + + + TTree *fChain; //!pointer to the analyzed TTree or TChain + Int_t fCurrent; //!current Tree number in a TChain + +// Fixed size dimensions of array or collections stored in the TTree if any. + + // Declaration of leaf types + ULong64_t event; + UInt_t lumi; + UInt_t run; + vector *trk_px; + vector *trk_py; + vector *trk_pz; + vector *trk_pt; + vector *trk_inner_px; + vector *trk_inner_py; + vector *trk_inner_pz; + vector *trk_inner_pt; + vector *trk_outer_px; + vector *trk_outer_py; + vector *trk_outer_pz; + vector *trk_outer_pt; + vector *trk_eta; + vector *trk_lambda; + vector *trk_cotTheta; + vector *trk_phi; + vector *trk_dxy; + vector *trk_dz; + vector *trk_ptErr; + vector *trk_etaErr; + vector *trk_lambdaErr; + vector *trk_phiErr; + vector *trk_dxyErr; + vector *trk_dzErr; + vector *trk_refpoint_x; + vector *trk_refpoint_y; + vector *trk_refpoint_z; + vector *trk_nChi2; + vector *trk_q; + vector *trk_nValid; + vector *trk_nInvalid; + vector *trk_nPixel; + vector *trk_nStrip; + vector *trk_nPixelLay; + vector *trk_nStripLay; + vector *trk_n3DLay; + vector *trk_nOuterLost; + vector *trk_nInnerLost; + vector *trk_algo; + vector *trk_originalAlgo; + vector *trk_algoMask; + vector *trk_stopReason; + vector *trk_isHP; + vector *trk_seedIdx; + vector *trk_vtxIdx; + vector > *trk_shareFrac; + vector > *trk_simTrkIdx; + vector > *trk_hitIdx; + vector > *trk_hitType; + vector *sim_event; + vector *sim_bunchCrossing; + vector *sim_pdgId; + vector > *sim_genPdgIds; + vector *sim_isFromBHadron; + vector *sim_px; + vector *sim_py; + vector *sim_pz; + vector *sim_pt; + vector *sim_eta; + vector *sim_phi; + vector *sim_pca_pt; + vector *sim_pca_eta; + vector *sim_pca_lambda; + vector *sim_pca_cotTheta; + vector *sim_pca_phi; + vector *sim_pca_dxy; + vector *sim_pca_dz; + vector *sim_q; + vector *sim_nValid; + vector *sim_nPixel; + vector *sim_nStrip; + vector *sim_nLay; + vector *sim_nPixelLay; + vector *sim_n3DLay; + vector > *sim_trkIdx; + vector > *sim_shareFrac; + vector > *sim_seedIdx; + vector *sim_parentVtxIdx; + vector > *sim_decayVtxIdx; + vector > *sim_simHitIdx; + vector *pix_isBarrel; + vector *pix_det; + vector *pix_lay; + vector *pix_detId; + vector > *pix_trkIdx; + vector > *pix_seeIdx; + vector > *pix_simHitIdx; + vector > *pix_chargeFraction; + vector *pix_simType; + vector *pix_x; + vector *pix_y; + vector *pix_z; + vector *pix_xx; + vector *pix_xy; + vector *pix_yy; + vector *pix_yz; + vector *pix_zz; + vector *pix_zx; + vector *pix_radL; + vector *pix_bbxi; + vector *str_isBarrel; + vector *str_isStereo; + vector *str_det; + vector *str_lay; + vector *str_detId; + vector > *str_trkIdx; + vector > *str_seeIdx; + vector > *str_simHitIdx; + vector > *str_chargeFraction; + vector *str_simType; + vector *str_x; + vector *str_y; + vector *str_z; + vector *str_xx; + vector *str_xy; + vector *str_yy; + vector *str_yz; + vector *str_zz; + vector *str_zx; + vector *str_radL; + vector *str_bbxi; + vector *glu_isBarrel; + vector *glu_det; + vector *glu_lay; + vector *glu_detId; + vector *glu_monoIdx; + vector *glu_stereoIdx; + vector > *glu_seeIdx; + vector *glu_x; + vector *glu_y; + vector *glu_z; + vector *glu_xx; + vector *glu_xy; + vector *glu_yy; + vector *glu_yz; + vector *glu_zz; + vector *glu_zx; + vector *glu_radL; + vector *glu_bbxi; + vector *inv_isBarrel; + vector *inv_det; + vector *inv_lay; + vector *inv_detId; + vector *inv_type; + vector *simhit_det; + vector *simhit_lay; + vector *simhit_detId; + vector *simhit_x; + vector *simhit_y; + vector *simhit_z; + vector *simhit_px; + vector *simhit_py; + vector *simhit_pz; + vector *simhit_particle; + vector *simhit_process; + vector *simhit_eloss; + vector *simhit_tof; + vector *simhit_simTrkIdx; + vector > *simhit_hitIdx; + vector > *simhit_hitType; + Float_t bsp_x; + Float_t bsp_y; + Float_t bsp_z; + Float_t bsp_sigmax; + Float_t bsp_sigmay; + Float_t bsp_sigmaz; + vector *see_fitok; + vector *see_px; + vector *see_py; + vector *see_pz; + vector *see_pt; + vector *see_eta; + vector *see_phi; + vector *see_dxy; + vector *see_dz; + vector *see_ptErr; + vector *see_etaErr; + vector *see_phiErr; + vector *see_dxyErr; + vector *see_dzErr; + vector *see_chi2; + vector *see_statePt; + vector *see_stateTrajX; + vector *see_stateTrajY; + vector *see_stateTrajPx; + vector *see_stateTrajPy; + vector *see_stateTrajPz; + vector *see_q; + vector *see_nValid; + vector *see_nPixel; + vector *see_nGlued; + vector *see_nStrip; + vector *see_nPhase2OT; + vector *see_algo; + vector *see_stopReason; + vector *see_trkIdx; + vector > *see_shareFrac; + vector > *see_simTrkIdx; + vector > *see_hitIdx; + vector > *see_hitType; + vector *see_offset; + vector *vtx_x; + vector *vtx_y; + vector *vtx_z; + vector *vtx_xErr; + vector *vtx_yErr; + vector *vtx_zErr; + vector *vtx_ndof; + vector *vtx_chi2; + vector *vtx_fake; + vector *vtx_valid; + vector > *vtx_trkIdx; + vector *simvtx_event; + vector *simvtx_bunchCrossing; + vector *simvtx_processType; + vector *simvtx_x; + vector *simvtx_y; + vector *simvtx_z; + vector > *simvtx_sourceSimIdx; + vector > *simvtx_daughterSimIdx; + vector *simpv_idx; + + // List of branches + TBranch *b_event; //! + TBranch *b_lumi; //! + TBranch *b_run; //! + TBranch *b_trk_px; //! + TBranch *b_trk_py; //! + TBranch *b_trk_pz; //! + TBranch *b_trk_pt; //! + TBranch *b_trk_inner_px; //! + TBranch *b_trk_inner_py; //! + TBranch *b_trk_inner_pz; //! + TBranch *b_trk_inner_pt; //! + TBranch *b_trk_outer_px; //! + TBranch *b_trk_outer_py; //! + TBranch *b_trk_outer_pz; //! + TBranch *b_trk_outer_pt; //! + TBranch *b_trk_eta; //! + TBranch *b_trk_lambda; //! + TBranch *b_trk_cotTheta; //! + TBranch *b_trk_phi; //! + TBranch *b_trk_dxy; //! + TBranch *b_trk_dz; //! + TBranch *b_trk_ptErr; //! + TBranch *b_trk_etaErr; //! + TBranch *b_trk_lambdaErr; //! + TBranch *b_trk_phiErr; //! + TBranch *b_trk_dxyErr; //! + TBranch *b_trk_dzErr; //! + TBranch *b_trk_refpoint_x; //! + TBranch *b_trk_refpoint_y; //! + TBranch *b_trk_refpoint_z; //! + TBranch *b_trk_nChi2; //! + TBranch *b_trk_q; //! + TBranch *b_trk_nValid; //! + TBranch *b_trk_nInvalid; //! + TBranch *b_trk_nPixel; //! + TBranch *b_trk_nStrip; //! + TBranch *b_trk_nPixelLay; //! + TBranch *b_trk_nStripLay; //! + TBranch *b_trk_n3DLay; //! + TBranch *b_trk_nOuterLost; //! + TBranch *b_trk_nInnerLost; //! + TBranch *b_trk_algo; //! + TBranch *b_trk_originalAlgo; //! + TBranch *b_trk_algoMask; //! + TBranch *b_trk_stopReason; //! + TBranch *b_trk_isHP; //! + TBranch *b_trk_seedIdx; //! + TBranch *b_trk_vtxIdx; //! + TBranch *b_trk_shareFrac; //! + TBranch *b_trk_simTrkIdx; //! + TBranch *b_trk_hitIdx; //! + TBranch *b_trk_hitType; //! + TBranch *b_sim_event; //! + TBranch *b_sim_bunchCrossing; //! + TBranch *b_sim_pdgId; //! + TBranch *b_sim_genPdgIds; //! + TBranch *b_sim_isFromBHadron; //! + TBranch *b_sim_px; //! + TBranch *b_sim_py; //! + TBranch *b_sim_pz; //! + TBranch *b_sim_pt; //! + TBranch *b_sim_eta; //! + TBranch *b_sim_phi; //! + TBranch *b_sim_pca_pt; //! + TBranch *b_sim_pca_eta; //! + TBranch *b_sim_pca_lambda; //! + TBranch *b_sim_pca_cotTheta; //! + TBranch *b_sim_pca_phi; //! + TBranch *b_sim_pca_dxy; //! + TBranch *b_sim_pca_dz; //! + TBranch *b_sim_q; //! + TBranch *b_sim_nValid; //! + TBranch *b_sim_nPixel; //! + TBranch *b_sim_nStrip; //! + TBranch *b_sim_nLay; //! + TBranch *b_sim_nPixelLay; //! + TBranch *b_sim_n3DLay; //! + TBranch *b_sim_trkIdx; //! + TBranch *b_sim_shareFrac; //! + TBranch *b_sim_seedIdx; //! + TBranch *b_sim_parentVtxIdx; //! + TBranch *b_sim_decayVtxIdx; //! + TBranch *b_sim_simHitIdx; //! + TBranch *b_pix_isBarrel; //! + TBranch *b_pix_det; //! + TBranch *b_pix_lay; //! + TBranch *b_pix_detId; //! + TBranch *b_pix_trkIdx; //! + TBranch *b_pix_seeIdx; //! + TBranch *b_pix_simHitIdx; //! + TBranch *b_pix_chargeFraction; //! + TBranch *b_pix_simType; //! + TBranch *b_pix_x; //! + TBranch *b_pix_y; //! + TBranch *b_pix_z; //! + TBranch *b_pix_xx; //! + TBranch *b_pix_xy; //! + TBranch *b_pix_yy; //! + TBranch *b_pix_yz; //! + TBranch *b_pix_zz; //! + TBranch *b_pix_zx; //! + TBranch *b_pix_radL; //! + TBranch *b_pix_bbxi; //! + TBranch *b_str_isBarrel; //! + TBranch *b_str_isStereo; //! + TBranch *b_str_det; //! + TBranch *b_str_lay; //! + TBranch *b_str_detId; //! + TBranch *b_str_trkIdx; //! + TBranch *b_str_seeIdx; //! + TBranch *b_str_simHitIdx; //! + TBranch *b_str_chargeFraction; //! + TBranch *b_str_simType; //! + TBranch *b_str_x; //! + TBranch *b_str_y; //! + TBranch *b_str_z; //! + TBranch *b_str_xx; //! + TBranch *b_str_xy; //! + TBranch *b_str_yy; //! + TBranch *b_str_yz; //! + TBranch *b_str_zz; //! + TBranch *b_str_zx; //! + TBranch *b_str_radL; //! + TBranch *b_str_bbxi; //! + TBranch *b_glu_isBarrel; //! + TBranch *b_glu_det; //! + TBranch *b_glu_lay; //! + TBranch *b_glu_detId; //! + TBranch *b_glu_monoIdx; //! + TBranch *b_glu_stereoIdx; //! + TBranch *b_glu_seeIdx; //! + TBranch *b_glu_x; //! + TBranch *b_glu_y; //! + TBranch *b_glu_z; //! + TBranch *b_glu_xx; //! + TBranch *b_glu_xy; //! + TBranch *b_glu_yy; //! + TBranch *b_glu_yz; //! + TBranch *b_glu_zz; //! + TBranch *b_glu_zx; //! + TBranch *b_glu_radL; //! + TBranch *b_glu_bbxi; //! + TBranch *b_inv_isBarrel; //! + TBranch *b_inv_det; //! + TBranch *b_inv_lay; //! + TBranch *b_inv_detId; //! + TBranch *b_inv_type; //! + TBranch *b_simhit_det; //! + TBranch *b_simhit_lay; //! + TBranch *b_simhit_detId; //! + TBranch *b_simhit_x; //! + TBranch *b_simhit_y; //! + TBranch *b_simhit_z; //! + TBranch *b_simhit_px; //! + TBranch *b_simhit_py; //! + TBranch *b_simhit_pz; //! + TBranch *b_simhit_particle; //! + TBranch *b_simhit_process; //! + TBranch *b_simhit_eloss; //! + TBranch *b_simhit_tof; //! + TBranch *b_simhit_simTrkIdx; //! + TBranch *b_simhit_hitIdx; //! + TBranch *b_simhit_hitType; //! + TBranch *b_bsp_x; //! + TBranch *b_bsp_y; //! + TBranch *b_bsp_z; //! + TBranch *b_bsp_sigmax; //! + TBranch *b_bsp_sigmay; //! + TBranch *b_bsp_sigmaz; //! + TBranch *b_see_fitok; //! + TBranch *b_see_px; //! + TBranch *b_see_py; //! + TBranch *b_see_pz; //! + TBranch *b_see_pt; //! + TBranch *b_see_eta; //! + TBranch *b_see_phi; //! + TBranch *b_see_dxy; //! + TBranch *b_see_dz; //! + TBranch *b_see_ptErr; //! + TBranch *b_see_etaErr; //! + TBranch *b_see_phiErr; //! + TBranch *b_see_dxyErr; //! + TBranch *b_see_dzErr; //! + TBranch *b_see_chi2; //! + TBranch *b_see_statePt; //! + TBranch *b_see_stateTrajX; //! + TBranch *b_see_stateTrajY; //! + TBranch *b_see_stateTrajPx; //! + TBranch *b_see_stateTrajPy; //! + TBranch *b_see_stateTrajPz; //! + TBranch *b_see_q; //! + TBranch *b_see_nValid; //! + TBranch *b_see_nPixel; //! + TBranch *b_see_nGlued; //! + TBranch *b_see_nStrip; //! + TBranch *b_see_nPhase2OT; //! + TBranch *b_see_algo; //! + TBranch *b_see_stopReason; //! + TBranch *b_see_trkIdx; //! + TBranch *b_see_shareFrac; //! + TBranch *b_see_simTrkIdx; //! + TBranch *b_see_hitIdx; //! + TBranch *b_see_hitType; //! + TBranch *b_see_offset; //! + TBranch *b_vtx_x; //! + TBranch *b_vtx_y; //! + TBranch *b_vtx_z; //! + TBranch *b_vtx_xErr; //! + TBranch *b_vtx_yErr; //! + TBranch *b_vtx_zErr; //! + TBranch *b_vtx_ndof; //! + TBranch *b_vtx_chi2; //! + TBranch *b_vtx_fake; //! + TBranch *b_vtx_valid; //! + TBranch *b_vtx_trkIdx; //! + TBranch *b_simvtx_event; //! + TBranch *b_simvtx_bunchCrossing; //! + TBranch *b_simvtx_processType; //! + TBranch *b_simvtx_x; //! + TBranch *b_simvtx_y; //! + TBranch *b_simvtx_z; //! + TBranch *b_simvtx_sourceSimIdx; //! + TBranch *b_simvtx_daughterSimIdx; //! + TBranch *b_simpv_idx; //! + + tnc(TTree *tree=0); + virtual ~tnc(); + virtual Int_t Cut(Long64_t entry); + virtual Int_t GetEntry(Long64_t entry); + virtual Long64_t LoadTree(Long64_t entry); + virtual void Init(TTree *tree); + virtual void Loop(); + virtual Bool_t Notify(); + virtual void Show(Long64_t entry = -1); + + void CreateBBS(); + + TEvePointSetArray *FillEPS(); +}; + +#endif + +#ifdef tnc_cxx +tnc::tnc(TTree *tree) : fChain(0) +{ +// if parameter tree is not specified (or zero), connect the file +// used to generate this class and read the Tree. + if (tree == 0) { + TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject("trackingNtuple.root"); + if (!f || !f->IsOpen()) { + f = new TFile("trackingNtuple.root"); + } + TDirectory * dir = (TDirectory*)f->Get("trackingNtuple.root:/trackingNtuple"); + dir->GetObject("tree",tree); + + } + Init(tree); +} + +tnc::~tnc() +{ + if (!fChain) return; + delete fChain->GetCurrentFile(); +} + +Int_t tnc::GetEntry(Long64_t entry) +{ +// Read contents of entry. + if (!fChain) return 0; + return fChain->GetEntry(entry); +} +Long64_t tnc::LoadTree(Long64_t entry) +{ +// Set the environment to read one entry + if (!fChain) return -5; + Long64_t centry = fChain->LoadTree(entry); + if (centry < 0) return centry; + if (fChain->GetTreeNumber() != fCurrent) { + fCurrent = fChain->GetTreeNumber(); + Notify(); + } + return centry; +} + +void tnc::Init(TTree *tree) +{ + // The Init() function is called when the selector needs to initialize + // a new tree or chain. Typically here the branch addresses and branch + // pointers of the tree will be set. + // It is normally not necessary to make changes to the generated + // code, but the routine can be extended by the user if needed. + // Init() will be called many times when running on PROOF + // (once per file to be processed). + + // Set object pointer + trk_px = 0; + trk_py = 0; + trk_pz = 0; + trk_pt = 0; + trk_inner_px = 0; + trk_inner_py = 0; + trk_inner_pz = 0; + trk_inner_pt = 0; + trk_outer_px = 0; + trk_outer_py = 0; + trk_outer_pz = 0; + trk_outer_pt = 0; + trk_eta = 0; + trk_lambda = 0; + trk_cotTheta = 0; + trk_phi = 0; + trk_dxy = 0; + trk_dz = 0; + trk_ptErr = 0; + trk_etaErr = 0; + trk_lambdaErr = 0; + trk_phiErr = 0; + trk_dxyErr = 0; + trk_dzErr = 0; + trk_refpoint_x = 0; + trk_refpoint_y = 0; + trk_refpoint_z = 0; + trk_nChi2 = 0; + trk_q = 0; + trk_nValid = 0; + trk_nInvalid = 0; + trk_nPixel = 0; + trk_nStrip = 0; + trk_nPixelLay = 0; + trk_nStripLay = 0; + trk_n3DLay = 0; + trk_nOuterLost = 0; + trk_nInnerLost = 0; + trk_algo = 0; + trk_originalAlgo = 0; + trk_algoMask = 0; + trk_stopReason = 0; + trk_isHP = 0; + trk_seedIdx = 0; + trk_vtxIdx = 0; + trk_shareFrac = 0; + trk_simTrkIdx = 0; + trk_hitIdx = 0; + trk_hitType = 0; + sim_event = 0; + sim_bunchCrossing = 0; + sim_pdgId = 0; + sim_genPdgIds = 0; + sim_isFromBHadron = 0; + sim_px = 0; + sim_py = 0; + sim_pz = 0; + sim_pt = 0; + sim_eta = 0; + sim_phi = 0; + sim_pca_pt = 0; + sim_pca_eta = 0; + sim_pca_lambda = 0; + sim_pca_cotTheta = 0; + sim_pca_phi = 0; + sim_pca_dxy = 0; + sim_pca_dz = 0; + sim_q = 0; + sim_nValid = 0; + sim_nPixel = 0; + sim_nStrip = 0; + sim_nLay = 0; + sim_nPixelLay = 0; + sim_n3DLay = 0; + sim_trkIdx = 0; + sim_shareFrac = 0; + sim_seedIdx = 0; + sim_parentVtxIdx = 0; + sim_decayVtxIdx = 0; + sim_simHitIdx = 0; + pix_isBarrel = 0; + pix_det = 0; + pix_lay = 0; + pix_detId = 0; + pix_trkIdx = 0; + pix_seeIdx = 0; + pix_simHitIdx = 0; + pix_chargeFraction = 0; + pix_simType = 0; + pix_x = 0; + pix_y = 0; + pix_z = 0; + pix_xx = 0; + pix_xy = 0; + pix_yy = 0; + pix_yz = 0; + pix_zz = 0; + pix_zx = 0; + pix_radL = 0; + pix_bbxi = 0; + str_isBarrel = 0; + str_isStereo = 0; + str_det = 0; + str_lay = 0; + str_detId = 0; + str_trkIdx = 0; + str_seeIdx = 0; + str_simHitIdx = 0; + str_chargeFraction = 0; + str_simType = 0; + str_x = 0; + str_y = 0; + str_z = 0; + str_xx = 0; + str_xy = 0; + str_yy = 0; + str_yz = 0; + str_zz = 0; + str_zx = 0; + str_radL = 0; + str_bbxi = 0; + glu_isBarrel = 0; + glu_det = 0; + glu_lay = 0; + glu_detId = 0; + glu_monoIdx = 0; + glu_stereoIdx = 0; + glu_seeIdx = 0; + glu_x = 0; + glu_y = 0; + glu_z = 0; + glu_xx = 0; + glu_xy = 0; + glu_yy = 0; + glu_yz = 0; + glu_zz = 0; + glu_zx = 0; + glu_radL = 0; + glu_bbxi = 0; + inv_isBarrel = 0; + inv_det = 0; + inv_lay = 0; + inv_detId = 0; + inv_type = 0; + simhit_det = 0; + simhit_lay = 0; + simhit_detId = 0; + simhit_x = 0; + simhit_y = 0; + simhit_z = 0; + simhit_px = 0; + simhit_py = 0; + simhit_pz = 0; + simhit_particle = 0; + simhit_process = 0; + simhit_eloss = 0; + simhit_tof = 0; + simhit_simTrkIdx = 0; + simhit_hitIdx = 0; + simhit_hitType = 0; + see_fitok = 0; + see_px = 0; + see_py = 0; + see_pz = 0; + see_pt = 0; + see_eta = 0; + see_phi = 0; + see_dxy = 0; + see_dz = 0; + see_ptErr = 0; + see_etaErr = 0; + see_phiErr = 0; + see_dxyErr = 0; + see_dzErr = 0; + see_chi2 = 0; + see_statePt = 0; + see_stateTrajX = 0; + see_stateTrajY = 0; + see_stateTrajPx = 0; + see_stateTrajPy = 0; + see_stateTrajPz = 0; + see_q = 0; + see_nValid = 0; + see_nPixel = 0; + see_nGlued = 0; + see_nStrip = 0; + see_nPhase2OT = 0; + see_algo = 0; + see_stopReason = 0; + see_trkIdx = 0; + see_shareFrac = 0; + see_simTrkIdx = 0; + see_hitIdx = 0; + see_hitType = 0; + see_offset = 0; + vtx_x = 0; + vtx_y = 0; + vtx_z = 0; + vtx_xErr = 0; + vtx_yErr = 0; + vtx_zErr = 0; + vtx_ndof = 0; + vtx_chi2 = 0; + vtx_fake = 0; + vtx_valid = 0; + vtx_trkIdx = 0; + simvtx_event = 0; + simvtx_bunchCrossing = 0; + simvtx_processType = 0; + simvtx_x = 0; + simvtx_y = 0; + simvtx_z = 0; + simvtx_sourceSimIdx = 0; + simvtx_daughterSimIdx = 0; + simpv_idx = 0; + // Set branch addresses and branch pointers + if (!tree) return; + fChain = tree; + fCurrent = -1; + fChain->SetMakeClass(1); + + fChain->SetBranchAddress("event", &event, &b_event); + fChain->SetBranchAddress("lumi", &lumi, &b_lumi); + fChain->SetBranchAddress("run", &run, &b_run); + fChain->SetBranchAddress("trk_px", &trk_px, &b_trk_px); + fChain->SetBranchAddress("trk_py", &trk_py, &b_trk_py); + fChain->SetBranchAddress("trk_pz", &trk_pz, &b_trk_pz); + fChain->SetBranchAddress("trk_pt", &trk_pt, &b_trk_pt); + fChain->SetBranchAddress("trk_inner_px", &trk_inner_px, &b_trk_inner_px); + fChain->SetBranchAddress("trk_inner_py", &trk_inner_py, &b_trk_inner_py); + fChain->SetBranchAddress("trk_inner_pz", &trk_inner_pz, &b_trk_inner_pz); + fChain->SetBranchAddress("trk_inner_pt", &trk_inner_pt, &b_trk_inner_pt); + fChain->SetBranchAddress("trk_outer_px", &trk_outer_px, &b_trk_outer_px); + fChain->SetBranchAddress("trk_outer_py", &trk_outer_py, &b_trk_outer_py); + fChain->SetBranchAddress("trk_outer_pz", &trk_outer_pz, &b_trk_outer_pz); + fChain->SetBranchAddress("trk_outer_pt", &trk_outer_pt, &b_trk_outer_pt); + fChain->SetBranchAddress("trk_eta", &trk_eta, &b_trk_eta); + fChain->SetBranchAddress("trk_lambda", &trk_lambda, &b_trk_lambda); + fChain->SetBranchAddress("trk_cotTheta", &trk_cotTheta, &b_trk_cotTheta); + fChain->SetBranchAddress("trk_phi", &trk_phi, &b_trk_phi); + fChain->SetBranchAddress("trk_dxy", &trk_dxy, &b_trk_dxy); + fChain->SetBranchAddress("trk_dz", &trk_dz, &b_trk_dz); + fChain->SetBranchAddress("trk_ptErr", &trk_ptErr, &b_trk_ptErr); + fChain->SetBranchAddress("trk_etaErr", &trk_etaErr, &b_trk_etaErr); + fChain->SetBranchAddress("trk_lambdaErr", &trk_lambdaErr, &b_trk_lambdaErr); + fChain->SetBranchAddress("trk_phiErr", &trk_phiErr, &b_trk_phiErr); + fChain->SetBranchAddress("trk_dxyErr", &trk_dxyErr, &b_trk_dxyErr); + fChain->SetBranchAddress("trk_dzErr", &trk_dzErr, &b_trk_dzErr); + fChain->SetBranchAddress("trk_refpoint_x", &trk_refpoint_x, &b_trk_refpoint_x); + fChain->SetBranchAddress("trk_refpoint_y", &trk_refpoint_y, &b_trk_refpoint_y); + fChain->SetBranchAddress("trk_refpoint_z", &trk_refpoint_z, &b_trk_refpoint_z); + fChain->SetBranchAddress("trk_nChi2", &trk_nChi2, &b_trk_nChi2); + fChain->SetBranchAddress("trk_q", &trk_q, &b_trk_q); + fChain->SetBranchAddress("trk_nValid", &trk_nValid, &b_trk_nValid); + fChain->SetBranchAddress("trk_nInvalid", &trk_nInvalid, &b_trk_nInvalid); + fChain->SetBranchAddress("trk_nPixel", &trk_nPixel, &b_trk_nPixel); + fChain->SetBranchAddress("trk_nStrip", &trk_nStrip, &b_trk_nStrip); + fChain->SetBranchAddress("trk_nPixelLay", &trk_nPixelLay, &b_trk_nPixelLay); + fChain->SetBranchAddress("trk_nStripLay", &trk_nStripLay, &b_trk_nStripLay); + fChain->SetBranchAddress("trk_n3DLay", &trk_n3DLay, &b_trk_n3DLay); + fChain->SetBranchAddress("trk_nOuterLost", &trk_nOuterLost, &b_trk_nOuterLost); + fChain->SetBranchAddress("trk_nInnerLost", &trk_nInnerLost, &b_trk_nInnerLost); + fChain->SetBranchAddress("trk_algo", &trk_algo, &b_trk_algo); + fChain->SetBranchAddress("trk_originalAlgo", &trk_originalAlgo, &b_trk_originalAlgo); + fChain->SetBranchAddress("trk_algoMask", &trk_algoMask, &b_trk_algoMask); + fChain->SetBranchAddress("trk_stopReason", &trk_stopReason, &b_trk_stopReason); + fChain->SetBranchAddress("trk_isHP", &trk_isHP, &b_trk_isHP); + fChain->SetBranchAddress("trk_seedIdx", &trk_seedIdx, &b_trk_seedIdx); + fChain->SetBranchAddress("trk_vtxIdx", &trk_vtxIdx, &b_trk_vtxIdx); + fChain->SetBranchAddress("trk_shareFrac", &trk_shareFrac, &b_trk_shareFrac); + fChain->SetBranchAddress("trk_simTrkIdx", &trk_simTrkIdx, &b_trk_simTrkIdx); + fChain->SetBranchAddress("trk_hitIdx", &trk_hitIdx, &b_trk_hitIdx); + fChain->SetBranchAddress("trk_hitType", &trk_hitType, &b_trk_hitType); + fChain->SetBranchAddress("sim_event", &sim_event, &b_sim_event); + fChain->SetBranchAddress("sim_bunchCrossing", &sim_bunchCrossing, &b_sim_bunchCrossing); + fChain->SetBranchAddress("sim_pdgId", &sim_pdgId, &b_sim_pdgId); + fChain->SetBranchAddress("sim_genPdgIds", &sim_genPdgIds, &b_sim_genPdgIds); + fChain->SetBranchAddress("sim_isFromBHadron", &sim_isFromBHadron, &b_sim_isFromBHadron); + fChain->SetBranchAddress("sim_px", &sim_px, &b_sim_px); + fChain->SetBranchAddress("sim_py", &sim_py, &b_sim_py); + fChain->SetBranchAddress("sim_pz", &sim_pz, &b_sim_pz); + fChain->SetBranchAddress("sim_pt", &sim_pt, &b_sim_pt); + fChain->SetBranchAddress("sim_eta", &sim_eta, &b_sim_eta); + fChain->SetBranchAddress("sim_phi", &sim_phi, &b_sim_phi); + fChain->SetBranchAddress("sim_pca_pt", &sim_pca_pt, &b_sim_pca_pt); + fChain->SetBranchAddress("sim_pca_eta", &sim_pca_eta, &b_sim_pca_eta); + fChain->SetBranchAddress("sim_pca_lambda", &sim_pca_lambda, &b_sim_pca_lambda); + fChain->SetBranchAddress("sim_pca_cotTheta", &sim_pca_cotTheta, &b_sim_pca_cotTheta); + fChain->SetBranchAddress("sim_pca_phi", &sim_pca_phi, &b_sim_pca_phi); + fChain->SetBranchAddress("sim_pca_dxy", &sim_pca_dxy, &b_sim_pca_dxy); + fChain->SetBranchAddress("sim_pca_dz", &sim_pca_dz, &b_sim_pca_dz); + fChain->SetBranchAddress("sim_q", &sim_q, &b_sim_q); + fChain->SetBranchAddress("sim_nValid", &sim_nValid, &b_sim_nValid); + fChain->SetBranchAddress("sim_nPixel", &sim_nPixel, &b_sim_nPixel); + fChain->SetBranchAddress("sim_nStrip", &sim_nStrip, &b_sim_nStrip); + fChain->SetBranchAddress("sim_nLay", &sim_nLay, &b_sim_nLay); + fChain->SetBranchAddress("sim_nPixelLay", &sim_nPixelLay, &b_sim_nPixelLay); + fChain->SetBranchAddress("sim_n3DLay", &sim_n3DLay, &b_sim_n3DLay); + fChain->SetBranchAddress("sim_trkIdx", &sim_trkIdx, &b_sim_trkIdx); + fChain->SetBranchAddress("sim_shareFrac", &sim_shareFrac, &b_sim_shareFrac); + fChain->SetBranchAddress("sim_seedIdx", &sim_seedIdx, &b_sim_seedIdx); + fChain->SetBranchAddress("sim_parentVtxIdx", &sim_parentVtxIdx, &b_sim_parentVtxIdx); + fChain->SetBranchAddress("sim_decayVtxIdx", &sim_decayVtxIdx, &b_sim_decayVtxIdx); + fChain->SetBranchAddress("sim_simHitIdx", &sim_simHitIdx, &b_sim_simHitIdx); + fChain->SetBranchAddress("pix_isBarrel", &pix_isBarrel, &b_pix_isBarrel); + fChain->SetBranchAddress("pix_det", &pix_det, &b_pix_det); + fChain->SetBranchAddress("pix_lay", &pix_lay, &b_pix_lay); + fChain->SetBranchAddress("pix_detId", &pix_detId, &b_pix_detId); + fChain->SetBranchAddress("pix_trkIdx", &pix_trkIdx, &b_pix_trkIdx); + fChain->SetBranchAddress("pix_seeIdx", &pix_seeIdx, &b_pix_seeIdx); + fChain->SetBranchAddress("pix_simHitIdx", &pix_simHitIdx, &b_pix_simHitIdx); + fChain->SetBranchAddress("pix_chargeFraction", &pix_chargeFraction, &b_pix_chargeFraction); + fChain->SetBranchAddress("pix_simType", &pix_simType, &b_pix_simType); + fChain->SetBranchAddress("pix_x", &pix_x, &b_pix_x); + fChain->SetBranchAddress("pix_y", &pix_y, &b_pix_y); + fChain->SetBranchAddress("pix_z", &pix_z, &b_pix_z); + fChain->SetBranchAddress("pix_xx", &pix_xx, &b_pix_xx); + fChain->SetBranchAddress("pix_xy", &pix_xy, &b_pix_xy); + fChain->SetBranchAddress("pix_yy", &pix_yy, &b_pix_yy); + fChain->SetBranchAddress("pix_yz", &pix_yz, &b_pix_yz); + fChain->SetBranchAddress("pix_zz", &pix_zz, &b_pix_zz); + fChain->SetBranchAddress("pix_zx", &pix_zx, &b_pix_zx); + fChain->SetBranchAddress("pix_radL", &pix_radL, &b_pix_radL); + fChain->SetBranchAddress("pix_bbxi", &pix_bbxi, &b_pix_bbxi); + fChain->SetBranchAddress("str_isBarrel", &str_isBarrel, &b_str_isBarrel); + fChain->SetBranchAddress("str_isStereo", &str_isStereo, &b_str_isStereo); + fChain->SetBranchAddress("str_det", &str_det, &b_str_det); + fChain->SetBranchAddress("str_lay", &str_lay, &b_str_lay); + fChain->SetBranchAddress("str_detId", &str_detId, &b_str_detId); + fChain->SetBranchAddress("str_trkIdx", &str_trkIdx, &b_str_trkIdx); + fChain->SetBranchAddress("str_seeIdx", &str_seeIdx, &b_str_seeIdx); + fChain->SetBranchAddress("str_simHitIdx", &str_simHitIdx, &b_str_simHitIdx); + fChain->SetBranchAddress("str_chargeFraction", &str_chargeFraction, &b_str_chargeFraction); + fChain->SetBranchAddress("str_simType", &str_simType, &b_str_simType); + fChain->SetBranchAddress("str_x", &str_x, &b_str_x); + fChain->SetBranchAddress("str_y", &str_y, &b_str_y); + fChain->SetBranchAddress("str_z", &str_z, &b_str_z); + fChain->SetBranchAddress("str_xx", &str_xx, &b_str_xx); + fChain->SetBranchAddress("str_xy", &str_xy, &b_str_xy); + fChain->SetBranchAddress("str_yy", &str_yy, &b_str_yy); + fChain->SetBranchAddress("str_yz", &str_yz, &b_str_yz); + fChain->SetBranchAddress("str_zz", &str_zz, &b_str_zz); + fChain->SetBranchAddress("str_zx", &str_zx, &b_str_zx); + fChain->SetBranchAddress("str_radL", &str_radL, &b_str_radL); + fChain->SetBranchAddress("str_bbxi", &str_bbxi, &b_str_bbxi); + fChain->SetBranchAddress("glu_isBarrel", &glu_isBarrel, &b_glu_isBarrel); + fChain->SetBranchAddress("glu_det", &glu_det, &b_glu_det); + fChain->SetBranchAddress("glu_lay", &glu_lay, &b_glu_lay); + fChain->SetBranchAddress("glu_detId", &glu_detId, &b_glu_detId); + fChain->SetBranchAddress("glu_monoIdx", &glu_monoIdx, &b_glu_monoIdx); + fChain->SetBranchAddress("glu_stereoIdx", &glu_stereoIdx, &b_glu_stereoIdx); + fChain->SetBranchAddress("glu_seeIdx", &glu_seeIdx, &b_glu_seeIdx); + fChain->SetBranchAddress("glu_x", &glu_x, &b_glu_x); + fChain->SetBranchAddress("glu_y", &glu_y, &b_glu_y); + fChain->SetBranchAddress("glu_z", &glu_z, &b_glu_z); + fChain->SetBranchAddress("glu_xx", &glu_xx, &b_glu_xx); + fChain->SetBranchAddress("glu_xy", &glu_xy, &b_glu_xy); + fChain->SetBranchAddress("glu_yy", &glu_yy, &b_glu_yy); + fChain->SetBranchAddress("glu_yz", &glu_yz, &b_glu_yz); + fChain->SetBranchAddress("glu_zz", &glu_zz, &b_glu_zz); + fChain->SetBranchAddress("glu_zx", &glu_zx, &b_glu_zx); + fChain->SetBranchAddress("glu_radL", &glu_radL, &b_glu_radL); + fChain->SetBranchAddress("glu_bbxi", &glu_bbxi, &b_glu_bbxi); + fChain->SetBranchAddress("inv_isBarrel", &inv_isBarrel, &b_inv_isBarrel); + fChain->SetBranchAddress("inv_det", &inv_det, &b_inv_det); + fChain->SetBranchAddress("inv_lay", &inv_lay, &b_inv_lay); + fChain->SetBranchAddress("inv_detId", &inv_detId, &b_inv_detId); + fChain->SetBranchAddress("inv_type", &inv_type, &b_inv_type); + fChain->SetBranchAddress("simhit_det", &simhit_det, &b_simhit_det); + fChain->SetBranchAddress("simhit_lay", &simhit_lay, &b_simhit_lay); + fChain->SetBranchAddress("simhit_detId", &simhit_detId, &b_simhit_detId); + fChain->SetBranchAddress("simhit_x", &simhit_x, &b_simhit_x); + fChain->SetBranchAddress("simhit_y", &simhit_y, &b_simhit_y); + fChain->SetBranchAddress("simhit_z", &simhit_z, &b_simhit_z); + fChain->SetBranchAddress("simhit_px", &simhit_px, &b_simhit_px); + fChain->SetBranchAddress("simhit_py", &simhit_py, &b_simhit_py); + fChain->SetBranchAddress("simhit_pz", &simhit_pz, &b_simhit_pz); + fChain->SetBranchAddress("simhit_particle", &simhit_particle, &b_simhit_particle); + fChain->SetBranchAddress("simhit_process", &simhit_process, &b_simhit_process); + fChain->SetBranchAddress("simhit_eloss", &simhit_eloss, &b_simhit_eloss); + fChain->SetBranchAddress("simhit_tof", &simhit_tof, &b_simhit_tof); + fChain->SetBranchAddress("simhit_simTrkIdx", &simhit_simTrkIdx, &b_simhit_simTrkIdx); + fChain->SetBranchAddress("simhit_hitIdx", &simhit_hitIdx, &b_simhit_hitIdx); + fChain->SetBranchAddress("simhit_hitType", &simhit_hitType, &b_simhit_hitType); + fChain->SetBranchAddress("bsp_x", &bsp_x, &b_bsp_x); + fChain->SetBranchAddress("bsp_y", &bsp_y, &b_bsp_y); + fChain->SetBranchAddress("bsp_z", &bsp_z, &b_bsp_z); + fChain->SetBranchAddress("bsp_sigmax", &bsp_sigmax, &b_bsp_sigmax); + fChain->SetBranchAddress("bsp_sigmay", &bsp_sigmay, &b_bsp_sigmay); + fChain->SetBranchAddress("bsp_sigmaz", &bsp_sigmaz, &b_bsp_sigmaz); + fChain->SetBranchAddress("see_fitok", &see_fitok, &b_see_fitok); + fChain->SetBranchAddress("see_px", &see_px, &b_see_px); + fChain->SetBranchAddress("see_py", &see_py, &b_see_py); + fChain->SetBranchAddress("see_pz", &see_pz, &b_see_pz); + fChain->SetBranchAddress("see_pt", &see_pt, &b_see_pt); + fChain->SetBranchAddress("see_eta", &see_eta, &b_see_eta); + fChain->SetBranchAddress("see_phi", &see_phi, &b_see_phi); + fChain->SetBranchAddress("see_dxy", &see_dxy, &b_see_dxy); + fChain->SetBranchAddress("see_dz", &see_dz, &b_see_dz); + fChain->SetBranchAddress("see_ptErr", &see_ptErr, &b_see_ptErr); + fChain->SetBranchAddress("see_etaErr", &see_etaErr, &b_see_etaErr); + fChain->SetBranchAddress("see_phiErr", &see_phiErr, &b_see_phiErr); + fChain->SetBranchAddress("see_dxyErr", &see_dxyErr, &b_see_dxyErr); + fChain->SetBranchAddress("see_dzErr", &see_dzErr, &b_see_dzErr); + fChain->SetBranchAddress("see_chi2", &see_chi2, &b_see_chi2); + fChain->SetBranchAddress("see_statePt", &see_statePt, &b_see_statePt); + fChain->SetBranchAddress("see_stateTrajX", &see_stateTrajX, &b_see_stateTrajX); + fChain->SetBranchAddress("see_stateTrajY", &see_stateTrajY, &b_see_stateTrajY); + fChain->SetBranchAddress("see_stateTrajPx", &see_stateTrajPx, &b_see_stateTrajPx); + fChain->SetBranchAddress("see_stateTrajPy", &see_stateTrajPy, &b_see_stateTrajPy); + fChain->SetBranchAddress("see_stateTrajPz", &see_stateTrajPz, &b_see_stateTrajPz); + fChain->SetBranchAddress("see_q", &see_q, &b_see_q); + fChain->SetBranchAddress("see_nValid", &see_nValid, &b_see_nValid); + fChain->SetBranchAddress("see_nPixel", &see_nPixel, &b_see_nPixel); + fChain->SetBranchAddress("see_nGlued", &see_nGlued, &b_see_nGlued); + fChain->SetBranchAddress("see_nStrip", &see_nStrip, &b_see_nStrip); + fChain->SetBranchAddress("see_nPhase2OT", &see_nPhase2OT, &b_see_nPhase2OT); + fChain->SetBranchAddress("see_algo", &see_algo, &b_see_algo); + fChain->SetBranchAddress("see_stopReason", &see_stopReason, &b_see_stopReason); + fChain->SetBranchAddress("see_trkIdx", &see_trkIdx, &b_see_trkIdx); + fChain->SetBranchAddress("see_shareFrac", &see_shareFrac, &b_see_shareFrac); + fChain->SetBranchAddress("see_simTrkIdx", &see_simTrkIdx, &b_see_simTrkIdx); + fChain->SetBranchAddress("see_hitIdx", &see_hitIdx, &b_see_hitIdx); + fChain->SetBranchAddress("see_hitType", &see_hitType, &b_see_hitType); + fChain->SetBranchAddress("see_offset", &see_offset, &b_see_offset); + fChain->SetBranchAddress("vtx_x", &vtx_x, &b_vtx_x); + fChain->SetBranchAddress("vtx_y", &vtx_y, &b_vtx_y); + fChain->SetBranchAddress("vtx_z", &vtx_z, &b_vtx_z); + fChain->SetBranchAddress("vtx_xErr", &vtx_xErr, &b_vtx_xErr); + fChain->SetBranchAddress("vtx_yErr", &vtx_yErr, &b_vtx_yErr); + fChain->SetBranchAddress("vtx_zErr", &vtx_zErr, &b_vtx_zErr); + fChain->SetBranchAddress("vtx_ndof", &vtx_ndof, &b_vtx_ndof); + fChain->SetBranchAddress("vtx_chi2", &vtx_chi2, &b_vtx_chi2); + fChain->SetBranchAddress("vtx_fake", &vtx_fake, &b_vtx_fake); + fChain->SetBranchAddress("vtx_valid", &vtx_valid, &b_vtx_valid); + fChain->SetBranchAddress("vtx_trkIdx", &vtx_trkIdx, &b_vtx_trkIdx); + fChain->SetBranchAddress("simvtx_event", &simvtx_event, &b_simvtx_event); + fChain->SetBranchAddress("simvtx_bunchCrossing", &simvtx_bunchCrossing, &b_simvtx_bunchCrossing); + fChain->SetBranchAddress("simvtx_processType", &simvtx_processType, &b_simvtx_processType); + fChain->SetBranchAddress("simvtx_x", &simvtx_x, &b_simvtx_x); + fChain->SetBranchAddress("simvtx_y", &simvtx_y, &b_simvtx_y); + fChain->SetBranchAddress("simvtx_z", &simvtx_z, &b_simvtx_z); + fChain->SetBranchAddress("simvtx_sourceSimIdx", &simvtx_sourceSimIdx, &b_simvtx_sourceSimIdx); + fChain->SetBranchAddress("simvtx_daughterSimIdx", &simvtx_daughterSimIdx, &b_simvtx_daughterSimIdx); + fChain->SetBranchAddress("simpv_idx", &simpv_idx, &b_simpv_idx); + Notify(); +} + +Bool_t tnc::Notify() +{ + // The Notify() function is called when a new file is opened. This + // can be either for a new TTree in a TChain or when when a new TTree + // is started when using PROOF. It is normally not necessary to make changes + // to the generated code, but the routine can be extended by the + // user if needed. The return value is currently not used. + + return kTRUE; +} + +void tnc::Show(Long64_t entry) +{ +// Print contents of entry. +// If entry is not specified, print current entry + if (!fChain) return; + fChain->Show(entry); +} +Int_t tnc::Cut(Long64_t entry) +{ +// This function may be called from Loop. +// returns 1 if entry is accepted. +// returns -1 otherwise. + return 1; +} +#endif // #ifdef tnc_cxx diff --git a/Geoms/CMS/tncdefs.h b/Geoms/CMS/tncdefs.h new file mode 100644 index 0000000000000..2fe13c89a3e92 --- /dev/null +++ b/Geoms/CMS/tncdefs.h @@ -0,0 +1,157 @@ +#include +#include + +const int Mdet = 7, Mlay = 10; +const int Xlay[] = { -1, 5, 4, 5, 4, 7, 10 }; + +const bool isbrl[] = { 0, 1, 0, 1, 0, 1, 0 }; + +struct RZBox +{ + int m_cnt = 0; + float m_minr, m_maxr; + float m_minz, m_maxz; + + void fill(float r, float z) + { + if (m_cnt == 0) + { + m_minr = m_maxr = r; + m_minz = m_maxz = z; + } + else + { + if (r < m_minr) m_minr = r; + else if (r > m_maxr) m_maxr = r; + if (z < m_minz) m_minz = z; + else if (z > m_maxz) m_maxz = z; + } + ++m_cnt; + } + + void print(bool nl=true) + { + printf("r~[%.4f, %.4f] z~[%.4f, %.4f]%s", + m_minr, m_maxr, m_minz, m_maxz, nl ? "\n" : ""); + } + + RZBox Extend(float eps=0.05) const + { + float dr = eps * (m_maxr - m_minr); + float dz = eps * (m_maxz - m_minz); + + RZBox e = *this; + e.m_minr -= dr; e.m_maxr += dr; + e.m_minz -= dz; e.m_maxz += dz; + + return e; + } + + RZBox Round(double base=100) const + { + RZBox e; + e.m_cnt = m_cnt; + + e.m_minr = std::floor(m_minr * base) / base; + e.m_maxr = std::ceil (m_maxr * base) / base; + e.m_minz = std::floor(m_minz * base) / base; + e.m_maxz = std::ceil (m_maxz * base) / base; + + return e; + } + + void MergeWith(const RZBox &o) + { + if (m_cnt == 0) *this = o; + if (o.m_cnt == 0) return; + + m_cnt += o.m_cnt; + + m_minr = std::min(m_minr, o.m_minr); + m_maxr = std::max(m_maxr, o.m_maxr); + m_minz = std::min(m_minz, o.m_minz); + m_maxz = std::max(m_maxz, o.m_maxz); + } +}; + +struct BBS +{ + int cnt[Mdet][Mlay] = { 0 }; + RZBox b[Mdet][Mlay]; + RZBox p[Mdet][Mlay]; + RZBox n[Mdet][Mlay]; + + RZBox& select_rzbox(int det, int lay, float z) + { + if (isbrl[det]) return b[det][lay]; + return (z > 0) ? p[det][lay] : n[det][lay]; + } + + void reset() + { + for (int d = 1; d < Mdet; ++d) + { + for (int l = 1; l < Mlay; ++l) + { + cnt[d][l] = 0; + b[d][l].m_cnt = 0; + p[d][l].m_cnt = 0; + n[d][l].m_cnt = 0; + } + } + } + + void print() + { + for (int d = 1; d < Mdet; ++d) + { + printf("det %d, is_brl=%d:\n", d, isbrl[d]); + for (int l = 1; l < Xlay[d]; ++l) + { + if (isbrl[d]) + { + printf(" lay %d: cnt=%5d, ", l, cnt[d][l]); b[d][l].print(); + } + else + { + printf(" pos %d: cnt=%5d, ", l, p[d][l].m_cnt); p[d][l].print(); + printf(" neg %d: cnt=%5d, ", l, n[d][l].m_cnt); n[d][l].print(); + } + } + printf("\n"); + } + } + + void save(const char* fname="bbs.root") + { + auto f = TFile::Open(fname, "RECREATE"); + f->WriteObject(this, "bbs"); + f->Close(); + delete f; + } + + void load(const char* fname="bbs.root") + { + auto f = TFile::Open(fname); + if ( ! f) throw std::runtime_error("tnc::load could not open file"); + + BBS *b = 0; + gFile->GetObject("bbs", b); + if ( ! b) throw std::runtime_error("tnc::load could not read bbs"); + + b->print(); + memcpy(this, b, sizeof(BBS)); + + delete b; + f->Close(); + delete f; + } +}; + +void tncdefs() +{ + printf("tncdefs() loaded\n"); +} + +#pragma link C++ class RZBox; +#pragma link C++ class BBS; diff --git a/CylCowWLids.cc b/Geoms/CylCowWLids.cc similarity index 70% rename from CylCowWLids.cc rename to Geoms/CylCowWLids.cc index 112b0412e57f3..f804bdbdf4cac 100644 --- a/CylCowWLids.cc +++ b/Geoms/CylCowWLids.cc @@ -1,6 +1,23 @@ -#include "CylCowWLids.h" - -#include "TrackerInfo.h" +//--------------------------- +// Cylindrical Cow with Lids +//--------------------------- +// +// Intended coverage: |eta| < 2.4 with D_z_beam_spot = +-3 cm (3 sigma) +// B-layer extends to 2.55. +// Layers 1 and 2 have somewhat longer barrels. It is assumed +// those will be needed / used for seed finding. +// +// Layers 3 - 9: +// Barrel: 0.0 - 1.0 +// Transition: 1.0 - 1.4 +// Endcap: 1.4 - 2.4 +// +// Run root test/CylCowWLids.C to get a plot and dumps of +// edge coordinates and etas. +// +// Eta partitions for B / T / EC + +#include "../TrackerInfo.h" #include @@ -46,10 +63,8 @@ namespace li.m_layer_type = LayerInfo::Barrel; - li.m_rin = r - m_det_half_thickness; - li.m_rout = r + m_det_half_thickness; - li.m_zmin = -z; - li.m_zmax = z; + li.set_limits(r - m_det_half_thickness, r + m_det_half_thickness, -z, z); + li.m_propagate_to = li.m_rin; li.m_next_barrel = lid < 9 ? lid + 1 : -1; li.m_next_ecap_pos = lid < 9 ? lid + 1 + 9 : -1; @@ -60,6 +75,9 @@ namespace li.m_sibl_ecap_neg = lid > 0 ? lid + 18 : -1; li.m_is_outer = (lid == 9); + + li.m_q_bin = 2.0; + li.set_selection_limits(0.01, 0.05, 1.0, 2.0); } void add_barrel_r_eta(int lid, float r, float eta) @@ -87,10 +105,8 @@ namespace li.m_layer_type = LayerInfo::EndCapPos; - li.m_rin = r_end; - li.m_rout = r; - li.m_zmin = z - m_det_half_thickness; - li.m_zmax = z + m_det_half_thickness; + li.set_limits(r_end, r, z - m_det_half_thickness, z + m_det_half_thickness); + li.m_propagate_to = li.m_zmin; li.m_next_barrel = lid < 18 ? lid - 10 + 2 : -1; li.m_next_ecap_pos = lid < 18 ? lid + 1 : -1; @@ -101,6 +117,9 @@ namespace li.m_sibl_ecap_neg = -1; li.m_is_outer = (lid == 18); + + li.m_q_bin = 1.5; + li.set_selection_limits(0.01, 0.05, 1.0, 2.0); } { lid += 9; @@ -108,10 +127,8 @@ namespace li.m_layer_type = LayerInfo::EndCapNeg; - li.m_rin = r_end; - li.m_rout = r; - li.m_zmin = -z - m_det_half_thickness; - li.m_zmax = -z + m_det_half_thickness; + li.set_limits(r_end, r, -z - m_det_half_thickness, -z + m_det_half_thickness); + li.m_propagate_to = li.m_zmax; li.m_next_barrel = lid < 27 ? lid - 19 + 2 : -1; li.m_next_ecap_pos = -1; @@ -122,6 +139,9 @@ namespace li.m_sibl_ecap_neg = -1; li.m_is_outer = (lid == 27); + + li.m_q_bin = 1.5; + li.set_selection_limits(0.01, 0.05, 1.0, 2.0); } } @@ -190,24 +210,27 @@ namespace // + endcap disks at -z } }; -} -//============================================================================== + //============================================================================ -void Create_TrackerInfo(TrackerInfo& ti, bool verbose) -{ - CylCowWLidsCreator creator(ti); + void Create_CylCowWLids(TrackerInfo& ti, bool verbose) + { + CylCowWLidsCreator creator(ti); - creator.FillTrackerInfo(); + creator.FillTrackerInfo(); - if (verbose) { - printf("==========================================================================================\n"); - } - printf("CylCowWLids -- Create_TrackerInfo finished\n"); + if (verbose) { + printf("==========================================================================================\n"); + } + printf("Create_CylCowWLids -- creation complete\n"); - if (verbose) { - printf("==========================================================================================\n"); - for (auto &i : ti.m_layers) i.print_layer(); - printf("==========================================================================================\n"); + if (verbose) { + printf("==========================================================================================\n"); + for (auto &i : ti.m_layers) i.print_layer(); + printf("==========================================================================================\n"); + } } + } + +void* TrackerInfoCrator_ptr = (void*) Create_CylCowWLids; diff --git a/Geoms/Makefile b/Geoms/Makefile new file mode 100644 index 0000000000000..48dcf1fb3a9ac --- /dev/null +++ b/Geoms/Makefile @@ -0,0 +1,36 @@ +include ../Makefile.config + +CPPEXTRA := ${USER_CPPFLAGS} ${DEFS} -I.. +LDEXTRA := ${USER_LDFLAGS} + +CPPFLAGS := ${CPPEXTRA} ${CPPFLAGS} +CXXFLAGS += -fPIC ${USER_CXXFLAGS} +LDFLAGS += ${LDEXTRA} + +.PHONY: all clean distclean echo + +SRCS := $(wildcard *.cc) +DEPS := $(SRCS:.cc=.d) + +TGTS := $(SRCS:.cc=) + +ifeq (${CXX},icc) + TGTS += $(addsuffix -mic, ${TGTS}) +endif + +TGTS := $(addsuffix .so, ${TGTS}) + +all: ${TGTS} + +%.o: %.cc %.d + ${CXX} ${CPPFLAGS} ${CXXFLAGS} ${VEC_HOST} -c -o $@ $< + +%.so: %.o + ${CXX} -shared -o $@ $< + +ifeq ($(filter clean distclean, ${MAKECMDGOALS}),) +include ${DEPS} +endif + +clean: + rm -f *.so *.o *.d diff --git a/Makefile b/Makefile index faee305597763..fda5900a15e0e 100644 --- a/Makefile +++ b/Makefile @@ -1,22 +1,27 @@ include Makefile.config -TGTS := main +LIB_CORE := libMicCore.so +LIB_CORE_MIC := libMicCore-mic.so -EXES := ${TGTS} + +TGTS := ${LIB_CORE} main ifeq (${CXX},icc) - EXES += $(addsuffix -mic, ${TGTS}) + TGTS += ${LIB_CORE_MIC} main-mic endif .PHONY: all clean distclean -all: ${EXES} +all: ${TGTS} + cd Geoms && ${MAKE} cd mkFit && ${MAKE} SRCS := $(wildcard *.cc) OBJS := $(SRCS:.cc=.o) DEPS := $(SRCS:.cc=.d) +CORE_OBJS := $(filter-out main.o, ${OBJS}) + AUTO_TGTS := ifdef USE_MATRIPLEX @@ -35,7 +40,7 @@ include ${DEPS} endif clean-local: - -rm -f ${EXES} *.d *.o *.om *.so + -rm -f ${TGTS} *.d *.o *.om *.so -rm -rf main.dSYM -rm -rf USolids-{host,mic} @@ -48,8 +53,11 @@ distclean: clean-local cd Matriplex && ${MAKE} distclean cd mkFit && ${MAKE} distclean -main: ${AUTO_TGTS} ${OBJS} ${LIBUSOLIDS} - ${CXX} ${CXXFLAGS} ${VEC_HOST} -o $@ ${OBJS} ${LIBUSOLIDS} ${LDFLAGS} +${LIB_CORE}: ${CORE_OBJS} + ${CXX} ${CXXFLAGS} ${VEC_HOST} ${LDFLAGS} ${CORE_OBJS} -shared -o $@ ${LDFLAGS_HOST} ${LDFLAGS_CU} + +main: ${AUTO_TGTS} ${LIB_CORE} main.o ${LIBUSOLIDS} + ${CXX} ${CXXFLAGS} ${VEC_HOST} -o $@ main.o ${LIBUSOLIDS} ${LDFLAGS} -L. -lMicCore -Wl,-rpath=. ${OBJS}: %.o: %.cc %.d ${CXX} ${CPPFLAGS} ${CXXFLAGS} ${VEC_HOST} -c -o $@ $< @@ -60,11 +68,14 @@ ${LIBUSOLIDS} : USolids/CMakeLists.txt ifeq ($(CXX),icc) -OBJS_MIC := $(OBJS:.o=.om) +OBJS_MIC := $(OBJS:.o=.om) +CORE_OBJS_MIC := $(CORE_OBJS:.o=.om + +${LIB_CORE_MIC}: ${CORE_OBJS_MIC} + ${CXX} ${CXXFLAGS} ${VEC_MIC} ${LDFLAGS_NO_ROOT} ${CORE_OBJS_MIC} -shared -o $@ ${LDFLAGS_MIC} -main-mic: ${AUTO_TGTS} ${OBJS_MIC} ${LIBUSOLIDS_MIC} - ${CXX} ${CXXFLAGS} ${VEC_MIC} ${LDFLAGS_NO_ROOT} -o $@ ${OBJS_MIC} ${LIBUSOLIDS_MIC} - scp $@ mic0: +main-mic: ${AUTO_TGTS} ${LIB_CORE_MIC} ${LIBUSOLIDS_MIC} + ${CXX} ${CXXFLAGS} ${VEC_MIC} ${LDFLAGS_NO_ROOT} -o $@ main.om ${LIBUSOLIDS_MIC} ${LDFLAGS_MIC} -L. -lMicCore -Wl,-rpath=. ${LIBUSOLIDS_MIC} : USolids/CMakeLists.txt -mkdir USolids-mic diff --git a/Makefile.config b/Makefile.config index aded91889dcef..7852080a743e9 100644 --- a/Makefile.config +++ b/Makefile.config @@ -117,7 +117,7 @@ INWARD_FIT := -DINWARDFIT ################################################################ CPPFLAGS := -I. ${USE_MATRIPLEX} ${USE_INTRINSICS} -std=c++11 -CXXFLAGS := ${OPT} ${OSX_CXXFLAGS} +CXXFLAGS := -fPIC ${OPT} ${OSX_CXXFLAGS} LDFLAGS_HOST := LDFLAGS_MIC := diff --git a/TrackerInfo.cc b/TrackerInfo.cc index f66dcc93a2164..67cc1127edc46 100644 --- a/TrackerInfo.cc +++ b/TrackerInfo.cc @@ -2,6 +2,25 @@ #include + +void LayerInfo::set_limits(float r1, float r2, float z1, float z2) +{ + m_rin = r1; m_rout = r2; m_zmin = z1; m_zmax = z2; +} + +void LayerInfo::set_next_layers(int nb, int nep, int nen) +{ + m_next_barrel = nb; m_next_ecap_pos = nep; m_next_ecap_neg = nen; +} + +void LayerInfo::set_selection_limits(float p1, float p2, float q1, float q2) +{ + m_select_min_dphi = p1; m_select_max_dphi = p2; + m_select_min_dq = q1; m_select_max_dq = q2; +} + +//============================================================================== + bool TrackerInfo::are_layers_siblings(int l1, int l2) const { assert(l1 < m_layers.size() && l2 < m_layers.size()); @@ -13,3 +32,51 @@ bool TrackerInfo::are_layers_siblings(int l1, int l2) const else return l2 == i1.m_sibl_barrel; } + + +//============================================================================== +// Plugin Loader +//============================================================================== + +#include +#include +#include + +namespace +{ + const char *search_path[] = { "", "../Geoms/", "Geoms/", "../", 0 }; +} + +void TrackerInfo::ExecTrackerInfoCreatorPlugin(const std::string& base, TrackerInfo &ti, bool verbose) +{ + std::string soname = base + ".so"; + + struct stat st; + + int si = 0; + while (search_path[si]) + { + std::string path(search_path[si]); path += soname; + if (stat(path.c_str(), &st) == 0) + { + printf("TrackerInfo::ExecTrackerInfoCreatorPlugin processing '%s'\n", path.c_str()); + + void *h = dlopen(path.c_str(), RTLD_LAZY); + if (!h) { perror("dlopen failed"); exit(2); } + + long long* p2f = (long long*) dlsym(h, "TrackerInfoCrator_ptr"); + if (!p2f) { perror("dlsym failed"); exit(2); } + + TrackerInfoCreator_foo foo = (TrackerInfoCreator_foo)(*p2f); + foo(ti, verbose); + + dlclose(h); + return; + } + + ++si; + } + + fprintf(stderr, "TrackerInfo plugin '%s' not found in search path.\n", soname.c_str()); + exit(2); +} diff --git a/TrackerInfo.h b/TrackerInfo.h index ce129dd4f794c..44005930f1f1c 100644 --- a/TrackerInfo.h +++ b/TrackerInfo.h @@ -1,6 +1,7 @@ #ifndef TRACKERINFO_H #define TRACKERINFO_H +#include #include #include @@ -15,20 +16,31 @@ class LayerInfo LayerType_e m_layer_type; float m_rin, m_rout, m_zmin, m_zmax; + float m_propagate_to; int m_next_barrel, m_next_ecap_pos, m_next_ecap_neg; int m_sibl_barrel, m_sibl_ecap_pos, m_sibl_ecap_neg; bool m_is_outer; + // Selection limits + float m_q_bin; // > 0 - bin width, < 0 - number of bins + float m_select_min_dphi, m_select_max_dphi; + float m_select_min_dq, m_select_max_dq; + // Additional stuff needed? // * pixel / strip, mono / stereo - // * resolutions + // * resolutions, min/max search windows + // * holes in coverage // * functions / lambdas for deciding / calculating stuff // * ... // * pointers to hit containers - LayerInfo(int lid) : m_layer_id(lid) {} + LayerInfo(int lid) : m_layer_id(lid) { m_sibl_barrel, m_sibl_ecap_pos, m_sibl_ecap_neg = -1; } + + void set_limits(float r1, float r2, float z1, float z2); + void set_next_layers(int nb, int nep, int nen); + void set_selection_limits(float p1, float p2, float q1, float q2); float r_mean() const { return (m_rin + m_rout) / 2; } float z_mean() const { return (m_zmin + m_zmax) / 2; } @@ -44,6 +56,8 @@ class LayerInfo } }; +//============================================================================== + class TrackerInfo { private: @@ -110,6 +124,10 @@ class TrackerInfo if (l <= m_ecap_pos.back()) return Reg_Endcap_Pos; return Reg_Endcap_Neg; } + + static void ExecTrackerInfoCreatorPlugin(const std::string& base, TrackerInfo &ti, bool verbose=false); }; +typedef void (*TrackerInfoCreator_foo)(TrackerInfo&, bool verbose); + #endif diff --git a/cmssw-trackerinfo-desc.txt b/cmssw-trackerinfo-desc.txt index 3207e17159015..026e60f066596 100644 --- a/cmssw-trackerinfo-desc.txt +++ b/cmssw-trackerinfo-desc.txt @@ -20,6 +20,8 @@ CMSSW -> TrackerInfo layer numbering CMSSW uses detector (1 - 6) / layer numbering, our code uses a single layer index. +stereo = simhit_detId & 3; 0 - single layer, 1 - stereo, 2 - dual layer + *** 1. PIXB, 4 layers 1 -> 0 2 -> 1 diff --git a/mkFit/HitStructures.cc b/mkFit/HitStructures.cc index 3c0f78698432b..c0931bcdf52fd 100644 --- a/mkFit/HitStructures.cc +++ b/mkFit/HitStructures.cc @@ -4,32 +4,46 @@ #include "Ice/IceRevisitedRadix.h" -void LayerOfHits::SetupLayer(float qmin, float qmax, float dq, int layer, bool is_barrel) +void LayerOfHits::setup_bins(float qmin, float qmax, float dq) { + // Define layer with min/max and number of bins along q. + // XXXX MT: Could have n_phi bins per layer, too. - assert (m_nq == 0 && "SetupLayer() already called."); + if (dq < 0) + { + m_nq = (int) -dq; + m_qmin = qmin; + m_qmax = qmax; + } + else + { + float extent = qmax - qmin; + m_nq = std::ceil(extent / dq); + float extra = 0.5f * (m_nq * dq - extent); + m_qmin = qmin - extra; + m_qmax = qmax + extra; + } + m_fq = m_nq / (qmax - qmin); // qbin = (q_hit - m_qmin) * m_fq; + + m_phi_bin_infos.resize(m_nq); + for (int i = 0; i < m_nq; ++i) m_phi_bin_infos[i].resize(Config::m_nphi); +} - m_layer_id = layer; - m_is_barrel = is_barrel; +void LayerOfHits::SetupLayer(const LayerInfo &li) +{ + // Note, LayerInfo::m_q_bin ==> > 0 - bin width, < 0 - number of bins - // Realign qmin/max on "global" dq boundaries. - // This might not be the best strategy, esp. for large bins. - // Could have instead: - // a) extra space on each side; - // b) pass in number of bins. + assert (m_layer_info == nullptr && "SetupLayer() already called."); - float nmin = std::floor(qmin / dq); - float nmax = std::ceil (qmax / dq); - m_qmin = dq * nmin; - m_qmax = dq * nmax; - m_fq = 1.0f / dq; // qbin = (q_hit - m_qmin) * m_fq; - m_nq = nmax - nmin; + m_layer_info = &li; - m_phi_bin_infos.resize(m_nq); - for (int i = 0; i < m_nq; ++i) m_phi_bin_infos[i].resize(Config::m_nphi); + if (is_barrel()) setup_bins(li.m_zmin, li.m_zmax, li.m_q_bin); + else setup_bins(li.m_rin, li.m_rout, li.m_q_bin); } +//============================================================================== + void LayerOfHits::SuckInHits(const HitVec &hitv) { // This is now in SetupLayer() @@ -55,7 +69,8 @@ void LayerOfHits::SuckInHits(const HitVec &hitv) assert (m_nq > 0 && "SetupLayer() was not called."); - const int size = hitv.size(); + const int size = hitv.size(); + const bool is_brl = is_barrel(); if (m_capacity < size) { @@ -83,7 +98,7 @@ void LayerOfHits::SuckInHits(const HitVec &hitv) { HitInfo &hi = ha[i]; hi.phi = h.phi(); - hi.q = m_is_barrel ? h.z() : h.r(); + hi.q = is_brl ? h.z() : h.r(); hi.qbin = std::max(std::min(static_cast((hi.q - m_qmin) * m_fq), m_nq - 1), 0); m_hit_phis[i] = hi.phi + 6.3f * (hi.qbin - nqh); ++qc[hi.qbin]; @@ -106,11 +121,11 @@ void LayerOfHits::SuckInHits(const HitVec &hitv) // XXXX MT: Endcap has special check - try to get rid of this! // Also, WTF ... this brings in holes as pos i is not filled. // If this stays I need i_offset variable. - if ( ! m_is_barrel && (hitv[j].r() > m_qmax || hitv[j].r() < m_qmin)) + if ( ! is_brl && (hitv[j].r() > m_qmax || hitv[j].r() < m_qmin)) { printf("LayerOfHits::SuckInHits WARNING hit out of r boundary of disk\n" " layer %d hit %d hit_r %f limits (%f, %f)\n", - m_layer_id, j, hitv[j].r(), m_qmin, m_qmax); + layer_id(), j, hitv[j].r(), m_qmin, m_qmax); // Figure out of this needs to stay ... and fix it // --m_size; // continue; @@ -200,10 +215,9 @@ void LayerOfHits::SelectHitIndices(float q, float phi, float dq, float dphi, std if ( ! isForSeeding) // seeding has set cuts for dq and dphi { - // XXXX MT: Here I reuse Config::m_max_dz also for endcap ... those will become - // layer dependant and get stored in TrackerInfo (or copied into LayerOfHits). - if (std::abs(dq) > Config::m_max_dz) dq = Config::m_max_dz; - if (std::abs(dphi) > Config::m_max_dphi) dphi = Config::m_max_dphi; + // XXXX MT: min search windows not enforced here. + dq = std::min(std::abs(dq), max_dq()); + dphi = std::min(std::abs(dphi), max_dphi()); } int qb1 = GetQBinChecked(q - dq); @@ -254,7 +268,7 @@ void LayerOfHits::PrintBins() { for (int qb = 0; qb < m_nq; ++qb) { - printf("%c bin %d\n", m_is_barrel ? 'Z' : 'R', qb); + printf("%c bin %d\n", is_barrel() ? 'Z' : 'R', qb); for (int pb = 0; pb < Config::m_nphi; ++pb) { if (pb % 8 == 0) @@ -271,44 +285,12 @@ void LayerOfHits::PrintBins() // EventOfHits //============================================================================== -EventOfHits::EventOfHits(int n_layers) : - m_layers_of_hits(n_layers), - m_n_layers(n_layers) -{ - for (int i = 0; i < n_layers; ++i) - { - assert("Butchering out old setup via Config ... for cyl-cow and cms." && 0); - //if (Config::endcapTest) m_layers_of_hits[i].SetupDisk(Config::cmsDiskMinRs[i], Config::cmsDiskMaxRs[i], Config::g_disk_dr[i]); - //else m_layers_of_hits[i].SetupLayer(-Config::g_layer_zwidth[i], Config::g_layer_zwidth[i], Config::g_layer_dz[i]); - } -} - EventOfHits::EventOfHits(TrackerInfo &trk_inf) : m_layers_of_hits(trk_inf.m_layers.size()), m_n_layers(trk_inf.m_layers.size()) { for (auto &li : trk_inf.m_layers) { - // XXXX MT bin width has to come from somewhere ... had arrays in Config. - // This is also different for strip detectors + the hack - // with mono / stereo regions in CMS endcap layers. - // I'm just hardocding this to 1 cm for now ... - - float bin_width = 1.0f; - - if (li.is_barrel()) - { - // printf("EventOfHits::EventOfHits setting up layer %2d as barrel\n", li.m_layer_id); - - m_layers_of_hits[li.m_layer_id].SetupLayer(li.m_zmin, li.m_zmax, bin_width, - li.m_layer_id, true); - } - else - { - // printf("EventOfHits::EventOfHits setting up layer %2d as endcap\n", li.m_layer_id); - - m_layers_of_hits[li.m_layer_id].SetupLayer(li.m_rin, li.m_rout, bin_width, - li.m_layer_id, false); - } + m_layers_of_hits[li.m_layer_id].SetupLayer(li); } } diff --git a/mkFit/HitStructures.h b/mkFit/HitStructures.h index 655b4bcf12a2e..969c4d555d01e 100644 --- a/mkFit/HitStructures.h +++ b/mkFit/HitStructures.h @@ -61,7 +61,7 @@ inline bool sortTrksByPhiMT(const Track& t1, const Track& t2) // and could help us reduce the number of hits we need to process with bigger // potential gains. -#define LOH_USE_PHI_Q_ARRAYS +// #define LOH_USE_PHI_Q_ARRAYS // Note: the same code is used for barrel and endcap. In barrel the longitudinal // bins are in Z and in endcap they are in R -- here this coordinate is called Q @@ -69,6 +69,7 @@ inline bool sortTrksByPhiMT(const Track& t1, const Track& t2) class LayerOfHits { public: + const LayerInfo *m_layer_info = 0; Hit *m_hits = 0; vecvecPhiBinInfo_t m_phi_bin_infos; #ifdef LOH_USE_PHI_Q_ARRAYS @@ -79,14 +80,23 @@ class LayerOfHits float m_qmin, m_qmax, m_fq; int m_nq = 0; int m_capacity = 0; - int m_layer_id = -1; - bool m_is_barrel; + + int layer_id() const { return m_layer_info->m_layer_id; } + bool is_barrel() const { return m_layer_info->is_barrel(); } + + float min_dphi() const { return m_layer_info->m_select_min_dphi; } + float max_dphi() const { return m_layer_info->m_select_max_dphi; } + float min_dq() const { return m_layer_info->m_select_min_dq; } + float max_dq() const { return m_layer_info->m_select_max_dq; } // Testing bin filling static constexpr float m_fphi = Config::m_nphi / Config::TwoPI; static constexpr int m_phi_mask = 0x3ff; protected: + + void setup_bins(float qmin, float qmax, float dq); + void alloc_hits(int size) { m_hits = (Hit*) _mm_malloc(sizeof(Hit) * size, 64); @@ -134,9 +144,9 @@ class LayerOfHits free_hits(); } - void Reset() {} + void SetupLayer(const LayerInfo &li); - void SetupLayer(float qmin, float qmax, float dq, int layer, bool is_barrel); + void Reset() {} float NormalizeQ(float q) const { if (q < m_qmin) return m_qmin; if (q > m_qmax) return m_qmax; return q; } @@ -149,11 +159,11 @@ class LayerOfHits const vecPhiBinInfo_t& GetVecPhiBinInfo(float q) const { return m_phi_bin_infos[GetQBin(q)]; } - void SuckInHits(const HitVec &hitv); + void SuckInHits(const HitVec &hitv); - void SelectHitIndices(float q, float phi, float dq, float dphi, std::vector& idcs, bool isForSeeding=false, bool dump=false); + void SelectHitIndices(float q, float phi, float dq, float dphi, std::vector& idcs, bool isForSeeding=false, bool dump=false); - void PrintBins(); + void PrintBins(); }; //============================================================================== @@ -165,7 +175,6 @@ class EventOfHits int m_n_layers; public: - EventOfHits(int n_layers); EventOfHits(TrackerInfo &trk_inf); void Reset() diff --git a/mkFit/Makefile b/mkFit/Makefile index 3c6083064dad6..bc86f9a073552 100644 --- a/mkFit/Makefile +++ b/mkFit/Makefile @@ -22,12 +22,10 @@ LDFLAGS_NO_ROOT += ${LDEXTRA} all: default -TGTS := mkFit - -EXES := ${TGTS} +TGTS := mkFit ifeq (${CXX},icc) - EXES += $(addsuffix -mic, ${TGTS}) + TGTS += mkFit-mic endif auto-genmplex: GenMPlexOps.pl @@ -35,10 +33,10 @@ auto-genmplex: GenMPlexOps.pl AUTO_TGTS := auto-genmplex -default: ${AUTO_TGTS} ${EXES} +default: ${AUTO_TGTS} ${TGTS} clean: - rm -f ${EXES} *.d *.o *.om Ice/*.d Ice/*.o Ice/*.om + rm -f ${TGTS} *.d *.o *.om Ice/*.d Ice/*.o Ice/*.om rm -rf mkFit.dSYM distclean: clean @@ -56,12 +54,6 @@ echo: ################################################################ -# Should be a lib, really -ABOVE_OBJS := $(patsubst %, ../%.o, Config Matrix Event Hit Track Propagation KalmanUtils Simulation Geometry SimpleGeom fittest buildtest ConformalUtils seedtest BinInfoUtils TTreeValidation Validation TrackerInfo CylCowWLids) - -${ABOVE_OBJS}: - ${MAKE} -C .. - MKFSRCS := $(wildcard *.cc) $(wildcard Ice/*.cc) MKFHDRS := $(wildcard *.h) @@ -88,7 +80,7 @@ ${CU_LINK}: ${CU_OBJS} ${NV} --device-link $^ --output-file $@ endif -ALLOBJS := ${MKFOBJS} ${ABOVE_OBJS} ${CU_OBJS} ${CU_LINK} +ALLOBJS := ${MKFOBJS} ${CU_OBJS} ${CU_LINK} ${MKFDEPS}: auto-genmplex @@ -97,7 +89,7 @@ include ${MKFDEPS} endif mkFit: ${ALLOBJS} - ${CXX} ${CXXFLAGS} ${VEC_HOST} ${LDFLAGS} ${ALLOBJS} -o $@ ${LDFLAGS_HOST} ${LDFLAGS_CU} + ${CXX} ${CXXFLAGS} ${VEC_HOST} ${LDFLAGS} ${ALLOBJS} -o $@ ${LDFLAGS_HOST} ${LDFLAGS_CU} -L.. -lMicCore -Wl,-rpath=.. ifdef WITH_ROOT fittestMPlex.o : CPPFLAGS += $(shell root-config --cflags) @@ -126,8 +118,7 @@ MKFOBJS_MIC := $(MKFOBJS:.o=.om) ALLOBJS_MIC := $(ALLOBJS:.o=.om) mkFit-mic: ${ALLOBJS_MIC} - ${CXX} ${CXXFLAGS} ${VEC_MIC} ${LDFLAGS_NO_ROOT} ${ALLOBJS_MIC} -o $@ ${LDFLAGS_MIC} - scp $@ mic0: + ${CXX} ${CXXFLAGS} ${VEC_MIC} ${LDFLAGS_NO_ROOT} ${ALLOBJS_MIC} -o $@ ${LDFLAGS_MIC} -L.. -lMicCore -Wl,-rpath=.. ${MKFOBJS_MIC}: %.om: %.cc %.d ${CXX} ${CPPFLAGS_NO_ROOT} ${CXXFLAGS} ${VEC_MIC} -c -o $@ $< diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index 2f6604c50415b..71f0e241ee410 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -177,7 +177,6 @@ MkBuilder::MkBuilder() : m_steering_params[TrackerInfo::Reg_Endcap_Neg] = { 21, - &LayerInfo::m_zmax, &LayerInfo::m_next_ecap_neg, &MkFitter::PropagateTracksToZ, &MkFitter::SelectHitIndicesEndcap, @@ -192,7 +191,6 @@ MkBuilder::MkBuilder() : m_steering_params[TrackerInfo::Reg_Barrel] = { 3, - &LayerInfo::m_rin, &LayerInfo::m_next_barrel, &MkFitter::PropagateTracksToR, &MkFitter::SelectHitIndices, @@ -207,7 +205,6 @@ MkBuilder::MkBuilder() : m_steering_params[TrackerInfo::Reg_Endcap_Pos] = { 12, - &LayerInfo::m_zmin, &LayerInfo::m_next_ecap_pos, &MkFitter::PropagateTracksToZ, &MkFitter::SelectHitIndicesEndcap, @@ -998,7 +995,7 @@ void MkBuilder::FindTracksBestHit() dcall(pre_prop_print(next_layer, mkfp.get())); - (mkfp.get()->*st_par.propagate_foo)(trk_info.m_layers[ilay].*st_par.prop_to_pos_doo, rng.n_proc()); + (mkfp.get()->*st_par.propagate_foo)(trk_info.m_layers[ilay].m_propagate_to, rng.n_proc()); dcall(post_prop_print(next_layer, mkfp.get())); @@ -1139,7 +1136,7 @@ void MkBuilder::FindTracksStandard() //propagate to layer dcall(pre_prop_print(ilay, mkfp.get())); - (mkfp.get()->*st_par.propagate_foo)(layer_info.*st_par.prop_to_pos_doo, end - itrack); + (mkfp.get()->*st_par.propagate_foo)(layer_info.m_propagate_to, end - itrack); dcall(post_prop_print(ilay, mkfp.get())); @@ -1349,7 +1346,7 @@ void MkBuilder::find_tracks_in_layers(CandCloner &cloner, MkFitter *mkfp, if (ilay >= 0) { // propagate to current layer - (mkfp->*st_par.propagate_foo)(layer_info.*st_par.prop_to_pos_doo, end - itrack); + (mkfp->*st_par.propagate_foo)(layer_info.m_propagate_to, end - itrack); // copy_out the propagated track params, errors only (hit-idcs and chi2 already updated) mkfp->CopyOutParErr(eoccs.m_candidates, end - itrack, true); } diff --git a/mkFit/MkFitter.cc b/mkFit/MkFitter.cc index e8b9c4183c7ad..655bf4127e371 100644 --- a/mkFit/MkFitter.cc +++ b/mkFit/MkFitter.cc @@ -712,6 +712,7 @@ void MkFitter::PropagateTracksToR(float R, const int N_proc) void MkFitter::SelectHitIndices(const LayerOfHits &layer_of_hits, const int N_proc, bool dump) { + const LayerOfHits &L = layer_of_hits; const int iI = iP; const float nSigmaPhi = 3; const float nSigmaZ = 3; @@ -745,9 +746,8 @@ void MkFitter::SelectHitIndices(const LayerOfHits &layer_of_hits, const int N_pr dphi = nSigmaPhi * std::sqrt(std::abs(dphi2)); - // XXXX MT: Where has this come from ... ??? - if (std::abs(dphi) < Config::minDPhi) dphi = Config::minDPhi; - if (std::abs(dz) < Config::minDZ) dz = Config::minDZ; + dphi = std::max(std::abs(dphi), L.min_dphi()); + dz = std::max(std::abs(dz), L.min_dq()); if (Config::useCMSGeom) { @@ -778,10 +778,8 @@ void MkFitter::SelectHitIndices(const LayerOfHits &layer_of_hits, const int N_pr } } - const LayerOfHits &L = layer_of_hits; - - if (std::abs(dz) > Config::m_max_dz) dz = Config::m_max_dz; - if (std::abs(dphi) > Config::m_max_dphi) dphi = Config::m_max_dphi; + dphi = std::min(std::abs(dphi), L.max_dphi()); + dz = std::min(std::abs(dz), L.max_dq()); const int zb1 = L.GetQBinChecked(z - dz); const int zb2 = L.GetQBinChecked(z + dz) + 1; @@ -1006,7 +1004,7 @@ void MkFitter::AddBestHit(const LayerOfHits &layer_of_hits, const int N_proc) msErr[Nhits].CopyIn(itrack, hit.errArray()); msPar[Nhits].CopyIn(itrack, hit.posArray()); Chi2(itrack, 0, 0) += chi2; - HoTArr[Nhits](itrack, 0, 0) = { bestHit[itrack], layer_of_hits.m_layer_id }; + HoTArr[Nhits](itrack, 0, 0) = { bestHit[itrack], layer_of_hits.layer_id() }; } else { @@ -1016,7 +1014,7 @@ void MkFitter::AddBestHit(const LayerOfHits &layer_of_hits, const int N_proc) msPar[Nhits](itrack,0,0) = Par[iP](itrack,0,0); msPar[Nhits](itrack,1,0) = Par[iP](itrack,1,0); msPar[Nhits](itrack,2,0) = Par[iP](itrack,2,0); - HoTArr[Nhits](itrack, 0, 0) = { -1, layer_of_hits.m_layer_id }; + HoTArr[Nhits](itrack, 0, 0) = { -1, layer_of_hits.layer_id() }; // Don't update chi2 } @@ -1157,7 +1155,7 @@ void MkFitter::FindCandidates(const LayerOfHits &layer_of_hits, { newcand.addHitIdx(HoTArr[hi](itrack, 0, 0),0.);//this should be ok since we already set the chi2 above } - newcand.addHitIdx(XHitArr.At(itrack, hit_cnt, 0), layer_of_hits.m_layer_id, chi2); + newcand.addHitIdx(XHitArr.At(itrack, hit_cnt, 0), layer_of_hits.layer_id(), chi2); newcand.setLabel(Label(itrack, 0, 0)); //set the track state to the updated parameters Err[iC].CopyOut(itrack, newcand.errors_nc().Array()); @@ -1186,7 +1184,7 @@ void MkFitter::FindCandidates(const LayerOfHits &layer_of_hits, { newcand.addHitIdx(HoTArr[hi](itrack, 0, 0),0.);//this should be ok since we already set the chi2 above } - newcand.addHitIdx(hit_idx, layer_of_hits.m_layer_id, 0.); + newcand.addHitIdx(hit_idx, layer_of_hits.layer_id(), 0.); newcand.setLabel(Label(itrack, 0, 0)); //set the track state to the propagated parameters Err[iP].CopyOut(itrack, newcand.errors_nc().Array()); @@ -1321,7 +1319,7 @@ void MkFitter::FindCandidatesEndcap(const LayerOfHits &layer_of_hits, { newcand.addHitIdx(HoTArr[hi](itrack, 0, 0), 0.);//this should be ok since we already set the chi2 above } - newcand.addHitIdx(XHitArr.At(itrack, hit_cnt, 0), layer_of_hits.m_layer_id, chi2); + newcand.addHitIdx(XHitArr.At(itrack, hit_cnt, 0), layer_of_hits.layer_id(), chi2); newcand.setLabel(Label(itrack, 0, 0)); //set the track state to the updated parameters Err[iC].CopyOut(itrack, newcand.errors_nc().Array()); @@ -1363,7 +1361,7 @@ void MkFitter::FindCandidatesEndcap(const LayerOfHits &layer_of_hits, { newcand.addHitIdx(HoTArr[hi](itrack, 0, 0), 0.);//this should be ok since we already set the chi2 above } - newcand.addHitIdx(hit_idx, layer_of_hits.m_layer_id, 0.); + newcand.addHitIdx(hit_idx, layer_of_hits.layer_id(), 0.); newcand.setLabel(Label(itrack, 0, 0)); // set the track state to the propagated parameters Err[iP].CopyOut(itrack, newcand.errors_nc().Array()); @@ -1663,7 +1661,7 @@ void MkFitter::SelectHitIndicesEndcap(const LayerOfHits &layer_of_hits, const int N_proc, bool dump) { // debug = 1; - + const LayerOfHits &L = layer_of_hits; const int iI = iP; const float nSigmaPhi = 3; const float nSigmaR = 3; @@ -1699,8 +1697,8 @@ void MkFitter::SelectHitIndicesEndcap(const LayerOfHits &layer_of_hits, dphi = nSigmaPhi * std::sqrt(std::abs(dphi2)); - // XXXXMT4K if (std::abs(dphi) < Config::minDPhi) dphi = Config::minDPhi; -// if (std::abs(dz) Config::m_max_dz) dz = Config::m_max_dz; - // XXXXMT4K if (std::abs(dphi) > Config::m_max_dphi) dphi = Config::m_max_dphi; + dphi = std::min(std::abs(dphi), L.max_dphi()); + dr = std::min(std::abs(dr), L.max_dq()); const int rb1 = L.GetQBinChecked(r - dr); const int rb2 = L.GetQBinChecked(r + dr) + 1; @@ -1942,7 +1938,7 @@ void MkFitter::AddBestHitEndcap(const LayerOfHits &layer_of_hits, const int N_pr msErr[Nhits].CopyIn(itrack, hit.errArray()); msPar[Nhits].CopyIn(itrack, hit.posArray()); Chi2(itrack, 0, 0) += chi2; - HoTArr[Nhits](itrack, 0, 0) = { bestHit[itrack], layer_of_hits.m_layer_id }; + HoTArr[Nhits](itrack, 0, 0) = { bestHit[itrack], layer_of_hits.layer_id() }; } else { @@ -1969,7 +1965,7 @@ void MkFitter::AddBestHitEndcap(const LayerOfHits &layer_of_hits, const int N_pr msPar[Nhits](itrack,1,0) = Par[iP](itrack,1,0); msPar[Nhits](itrack,2,0) = Par[iP](itrack,2,0); //-3 means we did not expect any hit since we are out of bounds, so it does not count in countInvalidHits - HoTArr[Nhits](itrack, 0, 0) = { withinBounds ? -1 : -3, layer_of_hits.m_layer_id }; + HoTArr[Nhits](itrack, 0, 0) = { withinBounds ? -1 : -3, layer_of_hits.layer_id() }; // Don't update chi2 } diff --git a/mkFit/SteeringParams.h b/mkFit/SteeringParams.h index f63aa1e86f4db..6952a930a3cea 100644 --- a/mkFit/SteeringParams.h +++ b/mkFit/SteeringParams.h @@ -8,7 +8,6 @@ class CandCloner; struct SteeringParams { int first_finding_layer; // layer to consider first - float LayerInfo::*prop_to_pos_doo; int LayerInfo::*next_layer_doo; void (MkFitter::*propagate_foo) (float, const int); void (MkFitter::*select_hits_foo) (const LayerOfHits &, const int, bool); @@ -20,7 +19,6 @@ struct SteeringParams SteeringParams() {} SteeringParams(int ffl, - float LayerInfo::*ptp_d, int LayerInfo::*nl_d, void (MkFitter::*p_f) (float, const int), void (MkFitter::*sh_f) (const LayerOfHits &, const int, bool), @@ -29,7 +27,6 @@ struct SteeringParams void (MkFitter::*fc_f)(const LayerOfHits &, std::vector> &, const int, const int), void (MkFitter::*fcmc_f)(const LayerOfHits &, CandCloner &, const int, const int)) : first_finding_layer(ffl), - prop_to_pos_doo(ptp_d), next_layer_doo(nl_d), propagate_foo(p_f), select_hits_foo(sh_f), diff --git a/mkFit/mkFit.cc b/mkFit/mkFit.cc index 1139d82d9392e..356e8d2f6b891 100644 --- a/mkFit/mkFit.cc +++ b/mkFit/mkFit.cc @@ -19,8 +19,6 @@ #include "MaterialEffects.h" -#include "CylCowWLids.h" - #ifndef NO_ROOT #include "Validation.h" #endif @@ -50,10 +48,13 @@ void initGeom(Geometry& geom) // are added starting from the center // NB: z is just a dummy variable, VUSolid is actually infinite in size. *** Therefore, set it to the eta of simulation *** + TrackerInfo::ExecTrackerInfoCreatorPlugin(Config::geomPlugin, Config::TrkInfo); + + /* if ( ! Config::endcapTest && ! Config::useCMSGeom) { // This is the new standalone case -- Cylindrical Cow with Lids - Create_TrackerInfo(Config::TrkInfo); + //Create_TrackerInfo(Config::TrkInfo); #ifndef WITH_USOLIDS geom.BuildFromTrackerInfo(Config::TrkInfo); #else @@ -86,6 +87,7 @@ void initGeom(Geometry& geom) } } } + */ } namespace @@ -210,6 +212,8 @@ void test_standard() MPT_SIZE, Config::numThreadsSimulation, Config::numThreadsFinder); printf(" sizeof(Track)=%zu, sizeof(Hit)=%zu, sizeof(SVector3)=%zu, sizeof(SMatrixSym33)=%zu, sizeof(MCHitInfo)=%zu\n", sizeof(Track), sizeof(Hit), sizeof(SVector3), sizeof(SMatrixSym33), sizeof(MCHitInfo)); + + // XXXX MT to revisit ... if (Config::useCMSGeom) { printf ("Using CMS-like geometry "); if (Config::readCmsswSeeds) printf ("with CMSSW seeds\n"); @@ -218,6 +222,9 @@ void test_standard() printf ("Test tracking in endcap, disks spacing 5 cm\n"); } else printf ("Using Cylindrical Cow with Lids, |eta| < 2.4\n"); + Geometry geom; + initGeom(geom); + if (g_operation == "write") { generate_and_save_tracks(); return; @@ -234,9 +241,6 @@ void test_standard() assert(g_input_version > 0 || 1 == Config::numThreadsEvents); } - Geometry geom; - initGeom(geom); - if (Config::useCMSGeom) fillZRgridME(); const int NT = 4; @@ -473,6 +477,7 @@ int main(int argc, const char *argv[]) printf( "Usage: %s [options]\n" "Options:\n" + " --geom geometry plugin to use (def: %s)\n" " --num-events number of events to run over (def: %d)\n" " --num-tracks number of tracks to generate for each event (def: %d)\n" " --num-thr-sim number of threads for simulation (def: %d)\n" @@ -481,6 +486,7 @@ int main(int argc, const char *argv[]) " --num-thr-ev number of threads to run the event loop\n" " --fit-std run standard fitting test (def: false)\n" " --fit-std-only run only standard fitting test (def: false)\n" + " --chi2cut chi2 cut used in building test (def: %.1f)\n" " --build-bh run best-hit building test (def: false)\n" " --build-std run standard combinatorial building test (def: false)\n" " --build-ce run clone engine combinatorial building test (def: false)\n" @@ -505,9 +511,11 @@ int main(int argc, const char *argv[]) " --num-thr-reorg number of threads to run the hits reorganization\n" , argv[0], + Config::geomPlugin.c_str(), Config::nEvents, Config::nTracks, Config::numThreadsSimulation, Config::numThreadsFinder, + Config::chi2Cut, Config::numSeedsPerTask, Config::finderReportBestOutOfN, Config::useCMSGeom, @@ -526,6 +534,11 @@ int main(int argc, const char *argv[]) ); exit(0); } + else if (*i == "--geom") + { + next_arg_or_die(mArgs, i); + Config::geomPlugin = *i; + } else if (*i == "--num-events") { next_arg_or_die(mArgs, i); @@ -555,6 +568,11 @@ int main(int argc, const char *argv[]) g_run_fit_std = true; g_run_build_all = false; g_run_build_bh = false; g_run_build_std = false; g_run_build_ce = false; } + else if (*i == "--chi2cut") + { + next_arg_or_die(mArgs, i); + Config::chi2Cut = atof(i->c_str()); + } else if(*i == "--build-bh") { g_run_build_all = false; g_run_build_bh = true; g_run_build_std = false; g_run_build_ce = false; From be1a488daebdbb51c346351fb6df55d20dc46268 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Fri, 5 May 2017 17:22:02 -0700 Subject: [PATCH 039/172] 28 is enough for the barrel --- Config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Config.h b/Config.h index 94c710c2fd9a2..18bfdbb2838f0 100644 --- a/Config.h +++ b/Config.h @@ -47,7 +47,7 @@ namespace Config // XXXX This needs to be generalized for other geometries ! // TrackerInfo more or less has all this information (or could have it). constexpr int nTotalLayers = 28; - constexpr int nMaxSimHits = 42; // Assuming dual hit on every barrel / endcap edge + constexpr int nMaxSimHits = 28; // Assuming dual hit on every barrel / endcap edge constexpr int nMaxRecHits = 10; // Assuming single hit on each layer constexpr int nMaxTrkHits = nMaxSimHits; // Used for array sizes in MkFitter and Track From 4abb8c0e31d73acc8b879f966a26e09ff1b0faf9 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Fri, 5 May 2017 17:22:15 -0700 Subject: [PATCH 040/172] add vv float --- tkNtuple/DictsLinkDef.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tkNtuple/DictsLinkDef.h b/tkNtuple/DictsLinkDef.h index 8097a812d23c4..14e57aa4b0115 100644 --- a/tkNtuple/DictsLinkDef.h +++ b/tkNtuple/DictsLinkDef.h @@ -3,9 +3,14 @@ #ifdef __CINT__ #pragma link C++ class vector >+ ; +#pragma link C++ class vector >+ ; #ifdef G__VECTOR_HAS_CLASS_ITERATOR #pragma link C++ operators vector >::iterator; #pragma link C++ operators vector >::const_iterator; #pragma link C++ operators vector >::reverse_iterator; + +#pragma link C++ operators vector >::iterator; +#pragma link C++ operators vector >::const_iterator; +#pragma link C++ operators vector >::reverse_iterator; #endif #endif From 19dd8a33bef0aa1d034ee6c1e37daea965ab37d7 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Fri, 5 May 2017 17:22:58 -0700 Subject: [PATCH 041/172] more appropriate simhit matching and some printout cleanup --- tkNtuple/WriteMemoryFile.cc | 166 ++++++++++++++++++++++++------------ 1 file changed, 111 insertions(+), 55 deletions(-) diff --git a/tkNtuple/WriteMemoryFile.cc b/tkNtuple/WriteMemoryFile.cc index 9f0f46a342f8c..f93be5e269187 100644 --- a/tkNtuple/WriteMemoryFile.cc +++ b/tkNtuple/WriteMemoryFile.cc @@ -154,7 +154,7 @@ int main() { TString outfilename = ""; - TFile* f = TFile::Open("./ntuple_input.root"); maxevt = 1;outfilename = "cmssw_output.bin"; + TFile* f = TFile::Open("./ntuple_input.root"); maxevt = 1000;outfilename = "cmssw_output.bin"; TTree* t = (TTree*) f->Get("trackingNtuple/tree"); @@ -192,16 +192,23 @@ int main() { //simhit std::vector* simhit_process; + std::vector* simhit_particle; std::vector* simhit_simTrkIdx; std::vector* simhit_px; std::vector* simhit_py; std::vector* simhit_pz; t->SetBranchAddress("simhit_process", &simhit_process); + t->SetBranchAddress("simhit_particle", &simhit_particle); t->SetBranchAddress("simhit_simTrkIdx", &simhit_simTrkIdx); t->SetBranchAddress("simhit_px", &simhit_px); t->SetBranchAddress("simhit_py", &simhit_py); t->SetBranchAddress("simhit_pz", &simhit_pz); - + + std::vector >* simhit_hitIdx = 0; + t->SetBranchAddress("simhit_hitIdx", &simhit_hitIdx); + std::vector >* simhit_hitType = 0; + t->SetBranchAddress("simhit_hitType", &simhit_hitType); + //rec tracks std::vector* trk_nValid = 0; std::vector* trk_nInvalid = 0; @@ -310,6 +317,8 @@ int main() { vector >* pix_simHitIdx = 0; t->SetBranchAddress("pix_simHitIdx", &pix_simHitIdx); + vector >* pix_chargeFraction = 0; + t->SetBranchAddress("pix_chargeFraction", &pix_chargeFraction); //strip hits vector* glu_isBarrel = 0; @@ -347,6 +356,7 @@ int main() { vector* str_isStereo = 0; vector* str_det = 0; vector* str_lay = 0; + vector* str_simType = 0; vector* str_x = 0; vector* str_y = 0; vector* str_z = 0; @@ -358,8 +368,9 @@ int main() { vector* str_zx = 0; t->SetBranchAddress("str_isBarrel",&str_isBarrel); t->SetBranchAddress("str_isStereo",&str_isStereo); - t->SetBranchAddress("str_lay",&str_lay); t->SetBranchAddress("str_det",&str_det); + t->SetBranchAddress("str_lay",&str_lay); + t->SetBranchAddress("str_simType",&str_simType); t->SetBranchAddress("str_x",&str_x); t->SetBranchAddress("str_y",&str_y); t->SetBranchAddress("str_z",&str_z); @@ -372,6 +383,8 @@ int main() { vector >* str_simHitIdx = 0; t->SetBranchAddress("str_simHitIdx", &str_simHitIdx); + vector >* str_chargeFraction = 0; + t->SetBranchAddress("str_chargeFraction", &str_chargeFraction); fwrite(&maxevt, sizeof(int), 1, fp); @@ -397,7 +410,6 @@ int main() { vector simTrackIdx_(sim_q->size(),-1);//keep track of original index in ntuple vector seedSimIdx(see_q->size(),-1); for (int isim = 0; isim < sim_q->size(); ++isim) { - std::cout<<__FILE__<<" "<<__LINE__<<" iSim "<at(isim); @@ -492,9 +504,7 @@ int main() { vector seedTracks_; vector > pixHitSeedIdx(pix_lay->size()); - std::cout<<__FILE__<<" "<<__LINE__<<" n see "<size()<size(); ++is) { - std::cout<<__FILE__<<" "<<__LINE__<<" see "<at(is)<at(is))!=TrackAlgorithm::initialStep) continue;//select seed in acceptance //if (see_pt->at(is)<0.5 || fabs(see_eta->at(is))>0.8) continue;//select seed in acceptance SVector3 pos = SVector3(see_stateTrajGlbX->at(is),see_stateTrajGlbY->at(is),see_stateTrajGlbZ->at(is)); @@ -532,7 +542,6 @@ int main() { auto const& shIdxs = see_hitIdx->at(is); if (! (TrackAlgorithm(see_algo->at(is))== TrackAlgorithm::initialStep && std::count(shTypes.begin(), shTypes.end(), int(HitType::Pixel))>=3)) continue;//check algo and nhits - std::cout<<__FILE__<<" "<<__LINE__<<" see "< const& shs, std::vector const& shfs, int rhIdx, HitType rhType){ + //assume that all simhits are associated + int ibest = -1; + int shbest = -1; + float hpbest = -1; + float tpbest = -1; + float hfbest = -1; + + float maxfrac = -1; + int ish = -1; + int nshs = shs.size(); + for (auto const sh : shs){ + ish++; + auto tkidx = simhit_simTrkIdx->at(sh); + //use only sh with available TP + if (tkidx < 0) continue; + + auto hpx = simhit_px->at(sh); + auto hpy = simhit_py->at(sh); + auto hpz = simhit_pz->at(sh); + auto hp = sqrt(hpx*hpx + hpy*hpy + hpz*hpz); + + //look only at hits with p> 50 MeV + if (hp < 0.05f) continue; + + auto tpx = sim_px->at(tkidx); + auto tpy = sim_py->at(tkidx); + auto tpz = sim_pz->at(tkidx); + auto tp = sqrt(tpx*tpx + tpy*tpy + tpz*tpz); + + //take only hits with hp> 0.5*tp + if (hp < 0.5*tp) continue; + + //pick tkidx corresponding to max hp/tp; .. this is probably redundant + if (maxfrac < hp/tp){ + maxfrac = hp/tp; + ibest = tkidx; + shbest = sh; + hpbest = hp; + tpbest = tp; + hfbest = shfs[ish]; + } + + } + + //arbitration: a rechit with one matching sim is matched to sim if it's the first + //FIXME: SOME BETTER SELECTION CAN BE DONE (it will require some more correlated knowledge) + if (nshs == 1 && ibest >= 0){ + auto const& srhIdxV = simhit_hitIdx->at(shbest); + auto const& srhTypeV = simhit_hitType->at(shbest); + int ih = -1; + for (auto itype : srhTypeV){ + ih++; + if (HitType(itype) == rhType && srhIdxV[ih] != rhIdx){ + ibest = -1; + break; + } + } + } + + // if (ibest >= 0) std::cout<<" best tkIdx "<at(shbest) + // <<" particle "<at(shbest) + // < > layerHits_; vector simHitsInfo_; int totHits = 0; layerHits_.resize(nTotalLayers); - std::cout<<__FILE__<<" "<<__LINE__<<" n pix "<size()<size(); ++ipix) { int ilay = -1; ilay = lnc.convertLayerNumber(pix_det->at(ipix),pix_lay->at(ipix),useMatched,-1,pix_z->at(ipix)>0); if (ilay<0) continue; - int simTkIdx = -1; - auto const& pixSimHits = pix_simHitIdx->at(ipix); - if (!pixSimHits.empty()){ - //FIXME: need to improve consistency instead of just using first available - simTkIdx = simTrackIdx_[simhit_simTrkIdx->at(pixSimHits[0])]; - } + int simTkIdx = bestTkIdx(pix_simHitIdx->at(ipix), pix_chargeFraction->at(ipix), ipix, HitType::Pixel); + //cout << Form("pix lay=%i det=%i x=(%6.3f, %6.3f, %6.3f)",ilay+1,pix_det->at(ipix),pix_x->at(ipix),pix_y->at(ipix),pix_z->at(ipix)) << endl; SVector3 pos(pix_x->at(ipix),pix_y->at(ipix),pix_z->at(ipix)); SMatrixSym33 err; @@ -568,7 +644,11 @@ int main() { err.At(0,1) = pix_xy->at(ipix); err.At(0,2) = pix_zx->at(ipix); err.At(1,2) = pix_yz->at(ipix); - if (simTkIdx>=0) simTracks_[simTkIdx].addHitIdx(layerHits_[ilay].size(), ilay, 0); + if (simTkIdx>=0){ + int nhits = simTracks_[simTkIdx].nTotalHits(); + if (nhits < Config::nMaxSimHits) simTracks_[simTkIdx].addHitIdx(layerHits_[ilay].size(), ilay, 0); + else cout<<"SKIP: Tried to add pix hit to track with "<size(); ++iglu) { if (glu_isBarrel->at(iglu)==0) continue; - int simTkIdx = -1; - auto const& strMSimHits = str_simHitIdx->at(glu_monoIdx->at(iglu)); - int strMSimHit_simTrkIdx = -1; - int strMSimHit_process = -1; - auto const& strSSimHits = str_simHitIdx->at(glu_stereoIdx->at(iglu)); - if (!strMSimHits.empty() /*|| !strSSimHits.empty() */){ - //FIXME: need to improve consistency instead of just using first available - strMSimHit_simTrkIdx = simhit_simTrkIdx->at(strMSimHits[0]); - strMSimHit_process = simhit_process->at(strMSimHits[0]); - simTkIdx = simTrackIdx_[strMSimHit_simTrkIdx]; - } + int igluMono = glu_monoIdx->at(iglu); + int simTkIdx = bestTkIdx(str_simHitIdx->at(igluMono), str_chargeFraction->at(igluMono), + igluMono, HitType::Strip); int ilay = lnc.convertLayerNumber(glu_det->at(iglu),glu_lay->at(iglu),useMatched,-1,glu_z->at(iglu)>0); - //cout << ilay << " " << strMSimHit_simTrkIdx << " " << strMSimHit_process << " " << strSSimHit_simTrkIdx << " " << strSSimHit_process << endl; // cout << Form("glu lay=%i det=%i bar=%i x=(%6.3f, %6.3f, %6.3f)",ilay+1,glu_det->at(iglu),glu_isBarrel->at(iglu),glu_x->at(iglu),glu_y->at(iglu),glu_z->at(iglu)) << endl; SVector3 pos(glu_x->at(iglu),glu_y->at(iglu),glu_z->at(iglu)); SMatrixSym33 err; @@ -606,7 +676,11 @@ int main() { err.At(0,1) = glu_xy->at(iglu); err.At(0,2) = glu_zx->at(iglu); err.At(1,2) = glu_yz->at(iglu); - if (simTkIdx>=0) simTracks_[simTkIdx].addHitIdx(layerHits_[ilay].size(), ilay, 0); + if (simTkIdx>=0){ + int nhits = simTracks_[simTkIdx].nTotalHits(); + if (nhits < Config::nMaxSimHits) simTracks_[simTkIdx].addHitIdx(layerHits_[ilay].size(), ilay, 0); + else cout<<"SKIP: Tried to add glu hit to track with "< strIdx; strIdx.resize(str_lay->size()); - std::cout<<__FILE__<<" "<<__LINE__<<" n str "<size()<size(); ++istr) { - std::cout<<__FILE__<<" "<<__LINE__<<" i str "<at(istr),str_lay->at(istr),useMatched,str_isStereo->at(istr),str_z->at(istr)>0); if (useMatched && str_isBarrel->at(istr)==1 && str_isStereo->at(istr)) continue; if (ilay==-1) continue; - int simTkIdx = -1; - int strSimHit_simTrkIdx = -1; - int strSimHit_process = -1; - auto const& strSimHits = str_simHitIdx->at(istr); - - if (!strSimHits.empty()){ - //FIXME: need to improve consistency instead of just using first available - strSimHit_simTrkIdx = simhit_simTrkIdx->at(strSimHits[0]); - std::cout<<__FILE__<<" "<<__LINE__<<" simTrk "<at(strSimHits[0]); - std::cout<<__FILE__<<" "<<__LINE__<<" process "<at(istr), str_chargeFraction->at(istr), istr, HitType::Strip); + //if (str_onTrack->at(istr)==0) continue;//do not consider hits that are not on track! - //cout << Form("str lay=%i istr=%i tridx=%i bar=%i x=(%6.3f, %6.3f, %6.3f) r=%6.3f proc=%i part=%i onTrk=%i isStereo=%i",ilay+1,istr,strSimHit_simTrkIdx,str_isBarrel->at(istr),str_x->at(istr),str_y->at(istr),str_z->at(istr),sqrt(pow(str_x->at(istr),2)+pow(str_y->at(istr),2)),strSimHit_process->at(istr),str_particle->at(istr),str_onTrack->at(istr),str_isStereo->at(istr)) << endl; - std::cout<<__FILE__<<" "<<__LINE__<<" fill in lay "<at(istr),str_y->at(istr),str_z->at(istr)); SMatrixSym33 err; err.At(0,0) = str_xx->at(istr); @@ -649,11 +707,10 @@ int main() { err.At(0,1) = str_xy->at(istr); err.At(0,2) = str_zx->at(istr); err.At(1,2) = str_yz->at(istr); - std::cout<<__FILE__<<" "<<__LINE__<<" got pos and err "<<" fill simTracks_ "<=0){ - std::cout<<__FILE__<<" "<<__LINE__<<" add hits; size now "< Date: Fri, 5 May 2017 17:35:44 -0700 Subject: [PATCH 042/172] flip TOB and TEC mono-stereo order to agree with mictest/cmssw-trackerinfo-desc.txt e9af459 --- tkNtuple/WriteMemoryFile.cc | 45 ++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/tkNtuple/WriteMemoryFile.cc b/tkNtuple/WriteMemoryFile.cc index f93be5e269187..715c76b7c9d53 100644 --- a/tkNtuple/WriteMemoryFile.cc +++ b/tkNtuple/WriteMemoryFile.cc @@ -78,7 +78,6 @@ class LayerNumberConverter { if (cmsswdet==5 && cmsswlay==6 && isStereo==0 ) return 12+lOffset; return -1; } else { - //FIXME: OLD stereo/mono layer is used here //TIB if (cmsswdet==3 && cmsswlay==1 && isStereo==0) return 3+lOffset; if (cmsswdet==3 && cmsswlay==1 && isStereo==1) return 4+lOffset; @@ -87,10 +86,10 @@ class LayerNumberConverter { if (cmsswdet==3 && cmsswlay==3 && isStereo==0) return 7+lOffset; if (cmsswdet==3 && cmsswlay==4 && isStereo==0) return 8+lOffset; //TOB - if (cmsswdet==5 && cmsswlay==1 && isStereo==1) return 9+lOffset; - if (cmsswdet==5 && cmsswlay==1 && isStereo==0) return 10+lOffset; - if (cmsswdet==5 && cmsswlay==2 && isStereo==1) return 11+lOffset; - if (cmsswdet==5 && cmsswlay==2 && isStereo==0) return 12+lOffset; + if (cmsswdet==5 && cmsswlay==1 && isStereo==0) return 9+lOffset; + if (cmsswdet==5 && cmsswlay==1 && isStereo==1) return 10+lOffset; + if (cmsswdet==5 && cmsswlay==2 && isStereo==0) return 11+lOffset; + if (cmsswdet==5 && cmsswlay==2 && isStereo==1) return 12+lOffset; if (cmsswdet==5 && cmsswlay==3 && isStereo==0) return 13+lOffset; if (cmsswdet==5 && cmsswlay==4 && isStereo==0) return 14+lOffset; if (cmsswdet==5 && cmsswlay==5 && isStereo==0) return 15+lOffset; @@ -114,24 +113,24 @@ class LayerNumberConverter { if (cmsswdet==4 && cmsswdisk==3 && isStereo==0) return 6+lOffset; if (cmsswdet==4 && cmsswdisk==3 && isStereo==1) return 7+lOffset; //TEC - if (cmsswdet==6 && cmsswdisk==1 && isStereo==1) return 8+lOffset; - if (cmsswdet==6 && cmsswdisk==1 && isStereo==0) return 9+lOffset; - if (cmsswdet==6 && cmsswdisk==2 && isStereo==1) return 10+lOffset; - if (cmsswdet==6 && cmsswdisk==2 && isStereo==0) return 11+lOffset; - if (cmsswdet==6 && cmsswdisk==3 && isStereo==1) return 12+lOffset; - if (cmsswdet==6 && cmsswdisk==3 && isStereo==0) return 13+lOffset; - if (cmsswdet==6 && cmsswdisk==4 && isStereo==1) return 14+lOffset; - if (cmsswdet==6 && cmsswdisk==4 && isStereo==0) return 15+lOffset; - if (cmsswdet==6 && cmsswdisk==5 && isStereo==1) return 16+lOffset; - if (cmsswdet==6 && cmsswdisk==5 && isStereo==0) return 17+lOffset; - if (cmsswdet==6 && cmsswdisk==6 && isStereo==1) return 18+lOffset; - if (cmsswdet==6 && cmsswdisk==6 && isStereo==0) return 19+lOffset; - if (cmsswdet==6 && cmsswdisk==7 && isStereo==1) return 20+lOffset; - if (cmsswdet==6 && cmsswdisk==7 && isStereo==0) return 21+lOffset; - if (cmsswdet==6 && cmsswdisk==8 && isStereo==1) return 22+lOffset; - if (cmsswdet==6 && cmsswdisk==8 && isStereo==0) return 23+lOffset; - if (cmsswdet==6 && cmsswdisk==9 && isStereo==1) return 24+lOffset; - if (cmsswdet==6 && cmsswdisk==9 && isStereo==0) return 25+lOffset; + if (cmsswdet==6 && cmsswdisk==1 && isStereo==0) return 8+lOffset; + if (cmsswdet==6 && cmsswdisk==1 && isStereo==1) return 9+lOffset; + if (cmsswdet==6 && cmsswdisk==2 && isStereo==0) return 10+lOffset; + if (cmsswdet==6 && cmsswdisk==2 && isStereo==1) return 11+lOffset; + if (cmsswdet==6 && cmsswdisk==3 && isStereo==0) return 12+lOffset; + if (cmsswdet==6 && cmsswdisk==3 && isStereo==1) return 13+lOffset; + if (cmsswdet==6 && cmsswdisk==4 && isStereo==0) return 14+lOffset; + if (cmsswdet==6 && cmsswdisk==4 && isStereo==1) return 15+lOffset; + if (cmsswdet==6 && cmsswdisk==5 && isStereo==0) return 16+lOffset; + if (cmsswdet==6 && cmsswdisk==5 && isStereo==1) return 17+lOffset; + if (cmsswdet==6 && cmsswdisk==6 && isStereo==0) return 18+lOffset; + if (cmsswdet==6 && cmsswdisk==6 && isStereo==1) return 19+lOffset; + if (cmsswdet==6 && cmsswdisk==7 && isStereo==0) return 20+lOffset; + if (cmsswdet==6 && cmsswdisk==7 && isStereo==1) return 21+lOffset; + if (cmsswdet==6 && cmsswdisk==8 && isStereo==0) return 22+lOffset; + if (cmsswdet==6 && cmsswdisk==8 && isStereo==1) return 23+lOffset; + if (cmsswdet==6 && cmsswdisk==9 && isStereo==0) return 24+lOffset; + if (cmsswdet==6 && cmsswdisk==9 && isStereo==1) return 25+lOffset; return -1; } } From f29bc65e1dff362b7a8da0ce4367f3dc0c5223af Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Fri, 5 May 2017 17:55:06 -0700 Subject: [PATCH 043/172] actually return the layer index for the endcap --- tkNtuple/WriteMemoryFile.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/tkNtuple/WriteMemoryFile.cc b/tkNtuple/WriteMemoryFile.cc index 715c76b7c9d53..805a30301ea62 100644 --- a/tkNtuple/WriteMemoryFile.cc +++ b/tkNtuple/WriteMemoryFile.cc @@ -54,6 +54,7 @@ class LayerNumberConverter { if (lo_ == TkLayout::phase1) lOffset = 1; disk += 17+lOffset; if (! posZ) disk += 25+2*lOffset; + return disk; } return -1; } From 2a67a38f734dd47025a6eb43023a54ce945880cd Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Fri, 5 May 2017 18:36:55 -0700 Subject: [PATCH 044/172] better format end of event printout (print all seed hits) --- tkNtuple/WriteMemoryFile.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tkNtuple/WriteMemoryFile.cc b/tkNtuple/WriteMemoryFile.cc index 805a30301ea62..7df12da8c79a3 100644 --- a/tkNtuple/WriteMemoryFile.cc +++ b/tkNtuple/WriteMemoryFile.cc @@ -761,7 +761,8 @@ int main() { for (int i=0;i Date: Sat, 6 May 2017 00:24:44 -0700 Subject: [PATCH 045/172] Get geometry plugins and libMicCore-mic.so work on KNC. --- Geoms/Makefile | 8 +++++++- Makefile | 6 +++--- Makefile.config | 2 +- TrackerInfo.cc | 4 ++++ mkFit/Makefile | 2 +- mkFit/mkFit.cc | 13 ++++++++++--- 6 files changed, 26 insertions(+), 9 deletions(-) diff --git a/Geoms/Makefile b/Geoms/Makefile index 48dcf1fb3a9ac..35f5a84fadc8b 100644 --- a/Geoms/Makefile +++ b/Geoms/Makefile @@ -28,9 +28,15 @@ all: ${TGTS} %.so: %.o ${CXX} -shared -o $@ $< +%.om: %.cc + ${CXX} ${CPPFLAGS_NO_ROOT} ${CXXFLAGS} ${VEC_MIC} -c -o $@ $< + +%-mic.so: %.om + ${CXX} ${CXXFLAGS} ${VEC_MIC} ${LDFLAGS_MIC} -shared -o $@ $< + ifeq ($(filter clean distclean, ${MAKECMDGOALS}),) include ${DEPS} endif clean: - rm -f *.so *.o *.d + rm -f *.so *.o *.om *.d *.optrpt diff --git a/Makefile b/Makefile index fda5900a15e0e..6c7e7ecaf2eaf 100644 --- a/Makefile +++ b/Makefile @@ -69,13 +69,13 @@ ${LIBUSOLIDS} : USolids/CMakeLists.txt ifeq ($(CXX),icc) OBJS_MIC := $(OBJS:.o=.om) -CORE_OBJS_MIC := $(CORE_OBJS:.o=.om +CORE_OBJS_MIC := $(CORE_OBJS:.o=.om) ${LIB_CORE_MIC}: ${CORE_OBJS_MIC} ${CXX} ${CXXFLAGS} ${VEC_MIC} ${LDFLAGS_NO_ROOT} ${CORE_OBJS_MIC} -shared -o $@ ${LDFLAGS_MIC} -main-mic: ${AUTO_TGTS} ${LIB_CORE_MIC} ${LIBUSOLIDS_MIC} - ${CXX} ${CXXFLAGS} ${VEC_MIC} ${LDFLAGS_NO_ROOT} -o $@ main.om ${LIBUSOLIDS_MIC} ${LDFLAGS_MIC} -L. -lMicCore -Wl,-rpath=. +main-mic: ${AUTO_TGTS} ${LIB_CORE_MIC} main.om ${LIBUSOLIDS_MIC} + ${CXX} ${CXXFLAGS} ${VEC_MIC} ${LDFLAGS_NO_ROOT} -o $@ main.om ${LIBUSOLIDS_MIC} ${LDFLAGS_MIC} -L. -lMicCore-mic -Wl,-rpath=. ${LIBUSOLIDS_MIC} : USolids/CMakeLists.txt -mkdir USolids-mic diff --git a/Makefile.config b/Makefile.config index 7852080a743e9..0f7f402656bb4 100644 --- a/Makefile.config +++ b/Makefile.config @@ -120,7 +120,7 @@ CPPFLAGS := -I. ${USE_MATRIPLEX} ${USE_INTRINSICS} -std=c++11 CXXFLAGS := -fPIC ${OPT} ${OSX_CXXFLAGS} LDFLAGS_HOST := -LDFLAGS_MIC := +LDFLAGS_MIC := -static-intel ifdef USE_CUDA CPPFLAGS += -DUSE_CUDA -I${CUBROOT} diff --git a/TrackerInfo.cc b/TrackerInfo.cc index 67cc1127edc46..f9e8f04869790 100644 --- a/TrackerInfo.cc +++ b/TrackerInfo.cc @@ -49,7 +49,11 @@ namespace void TrackerInfo::ExecTrackerInfoCreatorPlugin(const std::string& base, TrackerInfo &ti, bool verbose) { +#ifdef __MIC__ + std::string soname = base + "-mic.so"; +#else std::string soname = base + ".so"; +#endif struct stat st; diff --git a/mkFit/Makefile b/mkFit/Makefile index bc86f9a073552..1c25b18bccaba 100644 --- a/mkFit/Makefile +++ b/mkFit/Makefile @@ -118,7 +118,7 @@ MKFOBJS_MIC := $(MKFOBJS:.o=.om) ALLOBJS_MIC := $(ALLOBJS:.o=.om) mkFit-mic: ${ALLOBJS_MIC} - ${CXX} ${CXXFLAGS} ${VEC_MIC} ${LDFLAGS_NO_ROOT} ${ALLOBJS_MIC} -o $@ ${LDFLAGS_MIC} -L.. -lMicCore -Wl,-rpath=.. + ${CXX} ${CXXFLAGS} ${VEC_MIC} ${LDFLAGS_NO_ROOT} ${ALLOBJS_MIC} -o $@ ${LDFLAGS_MIC} -L.. -lMicCore-mic -Wl,-rpath=.. ${MKFOBJS_MIC}: %.om: %.cc %.d ${CXX} ${CPPFLAGS_NO_ROOT} ${CXXFLAGS} ${VEC_MIC} -c -o $@ $< diff --git a/mkFit/mkFit.cc b/mkFit/mkFit.cc index 356e8d2f6b891..1d4752d029d2b 100644 --- a/mkFit/mkFit.cc +++ b/mkFit/mkFit.cc @@ -50,6 +50,13 @@ void initGeom(Geometry& geom) TrackerInfo::ExecTrackerInfoCreatorPlugin(Config::geomPlugin, Config::TrkInfo); +#ifndef WITH_USOLIDS + geom.BuildFromTrackerInfo(Config::TrkInfo); +#else + fprintf(stderr, "TrackerInfo only supports SimpleGeometry, not USolids.\n"); + exit(1); +#endif + /* if ( ! Config::endcapTest && ! Config::useCMSGeom) { @@ -222,9 +229,6 @@ void test_standard() printf ("Test tracking in endcap, disks spacing 5 cm\n"); } else printf ("Using Cylindrical Cow with Lids, |eta| < 2.4\n"); - Geometry geom; - initGeom(geom); - if (g_operation == "write") { generate_and_save_tracks(); return; @@ -235,6 +239,9 @@ void test_standard() return; } + Geometry geom; + initGeom(geom); + if (g_operation == "read") { Config::nEvents = open_simtrack_file(); From ba972085595afc54a8b9733c3a70929d98ac9eb4 Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Mon, 8 May 2017 14:14:31 -0700 Subject: [PATCH 046/172] Rename auto-gerated CMS-2017.cc -> Geoms/CMS-2017.acc. --- Geoms/{CMS-2017.cc => CMS-2017.acc} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Geoms/{CMS-2017.cc => CMS-2017.acc} (100%) diff --git a/Geoms/CMS-2017.cc b/Geoms/CMS-2017.acc similarity index 100% rename from Geoms/CMS-2017.cc rename to Geoms/CMS-2017.acc From e33657560c8cae1d34a21cfca6e580df214395ac Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Mon, 8 May 2017 14:15:51 -0700 Subject: [PATCH 047/172] Handwritten part of the CMS-2017 trkinfo, remove include directives from .acc. --- Config.h | 2 +- Geoms/CMS-2017.acc | 3 --- Geoms/CMS-2017.cc | 13 +++++++++++++ Geoms/CMS/make_trk_info.C | 4 ---- 4 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 Geoms/CMS-2017.cc diff --git a/Config.h b/Config.h index dd41d45b5a9f8..0e5f6130282a3 100644 --- a/Config.h +++ b/Config.h @@ -49,7 +49,7 @@ namespace Config // XXXX This needs to be generalized for other geometries ! // TrackerInfo more or less has all this information (or could have it). constexpr int nTotalLayers = 28; - constexpr int nMaxSimHits = 19; // Assuming dual hit on every barrel / endcap edge + constexpr int nMaxSimHits = 28; // Assuming dual hit on every barrel / endcap edge constexpr int nMaxRecHits = 10; // Assuming single hit on each layer constexpr int nMaxTrkHits = nMaxSimHits; // Used for array sizes in MkFitter and Track diff --git a/Geoms/CMS-2017.acc b/Geoms/CMS-2017.acc index fea70b3bfa960..4e36bed2ac332 100644 --- a/Geoms/CMS-2017.acc +++ b/Geoms/CMS-2017.acc @@ -1,6 +1,3 @@ -#include "../Config.h" -#include "../TrackerInfo.h" - void Create_TrackerInfo(TrackerInfo& ti, bool verbose) { Config::chi2Cut = 30.0; diff --git a/Geoms/CMS-2017.cc b/Geoms/CMS-2017.cc new file mode 100644 index 0000000000000..b2518a94578ad --- /dev/null +++ b/Geoms/CMS-2017.cc @@ -0,0 +1,13 @@ +//------------------- +// CMS 2017 geometry +//------------------- + +#include "../Config.h" +#include "../TrackerInfo.h" + +namespace +{ +#include "CMS-2017.acc" +} + +void* TrackerInfoCrator_ptr = (void*) Create_TrackerInfo; diff --git a/Geoms/CMS/make_trk_info.C b/Geoms/CMS/make_trk_info.C index 72d973185a03e..afc8a3481605e 100644 --- a/Geoms/CMS/make_trk_info.C +++ b/Geoms/CMS/make_trk_info.C @@ -123,10 +123,6 @@ void print_trk_info() OOO = fopen("CMS-2017.cc", "w"); // OOO = stdout; - PRN("#include \"../Config.h\""); - PRN("#include \"../TrackerInfo.h\""); - NLN; - PRN("void Create_TrackerInfo(TrackerInfo& ti, bool verbose)"); SCOPE_BEG; From 472702979ae95626d51e2be37fe2796bcb7060f9 Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Tue, 9 May 2017 14:13:43 -0700 Subject: [PATCH 048/172] Cleanup while getting cms data/seed reading working. --- Event.cc | 2 +- Geoms/CMS-2017.acc | 16 +------------ Geoms/CMS-2017.cc | 28 +++++++++++++++++++++- Geoms/CMS/make_trk_info.C | 23 ++---------------- Geoms/CylCowWLids.cc | 5 +--- TrackerInfo.cc | 50 +++++++++++++++++++++++++++++++++++++++ TrackerInfo.h | 32 +++++++++++-------------- mkFit/mkFit.cc | 46 ++++++++++++++++------------------- 8 files changed, 116 insertions(+), 86 deletions(-) diff --git a/Event.cc b/Event.cc index 5f3d9ff5d287f..94412cf517aef 100644 --- a/Event.cc +++ b/Event.cc @@ -407,7 +407,7 @@ void Event::write_out(FILE *fp) for (int it = 0; it 0 - bin width, < 0 - number of bins @@ -36,7 +36,7 @@ class LayerInfo // * ... // * pointers to hit containers - LayerInfo(int lid) : m_layer_id(lid) { m_sibl_barrel, m_sibl_ecap_pos, m_sibl_ecap_neg = -1; } + LayerInfo(int lid) : m_layer_id(lid) {} void set_limits(float r1, float r2, float z1, float z2); void set_next_layers(int nb, int nep, int nen); @@ -61,12 +61,7 @@ class LayerInfo class TrackerInfo { private: - int new_layer() - { - int l = (int) m_layers.size(); - m_layers.push_back(LayerInfo(l)); - return l; - } + int new_layer(); public: enum AbsEtaRegion_e { AbsReg_Outside = -1, AbsReg_Barrel = 0, AbsReg_Transition = 1, AbsReg_Endcap = 2 }; @@ -82,12 +77,13 @@ class TrackerInfo float m_eta_trans_beg, m_eta_trans_end, m_eta_ecap_end; - void set_eta_regions(float tr_beg, float tr_end, float ec_end) - { m_eta_trans_beg = tr_beg; m_eta_trans_end = tr_end; m_eta_ecap_end = ec_end; } + void set_eta_regions(float tr_beg, float tr_end, float ec_end); - LayerInfo & new_barrel_layer() { m_barrel .push_back( new_layer() ); return m_layers.back(); } - LayerInfo & new_ecap_pos_layer() { m_ecap_pos.push_back( new_layer() ); return m_layers.back(); } - LayerInfo & new_ecap_neg_layer() { m_ecap_neg.push_back( new_layer() ); return m_layers.back(); } + void reserve_layers(int n_brl, int n_ec_pos, int n_ec_neg); + void create_layers (int n_brl, int n_ec_pos, int n_ec_neg); + LayerInfo & new_barrel_layer(); + LayerInfo & new_ecap_pos_layer(); + LayerInfo & new_ecap_neg_layer(); bool are_layers_siblings(int l1, int l2) const; diff --git a/mkFit/mkFit.cc b/mkFit/mkFit.cc index 1d4752d029d2b..97c5dc9a21321 100644 --- a/mkFit/mkFit.cc +++ b/mkFit/mkFit.cc @@ -114,6 +114,8 @@ namespace std::string g_file_name = "simtracks.bin"; std::string g_input_file = ""; int g_input_version = Config::FileVersion; + + const char* b2a(bool b) { return b ? "true" : "false"; } } void read_and_save_tracks() @@ -220,14 +222,9 @@ void test_standard() printf(" sizeof(Track)=%zu, sizeof(Hit)=%zu, sizeof(SVector3)=%zu, sizeof(SMatrixSym33)=%zu, sizeof(MCHitInfo)=%zu\n", sizeof(Track), sizeof(Hit), sizeof(SVector3), sizeof(SMatrixSym33), sizeof(MCHitInfo)); - // XXXX MT to revisit ... - if (Config::useCMSGeom) { - printf ("Using CMS-like geometry "); - if (Config::readCmsswSeeds) printf ("with CMSSW seeds\n"); - else printf ("with MC-truth seeds \n"); - } else if (Config::endcapTest) { - printf ("Test tracking in endcap, disks spacing 5 cm\n"); - } else printf ("Using Cylindrical Cow with Lids, |eta| < 2.4\n"); + if (Config::useCMSGeom) printf ("- using CMS-like geometry\n"); + if (Config::readCmsswSeeds) printf ("- reading seeds from file\n"); + if (Config::endcapTest) printf ("- endcap test enabled (to be nixed)\n"); if (g_operation == "write") { generate_and_save_tracks(); @@ -244,7 +241,10 @@ void test_standard() if (g_operation == "read") { - Config::nEvents = open_simtrack_file(); + int evs_in_file = open_simtrack_file(); + if (Config::nEvents == -1) + Config::nEvents = evs_in_file; + assert(g_input_version > 0 || 1 == Config::numThreadsEvents); } @@ -489,7 +489,6 @@ int main(int argc, const char *argv[]) " --num-tracks number of tracks to generate for each event (def: %d)\n" " --num-thr-sim number of threads for simulation (def: %d)\n" " --num-thr number of threads for track finding (def: %d)\n" - " extra cloning thread is spawned for each of them\n" " --num-thr-ev number of threads to run the event loop\n" " --fit-std run standard fitting test (def: false)\n" " --fit-std-only run only standard fitting test (def: false)\n" @@ -499,11 +498,10 @@ int main(int argc, const char *argv[]) " --build-ce run clone engine combinatorial building test (def: false)\n" " --seeds-per-task number of seeds to process in a tbb task (def: %d)\n" " --best-out-of run track finding num times, report best time (def: %d)\n" - " --cms-geom use cms-like geometry (def: %i)\n" - " --cmssw-seeds take seeds from CMSSW (def: %i)\n" + " --cmssw-seeds take seeds from CMSSW (def: %s)\n" " --find-seeds run road search seeding [CF enabled by default] (def: %s)\n" " --hits-per-task number of layer1 hits per task in finding seeds (def: %i)\n" - " --endcap-test test endcap tracking (def: %i)\n" + " --endcap-test test endcap tracking (def: %s)\n" " --cf-seeding enable CF in seeding (def: %s)\n" " --cf-fitting enable CF in fitting (def: %s)\n" " --root-val enable ROOT based validation for building [eff, FR, DR] (def: %s)\n" @@ -525,16 +523,15 @@ int main(int argc, const char *argv[]) Config::chi2Cut, Config::numSeedsPerTask, Config::finderReportBestOutOfN, - Config::useCMSGeom, - Config::readCmsswSeeds, - Config::findSeeds ? "true" : "false", + b2a(Config::readCmsswSeeds), + b2a(Config::findSeeds), Config::numHitsPerTask, - Config::endcapTest, - Config::cf_seeding ? "true" : "false", - Config::cf_fitting ? "true" : "false", - Config::root_val ? "true" : "false", - Config::fit_val ? "true" : "false", - Config::silent ? "true" : "false", + b2a(Config::endcapTest), + b2a(Config::cf_seeding), + b2a(Config::cf_fitting), + b2a(Config::root_val), + b2a(Config::fit_val), + b2a(Config::silent), g_file_name.c_str(), g_input_file.c_str(), g_input_version @@ -602,10 +599,6 @@ int main(int argc, const char *argv[]) next_arg_or_die(mArgs, i); Config::finderReportBestOutOfN = atoi(i->c_str()); } - else if(*i == "--cms-geom") - { - Config::useCMSGeom = true; - } else if(*i == "--cmssw-seeds") { Config::readCmsswSeeds = true; @@ -656,6 +649,7 @@ int main(int argc, const char *argv[]) else if(*i == "--read") { g_operation = "read"; + Config::nEvents = -1; } else if(*i == "--file-name") { From bdb83b6709dc73f34efb3b92c7c8e10c9e561971 Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Thu, 11 May 2017 08:42:42 -0700 Subject: [PATCH 049/172] working point in new efficiencies --- Event.cc | 2 +- TTreeValidation.cc | 65 +++++++++++++++++++++++++++++++--------------- Track.cc | 28 +++++++++++++------- Track.h | 4 +-- mkFit/MkBuilder.cc | 9 ++++--- 5 files changed, 70 insertions(+), 38 deletions(-) diff --git a/Event.cc b/Event.cc index 7cec629cefd9f..510a59d21f422 100644 --- a/Event.cc +++ b/Event.cc @@ -332,7 +332,7 @@ void Event::PrintStats(const TrackVec& trks, TrackExtraVec& trkextras) for (auto&& trk : trks) { auto&& extra = trkextras[trk.label()]; - extra.setMCTrackIDInfoByLabel(trk, layerHits_, simHitsInfo_, simTracks_[trk.label()]); + extra.setMCTrackIDInfoByLabel(trk, layerHits_, simHitsInfo_); if (extra.mcTrackID() < 0) { ++miss; } else { diff --git a/TTreeValidation.cc b/TTreeValidation.cc index ce5089b648e63..73215727bd1e9 100644 --- a/TTreeValidation.cc +++ b/TTreeValidation.cc @@ -446,7 +446,7 @@ void TTreeValidation::setTrackExtras(Event& ev) { auto&& track(ev.seedTracks_[itrack]); auto&& extra(ev.seedTracksExtra_[itrack]); - extra.setMCTrackIDInfo(track, ev.layerHits_, ev.simHitsInfo_, ev.simTracks_); // otherwise seeds are completely unmatched in ToyMC Sim Seeds + extra.setMCTrackIDInfo(track, ev.layerHits_, ev.simHitsInfo_, ev.simTracks_, true); // otherwise seeds are completely unmatched in ToyMC Sim Seeds } // set mcTrackID for built tracks @@ -454,8 +454,8 @@ void TTreeValidation::setTrackExtras(Event& ev) { auto&& track(ev.candidateTracks_[itrack]); auto&& extra(ev.candidateTracksExtra_[itrack]); - if (Config::useCMSGeom || Config::findSeeds) {extra.setMCTrackIDInfo(track, ev.layerHits_, ev.simHitsInfo_, ev.simTracks_);} - else {extra.setMCTrackIDInfoByLabel(track, ev.layerHits_, ev.simHitsInfo_, ev.simTracks_[track.label()]);} + if (Config::useCMSGeom || Config::findSeeds) {extra.setMCTrackIDInfo(track, ev.layerHits_, ev.simHitsInfo_, ev.simTracks_, false);} + else {extra.setMCTrackIDInfoByLabel(track, ev.layerHits_, ev.simHitsInfo_);} } // set mcTrackID for fit tracks @@ -463,8 +463,8 @@ void TTreeValidation::setTrackExtras(Event& ev) { auto&& track(ev.fitTracks_[itrack]); auto&& extra(ev.fitTracksExtra_[itrack]); - if (Config::useCMSGeom || Config::findSeeds) {extra.setMCTrackIDInfo(track, ev.layerHits_, ev.simHitsInfo_, ev.simTracks_);} - else {extra.setMCTrackIDInfoByLabel(track, ev.layerHits_, ev.simHitsInfo_, ev.simTracks_[track.label()]);} + if (Config::useCMSGeom || Config::findSeeds) {extra.setMCTrackIDInfo(track, ev.layerHits_, ev.simHitsInfo_, ev.simTracks_, false);} + else {extra.setMCTrackIDInfoByLabel(track, ev.layerHits_, ev.simHitsInfo_);} } } @@ -695,7 +695,6 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) pt_mc_seed_eff_ = initLayTS.pT(); phi_mc_seed_eff_ = initLayTS.momPhi(); eta_mc_seed_eff_ = initLayTS.momEta(); - helixchi2_seed_eff_ = computeHelixChi2(initLayTS.parameters,seedtrack.parameters(),seedtrack.errors()); } else @@ -703,7 +702,6 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) pt_mc_seed_eff_ = -101; phi_mc_seed_eff_ = -101; eta_mc_seed_eff_ = -101; - helixchi2_seed_eff_ = -101; } @@ -740,6 +738,7 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) pt_mc_seed_eff_ = -99; phi_mc_seed_eff_ = -99; eta_mc_seed_eff_ = -99; + helixchi2_seed_eff_ = -99; xhit_seed_eff_ = -2000; yhit_seed_eff_ = -2000; @@ -758,7 +757,6 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) lastlyr_seed_eff_ = -99; hitchi2_seed_eff_ = -99; - helixchi2_seed_eff_ = -99; duplmask_seed_eff_ = 2; // mask means unmatched sim track nTkMatches_seed_eff_ = -99; // unmatched @@ -782,7 +780,6 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) pt_mc_build_eff_ = initLayTS.pT(); phi_mc_build_eff_ = initLayTS.momPhi(); eta_mc_build_eff_ = initLayTS.momEta(); - helixchi2_build_eff_ = computeHelixChi2(initLayTS.parameters,buildtrack.parameters(),buildtrack.errors()); } else @@ -790,7 +787,6 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) pt_mc_build_eff_ = -101; phi_mc_build_eff_ = -101; eta_mc_build_eff_ = -101; - helixchi2_build_eff_ = -101; } @@ -826,6 +822,7 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) pt_mc_build_eff_ = -99; phi_mc_build_eff_ = -99; eta_mc_build_eff_ = -99; + helixchi2_build_eff_ = -99; xhit_build_eff_ = -2000; yhit_build_eff_ = -2000; @@ -844,7 +841,6 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) lastlyr_build_eff_ = -99; hitchi2_build_eff_ = -99; - helixchi2_build_eff_ = -99; duplmask_build_eff_ = 2; // mask means unmatched sim track nTkMatches_build_eff_ = -99; // unmatched @@ -868,7 +864,6 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) pt_mc_fit_eff_ = initLayTS.pT(); phi_mc_fit_eff_ = initLayTS.momPhi(); eta_mc_fit_eff_ = initLayTS.momEta(); - helixchi2_fit_eff_ = computeHelixChi2(initLayTS.parameters,fittrack.parameters(),fittrack.errors()); } else @@ -876,7 +871,6 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) pt_mc_fit_eff_ = -101; phi_mc_fit_eff_ = -101; eta_mc_fit_eff_ = -101; - helixchi2_fit_eff_ = -101; } @@ -913,6 +907,7 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) pt_mc_fit_eff_ = -99; phi_mc_fit_eff_ = -99; eta_mc_fit_eff_ = -99; + helixchi2_fit_eff_ = -99; xhit_fit_eff_ = -2000; yhit_fit_eff_ = -2000; @@ -931,7 +926,6 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) lastlyr_fit_eff_ = -99; hitchi2_fit_eff_ = -99; - helixchi2_fit_eff_ = -99; duplmask_fit_eff_ = 2; // mask means unmatched sim track nTkMatches_fit_eff_ = -99; // unmatched @@ -956,12 +950,16 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) auto& evt_layer_hits = ev.layerHits_; auto& evt_sim_trackstates = ev.simTrackStates_; + std::cout << ievt << std::endl; + for (auto&& seedtrack : evt_seed_tracks) { evtID_FR_ = ievt; auto& seedextra = evt_seed_extras[seedtrack.label()]; seedID_FR_ = seedextra.seedID(); + std::cout << " " << seedID_FR_ << std::endl; + // seed info seedmask_seed_FR_ = 1; // automatically set to 1, because at the moment no cuts on seeds after conformal+KF fit. seed triplets filtered by RZ chi2 before fitting. @@ -1003,11 +1001,16 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) } } - if (mcmask_seed_FR_ >= 0) // matched track to sim + std::cout << " " << mcID_seed_FR_ << " " << mcmask_seed_FR_ << std::endl; + + if (mcmask_seed_FR_ == 1) // matched track to sim { auto& simtrack = evt_sim_tracks[mcID_seed_FR_]; + + const int mcHitID = TTreeValidation::getLastGoodHit(seedtrack.getLastGoodMCHitID(evt_layer_hits),mcID_seed_FR_,ev); + std::cout << "----" << mcHitID << std::endl; if (mcHitID >= 0) { const TrackState & initLayTS = evt_sim_trackstates[mcHitID]; @@ -1046,21 +1049,38 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) } //==========================// - + // fill build information if track still alive if (seedToBuildMap_.count(seedID_FR_)) { seedmask_build_FR_ = 1; // quick logic + std::cout << " here a " << std::endl; + + + auto& buildtrack = evt_build_tracks[seedToBuildMap_[seedID_FR_]]; auto& buildextra = evt_build_extras[buildtrack.label()]; + std::cout << " here b: " << buildtrack.getLastGoodHitLyr() << " " << buildtrack.getLastGoodHitIdx() << std::endl; + if (seedID_FR_ == 5645) + { + for (int i = 0; i < Config::nMaxTrkHits; i++) + { + std::cout << buildtrack.getHitLyr(i) << " " << buildtrack.getHitIdx(i) << std::endl; + } + + + } + // last hit info const Hit& lasthit = evt_layer_hits[buildtrack.getLastGoodHitLyr()][buildtrack.getLastGoodHitIdx()]; xhit_build_FR_ = lasthit.x(); yhit_build_FR_ = lasthit.y(); zhit_build_FR_ = lasthit.z(); + std::cout << " here c " << std::endl; + pt_build_FR_ = buildtrack.pT(); ept_build_FR_ = buildtrack.epT(); phi_build_FR_ = buildtrack.momPhi(); @@ -1093,7 +1113,9 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) } } - if (mcmask_build_FR_ >= 0) // build track matched to seed and sim + std::cout << " " << mcID_build_FR_ << " " << mcmask_build_FR_ << std::endl; + + if (mcmask_build_FR_ == 1) // build track matched to seed and sim { auto& simtrack = evt_sim_tracks[mcID_build_FR_]; @@ -1179,7 +1201,6 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) //============================// fit tracks if (seedToFitMap_.count(seedID_FR_)) { - auto& simtrack = evt_sim_tracks[mcID_fit_FR_]; seedmask_fit_FR_ = 1; // quick logic auto& fittrack = evt_fit_tracks[seedToFitMap_[seedID_FR_]]; @@ -1223,10 +1244,12 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) } } - if (mcmask_fit_FR_ >= 0) // fit track matched to seed and sim - { - mcmask_fit_FR_ = 1; // matched track to sim + std::cout << " " << mcID_fit_FR_ << " " << mcmask_fit_FR_ << std::endl; + if (mcmask_fit_FR_ == 1) // fit track matched to seed and sim + { + auto& simtrack = evt_sim_tracks[mcID_fit_FR_]; + const int mcHitID = TTreeValidation::getLastGoodHit(fittrack.getLastGoodMCHitID(evt_layer_hits),mcID_fit_FR_,ev); // only works for outward fit for now if (mcHitID >= 0) { diff --git a/Track.cc b/Track.cc index 692ef7ef72489..8a19e0a862ece 100644 --- a/Track.cc +++ b/Track.cc @@ -75,9 +75,13 @@ SMatrix66 TrackState::jacobianCartesianToCCS(float px,float py,float pz) const { // ID == -5 : reco track somehow has zero hits... unclear what to do with these... ---> CMSSW OR REAL SEEDS ONLY // More stringent requirement for matching --> used only for simtrack pure seeds -void TrackExtra::setMCTrackIDInfoByLabel(const Track& trk, const std::vector& layerHits, const MCHitInfoVec& globalHitInfo, const Track& simtrack) +void TrackExtra::setMCTrackIDInfoByLabel(const Track& trk, const std::vector& layerHits, const MCHitInfoVec& globalHitInfo) { - const int label = simtrack.label(); + // In this routine, we know that seedtracks == simtracks + // and as such seedtrack.label() == simtrack.label() + // assume each seed track has a hit on the very first layer! + const int label = globalHitInfo[layerHits[trk.getHitLyr(0)][trk.getHitIdx(0)].mcHitID()].mcTrackID(); + int nHitsMatched = 0; // count hits matched to simtrack after the seed : will need to modify the start of this loop! XXKM4MT for (int ihit = Config::nlayers_per_seed; ihit < trk.nTotalHits(); ++ihit) @@ -88,8 +92,8 @@ void TrackExtra::setMCTrackIDInfoByLabel(const Track& trk, const std::vector*st_par.propagate_foo)(trk_info.m_layers[ilay].*st_par.prop_to_pos_doo, rng.n_proc()); - dcall(post_prop_print(next_layer, mkfp.get())); + dcall(post_prop_print(ilay, mkfp.get())); (mkfp.get()->*st_par.select_hits_foo)(layer_of_hits, rng.n_proc(), false); From 44e66921e142c647ce171b0e5fedf642bc74df04 Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Thu, 11 May 2017 10:51:53 -0700 Subject: [PATCH 050/172] CMS-2017 tracking in barrel works. `./mkFit --read --file-name /tmp/mu_brl-100-10.bin --build-bh --geom CMS-2017 --input-version 0 --cmssw-seeds --num-events 1` - Cleanup handling and preparation of seeds. Simplifies MkBuilder and functions in buildtestMPlex.cc. - add top-level function MkBuilder::PrepareSeeds(). - add internal function MkBuilder::import_seeds() and a helper function for sorting of seeds based on eta. This is used both for: - importing seeds from a file; - and importing seeds from MC tracks. - Event::read_in() add define statements for what parts to dump. - Track: - Fix bug in getLastGoodHitIdx/Lyr(). - Rename nGoodHitIdx_ to nGoodHits :) - mkFit/mkFit.cc: --num-events X is also honoured when --read is in force, but only if it is *after* the --read argument. *This was actually in previous commit, forgot to document it.* *Remains to be done:* Layer where we start searching for hits is set from SteeringParams. This is still fine for barrel but will be hard for CMS endcap as seeds come in with different last layer! So I'll have to be inventive there and on each layer select candidates to propagate further. This will be similar to what needs to be done for transition region. This also does not support different iterations, for this we'd need something like IterationParams. --- Config.h | 2 +- Event.cc | 69 +++++++++++++------ Geoms/CMS-2017.cc | 5 +- Track.h | 66 ++++++++---------- mkFit/MkBuilder.cc | 149 +++++++++++++++++++++++++++------------- mkFit/MkBuilder.h | 19 ++--- mkFit/buildtestMPlex.cc | 15 +--- 7 files changed, 199 insertions(+), 126 deletions(-) diff --git a/Config.h b/Config.h index 0e5f6130282a3..8f589657d0db4 100644 --- a/Config.h +++ b/Config.h @@ -153,7 +153,7 @@ namespace Config // Config for seeding extern int nlayers_per_seed; - constexpr int nlayers_per_seed_max = 3; // Needed for allocation of arrays on stack. + constexpr int nlayers_per_seed_max = 4; // Needed for allocation of arrays on stack. constexpr float chi2seedcut = 9.0; constexpr float lay01angdiff = 0.0634888; // analytically derived... depends on geometry of detector --> from mathematica ... d0 set to one sigma of getHypot(bsX,bsY) constexpr float lay02angdiff = 0.11537; diff --git a/Event.cc b/Event.cc index 94412cf517aef..13480d9ee011d 100644 --- a/Event.cc +++ b/Event.cc @@ -420,6 +420,12 @@ void Event::write_out(FILE *fp) */ } +// #define DUMP_SEEDS +// #define DUMP_SEED_HITS +// #define DUMP_TRACKS +// #define DUMP_TRACK_HITS +// #define DUMP_LAYER_HITS + void Event::read_in(FILE *fp, int version) { static long pos = sizeof(int); // header size @@ -469,39 +475,62 @@ void Event::read_in(FILE *fp, int version) seedTracks_.resize(ns); if (Config::readCmsswSeeds) fread(&seedTracks_[0], sizeof(Track), ns, fp); else fseek(fp, sizeof(Track)*ns, SEEK_CUR); - /* - printf("read %i seedtracks\n",nt); - for (int it = 0; it= 0) + printf(" hit %2d lyr=%d idx=%i pos r=%5.3f z=%6.3f\n", + ih, lyr, idx, layerHits_[lyr][idx].r(), layerHits_[lyr][idx].z()); + else + printf(" hit %2d idx=%i\n",ih,seedTracks_[it].getHitIdx(ih)); + + } +#endif } - */ +#endif } - /* */ - printf("read %i simtracks\n",nt); - /* - for (int it = 0; it= 0) - printf(" hit #%i lyr=%d idx=%i pos r=%5.3f z=%6.3f\n", + printf(" hit %2d lyr=%d idx=%i pos r=%5.3f z=%6.3f\n", ih, lyr, idx, layerHits_[lyr][idx].r(), layerHits_[lyr][idx].z()); else - printf(" hit #%i idx=%i\n",ih,simTracks_[it].getHitIdx(ih)); + printf(" hit %2d idx=%i\n",ih,simTracks_[it].getHitIdx(ih)); } +#endif } - printf("read %i layers\n",nl); +#endif +#ifdef DUMP_LAYER_HITS + printf("Read %i layers\n",nl); int total_hits = 0; - for (int il = 0; il= 0) { ++nGoodHitIdx_; chi2_+=chi2; } + if (hitIdx >= 0) { ++nGoodHits_; chi2_+=chi2; } } void addHitIdx(const HitOnTrack &hot, float chi2) { hitsOnTrk_[++hitIdxPos_] = hot; - if (hot.index >= 0) { ++nGoodHitIdx_; chi2_+=chi2; } + if (hot.index >= 0) { ++nGoodHits_; chi2_+=chi2; } } HitOnTrack getHitOnTrack(int posHitIdx) const { return hitsOnTrk_[posHitIdx]; } CUDA_CALLABLE - int getHitIdx(int posHitIdx) const - { - return hitsOnTrk_[posHitIdx].index; - } - int getHitLyr(int posHitIdx) const - { - return hitsOnTrk_[posHitIdx].layer; - } + int getHitIdx(int posHitIdx) const { return hitsOnTrk_[posHitIdx].index; } + int getHitLyr(int posHitIdx) const { return hitsOnTrk_[posHitIdx].layer; } - int getLastHitIdx() const - { - return hitsOnTrk_[hitIdxPos_].index; - } - int getLastHitLyr() const - { - return hitsOnTrk_[hitIdxPos_].layer; - } + HitOnTrack getLastHitOnTrack() const { return hitsOnTrk_[hitIdxPos_]; } + int getLastHitIdx() const { return hitsOnTrk_[hitIdxPos_].index; } + int getLastHitLyr() const { return hitsOnTrk_[hitIdxPos_].layer; } - int getLastGoodHitIdx() const - { - return hitsOnTrk_[nGoodHitIdx_-1].index; - } - int getLastGoodHitLyr() const + int getLastGoodHitPos() const { - return hitsOnTrk_[nGoodHitIdx_-1].layer; + int hi = hitIdxPos_; + while (hitsOnTrk_[hi].index < 0) --hi; + return hi; } + + HitOnTrack getLastGoodHitOnTrack() const { return hitsOnTrk_[getLastGoodHitPos()]; } + int getLastGoodHitIdx() const { return hitsOnTrk_[getLastGoodHitPos()].index; } + int getLastGoodHitLyr() const { return hitsOnTrk_[getLastGoodHitPos()].layer; } + int getLastGoodMCHitID(const std::vector& globalHitVec) const { - return globalHitVec[hitsOnTrk_[nGoodHitIdx_-1].layer][hitsOnTrk_[nGoodHitIdx_-1].index].mcHitID(); + HitOnTrack hot = getLastGoodHitOnTrack(); + return globalHitVec[hot.layer][hot.index].mcHitID(); } + int getMCHitIDFromLayer(const std::vector& globalHitVec, int layer) const { int mcHitID = -1; @@ -290,25 +284,25 @@ class Track hitsOnTrk_[posHitIdx] = { newIdx, newLyr }; } - void setNGoodHitIdx() { - nGoodHitIdx_=0; + void setNGoodHits() { + nGoodHits_=0; for (int i = 0; i <= hitIdxPos_; i++) { - if (hitsOnTrk_[i].index >= 0) nGoodHitIdx_++; + if (hitsOnTrk_[i].index >= 0) nGoodHits_++; } } CUDA_CALLABLE - void setNGoodHitIdx(int nHits) { - nGoodHitIdx_ = nHits; + void setNGoodHits(int nHits) { + nGoodHits_ = nHits; } CUDA_CALLABLE void resetHits() { hitIdxPos_ = -1; - nGoodHitIdx_ = 0; + nGoodHits_ = 0; } - int nFoundHits() const { return nGoodHitIdx_; } + int nFoundHits() const { return nGoodHits_; } int nTotalHits() const { return hitIdxPos_+1; } const std::vector foundLayers() const { @@ -335,10 +329,10 @@ class Track private: TrackState state_; HitOnTrack hitsOnTrk_[Config::nMaxTrkHits]; - float chi2_ = 0.; - int hitIdxPos_ = -1; - int nGoodHitIdx_ = 0; - int label_ = -1; + float chi2_ = 0.; + int hitIdxPos_ = -1; + int nGoodHits_ = 0; + int label_ = -1; }; class TrackExtra diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index 71f0e241ee410..1dd4a9cfe4cd7 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -290,10 +290,73 @@ void MkBuilder::begin_event(Event* ev, const char* build_type) // } // } // } +} + +void MkBuilder::end_event() +{ + m_event = 0; +} + + +//------------------------------------------------------------------------------ +// Seeding functions: importing, finding and fitting +//------------------------------------------------------------------------------ + +namespace +{ + void sort_seeds(Event* ev, TrackVec& tv, RadixSort& rs, std::vector& etas) + { + const int size = tv.size(); + + for (int i = 0; i < 5; ++i) ev->seedEtaSeparators_[i] = 0; + + etas.resize(size); + for (int i = 0; i < size; ++i) + { + //float eta = tv[i].momEta(); + + HitOnTrack hot = tv[i].getHitOnTrack(Config::nlayers_per_seed - 1); + float eta = ev->layerHits_[hot.layer][hot.index].eta(); + + etas[i] = eta; + ++ev->seedEtaSeparators_[ Config::TrkInfo.find_eta_region(eta) ]; + } + + rs.Sort(&etas[0], size); + } +} + +void MkBuilder::import_seeds() +{ + // debug=true; + + TrackerInfo &trk_info = Config::TrkInfo; + RadixSort sort; + std::vector etas; + + TrackVec &seeds = m_event->seedTracks_; + + if (Config::readCmsswSeeds) + { + TrackVec orig_seeds; + orig_seeds.swap(seeds); + + sort_seeds(m_event, orig_seeds, sort, etas); + + const int size = orig_seeds.size(); + seeds.reserve(size); + + for (int i = 0; i < size; ++i) + { + seeds.emplace_back( orig_seeds[ sort.GetRanks()[i] ] ); + } - if ( ! (Config::readCmsswSeeds || Config::findSeeds)) + dprintf("MkBuilder::import_seeds Finished seed import, ec- = %d, t- = %d, brl = %d, t+ = %d, ec+ = %d\n", + m_event->seedEtaSeparators_[0], m_event->seedEtaSeparators_[1], m_event->seedEtaSeparators_[2], m_event->seedEtaSeparators_[3], m_event->seedEtaSeparators_[4]); + } + else { - // debug=true; + // Import from simtrack snatching first Config::nlayers_per_seed hits // XXMT // Reduce number of hits, pick endcap over barrel when both are available. @@ -307,35 +370,17 @@ void MkBuilder::begin_event(Event* ev, const char* build_type) // make seed tracks == simtracks if not using "realistic" seeding // m_event->seedTracks_ = m_event->simTracks_; - TrackerInfo &trk_info = Config::TrkInfo; + TrackVec &sims = m_event->simTracks_; - m_event->seedTracks_.reserve( m_event->simTracks_.size() ); + sort_seeds(m_event, sims, sort, etas); - const int size = m_event->simTracks_.size(); - - // Loop over input sim-tracks, collect etas (and other relevant info) for sorting. - // After that we will make another pass and place seeds on their proper locations. - std::vector etas(size); - for (int i = 0; i < 5; ++i) m_event->seedEtaSeparators_[i] = 0; - - for (int i = 0; i < size; ++i) - { - //float eta = m_event->simTracks_[i].momEta(); - - HitOnTrack hot = m_event->simTracks_[i].getHitOnTrack(Config::nlayers_per_seed - 1); - float eta = m_event->layerHits_[hot.layer][hot.index].eta(); - - etas[i] = eta; - ++m_event->seedEtaSeparators_[ trk_info.find_eta_region(eta) ]; - } - - RadixSort sort; - sort.Sort(&etas[0], size); + const int size = sims.size(); + seeds.reserve(size); for (int i = 0; i < size; ++i) { const int j = sort.GetRanks()[i]; - const Track &src = m_event->simTracks_ [j]; + const Track &src = sims[j]; dprintf("MkBuilder::begin_event converting sim track %d into seed position %d, eta=%.3f\n", j, i, etas[j]); @@ -372,7 +417,7 @@ const HitOnTrack *hots = src.getHitsOnTrackArray(); ++h; } - m_event->seedTracks_.emplace_back( Track(src.state(), 0, src.label(), Config::nlayers_per_seed, new_hots) ); + seeds.emplace_back( Track(src.state(), 0, src.label(), Config::nlayers_per_seed, new_hots) ); Track &dst = m_event->seedTracks_.back(); dprintf(" Seed nh=%d, last_lay=%d, last_idx=%d\n", @@ -380,27 +425,18 @@ const HitOnTrack *hots = src.getHitsOnTrackArray(); // dprintf(" "); for (int i=0; iseedEtaSeparators_[0], m_event->seedEtaSeparators_[1], m_event->seedEtaSeparators_[2], m_event->seedEtaSeparators_[3], m_event->seedEtaSeparators_[4]); - - // Sum region counts up to contain actual separator indices: - for (int i = TrackerInfo::Reg_Transition_Neg; i < TrackerInfo::Reg_Count; ++i) - { - m_event->seedEtaSeparators_[i] += m_event->seedEtaSeparators_[i - 1]; - } } -} -void MkBuilder::end_event() -{ - m_event = 0; + // Sum region counts up to contain actual separator indices: + for (int i = TrackerInfo::Reg_Transition_Neg; i < TrackerInfo::Reg_Count; ++i) + { + m_event->seedEtaSeparators_[i] += m_event->seedEtaSeparators_[i - 1]; + } } -//------------------------------------------------------------------------------ -// Seeding functions: finding and fitting -//------------------------------------------------------------------------------ - -int MkBuilder::find_seeds() +void MkBuilder::find_seeds() { fprintf(stderr, "__FILE__::__LINE__ Needs fixing for B/E support, search for XXMT4K\n"); exit(1); @@ -410,9 +446,9 @@ int MkBuilder::find_seeds() #endif TripletIdxConVec seed_idcs; - double time = dtime(); + //double time = dtime(); findSeedsByRoadSearch(seed_idcs,m_event_of_hits.m_layers_of_hits,m_event->layerHits_[1].size(),m_event); - time = dtime() - time; + //time = dtime() - time; // use this to initialize tracks // XXMT4K ... configurable input layers ... or hardcode something else for endcap. @@ -451,7 +487,6 @@ int MkBuilder::find_seeds() dprint("iseed: " << iseed << " mcids: " << hit0.mcTrackID(m_event->simHitsInfo_) << " " << hit1.mcTrackID(m_event->simHitsInfo_) << " " << hit1.mcTrackID(m_event->simHitsInfo_)); } - return time; } namespace @@ -928,6 +963,26 @@ void MkBuilder::init_track_extras() m_event->validation_.alignTrackExtra(fittracks,fittrackextras); } +//------------------------------------------------------------------------------ +// PrepareSeeds +//------------------------------------------------------------------------------ + +void MkBuilder::PrepareSeeds() +{ + if (Config::findSeeds) + { + find_seeds(); + } + else + { + import_seeds(); + // all simulated seeds need to have hit indices line up in LOH for seed fit + map_seed_hits(); + } + + fit_seeds(); +} + //------------------------------------------------------------------------------ // FindTracksBestHit //------------------------------------------------------------------------------ @@ -993,11 +1048,11 @@ void MkBuilder::FindTracksBestHit() // _mm_prefetch((char*) & bunch_of_hits.m_hits[i], _MM_HINT_T1); // } - dcall(pre_prop_print(next_layer, mkfp.get())); + dcall(pre_prop_print(ilay, mkfp.get())); (mkfp.get()->*st_par.propagate_foo)(trk_info.m_layers[ilay].m_propagate_to, rng.n_proc()); - dcall(post_prop_print(next_layer, mkfp.get())); + dcall(post_prop_print(ilay, mkfp.get())); (mkfp.get()->*st_par.select_hits_foo)(layer_of_hits, rng.n_proc(), false); diff --git a/mkFit/MkBuilder.h b/mkFit/MkBuilder.h index 992b73373d3a5..7324f827e0859 100644 --- a/mkFit/MkBuilder.h +++ b/mkFit/MkBuilder.h @@ -64,13 +64,13 @@ class MkBuilder static MkBuilder* make_builder(); - virtual void begin_event(Event* ev, const char* build_type); + void begin_event(Event* ev, const char* build_type); + void end_event(); - int find_seeds(); - virtual void fit_seeds(); + void import_seeds(); + void find_seeds(); + void fit_seeds(); - void end_event(); - // -------- void map_seed_hits(); // m_event->layerHits_ -> m_event_of_hits.m_layers_of_hits (seeds only) @@ -99,9 +99,12 @@ class MkBuilder // -------- - virtual void FindTracksBestHit(); - virtual void FindTracksStandard(); - virtual void FindTracksCloneEngine(); + void PrepareSeeds(); + + void FindTracksBestHit(); + void FindTracksStandard(); + void FindTracksCloneEngine(); + #ifdef USE_CUDA const Event* get_event() const { return m_event; } const EventOfHits& get_event_of_hits() const { return m_event_of_hits; } diff --git a/mkFit/buildtestMPlex.cc b/mkFit/buildtestMPlex.cc index 38fcdffea8301..b319793d861a0 100644 --- a/mkFit/buildtestMPlex.cc +++ b/mkFit/buildtestMPlex.cc @@ -77,10 +77,7 @@ double runBuildingTestPlexBestHit(Event& ev, MkBuilder& builder) { builder.begin_event(&ev, __func__); - if (Config::findSeeds) {builder.find_seeds();} - else {builder.map_seed_hits();} // all other simulated seeds need to have hit indices line up in LOH for seed fit - - builder.fit_seeds(); + builder.PrepareSeeds(); // EventOfCandidates event_of_cands; builder.find_tracks_load_seeds_BH(); @@ -131,10 +128,7 @@ double runBuildingTestPlexStandard(Event& ev, MkBuilder& builder) { builder.begin_event(&ev, __func__); - if (Config::findSeeds) {builder.find_seeds();} - else {builder.map_seed_hits();} // all other simulated seeds need to have hit indices line up in LOH for seed fit - - builder.fit_seeds(); + builder.PrepareSeeds(); builder.find_tracks_load_seeds(); @@ -171,10 +165,7 @@ double runBuildingTestPlexCloneEngine(Event& ev, MkBuilder& builder) { builder.begin_event(&ev, __func__); - if (Config::findSeeds) {builder.find_seeds();} - else {builder.map_seed_hits();} // all other simulated seeds need to have hit indices line up in LOH for seed fit - - builder.fit_seeds(); + builder.PrepareSeeds(); builder.find_tracks_load_seeds(); From a93456d8c88252196399582c2e0b4e724e34d90f Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Thu, 11 May 2017 15:36:26 -0700 Subject: [PATCH 051/172] minor life improvements to validation --- TTreeValidation.cc | 30 ------------------------------ makeValidation.C | 2 +- runValidation.C | 2 +- 3 files changed, 2 insertions(+), 32 deletions(-) diff --git a/TTreeValidation.cc b/TTreeValidation.cc index 73215727bd1e9..c9ceaee8971c5 100644 --- a/TTreeValidation.cc +++ b/TTreeValidation.cc @@ -950,16 +950,12 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) auto& evt_layer_hits = ev.layerHits_; auto& evt_sim_trackstates = ev.simTrackStates_; - std::cout << ievt << std::endl; - for (auto&& seedtrack : evt_seed_tracks) { evtID_FR_ = ievt; auto& seedextra = evt_seed_extras[seedtrack.label()]; seedID_FR_ = seedextra.seedID(); - std::cout << " " << seedID_FR_ << std::endl; - // seed info seedmask_seed_FR_ = 1; // automatically set to 1, because at the moment no cuts on seeds after conformal+KF fit. seed triplets filtered by RZ chi2 before fitting. @@ -1001,16 +997,11 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) } } - std::cout << " " << mcID_seed_FR_ << " " << mcmask_seed_FR_ << std::endl; - if (mcmask_seed_FR_ == 1) // matched track to sim { auto& simtrack = evt_sim_tracks[mcID_seed_FR_]; - - const int mcHitID = TTreeValidation::getLastGoodHit(seedtrack.getLastGoodMCHitID(evt_layer_hits),mcID_seed_FR_,ev); - std::cout << "----" << mcHitID << std::endl; if (mcHitID >= 0) { const TrackState & initLayTS = evt_sim_trackstates[mcHitID]; @@ -1055,32 +1046,15 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) { seedmask_build_FR_ = 1; // quick logic - std::cout << " here a " << std::endl; - - - auto& buildtrack = evt_build_tracks[seedToBuildMap_[seedID_FR_]]; auto& buildextra = evt_build_extras[buildtrack.label()]; - std::cout << " here b: " << buildtrack.getLastGoodHitLyr() << " " << buildtrack.getLastGoodHitIdx() << std::endl; - if (seedID_FR_ == 5645) - { - for (int i = 0; i < Config::nMaxTrkHits; i++) - { - std::cout << buildtrack.getHitLyr(i) << " " << buildtrack.getHitIdx(i) << std::endl; - } - - - } - // last hit info const Hit& lasthit = evt_layer_hits[buildtrack.getLastGoodHitLyr()][buildtrack.getLastGoodHitIdx()]; xhit_build_FR_ = lasthit.x(); yhit_build_FR_ = lasthit.y(); zhit_build_FR_ = lasthit.z(); - std::cout << " here c " << std::endl; - pt_build_FR_ = buildtrack.pT(); ept_build_FR_ = buildtrack.epT(); phi_build_FR_ = buildtrack.momPhi(); @@ -1113,8 +1087,6 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) } } - std::cout << " " << mcID_build_FR_ << " " << mcmask_build_FR_ << std::endl; - if (mcmask_build_FR_ == 1) // build track matched to seed and sim { auto& simtrack = evt_sim_tracks[mcID_build_FR_]; @@ -1244,8 +1216,6 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) } } - std::cout << " " << mcID_fit_FR_ << " " << mcmask_fit_FR_ << std::endl; - if (mcmask_fit_FR_ == 1) // fit track matched to seed and sim { auto& simtrack = evt_sim_tracks[mcID_fit_FR_]; diff --git a/makeValidation.C b/makeValidation.C index 600ffc9e89c4b..bfd7dd0a2ca8b 100644 --- a/makeValidation.C +++ b/makeValidation.C @@ -8,7 +8,7 @@ #include -void makeValidation(TString label) +void makeValidation(TString label = "") { gStyle->SetOptStat(0); diff --git a/runValidation.C b/runValidation.C index a9a4cd486f6a4..13fdd13c2d141 100644 --- a/runValidation.C +++ b/runValidation.C @@ -16,7 +16,7 @@ void runValidation(TString test = "", Bool_t mvInput = true, { setupcpp11(); // use this to get PlotValidation to compile ... phiphi ROOT build has ACLiC with C++98! - gROOT->LoadMacro("PlotValidation.cpp++g"); + gROOT->LoadMacro("PlotValidation.cpp+g"); // PlotValidation arguments // First is additional input name of root file From 93e3a4356e84c498a0d821e062fd0203ac4dde41 Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Fri, 12 May 2017 03:12:23 -0700 Subject: [PATCH 052/172] bug fix: include short matched but not efficient tracks into inclusive FR calculation --- Config.cc | 6 +++--- Config.h | 2 +- PlotValidation.cpp | 8 ++------ TTreeValidation.cc | 45 ++++++++++++++++++++++++++------------------- main.cc | 8 ++++---- mkFit/mkFit.cc | 8 ++++---- 6 files changed, 40 insertions(+), 37 deletions(-) diff --git a/Config.cc b/Config.cc index f61994f2e5c03..8cf23f241ef67 100644 --- a/Config.cc +++ b/Config.cc @@ -53,9 +53,9 @@ namespace Config bool cf_seeding = false; bool cf_fitting = false; - bool root_val = false; - bool fit_val = false; - bool shortFakes = false; + bool root_val = false; + bool fit_val = false; + bool inclusiveShorts = false; void RecalculateDependentConstants() { diff --git a/Config.h b/Config.h index 9f8b335ac7fea..f7d78033e6c4b 100644 --- a/Config.h +++ b/Config.h @@ -230,7 +230,7 @@ namespace Config constexpr int nMinFoundHits = 7; extern bool root_val; extern bool fit_val; - extern bool shortFakes; + extern bool inclusiveShorts; // Effective eta bin is one half of nEtaPart -- so the above is twice the "average". // Note that last and first bin are 3/4 nEtaPart ... but can be made 1/4 by adding diff --git a/PlotValidation.cpp b/PlotValidation.cpp index 645936d21422f..e61b2936bd05d 100644 --- a/PlotValidation.cpp +++ b/PlotValidation.cpp @@ -220,7 +220,6 @@ void PlotValidation::PlotFakeRate() } IntVec mcmask_trk(trks.size()); // need to know if sim track associated to a given reco track type - IntVec seedmask_trk(trks.size()); // need to know if sim track associated to a given reco track type // Create FR plots TH1FRefVecVec varsNumerPlot(vars.size()); @@ -269,10 +268,7 @@ void PlotValidation::PlotFakeRate() for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index { mcmask_trk[j] = 0; - seedmask_trk[j] = 0; - fakeratetree->SetBranchAddress(Form("mcmask_%s",trks[j].Data()),&(mcmask_trk[j])); - fakeratetree->SetBranchAddress(Form("seedmask_%s",trks[j].Data()),&(seedmask_trk[j])); } // Fill histos, compute fake rate from tree branches @@ -283,7 +279,7 @@ void PlotValidation::PlotFakeRate() { for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index { - if (mcmask_trk[j] != -1) + if (mcmask_trk[j] != -1) // can include masks of 1,0,2 { varsDenomPlot[i][j]->Fill(recovars_val[i][j]); // all reco tracks fill denom if (mcmask_trk[j] == 0) // only completely unassociated reco tracks enter FR @@ -509,7 +505,7 @@ void PlotValidation::PlotNHits() { if (c == 0) // all reco { - if (seedmask_trk[j] == 1) // includes all the short tracks, too + if (seedmask_trk[j] == 1) // includes all the short tracks, too (including zero size tracks!!!) { nHitsPlot[j][c]->Fill(nHits_trk[j]); fracHitsMatchedPlot[j][c]->Fill(fracHitsMatched_trk[j]); diff --git a/TTreeValidation.cc b/TTreeValidation.cc index c9ceaee8971c5..77552e09ef957 100644 --- a/TTreeValidation.cc +++ b/TTreeValidation.cc @@ -1,35 +1,36 @@ // mcTrackID assignments in Track.cc // Efficiency -// numerator: sim tracks with at least one reco track with mcTrackID >= 0 +// numerator: sim tracks with at least one reco track with mcTrackID >= 0 (mcmask == 1) // denominator: all sim tracks -// Fake Rate (with only long reco tracks: Config::shortFakes == false) -// numerator: reco tracks with mcTrackID == -1 -// denominator: reco tracks with mcTrackID >= 0 || == -1 -// Fake Rate (with all reco tracks: Config::shortFakes == true) -// numerator: reco tracks with mcTrackID == -1, == -3 -// denominator: reco tracks with mcTrackID >= 0 || == -1 || == -2 || == -3 || == -4 +// Fake Rate (with only long reco tracks: Config::inclusiveShorts == false) +// numerator: reco tracks with mcTrackID == -1 (mcmask == 0) +// denominator: reco tracks with mcTrackID >= 0 || == -1 (mcmask == 1,0,2) +// Fake Rate (with all reco tracks: Config::inclusiveShorts == true) +// numerator: reco tracks with mcTrackID == -1, == -3 (mcmask == 0) +// denominator: reco tracks with mcTrackID >= 0 || == -1 || == -2 || == -3 || == -4 (mcmask == 1,0,2) // N.B. Mask assignments -// --> mcmask_[reco] == 1, "associated" reco to sim track [possible duplmask_[reco] == 1,0] {eff and FR} -// --> mcmask_[reco] == 0, "unassociated" reco to sim track. by definition no duplicates (no reco to associate to sim tracks!) [possible duplmask_[reco] == 2 {eff and FR}] +// --> mcmask_[reco] == 1,"associated" reco to sim track [possible duplmask_[reco] == 1,0] {eff and FR} +// --> mcmask_[reco] == 0,"unassociated" reco to sim track. by definition no duplicates (no reco to associate to sim tracks!) [possible duplmask_[reco] == 2 {eff and FR}] // --> mcmask_[reco] == -1, reco track excluded from denominator (and therefore numerator) of FR [possible duplmask_[reco] == -1] {FR only} +// --> mcmask_[reco] == 2, reco track included in demoninator of FR, but will not enter numerator: for short "matched" tracks of mcTrackID == -2,-4 {FR only} // --> nTkMatches_[reco] > 1, n reco tracks associated to the same sim track ID {eff only} // --> nTkMatches_[reco] == 1, 1 reco track associated to single sim track ID {eff only} // --> nTkMatches_[reco] == -99, no reco to sim match {eff only} // excluding position variables, as position could be -99! -// --> reco var == -99, "unassociated" reco to sim track, mcTrackID == -1 [possible mcmask_[reco] == 0; possible duplmask_[reco] == 2] {eff only} -// --> sim var == -99, "unassociated" reco to sim track, mcTrackID == -1 [possible mcmask_[reco] == 0; possible duplmask_[reco] == 2] {FR only} +// --> reco var == -99, "unassociated" reco to sim track [possible mcmask_[reco] == 0,-1,2; possible duplmask_[reco] == 2] {eff only} +// --> sim var == -99, "unassociated" reco to sim track [possible mcmask_[reco] == 0,-1,2; possible duplmask_[reco] == 2] {FR only} // --> reco/sim var == -100, "no matching seed to build/fit" track, fill all reco/sim variables -100 [possible mcmask_[reco] == -1, possible duplmask_[reco] == -1] {FR only} // --> sim var == -101, reco track is "associated" to sim track, however, sim track does have a hit on the layer the reco track is on -// --> seedmask_[reco] == 1, matching seed to reco/fit track [possible mcmask_[reco] == 0,1; possible duplmask_[reco] == 0,1,2] {FR only} +// --> seedmask_[reco] == 1, matching seed to reco/fit track [possible mcmask_[reco] == 0,1,2; possible duplmask_[reco] == 0,1,2] {FR only} // --> seedmask_[reco] == 0, no matching seed to reco/fit track [possible mcmask_[reco] == -1; possible duplmask_[reco] == -1] {FR only} // --> duplmask_[reco] == 0, only "associated" reco to sim track [possible mcmask_[reco] == 1] {eff and FR} // --> duplmask_[reco] == 1, more than one "associated" reco to sim track [possible mcmask_[reco] == 1] {eff and FR} -// --> duplmask_[reco] == 2, no "associated" reco to sim track [possible mcmask_[reco] == 0] {eff and FR} +// --> duplmask_[reco] == 2, no "associated" reco to sim track [possible mcmask_[reco] == 0,-1,2] {eff and FR} // --> duplmask_[reco] == -1, no matching built/fit track for given seed [possible mcmask_[reco] == -1] {FR only} // --> reco var == -10, variable not yet implemented for given track object @@ -987,9 +988,11 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) } else { - if (Config::shortFakes) + if (Config::inclusiveShorts) { - mcmask_seed_FR_ = ((mcID_seed_FR_ == -1 || mcID_seed_FR_ == -3) ? 0 : -1); // mask == -1 for mcID == -2,-4,-5 + if (mcID_seed_FR_ == -1 || mcID_seed_FR_ == -3) mcmask_seed_FR_ = 0; + else if (mcID_seed_FR_ == -2 || mcID_seed_FR_ == -4) mcmask_seed_FR_ = 2; + else mcmask_seed_FR_ = -1; // mcID == -5 } else { @@ -1077,9 +1080,11 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) } else { - if (Config::shortFakes) + if (Config::inclusiveShorts) { - mcmask_build_FR_ = ((mcID_build_FR_ == -1 || mcID_build_FR_ == -3) ? 0 : -1); // mask == -1 for mcID == -2,-4,-5 + if (mcID_build_FR_ == -1 || mcID_build_FR_ == -3) mcmask_build_FR_ = 0; + else if (mcID_build_FR_ == -2 || mcID_build_FR_ == -4) mcmask_build_FR_ = 2; + else mcmask_build_FR_ = -1; // mcID == -5 } else { @@ -1206,9 +1211,11 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) } else { - if (Config::shortFakes) + if (Config::inclusiveShorts) { - mcmask_fit_FR_ = ((mcID_fit_FR_ == -1 || mcID_fit_FR_ == -3) ? 0 : -1); // mask == -1 for mcID == -2,-4,-5 + if (mcID_fit_FR_ == -1 || mcID_fit_FR_ == -3) mcmask_fit_FR_ = 0; + else if (mcID_fit_FR_ == -2 || mcID_fit_FR_ == -4) mcmask_fit_FR_ = 2; + else mcmask_fit_FR_ = -1; // mcID == -5 } else { diff --git a/main.cc b/main.cc index f4bbcb5678767..de0d11e622125 100644 --- a/main.cc +++ b/main.cc @@ -179,7 +179,7 @@ int main(int argc, const char* argv[]) " --num-tracks number of tracks to generate for each event (def: %d)\n" " --num-thr number of threads used for TBB (def: %d)\n" " --root-val bool to enable normal validation (eff, FR, DR) (def: %s)\n" - " --short-fakes include short reco tracks into FR (def: %s)\n" + " --inc-shorts include short reco tracks into FR (def: %s)\n" " --cf-seeding bool to enable CF in MC seeding (def: %s)\n" " --read read input simtracks file (def: false)\n" " --file-name file name for write/read (def: %s)\n" @@ -191,7 +191,7 @@ int main(int argc, const char* argv[]) Config::nTracks, nThread, (Config::root_val ? "true" : "false"), - (Config::shortFakes ? "true" : "false"), + (Config::inclusiveShorts ? "true" : "false"), (Config::cf_seeding ? "true" : "false"), s_file_name.c_str(), Config::readCmsswSeeds, @@ -218,9 +218,9 @@ int main(int argc, const char* argv[]) { Config::root_val = true; Config::fit_val = false; } - else if (*i == "--short-fakes") + else if (*i == "--inc-shorts") { - Config::shortFakes = true; + Config::inclusiveShorts = true; } else if (*i == "--cf-seeding") { diff --git a/mkFit/mkFit.cc b/mkFit/mkFit.cc index 25d4c0f343a3e..3a935a8c7b2da 100644 --- a/mkFit/mkFit.cc +++ b/mkFit/mkFit.cc @@ -507,7 +507,7 @@ int main(int argc, const char *argv[]) " --cf-fitting enable CF in fitting (def: %s)\n" " --root-val enable ROOT based validation for building [eff, FR, DR] (def: %s)\n" " --fit-val enable ROOT based validation for fitting (def: %s)\n" - " --short-fakes include short reco tracks into FR (def: %s)\n" + " --inc-shorts include short reco tracks into FR (def: %s)\n" " --silent suppress printouts inside event loop (def: %s)\n" " --write write simulation to file and exit\n" " --read read simulation from file\n" @@ -533,7 +533,7 @@ int main(int argc, const char *argv[]) b2a(Config::cf_fitting), b2a(Config::root_val), b2a(Config::fit_val), - b2a(Config::shortFakes), + b2a(Config::inclusiveShorts), b2a(Config::silent), g_file_name.c_str(), g_input_file.c_str(), @@ -635,9 +635,9 @@ int main(int argc, const char *argv[]) { Config::root_val = false; Config::fit_val = true; } - else if (*i == "--short-fakes") + else if (*i == "--inc-shorts") { - Config::shortFakes = true; + Config::inclusiveShorts = true; } else if (*i == "--num-thr-ev") { From 026234f7f7f72b63753b763f99d9b7c59836b192 Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Fri, 12 May 2017 09:55:01 -0700 Subject: [PATCH 053/172] Add . to rpath of mkFit so it can be run from the top directory, too. --- mkFit/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mkFit/Makefile b/mkFit/Makefile index 1c25b18bccaba..51a2d1aaf3e80 100644 --- a/mkFit/Makefile +++ b/mkFit/Makefile @@ -89,7 +89,7 @@ include ${MKFDEPS} endif mkFit: ${ALLOBJS} - ${CXX} ${CXXFLAGS} ${VEC_HOST} ${LDFLAGS} ${ALLOBJS} -o $@ ${LDFLAGS_HOST} ${LDFLAGS_CU} -L.. -lMicCore -Wl,-rpath=.. + ${CXX} ${CXXFLAGS} ${VEC_HOST} ${LDFLAGS} ${ALLOBJS} -o $@ ${LDFLAGS_HOST} ${LDFLAGS_CU} -L.. -lMicCore -Wl,-rpath=..,-rpath=. ifdef WITH_ROOT fittestMPlex.o : CPPFLAGS += $(shell root-config --cflags) @@ -118,7 +118,7 @@ MKFOBJS_MIC := $(MKFOBJS:.o=.om) ALLOBJS_MIC := $(ALLOBJS:.o=.om) mkFit-mic: ${ALLOBJS_MIC} - ${CXX} ${CXXFLAGS} ${VEC_MIC} ${LDFLAGS_NO_ROOT} ${ALLOBJS_MIC} -o $@ ${LDFLAGS_MIC} -L.. -lMicCore-mic -Wl,-rpath=.. + ${CXX} ${CXXFLAGS} ${VEC_MIC} ${LDFLAGS_NO_ROOT} ${ALLOBJS_MIC} -o $@ ${LDFLAGS_MIC} -L.. -lMicCore-mic -Wl,-rpath=..,-rpath=. ${MKFOBJS_MIC}: %.om: %.cc %.d ${CXX} ${CPPFLAGS_NO_ROOT} ${CXXFLAGS} ${VEC_MIC} -c -o $@ $< From 7a08905230c940e8533b063c2850c52f3846b7d4 Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Fri, 12 May 2017 11:03:05 -0700 Subject: [PATCH 054/172] CloneEngine - Fix logic bug when there are no cands to process on a layer. --- mkFit/MkBuilder.cc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index 0bf12ae5470e1..c8b6e5808b688 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -1354,13 +1354,14 @@ void MkBuilder::find_tracks_in_layers(CandCloner &cloner, MkFitter *mkfp, } const int theEndCand = seed_cand_idx.size(); - // don't bother messing with the clone engine if there are no candidates - // (actually it crashes, so this protection is needed) - - if (theEndCand == 0) { - if (ilay < 0) break; - else continue; - } + // Don't bother messing with the clone engine if there are no candidates + // (actually it crashes, so this protection is needed). + // If there are no cands on this iteration, there won't be any later on either, + // by the construction of the seed_cand_idx vector. + // XXXXMT There might be cases in endcap where all tracks will miss the + // next layer, but only relevant if we do geometric selection before. + + if (theEndCand == 0) break; if (ilay >= 0) { From a232964772efcace1cdc78589b549e3475b09f72 Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Fri, 12 May 2017 13:15:06 -0700 Subject: [PATCH 055/172] add inefficiency plots for barrel and endcap --- PlotValidation.cpp | 146 ++++++++++++++++++++++++++++++++++++++++++--- PlotValidation.hh | 1 + makeValidation.C | 9 ++- 3 files changed, 148 insertions(+), 8 deletions(-) diff --git a/PlotValidation.cpp b/PlotValidation.cpp index e61b2936bd05d..d070e621aecb8 100644 --- a/PlotValidation.cpp +++ b/PlotValidation.cpp @@ -64,6 +64,7 @@ PlotValidation::~PlotValidation() void PlotValidation::Validation() { PlotValidation::PlotEfficiency(); + PlotValidation::PlotInefficiencyVsGeom(); PlotValidation::PlotFakeRate(); PlotValidation::PlotDuplicateRate(); PlotValidation::PlotNHits(); @@ -95,7 +96,7 @@ void PlotValidation::PlotEfficiency() TStrVec vars = {"pt","eta","phi"}; TStrVec svars = {"p_{T}","#eta","#phi"}; // svars --> labels for histograms for given variable TStrVec sunits= {" [GeV/c]","",""}; // units --> labels for histograms for given variable - IntVec nBins = {60,60,80}; + IntVec nBins = {60,60,80}; FltVec xlow = {0,-3,-4}; FltVec xhigh = {15,3,4}; @@ -187,6 +188,137 @@ void PlotValidation::PlotEfficiency() delete efftree; } +void PlotValidation::PlotInefficiencyVsGeom() +{ + // Get tree + TTree * efftree = (TTree*)fInRoot->Get("efftree"); + + // make output subdirectory and subdir in ROOT file, and cd to it. + TString subdirname = "inefficiency"; + PlotValidation::MakeSubDirectory(subdirname); + PlotValidation::MakeSubDirectory(Form("%s/lin",subdirname.Data())); + PlotValidation::MakeSubDirectory(Form("%s/log",subdirname.Data())); + TDirectory * subdir = fOutRoot->mkdir(subdirname.Data()); + subdir->cd(); + + //Declare strings for branches and plots + Bool_t zeroSupLin = true; + TStrVec vars = {"pt","eta","phi"}; + TStrVec svars = {"p_{T}","#eta","#phi"}; // svars --> labels for histograms for given variable + TStrVec sunits= {" [GeV/c]","",""}; // units --> labels for histograms for given variable + IntVec nBins = {60,60,80}; + FltVec xlow = {0,-3,-4}; + FltVec xhigh = {15,3,4}; + + TStrVec regs = {"barrel","endcap"}; + TStrVec sregs = {"Barrel","Endcap"}; + + TStrVec trks = {"seed","build","fit"}; + TStrVec strks = {"Seed","Build","Fit"}; // strk --> labels for histograms for given track type + + // Floats/Ints to be filled for trees + FltVec mcvars_val(vars.size()); // first index is var. only for mc values! so no extra index + IntVec mcmask_trk(trks.size()); // need to know if sim track associated to a given reco track type + + // Create plots + std::vector varsNumerPlot(regs.size()); + std::vector varsDenomPlot(regs.size()); + std::vector varsEffPlot(regs.size()); + for (UInt_t h = 0; h < regs.size(); h++) + { + varsNumerPlot[h].resize(vars.size()); + varsDenomPlot[h].resize(vars.size()); + varsEffPlot[h].resize(vars.size()); + for (UInt_t i = 0; i < vars.size(); i++) + { + varsNumerPlot[h][i].resize(trks.size()); + varsDenomPlot[h][i].resize(trks.size()); + varsEffPlot[h][i].resize(trks.size()); + } + } + + for (UInt_t h = 0; h < regs.size(); h++) + { + for (UInt_t i = 0; i < vars.size(); i++) + { + for (UInt_t j = 0; j < trks.size(); j++) + { + // Numerator + varsNumerPlot[h][i][j] = new TH1F(Form("h_sim_%s_numer_%s_%s_INEFF_%s",vars[i].Data(),regs[h].Data(),trks[j].Data(),regs[h].Data()),Form("%s Track vs MC %s (Numer) Ineff %s",strks[j].Data(),svars[i].Data(),sregs[h].Data()),nBins[i],xlow[i],xhigh[i]); + varsNumerPlot[h][i][j]->GetXaxis()->SetTitle(Form("%s%s",svars[i].Data(),sunits[i].Data())); + varsNumerPlot[h][i][j]->GetYaxis()->SetTitle("nTracks"); + // Denominator + varsDenomPlot[h][i][j] = new TH1F(Form("h_sim_%s_denom_%s_%s_INEFF_%s",vars[i].Data(),regs[h].Data(),trks[j].Data(),regs[h].Data()),Form("%s Track vs MC %s (Denom) Ineff %s",strks[j].Data(),svars[i].Data(),sregs[h].Data()),nBins[i],xlow[i],xhigh[i]); + varsDenomPlot[h][i][j]->GetXaxis()->SetTitle(Form("%s%s",svars[i].Data(),sunits[i].Data())); + varsDenomPlot[h][i][j]->GetYaxis()->SetTitle("nTracks"); + // Efficiency + varsEffPlot[h][i][j] = new TH1F(Form("h_sim_%s_INEFF_%s_%s_INEFF_%s",vars[i].Data(),regs[h].Data(),trks[j].Data(),regs[h].Data()),Form("%s Track Inefficiency vs MC %s %s",strks[j].Data(),svars[i].Data(),sregs[h].Data()),nBins[i],xlow[i],xhigh[i]); + varsEffPlot[h][i][j]->GetXaxis()->SetTitle(Form("%s%s",svars[i].Data(),sunits[i].Data())); + varsEffPlot[h][i][j]->GetYaxis()->SetTitle("Inefficiency"); + } + } + } + + //Initialize var_val/err arrays, SetBranchAddress + for (UInt_t i = 0; i < vars.size(); i++) // loop over trks index + { + // initialize var + mcvars_val[i] = 0.; + + //Set var+trk branch + efftree->SetBranchAddress(Form("%s_mc_gen",vars[i].Data()),&(mcvars_val[i])); + } + + //Initialize masks, set branch addresses + for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index + { + mcmask_trk[j] = 0; + efftree->SetBranchAddress(Form("mcmask_%s",trks[j].Data()),&(mcmask_trk[j])); + } + + // Fill histos, compute eff from tree branches + for (Int_t k = 0; k < efftree->GetEntries(); k++) + { + efftree->GetEntry(k); + for (UInt_t h = 0; h < regs.size(); h++) + { + if (h == 0 && std::abs(mcvars_val[1]) > 1.f) continue; // barrel only + if (h == 1 && std::abs(mcvars_val[1]) < 1.f) continue; // endcap only + + for (UInt_t i = 0; i < vars.size(); i++) // loop over vars index + { + for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index + { + varsDenomPlot[h][i][j]->Fill(mcvars_val[i]); + if (mcmask_trk[j] == 0) // must be associated + { + varsNumerPlot[h][i][j]->Fill(mcvars_val[i]); + } // must be a matched track for efficiency + } // end loop over trks + } // end loop over vars + } // end loop over regions + } // end loop over entry in tree + + // Draw, divide, and save efficiency plots + for (UInt_t h = 0; h < regs.size(); h++) + { + for (UInt_t i = 0; i < vars.size(); i++) + { + for (UInt_t j = 0; j < trks.size(); j++) + { + PlotValidation::ComputeRatioPlot(varsNumerPlot[h][i][j],varsDenomPlot[h][i][j],varsEffPlot[h][i][j]); + PlotValidation::WriteTH1FPlot(subdir,varsNumerPlot[h][i][j]); + PlotValidation::WriteTH1FPlot(subdir,varsDenomPlot[h][i][j]); + PlotValidation::DrawWriteSaveTH1FPlot(subdir,varsEffPlot[h][i][j],subdirname,Form("%s_INEFF_%s_%s",vars[i].Data(),trks[j].Data(),regs[h].Data()),zeroSupLin); + delete varsNumerPlot[h][i][j]; + delete varsDenomPlot[h][i][j]; + delete varsEffPlot[h][i][j]; + } + } + } + delete efftree; +} + void PlotValidation::PlotFakeRate() { // Get tree @@ -205,7 +337,7 @@ void PlotValidation::PlotFakeRate() TStrVec vars = {"pt","eta","phi"}; TStrVec svars = {"p_{T}","#eta","#phi"}; // svars --> labels for histograms for given variable TStrVec sunits= {" [GeV/c]","",""}; // units --> labels for histograms for given variable - IntVec nBins = {60,60,80}; + IntVec nBins = {60,60,80}; FltVec xlow = {0,-3,-4}; FltVec xhigh = {15,3,4}; @@ -325,7 +457,7 @@ void PlotValidation::PlotDuplicateRate(){ TStrVec vars = {"pt","eta","phi"}; TStrVec svars = {"p_{T}","#eta","#phi"}; // svars --> labels for histograms for given variable TStrVec sunits= {" [GeV/c]","",""}; // units --> labels for histograms for given variable - IntVec nBins = {60,60,80}; + IntVec nBins = {60,60,80}; FltVec xlow = {0,-3,-4}; FltVec xhigh = {15,3,4}; @@ -573,11 +705,11 @@ void PlotValidation::PlotMomResolutionPull() TStrVec evars = {"ept","eeta","ephi"}; TStrVec svars = {"p_{T}","#eta","#phi"}; // svars --> labels for histograms for given variable TStrVec sunits = {" [GeV/c]","",""}; // units --> labels for histograms for given variable - IntVec nBinsRes = {100,100,100}; + IntVec nBinsRes = {100,100,100}; FltVec xlowRes = {-0.5,-0.5,-0.5}; FltVec xhighRes = {0.5,0.5,0.5}; FltVec gausRes = {0.3,0.3,0.3}; // symmetric bounds for gaussian fit - IntVec nBinsPull = {100,100,100}; + IntVec nBinsPull = {100,100,100}; FltVec xlowPull = {-5,-5,-5}; FltVec xhighPull = {5,5,5}; FltVec gausPull = {3,3,3}; // symmetric bounds for gaussian fit @@ -793,8 +925,8 @@ void PlotValidation::PrintTotals() totalsout << "==========================================" << std::endl; for (UInt_t r = 0; r < rates.size(); r++) { - Int_t numerIntegral = numerPhiPlot[j][r]->Integral(0,numerPhiPlot[j][r]->GetNbinsX()+1); - Int_t denomIntegral = denomPhiPlot[j][r]->Integral(0,denomPhiPlot[j][r]->GetNbinsX()+1); + Int_t numerIntegral = numerPhiPlot[j][r]->GetEntries(); + Int_t denomIntegral = denomPhiPlot[j][r]->GetEntries(); Float_t ratetotal = Float_t(numerIntegral) / Float_t(denomIntegral); std::cout << snumer[r].Data() << ": " << numerIntegral << std::endl; diff --git a/PlotValidation.hh b/PlotValidation.hh index acbe8c152b62c..865174e2d4042 100644 --- a/PlotValidation.hh +++ b/PlotValidation.hh @@ -42,6 +42,7 @@ public: void Validation(); void PlotEfficiency(); + void PlotInefficiencyVsGeom(); void PlotFakeRate(); void PlotDuplicateRate(); void PlotNHits(); diff --git a/makeValidation.C b/makeValidation.C index bfd7dd0a2ca8b..049da6cf5c8ea 100644 --- a/makeValidation.C +++ b/makeValidation.C @@ -18,14 +18,20 @@ void makeValidation(TString label = "") std::vector dirs; dirs.push_back("efficiency"); + dirs.push_back("inefficiency"); + dirs.push_back("inefficiency"); dirs.push_back("fakerate"); dirs.push_back("duplicaterate"); std::vector sORr; sORr.push_back("sim"); + sORr.push_back("sim"); + sORr.push_back("sim"); sORr.push_back("reco"); sORr.push_back("sim"); std::vector rates; rates.push_back("EFF"); + rates.push_back("INEFF_barrel"); + rates.push_back("INEFF_endcap"); rates.push_back("FR"); rates.push_back("DR"); std::vector vars; @@ -51,7 +57,8 @@ void makeValidation(TString label = "") h_std->SetMarkerColor(kGreen+1); h_ce ->SetMarkerColor(kRed); - h_bh ->GetYaxis()->SetRangeUser(0.0,1.05); + if (!rates[i].Contains("INEFF",TString::kExact)) h_bh->GetYaxis()->SetRangeUser(0.0,0.05); + else h_bh->GetYaxis()->SetRangeUser(0.0,0.1); h_bh ->Draw("lep"); h_std->Draw("lep same"); From f25cbb0244798a9bcda7ba03536971878f5744e4 Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Sat, 13 May 2017 00:55:48 +0200 Subject: [PATCH 056/172] Update makeValidation.C change scale back to correct value --- makeValidation.C | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makeValidation.C b/makeValidation.C index 049da6cf5c8ea..5f35845320df2 100644 --- a/makeValidation.C +++ b/makeValidation.C @@ -57,7 +57,7 @@ void makeValidation(TString label = "") h_std->SetMarkerColor(kGreen+1); h_ce ->SetMarkerColor(kRed); - if (!rates[i].Contains("INEFF",TString::kExact)) h_bh->GetYaxis()->SetRangeUser(0.0,0.05); + if (!rates[i].Contains("INEFF",TString::kExact)) h_bh->GetYaxis()->SetRangeUser(0.0,1.05); else h_bh->GetYaxis()->SetRangeUser(0.0,0.1); h_bh ->Draw("lep"); From 959c42d84a48764a06c9fe5257a847603eb5aba0 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Fri, 12 May 2017 20:21:55 -0700 Subject: [PATCH 057/172] add some optional more detailed printout --- tkNtuple/WriteMemoryFile.cc | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/tkNtuple/WriteMemoryFile.cc b/tkNtuple/WriteMemoryFile.cc index 7df12da8c79a3..363fe125033b9 100644 --- a/tkNtuple/WriteMemoryFile.cc +++ b/tkNtuple/WriteMemoryFile.cc @@ -194,12 +194,18 @@ int main() { std::vector* simhit_process; std::vector* simhit_particle; std::vector* simhit_simTrkIdx; + std::vector* simhit_x; + std::vector* simhit_y; + std::vector* simhit_z; std::vector* simhit_px; std::vector* simhit_py; std::vector* simhit_pz; t->SetBranchAddress("simhit_process", &simhit_process); t->SetBranchAddress("simhit_particle", &simhit_particle); t->SetBranchAddress("simhit_simTrkIdx", &simhit_simTrkIdx); + t->SetBranchAddress("simhit_x", &simhit_x); + t->SetBranchAddress("simhit_y", &simhit_y); + t->SetBranchAddress("simhit_z", &simhit_z); t->SetBranchAddress("simhit_px", &simhit_px); t->SetBranchAddress("simhit_py", &simhit_py); t->SetBranchAddress("simhit_pz", &simhit_pz); @@ -613,13 +619,19 @@ int main() { } } - // if (ibest >= 0) std::cout<<" best tkIdx "<at(shbest) - // <<" particle "<at(shbest) - // <= 0 && false){ + std::cout<<" best tkIdx "<at(shbest) + <<" particle "<at(shbest) + <at(shbest)<<", "<at(shbest)<<", "<at(shbest) + <<" rh "<at(rhIdx)<<", "<at(rhIdx)<<", "<at(rhIdx) < Date: Thu, 25 May 2017 17:44:17 +0200 Subject: [PATCH 058/172] Switch to TEfficiency ... Duplicate Rate is now nerfed --- PlotValidation.cpp | 359 ++++++++++++++------------------------------- PlotValidation.hh | 32 ++-- makeValidation.C | 53 +++---- 3 files changed, 155 insertions(+), 289 deletions(-) diff --git a/PlotValidation.cpp b/PlotValidation.cpp index d070e621aecb8..ddd908ccdbb6f 100644 --- a/PlotValidation.cpp +++ b/PlotValidation.cpp @@ -34,8 +34,8 @@ PlotValidation::PlotValidation(TString inName, TString outName, gStyle->SetStatY(1.0); gStyle->SetStatH(0.08); + fTEffCanv = new TCanvas(); fTH1Canv = new TCanvas(); - fTH2Canv = new TCanvas(); // fColorBase fColors.push_back(kBlue); @@ -57,8 +57,8 @@ PlotValidation::~PlotValidation() { delete fInRoot; delete fOutRoot; // will delete all pointers to subdirectory + delete fTEffCanv; delete fTH1Canv; - delete fTH2Canv; } void PlotValidation::Validation() @@ -69,9 +69,7 @@ void PlotValidation::Validation() PlotValidation::PlotDuplicateRate(); PlotValidation::PlotNHits(); PlotValidation::PlotMomResolutionPull(); - PlotValidation::PrintTotals(); - if (fMvInput) { PlotValidation::MoveInput(); @@ -92,7 +90,6 @@ void PlotValidation::PlotEfficiency() subdir->cd(); //Declare strings for branches and plots - Bool_t zeroSupLin = true; TStrVec vars = {"pt","eta","phi"}; TStrVec svars = {"p_{T}","#eta","#phi"}; // svars --> labels for histograms for given variable TStrVec sunits= {" [GeV/c]","",""}; // units --> labels for histograms for given variable @@ -108,32 +105,16 @@ void PlotValidation::PlotEfficiency() IntVec mcmask_trk(trks.size()); // need to know if sim track associated to a given reco track type // Create plots - TH1FRefVecVec varsNumerPlot(vars.size()); - TH1FRefVecVec varsDenomPlot(vars.size()); - TH1FRefVecVec varsEffPlot(vars.size()); - for (UInt_t i = 0; i < vars.size(); i++) - { - varsNumerPlot[i].resize(trks.size()); - varsDenomPlot[i].resize(trks.size()); - varsEffPlot[i].resize(trks.size()); - } - + TEffRefVecVec varsEff(vars.size()); for (UInt_t i = 0; i < vars.size(); i++) { + varsEff[i].resize(trks.size()); for (UInt_t j = 0; j < trks.size(); j++) { - // Numerator - varsNumerPlot[i][j] = new TH1F(Form("h_sim_%s_numer_%s_EFF",vars[i].Data(),trks[j].Data()),Form("%s Track vs MC %s (Numer) Eff",strks[j].Data(),svars[i].Data()),nBins[i],xlow[i],xhigh[i]); - varsNumerPlot[i][j]->GetXaxis()->SetTitle(Form("%s%s",svars[i].Data(),sunits[i].Data())); - varsNumerPlot[i][j]->GetYaxis()->SetTitle("nTracks"); - // Denominator - varsDenomPlot[i][j] = new TH1F(Form("h_sim_%s_denom_%s_EFF",vars[i].Data(),trks[j].Data()),Form("%s Track vs MC %s (Denom) Eff",strks[j].Data(),svars[i].Data()),nBins[i],xlow[i],xhigh[i]); - varsDenomPlot[i][j]->GetXaxis()->SetTitle(Form("%s%s",svars[i].Data(),sunits[i].Data())); - varsDenomPlot[i][j]->GetYaxis()->SetTitle("nTracks"); - // Efficiency - varsEffPlot[i][j] = new TH1F(Form("h_sim_%s_EFF_%s_EFF",vars[i].Data(),trks[j].Data()),Form("%s Track Efficiency vs MC %s",strks[j].Data(),svars[i].Data()),nBins[i],xlow[i],xhigh[i]); - varsEffPlot[i][j]->GetXaxis()->SetTitle(Form("%s%s",svars[i].Data(),sunits[i].Data())); - varsEffPlot[i][j]->GetYaxis()->SetTitle("Efficiency"); + varsEff[i][j] = new TEfficiency(Form("eff_sim_%s_%s",vars[i].Data(),trks[j].Data()), + Form("%s Track Efficiency vs MC %s;%s%s;Efficiency", + strks[j].Data(),svars[i].Data(),svars[i].Data(),sunits[i].Data()), + nBins[i],xlow[i],xhigh[i]); } } @@ -162,11 +143,7 @@ void PlotValidation::PlotEfficiency() { for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index { - varsDenomPlot[i][j]->Fill(mcvars_val[i]); - if (mcmask_trk[j] == 1) // must be associated - { - varsNumerPlot[i][j]->Fill(mcvars_val[i]); - } // must be a matched track for efficiency + varsEff[i][j]->Fill((mcmask_trk[j]==1),mcvars_val[i]); // mc track must be associated to enter numerator } // end loop over trks } // end loop over vars } // end loop over entry in tree @@ -176,13 +153,8 @@ void PlotValidation::PlotEfficiency() { for (UInt_t j = 0; j < trks.size(); j++) { - PlotValidation::ComputeRatioPlot(varsNumerPlot[i][j],varsDenomPlot[i][j],varsEffPlot[i][j]); - PlotValidation::WriteTH1FPlot(subdir,varsNumerPlot[i][j]); - PlotValidation::WriteTH1FPlot(subdir,varsDenomPlot[i][j]); - PlotValidation::DrawWriteSaveTH1FPlot(subdir,varsEffPlot[i][j],subdirname,Form("%s_EFF_%s",vars[i].Data(),trks[j].Data()),zeroSupLin); - delete varsNumerPlot[i][j]; - delete varsDenomPlot[i][j]; - delete varsEffPlot[i][j]; + PlotValidation::DrawWriteSaveTEffPlot(subdir,varsEff[i][j],subdirname,Form("eff_%s_%s",vars[i].Data(),trks[j].Data())); + delete varsEff[i][j]; } } delete efftree; @@ -202,7 +174,6 @@ void PlotValidation::PlotInefficiencyVsGeom() subdir->cd(); //Declare strings for branches and plots - Bool_t zeroSupLin = true; TStrVec vars = {"pt","eta","phi"}; TStrVec svars = {"p_{T}","#eta","#phi"}; // svars --> labels for histograms for given variable TStrVec sunits= {" [GeV/c]","",""}; // units --> labels for histograms for given variable @@ -221,40 +192,20 @@ void PlotValidation::PlotInefficiencyVsGeom() IntVec mcmask_trk(trks.size()); // need to know if sim track associated to a given reco track type // Create plots - std::vector varsNumerPlot(regs.size()); - std::vector varsDenomPlot(regs.size()); - std::vector varsEffPlot(regs.size()); - for (UInt_t h = 0; h < regs.size(); h++) - { - varsNumerPlot[h].resize(vars.size()); - varsDenomPlot[h].resize(vars.size()); - varsEffPlot[h].resize(vars.size()); - for (UInt_t i = 0; i < vars.size(); i++) - { - varsNumerPlot[h][i].resize(trks.size()); - varsDenomPlot[h][i].resize(trks.size()); - varsEffPlot[h][i].resize(trks.size()); - } - } - + TEffRefVecVecVec varsIneff(regs.size()); for (UInt_t h = 0; h < regs.size(); h++) { + varsIneff[h].resize(vars.size()); for (UInt_t i = 0; i < vars.size(); i++) { + varsIneff[h][i].resize(trks.size()); for (UInt_t j = 0; j < trks.size(); j++) { - // Numerator - varsNumerPlot[h][i][j] = new TH1F(Form("h_sim_%s_numer_%s_%s_INEFF_%s",vars[i].Data(),regs[h].Data(),trks[j].Data(),regs[h].Data()),Form("%s Track vs MC %s (Numer) Ineff %s",strks[j].Data(),svars[i].Data(),sregs[h].Data()),nBins[i],xlow[i],xhigh[i]); - varsNumerPlot[h][i][j]->GetXaxis()->SetTitle(Form("%s%s",svars[i].Data(),sunits[i].Data())); - varsNumerPlot[h][i][j]->GetYaxis()->SetTitle("nTracks"); - // Denominator - varsDenomPlot[h][i][j] = new TH1F(Form("h_sim_%s_denom_%s_%s_INEFF_%s",vars[i].Data(),regs[h].Data(),trks[j].Data(),regs[h].Data()),Form("%s Track vs MC %s (Denom) Ineff %s",strks[j].Data(),svars[i].Data(),sregs[h].Data()),nBins[i],xlow[i],xhigh[i]); - varsDenomPlot[h][i][j]->GetXaxis()->SetTitle(Form("%s%s",svars[i].Data(),sunits[i].Data())); - varsDenomPlot[h][i][j]->GetYaxis()->SetTitle("nTracks"); // Efficiency - varsEffPlot[h][i][j] = new TH1F(Form("h_sim_%s_INEFF_%s_%s_INEFF_%s",vars[i].Data(),regs[h].Data(),trks[j].Data(),regs[h].Data()),Form("%s Track Inefficiency vs MC %s %s",strks[j].Data(),svars[i].Data(),sregs[h].Data()),nBins[i],xlow[i],xhigh[i]); - varsEffPlot[h][i][j]->GetXaxis()->SetTitle(Form("%s%s",svars[i].Data(),sunits[i].Data())); - varsEffPlot[h][i][j]->GetYaxis()->SetTitle("Inefficiency"); + varsIneff[h][i][j] = new TEfficiency(Form("ineff_%s_sim_%s_%s",regs[h].Data(),vars[i].Data(),trks[j].Data()), + Form("%s Track Inefficiency vs MC %s %s;%s%s;Inefficiency", + strks[j].Data(),svars[i].Data(),sregs[h].Data(),svars[i].Data(),sunits[i].Data()), + nBins[i],xlow[i],xhigh[i]); } } } @@ -289,11 +240,7 @@ void PlotValidation::PlotInefficiencyVsGeom() { for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index { - varsDenomPlot[h][i][j]->Fill(mcvars_val[i]); - if (mcmask_trk[j] == 0) // must be associated - { - varsNumerPlot[h][i][j]->Fill(mcvars_val[i]); - } // must be a matched track for efficiency + varsIneff[h][i][j]->Fill((mcmask_trk[j] == 0),mcvars_val[i]); // mc track must be UNassociated to enter numerator } // end loop over trks } // end loop over vars } // end loop over regions @@ -306,13 +253,8 @@ void PlotValidation::PlotInefficiencyVsGeom() { for (UInt_t j = 0; j < trks.size(); j++) { - PlotValidation::ComputeRatioPlot(varsNumerPlot[h][i][j],varsDenomPlot[h][i][j],varsEffPlot[h][i][j]); - PlotValidation::WriteTH1FPlot(subdir,varsNumerPlot[h][i][j]); - PlotValidation::WriteTH1FPlot(subdir,varsDenomPlot[h][i][j]); - PlotValidation::DrawWriteSaveTH1FPlot(subdir,varsEffPlot[h][i][j],subdirname,Form("%s_INEFF_%s_%s",vars[i].Data(),trks[j].Data(),regs[h].Data()),zeroSupLin); - delete varsNumerPlot[h][i][j]; - delete varsDenomPlot[h][i][j]; - delete varsEffPlot[h][i][j]; + PlotValidation::DrawWriteSaveTEffPlot(subdir,varsIneff[h][i][j],subdirname,Form("ineff_%s_%s_%s",regs[h].Data(),vars[i].Data(),trks[j].Data())); + delete varsIneff[h][i][j]; } } } @@ -333,7 +275,6 @@ void PlotValidation::PlotFakeRate() subdir->cd(); //Declare strings for branches and plots - Bool_t zeroSupLin = true; TStrVec vars = {"pt","eta","phi"}; TStrVec svars = {"p_{T}","#eta","#phi"}; // svars --> labels for histograms for given variable TStrVec sunits= {" [GeV/c]","",""}; // units --> labels for histograms for given variable @@ -354,32 +295,17 @@ void PlotValidation::PlotFakeRate() IntVec mcmask_trk(trks.size()); // need to know if sim track associated to a given reco track type // Create FR plots - TH1FRefVecVec varsNumerPlot(vars.size()); - TH1FRefVecVec varsDenomPlot(vars.size()); - TH1FRefVecVec varsFRPlot(vars.size()); - for (UInt_t i = 0; i < vars.size(); i++) - { - varsNumerPlot[i].resize(trks.size()); - varsDenomPlot[i].resize(trks.size()); - varsFRPlot[i].resize(trks.size()); - } - + TEffRefVecVec varsFR(vars.size()); for (UInt_t i = 0; i < vars.size(); i++) { + varsFR[i].resize(trks.size()); for (UInt_t j = 0; j < trks.size(); j++) { - // Numerator - varsNumerPlot[i][j] = new TH1F(Form("h_reco_%s_numer_%s_FR",vars[i].Data(),trks[j].Data()),Form("%s Track vs Reco %s (Numer) FR",strks[j].Data(),svars[i].Data()),nBins[i],xlow[i],xhigh[i]); - varsNumerPlot[i][j]->GetXaxis()->SetTitle(Form("%s%s",svars[i].Data(),sunits[i].Data())); - varsNumerPlot[i][j]->GetYaxis()->SetTitle("nTracks"); - // Denominator - varsDenomPlot[i][j] = new TH1F(Form("h_reco_%s_denom_%s_FR",vars[i].Data(),trks[j].Data()),Form("%s Track vs Reco %s (Denom) FR",strks[j].Data(),svars[i].Data()),nBins[i],xlow[i],xhigh[i]); - varsDenomPlot[i][j]->GetXaxis()->SetTitle(Form("%s%s",svars[i].Data(),sunits[i].Data())); - varsDenomPlot[i][j]->GetYaxis()->SetTitle("nTracks"); // Fake Rate - varsFRPlot[i][j] = new TH1F(Form("h_reco_%s_FR_%s_FR",vars[i].Data(),trks[j].Data()),Form("%s Track Fake Rate vs Reco %s",strks[j].Data(),svars[i].Data()),nBins[i],xlow[i],xhigh[i]); - varsFRPlot[i][j]->GetXaxis()->SetTitle(Form("%s%s",svars[i].Data(),sunits[i].Data())); - varsFRPlot[i][j]->GetYaxis()->SetTitle("Fake Rate"); + varsFR[i][j] = new TEfficiency(Form("fr_reco_%s_%s",vars[i].Data(),trks[j].Data()), + Form("%s Track Fake Rate vs Reco %s;%s%s;Fake Rate", + strks[j].Data(),svars[i].Data(),svars[i].Data(),sunits[i].Data()), + nBins[i],xlow[i],xhigh[i]); } } @@ -411,13 +337,9 @@ void PlotValidation::PlotFakeRate() { for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index { - if (mcmask_trk[j] != -1) // can include masks of 1,0,2 + if (mcmask_trk[j] != -1) // can include masks of 1,0,2 to enter denominator { - varsDenomPlot[i][j]->Fill(recovars_val[i][j]); // all reco tracks fill denom - if (mcmask_trk[j] == 0) // only completely unassociated reco tracks enter FR - { - varsNumerPlot[i][j]->Fill(recovars_val[i][j]); - } // must be an unmatched track for FR + varsFR[i][j]->Fill((mcmask_trk[j] == 0),recovars_val[i][j]); // only completely unassociated reco tracks enter FR } // must be a real reco track for FR } // end loop over trks } // end loop over vars @@ -428,19 +350,15 @@ void PlotValidation::PlotFakeRate() { for (UInt_t j = 0; j < trks.size(); j++) { - PlotValidation::ComputeRatioPlot(varsNumerPlot[i][j],varsDenomPlot[i][j],varsFRPlot[i][j]); - PlotValidation::WriteTH1FPlot(subdir,varsNumerPlot[i][j]); - PlotValidation::WriteTH1FPlot(subdir,varsDenomPlot[i][j]); - PlotValidation::DrawWriteSaveTH1FPlot(subdir,varsFRPlot[i][j],subdirname,Form("%s_FR_%s",vars[i].Data(),trks[j].Data()),zeroSupLin); - delete varsNumerPlot[i][j]; - delete varsDenomPlot[i][j]; - delete varsFRPlot[i][j]; + PlotValidation::DrawWriteSaveTEffPlot(subdir,varsFR[i][j],subdirname,Form("fr_%s_%s",vars[i].Data(),trks[j].Data())); + delete varsFR[i][j]; } } delete fakeratetree; } -void PlotValidation::PlotDuplicateRate(){ +void PlotValidation::PlotDuplicateRate() +{ // Get tree TTree * efftree = (TTree*)fInRoot->Get("efftree"); @@ -453,7 +371,6 @@ void PlotValidation::PlotDuplicateRate(){ subdir->cd(); //Declare strings for branches and plots - Bool_t zeroSupLin = true; TStrVec vars = {"pt","eta","phi"}; TStrVec svars = {"p_{T}","#eta","#phi"}; // svars --> labels for histograms for given variable TStrVec sunits= {" [GeV/c]","",""}; // units --> labels for histograms for given variable @@ -470,32 +387,17 @@ void PlotValidation::PlotDuplicateRate(){ IntVec nTkMatches_trk(trks.size()); // need to know how many duplicates each mc track produces. nDupl == 1 means one reco track // Create DR plots - TH1FRefVecVec varsNumerPlot(vars.size()); - TH1FRefVecVec varsDenomPlot(vars.size()); - TH1FRefVecVec varsDRPlot(vars.size()); - for (UInt_t i = 0; i < vars.size(); i++) - { - varsNumerPlot[i].resize(trks.size()); - varsDenomPlot[i].resize(trks.size()); - varsDRPlot[i].resize(trks.size()); - } - + TEffRefVecVec varsDR(vars.size()); for (UInt_t i = 0; i < vars.size(); i++) { + varsDR[i].resize(trks.size()); for (UInt_t j = 0; j < trks.size(); j++) { - // Numerator - varsNumerPlot[i][j] = new TH1F(Form("h_sim_%s_numer_%s_DR",vars[i].Data(),trks[j].Data()),Form("%s Track vs MC %s (Numer) DR",strks[j].Data(),svars[i].Data()),nBins[i],xlow[i],xhigh[i]); - varsNumerPlot[i][j]->GetXaxis()->SetTitle(Form("%s%s",svars[i].Data(),sunits[i].Data())); - varsNumerPlot[i][j]->GetYaxis()->SetTitle("nTracks"); - // Denominator - varsDenomPlot[i][j] = new TH1F(Form("h_sim_%s_denom_%s_DR",vars[i].Data(),trks[j].Data()),Form("%s Track vs MC %s (Denom) DR",strks[j].Data(),svars[i].Data()),nBins[i],xlow[i],xhigh[i]); - varsDenomPlot[i][j]->GetXaxis()->SetTitle(Form("%s%s",svars[i].Data(),sunits[i].Data())); - varsDenomPlot[i][j]->GetYaxis()->SetTitle("nTracks"); // Duplicate Rate - varsDRPlot[i][j] = new TH1F(Form("h_sim_%s_DR_%s_DR",vars[i].Data(),trks[j].Data()),Form("%s Track Duplicate Rate vs MC %s",strks[j].Data(),svars[i].Data()),nBins[i],xlow[i],xhigh[i]); - varsDRPlot[i][j]->GetXaxis()->SetTitle(Form("%s%s",svars[i].Data(),sunits[i].Data())); - varsDRPlot[i][j]->GetYaxis()->SetTitle("Duplicate Rate"); + varsDR[i][j] = new TEfficiency(Form("dr_sim_%s_%s",vars[i].Data(),trks[j].Data()), + Form("%s Track Duplicate Rate vs MC %s;%s%s;Duplicate Rate", + strks[j].Data(),svars[i].Data(),svars[i].Data(),sunits[i].Data()), + nBins[i],xlow[i],xhigh[i]); } } @@ -527,13 +429,15 @@ void PlotValidation::PlotDuplicateRate(){ { for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index { - if (mcmask_trk[j] == 1) + if (mcmask_trk[j] == 1) // need to be matched at least once { - varsDenomPlot[i][j]->Fill(mcvars_val[i]); - for (Int_t n = 0; n < nTkMatches_trk[j]; n++) - { - varsNumerPlot[i][j]->Fill(mcvars_val[i]); - } // fill n times sim track is matched. filled once is one sim to one reco. filled twice is two reco to one sim + // KM: At the moment, no support for TEfficiency to create weight numerator and NOT denominator + // fill n-1 times sim track is matched. e.g. numer not filled if one sim to one reco, numer filled once if two reco to one sim, etc. + // varsDR[i][j]->SetUseWeightedEvents(); + // varsDR[i][j]->FillWeighted(nTkMatches_trk[j]>1,nTkMatches_trk[j],mcvars_val[i]); + + // KM: As a result, DR is simply if a sim track is duplicated once, and not how many times it is duplicated + varsDR[i][j]->Fill(nTkMatches_trk[j]>1,mcvars_val[i]); } // must be a matched track for proper denom } // end loop over trks } // end loop over vars @@ -544,13 +448,8 @@ void PlotValidation::PlotDuplicateRate(){ { for (UInt_t j = 0; j < trks.size(); j++) { - PlotValidation::ComputeRatioPlot(varsNumerPlot[i][j],varsDenomPlot[i][j],varsDRPlot[i][j],true); - PlotValidation::WriteTH1FPlot(subdir,varsNumerPlot[i][j]); - PlotValidation::WriteTH1FPlot(subdir,varsDenomPlot[i][j]); - PlotValidation::DrawWriteSaveTH1FPlot(subdir,varsDRPlot[i][j],subdirname,Form("%s_DR_%s",vars[i].Data(),trks[j].Data()),zeroSupLin); - delete varsNumerPlot[i][j]; - delete varsDenomPlot[i][j]; - delete varsDRPlot[i][j]; + PlotValidation::DrawWriteSaveTEffPlot(subdir,varsDR[i][j],subdirname,Form("fr_%s_%s",vars[i].Data(),trks[j].Data())); + delete varsDR[i][j]; } } delete efftree; @@ -570,7 +469,6 @@ void PlotValidation::PlotNHits() subdir->cd(); //Declare strings for branches and plots - Bool_t zeroSupLin = false; TStrVec trks = {"seed","build","fit"}; TStrVec strks = {"Seed","Build","Fit"}; // strk --> labels for histograms for given track type TStrVec coll = {"allreco","fake","allmatch","bestmatch"}; @@ -676,8 +574,8 @@ void PlotValidation::PlotNHits() { for (UInt_t c = 0; c < coll.size(); c++) // loop over trk collection type { - PlotValidation::DrawWriteSaveTH1FPlot(subdir,nHitsPlot[j][c],subdirname,Form("nHits_%s_%s",coll[c].Data(),trks[j].Data()),zeroSupLin); - PlotValidation::DrawWriteSaveTH1FPlot(subdir,fracHitsMatchedPlot[j][c],subdirname,Form("fracHitsMatched_%s_%s",coll[c].Data(),trks[j].Data()),zeroSupLin); + PlotValidation::DrawWriteSaveTH1FPlot(subdir,nHitsPlot[j][c],subdirname,Form("nHits_%s_%s",coll[c].Data(),trks[j].Data())); + PlotValidation::DrawWriteSaveTH1FPlot(subdir,fracHitsMatchedPlot[j][c],subdirname,Form("fracHitsMatched_%s_%s",coll[c].Data(),trks[j].Data())); delete nHitsPlot[j][c]; delete fracHitsMatchedPlot[j][c]; @@ -789,7 +687,8 @@ void PlotValidation::PlotMomResolutionPull() { for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index { - if (mcmask_trk[j] == 1){ // must be associated + if (mcmask_trk[j] == 1) // must be associated + { PlotValidation::ComputeResolutionPull(mcvars_val[i][j],recovars_val[i][j],recovars_err[i][j],vars_out); if (!isnan(vars_out[0])) // fill if not nan { @@ -825,27 +724,20 @@ void PlotValidation::PrintTotals() TStrVec trks = {"seed","build","fit"}; TStrVec strks = {"Seed","Build","Fit"}; - TStrVec rates = {"EFF","FR","DR"}; + TStrVec rates = {"eff","fr","dr"}; TStrVec srates = {"Efficiency","Fake Rate","Duplicate Rate"}; TStrVec rateSD = {"efficiency","fakerate","duplicaterate"}; - TStrVec snumer = {"Sim Tracks Matched","Unmatched Reco Tracks","n Times Sim Tracks Matched"}; - TStrVec sdenom = {"All Sim Tracks","All Reco Tracks","All Sim Tracks"}; + TStrVec snumer = {"Sim Tracks Matched","Unmatched Reco Tracks","Sim Tracks Matched (nTimes>1)"}; + TStrVec sdenom = {"Eligible Sim Tracks","Eligible Reco Tracks","Eligible Sim Tracks"}; TStrVec types = {"sim","reco","sim"}; // types will be same size as rates! - TH1FRefVecVec numerPhiPlot(trks.size()); - TH1FRefVecVec denomPhiPlot(trks.size()); - for (UInt_t j = 0; j < trks.size(); j++) - { - numerPhiPlot[j].resize(rates.size()); - denomPhiPlot[j].resize(rates.size()); - } - + TEffRefVecVec phiRate(trks.size()); for (UInt_t j = 0; j < trks.size(); j++) { + phiRate[j].resize(rates.size()); for (UInt_t r = 0; r < rates.size(); r++) { - numerPhiPlot[j][r] = (TH1F*) fOutRoot->Get(Form("%s/h_%s_phi_numer_%s_%s",rateSD[r].Data(),types[r].Data(),trks[j].Data(),rates[r].Data())); - denomPhiPlot[j][r] = (TH1F*) fOutRoot->Get(Form("%s/h_%s_phi_denom_%s_%s",rateSD[r].Data(),types[r].Data(),trks[j].Data(),rates[r].Data())); + phiRate[j][r] = (TEfficiency*) fOutRoot->Get(Form("%s/%s_%s_phi_%s",rateSD[r].Data(),rates[r].Data(),types[r].Data(),trks[j].Data())); } } @@ -874,22 +766,18 @@ void PlotValidation::PrintTotals() totalsout.open(Form("%s/totals_%s.txt",fOutName.Data(),fOutName.Data())); TTree * configtree = (TTree*)fInRoot->Get("configtree"); - Int_t Ntracks = 0, Nevents = 0, nEtaPart = 0, nPhiPart = 0; + Int_t Ntracks = 0, Nevents = 0; configtree->SetBranchAddress("Nevents",&Nevents); configtree->SetBranchAddress("Ntracks",&Ntracks); - configtree->SetBranchAddress("nEtaPart",&nEtaPart); - configtree->SetBranchAddress("nPhiPart",&nPhiPart); configtree->GetEntry(0); std::cout << "--------Track Reconstruction Summary--------" << std::endl; std::cout << "nEvents: " << Nevents << " nTracks/evt: " << Ntracks << std::endl; - std::cout << "nEtaPart: " << nEtaPart << " nPhiPart: " << nPhiPart << std::endl; std::cout << "++++++++++++++++++++++++++++++++++++++++++++" << std::endl; std::cout << std::endl; totalsout << "--------Track Reconstruction Summary--------" << std::endl; totalsout << "nEvents: " << Nevents << " nTracks/evt: " << Ntracks << std::endl; - totalsout << "nEtaPart: " << nEtaPart << " nPhiPart: " << nPhiPart << std::endl; totalsout << "++++++++++++++++++++++++++++++++++++++++++++" << std::endl; totalsout << std::endl; @@ -906,16 +794,20 @@ void PlotValidation::PrintTotals() totalsout << "==========================================" << std::endl; for (UInt_t c = 0; c < coll.size(); c++) { - Float_t nHits_mean = nHitsPlot[j][c]->GetMean(1); // 1 is mean of x-axis - Float_t fracHits_mean = fracHitsMatchedPlot[j][c]->GetMean(1); + Float_t nHits_mean = nHitsPlot[j][c]->GetMean(1); // 1 is mean of x-axis + Float_t nHits_mean_unc = nHitsPlot[j][c]->GetMeanError(1); // 1 is mean of x-axis + Float_t fracHits_mean = fracHitsMatchedPlot[j][c]->GetMean(1); + Float_t fracHits_mean_unc = fracHitsMatchedPlot[j][c]->GetMeanError(1); std::cout << scoll[c].Data() << " Tracks" << std::endl; - std::cout << "Average nHits / Track: " << nHits_mean << std::endl; - std::cout << "Average shared Hits / Track: " << fracHits_mean << std::endl; + std::cout << "Mean nHits / Track = " << nHits_mean << " +/- " << nHits_mean_unc << std::endl; + std::cout << "Mean Shared Hits / Track = " << fracHits_mean << " +/- " << fracHits_mean_unc << std::endl; + std::cout << "------------------------------------------" << std::endl; totalsout << scoll[c].Data() << " Tracks" << std::endl; - totalsout << "Average nHits / Track: " << nHits_mean << std::endl; - totalsout << "Average shared Hits / Track: " << fracHits_mean << std::endl; + totalsout << "Mean nHits / Track = " << nHits_mean << " +/- " << nHits_mean_unc << std::endl; + totalsout << "Mean Shared Hits / Track = " << fracHits_mean << " +/- " << fracHits_mean_unc << std::endl; + totalsout << "------------------------------------------" << std::endl; } std::cout << std::endl << "Rates for " << strks[j].Data() << " Tracks" << std::endl; @@ -925,20 +817,19 @@ void PlotValidation::PrintTotals() totalsout << "==========================================" << std::endl; for (UInt_t r = 0; r < rates.size(); r++) { - Int_t numerIntegral = numerPhiPlot[j][r]->GetEntries(); - Int_t denomIntegral = denomPhiPlot[j][r]->GetEntries(); - Float_t ratetotal = Float_t(numerIntegral) / Float_t(denomIntegral); - - std::cout << snumer[r].Data() << ": " << numerIntegral << std::endl; - std::cout << sdenom[r].Data() << ": " << denomIntegral << std::endl; + EffStruct effs; + PlotValidation::GetTotalEfficiency(phiRate[j][r],effs); + + std::cout << snumer[r].Data() << ": " << effs.passed_ << std::endl; + std::cout << sdenom[r].Data() << ": " << effs.total_ << std::endl; std::cout << "------------------------------------------" << std::endl; - std::cout << srates[r].Data() << ": " << ratetotal << std::endl; + std::cout << srates[r].Data() << ": " << effs.eff_ << ", -" << effs.elow_ << ", +" << effs.eup_ << std::endl; std::cout << "------------------------------------------" << std::endl; - - totalsout << snumer[r].Data() << ": " << numerIntegral << std::endl; - totalsout << sdenom[r].Data() << ": " << denomIntegral << std::endl; + + totalsout << snumer[r].Data() << ": " << effs.passed_ << std::endl; + totalsout << sdenom[r].Data() << ": " << effs.total_ << std::endl; totalsout << "------------------------------------------" << std::endl; - totalsout << srates[r].Data() << ": " << ratetotal << std::endl; + totalsout << srates[r].Data() << ": " << effs.eff_ << ", -" << effs.elow_ << ", +" << effs.eup_ << std::endl; totalsout << "------------------------------------------" << std::endl; } std::cout << std::endl << std::endl; @@ -949,7 +840,8 @@ void PlotValidation::PrintTotals() delete configtree; } -void PlotValidation::MakeSubDirectory(const TString subdirname){ +void PlotValidation::MakeSubDirectory(const TString subdirname) +{ FileStat_t dummyFileStat; if (gSystem->GetPathInfo(Form("%s/%s",fOutName.Data(), subdirname.Data()), dummyFileStat) == 1) { @@ -972,96 +864,61 @@ void PlotValidation::ComputeResolutionPull(const Float_t mcvar_val, const Float_ var_out[1] = (recovar_val - mcvar_val)/recovar_err; } -void PlotValidation::ZeroSuppressPlot(TH1F *& hist) +void PlotValidation::GetTotalEfficiency(const TEfficiency * eff, EffStruct & effs) { - Float_t max = hist->GetBinContent(hist->GetMaximumBin()); - Float_t min = 100; - Bool_t newmin = false; - - for (Int_t bin = 1; bin <= hist->GetNbinsX(); bin++) - { - Float_t tmpmin = hist->GetBinContent(bin); - if ((tmpmin < min) && (tmpmin > 0)) - { - min = tmpmin; - newmin = true; - } - } + effs.passed_ = eff->GetPassedHistogram()->GetEntries(); + effs.total_ = eff->GetTotalHistogram()->GetEntries(); - hist->SetMaximum(1.02*max); - if (newmin) - { - hist->SetMinimum(0.98*min); - } -} + TEfficiency * tmp_eff = new TEfficiency("tmp_eff","tmp_eff",1,0,1); + tmp_eff->SetTotalEvents(1,effs.total_); + tmp_eff->SetPassedEvents(1,effs.passed_); -void PlotValidation::ComputeRatioPlot(const TH1F * numer, const TH1F * denom, TH1F *& ratioPlot, Bool_t subone) -{ - Double_t value = 0; - Double_t err = 0; - for (Int_t bin = 1; bin <= ratioPlot->GetNbinsX(); bin++) - { - if (denom->GetBinContent(bin)!=0) - { - value = numer->GetBinContent(bin) / denom->GetBinContent(bin); // currently implement same method for FR and Eff (minimize mask calls) - - if (subone) value -= 1.0; - - // Binonimal errors for both - err = sqrt( value*(1.0-value)/denom->GetBinContent(bin) ); + effs.eff_ = tmp_eff->GetEfficiency(1); + effs.elow_ = tmp_eff->GetEfficiencyErrorLow(1); + effs.eup_ = tmp_eff->GetEfficiencyErrorUp(1); - //Fill plots with correct values - ratioPlot->SetBinContent(bin,value); - ratioPlot->SetBinError(bin,err); - } - } + delete tmp_eff; } -void PlotValidation::WriteTH2FPlot(TDirectory *& subdir, TH2F *& hist) +void PlotValidation::DrawWriteSaveTEffPlot(TDirectory *& subdir, TEfficiency *& eff, const TString subdirname, const TString plotName) { subdir->cd(); - hist->Write(); -} + eff->Write(); -void PlotValidation::DrawWriteSaveTH2FPlot(TDirectory *& subdir, TH2F *& hist, const TString subdirname, const TString plotName) -{ - fTH2Canv->cd(); - hist->Draw("colz"); - subdir->cd(); - hist->Write(); - if (fSaveAs) fTH2Canv->SaveAs(Form("%s/%s/%s.png",fOutName.Data(),subdirname.Data(),plotName.Data())); + fTEffCanv->cd(); + eff->Draw("AP"); + + // first save log + fTEffCanv->SetLogy(1); + if (fSaveAs) fTEffCanv->SaveAs(Form("%s/%s/log/%s.%s",fOutName.Data(),subdirname.Data(),plotName.Data(),fOutType.Data())); + + fTEffCanv->SetLogy(0); + if (fSaveAs) fTEffCanv->SaveAs(Form("%s/%s/lin/%s.%s",fOutName.Data(),subdirname.Data(),plotName.Data(),fOutType.Data())); } -void PlotValidation::WriteTH1FPlot(TDirectory *& subdir, TH1F *& hist) +void PlotValidation::DrawWriteSaveTH1FPlot(TDirectory *& subdir, TH1F *& hist, const TString subdirname, const TString plotName) { subdir->cd(); hist->Write(); -} -void PlotValidation::DrawWriteSaveTH1FPlot(TDirectory *& subdir, TH1F *& hist, const TString subdirname, const TString plotName, const Bool_t zeroSupLin) -{ fTH1Canv->cd(); hist->Draw(); - subdir->cd(); - hist->Write(); - + // first save log fTH1Canv->SetLogy(1); if (fSaveAs) fTH1Canv->SaveAs(Form("%s/%s/log/%s.%s",fOutName.Data(),subdirname.Data(),plotName.Data(),fOutType.Data())); - // second save linear (check to zero suppress) - if (zeroSupLin) PlotValidation::ZeroSuppressPlot(hist); - fTH1Canv->SetLogy(0); if (fSaveAs) fTH1Canv->SaveAs(Form("%s/%s/lin/%s.%s",fOutName.Data(),subdirname.Data(),plotName.Data(),fOutType.Data())); } void PlotValidation::DrawWriteFitSaveTH1FPlot(TDirectory *& subdir, TH1F *& hist, const TString subdirname, const TString plotName, const Float_t fitRange) // separate method for fitting pulls/res, do not want gaus line in root file { - fTH1Canv->cd(); - hist->Draw(); subdir->cd(); hist->Write(); + + fTH1Canv->cd(); + hist->Draw(); hist->Fit("gaus","","",-fitRange,fitRange); // first save log diff --git a/PlotValidation.hh b/PlotValidation.hh index 865174e2d4042..66f1f40c190f6 100644 --- a/PlotValidation.hh +++ b/PlotValidation.hh @@ -1,4 +1,5 @@ #include "TFile.h" +#include "TEfficiency.h" #include "TH1F.h" #include "TString.h" #include "TTree.h" @@ -6,7 +7,6 @@ #include "TROOT.h" #include "TSystem.h" #include "TStyle.h" -#include "TH2F.h" #include "TDirectory.h" #include "TColor.h" @@ -31,8 +31,22 @@ typedef std::vector TH1FRefVec; typedef std::vector TH1FRefVecVec; typedef std::vector TH1FRefVecVecVec; +typedef std::vector TEffRefVec; +typedef std::vector TEffRefVecVec; +typedef std::vector TEffRefVecVecVec; + typedef std::vector TStrVec; +struct EffStruct +{ + Float_t passed_; + Float_t total_; + + Float_t eff_; + Float_t elow_; + Float_t eup_; +}; + class PlotValidation { public: @@ -55,15 +69,10 @@ public: void ComputeResidual (const Float_t mcvar_val, const Float_t recovar_val, Float_t & var_out); void ComputeResolutionPull(const Float_t mcvar_val, const Float_t recovar_val, const Float_t recovar_err, FltVec & var_out); - void ComputeRatioPlot(const TH1F * numer, const TH1F * denom, TH1F *& ratioPlot, Bool_t subone = false); - - void ZeroSuppressPlot(TH1F *& histo); - - void WriteTH2FPlot (TDirectory *& subdir, TH2F *& hist); - void DrawWriteSaveTH2FPlot(TDirectory *& subdir, TH2F *& histo, const TString subdirname, const TString plotName); - - void WriteTH1FPlot (TDirectory *& subdir, TH1F *& histo); - void DrawWriteSaveTH1FPlot (TDirectory *& subdir, TH1F *& histo, const TString subdirname, const TString plotName, const Bool_t zeroSupLin); + void GetTotalEfficiency(const TEfficiency * eff, EffStruct & effs); + + void DrawWriteSaveTEffPlot (TDirectory *& subdir, TEfficiency *& eff, const TString subdirname, const TString plotName); + void DrawWriteSaveTH1FPlot (TDirectory *& subdir, TH1F *& histo, const TString subdirname, const TString plotName); void DrawWriteFitSaveTH1FPlot(TDirectory *& subdir, TH1F *& histo, const TString subdirname, const TString plotName, const Float_t fitrange); void MoveInput(); @@ -76,11 +85,10 @@ private: TString fOutType; TString fOutName; TFile * fOutRoot; + TCanvas * fTEffCanv; TCanvas * fTH1Canv; - TCanvas * fTH2Canv; // color base std::vector fColors; UInt_t fColorSize; - }; diff --git a/makeValidation.C b/makeValidation.C index 5f35845320df2..401ca8b84cfb3 100644 --- a/makeValidation.C +++ b/makeValidation.C @@ -2,7 +2,8 @@ #include "TSystem.h" #include "TStyle.h" #include "TFile.h" -#include "TH1F.h" +#include "TEfficiency.h" +#include "TGraphAsymmErrors.h" #include "TCanvas.h" #include "TLegend.h" @@ -29,11 +30,11 @@ void makeValidation(TString label = "") sORr.push_back("reco"); sORr.push_back("sim"); std::vector rates; - rates.push_back("EFF"); - rates.push_back("INEFF_barrel"); - rates.push_back("INEFF_endcap"); - rates.push_back("FR"); - rates.push_back("DR"); + rates.push_back("eff"); + rates.push_back("ineff_barrel"); + rates.push_back("ineff_endcap"); + rates.push_back("fr"); + rates.push_back("dr"); std::vector vars; vars.push_back("pt"); vars.push_back("phi"); @@ -46,36 +47,36 @@ void makeValidation(TString label = "") TCanvas * canv = new TCanvas(); canv->cd(); - TH1F * h_bh = (TH1F*)f_bh ->Get(Form("%s/h_%s_%s_%s_build_%s",dirs[i].Data(),sORr[i].Data(),vars[j].Data(),rates[i].Data(),rates[i].Data())); - TH1F * h_std = (TH1F*)f_std->Get(Form("%s/h_%s_%s_%s_build_%s",dirs[i].Data(),sORr[i].Data(),vars[j].Data(),rates[i].Data(),rates[i].Data())); - TH1F * h_ce = (TH1F*)f_ce ->Get(Form("%s/h_%s_%s_%s_build_%s",dirs[i].Data(),sORr[i].Data(),vars[j].Data(),rates[i].Data(),rates[i].Data())); + TGraphAsymmErrors * g_bh = ((TEfficiency*)f_bh ->Get(Form("%s/%s_%s_%s_build",dirs[i].Data(),rates[i].Data(),sORr[i].Data(),vars[j].Data())))->CreateGraph(); + TGraphAsymmErrors * g_std = ((TEfficiency*)f_std->Get(Form("%s/%s_%s_%s_build",dirs[i].Data(),rates[i].Data(),sORr[i].Data(),vars[j].Data())))->CreateGraph(); + TGraphAsymmErrors * g_ce = ((TEfficiency*)f_ce ->Get(Form("%s/%s_%s_%s_build",dirs[i].Data(),rates[i].Data(),sORr[i].Data(),vars[j].Data())))->CreateGraph(); - h_bh ->SetLineColor(kBlue); - h_std->SetLineColor(kGreen+1); - h_ce ->SetLineColor(kRed); - h_bh ->SetMarkerColor(kBlue); - h_std->SetMarkerColor(kGreen+1); - h_ce ->SetMarkerColor(kRed); + g_bh ->SetLineColor(kBlue); + g_std->SetLineColor(kGreen+1); + g_ce ->SetLineColor(kRed); + g_bh ->SetMarkerColor(kBlue); + g_std->SetMarkerColor(kGreen+1); + g_ce ->SetMarkerColor(kRed); - if (!rates[i].Contains("INEFF",TString::kExact)) h_bh->GetYaxis()->SetRangeUser(0.0,1.05); - else h_bh->GetYaxis()->SetRangeUser(0.0,0.1); + if (!rates[i].Contains("ineff",TString::kExact)) g_bh->GetYaxis()->SetRangeUser(0.0,1.05); + else g_bh->GetYaxis()->SetRangeUser(0.0,0.1); - h_bh ->Draw("lep"); - h_std->Draw("lep same"); - h_ce ->Draw("lep same"); + g_bh ->Draw("APZ"); + g_std->Draw("PZ same"); + g_ce ->Draw("PZ same"); TLegend * leg = new TLegend(0.85,0.80,1.0,1.0); - leg->AddEntry(h_bh,"Best Hit","LEP"); - leg->AddEntry(h_std,"Standard","LEP"); - leg->AddEntry(h_ce,"Clone Engine","LEP"); + leg->AddEntry(g_bh,"Best Hit","LEP"); + leg->AddEntry(g_std,"Standard","LEP"); + leg->AddEntry(g_ce,"Clone Engine","LEP"); leg->Draw("same"); canv->SaveAs(Form("%s_%s_%s.png",label.Data(),rates[i].Data(),vars[j].Data())); delete leg; - delete h_ce; - delete h_std; - delete h_bh; + delete g_ce; + delete g_std; + delete g_bh; delete canv; } } From e22b6d028ab6e07c21f59bef6407a39c9ff29b49 Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Thu, 25 May 2017 10:32:16 -0700 Subject: [PATCH 059/172] ToyMC validation uses 400 events * 2.5k tracks/event for full detector --- PlotValidation.cpp | 9 ++++++++- generateToyMCsamples.sh | 8 ++++---- runBenchmark.sh | 6 +++--- validation-snb-toymc-barrel-build.sh | 22 ---------------------- validation-snb-toymc-fulldet-build.sh | 21 +++++++++++++++++++++ 5 files changed, 36 insertions(+), 30 deletions(-) delete mode 100755 validation-snb-toymc-barrel-build.sh create mode 100755 validation-snb-toymc-fulldet-build.sh diff --git a/PlotValidation.cpp b/PlotValidation.cpp index ddd908ccdbb6f..d335583b87a71 100644 --- a/PlotValidation.cpp +++ b/PlotValidation.cpp @@ -63,12 +63,19 @@ PlotValidation::~PlotValidation() void PlotValidation::Validation() { - PlotValidation::PlotEfficiency(); + std::cout << "Computing Efficiency ..." << std::endl; + PlotValidation::PlotEfficiency(); + std::cout << "Computing Inefficiency split in barrel and endcap..." << std::endl; PlotValidation::PlotInefficiencyVsGeom(); + std::cout << "Computing Fake Rate ..." << std::endl; PlotValidation::PlotFakeRate(); + std::cout << "Computing Duplicate Rate ..." << std::endl; PlotValidation::PlotDuplicateRate(); + std::cout << "Computing ..." << std::endl; PlotValidation::PlotNHits(); + std::cout << "Computing Momentum Pulls ..." << std::endl; PlotValidation::PlotMomResolutionPull(); + std::cout << "Printing Totals ..." << std::endl; PlotValidation::PrintTotals(); if (fMvInput) { diff --git a/generateToyMCsamples.sh b/generateToyMCsamples.sh index 8832b3047008b..21a1d21e075e9 100755 --- a/generateToyMCsamples.sh +++ b/generateToyMCsamples.sh @@ -30,11 +30,11 @@ make clean make -j 12 # Validation tests: Barrel -if [ ! -f ${dir}/simtracks_barrel_10x10k_val.bin ]; then - echo "++++Generating 10k tracks/event * 10 events for ToyMC barrel-only validation tests++++" +if [ ! -f ${dir}/simtracks_fulldet_400x2p5k_val.bin ]; then + echo "++++Generating 2.5k tracks/event * 400 events for ToyMC barrel-only validation tests++++" sed -i 's/#WITH_ROOT := yes/WITH_ROOT := yes/g' Makefile.config - ./mkFit/mkFit --num-thr-sim 1 --root-val --num-events 10 --num-tracks 10000 --write --file-name simtracks_barrel_10x10k_val.bin - mv simtracks_barrel_10x10k_val.bin ${dir}/ + ./mkFit/mkFit --num-thr-sim 12 --root-val --num-events 400 --num-tracks 2500 --write --file-name simtracks_fulldet_400x2p5k_val.bin + mv simtracks_fulldet_400x2p5k_val.bin ${dir}/ sed -i 's/WITH_ROOT := yes/#WITH_ROOT := yes/g' Makefile.config fi diff --git a/runBenchmark.sh b/runBenchmark.sh index 4196f98ade80f..15669d662eb1c 100755 --- a/runBenchmark.sh +++ b/runBenchmark.sh @@ -70,10 +70,10 @@ for test in BH STD CE; do done ##### Validation tests ##### -./validation-snb-toymc-barrel-build.sh +./validation-snb-toymc-fulldet-build.sh for test in BH STD CE; do - root -b -q -l runValidation.C\(\"_SNB_ToyMC_Barrel_${test}\"\) + root -b -q -l runValidation.C\(\"_SNB_ToyMC_FullDet_${test}\"\) done -root -b -q -l makeValidation.C\(\"SNB_ToyMC_Barrel\"\) +root -b -q -l makeValidation.C\(\"SNB_ToyMC_FullDet\"\) make distclean diff --git a/validation-snb-toymc-barrel-build.sh b/validation-snb-toymc-barrel-build.sh deleted file mode 100755 index 609a2745f4745..0000000000000 --- a/validation-snb-toymc-barrel-build.sh +++ /dev/null @@ -1,22 +0,0 @@ -#! /bin/bash - -sed -i 's/#WITH_ROOT := yes/WITH_ROOT := yes/g' Makefile.config - -make -j 12 - -dir=/data/nfsmic/${TOYMCUSER:-kmcdermo}/toymc - -echo "SNB ToyMC BH (Barrel): validation [nTH:24, nVU:8]" -./mkFit/mkFit --root-val --read --file-name ${dir}/simtracks_barrel_10x10k_val.bin --build-bh --num-thr 24 >& log_SNB_ToyMC_Barrel_BH_NVU8int_NTH24_val.txt -mv valtree.root valtree_SNB_ToyMC_Barrel_BH.root -echo "SNB ToyMC STD (Barrel): validation [nTH:24, nVU:8]" -./mkFit/mkFit --root-val --read --file-name ${dir}/simtracks_barrel_10x10k_val.bin --build-std --num-thr 24 >& log_SNB_ToyMC_Barrel_STD_NVU8int_NTH24_val.txt -mv valtree.root valtree_SNB_ToyMC_Barrel_STD.root -echo "SNB ToyMC CE (Barrel): validation [nTH:24, nVU:8]" -./mkFit/mkFit --root-val --read --file-name ${dir}/simtracks_barrel_10x10k_val.bin --build-ce --num-thr 24 >& log_SNB_ToyMC_Barrel_CE_NVU8int_NTH24_val.txt -mv valtree.root valtree_SNB_ToyMC_Barrel_CE.root - -sed -i 's/WITH_ROOT := yes/#WITH_ROOT := yes/g' Makefile.config - -make clean - diff --git a/validation-snb-toymc-fulldet-build.sh b/validation-snb-toymc-fulldet-build.sh new file mode 100755 index 0000000000000..8e6174e4b47d8 --- /dev/null +++ b/validation-snb-toymc-fulldet-build.sh @@ -0,0 +1,21 @@ +#! /bin/bash + +sed -i 's/#WITH_ROOT := yes/WITH_ROOT := yes/g' Makefile.config + +make -j 12 + +dir=/data/nfsmic/${TOYMCUSER:-kmcdermo}/toymc + +echo "SNB ToyMC BH (FullDet): validation [nTH:24, nVU:8]" +./mkFit/mkFit --root-val --read --file-name ${dir}/simtracks_fulldet_400x2p5k_val.bin --build-bh --num-thr 24 >& log_SNB_ToyMC_FullDet_BH_NVU8int_NTH24_val.txt +mv valtree.root valtree_SNB_ToyMC_FullDet_BH.root +echo "SNB ToyMC STD (FullDet): validation [nTH:24, nVU:8]" +./mkFit/mkFit --root-val --read --file-name ${dir}/simtracks_fulldet_400x2p5k_val.bin --build-std --num-thr 24 >& log_SNB_ToyMC_FullDet_STD_NVU8int_NTH24_val.txt +mv valtree.root valtree_SNB_ToyMC_FullDet_STD.root +echo "SNB ToyMC CE (FullDet): validation [nTH:24, nVU:8]" +./mkFit/mkFit --root-val --read --file-name ${dir}/simtracks_fulldet_400x2p5k_val.bin --build-ce --num-thr 24 >& log_SNB_ToyMC_FullDet_CE_NVU8int_NTH24_val.txt +mv valtree.root valtree_SNB_ToyMC_FullDet_CE.root + +sed -i 's/WITH_ROOT := yes/#WITH_ROOT := yes/g' Makefile.config + +make clean From 3402bc39c5f5e70635cdef59906cf4d35ba828e4 Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Fri, 26 May 2017 16:53:44 -0700 Subject: [PATCH 060/172] CMS tracking in endcaps 1. CMS endcap tracking only works with clone engine. 2. Width of Track hit index is a bit too low for endcap, especially since we are also adding hole hits (index -3). After the limit is reached, new hits are no longer added. The above two things are my first priorities for next week. --- Config.cc | 12 +- Config.h | 9 +- Event.cc | 121 +++++++++++++++-- Event.h | 10 +- Geoms/CMS-2017.acc | 112 +++++++++------- Geoms/CMS-2017.cc | 5 +- Geoms/CMS/make_trk_info.C | 115 +++++++++++----- Geoms/CylCowWLids.cc | 5 +- Simulation.cc | 2 +- Track.cc | 39 ++++-- Track.h | 44 ++++--- TrackerInfo.cc | 15 ++- TrackerInfo.h | 16 ++- mkFit/HitStructures.h | 2 + mkFit/MkBuilder.cc | 267 ++++++++++++++++++++++---------------- mkFit/MkBuilder.h | 1 + mkFit/MkFitter.cc | 51 ++------ mkFit/MkFitter.h | 9 +- mkFit/buildtestMPlex.cc | 4 +- mkFit/mt-notes.txt | 7 + 20 files changed, 535 insertions(+), 311 deletions(-) diff --git a/Config.cc b/Config.cc index 8cf23f241ef67..12b234c01dee0 100644 --- a/Config.cc +++ b/Config.cc @@ -9,11 +9,14 @@ namespace Config int nTracks = 10000; int nEvents = 20; + int nTotalLayers = -1; + std::string geomPlugin = "CylCowWLids"; - // Dependent constants, assigned after processing of commandline options - int maxHitsPerBunch; - int maxCandsPerEtaBin; + int maxCandsPerSeed = 6; // cmssw tests: 6 (GC had 3) \_ set from geom plugin + int maxHolesPerCand = 2; // cmssw tests: 12 / + + int maxCandsPerEtaBin; // Recalculated after config is read ... should be removed. // Multi threading and Clone engine configuration int numThreadsFinder = 1; @@ -30,7 +33,7 @@ namespace Config int finderReportBestOutOfN = 1; - int nlayers_per_seed = 3; // default is 3 for barrel seeding --> will need a new variable once we move to endcap seeding + int nlayers_per_seed = 3; // can be overriden from Geom plugin; a very confusing variable :) int numSeedsPerTask = 32; // number of hits per task for finding seeds @@ -60,6 +63,5 @@ namespace Config void RecalculateDependentConstants() { maxCandsPerEtaBin = std::max(100, maxCandsPerSeed * (nTracks+100) / nEtaPart); - maxHitsPerBunch = std::max(100, nTracks * 12 / 10 / nEtaPart) + maxHitsConsidered; } } diff --git a/Config.h b/Config.h index f7d78033e6c4b..4c7613cc4bea8 100644 --- a/Config.h +++ b/Config.h @@ -48,7 +48,7 @@ namespace Config // namespace, too. // XXXX This needs to be generalized for other geometries ! // TrackerInfo more or less has all this information (or could have it). - constexpr int nTotalLayers = 28; + extern int nTotalLayers; // To be set by geometry plugin. constexpr int nMaxSimHits = 28; // Assuming dual hit on every barrel / endcap edge constexpr int nMaxRecHits = 10; // Assuming single hit on each layer constexpr int nMaxTrkHits = nMaxSimHits; // Used for array sizes in MkFitter and Track @@ -152,7 +152,7 @@ namespace Config //const float xr = std::sqrt(Config::beamspotX*Config::beamspotX + Config::beamspotY*Config::beamspotY); // Config for seeding - extern int nlayers_per_seed; + extern int nlayers_per_seed; // default: 3, cms sets from geom plugin constexpr int nlayers_per_seed_max = 4; // Needed for allocation of arrays on stack. constexpr float chi2seedcut = 9.0; constexpr float lay01angdiff = 0.0634888; // analytically derived... depends on geometry of detector --> from mathematica ... d0 set to one sigma of getHypot(bsX,bsY) @@ -219,10 +219,9 @@ namespace Config //fixme: these should not be constant and modified when nTracks is set from reading a file constexpr int maxHitsConsidered = 25; - extern int maxHitsPerBunch; - constexpr int maxCandsPerSeed = 6; //default: 6; cmssw tests: 3 - constexpr int maxHolesPerCand = 2; + extern int maxCandsPerSeed; // default: 6; cms: 6 (GC had 3) + extern int maxHolesPerCand; // default: 2; cms 12 (should be reduced) extern int maxCandsPerEtaBin; // config on validation diff --git a/Event.cc b/Event.cc index 94b0f82f83855..43702e91f15f0 100644 --- a/Event.cc +++ b/Event.cc @@ -472,11 +472,18 @@ void Event::read_in(FILE *fp, int version) if (Config::useCMSGeom || Config::readCmsswSeeds) { int ns; fread(&ns, sizeof(int), 1, fp); - seedTracks_.resize(ns); - if (Config::readCmsswSeeds) fread(&seedTracks_[0], sizeof(Track), ns, fp); - else fseek(fp, sizeof(Track)*ns, SEEK_CUR); + if (Config::readCmsswSeeds) + { + seedTracks_.resize(ns); + fread(&seedTracks_[0], sizeof(Track), ns, fp); + } + else + { + fseek(fp, sizeof(Track)*ns, SEEK_CUR); + ns = -ns; + } #ifdef DUMP_SEEDS - printf("Read %i seedtracks\n", ns); + printf("Read %i seedtracks (neg value means actual reading was skipped)\n", ns); for (int it = 0; it < ns; it++) { printf(" q=%+i pT=%6.3f nHits=%i label=% i\n",seedTracks_[it].charge(),seedTracks_[it].pT(),seedTracks_[it].nFoundHits(),seedTracks_[it].label()); @@ -486,8 +493,12 @@ void Event::read_in(FILE *fp, int version) int lyr = seedTracks_[it].getHitLyr(ih); int idx = seedTracks_[it].getHitIdx(ih); if (idx >= 0) - printf(" hit %2d lyr=%d idx=%i pos r=%5.3f z=%6.3f\n", - ih, lyr, idx, layerHits_[lyr][idx].r(), layerHits_[lyr][idx].z()); + { + const Hit &hit = layerHits_[lyr][idx]; + printf(" hit %2d lyr=%3d idx=%4d pos r=%7.3f z=% 8.3f mc_hit=%3d mc_trk=%3d\n", + ih, lyr, idx, layerHits_[lyr][idx].r(), layerHits_[lyr][idx].z(), + hit.mcHitID(), hit.mcTrackID(simHitsInfo_)); + } else printf(" hit %2d idx=%i\n",ih,seedTracks_[it].getHitIdx(ih)); @@ -501,17 +512,23 @@ void Event::read_in(FILE *fp, int version) #ifdef DUMP_TRACKS for (int it = 0; it < nt; it++) { - printf(" %i with q=%+i pT=%5.3f eta=%6.3f nHits=%i\n",it,simTracks_[it].charge(),simTracks_[it].pT(),simTracks_[it].momEta(),simTracks_[it].nFoundHits()); + const Track &t = simTracks_[it]; + printf(" %i with q=%+i pT=%7.3f eta=% 7.3f nHits=%2d label=%4d\n", + it, t.charge(), t.pT(), t.momEta(), t.nFoundHits(), t.label()); #ifdef DUMP_TRACK_HITS - for (int ih = 0; ih < simTracks_[it].nTotalHits(); ++ih) + for (int ih = 0; ih < t.nTotalHits(); ++ih) { - int lyr = simTracks_[it].getHitLyr(ih); - int idx = simTracks_[it].getHitIdx(ih); + int lyr = t.getHitLyr(ih); + int idx = t.getHitIdx(ih); if (idx >= 0) - printf(" hit %2d lyr=%d idx=%i pos r=%5.3f z=%6.3f\n", - ih, lyr, idx, layerHits_[lyr][idx].r(), layerHits_[lyr][idx].z()); + { + const Hit &hit = layerHits_[lyr][idx]; + printf(" hit %2d lyr=%2d idx=%3d pos r=%7.3f z=% 8.3f mc_hit=%3d mc_trk=%3d\n", + ih, lyr, idx, layerHits_[lyr][idx].r(), layerHits_[lyr][idx].z(), + hit.mcHitID(), hit.mcTrackID(simHitsInfo_)); + } else - printf(" hit %2d idx=%i\n",ih,simTracks_[it].getHitIdx(ih)); + printf(" hit %2d idx=%i\n", ih, t.getHitIdx(ih)); } #endif } @@ -527,10 +544,86 @@ void Event::read_in(FILE *fp, int version) total_hits += layerHits_[il].size(); for (int ih = 0; ih < layerHits_[il].size(); ih++) { - printf(" hit with mcHitID=%i r=%5.3f x=%5.3f y=%5.3f z=%5.3f\n",layerHits_[il][ih].mcHitID(),layerHits_[il][ih].r(),layerHits_[il][ih].x(),layerHits_[il][ih].y(),layerHits_[il][ih].z()); + printf(" hit with mcHitID=%i r=%5.3f x=%5.3f y=%5.3f z=%5.3f\n", + layerHits_[il][ih].mcHitID(), layerHits_[il][ih].r(), + layerHits_[il][ih].x(),layerHits_[il][ih].y(),layerHits_[il][ih].z()); } } printf("Total hits in all layers = %d\n", total_hits); #endif printf("Read event done\n"); } + +void Event::clean_cms_simtracks() +{ + // Sim tracks from cmssw have the following issues: + // - hits are not sorted by layer; + // - there are tracks with too low number of hits, even 0. + + TrackVec orig; + simTracks_.swap(orig); + int osize = orig.size(); + simTracks_.reserve(orig.size()); + + for (int i = 0; i < osize; ++i) + { + Track &src = orig[i]; + const int nh = src.nFoundHits(); + if (nh < Config::nlayers_per_seed) + { + dprintf("Dropping simtrack %d, nhits=%d\n", i, nh); + continue; + } + dprintf("Accepting simtrack %d, nhits=%d\n", i, nh); + + // initialize original index locations + std::vector idx(nh); + std::iota(idx.begin(), idx.end(), 0); + + // sort indexes based on comparing values in v + std::sort(idx.begin(), idx.end(), + [&](int i1, int i2) { return src.getHitLyr(i1) < src.getHitLyr(i2); }); + // XXXX plus secondary sort by radius; + + simTracks_.emplace_back( Track(src.state(), 0, src.label(), 0, nullptr) ); + Track &dst = simTracks_.back(); + + for (int h = 0; h < nh; ++h) + { + // XXXX Should also check if it's the same layer as before? + dprintf(" adding hit %d which was %d, layer %d\n", h, idx[h], src.getHitLyr(idx[h])); + dst.addHitIdx(src.getHitOnTrack(idx[h]), 0.0f); + } + } +} + +void Event::print_tracks(const TrackVec& tracks, bool print_hits) const +{ + const int nt = tracks.size(); + + printf("Event::print_tracks printing %d tracks %s hits:\n", nt, (print_hits ? "with" : "without")); + for (int it = 0; it < nt; it++) + { + const Track &t = tracks[it]; + printf(" %i with q=%+i pT=%7.3f eta=% 7.3f nHits=%2d label=%4d\n", + it, t.charge(), t.pT(), t.momEta(), t.nFoundHits(), t.label()); + + if (print_hits) + { + for (int ih = 0; ih < t.nTotalHits(); ++ih) + { + int lyr = t.getHitLyr(ih); + int idx = t.getHitIdx(ih); + if (idx >= 0) + { + const Hit &hit = layerHits_[lyr][idx]; + printf(" hit %2d lyr=%2d idx=%3d pos r=%7.3f z=% 8.3f mc_hit=%3d mc_trk=%3d\n", + ih, lyr, idx, layerHits_[lyr][idx].r(), layerHits_[lyr][idx].z(), + hit.mcHitID(), hit.mcTrackID(simHitsInfo_)); + } + else + printf(" hit %2d idx=%i\n", ih, t.getHitIdx(ih)); + } + } + } +} diff --git a/Event.h b/Event.h index 60d7b4887a53b..79206bf43ea9a 100644 --- a/Event.h +++ b/Event.h @@ -23,7 +23,7 @@ class Event void Validate(); void PrintStats(const TrackVec&, TrackExtraVec&); - int evtID() const {return evtID_;} + int evtID() const {return evtID_;} void resetLayerHitMap(bool resetSimHits); int nextMCHitID() { return mcHitIDCounter_++; } @@ -31,6 +31,9 @@ class Event void write_out(FILE *fp); void read_in(FILE *fp, int version = Config::FileVersion); + void clean_cms_simtracks(); + void print_tracks(const TrackVec& tracks, bool print_hits) const; + const Geometry& geom_; Validation& validation_; @@ -48,9 +51,10 @@ class Event // validation sets these, so needs to be mutable mutable TrackExtraVec simTracksExtra_, seedTracksExtra_, candidateTracksExtra_, fitTracksExtra_; - // XXXXMT: Preliminary ... separators into seed/candidate arrays. - // There should be a better way of doing that. + // XXXXMT: Preliminary. Separators into seed/candidate arrays. + // This will have to be extended for multi-pass tracking. int seedEtaSeparators_[5]; + int seedMinLastLayer_[5]; TSVec simTrackStates_; static std::mutex printmutex; diff --git a/Geoms/CMS-2017.acc b/Geoms/CMS-2017.acc index 4b2935ca8450f..b33ac7a46cbd6 100644 --- a/Geoms/CMS-2017.acc +++ b/Geoms/CMS-2017.acc @@ -224,7 +224,7 @@ void Create_CMS_2017_AutoGen(TrackerInfo& ti) li.m_layer_type = LayerInfo::EndCapNeg; li.set_limits(4.590, 16.090, -35.200, -29.440); li.m_propagate_to = li.z_mean(); - li.set_next_layers(4, 46, -1); + li.set_next_layers(4, -1, 46); li.m_is_outer = false; li.m_q_bin = 1.000; li.set_selection_limits(0.01, 0.05, 0.8, 1.6); @@ -244,7 +244,7 @@ void Create_CMS_2017_AutoGen(TrackerInfo& ti) li.m_layer_type = LayerInfo::EndCapNeg; li.set_limits(4.590, 16.090, -42.700, -36.940); li.m_propagate_to = li.z_mean(); - li.set_next_layers(4, 47, -1); + li.set_next_layers(4, -1, 47); li.m_is_outer = false; li.m_q_bin = 1.000; li.set_selection_limits(0.01, 0.05, 0.8, 1.6); @@ -264,7 +264,7 @@ void Create_CMS_2017_AutoGen(TrackerInfo& ti) li.m_layer_type = LayerInfo::EndCapNeg; li.set_limits(4.590, 16.090, -52.210, -46.450); li.m_propagate_to = li.z_mean(); - li.set_next_layers(4, 48, -1); + li.set_next_layers(4, -1, 48); li.m_is_outer = false; li.m_q_bin = 1.000; li.set_selection_limits(0.01, 0.05, 0.8, 1.6); @@ -287,7 +287,7 @@ void Create_CMS_2017_AutoGen(TrackerInfo& ti) li.m_layer_type = LayerInfo::EndCapNeg; li.set_limits(22.980, 50.440, -84.050, -74.350); li.m_propagate_to = li.z_mean(); - li.set_next_layers(10, 49, -1); + li.set_next_layers(10, -1, 49); li.m_is_outer = false; li.m_q_bin = 20.000; li.set_selection_limits(0.01, 0.2, 10.0, 20.0); @@ -295,7 +295,7 @@ void Create_CMS_2017_AutoGen(TrackerInfo& ti) { LayerInfo & li = ti.m_layers[22]; li.m_layer_type = LayerInfo::EndCapPos; - li.set_limits(22.980, 50.440, 74.350, 84.050); + li.set_limits(22.800, 42.000, 74.350, 84.050); li.m_propagate_to = li.z_mean(); li.set_next_layers(10, 23, -1); li.m_is_outer = false; @@ -305,9 +305,9 @@ void Create_CMS_2017_AutoGen(TrackerInfo& ti) { LayerInfo & li = ti.m_layers[49]; li.m_layer_type = LayerInfo::EndCapNeg; - li.set_limits(22.980, 50.440, -84.050, -74.350); + li.set_limits(22.800, 42.000, -84.050, -74.350); li.m_propagate_to = li.z_mean(); - li.set_next_layers(10, 50, -1); + li.set_next_layers(10, -1, 50); li.m_is_outer = false; li.m_q_bin = 20.000; li.set_selection_limits(0.01, 0.2, 10.0, 20.0); @@ -327,7 +327,7 @@ void Create_CMS_2017_AutoGen(TrackerInfo& ti) li.m_layer_type = LayerInfo::EndCapNeg; li.set_limits(22.980, 50.440, -97.000, -87.300); li.m_propagate_to = li.z_mean(); - li.set_next_layers(10, 51, -1); + li.set_next_layers(10, -1, 51); li.m_is_outer = false; li.m_q_bin = 20.000; li.set_selection_limits(0.01, 0.2, 10.0, 20.0); @@ -335,7 +335,7 @@ void Create_CMS_2017_AutoGen(TrackerInfo& ti) { LayerInfo & li = ti.m_layers[24]; li.m_layer_type = LayerInfo::EndCapPos; - li.set_limits(22.980, 50.440, 87.300, 97.000); + li.set_limits(22.800, 42.000, 87.300, 97.000); li.m_propagate_to = li.z_mean(); li.set_next_layers(10, 25, -1); li.m_is_outer = false; @@ -345,9 +345,9 @@ void Create_CMS_2017_AutoGen(TrackerInfo& ti) { LayerInfo & li = ti.m_layers[51]; li.m_layer_type = LayerInfo::EndCapNeg; - li.set_limits(22.980, 50.440, -97.000, -87.300); + li.set_limits(22.800, 42.000, -97.000, -87.300); li.m_propagate_to = li.z_mean(); - li.set_next_layers(10, 52, -1); + li.set_next_layers(10, -1, 52); li.m_is_outer = false; li.m_q_bin = 20.000; li.set_selection_limits(0.01, 0.2, 10.0, 20.0); @@ -367,7 +367,7 @@ void Create_CMS_2017_AutoGen(TrackerInfo& ti) li.m_layer_type = LayerInfo::EndCapNeg; li.set_limits(22.980, 50.440, -109.950, -100.250); li.m_propagate_to = li.z_mean(); - li.set_next_layers(10, 53, -1); + li.set_next_layers(10, -1, 53); li.m_is_outer = false; li.m_q_bin = 20.000; li.set_selection_limits(0.01, 0.2, 10.0, 20.0); @@ -375,7 +375,7 @@ void Create_CMS_2017_AutoGen(TrackerInfo& ti) { LayerInfo & li = ti.m_layers[26]; li.m_layer_type = LayerInfo::EndCapPos; - li.set_limits(22.980, 50.440, 100.250, 109.950); + li.set_limits(22.800, 42.000, 100.250, 109.950); li.m_propagate_to = li.z_mean(); li.set_next_layers(10, 27, -1); li.m_is_outer = false; @@ -385,9 +385,9 @@ void Create_CMS_2017_AutoGen(TrackerInfo& ti) { LayerInfo & li = ti.m_layers[53]; li.m_layer_type = LayerInfo::EndCapNeg; - li.set_limits(22.980, 50.440, -109.950, -100.250); + li.set_limits(22.800, 42.000, -109.950, -100.250); li.m_propagate_to = li.z_mean(); - li.set_next_layers(10, 54, -1); + li.set_next_layers(10, -1, 54); li.m_is_outer = false; li.m_q_bin = 20.000; li.set_selection_limits(0.01, 0.2, 10.0, 20.0); @@ -410,7 +410,7 @@ void Create_CMS_2017_AutoGen(TrackerInfo& ti) li.m_layer_type = LayerInfo::EndCapNeg; li.set_limits(23.360, 109.400, -137.390, -126.380); li.m_propagate_to = li.z_mean(); - li.set_next_layers(-1, 55, -1); + li.set_next_layers(-1, -1, 55); li.m_is_outer = false; li.m_q_bin = 20.000; li.set_selection_limits(0.01, 0.2, 10.0, 20.0); @@ -418,22 +418,24 @@ void Create_CMS_2017_AutoGen(TrackerInfo& ti) { LayerInfo & li = ti.m_layers[28]; li.m_layer_type = LayerInfo::EndCapPos; - li.set_limits(23.370, 109.390, 126.380, 137.390); + li.set_limits(23.300, 76.100, 126.380, 137.390); li.m_propagate_to = li.z_mean(); li.set_next_layers(-1, 29, -1); li.m_is_outer = false; li.m_q_bin = 20.000; li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + li.set_r_hole_range(42.000, 59.900); } { LayerInfo & li = ti.m_layers[55]; li.m_layer_type = LayerInfo::EndCapNeg; - li.set_limits(23.360, 109.400, -137.390, -126.380); + li.set_limits(23.300, 76.100, -137.390, -126.380); li.m_propagate_to = li.z_mean(); - li.set_next_layers(-1, 56, -1); + li.set_next_layers(-1, -1, 56); li.m_is_outer = false; li.m_q_bin = 20.000; li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + li.set_r_hole_range(42.000, 59.900); } { LayerInfo & li = ti.m_layers[29]; @@ -450,7 +452,7 @@ void Create_CMS_2017_AutoGen(TrackerInfo& ti) li.m_layer_type = LayerInfo::EndCapNeg; li.set_limits(23.360, 109.390, -151.420, -140.380); li.m_propagate_to = li.z_mean(); - li.set_next_layers(-1, 57, -1); + li.set_next_layers(-1, -1, 57); li.m_is_outer = false; li.m_q_bin = 20.000; li.set_selection_limits(0.01, 0.2, 10.0, 20.0); @@ -458,22 +460,24 @@ void Create_CMS_2017_AutoGen(TrackerInfo& ti) { LayerInfo & li = ti.m_layers[30]; li.m_layer_type = LayerInfo::EndCapPos; - li.set_limits(23.360, 109.410, 140.380, 151.390); + li.set_limits(23.300, 76.100, 140.380, 151.390); li.m_propagate_to = li.z_mean(); li.set_next_layers(-1, 31, -1); li.m_is_outer = false; li.m_q_bin = 20.000; li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + li.set_r_hole_range(42.000, 59.900); } { LayerInfo & li = ti.m_layers[57]; li.m_layer_type = LayerInfo::EndCapNeg; - li.set_limits(23.360, 109.390, -151.420, -140.380); + li.set_limits(23.300, 76.100, -151.420, -140.380); li.m_propagate_to = li.z_mean(); - li.set_next_layers(-1, 58, -1); + li.set_next_layers(-1, -1, 58); li.m_is_outer = false; li.m_q_bin = 20.000; li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + li.set_r_hole_range(42.000, 59.900); } { LayerInfo & li = ti.m_layers[31]; @@ -490,7 +494,7 @@ void Create_CMS_2017_AutoGen(TrackerInfo& ti) li.m_layer_type = LayerInfo::EndCapNeg; li.set_limits(23.360, 109.390, -165.390, -154.380); li.m_propagate_to = li.z_mean(); - li.set_next_layers(-1, 59, -1); + li.set_next_layers(-1, -1, 59); li.m_is_outer = false; li.m_q_bin = 20.000; li.set_selection_limits(0.01, 0.2, 10.0, 20.0); @@ -498,22 +502,24 @@ void Create_CMS_2017_AutoGen(TrackerInfo& ti) { LayerInfo & li = ti.m_layers[32]; li.m_layer_type = LayerInfo::EndCapPos; - li.set_limits(23.360, 109.390, 154.380, 165.390); + li.set_limits(23.300, 76.100, 154.380, 165.390); li.m_propagate_to = li.z_mean(); li.set_next_layers(-1, 33, -1); li.m_is_outer = false; li.m_q_bin = 20.000; li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + li.set_r_hole_range(42.000, 59.900); } { LayerInfo & li = ti.m_layers[59]; li.m_layer_type = LayerInfo::EndCapNeg; - li.set_limits(23.360, 109.390, -165.390, -154.380); + li.set_limits(23.300, 76.100, -165.390, -154.380); li.m_propagate_to = li.z_mean(); - li.set_next_layers(-1, 60, -1); + li.set_next_layers(-1, -1, 60); li.m_is_outer = false; li.m_q_bin = 20.000; li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + li.set_r_hole_range(42.000, 59.900); } { LayerInfo & li = ti.m_layers[33]; @@ -530,7 +536,7 @@ void Create_CMS_2017_AutoGen(TrackerInfo& ti) li.m_layer_type = LayerInfo::EndCapNeg; li.set_limits(32.110, 109.390, -179.390, -168.380); li.m_propagate_to = li.z_mean(); - li.set_next_layers(-1, 61, -1); + li.set_next_layers(-1, -1, 61); li.m_is_outer = false; li.m_q_bin = 20.000; li.set_selection_limits(0.01, 0.2, 10.0, 20.0); @@ -538,22 +544,24 @@ void Create_CMS_2017_AutoGen(TrackerInfo& ti) { LayerInfo & li = ti.m_layers[34]; li.m_layer_type = LayerInfo::EndCapPos; - li.set_limits(32.110, 109.400, 168.380, 179.380); + li.set_limits(31.600, 75.900, 168.380, 179.380); li.m_propagate_to = li.z_mean(); li.set_next_layers(-1, 35, -1); li.m_is_outer = false; li.m_q_bin = 20.000; li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + li.set_r_hole_range(42.100, 59.700); } { LayerInfo & li = ti.m_layers[61]; li.m_layer_type = LayerInfo::EndCapNeg; - li.set_limits(32.110, 109.390, -179.390, -168.380); + li.set_limits(31.600, 75.900, -179.390, -168.380); li.m_propagate_to = li.z_mean(); - li.set_next_layers(-1, 62, -1); + li.set_next_layers(-1, -1, 62); li.m_is_outer = false; li.m_q_bin = 20.000; li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + li.set_r_hole_range(42.100, 59.700); } { LayerInfo & li = ti.m_layers[35]; @@ -570,7 +578,7 @@ void Create_CMS_2017_AutoGen(TrackerInfo& ti) li.m_layer_type = LayerInfo::EndCapNeg; li.set_limits(32.110, 109.390, -193.380, -182.380); li.m_propagate_to = li.z_mean(); - li.set_next_layers(-1, 63, -1); + li.set_next_layers(-1, -1, 63); li.m_is_outer = false; li.m_q_bin = 20.000; li.set_selection_limits(0.01, 0.2, 10.0, 20.0); @@ -578,22 +586,24 @@ void Create_CMS_2017_AutoGen(TrackerInfo& ti) { LayerInfo & li = ti.m_layers[36]; li.m_layer_type = LayerInfo::EndCapPos; - li.set_limits(32.110, 109.390, 182.370, 193.390); + li.set_limits(31.600, 75.900, 182.370, 193.390); li.m_propagate_to = li.z_mean(); li.set_next_layers(-1, 37, -1); li.m_is_outer = false; li.m_q_bin = 20.000; li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + li.set_r_hole_range(42.100, 59.700); } { LayerInfo & li = ti.m_layers[63]; li.m_layer_type = LayerInfo::EndCapNeg; - li.set_limits(32.110, 109.390, -193.380, -182.380); + li.set_limits(31.600, 75.900, -193.380, -182.380); li.m_propagate_to = li.z_mean(); - li.set_next_layers(-1, 64, -1); + li.set_next_layers(-1, -1, 64); li.m_is_outer = false; li.m_q_bin = 20.000; li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + li.set_r_hole_range(42.100, 59.700); } { LayerInfo & li = ti.m_layers[37]; @@ -610,7 +620,7 @@ void Create_CMS_2017_AutoGen(TrackerInfo& ti) li.m_layer_type = LayerInfo::EndCapNeg; li.set_limits(32.110, 109.390, -210.880, -199.870); li.m_propagate_to = li.z_mean(); - li.set_next_layers(-1, 65, -1); + li.set_next_layers(-1, -1, 65); li.m_is_outer = false; li.m_q_bin = 20.000; li.set_selection_limits(0.01, 0.2, 10.0, 20.0); @@ -618,22 +628,24 @@ void Create_CMS_2017_AutoGen(TrackerInfo& ti) { LayerInfo & li = ti.m_layers[38]; li.m_layer_type = LayerInfo::EndCapPos; - li.set_limits(32.110, 109.390, 199.870, 210.880); + li.set_limits(31.600, 75.900, 199.870, 210.880); li.m_propagate_to = li.z_mean(); li.set_next_layers(-1, 39, -1); li.m_is_outer = false; li.m_q_bin = 20.000; li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + li.set_r_hole_range(42.100, 59.700); } { LayerInfo & li = ti.m_layers[65]; li.m_layer_type = LayerInfo::EndCapNeg; - li.set_limits(32.110, 109.390, -210.880, -199.870); + li.set_limits(31.600, 75.900, -210.880, -199.870); li.m_propagate_to = li.z_mean(); - li.set_next_layers(-1, 66, -1); + li.set_next_layers(-1, -1, 66); li.m_is_outer = false; li.m_q_bin = 20.000; li.set_selection_limits(0.01, 0.2, 10.0, 20.0); + li.set_r_hole_range(42.100, 59.700); } { LayerInfo & li = ti.m_layers[39]; @@ -650,7 +662,7 @@ void Create_CMS_2017_AutoGen(TrackerInfo& ti) li.m_layer_type = LayerInfo::EndCapNeg; li.set_limits(39.200, 109.390, -229.860, -218.870); li.m_propagate_to = li.z_mean(); - li.set_next_layers(-1, 67, -1); + li.set_next_layers(-1, -1, 67); li.m_is_outer = false; li.m_q_bin = 20.000; li.set_selection_limits(0.01, 0.2, 10.0, 20.0); @@ -658,7 +670,7 @@ void Create_CMS_2017_AutoGen(TrackerInfo& ti) { LayerInfo & li = ti.m_layers[40]; li.m_layer_type = LayerInfo::EndCapPos; - li.set_limits(39.200, 109.390, 218.870, 229.860); + li.set_limits(59.900, 75.900, 218.870, 229.860); li.m_propagate_to = li.z_mean(); li.set_next_layers(-1, 41, -1); li.m_is_outer = false; @@ -668,9 +680,9 @@ void Create_CMS_2017_AutoGen(TrackerInfo& ti) { LayerInfo & li = ti.m_layers[67]; li.m_layer_type = LayerInfo::EndCapNeg; - li.set_limits(39.200, 109.390, -229.860, -218.870); + li.set_limits(59.900, 75.900, -229.860, -218.870); li.m_propagate_to = li.z_mean(); - li.set_next_layers(-1, 68, -1); + li.set_next_layers(-1, -1, 68); li.m_is_outer = false; li.m_q_bin = 20.000; li.set_selection_limits(0.01, 0.2, 10.0, 20.0); @@ -690,7 +702,7 @@ void Create_CMS_2017_AutoGen(TrackerInfo& ti) li.m_layer_type = LayerInfo::EndCapNeg; li.set_limits(39.200, 109.400, -250.360, -239.370); li.m_propagate_to = li.z_mean(); - li.set_next_layers(-1, 69, -1); + li.set_next_layers(-1, -1, 69); li.m_is_outer = false; li.m_q_bin = 20.000; li.set_selection_limits(0.01, 0.2, 10.0, 20.0); @@ -698,7 +710,7 @@ void Create_CMS_2017_AutoGen(TrackerInfo& ti) { LayerInfo & li = ti.m_layers[42]; li.m_layer_type = LayerInfo::EndCapPos; - li.set_limits(39.200, 109.400, 239.370, 250.360); + li.set_limits(59.900, 75.900, 239.370, 250.360); li.m_propagate_to = li.z_mean(); li.set_next_layers(-1, 43, -1); li.m_is_outer = false; @@ -708,9 +720,9 @@ void Create_CMS_2017_AutoGen(TrackerInfo& ti) { LayerInfo & li = ti.m_layers[69]; li.m_layer_type = LayerInfo::EndCapNeg; - li.set_limits(39.200, 109.400, -250.360, -239.370); + li.set_limits(59.900, 75.900, -250.360, -239.370); li.m_propagate_to = li.z_mean(); - li.set_next_layers(-1, 70, -1); + li.set_next_layers(-1, -1, 70); li.m_is_outer = false; li.m_q_bin = 20.000; li.set_selection_limits(0.01, 0.2, 10.0, 20.0); @@ -730,7 +742,7 @@ void Create_CMS_2017_AutoGen(TrackerInfo& ti) li.m_layer_type = LayerInfo::EndCapNeg; li.set_limits(50.410, 109.390, -271.880, -260.870); li.m_propagate_to = li.z_mean(); - li.set_next_layers(-1, 71, -1); + li.set_next_layers(-1, -1, 71); li.m_is_outer = false; li.m_q_bin = 20.000; li.set_selection_limits(0.01, 0.2, 10.0, 20.0); @@ -738,7 +750,7 @@ void Create_CMS_2017_AutoGen(TrackerInfo& ti) { LayerInfo & li = ti.m_layers[44]; li.m_layer_type = LayerInfo::EndCapPos; - li.set_limits(50.410, 109.400, 260.870, 271.870); + li.set_limits(59.900, 75.900, 260.870, 271.870); li.m_propagate_to = li.z_mean(); li.set_next_layers(-1, -1, -1); li.m_is_outer = true; @@ -748,7 +760,7 @@ void Create_CMS_2017_AutoGen(TrackerInfo& ti) { LayerInfo & li = ti.m_layers[71]; li.m_layer_type = LayerInfo::EndCapNeg; - li.set_limits(50.410, 109.390, -271.880, -260.870); + li.set_limits(59.900, 75.900, -271.880, -260.870); li.m_propagate_to = li.z_mean(); li.set_next_layers(-1, -1, -1); li.m_is_outer = true; diff --git a/Geoms/CMS-2017.cc b/Geoms/CMS-2017.cc index c86fae73198ed..1caf6e3f920d7 100644 --- a/Geoms/CMS-2017.cc +++ b/Geoms/CMS-2017.cc @@ -11,11 +11,14 @@ namespace void Create_CMS_2017(TrackerInfo& ti, bool verbose) { + Config::nTotalLayers = 18 + 2 * 27; Config::useCMSGeom = true; Config::nlayers_per_seed = 4; + Config::maxCandsPerSeed = 6; // GC said 3 is enough ??? + Config::maxHolesPerCand = 12; // should be reduced Config::chi2Cut = 30.0; - ti.set_eta_regions(0.9, 1.7, 2.45); + ti.set_eta_regions(0.9, 1.7, 2.45, false); ti.create_layers(18, 27, 27); Create_CMS_2017_AutoGen(ti); diff --git a/Geoms/CMS/make_trk_info.C b/Geoms/CMS/make_trk_info.C index daf4fae9a9adc..47c3091183eff 100644 --- a/Geoms/CMS/make_trk_info.C +++ b/Geoms/CMS/make_trk_info.C @@ -4,7 +4,7 @@ */ /* - Some "leftovers" of CMSSW from Config.h + Some "leftovers" of CMSSW from Config.h. For 2016 layout! constexpr float cmsAvgRads[13] = {4.42,7.31,10.17,25.58,33.98,41.79,49.78,60.78,69.2,77.96,86.80,96.53,108.00}; // cms average radii, noSplit version constexpr float cmsAvgRads[17] = {4.42, 7.31, 10.17, @@ -23,6 +23,22 @@ const float g_layer_dz[] = { 1, 1, 1, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20 }; */ + +// For TID and TEC only: +constexpr float cmsDiskMinRs[24] = {23.1,22.8,23.1,22.8,23.1,22.8, 23.3, 23.0, 23.3, 23.0, 23.3, 23.0, 31.6, 34.4, 31.6, 34.4, 31.6, 34.4, 59.9, 38.8, 59.9, 38.8, 59.9, 49.9}; +constexpr float cmsDiskMaxRs[24] = {50.8,42.0,50.8,42.0,50.8,42.0, 76.1,110.0, 76.1,110.0, 76.1,110.0, 75.9,109.7, 75.9,109.7, 75.9,109.7, 75.9,109.4, 75.9,109.4, 75.9,109.4}; +constexpr float cmsDiskMinRsHole[24] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 42.0, 0.0, 42.0, 0.0, 42.0, 0.0, 42.1, 0.0, 42.1, 0.0, 42.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; +constexpr float cmsDiskMaxRsHole[24] = {999.,999.,999.,999.,999.,999., 59.9, 999., 59.9, 999., 59.9, 999., 59.7, 999., 59.7, 999., 59.7, 999., 999., 999., 999., 999., 999., 999.}; +// 1. Note -- TEC stereo has index pefore the correcponding mono / full sub-layer! +// 2. For TID we only reduce the stereo layer R limits. +// 3. For TEC we also store the hole extent. +// 4. Other disks limits are taken from the tracking ntuple bounding boxes. +// It should be possible to make this automatic. + +constexpr int N_barrel = 18; +constexpr int N_endcap = 27; +constexpr int N_pix_endcap = 3; + #include "tncdefs.h" #include @@ -70,20 +86,38 @@ void add_barrel(int &lid, int det, int lay, bool is_pix, ++lid; } -void add_ecap(int &lid, int det, int lay, bool is_pix, - int nbrl) +void add_ecap(int &lid, int det, int lay, bool is_pix, bool stereo_hack, + int next_brl) { int lid_store = lid; - + + bool hole_hack = false; + int shi = -1; + if (stereo_hack) + { + shi = lid - N_barrel - N_pix_endcap; + if (shi > 5) + { + shi = shi - 1; // TEC order reversed in Giuseppe's map! + if (shi < 18) // No holes on last three layers + { + hole_hack = true; + } + } + } + SCOPE_BEG; { RZBox b = BBB.p[det][lay].Round(100); + float min_r = stereo_hack ? cmsDiskMinRs[shi] : b.m_minr; + float max_r = stereo_hack ? cmsDiskMaxRs[shi] : b.m_maxr; + PRN("LayerInfo & li = ti.m_layers[%d];", lid); PRN("li.m_layer_type = LayerInfo::EndCapPos;"); - PRN("li.set_limits(%.3f, %.3f, %.3f, %.3f);", b.m_minr, b.m_maxr, b.m_minz, b.m_maxz); + PRN("li.set_limits(%.3f, %.3f, %.3f, %.3f);", min_r, max_r, b.m_minz, b.m_maxz); PRN("li.m_propagate_to = li.z_mean();"); - PRN("li.set_next_layers(%d, %d, %d);", nbrl, lid < 44 ? lid + 1 : -1, -1); + PRN("li.set_next_layers(%d, %d, %d);", next_brl, lid < 44 ? lid + 1 : -1, -1); ASSB(m_is_outer, lid == 44); if (is_pix) { ASSF(m_q_bin, 1.0); @@ -92,18 +126,24 @@ void add_ecap(int &lid, int det, int lay, bool is_pix, ASSF(m_q_bin, 20.0); PRN("li.set_selection_limits(0.01, 0.2, 10.0, 20.0);"); } + if (hole_hack) { + PRN("li.set_r_hole_range(%.3f, %.3f);", cmsDiskMinRsHole[shi], cmsDiskMaxRsHole[shi]); + } } SCOPE_END; SCOPE_BEG; { - lid += 27; + lid += N_endcap; RZBox b = BBB.n[det][lay].Round(100); + float min_r = stereo_hack ? cmsDiskMinRs[shi] : b.m_minr; + float max_r = stereo_hack ? cmsDiskMaxRs[shi] : b.m_maxr; + PRN("LayerInfo & li = ti.m_layers[%d];", lid); PRN("li.m_layer_type = LayerInfo::EndCapNeg;"); - PRN("li.set_limits(%.3f, %.3f, %.3f, %.3f);", b.m_minr, b.m_maxr, b.m_minz, b.m_maxz); + PRN("li.set_limits(%.3f, %.3f, %.3f, %.3f);", min_r, max_r, b.m_minz, b.m_maxz); PRN("li.m_propagate_to = li.z_mean();"); - PRN("li.set_next_layers(%d, %d, %d);", nbrl, lid < 71 ? lid + 1 : -1, -1); + PRN("li.set_next_layers(%d, %d, %d);", next_brl, -1, lid < 71 ? lid + 1 : -1); ASSB(m_is_outer, lid == 71); if (is_pix) { ASSF(m_q_bin, 1.0); @@ -112,6 +152,9 @@ void add_ecap(int &lid, int det, int lay, bool is_pix, ASSF(m_q_bin, 20.0); PRN("li.set_selection_limits(0.01, 0.2, 10.0, 20.0);"); } + if (hole_hack) { + PRN("li.set_r_hole_range(%.3f, %.3f);", cmsDiskMinRsHole[shi], cmsDiskMaxRsHole[shi]); + } } SCOPE_END; @@ -156,39 +199,39 @@ void print_trk_info() NLN; PRN("// PIXE +/-\n"); - add_ecap(lid, 2, 1, true, 4); - add_ecap(lid, 2, 2, true, 4); - add_ecap(lid, 2, 3, true, 4); + add_ecap(lid, 2, 1, true, false, 4); + add_ecap(lid, 2, 2, true, false, 4); + add_ecap(lid, 2, 3, true, false, 4); NLN; PRN("// TID +/-\n"); - add_ecap(lid, 4, 1, false, 10); - add_ecap(lid, 4, 1, false, 10); - add_ecap(lid, 4, 2, false, 10); - add_ecap(lid, 4, 2, false, 10); - add_ecap(lid, 4, 3, false, 10); - add_ecap(lid, 4, 3, false, 10); + add_ecap(lid, 4, 1, false, false, 10); + add_ecap(lid, 4, 1, false, true, 10); + add_ecap(lid, 4, 2, false, false, 10); + add_ecap(lid, 4, 2, false, true, 10); + add_ecap(lid, 4, 3, false, false, 10); + add_ecap(lid, 4, 3, false, true, 10); NLN; PRN("// TID +/-\n"); - add_ecap(lid, 6, 1, false, -1); - add_ecap(lid, 6, 1, false, -1); - add_ecap(lid, 6, 2, false, -1); - add_ecap(lid, 6, 2, false, -1); - add_ecap(lid, 6, 3, false, -1); - add_ecap(lid, 6, 3, false, -1); - add_ecap(lid, 6, 4, false, -1); - add_ecap(lid, 6, 4, false, -1); - add_ecap(lid, 6, 5, false, -1); - add_ecap(lid, 6, 5, false, -1); - add_ecap(lid, 6, 6, false, -1); - add_ecap(lid, 6, 6, false, -1); - add_ecap(lid, 6, 7, false, -1); - add_ecap(lid, 6, 7, false, -1); - add_ecap(lid, 6, 8, false, -1); - add_ecap(lid, 6, 8, false, -1); - add_ecap(lid, 6, 9, false, -1); - add_ecap(lid, 6, 9, false, -1); + add_ecap(lid, 6, 1, false, false, -1); + add_ecap(lid, 6, 1, false, true, -1); + add_ecap(lid, 6, 2, false, false, -1); + add_ecap(lid, 6, 2, false, true, -1); + add_ecap(lid, 6, 3, false, false, -1); + add_ecap(lid, 6, 3, false, true, -1); + add_ecap(lid, 6, 4, false, false, -1); + add_ecap(lid, 6, 4, false, true, -1); + add_ecap(lid, 6, 5, false, false, -1); + add_ecap(lid, 6, 5, false, true, -1); + add_ecap(lid, 6, 6, false, false, -1); + add_ecap(lid, 6, 6, false, true, -1); + add_ecap(lid, 6, 7, false, false, -1); + add_ecap(lid, 6, 7, false, true, -1); + add_ecap(lid, 6, 8, false, false, -1); + add_ecap(lid, 6, 8, false, true, -1); + add_ecap(lid, 6, 9, false, false, -1); + add_ecap(lid, 6, 9, false, true, -1); NLN; SCOPE_END; diff --git a/Geoms/CylCowWLids.cc b/Geoms/CylCowWLids.cc index ee5ce40e07003..bee497e9bc618 100644 --- a/Geoms/CylCowWLids.cc +++ b/Geoms/CylCowWLids.cc @@ -17,6 +17,7 @@ // // Eta partitions for B / T / EC +#include "../Config.h" #include "../TrackerInfo.h" #include @@ -158,7 +159,7 @@ namespace // XXXXXXMT: Hack smaller transition region. // Need better estimate for seeds? // m_trkinfo.set_eta_regions(1.15, 1.4, 2.4); - m_trkinfo.set_eta_regions(1.1, 1.3, 2.4); + m_trkinfo.set_eta_regions(1.1, 1.3, 2.4, true); m_trkinfo.create_layers(10, 9, 9); // Actual coverage for tracks with z = 3cm is 2.4 @@ -212,6 +213,8 @@ namespace void Create_CylCowWLids(TrackerInfo& ti, bool verbose) { + Config::nTotalLayers = 10 + 2 * 9; + CylCowWLidsCreator creator(ti); creator.FillTrackerInfo(); diff --git a/Simulation.cc b/Simulation.cc index b40ad96bad842..c27ffe7551c7a 100644 --- a/Simulation.cc +++ b/Simulation.cc @@ -76,7 +76,7 @@ void setupTrackByToyMC(SVector3& pos, SVector3& mom, SMatrixSym66& covtrk, // useful info for loopers/overlaps - int layer_counts[Config::nTotalLayers]; + std::vector layer_counts(Config::nTotalLayers); for (int ilayer = 0; ilayer < Config::nTotalLayers; ++ilayer) { layer_counts[ilayer] = 0; diff --git a/Track.cc b/Track.cc index 8a19e0a862ece..a3ac0ecb88808 100644 --- a/Track.cc +++ b/Track.cc @@ -1,4 +1,5 @@ #include "Track.h" + //#define DEBUG #include "Debug.h" @@ -131,6 +132,10 @@ void TrackExtra::setMCTrackIDInfoByLabel(const Track& trk, const std::vector for seeding or CMSSW-like building void TrackExtra::setMCTrackIDInfo(const Track& trk, const std::vector& layerHits, const MCHitInfoVec& globalHitInfo, const TrackVec& simtracks, const bool isSeed) { + bool debug = true; + + dprintf("TrackExtra::setMCTrackIDInfo for track with label %d, total hits %d, found hits %d\n", + trk.label(), trk.nTotalHits(), trk.nFoundHits()); std::vector mcTrackIDs; for (int ihit = 0; ihit < trk.nTotalHits(); ++ihit) { @@ -139,30 +144,42 @@ void TrackExtra::setMCTrackIDInfo(const Track& trk, const std::vector& l if ((hitidx >= 0) && (hitidx < layerHits[hitlyr].size())) // make sure it is a real hit { const int mchitid = layerHits[hitlyr][hitidx].mcHitID(); - dprint("trk.label()=" << trk.label() << " ihit=" << ihit - << " trk.getHitIdx(ihit)=" << hitidx << "trk.getHitLyr(ihit)" << hitlyr - << " mchitid=" << mchitid << " globalHitInfo[mchitid].mcTrackID()=" << globalHitInfo[mchitid].mcTrackID()); + dprintf(" ihit=%3d trk.hit_idx=%4d trk.hit_lyr=%2d mchitid=%4d mctrkid=%3d\n", + ihit, hitidx, hitlyr, mchitid, globalHitInfo[mchitid].mcTrackID()); mcTrackIDs.push_back(globalHitInfo[mchitid].mcTrackID()); } + else + { + dprintf(" ihit=%3d trk.hit_idx=%4d trk.hit_lyr=%2d\n", ihit, hitidx, hitlyr); + } } + int mccount = 0; if (!mcTrackIDs.empty()) // protection against zero size tracks { // sorted list ensures that mcTrackIDs are counted properly std::sort(mcTrackIDs.begin(), mcTrackIDs.end()); - int mccount = 0, tmpcount = 0; - int mcTrackID(mcTrackIDs[0]); - for (int imcTrackID : mcTrackIDs) + int mcTrackID = -5; + int n_ids = mcTrackIDs.size(); + int i = 0; + while (i < n_ids) { - if (imcTrackID == mcTrackID) { ++tmpcount; } else { tmpcount = 1; } - if (tmpcount >= mccount) { mcTrackID = imcTrackID; mccount = tmpcount; } + int j = i + 1; while (j < n_ids && mcTrackIDs[j] == mcTrackIDs[i]) ++j; + + int n = j - i; + if (mcTrackIDs[i] >= 0 && n > mccount) + { + mcTrackID = mcTrackIDs[i]; + mccount = n; + } + i = j; } // 75% matching criterion if (4*mccount >= 3*trk.nFoundHits()) - { - if (isSeed) mcTrackID_ = mcTrackID; + { + if (isSeed) mcTrackID_ = mcTrackID; else { const int nMinSimHits = simtracks[mcTrackID].nFoundHits() * Config::nMinSimHitsFrac; @@ -185,7 +202,7 @@ void TrackExtra::setMCTrackIDInfo(const Track& trk, const std::vector& l fracHitsMatched_ = 0.f; } - dprint("Track " << trk.label() << " best mc track " << mcTrackID << " count " << mccount << "/" << trk.nFoundHits()); + dprint("Track " << trk.label() << " best mc track " << mcTrackID_ << " count " << mccount << "/" << trk.nFoundHits()); } //============================================================================== diff --git a/Track.h b/Track.h index d9d6a90d3a49c..947dc92a1c419 100644 --- a/Track.h +++ b/Track.h @@ -125,10 +125,11 @@ class Track { addHitIdx(hits[h].index, hits[h].layer, 0.0f); } - for (int h = nHits; h < Config::nMaxTrkHits; ++h) - { - setHitIdxLyr(h, -1, -1); - } + // XXXXMT Trying to take this out ... HOTs beyond the end should not be used. + // for (int h = nHits; h < Config::nMaxTrkHits; ++h) + // { + // setHitIdxLyr(h, -1, -1); + // } } Track(int charge, const SVector3& position, const SVector3& momentum, const SMatrixSym66& errors, float chi2) : @@ -215,12 +216,16 @@ class Track CUDA_CALLABLE void addHitIdx(int hitIdx, int hitLyr, float chi2) { + if (hitIdxPos_ >= Config::nMaxTrkHits - 1) return; + hitsOnTrk_[++hitIdxPos_] = { hitIdx, hitLyr }; if (hitIdx >= 0) { ++nGoodHits_; chi2_+=chi2; } } void addHitIdx(const HitOnTrack &hot, float chi2) { + if (hitIdxPos_ >= Config::nMaxTrkHits - 1) return; + hitsOnTrk_[++hitIdxPos_] = hot; if (hot.index >= 0) { ++nGoodHits_; chi2_+=chi2; } } @@ -299,8 +304,8 @@ class Track CUDA_CALLABLE void resetHits() { - hitIdxPos_ = -1; - nGoodHits_ = 0; + hitIdxPos_ = -1; + nGoodHits_ = 0; } int nFoundHits() const { return nGoodHits_; } int nTotalHits() const { return hitIdxPos_+1; } @@ -342,24 +347,27 @@ class TrackExtra public: TrackExtra() : seedID_(std::numeric_limits::max()) {} TrackExtra(int seedID) : seedID_(seedID) {} - int mcTrackID() const {return mcTrackID_;} - int nHitsMatched() const {return nHitsMatched_;} - float fracHitsMatched() const {return fracHitsMatched_;} - int seedID() const {return seedID_;} - bool isDuplicate() const {return isDuplicate_;} - int duplicateID() const {return duplicateID_;} + void setMCTrackIDInfoByLabel(const Track& trk, const std::vector& layerHits, const MCHitInfoVec& globalHitInfo); void setMCTrackIDInfo(const Track& trk, const std::vector& layerHits, const MCHitInfoVec& globalHitInfo, const TrackVec& simtracks, const bool isSeed); - void setMCDuplicateInfo(int duplicateID, bool isDuplicate) {duplicateID_ = duplicateID; isDuplicate_ = isDuplicate;} + + int mcTrackID() const {return mcTrackID_;} + int nHitsMatched() const {return nHitsMatched_;} + float fracHitsMatched() const {return fracHitsMatched_;} + int seedID() const {return seedID_;} + bool isDuplicate() const {return isDuplicate_;} + int duplicateID() const {return duplicateID_;} + void setMCDuplicateInfo(int duplicateID, bool isDuplicate) {duplicateID_ = duplicateID; isDuplicate_ = isDuplicate;} private: friend class Track; - int mcTrackID_; - int nHitsMatched_; + + int mcTrackID_; + int nHitsMatched_; float fracHitsMatched_; - int seedID_; - int duplicateID_; - bool isDuplicate_; + int seedID_; + int duplicateID_; + bool isDuplicate_; }; typedef std::vector TrackExtraVec; diff --git a/TrackerInfo.cc b/TrackerInfo.cc index 61c4f04da0844..224b455415cda 100644 --- a/TrackerInfo.cc +++ b/TrackerInfo.cc @@ -19,13 +19,21 @@ void LayerInfo::set_selection_limits(float p1, float p2, float q1, float q2) m_select_min_dq = q1; m_select_max_dq = q2; } +void LayerInfo::set_r_hole_range(float rh1, float rh2) +{ + m_has_r_range_hole = true; + m_hole_r2_min = rh1 * rh1; + m_hole_r2_max = rh2 * rh2; +} + //============================================================================== -void TrackerInfo::set_eta_regions(float tr_beg, float tr_end, float ec_end) +void TrackerInfo::set_eta_regions(float tr_beg, float tr_end, float ec_end, bool has_sibl_lyrs) { m_eta_trans_beg = tr_beg; m_eta_trans_end = tr_end; - m_eta_ecap_end = ec_end; + m_eta_ecap_end = ec_end; + m_has_sibling_layers = has_sibl_lyrs; } void TrackerInfo::reserve_layers(int n_brl, int n_ec_pos, int n_ec_neg) @@ -76,6 +84,9 @@ bool TrackerInfo::are_layers_siblings(int l1, int l2) const assert(l1 < m_layers.size() && l2 < m_layers.size()); const LayerInfo &i1 = m_layers[l1]; + const LayerInfo &i2 = m_layers[l2]; + + if ( ! m_has_sibling_layers || i1.m_layer_type == i2.m_layer_type) return false; if (i1.m_layer_type == LayerInfo::Barrel) return l2 == i1.m_sibl_ecap_pos || l2 == i1.m_sibl_ecap_neg; diff --git a/TrackerInfo.h b/TrackerInfo.h index 0e207688359ff..878469157a038 100644 --- a/TrackerInfo.h +++ b/TrackerInfo.h @@ -9,6 +9,9 @@ class LayerInfo { +private: + bool is_in_r2_hole(float r2) const { return r2 > m_hole_r2_min && r2 < m_hole_r2_max; } + public: enum LayerType_e { Undef = -1, Barrel = 0, EndCapPos = 1, EndCapNeg = 2 }; @@ -21,7 +24,9 @@ class LayerInfo int m_next_barrel = -1, m_next_ecap_pos = -1, m_next_ecap_neg = -1; int m_sibl_barrel = -1, m_sibl_ecap_pos = -1, m_sibl_ecap_neg = -1; - bool m_is_outer = false; + bool m_is_outer = false; + bool m_has_r_range_hole = false; + float m_hole_r2_min, m_hole_r2_max; // This could be turned into std::function when needed. // Selection limits float m_q_bin; // > 0 - bin width, < 0 - number of bins @@ -41,12 +46,16 @@ class LayerInfo void set_limits(float r1, float r2, float z1, float z2); void set_next_layers(int nb, int nep, int nen); void set_selection_limits(float p1, float p2, float q1, float q2); + void set_r_hole_range(float rh1, float rh2); float r_mean() const { return (m_rin + m_rout) / 2; } float z_mean() const { return (m_zmin + m_zmax) / 2; } bool is_barrel() const { return m_layer_type == Barrel; } + bool is_in_rsqr_hole(float r2) const { return m_has_r_range_hole ? is_in_r2_hole(r2) : false; } + bool is_in_xy_hole(float x, float y) const { return m_has_r_range_hole ? is_in_r2_hole(x*x + y*y): false; } + void print_layer() { printf("Layer %2d r(%7.4f, %7.4f) z(% 9.4f, % 9.4f) next(%2d, %2d, %2d) is_brl=%d is_outer=%d\n", @@ -76,9 +85,10 @@ class TrackerInfo std::vector m_ecap_neg; float m_eta_trans_beg, m_eta_trans_end, m_eta_ecap_end; + bool m_has_sibling_layers; - void set_eta_regions(float tr_beg, float tr_end, float ec_end); - + void set_eta_regions(float tr_beg, float tr_end, float ec_end, + bool has_sibl_lyrs); void reserve_layers(int n_brl, int n_ec_pos, int n_ec_neg); void create_layers (int n_brl, int n_ec_pos, int n_ec_neg); LayerInfo & new_barrel_layer(); diff --git a/mkFit/HitStructures.h b/mkFit/HitStructures.h index 969c4d555d01e..0b25dd5c6415d 100644 --- a/mkFit/HitStructures.h +++ b/mkFit/HitStructures.h @@ -89,6 +89,8 @@ class LayerOfHits float min_dq() const { return m_layer_info->m_select_min_dq; } float max_dq() const { return m_layer_info->m_select_max_dq; } + bool is_in_xy_hole(float x, float y) const { return m_layer_info->is_in_xy_hole(x, y); } + // Testing bin filling static constexpr float m_fphi = Config::m_nphi / Config::TwoPI; static constexpr int m_phi_mask = 0x3ff; diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index c8b6e5808b688..b5f7b76e18b24 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -259,7 +259,8 @@ void MkBuilder::begin_event(Event* ev, const char* build_type) m_event_of_hits.Reset(); - //fill vector of hits in each layer + // fill vector of hits in each layer + // XXXXMT: Does it really makes sense to multi-thread this? tbb::parallel_for(tbb::blocked_range(0, m_event->layerHits_.size()), [&](const tbb::blocked_range& layers) { @@ -302,133 +303,139 @@ void MkBuilder::end_event() // Seeding functions: importing, finding and fitting //------------------------------------------------------------------------------ -namespace +void MkBuilder::create_seeds_from_sim_tracks() { - void sort_seeds(Event* ev, TrackVec& tv, RadixSort& rs, std::vector& etas) - { - const int size = tv.size(); + // Import from simtrack snatching first Config::nlayers_per_seed hits. + // + // Reduce number of hits, pick endcap over barrel when both are available. + // This is done by assumin endcap hit is after the barrel, no checks. - for (int i = 0; i < 5; ++i) ev->seedEtaSeparators_[i] = 0; + // bool debug = true; - etas.resize(size); - for (int i = 0; i < size; ++i) - { - //float eta = tv[i].momEta(); + TrackerInfo &trk_info = Config::TrkInfo; + TrackVec &sims = m_event->simTracks_; + TrackVec &seeds = m_event->seedTracks_; - HitOnTrack hot = tv[i].getHitOnTrack(Config::nlayers_per_seed - 1); - float eta = ev->layerHits_[hot.layer][hot.index].eta(); - - etas[i] = eta; - ++ev->seedEtaSeparators_[ Config::TrkInfo.find_eta_region(eta) ]; - } + const int size = sims.size(); + seeds.clear(); // Needed when reading from file and then recreating from sim. + seeds.reserve(size); - rs.Sort(&etas[0], size); - } -} + dprintf("MkBuilder::create_seeds_from_sim_tracks processing %d simtracks.", size); -void MkBuilder::import_seeds() -{ - // debug=true; - - TrackerInfo &trk_info = Config::TrkInfo; - RadixSort sort; - std::vector etas; - - TrackVec &seeds = m_event->seedTracks_; - - if (Config::readCmsswSeeds) + for (int i = 0; i < size; ++i) { - TrackVec orig_seeds; - orig_seeds.swap(seeds); + const Track &src = sims[i]; - sort_seeds(m_event, orig_seeds, sort, etas); + int h_sel = 0, h = 0; + const HitOnTrack *hots = src.getHitsOnTrackArray(); + HitOnTrack new_hots[ Config::nlayers_per_seed_max ]; - const int size = orig_seeds.size(); - seeds.reserve(size); + // Exit condition -- need to check one more hit after Config::nlayers_per_seed + // good hits are found. + bool last_hit_check = false; - for (int i = 0; i < size; ++i) + while ( ! last_hit_check && h < src.nTotalHits()) { - seeds.emplace_back( orig_seeds[ sort.GetRanks()[i] ] ); - } + assert (hots[h].index >= 0 && "Expecting input sim tracks (or seeds later) to not have holes"); - dprintf("MkBuilder::import_seeds Finished seed import, ec- = %d, t- = %d, brl = %d, t+ = %d, ec+ = %d\n", - m_event->seedEtaSeparators_[0], m_event->seedEtaSeparators_[1], m_event->seedEtaSeparators_[2], m_event->seedEtaSeparators_[3], m_event->seedEtaSeparators_[4]); - } - else - { - // Import from simtrack snatching first Config::nlayers_per_seed hits + if (h_sel == Config::nlayers_per_seed) last_hit_check = true; - // XXMT - // Reduce number of hits, pick endcap over barrel when both are available. - // This is done by assumin endcap hit is after the barrel, no checks. - // Further, seeds are sorted by eta and counts for each eta region are - // stored into Event::seedEtaSeparators_. - // - // Seed fitting could change this eta ... - - // ORIGINAL IMPLEMENTATION WAS: - // make seed tracks == simtracks if not using "realistic" seeding - // m_event->seedTracks_ = m_event->simTracks_; + // Check if hit is on a sibling layer given the previous one. + if (h_sel > 0 && trk_info.are_layers_siblings(new_hots[h_sel - 1].layer, hots[h].layer)) + { + dprintf(" Sibling layers %d %d ... overwriting with new one\n", + new_hots[h_sel - 1].layer, hots[h].layer); - TrackVec &sims = m_event->simTracks_; + new_hots[h_sel - 1] = hots[h]; + } + // Drop further hits on the same layer. It seems hard to select the best one (in any way). + else if (h_sel > 0 && new_hots[h_sel - 1].layer == hots[h].layer) + { + dprintf(" Hits on the same layer %d ... keeping the first one\n", hots[h].layer); + } + else if ( ! last_hit_check) + { + new_hots[h_sel++] = hots[h]; + } - sort_seeds(m_event, sims, sort, etas); + ++h; + } - const int size = sims.size(); - seeds.reserve(size); + seeds.emplace_back( Track(src.state(), 0, src.label(), h_sel, new_hots) ); - for (int i = 0; i < size; ++i) - { - const int j = sort.GetRanks()[i]; - const Track &src = sims[j]; + Track &dst = seeds.back(); + dprintf(" Seed nh=%d, last_lay=%d, last_idx=%d\n", + dst.nTotalHits(), dst.getLastHitLyr(), dst.getLastHitIdx()); + // dprintf(" "); for (int i=0; i= 0 && "Expecting input sim tracks (or seeds later) to not have holes"); + { + printf("***\n*** MkBuilder::import_seeds REMOVING SEEDS WITH BAD LABEL. This is a development hack. ***\n***\n"); - if (h_sel == Config::nlayers_per_seed) last_hit_check = true; + if (true) { + TrackVec buf; m_event->seedTracks_.swap(buf); + std::copy_if(buf.begin(), buf.end(), std::back_inserter(m_event->seedTracks_), [](const Track& t){ return t.label() >= 0; }); + } + } - // Check if hit is on a sibling layer given the previous one. Barrel ignored. - if (h_sel > 0 && ! trk_info.is_barrel(etas[j]) && - trk_info.are_layers_siblings(new_hots[h_sel - 1].layer, hots[h].layer)) - { - dprintf(" Sibling layers %d %d ... overwriting with new one\n", - new_hots[h_sel - 1].layer, hots[h].layer); + TrackerInfo &trk_info = Config::TrkInfo; + TrackVec &seeds = m_event->seedTracks_; + const int size = seeds.size(); + for (int i = 0; i < 5; ++i) + { + m_event->seedEtaSeparators_[i] = 0; + m_event->seedMinLastLayer_ [i] = 9999; + } - new_hots[h_sel - 1] = hots[h]; - } - else if ( ! last_hit_check) - { - new_hots[h_sel++] = hots[h]; - } + std::vector etas(size); + for (int i = 0; i < size; ++i) + { + //float eta = seeds[i].momEta(); - ++h; - } + HitOnTrack hot = seeds[i].getLastHitOnTrack(); + float eta = m_event->layerHits_[hot.layer][hot.index].eta(); - seeds.emplace_back( Track(src.state(), 0, src.label(), Config::nlayers_per_seed, new_hots) ); + etas[i] = eta; + TrackerInfo::EtaRegion reg = Config::TrkInfo.find_eta_region(eta); + ++m_event->seedEtaSeparators_[reg]; + m_event->seedMinLastLayer_[reg] = std::min(m_event->seedMinLastLayer_[reg], hot.layer); + } + for (int i = 0; i < 5; ++i) + { + if (m_event->seedMinLastLayer_[i] == 9999) m_event->seedMinLastLayer_[i] = -1; + } - Track &dst = m_event->seedTracks_.back(); - dprintf(" Seed nh=%d, last_lay=%d, last_idx=%d\n", - dst.nTotalHits(), dst.getLastHitLyr(), dst.getLastHitIdx()); - // dprintf(" "); for (int i=0; iseedEtaSeparators_[0], m_event->seedEtaSeparators_[1], m_event->seedEtaSeparators_[2], m_event->seedEtaSeparators_[3], m_event->seedEtaSeparators_[4]); + TrackVec orig_seeds; + orig_seeds.swap(seeds); + seeds.reserve(size); + for (int i = 0; i < size; ++i) + { + seeds.emplace_back( orig_seeds[ rs.GetRanks()[i] ] ); } + dprintf("MkBuilder::import_seeds finished import of %d seeds (last seeding layer):\n" + " ec- = %d(%d), t- = %d(%d), brl = %d(%d), t+ = %d(%d), ec+ = %d(%d).\n", + size, + m_event->seedEtaSeparators_[0], m_event->seedMinLastLayer_[0], + m_event->seedEtaSeparators_[1], m_event->seedMinLastLayer_[1], + m_event->seedEtaSeparators_[2], m_event->seedMinLastLayer_[2], + m_event->seedEtaSeparators_[3], m_event->seedMinLastLayer_[3], + m_event->seedEtaSeparators_[4], m_event->seedMinLastLayer_[4]); + // Sum region counts up to contain actual separator indices: for (int i = TrackerInfo::Reg_Transition_Neg; i < TrackerInfo::Reg_Count; ++i) { @@ -856,8 +863,14 @@ void MkBuilder::quality_process(Track &tkcand) { TrackExtra extra(tkcand.label()); - if (Config::useCMSGeom || Config::findSeeds) {extra.setMCTrackIDInfo(tkcand, m_event->layerHits_, m_event->simHitsInfo_, m_event->simTracks_,false);} - else {extra.setMCTrackIDInfoByLabel(tkcand, m_event->layerHits_, m_event->simHitsInfo_);} + if (Config::useCMSGeom || Config::findSeeds) + { + extra.setMCTrackIDInfo(tkcand, m_event->layerHits_, m_event->simHitsInfo_, m_event->simTracks_, false); + } + else + { + extra.setMCTrackIDInfoByLabel(tkcand, m_event->layerHits_, m_event->simHitsInfo_); + } int mctrk = extra.mcTrackID(); // int mctrk = tkcand.label(); // assumes 100% "efficiency" @@ -869,8 +882,9 @@ void MkBuilder::quality_process(Track &tkcand) { ++m_cnt_nomc; std::cout << "XX bad track idx " << mctrk << ", orig label was " << tkcand.label() << "\n"; - } else { - + } + else + { ptmc = m_event->simTracks_[mctrk].pT() ; pr = pt / ptmc; nfoundmc = m_event->simTracks_[mctrk].nFoundHits(); @@ -881,15 +895,16 @@ void MkBuilder::quality_process(Track &tkcand) if (pr > 0.8 && pr < 1.2) ++m_cnt2; if (tkcand.nFoundHits() >= 0.8f*nfoundmc) - { - ++m_cnt_8; - if (pr > 0.9 && pr < 1.1) ++m_cnt1_8; - if (pr > 0.8 && pr < 1.2) ++m_cnt2_8; - } + { + ++m_cnt_8; + if (pr > 0.9 && pr < 1.1) ++m_cnt1_8; + if (pr > 0.8 && pr < 1.2) ++m_cnt2_8; + } } #if defined(DEBUG) || defined(PRINTOUTS_FOR_PLOTS) - if (!Config::silent) { + if (!Config::silent) + { std::lock_guard printlock(Event::printmutex); std::cout << "MX - found track with nFoundHits=" << tkcand.nFoundHits() << " chi2=" << tkcand.chi2() << " pT=" << pt <<" pTmc="<< ptmc << " nfoundmc=" << nfoundmc << " chi2mc=" << chi2mc <<" lab="<< tkcand.label() <clean_cms_simtracks(); + } + create_seeds_from_sim_tracks(); + } import_seeds(); - // all simulated seeds need to have hit indices line up in LOH for seed fit + + // printf("\n* Seeds after import / cleaning:\n"); + // m_event->print_tracks(m_event->seedTracks_, true); + // printf("\n"); + + // For now, all simulated seeds need to have hit indices line up in LOH for seed fit map_seed_hits(); } @@ -1008,9 +1038,10 @@ void MkBuilder::FindTracksBestHit() tbb::parallel_for_each(m_brl_ecp_regions.begin(), m_brl_ecp_regions.end(), [&](int region) { - // XXXXXX endcap only ... + // XXXXXX Select endcap / barrel only ... // if (region != TrackerInfo::Reg_Endcap_Neg && region != TrackerInfo::Reg_Endcap_Pos) - // continue; + // if (region != TrackerInfo::Reg_Barrel) + // return; const SteeringParams &st_par = m_steering_params[region]; @@ -1277,6 +1308,8 @@ void MkBuilder::FindTracksStandard() void MkBuilder::FindTracksCloneEngine() { + // debug = true; + g_exe_ctx.populate(Config::numThreadsFinder); EventOfCombCandidates &eoccs = m_event_of_comb_cands; @@ -1299,6 +1332,8 @@ void MkBuilder::FindTracksCloneEngine() find_tracks_in_layers(*cloner, mkfp.get(), seeds.begin(), seeds.end(), region); }); }); + + // debug = false; } void MkBuilder::find_tracks_in_layers(CandCloner &cloner, MkFitter *mkfp, @@ -1321,9 +1356,15 @@ void MkBuilder::find_tracks_in_layers(CandCloner &cloner, MkFitter *mkfp, int prev_ilay = -1; int n_hits = Config::nlayers_per_seed; - for (int ilay = st_par.first_finding_layer; ; ) + int last_seed_layer = m_event->seedMinLastLayer_[region]; + int first_layer = trk_info.m_layers[last_seed_layer].*st_par.next_layer_doo; + + dprintf("\nMkBuilder::find_tracks_in_layers region=%d, last_seed_layer=%d, first_layer=%d\n", + region, last_seed_layer, first_layer); + + for (int ilay = first_layer; ; ) { - dprint("processing lay=" << ilay); + dprint("\n* Processing lay=" << ilay); const LayerInfo &layer_info = trk_info.m_layers[ilay]; @@ -1346,7 +1387,7 @@ void MkBuilder::find_tracks_in_layers(CandCloner &cloner, MkFitter *mkfp, // Can leave some room for future missing-hit-types. // 2. Document these cases somewhere, have NAMES or constants or an enum. // 3. Make sure they are used consistently everywhere. - if (scands[ic].getLastHitIdx() >= -1) + if (scands[ic].getLastHitIdx() != -2 && scands[ic].getLastHitLyr() < ilay) { seed_cand_idx.push_back(std::pair(iseed,ic)); } diff --git a/mkFit/MkBuilder.h b/mkFit/MkBuilder.h index 7324f827e0859..f7fb1f6e9ba5f 100644 --- a/mkFit/MkBuilder.h +++ b/mkFit/MkBuilder.h @@ -67,6 +67,7 @@ class MkBuilder void begin_event(Event* ev, const char* build_type); void end_event(); + void create_seeds_from_sim_tracks(); void import_seeds(); void find_seeds(); void fit_seeds(); diff --git a/mkFit/MkFitter.cc b/mkFit/MkFitter.cc index 655bf4127e371..231ec63d54d47 100644 --- a/mkFit/MkFitter.cc +++ b/mkFit/MkFitter.cc @@ -1341,17 +1341,10 @@ void MkFitter::FindCandidatesEndcap(const LayerOfHits &layer_of_hits, { int hit_idx = countInvalidHits(itrack) < Config::maxHolesPerCand ? -1 : -2; - // XXXXMT4CMS Grrrr ... this is cmssw specific, sigh - /* - bool withinBounds = true; - float r2 = Par[iP](itrack,0,0)*Par[iP](itrack,0,0)+Par[iP](itrack,1,0)*Par[iP](itrack,1,0); - if ( r2<(Config::cmsDiskMinRs[Nhits]*Config::cmsDiskMinRs[Nhits]) || - r2>(Config::cmsDiskMaxRs[Nhits]*Config::cmsDiskMaxRs[Nhits]) || - r2>(Config::cmsDiskMinRsHole[Nhits]*Config::cmsDiskMinRsHole[Nhits]) || - r2<(Config::cmsDiskMaxRsHole[Nhits]*Config::cmsDiskMaxRsHole[Nhits]) ) withinBounds = false; - //-3 means we did not expect any hit since we are out of bounds, so it does not count in countInvalidHits - if (withinBounds==false) hit_idx = -3; - */ + if (layer_of_hits.is_in_xy_hole(Par[iP](itrack,0,0), Par[iP](itrack,1,0))) + { + hit_idx = -3; + } Track newcand; newcand.resetHits();//probably not needed @@ -1942,30 +1935,15 @@ void MkFitter::AddBestHitEndcap(const LayerOfHits &layer_of_hits, const int N_pr } else { + int fake_hit_idx = layer_of_hits.is_in_xy_hole(Par[iP](itrack,0,0), Par[iP](itrack,1,0)) ? -3 : -1; - bool withinBounds = true; - float r2 = Par[iP](itrack,0,0)*Par[iP](itrack,0,0)+Par[iP](itrack,1,0)*Par[iP](itrack,1,0); - // XXXXMT4CMS Grrrr ... this is cmssw specific, sigh - /* - if ( r2<(Config::cmsDiskMinRs[Nhits]*Config::cmsDiskMinRs[Nhits]) || - r2>(Config::cmsDiskMaxRs[Nhits]*Config::cmsDiskMaxRs[Nhits]) || - r2>(Config::cmsDiskMinRsHole[Nhits]*Config::cmsDiskMinRsHole[Nhits]) || - r2<(Config::cmsDiskMaxRsHole[Nhits]*Config::cmsDiskMaxRsHole[Nhits]) ) withinBounds = false; - */ - -#ifdef DEBUG - r2= std::sqrt(r2); -#endif - dprint("ADD FAKE HIT FOR TRACK #" << itrack << " withinBounds=" << withinBounds << " r=" << r2 - << " minR=" << Config::cmsDiskMinRs[Nhits] << " maxR=" << Config::cmsDiskMaxRs[Nhits] - << " minRHole=" << Config::cmsDiskMinRsHole[Nhits] << " maxRHole=" << Config::cmsDiskMaxRsHole[Nhits]); + dprint("ADD FAKE HIT FOR TRACK #" << itrack << " withinBounds=" << (fake_hit_idx != -3) << " r=" << std::hypot(Par[iP](itrack,0,0), Par[iP](itrack,1,0))); msErr[Nhits].SetDiagonal3x3(itrack, 666); msPar[Nhits](itrack,0,0) = Par[iP](itrack,0,0); msPar[Nhits](itrack,1,0) = Par[iP](itrack,1,0); msPar[Nhits](itrack,2,0) = Par[iP](itrack,2,0); - //-3 means we did not expect any hit since we are out of bounds, so it does not count in countInvalidHits - HoTArr[Nhits](itrack, 0, 0) = { withinBounds ? -1 : -3, layer_of_hits.layer_id() }; + HoTArr[Nhits](itrack, 0, 0) = { fake_hit_idx, layer_of_hits.layer_id() }; // Don't update chi2 } @@ -2099,17 +2077,10 @@ void MkFitter::FindCandidatesMinimizeCopyEndcap(const LayerOfHits &layer_of_hits int hit_idx = countInvalidHits(itrack) < Config::maxHolesPerCand ? -1 : -2; - bool withinBounds = true; - float r2 = Par[iP](itrack,0,0)*Par[iP](itrack,0,0)+Par[iP](itrack,1,0)*Par[iP](itrack,1,0); - // XXXXMT4CMS Grrrr ... this is cmssw specific, sigh - /* - if ( r2<(Config::cmsDiskMinRs[Nhits]*Config::cmsDiskMinRs[Nhits]) || - r2>(Config::cmsDiskMaxRs[Nhits]*Config::cmsDiskMaxRs[Nhits]) || - r2>(Config::cmsDiskMinRsHole[Nhits]*Config::cmsDiskMinRsHole[Nhits]) || - r2<(Config::cmsDiskMaxRsHole[Nhits]*Config::cmsDiskMaxRsHole[Nhits]) ) withinBounds = false; - //-3 means we did not expect any hit since we are out of bounds, so it does not count in countInvalidHits - if (withinBounds==false) hit_idx = -3; - */ + if (layer_of_hits.is_in_xy_hole(Par[iP](itrack,0,0), Par[iP](itrack,1,0))) + { + hit_idx = -3; + } IdxChi2List tmpList; tmpList.trkIdx = CandIdx(itrack, 0, 0); diff --git a/mkFit/MkFitter.h b/mkFit/MkFitter.h index e7308380314f0..346b4d877cce0 100644 --- a/mkFit/MkFitter.h +++ b/mkFit/MkFitter.h @@ -30,6 +30,7 @@ struct MkFitter MPlexQI Chg; MPlexQF Chi2; + MPlexQF OutChi2; MPlexHS msErr[Config::nMaxTrkHits]; MPlexHV msPar[Config::nMaxTrkHits]; @@ -54,12 +55,6 @@ struct MkFitter public: MkFitter() : Nhits(0) {} - MkFitter(int n_hits) : Nhits(n_hits) - { - // XXXX Eventually dynamically allocate measurement arrays. - // XXXX std::vector is no good, not aligned! - // XXXX Hmmh, should really copy them in layer by layer. - } // Copy-in timing tests. MPlexLS& GetErr0() { return Err[0]; } @@ -70,7 +65,7 @@ struct MkFitter void PrintPt(int idx); float getPar(int itrack, int i, int par) const { return Par[i].ConstAt(itrack, 0, par); } - void SetNhits(int newnhits) { Nhits=newnhits; } + void SetNhits(int newnhits) { Nhits = std::min(newnhits, Config::nMaxTrkHits - 1); } int countValidHits (int itrack, int end_hit) const; int countInvalidHits(int itrack, int end_hit) const; diff --git a/mkFit/buildtestMPlex.cc b/mkFit/buildtestMPlex.cc index b319793d861a0..d93f1aeb14b72 100644 --- a/mkFit/buildtestMPlex.cc +++ b/mkFit/buildtestMPlex.cc @@ -187,7 +187,9 @@ double runBuildingTestPlexCloneEngine(Event& ev, MkBuilder& builder) if (!Config::root_val) { if (!Config::silent) builder.quality_output_COMB(); - } else {builder.root_val_COMB();} + } else { + builder.root_val_COMB(); + } builder.end_event(); diff --git a/mkFit/mt-notes.txt b/mkFit/mt-notes.txt index 4e9a70ba202a7..8e215aa7703a0 100644 --- a/mkFit/mt-notes.txt +++ b/mkFit/mt-notes.txt @@ -1,3 +1,10 @@ +Test samples on desire: + +./mkFit --read --file-name /bar/mic/mu_brl-1000-10.bin-3 --build-ce --geom CMS-2017 --input-version 0 --cmssw-seeds +./mkFit --read --file-name /bar/mic/mu_ecp-1000-10.bin-3 --build-ce --geom CMS-2017 --input-version 0 --cmssw-seeds --num-events 990 +./mkFit --read --file-name /bar/mic/mu_ecn-1000-10.bin-3 --build-ce --geom CMS-2017 --input-version 0 --cmssw-seeds --num-events 990 + + ######### Notes for Kevin ######### From f3206baf0ab52ec2e60de1b01fbd3de22facbbc7 Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Fri, 2 Jun 2017 00:51:43 -0700 Subject: [PATCH 061/172] Add extended header to our save files. This performs consistency check before reading in events. Allows reading of files with number of hits on track than current Config::nMaxTrkHits. Defined in Event.h: struct DataFileHeader { int f_magic = 0xBEEF; int f_format_version = 2; int f_sizeof_track = sizeof(Track); int f_n_max_trk_hits = Config::nMaxTrkHits; int f_n_layers = -1; int f_n_events = -1; DataFileHeader() { f_n_layers = Config::nTotalLayers; } }; struct DataFile { FILE *f_fp = 0; DataFileHeader f_header; int OpenRead (const std::string& fname, bool set_n_layers = false); void OpenWrite(const std::string& fname, int nev); void Close(); }; --- Config.h | 7 ++-- Event.cc | 102 +++++++++++++++++++++++++++++++++++++++++---- Event.h | 38 +++++++++++++++-- Track.h | 2 +- main.cc | 35 ++-------------- mkFit/MkBuilder.cc | 3 +- mkFit/mkFit.cc | 98 ++++++++++++++----------------------------- 7 files changed, 173 insertions(+), 112 deletions(-) diff --git a/Config.h b/Config.h index 4c7613cc4bea8..8e102ea66ffbd 100644 --- a/Config.h +++ b/Config.h @@ -37,10 +37,12 @@ namespace Config // config on main + mkFit extern int nTracks; //defined in Config.cc by default or when reading events from file extern int nEvents; + // XXXXMT: nTracks should be thrown out ... SMatrix and Event allocate some arrays on this + // which can be wrong for real data or in multi-event environment extern std::string geomPlugin; - // config on main -- for geometry + // config on main -- for geometry; XXXXMT to be thrown out, too constexpr int nLayers = 10; // default: 10; cmssw tests: 13, 17, 26 (for endcap) // New layer constants for common barrel / endcap. I'd prefer those to go @@ -49,8 +51,7 @@ namespace Config // XXXX This needs to be generalized for other geometries ! // TrackerInfo more or less has all this information (or could have it). extern int nTotalLayers; // To be set by geometry plugin. - constexpr int nMaxSimHits = 28; // Assuming dual hit on every barrel / endcap edge - constexpr int nMaxRecHits = 10; // Assuming single hit on each layer + constexpr int nMaxSimHits = 32; // Assuming dual hit on every barrel / endcap edge -> used in tkNtuple constexpr int nMaxTrkHits = nMaxSimHits; // Used for array sizes in MkFitter and Track constexpr float fRadialSpacing = 4.; diff --git a/Event.cc b/Event.cc index 43702e91f15f0..a59cda086cc2c 100644 --- a/Event.cc +++ b/Event.cc @@ -35,6 +35,19 @@ inline bool sortByZ(const Hit& hit1, const Hit& hit2){ return hit1.z() dummyValidation( Validation::make_validation("dummy") ); +} + +Event::Event(int evtID) : + geom_(dummyGeometry), validation_(*dummyValidation), + evtID_(evtID), threads_(1), mcHitIDCounter_(0) +{ + layerHits_.resize(Config::nTotalLayers); +} + Event::Event(const Geometry& g, Validation& v, int evtID, int threads) : geom_(g), validation_(v), evtID_(evtID), threads_(threads), mcHitIDCounter_(0) @@ -353,8 +366,10 @@ void Event::PrintStats(const TrackVec& trks, TrackExtraVec& trkextras) << " nH >= 8 =" << hit8 << " in pT 10%=" << h8_10 << " in pT 20%=" << h8_20 << std::endl; } -void Event::write_out(FILE *fp) +void Event::write_out(DataFile &data_file) { + FILE *fp = data_file.f_fp; + static std::mutex writemutex; std::lock_guard writelock(writemutex); @@ -426,12 +441,14 @@ void Event::write_out(FILE *fp) // #define DUMP_TRACK_HITS // #define DUMP_LAYER_HITS -void Event::read_in(FILE *fp, int version) +void Event::read_in(DataFile &data_file) { - static long pos = sizeof(int); // header size + FILE *fp = data_file.f_fp; + + static long pos = sizeof(DataFileHeader); int evsize; - if (version > 0) { + { static std::mutex readmutex; std::lock_guard readlock(readmutex); @@ -443,7 +460,10 @@ void Event::read_in(FILE *fp, int version) int nt; fread(&nt, sizeof(int), 1, fp); simTracks_.resize(nt); - fread(&simTracks_[0], sizeof(Track), nt, fp); + for (int i = 0; i < nt; ++i) + { + fread(&simTracks_[i], data_file.f_header.f_sizeof_track, 1, fp); + } Config::nTracks = nt; if (Config::root_val || Config::fit_val) @@ -475,11 +495,14 @@ void Event::read_in(FILE *fp, int version) if (Config::readCmsswSeeds) { seedTracks_.resize(ns); - fread(&seedTracks_[0], sizeof(Track), ns, fp); + for (int i = 0; i < ns; ++i) + { + fread(&seedTracks_[i], data_file.f_header.f_sizeof_track, 1, fp); + } } else { - fseek(fp, sizeof(Track)*ns, SEEK_CUR); + fseek(fp, ns * data_file.f_header.f_sizeof_track, SEEK_CUR); ns = -ns; } #ifdef DUMP_SEEDS @@ -627,3 +650,68 @@ void Event::print_tracks(const TrackVec& tracks, bool print_hits) const } } } + + +//============================================================================== +// DataFile +//============================================================================== + +int DataFile::OpenRead(const std::string& fname, bool set_n_layers) +{ + constexpr int min_ver = 2; + constexpr int max_ver = 2; + + f_fp = fopen(fname.c_str(), "r"); + assert (f_fp != 0 || "Opening of input file failed."); + + fread(&f_header, sizeof(DataFileHeader), 1, f_fp); + + if (f_header.f_magic != 0xBEEF) + { + fprintf(stderr, "Incompatible input file (wrong magick).\n"); + exit(1); + } + if (f_header.f_format_version < min_ver || f_header.f_format_version > max_ver) + { + fprintf(stderr, "Unsupported file version %d. Supported versions are %d to %d.\n", + f_header.f_format_version, min_ver, max_ver); + exit(1); + } + if (f_header.f_n_max_trk_hits > Config::nMaxTrkHits) + { + fprintf(stderr, "Number of hits-on-track on file (%d) larger than current Config::nMaxTrkHits (%d).\n", + f_header.f_n_max_trk_hits, Config::nMaxTrkHits); + exit(1); + } + if (set_n_layers) + { + Config::nTotalLayers = f_header.f_n_layers; + } + else if (f_header.f_n_layers != Config::nTotalLayers) + { + fprintf(stderr, "Number of layers on file (%d) is different from current Config::nTotalLayers (%d).\n", + f_header.f_n_layers, Config::nTotalLayers); + exit(1); + } + + printf("Opened file '%s', format version %d, n_max_trk_hits %d, n_layers %d, n_events %d\n", + fname.c_str(), f_header.f_format_version, f_header.f_n_max_trk_hits, f_header.f_n_layers, f_header.f_n_events); + + return f_header.f_n_events; +} + +void DataFile::OpenWrite(const std::string& fname, int nev) +{ + f_fp = fopen(fname.c_str(), "w"); + + f_header.f_n_events = nev; + + fwrite(&f_header, sizeof(DataFileHeader), 1, f_fp); +} + +void DataFile::Close() +{ + fclose(f_fp); + f_fp = 0; + f_header = DataFileHeader(); +} diff --git a/Event.h b/Event.h index 79206bf43ea9a..a0ea764649e0d 100644 --- a/Event.h +++ b/Event.h @@ -9,10 +9,14 @@ #include +class DataFile; + class Event { public: + explicit Event(int evtID); Event(const Geometry& g, Validation& v, int evtID, int threads = 1); + void Reset(int evtID); void RemapHits(TrackVec & tracks); void Simulate(); @@ -28,8 +32,8 @@ class Event int nextMCHitID() { return mcHitIDCounter_++; } - void write_out(FILE *fp); - void read_in(FILE *fp, int version = Config::FileVersion); + void write_out(DataFile &data_file); + void read_in (DataFile &data_file); void clean_cms_simtracks(); void print_tracks(const TrackVec& tracks, bool print_hits) const; @@ -38,7 +42,7 @@ class Event Validation& validation_; private: - int evtID_; + int evtID_; public: int threads_; @@ -62,4 +66,32 @@ class Event typedef std::vector EventVec; + +struct DataFileHeader +{ + int f_magic = 0xBEEF; + int f_format_version = 2; + int f_sizeof_track = sizeof(Track); + int f_n_max_trk_hits = Config::nMaxTrkHits; + int f_n_layers = -1; + int f_n_events = -1; + + DataFileHeader() + { + f_n_layers = Config::nTotalLayers; + } +}; + +struct DataFile +{ + FILE *f_fp = 0; + + DataFileHeader f_header; + + int OpenRead (const std::string& fname, bool set_n_layers = false); + void OpenWrite(const std::string& fname, int nev); + + void Close(); +}; + #endif diff --git a/Track.h b/Track.h index 947dc92a1c419..2ee39105aa987 100644 --- a/Track.h +++ b/Track.h @@ -333,11 +333,11 @@ class Track private: TrackState state_; - HitOnTrack hitsOnTrk_[Config::nMaxTrkHits]; float chi2_ = 0.; int hitIdxPos_ = -1; int nGoodHits_ = 0; int label_ = -1; + HitOnTrack hitsOnTrk_[Config::nMaxTrkHits]; }; typedef std::vector TrackVec; diff --git a/main.cc b/main.cc index de0d11e622125..7adaa5e137502 100644 --- a/main.cc +++ b/main.cc @@ -101,38 +101,10 @@ static tick delta(timepoint& t0) // from mkFit namespace { - FILE *s_file = 0; - int s_file_num_ev = 0; - int s_file_cur_ev = 0; - std::string s_operation = "empty"; std::string s_file_name = "simtracks.bin"; } -// from mkFit -int open_simtrack_file() -{ - s_file = fopen(s_file_name.c_str(), "r"); - - assert (s_file != 0); - - fread(&s_file_num_ev, sizeof(int), 1, s_file); - s_file_cur_ev = 0; - - printf("\nReading simulated tracks from \"%s\", %d events on file.\n\n", - s_file_name.c_str(), s_file_num_ev); - - return s_file_num_ev; -} - -void close_simtrack_file() -{ - fclose(s_file); - s_file = 0; - s_file_num_ev = 0; - s_file_cur_ev = 0; -} - // also from mkfit typedef std::list lStr_t; typedef lStr_t::iterator lStr_i; @@ -266,9 +238,10 @@ int main(int argc, const char* argv[]) tbb::task_scheduler_init tasks(nThread); #endif + DataFile data_file; if (s_operation == "read") { - Config::nEvents = open_simtrack_file(); + Config::nEvents = data_file.OpenRead(s_file_name); } for (int evt=0; evt time(ticks.size()); diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index b5f7b76e18b24..7f3935cc3ba74 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -379,6 +379,7 @@ void MkBuilder::import_seeds() bool debug = true; + if (Config::readCmsswSeeds) { printf("***\n*** MkBuilder::import_seeds REMOVING SEEDS WITH BAD LABEL. This is a development hack. ***\n***\n"); @@ -878,7 +879,7 @@ void MkBuilder::quality_process(Track &tkcand) float pt = tkcand.pT(); float ptmc = 0., pr = 0., nfoundmc = 0., chi2mc = 0.; - if (mctrk < 0 || mctrk >= Config::nTracks) + if (mctrk < 0 || mctrk >= m_event->simTracks_.size()) { ++m_cnt_nomc; std::cout << "XX bad track idx " << mctrk << ", orig label was " << tkcand.label() << "\n"; diff --git a/mkFit/mkFit.cc b/mkFit/mkFit.cc index 3a935a8c7b2da..46dbb5d929cc4 100644 --- a/mkFit/mkFit.cc +++ b/mkFit/mkFit.cc @@ -99,10 +99,6 @@ void initGeom(Geometry& geom) namespace { - FILE *g_file = 0; - int g_file_num_ev = 0; - std::atomic g_file_cur_ev{0}; - bool g_run_fit_std = false; bool g_run_build_all = true; @@ -113,50 +109,48 @@ namespace std::string g_operation = "simulate_and_process";; std::string g_file_name = "simtracks.bin"; std::string g_input_file = ""; - int g_input_version = Config::FileVersion; const char* b2a(bool b) { return b ? "true" : "false"; } } +//============================================================================== + void read_and_save_tracks() { - FILE *ofp = fopen(g_file_name.c_str(), "w"); - FILE *ifp = fopen(g_input_file.c_str(), "r"); - - fread(&g_file_num_ev, sizeof(int), 1, ifp); - fwrite(&g_file_num_ev, sizeof(int), 1, ofp); + DataFile in; + const int Nevents = in.OpenRead(g_input_file, true); - Geometry geom; - initGeom(geom); - std::unique_ptr val(Validation::make_validation("empty.root")); + DataFile out; + out.OpenWrite(g_file_name, Nevents); - printf("writing %i events\n",g_file_num_ev); + printf("writing %i events\n", Nevents); - Event ev(geom, *val, 0); - for (int evt = 0; evt < g_file_num_ev; ++evt) + Event ev(0); + for (int evt = 0; evt < Nevents; ++evt) { ev.Reset(evt); - ev.read_in(ifp, g_input_version); - ev.write_out(ofp); + ev.read_in(in); + ev.write_out(out); } - fclose(ifp); - fclose(ofp); + out.Close(); + in .Close(); } +//============================================================================== + void generate_and_save_tracks() { - FILE *fp = fopen(g_file_name.c_str(), "w"); - - int Nevents = Config::nEvents; + const int Nevents = Config::nEvents; Geometry geom; initGeom(geom); std::unique_ptr val(Validation::make_validation("empty.root")); - fwrite(&Nevents, sizeof(int), 1, fp); + DataFile data_file; + data_file.OpenWrite(g_file_name, Nevents); - printf("writing %i events\n",Nevents); + printf("writing %i events\n", Nevents); tbb::task_scheduler_init tbb_init(Config::numThreadsSimulation); @@ -184,35 +178,13 @@ void generate_and_save_tracks() } #endif - ev.write_out(fp); + ev.write_out(data_file); } - fclose(fp); + data_file.Close(); } - -int open_simtrack_file() -{ - g_file = fopen(g_file_name.c_str(), "r"); - - assert (g_file != 0); - - fread(&g_file_num_ev, sizeof(int), 1, g_file); - g_file_cur_ev = 0; - - printf("\nReading simulated tracks from \"%s\", %d events on file.\n\n", - g_file_name.c_str(), g_file_num_ev); - - return g_file_num_ev; -} - -void close_simtrack_file() -{ - fclose(g_file); - g_file = 0; - g_file_num_ev = 0; - g_file_cur_ev = 0; -} +//============================================================================== void test_standard() { @@ -239,13 +211,12 @@ void test_standard() Geometry geom; initGeom(geom); + DataFile data_file; if (g_operation == "read") { - int evs_in_file = open_simtrack_file(); + int evs_in_file = data_file.OpenRead(g_file_name); if (Config::nEvents == -1) Config::nEvents = evs_in_file; - - assert(g_input_version > 0 || 1 == Config::numThreadsEvents); } if (Config::useCMSGeom) fillZRgridME(); @@ -336,14 +307,12 @@ void test_standard() auto& mkb = *mkbs[thisthread].get(); auto fp = fps[thisthread].get(); - if (g_input_version == 0) fseek(fp, sizeof(int), SEEK_SET); - int evstart = thisthread*events_per_thread; int evend = std::min(Config::nEvents, evstart+events_per_thread); dprint("thisthread " << thisthread << " events " << Config::nEvents << " events/thread " << events_per_thread << " range " << evstart << ":" << evend); - + for (int evt = evstart; evt < evend; ++evt) { ev.Reset(nevt++); @@ -357,7 +326,7 @@ void test_standard() if (g_operation == "read") { - ev.read_in(fp, g_input_version); + ev.read_in(data_file); } else { @@ -429,7 +398,7 @@ void test_standard() if (g_operation == "read") { - close_simtrack_file(); + data_file.Close(); } for (auto& val : vals) { @@ -438,6 +407,8 @@ void test_standard() } } +//============================================================================== +// Command line argument parsing //============================================================================== typedef std::list lStr_t; @@ -461,6 +432,8 @@ void next_arg_or_die(lStr_t& args, lStr_i& i, bool allow_single_minus=false) i = j; } +//============================================================================== +// main //============================================================================== int main(int argc, const char *argv[]) @@ -513,7 +486,6 @@ int main(int argc, const char *argv[]) " --read read simulation from file\n" " --file-name file name for write/read (def: %s)\n" " --input-file file name for reading when converting formats (def: %s)\n" - " --input-version version for reading when converting formats (def: %d)\n" "GPU specific options: \n" " --num-thr-reorg number of threads to run the hits reorganization\n" , @@ -536,8 +508,7 @@ int main(int argc, const char *argv[]) b2a(Config::inclusiveShorts), b2a(Config::silent), g_file_name.c_str(), - g_input_file.c_str(), - g_input_version + g_input_file.c_str() ); exit(0); } @@ -669,11 +640,6 @@ int main(int argc, const char *argv[]) g_operation = "convert"; g_input_file = *i; } - else if (*i == "--input-version") - { - next_arg_or_die(mArgs, i); - g_input_version = atoi(i->c_str()); - } else if(*i == "--silent") { Config::silent = true; From 1afed7ac849bc4d239171b191498ba756844cf24 Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Fri, 2 Jun 2017 00:55:57 -0700 Subject: [PATCH 062/172] Support new save file format. Use Event and DataFile classes for writing. Now requires two arguments, input and output file. If you want to run it outside of mictest/tkNtuple set LD_LIBRARY_PATH so ld can find libMicCore. --- tkNtuple/Makefile | 19 ++-- tkNtuple/WriteMemoryFile.cc | 181 +++++++++++++++++++----------------- 2 files changed, 103 insertions(+), 97 deletions(-) diff --git a/tkNtuple/Makefile b/tkNtuple/Makefile index 6cb9a134a0043..62e8abf821f69 100644 --- a/tkNtuple/Makefile +++ b/tkNtuple/Makefile @@ -1,5 +1,8 @@ include ../Makefile.config +# Overide debug settings +# OPT := -O0 -g + .PHONY: all clean distclean echo ifndef ROOTSYS @@ -12,8 +15,8 @@ CPPEXTRA := -I.. ${USER_CPPFLAGS} ${DEFS} LDEXTRA := ${USER_LDFLAGS} CPPFLAGS := $(shell root-config --cflags) ${CPPEXTRA} ${CPPFLAGS} -CXXFLAGS += ${USER_CXXFLAGS} -LDFLAGS += $(shell root-config --ldflags --cflags --libs) ${LDEXTRA} +CXXFLAGS += -fPIC ${USER_CXXFLAGS} +LDFLAGS += -fPIC $(shell root-config --ldflags --cflags --libs) ${LDEXTRA} TGTS := writeMemoryFile libDicts.so @@ -40,12 +43,6 @@ echo: ################################################################ -# Should be a lib, really -ABOVE_OBJS := $(patsubst %, ../%.o, Config Matrix Hit Track ) - -${ABOVE_OBJS}: - ${MAKE} -C .. - SRCS := $(wildcard *.cc) HDRS := $(wildcard *.h) @@ -57,11 +54,11 @@ ALLOBJS := ${OBJS} ${ABOVE_OBJS} libDicts.so: DictsDict.cc ${CXX} $(LDFLAGS) -Wno-deprecated -shared DictsDict.cc -o $@ -DictsDict.cc: - @rootcint -v3 -f DictsDict.cc -c -p DictsLinkDef.h +DictsDict.cc: DictsLinkDef.h + @rootcint -v3 -f $@ -c -p $< writeMemoryFile: ${OBJS} libDicts.so - ${CXX} ${CXXFLAGS} ${LDFLAGS} ${ALLOBJS} -L./ -lDicts -o $@ + ${CXX} ${CXXFLAGS} ${LDFLAGS} ${ALLOBJS} -L. -lDicts -L.. -lMicCore -Wl,-rpath=..,-rpath=. -o $@ ${OBJS}: %.o: %.cc diff --git a/tkNtuple/WriteMemoryFile.cc b/tkNtuple/WriteMemoryFile.cc index 363fe125033b9..2c04a8f1ca962 100644 --- a/tkNtuple/WriteMemoryFile.cc +++ b/tkNtuple/WriteMemoryFile.cc @@ -2,7 +2,9 @@ #include "TTree.h" #include -#include "Track.h" +#include "Event.h" + +constexpr int VERBOSE = 1; enum struct TkLayout {phase0 = 0, phase1 = 1}; @@ -140,27 +142,35 @@ class LayerNumberConverter { bool useMatched = false; -int main() { +int main(int argc, char *argv[]) +{ + if (argc != 3) + { + fprintf(stderr, "Usage: %s \n", argv[0]); + exit(1); + } using namespace std; LayerNumberConverter lnc(TkLayout::phase1); const unsigned int nTotalLayers = lnc.nLayers(); + Config::nTotalLayers = lnc.nLayers(); long long maxevt = 0; int nstot = 0; std::vector nhitstot(nTotalLayers, 0); - TString outfilename = ""; - - TFile* f = TFile::Open("./ntuple_input.root"); maxevt = 1000;outfilename = "cmssw_output.bin"; + TFile* f = TFile::Open(argv[1]); + if (f == 0) + { + fprintf(stderr, "Failed opening input root file '%s'\n", argv[1]); + exit(1); + } + maxevt = 1000; TTree* t = (TTree*) f->Get("trackingNtuple/tree"); - FILE * fp; - fp = fopen (outfilename.Data(), "wb"); - unsigned long long event; t->SetBranchAddress("event",&event); @@ -392,13 +402,17 @@ int main() { vector >* str_chargeFraction = 0; t->SetBranchAddress("str_chargeFraction", &str_chargeFraction); + long long totentries = t->GetEntries(); + long long savedEvents = 0; - fwrite(&maxevt, sizeof(int), 1, fp); + DataFile data_file; + data_file.OpenWrite(std::string(argv[2]), std::min(maxevt, totentries)); - long long totentries = t->GetEntries(); + Event EE(0); - long long savedEvents = 0; - for (long long i = 0; savedEvents < maxevt && i simTracks_; + vector &simTracks_ = EE.simTracks_; vector simTrackIdx_(sim_q->size(),-1);//keep track of original index in ntuple vector seedSimIdx(see_q->size(),-1); for (int isim = 0; isim < sim_q->size(); ++isim) { @@ -443,31 +457,31 @@ int main() { auto const ihType = HitType(hitTypes[ihit]); switch (ihType){ - case HitType::Pixel:{ - int ipix = ihIdx; - if (ipix<0) continue; - int cmsswlay = lnc.convertLayerNumber(pix_det->at(ipix),pix_lay->at(ipix),useMatched,-1,pix_z->at(ipix)>0); - if (cmsswlay>=0 && cmsswlayat(istr),str_lay->at(istr),useMatched,str_isStereo->at(istr),str_z->at(istr)>0); - if (cmsswlay>=0 && cmsswlayat(ipix),pix_lay->at(ipix),useMatched,-1,pix_z->at(ipix)>0); + if (cmsswlay>=0 && cmsswlayat(istr),str_lay->at(istr),useMatched,str_isStereo->at(istr),str_z->at(istr)>0); + if (cmsswlay>=0 && cmsswlayat(iglu),glu_lay->at(iglu),useMatched,-1,glu_z->at(iglu)>0); if (cmsswlay>=0 && cmsswlay0) nlay++; @@ -508,7 +522,7 @@ int main() { //if (simTracks_.size()<2) continue; - vector seedTracks_; + vector &seedTracks_ = EE.seedTracks_; vector > pixHitSeedIdx(pix_lay->size()); for (int is = 0; issize(); ++is) { if (TrackAlgorithm(see_algo->at(is))!=TrackAlgorithm::initialStep) continue;//select seed in acceptance @@ -637,8 +651,8 @@ int main() { - vector > layerHits_; - vector simHitsInfo_; + vector > &layerHits_ = EE.layerHits_; + vector &simHitsInfo_ = EE.simHitsInfo_; int totHits = 0; layerHits_.resize(nTotalLayers); for (int ipix = 0; ipix < pix_lay->size(); ++ipix) { @@ -733,71 +747,66 @@ int main() { // bool allTracksAllHits = true; for (int i=0;i Date: Mon, 5 Jun 2017 10:51:11 -0700 Subject: [PATCH 063/172] Whitespace. --- mkFit/mkFit.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mkFit/mkFit.cc b/mkFit/mkFit.cc index 46dbb5d929cc4..7ef6a2414237f 100644 --- a/mkFit/mkFit.cc +++ b/mkFit/mkFit.cc @@ -229,7 +229,7 @@ void test_standard() #if USE_CUDA tbb::task_scheduler_init tbb_init(Config::numThreadsFinder); //tbb::task_scheduler_init tbb_init(tbb::task_scheduler_init::automatic); - + //omp_set_num_threads(Config::numThreadsFinder); // fittest time. Sum of all events. In case of multiple events // being run simultaneously in different streams this time will @@ -255,7 +255,7 @@ void test_standard() // CUDA function. These function can be changed to another one // if it becomes important to time (e.g. if you want the profiler to // tell you how much time is spend running cudaDeviceSynchronize(), - // use another function). + // use another function). separate_first_call_for_meaningful_profiling_numbers(); if (g_run_fit_std) runAllEventsFittingTestPlexGPU(events); @@ -480,7 +480,7 @@ int main(int argc, const char *argv[]) " --cf-fitting enable CF in fitting (def: %s)\n" " --root-val enable ROOT based validation for building [eff, FR, DR] (def: %s)\n" " --fit-val enable ROOT based validation for fitting (def: %s)\n" - " --inc-shorts include short reco tracks into FR (def: %s)\n" + " --inc-shorts include short reco tracks into FR (def: %s)\n" " --silent suppress printouts inside event loop (def: %s)\n" " --write write simulation to file and exit\n" " --read read simulation from file\n" From e95a7d0271e6d2d5e2cef15ed11bccac1d7657e2 Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Mon, 5 Jun 2017 10:52:00 -0700 Subject: [PATCH 064/172] Add missing branch variable initializers. --- tkNtuple/Makefile | 42 ++++++++++++--------------------- tkNtuple/WriteMemoryFile.cc | 47 ++++++++++++++++++++----------------- 2 files changed, 40 insertions(+), 49 deletions(-) diff --git a/tkNtuple/Makefile b/tkNtuple/Makefile index 62e8abf821f69..b844f8839028a 100644 --- a/tkNtuple/Makefile +++ b/tkNtuple/Makefile @@ -1,27 +1,22 @@ -include ../Makefile.config +ifndef ROOTSYS +$(error ROOTSYS is not set. Please set ROOT environment properly) +endif -# Overide debug settings -# OPT := -O0 -g +include ../Makefile.config .PHONY: all clean distclean echo -ifndef ROOTSYS -all: - @echo "ROOTSYS is not set. Please set ROOT environment properly"; echo -else all: default CPPEXTRA := -I.. ${USER_CPPFLAGS} ${DEFS} LDEXTRA := ${USER_LDFLAGS} -CPPFLAGS := $(shell root-config --cflags) ${CPPEXTRA} ${CPPFLAGS} -CXXFLAGS += -fPIC ${USER_CXXFLAGS} -LDFLAGS += -fPIC $(shell root-config --ldflags --cflags --libs) ${LDEXTRA} +CPPFLAGS := -I${ROOTSYS}/include ${CPPEXTRA} ${CPPFLAGS} +CXXFLAGS += ${USER_CXXFLAGS} +LDFLAGS += -L${ROOTSYS}/lib -lCore -lRIO -lTree -lMathCore ${LDEXTRA} -TGTS := writeMemoryFile libDicts.so - -EXES := ${TGTS} +EXES := writeMemoryFile default: ${EXES} @@ -43,25 +38,18 @@ echo: ################################################################ -SRCS := $(wildcard *.cc) -HDRS := $(wildcard *.h) +SRCS := WriteMemoryFile.cc OBJS := $(SRCS:.cc=.o) -OBJS := $(filter-out DictsDict.o, $(OBJS)) - -ALLOBJS := ${OBJS} ${ABOVE_OBJS} -libDicts.so: DictsDict.cc - ${CXX} $(LDFLAGS) -Wno-deprecated -shared DictsDict.cc -o $@ +#libDicts.so: DictsDict.o +# ${CXX} ${CXXFLAGS} ${LDFLAGS} $< -shared -o $@ ${LDFLAGS_HOST} DictsDict.cc: DictsLinkDef.h - @rootcint -v3 -f $@ -c -p $< - -writeMemoryFile: ${OBJS} libDicts.so - ${CXX} ${CXXFLAGS} ${LDFLAGS} ${ALLOBJS} -L. -lDicts -L.. -lMicCore -Wl,-rpath=..,-rpath=. -o $@ + rootcint -v3 -f $@ -c -p $< +writeMemoryFile: ${OBJS} DictsDict.o + ${CXX} ${CXXFLAGS} ${LDFLAGS} $^ -L.. -lMicCore -Wl,-rpath=..,-rpath=. -o $@ -${OBJS}: %.o: %.cc +%.o: %.cc ${CXX} ${CPPFLAGS} ${CXXFLAGS} -c -o $@ $< -endif - diff --git a/tkNtuple/WriteMemoryFile.cc b/tkNtuple/WriteMemoryFile.cc index 2c04a8f1ca962..4fd27d1f4213d 100644 --- a/tkNtuple/WriteMemoryFile.cc +++ b/tkNtuple/WriteMemoryFile.cc @@ -4,7 +4,7 @@ #include #include "Event.h" -constexpr int VERBOSE = 1; +constexpr int VERBOSE = 0; enum struct TkLayout {phase0 = 0, phase1 = 1}; @@ -192,24 +192,24 @@ int main(int argc, char *argv[]) t->SetBranchAddress("sim_trkIdx", &sim_trkIdx); //simvtx - std::vector* simvtx_x; - std::vector* simvtx_y; - std::vector* simvtx_z; + std::vector* simvtx_x = 0; + std::vector* simvtx_y = 0; + std::vector* simvtx_z = 0; t->SetBranchAddress("simvtx_x" , &simvtx_x); t->SetBranchAddress("simvtx_y" , &simvtx_y); t->SetBranchAddress("simvtx_z" , &simvtx_z); //simhit - std::vector* simhit_process; - std::vector* simhit_particle; - std::vector* simhit_simTrkIdx; - std::vector* simhit_x; - std::vector* simhit_y; - std::vector* simhit_z; - std::vector* simhit_px; - std::vector* simhit_py; - std::vector* simhit_pz; + std::vector* simhit_process = 0; + std::vector* simhit_particle = 0; + std::vector* simhit_simTrkIdx = 0; + std::vector* simhit_x = 0; + std::vector* simhit_y = 0; + std::vector* simhit_z = 0; + std::vector* simhit_px = 0; + std::vector* simhit_py = 0; + std::vector* simhit_pz = 0; t->SetBranchAddress("simhit_process", &simhit_process); t->SetBranchAddress("simhit_particle", &simhit_particle); t->SetBranchAddress("simhit_simTrkIdx", &simhit_simTrkIdx); @@ -410,6 +410,8 @@ int main(int argc, char *argv[]) Event EE(0); + // gDebug = 8; + for (long long i = 0; savedEvents < maxevt && i Date: Mon, 5 Jun 2017 11:40:16 -0700 Subject: [PATCH 065/172] Add support for extra sections in DataFile. Enum ExtraSection in DataFile. Current options: SimTrackStates, Seeds. New field in DataFileHeader (bitwise or of sections). Passed to DataFile::OpenWrite(). Fix Event::write_out()/read_in() to use section info instead of Config variables to determine what to write/read. --- Event.cc | 19 ++++++++++++++----- Event.h | 13 ++++++++++++- mkFit/mkFit.cc | 8 +++++++- tkNtuple/WriteMemoryFile.cc | 2 +- 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/Event.cc b/Event.cc index a59cda086cc2c..a739eb6112bda 100644 --- a/Event.cc +++ b/Event.cc @@ -382,7 +382,7 @@ void Event::write_out(DataFile &data_file) fwrite(&simTracks_[0], sizeof(Track), nt, fp); evsize += sizeof(int) + nt*sizeof(Track); - if (Config::root_val || Config::fit_val) { + if (data_file.HasSimTrackStates()) { int nts = simTrackStates_.size(); fwrite(&nts, sizeof(int), 1, fp); fwrite(&simTrackStates_[0], sizeof(TrackState), nts, fp); @@ -404,7 +404,7 @@ void Event::write_out(DataFile &data_file) fwrite(&simHitsInfo_[0], sizeof(MCHitInfo), nm, fp); evsize += sizeof(int) + nm*sizeof(MCHitInfo); - if (Config::useCMSGeom || Config::readCmsswSeeds) { + if (data_file.HasSeeds()) { int ns = seedTracks_.size(); fwrite(&ns, sizeof(int), 1, fp); fwrite(&seedTracks_[0], sizeof(Track), ns, fp); @@ -466,7 +466,7 @@ void Event::read_in(DataFile &data_file) } Config::nTracks = nt; - if (Config::root_val || Config::fit_val) + if (data_file.HasSimTrackStates()) { int nts; fread(&nts, sizeof(int), 1, fp); @@ -489,7 +489,7 @@ void Event::read_in(DataFile &data_file) simHitsInfo_.resize(nm); fread(&simHitsInfo_[0], sizeof(MCHitInfo), nm, fp); - if (Config::useCMSGeom || Config::readCmsswSeeds) { + if (data_file.HasSeeds()) { int ns; fread(&ns, sizeof(int), 1, fp); if (Config::readCmsswSeeds) @@ -696,16 +696,25 @@ int DataFile::OpenRead(const std::string& fname, bool set_n_layers) printf("Opened file '%s', format version %d, n_max_trk_hits %d, n_layers %d, n_events %d\n", fname.c_str(), f_header.f_format_version, f_header.f_n_max_trk_hits, f_header.f_n_layers, f_header.f_n_events); + if (f_header.f_extra_sections) + { + printf(" Extra sections:"); + if (f_header.f_extra_sections & ES_SimTrackStates) printf(" SimTrackStates"); + if (f_header.f_extra_sections & ES_Seeds) printf(" Seeds"); + printf("\n"); + } return f_header.f_n_events; } -void DataFile::OpenWrite(const std::string& fname, int nev) +void DataFile::OpenWrite(const std::string& fname, int nev, int extra_sections) { f_fp = fopen(fname.c_str(), "w"); f_header.f_n_events = nev; + f_header.f_extra_sections = extra_sections; + fwrite(&f_header, sizeof(DataFileHeader), 1, f_fp); } diff --git a/Event.h b/Event.h index a0ea764649e0d..a0a0d68a29064 100644 --- a/Event.h +++ b/Event.h @@ -76,6 +76,8 @@ struct DataFileHeader int f_n_layers = -1; int f_n_events = -1; + int f_extra_sections = 0; + DataFileHeader() { f_n_layers = Config::nTotalLayers; @@ -84,12 +86,21 @@ struct DataFileHeader struct DataFile { + enum ExtraSection + { + ES_SimTrackStates = 0x1, + ES_Seeds = 0x2 + }; + FILE *f_fp = 0; DataFileHeader f_header; + bool HasSimTrackStates() const { return f_header.f_extra_sections & ES_SimTrackStates; } + bool HasSeeds() const { return f_header.f_extra_sections & ES_Seeds; } + int OpenRead (const std::string& fname, bool set_n_layers = false); - void OpenWrite(const std::string& fname, int nev); + void OpenWrite(const std::string& fname, int nev, int extra_sections=0); void Close(); }; diff --git a/mkFit/mkFit.cc b/mkFit/mkFit.cc index 7ef6a2414237f..0c745f59486ba 100644 --- a/mkFit/mkFit.cc +++ b/mkFit/mkFit.cc @@ -147,8 +147,14 @@ void generate_and_save_tracks() initGeom(geom); std::unique_ptr val(Validation::make_validation("empty.root")); + int extra_sections = 0; + if (Config::root_val || Config::fit_val) + { + extra_sections |= DataFile::ES_SimTrackStates; + } + DataFile data_file; - data_file.OpenWrite(g_file_name, Nevents); + data_file.OpenWrite(g_file_name, Nevents, extra_sections); printf("writing %i events\n", Nevents); diff --git a/tkNtuple/WriteMemoryFile.cc b/tkNtuple/WriteMemoryFile.cc index 4fd27d1f4213d..3d220cd768d49 100644 --- a/tkNtuple/WriteMemoryFile.cc +++ b/tkNtuple/WriteMemoryFile.cc @@ -406,7 +406,7 @@ int main(int argc, char *argv[]) long long savedEvents = 0; DataFile data_file; - data_file.OpenWrite(std::string(argv[2]), std::min(maxevt, totentries)); + data_file.OpenWrite(std::string(argv[2]), std::min(maxevt, totentries), DataFile::ES_Seeds); Event EE(0); From 31e11ff9b582418fee782e8b1f8342131159650b Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Fri, 9 Jun 2017 11:02:45 -0700 Subject: [PATCH 066/172] Introduce MkFinder - a splice off MkFitter. MkFitter was becoming unwieldy plus there was the assumption of all tracks having the same number of hits which is not true in endcap building. This is a partial conversion and there is some repetiotion of the code. BestHit finding already uses the MkFinder, Std and CE use the old code. --- TTreeValidation.cc | 34 +-- Track.h | 101 +++---- mkFit/HitStructures.h | 5 +- mkFit/MkBase.h | 36 +++ mkFit/MkBuilder.cc | 133 +++++---- mkFit/MkBuilder.h | 9 +- mkFit/MkFinder.cc | 574 ++++++++++++++++++++++++++++++++++++ mkFit/MkFinder.h | 158 ++++++++++ mkFit/MkFitter.cc | 43 +-- mkFit/MkFitter.h | 20 +- mkFit/PropagationMPlex.h | 1 - mkFit/SteeringParams.h | 41 ++- mkFit/mkFit.cc | 6 +- tkNtuple/WriteMemoryFile.cc | 2 +- 14 files changed, 962 insertions(+), 201 deletions(-) create mode 100644 mkFit/MkBase.h create mode 100644 mkFit/MkFinder.cc create mode 100644 mkFit/MkFinder.h diff --git a/TTreeValidation.cc b/TTreeValidation.cc index 77552e09ef957..9fd21a92e2b6c 100644 --- a/TTreeValidation.cc +++ b/TTreeValidation.cc @@ -676,7 +676,7 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) phi_mc_gen_eff_ = simtrack.momPhi(); eta_mc_gen_eff_ = simtrack.momEta(); nHits_mc_eff_ = simtrack.nFoundHits(); // could be that the sim track skips layers! - lastlyr_mc_eff_ = simtrack.getLastGoodHitLyr(); + lastlyr_mc_eff_ = simtrack.getLastFoundHitLyr(); // matched seed track if (simToSeedMap_.count(mcID_eff_)) // recoToSim match : save best match --> most hits, lowest chi2, i.e. simToSeedMap_[matched SimID][first element in vector] @@ -707,7 +707,7 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) } // last hit info - const Hit& lasthit = evt_layer_hits[seedtrack.getLastGoodHitLyr()][seedtrack.getLastGoodHitIdx()]; + const Hit& lasthit = evt_layer_hits[seedtrack.getLastFoundHitLyr()][seedtrack.getLastFoundHitIdx()]; xhit_seed_eff_ = lasthit.x(); yhit_seed_eff_ = lasthit.y(); zhit_seed_eff_ = lasthit.z(); @@ -723,7 +723,7 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) nHits_seed_eff_ = seedtrack.nFoundHits(); nHitsMatched_seed_eff_ = seedextra.nHitsMatched(); fracHitsMatched_seed_eff_ = seedextra.fracHitsMatched(); - lastlyr_seed_eff_ = seedtrack.getLastGoodHitLyr(); + lastlyr_seed_eff_ = seedtrack.getLastFoundHitLyr(); hitchi2_seed_eff_ = seedtrack.chi2(); // currently not being used @@ -773,7 +773,7 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) seedID_build_eff_ = buildextra.seedID(); // use this to access correct sim track layer params - const int mcHitID = TTreeValidation::getLastGoodHit(buildtrack.getLastGoodMCHitID(evt_layer_hits),mcID_eff_,ev); + const int mcHitID = TTreeValidation::getLastFoundHit(buildtrack.getLastGoodMCHitID(evt_layer_hits),mcID_eff_,ev); if (mcHitID >= 0) { const TrackState & initLayTS = evt_sim_trackstates[mcHitID]; @@ -792,7 +792,7 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) } // last hit info - const Hit& lasthit = evt_layer_hits[buildtrack.getLastGoodHitLyr()][buildtrack.getLastGoodHitIdx()]; + const Hit& lasthit = evt_layer_hits[buildtrack.getLastFoundHitLyr()][buildtrack.getLastFoundHitIdx()]; xhit_build_eff_ = lasthit.x(); yhit_build_eff_ = lasthit.y(); zhit_build_eff_ = lasthit.z(); @@ -807,7 +807,7 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) nHits_build_eff_ = buildtrack.nFoundHits(); nHitsMatched_build_eff_ = buildextra.nHitsMatched(); fracHitsMatched_build_eff_ = buildextra.fracHitsMatched(); - lastlyr_build_eff_ = buildtrack.getLastGoodHitLyr(); + lastlyr_build_eff_ = buildtrack.getLastFoundHitLyr(); hitchi2_build_eff_ = buildtrack.chi2(); @@ -876,7 +876,7 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) } // last hit info - const Hit& lasthit = evt_layer_hits[fittrack.getLastGoodHitLyr()][fittrack.getLastGoodHitIdx()]; + const Hit& lasthit = evt_layer_hits[fittrack.getLastFoundHitLyr()][fittrack.getLastFoundHitIdx()]; xhit_fit_eff_ = lasthit.x(); yhit_fit_eff_ = lasthit.y(); zhit_fit_eff_ = lasthit.z(); @@ -892,7 +892,7 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) nHits_fit_eff_ = fittrack.nFoundHits(); nHitsMatched_fit_eff_ = fitextra.nHitsMatched(); fracHitsMatched_fit_eff_ = fitextra.fracHitsMatched(); - lastlyr_fit_eff_ = fittrack.getLastGoodHitLyr(); + lastlyr_fit_eff_ = fittrack.getLastFoundHitLyr(); hitchi2_fit_eff_ = -10; //fittrack.chi2(); // currently not being used @@ -961,7 +961,7 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) seedmask_seed_FR_ = 1; // automatically set to 1, because at the moment no cuts on seeds after conformal+KF fit. seed triplets filtered by RZ chi2 before fitting. // last hit info - const Hit& lasthit = evt_layer_hits[seedtrack.getLastGoodHitLyr()][seedtrack.getLastGoodHitIdx()]; + const Hit& lasthit = evt_layer_hits[seedtrack.getLastFoundHitLyr()][seedtrack.getLastFoundHitIdx()]; xhit_seed_FR_ = lasthit.x(); yhit_seed_FR_ = lasthit.y(); zhit_seed_FR_ = lasthit.z(); @@ -976,7 +976,7 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) nHits_seed_FR_ = seedtrack.nFoundHits(); nHitsMatched_seed_FR_ = seedextra.nHitsMatched(); fracHitsMatched_seed_FR_ = seedextra.fracHitsMatched(); - lastlyr_seed_FR_ = seedtrack.getLastGoodHitLyr(); + lastlyr_seed_FR_ = seedtrack.getLastFoundHitLyr(); hitchi2_seed_FR_ = seedtrack.chi2(); //--> not currently used @@ -1022,7 +1022,7 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) } nHits_mc_seed_FR_ = simtrack.nFoundHits(); - lastlyr_mc_seed_FR_ = simtrack.getLastGoodHitLyr(); + lastlyr_mc_seed_FR_ = simtrack.getLastFoundHitLyr(); duplmask_seed_FR_ = seedextra.isDuplicate(); iTkMatches_seed_FR_ = seedextra.duplicateID(); // ith duplicate seed track, i = 0 "best" match, i > 0 "still matched, real reco, not as good as i-1 track" @@ -1053,7 +1053,7 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) auto& buildextra = evt_build_extras[buildtrack.label()]; // last hit info - const Hit& lasthit = evt_layer_hits[buildtrack.getLastGoodHitLyr()][buildtrack.getLastGoodHitIdx()]; + const Hit& lasthit = evt_layer_hits[buildtrack.getLastFoundHitLyr()][buildtrack.getLastFoundHitIdx()]; xhit_build_FR_ = lasthit.x(); yhit_build_FR_ = lasthit.y(); zhit_build_FR_ = lasthit.z(); @@ -1068,7 +1068,7 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) nHits_build_FR_ = buildtrack.nFoundHits(); nHitsMatched_build_FR_ = buildextra.nHitsMatched(); fracHitsMatched_build_FR_ = buildextra.fracHitsMatched(); - lastlyr_build_FR_ = buildtrack.getLastGoodHitLyr(); + lastlyr_build_FR_ = buildtrack.getLastFoundHitLyr(); hitchi2_build_FR_ = buildtrack.chi2(); @@ -1114,7 +1114,7 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) } nHits_mc_build_FR_ = simtrack.nFoundHits(); - lastlyr_mc_build_FR_ = simtrack.getLastGoodHitLyr(); + lastlyr_mc_build_FR_ = simtrack.getLastFoundHitLyr(); duplmask_build_FR_ = buildextra.isDuplicate(); iTkMatches_build_FR_ = buildextra.duplicateID(); // ith duplicate build track, i = 0 "best" match, i > 0 "still matched, real reco, not as good as i-1 track" @@ -1184,7 +1184,7 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) auto& fitextra = evt_fit_extras[fittrack.label()]; // last hit info - const Hit& lasthit = evt_layer_hits[fittrack.getLastGoodHitLyr()][fittrack.getLastGoodHitIdx()]; + const Hit& lasthit = evt_layer_hits[fittrack.getLastFoundHitLyr()][fittrack.getLastFoundHitIdx()]; xhit_fit_FR_ = lasthit.x(); yhit_fit_FR_ = lasthit.y(); zhit_fit_FR_ = lasthit.z(); @@ -1199,7 +1199,7 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) nHits_fit_FR_ = fittrack.nFoundHits(); nHitsMatched_fit_FR_ = fitextra.nHitsMatched(); fracHitsMatched_fit_FR_ = fitextra.fracHitsMatched(); - lastlyr_fit_FR_ = fittrack.getLastGoodHitLyr(); + lastlyr_fit_FR_ = fittrack.getLastFoundHitLyr(); hitchi2_fit_FR_ = -10; //fittrack.chi2() --> currently not used @@ -1245,7 +1245,7 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) } nHits_mc_fit_FR_ = simtrack.nFoundHits(); - lastlyr_mc_fit_FR_ = simtrack.getLastGoodHitLyr(); + lastlyr_mc_fit_FR_ = simtrack.getLastFoundHitLyr(); duplmask_fit_FR_ = fitextra.isDuplicate(); iTkMatches_fit_FR_ = fitextra.duplicateID(); // ith duplicate fit track, i = 0 "best" match, i > 0 "still matched, real reco, not as good as i-1 track" diff --git a/Track.h b/Track.h index 2ee39105aa987..057f0617ceac9 100644 --- a/Track.h +++ b/Track.h @@ -118,18 +118,13 @@ class Track Track(const TrackState& state, float chi2, int label, int nHits, const HitOnTrack* hits) : state_(state), - chi2_(chi2), + chi2_ (chi2), label_(label) { for (int h = 0; h < nHits; ++h) { addHitIdx(hits[h].index, hits[h].layer, 0.0f); } - // XXXXMT Trying to take this out ... HOTs beyond the end should not be used. - // for (int h = nHits; h < Config::nMaxTrkHits; ++h) - // { - // setHitIdxLyr(h, -1, -1); - // } } Track(int charge, const SVector3& position, const SVector3& momentum, const SMatrixSym66& errors, float chi2) : @@ -164,9 +159,9 @@ class Track CUDA_CALLABLE int label() const {return label_;} - float x() const { return state_.parameters[0];} - float y() const { return state_.parameters[1];} - float z() const { return state_.parameters[2];} + float x() const { return state_.parameters[0]; } + float y() const { return state_.parameters[1]; } + float z() const { return state_.parameters[2]; } float posR() const { return getHypot(state_.parameters[0],state_.parameters[1]); } float posPhi() const { return getPhi(state_.parameters[0],state_.parameters[1]); } float posEta() const { return getEta(state_.parameters[0],state_.parameters[1],state_.parameters[2]); } @@ -199,7 +194,7 @@ class Track void mcHitIDsVec(const std::vector& globalHitVec, const MCHitInfoVec& globalMCHitInfo, std::vector& mcHitIDs) const { - for (int ihit = 0; ihit <= hitIdxPos_; ++ihit) { + for (int ihit = 0; ihit <= lastHitIdx_; ++ihit) { const HitOnTrack &hot = hitsOnTrk_[ihit]; if ((hot.index >= 0) && (hot.index < globalHitVec[hot.layer].size())) { @@ -216,18 +211,18 @@ class Track CUDA_CALLABLE void addHitIdx(int hitIdx, int hitLyr, float chi2) { - if (hitIdxPos_ >= Config::nMaxTrkHits - 1) return; + if (lastHitIdx_ >= Config::nMaxTrkHits - 1) return; - hitsOnTrk_[++hitIdxPos_] = { hitIdx, hitLyr }; - if (hitIdx >= 0) { ++nGoodHits_; chi2_+=chi2; } + hitsOnTrk_[++lastHitIdx_] = { hitIdx, hitLyr }; + if (hitIdx >= 0) { ++nFoundHits_; chi2_+=chi2; } } void addHitIdx(const HitOnTrack &hot, float chi2) { - if (hitIdxPos_ >= Config::nMaxTrkHits - 1) return; + if (lastHitIdx_ >= Config::nMaxTrkHits - 1) return; - hitsOnTrk_[++hitIdxPos_] = hot; - if (hot.index >= 0) { ++nGoodHits_; chi2_+=chi2; } + hitsOnTrk_[++lastHitIdx_] = hot; + if (hot.index >= 0) { ++nFoundHits_; chi2_+=chi2; } } HitOnTrack getHitOnTrack(int posHitIdx) const { return hitsOnTrk_[posHitIdx]; } @@ -236,31 +231,31 @@ class Track int getHitIdx(int posHitIdx) const { return hitsOnTrk_[posHitIdx].index; } int getHitLyr(int posHitIdx) const { return hitsOnTrk_[posHitIdx].layer; } - HitOnTrack getLastHitOnTrack() const { return hitsOnTrk_[hitIdxPos_]; } - int getLastHitIdx() const { return hitsOnTrk_[hitIdxPos_].index; } - int getLastHitLyr() const { return hitsOnTrk_[hitIdxPos_].layer; } + HitOnTrack getLastHitOnTrack() const { return hitsOnTrk_[lastHitIdx_]; } + int getLastHitIdx() const { return hitsOnTrk_[lastHitIdx_].index; } + int getLastHitLyr() const { return hitsOnTrk_[lastHitIdx_].layer; } - int getLastGoodHitPos() const + int getLastFoundHitPos() const { - int hi = hitIdxPos_; + int hi = lastHitIdx_; while (hitsOnTrk_[hi].index < 0) --hi; return hi; } - HitOnTrack getLastGoodHitOnTrack() const { return hitsOnTrk_[getLastGoodHitPos()]; } - int getLastGoodHitIdx() const { return hitsOnTrk_[getLastGoodHitPos()].index; } - int getLastGoodHitLyr() const { return hitsOnTrk_[getLastGoodHitPos()].layer; } + HitOnTrack getLastFoundHitOnTrack() const { return hitsOnTrk_[getLastFoundHitPos()]; } + int getLastFoundHitIdx() const { return hitsOnTrk_[getLastFoundHitPos()].index; } + int getLastFoundHitLyr() const { return hitsOnTrk_[getLastFoundHitPos()].layer; } int getLastGoodMCHitID(const std::vector& globalHitVec) const { - HitOnTrack hot = getLastGoodHitOnTrack(); + HitOnTrack hot = getLastFoundHitOnTrack(); return globalHitVec[hot.layer][hot.index].mcHitID(); } int getMCHitIDFromLayer(const std::vector& globalHitVec, int layer) const { int mcHitID = -1; - for (int ihit = 0; ihit <= hitIdxPos_; ++ihit) + for (int ihit = 0; ihit <= lastHitIdx_; ++ihit) { if (hitsOnTrk_[ihit].layer == layer) { @@ -272,9 +267,13 @@ class Track } const HitOnTrack* getHitsOnTrackArray() const { return hitsOnTrk_; } + const HitOnTrack* BeginHitsOnTrack() const { return hitsOnTrk_; } + const HitOnTrack* EndHitsOnTrack() const { return & hitsOnTrk_[lastHitIdx_ + 1]; } + + HitOnTrack* BeginHitsOnTrack_nc() { return hitsOnTrk_; } void fillEmptyLayers() { - for (int h = hitIdxPos_ + 1; h < Config::nMaxTrkHits; h++) { + for (int h = lastHitIdx_ + 1; h < Config::nMaxTrkHits; h++) { setHitIdxLyr(h, -1, -1); } } @@ -289,30 +288,27 @@ class Track hitsOnTrk_[posHitIdx] = { newIdx, newLyr }; } - void setNGoodHits() { - nGoodHits_=0; - for (int i = 0; i <= hitIdxPos_; i++) { - if (hitsOnTrk_[i].index >= 0) nGoodHits_++; + void setNFoundHits() { + nFoundHits_=0; + for (int i = 0; i <= lastHitIdx_; i++) { + if (hitsOnTrk_[i].index >= 0) nFoundHits_++; } } CUDA_CALLABLE - void setNGoodHits(int nHits) { - nGoodHits_ = nHits; - } + void setNFoundHits(int nHits) { nFoundHits_ = nHits; } + void setNTotalHits(int nHits) { lastHitIdx_ = nHits - 1; } CUDA_CALLABLE - void resetHits() - { - hitIdxPos_ = -1; - nGoodHits_ = 0; - } - int nFoundHits() const { return nGoodHits_; } - int nTotalHits() const { return hitIdxPos_+1; } + void resetHits() { lastHitIdx_ = -1; nFoundHits_ = 0; } + + int nFoundHits() const { return nFoundHits_; } + int nTotalHits() const { return lastHitIdx_+1; } - const std::vector foundLayers() const { + const std::vector foundLayers() const + { std::vector layers; - for (int ihit = 0; ihit <= hitIdxPos_ ; ++ihit){ + for (int ihit = 0; ihit <= lastHitIdx_; ++ihit) { if (hitsOnTrk_[ihit].index >= 0) { layers.push_back( hitsOnTrk_[ihit].layer ); } @@ -321,26 +317,27 @@ class Track } CUDA_CALLABLE - void setCharge(int chg) {state_.charge=chg;} + void setCharge(int chg) { state_.charge = chg; } CUDA_CALLABLE - void setChi2(float chi2) {chi2_=chi2;} + void setChi2(float chi2) { chi2_ = chi2; } CUDA_CALLABLE - void setLabel(int lbl) {label_=lbl;} + void setLabel(int lbl) { label_ = lbl; } - void setState(const TrackState& newState) {state_=newState;} + void setState(const TrackState& newState) { state_ = newState; } Track clone() const { return Track(state_,chi2_,label_,nTotalHits(),hitsOnTrk_); } private: TrackState state_; - float chi2_ = 0.; - int hitIdxPos_ = -1; - int nGoodHits_ = 0; - int label_ = -1; + float chi2_ = 0.; + int lastHitIdx_ = -1; + int nFoundHits_ = 0; + int label_ = -1; HitOnTrack hitsOnTrk_[Config::nMaxTrkHits]; }; -typedef std::vector TrackVec; +typedef std::vector TrackVec; +typedef std::vector TrackVecVec; class TrackExtra { diff --git a/mkFit/HitStructures.h b/mkFit/HitStructures.h index 0b25dd5c6415d..71f29ffb21c3d 100644 --- a/mkFit/HitStructures.h +++ b/mkFit/HitStructures.h @@ -81,8 +81,9 @@ class LayerOfHits int m_nq = 0; int m_capacity = 0; - int layer_id() const { return m_layer_info->m_layer_id; } - bool is_barrel() const { return m_layer_info->is_barrel(); } + int layer_id() const { return m_layer_info->m_layer_id; } + bool is_barrel() const { return m_layer_info->is_barrel(); } + bool is_endcap() const { return ! m_layer_info->is_barrel(); } float min_dphi() const { return m_layer_info->m_select_min_dphi; } float max_dphi() const { return m_layer_info->m_select_max_dphi; } diff --git a/mkFit/MkBase.h b/mkFit/MkBase.h new file mode 100644 index 0000000000000..313392669144d --- /dev/null +++ b/mkFit/MkBase.h @@ -0,0 +1,36 @@ +#ifndef MkBase_h +#define MkBase_h + +#include "Matrix.h" + +#include "PropagationMPlex.h" + +struct MkBase +{ + MPlexLS Err[2]; + MPlexLV Par[2]; + + MPlexQI Chg; + + static constexpr int iC = 0; // current + static constexpr int iP = 1; // propagated + + //---------------------------------------------------------------------------- + + MkBase() {} + + void PropagateTracksToR(float R, const int N_proc) + { + propagateHelixToRMPlex(Err[iC], Par[iC], Chg, R, + Err[iP], Par[iP], N_proc); + } + + void PropagateTracksToZ(float Z, const int N_proc) + { + propagateHelixToZMPlex(Err[iC], Par[iC], Chg, Z, + Err[iP], Par[iP], N_proc); + } + +}; + +#endif diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index 7f3935cc3ba74..4213ee2f8fd5c 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -6,8 +6,6 @@ #include "Event.h" #include "TrackerInfo.h" -#include "MkFitter.h" - //#define DEBUG #include "Debug.h" @@ -19,10 +17,15 @@ ExecutionContext g_exe_ctx; //------------------------------------------------------------------------------ +#define CLONER(_n_) std::unique_ptr _n_(g_exe_ctx.m_cloners.GetFromPool(), retcand) +#define FITTER(_n_) std::unique_ptr _n_(g_exe_ctx.m_fitters.GetFromPool(), retfitr) +#define FINDER(_n_) std::unique_ptr _n_(g_exe_ctx.m_finders.GetFromPool(), retfndr) + namespace { auto retcand = [](CandCloner* cloner) { g_exe_ctx.m_cloners.ReturnToPool(cloner); }; - auto retfitr = [](MkFitter* mkfp ) { g_exe_ctx.m_fitters.ReturnToPool(mkfp); }; + auto retfitr = [](MkFitter* mkfttr) { g_exe_ctx.m_fitters.ReturnToPool(mkfttr); }; + auto retfndr = [](MkFinder* mkfndr) { g_exe_ctx.m_finders.ReturnToPool(mkfndr); }; // Range of indices processed within one iteration of a TBB parallel_for. @@ -96,22 +99,22 @@ MkBuilder* MkBuilder::make_builder() #ifdef DEBUG namespace { - void pre_prop_print(int ilay, MkFitter* mkfp) { + void pre_prop_print(int ilay, MkFitter* mkfttr) { std::cout << "propagate to lay=" << ilay - << " start from x=" << mkfp->getPar(0, 0, 0) << " y=" << mkfp->getPar(0, 0, 1) << " z=" << mkfp->getPar(0, 0, 2) - << " r=" << getHypot(mkfp->getPar(0, 0, 0), mkfp->getPar(0, 0, 1)) - << " px=" << mkfp->getPar(0, 0, 3) << " py=" << mkfp->getPar(0, 0, 4) << " pz=" << mkfp->getPar(0, 0, 5) + << " start from x=" << mkfttr->getPar(0, 0, 0) << " y=" << mkfttr->getPar(0, 0, 1) << " z=" << mkfttr->getPar(0, 0, 2) + << " r=" << getHypot(mkfttr->getPar(0, 0, 0), mkfttr->getPar(0, 0, 1)) + << " px=" << mkfttr->getPar(0, 0, 3) << " py=" << mkfttr->getPar(0, 0, 4) << " pz=" << mkfttr->getPar(0, 0, 5) #ifdef CCSCOORD - << " pT=" << 1./mkfp->getPar(0, 0, 3) << std::endl; + << " pT=" << 1./mkfttr->getPar(0, 0, 3) << std::endl; #else - << " pT=" << getHypot(mkfp->getPar(0, 0, 3), mkfp->getPar(0, 0, 4)) << std::endl; + << " pT=" << getHypot(mkfttr->getPar(0, 0, 3), mkfttr->getPar(0, 0, 4)) << std::endl; #endif } - void post_prop_print(int ilay, MkFitter* mkfp) { + void post_prop_print(int ilay, MkFitter* mkfttr) { std::cout << "propagate to lay=" << ilay - << " arrive at x=" << mkfp->getPar(0, 1, 0) << " y=" << mkfp->getPar(0, 1, 1) << " z=" << mkfp->getPar(0, 1, 2) - << " r=" << getHypot(mkfp->getPar(0, 1, 0), mkfp->getPar(0, 1, 1)) << std::endl; + << " arrive at x=" << mkfttr->getPar(0, 1, 0) << " y=" << mkfttr->getPar(0, 1, 1) << " z=" << mkfttr->getPar(0, 1, 2) + << " r=" << getHypot(mkfttr->getPar(0, 1, 0), mkfttr->getPar(0, 1, 1)) << std::endl; } void print_seed(const Track& seed) { @@ -168,6 +171,8 @@ namespace // Constructor and destructor //------------------------------------------------------------------------------ +#include "KalmanUtilsMPlex.h" + MkBuilder::MkBuilder() : m_event(0), m_event_of_hits(Config::TrkInfo) @@ -176,9 +181,12 @@ MkBuilder::MkBuilder() : m_steering_params[TrackerInfo::Reg_Endcap_Neg] = { + computeChi2EndcapMPlex, + updateParametersEndcapMPlex, + &MkFinder::SelectHitIndicesEndcap, 21, &LayerInfo::m_next_ecap_neg, - &MkFitter::PropagateTracksToZ, + &MkBase::PropagateTracksToZ, &MkFitter::SelectHitIndicesEndcap, &MkFitter::AddBestHitEndcap, &MkFitter::UpdateWithLastHitEndcap, @@ -190,9 +198,12 @@ MkBuilder::MkBuilder() : m_steering_params[TrackerInfo::Reg_Barrel] = { + computeChi2MPlex, + updateParametersMPlex, + &MkFinder::SelectHitIndices, 3, &LayerInfo::m_next_barrel, - &MkFitter::PropagateTracksToR, + &MkBase::PropagateTracksToR, &MkFitter::SelectHitIndices, &MkFitter::AddBestHit, &MkFitter::UpdateWithLastHit, @@ -204,9 +215,12 @@ MkBuilder::MkBuilder() : m_steering_params[TrackerInfo::Reg_Endcap_Pos] = { + computeChi2EndcapMPlex, + updateParametersEndcapMPlex, + &MkFinder::SelectHitIndicesEndcap, 12, &LayerInfo::m_next_ecap_pos, - &MkFitter::PropagateTracksToZ, + &MkBase::PropagateTracksToZ, &MkFitter::SelectHitIndicesEndcap, &MkFitter::AddBestHitEndcap, &MkFitter::UpdateWithLastHitEndcap, @@ -561,7 +575,7 @@ void MkBuilder::fit_seeds() // printf("Seed info pos( x y z r; eta phi) mom( pt pz; eta phi)\n"); - std::unique_ptr mkfp(g_exe_ctx.m_fitters.GetFromPool(), retfitr); + FITTER( mkfttr ); RangeOfSeedIndices rng = rosi.seed_rng(blk_rng); @@ -608,14 +622,14 @@ void MkBuilder::fit_seeds() { dprintf("Breaking seed range due to different layer signature at %d (%d, %d)\n", i, rng.m_beg, rng.m_end); - fit_one_seed_set(seedtracks, rng.m_beg, i, mkfp.get(), is_brl, m_steering_params[reg]); + fit_one_seed_set(seedtracks, rng.m_beg, i, mkfttr.get(), is_brl, m_steering_params[reg]); rng.m_beg = i; goto layer_sig_change; } } - fit_one_seed_set(seedtracks, rng.m_beg, rng.m_end, mkfp.get(), is_brl, m_steering_params[reg]); + fit_one_seed_set(seedtracks, rng.m_beg, rng.m_end, mkfttr.get(), is_brl, m_steering_params[reg]); ++rng; } @@ -624,22 +638,22 @@ void MkBuilder::fit_seeds() } inline void MkBuilder::fit_one_seed_set(TrackVec& seedtracks, int itrack, int end, - MkFitter *mkfp, const bool is_brl[], + MkFitter *mkfttr, const bool is_brl[], const SteeringParams &st_par) { //debug=true; - mkfp->SetNhits(Config::nlayers_per_seed); - mkfp->InputTracksAndHits(seedtracks, m_event_of_hits.m_layers_of_hits, itrack, end); + mkfttr->SetNhits(Config::nlayers_per_seed); + mkfttr->InputTracksAndHits(seedtracks, m_event_of_hits.m_layers_of_hits, itrack, end); - if (Config::cf_seeding) mkfp->ConformalFitTracks(false, itrack, end); + if (Config::cf_seeding) mkfttr->ConformalFitTracks(false, itrack, end); if (Config::readCmsswSeeds == false) { - mkfp->FitTracksSteered(is_brl, end - itrack, m_event); + mkfttr->FitTracksSteered(is_brl, end - itrack, m_event); } - mkfp->OutputFittedTracksAndHitIdx(m_event->seedTracks_, itrack, end, false); + mkfttr->OutputFittedTracksAndHitIdx(m_event->seedTracks_, itrack, end, false); } //------------------------------------------------------------------------------ @@ -1051,7 +1065,7 @@ void MkBuilder::FindTracksBestHit() tbb::parallel_for(rosi.tbb_blk_rng_vec(), [&](const tbb::blocked_range& blk_rng) { - std::unique_ptr mkfp(g_exe_ctx.m_fitters.GetFromPool(), retfitr); + FINDER( mkfndr ); const TrackerInfo &trk_info = Config::TrkInfo; @@ -1061,9 +1075,7 @@ void MkBuilder::FindTracksBestHit() { dprint(std::endl << "processing track=" << rng.m_beg << ", label=" <SetNhits(n_hits); - mkfp->InputTracksAndHitIdx(cands, rng.m_beg, rng.m_end, false); + mkfndr->InputTracksAndHitIdx(cands, rng.m_beg, rng.m_end, false); // Loop over layers, starting from after the seed. // Consider inverting loop order and make layer outer, need to @@ -1075,30 +1087,28 @@ void MkBuilder::FindTracksBestHit() // XXX This should actually be done in some other thread for the next layer while // this thread is crunching the current one. - // For now it's done in MkFitter::AddBestHit(), two loops before the data is needed. + // For now it's done in MkFinder::AddBestHit(), two loops before the data is needed. // for (int i = 0; i < bunch_of_hits.m_size; ++i) // { // _mm_prefetch((char*) & bunch_of_hits.m_hits[i], _MM_HINT_T1); // } - dcall(pre_prop_print(ilay, mkfp.get())); + dcall(pre_prop_print(ilay, mkfndr.get())); - (mkfp.get()->*st_par.propagate_foo)(trk_info.m_layers[ilay].m_propagate_to, rng.n_proc()); + (mkfndr.get()->*st_par.propagate_foo)(trk_info.m_layers[ilay].m_propagate_to, rng.n_proc()); - dcall(post_prop_print(ilay, mkfp.get())); + dcall(post_prop_print(ilay, mkfndr.get())); - (mkfp.get()->*st_par.select_hits_foo)(layer_of_hits, rng.n_proc(), false); + (mkfndr.get()->*st_par.select_hit_idcs_foo)(layer_of_hits, rng.n_proc(), false); // #ifdef PRINTOUTS_FOR_PLOTS -// std::cout << "MX number of hits in window in layer " << ilay << " is " << mkfp->getXHitEnd(0, 0, 0)-mkfp->getXHitBegin(0, 0, 0) << std::endl; +// std::cout << "MX number of hits in window in layer " << ilay << " is " << mkfndr->getXHitEnd(0, 0, 0)-mkfndr->getXHitBegin(0, 0, 0) << std::endl; // #endif // make candidates with best hit dprint("make new candidates"); - (mkfp.get()->*st_par.add_best_hit_foo)(layer_of_hits, rng.n_proc()); - - mkfp->SetNhits(++n_hits); + mkfndr->AddBestHit(layer_of_hits, rng.n_proc(), st_par); if (layer_info.m_is_outer) { @@ -1108,7 +1118,7 @@ void MkBuilder::FindTracksBestHit() ilay = layer_info.*st_par.next_layer_doo; } // end of layer loop - mkfp->OutputFittedTracksAndHitIdx(cands, rng.m_beg, rng.m_end, false); + mkfndr->OutputTracksAndHitIdx(cands, rng.m_beg, rng.m_end, false); ++rng; } // end of loop over candidates in a tbb chunk @@ -1161,7 +1171,7 @@ void MkBuilder::FindTracksStandard() tbb::parallel_for(rosi.tbb_blk_rng_std(/*adaptiveSPT*/), [&](const tbb::blocked_range& seeds) { - std::unique_ptr mkfp(g_exe_ctx.m_fitters.GetFromPool(), retfitr); + FITTER( mkfndr ); const TrackerInfo &trk_info = Config::TrkInfo; @@ -1214,29 +1224,29 @@ void MkBuilder::FindTracksStandard() dprint("processing track=" << itrack); - mkfp->SetNhits(n_hits); //here again assuming one hit per layer + mkfndr->SetNhits(n_hits); //here again assuming one hit per layer //fixme find a way to deal only with the candidates needed in this thread - mkfp->InputTracksAndHitIdx(eoccs.m_candidates, + mkfndr->InputTracksAndHitIdx(eoccs.m_candidates, seed_cand_idx, itrack, end, false); //propagate to layer - dcall(pre_prop_print(ilay, mkfp.get())); + dcall(pre_prop_print(ilay, mkfndr.get())); - (mkfp.get()->*st_par.propagate_foo)(layer_info.m_propagate_to, end - itrack); + (mkfndr.get()->*st_par.propagate_foo)(layer_info.m_propagate_to, end - itrack); - dcall(post_prop_print(ilay, mkfp.get())); + dcall(post_prop_print(ilay, mkfndr.get())); dprint("now get hit range"); - (mkfp.get()->*st_par.select_hits_foo)(layer_of_hits, end - itrack, false); + (mkfndr.get()->*st_par.select_hits_foo)(layer_of_hits, end - itrack, false); //#ifdef PRINTOUTS_FOR_PLOTS - //std::cout << "MX number of hits in window in layer " << ilay << " is " << mkfp->getXHitEnd(0, 0, 0)-mkfp->getXHitBegin(0, 0, 0) << std::endl; + //std::cout << "MX number of hits in window in layer " << ilay << " is " << mkfndr->getXHitEnd(0, 0, 0)-mkfndr->getXHitBegin(0, 0, 0) << std::endl; //#endif dprint("make new candidates"); - (mkfp.get()->*st_par.find_cands_foo)(layer_of_hits, tmp_cands, start_seed, end - itrack); + (mkfndr.get()->*st_par.find_cands_foo)(layer_of_hits, tmp_cands, start_seed, end - itrack); } //end of vectorized loop @@ -1326,18 +1336,18 @@ void MkBuilder::FindTracksCloneEngine() tbb::parallel_for(rosi.tbb_blk_rng_std(/*adaptiveSPT*/), [&](const tbb::blocked_range& seeds) { - std::unique_ptr cloner(g_exe_ctx.m_cloners.GetFromPool(), retcand); - std::unique_ptr mkfp (g_exe_ctx.m_fitters.GetFromPool(), retfitr); + CLONER( cloner ); + FITTER( mkfndr ); // loop over layers - find_tracks_in_layers(*cloner, mkfp.get(), seeds.begin(), seeds.end(), region); + find_tracks_in_layers(*cloner, mkfndr.get(), seeds.begin(), seeds.end(), region); }); }); // debug = false; } -void MkBuilder::find_tracks_in_layers(CandCloner &cloner, MkFitter *mkfp, +void MkBuilder::find_tracks_in_layers(CandCloner &cloner, MkFitter *mkfndr, int start_seed, int end_seed, int region) { EventOfCombCandidates &eoccs = m_event_of_comb_cands; @@ -1426,33 +1436,34 @@ void MkBuilder::find_tracks_in_layers(CandCloner &cloner, MkFitter *mkfp, dprintf("\n"); #endif - mkfp->SetNhits(n_hits); + // YYYYYY + mkfndr->SetNhits(n_hits); - mkfp->InputTracksAndHitIdx(eoccs.m_candidates, seed_cand_idx, + mkfndr->InputTracksAndHitIdx(eoccs.m_candidates, seed_cand_idx, itrack, end, prev_ilay >= 0); #ifdef DEBUG for (int i=itrack; i < end; ++i) - dprintf(" track %d, idx %d is from seed %d\n", i, i - itrack, mkfp->Label(i - itrack,0,0)); + dprintf(" track %d, idx %d is from seed %d\n", i, i - itrack, mkfndr->Label(i - itrack,0,0)); dprintf("\n"); #endif if (prev_ilay >= 0) { const LayerOfHits &prev_layer_of_hits = m_event_of_hits.m_layers_of_hits[prev_ilay]; - (mkfp->*st_par.update_with_last_hit_foo)(prev_layer_of_hits, end - itrack); + (mkfndr->*st_par.update_with_last_hit_foo)(prev_layer_of_hits, end - itrack); } if (ilay >= 0) { // propagate to current layer - (mkfp->*st_par.propagate_foo)(layer_info.m_propagate_to, end - itrack); + (mkfndr->*st_par.propagate_foo)(layer_info.m_propagate_to, end - itrack); // copy_out the propagated track params, errors only (hit-idcs and chi2 already updated) - mkfp->CopyOutParErr(eoccs.m_candidates, end - itrack, true); + mkfndr->CopyOutParErr(eoccs.m_candidates, end - itrack, true); } else { // copy_out the updated track params, errors only (hit-idcs and chi2 already updated) - mkfp->CopyOutParErr(eoccs.m_candidates, end - itrack, false); + mkfndr->CopyOutParErr(eoccs.m_candidates, end - itrack, false); continue; } @@ -1460,16 +1471,16 @@ void MkBuilder::find_tracks_in_layers(CandCloner &cloner, MkFitter *mkfp, const LayerOfHits &layer_of_hits = m_event_of_hits.m_layers_of_hits[ilay]; - (mkfp->*st_par.select_hits_foo)(layer_of_hits, end - itrack, false); + (mkfndr->*st_par.select_hits_foo)(layer_of_hits, end - itrack, false); //#ifdef PRINTOUTS_FOR_PLOTS - //std::cout << "MX number of hits in window in layer " << ilay << " is " << mkfp->getXHitEnd(0, 0, 0)-mkfp->getXHitBegin(0, 0, 0) << std::endl; + //std::cout << "MX number of hits in window in layer " << ilay << " is " << mkfndr->getXHitEnd(0, 0, 0)-mkfndr->getXHitBegin(0, 0, 0) << std::endl; //#endif dprint("make new candidates"); cloner.begin_iteration(); - (mkfp->*st_par.find_cands_min_copy_foo)(layer_of_hits, cloner, start_seed, end - itrack); + (mkfndr->*st_par.find_cands_min_copy_foo)(layer_of_hits, cloner, start_seed, end - itrack); cloner.end_iteration(); } //end of vectorized loop diff --git a/mkFit/MkBuilder.h b/mkFit/MkBuilder.h index f7fb1f6e9ba5f..eda5f2f677c97 100644 --- a/mkFit/MkBuilder.h +++ b/mkFit/MkBuilder.h @@ -5,8 +5,9 @@ //------------------------------------------------------------------------------ -#include "MkFitter.h" #include "CandCloner.h" +#include "MkFitter.h" +#include "MkFinder.h" #include "SteeringParams.h" #include @@ -23,11 +24,13 @@ struct ExecutionContext { Pool m_cloners; Pool m_fitters; + Pool m_finders; void populate(int n_thr) { m_cloners.populate(n_thr - m_cloners.size()); m_fitters.populate(n_thr - m_fitters.size()); + m_finders.populate(n_thr - m_finders.size()); } }; @@ -42,7 +45,7 @@ class Event; class MkBuilder { protected: - void fit_one_seed_set(TrackVec& simtracks, int itrack, int end, MkFitter *mkfp, + void fit_one_seed_set(TrackVec& simtracks, int itrack, int end, MkFitter *mkfttr, const bool is_brl[], const SteeringParams &st_par); Event *m_event; @@ -95,7 +98,7 @@ class MkBuilder void find_tracks_load_seeds_BH(); // for FindTracksBestHit void find_tracks_load_seeds(); - void find_tracks_in_layers(CandCloner &cloner, MkFitter *mkfp, + void find_tracks_in_layers(CandCloner &cloner, MkFitter *mkfndr, int start_seed, int end_seed, int region); // -------- diff --git a/mkFit/MkFinder.cc b/mkFit/MkFinder.cc new file mode 100644 index 0000000000000..095271045e854 --- /dev/null +++ b/mkFit/MkFinder.cc @@ -0,0 +1,574 @@ +#include "MkFinder.h" + +#include "CandCloner.h" +#include "SteeringParams.h" + +#include "KalmanUtilsMPlex.h" + +//#define DEBUG +#include "Debug.h" + +//============================================================================== +// Input / Output TracksAndHitIdx +//============================================================================== + +void MkFinder::InputTracksAndHitIdx(const std::vector& tracks, + int beg, int end, bool inputProp) +{ + // Assign track parameters to initial state and copy hit values in. + + // This might not be true for the last chunk! + // assert(end - beg == NN); + + const int iI = inputProp ? iP : iC; + + int itrack = 0; + for (int i = beg; i < end; ++i, ++itrack) + { + copy_in(tracks[i], itrack, iI); + } +} + +void MkFinder::InputTracksAndHitIdx(const std::vector >& tracks, + const std::vector >& idxs, + int beg, int end, bool inputProp) +{ + // Assign track parameters to initial state and copy hit values in. + + // This might not be true for the last chunk! + // assert(end - beg == NN); + + const int iI = inputProp ? iP : iC; + + int itrack = 0; + for (int i = beg; i < end; ++i, ++itrack) + { + const Track &trk = tracks[idxs[i].first][idxs[i].second]; + + copy_in(trk, itrack, iI); + + SeedIdx(itrack, 0, 0) = idxs[i].first; + CandIdx(itrack, 0, 0) = idxs[i].second; + } +} + +void MkFinder::InputTracksAndHitIdx(const std::vector >& tracks, + const std::vector >& idxs, + int beg, int end, bool inputProp) +{ + // Assign track parameters to initial state and copy hit values in. + + // This might not be true for the last chunk! + // assert(end - beg == NN); + + const int iI = inputProp ? iP : iC; + + int itrack = 0; + for (int i = beg; i < end; ++i, ++itrack) + { + const Track &trk = tracks[idxs[i].first][idxs[i].second.trkIdx]; + + copy_in(trk, itrack, iI); + + SeedIdx(itrack, 0, 0) = idxs[i].first; + CandIdx(itrack, 0, 0) = idxs[i].second.trkIdx; + } +} + +void MkFinder::OutputTracksAndHitIdx(std::vector& tracks, + int beg, int end, bool outputProp) const +{ + // Copies requested track parameters into Track objects. + // The tracks vector should be resized to allow direct copying. + + const int iO = outputProp ? iP : iC; + + int itrack = 0; + for (int i = beg; i < end; ++i, ++itrack) + { + copy_out(tracks[i], itrack, iO); + } +} + + +//============================================================================== +// SelectHitIndices / SelectHitIndicesEndcap +//============================================================================== +// Those are harder to merge as we use z in barrel and r in endcap. +// Probably could separate out common part and have two functions that return +// q of the hit. + +void MkFinder::SelectHitIndices(const LayerOfHits &layer_of_hits, + const int N_proc, bool dump) +{ + // debug = 1; + // dump = true; + + const LayerOfHits &L = layer_of_hits; + const int iI = iP; + const float nSigmaPhi = 3; + const float nSigmaZ = 3; + + // Vectorizing this makes it run slower! + //#pragma ivdep + //#pragma simd + for (int itrack = 0; itrack < N_proc; ++itrack) + { + XHitSize[itrack] = 0; + + float z, phi, dz, dphi; + { + const float x = Par[iI].ConstAt(itrack, 0, 0); + const float y = Par[iI].ConstAt(itrack, 1, 0); + + const float r2 = x*x + y*y; + + z = Par[iI].ConstAt(itrack, 2, 0); + phi = getPhi(x, y); + dz = nSigmaZ * std::sqrt(Err[iI].ConstAt(itrack, 2, 2)); + + const float dphidx = -y/r2, dphidy = x/r2; + const float dphi2 = dphidx * dphidx * Err[iI].ConstAt(itrack, 0, 0) + + dphidy * dphidy * Err[iI].ConstAt(itrack, 1, 1) + + 2 * dphidx * dphidy * Err[iI].ConstAt(itrack, 0, 1); + +#ifdef HARD_CHECK + assert(dphi2 >= 0); +#endif + + dphi = nSigmaPhi * std::sqrt(std::abs(dphi2)); + + dphi = std::max(std::abs(dphi), L.min_dphi()); + dz = std::max(std::abs(dz), L.min_dq()); + + if (Config::useCMSGeom) + { + //now correct for bending and for layer thickness unsing linear approximation + const float deltaR = Config::cmsDeltaRad; //fixme! using constant value, to be taken from layer properties + const float r = std::sqrt(r2); +#ifdef CCSCOORD + //here alpha is the difference between posPhi and momPhi + const float alpha = phi - Par[iP].ConstAt(itrack, 4, 0); + float cosA, sinA; + if (Config::useTrigApprox) { + sincos4(alpha, sinA, cosA); + } else { + cosA = std::cos(alpha); + sinA = std::sin(alpha); + } +#else + const float px = Par[iP].ConstAt(itrack, 3, 0); + const float py = Par[iP].ConstAt(itrack, 4, 0); + const float pt = std::sqrt(px*px + py*py); + //here alpha is the difference between posPhi and momPhi + const float cosA = ( x*px + y*py ) / (pt*r); + const float sinA = ( y*px - x*py ) / (pt*r); +#endif + //take abs so that we always inflate the window + const float dist = std::abs(deltaR*sinA/cosA); + dphi += dist / r; + } + } + + dphi = std::min(std::abs(dphi), L.max_dphi()); + dz = std::min(std::abs(dz), L.max_dq()); + + const int zb1 = L.GetQBinChecked(z - dz); + const int zb2 = L.GetQBinChecked(z + dz) + 1; + const int pb1 = L.GetPhiBin(phi - dphi); + const int pb2 = L.GetPhiBin(phi + dphi) + 1; + // MT: The extra phi bins give us ~1.5% more good tracks at expense of 10% runtime. + // const int pb1 = L.GetPhiBin(phi - dphi) - 1; + // const int pb2 = L.GetPhiBin(phi + dphi) + 2; + + if (dump) + printf("LayerOfHits::SelectHitIndices %6.3f %6.3f %6.6f %7.5f %3d %3d %4d %4d\n", + z, phi, dz, dphi, zb1, zb2, pb1, pb2); + + // MT: One could iterate in "spiral" order, to pick hits close to the center. + // http://stackoverflow.com/questions/398299/looping-in-a-spiral + // This would then work best with relatively small bin sizes. + // Or, set them up so I can always take 3x3 array around the intersection. + + for (int zi = zb1; zi < zb2; ++zi) + { + for (int pi = pb1; pi < pb2; ++pi) + { + const int pb = pi & L.m_phi_mask; + + // MT: The following line is the biggest hog (4% total run time). + // This comes from cache misses, I presume. + // It might make sense to make first loop to extract bin indices + // and issue prefetches at the same time. + // Then enter vectorized loop to actually collect the hits in proper order. + + for (int hi = L.m_phi_bin_infos[zi][pb].first; hi < L.m_phi_bin_infos[zi][pb].second; ++hi) + { + // MT: Access into m_hit_zs and m_hit_phis is 1% run-time each. + +#ifdef LOH_USE_PHI_Q_ARRAYS + float ddz = std::abs(z - L.m_hit_qs[hi]); + float ddphi = std::abs(phi - L.m_hit_phis[hi]); + if (ddphi > Config::PI) ddphi = Config::TwoPI - ddphi; + + if (dump) + printf(" SHI %3d %4d %4d %5d %6.3f %6.3f %6.4f %7.5f %s\n", + zi, pi, pb, hi, + L.m_hit_qs[hi], L.m_hit_phis[hi], ddz, ddphi, + (ddz < dz && ddphi < dphi) ? "PASS" : "FAIL"); + + // MT: Commenting this check out gives full efficiency ... + // and means our error estimations are wrong! + // Avi says we should have *minimal* search windows per layer. + // Also ... if bins are sufficiently small, we do not need the extra + // checks, see above. + // if (ddz < dz && ddphi < dphi && XHitSize[itrack] < MPlexHitIdxMax) +#endif + // MT: The following check also makes more sense with spiral traversal, + // we'd be taking in closest hits first. + if (XHitSize[itrack] < MPlexHitIdxMax) + { + XHitArr.At(itrack, XHitSize[itrack]++, 0) = hi; + } + } + } + } + } +} + +void MkFinder::SelectHitIndicesEndcap(const LayerOfHits &layer_of_hits, + const int N_proc, bool dump) +{ + // debug = 1; + // dump = true; + + const LayerOfHits &L = layer_of_hits; + const int iI = iP; + const float nSigmaPhi = 3; + const float nSigmaR = 3; + + // Vectorizing this makes it run slower! + //#pragma ivdep + //#pragma simd + for (int itrack = 0; itrack < N_proc; ++itrack) + { + XHitSize[itrack] = 0; + + float r, phi, dr, dphi; + { + const float x = Par[iI].ConstAt(itrack, 0, 0); + const float y = Par[iI].ConstAt(itrack, 1, 0); + + const float r2 = x*x + y*y; + r = std::sqrt(r2); + + phi = getPhi(x, y); + dr = nSigmaR*(x*x*Err[iI].ConstAt(itrack, 0, 0) + y*y*Err[iI].ConstAt(itrack, 1, 1) + 2*x*y*Err[iI].ConstAt(itrack, 0, 1))/r2; + + const float dphidx = -y/r2, dphidy = x/r2; + const float dphi2 = dphidx * dphidx * Err[iI].ConstAt(itrack, 0, 0) + + dphidy * dphidy * Err[iI].ConstAt(itrack, 1, 1) + + 2 * dphidx * dphidy * Err[iI].ConstAt(itrack, 0, 1); + +#ifdef HARD_CHECK + assert(dphi2 >= 0); +#endif + + dphi = nSigmaPhi * std::sqrt(std::abs(dphi2)); + + dphi = std::max(std::abs(dphi), L.min_dphi()); + dr = std::max(std::abs(dr), L.min_dq()); + + if (Config::useCMSGeom) + { +#ifdef CCSCOORD + //now correct for bending and for layer thickness unsing linear approximation + const float deltaZ = 5; //fixme! using constant value, to be taken from layer properties + float cosT = std::cos(Par[iI].ConstAt(itrack, 5, 0)); + float sinT = std::sin(Par[iI].ConstAt(itrack, 5, 0)); + //here alpha is the helix angular path corresponding to deltaZ + const float k = Chg.ConstAt(itrack, 0, 0) * 100.f / (-Config::sol*Config::Bfield); + const float alpha = deltaZ*sinT*Par[iI].ConstAt(itrack, 3, 0)/(cosT*k); + dphi += std::abs(alpha); +#else + assert(0); +#endif + } + } + + dphi = std::min(std::abs(dphi), L.max_dphi()); + dr = std::min(std::abs(dr), L.max_dq()); + + const int rb1 = L.GetQBinChecked(r - dr); + const int rb2 = L.GetQBinChecked(r + dr) + 1; + const int pb1 = L.GetPhiBin(phi - dphi); + const int pb2 = L.GetPhiBin(phi + dphi) + 1; + // MT: The extra phi bins give us ~1.5% more good tracks at expense of 10% runtime. + // const int pb1 = L.GetPhiBin(phi - dphi) - 1; + // const int pb2 = L.GetPhiBin(phi + dphi) + 2; + + if (dump) + printf("LayerOfHits::SelectHitIndicesEndcap %6.3f %6.3f %6.4f %7.5f %3d %3d %4d %4d\n", + r, phi, dr, dphi, rb1, rb2, pb1, pb2); + + // MT: One could iterate in "spiral" order, to pick hits close to the center. + // http://stackoverflow.com/questions/398299/looping-in-a-spiral + // This would then work best with relatively small bin sizes. + // Or, set them up so I can always take 3x3 array around the intersection. + + for (int ri = rb1; ri < rb2; ++ri) + { + for (int pi = pb1; pi < pb2; ++pi) + { + const int pb = pi & L.m_phi_mask; + + // MT: The following line is the biggest hog (4% total run time). + // This comes from cache misses, I presume. + // It might make sense to make first loop to extract bin indices + // and issue prefetches at the same time. + // Then enter vectorized loop to actually collect the hits in proper order. + + for (int hi = L.m_phi_bin_infos[ri][pb].first; hi < L.m_phi_bin_infos[ri][pb].second; ++hi) + { + // MT: Access into m_hit_zs and m_hit_phis is 1% run-time each. + +#ifdef LOH_USE_PHI_Q_ARRAYS + float ddr = std::abs(r - L.m_hit_qs[hi]); + float ddphi = std::abs(phi - L.m_hit_phis[hi]); + if (ddphi > Config::PI) ddphi = Config::TwoPI - ddphi; + + if (dump) + printf(" SHI %3d %4d %4d %5d %6.3f %6.3f %6.4f %7.5f %s\n", + ri, pi, pb, hi, + L.m_hit_qs[hi], L.m_hit_phis[hi], ddr, ddphi, + (ddr < dr && ddphi < dphi) ? "PASS" : "FAIL"); + + // MT: Commenting this check out gives full efficiency ... + // and means our error estimations are wrong! + // Avi says we should have *minimal* search windows per layer. + // Also ... if bins are sufficiently small, we do not need the extra + // checks, see above. + // if (ddz < dz && ddphi < dphi && XHitSize[itrack] < MPlexHitIdxMax) +#endif + // MT: The following check also makes more sense with spiral traversal, + // we'd be taking in closest hits first. + if (XHitSize[itrack] < MPlexHitIdxMax) + { + XHitArr.At(itrack, XHitSize[itrack]++, 0) = hi; + } + } + } + } + } +} + +//============================================================================== +// AddBestHit +//============================================================================== + +void MkFinder::AddBestHit(const LayerOfHits &layer_of_hits, const int N_proc, + const SteeringParams &st_par) +{ + // debug = true; + + float minChi2[NN]; + int bestHit[NN]; + // MT: fill_n gave me crap on MIC, NN=8,16, doing in maxSize search below. + // Must be a compiler issue. + // std::fill_n(minChi2, NN, Config::chi2Cut); + // std::fill_n(bestHit, NN, -1); + + const char *varr = (char*) layer_of_hits.m_hits; + + const int off_error = (char*) layer_of_hits.m_hits[0].errArray() - varr; + const int off_param = (char*) layer_of_hits.m_hits[0].posArray() - varr; + + int idx[NN] __attribute__((aligned(64))); + + int maxSize = 0; + + // Determine maximum number of hits for tracks in the collection. + // At the same time prefetch the first set of hits to L1 and the second one to L2. + for (int it = 0; it < NN; ++it) + { + if (it < N_proc) + { + if (XHitSize[it] > 0) + { +#ifndef NO_PREFETCH + _mm_prefetch(varr + XHitArr.At(it, 0, 0) * sizeof(Hit), _MM_HINT_T0); + if (XHitSize[it] > 1) + { + _mm_prefetch(varr + XHitArr.At(it, 1, 0) * sizeof(Hit), _MM_HINT_T1); + } +#endif + maxSize = std::max(maxSize, XHitSize[it]); + } + } + + idx[it] = 0; + bestHit[it] = -1; + minChi2[it] = Config::chi2Cut; + } + +// Has basically no effect, it seems. +//#pragma noprefetch + for (int hit_cnt = 0; hit_cnt < maxSize; ++hit_cnt) + { + //fixme what if size is zero??? + +#pragma simd + for (int itrack = 0; itrack < N_proc; ++itrack) + { + if (hit_cnt < XHitSize[itrack]) + { + idx[itrack] = XHitArr.At(itrack, hit_cnt, 0) * sizeof(Hit); + } + } +#if defined(MIC_INTRINSICS) + __m512i vi = _mm512_load_epi32(idx); +#endif + +#ifndef NO_PREFETCH + // Prefetch to L2 the hits we'll process after two loops iterations. + // Ideally this would be initiated before coming here, for whole bunch_of_hits.m_hits vector. + for (int itrack = 0; itrack < N_proc; ++itrack) + { + if (hit_cnt + 2 < XHitSize[itrack]) + { + _mm_prefetch(varr + XHitArr.At(itrack, hit_cnt+2, 0)*sizeof(Hit), _MM_HINT_T1); + } + } +#endif + +#ifdef NO_GATHER + +#pragma simd + for (int itrack = 0; itrack < N_proc; ++itrack) + { + if (hit_cnt < XHitSize[itrack]) + { + const Hit &hit = layer_of_hits.m_hits[XHitArr.At(itrack, hit_cnt, 0)]; + msErr.CopyIn(itrack, hit.errArray()); + msPar.CopyIn(itrack, hit.posArray()); + } + } + +#else //NO_GATHER + +#if defined(MIC_INTRINSICS) + msErr.SlurpIn(varr + off_error, vi); + msPar.SlurpIn(varr + off_param, vi); +#else + msErr.SlurpIn(varr + off_error, idx); + msPar.SlurpIn(varr + off_param, idx); +#endif +#endif //NO_GATHER + + //now compute the chi2 of track state vs hit + MPlexQF outChi2; + (*st_par.compute_chi2_foo)(Err[iP], Par[iP], Chg, msErr, msPar, + outChi2, N_proc); + +#ifndef NO_PREFETCH + // Prefetch to L1 the hits we'll process in the next loop iteration. + for (int itrack = 0; itrack < N_proc; ++itrack) + { + if (hit_cnt + 1 < XHitSize[itrack]) + { + _mm_prefetch(varr + XHitArr.At(itrack, hit_cnt+1, 0)*sizeof(Hit), _MM_HINT_T0); + } + } +#endif + + //update best hit in case chi2; + using MPlexQHoT = Matriplex::Matriplex; + + struct IdxChi2List + { + int trkIdx; // candidate index + int hitIdx; // hit index + int nhits; // number of hits (used for sorting) + float chi2; // total chi2 (used for sorting) + }; + + //---------------------------------------------------------------------------- + + MPlexQF Chi2; + MPlexQI Label; // seed index in global seed vector (for MC truth match) + + MPlexQI NHits; + MPlexQI NFoundHits; + HitOnTrack HoTArrs[NN][Config::nMaxTrkHits]; + + MPlexQI SeedIdx; // seed index in local thread (for bookkeeping at thread level) + MPlexQI CandIdx; // candidate index for the given seed (for bookkeeping of clone engine) + + // Hit indices into LayerOfHits to explore. + MPlexQI XHitSize; + MPlexHitIdx XHitArr; + + // Hit error / parameters for hit matching, update. + MPlexHS msErr; + MPlexHV msPar; + + //============================================================================ + + MkFinder() {} + + //---------------------------------------------------------------------------- + + void InputTracksAndHitIdx(const std::vector& tracks, + int beg, int end, bool inputProp); + void InputTracksAndHitIdx(const std::vector >& tracks, + const std::vector >& idxs, + int beg, int end, bool inputProp); + + void InputTracksAndHitIdx(const std::vector >& tracks, + const std::vector >& idxs, + int beg, int end, bool inputProp); + + void OutputTracksAndHitIdx(std::vector& tracks, + int beg, int end, bool outputProp) const; + + //---------------------------------------------------------------------------- + + void SelectHitIndices(const LayerOfHits &layer_of_hits, const int N_proc, bool dump=false); + void SelectHitIndicesEndcap(const LayerOfHits &layer_of_hits, const int N_proc, bool dump=false); + + void AddBestHit(const LayerOfHits &layer_of_hits, const int N_proc, + const SteeringParams &st_par); + + //---------------------------------------------------------------------------- + + void FindCandidates(const LayerOfHits &layer_of_hits, std::vector>& tmp_candidates, + const int offset, const int N_proc); + void FindCandidatesEndcap(const LayerOfHits &layer_of_hits, std::vector>& tmp_candidates, + const int offset, const int N_proc); + + //---------------------------------------------------------------------------- + + void FindCandidatesMinimizeCopy(const LayerOfHits &layer_of_hits, CandCloner& cloner, + const int offset, const int N_proc); + void FindCandidatesMinimizeCopyEndcap(const LayerOfHits &layer_of_hits, CandCloner& cloner, + const int offset, const int N_proc); + + void UpdateWithLastHit(const LayerOfHits &layer_of_hits, int N_proc); + void UpdateWithLastHitEndcap(const LayerOfHits &layer_of_hits, int N_proc); + + void CopyOutParErr(std::vector >& seed_cand_vec, + int N_proc, bool outputProp) const; + + //---------------------------------------------------------------------------- + +private: + + void copy_in(const Track& trk, const int mslot, const int tslot) + { + Err[tslot].CopyIn(mslot, trk.errors().Array()); + Par[tslot].CopyIn(mslot, trk.parameters().Array()); + + Chg (mslot, 0, 0) = trk.charge(); + Chi2 (mslot, 0, 0) = trk.chi2(); + Label(mslot, 0, 0) = trk.label(); + + NHits (mslot, 0, 0) = trk.nTotalHits(); + NFoundHits(mslot, 0, 0) = trk.nFoundHits(); + std::copy(trk.BeginHitsOnTrack(), trk.EndHitsOnTrack(), HoTArrs[mslot]); + } + + void copy_out(Track& trk, const int mslot, const int tslot) const + { + Err[tslot].CopyOut(mslot, trk.errors_nc().Array()); + Par[tslot].CopyOut(mslot, trk.parameters_nc().Array()); + + trk.setCharge(Chg (mslot, 0, 0)); + trk.setChi2 (Chi2 (mslot, 0, 0)); + trk.setLabel (Label(mslot, 0, 0)); + + trk.setNTotalHits(NHits (mslot, 0, 0)); + trk.setNFoundHits(NFoundHits(mslot, 0, 0)); + std::copy(HoTArrs[mslot], HoTArrs[mslot + 1], trk.BeginHitsOnTrack_nc()); + } + + void add_hit(const int mslot, int index, int layer) + { + HoTArrs[mslot][NHits(mslot, 0, 0)] = { index, layer }; + ++NHits(mslot, 0, 0); + if (index >= 0) ++NFoundHits(mslot, 0, 0); + } +}; + +#endif diff --git a/mkFit/MkFitter.cc b/mkFit/MkFitter.cc index 231ec63d54d47..0cb9b27157e67 100644 --- a/mkFit/MkFitter.cc +++ b/mkFit/MkFitter.cc @@ -1,7 +1,7 @@ #include "MkFitter.h" + #include "CandCloner.h" -#include "PropagationMPlex.h" #include "KalmanUtilsMPlex.h" #include "ConformalUtilsMPlex.h" #ifdef USE_CUDA @@ -314,16 +314,8 @@ void MkFitter::InputSeedsTracksAndHits(const std::vector& seeds, // assert(end - beg == NN); int itrack; -//#ifdef USE_CUDA -#if 0 - // This openmp loop brings some performances when using - // a single thread to fit all events. - // However, it is more advantageous to use the threads to - // parallelize over Events. - omp_set_num_threads(Config::numThreadsReorg); -#pragma omp parallel for private(itrack) -#endif - for (int i = beg; i < end; ++i) { + for (int i = beg; i < end; ++i) + { itrack = i - beg; const Track &see = seeds[i]; @@ -704,12 +696,6 @@ void MkFitter::OutputFittedTracksAndHitIdx(std::vector& tracks, int beg, } } -void MkFitter::PropagateTracksToR(float R, const int N_proc) -{ - propagateHelixToRMPlex(Err[iC], Par[iC], Chg, R, - Err[iP], Par[iP], N_proc); -} - void MkFitter::SelectHitIndices(const LayerOfHits &layer_of_hits, const int N_proc, bool dump) { const LayerOfHits &L = layer_of_hits; @@ -853,6 +839,8 @@ void MkFitter::SelectHitIndices(const LayerOfHits &layer_of_hits, const int N_pr void MkFitter::AddBestHit(const LayerOfHits &layer_of_hits, const int N_proc) { + // debug = true; + float minChi2[NN]; int bestHit[NN]; // MT: fill_n gave me crap on MIC, NN=8,16, doing in maxSize search below. @@ -1633,34 +1621,17 @@ void MkFitter::CopyOutParErr(std::vector >& seed_cand_vec, } } - - -//-----------------------------------------------------------------------------------------// -//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// -//-----------------------------------------------------------------------------------------// -// Endcap section: duplicate functions for now, cleanup and merge once strategy sorted out // -//-----------------------------------------------------------------------------------------// -//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// -//-----------------------------------------------------------------------------------------// - -void MkFitter::PropagateTracksToZ(float Z, const int N_proc) -{ - // printf("MkFitter::PropagateTracksToZ z=%f\n", Z); - propagateHelixToZMPlex(Err[iC], Par[iC], Chg, Z, - Err[iP], Par[iP], N_proc); -} - void MkFitter::SelectHitIndicesEndcap(const LayerOfHits &layer_of_hits, const int N_proc, bool dump) { // debug = 1; + // dump = true; + const LayerOfHits &L = layer_of_hits; const int iI = iP; const float nSigmaPhi = 3; const float nSigmaR = 3; - //dump = true; - // Vectorizing this makes it run slower! //#pragma ivdep //#pragma simd diff --git a/mkFit/MkFitter.h b/mkFit/MkFitter.h index 346b4d877cce0..a78421a41799e 100644 --- a/mkFit/MkFitter.h +++ b/mkFit/MkFitter.h @@ -1,8 +1,9 @@ #ifndef MkFitter_h #define MkFitter_h +#include "MkBase.h" + #include "Event.h" -#include "Matrix.h" #include "KalmanUtils.h" #include "HitStructures.h" @@ -22,15 +23,9 @@ const int MPlexHitIdxMax = 16; using MPlexHitIdx = Matriplex::Matriplex; using MPlexQHoT = Matriplex::Matriplex; -struct MkFitter +struct MkFitter : public MkBase { - MPlexLS Err[2]; - MPlexLV Par[2]; - - MPlexQI Chg; - MPlexQF Chi2; - MPlexQF OutChi2; MPlexHS msErr[Config::nMaxTrkHits]; MPlexHV msPar[Config::nMaxTrkHits]; @@ -45,11 +40,6 @@ struct MkFitter MPlexQI XHitSize; MPlexHitIdx XHitArr; - // Indices into Err and Par arrays. - // Thought I'll have to flip between them ... - const int iC = 0; // current - const int iP = 1; // propagated - int Nhits; public: @@ -101,10 +91,6 @@ struct MkFitter void OutputFittedTracksAndHitIdx(std::vector& tracks, int beg, int end, bool outputProp) const; - void PropagateTracksToR(float R, const int N_proc); - - void PropagateTracksToZ(float Z, const int N_proc); - void SelectHitIndices(const LayerOfHits &layer_of_hits, const int N_proc, bool dump=false); void SelectHitIndicesEndcap(const LayerOfHits &layer_of_hits, const int N_proc, bool dump=false); diff --git a/mkFit/PropagationMPlex.h b/mkFit/PropagationMPlex.h index 1e8d1bcc9a5ff..c44ca9f6a41d6 100644 --- a/mkFit/PropagationMPlex.h +++ b/mkFit/PropagationMPlex.h @@ -1,7 +1,6 @@ #ifndef _propagation_mplex_ #define _propagation_mplex_ -#include "Track.h" #include "Matrix.h" void propagateLineToRMPlex(const MPlexLS &psErr, const MPlexLV& psPar, diff --git a/mkFit/SteeringParams.h b/mkFit/SteeringParams.h index 6952a930a3cea..2bd289138c72d 100644 --- a/mkFit/SteeringParams.h +++ b/mkFit/SteeringParams.h @@ -1,31 +1,56 @@ #ifndef SteeringParams_h #define SteeringParams_h +#include "Matrix.h" + class LayerInfo; -class MkFitter; class CandCloner; +class MkBase; +class MkFitter; +class MkFinder; + +#define COMPUTE_CHI2_ARGS const MPlexLS &, const MPlexLV &, const MPlexQI &, \ + const MPlexHS &, const MPlexHV &, \ + MPlexQF &, const int +#define UPDATE_PARAM_ARGS const MPlexLS &, const MPlexLV &, const MPlexQI &, \ + const MPlexHS &, const MPlexHV &, \ + MPlexLS &, MPlexLV &, const int struct SteeringParams { - int first_finding_layer; // layer to consider first + void (*compute_chi2_foo) (COMPUTE_CHI2_ARGS); + void (*update_param_foo) (UPDATE_PARAM_ARGS); + void (MkFinder::*select_hit_idcs_foo) (const LayerOfHits &, const int, bool); + + int first_finding_layer; // layer to consider first .. to be thrown out XXXX + int LayerInfo::*next_layer_doo; - void (MkFitter::*propagate_foo) (float, const int); + + void (MkBase::*propagate_foo) (float, const int); void (MkFitter::*select_hits_foo) (const LayerOfHits &, const int, bool); void (MkFitter::*add_best_hit_foo)(const LayerOfHits &, const int); void (MkFitter::*update_with_last_hit_foo)(const LayerOfHits &, const int); void (MkFitter::*find_cands_foo)(const LayerOfHits &, std::vector> &, const int, const int); void (MkFitter::*find_cands_min_copy_foo)(const LayerOfHits &, CandCloner &, const int, const int); + //---------------------------------------------------------------------------- + SteeringParams() {} - SteeringParams(int ffl, + SteeringParams(void (*cch2_f)(COMPUTE_CHI2_ARGS), + void (*updp_f)(UPDATE_PARAM_ARGS), + void (MkFinder::*shi_f) (const LayerOfHits &, const int, bool), + int ffl, int LayerInfo::*nl_d, - void (MkFitter::*p_f) (float, const int), - void (MkFitter::*sh_f) (const LayerOfHits &, const int, bool), - void (MkFitter::*abh_f)(const LayerOfHits &, const int), + void (MkBase::*p_f) (float, const int), + void (MkFitter::*sh_f) (const LayerOfHits &, const int, bool), + void (MkFitter::*abh_f) (const LayerOfHits &, const int), void (MkFitter::*uwlh_f)(const LayerOfHits &, const int), - void (MkFitter::*fc_f)(const LayerOfHits &, std::vector> &, const int, const int), + void (MkFitter::*fc_f) (const LayerOfHits &, std::vector> &, const int, const int), void (MkFitter::*fcmc_f)(const LayerOfHits &, CandCloner &, const int, const int)) : + compute_chi2_foo(cch2_f), + update_param_foo(updp_f), + select_hit_idcs_foo(shi_f), first_finding_layer(ffl), next_layer_doo(nl_d), propagate_foo(p_f), diff --git a/mkFit/mkFit.cc b/mkFit/mkFit.cc index 0c745f59486ba..f09ea7fa8adec 100644 --- a/mkFit/mkFit.cc +++ b/mkFit/mkFit.cc @@ -275,10 +275,10 @@ void test_standard() std::atomic nevt{1}; std::atomic seedstot{0}, simtrackstot{0}; - std::vector> evs(Config::numThreadsEvents); + std::vector> evs(Config::numThreadsEvents); std::vector> vals(Config::numThreadsEvents); - std::vector> mkbs(Config::numThreadsEvents); - std::vector> fps; + std::vector> mkbs(Config::numThreadsEvents); + std::vector> fps; fps.reserve(Config::numThreadsEvents); const std::string valfile("valtree"); diff --git a/tkNtuple/WriteMemoryFile.cc b/tkNtuple/WriteMemoryFile.cc index 3d220cd768d49..596072ab68041 100644 --- a/tkNtuple/WriteMemoryFile.cc +++ b/tkNtuple/WriteMemoryFile.cc @@ -749,7 +749,7 @@ int main(int argc, char *argv[]) // bool allTracksAllHits = true; for (int i=0;i Date: Mon, 12 Jun 2017 16:01:19 -0700 Subject: [PATCH 067/172] Merge MkFinder barrel and endcap functions into one. --- mkFit/HitStructures.h | 2 +- mkFit/KalmanUtilsMPlex.cc | 2 + mkFit/MkBase.h | 2 + mkFit/MkBuilder.cc | 38 ++++---- mkFit/MkFinder.cc | 197 +++++++++++--------------------------- mkFit/MkFinder.h | 1 - mkFit/MkFitter.h | 1 - mkFit/SteeringParams.h | 3 - 8 files changed, 79 insertions(+), 167 deletions(-) diff --git a/mkFit/HitStructures.h b/mkFit/HitStructures.h index 71f29ffb21c3d..ac74fcd9af8a1 100644 --- a/mkFit/HitStructures.h +++ b/mkFit/HitStructures.h @@ -61,7 +61,7 @@ inline bool sortTrksByPhiMT(const Track& t1, const Track& t2) // and could help us reduce the number of hits we need to process with bigger // potential gains. -// #define LOH_USE_PHI_Q_ARRAYS +#define LOH_USE_PHI_Q_ARRAYS // Note: the same code is used for barrel and endcap. In barrel the longitudinal // bins are in Z and in endcap they are in R -- here this coordinate is called Q diff --git a/mkFit/KalmanUtilsMPlex.cc b/mkFit/KalmanUtilsMPlex.cc index 777db6adadda4..f305af040ee9f 100644 --- a/mkFit/KalmanUtilsMPlex.cc +++ b/mkFit/KalmanUtilsMPlex.cc @@ -530,6 +530,8 @@ void updateParametersMPlex(const MPlexLS &psErr, const MPlexLV& psPar, const MP // updateParametersContext ctx; //assert((long long)(&updateCtx.propErr.fArray[0]) % 64 == 0); + // debug = true; + MPlexLS propErr; MPlexLV propPar; // do a full propagation step to correct for residual distance from the hit radius - need the charge for this diff --git a/mkFit/MkBase.h b/mkFit/MkBase.h index 313392669144d..f4375aa07f346 100644 --- a/mkFit/MkBase.h +++ b/mkFit/MkBase.h @@ -15,6 +15,8 @@ struct MkBase static constexpr int iC = 0; // current static constexpr int iP = 1; // propagated + float getPar(int itrack, int i, int par) const { return Par[i].ConstAt(itrack, 0, par); } + //---------------------------------------------------------------------------- MkBase() {} diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index 4213ee2f8fd5c..c46af8b4a2746 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -98,23 +98,24 @@ MkBuilder* MkBuilder::make_builder() } #ifdef DEBUG -namespace { - void pre_prop_print(int ilay, MkFitter* mkfttr) { +namespace +{ + void pre_prop_print(int ilay, MkBase* fir) { std::cout << "propagate to lay=" << ilay - << " start from x=" << mkfttr->getPar(0, 0, 0) << " y=" << mkfttr->getPar(0, 0, 1) << " z=" << mkfttr->getPar(0, 0, 2) - << " r=" << getHypot(mkfttr->getPar(0, 0, 0), mkfttr->getPar(0, 0, 1)) - << " px=" << mkfttr->getPar(0, 0, 3) << " py=" << mkfttr->getPar(0, 0, 4) << " pz=" << mkfttr->getPar(0, 0, 5) + << " start from x=" << fir->getPar(0, 0, 0) << " y=" << fir->getPar(0, 0, 1) << " z=" << fir->getPar(0, 0, 2) + << " r=" << getHypot(fir->getPar(0, 0, 0), fir->getPar(0, 0, 1)) + << " px=" << fir->getPar(0, 0, 3) << " py=" << fir->getPar(0, 0, 4) << " pz=" << fir->getPar(0, 0, 5) #ifdef CCSCOORD - << " pT=" << 1./mkfttr->getPar(0, 0, 3) << std::endl; + << " pT=" << 1./fir->getPar(0, 0, 3) << std::endl; #else - << " pT=" << getHypot(mkfttr->getPar(0, 0, 3), mkfttr->getPar(0, 0, 4)) << std::endl; + << " pT=" << getHypot(fir->getPar(0, 0, 3), fir->getPar(0, 0, 4)) << std::endl; #endif } - void post_prop_print(int ilay, MkFitter* mkfttr) { + void post_prop_print(int ilay, MkBase* fir) { std::cout << "propagate to lay=" << ilay - << " arrive at x=" << mkfttr->getPar(0, 1, 0) << " y=" << mkfttr->getPar(0, 1, 1) << " z=" << mkfttr->getPar(0, 1, 2) - << " r=" << getHypot(mkfttr->getPar(0, 1, 0), mkfttr->getPar(0, 1, 1)) << std::endl; + << " arrive at x=" << fir->getPar(0, 1, 0) << " y=" << fir->getPar(0, 1, 1) << " z=" << fir->getPar(0, 1, 2) + << " r=" << getHypot(fir->getPar(0, 1, 0), fir->getPar(0, 1, 1)) << std::endl; } void print_seed(const Track& seed) { @@ -183,7 +184,6 @@ MkBuilder::MkBuilder() : { computeChi2EndcapMPlex, updateParametersEndcapMPlex, - &MkFinder::SelectHitIndicesEndcap, 21, &LayerInfo::m_next_ecap_neg, &MkBase::PropagateTracksToZ, @@ -200,7 +200,6 @@ MkBuilder::MkBuilder() : { computeChi2MPlex, updateParametersMPlex, - &MkFinder::SelectHitIndices, 3, &LayerInfo::m_next_barrel, &MkBase::PropagateTracksToR, @@ -217,7 +216,6 @@ MkBuilder::MkBuilder() : { computeChi2EndcapMPlex, updateParametersEndcapMPlex, - &MkFinder::SelectHitIndicesEndcap, 12, &LayerInfo::m_next_ecap_pos, &MkBase::PropagateTracksToZ, @@ -1058,17 +1056,20 @@ void MkBuilder::FindTracksBestHit() // if (region != TrackerInfo::Reg_Barrel) // return; - const SteeringParams &st_par = m_steering_params[region]; + const SteeringParams &st_par = m_steering_params[region]; + const TrackerInfo &trk_info = Config::TrkInfo; const RegionOfSeedIndices rosi(m_event, region); + // XXXXMT to be done on bunch basis, requires equalization or multi-pass + int last_seed_layer = m_event->seedMinLastLayer_[region]; + int first_layer = trk_info.m_layers[last_seed_layer].*st_par.next_layer_doo; + tbb::parallel_for(rosi.tbb_blk_rng_vec(), [&](const tbb::blocked_range& blk_rng) { FINDER( mkfndr ); - const TrackerInfo &trk_info = Config::TrkInfo; - RangeOfSeedIndices rng = rosi.seed_rng(blk_rng); while (rng.valid()) @@ -1080,8 +1081,9 @@ void MkBuilder::FindTracksBestHit() // Loop over layers, starting from after the seed. // Consider inverting loop order and make layer outer, need to // trade off hit prefetching with copy-out of candidates. - for (int ilay = st_par.first_finding_layer; ; ) + for (int ilay = first_layer; ; ) { + dprint("at layer " << ilay); const LayerOfHits &layer_of_hits = m_event_of_hits.m_layers_of_hits[ilay]; const LayerInfo &layer_info = trk_info.m_layers[ilay]; @@ -1099,7 +1101,7 @@ void MkBuilder::FindTracksBestHit() dcall(post_prop_print(ilay, mkfndr.get())); - (mkfndr.get()->*st_par.select_hit_idcs_foo)(layer_of_hits, rng.n_proc(), false); + mkfndr->SelectHitIndices(layer_of_hits, rng.n_proc(), false); // #ifdef PRINTOUTS_FOR_PLOTS // std::cout << "MX number of hits in window in layer " << ilay << " is " << mkfndr->getXHitEnd(0, 0, 0)-mkfndr->getXHitBegin(0, 0, 0) << std::endl; diff --git a/mkFit/MkFinder.cc b/mkFit/MkFinder.cc index 095271045e854..0f8f89d0df8cf 100644 --- a/mkFit/MkFinder.cc +++ b/mkFit/MkFinder.cc @@ -92,11 +92,8 @@ void MkFinder::OutputTracksAndHitIdx(std::vector& tracks, //============================================================================== -// SelectHitIndices / SelectHitIndicesEndcap +// SelectHitIndices //============================================================================== -// Those are harder to merge as we use z in barrel and r in endcap. -// Probably could separate out common part and have two functions that return -// q of the hit. void MkFinder::SelectHitIndices(const LayerOfHits &layer_of_hits, const int N_proc, bool dump) @@ -108,6 +105,11 @@ void MkFinder::SelectHitIndices(const LayerOfHits &layer_of_hits, const int iI = iP; const float nSigmaPhi = 3; const float nSigmaZ = 3; + const float nSigmaR = 3; + + if (dump) + printf("LayerOfHits::SelectHitIndices %s layer=%d N_proc=%d\n", + L.is_barrel() ? "barrel" : "endcap", L.layer_id(), N_proc); // Vectorizing this makes it run slower! //#pragma ivdep @@ -116,35 +118,37 @@ void MkFinder::SelectHitIndices(const LayerOfHits &layer_of_hits, { XHitSize[itrack] = 0; - float z, phi, dz, dphi; - { - const float x = Par[iI].ConstAt(itrack, 0, 0); - const float y = Par[iI].ConstAt(itrack, 1, 0); - - const float r2 = x*x + y*y; - - z = Par[iI].ConstAt(itrack, 2, 0); - phi = getPhi(x, y); - dz = nSigmaZ * std::sqrt(Err[iI].ConstAt(itrack, 2, 2)); - - const float dphidx = -y/r2, dphidy = x/r2; - const float dphi2 = dphidx * dphidx * Err[iI].ConstAt(itrack, 0, 0) + - dphidy * dphidy * Err[iI].ConstAt(itrack, 1, 1) + - 2 * dphidx * dphidy * Err[iI].ConstAt(itrack, 0, 1); + const float x = Par[iI].ConstAt(itrack, 0, 0); + const float y = Par[iI].ConstAt(itrack, 1, 0); + const float r2 = x*x + y*y; + const float dphidx = -y/r2, dphidy = x/r2; + const float dphi2 = dphidx * dphidx * Err[iI].ConstAt(itrack, 0, 0) + + dphidy * dphidy * Err[iI].ConstAt(itrack, 1, 1) + + 2 * dphidx * dphidy * Err[iI].ConstAt(itrack, 0, 1); #ifdef HARD_CHECK - assert(dphi2 >= 0); + assert(dphi2 >= 0); #endif - dphi = nSigmaPhi * std::sqrt(std::abs(dphi2)); + float q, dq, phi, dphi; - dphi = std::max(std::abs(dphi), L.min_dphi()); - dz = std::max(std::abs(dz), L.min_dq()); + phi = getPhi(x, y); + dphi = nSigmaPhi * std::sqrt(std::abs(dphi2)); + dphi = std::max(std::abs(dphi), L.min_dphi()); + + if (L.is_barrel()) + { + float z = Par[iI].ConstAt(itrack, 2, 0); + float dz = nSigmaZ * std::sqrt(Err[iI].ConstAt(itrack, 2, 2)); + + dz = std::max(std::abs(dz), L.min_dq()); if (Config::useCMSGeom) { //now correct for bending and for layer thickness unsing linear approximation - const float deltaR = Config::cmsDeltaRad; //fixme! using constant value, to be taken from layer properties + //fixme! using constant value, to be taken from layer properties + //XXXXMT4GC should we also increase dz? + const float deltaR = Config::cmsDeltaRad; const float r = std::sqrt(r2); #ifdef CCSCOORD //here alpha is the difference between posPhi and momPhi @@ -168,122 +172,24 @@ void MkFinder::SelectHitIndices(const LayerOfHits &layer_of_hits, const float dist = std::abs(deltaR*sinA/cosA); dphi += dist / r; } - } - - dphi = std::min(std::abs(dphi), L.max_dphi()); - dz = std::min(std::abs(dz), L.max_dq()); - - const int zb1 = L.GetQBinChecked(z - dz); - const int zb2 = L.GetQBinChecked(z + dz) + 1; - const int pb1 = L.GetPhiBin(phi - dphi); - const int pb2 = L.GetPhiBin(phi + dphi) + 1; - // MT: The extra phi bins give us ~1.5% more good tracks at expense of 10% runtime. - // const int pb1 = L.GetPhiBin(phi - dphi) - 1; - // const int pb2 = L.GetPhiBin(phi + dphi) + 2; - - if (dump) - printf("LayerOfHits::SelectHitIndices %6.3f %6.3f %6.6f %7.5f %3d %3d %4d %4d\n", - z, phi, dz, dphi, zb1, zb2, pb1, pb2); - - // MT: One could iterate in "spiral" order, to pick hits close to the center. - // http://stackoverflow.com/questions/398299/looping-in-a-spiral - // This would then work best with relatively small bin sizes. - // Or, set them up so I can always take 3x3 array around the intersection. - - for (int zi = zb1; zi < zb2; ++zi) - { - for (int pi = pb1; pi < pb2; ++pi) - { - const int pb = pi & L.m_phi_mask; - - // MT: The following line is the biggest hog (4% total run time). - // This comes from cache misses, I presume. - // It might make sense to make first loop to extract bin indices - // and issue prefetches at the same time. - // Then enter vectorized loop to actually collect the hits in proper order. - - for (int hi = L.m_phi_bin_infos[zi][pb].first; hi < L.m_phi_bin_infos[zi][pb].second; ++hi) - { - // MT: Access into m_hit_zs and m_hit_phis is 1% run-time each. - -#ifdef LOH_USE_PHI_Q_ARRAYS - float ddz = std::abs(z - L.m_hit_qs[hi]); - float ddphi = std::abs(phi - L.m_hit_phis[hi]); - if (ddphi > Config::PI) ddphi = Config::TwoPI - ddphi; - - if (dump) - printf(" SHI %3d %4d %4d %5d %6.3f %6.3f %6.4f %7.5f %s\n", - zi, pi, pb, hi, - L.m_hit_qs[hi], L.m_hit_phis[hi], ddz, ddphi, - (ddz < dz && ddphi < dphi) ? "PASS" : "FAIL"); - // MT: Commenting this check out gives full efficiency ... - // and means our error estimations are wrong! - // Avi says we should have *minimal* search windows per layer. - // Also ... if bins are sufficiently small, we do not need the extra - // checks, see above. - // if (ddz < dz && ddphi < dphi && XHitSize[itrack] < MPlexHitIdxMax) -#endif - // MT: The following check also makes more sense with spiral traversal, - // we'd be taking in closest hits first. - if (XHitSize[itrack] < MPlexHitIdxMax) - { - XHitArr.At(itrack, XHitSize[itrack]++, 0) = hi; - } - } - } + q = z; + dq = dz; } - } -} - -void MkFinder::SelectHitIndicesEndcap(const LayerOfHits &layer_of_hits, - const int N_proc, bool dump) -{ - // debug = 1; - // dump = true; - - const LayerOfHits &L = layer_of_hits; - const int iI = iP; - const float nSigmaPhi = 3; - const float nSigmaR = 3; - - // Vectorizing this makes it run slower! - //#pragma ivdep - //#pragma simd - for (int itrack = 0; itrack < N_proc; ++itrack) - { - XHitSize[itrack] = 0; - - float r, phi, dr, dphi; + else // endcap { - const float x = Par[iI].ConstAt(itrack, 0, 0); - const float y = Par[iI].ConstAt(itrack, 1, 0); + float r = std::sqrt(r2); + float dr = nSigmaR*(x*x*Err[iI].ConstAt(itrack, 0, 0) + y*y*Err[iI].ConstAt(itrack, 1, 1) + 2*x*y*Err[iI].ConstAt(itrack, 0, 1))/r2; - const float r2 = x*x + y*y; - r = std::sqrt(r2); - - phi = getPhi(x, y); - dr = nSigmaR*(x*x*Err[iI].ConstAt(itrack, 0, 0) + y*y*Err[iI].ConstAt(itrack, 1, 1) + 2*x*y*Err[iI].ConstAt(itrack, 0, 1))/r2; - - const float dphidx = -y/r2, dphidy = x/r2; - const float dphi2 = dphidx * dphidx * Err[iI].ConstAt(itrack, 0, 0) + - dphidy * dphidy * Err[iI].ConstAt(itrack, 1, 1) + - 2 * dphidx * dphidy * Err[iI].ConstAt(itrack, 0, 1); - -#ifdef HARD_CHECK - assert(dphi2 >= 0); -#endif - - dphi = nSigmaPhi * std::sqrt(std::abs(dphi2)); - - dphi = std::max(std::abs(dphi), L.min_dphi()); - dr = std::max(std::abs(dr), L.min_dq()); + dr = std::max(std::abs(dr), L.min_dq()); if (Config::useCMSGeom) { #ifdef CCSCOORD //now correct for bending and for layer thickness unsing linear approximation - const float deltaZ = 5; //fixme! using constant value, to be taken from layer properties + //fixme! using constant value, to be taken from layer properties + //XXXXMT4GC should we also increase dr? + const float deltaZ = 5; float cosT = std::cos(Par[iI].ConstAt(itrack, 5, 0)); float sinT = std::sin(Par[iI].ConstAt(itrack, 5, 0)); //here alpha is the helix angular path corresponding to deltaZ @@ -294,13 +200,16 @@ void MkFinder::SelectHitIndicesEndcap(const LayerOfHits &layer_of_hits, assert(0); #endif } + + q = r; + dq = dr; } dphi = std::min(std::abs(dphi), L.max_dphi()); - dr = std::min(std::abs(dr), L.max_dq()); + dq = std::min(std::abs(dq), L.max_dq()); - const int rb1 = L.GetQBinChecked(r - dr); - const int rb2 = L.GetQBinChecked(r + dr) + 1; + const int qb1 = L.GetQBinChecked(q - dq); + const int qb2 = L.GetQBinChecked(q + dq) + 1; const int pb1 = L.GetPhiBin(phi - dphi); const int pb2 = L.GetPhiBin(phi + dphi) + 1; // MT: The extra phi bins give us ~1.5% more good tracks at expense of 10% runtime. @@ -308,15 +217,15 @@ void MkFinder::SelectHitIndicesEndcap(const LayerOfHits &layer_of_hits, // const int pb2 = L.GetPhiBin(phi + dphi) + 2; if (dump) - printf("LayerOfHits::SelectHitIndicesEndcap %6.3f %6.3f %6.4f %7.5f %3d %3d %4d %4d\n", - r, phi, dr, dphi, rb1, rb2, pb1, pb2); + printf(" %2d: %6.3f %6.3f %6.6f %7.5f %3d %3d %4d %4d\n", + itrack, q, phi, dq, dphi, qb1, qb2, pb1, pb2); // MT: One could iterate in "spiral" order, to pick hits close to the center. // http://stackoverflow.com/questions/398299/looping-in-a-spiral // This would then work best with relatively small bin sizes. // Or, set them up so I can always take 3x3 array around the intersection. - for (int ri = rb1; ri < rb2; ++ri) + for (int qi = qb1; qi < qb2; ++qi) { for (int pi = pb1; pi < pb2; ++pi) { @@ -328,20 +237,20 @@ void MkFinder::SelectHitIndicesEndcap(const LayerOfHits &layer_of_hits, // and issue prefetches at the same time. // Then enter vectorized loop to actually collect the hits in proper order. - for (int hi = L.m_phi_bin_infos[ri][pb].first; hi < L.m_phi_bin_infos[ri][pb].second; ++hi) + for (int hi = L.m_phi_bin_infos[qi][pb].first; hi < L.m_phi_bin_infos[qi][pb].second; ++hi) { // MT: Access into m_hit_zs and m_hit_phis is 1% run-time each. #ifdef LOH_USE_PHI_Q_ARRAYS - float ddr = std::abs(r - L.m_hit_qs[hi]); + float ddq = std::abs(q - L.m_hit_qs[hi]); float ddphi = std::abs(phi - L.m_hit_phis[hi]); if (ddphi > Config::PI) ddphi = Config::TwoPI - ddphi; if (dump) printf(" SHI %3d %4d %4d %5d %6.3f %6.3f %6.4f %7.5f %s\n", - ri, pi, pb, hi, - L.m_hit_qs[hi], L.m_hit_phis[hi], ddr, ddphi, - (ddr < dr && ddphi < dphi) ? "PASS" : "FAIL"); + qi, pi, pb, hi, + L.m_hit_qs[hi], L.m_hit_phis[hi], ddq, ddphi, + (ddq < dq && ddphi < dphi) ? "PASS" : "FAIL"); // MT: Commenting this check out gives full efficiency ... // and means our error estimations are wrong! @@ -541,7 +450,9 @@ void MkFinder::AddBestHit(const LayerOfHits &layer_of_hits, const int N_proc, dprint("ADD FAKE HIT FOR TRACK #" << itrack << " withinBounds=" << (fake_hit_idx != -3) << " r=" << std::hypot(Par[iP](itrack,0,0), Par[iP](itrack,1,0))); msErr.SetDiagonal3x3(itrack, 666); - msPar.SetVal(0); + msPar(itrack,0,0) = Par[iP](itrack,0,0); + msPar(itrack,1,0) = Par[iP](itrack,1,0); + msPar(itrack,2,0) = Par[iP](itrack,2,0); // Don't update chi2 add_hit(itrack, fake_hit_idx, layer_of_hits.layer_id()); diff --git a/mkFit/MkFinder.h b/mkFit/MkFinder.h index e00a2306f527c..f47fda645d683 100644 --- a/mkFit/MkFinder.h +++ b/mkFit/MkFinder.h @@ -90,7 +90,6 @@ class MkFinder : public MkBase //---------------------------------------------------------------------------- void SelectHitIndices(const LayerOfHits &layer_of_hits, const int N_proc, bool dump=false); - void SelectHitIndicesEndcap(const LayerOfHits &layer_of_hits, const int N_proc, bool dump=false); void AddBestHit(const LayerOfHits &layer_of_hits, const int N_proc, const SteeringParams &st_par); diff --git a/mkFit/MkFitter.h b/mkFit/MkFitter.h index a78421a41799e..0269ff4d458f3 100644 --- a/mkFit/MkFitter.h +++ b/mkFit/MkFitter.h @@ -54,7 +54,6 @@ struct MkFitter : public MkBase void PrintPt(int idx); - float getPar(int itrack, int i, int par) const { return Par[i].ConstAt(itrack, 0, par); } void SetNhits(int newnhits) { Nhits = std::min(newnhits, Config::nMaxTrkHits - 1); } int countValidHits (int itrack, int end_hit) const; diff --git a/mkFit/SteeringParams.h b/mkFit/SteeringParams.h index 2bd289138c72d..e4be368f8d1d3 100644 --- a/mkFit/SteeringParams.h +++ b/mkFit/SteeringParams.h @@ -20,7 +20,6 @@ struct SteeringParams { void (*compute_chi2_foo) (COMPUTE_CHI2_ARGS); void (*update_param_foo) (UPDATE_PARAM_ARGS); - void (MkFinder::*select_hit_idcs_foo) (const LayerOfHits &, const int, bool); int first_finding_layer; // layer to consider first .. to be thrown out XXXX @@ -39,7 +38,6 @@ struct SteeringParams SteeringParams(void (*cch2_f)(COMPUTE_CHI2_ARGS), void (*updp_f)(UPDATE_PARAM_ARGS), - void (MkFinder::*shi_f) (const LayerOfHits &, const int, bool), int ffl, int LayerInfo::*nl_d, void (MkBase::*p_f) (float, const int), @@ -50,7 +48,6 @@ struct SteeringParams void (MkFitter::*fcmc_f)(const LayerOfHits &, CandCloner &, const int, const int)) : compute_chi2_foo(cch2_f), update_param_foo(updp_f), - select_hit_idcs_foo(shi_f), first_finding_layer(ffl), next_layer_doo(nl_d), propagate_foo(p_f), From 2665bff471eee4d2754e66a189014dfbab8c68c7 Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Thu, 15 Jun 2017 01:01:24 -0700 Subject: [PATCH 068/172] Full endcap support for FindTracksBestHit. * Seeds that start on later layers are properly added as the corresponding layer is reached. * AddBestHit/Endcap removed from MkFitter. --- Event.h | 3 +- Track.cc | 1 + mkFit/MkBuilder.cc | 99 +++++++---- mkFit/MkFinder.cc | 64 +++++-- mkFit/MkFinder.h | 17 +- mkFit/MkFitter.cc | 366 ----------------------------------------- mkFit/MkFitter.h | 3 - mkFit/SteeringParams.h | 3 - mkFit/mt-notes.txt | 30 +++- 9 files changed, 154 insertions(+), 432 deletions(-) diff --git a/Event.h b/Event.h index a0a0d68a29064..52805e511ff5a 100644 --- a/Event.h +++ b/Event.h @@ -30,7 +30,7 @@ class Event int evtID() const {return evtID_;} void resetLayerHitMap(bool resetSimHits); - int nextMCHitID() { return mcHitIDCounter_++; } + int nextMCHitID() { return mcHitIDCounter_++; } void write_out(DataFile &data_file); void read_in (DataFile &data_file); @@ -59,6 +59,7 @@ class Event // This will have to be extended for multi-pass tracking. int seedEtaSeparators_[5]; int seedMinLastLayer_[5]; + int seedMaxLastLayer_[5]; TSVec simTrackStates_; static std::mutex printmutex; diff --git a/Track.cc b/Track.cc index a3ac0ecb88808..b7b7269ed267f 100644 --- a/Track.cc +++ b/Track.cc @@ -182,6 +182,7 @@ void TrackExtra::setMCTrackIDInfo(const Track& trk, const std::vector& l if (isSeed) mcTrackID_ = mcTrackID; else { + // XXXXMT4K Requires Track::nFoundUniqueLayerHits() or Track::nFoundLayers() const int nMinSimHits = simtracks[mcTrackID].nFoundHits() * Config::nMinSimHitsFrac; const int minFoundHits = ((nMinSimHits >= Config::nMinFoundHits) ? Config::nMinFoundHits : nMinSimHits); diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index c46af8b4a2746..61bf9872a6c8e 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -188,7 +188,6 @@ MkBuilder::MkBuilder() : &LayerInfo::m_next_ecap_neg, &MkBase::PropagateTracksToZ, &MkFitter::SelectHitIndicesEndcap, - &MkFitter::AddBestHitEndcap, &MkFitter::UpdateWithLastHitEndcap, &MkFitter::FindCandidatesEndcap, &MkFitter::FindCandidatesMinimizeCopyEndcap @@ -204,7 +203,6 @@ MkBuilder::MkBuilder() : &LayerInfo::m_next_barrel, &MkBase::PropagateTracksToR, &MkFitter::SelectHitIndices, - &MkFitter::AddBestHit, &MkFitter::UpdateWithLastHit, &MkFitter::FindCandidates, &MkFitter::FindCandidatesMinimizeCopy @@ -220,7 +218,6 @@ MkBuilder::MkBuilder() : &LayerInfo::m_next_ecap_pos, &MkBase::PropagateTracksToZ, &MkFitter::SelectHitIndicesEndcap, - &MkFitter::AddBestHitEndcap, &MkFitter::UpdateWithLastHitEndcap, &MkFitter::FindCandidatesEndcap, &MkFitter::FindCandidatesMinimizeCopyEndcap @@ -389,7 +386,7 @@ void MkBuilder::import_seeds() // Seeds are sorted by eta and counts for each eta region are // stored into Event::seedEtaSeparators_. - bool debug = true; + // bool debug = true; if (Config::readCmsswSeeds) { @@ -409,6 +406,7 @@ void MkBuilder::import_seeds() { m_event->seedEtaSeparators_[i] = 0; m_event->seedMinLastLayer_ [i] = 9999; + m_event->seedMaxLastLayer_ [i] = 0; } std::vector etas(size); @@ -423,10 +421,12 @@ void MkBuilder::import_seeds() TrackerInfo::EtaRegion reg = Config::TrkInfo.find_eta_region(eta); ++m_event->seedEtaSeparators_[reg]; m_event->seedMinLastLayer_[reg] = std::min(m_event->seedMinLastLayer_[reg], hot.layer); + m_event->seedMaxLastLayer_[reg] = std::max(m_event->seedMaxLastLayer_[reg], hot.layer); } for (int i = 0; i < 5; ++i) { if (m_event->seedMinLastLayer_[i] == 9999) m_event->seedMinLastLayer_[i] = -1; + if (m_event->seedMaxLastLayer_[i] == 0) m_event->seedMaxLastLayer_[i] = -1; } RadixSort rs; @@ -441,13 +441,13 @@ void MkBuilder::import_seeds() } dprintf("MkBuilder::import_seeds finished import of %d seeds (last seeding layer):\n" - " ec- = %d(%d), t- = %d(%d), brl = %d(%d), t+ = %d(%d), ec+ = %d(%d).\n", + " ec- = %d(%d,%d), t- = %d(%d,%d), brl = %d(%d,%d), t+ = %d(%d,%d), ec+ = %d(%d,%d).\n", size, - m_event->seedEtaSeparators_[0], m_event->seedMinLastLayer_[0], - m_event->seedEtaSeparators_[1], m_event->seedMinLastLayer_[1], - m_event->seedEtaSeparators_[2], m_event->seedMinLastLayer_[2], - m_event->seedEtaSeparators_[3], m_event->seedMinLastLayer_[3], - m_event->seedEtaSeparators_[4], m_event->seedMinLastLayer_[4]); + m_event->seedEtaSeparators_[0], m_event->seedMinLastLayer_[0], m_event->seedMaxLastLayer_[0], + m_event->seedEtaSeparators_[1], m_event->seedMinLastLayer_[1], m_event->seedMaxLastLayer_[1], + m_event->seedEtaSeparators_[2], m_event->seedMinLastLayer_[2], m_event->seedMaxLastLayer_[2], + m_event->seedEtaSeparators_[3], m_event->seedMinLastLayer_[3], m_event->seedMaxLastLayer_[3], + m_event->seedEtaSeparators_[4], m_event->seedMinLastLayer_[4], m_event->seedMaxLastLayer_[4]); // Sum region counts up to contain actual separator indices: for (int i = TrackerInfo::Reg_Transition_Neg; i < TrackerInfo::Reg_Count; ++i) @@ -543,7 +543,7 @@ void MkBuilder::fit_seeds() // But we shot ourselves into the foot by doing propagation at the end of the loop. // Seemed like a good idea at the time. - // debug=true; + // debug = true; g_exe_ctx.populate(Config::numThreadsFinder); const TrackerInfo &trk_info = Config::TrkInfo; @@ -639,7 +639,7 @@ inline void MkBuilder::fit_one_seed_set(TrackVec& seedtracks, int itrack, int en MkFitter *mkfttr, const bool is_brl[], const SteeringParams &st_par) { - //debug=true; + // debug=true; mkfttr->SetNhits(Config::nlayers_per_seed); mkfttr->InputTracksAndHits(seedtracks, m_event_of_hits.m_layers_of_hits, itrack, end); @@ -900,6 +900,7 @@ void MkBuilder::quality_process(Track &tkcand) { ptmc = m_event->simTracks_[mctrk].pT() ; pr = pt / ptmc; + // XXXXMT4K Requires Track::nFoundUniqueLayerHits() or Track::nFoundLayers() nfoundmc = m_event->simTracks_[mctrk].nFoundHits(); chi2mc = m_event->simTracks_[mctrk].chi2();//this is actually the number of reco hits in cmssw @@ -1061,10 +1062,6 @@ void MkBuilder::FindTracksBestHit() const RegionOfSeedIndices rosi(m_event, region); - // XXXXMT to be done on bunch basis, requires equalization or multi-pass - int last_seed_layer = m_event->seedMinLastLayer_[region]; - int first_layer = trk_info.m_layers[last_seed_layer].*st_par.next_layer_doo; - tbb::parallel_for(rosi.tbb_blk_rng_vec(), [&](const tbb::blocked_range& blk_rng) { @@ -1072,20 +1069,48 @@ void MkBuilder::FindTracksBestHit() RangeOfSeedIndices rng = rosi.seed_rng(blk_rng); + std::vector trk_idcs(NN); + std::vector trk_llay(NN); + while (rng.valid()) { dprint(std::endl << "processing track=" << rng.m_beg << ", label=" <InputTracksAndHitIdx(cands, rng.m_beg, rng.m_end, false); + int prev_layer = 9999; + for (int i = rng.m_beg, ii = 0; i < rng.m_end; ++i, ++ii) + { + int llay = cands[i].getLastHitLyr(); + trk_llay[ii] = llay; + prev_layer = std::min(prev_layer, llay); + } + int curr_layer = trk_info.m_layers[prev_layer].*st_par.next_layer_doo; + int curr_tridx = 0; // Loop over layers, starting from after the seed. // Consider inverting loop order and make layer outer, need to // trade off hit prefetching with copy-out of candidates. - for (int ilay = first_layer; ; ) + while (true) { - dprint("at layer " << ilay); - const LayerOfHits &layer_of_hits = m_event_of_hits.m_layers_of_hits[ilay]; - const LayerInfo &layer_info = trk_info.m_layers[ilay]; + dprint("at layer " << curr_layer); + const LayerOfHits &layer_of_hits = m_event_of_hits.m_layers_of_hits[curr_layer]; + const LayerInfo &layer_info = trk_info.m_layers[curr_layer]; + + // Pick up seeds that become active on current layer -- unless already fully loaded. + if (curr_tridx < rng.n_proc()) + { + int prev_tridx = curr_tridx; + + for (int i = rng.m_beg, ii = 0; i < rng.m_end; ++i, ++ii) + { + if (trk_llay[ii] == prev_layer) trk_idcs[curr_tridx++] = i; + } + if (curr_tridx > prev_tridx) + { + dprintf("added %d seeds, started with %d\n", curr_tridx - prev_tridx, prev_tridx); + + mkfndr->InputTracksAndHitIdx(cands, trk_idcs, prev_tridx, curr_tridx, false, prev_tridx); + } + } // XXX This should actually be done in some other thread for the next layer while // this thread is crunching the current one. @@ -1095,32 +1120,33 @@ void MkBuilder::FindTracksBestHit() // _mm_prefetch((char*) & bunch_of_hits.m_hits[i], _MM_HINT_T1); // } - dcall(pre_prop_print(ilay, mkfndr.get())); + dcall(pre_prop_print(curr_layer, mkfndr.get())); - (mkfndr.get()->*st_par.propagate_foo)(trk_info.m_layers[ilay].m_propagate_to, rng.n_proc()); + (mkfndr.get()->*st_par.propagate_foo)(layer_info.m_propagate_to, curr_tridx); - dcall(post_prop_print(ilay, mkfndr.get())); + dcall(post_prop_print(curr_layer, mkfndr.get())); - mkfndr->SelectHitIndices(layer_of_hits, rng.n_proc(), false); + mkfndr->SelectHitIndices(layer_of_hits, curr_tridx, false); // #ifdef PRINTOUTS_FOR_PLOTS -// std::cout << "MX number of hits in window in layer " << ilay << " is " << mkfndr->getXHitEnd(0, 0, 0)-mkfndr->getXHitBegin(0, 0, 0) << std::endl; +// std::cout << "MX number of hits in window in layer " << curr_layer << " is " << mkfndr->getXHitEnd(0, 0, 0)-mkfndr->getXHitBegin(0, 0, 0) << std::endl; // #endif // make candidates with best hit dprint("make new candidates"); - mkfndr->AddBestHit(layer_of_hits, rng.n_proc(), st_par); + mkfndr->AddBestHit(layer_of_hits, curr_tridx, st_par); if (layer_info.m_is_outer) { break; } - ilay = layer_info.*st_par.next_layer_doo; + prev_layer = curr_layer; + curr_layer = layer_info.*st_par.next_layer_doo; } // end of layer loop - mkfndr->OutputTracksAndHitIdx(cands, rng.m_beg, rng.m_end, false); + mkfndr->OutputTracksAndHitIdx(cands, trk_idcs, 0, curr_tridx, false); ++rng; } // end of loop over candidates in a tbb chunk @@ -1193,7 +1219,7 @@ void MkBuilder::FindTracksStandard() // prepare unrolled vector to loop over std::vector > seed_cand_idx; - + for (int iseed = start_seed; iseed < end_seed; ++iseed) { std::vector &scands = eoccs[iseed]; @@ -1230,8 +1256,8 @@ void MkBuilder::FindTracksStandard() //fixme find a way to deal only with the candidates needed in this thread mkfndr->InputTracksAndHitIdx(eoccs.m_candidates, - seed_cand_idx, itrack, end, - false); + seed_cand_idx, itrack, end, + false); //propagate to layer dcall(pre_prop_print(ilay, mkfndr.get())); @@ -1268,14 +1294,15 @@ void MkBuilder::FindTracksStandard() } dprint("dump seed n " << is << " with output candidates=" << tmp_cands[is].size()); } - //now swap with input candidates + // now swap with input candidates for (int is = 0; is < tmp_cands.size(); ++is) { if (tmp_cands[is].size() > 0) { // Copy the best -2 cands back to the current list. int num_hits = tmp_cands[is].size(); - + + // XXXXMT This looks BAD if (num_hits < Config::maxCandsPerSeed) { std::vector &ov = eoccs[start_seed+is]; @@ -1303,8 +1330,8 @@ void MkBuilder::FindTracksStandard() ++n_hits; ilay = layer_info.*st_par.next_layer_doo; } // end of layer loop - - // final sorting + + // final sorting for (int iseed = start_seed; iseed < end_seed; ++iseed) { std::vector& finalcands = eoccs[iseed]; diff --git a/mkFit/MkFinder.cc b/mkFit/MkFinder.cc index 0f8f89d0df8cf..33725b5a2ae5f 100644 --- a/mkFit/MkFinder.cc +++ b/mkFit/MkFinder.cc @@ -22,10 +22,26 @@ void MkFinder::InputTracksAndHitIdx(const std::vector& tracks, const int iI = inputProp ? iP : iC; - int itrack = 0; - for (int i = beg; i < end; ++i, ++itrack) + for (int i = beg, imp = 0; i < end; ++i, ++imp) { - copy_in(tracks[i], itrack, iI); + copy_in(tracks[i], imp, iI); + } +} + +void MkFinder::InputTracksAndHitIdx(const std::vector& tracks, + const std::vector & idxs, + int beg, int end, bool inputProp, int mp_offset) +{ + // Assign track parameters to initial state and copy hit values in. + + // This might not be true for the last chunk! + // assert(end - beg == NN); + + const int iI = inputProp ? iP : iC; + + for (int i = beg, imp = mp_offset; i < end; ++i, ++imp) + { + copy_in(tracks[idxs[i]], imp, iI); } } @@ -40,15 +56,14 @@ void MkFinder::InputTracksAndHitIdx(const std::vector >& trac const int iI = inputProp ? iP : iC; - int itrack = 0; - for (int i = beg; i < end; ++i, ++itrack) + for (int i = beg, imp = 0; i < end; ++i, ++imp) { const Track &trk = tracks[idxs[i].first][idxs[i].second]; - copy_in(trk, itrack, iI); + copy_in(trk, imp, iI); - SeedIdx(itrack, 0, 0) = idxs[i].first; - CandIdx(itrack, 0, 0) = idxs[i].second; + SeedIdx(imp, 0, 0) = idxs[i].first; + CandIdx(imp, 0, 0) = idxs[i].second; } } @@ -63,15 +78,14 @@ void MkFinder::InputTracksAndHitIdx(const std::vector >& trac const int iI = inputProp ? iP : iC; - int itrack = 0; - for (int i = beg; i < end; ++i, ++itrack) + for (int i = beg, imp = 0; i < end; ++i, ++imp) { const Track &trk = tracks[idxs[i].first][idxs[i].second.trkIdx]; - copy_in(trk, itrack, iI); + copy_in(trk, imp, iI); - SeedIdx(itrack, 0, 0) = idxs[i].first; - CandIdx(itrack, 0, 0) = idxs[i].second.trkIdx; + SeedIdx(imp, 0, 0) = idxs[i].first; + CandIdx(imp, 0, 0) = idxs[i].second.trkIdx; } } @@ -83,10 +97,24 @@ void MkFinder::OutputTracksAndHitIdx(std::vector& tracks, const int iO = outputProp ? iP : iC; - int itrack = 0; - for (int i = beg; i < end; ++i, ++itrack) + for (int i = beg, imp = 0; i < end; ++i, ++imp) { - copy_out(tracks[i], itrack, iO); + copy_out(tracks[i], imp, iO); + } +} + +void MkFinder::OutputTracksAndHitIdx(std::vector& tracks, + const std::vector& idxs, + int beg, int end, bool outputProp) const +{ + // Copies requested track parameters into Track objects. + // The tracks vector should be resized to allow direct copying. + + const int iO = outputProp ? iP : iC; + + for (int i = beg, imp = 0; i < end; ++i, ++imp) + { + copy_out(tracks[idxs[i]], imp, iO); } } @@ -271,10 +299,14 @@ void MkFinder::SelectHitIndices(const LayerOfHits &layer_of_hits, } } + //============================================================================== // AddBestHit //============================================================================== +//#define NO_PREFETCH +//#define NO_GATHER + void MkFinder::AddBestHit(const LayerOfHits &layer_of_hits, const int N_proc, const SteeringParams &st_par) { diff --git a/mkFit/MkFinder.h b/mkFit/MkFinder.h index f47fda645d683..1931d6a50c7ba 100644 --- a/mkFit/MkFinder.h +++ b/mkFit/MkFinder.h @@ -76,17 +76,26 @@ class MkFinder : public MkBase void InputTracksAndHitIdx(const std::vector& tracks, int beg, int end, bool inputProp); - void InputTracksAndHitIdx(const std::vector >& tracks, - const std::vector >& idxs, + + void InputTracksAndHitIdx(const std::vector& tracks, + const std::vector & idxs, + int beg, int end, bool inputProp, int mp_offset); + + void InputTracksAndHitIdx(const std::vector>& tracks, + const std::vector>& idxs, int beg, int end, bool inputProp); - void InputTracksAndHitIdx(const std::vector >& tracks, - const std::vector >& idxs, + void InputTracksAndHitIdx(const std::vector>& tracks, + const std::vector>& idxs, int beg, int end, bool inputProp); void OutputTracksAndHitIdx(std::vector& tracks, int beg, int end, bool outputProp) const; + void OutputTracksAndHitIdx(std::vector& tracks, + const std::vector& idxs, + int beg, int end, bool outputProp) const; + //---------------------------------------------------------------------------- void SelectHitIndices(const LayerOfHits &layer_of_hits, const int N_proc, bool dump=false); diff --git a/mkFit/MkFitter.cc b/mkFit/MkFitter.cc index 0cb9b27157e67..5226e2a3f761b 100644 --- a/mkFit/MkFitter.cc +++ b/mkFit/MkFitter.cc @@ -830,192 +830,6 @@ void MkFitter::SelectHitIndices(const LayerOfHits &layer_of_hits, const int N_pr } } -//============================================================================== -// AddBestHit() -//============================================================================== - -//#define NO_PREFETCH -//#define NO_GATHER - -void MkFitter::AddBestHit(const LayerOfHits &layer_of_hits, const int N_proc) -{ - // debug = true; - - float minChi2[NN]; - int bestHit[NN]; - // MT: fill_n gave me crap on MIC, NN=8,16, doing in maxSize search below. - // Must be a compiler issue. - // std::fill_n(minChi2, NN, Config::chi2Cut); - // std::fill_n(bestHit, NN, -1); - - const char *varr = (char*) layer_of_hits.m_hits; - - const int off_error = (char*) layer_of_hits.m_hits[0].errArray() - varr; - const int off_param = (char*) layer_of_hits.m_hits[0].posArray() - varr; - - int idx[NN] __attribute__((aligned(64))); - - int maxSize = 0; - - // Determine maximum number of hits for tracks in the collection. - // At the same time prefetch the first set of hits to L1 and the second one to L2. - for (int it = 0; it < NN; ++it) - { - if (it < N_proc) - { - if (XHitSize[it] > 0) - { -#ifndef NO_PREFETCH - _mm_prefetch(varr + XHitArr.At(it, 0, 0) * sizeof(Hit), _MM_HINT_T0); - if (XHitSize[it] > 1) - { - _mm_prefetch(varr + XHitArr.At(it, 1, 0) * sizeof(Hit), _MM_HINT_T1); - } -#endif - maxSize = std::max(maxSize, XHitSize[it]); - } - } - - idx[it] = 0; - bestHit[it] = -1; - minChi2[it] = Config::chi2Cut; - } - -// Has basically no effect, it seems. -//#pragma noprefetch - for (int hit_cnt = 0; hit_cnt < maxSize; ++hit_cnt) - { - //fixme what if size is zero??? - -#pragma simd - for (int itrack = 0; itrack < N_proc; ++itrack) - { - if (hit_cnt < XHitSize[itrack]) - { - idx[itrack] = XHitArr.At(itrack, hit_cnt, 0) * sizeof(Hit); - } - } -#if defined(MIC_INTRINSICS) - __m512i vi = _mm512_load_epi32(idx); -#endif - -#ifndef NO_PREFETCH - // Prefetch to L2 the hits we'll process after two loops iterations. - // Ideally this would be initiated before coming here, for whole bunch_of_hits.m_hits vector. - for (int itrack = 0; itrack < N_proc; ++itrack) - { - if (hit_cnt + 2 < XHitSize[itrack]) - { - _mm_prefetch(varr + XHitArr.At(itrack, hit_cnt+2, 0)*sizeof(Hit), _MM_HINT_T1); - } - } -#endif - -#ifdef NO_GATHER - -#pragma simd - for (int itrack = 0; itrack < N_proc; ++itrack) - { - if (hit_cnt < XHitSize[itrack]) - { - const Hit &hit = layer_of_hits.m_hits[XHitArr.At(itrack, hit_cnt, 0)]; - msErr[Nhits].CopyIn(itrack, hit.errArray()); - msPar[Nhits].CopyIn(itrack, hit.posArray()); - } - } - -#else //NO_GATHER - -#if defined(MIC_INTRINSICS) - msErr[Nhits].SlurpIn(varr + off_error, vi); - msPar[Nhits].SlurpIn(varr + off_param, vi); -#else - msErr[Nhits].SlurpIn(varr + off_error, idx); - msPar[Nhits].SlurpIn(varr + off_param, idx); -#endif -#endif //NO_GATHER - - //now compute the chi2 of track state vs hit - MPlexQF outChi2; - computeChi2MPlex(Err[iP], Par[iP], Chg, msErr[Nhits], msPar[Nhits], outChi2, N_proc); - -#ifndef NO_PREFETCH - // Prefetch to L1 the hits we'll process in the next loop iteration. - for (int itrack = 0; itrack < N_proc; ++itrack) - { - if (hit_cnt + 1 < XHitSize[itrack]) - { - _mm_prefetch(varr + XHitArr.At(itrack, hit_cnt+1, 0)*sizeof(Hit), _MM_HINT_T0); - } - } -#endif - - //update best hit in case chi2& seeds) { - FITTER( mkfndr ); - - const TrackerInfo &trk_info = Config::TrkInfo; + FINDER( mkfndr ); const int start_seed = seeds.begin(); const int end_seed = seeds.end(); - const int nseeds = end_seed - start_seed; + const int n_seeds = end_seed - start_seed; - // Loop over layers, starting from after the seed. - int n_hits = Config::nlayers_per_seed; + std::vector> tmp_cands(n_seeds); + for (int iseed = 0; iseed < tmp_cands.size(); ++iseed) + { + tmp_cands[iseed].reserve(2*Config::maxCandsPerSeed);//factor 2 seems reasonable to start with + } + + std::vector> seed_cand_idx; + seed_cand_idx.reserve(n_seeds * Config::maxCandsPerSeed); - for (int ilay = st_par.first_finding_layer; ; ) + // Loop over layers, starting from after the seed. + for (int ilay = first_layer; ; ) { dprint("processing lay=" << ilay); @@ -1218,14 +1224,12 @@ void MkBuilder::FindTracksStandard() const LayerInfo &layer_info = trk_info.m_layers[ilay]; // prepare unrolled vector to loop over - std::vector > seed_cand_idx; - for (int iseed = start_seed; iseed < end_seed; ++iseed) { std::vector &scands = eoccs[iseed]; for (int ic = 0; ic < scands.size(); ++ic) { - if (scands[ic].getLastHitIdx() >= -1) + if (scands[ic].getLastHitIdx() != -2 && scands[ic].getLastHitLyr() < ilay) { seed_cand_idx.push_back(std::pair(iseed,ic)); } @@ -1233,27 +1237,15 @@ void MkBuilder::FindTracksStandard() } int theEndCand = seed_cand_idx.size(); - if (theEndCand == 0) continue; - - std::vector> tmp_cands(nseeds); - for (int iseed = 0; iseed < tmp_cands.size(); ++iseed) - { - // XXXX MT: Tried adding 25 to reserve below as I was seeing some - // time spent in push_back ... but it didn't really help. - // We need to optimize this by throwing away and replacing the worst - // candidate once a better one arrives. This will also avoid sorting. - tmp_cands[iseed].reserve(2*Config::maxCandsPerSeed);//factor 2 seems reasonable to start with - } + if (theEndCand == 0) goto next_layer; - //vectorized loop + // vectorized loop for (int itrack = 0; itrack < theEndCand; itrack += NN) { int end = std::min(itrack + NN, theEndCand); dprint("processing track=" << itrack); - mkfndr->SetNhits(n_hits); //here again assuming one hit per layer - //fixme find a way to deal only with the candidates needed in this thread mkfndr->InputTracksAndHitIdx(eoccs.m_candidates, seed_cand_idx, itrack, end, @@ -1267,20 +1259,20 @@ void MkBuilder::FindTracksStandard() dcall(post_prop_print(ilay, mkfndr.get())); dprint("now get hit range"); - (mkfndr.get()->*st_par.select_hits_foo)(layer_of_hits, end - itrack, false); + mkfndr->SelectHitIndices(layer_of_hits, end - itrack, false); //#ifdef PRINTOUTS_FOR_PLOTS //std::cout << "MX number of hits in window in layer " << ilay << " is " << mkfndr->getXHitEnd(0, 0, 0)-mkfndr->getXHitBegin(0, 0, 0) << std::endl; //#endif dprint("make new candidates"); - (mkfndr.get()->*st_par.find_cands_foo)(layer_of_hits, tmp_cands, start_seed, end - itrack); - + mkfndr->FindCandidates(layer_of_hits, tmp_cands, start_seed, end - itrack, st_par); + } //end of vectorized loop // clean exceeding candidates per seed // FIXME: is there a reason why these are not vectorized???? - for (int is = 0; is < tmp_cands.size(); ++is) + for (int is = 0; is < n_seeds; ++is) { dprint("dump seed n " << is << " with input candidates=" << tmp_cands[is].size()); std::sort(tmp_cands[is].begin(), tmp_cands[is].end(), sortCandByHitsChi2); @@ -1295,25 +1287,24 @@ void MkBuilder::FindTracksStandard() dprint("dump seed n " << is << " with output candidates=" << tmp_cands[is].size()); } // now swap with input candidates - for (int is = 0; is < tmp_cands.size(); ++is) + for (int is = 0; is < n_seeds; ++is) { if (tmp_cands[is].size() > 0) { // Copy the best -2 cands back to the current list. - int num_hits = tmp_cands[is].size(); + int num_cands = tmp_cands[is].size(); - // XXXXMT This looks BAD - if (num_hits < Config::maxCandsPerSeed) + if (num_cands < Config::maxCandsPerSeed) { - std::vector &ov = eoccs[start_seed+is]; + std::vector &ov = eoccs[start_seed + is]; const int max_m2 = ov.size(); - + int cur_m2 = 0; while (cur_m2 < max_m2 && ov[cur_m2].getLastHitIdx() != -2) ++cur_m2; - while (cur_m2 < max_m2 && num_hits < Config::maxCandsPerSeed) + while (cur_m2 < max_m2 && num_cands < Config::maxCandsPerSeed) { tmp_cands[is].push_back( ov[cur_m2++] ); - ++num_hits; + ++num_cands; } } @@ -1321,13 +1312,15 @@ void MkBuilder::FindTracksStandard() tmp_cands[is].clear(); } } + seed_cand_idx.clear(); + + next_layer: if (layer_info.m_is_outer) { break; } - ++n_hits; ilay = layer_info.*st_par.next_layer_doo; } // end of layer loop diff --git a/mkFit/MkFinder.cc b/mkFit/MkFinder.cc index 33725b5a2ae5f..e786b4329f5fc 100644 --- a/mkFit/MkFinder.cc +++ b/mkFit/MkFinder.cc @@ -301,7 +301,7 @@ void MkFinder::SelectHitIndices(const LayerOfHits &layer_of_hits, //============================================================================== -// AddBestHit +// AddBestHit - Best Hit Track Finding //============================================================================== //#define NO_PREFETCH @@ -475,7 +475,6 @@ void MkFinder::AddBestHit(const LayerOfHits &layer_of_hits, const int N_proc, layer_of_hits.is_in_xy_hole(Par[iP](itrack,0,0), Par[iP](itrack,1,0))) { // YYYYYY Config::store_missed_layers - fake_hit_idx = -3; } @@ -502,12 +501,170 @@ void MkFinder::AddBestHit(const LayerOfHits &layer_of_hits, const int N_proc, } //============================================================================== -// FindCandidates + Endcap +// FindCandidates - Standard Track Finding //============================================================================== +void MkFinder::FindCandidates(const LayerOfHits &layer_of_hits, + std::vector>& tmp_candidates, + const int offset, const int N_proc, + const SteeringParams &st_par) +{ + const char *varr = (char*) layer_of_hits.m_hits; + + const int off_error = (char*) layer_of_hits.m_hits[0].errArray() - varr; + const int off_param = (char*) layer_of_hits.m_hits[0].posArray() - varr; + + int idx[NN] __attribute__((aligned(64))); + + int maxSize = 0; + + // Determine maximum number of hits for tracks in the collection. + // At the same time prefetch the first set of hits to L1 and the second one to L2. + for (int it = 0; it < NN; ++it) + { + if (it < N_proc) + { + if (XHitSize[it] > 0) + { + _mm_prefetch(varr + XHitArr.At(it, 0, 0) * sizeof(Hit), _MM_HINT_T0); + if (XHitSize[it] > 1) + { + _mm_prefetch(varr + XHitArr.At(it, 1, 0) * sizeof(Hit), _MM_HINT_T1); + } + maxSize = std::max(maxSize, XHitSize[it]); + } + } + + idx[it] = 0; + } + + // Has basically no effect, it seems. + //#pragma noprefetch + for (int hit_cnt = 0; hit_cnt < maxSize; ++hit_cnt) + { +#pragma simd + for (int itrack = 0; itrack < N_proc; ++itrack) + { + if (hit_cnt < XHitSize[itrack]) + { + idx[itrack] = XHitArr.At(itrack, hit_cnt, 0) * sizeof(Hit); + } + } +#if defined(MIC_INTRINSICS) + __m512i vi = _mm512_load_epi32(idx); +#endif + + // Prefetch to L2 the hits we'll (probably) process after two loops iterations. + // Ideally this would be initiated before coming here, for whole bunch_of_hits.m_hits vector. + for (int itrack = 0; itrack < N_proc; ++itrack) + { + if (hit_cnt + 2 < XHitSize[itrack]) + { + _mm_prefetch(varr + XHitArr.At(itrack, hit_cnt+2, 0)*sizeof(Hit), _MM_HINT_T1); + } + } + +#if defined(MIC_INTRINSICS) + msErr.SlurpIn(varr + off_error, vi); + msPar.SlurpIn(varr + off_param, vi); +#else + msErr.SlurpIn(varr + off_error, idx); + msPar.SlurpIn(varr + off_param, idx); +#endif + + //now compute the chi2 of track state vs hit + MPlexQF outChi2; + (*st_par.compute_chi2_foo)(Err[iP], Par[iP], Chg, msErr, msPar, + outChi2, N_proc); + + // Prefetch to L1 the hits we'll (probably) process in the next loop iteration. + for (int itrack = 0; itrack < N_proc; ++itrack) + { + if (hit_cnt + 1 < XHitSize[itrack]) + { + _mm_prefetch(varr + XHitArr.At(itrack, hit_cnt+1, 0)*sizeof(Hit), _MM_HINT_T0); + } + } + + //now update the track parameters with this hit (note that some calculations are already done when computing chi2, to be optimized) + //this is not needed for candidates the hit is not added to, but it's vectorized so doing it serially below should take the same time + //still it's a waste of time in case the hit is not added to any of the candidates, so check beforehand that at least one cand needs update + bool oneCandPassCut = false; + for (int itrack = 0; itrack < N_proc; ++itrack) + { + if (hit_cnt < XHitSize[itrack]) + { + const float chi2 = std::abs(outChi2[itrack]);//fixme negative chi2 sometimes... + dprint("chi2=" << chi2); + if (chi2 < Config::chi2Cut) + { + oneCandPassCut = true; + break; + } + } + } + + if (oneCandPassCut) + { + (*st_par.update_param_foo)(Err[iP], Par[iP], Chg, msErr, msPar, + Err[iC], Par[iC], N_proc); + + dprint("update parameters" << std::endl + << "propagated track parameters x=" << Par[iP].ConstAt(0, 0, 0) << " y=" << Par[iP].ConstAt(0, 1, 0) << std::endl + << " hit position x=" << msPar.ConstAt(0, 0, 0) << " y=" << msPar.ConstAt(0, 1, 0) << std::endl + << " updated track parameters x=" << Par[iC].ConstAt(0, 0, 0) << " y=" << Par[iC].ConstAt(0, 1, 0)); + + //create candidate with hit in case chi2 < Config::chi2Cut + //fixme: please vectorize me... (not sure it's possible in this case) + for (int itrack = 0; itrack < N_proc; ++itrack) + { + if (hit_cnt < XHitSize[itrack]) + { + const float chi2 = std::abs(outChi2[itrack]);//fixme negative chi2 sometimes... + dprint("chi2=" << chi2); + if (chi2 < Config::chi2Cut) + { + dprint("chi2 cut passed, creating new candidate"); + //create a new candidate and fill the reccands_tmp vector + Track newcand; + copy_out(newcand, itrack, iC); + newcand.addHitIdx(XHitArr.At(itrack, hit_cnt, 0), layer_of_hits.layer_id(), chi2); + + dprint("updated track parameters x=" << newcand.parameters()[0] << " y=" << newcand.parameters()[1] << " z=" << newcand.parameters()[2] << " pt=" << 1./newcand.parameters()[3]); + + tmp_candidates[SeedIdx(itrack, 0, 0) - offset].emplace_back(newcand); + } + } + } + }//end if (oneCandPassCut) + + }//end loop over hits + + //now add invalid hit + //fixme: please vectorize me... + for (int itrack = 0; itrack < N_proc; ++itrack) + { + int fake_hit_idx = (NHits(itrack,0,0) - NFoundHits(itrack,0,0)) < Config::maxHolesPerCand ? -1 : -2; + + if (layer_of_hits.is_endcap() && + layer_of_hits.is_in_xy_hole(Par[iP](itrack,0,0), Par[iP](itrack,1,0))) + { + // YYYYYY Config::store_missed_layers + fake_hit_idx = -3; + } + + dprint("ADD FAKE HIT FOR TRACK #" << itrack << " withinBounds=" << (fake_hit_idx != -3) << " r=" << std::hypot(Par[iP](itrack,0,0), Par[iP](itrack,1,0))); + + Track newcand; + copy_out(newcand, itrack, iP); + newcand.addHitIdx(fake_hit_idx, layer_of_hits.layer_id(), 0.); + tmp_candidates[SeedIdx(itrack, 0, 0) - offset].emplace_back(newcand); + } +} + //============================================================================== -// FindCandidatesMinimizeCopy + Endcap +// FindCandidatesMinimizeCopy - Clone Engine Track Finding //============================================================================== diff --git a/mkFit/MkFinder.h b/mkFit/MkFinder.h index 1931d6a50c7ba..0bcd2deca6e61 100644 --- a/mkFit/MkFinder.h +++ b/mkFit/MkFinder.h @@ -105,15 +105,16 @@ class MkFinder : public MkBase //---------------------------------------------------------------------------- - void FindCandidates(const LayerOfHits &layer_of_hits, std::vector>& tmp_candidates, - const int offset, const int N_proc); - void FindCandidatesEndcap(const LayerOfHits &layer_of_hits, std::vector>& tmp_candidates, - const int offset, const int N_proc); + void FindCandidates(const LayerOfHits &layer_of_hits, + std::vector>& tmp_candidates, + const int offset, const int N_proc, + const SteeringParams &st_par); //---------------------------------------------------------------------------- void FindCandidatesMinimizeCopy(const LayerOfHits &layer_of_hits, CandCloner& cloner, - const int offset, const int N_proc); + const int offset, const int N_proc, + const SteeringParams &st_par); void FindCandidatesMinimizeCopyEndcap(const LayerOfHits &layer_of_hits, CandCloner& cloner, const int offset, const int N_proc); @@ -152,7 +153,7 @@ class MkFinder : public MkBase trk.setNTotalHits(NHits (mslot, 0, 0)); trk.setNFoundHits(NFoundHits(mslot, 0, 0)); - std::copy(HoTArrs[mslot], HoTArrs[mslot + 1], trk.BeginHitsOnTrack_nc()); + std::copy(HoTArrs[mslot], & HoTArrs[mslot][NHits(mslot, 0, 0)], trk.BeginHitsOnTrack_nc()); } void add_hit(const int mslot, int index, int layer) diff --git a/mkFit/MkFitter.cc b/mkFit/MkFitter.cc index 5226e2a3f761b..1d18cca35e349 100644 --- a/mkFit/MkFitter.cc +++ b/mkFit/MkFitter.cc @@ -831,340 +831,6 @@ void MkFitter::SelectHitIndices(const LayerOfHits &layer_of_hits, const int N_pr } -void MkFitter::FindCandidates(const LayerOfHits &layer_of_hits, - std::vector>& tmp_candidates, - const int offset, const int N_proc) -{ - const char *varr = (char*) layer_of_hits.m_hits; - - const int off_error = (char*) layer_of_hits.m_hits[0].errArray() - varr; - const int off_param = (char*) layer_of_hits.m_hits[0].posArray() - varr; - - int idx[NN] __attribute__((aligned(64))); - - int maxSize = 0; - - // Determine maximum number of hits for tracks in the collection. - // At the same time prefetch the first set of hits to L1 and the second one to L2. - for (int it = 0; it < NN; ++it) - { - if (it < N_proc) - { - if (XHitSize[it] > 0) - { - _mm_prefetch(varr + XHitArr.At(it, 0, 0) * sizeof(Hit), _MM_HINT_T0); - if (XHitSize[it] > 1) - { - _mm_prefetch(varr + XHitArr.At(it, 1, 0) * sizeof(Hit), _MM_HINT_T1); - } - maxSize = std::max(maxSize, XHitSize[it]); - } - } - - idx[it] = 0; - } - - // Has basically no effect, it seems. - //#pragma noprefetch - for (int hit_cnt = 0; hit_cnt < maxSize; ++hit_cnt) - { -#pragma simd - for (int itrack = 0; itrack < N_proc; ++itrack) - { - if (hit_cnt < XHitSize[itrack]) - { - idx[itrack] = XHitArr.At(itrack, hit_cnt, 0) * sizeof(Hit); - } - } -#if defined(MIC_INTRINSICS) - __m512i vi = _mm512_load_epi32(idx); -#endif - - // Prefetch to L2 the hits we'll (probably) process after two loops iterations. - // Ideally this would be initiated before coming here, for whole bunch_of_hits.m_hits vector. - for (int itrack = 0; itrack < N_proc; ++itrack) - { - if (hit_cnt + 2 < XHitSize[itrack]) - { - _mm_prefetch(varr + XHitArr.At(itrack, hit_cnt+2, 0)*sizeof(Hit), _MM_HINT_T1); - } - } - -#if defined(MIC_INTRINSICS) - msErr[Nhits].SlurpIn(varr + off_error, vi); - msPar[Nhits].SlurpIn(varr + off_param, vi); -#else - msErr[Nhits].SlurpIn(varr + off_error, idx); - msPar[Nhits].SlurpIn(varr + off_param, idx); -#endif - - //now compute the chi2 of track state vs hit - MPlexQF outChi2; - computeChi2MPlex(Err[iP], Par[iP], Chg, msErr[Nhits], msPar[Nhits], outChi2, N_proc); - - // Prefetch to L1 the hits we'll (probably) process in the next loop iteration. - for (int itrack = 0; itrack < N_proc; ++itrack) - { - if (hit_cnt + 1 < XHitSize[itrack]) - { - _mm_prefetch(varr + XHitArr.At(itrack, hit_cnt+1, 0)*sizeof(Hit), _MM_HINT_T0); - } - } - - //now update the track parameters with this hit (note that some calculations are already done when computing chi2, to be optimized) - //this is not needed for candidates the hit is not added to, but it's vectorized so doing it serially below should take the same time - //still it's a waste of time in case the hit is not added to any of the candidates, so check beforehand that at least one cand needs update - bool oneCandPassCut = false; - for (int itrack = 0; itrack < N_proc; ++itrack) - { - if (hit_cnt < XHitSize[itrack]) - { - const float chi2 = std::abs(outChi2[itrack]);//fixme negative chi2 sometimes... - dprint("chi2=" << chi2); - if (chi2 < Config::chi2Cut) - { - oneCandPassCut = true; - break; - } - } - } - - if (oneCandPassCut) - { - updateParametersMPlex(Err[iP], Par[iP], Chg, msErr[Nhits], msPar[Nhits], Err[iC], Par[iC], N_proc); - dprint("update parameters" << std::endl - << "propagated track parameters x=" << Par[iP].ConstAt(0, 0, 0) << " y=" << Par[iP].ConstAt(0, 1, 0) << std::endl - << " hit position x=" << msPar[Nhits].ConstAt(0, 0, 0) << " y=" << msPar[Nhits].ConstAt(0, 1, 0) << std::endl - << " updated track parameters x=" << Par[iC].ConstAt(0, 0, 0) << " y=" << Par[iC].ConstAt(0, 1, 0)); - - //create candidate with hit in case chi2 cand2.nhits; @@ -23,7 +26,7 @@ void CandCloner::ProcessSeedRange(int is_beg, int is_end) //1) sort the candidates for (int is = is_beg; is < is_end; ++is) { - std::vector& hitsForSeed = m_hits_to_add[is]; + std::vector& hitsForSeed = m_hits_to_add[is]; std::vector> &cands = mp_event_of_comb_candidates->m_candidates; @@ -52,7 +55,7 @@ void CandCloner::ProcessSeedRange(int is_beg, int is_end) for (int ih = 0; ih < num_hits; ih++) { - const MkFitter::IdxChi2List &h2a = hitsForSeed[ih]; + const MkFinder::IdxChi2List &h2a = hitsForSeed[ih]; cv.push_back( cands[ m_start_seed + is ][ h2a.trkIdx ] ); cv.back().addHitIdx(h2a.hitIdx, m_layer, 0); cv.back().setChi2(h2a.chi2); diff --git a/mkFit/CandCloner.h b/mkFit/CandCloner.h index 929cf2db54a74..c08047b16c911 100644 --- a/mkFit/CandCloner.h +++ b/mkFit/CandCloner.h @@ -1,10 +1,12 @@ #ifndef CandCloner_h #define CandCloner_h -#include "MkFitter.h" +#include "MkFinder.h" #include +class EventOfCombCandidates; + //#define CC_TIME_LAYER //#define CC_TIME_ETA @@ -25,8 +27,6 @@ class CandCloner public: CandCloner() { - // m_fitter = new (_mm_malloc(sizeof(MkFitter), 64)) MkFitter(0); - t_cands_for_next_lay.resize(s_max_seed_range); for (int iseed = 0; iseed < s_max_seed_range; ++iseed) { @@ -74,7 +74,7 @@ class CandCloner // Do nothing, "secondary" state vars updated when work completed/assigned. } - void add_cand(int idx, const MkFitter::IdxChi2List& cand_info) + void add_cand(int idx, const MkFinder::IdxChi2List& cand_info) { m_hits_to_add[idx].push_back(cand_info); @@ -159,7 +159,7 @@ class CandCloner // eventually, protected or private int m_idx_max, m_idx_max_prev; - std::vector> m_hits_to_add; + std::vector> m_hits_to_add; EventOfCombCandidates *mp_event_of_comb_candidates; diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index 5b2e676bcc4b4..4185f542fb382 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -184,12 +184,8 @@ MkBuilder::MkBuilder() : { computeChi2EndcapMPlex, updateParametersEndcapMPlex, - 21, &LayerInfo::m_next_ecap_neg, &MkBase::PropagateTracksToZ, - &MkFitter::SelectHitIndicesEndcap, - &MkFitter::UpdateWithLastHitEndcap, - &MkFitter::FindCandidatesMinimizeCopyEndcap }; //m_steering_params[TrackerInfo::Reg_Transition_Neg] = { }; @@ -198,12 +194,8 @@ MkBuilder::MkBuilder() : { computeChi2MPlex, updateParametersMPlex, - 3, &LayerInfo::m_next_barrel, &MkBase::PropagateTracksToR, - &MkFitter::SelectHitIndices, - &MkFitter::UpdateWithLastHit, - &MkFitter::FindCandidatesMinimizeCopy }; //m_steering_params[TrackerInfo::Reg_Transition_Pos] = { }; @@ -212,12 +204,8 @@ MkBuilder::MkBuilder() : { computeChi2EndcapMPlex, updateParametersEndcapMPlex, - 12, &LayerInfo::m_next_ecap_pos, &MkBase::PropagateTracksToZ, - &MkFitter::SelectHitIndicesEndcap, - &MkFitter::UpdateWithLastHitEndcap, - &MkFitter::FindCandidatesMinimizeCopyEndcap }; // XXMT4D Changing this order might @@ -1172,6 +1160,26 @@ void MkBuilder::find_tracks_load_seeds() dcall(print_seeds(eoccs)); } +int MkBuilder::find_tracks_unroll_candidates(std::vector> & seed_cand_vec, + int start_seed, int end_seed, int layer) +{ + seed_cand_vec.clear(); + + for (int iseed = start_seed; iseed < end_seed; ++iseed) + { + std::vector &scands = m_event_of_comb_cands[iseed]; + for (int ic = 0; ic < scands.size(); ++ic) + { + if (scands[ic].getLastHitIdx() != -2 && scands[ic].getLastHitLyr() < layer) + { + seed_cand_vec.push_back(std::pair(iseed,ic)); + } + } + } + + return seed_cand_vec.size(); +} + //------------------------------------------------------------------------------ // FindTracksCombinatorial: Standard TBB //------------------------------------------------------------------------------ @@ -1223,19 +1231,7 @@ void MkBuilder::FindTracksStandard() const LayerOfHits &layer_of_hits = m_event_of_hits.m_layers_of_hits[ilay]; const LayerInfo &layer_info = trk_info.m_layers[ilay]; - // prepare unrolled vector to loop over - for (int iseed = start_seed; iseed < end_seed; ++iseed) - { - std::vector &scands = eoccs[iseed]; - for (int ic = 0; ic < scands.size(); ++ic) - { - if (scands[ic].getLastHitIdx() != -2 && scands[ic].getLastHitLyr() < ilay) - { - seed_cand_idx.push_back(std::pair(iseed,ic)); - } - } - } - int theEndCand = seed_cand_idx.size(); + int theEndCand = find_tracks_unroll_candidates(seed_cand_idx, start_seed, end_seed, ilay); if (theEndCand == 0) goto next_layer; @@ -1312,7 +1308,6 @@ void MkBuilder::FindTracksStandard() tmp_cands[is].clear(); } } - seed_cand_idx.clear(); next_layer: @@ -1359,7 +1354,7 @@ void MkBuilder::FindTracksCloneEngine() [&](const tbb::blocked_range& seeds) { CLONER( cloner ); - FITTER( mkfndr ); + FINDER( mkfndr ); // loop over layers find_tracks_in_layers(*cloner, mkfndr.get(), seeds.begin(), seeds.end(), region); @@ -1369,9 +1364,11 @@ void MkBuilder::FindTracksCloneEngine() // debug = false; } -void MkBuilder::find_tracks_in_layers(CandCloner &cloner, MkFitter *mkfndr, +void MkBuilder::find_tracks_in_layers(CandCloner &cloner, MkFinder *mkfndr, int start_seed, int end_seed, int region) { + // int debug = 1; + EventOfCombCandidates &eoccs = m_event_of_comb_cands; const SteeringParams &st_par = m_steering_params[region]; const TrackerInfo &trk_info = Config::TrkInfo; @@ -1387,7 +1384,6 @@ void MkBuilder::find_tracks_in_layers(CandCloner &cloner, MkFitter *mkfndr, // Note that we do a final pass with ilay = -1 to update parameters // and output final tracks. prev_ilay == -1 serves as is_first_layer. int prev_ilay = -1; - int n_hits = Config::nlayers_per_seed; int last_seed_layer = m_event->seedMinLastLayer_[region]; int first_layer = trk_info.m_layers[last_seed_layer].*st_par.next_layer_doo; @@ -1401,32 +1397,9 @@ void MkBuilder::find_tracks_in_layers(CandCloner &cloner, MkFitter *mkfndr, const LayerInfo &layer_info = trk_info.m_layers[ilay]; - //prepare unrolled vector to loop over - for (int iseed = start_seed; iseed < end_seed; ++iseed) - { - std::vector &scands = eoccs.m_candidates[iseed]; - for (int ic = 0; ic < scands.size(); ++ic) - { - // XXXXXXMT4MT what is -2, -3 now? - // My understanding: - // -1 missing hit - // -2 missing hit - stopped tracking - // -3 missing hit due to detector geometry - // So -3 should also be taken -- but it only applies to CMS which is - // currently not used. - // - // TODO: - // 1. Renumber so stopped track is the most negative number. - // Can leave some room for future missing-hit-types. - // 2. Document these cases somewhere, have NAMES or constants or an enum. - // 3. Make sure they are used consistently everywhere. - if (scands[ic].getLastHitIdx() != -2 && scands[ic].getLastHitLyr() < ilay) - { - seed_cand_idx.push_back(std::pair(iseed,ic)); - } - } - } - const int theEndCand = seed_cand_idx.size(); + const int theEndCand = find_tracks_unroll_candidates(seed_cand_idx, start_seed, end_seed, ilay); + + dprintf(" Number of candidates to process: %d\n", theEndCand); // Don't bother messing with the clone engine if there are no candidates // (actually it crashes, so this protection is needed). @@ -1435,7 +1408,7 @@ void MkBuilder::find_tracks_in_layers(CandCloner &cloner, MkFitter *mkfndr, // XXXXMT There might be cases in endcap where all tracks will miss the // next layer, but only relevant if we do geometric selection before. - if (theEndCand == 0) break; + if (theEndCand == 0 && ilay != -1) goto next_layer; if (ilay >= 0) { @@ -1458,9 +1431,6 @@ void MkBuilder::find_tracks_in_layers(CandCloner &cloner, MkFitter *mkfndr, dprintf("\n"); #endif - // YYYYYY - mkfndr->SetNhits(n_hits); - mkfndr->InputTracksAndHitIdx(eoccs.m_candidates, seed_cand_idx, itrack, end, prev_ilay >= 0); @@ -1473,7 +1443,7 @@ void MkBuilder::find_tracks_in_layers(CandCloner &cloner, MkFitter *mkfndr, { const LayerOfHits &prev_layer_of_hits = m_event_of_hits.m_layers_of_hits[prev_ilay]; - (mkfndr->*st_par.update_with_last_hit_foo)(prev_layer_of_hits, end - itrack); + mkfndr->UpdateWithLastHit(prev_layer_of_hits, end - itrack, st_par); } if (ilay >= 0) { @@ -1493,7 +1463,7 @@ void MkBuilder::find_tracks_in_layers(CandCloner &cloner, MkFitter *mkfndr, const LayerOfHits &layer_of_hits = m_event_of_hits.m_layers_of_hits[ilay]; - (mkfndr->*st_par.select_hits_foo)(layer_of_hits, end - itrack, false); + mkfndr->SelectHitIndices(layer_of_hits, end - itrack, false); //#ifdef PRINTOUTS_FOR_PLOTS //std::cout << "MX number of hits in window in layer " << ilay << " is " << mkfndr->getXHitEnd(0, 0, 0)-mkfndr->getXHitBegin(0, 0, 0) << std::endl; @@ -1502,7 +1472,7 @@ void MkBuilder::find_tracks_in_layers(CandCloner &cloner, MkFitter *mkfndr, dprint("make new candidates"); cloner.begin_iteration(); - (mkfndr->*st_par.find_cands_min_copy_foo)(layer_of_hits, cloner, start_seed, end - itrack); + mkfndr->FindCandidatesCloneEngine(layer_of_hits, cloner, start_seed, end - itrack, st_par); cloner.end_iteration(); } //end of vectorized loop @@ -1515,11 +1485,11 @@ void MkBuilder::find_tracks_in_layers(CandCloner &cloner, MkFitter *mkfndr, { break; } - seed_cand_idx.clear(); - ++n_hits; prev_ilay = ilay; - ilay = layer_info.*st_par.next_layer_doo; + + next_layer: + ilay = layer_info.*st_par.next_layer_doo; } // end of layer loop cloner.end_eta_bin(); diff --git a/mkFit/MkBuilder.h b/mkFit/MkBuilder.h index eda5f2f677c97..7af85596444c9 100644 --- a/mkFit/MkBuilder.h +++ b/mkFit/MkBuilder.h @@ -98,7 +98,9 @@ class MkBuilder void find_tracks_load_seeds_BH(); // for FindTracksBestHit void find_tracks_load_seeds(); - void find_tracks_in_layers(CandCloner &cloner, MkFitter *mkfndr, + int find_tracks_unroll_candidates(std::vector> & seed_cand_vec, + int start_seed, int end_seed, int layer); + void find_tracks_in_layers(CandCloner &cloner, MkFinder *mkfndr, int start_seed, int end_seed, int region); // -------- diff --git a/mkFit/MkFinder.cc b/mkFit/MkFinder.cc index e786b4329f5fc..bc06e82b66f4b 100644 --- a/mkFit/MkFinder.cc +++ b/mkFit/MkFinder.cc @@ -2,6 +2,7 @@ #include "CandCloner.h" #include "SteeringParams.h" +#include "HitStructures.h" #include "KalmanUtilsMPlex.h" @@ -644,7 +645,7 @@ void MkFinder::FindCandidates(const LayerOfHits &layer_of_hits, //fixme: please vectorize me... for (int itrack = 0; itrack < N_proc; ++itrack) { - int fake_hit_idx = (NHits(itrack,0,0) - NFoundHits(itrack,0,0)) < Config::maxHolesPerCand ? -1 : -2; + int fake_hit_idx = num_invalid_hits(itrack) < Config::maxHolesPerCand ? -1 : -2; if (layer_of_hits.is_endcap() && layer_of_hits.is_in_xy_hole(Par[iP](itrack,0,0), Par[iP](itrack,1,0))) @@ -664,11 +665,215 @@ void MkFinder::FindCandidates(const LayerOfHits &layer_of_hits, //============================================================================== -// FindCandidatesMinimizeCopy - Clone Engine Track Finding +// FindCandidatesCloneEngine - Clone Engine Track Finding //============================================================================== +void MkFinder::FindCandidatesCloneEngine(const LayerOfHits &layer_of_hits, CandCloner& cloner, + const int offset, const int N_proc, + const SteeringParams &st_par) +{ + const char *varr = (char*) layer_of_hits.m_hits; + + const int off_error = (char*) layer_of_hits.m_hits[0].errArray() - varr; + const int off_param = (char*) layer_of_hits.m_hits[0].posArray() - varr; + + int idx[NN] __attribute__((aligned(64))); + + int maxSize = 0; + + // Determine maximum number of hits for tracks in the collection. + // At the same time prefetch the first set of hits to L1 and the second one to L2. +#pragma simd + for (int it = 0; it < NN; ++it) + { + if (it < N_proc) + { + if (XHitSize[it] > 0) + { + _mm_prefetch(varr + XHitArr.At(it, 0, 0) * sizeof(Hit), _MM_HINT_T0); + if (XHitSize[it] > 1) + { + _mm_prefetch(varr + XHitArr.At(it, 1, 0) * sizeof(Hit), _MM_HINT_T1); + } + maxSize = std::max(maxSize, XHitSize[it]); + } + } + + idx[it] = 0; + } + // XXXX MT FIXME: use masks to filter out SlurpIns + +// Has basically no effect, it seems. +//#pragma noprefetch + for (int hit_cnt = 0; hit_cnt < maxSize; ++hit_cnt) + { +#pragma simd + for (int itrack = 0; itrack < N_proc; ++itrack) + { + if (hit_cnt < XHitSize[itrack]) + { + idx[itrack] = XHitArr.At(itrack, hit_cnt, 0) * sizeof(Hit); + } + } +#if defined(MIC_INTRINSICS) + __m512i vi = _mm512_load_epi32(idx); +#endif + + // Prefetch to L2 the hits we'll (probably) process after two loops iterations. + // Ideally this would be initiated before coming here, for whole bunch_of_hits.m_hits vector. + for (int itrack = 0; itrack < N_proc; ++itrack) + { + if (hit_cnt + 2 < XHitSize[itrack]) + { + _mm_prefetch(varr + XHitArr.At(itrack, hit_cnt+2, 0)*sizeof(Hit), _MM_HINT_T1); + } + } + +#if defined(MIC_INTRINSICS) + msErr.SlurpIn(varr + off_error, vi); + msPar.SlurpIn(varr + off_param, vi); +#else + msErr.SlurpIn(varr + off_error, idx); + msPar.SlurpIn(varr + off_param, idx); +#endif + + //now compute the chi2 of track state vs hit + MPlexQF outChi2; + (*st_par.compute_chi2_foo)(Err[iP], Par[iP], Chg, msErr, msPar, outChi2, N_proc); + + // Prefetch to L1 the hits we'll (probably) process in the next loop iteration. + for (int itrack = 0; itrack < N_proc; ++itrack) + { + if (hit_cnt + 1 < XHitSize[itrack]) + { + _mm_prefetch(varr + XHitArr.At(itrack, hit_cnt+1, 0)*sizeof(Hit), _MM_HINT_T0); + } + } + +#pragma simd // DOES NOT VECTORIZE AS IT IS NOW + for (int itrack = 0; itrack < N_proc; ++itrack) + { + // make sure the hit was in the compatiblity window for the candidate + + if (hit_cnt < XHitSize[itrack]) + { + float chi2 = fabs(outChi2[itrack]);//fixme negative chi2 sometimes... +#ifdef DEBUG + std::cout << "chi2=" << chi2 << " for trkIdx=" << itrack << std::endl; +#endif + if (chi2 < Config::chi2Cut) + { + IdxChi2List tmpList; + tmpList.trkIdx = CandIdx(itrack, 0, 0); + tmpList.hitIdx = XHitArr.At(itrack, hit_cnt, 0); + tmpList.nhits = NFoundHits(itrack,0,0) + 1; + tmpList.chi2 = Chi2(itrack, 0, 0) + chi2; + cloner.add_cand(SeedIdx(itrack, 0, 0) - offset, tmpList); + // hitsToAdd[SeedIdx(itrack, 0, 0)-offset].push_back(tmpList); +#ifdef DEBUG + std::cout << "adding hit with hit_cnt=" << hit_cnt << " for trkIdx=" << tmpList.trkIdx << " orig Seed=" << Label(itrack, 0, 0) << std::endl; +#endif + } + } + } + + }//end loop over hits + + //now add invalid hit + //fixme: please vectorize me... + for (int itrack = 0; itrack < N_proc; ++itrack) + { +#ifdef DEBUG + std::cout << "countInvalidHits(" << itrack << ")=" << countInvalidHits(itrack) << std::endl; +#endif + + int fake_hit_idx = num_invalid_hits(itrack) < Config::maxHolesPerCand ? -1 : -2; + + if (layer_of_hits.is_endcap() && + layer_of_hits.is_in_xy_hole(Par[iP](itrack,0,0), Par[iP](itrack,1,0))) + { + // YYYYYY Config::store_missed_layers + fake_hit_idx = -3; + } + + IdxChi2List tmpList; + tmpList.trkIdx = CandIdx(itrack, 0, 0); + tmpList.hitIdx = fake_hit_idx; + tmpList.nhits = NFoundHits(itrack,0,0); + tmpList.chi2 = Chi2(itrack, 0, 0); + cloner.add_cand(SeedIdx(itrack, 0, 0) - offset, tmpList); +#ifdef DEBUG + std::cout << "adding invalid hit" << std::endl; +#endif + } +} + + +//============================================================================== +// UpdateWithLastHit +//============================================================================== + +void MkFinder::UpdateWithLastHit(const LayerOfHits &layer_of_hits, int N_proc, + const SteeringParams &st_par) +{ + // layer_of_hits is for previous layer! + + for (int i = 0; i < N_proc; ++i) + { + int hit_idx = HoTArrs[i][ NHits[i] - 1].index; + + if (hit_idx < 0) continue; + + Hit &hit = layer_of_hits.m_hits[hit_idx]; + + msErr.CopyIn(i, hit.errArray()); + msPar.CopyIn(i, hit.posArray()); + } + + (*st_par.update_param_foo)(Err[iP], Par[iP], Chg, msErr, msPar, + Err[iC], Par[iC], N_proc); + + //now that we have moved propagation at the end of the sequence we lost the handle of + //using the propagated parameters instead of the updated for the missing hit case. + //so we need to replace by hand the updated with the propagated + //there may be a better way to restore this... + + for (int i = 0; i < N_proc; ++i) + { + if (HoTArrs[i][ NHits[i] - 1].index < 0) + { + float tmp[21]; + Err[iP].CopyOut(i, tmp); + Err[iC].CopyIn (i, tmp); + Par[iP].CopyOut(i, tmp); + Par[iC].CopyIn (i, tmp); + } + } +} + //============================================================================== // CopyOutParErr //============================================================================== +void MkFinder::CopyOutParErr(std::vector >& seed_cand_vec, + int N_proc, bool outputProp) const +{ + const int iO = outputProp ? iP : iC; + + for (int i = 0; i < N_proc; ++i) + { + //create a new candidate and fill the cands_for_next_lay vector + Track &cand = seed_cand_vec[SeedIdx(i, 0, 0)][CandIdx(i, 0, 0)]; + + //set the track state to the updated parameters + Err[iO].CopyOut(i, cand.errors_nc().Array()); + Par[iO].CopyOut(i, cand.parameters_nc().Array()); + + dprint((outputProp?"propagated":"updated") << " track parameters x=" << cand.parameters()[0] + << " y=" << cand.parameters()[1] + << " z=" << cand.parameters()[2] + << " pt=" << 1./cand.parameters()[3] + << " posEta=" << cand.posEta()); + } +} diff --git a/mkFit/MkFinder.h b/mkFit/MkFinder.h index 0bcd2deca6e61..946a102ae3482 100644 --- a/mkFit/MkFinder.h +++ b/mkFit/MkFinder.h @@ -112,14 +112,12 @@ class MkFinder : public MkBase //---------------------------------------------------------------------------- - void FindCandidatesMinimizeCopy(const LayerOfHits &layer_of_hits, CandCloner& cloner, - const int offset, const int N_proc, - const SteeringParams &st_par); - void FindCandidatesMinimizeCopyEndcap(const LayerOfHits &layer_of_hits, CandCloner& cloner, - const int offset, const int N_proc); + void FindCandidatesCloneEngine(const LayerOfHits &layer_of_hits, CandCloner& cloner, + const int offset, const int N_proc, + const SteeringParams &st_par); - void UpdateWithLastHit(const LayerOfHits &layer_of_hits, int N_proc); - void UpdateWithLastHitEndcap(const LayerOfHits &layer_of_hits, int N_proc); + void UpdateWithLastHit(const LayerOfHits &layer_of_hits, int N_proc, + const SteeringParams &st_par); void CopyOutParErr(std::vector >& seed_cand_vec, int N_proc, bool outputProp) const; @@ -162,6 +160,11 @@ class MkFinder : public MkBase ++NHits(mslot, 0, 0); if (index >= 0) ++NFoundHits(mslot, 0, 0); } + + int num_invalid_hits(const int mslot) const + { + return NHits(mslot,0,0) - NFoundHits(mslot,0,0); + } }; #endif diff --git a/mkFit/MkFitter.cc b/mkFit/MkFitter.cc index 1d18cca35e349..4fa0eb238f97b 100644 --- a/mkFit/MkFitter.cc +++ b/mkFit/MkFitter.cc @@ -695,673 +695,3 @@ void MkFitter::OutputFittedTracksAndHitIdx(std::vector& tracks, int beg, } } } - -void MkFitter::SelectHitIndices(const LayerOfHits &layer_of_hits, const int N_proc, bool dump) -{ - const LayerOfHits &L = layer_of_hits; - const int iI = iP; - const float nSigmaPhi = 3; - const float nSigmaZ = 3; - - // Vectorizing this makes it run slower! - //#pragma ivdep - //#pragma simd - for (int itrack = 0; itrack < N_proc; ++itrack) - { - XHitSize[itrack] = 0; - - float z, phi, dz, dphi; - { - const float x = Par[iI].ConstAt(itrack, 0, 0); - const float y = Par[iI].ConstAt(itrack, 1, 0); - - const float r2 = x*x + y*y; - - z = Par[iI].ConstAt(itrack, 2, 0); - phi = getPhi(x, y); - dz = nSigmaZ * std::sqrt(Err[iI].ConstAt(itrack, 2, 2)); - - const float dphidx = -y/r2, dphidy = x/r2; - const float dphi2 = dphidx * dphidx * Err[iI].ConstAt(itrack, 0, 0) + - dphidy * dphidy * Err[iI].ConstAt(itrack, 1, 1) + - 2 * dphidx * dphidy * Err[iI].ConstAt(itrack, 0, 1); - -#ifdef HARD_CHECK - assert(dphi2 >= 0); -#endif - - dphi = nSigmaPhi * std::sqrt(std::abs(dphi2)); - - dphi = std::max(std::abs(dphi), L.min_dphi()); - dz = std::max(std::abs(dz), L.min_dq()); - - if (Config::useCMSGeom) - { - //now correct for bending and for layer thickness unsing linear approximation - const float deltaR = Config::cmsDeltaRad; //fixme! using constant value, to be taken from layer properties - const float r = std::sqrt(r2); -#ifdef CCSCOORD - //here alpha is the difference between posPhi and momPhi - const float alpha = phi - Par[iP].ConstAt(itrack, 4, 0); - float cosA, sinA; - if (Config::useTrigApprox) { - sincos4(alpha, sinA, cosA); - } else { - cosA = std::cos(alpha); - sinA = std::sin(alpha); - } -#else - const float px = Par[iP].ConstAt(itrack, 3, 0); - const float py = Par[iP].ConstAt(itrack, 4, 0); - const float pt = std::sqrt(px*px + py*py); - //here alpha is the difference between posPhi and momPhi - const float cosA = ( x*px + y*py ) / (pt*r); - const float sinA = ( y*px - x*py ) / (pt*r); -#endif - //take abs so that we always inflate the window - const float dist = std::abs(deltaR*sinA/cosA); - dphi += dist / r; - } - } - - dphi = std::min(std::abs(dphi), L.max_dphi()); - dz = std::min(std::abs(dz), L.max_dq()); - - const int zb1 = L.GetQBinChecked(z - dz); - const int zb2 = L.GetQBinChecked(z + dz) + 1; - const int pb1 = L.GetPhiBin(phi - dphi); - const int pb2 = L.GetPhiBin(phi + dphi) + 1; - // MT: The extra phi bins give us ~1.5% more good tracks at expense of 10% runtime. - // const int pb1 = L.GetPhiBin(phi - dphi) - 1; - // const int pb2 = L.GetPhiBin(phi + dphi) + 2; - - if (dump) - printf("LayerOfHits::SelectHitIndices %6.3f %6.3f %6.6f %7.5f %3d %3d %4d %4d\n", - z, phi, dz, dphi, zb1, zb2, pb1, pb2); - - // MT: One could iterate in "spiral" order, to pick hits close to the center. - // http://stackoverflow.com/questions/398299/looping-in-a-spiral - // This would then work best with relatively small bin sizes. - // Or, set them up so I can always take 3x3 array around the intersection. - - for (int zi = zb1; zi < zb2; ++zi) - { - for (int pi = pb1; pi < pb2; ++pi) - { - const int pb = pi & L.m_phi_mask; - - // MT: The following line is the biggest hog (4% total run time). - // This comes from cache misses, I presume. - // It might make sense to make first loop to extract bin indices - // and issue prefetches at the same time. - // Then enter vectorized loop to actually collect the hits in proper order. - - for (int hi = L.m_phi_bin_infos[zi][pb].first; hi < L.m_phi_bin_infos[zi][pb].second; ++hi) - { - // MT: Access into m_hit_zs and m_hit_phis is 1% run-time each. - -#ifdef LOH_USE_PHI_Q_ARRAYS - float ddz = std::abs(z - L.m_hit_qs[hi]); - float ddphi = std::abs(phi - L.m_hit_phis[hi]); - if (ddphi > Config::PI) ddphi = Config::TwoPI - ddphi; - - if (dump) - printf(" SHI %3d %4d %4d %5d %6.3f %6.3f %6.4f %7.5f %s\n", - zi, pi, pb, hi, - L.m_hit_qs[hi], L.m_hit_phis[hi], ddz, ddphi, - (ddz < dz && ddphi < dphi) ? "PASS" : "FAIL"); - - // MT: Commenting this check out gives full efficiency ... - // and means our error estimations are wrong! - // Avi says we should have *minimal* search windows per layer. - // Also ... if bins are sufficiently small, we do not need the extra - // checks, see above. - // if (ddz < dz && ddphi < dphi && XHitSize[itrack] < MPlexHitIdxMax) -#endif - // MT: The following check also makes more sense with spiral traversal, - // we'd be taking in closest hits first. - if (XHitSize[itrack] < MPlexHitIdxMax) - { - XHitArr.At(itrack, XHitSize[itrack]++, 0) = hi; - } - } - } - } - } -} - - -void MkFitter::FindCandidatesMinimizeCopy(const LayerOfHits &layer_of_hits, CandCloner& cloner, - const int offset, const int N_proc) -{ - const char *varr = (char*) layer_of_hits.m_hits; - - const int off_error = (char*) layer_of_hits.m_hits[0].errArray() - varr; - const int off_param = (char*) layer_of_hits.m_hits[0].posArray() - varr; - - int idx[NN] __attribute__((aligned(64))); - - int maxSize = 0; - - // Determine maximum number of hits for tracks in the collection. - // At the same time prefetch the first set of hits to L1 and the second one to L2. -#pragma simd - for (int it = 0; it < NN; ++it) - { - if (it < N_proc) - { - if (XHitSize[it] > 0) - { - _mm_prefetch(varr + XHitArr.At(it, 0, 0) * sizeof(Hit), _MM_HINT_T0); - if (XHitSize[it] > 1) - { - _mm_prefetch(varr + XHitArr.At(it, 1, 0) * sizeof(Hit), _MM_HINT_T1); - } - maxSize = std::max(maxSize, XHitSize[it]); - } - } - - idx[it] = 0; - } - // XXXX MT FIXME: use masks to filter out SlurpIns - -// Has basically no effect, it seems. -//#pragma noprefetch - for (int hit_cnt = 0; hit_cnt < maxSize; ++hit_cnt) - { -#pragma simd - for (int itrack = 0; itrack < N_proc; ++itrack) - { - if (hit_cnt < XHitSize[itrack]) - { - idx[itrack] = XHitArr.At(itrack, hit_cnt, 0) * sizeof(Hit); - } - } -#if defined(MIC_INTRINSICS) - __m512i vi = _mm512_load_epi32(idx); -#endif - - // Prefetch to L2 the hits we'll (probably) process after two loops iterations. - // Ideally this would be initiated before coming here, for whole bunch_of_hits.m_hits vector. - for (int itrack = 0; itrack < N_proc; ++itrack) - { - if (hit_cnt + 2 < XHitSize[itrack]) - { - _mm_prefetch(varr + XHitArr.At(itrack, hit_cnt+2, 0)*sizeof(Hit), _MM_HINT_T1); - } - } - -#if defined(MIC_INTRINSICS) - msErr[Nhits].SlurpIn(varr + off_error, vi); - msPar[Nhits].SlurpIn(varr + off_param, vi); -#else - msErr[Nhits].SlurpIn(varr + off_error, idx); - msPar[Nhits].SlurpIn(varr + off_param, idx); -#endif - - //now compute the chi2 of track state vs hit - MPlexQF outChi2; - computeChi2MPlex(Err[iP], Par[iP], Chg, msErr[Nhits], msPar[Nhits], outChi2, N_proc); - - // Prefetch to L1 the hits we'll (probably) process in the next loop iteration. - for (int itrack = 0; itrack < N_proc; ++itrack) - { - if (hit_cnt + 1 < XHitSize[itrack]) - { - _mm_prefetch(varr + XHitArr.At(itrack, hit_cnt+1, 0)*sizeof(Hit), _MM_HINT_T0); - } - } - -#pragma simd // DOES NOT VECTORIZE AS IT IS NOW - for (int itrack = 0; itrack < N_proc; ++itrack) - { - // make sure the hit was in the compatiblity window for the candidate - - if (hit_cnt < XHitSize[itrack]) - { - float chi2 = fabs(outChi2[itrack]);//fixme negative chi2 sometimes... -#ifdef DEBUG - std::cout << "chi2=" << chi2 << " for trkIdx=" << itrack << std::endl; -#endif - if (chi2 < Config::chi2Cut) - { - IdxChi2List tmpList; - tmpList.trkIdx = CandIdx(itrack, 0, 0); - tmpList.hitIdx = XHitArr.At(itrack, hit_cnt, 0); - tmpList.nhits = countValidHits(itrack) + 1; - tmpList.chi2 = Chi2(itrack, 0, 0) + chi2; - cloner.add_cand(SeedIdx(itrack, 0, 0) - offset, tmpList); - // hitsToAdd[SeedIdx(itrack, 0, 0)-offset].push_back(tmpList); -#ifdef DEBUG - std::cout << "adding hit with hit_cnt=" << hit_cnt << " for trkIdx=" << tmpList.trkIdx << " orig Seed=" << Label(itrack, 0, 0) << std::endl; -#endif - } - } - } - - }//end loop over hits - - //now add invalid hit - //fixme: please vectorize me... - for (int itrack = 0; itrack < N_proc; ++itrack) - { -#ifdef DEBUG - std::cout << "countInvalidHits(" << itrack << ")=" << countInvalidHits(itrack) << std::endl; -#endif - - int hit_idx = countInvalidHits(itrack) < Config::maxHolesPerCand ? -1 : -2; - - IdxChi2List tmpList; - tmpList.trkIdx = CandIdx(itrack, 0, 0); - tmpList.hitIdx = hit_idx; - tmpList.nhits = countValidHits(itrack); - tmpList.chi2 = Chi2(itrack, 0, 0); - cloner.add_cand(SeedIdx(itrack, 0, 0) - offset, tmpList); - // hitsToAdd[SeedIdx(itrack, 0, 0)-offset].push_back(tmpList); -#ifdef DEBUG - std::cout << "adding invalid hit" << std::endl; -#endif - } -} - - - -void MkFitter::InputTracksAndHitIdx(const std::vector >& tracks, - const std::vector >& idxs, - int beg, int end, bool inputProp) -{ - // Assign track parameters to initial state and copy hit values in. - - // This might not be true for the last chunk! - // assert(end - beg == NN); - - //fixme: why do we need both i and itrack in the loops below? - - int itrack = 0; - for (int i = beg; i < end; ++i, ++itrack) - { - - const Track &trk = tracks[idxs[i].first][idxs[i].second.trkIdx]; - - Label(itrack, 0, 0) = trk.label(); - SeedIdx(itrack, 0, 0) = idxs[i].first; - CandIdx(itrack, 0, 0) = idxs[i].second.trkIdx; - - if (inputProp) - { - Err[iP].CopyIn(itrack, trk.errors().Array()); - Par[iP].CopyIn(itrack, trk.parameters().Array()); - } - else - { - Err[iC].CopyIn(itrack, trk.errors().Array()); - Par[iC].CopyIn(itrack, trk.parameters().Array()); - } - - Chg(itrack, 0, 0) = trk.charge(); - Chi2(itrack, 0, 0) = trk.chi2(); - - for (int hi = 0; hi < Nhits; ++hi) - { - HoTArr[hi](itrack, 0, 0) = trk.getHitOnTrack(hi); - } - } -} - - -void MkFitter::UpdateWithLastHit(const LayerOfHits &layer_of_hits, int N_proc) -{ - // layer_of_hits is for previous layer! - - for (int i = 0; i < N_proc; ++i) - { - int hit_idx = HoTArr[Nhits - 1](i, 0, 0).index; - - if (hit_idx < 0) continue; - - Hit &hit = layer_of_hits.m_hits[hit_idx]; - - msErr[Nhits - 1].CopyIn(i, hit.errArray()); - msPar[Nhits - 1].CopyIn(i, hit.posArray()); - } - - updateParametersMPlex(Err[iP], Par[iP], Chg, msErr[Nhits-1], msPar[Nhits-1], Err[iC], Par[iC], N_proc); - - //now that we have moved propagation at the end of the sequence we lost the handle of - //using the propagated parameters instead of the updated for the missing hit case. - //so we need to replace by hand the updated with the propagated - //there may be a better way to restore this... - - for (int i = 0; i < N_proc; ++i) - { - if (HoTArr[Nhits - 1](i, 0, 0).index < 0) - { - float tmp[21]; - Err[iP].CopyOut(i, tmp); - Err[iC].CopyIn(i, tmp); - Par[iP].CopyOut(i, tmp); - Par[iC].CopyIn(i, tmp); - } - } -} - -void MkFitter::UpdateWithLastHitEndcap(const LayerOfHits &layer_of_hits, int N_proc) -{ - for (int i = 0; i < N_proc; ++i) - { - int hit_idx = HoTArr[Nhits - 1](i, 0, 0).index; - - if (hit_idx < 0) continue; - - Hit &hit = layer_of_hits.m_hits[hit_idx]; - - msErr[Nhits - 1].CopyIn(i, hit.errArray()); - msPar[Nhits - 1].CopyIn(i, hit.posArray()); - } - - updateParametersEndcapMPlex(Err[iP], Par[iP], Chg, msErr[Nhits-1], msPar[Nhits-1], Err[iC], Par[iC], N_proc); - - //now that we have moved propagation at the end of the sequence we lost the handle of - //using the propagated parameters instead of the updated for the missing hit case. - //so we need to replace by hand the updated with the propagated - //there may be a better way to restore this... - - for (int i = 0; i < N_proc; ++i) - { - if (HoTArr[Nhits - 1](i, 0, 0).index < 0) - { - float tmp[21]; - Err[iP].CopyOut(i, tmp); - Err[iC].CopyIn(i, tmp); - Par[iP].CopyOut(i, tmp); - Par[iC].CopyIn(i, tmp); - } - } -} - -void MkFitter::CopyOutParErr(std::vector >& seed_cand_vec, - int N_proc, bool outputProp) const -{ - const int iO = outputProp ? iP : iC; - - for (int i = 0; i < N_proc; ++i) - { - //create a new candidate and fill the cands_for_next_lay vector - Track &cand = seed_cand_vec[SeedIdx(i, 0, 0)][CandIdx(i, 0, 0)]; - - //set the track state to the updated parameters - Err[iO].CopyOut(i, cand.errors_nc().Array()); - Par[iO].CopyOut(i, cand.parameters_nc().Array()); - - dprint((outputProp?"propagated":"updated") << " track parameters x=" << cand.parameters()[0] - << " y=" << cand.parameters()[1] - << " z=" << cand.parameters()[2] - << " pt=" << 1./cand.parameters()[3] - << " posEta=" << cand.posEta()); - } -} - -void MkFitter::SelectHitIndicesEndcap(const LayerOfHits &layer_of_hits, - const int N_proc, bool dump) -{ - // debug = 1; - // dump = true; - - const LayerOfHits &L = layer_of_hits; - const int iI = iP; - const float nSigmaPhi = 3; - const float nSigmaR = 3; - - // Vectorizing this makes it run slower! - //#pragma ivdep - //#pragma simd - for (int itrack = 0; itrack < N_proc; ++itrack) - { - XHitSize[itrack] = 0; - - float r, phi, dr, dphi; - { - const float x = Par[iI].ConstAt(itrack, 0, 0); - const float y = Par[iI].ConstAt(itrack, 1, 0); - - const float r2 = x*x + y*y; - r = std::sqrt(r2); - - phi = getPhi(x, y); - dr = nSigmaR*(x*x*Err[iI].ConstAt(itrack, 0, 0) + y*y*Err[iI].ConstAt(itrack, 1, 1) + 2*x*y*Err[iI].ConstAt(itrack, 0, 1))/r2; - - const float dphidx = -y/r2, dphidy = x/r2; - const float dphi2 = dphidx * dphidx * Err[iI].ConstAt(itrack, 0, 0) + - dphidy * dphidy * Err[iI].ConstAt(itrack, 1, 1) + - 2 * dphidx * dphidy * Err[iI].ConstAt(itrack, 0, 1); - -#ifdef HARD_CHECK - assert(dphi2 >= 0); -#endif - - dphi = nSigmaPhi * std::sqrt(std::abs(dphi2)); - - dphi = std::max(std::abs(dphi), L.min_dphi()); - dr = std::max(std::abs(dr), L.min_dq()); - - if (Config::useCMSGeom) - { -#ifdef CCSCOORD - //now correct for bending and for layer thickness unsing linear approximation - const float deltaZ = 5; //fixme! using constant value, to be taken from layer properties - float cosT = std::cos(Par[iI].ConstAt(itrack, 5, 0)); - float sinT = std::sin(Par[iI].ConstAt(itrack, 5, 0)); - //here alpha is the helix angular path corresponding to deltaZ - const float k = Chg.ConstAt(itrack, 0, 0) * 100.f / (-Config::sol*Config::Bfield); - const float alpha = deltaZ*sinT*Par[iI].ConstAt(itrack, 3, 0)/(cosT*k); - dphi += std::abs(alpha); -#else - assert(0); -#endif - } - } - - dphi = std::min(std::abs(dphi), L.max_dphi()); - dr = std::min(std::abs(dr), L.max_dq()); - - const int rb1 = L.GetQBinChecked(r - dr); - const int rb2 = L.GetQBinChecked(r + dr) + 1; - const int pb1 = L.GetPhiBin(phi - dphi); - const int pb2 = L.GetPhiBin(phi + dphi) + 1; - // MT: The extra phi bins give us ~1.5% more good tracks at expense of 10% runtime. - // const int pb1 = L.GetPhiBin(phi - dphi) - 1; - // const int pb2 = L.GetPhiBin(phi + dphi) + 2; - - if (dump) - printf("LayerOfHits::SelectHitIndicesEndcap %6.3f %6.3f %6.4f %7.5f %3d %3d %4d %4d\n", - r, phi, dr, dphi, rb1, rb2, pb1, pb2); - - // MT: One could iterate in "spiral" order, to pick hits close to the center. - // http://stackoverflow.com/questions/398299/looping-in-a-spiral - // This would then work best with relatively small bin sizes. - // Or, set them up so I can always take 3x3 array around the intersection. - - for (int ri = rb1; ri < rb2; ++ri) - { - for (int pi = pb1; pi < pb2; ++pi) - { - const int pb = pi & L.m_phi_mask; - - // MT: The following line is the biggest hog (4% total run time). - // This comes from cache misses, I presume. - // It might make sense to make first loop to extract bin indices - // and issue prefetches at the same time. - // Then enter vectorized loop to actually collect the hits in proper order. - - for (int hi = L.m_phi_bin_infos[ri][pb].first; hi < L.m_phi_bin_infos[ri][pb].second; ++hi) - { - // MT: Access into m_hit_zs and m_hit_phis is 1% run-time each. - -#ifdef LOH_USE_PHI_Q_ARRAYS - float ddr = std::abs(r - L.m_hit_qs[hi]); - float ddphi = std::abs(phi - L.m_hit_phis[hi]); - if (ddphi > Config::PI) ddphi = Config::TwoPI - ddphi; - - if (dump) - printf(" SHI %3d %4d %4d %5d %6.3f %6.3f %6.4f %7.5f %s\n", - ri, pi, pb, hi, - L.m_hit_qs[hi], L.m_hit_phis[hi], ddr, ddphi, - (ddr < dr && ddphi < dphi) ? "PASS" : "FAIL"); - - // MT: Commenting this check out gives full efficiency ... - // and means our error estimations are wrong! - // Avi says we should have *minimal* search windows per layer. - // Also ... if bins are sufficiently small, we do not need the extra - // checks, see above. - // if (ddz < dz && ddphi < dphi && XHitSize[itrack] < MPlexHitIdxMax) -#endif - // MT: The following check also makes more sense with spiral traversal, - // we'd be taking in closest hits first. - if (XHitSize[itrack] < MPlexHitIdxMax) - { - XHitArr.At(itrack, XHitSize[itrack]++, 0) = hi; - } - } - } - } - } -} - - -void MkFitter::FindCandidatesMinimizeCopyEndcap(const LayerOfHits &layer_of_hits, CandCloner& cloner, - const int offset, const int N_proc) -{ - const char *varr = (char*) layer_of_hits.m_hits; - - const int off_error = (char*) layer_of_hits.m_hits[0].errArray() - varr; - const int off_param = (char*) layer_of_hits.m_hits[0].posArray() - varr; - - int idx[NN] __attribute__((aligned(64))); - - int maxSize = 0; - - // Determine maximum number of hits for tracks in the collection. - // At the same time prefetch the first set of hits to L1 and the second one to L2. -#pragma simd - for (int it = 0; it < NN; ++it) - { - if (it < N_proc) - { - if (XHitSize[it] > 0) - { - _mm_prefetch(varr + XHitArr.At(it, 0, 0) * sizeof(Hit), _MM_HINT_T0); - if (XHitSize[it] > 1) - { - _mm_prefetch(varr + XHitArr.At(it, 1, 0) * sizeof(Hit), _MM_HINT_T1); - } - maxSize = std::max(maxSize, XHitSize[it]); - } - } - - idx[it] = 0; - } - // XXXX MT FIXME: use masks to filter out SlurpIns - -// Has basically no effect, it seems. -//#pragma noprefetch - for (int hit_cnt = 0; hit_cnt < maxSize; ++hit_cnt) - { -#pragma simd - for (int itrack = 0; itrack < N_proc; ++itrack) - { - if (hit_cnt < XHitSize[itrack]) - { - idx[itrack] = XHitArr.At(itrack, hit_cnt, 0) * sizeof(Hit); - } - } -#if defined(MIC_INTRINSICS) - __m512i vi = _mm512_load_epi32(idx); -#endif - - // Prefetch to L2 the hits we'll (probably) process after two loops iterations. - // Ideally this would be initiated before coming here, for whole bunch_of_hits.m_hits vector. - for (int itrack = 0; itrack < N_proc; ++itrack) - { - if (hit_cnt + 2 < XHitSize[itrack]) - { - _mm_prefetch(varr + XHitArr.At(itrack, hit_cnt+2, 0)*sizeof(Hit), _MM_HINT_T1); - } - } - -#if defined(MIC_INTRINSICS) - msErr[Nhits].SlurpIn(varr + off_error, vi); - msPar[Nhits].SlurpIn(varr + off_param, vi); -#else - msErr[Nhits].SlurpIn(varr + off_error, idx); - msPar[Nhits].SlurpIn(varr + off_param, idx); -#endif - - //now compute the chi2 of track state vs hit - MPlexQF outChi2; - computeChi2EndcapMPlex(Err[iP], Par[iP], Chg, msErr[Nhits], msPar[Nhits], outChi2, N_proc); - - // Prefetch to L1 the hits we'll (probably) process in the next loop iteration. - for (int itrack = 0; itrack < N_proc; ++itrack) - { - if (hit_cnt + 1 < XHitSize[itrack]) - { - _mm_prefetch(varr + XHitArr.At(itrack, hit_cnt+1, 0)*sizeof(Hit), _MM_HINT_T0); - } - } - -#pragma simd // DOES NOT VECTORIZE AS IT IS NOW - for (int itrack = 0; itrack < N_proc; ++itrack) - { - // make sure the hit was in the compatiblity window for the candidate - - if (hit_cnt < XHitSize[itrack]) - { - float chi2 = fabs(outChi2[itrack]);//fixme negative chi2 sometimes... -#ifdef DEBUG - std::cout << "chi2=" << chi2 << " for trkIdx=" << itrack << std::endl; -#endif - if (chi2 < Config::chi2Cut) - { - IdxChi2List tmpList; - tmpList.trkIdx = CandIdx(itrack, 0, 0); - tmpList.hitIdx = XHitArr.At(itrack, hit_cnt, 0); - tmpList.nhits = countValidHits(itrack) + 1; - tmpList.chi2 = Chi2(itrack, 0, 0) + chi2; - cloner.add_cand(SeedIdx(itrack, 0, 0) - offset, tmpList); - // hitsToAdd[SeedIdx(itrack, 0, 0)-offset].push_back(tmpList); -#ifdef DEBUG - std::cout << "adding hit with hit_cnt=" << hit_cnt << " for trkIdx=" << tmpList.trkIdx << " orig Seed=" << Label(itrack, 0, 0) << std::endl; -#endif - } - } - } - - }//end loop over hits - - //now add invalid hit - //fixme: please vectorize me... - for (int itrack = 0; itrack < N_proc; ++itrack) - { -#ifdef DEBUG - std::cout << "countInvalidHits(" << itrack << ")=" << countInvalidHits(itrack) << std::endl; -#endif - - int hit_idx = countInvalidHits(itrack) < Config::maxHolesPerCand ? -1 : -2; - - if (layer_of_hits.is_in_xy_hole(Par[iP](itrack,0,0), Par[iP](itrack,1,0))) - { - hit_idx = -3; - } - - IdxChi2List tmpList; - tmpList.trkIdx = CandIdx(itrack, 0, 0); - tmpList.hitIdx = hit_idx; - tmpList.nhits = countValidHits(itrack); - tmpList.chi2 = Chi2(itrack, 0, 0); - cloner.add_cand(SeedIdx(itrack, 0, 0) - offset, tmpList); - // hitsToAdd[SeedIdx(itrack, 0, 0)-offset].push_back(tmpList); -#ifdef DEBUG - std::cout << "adding invalid hit" << std::endl; -#endif - } -} diff --git a/mkFit/MkFitter.h b/mkFit/MkFitter.h index 9f284e1212254..b300a43093cf7 100644 --- a/mkFit/MkFitter.h +++ b/mkFit/MkFitter.h @@ -90,36 +90,6 @@ struct MkFitter : public MkBase void OutputFittedTracksAndHitIdx(std::vector& tracks, int beg, int end, bool outputProp) const; - void SelectHitIndices(const LayerOfHits &layer_of_hits, const int N_proc, bool dump=false); - void SelectHitIndicesEndcap(const LayerOfHits &layer_of_hits, const int N_proc, bool dump=false); - - // ================================================================ - // Methods used with clone engine - // ================================================================ - //minimal set of information for bookkeping - struct IdxChi2List - { - int trkIdx;//candidate index - int hitIdx;//hit index - int nhits; //number of hits (used for sorting) - float chi2;//total chi2 (used for sorting) - }; - //version of find candidates that does not cloning, just fills the IdxChi2List as output (to be then read by the clone engine) - void FindCandidatesMinimizeCopy(const LayerOfHits &layer_of_hits, CandCloner& cloner, - const int offset, const int N_proc); - void FindCandidatesMinimizeCopyEndcap(const LayerOfHits &layer_of_hits, CandCloner& cloner, - const int offset, const int N_proc); - - //version of input tracks using IdxChi2List - void InputTracksAndHitIdx(const std::vector >& tracks, - const std::vector >& idxs, - int beg, int end, bool inputProp = false); - - void UpdateWithLastHit(const LayerOfHits &layer_of_hits, int N_proc); - void UpdateWithLastHitEndcap(const LayerOfHits &layer_of_hits, int N_proc); - - void CopyOutParErr(std::vector >& seed_cand_vec, - int N_proc, bool outputProp) const; }; #endif diff --git a/mkFit/SteeringParams.h b/mkFit/SteeringParams.h index 375e0316b00a7..cf90080b8fc97 100644 --- a/mkFit/SteeringParams.h +++ b/mkFit/SteeringParams.h @@ -21,14 +21,9 @@ struct SteeringParams void (*compute_chi2_foo) (COMPUTE_CHI2_ARGS); void (*update_param_foo) (UPDATE_PARAM_ARGS); - int first_finding_layer; // layer to consider first .. to be thrown out XXXX - int LayerInfo::*next_layer_doo; void (MkBase::*propagate_foo) (float, const int); - void (MkFitter::*select_hits_foo) (const LayerOfHits &, const int, bool); - void (MkFitter::*update_with_last_hit_foo)(const LayerOfHits &, const int); - void (MkFitter::*find_cands_min_copy_foo)(const LayerOfHits &, CandCloner &, const int, const int); //---------------------------------------------------------------------------- @@ -36,20 +31,12 @@ struct SteeringParams SteeringParams(void (*cch2_f)(COMPUTE_CHI2_ARGS), void (*updp_f)(UPDATE_PARAM_ARGS), - int ffl, int LayerInfo::*nl_d, - void (MkBase::*p_f) (float, const int), - void (MkFitter::*sh_f) (const LayerOfHits &, const int, bool), - void (MkFitter::*uwlh_f)(const LayerOfHits &, const int), - void (MkFitter::*fcmc_f)(const LayerOfHits &, CandCloner &, const int, const int)) : + void (MkBase::*p_f) (float, const int)) : compute_chi2_foo(cch2_f), update_param_foo(updp_f), - first_finding_layer(ffl), next_layer_doo(nl_d), - propagate_foo(p_f), - select_hits_foo(sh_f), - update_with_last_hit_foo(uwlh_f), - find_cands_min_copy_foo(fcmc_f) + propagate_foo(p_f) {} }; From 9a45730be4d1295eccc799c197321fb7ec103b21 Mon Sep 17 00:00:00 2001 From: Dan Riley Date: Thu, 22 Jun 2017 11:44:28 -0700 Subject: [PATCH 071/172] split SelectHitIndices loop into vectorizable and non-vector loops --- Event.cc | 2 ++ mkFit/MkFinder.cc | 40 +++++++++++++++++++++++++++++++++------- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/Event.cc b/Event.cc index a739eb6112bda..50fcf40fb4e71 100644 --- a/Event.cc +++ b/Event.cc @@ -14,6 +14,8 @@ #include "tbb/tbb.h" #endif +#include + std::mutex Event::printmutex; inline bool sortByPhi(const Hit& hit1, const Hit& hit2) diff --git a/mkFit/MkFinder.cc b/mkFit/MkFinder.cc index bc06e82b66f4b..d274298e651f9 100644 --- a/mkFit/MkFinder.cc +++ b/mkFit/MkFinder.cc @@ -140,10 +140,14 @@ void MkFinder::SelectHitIndices(const LayerOfHits &layer_of_hits, printf("LayerOfHits::SelectHitIndices %s layer=%d N_proc=%d\n", L.is_barrel() ? "barrel" : "endcap", L.layer_id(), N_proc); - // Vectorizing this makes it run slower! + float dqv[NN], dphiv[NN], qv[NN], phiv[NN]; + int qb1v[NN], qb2v[NN], pb1v[NN], pb2v[NN]; + + + // Pull out the part of the loop that vectorizes //#pragma ivdep - //#pragma simd - for (int itrack = 0; itrack < N_proc; ++itrack) +#pragma simd + for (int itrack = 0; itrack < NN; ++itrack) { XHitSize[itrack] = 0; @@ -237,13 +241,35 @@ void MkFinder::SelectHitIndices(const LayerOfHits &layer_of_hits, dphi = std::min(std::abs(dphi), L.max_dphi()); dq = std::min(std::abs(dq), L.max_dq()); - const int qb1 = L.GetQBinChecked(q - dq); - const int qb2 = L.GetQBinChecked(q + dq) + 1; - const int pb1 = L.GetPhiBin(phi - dphi); - const int pb2 = L.GetPhiBin(phi + dphi) + 1; + qv[itrack] = q; + phiv[itrack] = phi; + dphiv[itrack] = dphi; + dqv[itrack] = dq; + + qb1v[itrack] = L.GetQBinChecked(q - dq); + qb2v[itrack] = L.GetQBinChecked(q + dq) + 1; + pb1v[itrack] = L.GetPhiBin(phi - dphi); + pb2v[itrack] = L.GetPhiBin(phi + dphi) + 1; // MT: The extra phi bins give us ~1.5% more good tracks at expense of 10% runtime. // const int pb1 = L.GetPhiBin(phi - dphi) - 1; // const int pb2 = L.GetPhiBin(phi + dphi) + 2; + } + + // Vectorizing this makes it run slower! + //#pragma ivdep + //#pragma simd + for (int itrack = 0; itrack < N_proc; ++itrack) + { + const float q = qv[itrack]; + const float phi = phiv[itrack]; + + const float dphi = dphiv[itrack]; + const float dq = dqv[itrack]; + + const int qb1 = qb1v[itrack]; + const int qb2 = qb2v[itrack]; + const int pb1 = pb1v[itrack]; + const int pb2 = pb2v[itrack]; if (dump) printf(" %2d: %6.3f %6.3f %6.6f %7.5f %3d %3d %4d %4d\n", From d5d5c4bbbb89cc81602f86246e83b7e8e4e6503e Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Thu, 22 Jun 2017 23:55:11 -0700 Subject: [PATCH 072/172] Add option --start-event to allow skipping first N events. --- Event.cc | 43 ++++++++++++++++++++++++++++++------------- Event.h | 13 +++++++++++-- mkFit/mkFit.cc | 30 ++++++++++++++++++++++++++---- 3 files changed, 67 insertions(+), 19 deletions(-) diff --git a/Event.cc b/Event.cc index a739eb6112bda..14383eae8d502 100644 --- a/Event.cc +++ b/Event.cc @@ -441,21 +441,11 @@ void Event::write_out(DataFile &data_file) // #define DUMP_TRACK_HITS // #define DUMP_LAYER_HITS -void Event::read_in(DataFile &data_file) +void Event::read_in(DataFile &data_file, FILE *in_fp) { - FILE *fp = data_file.f_fp; - - static long pos = sizeof(DataFileHeader); - int evsize; + FILE *fp = in_fp ? in_fp : data_file.f_fp; - { - static std::mutex readmutex; - std::lock_guard readlock(readmutex); - - fseek(fp, pos, SEEK_SET); - fread(&evsize, sizeof(int), 1, fp); - pos += evsize; - } + int evsize = data_file.AdvancePosToNextEvent(fp); int nt; fread(&nt, sizeof(int), 1, fp); @@ -718,6 +708,33 @@ void DataFile::OpenWrite(const std::string& fname, int nev, int extra_sections) fwrite(&f_header, sizeof(DataFileHeader), 1, f_fp); } +int DataFile::AdvancePosToNextEvent(FILE *fp) +{ + int evsize; + + std::lock_guard readlock(f_next_ev_mutex); + + fseek(fp, f_pos, SEEK_SET); + fread(&evsize, sizeof(int), 1, fp); + f_pos += evsize; + + return evsize; +} + +void DataFile::SkipNEvents(int n_to_skip) +{ + int evsize; + + std::lock_guard readlock(f_next_ev_mutex); + + while (n_to_skip-- > 0) + { + fseek(f_fp, f_pos, SEEK_SET); + fread(&evsize, sizeof(int), 1, f_fp); + f_pos += evsize; + } +} + void DataFile::Close() { fclose(f_fp); diff --git a/Event.h b/Event.h index 52805e511ff5a..4cc08c07fc554 100644 --- a/Event.h +++ b/Event.h @@ -33,7 +33,7 @@ class Event int nextMCHitID() { return mcHitIDCounter_++; } void write_out(DataFile &data_file); - void read_in (DataFile &data_file); + void read_in (DataFile &data_file, FILE *in_fp=0); void clean_cms_simtracks(); void print_tracks(const TrackVec& tracks, bool print_hits) const; @@ -93,16 +93,25 @@ struct DataFile ES_Seeds = 0x2 }; - FILE *f_fp = 0; + FILE *f_fp = 0; + long f_pos = sizeof(DataFileHeader); DataFileHeader f_header; + std::mutex f_next_ev_mutex; + + // ---------------------------------------------------------------- + bool HasSimTrackStates() const { return f_header.f_extra_sections & ES_SimTrackStates; } bool HasSeeds() const { return f_header.f_extra_sections & ES_Seeds; } int OpenRead (const std::string& fname, bool set_n_layers = false); void OpenWrite(const std::string& fname, int nev, int extra_sections=0); + int AdvancePosToNextEvent(FILE *fp); + + void SkipNEvents(int n_to_skip); + void Close(); }; diff --git a/mkFit/mkFit.cc b/mkFit/mkFit.cc index f09ea7fa8adec..e4b9cc94369f6 100644 --- a/mkFit/mkFit.cc +++ b/mkFit/mkFit.cc @@ -99,6 +99,7 @@ void initGeom(Geometry& geom) namespace { + int g_start_event = 1; bool g_run_fit_std = false; bool g_run_build_all = true; @@ -220,9 +221,23 @@ void test_standard() DataFile data_file; if (g_operation == "read") { - int evs_in_file = data_file.OpenRead(g_file_name); + int evs_in_file = data_file.OpenRead(g_file_name); + int evs_available = evs_in_file - g_start_event + 1; if (Config::nEvents == -1) - Config::nEvents = evs_in_file; + { + Config::nEvents = evs_available; + } + else if (Config::nEvents > evs_available) + { + printf("Requested number of events %d, only %d available.\n", + Config::nEvents, evs_available); + Config::nEvents = evs_available; + } + + if (g_start_event > 1) + { + data_file.SkipNEvents(g_start_event - 1); + } } if (Config::useCMSGeom) fillZRgridME(); @@ -272,7 +287,7 @@ void test_standard() std::cout << "Total best hit time (GPU): " << total_best_hit_time << std::endl; } #else - std::atomic nevt{1}; + std::atomic nevt{g_start_event}; std::atomic seedstot{0}, simtrackstot{0}; std::vector> evs(Config::numThreadsEvents); @@ -332,7 +347,7 @@ void test_standard() if (g_operation == "read") { - ev.read_in(data_file); + ev.read_in(data_file, fp); } else { @@ -490,6 +505,7 @@ int main(int argc, const char *argv[]) " --silent suppress printouts inside event loop (def: %s)\n" " --write write simulation to file and exit\n" " --read read simulation from file\n" + " --skip-events number of events to skip when reading from a file (def: %d)\n" " --file-name file name for write/read (def: %s)\n" " --input-file file name for reading when converting formats (def: %s)\n" "GPU specific options: \n" @@ -513,6 +529,7 @@ int main(int argc, const char *argv[]) b2a(Config::fit_val), b2a(Config::inclusiveShorts), b2a(Config::silent), + g_start_event, g_file_name.c_str(), g_input_file.c_str() ); @@ -635,6 +652,11 @@ int main(int argc, const char *argv[]) g_operation = "read"; Config::nEvents = -1; } + else if (*i == "--start-event") + { + next_arg_or_die(mArgs, i); + g_start_event = atoi(i->c_str()); + } else if(*i == "--file-name") { next_arg_or_die(mArgs, i); From d3972390d664b38fb42206ba10f309d5e2d4775f Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Thu, 22 Jun 2017 23:56:05 -0700 Subject: [PATCH 073/172] Avoid dlclose ... saw some unexpected valgrind errors. --- TrackerInfo.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/TrackerInfo.cc b/TrackerInfo.cc index 224b455415cda..5eeafdc5377f8 100644 --- a/TrackerInfo.cc +++ b/TrackerInfo.cc @@ -135,7 +135,12 @@ void TrackerInfo::ExecTrackerInfoCreatorPlugin(const std::string& base, TrackerI TrackerInfoCreator_foo foo = (TrackerInfoCreator_foo)(*p2f); foo(ti, verbose); - dlclose(h); + // XXXXMT4Dan + // With dlclose I saw (rarely) valgrind errors saying + // Invalid read of size 4 + // at 0x4119F7: is_barrel (TrackerInfo.h:54) + // Commenting it out for now. + // dlclose(h); return; } From ce8dd1978c062420cc643fe8752b19401b233043 Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Fri, 23 Jun 2017 00:28:18 -0700 Subject: [PATCH 074/172] Add protection in MkBuilder seeds-from-simtracks. In cmssw, apparently we get simtracks with hits on only three layers, e.g.: 10 with q=-1 pT= 0.121 eta= 2.250 nHits= 6 label= 10 hit 0 lyr=18 idx= 5 pos r= 6.942 z= 33.263 mc_hit= 27 mc_trk= 10 hit 1 lyr=18 idx= 7 pos r= 6.979 z= 33.451 mc_hit= 29 mc_trk= 10 hit 2 lyr=19 idx= 2 pos r= 8.575 z= 41.100 mc_hit= 46 mc_trk= 10 hit 3 lyr=20 idx= 1 pos r= 10.760 z= 52.045 mc_hit= 60 mc_trk= 10 hit 4 lyr=20 idx= 11 pos r= 10.083 z= 48.599 mc_hit= 70 mc_trk= 10 hit 5 lyr=20 idx= 12 pos r= 10.114 z= 48.774 mc_hit= 71 mc_trk= 10 Read event done This now prints: MkBuilder::create_seeds_from_sim_tracks simtrack 10 only yielded 3 hits. Skipping ... --- mkFit/MkBuilder.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index 4185f542fb382..a2d795c4dcc64 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -355,6 +355,13 @@ void MkBuilder::create_seeds_from_sim_tracks() ++h; } + if (h_sel < Config::nlayers_per_seed) + { + printf("MkBuilder::create_seeds_from_sim_tracks simtrack %d only yielded %d hits. Skipping ...\n", + src.label(), h_sel); + continue; + } + seeds.emplace_back( Track(src.state(), 0, src.label(), h_sel, new_hots) ); Track &dst = seeds.back(); From ecd0f205bc7ba452341076c711afe99f7f45e03c Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Tue, 27 Jun 2017 16:10:58 -0700 Subject: [PATCH 075/172] Clean simtracks when reading the event. --- Config.h | 10 ++++----- Event.cc | 54 +++++++++++++++++++++++++++++++++++----------- Event.h | 2 +- mkFit/MkBuilder.cc | 6 +----- 4 files changed, 49 insertions(+), 23 deletions(-) diff --git a/Config.h b/Config.h index 8e102ea66ffbd..8ac952b5a8545 100644 --- a/Config.h +++ b/Config.h @@ -225,6 +225,10 @@ namespace Config extern int maxHolesPerCand; // default: 2; cms 12 (should be reduced) extern int maxCandsPerEtaBin; + // Selection of simtracks from CMSSW. Used in Event::clean_cms_simtracks(). + constexpr int cmsSimSelMinLayers = 8; + constexpr float cmsSimSelMinPt = 0.5; + // config on validation constexpr float nMinSimHitsFrac = 0.7; constexpr int nMinFoundHits = 7; @@ -232,11 +236,7 @@ namespace Config extern bool fit_val; extern bool inclusiveShorts; - // Effective eta bin is one half of nEtaPart -- so the above is twice the "average". - // Note that last and first bin are 3/4 nEtaPart ... but can be made 1/4 by adding - // additional bins on each end. - - // XXX std::min/max have constexpr versions in c++-14. + // Threading extern int numThreadsFinder; extern int numThreadsSimulation; diff --git a/Event.cc b/Event.cc index 46f6f0777b90c..d9e0adeeb860b 100644 --- a/Event.cc +++ b/Event.cc @@ -523,8 +523,8 @@ void Event::read_in(DataFile &data_file, FILE *in_fp) #endif } - printf("Read %i simtracks\n",nt); #ifdef DUMP_TRACKS + printf("Read %i simtracks\n", nt); for (int it = 0; it < nt; it++) { const Track &t = simTracks_[it]; @@ -566,30 +566,43 @@ void Event::read_in(DataFile &data_file, FILE *in_fp) } printf("Total hits in all layers = %d\n", total_hits); #endif - printf("Read event done\n"); + + // This could be conditional: if (Config::useCMSGeom) + int nt_acc = clean_cms_simtracks(); + + printf("Read complete %d simtracks accepted (%d on file).\n", nt_acc, nt); } -void Event::clean_cms_simtracks() +int Event::clean_cms_simtracks() { // Sim tracks from cmssw have the following issues: // - hits are not sorted by layer; - // - there are tracks with too low number of hits, even 0. + // - there are tracks with too low number of hits, even 0; + // - even with enough hits, there can be too few layers (esp. in endcap); + // - tracks from secondaries can have extremely low pT. + // Possible further checks: + // - make sure enough hits exist in seeding layers. + // + // Returns number of passed simtracks. TrackVec orig; simTracks_.swap(orig); int osize = orig.size(); simTracks_.reserve(orig.size()); + dprintf("Event::clean_cms_simtracks processing %d simtracks.\n", osize); + for (int i = 0; i < osize; ++i) { Track &src = orig[i]; const int nh = src.nFoundHits(); - if (nh < Config::nlayers_per_seed) + + // Basic checks. More after hit sorting. + if (nh < Config::cmsSimSelMinLayers || src.pT() < Config::cmsSimSelMinPt) { - dprintf("Dropping simtrack %d, nhits=%d\n", i, nh); + dprintf("Dropping simtrack %d, nhits=%d, pT=%f\n", i, nh, src.pT()); continue; } - dprintf("Accepting simtrack %d, nhits=%d\n", i, nh); // initialize original index locations std::vector idx(nh); @@ -598,18 +611,35 @@ void Event::clean_cms_simtracks() // sort indexes based on comparing values in v std::sort(idx.begin(), idx.end(), [&](int i1, int i2) { return src.getHitLyr(i1) < src.getHitLyr(i2); }); - // XXXX plus secondary sort by radius; + // XXXX Add secondary sort on radius? Need to access hits ... - simTracks_.emplace_back( Track(src.state(), 0, src.label(), 0, nullptr) ); - Track &dst = simTracks_.back(); + Track dst(src.state(), 0, src.label(), 0, nullptr); + int lyr_cnt = 0; + int prev_lyr = -1; for (int h = 0; h < nh; ++h) { - // XXXX Should also check if it's the same layer as before? - dprintf(" adding hit %d which was %d, layer %d\n", h, idx[h], src.getHitLyr(idx[h])); + int h_lyr = src.getHitLyr(idx[h]); + dprintf(" adding hit %d which was %d, layer %d\n", h, idx[h], h_lyr); dst.addHitIdx(src.getHitOnTrack(idx[h]), 0.0f); + if (h_lyr >= 0 && h_lyr != prev_lyr) + { + ++lyr_cnt; + prev_lyr = h_lyr; + } } + + if (nh < Config::cmsSimSelMinLayers && src.pT() < Config::cmsSimSelMinPt) + { + dprintf("Dropping simtrack %d, n_layers=%d\n", i, lyr_cnt); + continue; + } + dprintf("Accepting simtrack %d, n_hits=%d, n_layers=%d\n", i, nh, lyr_cnt); + + simTracks_.emplace_back(dst); } + + return simTracks_.size(); } void Event::print_tracks(const TrackVec& tracks, bool print_hits) const diff --git a/Event.h b/Event.h index 4cc08c07fc554..71fb28095bfaa 100644 --- a/Event.h +++ b/Event.h @@ -35,7 +35,7 @@ class Event void write_out(DataFile &data_file); void read_in (DataFile &data_file, FILE *in_fp=0); - void clean_cms_simtracks(); + int clean_cms_simtracks(); void print_tracks(const TrackVec& tracks, bool print_hits) const; const Geometry& geom_; diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index a2d795c4dcc64..ff065705b87d7 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -995,16 +995,12 @@ void MkBuilder::PrepareSeeds() { find_seeds(); // XXXMT4K Those should be either sorted or sort should be called afterwards. - // Note, sort also fills out some arrays in event. + // Note, sort also fills out some eta region info arrays in Event. } else { if ( ! Config::readCmsswSeeds) { - if (Config::useCMSGeom) - { - m_event->clean_cms_simtracks(); - } create_seeds_from_sim_tracks(); } import_seeds(); From 753f20cdcefe6cfc04332e39a0b1bb741b467d06 Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Fri, 30 Jun 2017 16:21:52 -0700 Subject: [PATCH 076/172] Add Track::Status, make hit counts short ints. - This changes file format ... bumped to 3. - Even::clean_cms_tracks() now just marks "bad" tracks as not findable. - This is used in MkBuilder::create_seeds_from_sim_tracks() to only pick the findable ones. TODO: 1. This flas should also be picked by validation. 2. More / better selection criteria for findable tracks. --- Event.cc | 69 +++++++++++++++++----------------------------- Event.h | 2 +- Track.cc | 19 +++++++++++++ Track.h | 49 ++++++++++++++++++++++++++++++-- mkFit/MkBuilder.cc | 12 +++++++- mkFit/mkFit.cc | 2 ++ 6 files changed, 105 insertions(+), 48 deletions(-) diff --git a/Event.cc b/Event.cc index d9e0adeeb860b..5e2c584059873 100644 --- a/Event.cc +++ b/Event.cc @@ -567,10 +567,7 @@ void Event::read_in(DataFile &data_file, FILE *in_fp) printf("Total hits in all layers = %d\n", total_hits); #endif - // This could be conditional: if (Config::useCMSGeom) - int nt_acc = clean_cms_simtracks(); - - printf("Read complete %d simtracks accepted (%d on file).\n", nt_acc, nt); + printf("Read complete, %d simtracks on file.\n", nt); } int Event::clean_cms_simtracks() @@ -583,45 +580,27 @@ int Event::clean_cms_simtracks() // Possible further checks: // - make sure enough hits exist in seeding layers. // + // What is done: + // 1. Hits are sorted by layer; + // 2. Non-findable tracks are marked with Track::Status::not_findable flag. + // // Returns number of passed simtracks. - TrackVec orig; - simTracks_.swap(orig); - int osize = orig.size(); - simTracks_.reserve(orig.size()); + dprintf("Event::clean_cms_simtracks processing %d simtracks.\n", simTracks_.size()); - dprintf("Event::clean_cms_simtracks processing %d simtracks.\n", osize); + int n_acc = 0; - for (int i = 0; i < osize; ++i) + for (Track & t : simTracks_) { - Track &src = orig[i]; - const int nh = src.nFoundHits(); - - // Basic checks. More after hit sorting. - if (nh < Config::cmsSimSelMinLayers || src.pT() < Config::cmsSimSelMinPt) - { - dprintf("Dropping simtrack %d, nhits=%d, pT=%f\n", i, nh, src.pT()); - continue; - } - - // initialize original index locations - std::vector idx(nh); - std::iota(idx.begin(), idx.end(), 0); - - // sort indexes based on comparing values in v - std::sort(idx.begin(), idx.end(), - [&](int i1, int i2) { return src.getHitLyr(i1) < src.getHitLyr(i2); }); - // XXXX Add secondary sort on radius? Need to access hits ... + const int nh = t.nFoundHits(); - Track dst(src.state(), 0, src.label(), 0, nullptr); + t.sortHitsByLayer(); int lyr_cnt = 0; int prev_lyr = -1; for (int h = 0; h < nh; ++h) { - int h_lyr = src.getHitLyr(idx[h]); - dprintf(" adding hit %d which was %d, layer %d\n", h, idx[h], h_lyr); - dst.addHitIdx(src.getHitOnTrack(idx[h]), 0.0f); + int h_lyr = t.getHitLyr(h); if (h_lyr >= 0 && h_lyr != prev_lyr) { ++lyr_cnt; @@ -629,17 +608,19 @@ int Event::clean_cms_simtracks() } } - if (nh < Config::cmsSimSelMinLayers && src.pT() < Config::cmsSimSelMinPt) + if (lyr_cnt < Config::cmsSimSelMinLayers || t.pT() < Config::cmsSimSelMinPt) { - dprintf("Dropping simtrack %d, n_layers=%d\n", i, lyr_cnt); - continue; + dprintf("Rejecting simtrack %d, n_hits=%d, n_layers=%d, pT=%f\n", i, nh, lyr_cnt, t.pT()); + t.setNotFindable(); + } + else + { + dprintf("Accepting simtrack %d, n_hits=%d, n_layers=%d, pT=%f\n", i, nh, lyr_cnt, t.pT()); + ++n_acc; } - dprintf("Accepting simtrack %d, n_hits=%d, n_layers=%d\n", i, nh, lyr_cnt); - - simTracks_.emplace_back(dst); } - return simTracks_.size(); + return n_acc; } void Event::print_tracks(const TrackVec& tracks, bool print_hits) const @@ -650,8 +631,8 @@ void Event::print_tracks(const TrackVec& tracks, bool print_hits) const for (int it = 0; it < nt; it++) { const Track &t = tracks[it]; - printf(" %i with q=%+i pT=%7.3f eta=% 7.3f nHits=%2d label=%4d\n", - it, t.charge(), t.pT(), t.momEta(), t.nFoundHits(), t.label()); + printf(" %i with q=%+i pT=%7.3f eta=% 7.3f nHits=%2d label=%4d findable=%d\n", + it, t.charge(), t.pT(), t.momEta(), t.nFoundHits(), t.label(), t.isFindable()); if (print_hits) { @@ -680,8 +661,8 @@ void Event::print_tracks(const TrackVec& tracks, bool print_hits) const int DataFile::OpenRead(const std::string& fname, bool set_n_layers) { - constexpr int min_ver = 2; - constexpr int max_ver = 2; + constexpr int min_ver = 3; + constexpr int max_ver = 3; f_fp = fopen(fname.c_str(), "r"); assert (f_fp != 0 || "Opening of input file failed."); @@ -695,7 +676,7 @@ int DataFile::OpenRead(const std::string& fname, bool set_n_layers) } if (f_header.f_format_version < min_ver || f_header.f_format_version > max_ver) { - fprintf(stderr, "Unsupported file version %d. Supported versions are %d to %d.\n", + fprintf(stderr, "Unsupported file version %d. Supported versions are from %d to %d.\n", f_header.f_format_version, min_ver, max_ver); exit(1); } diff --git a/Event.h b/Event.h index 71fb28095bfaa..2658fd95f79e6 100644 --- a/Event.h +++ b/Event.h @@ -71,7 +71,7 @@ typedef std::vector EventVec; struct DataFileHeader { int f_magic = 0xBEEF; - int f_format_version = 2; + int f_format_version = 3; int f_sizeof_track = sizeof(Track); int f_n_max_trk_hits = Config::nMaxTrkHits; int f_n_layers = -1; diff --git a/Track.cc b/Track.cc index b7b7269ed267f..3bd2c0d6b05e5 100644 --- a/Track.cc +++ b/Track.cc @@ -3,6 +3,10 @@ //#define DEBUG #include "Debug.h" +//============================================================================== +// TrackState +//============================================================================== + void TrackState::convertFromCartesianToCCS() { //assume we are currently in cartesian coordinates and want to move to ccs const float px = parameters.At(3); @@ -67,6 +71,21 @@ SMatrix66 TrackState::jacobianCartesianToCCS(float px,float py,float pz) const { return jac; } + +//============================================================================== +// Track +//============================================================================== + +void Track::sortHitsByLayer() +{ + std::sort(& hitsOnTrk_[0], & hitsOnTrk_[lastHitIdx_ + 1], + [&](HitOnTrack h1, HitOnTrack h2) { return h1.layer < h2.layer; }); +} + +//============================================================================== +// TrackExtra +//============================================================================== + // mcTrackID assignments // ID >= 0 : reco track matched to sim track (n eligible found reco hits matching single sim track above some threshold, and n eligible found reco hits above some threshold) // ID == -1 : reco track is a true fake (n eligible found reco hits matching single sim track below some threshold, and n eligible found reco hits above some threshold) diff --git a/Track.h b/Track.h index 057f0617ceac9..9e7fa9c849812 100644 --- a/Track.h +++ b/Track.h @@ -111,6 +111,7 @@ struct TrackState // possible to add same accessors as track? SMatrix66 jacobianCartesianToCCS(float px,float py,float pz) const; }; + class Track { public: @@ -272,6 +273,8 @@ class Track HitOnTrack* BeginHitsOnTrack_nc() { return hitsOnTrk_; } + void sortHitsByLayer(); + void fillEmptyLayers() { for (int h = lastHitIdx_ + 1; h < Config::nMaxTrkHits; h++) { setHitIdxLyr(h, -1, -1); @@ -327,11 +330,53 @@ class Track Track clone() const { return Track(state_,chi2_,label_,nTotalHits(),hitsOnTrk_); } + struct Status + { + union + { + struct + { + // Set to true for short, low-pt CMS tracks. They do not generate mc seeds and + // do not enter the efficiency denominator. + bool not_findable : 1; + + // Set to true when number of holes would exceed an external limit, Config::maxHolesPerCand. + // XXXXMT Not used yet, -3 last hit idx is still used! Need to add it to MkFi**r classes. + bool stopped : 1; + + // The rest, testing if mixing int and uint is ok. + int _some_free_bits_ : 13; + uint _more_free_bits_ : 17; + }; + + uint _raw_; + }; + + Status() : _raw_(0) {} + }; + + Status getStatus() const { return status_; } + // Maybe needed for MkFi**r copy in / out + // Status& refStatus() { return status_; } + // Status* ptrStatus() { return &status_; } + // uint rawStatus() const { return status_._raw_; } + // void setRawStatus(uint rs) { status_._raw_ = rs; } + + bool isFindable() const { return ! status_.not_findable; } + bool isNotFindable() const { return status_.not_findable; } + void setNotFindable() { status_.not_findable = true; } + + // To be used later + // bool isStopped() const { return status_.stopped; } + // void setStopped() { status_.stopped = true; } + private: + TrackState state_; float chi2_ = 0.; - int lastHitIdx_ = -1; - int nFoundHits_ = 0; + short int lastHitIdx_ = -1; + short int nFoundHits_ = 0; + Status status_; int label_ = -1; HitOnTrack hitsOnTrk_[Config::nMaxTrkHits]; }; diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index ff065705b87d7..b95e06d479552 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -320,6 +320,8 @@ void MkBuilder::create_seeds_from_sim_tracks() { const Track &src = sims[i]; + if (src.isNotFindable()) continue; + int h_sel = 0, h = 0; const HitOnTrack *hots = src.getHitsOnTrackArray(); HitOnTrack new_hots[ Config::nlayers_per_seed_max ]; @@ -1001,11 +1003,19 @@ void MkBuilder::PrepareSeeds() { if ( ! Config::readCmsswSeeds) { + if (Config::useCMSGeom) + { + m_event->clean_cms_simtracks(); + + // printf("\n* Simtracks after cleaning:\n"); + // m_event->print_tracks(m_event->simTracks_, true); + // printf("\n"); + } create_seeds_from_sim_tracks(); } import_seeds(); - // printf("\n* Seeds after import / cleaning:\n"); + // printf("\n* Seeds after import:\n"); // m_event->print_tracks(m_event->seedTracks_, true); // printf("\n"); diff --git a/mkFit/mkFit.cc b/mkFit/mkFit.cc index e4b9cc94369f6..0f17325c3207f 100644 --- a/mkFit/mkFit.cc +++ b/mkFit/mkFit.cc @@ -463,6 +463,8 @@ int main(int argc, const char *argv[]) __itt_pause(); #endif + assert (sizeof(Track::Status) == 4 && "To make sure this is true for icc and gcc<6 when mixing bools/ints in bitfields."); + lStr_t mArgs; for (int i = 1; i < argc; ++i) { From 7eb9b84b2a94e8f3e021ccb12cce349b645e28ad Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Sun, 2 Jul 2017 13:54:56 -0700 Subject: [PATCH 077/172] add protections for validation, minor fixups for validation functions in Track class --- TTreeValidation.cc | 32 +++++++++++++++++++------------- TTreeValidation.h | 21 +++++++++++++-------- Track.cc | 4 ++-- Track.h | 2 +- mkFit/mkFit.cc | 2 +- 5 files changed, 36 insertions(+), 25 deletions(-) diff --git a/TTreeValidation.cc b/TTreeValidation.cc index 9fd21a92e2b6c..cac9df6bf919f 100644 --- a/TTreeValidation.cc +++ b/TTreeValidation.cc @@ -75,6 +75,7 @@ TTreeValidation::TTreeValidation(std::string fileName) } if (Config::fit_val) { + for (int i = 0; i < nfvs_; ++i) fvs_[i].resize(Config::nTotalLayers); TTreeValidation::initializeFitTree(); } TTreeValidation::initializeConfigTree(); @@ -539,7 +540,7 @@ void TTreeValidation::mapSeedTkToRecoTk(const TrackVec& evt_tracks, const TrackE } } -int TTreeValidation::getLastGoodHit(const int trackMCHitID, const int mcTrackID, const Event& ev) +int TTreeValidation::getLastFoundHit(const int trackMCHitID, const int mcTrackID, const Event& ev) { int mcHitID = -1; if (ev.simHitsInfo_[trackMCHitID].mcTrackID() == mcTrackID) @@ -662,6 +663,8 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) auto& evt_layer_hits = ev.layerHits_; const auto& evt_sim_trackstates = ev.simTrackStates_; + const bool useSimTSInfo = (evt_sim_trackstates.size() > 0); + for (auto&& simtrack : evt_sim_tracks) { evtID_eff_ = ievt; @@ -688,8 +691,8 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) seedID_seed_eff_ = seedextra.seedID(); // use this to access correct sim track layer params - const int mcHitID = TTreeValidation::getLastGoodHit(seedtrack.getLastGoodMCHitID(evt_layer_hits),mcID_eff_,ev); - if (mcHitID >= 0) + const int mcHitID = TTreeValidation::getLastFoundHit(seedtrack.getLastFoundMCHitID(evt_layer_hits),mcID_eff_,ev); + if (mcHitID >= 0 && useSimTSInfo) { const TrackState & initLayTS = evt_sim_trackstates[mcHitID]; @@ -773,8 +776,8 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) seedID_build_eff_ = buildextra.seedID(); // use this to access correct sim track layer params - const int mcHitID = TTreeValidation::getLastFoundHit(buildtrack.getLastGoodMCHitID(evt_layer_hits),mcID_eff_,ev); - if (mcHitID >= 0) + const int mcHitID = TTreeValidation::getLastFoundHit(buildtrack.getLastFoundMCHitID(evt_layer_hits),mcID_eff_,ev); + if (mcHitID >= 0 && useSimTSInfo) { const TrackState & initLayTS = evt_sim_trackstates[mcHitID]; @@ -857,8 +860,8 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) seedID_fit_eff_ = fitextra.seedID(); // use this to access correct sim track layer params - const int mcHitID = TTreeValidation::getLastGoodHit(fittrack.getLastGoodMCHitID(evt_layer_hits),mcID_eff_,ev); - if (mcHitID >= 0) + const int mcHitID = TTreeValidation::getLastFoundHit(fittrack.getLastFoundMCHitID(evt_layer_hits),mcID_eff_,ev); + if (mcHitID >= 0 && useSimTSInfo) { const TrackState & initLayTS = evt_sim_trackstates[mcHitID]; @@ -951,6 +954,8 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) auto& evt_layer_hits = ev.layerHits_; auto& evt_sim_trackstates = ev.simTrackStates_; + const bool useSimTSInfo = (evt_sim_trackstates.size() > 0); + for (auto&& seedtrack : evt_seed_tracks) { evtID_FR_ = ievt; @@ -1004,8 +1009,8 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) { auto& simtrack = evt_sim_tracks[mcID_seed_FR_]; - const int mcHitID = TTreeValidation::getLastGoodHit(seedtrack.getLastGoodMCHitID(evt_layer_hits),mcID_seed_FR_,ev); - if (mcHitID >= 0) + const int mcHitID = TTreeValidation::getLastFoundHit(seedtrack.getLastFoundMCHitID(evt_layer_hits),mcID_seed_FR_,ev); + if (mcHitID >= 0 && useSimTSInfo) { const TrackState & initLayTS = evt_sim_trackstates[mcHitID]; pt_mc_seed_FR_ = initLayTS.pT(); @@ -1022,6 +1027,7 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) } nHits_mc_seed_FR_ = simtrack.nFoundHits(); + lastlyr_mc_seed_FR_ = simtrack.getLastFoundHitLyr(); duplmask_seed_FR_ = seedextra.isDuplicate(); @@ -1096,8 +1102,8 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) { auto& simtrack = evt_sim_tracks[mcID_build_FR_]; - const int mcHitID = TTreeValidation::getLastGoodHit(buildtrack.getLastGoodMCHitID(evt_layer_hits),mcID_build_FR_,ev); - if (mcHitID >= 0) + const int mcHitID = TTreeValidation::getLastFoundHit(buildtrack.getLastFoundMCHitID(evt_layer_hits),mcID_build_FR_,ev); + if (mcHitID >= 0 && useSimTSInfo) { const TrackState & initLayTS = evt_sim_trackstates[mcHitID]; pt_mc_build_FR_ = initLayTS.pT(); @@ -1227,8 +1233,8 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) { auto& simtrack = evt_sim_tracks[mcID_fit_FR_]; - const int mcHitID = TTreeValidation::getLastGoodHit(fittrack.getLastGoodMCHitID(evt_layer_hits),mcID_fit_FR_,ev); // only works for outward fit for now - if (mcHitID >= 0) + const int mcHitID = TTreeValidation::getLastFoundHit(fittrack.getLastFoundMCHitID(evt_layer_hits),mcID_fit_FR_,ev); // only works for outward fit for now + if (mcHitID >= 0 && useSimTSInfo) { const TrackState & initLayTS = evt_sim_trackstates[mcHitID]; pt_mc_fit_FR_ = initLayTS.pT(); diff --git a/TTreeValidation.h b/TTreeValidation.h index 95f6578c063f3..28936db8eaad1 100644 --- a/TTreeValidation.h +++ b/TTreeValidation.h @@ -44,7 +44,7 @@ class TTreeValidation : public Validation { void makeSeedTkToRecoTkMaps(Event& ev) override; void mapSeedTkToRecoTk(const TrackVec& evt_tracks, const TrackExtraVec& evt_extras, TkIDToTkIDMap& seedTkMap); - int getLastGoodHit(const int trackMCHitID, const int mcTrackID, const Event& ev); + int getLastFoundHit(const int trackMCHitID, const int mcTrackID, const Event& ev); void fillEfficiencyTree(const Event& ev) override; void fillFakeRateTree(const Event& ev) override; @@ -160,13 +160,18 @@ class TTreeValidation : public Validation { // Fit tree (for fine tuning z-phi windows and such --> MPlex Only TTree* fittree_; int ntotallayers_fit_=0,tkid_fit_=0,evtid_fit_=0; - float z_prop_fit_[Config::nTotalLayers],ez_prop_fit_[Config::nTotalLayers]; - float z_hit_fit_[Config::nTotalLayers],ez_hit_fit_[Config::nTotalLayers],z_sim_fit_[Config::nTotalLayers],ez_sim_fit_[Config::nTotalLayers]; - float pphi_prop_fit_[Config::nTotalLayers],epphi_prop_fit_[Config::nTotalLayers]; - float pphi_hit_fit_[Config::nTotalLayers],epphi_hit_fit_[Config::nTotalLayers],pphi_sim_fit_[Config::nTotalLayers],epphi_sim_fit_[Config::nTotalLayers]; - float pt_up_fit_[Config::nTotalLayers],ept_up_fit_[Config::nTotalLayers],pt_sim_fit_[Config::nTotalLayers],ept_sim_fit_[Config::nTotalLayers]; - float mphi_up_fit_[Config::nTotalLayers],emphi_up_fit_[Config::nTotalLayers],mphi_sim_fit_[Config::nTotalLayers],emphi_sim_fit_[Config::nTotalLayers]; - float meta_up_fit_[Config::nTotalLayers],emeta_up_fit_[Config::nTotalLayers],meta_sim_fit_[Config::nTotalLayers],emeta_sim_fit_[Config::nTotalLayers]; + + static const int nfvs_ = 24; + std::vector fvs_[nfvs_]; + + // perl -pe 'BEGIN{$i=0} while (s/\(Config::nTotalLayers\)/ = fvs_[$i]/){++$i}' xxin + std::vector &z_prop_fit_ = fvs_[0],&ez_prop_fit_ = fvs_[1]; + std::vector &z_hit_fit_ = fvs_[2],&ez_hit_fit_ = fvs_[3],&z_sim_fit_ = fvs_[4],&ez_sim_fit_ = fvs_[5]; + std::vector &pphi_prop_fit_ = fvs_[6],&epphi_prop_fit_ = fvs_[7]; + std::vector &pphi_hit_fit_ = fvs_[8],&epphi_hit_fit_ = fvs_[9],&pphi_sim_fit_ = fvs_[10],&epphi_sim_fit_ = fvs_[11]; + std::vector &pt_up_fit_ = fvs_[12],&ept_up_fit_ = fvs_[13],&pt_sim_fit_ = fvs_[14],&ept_sim_fit_ = fvs_[15]; + std::vector &mphi_up_fit_ = fvs_[16],&emphi_up_fit_ = fvs_[17],&mphi_sim_fit_ = fvs_[18],&emphi_sim_fit_ = fvs_[19]; + std::vector &meta_up_fit_ = fvs_[20],&emeta_up_fit_ = fvs_[21],&meta_sim_fit_ = fvs_[22],&emeta_sim_fit_ = fvs_[23]; std::mutex glock_; }; diff --git a/Track.cc b/Track.cc index b7b7269ed267f..32bb578c67a3b 100644 --- a/Track.cc +++ b/Track.cc @@ -112,8 +112,8 @@ void TrackExtra::setMCTrackIDInfoByLabel(const Track& trk, const std::vector& globalHitVec) const + int getLastFoundMCHitID(const std::vector& globalHitVec) const { HitOnTrack hot = getLastFoundHitOnTrack(); return globalHitVec[hot.layer][hot.index].mcHitID(); diff --git a/mkFit/mkFit.cc b/mkFit/mkFit.cc index e4b9cc94369f6..5c5ecb3333d75 100644 --- a/mkFit/mkFit.cc +++ b/mkFit/mkFit.cc @@ -505,7 +505,7 @@ int main(int argc, const char *argv[]) " --silent suppress printouts inside event loop (def: %s)\n" " --write write simulation to file and exit\n" " --read read simulation from file\n" - " --skip-events number of events to skip when reading from a file (def: %d)\n" + " --start-event event number to start at when reading from a file (def: %d)\n" " --file-name file name for write/read (def: %s)\n" " --input-file file name for reading when converting formats (def: %s)\n" "GPU specific options: \n" From c078fde490bfcf4bc60c570f1f39ef05179ac181 Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Wed, 5 Jul 2017 06:39:48 -0700 Subject: [PATCH 078/172] include validation script for full-det-tracking with muons, updates to cleaning -- used unique layers in track matching --- Event.cc | 14 +----- Track.cc | 4 +- Track.h | 18 +++++++- validation-snb-cmssw-fulldet-build.sh | 64 +++++++++++++++++++++++++++ 4 files changed, 85 insertions(+), 15 deletions(-) create mode 100755 validation-snb-cmssw-fulldet-build.sh diff --git a/Event.cc b/Event.cc index 5e2c584059873..0253b1d95e69c 100644 --- a/Event.cc +++ b/Event.cc @@ -595,18 +595,8 @@ int Event::clean_cms_simtracks() const int nh = t.nFoundHits(); t.sortHitsByLayer(); - - int lyr_cnt = 0; - int prev_lyr = -1; - for (int h = 0; h < nh; ++h) - { - int h_lyr = t.getHitLyr(h); - if (h_lyr >= 0 && h_lyr != prev_lyr) - { - ++lyr_cnt; - prev_lyr = h_lyr; - } - } + + const int lyr_cnt = t.nUniqueLayers(); if (lyr_cnt < Config::cmsSimSelMinLayers || t.pT() < Config::cmsSimSelMinPt) { diff --git a/Track.cc b/Track.cc index 7ccb725feb9a7..4a00cfe3599a8 100644 --- a/Track.cc +++ b/Track.cc @@ -156,6 +156,7 @@ void TrackExtra::setMCTrackIDInfo(const Track& trk, const std::vector& l dprintf("TrackExtra::setMCTrackIDInfo for track with label %d, total hits %d, found hits %d\n", trk.label(), trk.nTotalHits(), trk.nFoundHits()); std::vector mcTrackIDs; + for (int ihit = 0; ihit < trk.nTotalHits(); ++ihit) { const int hitidx = trk.getHitIdx(ihit); @@ -201,8 +202,7 @@ void TrackExtra::setMCTrackIDInfo(const Track& trk, const std::vector& l if (isSeed) mcTrackID_ = mcTrackID; else { - // XXXXMT4K Requires Track::nFoundUniqueLayerHits() or Track::nFoundLayers() - const int nMinSimHits = simtracks[mcTrackID].nFoundHits() * Config::nMinSimHitsFrac; + const int nMinSimHits = simtracks[mcTrackID].nUniqueLayers() * Config::nMinSimHitsFrac; const int minFoundHits = ((nMinSimHits >= Config::nMinFoundHits) ? Config::nMinFoundHits : nMinSimHits); if (trk.nFoundHits() >= minFoundHits) mcTrackID_ = mcTrackID; diff --git a/Track.h b/Track.h index 59dd911aaa80a..03e627722ccb5 100644 --- a/Track.h +++ b/Track.h @@ -307,7 +307,23 @@ class Track int nFoundHits() const { return nFoundHits_; } int nTotalHits() const { return lastHitIdx_+1; } - + + int nUniqueLayers() const + { + int lyr_cnt = 0; + int prev_lyr = -1; + for (int ihit = 0; ihit < lastHitIdx_ ; ++ihit) + { + int h_lyr = hitsOnTrk_[ihit].layer; + if (h_lyr >= 0 && h_lyr != prev_lyr) + { + ++lyr_cnt; + prev_lyr = h_lyr; + } + } + return lyr_cnt; + } + const std::vector foundLayers() const { std::vector layers; diff --git a/validation-snb-cmssw-fulldet-build.sh b/validation-snb-cmssw-fulldet-build.sh new file mode 100755 index 0000000000000..92c8ed6c258b9 --- /dev/null +++ b/validation-snb-cmssw-fulldet-build.sh @@ -0,0 +1,64 @@ +#! /bin/bash + +sed -i 's/#WITH_ROOT := yes/WITH_ROOT := yes/g' Makefile.config + +make -j 12 + +dir=/data/nfsmic/scratch/10mu-new + +## ECN ## +echo "SNB CMSSW BH (ECN): validation [nTH:24, nVU:8]" +./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${dir}/mu_ecn-1000-10.bin-5 --build-bh --num-thr 24 >& log_SNB_CMSSW_ECN_BH_NVU8int_NTH24_val.txt +mv valtree.root valtree_SNB_CMSSW_ECN_BH.root +echo "SNB CMSSW STD (ECN): validation [nTH:24, nVU:8]" +./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${dir}/mu_ecn-1000-10.bin-5 --build-std --num-thr 24 >& log_SNB_CMSSW_ECN_STD_NVU8int_NTH24_val.txt +mv valtree.root valtree_SNB_CMSSW_ECN_STD.root +echo "SNB CMSSW CE (ECN): validation [nTH:24, nVU:8]" +./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${dir}/mu_ecn-1000-10.bin-5 --build-ce --num-thr 24 >& log_SNB_CMSSW_ECN_CE_NVU8int_NTH24_val.txt +mv valtree.root valtree_SNB_CMSSW_ECN_CE.root + +## BRL ## +echo "SNB CMSSW BH (BRL): validation [nTH:24, nVU:8]" +./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${dir}/mu_brl-1000-10.bin-5 --build-bh --num-thr 24 >& log_SNB_CMSSW_BRL_BH_NVU8int_NTH24_val.txt +mv valtree.root valtree_SNB_CMSSW_BRL_BH.root +echo "SNB CMSSW STD (BRL): validation [nTH:24, nVU:8]" +./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${dir}/mu_brl-1000-10.bin-5 --build-std --num-thr 24 >& log_SNB_CMSSW_BRL_STD_NVU8int_NTH24_val.txt +mv valtree.root valtree_SNB_CMSSW_BRL_STD.root +echo "SNB CMSSW CE (BRL): validation [nTH:24, nVU:8]" +./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${dir}/mu_brl-1000-10.bin-5 --build-ce --num-thr 24 >& log_SNB_CMSSW_BRL_CE_NVU8int_NTH24_val.txt +mv valtree.root valtree_SNB_CMSSW_BRL_CE.root + +## ECP ## +echo "SNB CMSSW BH (ECP): validation [nTH:24, nVU:8]" +./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${dir}/mu_ecp-1000-10.bin-5 --build-bh --num-thr 24 >& log_SNB_CMSSW_ECP_BH_NVU8int_NTH24_val.txt +mv valtree.root valtree_SNB_CMSSW_ECP_BH.root +echo "SNB CMSSW STD (ECP): validation [nTH:24, nVU:8]" +./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${dir}/mu_ecp-1000-10.bin-5 --build-std --num-thr 24 >& log_SNB_CMSSW_ECP_STD_NVU8int_NTH24_val.txt +mv valtree.root valtree_SNB_CMSSW_ECP_STD.root +echo "SNB CMSSW CE (ECP): validation [nTH:24, nVU:8]" +./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${dir}/mu_ecp-1000-10.bin-5 --build-ce --num-thr 24 >& log_SNB_CMSSW_ECP_CE_NVU8int_NTH24_val.txt +mv valtree.root valtree_SNB_CMSSW_ECP_CE.root + +sed -i 's/WITH_ROOT := yes/#WITH_ROOT := yes/g' Makefile.config + +make clean + +for section in ECN BRL ECP +do + for build in BH STD CE + do + root -b -q -l runValidation.C\(\"_SNB_CMSSW_${section}_${build}\"\) + done + root -b -q -l makeValidation.C\(\"SNB_CMSSW_${section}\"\) +done + +for build in BH STD CE +do + hadd valtree_SNB_CMSSW_FullDet_${build}.root validation_SNB_CMSSW_ECN_${build}/valtree_SNB_CMSSW_ECN_${build}.root validation_SNB_CMSSW_BRL_${build}/valtree_SNB_CMSSW_BRL_${build}.root validation_SNB_CMSSW_ECP_${build}/valtree_SNB_CMSSW_ECP_${build}.root + + root -b -q -l runValidation.C\(\"_SNB_CMSSW_FullDet_${build}\"\) +done + +root -b -q -l makeValidation.C\(\"SNB_CMSSW_FullDet\"\) + +make distclean \ No newline at end of file From 5c7d04e74ea4d85b44c1501ad153bd957422c578 Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Wed, 5 Jul 2017 07:36:35 -0700 Subject: [PATCH 079/172] increase range for inefficiency plot: ARGH --- makeValidation.C | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makeValidation.C b/makeValidation.C index 401ca8b84cfb3..ce7ddba453d72 100644 --- a/makeValidation.C +++ b/makeValidation.C @@ -59,7 +59,7 @@ void makeValidation(TString label = "") g_ce ->SetMarkerColor(kRed); if (!rates[i].Contains("ineff",TString::kExact)) g_bh->GetYaxis()->SetRangeUser(0.0,1.05); - else g_bh->GetYaxis()->SetRangeUser(0.0,0.1); + else g_bh->GetYaxis()->SetRangeUser(0.0,0.25); g_bh ->Draw("APZ"); g_std->Draw("PZ same"); From ccf53e49fba2f6145b13df98a88e24e38a442fd0 Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Thu, 6 Jul 2017 08:15:09 -0700 Subject: [PATCH 080/172] exclude cleaned simtracks from denominator of efficiency --- PlotValidation.cpp | 10 ++++++++-- TTreeValidation.cc | 10 +++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/PlotValidation.cpp b/PlotValidation.cpp index d335583b87a71..aa7b0a78cb6a1 100644 --- a/PlotValidation.cpp +++ b/PlotValidation.cpp @@ -150,7 +150,10 @@ void PlotValidation::PlotEfficiency() { for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index { - varsEff[i][j]->Fill((mcmask_trk[j]==1),mcvars_val[i]); // mc track must be associated to enter numerator + if (mcmask_trk[j] != -1) + { + varsEff[i][j]->Fill((mcmask_trk[j]==1),mcvars_val[i]); // mc track must be associated to enter numerator + } } // end loop over trks } // end loop over vars } // end loop over entry in tree @@ -247,7 +250,10 @@ void PlotValidation::PlotInefficiencyVsGeom() { for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index { - varsIneff[h][i][j]->Fill((mcmask_trk[j] == 0),mcvars_val[i]); // mc track must be UNassociated to enter numerator + if (mcmask_trk[j] != -1) + { + varsIneff[h][i][j]->Fill((mcmask_trk[j] == 0),mcvars_val[i]); // mc track must be UNassociated to enter numerator + } } // end loop over trks } // end loop over vars } // end loop over regions diff --git a/TTreeValidation.cc b/TTreeValidation.cc index cac9df6bf919f..f418fe48b4ae3 100644 --- a/TTreeValidation.cc +++ b/TTreeValidation.cc @@ -1,7 +1,7 @@ // mcTrackID assignments in Track.cc // Efficiency // numerator: sim tracks with at least one reco track with mcTrackID >= 0 (mcmask == 1) -// denominator: all sim tracks +// denominator: all findable sim tracks (mcmask = 0 || == 1) // Fake Rate (with only long reco tracks: Config::inclusiveShorts == false) // numerator: reco tracks with mcTrackID == -1 (mcmask == 0) // denominator: reco tracks with mcTrackID >= 0 || == -1 (mcmask == 1,0,2) @@ -12,7 +12,7 @@ // N.B. Mask assignments // --> mcmask_[reco] == 1,"associated" reco to sim track [possible duplmask_[reco] == 1,0] {eff and FR} // --> mcmask_[reco] == 0,"unassociated" reco to sim track. by definition no duplicates (no reco to associate to sim tracks!) [possible duplmask_[reco] == 2 {eff and FR}] -// --> mcmask_[reco] == -1, reco track excluded from denominator (and therefore numerator) of FR [possible duplmask_[reco] == -1] {FR only} +// --> mcmask_[reco] == -1, sim or reco track excluded from denominator (and therefore numerator) [possible duplmask_[reco] == -1] {eff and FR} // --> mcmask_[reco] == 2, reco track included in demoninator of FR, but will not enter numerator: for short "matched" tracks of mcTrackID == -2,-4 {FR only} // --> nTkMatches_[reco] > 1, n reco tracks associated to the same sim track ID {eff only} @@ -735,7 +735,7 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) } else // unmatched simTracks ... put -99 for all reco values to denote unmatched { - mcmask_seed_eff_ = 0; // quick logic for not matched + mcmask_seed_eff_ = (simtrack.isFindable() ? 0 : -1); // quick logic for not matched seedID_seed_eff_ = -99; @@ -819,7 +819,7 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) } else // unmatched simTracks ... put -99 for all reco values to denote unmatched { - mcmask_build_eff_ = 0; // quick logic for not matched + mcmask_build_eff_ = (simtrack.isFindable() ? 0 : -1); // quick logic for not matched seedID_build_eff_ = -99; @@ -904,7 +904,7 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) } else // unmatched simTracks ... put -99 for all reco values to denote unmatched { - mcmask_fit_eff_ = 0; // quick logic for not matched + mcmask_fit_eff_ = (simtrack.isFindable() ? 0 : -1); // quick logic for not matched seedID_fit_eff_ = -99; From df4894426e2eeddc191544db955eeecea40b12bf Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Fri, 7 Jul 2017 08:59:13 -0700 Subject: [PATCH 081/172] add web directory for making validation plots --- web/README_WEBPLOTS.txt | 21 +++++++++ web/copyphp.sh | 4 ++ web/index.php | 97 +++++++++++++++++++++++++++++++++++++++++ web/makereadable.sh | 8 ++++ 4 files changed, 130 insertions(+) create mode 100644 web/README_WEBPLOTS.txt create mode 100755 web/copyphp.sh create mode 100644 web/index.php create mode 100755 web/makereadable.sh diff --git a/web/README_WEBPLOTS.txt b/web/README_WEBPLOTS.txt new file mode 100644 index 0000000000000..2acb2611f692f --- /dev/null +++ b/web/README_WEBPLOTS.txt @@ -0,0 +1,21 @@ +To get CERN website up and running: + +A) Request CERN website from websites.cern.ch + --> set website to point to AFS directory + --> make website match username + --> set address to /afs/cern.ch/user/{u}/{username}/{dir} + --> make sure {dir} exists! + +B) While waiting for request, do the follow commands in one directory above {dir} + + 1) fs setacl {dir} webserver:afs read + 2) afind {dir} -t d -e "fs setacl -dir {} -acl webserver:afs read" + 3) cd {dir} + 4) touch .htaccess + 5) [open .htaccess and paste the following] "Options +Indexes" [without quotes] + +C) Then copy in really the very useful index.php into {dir} + +D) Once set up and website is live, copy plots and directories into {dir} +E) cd {dir} +F) ./makereadable {subdir}, for every subdir diff --git a/web/copyphp.sh b/web/copyphp.sh new file mode 100755 index 0000000000000..41511c1ad9e18 --- /dev/null +++ b/web/copyphp.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +#cp index.php into all subdirectories +find . -mindepth 1 -type d -exec cp index.php {} \; diff --git a/web/index.php b/web/index.php new file mode 100644 index 0000000000000..ef06ee531f58d --- /dev/null +++ b/web/index.php @@ -0,0 +1,97 @@ + + +<?php echo getcwd(); ?> + + + +

+
+

Filter:

+

Directories

+ +
+

Plots

+
+\n"; + print "

$filename

"; + print ""; + $others = array(); + foreach ($other_exts as $ex) { + $other_filename = str_replace('.png', $ex, $filename); + if (file_exists($other_filename)) { + array_push($others, "[" . $ex . "]"); + if ($ex != '.txt') array_push($displayed, $other_filename); + } + } + if ($others) print "

Also as ".implode(', ',$others)."

"; + print "
"; + } +} +?> + +
+

Other files

+ +
+ + \ No newline at end of file diff --git a/web/makereadable.sh b/web/makereadable.sh new file mode 100755 index 0000000000000..5fd351a67ed68 --- /dev/null +++ b/web/makereadable.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +dir=$1 + +fs setacl ${dir} webserver:afs read +afind ${dir} -t d -e "fs setacl -dir {} -acl webserver:afs read" + +./copyphp.sh \ No newline at end of file From 9a129ac7a1e080db3fd758fb319114a1dfcd8159 Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Fri, 7 Jul 2017 08:59:48 -0700 Subject: [PATCH 082/172] update validation benchmark scripts to be self-contained --- runBenchmark.sh | 5 +---- validation-snb-toymc-fulldet-build.sh | 6 ++++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/runBenchmark.sh b/runBenchmark.sh index 15669d662eb1c..b8de9abd23103 100755 --- a/runBenchmark.sh +++ b/runBenchmark.sh @@ -71,9 +71,6 @@ done ##### Validation tests ##### ./validation-snb-toymc-fulldet-build.sh -for test in BH STD CE; do - root -b -q -l runValidation.C\(\"_SNB_ToyMC_FullDet_${test}\"\) -done -root -b -q -l makeValidation.C\(\"SNB_ToyMC_FullDet\"\) +./validation-snb-cmssw-fulldet-build.sh make distclean diff --git a/validation-snb-toymc-fulldet-build.sh b/validation-snb-toymc-fulldet-build.sh index 8e6174e4b47d8..7d28453670b9c 100755 --- a/validation-snb-toymc-fulldet-build.sh +++ b/validation-snb-toymc-fulldet-build.sh @@ -18,4 +18,10 @@ mv valtree.root valtree_SNB_ToyMC_FullDet_CE.root sed -i 's/WITH_ROOT := yes/#WITH_ROOT := yes/g' Makefile.config +for build in BH STD CE +do + root -b -q -l runValidation.C\(\"_SNB_ToyMC_FullDet_${build}\"\) +done +root -b -q -l makeValidation.C\(\"SNB_ToyMC_FullDet\"\) + make clean From ba1720d3bd53675d82eebd690c9628dd9fbfa257 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Fri, 7 Jul 2017 22:20:19 +0200 Subject: [PATCH 083/172] fix to compile with gcc --- Makefile.config | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Makefile.config b/Makefile.config index 0f7f402656bb4..566044da201d3 100644 --- a/Makefile.config +++ b/Makefile.config @@ -181,7 +181,11 @@ ifdef WITH_TBB ifneq ($(CXX),icc) ifdef TBB_PREFIX CPPFLAGS += -I${TBB_PREFIX}/include - LDFLAGS += -L${TBB_PREFIX}/lib -rpath ${TBB_PREFIX}/lib + ifeq ($(CXX),g++) + LDFLAGS += -L${TBB_PREFIX}/lib -Wl,-rpath,${TBB_PREFIX}/lib + else + LDFLAGS += -L${TBB_PREFIX}/lib -rpath ${TBB_PREFIX}/lib + endif # else use the system version endif endif From c1dd17873bcd9a509cb24fd824c1dc7ce065a7b0 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Fri, 7 Jul 2017 22:20:53 +0200 Subject: [PATCH 084/172] make it explicit that ROOT is needed to compile tkNtuple --- tkNtuple/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tkNtuple/Makefile b/tkNtuple/Makefile index b844f8839028a..5a5d37598acad 100644 --- a/tkNtuple/Makefile +++ b/tkNtuple/Makefile @@ -2,6 +2,8 @@ ifndef ROOTSYS $(error ROOTSYS is not set. Please set ROOT environment properly) endif +WITH_ROOT:=yes + include ../Makefile.config .PHONY: all clean distclean echo From 82c7e70d8b1be6dadeac330b5b388c4f12d27afe Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Sat, 8 Jul 2017 06:52:26 +0200 Subject: [PATCH 085/172] add production type flags, most useful for simtracks --- Track.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Track.h b/Track.h index 03e627722ccb5..85dccb36cbd19 100644 --- a/Track.h +++ b/Track.h @@ -360,8 +360,10 @@ class Track // XXXXMT Not used yet, -3 last hit idx is still used! Need to add it to MkFi**r classes. bool stopped : 1; + // Production type (most useful for sim tracks): 0, 1, 2, 3 for unset, signal, in-time PU, oot PU + uint prod_type : 2; // The rest, testing if mixing int and uint is ok. - int _some_free_bits_ : 13; + int _some_free_bits_ : 11; uint _more_free_bits_ : 17; }; @@ -382,6 +384,10 @@ class Track bool isNotFindable() const { return status_.not_findable; } void setNotFindable() { status_.not_findable = true; } + enum class ProdType { NotSet = 0, Signal = 1, InTimePU = 2, OutOfTimePU = 3}; + ProdType prodType() const { return ProdType(status_.prod_type); } + void setProdType(ProdType ptyp) { status_.prod_type = uint(ptyp); } + // To be used later // bool isStopped() const { return status_.stopped; } // void setStopped() { status_.stopped = true; } From 60ca72ac4ad08e385c5def8a73c079793fa32a2d Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Sat, 8 Jul 2017 06:54:12 +0200 Subject: [PATCH 086/172] - add input argument parsing to set input, output, verbosity, enable cleaning etc - apply simTrack cleaning when requested: use very loose selections of at least 3 sim and 2 rec hits - set simTrack production type to distinguish signal and pileup tracks --- tkNtuple/WriteMemoryFile.cc | 392 ++++++++++++++++++++++++------------ 1 file changed, 264 insertions(+), 128 deletions(-) diff --git a/tkNtuple/WriteMemoryFile.cc b/tkNtuple/WriteMemoryFile.cc index 596072ab68041..171217e0e51b4 100644 --- a/tkNtuple/WriteMemoryFile.cc +++ b/tkNtuple/WriteMemoryFile.cc @@ -2,9 +2,13 @@ #include "TTree.h" #include +#include #include "Event.h" -constexpr int VERBOSE = 0; +constexpr bool useMatched = false; + +constexpr int cleanSimTrack_minSimHits = 3; +constexpr int cleanSimTrack_minRecHits = 2; enum struct TkLayout {phase0 = 0, phase1 = 1}; @@ -140,15 +144,97 @@ class LayerNumberConverter { TkLayout lo_; }; -bool useMatched = false; +typedef std::list lStr_t; +typedef lStr_t::iterator lStr_i; +void next_arg_or_die(lStr_t& args, lStr_i& i) +{ + lStr_i j = i; + if (++j == args.end() || ((*j)[0] == '-' )) + { + std::cerr <<"Error: option "<< *i <<" requires an argument.\n"; + exit(1); + } + i = j; +} + +void printHelp(const char* av0){ + printf( + "Usage: %s [options]\n" + "Options:\n" + " --input input file\n" + " --output output file\n" + " --verbosity print details (0 quiet, 1 print counts, 2 print all; def: 0)\n" + " --clean-sim-tracks apply sim track cleaning (def: no cleaning)\n" + " --keep-empty-sim-tracks keep event with empty [cleaned] sim tracks (def: skip events with 0 simtracks)\n" + , av0); +} int main(int argc, char *argv[]) { - if (argc != 3) - { - fprintf(stderr, "Usage: %s \n", argv[0]); - exit(1); - } + bool haveInput = false; + std::string inputFileName; + bool haveOutput = false; + std::string outputFileName; + + bool cleanSimTracks = false; + bool keepEmptySimTracks = false; + int verbosity = 0; + + lStr_t mArgs; + for (int i = 1; i < argc; ++i) + { + mArgs.push_back(argv[i]); + } + + lStr_i i = mArgs.begin(); + while (i != mArgs.end()) + { + lStr_i start = i; + + if (*i == "-h" || *i == "-help" || *i == "--help") + { + printHelp(argv[0]); + } + else if (*i == "--input") + { + next_arg_or_die(mArgs, i); + inputFileName = *i; + haveInput = true; + } + else if (*i == "--output") + { + next_arg_or_die(mArgs, i); + outputFileName = *i; + haveOutput = true; + } + else if (*i == "--verbosity") + { + next_arg_or_die(mArgs, i); + verbosity = std::atoi(i->c_str()); + } + else if (*i == "--clean-sim-tracks") + { + cleanSimTracks = true; + } + else if (*i == "--keep-empty-sim-tracks") + { + keepEmptySimTracks = true; + } + else + { + fprintf(stderr, "Error: Unknown option/argument '%s'.\n", i->c_str()); + printHelp(argv[0]); + exit(1); + } + mArgs.erase(start, ++i); + }//while arguments + + if (not haveOutput or not haveInput) + { + fprintf(stderr, "Error: both input and output are required\n"); + printHelp(argv[0]); + exit(1); + } using namespace std; @@ -161,10 +247,10 @@ int main(int argc, char *argv[]) int nstot = 0; std::vector nhitstot(nTotalLayers, 0); - TFile* f = TFile::Open(argv[1]); + TFile* f = TFile::Open(inputFileName.c_str()); if (f == 0) { - fprintf(stderr, "Failed opening input root file '%s'\n", argv[1]); + fprintf(stderr, "Failed opening input root file '%s'\n", inputFileName); exit(1); } maxevt = 1000; @@ -181,12 +267,18 @@ int main(int argc, char *argv[]) std::vector* sim_pz = 0; std::vector* sim_parentVtxIdx = 0; std::vector* sim_q = 0; + std::vector* sim_event = 0; + std::vector* sim_bunchCrossing = 0; + std::vector* sim_nValid = 0;//simHit count, actually t->SetBranchAddress("sim_eta",&sim_eta); t->SetBranchAddress("sim_px",&sim_px); t->SetBranchAddress("sim_py",&sim_py); t->SetBranchAddress("sim_pz",&sim_pz); t->SetBranchAddress("sim_parentVtxIdx",&sim_parentVtxIdx); t->SetBranchAddress("sim_q",&sim_q); + t->SetBranchAddress("sim_event",&sim_event); + t->SetBranchAddress("sim_bunchCrossing",&sim_bunchCrossing); + t->SetBranchAddress("sim_nValid",&sim_nValid); std::vector >* sim_trkIdx = 0; t->SetBranchAddress("sim_trkIdx", &sim_trkIdx); @@ -406,7 +498,7 @@ int main(int argc, char *argv[]) long long savedEvents = 0; DataFile data_file; - data_file.OpenWrite(std::string(argv[2]), std::min(maxevt, totentries), DataFile::ES_Seeds); + data_file.OpenWrite(outputFileName, std::min(maxevt, totentries), DataFile::ES_Seeds); Event EE(0); @@ -426,7 +518,85 @@ int main(int argc, char *argv[]) if (nSims==0) { cout << "branches not loaded" << endl; exit(1); } - std::cout<<__FILE__<<" "<<__LINE__<<" nSims "<0) std::cout<<__FILE__<<" "<<__LINE__<<" nSims "< const& shs, std::vector const& shfs, int rhIdx, HitType rhType){ + //assume that all simhits are associated + int ibest = -1; + int shbest = -1; + float hpbest = -1; + float tpbest = -1; + float hfbest = -1; + + float maxfrac = -1; + int ish = -1; + int nshs = shs.size(); + for (auto const sh : shs){ + ish++; + auto tkidx = simhit_simTrkIdx->at(sh); + //use only sh with available TP + if (tkidx < 0) continue; + + auto hpx = simhit_px->at(sh); + auto hpy = simhit_py->at(sh); + auto hpz = simhit_pz->at(sh); + auto hp = sqrt(hpx*hpx + hpy*hpy + hpz*hpz); + + //look only at hits with p> 50 MeV + if (hp < 0.05f) continue; + + auto tpx = sim_px->at(tkidx); + auto tpy = sim_py->at(tkidx); + auto tpz = sim_pz->at(tkidx); + auto tp = sqrt(tpx*tpx + tpy*tpy + tpz*tpz); + + //take only hits with hp> 0.5*tp + if (hp < 0.5*tp) continue; + + //pick tkidx corresponding to max hp/tp; .. this is probably redundant + if (maxfrac < hp/tp){ + maxfrac = hp/tp; + ibest = tkidx; + shbest = sh; + hpbest = hp; + tpbest = tp; + hfbest = shfs[ish]; + } + + } + + //arbitration: a rechit with one matching sim is matched to sim if it's the first + //FIXME: SOME BETTER SELECTION CAN BE DONE (it will require some more correlated knowledge) + if (nshs == 1 && ibest >= 0){ + auto const& srhIdxV = simhit_hitIdx->at(shbest); + auto const& srhTypeV = simhit_hitType->at(shbest); + int ih = -1; + for (auto itype : srhTypeV){ + ih++; + if (HitType(itype) == rhType && srhIdxV[ih] != rhIdx){ + ibest = -1; + break; + } + } + } + + if (ibest >= 0 && false){ + std::cout<<" best tkIdx "<at(shbest) + <<" particle "<at(shbest) + <at(shbest)<<", "<at(shbest)<<", "<at(shbest) + <<" rh "<at(rhIdx)<<", "<at(rhIdx)<<", "<at(rhIdx) < &simTracks_ = EE.simTracks_; vector simTrackIdx_(sim_q->size(),-1);//keep track of original index in ntuple @@ -508,6 +678,12 @@ int main(int argc, char *argv[]) //end test CCS coordinates #endif Track track(state, float(nlay), isim, 0, nullptr);//store number of reco hits in place of track chi2; fill hits later + if (sim_bunchCrossing->at(isim) == 0){//in time + if (sim_event->at(isim) == 0) track.setProdType(Track::ProdType::Signal); + else track.setProdType(Track::ProdType::InTimePU); + } else { + track.setProdType(Track::ProdType::OutOfTimePU); + } if (trkIdx>=0) { int seedIdx = trk_seedIdx->at(trkIdx); auto const& shTypes = see_hitType->at(seedIdx); @@ -515,14 +691,43 @@ int main(int argc, char *argv[]) seedSimIdx[seedIdx] = simTracks_.size(); } } + if (cleanSimTracks){ + if (sim_nValid->at(isim) < cleanSimTrack_minSimHits) continue; + if (cleanSimTrack_minRecHits > 0){ + int nRecToSimHit = 0; + for (int ipix = 0; ipix < pix_lay->size() && nRecToSimHit < cleanSimTrack_minRecHits; ++ipix) { + int ilay = -1; + ilay = lnc.convertLayerNumber(pix_det->at(ipix),pix_lay->at(ipix),useMatched,-1,pix_z->at(ipix)>0); + if (ilay<0) continue; + int simTkIdxNt = bestTkIdx(pix_simHitIdx->at(ipix), pix_chargeFraction->at(ipix), ipix, HitType::Pixel); + if (simTkIdxNt >= 0) nRecToSimHit++; + } + if (useMatched) { + for (int iglu = 0; iglu < glu_lay->size() && nRecToSimHit < cleanSimTrack_minRecHits; ++iglu) { + if (glu_isBarrel->at(iglu)==0) continue; + int igluMono = glu_monoIdx->at(iglu); + int simTkIdxNt = bestTkIdx(str_simHitIdx->at(igluMono), str_chargeFraction->at(igluMono), igluMono, HitType::Strip); + if (simTkIdxNt >= 0) nRecToSimHit++; + } + } + for (int istr = 0; istr < str_lay->size() && nRecToSimHit < cleanSimTrack_minRecHits; ++istr) { + int ilay = -1; + ilay = lnc.convertLayerNumber(str_det->at(istr),str_lay->at(istr),useMatched,str_isStereo->at(istr),str_z->at(istr)>0); + if (useMatched && str_isBarrel->at(istr)==1 && str_isStereo->at(istr)) continue; + if (ilay==-1) continue; + int simTkIdxNt = bestTkIdx(str_simHitIdx->at(istr), str_chargeFraction->at(istr), istr, HitType::Strip); + if (simTkIdxNt >= 0) nRecToSimHit++; + } + if (nRecToSimHit < cleanSimTrack_minRecHits) continue; + }//count rec-to-sim hits + }//cleanSimTracks + simTrackIdx_[isim] = simTracks_.size(); simTracks_.push_back(track); - + } - if (simTracks_.size()==0) continue; - //if (simTracks_.size()<2) continue; - + if (simTracks_.empty() and not keepEmptySimTracks) continue; vector &seedTracks_ = EE.seedTracks_; vector > pixHitSeedIdx(pix_lay->size()); @@ -574,83 +779,6 @@ int main(int argc, char *argv[]) if (seedTracks_.size()==0) continue; - //find best matching tkIdx from a list of simhits indices - auto bestTkIdx = [&](std::vector const& shs, std::vector const& shfs, int rhIdx, HitType rhType){ - //assume that all simhits are associated - int ibest = -1; - int shbest = -1; - float hpbest = -1; - float tpbest = -1; - float hfbest = -1; - - float maxfrac = -1; - int ish = -1; - int nshs = shs.size(); - for (auto const sh : shs){ - ish++; - auto tkidx = simhit_simTrkIdx->at(sh); - //use only sh with available TP - if (tkidx < 0) continue; - - auto hpx = simhit_px->at(sh); - auto hpy = simhit_py->at(sh); - auto hpz = simhit_pz->at(sh); - auto hp = sqrt(hpx*hpx + hpy*hpy + hpz*hpz); - - //look only at hits with p> 50 MeV - if (hp < 0.05f) continue; - - auto tpx = sim_px->at(tkidx); - auto tpy = sim_py->at(tkidx); - auto tpz = sim_pz->at(tkidx); - auto tp = sqrt(tpx*tpx + tpy*tpy + tpz*tpz); - - //take only hits with hp> 0.5*tp - if (hp < 0.5*tp) continue; - - //pick tkidx corresponding to max hp/tp; .. this is probably redundant - if (maxfrac < hp/tp){ - maxfrac = hp/tp; - ibest = tkidx; - shbest = sh; - hpbest = hp; - tpbest = tp; - hfbest = shfs[ish]; - } - - } - - //arbitration: a rechit with one matching sim is matched to sim if it's the first - //FIXME: SOME BETTER SELECTION CAN BE DONE (it will require some more correlated knowledge) - if (nshs == 1 && ibest >= 0){ - auto const& srhIdxV = simhit_hitIdx->at(shbest); - auto const& srhTypeV = simhit_hitType->at(shbest); - int ih = -1; - for (auto itype : srhTypeV){ - ih++; - if (HitType(itype) == rhType && srhIdxV[ih] != rhIdx){ - ibest = -1; - break; - } - } - } - - if (ibest >= 0 && false){ - std::cout<<" best tkIdx "<at(shbest) - <<" particle "<at(shbest) - <at(shbest)<<", "<at(shbest)<<", "<at(shbest) - <<" rh "<at(rhIdx)<<", "<at(rhIdx)<<", "<at(rhIdx) < > &layerHits_ = EE.layerHits_; @@ -661,7 +789,8 @@ int main(int argc, char *argv[]) int ilay = -1; ilay = lnc.convertLayerNumber(pix_det->at(ipix),pix_lay->at(ipix),useMatched,-1,pix_z->at(ipix)>0); if (ilay<0) continue; - int simTkIdx = bestTkIdx(pix_simHitIdx->at(ipix), pix_chargeFraction->at(ipix), ipix, HitType::Pixel); + int simTkIdxNt = bestTkIdx(pix_simHitIdx->at(ipix), pix_chargeFraction->at(ipix), ipix, HitType::Pixel); + int simTkIdx = simTkIdxNt >= 0 ? simTrackIdx_[simTkIdxNt] : -1; //switch to index in simTracks_ //cout << Form("pix lay=%i det=%i x=(%6.3f, %6.3f, %6.3f)",ilay+1,pix_det->at(ipix),pix_x->at(ipix),pix_y->at(ipix),pix_z->at(ipix)) << endl; SVector3 pos(pix_x->at(ipix),pix_y->at(ipix),pix_z->at(ipix)); @@ -692,8 +821,9 @@ int main(int argc, char *argv[]) for (int iglu = 0; iglu < glu_lay->size(); ++iglu) { if (glu_isBarrel->at(iglu)==0) continue; int igluMono = glu_monoIdx->at(iglu); - int simTkIdx = bestTkIdx(str_simHitIdx->at(igluMono), str_chargeFraction->at(igluMono), - igluMono, HitType::Strip); + int simTkIdxNt = bestTkIdx(str_simHitIdx->at(igluMono), str_chargeFraction->at(igluMono), igluMono, HitType::Strip); + int simTkIdx = simTkIdxNt >= 0 ? simTrackIdx_[simTkIdxNt] : -1; //switch to index in simTracks_ + int ilay = lnc.convertLayerNumber(glu_det->at(iglu),glu_lay->at(iglu),useMatched,-1,glu_z->at(iglu)>0); // cout << Form("glu lay=%i det=%i bar=%i x=(%6.3f, %6.3f, %6.3f)",ilay+1,glu_det->at(iglu),glu_isBarrel->at(iglu),glu_x->at(iglu),glu_y->at(iglu),glu_z->at(iglu)) << endl; SVector3 pos(glu_x->at(iglu),glu_y->at(iglu),glu_z->at(iglu)); @@ -724,7 +854,8 @@ int main(int argc, char *argv[]) ilay = lnc.convertLayerNumber(str_det->at(istr),str_lay->at(istr),useMatched,str_isStereo->at(istr),str_z->at(istr)>0); if (useMatched && str_isBarrel->at(istr)==1 && str_isStereo->at(istr)) continue; if (ilay==-1) continue; - int simTkIdx = bestTkIdx(str_simHitIdx->at(istr), str_chargeFraction->at(istr), istr, HitType::Strip); + int simTkIdxNt = bestTkIdx(str_simHitIdx->at(istr), str_chargeFraction->at(istr), istr, HitType::Strip); + int simTkIdx = simTkIdxNt >= 0 ? simTrackIdx_[simTkIdxNt] : -1; //switch to index in simTracks_ //if (str_onTrack->at(istr)==0) continue;//do not consider hits that are not on track! SVector3 pos(str_x->at(istr),str_y->at(istr),str_z->at(istr)); @@ -761,50 +892,55 @@ int main(int argc, char *argv[]) nhitstot[il]+=nh; } - if (VERBOSE) + if (verbosity>0) { int nt = simTracks_.size(); - printf("number of simTracks %i\n",nt); - int nl = layerHits_.size(); int nm = simHitsInfo_.size(); int ns = seedTracks_.size(); - printf("\n"); - for (int il = 0; il1) { + printf("\n"); + for (int il = 0; il1 + }//verbosity>0 EE.write_out(data_file); - + savedEvents++; printf("end of event %lli\n",savedEvents); } From 3d4f2258bbd4c6eb1c3c798f663450e59c17982e Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Fri, 14 Jul 2017 12:11:15 -0400 Subject: [PATCH 087/172] Add optional external rec tracks - collection, commandline option and data file bit. --- Config.cc | 1 + Config.h | 1 + Event.cc | 41 +++++++++++++++++++++++++++++++++++++++++ Event.h | 6 +++++- mkFit/mkFit.cc | 5 +++++ 5 files changed, 53 insertions(+), 1 deletion(-) diff --git a/Config.cc b/Config.cc index 12b234c01dee0..11e8add030308 100644 --- a/Config.cc +++ b/Config.cc @@ -47,6 +47,7 @@ namespace Config bool useCMSGeom = false; bool readCmsswSeeds = false; + bool readExtRecTracks = false; bool findSeeds = false; bool endcapTest = false; diff --git a/Config.h b/Config.h index 8ac952b5a8545..49eab5d9d9b73 100644 --- a/Config.h +++ b/Config.h @@ -253,6 +253,7 @@ namespace Config extern bool useCMSGeom; extern bool readCmsswSeeds; + extern bool readExtRecTracks; extern bool endcapTest; diff --git a/Event.cc b/Event.cc index 0253b1d95e69c..aca7e8d730f61 100644 --- a/Event.cc +++ b/Event.cc @@ -76,6 +76,8 @@ void Event::Reset(int evtID) candidateTracksExtra_.clear(); fitTracks_.clear(); fitTracksExtra_.clear(); + extRecTracks_.clear(); + extRecTracksExtra_.clear(); validation_.resetValidationMaps(); // need to reset maps for every event. } @@ -413,6 +415,13 @@ void Event::write_out(DataFile &data_file) evsize += sizeof(int) + ns*sizeof(Track); } + if (data_file.HasExtRecTracks()) { + int nert = extRecTracks_.size(); + fwrite(&nert, sizeof(int), 1, fp); + fwrite(&extRecTracks_[0], sizeof(Track), nert, fp); + evsize += sizeof(int) + nert*sizeof(Track); + } + fseek(fp, start, SEEK_SET); fwrite(&evsize, sizeof(int), 1, fp); fseek(fp, 0, SEEK_END); @@ -523,6 +532,25 @@ void Event::read_in(DataFile &data_file, FILE *in_fp) #endif } + if (data_file.HasExtRecTracks()) + { + int nert; + fread(&nert, sizeof(int), 1, fp); + if (Config::readExtRecTracks) + { + extRecTracks_.resize(nert); + for (int i = 0; i < nert; ++i) + { + fread(&extRecTracks_[i], data_file.f_header.f_sizeof_track, 1, fp); + } + } + else + { + fseek(fp, nert * data_file.f_header.f_sizeof_track, SEEK_CUR); + nert = -nert; + } + } + #ifdef DUMP_TRACKS printf("Read %i simtracks\n", nt); for (int it = 0; it < nt; it++) @@ -694,9 +722,22 @@ int DataFile::OpenRead(const std::string& fname, bool set_n_layers) printf(" Extra sections:"); if (f_header.f_extra_sections & ES_SimTrackStates) printf(" SimTrackStates"); if (f_header.f_extra_sections & ES_Seeds) printf(" Seeds"); + if (f_header.f_extra_sections & ES_ExtRecTracks) printf(" ExtRecTracks"); printf("\n"); } + if (Config::readCmsswSeeds && ! data_file.HasSeeds()) { + fprintf(stderr, "Reading of CmsswSeeds requested but data not available on file.\n", + f_header.f_n_layers, Config::nTotalLayers); + exit(1); + } + + if (Config::readExtRecTracks && ! data_file.HasExtRecTracks()) { + fprintf(stderr, "Reading of ExtRecTracks requested but data not available on file.\n", + f_header.f_n_layers, Config::nTotalLayers); + exit(1); + } + return f_header.f_n_events; } diff --git a/Event.h b/Event.h index 2658fd95f79e6..07bc959444046 100644 --- a/Event.h +++ b/Event.h @@ -52,8 +52,10 @@ class Event MCHitInfoVec simHitsInfo_; TrackVec simTracks_, seedTracks_, candidateTracks_, fitTracks_; + TrackVec extRecTracks_; // validation sets these, so needs to be mutable mutable TrackExtraVec simTracksExtra_, seedTracksExtra_, candidateTracksExtra_, fitTracksExtra_; + mutable TrackExtraVec extRecTracksExtra_; // XXXXMT: Preliminary. Separators into seed/candidate arrays. // This will have to be extended for multi-pass tracking. @@ -90,7 +92,8 @@ struct DataFile enum ExtraSection { ES_SimTrackStates = 0x1, - ES_Seeds = 0x2 + ES_Seeds = 0x2, + ES_ExtRecTracks = 0x4 }; FILE *f_fp = 0; @@ -104,6 +107,7 @@ struct DataFile bool HasSimTrackStates() const { return f_header.f_extra_sections & ES_SimTrackStates; } bool HasSeeds() const { return f_header.f_extra_sections & ES_Seeds; } + bool HasExtRecTracks() const { return f_header.f_extra_sections & ES_ExtRecTracks; } int OpenRead (const std::string& fname, bool set_n_layers = false); void OpenWrite(const std::string& fname, int nev, int extra_sections=0); diff --git a/mkFit/mkFit.cc b/mkFit/mkFit.cc index 278a67905d63f..5cbcc1ccfa977 100644 --- a/mkFit/mkFit.cc +++ b/mkFit/mkFit.cc @@ -495,6 +495,7 @@ int main(int argc, const char *argv[]) " --build-ce run clone engine combinatorial building test (def: false)\n" " --seeds-per-task number of seeds to process in a tbb task (def: %d)\n" " --best-out-of run track finding num times, report best time (def: %d)\n" + " --ext-rec-tracks read external rec trakcs if available (def: %s)\n" " --cmssw-seeds take seeds from CMSSW (def: %s)\n" " --find-seeds run road search seeding [CF enabled by default] (def: %s)\n" " --hits-per-task number of layer1 hits per task in finding seeds (def: %i)\n" @@ -598,6 +599,10 @@ int main(int argc, const char *argv[]) next_arg_or_die(mArgs, i); Config::finderReportBestOutOfN = atoi(i->c_str()); } + else if(*i == "--ext-rec-tracks") + { + Config::readExtRecTracks = true; + } else if(*i == "--cmssw-seeds") { Config::readCmsswSeeds = true; From d173077ffb1bff7995b36fe4ac3d1a059c829901 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Fri, 14 Jul 2017 23:01:40 +0200 Subject: [PATCH 088/172] DataFile::CloseWrite(int n_written) to override nevents in the header and close --- Event.cc | 10 ++++++++++ Event.h | 1 + 2 files changed, 11 insertions(+) diff --git a/Event.cc b/Event.cc index 0253b1d95e69c..b819703cc7af7 100644 --- a/Event.cc +++ b/Event.cc @@ -744,3 +744,13 @@ void DataFile::Close() f_fp = 0; f_header = DataFileHeader(); } + + void DataFile::CloseWrite(int n_written){ + fseek(f_fp, 0, SEEK_SET); + DataFileHeader a_header; + fread(&a_header, sizeof(DataFileHeader), 1, f_fp); + + a_header.f_n_events = n_written; + fwrite(&a_header, sizeof(DataFileHeader), 1, f_fp); + Close(); + } diff --git a/Event.h b/Event.h index 2658fd95f79e6..bf137a69e0eac 100644 --- a/Event.h +++ b/Event.h @@ -113,6 +113,7 @@ struct DataFile void SkipNEvents(int n_to_skip); void Close(); + void CloseWrite(int n_written); //override nevents in the header and close }; #endif From fd8fda5aaa11c3030db2f22b36d261363e594e4f Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Fri, 14 Jul 2017 23:02:56 +0200 Subject: [PATCH 089/172] includes and include protections --- PlotValidation.hh | 5 +++++ makeValidation.C | 1 + 2 files changed, 6 insertions(+) diff --git a/PlotValidation.hh b/PlotValidation.hh index 66f1f40c190f6..45ad6caa45eb4 100644 --- a/PlotValidation.hh +++ b/PlotValidation.hh @@ -1,3 +1,6 @@ +#ifndef PlotValidation_hh +#define PlotValidation_hh + #include "TFile.h" #include "TEfficiency.h" #include "TH1F.h" @@ -92,3 +95,5 @@ private: std::vector fColors; UInt_t fColorSize; }; + +#endif diff --git a/makeValidation.C b/makeValidation.C index ce7ddba453d72..ac262a98ce39a 100644 --- a/makeValidation.C +++ b/makeValidation.C @@ -6,6 +6,7 @@ #include "TGraphAsymmErrors.h" #include "TCanvas.h" #include "TLegend.h" +#include "TAxis.h" #include From 4882929267d32da9f81f464772f30ec874bac83d Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Fri, 14 Jul 2017 23:04:01 +0200 Subject: [PATCH 090/172] change --keep-empty-sim-tracks to a more appropriate --write-all-events; fix the output file header to give a correct number of events written --- tkNtuple/WriteMemoryFile.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tkNtuple/WriteMemoryFile.cc b/tkNtuple/WriteMemoryFile.cc index 171217e0e51b4..195dd37a773a5 100644 --- a/tkNtuple/WriteMemoryFile.cc +++ b/tkNtuple/WriteMemoryFile.cc @@ -165,7 +165,7 @@ void printHelp(const char* av0){ " --output output file\n" " --verbosity print details (0 quiet, 1 print counts, 2 print all; def: 0)\n" " --clean-sim-tracks apply sim track cleaning (def: no cleaning)\n" - " --keep-empty-sim-tracks keep event with empty [cleaned] sim tracks (def: skip events with 0 simtracks)\n" + " --write-all-events write all events (def: skip events with 0 simtracks or seeds)\n" , av0); } @@ -177,7 +177,7 @@ int main(int argc, char *argv[]) std::string outputFileName; bool cleanSimTracks = false; - bool keepEmptySimTracks = false; + bool writeAllEvents = false; int verbosity = 0; lStr_t mArgs; @@ -216,9 +216,9 @@ int main(int argc, char *argv[]) { cleanSimTracks = true; } - else if (*i == "--keep-empty-sim-tracks") + else if (*i == "--write-all-events") { - keepEmptySimTracks = true; + writeAllEvents = true; } else { @@ -727,7 +727,7 @@ int main(int argc, char *argv[]) } - if (simTracks_.empty() and not keepEmptySimTracks) continue; + if (simTracks_.empty() and not writeAllEvents) continue; vector &seedTracks_ = EE.seedTracks_; vector > pixHitSeedIdx(pix_lay->size()); @@ -777,7 +777,7 @@ int main(int argc, char *argv[]) seedTracks_.push_back(track); } - if (seedTracks_.size()==0) continue; + if (seedTracks_.empty() and not writeAllEvents) continue; @@ -945,7 +945,7 @@ int main(int argc, char *argv[]) printf("end of event %lli\n",savedEvents); } - data_file.Close(); + data_file.CloseWrite(savedEvents); printf("\nSaved %lli events\n\n",savedEvents); printf("Average number of seeds per event %f\n",float(nstot)/float(savedEvents)); From 540e8699ce4cbde2f25f3d73624a737144a2519f Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Fri, 14 Jul 2017 23:09:23 +0200 Subject: [PATCH 091/172] add an include to get a working version for root 6 --- runValidation.C | 2 ++ 1 file changed, 2 insertions(+) diff --git a/runValidation.C b/runValidation.C index 13fdd13c2d141..f8091b640aa96 100644 --- a/runValidation.C +++ b/runValidation.C @@ -1,3 +1,5 @@ +#include "PlotValidation.hh" + void setupcpp11() { // customize ACLiC's behavior ... TString o; From f6890251256785ddb400515962ccefa40f55c387 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Tue, 18 Jul 2017 01:40:20 +0200 Subject: [PATCH 092/172] hide PlotValidation.hh from CINT --- runValidation.C | 2 ++ 1 file changed, 2 insertions(+) diff --git a/runValidation.C b/runValidation.C index f8091b640aa96..eb6f9f22c5711 100644 --- a/runValidation.C +++ b/runValidation.C @@ -1,4 +1,6 @@ +#if !defined(__CINT__) #include "PlotValidation.hh" +#endif void setupcpp11() { // customize ACLiC's behavior ... From 549a9d19eab39d957a30f5351c552dea4112e7aa Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Tue, 18 Jul 2017 23:10:57 -0700 Subject: [PATCH 093/172] Remove wrong object reference. --- Event.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Event.cc b/Event.cc index 3c66436fa1455..3832cf3e458e6 100644 --- a/Event.cc +++ b/Event.cc @@ -726,13 +726,13 @@ int DataFile::OpenRead(const std::string& fname, bool set_n_layers) printf("\n"); } - if (Config::readCmsswSeeds && ! data_file.HasSeeds()) { + if (Config::readCmsswSeeds && ! HasSeeds()) { fprintf(stderr, "Reading of CmsswSeeds requested but data not available on file.\n", f_header.f_n_layers, Config::nTotalLayers); exit(1); } - if (Config::readExtRecTracks && ! data_file.HasExtRecTracks()) { + if (Config::readExtRecTracks && ! HasExtRecTracks()) { fprintf(stderr, "Reading of ExtRecTracks requested but data not available on file.\n", f_header.f_n_layers, Config::nTotalLayers); exit(1); From 2b2ca8dfe2f1d2c2c977a6988149c2dee733c0a1 Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Tue, 18 Jul 2017 23:11:32 -0700 Subject: [PATCH 094/172] Make the whole thing build on osx again. --- Geoms/Makefile | 2 +- Makefile | 2 +- Makefile.config | 6 +----- Track.h | 15 ++++++++------- mkFit/Makefile | 2 +- 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/Geoms/Makefile b/Geoms/Makefile index 35f5a84fadc8b..9d9c21508f686 100644 --- a/Geoms/Makefile +++ b/Geoms/Makefile @@ -26,7 +26,7 @@ all: ${TGTS} ${CXX} ${CPPFLAGS} ${CXXFLAGS} ${VEC_HOST} -c -o $@ $< %.so: %.o - ${CXX} -shared -o $@ $< + ${CXX} -shared -L.. -lMicCore -o $@ $< %.om: %.cc ${CXX} ${CPPFLAGS_NO_ROOT} ${CXXFLAGS} ${VEC_MIC} -c -o $@ $< diff --git a/Makefile b/Makefile index 6c7e7ecaf2eaf..04f818875af43 100644 --- a/Makefile +++ b/Makefile @@ -57,7 +57,7 @@ ${LIB_CORE}: ${CORE_OBJS} ${CXX} ${CXXFLAGS} ${VEC_HOST} ${LDFLAGS} ${CORE_OBJS} -shared -o $@ ${LDFLAGS_HOST} ${LDFLAGS_CU} main: ${AUTO_TGTS} ${LIB_CORE} main.o ${LIBUSOLIDS} - ${CXX} ${CXXFLAGS} ${VEC_HOST} -o $@ main.o ${LIBUSOLIDS} ${LDFLAGS} -L. -lMicCore -Wl,-rpath=. + ${CXX} ${CXXFLAGS} ${VEC_HOST} -o $@ main.o ${LIBUSOLIDS} ${LDFLAGS} -L. -lMicCore -Wl,-rpath,. ${OBJS}: %.o: %.cc %.d ${CXX} ${CPPFLAGS} ${CXXFLAGS} ${VEC_HOST} -c -o $@ $< diff --git a/Makefile.config b/Makefile.config index 566044da201d3..bc5cb2674c8ae 100644 --- a/Makefile.config +++ b/Makefile.config @@ -181,11 +181,7 @@ ifdef WITH_TBB ifneq ($(CXX),icc) ifdef TBB_PREFIX CPPFLAGS += -I${TBB_PREFIX}/include - ifeq ($(CXX),g++) - LDFLAGS += -L${TBB_PREFIX}/lib -Wl,-rpath,${TBB_PREFIX}/lib - else - LDFLAGS += -L${TBB_PREFIX}/lib -rpath ${TBB_PREFIX}/lib - endif + LDFLAGS += -L${TBB_PREFIX}/lib -Wl,-rpath,${TBB_PREFIX}/lib # else use the system version endif endif diff --git a/Track.h b/Track.h index 85dccb36cbd19..a6d0d72bd1876 100644 --- a/Track.h +++ b/Track.h @@ -361,13 +361,14 @@ class Track bool stopped : 1; // Production type (most useful for sim tracks): 0, 1, 2, 3 for unset, signal, in-time PU, oot PU - uint prod_type : 2; - // The rest, testing if mixing int and uint is ok. - int _some_free_bits_ : 11; - uint _more_free_bits_ : 17; + unsigned int prod_type : 2; + + // The rest, testing if mixing int and unsigned int is ok. + int _some_free_bits_ : 11; + unsigned int _more_free_bits_ : 17; }; - uint _raw_; + unsigned int _raw_; }; Status() : _raw_(0) {} @@ -377,8 +378,8 @@ class Track // Maybe needed for MkFi**r copy in / out // Status& refStatus() { return status_; } // Status* ptrStatus() { return &status_; } - // uint rawStatus() const { return status_._raw_; } - // void setRawStatus(uint rs) { status_._raw_ = rs; } + // unsigned int rawStatus() const { return status_._raw_; } + // void setRawStatus(unsigned int rs) { status_._raw_ = rs; } bool isFindable() const { return ! status_.not_findable; } bool isNotFindable() const { return status_.not_findable; } diff --git a/mkFit/Makefile b/mkFit/Makefile index 51a2d1aaf3e80..bb01d7f6ca36f 100644 --- a/mkFit/Makefile +++ b/mkFit/Makefile @@ -89,7 +89,7 @@ include ${MKFDEPS} endif mkFit: ${ALLOBJS} - ${CXX} ${CXXFLAGS} ${VEC_HOST} ${LDFLAGS} ${ALLOBJS} -o $@ ${LDFLAGS_HOST} ${LDFLAGS_CU} -L.. -lMicCore -Wl,-rpath=..,-rpath=. + ${CXX} ${CXXFLAGS} ${VEC_HOST} ${LDFLAGS} ${ALLOBJS} -o $@ ${LDFLAGS_HOST} ${LDFLAGS_CU} -L.. -lMicCore -Wl,-rpath,..,-rpath,. ifdef WITH_ROOT fittestMPlex.o : CPPFLAGS += $(shell root-config --cflags) From 9868cf1755390b08096cdf0de0efb781f2ecda4d Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Wed, 19 Jul 2017 00:36:42 +0200 Subject: [PATCH 095/172] for validation on cmswn1937 --- validationMICwn37-build-10mu.sh | 93 +++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100755 validationMICwn37-build-10mu.sh diff --git a/validationMICwn37-build-10mu.sh b/validationMICwn37-build-10mu.sh new file mode 100755 index 0000000000000..a7dea21ef52c7 --- /dev/null +++ b/validationMICwn37-build-10mu.sh @@ -0,0 +1,93 @@ +#! /bin/bash + +sed -i 's/#WITH_ROOT := yes/WITH_ROOT := yes/g' Makefile.config + +make -j 12 + +ecn2=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEta-24to-17Pt1to10/memoryFile.fv3.071417.bin +ecn1=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEta-175to-055Pt1to10/memoryFile.fv3.071417.bin +brl=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEtaLT06Pt1to10/memoryFile.fv3.071417.bin +ecp1=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEta055to175Pt1to10/memoryFile.fv3.071417.bin +ecp2=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEta17to24Pt1to10/memoryFile.fv3.071417.bin + + +## ECN2 ## +echo "SNB CMSSW BH (ECN2): validation [nTH:1, nVU:8]" +./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${ecn2} --build-bh --num-thr 8 >& log_SNB_CMSSW_ECN2_BH_NVU8int_NTH8_val.txt +mv valtree.root valtree_SNB_CMSSW_ECN2_BH.root +echo "SNB CMSSW STD (ECN2): validation [nTH:8, nVU:8]" +./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${ecn2} --build-std --num-thr 8 >& log_SNB_CMSSW_ECN2_STD_NVU8int_NTH8_val.txt +mv valtree.root valtree_SNB_CMSSW_ECN2_STD.root +echo "SNB CMSSW CE (ECN2): validation [nTH:8, nVU:8]" +./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${ecn2} --build-ce --num-thr 8 >& log_SNB_CMSSW_ECN2_CE_NVU8int_NTH8_val.txt +mv valtree.root valtree_SNB_CMSSW_ECN2_CE.root + +## ECN1 ## +echo "SNB CMSSW BH (ECN1): validation [nTH:8, nVU:8]" +./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${ecn1} --build-bh --num-thr 8 >& log_SNB_CMSSW_ECN1_BH_NVU8int_NTH8_val.txt +mv valtree.root valtree_SNB_CMSSW_ECN1_BH.root +echo "SNB CMSSW STD (ECN1): validation [nTH:8, nVU:8]" +./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${ecn1} --build-std --num-thr 8 >& log_SNB_CMSSW_ECN1_STD_NVU8int_NTH8_val.txt +mv valtree.root valtree_SNB_CMSSW_ECN1_STD.root +echo "SNB CMSSW CE (ECN1): validation [nTH:8, nVU:8]" +./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${ecn1} --build-ce --num-thr 8 >& log_SNB_CMSSW_ECN1_CE_NVU8int_NTH8_val.txt +mv valtree.root valtree_SNB_CMSSW_ECN1_CE.root + +## BRL ## +echo "SNB CMSSW BH (BRL): validation [nTH:8, nVU:8]" +./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${brl} --build-bh --num-thr 8 >& log_SNB_CMSSW_BRL_BH_NVU8int_NTH8_val.txt +mv valtree.root valtree_SNB_CMSSW_BRL_BH.root +echo "SNB CMSSW STD (BRL): validation [nTH:8, nVU:8]" +./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${brl} --build-std --num-thr 8 >& log_SNB_CMSSW_BRL_STD_NVU8int_NTH8_val.txt +mv valtree.root valtree_SNB_CMSSW_BRL_STD.root +echo "SNB CMSSW CE (BRL): validation [nTH:8, nVU:8]" +./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${brl} --build-ce --num-thr 8 >& log_SNB_CMSSW_BRL_CE_NVU8int_NTH8_val.txt +mv valtree.root valtree_SNB_CMSSW_BRL_CE.root + +## ECP1 ## +echo "SNB CMSSW BH (ECP1): validation [nTH:8, nVU:8]" +./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${ecp1} --build-bh --num-thr 8 >& log_SNB_CMSSW_ECP1_BH_NVU8int_NTH8_val.txt +mv valtree.root valtree_SNB_CMSSW_ECP1_BH.root +echo "SNB CMSSW STD (ECP1): validation [nTH:8, nVU:8]" +./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${ecp1} --build-std --num-thr 8 >& log_SNB_CMSSW_ECP1_STD_NVU8int_NTH8_val.txt +mv valtree.root valtree_SNB_CMSSW_ECP1_STD.root +echo "SNB CMSSW CE (ECP1): validation [nTH:8, nVU:8]" +./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${ecp1} --build-ce --num-thr 8 >& log_SNB_CMSSW_ECP1_CE_NVU8int_NTH8_val.txt +mv valtree.root valtree_SNB_CMSSW_ECP1_CE.root + +## ECP2 ## +echo "SNB CMSSW BH (ECP2): validation [nTH:8, nVU:8]" +./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${ecp2} --build-bh --num-thr 8 >& log_SNB_CMSSW_ECP2_BH_NVU8int_NTH8_val.txt +mv valtree.root valtree_SNB_CMSSW_ECP2_BH.root +echo "SNB CMSSW STD (ECP2): validation [nTH:8, nVU:8]" +./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${ecp2} --build-std --num-thr 8 >& log_SNB_CMSSW_ECP2_STD_NVU8int_NTH8_val.txt +mv valtree.root valtree_SNB_CMSSW_ECP2_STD.root +echo "SNB CMSSW CE (ECP2): validation [nTH:8, nVU:8]" +./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${ecp2} --build-ce --num-thr 8 >& log_SNB_CMSSW_ECP2_CE_NVU8int_NTH8_val.txt +mv valtree.root valtree_SNB_CMSSW_ECP2_CE.root + + + +sed -i 's/WITH_ROOT := yes/#WITH_ROOT := yes/g' Makefile.config + +make clean + +for section in ECN2 ECN1 BRL ECP1 ECP2 +do + for build in BH STD CE + do + root -b -q -l runValidation.C+\(\"_SNB_CMSSW_${section}_${build}\"\) + done + root -b -q -l makeValidation.C+\(\"SNB_CMSSW_${section}\"\) +done + +for build in BH STD CE +do + hadd valtree_SNB_CMSSW_FullDet_${build}.root validation_SNB_CMSSW_ECN2_${build}/valtree_SNB_CMSSW_ECN2_${build}.root validation_SNB_CMSSW_ECN1_${build}/valtree_SNB_CMSSW_ECN1_${build}.root validation_SNB_CMSSW_BRL_${build}/valtree_SNB_CMSSW_BRL_${build}.root validation_SNB_CMSSW_ECP1_${build}/valtree_SNB_CMSSW_ECP1_${build}.root validation_SNB_CMSSW_ECP2_${build}/valtree_SNB_CMSSW_ECP2_${build}.root + + root -b -q -l runValidation.C+\(\"_SNB_CMSSW_FullDet_${build}\"\) +done + +root -b -q -l makeValidation.C+\(\"SNB_CMSSW_FullDet\"\) + +make distclean \ No newline at end of file From 4333d6f501fbed2bb8bece830ca6142db6ae657e Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Wed, 19 Jul 2017 14:53:36 +0200 Subject: [PATCH 096/172] fix extra_sections integrity check on read; fix DataFile::CloseWrite to use only write and update only when n_written differs from expectation --- Event.cc | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Event.cc b/Event.cc index 3832cf3e458e6..8abd17d2ce186 100644 --- a/Event.cc +++ b/Event.cc @@ -786,12 +786,11 @@ void DataFile::Close() f_header = DataFileHeader(); } - void DataFile::CloseWrite(int n_written){ - fseek(f_fp, 0, SEEK_SET); - DataFileHeader a_header; - fread(&a_header, sizeof(DataFileHeader), 1, f_fp); - - a_header.f_n_events = n_written; - fwrite(&a_header, sizeof(DataFileHeader), 1, f_fp); - Close(); - } +void DataFile::CloseWrite(int n_written){ + if (f_header.f_n_events != n_written){ + fseek(f_fp, 0, SEEK_SET); + f_header.f_n_events = n_written; + fwrite(&f_header, sizeof(DataFileHeader), 1, f_fp); + } + Close(); +} From 13c7a6a195dbeabe4c3f7045478bccd168657abd Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Wed, 19 Jul 2017 14:56:38 +0200 Subject: [PATCH 097/172] fill and optionally write reco tracks: rec track label points to the seed (unconditionally), track uncertainties are only partially filled from diagonal elements (should be good enough for our purpose) --- tkNtuple/WriteMemoryFile.cc | 208 ++++++++++++++++++++++++++++++++---- 1 file changed, 185 insertions(+), 23 deletions(-) diff --git a/tkNtuple/WriteMemoryFile.cc b/tkNtuple/WriteMemoryFile.cc index 195dd37a773a5..e202091020573 100644 --- a/tkNtuple/WriteMemoryFile.cc +++ b/tkNtuple/WriteMemoryFile.cc @@ -166,6 +166,7 @@ void printHelp(const char* av0){ " --verbosity print details (0 quiet, 1 print counts, 2 print all; def: 0)\n" " --clean-sim-tracks apply sim track cleaning (def: no cleaning)\n" " --write-all-events write all events (def: skip events with 0 simtracks or seeds)\n" + " --write-rec-tracks write rec tracks (def: not written)\n" , av0); } @@ -178,6 +179,8 @@ int main(int argc, char *argv[]) bool cleanSimTracks = false; bool writeAllEvents = false; + bool writeRecTracks = false; + int verbosity = 0; lStr_t mArgs; @@ -220,6 +223,10 @@ int main(int argc, char *argv[]) { writeAllEvents = true; } + else if (*i == "--write-rec-tracks") + { + writeRecTracks = true; + } else { fprintf(stderr, "Error: Unknown option/argument '%s'.\n", i->c_str()); @@ -318,12 +325,48 @@ int main(int argc, char *argv[]) t->SetBranchAddress("simhit_hitType", &simhit_hitType); //rec tracks - std::vector* trk_nValid = 0; - std::vector* trk_nInvalid = 0; - std::vector* trk_seedIdx = 0; + std::vector* trk_q = 0; + std::vector* trk_nValid = 0; + std::vector* trk_nInvalid = 0; + std::vector* trk_seedIdx = 0; + std::vector* trk_algoMask = 0; + std::vector* trk_algo = 0 ; + std::vector* trk_originalAlgo = 0; + std::vector* trk_nChi2 = 0; + std::vector* trk_px = 0; + std::vector* trk_py = 0; + std::vector* trk_pz = 0; + std::vector* trk_pt = 0; + std::vector* trk_phi = 0; + std::vector* trk_refpoint_x = 0; + std::vector* trk_refpoint_y = 0; + std::vector* trk_refpoint_z = 0; + std::vector* trk_dxyErr = 0; + std::vector* trk_dzErr = 0; + std::vector* trk_ptErr = 0; + std::vector* trk_phiErr = 0; + std::vector* trk_lambdaErr = 0; + t->SetBranchAddress("trk_q", &trk_q); t->SetBranchAddress("trk_nValid", &trk_nValid); t->SetBranchAddress("trk_nInvalid", &trk_nInvalid); t->SetBranchAddress("trk_seedIdx", &trk_seedIdx); + t->SetBranchAddress("trk_algoMask", &trk_algoMask); + t->SetBranchAddress("trk_algo", &trk_algo); + t->SetBranchAddress("trk_originalAlgo", &trk_originalAlgo); + t->SetBranchAddress("trk_nChi2", &trk_nChi2); + t->SetBranchAddress("trk_px", &trk_px); + t->SetBranchAddress("trk_py", &trk_py); + t->SetBranchAddress("trk_pz", &trk_pz); + t->SetBranchAddress("trk_pt", &trk_pt); + t->SetBranchAddress("trk_phi", &trk_phi); + t->SetBranchAddress("trk_refpoint_x", &trk_refpoint_x); + t->SetBranchAddress("trk_refpoint_y", &trk_refpoint_y); + t->SetBranchAddress("trk_refpoint_z", &trk_refpoint_z); + t->SetBranchAddress("trk_dxyErr", &trk_dxyErr); + t->SetBranchAddress("trk_dzErr", &trk_dzErr); + t->SetBranchAddress("trk_ptErr", &trk_ptErr); + t->SetBranchAddress("trk_phiErr", &trk_phiErr); + t->SetBranchAddress("trk_lambdaErr", &trk_lambdaErr); std::vector >* trk_hitIdx = 0; t->SetBranchAddress("trk_hitIdx", &trk_hitIdx); @@ -443,22 +486,20 @@ int main(int argc, char *argv[]) vector* glu_yz = 0; vector* glu_zz = 0; vector* glu_zx = 0; - if (useMatched) { - t->SetBranchAddress("glu_isBarrel",&glu_isBarrel); - t->SetBranchAddress("glu_det",&glu_det); - t->SetBranchAddress("glu_lay",&glu_lay); - t->SetBranchAddress("glu_monoIdx",&glu_monoIdx); - t->SetBranchAddress("glu_stereoIdx",&glu_stereoIdx); - t->SetBranchAddress("glu_x",&glu_x); - t->SetBranchAddress("glu_y",&glu_y); - t->SetBranchAddress("glu_z",&glu_z); - t->SetBranchAddress("glu_xx",&glu_xx); - t->SetBranchAddress("glu_xy",&glu_xy); - t->SetBranchAddress("glu_yy",&glu_yy); - t->SetBranchAddress("glu_yz",&glu_yz); - t->SetBranchAddress("glu_zz",&glu_zz); - t->SetBranchAddress("glu_zx",&glu_zx); - } + t->SetBranchAddress("glu_isBarrel",&glu_isBarrel); + t->SetBranchAddress("glu_det",&glu_det); + t->SetBranchAddress("glu_lay",&glu_lay); + t->SetBranchAddress("glu_monoIdx",&glu_monoIdx); + t->SetBranchAddress("glu_stereoIdx",&glu_stereoIdx); + t->SetBranchAddress("glu_x",&glu_x); + t->SetBranchAddress("glu_y",&glu_y); + t->SetBranchAddress("glu_z",&glu_z); + t->SetBranchAddress("glu_xx",&glu_xx); + t->SetBranchAddress("glu_xy",&glu_xy); + t->SetBranchAddress("glu_yy",&glu_yy); + t->SetBranchAddress("glu_yz",&glu_yz); + t->SetBranchAddress("glu_zz",&glu_zz); + t->SetBranchAddress("glu_zx",&glu_zx); vector* str_isBarrel = 0; vector* str_isStereo = 0; @@ -498,7 +539,9 @@ int main(int argc, char *argv[]) long long savedEvents = 0; DataFile data_file; - data_file.OpenWrite(outputFileName, std::min(maxevt, totentries), DataFile::ES_Seeds); + int outOptions = DataFile::ES_Seeds; + if (writeRecTracks) outOptions |= DataFile::ES_ExtRecTracks; + data_file.OpenWrite(outputFileName, std::min(maxevt, totentries), outOptions); Event EE(0); @@ -518,7 +561,11 @@ int main(int argc, char *argv[]) if (nSims==0) { cout << "branches not loaded" << endl; exit(1); } - if (verbosity>0) std::cout<<__FILE__<<" "<<__LINE__<<" nSims "<0) std::cout<<__FILE__<<" "<<__LINE__ + <<" nSims "<size() + <<" nRecT "<size() + < const& shs, std::vector const& shfs, int rhIdx, HitType rhType){ @@ -779,6 +826,84 @@ int main(int argc, char *argv[]) if (seedTracks_.empty() and not writeAllEvents) continue; + vector &extRecTracks_ = EE.extRecTracks_; + vector > pixHitRecIdx(pix_lay->size()); + vector > strHitRecIdx(str_lay->size()); + vector > gluHitRecIdx(glu_lay->size()); + for (int ir = 0; irsize(); ++ir) { + if ((trk_algoMask->at(ir) & (1 << int(TrackAlgorithm::initialStep))) == 0){//check the origin; redundant for initialStep ntuples + if (verbosity > 1){ + std::cout<<"track "<at(ir) + <<" origAlgo "<at(ir)<<" algo "<at(ir) + <at(ir), trk_refpoint_y->at(ir), trk_refpoint_z->at(ir)); + SVector3 mom = SVector3(trk_px->at(ir), trk_py->at(ir), trk_pz->at(ir)); + SMatrixSym66 err; + /* + vx = -dxy*sin(phi) - pt*cos(phi)/p*pz/p*dz; + vy = dxy*cos(phi) - pt*sin(phi)/p*pz/p*dz; + vz = dz*pt*pt/p/p; + //partial: ignores cross-terms + c(vx,vx) = c(dxy,dxy)*sin(phi)*sin(phi) + c(dz,dz)*pow(pt*cos(phi)/p*pz/p ,2); + c(vx,vy) = -c(dxy,dxy)*cos(phi)*sin(phi) + c(dz,dz)*cos(phi)*sin(phi)*pow(pt/p*pz/p, 2); + c(vy,vy) = c(dxy,dxy)*cos(phi)*cos(phi) + c(dz,dz)*pow(pt*sin(phi)/p*pz/p ,2); + c(vx,vz) = -c(dz,dz)*pt*pt/p/p*pt/p*pz/p*cos(phi); + c(vy,vz) = -c(dz,dz)*pt*pt/p/p*pt/p*pz/p*sin(phi); + c(vz,vz) = c(dz,dz)*pow(pt*pt/p/p, 2); + */ + float pt = trk_pt->at(ir); + float pz = trk_pz->at(ir); + float p2 = pt*pt + pz*pz; + float sP = sin(trk_phi->at(ir)); + float cP = cos(trk_phi->at(ir)); + err.At(0,0) = std::pow(trk_dxyErr->at(ir), 2)*sP*sP + std::pow(trk_dzErr->at(ir)*(pt*pz/p2), 2)*cP*cP; + err.At(0,1) = -std::pow(trk_dxyErr->at(ir), 2)*cP*sP + std::pow(trk_dzErr->at(ir)*(pt*pz/p2), 2)*cP*sP; + err.At(1,1) = std::pow(trk_dxyErr->at(ir), 2)*cP*cP + std::pow(trk_dzErr->at(ir)*(pt*pz/p2), 2)*sP*sP; + err.At(0,2) = -std::pow(trk_dzErr->at(ir)*(pt*pz/p2), 2)*cP*pt/pz; + err.At(1,2) = -std::pow(trk_dzErr->at(ir)*(pt*pz/p2), 2)*sP*pt/pz; + err.At(2,2) = std::pow(trk_dzErr->at(ir)*(pt*pt/p2), 2); + err.At(3,3) = std::pow(trk_ptErr->at(ir)/pt/pt, 2); + err.At(4,4) = std::pow(trk_phiErr->at(ir), 2); + err.At(5,5) = std::pow(trk_lambdaErr->at(ir), 2); + TrackState state(trk_q->at(ir), pos, mom, err); +#ifndef CCSCOORD + //begin test CCS coordinates + state.convertFromCCSToCartesian(); + //end test CCS coordinates +#endif + Track track(state, trk_nChi2->at(ir), trk_seedIdx->at(ir), 0, nullptr);//hits are filled later + auto const& hTypes = trk_hitType->at(ir); + auto const& hIdxs = trk_hitIdx->at(ir); + for (int ip=0; ip > &layerHits_ = EE.layerHits_; @@ -810,6 +935,10 @@ int main(int argc, char *argv[]) //cout << "xxx ipix=" << ipix << " seed=" << pixHitSeedIdx[ipix][is] << endl; seedTracks_[pixHitSeedIdx[ipix][is]].addHitIdx(layerHits_[ilay].size(), ilay, 0);//per-hit chi2 is not known } + for (int ir=0;ir1) { printf("\n"); @@ -918,7 +1058,9 @@ int main(int argc, char *argv[]) for (int i=0;i1 }//verbosity>0 EE.write_out(data_file); From 05e4406b852def06ba45e5cf83259c5f4884907c Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Wed, 19 Jul 2017 14:57:05 +0200 Subject: [PATCH 098/172] update to 071817 input files with recT present --- validationMICwn37-build-10mu.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/validationMICwn37-build-10mu.sh b/validationMICwn37-build-10mu.sh index a7dea21ef52c7..0563651adcad4 100755 --- a/validationMICwn37-build-10mu.sh +++ b/validationMICwn37-build-10mu.sh @@ -4,11 +4,11 @@ sed -i 's/#WITH_ROOT := yes/WITH_ROOT := yes/g' Makefile.config make -j 12 -ecn2=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEta-24to-17Pt1to10/memoryFile.fv3.071417.bin -ecn1=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEta-175to-055Pt1to10/memoryFile.fv3.071417.bin -brl=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEtaLT06Pt1to10/memoryFile.fv3.071417.bin -ecp1=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEta055to175Pt1to10/memoryFile.fv3.071417.bin -ecp2=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEta17to24Pt1to10/memoryFile.fv3.071417.bin +ecn2=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEta-24to-17Pt1to10/memoryFile.fv3.recT.071817.bin +ecn1=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEta-175to-055Pt1to10/memoryFile.fv3.recT.071817.bin +brl=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEtaLT06Pt1to10/memoryFile.fv3.recT.071817.bin +ecp1=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEta055to175Pt1to10/memoryFile.fv3.recT.071817.bin +ecp2=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEta17to24Pt1to10/memoryFile.fv3.recT.071817.bin ## ECN2 ## From 6b577e5e642b87bf6d4947e83c74ced4d532340b Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Fri, 21 Jul 2017 02:58:16 +0200 Subject: [PATCH 099/172] refactor and include CMSSW seed option --- validationMICwn37-build-10mu.sh | 116 ++++++++++++-------------------- 1 file changed, 43 insertions(+), 73 deletions(-) diff --git a/validationMICwn37-build-10mu.sh b/validationMICwn37-build-10mu.sh index 0563651adcad4..d21555eb7a6a8 100755 --- a/validationMICwn37-build-10mu.sh +++ b/validationMICwn37-build-10mu.sh @@ -4,90 +4,60 @@ sed -i 's/#WITH_ROOT := yes/WITH_ROOT := yes/g' Makefile.config make -j 12 -ecn2=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEta-24to-17Pt1to10/memoryFile.fv3.recT.071817.bin -ecn1=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEta-175to-055Pt1to10/memoryFile.fv3.recT.071817.bin -brl=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEtaLT06Pt1to10/memoryFile.fv3.recT.071817.bin -ecp1=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEta055to175Pt1to10/memoryFile.fv3.recT.071817.bin -ecp2=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEta17to24Pt1to10/memoryFile.fv3.recT.071817.bin - - -## ECN2 ## -echo "SNB CMSSW BH (ECN2): validation [nTH:1, nVU:8]" -./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${ecn2} --build-bh --num-thr 8 >& log_SNB_CMSSW_ECN2_BH_NVU8int_NTH8_val.txt -mv valtree.root valtree_SNB_CMSSW_ECN2_BH.root -echo "SNB CMSSW STD (ECN2): validation [nTH:8, nVU:8]" -./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${ecn2} --build-std --num-thr 8 >& log_SNB_CMSSW_ECN2_STD_NVU8int_NTH8_val.txt -mv valtree.root valtree_SNB_CMSSW_ECN2_STD.root -echo "SNB CMSSW CE (ECN2): validation [nTH:8, nVU:8]" -./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${ecn2} --build-ce --num-thr 8 >& log_SNB_CMSSW_ECN2_CE_NVU8int_NTH8_val.txt -mv valtree.root valtree_SNB_CMSSW_ECN2_CE.root - -## ECN1 ## -echo "SNB CMSSW BH (ECN1): validation [nTH:8, nVU:8]" -./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${ecn1} --build-bh --num-thr 8 >& log_SNB_CMSSW_ECN1_BH_NVU8int_NTH8_val.txt -mv valtree.root valtree_SNB_CMSSW_ECN1_BH.root -echo "SNB CMSSW STD (ECN1): validation [nTH:8, nVU:8]" -./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${ecn1} --build-std --num-thr 8 >& log_SNB_CMSSW_ECN1_STD_NVU8int_NTH8_val.txt -mv valtree.root valtree_SNB_CMSSW_ECN1_STD.root -echo "SNB CMSSW CE (ECN1): validation [nTH:8, nVU:8]" -./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${ecn1} --build-ce --num-thr 8 >& log_SNB_CMSSW_ECN1_CE_NVU8int_NTH8_val.txt -mv valtree.root valtree_SNB_CMSSW_ECN1_CE.root - -## BRL ## -echo "SNB CMSSW BH (BRL): validation [nTH:8, nVU:8]" -./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${brl} --build-bh --num-thr 8 >& log_SNB_CMSSW_BRL_BH_NVU8int_NTH8_val.txt -mv valtree.root valtree_SNB_CMSSW_BRL_BH.root -echo "SNB CMSSW STD (BRL): validation [nTH:8, nVU:8]" -./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${brl} --build-std --num-thr 8 >& log_SNB_CMSSW_BRL_STD_NVU8int_NTH8_val.txt -mv valtree.root valtree_SNB_CMSSW_BRL_STD.root -echo "SNB CMSSW CE (BRL): validation [nTH:8, nVU:8]" -./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${brl} --build-ce --num-thr 8 >& log_SNB_CMSSW_BRL_CE_NVU8int_NTH8_val.txt -mv valtree.root valtree_SNB_CMSSW_BRL_CE.root - -## ECP1 ## -echo "SNB CMSSW BH (ECP1): validation [nTH:8, nVU:8]" -./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${ecp1} --build-bh --num-thr 8 >& log_SNB_CMSSW_ECP1_BH_NVU8int_NTH8_val.txt -mv valtree.root valtree_SNB_CMSSW_ECP1_BH.root -echo "SNB CMSSW STD (ECP1): validation [nTH:8, nVU:8]" -./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${ecp1} --build-std --num-thr 8 >& log_SNB_CMSSW_ECP1_STD_NVU8int_NTH8_val.txt -mv valtree.root valtree_SNB_CMSSW_ECP1_STD.root -echo "SNB CMSSW CE (ECP1): validation [nTH:8, nVU:8]" -./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${ecp1} --build-ce --num-thr 8 >& log_SNB_CMSSW_ECP1_CE_NVU8int_NTH8_val.txt -mv valtree.root valtree_SNB_CMSSW_ECP1_CE.root - -## ECP2 ## -echo "SNB CMSSW BH (ECP2): validation [nTH:8, nVU:8]" -./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${ecp2} --build-bh --num-thr 8 >& log_SNB_CMSSW_ECP2_BH_NVU8int_NTH8_val.txt -mv valtree.root valtree_SNB_CMSSW_ECP2_BH.root -echo "SNB CMSSW STD (ECP2): validation [nTH:8, nVU:8]" -./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${ecp2} --build-std --num-thr 8 >& log_SNB_CMSSW_ECP2_STD_NVU8int_NTH8_val.txt -mv valtree.root valtree_SNB_CMSSW_ECP2_STD.root -echo "SNB CMSSW CE (ECP2): validation [nTH:8, nVU:8]" -./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${ecp2} --build-ce --num-thr 8 >& log_SNB_CMSSW_ECP2_CE_NVU8int_NTH8_val.txt -mv valtree.root valtree_SNB_CMSSW_ECP2_CE.root - - +ECN2=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEta-24to-17Pt1to10/memoryFile.fv3.recT.071817.bin +ECN1=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEta-175to-055Pt1to10/memoryFile.fv3.recT.071817.bin +BRL=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEtaLT06Pt1to10/memoryFile.fv3.recT.071817.bin +ECP1=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEta055to175Pt1to10/memoryFile.fv3.recT.071817.bin +ECP2=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEta17to24Pt1to10/memoryFile.fv3.recT.071817.bin + +for section in ECN2 ECN1 BRL ECP1 ECP2; do + echo "SNB CMSSW_sim BH (${section}): validation [nTH:1, nVU:8]" + ./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${!section} --build-bh --num-thr 8 >& log_SNB_CMSSW_sim_${section}_BH_NVU8int_NTH8_val.txt + mv valtree.root valtree_SNB_CMSSW_sim_${section}_BH.root + echo "SNB CMSSW_sim STD (${section}): validation [nTH:8, nVU:8]" + ./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${!section} --build-std --num-thr 8 >& log_SNB_CMSSW_sim_${section}_STD_NVU8int_NTH8_val.txt + mv valtree.root valtree_SNB_CMSSW_sim_${section}_STD.root + echo "SNB CMSSW_sim CE (${section}): validation [nTH:8, nVU:8]" + ./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${!section} --build-ce --num-thr 8 >& log_SNB_CMSSW_sim_${section}_CE_NVU8int_NTH8_val.txt + mv valtree.root valtree_SNB_CMSSW_sim_${section}_CE.root +done +for section in ECN2 ECN1 BRL ECP1 ECP2; do + echo "SNB CMSSW_see BH (${section}): validation [nTH:1, nVU:8]" + ./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${!section} --build-bh --cmssw-seeds --num-thr 8 >& log_SNB_CMSSW_see_${section}_BH_NVU8int_NTH8_val.txt + mv valtree.root valtree_SNB_CMSSW_see_${section}_BH.root + echo "SNB CMSSW_see STD (${section}): validation [nTH:8, nVU:8]" + ./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${!section} --build-std --cmssw-seeds --num-thr 8 >& log_SNB_CMSSW_see_${section}_STD_NVU8int_NTH8_val.txt + mv valtree.root valtree_SNB_CMSSW_see_${section}_STD.root + echo "SNB CMSSW_see CE (${section}): validation [nTH:8, nVU:8]" + ./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${!section} --build-ce --cmssw-seeds --num-thr 8 >& log_SNB_CMSSW_see_${section}_CE_NVU8int_NTH8_val.txt + mv valtree.root valtree_SNB_CMSSW_see_${section}_CE.root +done sed -i 's/WITH_ROOT := yes/#WITH_ROOT := yes/g' Makefile.config make clean -for section in ECN2 ECN1 BRL ECP1 ECP2 +for opt in sim see do + for section in ECN2 ECN1 BRL ECP1 ECP2 + do + for build in BH STD CE + do + root -b -q -l runValidation.C+\(\"_SNB_CMSSW_${opt}_${section}_${build}\"\) + done + root -b -q -l makeValidation.C+\(\"SNB_CMSSW_${opt}_${section}\"\) + done + for build in BH STD CE do - root -b -q -l runValidation.C+\(\"_SNB_CMSSW_${section}_${build}\"\) + hadd valtree_SNB_CMSSW_${opt}_FullDet_${build}.root validation_SNB_CMSSW_${opt}_ECN2_${build}/valtree_SNB_CMSSW_${opt}_ECN2_${build}.root validation_SNB_CMSSW_${opt}_ECN1_${build}/valtree_SNB_CMSSW_${opt}_ECN1_${build}.root validation_SNB_CMSSW_${opt}_BRL_${build}/valtree_SNB_CMSSW_${opt}_BRL_${build}.root validation_SNB_CMSSW_${opt}_ECP1_${build}/valtree_SNB_CMSSW_${opt}_ECP1_${build}.root validation_SNB_CMSSW_${opt}_ECP2_${build}/valtree_SNB_CMSSW_${opt}_ECP2_${build}.root + + root -b -q -l runValidation.C+\(\"_SNB_CMSSW_${opt}_FullDet_${build}\"\) done - root -b -q -l makeValidation.C+\(\"SNB_CMSSW_${section}\"\) -done -for build in BH STD CE -do - hadd valtree_SNB_CMSSW_FullDet_${build}.root validation_SNB_CMSSW_ECN2_${build}/valtree_SNB_CMSSW_ECN2_${build}.root validation_SNB_CMSSW_ECN1_${build}/valtree_SNB_CMSSW_ECN1_${build}.root validation_SNB_CMSSW_BRL_${build}/valtree_SNB_CMSSW_BRL_${build}.root validation_SNB_CMSSW_ECP1_${build}/valtree_SNB_CMSSW_ECP1_${build}.root validation_SNB_CMSSW_ECP2_${build}/valtree_SNB_CMSSW_ECP2_${build}.root + root -b -q -l makeValidation.C+\(\"SNB_CMSSW_${opt}_FullDet\"\) - root -b -q -l runValidation.C+\(\"_SNB_CMSSW_FullDet_${build}\"\) done -root -b -q -l makeValidation.C+\(\"SNB_CMSSW_FullDet\"\) +make distclean -make distclean \ No newline at end of file From 06d24a55e2e72198453a0ddeea83fe5847a2f689 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Fri, 21 Jul 2017 02:59:03 +0200 Subject: [PATCH 100/172] fix region selection in the negative side --- TrackerInfo.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TrackerInfo.h b/TrackerInfo.h index 878469157a038..8e327971a4418 100644 --- a/TrackerInfo.h +++ b/TrackerInfo.h @@ -114,8 +114,8 @@ class TrackerInfo EtaRegion find_eta_region(float eta) const { - if (eta < -m_eta_trans_beg) return Reg_Endcap_Neg; - else if (eta < -m_eta_trans_end) return Reg_Transition_Neg; + if (eta < -m_eta_trans_end) return Reg_Endcap_Neg; + else if (eta < -m_eta_trans_beg) return Reg_Transition_Neg; else if (eta < m_eta_trans_beg) return Reg_Barrel; else if (eta < m_eta_trans_end) return Reg_Transition_Pos; else return Reg_Endcap_Pos; From 994bbc72da6c52fb060d63be2e56143ffaac71d9 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Fri, 21 Jul 2017 15:53:07 +0200 Subject: [PATCH 101/172] add CPPUSERFLAGS CXXUSERFLAGS LDUSERFLAGS, which can be passed to make in the command line or in another Makefile --- Makefile.config | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile.config b/Makefile.config index bc5cb2674c8ae..00014d7970693 100644 --- a/Makefile.config +++ b/Makefile.config @@ -216,5 +216,9 @@ else MAKEDEPEND = ${CXX} -MM -MG ${DEPEND_TGTS} ${CPPFLAGS} endif +CPPFLAGS += ${CPPUSERFLAGS} +CXXFLAGS += ${CXXUSERFLAGS} +LDFLAGS += ${LDUSERFLAGS} + %.d: %.cc ${MAKEDEPEND} -o $@ $< From 3304e3be2ca8d6046702920f415212c72b77688c Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Fri, 21 Jul 2017 15:54:03 +0200 Subject: [PATCH 102/172] fix to compile in DEBUG mode --- Event.cc | 3 ++- mkFit/MkFinder.cc | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Event.cc b/Event.cc index 8abd17d2ce186..4fda5686c851e 100644 --- a/Event.cc +++ b/Event.cc @@ -617,9 +617,10 @@ int Event::clean_cms_simtracks() dprintf("Event::clean_cms_simtracks processing %d simtracks.\n", simTracks_.size()); int n_acc = 0; - + int i = -1;//wrap in ifdef DEBUG? for (Track & t : simTracks_) { + i++; const int nh = t.nFoundHits(); t.sortHitsByLayer(); diff --git a/mkFit/MkFinder.cc b/mkFit/MkFinder.cc index d274298e651f9..37fb869a31eb5 100644 --- a/mkFit/MkFinder.cc +++ b/mkFit/MkFinder.cc @@ -810,7 +810,7 @@ void MkFinder::FindCandidatesCloneEngine(const LayerOfHits &layer_of_hits, CandC for (int itrack = 0; itrack < N_proc; ++itrack) { #ifdef DEBUG - std::cout << "countInvalidHits(" << itrack << ")=" << countInvalidHits(itrack) << std::endl; + std::cout << "num_invalid_hits(" << itrack << ")=" << num_invalid_hits(itrack) << std::endl; #endif int fake_hit_idx = num_invalid_hits(itrack) < Config::maxHolesPerCand ? -1 : -2; From 8e7c4988a9d995f6e02fc99c293a65d1b564cbe4 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Fri, 21 Jul 2017 22:44:06 +0200 Subject: [PATCH 103/172] use command line to pass env vars --- validationMICwn37-build-10mu.sh | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/validationMICwn37-build-10mu.sh b/validationMICwn37-build-10mu.sh index d21555eb7a6a8..66adc76a1ca78 100755 --- a/validationMICwn37-build-10mu.sh +++ b/validationMICwn37-build-10mu.sh @@ -1,8 +1,6 @@ #! /bin/bash -sed -i 's/#WITH_ROOT := yes/WITH_ROOT := yes/g' Makefile.config - -make -j 12 +make -j 12 WITH_ROOT=yes ECN2=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEta-24to-17Pt1to10/memoryFile.fv3.recT.071817.bin ECN1=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEta-175to-055Pt1to10/memoryFile.fv3.recT.071817.bin @@ -33,8 +31,6 @@ for section in ECN2 ECN1 BRL ECP1 ECP2; do mv valtree.root valtree_SNB_CMSSW_see_${section}_CE.root done -sed -i 's/WITH_ROOT := yes/#WITH_ROOT := yes/g' Makefile.config - make clean for opt in sim see From dfd0d482a5d63b0a48e12973d1e8f117f8f718c8 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Wed, 26 Jul 2017 21:46:24 +0200 Subject: [PATCH 104/172] compact some more --- validationMICwn37-build-10mu.sh | 49 ++++++++++++++++----------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/validationMICwn37-build-10mu.sh b/validationMICwn37-build-10mu.sh index 66adc76a1ca78..79521b9056406 100755 --- a/validationMICwn37-build-10mu.sh +++ b/validationMICwn37-build-10mu.sh @@ -8,27 +8,20 @@ BRL=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4 ECP1=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEta055to175Pt1to10/memoryFile.fv3.recT.071817.bin ECP2=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEta17to24Pt1to10/memoryFile.fv3.recT.071817.bin -for section in ECN2 ECN1 BRL ECP1 ECP2; do - echo "SNB CMSSW_sim BH (${section}): validation [nTH:1, nVU:8]" - ./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${!section} --build-bh --num-thr 8 >& log_SNB_CMSSW_sim_${section}_BH_NVU8int_NTH8_val.txt - mv valtree.root valtree_SNB_CMSSW_sim_${section}_BH.root - echo "SNB CMSSW_sim STD (${section}): validation [nTH:8, nVU:8]" - ./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${!section} --build-std --num-thr 8 >& log_SNB_CMSSW_sim_${section}_STD_NVU8int_NTH8_val.txt - mv valtree.root valtree_SNB_CMSSW_sim_${section}_STD.root - echo "SNB CMSSW_sim CE (${section}): validation [nTH:8, nVU:8]" - ./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${!section} --build-ce --num-thr 8 >& log_SNB_CMSSW_sim_${section}_CE_NVU8int_NTH8_val.txt - mv valtree.root valtree_SNB_CMSSW_sim_${section}_CE.root -done -for section in ECN2 ECN1 BRL ECP1 ECP2; do - echo "SNB CMSSW_see BH (${section}): validation [nTH:1, nVU:8]" - ./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${!section} --build-bh --cmssw-seeds --num-thr 8 >& log_SNB_CMSSW_see_${section}_BH_NVU8int_NTH8_val.txt - mv valtree.root valtree_SNB_CMSSW_see_${section}_BH.root - echo "SNB CMSSW_see STD (${section}): validation [nTH:8, nVU:8]" - ./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${!section} --build-std --cmssw-seeds --num-thr 8 >& log_SNB_CMSSW_see_${section}_STD_NVU8int_NTH8_val.txt - mv valtree.root valtree_SNB_CMSSW_see_${section}_STD.root - echo "SNB CMSSW_see CE (${section}): validation [nTH:8, nVU:8]" - ./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${!section} --build-ce --cmssw-seeds --num-thr 8 >& log_SNB_CMSSW_see_${section}_CE_NVU8int_NTH8_val.txt - mv valtree.root valtree_SNB_CMSSW_see_${section}_CE.root +base=SNB_CMSSW_10mu + +for sV in "sim " "see --cmssw-seeds"; do echo $sV | while read -r sN sO; do + for section in ECN2 ECN1 BRL ECP1 ECP2; do + for bV in "BH bh" "STD std" "CE ce"; do echo $bV | while read -r bN bO; do + oBase=${base}_${sN}_${section}_${bN} + nTH=8 + echo "${oBase}: validation [nTH:${nTH}, nVU:8]" + ./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${!section} --build-${bO} ${sO} --num-thr ${nTH} >& log_${oBase}_NVU8int_NTH${nTH}_val.txt + mv valtree.root valtree_${oBase}.root + done + done + done + done done make clean @@ -37,21 +30,25 @@ for opt in sim see do for section in ECN2 ECN1 BRL ECP1 ECP2 do + oBase=${base}_${opt}_${section} for build in BH STD CE do - root -b -q -l runValidation.C+\(\"_SNB_CMSSW_${opt}_${section}_${build}\"\) + root -b -q -l runValidation.C+\(\"_${oBase}_${build}\"\) done - root -b -q -l makeValidation.C+\(\"SNB_CMSSW_${opt}_${section}\"\) + root -b -q -l makeValidation.C+\(\"${oBase}\"\) done for build in BH STD CE do - hadd valtree_SNB_CMSSW_${opt}_FullDet_${build}.root validation_SNB_CMSSW_${opt}_ECN2_${build}/valtree_SNB_CMSSW_${opt}_ECN2_${build}.root validation_SNB_CMSSW_${opt}_ECN1_${build}/valtree_SNB_CMSSW_${opt}_ECN1_${build}.root validation_SNB_CMSSW_${opt}_BRL_${build}/valtree_SNB_CMSSW_${opt}_BRL_${build}.root validation_SNB_CMSSW_${opt}_ECP1_${build}/valtree_SNB_CMSSW_${opt}_ECP1_${build}.root validation_SNB_CMSSW_${opt}_ECP2_${build}/valtree_SNB_CMSSW_${opt}_ECP2_${build}.root + oBase=${base}_${opt} + fBase=valtree_${oBase} + dBase=validation_${oBase} + hadd ${fBase}_FullDet_${build}.root `for section in ECN2 ECN1 BRL ECP1 ECP2; do echo -n ${dBase}_${section}_${build}/${fBase}_${section}_${build}.root" "; done` - root -b -q -l runValidation.C+\(\"_SNB_CMSSW_${opt}_FullDet_${build}\"\) + root -b -q -l runValidation.C+\(\"_${oBase}_FullDet_${build}\"\) done - root -b -q -l makeValidation.C+\(\"SNB_CMSSW_${opt}_FullDet\"\) + root -b -q -l makeValidation.C+\(\"${oBase}_FullDet\"\) done From aa28d65834147599012ac7a5864a8e8796235ac1 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Wed, 26 Jul 2017 21:47:55 +0200 Subject: [PATCH 105/172] PU70 validation driver --- validationMICwn37-build-PU70.sh | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 validationMICwn37-build-PU70.sh diff --git a/validationMICwn37-build-PU70.sh b/validationMICwn37-build-PU70.sh new file mode 100755 index 0000000000000..07a853a649698 --- /dev/null +++ b/validationMICwn37-build-PU70.sh @@ -0,0 +1,33 @@ +#! /bin/bash + +make -j 12 WITH_ROOT=yes + +fin=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/PU70/10224.0_TTbar_13+TTbar_13TeV_TuneCUETP8M1_2017PU_GenSimFullINPUT+DigiFullPU_2017PU+RecoFullPU_2017PU+HARVESTFullPU_2017PU/memoryFile.fv3.clean.writeAll.recT.071817.bin + +base=SNB_CMSSW_PU70_clean + +for sV in "sim " "see --cmssw-seeds"; do echo $sV | while read -r sN sO; do + for bV in "BH bh" "STD std" "CE ce"; do echo $bV | while read -r bN bO; do + oBase=${base}_${sN}_${bN} + nTH=8 + echo "${oBase}: validation [nTH:${nTH}, nVU:8]" + ./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${fin} --build-${bO} ${sO} --num-thr ${nTH} >& log_${oBase}_NVU8int_NTH${nTH}_val.txt + mv valtree.root valtree_${oBase}.root + done + done + done +done + +make clean + +for opt in sim see +do + oBase=${base}_${opt} + for build in BH STD CE + do + root -b -q -l runValidation.C+\(\"_${oBase}_${build}\"\) + done + root -b -q -l makeValidation.C+\(\"${oBase}\"\) +done + +make distclean From 2353bbe88da46db941343a18a1401fb82de448cc Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Wed, 26 Jul 2017 23:51:51 +0200 Subject: [PATCH 106/172] consistently set track state parameters in CCS --- tkNtuple/WriteMemoryFile.cc | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/tkNtuple/WriteMemoryFile.cc b/tkNtuple/WriteMemoryFile.cc index e202091020573..334fd9661ee6d 100644 --- a/tkNtuple/WriteMemoryFile.cc +++ b/tkNtuple/WriteMemoryFile.cc @@ -338,6 +338,7 @@ int main(int argc, char *argv[]) std::vector* trk_pz = 0; std::vector* trk_pt = 0; std::vector* trk_phi = 0; + std::vector* trk_lambda = 0; std::vector* trk_refpoint_x = 0; std::vector* trk_refpoint_y = 0; std::vector* trk_refpoint_z = 0; @@ -359,6 +360,7 @@ int main(int argc, char *argv[]) t->SetBranchAddress("trk_pz", &trk_pz); t->SetBranchAddress("trk_pt", &trk_pt); t->SetBranchAddress("trk_phi", &trk_phi); + t->SetBranchAddress("trk_lambda", &trk_lambda); t->SetBranchAddress("trk_refpoint_x", &trk_refpoint_x); t->SetBranchAddress("trk_refpoint_y", &trk_refpoint_y); t->SetBranchAddress("trk_refpoint_z", &trk_refpoint_z); @@ -839,8 +841,7 @@ int main(int argc, char *argv[]) } continue; } - SVector3 pos = SVector3(trk_refpoint_x->at(ir), trk_refpoint_y->at(ir), trk_refpoint_z->at(ir)); - SVector3 mom = SVector3(trk_px->at(ir), trk_py->at(ir), trk_pz->at(ir)); + //fill the state in CCS upfront SMatrixSym66 err; /* vx = -dxy*sin(phi) - pt*cos(phi)/p*pz/p*dz; @@ -857,17 +858,23 @@ int main(int argc, char *argv[]) float pt = trk_pt->at(ir); float pz = trk_pz->at(ir); float p2 = pt*pt + pz*pz; - float sP = sin(trk_phi->at(ir)); - float cP = cos(trk_phi->at(ir)); - err.At(0,0) = std::pow(trk_dxyErr->at(ir), 2)*sP*sP + std::pow(trk_dzErr->at(ir)*(pt*pz/p2), 2)*cP*cP; - err.At(0,1) = -std::pow(trk_dxyErr->at(ir), 2)*cP*sP + std::pow(trk_dzErr->at(ir)*(pt*pz/p2), 2)*cP*sP; - err.At(1,1) = std::pow(trk_dxyErr->at(ir), 2)*cP*cP + std::pow(trk_dzErr->at(ir)*(pt*pz/p2), 2)*sP*sP; - err.At(0,2) = -std::pow(trk_dzErr->at(ir)*(pt*pz/p2), 2)*cP*pt/pz; - err.At(1,2) = -std::pow(trk_dzErr->at(ir)*(pt*pz/p2), 2)*sP*pt/pz; - err.At(2,2) = std::pow(trk_dzErr->at(ir)*(pt*pt/p2), 2); + float phi = trk_phi->at(ir); + float sP = sin(phi); + float cP = cos(phi); + float dxyErr2 = trk_dxyErr->at(ir); dxyErr2 *= dxyErr2; + float dzErr2 = trk_dzErr->at(ir); dzErr2 *= dzErr2; + float dzErrF2 = trk_dzErr->at(ir)*(pt*pz/p2); dzErr2 *= dzErr2; + err.At(0,0) = dxyErr2 *sP*sP + dzErrF2 *cP*cP; + err.At(0,1) = -dxyErr2 *cP*sP + dzErrF2 *cP*sP; + err.At(1,1) = dxyErr2 *cP*cP + dzErrF2 *sP*sP; + err.At(0,2) = -dzErrF2*cP*pt/pz; + err.At(1,2) = -dzErrF2*sP*pt/pz; + err.At(2,2) = dzErr2*std::pow((pt*pt/p2), 2); err.At(3,3) = std::pow(trk_ptErr->at(ir)/pt/pt, 2); err.At(4,4) = std::pow(trk_phiErr->at(ir), 2); err.At(5,5) = std::pow(trk_lambdaErr->at(ir), 2); + SVector3 pos = SVector3(trk_refpoint_x->at(ir), trk_refpoint_y->at(ir), trk_refpoint_z->at(ir)); + SVector3 mom = SVector3(1.f/pt, phi, M_PI_2 - trk_lambda->at(ir)); TrackState state(trk_q->at(ir), pos, mom, err); #ifndef CCSCOORD //begin test CCS coordinates @@ -1083,7 +1090,8 @@ int main(int argc, char *argv[]) if (writeRecTracks){ for (int i=0;i Date: Thu, 27 Jul 2017 01:39:48 +0200 Subject: [PATCH 107/172] set simtrack label to match the track index in the output --- tkNtuple/WriteMemoryFile.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tkNtuple/WriteMemoryFile.cc b/tkNtuple/WriteMemoryFile.cc index 334fd9661ee6d..a128ad55be8d9 100644 --- a/tkNtuple/WriteMemoryFile.cc +++ b/tkNtuple/WriteMemoryFile.cc @@ -726,7 +726,9 @@ int main(int argc, char *argv[]) state.convertFromCartesianToCCS(); //end test CCS coordinates #endif - Track track(state, float(nlay), isim, 0, nullptr);//store number of reco hits in place of track chi2; fill hits later + //create track: store number of reco hits in place of track chi2; fill hits later + // set label to be its own index in the output file + Track track(state, float(nlay), simTracks_.size(), 0, nullptr); if (sim_bunchCrossing->at(isim) == 0){//in time if (sim_event->at(isim) == 0) track.setProdType(Track::ProdType::Signal); else track.setProdType(Track::ProdType::InTimePU); From 5b82b1718404144eeccecd7286881de9a1420a2c Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Thu, 27 Jul 2017 01:46:35 +0200 Subject: [PATCH 108/172] advance to new files --- validationMICwn37-build-10mu.sh | 10 +++++----- validationMICwn37-build-PU70.sh | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/validationMICwn37-build-10mu.sh b/validationMICwn37-build-10mu.sh index 79521b9056406..890b91d06500b 100755 --- a/validationMICwn37-build-10mu.sh +++ b/validationMICwn37-build-10mu.sh @@ -2,11 +2,11 @@ make -j 12 WITH_ROOT=yes -ECN2=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEta-24to-17Pt1to10/memoryFile.fv3.recT.071817.bin -ECN1=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEta-175to-055Pt1to10/memoryFile.fv3.recT.071817.bin -BRL=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEtaLT06Pt1to10/memoryFile.fv3.recT.071817.bin -ECP1=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEta055to175Pt1to10/memoryFile.fv3.recT.071817.bin -ECP2=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEta17to24Pt1to10/memoryFile.fv3.recT.071817.bin +ECN2=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEta-24to-17Pt1to10/memoryFile.fv3.recT.072617.bin +ECN1=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEta-175to-055Pt1to10/memoryFile.fv3.recT.072617.bin +BRL=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEtaLT06Pt1to10/memoryFile.fv3.recT.072617.bin +ECP1=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEta055to175Pt1to10/memoryFile.fv3.recT.072617.bin +ECP2=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEta17to24Pt1to10/memoryFile.fv3.recT.072617.bin base=SNB_CMSSW_10mu diff --git a/validationMICwn37-build-PU70.sh b/validationMICwn37-build-PU70.sh index 07a853a649698..22915bb538c7b 100755 --- a/validationMICwn37-build-PU70.sh +++ b/validationMICwn37-build-PU70.sh @@ -2,7 +2,7 @@ make -j 12 WITH_ROOT=yes -fin=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/PU70/10224.0_TTbar_13+TTbar_13TeV_TuneCUETP8M1_2017PU_GenSimFullINPUT+DigiFullPU_2017PU+RecoFullPU_2017PU+HARVESTFullPU_2017PU/memoryFile.fv3.clean.writeAll.recT.071817.bin +fin=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/PU70/10224.0_TTbar_13+TTbar_13TeV_TuneCUETP8M1_2017PU_GenSimFullINPUT+DigiFullPU_2017PU+RecoFullPU_2017PU+HARVESTFullPU_2017PU/memoryFile.fv3.clean.writeAll.recT.072617.bin base=SNB_CMSSW_PU70_clean From f3b948910a461e053c39f12ad9a5dc35d32a5548 Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Fri, 14 Jul 2017 06:53:38 -0700 Subject: [PATCH 109/172] Add momentum phi wrapping to propagation and update * includes an if version (assuming only diffs of +/-PI): default for now * includes a more generic version for multiples of +/-PI (versus using a while which can lead to junk loops when looping over NN instead of N_proc) * fixups to validation scripts --- generateToyMCsamples.sh | 4 ++-- mkFit/KalmanUtilsMPlex.cc | 3 +++ mkFit/PropagationMPlex.cc | 8 ++++++++ mkFit/PropagationMPlex.h | 17 +++++++++++++++++ validation-snb-toymc-fulldet-build.sh | 2 +- 5 files changed, 31 insertions(+), 3 deletions(-) diff --git a/generateToyMCsamples.sh b/generateToyMCsamples.sh index 21a1d21e075e9..900d4f1a46223 100755 --- a/generateToyMCsamples.sh +++ b/generateToyMCsamples.sh @@ -2,7 +2,7 @@ make -j 12 -dir=/data/nfsmic/${TOYMCUSER:-kmcdermo}/toymc +dir=/data/nfsmic/scratch/toymc mkdir -p ${dir} # Building test: Barrel @@ -27,12 +27,12 @@ if [ ! -f ${dir}/simtracks_endcap_1kx10k.bin ]; then fi make clean -make -j 12 # Validation tests: Barrel if [ ! -f ${dir}/simtracks_fulldet_400x2p5k_val.bin ]; then echo "++++Generating 2.5k tracks/event * 400 events for ToyMC barrel-only validation tests++++" sed -i 's/#WITH_ROOT := yes/WITH_ROOT := yes/g' Makefile.config + make -j 12 ./mkFit/mkFit --num-thr-sim 12 --root-val --num-events 400 --num-tracks 2500 --write --file-name simtracks_fulldet_400x2p5k_val.bin mv simtracks_fulldet_400x2p5k_val.bin ${dir}/ sed -i 's/WITH_ROOT := yes/#WITH_ROOT := yes/g' Makefile.config diff --git a/mkFit/KalmanUtilsMPlex.cc b/mkFit/KalmanUtilsMPlex.cc index f305af040ee9f..9ee2d04b51d34 100644 --- a/mkFit/KalmanUtilsMPlex.cc +++ b/mkFit/KalmanUtilsMPlex.cc @@ -633,6 +633,7 @@ void updateParametersMPlex(const MPlexLS &psErr, const MPlexLV& psPar, const MP MultResidualsAdd(K, propPar_ccs, res_loc, propPar_ccs);// propPar_ccs is now the updated parameters in CCS coordinates #endif + squashPhiMPlex(outPar,N_proc); // ensure phi is between |pi| KHMult(K, rotT00, rotT01, tempLL); KHC(tempLL, propErr, outErr); @@ -866,6 +867,8 @@ void updateParametersEndcapMPlex(const MPlexLS &psErr, const MPlexLV& psPar, co MultResidualsAdd(K, propPar, res, outPar); + squashPhiMPlex(outPar,N_proc); // ensure phi is between |pi| + KHC(K, propErr, outErr); #ifdef DEBUG diff --git a/mkFit/PropagationMPlex.cc b/mkFit/PropagationMPlex.cc index bdf98d516b213..a71a23154693e 100644 --- a/mkFit/PropagationMPlex.cc +++ b/mkFit/PropagationMPlex.cc @@ -566,6 +566,8 @@ void propagateHelixToRMPlex(const MPlexLS &inErr, const MPlexLV& inPar, applyMaterialEffects(hitsRl, hitsXi, outErr, outPar, N_proc); } + squashPhiMPlex(outPar,N_proc); // ensure phi is between |pi| + // Matriplex version of: // result.errors = ROOT::Math::Similarity(errorProp, outErr); MPlexLL temp; @@ -636,6 +638,8 @@ void propagateHelixToRMPlex(const MPlexLS& inErr, const MPlexLV& inPar, applyMaterialEffects(hitsRl, hitsXi, outErr, outPar, N_proc); } + squashPhiMPlex(outPar,N_proc); // ensure phi is between |pi| + // Matriplex version of: // result.errors = ROOT::Math::Similarity(errorProp, outErr); @@ -723,6 +727,8 @@ void propagateHelixToZMPlex(const MPlexLS &inErr, const MPlexLV& inPar, applyMaterialEffects(hitsRl, hitsXi, outErr, outPar, N_proc); } + squashPhiMPlex(outPar,N_proc); // ensure phi is between |pi| + // Matriplex version of: // result.errors = ROOT::Math::Similarity(errorProp, outErr); MPlexLL temp; @@ -808,6 +814,8 @@ void propagateHelixToZMPlex(const MPlexLS &inErr, const MPlexLV& inPar, applyMaterialEffects(hitsRl, hitsXi, outErr, outPar, N_proc); } + squashPhiMPlex(outPar,N_proc); // ensure phi is between |pi| + // Matriplex version of: // result.errors = ROOT::Math::Similarity(errorProp, outErr); MPlexLL temp; diff --git a/mkFit/PropagationMPlex.h b/mkFit/PropagationMPlex.h index c44ca9f6a41d6..e3eed36a41507 100644 --- a/mkFit/PropagationMPlex.h +++ b/mkFit/PropagationMPlex.h @@ -3,6 +3,23 @@ #include "Matrix.h" +inline void squashPhiMPlex(MPlexLV& par, const int N_proc) +{ + #pragma simd + for (int n = 0; n < NN; ++n) { + if (par(n, 4, 0) >= Config::PI) par(n, 4, 0) -= Config::TwoPI; + if (par(n, 4, 0) < -Config::PI) par(n, 4, 0) += Config::TwoPI; + } +} + +inline void squashPhiMPlexGeneral(MPlexLV& par, const int N_proc) +{ + #pragma simd + for (int n = 0; n < NN; ++n) { + par(n, 4, 0) -= std::floor(0.5f*Config::InvPI*(par(n, 4, 0)+Config::PI)) * Config::TwoPI; + } +} + void propagateLineToRMPlex(const MPlexLS &psErr, const MPlexLV& psPar, const MPlexHS &msErr, const MPlexHV& msPar, MPlexLS &outErr, MPlexLV& outPar, diff --git a/validation-snb-toymc-fulldet-build.sh b/validation-snb-toymc-fulldet-build.sh index 7d28453670b9c..c68a5d1f772b6 100755 --- a/validation-snb-toymc-fulldet-build.sh +++ b/validation-snb-toymc-fulldet-build.sh @@ -4,7 +4,7 @@ sed -i 's/#WITH_ROOT := yes/WITH_ROOT := yes/g' Makefile.config make -j 12 -dir=/data/nfsmic/${TOYMCUSER:-kmcdermo}/toymc +dir=/data/nfsmic/scratch/toymc echo "SNB ToyMC BH (FullDet): validation [nTH:24, nVU:8]" ./mkFit/mkFit --root-val --read --file-name ${dir}/simtracks_fulldet_400x2p5k_val.bin --build-bh --num-thr 24 >& log_SNB_ToyMC_FullDet_BH_NVU8int_NTH24_val.txt From d6ba0a425f52c95a8ea0c5d6f035e9b0b60e8c75 Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Wed, 26 Jul 2017 14:29:58 -0700 Subject: [PATCH 110/172] add Geoms to distclean --- Geoms/Makefile | 2 ++ Makefile | 1 + 2 files changed, 3 insertions(+) diff --git a/Geoms/Makefile b/Geoms/Makefile index 9d9c21508f686..06305bba069b6 100644 --- a/Geoms/Makefile +++ b/Geoms/Makefile @@ -40,3 +40,5 @@ endif clean: rm -f *.so *.o *.om *.d *.optrpt + +distclean: clean \ No newline at end of file diff --git a/Makefile b/Makefile index 04f818875af43..f85528069e7ec 100644 --- a/Makefile +++ b/Makefile @@ -50,6 +50,7 @@ clean: clean-local distclean: clean-local -rm -f ${AUTO_TGTS} -rm -f *.optrpt + cd Geoms && ${MAKE} distclean cd Matriplex && ${MAKE} distclean cd mkFit && ${MAKE} distclean From d55ff893c29b978f845a6bc27f246586b28c9deb Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Wed, 26 Jul 2017 14:50:32 -0700 Subject: [PATCH 111/172] fixups: * fix alignment bug in track extras * move some legacy smatrix routines to track header to be used by validation vs having multiple copies * use generic phi wrapping for smatrix (templated for later use in reco cmssw validation) --- Event.cc | 2 +- TTreeValidation.cc | 40 +++++++++++++----------------------- TTreeValidation.h | 2 +- Track.h | 23 +++++++++++++++++++++ Validation.h | 2 +- buildtest.cc | 6 ------ mkFit/MkBuilder.cc | 51 +++++++++++++++------------------------------- mkFit/MkBuilder.h | 2 +- 8 files changed, 57 insertions(+), 71 deletions(-) diff --git a/Event.cc b/Event.cc index 4fda5686c851e..565ead7b8e0a6 100644 --- a/Event.cc +++ b/Event.cc @@ -304,7 +304,7 @@ void Event::Seed(const BinInfoMap & segmentMap) simTracksExtra_ = seedTracksExtra_; #endif std::sort(seedTracks_.begin(), seedTracks_.end(), tracksByPhi); - validation_.alignTrackExtra(seedTracks_,seedTracksExtra_); // if we sort here, also have to sort seedTracksExtra and redo labels. + validation_.alignTracks(seedTracks_,seedTracksExtra_,true); // if we sort here, also have to sort seedTracksExtra and redo labels. } void Event::Find(const BinInfoMap & segmentMap) diff --git a/TTreeValidation.cc b/TTreeValidation.cc index f418fe48b4ae3..82da2ac438faf 100644 --- a/TTreeValidation.cc +++ b/TTreeValidation.cc @@ -46,22 +46,6 @@ #include "Propagation.h" #ifndef NO_ROOT -inline bool sortByHitsChi2(const Track & cand1, const Track & cand2) -{ - if (cand1.nFoundHits()==cand2.nFoundHits()) return cand1.chi2()cand2.nFoundHits(); -} - -inline float computeHelixChi2(const SVector6& simParams, const SVector6& recoParams, const SMatrixSym66& recoErrs) -{ - float chi2 = 0; - for(auto i = 0; i < Config::nParams; i++){ - float delta = simParams.At(i) - recoParams.At(i); - chi2 += (delta*delta) / recoErrs.At(i,i); - } - return chi2 / (Config::nParams - 1); -} - TTreeValidation::TTreeValidation(std::string fileName) { std::lock_guard locker(glock_); @@ -396,19 +380,23 @@ void TTreeValidation::initializeFitTree() fittree_->Branch("emeta_sim",&emeta_sim_fit_,"emeta_sim_fit_[ntotallayers_fit_]/F"); } -void TTreeValidation::alignTrackExtra(TrackVec& evt_tracks, TrackExtraVec& evt_extras) +void TTreeValidation::alignTracks(TrackVec& evt_tracks, TrackExtraVec& evt_extras, bool alignExtra) { - TrackExtraVec trackExtra_tmp(evt_tracks.size()); + // redo trackExtras first if necessary + if (alignExtra) + { + TrackExtraVec trackExtra_tmp(evt_tracks.size()); - // align temporary tkExVec with new track collection ordering - for (int itrack = 0; itrack < evt_tracks.size(); itrack++) - { - trackExtra_tmp[itrack] = evt_extras[evt_tracks[itrack].label()]; // label is old seedID! - } + // align temporary tkExVec with new track collection ordering + for (int itrack = 0; itrack < evt_tracks.size(); itrack++) + { + trackExtra_tmp[itrack] = evt_extras[evt_tracks[itrack].label()]; // label is old seedID! + } + + // now copy the temporary back in the old one + evt_extras = trackExtra_tmp; + } - // now copy the temporary back in the old one - evt_extras = trackExtra_tmp; - // redo track labels to match index in vector for (int itrack = 0; itrack < evt_tracks.size(); itrack++) { diff --git a/TTreeValidation.h b/TTreeValidation.h index 28936db8eaad1..3144c09211e0d 100644 --- a/TTreeValidation.h +++ b/TTreeValidation.h @@ -30,7 +30,7 @@ class TTreeValidation : public Validation { void initializeConfigTree(); void initializeFitTree(); - void alignTrackExtra(TrackVec& evt_tracks, TrackExtraVec& evt_extra) override; + void alignTracks(TrackVec& evt_tracks, TrackExtraVec& evt_extra, bool alignExtra) override; void collectFitInfo(const FitVal& tmpfitval, int tkid, int layer) override; diff --git a/Track.h b/Track.h index a6d0d72bd1876..ddd39d72428ea 100644 --- a/Track.h +++ b/Track.h @@ -407,6 +407,29 @@ class Track typedef std::vector TrackVec; typedef std::vector TrackVecVec; +inline bool sortByHitsChi2(const Track & cand1, const Track & cand2) +{ + if (cand1.nFoundHits()==cand2.nFoundHits()) return cand1.chi2()cand2.nFoundHits(); +} + +template +inline void squashPhiGeneral(V& params) +{ + const int i = params.kSize-2; // phi index + params[i] -= floor(0.5f*Config::InvPI*(params[i]+Config::PI)) * Config::TwoPI; +} + +template +inline float computeHelixChi2(const V& simParams, const V& recoParams, const M& recoErrs) +{ + int invFail(0); + const M recoErrsI = recoErrs.InverseFast(invFail); + V diffParams = recoParams - simParams; + squashPhiGeneral(diffParams); + return ROOT::Math::Dot(diffParams*recoErrsI,diffParams) / (diffParams.kSize - 1); +} + class TrackExtra { public: diff --git a/Validation.h b/Validation.h index 1e1fed4879156..d1ee627d9d9a3 100644 --- a/Validation.h +++ b/Validation.h @@ -23,7 +23,7 @@ struct FitVal class Validation { public: - virtual void alignTrackExtra(TrackVec&, TrackExtraVec&) {} + virtual void alignTracks(TrackVec&, TrackExtraVec&, bool) {} virtual void resetValidationMaps() {} virtual void resetDebugVectors() {} diff --git a/buildtest.cc b/buildtest.cc index 425ce74f3020c..9d07839d644c4 100644 --- a/buildtest.cc +++ b/buildtest.cc @@ -27,12 +27,6 @@ typedef candvec::const_iterator canditer; void extendCandidate(const BinInfoMap & segmentMap, const Event& ev, const cand_t& cand, candvec& tmp_candidates, int ilay, int seedID, bool debug); -inline bool sortByHitsChi2(const cand_t& cand1, const cand_t& cand2) -{ - if (cand1.nFoundHits()==cand2.nFoundHits()) return cand1.chi2()cand2.nFoundHits(); -} - void processCandidates(const BinInfoMap & segmentMap, Event& ev, candvec& candidates, int ilay, int seedID, const bool debug) { auto& evt_track_candidates(ev.candidateTracks_); diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index b95e06d479552..39b22a5c1a264 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -796,19 +796,6 @@ void MkBuilder::remap_cand_hits() } } -void MkBuilder::align_simtracks() -{ - // XXXXMT : Does this change with the new format? - - if (Config::readCmsswSeeds && Config::endcapTest) - { - for (int itrack = 0; itrack < m_event->simTracks_.size(); itrack++) - { - m_event->simTracks_[itrack].setLabel(itrack); - } - } -} - //------------------------------------------------------------------------------ // Non-ROOT validation //------------------------------------------------------------------------------ @@ -819,8 +806,6 @@ void MkBuilder::quality_output_BH() remap_cand_hits(); - align_simtracks(); - for (int i = 0; i < m_event->candidateTracks_.size(); i++) { quality_process(m_event->candidateTracks_[i]); @@ -837,8 +822,6 @@ void MkBuilder::quality_output_COMB() remap_cand_hits(); - align_simtracks(); - for (int i = 0; i < m_event->candidateTracks_.size(); i++) { quality_process(m_event->candidateTracks_[i]); @@ -940,8 +923,8 @@ void MkBuilder::root_val_BH() // get the tracks ready for validation remap_cand_hits(); m_event->fitTracks_ = m_event->candidateTracks_; // fixme: hack for now. eventually fitting will be including end-to-end - align_simtracks(); init_track_extras(); + align_recotracks(); m_event->Validate(); } @@ -954,37 +937,35 @@ void MkBuilder::root_val_COMB() quality_store_tracks_COMB(); remap_cand_hits(); m_event->fitTracks_ = m_event->candidateTracks_; // fixme: hack for now. eventually fitting will be including end-to-end - align_simtracks(); init_track_extras(); + align_recotracks(); m_event->Validate(); } void MkBuilder::init_track_extras() { - TrackVec & seedtracks = m_event->seedTracks_; - TrackExtraVec & seedtrackextras = m_event->seedTracksExtra_; - for (int i = 0; i < seedtracks.size(); i++) + for (int i = 0; i < m_event->seedTracks_.size(); i++) { - seedtrackextras.emplace_back(seedtracks[i].label()); + m_event->seedTracksExtra_.emplace_back(m_event->seedTracks_[i].label()); } - m_event->validation_.alignTrackExtra(seedtracks,seedtrackextras); - TrackVec & candidatetracks = m_event->candidateTracks_; - TrackExtraVec & candidatetrackextras = m_event->candidateTracksExtra_; - for (int i = 0; i < candidatetracks.size(); i++) + for (int i = 0; i < m_event->candidateTracks_.size(); i++) { - candidatetrackextras.emplace_back(candidatetracks[i].label()); + m_event->candidateTracksExtra_.emplace_back(m_event->candidateTracks_[i].label()); } - m_event->validation_.alignTrackExtra(candidatetracks,candidatetrackextras); - - TrackVec & fittracks = m_event->fitTracks_; - TrackExtraVec & fittrackextras = m_event->fitTracksExtra_; - for (int i = 0; i < fittracks.size(); i++) + + for (int i = 0; i < m_event->fitTracks_.size(); i++) { - fittrackextras.emplace_back(fittracks[i].label()); + m_event->fitTracksExtra_.emplace_back(m_event->fitTracks_[i].label()); } - m_event->validation_.alignTrackExtra(fittracks,fittrackextras); +} + +void MkBuilder::align_recotracks() +{ + m_event->validation_.alignTracks(m_event->seedTracks_,m_event->seedTracksExtra_,false); + m_event->validation_.alignTracks(m_event->candidateTracks_,m_event->candidateTracksExtra_,false); + m_event->validation_.alignTracks(m_event->fitTracks_,m_event->fitTracksExtra_,false); } //------------------------------------------------------------------------------ diff --git a/mkFit/MkBuilder.h b/mkFit/MkBuilder.h index 7af85596444c9..e7ae302b150b6 100644 --- a/mkFit/MkBuilder.h +++ b/mkFit/MkBuilder.h @@ -80,7 +80,7 @@ class MkBuilder void map_seed_hits(); // m_event->layerHits_ -> m_event_of_hits.m_layers_of_hits (seeds only) void remap_seed_hits(); // m_event_of_hits.m_layers_of_hits -> m_event->layerHits_ (seeds only) void remap_cand_hits(); // m_event_of_hits.m_layers_of_hits -> m_event->layerHits_ (cands only) - void align_simtracks(); // simtrack labels get screwed up in endcap tests + void align_recotracks(); // ensure that all track collections have labels equal to index inside vector void quality_output_BH(); void quality_output_COMB(); From a94be8e6302c646d8dad07ea8084631241226fd8 Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Wed, 26 Jul 2017 15:19:27 -0700 Subject: [PATCH 112/172] fix warnings --- Event.cc | 6 ++---- mkFit/mkFit.cc | 10 ++++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Event.cc b/Event.cc index 565ead7b8e0a6..54605f7dfd3f4 100644 --- a/Event.cc +++ b/Event.cc @@ -728,14 +728,12 @@ int DataFile::OpenRead(const std::string& fname, bool set_n_layers) } if (Config::readCmsswSeeds && ! HasSeeds()) { - fprintf(stderr, "Reading of CmsswSeeds requested but data not available on file.\n", - f_header.f_n_layers, Config::nTotalLayers); + fprintf(stderr, "Reading of CmsswSeeds requested but data not available on file.\n"); exit(1); } if (Config::readExtRecTracks && ! HasExtRecTracks()) { - fprintf(stderr, "Reading of ExtRecTracks requested but data not available on file.\n", - f_header.f_n_layers, Config::nTotalLayers); + fprintf(stderr, "Reading of ExtRecTracks requested but data not available on file.\n"); exit(1); } diff --git a/mkFit/mkFit.cc b/mkFit/mkFit.cc index 5cbcc1ccfa977..df5554b9dd8d7 100644 --- a/mkFit/mkFit.cc +++ b/mkFit/mkFit.cc @@ -486,7 +486,7 @@ int main(int argc, const char *argv[]) " --num-tracks number of tracks to generate for each event (def: %d)\n" " --num-thr-sim number of threads for simulation (def: %d)\n" " --num-thr number of threads for track finding (def: %d)\n" - " --num-thr-ev number of threads to run the event loop\n" + " --num-thr-ev number of threads to run the event loop (def: %d)\n" " --fit-std run standard fitting test (def: false)\n" " --fit-std-only run only standard fitting test (def: false)\n" " --chi2cut chi2 cut used in building test (def: %.1f)\n" @@ -512,16 +512,17 @@ int main(int argc, const char *argv[]) " --file-name file name for write/read (def: %s)\n" " --input-file file name for reading when converting formats (def: %s)\n" "GPU specific options: \n" - " --num-thr-reorg number of threads to run the hits reorganization\n" + " --num-thr-reorg number of threads to run the hits reorganization (def: %d)\n" , argv[0], Config::geomPlugin.c_str(), Config::nEvents, Config::nTracks, - Config::numThreadsSimulation, Config::numThreadsFinder, + Config::numThreadsSimulation, Config::numThreadsFinder, Config::numThreadsEvents, Config::chi2Cut, Config::numSeedsPerTask, Config::finderReportBestOutOfN, + b2a(Config::readExtRecTracks), b2a(Config::readCmsswSeeds), b2a(Config::findSeeds), Config::numHitsPerTask, @@ -534,7 +535,8 @@ int main(int argc, const char *argv[]) b2a(Config::silent), g_start_event, g_file_name.c_str(), - g_input_file.c_str() + g_input_file.c_str(), + Config::numThreadsReorg ); exit(0); } From 616f321f4a0d1c5925dd5d9cf4daf2d7b394059f Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Thu, 27 Jul 2017 05:21:38 -0700 Subject: [PATCH 113/172] only use 75% associator if using simtracks for seeds, regardless of geom; update 10mu script --- TTreeValidation.cc | 4 +- validation-snb-cmssw-fulldet-build.sh | 94 +++++++++++++-------------- 2 files changed, 47 insertions(+), 51 deletions(-) diff --git a/TTreeValidation.cc b/TTreeValidation.cc index 82da2ac438faf..8b107311f2e8e 100644 --- a/TTreeValidation.cc +++ b/TTreeValidation.cc @@ -444,7 +444,7 @@ void TTreeValidation::setTrackExtras(Event& ev) { auto&& track(ev.candidateTracks_[itrack]); auto&& extra(ev.candidateTracksExtra_[itrack]); - if (Config::useCMSGeom || Config::findSeeds) {extra.setMCTrackIDInfo(track, ev.layerHits_, ev.simHitsInfo_, ev.simTracks_, false);} + if (Config::readCmsswSeeds || Config::findSeeds) {extra.setMCTrackIDInfo(track, ev.layerHits_, ev.simHitsInfo_, ev.simTracks_, false);} else {extra.setMCTrackIDInfoByLabel(track, ev.layerHits_, ev.simHitsInfo_);} } @@ -453,7 +453,7 @@ void TTreeValidation::setTrackExtras(Event& ev) { auto&& track(ev.fitTracks_[itrack]); auto&& extra(ev.fitTracksExtra_[itrack]); - if (Config::useCMSGeom || Config::findSeeds) {extra.setMCTrackIDInfo(track, ev.layerHits_, ev.simHitsInfo_, ev.simTracks_, false);} + if (Config::readCmsswSeeds || Config::findSeeds) {extra.setMCTrackIDInfo(track, ev.layerHits_, ev.simHitsInfo_, ev.simTracks_, false);} else {extra.setMCTrackIDInfoByLabel(track, ev.layerHits_, ev.simHitsInfo_);} } } diff --git a/validation-snb-cmssw-fulldet-build.sh b/validation-snb-cmssw-fulldet-build.sh index 92c8ed6c258b9..71a14cebc80a3 100755 --- a/validation-snb-cmssw-fulldet-build.sh +++ b/validation-snb-cmssw-fulldet-build.sh @@ -1,64 +1,60 @@ #! /bin/bash -sed -i 's/#WITH_ROOT := yes/WITH_ROOT := yes/g' Makefile.config +make distclean +make -j 12 WITH_ROOT=yes -make -j 12 +dir=/data/nfsmic/slava77/samples/2017/pass-4874f28/initialStep +file=memoryFile.fv3.recT.072617.bin -dir=/data/nfsmic/scratch/10mu-new +ECN2=${dir}/10muEta-24to-17Pt1to10/${file} +ECN1=${dir}/10muEta-175to-055Pt1to10/${file} +BRL=${dir}/10muEtaLT06Pt1to10/${file} +ECP1=${dir}/10muEta055to175Pt1to10/${file} +ECP2=${dir}/10muEta17to24Pt1to10/${file} -## ECN ## -echo "SNB CMSSW BH (ECN): validation [nTH:24, nVU:8]" -./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${dir}/mu_ecn-1000-10.bin-5 --build-bh --num-thr 24 >& log_SNB_CMSSW_ECN_BH_NVU8int_NTH24_val.txt -mv valtree.root valtree_SNB_CMSSW_ECN_BH.root -echo "SNB CMSSW STD (ECN): validation [nTH:24, nVU:8]" -./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${dir}/mu_ecn-1000-10.bin-5 --build-std --num-thr 24 >& log_SNB_CMSSW_ECN_STD_NVU8int_NTH24_val.txt -mv valtree.root valtree_SNB_CMSSW_ECN_STD.root -echo "SNB CMSSW CE (ECN): validation [nTH:24, nVU:8]" -./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${dir}/mu_ecn-1000-10.bin-5 --build-ce --num-thr 24 >& log_SNB_CMSSW_ECN_CE_NVU8int_NTH24_val.txt -mv valtree.root valtree_SNB_CMSSW_ECN_CE.root +base=SNB_CMSSW_10mu -## BRL ## -echo "SNB CMSSW BH (BRL): validation [nTH:24, nVU:8]" -./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${dir}/mu_brl-1000-10.bin-5 --build-bh --num-thr 24 >& log_SNB_CMSSW_BRL_BH_NVU8int_NTH24_val.txt -mv valtree.root valtree_SNB_CMSSW_BRL_BH.root -echo "SNB CMSSW STD (BRL): validation [nTH:24, nVU:8]" -./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${dir}/mu_brl-1000-10.bin-5 --build-std --num-thr 24 >& log_SNB_CMSSW_BRL_STD_NVU8int_NTH24_val.txt -mv valtree.root valtree_SNB_CMSSW_BRL_STD.root -echo "SNB CMSSW CE (BRL): validation [nTH:24, nVU:8]" -./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${dir}/mu_brl-1000-10.bin-5 --build-ce --num-thr 24 >& log_SNB_CMSSW_BRL_CE_NVU8int_NTH24_val.txt -mv valtree.root valtree_SNB_CMSSW_BRL_CE.root - -## ECP ## -echo "SNB CMSSW BH (ECP): validation [nTH:24, nVU:8]" -./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${dir}/mu_ecp-1000-10.bin-5 --build-bh --num-thr 24 >& log_SNB_CMSSW_ECP_BH_NVU8int_NTH24_val.txt -mv valtree.root valtree_SNB_CMSSW_ECP_BH.root -echo "SNB CMSSW STD (ECP): validation [nTH:24, nVU:8]" -./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${dir}/mu_ecp-1000-10.bin-5 --build-std --num-thr 24 >& log_SNB_CMSSW_ECP_STD_NVU8int_NTH24_val.txt -mv valtree.root valtree_SNB_CMSSW_ECP_STD.root -echo "SNB CMSSW CE (ECP): validation [nTH:24, nVU:8]" -./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${dir}/mu_ecp-1000-10.bin-5 --build-ce --num-thr 24 >& log_SNB_CMSSW_ECP_CE_NVU8int_NTH24_val.txt -mv valtree.root valtree_SNB_CMSSW_ECP_CE.root - -sed -i 's/WITH_ROOT := yes/#WITH_ROOT := yes/g' Makefile.config +for sV in "SimSeed " "CMSSeed --cmssw-seeds" +do echo $sV | while read -r sN sO + do + for section in ECN2 ECN1 BRL ECP1 ECP2 + do + for bV in "BH bh" "STD std" "CE ce" + do echo $bV | while read -r bN bO + do + oBase=${base}_${sN}_${section}_${bN} + echo "${oBase}: validation [nTH:24, nVU:8]" + ./mkFit/mkFit ${sO} --geom CMS-2017 --root-val --read --file-name ${!section} --build-${bO} ${sO} --num-thr 24 >& log_${oBase}_NVU8int_NTH24_val.txt + mv valtree.root valtree_${oBase}.root + done + done + done + done +done make clean -for section in ECN BRL ECP +for seed in SimSeed CMSSeed do - for build in BH STD CE + for section in ECN2 ECN1 BRL ECP1 ECP2 do - root -b -q -l runValidation.C\(\"_SNB_CMSSW_${section}_${build}\"\) + oBase=${base}_${seed}_${section} + for build in BH STD CE + do + root -b -q -l runValidation.C\(\"_${oBase}_${build}\"\) + done + root -b -q -l makeValidation.C\(\"${oBase}\"\) done - root -b -q -l makeValidation.C\(\"SNB_CMSSW_${section}\"\) -done -for build in BH STD CE -do - hadd valtree_SNB_CMSSW_FullDet_${build}.root validation_SNB_CMSSW_ECN_${build}/valtree_SNB_CMSSW_ECN_${build}.root validation_SNB_CMSSW_BRL_${build}/valtree_SNB_CMSSW_BRL_${build}.root validation_SNB_CMSSW_ECP_${build}/valtree_SNB_CMSSW_ECP_${build}.root - - root -b -q -l runValidation.C\(\"_SNB_CMSSW_FullDet_${build}\"\) + for build in BH STD CE + do + oBase=${base}_${seed} + fBase=valtree_${oBase} + dBase=validation_${oBase} + hadd ${fBase}_FullDet_${build}.root `for section in ECN2 ECN1 BRL ECP1 ECP2; do echo -n ${dBase}_${section}_${build}/${fBase}_${section}_${build}.root" "; done` + root -b -q -l runValidation.C\(\"_${oBase}_FullDet_${build}\"\) + done + root -b -q -l makeValidation.C\(\"${oBase}_FullDet\"\) done -root -b -q -l makeValidation.C\(\"SNB_CMSSW_FullDet\"\) - -make distclean \ No newline at end of file +make distclean From f8f01bfe3da568e5b135c1b0d2f74c9488e1a606 Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Thu, 27 Jul 2017 16:38:38 -0700 Subject: [PATCH 114/172] bug fix for counting of unique layers --- Track.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Track.h b/Track.h index ddd39d72428ea..152560b7c946a 100644 --- a/Track.h +++ b/Track.h @@ -312,10 +312,10 @@ class Track { int lyr_cnt = 0; int prev_lyr = -1; - for (int ihit = 0; ihit < lastHitIdx_ ; ++ihit) + for (int ihit = 0; ihit <= lastHitIdx_ ; ++ihit) { int h_lyr = hitsOnTrk_[ihit].layer; - if (h_lyr >= 0 && h_lyr != prev_lyr) + if (h_lyr >= 0 && hitsOnTrk_[ihit].index >= 0 && h_lyr != prev_lyr) { ++lyr_cnt; prev_lyr = h_lyr; From 87a23475e47bee613b6e471a675c449f15ff2599 Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Tue, 1 Aug 2017 09:34:09 +0200 Subject: [PATCH 115/172] updates to non-root-based validation of mkFit --- mkFit/MkBuilder.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index 39b22a5c1a264..f70a99e8a7790 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -853,7 +853,7 @@ void MkBuilder::quality_process(Track &tkcand) { TrackExtra extra(tkcand.label()); - if (Config::useCMSGeom || Config::findSeeds) + if (Config::readCmsswSeeds || Config::findSeeds) { extra.setMCTrackIDInfo(tkcand, m_event->layerHits_, m_event->simHitsInfo_, m_event->simTracks_, false); } @@ -877,8 +877,8 @@ void MkBuilder::quality_process(Track &tkcand) { ptmc = m_event->simTracks_[mctrk].pT() ; pr = pt / ptmc; - // XXXXMT4K Requires Track::nFoundUniqueLayerHits() or Track::nFoundLayers() - nfoundmc = m_event->simTracks_[mctrk].nFoundHits(); + m_event->simTracks_[mctrck].sortHitsByLayer(); + nfoundmc = m_event->simTracks_[mctrk].nUniqueLayers(); chi2mc = m_event->simTracks_[mctrk].chi2();//this is actually the number of reco hits in cmssw ++m_cnt; From d75e2424a453ca303ef8ebf9b4a8dfdba319e8bc Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Wed, 2 Aug 2017 00:48:29 -0700 Subject: [PATCH 116/172] hot fix to compile non-root validation in MkBuilder --- mkFit/MkBuilder.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index f70a99e8a7790..71c61b8876d73 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -877,7 +877,7 @@ void MkBuilder::quality_process(Track &tkcand) { ptmc = m_event->simTracks_[mctrk].pT() ; pr = pt / ptmc; - m_event->simTracks_[mctrck].sortHitsByLayer(); + m_event->simTracks_[mctrk].sortHitsByLayer(); nfoundmc = m_event->simTracks_[mctrk].nUniqueLayers(); chi2mc = m_event->simTracks_[mctrk].chi2();//this is actually the number of reco hits in cmssw From 870f13c7cb16cbfd8d392f6120aed0a2f885d83b Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Thu, 3 Aug 2017 15:38:33 -0700 Subject: [PATCH 117/172] make it relocatable --- validationMIC-build-PU70.sh | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 validationMIC-build-PU70.sh diff --git a/validationMIC-build-PU70.sh b/validationMIC-build-PU70.sh new file mode 100755 index 0000000000000..998082f2672b8 --- /dev/null +++ b/validationMIC-build-PU70.sh @@ -0,0 +1,34 @@ +#! /bin/bash + +make -j 12 WITH_ROOT=yes + +[ -e "$BIN_DATA_PATH" ] || BIN_DATA_PATH=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep +fin=${BIN_DATA_PATH}/PU70/10224.0_TTbar_13+TTbar_13TeV_TuneCUETP8M1_2017PU_GenSimFullINPUT+DigiFullPU_2017PU+RecoFullPU_2017PU+HARVESTFullPU_2017PU/memoryFile.fv3.clean.writeAll.recT.072617.bin + +base=SNB_CMSSW_PU70_clean + +for sV in "sim " "see --cmssw-seeds"; do echo $sV | while read -r sN sO; do + for bV in "BH bh" "STD std" "CE ce"; do echo $bV | while read -r bN bO; do + oBase=${base}_${sN}_${bN} + nTH=8 + echo "${oBase}: validation [nTH:${nTH}, nVU:8]" + ./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${fin} --build-${bO} ${sO} --num-thr ${nTH} >& log_${oBase}_NVU8int_NTH${nTH}_val.txt + mv valtree.root valtree_${oBase}.root + done + done + done +done + +make clean + +for opt in sim see +do + oBase=${base}_${opt} + for build in BH STD CE + do + root -b -q -l runValidation.C+\(\"_${oBase}_${build}\"\) + done + root -b -q -l makeValidation.C+\(\"${oBase}\"\) +done + +make distclean From f1626e8cbd60ab18ba3363cd20c27f5016212a50 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Thu, 3 Aug 2017 15:48:27 -0700 Subject: [PATCH 118/172] add benchmark file to run on a host --- benchmarkMIC-build.sh | 62 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100755 benchmarkMIC-build.sh diff --git a/benchmarkMIC-build.sh b/benchmarkMIC-build.sh new file mode 100755 index 0000000000000..dd123760d0105 --- /dev/null +++ b/benchmarkMIC-build.sh @@ -0,0 +1,62 @@ +#! /bin/bash + +[ -e "$BIN_DATA_PATH" ] || BIN_DATA_PATH=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep +fin=${BIN_DATA_PATH}/PU70/10224.0_TTbar_13+TTbar_13TeV_TuneCUETP8M1_2017PU_GenSimFullINPUT+DigiFullPU_2017PU+RecoFullPU_2017PU+HARVESTFullPU_2017PU/memoryFile.fv3.clean.writeAll.recT.072617.bin + +base=SNB_CMSSW_PU70_clean + +make -j 12 +for sV in "sim " "see --cmssw-seeds"; do echo $sV | while read -r sN sO; do + for bV in "BH bh" "STD std" "CE ce"; do echo $bV | while read -r bN bO; do + oBase=${base}_${sN}_${bN} + for nTH in 1 2 4 8 12 16 24 32; do + echo "${oBase}: benchmark [nTH:${nTH}, nVU:8]" + time ./mkFit/mkFit --geom CMS-2017 --read --file-name ${fin} --build-${bO} ${sO} --num-thr ${nTH} >& log_${oBase}_NVU8int_NTH${nTH}_benchmark.txt + done + done + done + done +done +make clean +make distclean + +make -j 12 CPPUSERFLAGS+="-march=native -mtune=native" CXXUSERFLAGS+="-march=native -mtune=native" +for sV in "sim " "see --cmssw-seeds"; do echo $sV | while read -r sN sO; do + for bV in "BH bh" "STD std" "CE ce"; do echo $bV | while read -r bN bO; do + oBase=${base}_${sN}_${bN} + for nTH in 1 2 4 8 12 16 24 32; do + echo "${oBase}: benchmark native [nTH:${nTH}, nVU:8]" + time ./mkFit/mkFit --geom CMS-2017 --read --file-name ${fin} --build-${bO} ${sO} --num-thr ${nTH} >& log_${oBase}_NVU8int_NTH${nTH}_benchmark_native.txt + done + done + done + done +done +make clean +make distclean + +make -j 12 + +ECN2=${BIN_DATA_PATH}/10muEta-24to-17Pt1to10/memoryFile.fv3.recT.072617.bin +ECN1=${BIN_DATA_PATH}/10muEta-175to-055Pt1to10/memoryFile.fv3.recT.072617.bin +BRL=${BIN_DATA_PATH}/10muEtaLT06Pt1to10/memoryFile.fv3.recT.072617.bin +ECP1=${BIN_DATA_PATH}/10muEta055to175Pt1to10/memoryFile.fv3.recT.072617.bin +ECP2=${BIN_DATA_PATH}/10muEta17to24Pt1to10/memoryFile.fv3.recT.072617.bin +base=SNB_CMSSW_10mu + +for sV in "sim " "see --cmssw-seeds"; do echo $sV | while read -r sN sO; do + for section in ECN2 ECN1 BRL ECP1 ECP2; do + for bV in "BH bh" "STD std" "CE ce"; do echo $bV | while read -r bN bO; do + oBase=${base}_${sN}_${section}_${bN} + nTH=8 + echo "${oBase}: benchmark [nTH:${nTH}, nVU:8]" + time ./mkFit/mkFit --geom CMS-2017 --read --file-name ${!section} --build-${bO} ${sO} --num-thr ${nTH} >& log_${oBase}_NVU8int_NTH${nTH}_benchmark.txt + done + done + done + done +done + + +make clean +make distclean From 9b9c7668622ad68b7c7678a5cae0861c17c372e0 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Thu, 3 Aug 2017 15:49:13 -0700 Subject: [PATCH 119/172] relocatable validationMIC scripts --- ...ild-10mu.sh => validationMIC-build-10mu.sh | 0 validationMICwn37-build-PU70.sh | 33 ------------------- 2 files changed, 33 deletions(-) rename validationMICwn37-build-10mu.sh => validationMIC-build-10mu.sh (100%) delete mode 100755 validationMICwn37-build-PU70.sh diff --git a/validationMICwn37-build-10mu.sh b/validationMIC-build-10mu.sh similarity index 100% rename from validationMICwn37-build-10mu.sh rename to validationMIC-build-10mu.sh diff --git a/validationMICwn37-build-PU70.sh b/validationMICwn37-build-PU70.sh deleted file mode 100755 index 22915bb538c7b..0000000000000 --- a/validationMICwn37-build-PU70.sh +++ /dev/null @@ -1,33 +0,0 @@ -#! /bin/bash - -make -j 12 WITH_ROOT=yes - -fin=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/PU70/10224.0_TTbar_13+TTbar_13TeV_TuneCUETP8M1_2017PU_GenSimFullINPUT+DigiFullPU_2017PU+RecoFullPU_2017PU+HARVESTFullPU_2017PU/memoryFile.fv3.clean.writeAll.recT.072617.bin - -base=SNB_CMSSW_PU70_clean - -for sV in "sim " "see --cmssw-seeds"; do echo $sV | while read -r sN sO; do - for bV in "BH bh" "STD std" "CE ce"; do echo $bV | while read -r bN bO; do - oBase=${base}_${sN}_${bN} - nTH=8 - echo "${oBase}: validation [nTH:${nTH}, nVU:8]" - ./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${fin} --build-${bO} ${sO} --num-thr ${nTH} >& log_${oBase}_NVU8int_NTH${nTH}_val.txt - mv valtree.root valtree_${oBase}.root - done - done - done -done - -make clean - -for opt in sim see -do - oBase=${base}_${opt} - for build in BH STD CE - do - root -b -q -l runValidation.C+\(\"_${oBase}_${build}\"\) - done - root -b -q -l makeValidation.C+\(\"${oBase}\"\) -done - -make distclean From 5f6de6082a7a21180e1ddfd7912792785ad0c0e1 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 3 Aug 2017 16:15:14 -0700 Subject: [PATCH 120/172] Adding option to clean seeds based on direction (dr). By default, dr<0.005 --- Event.cc | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Event.h | 1 + 2 files changed, 75 insertions(+) diff --git a/Event.cc b/Event.cc index 54605f7dfd3f4..91ef15fa9b648 100644 --- a/Event.cc +++ b/Event.cc @@ -451,6 +451,7 @@ void Event::write_out(DataFile &data_file) // #define DUMP_TRACKS // #define DUMP_TRACK_HITS // #define DUMP_LAYER_HITS +// #define CLEAN_SEEDS void Event::read_in(DataFile &data_file, FILE *in_fp) { @@ -506,6 +507,11 @@ void Event::read_in(DataFile &data_file, FILE *in_fp) fseek(fp, ns * data_file.f_header.f_sizeof_track, SEEK_CUR); ns = -ns; } +#ifdef CLEAN_SEEDS + TrackVec mySeedTracks = clean_cms_seedtracks(); + seedTracks_ = mySeedTracks; + ns = seedTracks_.size(); +#endif #ifdef DUMP_SEEDS printf("Read %i seedtracks (neg value means actual reading was skipped)\n", ns); for (int it = 0; it < ns; it++) @@ -673,6 +679,73 @@ void Event::print_tracks(const TrackVec& tracks, bool print_hits) const } } +TrackVec Event::clean_cms_seedtracks(double maxDR, int minNHits) +{ + + int ns = seedTracks_.size(); + + TrackVec cleanSeedTracks; + std::vector writetrack; + for(int ts=0; ts pos_first ) + thisDXY*=-1; + + double oldPhi1 = track_first.momPhi(); + double oldPhi2 = track_second.monPhi(); + + double newPhi1 = oldPhi1-thisDXY/87.6/track_first.pT()*track_first.charge(); + double newPhi2 = oldPhi2+thisDXY/87.6/track_second.pT()*track_second.charge(); + + double Eta1 = track_first.momEta(); + double Eta2 = track_second.monEta(); + + double deta = fabs(Eta1-Eta2); + + double dphi = newPhi1-newPhi2; + if(dphi>=Config::PI) dphi-=Config::TwoPI; + else if(dphi<-Config::PI) dphi+=Config::TwoPI; + + double dr = sqrt(deta*deta+dphi*dphi); + + if (dr < maxDR) + writetrack[tss]=false; + + } + + + if(writetrack[ts]==true) + cleanSeedTracks.push_back(seedTracks_[ts]); + + } + +#ifdef DEBUG + printf("Number of seeds: %d --> %d\n", ns, cleanSeedTracks.size()); +#endif + + return cleanSeedTracks; + +} + //============================================================================== // DataFile @@ -793,3 +866,4 @@ void DataFile::CloseWrite(int n_written){ } Close(); } + diff --git a/Event.h b/Event.h index 603f31790a572..c57179d4a0ff9 100644 --- a/Event.h +++ b/Event.h @@ -36,6 +36,7 @@ class Event void read_in (DataFile &data_file, FILE *in_fp=0); int clean_cms_simtracks(); + TrackVec clean_cms_seedtracks(double maxDR=0.005, int minNHits=4); void print_tracks(const TrackVec& tracks, bool print_hits) const; const Geometry& geom_; From c1bb15ba874f5277304f6f001a261ea4b5b57e0d Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 3 Aug 2017 16:21:14 -0700 Subject: [PATCH 121/172] Fix typo --- Event.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Event.cc b/Event.cc index 91ef15fa9b648..0369b8158040d 100644 --- a/Event.cc +++ b/Event.cc @@ -711,13 +711,13 @@ TrackVec Event::clean_cms_seedtracks(double maxDR, int minNHits) thisDXY*=-1; double oldPhi1 = track_first.momPhi(); - double oldPhi2 = track_second.monPhi(); + double oldPhi2 = track_second.momPhi(); double newPhi1 = oldPhi1-thisDXY/87.6/track_first.pT()*track_first.charge(); double newPhi2 = oldPhi2+thisDXY/87.6/track_second.pT()*track_second.charge(); double Eta1 = track_first.momEta(); - double Eta2 = track_second.monEta(); + double Eta2 = track_second.momEta(); double deta = fabs(Eta1-Eta2); From bf6d84adb0ef88b7104153feaa544cb0e7f554b4 Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Fri, 28 Jul 2017 10:43:26 -0700 Subject: [PATCH 122/172] Initial commit for CMSSW RecTrack Validation: * Add command line options to run special validation, with a variety of configs * initial function structure for track matching, including hit matching * add a small data structure to Track.h for ease of use in track matching * add generalized switm to phi, chi2 functions to track class * add prep functions for external rec tracks --- Config.cc | 6 ++- Config.h | 5 ++ Event.cc | 10 +++- Hit.h | 5 ++ Matrix.h | 9 ++++ TTreeValidation.cc | 117 ++++++++++++++++++++++++++++++++-------- TTreeValidation.h | 11 ++++ Track.cc | 62 +++++++++++++++++++++ Track.h | 57 ++++++++++++++++---- Validation.cc | 2 +- Validation.h | 3 ++ mkFit/MkBuilder.cc | 23 ++++++++ mkFit/MkBuilder.h | 5 +- mkFit/buildtestMPlex.cc | 24 ++++++--- mkFit/mkFit.cc | 16 +++++- 15 files changed, 309 insertions(+), 46 deletions(-) diff --git a/Config.cc b/Config.cc index 11e8add030308..092b5fd7d1a86 100644 --- a/Config.cc +++ b/Config.cc @@ -57,9 +57,11 @@ namespace Config bool cf_seeding = false; bool cf_fitting = false; - bool root_val = false; - bool fit_val = false; + bool root_val = false; + bool cmssw_val = false; + bool fit_val = false; bool inclusiveShorts = false; + bool applyCMSSWHitMatch = false; void RecalculateDependentConstants() { diff --git a/Config.h b/Config.h index 49eab5d9d9b73..a498c3bb9b554 100644 --- a/Config.h +++ b/Config.h @@ -232,9 +232,14 @@ namespace Config // config on validation constexpr float nMinSimHitsFrac = 0.7; constexpr int nMinFoundHits = 7; + constexpr float minCMSSWMatchChi2 = 50; + constexpr float minCMSSWMatchdPhi = 0.03; + constexpr int nCMSSWMatchHits = 7; extern bool root_val; + extern bool cmssw_val; extern bool fit_val; extern bool inclusiveShorts; + extern bool applyCMSSWHitMatch; // Threading extern int numThreadsFinder; diff --git a/Event.cc b/Event.cc index 54605f7dfd3f4..aecffeadfa879 100644 --- a/Event.cc +++ b/Event.cc @@ -329,7 +329,7 @@ void Event::Fit() void Event::Validate() { - // KM: Config tree just filled once... in main.cc + // standard eff/fr/dr validation if (Config::root_val) { validation_.setTrackExtras(*this); validation_.makeSimTkToRecoTksMaps(*this); @@ -338,6 +338,14 @@ void Event::Validate() validation_.fillFakeRateTree(*this); } + // special cmssw to mkfit validation + if (Config::cmssw_val) { + validation_.setTrackExtras(*this); + validation_.makeCMSSWTkToRecoTksMap(*this); + validation_.fillCMSSWEfficiencyTree(*this); + validation_.fillCMSSWFakeRateTree(*this); + } + if (Config::fit_val) { // fit val for z-phi tuning validation_.fillFitTree(*this); } diff --git a/Hit.h b/Hit.h index 95593fac93e34..944a4edd32d5d 100644 --- a/Hit.h +++ b/Hit.h @@ -11,6 +11,11 @@ template inline T sqr(T x) { return x*x; } template inline T cube(T x) { return x*x*x; } +inline float squashPhiGeneral(float phi) +{ + return phi - floor(0.5f*Config::InvPI*(phi+Config::PI)) * Config::TwoPI; +} + // moved from config to here inline int getEtaBin(float eta) { diff --git a/Matrix.h b/Matrix.h index 80db7558dd0cb..15ab60803aa45 100644 --- a/Matrix.h +++ b/Matrix.h @@ -34,6 +34,15 @@ void dumpMatrix(Matrix m) } } +template +inline void diagonalOnly(Matrix& m) +{ + for (int r=0; rBranch("thetaerr012",&thetaerr012_); } +void TTreeValidation::initializeCMSSWEfficiencyTree() +{ + // cmssw reco track efficiency validation + cmsswefftree_ = new TTree("cmsswefftree","cmsswefftree"); +} + +void TTreeValidation::initializeCMSSWFakeRateTree() +{ + // cmssw reco track efficiency validation + cmsswfrtree_ = new TTree("cmsswfrtree","cmsswfrtree"); +} + void TTreeValidation::initializeFitTree() { ntotallayers_fit_ = Config::nTotalLayers; @@ -431,30 +453,66 @@ void TTreeValidation::setTrackExtras(Event& ev) { std::lock_guard locker(glock_); - // set mcTrackID for seed tracks - for (int itrack = 0; itrack < ev.seedTracks_.size(); itrack++) + if (Config::root_val) { - auto&& track(ev.seedTracks_[itrack]); - auto&& extra(ev.seedTracksExtra_[itrack]); - extra.setMCTrackIDInfo(track, ev.layerHits_, ev.simHitsInfo_, ev.simTracks_, true); // otherwise seeds are completely unmatched in ToyMC Sim Seeds + // set mcTrackID for seed tracks + for (int itrack = 0; itrack < ev.seedTracks_.size(); itrack++) + { + auto&& track(ev.seedTracks_[itrack]); + auto&& extra(ev.seedTracksExtra_[itrack]); + extra.setMCTrackIDInfo(track, ev.layerHits_, ev.simHitsInfo_, ev.simTracks_, true); // otherwise seeds are completely unmatched in ToyMC Sim Seeds + } + + // set mcTrackID for built tracks + for (int itrack = 0; itrack < ev.candidateTracks_.size(); itrack++) + { + auto&& track(ev.candidateTracks_[itrack]); + auto&& extra(ev.candidateTracksExtra_[itrack]); + if (Config::readCmsswSeeds || Config::findSeeds) {extra.setMCTrackIDInfo(track, ev.layerHits_, ev.simHitsInfo_, ev.simTracks_, false);} + else {extra.setMCTrackIDInfoByLabel(track, ev.layerHits_, ev.simHitsInfo_);} + } + + // set mcTrackID for fit tracks + for (int itrack = 0; itrack < ev.fitTracks_.size(); itrack++) + { + auto&& track(ev.fitTracks_[itrack]); + auto&& extra(ev.fitTracksExtra_[itrack]); + if (Config::readCmsswSeeds || Config::findSeeds) {extra.setMCTrackIDInfo(track, ev.layerHits_, ev.simHitsInfo_, ev.simTracks_, false);} + else {extra.setMCTrackIDInfoByLabel(track, ev.layerHits_, ev.simHitsInfo_);} + } } - // set mcTrackID for built tracks - for (int itrack = 0; itrack < ev.candidateTracks_.size(); itrack++) - { - auto&& track(ev.candidateTracks_[itrack]); - auto&& extra(ev.candidateTracksExtra_[itrack]); - if (Config::readCmsswSeeds || Config::findSeeds) {extra.setMCTrackIDInfo(track, ev.layerHits_, ev.simHitsInfo_, ev.simTracks_, false);} - else {extra.setMCTrackIDInfoByLabel(track, ev.layerHits_, ev.simHitsInfo_);} - } - - // set mcTrackID for fit tracks - for (int itrack = 0; itrack < ev.fitTracks_.size(); itrack++) - { - auto&& track(ev.fitTracks_[itrack]); - auto&& extra(ev.fitTracksExtra_[itrack]); - if (Config::readCmsswSeeds || Config::findSeeds) {extra.setMCTrackIDInfo(track, ev.layerHits_, ev.simHitsInfo_, ev.simTracks_, false);} - else {extra.setMCTrackIDInfoByLabel(track, ev.layerHits_, ev.simHitsInfo_);} + if (Config::cmssw_val) + { + RedTrackVec reducedCMSSW(ev.extRecTracks_.size()); // use 2D chi2 for now, so might as well make use of this object for now + for (int itrack = 0; itrack < ev.extRecTracks_.size(); itrack++) + { + const auto & cmsswtrack = ev.extRecTracks_[itrack]; + const SVector6 & params = cmsswtrack.parameters(); + SVector2 tmpv; + tmpv[0] = params[3]; + tmpv[1] = params[5]; + + HitLayerMap tmpmap; + for (int ihit = 0; ihit < cmsswtrack.nTotalHits(); ihit++) + { + const int lyr = cmsswtrack.getHitLyr(ihit); + const int idx = cmsswtrack.getHitIdx(ihit); + + if (idx >= 0) tmpmap[lyr].push_back(idx); + } + + // index inside object is label (as cmsswtracks are now aligned) + reducedCMSSW[itrack] = ReducedTrack(cmsswtrack.label(),tmpv,cmsswtrack.momPhi(),tmpmap); + } + + // set cmsswTrackID for built tracks + for (int itrack = 0; itrack < ev.candidateTracks_.size(); itrack++) + { + auto&& track(ev.candidateTracks_[itrack]); + auto&& extra(ev.candidateTracksExtra_[itrack]); + extra.setCMSSWTrackIDInfo(track, ev.layerHits_, ev.extRecTracks_,reducedCMSSW); + } } } @@ -528,6 +586,15 @@ void TTreeValidation::mapSeedTkToRecoTk(const TrackVec& evt_tracks, const TrackE } } +void TTreeValidation::makeCMSSWTkToRecoTksMap(Event& ev) +{ + int nmatched = 0; + for (auto&& trk : ev.candidateTracks_) + if (ev.candidateTracksExtra_[trk.label()].cmsswTrackID() != -1) nmatched++; + + std::cout << "Matched: " << nmatched << " / " << ev.candidateTracks_.size() << std::endl; +} + int TTreeValidation::getLastFoundHit(const int trackMCHitID, const int mcTrackID, const Event& ev) { int mcHitID = -1; @@ -1354,6 +1421,14 @@ void TTreeValidation::fillConfigTree() configtree_->Fill(); } +void TTreeValidation::fillCMSSWEfficiencyTree(const Event& ev) +{ +} + +void TTreeValidation::fillCMSSWFakeRateTree(const Event& ev) +{ +} + void TTreeValidation::saveTTrees() { std::lock_guard locker(glock_); diff --git a/TTreeValidation.h b/TTreeValidation.h index 3144c09211e0d..3bfdc14ee7fd3 100644 --- a/TTreeValidation.h +++ b/TTreeValidation.h @@ -28,6 +28,8 @@ class TTreeValidation : public Validation { void initializeEfficiencyTree(); void initializeFakeRateTree(); void initializeConfigTree(); + void initializeCMSSWEfficiencyTree(); + void initializeCMSSWFakeRateTree(); void initializeFitTree(); void alignTracks(TrackVec& evt_tracks, TrackExtraVec& evt_extra, bool alignExtra) override; @@ -43,12 +45,15 @@ class TTreeValidation : public Validation { void mapSimTkToRecoTks(const TrackVec& evt_tracks, TrackExtraVec& evt_extras, TkIDToTkIDVecMap& simTkMap); void makeSeedTkToRecoTkMaps(Event& ev) override; void mapSeedTkToRecoTk(const TrackVec& evt_tracks, const TrackExtraVec& evt_extras, TkIDToTkIDMap& seedTkMap); + void makeCMSSWTkToRecoTksMap(Event& ev) override; int getLastFoundHit(const int trackMCHitID, const int mcTrackID, const Event& ev); void fillEfficiencyTree(const Event& ev) override; void fillFakeRateTree(const Event& ev) override; void fillConfigTree() override; + void fillCMSSWEfficiencyTree(const Event& ev) override; + void fillCMSSWFakeRateTree(const Event& ev) override; void fillFitTree(const Event& ev) override; void saveTTrees() override; @@ -157,6 +162,12 @@ class TTreeValidation : public Validation { int nTotHit_=0; float ptinverr049_=0.,phierr049_=0.,thetaerr049_=0.,ptinverr012_=0.,phierr012_=0.,thetaerr012_=0.; + // CMSSW Efficiency tree + TTree* cmsswefftree_; + + // CMSSW FakeRate tree + TTree* cmsswfrtree_; + // Fit tree (for fine tuning z-phi windows and such --> MPlex Only TTree* fittree_; int ntotallayers_fit_=0,tkid_fit_=0,evtid_fit_=0; diff --git a/Track.cc b/Track.cc index 4a00cfe3599a8..ffa4f52ba5c4f 100644 --- a/Track.cc +++ b/Track.cc @@ -82,6 +82,13 @@ void Track::sortHitsByLayer() [&](HitOnTrack h1, HitOnTrack h2) { return h1.layer < h2.layer; }); } +float Track::swimPhiToR(const float x0, const float y0) const +{ + const float dR = getHypot(x()-x0,y()-y0); + const float dPhi = 2.f*std::asin(dR/176.f/pT()*charge()); + return squashPhiGeneral(momPhi()-dPhi); +} + //============================================================================== // TrackExtra //============================================================================== @@ -225,6 +232,61 @@ void TrackExtra::setMCTrackIDInfo(const Track& trk, const std::vector& l dprint("Track " << trk.label() << " best mc track " << mcTrackID_ << " count " << mccount << "/" << trk.nFoundHits()); } +void TrackExtra::setCMSSWTrackIDInfo(const Track& trk, const std::vector& layerHits, const TrackVec& cmsswtracks, const RedTrackVec& redcmsswtracks) +{ + const SVector6 & trkParams = trk.parameters(); + const SMatrixSym66 & trkErrs = trk.errors(); + + // temps needed for chi2 + SVector2 trkParamsR; + trkParamsR[0] = trkParams[3]; + trkParamsR[1] = trkParams[5]; + + SMatrixSym22 trkErrsR; + trkErrsR[0][0] = trkErrs[3][3]; + trkErrsR[1][1] = trkErrs[5][5]; + trkErrsR[0][1] = trkErrs[3][5]; + trkErrsR[1][0] = trkErrs[5][3]; + + std::vector cands; + for (auto&& redcmsswtrack : redcmsswtracks) + { + const float chi2 = computeHelixChi2(redcmsswtrack.parameters(),trkParamsR,trkErrsR,false); + if (chi2 < Config::minCMSSWMatchChi2) cands.push_back(redcmsswtrack.label()); + } + + int best = -1; + float bestdPhi = Config::minCMSSWMatchdPhi; + for (auto cand : cands) // loop over possible cmssw tracks + { + const auto & cmsswtrack = cmsswtracks[cand]; + const float diffPhi = std::abs(squashPhiGeneral(cmsswtrack.swimPhiToR(trk.x(),trk.y())-trk.momPhi())); + if (diffPhi < bestdPhi) // check for best matched track by phi + { + if (Config::applyCMSSWHitMatch) // check for nMatchedHits if applied + { + const HitLayerMap & hitLayerMap = redcmsswtracks[cand].hitLayerMap(); + int matched = 0; + for (int ihit = Config::nlayers_per_seed; ihit < trk.nTotalHits(); ihit++) // loop over mkfit track hits + { + const int lyr = trk.getHitLyr(ihit); + const int idx = trk.getHitIdx(ihit); + + if (idx < 0 || !hitLayerMap.count(lyr)) continue; // skip if bad index or cmssw track does not have that layer + for (auto cidx : hitLayerMap.at(lyr)) // loop over hits in layer for the cmssw track + { + if (cidx == idx) {matched++; break;} + } + } + if (matched < Config::nCMSSWMatchHits) continue; + } + bestdPhi = diffPhi; best = cand; + } + } + + cmsswTrackID_ = best; +} + //============================================================================== void print(const TrackState& s) diff --git a/Track.h b/Track.h index 152560b7c946a..763857738edcd 100644 --- a/Track.h +++ b/Track.h @@ -6,9 +6,11 @@ #include "Config.h" #include +#include typedef std::pair SimTkIDInfo; typedef std::vector HitIdxVec; +typedef std::map > HitLayerMap; inline int calculateCharge(const Hit & hit0, const Hit & hit1, const Hit & hit2){ return ((hit2.y()-hit0.y())*(hit2.x()-hit1.x())>(hit2.y()-hit1.y())*(hit2.x()-hit0.x())?1:-1); @@ -20,6 +22,26 @@ inline int calculateCharge(const float hit0_x, const float hit0_y, return ((hit2_y-hit0_y)*(hit2_x-hit1_x)>(hit2_y-hit1_y)*(hit2_x-hit0_x)?1:-1); } +struct ReducedTrack // used for cmssw reco track validation +{ +public: + ReducedTrack() {} + ReducedTrack(const int label, const SVector2 & params, const float phi, const HitLayerMap & hitmap) : + label_(label), parameters_(params), phi_(phi), hitLayerMap_(hitmap) {} + ~ReducedTrack() {} + + int label() const {return label_;} + const SVector2& parameters() const {return parameters_;} + float momPhi() const {return phi_;} + const HitLayerMap& hitLayerMap() const {return hitLayerMap_;} + + int label_; + SVector2 parameters_; + float phi_; + HitLayerMap hitLayerMap_; +}; +typedef std::vector RedTrackVec; + struct TrackState // possible to add same accessors as track? { public: @@ -179,6 +201,9 @@ class Track float epT() const { return state_.epT();} float emomPhi() const { return state_.emomPhi();} float emomEta() const { return state_.emomEta();} + + // used for swimming cmssw rec tracks to mkFit position + float swimPhiToR(const float x, const float y) const; //this function is very inefficient, use only for debug and validation! const HitVec hitsVector(const std::vector& globalHitVec) const @@ -413,21 +438,26 @@ inline bool sortByHitsChi2(const Track & cand1, const Track & cand2) return cand1.nFoundHits()>cand2.nFoundHits(); } -template -inline void squashPhiGeneral(V& params) +template +inline void squashPhiGeneral(Vector& v) { - const int i = params.kSize-2; // phi index - params[i] -= floor(0.5f*Config::InvPI*(params[i]+Config::PI)) * Config::TwoPI; + const int i = v.kSize-2; // phi index + v[i] = squashPhiGeneral(v[i]); } -template -inline float computeHelixChi2(const V& simParams, const V& recoParams, const M& recoErrs) +//https://github.com/cms-sw/cmssw/blob/09c3fce6626f70fd04223e7dacebf0b485f73f54/SimTracker/TrackAssociatorProducers/plugins/getChi2.cc#L23 +template +float computeHelixChi2(const Vector& simV, const Vector& recoV, const Matrix& recoM, const bool diagOnly = false) { + Vector diffV = recoV - simV; + if (diffV.kSize > 2) squashPhiGeneral(diffV); + + Matrix recoM_tmp = recoM; + if (diagOnly) diagonalOnly(recoM_tmp); int invFail(0); - const M recoErrsI = recoErrs.InverseFast(invFail); - V diffParams = recoParams - simParams; - squashPhiGeneral(diffParams); - return ROOT::Math::Dot(diffParams*recoErrsI,diffParams) / (diffParams.kSize - 1); + const Matrix recoMI = recoM_tmp.InverseFast(invFail); + + return ROOT::Math::Dot(diffV*recoMI,diffV)/(diffV.kSize-1); } class TrackExtra @@ -438,14 +468,18 @@ class TrackExtra void setMCTrackIDInfoByLabel(const Track& trk, const std::vector& layerHits, const MCHitInfoVec& globalHitInfo); void setMCTrackIDInfo(const Track& trk, const std::vector& layerHits, const MCHitInfoVec& globalHitInfo, const TrackVec& simtracks, const bool isSeed); + void setCMSSWTrackIDInfo(const Track& trk, const std::vector& layerHits, const TrackVec& cmsswtracks, const RedTrackVec& redcmsswtracks); int mcTrackID() const {return mcTrackID_;} int nHitsMatched() const {return nHitsMatched_;} float fracHitsMatched() const {return fracHitsMatched_;} + int nLayersMatched() const {return nLayersMatched_;} + float fracLayersMatched() const {return fracLayersMatched_;} int seedID() const {return seedID_;} bool isDuplicate() const {return isDuplicate_;} int duplicateID() const {return duplicateID_;} void setMCDuplicateInfo(int duplicateID, bool isDuplicate) {duplicateID_ = duplicateID; isDuplicate_ = isDuplicate;} + int cmsswTrackID() const {return cmsswTrackID_;} private: friend class Track; @@ -453,9 +487,12 @@ class TrackExtra int mcTrackID_; int nHitsMatched_; float fracHitsMatched_; + int nLayersMatched_; + float fracLayersMatched_; int seedID_; int duplicateID_; bool isDuplicate_; + int cmsswTrackID_; }; typedef std::vector TrackExtraVec; diff --git a/Validation.cc b/Validation.cc index b34a5437ae7ec..cf519f62a1500 100644 --- a/Validation.cc +++ b/Validation.cc @@ -3,7 +3,7 @@ Validation* Validation::make_validation(const std::string& fileName) { #ifndef NO_ROOT - if (Config::root_val || Config::fit_val) { + if (Config::root_val || Config::fit_val || Config::cmssw_val) { return new TTreeValidation(fileName); } #endif diff --git a/Validation.h b/Validation.h index d1ee627d9d9a3..c909d988d7e54 100644 --- a/Validation.h +++ b/Validation.h @@ -33,10 +33,13 @@ class Validation { virtual void setTrackExtras(Event& ev) {} virtual void makeSimTkToRecoTksMaps(Event&) {} virtual void makeSeedTkToRecoTkMaps(Event&) {} + virtual void makeCMSSWTkToRecoTksMap(Event&) {} virtual void fillEfficiencyTree(const Event&) {} virtual void fillFakeRateTree(const Event&) {} virtual void fillConfigTree() {} + virtual void fillCMSSWEfficiencyTree(const Event&) {} + virtual void fillCMSSWFakeRateTree(const Event&) {} virtual void fillFitTree(const Event&) {} virtual void saveTTrees() {} diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index 71c61b8876d73..cd578af3b8d15 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -943,6 +943,18 @@ void MkBuilder::root_val_COMB() m_event->Validate(); } +void MkBuilder::cmssw_val_BH() +{ + prep_cmsswtracks(); + root_val_BH(); +} + +void MkBuilder::cmssw_val_COMB() +{ + prep_cmsswtracks(); + root_val_COMB(); +} + void MkBuilder::init_track_extras() { for (int i = 0; i < m_event->seedTracks_.size(); i++) @@ -968,6 +980,17 @@ void MkBuilder::align_recotracks() m_event->validation_.alignTracks(m_event->fitTracks_,m_event->fitTracksExtra_,false); } +void MkBuilder::prep_cmsswtracks() +{ + for (int i = 0; i < m_event->extRecTracks_.size(); i++) + { + m_event->extRecTracks_[i].sortHitsByLayer(); + m_event->extRecTracksExtra_.emplace_back(m_event->extRecTracks_[i].label()); + } + + m_event->validation_.alignTracks(m_event->extRecTracks_,m_event->extRecTracksExtra_,false); +} + //------------------------------------------------------------------------------ // PrepareSeeds //------------------------------------------------------------------------------ diff --git a/mkFit/MkBuilder.h b/mkFit/MkBuilder.h index e7ae302b150b6..39c30fe4c0632 100644 --- a/mkFit/MkBuilder.h +++ b/mkFit/MkBuilder.h @@ -80,7 +80,6 @@ class MkBuilder void map_seed_hits(); // m_event->layerHits_ -> m_event_of_hits.m_layers_of_hits (seeds only) void remap_seed_hits(); // m_event_of_hits.m_layers_of_hits -> m_event->layerHits_ (seeds only) void remap_cand_hits(); // m_event_of_hits.m_layers_of_hits -> m_event->layerHits_ (cands only) - void align_recotracks(); // ensure that all track collections have labels equal to index inside vector void quality_output_BH(); void quality_output_COMB(); @@ -92,7 +91,11 @@ class MkBuilder void root_val_BH(); void root_val_COMB(); + void cmssw_val_BH(); + void cmssw_val_COMB(); void init_track_extras(); + void align_recotracks(); // ensure that all track collections have labels equal to index inside vector + void prep_cmsswtracks(); // ensure that cmssw rec tracks have the right labels and extras are good // -------- diff --git a/mkFit/buildtestMPlex.cc b/mkFit/buildtestMPlex.cc index d93f1aeb14b72..be7cdabe71ca4 100644 --- a/mkFit/buildtestMPlex.cc +++ b/mkFit/buildtestMPlex.cc @@ -109,10 +109,12 @@ double runBuildingTestPlexBestHit(Event& ev, MkBuilder& builder) __SSC_MARK(0x222); // use this to pause Intel SDE at the same point #endif - if (!Config::root_val) { + if (!Config::root_val && !Config::cmssw_val) { if (!Config::silent) builder.quality_output_BH(); - } else { + } else if (Config::root_val) { builder.root_val_BH(); + } else if (Config::cmssw_val) { + builder.cmssw_val_BH(); } builder.end_event(); @@ -148,9 +150,13 @@ double runBuildingTestPlexStandard(Event& ev, MkBuilder& builder) __SSC_MARK(0x222); // use this to pause Intel SDE at the same point #endif - if (!Config::root_val) { + if (!Config::root_val && !Config::cmssw_val) { if (!Config::silent) builder.quality_output_COMB(); - } else {builder.root_val_COMB();} + } else if (Config::root_val) { + builder.root_val_COMB(); + } else if (Config::cmssw_val) { + builder.cmssw_val_COMB(); + } builder.end_event(); @@ -185,10 +191,12 @@ double runBuildingTestPlexCloneEngine(Event& ev, MkBuilder& builder) __SSC_MARK(0x222); // use this to pause Intel SDE at the same point #endif - if (!Config::root_val) { + if (!Config::root_val && !Config::cmssw_val) { if (!Config::silent) builder.quality_output_COMB(); - } else { + } else if (Config::root_val) { builder.root_val_COMB(); + } else if (Config::cmssw_val) { + builder.cmssw_val_COMB(); } builder.end_event(); @@ -248,9 +256,9 @@ double runAllBuildingTestPlexBestHitGPU(std::vector &events) EventOfCandidates &event_of_cands = event_of_cands_vec[i]; BuilderCU &builder_cu = builder_cu_vec[i]; MkBuilder &builder = * builder_ptrs[i].get(); - if (!Config::root_val) { + if (!Config::root_val && !Config::cmssw_val) { if (!Config::silent) builder.quality_output_BH(event_of_cands); - } else { + } else if (Config::root_val) { builder.root_val_BH(event_of_cands); } diff --git a/mkFit/mkFit.cc b/mkFit/mkFit.cc index df5554b9dd8d7..81106ef03ae6a 100644 --- a/mkFit/mkFit.cc +++ b/mkFit/mkFit.cc @@ -503,8 +503,10 @@ int main(int argc, const char *argv[]) " --cf-seeding enable CF in seeding (def: %s)\n" " --cf-fitting enable CF in fitting (def: %s)\n" " --root-val enable ROOT based validation for building [eff, FR, DR] (def: %s)\n" + " --cmssw-val enable special CMSSW ROOT based validation for building [eff] (def: %s)\n" " --fit-val enable ROOT based validation for fitting (def: %s)\n" " --inc-shorts include short reco tracks into FR (def: %s)\n" + " --hit-match apply hit matching criteria for CMSSW reco track matching (def: %s)\n" " --silent suppress printouts inside event loop (def: %s)\n" " --write write simulation to file and exit\n" " --read read simulation from file\n" @@ -530,8 +532,10 @@ int main(int argc, const char *argv[]) b2a(Config::cf_seeding), b2a(Config::cf_fitting), b2a(Config::root_val), + b2a(Config::cmssw_val), b2a(Config::fit_val), b2a(Config::inclusiveShorts), + b2a(Config::applyCMSSWHitMatch), b2a(Config::silent), g_start_event, g_file_name.c_str(), @@ -632,16 +636,24 @@ int main(int argc, const char *argv[]) } else if (*i == "--root-val") { - Config::root_val = true; Config::fit_val = false; + Config::root_val = true; Config::cmssw_val = false; Config::fit_val = false; + } + else if (*i == "--cmssw-val") + { + Config::root_val = false; Config::cmssw_val = true; Config::fit_val = false; } else if (*i == "--fit-val") { - Config::root_val = false; Config::fit_val = true; + Config::root_val = false; Config::cmssw_val = false; Config::fit_val = true; } else if (*i == "--inc-shorts") { Config::inclusiveShorts = true; } + else if (*i == "--hit-match") + { + Config::applyCMSSWHitMatch = true; + } else if (*i == "--num-thr-ev") { next_arg_or_die(mArgs, i); From 30ec7554117b398ec1235a388b871789062d6170 Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Thu, 3 Aug 2017 16:30:09 -0700 Subject: [PATCH 123/172] mass search+replaced of fakeratetree to frtree in standard root_val --- PlotValidation.cpp | 30 ++++---- TTreeValidation.cc | 186 ++++++++++++++++++++++----------------------- TTreeValidation.h | 2 +- 3 files changed, 109 insertions(+), 109 deletions(-) diff --git a/PlotValidation.cpp b/PlotValidation.cpp index aa7b0a78cb6a1..2496113fef8f4 100644 --- a/PlotValidation.cpp +++ b/PlotValidation.cpp @@ -277,7 +277,7 @@ void PlotValidation::PlotInefficiencyVsGeom() void PlotValidation::PlotFakeRate() { // Get tree - TTree * fakeratetree = (TTree*)fInRoot->Get("fakeratetree"); + TTree * frtree = (TTree*)fInRoot->Get("frtree"); // make output subdirectory and subdir in ROOT file, and cd to it. TString subdirname = "fakerate"; @@ -331,7 +331,7 @@ void PlotValidation::PlotFakeRate() recovars_val[i][j] = 0.; //Set var+trk branch - fakeratetree->SetBranchAddress(Form("%s_%s",vars[i].Data(),trks[j].Data()),&(recovars_val[i][j])); + frtree->SetBranchAddress(Form("%s_%s",vars[i].Data(),trks[j].Data()),&(recovars_val[i][j])); } } @@ -339,13 +339,13 @@ void PlotValidation::PlotFakeRate() for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index { mcmask_trk[j] = 0; - fakeratetree->SetBranchAddress(Form("mcmask_%s",trks[j].Data()),&(mcmask_trk[j])); + frtree->SetBranchAddress(Form("mcmask_%s",trks[j].Data()),&(mcmask_trk[j])); } // Fill histos, compute fake rate from tree branches - for (Int_t k = 0; k < fakeratetree->GetEntries(); k++) + for (Int_t k = 0; k < frtree->GetEntries(); k++) { - fakeratetree->GetEntry(k); + frtree->GetEntry(k); for (UInt_t i = 0; i < vars.size(); i++) // loop over vars index { for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index @@ -367,7 +367,7 @@ void PlotValidation::PlotFakeRate() delete varsFR[i][j]; } } - delete fakeratetree; + delete frtree; } void PlotValidation::PlotDuplicateRate() @@ -471,7 +471,7 @@ void PlotValidation::PlotDuplicateRate() void PlotValidation::PlotNHits() { // Get tree --> can do this all with fake rate tree - TTree * fakeratetree = (TTree*)fInRoot->Get("fakeratetree"); + TTree * frtree = (TTree*)fInRoot->Get("frtree"); // make output subdirectory and subdir in ROOT file, and cd to it. TString subdirname = "nHits"; @@ -531,17 +531,17 @@ void PlotValidation::PlotNHits() nHits_trk[j] = 0; fracHitsMatched_trk[j] = 0; - fakeratetree->SetBranchAddress(Form("mcmask_%s",trks[j].Data()),&(mcmask_trk[j])); - fakeratetree->SetBranchAddress(Form("seedmask_%s",trks[j].Data()),&(seedmask_trk[j])); - fakeratetree->SetBranchAddress(Form("iTkMatches_%s",trks[j].Data()),&(iTkMatches_trk[j])); - fakeratetree->SetBranchAddress(Form("nHits_%s",trks[j].Data()),&(nHits_trk[j])); - fakeratetree->SetBranchAddress(Form("fracHitsMatched_%s",trks[j].Data()),&(fracHitsMatched_trk[j])); + frtree->SetBranchAddress(Form("mcmask_%s",trks[j].Data()),&(mcmask_trk[j])); + frtree->SetBranchAddress(Form("seedmask_%s",trks[j].Data()),&(seedmask_trk[j])); + frtree->SetBranchAddress(Form("iTkMatches_%s",trks[j].Data()),&(iTkMatches_trk[j])); + frtree->SetBranchAddress(Form("nHits_%s",trks[j].Data()),&(nHits_trk[j])); + frtree->SetBranchAddress(Form("fracHitsMatched_%s",trks[j].Data()),&(fracHitsMatched_trk[j])); } // Fill histos, compute res/pull from tree branches - for (Int_t k = 0; k < fakeratetree->GetEntries(); k++) + for (Int_t k = 0; k < frtree->GetEntries(); k++) { - fakeratetree->GetEntry(k); + frtree->GetEntry(k); for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index { for (UInt_t c = 0; c < coll.size(); c++) // loop over trk collection type @@ -595,7 +595,7 @@ void PlotValidation::PlotNHits() } } - delete fakeratetree; + delete frtree; } void PlotValidation::PlotMomResolutionPull() diff --git a/TTreeValidation.cc b/TTreeValidation.cc index 2c6346123e0ef..26cfcdde7715e 100644 --- a/TTreeValidation.cc +++ b/TTreeValidation.cc @@ -75,7 +75,7 @@ TTreeValidation::~TTreeValidation() if (Config::root_val) { delete efftree_; - delete fakeratetree_; + delete frtree_; } if (Config::cmssw_val) { @@ -194,108 +194,108 @@ void TTreeValidation::initializeEfficiencyTree() void TTreeValidation::initializeFakeRateTree() { // fake rate validation - fakeratetree_ = new TTree("fakeratetree","fakeratetree"); - - fakeratetree_->Branch("evtID",&evtID_FR_); - fakeratetree_->Branch("seedID",&seedID_FR_); - - fakeratetree_->Branch("seedmask_seed",&seedmask_seed_FR_); - fakeratetree_->Branch("seedmask_build",&seedmask_build_FR_); - fakeratetree_->Branch("seedmask_fit",&seedmask_fit_FR_); - - fakeratetree_->Branch("xhit_seed",&xhit_seed_FR_); - fakeratetree_->Branch("xhit_build",&xhit_build_FR_); - fakeratetree_->Branch("xhit_fit",&xhit_fit_FR_); - - fakeratetree_->Branch("yhit_seed",&yhit_seed_FR_); - fakeratetree_->Branch("yhit_build",&yhit_build_FR_); - fakeratetree_->Branch("yhit_fit",&yhit_fit_FR_); - - fakeratetree_->Branch("zhit_seed",&zhit_seed_FR_); - fakeratetree_->Branch("zhit_build",&zhit_build_FR_); - fakeratetree_->Branch("zhit_fit",&zhit_fit_FR_); - - fakeratetree_->Branch("pt_seed",&pt_seed_FR_); - fakeratetree_->Branch("ept_seed",&ept_seed_FR_); - fakeratetree_->Branch("pt_build",&pt_build_FR_); - fakeratetree_->Branch("ept_build",&ept_build_FR_); - fakeratetree_->Branch("pt_fit",&pt_fit_FR_); - fakeratetree_->Branch("ept_fit",&ept_fit_FR_); - - fakeratetree_->Branch("phi_seed",&phi_seed_FR_); - fakeratetree_->Branch("ephi_seed",&ephi_seed_FR_); - fakeratetree_->Branch("phi_build",&phi_build_FR_); - fakeratetree_->Branch("ephi_build",&ephi_build_FR_); - fakeratetree_->Branch("phi_fit",&phi_fit_FR_); - fakeratetree_->Branch("ephi_fit",&ephi_fit_FR_); - - fakeratetree_->Branch("eta_seed",&eta_seed_FR_); - fakeratetree_->Branch("eeta_seed",&eeta_seed_FR_); - fakeratetree_->Branch("eta_build",&eta_build_FR_); - fakeratetree_->Branch("eeta_build",&eeta_build_FR_); - fakeratetree_->Branch("eta_fit",&eta_fit_FR_); - fakeratetree_->Branch("eeta_fit",&eeta_fit_FR_); - - fakeratetree_->Branch("nHits_seed",&nHits_seed_FR_); - fakeratetree_->Branch("nHits_build",&nHits_build_FR_); - fakeratetree_->Branch("nHits_fit",&nHits_fit_FR_); - - fakeratetree_->Branch("nHitsMatched_seed",&nHitsMatched_seed_FR_); - fakeratetree_->Branch("nHitsMatched_build",&nHitsMatched_build_FR_); - fakeratetree_->Branch("nHitsMatched_fit",&nHitsMatched_fit_FR_); - - fakeratetree_->Branch("fracHitsMatched_seed",&fracHitsMatched_seed_FR_); - fakeratetree_->Branch("fracHitsMatched_build",&fracHitsMatched_build_FR_); - fakeratetree_->Branch("fracHitsMatched_fit",&fracHitsMatched_fit_FR_); - - fakeratetree_->Branch("lastlyr_seed",&lastlyr_seed_FR_); - fakeratetree_->Branch("lastlyr_build",&lastlyr_build_FR_); - fakeratetree_->Branch("lastlyr_fit",&lastlyr_fit_FR_); - - fakeratetree_->Branch("hitchi2_seed",&hitchi2_seed_FR_); - fakeratetree_->Branch("hitchi2_build",&hitchi2_build_FR_); - fakeratetree_->Branch("hitchi2_fit",&hitchi2_fit_FR_); + frtree_ = new TTree("frtree","frtree"); + + frtree_->Branch("evtID",&evtID_FR_); + frtree_->Branch("seedID",&seedID_FR_); + + frtree_->Branch("seedmask_seed",&seedmask_seed_FR_); + frtree_->Branch("seedmask_build",&seedmask_build_FR_); + frtree_->Branch("seedmask_fit",&seedmask_fit_FR_); + + frtree_->Branch("xhit_seed",&xhit_seed_FR_); + frtree_->Branch("xhit_build",&xhit_build_FR_); + frtree_->Branch("xhit_fit",&xhit_fit_FR_); + + frtree_->Branch("yhit_seed",&yhit_seed_FR_); + frtree_->Branch("yhit_build",&yhit_build_FR_); + frtree_->Branch("yhit_fit",&yhit_fit_FR_); + + frtree_->Branch("zhit_seed",&zhit_seed_FR_); + frtree_->Branch("zhit_build",&zhit_build_FR_); + frtree_->Branch("zhit_fit",&zhit_fit_FR_); + + frtree_->Branch("pt_seed",&pt_seed_FR_); + frtree_->Branch("ept_seed",&ept_seed_FR_); + frtree_->Branch("pt_build",&pt_build_FR_); + frtree_->Branch("ept_build",&ept_build_FR_); + frtree_->Branch("pt_fit",&pt_fit_FR_); + frtree_->Branch("ept_fit",&ept_fit_FR_); + + frtree_->Branch("phi_seed",&phi_seed_FR_); + frtree_->Branch("ephi_seed",&ephi_seed_FR_); + frtree_->Branch("phi_build",&phi_build_FR_); + frtree_->Branch("ephi_build",&ephi_build_FR_); + frtree_->Branch("phi_fit",&phi_fit_FR_); + frtree_->Branch("ephi_fit",&ephi_fit_FR_); + + frtree_->Branch("eta_seed",&eta_seed_FR_); + frtree_->Branch("eeta_seed",&eeta_seed_FR_); + frtree_->Branch("eta_build",&eta_build_FR_); + frtree_->Branch("eeta_build",&eeta_build_FR_); + frtree_->Branch("eta_fit",&eta_fit_FR_); + frtree_->Branch("eeta_fit",&eeta_fit_FR_); + + frtree_->Branch("nHits_seed",&nHits_seed_FR_); + frtree_->Branch("nHits_build",&nHits_build_FR_); + frtree_->Branch("nHits_fit",&nHits_fit_FR_); + + frtree_->Branch("nHitsMatched_seed",&nHitsMatched_seed_FR_); + frtree_->Branch("nHitsMatched_build",&nHitsMatched_build_FR_); + frtree_->Branch("nHitsMatched_fit",&nHitsMatched_fit_FR_); + + frtree_->Branch("fracHitsMatched_seed",&fracHitsMatched_seed_FR_); + frtree_->Branch("fracHitsMatched_build",&fracHitsMatched_build_FR_); + frtree_->Branch("fracHitsMatched_fit",&fracHitsMatched_fit_FR_); + + frtree_->Branch("lastlyr_seed",&lastlyr_seed_FR_); + frtree_->Branch("lastlyr_build",&lastlyr_build_FR_); + frtree_->Branch("lastlyr_fit",&lastlyr_fit_FR_); + + frtree_->Branch("hitchi2_seed",&hitchi2_seed_FR_); + frtree_->Branch("hitchi2_build",&hitchi2_build_FR_); + frtree_->Branch("hitchi2_fit",&hitchi2_fit_FR_); // sim info of seed,build,fit tracks - fakeratetree_->Branch("mcID_seed",&mcID_seed_FR_); - fakeratetree_->Branch("mcID_build",&mcID_build_FR_); - fakeratetree_->Branch("mcID_fit",&mcID_fit_FR_); + frtree_->Branch("mcID_seed",&mcID_seed_FR_); + frtree_->Branch("mcID_build",&mcID_build_FR_); + frtree_->Branch("mcID_fit",&mcID_fit_FR_); - fakeratetree_->Branch("mcmask_seed",&mcmask_seed_FR_); - fakeratetree_->Branch("mcmask_build",&mcmask_build_FR_); - fakeratetree_->Branch("mcmask_fit",&mcmask_fit_FR_); + frtree_->Branch("mcmask_seed",&mcmask_seed_FR_); + frtree_->Branch("mcmask_build",&mcmask_build_FR_); + frtree_->Branch("mcmask_fit",&mcmask_fit_FR_); - fakeratetree_->Branch("pt_mc_seed",&pt_mc_seed_FR_); - fakeratetree_->Branch("pt_mc_build",&pt_mc_build_FR_); - fakeratetree_->Branch("pt_mc_fit",&pt_mc_fit_FR_); + frtree_->Branch("pt_mc_seed",&pt_mc_seed_FR_); + frtree_->Branch("pt_mc_build",&pt_mc_build_FR_); + frtree_->Branch("pt_mc_fit",&pt_mc_fit_FR_); - fakeratetree_->Branch("phi_mc_seed",&phi_mc_seed_FR_); - fakeratetree_->Branch("phi_mc_build",&phi_mc_build_FR_); - fakeratetree_->Branch("phi_mc_fit",&phi_mc_fit_FR_); + frtree_->Branch("phi_mc_seed",&phi_mc_seed_FR_); + frtree_->Branch("phi_mc_build",&phi_mc_build_FR_); + frtree_->Branch("phi_mc_fit",&phi_mc_fit_FR_); - fakeratetree_->Branch("eta_mc_seed",&eta_mc_seed_FR_); - fakeratetree_->Branch("eta_mc_build",&eta_mc_build_FR_); - fakeratetree_->Branch("eta_mc_fit",&eta_mc_fit_FR_); + frtree_->Branch("eta_mc_seed",&eta_mc_seed_FR_); + frtree_->Branch("eta_mc_build",&eta_mc_build_FR_); + frtree_->Branch("eta_mc_fit",&eta_mc_fit_FR_); - fakeratetree_->Branch("nHits_mc_seed",&nHits_mc_seed_FR_); - fakeratetree_->Branch("nHits_mc_build",&nHits_mc_build_FR_); - fakeratetree_->Branch("nHits_mc_fit",&nHits_mc_fit_FR_); + frtree_->Branch("nHits_mc_seed",&nHits_mc_seed_FR_); + frtree_->Branch("nHits_mc_build",&nHits_mc_build_FR_); + frtree_->Branch("nHits_mc_fit",&nHits_mc_fit_FR_); - fakeratetree_->Branch("lastlyr_mc_seed",&lastlyr_mc_seed_FR_); - fakeratetree_->Branch("lastlyr_mc_build",&lastlyr_mc_build_FR_); - fakeratetree_->Branch("lastlyr_mc_fit",&lastlyr_mc_fit_FR_); + frtree_->Branch("lastlyr_mc_seed",&lastlyr_mc_seed_FR_); + frtree_->Branch("lastlyr_mc_build",&lastlyr_mc_build_FR_); + frtree_->Branch("lastlyr_mc_fit",&lastlyr_mc_fit_FR_); - fakeratetree_->Branch("helixchi2_seed",&helixchi2_seed_FR_); - fakeratetree_->Branch("helixchi2_build",&helixchi2_build_FR_); - fakeratetree_->Branch("helixchi2_fit",&helixchi2_fit_FR_); + frtree_->Branch("helixchi2_seed",&helixchi2_seed_FR_); + frtree_->Branch("helixchi2_build",&helixchi2_build_FR_); + frtree_->Branch("helixchi2_fit",&helixchi2_fit_FR_); - fakeratetree_->Branch("duplmask_seed",&duplmask_seed_FR_); - fakeratetree_->Branch("duplmask_build",&duplmask_build_FR_); - fakeratetree_->Branch("duplmask_fit",&duplmask_fit_FR_); + frtree_->Branch("duplmask_seed",&duplmask_seed_FR_); + frtree_->Branch("duplmask_build",&duplmask_build_FR_); + frtree_->Branch("duplmask_fit",&duplmask_fit_FR_); - fakeratetree_->Branch("iTkMatches_seed",&iTkMatches_seed_FR_); - fakeratetree_->Branch("iTkMatches_build",&iTkMatches_build_FR_); - fakeratetree_->Branch("iTkMatches_fit",&iTkMatches_fit_FR_); + frtree_->Branch("iTkMatches_seed",&iTkMatches_seed_FR_); + frtree_->Branch("iTkMatches_build",&iTkMatches_build_FR_); + frtree_->Branch("iTkMatches_fit",&iTkMatches_fit_FR_); } void TTreeValidation::initializeConfigTree() @@ -1367,7 +1367,7 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) iTkMatches_fit_FR_ = -100; } - fakeratetree_->Fill(); // fill once per seed! + frtree_->Fill(); // fill once per seed! }// end of seed to seed loop } diff --git a/TTreeValidation.h b/TTreeValidation.h index 3bfdc14ee7fd3..79a223150a0d1 100644 --- a/TTreeValidation.h +++ b/TTreeValidation.h @@ -111,7 +111,7 @@ class TTreeValidation : public Validation { int nTkMatches_seed_eff_=0,nTkMatches_build_eff_=0,nTkMatches_fit_eff_=0; // Fake Rate tree and variables - TTree* fakeratetree_; + TTree* frtree_; int evtID_FR_=0,seedID_FR_=0; int seedmask_seed_FR_=0,seedmask_build_FR_=0,seedmask_fit_FR_=0; From 12ec123ac59f51a8376320bd3429fa1f2413e163 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 3 Aug 2017 16:59:13 -0700 Subject: [PATCH 124/172] Moving configurables to Config --- Config.h | 5 +++++ Event.cc | 9 ++++++--- Event.h | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Config.h b/Config.h index 49eab5d9d9b73..7c60902d4821b 100644 --- a/Config.h +++ b/Config.h @@ -236,6 +236,11 @@ namespace Config extern bool fit_val; extern bool inclusiveShorts; + // config on seed cleaning + constexpr double maxDR_seedclean = 0.005; + constexpr int minNHits_seedclean = 4; + constexpr double track1GeVradius = 87.6; // = 1/(c*B) + // Threading extern int numThreadsFinder; extern int numThreadsSimulation; diff --git a/Event.cc b/Event.cc index 0369b8158040d..063149ee0076f 100644 --- a/Event.cc +++ b/Event.cc @@ -679,9 +679,12 @@ void Event::print_tracks(const TrackVec& tracks, bool print_hits) const } } -TrackVec Event::clean_cms_seedtracks(double maxDR, int minNHits) +TrackVec Event::clean_cms_seedtracks() { + double maxDR = Config::maxDR_seedclean; + int minNHits = Config::minNHits_seedclean; + int ns = seedTracks_.size(); TrackVec cleanSeedTracks; @@ -713,8 +716,8 @@ TrackVec Event::clean_cms_seedtracks(double maxDR, int minNHits) double oldPhi1 = track_first.momPhi(); double oldPhi2 = track_second.momPhi(); - double newPhi1 = oldPhi1-thisDXY/87.6/track_first.pT()*track_first.charge(); - double newPhi2 = oldPhi2+thisDXY/87.6/track_second.pT()*track_second.charge(); + double newPhi1 = oldPhi1-thisDXY/(Config::track1GeVradius)/track_first.pT()*track_first.charge(); + double newPhi2 = oldPhi2+thisDXY/(Config::track1GeVradius)/track_second.pT()*track_second.charge(); double Eta1 = track_first.momEta(); double Eta2 = track_second.momEta(); diff --git a/Event.h b/Event.h index c57179d4a0ff9..876605b5a764b 100644 --- a/Event.h +++ b/Event.h @@ -36,7 +36,7 @@ class Event void read_in (DataFile &data_file, FILE *in_fp=0); int clean_cms_simtracks(); - TrackVec clean_cms_seedtracks(double maxDR=0.005, int minNHits=4); + TrackVec clean_cms_seedtracks(); void print_tracks(const TrackVec& tracks, bool print_hits) const; const Geometry& geom_; From f69f6ce6002efba3b77602029bcb6595a44fd6d0 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Thu, 3 Aug 2017 17:13:27 -0700 Subject: [PATCH 125/172] relocatable validationMIC scripts --- validationMIC-build-10mu.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/validationMIC-build-10mu.sh b/validationMIC-build-10mu.sh index 890b91d06500b..75af380131c3b 100755 --- a/validationMIC-build-10mu.sh +++ b/validationMIC-build-10mu.sh @@ -2,11 +2,12 @@ make -j 12 WITH_ROOT=yes -ECN2=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEta-24to-17Pt1to10/memoryFile.fv3.recT.072617.bin -ECN1=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEta-175to-055Pt1to10/memoryFile.fv3.recT.072617.bin -BRL=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEtaLT06Pt1to10/memoryFile.fv3.recT.072617.bin -ECP1=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEta055to175Pt1to10/memoryFile.fv3.recT.072617.bin -ECP2=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep/10muEta17to24Pt1to10/memoryFile.fv3.recT.072617.bin +[ -e "$BIN_DATA_PATH" ] || BIN_DATA_PATH=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep +ECN2=${BIN_DATA_PATH}/10muEta-24to-17Pt1to10/memoryFile.fv3.recT.072617.bin +ECN1=${BIN_DATA_PATH}/10muEta-175to-055Pt1to10/memoryFile.fv3.recT.072617.bin +BRL=${BIN_DATA_PATH}/10muEtaLT06Pt1to10/memoryFile.fv3.recT.072617.bin +ECP1=${BIN_DATA_PATH}/10muEta055to175Pt1to10/memoryFile.fv3.recT.072617.bin +ECP2=${BIN_DATA_PATH}/10muEta17to24Pt1to10/memoryFile.fv3.recT.072617.bin base=SNB_CMSSW_10mu From cc002f34be7ecdb8b534ffc81014f244de2c71af Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Fri, 4 Aug 2017 11:17:54 -0700 Subject: [PATCH 126/172] add a build with CLEAN_SEEDS; wrap common call part into a function --- benchmarkMIC-build.sh | 94 +++++++++++++++++++++++-------------- validationMIC-build-10mu.sh | 94 ++++++++++++++++++++++--------------- validationMIC-build-PU70.sh | 62 +++++++++++++++--------- 3 files changed, 153 insertions(+), 97 deletions(-) diff --git a/benchmarkMIC-build.sh b/benchmarkMIC-build.sh index dd123760d0105..e2fcd0e6862e1 100755 --- a/benchmarkMIC-build.sh +++ b/benchmarkMIC-build.sh @@ -3,60 +3,82 @@ [ -e "$BIN_DATA_PATH" ] || BIN_DATA_PATH=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep fin=${BIN_DATA_PATH}/PU70/10224.0_TTbar_13+TTbar_13TeV_TuneCUETP8M1_2017PU_GenSimFullINPUT+DigiFullPU_2017PU+RecoFullPU_2017PU+HARVESTFullPU_2017PU/memoryFile.fv3.clean.writeAll.recT.072617.bin -base=SNB_CMSSW_PU70_clean - -make -j 12 -for sV in "sim " "see --cmssw-seeds"; do echo $sV | while read -r sN sO; do - for bV in "BH bh" "STD std" "CE ce"; do echo $bV | while read -r bN bO; do - oBase=${base}_${sN}_${bN} - for nTH in 1 2 4 8 12 16 24 32; do - echo "${oBase}: benchmark [nTH:${nTH}, nVU:8]" - time ./mkFit/mkFit --geom CMS-2017 --read --file-name ${fin} --build-${bO} ${sO} --num-thr ${nTH} >& log_${oBase}_NVU8int_NTH${nTH}_benchmark.txt - done +runBenchmark() +{ + for sV in "sim " "see --cmssw-seeds"; do echo $sV | while read -r sN sO; do + for bV in "BH bh" "STD std" "CE ce"; do echo $bV | while read -r bN bO; do + oBase=${base}_${sN}_${bN} + for nTH in 1 2 4 8 12 16 24 32; do + echo "${oBase}: benchmark [nTH:${nTH}, nVU:8]" + time ./mkFit/mkFit --geom CMS-2017 --read --file-name ${fin} --build-${bO} ${sO} --num-thr ${nTH} >& log_${oBase}_NVU8int_NTH${nTH}_benchmark.txt + done + done done done done -done -make clean -make distclean + make clean + make distclean +} -make -j 12 CPPUSERFLAGS+="-march=native -mtune=native" CXXUSERFLAGS+="-march=native -mtune=native" -for sV in "sim " "see --cmssw-seeds"; do echo $sV | while read -r sN sO; do - for bV in "BH bh" "STD std" "CE ce"; do echo $bV | while read -r bN bO; do - oBase=${base}_${sN}_${bN} - for nTH in 1 2 4 8 12 16 24 32; do - echo "${oBase}: benchmark native [nTH:${nTH}, nVU:8]" - time ./mkFit/mkFit --geom CMS-2017 --read --file-name ${fin} --build-${bO} ${sO} --num-thr ${nTH} >& log_${oBase}_NVU8int_NTH${nTH}_benchmark_native.txt - done - done - done - done -done +#cleanup first make clean make distclean +export base=SNB_CMSSW_PU70_clean +echo Run default build with base = ${base} make -j 12 +#this does make clean inside +runBenchmark + +export base=SNB_CMSSW_PU70_clean_native +echo Run native build with base = ${base} +make -j 12 CPPUSERFLAGS+="-march=native -mtune=native" CXXUSERFLAGS+="-march=native -mtune=native" +#this does make clean inside +runBenchmark + +export base=SNB_CMSSW_PU70_clean_cleanSeed +echo Run CLEAN_SEEDS build with base = ${base} +make -j 12 CPPUSERFLAGS+=-DCLEAN_SEEDS CXXUSERFLAGS+=-DCLEAN_SEEDS +#this does make clean inside +runBenchmark + +export base=SNB_CMSSW_PU70_clean_native_cleanSeed +echo Run CLEAN_SEEDS build with base = ${base} +make -j 12 CPPUSERFLAGS+="-march=native -mtune=native" CXXUSERFLAGS+="-march=native -mtune=native" CPPUSERFLAGS+=-DCLEAN_SEEDS CXXUSERFLAGS+=-DCLEAN_SEEDS +#this does make clean inside +runBenchmark ECN2=${BIN_DATA_PATH}/10muEta-24to-17Pt1to10/memoryFile.fv3.recT.072617.bin ECN1=${BIN_DATA_PATH}/10muEta-175to-055Pt1to10/memoryFile.fv3.recT.072617.bin BRL=${BIN_DATA_PATH}/10muEtaLT06Pt1to10/memoryFile.fv3.recT.072617.bin ECP1=${BIN_DATA_PATH}/10muEta055to175Pt1to10/memoryFile.fv3.recT.072617.bin ECP2=${BIN_DATA_PATH}/10muEta17to24Pt1to10/memoryFile.fv3.recT.072617.bin -base=SNB_CMSSW_10mu -for sV in "sim " "see --cmssw-seeds"; do echo $sV | while read -r sN sO; do - for section in ECN2 ECN1 BRL ECP1 ECP2; do - for bV in "BH bh" "STD std" "CE ce"; do echo $bV | while read -r bN bO; do - oBase=${base}_${sN}_${section}_${bN} - nTH=8 - echo "${oBase}: benchmark [nTH:${nTH}, nVU:8]" - time ./mkFit/mkFit --geom CMS-2017 --read --file-name ${!section} --build-${bO} ${sO} --num-thr ${nTH} >& log_${oBase}_NVU8int_NTH${nTH}_benchmark.txt +runBenchmarkSections() +{ + for sV in "sim " "see --cmssw-seeds"; do echo $sV | while read -r sN sO; do + for section in ECN2 ECN1 BRL ECP1 ECP2; do + for bV in "BH bh" "STD std" "CE ce"; do echo $bV | while read -r bN bO; do + oBase=${base}_${sN}_${section}_${bN} + nTH=8 + echo "${oBase}: benchmark [nTH:${nTH}, nVU:8]" + time ./mkFit/mkFit --geom CMS-2017 --read --file-name ${!section} --build-${bO} ${sO} --num-thr ${nTH} >& log_${oBase}_NVU8int_NTH${nTH}_benchmark.txt + done done done done done -done -make clean -make distclean + make clean + make distclean +} + +export base=SNB_CMSSW_10mu +echo Run default build with base = ${base} +make -j 12 +#this does make clean inside +runBenchmarkSections + +unset base + diff --git a/validationMIC-build-10mu.sh b/validationMIC-build-10mu.sh index 75af380131c3b..28d674abe954a 100755 --- a/validationMIC-build-10mu.sh +++ b/validationMIC-build-10mu.sh @@ -1,6 +1,5 @@ #! /bin/bash -make -j 12 WITH_ROOT=yes [ -e "$BIN_DATA_PATH" ] || BIN_DATA_PATH=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep ECN2=${BIN_DATA_PATH}/10muEta-24to-17Pt1to10/memoryFile.fv3.recT.072617.bin @@ -9,49 +8,66 @@ BRL=${BIN_DATA_PATH}/10muEtaLT06Pt1to10/memoryFile.fv3.recT.072617.bin ECP1=${BIN_DATA_PATH}/10muEta055to175Pt1to10/memoryFile.fv3.recT.072617.bin ECP2=${BIN_DATA_PATH}/10muEta17to24Pt1to10/memoryFile.fv3.recT.072617.bin -base=SNB_CMSSW_10mu - -for sV in "sim " "see --cmssw-seeds"; do echo $sV | while read -r sN sO; do - for section in ECN2 ECN1 BRL ECP1 ECP2; do - for bV in "BH bh" "STD std" "CE ce"; do echo $bV | while read -r bN bO; do - oBase=${base}_${sN}_${section}_${bN} - nTH=8 - echo "${oBase}: validation [nTH:${nTH}, nVU:8]" - ./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${!section} --build-${bO} ${sO} --num-thr ${nTH} >& log_${oBase}_NVU8int_NTH${nTH}_val.txt - mv valtree.root valtree_${oBase}.root - done +runValidation(){ + for sV in "sim " "see --cmssw-seeds"; do echo $sV | while read -r sN sO; do + for section in ECN2 ECN1 BRL ECP1 ECP2; do + for bV in "BH bh" "STD std" "CE ce"; do echo $bV | while read -r bN bO; do + oBase=${base}_${sN}_${section}_${bN} + nTH=8 + echo "${oBase}: validation [nTH:${nTH}, nVU:8]" + ./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${!section} --build-${bO} ${sO} --num-thr ${nTH} >& log_${oBase}_NVU8int_NTH${nTH}_val.txt + mv valtree.root valtree_${oBase}.root + done + done done - done - done -done - -make clean - -for opt in sim see -do - for section in ECN2 ECN1 BRL ECP1 ECP2 - do - oBase=${base}_${opt}_${section} - for build in BH STD CE - do - root -b -q -l runValidation.C+\(\"_${oBase}_${build}\"\) - done - root -b -q -l makeValidation.C+\(\"${oBase}\"\) + done done - - for build in BH STD CE + + make clean + + for opt in sim see do - oBase=${base}_${opt} - fBase=valtree_${oBase} - dBase=validation_${oBase} - hadd ${fBase}_FullDet_${build}.root `for section in ECN2 ECN1 BRL ECP1 ECP2; do echo -n ${dBase}_${section}_${build}/${fBase}_${section}_${build}.root" "; done` - - root -b -q -l runValidation.C+\(\"_${oBase}_FullDet_${build}\"\) + for section in ECN2 ECN1 BRL ECP1 ECP2 + do + oBase=${base}_${opt}_${section} + for build in BH STD CE + do + root -b -q -l runValidation.C+\(\"_${oBase}_${build}\"\) + done + root -b -q -l makeValidation.C+\(\"${oBase}\"\) + done + + for build in BH STD CE + do + oBase=${base}_${opt} + fBase=valtree_${oBase} + dBase=validation_${oBase} + hadd ${fBase}_FullDet_${build}.root `for section in ECN2 ECN1 BRL ECP1 ECP2; do echo -n ${dBase}_${section}_${build}/${fBase}_${section}_${build}.root" "; done` + + root -b -q -l runValidation.C+\(\"_${oBase}_FullDet_${build}\"\) + done + + root -b -q -l makeValidation.C+\(\"${oBase}_FullDet\"\) + done + + make distclean +} - root -b -q -l makeValidation.C+\(\"${oBase}_FullDet\"\) +#cleanup first +make clean +make distclean -done +export base=SNB_CMSSW_10mu +echo Run default with base = ${base} +make -j 12 WITH_ROOT=yes +#this does make clean inside +runValidation -make distclean +export base=SNB_CMSSW_10mu_cleanSeed +echo Run CLEAN_SEEDS with base = ${base} +make -j 12 WITH_ROOT=yes CPPUSERFLAGS+=-DCLEAN_SEEDS CXXUSERFLAGS+=-DCLEAN_SEEDS +#this does make clean inside +runValidation +unset base diff --git a/validationMIC-build-PU70.sh b/validationMIC-build-PU70.sh index 998082f2672b8..97dc0085f902c 100755 --- a/validationMIC-build-PU70.sh +++ b/validationMIC-build-PU70.sh @@ -1,34 +1,52 @@ #! /bin/bash -make -j 12 WITH_ROOT=yes - [ -e "$BIN_DATA_PATH" ] || BIN_DATA_PATH=/store/disk00/slava77/analysis/CMSSW_9_1_0_pre1-tkNtuple/run1000/2017/pass-4874f28/initialStep fin=${BIN_DATA_PATH}/PU70/10224.0_TTbar_13+TTbar_13TeV_TuneCUETP8M1_2017PU_GenSimFullINPUT+DigiFullPU_2017PU+RecoFullPU_2017PU+HARVESTFullPU_2017PU/memoryFile.fv3.clean.writeAll.recT.072617.bin -base=SNB_CMSSW_PU70_clean - -for sV in "sim " "see --cmssw-seeds"; do echo $sV | while read -r sN sO; do - for bV in "BH bh" "STD std" "CE ce"; do echo $bV | while read -r bN bO; do - oBase=${base}_${sN}_${bN} - nTH=8 - echo "${oBase}: validation [nTH:${nTH}, nVU:8]" - ./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${fin} --build-${bO} ${sO} --num-thr ${nTH} >& log_${oBase}_NVU8int_NTH${nTH}_val.txt - mv valtree.root valtree_${oBase}.root +runValidation() +{ + for sV in "sim " "see --cmssw-seeds"; do echo $sV | while read -r sN sO; do + for bV in "BH bh" "STD std" "CE ce"; do echo $bV | while read -r bN bO; do + oBase=${base}_${sN}_${bN} + nTH=8 + echo "${oBase}: validation [nTH:${nTH}, nVU:8]" + ./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${fin} --build-${bO} ${sO} --num-thr ${nTH} >& log_${oBase}_NVU8int_NTH${nTH}_val.txt + mv valtree.root valtree_${oBase}.root + done done done done -done - -make clean - -for opt in sim see -do - oBase=${base}_${opt} - for build in BH STD CE + + make clean + + for opt in sim see do - root -b -q -l runValidation.C+\(\"_${oBase}_${build}\"\) + oBase=${base}_${opt} + for build in BH STD CE + do + root -b -q -l runValidation.C+\(\"_${oBase}_${build}\"\) + done + root -b -q -l makeValidation.C+\(\"${oBase}\"\) done - root -b -q -l makeValidation.C+\(\"${oBase}\"\) -done + + make distclean +} +#cleanup first +make clean make distclean + +export base=SNB_CMSSW_PU70_clean +echo Run default build with base = ${base} +make -j 12 WITH_ROOT=yes +#this does make clean inside +runValidation + + +export base=SNB_CMSSW_PU70_clean_cleanSeed +echo Run CLEAN_SEEDS with base = ${base} +make -j 12 WITH_ROOT=yes CPPUSERFLAGS+=-DCLEAN_SEEDS CXXUSERFLAGS+=-DCLEAN_SEEDS +#this does make clean inside +runValidation + +unset base From 320f81bf37c4c9078bd2218ec88d39034558030a Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Fri, 4 Aug 2017 13:09:09 -0700 Subject: [PATCH 127/172] do not clean with label -1 if CLEAN_SEEDS is defined --- mkFit/MkBuilder.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index 71c61b8876d73..13f4d028aabf0 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -384,12 +384,14 @@ void MkBuilder::import_seeds() if (Config::readCmsswSeeds) { +#ifndef CLEAN_SEEDS printf("***\n*** MkBuilder::import_seeds REMOVING SEEDS WITH BAD LABEL. This is a development hack. ***\n***\n"); if (true) { TrackVec buf; m_event->seedTracks_.swap(buf); std::copy_if(buf.begin(), buf.end(), std::back_inserter(m_event->seedTracks_), [](const Track& t){ return t.label() >= 0; }); } +#endif } TrackerInfo &trk_info = Config::TrkInfo; From 43a83577572758243bac56144d444bdfdbdd951d Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Fri, 4 Aug 2017 06:21:43 -0700 Subject: [PATCH 128/172] CMSSW TTreeValidation complete... compiles and runs. Other fixups to standard validation: * revert squashPhiGeneral (does not compile with two templates as currently implemented) * include cms sim track cleaning when using cmssw seeds * factorize mkbuilder validation functions * factorize mc track mapping to be reused by CMSSW validation * set 75% matching to have a hard cut (not variable) * add two additional mcTrackIDs (-6,-7) to indicate simtrack not findable * resuse ids for cmssw validation --- Config.h | 9 +- Event.cc | 2 +- Hit.h | 2 +- TTreeValidation.cc | 391 ++++++++++++++++++++++++++++++++++++---- TTreeValidation.h | 52 +++++- Track.cc | 119 ++++++++---- Track.h | 8 +- mkFit/MkBuilder.cc | 88 +++------ mkFit/MkBuilder.h | 17 +- mkFit/buildtestMPlex.cc | 42 +++-- 10 files changed, 556 insertions(+), 174 deletions(-) diff --git a/Config.h b/Config.h index a498c3bb9b554..396e42b56c4b4 100644 --- a/Config.h +++ b/Config.h @@ -225,16 +225,15 @@ namespace Config extern int maxHolesPerCand; // default: 2; cms 12 (should be reduced) extern int maxCandsPerEtaBin; - // Selection of simtracks from CMSSW. Used in Event::clean_cms_simtracks(). - constexpr int cmsSimSelMinLayers = 8; - constexpr float cmsSimSelMinPt = 0.5; + // Selection of simtracks from CMSSW. Used in Event::clean_cms_simtracks() and MkBuilder::prep_cmsswtracks() + constexpr int cmsSelMinLayers = 8; + constexpr float cmsSelMinPt = 0.5; // config on validation - constexpr float nMinSimHitsFrac = 0.7; constexpr int nMinFoundHits = 7; constexpr float minCMSSWMatchChi2 = 50; constexpr float minCMSSWMatchdPhi = 0.03; - constexpr int nCMSSWMatchHits = 7; + constexpr int nCMSSWMatchHitsAfterSeed = 5; extern bool root_val; extern bool cmssw_val; extern bool fit_val; diff --git a/Event.cc b/Event.cc index aecffeadfa879..afe5997cd2059 100644 --- a/Event.cc +++ b/Event.cc @@ -635,7 +635,7 @@ int Event::clean_cms_simtracks() const int lyr_cnt = t.nUniqueLayers(); - if (lyr_cnt < Config::cmsSimSelMinLayers || t.pT() < Config::cmsSimSelMinPt) + if (lyr_cnt < Config::cmsSelMinLayers || t.pT() < Config::cmsSelMinPt) { dprintf("Rejecting simtrack %d, n_hits=%d, n_layers=%d, pT=%f\n", i, nh, lyr_cnt, t.pT()); t.setNotFindable(); diff --git a/Hit.h b/Hit.h index 944a4edd32d5d..1a08181817b34 100644 --- a/Hit.h +++ b/Hit.h @@ -13,7 +13,7 @@ template inline T cube(T x) { return x*x*x; } inline float squashPhiGeneral(float phi) { - return phi - floor(0.5f*Config::InvPI*(phi+Config::PI)) * Config::TwoPI; + return phi - floor(0.5*Config::InvPI*(phi+Config::PI)) * Config::TwoPI; } // moved from config to here diff --git a/TTreeValidation.cc b/TTreeValidation.cc index 26cfcdde7715e..193cf0e0e56a0 100644 --- a/TTreeValidation.cc +++ b/TTreeValidation.cc @@ -4,10 +4,10 @@ // denominator: all findable sim tracks (mcmask = 0 || == 1) // Fake Rate (with only long reco tracks: Config::inclusiveShorts == false) // numerator: reco tracks with mcTrackID == -1 (mcmask == 0) -// denominator: reco tracks with mcTrackID >= 0 || == -1 (mcmask == 1,0,2) +// denominator: reco tracks with mcTrackID >= 0 || == -1 || == -6 (mcmask == 1,0,2) // Fake Rate (with all reco tracks: Config::inclusiveShorts == true) // numerator: reco tracks with mcTrackID == -1, == -3 (mcmask == 0) -// denominator: reco tracks with mcTrackID >= 0 || == -1 || == -2 || == -3 || == -4 (mcmask == 1,0,2) +// denominator: reco tracks with mcTrackID >= 0 || == -1 || == -2 || == -3 || == -4 || == -6 || == -7 (mcmask == 1,0,2) // N.B. Mask assignments // --> mcmask_[reco] == 1,"associated" reco to sim track [possible duplmask_[reco] == 1,0] {eff and FR} @@ -354,12 +354,97 @@ void TTreeValidation::initializeCMSSWEfficiencyTree() { // cmssw reco track efficiency validation cmsswefftree_ = new TTree("cmsswefftree","cmsswefftree"); + cmsswefftree_->Branch("evtID",&evtID_ceff_); + cmsswefftree_->Branch("cmsswID",&cmsswID_ceff_); + cmsswefftree_->Branch("cmsswmask_build",&cmsswmask_build_ceff_); + cmsswefftree_->Branch("seedID_cmssw",&seedID_cmssw_ceff_); + cmsswefftree_->Branch("seedID_build",&seedID_build_ceff_); + + cmsswefftree_->Branch("x_cmssw",&x_cmssw_ceff_); + cmsswefftree_->Branch("y_cmssw",&y_cmssw_ceff_); + cmsswefftree_->Branch("z_cmssw",&z_cmssw_ceff_); + + cmsswefftree_->Branch("pt_cmssw",&pt_cmssw_ceff_); + cmsswefftree_->Branch("phi_cmssw",&phi_cmssw_ceff_); + cmsswefftree_->Branch("eta_cmssw",&eta_cmssw_ceff_); + + cmsswefftree_->Branch("nHits_cmssw",&nHits_cmssw_ceff_); + cmsswefftree_->Branch("nLayers_cmssw",&nLayers_cmssw_ceff_); + cmsswefftree_->Branch("lastlyr_cmssw",&lastlyr_cmssw_ceff_); + + cmsswefftree_->Branch("pt_build",&pt_build_ceff_); + cmsswefftree_->Branch("ept_build",&ept_build_ceff_); + cmsswefftree_->Branch("phi_build",&phi_build_ceff_); + cmsswefftree_->Branch("ephi_build",&ephi_build_ceff_); + cmsswefftree_->Branch("eta_build",&eta_build_ceff_); + cmsswefftree_->Branch("eeta_build",&eeta_build_ceff_); + + cmsswefftree_->Branch("nHits_build",&nHits_build_ceff_); + cmsswefftree_->Branch("nLayers_build",&nLayers_build_ceff_); + cmsswefftree_->Branch("nHitsMatched_build",&nHitsMatched_build_ceff_); + cmsswefftree_->Branch("fracHitsMatched_build",&fracHitsMatched_build_ceff_); + cmsswefftree_->Branch("lastlyr_build",&lastlyr_build_ceff_); + + cmsswefftree_->Branch("xhit_build",&xhit_build_ceff_); + cmsswefftree_->Branch("yhit_build",&yhit_build_ceff_); + cmsswefftree_->Branch("zhit_build",&zhit_build_ceff_); + + cmsswefftree_->Branch("hitchi2_build",&hitchi2_build_ceff_); + cmsswefftree_->Branch("helixchi2_build",&helixchi2_build_ceff_); + cmsswefftree_->Branch("phi_cmssw_build",&phi_cmssw_build_ceff_); + + cmsswefftree_->Branch("duplmask_build",&duplmask_build_ceff_); + cmsswefftree_->Branch("nTkMatches_build",&nTkMatches_build_ceff_); } void TTreeValidation::initializeCMSSWFakeRateTree() { // cmssw reco track efficiency validation cmsswfrtree_ = new TTree("cmsswfrtree","cmsswfrtree"); + + cmsswfrtree_->Branch("evtID",&evtID_cFR_); + cmsswfrtree_->Branch("label_build",&label_build_cFR_); + cmsswfrtree_->Branch("cmsswID_build",&cmsswID_build_cFR_); + cmsswfrtree_->Branch("cmsswmask_build",&cmsswmask_build_cFR_); + cmsswfrtree_->Branch("seedID_cmssw",&seedID_cmssw_cFR_); + cmsswfrtree_->Branch("seedID_build",&seedID_build_cFR_); + + cmsswfrtree_->Branch("pt_build",&pt_build_cFR_); + cmsswfrtree_->Branch("ept_build",&ept_build_cFR_); + cmsswfrtree_->Branch("phi_build",&phi_build_cFR_); + cmsswfrtree_->Branch("ephi_build",&ephi_build_cFR_); + cmsswfrtree_->Branch("eta_build",&eta_build_cFR_); + cmsswfrtree_->Branch("eeta_build",&eeta_build_cFR_); + + cmsswfrtree_->Branch("nHits_build",&nHits_build_cFR_); + cmsswfrtree_->Branch("nLayers_build",&nLayers_build_cFR_); + cmsswfrtree_->Branch("nHitsMatched_build",&nHitsMatched_build_cFR_); + cmsswfrtree_->Branch("fracHitsMatched_build",&fracHitsMatched_build_cFR_); + cmsswfrtree_->Branch("lastlyr_build",&lastlyr_build_cFR_); + + cmsswfrtree_->Branch("xhit_build",&xhit_build_cFR_); + cmsswfrtree_->Branch("yhit_build",&yhit_build_cFR_); + cmsswfrtree_->Branch("zhit_build",&zhit_build_cFR_); + + cmsswfrtree_->Branch("hitchi2_build",&hitchi2_build_cFR_); + cmsswfrtree_->Branch("helixchi2_build",&helixchi2_build_cFR_); + + cmsswfrtree_->Branch("duplmask_build",&duplmask_build_cFR_); + cmsswfrtree_->Branch("iTkMatches_build",&iTkMatches_build_cFR_); + + cmsswfrtree_->Branch("x_cmssw",&x_cmssw_cFR_); + cmsswfrtree_->Branch("y_cmssw",&y_cmssw_cFR_); + cmsswfrtree_->Branch("z_cmssw",&z_cmssw_cFR_); + + cmsswfrtree_->Branch("pt_cmssw",&pt_cmssw_cFR_); + cmsswfrtree_->Branch("phi_cmssw",&phi_cmssw_cFR_); + cmsswfrtree_->Branch("eta_cmssw",&eta_cmssw_cFR_); + + cmsswfrtree_->Branch("nHits_cmssw",&nHits_cmssw_cFR_); + cmsswfrtree_->Branch("nLayers_cmssw",&nLayers_cmssw_cFR_); + cmsswfrtree_->Branch("lastlyr_cmssw",&lastlyr_cmssw_cFR_); + + cmsswfrtree_->Branch("phi_cmssw_build",&phi_cmssw_build_cFR_); } void TTreeValidation::initializeFitTree() @@ -447,6 +532,9 @@ void TTreeValidation::resetValidationMaps() // reset map of seed tracks to reco tracks seedToBuildMap_.clear(); seedToFitMap_.clear(); + + // reest map of cmssw tracks to reco tracks + cmsswToBuildMap_.clear(); } void TTreeValidation::setTrackExtras(Event& ev) @@ -489,9 +577,7 @@ void TTreeValidation::setTrackExtras(Event& ev) { const auto & cmsswtrack = ev.extRecTracks_[itrack]; const SVector6 & params = cmsswtrack.parameters(); - SVector2 tmpv; - tmpv[0] = params[3]; - tmpv[1] = params[5]; + SVector2 tmpv(params[3],params[5]); HitLayerMap tmpmap; for (int ihit = 0; ihit < cmsswtrack.nTotalHits(); ihit++) @@ -520,50 +606,60 @@ void TTreeValidation::makeSimTkToRecoTksMaps(Event& ev) { std::lock_guard locker(glock_); // map sim track ids to reco labels sort by each (simTracks set in order by default!) - TTreeValidation::mapSimTkToRecoTks(ev.seedTracks_,ev.seedTracksExtra_,simToSeedMap_); - TTreeValidation::mapSimTkToRecoTks(ev.candidateTracks_,ev.candidateTracksExtra_,simToBuildMap_); - TTreeValidation::mapSimTkToRecoTks(ev.fitTracks_,ev.fitTracksExtra_,simToFitMap_); + TTreeValidation::mapRefTkToRecoTks(ev.seedTracks_,ev.seedTracksExtra_,simToSeedMap_); + TTreeValidation::mapRefTkToRecoTks(ev.candidateTracks_,ev.candidateTracksExtra_,simToBuildMap_); + TTreeValidation::mapRefTkToRecoTks(ev.fitTracks_,ev.fitTracksExtra_,simToFitMap_); } -void TTreeValidation::mapSimTkToRecoTks(const TrackVec& evt_tracks, TrackExtraVec& evt_extras, TkIDToTkIDVecMap& simTkMap) +void TTreeValidation::mapRefTkToRecoTks(const TrackVec& evt_tracks, TrackExtraVec& evt_extras, TkIDToTkIDVecMap& refTkMap) { for (auto itrack = 0; itrack < evt_tracks.size(); ++itrack) { auto&& track(evt_tracks[itrack]); auto&& extra(evt_extras[itrack]); - if (extra.mcTrackID() >= 0) // skip fakes, don't store them at all in sim map + if (Config::root_val) + { + if (extra.mcTrackID() >= 0) // skip fakes, don't store them at all in sim map + { + refTkMap[extra.mcTrackID()].push_back(track.label()); // store vector of reco tk labels, mapped to the sim track label (i.e. mcTrackID) + } + } + if (Config::cmssw_val) { - simTkMap[extra.mcTrackID()].push_back(track.label()); // store vector of reco tk labels, mapped to the sim track label (i.e. mcTrackID) + if (extra.cmsswTrackID() >= 0) // skip fakes, don't store them at all in cmssw map + { + refTkMap[extra.cmsswTrackID()].push_back(track.label()); // store vector of reco tk labels, mapped to the cmssw track label (i.e. cmsswTrackID) + } } } - for (auto&& simTkMatches : simTkMap) + for (auto&& refTkMatches : refTkMap) { - if (simTkMatches.second.size() < 2) // no duplicates + if (refTkMatches.second.size() < 2) // no duplicates { - auto& extra(evt_extras[simTkMatches.second[0]]); - extra.setMCDuplicateInfo(0,bool(false)); + auto& extra(evt_extras[refTkMatches.second[0]]); + extra.setDuplicateInfo(0,bool(false)); } else // sort duplicates (ghosts) to keep best one --> most hits, lowest chi2 { // really should sort on indices with a reduced data structure... this is a hack way to do this for now... // e.g. std::tuple, (label, nHits, chi2) TrackVec tmpMatches; - for (auto&& label : simTkMatches.second) // loop over vector of reco track labels, push back the track with each label + for (auto&& label : refTkMatches.second) // loop over vector of reco track labels, push back the track with each label { tmpMatches.push_back(evt_tracks[label]); } std::sort(tmpMatches.begin(), tmpMatches.end(), sortByHitsChi2); // sort the tracks for (auto itrack = 0; itrack < tmpMatches.size(); itrack++) // loop over sorted tracks, now make the vector of sorted labels match { - simTkMatches.second[itrack] = tmpMatches[itrack].label(); + refTkMatches.second[itrack] = tmpMatches[itrack].label(); } int duplicateID = 0; - for (auto&& label : simTkMatches.second) // loop over vector of reco tracsk + for (auto&& label : refTkMatches.second) // loop over vector of reco tracsk { auto& extra(evt_extras[label]); - extra.setMCDuplicateInfo(duplicateID,bool(true)); + extra.setDuplicateInfo(duplicateID,bool(true)); duplicateID++; // used in fake rate trees! } } @@ -588,11 +684,9 @@ void TTreeValidation::mapSeedTkToRecoTk(const TrackVec& evt_tracks, const TrackE void TTreeValidation::makeCMSSWTkToRecoTksMap(Event& ev) { - int nmatched = 0; - for (auto&& trk : ev.candidateTracks_) - if (ev.candidateTracksExtra_[trk.label()].cmsswTrackID() != -1) nmatched++; - - std::cout << "Matched: " << nmatched << " / " << ev.candidateTracks_.size() << std::endl; + std::lock_guard locker(glock_); + // can reuse this function + TTreeValidation::mapRefTkToRecoTks(ev.candidateTracks_,ev.candidateTracksExtra_,cmsswToBuildMap_); } int TTreeValidation::getLastFoundHit(const int trackMCHitID, const int mcTrackID, const Event& ev) @@ -737,7 +831,7 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) lastlyr_mc_eff_ = simtrack.getLastFoundHitLyr(); // matched seed track - if (simToSeedMap_.count(mcID_eff_)) // recoToSim match : save best match --> most hits, lowest chi2, i.e. simToSeedMap_[matched SimID][first element in vector] + if (simToSeedMap_.count(mcID_eff_) && simtrack.isFindable()) // recoToSim match : save best match --> most hits, lowest chi2, i.e. simToSeedMap_[matched SimID][first element in vector] { auto& seedtrack = evt_seed_tracks[simToSeedMap_[mcID_eff_][0]]; // returns seedTrack best matched to sim track auto& seedextra = evt_seed_extras[seedtrack.label()]; // returns track extra best aligned with seed track @@ -822,7 +916,7 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) } // matched build track - if (simToBuildMap_.count(mcID_eff_)) // recoToSim match : save best match --> most hits, lowest chi2, i.e. simToBuildMap_[matched SimID][first element in vector] + if (simToBuildMap_.count(mcID_eff_) && simtrack.isFindable()) // recoToSim match : save best match --> most hits, lowest chi2, i.e. simToBuildMap_[matched SimID][first element in vector] { auto& buildtrack = evt_build_tracks[simToBuildMap_[mcID_eff_][0]]; // returns buildTrack best matched to sim track auto& buildextra = evt_build_extras[buildtrack.label()]; // returns track extra best aligned with build track @@ -906,7 +1000,7 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) } // matched fit track - if (simToFitMap_.count(mcID_eff_)) // recoToSim match : save best match --> most hits, lowest chi2, i.e. simToFitMap_[matched SimID][first element in vector] + if (simToFitMap_.count(mcID_eff_) && simtrack.isFindable()) // recoToSim match : save best match --> most hits, lowest chi2, i.e. simToFitMap_[matched SimID][first element in vector] { auto& fittrack = evt_fit_tracks[simToFitMap_[mcID_eff_][0]]; // returns fitTrack best matched to sim track auto& fitextra = evt_fit_extras[fittrack.label()]; // returns track extra best aligned with fit track @@ -1051,12 +1145,15 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) if (Config::inclusiveShorts) { if (mcID_seed_FR_ == -1 || mcID_seed_FR_ == -3) mcmask_seed_FR_ = 0; - else if (mcID_seed_FR_ == -2 || mcID_seed_FR_ == -4) mcmask_seed_FR_ = 2; + else if (mcID_seed_FR_ == -2 || mcID_seed_FR_ == -4 || + mcID_seed_FR_ == -6 || mcID_seed_FR_ == -7) mcmask_seed_FR_ = 2; else mcmask_seed_FR_ = -1; // mcID == -5 } else { - mcmask_seed_FR_ = (mcID_seed_FR_ == -1 ? 0 : -1); // mask == -1 for mcID == -2,-3,-4,-5 + if (mcID_seed_FR_ == -1) mcmask_seed_FR_ = 0; + else if (mcID_seed_FR_ == -6) mcmask_seed_FR_ = 2; + else mcmask_seed_FR_ = -1; // mcID == -2,-3,-4,-5,-7 } } @@ -1142,14 +1239,17 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) else { if (Config::inclusiveShorts) - { + { if (mcID_build_FR_ == -1 || mcID_build_FR_ == -3) mcmask_build_FR_ = 0; - else if (mcID_build_FR_ == -2 || mcID_build_FR_ == -4) mcmask_build_FR_ = 2; + else if (mcID_build_FR_ == -2 || mcID_build_FR_ == -4 || + mcID_build_FR_ == -6 || mcID_build_FR_ == -7) mcmask_build_FR_ = 2; else mcmask_build_FR_ = -1; // mcID == -5 } else - { - mcmask_build_FR_ = (mcID_build_FR_ == -1 ? 0 : -1); // mask == -1 for mcID == -2,-3,-4,-5 + { + if (mcID_build_FR_ == -1) mcmask_build_FR_ = 0; + else if (mcID_build_FR_ == -6) mcmask_build_FR_ = 2; + else mcmask_build_FR_ = -1; // mcID == -2,-3,-4,-5,-7 } } @@ -1273,14 +1373,17 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) else { if (Config::inclusiveShorts) - { + { if (mcID_fit_FR_ == -1 || mcID_fit_FR_ == -3) mcmask_fit_FR_ = 0; - else if (mcID_fit_FR_ == -2 || mcID_fit_FR_ == -4) mcmask_fit_FR_ = 2; + else if (mcID_fit_FR_ == -2 || mcID_fit_FR_ == -4 || + mcID_fit_FR_ == -6 || mcID_fit_FR_ == -7) mcmask_fit_FR_ = 2; else mcmask_fit_FR_ = -1; // mcID == -5 } else - { - mcmask_fit_FR_ = (mcID_fit_FR_ == -1 ? 0 : -1); // mask == -1 for mcID == -2,-3,-4,-5 + { + if (mcID_fit_FR_ == -1) mcmask_fit_FR_ = 0; + else if (mcID_fit_FR_ == -6) mcmask_fit_FR_ = 2; + else mcmask_fit_FR_ = -1; // mcID == -2,-3,-4,-5,-7 } } @@ -1423,10 +1526,224 @@ void TTreeValidation::fillConfigTree() void TTreeValidation::fillCMSSWEfficiencyTree(const Event& ev) { + std::lock_guard locker(glock_); + + auto ievt = ev.evtID(); + auto& evt_cmssw_tracks = ev.extRecTracks_; + auto& evt_cmssw_extras = ev.extRecTracksExtra_; + auto& evt_build_tracks = ev.candidateTracks_; + auto& evt_build_extras = ev.candidateTracksExtra_; + auto& evt_layer_hits = ev.layerHits_; + + for (auto&& cmsswtrack : evt_cmssw_tracks) + { + const auto& cmsswextra = evt_cmssw_extras[cmsswtrack.label()]; + + evtID_ceff_ = ievt; + cmsswID_ceff_ = cmsswtrack.label(); + seedID_cmssw_ceff_ = cmsswextra.seedID(); + + // PCA parameters + x_cmssw_ceff_ = cmsswtrack.x(); + y_cmssw_ceff_ = cmsswtrack.y(); + z_cmssw_ceff_ = cmsswtrack.z(); + + pt_cmssw_ceff_ = cmsswtrack.pT(); + phi_cmssw_ceff_ = cmsswtrack.momPhi(); + eta_cmssw_ceff_ = cmsswtrack.momEta(); + + nHits_cmssw_ceff_ = cmsswtrack.nFoundHits(); + nLayers_cmssw_ceff_ = cmsswtrack.nUniqueLayers(); + lastlyr_cmssw_ceff_ = cmsswtrack.getLastFoundHitLyr(); + + // matched build track + if (cmsswToBuildMap_.count(cmsswID_ceff_) && cmsswtrack.isFindable()) // recoToCmssw match : save best match --> most hits, lowest chi2, i.e. cmsswToBuildMap_[matched CmsswID][first element in vector] + { + const auto& buildtrack = evt_build_tracks[cmsswToBuildMap_[cmsswID_ceff_][0]]; // returns buildTrack best matched to cmssw track + const auto& buildextra = evt_build_extras[buildtrack.label()]; // returns track extra best aligned with build track + cmsswmask_build_ceff_ = 1; // quick logic for matched + + seedID_build_ceff_ = buildextra.seedID(); + + // track parameters + pt_build_ceff_ = buildtrack.pT(); + ept_build_ceff_ = buildtrack.epT(); + phi_build_ceff_ = buildtrack.momPhi(); + ephi_build_ceff_ = buildtrack.emomPhi(); + eta_build_ceff_ = buildtrack.momEta(); + eeta_build_ceff_ = buildtrack.emomEta(); + + // hit/layer info + nHits_build_ceff_ = buildtrack.nFoundHits(); + nLayers_build_ceff_ = buildtrack.nUniqueLayers(); + nHitsMatched_build_ceff_ = buildextra.nHitsMatched(); + fracHitsMatched_build_ceff_ = buildextra.fracHitsMatched(); + lastlyr_build_ceff_ = buildtrack.getLastFoundHitLyr(); + + // hit info + const Hit& lasthit = evt_layer_hits[buildtrack.getLastFoundHitLyr()][buildtrack.getLastFoundHitIdx()]; + xhit_build_ceff_ = lasthit.x(); + yhit_build_ceff_ = lasthit.y(); + zhit_build_ceff_ = lasthit.z(); + + // chi2 info + hitchi2_build_ceff_ = buildtrack.chi2(); + helixchi2_build_ceff_ = buildextra.helixChi2(); + + // swim phi + phi_cmssw_build_ceff_ = squashPhiGeneral(cmsswtrack.swimPhiToR(buildtrack.x(),buildtrack.y())); + + // duplicate info + duplmask_build_ceff_ = buildextra.isDuplicate(); + nTkMatches_build_ceff_ = cmsswToBuildMap_[cmsswID_ceff_].size(); // n reco matches to this cmssw track. + } + else // unmatched cmsswtracks ... put -99 for all reco values to denote unmatched + { + cmsswmask_build_ceff_ = (cmsswtrack.isFindable() ? 0 : -1); // quick logic for not matched + + seedID_build_ceff_ = -99; + + pt_build_ceff_ = -99; + ept_build_ceff_ = -99; + phi_build_ceff_ = -99; + ephi_build_ceff_ = -99; + eta_build_ceff_ = -99; + eeta_build_ceff_ = -99; + + nHits_build_ceff_ = -99; + nLayers_build_ceff_ = -99; + nHitsMatched_build_ceff_ = -99; + fracHitsMatched_build_ceff_ = -99; + lastlyr_build_ceff_ = -99; + + xhit_build_ceff_ = -2000; + yhit_build_ceff_ = -2000; + zhit_build_ceff_ = -2000; + + hitchi2_build_ceff_ = -99; + helixchi2_build_ceff_ = -99; + + phi_cmssw_build_ceff_ = -99; + + duplmask_build_ceff_ = 2; // mask means unmatched cmssw track + nTkMatches_build_ceff_ = -99; // unmatched + } + cmsswefftree_->Fill(); + } } void TTreeValidation::fillCMSSWFakeRateTree(const Event& ev) { + std::lock_guard locker(glock_); + + auto ievt = ev.evtID(); + auto& evt_cmssw_tracks = ev.extRecTracks_; + auto& evt_cmssw_extras = ev.extRecTracksExtra_; + auto& evt_build_tracks = ev.candidateTracks_; + auto& evt_build_extras = ev.candidateTracksExtra_; + auto& evt_layer_hits = ev.layerHits_; + + for (auto&& buildtrack : evt_build_tracks) + { + const auto& buildextra = evt_build_extras[buildtrack.label()]; + + evtID_cFR_ = ievt; + label_build_cFR_ = buildtrack.label(); + seedID_build_cFR_ = buildextra.seedID(); + + // track parameters + pt_build_cFR_ = buildtrack.pT(); + ept_build_cFR_ = buildtrack.epT(); + phi_build_cFR_ = buildtrack.momPhi(); + ephi_build_cFR_ = buildtrack.emomPhi(); + eta_build_cFR_ = buildtrack.momEta(); + eeta_build_cFR_ = buildtrack.emomEta(); + + // hit/layer info + nHits_build_cFR_ = buildtrack.nFoundHits(); + nLayers_build_cFR_ = buildtrack.nUniqueLayers(); + nHitsMatched_build_cFR_ = buildextra.nHitsMatched(); + fracHitsMatched_build_cFR_ = buildextra.fracHitsMatched(); + lastlyr_build_cFR_ = buildtrack.getLastFoundHitLyr(); + + // hit info + const Hit& lasthit = evt_layer_hits[buildtrack.getLastFoundHitLyr()][buildtrack.getLastFoundHitIdx()]; + xhit_build_cFR_ = lasthit.x(); + yhit_build_cFR_ = lasthit.y(); + zhit_build_cFR_ = lasthit.z(); + + // chi2 info + hitchi2_build_cFR_ = buildtrack.chi2(); + helixchi2_build_cFR_ = buildextra.helixChi2(); + + // duplicate info + duplmask_build_cFR_ = buildextra.isDuplicate(); + iTkMatches_build_cFR_ = buildextra.duplicateID(); + + // cmssw match? + cmsswID_build_cFR_ = buildextra.cmsswTrackID(); + if (cmsswID_build_cFR_ >= 0) // matched track to cmssw + { + cmsswmask_build_cFR_ = 1; + } + else + { + if (Config::inclusiveShorts) + { + if (cmsswID_build_cFR_ == -1 || cmsswID_build_cFR_ == -3) cmsswmask_build_cFR_ = 0; + else if (cmsswID_build_cFR_ == -2 || cmsswID_build_cFR_ == -6 || cmsswID_build_cFR_ == -7) cmsswmask_build_cFR_ = 2; + else std::cerr << "Somehow got a bad cmsswID: " << cmsswID_build_cFR_ << " trackID: " << label_build_cFR_ << std::endl; + } + else + { + if (cmsswID_build_cFR_ == -1) cmsswmask_build_cFR_ = 0; + else if (cmsswID_build_cFR_ == -6) cmsswmask_build_cFR_ = 2; + else cmsswmask_build_cFR_ = -1; // cmsswID == -2,-3,-7 + } + } + + if (cmsswmask_build_cFR_ == 1) // matched track to cmssw + { + const auto& cmsswtrack = evt_cmssw_tracks[cmsswID_build_cFR_]; + const auto& cmsswextra = evt_cmssw_extras[cmsswtrack.label()]; + seedID_cmssw_cFR_ = cmsswextra.seedID(); + + // PCA parameters + x_cmssw_cFR_ = cmsswtrack.x(); + y_cmssw_cFR_ = cmsswtrack.y(); + z_cmssw_cFR_ = cmsswtrack.z(); + + pt_cmssw_cFR_ = cmsswtrack.pT(); + phi_cmssw_cFR_ = cmsswtrack.momPhi(); + eta_cmssw_cFR_ = cmsswtrack.momEta(); + + nHits_cmssw_cFR_ = cmsswtrack.nFoundHits(); + nLayers_cmssw_cFR_ = cmsswtrack.nUniqueLayers(); + lastlyr_cmssw_cFR_ = cmsswtrack.getLastFoundHitLyr(); + + // swim phi + phi_cmssw_build_cFR_ = squashPhiGeneral(cmsswtrack.swimPhiToR(buildtrack.x(),buildtrack.y())); + } + else // unmatched cmsswtracks ... put -99 for all reco values to denote unmatched + { + seedID_cmssw_cFR_ = -99; + + x_cmssw_cFR_ = -2000; + y_cmssw_cFR_ = -2000; + z_cmssw_cFR_ = -2000; + + pt_cmssw_cFR_ = -99; + phi_cmssw_cFR_ = -99; + eta_cmssw_cFR_ = -99; + + nHits_cmssw_cFR_ = -99; + nLayers_cmssw_cFR_ = -99; + lastlyr_cmssw_cFR_ = -99; + + phi_cmssw_build_cFR_ = -99; + } + cmsswfrtree_->Fill(); + } } void TTreeValidation::saveTTrees() diff --git a/TTreeValidation.h b/TTreeValidation.h index 79a223150a0d1..4da20824d0290 100644 --- a/TTreeValidation.h +++ b/TTreeValidation.h @@ -42,7 +42,7 @@ class TTreeValidation : public Validation { void setTrackExtras(Event& ev) override; void makeSimTkToRecoTksMaps(Event& ev) override; - void mapSimTkToRecoTks(const TrackVec& evt_tracks, TrackExtraVec& evt_extras, TkIDToTkIDVecMap& simTkMap); + void mapRefTkToRecoTks(const TrackVec& evt_tracks, TrackExtraVec& evt_extras, TkIDToTkIDVecMap& refTkMap); void makeSeedTkToRecoTkMaps(Event& ev) override; void mapSeedTkToRecoTk(const TrackVec& evt_tracks, const TrackExtraVec& evt_extras, TkIDToTkIDMap& seedTkMap); void makeCMSSWTkToRecoTksMap(Event& ev) override; @@ -72,6 +72,9 @@ class TTreeValidation : public Validation { TkIDToTkIDMap seedToBuildMap_; TkIDToTkIDMap seedToFitMap_; + // CMSSW to Reco Maps + TkIDToTkIDVecMap cmsswToBuildMap_; + // Efficiency Tree TTree* efftree_; int evtID_eff_=0,mcID_eff_=0; @@ -164,10 +167,57 @@ class TTreeValidation : public Validation { // CMSSW Efficiency tree TTree* cmsswefftree_; + int evtID_ceff_=0,cmsswID_ceff_=0; + int seedID_cmssw_ceff_=0,seedID_build_ceff_=0; + int cmsswmask_build_ceff_=0; + + float x_cmssw_ceff_=0.,y_cmssw_ceff_=0.,z_cmssw_ceff_=0.; + float pt_cmssw_ceff_=0.,phi_cmssw_ceff_=0.,eta_cmssw_ceff_=0.; + int nHits_cmssw_ceff_=0,nLayers_cmssw_ceff_=0,lastlyr_cmssw_ceff_=0; + + float pt_build_ceff_=0.,ept_build_ceff_=0.; + float phi_build_ceff_=0.,ephi_build_ceff_=0.; + float eta_build_ceff_=0.,eeta_build_ceff_=0.; + + int nHits_build_ceff_=0,nLayers_build_ceff_=0,nHitsMatched_build_ceff_=0,lastlyr_build_ceff_=0; + float fracHitsMatched_build_ceff_=0; + + float xhit_build_ceff_=0.,yhit_build_ceff_=0.,zhit_build_ceff_=0.; + + // chi2 of tracks + phi swim + float hitchi2_build_ceff_=0.,helixchi2_build_ceff_=0.; + float phi_cmssw_build_ceff_=0.; + + int duplmask_build_ceff_=0,nTkMatches_build_ceff_=0; // CMSSW FakeRate tree TTree* cmsswfrtree_; + int evtID_cFR_=0,label_build_cFR_=0,cmsswID_build_cFR_=0; + int seedID_cmssw_cFR_=0,seedID_build_cFR_=0; + int cmsswmask_build_cFR_=0; + + float pt_build_cFR_=0.,ept_build_cFR_=0.; + float phi_build_cFR_=0.,ephi_build_cFR_=0.; + float eta_build_cFR_=0.,eeta_build_cFR_=0.; + + int nHits_build_cFR_=0,nLayers_build_cFR_=0,nHitsMatched_build_cFR_=0,lastlyr_build_cFR_=0; + float fracHitsMatched_build_cFR_=0; + + float xhit_build_cFR_=0.,yhit_build_cFR_=0.,zhit_build_cFR_=0.; + + // chi2 of tracks + float hitchi2_build_cFR_=0.,helixchi2_build_cFR_=0.; + + // for duplicate track matches + int duplmask_build_cFR_=0,iTkMatches_build_cFR_=0; + + float x_cmssw_cFR_=0.,y_cmssw_cFR_=0.,z_cmssw_cFR_=0.; + float pt_cmssw_cFR_=0.,phi_cmssw_cFR_=0.,eta_cmssw_cFR_=0.; + int nHits_cmssw_cFR_=0,nLayers_cmssw_cFR_=0,lastlyr_cmssw_cFR_=0; + + float phi_cmssw_build_cFR_=0.; + // Fit tree (for fine tuning z-phi windows and such --> MPlex Only TTree* fittree_; int ntotallayers_fit_=0,tkid_fit_=0,evtid_fit_=0; diff --git a/Track.cc b/Track.cc index ffa4f52ba5c4f..8885c6389761a 100644 --- a/Track.cc +++ b/Track.cc @@ -100,6 +100,8 @@ float Track::swimPhiToR(const float x0, const float y0) const // ID == -3 : reco track is a short fake (n eligible found reco hits matching single sim track below some threshold, and n eligible found reco hits below some threshold) --> TOYMC SIM SEEDS ONLY // ID == -4 : reco track never made it past its sim seed --> inefficient but not fake --> TOYMC SIM SEEDS ONLY // ID == -5 : reco track somehow has zero hits... unclear what to do with these... ---> CMSSW OR REAL SEEDS ONLY +// ID == -6 : reco track is long, and matched to sim track. however, simtrack is unfindable (enter denom of FR) +// ID == -7 : reco track is short, and matched to sim track. however, simtrack is unfindable (enter denom of FR for inclusive shorts) // More stringent requirement for matching --> used only for simtrack pure seeds void TrackExtra::setMCTrackIDInfoByLabel(const Track& trk, const std::vector& layerHits, const MCHitInfoVec& globalHitInfo) @@ -107,7 +109,7 @@ void TrackExtra::setMCTrackIDInfoByLabel(const Track& trk, const std::vector= nCandHits) mcTrackID_ = label; else mcTrackID_ = -1; - // Modify mcTrackID based on nMinHits + // Modify mcTrackID based on nMinHits if (nCandHits < (Config::nMinFoundHits-Config::nlayers_per_seed)) { - if (mcTrackID_ == label) mcTrackID_ = -2; - else mcTrackID_ = -3; + if (mcTrackID_ >= 0) mcTrackID_ = -2; + else mcTrackID_ = -3; } nHitsMatched_ = nHitsMatched; // nHitsMatched + Config::nlayers_per_seed @@ -202,21 +204,31 @@ void TrackExtra::setMCTrackIDInfo(const Track& trk, const std::vector& l } i = j; } - + // 75% matching criterion - if (4*mccount >= 3*trk.nFoundHits()) + if (4*mccount >= 3*trk.nFoundHits()) mcTrackID_ = mcTrackID; + else mcTrackID_ = -1; + + // Modify mcTrackID based on length of track (excluding seed tracks, of course + if (!isSeed) { - if (isSeed) mcTrackID_ = mcTrackID; - else + // Check for length + if (trk.nFoundHits() < Config::nMinFoundHits) { - const int nMinSimHits = simtracks[mcTrackID].nUniqueLayers() * Config::nMinSimHitsFrac; - const int minFoundHits = ((nMinSimHits >= Config::nMinFoundHits) ? Config::nMinFoundHits : nMinSimHits); - - if (trk.nFoundHits() >= minFoundHits) mcTrackID_ = mcTrackID; - else mcTrackID_ = -2; + if (mcTrackID_ >= 0) mcTrackID_ = -2; + else mcTrackID_ = -3; } - } - else mcTrackID_ = -1; + + // Modify mcTrackID based on if simtrack is findable + if (mcTrackID >= 0) + { + if (simtracks[mcTrackID].isNotFindable()) + { + if (mcTrackID_ >= 0) mcTrackID_ = -6; + else mcTrackID_ = -7; + } + } + } // end check over sedd nHitsMatched_ = mccount; fracHitsMatched_ = float(nHitsMatched_) / float(trk.nFoundHits()); @@ -232,6 +244,14 @@ void TrackExtra::setMCTrackIDInfo(const Track& trk, const std::vector& l dprint("Track " << trk.label() << " best mc track " << mcTrackID_ << " count " << mccount << "/" << trk.nFoundHits()); } +typedef std::pair idchi2Pair; +typedef std::vector idchi2PairVec; + +inline bool sortIDsByChi2(const idchi2Pair & cand1, const idchi2Pair & cand2) +{ + return cand1.second& layerHits, const TrackVec& cmsswtracks, const RedTrackVec& redcmsswtracks) { const SVector6 & trkParams = trk.parameters(); @@ -248,43 +268,72 @@ void TrackExtra::setCMSSWTrackIDInfo(const Track& trk, const std::vector trkErrsR[0][1] = trkErrs[3][5]; trkErrsR[1][0] = trkErrs[5][3]; - std::vector cands; + idchi2PairVec cands; for (auto&& redcmsswtrack : redcmsswtracks) { const float chi2 = computeHelixChi2(redcmsswtrack.parameters(),trkParamsR,trkErrsR,false); - if (chi2 < Config::minCMSSWMatchChi2) cands.push_back(redcmsswtrack.label()); + if (chi2 < Config::minCMSSWMatchChi2) cands.push_back(std::make_pair(redcmsswtrack.label(),chi2)); } - int best = -1; + float minchi2 = -1e6; + if (cands.size()>0) + { + std::sort(cands.begin(),cands.end(),sortIDsByChi2); + minchi2 = cands.front().second; + } + + int cmsswTrackID = -1; + int nHMatched = 0; float bestdPhi = Config::minCMSSWMatchdPhi; - for (auto cand : cands) // loop over possible cmssw tracks + for (auto&& cand : cands) // loop over possible cmssw tracks { - const auto & cmsswtrack = cmsswtracks[cand]; + const auto label = cand.first; + const auto & cmsswtrack = cmsswtracks[label]; const float diffPhi = std::abs(squashPhiGeneral(cmsswtrack.swimPhiToR(trk.x(),trk.y())-trk.momPhi())); if (diffPhi < bestdPhi) // check for best matched track by phi { - if (Config::applyCMSSWHitMatch) // check for nMatchedHits if applied + const HitLayerMap & hitLayerMap = redcmsswtracks[label].hitLayerMap(); + int matched = 0; + for (int ihit = 0; ihit < trk.nTotalHits(); ihit++) // loop over mkfit track hits { - const HitLayerMap & hitLayerMap = redcmsswtracks[cand].hitLayerMap(); - int matched = 0; - for (int ihit = Config::nlayers_per_seed; ihit < trk.nTotalHits(); ihit++) // loop over mkfit track hits + const int lyr = trk.getHitLyr(ihit); + const int idx = trk.getHitIdx(ihit); + + if (idx < 0 || !hitLayerMap.count(lyr)) continue; // skip if bad index or cmssw track does not have that layer + for (auto cidx : hitLayerMap.at(lyr)) // loop over hits in layer for the cmssw track { - const int lyr = trk.getHitLyr(ihit); - const int idx = trk.getHitIdx(ihit); - - if (idx < 0 || !hitLayerMap.count(lyr)) continue; // skip if bad index or cmssw track does not have that layer - for (auto cidx : hitLayerMap.at(lyr)) // loop over hits in layer for the cmssw track - { - if (cidx == idx) {matched++; break;} - } + if (cidx == idx) {matched++; break;} } - if (matched < Config::nCMSSWMatchHits) continue; } - bestdPhi = diffPhi; best = cand; + if (Config::applyCMSSWHitMatch && matched < (Config::nCMSSWMatchHitsAfterSeed+Config::nlayers_per_seed)) continue; // check for nMatchedHits if applied (in principle all seed hits should be found!) + bestdPhi = diffPhi; nHMatched = matched; cmsswTrackID = label; + } + } + + // set cmsswTrackID + cmsswTrackID_ = cmsswTrackID; + helixChi2_ = (cmsswTrackID_ >= 0 ? cands[cmsswTrackID_].second : minchi2); + + // Modify cmsswTrackID based on length + if (trk.nFoundHits() < Config::nMinFoundHits) + { + if (cmsswTrackID_ >= 0) cmsswTrackID_ = -2; + else cmsswTrackID_ = -3; + } + + // Modify cmsswTrackID based on if simtrack is findable + if (cmsswTrackID >= 0) + { + if (cmsswtracks[cmsswTrackID].isNotFindable()) + { + if (cmsswTrackID_ >= 0) cmsswTrackID_ = -6; + else cmsswTrackID_ = -7; } } - cmsswTrackID_ = best; + // other important info + nHitsMatched_ = nHMatched; + fracHitsMatched_ = float(nHitsMatched_) / float(trk.nFoundHits()); // seed hits may already be included! } //============================================================================== diff --git a/Track.h b/Track.h index 763857738edcd..1f64edf99ab34 100644 --- a/Track.h +++ b/Track.h @@ -473,13 +473,12 @@ class TrackExtra int mcTrackID() const {return mcTrackID_;} int nHitsMatched() const {return nHitsMatched_;} float fracHitsMatched() const {return fracHitsMatched_;} - int nLayersMatched() const {return nLayersMatched_;} - float fracLayersMatched() const {return fracLayersMatched_;} int seedID() const {return seedID_;} bool isDuplicate() const {return isDuplicate_;} int duplicateID() const {return duplicateID_;} - void setMCDuplicateInfo(int duplicateID, bool isDuplicate) {duplicateID_ = duplicateID; isDuplicate_ = isDuplicate;} + void setDuplicateInfo(int duplicateID, bool isDuplicate) {duplicateID_ = duplicateID; isDuplicate_ = isDuplicate;} int cmsswTrackID() const {return cmsswTrackID_;} + float helixChi2() const {return helixChi2_;} private: friend class Track; @@ -487,12 +486,11 @@ class TrackExtra int mcTrackID_; int nHitsMatched_; float fracHitsMatched_; - int nLayersMatched_; - float fracLayersMatched_; int seedID_; int duplicateID_; bool isDuplicate_; int cmsswTrackID_; + float helixChi2_; }; typedef std::vector TrackExtraVec; diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index cd578af3b8d15..629976f1427a2 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -800,7 +800,7 @@ void MkBuilder::remap_cand_hits() // Non-ROOT validation //------------------------------------------------------------------------------ -void MkBuilder::quality_output_BH() +void MkBuilder::quality_output() { quality_reset(); @@ -814,28 +814,12 @@ void MkBuilder::quality_output_BH() quality_print(); } -void MkBuilder::quality_output_COMB() -{ - quality_reset(); - - quality_store_tracks_COMB(); - - remap_cand_hits(); - - for (int i = 0; i < m_event->candidateTracks_.size(); i++) - { - quality_process(m_event->candidateTracks_[i]); - } - - quality_print(); -} - void MkBuilder::quality_reset() { m_cnt = m_cnt1 = m_cnt2 = m_cnt_8 = m_cnt1_8 = m_cnt2_8 = m_cnt_nomc = 0; } -void MkBuilder::quality_store_tracks_COMB() +void MkBuilder::quality_store_tracks() { const EventOfCombCandidates &eoccs = m_event_of_comb_cands; @@ -915,7 +899,7 @@ void MkBuilder::quality_print() // Root validation //------------------------------------------------------------------------------ -void MkBuilder::root_val_BH() +void MkBuilder::root_val() { // remap seed tracks remap_seed_hits(); @@ -923,72 +907,52 @@ void MkBuilder::root_val_BH() // get the tracks ready for validation remap_cand_hits(); m_event->fitTracks_ = m_event->candidateTracks_; // fixme: hack for now. eventually fitting will be including end-to-end - init_track_extras(); - align_recotracks(); + prep_recotracks(); + if (Config::readCmsswSeeds) m_event->clean_cms_simtracks(); m_event->Validate(); } -void MkBuilder::root_val_COMB() +void MkBuilder::cmssw_val() { - remap_seed_hits(); // prepare seed tracks for validation - // get the tracks ready for validation - quality_store_tracks_COMB(); remap_cand_hits(); - m_event->fitTracks_ = m_event->candidateTracks_; // fixme: hack for now. eventually fitting will be including end-to-end - init_track_extras(); - align_recotracks(); - - m_event->Validate(); -} + prep_recotracks(); -void MkBuilder::cmssw_val_BH() -{ prep_cmsswtracks(); - root_val_BH(); -} - -void MkBuilder::cmssw_val_COMB() -{ - prep_cmsswtracks(); - root_val_COMB(); + m_event->Validate(); } -void MkBuilder::init_track_extras() +void MkBuilder::prep_recotracks() { - for (int i = 0; i < m_event->seedTracks_.size(); i++) + prep_tracks(m_event->candidateTracks_,m_event->candidateTracksExtra_); + if (Config::root_val) { - m_event->seedTracksExtra_.emplace_back(m_event->seedTracks_[i].label()); + prep_tracks(m_event->seedTracks_,m_event->seedTracksExtra_); + prep_tracks(m_event->fitTracks_,m_event->fitTracksExtra_); } +} - for (int i = 0; i < m_event->candidateTracks_.size(); i++) - { - m_event->candidateTracksExtra_.emplace_back(m_event->candidateTracks_[i].label()); - } +void MkBuilder::prep_cmsswtracks() +{ + prep_tracks(m_event->extRecTracks_,m_event->extRecTracksExtra_); - for (int i = 0; i < m_event->fitTracks_.size(); i++) + // mark cmsswtracks as unfindable if too short + for (auto&& cmsswtrack : m_event->extRecTracks_) { - m_event->fitTracksExtra_.emplace_back(m_event->fitTracks_[i].label()); + const int nlyr = cmsswtrack.nUniqueLayers(); + if (nlyr < Config::cmsSelMinLayers || cmsswtrack.pT() < Config::cmsSelMinPt) cmsswtrack.setNotFindable(); } } -void MkBuilder::align_recotracks() +void MkBuilder::prep_tracks(TrackVec& tracks, TrackExtraVec& extras) { - m_event->validation_.alignTracks(m_event->seedTracks_,m_event->seedTracksExtra_,false); - m_event->validation_.alignTracks(m_event->candidateTracks_,m_event->candidateTracksExtra_,false); - m_event->validation_.alignTracks(m_event->fitTracks_,m_event->fitTracksExtra_,false); -} - -void MkBuilder::prep_cmsswtracks() -{ - for (int i = 0; i < m_event->extRecTracks_.size(); i++) + for (int i = 0; i < tracks.size(); i++) { - m_event->extRecTracks_[i].sortHitsByLayer(); - m_event->extRecTracksExtra_.emplace_back(m_event->extRecTracks_[i].label()); + tracks[i].sortHitsByLayer(); + extras.emplace_back(tracks[i].label()); } - - m_event->validation_.alignTracks(m_event->extRecTracks_,m_event->extRecTracksExtra_,false); + m_event->validation_.alignTracks(tracks,extras,false); } //------------------------------------------------------------------------------ diff --git a/mkFit/MkBuilder.h b/mkFit/MkBuilder.h index 39c30fe4c0632..c2573de797e2b 100644 --- a/mkFit/MkBuilder.h +++ b/mkFit/MkBuilder.h @@ -81,21 +81,18 @@ class MkBuilder void remap_seed_hits(); // m_event_of_hits.m_layers_of_hits -> m_event->layerHits_ (seeds only) void remap_cand_hits(); // m_event_of_hits.m_layers_of_hits -> m_event->layerHits_ (cands only) - void quality_output_BH(); - void quality_output_COMB(); + void quality_output(); void quality_reset(); void quality_process(Track& tkcand); void quality_print(); - void quality_store_tracks_COMB(); + void quality_store_tracks(); - void root_val_BH(); - void root_val_COMB(); - void cmssw_val_BH(); - void cmssw_val_COMB(); - void init_track_extras(); - void align_recotracks(); // ensure that all track collections have labels equal to index inside vector - void prep_cmsswtracks(); // ensure that cmssw rec tracks have the right labels and extras are good + void root_val(); + void cmssw_val(); + void prep_recotracks(); + void prep_cmsswtracks(); + void prep_tracks(TrackVec& tracks, TrackExtraVec& extras); // sort hits by layer, init track extras, align track labels // -------- diff --git a/mkFit/buildtestMPlex.cc b/mkFit/buildtestMPlex.cc index be7cdabe71ca4..d320cb28bafa5 100644 --- a/mkFit/buildtestMPlex.cc +++ b/mkFit/buildtestMPlex.cc @@ -110,11 +110,11 @@ double runBuildingTestPlexBestHit(Event& ev, MkBuilder& builder) #endif if (!Config::root_val && !Config::cmssw_val) { - if (!Config::silent) builder.quality_output_BH(); + if (!Config::silent) builder.quality_output(); } else if (Config::root_val) { - builder.root_val_BH(); + builder.root_val(); } else if (Config::cmssw_val) { - builder.cmssw_val_BH(); + builder.cmssw_val(); } builder.end_event(); @@ -150,12 +150,16 @@ double runBuildingTestPlexStandard(Event& ev, MkBuilder& builder) __SSC_MARK(0x222); // use this to pause Intel SDE at the same point #endif - if (!Config::root_val && !Config::cmssw_val) { - if (!Config::silent) builder.quality_output_COMB(); - } else if (Config::root_val) { - builder.root_val_COMB(); - } else if (Config::cmssw_val) { - builder.cmssw_val_COMB(); + if (!Config::silent) + { + builder.quality_store_tracks(); + if (!Config::root_val && !Config::cmssw_val) { + builder.quality_output(); + } else if (Config::root_val) { + builder.root_val(); + } else if (Config::cmssw_val) { + builder.cmssw_val(); + } } builder.end_event(); @@ -191,12 +195,16 @@ double runBuildingTestPlexCloneEngine(Event& ev, MkBuilder& builder) __SSC_MARK(0x222); // use this to pause Intel SDE at the same point #endif - if (!Config::root_val && !Config::cmssw_val) { - if (!Config::silent) builder.quality_output_COMB(); - } else if (Config::root_val) { - builder.root_val_COMB(); - } else if (Config::cmssw_val) { - builder.cmssw_val_COMB(); + if (!Config::silent) + { + builder.quality_store_tracks(); + if (!Config::root_val && !Config::cmssw_val) { + builder.quality_output(); + } else if (Config::root_val) { + builder.root_val(); + } else if (Config::cmssw_val) { + builder.cmssw_val(); + } } builder.end_event(); @@ -257,9 +265,9 @@ double runAllBuildingTestPlexBestHitGPU(std::vector &events) BuilderCU &builder_cu = builder_cu_vec[i]; MkBuilder &builder = * builder_ptrs[i].get(); if (!Config::root_val && !Config::cmssw_val) { - if (!Config::silent) builder.quality_output_BH(event_of_cands); + if (!Config::silent) builder.quality_output(); } else if (Config::root_val) { - builder.root_val_BH(event_of_cands); + builder.root_val(); } builder.end_event(); From db22c3e106583d98f3bc74fd21c167722704b0bd Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Fri, 4 Aug 2017 10:21:11 -0700 Subject: [PATCH 129/172] Full working version of cmssw validation with external reco tracks: * Validation macros updated to reuse code for cmssw validation * generated automatic validation script * updated old validation scripts to match new format of validation macros --- PlotValidation.cpp | 258 ++++++++++-------- PlotValidation.hh | 16 +- makeValidation.C | 16 +- runValidation.C | 15 +- ...on-snb-cmssw-fulldet-build-extrectracks.sh | 51 ++++ validation-snb-cmssw-fulldet-build.sh | 3 +- validation-snb-toymc-fulldet-build.sh | 8 +- 7 files changed, 223 insertions(+), 144 deletions(-) create mode 100755 validation-snb-cmssw-fulldet-build-extrectracks.sh diff --git a/PlotValidation.cpp b/PlotValidation.cpp index 2496113fef8f4..5f618fad9e07e 100644 --- a/PlotValidation.cpp +++ b/PlotValidation.cpp @@ -1,9 +1,8 @@ #include "PlotValidation.hh" -#include "TLegend.h" -PlotValidation::PlotValidation(TString inName, TString outName, +PlotValidation::PlotValidation(TString inName, TString outName, Bool_t computePulls, Bool_t cmsswComp, Bool_t mvInput, Bool_t saveAs, TString outType) - : fInName(inName), fOutName(outName), + : fInName(inName), fOutName(outName), fComputePulls(computePulls), fCmsswComp(cmsswComp), fMvInput(mvInput), fSaveAs(saveAs), fOutType(outType) { // ++++ Get Root File ++++ // @@ -65,18 +64,28 @@ void PlotValidation::Validation() { std::cout << "Computing Efficiency ..." << std::endl; PlotValidation::PlotEfficiency(); + std::cout << "Computing Inefficiency split in barrel and endcap..." << std::endl; PlotValidation::PlotInefficiencyVsGeom(); + std::cout << "Computing Fake Rate ..." << std::endl; PlotValidation::PlotFakeRate(); + std::cout << "Computing Duplicate Rate ..." << std::endl; PlotValidation::PlotDuplicateRate(); + std::cout << "Computing ..." << std::endl; PlotValidation::PlotNHits(); - std::cout << "Computing Momentum Pulls ..." << std::endl; - PlotValidation::PlotMomResolutionPull(); + + if (fComputePulls) + { + std::cout << "Computing Momentum Pulls ..." << std::endl; + PlotValidation::PlotMomResolutionPull(); + } + std::cout << "Printing Totals ..." << std::endl; PlotValidation::PrintTotals(); + if (fMvInput) { PlotValidation::MoveInput(); @@ -86,10 +95,11 @@ void PlotValidation::Validation() void PlotValidation::PlotEfficiency() { // Get tree - TTree * efftree = (TTree*)fInRoot->Get("efftree"); + TTree * efftree = (TTree*)fInRoot->Get((fCmsswComp?"cmsswefftree":"efftree")); // make output subdirectory and subdir in ROOT file, and cd to it. TString subdirname = "efficiency"; + if (fCmsswComp) subdirname+="_cmssw"; PlotValidation::MakeSubDirectory(subdirname); PlotValidation::MakeSubDirectory(Form("%s/lin",subdirname.Data())); PlotValidation::MakeSubDirectory(Form("%s/log",subdirname.Data())); @@ -97,15 +107,15 @@ void PlotValidation::PlotEfficiency() subdir->cd(); //Declare strings for branches and plots - TStrVec vars = {"pt","eta","phi"}; - TStrVec svars = {"p_{T}","#eta","#phi"}; // svars --> labels for histograms for given variable - TStrVec sunits= {" [GeV/c]","",""}; // units --> labels for histograms for given variable - IntVec nBins = {60,60,80}; - FltVec xlow = {0,-3,-4}; - FltVec xhigh = {15,3,4}; + const TStrVec vars = {"pt","eta","phi"}; + const TStrVec svars = {"p_{T}","#eta","#phi"}; // svars --> labels for histograms for given variable + const TStrVec sunits= {" [GeV/c]","",""}; // units --> labels for histograms for given variable + const IntVec nBins = {60,60,80}; + const FltVec xlow = {0,-3,-4}; + const FltVec xhigh = {15,3,4}; - TStrVec trks = {"seed","build","fit"}; - TStrVec strks = {"Seed","Build","Fit"}; // strk --> labels for histograms for given track type + const TStrVec trks = (fCmsswComp ? TStrVec{"build"} : TStrVec{"seed","build","fit"}); + const TStrVec strks = (fCmsswComp ? TStrVec{"Build"} : TStrVec{"Seed","Build","Fit"}); // strk --> labels for histograms for given track type // Floats/Ints to be filled for trees FltVec mcvars_val(vars.size()); // first index is var. only for mc values! so no extra index @@ -118,9 +128,9 @@ void PlotValidation::PlotEfficiency() varsEff[i].resize(trks.size()); for (UInt_t j = 0; j < trks.size(); j++) { - varsEff[i][j] = new TEfficiency(Form("eff_sim_%s_%s",vars[i].Data(),trks[j].Data()), - Form("%s Track Efficiency vs MC %s;%s%s;Efficiency", - strks[j].Data(),svars[i].Data(),svars[i].Data(),sunits[i].Data()), + varsEff[i][j] = new TEfficiency(Form("eff_%s_%s_%s",(fCmsswComp?"cmssw":"sim"),vars[i].Data(),trks[j].Data()), + Form("%s Track Efficiency vs %s %s;%s;Efficiency", + strks[j].Data(),(fCmsswComp?"CMSSW Reco":"MC"),svars[i].Data(),svars[i].Data(),sunits[i].Data()), nBins[i],xlow[i],xhigh[i]); } } @@ -132,14 +142,14 @@ void PlotValidation::PlotEfficiency() mcvars_val[i] = 0.; //Set var+trk branch - efftree->SetBranchAddress(Form("%s_mc_gen",vars[i].Data()),&(mcvars_val[i])); + efftree->SetBranchAddress(Form("%s_%s",vars[i].Data(),(fCmsswComp?"cmssw":"mc_gen")),&(mcvars_val[i])); } //Initialize masks, set branch addresses for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index { mcmask_trk[j] = 0; - efftree->SetBranchAddress(Form("mcmask_%s",trks[j].Data()),&(mcmask_trk[j])); + efftree->SetBranchAddress(Form("%smask_%s",(fCmsswComp?"cmssw":"mc"),trks[j].Data()),&(mcmask_trk[j])); } // Fill histos, compute eff from tree branches @@ -173,10 +183,11 @@ void PlotValidation::PlotEfficiency() void PlotValidation::PlotInefficiencyVsGeom() { // Get tree - TTree * efftree = (TTree*)fInRoot->Get("efftree"); + TTree * efftree = (TTree*)fInRoot->Get((fCmsswComp?"cmsswefftree":"efftree")); // make output subdirectory and subdir in ROOT file, and cd to it. TString subdirname = "inefficiency"; + if (fCmsswComp) subdirname+="_cmssw"; PlotValidation::MakeSubDirectory(subdirname); PlotValidation::MakeSubDirectory(Form("%s/lin",subdirname.Data())); PlotValidation::MakeSubDirectory(Form("%s/log",subdirname.Data())); @@ -184,18 +195,18 @@ void PlotValidation::PlotInefficiencyVsGeom() subdir->cd(); //Declare strings for branches and plots - TStrVec vars = {"pt","eta","phi"}; - TStrVec svars = {"p_{T}","#eta","#phi"}; // svars --> labels for histograms for given variable - TStrVec sunits= {" [GeV/c]","",""}; // units --> labels for histograms for given variable - IntVec nBins = {60,60,80}; - FltVec xlow = {0,-3,-4}; - FltVec xhigh = {15,3,4}; + const TStrVec vars = {"pt","eta","phi"}; + const TStrVec svars = {"p_{T}","#eta","#phi"}; // svars --> labels for histograms for given variable + const TStrVec sunits= {" [GeV/c]","",""}; // units --> labels for histograms for given variable + const IntVec nBins = {60,60,80}; + const FltVec xlow = {0,-3,-4}; + const FltVec xhigh = {15,3,4}; - TStrVec regs = {"barrel","endcap"}; - TStrVec sregs = {"Barrel","Endcap"}; + const TStrVec regs = {"barrel","endcap"}; + const TStrVec sregs = {"Barrel","Endcap"}; - TStrVec trks = {"seed","build","fit"}; - TStrVec strks = {"Seed","Build","Fit"}; // strk --> labels for histograms for given track type + const TStrVec trks = (fCmsswComp ? TStrVec{"build"} : TStrVec{"seed","build","fit"}); + const TStrVec strks = (fCmsswComp ? TStrVec{"Build"} : TStrVec{"Seed","Build","Fit"}); // strk --> labels for histograms for given track type // Floats/Ints to be filled for trees FltVec mcvars_val(vars.size()); // first index is var. only for mc values! so no extra index @@ -212,9 +223,9 @@ void PlotValidation::PlotInefficiencyVsGeom() for (UInt_t j = 0; j < trks.size(); j++) { // Efficiency - varsIneff[h][i][j] = new TEfficiency(Form("ineff_%s_sim_%s_%s",regs[h].Data(),vars[i].Data(),trks[j].Data()), - Form("%s Track Inefficiency vs MC %s %s;%s%s;Inefficiency", - strks[j].Data(),svars[i].Data(),sregs[h].Data(),svars[i].Data(),sunits[i].Data()), + varsIneff[h][i][j] = new TEfficiency(Form("ineff_%s_%s_%s_%s",regs[h].Data(),(fCmsswComp?"cmssw":"sim"),vars[i].Data(),trks[j].Data()), + Form("%s Track Inefficiency vs %s %s %s;%s%s;Inefficiency", + strks[j].Data(),(fCmsswComp?"CMSSW Reco":"MC"),svars[i].Data(),sregs[h].Data(),svars[i].Data(),sunits[i].Data()), nBins[i],xlow[i],xhigh[i]); } } @@ -227,14 +238,14 @@ void PlotValidation::PlotInefficiencyVsGeom() mcvars_val[i] = 0.; //Set var+trk branch - efftree->SetBranchAddress(Form("%s_mc_gen",vars[i].Data()),&(mcvars_val[i])); + efftree->SetBranchAddress(Form("%s_%s",vars[i].Data(),(fCmsswComp?"cmssw":"mc_gen")),&(mcvars_val[i])); } //Initialize masks, set branch addresses for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index { mcmask_trk[j] = 0; - efftree->SetBranchAddress(Form("mcmask_%s",trks[j].Data()),&(mcmask_trk[j])); + efftree->SetBranchAddress(Form("%smask_%s",(fCmsswComp?"cmssw":"mc"),trks[j].Data()),&(mcmask_trk[j])); } // Fill histos, compute eff from tree branches @@ -277,10 +288,11 @@ void PlotValidation::PlotInefficiencyVsGeom() void PlotValidation::PlotFakeRate() { // Get tree - TTree * frtree = (TTree*)fInRoot->Get("frtree"); + TTree * frtree = (TTree*)fInRoot->Get((fCmsswComp?"cmsswfrtree":"frtree")); // make output subdirectory and subdir in ROOT file, and cd to it. TString subdirname = "fakerate"; + if (fCmsswComp) subdirname+="_cmssw"; PlotValidation::MakeSubDirectory(subdirname); PlotValidation::MakeSubDirectory(Form("%s/lin",subdirname.Data())); PlotValidation::MakeSubDirectory(Form("%s/log",subdirname.Data())); @@ -288,15 +300,15 @@ void PlotValidation::PlotFakeRate() subdir->cd(); //Declare strings for branches and plots - TStrVec vars = {"pt","eta","phi"}; - TStrVec svars = {"p_{T}","#eta","#phi"}; // svars --> labels for histograms for given variable - TStrVec sunits= {" [GeV/c]","",""}; // units --> labels for histograms for given variable - IntVec nBins = {60,60,80}; - FltVec xlow = {0,-3,-4}; - FltVec xhigh = {15,3,4}; + const TStrVec vars = {"pt","eta","phi"}; + const TStrVec svars = {"p_{T}","#eta","#phi"}; // svars --> labels for histograms for given variable + const TStrVec sunits= {" [GeV/c]","",""}; // units --> labels for histograms for given variable + const IntVec nBins = {60,60,80}; + const FltVec xlow = {0,-3,-4}; + const FltVec xhigh = {15,3,4}; - TStrVec trks = {"seed","build","fit"}; - TStrVec strks = {"Seed","Build","Fit"}; // strk --> labels for histograms for given track type + const TStrVec trks = (fCmsswComp ? TStrVec{"build"} : TStrVec{"seed","build","fit"}); + const TStrVec strks = (fCmsswComp ? TStrVec{"Build"} : TStrVec{"Seed","Build","Fit"}); // strk --> labels for histograms for given track type // Floats/Ints to be filled for trees FltVecVec recovars_val(vars.size()); // first index is var, second is type of track @@ -339,7 +351,7 @@ void PlotValidation::PlotFakeRate() for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index { mcmask_trk[j] = 0; - frtree->SetBranchAddress(Form("mcmask_%s",trks[j].Data()),&(mcmask_trk[j])); + frtree->SetBranchAddress(Form("%smask_%s",(fCmsswComp?"cmssw":"mc"),trks[j].Data()),&(mcmask_trk[j])); } // Fill histos, compute fake rate from tree branches @@ -373,10 +385,11 @@ void PlotValidation::PlotFakeRate() void PlotValidation::PlotDuplicateRate() { // Get tree - TTree * efftree = (TTree*)fInRoot->Get("efftree"); + TTree * efftree = (TTree*)fInRoot->Get((fCmsswComp?"cmsswefftree":"efftree")); // make output subdirectory and subdir in ROOT file, and cd to it. - TString subdirname = "duplicaterate"; + TString subdirname = "duplicaterate"; + if (fCmsswComp) subdirname+="_cmssw"; PlotValidation::MakeSubDirectory(subdirname); PlotValidation::MakeSubDirectory(Form("%s/lin",subdirname.Data())); PlotValidation::MakeSubDirectory(Form("%s/log",subdirname.Data())); @@ -384,15 +397,15 @@ void PlotValidation::PlotDuplicateRate() subdir->cd(); //Declare strings for branches and plots - TStrVec vars = {"pt","eta","phi"}; - TStrVec svars = {"p_{T}","#eta","#phi"}; // svars --> labels for histograms for given variable - TStrVec sunits= {" [GeV/c]","",""}; // units --> labels for histograms for given variable - IntVec nBins = {60,60,80}; - FltVec xlow = {0,-3,-4}; - FltVec xhigh = {15,3,4}; + const TStrVec vars = {"pt","eta","phi"}; + const TStrVec svars = {"p_{T}","#eta","#phi"}; // svars --> labels for histograms for given variable + const TStrVec sunits= {" [GeV/c]","",""}; // units --> labels for histograms for given variable + const IntVec nBins = {60,60,80}; + const FltVec xlow = {0,-3,-4}; + const FltVec xhigh = {15,3,4}; - TStrVec trks = {"seed","build","fit"}; - TStrVec strks = {"Seed","Build","Fit"}; // strk --> labels for histograms for given track type + const TStrVec trks = (fCmsswComp ? TStrVec{"build"} : TStrVec{"seed","build","fit"}); + const TStrVec strks = (fCmsswComp ? TStrVec{"Build"} : TStrVec{"Seed","Build","Fit"}); // strk --> labels for histograms for given track type // Floats/Ints to be filled for trees FltVec mcvars_val(vars.size()); // first index is var. only for mc values! so no extra index @@ -407,9 +420,9 @@ void PlotValidation::PlotDuplicateRate() for (UInt_t j = 0; j < trks.size(); j++) { // Duplicate Rate - varsDR[i][j] = new TEfficiency(Form("dr_sim_%s_%s",vars[i].Data(),trks[j].Data()), - Form("%s Track Duplicate Rate vs MC %s;%s%s;Duplicate Rate", - strks[j].Data(),svars[i].Data(),svars[i].Data(),sunits[i].Data()), + varsDR[i][j] = new TEfficiency(Form("dr_%s_%s_%s",(fCmsswComp?"cmssw":"sim"),vars[i].Data(),trks[j].Data()), + Form("%s Track Duplicate Rate vs %s %s;%s%s;Duplicate Rate", + strks[j].Data(),(fCmsswComp?"CMSSW":"MC"),svars[i].Data(),svars[i].Data(),sunits[i].Data()), nBins[i],xlow[i],xhigh[i]); } } @@ -421,7 +434,7 @@ void PlotValidation::PlotDuplicateRate() mcvars_val[i] = 0.; //Set var+trk branch - efftree->SetBranchAddress(Form("%s_mc_gen",vars[i].Data()),&(mcvars_val[i])); + efftree->SetBranchAddress(Form("%s_%s",vars[i].Data(),(fCmsswComp?"cmssw":"mc_gen")),&(mcvars_val[i])); } //Initialize masks, set branch addresses @@ -430,7 +443,7 @@ void PlotValidation::PlotDuplicateRate() mcmask_trk[j] = 0; nTkMatches_trk[j] = 0; - efftree->SetBranchAddress(Form("mcmask_%s",trks[j].Data()),&(mcmask_trk[j])); + efftree->SetBranchAddress(Form("%smask_%s",(fCmsswComp?"cmssw":"mc"),trks[j].Data()),&(mcmask_trk[j])); efftree->SetBranchAddress(Form("nTkMatches_%s",trks[j].Data()),&(nTkMatches_trk[j])); } @@ -461,7 +474,7 @@ void PlotValidation::PlotDuplicateRate() { for (UInt_t j = 0; j < trks.size(); j++) { - PlotValidation::DrawWriteSaveTEffPlot(subdir,varsDR[i][j],subdirname,Form("fr_%s_%s",vars[i].Data(),trks[j].Data())); + PlotValidation::DrawWriteSaveTEffPlot(subdir,varsDR[i][j],subdirname,Form("dr_%s_%s",vars[i].Data(),trks[j].Data())); delete varsDR[i][j]; } } @@ -471,10 +484,11 @@ void PlotValidation::PlotDuplicateRate() void PlotValidation::PlotNHits() { // Get tree --> can do this all with fake rate tree - TTree * frtree = (TTree*)fInRoot->Get("frtree"); + TTree * frtree = (TTree*)fInRoot->Get((fCmsswComp?"cmsswfrtree":"frtree")); // make output subdirectory and subdir in ROOT file, and cd to it. TString subdirname = "nHits"; + if (fCmsswComp) subdirname+="_cmssw"; PlotValidation::MakeSubDirectory(subdirname); PlotValidation::MakeSubDirectory(Form("%s/lin",subdirname.Data())); PlotValidation::MakeSubDirectory(Form("%s/log",subdirname.Data())); @@ -482,10 +496,10 @@ void PlotValidation::PlotNHits() subdir->cd(); //Declare strings for branches and plots - TStrVec trks = {"seed","build","fit"}; - TStrVec strks = {"Seed","Build","Fit"}; // strk --> labels for histograms for given track type - TStrVec coll = {"allreco","fake","allmatch","bestmatch"}; - TStrVec scoll = {"All Reco","Fake","All Match","Best Match"}; + const TStrVec trks = (fCmsswComp ? TStrVec{"build"} : TStrVec{"seed","build","fit"}); + const TStrVec strks = (fCmsswComp ? TStrVec{"Build"} : TStrVec{"Seed","Build","Fit"}); // strk --> labels for histograms + const TStrVec coll = {"allreco","fake","allmatch","bestmatch"}; + const TStrVec scoll = {"All Reco","Fake","All Match","Best Match"}; // Floats/Ints to be filled for trees IntVec nHits_trk(trks.size()); @@ -493,7 +507,6 @@ void PlotValidation::PlotNHits() // masks IntVec mcmask_trk(trks.size()); // need to know if sim track associated to a given reco track type - IntVec seedmask_trk(trks.size()); // need to know if reco track associated to a seed track IntVec iTkMatches_trk(trks.size()); // Create plots @@ -526,13 +539,11 @@ void PlotValidation::PlotNHits() for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index { mcmask_trk[j] = 0; - seedmask_trk[j] = 0; iTkMatches_trk[j] = 0; nHits_trk[j] = 0; fracHitsMatched_trk[j] = 0; - frtree->SetBranchAddress(Form("mcmask_%s",trks[j].Data()),&(mcmask_trk[j])); - frtree->SetBranchAddress(Form("seedmask_%s",trks[j].Data()),&(seedmask_trk[j])); + frtree->SetBranchAddress(Form("%smask_%s",(fCmsswComp?"cmssw":"mc"),trks[j].Data()),&(mcmask_trk[j])); frtree->SetBranchAddress(Form("iTkMatches_%s",trks[j].Data()),&(iTkMatches_trk[j])); frtree->SetBranchAddress(Form("nHits_%s",trks[j].Data()),&(nHits_trk[j])); frtree->SetBranchAddress(Form("fracHitsMatched_%s",trks[j].Data()),&(fracHitsMatched_trk[j])); @@ -548,15 +559,12 @@ void PlotValidation::PlotNHits() { if (c == 0) // all reco { - if (seedmask_trk[j] == 1) // includes all the short tracks, too (including zero size tracks!!!) - { - nHitsPlot[j][c]->Fill(nHits_trk[j]); - fracHitsMatchedPlot[j][c]->Fill(fracHitsMatched_trk[j]); - } + nHitsPlot[j][c]->Fill(nHits_trk[j]); + fracHitsMatchedPlot[j][c]->Fill(fracHitsMatched_trk[j]); } else if (c == 1) // all fakes { - if ((seedmask_trk[j] == 1) && (mcmask_trk[j] == 0)) + if (mcmask_trk[j] == 0) { nHitsPlot[j][c]->Fill(nHits_trk[j]); fracHitsMatchedPlot[j][c]->Fill(fracHitsMatched_trk[j]); @@ -564,7 +572,7 @@ void PlotValidation::PlotNHits() } else if (c == 2) // all matches { - if ((seedmask_trk[j] == 1) && (mcmask_trk[j] == 1)) + if (mcmask_trk[j] == 1) { nHitsPlot[j][c]->Fill(nHits_trk[j]); fracHitsMatchedPlot[j][c]->Fill(fracHitsMatched_trk[j]); @@ -572,7 +580,7 @@ void PlotValidation::PlotNHits() } else if (c == 3) // best matches only { - if ((seedmask_trk[j] == 1) && (mcmask_trk[j] == 1) && (iTkMatches_trk[j] == 0)) + if ((mcmask_trk[j] == 1) && (iTkMatches_trk[j] == 0)) { nHitsPlot[j][c]->Fill(nHits_trk[j]); fracHitsMatchedPlot[j][c]->Fill(fracHitsMatched_trk[j]); @@ -601,10 +609,11 @@ void PlotValidation::PlotNHits() void PlotValidation::PlotMomResolutionPull() { // Get tree - TTree * efftree = (TTree*)fInRoot->Get("efftree"); + TTree * efftree = (TTree*)fInRoot->Get("efftree"); // make output subdirectory and subdir in ROOT file, and cd to it. TString subdirname = "momentum_resolutionpull"; + if (fCmsswComp) subdirname+="_cmssw"; PlotValidation::MakeSubDirectory(subdirname); PlotValidation::MakeSubDirectory(Form("%s/lin",subdirname.Data())); PlotValidation::MakeSubDirectory(Form("%s/log",subdirname.Data())); @@ -612,21 +621,21 @@ void PlotValidation::PlotMomResolutionPull() subdir->cd(); //Declare strings for branches and plots - TStrVec vars = {"pt","eta","phi"}; - TStrVec evars = {"ept","eeta","ephi"}; - TStrVec svars = {"p_{T}","#eta","#phi"}; // svars --> labels for histograms for given variable - TStrVec sunits = {" [GeV/c]","",""}; // units --> labels for histograms for given variable - IntVec nBinsRes = {100,100,100}; - FltVec xlowRes = {-0.5,-0.5,-0.5}; - FltVec xhighRes = {0.5,0.5,0.5}; - FltVec gausRes = {0.3,0.3,0.3}; // symmetric bounds for gaussian fit - IntVec nBinsPull = {100,100,100}; - FltVec xlowPull = {-5,-5,-5}; - FltVec xhighPull = {5,5,5}; - FltVec gausPull = {3,3,3}; // symmetric bounds for gaussian fit - - TStrVec trks = {"seed","build","fit"}; - TStrVec strks = {"Seed","Build","Fit"}; // strk --> labels for histograms for given track type + const TStrVec vars = {"pt","eta","phi"}; + const TStrVec evars = {"ept","eeta","ephi"}; + const TStrVec svars = {"p_{T}","#eta","#phi"}; // svars --> labels for histograms for given variable + const TStrVec sunits = {" [GeV/c]","",""}; // units --> labels for histograms for given variable + const IntVec nBinsRes = {100,100,100}; + const FltVec xlowRes = {-0.5,-0.5,-0.5}; + const FltVec xhighRes = {0.5,0.5,0.5}; + const FltVec gausRes = {0.3,0.3,0.3}; // symmetric bounds for gaussian fit + const IntVec nBinsPull = {100,100,100}; + const FltVec xlowPull = {-5,-5,-5}; + const FltVec xhighPull = {5,5,5}; + const FltVec gausPull = {3,3,3}; // symmetric bounds for gaussian fit + + const TStrVec trks = {"seed","build","fit"}; + const TStrVec strks = {"Seed","Build","Fit"}; // strk --> labels for histograms for given track type // Floats/Ints to be filled for trees FltVecVec mcvars_val(vars.size()); @@ -735,14 +744,14 @@ void PlotValidation::PrintTotals() // want to print out totals of nHits, fraction of Hits shared, efficiency, fake rate, duplicate rate of seeds, build, fit // --> numer/denom plots for phi, know it will be in the bounds. - TStrVec trks = {"seed","build","fit"}; - TStrVec strks = {"Seed","Build","Fit"}; - TStrVec rates = {"eff","fr","dr"}; - TStrVec srates = {"Efficiency","Fake Rate","Duplicate Rate"}; - TStrVec rateSD = {"efficiency","fakerate","duplicaterate"}; - TStrVec snumer = {"Sim Tracks Matched","Unmatched Reco Tracks","Sim Tracks Matched (nTimes>1)"}; - TStrVec sdenom = {"Eligible Sim Tracks","Eligible Reco Tracks","Eligible Sim Tracks"}; - TStrVec types = {"sim","reco","sim"}; // types will be same size as rates! + const TStrVec trks = (fCmsswComp ? TStrVec{"build"} : TStrVec{"seed","build","fit"}); + const TStrVec strks = (fCmsswComp ? TStrVec{"Build"} : TStrVec{"Seed","Build","Fit"}); // strk --> labels for histograms for given track type + const TStrVec rates = {"eff","fr","dr"}; + const TStrVec srates = {"Efficiency","Fake Rate","Duplicate Rate"}; + const TStrVec rateSD = {"efficiency","fakerate","duplicaterate"}; + const TStrVec snumer = {Form("%s Tracks Matched",(fCmsswComp?"CMSSW":"Sim")),"Unmatched Reco Tracks",Form("%s Tracks Matched (nTimes>1)",(fCmsswComp?"CMSSW":"Sim"))}; + const TStrVec sdenom = {Form("Eligible %s Tracks",(fCmsswComp?"CMSSW":"Sim")),"Eligible Reco Tracks",Form("Eligible %s Tracks",(fCmsswComp?"CMSSW":"Sim"))}; + const TStrVec types = (fCmsswComp ? TStrVec{"cmssw","reco","cmssw"} : TStrVec{"sim","reco","sim"}); // types will be same size as rates! TEffRefVecVec phiRate(trks.size()); for (UInt_t j = 0; j < trks.size(); j++) @@ -750,13 +759,13 @@ void PlotValidation::PrintTotals() phiRate[j].resize(rates.size()); for (UInt_t r = 0; r < rates.size(); r++) { - phiRate[j][r] = (TEfficiency*) fOutRoot->Get(Form("%s/%s_%s_phi_%s",rateSD[r].Data(),rates[r].Data(),types[r].Data(),trks[j].Data())); + phiRate[j][r] = (TEfficiency*) fOutRoot->Get(Form("%s%s/%s_%s_phi_%s",rateSD[r].Data(),(fCmsswComp?"_cmssw":""),rates[r].Data(),types[r].Data(),trks[j].Data())); } } // want nHits plots for all types of tracks - TStrVec coll = {"allreco","fake","bestmatch"}; - TStrVec scoll = {"All Reco","Fake","Best Match"}; + const TStrVec coll = {"allreco","fake","bestmatch"}; + const TStrVec scoll = {"All Reco","Fake","Best Match"}; TH1FRefVecVec nHitsPlot(trks.size()); TH1FRefVecVec fracHitsMatchedPlot(trks.size()); @@ -770,27 +779,38 @@ void PlotValidation::PrintTotals() { for (UInt_t c = 0; c < coll.size(); c++) { - nHitsPlot[j][c] = (TH1F*) fOutRoot->Get(Form("nHits/h_nHits_%s_%s",coll[c].Data(),trks[j].Data())); - fracHitsMatchedPlot[j][c] = (TH1F*) fOutRoot->Get(Form("nHits/h_fracHitsMatched_%s_%s",coll[c].Data(),trks[j].Data())); + nHitsPlot[j][c] = (TH1F*) fOutRoot->Get(Form("nHits%s/h_nHits_%s_%s",(fCmsswComp?"_cmssw":""),coll[c].Data(),trks[j].Data())); + fracHitsMatchedPlot[j][c] = (TH1F*) fOutRoot->Get(Form("nHits%s/h_fracHitsMatched_%s_%s",(fCmsswComp?"_cmssw":""),coll[c].Data(),trks[j].Data())); } } - ofstream totalsout; - totalsout.open(Form("%s/totals_%s.txt",fOutName.Data(),fOutName.Data())); - - TTree * configtree = (TTree*)fInRoot->Get("configtree"); - Int_t Ntracks = 0, Nevents = 0; - configtree->SetBranchAddress("Nevents",&Nevents); - configtree->SetBranchAddress("Ntracks",&Ntracks); - configtree->GetEntry(0); + TString outfilename = Form("%s/totals_%s",fOutName.Data(),fOutName.Data()); + if (fCmsswComp) outfilename += "_cmssw"; + outfilename += ".txt"; + std::ofstream totalsout; + totalsout.open(outfilename.Data()); + + TTree * efftree = (TTree*)fInRoot->Get((fCmsswComp?"cmsswefftree":"efftree")); + TTree * frtree = (TTree*)fInRoot->Get((fCmsswComp?"cmsswfrtree":"frtree")); + Int_t Nevents = 0; + Int_t evtID = 0; efftree->SetBranchAddress("evtID",&evtID); + for (Int_t i = 0; i < efftree->GetEntries(); i++) + { + efftree->GetEntry(i); + if (evtID > Nevents) Nevents = evtID; + } + const Int_t NtracksMC = efftree->GetEntries(); + const Float_t ntkspevMC = Float_t(NtracksMC) / Float_t(Nevents); + const Int_t NtracksReco = frtree->GetEntries(); + const Float_t ntkspevReco = Float_t(NtracksReco) / Float_t(Nevents); std::cout << "--------Track Reconstruction Summary--------" << std::endl; - std::cout << "nEvents: " << Nevents << " nTracks/evt: " << Ntracks << std::endl; + std::cout << "nEvents: " << Nevents << Form(" n%sTracks/evt: ",(fCmsswComp?"CMSSW":"MC")) << ntkspevMC << " nRecoTracks/evt: " << ntkspevReco << std::endl; std::cout << "++++++++++++++++++++++++++++++++++++++++++++" << std::endl; std::cout << std::endl; totalsout << "--------Track Reconstruction Summary--------" << std::endl; - totalsout << "nEvents: " << Nevents << " nTracks/evt: " << Ntracks << std::endl; + totalsout << "nEvents: " << Nevents << Form(" n%sTracks/evt: ",(fCmsswComp?"CMSSW":"MC")) << ntkspevMC << " nRecoTracks/evt: " << ntkspevReco << std::endl; totalsout << "++++++++++++++++++++++++++++++++++++++++++++" << std::endl; totalsout << std::endl; @@ -850,7 +870,9 @@ void PlotValidation::PrintTotals() } totalsout.close(); - delete configtree; + + delete frtree; + delete efftree; } void PlotValidation::MakeSubDirectory(const TString subdirname) diff --git a/PlotValidation.hh b/PlotValidation.hh index 45ad6caa45eb4..235b6e55d945d 100644 --- a/PlotValidation.hh +++ b/PlotValidation.hh @@ -12,9 +12,11 @@ #include "TStyle.h" #include "TDirectory.h" #include "TColor.h" +#include "TLegend.h" #include #include +#include #include #include @@ -53,7 +55,7 @@ struct EffStruct class PlotValidation { public: - PlotValidation(TString inName, TString outName, + PlotValidation(TString inName, TString outName, Bool_t computePulls, Bool_t cmsswComp, Bool_t mvInput, Bool_t saveAs, TString outType); ~PlotValidation(); void Validation(); @@ -81,11 +83,13 @@ public: void MoveInput(); private: - TString fInName; - TFile * fInRoot; - Bool_t fMvInput; - Bool_t fSaveAs; - TString fOutType; + const TString fInName; + TFile * fInRoot; + const Bool_t fComputePulls; + const Bool_t fCmsswComp; + const Bool_t fMvInput; + const Bool_t fSaveAs; + const TString fOutType; TString fOutName; TFile * fOutRoot; TCanvas * fTEffCanv; diff --git a/makeValidation.C b/makeValidation.C index ac262a98ce39a..926e95c07f391 100644 --- a/makeValidation.C +++ b/makeValidation.C @@ -10,7 +10,7 @@ #include -void makeValidation(TString label = "") +void makeValidation(TString label = "", const Bool_t cmsswComp = false) { gStyle->SetOptStat(0); @@ -18,18 +18,24 @@ void makeValidation(TString label = "") TFile * f_std = TFile::Open(Form("validation_%s_STD/plots.root",label.Data())); TFile * f_ce = TFile::Open(Form("validation_%s_CE/plots.root",label.Data())); + const TString ref = (cmsswComp?"cmssw":"sim"); + std::vector dirs; dirs.push_back("efficiency"); dirs.push_back("inefficiency"); dirs.push_back("inefficiency"); dirs.push_back("fakerate"); dirs.push_back("duplicaterate"); + if (cmsswComp) + { + for (UInt_t i = 0; i < dirs.size(); i++) dirs[i] += "_cmssw"; + } std::vector sORr; - sORr.push_back("sim"); - sORr.push_back("sim"); - sORr.push_back("sim"); + sORr.push_back(ref); + sORr.push_back(ref); + sORr.push_back(ref); sORr.push_back("reco"); - sORr.push_back("sim"); + sORr.push_back(ref); std::vector rates; rates.push_back("eff"); rates.push_back("ineff_barrel"); diff --git a/runValidation.C b/runValidation.C index eb6f9f22c5711..463ce70a916ff 100644 --- a/runValidation.C +++ b/runValidation.C @@ -15,8 +15,8 @@ void setupcpp11() gSystem->SetMakeExe(o.Data()); } -void runValidation(TString test = "", Bool_t mvInput = true, - Bool_t saveAs = false, TString image = "pdf") +void runValidation(TString test = "", Bool_t computePulls = false, Bool_t cmsswComp = false, + Bool_t mvInput = true, Bool_t saveAs = false, TString image = "pdf") { setupcpp11(); // use this to get PlotValidation to compile ... phiphi ROOT build has ACLiC with C++98! @@ -24,12 +24,13 @@ void runValidation(TString test = "", Bool_t mvInput = true, // PlotValidation arguments // First is additional input name of root file - // Second is output name of directory/rootfile/file plots - // The first boolean argument == true to move input root file to output directory, false to keep input file where it is. - // Main validation includes efficiencies, fake rates, duplicate rates. Also momentum pulls, nHits plots, timing plots. - // Second Bool is saving the image files + // Second is name of output directory + // First boolean argument is to compute momentum pulls: currently implemented only when sim track states are available! + // Second boolean argument is to do special CMSSW validation + // The third boolean argument == true to move input root file to output directory, false to keep input file where it is. + // Fourth Bool is saving the image files // Last argument is output type of plots - PlotValidation Val(Form("valtree%s.root",test.Data()),Form("validation%s",test.Data()),mvInput,saveAs,image); + PlotValidation Val(Form("valtree%s.root",test.Data()),Form("validation%s",test.Data()),computePulls,cmsswComp,mvInput,saveAs,image); Val.Validation(); } diff --git a/validation-snb-cmssw-fulldet-build-extrectracks.sh b/validation-snb-cmssw-fulldet-build-extrectracks.sh new file mode 100755 index 0000000000000..a2878bde5e5f2 --- /dev/null +++ b/validation-snb-cmssw-fulldet-build-extrectracks.sh @@ -0,0 +1,51 @@ +#! /bin/bash + +make -j 12 WITH_ROOT=yes + +dir=/data/nfsmic/slava77/samples/2017/pass-4874f28/initialStep +file=memoryFile.fv3.recT.072617.bin + +ECN2=${dir}/10muEta-24to-17Pt1to10/${file} +ECN1=${dir}/10muEta-175to-055Pt1to10/${file} +BRL=${dir}/10muEtaLT06Pt1to10/${file} +ECP1=${dir}/10muEta055to175Pt1to10/${file} +ECP2=${dir}/10muEta17to24Pt1to10/${file} + +base=SNB_CMSSW_10mu + +for section in ECN2 ECN1 BRL ECP1 ECP2 +do + for bV in "BH bh" "STD std" "CE ce" + do echo $bV | while read -r bN bO + do + oBase=${base}_${section}_${bN} + echo "${oBase}: validation [nTH:24, nVU:8]" + ./mkFit/mkFit --cmssw-seeds --geom CMS-2017 --cmssw-val --ext-rec-tracks --read --file-name ${!section} --build-${bO} --num-thr 24 >& log_${oBase}_NVU8int_NTH24_cmsswval.txt + mv valtree.root valtree_${oBase}.root + done + done +done + +make clean + +for section in ECN2 ECN1 BRL ECP1 ECP2 +do + oBase=${base}_${section} + for build in BH STD CE + do + root -b -q -l runValidation.C\(\"_${oBase}_${build}\",0,1\) + done + root -b -q -l makeValidation.C\(\"${oBase}\",1\) +done + +for build in BH STD CE +do + oBase=${base} + fBase=valtree_${oBase} + dBase=validation_${oBase} + hadd ${fBase}_FullDet_${build}.root `for section in ECN2 ECN1 BRL ECP1 ECP2; do echo -n ${dBase}_${section}_${build}/${fBase}_${section}_${build}.root" "; done` + root -b -q -l runValidation.C\(\"_${oBase}_FullDet_${build}\",0,1\) +done +root -b -q -l makeValidation.C\(\"${oBase}_FullDet\",1\) + +make distclean diff --git a/validation-snb-cmssw-fulldet-build.sh b/validation-snb-cmssw-fulldet-build.sh index 71a14cebc80a3..eea31fe42c753 100755 --- a/validation-snb-cmssw-fulldet-build.sh +++ b/validation-snb-cmssw-fulldet-build.sh @@ -1,6 +1,5 @@ #! /bin/bash -make distclean make -j 12 WITH_ROOT=yes dir=/data/nfsmic/slava77/samples/2017/pass-4874f28/initialStep @@ -24,7 +23,7 @@ do echo $sV | while read -r sN sO do oBase=${base}_${sN}_${section}_${bN} echo "${oBase}: validation [nTH:24, nVU:8]" - ./mkFit/mkFit ${sO} --geom CMS-2017 --root-val --read --file-name ${!section} --build-${bO} ${sO} --num-thr 24 >& log_${oBase}_NVU8int_NTH24_val.txt + ./mkFit/mkFit ${sO} --geom CMS-2017 --root-val --read --file-name ${!section} --build-${bO} --num-thr 24 >& log_${oBase}_NVU8int_NTH24_val.txt mv valtree.root valtree_${oBase}.root done done diff --git a/validation-snb-toymc-fulldet-build.sh b/validation-snb-toymc-fulldet-build.sh index c68a5d1f772b6..636cebee83e2a 100755 --- a/validation-snb-toymc-fulldet-build.sh +++ b/validation-snb-toymc-fulldet-build.sh @@ -1,8 +1,6 @@ #! /bin/bash -sed -i 's/#WITH_ROOT := yes/WITH_ROOT := yes/g' Makefile.config - -make -j 12 +make -j 12 WITH_ROOT=yes dir=/data/nfsmic/scratch/toymc @@ -16,11 +14,9 @@ echo "SNB ToyMC CE (FullDet): validation [nTH:24, nVU:8]" ./mkFit/mkFit --root-val --read --file-name ${dir}/simtracks_fulldet_400x2p5k_val.bin --build-ce --num-thr 24 >& log_SNB_ToyMC_FullDet_CE_NVU8int_NTH24_val.txt mv valtree.root valtree_SNB_ToyMC_FullDet_CE.root -sed -i 's/WITH_ROOT := yes/#WITH_ROOT := yes/g' Makefile.config - for build in BH STD CE do - root -b -q -l runValidation.C\(\"_SNB_ToyMC_FullDet_${build}\"\) + root -b -q -l runValidation.C\(\"_SNB_ToyMC_FullDet_${build}\",1\) done root -b -q -l makeValidation.C\(\"SNB_ToyMC_FullDet\"\) From 375eadb0c3044ccb690530e5fb1b418a17057cf4 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Sat, 5 Aug 2017 06:52:29 -0700 Subject: [PATCH 130/172] add Track::invpT --- Track.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Track.h b/Track.h index 152560b7c946a..c0d42725a14d1 100644 --- a/Track.h +++ b/Track.h @@ -171,6 +171,7 @@ class Track float py() const { return state_.py();} float pz() const { return state_.pz();} float pT() const { return state_.pT();} + float invpT() const { return state_.invpT();} float p() const { return state_.p(); } float momPhi() const { return state_.momPhi(); } float momEta() const { return state_.momEta(); } From 6d99d7a08e8b3593b72ce534683228f4e58b96dd Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Sat, 5 Aug 2017 06:53:34 -0700 Subject: [PATCH 131/172] trim the set of nTH; do not benchmark sim with PU (commented out) --- benchmarkMIC-build.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/benchmarkMIC-build.sh b/benchmarkMIC-build.sh index e2fcd0e6862e1..5a8142c745284 100755 --- a/benchmarkMIC-build.sh +++ b/benchmarkMIC-build.sh @@ -5,10 +5,11 @@ fin=${BIN_DATA_PATH}/PU70/10224.0_TTbar_13+TTbar_13TeV_TuneCUETP8M1_2017PU_GenSi runBenchmark() { - for sV in "sim " "see --cmssw-seeds"; do echo $sV | while read -r sN sO; do +# for sV in "sim " "see --cmssw-seeds"; do echo $sV | while read -r sN sO; do + for sV in "see --cmssw-seeds"; do echo $sV | while read -r sN sO; do for bV in "BH bh" "STD std" "CE ce"; do echo $bV | while read -r bN bO; do oBase=${base}_${sN}_${bN} - for nTH in 1 2 4 8 12 16 24 32; do + for nTH in 1 4 8 16 32; do echo "${oBase}: benchmark [nTH:${nTH}, nVU:8]" time ./mkFit/mkFit --geom CMS-2017 --read --file-name ${fin} --build-${bO} ${sO} --num-thr ${nTH} >& log_${oBase}_NVU8int_NTH${nTH}_benchmark.txt done From c5a09f1f1e49310414bc804c32ec413a900709da Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Sat, 5 Aug 2017 06:55:10 -0700 Subject: [PATCH 132/172] dprint XX bad track idx message in quality_process --- mkFit/MkBuilder.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index 13f4d028aabf0..7c7b23baa13f7 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -873,7 +873,7 @@ void MkBuilder::quality_process(Track &tkcand) if (mctrk < 0 || mctrk >= m_event->simTracks_.size()) { ++m_cnt_nomc; - std::cout << "XX bad track idx " << mctrk << ", orig label was " << tkcand.label() << "\n"; + dprint("XX bad track idx " << mctrk << ", orig label was " << tkcand.label()); } else { From 417b67bf5c8d01c1bdd065fda51cc737e1a68d11 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Sat, 5 Aug 2017 06:56:02 -0700 Subject: [PATCH 133/172] faster clean_cms_seedtracks --- Event.cc | 67 +++++++++++++++++++++++++++++--------------------------- Event.h | 2 +- 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/Event.cc b/Event.cc index 063149ee0076f..119fb9d5c2099 100644 --- a/Event.cc +++ b/Event.cc @@ -508,9 +508,8 @@ void Event::read_in(DataFile &data_file, FILE *in_fp) ns = -ns; } #ifdef CLEAN_SEEDS - TrackVec mySeedTracks = clean_cms_seedtracks(); - seedTracks_ = mySeedTracks; - ns = seedTracks_.size(); + + ns = clean_cms_seedtracks();//operates on seedTracks_; returns the number of cleaned seeds #endif #ifdef DUMP_SEEDS printf("Read %i seedtracks (neg value means actual reading was skipped)\n", ns); @@ -679,65 +678,69 @@ void Event::print_tracks(const TrackVec& tracks, bool print_hits) const } } -TrackVec Event::clean_cms_seedtracks() +int Event::clean_cms_seedtracks() { - double maxDR = Config::maxDR_seedclean; + double maxDR2 = Config::maxDR_seedclean*Config::maxDR_seedclean; int minNHits = Config::minNHits_seedclean; int ns = seedTracks_.size(); TrackVec cleanSeedTracks; - std::vector writetrack; - for(int ts=0; ts writetrack(ns, true); + + const float invR1GeV = 1.f/Config::track1GeVradius; for(int ts=0; ts maxDR2 ) continue; - double thisDXY = 0.5*sqrt( (track_first.x()-track_second.x())*(track_first.x()-track_second.x()) + (track_first.y()-track_second.y())*(track_first.y()-track_second.y()) ); - double pos_first = sqrt(track_first.x()*track_first.x() + track_first.y()*track_first.y()); - double pos_second = sqrt(track_second.x()*track_second.x() + track_second.y()*track_second.y()); + const float pos2_second = std::pow(track_second.x(), 2) + std::pow(track_second.y(), 2); + const float thisDXYSign05 = pos2_second > pos2_first ? -0.5f : 0.5f; - if( pos_second > pos_first ) - thisDXY*=-1; + const float thisDXY = thisDXYSign05*sqrt( std::pow(track_first.x()-track_second.x(), 2) + + std::pow(track_first.y()-track_second.y(), 2) ); - double oldPhi1 = track_first.momPhi(); - double oldPhi2 = track_second.momPhi(); + const float oldPhi2 = track_second.momPhi(); + const float invptq_second = track_second.charge()*track_second.invpT(); - double newPhi1 = oldPhi1-thisDXY/(Config::track1GeVradius)/track_first.pT()*track_first.charge(); - double newPhi2 = oldPhi2+thisDXY/(Config::track1GeVradius)/track_second.pT()*track_second.charge(); + const float newPhi1 = oldPhi1-thisDXY*invR1GeV*invptq_first; + const float newPhi2 = oldPhi2+thisDXY*invR1GeV*invptq_second; - double Eta1 = track_first.momEta(); - double Eta2 = track_second.momEta(); - - double deta = fabs(Eta1-Eta2); - - double dphi = newPhi1-newPhi2; + float dphi = newPhi1-newPhi2; if(dphi>=Config::PI) dphi-=Config::TwoPI; else if(dphi<-Config::PI) dphi+=Config::TwoPI; - double dr = sqrt(deta*deta+dphi*dphi); + const float dr2 = deta2+dphi*dphi; - if (dr < maxDR) + if (dr2 < maxDR2) writetrack[tss]=false; } - if(writetrack[ts]==true) - cleanSeedTracks.push_back(seedTracks_[ts]); + if(writetrack[ts]) + cleanSeedTracks.emplace_back(track_first); } @@ -745,7 +748,7 @@ TrackVec Event::clean_cms_seedtracks() printf("Number of seeds: %d --> %d\n", ns, cleanSeedTracks.size()); #endif - return cleanSeedTracks; + seedTracks_.swap(cleanSeedTracks); } diff --git a/Event.h b/Event.h index 876605b5a764b..ef9ced1e5d13b 100644 --- a/Event.h +++ b/Event.h @@ -36,7 +36,7 @@ class Event void read_in (DataFile &data_file, FILE *in_fp=0); int clean_cms_simtracks(); - TrackVec clean_cms_seedtracks(); + int clean_cms_seedtracks(); //operates on seedTracks_; returns the number of cleaned seeds void print_tracks(const TrackVec& tracks, bool print_hits) const; const Geometry& geom_; From 99907e5a6912e672d96e1be91af408171938e659 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Sat, 5 Aug 2017 11:00:14 -0700 Subject: [PATCH 134/172] clean_cms_seedtracks optimization --- Event.cc | 63 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/Event.cc b/Event.cc index 119fb9d5c2099..e6465946573df 100644 --- a/Event.cc +++ b/Event.cc @@ -692,45 +692,62 @@ int Event::clean_cms_seedtracks() const float invR1GeV = 1.f/Config::track1GeVradius; - for(int ts=0; ts nHits(ns); + std::vector oldPhi(ns); + std::vector pos2(ns); + std::vector eta(ns); + std::vector invptq(ns); + std::vector x(ns); + std::vector y(ns); - const Track & track_first = seedTracks_[ts]; + for(int ts=0; ts maxDR2 ) continue; - const float pos2_second = std::pow(track_second.x(), 2) + std::pow(track_second.y(), 2); + const float oldPhi2 = oldPhi[tss]; + float dphiOld = std::abs(oldPhi1-oldPhi2); + if(dphiOld>=Config::PI) dphiOld =Config::TwoPI - dphiOld; + if (dphiOld > 0.5f) continue; + + const float pos2_second = pos2[tss]; const float thisDXYSign05 = pos2_second > pos2_first ? -0.5f : 0.5f; - const float thisDXY = thisDXYSign05*sqrt( std::pow(track_first.x()-track_second.x(), 2) - + std::pow(track_first.y()-track_second.y(), 2) ); + const float thisDXY = thisDXYSign05*sqrt( std::pow(x[ts]-x[tss], 2) + std::pow(y[ts]-y[tss], 2) ); - const float oldPhi2 = track_second.momPhi(); - const float invptq_second = track_second.charge()*track_second.invpT(); + const float invptq_second = invptq[tss]; const float newPhi1 = oldPhi1-thisDXY*invR1GeV*invptq_first; const float newPhi2 = oldPhi2+thisDXY*invR1GeV*invptq_second; - float dphi = newPhi1-newPhi2; - if(dphi>=Config::PI) dphi-=Config::TwoPI; - else if(dphi<-Config::PI) dphi+=Config::TwoPI; - + float dphi = std::abs(newPhi1-newPhi2); + if(dphi>=Config::PI) dphi =Config::TwoPI - dphi; + const float dr2 = deta2+dphi*dphi; if (dr2 < maxDR2) @@ -740,7 +757,7 @@ int Event::clean_cms_seedtracks() if(writetrack[ts]) - cleanSeedTracks.emplace_back(track_first); + cleanSeedTracks.emplace_back(seedTracks_[ts]); } From 6e177d9333ef5937d210d7307db972ce375974e0 Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Sun, 6 Aug 2017 07:12:34 -0700 Subject: [PATCH 135/172] add scripts to move validation plots and text files to the web --- web/move-cmsswval-extrectracks.sh | 46 ++++++++++++++++++++++++++ web/move-cmsswval.sh | 54 +++++++++++++++++++++++++++++++ web/move-toymcval.sh | 35 ++++++++++++++++++++ 3 files changed, 135 insertions(+) create mode 100755 web/move-cmsswval-extrectracks.sh create mode 100755 web/move-cmsswval.sh create mode 100755 web/move-toymcval.sh diff --git a/web/move-cmsswval-extrectracks.sh b/web/move-cmsswval-extrectracks.sh new file mode 100755 index 0000000000000..ce0de3cdcd8ff --- /dev/null +++ b/web/move-cmsswval-extrectracks.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +dir=${1:-cmsswval-ext} +base=SNB_CMSSW_10mu + +echo "Moving plots and text files locally to ${dir}" +for region in ECN2 ECN1 BRL ECP1 ECP2 FullDet +do + outdir=${dir}/${region} + mkdir -p ${outdir} + + mv ${base}_${region}_*.png ${outdir} + for build in BH STD CE + do + vbase=validation_${base}_${region}_${build} + mv ${vbase}/totals_${vbase}_cmssw.txt ${outdir} + done +done + +mv ${dir}/FullDet/*png ${dir}/FullDet/*txt ${dir} +rm -rf ${dir}/FullDet + +host=kmcdermo@lxplus.cern.ch +whost=${host}":~/www" +echo "Moving plots and text files remotly to ${whost}" +scp -r ${dir} ${whost} + +echo "Executing remotely ./makereadable.sh ${dir}" +ssh ${host} bash -c "' +cd www +./makereadable.sh ${dir} +exit +'" + +echo "Removing local files" +for region in ECN2 ECN1 BRL ECP1 ECP2 FullDet +do + for build in BH STD CE + do + testbase=${base}_${region}_${build} + rm -rf validation_${testbase} + rm -rf log_${testbase}_NVU8int_NTH24_cmsswval.txt + done +done + +rm -rf ${dir} diff --git a/web/move-cmsswval.sh b/web/move-cmsswval.sh new file mode 100755 index 0000000000000..64b0fc1a12a47 --- /dev/null +++ b/web/move-cmsswval.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +dir=${1:-cmsswval} +base=SNB_CMSSW_10mu + +echo "Moving plots and text files locally to ${dir}" +for seed in SimSeed CMSSeed +do + for region in ECN2 ECN1 BRL ECP1 ECP2 FullDet + do + outdir=${dir}/${seed}/${region} + mkdir -p ${outdir} + + srbase=${seed}_${region} + mv ${base}_${srbase}_*.png ${outdir} + for build in BH STD CE + do + vbase=validation_${base}_${srbase}_${build} + mv ${vbase}/totals_${vbase}.txt ${outdir} + done + done + sdir=${dir}/${seed} + mv ${sdir}/FullDet/*png ${sdir}/FullDet/*txt ${sdir} + rm -rf ${sdir}/FullDet +done + +host=kmcdermo@lxplus.cern.ch +whost=${host}":~/www" +echo "Moving plots and text files remotly to ${whost}" +scp -r ${dir} ${whost} + +echo "Executing remotely ./makereadable.sh ${dir}" +ssh ${host} bash -c "' +cd www +./makereadable.sh ${dir} +exit +'" + +echo "Removing local files" +for seed in SimSeed CMSSeed +do + for region in ECN2 ECN1 BRL ECP1 ECP2 FullDet + do + srbase=${seed}_${region} + for build in BH STD CE + do + testbase=${base}_${srbase}_${build} + rm -rf validation_${testbase} + rm -rf log_${testbase}_NVU8int_NTH24_val.txt + done + done +done + +rm -rf ${dir} diff --git a/web/move-toymcval.sh b/web/move-toymcval.sh new file mode 100755 index 0000000000000..90539a30c4c20 --- /dev/null +++ b/web/move-toymcval.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +dir=${1:-toymcval} +base=SNB_ToyMC_FullDet + +echo "Moving plots and text files locally to ${dir}" +mkdir -p ${dir} +mv ${base}_*.png ${dir} +for build in BH STD CE +do + vbase=validation_${base}_${build} + mv ${vbase}/totals_${vbase}.txt ${dir} +done + +host=kmcdermo@lxplus.cern.ch +whost=${host}":~/www" +echo "Moving plots and text files remotly to ${whost}" +scp -r ${dir} ${whost} + +echo "Executing remotely ./makereadable.sh ${dir}" +ssh ${host} bash -c "' +cd www +./makereadable.sh ${dir} +exit +'" + +echo "Removing local files" +for build in BH STD CE +do + testbase=${base}_${build} + rm -rf validation_${testbase} + rm -rf log_${testbase}_NVU8int_NTH24_val.txt +done + +rm -rf ${dir} From 4b98c626577a7d1f4e257002a191242c9d3a8744 Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Sun, 6 Aug 2017 12:01:40 -0700 Subject: [PATCH 136/172] create validation manifesto and move some large block of comments from code to manifesto --- TTreeValidation.cc | 42 ----- Track.cc | 10 -- mkFit/MkBuilder.cc | 32 ---- validation-desc.txt | 421 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 421 insertions(+), 84 deletions(-) create mode 100644 validation-desc.txt diff --git a/TTreeValidation.cc b/TTreeValidation.cc index 193cf0e0e56a0..9fc0dc20ed46f 100644 --- a/TTreeValidation.cc +++ b/TTreeValidation.cc @@ -1,45 +1,3 @@ -// mcTrackID assignments in Track.cc -// Efficiency -// numerator: sim tracks with at least one reco track with mcTrackID >= 0 (mcmask == 1) -// denominator: all findable sim tracks (mcmask = 0 || == 1) -// Fake Rate (with only long reco tracks: Config::inclusiveShorts == false) -// numerator: reco tracks with mcTrackID == -1 (mcmask == 0) -// denominator: reco tracks with mcTrackID >= 0 || == -1 || == -6 (mcmask == 1,0,2) -// Fake Rate (with all reco tracks: Config::inclusiveShorts == true) -// numerator: reco tracks with mcTrackID == -1, == -3 (mcmask == 0) -// denominator: reco tracks with mcTrackID >= 0 || == -1 || == -2 || == -3 || == -4 || == -6 || == -7 (mcmask == 1,0,2) - -// N.B. Mask assignments -// --> mcmask_[reco] == 1,"associated" reco to sim track [possible duplmask_[reco] == 1,0] {eff and FR} -// --> mcmask_[reco] == 0,"unassociated" reco to sim track. by definition no duplicates (no reco to associate to sim tracks!) [possible duplmask_[reco] == 2 {eff and FR}] -// --> mcmask_[reco] == -1, sim or reco track excluded from denominator (and therefore numerator) [possible duplmask_[reco] == -1] {eff and FR} -// --> mcmask_[reco] == 2, reco track included in demoninator of FR, but will not enter numerator: for short "matched" tracks of mcTrackID == -2,-4 {FR only} - -// --> nTkMatches_[reco] > 1, n reco tracks associated to the same sim track ID {eff only} -// --> nTkMatches_[reco] == 1, 1 reco track associated to single sim track ID {eff only} -// --> nTkMatches_[reco] == -99, no reco to sim match {eff only} - -// excluding position variables, as position could be -99! -// --> reco var == -99, "unassociated" reco to sim track [possible mcmask_[reco] == 0,-1,2; possible duplmask_[reco] == 2] {eff only} -// --> sim var == -99, "unassociated" reco to sim track [possible mcmask_[reco] == 0,-1,2; possible duplmask_[reco] == 2] {FR only} -// --> reco/sim var == -100, "no matching seed to build/fit" track, fill all reco/sim variables -100 [possible mcmask_[reco] == -1, possible duplmask_[reco] == -1] {FR only} -// --> sim var == -101, reco track is "associated" to sim track, however, sim track does have a hit on the layer the reco track is on - -// --> seedmask_[reco] == 1, matching seed to reco/fit track [possible mcmask_[reco] == 0,1,2; possible duplmask_[reco] == 0,1,2] {FR only} -// --> seedmask_[reco] == 0, no matching seed to reco/fit track [possible mcmask_[reco] == -1; possible duplmask_[reco] == -1] {FR only} - -// --> duplmask_[reco] == 0, only "associated" reco to sim track [possible mcmask_[reco] == 1] {eff and FR} -// --> duplmask_[reco] == 1, more than one "associated" reco to sim track [possible mcmask_[reco] == 1] {eff and FR} -// --> duplmask_[reco] == 2, no "associated" reco to sim track [possible mcmask_[reco] == 0,-1,2] {eff and FR} -// --> duplmask_[reco] == -1, no matching built/fit track for given seed [possible mcmask_[reco] == -1] {FR only} - -// --> reco var == -10, variable not yet implemented for given track object - -// position reco variables -// --> layers_[reco] == -1, reco unassociated to sim tk {eff only} -// --> reco pos+err var == -2000, reco tk is unassociated to sim tk {eff only} -// --> reco pos+err var == -3000, reco tk is unassociated to seed tk {FR only} - #include "TTreeValidation.h" #include "Event.h" #include "Config.h" diff --git a/Track.cc b/Track.cc index 8885c6389761a..1fe711fc3f602 100644 --- a/Track.cc +++ b/Track.cc @@ -93,16 +93,6 @@ float Track::swimPhiToR(const float x0, const float y0) const // TrackExtra //============================================================================== -// mcTrackID assignments -// ID >= 0 : reco track matched to sim track (n eligible found reco hits matching single sim track above some threshold, and n eligible found reco hits above some threshold) -// ID == -1 : reco track is a true fake (n eligible found reco hits matching single sim track below some threshold, and n eligible found reco hits above some threshold) -// ID == -2 : reco track is a matched short track --> inefficient but not fake (n eligible found reco hits matching single sim track above some threshold, and n eligible found reco hits below some threshold) -// ID == -3 : reco track is a short fake (n eligible found reco hits matching single sim track below some threshold, and n eligible found reco hits below some threshold) --> TOYMC SIM SEEDS ONLY -// ID == -4 : reco track never made it past its sim seed --> inefficient but not fake --> TOYMC SIM SEEDS ONLY -// ID == -5 : reco track somehow has zero hits... unclear what to do with these... ---> CMSSW OR REAL SEEDS ONLY -// ID == -6 : reco track is long, and matched to sim track. however, simtrack is unfindable (enter denom of FR) -// ID == -7 : reco track is short, and matched to sim track. however, simtrack is unfindable (enter denom of FR for inclusive shorts) - // More stringent requirement for matching --> used only for simtrack pure seeds void TrackExtra::setMCTrackIDInfoByLabel(const Track& trk, const std::vector& layerHits, const MCHitInfoVec& globalHitInfo) { diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index 629976f1427a2..e01950be62970 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -652,38 +652,6 @@ inline void MkBuilder::fit_one_seed_set(TrackVec& seedtracks, int itrack, int en // Common functions for validation //------------------------------------------------------------------------------ -//////////////////////////////// -// Outline of map/remap logic // -//////////////////////////////// -/* -All built candidate tracks have all hit indices pointing to m_event_of_hits.m_layers_of_hits[layer].m_hits (LOH) -MC seeds (both CMSSW and toyMC) have seed hit indices pointing to global HitVec m_event->layerHits_[layer] (GLH) -"Real" seeds have all seed hit indices pointing to LOH. -So.. to have universal seed fitting function --> have seed hits point to LOH no matter their origin. -This means that all MC seeds must be "mapped" from GLH to LOH: map_seed_hits(). -Now InputTracksAndHits() for seed fit will use LOH instead of GLH. -The output tracks of the seed fitting are now stored in m_event->seedTracks_. - -Then building proceeds as normal, using m_event->seedTracks_ as input no matter the choice of seeds. - -For the validation, we can reuse the TrackExtra setMCTrackIDInfo() with a few tricks. -Since setMCTrackIDInfo by necessity uses GLH, we then need ALL track collections (seed, candidate, fit) to their hits point back to GLH. -There are also two validation options: w/ or w/o ROOT. - -W/ ROOT uses the TTreValidation class which needs seedTracks_, candidateTracks_, and fitTracks_ all stored in m_event. -The fitTracks_ collection for now is just a copy of candidateTracks_ (eventually may have cuts and things that affect which tracks to fit). -So... need to "remap" seedTracks_ hits from LOH to GLH with remap_seed_hits(). -And also copy in tracks from EtaBin* to candidateTracks_, and then remap hits from LOH to GLH with quality_store_tracks() and remap_cand_hits(). -W/ ROOT uses root_val_BH for BH, and root_val_COMB() for non-BH. - -W/O ROOT is a bit simpler... as we only need to do the copy out tracks from EtaBin* and then remap just candidateTracks_. -This uses quality_output_COMB() or quality_output_BH() - -N.B.1 Since fittestMPlex at the moment is not "end-to-end" with candidate tracks, we can still use the GLH version of InputTracksAndHits() - -N.B.2 Since we inflate LOH by 2% more than GLH, hit indices in building only go to GLH, so all loops are sized to GLH. -*/ - void MkBuilder::map_seed_hits() { // map seed hit indices from global m_event->layerHits_[i] to hit indices in diff --git a/validation-desc.txt b/validation-desc.txt new file mode 100644 index 0000000000000..3aac9a9cae6ba --- /dev/null +++ b/validation-desc.txt @@ -0,0 +1,421 @@ +This file is a compendium on how the validation runs within mkFit, which makes use of the TTreeValidation class and other supporting macros. + +Table of Contents + +A. Overview of code +B. Overview of routine calls in mkFit +C. Explanation of validation routines + I. Tracks and Extras Prep + II. Track Association Routines + III. TTree Filling +D. Definitions of efficiency, fake rate, and duplicate rate +E. Overview of scripts +F. Hit map/remapping logic +G. Extra info on ID and mask assignments + +===================== + A. Overview of code +===================== + +TTreeValidation will only compile the necessary ROOT code with WITH_ROOT=yes enabled (either manually editting Makefile.config, or at the command line). Always do a make clean before compiling with ROOT, as the code is ifdef'ed. To hide the heavy-duty functions from the main code, TTreeValidation inherits from the virtual class "Validation", and overrides the common functions. The TTreeValidation object is created once per number of events in flight. The Event object obtains a reference to the validation object (store as a data member "validation_"), so it is up to the Event object to reset some of the data members of the TTreeValidation object on every event. + +Three types of validation exist within TTreeValidation: +[1.] "Building validation", enabled with Config::root_val, via the command line option: --root-val +[2.] "CMSSW external tracks building validation", enabled with Config::cmssw_val, via the command line options: --cmss-val --cmssw-seeds --ext-rec-tracks --geom CMS-2017 +[3.] "Fit validation", enabled with Config::fit_val, via the command line option: --fit-val + +We will ignore fit validation for the moment. The main idea behind the other two is that the validation routines are called outside of the standard timed sections, and as such, we do not care too much about performance, as long as it takes a reasonable amount of time to complete. Of course, the full wall clock time matters when running multiple events in flight, and because there is a lot of I/O as well as moves and stores that would hurt the performance with the validation enabled, these routines are ignored if the command line option "--silent" is enabled. + +The building validation takes advantage of filling two trees per event per track, namely: +[1.] + - efftree (filled once per sim track) + - frtree (filled once per seed track) +[2.] + - cmsswefftree (filled once per cmssw external track) + - cmsswfrtree (filled once per mkFit build track) + +[1.] validation exists in the following combinations of geometry and seed source: +- ToyMC, with sim seeds or find-seeds +- CMSSW, with sim seeds or cmssw-seeds + +Upon instantiation of the TTreeValidation object, the respective ROOT trees are defined and allocated on the heap, along with setting the addresses of all the branches. After the building is completed in mkFit, we have to have the tracks in their standard event containers, namely: seedTracks_, candidateTracks_, and fitTracks_. In the standard combinatorial or clone engine, we have to copy out the built tracks from event of combined candiates into candidateTracks_ via: builder.quality_store_tracks() in mkFit/buildtestMPlex.cc. Since we do not yet have fitting after building, we just set the fitTracks_ equal to the candidateTracks_. For ease, I will from now on refer to the candidateTracks_ as buildTracks_. + +As a reminder, the sim tracks are stored in the Event.cc as simTracks_, while the CMSSW reco tracks are stored as extRecTracks_. Each track collection has an associated TrackExtra collection, which is stored as {trackname}Extra_ inside the Event object. It is indexed the same as the collection it references, i.e. track[0] has an associated extra extra[0]. The TrackExtra object contains the mcTrackID, seedID, and cmsswTrackID each mkFit track is associated to. The validation also makes use of simHitsInfo_ (container for storing mcTrackID for each hit), layerHits_, and simTrackStates_ (used for pulls). See Section B and C for explanations on how the track matching is performed and track information is saved. + +Following each event, each of the track and extra objects are cleared. In addition, the association maps are cleared and reset. After the main loop over events expires, the ROOT file is written out with the TTrees saved via: val.saveTTrees() in mkFit.cc. The destructor for the validation then deletes the trees. The output is "valtree.root", appended by the thread number if using multiple events in flight. From here, we then take advantage of the following files: + +- runValidation.C // macro used for turning TTrees into efficiency/fake rate/duplicate rate plots +- PlotValidation.cpp/.hh // source code for doing calculations +- makeValidation.C // plots on a single canvas results for Best Hit (BH), Standard Combinatorial (STD), and Clone Engine (CE) + +====================================== + B. Outline of routine calls in mkFit +====================================== + +The following routines are then called after the building (MkBuilder.cc, Event.cc, TTreeValidation.cc, Track.cc): + +[1.] builder.root_val() + : remap_seed_hits() + : remap_cand_hits() + : prep_recotracks() + : prep_tracks(seedtracks,seedextras) + : m_event->validation_.alignTracks(tracks,extras,false) + : prep_tracks(buildtracks,buildextras) + : m_event->validation_.alignTracks(tracks,extras,false) + : prep_tracks(fittracks,fitextras) + : m_event->validation_.alignTracks(tracks,extras,false) + : if (cmssw-seeds) m_event->clean_cms_simtracks() // label which simtracks are not findable: already set if using sim seeds + : m_event->Validate() + : validation_.setTrackExtras(*this) + : if (sim seeds) extra.setMCTrackIDInfoByLabel() // Require 50% of found hits after seed to match label of seed/sim track + : if (cms seeds) extra.setMCTrackIDInfo() // Require 75% of found hits to match a single sim track + : validation_.makeSimTkToRecoTksMaps(*this) + : mapRefTkToRecoTks(seedtracks,seedextras,simToSeedMap) // map key = mcTrackID, map value = vector of seed labels + : mapRefTkToRecoTks(buildtracks,buildextras,simToBuildMap) // map key = mcTrackID, map value = vector of build labels + : mapRefTkToRecoTks(fittracks,fitextras,simToFitMap) // map key = mcTrackID, map value = vector of fit labels + : validation_.makeSeedTkToRecoTkMaps(*this) + : mapSeedTkToRecoTk(buildtracks,buildextras,seedToBuildMap) // map key = seedID, map value = build track label + : mapSeedTkToRecoTk(fittracks,fitextras,seedToFitMap) // map key = seedID, map value = fit track label + : validation_.fillEfficiencyTree(*this) + : validation_.fillFakeRateTree(*this) + +[2.] builder.cmssw_val() + : remap_cand_hits() + : prep_recotracks() + : prep_tracks(buildtracks,buildextras) + : m_event->validation_.alignTracks(tracks,extras,false) + : prep_cmsswtracks() + : prep_tracks(cmsswtracks,cmsswextras) + : m_event->validation_.alignTracks(tracks,extras,false) + : m_event->Validate() + : validation_.setTrackExtras(*this) + : extra.setCMSSWTrackInfo() // Chi2 and dphi matching (also incudes option for nHits matching) + : validation_.makeCMSSWTkToRecoTksMaps(*this) + : mapRefTkToRecoTks(buildtracks,buildextras,cmsswToBuildMap) + : validation_.fillCMSSWEfficiencyTree(*this) + : validation_.fillCMSSWFakeRateTree(*this) + +======================================= + C. Explanation of validation routines +======================================= + +- map/remap hit functions: see notes in section E. Essentially, validation needs all hit indices inside tracks to match the hit indices inside ev.layerHits_. + ++++++++++++++++++++++++++++ + I. Tracks and Extras Prep ++++++++++++++++++++++++++++ + +- prep_tracks(tracks,extras) + : Loop over all tracks in consideration + : sort hits inside track by layer : needed for counting unique layers and for association routines + : emplace_back a track extra, initialized with the label of the track (which happens to be its seed ID) + : m_event->validation_.alignTracks(tracks,extras,alignExtra) + +- alignTracks(tracks,extras,alignExtra) + : if alignExtra == true // needed for when a reco track collection, which was previously labeled by its label() == seedID, created its track extra at the same time but the track collection has been moved or sorted + : create temporary track extra collection, size of track collection + : loop over tracks + : set tmp extra to the old track extra collection matching the track label + : set the old track extra to equal the new collection + : loop over tracks + : set the track label equal to the index inside the vector // needed for filling routines which rely on maps of indices between two track collections + +- prep_cmsswtracks() + : Stanard prep_tracks() + : loop over cmssw tracks + : Count unique layers = nLayers + : set status of cmssw track to notFindable() if: (nLayers < [Config::cmsSelMinLayers == 8] || cmssw.pT() < [Config::cmsSelMinPt == 0.5]) // same criteria for "notFindable()" cmssw sim tracks used for seeds + +++++++++++++++++++++++++++++++++ + II. Track Association Routines +++++++++++++++++++++++++++++++++ + +- setTrackExtras(&Event) + : if [1.] + : loop over seed tracks + : setMCTrackIDInfo(true) : Require 75% of found hits to match a single sim track + : loop over build tracks + : if (sim seeds) setMCTrackIDInfoByLabel() : Require 50% of found hits after seed to match label of seed/sim track + : if (cms seeds) setMCTrackIDInfo(false) : Require 75% of found hits to match a single sim track + : loop over fit tracks + : same options as build tracks + : if [2.] + : first loop over cmssw tracks + : create a vector of "reduced tracks" that stores 1./pt, eta, and associated covariances in reduced track states + : also include track momentum phi, and a list of hits inside a map. map key = layer, map value = vector of hit indices + : loop over build tracks + : setCMSSWTrackIDInfo() : require matching by chi2 and dphi + +- setMCTrackIDInfoByLabel(label) + : if no hits are found after seed, mcTrackID == -4, and skip the rest of the function + : Loop over found hits on build track after seed + : count the hits who have a mcTrackID == label (i.e. seedID == simTrack label == mcTrackID) + : if 50% are matched, mcTrackID == label + : else, mcTrackID == -1 + : if (track.nFoundHits() < [Config::nMinFoundHits == 7] - [Config::nlayers_per_seed == 4 or 3]) + : if already matched, mcTrackID = -2 + : else, mcTrackID = -3 + +- setMCTrackIDInfo(isSeedTrack) + : if track somehow has zero hits on track, mcTrackID = -5 --> should never happen unless some really deep bug + : Loop over all found hits on build track (includes seed hits) + : count the mcTrackID that appears most from the hits + : if 75% of hits on reco track match a single sim track, mcTrackID == mcTrackID of single sim track + : else, mcTrackID == -1 + : if (!isSeedTrack) + : if (track.nFoundHits() < [Config::nMinFoundHits == 7]) + : if already matched, mcTrackID = -2 + : else, mcTrackID = -3 + : if already matched + : if simtrack matched to isNotFindable() + : if failed check on length of track (i.e. -2), mcTrackID == -7 + : else, mcTrackID == -6 + +- setCMSSWTrackIDInfo() + : Loop over all cmssw "reduced" tracks + : if helix chi2 < [Config::minCMSSWMatchChi2 == 50] + : append label of cmssw track to a vector, along with chi2 + : sort vector by chi2 + : loop over label vector + : swim cmssw track momentum phi from phi0 to mkFit reco track + : if abs(wrapphi(dphi)) < [Config::minCMSSWMatchdPhi == 0.03] + : see if dphi < currently best stored mindphi, and if yes, then set this as the new mindphi + label as matched cmsswTrackID + : if using nHits matching, check for nHits matched --> currently not used nor tuned + : if no label is found, cmsswTrackID == -1 + : follow same logic for labeling as setMCTrackIDInfo for -2, -3, -6, -7 + +- mapRefTkToRecoTks(tracks,extras,map) + : Loop over reco tracks + : get track extra for track + : if [1.], map[extra.mcTrackID()].push_back(track.label()) // reminder, label() now equals index inside track vector! + : if [2.], map[extra.cmsswTrackID()].push_back(track.label()) // reminder, label() now equals index inside track vector! + : Loop over pairs in map + : if vector of labels size == 1, get track extra for label, and set duplicate index == 0 + : else + : make temp track vector from track labels, sort track vector by nHits (and sum hit chi2 if tracks have same nHits) + : set vector of labels to sorted tracks + : loop over vector labels + : get track extra for label, and set duplicate index++ + +- mapSeedTkToRecoTk(tracks,extras,map) + : loop over reco tracks + : map[extra.seedID()] = track.label() + +++++++++++++++++++++ + III. TTree Filling +++++++++++++++++++++ + +- fillEfficiencyTree() + : loop over simtracks + : get mcTrackID (i.e. simTrack.label()) + : store sim track gen info + : if simToSeedMap[mcTrackID] has value + : mcmask == 1 + : get first seed track matched (i.e. the one with the highest nHits --> or lowest sum hit chi2 as provided by sort from above) + : store seed track parameters + : store nHits, nlayers, last layer, chi2, duplicate info + : get last found hit index + : store hit parameters + : if mcTrackID of hit == mcTrackID of sim track // ONLY for when simtrackstates are stored, i.e. in ToyMC only at the moment + : store sim track state momentum info from this layer (from simTrackStates[mcHitID]) + : else get sim track state of mcTrackID, then store momentum info + : else + : mcmask == 0, or == -1 if simtrack.isNotFindable() + : if simToBuildMap[mcTrackID] has value + : repeat as above + : if simToFitMap[mcTrackID] has value + : repeat as above + : fill efftree + +- fillFakeRateTree() + : loop over seed tracks + : get seedID of seed track from track extra + : fill seed track parameters + last hit info, nhits, etc + : assign mcmask info based on mcTrackID from track extra (see section D and G for explanation of mask assignments) + : if mcmask == 1 + : store gen sim momentum parameters + : store nhits info, last layer, duplicate info + : if last hit found has a valid mcHitID + : store sim track state momentum info from simTrackStates[mcHitID] + : if seedToBuildMap[seedID] has value + : fill build track parameters + last hit info, nhits, etc + : assign mcmask info based on mcTrackID from track extra (see section D and G for explanation of mask assignments) + : if mcmask == 1 + : store gen sim momentum parameters + : store nhits info, last layer, duplicate info + : if last hit found has a valid mcHitID + : store sim track state momentum info from simTrackStates[mcHitID] + : if seedToFitMap[seedID] has value + : same as aboe + : fill frtree + +- fillCMSSWEfficiencyTree() + : loop over cmsswtracks + : get label of cmsswtrack + : store cmssw track PCA parameters + nhits, nlayers, last layer + : if cmsswToBuilddMap[cmsswtrack.label()] has value + : get first build track matched (i.e. the one with the highest nHits --> or lowest sum hit chi2 as provided by sort from above) + : store build track parameters + errors + : store nHits, nlayers, last layer, last hit parameters, hit and helix chi2, duplicate info + : swim cmssw phi to mkFit track, store it + : fill cmsswefftree + +- fillCMSSWFakeRateTree() + : loop over build tracks + : store build track parameters + errors + : store nHits, nlayers, last layer, last hit parameters, hit and helix chi2, duplicate info + : get cmsswTrackID, assign cmsswmask according to section D and G + : if cmsswmask == 1 + : store cmssw track PCA parameters + nhits, nlayers, last layer + : swim cmssw phi to mkFit track, store it + : fill cmsswefftree + +============================================================= + D. Definitions of efficiency, fake rate, and duplicate rate +============================================================= + +Use rootValidation.C to create efficiency, fake rate, and duplicate rate vs. pT, phi, eta. This macro compiles PlotValidation.cpp/.hh. Efficiency uses sim track momentum info. Fake rate uses the reco track momentum. For [1.], plots are made for seed, build, and fit tracks. For [2.], the plots are only against the build tracks. + +root -l -b -q runValidation.C\([agruments]\) + +Argument list: +First is additional input name of root file [def = ""] +Second argument is boolean to compute momentum pulls: currently implemented only when sim track states are available (ToyMC validation only)! [def = false] +Third argument is boolean to do special CMSSW validation [def = false] +Fourth argument == true to move input root file to output directory, false to keep input file where it is. [def = true] +Fifth argument is a bool to save the image files [def = false] +Last argument is output type of plots [def = "pdf"] + +Efficiency [PlotValidation::PlotEfficiency()] + numerator: sim tracks with at least one reco track with mcTrackID >= 0 (mcmask_[reco] == 1) + denominator: all findable sim tracks (mcmask_[reco] = 0 || == 1) + mcmask_[reco] == - 1 excluded from both numerator and denominator because this sim track was not findable! + +Fake Rate (with only long reco tracks: Config::inclusiveShorts == false) [PlotValidation::PlotFakeRate()] + numerator: reco tracks with mcTrackID == -1 + denominator: reco tracks with mcTrackID >= 0 || == -1 || == -6 + mcTrackID | mcmask_[reco] + >= 0 | 1 + -1 | 0 + -6 | 2 + else | -1 + +Fake Rate (with all reco tracks: Config::inclusiveShorts == true, enabled with command line option: --inc-shorts) [PlotValidation::PlotFakeRate()] + numerator: reco tracks with mcTrackID == -1 || == -3 + denominator: reco tracks with mcTrackID >= 0 || == -1 || == -2 || == -3 || == -4 || == -6 || == -7 + mcTrackID | mcmask_[reco] + >= 0 | 1 + -1 or -3 | 0 + -2 or -4 or -6 or -7 | 2 + +Duplicate Rate [PlotValidation::PlotDuplicateRate()] + numerator: sim tracks with more than reco track match (nTkMatches_[reco] > 1) + denominator: sim tracks with at least one reco track with mcTrackID >= 0 (mcmask_[reco] == 1) + +======================== + E. Overview of scripts +======================== + +./validation-snb-toymc-fulldet-build.sh +Runs ToyMC full detector tracking for BH, STD, CE, for 400 events with nTracks/event = 2500. Sim seeds only. + +./validation-snb-cmssw-fulldet-build.sh +Runs CMSSW full detector tracking for BH, STD, CE, for ~1000 events with 10 muons/event, with sim and cmssw seeds. +Samples are split by eta region. Building is run for each region: +- ECN2: 2.4 < eta < 1.7 +- ECN1: 1.75 < eta < 0.55 +- BRL: |eta| < 0.6 +- ECP1: 0.55 < eta < 1.75 +- ECP2: 1.7 < eta < 2.4 + +Validation plots are produced for each sample (region), seeding source, and building routine. At the very end, validation trees are hadd'ed for each region in a given seed source + building routine. Plots are produced again to yield "full-detector" tracking. + +./validation-snb-cmssw-fulldet-extrectracks.sh +Same as above, but now only run with cmssw seeds (as we are comparing directly to cmssw output as the reference). + +============================ + F. Hit map/remapping logic +============================ + +*** Originally from mkFit/MkBuilder.cc *** + +All built candidate tracks have all hit indices pointing to m_event_of_hits.m_layers_of_hits[layer].m_hits (LOH) +MC seeds (both CMSSW and toyMC) have seed hit indices pointing to global HitVec m_event->layerHits_[layer] (GLH) +"Real" seeds have all seed hit indices pointing to LOH. +So.. to have universal seed fitting function --> have seed hits point to LOH no matter their origin. +This means that all MC seeds must be "mapped" from GLH to LOH: map_seed_hits(). +Now InputTracksAndHits() for seed fit will use LOH instead of GLH. +The output tracks of the seed fitting are now stored in m_event->seedTracks_. + +Then building proceeds as normal, using m_event->seedTracks_ as input no matter the choice of seeds. + +For the validation, we can reuse the TrackExtra setMCTrackIDInfo() with a few tricks. +Since setMCTrackIDInfo by necessity uses GLH, we then need ALL track collections (seed, candidate, fit) to their hits point back to GLH. +There are also two validation options: w/ or w/o ROOT. + +W/ ROOT uses the TTreValidation class which needs seedTracks_, candidateTracks_, and fitTracks_ all stored in m_event. +The fitTracks_ collection for now is just a copy of candidateTracks_ (eventually may have cuts and things that affect which tracks to fit). +So... need to "remap" seedTracks_ hits from LOH to GLH with remap_seed_hits(). +And also copy in tracks from EtaBin* to candidateTracks_, and then remap hits from LOH to GLH with quality_store_tracks() and remap_cand_hits(). +W/ ROOT uses root_val_BH for BH, and root_val_COMB() for non-BH. + +W/O ROOT is a bit simpler... as we only need to do the copy out tracks from EtaBin* and then remap just candidateTracks_. +This uses quality_output_COMB() or quality_output_BH() + +N.B.1 Since fittestMPlex at the moment is not "end-to-end" with candidate tracks, we can still use the GLH version of InputTracksAndHits() +N.B.2 Since we inflate LOH by 2% more than GLH, hit indices in building only go to GLH, so all loops are sized to GLH. + +========================================== + G. Extra info on ID and mask assignments +========================================== + +*** Originally from Track.cc *** + +mcTrackID assignments +ID >= 0 : reco track matched to sim track (n eligible found reco hits matching single sim track above some threshold, and n eligible found reco hits above some threshold) +ID == -1 : reco track is a true fake (n eligible found reco hits matching single sim track below some threshold, and n eligible found reco hits above some threshold) +ID == -2 : reco track is a matched short track --> inefficient but not fake (n eligible found reco hits matching single sim track above some threshold, and n eligible found reco hits below some threshold) +ID == -3 : reco track is a short fake (n eligible found reco hits matching single sim track below some threshold, and n eligible found reco hits below some threshold) --> TOYMC SIM SEEDS ONLY +ID == -4 : reco track never made it past its sim seed --> inefficient but not fake --> TOYMC SIM SEEDS ONLY +ID == -5 : reco track somehow has zero hits... unclear what to do with these... ---> CMSSW OR REAL SEEDS ONLY +ID == -6 : reco track is long, and matched to sim track. however, simtrack is unfindable (enter denom of FR) +ID == -7 : reco track is short, and matched to sim track. however, simtrack is unfindable (enter denom of FR for inclusive shorts) + +N.B. CMSSW TrackID uses same assignments! + +*** Originally from TTreeValidation.cc *** + +mcTrackID assignments in Track.cc + +_[reco] = {seed,build,fit} + +N.B. Mask assignments +--> mcmask_[reco] == 1,"associated" reco to sim track [possible duplmask_[reco] == 1,0] {eff and FR}, enter numer and denom of eff, enter denom only of FR +--> mcmask_[reco] == 0,"unassociated" reco to sim track. by definition no duplicates (no reco to associate to sim tracks!) [possible duplmask_[reco] == 2 {eff and FR}], enter denom only of eff, enter numer and denom of FR +--> mcmask_[reco] == -1, sim or reco track excluded from denominator (and therefore numerator) [possible duplmask_[reco] == -1] {eff and FR} +--> mcmask_[reco] == 2, reco track included in demoninator of FR, but will not enter numerator: for short "matched" tracks of mcTrackID == -2,-4 {FR only} + +--> nTkMatches_[reco] > 1, n reco tracks associated to the same sim track ID {eff only} +--> nTkMatches_[reco] == 1, 1 reco track associated to single sim track ID {eff only} +--> nTkMatches_[reco] == -99, no reco to sim match {eff only} + +excluding position variables, as position could be -99! +--> reco var == -99, "unassociated" reco to sim track [possible mcmask_[reco] == 0,-1,2; possible duplmask_[reco] == 2] {eff only} +--> sim var == -99, "unassociated" reco to sim track [possible mcmask_[reco] == 0,-1,2; possible duplmask_[reco] == 2] {FR only} +--> reco/sim var == -100, "no matching seed to build/fit" track, fill all reco/sim variables -100 [possible mcmask_[reco] == -1, possible duplmask_[reco] == -1] {FR only} +--> sim var == -101, reco track is "associated" to sim track, however, sim track does have a hit on the layer the reco track is on + +--> seedmask_[reco] == 1, matching seed to reco/fit track [possible mcmask_[reco] == 0,1,2; possible duplmask_[reco] == 0,1,2] {FR only} +--> seedmask_[reco] == 0, no matching seed to reco/fit track [possible mcmask_[reco] == -1; possible duplmask_[reco] == -1] {FR only} + +--> duplmask_[reco] == 0, only "associated" reco to sim track [possible mcmask_[reco] == 1] {eff and FR} +--> duplmask_[reco] == 1, more than one "associated" reco to sim track [possible mcmask_[reco] == 1] {eff and FR} +--> duplmask_[reco] == 2, no "associated" reco to sim track [possible mcmask_[reco] == 0,-1,2] {eff and FR} +--> duplmask_[reco] == -1, no matching built/fit track for given seed [possible mcmask_[reco] == -1] {FR only} + +--> reco var == -10, variable not yet implemented for given track object + +position reco variables +--> layers_[reco] == -1, reco unassociated to sim tk {eff only} +--> reco pos+err var == -2000, reco tk is unassociated to sim tk {eff only} +--> reco pos+err var == -3000, reco tk is unassociated to seed tk {FR only} From 085312754ca4699e3792e070eea0301b0b113df7 Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Tue, 8 Aug 2017 04:26:51 -0700 Subject: [PATCH 137/172] add seed relabeling + validation and web scripts for pu70 --- Event.cc | 12 ++++++ validation-snb-cmssw-PU70-fulldet-build.sh | 37 +++++++++++++++++++ web/move-cmsswval-pu70.sh | 43 ++++++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100755 validation-snb-cmssw-PU70-fulldet-build.sh create mode 100755 web/move-cmsswval-pu70.sh diff --git a/Event.cc b/Event.cc index e6465946573df..80b355618449d 100644 --- a/Event.cc +++ b/Event.cc @@ -767,6 +767,18 @@ int Event::clean_cms_seedtracks() seedTracks_.swap(cleanSeedTracks); + if (Config::root_val && (seedTracks_.size() > 0)) + { + std::vector stids; + for (auto&& track : seedTracks_) stids.push_back(track.label()); + std::sort(stids.begin(),stids.end()); + + int newlabel = stids.back(); + for (auto&& seedtrack : seedTracks_) + { + if (seedtrack.label() < 0) seedtrack.setLabel(++newlabel); + } + } } diff --git a/validation-snb-cmssw-PU70-fulldet-build.sh b/validation-snb-cmssw-PU70-fulldet-build.sh new file mode 100755 index 0000000000000..1137a6e5b3ac2 --- /dev/null +++ b/validation-snb-cmssw-PU70-fulldet-build.sh @@ -0,0 +1,37 @@ +#! /bin/bash + +make -j 12 WITH_ROOT=yes CPPUSERFLAGS+=-DCLEAN_SEEDS CXXUSERFLAGS+=-DCLEAN_SEEDS + +dir=/data/nfsmic/slava77/samples/2017/pass-4874f28/initialStep/PU70/10224.0_TTbar_13+TTbar_13TeV_TuneCUETP8M1_2017PU_GenSimFullINPUT+DigiFullPU_2017PU+RecoFullPU_2017PU+HARVESTFullPU_2017PU +file=memoryFile.fv3.clean.writeAll.recT.072617.bin + +base=SNB_CMSSW_PU70 + +for sV in "SimSeed " "CMSSeed --cmssw-seeds" +do echo $sV | while read -r sN sO + do + for bV in "BH bh" "STD std" "CE ce" + do echo $bV | while read -r bN bO + do + oBase=${base}_${sN}_${bN} + echo "${oBase}: validation [nTH:24, nVU:8]" + ./mkFit/mkFit ${sO} --geom CMS-2017 --root-val --read --file-name ${dir}/${file} --build-${bO} --num-thr 24 >& log_${oBase}_NVU8int_NTH24_val.txt + mv valtree.root valtree_${oBase}.root + done + done + done +done + +make clean + +for seed in SimSeed CMSSeed +do + oBase=${base}_${seed} + for build in BH STD CE + do + root -b -q -l runValidation.C\(\"_${oBase}_${build}\"\) + done + root -b -q -l makeValidation.C\(\"${oBase}\"\) +done + +make distclean diff --git a/web/move-cmsswval-pu70.sh b/web/move-cmsswval-pu70.sh new file mode 100755 index 0000000000000..ba92f306e4b34 --- /dev/null +++ b/web/move-cmsswval-pu70.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +dir=${1:-cmsswval-pu70} +base=SNB_CMSSW_PU70 + +echo "Moving plots and text files locally to ${dir}" +for seed in SimSeed CMSSeed +do + outdir=${dir}/${seed} + mkdir -p ${outdir} + + mv ${base}_${seed}_*.png ${outdir} + for build in BH STD CE + do + vbase=validation_${base}_${seed}_${build} + mv ${vbase}/totals_${vbase}.txt ${outdir} + done +done + +host=kmcdermo@lxplus.cern.ch +whost=${host}":~/www" +echo "Moving plots and text files remotly to ${whost}" +scp -r ${dir} ${whost} + +echo "Executing remotely ./makereadable.sh ${dir}" +ssh ${host} bash -c "' +cd www +./makereadable.sh ${dir} +exit +'" + +echo "Removing local files" +for seed in SimSeed CMSSeed +do + for build in BH STD CE + do + testbase=${base}_${seed}_${build} + rm -rf validation_${testbase} + rm -rf log_${testbase}_NVU8int_NTH24_val.txt + done +done + +rm -rf ${dir} From fe21c53bfe2414944a5e5c92a2679089a7b655ab Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Tue, 8 Aug 2017 12:54:26 -0700 Subject: [PATCH 138/172] use incrementating negative labels for cmssw seeds with original label -1 --- Event.cc | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/Event.cc b/Event.cc index 80b355618449d..b4ac17b62b84c 100644 --- a/Event.cc +++ b/Event.cc @@ -769,15 +769,8 @@ int Event::clean_cms_seedtracks() if (Config::root_val && (seedTracks_.size() > 0)) { - std::vector stids; - for (auto&& track : seedTracks_) stids.push_back(track.label()); - std::sort(stids.begin(),stids.end()); - - int newlabel = stids.back(); - for (auto&& seedtrack : seedTracks_) - { - if (seedtrack.label() < 0) seedtrack.setLabel(++newlabel); - } + int newlabel = 0; + for (auto&& track : seedTracks_) if (track.label() < 0) track.setLabel(--newlabel); } } From 5b20df8eec00fd36fcc6182b088834d9cf74e287 Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Wed, 9 Aug 2017 08:49:22 -0700 Subject: [PATCH 139/172] change label checking to seedID_ check, add pu70 cmssw validation --- Event.cc | 2 +- Track.cc | 13 +++------ validation-desc.txt | 20 ++++++------- ...b-cmssw-10mu-fulldet-build-extrectracks.sh | 0 ...validation-snb-cmssw-10mu-fulldet-build.sh | 0 ...b-cmssw-PU70-fulldet-build-extrectracks.sh | 28 +++++++++++++++++++ 6 files changed, 43 insertions(+), 20 deletions(-) rename validation-snb-cmssw-fulldet-build-extrectracks.sh => validation-snb-cmssw-10mu-fulldet-build-extrectracks.sh (100%) rename validation-snb-cmssw-fulldet-build.sh => validation-snb-cmssw-10mu-fulldet-build.sh (100%) create mode 100755 validation-snb-cmssw-PU70-fulldet-build-extrectracks.sh diff --git a/Event.cc b/Event.cc index adaeade54adb9..0e17134c42504 100644 --- a/Event.cc +++ b/Event.cc @@ -775,7 +775,7 @@ int Event::clean_cms_seedtracks() seedTracks_.swap(cleanSeedTracks); - if (Config::root_val && (seedTracks_.size() > 0)) + if (Config::root_val || Config::cmssw_val) { int newlabel = 0; for (auto&& track : seedTracks_) if (track.label() < 0) track.setLabel(--newlabel); diff --git a/Track.cc b/Track.cc index 1fe711fc3f602..0709052f7157e 100644 --- a/Track.cc +++ b/Track.cc @@ -96,11 +96,6 @@ float Track::swimPhiToR(const float x0, const float y0) const // More stringent requirement for matching --> used only for simtrack pure seeds void TrackExtra::setMCTrackIDInfoByLabel(const Track& trk, const std::vector& layerHits, const MCHitInfoVec& globalHitInfo) { - // In this routine, we know that seedtracks == simtracks - // and as such seedtrack.label() == simtrack.label() - // assume each seed track has a hit on the very first layer! - const int label = globalHitInfo[layerHits[trk.getHitLyr(0)][trk.getHitIdx(0)].mcHitID()].mcTrackID(); - int nHitsMatched = 0; // count hits matched to simtrack after the seed : will need to modify the start of this loop! XXKM4MT for (int ihit = Config::nlayers_per_seed; ihit < trk.nTotalHits(); ++ihit) @@ -110,10 +105,10 @@ void TrackExtra::setMCTrackIDInfoByLabel(const Track& trk, const std::vector= 0) && (hitidx < layerHits[hitlyr].size())) // make sure it is a real hit { const int mchitid = layerHits[hitlyr][hitidx].mcHitID(); - dprint("trk.label()=" << trk.label() << " simtrack.label()= " << label << " ihit=" << ihit + dprint("trk.label()=" << trk.label() << " simtrack.label()= " << seedID_ << " ihit=" << ihit << " trk.getHitIdx(ihit)=" << hitidx << " trk.getHitLyr(ihit)" << hitlyr << " mchitid=" << mchitid << " globalHitInfo[mchitid].mcTrackID()=" << globalHitInfo[mchitid].mcTrackID()); - if (globalHitInfo[mchitid].mcTrackID() == label) nHitsMatched++; + if (globalHitInfo[mchitid].mcTrackID() == seedID_) nHitsMatched++; } } @@ -124,7 +119,7 @@ void TrackExtra::setMCTrackIDInfoByLabel(const Track& trk, const std::vector= nCandHits) mcTrackID_ = label; + if (2*nHitsMatched >= nCandHits) mcTrackID_ = seedID_; else mcTrackID_ = -1; // Modify mcTrackID based on nMinHits @@ -144,7 +139,7 @@ void TrackExtra::setMCTrackIDInfoByLabel(const Track& trk, const std::vector for seeding or CMSSW-like building diff --git a/validation-desc.txt b/validation-desc.txt index 3aac9a9cae6ba..4f7ed7caa796e 100644 --- a/validation-desc.txt +++ b/validation-desc.txt @@ -35,8 +35,8 @@ The building validation takes advantage of filling two trees per event per track - cmsswfrtree (filled once per mkFit build track) [1.] validation exists in the following combinations of geometry and seed source: -- ToyMC, with sim seeds or find-seeds -- CMSSW, with sim seeds or cmssw-seeds + - ToyMC, with sim seeds or find-seeds + - CMSSW, with sim seeds or cmssw-seeds Upon instantiation of the TTreeValidation object, the respective ROOT trees are defined and allocated on the heap, along with setting the addresses of all the branches. After the building is completed in mkFit, we have to have the tracks in their standard event containers, namely: seedTracks_, candidateTracks_, and fitTracks_. In the standard combinatorial or clone engine, we have to copy out the built tracks from event of combined candiates into candidateTracks_ via: builder.quality_store_tracks() in mkFit/buildtestMPlex.cc. Since we do not yet have fitting after building, we just set the fitTracks_ equal to the candidateTracks_. For ease, I will from now on refer to the candidateTracks_ as buildTracks_. @@ -108,7 +108,7 @@ The following routines are then called after the building (MkBuilder.cc, Event.c - prep_tracks(tracks,extras) : Loop over all tracks in consideration : sort hits inside track by layer : needed for counting unique layers and for association routines - : emplace_back a track extra, initialized with the label of the track (which happens to be its seed ID) + : emplace_back a track extra, initialized with the label of the track (which happens to be its seed ID) // if using sim seeds, we know that seed ID == sim ID : m_event->validation_.alignTracks(tracks,extras,alignExtra) - alignTracks(tracks,extras,alignExtra) @@ -146,10 +146,10 @@ The following routines are then called after the building (MkBuilder.cc, Event.c : loop over build tracks : setCMSSWTrackIDInfo() : require matching by chi2 and dphi -- setMCTrackIDInfoByLabel(label) +- setMCTrackIDInfoByLabel() : if no hits are found after seed, mcTrackID == -4, and skip the rest of the function : Loop over found hits on build track after seed - : count the hits who have a mcTrackID == label (i.e. seedID == simTrack label == mcTrackID) + : count the hits who have a mcTrackID == seedID_ (i.e. seedID == simTrack label == mcTrackID) : if 50% are matched, mcTrackID == label : else, mcTrackID == -1 : if (track.nFoundHits() < [Config::nMinFoundHits == 7] - [Config::nlayers_per_seed == 4 or 3]) @@ -340,10 +340,10 @@ Same as above, but now only run with cmssw seeds (as we are comparing directly t *** Originally from mkFit/MkBuilder.cc *** All built candidate tracks have all hit indices pointing to m_event_of_hits.m_layers_of_hits[layer].m_hits (LOH) -MC seeds (both CMSSW and toyMC) have seed hit indices pointing to global HitVec m_event->layerHits_[layer] (GLH) -"Real" seeds have all seed hit indices pointing to LOH. +MC seeds (both CMSSW and toyMC),as well as CMSSW seeds, have seed hit indices pointing to global HitVec m_event->layerHits_[layer] (GLH) +Found seeds from our code have all seed hit indices pointing to LOH. So.. to have universal seed fitting function --> have seed hits point to LOH no matter their origin. -This means that all MC seeds must be "mapped" from GLH to LOH: map_seed_hits(). +This means that all MC and CMSSW seeds must be "mapped" from GLH to LOH: map_seed_hits(). Now InputTracksAndHits() for seed fit will use LOH instead of GLH. The output tracks of the seed fitting are now stored in m_event->seedTracks_. @@ -357,10 +357,10 @@ W/ ROOT uses the TTreValidation class which needs seedTracks_, candidateTracks_, The fitTracks_ collection for now is just a copy of candidateTracks_ (eventually may have cuts and things that affect which tracks to fit). So... need to "remap" seedTracks_ hits from LOH to GLH with remap_seed_hits(). And also copy in tracks from EtaBin* to candidateTracks_, and then remap hits from LOH to GLH with quality_store_tracks() and remap_cand_hits(). -W/ ROOT uses root_val_BH for BH, and root_val_COMB() for non-BH. +W/ ROOT uses root_val() W/O ROOT is a bit simpler... as we only need to do the copy out tracks from EtaBin* and then remap just candidateTracks_. -This uses quality_output_COMB() or quality_output_BH() +This uses quality_output() N.B.1 Since fittestMPlex at the moment is not "end-to-end" with candidate tracks, we can still use the GLH version of InputTracksAndHits() N.B.2 Since we inflate LOH by 2% more than GLH, hit indices in building only go to GLH, so all loops are sized to GLH. diff --git a/validation-snb-cmssw-fulldet-build-extrectracks.sh b/validation-snb-cmssw-10mu-fulldet-build-extrectracks.sh similarity index 100% rename from validation-snb-cmssw-fulldet-build-extrectracks.sh rename to validation-snb-cmssw-10mu-fulldet-build-extrectracks.sh diff --git a/validation-snb-cmssw-fulldet-build.sh b/validation-snb-cmssw-10mu-fulldet-build.sh similarity index 100% rename from validation-snb-cmssw-fulldet-build.sh rename to validation-snb-cmssw-10mu-fulldet-build.sh diff --git a/validation-snb-cmssw-PU70-fulldet-build-extrectracks.sh b/validation-snb-cmssw-PU70-fulldet-build-extrectracks.sh new file mode 100755 index 0000000000000..b917f64513a95 --- /dev/null +++ b/validation-snb-cmssw-PU70-fulldet-build-extrectracks.sh @@ -0,0 +1,28 @@ +#! /bin/bash + +make -j 12 WITH_ROOT=yes CPPUSERFLAGS+=-DCLEAN_SEEDS CXXUSERFLAGS+=-DCLEAN_SEEDS + +dir=/data/nfsmic/slava77/samples/2017/pass-4874f28/initialStep/PU70/10224.0_TTbar_13+TTbar_13TeV_TuneCUETP8M1_2017PU_GenSimFullINPUT+DigiFullPU_2017PU+RecoFullPU_2017PU+HARVESTFullPU_2017PU +file=memoryFile.fv3.clean.writeAll.recT.072617.bin + +base=SNB_CMSSW_PU70 + +for bV in "BH bh" "STD std" "CE ce" +do echo $bV | while read -r bN bO + do + oBase=${base}_${bN} + echo "${oBase}: validation [nTH:24, nVU:8]" + ./mkFit/mkFit --cmssw-seeds --geom CMS-2017 --cmssw-val --ext-rec-tracks --read --file-name ${dir}/${file} --build-${bO} --num-thr 24 >& log_${oBase}_NVU8int_NTH24_cmsswval.txt + mv valtree.root valtree_${oBase}.root + done +done + +make clean + +for build in BH STD CE +do + root -b -q -l runValidation.C\(\"_${base}_${build}\",0,1\) +done +root -b -q -l makeValidation.C\(\"${base}\",1\) + +make distclean From 8c9d067309c334d6b109822002e9e9ecf909fb7b Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Wed, 9 Aug 2017 15:15:17 -0700 Subject: [PATCH 140/172] aesthetic updates to web move scripts --- ....sh => move-cmsswval-10mu-extrectracks.sh} | 23 ++++++------ ...move-cmsswval.sh => move-cmsswval-10mu.sh} | 21 ++++++----- web/move-cmsswval-pu70-extrectracks.sh | 37 +++++++++++++++++++ web/move-cmsswval-pu70.sh | 19 +++++----- web/move-toymcval.sh | 17 +++++---- 5 files changed, 79 insertions(+), 38 deletions(-) rename web/{move-cmsswval-extrectracks.sh => move-cmsswval-10mu-extrectracks.sh} (53%) rename web/{move-cmsswval.sh => move-cmsswval-10mu.sh} (65%) create mode 100755 web/move-cmsswval-pu70-extrectracks.sh diff --git a/web/move-cmsswval-extrectracks.sh b/web/move-cmsswval-10mu-extrectracks.sh similarity index 53% rename from web/move-cmsswval-extrectracks.sh rename to web/move-cmsswval-10mu-extrectracks.sh index ce0de3cdcd8ff..df30ea57e7c61 100755 --- a/web/move-cmsswval-extrectracks.sh +++ b/web/move-cmsswval-10mu-extrectracks.sh @@ -1,34 +1,35 @@ #!/bin/bash -dir=${1:-cmsswval-ext} +dir=${1:-plots} +outdir=${dir}/cmsswval-10mu-extrectracks base=SNB_CMSSW_10mu -echo "Moving plots and text files locally to ${dir}" +echo "Moving plots and text files locally to ${outdir}" for region in ECN2 ECN1 BRL ECP1 ECP2 FullDet do - outdir=${dir}/${region} - mkdir -p ${outdir} + fulldir=${outdir}/${region} + mkdir -p ${fulldir} - mv ${base}_${region}_*.png ${outdir} + mv ${base}_${region}_*.png ${fulldir} for build in BH STD CE do vbase=validation_${base}_${region}_${build} - mv ${vbase}/totals_${vbase}_cmssw.txt ${outdir} + mv ${vbase}/totals_${vbase}_cmssw.txt ${fulldir} done done -mv ${dir}/FullDet/*png ${dir}/FullDet/*txt ${dir} -rm -rf ${dir}/FullDet +mv ${outdir}/FullDet/*png ${outdir}/FullDet/*txt ${outdir} +rm -rf ${outdir}/FullDet host=kmcdermo@lxplus.cern.ch whost=${host}":~/www" -echo "Moving plots and text files remotly to ${whost}" +echo "Moving plots and text files remotely to ${whost}" scp -r ${dir} ${whost} -echo "Executing remotely ./makereadable.sh ${dir}" +echo "Executing remotely ./makereadable.sh ${outdir}" ssh ${host} bash -c "' cd www -./makereadable.sh ${dir} +./makereadable.sh ${outdir} exit '" diff --git a/web/move-cmsswval.sh b/web/move-cmsswval-10mu.sh similarity index 65% rename from web/move-cmsswval.sh rename to web/move-cmsswval-10mu.sh index 64b0fc1a12a47..d83ee246908ba 100755 --- a/web/move-cmsswval.sh +++ b/web/move-cmsswval-10mu.sh @@ -1,38 +1,39 @@ #!/bin/bash -dir=${1:-cmsswval} +dir=${1:-plots} +outdir=${dir}/cmsswval-10mu base=SNB_CMSSW_10mu -echo "Moving plots and text files locally to ${dir}" +echo "Moving plots and text files locally to ${outdir}" for seed in SimSeed CMSSeed do for region in ECN2 ECN1 BRL ECP1 ECP2 FullDet do - outdir=${dir}/${seed}/${region} - mkdir -p ${outdir} + fulldir=${outdir}/${seed}/${region} + mkdir -p ${fulldir} srbase=${seed}_${region} - mv ${base}_${srbase}_*.png ${outdir} + mv ${base}_${srbase}_*.png ${fulldir} for build in BH STD CE do vbase=validation_${base}_${srbase}_${build} - mv ${vbase}/totals_${vbase}.txt ${outdir} + mv ${vbase}/totals_${vbase}.txt ${fulldir} done done - sdir=${dir}/${seed} + sdir=${outdir}/${seed} mv ${sdir}/FullDet/*png ${sdir}/FullDet/*txt ${sdir} rm -rf ${sdir}/FullDet done host=kmcdermo@lxplus.cern.ch whost=${host}":~/www" -echo "Moving plots and text files remotly to ${whost}" +echo "Moving plots and text files remotely to ${whost}" scp -r ${dir} ${whost} -echo "Executing remotely ./makereadable.sh ${dir}" +echo "Executing remotely ./makereadable.sh ${outdir}" ssh ${host} bash -c "' cd www -./makereadable.sh ${dir} +./makereadable.sh ${outdir} exit '" diff --git a/web/move-cmsswval-pu70-extrectracks.sh b/web/move-cmsswval-pu70-extrectracks.sh new file mode 100755 index 0000000000000..fd9f4f64ba9e1 --- /dev/null +++ b/web/move-cmsswval-pu70-extrectracks.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +dir=${1:-plots} +outdir=${dir}/cmsswval-pu70-extrectracks +base=SNB_CMSSW_PU70 + +echo "Moving plots and text files locally to ${outdir}" + +mkdir -p ${outdir} +mv ${base}_*.png ${outdir} +for build in BH STD CE +do + vbase=validation_${base}_${build} + mv ${vbase}/totals_${vbase}_cmssw.txt ${outdir} +done + +host=kmcdermo@lxplus.cern.ch +whost=${host}":~/www" +echo "Moving plots and text files remotely to ${whost}" +scp -r ${dir} ${whost} + +echo "Executing remotely ./makereadable.sh ${outdir}" +ssh ${host} bash -c "' +cd www +./makereadable.sh ${outdir} +exit +'" + +echo "Removing local files" +for build in BH STD CE +do + testbase=${base}_${build} + rm -rf validation_${testbase} + rm -rf log_${testbase}_NVU8int_NTH24_cmsswval.txt +done + +rm -rf ${dir} diff --git a/web/move-cmsswval-pu70.sh b/web/move-cmsswval-pu70.sh index ba92f306e4b34..012605ccd86c8 100755 --- a/web/move-cmsswval-pu70.sh +++ b/web/move-cmsswval-pu70.sh @@ -1,31 +1,32 @@ #!/bin/bash -dir=${1:-cmsswval-pu70} +dir=${1:-plots} +outdir=${dir}/cmsswval-pu70 base=SNB_CMSSW_PU70 -echo "Moving plots and text files locally to ${dir}" +echo "Moving plots and text files locally to ${outdir}" for seed in SimSeed CMSSeed do - outdir=${dir}/${seed} - mkdir -p ${outdir} + fulldir=${outdir}/${seed} + mkdir -p ${fulldir} - mv ${base}_${seed}_*.png ${outdir} + mv ${base}_${seed}_*.png ${fulldir} for build in BH STD CE do vbase=validation_${base}_${seed}_${build} - mv ${vbase}/totals_${vbase}.txt ${outdir} + mv ${vbase}/totals_${vbase}.txt ${fulldir} done done host=kmcdermo@lxplus.cern.ch whost=${host}":~/www" -echo "Moving plots and text files remotly to ${whost}" +echo "Moving plots and text files remotely to ${whost}" scp -r ${dir} ${whost} -echo "Executing remotely ./makereadable.sh ${dir}" +echo "Executing remotely ./makereadable.sh ${outdir}" ssh ${host} bash -c "' cd www -./makereadable.sh ${dir} +./makereadable.sh ${outdir} exit '" diff --git a/web/move-toymcval.sh b/web/move-toymcval.sh index 90539a30c4c20..af2f6d4990553 100755 --- a/web/move-toymcval.sh +++ b/web/move-toymcval.sh @@ -1,26 +1,27 @@ #!/bin/bash -dir=${1:-toymcval} +dir=${1:-plots} +outdir=${dir}/toymcval base=SNB_ToyMC_FullDet -echo "Moving plots and text files locally to ${dir}" -mkdir -p ${dir} -mv ${base}_*.png ${dir} +echo "Moving plots and text files locally to ${outdir}" +mkdir -p ${outdir} +mv ${base}_*.png ${outdir} for build in BH STD CE do vbase=validation_${base}_${build} - mv ${vbase}/totals_${vbase}.txt ${dir} + mv ${vbase}/totals_${vbase}.txt ${outdir} done host=kmcdermo@lxplus.cern.ch whost=${host}":~/www" -echo "Moving plots and text files remotly to ${whost}" +echo "Moving plots and text files remotely to ${whost}" scp -r ${dir} ${whost} -echo "Executing remotely ./makereadable.sh ${dir}" +echo "Executing remotely ./makereadable.sh ${outdir}" ssh ${host} bash -c "' cd www -./makereadable.sh ${dir} +./makereadable.sh ${outdir} exit '" From b31dc7b98c3386e51e5173d5cf9e34fabc87504a Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Thu, 10 Aug 2017 06:04:11 -0700 Subject: [PATCH 141/172] include a pt cut inside the validation plotter, update manifesto --- PlotValidation.cpp | 535 +++++++++++++++++++++++++------------------- PlotValidation.hh | 2 + makeValidation.C | 75 ++++--- validation-desc.txt | 19 +- 4 files changed, 361 insertions(+), 270 deletions(-) diff --git a/PlotValidation.cpp b/PlotValidation.cpp index 5f618fad9e07e..3279a93a193f0 100644 --- a/PlotValidation.cpp +++ b/PlotValidation.cpp @@ -110,6 +110,7 @@ void PlotValidation::PlotEfficiency() const TStrVec vars = {"pt","eta","phi"}; const TStrVec svars = {"p_{T}","#eta","#phi"}; // svars --> labels for histograms for given variable const TStrVec sunits= {" [GeV/c]","",""}; // units --> labels for histograms for given variable + const FltVec ptcuts= {0.f,0.9f,2.f}; const IntVec nBins = {60,60,80}; const FltVec xlow = {0,-3,-4}; const FltVec xhigh = {15,3,4}; @@ -117,25 +118,27 @@ void PlotValidation::PlotEfficiency() const TStrVec trks = (fCmsswComp ? TStrVec{"build"} : TStrVec{"seed","build","fit"}); const TStrVec strks = (fCmsswComp ? TStrVec{"Build"} : TStrVec{"Seed","Build","Fit"}); // strk --> labels for histograms for given track type - // Floats/Ints to be filled for trees - FltVec mcvars_val(vars.size()); // first index is var. only for mc values! so no extra index - IntVec mcmask_trk(trks.size()); // need to know if sim track associated to a given reco track type - // Create plots - TEffRefVecVec varsEff(vars.size()); + TEffRefVecVecVec varsEff(vars.size()); for (UInt_t i = 0; i < vars.size(); i++) { varsEff[i].resize(trks.size()); for (UInt_t j = 0; j < trks.size(); j++) { - varsEff[i][j] = new TEfficiency(Form("eff_%s_%s_%s",(fCmsswComp?"cmssw":"sim"),vars[i].Data(),trks[j].Data()), - Form("%s Track Efficiency vs %s %s;%s;Efficiency", - strks[j].Data(),(fCmsswComp?"CMSSW Reco":"MC"),svars[i].Data(),svars[i].Data(),sunits[i].Data()), - nBins[i],xlow[i],xhigh[i]); + varsEff[i][j].resize(ptcuts.size()); + for (UInt_t p = 0; p < ptcuts.size(); p++) + { + varsEff[i][j][p] = new TEfficiency(Form("eff_%s_%s_%s_pt%3.1f",(fCmsswComp?"cmssw":"sim"),vars[i].Data(),trks[j].Data(),ptcuts[p]), + Form("%s Track Efficiency vs %s %s [p_{T} > %3.1f GeV/c];%s%s;Efficiency", + strks[j].Data(),(fCmsswComp?"CMSSW Reco":"MC"),svars[i].Data(),ptcuts[p],svars[i].Data(),sunits[i].Data()), + nBins[i],xlow[i],xhigh[i]); + } } } + // Floats/Ints to be filled for trees //Initialize var_val/err arrays, SetBranchAddress + FltVec mcvars_val(vars.size()); // first index is var. only for mc values! so no extra index for (UInt_t i = 0; i < vars.size(); i++) // loop over trks index { // initialize var @@ -146,6 +149,7 @@ void PlotValidation::PlotEfficiency() } //Initialize masks, set branch addresses + IntVec mcmask_trk(trks.size()); // need to know if sim track associated to a given reco track type for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index { mcmask_trk[j] = 0; @@ -160,10 +164,14 @@ void PlotValidation::PlotEfficiency() { for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index { - if (mcmask_trk[j] != -1) + for (UInt_t p = 0; p < ptcuts.size(); p++) // loop over pt cuts { - varsEff[i][j]->Fill((mcmask_trk[j]==1),mcvars_val[i]); // mc track must be associated to enter numerator - } + if (mcvars_val[0] < ptcuts[p]) continue; // cut on tracks with a low pt + if (mcmask_trk[j] != -1) + { + varsEff[i][j][p]->Fill((mcmask_trk[j]==1),mcvars_val[i]); // mc track must be associated to enter numerator + } + } // end loop over pt cuts } // end loop over trks } // end loop over vars } // end loop over entry in tree @@ -173,8 +181,11 @@ void PlotValidation::PlotEfficiency() { for (UInt_t j = 0; j < trks.size(); j++) { - PlotValidation::DrawWriteSaveTEffPlot(subdir,varsEff[i][j],subdirname,Form("eff_%s_%s",vars[i].Data(),trks[j].Data())); - delete varsEff[i][j]; + for (UInt_t p = 0; p < ptcuts.size(); p++) + { + PlotValidation::DrawWriteSaveTEffPlot(subdir,varsEff[i][j][p],subdirname,Form("eff_%s_%s_pt%3.1f",vars[i].Data(),trks[j].Data(),ptcuts[p])); + delete varsEff[i][j][p]; + } } } delete efftree; @@ -198,6 +209,7 @@ void PlotValidation::PlotInefficiencyVsGeom() const TStrVec vars = {"pt","eta","phi"}; const TStrVec svars = {"p_{T}","#eta","#phi"}; // svars --> labels for histograms for given variable const TStrVec sunits= {" [GeV/c]","",""}; // units --> labels for histograms for given variable + const FltVec ptcuts= {0.f,0.9f,2.f}; const IntVec nBins = {60,60,80}; const FltVec xlow = {0,-3,-4}; const FltVec xhigh = {15,3,4}; @@ -208,12 +220,8 @@ void PlotValidation::PlotInefficiencyVsGeom() const TStrVec trks = (fCmsswComp ? TStrVec{"build"} : TStrVec{"seed","build","fit"}); const TStrVec strks = (fCmsswComp ? TStrVec{"Build"} : TStrVec{"Seed","Build","Fit"}); // strk --> labels for histograms for given track type - // Floats/Ints to be filled for trees - FltVec mcvars_val(vars.size()); // first index is var. only for mc values! so no extra index - IntVec mcmask_trk(trks.size()); // need to know if sim track associated to a given reco track type - // Create plots - TEffRefVecVecVec varsIneff(regs.size()); + TEffRefVecVecVecVec varsIneff(regs.size()); for (UInt_t h = 0; h < regs.size(); h++) { varsIneff[h].resize(vars.size()); @@ -222,16 +230,22 @@ void PlotValidation::PlotInefficiencyVsGeom() varsIneff[h][i].resize(trks.size()); for (UInt_t j = 0; j < trks.size(); j++) { - // Efficiency - varsIneff[h][i][j] = new TEfficiency(Form("ineff_%s_%s_%s_%s",regs[h].Data(),(fCmsswComp?"cmssw":"sim"),vars[i].Data(),trks[j].Data()), - Form("%s Track Inefficiency vs %s %s %s;%s%s;Inefficiency", - strks[j].Data(),(fCmsswComp?"CMSSW Reco":"MC"),svars[i].Data(),sregs[h].Data(),svars[i].Data(),sunits[i].Data()), - nBins[i],xlow[i],xhigh[i]); + varsIneff[h][i][j].resize(ptcuts.size()); + for (UInt_t p = 0; p < ptcuts.size(); p++) + { + // Efficiency + varsIneff[h][i][j][p] = new TEfficiency(Form("ineff_%s_%s_%s_%s_pt%3.1f",regs[h].Data(),(fCmsswComp?"cmssw":"sim"),vars[i].Data(),trks[j].Data(),ptcuts[p]), + Form("%s Track Inefficiency vs %s %s %s [p_{T} > %3.1f GeV/c];%s%s;Inefficiency", + strks[j].Data(),(fCmsswComp?"CMSSW Reco":"MC"),svars[i].Data(),sregs[h].Data(),ptcuts[p],svars[i].Data(),sunits[i].Data()), + nBins[i],xlow[i],xhigh[i]); + } } } } + // Floats/Ints to be filled for trees //Initialize var_val/err arrays, SetBranchAddress + FltVec mcvars_val(vars.size()); // first index is var. only for mc values! so no extra index for (UInt_t i = 0; i < vars.size(); i++) // loop over trks index { // initialize var @@ -242,6 +256,7 @@ void PlotValidation::PlotInefficiencyVsGeom() } //Initialize masks, set branch addresses + IntVec mcmask_trk(trks.size()); // need to know if sim track associated to a given reco track type for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index { mcmask_trk[j] = 0; @@ -261,10 +276,14 @@ void PlotValidation::PlotInefficiencyVsGeom() { for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index { - if (mcmask_trk[j] != -1) + for (UInt_t p = 0; p < ptcuts.size(); p++) { - varsIneff[h][i][j]->Fill((mcmask_trk[j] == 0),mcvars_val[i]); // mc track must be UNassociated to enter numerator - } + if (mcvars_val[0] < ptcuts[p]) continue; // pt cut + if (mcmask_trk[j] != -1) + { + varsIneff[h][i][j][p]->Fill((mcmask_trk[j] == 0),mcvars_val[i]); // mc track must be UNassociated to enter numerator + } + } // end loop over pt cuts } // end loop over trks } // end loop over vars } // end loop over regions @@ -277,8 +296,11 @@ void PlotValidation::PlotInefficiencyVsGeom() { for (UInt_t j = 0; j < trks.size(); j++) { - PlotValidation::DrawWriteSaveTEffPlot(subdir,varsIneff[h][i][j],subdirname,Form("ineff_%s_%s_%s",regs[h].Data(),vars[i].Data(),trks[j].Data())); - delete varsIneff[h][i][j]; + for (UInt_t p = 0; p < ptcuts.size(); p++) + { + PlotValidation::DrawWriteSaveTEffPlot(subdir,varsIneff[h][i][j][p],subdirname,Form("ineff_%s_%s_%s_pt%3.1f",regs[h].Data(),vars[i].Data(),trks[j].Data(),ptcuts[p])); + delete varsIneff[h][i][j][p]; + } } } } @@ -303,6 +325,7 @@ void PlotValidation::PlotFakeRate() const TStrVec vars = {"pt","eta","phi"}; const TStrVec svars = {"p_{T}","#eta","#phi"}; // svars --> labels for histograms for given variable const TStrVec sunits= {" [GeV/c]","",""}; // units --> labels for histograms for given variable + const FltVec ptcuts= {0.f,0.9f,2.f}; const IntVec nBins = {60,60,80}; const FltVec xlow = {0,-3,-4}; const FltVec xhigh = {15,3,4}; @@ -310,33 +333,31 @@ void PlotValidation::PlotFakeRate() const TStrVec trks = (fCmsswComp ? TStrVec{"build"} : TStrVec{"seed","build","fit"}); const TStrVec strks = (fCmsswComp ? TStrVec{"Build"} : TStrVec{"Seed","Build","Fit"}); // strk --> labels for histograms for given track type - // Floats/Ints to be filled for trees - FltVecVec recovars_val(vars.size()); // first index is var, second is type of track - for (UInt_t i = 0; i < vars.size(); i++) - { - recovars_val[i].resize(trks.size()); - } - - IntVec mcmask_trk(trks.size()); // need to know if sim track associated to a given reco track type - // Create FR plots - TEffRefVecVec varsFR(vars.size()); + TEffRefVecVecVec varsFR(vars.size()); for (UInt_t i = 0; i < vars.size(); i++) { varsFR[i].resize(trks.size()); for (UInt_t j = 0; j < trks.size(); j++) { - // Fake Rate - varsFR[i][j] = new TEfficiency(Form("fr_reco_%s_%s",vars[i].Data(),trks[j].Data()), - Form("%s Track Fake Rate vs Reco %s;%s%s;Fake Rate", - strks[j].Data(),svars[i].Data(),svars[i].Data(),sunits[i].Data()), - nBins[i],xlow[i],xhigh[i]); + varsFR[i][j].resize(ptcuts.size()); + for (UInt_t p = 0; p < ptcuts.size(); p++) + { + // Fake Rate + varsFR[i][j][p] = new TEfficiency(Form("fr_reco_%s_%s_pt%3.1f",vars[i].Data(),trks[j].Data(),ptcuts[p]), + Form("%s Track Fake Rate vs Reco %s [p_{T} > %3.1f GeV/c];%s%s;Fake Rate", + strks[j].Data(),svars[i].Data(),ptcuts[p],svars[i].Data(),sunits[i].Data()), + nBins[i],xlow[i],xhigh[i]); + } } } + // Floats/Ints to be filled for trees //Initialize var_val/err arrays, SetBranchAddress + FltVecVec recovars_val(vars.size()); // first index is var, second is type of track for (UInt_t i = 0; i < vars.size(); i++) // loop over vars index { + recovars_val[i].resize(trks.size()); for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index { // initialize var @@ -346,8 +367,9 @@ void PlotValidation::PlotFakeRate() frtree->SetBranchAddress(Form("%s_%s",vars[i].Data(),trks[j].Data()),&(recovars_val[i][j])); } } - + //Initialize masks, set branch addresses + IntVec mcmask_trk(trks.size()); // need to know if sim track associated to a given reco track type for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index { mcmask_trk[j] = 0; @@ -362,10 +384,14 @@ void PlotValidation::PlotFakeRate() { for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index { - if (mcmask_trk[j] != -1) // can include masks of 1,0,2 to enter denominator + for (UInt_t p = 0; p < ptcuts.size(); p++) // loop over pt cuts { - varsFR[i][j]->Fill((mcmask_trk[j] == 0),recovars_val[i][j]); // only completely unassociated reco tracks enter FR - } // must be a real reco track for FR + if (recovars_val[0][j] < ptcuts[p]) continue; // pt cut + if (mcmask_trk[j] != -1) // can include masks of 1,0,2 to enter denominator + { + varsFR[i][j][p]->Fill((mcmask_trk[j] == 0),recovars_val[i][j]); // only completely unassociated reco tracks enter FR + } // must be a real reco track for FR + } // end loop over pt cuts } // end loop over trks } // end loop over vars } // end loop over entry in tree @@ -375,8 +401,11 @@ void PlotValidation::PlotFakeRate() { for (UInt_t j = 0; j < trks.size(); j++) { - PlotValidation::DrawWriteSaveTEffPlot(subdir,varsFR[i][j],subdirname,Form("fr_%s_%s",vars[i].Data(),trks[j].Data())); - delete varsFR[i][j]; + for (UInt_t p = 0; p < ptcuts.size(); p++) + { + PlotValidation::DrawWriteSaveTEffPlot(subdir,varsFR[i][j][p],subdirname,Form("fr_%s_%s_pt%3.1f",vars[i].Data(),trks[j].Data(),ptcuts[p])); + delete varsFR[i][j][p]; + } } } delete frtree; @@ -400,6 +429,7 @@ void PlotValidation::PlotDuplicateRate() const TStrVec vars = {"pt","eta","phi"}; const TStrVec svars = {"p_{T}","#eta","#phi"}; // svars --> labels for histograms for given variable const TStrVec sunits= {" [GeV/c]","",""}; // units --> labels for histograms for given variable + const FltVec ptcuts= {0.f,0.9f,2.f}; const IntVec nBins = {60,60,80}; const FltVec xlow = {0,-3,-4}; const FltVec xhigh = {15,3,4}; @@ -407,27 +437,28 @@ void PlotValidation::PlotDuplicateRate() const TStrVec trks = (fCmsswComp ? TStrVec{"build"} : TStrVec{"seed","build","fit"}); const TStrVec strks = (fCmsswComp ? TStrVec{"Build"} : TStrVec{"Seed","Build","Fit"}); // strk --> labels for histograms for given track type - // Floats/Ints to be filled for trees - FltVec mcvars_val(vars.size()); // first index is var. only for mc values! so no extra index - IntVec mcmask_trk(trks.size()); // need to know if sim track associated to a given reco track type - IntVec nTkMatches_trk(trks.size()); // need to know how many duplicates each mc track produces. nDupl == 1 means one reco track - // Create DR plots - TEffRefVecVec varsDR(vars.size()); + TEffRefVecVecVec varsDR(vars.size()); for (UInt_t i = 0; i < vars.size(); i++) { varsDR[i].resize(trks.size()); for (UInt_t j = 0; j < trks.size(); j++) { - // Duplicate Rate - varsDR[i][j] = new TEfficiency(Form("dr_%s_%s_%s",(fCmsswComp?"cmssw":"sim"),vars[i].Data(),trks[j].Data()), - Form("%s Track Duplicate Rate vs %s %s;%s%s;Duplicate Rate", - strks[j].Data(),(fCmsswComp?"CMSSW":"MC"),svars[i].Data(),svars[i].Data(),sunits[i].Data()), - nBins[i],xlow[i],xhigh[i]); + varsDR[i][j].resize(ptcuts.size()); + for (UInt_t p = 0; p < ptcuts.size(); p++) + { + // Duplicate Rate + varsDR[i][j][p] = new TEfficiency(Form("dr_%s_%s_%s_pt%3.1f",(fCmsswComp?"cmssw":"sim"),vars[i].Data(),trks[j].Data(),ptcuts[p]), + Form("%s Track Duplicate Rate vs %s %s [p_{T} > %3.1f GeV/c];%s%s;Duplicate Rate", + strks[j].Data(),(fCmsswComp?"CMSSW":"MC"),svars[i].Data(),ptcuts[p],svars[i].Data(),sunits[i].Data()), + nBins[i],xlow[i],xhigh[i]); + } } } + // Floats/Ints to be filled for trees //Initialize var_val/err arrays, SetBranchAddress + FltVec mcvars_val(vars.size()); // first index is var. only for mc values! so no extra index for (UInt_t i = 0; i < vars.size(); i++) // loop over trks index { // initialize var @@ -438,6 +469,8 @@ void PlotValidation::PlotDuplicateRate() } //Initialize masks, set branch addresses + IntVec mcmask_trk(trks.size()); // need to know if sim track associated to a given reco track type + IntVec nTkMatches_trk(trks.size()); // need to know how many duplicates each mc track produces. nDupl == 1 means one reco track for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index { mcmask_trk[j] = 0; @@ -455,15 +488,13 @@ void PlotValidation::PlotDuplicateRate() { for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index { - if (mcmask_trk[j] == 1) // need to be matched at least once + for (UInt_t p = 0; p < ptcuts.size(); p++) // loop over pt cuts { - // KM: At the moment, no support for TEfficiency to create weight numerator and NOT denominator - // fill n-1 times sim track is matched. e.g. numer not filled if one sim to one reco, numer filled once if two reco to one sim, etc. - // varsDR[i][j]->SetUseWeightedEvents(); - // varsDR[i][j]->FillWeighted(nTkMatches_trk[j]>1,nTkMatches_trk[j],mcvars_val[i]); - - // KM: As a result, DR is simply if a sim track is duplicated once, and not how many times it is duplicated - varsDR[i][j]->Fill(nTkMatches_trk[j]>1,mcvars_val[i]); + if (mcvars_val[0] < ptcuts[p]) continue; + if (mcmask_trk[j] == 1) // need to be matched at least once + { + varsDR[i][j][p]->Fill(nTkMatches_trk[j]>1,mcvars_val[i]); + } } // must be a matched track for proper denom } // end loop over trks } // end loop over vars @@ -474,8 +505,11 @@ void PlotValidation::PlotDuplicateRate() { for (UInt_t j = 0; j < trks.size(); j++) { - PlotValidation::DrawWriteSaveTEffPlot(subdir,varsDR[i][j],subdirname,Form("dr_%s_%s",vars[i].Data(),trks[j].Data())); - delete varsDR[i][j]; + for (UInt_t p = 0; p < ptcuts.size(); p++) + { + PlotValidation::DrawWriteSaveTEffPlot(subdir,varsDR[i][j][p],subdirname,Form("dr_%s_%s_pt%3.1f",vars[i].Data(),trks[j].Data(),ptcuts[p])); + delete varsDR[i][j][p]; + } } } delete efftree; @@ -498,55 +532,60 @@ void PlotValidation::PlotNHits() //Declare strings for branches and plots const TStrVec trks = (fCmsswComp ? TStrVec{"build"} : TStrVec{"seed","build","fit"}); const TStrVec strks = (fCmsswComp ? TStrVec{"Build"} : TStrVec{"Seed","Build","Fit"}); // strk --> labels for histograms + const FltVec ptcuts= {0.f,0.9f,2.f}; const TStrVec coll = {"allreco","fake","allmatch","bestmatch"}; const TStrVec scoll = {"All Reco","Fake","All Match","Best Match"}; - // Floats/Ints to be filled for trees - IntVec nHits_trk(trks.size()); - FltVec fracHitsMatched_trk(trks.size()); - - // masks - IntVec mcmask_trk(trks.size()); // need to know if sim track associated to a given reco track type - IntVec iTkMatches_trk(trks.size()); - // Create plots - TH1FRefVecVec nHitsPlot(trks.size()); - TH1FRefVecVec fracHitsMatchedPlot(trks.size()); + TH1FRefVecVecVec nHitsPlot(trks.size()); + TH1FRefVecVecVec fracHitsMatchedPlot(trks.size()); for (UInt_t j = 0; j < trks.size(); j++) { nHitsPlot[j].resize(coll.size()); fracHitsMatchedPlot[j].resize(coll.size()); - } - - for (UInt_t j = 0; j < trks.size(); j++) - { for (UInt_t c = 0; c < coll.size(); c++) { - // Numerator only type plots only! - nHitsPlot[j][c] = new TH1F(Form("h_nHits_%s_%s",coll[c].Data(),trks[j].Data()),Form("%s %s Track vs nHits / Track",scoll[c].Data(),strks[j].Data()),30,0,30); - nHitsPlot[j][c]->GetXaxis()->SetTitle("nHits / Track"); - nHitsPlot[j][c]->GetYaxis()->SetTitle("nTracks"); - nHitsPlot[j][c]->Sumw2(); - - fracHitsMatchedPlot[j][c] = new TH1F(Form("h_fracHitsMatched_%s_%s",coll[c].Data(),trks[j].Data()),Form("%s %s Track vs Highest Fraction of Matched Hits / Track",scoll[c].Data(),strks[j].Data()),4000,0,1.1); - fracHitsMatchedPlot[j][c]->GetXaxis()->SetTitle("Highest Fraction of Matched Hits / Track"); - fracHitsMatchedPlot[j][c]->GetYaxis()->SetTitle("nTracks"); - fracHitsMatchedPlot[j][c]->Sumw2(); + nHitsPlot[j][c].resize(ptcuts.size()); + fracHitsMatchedPlot[j][c].resize(ptcuts.size()); + for (UInt_t p = 0; p < ptcuts.size(); p++) + { + // Numerator only type plots only! + nHitsPlot[j][c][p] = new TH1F(Form("h_nHits_%s_%s_pt%3.1f",coll[c].Data(),trks[j].Data(),ptcuts[p]), + Form("%s %s Track vs nHits / Track [p_{T} > %3.1f GeV/c];nHits / Track;nTracks",scoll[c].Data(),strks[j].Data(),ptcuts[p]), + 30,0,30); + nHitsPlot[j][c][p]->Sumw2(); + + fracHitsMatchedPlot[j][c][p] = new TH1F(Form("h_fracHitsMatched_%s_%s_pt%3.1f",coll[c].Data(),trks[j].Data(),ptcuts[p]), + Form("%s %s Track vs Highest Fraction of Matched Hits / Track [p_{T} > %3.1f];Highest Fraction of Matched Hits / Track;nTracks", + scoll[c].Data(),strks[j].Data(),ptcuts[p]), + 4000,0,1.1); + fracHitsMatchedPlot[j][c][p]->Sumw2(); + } } } //Initialize masks and variables, set branch addresses + // Floats/Ints to be filled for trees + IntVec nHits_trk(trks.size()); + FltVec fracHitsMatched_trk(trks.size()); + FltVec recopt_trk(trks.size()); + + // masks + IntVec mcmask_trk(trks.size()); // need to know if sim track associated to a given reco track type + IntVec iTkMatches_trk(trks.size()); for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index { mcmask_trk[j] = 0; iTkMatches_trk[j] = 0; nHits_trk[j] = 0; fracHitsMatched_trk[j] = 0; + recopt_trk[j] = 0; frtree->SetBranchAddress(Form("%smask_%s",(fCmsswComp?"cmssw":"mc"),trks[j].Data()),&(mcmask_trk[j])); frtree->SetBranchAddress(Form("iTkMatches_%s",trks[j].Data()),&(iTkMatches_trk[j])); frtree->SetBranchAddress(Form("nHits_%s",trks[j].Data()),&(nHits_trk[j])); frtree->SetBranchAddress(Form("fracHitsMatched_%s",trks[j].Data()),&(fracHitsMatched_trk[j])); + frtree->SetBranchAddress(Form("pt_%s",trks[j].Data()),&(recopt_trk[j])); } // Fill histos, compute res/pull from tree branches @@ -557,49 +596,56 @@ void PlotValidation::PlotNHits() { for (UInt_t c = 0; c < coll.size(); c++) // loop over trk collection type { - if (c == 0) // all reco - { - nHitsPlot[j][c]->Fill(nHits_trk[j]); - fracHitsMatchedPlot[j][c]->Fill(fracHitsMatched_trk[j]); - } - else if (c == 1) // all fakes + for (UInt_t p = 0; p < ptcuts.size(); p++) { - if (mcmask_trk[j] == 0) - { - nHitsPlot[j][c]->Fill(nHits_trk[j]); - fracHitsMatchedPlot[j][c]->Fill(fracHitsMatched_trk[j]); + if (recopt_trk[j] < ptcuts[p]) continue; + if (c == 0) // all reco + { + nHitsPlot[j][c][p]->Fill(nHits_trk[j]); + fracHitsMatchedPlot[j][c][p]->Fill(fracHitsMatched_trk[j]); } - } - else if (c == 2) // all matches - { - if (mcmask_trk[j] == 1) - { - nHitsPlot[j][c]->Fill(nHits_trk[j]); - fracHitsMatchedPlot[j][c]->Fill(fracHitsMatched_trk[j]); + else if (c == 1) // all fakes + { + if (mcmask_trk[j] == 0) + { + nHitsPlot[j][c][p]->Fill(nHits_trk[j]); + fracHitsMatchedPlot[j][c][p]->Fill(fracHitsMatched_trk[j]); + } } - } - else if (c == 3) // best matches only - { - if ((mcmask_trk[j] == 1) && (iTkMatches_trk[j] == 0)) + else if (c == 2) // all matches { - nHitsPlot[j][c]->Fill(nHits_trk[j]); - fracHitsMatchedPlot[j][c]->Fill(fracHitsMatched_trk[j]); + if (mcmask_trk[j] == 1) + { + nHitsPlot[j][c][p]->Fill(nHits_trk[j]); + fracHitsMatchedPlot[j][c][p]->Fill(fracHitsMatched_trk[j]); + } } - } + else if (c == 3) // best matches only + { + if ((mcmask_trk[j] == 1) && (iTkMatches_trk[j] == 0)) + { + nHitsPlot[j][c][p]->Fill(nHits_trk[j]); + fracHitsMatchedPlot[j][c][p]->Fill(fracHitsMatched_trk[j]); + } + } + } // end loop over pt cuts } // end loop over trk type collection } // end loop over trks } // end loop over entry in tree - + // Draw and save nHits plots for (UInt_t j = 0; j < trks.size(); j++) { for (UInt_t c = 0; c < coll.size(); c++) // loop over trk collection type { - PlotValidation::DrawWriteSaveTH1FPlot(subdir,nHitsPlot[j][c],subdirname,Form("nHits_%s_%s",coll[c].Data(),trks[j].Data())); - PlotValidation::DrawWriteSaveTH1FPlot(subdir,fracHitsMatchedPlot[j][c],subdirname,Form("fracHitsMatched_%s_%s",coll[c].Data(),trks[j].Data())); - - delete nHitsPlot[j][c]; - delete fracHitsMatchedPlot[j][c]; + for (UInt_t p = 0; p < ptcuts.size(); p++) + { + PlotValidation::DrawWriteSaveTH1FPlot(subdir,nHitsPlot[j][c][p],subdirname,Form("nHits_%s_%s_pt%3.1f",coll[c].Data(),trks[j].Data(),ptcuts[p])); + PlotValidation::DrawWriteSaveTH1FPlot(subdir,fracHitsMatchedPlot[j][c][p],subdirname,Form("fracHitsMatched_%s_%s_pt%3.1f",coll[c].Data(),trks[j].Data(),ptcuts[p])); + + delete nHitsPlot[j][c][p]; + delete fracHitsMatchedPlot[j][c][p]; + } } } @@ -625,6 +671,7 @@ void PlotValidation::PlotMomResolutionPull() const TStrVec evars = {"ept","eeta","ephi"}; const TStrVec svars = {"p_{T}","#eta","#phi"}; // svars --> labels for histograms for given variable const TStrVec sunits = {" [GeV/c]","",""}; // units --> labels for histograms for given variable + const FltVec ptcuts = {0.f,0.9f,2.f}; const IntVec nBinsRes = {100,100,100}; const FltVec xlowRes = {-0.5,-0.5,-0.5}; const FltVec xhighRes = {0.5,0.5,0.5}; @@ -637,49 +684,48 @@ void PlotValidation::PlotMomResolutionPull() const TStrVec trks = {"seed","build","fit"}; const TStrVec strks = {"Seed","Build","Fit"}; // strk --> labels for histograms for given track type - // Floats/Ints to be filled for trees - FltVecVec mcvars_val(vars.size()); - IntVec mcmask_trk(trks.size()); // need to know if sim track associated to a given reco track type - FltVecVec recovars_val(vars.size()); // first index is nVars, second is nTrkTypes - FltVecVec recovars_err(vars.size()); - for (UInt_t i = 0; i < vars.size(); i++) - { - mcvars_val[i].resize(trks.size()); - recovars_val[i].resize(trks.size()); - recovars_err[i].resize(trks.size()); - } - FltVec vars_out = {0.,0.}; // res/pull output - // Create pos plots - TH1FRefVecVec varsResPlot(vars.size()); - TH1FRefVecVec varsPullPlot(vars.size()); - for (UInt_t i = 0; i < vars.size(); i++) + TH1FRefVecVecVec varsResPlot(vars.size()); + TH1FRefVecVecVec varsPullPlot(vars.size()); + for (UInt_t i = 0; i < vars.size(); i++) { varsResPlot[i].resize(trks.size()); varsPullPlot[i].resize(trks.size()); - } - - for (UInt_t i = 0; i < vars.size(); i++) - { for (UInt_t j = 0; j < trks.size(); j++) { - //Res - varsResPlot[i][j] = new TH1F(Form("h_%s_res_%s",vars[i].Data(),trks[j].Data()),Form("%s Resolution (%s Track vs. MC Track)",svars[i].Data(),strks[j].Data()),nBinsRes[i],xlowRes[i],xhighRes[i]); - varsResPlot[i][j]->GetXaxis()->SetTitle(Form("(%s^{%s}%s - %s^{mc}%s)/%s^{mc}%s",svars[i].Data(),strks[j].Data(),sunits[i].Data(),svars[i].Data(),sunits[i].Data(),svars[i].Data(),sunits[i].Data())); - varsResPlot[i][j]->GetYaxis()->SetTitle("nTracks"); - varsResPlot[i][j]->Sumw2(); - - //Pull - varsPullPlot[i][j] = new TH1F(Form("h_%s_pull_%s",vars[i].Data(),trks[j].Data()),Form("%s Pull (%s Track vs. MC Track)",svars[i].Data(),strks[j].Data()),nBinsPull[i],xlowPull[i],xhighPull[i]); - varsPullPlot[i][j]->GetXaxis()->SetTitle(Form("(%s^{%s}%s - %s^{mc}%s)/#sigma(%s^{%s})%s",svars[i].Data(),strks[j].Data(),sunits[i].Data(),svars[i].Data(),sunits[i].Data(),svars[i].Data(),strks[j].Data(),sunits[i].Data())); - varsPullPlot[i][j]->GetYaxis()->SetTitle("nTracks"); - varsPullPlot[i][j]->Sumw2(); + varsResPlot[i][j].resize(ptcuts.size()); + varsPullPlot[i][j].resize(ptcuts.size()); + for (UInt_t p = 0; p < ptcuts.size(); p++) + { + //Res + varsResPlot[i][j][p] = new TH1F(Form("h_%s_res_%s_pt%3.1f",vars[i].Data(),trks[j].Data(),ptcuts[p]), + Form("%s Resolution (%s Track vs. MC Track) [p_{T} > %3.1f GeV/c];(%s^{%s}%s - %s^{mc}%s)/%s^{mc}%s;nTracks", + svars[i].Data(),strks[j].Data(),ptcuts[p], + svars[i].Data(),strks[j].Data(),sunits[i].Data(),svars[i].Data(),sunits[i].Data(),svars[i].Data(),sunits[i].Data()), + nBinsRes[i],xlowRes[i],xhighRes[i]); + varsResPlot[i][j][p]->Sumw2(); + + //Pull + varsPullPlot[i][j][p] = new TH1F(Form("h_%s_pull_%s_pt%3.1f",vars[i].Data(),trks[j].Data(),ptcuts[p]), + Form("%s Pull (%s Track vs. MC Track) [p_{T} > %3.1f GeV/c];(%s^{%s}%s - %s^{mc}%s)/#sigma(%s^{%s})%s;nTracks", + svars[i].Data(),strks[j].Data(),ptcuts[p], + svars[i].Data(),strks[j].Data(),sunits[i].Data(),svars[i].Data(),sunits[i].Data(),svars[i].Data(),strks[j].Data(),sunits[i].Data()), + nBinsPull[i],xlowPull[i],xhighPull[i]); + varsPullPlot[i][j][p]->Sumw2(); + } } } + // Floats/Ints to be filled for trees //Initialize var_val/err arrays, SetBranchAddress + FltVecVec mcvars_val(vars.size()); + FltVecVec recovars_val(vars.size()); // first index is nVars, second is nTrkTypes + FltVecVec recovars_err(vars.size()); for (UInt_t i = 0; i < vars.size(); i++) // loop over var index { + mcvars_val[i].resize(trks.size()); + recovars_val[i].resize(trks.size()); + recovars_err[i].resize(trks.size()); for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index { // initialize var + errors @@ -695,6 +741,7 @@ void PlotValidation::PlotMomResolutionPull() } //Initialize masks, set branch addresses + IntVec mcmask_trk(trks.size()); // need to know if sim track associated to a given reco track type for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index { mcmask_trk[j] = 0; @@ -702,6 +749,7 @@ void PlotValidation::PlotMomResolutionPull() } // Fill histos, compute res/pull from tree branches + FltVec vars_out = {0.,0.}; // res/pull output for (Int_t k = 0; k < efftree->GetEntries(); k++) { efftree->GetEntry(k); @@ -709,18 +757,22 @@ void PlotValidation::PlotMomResolutionPull() { for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index { - if (mcmask_trk[j] == 1) // must be associated + for (UInt_t p = 0; p < ptcuts.size(); p++) // loop over pt cuts { - PlotValidation::ComputeResolutionPull(mcvars_val[i][j],recovars_val[i][j],recovars_err[i][j],vars_out); - if (!isnan(vars_out[0])) // fill if not nan - { - varsResPlot[i][j]->Fill(vars_out[0]); - } - if (!isnan(vars_out[1])) // fill if not nan + if (mcvars_val[0][j] < ptcuts[p]) continue; + if (mcmask_trk[j] == 1) // must be associated { - varsPullPlot[i][j]->Fill(vars_out[1]); - } - } // must be a matched track to make resolution plots + PlotValidation::ComputeResolutionPull(mcvars_val[i][j],recovars_val[i][j],recovars_err[i][j],vars_out); + if (!isnan(vars_out[0])) // fill if not nan + { + varsResPlot[i][j][p]->Fill(vars_out[0]); + } + if (!isnan(vars_out[1])) // fill if not nan + { + varsPullPlot[i][j][p]->Fill(vars_out[1]); + } + } // must be a matched track to make resolution plots + } // end loop over pt cuts } // end loop over trks } // end loop over vars } // end loop over entry in tree @@ -730,10 +782,13 @@ void PlotValidation::PlotMomResolutionPull() { for (UInt_t j = 0; j < trks.size(); j++) { - PlotValidation::DrawWriteFitSaveTH1FPlot(subdir,varsResPlot[i][j],subdirname,Form("%s_resolution_%s",vars[i].Data(),trks[j].Data()),gausRes[i]); - PlotValidation::DrawWriteFitSaveTH1FPlot(subdir,varsPullPlot[i][j],subdirname,Form("%s_pull_%s",vars[i].Data(),trks[j].Data()),gausPull[i]); - delete varsResPlot[i][j]; - delete varsPullPlot[i][j]; + for (UInt_t p = 0; p < ptcuts.size(); p++) + { + PlotValidation::DrawWriteFitSaveTH1FPlot(subdir,varsResPlot[i][j][p],subdirname,Form("%s_resolution_%s_pt%3.1f",vars[i].Data(),trks[j].Data(),ptcuts[p]),gausRes[i]); + PlotValidation::DrawWriteFitSaveTH1FPlot(subdir,varsPullPlot[i][j][p],subdirname,Form("%s_pull_%s_pt%3.1f",vars[i].Data(),trks[j].Data(),ptcuts[p]),gausPull[i]); + delete varsResPlot[i][j][p]; + delete varsPullPlot[i][j][p]; + } } } delete efftree; @@ -752,14 +807,19 @@ void PlotValidation::PrintTotals() const TStrVec snumer = {Form("%s Tracks Matched",(fCmsswComp?"CMSSW":"Sim")),"Unmatched Reco Tracks",Form("%s Tracks Matched (nTimes>1)",(fCmsswComp?"CMSSW":"Sim"))}; const TStrVec sdenom = {Form("Eligible %s Tracks",(fCmsswComp?"CMSSW":"Sim")),"Eligible Reco Tracks",Form("Eligible %s Tracks",(fCmsswComp?"CMSSW":"Sim"))}; const TStrVec types = (fCmsswComp ? TStrVec{"cmssw","reco","cmssw"} : TStrVec{"sim","reco","sim"}); // types will be same size as rates! - - TEffRefVecVec phiRate(trks.size()); + const FltVec ptcuts = {0.f,0.9f,2.f}; + + TEffRefVecVecVec phiRate(trks.size()); for (UInt_t j = 0; j < trks.size(); j++) { phiRate[j].resize(rates.size()); for (UInt_t r = 0; r < rates.size(); r++) { - phiRate[j][r] = (TEfficiency*) fOutRoot->Get(Form("%s%s/%s_%s_phi_%s",rateSD[r].Data(),(fCmsswComp?"_cmssw":""),rates[r].Data(),types[r].Data(),trks[j].Data())); + phiRate[j][r].resize(ptcuts.size()); + for (UInt_t p = 0; p < ptcuts.size(); p++) + { + phiRate[j][r][p] = (TEfficiency*) fOutRoot->Get(Form("%s%s/%s_%s_phi_%s_pt%3.1f",rateSD[r].Data(),(fCmsswComp?"_cmssw":""),rates[r].Data(),types[r].Data(),trks[j].Data(),ptcuts[p])); + } } } @@ -767,20 +827,21 @@ void PlotValidation::PrintTotals() const TStrVec coll = {"allreco","fake","bestmatch"}; const TStrVec scoll = {"All Reco","Fake","Best Match"}; - TH1FRefVecVec nHitsPlot(trks.size()); - TH1FRefVecVec fracHitsMatchedPlot(trks.size()); + TH1FRefVecVecVec nHitsPlot(trks.size()); + TH1FRefVecVecVec fracHitsMatchedPlot(trks.size()); for (UInt_t j = 0; j < trks.size(); j++) { nHitsPlot[j].resize(coll.size()); fracHitsMatchedPlot[j].resize(coll.size()); - } - - for (UInt_t j = 0; j < trks.size(); j++) - { for (UInt_t c = 0; c < coll.size(); c++) { - nHitsPlot[j][c] = (TH1F*) fOutRoot->Get(Form("nHits%s/h_nHits_%s_%s",(fCmsswComp?"_cmssw":""),coll[c].Data(),trks[j].Data())); - fracHitsMatchedPlot[j][c] = (TH1F*) fOutRoot->Get(Form("nHits%s/h_fracHitsMatched_%s_%s",(fCmsswComp?"_cmssw":""),coll[c].Data(),trks[j].Data())); + nHitsPlot[j][c].resize(ptcuts.size()); + fracHitsMatchedPlot[j][c].resize(ptcuts.size()); + for (UInt_t p = 0; p < ptcuts.size(); p++) + { + nHitsPlot[j][c][p] = (TH1F*) fOutRoot->Get(Form("nHits%s/h_nHits_%s_%s_pt%3.1f",(fCmsswComp?"_cmssw":""),coll[c].Data(),trks[j].Data(),ptcuts[p])); + fracHitsMatchedPlot[j][c][p] = (TH1F*) fOutRoot->Get(Form("nHits%s/h_fracHitsMatched_%s_%s_pt%3.1f",(fCmsswComp?"_cmssw":""),coll[c].Data(),trks[j].Data(),ptcuts[p])); + } } } @@ -794,9 +855,9 @@ void PlotValidation::PrintTotals() TTree * frtree = (TTree*)fInRoot->Get((fCmsswComp?"cmsswfrtree":"frtree")); Int_t Nevents = 0; Int_t evtID = 0; efftree->SetBranchAddress("evtID",&evtID); - for (Int_t i = 0; i < efftree->GetEntries(); i++) + for (Int_t k = 0; k < efftree->GetEntries(); k++) { - efftree->GetEntry(i); + efftree->GetEntry(k); if (evtID > Nevents) Nevents = evtID; } const Int_t NtracksMC = efftree->GetEntries(); @@ -814,63 +875,71 @@ void PlotValidation::PrintTotals() totalsout << "++++++++++++++++++++++++++++++++++++++++++++" << std::endl; totalsout << std::endl; - for (UInt_t j = 0; j < trks.size(); j++) + for (UInt_t p = 0; p < ptcuts.size(); p++) { - std::cout << strks[j].Data() << " Tracks" << std::endl; - std::cout << "++++++++++++++++++++++++++++++++++++++++++" << std::endl << std::endl; - std::cout << "Hit Totals for " << strks[j].Data() << " Track Collections" << std::endl; - std::cout << "==========================================" << std::endl; + std::cout << Form("xxxxxxxxxx Track pT > %3.1f Cut xxxxxxxxxx",ptcuts[p]) << std::endl; + std::cout << std::endl; - totalsout << strks[j].Data() << " Tracks" << std::endl; - totalsout << "++++++++++++++++++++++++++++++++++++++++++" << std::endl << std::endl; - totalsout << "Hit Totals for " << strks[j].Data() << " Track Collections" << std::endl; - totalsout << "==========================================" << std::endl; - for (UInt_t c = 0; c < coll.size(); c++) + totalsout << Form("xxxxxxxxxx Track pT > %3.1f Cut xxxxxxxxxx",ptcuts[p]) << std::endl; + totalsout << std::endl; + + for (UInt_t j = 0; j < trks.size(); j++) { - Float_t nHits_mean = nHitsPlot[j][c]->GetMean(1); // 1 is mean of x-axis - Float_t nHits_mean_unc = nHitsPlot[j][c]->GetMeanError(1); // 1 is mean of x-axis - Float_t fracHits_mean = fracHitsMatchedPlot[j][c]->GetMean(1); - Float_t fracHits_mean_unc = fracHitsMatchedPlot[j][c]->GetMeanError(1); - - std::cout << scoll[c].Data() << " Tracks" << std::endl; - std::cout << "Mean nHits / Track = " << nHits_mean << " +/- " << nHits_mean_unc << std::endl; - std::cout << "Mean Shared Hits / Track = " << fracHits_mean << " +/- " << fracHits_mean_unc << std::endl; - std::cout << "------------------------------------------" << std::endl; - - totalsout << scoll[c].Data() << " Tracks" << std::endl; - totalsout << "Mean nHits / Track = " << nHits_mean << " +/- " << nHits_mean_unc << std::endl; - totalsout << "Mean Shared Hits / Track = " << fracHits_mean << " +/- " << fracHits_mean_unc << std::endl; - totalsout << "------------------------------------------" << std::endl; - } - - std::cout << std::endl << "Rates for " << strks[j].Data() << " Tracks" << std::endl; - std::cout << "==========================================" << std::endl; + std::cout << strks[j].Data() << " Tracks" << std::endl; + std::cout << "++++++++++++++++++++++++++++++++++++++++++" << std::endl << std::endl; + std::cout << "Hit Totals for " << strks[j].Data() << " Track Collections" << std::endl; + std::cout << "==========================================" << std::endl; + + totalsout << strks[j].Data() << " Tracks" << std::endl; + totalsout << "++++++++++++++++++++++++++++++++++++++++++" << std::endl << std::endl; + totalsout << "Hit Totals for " << strks[j].Data() << " Track Collections" << std::endl; + totalsout << "==========================================" << std::endl; + for (UInt_t c = 0; c < coll.size(); c++) + { + const Float_t nHits_mean = nHitsPlot[j][c][p]->GetMean(1); // 1 is mean of x-axis + const Float_t nHits_mean_unc = nHitsPlot[j][c][p]->GetMeanError(1); // 1 is mean of x-axis + const Float_t fracHits_mean = fracHitsMatchedPlot[j][c][p]->GetMean(1); + const Float_t fracHits_mean_unc = fracHitsMatchedPlot[j][c][p]->GetMeanError(1); + + std::cout << scoll[c].Data() << " Tracks" << std::endl; + std::cout << "Mean nHits / Track = " << nHits_mean << " +/- " << nHits_mean_unc << std::endl; + std::cout << "Mean Shared Hits / Track = " << fracHits_mean << " +/- " << fracHits_mean_unc << std::endl; + std::cout << "------------------------------------------" << std::endl; + + totalsout << scoll[c].Data() << " Tracks" << std::endl; + totalsout << "Mean nHits / Track = " << nHits_mean << " +/- " << nHits_mean_unc << std::endl; + totalsout << "Mean Shared Hits / Track = " << fracHits_mean << " +/- " << fracHits_mean_unc << std::endl; + totalsout << "------------------------------------------" << std::endl; + } + + std::cout << std::endl << "Rates for " << strks[j].Data() << " Tracks" << std::endl; + std::cout << "==========================================" << std::endl; - totalsout << std::endl << "Rates for " << strks[j].Data() << " Tracks" << std::endl; - totalsout << "==========================================" << std::endl; - for (UInt_t r = 0; r < rates.size(); r++) - { - EffStruct effs; - PlotValidation::GetTotalEfficiency(phiRate[j][r],effs); - - std::cout << snumer[r].Data() << ": " << effs.passed_ << std::endl; - std::cout << sdenom[r].Data() << ": " << effs.total_ << std::endl; - std::cout << "------------------------------------------" << std::endl; - std::cout << srates[r].Data() << ": " << effs.eff_ << ", -" << effs.elow_ << ", +" << effs.eup_ << std::endl; - std::cout << "------------------------------------------" << std::endl; - - totalsout << snumer[r].Data() << ": " << effs.passed_ << std::endl; - totalsout << sdenom[r].Data() << ": " << effs.total_ << std::endl; - totalsout << "------------------------------------------" << std::endl; - totalsout << srates[r].Data() << ": " << effs.eff_ << ", -" << effs.elow_ << ", +" << effs.eup_ << std::endl; - totalsout << "------------------------------------------" << std::endl; + totalsout << std::endl << "Rates for " << strks[j].Data() << " Tracks" << std::endl; + totalsout << "==========================================" << std::endl; + for (UInt_t r = 0; r < rates.size(); r++) + { + EffStruct effs; + PlotValidation::GetTotalEfficiency(phiRate[j][r][p],effs); + + std::cout << snumer[r].Data() << ": " << effs.passed_ << std::endl; + std::cout << sdenom[r].Data() << ": " << effs.total_ << std::endl; + std::cout << "------------------------------------------" << std::endl; + std::cout << srates[r].Data() << ": " << effs.eff_ << ", -" << effs.elow_ << ", +" << effs.eup_ << std::endl; + std::cout << "------------------------------------------" << std::endl; + + totalsout << snumer[r].Data() << ": " << effs.passed_ << std::endl; + totalsout << sdenom[r].Data() << ": " << effs.total_ << std::endl; + totalsout << "------------------------------------------" << std::endl; + totalsout << srates[r].Data() << ": " << effs.eff_ << ", -" << effs.elow_ << ", +" << effs.eup_ << std::endl; + totalsout << "------------------------------------------" << std::endl; + } + std::cout << std::endl << std::endl; + totalsout << std::endl << std::endl; } - std::cout << std::endl << std::endl; - totalsout << std::endl << std::endl; } totalsout.close(); - - + delete frtree; delete efftree; } diff --git a/PlotValidation.hh b/PlotValidation.hh index 235b6e55d945d..479330a299011 100644 --- a/PlotValidation.hh +++ b/PlotValidation.hh @@ -35,10 +35,12 @@ typedef std::vector IntVecRefVec; typedef std::vector TH1FRefVec; typedef std::vector TH1FRefVecVec; typedef std::vector TH1FRefVecVecVec; +typedef std::vector TH1FRefVecVecVecVec; typedef std::vector TEffRefVec; typedef std::vector TEffRefVecVec; typedef std::vector TEffRefVecVecVec; +typedef std::vector TEffRefVecVecVecVec; typedef std::vector TStrVec; diff --git a/makeValidation.C b/makeValidation.C index 926e95c07f391..0d0876701a14a 100644 --- a/makeValidation.C +++ b/makeValidation.C @@ -46,45 +46,52 @@ void makeValidation(TString label = "", const Bool_t cmsswComp = false) vars.push_back("pt"); vars.push_back("phi"); vars.push_back("eta"); + std::vector ptcuts; + ptcuts.push_back(0.f); + ptcuts.push_back(0.9f); + ptcuts.push_back(2.f); for (UInt_t i = 0; i < rates.size(); i++) { for (UInt_t j = 0; j < vars.size(); j++) { - TCanvas * canv = new TCanvas(); - canv->cd(); - - TGraphAsymmErrors * g_bh = ((TEfficiency*)f_bh ->Get(Form("%s/%s_%s_%s_build",dirs[i].Data(),rates[i].Data(),sORr[i].Data(),vars[j].Data())))->CreateGraph(); - TGraphAsymmErrors * g_std = ((TEfficiency*)f_std->Get(Form("%s/%s_%s_%s_build",dirs[i].Data(),rates[i].Data(),sORr[i].Data(),vars[j].Data())))->CreateGraph(); - TGraphAsymmErrors * g_ce = ((TEfficiency*)f_ce ->Get(Form("%s/%s_%s_%s_build",dirs[i].Data(),rates[i].Data(),sORr[i].Data(),vars[j].Data())))->CreateGraph(); - - g_bh ->SetLineColor(kBlue); - g_std->SetLineColor(kGreen+1); - g_ce ->SetLineColor(kRed); - g_bh ->SetMarkerColor(kBlue); - g_std->SetMarkerColor(kGreen+1); - g_ce ->SetMarkerColor(kRed); - - if (!rates[i].Contains("ineff",TString::kExact)) g_bh->GetYaxis()->SetRangeUser(0.0,1.05); - else g_bh->GetYaxis()->SetRangeUser(0.0,0.25); - - g_bh ->Draw("APZ"); - g_std->Draw("PZ same"); - g_ce ->Draw("PZ same"); - - TLegend * leg = new TLegend(0.85,0.80,1.0,1.0); - leg->AddEntry(g_bh,"Best Hit","LEP"); - leg->AddEntry(g_std,"Standard","LEP"); - leg->AddEntry(g_ce,"Clone Engine","LEP"); - leg->Draw("same"); - - canv->SaveAs(Form("%s_%s_%s.png",label.Data(),rates[i].Data(),vars[j].Data())); - - delete leg; - delete g_ce; - delete g_std; - delete g_bh; - delete canv; + for (UInt_t p = 0; p < ptcuts.size(); p++) + { + TCanvas * canv = new TCanvas(); + canv->cd(); + + TGraphAsymmErrors * g_bh = ((TEfficiency*)f_bh ->Get(Form("%s/%s_%s_%s_build_pt%3.1f",dirs[i].Data(),rates[i].Data(),sORr[i].Data(),vars[j].Data(),ptcuts[p])))->CreateGraph(); + TGraphAsymmErrors * g_std = ((TEfficiency*)f_std->Get(Form("%s/%s_%s_%s_build_pt%3.1f",dirs[i].Data(),rates[i].Data(),sORr[i].Data(),vars[j].Data(),ptcuts[p])))->CreateGraph(); + TGraphAsymmErrors * g_ce = ((TEfficiency*)f_ce ->Get(Form("%s/%s_%s_%s_build_pt%3.1f",dirs[i].Data(),rates[i].Data(),sORr[i].Data(),vars[j].Data(),ptcuts[p])))->CreateGraph(); + + g_bh ->SetLineColor(kBlue); + g_std->SetLineColor(kGreen+1); + g_ce ->SetLineColor(kRed); + g_bh ->SetMarkerColor(kBlue); + g_std->SetMarkerColor(kGreen+1); + g_ce ->SetMarkerColor(kRed); + + if (!rates[i].Contains("ineff",TString::kExact)) g_bh->GetYaxis()->SetRangeUser(0.0,1.05); + else g_bh->GetYaxis()->SetRangeUser(0.0,0.25); + + g_bh ->Draw("APZ"); + g_std->Draw("PZ same"); + g_ce ->Draw("PZ same"); + + TLegend * leg = new TLegend(0.85,0.80,1.0,1.0); + leg->AddEntry(g_bh,"Best Hit","LEP"); + leg->AddEntry(g_std,"Standard","LEP"); + leg->AddEntry(g_ce,"Clone Engine","LEP"); + leg->Draw("same"); + + canv->SaveAs(Form("%s_%s_%s_pt%3.1f.png",label.Data(),rates[i].Data(),vars[j].Data(),ptcuts[p])); + + delete leg; + delete g_ce; + delete g_std; + delete g_bh; + delete canv; + } } } diff --git a/validation-desc.txt b/validation-desc.txt index 4f7ed7caa796e..df7b32145802b 100644 --- a/validation-desc.txt +++ b/validation-desc.txt @@ -12,6 +12,7 @@ D. Definitions of efficiency, fake rate, and duplicate rate E. Overview of scripts F. Hit map/remapping logic G. Extra info on ID and mask assignments +H. Special note about duplicate rate ===================== A. Overview of code @@ -21,7 +22,7 @@ TTreeValidation will only compile the necessary ROOT code with WITH_ROOT=yes ena Three types of validation exist within TTreeValidation: [1.] "Building validation", enabled with Config::root_val, via the command line option: --root-val -[2.] "CMSSW external tracks building validation", enabled with Config::cmssw_val, via the command line options: --cmss-val --cmssw-seeds --ext-rec-tracks --geom CMS-2017 +[2.] "CMSSW external tracks building validation", enabled with Config::cmssw_val, via the command line options: --cmssw-val --cmssw-seeds --ext-rec-tracks --geom CMS-2017 [3.] "Fit validation", enabled with Config::fit_val, via the command line option: --fit-val We will ignore fit validation for the moment. The main idea behind the other two is that the validation routines are called outside of the standard timed sections, and as such, we do not care too much about performance, as long as it takes a reasonable amount of time to complete. Of course, the full wall clock time matters when running multiple events in flight, and because there is a lot of I/O as well as moves and stores that would hurt the performance with the validation enabled, these routines are ignored if the command line option "--silent" is enabled. @@ -38,7 +39,7 @@ The building validation takes advantage of filling two trees per event per track - ToyMC, with sim seeds or find-seeds - CMSSW, with sim seeds or cmssw-seeds -Upon instantiation of the TTreeValidation object, the respective ROOT trees are defined and allocated on the heap, along with setting the addresses of all the branches. After the building is completed in mkFit, we have to have the tracks in their standard event containers, namely: seedTracks_, candidateTracks_, and fitTracks_. In the standard combinatorial or clone engine, we have to copy out the built tracks from event of combined candiates into candidateTracks_ via: builder.quality_store_tracks() in mkFit/buildtestMPlex.cc. Since we do not yet have fitting after building, we just set the fitTracks_ equal to the candidateTracks_. For ease, I will from now on refer to the candidateTracks_ as buildTracks_. +Upon instantiation of the TTreeValidation object, the respective ROOT trees are defined and allocated on the heap, along with setting the addresses of all the branches. After the building is completed in mkFit, we have to have the tracks in their standard event containers, namely: seedTracks_, candidateTracks_, and fitTracks_. In the standard combinatorial or clone engine, we have to copy out the built tracks from event of combined candidates into candidateTracks_ via: builder.quality_store_tracks() in mkFit/buildtestMPlex.cc. Since we do not yet have fitting after building, we just set the fitTracks_ equal to the candidateTracks_. For ease, I will from now on refer to the candidateTracks_ as buildTracks_. As a reminder, the sim tracks are stored in the Event.cc as simTracks_, while the CMSSW reco tracks are stored as extRecTracks_. Each track collection has an associated TrackExtra collection, which is stored as {trackname}Extra_ inside the Event object. It is indexed the same as the collection it references, i.e. track[0] has an associated extra extra[0]. The TrackExtra object contains the mcTrackID, seedID, and cmsswTrackID each mkFit track is associated to. The validation also makes use of simHitsInfo_ (container for storing mcTrackID for each hit), layerHits_, and simTrackStates_ (used for pulls). See Section B and C for explanations on how the track matching is performed and track information is saved. @@ -308,7 +309,7 @@ Fake Rate (with all reco tracks: Config::inclusiveShorts == true, enabled with c -1 or -3 | 0 -2 or -4 or -6 or -7 | 2 -Duplicate Rate [PlotValidation::PlotDuplicateRate()] +Duplicate Rate [PlotValidation::PlotDuplicateRate()], see special note in section H numerator: sim tracks with more than reco track match (nTkMatches_[reco] > 1) denominator: sim tracks with at least one reco track with mcTrackID >= 0 (mcmask_[reco] == 1) @@ -419,3 +420,15 @@ position reco variables --> layers_[reco] == -1, reco unassociated to sim tk {eff only} --> reco pos+err var == -2000, reco tk is unassociated to sim tk {eff only} --> reco pos+err var == -3000, reco tk is unassociated to seed tk {FR only} + +====================================== + H. Special note about duplicate rate +====================================== + +*** Originally from PlotValidation.cpp *** + +Currently, TEfficiency does not allow you to fill a weighted number in the numerator and NOT the denominator. +In other words, we cannot fill numerator n-1 times sim track is matched, while denominator is just filled once. +As a result, DR is simply if a sim track is duplicated once, and not how many times it is duplicated. + +We can revert back to the n-1 filling for the numerator to weight by the amount of times a sim track is duplicated, but this would mean going back to the TH1Fs, and then using the binomial errors (or computing by hand the CP errors or something), in the case that the DR in any bin > 1... This would break the flow of the printouts as well as the stacking macro, but could be done with some mild pain. From 897f8928f03c5c58d36ca7a5ec3cba3debd2bc0a Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Thu, 10 Aug 2017 07:17:33 -0700 Subject: [PATCH 142/172] clean_cms_seedtracks actually returns n cleaned seeds, 10mu validation uses n^2 cleaning for cms seeds --- Event.cc | 4 +++- validation-snb-cmssw-10mu-fulldet-build-extrectracks.sh | 2 +- validation-snb-cmssw-10mu-fulldet-build.sh | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Event.cc b/Event.cc index 0e17134c42504..772d4c24e084b 100644 --- a/Event.cc +++ b/Event.cc @@ -517,7 +517,7 @@ void Event::read_in(DataFile &data_file, FILE *in_fp) } #ifdef CLEAN_SEEDS - ns = clean_cms_seedtracks();//operates on seedTracks_; returns the number of cleaned seeds + ns = clean_cms_seedtracks();//operates on seedTracks_; swaps cleaned seeds into seedTracks_; returns number of cleaned seedTracks #endif #ifdef DUMP_SEEDS printf("Read %i seedtracks (neg value means actual reading was skipped)\n", ns); @@ -780,6 +780,8 @@ int Event::clean_cms_seedtracks() int newlabel = 0; for (auto&& track : seedTracks_) if (track.label() < 0) track.setLabel(--newlabel); } + + return seedTracks_.size(); } diff --git a/validation-snb-cmssw-10mu-fulldet-build-extrectracks.sh b/validation-snb-cmssw-10mu-fulldet-build-extrectracks.sh index a2878bde5e5f2..566dd57e7b903 100755 --- a/validation-snb-cmssw-10mu-fulldet-build-extrectracks.sh +++ b/validation-snb-cmssw-10mu-fulldet-build-extrectracks.sh @@ -1,6 +1,6 @@ #! /bin/bash -make -j 12 WITH_ROOT=yes +make -j 12 WITH_ROOT=yes CPPUSERFLAGS+=-DCLEAN_SEEDS CXXUSERFLAGS+=-DCLEAN_SEEDS dir=/data/nfsmic/slava77/samples/2017/pass-4874f28/initialStep file=memoryFile.fv3.recT.072617.bin diff --git a/validation-snb-cmssw-10mu-fulldet-build.sh b/validation-snb-cmssw-10mu-fulldet-build.sh index eea31fe42c753..1bfc71f682b24 100755 --- a/validation-snb-cmssw-10mu-fulldet-build.sh +++ b/validation-snb-cmssw-10mu-fulldet-build.sh @@ -1,6 +1,6 @@ #! /bin/bash -make -j 12 WITH_ROOT=yes +make -j 12 WITH_ROOT=yes CPPUSERFLAGS+=-DCLEAN_SEEDS CXXUSERFLAGS+=-DCLEAN_SEEDS dir=/data/nfsmic/slava77/samples/2017/pass-4874f28/initialStep file=memoryFile.fv3.recT.072617.bin From ab4aa78b3bff902f8d9aa7b545914ccb45d3bde3 Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Thu, 10 Aug 2017 07:46:32 -0700 Subject: [PATCH 143/172] fix access of best helix chi2 --- Track.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Track.cc b/Track.cc index 0709052f7157e..6585be34ed610 100644 --- a/Track.cc +++ b/Track.cc @@ -256,20 +256,21 @@ void TrackExtra::setCMSSWTrackIDInfo(const Track& trk, const std::vector idchi2PairVec cands; for (auto&& redcmsswtrack : redcmsswtracks) { - const float chi2 = computeHelixChi2(redcmsswtrack.parameters(),trkParamsR,trkErrsR,false); + const float chi2 = std::abs(computeHelixChi2(redcmsswtrack.parameters(),trkParamsR,trkErrsR,false)); if (chi2 < Config::minCMSSWMatchChi2) cands.push_back(std::make_pair(redcmsswtrack.label(),chi2)); } float minchi2 = -1e6; if (cands.size()>0) { - std::sort(cands.begin(),cands.end(),sortIDsByChi2); + std::sort(cands.begin(),cands.end(),sortIDsByChi2); // in case we just want to stop at the first dPhi match minchi2 = cands.front().second; } int cmsswTrackID = -1; int nHMatched = 0; float bestdPhi = Config::minCMSSWMatchdPhi; + float bestchi2 = minchi2; for (auto&& cand : cands) // loop over possible cmssw tracks { const auto label = cand.first; @@ -291,13 +292,13 @@ void TrackExtra::setCMSSWTrackIDInfo(const Track& trk, const std::vector } } if (Config::applyCMSSWHitMatch && matched < (Config::nCMSSWMatchHitsAfterSeed+Config::nlayers_per_seed)) continue; // check for nMatchedHits if applied (in principle all seed hits should be found!) - bestdPhi = diffPhi; nHMatched = matched; cmsswTrackID = label; + bestdPhi = diffPhi; nHMatched = matched; cmsswTrackID = label; bestchi2 = cand.second; } } // set cmsswTrackID cmsswTrackID_ = cmsswTrackID; - helixChi2_ = (cmsswTrackID_ >= 0 ? cands[cmsswTrackID_].second : minchi2); + helixChi2_ = bestchi2; // Modify cmsswTrackID based on length if (trk.nFoundHits() < Config::nMinFoundHits) From b34c8b09226ce7584f1418b6f012c6884fc52a48 Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Fri, 11 Aug 2017 08:46:31 -0700 Subject: [PATCH 144/172] validation for all ttbar samples --- ...b-cmssw-PU70-fulldet-build-extrectracks.sh | 28 ------------ ...-cmssw-ttbar-fulldet-build-extrectracks.sh | 39 ++++++++++++++++ web/move-cmsswval-pu70-extrectracks.sh | 37 ---------------- web/move-cmsswval-ttbar-extrectracks.sh | 44 +++++++++++++++++++ 4 files changed, 83 insertions(+), 65 deletions(-) delete mode 100755 validation-snb-cmssw-PU70-fulldet-build-extrectracks.sh create mode 100755 validation-snb-cmssw-ttbar-fulldet-build-extrectracks.sh delete mode 100755 web/move-cmsswval-pu70-extrectracks.sh create mode 100755 web/move-cmsswval-ttbar-extrectracks.sh diff --git a/validation-snb-cmssw-PU70-fulldet-build-extrectracks.sh b/validation-snb-cmssw-PU70-fulldet-build-extrectracks.sh deleted file mode 100755 index b917f64513a95..0000000000000 --- a/validation-snb-cmssw-PU70-fulldet-build-extrectracks.sh +++ /dev/null @@ -1,28 +0,0 @@ -#! /bin/bash - -make -j 12 WITH_ROOT=yes CPPUSERFLAGS+=-DCLEAN_SEEDS CXXUSERFLAGS+=-DCLEAN_SEEDS - -dir=/data/nfsmic/slava77/samples/2017/pass-4874f28/initialStep/PU70/10224.0_TTbar_13+TTbar_13TeV_TuneCUETP8M1_2017PU_GenSimFullINPUT+DigiFullPU_2017PU+RecoFullPU_2017PU+HARVESTFullPU_2017PU -file=memoryFile.fv3.clean.writeAll.recT.072617.bin - -base=SNB_CMSSW_PU70 - -for bV in "BH bh" "STD std" "CE ce" -do echo $bV | while read -r bN bO - do - oBase=${base}_${bN} - echo "${oBase}: validation [nTH:24, nVU:8]" - ./mkFit/mkFit --cmssw-seeds --geom CMS-2017 --cmssw-val --ext-rec-tracks --read --file-name ${dir}/${file} --build-${bO} --num-thr 24 >& log_${oBase}_NVU8int_NTH24_cmsswval.txt - mv valtree.root valtree_${oBase}.root - done -done - -make clean - -for build in BH STD CE -do - root -b -q -l runValidation.C\(\"_${base}_${build}\",0,1\) -done -root -b -q -l makeValidation.C\(\"${base}\",1\) - -make distclean diff --git a/validation-snb-cmssw-ttbar-fulldet-build-extrectracks.sh b/validation-snb-cmssw-ttbar-fulldet-build-extrectracks.sh new file mode 100755 index 0000000000000..1d4781d63d4e7 --- /dev/null +++ b/validation-snb-cmssw-ttbar-fulldet-build-extrectracks.sh @@ -0,0 +1,39 @@ +#! /bin/bash + +make -j 12 WITH_ROOT=yes CPPUSERFLAGS+=-DCLEAN_SEEDS CXXUSERFLAGS+=-DCLEAN_SEEDS + +dir=/data/nfsmic/slava77/samples/2017/pass-4874f28/initialStep +file=memoryFile.fv3.clean.writeAll.recT.072617.bin + +NoPU=10024.0_TTbar_13+TTbar_13TeV_TuneCUETP8M1_2017_GenSimFullINPUT+DigiFull_2017+RecoFull_2017+ALCAFull_2017+HARVESTFull_2017 +PU35=10224.0_TTbar_13+TTbar_13TeV_TuneCUETP8M1_2017PU_GenSimFullINPUT+DigiFullPU_2017PU+RecoFullPU_2017PU+HARVESTFullPU_2017PU +PU70=PU70/10224.0_TTbar_13+TTbar_13TeV_TuneCUETP8M1_2017PU_GenSimFullINPUT+DigiFullPU_2017PU+RecoFullPU_2017PU+HARVESTFullPU_2017PU + +base=SNB_CMSSW_TTbar + +for ttbar in NoPU PU35 PU70 +do + for bV in "BH bh" "STD std" "CE ce" + do echo $bV | while read -r bN bO + do + oBase=${base}_${ttbar}_${bN} + echo "${oBase}: validation [nTH:24, nVU:8]" + ./mkFit/mkFit --cmssw-seeds --geom CMS-2017 --cmssw-val --ext-rec-tracks --read --file-name ${dir}/${!ttbar}/${file} --build-${bO} --num-thr 24 >& log_${oBase}_NVU8int_NTH24_cmsswval.txt + mv valtree.root valtree_${oBase}.root + done + done +done + +make clean + +for ttbar in NoPU PU35 PU70 +do + tbase=${base}_${ttbar} + for build in BH STD CE + do + root -b -q -l runValidation.C\(\"_${tbase}_${build}\",0,1\) + done + root -b -q -l makeValidation.C\(\"${tbase}\",1\) +done + +make distclean diff --git a/web/move-cmsswval-pu70-extrectracks.sh b/web/move-cmsswval-pu70-extrectracks.sh deleted file mode 100755 index fd9f4f64ba9e1..0000000000000 --- a/web/move-cmsswval-pu70-extrectracks.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash - -dir=${1:-plots} -outdir=${dir}/cmsswval-pu70-extrectracks -base=SNB_CMSSW_PU70 - -echo "Moving plots and text files locally to ${outdir}" - -mkdir -p ${outdir} -mv ${base}_*.png ${outdir} -for build in BH STD CE -do - vbase=validation_${base}_${build} - mv ${vbase}/totals_${vbase}_cmssw.txt ${outdir} -done - -host=kmcdermo@lxplus.cern.ch -whost=${host}":~/www" -echo "Moving plots and text files remotely to ${whost}" -scp -r ${dir} ${whost} - -echo "Executing remotely ./makereadable.sh ${outdir}" -ssh ${host} bash -c "' -cd www -./makereadable.sh ${outdir} -exit -'" - -echo "Removing local files" -for build in BH STD CE -do - testbase=${base}_${build} - rm -rf validation_${testbase} - rm -rf log_${testbase}_NVU8int_NTH24_cmsswval.txt -done - -rm -rf ${dir} diff --git a/web/move-cmsswval-ttbar-extrectracks.sh b/web/move-cmsswval-ttbar-extrectracks.sh new file mode 100755 index 0000000000000..e3c8d9408df28 --- /dev/null +++ b/web/move-cmsswval-ttbar-extrectracks.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +dir=${1:-plots} +outdir=${dir}/cmsswval-ttbar-extrectracks +base=SNB_CMSSW_TTbar + +echo "Moving plots and text files locally to ${outdir}" +for ttbar in NoPU PU35 PU70 +do + fulldir=${outdir}/${ttbar} + mkdir -p ${fulldir} + + mv ${base}_${ttbar}_*.png ${fulldir} + for build in BH STD CE + do + vbase=validation_${base}_${ttbar}_${build} + mv ${vbase}/totals_${vbase}_cmssw.txt ${fulldir} + done +done + +host=kmcdermo@lxplus.cern.ch +whost=${host}":~/www" +echo "Moving plots and text files remotely to ${whost}" +scp -r ${dir} ${whost} + +echo "Executing remotely ./makereadable.sh ${outdir}" +ssh ${host} bash -c "' +cd www +./makereadable.sh ${outdir} +exit +'" + +echo "Removing local files" +for ttbar in NoPU PU35 PU70 +do + for build in BH STD CE + do + testbase=${base}_${ttbar}_${build} + rm -rf validation_${testbase} + rm -rf log_${testbase}_NVU8int_NTH24_cmsswval.txt + done +done + +rm -rf ${dir} From 012d51f328d863e94ed9fc0ce1bc4791540ba6e2 Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Thu, 17 Aug 2017 16:42:49 -0700 Subject: [PATCH 145/172] add true seedID to cmssw reco validation through some tricks --- TTreeValidation.cc | 60 +++++++++++++++++++++++++++++++++++++++------- TTreeValidation.h | 11 ++++++--- Track.h | 3 +++ Validation.h | 1 + mkFit/MkBuilder.cc | 10 +++++++- 5 files changed, 73 insertions(+), 12 deletions(-) diff --git a/TTreeValidation.cc b/TTreeValidation.cc index 9fc0dc20ed46f..432a759879379 100644 --- a/TTreeValidation.cc +++ b/TTreeValidation.cc @@ -317,6 +317,7 @@ void TTreeValidation::initializeCMSSWEfficiencyTree() cmsswefftree_->Branch("cmsswmask_build",&cmsswmask_build_ceff_); cmsswefftree_->Branch("seedID_cmssw",&seedID_cmssw_ceff_); cmsswefftree_->Branch("seedID_build",&seedID_build_ceff_); + cmsswefftree_->Branch("mcTrackID_build",&mcTrackID_build_ceff_); cmsswefftree_->Branch("x_cmssw",&x_cmssw_ceff_); cmsswefftree_->Branch("y_cmssw",&y_cmssw_ceff_); @@ -361,11 +362,11 @@ void TTreeValidation::initializeCMSSWFakeRateTree() cmsswfrtree_ = new TTree("cmsswfrtree","cmsswfrtree"); cmsswfrtree_->Branch("evtID",&evtID_cFR_); - cmsswfrtree_->Branch("label_build",&label_build_cFR_); cmsswfrtree_->Branch("cmsswID_build",&cmsswID_build_cFR_); cmsswfrtree_->Branch("cmsswmask_build",&cmsswmask_build_cFR_); cmsswfrtree_->Branch("seedID_cmssw",&seedID_cmssw_cFR_); cmsswfrtree_->Branch("seedID_build",&seedID_build_cFR_); + cmsswfrtree_->Branch("mcTrackID_build",&mcTrackID_build_cFR_); cmsswfrtree_->Branch("pt_build",&pt_build_cFR_); cmsswfrtree_->Branch("ept_build",&ept_build_cFR_); @@ -491,8 +492,11 @@ void TTreeValidation::resetValidationMaps() seedToBuildMap_.clear(); seedToFitMap_.clear(); - // reest map of cmssw tracks to reco tracks + // reset map of cmssw tracks to reco tracks cmsswToBuildMap_.clear(); + + // reset special map of seed labels to cmssw tracks + seedToCmsswMap_.clear(); } void TTreeValidation::setTrackExtras(Event& ev) @@ -557,6 +561,9 @@ void TTreeValidation::setTrackExtras(Event& ev) auto&& extra(ev.candidateTracksExtra_[itrack]); extra.setCMSSWTrackIDInfo(track, ev.layerHits_, ev.extRecTracks_,reducedCMSSW); } + + // store mcTrackID and seedID correctly + storeSeedAndMCID(ev); } } @@ -647,6 +654,41 @@ void TTreeValidation::makeCMSSWTkToRecoTksMap(Event& ev) TTreeValidation::mapRefTkToRecoTks(ev.candidateTracks_,ev.candidateTracksExtra_,cmsswToBuildMap_); } +void TTreeValidation::makeSeedTkToCMSSWTkMap(Event& ev) +{ + const auto& seedtracks = ev.seedTracks_; + const auto& cmsswtracks = ev.extRecTracks_; + for (int itrack = 0; itrack < seedtracks.size(); itrack++) + { + for (auto&& cmsswtrack : cmsswtracks) + { + if (cmsswtrack.label() == itrack) seedToCmsswMap_[seedtracks[itrack].label()] = cmsswtrack.label(); + } + } +} + +void TTreeValidation::storeSeedAndMCID(Event& ev) +{ + const auto& buildtracks = ev.candidateTracks_; + auto& buildextras = ev.candidateTracksExtra_; + + for (int itrack = 0; itrack < buildtracks.size(); itrack++) + { + auto& extra = buildextras[itrack]; + const int seedID = extra.seedID(); + + extra.setmcTrackID(seedID); + if (seedToCmsswMap_.count(seedID)) + { + extra.setseedID(seedToCmsswMap_[seedID]); + } + else + { + extra.setseedID(-1); + } + } +} + int TTreeValidation::getLastFoundHit(const int trackMCHitID, const int mcTrackID, const Event& ev) { int mcHitID = -1; @@ -1521,7 +1563,8 @@ void TTreeValidation::fillCMSSWEfficiencyTree(const Event& ev) const auto& buildextra = evt_build_extras[buildtrack.label()]; // returns track extra best aligned with build track cmsswmask_build_ceff_ = 1; // quick logic for matched - seedID_build_ceff_ = buildextra.seedID(); + seedID_build_ceff_ = buildextra.seedID(); + mcTrackID_build_ceff_ = buildextra.mcTrackID(); // track parameters pt_build_ceff_ = buildtrack.pT(); @@ -1559,7 +1602,8 @@ void TTreeValidation::fillCMSSWEfficiencyTree(const Event& ev) { cmsswmask_build_ceff_ = (cmsswtrack.isFindable() ? 0 : -1); // quick logic for not matched - seedID_build_ceff_ = -99; + seedID_build_ceff_ = -99; + mcTrackID_build_ceff_ = -99; pt_build_ceff_ = -99; ept_build_ceff_ = -99; @@ -1605,9 +1649,9 @@ void TTreeValidation::fillCMSSWFakeRateTree(const Event& ev) { const auto& buildextra = evt_build_extras[buildtrack.label()]; - evtID_cFR_ = ievt; - label_build_cFR_ = buildtrack.label(); - seedID_build_cFR_ = buildextra.seedID(); + evtID_cFR_ = ievt; + seedID_build_cFR_ = buildextra.seedID(); + mcTrackID_build_cFR_ = buildextra.mcTrackID(); // track parameters pt_build_cFR_ = buildtrack.pT(); @@ -1650,7 +1694,7 @@ void TTreeValidation::fillCMSSWFakeRateTree(const Event& ev) { if (cmsswID_build_cFR_ == -1 || cmsswID_build_cFR_ == -3) cmsswmask_build_cFR_ = 0; else if (cmsswID_build_cFR_ == -2 || cmsswID_build_cFR_ == -6 || cmsswID_build_cFR_ == -7) cmsswmask_build_cFR_ = 2; - else std::cerr << "Somehow got a bad cmsswID: " << cmsswID_build_cFR_ << " trackID: " << label_build_cFR_ << std::endl; + else std::cerr << "Somehow got a bad cmsswID: " << cmsswID_build_cFR_ << " trackID: " << mcTrackID_build_cFR_ << std::endl; } else { diff --git a/TTreeValidation.h b/TTreeValidation.h index 4da20824d0290..6d28fb4687f9f 100644 --- a/TTreeValidation.h +++ b/TTreeValidation.h @@ -46,6 +46,8 @@ class TTreeValidation : public Validation { void makeSeedTkToRecoTkMaps(Event& ev) override; void mapSeedTkToRecoTk(const TrackVec& evt_tracks, const TrackExtraVec& evt_extras, TkIDToTkIDMap& seedTkMap); void makeCMSSWTkToRecoTksMap(Event& ev) override; + void makeSeedTkToCMSSWTkMap(Event& ev) override; + void storeSeedAndMCID(Event& ev); int getLastFoundHit(const int trackMCHitID, const int mcTrackID, const Event& ev); @@ -75,6 +77,9 @@ class TTreeValidation : public Validation { // CMSSW to Reco Maps TkIDToTkIDVecMap cmsswToBuildMap_; + // Special map for CMSSW tracks to seed track labels --> NOT used for fake rate!! + TkIDToTkIDMap seedToCmsswMap_; + // Efficiency Tree TTree* efftree_; int evtID_eff_=0,mcID_eff_=0; @@ -168,7 +173,7 @@ class TTreeValidation : public Validation { // CMSSW Efficiency tree TTree* cmsswefftree_; int evtID_ceff_=0,cmsswID_ceff_=0; - int seedID_cmssw_ceff_=0,seedID_build_ceff_=0; + int seedID_cmssw_ceff_=0,seedID_build_ceff_=0,mcTrackID_build_ceff_=0; int cmsswmask_build_ceff_=0; float x_cmssw_ceff_=0.,y_cmssw_ceff_=0.,z_cmssw_ceff_=0.; @@ -193,8 +198,8 @@ class TTreeValidation : public Validation { // CMSSW FakeRate tree TTree* cmsswfrtree_; - int evtID_cFR_=0,label_build_cFR_=0,cmsswID_build_cFR_=0; - int seedID_cmssw_cFR_=0,seedID_build_cFR_=0; + int evtID_cFR_=0,cmsswID_build_cFR_=0; + int seedID_cmssw_cFR_=0,seedID_build_cFR_=0,mcTrackID_build_cFR_=0; int cmsswmask_build_cFR_=0; float pt_build_cFR_=0.,ept_build_cFR_=0.; diff --git a/Track.h b/Track.h index ae4cdb2b068f5..110d2ccbf2b5e 100644 --- a/Track.h +++ b/Track.h @@ -481,6 +481,9 @@ class TrackExtra int cmsswTrackID() const {return cmsswTrackID_;} float helixChi2() const {return helixChi2_;} + void setmcTrackID(int mcTrackID) {mcTrackID_ = mcTrackID;} + void setseedID(int seedID) {seedID_ = seedID;} + private: friend class Track; diff --git a/Validation.h b/Validation.h index c909d988d7e54..879648281297b 100644 --- a/Validation.h +++ b/Validation.h @@ -34,6 +34,7 @@ class Validation { virtual void makeSimTkToRecoTksMaps(Event&) {} virtual void makeSeedTkToRecoTkMaps(Event&) {} virtual void makeCMSSWTkToRecoTksMap(Event&) {} + virtual void makeSeedTkToCMSSWTkMap(Event&) {} virtual void fillEfficiencyTree(const Event&) {} virtual void fillFakeRateTree(const Event&) {} diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index 7249807505af2..6fd1c2177671d 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -888,8 +888,8 @@ void MkBuilder::cmssw_val() // get the tracks ready for validation remap_cand_hits(); prep_recotracks(); - prep_cmsswtracks(); + m_event->Validate(); } @@ -951,6 +951,14 @@ void MkBuilder::PrepareSeeds() } create_seeds_from_sim_tracks(); } + else + { + if (Config::cmssw_val) + { + m_event->validation_.makeSeedTkToCMSSWTkMap(*m_event); + } + } + import_seeds(); // printf("\n* Seeds after import:\n"); From 08eb87bf92f979f3181799d7b600a95005bcb55c Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Thu, 17 Aug 2017 17:45:21 -0700 Subject: [PATCH 146/172] make n^2 cleaning a command line option --- Config.cc | 1 + Config.h | 1 + Event.cc | 20 ++++++-- Event.h | 3 +- mkFit/MkBuilder.cc | 12 ----- mkFit/mkFit.cc | 6 +++ ...b-cmssw-10mu-fulldet-build-extrectracks.sh | 4 +- validation-snb-cmssw-10mu-fulldet-build.sh | 8 +-- validation-snb-cmssw-PU70-fulldet-build.sh | 37 -------------- ...-cmssw-ttbar-fulldet-build-extrectracks.sh | 4 +- validation-snb-cmssw-ttbar-fulldet-build.sh | 47 +++++++++++++++++ validationMIC-build-10mu.sh | 22 ++++---- validationMIC-build-PU70.sh | 24 ++++----- web/move-cmsswval-pu70.sh | 44 ---------------- web/move-cmsswval-ttbar.sh | 50 +++++++++++++++++++ 15 files changed, 152 insertions(+), 131 deletions(-) delete mode 100755 validation-snb-cmssw-PU70-fulldet-build.sh create mode 100755 validation-snb-cmssw-ttbar-fulldet-build.sh delete mode 100755 web/move-cmsswval-pu70.sh create mode 100755 web/move-cmsswval-ttbar.sh diff --git a/Config.cc b/Config.cc index 092b5fd7d1a86..0896bb753f1a0 100644 --- a/Config.cc +++ b/Config.cc @@ -47,6 +47,7 @@ namespace Config bool useCMSGeom = false; bool readCmsswSeeds = false; + bool cleanCmsswSeeds = false; bool readExtRecTracks = false; bool findSeeds = false; diff --git a/Config.h b/Config.h index ee83f13eba687..79ec6819608c9 100644 --- a/Config.h +++ b/Config.h @@ -262,6 +262,7 @@ namespace Config extern bool useCMSGeom; extern bool readCmsswSeeds; + extern bool cleanCmsswSeeds; extern bool readExtRecTracks; extern bool endcapTest; diff --git a/Event.cc b/Event.cc index 772d4c24e084b..158f7e2d1b154 100644 --- a/Event.cc +++ b/Event.cc @@ -459,7 +459,6 @@ void Event::write_out(DataFile &data_file) // #define DUMP_TRACKS // #define DUMP_TRACK_HITS // #define DUMP_LAYER_HITS -// #define CLEAN_SEEDS void Event::read_in(DataFile &data_file, FILE *in_fp) { @@ -515,10 +514,16 @@ void Event::read_in(DataFile &data_file, FILE *in_fp) fseek(fp, ns * data_file.f_header.f_sizeof_track, SEEK_CUR); ns = -ns; } -#ifdef CLEAN_SEEDS + + if (Config::cleanCmsswSeeds) + { + ns = clean_cms_seedtracks();//operates on seedTracks_; swaps cleaned seeds into seedTracks_; returns number of cleaned seedTracks + } + else + { + ns = clean_cms_seedtracks_badlabel();//operates on seedTracks_, removes those with label == -1; + } - ns = clean_cms_seedtracks();//operates on seedTracks_; swaps cleaned seeds into seedTracks_; returns number of cleaned seedTracks -#endif #ifdef DUMP_SEEDS printf("Read %i seedtracks (neg value means actual reading was skipped)\n", ns); for (int it = 0; it < ns; it++) @@ -784,6 +789,13 @@ int Event::clean_cms_seedtracks() return seedTracks_.size(); } +int Event::clean_cms_seedtracks_badlabel() +{ + printf("***\n*** MkBuilder::import_seeds REMOVING SEEDS WITH BAD LABEL. This is a development hack. ***\n***\n"); + TrackVec buf; seedTracks_.swap(buf); + std::copy_if(buf.begin(), buf.end(), std::back_inserter(seedTracks_), [](const Track& t){ return t.label() >= 0; }); + return seedTracks_.size(); +} //============================================================================== // DataFile diff --git a/Event.h b/Event.h index ef9ced1e5d13b..d941ca36d36c8 100644 --- a/Event.h +++ b/Event.h @@ -36,7 +36,8 @@ class Event void read_in (DataFile &data_file, FILE *in_fp=0); int clean_cms_simtracks(); - int clean_cms_seedtracks(); //operates on seedTracks_; returns the number of cleaned seeds + int clean_cms_seedtracks(); //operates on seedTracks_; returns the number of cleaned seeds + int clean_cms_seedtracks_badlabel(); //operates on seedTracks_, removes those with label == -1; void print_tracks(const TrackVec& tracks, bool print_hits) const; const Geometry& geom_; diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index 6fd1c2177671d..8349645e77c9e 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -382,18 +382,6 @@ void MkBuilder::import_seeds() // bool debug = true; - if (Config::readCmsswSeeds) - { -#ifndef CLEAN_SEEDS - printf("***\n*** MkBuilder::import_seeds REMOVING SEEDS WITH BAD LABEL. This is a development hack. ***\n***\n"); - - if (true) { - TrackVec buf; m_event->seedTracks_.swap(buf); - std::copy_if(buf.begin(), buf.end(), std::back_inserter(m_event->seedTracks_), [](const Track& t){ return t.label() >= 0; }); - } -#endif - } - TrackerInfo &trk_info = Config::TrkInfo; TrackVec &seeds = m_event->seedTracks_; const int size = seeds.size(); diff --git a/mkFit/mkFit.cc b/mkFit/mkFit.cc index 81106ef03ae6a..1c879220abfa5 100644 --- a/mkFit/mkFit.cc +++ b/mkFit/mkFit.cc @@ -497,6 +497,7 @@ int main(int argc, const char *argv[]) " --best-out-of run track finding num times, report best time (def: %d)\n" " --ext-rec-tracks read external rec trakcs if available (def: %s)\n" " --cmssw-seeds take seeds from CMSSW (def: %s)\n" + " --clean-seeds use N^2 seed cleaning on CMSSW seeds, else clean seeds with label == -1 (def: %s)\n" " --find-seeds run road search seeding [CF enabled by default] (def: %s)\n" " --hits-per-task number of layer1 hits per task in finding seeds (def: %i)\n" " --endcap-test test endcap tracking (def: %s)\n" @@ -526,6 +527,7 @@ int main(int argc, const char *argv[]) Config::finderReportBestOutOfN, b2a(Config::readExtRecTracks), b2a(Config::readCmsswSeeds), + b2a(Config::cleanCmsswSeeds), b2a(Config::findSeeds), Config::numHitsPerTask, b2a(Config::endcapTest), @@ -613,6 +615,10 @@ int main(int argc, const char *argv[]) { Config::readCmsswSeeds = true; } + else if(*i == "--clean-seeds") + { + Config::cleanCmsswSeeds = true; + } else if(*i == "--find-seeds") { Config::findSeeds = true; Config::cf_seeding = true; diff --git a/validation-snb-cmssw-10mu-fulldet-build-extrectracks.sh b/validation-snb-cmssw-10mu-fulldet-build-extrectracks.sh index 566dd57e7b903..f4ca9b4fd925f 100755 --- a/validation-snb-cmssw-10mu-fulldet-build-extrectracks.sh +++ b/validation-snb-cmssw-10mu-fulldet-build-extrectracks.sh @@ -1,6 +1,6 @@ #! /bin/bash -make -j 12 WITH_ROOT=yes CPPUSERFLAGS+=-DCLEAN_SEEDS CXXUSERFLAGS+=-DCLEAN_SEEDS +make -j 12 WITH_ROOT=yes dir=/data/nfsmic/slava77/samples/2017/pass-4874f28/initialStep file=memoryFile.fv3.recT.072617.bin @@ -20,7 +20,7 @@ do do oBase=${base}_${section}_${bN} echo "${oBase}: validation [nTH:24, nVU:8]" - ./mkFit/mkFit --cmssw-seeds --geom CMS-2017 --cmssw-val --ext-rec-tracks --read --file-name ${!section} --build-${bO} --num-thr 24 >& log_${oBase}_NVU8int_NTH24_cmsswval.txt + ./mkFit/mkFit --cmssw-seeds --clean-seeds --geom CMS-2017 --cmssw-val --ext-rec-tracks --read --file-name ${!section} --build-${bO} --num-thr 24 >& log_${oBase}_NVU8int_NTH24_cmsswval.txt mv valtree.root valtree_${oBase}.root done done diff --git a/validation-snb-cmssw-10mu-fulldet-build.sh b/validation-snb-cmssw-10mu-fulldet-build.sh index 1bfc71f682b24..dd937f48865c4 100755 --- a/validation-snb-cmssw-10mu-fulldet-build.sh +++ b/validation-snb-cmssw-10mu-fulldet-build.sh @@ -1,6 +1,6 @@ #! /bin/bash -make -j 12 WITH_ROOT=yes CPPUSERFLAGS+=-DCLEAN_SEEDS CXXUSERFLAGS+=-DCLEAN_SEEDS +make -j 12 WITH_ROOT=yes dir=/data/nfsmic/slava77/samples/2017/pass-4874f28/initialStep file=memoryFile.fv3.recT.072617.bin @@ -13,8 +13,8 @@ ECP2=${dir}/10muEta17to24Pt1to10/${file} base=SNB_CMSSW_10mu -for sV in "SimSeed " "CMSSeed --cmssw-seeds" -do echo $sV | while read -r sN sO +for sV in "SimSeed " "CMSSeed --cmssw-seeds --clean-seeds" +do echo $sV | while read -r sN sO sC do for section in ECN2 ECN1 BRL ECP1 ECP2 do @@ -23,7 +23,7 @@ do echo $sV | while read -r sN sO do oBase=${base}_${sN}_${section}_${bN} echo "${oBase}: validation [nTH:24, nVU:8]" - ./mkFit/mkFit ${sO} --geom CMS-2017 --root-val --read --file-name ${!section} --build-${bO} --num-thr 24 >& log_${oBase}_NVU8int_NTH24_val.txt + ./mkFit/mkFit ${sO} ${sC} --geom CMS-2017 --root-val --read --file-name ${!section} --build-${bO} --num-thr 24 >& log_${oBase}_NVU8int_NTH24_val.txt mv valtree.root valtree_${oBase}.root done done diff --git a/validation-snb-cmssw-PU70-fulldet-build.sh b/validation-snb-cmssw-PU70-fulldet-build.sh deleted file mode 100755 index 1137a6e5b3ac2..0000000000000 --- a/validation-snb-cmssw-PU70-fulldet-build.sh +++ /dev/null @@ -1,37 +0,0 @@ -#! /bin/bash - -make -j 12 WITH_ROOT=yes CPPUSERFLAGS+=-DCLEAN_SEEDS CXXUSERFLAGS+=-DCLEAN_SEEDS - -dir=/data/nfsmic/slava77/samples/2017/pass-4874f28/initialStep/PU70/10224.0_TTbar_13+TTbar_13TeV_TuneCUETP8M1_2017PU_GenSimFullINPUT+DigiFullPU_2017PU+RecoFullPU_2017PU+HARVESTFullPU_2017PU -file=memoryFile.fv3.clean.writeAll.recT.072617.bin - -base=SNB_CMSSW_PU70 - -for sV in "SimSeed " "CMSSeed --cmssw-seeds" -do echo $sV | while read -r sN sO - do - for bV in "BH bh" "STD std" "CE ce" - do echo $bV | while read -r bN bO - do - oBase=${base}_${sN}_${bN} - echo "${oBase}: validation [nTH:24, nVU:8]" - ./mkFit/mkFit ${sO} --geom CMS-2017 --root-val --read --file-name ${dir}/${file} --build-${bO} --num-thr 24 >& log_${oBase}_NVU8int_NTH24_val.txt - mv valtree.root valtree_${oBase}.root - done - done - done -done - -make clean - -for seed in SimSeed CMSSeed -do - oBase=${base}_${seed} - for build in BH STD CE - do - root -b -q -l runValidation.C\(\"_${oBase}_${build}\"\) - done - root -b -q -l makeValidation.C\(\"${oBase}\"\) -done - -make distclean diff --git a/validation-snb-cmssw-ttbar-fulldet-build-extrectracks.sh b/validation-snb-cmssw-ttbar-fulldet-build-extrectracks.sh index 1d4781d63d4e7..61063da1dc945 100755 --- a/validation-snb-cmssw-ttbar-fulldet-build-extrectracks.sh +++ b/validation-snb-cmssw-ttbar-fulldet-build-extrectracks.sh @@ -1,6 +1,6 @@ #! /bin/bash -make -j 12 WITH_ROOT=yes CPPUSERFLAGS+=-DCLEAN_SEEDS CXXUSERFLAGS+=-DCLEAN_SEEDS +make -j 12 WITH_ROOT=yes dir=/data/nfsmic/slava77/samples/2017/pass-4874f28/initialStep file=memoryFile.fv3.clean.writeAll.recT.072617.bin @@ -18,7 +18,7 @@ do do oBase=${base}_${ttbar}_${bN} echo "${oBase}: validation [nTH:24, nVU:8]" - ./mkFit/mkFit --cmssw-seeds --geom CMS-2017 --cmssw-val --ext-rec-tracks --read --file-name ${dir}/${!ttbar}/${file} --build-${bO} --num-thr 24 >& log_${oBase}_NVU8int_NTH24_cmsswval.txt + ./mkFit/mkFit --cmssw-seeds --clean-seeds --geom CMS-2017 --cmssw-val --ext-rec-tracks --read --file-name ${dir}/${!ttbar}/${file} --build-${bO} --num-thr 24 >& log_${oBase}_NVU8int_NTH24_cmsswval.txt mv valtree.root valtree_${oBase}.root done done diff --git a/validation-snb-cmssw-ttbar-fulldet-build.sh b/validation-snb-cmssw-ttbar-fulldet-build.sh new file mode 100755 index 0000000000000..cb3e484d91fec --- /dev/null +++ b/validation-snb-cmssw-ttbar-fulldet-build.sh @@ -0,0 +1,47 @@ +#! /bin/bash + +make -j 12 WITH_ROOT=yes + +dir=/data/nfsmic/slava77/samples/2017/pass-4874f28/initialStep +file=memoryFile.fv3.clean.writeAll.recT.072617.bin + +NoPU=10024.0_TTbar_13+TTbar_13TeV_TuneCUETP8M1_2017_GenSimFullINPUT+DigiFull_2017+RecoFull_2017+ALCAFull_2017+HARVESTFull_2017 +PU35=10224.0_TTbar_13+TTbar_13TeV_TuneCUETP8M1_2017PU_GenSimFullINPUT+DigiFullPU_2017PU+RecoFullPU_2017PU+HARVESTFullPU_2017PU +PU70=PU70/10224.0_TTbar_13+TTbar_13TeV_TuneCUETP8M1_2017PU_GenSimFullINPUT+DigiFullPU_2017PU+RecoFullPU_2017PU+HARVESTFullPU_2017PU + +base=SNB_CMSSW_TTbar + +for ttbar in NoPU PU35 PU70 +do + for sV in "SimSeed " "CMSSeed --cmssw-seeds --clean-seeds" + do echo $sV | while read -r sN sO sC + do + for bV in "BH bh" "STD std" "CE ce" + do echo $bV | while read -r bN bO + do + oBase=${base}_${ttbar}_${sN}_${bN} + echo "${oBase}: validation [nTH:24, nVU:8]" + ./mkFit/mkFit ${sO} ${sC} --geom CMS-2017 --root-val --read --file-name ${dir}/${!ttbar}/${file} --build-${bO} --num-thr 24 >& log_${oBase}_NVU8int_NTH24_val.txt + mv valtree.root valtree_${oBase}.root + done + done + done + done +done + +make clean + +for ttbar in NoPU PU35 PU70 +do + for seed in SimSeed CMSSeed + do + oBase=${base}_${ttbar}_${seed} + for build in BH STD CE + do + root -b -q -l runValidation.C\(\"_${oBase}_${build}\"\) + done + root -b -q -l makeValidation.C\(\"${oBase}\"\) + done +done + +make distclean diff --git a/validationMIC-build-10mu.sh b/validationMIC-build-10mu.sh index 28d674abe954a..8ea277155551c 100755 --- a/validationMIC-build-10mu.sh +++ b/validationMIC-build-10mu.sh @@ -9,13 +9,16 @@ ECP1=${BIN_DATA_PATH}/10muEta055to175Pt1to10/memoryFile.fv3.recT.072617.bin ECP2=${BIN_DATA_PATH}/10muEta17to24Pt1to10/memoryFile.fv3.recT.072617.bin runValidation(){ - for sV in "sim " "see --cmssw-seeds"; do echo $sV | while read -r sN sO; do + for sV in "sim " "see --cmssw-seeds --clean-seeds"; do echo $sV | while read -r sN sO sC; do + if [ "${1}" == 0 ] + sC="" + fi for section in ECN2 ECN1 BRL ECP1 ECP2; do for bV in "BH bh" "STD std" "CE ce"; do echo $bV | while read -r bN bO; do oBase=${base}_${sN}_${section}_${bN} nTH=8 echo "${oBase}: validation [nTH:${nTH}, nVU:8]" - ./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${!section} --build-${bO} ${sO} --num-thr ${nTH} >& log_${oBase}_NVU8int_NTH${nTH}_val.txt + ./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${!section} --build-${bO} ${sO} ${sc} --num-thr ${nTH} >& log_${oBase}_NVU8int_NTH${nTH}_val.txt mv valtree.root valtree_${oBase}.root done done @@ -23,8 +26,6 @@ runValidation(){ done done - make clean - for opt in sim see do for section in ECN2 ECN1 BRL ECP1 ECP2 @@ -50,24 +51,21 @@ runValidation(){ root -b -q -l makeValidation.C+\(\"${oBase}_FullDet\"\) done - - make distclean } #cleanup first make clean make distclean +make -j 12 WITH_ROOT=yes export base=SNB_CMSSW_10mu echo Run default with base = ${base} -make -j 12 WITH_ROOT=yes -#this does make clean inside -runValidation +runValidation 0 export base=SNB_CMSSW_10mu_cleanSeed echo Run CLEAN_SEEDS with base = ${base} -make -j 12 WITH_ROOT=yes CPPUSERFLAGS+=-DCLEAN_SEEDS CXXUSERFLAGS+=-DCLEAN_SEEDS -#this does make clean inside -runValidation +runValidation 1 + +make distclean unset base diff --git a/validationMIC-build-PU70.sh b/validationMIC-build-PU70.sh index 97dc0085f902c..036fa84bd0854 100755 --- a/validationMIC-build-PU70.sh +++ b/validationMIC-build-PU70.sh @@ -5,20 +5,21 @@ fin=${BIN_DATA_PATH}/PU70/10224.0_TTbar_13+TTbar_13TeV_TuneCUETP8M1_2017PU_GenSi runValidation() { - for sV in "sim " "see --cmssw-seeds"; do echo $sV | while read -r sN sO; do + for sV in "sim " "see --cmssw-seeds --clean-seeds"; do echo $sV | while read -r sN sO sC; do + if [ "$1" == 0 ] ; then + sC="" + fi for bV in "BH bh" "STD std" "CE ce"; do echo $bV | while read -r bN bO; do oBase=${base}_${sN}_${bN} nTH=8 echo "${oBase}: validation [nTH:${nTH}, nVU:8]" - ./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${fin} --build-${bO} ${sO} --num-thr ${nTH} >& log_${oBase}_NVU8int_NTH${nTH}_val.txt + ./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${fin} --build-${bO} ${sO} ${sC} --num-thr ${nTH} >& log_${oBase}_NVU8int_NTH${nTH}_val.txt mv valtree.root valtree_${oBase}.root done done done done - - make clean - + for opt in sim see do oBase=${base}_${opt} @@ -28,25 +29,22 @@ runValidation() done root -b -q -l makeValidation.C+\(\"${oBase}\"\) done - - make distclean } #cleanup first make clean make distclean +make -j 12 WITH_ROOT=yes export base=SNB_CMSSW_PU70_clean echo Run default build with base = ${base} -make -j 12 WITH_ROOT=yes -#this does make clean inside -runValidation +runValidation 0 export base=SNB_CMSSW_PU70_clean_cleanSeed echo Run CLEAN_SEEDS with base = ${base} -make -j 12 WITH_ROOT=yes CPPUSERFLAGS+=-DCLEAN_SEEDS CXXUSERFLAGS+=-DCLEAN_SEEDS -#this does make clean inside -runValidation +runValidation 1 + +make distclean unset base diff --git a/web/move-cmsswval-pu70.sh b/web/move-cmsswval-pu70.sh deleted file mode 100755 index 012605ccd86c8..0000000000000 --- a/web/move-cmsswval-pu70.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash - -dir=${1:-plots} -outdir=${dir}/cmsswval-pu70 -base=SNB_CMSSW_PU70 - -echo "Moving plots and text files locally to ${outdir}" -for seed in SimSeed CMSSeed -do - fulldir=${outdir}/${seed} - mkdir -p ${fulldir} - - mv ${base}_${seed}_*.png ${fulldir} - for build in BH STD CE - do - vbase=validation_${base}_${seed}_${build} - mv ${vbase}/totals_${vbase}.txt ${fulldir} - done -done - -host=kmcdermo@lxplus.cern.ch -whost=${host}":~/www" -echo "Moving plots and text files remotely to ${whost}" -scp -r ${dir} ${whost} - -echo "Executing remotely ./makereadable.sh ${outdir}" -ssh ${host} bash -c "' -cd www -./makereadable.sh ${outdir} -exit -'" - -echo "Removing local files" -for seed in SimSeed CMSSeed -do - for build in BH STD CE - do - testbase=${base}_${seed}_${build} - rm -rf validation_${testbase} - rm -rf log_${testbase}_NVU8int_NTH24_val.txt - done -done - -rm -rf ${dir} diff --git a/web/move-cmsswval-ttbar.sh b/web/move-cmsswval-ttbar.sh new file mode 100755 index 0000000000000..16561e5272a06 --- /dev/null +++ b/web/move-cmsswval-ttbar.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +dir=${1:-plots} +outdir=${dir}/cmsswval-ttbar +base=SNB_CMSSW_TTbar + +echo "Moving plots and text files locally to ${outdir}" +for ttbar in NoPU PU35 PU70 +do + for seed in SimSeed CMSSeed + do + fulldir=${outdir}/${ttbar}/${seed} + mkdir -p ${fulldir} + + mv ${base}_${ttbar}_${seed}_*.png ${fulldir} + for build in BH STD CE + do + vbase=validation_${base}_${ttbar}_${seed}_${build} + mv ${vbase}/totals_${vbase}.txt ${fulldir} + done + done +done + +host=kmcdermo@lxplus.cern.ch +whost=${host}":~/www" +echo "Moving plots and text files remotely to ${whost}" +scp -r ${dir} ${whost} + +echo "Executing remotely ./makereadable.sh ${outdir}" +ssh ${host} bash -c "' +cd www +./makereadable.sh ${outdir} +exit +'" + +echo "Removing local files" +for ttbar in NoPU PU35 PU70 +do + for seed in SimSeed CMSSeed + do + for build in BH STD CE + do + testbase=${base}_${ttbar}_${seed}_${build} + rm -rf validation_${testbase} + rm -rf log_${testbase}_NVU8int_NTH24_val.txt + done + done +done + +rm -rf ${dir} From f72d8511eed2e21246a4f21b6a0144546d0dd65b Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Thu, 17 Aug 2017 18:53:16 -0700 Subject: [PATCH 147/172] update validation description to include new assingment of seedID in cmssw reco track validation --- validation-desc.txt | 145 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 132 insertions(+), 13 deletions(-) diff --git a/validation-desc.txt b/validation-desc.txt index df7b32145802b..71c3f99f07a7c 100644 --- a/validation-desc.txt +++ b/validation-desc.txt @@ -13,6 +13,7 @@ E. Overview of scripts F. Hit map/remapping logic G. Extra info on ID and mask assignments H. Special note about duplicate rate +I. The use of label_ ===================== A. Overview of code @@ -22,7 +23,7 @@ TTreeValidation will only compile the necessary ROOT code with WITH_ROOT=yes ena Three types of validation exist within TTreeValidation: [1.] "Building validation", enabled with Config::root_val, via the command line option: --root-val -[2.] "CMSSW external tracks building validation", enabled with Config::cmssw_val, via the command line options: --cmssw-val --cmssw-seeds --ext-rec-tracks --geom CMS-2017 +[2.] "CMSSW external tracks building validation", enabled with Config::cmssw_val, via the command line options: --cmssw-val --cmssw-seeds --clean-seeds --ext-rec-tracks --geom CMS-2017 [3.] "Fit validation", enabled with Config::fit_val, via the command line option: --fit-val We will ignore fit validation for the moment. The main idea behind the other two is that the validation routines are called outside of the standard timed sections, and as such, we do not care too much about performance, as long as it takes a reasonable amount of time to complete. Of course, the full wall clock time matters when running multiple events in flight, and because there is a lot of I/O as well as moves and stores that would hurt the performance with the validation enabled, these routines are ignored if the command line option "--silent" is enabled. @@ -36,8 +37,8 @@ The building validation takes advantage of filling two trees per event per track - cmsswfrtree (filled once per mkFit build track) [1.] validation exists in the following combinations of geometry and seed source: - - ToyMC, with sim seeds or find-seeds - - CMSSW, with sim seeds or cmssw-seeds + - ToyMC, with sim seeds or --find-seeds + - CMSSW, with sim seeds or --cmssw-seeds (+ --clean-seeds) Upon instantiation of the TTreeValidation object, the respective ROOT trees are defined and allocated on the heap, along with setting the addresses of all the branches. After the building is completed in mkFit, we have to have the tracks in their standard event containers, namely: seedTracks_, candidateTracks_, and fitTracks_. In the standard combinatorial or clone engine, we have to copy out the built tracks from event of combined candidates into candidateTracks_ via: builder.quality_store_tracks() in mkFit/buildtestMPlex.cc. Since we do not yet have fitting after building, we just set the fitTracks_ equal to the candidateTracks_. For ease, I will from now on refer to the candidateTracks_ as buildTracks_. @@ -56,6 +57,7 @@ Following each event, each of the track and extra objects are cleared. In additi The following routines are then called after the building (MkBuilder.cc, Event.cc, TTreeValidation.cc, Track.cc): [1.] builder.root_val() + : (actually run clean_cms_simtracks() when using CMS geom and using sim tracks as reference set) : remap_seed_hits() : remap_cand_hits() : prep_recotracks() @@ -81,6 +83,8 @@ The following routines are then called after the building (MkBuilder.cc, Event.c : validation_.fillFakeRateTree(*this) [2.] builder.cmssw_val() + : (when using N^2 cleanings, Event::clean_cms_seedtracks()) + : (actually runs m_event->validation.makeSeedTkToCMSSWTkMap() from MkBuilder::prepare_seeds()) : remap_cand_hits() : prep_recotracks() : prep_tracks(buildtracks,buildextras) @@ -91,6 +95,7 @@ The following routines are then called after the building (MkBuilder.cc, Event.c : m_event->Validate() : validation_.setTrackExtras(*this) : extra.setCMSSWTrackInfo() // Chi2 and dphi matching (also incudes option for nHits matching) + : storeSeedAndMCID() : validation_.makeCMSSWTkToRecoTksMaps(*this) : mapRefTkToRecoTks(buildtracks,buildextras,cmsswToBuildMap) : validation_.fillCMSSWEfficiencyTree(*this) @@ -106,8 +111,17 @@ The following routines are then called after the building (MkBuilder.cc, Event.c I. Tracks and Extras Prep +++++++++++++++++++++++++++ +- clean_cms_simtracks() + : loop over sim tracks + : mark sim track status not findable if (nLayers < [Config::cmsSelMinLayers == 8] || cmssw.pT() < [Config::cmsSelMinPt == 0.5]) + : tracks are not removed from collection, just have this bit set. this way the mcTrackID == position in vector == label + +- clean_cms_seedtracks() + : cmssw seed tracks are cleaned according to closeness in deta, dphi, dR to other cmssw seed tracks--> duplicate removal + : loop over cleaned seed tracks, and if label_ == -1, then incrementally decrease label (so second -1 seed is -2, third is -3) + - prep_tracks(tracks,extras) - : Loop over all tracks in consideration + : Loop over all track collections in consideration : sort hits inside track by layer : needed for counting unique layers and for association routines : emplace_back a track extra, initialized with the label of the track (which happens to be its seed ID) // if using sim seeds, we know that seed ID == sim ID : m_event->validation_.alignTracks(tracks,extras,alignExtra) @@ -146,6 +160,7 @@ The following routines are then called after the building (MkBuilder.cc, Event.c : also include track momentum phi, and a list of hits inside a map. map key = layer, map value = vector of hit indices : loop over build tracks : setCMSSWTrackIDInfo() : require matching by chi2 and dphi + : storeMCandSeedID() - setMCTrackIDInfoByLabel() : if no hits are found after seed, mcTrackID == -4, and skip the rest of the function @@ -202,6 +217,17 @@ The following routines are then called after the building (MkBuilder.cc, Event.c : loop over reco tracks : map[extra.seedID()] = track.label() +- makeSeedTkToCMSSWTkMap(event) + : this is run AFTER seed cleaning but BEFORE the seeds are sorted in eta in prepare_seeds() + : if seed track index in vector == cmssw track label(), store map key = seed track label(), map value = cmssw track label() in seedToCmsswMap (seedID of cmssw track) + +- storeMCandSeedID() + : reminder: both the candidate tracks and the cmssw tracks have had their labels reassigned, but their original labels were stored in their track extra seedIDs. reminder, seedID of candidate track points to the label of the seed track. label on seed track == sim track reference, if it exists! + : loop over candidate tracks + : set mcTrackID == seedID of track + : if seedToCmsswMap[cand.label()] exists, then set the seedID equal to the mapped value (i.e. the seedID of the cmssw track!) + : else, set seedID == -1 + ++++++++++++++++++++ III. TTree Filling ++++++++++++++++++++ @@ -252,22 +278,22 @@ The following routines are then called after the building (MkBuilder.cc, Event.c - fillCMSSWEfficiencyTree() : loop over cmsswtracks - : get label of cmsswtrack + : get label of cmsswtrack, seedID : store cmssw track PCA parameters + nhits, nlayers, last layer : if cmsswToBuilddMap[cmsswtrack.label()] has value : get first build track matched (i.e. the one with the highest nHits --> or lowest sum hit chi2 as provided by sort from above) : store build track parameters + errors - : store nHits, nlayers, last layer, last hit parameters, hit and helix chi2, duplicate info + : store nHits, nlayers, last layer, last hit parameters, hit and helix chi2, duplicate info, seedID : swim cmssw phi to mkFit track, store it : fill cmsswefftree - fillCMSSWFakeRateTree() : loop over build tracks : store build track parameters + errors - : store nHits, nlayers, last layer, last hit parameters, hit and helix chi2, duplicate info + : store nHits, nlayers, last layer, last hit parameters, hit and helix chi2, duplicate info, seedID : get cmsswTrackID, assign cmsswmask according to section D and G : if cmsswmask == 1 - : store cmssw track PCA parameters + nhits, nlayers, last layer + : store cmssw track PCA parameters + nhits, nlayers, last layer, seedID : swim cmssw phi to mkFit track, store it : fill cmsswefftree @@ -317,11 +343,14 @@ Duplicate Rate [PlotValidation::PlotDuplicateRate()], see special note in sectio E. Overview of scripts ======================== -./validation-snb-toymc-fulldet-build.sh +I. ./validation-snb-toymc-fulldet-build.sh Runs ToyMC full detector tracking for BH, STD, CE, for 400 events with nTracks/event = 2500. Sim seeds only. -./validation-snb-cmssw-fulldet-build.sh -Runs CMSSW full detector tracking for BH, STD, CE, for ~1000 events with 10 muons/event, with sim and cmssw seeds. +To move the images + text files and clean up directory: +./web/move-toymcval.sh ${outdir name} + +II. ./validation-snb-cmssw-10mu-fulldet-build.sh +Runs CMSSW full detector tracking for BH, STD, CE, for ~1000 events with 10 muons/event, with sim and cmssw seeds, using N^2 cleaning for cmssw seeds. Samples are split by eta region. Building is run for each region: - ECN2: 2.4 < eta < 1.7 - ECN1: 1.75 < eta < 0.55 @@ -331,8 +360,30 @@ Samples are split by eta region. Building is run for each region: Validation plots are produced for each sample (region), seeding source, and building routine. At the very end, validation trees are hadd'ed for each region in a given seed source + building routine. Plots are produced again to yield "full-detector" tracking. -./validation-snb-cmssw-fulldet-extrectracks.sh -Same as above, but now only run with cmssw seeds (as we are comparing directly to cmssw output as the reference). +To move the images + text files and clean up directory: +./web/move-cmsswval-10mu.sh ${outdir name} + +III. ./validation-snb-cmssw-10mu-fulldet-extrectracks.sh +Same as II., but now only run with cmssw seeds (as we are comparing directly to cmssw output as the reference). + +To move the images + text files and clean up directory: +./web/move-cmsswval-10mu-extrectracks.sh ${outdir name} + +IV. ./validation-snb-cmssw-ttbar-fulldet.sh +Runs CMSSW full detector tracking for BH, STD, CE, for three different ttbar samples with 100 events each, with sim and cmssw seeds, using N^2 cleaning for cmssw seeds. +TTbar samples: +- No PU +- PU 35 +- PU 70 + +To move the images + text files and clean up directory: +./web/move-cmsswval-ttbar.sh ${outdir name} + +V. ./validation-snb-cmssw-ttbar-fulldet.sh +Same as IV., but now only run with cmssw seeds, using cmssw rec tracks as the reference set of tracks. + +To move the images + text files and clean up directory: +./web/move-cmsswval-ttbar-extrectracks.sh ${outdir name} ============================ F. Hit map/remapping logic @@ -432,3 +483,71 @@ In other words, we cannot fill numerator n-1 times sim track is matched, while d As a result, DR is simply if a sim track is duplicated once, and not how many times it is duplicated. We can revert back to the n-1 filling for the numerator to weight by the amount of times a sim track is duplicated, but this would mean going back to the TH1Fs, and then using the binomial errors (or computing by hand the CP errors or something), in the case that the DR in any bin > 1... This would break the flow of the printouts as well as the stacking macro, but could be done with some mild pain. + +====================== + I. The use of label_ +====================== + +*** Originally from Issue #99 on https://github.com/cerati/mictest *** + +## Introduction + +The label currently has multiple meanings depending on the type of track and where it is in the pipeline between seeding, building, and validation. To begin, allow me to map out the differences in inputs for the various validation sequences, and the associated track associator function: + +1. ToyMC Geom + sim seeds: setMCTrackIDInfoByLabel() +2. CMSSW Geom + sim seeds (--geom CMS-2017): setMCTrackIDInfoByLabel() +3. ToyMC Geom + found seeds (--find-seeds): setMCTrackIDInfo() +4. CMSSW Geom + cmssw seeds (--geom CMS-2017 --cmssw-seeds --clean-seeds): setMCTrackIDInfo() +5. CMSSW Geom + cmssw seeds + external CMSSW tracks as reference (--geom CMS-2017 --cmssw-seeds --clean-seeds: setCMSSWTrackIDInfo() + +## Important note about hits and relation to the label: +As a reminder, all hits that originate from a simulated particle will have a **mcHitID_** >= 0. This is the index to the vector of simHitInfo_, where each element of the vector contains additional information about the hit. Most importantly, it stores the **mcTrackID_** that the hit originated from. + +As such, the following must be respected for the tracks inside simTracks_: **label_** == **mcTrackID_** == **position** inside the track vector. If the simTracks_ are moved, shuffled, sorted, deleted, etc., this means that the matching of candidate tracks via **mcTrackID_'s** via hits via **mcHitID_** will be ruined! + +## Case 1. and 2.: setMCTrackIDInfoByLabel() + +In both 1. and 2., the seeds are generated from the simtracks, and as such their **label_** == **mcTrackID_**. Before the building starts, the seeds can be moved around and into different structures. Regardless, for each seed, a candidate track is created with its **label_** equal to the **label_** of the seed it originated from. At the end of building, the candidate tracks are dumped into their conventional candidateTracks_ collection. At this point, the **label_** of the track may not be pointing to its **position** inside the vector, but still uniquely identifies it as to which seed it came from. + +So we then create a TrackExtra for the track, storing the **label_** as the **seedID**, and then reassign the **label_** of track to be its **position** inside the candidate track vector. We actually do this for the seed and fit tracks also. Each track collection has an associated track extra collection, indexed the same such that candidateTracks_[i] has an associated candidateTracksExtra_[i]. + +The associator is run for each candidate track, using the fact that the now stored **seedID_** also points to the correct **mcTrackID_** this candidate was created from, counting the number of hits in the candidate track after the seed matching this id. If more than 50% are matched, the candidate track now sets its track extra **mcTrackID_** == **seedID_**. + +We then produce two maps to map the candidate tracks: +1. simToCandidates: + - map key = **mcTrackID** + - mapped value = vector of candidate track **label_'s**, where the **label_'s** now represent the **positions** in the candidate vector for tracks who have the **mcTrackID_** in question + +2. seedToCandidates: + - map key = **seedID_** + - mapped value = **label_** of candidate track (again, the **label_** now being the **position** inside the track vector) + +These maps are then used to get the associated sim and reco information for the trees. + +## Case 3. and 4.: setMCTrackIDInfo() + +In both 3. and 4., the seedTracks are not intrinsically related to the simTracks_ . For 3., the seeds are generated from find_seeds(), and the **label_** assigned to the track is just the index at which the seed was created. For 4., the **label_** is the **mcTrackID** for the sim track it is most closely assocaited to, if it exists. + +The CMSSW seeds are read in, and then cleaned. If a surviving seed has a **label_** > 0, the label stays the same, and becomes its **seedID_**. In the case of the N^2 cleaning, some seeds may remain which have a **label_** == -1. Since there might be more than one and we want to uniquely identify them after building, we reassign the **label_'s** with an increasing negative number. So the first seed track with **label_** == -1 has label == -1, the second track with **label_** == -1 then has a new **label_* == -2, third track assigned to == -3, etc. + +It is clear here that **label_** of the seed track does not have to equal the **position** inside the track vector! So the building proceeds in the same manner as 1. and 2., where each seed first generates a single candidate track with a **label_** equal to the seed **label_** which happens to be its **seedID_**. The candidateTracks_ are dumped out in some order, where the **label_** is still the **seedID_**. + +We then generate a TrackExtra for each candidate track (and seed and fit tracks), with the **seedID_** set to the **label_**, then reassigning the **label_** to be the **position** inside the track vector. + +The associator is run, now just counting how many hits on the candidate track are matched to a single **mcTrackID**. If the fraction of hits matching a single **mcTrackID** is greater than 75%, then the track extra **mcTrackID_** is set to the matched **mcTrackID**. + +The associate maps are then used in the same fashion as described above. + +## Case 5.: setCMSSWTrackIDInfo() + +The seed cleaning and labeling is the same as described for 4. The only difference now is that we run a special sequence before the seeds are sorted in eta, storing the original index position of the seed track as a mapped value of the seed track label. This is because we wish to keep track of which cmssw track originates from which seed track, and the matching is such that the cmssw track label (before being reassigned to its position) == seedID of the track, which equals the position of a seed track inside the track vector. Not all seed tracks will have this property, as not all seeds become cmssw tracks. + +The building proceeds, tracks are dumped out, track extra **seedID_** are set to the track candidate **label_**, and the **label_** is reassigned to the track's **position** inside the vector. We also take the chance to generate a track extra for the CMSSW tracks, storing the **label_** as the **seedID_**, and reassigning the **label_** to the CMSSW track's position inside the extRecTracks_ vector. + +Afterwards, we set the **mcTrackID** of the candidate track == **seedID** (as described previously). In addition, if the candidate track **label_** is mapped, then we set the **seedID_** == mapped value (i.e. the seedID of the cmssw track before it was realigned --> the position of the seed track in its vector before it was moved in eta bins). + +The candidate track to CMSSW associator is run, matching by chi2 and dphi. If track finds at least one CMSSW track with a match, the **cmsswTrackID_** is set to the **label_** of the CMSSW track. We then produce a map of the CMSSW tracks to the candidate mkFit tracks. + +cmsswToCandidates: + - map key = **cmsswTrackID** (which is now the position of a cmssw track in extRecTracks_) + - mapped value = vector of candidate track **label_'s**, where the **label_'s** now represent the **positions** in the candidate vector for tracks who have the **cmsswTrackID_** in question From c95bad5951b3629dc34b7017ac493d8d4700ee71 Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Fri, 18 Aug 2017 07:35:57 -0700 Subject: [PATCH 148/172] bug fix to put order of mapping seeds from cmssw tracks in the right place --- Event.cc | 29 +++++++++++++++++++---------- Event.h | 1 + TTreeValidation.cc | 6 +++--- mkFit/MkBuilder.cc | 18 ++++++++++++++++++ validation-desc.txt | 9 +++++---- 5 files changed, 46 insertions(+), 17 deletions(-) diff --git a/Event.cc b/Event.cc index 158f7e2d1b154..b3492aec77939 100644 --- a/Event.cc +++ b/Event.cc @@ -515,15 +515,6 @@ void Event::read_in(DataFile &data_file, FILE *in_fp) ns = -ns; } - if (Config::cleanCmsswSeeds) - { - ns = clean_cms_seedtracks();//operates on seedTracks_; swaps cleaned seeds into seedTracks_; returns number of cleaned seedTracks - } - else - { - ns = clean_cms_seedtracks_badlabel();//operates on seedTracks_, removes those with label == -1; - } - #ifdef DUMP_SEEDS printf("Read %i seedtracks (neg value means actual reading was skipped)\n", ns); for (int it = 0; it < ns; it++) @@ -791,12 +782,30 @@ int Event::clean_cms_seedtracks() int Event::clean_cms_seedtracks_badlabel() { - printf("***\n*** MkBuilder::import_seeds REMOVING SEEDS WITH BAD LABEL. This is a development hack. ***\n***\n"); + printf("***\n*** REMOVING SEEDS WITH BAD LABEL. This is a development hack. ***\n***\n"); TrackVec buf; seedTracks_.swap(buf); std::copy_if(buf.begin(), buf.end(), std::back_inserter(seedTracks_), [](const Track& t){ return t.label() >= 0; }); return seedTracks_.size(); } +int Event::use_seeds_from_cmsswtracks() +{ + int ns = seedTracks_.size(); + + TrackVec cleanSeedTracks; + cleanSeedTracks.reserve(ns); + + int i = 0; + for (auto&& cmsswtrack : extRecTracks_) + { + cleanSeedTracks.emplace_back(seedTracks_[cmsswtrack.label()]); + } + + seedTracks_.swap(cleanSeedTracks); + + return seedTracks_.size(); +} + //============================================================================== // DataFile //============================================================================== diff --git a/Event.h b/Event.h index d941ca36d36c8..31b706def1b62 100644 --- a/Event.h +++ b/Event.h @@ -35,6 +35,7 @@ class Event void write_out(DataFile &data_file); void read_in (DataFile &data_file, FILE *in_fp=0); + int use_seeds_from_cmsswtracks(); //special mode --> use only seeds which generated cmssw reco track int clean_cms_simtracks(); int clean_cms_seedtracks(); //operates on seedTracks_; returns the number of cleaned seeds int clean_cms_seedtracks_badlabel(); //operates on seedTracks_, removes those with label == -1; diff --git a/TTreeValidation.cc b/TTreeValidation.cc index 432a759879379..dfb0a83e90c58 100644 --- a/TTreeValidation.cc +++ b/TTreeValidation.cc @@ -534,6 +534,9 @@ void TTreeValidation::setTrackExtras(Event& ev) if (Config::cmssw_val) { + // store mcTrackID and seedID correctly + storeSeedAndMCID(ev); + RedTrackVec reducedCMSSW(ev.extRecTracks_.size()); // use 2D chi2 for now, so might as well make use of this object for now for (int itrack = 0; itrack < ev.extRecTracks_.size(); itrack++) { @@ -561,9 +564,6 @@ void TTreeValidation::setTrackExtras(Event& ev) auto&& extra(ev.candidateTracksExtra_[itrack]); extra.setCMSSWTrackIDInfo(track, ev.layerHits_, ev.extRecTracks_,reducedCMSSW); } - - // store mcTrackID and seedID correctly - storeSeedAndMCID(ev); } } diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index 8349645e77c9e..e9d4ea54ddbf6 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -945,6 +945,24 @@ void MkBuilder::PrepareSeeds() { m_event->validation_.makeSeedTkToCMSSWTkMap(*m_event); } + + // CMSSW Seed Cleaning + int ns = 0; + if (Config::cleanCmsswSeeds) + { + ns = m_event->clean_cms_seedtracks(); + } + else + { + if (Config::cmssw_val) + { + ns = m_event->use_seeds_from_cmsswtracks(); + } + else + { + ns = m_event->clean_cms_seedtracks_badlabel(); + } + } } import_seeds(); diff --git a/validation-desc.txt b/validation-desc.txt index 71c3f99f07a7c..8ae1ab85160af 100644 --- a/validation-desc.txt +++ b/validation-desc.txt @@ -83,8 +83,8 @@ The following routines are then called after the building (MkBuilder.cc, Event.c : validation_.fillFakeRateTree(*this) [2.] builder.cmssw_val() - : (when using N^2 cleanings, Event::clean_cms_seedtracks()) : (actually runs m_event->validation.makeSeedTkToCMSSWTkMap() from MkBuilder::prepare_seeds()) + : (when using N^2 cleanings, Event::clean_cms_seedtracks(), or if not using N^2 cleaning, Event::use_seeds_from_cmsswtracks()) : remap_cand_hits() : prep_recotracks() : prep_tracks(buildtracks,buildextras) @@ -218,15 +218,16 @@ The following routines are then called after the building (MkBuilder.cc, Event.c : map[extra.seedID()] = track.label() - makeSeedTkToCMSSWTkMap(event) - : this is run AFTER seed cleaning but BEFORE the seeds are sorted in eta in prepare_seeds() + : this is run BEFORE seed cleaning AND BEFORE the seeds are sorted in eta in prepare_seeds() : if seed track index in vector == cmssw track label(), store map key = seed track label(), map value = cmssw track label() in seedToCmsswMap (seedID of cmssw track) - storeMCandSeedID() : reminder: both the candidate tracks and the cmssw tracks have had their labels reassigned, but their original labels were stored in their track extra seedIDs. reminder, seedID of candidate track points to the label of the seed track. label on seed track == sim track reference, if it exists! : loop over candidate tracks - : set mcTrackID == seedID of track + : set mcTrackID == seedID_ of track : if seedToCmsswMap[cand.label()] exists, then set the seedID equal to the mapped value (i.e. the seedID of the cmssw track!) : else, set seedID == -1 + : After this is run, to get the matching CMSSW track, we then need to loop over the CMSSW track extras with an index based loop, popping out when the cmsswextra[i].seedID() == buidextra[j].seedID() ++++++++++++++++++++ III. TTree Filling @@ -540,7 +541,7 @@ The associate maps are then used in the same fashion as described above. ## Case 5.: setCMSSWTrackIDInfo() -The seed cleaning and labeling is the same as described for 4. The only difference now is that we run a special sequence before the seeds are sorted in eta, storing the original index position of the seed track as a mapped value of the seed track label. This is because we wish to keep track of which cmssw track originates from which seed track, and the matching is such that the cmssw track label (before being reassigned to its position) == seedID of the track, which equals the position of a seed track inside the track vector. Not all seed tracks will have this property, as not all seeds become cmssw tracks. +The seed cleaning and labeling is the same as described for 4. The only difference now is that we run a special sequence before the seeds cleaned and then are sorted in eta, storing the original index position of the seed track as a mapped value of the seed track label. This is because we wish to keep track of which cmssw track originates from which seed track, and the matching is such that the cmssw track label (before being reassigned to its position) == seedID of the track, which equals the position of a seed track inside the track vector. Not all seed tracks will have this property, as not all seeds become cmssw tracks. The building proceeds, tracks are dumped out, track extra **seedID_** are set to the track candidate **label_**, and the **label_** is reassigned to the track's **position** inside the vector. We also take the chance to generate a track extra for the CMSSW tracks, storing the **label_** as the **seedID_**, and reassigning the **label_** to the CMSSW track's position inside the extRecTracks_ vector. From d4b181bf040823561182ad1be4613cd28451b53a Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Sun, 20 Aug 2017 08:56:17 -0700 Subject: [PATCH 149/172] include pure cmssw track validation --- Config.h | 6 +-- TTreeValidation.cc | 56 ++++++++++++++++++-------- TTreeValidation.h | 8 ++-- Track.cc | 95 ++++++++++++++++++++++++++++++++++++++++++++- Track.h | 9 ++++- validation-desc.txt | 77 ++++++++++++++++++++++++++++-------- 6 files changed, 208 insertions(+), 43 deletions(-) diff --git a/Config.h b/Config.h index 79ec6819608c9..b2c759ce702aa 100644 --- a/Config.h +++ b/Config.h @@ -230,9 +230,9 @@ namespace Config constexpr float cmsSelMinPt = 0.5; // config on validation - constexpr int nMinFoundHits = 7; - constexpr float minCMSSWMatchChi2 = 50; - constexpr float minCMSSWMatchdPhi = 0.03; + constexpr int nMinFoundHits = 7; + constexpr float minCMSSWMatchChi2[6] = {100,100,50,50,30,20}; + constexpr float minCMSSWMatchdPhi[6] = {0.2,0.2,0.1,0.05,0.01,0.005}; constexpr int nCMSSWMatchHitsAfterSeed = 5; extern bool root_val; extern bool cmssw_val; diff --git a/TTreeValidation.cc b/TTreeValidation.cc index dfb0a83e90c58..ab16ad081c5c7 100644 --- a/TTreeValidation.cc +++ b/TTreeValidation.cc @@ -350,7 +350,7 @@ void TTreeValidation::initializeCMSSWEfficiencyTree() cmsswefftree_->Branch("hitchi2_build",&hitchi2_build_ceff_); cmsswefftree_->Branch("helixchi2_build",&helixchi2_build_ceff_); - cmsswefftree_->Branch("phi_cmssw_build",&phi_cmssw_build_ceff_); + cmsswefftree_->Branch("dphi_build",&dphi_build_ceff_); cmsswefftree_->Branch("duplmask_build",&duplmask_build_ceff_); cmsswefftree_->Branch("nTkMatches_build",&nTkMatches_build_ceff_); @@ -387,6 +387,7 @@ void TTreeValidation::initializeCMSSWFakeRateTree() cmsswfrtree_->Branch("hitchi2_build",&hitchi2_build_cFR_); cmsswfrtree_->Branch("helixchi2_build",&helixchi2_build_cFR_); + cmsswfrtree_->Branch("dphi_build",&dphi_build_cFR_); cmsswfrtree_->Branch("duplmask_build",&duplmask_build_cFR_); cmsswfrtree_->Branch("iTkMatches_build",&iTkMatches_build_cFR_); @@ -402,8 +403,6 @@ void TTreeValidation::initializeCMSSWFakeRateTree() cmsswfrtree_->Branch("nHits_cmssw",&nHits_cmssw_cFR_); cmsswfrtree_->Branch("nLayers_cmssw",&nLayers_cmssw_cFR_); cmsswfrtree_->Branch("lastlyr_cmssw",&lastlyr_cmssw_cFR_); - - cmsswfrtree_->Branch("phi_cmssw_build",&phi_cmssw_build_cFR_); } void TTreeValidation::initializeFitTree() @@ -497,6 +496,9 @@ void TTreeValidation::resetValidationMaps() // reset special map of seed labels to cmssw tracks seedToCmsswMap_.clear(); + + // reset special map of matching build tracks exactly to cmssw tracks through seedIDs + buildToCmsswMap_.clear(); } void TTreeValidation::setTrackExtras(Event& ev) @@ -541,6 +543,7 @@ void TTreeValidation::setTrackExtras(Event& ev) for (int itrack = 0; itrack < ev.extRecTracks_.size(); itrack++) { const auto & cmsswtrack = ev.extRecTracks_[itrack]; + const auto & cmsswextra = ev.extRecTracksExtra_[itrack]; const SVector6 & params = cmsswtrack.parameters(); SVector2 tmpv(params[3],params[5]); @@ -554,7 +557,7 @@ void TTreeValidation::setTrackExtras(Event& ev) } // index inside object is label (as cmsswtracks are now aligned) - reducedCMSSW[itrack] = ReducedTrack(cmsswtrack.label(),tmpv,cmsswtrack.momPhi(),tmpmap); + reducedCMSSW[itrack] = ReducedTrack(cmsswtrack.label(),cmsswextra.seedID(),tmpv,cmsswtrack.momPhi(),tmpmap); } // set cmsswTrackID for built tracks @@ -562,7 +565,15 @@ void TTreeValidation::setTrackExtras(Event& ev) { auto&& track(ev.candidateTracks_[itrack]); auto&& extra(ev.candidateTracksExtra_[itrack]); - extra.setCMSSWTrackIDInfo(track, ev.layerHits_, ev.extRecTracks_,reducedCMSSW); + if (Config::cleanCmsswSeeds) + { + extra.setCMSSWTrackIDInfo(track, ev.layerHits_, ev.extRecTracks_, reducedCMSSW); + } + else + { + auto&& cmsswtrack(ev.extRecTracks_[buildToCmsswMap_[track.label()]]); + extra.setCMSSWTrackIDInfoByLabel(track, ev.layerHits_, cmsswtrack, reducedCMSSW[cmsswtrack.label()]); + } } } } @@ -671,6 +682,9 @@ void TTreeValidation::storeSeedAndMCID(Event& ev) { const auto& buildtracks = ev.candidateTracks_; auto& buildextras = ev.candidateTracksExtra_; + + const auto& cmsswtracks = ev.extRecTracks_; + auto& cmsswextras = ev.extRecTracksExtra_; for (int itrack = 0; itrack < buildtracks.size(); itrack++) { @@ -681,6 +695,14 @@ void TTreeValidation::storeSeedAndMCID(Event& ev) if (seedToCmsswMap_.count(seedID)) { extra.setseedID(seedToCmsswMap_[seedID]); + for (int ctrack = 0; ctrack < cmsswextras.size(); ctrack++) + { + if (cmsswextras[ctrack].seedID() == extra.seedID()) + { + buildToCmsswMap_[itrack] = cmsswtracks[ctrack].label(); // cmsstracks[ctrack].label() == ctrack! + break; + } + } } else { @@ -1591,8 +1613,8 @@ void TTreeValidation::fillCMSSWEfficiencyTree(const Event& ev) hitchi2_build_ceff_ = buildtrack.chi2(); helixchi2_build_ceff_ = buildextra.helixChi2(); - // swim phi - phi_cmssw_build_ceff_ = squashPhiGeneral(cmsswtrack.swimPhiToR(buildtrack.x(),buildtrack.y())); + // swim dphi + dphi_build_ceff_ = buildextra.dPhi(); // duplicate info duplmask_build_ceff_ = buildextra.isDuplicate(); @@ -1625,7 +1647,7 @@ void TTreeValidation::fillCMSSWEfficiencyTree(const Event& ev) hitchi2_build_ceff_ = -99; helixchi2_build_ceff_ = -99; - phi_cmssw_build_ceff_ = -99; + dphi_build_ceff_ = -99; duplmask_build_ceff_ = 2; // mask means unmatched cmssw track nTkMatches_build_ceff_ = -99; // unmatched @@ -1677,11 +1699,14 @@ void TTreeValidation::fillCMSSWFakeRateTree(const Event& ev) // chi2 info hitchi2_build_cFR_ = buildtrack.chi2(); helixchi2_build_cFR_ = buildextra.helixChi2(); - + // duplicate info duplmask_build_cFR_ = buildextra.isDuplicate(); iTkMatches_build_cFR_ = buildextra.duplicateID(); + //dphi + dphi_build_cFR_ = buildextra.dPhi(); + // cmssw match? cmsswID_build_cFR_ = buildextra.cmsswTrackID(); if (cmsswID_build_cFR_ >= 0) // matched track to cmssw @@ -1692,15 +1717,17 @@ void TTreeValidation::fillCMSSWFakeRateTree(const Event& ev) { if (Config::inclusiveShorts) { - if (cmsswID_build_cFR_ == -1 || cmsswID_build_cFR_ == -3) cmsswmask_build_cFR_ = 0; - else if (cmsswID_build_cFR_ == -2 || cmsswID_build_cFR_ == -6 || cmsswID_build_cFR_ == -7) cmsswmask_build_cFR_ = 2; + if (cmsswID_build_cFR_ == -1 || cmsswID_build_cFR_ == -3) cmsswmask_build_cFR_ = 0; + else if (cmsswID_build_cFR_ == -2 || cmsswID_build_cFR_ == -4 || + cmsswID_build_cFR_ == -6 || cmsswID_build_cFR_ == -7 || + cmsswID_build_cFR_ == -8) cmsswmask_build_cFR_ = 2; else std::cerr << "Somehow got a bad cmsswID: " << cmsswID_build_cFR_ << " trackID: " << mcTrackID_build_cFR_ << std::endl; } else { if (cmsswID_build_cFR_ == -1) cmsswmask_build_cFR_ = 0; else if (cmsswID_build_cFR_ == -6) cmsswmask_build_cFR_ = 2; - else cmsswmask_build_cFR_ = -1; // cmsswID == -2,-3,-7 + else cmsswmask_build_cFR_ = -1; // cmsswID == -2,-3,-4,-7,-8 } } @@ -1722,9 +1749,6 @@ void TTreeValidation::fillCMSSWFakeRateTree(const Event& ev) nHits_cmssw_cFR_ = cmsswtrack.nFoundHits(); nLayers_cmssw_cFR_ = cmsswtrack.nUniqueLayers(); lastlyr_cmssw_cFR_ = cmsswtrack.getLastFoundHitLyr(); - - // swim phi - phi_cmssw_build_cFR_ = squashPhiGeneral(cmsswtrack.swimPhiToR(buildtrack.x(),buildtrack.y())); } else // unmatched cmsswtracks ... put -99 for all reco values to denote unmatched { @@ -1741,8 +1765,6 @@ void TTreeValidation::fillCMSSWFakeRateTree(const Event& ev) nHits_cmssw_cFR_ = -99; nLayers_cmssw_cFR_ = -99; lastlyr_cmssw_cFR_ = -99; - - phi_cmssw_build_cFR_ = -99; } cmsswfrtree_->Fill(); } diff --git a/TTreeValidation.h b/TTreeValidation.h index 6d28fb4687f9f..ccfa285890ca3 100644 --- a/TTreeValidation.h +++ b/TTreeValidation.h @@ -80,6 +80,9 @@ class TTreeValidation : public Validation { // Special map for CMSSW tracks to seed track labels --> NOT used for fake rate!! TkIDToTkIDMap seedToCmsswMap_; + // Special map for geting exact CMSSW track that originate build track from seed track through seedIDs + TkIDToTkIDMap buildToCmsswMap_; + // Efficiency Tree TTree* efftree_; int evtID_eff_=0,mcID_eff_=0; @@ -191,7 +194,7 @@ class TTreeValidation : public Validation { // chi2 of tracks + phi swim float hitchi2_build_ceff_=0.,helixchi2_build_ceff_=0.; - float phi_cmssw_build_ceff_=0.; + float dphi_build_ceff_=0.; int duplmask_build_ceff_=0,nTkMatches_build_ceff_=0; @@ -213,6 +216,7 @@ class TTreeValidation : public Validation { // chi2 of tracks float hitchi2_build_cFR_=0.,helixchi2_build_cFR_=0.; + float dphi_build_cFR_=0.; // for duplicate track matches int duplmask_build_cFR_=0,iTkMatches_build_cFR_=0; @@ -221,8 +225,6 @@ class TTreeValidation : public Validation { float pt_cmssw_cFR_=0.,phi_cmssw_cFR_=0.,eta_cmssw_cFR_=0.; int nHits_cmssw_cFR_=0,nLayers_cmssw_cFR_=0,lastlyr_cmssw_cFR_=0; - float phi_cmssw_build_cFR_=0.; - // Fit tree (for fine tuning z-phi windows and such --> MPlex Only TTree* fittree_; int ntotallayers_fit_=0,tkid_fit_=0,evtid_fit_=0; diff --git a/Track.cc b/Track.cc index 6585be34ed610..7c1dccc3843b5 100644 --- a/Track.cc +++ b/Track.cc @@ -237,11 +237,23 @@ inline bool sortIDsByChi2(const idchi2Pair & cand1, const idchi2Pair & cand2) return cand1.second& layerHits, const TrackVec& cmsswtracks, const RedTrackVec& redcmsswtracks) { const SVector6 & trkParams = trk.parameters(); const SMatrixSym66 & trkErrs = trk.errors(); + const int bin = getMatchBin(trk.pT()); + // temps needed for chi2 SVector2 trkParamsR; trkParamsR[0] = trkParams[3]; @@ -257,7 +269,7 @@ void TrackExtra::setCMSSWTrackIDInfo(const Track& trk, const std::vector for (auto&& redcmsswtrack : redcmsswtracks) { const float chi2 = std::abs(computeHelixChi2(redcmsswtrack.parameters(),trkParamsR,trkErrsR,false)); - if (chi2 < Config::minCMSSWMatchChi2) cands.push_back(std::make_pair(redcmsswtrack.label(),chi2)); + if (chi2 < Config::minCMSSWMatchChi2[bin]) cands.push_back(std::make_pair(redcmsswtrack.label(),chi2)); } float minchi2 = -1e6; @@ -269,7 +281,7 @@ void TrackExtra::setCMSSWTrackIDInfo(const Track& trk, const std::vector int cmsswTrackID = -1; int nHMatched = 0; - float bestdPhi = Config::minCMSSWMatchdPhi; + float bestdPhi = Config::minCMSSWMatchdPhi[bin]; float bestchi2 = minchi2; for (auto&& cand : cands) // loop over possible cmssw tracks { @@ -299,6 +311,7 @@ void TrackExtra::setCMSSWTrackIDInfo(const Track& trk, const std::vector // set cmsswTrackID cmsswTrackID_ = cmsswTrackID; helixChi2_ = bestchi2; + dPhi_ = bestdPhi; // Modify cmsswTrackID based on length if (trk.nFoundHits() < Config::nMinFoundHits) @@ -322,6 +335,84 @@ void TrackExtra::setCMSSWTrackIDInfo(const Track& trk, const std::vector fracHitsMatched_ = float(nHitsMatched_) / float(trk.nFoundHits()); // seed hits may already be included! } +void TrackExtra::setCMSSWTrackIDInfoByLabel(const Track& trk, const std::vector& layerHits, const Track& cmsswtrack, const ReducedTrack& redcmsswtrack) +{ + const SVector6 & trkParams = trk.parameters(); + const SMatrixSym66 & trkErrs = trk.errors(); + + // temps needed for chi2 + SVector2 trkParamsR; + trkParamsR[0] = trkParams[3]; + trkParamsR[1] = trkParams[5]; + + SMatrixSym22 trkErrsR; + trkErrsR[0][0] = trkErrs[3][3]; + trkErrsR[1][1] = trkErrs[5][5]; + trkErrsR[0][1] = trkErrs[3][5]; + trkErrsR[1][0] = trkErrs[5][3]; + + helixChi2_ = std::abs(computeHelixChi2(redcmsswtrack.parameters(),trkParamsR,trkErrsR,false)); + dPhi_ = std::abs(squashPhiGeneral(cmsswtrack.swimPhiToR(trk.x(),trk.y())-trk.momPhi())); + + const HitLayerMap & hitLayerMap = redcmsswtrack.hitLayerMap(); + nHitsMatched_ = 0; + for (int ihit = Config::nlayers_per_seed; ihit < trk.nTotalHits(); ihit++) // loop over mkfit track hits + { + const int lyr = trk.getHitLyr(ihit); + const int idx = trk.getHitIdx(ihit); + + if (idx < 0 || !hitLayerMap.count(lyr)) continue; // skip if bad index or cmssw track does not have that layer + for (auto cidx : hitLayerMap.at(lyr)) // loop over hits in layer for the cmssw track + { + if (cidx == idx) {nHitsMatched_++; break;} + } + } + + // get eligible hits + const int nCandHits = trk.nFoundHits()-Config::nlayers_per_seed; + + // protect against tracks that never make it past the seed + if (nCandHits != 0) + { + // Require majority of hits to match + if (2*nHitsMatched_ >= nCandHits) cmsswTrackID_ = cmsswtrack.label(); + else cmsswTrackID_ = -1; + + // Modify mcTrackID based on nMinHits + if (nCandHits < (Config::nMinFoundHits-Config::nlayers_per_seed)) + { + if (cmsswTrackID_ >= 0) cmsswTrackID_ = -2; + else cmsswTrackID_ = -3; + } + + // Modify cmsswTrackID based on if cmsswtrack is findable + if (cmsswTrackID_ >= 0) + { + if (cmsswtrack.isNotFindable()) + { + if (cmsswTrackID_ >= 0) cmsswTrackID_ = -6; + else cmsswTrackID_ = -7; + } + } + + fracHitsMatched_ = float(nHitsMatched_) / float(nCandHits); + } + else + { + if (cmsswtrack.isNotFindable()) + { + cmsswTrackID_ = -8; + } + else + { + cmsswTrackID_ = -4; + } + + fracHitsMatched_ = 0.f; + } +} + + //============================================================================== void print(const TrackState& s) diff --git a/Track.h b/Track.h index 110d2ccbf2b5e..99b723944fa3a 100644 --- a/Track.h +++ b/Track.h @@ -26,16 +26,18 @@ struct ReducedTrack // used for cmssw reco track validation { public: ReducedTrack() {} - ReducedTrack(const int label, const SVector2 & params, const float phi, const HitLayerMap & hitmap) : - label_(label), parameters_(params), phi_(phi), hitLayerMap_(hitmap) {} + ReducedTrack(const int label, const int seedID, const SVector2 & params, const float phi, const HitLayerMap & hitmap) : + label_(label), seedID_(seedID), parameters_(params), phi_(phi), hitLayerMap_(hitmap) {} ~ReducedTrack() {} int label() const {return label_;} + int seedID() const {return seedID_;} const SVector2& parameters() const {return parameters_;} float momPhi() const {return phi_;} const HitLayerMap& hitLayerMap() const {return hitLayerMap_;} int label_; + int seedID_; SVector2 parameters_; float phi_; HitLayerMap hitLayerMap_; @@ -470,6 +472,7 @@ class TrackExtra void setMCTrackIDInfoByLabel(const Track& trk, const std::vector& layerHits, const MCHitInfoVec& globalHitInfo); void setMCTrackIDInfo(const Track& trk, const std::vector& layerHits, const MCHitInfoVec& globalHitInfo, const TrackVec& simtracks, const bool isSeed); void setCMSSWTrackIDInfo(const Track& trk, const std::vector& layerHits, const TrackVec& cmsswtracks, const RedTrackVec& redcmsswtracks); + void setCMSSWTrackIDInfoByLabel(const Track& trk, const std::vector& layerHits, const Track& cmsswtrack, const ReducedTrack& redcmsswtrack); int mcTrackID() const {return mcTrackID_;} int nHitsMatched() const {return nHitsMatched_;} @@ -480,6 +483,7 @@ class TrackExtra void setDuplicateInfo(int duplicateID, bool isDuplicate) {duplicateID_ = duplicateID; isDuplicate_ = isDuplicate;} int cmsswTrackID() const {return cmsswTrackID_;} float helixChi2() const {return helixChi2_;} + float dPhi() const {return dPhi_;} void setmcTrackID(int mcTrackID) {mcTrackID_ = mcTrackID;} void setseedID(int seedID) {seedID_ = seedID;} @@ -495,6 +499,7 @@ class TrackExtra bool isDuplicate_; int cmsswTrackID_; float helixChi2_; + float dPhi_; }; typedef std::vector TrackExtraVec; diff --git a/validation-desc.txt b/validation-desc.txt index 8ae1ab85160af..84b7b9e2dab57 100644 --- a/validation-desc.txt +++ b/validation-desc.txt @@ -94,8 +94,9 @@ The following routines are then called after the building (MkBuilder.cc, Event.c : m_event->validation_.alignTracks(tracks,extras,false) : m_event->Validate() : validation_.setTrackExtras(*this) - : extra.setCMSSWTrackInfo() // Chi2 and dphi matching (also incudes option for nHits matching) : storeSeedAndMCID() + : if (clean-seeds) extra.setCMSSWTrackIDInfo() // Chi2 and dphi matching (also incudes option for nHits matching) + : else extra.setCMSSWTrackIDInfoByLabel() // 50% hit sharing after seed : validation_.makeCMSSWTkToRecoTksMaps(*this) : mapRefTkToRecoTks(buildtracks,buildextras,cmsswToBuildMap) : validation_.fillCMSSWEfficiencyTree(*this) @@ -200,6 +201,16 @@ The following routines are then called after the building (MkBuilder.cc, Event.c : if no label is found, cmsswTrackID == -1 : follow same logic for labeling as setMCTrackIDInfo for -2, -3, -6, -7 +- setCMSSWTrackIDInfoByLabel() + : want to match the hits on the reco track to those on the CMSSW track + : loop over hits on reco track after seed + : get hit idx and lyr + : if the cmssw track has this lyr, loop over hit indices on cmssw track with this layer + : if cmssw hit idx matches reco idx, increment nHitsMatched_ + : follow same logic as setMCTrackIDInfoLabel() for setting cmsswTrackID + : follow same logic for labeling as setCMSSWTrackIDInfo() for -6, -7 + : if ID == -4 && cmssw track is not findable, ID == -8 + - mapRefTkToRecoTks(tracks,extras,map) : Loop over reco tracks : get track extra for track @@ -330,11 +341,11 @@ Fake Rate (with only long reco tracks: Config::inclusiveShorts == false) [PlotVa Fake Rate (with all reco tracks: Config::inclusiveShorts == true, enabled with command line option: --inc-shorts) [PlotValidation::PlotFakeRate()] numerator: reco tracks with mcTrackID == -1 || == -3 - denominator: reco tracks with mcTrackID >= 0 || == -1 || == -2 || == -3 || == -4 || == -6 || == -7 - mcTrackID | mcmask_[reco] - >= 0 | 1 - -1 or -3 | 0 - -2 or -4 or -6 or -7 | 2 + denominator: reco tracks with mcTrackID >= 0 || == -1 || == -2 || == -3 || == -4 || == -6 || == -7 || == -8 + mcTrackID | mcmask_[reco] + >= 0 | 1 + -1 or -3 | 0 + -2 or -4 or -6 or -7 or -8 | 2 Duplicate Rate [PlotValidation::PlotDuplicateRate()], see special note in section H numerator: sim tracks with more than reco track match (nTkMatches_[reco] > 1) @@ -425,14 +436,43 @@ N.B.2 Since we inflate LOH by 2% more than GLH, hit indices in building only go *** Originally from Track.cc *** mcTrackID assignments -ID >= 0 : reco track matched to sim track (n eligible found reco hits matching single sim track above some threshold, and n eligible found reco hits above some threshold) -ID == -1 : reco track is a true fake (n eligible found reco hits matching single sim track below some threshold, and n eligible found reco hits above some threshold) -ID == -2 : reco track is a matched short track --> inefficient but not fake (n eligible found reco hits matching single sim track above some threshold, and n eligible found reco hits below some threshold) -ID == -3 : reco track is a short fake (n eligible found reco hits matching single sim track below some threshold, and n eligible found reco hits below some threshold) --> TOYMC SIM SEEDS ONLY -ID == -4 : reco track never made it past its sim seed --> inefficient but not fake --> TOYMC SIM SEEDS ONLY -ID == -5 : reco track somehow has zero hits... unclear what to do with these... ---> CMSSW OR REAL SEEDS ONLY -ID == -6 : reco track is long, and matched to sim track. however, simtrack is unfindable (enter denom of FR) -ID == -7 : reco track is short, and matched to sim track. however, simtrack is unfindable (enter denom of FR for inclusive shorts) +ID >= 0 : reco track matched to a findable sim/cmssw track, the ID being the label of the sim/cmssw track + A0. fraction of n eligible found reco hits matching single sim/cmssw track above some threshold (byLabel matching is 50% of hits after seed, else 75% of all hits) + B0. reco track is long enough given n eligible found reco hits above some threshold [Config::nMinHits == 8, which includes seed] + C0. sim/cmssw track is findable: pT of track above some value [Config::cmsSelMinPt], and has enough unique layers [Config::cmsSelMinLayers == 8] + +ID == -1 : reco track is a true fake, enter numer and denom of FR + A1. failed hit sharing threshold as described in A0 + B1. passed track length threshold as described in B0 + +ID == -2 : reco track is a matched short track: inefficient but not fake, thus only entering denom of FR + A2. passed hit sharing threshold as described in A0 + B2. failed track length threshold as described in B0 + C2. reference track is findable as described in C0 + +ID == -3 : reco track is a short fake, and will enter numer and denom of FR only when using --inclusive-shorts + A3. failed hit sharing threshold as described in A0 + B3. failed track length threshold as described in B0 + +ID == -4 : reco track never made it past its sim seed, inefficient but not fake (used in byLabel matching only), entering only denom of FR when using --inclusive-shorts + A4. by default, since no new hits were added, failed hit sharing threshold as described in A0 + B4. failed track length threshold as described in B0 + C4. sim/cmssw track is findable: when using sim seeds, sim tracks that are not findable are already excluded from efficiency denom and do not form seeds + +ID == -5 : reco track somehow has zero hits... which should never happen... unclear what to do with these... currently excluded from all calculations + +ID == -6 : reco track is long and matched to sim track. however, simtrack is unfindable, thus the reco track enters denom of FR, while sim track excluded from denom+numer of eff + A6. passed hit sharing threshold as described in A0 + B6. passed track length threshold as described in B0 + C6. reference track is not findable, failing thresholds as described in C0 + +ID == -7 : reco track is short, and matched to sim track. however, simtrack is unfindable, thus the reco track enters denom of FR when using --inclusive-shorts, while sim track excluded from denom+numer of eff + A7. passed hit sharing threshold as described in A0 + B7. failed track length threshold as described in B0 + C7. reference track is not findable, failing thresholds as described in C0 + +ID == -8 : same as ID == -4, except the reference track was never findable + C8. sim/cmssw track is NOT findable: can only happen in CMSSW external tracks used as reference N.B. CMSSW TrackID uses same assignments! @@ -495,11 +535,12 @@ We can revert back to the n-1 filling for the numerator to weight by the amount The label currently has multiple meanings depending on the type of track and where it is in the pipeline between seeding, building, and validation. To begin, allow me to map out the differences in inputs for the various validation sequences, and the associated track associator function: -1. ToyMC Geom + sim seeds: setMCTrackIDInfoByLabel() +1. ToyMC Geom + sim seeds: setMCTrackIDInfoByLabel() 2. CMSSW Geom + sim seeds (--geom CMS-2017): setMCTrackIDInfoByLabel() 3. ToyMC Geom + found seeds (--find-seeds): setMCTrackIDInfo() 4. CMSSW Geom + cmssw seeds (--geom CMS-2017 --cmssw-seeds --clean-seeds): setMCTrackIDInfo() -5. CMSSW Geom + cmssw seeds + external CMSSW tracks as reference (--geom CMS-2017 --cmssw-seeds --clean-seeds: setCMSSWTrackIDInfo() +5. CMSSW Geom + cmssw seeds + external CMSSW tracks as reference + N^2 cleaning (--geom CMS-2017 --cmssw-seeds --clean-seeds): setCMSSWTrackIDInfo() +5. CMSSW Geom + cmssw seeds + external CMSSW tracks as reference (--geom CMS-2017 --cmssw-seeds): setCMSSWTrackIDInfoByLabel() ## Important note about hits and relation to the label: As a reminder, all hits that originate from a simulated particle will have a **mcHitID_** >= 0. This is the index to the vector of simHitInfo_, where each element of the vector contains additional information about the hit. Most importantly, it stores the **mcTrackID_** that the hit originated from. @@ -552,3 +593,7 @@ The candidate track to CMSSW associator is run, matching by chi2 and dphi. If t cmsswToCandidates: - map key = **cmsswTrackID** (which is now the position of a cmssw track in extRecTracks_) - mapped value = vector of candidate track **label_'s**, where the **label_'s** now represent the **positions** in the candidate vector for tracks who have the **cmsswTrackID_** in question + +## Case 6.: setCMSSWTrackIDInfoByLabel() + +The meaning of the label here is still the same case 5. Now, of course, we have a "pure" efficiency denominator made of all the CMSSW reco tracks that are findable. From 66b8a89dc3dc23e80ccb05b3951290f796479b8f Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Tue, 22 Aug 2017 06:24:05 -0700 Subject: [PATCH 150/172] relabel seeds with label == -1 for pure cmssw tracks --- Event.cc | 17 ++++++++++++----- Event.h | 1 + 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Event.cc b/Event.cc index b3492aec77939..653e0cbb233ea 100644 --- a/Event.cc +++ b/Event.cc @@ -771,11 +771,7 @@ int Event::clean_cms_seedtracks() seedTracks_.swap(cleanSeedTracks); - if (Config::root_val || Config::cmssw_val) - { - int newlabel = 0; - for (auto&& track : seedTracks_) if (track.label() < 0) track.setLabel(--newlabel); - } + if (Config::root_val || Config::cmssw_val) relabel_bad_seedtracks(); return seedTracks_.size(); } @@ -803,9 +799,20 @@ int Event::use_seeds_from_cmsswtracks() seedTracks_.swap(cleanSeedTracks); + if (Config::root_val || Config::cmssw_val) relabel_bad_seedtracks(); + return seedTracks_.size(); } +void Event::relabel_bad_seedtracks() +{ + int newlabel = 0; + for (auto&& track : seedTracks_) + { + if (track.label() < 0) track.setLabel(--newlabel); + } +} + //============================================================================== // DataFile //============================================================================== diff --git a/Event.h b/Event.h index 31b706def1b62..1a1a46fdbe0a8 100644 --- a/Event.h +++ b/Event.h @@ -39,6 +39,7 @@ class Event int clean_cms_simtracks(); int clean_cms_seedtracks(); //operates on seedTracks_; returns the number of cleaned seeds int clean_cms_seedtracks_badlabel(); //operates on seedTracks_, removes those with label == -1; + void relabel_bad_seedtracks(); void print_tracks(const TrackVec& tracks, bool print_hits) const; const Geometry& geom_; From 71ff33f5d8e645a535fabf8d1994e8d1a559d779 Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Wed, 23 Aug 2017 03:24:03 -0700 Subject: [PATCH 151/172] refactor modifying mc/cmsswTrackID, require relabeling before making cmssw to seed map --- Event.cc | 6 +- TTreeValidation.cc | 231 +++++++++++++++++++++++++++++++------------- Track.cc | 154 ++++++++++++++--------------- Track.h | 5 +- mkFit/MkBuilder.cc | 4 +- validation-desc.txt | 172 ++++++++++++++++++--------------- 6 files changed, 339 insertions(+), 233 deletions(-) diff --git a/Event.cc b/Event.cc index 653e0cbb233ea..e3e99e2aeb0de 100644 --- a/Event.cc +++ b/Event.cc @@ -357,7 +357,7 @@ void Event::PrintStats(const TrackVec& trks, TrackExtraVec& trkextras) for (auto&& trk : trks) { auto&& extra = trkextras[trk.label()]; - extra.setMCTrackIDInfoByLabel(trk, layerHits_, simHitsInfo_); + extra.setMCTrackIDInfoByLabel(trk, layerHits_, simHitsInfo_, simTracks_); if (extra.mcTrackID() < 0) { ++miss; } else { @@ -771,8 +771,6 @@ int Event::clean_cms_seedtracks() seedTracks_.swap(cleanSeedTracks); - if (Config::root_val || Config::cmssw_val) relabel_bad_seedtracks(); - return seedTracks_.size(); } @@ -799,8 +797,6 @@ int Event::use_seeds_from_cmsswtracks() seedTracks_.swap(cleanSeedTracks); - if (Config::root_val || Config::cmssw_val) relabel_bad_seedtracks(); - return seedTracks_.size(); } diff --git a/TTreeValidation.cc b/TTreeValidation.cc index ab16ad081c5c7..04e2bc7bdb708 100644 --- a/TTreeValidation.cc +++ b/TTreeValidation.cc @@ -505,32 +505,42 @@ void TTreeValidation::setTrackExtras(Event& ev) { std::lock_guard locker(glock_); + const auto& layerhits = ev.layerHits_; + if (Config::root_val) { + const auto& simhits = ev.simHitsInfo_; + const auto& simtracks = ev.simTracks_; + const auto& seedtracks = ev.seedTracks_; + auto& seedextras = ev.seedTracksExtra_; + const auto& buildtracks = ev.candidateTracks_; + auto& buildextras = ev.candidateTracksExtra_; + const auto& fittracks = ev.fitTracks_; + auto& fitextras = ev.fitTracksExtra_; // set mcTrackID for seed tracks - for (int itrack = 0; itrack < ev.seedTracks_.size(); itrack++) + for (int itrack = 0; itrack < seedtracks.size(); itrack++) { - auto&& track(ev.seedTracks_[itrack]); - auto&& extra(ev.seedTracksExtra_[itrack]); - extra.setMCTrackIDInfo(track, ev.layerHits_, ev.simHitsInfo_, ev.simTracks_, true); // otherwise seeds are completely unmatched in ToyMC Sim Seeds + const auto& track = seedtracks[itrack]; + auto& extra = seedextras[itrack]; + extra.setMCTrackIDInfo(track, layerhits, simhits, simtracks, true); // otherwise seeds are completely unmatched in ToyMC Sim Seeds } // set mcTrackID for built tracks - for (int itrack = 0; itrack < ev.candidateTracks_.size(); itrack++) + for (int itrack = 0; itrack < buildtracks.size(); itrack++) { - auto&& track(ev.candidateTracks_[itrack]); - auto&& extra(ev.candidateTracksExtra_[itrack]); - if (Config::readCmsswSeeds || Config::findSeeds) {extra.setMCTrackIDInfo(track, ev.layerHits_, ev.simHitsInfo_, ev.simTracks_, false);} - else {extra.setMCTrackIDInfoByLabel(track, ev.layerHits_, ev.simHitsInfo_);} + const auto& track = buildtracks[itrack]; + auto& extra = buildextras[itrack]; + if (Config::readCmsswSeeds || Config::findSeeds) {extra.setMCTrackIDInfo(track, layerhits, simhits, simtracks, false);} + else {extra.setMCTrackIDInfoByLabel(track, layerhits, simhits, simtracks);} } // set mcTrackID for fit tracks - for (int itrack = 0; itrack < ev.fitTracks_.size(); itrack++) + for (int itrack = 0; itrack < fittracks.size(); itrack++) { - auto&& track(ev.fitTracks_[itrack]); - auto&& extra(ev.fitTracksExtra_[itrack]); - if (Config::readCmsswSeeds || Config::findSeeds) {extra.setMCTrackIDInfo(track, ev.layerHits_, ev.simHitsInfo_, ev.simTracks_, false);} - else {extra.setMCTrackIDInfoByLabel(track, ev.layerHits_, ev.simHitsInfo_);} + const auto& track = fittracks[itrack]; + auto& extra = fitextras[itrack]; + if (Config::readCmsswSeeds || Config::findSeeds) {extra.setMCTrackIDInfo(track, layerhits, simhits, simtracks, false);} + else {extra.setMCTrackIDInfoByLabel(track, layerhits, simhits, simtracks);} } } @@ -539,11 +549,16 @@ void TTreeValidation::setTrackExtras(Event& ev) // store mcTrackID and seedID correctly storeSeedAndMCID(ev); - RedTrackVec reducedCMSSW(ev.extRecTracks_.size()); // use 2D chi2 for now, so might as well make use of this object for now - for (int itrack = 0; itrack < ev.extRecTracks_.size(); itrack++) + const auto& cmsswtracks = ev.extRecTracks_; + auto& cmsswextras = ev.extRecTracksExtra_; + const auto& buildtracks = ev.candidateTracks_; + auto& buildextras = ev.candidateTracksExtra_; + + RedTrackVec reducedCMSSW(cmsswtracks.size()); // use 2D chi2 for now, so might as well make use of this object for now + for (int itrack = 0; itrack < cmsswtracks.size(); itrack++) { - const auto & cmsswtrack = ev.extRecTracks_[itrack]; - const auto & cmsswextra = ev.extRecTracksExtra_[itrack]; + const auto & cmsswtrack = cmsswtracks[itrack]; + const int seedID = cmsswextras[itrack].seedID(); const SVector6 & params = cmsswtrack.parameters(); SVector2 tmpv(params[3],params[5]); @@ -553,26 +568,28 @@ void TTreeValidation::setTrackExtras(Event& ev) const int lyr = cmsswtrack.getHitLyr(ihit); const int idx = cmsswtrack.getHitIdx(ihit); - if (idx >= 0) tmpmap[lyr].push_back(idx); + if (idx >= 0) + { + tmpmap[lyr].push_back(idx); + } } // index inside object is label (as cmsswtracks are now aligned) - reducedCMSSW[itrack] = ReducedTrack(cmsswtrack.label(),cmsswextra.seedID(),tmpv,cmsswtrack.momPhi(),tmpmap); + reducedCMSSW[itrack] = ReducedTrack(cmsswtrack.label(),seedID,tmpv,cmsswtrack.momPhi(),tmpmap); } // set cmsswTrackID for built tracks - for (int itrack = 0; itrack < ev.candidateTracks_.size(); itrack++) + for (int itrack = 0; itrack < buildtracks.size(); itrack++) { - auto&& track(ev.candidateTracks_[itrack]); - auto&& extra(ev.candidateTracksExtra_[itrack]); + const auto& track = buildtracks[itrack]; + auto& extra = buildextras[itrack]; if (Config::cleanCmsswSeeds) { - extra.setCMSSWTrackIDInfo(track, ev.layerHits_, ev.extRecTracks_, reducedCMSSW); + extra.setCMSSWTrackIDInfo(track, layerhits, cmsswtracks, reducedCMSSW); } else { - auto&& cmsswtrack(ev.extRecTracks_[buildToCmsswMap_[track.label()]]); - extra.setCMSSWTrackIDInfoByLabel(track, ev.layerHits_, cmsswtrack, reducedCMSSW[cmsswtrack.label()]); + extra.setCMSSWTrackIDInfoByLabel(track, layerhits, cmsswtracks, reducedCMSSW[cmsswtracks[buildToCmsswMap_[track.label()]].label()]); } } } @@ -686,12 +703,14 @@ void TTreeValidation::storeSeedAndMCID(Event& ev) const auto& cmsswtracks = ev.extRecTracks_; auto& cmsswextras = ev.extRecTracksExtra_; + int newlabel = -1; for (int itrack = 0; itrack < buildtracks.size(); itrack++) { auto& extra = buildextras[itrack]; const int seedID = extra.seedID(); extra.setmcTrackID(seedID); + if (seedToCmsswMap_.count(seedID)) { extra.setseedID(seedToCmsswMap_[seedID]); @@ -706,7 +725,7 @@ void TTreeValidation::storeSeedAndMCID(Event& ev) } else { - extra.setseedID(-1); + extra.setseedID(--newlabel); } } } @@ -1166,18 +1185,37 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) { if (Config::inclusiveShorts) { - if (mcID_seed_FR_ == -1 || mcID_seed_FR_ == -3) mcmask_seed_FR_ = 0; - else if (mcID_seed_FR_ == -2 || mcID_seed_FR_ == -4 || - mcID_seed_FR_ == -6 || mcID_seed_FR_ == -7) mcmask_seed_FR_ = 2; - else mcmask_seed_FR_ = -1; // mcID == -5 + if (mcID_seed_FR_ == -1 || mcID_seed_FR_ == -5 || mcID_seed_FR_ == -6 || + mcID_seed_FR_ == -7 || mcID_seed_FR_ == -8 || mcID_seed_FR_ == -9) + { + mcmask_seed_FR_ = 0; + } + else if (mcID_seed_FR_ == -2 || mcID_seed_FR_ == -3 || mcID_seed_FR_ == -4 || + mcID_seed_FR_ == -10 || mcID_seed_FR_ == -11 || mcID_seed_FR_ == -12) + { + mcmask_seed_FR_ = 2; + } + else // mcID == -13 + { + mcmask_seed_FR_ = -1; + } } - else + else // only count long tracks { - if (mcID_seed_FR_ == -1) mcmask_seed_FR_ = 0; - else if (mcID_seed_FR_ == -6) mcmask_seed_FR_ = 2; - else mcmask_seed_FR_ = -1; // mcID == -2,-3,-4,-5,-7 + if (mcID_seed_FR_ == -1 || mcID_seed_FR_ == -7 || mcID_seed_FR_ == -9) + { + mcmask_seed_FR_ = 0; + } + else if (mcID_seed_FR_ == -4) + { + mcmask_seed_FR_ = 2; + } + else // mcID == -2,-3,-5,-6,-8,-10,-11,-12,-13 + { + mcmask_seed_FR_ = -1; + } } - } + } // end check over not matched if (mcmask_seed_FR_ == 1) // matched track to sim { @@ -1262,18 +1300,37 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) { if (Config::inclusiveShorts) { - if (mcID_build_FR_ == -1 || mcID_build_FR_ == -3) mcmask_build_FR_ = 0; - else if (mcID_build_FR_ == -2 || mcID_build_FR_ == -4 || - mcID_build_FR_ == -6 || mcID_build_FR_ == -7) mcmask_build_FR_ = 2; - else mcmask_build_FR_ = -1; // mcID == -5 + if (mcID_build_FR_ == -1 || mcID_build_FR_ == -5 || mcID_build_FR_ == -6 || + mcID_build_FR_ == -7 || mcID_build_FR_ == -8 || mcID_build_FR_ == -9) + { + mcmask_build_FR_ = 0; + } + else if (mcID_build_FR_ == -2 || mcID_build_FR_ == -3 || mcID_build_FR_ == -4 || + mcID_build_FR_ == -10 || mcID_build_FR_ == -11 || mcID_build_FR_ == -12) + { + mcmask_build_FR_ = 2; + } + else // mcID == -13 + { + mcmask_build_FR_ = -1; + } } - else + else // only count long tracks { - if (mcID_build_FR_ == -1) mcmask_build_FR_ = 0; - else if (mcID_build_FR_ == -6) mcmask_build_FR_ = 2; - else mcmask_build_FR_ = -1; // mcID == -2,-3,-4,-5,-7 + if (mcID_build_FR_ == -1 || mcID_build_FR_ == -7 || mcID_build_FR_ == -9) + { + mcmask_build_FR_ = 0; + } + else if (mcID_build_FR_ == -4) + { + mcmask_build_FR_ = 2; + } + else // mcID == -2,-3,-5,-6,-8,-10,-11,-12,-13 + { + mcmask_build_FR_ = -1; + } } - } + } // end check over not matched if (mcmask_build_FR_ == 1) // build track matched to seed and sim { @@ -1396,19 +1453,38 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) { if (Config::inclusiveShorts) { - if (mcID_fit_FR_ == -1 || mcID_fit_FR_ == -3) mcmask_fit_FR_ = 0; - else if (mcID_fit_FR_ == -2 || mcID_fit_FR_ == -4 || - mcID_fit_FR_ == -6 || mcID_fit_FR_ == -7) mcmask_fit_FR_ = 2; - else mcmask_fit_FR_ = -1; // mcID == -5 + if (mcID_fit_FR_ == -1 || mcID_fit_FR_ == -5 || mcID_fit_FR_ == -6 || + mcID_fit_FR_ == -7 || mcID_fit_FR_ == -8 || mcID_fit_FR_ == -9) + { + mcmask_fit_FR_ = 0; + } + else if (mcID_fit_FR_ == -2 || mcID_fit_FR_ == -3 || mcID_fit_FR_ == -4 || + mcID_fit_FR_ == -10 || mcID_fit_FR_ == -11 || mcID_fit_FR_ == -12) + { + mcmask_fit_FR_ = 2; + } + else // mcID == -13 + { + mcmask_fit_FR_ = -1; + } } - else + else // only count long tracks { - if (mcID_fit_FR_ == -1) mcmask_fit_FR_ = 0; - else if (mcID_fit_FR_ == -6) mcmask_fit_FR_ = 2; - else mcmask_fit_FR_ = -1; // mcID == -2,-3,-4,-5,-7 + if (mcID_fit_FR_ == -1 || mcID_fit_FR_ == -7 || mcID_fit_FR_ == -9) + { + mcmask_fit_FR_ = 0; + } + else if (mcID_fit_FR_ == -4) + { + mcmask_fit_FR_ = 2; + } + else // mcID == -2,-3,-5,-6,-8,-10,-11,-12,-13 + { + mcmask_fit_FR_ = -1; + } } - } - + } // end check over not matched + if (mcmask_fit_FR_ == 1) // fit track matched to seed and sim { auto& simtrack = evt_sim_tracks[mcID_fit_FR_]; @@ -1704,7 +1780,7 @@ void TTreeValidation::fillCMSSWFakeRateTree(const Event& ev) duplmask_build_cFR_ = buildextra.isDuplicate(); iTkMatches_build_cFR_ = buildextra.duplicateID(); - //dphi + // stored dphi dphi_build_cFR_ = buildextra.dPhi(); // cmssw match? @@ -1717,27 +1793,45 @@ void TTreeValidation::fillCMSSWFakeRateTree(const Event& ev) { if (Config::inclusiveShorts) { - if (cmsswID_build_cFR_ == -1 || cmsswID_build_cFR_ == -3) cmsswmask_build_cFR_ = 0; - else if (cmsswID_build_cFR_ == -2 || cmsswID_build_cFR_ == -4 || - cmsswID_build_cFR_ == -6 || cmsswID_build_cFR_ == -7 || - cmsswID_build_cFR_ == -8) cmsswmask_build_cFR_ = 2; - else std::cerr << "Somehow got a bad cmsswID: " << cmsswID_build_cFR_ << " trackID: " << mcTrackID_build_cFR_ << std::endl; + if (cmsswID_build_cFR_ == -1 || cmsswID_build_cFR_ == -5 || cmsswID_build_cFR_ == -6 || + cmsswID_build_cFR_ == -7 || cmsswID_build_cFR_ == -8 || cmsswID_build_cFR_ == -9) + { + cmsswmask_build_cFR_ = 0; + } + else if (cmsswID_build_cFR_ == -2 || cmsswID_build_cFR_ == -3 || cmsswID_build_cFR_ == -4 || + cmsswID_build_cFR_ == -10 || cmsswID_build_cFR_ == -11 || cmsswID_build_cFR_ == -12) + { + cmsswmask_build_cFR_ = 2; + } + else // mcID == -13 + { + cmsswmask_build_cFR_ = -1; + } } - else + else // only count long tracks { - if (cmsswID_build_cFR_ == -1) cmsswmask_build_cFR_ = 0; - else if (cmsswID_build_cFR_ == -6) cmsswmask_build_cFR_ = 2; - else cmsswmask_build_cFR_ = -1; // cmsswID == -2,-3,-4,-7,-8 + if (cmsswID_build_cFR_ == -1 || cmsswID_build_cFR_ == -7 || cmsswID_build_cFR_ == -9) + { + cmsswmask_build_cFR_ = 0; + } + else if (cmsswID_build_cFR_ == -4) + { + cmsswmask_build_cFR_ = 2; + } + else // mcID == -2,-3,-5,-6,-8,-10,-11,-12,-13 + { + cmsswmask_build_cFR_ = -1; + } } - } + } // end check over not matched if (cmsswmask_build_cFR_ == 1) // matched track to cmssw { const auto& cmsswtrack = evt_cmssw_tracks[cmsswID_build_cFR_]; const auto& cmsswextra = evt_cmssw_extras[cmsswtrack.label()]; + seedID_cmssw_cFR_ = cmsswextra.seedID(); - // PCA parameters x_cmssw_cFR_ = cmsswtrack.x(); y_cmssw_cFR_ = cmsswtrack.y(); z_cmssw_cFR_ = cmsswtrack.z(); @@ -1757,7 +1851,7 @@ void TTreeValidation::fillCMSSWFakeRateTree(const Event& ev) x_cmssw_cFR_ = -2000; y_cmssw_cFR_ = -2000; z_cmssw_cFR_ = -2000; - + pt_cmssw_cFR_ = -99; phi_cmssw_cFR_ = -99; eta_cmssw_cFR_ = -99; @@ -1766,6 +1860,7 @@ void TTreeValidation::fillCMSSWFakeRateTree(const Event& ev) nLayers_cmssw_cFR_ = -99; lastlyr_cmssw_cFR_ = -99; } + cmsswfrtree_->Fill(); } } diff --git a/Track.cc b/Track.cc index 7c1dccc3843b5..f7b0c1acddc47 100644 --- a/Track.cc +++ b/Track.cc @@ -93,8 +93,54 @@ float Track::swimPhiToR(const float x0, const float y0) const // TrackExtra //============================================================================== +int TrackExtra::modifyRefTrackID(const int foundHits, const int minHits, const TrackVec& reftracks, const int trueID, int refTrackID) +{ + // Modify refTrackID based on nMinHits and findability + if (refTrackID >= 0) + { + if (reftracks[refTrackID].isFindable()) + { + if (foundHits < minHits) refTrackID = -2; + } + else // ref track is not findable + { + if (foundHits < minHits) refTrackID = -3; + else refTrackID = -4; + } + } + else if (refTrackID == -1) + { + if (trueID >= 0) + { + if (reftracks[trueID].isFindable()) + { + if (foundHits < minHits) refTrackID = -5; + } + else // sim track is not findable + { + if (foundHits < minHits) refTrackID = -6; + else refTrackID = -7; + } + } + else + { + if (foundHits < minHits) refTrackID = -8; + else refTrackID = -9; + } + } + else if (refTrackID == -10) + { + if (trueID >= 0) + { + if (reftracks[trueID].isFindable()) refTrackID = -11; + else refTrackID = -12; + } + } + return refTrackID; +} + // More stringent requirement for matching --> used only for simtrack pure seeds -void TrackExtra::setMCTrackIDInfoByLabel(const Track& trk, const std::vector& layerHits, const MCHitInfoVec& globalHitInfo) +void TrackExtra::setMCTrackIDInfoByLabel(const Track& trk, const std::vector& layerHits, const MCHitInfoVec& globalHitInfo, const TrackVec& simtracks) { int nHitsMatched = 0; // count hits matched to simtrack after the seed : will need to modify the start of this loop! XXKM4MT @@ -122,23 +168,18 @@ void TrackExtra::setMCTrackIDInfoByLabel(const Track& trk, const std::vector= nCandHits) mcTrackID_ = seedID_; else mcTrackID_ = -1; - // Modify mcTrackID based on nMinHits - if (nCandHits < (Config::nMinFoundHits-Config::nlayers_per_seed)) - { - if (mcTrackID_ >= 0) mcTrackID_ = -2; - else mcTrackID_ = -3; - } - nHitsMatched_ = nHitsMatched; // nHitsMatched + Config::nlayers_per_seed fracHitsMatched_ = float(nHitsMatched_) / float(nCandHits); } else { - mcTrackID_ = -4; + mcTrackID_ = -10; nHitsMatched_ = 0; fracHitsMatched_ = 0.f; } + mcTrackID_ = modifyRefTrackID(nCandHits,Config::nMinFoundHits-Config::nlayers_per_seed,simtracks,seedID_,mcTrackID_); + dprint("Track " << trk.label() << " parent mc track " << seedID_ << " matched id " << mcTrackID_ << " count " << nHitsMatched_ << "/" << nCandHits); } @@ -194,26 +235,8 @@ void TrackExtra::setMCTrackIDInfo(const Track& trk, const std::vector& l if (4*mccount >= 3*trk.nFoundHits()) mcTrackID_ = mcTrackID; else mcTrackID_ = -1; - // Modify mcTrackID based on length of track (excluding seed tracks, of course - if (!isSeed) - { - // Check for length - if (trk.nFoundHits() < Config::nMinFoundHits) - { - if (mcTrackID_ >= 0) mcTrackID_ = -2; - else mcTrackID_ = -3; - } - - // Modify mcTrackID based on if simtrack is findable - if (mcTrackID >= 0) - { - if (simtracks[mcTrackID].isNotFindable()) - { - if (mcTrackID_ >= 0) mcTrackID_ = -6; - else mcTrackID_ = -7; - } - } - } // end check over sedd + // Modify mcTrackID based on length of track (excluding seed tracks, of course) and findability + if (!isSeed) mcTrackID_ = modifyRefTrackID(trk.nFoundHits(),Config::nMinFoundHits,simtracks,-1,mcTrackID_); nHitsMatched_ = mccount; fracHitsMatched_ = float(nHitsMatched_) / float(trk.nFoundHits()); @@ -221,7 +244,7 @@ void TrackExtra::setMCTrackIDInfo(const Track& trk, const std::vector& l else { // zero size tracks --> should never happen... - mcTrackID_ = -5; + mcTrackID_ = -13; nHitsMatched_ = 0; fracHitsMatched_ = 0.f; } @@ -309,36 +332,23 @@ void TrackExtra::setCMSSWTrackIDInfo(const Track& trk, const std::vector } // set cmsswTrackID - cmsswTrackID_ = cmsswTrackID; + cmsswTrackID_ = cmsswTrackID; // defaults to -1! helixChi2_ = bestchi2; dPhi_ = bestdPhi; - // Modify cmsswTrackID based on length - if (trk.nFoundHits() < Config::nMinFoundHits) - { - if (cmsswTrackID_ >= 0) cmsswTrackID_ = -2; - else cmsswTrackID_ = -3; - } - - // Modify cmsswTrackID based on if simtrack is findable - if (cmsswTrackID >= 0) - { - if (cmsswtracks[cmsswTrackID].isNotFindable()) - { - if (cmsswTrackID_ >= 0) cmsswTrackID_ = -6; - else cmsswTrackID_ = -7; - } - } + // Modify cmsswTrackID based on length and findability + cmsswTrackID_ = modifyRefTrackID(trk.nFoundHits(),Config::nMinFoundHits,cmsswtracks,-1,cmsswTrackID_); // other important info nHitsMatched_ = nHMatched; fracHitsMatched_ = float(nHitsMatched_) / float(trk.nFoundHits()); // seed hits may already be included! } -void TrackExtra::setCMSSWTrackIDInfoByLabel(const Track& trk, const std::vector& layerHits, const Track& cmsswtrack, const ReducedTrack& redcmsswtrack) +void TrackExtra::setCMSSWTrackIDInfoByLabel(const Track& trk, const std::vector& layerHits, const TrackVec& cmsswtracks, const ReducedTrack& redcmsswtrack) { const SVector6 & trkParams = trk.parameters(); const SMatrixSym66 & trkErrs = trk.errors(); + const int cmsswlabel = redcmsswtrack.label(); // temps needed for chi2 SVector2 trkParamsR; @@ -352,22 +362,26 @@ void TrackExtra::setCMSSWTrackIDInfoByLabel(const Track& trk, const std::vector< trkErrsR[1][0] = trkErrs[5][3]; helixChi2_ = std::abs(computeHelixChi2(redcmsswtrack.parameters(),trkParamsR,trkErrsR,false)); - dPhi_ = std::abs(squashPhiGeneral(cmsswtrack.swimPhiToR(trk.x(),trk.y())-trk.momPhi())); + dPhi_ = std::abs(squashPhiGeneral(cmsswtracks[cmsswlabel].swimPhiToR(trk.x(),trk.y())-trk.momPhi())); - const HitLayerMap & hitLayerMap = redcmsswtrack.hitLayerMap(); nHitsMatched_ = 0; + const HitLayerMap & hitLayerMap = redcmsswtrack.hitLayerMap(); for (int ihit = Config::nlayers_per_seed; ihit < trk.nTotalHits(); ihit++) // loop over mkfit track hits { const int lyr = trk.getHitLyr(ihit); const int idx = trk.getHitIdx(ihit); - if (idx < 0 || !hitLayerMap.count(lyr)) continue; // skip if bad index or cmssw track does not have that layer - for (auto cidx : hitLayerMap.at(lyr)) // loop over hits in layer for the cmssw track + if (idx < 0) continue; + + if (hitLayerMap.count(lyr)) { - if (cidx == idx) {nHitsMatched_++; break;} + for (auto cidx : hitLayerMap.at(lyr)) // loop over hits in layer for the cmssw track + { + if (cidx == idx) {nHitsMatched_++; break;} + } } } - + // get eligible hits const int nCandHits = trk.nFoundHits()-Config::nlayers_per_seed; @@ -375,41 +389,19 @@ void TrackExtra::setCMSSWTrackIDInfoByLabel(const Track& trk, const std::vector< if (nCandHits != 0) { // Require majority of hits to match - if (2*nHitsMatched_ >= nCandHits) cmsswTrackID_ = cmsswtrack.label(); + if (2*nHitsMatched_ >= nCandHits) cmsswTrackID_ = cmsswlabel; else cmsswTrackID_ = -1; - // Modify mcTrackID based on nMinHits - if (nCandHits < (Config::nMinFoundHits-Config::nlayers_per_seed)) - { - if (cmsswTrackID_ >= 0) cmsswTrackID_ = -2; - else cmsswTrackID_ = -3; - } - - // Modify cmsswTrackID based on if cmsswtrack is findable - if (cmsswTrackID_ >= 0) - { - if (cmsswtrack.isNotFindable()) - { - if (cmsswTrackID_ >= 0) cmsswTrackID_ = -6; - else cmsswTrackID_ = -7; - } - } - fracHitsMatched_ = float(nHitsMatched_) / float(nCandHits); } else { - if (cmsswtrack.isNotFindable()) - { - cmsswTrackID_ = -8; - } - else - { - cmsswTrackID_ = -4; - } - + cmsswTrackID_ = -10; fracHitsMatched_ = 0.f; } + + // Modify cmsswTrackID based on nMinHits + cmsswTrackID_ = modifyRefTrackID(nCandHits,Config::nMinFoundHits-Config::nlayers_per_seed,cmsswtracks,cmsswlabel,cmsswTrackID_); } diff --git a/Track.h b/Track.h index 99b723944fa3a..96fe58628556d 100644 --- a/Track.h +++ b/Track.h @@ -469,10 +469,11 @@ class TrackExtra TrackExtra() : seedID_(std::numeric_limits::max()) {} TrackExtra(int seedID) : seedID_(seedID) {} - void setMCTrackIDInfoByLabel(const Track& trk, const std::vector& layerHits, const MCHitInfoVec& globalHitInfo); + int modifyRefTrackID(const int foundHits, const int minHits, const TrackVec& reftracks, const int trueID, int refTrackID); + void setMCTrackIDInfoByLabel(const Track& trk, const std::vector& layerHits, const MCHitInfoVec& globalHitInfo, const TrackVec& simtracks); void setMCTrackIDInfo(const Track& trk, const std::vector& layerHits, const MCHitInfoVec& globalHitInfo, const TrackVec& simtracks, const bool isSeed); void setCMSSWTrackIDInfo(const Track& trk, const std::vector& layerHits, const TrackVec& cmsswtracks, const RedTrackVec& redcmsswtracks); - void setCMSSWTrackIDInfoByLabel(const Track& trk, const std::vector& layerHits, const Track& cmsswtrack, const ReducedTrack& redcmsswtrack); + void setCMSSWTrackIDInfoByLabel(const Track& trk, const std::vector& layerHits, const TrackVec& cmsswtracks, const ReducedTrack& redcmsswtrack); int mcTrackID() const {return mcTrackID_;} int nHitsMatched() const {return nHitsMatched_;} diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index e9d4ea54ddbf6..b00a0ea512a21 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -801,7 +801,7 @@ void MkBuilder::quality_process(Track &tkcand) } else { - extra.setMCTrackIDInfoByLabel(tkcand, m_event->layerHits_, m_event->simHitsInfo_); + extra.setMCTrackIDInfoByLabel(tkcand, m_event->layerHits_, m_event->simHitsInfo_, m_event->simTracks_); } int mctrk = extra.mcTrackID(); @@ -941,6 +941,8 @@ void MkBuilder::PrepareSeeds() } else { + m_event->relabel_bad_seedtracks(); + if (Config::cmssw_val) { m_event->validation_.makeSeedTkToCMSSWTkMap(*m_event); diff --git a/validation-desc.txt b/validation-desc.txt index 84b7b9e2dab57..e7db6fcaf4ef4 100644 --- a/validation-desc.txt +++ b/validation-desc.txt @@ -42,7 +42,7 @@ The building validation takes advantage of filling two trees per event per track Upon instantiation of the TTreeValidation object, the respective ROOT trees are defined and allocated on the heap, along with setting the addresses of all the branches. After the building is completed in mkFit, we have to have the tracks in their standard event containers, namely: seedTracks_, candidateTracks_, and fitTracks_. In the standard combinatorial or clone engine, we have to copy out the built tracks from event of combined candidates into candidateTracks_ via: builder.quality_store_tracks() in mkFit/buildtestMPlex.cc. Since we do not yet have fitting after building, we just set the fitTracks_ equal to the candidateTracks_. For ease, I will from now on refer to the candidateTracks_ as buildTracks_. -As a reminder, the sim tracks are stored in the Event.cc as simTracks_, while the CMSSW reco tracks are stored as extRecTracks_. Each track collection has an associated TrackExtra collection, which is stored as {trackname}Extra_ inside the Event object. It is indexed the same as the collection it references, i.e. track[0] has an associated extra extra[0]. The TrackExtra object contains the mcTrackID, seedID, and cmsswTrackID each mkFit track is associated to. The validation also makes use of simHitsInfo_ (container for storing mcTrackID for each hit), layerHits_, and simTrackStates_ (used for pulls). See Section B and C for explanations on how the track matching is performed and track information is saved. +As a reminder, the sim tracks are stored in the Event.cc as simTracks_, while the CMSSW reco tracks are stored as extRecTracks_. Each track collection has an associated TrackExtra collection, which is stored as {trackname}Extra_ inside the Event object. It is indexed the same as the collection it references, i.e. track[0] has an associated extra extra[0]. The TrackExtra object contains the mcTrackID, seedID, and cmsswTrackID each mkFit track is associated to. The validation also makes use of simHitsInfo_ (container for storing mcTrackID for each hit), layerHits_, and simTrackStates_ (used for pulls). See Section B and C for explanations on how the track matching is performed and track information is saved. Essentially, we store two sets of maps, one which has a key that is an index to the reference track (MC or CMSSW) and a vector of indices for those that match it (for seeds, build tracks, and fit tracks), and the second map which maps the seed track index to its corresponding build and fit tracks. The reason for having a sim match map for seeds, build tracks, and fit tracks is to keep track of how well the efficiency/fake rate/duplicate improves/degrades with potential cuts between them. And the same reason for having a map of seed to build as well as seed to fit. Following each event, each of the track and extra objects are cleared. In addition, the association maps are cleared and reset. After the main loop over events expires, the ROOT file is written out with the TTrees saved via: val.saveTTrees() in mkFit.cc. The destructor for the validation then deletes the trees. The output is "valtree.root", appended by the thread number if using multiple events in flight. From here, we then take advantage of the following files: @@ -71,7 +71,9 @@ The following routines are then called after the building (MkBuilder.cc, Event.c : m_event->Validate() : validation_.setTrackExtras(*this) : if (sim seeds) extra.setMCTrackIDInfoByLabel() // Require 50% of found hits after seed to match label of seed/sim track - : if (cms seeds) extra.setMCTrackIDInfo() // Require 75% of found hits to match a single sim track + : modifyRecTrackID() + : if (--cmssw-seeds or --find-seeds) extra.setMCTrackIDInfo() // Require 75% of found hits to match a single sim track + : modifyRecTrackID() : validation_.makeSimTkToRecoTksMaps(*this) : mapRefTkToRecoTks(seedtracks,seedextras,simToSeedMap) // map key = mcTrackID, map value = vector of seed labels : mapRefTkToRecoTks(buildtracks,buildextras,simToBuildMap) // map key = mcTrackID, map value = vector of build labels @@ -79,7 +81,7 @@ The following routines are then called after the building (MkBuilder.cc, Event.c : validation_.makeSeedTkToRecoTkMaps(*this) : mapSeedTkToRecoTk(buildtracks,buildextras,seedToBuildMap) // map key = seedID, map value = build track label : mapSeedTkToRecoTk(fittracks,fitextras,seedToFitMap) // map key = seedID, map value = fit track label - : validation_.fillEfficiencyTree(*this) + : validation_.fillEfficiencyTree(*this) : validation_.fillFakeRateTree(*this) [2.] builder.cmssw_val() @@ -95,8 +97,10 @@ The following routines are then called after the building (MkBuilder.cc, Event.c : m_event->Validate() : validation_.setTrackExtras(*this) : storeSeedAndMCID() - : if (clean-seeds) extra.setCMSSWTrackIDInfo() // Chi2 and dphi matching (also incudes option for nHits matching) + : if (--clean-seeds) extra.setCMSSWTrackIDInfo() // Chi2 and dphi matching (also incudes option for nHits matching) + : modifyRecTrackID() : else extra.setCMSSWTrackIDInfoByLabel() // 50% hit sharing after seed + : modifyRecTrackID() : validation_.makeCMSSWTkToRecoTksMaps(*this) : mapRefTkToRecoTks(buildtracks,buildextras,cmsswToBuildMap) : validation_.fillCMSSWEfficiencyTree(*this) @@ -163,30 +167,50 @@ The following routines are then called after the building (MkBuilder.cc, Event.c : setCMSSWTrackIDInfo() : require matching by chi2 and dphi : storeMCandSeedID() +- modifyRecTrackID() + // Config::nMinFoundHits = 7, Config::nlayers_per_seed = 4 or 3 + // nCandHits = trk.nFoundHits() OR trk.nFoundHits()-Config::nlayers_per_seed (see calling function) + // nMinHits = Config::nMinFoundHits OR Config::nMinFoundHits-Config::nlayers_per_seed (see calling function) + : if (mc/cmsswTrackID >= 0) (i.e. the track has successfully matched) + : if mc/cmsswTrack is findable + : if nCandHits < nMinHits, mc/cmsswTrackID = -2 + : else + : if nCandHits < nMinHits, mc/cmsswTrackID = -3 + : else mc/cmsswTrackID = -4 (track is long enough, matched, but that sim track that is unfindable) + : else if (mc/cmsswTrackID == -1) + : if matching by label, and ref track exists + : if ref track is findable + : if nCandHits < minHits, ID = -5 + : else + : if nCandHits < nMinHits, ID = -6 + : else, ID = -7 + : else (not matching by label, or ref track does not exist + : if nCandHits < nMinHits, ID = -8 + : else, ID = -9 + : else if (mc/cmsswTrackID == -10), i.e. track is a pure seed and we are matching using byLabel + : if ref track exists + : if nCandHits < nMinHits, ID = -11 + : else, ID = -12 + -->return potentially new ID assignment + - setMCTrackIDInfoByLabel() - : if no hits are found after seed, mcTrackID == -4, and skip the rest of the function : Loop over found hits on build track after seed : count the hits who have a mcTrackID == seedID_ (i.e. seedID == simTrack label == mcTrackID) - : if 50% are matched, mcTrackID == label - : else, mcTrackID == -1 - : if (track.nFoundHits() < [Config::nMinFoundHits == 7] - [Config::nlayers_per_seed == 4 or 3]) - : if already matched, mcTrackID = -2 - : else, mcTrackID = -3 + : if hits are found after seed + : if 50% are matched, mcTrackID == seedID_ + : else, mcTrackID == -1 + : else + : mcTrackID = -10 + : mcTrackID = modifyRecTrackID() // nCandhits = nFoundHits-nlayers_per_seed, nMinHits = Config::nMinFoundHits - Config::nlayers_per_seed - setMCTrackIDInfo(isSeedTrack) - : if track somehow has zero hits on track, mcTrackID = -5 --> should never happen unless some really deep bug + : if track somehow has zero hits on track, mcTrackID = -13 --> should never happen unless some really deep bug : Loop over all found hits on build track (includes seed hits) : count the mcTrackID that appears most from the hits : if 75% of hits on reco track match a single sim track, mcTrackID == mcTrackID of single sim track : else, mcTrackID == -1 : if (!isSeedTrack) - : if (track.nFoundHits() < [Config::nMinFoundHits == 7]) - : if already matched, mcTrackID = -2 - : else, mcTrackID = -3 - : if already matched - : if simtrack matched to isNotFindable() - : if failed check on length of track (i.e. -2), mcTrackID == -7 - : else, mcTrackID == -6 + : modifyRecTrackID() // nCandHits = nFoundHits, nMinHits = Config::nMinFoundHits - setCMSSWTrackIDInfo() : Loop over all cmssw "reduced" tracks @@ -199,7 +223,7 @@ The following routines are then called after the building (MkBuilder.cc, Event.c : see if dphi < currently best stored mindphi, and if yes, then set this as the new mindphi + label as matched cmsswTrackID : if using nHits matching, check for nHits matched --> currently not used nor tuned : if no label is found, cmsswTrackID == -1 - : follow same logic for labeling as setMCTrackIDInfo for -2, -3, -6, -7 + : modifyRefTrackID() // nCandHits and nMinHits same as setMCTrackIDInfo() - setCMSSWTrackIDInfoByLabel() : want to match the hits on the reco track to those on the CMSSW track @@ -207,9 +231,8 @@ The following routines are then called after the building (MkBuilder.cc, Event.c : get hit idx and lyr : if the cmssw track has this lyr, loop over hit indices on cmssw track with this layer : if cmssw hit idx matches reco idx, increment nHitsMatched_ - : follow same logic as setMCTrackIDInfoLabel() for setting cmsswTrackID - : follow same logic for labeling as setCMSSWTrackIDInfo() for -6, -7 - : if ID == -4 && cmssw track is not findable, ID == -8 + : follow same logic as setMCTrackIDInfoByLabel() for setting cmsswTrackID + : modifyRecTrackID() // nCandHits and nMinHits same as setMCTrackIDInfoByLabel() - mapRefTkToRecoTks(tracks,extras,map) : Loop over reco tracks @@ -285,7 +308,7 @@ The following routines are then called after the building (MkBuilder.cc, Event.c : if last hit found has a valid mcHitID : store sim track state momentum info from simTrackStates[mcHitID] : if seedToFitMap[seedID] has value - : same as aboe + : same as above : fill frtree - fillCMSSWEfficiencyTree() @@ -313,7 +336,7 @@ The following routines are then called after the building (MkBuilder.cc, Event.c D. Definitions of efficiency, fake rate, and duplicate rate ============================================================= -Use rootValidation.C to create efficiency, fake rate, and duplicate rate vs. pT, phi, eta. This macro compiles PlotValidation.cpp/.hh. Efficiency uses sim track momentum info. Fake rate uses the reco track momentum. For [1.], plots are made for seed, build, and fit tracks. For [2.], the plots are only against the build tracks. +Use rootValidation.C to create efficiency, fake rate, and duplicate rate vs. pT, phi, eta. This macro compiles PlotValidation.cpp/.hh. Efficiency uses sim track momentum info. Fake rate uses the reco track momentum. For [1.], plots are made for seed, build, and fit tracks. For [2.], the plots are only against the build tracks. See G. for more details on ID assignments. root -l -b -q runValidation.C\([agruments]\) @@ -331,21 +354,22 @@ Efficiency [PlotValidation::PlotEfficiency()] mcmask_[reco] == - 1 excluded from both numerator and denominator because this sim track was not findable! Fake Rate (with only long reco tracks: Config::inclusiveShorts == false) [PlotValidation::PlotFakeRate()] - numerator: reco tracks with mcTrackID == -1 - denominator: reco tracks with mcTrackID >= 0 || == -1 || == -6 + numerator: reco tracks with mcTrackID == -1 || == -7 || == -9 + denominator: reco tracks with mcTrackID >= 0 || == -4 || == -1 || == -7 || == -9 mcTrackID | mcmask_[reco] >= 0 | 1 - -1 | 0 - -6 | 2 - else | -1 + -1,-7,-9 | 0 + -4 | 2 + else | -1 // OR the seed track does produce a build/fit track as determined by the seedToBuild/FitMap Fake Rate (with all reco tracks: Config::inclusiveShorts == true, enabled with command line option: --inc-shorts) [PlotValidation::PlotFakeRate()] - numerator: reco tracks with mcTrackID == -1 || == -3 - denominator: reco tracks with mcTrackID >= 0 || == -1 || == -2 || == -3 || == -4 || == -6 || == -7 || == -8 - mcTrackID | mcmask_[reco] - >= 0 | 1 - -1 or -3 | 0 - -2 or -4 or -6 or -7 or -8 | 2 + numerator: reco tracks with mcTrackID == -1 || == -5 || == -6 || == -7 || == -8 || == -9 + denominator: reco tracks with mcTrackID >= 0 || == -2 || == -3 || == -4 || == -10 || == -11 || == -12 || == -1 || == -5 || == -6 || == -7 || == -8 || == -9 + mcTrackID | mcmask_[reco] + >= 0 | 1 + -1,-5,-6,-7,-8,-9 | 0 + -2,-3,-4,-10,-11,-12 | 2 + -13 | -1 // OR the seed track does produce a build/fit track as determined by the seedToBuild/FitMap Duplicate Rate [PlotValidation::PlotDuplicateRate()], see special note in section H numerator: sim tracks with more than reco track match (nTkMatches_[reco] > 1) @@ -435,44 +459,40 @@ N.B.2 Since we inflate LOH by 2% more than GLH, hit indices in building only go *** Originally from Track.cc *** +Three basic quantities determine the track ID: + 1. matching criterion (50% after seed for *ByLabel(), 75% for other hit matching, or via chi2+dphi) + 2. nCandidateHits found compared nMinHits + 3. findability of reference track (if applicable) + +Three outcomes exist for each quantity: + 1. matching criterion + a. reco track passed the matching criterion in set*TrackIDInfo*(): M + b. reco track failed the matching criterion in set*TrackIDInfo*(): N + c. reco track never made it past its seed, so matching selection by hit matching via reference track label does not exist in set*TrackIDInfoByLabel(): N/A + 2. nCandHits compared to nMinHits + a. reco track has greater than or equal to the min hits requirement (i.e. is long enough): L + b. reco track has less than the min hits requirement (i.e. short): S + c. reco track is a pure seed, and calling function is set*TrackIDInfoByLabel(): O, by definition then O also equals S + 3. findability of reference track + a. reference track is findable (nUniqueLayers >= 8 && pT > 0.5): isF + b. reference track is NOT findable (nUniqueLayers < 8 || pT < 0.5): unF + c. reference track does not exist in set*TrackIDInfoByLabel(), or we are using set*TrackIDInfo(): ? + mcTrackID assignments -ID >= 0 : reco track matched to a findable sim/cmssw track, the ID being the label of the sim/cmssw track - A0. fraction of n eligible found reco hits matching single sim/cmssw track above some threshold (byLabel matching is 50% of hits after seed, else 75% of all hits) - B0. reco track is long enough given n eligible found reco hits above some threshold [Config::nMinHits == 8, which includes seed] - C0. sim/cmssw track is findable: pT of track above some value [Config::cmsSelMinPt], and has enough unique layers [Config::cmsSelMinLayers == 8] - -ID == -1 : reco track is a true fake, enter numer and denom of FR - A1. failed hit sharing threshold as described in A0 - B1. passed track length threshold as described in B0 - -ID == -2 : reco track is a matched short track: inefficient but not fake, thus only entering denom of FR - A2. passed hit sharing threshold as described in A0 - B2. failed track length threshold as described in B0 - C2. reference track is findable as described in C0 - -ID == -3 : reco track is a short fake, and will enter numer and denom of FR only when using --inclusive-shorts - A3. failed hit sharing threshold as described in A0 - B3. failed track length threshold as described in B0 - -ID == -4 : reco track never made it past its sim seed, inefficient but not fake (used in byLabel matching only), entering only denom of FR when using --inclusive-shorts - A4. by default, since no new hits were added, failed hit sharing threshold as described in A0 - B4. failed track length threshold as described in B0 - C4. sim/cmssw track is findable: when using sim seeds, sim tracks that are not findable are already excluded from efficiency denom and do not form seeds - -ID == -5 : reco track somehow has zero hits... which should never happen... unclear what to do with these... currently excluded from all calculations - -ID == -6 : reco track is long and matched to sim track. however, simtrack is unfindable, thus the reco track enters denom of FR, while sim track excluded from denom+numer of eff - A6. passed hit sharing threshold as described in A0 - B6. passed track length threshold as described in B0 - C6. reference track is not findable, failing thresholds as described in C0 - -ID == -7 : reco track is short, and matched to sim track. however, simtrack is unfindable, thus the reco track enters denom of FR when using --inclusive-shorts, while sim track excluded from denom+numer of eff - A7. passed hit sharing threshold as described in A0 - B7. failed track length threshold as described in B0 - C7. reference track is not findable, failing thresholds as described in C0 - -ID == -8 : same as ID == -4, except the reference track was never findable - C8. sim/cmssw track is NOT findable: can only happen in CMSSW external tracks used as reference +ID >= 0 : a long reco track is matched to a findable sim/cmssw track: M,L,isF +ID == -1 : a long reco track is a true fake, enter numer and denom of FR: N,L,isF +ID == -2 : a short reco track is matched to a findable sim/cmssw track: M,S,isF +ID == -3 : a short reco track is matched to an unfindable sim/cmssw track: M,S,unF +ID == -4 : a long reco track is matched to an unfindable sim/cmssw track: M,L,unF +ID == -5 : a short reco track is unmatched to a findable sim/cmssw track: N,S,isF +ID == -6 : a short reco track is unmatched to an unfindable sim/cmssw track: N,S,unF +ID == -7 : a long reco track is unmatched to an unfindable sim/cmssw track: N,S,unF +ID == -8 : a short reco track is unmatched to a track that may not have a reference or the reference is not give: N,S,? +ID == -9 : a long reco track is unmatched to a track that may not have a reference or the reference is not give: N,L,? +ID == -10 : a pure seed cannot determine its reference track: N/A,O,? +ID == -13 : a pure seed has a findable reference track: N/A,O,isF +ID == -12 : a pure seed has an unfindable reference track: N/A,O,unF +ID == -13 : a zero size track, protection inside setMCTrackIDInfo(). This should never happen... N.B. CMSSW TrackID uses same assignments! @@ -486,7 +506,7 @@ N.B. Mask assignments --> mcmask_[reco] == 1,"associated" reco to sim track [possible duplmask_[reco] == 1,0] {eff and FR}, enter numer and denom of eff, enter denom only of FR --> mcmask_[reco] == 0,"unassociated" reco to sim track. by definition no duplicates (no reco to associate to sim tracks!) [possible duplmask_[reco] == 2 {eff and FR}], enter denom only of eff, enter numer and denom of FR --> mcmask_[reco] == -1, sim or reco track excluded from denominator (and therefore numerator) [possible duplmask_[reco] == -1] {eff and FR} ---> mcmask_[reco] == 2, reco track included in demoninator of FR, but will not enter numerator: for short "matched" tracks of mcTrackID == -2,-4 {FR only} +--> mcmask_[reco] == 2, reco track included in demoninator of FR, but will not enter numerator: for short "matched" tracks {FR only} --> nTkMatches_[reco] > 1, n reco tracks associated to the same sim track ID {eff only} --> nTkMatches_[reco] == 1, 1 reco track associated to single sim track ID {eff only} @@ -568,9 +588,9 @@ These maps are then used to get the associated sim and reco information for the ## Case 3. and 4.: setMCTrackIDInfo() -In both 3. and 4., the seedTracks are not intrinsically related to the simTracks_ . For 3., the seeds are generated from find_seeds(), and the **label_** assigned to the track is just the index at which the seed was created. For 4., the **label_** is the **mcTrackID** for the sim track it is most closely assocaited to, if it exists. +In both 3. and 4., the seedTracks are not intrinsically related to the simTracks_ . For 3., the seeds are generated from find_seeds(), and the **label_** assigned to the track is just the index at which the seed was created. For 4., the **label_** is the **mcTrackID** for the sim track it is most closely assocaited to (as given to us from CMSSW), if it exists. -The CMSSW seeds are read in, and then cleaned. If a surviving seed has a **label_** > 0, the label stays the same, and becomes its **seedID_**. In the case of the N^2 cleaning, some seeds may remain which have a **label_** == -1. Since there might be more than one and we want to uniquely identify them after building, we reassign the **label_'s** with an increasing negative number. So the first seed track with **label_** == -1 has label == -1, the second track with **label_** == -1 then has a new **label_* == -2, third track assigned to == -3, etc. +If using 4., we do relabeling prior to seed cleaning. If **label_** >= 0, the label stays the same, and becomes its **seedID_**. In the case of the N^2 cleaning, some seeds may remain which have a **label_** == -1. Since there might be more than one and we want to uniquely identify them after building, we reassign the **label_'s** with an increasing negative number. So the first seed track with **label_** == -1 has label == -1, the second track with **label_** == -1 then has a new **label_* == -2, third track assigned to == -3, etc. This can also occur in the pure CMSSW seeds (i.e. cmssw seeds that turn into cmssw reco tracks in the extRecTracks_ collection), in which case we do the relabling in the same fashion. The CMSSW seeds are then read in and cleaned. It is clear here that **label_** of the seed track does not have to equal the **position** inside the track vector! So the building proceeds in the same manner as 1. and 2., where each seed first generates a single candidate track with a **label_** equal to the seed **label_** which happens to be its **seedID_**. The candidateTracks_ are dumped out in some order, where the **label_** is still the **seedID_**. @@ -596,4 +616,4 @@ cmsswToCandidates: ## Case 6.: setCMSSWTrackIDInfoByLabel() -The meaning of the label here is still the same case 5. Now, of course, we have a "pure" efficiency denominator made of all the CMSSW reco tracks that are findable. +The meaning of the label here is still the same case 5. Now, of course, we have a "pure" efficiency denominator made of all the CMSSW reco tracks. From c2dd595b620ba7dd4e1f9a249fea7530bfe29852 Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Fri, 25 Aug 2017 08:52:17 -0700 Subject: [PATCH 152/172] drop pt cut on findability and add transition region cut for now --- mkFit/MkBuilder.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index b00a0ea512a21..874586e6e9cfc 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -899,7 +899,9 @@ void MkBuilder::prep_cmsswtracks() for (auto&& cmsswtrack : m_event->extRecTracks_) { const int nlyr = cmsswtrack.nUniqueLayers(); - if (nlyr < Config::cmsSelMinLayers || cmsswtrack.pT() < Config::cmsSelMinPt) cmsswtrack.setNotFindable(); + const int ihit = cmsswtrack.getLastFoundHitPos(); + const float eta = m_event->layerHits_[cmsswtrack.getHitLyr(ihit)][cmsswtrack.getHitIdx(ihit)].eta(); + if (nlyr < Config::cmsSelMinLayers || Config::TrkInfo.is_transition(eta)) cmsswtrack.setNotFindable(); } } From 9750b9eea705c2548b8c8f35b40e39508db886f7 Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Sat, 26 Aug 2017 17:10:41 +0200 Subject: [PATCH 153/172] also drop pt cut on findability of sim tracks, and add transition region eta cut for now --- Event.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Event.cc b/Event.cc index e3e99e2aeb0de..adead5de0e3f4 100644 --- a/Event.cc +++ b/Event.cc @@ -6,6 +6,7 @@ #include "buildtest.h" #include "fittest.h" #include "ConformalUtils.h" +#include "TrackerInfo.h" //#define DEBUG #include "Debug.h" @@ -636,7 +637,10 @@ int Event::clean_cms_simtracks() const int lyr_cnt = t.nUniqueLayers(); - if (lyr_cnt < Config::cmsSelMinLayers || t.pT() < Config::cmsSelMinPt) + const int lasthit = t.getLastFoundHitPos(); + const float eta = layerHits_[t.getHitLyr(lasthit)][t.getHitIdx(lasthit)].eta(); + + if (lyr_cnt < Config::cmsSelMinLayers || Config::TrkInfo.is_transition(eta)) { dprintf("Rejecting simtrack %d, n_hits=%d, n_layers=%d, pT=%f\n", i, nh, lyr_cnt, t.pT()); t.setNotFindable(); From 5bffed1b643dde8ad2a3efdb0011bb474f4032af Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Sat, 26 Aug 2017 21:25:24 +0200 Subject: [PATCH 154/172] techical changes to duplicate mask assignment --- PlotValidation.cpp | 15 ++++++--------- TTreeValidation.cc | 33 ++++++++++++++++++--------------- validation-desc.txt | 30 ++++++++++++++++++------------ 3 files changed, 42 insertions(+), 36 deletions(-) diff --git a/PlotValidation.cpp b/PlotValidation.cpp index 3279a93a193f0..fcf613d204299 100644 --- a/PlotValidation.cpp +++ b/PlotValidation.cpp @@ -387,7 +387,7 @@ void PlotValidation::PlotFakeRate() for (UInt_t p = 0; p < ptcuts.size(); p++) // loop over pt cuts { if (recovars_val[0][j] < ptcuts[p]) continue; // pt cut - if (mcmask_trk[j] != -1) // can include masks of 1,0,2 to enter denominator + if (mcmask_trk[j] >= 0) // can include masks of 1,0,2 to enter denominator { varsFR[i][j][p]->Fill((mcmask_trk[j] == 0),recovars_val[i][j]); // only completely unassociated reco tracks enter FR } // must be a real reco track for FR @@ -469,15 +469,12 @@ void PlotValidation::PlotDuplicateRate() } //Initialize masks, set branch addresses - IntVec mcmask_trk(trks.size()); // need to know if sim track associated to a given reco track type - IntVec nTkMatches_trk(trks.size()); // need to know how many duplicates each mc track produces. nDupl == 1 means one reco track + IntVec duplmask_trk(trks.size()); // need to know if sim track is duplicated for (UInt_t j = 0; j < trks.size(); j++) // loop over trks index { - mcmask_trk[j] = 0; - nTkMatches_trk[j] = 0; + duplmask_trk[j] = 0; - efftree->SetBranchAddress(Form("%smask_%s",(fCmsswComp?"cmssw":"mc"),trks[j].Data()),&(mcmask_trk[j])); - efftree->SetBranchAddress(Form("nTkMatches_%s",trks[j].Data()),&(nTkMatches_trk[j])); + efftree->SetBranchAddress(Form("duplmask_%s",trks[j].Data()),&(duplmask_trk[j])); } // Fill histos, compute DR from tree branches @@ -491,9 +488,9 @@ void PlotValidation::PlotDuplicateRate() for (UInt_t p = 0; p < ptcuts.size(); p++) // loop over pt cuts { if (mcvars_val[0] < ptcuts[p]) continue; - if (mcmask_trk[j] == 1) // need to be matched at least once + if (duplmask_trk[j] != -1) // need sim track to be matched at least once { - varsDR[i][j][p]->Fill(nTkMatches_trk[j]>1,mcvars_val[i]); + varsDR[i][j][p]->Fill((duplmask_trk[j]==1),mcvars_val[i]); } } // must be a matched track for proper denom } // end loop over trks diff --git a/TTreeValidation.cc b/TTreeValidation.cc index 04e2bc7bdb708..b2b7ff7d81687 100644 --- a/TTreeValidation.cc +++ b/TTreeValidation.cc @@ -952,7 +952,7 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) hitchi2_seed_eff_ = -99; - duplmask_seed_eff_ = 2; // mask means unmatched sim track + duplmask_seed_eff_ = -1; // mask means unmatched sim track nTkMatches_seed_eff_ = -99; // unmatched } @@ -1036,7 +1036,7 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) hitchi2_build_eff_ = -99; - duplmask_build_eff_ = 2; // mask means unmatched sim track + duplmask_build_eff_ = -1; // mask means unmatched sim track nTkMatches_build_eff_ = -99; // unmatched } @@ -1121,7 +1121,7 @@ void TTreeValidation::fillEfficiencyTree(const Event& ev) hitchi2_fit_eff_ = -99; - duplmask_fit_eff_ = 2; // mask means unmatched sim track + duplmask_fit_eff_ = -1; // mask means unmatched sim track nTkMatches_fit_eff_ = -99; // unmatched } @@ -1256,7 +1256,7 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) nHits_mc_seed_FR_ = -99; lastlyr_mc_seed_FR_ = -99; - duplmask_seed_FR_ = 2; // see notation above + duplmask_seed_FR_ = -1; iTkMatches_seed_FR_ = -99; } @@ -1370,7 +1370,7 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) nHits_mc_build_FR_ = -99; lastlyr_mc_build_FR_ = -99; - duplmask_build_FR_ = 2; + duplmask_build_FR_ = -1; iTkMatches_build_FR_ = -99; } // matched seed to build, not build to sim } @@ -1400,7 +1400,7 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) hitchi2_build_FR_ = -100; // keep -100 for all sim variables as no such reco exists for this seed - mcmask_build_FR_ = -1; // do not want to count towards build FR + mcmask_build_FR_ = -2; // do not want to count towards build FR mcID_build_FR_ = -100; pt_mc_build_FR_ = -100; @@ -1411,7 +1411,7 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) nHits_mc_build_FR_ = -100; lastlyr_mc_build_FR_ = -100; - duplmask_build_FR_ = -1; + duplmask_build_FR_ = -2; iTkMatches_build_FR_ = -100; } @@ -1523,7 +1523,7 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) nHits_mc_fit_FR_ = -99; lastlyr_mc_fit_FR_ = -99; - duplmask_fit_FR_ = 2; + duplmask_fit_FR_ = -1; iTkMatches_fit_FR_ = -99; } // matched seed to fit, not fit to sim } @@ -1553,7 +1553,7 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) hitchi2_fit_FR_ = -100; // keep -100 for all sim variables as no such reco exists for this seed - mcmask_fit_FR_ = -1; // do not want to count towards fit FR + mcmask_fit_FR_ = -2; // do not want to count towards fit FR mcID_fit_FR_ = -100; pt_mc_fit_FR_ = -100; @@ -1564,7 +1564,7 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) nHits_mc_fit_FR_ = -100; lastlyr_mc_fit_FR_ = -100; - duplmask_fit_FR_ = -1; + duplmask_fit_FR_ = -2; iTkMatches_fit_FR_ = -100; } @@ -1725,7 +1725,7 @@ void TTreeValidation::fillCMSSWEfficiencyTree(const Event& ev) dphi_build_ceff_ = -99; - duplmask_build_ceff_ = 2; // mask means unmatched cmssw track + duplmask_build_ceff_ = -1; // mask means unmatched cmssw track nTkMatches_build_ceff_ = -99; // unmatched } cmsswefftree_->Fill(); @@ -1776,10 +1776,6 @@ void TTreeValidation::fillCMSSWFakeRateTree(const Event& ev) hitchi2_build_cFR_ = buildtrack.chi2(); helixchi2_build_cFR_ = buildextra.helixChi2(); - // duplicate info - duplmask_build_cFR_ = buildextra.isDuplicate(); - iTkMatches_build_cFR_ = buildextra.duplicateID(); - // stored dphi dphi_build_cFR_ = buildextra.dPhi(); @@ -1843,6 +1839,10 @@ void TTreeValidation::fillCMSSWFakeRateTree(const Event& ev) nHits_cmssw_cFR_ = cmsswtrack.nFoundHits(); nLayers_cmssw_cFR_ = cmsswtrack.nUniqueLayers(); lastlyr_cmssw_cFR_ = cmsswtrack.getLastFoundHitLyr(); + + // duplicate info + duplmask_build_cFR_ = buildextra.isDuplicate(); + iTkMatches_build_cFR_ = buildextra.duplicateID(); } else // unmatched cmsswtracks ... put -99 for all reco values to denote unmatched { @@ -1859,6 +1859,9 @@ void TTreeValidation::fillCMSSWFakeRateTree(const Event& ev) nHits_cmssw_cFR_ = -99; nLayers_cmssw_cFR_ = -99; lastlyr_cmssw_cFR_ = -99; + + duplmask_build_cFR_ = -1; + iTkMatches_build_cFR_ = -99; } cmsswfrtree_->Fill(); diff --git a/validation-desc.txt b/validation-desc.txt index e7db6fcaf4ef4..d05eadfeeebc7 100644 --- a/validation-desc.txt +++ b/validation-desc.txt @@ -275,7 +275,8 @@ The following routines are then called after the building (MkBuilder.cc, Event.c : mcmask == 1 : get first seed track matched (i.e. the one with the highest nHits --> or lowest sum hit chi2 as provided by sort from above) : store seed track parameters - : store nHits, nlayers, last layer, chi2, duplicate info + : store nHits, nlayers, last layer, chi2 + : store duplicate info: nTrks_matched from size() of mapped vector of labels, and duplicateMask == seedtrack.isDuplicate() : get last found hit index : store hit parameters : if mcTrackID of hit == mcTrackID of sim track // ONLY for when simtrackstates are stored, i.e. in ToyMC only at the moment @@ -296,7 +297,8 @@ The following routines are then called after the building (MkBuilder.cc, Event.c : assign mcmask info based on mcTrackID from track extra (see section D and G for explanation of mask assignments) : if mcmask == 1 : store gen sim momentum parameters - : store nhits info, last layer, duplicate info + : store nhits info, last layer + : store duplicate info: iTh track matched from seedtrack extra, duplicateMask == seedtrack.isDuplicate() : if last hit found has a valid mcHitID : store sim track state momentum info from simTrackStates[mcHitID] : if seedToBuildMap[seedID] has value @@ -304,7 +306,7 @@ The following routines are then called after the building (MkBuilder.cc, Event.c : assign mcmask info based on mcTrackID from track extra (see section D and G for explanation of mask assignments) : if mcmask == 1 : store gen sim momentum parameters - : store nhits info, last layer, duplicate info + : store nhits info, last layer, duplicate info as above : if last hit found has a valid mcHitID : store sim track state momentum info from simTrackStates[mcHitID] : if seedToFitMap[seedID] has value @@ -372,8 +374,8 @@ Fake Rate (with all reco tracks: Config::inclusiveShorts == true, enabled with c -13 | -1 // OR the seed track does produce a build/fit track as determined by the seedToBuild/FitMap Duplicate Rate [PlotValidation::PlotDuplicateRate()], see special note in section H - numerator: sim tracks with more than reco track match (nTkMatches_[reco] > 1) - denominator: sim tracks with at least one reco track with mcTrackID >= 0 (mcmask_[reco] == 1) + numerator: sim tracks with more than reco track match (duplmask_[reco] == 1), or another way is nTrks_matched_[reco] > 1 + denominator: sim tracks with at least one reco track with mcTrackID >= 0 (duplmask_[reco] != -1), or mcmask_[reco] == 1 ======================== E. Overview of scripts @@ -503,9 +505,13 @@ mcTrackID assignments in Track.cc _[reco] = {seed,build,fit} N.B. Mask assignments + +Logic is as follows: any negative integer means that track is excluded from both the numerator and denominator. A mask with a value greater than 1 means that the track is included in the denominator, but not the numerator. + --> mcmask_[reco] == 1,"associated" reco to sim track [possible duplmask_[reco] == 1,0] {eff and FR}, enter numer and denom of eff, enter denom only of FR ---> mcmask_[reco] == 0,"unassociated" reco to sim track. by definition no duplicates (no reco to associate to sim tracks!) [possible duplmask_[reco] == 2 {eff and FR}], enter denom only of eff, enter numer and denom of FR +--> mcmask_[reco] == 0,"unassociated" reco to sim track. by definition no duplicates (no reco to associate to sim tracks!) [possible duplmask_[reco] == -1 {eff and FR}], enter denom only of eff, enter numer and denom of FR --> mcmask_[reco] == -1, sim or reco track excluded from denominator (and therefore numerator) [possible duplmask_[reco] == -1] {eff and FR} +--> mcmask_[reco] == -2, reco track excluded from denominator because it does not exist (and therefore numerator) [possible duplmask_[reco] == -2] {FR} --> mcmask_[reco] == 2, reco track included in demoninator of FR, but will not enter numerator: for short "matched" tracks {FR only} --> nTkMatches_[reco] > 1, n reco tracks associated to the same sim track ID {eff only} @@ -513,18 +519,18 @@ N.B. Mask assignments --> nTkMatches_[reco] == -99, no reco to sim match {eff only} excluding position variables, as position could be -99! ---> reco var == -99, "unassociated" reco to sim track [possible mcmask_[reco] == 0,-1,2; possible duplmask_[reco] == 2] {eff only} ---> sim var == -99, "unassociated" reco to sim track [possible mcmask_[reco] == 0,-1,2; possible duplmask_[reco] == 2] {FR only} +--> reco var == -99, "unassociated" reco to sim track [possible mcmask_[reco] == 0,-1,2; possible duplmask_[reco] == -1] {eff only} +--> sim var == -99, "unassociated" reco to sim track [possible mcmask_[reco] == 0,-1,2; possible duplmask_[reco] == -1] {FR only} --> reco/sim var == -100, "no matching seed to build/fit" track, fill all reco/sim variables -100 [possible mcmask_[reco] == -1, possible duplmask_[reco] == -1] {FR only} --> sim var == -101, reco track is "associated" to sim track, however, sim track does have a hit on the layer the reco track is on ---> seedmask_[reco] == 1, matching seed to reco/fit track [possible mcmask_[reco] == 0,1,2; possible duplmask_[reco] == 0,1,2] {FR only} ---> seedmask_[reco] == 0, no matching seed to reco/fit track [possible mcmask_[reco] == -1; possible duplmask_[reco] == -1] {FR only} +--> seedmask_[reco] == 1, matching seed to reco/fit track [possible mcmask_[reco] == 0,1,2; possible duplmask_[reco] == 0,1,-1] {FR only} +--> seedmask_[reco] == 0, no matching seed to reco/fit track [possible mcmask_[reco] == -2; possible duplmask_[reco] == -2] {FR only} --> duplmask_[reco] == 0, only "associated" reco to sim track [possible mcmask_[reco] == 1] {eff and FR} --> duplmask_[reco] == 1, more than one "associated" reco to sim track [possible mcmask_[reco] == 1] {eff and FR} ---> duplmask_[reco] == 2, no "associated" reco to sim track [possible mcmask_[reco] == 0,-1,2] {eff and FR} ---> duplmask_[reco] == -1, no matching built/fit track for given seed [possible mcmask_[reco] == -1] {FR only} +--> duplmask_[reco] == -1, no "associated" reco to sim track [possible mcmask_[reco] == 0,-1,-2] {eff and FR} +--> duplmask_[reco] == -2, no matching built/fit track for given seed [possible mcmask_[reco] == -2] {FR only} --> reco var == -10, variable not yet implemented for given track object From 43049493a16d110b6707169e811a4597fcf10c0c Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Sat, 26 Aug 2017 15:40:09 -0700 Subject: [PATCH 155/172] actually exclude unfindable tracks from fake rate --- TTreeValidation.cc | 72 ++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 44 deletions(-) diff --git a/TTreeValidation.cc b/TTreeValidation.cc index b2b7ff7d81687..d0dcbf2d2049e 100644 --- a/TTreeValidation.cc +++ b/TTreeValidation.cc @@ -1185,32 +1185,28 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) { if (Config::inclusiveShorts) { - if (mcID_seed_FR_ == -1 || mcID_seed_FR_ == -5 || mcID_seed_FR_ == -6 || - mcID_seed_FR_ == -7 || mcID_seed_FR_ == -8 || mcID_seed_FR_ == -9) + if (mcID_seed_FR_ == -1 || mcID_seed_FR_ == -5 || + mcID_seed_FR_ == -8 || mcID_seed_FR_ == -9) { mcmask_seed_FR_ = 0; } - else if (mcID_seed_FR_ == -2 || mcID_seed_FR_ == -3 || mcID_seed_FR_ == -4 || - mcID_seed_FR_ == -10 || mcID_seed_FR_ == -11 || mcID_seed_FR_ == -12) + else if (mcID_seed_FR_ == -2 || mcID_seed_FR_ == -10 || + mcID_seed_FR_ == -11) { mcmask_seed_FR_ = 2; } - else // mcID == -13 + else // mcID == -3,-4,-6,-7,-12,-13 { mcmask_seed_FR_ = -1; } } else // only count long tracks { - if (mcID_seed_FR_ == -1 || mcID_seed_FR_ == -7 || mcID_seed_FR_ == -9) + if (mcID_seed_FR_ == -1 || mcID_seed_FR_ == -9) { mcmask_seed_FR_ = 0; } - else if (mcID_seed_FR_ == -4) - { - mcmask_seed_FR_ = 2; - } - else // mcID == -2,-3,-5,-6,-8,-10,-11,-12,-13 + else // mcID == -2,-3,-5,-6,-7,-8,-10,-11,-12,-13 { mcmask_seed_FR_ = -1; } @@ -1300,32 +1296,28 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) { if (Config::inclusiveShorts) { - if (mcID_build_FR_ == -1 || mcID_build_FR_ == -5 || mcID_build_FR_ == -6 || - mcID_build_FR_ == -7 || mcID_build_FR_ == -8 || mcID_build_FR_ == -9) + if (mcID_build_FR_ == -1 || mcID_build_FR_ == -5 || + mcID_build_FR_ == -8 || mcID_build_FR_ == -9) { mcmask_build_FR_ = 0; } - else if (mcID_build_FR_ == -2 || mcID_build_FR_ == -3 || mcID_build_FR_ == -4 || - mcID_build_FR_ == -10 || mcID_build_FR_ == -11 || mcID_build_FR_ == -12) + else if (mcID_build_FR_ == -2 || mcID_build_FR_ == -10 || + mcID_build_FR_ == -11) { mcmask_build_FR_ = 2; } - else // mcID == -13 + else // mcID == -3,-4,-6,-7,-12,-13 { mcmask_build_FR_ = -1; } } else // only count long tracks { - if (mcID_build_FR_ == -1 || mcID_build_FR_ == -7 || mcID_build_FR_ == -9) + if (mcID_build_FR_ == -1 || mcID_build_FR_ == -9) { mcmask_build_FR_ = 0; } - else if (mcID_build_FR_ == -4) - { - mcmask_build_FR_ = 2; - } - else // mcID == -2,-3,-5,-6,-8,-10,-11,-12,-13 + else // mcID == -2,-3,-4,-5,-6,-7,-8,-10,-11,-12,-13 { mcmask_build_FR_ = -1; } @@ -1453,32 +1445,28 @@ void TTreeValidation::fillFakeRateTree(const Event& ev) { if (Config::inclusiveShorts) { - if (mcID_fit_FR_ == -1 || mcID_fit_FR_ == -5 || mcID_fit_FR_ == -6 || - mcID_fit_FR_ == -7 || mcID_fit_FR_ == -8 || mcID_fit_FR_ == -9) + if (mcID_fit_FR_ == -1 || mcID_fit_FR_ == -5 || + mcID_fit_FR_ == -8 || mcID_fit_FR_ == -9) { mcmask_fit_FR_ = 0; } - else if (mcID_fit_FR_ == -2 || mcID_fit_FR_ == -3 || mcID_fit_FR_ == -4 || - mcID_fit_FR_ == -10 || mcID_fit_FR_ == -11 || mcID_fit_FR_ == -12) + else if (mcID_fit_FR_ == -2 || mcID_fit_FR_ == -10 || + mcID_fit_FR_ == -11) { mcmask_fit_FR_ = 2; } - else // mcID == -13 + else // mcID == -3,-4,-6,-7,-12,-13 { mcmask_fit_FR_ = -1; } } else // only count long tracks { - if (mcID_fit_FR_ == -1 || mcID_fit_FR_ == -7 || mcID_fit_FR_ == -9) + if (mcID_fit_FR_ == -1 || mcID_fit_FR_ == -9) { mcmask_fit_FR_ = 0; } - else if (mcID_fit_FR_ == -4) - { - mcmask_fit_FR_ = 2; - } - else // mcID == -2,-3,-5,-6,-8,-10,-11,-12,-13 + else // mcID == -2,-3,-4,-5,-6,-7,-8,-10,-11,-12,-13 { mcmask_fit_FR_ = -1; } @@ -1789,32 +1777,28 @@ void TTreeValidation::fillCMSSWFakeRateTree(const Event& ev) { if (Config::inclusiveShorts) { - if (cmsswID_build_cFR_ == -1 || cmsswID_build_cFR_ == -5 || cmsswID_build_cFR_ == -6 || - cmsswID_build_cFR_ == -7 || cmsswID_build_cFR_ == -8 || cmsswID_build_cFR_ == -9) + if (cmsswID_build_cFR_ == -1 || cmsswID_build_cFR_ == -5 || + cmsswID_build_cFR_ == -8 || cmsswID_build_cFR_ == -9) { cmsswmask_build_cFR_ = 0; } - else if (cmsswID_build_cFR_ == -2 || cmsswID_build_cFR_ == -3 || cmsswID_build_cFR_ == -4 || - cmsswID_build_cFR_ == -10 || cmsswID_build_cFR_ == -11 || cmsswID_build_cFR_ == -12) + else if (cmsswID_build_cFR_ == -2 || cmsswID_build_cFR_ == -10 || + cmsswID_build_cFR_ == -11) { cmsswmask_build_cFR_ = 2; } - else // mcID == -13 + else // mcID == -3,-4,-6,-7,-12,-13 { cmsswmask_build_cFR_ = -1; } } else // only count long tracks { - if (cmsswID_build_cFR_ == -1 || cmsswID_build_cFR_ == -7 || cmsswID_build_cFR_ == -9) + if (cmsswID_build_cFR_ == -1 || cmsswID_build_cFR_ == -9) { cmsswmask_build_cFR_ = 0; } - else if (cmsswID_build_cFR_ == -4) - { - cmsswmask_build_cFR_ = 2; - } - else // mcID == -2,-3,-5,-6,-8,-10,-11,-12,-13 + else // mcID == -2,-3,-4,-5,-6,-7,-8,-10,-11,-12,-13 { cmsswmask_build_cFR_ = -1; } From 58e097b9be682abe8cea02f1fa4f270c6ae32d34 Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Mon, 28 Aug 2017 16:48:06 +0200 Subject: [PATCH 156/172] update validation manifesto for correct mask assignments in FR --- validation-desc.txt | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/validation-desc.txt b/validation-desc.txt index d05eadfeeebc7..f26e4a64c8a0c 100644 --- a/validation-desc.txt +++ b/validation-desc.txt @@ -356,22 +356,21 @@ Efficiency [PlotValidation::PlotEfficiency()] mcmask_[reco] == - 1 excluded from both numerator and denominator because this sim track was not findable! Fake Rate (with only long reco tracks: Config::inclusiveShorts == false) [PlotValidation::PlotFakeRate()] - numerator: reco tracks with mcTrackID == -1 || == -7 || == -9 - denominator: reco tracks with mcTrackID >= 0 || == -4 || == -1 || == -7 || == -9 + numerator: reco tracks with mcTrackID == -1 || == -9 + denominator: reco tracks with mcTrackID >= 0 || == -1 || == -9 mcTrackID | mcmask_[reco] >= 0 | 1 - -1,-7,-9 | 0 - -4 | 2 + -1,-9 | 0 else | -1 // OR the seed track does produce a build/fit track as determined by the seedToBuild/FitMap Fake Rate (with all reco tracks: Config::inclusiveShorts == true, enabled with command line option: --inc-shorts) [PlotValidation::PlotFakeRate()] - numerator: reco tracks with mcTrackID == -1 || == -5 || == -6 || == -7 || == -8 || == -9 - denominator: reco tracks with mcTrackID >= 0 || == -2 || == -3 || == -4 || == -10 || == -11 || == -12 || == -1 || == -5 || == -6 || == -7 || == -8 || == -9 - mcTrackID | mcmask_[reco] - >= 0 | 1 - -1,-5,-6,-7,-8,-9 | 0 - -2,-3,-4,-10,-11,-12 | 2 - -13 | -1 // OR the seed track does produce a build/fit track as determined by the seedToBuild/FitMap + numerator: reco tracks with mcTrackID == -1 || == -5 || == -8 || == -9 + denominator: reco tracks with mcTrackID >= 0 || == -2 || == -10 || == -11 || == -1 || == -5 || == -8 || == -9 + mcTrackID | mcmask_[reco] + >= 0 | 1 + -1,-5,-8,-9 | 0 + -2,-10,-11 | 2 + else | -1 // OR the seed track does produce a build/fit track as determined by the seedToBuild/FitMap Duplicate Rate [PlotValidation::PlotDuplicateRate()], see special note in section H numerator: sim tracks with more than reco track match (duplmask_[reco] == 1), or another way is nTrks_matched_[reco] > 1 From d789d857b763acc94cac7e339ff60c3a552bfae6 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Thu, 31 Aug 2017 16:45:13 -0700 Subject: [PATCH 157/172] fix syntax --- validationMIC-build-10mu.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validationMIC-build-10mu.sh b/validationMIC-build-10mu.sh index 8ea277155551c..3a366dbaf21bb 100755 --- a/validationMIC-build-10mu.sh +++ b/validationMIC-build-10mu.sh @@ -10,7 +10,7 @@ ECP2=${BIN_DATA_PATH}/10muEta17to24Pt1to10/memoryFile.fv3.recT.072617.bin runValidation(){ for sV in "sim " "see --cmssw-seeds --clean-seeds"; do echo $sV | while read -r sN sO sC; do - if [ "${1}" == 0 ] + if [ "${1}" == 0 ]; then sC="" fi for section in ECN2 ECN1 BRL ECP1 ECP2; do From 422dac738f9916244cf23051dbf773f326601847 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Thu, 31 Aug 2017 18:32:00 -0700 Subject: [PATCH 158/172] fix syntax --- validationMIC-build-10mu.sh | 4 ++-- validationMIC-build-PU70.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/validationMIC-build-10mu.sh b/validationMIC-build-10mu.sh index 3a366dbaf21bb..fa54c13f40e7e 100755 --- a/validationMIC-build-10mu.sh +++ b/validationMIC-build-10mu.sh @@ -10,7 +10,7 @@ ECP2=${BIN_DATA_PATH}/10muEta17to24Pt1to10/memoryFile.fv3.recT.072617.bin runValidation(){ for sV in "sim " "see --cmssw-seeds --clean-seeds"; do echo $sV | while read -r sN sO sC; do - if [ "${1}" == 0 ]; then + if [ "${1}" == "0" ]; then sC="" fi for section in ECN2 ECN1 BRL ECP1 ECP2; do @@ -18,7 +18,7 @@ runValidation(){ oBase=${base}_${sN}_${section}_${bN} nTH=8 echo "${oBase}: validation [nTH:${nTH}, nVU:8]" - ./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${!section} --build-${bO} ${sO} ${sc} --num-thr ${nTH} >& log_${oBase}_NVU8int_NTH${nTH}_val.txt + ./mkFit/mkFit --geom CMS-2017 --root-val --read --file-name ${!section} --build-${bO} ${sO} ${sC} --num-thr ${nTH} >& log_${oBase}_NVU8int_NTH${nTH}_val.txt mv valtree.root valtree_${oBase}.root done done diff --git a/validationMIC-build-PU70.sh b/validationMIC-build-PU70.sh index 036fa84bd0854..4665f06b9e2d9 100755 --- a/validationMIC-build-PU70.sh +++ b/validationMIC-build-PU70.sh @@ -6,7 +6,7 @@ fin=${BIN_DATA_PATH}/PU70/10224.0_TTbar_13+TTbar_13TeV_TuneCUETP8M1_2017PU_GenSi runValidation() { for sV in "sim " "see --cmssw-seeds --clean-seeds"; do echo $sV | while read -r sN sO sC; do - if [ "$1" == 0 ] ; then + if [ "${1}" == "0" ]; then sC="" fi for bV in "BH bh" "STD std" "CE ce"; do echo $bV | while read -r bN bO; do From e6a55048f364e8562c5f5fc6dd6ed5504a76af66 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Thu, 31 Aug 2017 22:14:43 -0700 Subject: [PATCH 159/172] update to pickup --clean-seeds switch, which has replaced the compile-time switch --- benchmarkMIC-build.sh | 57 +++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/benchmarkMIC-build.sh b/benchmarkMIC-build.sh index 5a8142c745284..6d5f20b0fa560 100755 --- a/benchmarkMIC-build.sh +++ b/benchmarkMIC-build.sh @@ -5,8 +5,11 @@ fin=${BIN_DATA_PATH}/PU70/10224.0_TTbar_13+TTbar_13TeV_TuneCUETP8M1_2017PU_GenSi runBenchmark() { -# for sV in "sim " "see --cmssw-seeds"; do echo $sV | while read -r sN sO; do - for sV in "see --cmssw-seeds"; do echo $sV | while read -r sN sO; do +# for sV in "sim " "see --cmssw-seeds --clean-seeds"; do echo $sV | while read -r sN sO sC; do + for sV in "see --cmssw-seeds --clean-seeds"; do echo $sV | while read -r sN sO sC; do + if [ "${1}" == "0" ]; then + sC="" + fi for bV in "BH bh" "STD std" "CE ce"; do echo $bV | while read -r bN bO; do oBase=${base}_${sN}_${bN} for nTH in 1 4 8 16 32; do @@ -17,37 +20,35 @@ runBenchmark() done done done - make clean - make distclean } #cleanup first make clean make distclean +make -j 12 export base=SNB_CMSSW_PU70_clean echo Run default build with base = ${base} -make -j 12 -#this does make clean inside -runBenchmark - -export base=SNB_CMSSW_PU70_clean_native -echo Run native build with base = ${base} -make -j 12 CPPUSERFLAGS+="-march=native -mtune=native" CXXUSERFLAGS+="-march=native -mtune=native" -#this does make clean inside -runBenchmark +runBenchmark 0 export base=SNB_CMSSW_PU70_clean_cleanSeed echo Run CLEAN_SEEDS build with base = ${base} -make -j 12 CPPUSERFLAGS+=-DCLEAN_SEEDS CXXUSERFLAGS+=-DCLEAN_SEEDS -#this does make clean inside -runBenchmark +runBenchmark 1 +make clean +make distclean + + +make -j 12 CPPUSERFLAGS+="-march=native -mtune=native" CXXUSERFLAGS+="-march=native -mtune=native" +export base=SNB_CMSSW_PU70_clean_native +echo Run native build with base = ${base} +runBenchmark 0 export base=SNB_CMSSW_PU70_clean_native_cleanSeed echo Run CLEAN_SEEDS build with base = ${base} -make -j 12 CPPUSERFLAGS+="-march=native -mtune=native" CXXUSERFLAGS+="-march=native -mtune=native" CPPUSERFLAGS+=-DCLEAN_SEEDS CXXUSERFLAGS+=-DCLEAN_SEEDS -#this does make clean inside -runBenchmark +runBenchmark 1 +make clean +make distclean + ECN2=${BIN_DATA_PATH}/10muEta-24to-17Pt1to10/memoryFile.fv3.recT.072617.bin ECN1=${BIN_DATA_PATH}/10muEta-175to-055Pt1to10/memoryFile.fv3.recT.072617.bin @@ -57,29 +58,33 @@ ECP2=${BIN_DATA_PATH}/10muEta17to24Pt1to10/memoryFile.fv3.recT.072617.bin runBenchmarkSections() { - for sV in "sim " "see --cmssw-seeds"; do echo $sV | while read -r sN sO; do + for sV in "sim " "see --cmssw-seeds --clean-seeds"; do echo $sV | while read -r sN sO sC; do + if [ "${1}" == "0" ]; then + sC="" + fi for section in ECN2 ECN1 BRL ECP1 ECP2; do for bV in "BH bh" "STD std" "CE ce"; do echo $bV | while read -r bN bO; do oBase=${base}_${sN}_${section}_${bN} nTH=8 echo "${oBase}: benchmark [nTH:${nTH}, nVU:8]" - time ./mkFit/mkFit --geom CMS-2017 --read --file-name ${!section} --build-${bO} ${sO} --num-thr ${nTH} >& log_${oBase}_NVU8int_NTH${nTH}_benchmark.txt + time ./mkFit/mkFit --geom CMS-2017 --read --file-name ${!section} --build-${bO} ${sO} ${sC} --num-thr ${nTH} >& log_${oBase}_NVU8int_NTH${nTH}_benchmark.txt done done done done done - - make clean - make distclean } +#this part has a pretty limited value due to the tiny load in the muon samples +make -j 12 export base=SNB_CMSSW_10mu echo Run default build with base = ${base} -make -j 12 -#this does make clean inside runBenchmarkSections +make clean +make distclean + + unset base From 11c5f1f10703792b966ec0bd367d0e7030c3aa2c Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Thu, 31 Aug 2017 22:21:49 -0700 Subject: [PATCH 160/172] benchmark 10mu with clean-seed --- benchmarkMIC-build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmarkMIC-build.sh b/benchmarkMIC-build.sh index 6d5f20b0fa560..2955e9f54ecbc 100755 --- a/benchmarkMIC-build.sh +++ b/benchmarkMIC-build.sh @@ -80,7 +80,7 @@ runBenchmarkSections() make -j 12 export base=SNB_CMSSW_10mu echo Run default build with base = ${base} -runBenchmarkSections +runBenchmarkSections 1 make clean make distclean From 9eb09e798eb7790491c4bb945601ca56daecc2ef Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 11 Sep 2017 11:19:35 -0700 Subject: [PATCH 161/172] Removing vectorization pragma from seed cleaning --- Event.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/Event.cc b/Event.cc index adead5de0e3f4..c24a7efc959c9 100644 --- a/Event.cc +++ b/Event.cc @@ -729,7 +729,6 @@ int Event::clean_cms_seedtracks() const float Eta1 = eta[ts]; const float invptq_first = invptq[ts]; - #pragma simd for (int tss= ts+1; tss Date: Mon, 11 Sep 2017 11:37:23 -0700 Subject: [PATCH 162/172] Commenting out vectorization pragma from seed cleaning --- Event.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/Event.cc b/Event.cc index c24a7efc959c9..7979458f458da 100644 --- a/Event.cc +++ b/Event.cc @@ -729,6 +729,7 @@ int Event::clean_cms_seedtracks() const float Eta1 = eta[ts]; const float invptq_first = invptq[ts]; + //#pragma simd /* Vectorization via simd had issues with icc */ for (int tss= ts+1; tss Date: Tue, 19 Sep 2017 17:03:49 -0700 Subject: [PATCH 163/172] add missing seed-cleaning flag --- benchmarkMIC-build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmarkMIC-build.sh b/benchmarkMIC-build.sh index 2955e9f54ecbc..8d73af7d9bbac 100755 --- a/benchmarkMIC-build.sh +++ b/benchmarkMIC-build.sh @@ -14,7 +14,7 @@ runBenchmark() oBase=${base}_${sN}_${bN} for nTH in 1 4 8 16 32; do echo "${oBase}: benchmark [nTH:${nTH}, nVU:8]" - time ./mkFit/mkFit --geom CMS-2017 --read --file-name ${fin} --build-${bO} ${sO} --num-thr ${nTH} >& log_${oBase}_NVU8int_NTH${nTH}_benchmark.txt + time ./mkFit/mkFit --geom CMS-2017 --read --file-name ${fin} --build-${bO} ${sO} ${sC} --num-thr ${nTH} >& log_${oBase}_NVU8int_NTH${nTH}_benchmark.txt done done done From cb067afa224f06c152d0e11dec5da7e9458b2baf Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Wed, 20 Sep 2017 00:30:21 -0700 Subject: [PATCH 164/172] Transition region, Version 0.5. --- Geoms/CMS-2017.acc | 2 +- Geoms/CMS/make_trk_info.C | 2 +- Track.cc | 112 +++++++++++ Track.h | 7 +- TrackerInfo.cc | 16 +- TrackerInfo.h | 28 ++- mkFit/CandCloner.cc | 2 +- mkFit/HitStructures.h | 20 +- mkFit/MkBuilder.cc | 409 +++++++++++++++++++++++++++----------- mkFit/MkBuilder.h | 8 +- mkFit/MkFinder.cc | 97 ++++++--- mkFit/MkFinder.h | 18 +- mkFit/MkFitter.cc | 2 +- mkFit/SteeringParams.h | 52 ++++- mkFit/buildtestMPlex.cc | 8 +- 15 files changed, 608 insertions(+), 175 deletions(-) diff --git a/Geoms/CMS-2017.acc b/Geoms/CMS-2017.acc index b33ac7a46cbd6..5c346c955daae 100644 --- a/Geoms/CMS-2017.acc +++ b/Geoms/CMS-2017.acc @@ -393,7 +393,7 @@ void Create_CMS_2017_AutoGen(TrackerInfo& ti) li.set_selection_limits(0.01, 0.2, 10.0, 20.0); } - // TID +/- + // TEC +/- { LayerInfo & li = ti.m_layers[27]; diff --git a/Geoms/CMS/make_trk_info.C b/Geoms/CMS/make_trk_info.C index 47c3091183eff..7405237fa70ea 100644 --- a/Geoms/CMS/make_trk_info.C +++ b/Geoms/CMS/make_trk_info.C @@ -213,7 +213,7 @@ void print_trk_info() add_ecap(lid, 4, 3, false, true, 10); NLN; - PRN("// TID +/-\n"); + PRN("// TEC +/-\n"); add_ecap(lid, 6, 1, false, false, -1); add_ecap(lid, 6, 1, false, true, -1); add_ecap(lid, 6, 2, false, false, -1); diff --git a/Track.cc b/Track.cc index f7b0c1acddc47..5cfa30592f1da 100644 --- a/Track.cc +++ b/Track.cc @@ -89,6 +89,118 @@ float Track::swimPhiToR(const float x0, const float y0) const return squashPhiGeneral(momPhi()-dPhi); } +bool Track::canReachRadius(float R) const +{ + const float k = ((charge() < 0) ? 100.0f : -100.0f) / (Config::sol * Config::Bfield); + const float ooc = 2.0f * k * pT(); + return std::abs(ooc) > R - std::hypot(x(), y()); +} + +float Track::zAtR(float R, float *r_reached) const +{ + float xc = x(); + float yc = y(); + float pxc = px(); + float pyc = py(); + + const float ipt = invpT(); + const float kinv = ((charge() < 0) ? 0.01f : -0.01f) * Config::sol * Config::Bfield; + const float k = 1.0f / kinv; + + const float c = 0.5f * kinv * ipt; + const float ooc = 1.0f / c; // 2 * radius of curvature + const float lambda = pz() * ipt; + + //printf("Track::zAtR to R=%f: k=%e, ipt=%e, c=%e, ooc=%e -- can hit = %f (if > 1 can)\n", + // R, k, ipt, c, ooc, ooc / (R - std::hypot(xc,yc))); + + float D = 0; + + for (int i = 0; i < Config::Niter; ++i) + { + // compute tangental and ideal distance for the current iteration. + // 3-rd order asin for symmetric incidence (shortest arc lenght). + float r0 = std::hypot(xc, yc); + float td = (R - r0) * c; + float id = ooc * td * (1.0f + 0.16666666f * td *td); + // This would be for line approximation: + // float id = R - r0; + D += id; + + //printf("%-3d r0=%f R-r0=%f td=%f id=%f id_line=%f delta_id=%g\n", + // i, r0, R-r0, td, id, R - r0, id - (R-r0)); + + float cosa = std::cos(id*ipt*kinv); + float sina = std::sin(id*ipt*kinv); + + //update parameters + xc += k * (pxc * sina - pyc * (1.0f - cosa)); + yc += k * (pyc * sina + pxc * (1.0f - cosa)); + + const float pxo = pxc;//copy before overwriting + pxc = pxc * cosa - pyc * sina; + pyc = pyc * cosa + pxo * sina; + } + + if (r_reached) *r_reached = std::hypot(xc, yc); + + return z() + lambda * D; + + // ---------------------------------------------------------------- + // Exact solution from Avery's notes ... loses precision somewhere + // { + // const float a = kinv; + // float pT = S.pT(); + + // float ax2y2 = a*(x*x + y*y); + // float T = std::sqrt(pT*pT - 2.0f*a*(x*py - y*px) + a*ax2y2); + // float D0 = (T - pT) / a; + // float D = (-2.0f * (x*py - y*px) + a * (x*x + y*y)) / (T + pT); + + // float B = c * std::sqrt((R*R - D*D) / (1.0f + 2.0f*c*D)); + // float s1 = std::asin(B) / c; + // float s2 = (Config::PI - std::asin(B)) / c; + + // printf("pt %f, invpT %f\n", pT, S.invpT()); + // printf("lambda %f, a %f, c %f, T %f, D0 %f, D %f, B %f, s1 %f, s2 %f\n", + // lambda, a, c, T, D0, D, B, s1, s2); + // printf("%f = %f / %f\n", (R*R - D*D) / (1.0f + 2.0f*c*D), (R*R - D*D), (1.0f + 2.0f*c*D)); + + // z1 = S.z() + lambda * s1; + // z2 = S.z() + lambda * s2; + + // printf("z1=%f z2=%f\n", z1, z2); + // } + // ---------------------------------------------------------------- +} + +float Track::rAtZ(float Z) const +{ + float xc = x(); + float yc = y(); + float pxc = px(); + float pyc = py(); + + const float ipt = invpT(); + const float kinv = ((charge() < 0) ? 0.01f : -0.01f) * Config::sol * Config::Bfield; + const float k = 1.0f / kinv; + + const float dz = Z - z(); + const float alpha = dz * ipt * kinv * std::tan(theta()); + + const float cosa = std::cos(alpha); + const float sina = std::sin(alpha); + + xc += k * (pxc * sina - pyc * (1.0f - cosa)); + yc += k * (pyc * sina + pxc * (1.0f - cosa)); + + // const float pxo = pxc;//copy before overwriting + // pxc = pxc * cosa - pyc * sina; + // pyc = pyc * cosa + pxo * sina; + + return std::hypot(xc, yc); +} + //============================================================================== // TrackExtra //============================================================================== diff --git a/Track.h b/Track.h index 96fe58628556d..f5e15bd067c9b 100644 --- a/Track.h +++ b/Track.h @@ -199,6 +199,7 @@ class Track float p() const { return state_.p(); } float momPhi() const { return state_.momPhi(); } float momEta() const { return state_.momEta(); } + float theta() const { return state_.theta(); } // track state momentum errors float epT() const { return state_.epT();} @@ -207,7 +208,11 @@ class Track // used for swimming cmssw rec tracks to mkFit position float swimPhiToR(const float x, const float y) const; - + + bool canReachRadius(float R) const; + float zAtR(float R, float *r_reached=0) const; + float rAtZ(float Z) const; + //this function is very inefficient, use only for debug and validation! const HitVec hitsVector(const std::vector& globalHitVec) const { diff --git a/TrackerInfo.cc b/TrackerInfo.cc index 5eeafdc5377f8..ce7e1b6151ec8 100644 --- a/TrackerInfo.cc +++ b/TrackerInfo.cc @@ -2,7 +2,6 @@ #include - void LayerInfo::set_limits(float r1, float r2, float z1, float z2) { m_rin = r1; m_rout = r2; m_zmin = z1; m_zmax = z2; @@ -26,7 +25,12 @@ void LayerInfo::set_r_hole_range(float rh1, float rh2) m_hole_r2_max = rh2 * rh2; } + //============================================================================== +// TrackerInfo +//============================================================================== + +LayerInfo TrackerInfo::s_undefined_layer(-1, LayerInfo::Undef); void TrackerInfo::set_eta_regions(float tr_beg, float tr_end, float ec_end, bool has_sibl_lyrs) { @@ -52,28 +56,28 @@ void TrackerInfo::create_layers(int n_brl, int n_ec_pos, int n_ec_neg) for (int i = 0; i < n_ec_neg; ++i) new_ecap_neg_layer(); } -int TrackerInfo::new_layer() +int TrackerInfo::new_layer(LayerInfo::LayerType_e type) { int l = (int) m_layers.size(); - m_layers.emplace_back(LayerInfo(l)); + m_layers.emplace_back(LayerInfo(l, type)); return l; } LayerInfo& TrackerInfo::new_barrel_layer() { - m_barrel.push_back( new_layer() ); + m_barrel.push_back( new_layer(LayerInfo::Barrel) ); return m_layers.back(); } LayerInfo& TrackerInfo::new_ecap_pos_layer() { - m_ecap_pos.push_back( new_layer() ); + m_ecap_pos.push_back( new_layer(LayerInfo::EndCapPos) ); return m_layers.back(); } LayerInfo& TrackerInfo::new_ecap_neg_layer() { - m_ecap_neg.push_back( new_layer() ); + m_ecap_neg.push_back( new_layer(LayerInfo::EndCapNeg) ); return m_layers.back(); } diff --git a/TrackerInfo.h b/TrackerInfo.h index 8e327971a4418..d313a4ee87ff9 100644 --- a/TrackerInfo.h +++ b/TrackerInfo.h @@ -1,12 +1,16 @@ #ifndef TRACKERINFO_H #define TRACKERINFO_H +#include "Matrix.h" + #include #include +#include #include #include + class LayerInfo { private: @@ -41,7 +45,10 @@ class LayerInfo // * ... // * pointers to hit containers - LayerInfo(int lid) : m_layer_id(lid) {} + LayerInfo(int lid, LayerType_e type) : + m_layer_id(lid), + m_layer_type(type) + {} void set_limits(float r1, float r2, float z1, float z2); void set_next_layers(int nb, int nep, int nen); @@ -53,6 +60,10 @@ class LayerInfo bool is_barrel() const { return m_layer_type == Barrel; } + bool is_within_z_limits(float z) const { return z > m_zmin && z < m_zmax; } + bool is_within_r_limits(float r) const { return r > m_rin && r < m_rout; } + bool is_within_q_limits(float q) const { return is_barrel() ? is_within_z_limits(q) : is_within_r_limits(q); } + bool is_in_rsqr_hole(float r2) const { return m_has_r_range_hole ? is_in_r2_hole(r2) : false; } bool is_in_xy_hole(float x, float y) const { return m_has_r_range_hole ? is_in_r2_hole(x*x + y*y): false; } @@ -70,7 +81,7 @@ class LayerInfo class TrackerInfo { private: - int new_layer(); + int new_layer(LayerInfo::LayerType_e type); public: enum AbsEtaRegion_e { AbsReg_Outside = -1, AbsReg_Barrel = 0, AbsReg_Transition = 1, AbsReg_Endcap = 2 }; @@ -79,6 +90,7 @@ class TrackerInfo Reg_Transition_Pos, Reg_Endcap_Pos, Reg_End, Reg_Count = Reg_End }; std::vector m_layers; + static LayerInfo s_undefined_layer; std::vector m_barrel; std::vector m_ecap_pos; @@ -87,6 +99,7 @@ class TrackerInfo float m_eta_trans_beg, m_eta_trans_end, m_eta_ecap_end; bool m_has_sibling_layers; + void set_eta_regions(float tr_beg, float tr_end, float ec_end, bool has_sibl_lyrs); void reserve_layers(int n_brl, int n_ec_pos, int n_ec_neg); @@ -131,6 +144,17 @@ class TrackerInfo return Reg_Endcap_Neg; } + const LayerInfo& outer_barrel_layer() + { + return m_layers[m_barrel.back()]; + } + + const LayerInfo& next_barrel_layer(int layer) + { + int nb = m_layers[layer].m_next_barrel; + return (nb >= 0) ? m_layers[nb] : s_undefined_layer; + } + static void ExecTrackerInfoCreatorPlugin(const std::string& base, TrackerInfo &ti, bool verbose=false); }; diff --git a/mkFit/CandCloner.cc b/mkFit/CandCloner.cc index 9e340c2f8f1c4..3e1e223fa630a 100644 --- a/mkFit/CandCloner.cc +++ b/mkFit/CandCloner.cc @@ -28,7 +28,7 @@ void CandCloner::ProcessSeedRange(int is_beg, int is_end) { std::vector& hitsForSeed = m_hits_to_add[is]; - std::vector> &cands = mp_event_of_comb_candidates->m_candidates; + std::vector &cands = mp_event_of_comb_candidates->m_candidates; #ifdef DEBUG int th_start_seed = m_start_seed; diff --git a/mkFit/HitStructures.h b/mkFit/HitStructures.h index ac74fcd9af8a1..ccd6997f251dc 100644 --- a/mkFit/HitStructures.h +++ b/mkFit/HitStructures.h @@ -169,6 +169,7 @@ class LayerOfHits void PrintBins(); }; + //============================================================================== class EventOfHits @@ -279,10 +280,21 @@ class EventOfCandidates // for combinatorial version, switch to vector of vectors //------------------------------------------------------- +// This inheritance sucks but not doing it will require more changes. + +class CombCandidate : public std::vector +{ +public: + enum SeedState_e { Dormant = 0, Finding, Finished }; + + SeedState_e m_state = Dormant; + int m_last_seed_layer = -1; +}; + class EventOfCombCandidates { public: - std::vector > m_candidates; + std::vector m_candidates; int m_capacity; int m_size; @@ -318,13 +330,15 @@ class EventOfCombCandidates m_size = 0; } - std::vector& operator[](int i) { return m_candidates[i]; } + CombCandidate& operator[](int i) { return m_candidates[i]; } void InsertSeed(const Track& seed) { assert (m_size < m_capacity); - m_candidates[m_size].emplace_back(seed); + m_candidates[m_size].push_back(seed); + m_candidates[m_size].m_state = CombCandidate::Dormant; + m_candidates[m_size].m_last_seed_layer = seed.getLastHitLyr(); ++m_size; } diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index 874586e6e9cfc..bbfcd2052aad6 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -180,39 +180,84 @@ MkBuilder::MkBuilder() : { const TrackerInfo &ti = Config::TrkInfo; - m_steering_params[TrackerInfo::Reg_Endcap_Neg] = + m_fndfoos_brl = { computeChi2MPlex, updateParametersMPlex, &MkBase::PropagateTracksToR }; + m_fndfoos_ec = { computeChi2EndcapMPlex, updateParametersEndcapMPlex, &MkBase::PropagateTracksToZ }; + + { SteeringParams &sp = m_steering_params[TrackerInfo::Reg_Endcap_Neg] = { computeChi2EndcapMPlex, updateParametersEndcapMPlex, &LayerInfo::m_next_ecap_neg, &MkBase::PropagateTracksToZ, }; + sp.reserve_plan(2 + 6 + 18); + sp.append_plan(46, true); + sp.append_plan(47, false); + sp.fill_plan(48, 53); // TID, 6 layers + sp.fill_plan(54, 71); // TEC, 18 layers + } + + { SteeringParams &sp = m_steering_params[TrackerInfo::Reg_Transition_Neg] = + { }; + sp.reserve_plan(4 + 6 + 6 + 8 + 18); + sp.append_plan( 3, true); + sp.append_plan(45, true); + sp.append_plan(46, false); + sp.append_plan(47, false); + sp.fill_plan( 4, 9); // TIB, 6 layers + sp.fill_plan(48, 53); // TID, 6 layers + sp.fill_plan(10, 17); // TOB, 8 layers + sp.fill_plan(54, 71); // TEC, 18 layers + } - //m_steering_params[TrackerInfo::Reg_Transition_Neg] = { }; - m_steering_params[TrackerInfo::Reg_Barrel] = + { SteeringParams &sp = m_steering_params[TrackerInfo::Reg_Barrel] = { computeChi2MPlex, updateParametersMPlex, &LayerInfo::m_next_barrel, &MkBase::PropagateTracksToR, }; + sp.reserve_plan(1 + 6 + 8); + sp.append_plan(3, true); // pickup-only + sp.fill_plan( 4, 9); // TIB, 6 layers + sp.fill_plan(10, 17); // TOB, 8 layers + } - //m_steering_params[TrackerInfo::Reg_Transition_Pos] = { }; + { SteeringParams &sp = m_steering_params[TrackerInfo::Reg_Transition_Pos] = + { }; + sp.reserve_plan(4 + 6 + 6 + 8 + 18); + sp.append_plan( 3, true); + sp.append_plan(18, true); + sp.append_plan(19, false); + sp.append_plan(20, false); + sp.fill_plan( 4, 9); // TIB, 6 layers + sp.fill_plan(21, 26); // TID, 6 layers + sp.fill_plan(10, 17); // TOB, 8 layers + sp.fill_plan(27, 44); // TEC, 18 layers + } - m_steering_params[TrackerInfo::Reg_Endcap_Pos] = + { SteeringParams &sp = m_steering_params[TrackerInfo::Reg_Endcap_Pos] = { computeChi2EndcapMPlex, updateParametersEndcapMPlex, &LayerInfo::m_next_ecap_pos, &MkBase::PropagateTracksToZ, }; + sp.reserve_plan(2 + 6 + 18); + sp.append_plan(19, true); + sp.append_plan(20, false); + sp.fill_plan(21, 26); // TID, 6 layers + sp.fill_plan(27, 44); // TEC, 18 layers + } - // XXMT4D Changing this order might - m_brl_ecp_regions.resize(3); - m_brl_ecp_regions[0] = TrackerInfo::Reg_Endcap_Neg; - m_brl_ecp_regions[1] = TrackerInfo::Reg_Barrel; - m_brl_ecp_regions[2] = TrackerInfo::Reg_Endcap_Pos; + // XXMT4D Changing this order might help. + m_regions.resize(5); + m_regions[0] = TrackerInfo::Reg_Transition_Pos; + m_regions[1] = TrackerInfo::Reg_Transition_Neg; + m_regions[2] = TrackerInfo::Reg_Endcap_Pos; + m_regions[3] = TrackerInfo::Reg_Endcap_Neg; + m_regions[4] = TrackerInfo::Reg_Barrel; } MkBuilder::~MkBuilder() @@ -380,7 +425,7 @@ void MkBuilder::import_seeds() // Seeds are sorted by eta and counts for each eta region are // stored into Event::seedEtaSeparators_. - // bool debug = true; + bool debug = true; TrackerInfo &trk_info = Config::TrkInfo; TrackVec &seeds = m_event->seedTracks_; @@ -396,17 +441,121 @@ void MkBuilder::import_seeds() std::vector etas(size); for (int i = 0; i < size; ++i) { - //float eta = seeds[i].momEta(); + const Track &S = seeds[i]; + const bool z_dir_pos = S.pz() > 0; - HitOnTrack hot = seeds[i].getLastHitOnTrack(); + HitOnTrack hot = S.getLastHitOnTrack(); float eta = m_event->layerHits_[hot.layer][hot.index].eta(); + // float eta = S.momEta(); + + // XXXX reg to be defined by propagation / intersection tests + TrackerInfo::EtaRegion reg; + TrackerInfo::EtaRegion reg_eta = Config::TrkInfo.find_eta_region(eta); + + // hardcode for cms ... needs some lists of layers (hit/miss) for brl / ecp tests. + + const LayerInfo &outer_brl = trk_info.outer_barrel_layer(); + + const LayerInfo &tib1 = trk_info.m_layers[ 4]; + const LayerInfo &tob1 = trk_info.m_layers[10]; + + const LayerInfo &tecp1 = trk_info.m_layers[27]; + const LayerInfo &tecn1 = trk_info.m_layers[54]; + + const LayerInfo &tec_first = z_dir_pos ? tecp1 : tecn1; + + // If I hit outer barrel ... the track is in barrel (for central, "outgoing" tracks). + // This is also true for cyl-cow. + // Better check is: hits outer TIB, misses inner TEC (but is +-z dependant). + // XXXX Calculate z ... then check is inside or less that first EC z. + // There are a lot of tracks that go through that crack. + + bool can_reach_outer_brl = S.canReachRadius(outer_brl.m_rout); + float z_at_outer_brl; + bool misses_first_tec; + if (can_reach_outer_brl) + { + z_at_outer_brl = S.zAtR(outer_brl.m_rout); + if (z_dir_pos) + misses_first_tec = z_at_outer_brl < tec_first.m_zmin; + else + misses_first_tec = z_at_outer_brl > tec_first.m_zmax; + } + + //printf("Processing seed %d: r_means %f %f %f\n", i, tib1.r_mean(), tob1.r_mean(), outer_brl.r_mean()); + + if (can_reach_outer_brl && misses_first_tec) + //outer_brl.is_within_z_limits(S.zAtR(outer_brl.r_mean()))) + { + reg = TrackerInfo::Reg_Barrel; + } + else + { + // This should be a list of layers + // CMS, first tib, tob: 4, 10 + // In principle, for central tracks, could also only check the next barrel but + // then would have another condition of actually being in barrel with last seed hit. + // This would also work for cyl-cow. + // Argh ... and it is becoming more and more seed dependant ... which makes sense. + // All this confusion needs to be generalized so it's easy to do it for each seeding + // iteration. With some configuration and/or some code. + + if ((S.canReachRadius(tib1.m_rin) && tib1.is_within_z_limits(S.zAtR(tib1.m_rin))) || + (S.canReachRadius(tob1.m_rin) && tob1.is_within_z_limits(S.zAtR(tob1.m_rin))) ) + { + // transition region ... we are still hitting barrel layers + + reg = z_dir_pos ? TrackerInfo::Reg_Transition_Pos : TrackerInfo::Reg_Transition_Neg; + } + else + { + // endcap ... no barrel layers will be hit anymore. + + reg = z_dir_pos ? TrackerInfo::Reg_Endcap_Pos : TrackerInfo::Reg_Endcap_Neg; + } + } + // reg is now defined - etas[i] = eta; - TrackerInfo::EtaRegion reg = Config::TrkInfo.find_eta_region(eta); ++m_event->seedEtaSeparators_[reg]; + m_event->seedMinLastLayer_[reg] = std::min(m_event->seedMinLastLayer_[reg], hot.layer); m_event->seedMaxLastLayer_[reg] = std::max(m_event->seedMaxLastLayer_[reg], hot.layer); + + etas[i] = 5.0f * (reg - 2) + eta; + + // ------------------------------------------------- + // Compare r-z line vs. propagation + + // const Hit &hit = m_event->layerHits_[hot.layer][hot.index]; + + // Do we hit the outermoset barrel? If yes, we are in barrel + // Do we hit the next barrel? If not, we are in endcap. + // XXXXMT: Dow we need some tolerances for this? + // XXXXMT: These conditions are true for central tracks. After that will need + // iteration specific list of layers to check. + + // const LayerInfo &outer_brl = trk_info.outer_barrel_layer(); + const LayerInfo &next_brl = trk_info.next_barrel_layer(hot.layer); + + float z_outer = S.z() + S.pz()/S.pT()*(outer_brl.m_rout - S.posR()); + float z_next = S.z() + S.pz()/S.pT()*(next_brl .m_rout - S.posR()); + + bool outer_hit = z_outer < outer_brl.m_zmax && z_outer > outer_brl.m_zmin; + bool next_hit = z_next < next_brl .m_zmax && z_next > next_brl .m_zmin; + + // ---------------------------------------------------------------- + + float r_it, z; + + z = S.zAtR(outer_brl.m_rout, &r_it); + + // printf("%3d % 6.3f %d %d %d -- % 8.3e % 8.3e %8.3f | linear: % 7.3f - iterative: % 7.3f dr = %e\n", + // i, eta, reg, outer_hit, next_hit, + // S.x(), S.y(), S.z(), z_outer, z, outer_brl.r_mean() - r_it); + + // printf("ZZZZ %d %d\n", reg, hot.layer); } + for (int i = 0; i < 5; ++i) { if (m_event->seedMinLastLayer_[i] == 9999) m_event->seedMinLastLayer_[i] = -1; @@ -540,7 +689,7 @@ void MkBuilder::fit_seeds() // int count = (theEnd + NN - 1)/NN; // XXXXMT Actually, this should be good for all regions - tbb::parallel_for_each(m_brl_ecp_regions.begin(), m_brl_ecp_regions.end(), + tbb::parallel_for_each(m_regions.begin(), m_regions.end(), [&](int reg) { // XXXXXX endcap only ... @@ -808,7 +957,8 @@ void MkBuilder::quality_process(Track &tkcand) // int mctrk = tkcand.label(); // assumes 100% "efficiency" float pt = tkcand.pT(); - float ptmc = 0., pr = 0., nfoundmc = 0., chi2mc = 0.; + float ptmc = 0., pr = 0., chi2mc = 0.; + int nfoundmc = 0; if (mctrk < 0 || mctrk >= m_event->simTracks_.size()) { @@ -839,7 +989,8 @@ void MkBuilder::quality_process(Track &tkcand) if (!Config::silent) { std::lock_guard printlock(Event::printmutex); - std::cout << "MX - found track with nFoundHits=" << tkcand.nFoundHits() << " chi2=" << tkcand.chi2() << " pT=" << pt <<" pTmc="<< ptmc << " nfoundmc=" << nfoundmc << " chi2mc=" << chi2mc <<" lab="<< tkcand.label() <candidateTracks_; - tbb::parallel_for_each(m_brl_ecp_regions.begin(), m_brl_ecp_regions.end(), + tbb::parallel_for_each(m_regions.begin(), m_regions.end(), [&](int region) { // XXXXXX Select endcap / barrel only ... @@ -1023,31 +1174,43 @@ void MkBuilder::FindTracksBestHit() RangeOfSeedIndices rng = rosi.seed_rng(blk_rng); - std::vector trk_idcs(NN); - std::vector trk_llay(NN); + std::vector trk_idcs(NN); // track indices in Matriplex + std::vector trk_llay(NN); // last layer on input track while (rng.valid()) { - dprint(std::endl << "processing track=" << rng.m_beg << ", label=" <m_pickup_only ); + + int curr_layer = layer_plan_it->m_layer; + // Loop over layers, starting from after the seed. // Consider inverting loop order and make layer outer, need to // trade off hit prefetching with copy-out of candidates. - while (true) + while (++layer_plan_it != st_par.layer_plan.end()) { + prev_layer = curr_layer; + curr_layer = layer_plan_it->m_layer; + dprint("at layer " << curr_layer); const LayerOfHits &layer_of_hits = m_event_of_hits.m_layers_of_hits[curr_layer]; const LayerInfo &layer_info = trk_info.m_layers[curr_layer]; + const FindingFoos &fnd_foos = layer_info.is_barrel() ? m_fndfoos_brl : m_fndfoos_ec; // Pick up seeds that become active on current layer -- unless already fully loaded. if (curr_tridx < rng.n_proc()) @@ -1066,17 +1229,11 @@ void MkBuilder::FindTracksBestHit() } } - // XXX This should actually be done in some other thread for the next layer while - // this thread is crunching the current one. - // For now it's done in MkFinder::AddBestHit(), two loops before the data is needed. - // for (int i = 0; i < bunch_of_hits.m_size; ++i) - // { - // _mm_prefetch((char*) & bunch_of_hits.m_hits[i], _MM_HINT_T1); - // } + if (layer_plan_it->m_pickup_only) continue; dcall(pre_prop_print(curr_layer, mkfndr.get())); - (mkfndr.get()->*st_par.propagate_foo)(layer_info.m_propagate_to, curr_tridx); + (mkfndr.get()->*fnd_foos.m_propagate_foo)(layer_info.m_propagate_to, curr_tridx); dcall(post_prop_print(curr_layer, mkfndr.get())); @@ -1089,15 +1246,8 @@ void MkBuilder::FindTracksBestHit() // make candidates with best hit dprint("make new candidates"); - mkfndr->AddBestHit(layer_of_hits, curr_tridx, st_par); + mkfndr->AddBestHit(layer_of_hits, curr_tridx, fnd_foos); - if (layer_info.m_is_outer) - { - break; - } - - prev_layer = curr_layer; - curr_layer = layer_info.*st_par.next_layer_doo; } // end of layer loop mkfndr->OutputTracksAndHitIdx(cands, trk_idcs, 0, curr_tridx, false); @@ -1114,7 +1264,7 @@ void MkBuilder::FindTracksBestHit() void MkBuilder::find_tracks_load_seeds() { - // Assumes seeds are sorter according to m_regions_of_comb_candidates + // Assumes seeds are sorted according to m_regions_of_comb_candidates EventOfCombCandidates &eoccs = m_event_of_comb_cands; @@ -1130,18 +1280,33 @@ void MkBuilder::find_tracks_load_seeds() } int MkBuilder::find_tracks_unroll_candidates(std::vector> & seed_cand_vec, - int start_seed, int end_seed, int layer) + int start_seed, int end_seed, + int prev_layer, bool pickup_only) { seed_cand_vec.clear(); for (int iseed = start_seed; iseed < end_seed; ++iseed) { - std::vector &scands = m_event_of_comb_cands[iseed]; - for (int ic = 0; ic < scands.size(); ++ic) + CombCandidate &ccand = m_event_of_comb_cands[iseed]; + + if (ccand.m_state == CombCandidate::Dormant && ccand.m_last_seed_layer == prev_layer) { - if (scands[ic].getLastHitIdx() != -2 && scands[ic].getLastHitLyr() < layer) + ccand.m_state = CombCandidate::Finding; + } + if ( ! pickup_only && ccand.m_state == CombCandidate::Finding) + { + bool active = false; + for (int ic = 0; ic < ccand.size(); ++ic) + { + if (ccand[ic].getLastHitIdx() != -2) + { + active = true; + seed_cand_vec.push_back(std::pair(iseed,ic)); + } + } + if ( ! active) { - seed_cand_vec.push_back(std::pair(iseed,ic)); + ccand.m_state = CombCandidate::Finished; } } } @@ -1155,11 +1320,13 @@ int MkBuilder::find_tracks_unroll_candidates(std::vector> & s void MkBuilder::FindTracksStandard() { + bool debug = true; + g_exe_ctx.populate(Config::numThreadsFinder); EventOfCombCandidates &eoccs = m_event_of_comb_cands; - tbb::parallel_for_each(m_brl_ecp_regions.begin(), m_brl_ecp_regions.end(), + tbb::parallel_for_each(m_regions.begin(), m_regions.end(), [&](int region) { const SteeringParams &st_par = m_steering_params[region]; @@ -1192,17 +1359,31 @@ void MkBuilder::FindTracksStandard() std::vector> seed_cand_idx; seed_cand_idx.reserve(n_seeds * Config::maxCandsPerSeed); + auto layer_plan_it = st_par.layer_plan.begin(); + + assert( layer_plan_it->m_pickup_only ); + + int curr_layer = layer_plan_it->m_layer, prev_layer; + + dprintf("\nMkBuilder::FindTracksStandard region=%d, seed_pickup_layer=%d, first_layer=%d\n", + region, curr_layer, (layer_plan_it + 1)->m_layer); + // Loop over layers, starting from after the seed. - for (int ilay = first_layer; ; ) + while (++layer_plan_it != st_par.layer_plan.end()) { - dprint("processing lay=" << ilay); - - const LayerOfHits &layer_of_hits = m_event_of_hits.m_layers_of_hits[ilay]; - const LayerInfo &layer_info = trk_info.m_layers[ilay]; + prev_layer = curr_layer; + curr_layer = layer_plan_it->m_layer; + + dprint("processing lay=" << curr_layer); + + const LayerOfHits &layer_of_hits = m_event_of_hits.m_layers_of_hits[curr_layer]; + const LayerInfo &layer_info = trk_info.m_layers[curr_layer]; + const FindingFoos &fnd_foos = layer_info.is_barrel() ? m_fndfoos_brl : m_fndfoos_ec; - int theEndCand = find_tracks_unroll_candidates(seed_cand_idx, start_seed, end_seed, ilay); + int theEndCand = find_tracks_unroll_candidates(seed_cand_idx, start_seed, end_seed, + prev_layer, layer_plan_it->m_pickup_only); - if (theEndCand == 0) goto next_layer; + if (layer_plan_it->m_pickup_only || theEndCand == 0) continue; // vectorized loop for (int itrack = 0; itrack < theEndCand; itrack += NN) @@ -1217,21 +1398,21 @@ void MkBuilder::FindTracksStandard() false); //propagate to layer - dcall(pre_prop_print(ilay, mkfndr.get())); + dcall(pre_prop_print(curr_layer, mkfndr.get())); - (mkfndr.get()->*st_par.propagate_foo)(layer_info.m_propagate_to, end - itrack); + (mkfndr.get()->*fnd_foos.m_propagate_foo)(layer_info.m_propagate_to, end - itrack); - dcall(post_prop_print(ilay, mkfndr.get())); + dcall(post_prop_print(curr_layer, mkfndr.get())); dprint("now get hit range"); mkfndr->SelectHitIndices(layer_of_hits, end - itrack, false); //#ifdef PRINTOUTS_FOR_PLOTS - //std::cout << "MX number of hits in window in layer " << ilay << " is " << mkfndr->getXHitEnd(0, 0, 0)-mkfndr->getXHitBegin(0, 0, 0) << std::endl; + //std::cout << "MX number of hits in window in layer " << curr_layer << " is " << mkfndr->getXHitEnd(0, 0, 0)-mkfndr->getXHitBegin(0, 0, 0) << std::endl; //#endif dprint("make new candidates"); - mkfndr->FindCandidates(layer_of_hits, tmp_cands, start_seed, end - itrack, st_par); + mkfndr->FindCandidates(layer_of_hits, tmp_cands, start_seed, end - itrack, fnd_foos); } //end of vectorized loop @@ -1278,14 +1459,6 @@ void MkBuilder::FindTracksStandard() } } - next_layer: - - if (layer_info.m_is_outer) - { - break; - } - - ilay = layer_info.*st_par.next_layer_doo; } // end of layer loop // final sorting @@ -1311,7 +1484,7 @@ void MkBuilder::FindTracksCloneEngine() EventOfCombCandidates &eoccs = m_event_of_comb_cands; - tbb::parallel_for_each(m_brl_ecp_regions.begin(), m_brl_ecp_regions.end(), + tbb::parallel_for_each(m_regions.begin(), m_regions.end(), [&](int region) { int adaptiveSPT = eoccs.m_size / Config::numThreadsFinder / 2 + 1; @@ -1338,9 +1511,9 @@ void MkBuilder::find_tracks_in_layers(CandCloner &cloner, MkFinder *mkfndr, { // int debug = 1; - EventOfCombCandidates &eoccs = m_event_of_comb_cands; - const SteeringParams &st_par = m_steering_params[region]; - const TrackerInfo &trk_info = Config::TrkInfo; + EventOfCombCandidates &eoccs = m_event_of_comb_cands; + const SteeringParams &st_par = m_steering_params[region]; + const TrackerInfo &trk_info = Config::TrkInfo; const int n_seeds = end_seed - start_seed; @@ -1350,23 +1523,34 @@ void MkBuilder::find_tracks_in_layers(CandCloner &cloner, MkFinder *mkfndr, cloner.begin_eta_bin(&eoccs, start_seed, n_seeds); // Loop over layers, starting from after the seed. - // Note that we do a final pass with ilay = -1 to update parameters - // and output final tracks. prev_ilay == -1 serves as is_first_layer. - int prev_ilay = -1; + // Note that we do a final pass with curr_layer = -1 to update parameters + // and output final tracks. - int last_seed_layer = m_event->seedMinLastLayer_[region]; - int first_layer = trk_info.m_layers[last_seed_layer].*st_par.next_layer_doo; + auto layer_plan_it = st_par.layer_plan.begin(); - dprintf("\nMkBuilder::find_tracks_in_layers region=%d, last_seed_layer=%d, first_layer=%d\n", - region, last_seed_layer, first_layer); + assert( layer_plan_it->m_pickup_only ); - for (int ilay = first_layer; ; ) + int curr_layer = layer_plan_it->m_layer, prev_layer; + + dprintf("\nMkBuilder::find_tracks_in_layers region=%d, seed_pickup_layer=%d, first_layer=%d\n", + region, curr_layer, (layer_plan_it + 1)->m_layer); + + // Loop over layers according to plan. + while (++layer_plan_it != st_par.layer_plan.end()) { - dprint("\n* Processing lay=" << ilay); + prev_layer = curr_layer; + curr_layer = layer_plan_it->m_layer; + + const bool pickup_only = layer_plan_it->m_pickup_only; + + dprintf("\n* Processing layer %d, %s\n", curr_layer, pickup_only ? "pickup only" : "full finding"); - const LayerInfo &layer_info = trk_info.m_layers[ilay]; + const LayerInfo &layer_info = trk_info.m_layers[curr_layer]; + const LayerOfHits &layer_of_hits = m_event_of_hits.m_layers_of_hits[curr_layer]; + const FindingFoos &fnd_foos = layer_info.is_barrel() ? m_fndfoos_brl : m_fndfoos_ec; - const int theEndCand = find_tracks_unroll_candidates(seed_cand_idx, start_seed, end_seed, ilay); + const int theEndCand = find_tracks_unroll_candidates(seed_cand_idx, start_seed, end_seed, + prev_layer, pickup_only); dprintf(" Number of candidates to process: %d\n", theEndCand); @@ -1377,12 +1561,9 @@ void MkBuilder::find_tracks_in_layers(CandCloner &cloner, MkFinder *mkfndr, // XXXXMT There might be cases in endcap where all tracks will miss the // next layer, but only relevant if we do geometric selection before. - if (theEndCand == 0 && ilay != -1) goto next_layer; + if (pickup_only || theEndCand == 0) continue; - if (ilay >= 0) - { - cloner.begin_layer(ilay); - } + cloner.begin_layer(curr_layer); //vectorized loop for (int itrack = 0; itrack < theEndCand; itrack += NN) @@ -1401,64 +1582,52 @@ void MkBuilder::find_tracks_in_layers(CandCloner &cloner, MkFinder *mkfndr, #endif mkfndr->InputTracksAndHitIdx(eoccs.m_candidates, seed_cand_idx, - itrack, end, prev_ilay >= 0); + itrack, end, false); #ifdef DEBUG for (int i=itrack; i < end; ++i) dprintf(" track %d, idx %d is from seed %d\n", i, i - itrack, mkfndr->Label(i - itrack,0,0)); dprintf("\n"); #endif - if (prev_ilay >= 0) - { - const LayerOfHits &prev_layer_of_hits = m_event_of_hits.m_layers_of_hits[prev_ilay]; - mkfndr->UpdateWithLastHit(prev_layer_of_hits, end - itrack, st_par); - } - if (ilay >= 0) - { - // propagate to current layer - (mkfndr->*st_par.propagate_foo)(layer_info.m_propagate_to, end - itrack); - // copy_out the propagated track params, errors only (hit-idcs and chi2 already updated) - mkfndr->CopyOutParErr(eoccs.m_candidates, end - itrack, true); - } - else - { - // copy_out the updated track params, errors only (hit-idcs and chi2 already updated) - mkfndr->CopyOutParErr(eoccs.m_candidates, end - itrack, false); - continue; - } + // propagate to current layer + (mkfndr->*fnd_foos.m_propagate_foo)(layer_info.m_propagate_to, end - itrack); - dprint("now get hit range"); + // copy_out the propagated track params, errors only (hit-idcs and chi2 already updated) + mkfndr->CopyOutParErr(eoccs.m_candidates, end - itrack, true); - const LayerOfHits &layer_of_hits = m_event_of_hits.m_layers_of_hits[ilay]; + dprint("now get hit range"); mkfndr->SelectHitIndices(layer_of_hits, end - itrack, false); //#ifdef PRINTOUTS_FOR_PLOTS - //std::cout << "MX number of hits in window in layer " << ilay << " is " << mkfndr->getXHitEnd(0, 0, 0)-mkfndr->getXHitBegin(0, 0, 0) << std::endl; + //std::cout << "MX number of hits in window in layer " << curr_layer << " is " << mkfndr->getXHitEnd(0, 0, 0)-mkfndr->getXHitBegin(0, 0, 0) << std::endl; //#endif dprint("make new candidates"); cloner.begin_iteration(); - mkfndr->FindCandidatesCloneEngine(layer_of_hits, cloner, start_seed, end - itrack, st_par); + mkfndr->FindCandidatesCloneEngine(layer_of_hits, cloner, start_seed, end - itrack, fnd_foos); cloner.end_iteration(); } //end of vectorized loop - if (ilay >= 0) - { - cloner.end_layer(); - } - else + cloner.end_layer(); + + // Update loop of best candidates. + for (int itrack = 0; itrack < theEndCand; itrack += NN) { - break; - } + const int end = std::min(itrack + NN, theEndCand); + + mkfndr->InputTracksAndHitIdx(eoccs.m_candidates, seed_cand_idx, + itrack, end, true); + + mkfndr->UpdateWithLastHit(layer_of_hits, end - itrack, fnd_foos); - prev_ilay = ilay; + // copy_out the updated track params, errors only (hit-idcs and chi2 already updated) + mkfndr->CopyOutParErr(eoccs.m_candidates, end - itrack, false); + } - next_layer: - ilay = layer_info.*st_par.next_layer_doo; } // end of layer loop cloner.end_eta_bin(); diff --git a/mkFit/MkBuilder.h b/mkFit/MkBuilder.h index c2573de797e2b..6ff6d9b61bcc5 100644 --- a/mkFit/MkBuilder.h +++ b/mkFit/MkBuilder.h @@ -54,8 +54,9 @@ class MkBuilder int m_cnt=0, m_cnt1=0, m_cnt2=0, m_cnt_8=0, m_cnt1_8=0, m_cnt2_8=0, m_cnt_nomc=0; + FindingFoos m_fndfoos_brl, m_fndfoos_ec; SteeringParams m_steering_params[5]; - std::vector m_brl_ecp_regions; + std::vector m_regions; public: typedef std::vector> CandIdx_t; @@ -98,8 +99,11 @@ class MkBuilder void find_tracks_load_seeds_BH(); // for FindTracksBestHit void find_tracks_load_seeds(); + int find_tracks_unroll_candidates(std::vector> & seed_cand_vec, - int start_seed, int end_seed, int layer); + int start_seed, int end_seed, + int prev_layer, bool pickup_only); + void find_tracks_in_layers(CandCloner &cloner, MkFinder *mkfndr, int start_seed, int end_seed, int region); diff --git a/mkFit/MkFinder.cc b/mkFit/MkFinder.cc index 37fb869a31eb5..d0a4542d031f4 100644 --- a/mkFit/MkFinder.cc +++ b/mkFit/MkFinder.cc @@ -46,8 +46,8 @@ void MkFinder::InputTracksAndHitIdx(const std::vector& tracks, } } -void MkFinder::InputTracksAndHitIdx(const std::vector >& tracks, - const std::vector >& idxs, +void MkFinder::InputTracksAndHitIdx(const std::vector & tracks, + const std::vector>& idxs, int beg, int end, bool inputProp) { // Assign track parameters to initial state and copy hit values in. @@ -68,8 +68,8 @@ void MkFinder::InputTracksAndHitIdx(const std::vector >& trac } } -void MkFinder::InputTracksAndHitIdx(const std::vector >& tracks, - const std::vector >& idxs, +void MkFinder::InputTracksAndHitIdx(const std::vector & tracks, + const std::vector>& idxs, int beg, int end, bool inputProp) { // Assign track parameters to initial state and copy hit values in. @@ -334,8 +334,8 @@ void MkFinder::SelectHitIndices(const LayerOfHits &layer_of_hits, //#define NO_PREFETCH //#define NO_GATHER -void MkFinder::AddBestHit(const LayerOfHits &layer_of_hits, const int N_proc, - const SteeringParams &st_par) +void MkFinder::AddBestHit(const LayerOfHits &layer_of_hits, const int N_proc, + const FindingFoos &fnd_foos) { // debug = true; @@ -435,8 +435,8 @@ void MkFinder::AddBestHit(const LayerOfHits &layer_of_hits, const int N_proc, //now compute the chi2 of track state vs hit MPlexQF outChi2; - (*st_par.compute_chi2_foo)(Err[iP], Par[iP], Chg, msErr, msPar, - outChi2, N_proc); + (*fnd_foos.m_compute_chi2_foo)(Err[iP], Par[iP], Chg, msErr, msPar, + outChi2, N_proc); #ifndef NO_PREFETCH // Prefetch to L1 the hits we'll process in the next loop iteration. @@ -478,6 +478,20 @@ void MkFinder::AddBestHit(const LayerOfHits &layer_of_hits, const int N_proc, #pragma simd for (int itrack = 0; itrack < N_proc; ++itrack) { + // XXXXMT HACK ... SKIP missed layers here. + // Can/should be done earlier? + bool is_brl = layer_of_hits.is_barrel(); + float q = is_brl ? Par[iP](itrack,2,0) : std::hypot(Par[iP](itrack,0,0), Par[iP](itrack,1,0)); + if ( ! layer_of_hits.m_layer_info->is_within_q_limits(q)) + { + msErr.SetDiagonal3x3(itrack, 666); + msPar(itrack,0,0) = Par[iP](itrack,0,0); + msPar(itrack,1,0) = Par[iP](itrack,1,0); + msPar(itrack,2,0) = Par[iP](itrack,2,0); + // Don't update chi2 + continue; + } + //fixme decide what to do in case no hit found if (bestHit[itrack] >= 0) { @@ -521,8 +535,8 @@ void MkFinder::AddBestHit(const LayerOfHits &layer_of_hits, const int N_proc, // are already done when computing chi2. Not sure it's worth caching them?) dprint("update parameters"); - (*st_par.update_param_foo)(Err[iP], Par[iP], Chg, msErr, msPar, - Err[iC], Par[iC], N_proc); + (*fnd_foos.m_update_param_foo)(Err[iP], Par[iP], Chg, msErr, msPar, + Err[iC], Par[iC], N_proc); //std::cout << "Par[iP](0,0,0)=" << Par[iP](0,0,0) << " Par[iC](0,0,0)=" << Par[iC](0,0,0)<< std::endl; } @@ -534,7 +548,7 @@ void MkFinder::AddBestHit(const LayerOfHits &layer_of_hits, const int N_proc, void MkFinder::FindCandidates(const LayerOfHits &layer_of_hits, std::vector>& tmp_candidates, const int offset, const int N_proc, - const SteeringParams &st_par) + const FindingFoos &fnd_foos) { const char *varr = (char*) layer_of_hits.m_hits; @@ -601,8 +615,8 @@ void MkFinder::FindCandidates(const LayerOfHits &layer_of_hits, //now compute the chi2 of track state vs hit MPlexQF outChi2; - (*st_par.compute_chi2_foo)(Err[iP], Par[iP], Chg, msErr, msPar, - outChi2, N_proc); + (*fnd_foos.m_compute_chi2_foo)(Err[iP], Par[iP], Chg, msErr, msPar, + outChi2, N_proc); // Prefetch to L1 the hits we'll (probably) process in the next loop iteration. for (int itrack = 0; itrack < N_proc; ++itrack) @@ -633,8 +647,8 @@ void MkFinder::FindCandidates(const LayerOfHits &layer_of_hits, if (oneCandPassCut) { - (*st_par.update_param_foo)(Err[iP], Par[iP], Chg, msErr, msPar, - Err[iC], Par[iC], N_proc); + (*fnd_foos.m_update_param_foo)(Err[iP], Par[iP], Chg, msErr, msPar, + Err[iC], Par[iC], N_proc); dprint("update parameters" << std::endl << "propagated track parameters x=" << Par[iP].ConstAt(0, 0, 0) << " y=" << Par[iP].ConstAt(0, 1, 0) << std::endl @@ -671,6 +685,18 @@ void MkFinder::FindCandidates(const LayerOfHits &layer_of_hits, //fixme: please vectorize me... for (int itrack = 0; itrack < N_proc; ++itrack) { + // XXXXMT HACK ... put in original track if a layer was missed completely. + // Can/should be done earlier? + bool is_brl = layer_of_hits.is_barrel(); + float q = is_brl ? Par[iP](itrack,2,0) : std::hypot(Par[iP](itrack,0,0), Par[iP](itrack,1,0)); + if ( ! layer_of_hits.m_layer_info->is_within_q_limits(q)) + { + Track newcand; + copy_out(newcand, itrack, iP); + tmp_candidates[SeedIdx(itrack, 0, 0) - offset].emplace_back(newcand); + continue; + } + int fake_hit_idx = num_invalid_hits(itrack) < Config::maxHolesPerCand ? -1 : -2; if (layer_of_hits.is_endcap() && @@ -696,7 +722,7 @@ void MkFinder::FindCandidates(const LayerOfHits &layer_of_hits, void MkFinder::FindCandidatesCloneEngine(const LayerOfHits &layer_of_hits, CandCloner& cloner, const int offset, const int N_proc, - const SteeringParams &st_par) + const FindingFoos &fnd_foos) { const char *varr = (char*) layer_of_hits.m_hits; @@ -765,7 +791,7 @@ void MkFinder::FindCandidatesCloneEngine(const LayerOfHits &layer_of_hits, CandC //now compute the chi2 of track state vs hit MPlexQF outChi2; - (*st_par.compute_chi2_foo)(Err[iP], Par[iP], Chg, msErr, msPar, outChi2, N_proc); + (*fnd_foos.m_compute_chi2_foo)(Err[iP], Par[iP], Chg, msErr, msPar, outChi2, N_proc); // Prefetch to L1 the hits we'll (probably) process in the next loop iteration. for (int itrack = 0; itrack < N_proc; ++itrack) @@ -815,8 +841,17 @@ void MkFinder::FindCandidatesCloneEngine(const LayerOfHits &layer_of_hits, CandC int fake_hit_idx = num_invalid_hits(itrack) < Config::maxHolesPerCand ? -1 : -2; - if (layer_of_hits.is_endcap() && - layer_of_hits.is_in_xy_hole(Par[iP](itrack,0,0), Par[iP](itrack,1,0))) + // XXXXMT HACK ... put a special code -4 if a layer was missed completely. + // The hit is then removed in update. + // Can/should be done earlier? + bool is_brl = layer_of_hits.is_barrel(); + float q = is_brl ? Par[iP](itrack,2,0) : std::hypot(Par[iP](itrack,0,0), Par[iP](itrack,1,0)); + if ( ! layer_of_hits.m_layer_info->is_within_q_limits(q)) + { + fake_hit_idx = -4; + } + else if (layer_of_hits.is_endcap() && + layer_of_hits.is_in_xy_hole(Par[iP](itrack,0,0), Par[iP](itrack,1,0))) { // YYYYYY Config::store_missed_layers fake_hit_idx = -3; @@ -829,7 +864,7 @@ void MkFinder::FindCandidatesCloneEngine(const LayerOfHits &layer_of_hits, CandC tmpList.chi2 = Chi2(itrack, 0, 0); cloner.add_cand(SeedIdx(itrack, 0, 0) - offset, tmpList); #ifdef DEBUG - std::cout << "adding invalid hit" << std::endl; + std::cout << "adding invalid hit " << fake_hit_idx << std::endl; #endif } } @@ -840,24 +875,24 @@ void MkFinder::FindCandidatesCloneEngine(const LayerOfHits &layer_of_hits, CandC //============================================================================== void MkFinder::UpdateWithLastHit(const LayerOfHits &layer_of_hits, int N_proc, - const SteeringParams &st_par) + const FindingFoos &fnd_foos) { // layer_of_hits is for previous layer! for (int i = 0; i < N_proc; ++i) { - int hit_idx = HoTArrs[i][ NHits[i] - 1].index; + const HitOnTrack &hot = HoTArrs[i][ NHits[i] - 1]; - if (hit_idx < 0) continue; + if (hot.index < 0) continue; - Hit &hit = layer_of_hits.m_hits[hit_idx]; + Hit &hit = layer_of_hits.m_hits[hot.index]; msErr.CopyIn(i, hit.errArray()); msPar.CopyIn(i, hit.posArray()); } - (*st_par.update_param_foo)(Err[iP], Par[iP], Chg, msErr, msPar, - Err[iC], Par[iC], N_proc); + (*fnd_foos.m_update_param_foo)(Err[iP], Par[iP], Chg, msErr, msPar, + Err[iC], Par[iC], N_proc); //now that we have moved propagation at the end of the sequence we lost the handle of //using the propagated parameters instead of the updated for the missing hit case. @@ -873,6 +908,11 @@ void MkFinder::UpdateWithLastHit(const LayerOfHits &layer_of_hits, int N_proc, Err[iC].CopyIn (i, tmp); Par[iP].CopyOut(i, tmp); Par[iC].CopyIn (i, tmp); + + if (HoTArrs[i][ NHits[i] - 1].index == -4) + { + --NHits[i]; + } } } } @@ -882,7 +922,7 @@ void MkFinder::UpdateWithLastHit(const LayerOfHits &layer_of_hits, int N_proc, // CopyOutParErr //============================================================================== -void MkFinder::CopyOutParErr(std::vector >& seed_cand_vec, +void MkFinder::CopyOutParErr(std::vector& seed_cand_vec, int N_proc, bool outputProp) const { const int iO = outputProp ? iP : iC; @@ -892,6 +932,9 @@ void MkFinder::CopyOutParErr(std::vector >& seed_cand_vec, //create a new candidate and fill the cands_for_next_lay vector Track &cand = seed_cand_vec[SeedIdx(i, 0, 0)][CandIdx(i, 0, 0)]; + // clone-engine update can remove the last hit if invalid (no chi2 change) + cand.setNTotalHits(NHits[i]); + //set the track state to the updated parameters Err[iO].CopyOut(i, cand.errors_nc().Array()); Par[iO].CopyOut(i, cand.parameters_nc().Array()); diff --git a/mkFit/MkFinder.h b/mkFit/MkFinder.h index 946a102ae3482..f50aad58a3f6a 100644 --- a/mkFit/MkFinder.h +++ b/mkFit/MkFinder.h @@ -6,7 +6,9 @@ #include "Track.h" class CandCloner; +class CombCandidate; class LayerOfHits; +class FindingFoos; class SteeringParams; //#include "Event.h" @@ -81,11 +83,11 @@ class MkFinder : public MkBase const std::vector & idxs, int beg, int end, bool inputProp, int mp_offset); - void InputTracksAndHitIdx(const std::vector>& tracks, + void InputTracksAndHitIdx(const std::vector& tracks, const std::vector>& idxs, int beg, int end, bool inputProp); - void InputTracksAndHitIdx(const std::vector>& tracks, + void InputTracksAndHitIdx(const std::vector& tracks, const std::vector>& idxs, int beg, int end, bool inputProp); @@ -100,26 +102,26 @@ class MkFinder : public MkBase void SelectHitIndices(const LayerOfHits &layer_of_hits, const int N_proc, bool dump=false); - void AddBestHit(const LayerOfHits &layer_of_hits, const int N_proc, - const SteeringParams &st_par); + void AddBestHit(const LayerOfHits &layer_of_hits, const int N_proc, + const FindingFoos &fnd_foos); //---------------------------------------------------------------------------- void FindCandidates(const LayerOfHits &layer_of_hits, std::vector>& tmp_candidates, const int offset, const int N_proc, - const SteeringParams &st_par); + const FindingFoos &fnd_foos); //---------------------------------------------------------------------------- void FindCandidatesCloneEngine(const LayerOfHits &layer_of_hits, CandCloner& cloner, const int offset, const int N_proc, - const SteeringParams &st_par); + const FindingFoos &fnd_foos); void UpdateWithLastHit(const LayerOfHits &layer_of_hits, int N_proc, - const SteeringParams &st_par); + const FindingFoos &fnd_foos); - void CopyOutParErr(std::vector >& seed_cand_vec, + void CopyOutParErr(std::vector& seed_cand_vec, int N_proc, bool outputProp) const; //---------------------------------------------------------------------------- diff --git a/mkFit/MkFitter.cc b/mkFit/MkFitter.cc index 4fa0eb238f97b..8134160069442 100644 --- a/mkFit/MkFitter.cc +++ b/mkFit/MkFitter.cc @@ -28,7 +28,7 @@ void MkFitter::PrintPt(int idx) { for (int i = 0; i < NN; ++i) { - printf("%5.2f ", hipo(Par[idx].At(i, 3, 0), Par[idx].At(i, 4, 0))); + printf("%5.2f ", std::hypot(Par[idx].At(i, 3, 0), Par[idx].At(i, 4, 0))); } } diff --git a/mkFit/SteeringParams.h b/mkFit/SteeringParams.h index cf90080b8fc97..bc890efadcb51 100644 --- a/mkFit/SteeringParams.h +++ b/mkFit/SteeringParams.h @@ -16,6 +16,39 @@ class MkFinder; #define UPDATE_PARAM_ARGS const MPlexLS &, const MPlexLV &, const MPlexQI &, \ const MPlexHS &, const MPlexHV &, \ MPlexLS &, MPlexLV &, const int + +struct FindingFoos +{ + void (*m_compute_chi2_foo) (COMPUTE_CHI2_ARGS); + void (*m_update_param_foo) (UPDATE_PARAM_ARGS); + void (MkBase::*m_propagate_foo) (float, const int); + + FindingFoos() {} + + FindingFoos(void (*cch2_f) (COMPUTE_CHI2_ARGS), + void (*updp_f) (UPDATE_PARAM_ARGS), + void (MkBase::*p_f) (float, const int)) : + m_compute_chi2_foo(cch2_f), + m_update_param_foo(updp_f), + m_propagate_foo(p_f) + {} + +}; + +struct LayerControl +{ + int m_layer; + + // Idea only ... need some parallel structure for candidates to make sense (where i can store it). + // Or have per layer containers where I place track indices to enable. Or something. Sigh. + int m_on_miss_jump_to; + int m_on_hit_jump_to; + + bool m_pickup_only; // do not propagate to this layer and process hits, pickup seeds only. + + LayerControl(int lay, bool pu_only=false) : m_layer(lay), m_pickup_only(pu_only) {} +}; + struct SteeringParams { void (*compute_chi2_foo) (COMPUTE_CHI2_ARGS); @@ -23,7 +56,9 @@ struct SteeringParams int LayerInfo::*next_layer_doo; - void (MkBase::*propagate_foo) (float, const int); + void (MkBase::*propagate_foo) (float, const int); + + std::vector layer_plan; //---------------------------------------------------------------------------- @@ -38,6 +73,21 @@ struct SteeringParams next_layer_doo(nl_d), propagate_foo(p_f) {} + + void reserve_plan(int n) + { + layer_plan.reserve(n); + } + + void append_plan(int layer, bool pu_only=false) + { + layer_plan.emplace_back(LayerControl(layer, pu_only)); + } + + void fill_plan(int first, int last, bool pu_only=false) + { + for (int i = first; i <= last; ++i) append_plan(i, pu_only); + } }; #endif diff --git a/mkFit/buildtestMPlex.cc b/mkFit/buildtestMPlex.cc index d320cb28bafa5..d2073319f83c0 100644 --- a/mkFit/buildtestMPlex.cc +++ b/mkFit/buildtestMPlex.cc @@ -108,7 +108,7 @@ double runBuildingTestPlexBestHit(Event& ev, MkBuilder& builder) __itt_pause(); __SSC_MARK(0x222); // use this to pause Intel SDE at the same point #endif - + if (!Config::root_val && !Config::cmssw_val) { if (!Config::silent) builder.quality_output(); } else if (Config::root_val) { @@ -119,6 +119,8 @@ double runBuildingTestPlexBestHit(Event& ev, MkBuilder& builder) builder.end_event(); + // ev.print_tracks(ev.candidateTracks_, true); + return time; } @@ -164,6 +166,8 @@ double runBuildingTestPlexStandard(Event& ev, MkBuilder& builder) builder.end_event(); + // ev.print_tracks(ev.candidateTracks_, true); + return time; } @@ -209,6 +213,8 @@ double runBuildingTestPlexCloneEngine(Event& ev, MkBuilder& builder) builder.end_event(); + // ev.print_tracks(ev.candidateTracks_, true); + return time; } From 1365812d49303f42744550df7eeb32e37182e354 Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Thu, 21 Sep 2017 16:23:45 -0700 Subject: [PATCH 165/172] Clone engine now builds proper list of (seed, cand) pairs for update. --- Event.cc | 2 +- mkFit/CandCloner.cc | 19 +++++++++++++++---- mkFit/CandCloner.h | 12 +++++++++--- mkFit/MkBuilder.cc | 22 +++++++++++++++------- mkFit/MkFinder.cc | 7 +++++-- 5 files changed, 45 insertions(+), 17 deletions(-) diff --git a/Event.cc b/Event.cc index 7979458f458da..9a9e6d945d859 100644 --- a/Event.cc +++ b/Event.cc @@ -640,7 +640,7 @@ int Event::clean_cms_simtracks() const int lasthit = t.getLastFoundHitPos(); const float eta = layerHits_[t.getHitLyr(lasthit)][t.getHitIdx(lasthit)].eta(); - if (lyr_cnt < Config::cmsSelMinLayers || Config::TrkInfo.is_transition(eta)) + if (lyr_cnt < Config::cmsSelMinLayers) // || Config::TrkInfo.is_transition(eta)) { dprintf("Rejecting simtrack %d, n_hits=%d, n_layers=%d, pT=%f\n", i, nh, lyr_cnt, t.pT()); t.setNotFindable(); diff --git a/mkFit/CandCloner.cc b/mkFit/CandCloner.cc index 3e1e223fa630a..0d9d0b0c2a9c0 100644 --- a/mkFit/CandCloner.cc +++ b/mkFit/CandCloner.cc @@ -34,7 +34,7 @@ void CandCloner::ProcessSeedRange(int is_beg, int is_end) int th_start_seed = m_start_seed; dprint("dump seed n " << is << " with input candidates=" << hitsForSeed.size()); - for (int ih = 0; ih &cv = t_cands_for_next_lay[is - is_beg]; for (int ih = 0; ih < num_hits; ih++) { const MkFinder::IdxChi2List &h2a = hitsForSeed[ih]; + cv.push_back( cands[ m_start_seed + is ][ h2a.trkIdx ] ); - cv.back().addHitIdx(h2a.hitIdx, m_layer, 0); - cv.back().setChi2(h2a.chi2); + + if (h2a.hitIdx != -4) // Could also skip storing of -3 hits. + { + cv.back().addHitIdx(h2a.hitIdx, m_layer, 0); + cv.back().setChi2(h2a.chi2); + + if (h2a.hitIdx >= 0) + { + mp_kalman_update_list->push_back(std::pair( m_start_seed + is, ih)); + } + } } - // Copy the best -2 cands back to the current list. + // Copy the best -2 cands back to the current list while there is room. if (num_hits < Config::maxCandsPerSeed) { const std::vector &ov = cands[m_start_seed + is]; diff --git a/mkFit/CandCloner.h b/mkFit/CandCloner.h index c08047b16c911..cae61569cdfc9 100644 --- a/mkFit/CandCloner.h +++ b/mkFit/CandCloner.h @@ -19,7 +19,7 @@ class CandCloner static const int s_max_seed_range = MPT_SIZE; private: - // Temporaries in ProcessSeedRange(), re-sized/served in constructor. + // Temporaries in ProcessSeedRange(), resized/reserved in constructor. // Size of this one is s_max_seed_range std::vector > t_cands_for_next_lay; @@ -38,9 +38,12 @@ class CandCloner { } - void begin_eta_bin(EventOfCombCandidates * e_o_ccs, int start_seed, int n_seeds) + void begin_eta_bin(EventOfCombCandidates *e_o_ccs, + std::vector> *update_list, + int start_seed, int n_seeds) { mp_event_of_comb_candidates = e_o_ccs; + mp_kalman_update_list = update_list, m_start_seed = start_seed; m_n_seeds = n_seeds; m_hits_to_add.resize(n_seeds); @@ -64,6 +67,8 @@ class CandCloner m_idx_max = 0; m_idx_max_prev = 0; + mp_kalman_update_list->clear(); + #ifdef CC_TIME_LAYER t_lay = dtime(); #endif @@ -161,7 +166,8 @@ class CandCloner int m_idx_max, m_idx_max_prev; std::vector> m_hits_to_add; - EventOfCombCandidates *mp_event_of_comb_candidates; + EventOfCombCandidates *mp_event_of_comb_candidates; + std::vector> *mp_kalman_update_list; #if defined(CC_TIME_ETA) or defined(CC_TIME_LAYER) double t_eta, t_lay; diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index bbfcd2052aad6..ec03beee29155 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -1314,6 +1314,7 @@ int MkBuilder::find_tracks_unroll_candidates(std::vector> & s return seed_cand_vec.size(); } + //------------------------------------------------------------------------------ // FindTracksCombinatorial: Standard TBB //------------------------------------------------------------------------------ @@ -1517,10 +1518,11 @@ void MkBuilder::find_tracks_in_layers(CandCloner &cloner, MkFinder *mkfndr, const int n_seeds = end_seed - start_seed; - std::vector> seed_cand_idx; - seed_cand_idx.reserve(n_seeds * Config::maxCandsPerSeed); + std::vector> seed_cand_idx, seed_cand_update_idx; + seed_cand_idx.reserve (n_seeds * Config::maxCandsPerSeed); + seed_cand_update_idx.reserve(n_seeds * Config::maxCandsPerSeed); - cloner.begin_eta_bin(&eoccs, start_seed, n_seeds); + cloner.begin_eta_bin(&eoccs, &seed_cand_update_idx, start_seed, n_seeds); // Loop over layers, starting from after the seed. // Note that we do a final pass with curr_layer = -1 to update parameters @@ -1614,12 +1616,18 @@ void MkBuilder::find_tracks_in_layers(CandCloner &cloner, MkFinder *mkfndr, cloner.end_layer(); - // Update loop of best candidates. - for (int itrack = 0; itrack < theEndCand; itrack += NN) + // Update loop of best candidates. CandCloner prepares the list of those + // that need update (excluding all those with negative last hid index). + + const int theEndUpdater = seed_cand_update_idx.size(); + + if (theEndUpdater == 0) continue; + + for (int itrack = 0; itrack < theEndUpdater; itrack += NN) { - const int end = std::min(itrack + NN, theEndCand); + const int end = std::min(itrack + NN, theEndUpdater); - mkfndr->InputTracksAndHitIdx(eoccs.m_candidates, seed_cand_idx, + mkfndr->InputTracksAndHitIdx(eoccs.m_candidates, seed_cand_update_idx, itrack, end, true); mkfndr->UpdateWithLastHit(layer_of_hits, end - itrack, fnd_foos); diff --git a/mkFit/MkFinder.cc b/mkFit/MkFinder.cc index d0a4542d031f4..5c31024efde5c 100644 --- a/mkFit/MkFinder.cc +++ b/mkFit/MkFinder.cc @@ -842,8 +842,8 @@ void MkFinder::FindCandidatesCloneEngine(const LayerOfHits &layer_of_hits, CandC int fake_hit_idx = num_invalid_hits(itrack) < Config::maxHolesPerCand ? -1 : -2; // XXXXMT HACK ... put a special code -4 if a layer was missed completely. - // The hit is then removed in update. - // Can/should be done earlier? + // The hit is then ignored in CandCloner. + // Can/should the "miss-layer" test be done earlier? bool is_brl = layer_of_hits.is_barrel(); float q = is_brl ? Par[iP](itrack,2,0) : std::hypot(Par[iP](itrack,0,0), Par[iP](itrack,1,0)); if ( ! layer_of_hits.m_layer_info->is_within_q_limits(q)) @@ -903,6 +903,8 @@ void MkFinder::UpdateWithLastHit(const LayerOfHits &layer_of_hits, int N_proc, { if (HoTArrs[i][ NHits[i] - 1].index < 0) { + assert (false && "This should not happen now that CandCloner builds a true update list."); + /* float tmp[21]; Err[iP].CopyOut(i, tmp); Err[iC].CopyIn (i, tmp); @@ -913,6 +915,7 @@ void MkFinder::UpdateWithLastHit(const LayerOfHits &layer_of_hits, int N_proc, { --NHits[i]; } + */ } } } From 89e79e6a20ed07222f027c0f682a5cd4c0d0dc98 Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Fri, 22 Sep 2017 08:55:21 -0700 Subject: [PATCH 166/172] remove eta restriction in validation for non-findability --- mkFit/MkBuilder.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index ec03beee29155..e455e3b8fbe80 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -1052,7 +1052,7 @@ void MkBuilder::prep_cmsswtracks() const int nlyr = cmsswtrack.nUniqueLayers(); const int ihit = cmsswtrack.getLastFoundHitPos(); const float eta = m_event->layerHits_[cmsswtrack.getHitLyr(ihit)][cmsswtrack.getHitIdx(ihit)].eta(); - if (nlyr < Config::cmsSelMinLayers || Config::TrkInfo.is_transition(eta)) cmsswtrack.setNotFindable(); + if (nlyr < Config::cmsSelMinLayers) cmsswtrack.setNotFindable(); } } From 4c96d5d762af3dbcaa2378d0e2d14d74fe6aec17 Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Mon, 25 Sep 2017 12:28:42 -0700 Subject: [PATCH 167/172] Fix compilation with icc. --- Geoms/CMS-2017.cc | 4 ++-- Geoms/Makefile | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Geoms/CMS-2017.cc b/Geoms/CMS-2017.cc index 1caf6e3f920d7..1ff2683ec62d6 100644 --- a/Geoms/CMS-2017.cc +++ b/Geoms/CMS-2017.cc @@ -2,8 +2,8 @@ // CMS 2017 geometry //------------------- -#include "../Config.h" -#include "../TrackerInfo.h" +#include "Config.h" +#include "TrackerInfo.h" namespace { diff --git a/Geoms/Makefile b/Geoms/Makefile index 06305bba069b6..eb0df3ed3d8aa 100644 --- a/Geoms/Makefile +++ b/Geoms/Makefile @@ -7,6 +7,8 @@ CPPFLAGS := ${CPPEXTRA} ${CPPFLAGS} CXXFLAGS += -fPIC ${USER_CXXFLAGS} LDFLAGS += ${LDEXTRA} +CPPFLAGS_NO_ROOT := ${CPPFLAGS} + .PHONY: all clean distclean echo SRCS := $(wildcard *.cc) @@ -28,7 +30,7 @@ all: ${TGTS} %.so: %.o ${CXX} -shared -L.. -lMicCore -o $@ $< -%.om: %.cc +%.om: %.cc %.d ${CXX} ${CPPFLAGS_NO_ROOT} ${CXXFLAGS} ${VEC_MIC} -c -o $@ $< %-mic.so: %.om @@ -41,4 +43,4 @@ endif clean: rm -f *.so *.o *.om *.d *.optrpt -distclean: clean \ No newline at end of file +distclean: clean From 3c32b543e17cd16e7f7a695278fc971bfbdd2660 Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Mon, 25 Sep 2017 12:45:47 -0700 Subject: [PATCH 168/172] Use CPPFLAGS_NO_ROOT from toplevel Makefile.config. --- Geoms/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Geoms/Makefile b/Geoms/Makefile index eb0df3ed3d8aa..f0d0f8440951f 100644 --- a/Geoms/Makefile +++ b/Geoms/Makefile @@ -7,7 +7,7 @@ CPPFLAGS := ${CPPEXTRA} ${CPPFLAGS} CXXFLAGS += -fPIC ${USER_CXXFLAGS} LDFLAGS += ${LDEXTRA} -CPPFLAGS_NO_ROOT := ${CPPFLAGS} +CPPFLAGS_NO_ROOT := ${CPPEXTRA} ${CPPFLAGS_NO_ROOT} .PHONY: all clean distclean echo From f36425cdfbecf7180a3629a9daa4f13f3973be92 Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Mon, 25 Sep 2017 22:02:12 -0700 Subject: [PATCH 169/172] In Track::addHitIdx replace the last hit once the array is full if the new hit is a true hit or signals the end of track. --- Track.cc | 7 ++++++- Track.h | 33 +++++++++++++++++++++++++-------- mkFit/CandCloner.cc | 10 +++++++--- mkFit/MkFinder.cc | 2 ++ 4 files changed, 40 insertions(+), 12 deletions(-) diff --git a/Track.cc b/Track.cc index 5cfa30592f1da..ed74368dfe669 100644 --- a/Track.cc +++ b/Track.cc @@ -532,10 +532,15 @@ void print(const TrackState& s) std::cout << std::endl; } -void print(std::string label, int itrack, const Track& trk) +void print(std::string label, int itrack, const Track& trk, bool print_hits) { std::cout << std::endl << label << ": " << itrack << " hits: " << trk.nFoundHits() << " State" << std::endl; print(trk.state()); + if (print_hits) + { + for (int i = 0; i < trk.nTotalHits(); ++i) + printf(" %2d: lyr %2d idx %d\n", i, trk.getHitLyr(i), trk.getHitIdx(i)); + } } void print(std::string label, const TrackState& s) diff --git a/Track.h b/Track.h index f5e15bd067c9b..f2d683cb866f5 100644 --- a/Track.h +++ b/Track.h @@ -245,18 +245,35 @@ class Track CUDA_CALLABLE void addHitIdx(int hitIdx, int hitLyr, float chi2) { - if (lastHitIdx_ >= Config::nMaxTrkHits - 1) return; + if (lastHitIdx_ < Config::nMaxTrkHits - 1) + { + hitsOnTrk_[++lastHitIdx_] = { hitIdx, hitLyr }; + if (hitIdx >= 0) { ++nFoundHits_; chi2_+=chi2; } + } + else + { + // printf("WARNING Track::addHitIdx hit-on-track limit reached for label=%d\n", label_); + // print("Track", -1, *this, true); - hitsOnTrk_[++lastHitIdx_] = { hitIdx, hitLyr }; - if (hitIdx >= 0) { ++nFoundHits_; chi2_+=chi2; } + if (hitIdx >= 0) + { + if (hitsOnTrk_[lastHitIdx_].index < 0) + ++nFoundHits_; + chi2_+=chi2; + hitsOnTrk_[lastHitIdx_] = { hitIdx, hitLyr }; + } + else if (hitIdx == -2) + { + if (hitsOnTrk_[lastHitIdx_].index >= 0) + --nFoundHits_; + hitsOnTrk_[lastHitIdx_] = { hitIdx, hitLyr }; + } + } } void addHitIdx(const HitOnTrack &hot, float chi2) { - if (lastHitIdx_ >= Config::nMaxTrkHits - 1) return; - - hitsOnTrk_[++lastHitIdx_] = hot; - if (hot.index >= 0) { ++nFoundHits_; chi2_+=chi2; } + addHitIdx(hot.index, hot.layer, chi2); } HitOnTrack getHitOnTrack(int posHitIdx) const { return hitsOnTrk_[posHitIdx]; } @@ -522,7 +539,7 @@ typedef std::unordered_map TkIDToTSMap; typedef std::unordered_map TkIDToTSLayerPairVecMap; void print(const TrackState& s); -void print(std::string label, int itrack, const Track& trk); +void print(std::string label, int itrack, const Track& trk, bool print_hits=false); void print(std::string label, const TrackState& s); #endif diff --git a/mkFit/CandCloner.cc b/mkFit/CandCloner.cc index 0d9d0b0c2a9c0..3f778ee54cd73 100644 --- a/mkFit/CandCloner.cc +++ b/mkFit/CandCloner.cc @@ -90,13 +90,17 @@ void CandCloner::ProcessSeedRange(int is_beg, int is_end) cands[ m_start_seed + is ].swap(cv); cv.clear(); } - // else + // else // hitsForSeed.empty() // { - // // MT: make sure we have all cands with last hit idx == -2 at this point + // // Cross-check for what is left once there are no more changes for a whole seed. // // for (auto &cand : cands[ m_start_seed + is ]) // { - // assert(cand.getLastHitIdx() == -2); + // if (cand.getLastHitIdx() < 0 && cand.getLastHitIdx() != -2) + // { + // printf(" We got cand with index %d\n", cand.getLastHitIdx()); + // print("offending track (unknown index)", -666, cand, true); + // } // } // } } diff --git a/mkFit/MkFinder.cc b/mkFit/MkFinder.cc index 5c31024efde5c..8b47cbf39555f 100644 --- a/mkFit/MkFinder.cc +++ b/mkFit/MkFinder.cc @@ -903,6 +903,8 @@ void MkFinder::UpdateWithLastHit(const LayerOfHits &layer_of_hits, int N_proc, { if (HoTArrs[i][ NHits[i] - 1].index < 0) { + printf("MkFinder::UpdateWithLastHit hit with negative index %d ... i=%d, N_proc=%d.\n", + HoTArrs[i][ NHits[i] - 1].index, i, N_proc); assert (false && "This should not happen now that CandCloner builds a true update list."); /* float tmp[21]; From 91b796639f864b44f4b13e4c5c8612d95de53d5d Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Tue, 26 Sep 2017 11:16:59 -0700 Subject: [PATCH 170/172] Fix LayerPlan for endcap. Some seeds end on layer 18 (was only expecting them at 19). --- Event.cc | 14 +++++++++++++- mkFit/MkBuilder.cc | 12 +++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Event.cc b/Event.cc index 9a9e6d945d859..949772f7b27ff 100644 --- a/Event.cc +++ b/Event.cc @@ -561,6 +561,18 @@ void Event::read_in(DataFile &data_file, FILE *in_fp) } } + /* + // HACK TO ONLY SELECT ONE PROBLEMATIC TRACK. + // Note that MC matching gets screwed. + // Works for MC seeding. + // + printf("************** SIM SELECTION HACK IN FORCE ********************\n"); + TrackVec x; + x.push_back(simTracks_[3]); + simTracks_.swap(x); + nt = 1; + */ + #ifdef DUMP_TRACKS printf("Read %i simtracks\n", nt); for (int it = 0; it < nt; it++) @@ -680,7 +692,7 @@ void Event::print_tracks(const TrackVec& tracks, bool print_hits) const hit.mcHitID(), hit.mcTrackID(simHitsInfo_)); } else - printf(" hit %2d idx=%i\n", ih, t.getHitIdx(ih)); + printf(" hit %2d lyr=%2d idx=%3d\n", ih, t.getHitLyr(ih), t.getHitIdx(ih)); } } } diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index e455e3b8fbe80..b9db5d0b7d65e 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -190,8 +190,9 @@ MkBuilder::MkBuilder() : &LayerInfo::m_next_ecap_neg, &MkBase::PropagateTracksToZ, }; - sp.reserve_plan(2 + 6 + 18); - sp.append_plan(46, true); + sp.reserve_plan(3 + 6 + 18); + sp.append_plan(45, true); + sp.append_plan(46, false); sp.append_plan(47, false); sp.fill_plan(48, 53); // TID, 6 layers sp.fill_plan(54, 71); // TEC, 18 layers @@ -244,8 +245,9 @@ MkBuilder::MkBuilder() : &LayerInfo::m_next_ecap_pos, &MkBase::PropagateTracksToZ, }; - sp.reserve_plan(2 + 6 + 18); - sp.append_plan(19, true); + sp.reserve_plan(3 + 6 + 18); + sp.append_plan(18, true); + sp.append_plan(19, false); sp.append_plan(20, false); sp.fill_plan(21, 26); // TID, 6 layers sp.fill_plan(27, 44); // TEC, 18 layers @@ -1321,7 +1323,7 @@ int MkBuilder::find_tracks_unroll_candidates(std::vector> & s void MkBuilder::FindTracksStandard() { - bool debug = true; + // bool debug = true; g_exe_ctx.populate(Config::numThreadsFinder); From 8278aba6e8395e451db0f4c5d556628f46f12383 Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Tue, 26 Sep 2017 21:24:26 -0700 Subject: [PATCH 171/172] Add hit-on-track overflow protection to MkFinder::add_hit() used by best-hit finding. --- mkFit/MkFinder.h | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/mkFit/MkFinder.h b/mkFit/MkFinder.h index f50aad58a3f6a..172fc653e6012 100644 --- a/mkFit/MkFinder.h +++ b/mkFit/MkFinder.h @@ -158,9 +158,33 @@ class MkFinder : public MkBase void add_hit(const int mslot, int index, int layer) { - HoTArrs[mslot][NHits(mslot, 0, 0)] = { index, layer }; - ++NHits(mslot, 0, 0); - if (index >= 0) ++NFoundHits(mslot, 0, 0); + int &n_tot_hits = NHits(mslot, 0, 0); + int &n_fnd_hits = NFoundHits(mslot, 0, 0); + + if (n_tot_hits < Config::nMaxTrkHits) + { + HoTArrs[mslot][n_tot_hits++] = { index, layer }; + if (index >= 0) { ++n_fnd_hits; } + } + else + { + // printf("WARNING MkFinder::add_hit hit-on-track limit reached for label=%d\n", label_); + + const int LH = Config::nMaxTrkHits - 1; + + if (index >= 0) + { + if (HoTArrs[mslot][LH].index < 0) + ++n_fnd_hits; + HoTArrs[mslot][LH] = { index, layer }; + } + else if (index == -2) + { + if (HoTArrs[mslot][LH].index >= 0) + --n_fnd_hits; + HoTArrs[mslot][LH] = { index, layer }; + } + } } int num_invalid_hits(const int mslot) const From 3f662ac2b2f81dced28f34cf9a9e3201a349622a Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Thu, 28 Sep 2017 21:35:34 -0700 Subject: [PATCH 172/172] Cleanup SteeringParams. --- mkFit/MkBuilder.cc | 41 ++++++++--------------------------------- mkFit/MkBuilder.h | 2 +- mkFit/MkFinder.cc | 2 +- mkFit/MkFinder.h | 1 - mkFit/SteeringParams.h | 17 ----------------- 5 files changed, 10 insertions(+), 53 deletions(-) diff --git a/mkFit/MkBuilder.cc b/mkFit/MkBuilder.cc index b9db5d0b7d65e..205ced021ca0a 100644 --- a/mkFit/MkBuilder.cc +++ b/mkFit/MkBuilder.cc @@ -183,13 +183,7 @@ MkBuilder::MkBuilder() : m_fndfoos_brl = { computeChi2MPlex, updateParametersMPlex, &MkBase::PropagateTracksToR }; m_fndfoos_ec = { computeChi2EndcapMPlex, updateParametersEndcapMPlex, &MkBase::PropagateTracksToZ }; - { SteeringParams &sp = m_steering_params[TrackerInfo::Reg_Endcap_Neg] = - { - computeChi2EndcapMPlex, - updateParametersEndcapMPlex, - &LayerInfo::m_next_ecap_neg, - &MkBase::PropagateTracksToZ, - }; + { SteeringParams &sp = m_steering_params[TrackerInfo::Reg_Endcap_Neg]; sp.reserve_plan(3 + 6 + 18); sp.append_plan(45, true); sp.append_plan(46, false); @@ -198,8 +192,7 @@ MkBuilder::MkBuilder() : sp.fill_plan(54, 71); // TEC, 18 layers } - { SteeringParams &sp = m_steering_params[TrackerInfo::Reg_Transition_Neg] = - { }; + { SteeringParams &sp = m_steering_params[TrackerInfo::Reg_Transition_Neg]; sp.reserve_plan(4 + 6 + 6 + 8 + 18); sp.append_plan( 3, true); sp.append_plan(45, true); @@ -212,21 +205,14 @@ MkBuilder::MkBuilder() : } - { SteeringParams &sp = m_steering_params[TrackerInfo::Reg_Barrel] = - { - computeChi2MPlex, - updateParametersMPlex, - &LayerInfo::m_next_barrel, - &MkBase::PropagateTracksToR, - }; + { SteeringParams &sp = m_steering_params[TrackerInfo::Reg_Barrel]; sp.reserve_plan(1 + 6 + 8); sp.append_plan(3, true); // pickup-only sp.fill_plan( 4, 9); // TIB, 6 layers sp.fill_plan(10, 17); // TOB, 8 layers } - { SteeringParams &sp = m_steering_params[TrackerInfo::Reg_Transition_Pos] = - { }; + { SteeringParams &sp = m_steering_params[TrackerInfo::Reg_Transition_Pos]; sp.reserve_plan(4 + 6 + 6 + 8 + 18); sp.append_plan( 3, true); sp.append_plan(18, true); @@ -238,13 +224,7 @@ MkBuilder::MkBuilder() : sp.fill_plan(27, 44); // TEC, 18 layers } - { SteeringParams &sp = m_steering_params[TrackerInfo::Reg_Endcap_Pos] = - { - computeChi2EndcapMPlex, - updateParametersEndcapMPlex, - &LayerInfo::m_next_ecap_pos, - &MkBase::PropagateTracksToZ, - }; + { SteeringParams &sp = m_steering_params[TrackerInfo::Reg_Endcap_Pos]; sp.reserve_plan(3 + 6 + 18); sp.append_plan(18, true); sp.append_plan(19, false); @@ -253,7 +233,6 @@ MkBuilder::MkBuilder() : sp.fill_plan(27, 44); // TEC, 18 layers } - // XXMT4D Changing this order might help. m_regions.resize(5); m_regions[0] = TrackerInfo::Reg_Transition_Pos; m_regions[1] = TrackerInfo::Reg_Transition_Neg; @@ -755,14 +734,14 @@ void MkBuilder::fit_seeds() { dprintf("Breaking seed range due to different layer signature at %d (%d, %d)\n", i, rng.m_beg, rng.m_end); - fit_one_seed_set(seedtracks, rng.m_beg, i, mkfttr.get(), is_brl, m_steering_params[reg]); + fit_one_seed_set(seedtracks, rng.m_beg, i, mkfttr.get(), is_brl); rng.m_beg = i; goto layer_sig_change; } } - fit_one_seed_set(seedtracks, rng.m_beg, rng.m_end, mkfttr.get(), is_brl, m_steering_params[reg]); + fit_one_seed_set(seedtracks, rng.m_beg, rng.m_end, mkfttr.get(), is_brl); ++rng; } @@ -771,8 +750,7 @@ void MkBuilder::fit_seeds() } inline void MkBuilder::fit_one_seed_set(TrackVec& seedtracks, int itrack, int end, - MkFitter *mkfttr, const bool is_brl[], - const SteeringParams &st_par) + MkFitter *mkfttr, const bool is_brl[]) { // debug=true; @@ -1337,9 +1315,6 @@ void MkBuilder::FindTracksStandard() const RegionOfSeedIndices rosi(m_event, region); - const int last_seed_layer = m_event->seedMinLastLayer_[region]; - const int first_layer = trk_info.m_layers[last_seed_layer].*st_par.next_layer_doo; - int adaptiveSPT = eoccs.m_size / Config::numThreadsFinder / 2 + 1; dprint("adaptiveSPT " << adaptiveSPT << " fill " << eoccs.m_size); diff --git a/mkFit/MkBuilder.h b/mkFit/MkBuilder.h index 6ff6d9b61bcc5..3657331387e75 100644 --- a/mkFit/MkBuilder.h +++ b/mkFit/MkBuilder.h @@ -46,7 +46,7 @@ class MkBuilder { protected: void fit_one_seed_set(TrackVec& simtracks, int itrack, int end, MkFitter *mkfttr, - const bool is_brl[], const SteeringParams &st_par); + const bool is_brl[]); Event *m_event; EventOfHits m_event_of_hits; diff --git a/mkFit/MkFinder.cc b/mkFit/MkFinder.cc index 8b47cbf39555f..8ad36ccaa718f 100644 --- a/mkFit/MkFinder.cc +++ b/mkFit/MkFinder.cc @@ -1,8 +1,8 @@ #include "MkFinder.h" #include "CandCloner.h" -#include "SteeringParams.h" #include "HitStructures.h" +#include "SteeringParams.h" #include "KalmanUtilsMPlex.h" diff --git a/mkFit/MkFinder.h b/mkFit/MkFinder.h index 172fc653e6012..c7b01e6a9cb5a 100644 --- a/mkFit/MkFinder.h +++ b/mkFit/MkFinder.h @@ -9,7 +9,6 @@ class CandCloner; class CombCandidate; class LayerOfHits; class FindingFoos; -class SteeringParams; //#include "Event.h" diff --git a/mkFit/SteeringParams.h b/mkFit/SteeringParams.h index bc890efadcb51..e7f3927d81b5a 100644 --- a/mkFit/SteeringParams.h +++ b/mkFit/SteeringParams.h @@ -51,29 +51,12 @@ struct LayerControl struct SteeringParams { - void (*compute_chi2_foo) (COMPUTE_CHI2_ARGS); - void (*update_param_foo) (UPDATE_PARAM_ARGS); - - int LayerInfo::*next_layer_doo; - - void (MkBase::*propagate_foo) (float, const int); - std::vector layer_plan; //---------------------------------------------------------------------------- SteeringParams() {} - SteeringParams(void (*cch2_f)(COMPUTE_CHI2_ARGS), - void (*updp_f)(UPDATE_PARAM_ARGS), - int LayerInfo::*nl_d, - void (MkBase::*p_f) (float, const int)) : - compute_chi2_foo(cch2_f), - update_param_foo(updp_f), - next_layer_doo(nl_d), - propagate_foo(p_f) - {} - void reserve_plan(int n) { layer_plan.reserve(n);