Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MicromegasCombinedDataDecoder.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file MicromegasCombinedDataDecoder.cc
1 
7 #include "MicromegasDefs.h"
8 
11 
13 
14 #include <phool/getClass.h>
15 #include <phool/PHCompositeNode.h>
16 #include <phool/PHNodeIterator.h>
17 
18 #include <trackbase/TrkrHitv2.h>
19 #include <trackbase/TrkrHitSet.h>
21 
22 #include <algorithm>
23 #include <cassert>
24 #include <memory>
25 
26 //_________________________________________________________
28  SubsysReco( name )
29 {}
30 
31 //_____________________________________________________________________
33 {
34  // print configuration
35  std::cout
36  << "MicromegasCombinedDataDecoder::Init -"
37  << " m_calibration_filename: "
38  << (m_calibration_filename.empty() ? "unspecified":m_calibration_filename )
39  << std::endl;
40 
41  std::cout
42  << "MicromegasCombinedDataDecoder::Init -"
43  << " m_hot_channel_map_filename: "
44  << (m_hot_channel_map_filename.empty() ? "unspecified":m_hot_channel_map_filename)
45  << std::endl;
46 
47  std::cout << "MicromegasCombinedDataDecoder::Init - m_n_sigma: " << m_n_sigma << std::endl;
48  std::cout << "MicromegasCombinedDataDecoder::Init - m_min_adc: " << m_min_adc << std::endl;
49  std::cout << "MicromegasCombinedDataDecoder::Init - m_sample_min: " << m_sample_min << std::endl;
50  std::cout << "MicromegasCombinedDataDecoder::Init - m_sample_max: " << m_sample_max << std::endl;
51 
52  // read calibrations
54 
55  // read hot channels
56  if( !m_hot_channel_map_filename.empty() )
58 
60 }
61 
62 //____________________________________________________________________________..
64 {
65 
66  // get dst node
67  PHNodeIterator iter(topNode);
68  auto dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
69  if (!dstNode)
70  {
71  std::cout << "MicromegasCombinedDataDecoder::InitRun - DST Node missing, doing nothing." << std::endl;
72  exit(1);
73  }
74 
75  // create hitset container if needed
76  auto hitsetcontainer = findNode::getClass<TrkrHitSetContainer>(topNode, "TRKR_HITSET");
77  if (!hitsetcontainer)
78  {
79  std::cout << "MicromegasCombinedDataDecoder::InitRun - creating TRKR_HITSET." << std::endl;
80 
81  // find or create TRKR node
82  PHNodeIterator dstiter(dstNode);
83  auto trkrnode = dynamic_cast<PHCompositeNode *>(dstiter.findFirst("PHCompositeNode", "TRKR"));
84  if (!trkrnode)
85  {
86  trkrnode = new PHCompositeNode("TRKR");
87  dstNode->addNode(trkrnode);
88  }
89 
90  // create container and add to the tree
91  hitsetcontainer = new TrkrHitSetContainerv1;
92  auto newNode = new PHIODataNode<PHObject>(hitsetcontainer, "TRKR_HITSET", "PHObject");
93  trkrnode->addNode(newNode);
94  }
95 
97 
98 }
99 
100 //___________________________________________________________________________
102 {
103 
104  // load relevant nodes
105  // Get the TrkrHitSetContainer node
106  auto trkrhitsetcontainer = findNode::getClass<TrkrHitSetContainer>(topNode, "TRKR_HITSET");
107  assert(trkrhitsetcontainer);
108 
109  // load raw hits container
110  auto rawhitcontainer = findNode::getClass<MicromegasRawHitContainer>(topNode, m_rawhitnodename);
111  assert( rawhitcontainer );
112 
113  // loop over raw hits
114  if( Verbosity() )
115  { std::cout << "MicromegasCombinedDataDecoder::process_event - hits: " << rawhitcontainer->get_nhits() << std::endl; }
116 
117  int n_signal_hits = 0;
118 
119  bool first = true;
120  uint64_t first_lvl1_bco = 0;
121 
122  for( unsigned int ihit = 0; ihit < rawhitcontainer->get_nhits(); ++ihit )
123  {
124  const auto rawhit = rawhitcontainer->get_hit(ihit);
125  const auto packet_id = rawhit->get_packetid();
126 
127  if( first )
128  {
129  first = false;
130  first_lvl1_bco = rawhit->get_gtm_bco();
131  }
132 
133  // make sure packet is valid
135  {
136  std::cout << "MicromegasCombinedDataDecoder::process_event - invalid packet: " << packet_id << std::endl;
137  continue;
138  }
139 
140  const int fee = rawhit->get_fee();
141  const auto channel = rawhit->get_channel();
142  const int samples = rawhit->get_samples();
143 
144  // map fee and channel to physical hitsetid and physical strip
145  // get hitset key matching this fee
147  if( !hitsetkey ) continue;
148 
149  // get matching layer, tile, physical strip
150  int layer = int(TrkrDefs::getLayer(hitsetkey));
151  int tile = int( MicromegasDefs::getTileId( hitsetkey ));
152  int strip = m_mapping.get_physical_strip( fee, channel );
153  if( strip < 0 ) continue;
154 
155  // check agains hot channels
156  if(m_hot_channels.is_hot_channel(layer, tile, strip)) continue;
157 
158  // get channel rms and pedestal from calibration data
159  const double pedestal = m_calibration_data.get_pedestal( fee, channel );
160  const double rms = m_calibration_data.get_rms( fee, channel );
161 
162  // a rms of zero means the calibration has failed. the data is unusable
163  if( rms <= 0 ) continue;
164 
165  // loop over samples find maximum
166  std::vector<int> adc;
167  for( int is = std::max( m_sample_min,0 ); is < std::min( m_sample_max,samples ); ++ is )
168  { adc.push_back(rawhit->get_adc(is)); }
169 
170  if( adc.empty() ) continue;
171 
172  // get max adc value in range
173  /* TODO: use more advanced signal processing */
174  auto max_adc = *std::max_element( adc.begin(), adc.end() );
175 
176  // compare to hard min_adc value
177  if( max_adc < m_min_adc ) continue;
178 
179  // compare to threshold
180  if( max_adc < pedestal + m_n_sigma * rms ) continue;
181 
182  if( Verbosity() )
183  {
184  const auto bco = rawhit->get_gtm_bco();
185  std::cout << "MicromegasCombinedDataDecoder::process_event -"
186  << " bco: " << bco
187  << " layer: " << layer
188  << " tile: " << tile
189  << " channel: " << channel
190  << " strip: " << strip
191  << " adc: " << max_adc
192  << std::endl;
193  }
194 
195  // get matching hitset
196  const auto hitset_it = trkrhitsetcontainer->findOrAddHitSet(hitsetkey);
197 
198  // generate hit key
200 
201  // find existing hit, or create
202  auto hit = hitset_it->second->getHit(hitkey);
203  if( hit )
204  {
205  // std::cout << "MicromegasCombinedDataDecoder::process_event - duplicated hit, hitsetkey: " << hitsetkey << " strip: " << strip << std::endl;
206  continue;
207  }
208 
209  // create hit, assign adc and insert in hitset
210  hit = new TrkrHitv2;
211  hit->setAdc( max_adc );
212  hitset_it->second->addHitSpecificKey(hitkey, hit);
213 
214  // increment counter
216  ++n_signal_hits;
217  }
218 
219  if( Verbosity() )
220  { std::cout << "MicromegasCombinedDataDecoder::process_event - BCO: " << first_lvl1_bco << " n_signal_hits: " << n_signal_hits << std::endl; }
221 
223 }
224 
225 //_____________________________________________________________________
227 {
228  // if( Verbosity() )
229  {
230  for( const auto& [hitsetkey, count]:m_hitcounts )
231  { std::cout << "MicromegasCombinedDataDecoder::End - hitsetkey: " << hitsetkey << ", count: " << count << std::endl; }
232  }
233 
235 }