Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MvtxApplyHotDead.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file MvtxApplyHotDead.C
1 #include "MvtxApplyHotDead.h"
2 
3 #include "mvtx/MvtxDefUtil.h"
4 #include "mvtx/MvtxHitSetv1.h"
5 
10 
11 
13 #include <phool/PHCompositeNode.h>
14 #include <phool/PHIODataNode.h>
15 #include <phool/PHNodeIterator.h>
16 #include <phool/getClass.h>
21 #include <g4detectors/PHG4CylinderGeom_MAPS.h>
22 #include <g4detectors/PHG4CylinderGeom_Siladders.h>
23 #include <g4detectors/PHG4Cell.h>
25 
26 #include <iostream>
27 #include <fstream>
28 #include <stdio.h>
29 
30 using namespace std;
31 
33  SubsysReco(name),
34  hits_(NULL),
35  hdfile_(file),
36  _timer(PHTimeServer::get()->insert_new(name))
37 {
39 }
40 
42 {
44 }
45 
47 {
48 
49  _timer.get()->restart();
50 
51  //------
52  //--- get node containing the digitized hits
53  //------
54  hits_ = findNode::getClass<TrkrHitSetContainer>(topNode, "TrkrHitSetContainer");
55  if (!hits_)
56  {
57  cout << PHWHERE << "ERROR: Can't find node TrkrHitSetContainer" << endl;
59  }
60 
61  //------
62  //-- mask pixels
63  //------
64  MvtxHitSetv1 *hitset = NULL;
65  TrkrDefs::hitsetkey prevkey = TrkrDefs::HITSETKEYMAX;
66  for ( ConstIterator iter = hdmap_.begin();
67  iter != hdmap_.end();
68  ++iter)
69  {
70 
71  // get the new hitset if necessary
72  if ( iter->first != prevkey )
73  {
74  prevkey = iter->first;
75  hitset = static_cast<MvtxHitSetv1*>(hits_->FindHitSet(iter->first));
76  }
77 
78  // check to make sure we have this hitset
79  if ( hitset )
80  {
81  int retval = hitset->RemoveHit((iter->second).first, (iter->second).second);
82 
83  if ( retval > 0 && verbosity > 0)
84  {
85  cout << PHWHERE << " Successfully removed hit "
86  << " key:0x" << hex << iter->first << dec
87  << " col:" << (iter->second).first
88  << " row:" << (iter->second).second
89  << endl;
90  hitset->identify();
91  }
92  else if ( verbosity > 1 )
93  {
94  cout << PHWHERE << " no hit found hit "
95  << " key:0x" << hex << iter->first << dec
96  << " col:" << (iter->second).first
97  << " row:" << (iter->second).second
98  << endl;
99  }
100 
101  }
102  else
103  {
104  if ( verbosity > 0 )
105  cout << PHWHERE << " no TrkrHitSet found for key 0x" << hex << iter->first << dec << endl;
106  }
107  }
108 
109 
110  //------
111  //--- done
112  //------
113  _timer.get()->stop();
115 }
116 
118 {
119  if (verbosity > 0)
120  cout << "Entering MvtxApplyHotDead::ReadHotDeadFile " << endl;
121 
122  //----------
123  //--- Open file
124  //----------
125 
126  // check for reasonable file name
127  if ( hdfile_.length() < 2 )
128  return;
129 
130  ifstream fin;
131  fin.open(hdfile_.c_str());
132  if ( fin.is_open() )
133  {
134  string line;
135 
136  MvtxDefUtil util;
137 
138  while ( getline(fin, line) )
139  {
140  int lyr, stave, chip, col, row;
141  sscanf(line.c_str(), "%i %i %i %i %i", &lyr, &stave, &chip, &col, &row);
142 
143  // check validity
144  if ( lyr < 0 || stave < 0 || chip < 0 || col < 0 || row < 0 )
145  {
146  cout << PHWHERE << "WARNING: skipping invalid entry: "
147  << " lyr:" << lyr
148  << " stave:" << stave
149  << " chip:" << chip
150  << " col:" << col
151  << " row:" << row
152  << endl;
153  }
154 
155  // generate the hitsetkey
156  TrkrDefs::hitsetkey key = util.GenHitSetKey(lyr, stave, chip);
157 
158  // add to the map
159  hdmap_.insert(make_pair(key, make_pair(col, row)));
160  }
161  fin.close();
162  }
163  else
164  {
165  cout << PHWHERE << "ERROR: Can't open " << hdfile_ << ", will not mask any pixels." << endl;
166  }
167 
168  return;
169 }
170 
171 void MvtxApplyHotDead::PrintHotDeadMap(std::ostream& os) const
172 {
173  os << "=============================================================" << endl;
174  os << "== " << PHWHERE << "==" << endl;
175  os << "=============================================================" << endl;
176 
177  MvtxDefUtil util;
178  for ( ConstIterator iter = hdmap_.begin();
179  iter != hdmap_.end();
180  ++iter)
181  {
182  os << " "
183  << util.GetLayer(iter->first) << " "
184  << util.GetStaveId(iter->first) << " "
185  << util.GetChipId(iter->first) << " "
186  << (iter->second).first << " "
187  << (iter->second).second
188  << endl;
189  }
190 
191  os << "=============================================================" << endl;
192 }
193