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<10000;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;
221 for(
int i=0;i<4;i++) {
222 for(
int j=0;j<43;j++) {
223 m_ddg[i][j] =
test->getddg(i,j);
224 m_ggs[i][j] =
test->getggs(i,j);
225 m_zdep[i][j] =
test->getzdep(i,j);
234 m_dedx_gain =
test->getgain();
235 std::cout<<
"gain="<<m_dedx_gain<<
"\n";
237 m_dedx_resol =
test->getresol();
238 std::cout<<
"resol="<<m_dedx_resol<<
"\n";
240 for(
int i=0;i<43;i++) {
241 m_layer_g[i] =
test -> getlayerg(i);
242 if(m_layer_g[i]>2.0 || m_layer_g[i]<0.5) m_layer_g[i] =1;
258 for(
int i=0;i<6796;i++) {
259 m_wire_g[i] =
test -> getwireg(i);
269 for(
int i=0;i<6796;i++) {
272 for(
int j=0; j<25; j++){
273 if( i == dead_wire[kk][j] )
302 for(
int i=0; i<nbin; i++){
303 cos.push_back(
test -> get_costheta(i));
305 for(
int i=0;i<nbin-1;i++){
310 double x1=-1.00+(0.5+i)*(2.00/nbin);
312 double x2=-1.00+(0.5+i+1)*(2.00/nbin);
315 if(fabs(x1)>0.8) x1 =
f_larcos(x1, nbin);
316 if(fabs(x2)>0.8) x2 =
f_larcos(x2, nbin);
323 double x1=-1.00+(0.5+i-1)*(2.00/nbin);
325 double x2=-1.00+(0.5+i)*(2.00/nbin);
328 if(fabs(x1)>0.8) x1 =
f_larcos(x1, nbin);
329 if(fabs(x2)>0.8) x2 =
f_larcos(x2, nbin);
338 if(
cos[i-1]>0.0001 &&
cos[i+1]>0.0001){
339 double x1=-1.00+(0.5+i-1)*(2.00/nbin);
341 double x2=-1.00+(0.5+i+1)*(2.00/nbin);
344 if(fabs(x1)>0.8) x1 =
f_larcos(x1, nbin);
345 if(fabs(x2)>0.8) x2 =
f_larcos(x2, nbin);
383 for(
int i=0; i<35; i++){
384 xbin.push_back(
test ->get_t0(i));
385 ybin.push_back(
test ->get_dedx(i));
388 for(
int i=0;i<nbin-1;i++){
398 b=(y1*x2-y2*x1)/(x2-x1);
407 b=(y1*x2-y2*x1)/(x2-x1);
413 if(ybin[i-1]>0 && ybin[i+1]>0){
419 b=(y1*x2-y2*x1)/(x2-x1);
467 double docaeangle_gain[
n];
468 double docaeangle_chisq[
n];
469 double docaeangle_entries[
n];
471 for(
int i=0; i<
n; i++){
473 docaeangle_gain[i] =
test -> get_out_gain(i);
474 docaeangle_chisq[i] =
test -> get_out_chi(i);
475 docaeangle_entries[i] =
test -> get_out_hits(i);
476 int Id_Doca_temp =
test -> get_id_doca(i);
477 int Ip_Eangle_temp =
test -> get_ip_eangle(i);
478 m_docaeangle[Id_Doca_temp][Ip_Eangle_temp] = docaeangle_gain[i];
479 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;
486 int onedsize=
test->get_enanglesize();
488 for(
int i=0; i< onedsize; i++){
489 m_venangle.push_back(
test->get_enangle(i));
504 const int hadronNo=
test -> get_hadronNo();
506 m_alpha=
test -> get_hadron(0);
508 m_gamma=
test -> get_hadron(1);
510 m_delta=
test -> get_hadron(2);
512 m_power=
test -> get_hadron(3);
514 m_ratio=
test -> get_hadron(4);
534 if( m_wire_g[wireid] > 0 ){
535 double ch_dedx = (ex/m_wire_g[wireid])*m_valid[wireid];
538 else if( m_wire_g[wireid] == 0 ){
549 costheta = fabs(costheta);
550 if(m_par_flag == 1) {
551 dedx_ggs = m_ggs[0][layer] + m_ggs[1][layer]*costheta +
552 m_ggs[2][layer]*pow(costheta,2) + m_ggs[3][layer]*pow(costheta,3);
553 }
else if(m_par_flag == 0) {
554 dedx_ggs = m_ggs[0][layer] + m_ggs[1][layer]*T1(costheta) +
555 m_ggs[2][layer]*T2(costheta) + m_ggs[3][layer]*T3(costheta);
558 dedx_ggs = dedx/dedx_ggs;
559 if(dedx_ggs>0.0)
return dedx_ggs;
569 if(fabs(costheta)>1.0)
return dedx;
571 const int nbin=cos_k.size()+1;
572 const double step=2.00/nbin;
573 int n= (int)((costheta+1.00-0.5*step)/step);
574 if(costheta>(1.00-0.5*step))
577 if(costheta>-0.5*step && costheta<=0)
578 dedx_cos=cos_k[
n-1]*costheta+cos_b[
n-1];
579 else if(costheta>0 && costheta<0.5*step)
580 dedx_cos=cos_k[
n+1]*costheta+cos_b[
n+1];
582 dedx_cos=cos_k[
n]*costheta+cos_b[
n];
589 if(costheta>0.80 && costheta<0.95){
591 if(costheta<0.9282)
n--;
592 if(costheta<0.9115)
n--;
593 if(costheta<0.8877)
n--;
594 if(costheta<0.8634)
n--;
595 if(costheta<0.8460)
n--;
596 if(costheta<0.8089)
n--;
597 dedx_cos=cos_k[
n]*costheta+cos_b[
n];
599 else if(costheta<-0.80 && costheta>-0.95){
601 if(costheta>-0.9115)
n++;
602 if(costheta>-0.8877)
n++;
603 if(costheta>-0.8634)
n++;
604 if(costheta>-0.8460)
n++;
605 if(costheta>-0.8089)
n++;
606 dedx_cos=cos_k[
n]*costheta+cos_b[
n];
611 dedx_cos = dedx/dedx_cos;
622 const int nbin=t0_k.size()+1;
624 cout<<
"there should be 35 bins for t0 correction, check it!"<<endl;
631 else if(t0>=610 && t0<1190){
632 n=(int)( (t0-610.0)/20.0 ) + 2;
634 else if(t0>=1190 && t0<1225)
636 else if(t0>=1225 && t0<1275)
641 dedx_t0=t0_k[
n]*t0+t0_b[
n];
644 dedx_t0 = dedx/dedx_t0;
655 return D2I(costheta,
I2D(costheta,1.00)/1.00*dedx)*550;
660 if( m_layer_g[layid] > 0 ){
661 double ch_dedx = dedx/m_layer_g[layid];
664 else if( m_layer_g[layid] == 0 ){
678 for(
int j=0;j<10000;j++) {
679 if(runNO == m_rung[2][j]) {
680 dedx_rung = dedx/m_rung[0][j];
687 cout<<
"Warning!!! in DedxCorrecSvc::RungCorrec(): no rungain to "<<runNO<<endl;
700 if(m_par_flag == 1) {
701 dedx_ddg = m_ddg[0][layer] + m_ddg[1][layer]*dd +
702 m_ddg[2][layer]*dd*dd + m_ddg[3][layer]*pow(dd,3);
703 }
else if(m_par_flag == 0) {
704 dedx_ddg = m_ddg[0][layer] + m_ddg[1][layer]*T1(dd) +
705 m_ddg[2][layer]*T2(dd) + m_ddg[3][layer]*T3(dd);
708 dedx_ddg = dedx/dedx_ddg;
709 if (dedx_ddg>0.0)
return dedx_ddg;
729 if(eangle>-0.25 && eangle<0.25){
730 double stepsize= 0.5/m_venangle.size();
731 int nsize= m_venangle.size();
734 double y1=0,y2=0,x1=0,x2=0;
736 if(eangle>=-0.25+0.5*stepsize && eangle<=0.25-0.5*stepsize){
737 int bin = (int)( (eangle-(-0.25+0.5*stepsize))/stepsize);
739 x1=-0.25+0.5*stepsize+
bin*stepsize;
740 y2=m_venangle[
bin+1];
741 x2=-0.25+1.5*stepsize+
bin*stepsize;
743 else if(eangle<=-0.25+0.5*stepsize){
745 x1=-0.25+0.5*stepsize;
747 x2=-0.25+1.5*stepsize;
749 else if( eangle>=0.25-0.5*stepsize){
750 y1=m_venangle[nsize-2];
751 x1=0.25-1.5*stepsize;
752 y2=m_venangle[nsize-1];
753 x2=0.25-0.5*stepsize;
755 double kcof= (y2-y1)/(x2-x1);
756 double bcof= y1-kcof*x1;
757 double ratio = kcof*eangle+bcof;
769 if(m_par_flag == 1) {
770 dedx_zdep = m_zdep[0][layer] + m_zdep[1][layer]*z +
771 m_zdep[2][layer]*z*z + m_zdep[3][layer]*pow(z,3);
772 }
else if(m_par_flag == 0) {
773 dedx_zdep = m_zdep[0][layer] + m_zdep[1][layer]*T1(z) +
774 m_zdep[2][layer]*T2(z) + m_zdep[3][layer]*T3(z);
776 dedx_zdep = dedx/dedx_zdep;
777 if (dedx_zdep>0.0)
return dedx_zdep;
786 if(m_debug) cout<<
"DedxCorrecSvc::DocaSinCorrec"<<endl;
789 if(eangle>0.25) eangle = eangle -0.5;
790 else if(eangle < -0.25) eangle = eangle +0.5;
793 doca = doca/doca_norm[layer];
794 iDoca =(Int_t)floor((doca-
Out_DocaMin)/Out_Stepdoca);
799 if(iDoca<0) iDoca = 0;
800 if(m_debug) cout<<
"iDoca : "<<iDoca<<
" doca : "<<doca<<
" Out_DocaMin : "<<
Out_DocaMin<<
" Out_Stepdoca : "<<Out_Stepdoca<<endl;
803 for(
int i =0; i<14; i++){
805 if(eangle <Eangle_value_cut[i] || eangle > Eangle_value_cut[i+1])
continue;
806 else if(eangle>= Eangle_value_cut[i] && eangle < Eangle_value_cut[i+1]) {
807 for(
int k =0; k<i; k++){
808 iEAng+= Eangle_cut_bin[k];
810 double eangle_bin_cut_step = (Eangle_value_cut[i+1] - Eangle_value_cut[i])/Eangle_cut_bin[i];
811 int temp_bin = int((eangle-Eangle_value_cut[i])/eangle_bin_cut_step);
816 if(m_docaeangle[iDoca][iEAng]>0) {
817 if(m_debug && (iDoca==m_debug_i) && (iEAng==m_debug_j))
818 cout <<
"doca: " << doca <<
" eang" << eangle <<
" dedx before: " << dedx << endl;
819 dedx = dedx/m_docaeangle[iDoca][iEAng];
820 if(m_debug && (iDoca==m_debug_i) && (iEAng==m_debug_j))
821 cout <<
"gain: " << m_docaeangle[iDoca][iEAng] <<
" dedx after: " << dedx << endl;
833 if( m_mdcg_flag == 0 )
return dedx;
834 double calib_ex = dedx;
835 if( m_dedx_gain > 0 ) calib_ex /= m_dedx_gain;
843 double z,
double costheta )
const {
845 if( m_rung_flag == 0 && m_wireg_flag == 0 && m_ddg_flag == 0
846 && m_layerg_flag == 0 && m_zdep_flag == 0 &&
847 m_ggs_flag == 0)
return adc;
848 adc = m_valid[ser]*m_wire_g[ser]*adc;
852 double correct1_ex , correct2_ex, correct3_ex, correct4_ex, correct5_ex;
865 correct2_ex =correct1_ex;
871 correct3_ex =correct2_ex;
875 correct4_ex =
ZdepCorrec( lyr, z, correct3_ex );
878 correct4_ex = correct3_ex;
885 correct5_ex = correct4_ex;
895 if( m_zdep_flag == 0 && m_ggs_flag == 0 )
return ex;
898 if( m_ggs_flag != 0 ) calib_ex =
SaturCorrec( layer, costheta, calib_ex );
906 if( m_mdcg_flag == 0 )
return dedx;
908 double calib_ex = dedx;
910 double run_const = m_dedx_gain;
911 if( run_const > 0 && m_mdcg_flag != 0 ) calib_ex /= run_const;
919DedxCorrecSvc::StandardCorrec(
int runFlag,
int ntpFlag,
int runNO,
double pathl,
int wid,
int layid,
double adc,
double dd,
double eangle,
double z,
double costheta )
const {
928 if( runNO<0 )
return ex;
932 if( ntpFlag ==0)
return ex;
934 if( m_rung_flag == 0 && m_wireg_flag == 0 && m_dcasin_flag==0 && m_ddg_flag == 0
935 && m_layerg_flag == 0 && m_zdep_flag == 0 &&
936 m_ggs_flag == 0)
return ex;
953 if(m_enta_flag && runFlag>=3){
993DedxCorrecSvc::StandardHitCorrec(
int calib_rec_Flag,
int runFlag,
int ntpFlag,
int runNO,
double pathl,
int wid,
int layid,
double adc,
double dd,
double eangle,
double costheta )
const {
994 if(m_debug) cout<<
"DedxCorrecSvc::StandardHitCorrec"<<endl;
1003 if( runNO<0 )
return ex;
1007 if( ntpFlag ==0)
return ex;
1011 if( m_rung_flag == 0 && m_wireg_flag == 0 && m_ddg_flag == 0
1012 && m_layerg_flag == 0 && m_zdep_flag == 0 && m_dcasin_flag==0
1013 && m_ggs_flag == 0 && m_enta_flag==0)
return ex;
1025 if( m_dcasin_flag) {
1036 if(m_enta_flag && runFlag>=3){
1059 if(m_debug) cout<<
"DedxCorrecSvc::StandardTrackCorrec"<<endl;
1060 if( runNO<0 )
return ex;
1061 if( ntpFlag ==0)
return ex;
1062 if( runFlag <3)
return ex;
1063 if( calib_rec_Flag ==1){
1065 if(m_t0_flag) ex=
T0Correc(t0, ex);
1075 if(runFlag==3) {ex=
T0Correc(t0, ex);}
1076 else if(runFlag>3) {ex=ex;}
1083 if(m_rung_flag && calib_rec_Flag ==2){
1084 double rungain_temp =
RungCorrec( runNO, ex )/ex;
1085 ex = ex/rungain_temp;
1096DedxCorrecSvc::init_param() {
1100 for(
int i = 0; i<6796 ; i++) {
1106 for(
int j = 0; j<100; j++){
1109 for(
int j = 0; j<43; j++) {
1115 for(
int k = 1; k<4; k++ ) {
1123 std::cout<<
"DedxCorrecSvc::init_param()!!!"<<std::endl;
1124 std::cout<<
"hello,init_param"<<endl;
1125 m_initConstFlg =
true;
1133 cout<<
"calib_F is = "<<calib_F<<endl;
1134 if(calib_F<0){ m_enta_flag = 0; calib_F =
abs(calib_F); }
1135 else m_enta_flag = 1;
1136 m_rung_flag = ( calib_F & 1 )? 1 : 0;
1137 m_wireg_flag = ( calib_F & 2 )? 1 : 0;
1138 m_dcasin_flag = ( calib_F & 4 )? 1 : 0;
1139 m_ggs_flag = ( calib_F & 8 )? 1 : 0;
1142 m_t0_flag = ( calib_F & 16 )? 1 : 0;
1143 m_sat_flag = ( calib_F & 32 )? 1 : 0;
1144 m_layerg_flag = ( calib_F & 64 )? 1 : 0;
1146 m_dip_flag = ( calib_F & 256 )? 1 : 0;
1147 m_mdcg_flag = ( calib_F & 512 )? 1 : 0;
1156HepPoint3D piv(hel.pivot());
1157double dr = hel.a()[0];
1158double phi0 = hel.a()[1];
1159double tanl = hel.a()[4];
1160double dz = hel.a()[3];
1162double dr = -19.1901;
1163double phi0 = 3.07309;
1164double tanl = -0.466654;
1167double csf0 = cos(phi0);
1168double snf0 = sin(phi0);
1169double x_c = dr*csf0;
1170double y_c = dr*snf0;
1171double z_c = hel.a()[3];
1177double m_zb, m_zf, Calpha;
1178// double sintheta = sin(M_PI_2-atan(hel.a()[4]));
1179double sintheta = sin(M_PI_2-atan(tanl));
1180// retrieve Mdc geometry information
1181double rcsiz1= geosvc->Layer(layer)->RCSiz1();
1182double rcsiz2= geosvc->Layer(layer)->RCSiz2();
1183double rlay= geosvc->Layer(layer)->Radius();
1184int ncell= geosvc->Layer(layer)->NCell();
1185double phioffset= geosvc->Layer(layer)->Offset();
1186float shift= geosvc->Layer(layer)->Shift();
1187double slant= geosvc->Layer(layer)->Slant();
1188double length = geosvc->Layer(layer)->Length();
1189int type = geosvc->Layer(layer)->Sup()->Type();
1190// shift = shift*type;
1192//conversion of the units(mm=>cm)
1199m_crio[0] = rlay - rcsiz1;
1200m_crio[1] = rlay + rcsiz2;
1203{ if(rlay<= fabs(dr)) rlay = rlay + rcsiz2;
1204if(rlay<fabs(dr)) return -1;
1205double t_digi = sqrt(rlay*rlay - dr*dr);
1206double x_t_digi = x_c - t_digi*snf0;
1207double y_t_digi = y_c + t_digi*csf0;
1208double z_t_digi = z_c + t_digi*tanl;
1209double x__t_digi = x_c + t_digi*snf0;
1210double y__t_digi = y_c - t_digi*csf0;
1211double z__t_digi = z_c - t_digi*tanl;
1212double phi_t_digi = atan2(y_t_digi,x_t_digi);
1213double phi__t_digi = atan2(y__t_digi,x__t_digi);
1214phi_t_digi = fmod( phi_t_digi+4*M_PI,2*M_PI );
1215phi__t_digi = fmod( phi__t_digi+4*M_PI,2*M_PI );
1216double phibin_digi = 2.0*M_PI/ncell;
1217double phi_cellid_digi = phioffset + shift*phibin_digi*0.5 + cellid *phibin_digi;
1218if(fabs(phi_cellid_digi - phi_t_digi)<fabs(phi_cellid_digi - phi__t_digi))
1220else if (fabs(phi_cellid_digi - phi_t_digi)>fabs(phi_cellid_digi - phi__t_digi))
1225int sign = 1; ///assumed the first half circle
1228Hep3Vector cell_IO[2];
1232 downin = (z*z-m_zb*m_zb)*pow(tan(slant),2);
1233 m_crio[0] = sqrt(m_crio[0]*m_crio[0]+downin);
1234 m_crio[1] = sqrt(m_crio[1]*m_crio[1]+downin);
1239if(m_crio[1]<fabs(dr)) return -1;
1240else if(m_crio[0]<fabs(dr)) {
1241 t[0] = sqrt(m_crio[1]*m_crio[1] - dr*dr);
1245 for( int i = 0; i < 2; i++ ) {
1246 if(m_crio[i]<fabs(dr)) return -1;
1247 t[i] = sqrt(m_crio[i]*m_crio[i] - dr*dr);
1251// calculate the cooridate of hits
1252double x_t[2],y_t[2],z_t[2];
1253double x__t[2],y__t[2],z__t[2];
1254double x_p[2],y_p[2],z_p[2];
1255for( int i = 0; i < 2; i++){
1256 x_t[i] = x_c - t[i]*snf0;
1257 y_t[i] = y_c + t[i]*csf0;
1258 z_t[i] = z_c + t[i]*tanl;
1259 x__t[i] = x_c + t[i]*snf0;
1260 y__t[i] = y_c - t[i]*csf0;
1261 z__t[i] = z_c - t[i]*tanl;
1264double phi_in_t,phi_in__t, phi_out_t,phi_out__t,phi_t,phi__t;
1265double phibin = 2.0*M_PI/ncell;
1266double phi_cellid = phioffset + shift*phibin*(0.5-z/length) + cellid *phibin;
1267phi_in_t = atan2(y_t[0],x_t[0]);
1268phi_out_t = atan2(y_t[1],x_t[1]);
1269phi_in__t = atan2(y__t[0],x__t[0]);
1270phi_out__t = atan2(y__t[1],x__t[1]);
1271phi_t = atan2(((y_t[0]+y_t[1])/2),((x_t[0]+x_t[1])/2));
1272phi__t = atan2(((y__t[0]+y__t[1])/2),((x__t[0]+x__t[1])/2));
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_in__t = fmod( phi_in__t+4*M_PI,2*M_PI );
1277phi_out__t = fmod( phi_out__t+4*M_PI,2*M_PI );
1278phi_t = fmod( phi_t+4*M_PI,2*M_PI );
1279phi__t = fmod( phi__t+4*M_PI,2*M_PI );
1280phi_cellid = fmod( phi_cellid+4*M_PI,2*M_PI );
1282if(fabs(phi_cellid - phi_t)<fabs(phi_cellid - phi__t))
1284 for(int i =0; i<2; i++ )
1289else if (fabs(phi_cellid - phi_t)>fabs(phi_cellid - phi__t))
1291 for(int i =0; i<2; i++ )
1298 for(int i =0; i<2; i++ )
1304//calculate path length in r_phi plane and all length in this layer
1305double ch_ltrk_rp, ch_ltrk;
1306ch_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]));
1307ch_ltrk = ch_ltrk_rp/sintheta;
1308//give cellid of in and out of this layer
1309double phi_in,phi_out;
1310phi_in = atan2(y_p[0],x_p[0]);
1311phi_out = atan2(y_p[1],x_p[1]);
1312phi_in = fmod( phi_in+4*M_PI,2*M_PI );
1313phi_out = fmod( phi_out+4*M_PI,2*M_PI );
1315//determine the in/out cellid
1316double inlow, inup, outlow, outup, gap, phi1, phi2, phi_mid, phi_midin, phi_midout;
1318// int cid_in_t,cid_in__t,cid_out_t,cid_out__t;
1319//cache sampl in each cell for this layer
1320std::vector<double> phi_entrance;
1321std::vector<double> sampl;
1323phi_entrance.resize(ncell);
1324for(int k=0; k<ncell; k++) {
1326 phi_entrance[k] = 0;
1329cid_in = cid_out = -1;
1330phibin = 2.0*M_PI/ncell;
1331//determine the in/out cell id
1332double stphi[2], phioff[2];
1333stphi[0] = shift*phibin*(0.5-z_p[0]/length);
1334stphi[1] = shift*phibin*(0.5-z_p[1]/length);
1335phioff[0] = phioffset+stphi[0];
1336phioff[1] = phioffset+stphi[1];
1337for(int i=0; i<ncell; i++) {
1339 // phi[i] = phioff[0]+phibin*i;
1340 inlow = phioff[0]+phibin*i-phibin*0.5;
1341 inup = phioff[0]+phibin*i+phibin*0.5;
1342 outlow = phioff[1]+phibin*i-phibin*0.5;
1343 outup = phioff[1]+phibin*i+phibin*0.5;
1344 inlow = fmod( inlow+4*M_PI,2*M_PI );
1345 inup = fmod( inup+4*M_PI,2*M_PI );
1346 outlow = fmod( outlow+4*M_PI,2*M_PI );
1347 outup = fmod( outup+4*M_PI,2*M_PI );
1349 cout << "shift " << shift<< " cellid " << i
1350 <<" phi_in " << phi_in << " phi_out " << phi_out
1351 << " inup "<< inup << " inlow " << inlow
1352 << " outup "<< outup << " outlow " << outlow << endl;
1354 if(phi_in>=inlow&&phi_in<inup) cid_in = i;
1355 if(phi_out>=outlow&&phi_out<outup) cid_out = i;
1357 if((phi_in>=inlow&&phi_in<2.0*M_PI)||(phi_in>=0.0&&phi_in<inup)) cid_in = i;
1359 if ( outlow>outup) {
1360 if((phi_out>=outlow&&phi_out<2.0*M_PI)||(phi_out>=0.0&&phi_out<outup)) cid_out = i;
1364// judge how many cells are traversed and deal with different situations
1365phi_midin = phi_midout = phi1 = phi2 = -999.0;
1367//only one cell traversed
1368if( cid_in == cid_out) {
1369 sampl[cid_in] = ch_ltrk;
1372} else if(cid_in < cid_out) {
1373 //in cell id less than out cell id
1374 //deal with the special case crossing x axis
1375 if( cid_out-cid_in>ncell/2 ) {
1376 // if(gap>=M_PI) gap = 2.0*M_PI-gap;
1377 phi_midin = phioff[0]+phibin*cid_in-phibin*0.5;
1378 phi_midout = phioff[1]+phibin*cid_out+phibin*0.5;
1379 phi_midin = fmod( phi_midin+4*M_PI,2*M_PI );
1380 phi_midout = fmod( phi_midout+4*M_PI,2*M_PI );
1381 phi1 = phi_midout-phi_out;
1382 phi2 = phi_in-phi_midin;
1383 phi1 = fmod(phi1+2.0*M_PI,2.0*M_PI);
1384 phi2 = fmod(phi2+2.0*M_PI,2.0*M_PI);
1385 gap = phi1+phi2+(ncell-1-cid_out+cid_in)*phibin;
1386 gap = fmod(gap+2.0*M_PI,2.0*M_PI);
1387 sampl[cid_in]=phi2/gap*ch_ltrk;
1388 sampl[cid_out]=phi1/gap*ch_ltrk;
1390 for( int jj = cid_out+1; jj<ncell; jj++) {
1391 sampl[jj]=phibin/gap*ch_ltrk;
1393 for( int jj = 0; jj<cid_in; jj++) {
1394 sampl[jj]=phibin/gap*ch_ltrk;
1399 phi_midin = phioff[0]+phibin*cid_in+phibin*0.5;
1400 phi_midout = phioff[1]+phibin*cid_out-phibin*0.5;
1401 phi_midin = fmod( phi_midin+4*M_PI,2*M_PI );
1402 phi_midout = fmod( phi_midout+4*M_PI,2*M_PI );
1403 phi1 = phi_midin-phi_in;
1404 phi2 = phi_out-phi_midout;
1405 phi1 = fmod(phi1+2.0*M_PI,2.0*M_PI);
1406 phi2 = fmod(phi2+2.0*M_PI,2.0*M_PI);
1407 gap = phi1+phi2+(cid_out-cid_in-1)*phibin;
1408 gap = fmod(gap+2.0*M_PI,2.0*M_PI);
1409 sampl[cid_in]=phi1/gap*ch_ltrk;
1410 sampl[cid_out]=phi2/gap*ch_ltrk;
1411 phi_entrance[cid_in] = phi_in;
1412 phi_entrance[cid_out] = phi_midout;
1413 for( int jj = cid_in+1; jj<cid_out; jj++) {
1414 sampl[jj]=phibin/gap*ch_ltrk;
1417} else if(cid_in > cid_out) {
1418 //in cell id greater than out cell id
1419 //deal with the special case crossing x axis
1420 if( cid_in-cid_out>ncell/2 ) {
1421 // if(gap>=M_PI) gap = 2.0*M_PI-gap;
1422 phi_midin = phioff[0]+phibin*cid_in+phibin*0.5;
1423 phi_midout = phioff[1]+phibin*cid_out-phibin*0.5;
1424 phi_midin = fmod( phi_midin+4*M_PI,2*M_PI );
1425 phi_midout = fmod( phi_midout+4*M_PI,2*M_PI );
1426 phi1 = phi_midin-phi_in;
1427 phi2 = phi_out-phi_midout;
1428 phi1 = fmod(phi1+2.0*M_PI,2.0*M_PI);
1429 phi2 = fmod(phi2+2.0*M_PI,2.0*M_PI);
1430 gap = phi1+phi2+(ncell-1-cid_in+cid_out)*phibin;
1431 gap = fmod(gap+2.0*M_PI,2.0*M_PI);
1432 sampl[cid_out]=phi2/gap*ch_ltrk;
1433 sampl[cid_in]=phi1/gap*ch_ltrk;
1435 for( int jj = cid_in+1; jj<ncell; jj++) {
1436 sampl[jj]=phibin/gap*ch_ltrk;
1438 for( int jj = 0; jj<cid_out; jj++) {
1439 sampl[jj]=phibin/gap*ch_ltrk;
1443 phi_midin = phioff[0]+phibin*cid_in-phibin*0.5;
1444 phi_midout = phioff[1]+phibin*cid_out+phibin*0.5;
1445 phi_midin = fmod( phi_midin+4*M_PI,2*M_PI );
1446 phi_midout = fmod( phi_midout+4*M_PI,2*M_PI );
1447 phi1 = phi_midout-phi_out;
1448 phi2 = phi_in-phi_midin;
1449 phi1 = fmod(phi1+2.0*M_PI,2.0*M_PI);
1450 phi2 = fmod(phi2+2.0*M_PI,2.0*M_PI);
1451 gap = phi1+phi2+(cid_in-cid_out-1)*phibin;
1452 gap = fmod(gap+2.0*M_PI,2.0*M_PI);
1453 sampl[cid_in]=phi2/gap*ch_ltrk;
1454 sampl[cid_out]=phi1/gap*ch_ltrk;
1455 for( int jj = cid_out+1; jj<cid_in; jj++) {
1456 sampl[jj]=phibin/gap*ch_ltrk;
1462if(sampl[cellid]<0.0) {
1463 if(cid_in!=cid_out) cout<<"?????????"<<endl;
1464 cout<< "layerId " << layer <<" cell id "<< cellid <<" shift " << shift
1465 << " cid_in " << cid_in << " cid_out " << cid_out << endl;
1467 cout <<" phi_in " << phi_in <<" phi_midin " << phi_midin << " phi_out "
1468 << phi_out << " phi_midout " << phi_midout <<endl;
1469 cout<<"total sampl " << ch_ltrk << " gap "<< gap << " phi1 "
1470 << phi1 << " phi2 " << phi2 << " phibin " << phibin << endl;
1473 for(int l=0; l<ncell; l++) {
1475 cout<<"picked cellid " << l << " sampling length "<< sampl[l]<< endl;
1479return sampl[cellid];
1492 int genlay = geosvc->
Layer(layer)->
Gen();
1500 HepPoint3D East_origin(East_lay_X, East_lay_Y, East_lay_Z);
1501 HepPoint3D West_origin(West_lay_X, West_lay_Y, West_lay_Z);
1502 Hep3Vector wire = (CLHEP::Hep3Vector)East_origin - (CLHEP::Hep3Vector)West_origin;
1503 HepPoint3D piovt_z =(z*10+length/2 )/length * wire + West_origin;
1504 piovt_z = piovt_z*0.1;
1511 double dr0 = hel.
a()[0];
1512 double phi0 = hel.
a()[1];
1513 double kappa = hel.
a()[2];
1514 double dz0 = hel.
a()[3];
1515 double tanl = hel.
a()[4];
1519 double ALPHA_loc = 1000/(2.99792458*Bz);
1525 int charge = ( kappa >= 0 )? 1 : -1;
1526 double rho = ALPHA_loc/kappa;
1527 double pt = fabs( 1.0/kappa );
1528 double lambda = atan( tanl );
1529 double theta = M_PI_2- lambda;
1530 double sintheta =
sin(M_PI_2-atan(tanl));
1532 double phi = fmod(phi0 +
M_PI*4,
M_PI*2);
1533 double csf0 =
cos(phi);
1534 double snf0 = (1. - csf0) * (1. + csf0);
1535 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
1536 if(phi >
M_PI) snf0 = - snf0;
1541 double x_c = piv.x() + ( hel.
dr() + rho )*csf0;
1542 double y_c = piv.y() + ( hel.
dr() + rho )*snf0;
1543 double z_c = piv.z() + hel.
dz();
1545 double m_c_perp(ccenter.perp());
1546 Hep3Vector m_c_unit((
HepPoint3D)ccenter.unit());
1550 double x_c_boost = x_c - piovt_z.x();
1551 double y_c_boost = y_c - piovt_z.y();
1552 double z_c_boost = z_c - piovt_z.z();
1553 HepPoint3D ccenter_boost(x_c_boost, y_c_boost, 0.0);
1554 double m_c_perp_boost(ccenter_boost.perp());
1557 Hep3Vector m_c_unit_boost((
HepPoint3D)ccenter_boost.unit());
1562 double dphi0 = fmod( IO.phi()+4*
M_PI,2*
M_PI ) - phi;
1563 double IO_phi = fmod( IO.phi()+4*
M_PI,2*
M_PI );
1567 if( dphi0 >
M_PI ) dphi0 -= 2*
M_PI;
1568 else if( dphi0 < -
M_PI ) dphi0 += 2*
M_PI;
1571 phi_io[0] = -(1+charge)*M_PI_2 - charge*dphi0;
1573 phi_io[1] = phi_io[0]+1.5*
M_PI;
1576 double m_zb, m_zf, Calpha;
1593 int wid = w0id + cellid;
1596 double x_lay_backward = geosvc->
Wire(layer, cellid)->
Backward().x();
1597 double y_lay_backward = geosvc->
Wire(layer, cellid)->
Backward().y();
1598 double x_lay_forward = geosvc->
Wire(layer, cellid)->
Forward().x();
1599 double y_lay_forward = geosvc->
Wire(layer, cellid)->
Forward().y();
1600 double r_lay_backward = sqrt(x_lay_backward*x_lay_backward+y_lay_backward*y_lay_backward);
1601 double r_lay_forward = sqrt(x_lay_forward*x_lay_forward+y_lay_forward*y_lay_forward);
1602 double r_lay_use = ((z*10+length/2)/length)*(r_lay_backward-r_lay_forward) + r_lay_forward;
1610 r_lay_use = 0.1*r_lay_use;
1611 rcsiz1 = 0.1*rcsiz1;
1612 rcsiz2 = 0.1*rcsiz2;
1614 length = 0.1*length;
1617 m_crio[0] = rlay - rcsiz1;
1618 m_crio[1] = rlay + rcsiz2;
1622 Hep3Vector iocand[2];
1623 Hep3Vector cell_IO[2];
1624 double dphi, downin;
1628 downin = (z*z-m_zb*m_zb)*pow(
tan(slant),2);
1629 m_crio[0] = sqrt(m_crio[0]*m_crio[0]+downin);
1630 m_crio[1] = sqrt(m_crio[1]*m_crio[1]+downin);
1635 for(
int i = 0; i < 2; i++ ) {
1636 double cos_alpha = m_c_perp_boost*m_c_perp_boost + m_crio[i]*m_crio[i] - rho*rho;
1637 cos_alpha = 0.5*cos_alpha/( m_c_perp_boost*m_crio[i] );
1638 if(fabs(cos_alpha)>1&&i==0)
return(-1.0);
1639 if(fabs(cos_alpha)>1&&i==1) {
1640 cos_alpha = m_c_perp_boost*m_c_perp_boost + m_crio[0]*m_crio[0] - rho*rho;
1641 cos_alpha = 0.5*cos_alpha/( m_c_perp_boost*m_crio[0] );
1642 Calpha = 2.0*
M_PI-acos( cos_alpha );
1644 Calpha = acos( cos_alpha );
1647 iocand[i] = m_c_unit_boost;
1648 iocand[i].rotateZ( charge*sign*Calpha );
1649 iocand[i]*= m_crio[i];
1656 iocand[i] = iocand[i]+ piovt_z;
1661 double xx = iocand[i].x() - x_c;
1662 double yy = iocand[i].y() - y_c;
1664 dphi = atan2(yy, xx) - phi0 - M_PI_2*(1-charge);
1665 dphi = fmod( dphi + 8.0*
M_PI, 2*
M_PI );
1667 if( dphi < phi_io[0] ) {
1670 else if( phi_io[1] < dphi ) {
1676 Hep3Vector zvector( 0., 0., z_c-rho*dphi*tanl-piovt_z.z());
1678 cell_IO[i] = iocand[i];
1679 cell_IO[i] += zvector;
1684 double xcio, ycio, phip;
1716 cell_IO[i] = hel.
x(dphi);
1723 Hep3Vector cl = cell_IO[1] - cell_IO[0];
1729 double ch_ltrk_rp = 0;
1730 ch_dphi = cl.perp()*0.5/(ALPHA_loc*pt);
1731 ch_dphi = 2.0 * asin( ch_dphi );
1732 ch_ltrk_rp = ch_dphi*ALPHA_loc*pt;
1733 double rpi_path = sqrt(cl.x()*cl.x()+cl.y()*cl.y());
1734 ch_ltrk = sqrt( ch_ltrk_rp*ch_ltrk_rp + cl.z()*cl.z() );
1735 double path = ch_ltrk_rp/ sintheta;
1736 ch_theta = cl.theta();
1752 double phibin, phi_in, phi_out, inlow, inup, outlow, outup, gap,
phi1,
phi2, phi_mid, phi_midin, phi_midout;
1753 int cid_in, cid_out;
1754 double inlow_z, inup_z, outlow_z, outup_z, gap_z, phi1_z, phi2_z, phi_mid_z, phi_midin_z, phi_midout_z;
1757 std::vector<double> sampl;
1758 sampl.resize(ncell);
1759 for(
int k=0; k<ncell; k++) {
1763 cid_in = cid_out = -1;
1764 phi_in = cell_IO[0].phi();
1765 phi_out = cell_IO[1].phi();
1768 phi_in = fmod( phi_in+4*
M_PI,2*
M_PI );
1769 phi_out = fmod( phi_out+4*
M_PI,2*
M_PI );
1770 phibin = 2.0*
M_PI/ncell;
1774 Hep3Vector cell_mid=0.5*(cell_IO[0]+cell_IO[1]);
1779 double stphi[2], phioff[2];
1780 stphi[0] = shift*phibin*(0.5-cell_IO[0].z()/length);
1781 stphi[1] = shift*phibin*(0.5-cell_IO[1].z()/length);
1784 phioff[0] = phioffset+stphi[0];
1785 phioff[1] = phioffset+stphi[1];
1787 for(
int i=0; i<ncell; i++) {
1789 double x_lay_backward_cell = geosvc->
Wire(layer, i)->
Backward().x()*0.1;
1790 double y_lay_backward_cell = geosvc->
Wire(layer, i)->
Backward().y()*0.1;
1791 double x_lay_forward_cell = geosvc->
Wire(layer, i)->
Forward().x()*0.1;
1792 double y_lay_forward_cell = geosvc->
Wire(layer, i)->
Forward().y()*0.1;
1795 Hep3Vector lay_backward(x_lay_backward_cell, y_lay_backward_cell, 0);
1796 Hep3Vector lay_forward(x_lay_forward_cell, y_lay_forward_cell, 0);
1797 Hep3Vector Cell_z[2];
1798 Cell_z[0] = ((cell_IO[0].z()+length/2)/length)*(lay_backward - lay_forward) + lay_forward;
1799 Cell_z[1] = ((cell_IO[1].z()+length/2)/length)*(lay_backward - lay_forward) + lay_forward;
1801 z_phi[0] = Cell_z[0].phi();
1802 z_phi[1] = Cell_z[1].phi();
1803 z_phi[0] = fmod( z_phi[0]+4*
M_PI,2*
M_PI );
1804 z_phi[1] = fmod( z_phi[1]+4*
M_PI,2*
M_PI );
1816 inlow_z = z_phi[0] - phibin*0.5;
1817 inup_z = z_phi[0] + phibin*0.5;
1818 outlow_z = z_phi[1] - phibin*0.5;
1819 outup_z = z_phi[1] + phibin*0.5;
1820 inlow_z = fmod( inlow_z+4*
M_PI,2*
M_PI );
1821 inup_z = fmod( inup_z+4*
M_PI,2*
M_PI );
1822 outlow_z = fmod( outlow_z+4*
M_PI,2*
M_PI );
1823 outup_z = fmod( outup_z+4*
M_PI,2*
M_PI );
1827 inlow = phioff[0]+phibin*i-phibin*0.5;
1828 inup = phioff[0]+phibin*i+phibin*0.5;
1829 outlow = phioff[1]+phibin*i-phibin*0.5;
1830 outup = phioff[1]+phibin*i+phibin*0.5;
1831 inlow = fmod( inlow+4*
M_PI,2*
M_PI );
1833 outlow = fmod( outlow+4*
M_PI,2*
M_PI );
1834 outup = fmod( outup+4*
M_PI,2*
M_PI );
1837 if(ntpFlag > 0) cout <<
"shift " << shift
1838 <<
" phi_in " << phi_in <<
" phi_out " << phi_out
1839 <<
" inup "<< inup <<
" inlow " << inlow
1840 <<
" outup "<< outup <<
" outlow " << outlow << endl;
1852 if(phi_in>=inlow_z&&phi_in<inup_z) cid_in = i;
1853 if(phi_out>=outlow_z&&phi_out<outup_z) cid_out = i;
1854 if ( inlow_z>inup_z) {
1855 if((phi_in>=inlow_z&&phi_in<2.0*
M_PI)||(phi_in>=0.0&&phi_in<inup_z)) cid_in = i;
1857 if ( outlow_z>outup_z) {
1858 if((phi_out>=outlow_z&&phi_out<2.0*
M_PI)||(phi_out>=0.0&&phi_out<outup_z)) cid_out = i;
1862 phi_midin = phi_midout =
phi1 =
phi2 = -999.0;
1866 if(cid_in == -1 || cid_out == -1)
return -1;
1868 if( cid_in == cid_out) {
1869 sampl[cid_in]= ch_ltrk;
1871 return sampl[cellid];
1872 }
else if(cid_in < cid_out) {
1875 if( cid_out-cid_in>ncell/2 ) {
1878 double x_lay_backward_cin = geosvc->
Wire(layer, cid_in)->
Backward().x()*0.1;
1879 double y_lay_backward_cin = geosvc->
Wire(layer, cid_in)->
Backward().y()*0.1;
1880 double x_lay_forward_cin = geosvc->
Wire(layer, cid_in)->
Forward().x()*0.1;
1881 double y_lay_forward_cin = geosvc->
Wire(layer, cid_in)->
Forward().y()*0.1;
1882 Hep3Vector lay_backward_cin(x_lay_backward_cin, y_lay_backward_cin, 0);
1883 Hep3Vector lay_forward_cin(x_lay_forward_cin, y_lay_forward_cin, 0);
1884 Hep3Vector Cell_z[2];
1885 Cell_z[0]=((cell_IO[0].z()+length/2)/length)*(lay_backward_cin-lay_forward_cin)+lay_forward_cin;
1886 double phi_cin_z = Cell_z[0].phi();
1887 phi_cin_z = fmod( phi_cin_z+4*
M_PI,2*
M_PI );
1888 double x_lay_backward_cout = geosvc->
Wire(layer, cid_out)->
Backward().x()*0.1;
1889 double y_lay_backward_cout = geosvc->
Wire(layer, cid_out)->
Backward().y()*0.1;
1890 double x_lay_forward_cout = geosvc->
Wire(layer, cid_out)->
Forward().x()*0.1;
1891 double y_lay_forward_cout = geosvc->
Wire(layer, cid_out)->
Forward().y()*0.1;
1892 Hep3Vector lay_backward_cout(x_lay_backward_cout, y_lay_backward_cout, 0);
1893 Hep3Vector lay_forward_cout(x_lay_forward_cout, y_lay_forward_cout, 0);
1894 Cell_z[1]=((cell_IO[1].z()+length/2)/length)*(lay_backward_cout-lay_forward_cout)+lay_forward_cout;
1895 double phi_cout_z = Cell_z[1].phi();
1896 phi_cout_z = fmod( phi_cout_z+4*
M_PI,2*
M_PI );
1898 phi_midin_z = phi_cin_z-phibin*0.5;
1899 phi_midout_z = phi_cout_z+phibin*0.5;
1900 phi_midin_z = fmod( phi_midin_z+4*
M_PI,2*
M_PI );
1901 phi_midout_z = fmod( phi_midout_z+4*
M_PI,2*
M_PI );
1902 phi1_z = phi_midout_z-phi_out;
1903 phi2_z = phi_in-phi_midin_z;
1904 phi1_z = fmod(phi1_z+2.0*
M_PI,2.0*
M_PI);
1905 phi2_z = fmod(phi2_z+2.0*
M_PI,2.0*
M_PI);
1906 gap_z = phi1_z+phi2_z+(ncell-1-cid_out+cid_in)*phibin;
1907 gap_z = fmod(gap_z+2.0*
M_PI,2.0*
M_PI);
1908 sampl[cid_in]=phi2_z/gap_z*ch_ltrk;
1909 sampl[cid_out]=phi1_z/gap_z*ch_ltrk;
1910 for(
int jj = cid_out+1; jj<ncell; jj++) {
1911 sampl[jj]=phibin/gap_z*ch_ltrk;
1913 for(
int jj = 0; jj<cid_in; jj++) {
1914 sampl[jj]=phibin/gap_z*ch_ltrk;
1948 double x_lay_backward_cin = geosvc->
Wire(layer, cid_in)->
Backward().x()*0.1;
1949 double y_lay_backward_cin = geosvc->
Wire(layer, cid_in)->
Backward().y()*0.1;
1950 double x_lay_forward_cin = geosvc->
Wire(layer, cid_in)->
Forward().x()*0.1;
1951 double y_lay_forward_cin = geosvc->
Wire(layer, cid_in)->
Forward().y()*0.1;
1952 Hep3Vector lay_backward_cin(x_lay_backward_cin, y_lay_backward_cin, 0);
1953 Hep3Vector lay_forward_cin(x_lay_forward_cin, y_lay_forward_cin, 0);
1954 Hep3Vector Cell_z[2];
1955 Cell_z[0]=((cell_IO[0].z()+length/2)/length)*(lay_backward_cin-lay_forward_cin)+lay_forward_cin;
1956 double phi_cin_z = Cell_z[0].phi();
1957 phi_cin_z = fmod( phi_cin_z+4*
M_PI,2*
M_PI );
1958 double x_lay_backward_cout = geosvc->
Wire(layer, cid_out)->
Backward().x()*0.1;
1959 double y_lay_backward_cout = geosvc->
Wire(layer, cid_out)->
Backward().y()*0.1;
1960 double x_lay_forward_cout = geosvc->
Wire(layer, cid_out)->
Forward().x()*0.1;
1961 double y_lay_forward_cout = geosvc->
Wire(layer, cid_out)->
Forward().y()*0.1;
1962 Hep3Vector lay_backward_cout(x_lay_backward_cout, y_lay_backward_cout, 0);
1963 Hep3Vector lay_forward_cout(x_lay_forward_cout, y_lay_forward_cout, 0);
1964 Cell_z[1]=((cell_IO[1].z()+length/2)/length)*(lay_backward_cout-lay_forward_cout)+lay_forward_cout;
1965 double phi_cout_z = Cell_z[1].phi();
1966 phi_cout_z = fmod( phi_cout_z+4*
M_PI,2*
M_PI );
1968 phi_midin_z = phi_cin_z+phibin*0.5;
1969 phi_midout_z = phi_cout_z-phibin*0.5;
1970 phi_midin_z = fmod( phi_midin_z+4*
M_PI,2*
M_PI );
1971 phi_midout_z = fmod( phi_midout_z+4*
M_PI,2*
M_PI );
1972 phi1_z = phi_midin_z-phi_in;
1973 phi2_z = phi_out-phi_midout_z;
1974 phi1_z = fmod(phi1_z+2.0*
M_PI,2.0*
M_PI);
1975 phi2_z = fmod(phi2_z+2.0*
M_PI,2.0*
M_PI);
1976 gap_z = phi1_z+phi2_z+(cid_out-cid_in-1)*phibin;
1977 gap_z = fmod(gap_z+2.0*
M_PI,2.0*
M_PI);
1978 sampl[cid_in]=phi1_z/gap_z*ch_ltrk;
1979 sampl[cid_out]=phi2_z/gap_z*ch_ltrk;
1980 for(
int jj = cid_in+1; jj<cid_out; jj++) {
1981 sampl[jj]=phibin/gap_z*ch_ltrk;
2001 }
else if(cid_in > cid_out) {
2004 if( cid_in-cid_out>ncell/2 ) {
2005 double x_lay_backward_cin = geosvc->
Wire(layer, cid_in)->
Backward().x()*0.1;
2006 double y_lay_backward_cin = geosvc->
Wire(layer, cid_in)->
Backward().y()*0.1;
2007 double x_lay_forward_cin = geosvc->
Wire(layer, cid_in)->
Forward().x()*0.1;
2008 double y_lay_forward_cin = geosvc->
Wire(layer, cid_in)->
Forward().y()*0.1;
2009 Hep3Vector lay_backward_cin(x_lay_backward_cin, y_lay_backward_cin, 0);
2010 Hep3Vector lay_forward_cin(x_lay_forward_cin, y_lay_forward_cin, 0);
2011 Hep3Vector Cell_z[2];
2012 Cell_z[0]=((cell_IO[0].z()+length/2)/length)*(lay_backward_cin-lay_forward_cin)+lay_forward_cin;
2013 double phi_cin_z = Cell_z[0].phi();
2014 phi_cin_z = fmod( phi_cin_z+4*
M_PI,2*
M_PI );
2015 double x_lay_backward_cout = geosvc->
Wire(layer, cid_out)->
Backward().x()*0.1;
2016 double y_lay_backward_cout = geosvc->
Wire(layer, cid_out)->
Backward().y()*0.1;
2017 double x_lay_forward_cout = geosvc->
Wire(layer, cid_out)->
Forward().x()*0.1;
2018 double y_lay_forward_cout = geosvc->
Wire(layer, cid_out)->
Forward().y()*0.1;
2019 Hep3Vector lay_backward_cout(x_lay_backward_cout, y_lay_backward_cout, 0);
2020 Hep3Vector lay_forward_cout(x_lay_forward_cout, y_lay_forward_cout, 0);
2021 Cell_z[1]=((cell_IO[1].z()+length/2)/length)*(lay_backward_cout-lay_forward_cout)+lay_forward_cout;
2022 double phi_cout_z = Cell_z[1].phi();
2023 phi_cout_z = fmod( phi_cout_z+4*
M_PI,2*
M_PI );
2025 phi_midin_z = phi_cin_z+phibin*0.5;
2026 phi_midout_z = phi_cout_z-phibin*0.5;
2027 phi_midin_z = fmod( phi_midin_z+4*
M_PI,2*
M_PI );
2028 phi_midout_z = fmod( phi_midout_z+4*
M_PI,2*
M_PI );
2029 phi1_z = phi_midin_z-phi_in;
2030 phi2_z = phi_out-phi_midout_z;
2031 phi1_z = fmod(phi1_z+2.0*
M_PI,2.0*
M_PI);
2032 phi2_z = fmod(phi2_z+2.0*
M_PI,2.0*
M_PI);
2033 gap_z = phi1_z+phi2_z+(ncell-1-cid_in+cid_out)*phibin;
2034 gap_z = fmod(gap_z+2.0*
M_PI,2.0*
M_PI);
2035 sampl[cid_out]=phi2_z/gap_z*ch_ltrk;
2036 sampl[cid_in]=phi1_z/gap_z*ch_ltrk;
2037 for(
int jj = cid_in+1; jj<ncell; jj++) {
2038 sampl[jj]=phibin/gap_z*ch_ltrk;
2040 for(
int jj = 0; jj<cid_out; jj++) {
2041 sampl[jj]=phibin/gap_z*ch_ltrk;
2073 double x_lay_backward_cin = geosvc->
Wire(layer, cid_in)->
Backward().x()*0.1;
2074 double y_lay_backward_cin = geosvc->
Wire(layer, cid_in)->
Backward().y()*0.1;
2075 double x_lay_forward_cin = geosvc->
Wire(layer, cid_in)->
Forward().x()*0.1;
2076 double y_lay_forward_cin = geosvc->
Wire(layer, cid_in)->
Forward().y()*0.1;
2077 Hep3Vector lay_backward_cin(x_lay_backward_cin, y_lay_backward_cin, 0);
2078 Hep3Vector lay_forward_cin(x_lay_forward_cin, y_lay_forward_cin, 0);
2079 Hep3Vector Cell_z[2];
2080 Cell_z[0]=((cell_IO[0].z()+length/2)/length)*(lay_backward_cin-lay_forward_cin)+lay_forward_cin;
2081 double phi_cin_z = Cell_z[0].phi();
2082 phi_cin_z = fmod( phi_cin_z+4*
M_PI,2*
M_PI );
2083 double x_lay_backward_cout = geosvc->
Wire(layer, cid_out)->
Backward().x()*0.1;
2084 double y_lay_backward_cout = geosvc->
Wire(layer, cid_out)->
Backward().y()*0.1;
2085 double x_lay_forward_cout = geosvc->
Wire(layer, cid_out)->
Forward().x()*0.1;
2086 double y_lay_forward_cout = geosvc->
Wire(layer, cid_out)->
Forward().y()*0.1;
2087 Hep3Vector lay_backward_cout(x_lay_backward_cout, y_lay_backward_cout, 0);
2088 Hep3Vector lay_forward_cout(x_lay_forward_cout, y_lay_forward_cout, 0);
2089 Cell_z[1]=((cell_IO[1].z()+length/2)/length)*(lay_backward_cout-lay_forward_cout)+lay_forward_cout;
2090 double phi_cout_z = Cell_z[1].phi();
2091 phi_cout_z = fmod( phi_cout_z+4*
M_PI,2*
M_PI );
2093 phi_midin_z = phi_cin_z-phibin*0.5;
2094 phi_midout_z = phi_cout_z+phibin*0.5;
2095 phi_midin_z = fmod( phi_midin_z+4*
M_PI,2*
M_PI );
2096 phi_midout_z = fmod( phi_midout_z+4*
M_PI,2*
M_PI );
2097 phi1_z = phi_midout_z-phi_out;
2098 phi2_z = phi_in-phi_midin_z;
2099 phi1_z = fmod(phi1_z+2.0*
M_PI,2.0*
M_PI);
2100 phi2_z = fmod(phi2_z+2.0*
M_PI,2.0*
M_PI);
2101 gap_z = phi1_z+phi2_z+(cid_in-cid_out-1)*phibin;
2102 gap_z = fmod(gap_z+2.0*
M_PI,2.0*
M_PI);
2103 sampl[cid_in]=phi2_z/gap_z*ch_ltrk;
2104 sampl[cid_out]=phi1_z/gap_z*ch_ltrk;
2105 for(
int jj = cid_out+1; jj<cid_in; jj++) {
2106 sampl[jj]=phibin/gap_z*ch_ltrk;
2129 if(sampl[cellid]<0.0) {
2130 if(cid_in!=cid_out) cout<<
"?????????"<<endl;
2131 cout<<
"layerId " << layer <<
" cell id "<< cellid <<
" shift " << shift
2132 <<
" cid_in " << cid_in <<
" cid_out " << cid_out << endl;
2134 cout <<
" phi_in " << phi_in <<
" phi_midin " << phi_midin <<
" phi_out "
2135 << phi_out <<
" phi_midout " << phi_midout <<endl;
2136 cout<<
"total sampl " << ch_ltrk <<
" gap "<< gap <<
" phi1 "
2137 <<
phi1 <<
" phi2 " <<
phi2 <<
" phibin " << phibin << endl;
2140 for(
int l=0; l<ncell; l++) {
2142 cout<<
"picked cellid " << l <<
" sampling length "<< sampl[l]<< endl;
2146 return sampl[cellid];
2156 double absCosTheta = fabs(cosTheta);
2157 double projection = pow(absCosTheta,m_power) + m_delta;
2158 double chargeDensity = D/projection;
2159 double numerator = 1 + m_alpha*chargeDensity;
2160 double denominator = 1 + m_gamma*chargeDensity;
2165 I = D * m_ratio* numerator/denominator;
2178 double absCosTheta = fabs(cosTheta);
2179 double projection = pow(absCosTheta,m_power) + m_delta;
2182 double a = m_alpha / projection;
2183 double b = 1 - m_gamma / projection*(
I/m_ratio);
2184 double c = -
I/m_ratio;
2187 cout<<
"both a and b coefficiants for hadron correction are 0"<<endl;
2191 double D = a != 0? (-b + sqrt(b*b - 4.0*a*c))/(2.0*a) : -c/b;
2193 cout<<
"D is less 0! will try another solution"<<endl;
2194 D=a != 0? (-b - sqrt(b*b + 4.0*a*c))/(2.0*a) : -c/b;
2196 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)
double abs(const EvtComplex &c)
*******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
void handle(const Incident &)
double T0Correc(double t0, double ex) const
double RungCorrec(int runNO, double ex) const
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvUnknown)
double LayerGainCorrec(int layid, double ex) const
double StandardCorrec(int runFlag, int ntpFlag, int runNO, double pathl, int wid, int layid, double adc, double dd, double eangle, double z, double costheta) const
double StandardHitCorrec(int calib_rec_Flag, int runFlag, int ntpFlag, int runNO, double pathl, int wid, int layid, double adc, double dd, double eangle, double costheta) const
double EntaCorrec(int layid, double enta, double ex) const
double SaturCorrec(int layid, double costheta, double ex) const
double StandardTrackCorrec(int calib_rec_Flag, int typFlag, int ntpFlag, int runNO, double ex, double costheta, double t0) 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 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 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