Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TpcLoadDistortionCorrection.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TpcLoadDistortionCorrection.cc
1 
9 
11 #include <phool/getClass.h>
12 #include <phool/PHCompositeNode.h>
13 #include <phool/PHDataNode.h>
14 
15 #include <TFile.h>
16 #include <TH1.h>
17 
18 namespace
19 {
20 
21  // print histogram
22  void print_histogram( TH1* h )
23  {
24 
25  std::cout << "TpcLoadDistortionCorrection::InitRun - name: " << h->GetName() << std::endl;
26  for( const auto& axis:{h->GetXaxis(), h->GetYaxis(), h->GetZaxis() } )
27  {
28  if( axis )
29  {
30  std::cout
31  << " " << axis->GetName()
32  << " bins: " << axis->GetNbins()
33  << " min: " << axis->GetXmin()
34  << " max: " << axis->GetXmax()
35  << std::endl;
36  }
37  }
38  std::cout << std::endl;
39  }
40 
41 } // namespace
42 
43 
44 //_____________________________________________________________________
46  SubsysReco( name)
47  {}
48 
49 //_____________________________________________________________________
51 {
52 
53  // look for distortion calibration object
54  PHNodeIterator iter(topNode);
55 
57  auto runNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "RUN"));
58  if (!runNode)
59  {
60  std::cout << "TpcLoadDistortionCorrection::InitRun - RUN Node missing, quitting" << std::endl;
62  }
63 
64  //create and populate the nodes for each distortion, if present:
65  for (int i=0;i<3;i++){
66 
67  if( !m_correction_in_use[i] ) continue;
68 
69  // get distortion correction object and create if not found
70  auto distortion_correction_object = findNode::getClass<TpcDistortionCorrectionContainer>( topNode, m_node_name[i] );
71  if( !distortion_correction_object )
72  {
73  std::cout << "TpcLoadDistortionCorrection::InitRun - creating TpcDistortionCorrectionContainer in node " << m_node_name[i] << std::endl;
74  distortion_correction_object = new TpcDistortionCorrectionContainer;
75  auto node = new PHDataNode<TpcDistortionCorrectionContainer>(distortion_correction_object, m_node_name[i]);
76  runNode->addNode(node);
77  }
78 
79  std::cout << "TpcLoadDistortionCorrection::InitRun - reading corrections from " << m_correction_filename[i] << std::endl;
80  auto distortion_tfile = TFile::Open( m_correction_filename[i].c_str());
81  if( !distortion_tfile && m_correction_in_use[i])
82  {
83  std::cout << "TpcLoadDistortionCorrection::InitRun - cannot open " << m_correction_filename[i] << std::endl;
84  exit(1);
85  }
86 
87  const std::array<const std::string,2> extension = {{ "_negz", "_posz" }};
88  for( int j =0; j < 2; ++j )
89  {
90  distortion_correction_object->m_hDPint[j] = dynamic_cast<TH1*>(distortion_tfile->Get(Form("hIntDistortionP%s", extension[j].c_str()))); assert( distortion_correction_object->m_hDPint[j] );
91  distortion_correction_object->m_hDRint[j] = dynamic_cast<TH1*>(distortion_tfile->Get(Form("hIntDistortionR%s", extension[j].c_str()))); assert( distortion_correction_object->m_hDRint[j] );
92  distortion_correction_object->m_hDZint[j] = dynamic_cast<TH1*>(distortion_tfile->Get(Form("hIntDistortionZ%s", extension[j].c_str()))); assert( distortion_correction_object->m_hDZint[j] );
93  }
94 
95  // assign correction object dimension from histograms dimention, assuming all histograms have the same
96  distortion_correction_object->dimensions = distortion_correction_object->m_hDPint[0]->GetDimension();
97 
98  // only dimensions 2 or 3 are supported
99  assert( distortion_correction_object->dimensions == 2 || distortion_correction_object->dimensions == 3 );
100 
101  if( Verbosity() )
102  {
103  for( const auto& h:{
104  distortion_correction_object->m_hDPint[0], distortion_correction_object->m_hDPint[1],
105  distortion_correction_object->m_hDRint[0], distortion_correction_object->m_hDRint[1],
106  distortion_correction_object->m_hDZint[0], distortion_correction_object->m_hDZint[1] } )
107  { print_histogram( h ); }
108  }
109 
110  }
112 }
113 
114 //_____________________________________________________________________