Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MvtxPrototype2Align.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file MvtxPrototype2Align.cc
1 #include "MvtxPrototype2Align.h"
2 
3 #include <mvtx/MvtxDefs.h>
5 
8 
9 
11 #include <phool/PHCompositeNode.h>
12 #include <phool/PHIODataNode.h>
13 #include <phool/PHNodeIterator.h>
14 #include <phool/getClass.h>
15 #include <phool/recoConsts.h>
16 
17 #include <iostream>
18 #include <fstream>
19 #include <stdio.h>
20 
21 using namespace std;
22 
24  SubsysReco(name),
25  clusters_(NULL),
26  fdir_(""),
27  runnumber_(0),
28  apff_(true),
29  m_afname(""),
30  m_is_global(true),
31  _timer(PHTimeServer::get()->insert_new(name))
32 {
33 
34 }
35 
37 {
38  // get the run number
39  if ( apff_ )
40  {
42  runnumber_ = rc->get_IntFlag("RUNNUMBER");
43  cout << PHWHERE << " Runnumber: " << runnumber_ << endl;
45  }
46 
48 }
49 
51 {
52 
53  _timer.get()->restart();
54 
55  //------
56  //--- get cluster container
57  //------
58  clusters_ = findNode::getClass<TrkrClusterContainer>(topNode, "TRKR_CLUSTER");
59  if (!clusters_)
60  {
61  cout << PHWHERE << "ERROR: Can't find node TRKR_CLUSTER" << endl;
63  }
64 
65  //------
66  //-- shift clusters
67  //------
69  for ( TrkrClusterContainer::ConstIterator iter = clusrange.first;
70  iter != clusrange.second;
71  ++iter)
72  {
73 
74  // get the key and check if we need to realign this cluster
75  TrkrDefs::cluskey ckey = (iter->second)->getClusKey();
77  auto aligniter = alignmap_.find(hkey);
78 
79  if ( aligniter != alignmap_.end() )
80  {
81  // get a non-const pointer to the cluster
82  TrkrClusterv1* clus = static_cast<TrkrClusterv1*>(clusters_->findCluster(ckey));
83 
84  if ( Verbosity() > 1 )
85  {
86  cout << " applying alignment to " << endl;
87  clus->identify();
88  }
89 
90  // apply the alignment
91  clus->setX(clus->getX() - (aligniter->second).dx);//row and xaxis are oppositive
92  clus->setY(clus->getY() - (aligniter->second).dy);
93  clus->setZ(clus->getZ() - (aligniter->second).dz);
94 
95  if ( Verbosity() > 1 )
96  clus->identify();
97  }
98 
99  }
100 
101 
102  //------
103  //--- done
104  //------
105  _timer.get()->stop();
107 }
108 
109 
110 void MvtxPrototype2Align::AddAlignmentPar(TrkrDefs::hitsetkey key, double dx, double dy, double dz)
111 {
112 
113  // check that the misalignment doesn't already exist
114  auto iter = alignmap_.find(key);
115  if ( iter != alignmap_.end() )
116  {
117  cout << PHWHERE << " WARNING: overwriting existing misalignment for"
118  << " key:0x" << hex << key << dec << endl;
119 
120  (iter->second).dx = dx;
121  (iter->second).dy = dy;
122  (iter->second).dz = dz;
123  }
124  else
125  {
127  mis.dx = dx;
128  mis.dy = dy;
129  mis.dz = dz;
130 
131  alignmap_.insert(make_pair(key, mis));
132 
133  if ( Verbosity() > 0 )
134  {
135  cout << PHWHERE << " Added alignment pars:"
136  << " key:0x" << hex << key << dec
137  << " dx:" << dx
138  << " dy:" << dy
139  << " dz:" << dz
140  << endl;
141  }
142  }
143 
144 }
145 
146 
147 
149 {
150  os << "=============================================================" << endl;
151  os << "== " << PHWHERE << "==" << endl;
152  os << "=============================================================" << endl;
153 
154  for ( auto iter = alignmap_.begin();
155  iter != alignmap_.end();
156  ++iter)
157  {
158  os << " key:0x" << hex << iter->first << dec
159  << " dx:" << (iter->second).dx
160  << " dy:" << (iter->second).dy
161  << " dz:" << (iter->second).dz
162  << endl;
163  }
164 
165  os << "=============================================================" << endl;
166 }
167 
168 
170 {
171  string flname(fdir_);
172  if ( m_afname.empty() )
173  {
174  char fname[100];
175  sprintf(fname, "beamcenter_%08d.txt", runnumber_);
176  flname += fname;
177  }
178  else
179  {
180  flname += m_afname;
181  }
182  ifstream fin;
183  fin.open(flname);
184  if ( fin.is_open() )
185  {
186  cout << PHWHERE << " Reading alignment parameters from " << flname << endl;
187  //MvtxDefUtil util;
188 
189  string line;
190  // static bool is_first = true;
191  // float bc0_x = 0;
192  // float bc0_y = 0;
193  // float bc0_z = 0;
194  while ( getline(fin, line) )
195  {
196  int lyr, stave;
197  float bcx, bcy, bcz;
198 
199  sscanf(line.c_str(), "%d %d %f %f %f", &lyr, &stave, &bcx, &bcy, &bcz);
200 
201  // if ( is_first )
202  // {
203  // bc0_x = bcx;
204  // bc0_y = bcy;
205  // bc0_z = bcz;
206  // is_first = false;
207  // }
208 
209  // double dx = bc0_x - bcx;
210  // double dy = bc0_y - bcy;
211  // double dz = bc0_z - bcz;
212 
213  for ( int chip = 0; chip < 9; ++chip )
214  {
216  MvtxDefs::genHitSetKey(lyr, 0, chip),
217  double(bcx), double(bcy), double(bcz));
218  }
219  }
220  }
221  else
222  {
223  cout << PHWHERE << "ERROR: Unable to open file " << flname << endl;
224  return 1;
225  }
226 
227  if ( Verbosity() > 0 )
229 
230  return 0;
231 }