Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:21:59

0001 #include "MvtxApplyHotDead.h"
0002 
0003 #include "mvtx/MvtxDefUtil.h"
0004 #include "mvtx/MvtxHitSetv1.h"
0005 
0006 #include <trackbase/TrkrHitSetContainer.h>
0007 #include <trackbase/TrkrHitSetv1.h>
0008 #include <trackbase/TrkrClusterContainer.h>
0009 #include <trackbase/TrkrClusterv1.h>
0010 
0011 
0012 #include <fun4all/Fun4AllReturnCodes.h>
0013 #include <phool/PHCompositeNode.h>
0014 #include <phool/PHIODataNode.h>
0015 #include <phool/PHNodeIterator.h>
0016 #include <phool/getClass.h>
0017 #include <g4detectors/PHG4CellContainer.h>
0018 #include <g4detectors/PHG4CylinderCellGeomContainer.h>
0019 #include <g4detectors/PHG4CylinderGeomContainer.h>
0020 #include <g4detectors/PHG4CylinderGeom.h>
0021 #include <g4detectors/PHG4CylinderGeom_MAPS.h>
0022 #include <g4detectors/PHG4CylinderGeom_Siladders.h>
0023 #include <g4detectors/PHG4Cell.h>
0024 #include <g4detectors/PHG4CylinderCellGeom.h>
0025 
0026 #include <iostream>
0027 #include <fstream>
0028 #include <stdio.h>
0029 
0030 using namespace std;
0031 
0032 MvtxApplyHotDead::MvtxApplyHotDead(const string &name, const std::string file ) :
0033   SubsysReco(name),
0034   hits_(NULL),
0035   hdfile_(file),
0036   _timer(PHTimeServer::get()->insert_new(name))
0037 {
0038   ReadHotDeadFile();
0039 }
0040 
0041 int MvtxApplyHotDead::InitRun(PHCompositeNode* topNode)
0042 {
0043   return Fun4AllReturnCodes::EVENT_OK;
0044 }
0045 
0046 int MvtxApplyHotDead::process_event(PHCompositeNode *topNode)
0047 {
0048 
0049   _timer.get()->restart();
0050 
0051   //------
0052   //--- get node containing the digitized hits
0053   //------
0054   hits_ = findNode::getClass<TrkrHitSetContainer>(topNode, "TrkrHitSetContainer");
0055   if (!hits_)
0056   {
0057     cout << PHWHERE << "ERROR: Can't find node TrkrHitSetContainer" << endl;
0058     return Fun4AllReturnCodes::ABORTRUN;
0059   }
0060 
0061   //------
0062   //-- mask pixels
0063   //------
0064   MvtxHitSetv1 *hitset = NULL;
0065   TrkrDefs::hitsetkey prevkey = TrkrDefs::HITSETKEYMAX;
0066   for ( ConstIterator iter = hdmap_.begin();
0067         iter != hdmap_.end();
0068         ++iter)
0069   {
0070 
0071     // get the new hitset if necessary
0072     if ( iter->first != prevkey )
0073     {
0074       prevkey = iter->first;
0075       hitset = static_cast<MvtxHitSetv1*>(hits_->FindHitSet(iter->first));
0076     }
0077 
0078     // check to make sure we have this hitset
0079     if ( hitset )
0080     {
0081       int retval = hitset->RemoveHit((iter->second).first, (iter->second).second);
0082 
0083       if ( retval > 0 && verbosity > 0)
0084       {
0085         cout << PHWHERE << " Successfully removed hit "
0086              << " key:0x" << hex << iter->first << dec
0087              << " col:" << (iter->second).first
0088              << " row:" << (iter->second).second
0089              << endl;
0090              hitset->identify();
0091       }
0092       else if ( verbosity > 1 )
0093       {
0094         cout << PHWHERE << " no hit found hit "
0095              << " key:0x" << hex << iter->first << dec
0096              << " col:" << (iter->second).first
0097              << " row:" << (iter->second).second
0098              << endl;
0099       }
0100 
0101     }
0102     else
0103     {
0104       if ( verbosity > 0 )
0105         cout << PHWHERE << " no TrkrHitSet found for key 0x" << hex << iter->first << dec << endl;
0106     }
0107   }
0108 
0109 
0110   //------
0111   //--- done
0112   //------
0113   _timer.get()->stop();
0114   return Fun4AllReturnCodes::EVENT_OK;
0115 }
0116 
0117 void MvtxApplyHotDead::ReadHotDeadFile()
0118 {
0119   if (verbosity > 0)
0120     cout << "Entering MvtxApplyHotDead::ReadHotDeadFile " << endl;
0121 
0122   //----------
0123   //--- Open file
0124   //----------
0125 
0126   // check for reasonable file name
0127   if ( hdfile_.length() < 2 )
0128     return;
0129 
0130   ifstream fin;
0131   fin.open(hdfile_.c_str());
0132   if ( fin.is_open() )
0133   {
0134     string line;
0135 
0136     MvtxDefUtil util;
0137 
0138     while ( getline(fin, line) )
0139     {
0140       int lyr, stave, chip, col, row;
0141       sscanf(line.c_str(), "%i %i %i %i %i", &lyr, &stave, &chip, &col, &row);
0142 
0143       // check validity
0144       if ( lyr < 0 || stave < 0 || chip < 0 || col < 0 || row < 0 )
0145       {
0146         cout << PHWHERE << "WARNING: skipping invalid entry: "
0147              << " lyr:" << lyr
0148              << " stave:" << stave
0149              << " chip:" << chip
0150              << " col:" << col
0151              << " row:" << row
0152              << endl;
0153       }
0154 
0155       // generate the hitsetkey
0156       TrkrDefs::hitsetkey key = util.GenHitSetKey(lyr, stave, chip);
0157 
0158       // add to the map
0159       hdmap_.insert(make_pair(key, make_pair(col, row)));
0160     }
0161     fin.close();
0162   }
0163   else
0164   {
0165     cout << PHWHERE << "ERROR: Can't open " << hdfile_ << ", will not mask any pixels." << endl;
0166   }
0167 
0168   return;
0169 }
0170 
0171 void MvtxApplyHotDead::PrintHotDeadMap(std::ostream& os) const
0172 {
0173   os << "=============================================================" << endl;
0174   os << "== " << PHWHERE << "==" << endl;
0175   os << "=============================================================" << endl;
0176 
0177   MvtxDefUtil util;
0178   for ( ConstIterator iter = hdmap_.begin();
0179         iter != hdmap_.end();
0180         ++iter)
0181   {
0182     os << " "
0183        << util.GetLayer(iter->first) << " "
0184        << util.GetStaveId(iter->first) << " "
0185        << util.GetChipId(iter->first) << " "
0186        << (iter->second).first << " "
0187        << (iter->second).second
0188        << endl;
0189   }
0190 
0191   os << "=============================================================" << endl;
0192 }
0193