Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-10-16 05:06:31

0001 // Author: Felice Pantaleo - felice.pantaleo@cern.ch
0002 // Date: 05/2024
0003 
0004 #include <vector>
0005 #include "DataFormats/Math/interface/deltaR.h"
0006 #include "FWCore/Framework/interface/Event.h"
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 #include "FWCore/Utilities/interface/Exception.h"
0009 #include "PatternRecognitionbyRecovery.h"
0010 #include "DataFormats/HGCalReco/interface/Trackster.h"
0011 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0012 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0013 #include "FWCore/Framework/interface/EventSetup.h"
0014 #include "TrackstersPCA.h"
0015 
0016 using namespace ticl;
0017 
0018 template <typename TILES>
0019 PatternRecognitionbyRecovery<TILES>::PatternRecognitionbyRecovery(const edm::ParameterSet &conf,
0020                                                                   edm::ConsumesCollector iC)
0021     : PatternRecognitionAlgoBaseT<TILES>(conf, iC), caloGeomToken_(iC.esConsumes<CaloGeometry, CaloGeometryRecord>()) {}
0022 
0023 template <typename TILES>
0024 void PatternRecognitionbyRecovery<TILES>::makeTracksters(
0025     const typename PatternRecognitionAlgoBaseT<TILES>::Inputs &input,
0026     std::vector<Trackster> &result,
0027     std::unordered_map<int, std::vector<int>> &seedToTracksterAssociation) {
0028   // Get the geometry setup
0029   edm::EventSetup const &es = input.es;
0030   const CaloGeometry &geom = es.getData(caloGeomToken_);
0031   rhtools_.setGeometry(geom);
0032   const auto z_limit_em = rhtools_.getPositionLayer(rhtools_.lastLayerEE(false), false).z();
0033   // Clear the result vector
0034   result.clear();
0035 
0036   // Iterate over all layer clusters
0037   for (size_t i = 0; i < input.layerClusters.size(); ++i) {
0038     if (input.mask[i] == 0.f) {
0039       continue;  // Skip masked clusters
0040     }
0041 
0042     // Create a new trackster for each layer cluster
0043     Trackster trackster;
0044     trackster.vertices().push_back(i);
0045     trackster.vertex_multiplicity().push_back(1);
0046     const auto &lc = input.layerClusters[i];
0047     trackster.setTimeAndError(input.layerClustersTime.get(i).first, input.layerClustersTime.get(i).second);
0048     trackster.setRawEnergy(lc.energy());
0049     trackster.setBarycenter({float(lc.x()), float(lc.y()), float(lc.z())});
0050     float invcosh = 1.f / std::cosh(lc.position().eta());
0051     trackster.setRawPt(lc.energy() * invcosh);
0052 
0053     if (std::abs(lc.z()) <= z_limit_em) {
0054       trackster.setRawEmEnergy(lc.energy());
0055       trackster.setRawEmPt(lc.energy() * invcosh);
0056     }
0057 
0058     // Add the trackster to the result vector
0059     result.push_back(trackster);
0060   }
0061 
0062   // Log the number of tracksters created
0063   if (PatternRecognitionAlgoBaseT<TILES>::algo_verbosity_ > VerbosityLevel::Advanced) {
0064     edm::LogVerbatim("PatternRecognitionbyRecovery") << "Created " << result.size() << " tracksters";
0065   }
0066 }
0067 
0068 template <typename TILES>
0069 void PatternRecognitionbyRecovery<TILES>::filter(std::vector<Trackster> &output,
0070                                                  const std::vector<Trackster> &inTracksters,
0071                                                  const typename PatternRecognitionAlgoBaseT<TILES>::Inputs &input,
0072                                                  std::unordered_map<int, std::vector<int>> &seedToTracksterAssociation) {
0073   output = inTracksters;
0074 }
0075 
0076 template <typename TILES>
0077 void PatternRecognitionbyRecovery<TILES>::fillPSetDescription(edm::ParameterSetDescription &iDesc) {
0078   iDesc.add<int>("algo_verbosity", 0);
0079 }
0080 
0081 // Explicitly instantiate the templates
0082 template class ticl::PatternRecognitionbyRecovery<TICLLayerTiles>;
0083 template class ticl::PatternRecognitionbyRecovery<TICLLayerTilesHFNose>;