00001 #include "KalFitAlg/KalFitAlg.h"
00002 #include "KalFitAlg/KalFitTrack.h"
00003 #include "GaudiKernel/MsgStream.h"
00004 #include "GaudiKernel/AlgFactory.h"
00005 #include "GaudiKernel/ISvcLocator.h"
00006 #include "GaudiKernel/SmartDataPtr.h"
00007 #include "GaudiKernel/IDataProviderSvc.h"
00008 #include "GaudiKernel/PropertyMgr.h"
00009 #include "MdcGeomSvc/IMdcGeomSvc.h"
00010 #include <fstream>
00011
00012
00013
00014 IMdcGeomSvc* KalFitAlg::imdcGeomSvc_ = 0;
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00053
00054
00055
00056
00057
00058
00059
00060
00061
00063
00064
00065
00066
00067
00068
00069
00070
00071
00073
00074
00075
00076
00077
00078
00079
00080
00081
00083
00084
00085
00086
00087
00088
00089
00090
00091
00093
00094
00095
00096
00097
00098
00099
00100
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 void KalFitAlg::set_Mdc(void)
00115 {
00116 MdcGeomSvc * mdcGeomSvc = dynamic_cast<MdcGeomSvc* >(imdcGeomSvc_);
00117 if(! mdcGeomSvc) {
00118 std::cout<<"ERROR OCCUR when dynamic_cast in KalFitAlg2.cxx ..!!"<<std::endl;
00119 }
00120
00121 if(debug_ == 4) {
00122 cout << "KalFitAlg:: MDC initialisation " << std::endl;
00123 }
00124 _wire = NULL;
00125 _layer = NULL;
00126 _superLayer = NULL;
00127
00128 const int Nwire = mdcGeomSvc->getWireSize();
00129 const int Nlyr = mdcGeomSvc->getLayerSize();
00130 const int Nsup = mdcGeomSvc->getSuperLayerSize();
00131
00132 if (!Nwire || !Nlyr || !Nsup){
00133 cout << ".....MdcGeom Objects are missing !! " << std::endl;
00134 exit(-1);
00135 }
00136
00137 if (!_wire)
00138 _wire = (KalFitWire *) malloc((Nwire+1) * sizeof(KalFitWire));
00139 if (!_layer)
00140 _layer = (KalFitLayer_Mdc *) malloc(Nlyr * sizeof(KalFitLayer_Mdc));
00141 if (!_superLayer)
00142 _superLayer = (KalFitSuper_Mdc *) malloc(Nsup * sizeof(KalFitSuper_Mdc));
00143
00144 if (!_wire || !_layer || !_superLayer){
00145 std::cerr << "KalFitAlg::Cannot allocate geometries" << std::endl;
00146 std::cerr << "JOB will stop" << std::endl;
00147 exit(-1);
00148 }
00149
00150 int superLayerID = 0;
00151 int layerID = 0;
00152 int localLayerID = 0;
00153 int localWireID = 0;
00154 int localID = 0;
00155 int wireID;
00156
00157 MdcGeoLayer * layer_back = NULL;
00158 MdcGeoSuper * superLayer_back = NULL;
00159 int k = 0;
00160 int Nlayer[12];
00161 int Nlocal[12];
00162 int NlocalWireID[43];
00163
00164 for (wireID = 0;wireID <= Nwire; wireID++) {
00165 MdcGeoLayer * layer = (wireID==Nwire) ? NULL : mdcGeomSvc->Wire(wireID)->Lyr();
00166 if (layer != layer_back) {
00167 layer_back = layer;
00168 MdcGeoSuper * superLayer = (wireID==Nwire) ? NULL : mdcGeomSvc->Layer(layerID)->Sup();
00169 if (superLayer != superLayer_back) {
00170 superLayer_back = superLayer;
00171 Nlayer[k] = localLayerID;
00172 Nlocal[k] = localID;
00173 localLayerID = 0;
00174 k++;
00175 }
00176 NlocalWireID[layerID] = localWireID;
00177 localID = 0;
00178 localWireID = 0;
00179 layerID++;
00180 localLayerID++;
00181 }
00182 localID++;
00183 localWireID++;
00184 }
00185
00186 superLayerID = -1;
00187 layerID = -1;
00188 localLayerID = 0;
00189 localID = 0;
00190 layer_back = NULL;
00191 superLayer_back = NULL;
00192 for (wireID = 0;wireID < Nwire; wireID++) {
00193 MdcGeoLayer * layer = (wireID==Nwire) ?
00194 NULL : mdcGeomSvc->Wire(wireID)->Lyr();
00195 if (layer != layer_back){
00196 layer_back = layer;
00197 MdcGeoSuper * superLayer = (wireID==Nwire) ?
00198 NULL : mdcGeomSvc->Layer(layerID+1)->Sup();
00199 if (superLayer != superLayer_back){
00200 superLayer_back = superLayer;
00201
00202 superLayerID++;
00203 new(_superLayer+superLayerID) KalFitSuper_Mdc(wireID,
00204 Nlocal[superLayerID+1],
00205 layerID+1,
00206 Nlayer[superLayerID+1],
00207 superLayerID);
00208 localLayerID=0;
00209 }
00210
00211 layerID++;
00212 double slantWithSymbol = (mdcGeomSvc->Layer(layerID)->Slant())
00213 *(mdcGeomSvc->Layer(layerID)->Sup()->Type());
00214 new(_layer+layerID) KalFitLayer_Mdc(_superLayer[superLayerID],
00215 0.1*layer->Radius(), (layer->Slant())*(layer->Sup()->Type()),
00216 0.1*(layer->Length()/2),
00217 0.1*(-layer->Length()/2), layer->Offset(),
00218 layerID, localLayerID++ );
00219 localID = 0;
00220 }
00221
00222
00223 const MdcGeoWire * wire = (wireID==Nwire) ? NULL : mdcGeomSvc->Wire(wireID);
00224 HepPoint3D fwd(0.1*wire->Backward());
00225 HepPoint3D bck(0.1*wire->Forward());
00226
00227 if (superLayerID == 2 || superLayerID == 3 ||
00228 superLayerID == 4 || superLayerID == 9 ||
00229 superLayerID == 10) {
00230 new(_wire+wireID) KalFitWire(localID++,_layer[layerID],
00231 fwd,bck, _wire+Nwire,wire->Id(),0);
00232
00233 } else {
00234 new(_wire+wireID) KalFitWire(localID++,_layer[layerID],
00235 fwd,bck, _wire+Nwire,wire->Id(),1);
00236 }
00237 }
00238
00239
00240 new(_wire+Nwire) KalFitWire();
00241
00242 if (debug_ == 4) cout << "MDC geometry reading done" << std::endl;
00243
00244 return;
00245 }
00246
00247 void KalFitAlg::setCalibSvc_init()
00248 {
00249 IMdcCalibFunSvc* imdcCalibSvc;
00250 MsgStream log(msgSvc(), name());
00251 StatusCode sc = service ("MdcCalibFunSvc", imdcCalibSvc);
00252 m_mdcCalibFunSvc_ = dynamic_cast<MdcCalibFunSvc*>(imdcCalibSvc);
00253 if ( sc.isFailure() ){
00254 log << MSG::FATAL << "Could not load MdcCalibFunSvc!" << endreq;
00255 }
00256 KalFitTrack::setMdcCalibFunSvc( m_mdcCalibFunSvc_);
00257 }
00258
00259 void KalFitAlg::setGeomSvc_init()
00260 {
00261 IMdcGeomSvc* imdcGeomSvc;
00262 MsgStream log(msgSvc(), name());
00263 StatusCode sc = service ("MdcGeomSvc", imdcGeomSvc);
00264
00265 if ( sc.isFailure() ){
00266 log << MSG::FATAL << "Could not load MdcGeomSvc!" << endreq;
00267 }
00268 imdcGeomSvc_ = imdcGeomSvc;
00269
00270 KalFitTrack::setIMdcGeomSvc( imdcGeomSvc);
00271 }
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292