00001
00002
00003
00004 #include "TdSiData.h"
00005
00006 #include "instrument/SiTracker.h"
00007 #include <algorithm>
00008 using namespace std;
00009
00010 class TdSiData::Strip {
00011 private:
00012 friend class TdSiData;
00013
00014 public:
00015 Strip () {}
00016
00017 private:
00018 Strip (Point p, Id m, unsigned int n, unsigned int t = 0)
00019 : stripIndex(n), stripType(t), pos(p), module(m)
00020 {}
00021
00022 unsigned int stripIndex;
00023 unsigned int stripType;
00024 Point pos;
00025 Id module;
00026 };
00027
00028
00029 TdSiData::TdSiData ()
00030 {
00031 for(int i = 0; i < SiTracker::numTrays(); i++) {
00032 xLayers.push_back(-1);
00033 yLayers.push_back(-1);
00034 xhitList.push_back(new vector<Strip>);
00035 yhitList.push_back(new vector<Strip>);
00036 }
00037 m_total_hits=0;
00038 }
00039
00040 TdSiData::TdSiData (unsigned int n)
00041 {
00042 for(unsigned i=0; i<n; i++) {
00043 xLayers.push_back(-1);
00044 yLayers.push_back(-1);
00045 xhitList.push_back(new vector<Strip>);
00046 yhitList.push_back(new vector<Strip>);
00047 }
00048 }
00049
00055 TdSiData::TdSiData ( TdSiData* copy, unsigned int n)
00056 {
00057
00058 }
00059
00060 TdSiData::~TdSiData ()
00061 {
00062 clear();
00063 for(unsigned i=0; i<xhitList.size(); i++) {
00064 delete xhitList[i];
00065 delete yhitList[i];
00066 }
00067
00068 }
00069
00070
00071 const SiData::Id& TdSiData::moduleId (enum TdSiData::Axis a,
00072 unsigned int tray,
00073 unsigned int n ) const
00074 {
00075 return a==X? (*xhitList[tray])[n].module
00076 : (*yhitList[tray])[n].module;
00077 }
00078
00079 void TdSiData::load (const SiDetector& plane, idents::ModuleId moduleId)
00080 {
00081
00082
00083
00084 CoordTransform T
00085 = plane.localToGlobal();
00086
00087
00088 Vector a(1,0,0),b(1,0,0); a.transform(T);
00089 double rot = a*b;
00090 Axis axis = (rot>0.5)? X : Y;
00091 Point p(0,0,0); p.transform(T);
00092 double z = p.z();
00093
00094
00095
00096 int tray_nummax = SiTracker::numTrays() - 2;
00097 int layer = static_cast<int>(((z - SiTracker::zFirstPlane())/SiTracker::traySpacing()) + 0.5);
00098 layer = layer < 0 ? 0 : layer;
00099 layer = layer > tray_nummax ? tray_nummax : layer;
00100
00101 int tray = tray_nummax - layer;
00102 if (axis == X) {xLayers[tray] = layer;}
00103 else {yLayers[tray] = layer;}
00104
00105
00106 for( SiDetector::const_iterator it3=plane.begin();
00107 it3!=plane.end(); ++it3) {
00108 int wire_num = (*it3).index();
00109 int wire_typ = (*it3).noise();
00110
00111
00112
00113 Point p = Point(SiDetector::localX(wire_num),0,0);
00114 p.transform(T);
00115
00116
00117 if( axis == X) {
00118 xhitList[tray]->push_back(
00119 Strip(p, moduleId, wire_num, wire_typ));
00120 } else {
00121 yhitList[tray]->push_back(
00122 Strip(p, moduleId, wire_num, wire_typ));
00123 }
00124 m_total_hits++;
00125 }
00126 }
00127
00128 void TdSiData::clear () {
00129 for(unsigned i=0; i<xhitList.size(); i++) {
00130 xLayers[i] = -1;
00131 xhitList[i]->clear();
00132 yLayers[i] = -1;
00133 yhitList[i]->clear();
00134 }
00135 m_total_hits=0;
00136 }
00137
00138 int TdSiData::nTrays (enum TdSiData::Axis a) const
00139 {
00140 return a == X ? xhitList.size() : yhitList.size() ;
00141
00142 }
00143
00144 int TdSiData::nHits (enum TdSiData::Axis a, int tray) const
00145 {
00146 int numHits = xhitList[tray]->size();
00147
00148 if (a != X) numHits = yhitList[tray]->size();
00149
00150 return numHits;
00151 }
00152
00153 int TdSiData::layerNum (enum TdSiData::Axis a, int tray) const
00154 {
00155 int layer = xLayers[tray];
00156
00157 if (a != X) layer = yLayers[tray];
00158
00159 return layer;
00160 }
00161
00162 Point TdSiData::hit (enum TdSiData::Axis a,
00163 unsigned int tray,
00164 unsigned int n ) const
00165 {
00166 return a==X? (*xhitList[tray])[n].pos
00167 : (*yhitList[tray])[n].pos;
00168 }
00169
00170 unsigned int TdSiData::hitId (enum TdSiData::Axis a,
00171 unsigned int tray,
00172 unsigned int n ) const
00173 {
00174 return a==X? (*xhitList[tray])[n].stripIndex
00175 : (*yhitList[tray])[n].stripIndex;
00176 }
00177 #if 0
00178 unsigned int TdSiData::hitType (enum TdSiData::Axis a,
00179 unsigned int tray,
00180 unsigned int n ) const
00181 {
00182 return a==X? (*xhitList[tray])[n].stripType
00183 : (*yhitList[tray])[n].stripType;
00184 }
00185 #endif
00186 int TdSiData::totalHits () const
00187 {
00188 return m_total_hits;
00189 }
00190
00191
00192 void TdSiData::printOn (ostream& cout) const
00193 {
00194 unsigned tray, i;
00195 cout << "\nTdSiData:\n";
00196 for(tray=0; tray < xhitList.size() && tray < yhitList.size(); tray++)
00197 {
00198 unsigned nx= nHits(X,tray),
00199 ny= nHits(Y,tray);
00200 if( nx==0 && ny==0 ) continue;
00201 cout << tray << "X";
00202 for( i =0; i<nx; i++)
00203 cout << '\t'<< hit(X,tray,i)
00204
00205 << '\n';
00206 cout << tray << "Y";
00207 for( i =0; i<ny; i++)
00208 cout << '\t'<< hit(Y,tray,i)
00209
00210 << '\n';
00211 }
00212 return;
00213 }
00214
00215