Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:17:54

0001 #include "MvtxPixelMask.h"
0002 #include "MvtxPixelDefs.h"
0003 
0004 #include <cdbobjects/CDBTTree.h>
0005 #include <ffamodules/CDBInterface.h>
0006 
0007 #include <trackbase/MvtxDefs.h>
0008 #include <trackbase/TrkrDefs.h>
0009 
0010 #include <ffarawobjects/MvtxRawHit.h>
0011 #include <ffarawobjects/MvtxRawHitv1.h>
0012 
0013 #include <algorithm>
0014 #include <iostream>
0015 #include <set>
0016 #include <string>
0017 
0018 // MvtxPixelMask class
0019 //==============================================================================
0020 void MvtxPixelMask::load_from_CDB()
0021 {
0022   if (!m_hot_pixel_map.empty())
0023   {
0024     clear();
0025   }
0026 
0027   // Load the hot pixel file from the CDB
0028   std::string database = CDBInterface::instance()->getUrl("MVTX_HotPixelMap");  // This is specifically for MVTX Hot Pixels
0029   CDBTTree* cdbttree = new CDBTTree(database);
0030   int n_total_masked = cdbttree->GetSingleIntValue("TotalHotPixels");
0031 
0032   // Load the hot pixel map
0033   std::set<MvtxPixelDefs::pixelkey> masked_pixels{};
0034   for (int i = 0; i < n_total_masked; i++)
0035   {
0036     int layer = cdbttree->GetIntValue(i, "layer");
0037     int stave = cdbttree->GetIntValue(i, "stave");
0038     int chip = cdbttree->GetIntValue(i, "chip");
0039     int row = cdbttree->GetIntValue(i, "row");
0040     int col = cdbttree->GetIntValue(i, "col");
0041 
0042     MvtxPixelDefs::pixelkey this_pixel_key = MvtxPixelDefs::gen_pixelkey_from_coors(layer, stave, chip, row, col);
0043     masked_pixels.insert(this_pixel_key);
0044   }
0045 
0046   // Copy the masked pixels to the hot pixel map
0047   // m_hot_pixel_map.assign(masked_pixels.begin(), masked_pixels.end());
0048   for (unsigned long masked_pixel : masked_pixels)
0049   {
0050     m_hot_pixel_map.push_back(masked_pixel);
0051   }
0052 
0053   return;
0054 }
0055 
0056 void MvtxPixelMask::add_pixel(MvtxPixelDefs::pixelkey key)
0057 {
0058   if (std::find(m_hot_pixel_map.begin(), m_hot_pixel_map.end(), key) == m_hot_pixel_map.end())
0059   {
0060     m_hot_pixel_map.push_back(key);
0061   }
0062 
0063   return;
0064 }
0065 
0066 void MvtxPixelMask::remove_pixel(MvtxPixelDefs::pixelkey key)
0067 {
0068   auto it = std::find(m_hot_pixel_map.begin(), m_hot_pixel_map.end(), key);
0069   if (it != m_hot_pixel_map.end())
0070   {
0071     m_hot_pixel_map.erase(it);
0072   }
0073 
0074   return;
0075 }
0076 
0077 void MvtxPixelMask::clear()
0078 {
0079   m_hot_pixel_map.clear();
0080   return;
0081 }
0082 
0083 bool MvtxPixelMask::is_masked(MvtxRawHit* hit) const
0084 {
0085   uint8_t layer = hit->get_layer_id();
0086   uint8_t stave = hit->get_stave_id();
0087   uint8_t chip = hit->get_chip_id();
0088   uint16_t row = hit->get_row();
0089   uint16_t col = hit->get_col();
0090 
0091   // generate hit key and hitset key
0092   const TrkrDefs::hitkey this_pixel_hitkey = MvtxDefs::genHitKey(col, row);
0093   const TrkrDefs::hitsetkey this_pixel_hitsetkey = MvtxDefs::genHitSetKey(layer, stave, chip, 0);
0094   MvtxPixelDefs::pixelkey this_pixel_key = MvtxPixelDefs::gen_pixelkey(this_pixel_hitsetkey, this_pixel_hitkey);
0095 
0096   return std::find(m_hot_pixel_map.begin(), m_hot_pixel_map.end(), this_pixel_key) != m_hot_pixel_map.end();
0097 }