Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MicromegasRawDataCalibration.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file MicromegasRawDataCalibration.cc
1 
8 #include "MicromegasDefs.h"
9 
10 #include <Event/Event.h>
11 #include <Event/EventTypes.h>
12 #include <Event/packet.h>
13 
15 
16 #include <phool/getClass.h>
17 #include <phool/PHCompositeNode.h>
18 
19 #include <TFile.h>
20 #include <TProfile.h>
21 
22 #include <cassert>
23 #include <fstream>
24 #include <memory>
25 
26 //_________________________________________________________
28  SubsysReco( name )
29 {}
30 
31 //_____________________________________________________________________
33 {
34  // histogram evaluation
36 }
37 
38 //____________________________________________________________________________..
41 
42 //___________________________________________________________________________
44 {
45 
46  // load relevant nodes
47  // PRDF node
48  auto event = findNode::getClass<Event>(topNode, "PRDF");
49  assert( event );
50 
51  // check event type
52  if(event->getEvtType() >= 8)
54 
55 
56  // loop over TPOT packets
57  for( const auto& packet_id:MicromegasDefs::m_packet_ids )
58  {
59  std::unique_ptr<Packet> packet( event->getPacket(packet_id) );
60  if( !packet )
61  {
62  // no data
63  if( Verbosity() )
64  { std::cout << "MicromegasRawDataCalibration::process_event - event contains no TPOT data" << std::endl; }
65  continue;
66  }
67 
68  // get number of datasets (also call waveforms)
69  const auto n_waveforms = packet->iValue(0, "NR_WF" );
70  if( Verbosity() )
71  { std::cout << "MicromegasRawDataCalibration::process_event - n_waveforms: " << n_waveforms << std::endl; }
72 
73  for( int i=0; i<n_waveforms; ++i )
74  {
75  auto channel = packet->iValue( i, "CHANNEL" );
76  int fee = packet->iValue(i, "FEE" );
77  int samples = packet->iValue( i, "SAMPLES" );
78  if( Verbosity() )
79  {
80  std::cout
81  << "MicromegasRawDataCalibration::process_event -"
82  << " waveform: " << i
83  << " fee: " << fee
84  << " channel: " << channel
85  << " samples: " << samples
86  << std::endl;
87  }
88 
89  // find relevant profile histogram
90  TProfile* profile = nullptr;
91  auto piter = m_profile_map.lower_bound( fee );
92  if( piter == m_profile_map.end() || fee < piter->first )
93  {
94  // create and insert
95  profile = new TProfile( Form( "h_adc_channel_%i", fee ), "ADC vs channel;channel;adc", MicromegasDefs::m_nchannels_fee, 0, MicromegasDefs::m_nchannels_fee );
96  profile->SetErrorOption( "s" );
97  m_profile_map.insert( piter, std::make_pair( fee, profile ) );
98  } else profile = piter->second;
99 
100  // fill
101  for( int is = std::max( m_sample_min,0 ); is < std::min( m_sample_max,samples ); ++ is )
102  { profile->Fill( channel, packet->iValue(i,is) ); }
103 
104  }
105  }
107 }
108 
109 //_____________________________________________________________________
111 {
112 
113  // write calibration data to ouput file
114  if( m_profile_map.empty() )
115  {
116  std::cout << "MicromegasRawDataCalibration::End - no data" << std::endl;
117  } else {
118 
119  // create calibration data object
120  MicromegasCalibrationData calibration_data;
121  for( const auto& [fee, profile]:m_profile_map )
122  {
123  for( int i = 0; i < profile->GetNbinsX(); ++ i )
124  {
125  const auto pedestal = profile->GetBinContent(i+1);
126  const auto rms = profile->GetBinError(i+1);
127  calibration_data.set_pedestal( fee, i, pedestal );
128  calibration_data.set_rms( fee, i, rms );
129  }
130  }
131  calibration_data.write( m_calibration_filename );
132  }
133 
135 }