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;
41 geosvc(0),base_class(name, svcloc) {
42 declareProperty(
"Run",m_run=1);
43 declareProperty(
"init",m_init=1);
44 declareProperty(
"par_flag",m_par_flag=0);
45 declareProperty(
"Debug",
m_debug=
false);
46 declareProperty(
"DebugI",m_debug_i=1);
47 declareProperty(
"DebugJ",m_debug_j=1);
48 m_initConstFlg =
false;
58 MsgStream log(messageService(), name());
59 log << MSG::INFO << name() <<
"DedxCorrecSvc::initialize()" << endreq;
61 StatusCode sc = Service::initialize();
62 if( sc.isFailure() )
return sc;
65 sc = service(
"IncidentSvc", incsvc);
69 incsvc -> addListener(
this,
"NewRun", priority);
72 StatusCode scgeo = service(
"MdcGeomSvc", geosvc);
73 if(scgeo.isFailure() ) {
74 log << MSG::ERROR <<
"GeoSvc failing!!!!!!!" << endreq;
78 StatusCode scmgn = service (
"MagneticFieldSvc",m_pIMF);
79 if(scmgn!=StatusCode::SUCCESS) {
80 log << MSG::ERROR <<
"Unable to open Magnetic field service"<<endreq;
83 return StatusCode::SUCCESS;
88 MsgStream log(messageService(), name());
89 log << MSG::INFO << name() <<
"DedxCorrecSvc::finalize()" << endreq;
90 return StatusCode::SUCCESS;
95 MsgStream log( messageService(), name() );
96 log << MSG::DEBUG <<
"handle: " << inc.type() << endreq;
98 if ( inc.type() ==
"NewRun" ){
99 log << MSG::DEBUG <<
"New Run" << endreq;
101 if( ! m_initConstFlg )
103 if( m_init == 0 ) { init_param(); }
104 else if( m_init ==1 ) { init_param_svc(); }
114 if(nbin!=80)
return x;
115 double m_absx(fabs(
x));
116 double m_charge(
x/m_absx);
117 if(m_absx>0.925 && m_absx<=0.950)
return 0.9283*m_charge;
118 if(m_absx>0.900 && m_absx<=0.925)
return 0.9115*m_charge;
119 if(m_absx>0.875 && m_absx<=0.900)
return 0.8877*m_charge;
120 if(m_absx>0.850 && m_absx<=0.875)
return 0.8634*m_charge;
121 if(m_absx>0.825 && m_absx<=0.850)
return 0.8460*m_charge;
122 if(m_absx>0.800 && m_absx<=0.825)
return 0.8089*m_charge;
126DedxCorrecSvc::init_param_svc() {
128 MsgStream log(messageService(), name());
129 IDataProviderSvc* pCalibDataSvc;
130 StatusCode sc = service(
"CalibDataSvc", pCalibDataSvc,
true);
131 if ( !sc.isSuccess() ) {
133 <<
"Could not get IDataProviderSvc interface of CalibXmlCnvSvc"
138 <<
"Retrieved IDataProviderSvc interface of CalibXmlCnvSvc"
145 std::string fullPath =
"/Calib/DedxCal";
147 SmartDataPtr<CalibData::DedxCalibData>
test(pCalibDataSvc, fullPath);
150 N_run =
test->getrunNO();
152 cout<<
"N_run = "<<N_run<<endl;
153 for(
int j=0;j<100000;j++)
159 m_rung[i][j] =
test->getrung(i,j);
160 if(i==2 && m_rung[2][j]>run_temp) run_temp = m_rung[2][j];
168 m_rung[2][j] = run_temp;
171 m_rung[5][j] = 1000000000;
215 for(
int i=0;i<4;i++) {
216 for(
int j=0;j<43;j++) {
217 m_ddg[i][j] =
test->getddg(i,j);
218 m_ggs[i][j] =
test->getggs(i,j);
219 m_zdep[i][j] =
test->getzdep(i,j);
228 m_dedx_gain =
test->getgain();
229 std::cout<<
"gain="<<m_dedx_gain<<
"\n";
231 m_dedx_resol =
test->getresol();
232 std::cout<<
"resol="<<m_dedx_resol<<
"\n";
234 for(
int i=0;i<43;i++) {
235 m_layer_g[i] =
test -> getlayerg(i);
236 if(m_layer_g[i]>2.0 || m_layer_g[i]<0.5) m_layer_g[i] =1;
252 for(
int i=0;i<6796;i++) {
253 m_wire_g[i] =
test -> getwireg(i);
263 for(
int i=0;i<6796;i++) {
266 for(
int j=0; j<25; j++){
267 if( i == dead_wire[kk][j] )
296 for(
int i=0; i<nbin; i++){
297 cos.push_back(
test -> get_costheta(i));
299 for(
int i=0;i<nbin-1;i++){
304 double x1=-1.00+(0.5+i)*(2.00/nbin);
306 double x2=-1.00+(0.5+i+1)*(2.00/nbin);
309 if(fabs(x1)>0.8) x1 =
f_larcos(x1, nbin);
310 if(fabs(x2)>0.8) x2 =
f_larcos(x2, nbin);
317 double x1=-1.00+(0.5+i-1)*(2.00/nbin);
319 double x2=-1.00+(0.5+i)*(2.00/nbin);
322 if(fabs(x1)>0.8) x1 =
f_larcos(x1, nbin);
323 if(fabs(x2)>0.8) x2 =
f_larcos(x2, nbin);
332 if(
cos[i-1]>0.0001 &&
cos[i+1]>0.0001){
333 double x1=-1.00+(0.5+i-1)*(2.00/nbin);
335 double x2=-1.00+(0.5+i+1)*(2.00/nbin);
338 if(fabs(x1)>0.8) x1 =
f_larcos(x1, nbin);
339 if(fabs(x2)>0.8) x2 =
f_larcos(x2, nbin);
377 for(
int i=0; i<35; i++){
378 xbin.push_back(
test ->get_t0(i));
379 ybin.push_back(
test ->get_dedx(i));
382 for(
int i=0;i<nbin-1;i++){
392 b=(y1*x2-y2*x1)/(x2-x1);
401 b=(y1*x2-y2*x1)/(x2-x1);
407 if(ybin[i-1]>0 && ybin[i+1]>0){
413 b=(y1*x2-y2*x1)/(x2-x1);
461 double docaeangle_gain[
n];
462 double docaeangle_chisq[
n];
463 double docaeangle_entries[
n];
465 for(
int i=0; i<
n; i++){
467 docaeangle_gain[i] =
test -> get_out_gain(i);
468 docaeangle_chisq[i] =
test -> get_out_chi(i);
469 docaeangle_entries[i] =
test -> get_out_hits(i);
470 int Id_Doca_temp =
test -> get_id_doca(i);
471 int Ip_Eangle_temp =
test -> get_ip_eangle(i);
472 m_docaeangle[Id_Doca_temp][Ip_Eangle_temp] = docaeangle_gain[i];
473 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;
480 int onedsize=
test->get_enanglesize();
482 for(
int i=0; i< onedsize; i++){
483 m_venangle.push_back(
test->get_enangle(i));
498 const int hadronNo=
test -> get_hadronNo();
500 m_alpha=
test -> get_hadron(0);
502 m_gamma=
test -> get_hadron(1);
504 m_delta=
test -> get_hadron(2);
506 m_power=
test -> get_hadron(3);
508 m_ratio=
test -> get_hadron(4);
528 if( m_wire_g[wireid] > 0 ){
529 double ch_dedx = (ex/m_wire_g[wireid])*m_valid[wireid];
532 else if( m_wire_g[wireid] == 0 ){
544 if(m_par_flag == 1) {
545 dedx_ggs = m_ggs[0][layer] + m_ggs[1][layer]*
costheta +
547 }
else if(m_par_flag == 0) {
548 dedx_ggs = m_ggs[0][layer] + m_ggs[1][layer]*T1(
costheta) +
552 dedx_ggs = dedx/dedx_ggs;
553 if(dedx_ggs>0.0)
return dedx_ggs;
565 const int nbin=cos_k.size()+1;
566 const double step=2.00/nbin;
567 int n= (int)((
costheta+1.00-0.5*step)/step);
605 dedx_cos = dedx/dedx_cos;
616 const int nbin=t0_k.size()+1;
618 cout<<
"there should be 35 bins for t0 correction, check it!"<<endl;
625 else if(t0>=610 && t0<1190){
626 n=(int)( (t0-610.0)/20.0 ) + 2;
628 else if(t0>=1190 && t0<1225)
630 else if(t0>=1225 && t0<1275)
635 dedx_t0=t0_k[
n]*t0+t0_b[
n];
638 dedx_t0 = dedx/dedx_t0;
654 if( m_layer_g[layid] > 0 ){
655 double ch_dedx = dedx/m_layer_g[layid];
658 else if( m_layer_g[layid] == 0 ){
672 for(
int j=0;j<100000;j++) {
674 if((runNO == m_rung[2][j]) && (evtNO >= m_rung[4][j]) && (evtNO <= m_rung[5][j])) {
675 dedx_rung = dedx/m_rung[0][j];
683 cout<<
"Warning!!! in DedxCorrecSvc::RungCorrec(): no rungain to "<<runNO<<endl;
696 if(m_par_flag == 1) {
697 dedx_ddg = m_ddg[0][layer] + m_ddg[1][layer]*dd +
698 m_ddg[2][layer]*dd*dd + m_ddg[3][layer]*pow(dd,3);
699 }
else if(m_par_flag == 0) {
700 dedx_ddg = m_ddg[0][layer] + m_ddg[1][layer]*T1(dd) +
701 m_ddg[2][layer]*T2(dd) + m_ddg[3][layer]*T3(dd);
704 dedx_ddg = dedx/dedx_ddg;
705 if (dedx_ddg>0.0)
return dedx_ddg;
725 if(eangle>-0.25 && eangle<0.25){
726 double stepsize= 0.5/m_venangle.size();
727 int nsize= m_venangle.size();
730 double y1=0,y2=0,x1=0,x2=0;
732 if(eangle>=-0.25+0.5*stepsize && eangle<=0.25-0.5*stepsize){
733 int bin = (int)( (eangle-(-0.25+0.5*stepsize))/stepsize);
735 x1=-0.25+0.5*stepsize+
bin*stepsize;
736 y2=m_venangle[
bin+1];
737 x2=-0.25+1.5*stepsize+
bin*stepsize;
739 else if(eangle<=-0.25+0.5*stepsize){
741 x1=-0.25+0.5*stepsize;
743 x2=-0.25+1.5*stepsize;
745 else if( eangle>=0.25-0.5*stepsize){
746 y1=m_venangle[nsize-2];
747 x1=0.25-1.5*stepsize;
748 y2=m_venangle[nsize-1];
749 x2=0.25-0.5*stepsize;
751 double kcof= (y2-y1)/(x2-x1);
752 double bcof= y1-kcof*x1;
753 double ratio = kcof*eangle+bcof;
765 if(m_par_flag == 1) {
766 dedx_zdep = m_zdep[0][layer] + m_zdep[1][layer]*z +
767 m_zdep[2][layer]*z*z + m_zdep[3][layer]*pow(z,3);
768 }
else if(m_par_flag == 0) {
769 dedx_zdep = m_zdep[0][layer] + m_zdep[1][layer]*T1(z) +
770 m_zdep[2][layer]*T2(z) + m_zdep[3][layer]*T3(z);
772 dedx_zdep = dedx/dedx_zdep;
773 if (dedx_zdep>0.0)
return dedx_zdep;
782 if(m_debug) cout<<
"DedxCorrecSvc::DocaSinCorrec"<<endl;
785 if(eangle>0.25) eangle = eangle -0.5;
786 else if(eangle < -0.25) eangle = eangle +0.5;
789 doca = doca/doca_norm[layer];
790 iDoca =(Int_t)floor((doca-
Out_DocaMin)/Out_Stepdoca);
795 if(iDoca<0) iDoca = 0;
796 if(m_debug) cout<<
"iDoca : "<<iDoca<<
" doca : "<<doca<<
" Out_DocaMin : "<<
Out_DocaMin<<
" Out_Stepdoca : "<<Out_Stepdoca<<endl;
799 for(
int i =0; i<14; i++){
801 if(eangle <Eangle_value_cut[i] || eangle > Eangle_value_cut[i+1])
continue;
802 else if(eangle>= Eangle_value_cut[i] && eangle < Eangle_value_cut[i+1]) {
803 for(
int k =0; k<i; k++){
804 iEAng+= Eangle_cut_bin[k];
806 double eangle_bin_cut_step = (Eangle_value_cut[i+1] - Eangle_value_cut[i])/Eangle_cut_bin[i];
807 int temp_bin = int((eangle-Eangle_value_cut[i])/eangle_bin_cut_step);
812 if(m_docaeangle[iDoca][iEAng]>0) {
813 if(m_debug && (iDoca==m_debug_i) && (iEAng==m_debug_j))
814 cout <<
"doca: " << doca <<
" eang" << eangle <<
" dedx before: " << dedx << endl;
815 dedx = dedx/m_docaeangle[iDoca][iEAng];
816 if(m_debug && (iDoca==m_debug_i) && (iEAng==m_debug_j))
817 cout <<
"gain: " << m_docaeangle[iDoca][iEAng] <<
" dedx after: " << dedx << endl;
829 if( m_mdcg_flag == 0 )
return dedx;
830 double calib_ex = dedx;
831 if( m_dedx_gain > 0 ) calib_ex /= m_dedx_gain;
841 if( m_rung_flag == 0 && m_wireg_flag == 0 && m_ddg_flag == 0
842 && m_layerg_flag == 0 && m_zdep_flag == 0 &&
843 m_ggs_flag == 0)
return adc;
844 adc = m_valid[ser]*m_wire_g[ser]*adc;
848 double correct1_ex , correct2_ex, correct3_ex, correct4_ex, correct5_ex;
861 correct2_ex =correct1_ex;
867 correct3_ex =correct2_ex;
871 correct4_ex =
ZdepCorrec( lyr, z, correct3_ex );
874 correct4_ex = correct3_ex;
881 correct5_ex = correct4_ex;
891 if( m_zdep_flag == 0 && m_ggs_flag == 0 )
return ex;
902 if( m_mdcg_flag == 0 )
return dedx;
904 double calib_ex = dedx;
906 double run_const = m_dedx_gain;
907 if( run_const > 0 && m_mdcg_flag != 0 ) calib_ex /= run_const;
915DedxCorrecSvc::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 {
924 if( runNO<0 )
return ex;
928 if( ntpFlag ==0)
return ex;
930 if( m_rung_flag == 0 && m_wireg_flag == 0 && m_dcasin_flag==0 && m_ddg_flag == 0
931 && m_layerg_flag == 0 && m_zdep_flag == 0 &&
932 m_ggs_flag == 0)
return ex;
949 if(m_enta_flag && runFlag>=3){
989DedxCorrecSvc::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 {
990 if(m_debug) cout<<
"DedxCorrecSvc::StandardHitCorrec"<<endl;
999 if( runNO<0 )
return ex;
1003 if( ntpFlag ==0)
return ex;
1007 if( m_rung_flag == 0 && m_wireg_flag == 0 && m_ddg_flag == 0
1008 && m_layerg_flag == 0 && m_zdep_flag == 0 && m_dcasin_flag==0
1009 && m_ggs_flag == 0 && m_enta_flag==0)
return ex;
1021 if( m_dcasin_flag) {
1032 if(m_enta_flag && runFlag>=3){
1055 if(m_debug) cout<<
"DedxCorrecSvc::StandardTrackCorrec"<<endl;
1056 if( runNO<0 )
return ex;
1057 if( ntpFlag ==0)
return ex;
1058 if( runFlag <3)
return ex;
1059 if( calib_rec_Flag ==1){
1061 if(m_t0_flag) ex=
T0Correc(t0, ex);
1081 if(m_rung_flag && calib_rec_Flag ==2){
1082 double rungain_temp =
RungCorrec( runNO, evtNO, ex )/ex;
1083 ex = ex/rungain_temp;
1094DedxCorrecSvc::init_param() {
1098 for(
int i = 0; i<6796 ; i++) {
1104 for(
int j = 0; j<100; j++){
1107 for(
int j = 0; j<43; j++) {
1113 for(
int k = 1; k<4; k++ ) {
1121 std::cout<<
"DedxCorrecSvc::init_param()!!!"<<std::endl;
1122 std::cout<<
"hello,init_param"<<endl;
1123 m_initConstFlg =
true;
1131 cout<<
"calib_F is = "<<calib_F<<endl;
1132 if(calib_F<0){ m_enta_flag = 0; calib_F =
abs(calib_F); }
1133 else m_enta_flag = 1;
1134 m_rung_flag = ( calib_F & 1 )? 1 : 0;
1135 m_wireg_flag = ( calib_F & 2 )? 1 : 0;
1136 m_dcasin_flag = ( calib_F & 4 )? 1 : 0;
1137 m_ggs_flag = ( calib_F & 8 )? 1 : 0;
1140 m_t0_flag = ( calib_F & 16 )? 1 : 0;
1141 m_sat_flag = ( calib_F & 32 )? 1 : 0;
1142 m_layerg_flag = ( calib_F & 64 )? 1 : 0;
1144 m_dip_flag = ( calib_F & 256 )? 1 : 0;
1145 m_mdcg_flag = ( calib_F & 512 )? 1 : 0;
1154HepPoint3D piv(hel.pivot());
1155double dr = hel.a()[0];
1156double phi0 = hel.a()[1];
1157double tanl = hel.a()[4];
1158double dz = hel.a()[3];
1160double dr = -19.1901;
1161double phi0 = 3.07309;
1162double tanl = -0.466654;
1165double csf0 = cos(phi0);
1166double snf0 = sin(phi0);
1167double x_c = dr*csf0;
1168double y_c = dr*snf0;
1169double z_c = hel.a()[3];
1175double m_zb, m_zf, Calpha;
1176// double sintheta = sin(M_PI_2-atan(hel.a()[4]));
1177double sintheta = sin(M_PI_2-atan(tanl));
1178// retrieve Mdc geometry information
1179double rcsiz1= geosvc->Layer(layer)->RCSiz1();
1180double rcsiz2= geosvc->Layer(layer)->RCSiz2();
1181double rlay= geosvc->Layer(layer)->Radius();
1182int ncell= geosvc->Layer(layer)->NCell();
1183double phioffset= geosvc->Layer(layer)->Offset();
1184float shift= geosvc->Layer(layer)->Shift();
1185double slant= geosvc->Layer(layer)->Slant();
1186double length = geosvc->Layer(layer)->Length();
1187int type = geosvc->Layer(layer)->Sup()->Type();
1188// shift = shift*type;
1190//conversion of the units(mm=>cm)
1197m_crio[0] = rlay - rcsiz1;
1198m_crio[1] = rlay + rcsiz2;
1201{ if(rlay<= fabs(dr)) rlay = rlay + rcsiz2;
1202if(rlay<fabs(dr)) return -1;
1203double t_digi = sqrt(rlay*rlay - dr*dr);
1204double x_t_digi = x_c - t_digi*snf0;
1205double y_t_digi = y_c + t_digi*csf0;
1206double z_t_digi = z_c + t_digi*tanl;
1207double x__t_digi = x_c + t_digi*snf0;
1208double y__t_digi = y_c - t_digi*csf0;
1209double z__t_digi = z_c - t_digi*tanl;
1210double phi_t_digi = atan2(y_t_digi,x_t_digi);
1211double phi__t_digi = atan2(y__t_digi,x__t_digi);
1212phi_t_digi = fmod( phi_t_digi+4*M_PI,2*M_PI );
1213phi__t_digi = fmod( phi__t_digi+4*M_PI,2*M_PI );
1214double phibin_digi = 2.0*M_PI/ncell;
1215double phi_cellid_digi = phioffset + shift*phibin_digi*0.5 + cellid *phibin_digi;
1216if(fabs(phi_cellid_digi - phi_t_digi)<fabs(phi_cellid_digi - phi__t_digi))
1218else if (fabs(phi_cellid_digi - phi_t_digi)>fabs(phi_cellid_digi - phi__t_digi))
1223int sign = 1; ///assumed the first half circle
1226Hep3Vector cell_IO[2];
1230 downin = (z*z-m_zb*m_zb)*pow(tan(slant),2);
1231 m_crio[0] = sqrt(m_crio[0]*m_crio[0]+downin);
1232 m_crio[1] = sqrt(m_crio[1]*m_crio[1]+downin);
1237if(m_crio[1]<fabs(dr)) return -1;
1238else if(m_crio[0]<fabs(dr)) {
1239 t[0] = sqrt(m_crio[1]*m_crio[1] - dr*dr);
1243 for( int i = 0; i < 2; i++ ) {
1244 if(m_crio[i]<fabs(dr)) return -1;
1245 t[i] = sqrt(m_crio[i]*m_crio[i] - dr*dr);
1249// calculate the cooridate of hits
1250double x_t[2],y_t[2],z_t[2];
1251double x__t[2],y__t[2],z__t[2];
1252double x_p[2],y_p[2],z_p[2];
1253for( int i = 0; i < 2; i++){
1254 x_t[i] = x_c - t[i]*snf0;
1255 y_t[i] = y_c + t[i]*csf0;
1256 z_t[i] = z_c + t[i]*tanl;
1257 x__t[i] = x_c + t[i]*snf0;
1258 y__t[i] = y_c - t[i]*csf0;
1259 z__t[i] = z_c - t[i]*tanl;
1262double phi_in_t,phi_in__t, phi_out_t,phi_out__t,phi_t,phi__t;
1263double phibin = 2.0*M_PI/ncell;
1264double phi_cellid = phioffset + shift*phibin*(0.5-z/length) + cellid *phibin;
1265phi_in_t = atan2(y_t[0],x_t[0]);
1266phi_out_t = atan2(y_t[1],x_t[1]);
1267phi_in__t = atan2(y__t[0],x__t[0]);
1268phi_out__t = atan2(y__t[1],x__t[1]);
1269phi_t = atan2(((y_t[0]+y_t[1])/2),((x_t[0]+x_t[1])/2));
1270phi__t = atan2(((y__t[0]+y__t[1])/2),((x__t[0]+x__t[1])/2));
1272phi_in_t = fmod( phi_in_t+4*M_PI,2*M_PI );
1273phi_out_t = fmod( phi_out_t+4*M_PI,2*M_PI );
1274phi_in__t = fmod( phi_in__t+4*M_PI,2*M_PI );
1275phi_out__t = fmod( phi_out__t+4*M_PI,2*M_PI );
1276phi_t = fmod( phi_t+4*M_PI,2*M_PI );
1277phi__t = fmod( phi__t+4*M_PI,2*M_PI );
1278phi_cellid = fmod( phi_cellid+4*M_PI,2*M_PI );
1280if(fabs(phi_cellid - phi_t)<fabs(phi_cellid - phi__t))
1282 for(int i =0; i<2; i++ )
1287else if (fabs(phi_cellid - phi_t)>fabs(phi_cellid - phi__t))
1289 for(int i =0; i<2; i++ )
1296 for(int i =0; i<2; i++ )
1302//calculate path length in r_phi plane and all length in this layer
1303double ch_ltrk_rp, ch_ltrk;
1304ch_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]));
1305ch_ltrk = ch_ltrk_rp/sintheta;
1306//give cellid of in and out of this layer
1307double phi_in,phi_out;
1308phi_in = atan2(y_p[0],x_p[0]);
1309phi_out = atan2(y_p[1],x_p[1]);
1310phi_in = fmod( phi_in+4*M_PI,2*M_PI );
1311phi_out = fmod( phi_out+4*M_PI,2*M_PI );
1313//determine the in/out cellid
1314double inlow, inup, outlow, outup, gap, phi1, phi2, phi_mid, phi_midin, phi_midout;
1316// int cid_in_t,cid_in__t,cid_out_t,cid_out__t;
1317//cache sampl in each cell for this layer
1318std::vector<double> phi_entrance;
1319std::vector<double> sampl;
1321phi_entrance.resize(ncell);
1322for(int k=0; k<ncell; k++) {
1324 phi_entrance[k] = 0;
1327cid_in = cid_out = -1;
1328phibin = 2.0*M_PI/ncell;
1329//determine the in/out cell id
1330double stphi[2], phioff[2];
1331stphi[0] = shift*phibin*(0.5-z_p[0]/length);
1332stphi[1] = shift*phibin*(0.5-z_p[1]/length);
1333phioff[0] = phioffset+stphi[0];
1334phioff[1] = phioffset+stphi[1];
1335for(int i=0; i<ncell; i++) {
1337 // phi[i] = phioff[0]+phibin*i;
1338 inlow = phioff[0]+phibin*i-phibin*0.5;
1339 inup = phioff[0]+phibin*i+phibin*0.5;
1340 outlow = phioff[1]+phibin*i-phibin*0.5;
1341 outup = phioff[1]+phibin*i+phibin*0.5;
1342 inlow = fmod( inlow+4*M_PI,2*M_PI );
1343 inup = fmod( inup+4*M_PI,2*M_PI );
1344 outlow = fmod( outlow+4*M_PI,2*M_PI );
1345 outup = fmod( outup+4*M_PI,2*M_PI );
1347 cout << "shift " << shift<< " cellid " << i
1348 <<" phi_in " << phi_in << " phi_out " << phi_out
1349 << " inup "<< inup << " inlow " << inlow
1350 << " outup "<< outup << " outlow " << outlow << endl;
1352 if(phi_in>=inlow&&phi_in<inup) cid_in = i;
1353 if(phi_out>=outlow&&phi_out<outup) cid_out = i;
1355 if((phi_in>=inlow&&phi_in<2.0*M_PI)||(phi_in>=0.0&&phi_in<inup)) cid_in = i;
1357 if ( outlow>outup) {
1358 if((phi_out>=outlow&&phi_out<2.0*M_PI)||(phi_out>=0.0&&phi_out<outup)) cid_out = i;
1362// judge how many cells are traversed and deal with different situations
1363phi_midin = phi_midout = phi1 = phi2 = -999.0;
1365//only one cell traversed
1366if( cid_in == cid_out) {
1367 sampl[cid_in] = ch_ltrk;
1370} else if(cid_in < cid_out) {
1371 //in cell id less than out cell id
1372 //deal with the special case crossing x axis
1373 if( cid_out-cid_in>ncell/2 ) {
1374 // if(gap>=M_PI) gap = 2.0*M_PI-gap;
1375 phi_midin = phioff[0]+phibin*cid_in-phibin*0.5;
1376 phi_midout = phioff[1]+phibin*cid_out+phibin*0.5;
1377 phi_midin = fmod( phi_midin+4*M_PI,2*M_PI );
1378 phi_midout = fmod( phi_midout+4*M_PI,2*M_PI );
1379 phi1 = phi_midout-phi_out;
1380 phi2 = phi_in-phi_midin;
1381 phi1 = fmod(phi1+2.0*M_PI,2.0*M_PI);
1382 phi2 = fmod(phi2+2.0*M_PI,2.0*M_PI);
1383 gap = phi1+phi2+(ncell-1-cid_out+cid_in)*phibin;
1384 gap = fmod(gap+2.0*M_PI,2.0*M_PI);
1385 sampl[cid_in]=phi2/gap*ch_ltrk;
1386 sampl[cid_out]=phi1/gap*ch_ltrk;
1388 for( int jj = cid_out+1; jj<ncell; jj++) {
1389 sampl[jj]=phibin/gap*ch_ltrk;
1391 for( int jj = 0; jj<cid_in; jj++) {
1392 sampl[jj]=phibin/gap*ch_ltrk;
1397 phi_midin = phioff[0]+phibin*cid_in+phibin*0.5;
1398 phi_midout = phioff[1]+phibin*cid_out-phibin*0.5;
1399 phi_midin = fmod( phi_midin+4*M_PI,2*M_PI );
1400 phi_midout = fmod( phi_midout+4*M_PI,2*M_PI );
1401 phi1 = phi_midin-phi_in;
1402 phi2 = phi_out-phi_midout;
1403 phi1 = fmod(phi1+2.0*M_PI,2.0*M_PI);
1404 phi2 = fmod(phi2+2.0*M_PI,2.0*M_PI);
1405 gap = phi1+phi2+(cid_out-cid_in-1)*phibin;
1406 gap = fmod(gap+2.0*M_PI,2.0*M_PI);
1407 sampl[cid_in]=phi1/gap*ch_ltrk;
1408 sampl[cid_out]=phi2/gap*ch_ltrk;
1409 phi_entrance[cid_in] = phi_in;
1410 phi_entrance[cid_out] = phi_midout;
1411 for( int jj = cid_in+1; jj<cid_out; jj++) {
1412 sampl[jj]=phibin/gap*ch_ltrk;
1415} else if(cid_in > cid_out) {
1416 //in cell id greater than out cell id
1417 //deal with the special case crossing x axis
1418 if( cid_in-cid_out>ncell/2 ) {
1419 // if(gap>=M_PI) gap = 2.0*M_PI-gap;
1420 phi_midin = phioff[0]+phibin*cid_in+phibin*0.5;
1421 phi_midout = phioff[1]+phibin*cid_out-phibin*0.5;
1422 phi_midin = fmod( phi_midin+4*M_PI,2*M_PI );
1423 phi_midout = fmod( phi_midout+4*M_PI,2*M_PI );
1424 phi1 = phi_midin-phi_in;
1425 phi2 = phi_out-phi_midout;
1426 phi1 = fmod(phi1+2.0*M_PI,2.0*M_PI);
1427 phi2 = fmod(phi2+2.0*M_PI,2.0*M_PI);
1428 gap = phi1+phi2+(ncell-1-cid_in+cid_out)*phibin;
1429 gap = fmod(gap+2.0*M_PI,2.0*M_PI);
1430 sampl[cid_out]=phi2/gap*ch_ltrk;
1431 sampl[cid_in]=phi1/gap*ch_ltrk;
1433 for( int jj = cid_in+1; jj<ncell; jj++) {
1434 sampl[jj]=phibin/gap*ch_ltrk;
1436 for( int jj = 0; jj<cid_out; jj++) {
1437 sampl[jj]=phibin/gap*ch_ltrk;
1441 phi_midin = phioff[0]+phibin*cid_in-phibin*0.5;
1442 phi_midout = phioff[1]+phibin*cid_out+phibin*0.5;
1443 phi_midin = fmod( phi_midin+4*M_PI,2*M_PI );
1444 phi_midout = fmod( phi_midout+4*M_PI,2*M_PI );
1445 phi1 = phi_midout-phi_out;
1446 phi2 = phi_in-phi_midin;
1447 phi1 = fmod(phi1+2.0*M_PI,2.0*M_PI);
1448 phi2 = fmod(phi2+2.0*M_PI,2.0*M_PI);
1449 gap = phi1+phi2+(cid_in-cid_out-1)*phibin;
1450 gap = fmod(gap+2.0*M_PI,2.0*M_PI);
1451 sampl[cid_in]=phi2/gap*ch_ltrk;
1452 sampl[cid_out]=phi1/gap*ch_ltrk;
1453 for( int jj = cid_out+1; jj<cid_in; jj++) {
1454 sampl[jj]=phibin/gap*ch_ltrk;
1460if(sampl[cellid]<0.0) {
1461 if(cid_in!=cid_out) cout<<"?????????"<<endl;
1462 cout<< "layerId " << layer <<" cell id "<< cellid <<" shift " << shift
1463 << " cid_in " << cid_in << " cid_out " << cid_out << endl;
1465 cout <<" phi_in " << phi_in <<" phi_midin " << phi_midin << " phi_out "
1466 << phi_out << " phi_midout " << phi_midout <<endl;
1467 cout<<"total sampl " << ch_ltrk << " gap "<< gap << " phi1 "
1468 << phi1 << " phi2 " << phi2 << " phibin " << phibin << endl;
1471 for(int l=0; l<ncell; l++) {
1473 cout<<"picked cellid " << l << " sampling length "<< sampl[l]<< endl;
1477return sampl[cellid];
1490 int genlay = geosvc->
Layer(layer)->
Gen();
1498 HepPoint3D East_origin(East_lay_X, East_lay_Y, East_lay_Z);
1499 HepPoint3D West_origin(West_lay_X, West_lay_Y, West_lay_Z);
1500 Hep3Vector wire = (CLHEP::Hep3Vector)East_origin - (CLHEP::Hep3Vector)West_origin;
1501 HepPoint3D piovt_z =(z*10+length/2 )/length * wire + West_origin;
1502 piovt_z = piovt_z*0.1;
1509 double dr0 = hel.
a()[0];
1510 double phi0 = hel.
a()[1];
1511 double kappa = hel.
a()[2];
1512 double dz0 = hel.
a()[3];
1513 double tanl = hel.
a()[4];
1517 double ALPHA_loc = 1000/(2.99792458*Bz);
1523 int charge = ( kappa >= 0 )? 1 : -1;
1524 double rho = ALPHA_loc/kappa;
1525 double pt = fabs( 1.0/kappa );
1526 double lambda = atan( tanl );
1527 double theta = M_PI_2- lambda;
1528 double sintheta =
sin(M_PI_2-atan(tanl));
1530 double phi = fmod(phi0 +
M_PI*4,
M_PI*2);
1531 double csf0 =
cos(phi);
1532 double snf0 = (1. - csf0) * (1. + csf0);
1533 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
1534 if(phi >
M_PI) snf0 = - snf0;
1539 double x_c = piv.x() + ( hel.
dr() + rho )*csf0;
1540 double y_c = piv.y() + ( hel.
dr() + rho )*snf0;
1541 double z_c = piv.z() + hel.
dz();
1543 double m_c_perp(ccenter.perp());
1544 Hep3Vector m_c_unit((
HepPoint3D)ccenter.unit());
1548 double x_c_boost = x_c - piovt_z.x();
1549 double y_c_boost = y_c - piovt_z.y();
1550 double z_c_boost = z_c - piovt_z.z();
1551 HepPoint3D ccenter_boost(x_c_boost, y_c_boost, 0.0);
1552 double m_c_perp_boost(ccenter_boost.perp());
1555 Hep3Vector m_c_unit_boost((
HepPoint3D)ccenter_boost.unit());
1560 double dphi0 = fmod( IO.phi()+4*
M_PI,2*
M_PI ) - phi;
1561 double IO_phi = fmod( IO.phi()+4*
M_PI,2*
M_PI );
1565 if( dphi0 >
M_PI ) dphi0 -= 2*
M_PI;
1566 else if( dphi0 < -
M_PI ) dphi0 += 2*
M_PI;
1571 phi_io[1] = phi_io[0]+1.5*
M_PI;
1574 double m_zb, m_zf, Calpha;
1591 int wid = w0id + cellid;
1594 double x_lay_backward = geosvc->
Wire(layer, cellid)->
Backward().x();
1595 double y_lay_backward = geosvc->
Wire(layer, cellid)->
Backward().y();
1596 double x_lay_forward = geosvc->
Wire(layer, cellid)->
Forward().x();
1597 double y_lay_forward = geosvc->
Wire(layer, cellid)->
Forward().y();
1598 double r_lay_backward = sqrt(x_lay_backward*x_lay_backward+y_lay_backward*y_lay_backward);
1599 double r_lay_forward = sqrt(x_lay_forward*x_lay_forward+y_lay_forward*y_lay_forward);
1600 double r_lay_use = ((z*10+length/2)/length)*(r_lay_backward-r_lay_forward) + r_lay_forward;
1608 r_lay_use = 0.1*r_lay_use;
1609 rcsiz1 = 0.1*rcsiz1;
1610 rcsiz2 = 0.1*rcsiz2;
1612 length = 0.1*length;
1615 m_crio[0] = rlay - rcsiz1;
1616 m_crio[1] = rlay + rcsiz2;
1620 Hep3Vector iocand[2];
1621 Hep3Vector cell_IO[2];
1622 double dphi, downin;
1626 downin = (z*z-m_zb*m_zb)*pow(
tan(slant),2);
1627 m_crio[0] = sqrt(m_crio[0]*m_crio[0]+downin);
1628 m_crio[1] = sqrt(m_crio[1]*m_crio[1]+downin);
1633 for(
int i = 0; i < 2; i++ ) {
1634 double cos_alpha = m_c_perp_boost*m_c_perp_boost + m_crio[i]*m_crio[i] - rho*rho;
1635 cos_alpha = 0.5*cos_alpha/( m_c_perp_boost*m_crio[i] );
1636 if(fabs(cos_alpha)>1&&i==0)
return(-1.0);
1637 if(fabs(cos_alpha)>1&&i==1) {
1638 cos_alpha = m_c_perp_boost*m_c_perp_boost + m_crio[0]*m_crio[0] - rho*rho;
1639 cos_alpha = 0.5*cos_alpha/( m_c_perp_boost*m_crio[0] );
1640 Calpha = 2.0*
M_PI-acos( cos_alpha );
1642 Calpha = acos( cos_alpha );
1645 iocand[i] = m_c_unit_boost;
1646 iocand[i].rotateZ(
charge*sign*Calpha );
1647 iocand[i]*= m_crio[i];
1654 iocand[i] = iocand[i]+ piovt_z;
1659 double xx = iocand[i].x() - x_c;
1660 double yy = iocand[i].y() - y_c;
1662 dphi = atan2(yy, xx) - phi0 - M_PI_2*(1-
charge);
1663 dphi = fmod( dphi + 8.0*
M_PI, 2*
M_PI );
1665 if( dphi < phi_io[0] ) {
1668 else if( phi_io[1] < dphi ) {
1674 Hep3Vector zvector( 0., 0., z_c-rho*dphi*tanl-piovt_z.z());
1676 cell_IO[i] = iocand[i];
1677 cell_IO[i] += zvector;
1682 double xcio, ycio, phip;
1714 cell_IO[i] = hel.
x(dphi);
1721 Hep3Vector cl = cell_IO[1] - cell_IO[0];
1727 double ch_ltrk_rp = 0;
1728 ch_dphi = cl.perp()*0.5/(ALPHA_loc*pt);
1729 ch_dphi = 2.0 * asin( ch_dphi );
1730 ch_ltrk_rp = ch_dphi*ALPHA_loc*pt;
1731 double rpi_path = sqrt(cl.x()*cl.x()+cl.y()*cl.y());
1732 ch_ltrk = sqrt( ch_ltrk_rp*ch_ltrk_rp + cl.z()*cl.z() );
1733 double path = ch_ltrk_rp/ sintheta;
1734 ch_theta = cl.theta();
1750 double phibin, phi_in, phi_out, inlow, inup, outlow, outup, gap,
phi1,
phi2, phi_mid, phi_midin, phi_midout;
1751 int cid_in, cid_out;
1752 double inlow_z, inup_z, outlow_z, outup_z, gap_z, phi1_z, phi2_z, phi_mid_z, phi_midin_z, phi_midout_z;
1755 std::vector<double> sampl;
1756 sampl.resize(ncell);
1757 for(
int k=0; k<ncell; k++) {
1761 cid_in = cid_out = -1;
1762 phi_in = cell_IO[0].phi();
1763 phi_out = cell_IO[1].phi();
1766 phi_in = fmod( phi_in+4*
M_PI,2*
M_PI );
1767 phi_out = fmod( phi_out+4*
M_PI,2*
M_PI );
1768 phibin = 2.0*
M_PI/ncell;
1772 Hep3Vector cell_mid=0.5*(cell_IO[0]+cell_IO[1]);
1777 double stphi[2], phioff[2];
1778 stphi[0] = shift*phibin*(0.5-cell_IO[0].z()/length);
1779 stphi[1] = shift*phibin*(0.5-cell_IO[1].z()/length);
1782 phioff[0] = phioffset+stphi[0];
1783 phioff[1] = phioffset+stphi[1];
1785 for(
int i=0; i<ncell; i++) {
1787 double x_lay_backward_cell = geosvc->
Wire(layer, i)->
Backward().x()*0.1;
1788 double y_lay_backward_cell = geosvc->
Wire(layer, i)->
Backward().y()*0.1;
1789 double x_lay_forward_cell = geosvc->
Wire(layer, i)->
Forward().x()*0.1;
1790 double y_lay_forward_cell = geosvc->
Wire(layer, i)->
Forward().y()*0.1;
1793 Hep3Vector lay_backward(x_lay_backward_cell, y_lay_backward_cell, 0);
1794 Hep3Vector lay_forward(x_lay_forward_cell, y_lay_forward_cell, 0);
1795 Hep3Vector Cell_z[2];
1796 Cell_z[0] = ((cell_IO[0].z()+length/2)/length)*(lay_backward - lay_forward) + lay_forward;
1797 Cell_z[1] = ((cell_IO[1].z()+length/2)/length)*(lay_backward - lay_forward) + lay_forward;
1799 z_phi[0] = Cell_z[0].phi();
1800 z_phi[1] = Cell_z[1].phi();
1801 z_phi[0] = fmod( z_phi[0]+4*
M_PI,2*
M_PI );
1802 z_phi[1] = fmod( z_phi[1]+4*
M_PI,2*
M_PI );
1814 inlow_z = z_phi[0] - phibin*0.5;
1815 inup_z = z_phi[0] + phibin*0.5;
1816 outlow_z = z_phi[1] - phibin*0.5;
1817 outup_z = z_phi[1] + phibin*0.5;
1818 inlow_z = fmod( inlow_z+4*
M_PI,2*
M_PI );
1819 inup_z = fmod( inup_z+4*
M_PI,2*
M_PI );
1820 outlow_z = fmod( outlow_z+4*
M_PI,2*
M_PI );
1821 outup_z = fmod( outup_z+4*
M_PI,2*
M_PI );
1825 inlow = phioff[0]+phibin*i-phibin*0.5;
1826 inup = phioff[0]+phibin*i+phibin*0.5;
1827 outlow = phioff[1]+phibin*i-phibin*0.5;
1828 outup = phioff[1]+phibin*i+phibin*0.5;
1829 inlow = fmod( inlow+4*
M_PI,2*
M_PI );
1831 outlow = fmod( outlow+4*
M_PI,2*
M_PI );
1832 outup = fmod( outup+4*
M_PI,2*
M_PI );
1835 if(ntpFlag > 0) cout <<
"shift " << shift
1836 <<
" phi_in " << phi_in <<
" phi_out " << phi_out
1837 <<
" inup "<< inup <<
" inlow " << inlow
1838 <<
" outup "<< outup <<
" outlow " << outlow << endl;
1850 if(phi_in>=inlow_z&&phi_in<inup_z) cid_in = i;
1851 if(phi_out>=outlow_z&&phi_out<outup_z) cid_out = i;
1852 if ( inlow_z>inup_z) {
1853 if((phi_in>=inlow_z&&phi_in<2.0*
M_PI)||(phi_in>=0.0&&phi_in<inup_z)) cid_in = i;
1855 if ( outlow_z>outup_z) {
1856 if((phi_out>=outlow_z&&phi_out<2.0*
M_PI)||(phi_out>=0.0&&phi_out<outup_z)) cid_out = i;
1860 phi_midin = phi_midout =
phi1 =
phi2 = -999.0;
1864 if(cid_in == -1 || cid_out == -1)
return -1;
1866 if( cid_in == cid_out) {
1867 sampl[cid_in]= ch_ltrk;
1869 return sampl[cellid];
1870 }
else if(cid_in < cid_out) {
1873 if( cid_out-cid_in>ncell/2 ) {
1876 double x_lay_backward_cin = geosvc->
Wire(layer, cid_in)->
Backward().x()*0.1;
1877 double y_lay_backward_cin = geosvc->
Wire(layer, cid_in)->
Backward().y()*0.1;
1878 double x_lay_forward_cin = geosvc->
Wire(layer, cid_in)->
Forward().x()*0.1;
1879 double y_lay_forward_cin = geosvc->
Wire(layer, cid_in)->
Forward().y()*0.1;
1880 Hep3Vector lay_backward_cin(x_lay_backward_cin, y_lay_backward_cin, 0);
1881 Hep3Vector lay_forward_cin(x_lay_forward_cin, y_lay_forward_cin, 0);
1882 Hep3Vector Cell_z[2];
1883 Cell_z[0]=((cell_IO[0].z()+length/2)/length)*(lay_backward_cin-lay_forward_cin)+lay_forward_cin;
1884 double phi_cin_z = Cell_z[0].phi();
1885 phi_cin_z = fmod( phi_cin_z+4*
M_PI,2*
M_PI );
1886 double x_lay_backward_cout = geosvc->
Wire(layer, cid_out)->
Backward().x()*0.1;
1887 double y_lay_backward_cout = geosvc->
Wire(layer, cid_out)->
Backward().y()*0.1;
1888 double x_lay_forward_cout = geosvc->
Wire(layer, cid_out)->
Forward().x()*0.1;
1889 double y_lay_forward_cout = geosvc->
Wire(layer, cid_out)->
Forward().y()*0.1;
1890 Hep3Vector lay_backward_cout(x_lay_backward_cout, y_lay_backward_cout, 0);
1891 Hep3Vector lay_forward_cout(x_lay_forward_cout, y_lay_forward_cout, 0);
1892 Cell_z[1]=((cell_IO[1].z()+length/2)/length)*(lay_backward_cout-lay_forward_cout)+lay_forward_cout;
1893 double phi_cout_z = Cell_z[1].phi();
1894 phi_cout_z = fmod( phi_cout_z+4*
M_PI,2*
M_PI );
1896 phi_midin_z = phi_cin_z-phibin*0.5;
1897 phi_midout_z = phi_cout_z+phibin*0.5;
1898 phi_midin_z = fmod( phi_midin_z+4*
M_PI,2*
M_PI );
1899 phi_midout_z = fmod( phi_midout_z+4*
M_PI,2*
M_PI );
1900 phi1_z = phi_midout_z-phi_out;
1901 phi2_z = phi_in-phi_midin_z;
1902 phi1_z = fmod(phi1_z+2.0*
M_PI,2.0*
M_PI);
1903 phi2_z = fmod(phi2_z+2.0*
M_PI,2.0*
M_PI);
1904 gap_z = phi1_z+phi2_z+(ncell-1-cid_out+cid_in)*phibin;
1905 gap_z = fmod(gap_z+2.0*
M_PI,2.0*
M_PI);
1906 sampl[cid_in]=phi2_z/gap_z*ch_ltrk;
1907 sampl[cid_out]=phi1_z/gap_z*ch_ltrk;
1908 for(
int jj = cid_out+1; jj<ncell; jj++) {
1909 sampl[jj]=phibin/gap_z*ch_ltrk;
1911 for(
int jj = 0; jj<cid_in; jj++) {
1912 sampl[jj]=phibin/gap_z*ch_ltrk;
1946 double x_lay_backward_cin = geosvc->
Wire(layer, cid_in)->
Backward().x()*0.1;
1947 double y_lay_backward_cin = geosvc->
Wire(layer, cid_in)->
Backward().y()*0.1;
1948 double x_lay_forward_cin = geosvc->
Wire(layer, cid_in)->
Forward().x()*0.1;
1949 double y_lay_forward_cin = geosvc->
Wire(layer, cid_in)->
Forward().y()*0.1;
1950 Hep3Vector lay_backward_cin(x_lay_backward_cin, y_lay_backward_cin, 0);
1951 Hep3Vector lay_forward_cin(x_lay_forward_cin, y_lay_forward_cin, 0);
1952 Hep3Vector Cell_z[2];
1953 Cell_z[0]=((cell_IO[0].z()+length/2)/length)*(lay_backward_cin-lay_forward_cin)+lay_forward_cin;
1954 double phi_cin_z = Cell_z[0].phi();
1955 phi_cin_z = fmod( phi_cin_z+4*
M_PI,2*
M_PI );
1956 double x_lay_backward_cout = geosvc->
Wire(layer, cid_out)->
Backward().x()*0.1;
1957 double y_lay_backward_cout = geosvc->
Wire(layer, cid_out)->
Backward().y()*0.1;
1958 double x_lay_forward_cout = geosvc->
Wire(layer, cid_out)->
Forward().x()*0.1;
1959 double y_lay_forward_cout = geosvc->
Wire(layer, cid_out)->
Forward().y()*0.1;
1960 Hep3Vector lay_backward_cout(x_lay_backward_cout, y_lay_backward_cout, 0);
1961 Hep3Vector lay_forward_cout(x_lay_forward_cout, y_lay_forward_cout, 0);
1962 Cell_z[1]=((cell_IO[1].z()+length/2)/length)*(lay_backward_cout-lay_forward_cout)+lay_forward_cout;
1963 double phi_cout_z = Cell_z[1].phi();
1964 phi_cout_z = fmod( phi_cout_z+4*
M_PI,2*
M_PI );
1966 phi_midin_z = phi_cin_z+phibin*0.5;
1967 phi_midout_z = phi_cout_z-phibin*0.5;
1968 phi_midin_z = fmod( phi_midin_z+4*
M_PI,2*
M_PI );
1969 phi_midout_z = fmod( phi_midout_z+4*
M_PI,2*
M_PI );
1970 phi1_z = phi_midin_z-phi_in;
1971 phi2_z = phi_out-phi_midout_z;
1972 phi1_z = fmod(phi1_z+2.0*
M_PI,2.0*
M_PI);
1973 phi2_z = fmod(phi2_z+2.0*
M_PI,2.0*
M_PI);
1974 gap_z = phi1_z+phi2_z+(cid_out-cid_in-1)*phibin;
1975 gap_z = fmod(gap_z+2.0*
M_PI,2.0*
M_PI);
1976 sampl[cid_in]=phi1_z/gap_z*ch_ltrk;
1977 sampl[cid_out]=phi2_z/gap_z*ch_ltrk;
1978 for(
int jj = cid_in+1; jj<cid_out; jj++) {
1979 sampl[jj]=phibin/gap_z*ch_ltrk;
1999 }
else if(cid_in > cid_out) {
2002 if( cid_in-cid_out>ncell/2 ) {
2003 double x_lay_backward_cin = geosvc->
Wire(layer, cid_in)->
Backward().x()*0.1;
2004 double y_lay_backward_cin = geosvc->
Wire(layer, cid_in)->
Backward().y()*0.1;
2005 double x_lay_forward_cin = geosvc->
Wire(layer, cid_in)->
Forward().x()*0.1;
2006 double y_lay_forward_cin = geosvc->
Wire(layer, cid_in)->
Forward().y()*0.1;
2007 Hep3Vector lay_backward_cin(x_lay_backward_cin, y_lay_backward_cin, 0);
2008 Hep3Vector lay_forward_cin(x_lay_forward_cin, y_lay_forward_cin, 0);
2009 Hep3Vector Cell_z[2];
2010 Cell_z[0]=((cell_IO[0].z()+length/2)/length)*(lay_backward_cin-lay_forward_cin)+lay_forward_cin;
2011 double phi_cin_z = Cell_z[0].phi();
2012 phi_cin_z = fmod( phi_cin_z+4*
M_PI,2*
M_PI );
2013 double x_lay_backward_cout = geosvc->
Wire(layer, cid_out)->
Backward().x()*0.1;
2014 double y_lay_backward_cout = geosvc->
Wire(layer, cid_out)->
Backward().y()*0.1;
2015 double x_lay_forward_cout = geosvc->
Wire(layer, cid_out)->
Forward().x()*0.1;
2016 double y_lay_forward_cout = geosvc->
Wire(layer, cid_out)->
Forward().y()*0.1;
2017 Hep3Vector lay_backward_cout(x_lay_backward_cout, y_lay_backward_cout, 0);
2018 Hep3Vector lay_forward_cout(x_lay_forward_cout, y_lay_forward_cout, 0);
2019 Cell_z[1]=((cell_IO[1].z()+length/2)/length)*(lay_backward_cout-lay_forward_cout)+lay_forward_cout;
2020 double phi_cout_z = Cell_z[1].phi();
2021 phi_cout_z = fmod( phi_cout_z+4*
M_PI,2*
M_PI );
2023 phi_midin_z = phi_cin_z+phibin*0.5;
2024 phi_midout_z = phi_cout_z-phibin*0.5;
2025 phi_midin_z = fmod( phi_midin_z+4*
M_PI,2*
M_PI );
2026 phi_midout_z = fmod( phi_midout_z+4*
M_PI,2*
M_PI );
2027 phi1_z = phi_midin_z-phi_in;
2028 phi2_z = phi_out-phi_midout_z;
2029 phi1_z = fmod(phi1_z+2.0*
M_PI,2.0*
M_PI);
2030 phi2_z = fmod(phi2_z+2.0*
M_PI,2.0*
M_PI);
2031 gap_z = phi1_z+phi2_z+(ncell-1-cid_in+cid_out)*phibin;
2032 gap_z = fmod(gap_z+2.0*
M_PI,2.0*
M_PI);
2033 sampl[cid_out]=phi2_z/gap_z*ch_ltrk;
2034 sampl[cid_in]=phi1_z/gap_z*ch_ltrk;
2035 for(
int jj = cid_in+1; jj<ncell; jj++) {
2036 sampl[jj]=phibin/gap_z*ch_ltrk;
2038 for(
int jj = 0; jj<cid_out; jj++) {
2039 sampl[jj]=phibin/gap_z*ch_ltrk;
2071 double x_lay_backward_cin = geosvc->
Wire(layer, cid_in)->
Backward().x()*0.1;
2072 double y_lay_backward_cin = geosvc->
Wire(layer, cid_in)->
Backward().y()*0.1;
2073 double x_lay_forward_cin = geosvc->
Wire(layer, cid_in)->
Forward().x()*0.1;
2074 double y_lay_forward_cin = geosvc->
Wire(layer, cid_in)->
Forward().y()*0.1;
2075 Hep3Vector lay_backward_cin(x_lay_backward_cin, y_lay_backward_cin, 0);
2076 Hep3Vector lay_forward_cin(x_lay_forward_cin, y_lay_forward_cin, 0);
2077 Hep3Vector Cell_z[2];
2078 Cell_z[0]=((cell_IO[0].z()+length/2)/length)*(lay_backward_cin-lay_forward_cin)+lay_forward_cin;
2079 double phi_cin_z = Cell_z[0].phi();
2080 phi_cin_z = fmod( phi_cin_z+4*
M_PI,2*
M_PI );
2081 double x_lay_backward_cout = geosvc->
Wire(layer, cid_out)->
Backward().x()*0.1;
2082 double y_lay_backward_cout = geosvc->
Wire(layer, cid_out)->
Backward().y()*0.1;
2083 double x_lay_forward_cout = geosvc->
Wire(layer, cid_out)->
Forward().x()*0.1;
2084 double y_lay_forward_cout = geosvc->
Wire(layer, cid_out)->
Forward().y()*0.1;
2085 Hep3Vector lay_backward_cout(x_lay_backward_cout, y_lay_backward_cout, 0);
2086 Hep3Vector lay_forward_cout(x_lay_forward_cout, y_lay_forward_cout, 0);
2087 Cell_z[1]=((cell_IO[1].z()+length/2)/length)*(lay_backward_cout-lay_forward_cout)+lay_forward_cout;
2088 double phi_cout_z = Cell_z[1].phi();
2089 phi_cout_z = fmod( phi_cout_z+4*
M_PI,2*
M_PI );
2091 phi_midin_z = phi_cin_z-phibin*0.5;
2092 phi_midout_z = phi_cout_z+phibin*0.5;
2093 phi_midin_z = fmod( phi_midin_z+4*
M_PI,2*
M_PI );
2094 phi_midout_z = fmod( phi_midout_z+4*
M_PI,2*
M_PI );
2095 phi1_z = phi_midout_z-phi_out;
2096 phi2_z = phi_in-phi_midin_z;
2097 phi1_z = fmod(phi1_z+2.0*
M_PI,2.0*
M_PI);
2098 phi2_z = fmod(phi2_z+2.0*
M_PI,2.0*
M_PI);
2099 gap_z = phi1_z+phi2_z+(cid_in-cid_out-1)*phibin;
2100 gap_z = fmod(gap_z+2.0*
M_PI,2.0*
M_PI);
2101 sampl[cid_in]=phi2_z/gap_z*ch_ltrk;
2102 sampl[cid_out]=phi1_z/gap_z*ch_ltrk;
2103 for(
int jj = cid_out+1; jj<cid_in; jj++) {
2104 sampl[jj]=phibin/gap_z*ch_ltrk;
2127 if(sampl[cellid]<0.0) {
2128 if(cid_in!=cid_out) cout<<
"?????????"<<endl;
2129 cout<<
"layerId " << layer <<
" cell id "<< cellid <<
" shift " << shift
2130 <<
" cid_in " << cid_in <<
" cid_out " << cid_out << endl;
2132 cout <<
" phi_in " << phi_in <<
" phi_midin " << phi_midin <<
" phi_out "
2133 << phi_out <<
" phi_midout " << phi_midout <<endl;
2134 cout<<
"total sampl " << ch_ltrk <<
" gap "<< gap <<
" phi1 "
2135 <<
phi1 <<
" phi2 " <<
phi2 <<
" phibin " << phibin << endl;
2138 for(
int l=0; l<ncell; l++) {
2140 cout<<
"picked cellid " << l <<
" sampling length "<< sampl[l]<< endl;
2144 return sampl[cellid];
2154 double absCosTheta = fabs(cosTheta);
2155 double projection = pow(absCosTheta,m_power) + m_delta;
2156 double chargeDensity = D/projection;
2157 double numerator = 1 + m_alpha*chargeDensity;
2158 double denominator = 1 + m_gamma*chargeDensity;
2163 I = D * m_ratio* numerator/denominator;
2176 double absCosTheta = fabs(cosTheta);
2177 double projection = pow(absCosTheta,m_power) + m_delta;
2180 double a = m_alpha / projection;
2181 double b = 1 - m_gamma / projection*(
I/m_ratio);
2182 double c = -
I/m_ratio;
2185 cout<<
"both a and b coefficiants for hadron correction are 0"<<endl;
2189 double D = a != 0? (-
b + sqrt(
b*
b - 4.0*a*c))/(2.0*a) : -c/
b;
2191 cout<<
"D is less 0! will try another solution"<<endl;
2192 D=a != 0? (-
b - sqrt(
b*
b + 4.0*a*c))/(2.0*a) : -c/
b;
2194 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
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
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