3#include "GaudiKernel/Kernel.h"
4#include "GaudiKernel/IInterface.h"
5#include "GaudiKernel/StatusCode.h"
7#include "GaudiKernel/SvcFactory.h"
8#include "GaudiKernel/MsgStream.h"
9#include "GaudiKernel/SmartDataPtr.h"
10#include "GaudiKernel/DataSvc.h"
12#include "GaudiKernel/IIncidentSvc.h"
13#include "GaudiKernel/Incident.h"
14#include "GaudiKernel/IIncidentListener.h"
18#include "CLHEP/Vector/ThreeVector.h"
32using CLHEP::Hep3Vector;
40 geosvc(0),Service (name, svcloc) {
41 declareProperty(
"Run",m_run=1);
42 declareProperty(
"init",m_init=1);
43 declareProperty(
"par_flag",m_par_flag=0);
44 declareProperty(
"Debug",m_debug=
false);
45 declareProperty(
"DebugI",m_debug_i=1);
46 declareProperty(
"DebugJ",m_debug_j=1);
47 m_initConstFlg =
false;
56 if( IID_IDedxCorrecSvc.versionMatch(riid) ){
59 return Service::queryInterface(riid, ppvInterface);
61 return StatusCode::SUCCESS;
66 MsgStream log(messageService(), name());
67 log << MSG::INFO << name() <<
"DedxCorrecSvc::initialize()" << endreq;
69 StatusCode sc = Service::initialize();
70 if( sc.isFailure() )
return sc;
73 sc = service(
"IncidentSvc", incsvc);
77 incsvc -> addListener(
this,
"NewRun", priority);
80 StatusCode scgeo = service(
"MdcGeomSvc", geosvc);
81 if(scgeo.isFailure() ) {
82 log << MSG::ERROR <<
"GeoSvc failing!!!!!!!" << endreq;
86 StatusCode scmgn = service (
"MagneticFieldSvc",m_pIMF);
87 if(scmgn!=StatusCode::SUCCESS) {
88 log << MSG::ERROR <<
"Unable to open Magnetic field service"<<endreq;
91 return StatusCode::SUCCESS;
96 MsgStream log(messageService(), name());
97 log << MSG::INFO << name() <<
"DedxCorrecSvc::finalize()" << endreq;
98 return StatusCode::SUCCESS;
103 MsgStream log( messageService(), name() );
104 log << MSG::DEBUG <<
"handle: " << inc.type() << endreq;
106 if ( inc.type() ==
"NewRun" ){
107 log << MSG::DEBUG <<
"New Run" << endreq;
109 if( ! m_initConstFlg )
111 if( m_init == 0 ) { init_param(); }
112 else if( m_init ==1 ) { init_param_svc(); }
122 if(nbin!=80)
return x;
123 double m_absx(fabs(
x));
124 double m_charge(
x/m_absx);
125 if(m_absx>0.925 && m_absx<=0.950)
return 0.9283*m_charge;
126 if(m_absx>0.900 && m_absx<=0.925)
return 0.9115*m_charge;
127 if(m_absx>0.875 && m_absx<=0.900)
return 0.8877*m_charge;
128 if(m_absx>0.850 && m_absx<=0.875)
return 0.8634*m_charge;
129 if(m_absx>0.825 && m_absx<=0.850)
return 0.8460*m_charge;
130 if(m_absx>0.800 && m_absx<=0.825)
return 0.8089*m_charge;
134DedxCorrecSvc::init_param_svc() {
136 MsgStream log(messageService(), name());
137 IDataProviderSvc* pCalibDataSvc;
138 StatusCode sc = service(
"CalibDataSvc", pCalibDataSvc,
true);
139 if ( !sc.isSuccess() ) {
141 <<
"Could not get IDataProviderSvc interface of CalibXmlCnvSvc"
146 <<
"Retrieved IDataProviderSvc interface of CalibXmlCnvSvc"
153 std::string fullPath =
"/Calib/DedxCal";
155 SmartDataPtr<CalibData::DedxCalibData>
test(pCalibDataSvc, fullPath);
158 N_run =
test->getrunNO();
160 cout<<
"N_run = "<<N_run<<endl;
161 for(
int j=0;j<100000;j++)
167 m_rung[i][j] =
test->getrung(i,j);
168 if(i==2 && m_rung[2][j]>run_temp) run_temp = m_rung[2][j];
176 m_rung[2][j] = run_temp;
179 m_rung[5][j] = 1000000000;
223 for(
int i=0;i<4;i++) {
224 for(
int j=0;j<43;j++) {
225 m_ddg[i][j] =
test->getddg(i,j);
226 m_ggs[i][j] =
test->getggs(i,j);
227 m_zdep[i][j] =
test->getzdep(i,j);
236 m_dedx_gain =
test->getgain();
237 std::cout<<
"gain="<<m_dedx_gain<<
"\n";
239 m_dedx_resol =
test->getresol();
240 std::cout<<
"resol="<<m_dedx_resol<<
"\n";
242 for(
int i=0;i<43;i++) {
243 m_layer_g[i] =
test -> getlayerg(i);
244 if(m_layer_g[i]>2.0 || m_layer_g[i]<0.5) m_layer_g[i] =1;
260 for(
int i=0;i<6796;i++) {
261 m_wire_g[i] =
test -> getwireg(i);
271 for(
int i=0;i<6796;i++) {
274 for(
int j=0; j<25; j++){
275 if( i == dead_wire[kk][j] )
304 for(
int i=0; i<nbin; i++){
305 cos.push_back(
test -> get_costheta(i));
307 for(
int i=0;i<nbin-1;i++){
312 double x1=-1.00+(0.5+i)*(2.00/nbin);
314 double x2=-1.00+(0.5+i+1)*(2.00/nbin);
317 if(fabs(x1)>0.8) x1 =
f_larcos(x1, nbin);
318 if(fabs(x2)>0.8) x2 =
f_larcos(x2, nbin);
325 double x1=-1.00+(0.5+i-1)*(2.00/nbin);
327 double x2=-1.00+(0.5+i)*(2.00/nbin);
330 if(fabs(x1)>0.8) x1 =
f_larcos(x1, nbin);
331 if(fabs(x2)>0.8) x2 =
f_larcos(x2, nbin);
340 if(
cos[i-1]>0.0001 &&
cos[i+1]>0.0001){
341 double x1=-1.00+(0.5+i-1)*(2.00/nbin);
343 double x2=-1.00+(0.5+i+1)*(2.00/nbin);
346 if(fabs(x1)>0.8) x1 =
f_larcos(x1, nbin);
347 if(fabs(x2)>0.8) x2 =
f_larcos(x2, nbin);
385 for(
int i=0; i<35; i++){
386 xbin.push_back(
test ->get_t0(i));
387 ybin.push_back(
test ->get_dedx(i));
390 for(
int i=0;i<nbin-1;i++){
400 b=(y1*x2-y2*x1)/(x2-x1);
409 b=(y1*x2-y2*x1)/(x2-x1);
415 if(ybin[i-1]>0 && ybin[i+1]>0){
421 b=(y1*x2-y2*x1)/(x2-x1);
469 double docaeangle_gain[n];
470 double docaeangle_chisq[n];
471 double docaeangle_entries[n];
473 for(
int i=0; i<n; i++){
475 docaeangle_gain[i] =
test -> get_out_gain(i);
476 docaeangle_chisq[i] =
test -> get_out_chi(i);
477 docaeangle_entries[i] =
test -> get_out_hits(i);
478 int Id_Doca_temp =
test -> get_id_doca(i);
479 int Ip_Eangle_temp =
test -> get_ip_eangle(i);
480 m_docaeangle[Id_Doca_temp][Ip_Eangle_temp] = docaeangle_gain[i];
481 if(m_debug && (Id_Doca_temp==m_debug_i) && (Ip_Eangle_temp==m_debug_j)) std::cout<<
"docaeangle_gain["<<Id_Doca_temp<<
"]["<<Ip_Eangle_temp<<
"]="<<m_docaeangle[m_debug_i][m_debug_j] << std::endl;
488 int onedsize=
test->get_enanglesize();
490 for(
int i=0; i< onedsize; i++){
491 m_venangle.push_back(
test->get_enangle(i));
506 const int hadronNo=
test -> get_hadronNo();
508 m_alpha=
test -> get_hadron(0);
510 m_gamma=
test -> get_hadron(1);
512 m_delta=
test -> get_hadron(2);
514 m_power=
test -> get_hadron(3);
516 m_ratio=
test -> get_hadron(4);
536 if( m_wire_g[wireid] > 0 ){
537 double ch_dedx = (ex/m_wire_g[wireid])*m_valid[wireid];
540 else if( m_wire_g[wireid] == 0 ){
552 if(m_par_flag == 1) {
553 dedx_ggs = m_ggs[0][layer] + m_ggs[1][layer]*
costheta +
555 }
else if(m_par_flag == 0) {
556 dedx_ggs = m_ggs[0][layer] + m_ggs[1][layer]*T1(
costheta) +
560 dedx_ggs = dedx/dedx_ggs;
561 if(dedx_ggs>0.0)
return dedx_ggs;
573 const int nbin=cos_k.size()+1;
574 const double step=2.00/nbin;
575 int n= (int)((
costheta+1.00-0.5*step)/step);
580 dedx_cos=cos_k[n-1]*
costheta+cos_b[n-1];
582 dedx_cos=cos_k[n+1]*
costheta+cos_b[n+1];
584 dedx_cos=cos_k[n]*
costheta+cos_b[n];
599 dedx_cos=cos_k[n]*
costheta+cos_b[n];
601 else if(costheta<-0.80 && costheta>-0.95){
608 dedx_cos=cos_k[n]*
costheta+cos_b[n];
613 dedx_cos = dedx/dedx_cos;
624 const int nbin=t0_k.size()+1;
626 cout<<
"there should be 35 bins for t0 correction, check it!"<<endl;
633 else if(t0>=610 && t0<1190){
634 n=(int)( (t0-610.0)/20.0 ) + 2;
636 else if(t0>=1190 && t0<1225)
638 else if(t0>=1225 && t0<1275)
643 dedx_t0=t0_k[n]*t0+t0_b[n];
646 dedx_t0 = dedx/dedx_t0;
662 if( m_layer_g[layid] > 0 ){
663 double ch_dedx = dedx/m_layer_g[layid];
666 else if( m_layer_g[layid] == 0 ){
680 for(
int j=0;j<100000;j++) {
682 if((runNO == m_rung[2][j]) && (evtNO >= m_rung[4][j]) && (evtNO <= m_rung[5][j])) {
683 dedx_rung = dedx/m_rung[0][j];
691 cout<<
"Warning!!! in DedxCorrecSvc::RungCorrec(): no rungain to "<<runNO<<endl;
704 if(m_par_flag == 1) {
705 dedx_ddg = m_ddg[0][layer] + m_ddg[1][layer]*dd +
706 m_ddg[2][layer]*dd*dd + m_ddg[3][layer]*pow(dd,3);
707 }
else if(m_par_flag == 0) {
708 dedx_ddg = m_ddg[0][layer] + m_ddg[1][layer]*T1(dd) +
709 m_ddg[2][layer]*T2(dd) + m_ddg[3][layer]*T3(dd);
712 dedx_ddg = dedx/dedx_ddg;
713 if (dedx_ddg>0.0)
return dedx_ddg;
733 if(eangle>-0.25 && eangle<0.25){
734 double stepsize= 0.5/m_venangle.size();
735 int nsize= m_venangle.size();
738 double y1=0,y2=0,x1=0,x2=0;
740 if(eangle>=-0.25+0.5*stepsize && eangle<=0.25-0.5*stepsize){
741 int bin = (int)( (eangle-(-0.25+0.5*stepsize))/stepsize);
743 x1=-0.25+0.5*stepsize+
bin*stepsize;
744 y2=m_venangle[
bin+1];
745 x2=-0.25+1.5*stepsize+
bin*stepsize;
747 else if(eangle<=-0.25+0.5*stepsize){
749 x1=-0.25+0.5*stepsize;
751 x2=-0.25+1.5*stepsize;
753 else if( eangle>=0.25-0.5*stepsize){
754 y1=m_venangle[nsize-2];
755 x1=0.25-1.5*stepsize;
756 y2=m_venangle[nsize-1];
757 x2=0.25-0.5*stepsize;
759 double kcof= (y2-y1)/(x2-x1);
760 double bcof= y1-kcof*x1;
761 double ratio = kcof*eangle+bcof;
773 if(m_par_flag == 1) {
774 dedx_zdep = m_zdep[0][layer] + m_zdep[1][layer]*z +
775 m_zdep[2][layer]*z*z + m_zdep[3][layer]*pow(z,3);
776 }
else if(m_par_flag == 0) {
777 dedx_zdep = m_zdep[0][layer] + m_zdep[1][layer]*T1(z) +
778 m_zdep[2][layer]*T2(z) + m_zdep[3][layer]*T3(z);
780 dedx_zdep = dedx/dedx_zdep;
781 if (dedx_zdep>0.0)
return dedx_zdep;
790 if(m_debug) cout<<
"DedxCorrecSvc::DocaSinCorrec"<<endl;
793 if(eangle>0.25) eangle = eangle -0.5;
794 else if(eangle < -0.25) eangle = eangle +0.5;
797 doca = doca/doca_norm[layer];
798 iDoca =(Int_t)floor((doca-
Out_DocaMin)/Out_Stepdoca);
803 if(iDoca<0) iDoca = 0;
804 if(m_debug) cout<<
"iDoca : "<<iDoca<<
" doca : "<<doca<<
" Out_DocaMin : "<<
Out_DocaMin<<
" Out_Stepdoca : "<<Out_Stepdoca<<endl;
807 for(
int i =0; i<14; i++){
809 if(eangle <Eangle_value_cut[i] || eangle > Eangle_value_cut[i+1])
continue;
810 else if(eangle>= Eangle_value_cut[i] && eangle < Eangle_value_cut[i+1]) {
811 for(
int k =0; k<i; k++){
812 iEAng+= Eangle_cut_bin[k];
814 double eangle_bin_cut_step = (Eangle_value_cut[i+1] - Eangle_value_cut[i])/Eangle_cut_bin[i];
815 int temp_bin = int((eangle-Eangle_value_cut[i])/eangle_bin_cut_step);
820 if(m_docaeangle[iDoca][iEAng]>0) {
821 if(m_debug && (iDoca==m_debug_i) && (iEAng==m_debug_j))
822 cout <<
"doca: " << doca <<
" eang" << eangle <<
" dedx before: " << dedx << endl;
823 dedx = dedx/m_docaeangle[iDoca][iEAng];
824 if(m_debug && (iDoca==m_debug_i) && (iEAng==m_debug_j))
825 cout <<
"gain: " << m_docaeangle[iDoca][iEAng] <<
" dedx after: " << dedx << endl;
837 if( m_mdcg_flag == 0 )
return dedx;
838 double calib_ex = dedx;
839 if( m_dedx_gain > 0 ) calib_ex /= m_dedx_gain;
849 if( m_rung_flag == 0 && m_wireg_flag == 0 && m_ddg_flag == 0
850 && m_layerg_flag == 0 && m_zdep_flag == 0 &&
851 m_ggs_flag == 0)
return adc;
852 adc = m_valid[ser]*m_wire_g[ser]*adc;
856 double correct1_ex , correct2_ex, correct3_ex, correct4_ex, correct5_ex;
869 correct2_ex =correct1_ex;
875 correct3_ex =correct2_ex;
879 correct4_ex =
ZdepCorrec( lyr, z, correct3_ex );
882 correct4_ex = correct3_ex;
889 correct5_ex = correct4_ex;
899 if( m_zdep_flag == 0 && m_ggs_flag == 0 )
return ex;
910 if( m_mdcg_flag == 0 )
return dedx;
912 double calib_ex = dedx;
914 double run_const = m_dedx_gain;
915 if( run_const > 0 && m_mdcg_flag != 0 ) calib_ex /= run_const;
923DedxCorrecSvc::StandardCorrec(
int runFlag,
int ntpFlag,
int runNO,
int evtNO,
double pathl,
int wid,
int layid,
double adc,
double dd,
double eangle,
double z,
double costheta )
const {
932 if( runNO<0 )
return ex;
936 if( ntpFlag ==0)
return ex;
938 if( m_rung_flag == 0 && m_wireg_flag == 0 && m_dcasin_flag==0 && m_ddg_flag == 0
939 && m_layerg_flag == 0 && m_zdep_flag == 0 &&
940 m_ggs_flag == 0)
return ex;
957 if(m_enta_flag && runFlag>=3){
997DedxCorrecSvc::StandardHitCorrec(
int calib_rec_Flag,
int runFlag,
int ntpFlag,
int runNO,
int evtNO,
double pathl,
int wid,
int layid,
double adc,
double dd,
double eangle,
double costheta )
const {
998 if(m_debug) cout<<
"DedxCorrecSvc::StandardHitCorrec"<<endl;
1007 if( runNO<0 )
return ex;
1011 if( ntpFlag ==0)
return ex;
1015 if( m_rung_flag == 0 && m_wireg_flag == 0 && m_ddg_flag == 0
1016 && m_layerg_flag == 0 && m_zdep_flag == 0 && m_dcasin_flag==0
1017 && m_ggs_flag == 0 && m_enta_flag==0)
return ex;
1029 if( m_dcasin_flag) {
1040 if(m_enta_flag && runFlag>=3){
1063 if(m_debug) cout<<
"DedxCorrecSvc::StandardTrackCorrec"<<endl;
1064 if( runNO<0 )
return ex;
1065 if( ntpFlag ==0)
return ex;
1066 if( runFlag <3)
return ex;
1067 if( calib_rec_Flag ==1){
1069 if(m_t0_flag) ex=
T0Correc(t0, ex);
1089 if(m_rung_flag && calib_rec_Flag ==2){
1090 double rungain_temp =
RungCorrec( runNO, evtNO, ex )/ex;
1091 ex = ex/rungain_temp;
1102DedxCorrecSvc::init_param() {
1106 for(
int i = 0; i<6796 ; i++) {
1112 for(
int j = 0; j<100; j++){
1115 for(
int j = 0; j<43; j++) {
1121 for(
int k = 1; k<4; k++ ) {
1129 std::cout<<
"DedxCorrecSvc::init_param()!!!"<<std::endl;
1130 std::cout<<
"hello,init_param"<<endl;
1131 m_initConstFlg =
true;
1139 cout<<
"calib_F is = "<<calib_F<<endl;
1140 if(calib_F<0){ m_enta_flag = 0; calib_F =
abs(calib_F); }
1141 else m_enta_flag = 1;
1142 m_rung_flag = ( calib_F & 1 )? 1 : 0;
1143 m_wireg_flag = ( calib_F & 2 )? 1 : 0;
1144 m_dcasin_flag = ( calib_F & 4 )? 1 : 0;
1145 m_ggs_flag = ( calib_F & 8 )? 1 : 0;
1148 m_t0_flag = ( calib_F & 16 )? 1 : 0;
1149 m_sat_flag = ( calib_F & 32 )? 1 : 0;
1150 m_layerg_flag = ( calib_F & 64 )? 1 : 0;
1152 m_dip_flag = ( calib_F & 256 )? 1 : 0;
1153 m_mdcg_flag = ( calib_F & 512 )? 1 : 0;
1162HepPoint3D piv(hel.pivot());
1163double dr = hel.a()[0];
1164double phi0 = hel.a()[1];
1165double tanl = hel.a()[4];
1166double dz = hel.a()[3];
1168double dr = -19.1901;
1169double phi0 = 3.07309;
1170double tanl = -0.466654;
1173double csf0 = cos(phi0);
1174double snf0 = sin(phi0);
1175double x_c = dr*csf0;
1176double y_c = dr*snf0;
1177double z_c = hel.a()[3];
1183double m_zb, m_zf, Calpha;
1184// double sintheta = sin(M_PI_2-atan(hel.a()[4]));
1185double sintheta = sin(M_PI_2-atan(tanl));
1186// retrieve Mdc geometry information
1187double rcsiz1= geosvc->Layer(layer)->RCSiz1();
1188double rcsiz2= geosvc->Layer(layer)->RCSiz2();
1189double rlay= geosvc->Layer(layer)->Radius();
1190int ncell= geosvc->Layer(layer)->NCell();
1191double phioffset= geosvc->Layer(layer)->Offset();
1192float shift= geosvc->Layer(layer)->Shift();
1193double slant= geosvc->Layer(layer)->Slant();
1194double length = geosvc->Layer(layer)->Length();
1195int type = geosvc->Layer(layer)->Sup()->Type();
1196// shift = shift*type;
1198//conversion of the units(mm=>cm)
1205m_crio[0] = rlay - rcsiz1;
1206m_crio[1] = rlay + rcsiz2;
1209{ if(rlay<= fabs(dr)) rlay = rlay + rcsiz2;
1210if(rlay<fabs(dr)) return -1;
1211double t_digi = sqrt(rlay*rlay - dr*dr);
1212double x_t_digi = x_c - t_digi*snf0;
1213double y_t_digi = y_c + t_digi*csf0;
1214double z_t_digi = z_c + t_digi*tanl;
1215double x__t_digi = x_c + t_digi*snf0;
1216double y__t_digi = y_c - t_digi*csf0;
1217double z__t_digi = z_c - t_digi*tanl;
1218double phi_t_digi = atan2(y_t_digi,x_t_digi);
1219double phi__t_digi = atan2(y__t_digi,x__t_digi);
1220phi_t_digi = fmod( phi_t_digi+4*M_PI,2*M_PI );
1221phi__t_digi = fmod( phi__t_digi+4*M_PI,2*M_PI );
1222double phibin_digi = 2.0*M_PI/ncell;
1223double phi_cellid_digi = phioffset + shift*phibin_digi*0.5 + cellid *phibin_digi;
1224if(fabs(phi_cellid_digi - phi_t_digi)<fabs(phi_cellid_digi - phi__t_digi))
1226else if (fabs(phi_cellid_digi - phi_t_digi)>fabs(phi_cellid_digi - phi__t_digi))
1231int sign = 1; ///assumed the first half circle
1234Hep3Vector cell_IO[2];
1238 downin = (z*z-m_zb*m_zb)*pow(tan(slant),2);
1239 m_crio[0] = sqrt(m_crio[0]*m_crio[0]+downin);
1240 m_crio[1] = sqrt(m_crio[1]*m_crio[1]+downin);
1245if(m_crio[1]<fabs(dr)) return -1;
1246else if(m_crio[0]<fabs(dr)) {
1247 t[0] = sqrt(m_crio[1]*m_crio[1] - dr*dr);
1251 for( int i = 0; i < 2; i++ ) {
1252 if(m_crio[i]<fabs(dr)) return -1;
1253 t[i] = sqrt(m_crio[i]*m_crio[i] - dr*dr);
1257// calculate the cooridate of hits
1258double x_t[2],y_t[2],z_t[2];
1259double x__t[2],y__t[2],z__t[2];
1260double x_p[2],y_p[2],z_p[2];
1261for( int i = 0; i < 2; i++){
1262 x_t[i] = x_c - t[i]*snf0;
1263 y_t[i] = y_c + t[i]*csf0;
1264 z_t[i] = z_c + t[i]*tanl;
1265 x__t[i] = x_c + t[i]*snf0;
1266 y__t[i] = y_c - t[i]*csf0;
1267 z__t[i] = z_c - t[i]*tanl;
1270double phi_in_t,phi_in__t, phi_out_t,phi_out__t,phi_t,phi__t;
1271double phibin = 2.0*M_PI/ncell;
1272double phi_cellid = phioffset + shift*phibin*(0.5-z/length) + cellid *phibin;
1273phi_in_t = atan2(y_t[0],x_t[0]);
1274phi_out_t = atan2(y_t[1],x_t[1]);
1275phi_in__t = atan2(y__t[0],x__t[0]);
1276phi_out__t = atan2(y__t[1],x__t[1]);
1277phi_t = atan2(((y_t[0]+y_t[1])/2),((x_t[0]+x_t[1])/2));
1278phi__t = atan2(((y__t[0]+y__t[1])/2),((x__t[0]+x__t[1])/2));
1280phi_in_t = fmod( phi_in_t+4*M_PI,2*M_PI );
1281phi_out_t = fmod( phi_out_t+4*M_PI,2*M_PI );
1282phi_in__t = fmod( phi_in__t+4*M_PI,2*M_PI );
1283phi_out__t = fmod( phi_out__t+4*M_PI,2*M_PI );
1284phi_t = fmod( phi_t+4*M_PI,2*M_PI );
1285phi__t = fmod( phi__t+4*M_PI,2*M_PI );
1286phi_cellid = fmod( phi_cellid+4*M_PI,2*M_PI );
1288if(fabs(phi_cellid - phi_t)<fabs(phi_cellid - phi__t))
1290 for(int i =0; i<2; i++ )
1295else if (fabs(phi_cellid - phi_t)>fabs(phi_cellid - phi__t))
1297 for(int i =0; i<2; i++ )
1304 for(int i =0; i<2; i++ )
1310//calculate path length in r_phi plane and all length in this layer
1311double ch_ltrk_rp, ch_ltrk;
1312ch_ltrk_rp = sqrt((x_p[0]-x_p[1])*(x_p[0]-x_p[1])+(y_p[0]-y_p[1])*(y_p[0]-y_p[1]));
1313ch_ltrk = ch_ltrk_rp/sintheta;
1314//give cellid of in and out of this layer
1315double phi_in,phi_out;
1316phi_in = atan2(y_p[0],x_p[0]);
1317phi_out = atan2(y_p[1],x_p[1]);
1318phi_in = fmod( phi_in+4*M_PI,2*M_PI );
1319phi_out = fmod( phi_out+4*M_PI,2*M_PI );
1321//determine the in/out cellid
1322double inlow, inup, outlow, outup, gap, phi1, phi2, phi_mid, phi_midin, phi_midout;
1324// int cid_in_t,cid_in__t,cid_out_t,cid_out__t;
1325//cache sampl in each cell for this layer
1326std::vector<double> phi_entrance;
1327std::vector<double> sampl;
1329phi_entrance.resize(ncell);
1330for(int k=0; k<ncell; k++) {
1332 phi_entrance[k] = 0;
1335cid_in = cid_out = -1;
1336phibin = 2.0*M_PI/ncell;
1337//determine the in/out cell id
1338double stphi[2], phioff[2];
1339stphi[0] = shift*phibin*(0.5-z_p[0]/length);
1340stphi[1] = shift*phibin*(0.5-z_p[1]/length);
1341phioff[0] = phioffset+stphi[0];
1342phioff[1] = phioffset+stphi[1];
1343for(int i=0; i<ncell; i++) {
1345 // phi[i] = phioff[0]+phibin*i;
1346 inlow = phioff[0]+phibin*i-phibin*0.5;
1347 inup = phioff[0]+phibin*i+phibin*0.5;
1348 outlow = phioff[1]+phibin*i-phibin*0.5;
1349 outup = phioff[1]+phibin*i+phibin*0.5;
1350 inlow = fmod( inlow+4*M_PI,2*M_PI );
1351 inup = fmod( inup+4*M_PI,2*M_PI );
1352 outlow = fmod( outlow+4*M_PI,2*M_PI );
1353 outup = fmod( outup+4*M_PI,2*M_PI );
1355 cout << "shift " << shift<< " cellid " << i
1356 <<" phi_in " << phi_in << " phi_out " << phi_out
1357 << " inup "<< inup << " inlow " << inlow
1358 << " outup "<< outup << " outlow " << outlow << endl;
1360 if(phi_in>=inlow&&phi_in<inup) cid_in = i;
1361 if(phi_out>=outlow&&phi_out<outup) cid_out = i;
1363 if((phi_in>=inlow&&phi_in<2.0*M_PI)||(phi_in>=0.0&&phi_in<inup)) cid_in = i;
1365 if ( outlow>outup) {
1366 if((phi_out>=outlow&&phi_out<2.0*M_PI)||(phi_out>=0.0&&phi_out<outup)) cid_out = i;
1370// judge how many cells are traversed and deal with different situations
1371phi_midin = phi_midout = phi1 = phi2 = -999.0;
1373//only one cell traversed
1374if( cid_in == cid_out) {
1375 sampl[cid_in] = ch_ltrk;
1378} else if(cid_in < cid_out) {
1379 //in cell id less than out cell id
1380 //deal with the special case crossing x axis
1381 if( cid_out-cid_in>ncell/2 ) {
1382 // if(gap>=M_PI) gap = 2.0*M_PI-gap;
1383 phi_midin = phioff[0]+phibin*cid_in-phibin*0.5;
1384 phi_midout = phioff[1]+phibin*cid_out+phibin*0.5;
1385 phi_midin = fmod( phi_midin+4*M_PI,2*M_PI );
1386 phi_midout = fmod( phi_midout+4*M_PI,2*M_PI );
1387 phi1 = phi_midout-phi_out;
1388 phi2 = phi_in-phi_midin;
1389 phi1 = fmod(phi1+2.0*M_PI,2.0*M_PI);
1390 phi2 = fmod(phi2+2.0*M_PI,2.0*M_PI);
1391 gap = phi1+phi2+(ncell-1-cid_out+cid_in)*phibin;
1392 gap = fmod(gap+2.0*M_PI,2.0*M_PI);
1393 sampl[cid_in]=phi2/gap*ch_ltrk;
1394 sampl[cid_out]=phi1/gap*ch_ltrk;
1396 for( int jj = cid_out+1; jj<ncell; jj++) {
1397 sampl[jj]=phibin/gap*ch_ltrk;
1399 for( int jj = 0; jj<cid_in; jj++) {
1400 sampl[jj]=phibin/gap*ch_ltrk;
1405 phi_midin = phioff[0]+phibin*cid_in+phibin*0.5;
1406 phi_midout = phioff[1]+phibin*cid_out-phibin*0.5;
1407 phi_midin = fmod( phi_midin+4*M_PI,2*M_PI );
1408 phi_midout = fmod( phi_midout+4*M_PI,2*M_PI );
1409 phi1 = phi_midin-phi_in;
1410 phi2 = phi_out-phi_midout;
1411 phi1 = fmod(phi1+2.0*M_PI,2.0*M_PI);
1412 phi2 = fmod(phi2+2.0*M_PI,2.0*M_PI);
1413 gap = phi1+phi2+(cid_out-cid_in-1)*phibin;
1414 gap = fmod(gap+2.0*M_PI,2.0*M_PI);
1415 sampl[cid_in]=phi1/gap*ch_ltrk;
1416 sampl[cid_out]=phi2/gap*ch_ltrk;
1417 phi_entrance[cid_in] = phi_in;
1418 phi_entrance[cid_out] = phi_midout;
1419 for( int jj = cid_in+1; jj<cid_out; jj++) {
1420 sampl[jj]=phibin/gap*ch_ltrk;
1423} else if(cid_in > cid_out) {
1424 //in cell id greater than out cell id
1425 //deal with the special case crossing x axis
1426 if( cid_in-cid_out>ncell/2 ) {
1427 // if(gap>=M_PI) gap = 2.0*M_PI-gap;
1428 phi_midin = phioff[0]+phibin*cid_in+phibin*0.5;
1429 phi_midout = phioff[1]+phibin*cid_out-phibin*0.5;
1430 phi_midin = fmod( phi_midin+4*M_PI,2*M_PI );
1431 phi_midout = fmod( phi_midout+4*M_PI,2*M_PI );
1432 phi1 = phi_midin-phi_in;
1433 phi2 = phi_out-phi_midout;
1434 phi1 = fmod(phi1+2.0*M_PI,2.0*M_PI);
1435 phi2 = fmod(phi2+2.0*M_PI,2.0*M_PI);
1436 gap = phi1+phi2+(ncell-1-cid_in+cid_out)*phibin;
1437 gap = fmod(gap+2.0*M_PI,2.0*M_PI);
1438 sampl[cid_out]=phi2/gap*ch_ltrk;
1439 sampl[cid_in]=phi1/gap*ch_ltrk;
1441 for( int jj = cid_in+1; jj<ncell; jj++) {
1442 sampl[jj]=phibin/gap*ch_ltrk;
1444 for( int jj = 0; jj<cid_out; jj++) {
1445 sampl[jj]=phibin/gap*ch_ltrk;
1449 phi_midin = phioff[0]+phibin*cid_in-phibin*0.5;
1450 phi_midout = phioff[1]+phibin*cid_out+phibin*0.5;
1451 phi_midin = fmod( phi_midin+4*M_PI,2*M_PI );
1452 phi_midout = fmod( phi_midout+4*M_PI,2*M_PI );
1453 phi1 = phi_midout-phi_out;
1454 phi2 = phi_in-phi_midin;
1455 phi1 = fmod(phi1+2.0*M_PI,2.0*M_PI);
1456 phi2 = fmod(phi2+2.0*M_PI,2.0*M_PI);
1457 gap = phi1+phi2+(cid_in-cid_out-1)*phibin;
1458 gap = fmod(gap+2.0*M_PI,2.0*M_PI);
1459 sampl[cid_in]=phi2/gap*ch_ltrk;
1460 sampl[cid_out]=phi1/gap*ch_ltrk;
1461 for( int jj = cid_out+1; jj<cid_in; jj++) {
1462 sampl[jj]=phibin/gap*ch_ltrk;
1468if(sampl[cellid]<0.0) {
1469 if(cid_in!=cid_out) cout<<"?????????"<<endl;
1470 cout<< "layerId " << layer <<" cell id "<< cellid <<" shift " << shift
1471 << " cid_in " << cid_in << " cid_out " << cid_out << endl;
1473 cout <<" phi_in " << phi_in <<" phi_midin " << phi_midin << " phi_out "
1474 << phi_out << " phi_midout " << phi_midout <<endl;
1475 cout<<"total sampl " << ch_ltrk << " gap "<< gap << " phi1 "
1476 << phi1 << " phi2 " << phi2 << " phibin " << phibin << endl;
1479 for(int l=0; l<ncell; l++) {
1481 cout<<"picked cellid " << l << " sampling length "<< sampl[l]<< endl;
1485return sampl[cellid];
1498 int genlay = geosvc->
Layer(layer)->
Gen();
1506 HepPoint3D East_origin(East_lay_X, East_lay_Y, East_lay_Z);
1507 HepPoint3D West_origin(West_lay_X, West_lay_Y, West_lay_Z);
1508 Hep3Vector wire = (CLHEP::Hep3Vector)East_origin - (CLHEP::Hep3Vector)West_origin;
1509 HepPoint3D piovt_z =(z*10+length/2 )/length * wire + West_origin;
1510 piovt_z = piovt_z*0.1;
1517 double dr0 = hel.
a()[0];
1518 double phi0 = hel.
a()[1];
1519 double kappa = hel.
a()[2];
1520 double dz0 = hel.
a()[3];
1521 double tanl = hel.
a()[4];
1525 double ALPHA_loc = 1000/(2.99792458*Bz);
1531 int charge = ( kappa >= 0 )? 1 : -1;
1532 double rho = ALPHA_loc/kappa;
1533 double pt = fabs( 1.0/kappa );
1534 double lambda = atan( tanl );
1535 double theta = M_PI_2- lambda;
1536 double sintheta =
sin(M_PI_2-atan(tanl));
1538 double phi = fmod(phi0 +
M_PI*4,
M_PI*2);
1539 double csf0 =
cos(phi);
1540 double snf0 = (1. - csf0) * (1. + csf0);
1541 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
1542 if(phi >
M_PI) snf0 = - snf0;
1547 double x_c = piv.x() + ( hel.
dr() + rho )*csf0;
1548 double y_c = piv.y() + ( hel.
dr() + rho )*snf0;
1549 double z_c = piv.z() + hel.
dz();
1551 double m_c_perp(ccenter.perp());
1552 Hep3Vector m_c_unit((
HepPoint3D)ccenter.unit());
1556 double x_c_boost = x_c - piovt_z.x();
1557 double y_c_boost = y_c - piovt_z.y();
1558 double z_c_boost = z_c - piovt_z.z();
1559 HepPoint3D ccenter_boost(x_c_boost, y_c_boost, 0.0);
1560 double m_c_perp_boost(ccenter_boost.perp());
1563 Hep3Vector m_c_unit_boost((
HepPoint3D)ccenter_boost.unit());
1568 double dphi0 = fmod( IO.phi()+4*
M_PI,2*
M_PI ) - phi;
1569 double IO_phi = fmod( IO.phi()+4*
M_PI,2*
M_PI );
1573 if( dphi0 >
M_PI ) dphi0 -= 2*
M_PI;
1574 else if( dphi0 < -
M_PI ) dphi0 += 2*
M_PI;
1579 phi_io[1] = phi_io[0]+1.5*
M_PI;
1582 double m_zb, m_zf, Calpha;
1599 int wid = w0id + cellid;
1602 double x_lay_backward = geosvc->
Wire(layer, cellid)->
Backward().x();
1603 double y_lay_backward = geosvc->
Wire(layer, cellid)->
Backward().y();
1604 double x_lay_forward = geosvc->
Wire(layer, cellid)->
Forward().x();
1605 double y_lay_forward = geosvc->
Wire(layer, cellid)->
Forward().y();
1606 double r_lay_backward = sqrt(x_lay_backward*x_lay_backward+y_lay_backward*y_lay_backward);
1607 double r_lay_forward = sqrt(x_lay_forward*x_lay_forward+y_lay_forward*y_lay_forward);
1608 double r_lay_use = ((z*10+length/2)/length)*(r_lay_backward-r_lay_forward) + r_lay_forward;
1616 r_lay_use = 0.1*r_lay_use;
1617 rcsiz1 = 0.1*rcsiz1;
1618 rcsiz2 = 0.1*rcsiz2;
1620 length = 0.1*length;
1623 m_crio[0] = rlay - rcsiz1;
1624 m_crio[1] = rlay + rcsiz2;
1628 Hep3Vector iocand[2];
1629 Hep3Vector cell_IO[2];
1630 double dphi, downin;
1634 downin = (z*z-m_zb*m_zb)*pow(
tan(slant),2);
1635 m_crio[0] = sqrt(m_crio[0]*m_crio[0]+downin);
1636 m_crio[1] = sqrt(m_crio[1]*m_crio[1]+downin);
1641 for(
int i = 0; i < 2; i++ ) {
1642 double cos_alpha = m_c_perp_boost*m_c_perp_boost + m_crio[i]*m_crio[i] - rho*rho;
1643 cos_alpha = 0.5*cos_alpha/( m_c_perp_boost*m_crio[i] );
1644 if(fabs(cos_alpha)>1&&i==0)
return(-1.0);
1645 if(fabs(cos_alpha)>1&&i==1) {
1646 cos_alpha = m_c_perp_boost*m_c_perp_boost + m_crio[0]*m_crio[0] - rho*rho;
1647 cos_alpha = 0.5*cos_alpha/( m_c_perp_boost*m_crio[0] );
1648 Calpha = 2.0*
M_PI-acos( cos_alpha );
1650 Calpha = acos( cos_alpha );
1653 iocand[i] = m_c_unit_boost;
1654 iocand[i].rotateZ(
charge*sign*Calpha );
1655 iocand[i]*= m_crio[i];
1662 iocand[i] = iocand[i]+ piovt_z;
1667 double xx = iocand[i].x() - x_c;
1668 double yy = iocand[i].y() - y_c;
1670 dphi = atan2(yy, xx) - phi0 - M_PI_2*(1-
charge);
1671 dphi = fmod( dphi + 8.0*
M_PI, 2*
M_PI );
1673 if( dphi < phi_io[0] ) {
1676 else if( phi_io[1] < dphi ) {
1682 Hep3Vector zvector( 0., 0., z_c-rho*dphi*tanl-piovt_z.z());
1684 cell_IO[i] = iocand[i];
1685 cell_IO[i] += zvector;
1690 double xcio, ycio, phip;
1722 cell_IO[i] = hel.
x(dphi);
1729 Hep3Vector cl = cell_IO[1] - cell_IO[0];
1735 double ch_ltrk_rp = 0;
1736 ch_dphi = cl.perp()*0.5/(ALPHA_loc*pt);
1737 ch_dphi = 2.0 * asin( ch_dphi );
1738 ch_ltrk_rp = ch_dphi*ALPHA_loc*pt;
1739 double rpi_path = sqrt(cl.x()*cl.x()+cl.y()*cl.y());
1740 ch_ltrk = sqrt( ch_ltrk_rp*ch_ltrk_rp + cl.z()*cl.z() );
1741 double path = ch_ltrk_rp/ sintheta;
1742 ch_theta = cl.theta();
1758 double phibin, phi_in, phi_out, inlow, inup, outlow, outup, gap, phi1, phi2, phi_mid, phi_midin, phi_midout;
1759 int cid_in, cid_out;
1760 double inlow_z, inup_z, outlow_z, outup_z, gap_z, phi1_z, phi2_z, phi_mid_z, phi_midin_z, phi_midout_z;
1763 std::vector<double> sampl;
1764 sampl.resize(ncell);
1765 for(
int k=0; k<ncell; k++) {
1769 cid_in = cid_out = -1;
1770 phi_in = cell_IO[0].phi();
1771 phi_out = cell_IO[1].phi();
1774 phi_in = fmod( phi_in+4*
M_PI,2*
M_PI );
1775 phi_out = fmod( phi_out+4*
M_PI,2*
M_PI );
1776 phibin = 2.0*
M_PI/ncell;
1780 Hep3Vector cell_mid=0.5*(cell_IO[0]+cell_IO[1]);
1785 double stphi[2], phioff[2];
1786 stphi[0] = shift*phibin*(0.5-cell_IO[0].z()/length);
1787 stphi[1] = shift*phibin*(0.5-cell_IO[1].z()/length);
1790 phioff[0] = phioffset+stphi[0];
1791 phioff[1] = phioffset+stphi[1];
1793 for(
int i=0; i<ncell; i++) {
1795 double x_lay_backward_cell = geosvc->
Wire(layer, i)->
Backward().x()*0.1;
1796 double y_lay_backward_cell = geosvc->
Wire(layer, i)->
Backward().y()*0.1;
1797 double x_lay_forward_cell = geosvc->
Wire(layer, i)->
Forward().x()*0.1;
1798 double y_lay_forward_cell = geosvc->
Wire(layer, i)->
Forward().y()*0.1;
1801 Hep3Vector lay_backward(x_lay_backward_cell, y_lay_backward_cell, 0);
1802 Hep3Vector lay_forward(x_lay_forward_cell, y_lay_forward_cell, 0);
1803 Hep3Vector Cell_z[2];
1804 Cell_z[0] = ((cell_IO[0].z()+length/2)/length)*(lay_backward - lay_forward) + lay_forward;
1805 Cell_z[1] = ((cell_IO[1].z()+length/2)/length)*(lay_backward - lay_forward) + lay_forward;
1807 z_phi[0] = Cell_z[0].phi();
1808 z_phi[1] = Cell_z[1].phi();
1809 z_phi[0] = fmod( z_phi[0]+4*
M_PI,2*
M_PI );
1810 z_phi[1] = fmod( z_phi[1]+4*
M_PI,2*
M_PI );
1822 inlow_z = z_phi[0] - phibin*0.5;
1823 inup_z = z_phi[0] + phibin*0.5;
1824 outlow_z = z_phi[1] - phibin*0.5;
1825 outup_z = z_phi[1] + phibin*0.5;
1826 inlow_z = fmod( inlow_z+4*
M_PI,2*
M_PI );
1827 inup_z = fmod( inup_z+4*
M_PI,2*
M_PI );
1828 outlow_z = fmod( outlow_z+4*
M_PI,2*
M_PI );
1829 outup_z = fmod( outup_z+4*
M_PI,2*
M_PI );
1833 inlow = phioff[0]+phibin*i-phibin*0.5;
1834 inup = phioff[0]+phibin*i+phibin*0.5;
1835 outlow = phioff[1]+phibin*i-phibin*0.5;
1836 outup = phioff[1]+phibin*i+phibin*0.5;
1837 inlow = fmod( inlow+4*
M_PI,2*
M_PI );
1839 outlow = fmod( outlow+4*
M_PI,2*
M_PI );
1840 outup = fmod( outup+4*
M_PI,2*
M_PI );
1843 if(ntpFlag > 0) cout <<
"shift " << shift
1844 <<
" phi_in " << phi_in <<
" phi_out " << phi_out
1845 <<
" inup "<< inup <<
" inlow " << inlow
1846 <<
" outup "<< outup <<
" outlow " << outlow << endl;
1858 if(phi_in>=inlow_z&&phi_in<inup_z) cid_in = i;
1859 if(phi_out>=outlow_z&&phi_out<outup_z) cid_out = i;
1860 if ( inlow_z>inup_z) {
1861 if((phi_in>=inlow_z&&phi_in<2.0*
M_PI)||(phi_in>=0.0&&phi_in<inup_z)) cid_in = i;
1863 if ( outlow_z>outup_z) {
1864 if((phi_out>=outlow_z&&phi_out<2.0*
M_PI)||(phi_out>=0.0&&phi_out<outup_z)) cid_out = i;
1868 phi_midin = phi_midout = phi1 = phi2 = -999.0;
1872 if(cid_in == -1 || cid_out == -1)
return -1;
1874 if( cid_in == cid_out) {
1875 sampl[cid_in]= ch_ltrk;
1877 return sampl[cellid];
1878 }
else if(cid_in < cid_out) {
1881 if( cid_out-cid_in>ncell/2 ) {
1884 double x_lay_backward_cin = geosvc->
Wire(layer, cid_in)->
Backward().x()*0.1;
1885 double y_lay_backward_cin = geosvc->
Wire(layer, cid_in)->
Backward().y()*0.1;
1886 double x_lay_forward_cin = geosvc->
Wire(layer, cid_in)->
Forward().x()*0.1;
1887 double y_lay_forward_cin = geosvc->
Wire(layer, cid_in)->
Forward().y()*0.1;
1888 Hep3Vector lay_backward_cin(x_lay_backward_cin, y_lay_backward_cin, 0);
1889 Hep3Vector lay_forward_cin(x_lay_forward_cin, y_lay_forward_cin, 0);
1890 Hep3Vector Cell_z[2];
1891 Cell_z[0]=((cell_IO[0].z()+length/2)/length)*(lay_backward_cin-lay_forward_cin)+lay_forward_cin;
1892 double phi_cin_z = Cell_z[0].phi();
1893 phi_cin_z = fmod( phi_cin_z+4*
M_PI,2*
M_PI );
1894 double x_lay_backward_cout = geosvc->
Wire(layer, cid_out)->
Backward().x()*0.1;
1895 double y_lay_backward_cout = geosvc->
Wire(layer, cid_out)->
Backward().y()*0.1;
1896 double x_lay_forward_cout = geosvc->
Wire(layer, cid_out)->
Forward().x()*0.1;
1897 double y_lay_forward_cout = geosvc->
Wire(layer, cid_out)->
Forward().y()*0.1;
1898 Hep3Vector lay_backward_cout(x_lay_backward_cout, y_lay_backward_cout, 0);
1899 Hep3Vector lay_forward_cout(x_lay_forward_cout, y_lay_forward_cout, 0);
1900 Cell_z[1]=((cell_IO[1].z()+length/2)/length)*(lay_backward_cout-lay_forward_cout)+lay_forward_cout;
1901 double phi_cout_z = Cell_z[1].phi();
1902 phi_cout_z = fmod( phi_cout_z+4*
M_PI,2*
M_PI );
1904 phi_midin_z = phi_cin_z-phibin*0.5;
1905 phi_midout_z = phi_cout_z+phibin*0.5;
1906 phi_midin_z = fmod( phi_midin_z+4*
M_PI,2*
M_PI );
1907 phi_midout_z = fmod( phi_midout_z+4*
M_PI,2*
M_PI );
1908 phi1_z = phi_midout_z-phi_out;
1909 phi2_z = phi_in-phi_midin_z;
1910 phi1_z = fmod(phi1_z+2.0*
M_PI,2.0*
M_PI);
1911 phi2_z = fmod(phi2_z+2.0*
M_PI,2.0*
M_PI);
1912 gap_z = phi1_z+phi2_z+(ncell-1-cid_out+cid_in)*phibin;
1913 gap_z = fmod(gap_z+2.0*
M_PI,2.0*
M_PI);
1914 sampl[cid_in]=phi2_z/gap_z*ch_ltrk;
1915 sampl[cid_out]=phi1_z/gap_z*ch_ltrk;
1916 for(
int jj = cid_out+1; jj<ncell; jj++) {
1917 sampl[jj]=phibin/gap_z*ch_ltrk;
1919 for(
int jj = 0; jj<cid_in; jj++) {
1920 sampl[jj]=phibin/gap_z*ch_ltrk;
1954 double x_lay_backward_cin = geosvc->
Wire(layer, cid_in)->
Backward().x()*0.1;
1955 double y_lay_backward_cin = geosvc->
Wire(layer, cid_in)->
Backward().y()*0.1;
1956 double x_lay_forward_cin = geosvc->
Wire(layer, cid_in)->
Forward().x()*0.1;
1957 double y_lay_forward_cin = geosvc->
Wire(layer, cid_in)->
Forward().y()*0.1;
1958 Hep3Vector lay_backward_cin(x_lay_backward_cin, y_lay_backward_cin, 0);
1959 Hep3Vector lay_forward_cin(x_lay_forward_cin, y_lay_forward_cin, 0);
1960 Hep3Vector Cell_z[2];
1961 Cell_z[0]=((cell_IO[0].z()+length/2)/length)*(lay_backward_cin-lay_forward_cin)+lay_forward_cin;
1962 double phi_cin_z = Cell_z[0].phi();
1963 phi_cin_z = fmod( phi_cin_z+4*
M_PI,2*
M_PI );
1964 double x_lay_backward_cout = geosvc->
Wire(layer, cid_out)->
Backward().x()*0.1;
1965 double y_lay_backward_cout = geosvc->
Wire(layer, cid_out)->
Backward().y()*0.1;
1966 double x_lay_forward_cout = geosvc->
Wire(layer, cid_out)->
Forward().x()*0.1;
1967 double y_lay_forward_cout = geosvc->
Wire(layer, cid_out)->
Forward().y()*0.1;
1968 Hep3Vector lay_backward_cout(x_lay_backward_cout, y_lay_backward_cout, 0);
1969 Hep3Vector lay_forward_cout(x_lay_forward_cout, y_lay_forward_cout, 0);
1970 Cell_z[1]=((cell_IO[1].z()+length/2)/length)*(lay_backward_cout-lay_forward_cout)+lay_forward_cout;
1971 double phi_cout_z = Cell_z[1].phi();
1972 phi_cout_z = fmod( phi_cout_z+4*
M_PI,2*
M_PI );
1974 phi_midin_z = phi_cin_z+phibin*0.5;
1975 phi_midout_z = phi_cout_z-phibin*0.5;
1976 phi_midin_z = fmod( phi_midin_z+4*
M_PI,2*
M_PI );
1977 phi_midout_z = fmod( phi_midout_z+4*
M_PI,2*
M_PI );
1978 phi1_z = phi_midin_z-phi_in;
1979 phi2_z = phi_out-phi_midout_z;
1980 phi1_z = fmod(phi1_z+2.0*
M_PI,2.0*
M_PI);
1981 phi2_z = fmod(phi2_z+2.0*
M_PI,2.0*
M_PI);
1982 gap_z = phi1_z+phi2_z+(cid_out-cid_in-1)*phibin;
1983 gap_z = fmod(gap_z+2.0*
M_PI,2.0*
M_PI);
1984 sampl[cid_in]=phi1_z/gap_z*ch_ltrk;
1985 sampl[cid_out]=phi2_z/gap_z*ch_ltrk;
1986 for(
int jj = cid_in+1; jj<cid_out; jj++) {
1987 sampl[jj]=phibin/gap_z*ch_ltrk;
2007 }
else if(cid_in > cid_out) {
2010 if( cid_in-cid_out>ncell/2 ) {
2011 double x_lay_backward_cin = geosvc->
Wire(layer, cid_in)->
Backward().x()*0.1;
2012 double y_lay_backward_cin = geosvc->
Wire(layer, cid_in)->
Backward().y()*0.1;
2013 double x_lay_forward_cin = geosvc->
Wire(layer, cid_in)->
Forward().x()*0.1;
2014 double y_lay_forward_cin = geosvc->
Wire(layer, cid_in)->
Forward().y()*0.1;
2015 Hep3Vector lay_backward_cin(x_lay_backward_cin, y_lay_backward_cin, 0);
2016 Hep3Vector lay_forward_cin(x_lay_forward_cin, y_lay_forward_cin, 0);
2017 Hep3Vector Cell_z[2];
2018 Cell_z[0]=((cell_IO[0].z()+length/2)/length)*(lay_backward_cin-lay_forward_cin)+lay_forward_cin;
2019 double phi_cin_z = Cell_z[0].phi();
2020 phi_cin_z = fmod( phi_cin_z+4*
M_PI,2*
M_PI );
2021 double x_lay_backward_cout = geosvc->
Wire(layer, cid_out)->
Backward().x()*0.1;
2022 double y_lay_backward_cout = geosvc->
Wire(layer, cid_out)->
Backward().y()*0.1;
2023 double x_lay_forward_cout = geosvc->
Wire(layer, cid_out)->
Forward().x()*0.1;
2024 double y_lay_forward_cout = geosvc->
Wire(layer, cid_out)->
Forward().y()*0.1;
2025 Hep3Vector lay_backward_cout(x_lay_backward_cout, y_lay_backward_cout, 0);
2026 Hep3Vector lay_forward_cout(x_lay_forward_cout, y_lay_forward_cout, 0);
2027 Cell_z[1]=((cell_IO[1].z()+length/2)/length)*(lay_backward_cout-lay_forward_cout)+lay_forward_cout;
2028 double phi_cout_z = Cell_z[1].phi();
2029 phi_cout_z = fmod( phi_cout_z+4*
M_PI,2*
M_PI );
2031 phi_midin_z = phi_cin_z+phibin*0.5;
2032 phi_midout_z = phi_cout_z-phibin*0.5;
2033 phi_midin_z = fmod( phi_midin_z+4*
M_PI,2*
M_PI );
2034 phi_midout_z = fmod( phi_midout_z+4*
M_PI,2*
M_PI );
2035 phi1_z = phi_midin_z-phi_in;
2036 phi2_z = phi_out-phi_midout_z;
2037 phi1_z = fmod(phi1_z+2.0*
M_PI,2.0*
M_PI);
2038 phi2_z = fmod(phi2_z+2.0*
M_PI,2.0*
M_PI);
2039 gap_z = phi1_z+phi2_z+(ncell-1-cid_in+cid_out)*phibin;
2040 gap_z = fmod(gap_z+2.0*
M_PI,2.0*
M_PI);
2041 sampl[cid_out]=phi2_z/gap_z*ch_ltrk;
2042 sampl[cid_in]=phi1_z/gap_z*ch_ltrk;
2043 for(
int jj = cid_in+1; jj<ncell; jj++) {
2044 sampl[jj]=phibin/gap_z*ch_ltrk;
2046 for(
int jj = 0; jj<cid_out; jj++) {
2047 sampl[jj]=phibin/gap_z*ch_ltrk;
2079 double x_lay_backward_cin = geosvc->
Wire(layer, cid_in)->
Backward().x()*0.1;
2080 double y_lay_backward_cin = geosvc->
Wire(layer, cid_in)->
Backward().y()*0.1;
2081 double x_lay_forward_cin = geosvc->
Wire(layer, cid_in)->
Forward().x()*0.1;
2082 double y_lay_forward_cin = geosvc->
Wire(layer, cid_in)->
Forward().y()*0.1;
2083 Hep3Vector lay_backward_cin(x_lay_backward_cin, y_lay_backward_cin, 0);
2084 Hep3Vector lay_forward_cin(x_lay_forward_cin, y_lay_forward_cin, 0);
2085 Hep3Vector Cell_z[2];
2086 Cell_z[0]=((cell_IO[0].z()+length/2)/length)*(lay_backward_cin-lay_forward_cin)+lay_forward_cin;
2087 double phi_cin_z = Cell_z[0].phi();
2088 phi_cin_z = fmod( phi_cin_z+4*
M_PI,2*
M_PI );
2089 double x_lay_backward_cout = geosvc->
Wire(layer, cid_out)->
Backward().x()*0.1;
2090 double y_lay_backward_cout = geosvc->
Wire(layer, cid_out)->
Backward().y()*0.1;
2091 double x_lay_forward_cout = geosvc->
Wire(layer, cid_out)->
Forward().x()*0.1;
2092 double y_lay_forward_cout = geosvc->
Wire(layer, cid_out)->
Forward().y()*0.1;
2093 Hep3Vector lay_backward_cout(x_lay_backward_cout, y_lay_backward_cout, 0);
2094 Hep3Vector lay_forward_cout(x_lay_forward_cout, y_lay_forward_cout, 0);
2095 Cell_z[1]=((cell_IO[1].z()+length/2)/length)*(lay_backward_cout-lay_forward_cout)+lay_forward_cout;
2096 double phi_cout_z = Cell_z[1].phi();
2097 phi_cout_z = fmod( phi_cout_z+4*
M_PI,2*
M_PI );
2099 phi_midin_z = phi_cin_z-phibin*0.5;
2100 phi_midout_z = phi_cout_z+phibin*0.5;
2101 phi_midin_z = fmod( phi_midin_z+4*
M_PI,2*
M_PI );
2102 phi_midout_z = fmod( phi_midout_z+4*
M_PI,2*
M_PI );
2103 phi1_z = phi_midout_z-phi_out;
2104 phi2_z = phi_in-phi_midin_z;
2105 phi1_z = fmod(phi1_z+2.0*
M_PI,2.0*
M_PI);
2106 phi2_z = fmod(phi2_z+2.0*
M_PI,2.0*
M_PI);
2107 gap_z = phi1_z+phi2_z+(cid_in-cid_out-1)*phibin;
2108 gap_z = fmod(gap_z+2.0*
M_PI,2.0*
M_PI);
2109 sampl[cid_in]=phi2_z/gap_z*ch_ltrk;
2110 sampl[cid_out]=phi1_z/gap_z*ch_ltrk;
2111 for(
int jj = cid_out+1; jj<cid_in; jj++) {
2112 sampl[jj]=phibin/gap_z*ch_ltrk;
2135 if(sampl[cellid]<0.0) {
2136 if(cid_in!=cid_out) cout<<
"?????????"<<endl;
2137 cout<<
"layerId " << layer <<
" cell id "<< cellid <<
" shift " << shift
2138 <<
" cid_in " << cid_in <<
" cid_out " << cid_out << endl;
2140 cout <<
" phi_in " << phi_in <<
" phi_midin " << phi_midin <<
" phi_out "
2141 << phi_out <<
" phi_midout " << phi_midout <<endl;
2142 cout<<
"total sampl " << ch_ltrk <<
" gap "<< gap <<
" phi1 "
2143 << phi1 <<
" phi2 " << phi2 <<
" phibin " << phibin << endl;
2146 for(
int l=0; l<ncell; l++) {
2148 cout<<
"picked cellid " << l <<
" sampling length "<< sampl[l]<< endl;
2152 return sampl[cellid];
2162 double absCosTheta = fabs(cosTheta);
2163 double projection = pow(absCosTheta,m_power) + m_delta;
2164 double chargeDensity = D/projection;
2165 double numerator = 1 + m_alpha*chargeDensity;
2166 double denominator = 1 + m_gamma*chargeDensity;
2171 I = D * m_ratio* numerator/denominator;
2184 double absCosTheta = fabs(cosTheta);
2185 double projection = pow(absCosTheta,m_power) + m_delta;
2188 double a = m_alpha / projection;
2189 double b = 1 - m_gamma / projection*(
I/m_ratio);
2190 double c = -
I/m_ratio;
2193 cout<<
"both a and b coefficiants for hadron correction are 0"<<endl;
2197 double D = a != 0? (-
b + sqrt(
b*
b - 4.0*a*c))/(2.0*a) : -c/
b;
2199 cout<<
"D is less 0! will try another solution"<<endl;
2200 D=a != 0? (-
b - sqrt(
b*
b + 4.0*a*c))/(2.0*a) : -c/
b;
2202 cout<<
"D is still less 0! just return uncorrectecd value"<<endl;
double tan(const BesAngle a)
double sin(const BesAngle a)
double cos(const BesAngle a)
*******INTEGER m_nBinMax INTEGER m_NdiMax !No of bins in histogram for cell exploration division $ !Last vertex $ !Last active cell $ !Last cell in buffer $ !No of sampling when dividing cell $ !No of function total $ !Flag for random ceel for $ !Flag for type of for WtMax $ !Flag which decides whether vertices are included in the sampling $ entire domain is hyp !Maximum effective eevents per bin
double CosthetaCorrec(double costheta, double ex) const
double D2I(const double &cosTheta, const double &D) const
double f_larcos(double x, int nbin)
virtual StatusCode finalize()
double LayerCorrec(int layer, double z, double costheta, double ex) const
double PathL(int ntpFlag, const Dedx_Helix &hel, int layer, int cellid, double z) const
double StandardTrackCorrec(int calib_rec_Flag, int typFlag, int ntpFlag, int runNO, int evtNO, double ex, double costheta, double t0) const
void handle(const Incident &)
double T0Correc(double t0, double ex) const
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvUnknown)
double LayerGainCorrec(int layid, double ex) const
double EntaCorrec(int layid, double enta, double ex) const
double SaturCorrec(int layid, double costheta, double ex) const
double StandardHitCorrec(int calib_rec_Flag, int runFlag, int ntpFlag, int runNO, int evtNO, double pathl, int wid, int layid, double adc, double dd, double eangle, double costheta) const
double CellCorrec(int ser, double adc, double dd, double enta, double z, double costheta) const
virtual StatusCode initialize()
double WireGainCorrec(int wireid, double ex) const
double HadronCorrec(double costheta, double dedx) const
double TrkCorrec(double costheta, double dedx) const
double RungCorrec(int runNO, int evtNO, double ex) const
double DriftDistCorrec(int layid, double ddrift, double ex) const
double DocaSinCorrec(int layid, double doca, double enta, double ex) const
double DipAngCorrec(int layid, double costheta, double ex) const
double ZdepCorrec(int layid, double zhit, double ex) const
double I2D(const double &cosTheta, const double &I) const
DedxCorrecSvc(const std::string &name, ISvcLocator *svcloc)
double StandardCorrec(int runFlag, int ntpFlag, int runNO, int evtNO, double pathl, int wid, int layid, double adc, double dd, double eangle, double z, double costheta) const
double GlobalCorrec(double dedx) const
void set_flag(int calib_F)
const HepVector & a(void) const
returns helix parameters.
HepPoint3D x(double dPhi=0.) const
returns position after rotating angle dPhi in phi direction.
const HepPoint3D & pivot(void) const
returns pivot position.
double dr(void) const
returns an element of parameters.
virtual double getReferField()=0
virtual const MdcGeoLayer *const Layer(unsigned id)=0
virtual const MdcGeoWire *const Wire(unsigned id)=0
virtual const MdcGeoGeneral *const GeneralLayer(unsigned id)=0
double SzWest(void) const
double SxEast(void) const
double SyWest(void) const
double SxWest(void) const
double SzEast(void) const
double SyEast(void) const
double Radius(void) const
double RCSiz2(void) const
double Length(void) const
MdcGeoSuper * Sup(void) const
double RCSiz1(void) const
double Offset(void) const
HepPoint3D FWirePos(void) const
HepPoint3D BWirePos(void) const
HepPoint3D Forward(void) const
HepPoint3D Backward(void) const