CFEL - ASG Software Suite  2.5.0
CASS
achimsorter_hex.cpp
Go to the documentation of this file.
1 //Copyright (C) 2008-2011 Lutz Foucar
2 
3 /**
4  * @file achimsorter_hex.cpp file contains class that uses achims resort routine
5  *
6  * @author Lutz Foucar
7  */
8 
9 #include <stdexcept>
10 #include <sstream>
11 #include <algorithm>
12 
13 #include "achimsorter_hex.h"
14 
15 #include "resort64c.h"
16 #include "cass_settings.h"
17 
18 using namespace cass::ACQIRIS;
19 using namespace std;
20 
21 namespace cass
22 {
23 namespace ACQIRIS
24 {
25 namespace AchimHex
26 {
27 /** extract times from signal producer
28  *
29  * extract the time values from the signal producer and puts it into
30  * the corrosponding tdc like array
31  *
32  * @param thePair container for tdc like array mapped to the corrosponding
33  * signalproducer.
34  *
35  * @author Lutz Foucar
36  */
37 void extactTimes(pair<SignalProducer*,vector<double> > & thePair)
38 {
39  vector<double> &tdcarray(thePair.second);
40  tdcarray.clear();
41  SignalProducer::signals_t &sigs(thePair.first->output());
42  SignalProducer::signals_t::const_iterator sigsIt(sigs.begin());
43  for (;sigsIt !=sigs.end(); ++sigsIt)
44  tdcarray.push_back((*sigsIt)[time]);
45 }
46 }//end namespace AchimHex
47 }//end namespace acqiris
48 }//end namespace cass
49 
50 
51 
52 
55  _sorter(new sort_class()),
56  _count(7,0),
57  _timesums(3,0)
58 {
59  _sorter->Cmcp = 0;
60  _sorter->Cu1 = 1;
61  _sorter->Cu2 = 2;
62  _sorter->Cv1 = 3;
63  _sorter->Cv2 = 4;
64  _sorter->Cw1 = 5;
65  _sorter->Cw2 = 6;
66  _sorter->count = &_count.front();
67  _sorter->TDC_resolution_ns = 0.1;
68  _sorter->tdc_array_row_length = 1000;
69  _sorter->dont_overwrite_original_data = true;
70  _sorter->use_pos_correction = false;
71  _sorter->common_start_mode = true;
72  _sorter->use_HEX = true;
73 
74  //this is needed to tell achims routine that we care for our own arrays//
75  for (size_t i=0;i<7;++i)
76  _sorter->tdc[i] = (double*)(0x1);
77 }
78 
80 {
81  for_each(_signals.begin(),_signals.end(),AchimHex::extactTimes);
82  //assign the tdc arrays and copy the number of found signals
83  for (size_t i(0); i<7;++i)
84  {
85  if (!_signals[i].second.empty())
86  _sorter->tdc[i] = &_signals[i].second.front();
87  _count[i] = _signals[i].second.size();
88  }
89  // shift all time sums to zero
90  _sorter->shift_sums(+1,_timesums[0],_timesums[1],_timesums[2]);
91  // shift layer w so that all center lines of the layers meet in one point
92  _sorter->shift_layer_w(+1,_wLayerOffset);
93  // shift all layers so that the position picture is centered around X=zero,Y=zero
94  _sorter->shift_position_origin(+1,_center.first,_center.second);
95  int32_t nbrOfRecHits = _sorter->sort();
96  //copy the reconstructed hits to our dethits//
97  for (int i(0);i<nbrOfRecHits;++i)
98  {
100  hit[x] = _sorter->output_hit_array[i]->x;
101  hit[y] = _sorter->output_hit_array[i]->y;
102  hit[t] = _sorter->output_hit_array[i]->time;
103  hit[method] = _sorter->output_hit_array[i]->method;
104  hits.push_back(hit);
105  }
106 
107  return hits;
108 }
109 
111 {
112  if(!d.isHex())
113  throw invalid_argument("HexSorter::loadSettings: Error The Hex-Sorter cannot work on '" +
114  d.name() + "' which is not a Hex Detector.");
115  _signals.clear();
116  _signals.push_back(make_pair(&d.mcp(),vector<double>()));
117  _signals.push_back(make_pair(&d.layers()['U'].wireends()['1'],vector<double>()));
118  _signals.push_back(make_pair(&d.layers()['U'].wireends()['2'],vector<double>()));
119  _signals.push_back(make_pair(&d.layers()['V'].wireends()['1'],vector<double>()));
120  _signals.push_back(make_pair(&d.layers()['V'].wireends()['2'],vector<double>()));
121  _signals.push_back(make_pair(&d.layers()['W'].wireends()['1'],vector<double>()));
122  _signals.push_back(make_pair(&d.layers()['W'].wireends()['2'],vector<double>()));
123 
124  /** @todo add the loading of the settings, make sure they are documented. */
125 
126  s.beginGroup("HexSorting");
127  _sorter->uncorrected_time_sum_half_width_u = s.value("TimeSumUWidth",0).toDouble();
128  _sorter->uncorrected_time_sum_half_width_v = s.value("TimeSumVWidth",0).toDouble();
129  _sorter->uncorrected_time_sum_half_width_w = s.value("TimeSumWWidth",0).toDouble();
130  _timesums[0] = s.value("TimeSumU",100).toDouble();
131  _timesums[1] = s.value("TimeSumV",100).toDouble();
132  _timesums[2] = s.value("TimeSumW",100).toDouble();
133  _sorter->max_runtime = s.value("MaxRuntime",130).toDouble();
134  _sorter->dead_time_anode = s.value("DeadTimeAnode",20).toDouble();
135  _sorter->dead_time_mcp = s.value("DeadTimeMCP",20).toDouble();
136  _sorter->MCP_radius = s.value("MCPRadius",88).toDouble();
137  _sorter->use_MCP = s.value("UseMCP",true).toBool();
138  _sorter->fu = s.value("ScalefactorU",1).toDouble();
139  _center = make_pair(s.value("CenterX",0).toDouble(),
140  s.value("CenterY",0).toDouble());
141 
142 
143  //the following settings can be retrieved from the calibration file
144  string settingsfilename (s.value("SettingsFilename").toString().toStdString());
145  QSettings hexsettings(QString::fromStdString(settingsfilename),
147  /** @todo check whether one can set the goup this way */
148  hexsettings.beginGroup(s.group());
149  _sorter->fv = hexsettings.value("ScalefactorV",1).toDouble();
150  _sorter->fw = hexsettings.value("ScalefactorW",1).toDouble();
151  _wLayerOffset = hexsettings.value("WLayerOffset",0).toDouble();
152  int size = hexsettings.beginReadArray("SumUCorrectionPoints");
153  _sorter->use_sum_correction = static_cast<bool>(size);
154  for (int i = 0; i< size; ++i)
155  {
156  hexsettings.setArrayIndex(i);
157  _sorter->
158  signal_corrector->
159  sum_corrector_U->
160  set_point(hexsettings.value("Position").toDouble(),
161  hexsettings.value("Correction").toDouble());
162  }
163  hexsettings.endArray();
164  size = hexsettings.beginReadArray("SumVCorrectionPoints");
165  for (int i = 0; i < size; ++i)
166  {
167  hexsettings.setArrayIndex(i);
168  _sorter->
169  signal_corrector->
170  sum_corrector_V->
171  set_point(hexsettings.value("Position").toDouble(),
172  hexsettings.value("Correction").toDouble());
173  }
174  hexsettings.endArray();
175  size = hexsettings.beginReadArray("SumWCorrectionPoints");
176  for (int i = 0; i < size; ++i)
177  {
178  hexsettings.setArrayIndex(i);
179  _sorter->
180  signal_corrector->
181  sum_corrector_W->
182  set_point(hexsettings.value("Position").toDouble(),
183  hexsettings.value("Correction").toDouble());
184  }
185  hexsettings.endArray();
186 
187  int error_code = _sorter->init_after_setting_parameters();
188  if (error_code != 0)
189  {
190  char error_text[500];
191  _sorter->get_error_text(error_code,500,error_text);
192  throw invalid_argument("HexSorter::loadSettings: Error '" + toString(error_code) +
193  "' while trying to initialize the sorter: '" + error_text + "'");
194  }
195 }
std::vector< double > detectorHit_t
define a detector hit
std::vector< int32_t > _count
counter array for achims routine
std::vector< signal_t > signals_t
void loadSettings(CASSSettings &s, DelaylineDetector &d)
load the detector analyzers settings from .ini file
std::vector< double > _timesums
the timesums
void extactTimes(pair< SignalProducer *, vector< double > > &thePair)
extract times from signal producer
Settings for CASS.
Definition: cass_settings.h:30
detectorHits_t & operator()(detectorHits_t &hits)
the function creating the detectorhit list
std::vector< detectorHit_t > detectorHits_t
define container for all detector hits
std::vector< std::pair< SignalProducer *, std::vector< double > > > _signals
container for tdc like arrays mapped to the corrosponding signalproducer
define which of the hitfinders defined above will be used as hit
STL namespace.
Average out the iShit status to get the avererage hits
things written only at end of run H5Dump ProcessorSummary size
SignalProducer & mcp()
retrieve the mcp
Definition: tof_detector.h:67
fromStdString(const std::string &str)
anodelayers_t & layers()
return the layers
std::tr1::shared_ptr< sort_class > _sorter
the instance of Achims routine
file contains class that uses achims resort routine
std::string toString(const Type &t)
convert any type to a string
Definition: cass.h:63
value(const QString &key, const QVariant &defaultValue=QVariant()
const std::string name() const
return the detector name
bool isHex() const
retrieve the anode type property
file contains specialized class that do the settings for cass
double _wLayerOffset
the w-layer offset
std::pair< double, double > _center
the center of the detector
beginGroup(const QString &prefix)
Base class for all detector analyzers.