00001 #include "DedxCorrecSvc/DedxCorrecSvc.h"
00002 #include "DedxCorrecSvc/DedxCorrParameters.h"
00003 #include "GaudiKernel/Kernel.h"
00004 #include "GaudiKernel/IInterface.h"
00005 #include "GaudiKernel/StatusCode.h"
00006
00007 #include "GaudiKernel/SvcFactory.h"
00008 #include "GaudiKernel/MsgStream.h"
00009 #include "GaudiKernel/SmartDataPtr.h"
00010 #include "GaudiKernel/DataSvc.h"
00011
00012 #include "GaudiKernel/IIncidentSvc.h"
00013 #include "GaudiKernel/Incident.h"
00014 #include "GaudiKernel/IIncidentListener.h"
00015
00016 #include "Identifier/Identifier.h"
00017 #include "Identifier/MdcID.h"
00018 #include "CLHEP/Vector/ThreeVector.h"
00019 #include "CalibData/Dedx/DedxCalibData.h"
00020 #include "CalibData/CalibModel.h"
00021 #include <math.h>
00022 #include <vector>
00023 #include <iostream>
00024 #include <fstream>
00025 #include <string>
00026
00027 #include "TFile.h"
00028 #include "TTree.h"
00029 #include "TLeafD.h"
00030
00031 using namespace std;
00032 using CLHEP::Hep3Vector;
00033
00034
00035
00036
00037
00038
00039 DedxCorrecSvc::DedxCorrecSvc( const string& name, ISvcLocator* svcloc) :
00040 geosvc(0),Service (name, svcloc) {
00041 declareProperty("Run",m_run=1);
00042 declareProperty("init",m_init=1);
00043 declareProperty("par_flag",m_par_flag=0);
00044 declareProperty("Debug",m_debug=false);
00045 declareProperty("DebugI",m_debug_i=1);
00046 declareProperty("DebugJ",m_debug_j=1);
00047 m_initConstFlg = false;
00048
00049 }
00050
00051 DedxCorrecSvc::~DedxCorrecSvc(){
00052 }
00053
00054 StatusCode DedxCorrecSvc::queryInterface(const InterfaceID& riid, void** ppvInterface){
00055
00056 if( IID_IDedxCorrecSvc.versionMatch(riid) ){
00057 *ppvInterface = static_cast<IDedxCorrecSvc*> (this);
00058 } else{
00059 return Service::queryInterface(riid, ppvInterface);
00060 }
00061 return StatusCode::SUCCESS;
00062 }
00063
00064 StatusCode DedxCorrecSvc::initialize(){
00065
00066 MsgStream log(messageService(), name());
00067 log << MSG::INFO << name() << "DedxCorrecSvc::initialize()" << endreq;
00068
00069 StatusCode sc = Service::initialize();
00070 if( sc.isFailure() ) return sc;
00071
00072 IIncidentSvc* incsvc;
00073 sc = service("IncidentSvc", incsvc);
00074 int priority = 100;
00075 if( sc.isSuccess() ){
00076
00077 incsvc -> addListener(this, "NewRun", priority);
00078 }
00079
00080 StatusCode scgeo = service("MdcGeomSvc", geosvc);
00081 if(scgeo.isFailure() ) {
00082 log << MSG::ERROR << "GeoSvc failing!!!!!!!" << endreq;
00083 return scgeo;
00084 }
00085
00086 StatusCode scmgn = service ("MagneticFieldSvc",m_pIMF);
00087 if(scmgn!=StatusCode::SUCCESS) {
00088 log << MSG::ERROR << "Unable to open Magnetic field service"<<endreq;
00089 }
00090
00091 return StatusCode::SUCCESS;
00092 }
00093
00094 StatusCode DedxCorrecSvc::finalize(){
00095
00096 MsgStream log(messageService(), name());
00097 log << MSG::INFO << name() << "DedxCorrecSvc::finalize()" << endreq;
00098 return StatusCode::SUCCESS;
00099 }
00100
00101 void DedxCorrecSvc::handle(const Incident& inc){
00102
00103 MsgStream log( messageService(), name() );
00104 log << MSG::DEBUG << "handle: " << inc.type() << endreq;
00105
00106 if ( inc.type() == "NewRun" ){
00107 log << MSG::DEBUG << "New Run" << endreq;
00108
00109 if( ! m_initConstFlg )
00110 {
00111 if( m_init == 0 ) { init_param(); }
00112 else if( m_init ==1 ) { init_param_svc(); }
00113
00114
00115
00116
00117 }
00118 }
00119 }
00120
00121 double DedxCorrecSvc::f_larcos(double x, int nbin) {
00122 if(nbin!=80) return x;
00123 double m_absx(fabs(x));
00124 double m_charge(x/m_absx);
00125 if(m_absx>0.925 && m_absx<=0.950) return 0.9283*m_charge;
00126 if(m_absx>0.900 && m_absx<=0.925) return 0.9115*m_charge;
00127 if(m_absx>0.875 && m_absx<=0.900) return 0.8877*m_charge;
00128 if(m_absx>0.850 && m_absx<=0.875) return 0.8634*m_charge;
00129 if(m_absx>0.825 && m_absx<=0.850) return 0.8460*m_charge;
00130 if(m_absx>0.800 && m_absx<=0.825) return 0.8089*m_charge;
00131 }
00132
00133 void
00134 DedxCorrecSvc::init_param_svc() {
00135
00136 MsgStream log(messageService(), name());
00137 IDataProviderSvc* pCalibDataSvc;
00138 StatusCode sc = service("CalibDataSvc", pCalibDataSvc, true);
00139 if ( !sc.isSuccess() ) {
00140 log << MSG::ERROR
00141 << "Could not get IDataProviderSvc interface of CalibXmlCnvSvc"
00142 << endreq;
00143 return ;
00144 } else {
00145 log << MSG::DEBUG
00146 << "Retrieved IDataProviderSvc interface of CalibXmlCnvSvc"
00147 << endreq;
00148 }
00149
00150 Iner_Stepdoca = (Iner_DocaMax-Iner_DocaMin)/NumSlicesDoca;
00151 Out_Stepdoca = (Out_DocaMax-Out_DocaMin)/NumSlicesDoca;
00152
00153 std::string fullPath = "/Calib/DedxCal";
00154
00155 SmartDataPtr<CalibData::DedxCalibData> test(pCalibDataSvc, fullPath);
00156
00157
00158 N_run = test->getrunNO();
00159 int run_temp = 0;
00160 cout<<"N_run = "<<N_run<<endl;
00161 for(int j=0;j<10000;j++)
00162 {
00163 if(j<N_run)
00164 {
00165 for(int i=0;i<4;i++)
00166 {
00167 m_rung[i][j] = test->getrung(i,j);
00168 if(i==2 && m_rung[2][j]>run_temp) run_temp = m_rung[2][j];
00169 }
00170 }
00171 else
00172 {
00173 run_temp++;
00174 m_rung[0][j] = 1;
00175 m_rung[1][j] = 550;
00176 m_rung[2][j] = run_temp;
00177 m_rung[3][j] = 26.8;
00178 }
00179 }
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221 for(int i=0;i<4;i++) {
00222 for(int j=0;j<43;j++) {
00223 m_ddg[i][j] = test->getddg(i,j);
00224 m_ggs[i][j] = test->getggs(i,j);
00225 m_zdep[i][j] = test->getzdep(i,j);
00226
00227
00228
00229
00230
00231 }
00232 }
00233
00234 m_dedx_gain = test->getgain();
00235 std::cout<<"gain="<<m_dedx_gain<<"\n";
00236
00237 m_dedx_resol = test->getresol();
00238 std::cout<<"resol="<<m_dedx_resol<<"\n";
00239
00240 for(int i=0;i<43;i++) {
00241 m_layer_g[i] = test -> getlayerg(i);
00242 if(m_layer_g[i]>2.0 || m_layer_g[i]<0.5) m_layer_g[i] =1;
00243
00244 }
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258 for(int i=0;i<6796;i++) {
00259 m_wire_g[i] = test -> getwireg(i);
00260
00261 }
00262
00263
00264
00265
00266
00267
00268 int kk=3;
00269 for(int i=0;i<6796;i++) {
00270 m_valid[i] = 1;
00271
00272 for(int j=0; j<25; j++){
00273 if( i == dead_wire[kk][j] )
00274 {m_valid[i] = 0;
00275
00276
00277 }
00278 }
00279
00280 }
00281
00282
00283 cos_k.clear();
00284 cos_b.clear();
00285
00286 if(true){
00287 const int nbin=80;
00288 vector<double> cos;
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302 for(int i=0; i<nbin; i++){
00303 cos.push_back(test -> get_costheta(i));
00304 }
00305 for(int i=0;i<nbin-1;i++){
00306 double k=0;
00307 double b=0;
00308 if(cos[i]>0.0001){
00309 if(cos[i+1]>0.0001){
00310 double x1=-1.00+(0.5+i)*(2.00/nbin);
00311 double y1=cos[i];
00312 double x2=-1.00+(0.5+i+1)*(2.00/nbin);
00313 double y2=cos[i+1];
00314
00315 if(fabs(x1)>0.8) x1 = f_larcos(x1, nbin);
00316 if(fabs(x2)>0.8) x2 = f_larcos(x2, nbin);
00317 k=(y2-y1)/(x2-x1);
00318 b=y1-k*x1;
00319
00320 }
00321 else if(i>0){
00322 if(cos[i-1]>0.0001){
00323 double x1=-1.00+(0.5+i-1)*(2.00/nbin);
00324 double y1=cos[i-1];
00325 double x2=-1.00+(0.5+i)*(2.00/nbin);
00326 double y2=cos[i];
00327
00328 if(fabs(x1)>0.8) x1 = f_larcos(x1, nbin);
00329 if(fabs(x2)>0.8) x2 = f_larcos(x2, nbin);
00330 k=(y2-y1)/(x2-x1);
00331 b=y1-k*x1;
00332
00333 }
00334 }
00335 }
00336 else {
00337 if(i>0){
00338 if(cos[i-1]>0.0001 && cos[i+1]>0.0001){
00339 double x1=-1.00+(0.5+i-1)*(2.00/nbin);
00340 double y1=cos[i-1];
00341 double x2=-1.00+(0.5+i+1)*(2.00/nbin);
00342 double y2=cos[i+1];
00343
00344 if(fabs(x1)>0.8) x1 = f_larcos(x1, nbin);
00345 if(fabs(x2)>0.8) x2 = f_larcos(x2, nbin);
00346 k=(y2-y1)/(x2-x1);
00347 b=y1-k*x1;
00348
00349 }
00350 }
00351 }
00352
00353 cos_k.push_back(k);
00354 cos_b.push_back(b);
00355 }
00356 }
00357
00358 t0_k.clear();
00359 t0_b.clear();
00360 if(true){
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380 const int nbin=35;
00381 vector<double> xbin;
00382 vector<double> ybin;
00383 for(int i=0; i<35; i++){
00384 xbin.push_back(test ->get_t0(i));
00385 ybin.push_back(test ->get_dedx(i));
00386
00387 }
00388 for(int i=0;i<nbin-1;i++){
00389 double k=0;
00390 double b=0;
00391 if(ybin[i]>0){
00392 if(ybin[i+1]>0){
00393 double x1=xbin[i];
00394 double y1=ybin[i];
00395 double x2=xbin[i+1];
00396 double y2=ybin[i+1];
00397 k=(y2-y1)/(x2-x1);
00398 b=(y1*x2-y2*x1)/(x2-x1);
00399 }
00400 else if(i>0){
00401 if(ybin[i-1]>0){
00402 double x1=xbin[i-1];
00403 double y1=ybin[i-1];
00404 double x2=xbin[i];
00405 double y2=ybin[i];
00406 k=(y2-y1)/(x2-x1);
00407 b=(y1*x2-y2*x1)/(x2-x1);
00408 }
00409 }
00410 }
00411 else {
00412 if(i>0){
00413 if(ybin[i-1]>0 && ybin[i+1]>0){
00414 double x1=xbin[i-1];
00415 double y1=ybin[i-1];
00416 double x2=xbin[i+1];
00417 double y2=ybin[i+1];
00418 k=(y2-y1)/(x2-x1);
00419 b=(y1*x2-y2*x1)/(x2-x1);
00420 }
00421 }
00422 }
00423 t0_k.push_back(k);
00424 t0_b.push_back(b);
00425 }
00426 }
00427
00428 if(true){
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466 const int n = 1600;
00467 double docaeangle_gain[n];
00468 double docaeangle_chisq[n];
00469 double docaeangle_entries[n];
00470 double cell[n];
00471 for(int i=0; i<n; i++){
00472 cell[i] = i;
00473 docaeangle_gain[i] = test -> get_out_gain(i);
00474 docaeangle_chisq[i] = test -> get_out_chi(i);
00475 docaeangle_entries[i] = test -> get_out_hits(i);
00476 int Id_Doca_temp = test -> get_id_doca(i);
00477 int Ip_Eangle_temp = test -> get_ip_eangle(i);
00478 m_docaeangle[Id_Doca_temp][Ip_Eangle_temp] = docaeangle_gain[i];
00479 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;
00480
00481 }
00482 }
00483
00484
00485
00486 int onedsize=test->get_enanglesize();
00487 m_venangle.clear();
00488 for(int i=0; i< onedsize; i++){
00489 m_venangle.push_back(test->get_enangle(i));
00490 }
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504 const int hadronNo=test -> get_hadronNo();
00505
00506 m_alpha=test -> get_hadron(0);
00507
00508 m_gamma=test -> get_hadron(1);
00509
00510 m_delta=test -> get_hadron(2);
00511
00512 m_power=test -> get_hadron(3);
00513
00514 m_ratio=test -> get_hadron(4);
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531 }
00532
00533 double DedxCorrecSvc::WireGainCorrec(int wireid, double ex) const{
00534 if( m_wire_g[wireid] > 0 ){
00535 double ch_dedx = (ex/m_wire_g[wireid])*m_valid[wireid];
00536 return ch_dedx;
00537 }
00538 else if( m_wire_g[wireid] == 0 ){
00539 return ex;
00540 }
00541 else return 0;
00542 }
00543
00544 double
00545 DedxCorrecSvc::SaturCorrec( int layer, double costheta, double dedx ) const {
00546
00547 double dedx_ggs;
00548
00549 costheta = fabs(costheta);
00550 if(m_par_flag == 1) {
00551 dedx_ggs = m_ggs[0][layer] + m_ggs[1][layer]*costheta +
00552 m_ggs[2][layer]*pow(costheta,2) + m_ggs[3][layer]*pow(costheta,3);
00553 } else if(m_par_flag == 0) {
00554 dedx_ggs = m_ggs[0][layer] + m_ggs[1][layer]*T1(costheta) +
00555 m_ggs[2][layer]*T2(costheta) + m_ggs[3][layer]*T3(costheta);
00556 }
00557
00558 dedx_ggs = dedx/dedx_ggs;
00559 if(dedx_ggs>0.0) return dedx_ggs;
00560 else return dedx;
00561 }
00562
00563
00564 double
00565 DedxCorrecSvc::CosthetaCorrec( double costheta, double dedx ) const {
00566
00567 double dedx_cos;
00568
00569 if(fabs(costheta)>1.0) return dedx;
00570
00571 const int nbin=cos_k.size()+1;
00572 const double step=2.00/nbin;
00573 int n= (int)((costheta+1.00-0.5*step)/step);
00574 if(costheta>(1.00-0.5*step))
00575 n=nbin-2;
00576
00577 if(costheta>-0.5*step && costheta<=0)
00578 dedx_cos=cos_k[n-1]*costheta+cos_b[n-1];
00579 else if(costheta>0 && costheta<0.5*step)
00580 dedx_cos=cos_k[n+1]*costheta+cos_b[n+1];
00581 else
00582 dedx_cos=cos_k[n]*costheta+cos_b[n];
00583
00584
00585
00586
00587
00588 if(nbin==80){
00589 if(costheta>0.80 && costheta<0.95){
00590 n = 77;
00591 if(costheta<0.9282) n--;
00592 if(costheta<0.9115) n--;
00593 if(costheta<0.8877) n--;
00594 if(costheta<0.8634) n--;
00595 if(costheta<0.8460) n--;
00596 if(costheta<0.8089) n--;
00597 dedx_cos=cos_k[n]*costheta+cos_b[n];
00598 }
00599 else if(costheta<-0.80 && costheta>-0.95){
00600 n = 2;
00601 if(costheta>-0.9115) n++;
00602 if(costheta>-0.8877) n++;
00603 if(costheta>-0.8634) n++;
00604 if(costheta>-0.8460) n++;
00605 if(costheta>-0.8089) n++;
00606 dedx_cos=cos_k[n]*costheta+cos_b[n];
00607 }
00608 }
00609
00610 if(dedx_cos>0){
00611 dedx_cos = dedx/dedx_cos;
00612 return dedx_cos;
00613 }
00614 else return dedx;
00615 }
00616
00617
00618 double
00619 DedxCorrecSvc::T0Correc( double t0, double dedx ) const {
00620
00621 double dedx_t0;
00622 const int nbin=t0_k.size()+1;
00623 if(nbin!=35)
00624 cout<<"there should be 35 bins for t0 correction, check it!"<<endl;
00625
00626 int n=0;
00627 if(t0<575)
00628 n=0;
00629 else if(t0<610)
00630 n=1;
00631 else if(t0>=610 && t0<1190){
00632 n=(int)( (t0-610.0)/20.0 ) + 2;
00633 }
00634 else if(t0>=1190 && t0<1225)
00635 n=31;
00636 else if(t0>=1225 && t0<1275)
00637 n=32;
00638 else if(t0>=1275)
00639 n=33;
00640
00641 dedx_t0=t0_k[n]*t0+t0_b[n];
00642
00643 if(dedx_t0>0){
00644 dedx_t0 = dedx/dedx_t0;
00645 return dedx_t0;
00646 }
00647 else return dedx;
00648 }
00649
00650 double
00651 DedxCorrecSvc::HadronCorrec( double costheta, double dedx ) const {
00652
00653
00654 dedx=dedx/550.00;
00655 return D2I(costheta, I2D(costheta,1.00)/1.00*dedx)*550;
00656 }
00657 double
00658 DedxCorrecSvc::LayerGainCorrec( int layid, double dedx ) const {
00659
00660 if( m_layer_g[layid] > 0 ){
00661 double ch_dedx = dedx/m_layer_g[layid];
00662 return ch_dedx;
00663 }
00664 else if( m_layer_g[layid] == 0 ){
00665 return dedx;
00666 }
00667 else return 0;
00668 }
00669
00670
00671 double
00672 DedxCorrecSvc::RungCorrec( int runNO, double dedx ) const{
00673
00674 double dedx_rung;
00675 int run_ture =0;
00676
00677
00678 for(int j=0;j<10000;j++) {
00679 if(runNO == m_rung[2][j]) {
00680 dedx_rung = dedx/m_rung[0][j];
00681 run_ture =1;
00682 return dedx_rung;
00683 }
00684 }
00685 if(run_ture ==0)
00686 {
00687 cout<<"Warning!!! in DedxCorrecSvc::RungCorrec(): no rungain to "<<runNO<<endl;
00688 exit(1);
00689 }
00690 }
00691
00692
00693 double
00694 DedxCorrecSvc::DriftDistCorrec( int layer, double dd, double dedx ) const {
00695
00696 double dedx_ddg;
00697
00698
00699 dd = fabs(dd);
00700 if(m_par_flag == 1) {
00701 dedx_ddg = m_ddg[0][layer] + m_ddg[1][layer]*dd +
00702 m_ddg[2][layer]*dd*dd + m_ddg[3][layer]*pow(dd,3);
00703 } else if(m_par_flag == 0) {
00704 dedx_ddg = m_ddg[0][layer] + m_ddg[1][layer]*T1(dd) +
00705 m_ddg[2][layer]*T2(dd) + m_ddg[3][layer]*T3(dd);
00706 }
00707
00708 dedx_ddg = dedx/dedx_ddg;
00709 if (dedx_ddg>0.0) return dedx_ddg;
00710 else return dedx;
00711 }
00712
00713
00714 double
00715 DedxCorrecSvc::EntaCorrec( int layer, double eangle, double dedx ) const {
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729 if(eangle>-0.25 && eangle<0.25){
00730 double stepsize= 0.5/m_venangle.size();
00731 int nsize= m_venangle.size();
00732 double slope=0;
00733 double offset=1;
00734 double y1=0,y2=0,x1=0,x2=0;
00735
00736 if(eangle>=-0.25+0.5*stepsize && eangle<=0.25-0.5*stepsize){
00737 int bin = (int)( (eangle-(-0.25+0.5*stepsize))/stepsize);
00738 y1=m_venangle[bin];
00739 x1=-0.25+0.5*stepsize+bin*stepsize;
00740 y2=m_venangle[bin+1];
00741 x2=-0.25+1.5*stepsize+bin*stepsize;
00742 }
00743 else if(eangle<=-0.25+0.5*stepsize){
00744 y1=m_venangle[0];
00745 x1=-0.25+0.5*stepsize;
00746 y2=m_venangle[1];
00747 x2=-0.25+1.5*stepsize;
00748 }
00749 else if( eangle>=0.25-0.5*stepsize){
00750 y1=m_venangle[nsize-2];
00751 x1=0.25-1.5*stepsize;
00752 y2=m_venangle[nsize-1];
00753 x2=0.25-0.5*stepsize;
00754 }
00755 double kcof= (y2-y1)/(x2-x1);
00756 double bcof= y1-kcof*x1;
00757 double ratio = kcof*eangle+bcof;
00758 dedx=dedx/ratio;
00759 }
00760
00761 return dedx;
00762 }
00763
00764
00765 double
00766 DedxCorrecSvc::ZdepCorrec( int layer, double z, double dedx ) const {
00767
00768 double dedx_zdep;
00769 if(m_par_flag == 1) {
00770 dedx_zdep = m_zdep[0][layer] + m_zdep[1][layer]*z +
00771 m_zdep[2][layer]*z*z + m_zdep[3][layer]*pow(z,3);
00772 } else if(m_par_flag == 0) {
00773 dedx_zdep = m_zdep[0][layer] + m_zdep[1][layer]*T1(z) +
00774 m_zdep[2][layer]*T2(z) + m_zdep[3][layer]*T3(z);
00775 }
00776 dedx_zdep = dedx/dedx_zdep;
00777 if (dedx_zdep>0.0) return dedx_zdep;
00778 else return dedx;
00779
00780
00781 }
00782
00783
00784 double
00785 DedxCorrecSvc::DocaSinCorrec( int layer,double doca, double eangle, double dedx ) const {
00786 if(m_debug) cout<<"DedxCorrecSvc::DocaSinCorrec"<<endl;
00787
00788
00789 if(eangle>0.25) eangle = eangle -0.5;
00790 else if(eangle < -0.25) eangle = eangle +0.5;
00791 int iDoca;
00792 int iEAng = 0;
00793 doca = doca/doca_norm[layer];
00794 iDoca =(Int_t)floor((doca-Out_DocaMin)/Out_Stepdoca);
00795 if(doca<Out_DocaMin) iDoca=0;
00796 if(doca>Out_DocaMax) iDoca=NumSlicesDoca-1;
00797 if(iDoca >=(Int_t)floor((Out_DocaMax-Out_DocaMin)/Out_Stepdoca) )
00798 iDoca = (Int_t)floor((Out_DocaMax-Out_DocaMin)/Out_Stepdoca)-1;
00799 if(iDoca<0) iDoca = 0;
00800 if(m_debug) cout<<"iDoca : "<<iDoca<<" doca : "<<doca<<" Out_DocaMin : "<<Out_DocaMin<<" Out_Stepdoca : "<<Out_Stepdoca<<endl;
00801
00802
00803 for(int i =0; i<14; i++){
00804
00805 if(eangle <Eangle_value_cut[i] || eangle > Eangle_value_cut[i+1]) continue;
00806 else if(eangle>= Eangle_value_cut[i] && eangle < Eangle_value_cut[i+1]) {
00807 for(int k =0; k<i; k++){
00808 iEAng+= Eangle_cut_bin[k];
00809 }
00810 double eangle_bin_cut_step = (Eangle_value_cut[i+1] - Eangle_value_cut[i])/Eangle_cut_bin[i];
00811 int temp_bin = int((eangle-Eangle_value_cut[i])/eangle_bin_cut_step);
00812 iEAng+= temp_bin;
00813 }
00814 }
00815
00816 if(m_docaeangle[iDoca][iEAng]>0) {
00817 if(m_debug && (iDoca==m_debug_i) && (iEAng==m_debug_j))
00818 cout << "doca: " << doca << " eang" << eangle << " dedx before: " << dedx << endl;
00819 dedx = dedx/m_docaeangle[iDoca][iEAng];
00820 if(m_debug && (iDoca==m_debug_i) && (iEAng==m_debug_j))
00821 cout << "gain: " << m_docaeangle[iDoca][iEAng] << " dedx after: " << dedx << endl;
00822 }
00823 return dedx;
00824 }
00825
00826
00827 double
00828 DedxCorrecSvc::DipAngCorrec(int layer, double costheta, double dedx) const {
00829 }
00830
00831 double
00832 DedxCorrecSvc::GlobalCorrec( double dedx) const{
00833 if( m_mdcg_flag == 0 ) return dedx;
00834 double calib_ex = dedx;
00835 if( m_dedx_gain > 0 ) calib_ex /= m_dedx_gain;
00836 return calib_ex;
00837 }
00838
00839
00840
00841 double
00842 DedxCorrecSvc::CellCorrec( int ser, double adc, double dd, double sinenta,
00843 double z, double costheta ) const {
00844
00845 if( m_rung_flag == 0 && m_wireg_flag == 0 && m_ddg_flag == 0
00846 && m_layerg_flag == 0 && m_zdep_flag == 0 &&
00847 m_ggs_flag == 0) return adc;
00848 adc = m_valid[ser]*m_wire_g[ser]*adc;
00849
00850 int lyr = ser;
00851 double ex = adc;
00852 double correct1_ex , correct2_ex, correct3_ex, correct4_ex, correct5_ex;
00853
00854 if( m_ggs_flag) {
00855 correct1_ex = SaturCorrec( lyr, costheta, adc );
00856 ex = correct1_ex;
00857 } else {
00858 correct1_ex = adc;
00859 }
00860
00861 if( m_ddg_flag) {
00862 correct2_ex = DriftDistCorrec( lyr, dd, correct1_ex );
00863 ex = correct2_ex;
00864 } else {
00865 correct2_ex =correct1_ex;
00866 }
00867 if( m_enta_flag) {
00868 correct3_ex = DriftDistCorrec( lyr, sinenta, correct2_ex );
00869 ex = correct3_ex;
00870 } else {
00871 correct3_ex =correct2_ex;
00872 }
00873
00874 if( m_zdep_flag) {
00875 correct4_ex = ZdepCorrec( lyr, z, correct3_ex );
00876 ex = correct4_ex;
00877 } else {
00878 correct4_ex = correct3_ex;
00879 }
00880
00881 if( m_layerg_flag) {
00882 correct5_ex = LayerGainCorrec( lyr, correct4_ex );
00883 ex = correct5_ex;
00884 } else {
00885 correct5_ex = correct4_ex;
00886 }
00887 return ex;
00888
00889 }
00890
00891 double
00892 DedxCorrecSvc::LayerCorrec( int layer, double z, double costheta, double ex ) const{
00893
00894
00895 if( m_zdep_flag == 0 && m_ggs_flag == 0 ) return ex;
00896
00897 double calib_ex = ZdepCorrec( layer, z, ex );
00898 if( m_ggs_flag != 0 ) calib_ex = SaturCorrec( layer, costheta, calib_ex );
00899 return calib_ex;
00900
00901 }
00902
00903 double
00904 DedxCorrecSvc::TrkCorrec( double costheta, double dedx ) const{
00905
00906 if( m_mdcg_flag == 0 ) return dedx;
00908 double calib_ex = dedx;
00909
00910 double run_const = m_dedx_gain;
00911 if( run_const > 0 && m_mdcg_flag != 0 ) calib_ex /= run_const;
00912
00913 return calib_ex;
00914
00915 }
00916
00917
00918 double
00919 DedxCorrecSvc::StandardCorrec( int runFlag, int ntpFlag, int runNO, double pathl, int wid, int layid, double adc, double dd, double eangle, double z, double costheta ) const {
00920
00921
00922
00923
00924
00925
00927 double ex = adc;
00928 if( runNO<0 ) return ex;
00929 ex = ex*1.5/pathl;
00930
00931
00932 if( ntpFlag ==0) return ex;
00933
00934 if( m_rung_flag == 0 && m_wireg_flag == 0 && m_dcasin_flag==0 && m_ddg_flag == 0
00935 && m_layerg_flag == 0 && m_zdep_flag == 0 &&
00936 m_ggs_flag == 0) return ex;
00937
00938 if(m_rung_flag) {
00939 ex = RungCorrec( runNO, ex );
00940 }
00941
00942 if( m_wireg_flag) {
00943 ex = WireGainCorrec(wid, ex);
00944 }
00945
00946 if( m_dcasin_flag) {
00947 if(runFlag<3) {
00948 ex = DriftDistCorrec( layid, dd, ex );
00949 }
00950 else{ ex = DocaSinCorrec(layid, dd, eangle, ex);}
00951 }
00952
00953 if(m_enta_flag && runFlag>=3){
00954 ex = EntaCorrec(layid, eangle, ex);
00955 }
00956
00957
00958 if(m_ddg_flag) {
00959 ex = DriftDistCorrec( layid, dd, ex );
00960 }
00961
00962 if(m_ggs_flag) {
00963 if(runFlag <3 ){
00964 ex = SaturCorrec( layid, costheta, ex );
00965 }
00966 else{ ex = CosthetaCorrec( costheta, ex );}
00967
00968 }
00969
00970 if( m_sat_flag) {
00971 ex = HadronCorrec( costheta, ex );
00972 }
00973
00974 if( m_zdep_flag) {
00975 ex = ZdepCorrec( layid, z, ex );
00976 }
00977
00978 if( m_layerg_flag) {
00979 ex = LayerGainCorrec( layid, ex );
00980 }
00981
00982 if( m_dip_flag){
00983 ex = DipAngCorrec(layid, costheta, ex);
00984 }
00985
00986 if( m_mdcg_flag) {
00987 ex = GlobalCorrec( ex );
00988 }
00989 return ex;
00990 }
00991
00992 double
00993 DedxCorrecSvc::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 {
00994 if(m_debug) cout<<"DedxCorrecSvc::StandardHitCorrec"<<endl;
00995
00996
00997
00998
00999
01000
01001
01002 double ex = adc;
01003 if( runNO<0 ) return ex;
01004 ex = ex*1.5/pathl;
01005
01006
01007 if( ntpFlag ==0) return ex;
01008
01009
01010
01011 if( m_rung_flag == 0 && m_wireg_flag == 0 && m_ddg_flag == 0
01012 && m_layerg_flag == 0 && m_zdep_flag == 0 && m_dcasin_flag==0
01013 && m_ggs_flag == 0 && m_enta_flag==0) return ex;
01014
01015 if(m_rung_flag) {
01016 ex = RungCorrec( runNO, ex );
01017 }
01018
01019
01020 if( m_wireg_flag) {
01021 ex = WireGainCorrec(wid, ex);
01022 }
01023
01024
01025 if( m_dcasin_flag) {
01026 if(runFlag<3){
01027 ex = DriftDistCorrec( layid, dd, ex );
01028 }
01029 else{
01030
01031 ex = DocaSinCorrec(layid, dd, eangle, ex);
01032 }
01033 }
01034
01035
01036 if(m_enta_flag && runFlag>=3){
01037 ex = EntaCorrec(layid, eangle, ex);
01038 }
01039
01040
01041 if( m_ddg_flag) {
01042 ex = DriftDistCorrec( layid, dd, ex );
01043 }
01044
01045
01046 if(m_ggs_flag) {
01047 if(runFlag <3 ){
01048 ex = SaturCorrec( layid, costheta, ex );
01049 }
01050 else{ ex = ex;}
01051 }
01052
01053 return ex;
01054 }
01055
01056
01057 double
01058 DedxCorrecSvc::StandardTrackCorrec(int calib_rec_Flag, int runFlag, int ntpFlag, int runNO, double ex, double costheta, double t0 ) const {
01059 if(m_debug) cout<<"DedxCorrecSvc::StandardTrackCorrec"<<endl;
01060 if( runNO<0 ) return ex;
01061 if( ntpFlag ==0) return ex;
01062 if( runFlag <3) return ex;
01063 if( calib_rec_Flag ==1){
01064 ex = CosthetaCorrec( costheta, ex );
01065 if(m_t0_flag) ex= T0Correc(t0, ex);
01066 return ex;
01067 }
01068
01069
01070 if( m_ggs_flag) {
01071 ex = CosthetaCorrec( costheta, ex );
01072 }
01073
01074 if(m_t0_flag){
01075 if(runFlag==3) {ex= T0Correc(t0, ex);}
01076 else if(runFlag>3) {ex=ex;}
01077 }
01078
01079 if( m_sat_flag) {
01080 ex = HadronCorrec( costheta, ex );
01081 }
01082
01083 if(m_rung_flag && calib_rec_Flag ==2){
01084 double rungain_temp =RungCorrec( runNO, ex )/ex;
01085 ex = ex/rungain_temp;
01086 }
01087
01088
01089 return ex;
01090
01091 }
01092
01093
01094
01095 void
01096 DedxCorrecSvc::init_param() {
01097
01098
01099
01100 for( int i = 0; i<6796 ; i++) {
01101 m_valid[i] = 1.0;
01102 m_wire_g[i] = 1.0;
01103 }
01104 m_dedx_gain = 1.0;
01105 m_dedx_resol = 1.0;
01106 for(int j = 0; j<100; j++){
01107 m_rung[0][j] =1;
01108 }
01109 for(int j = 0; j<43; j++) {
01110 m_layer_g[j] = 1.0;
01111 m_ggs[0][j] = 1.0;
01112 m_ddg[0][j] = 1.0;
01113 m_enta[0][j] = 1.0;
01114 m_zdep[0][j] = 1.0;
01115 for(int k = 1; k<4; k++ ) {
01116 m_ggs[k][j] = 0.0;
01117 m_ddg[k][j] = 0.0;
01118 m_enta[k][j] = 0.0;
01119 m_zdep[k][j] = 0.0;
01120 }
01121 }
01122
01123 std::cout<<"DedxCorrecSvc::init_param()!!!"<<std::endl;
01124 std::cout<<"hello,init_param"<<endl;
01125 m_initConstFlg =true;
01126
01127 }
01128
01129
01130 void
01131 DedxCorrecSvc::set_flag( int calib_F ) {
01132
01133 cout<<"calib_F is = "<<calib_F<<endl;
01134 if(calib_F<0){ m_enta_flag = 0; calib_F = abs(calib_F); }
01135 else m_enta_flag = 1;
01136 m_rung_flag = ( calib_F & 1 )? 1 : 0;
01137 m_wireg_flag = ( calib_F & 2 )? 1 : 0;
01138 m_dcasin_flag = ( calib_F & 4 )? 1 : 0;
01139 m_ggs_flag = ( calib_F & 8 )? 1 : 0;
01140 m_ddg_flag = 0;
01141
01142 m_t0_flag = ( calib_F & 16 )? 1 : 0;
01143 m_sat_flag = ( calib_F & 32 )? 1 : 0;
01144 m_layerg_flag = ( calib_F & 64 )? 1 : 0;
01145
01146 m_dip_flag = ( calib_F & 256 )? 1 : 0;
01147 m_mdcg_flag = ( calib_F & 512 )? 1 : 0;
01148 }
01149
01150
01151
01152
01153
01154
01156
01157
01158
01159
01160
01161
01162
01163
01164
01165
01166
01167
01168
01169
01170
01171
01172
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193
01194
01195
01196
01197
01198
01199
01200
01201
01202
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225
01226
01227
01228
01229
01230
01231
01232
01233
01234
01235
01236
01237
01238
01239
01240
01241
01242
01243
01244
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255
01256
01257
01258
01259
01260
01261
01262
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272
01273
01274
01275
01276
01277
01278
01279
01280
01281
01282
01283
01284
01285
01286
01287
01288
01289
01290
01291
01292
01293
01294
01295
01296
01297
01298
01299
01300
01301
01302
01303
01304
01305
01306
01307
01308
01309
01310
01311
01312
01313
01314
01315
01316
01317
01318
01319
01320
01321
01322
01323
01324
01325
01326
01327
01328
01329
01330
01331
01332
01333
01334
01335
01336
01337
01338
01339
01340
01341
01342
01343
01344
01345
01346
01347
01348
01349
01350
01351
01352
01353
01354
01355
01356
01357
01358
01359
01360
01361
01362
01363
01364
01365
01366
01367
01368
01369
01370
01371
01372
01373
01374
01375
01376
01377
01378
01379
01380
01381
01382
01383
01384
01385
01386
01387
01388
01389
01390
01391
01392
01393
01394
01395
01396
01397
01398
01399
01400
01401
01402
01403
01404
01405
01406
01407
01408
01409
01410
01411
01412
01413
01414
01415
01416
01417
01418
01419
01420
01421
01422
01423
01424
01425
01426
01427
01428
01429
01430
01431
01432
01433
01434
01435
01436
01437
01438
01439
01440
01441
01442
01443
01444
01445
01446
01447
01448
01449
01450
01451
01452
01453
01454
01455
01456
01457
01458
01459
01460
01461
01462
01463
01464
01465
01466
01467
01468
01469
01470
01471
01472
01473
01474
01475
01476
01477
01478
01479
01480
01481
01482
01483
01484
01485
01486
01487
01488 double
01489 DedxCorrecSvc::PathL( int ntpFlag, const Dedx_Helix& hel, int layer, int cellid, double z ) const {
01490
01491 double length = geosvc->Layer(layer)->Length();
01492 int genlay = geosvc->Layer(layer)->Gen();
01493 double East_lay_X = geosvc->GeneralLayer(genlay)->SxEast();
01494 double East_lay_Y = geosvc->GeneralLayer(genlay)->SyEast();
01495 double East_lay_Z = geosvc->GeneralLayer(genlay)->SzEast();
01496 double West_lay_X = geosvc->GeneralLayer(genlay)->SxWest();
01497 double West_lay_Y = geosvc->GeneralLayer(genlay)->SyWest();
01498 double West_lay_Z = geosvc->GeneralLayer(genlay)->SzWest();
01499
01500 HepPoint3D East_origin(East_lay_X, East_lay_Y, East_lay_Z);
01501 HepPoint3D West_origin(West_lay_X, West_lay_Y, West_lay_Z);
01502 Hep3Vector wire = (CLHEP::Hep3Vector)East_origin - (CLHEP::Hep3Vector)West_origin;
01503 HepPoint3D piovt_z =(z*10+length/2 )/length * wire + West_origin;
01504 piovt_z = piovt_z*0.1;
01505
01506
01507
01508 HepPoint3D piv(hel.pivot());
01509
01510
01511 double dr0 = hel.a()[0];
01512 double phi0 = hel.a()[1];
01513 double kappa = hel.a()[2];
01514 double dz0 = hel.a()[3];
01515 double tanl = hel.a()[4];
01516
01517
01518 double Bz = 1000*(m_pIMF->getReferField());
01519 double ALPHA_loc = 1000/(2.99792458*Bz);
01520
01521
01522
01523
01524
01525 int charge = ( kappa >= 0 )? 1 : -1;
01526 double rho = ALPHA_loc/kappa;
01527 double pt = fabs( 1.0/kappa );
01528 double lambda = atan( tanl );
01529 double theta = M_PI_2- lambda;
01530 double sintheta = sin(M_PI_2-atan(tanl));
01531
01532 double phi = fmod(phi0 + M_PI*4, M_PI*2);
01533 double csf0 = cos(phi);
01534 double snf0 = (1. - csf0) * (1. + csf0);
01535 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
01536 if(phi > M_PI) snf0 = - snf0;
01537
01538
01539
01540
01541 double x_c = piv.x() + ( hel.dr() + rho )*csf0;
01542 double y_c = piv.y() + ( hel.dr() + rho )*snf0;
01543 double z_c = piv.z() + hel.dz();
01544 HepPoint3D ccenter(x_c, y_c, 0.0);
01545 double m_c_perp(ccenter.perp());
01546 Hep3Vector m_c_unit((HepPoint3D)ccenter.unit());
01547
01548
01550 double x_c_boost = x_c - piovt_z.x();
01551 double y_c_boost = y_c - piovt_z.y();
01552 double z_c_boost = z_c - piovt_z.z();
01553 HepPoint3D ccenter_boost(x_c_boost, y_c_boost, 0.0);
01554 double m_c_perp_boost(ccenter_boost.perp());
01555
01556
01557 Hep3Vector m_c_unit_boost((HepPoint3D)ccenter_boost.unit());
01558
01559
01560 double phi_io[2];
01561 HepPoint3D IO = (-1)*charge*m_c_unit;
01562 double dphi0 = fmod( IO.phi()+4*M_PI,2*M_PI ) - phi;
01563 double IO_phi = fmod( IO.phi()+4*M_PI,2*M_PI );
01564
01565
01566
01567 if( dphi0 > M_PI ) dphi0 -= 2*M_PI;
01568 else if( dphi0 < -M_PI ) dphi0 += 2*M_PI;
01569
01570
01571 phi_io[0] = -(1+charge)*M_PI_2 - charge*dphi0;
01572
01573 phi_io[1] = phi_io[0]+1.5*M_PI;
01574
01575 double m_crio[2];
01576 double m_zb, m_zf, Calpha;
01577
01578
01579 double rcsiz1= geosvc->Layer(layer)->RCSiz1();
01580 double rcsiz2= geosvc->Layer(layer)->RCSiz2();
01581 double rlay= geosvc->Layer(layer)->Radius();
01582 int ncell= geosvc->Layer(layer)->NCell();
01583 double phioffset= geosvc->Layer(layer)->Offset();
01584 float shift= geosvc->Layer(layer)->Shift();
01585 double slant= geosvc->Layer(layer)->Slant();
01586
01587 int type = geosvc->Layer(layer)->Sup()->Type();
01588
01590
01592 int w0id = geosvc->Layer(layer)->Wirst();
01593 int wid = w0id + cellid;
01594 HepPoint3D backkward = geosvc->Wire(wid)->BWirePos();
01595 HepPoint3D forward = geosvc->Wire(wid)->FWirePos();
01596 double x_lay_backward = geosvc->Wire(layer, cellid)->Backward().x();
01597 double y_lay_backward = geosvc->Wire(layer, cellid)->Backward().y();
01598 double x_lay_forward = geosvc->Wire(layer, cellid)->Forward().x();
01599 double y_lay_forward = geosvc->Wire(layer, cellid)->Forward().y();
01600 double r_lay_backward = sqrt(x_lay_backward*x_lay_backward+y_lay_backward*y_lay_backward);
01601 double r_lay_forward = sqrt(x_lay_forward*x_lay_forward+y_lay_forward*y_lay_forward);
01602 double r_lay_use = ((z*10+length/2)/length)*(r_lay_backward-r_lay_forward) + r_lay_forward;
01603
01604
01605
01606
01607
01608
01609
01610 r_lay_use = 0.1*r_lay_use;
01611 rcsiz1 = 0.1*rcsiz1;
01612 rcsiz2 = 0.1*rcsiz2;
01613 rlay = 0.1*rlay;
01614 length = 0.1*length;
01615 m_zb = 0.5*length;
01616 m_zf = -0.5*length;
01617 m_crio[0] = rlay - rcsiz1;
01618 m_crio[1] = rlay + rcsiz2;
01619
01620 int sign = -1;
01621 int epflag[2];
01622 Hep3Vector iocand[2];
01623 Hep3Vector cell_IO[2];
01624 double dphi, downin;
01625 Hep3Vector zvector;
01626
01627 if( type ) {
01628 downin = (z*z-m_zb*m_zb)*pow(tan(slant),2);
01629 m_crio[0] = sqrt(m_crio[0]*m_crio[0]+downin);
01630 m_crio[1] = sqrt(m_crio[1]*m_crio[1]+downin);
01631 }
01632
01633
01634
01635 for( int i = 0; i < 2; i++ ) {
01636 double cos_alpha = m_c_perp_boost*m_c_perp_boost + m_crio[i]*m_crio[i] - rho*rho;
01637 cos_alpha = 0.5*cos_alpha/( m_c_perp_boost*m_crio[i] );
01638 if(fabs(cos_alpha)>1&&i==0) return(-1.0);
01639 if(fabs(cos_alpha)>1&&i==1) {
01640 cos_alpha = m_c_perp_boost*m_c_perp_boost + m_crio[0]*m_crio[0] - rho*rho;
01641 cos_alpha = 0.5*cos_alpha/( m_c_perp_boost*m_crio[0] );
01642 Calpha = 2.0*M_PI-acos( cos_alpha );
01643 } else {
01644 Calpha = acos( cos_alpha );
01645 }
01646 epflag[i] = 0;
01647 iocand[i] = m_c_unit_boost;
01648 iocand[i].rotateZ( charge*sign*Calpha );
01649 iocand[i]*= m_crio[i];
01650
01651
01653
01655
01656 iocand[i] = iocand[i]+ piovt_z;
01657
01658
01659
01660
01661 double xx = iocand[i].x() - x_c;
01662 double yy = iocand[i].y() - y_c;
01663
01664 dphi = atan2(yy, xx) - phi0 - M_PI_2*(1-charge);
01665 dphi = fmod( dphi + 8.0*M_PI, 2*M_PI );
01666
01667 if( dphi < phi_io[0] ) {
01668 dphi += 2*M_PI;
01669 }
01670 else if( phi_io[1] < dphi ) {
01671 dphi -= 2*M_PI;
01672 }
01674
01675
01676 Hep3Vector zvector( 0., 0., z_c-rho*dphi*tanl-piovt_z.z());
01677
01678 cell_IO[i] = iocand[i];
01679 cell_IO[i] += zvector;
01680
01681
01682
01683
01684 double xcio, ycio, phip;
01686
01687
01688
01689
01690
01691
01692
01693
01694
01695
01696
01697
01698
01699
01700
01701
01702
01703
01704
01705
01706
01707
01708
01709
01710
01711
01712
01713
01714
01715
01716 cell_IO[i] = hel.x(dphi);
01717
01718
01719 }
01720
01721
01722
01723 Hep3Vector cl = cell_IO[1] - cell_IO[0];
01724
01725
01726 double ch_theta;
01727 double ch_dphi;
01728 double ch_ltrk = 0;
01729 double ch_ltrk_rp = 0;
01730 ch_dphi = cl.perp()*0.5/(ALPHA_loc*pt);
01731 ch_dphi = 2.0 * asin( ch_dphi );
01732 ch_ltrk_rp = ch_dphi*ALPHA_loc*pt;
01733 double rpi_path = sqrt(cl.x()*cl.x()+cl.y()*cl.y());
01734 ch_ltrk = sqrt( ch_ltrk_rp*ch_ltrk_rp + cl.z()*cl.z() );
01735 double path = ch_ltrk_rp/ sintheta;
01736 ch_theta = cl.theta();
01737
01738
01739
01740
01741
01742
01743
01744
01745
01746
01747
01748
01749
01750
01751
01752 double phibin, phi_in, phi_out, inlow, inup, outlow, outup, gap, phi1, phi2, phi_mid, phi_midin, phi_midout;
01753 int cid_in, cid_out;
01754 double inlow_z, inup_z, outlow_z, outup_z, gap_z, phi1_z, phi2_z, phi_mid_z, phi_midin_z, phi_midout_z;
01755
01756
01757 std::vector<double> sampl;
01758 sampl.resize(ncell);
01759 for(int k=0; k<ncell; k++) {
01760 sampl[k] = -1.0;
01761 }
01762
01763 cid_in = cid_out = -1;
01764 phi_in = cell_IO[0].phi();
01765 phi_out = cell_IO[1].phi();
01766
01767
01768 phi_in = fmod( phi_in+4*M_PI,2*M_PI );
01769 phi_out = fmod( phi_out+4*M_PI,2*M_PI );
01770 phibin = 2.0*M_PI/ncell;
01771
01772
01773
01774 Hep3Vector cell_mid=0.5*(cell_IO[0]+cell_IO[1]);
01775
01776
01777
01778
01779 double stphi[2], phioff[2];
01780 stphi[0] = shift*phibin*(0.5-cell_IO[0].z()/length);
01781 stphi[1] = shift*phibin*(0.5-cell_IO[1].z()/length);
01782
01783
01784 phioff[0] = phioffset+stphi[0];
01785 phioff[1] = phioffset+stphi[1];
01786
01787 for(int i=0; i<ncell; i++) {
01788
01789 double x_lay_backward_cell = geosvc->Wire(layer, i)->Backward().x()*0.1;
01790 double y_lay_backward_cell = geosvc->Wire(layer, i)->Backward().y()*0.1;
01791 double x_lay_forward_cell = geosvc->Wire(layer, i)->Forward().x()*0.1;
01792 double y_lay_forward_cell = geosvc->Wire(layer, i)->Forward().y()*0.1;
01793
01794
01795 Hep3Vector lay_backward(x_lay_backward_cell, y_lay_backward_cell, 0);
01796 Hep3Vector lay_forward(x_lay_forward_cell, y_lay_forward_cell, 0);
01797 Hep3Vector Cell_z[2];
01798 Cell_z[0] = ((cell_IO[0].z()+length/2)/length)*(lay_backward - lay_forward) + lay_forward;
01799 Cell_z[1] = ((cell_IO[1].z()+length/2)/length)*(lay_backward - lay_forward) + lay_forward;
01800 double z_phi[2];
01801 z_phi[0] = Cell_z[0].phi();
01802 z_phi[1] = Cell_z[1].phi();
01803 z_phi[0] = fmod( z_phi[0]+4*M_PI,2*M_PI );
01804 z_phi[1] = fmod( z_phi[1]+4*M_PI,2*M_PI );
01805
01806
01807
01808
01809
01810
01811
01812
01813
01814
01815
01816 inlow_z = z_phi[0] - phibin*0.5;
01817 inup_z = z_phi[0] + phibin*0.5;
01818 outlow_z = z_phi[1] - phibin*0.5;
01819 outup_z = z_phi[1] + phibin*0.5;
01820 inlow_z = fmod( inlow_z+4*M_PI,2*M_PI );
01821 inup_z = fmod( inup_z+4*M_PI,2*M_PI );
01822 outlow_z = fmod( outlow_z+4*M_PI,2*M_PI );
01823 outup_z = fmod( outup_z+4*M_PI,2*M_PI );
01824
01825
01826
01827 inlow = phioff[0]+phibin*i-phibin*0.5;
01828 inup = phioff[0]+phibin*i+phibin*0.5;
01829 outlow = phioff[1]+phibin*i-phibin*0.5;
01830 outup = phioff[1]+phibin*i+phibin*0.5;
01831 inlow = fmod( inlow+4*M_PI,2*M_PI );
01832 inup = fmod( inup+4*M_PI,2*M_PI );
01833 outlow = fmod( outlow+4*M_PI,2*M_PI );
01834 outup = fmod( outup+4*M_PI,2*M_PI );
01835
01836 #ifdef YDEBUG
01837 if(ntpFlag > 0) cout << "shift " << shift
01838 <<" phi_in " << phi_in << " phi_out " << phi_out
01839 << " inup "<< inup << " inlow " << inlow
01840 << " outup "<< outup << " outlow " << outlow << endl;
01841 #endif
01842
01843
01844
01845
01846
01847
01848
01849
01850
01851
01852 if(phi_in>=inlow_z&&phi_in<inup_z) cid_in = i;
01853 if(phi_out>=outlow_z&&phi_out<outup_z) cid_out = i;
01854 if ( inlow_z>inup_z) {
01855 if((phi_in>=inlow_z&&phi_in<2.0*M_PI)||(phi_in>=0.0&&phi_in<inup_z)) cid_in = i;
01856 }
01857 if ( outlow_z>outup_z) {
01858 if((phi_out>=outlow_z&&phi_out<2.0*M_PI)||(phi_out>=0.0&&phi_out<outup_z)) cid_out = i;
01859 }
01860 }
01861
01862 phi_midin = phi_midout = phi1 = phi2 = -999.0;
01863 gap = -999.0;
01864
01865
01866 if(cid_in == -1 || cid_out == -1) return -1;
01867
01868 if( cid_in == cid_out) {
01869 sampl[cid_in]= ch_ltrk;
01870
01871 return sampl[cellid];
01872 } else if(cid_in < cid_out) {
01873
01874
01875 if( cid_out-cid_in>ncell/2 ) {
01876
01877
01878 double x_lay_backward_cin = geosvc->Wire(layer, cid_in)->Backward().x()*0.1;
01879 double y_lay_backward_cin = geosvc->Wire(layer, cid_in)->Backward().y()*0.1;
01880 double x_lay_forward_cin = geosvc->Wire(layer, cid_in)->Forward().x()*0.1;
01881 double y_lay_forward_cin = geosvc->Wire(layer, cid_in)->Forward().y()*0.1;
01882 Hep3Vector lay_backward_cin(x_lay_backward_cin, y_lay_backward_cin, 0);
01883 Hep3Vector lay_forward_cin(x_lay_forward_cin, y_lay_forward_cin, 0);
01884 Hep3Vector Cell_z[2];
01885 Cell_z[0]=((cell_IO[0].z()+length/2)/length)*(lay_backward_cin-lay_forward_cin)+lay_forward_cin;
01886 double phi_cin_z = Cell_z[0].phi();
01887 phi_cin_z = fmod( phi_cin_z+4*M_PI,2*M_PI );
01888 double x_lay_backward_cout = geosvc->Wire(layer, cid_out)->Backward().x()*0.1;
01889 double y_lay_backward_cout = geosvc->Wire(layer, cid_out)->Backward().y()*0.1;
01890 double x_lay_forward_cout = geosvc->Wire(layer, cid_out)->Forward().x()*0.1;
01891 double y_lay_forward_cout = geosvc->Wire(layer, cid_out)->Forward().y()*0.1;
01892 Hep3Vector lay_backward_cout(x_lay_backward_cout, y_lay_backward_cout, 0);
01893 Hep3Vector lay_forward_cout(x_lay_forward_cout, y_lay_forward_cout, 0);
01894 Cell_z[1]=((cell_IO[1].z()+length/2)/length)*(lay_backward_cout-lay_forward_cout)+lay_forward_cout;
01895 double phi_cout_z = Cell_z[1].phi();
01896 phi_cout_z = fmod( phi_cout_z+4*M_PI,2*M_PI );
01897
01898 phi_midin_z = phi_cin_z-phibin*0.5;
01899 phi_midout_z = phi_cout_z+phibin*0.5;
01900 phi_midin_z = fmod( phi_midin_z+4*M_PI,2*M_PI );
01901 phi_midout_z = fmod( phi_midout_z+4*M_PI,2*M_PI );
01902 phi1_z = phi_midout_z-phi_out;
01903 phi2_z = phi_in-phi_midin_z;
01904 phi1_z = fmod(phi1_z+2.0*M_PI,2.0*M_PI);
01905 phi2_z = fmod(phi2_z+2.0*M_PI,2.0*M_PI);
01906 gap_z = phi1_z+phi2_z+(ncell-1-cid_out+cid_in)*phibin;
01907 gap_z = fmod(gap_z+2.0*M_PI,2.0*M_PI);
01908 sampl[cid_in]=phi2_z/gap_z*ch_ltrk;
01909 sampl[cid_out]=phi1_z/gap_z*ch_ltrk;
01910 for( int jj = cid_out+1; jj<ncell; jj++) {
01911 sampl[jj]=phibin/gap_z*ch_ltrk;
01912 }
01913 for( int jj = 0; jj<cid_in; jj++) {
01914 sampl[jj]=phibin/gap_z*ch_ltrk;
01915 }
01916
01917
01918
01919
01920
01921
01922
01923
01924
01925
01926
01927
01928
01929
01930
01931
01932
01933
01934
01935
01936
01937
01938
01939
01940
01941
01942
01943
01944
01945
01946 } else {
01947
01948 double x_lay_backward_cin = geosvc->Wire(layer, cid_in)->Backward().x()*0.1;
01949 double y_lay_backward_cin = geosvc->Wire(layer, cid_in)->Backward().y()*0.1;
01950 double x_lay_forward_cin = geosvc->Wire(layer, cid_in)->Forward().x()*0.1;
01951 double y_lay_forward_cin = geosvc->Wire(layer, cid_in)->Forward().y()*0.1;
01952 Hep3Vector lay_backward_cin(x_lay_backward_cin, y_lay_backward_cin, 0);
01953 Hep3Vector lay_forward_cin(x_lay_forward_cin, y_lay_forward_cin, 0);
01954 Hep3Vector Cell_z[2];
01955 Cell_z[0]=((cell_IO[0].z()+length/2)/length)*(lay_backward_cin-lay_forward_cin)+lay_forward_cin;
01956 double phi_cin_z = Cell_z[0].phi();
01957 phi_cin_z = fmod( phi_cin_z+4*M_PI,2*M_PI );
01958 double x_lay_backward_cout = geosvc->Wire(layer, cid_out)->Backward().x()*0.1;
01959 double y_lay_backward_cout = geosvc->Wire(layer, cid_out)->Backward().y()*0.1;
01960 double x_lay_forward_cout = geosvc->Wire(layer, cid_out)->Forward().x()*0.1;
01961 double y_lay_forward_cout = geosvc->Wire(layer, cid_out)->Forward().y()*0.1;
01962 Hep3Vector lay_backward_cout(x_lay_backward_cout, y_lay_backward_cout, 0);
01963 Hep3Vector lay_forward_cout(x_lay_forward_cout, y_lay_forward_cout, 0);
01964 Cell_z[1]=((cell_IO[1].z()+length/2)/length)*(lay_backward_cout-lay_forward_cout)+lay_forward_cout;
01965 double phi_cout_z = Cell_z[1].phi();
01966 phi_cout_z = fmod( phi_cout_z+4*M_PI,2*M_PI );
01967
01968 phi_midin_z = phi_cin_z+phibin*0.5;
01969 phi_midout_z = phi_cout_z-phibin*0.5;
01970 phi_midin_z = fmod( phi_midin_z+4*M_PI,2*M_PI );
01971 phi_midout_z = fmod( phi_midout_z+4*M_PI,2*M_PI );
01972 phi1_z = phi_midin_z-phi_in;
01973 phi2_z = phi_out-phi_midout_z;
01974 phi1_z = fmod(phi1_z+2.0*M_PI,2.0*M_PI);
01975 phi2_z = fmod(phi2_z+2.0*M_PI,2.0*M_PI);
01976 gap_z = phi1_z+phi2_z+(cid_out-cid_in-1)*phibin;
01977 gap_z = fmod(gap_z+2.0*M_PI,2.0*M_PI);
01978 sampl[cid_in]=phi1_z/gap_z*ch_ltrk;
01979 sampl[cid_out]=phi2_z/gap_z*ch_ltrk;
01980 for( int jj = cid_in+1; jj<cid_out; jj++) {
01981 sampl[jj]=phibin/gap_z*ch_ltrk;
01982 }
01983
01984
01985
01986
01987
01988
01989
01990
01991
01992
01993
01994
01995
01996
01997
01998
01999 }
02000
02001 } else if(cid_in > cid_out) {
02002
02003
02004 if( cid_in-cid_out>ncell/2 ) {
02005 double x_lay_backward_cin = geosvc->Wire(layer, cid_in)->Backward().x()*0.1;
02006 double y_lay_backward_cin = geosvc->Wire(layer, cid_in)->Backward().y()*0.1;
02007 double x_lay_forward_cin = geosvc->Wire(layer, cid_in)->Forward().x()*0.1;
02008 double y_lay_forward_cin = geosvc->Wire(layer, cid_in)->Forward().y()*0.1;
02009 Hep3Vector lay_backward_cin(x_lay_backward_cin, y_lay_backward_cin, 0);
02010 Hep3Vector lay_forward_cin(x_lay_forward_cin, y_lay_forward_cin, 0);
02011 Hep3Vector Cell_z[2];
02012 Cell_z[0]=((cell_IO[0].z()+length/2)/length)*(lay_backward_cin-lay_forward_cin)+lay_forward_cin;
02013 double phi_cin_z = Cell_z[0].phi();
02014 phi_cin_z = fmod( phi_cin_z+4*M_PI,2*M_PI );
02015 double x_lay_backward_cout = geosvc->Wire(layer, cid_out)->Backward().x()*0.1;
02016 double y_lay_backward_cout = geosvc->Wire(layer, cid_out)->Backward().y()*0.1;
02017 double x_lay_forward_cout = geosvc->Wire(layer, cid_out)->Forward().x()*0.1;
02018 double y_lay_forward_cout = geosvc->Wire(layer, cid_out)->Forward().y()*0.1;
02019 Hep3Vector lay_backward_cout(x_lay_backward_cout, y_lay_backward_cout, 0);
02020 Hep3Vector lay_forward_cout(x_lay_forward_cout, y_lay_forward_cout, 0);
02021 Cell_z[1]=((cell_IO[1].z()+length/2)/length)*(lay_backward_cout-lay_forward_cout)+lay_forward_cout;
02022 double phi_cout_z = Cell_z[1].phi();
02023 phi_cout_z = fmod( phi_cout_z+4*M_PI,2*M_PI );
02024
02025 phi_midin_z = phi_cin_z+phibin*0.5;
02026 phi_midout_z = phi_cout_z-phibin*0.5;
02027 phi_midin_z = fmod( phi_midin_z+4*M_PI,2*M_PI );
02028 phi_midout_z = fmod( phi_midout_z+4*M_PI,2*M_PI );
02029 phi1_z = phi_midin_z-phi_in;
02030 phi2_z = phi_out-phi_midout_z;
02031 phi1_z = fmod(phi1_z+2.0*M_PI,2.0*M_PI);
02032 phi2_z = fmod(phi2_z+2.0*M_PI,2.0*M_PI);
02033 gap_z = phi1_z+phi2_z+(ncell-1-cid_in+cid_out)*phibin;
02034 gap_z = fmod(gap_z+2.0*M_PI,2.0*M_PI);
02035 sampl[cid_out]=phi2_z/gap_z*ch_ltrk;
02036 sampl[cid_in]=phi1_z/gap_z*ch_ltrk;
02037 for( int jj = cid_in+1; jj<ncell; jj++) {
02038 sampl[jj]=phibin/gap_z*ch_ltrk;
02039 }
02040 for( int jj = 0; jj<cid_out; jj++) {
02041 sampl[jj]=phibin/gap_z*ch_ltrk;
02042 }
02043
02044
02045
02046
02047
02048
02049
02050
02051
02052
02053
02054
02055
02056
02057
02058
02059
02060
02061
02062
02063
02064
02065
02066
02067
02068
02069
02070
02071
02072 } else {
02073 double x_lay_backward_cin = geosvc->Wire(layer, cid_in)->Backward().x()*0.1;
02074 double y_lay_backward_cin = geosvc->Wire(layer, cid_in)->Backward().y()*0.1;
02075 double x_lay_forward_cin = geosvc->Wire(layer, cid_in)->Forward().x()*0.1;
02076 double y_lay_forward_cin = geosvc->Wire(layer, cid_in)->Forward().y()*0.1;
02077 Hep3Vector lay_backward_cin(x_lay_backward_cin, y_lay_backward_cin, 0);
02078 Hep3Vector lay_forward_cin(x_lay_forward_cin, y_lay_forward_cin, 0);
02079 Hep3Vector Cell_z[2];
02080 Cell_z[0]=((cell_IO[0].z()+length/2)/length)*(lay_backward_cin-lay_forward_cin)+lay_forward_cin;
02081 double phi_cin_z = Cell_z[0].phi();
02082 phi_cin_z = fmod( phi_cin_z+4*M_PI,2*M_PI );
02083 double x_lay_backward_cout = geosvc->Wire(layer, cid_out)->Backward().x()*0.1;
02084 double y_lay_backward_cout = geosvc->Wire(layer, cid_out)->Backward().y()*0.1;
02085 double x_lay_forward_cout = geosvc->Wire(layer, cid_out)->Forward().x()*0.1;
02086 double y_lay_forward_cout = geosvc->Wire(layer, cid_out)->Forward().y()*0.1;
02087 Hep3Vector lay_backward_cout(x_lay_backward_cout, y_lay_backward_cout, 0);
02088 Hep3Vector lay_forward_cout(x_lay_forward_cout, y_lay_forward_cout, 0);
02089 Cell_z[1]=((cell_IO[1].z()+length/2)/length)*(lay_backward_cout-lay_forward_cout)+lay_forward_cout;
02090 double phi_cout_z = Cell_z[1].phi();
02091 phi_cout_z = fmod( phi_cout_z+4*M_PI,2*M_PI );
02092
02093 phi_midin_z = phi_cin_z-phibin*0.5;
02094 phi_midout_z = phi_cout_z+phibin*0.5;
02095 phi_midin_z = fmod( phi_midin_z+4*M_PI,2*M_PI );
02096 phi_midout_z = fmod( phi_midout_z+4*M_PI,2*M_PI );
02097 phi1_z = phi_midout_z-phi_out;
02098 phi2_z = phi_in-phi_midin_z;
02099 phi1_z = fmod(phi1_z+2.0*M_PI,2.0*M_PI);
02100 phi2_z = fmod(phi2_z+2.0*M_PI,2.0*M_PI);
02101 gap_z = phi1_z+phi2_z+(cid_in-cid_out-1)*phibin;
02102 gap_z = fmod(gap_z+2.0*M_PI,2.0*M_PI);
02103 sampl[cid_in]=phi2_z/gap_z*ch_ltrk;
02104 sampl[cid_out]=phi1_z/gap_z*ch_ltrk;
02105 for( int jj = cid_out+1; jj<cid_in; jj++) {
02106 sampl[jj]=phibin/gap_z*ch_ltrk;
02107 }
02108
02109
02110
02111
02112
02113
02114
02115
02116
02117
02118
02119
02120
02121
02122
02123
02124
02125 }
02126 }
02127
02128 #ifdef YDEBUG
02129 if(sampl[cellid]<0.0) {
02130 if(cid_in!=cid_out) cout<<"?????????"<<endl;
02131 cout<< "layerId " << layer <<" cell id "<< cellid <<" shift " << shift
02132 << " cid_in " << cid_in << " cid_out " << cid_out << endl;
02133
02134 cout <<" phi_in " << phi_in <<" phi_midin " << phi_midin << " phi_out "
02135 << phi_out << " phi_midout " << phi_midout <<endl;
02136 cout<<"total sampl " << ch_ltrk << " gap "<< gap << " phi1 "
02137 << phi1 << " phi2 " << phi2 << " phibin " << phibin << endl;
02138
02139
02140 for(int l=0; l<ncell; l++) {
02141 if(sampl[l]>=0.0)
02142 cout<<"picked cellid " << l << " sampling length "<< sampl[l]<< endl;
02143 }
02144 }
02145 #endif
02146 return sampl[cellid];
02147 }
02148
02149
02150
02151
02152
02153 double DedxCorrecSvc::D2I(const double& cosTheta, const double& D) const
02154 {
02155
02156 double absCosTheta = fabs(cosTheta);
02157 double projection = pow(absCosTheta,m_power) + m_delta;
02158 double chargeDensity = D/projection;
02159 double numerator = 1 + m_alpha*chargeDensity;
02160 double denominator = 1 + m_gamma*chargeDensity;
02161 double I = D;
02162
02163
02164
02165 I = D * m_ratio* numerator/denominator;
02166
02167
02168
02169
02170
02171 return I;
02172 }
02173
02174
02175 double DedxCorrecSvc::I2D(const double& cosTheta, const double& I) const
02176 {
02177
02178 double absCosTheta = fabs(cosTheta);
02179 double projection = pow(absCosTheta,m_power) + m_delta;
02180
02181
02182 double a = m_alpha / projection;
02183 double b = 1 - m_gamma / projection*(I/m_ratio);
02184 double c = -I/m_ratio;
02185
02186 if(b==0 && a==0){
02187 cout<<"both a and b coefficiants for hadron correction are 0"<<endl;
02188 return I;
02189 }
02190
02191 double D = a != 0? (-b + sqrt(b*b - 4.0*a*c))/(2.0*a) : -c/b;
02192 if(D<0){
02193 cout<<"D is less 0! will try another solution"<<endl;
02194 D=a != 0? (-b - sqrt(b*b + 4.0*a*c))/(2.0*a) : -c/b;
02195 if(D<0){
02196 cout<<"D is still less 0! just return uncorrectecd value"<<endl;
02197 return I;
02198 }
02199 }
02200
02201 return D;
02202 }
02203
02204