13 Double_t theta0 = x[1];
15 for ( Int_t i=0; i<
nmeas; i++ )
19 Double_t yy =
ymeas[i];
23 Double_t rad_length = 14.0;
25 Double_t l0 = xx/rad_length;
29 if ( xx>0 && p>0 ) res1 = ( 13.6/p )*sqrt( l0 )*( 1.0+0.038*TMath::Log( l0 ) );
31 res1 = sqrt( res1*res1+theta0*theta0 );
33 Double_t diff = yy-res1;
35 if ( ey==0 ) { cout <<
" Zero denominator in my_mcs_chi2 ! " << endl;
return -1; }
37 Double_t incre = pow( diff/ey, 2.0 );
43 result += 2.0/( 4.6 )*theta0;
45 if ( isnan(
float(result) ) || isinf(
float(result) ) ) {
46 LOG_DEBUG(
"TrackMomentumCalculator")<<
" Is nan in my_mcs_chi2 ! ";
69 basex.SetXYZ( 1.0, 0.0, 0.0 );
basey.SetXYZ( 0.0, 1.0, 0.0 );
basez.SetXYZ( 0.0, 0.0, 1.0 );
83 Float_t Range_grampercm[29] = {9.833E-1, 1.786E0, 3.321E0, 6.598E0, 1.058E1, 3.084E1, 4.250E1, 6.732E1, 1.063E2, 1.725E2, 2.385E2, 4.934E2,
84 6.163E2, 8.552E2, 1.202E3, 1.758E3, 2.297E3,
85 4.359E3, 5.354E3, 7.298E3, 1.013E4, 1.469E4, 1.910E4, 3.558E4, 4.326E4, 5.768E4, 7.734E4, 1.060E5, 1.307E5};
86 for (
int i = 0; i<29; ++i){
87 Range_grampercm[i] /= 1.396;
89 Float_t KE_MeV[29] = {10, 14, 20, 30, 40, 80, 100, 140, 200, 300, 400, 800, 1000, 1400, 2000, 3000, 4000, 8000, 10000, 14000, 20000, 30000,
90 40000, 80000, 100000, 140000, 200000, 300000, 400000};
91 KEvsR =
new TGraph(29, Range_grampercm, KE_MeV);
167 if (trkrange<0 || std::isnan(trkrange)){
168 mf::LogError(
"TrackMomentumCalculator")<<
"Invalid track range "<<trkrange<<
" return -1";
172 double KE, Momentum, Muon_M = 105.7, Proton_M = 938.272, M;
190 else if (abs(pdg) == 2212){
192 if (trkrange>0 && trkrange<=80)
193 KE = 29.9317*TMath::Power(trkrange,0.586304);
194 else if (trkrange>80 && trkrange<=3.022E3)
195 KE = 149.904+ (3.34146*trkrange) + (-0.00318856*trkrange*trkrange)+
196 (4.34587E-6*trkrange*trkrange*trkrange)+
197 (-3.18146
E-9*trkrange*trkrange*trkrange*trkrange)+
198 (1.17854E-12*trkrange*trkrange*trkrange*trkrange*trkrange)+
199 (-1.71763
E-16*trkrange*trkrange*trkrange*trkrange*trkrange*trkrange);
209 Momentum = TMath::Sqrt((KE*KE)+(2*M*KE));
211 Momentum = Momentum/1000;
241 std::vector<Float_t> recoX; std::vector<Float_t> recoY; std::vector<Float_t> recoZ;
243 recoX.clear(); recoY.clear(); recoZ.clear();
247 for ( Int_t i=0; i<n_points; i++ )
251 recoX.push_back( pos.X() ); recoY.push_back( pos.Y() ); recoZ.push_back( pos.Z() );
257 Int_t my_steps = recoX.size();
259 if ( my_steps<2 )
return -1.0;
263 if ( check0!=0 )
return -1.0;
269 if ( check1!=0 )
return -1.0;
271 Int_t seg_steps =
segx.size();
273 if ( seg_steps<2 )
return -1;
275 Int_t seg_steps0 = seg_steps-1;
277 Double_t recoL =
segL.at(seg_steps0);
279 if ( recoL<minLength || recoL>
maxLength )
return -1;
283 if ( check2!=0 )
return -1.0;
285 Double_t logL = 1
e+16;
287 Double_t bf = -666.0;
289 Double_t start1 = 0.0; Double_t end1 = 750.0;
291 Double_t start2 = 0.0; Int_t end2 = 0.0;
293 for ( Int_t k=start1; k<=end1; k++ )
295 Double_t p_test = 0.001+k*0.01;
297 for ( Int_t l=start2; l<=end2; l++ )
299 Double_t res_test = 2.0;
333 if ( LLHDp!=-1 && LLHDm!=-1 )
341 start.SetXYZ( pos.X(), pos.Y(), pos.Z() );
348 start.SetXYZ( pos.X(), pos.Y(), pos.Z() );
358 start.SetXYZ( pos.X(), pos.Y(), pos.Z() );
484 Double_t LLHD = -1.0;
486 std::vector<Float_t> recoX; std::vector<Float_t> recoY; std::vector<Float_t> recoZ;
488 recoX.clear(); recoY.clear(); recoZ.clear();
494 for ( Int_t i=0; i<n_points; i++ )
498 recoX.push_back( pos.X() ); recoY.push_back( pos.Y() ); recoZ.push_back( pos.Z() );
507 for ( Int_t i=0; i<n_points; i++ )
511 recoX.push_back( pos.X() ); recoY.push_back( pos.Y() ); recoZ.push_back( pos.Z() );
519 Int_t my_steps = recoX.size();
521 if ( my_steps<2 )
return -1.0;
525 if ( check0!=0 )
return -1.0;
531 if ( check1!=0 )
return -1.0;
533 Int_t seg_steps =
segx.size();
535 if ( seg_steps<2 )
return -1;
537 Int_t seg_steps0 = seg_steps-1;
539 Double_t recoL =
segL.at(seg_steps0);
541 if ( recoL<15.0 || recoL>
maxLength )
return -1;
545 if ( check2!=0 )
return -1.0;
547 Double_t p_range = recoL*
kcal;
561 if ( ( a1!=a2 ) || ( a1!=a3 ) ) { cout <<
" ( Get thij ) Error ! " << endl;
return -1.0; }
563 Int_t tot = a1-1; Double_t thick1 = thick+0.13;
565 ei.clear(); ej.clear(); th.clear(); ind.clear();
569 for ( Int_t i=0; i<tot; i++ )
571 Double_t dx =
segnx.at( i ); Double_t dy =
segny.at( i ); Double_t dz =
segnz.at( i );
573 TVector3 vec_z( dx, dy, dz );
579 Double_t switcher =
basex.Dot( vec_z );
581 if ( TMath::Abs( switcher )<=0.995 )
583 vec_y = vec_z.Cross(
basex ); vec_y = vec_y.Unit();
585 vec_x = vec_y.Cross( vec_z );
593 vec_y =
basez.Cross( vec_z ); vec_y = vec_y.Unit();
595 vec_x = vec_y.Cross( vec_z );
601 Double_t ex = vec_x.Dot(
basex ); Rx.SetX( ex );
603 ex = vec_x.Dot(
basey ); Rx.SetY( ex );
605 ex = vec_x.Dot(
basez ); Rx.SetZ( ex );
609 Double_t ey = vec_y.Dot(
basex ); Ry.SetX( ey );
611 ey = vec_y.Dot(
basey ); Ry.SetY( ey );
613 ey = vec_y.Dot(
basez ); Ry.SetZ( ey );
617 Double_t ez = vec_z.Dot(
basex ); Rz.SetX( ez );
619 ez = vec_z.Dot(
basey ); Rz.SetY( ez );
621 ez = vec_z.Dot(
basez ); Rz.SetZ( ez );
623 Double_t refL =
segL.at( i );
625 for ( Int_t j=i; j<tot; j++ )
627 Double_t L1 =
segL.at( j );
629 Double_t L2 =
segL.at( j+1 );
631 Double_t dz1 = L1 - refL;
633 Double_t dz2 = L2 - refL;
635 if ( dz1<=thick1 && dz2>thick1 )
637 Double_t here_dx =
segnx.at( j );
639 Double_t here_dy =
segny.at( j );
641 Double_t here_dz =
segnz.at( j );
643 Double_t ac1 = 0.001*180.0/3.14159*
find_angle( here_dz, here_dx );
645 Double_t ac2 = 0.001*180.0/3.14159*
find_angle( here_dz, here_dy );
647 TVector3 here_vec; here_vec.SetXYZ( here_dx, here_dy, here_dz );
649 TVector3 rot_here; rot_here.SetXYZ( Rx.Dot( here_vec ), Ry.Dot( here_vec ), Rz.Dot( here_vec ) );
651 Double_t scx = rot_here.X();
653 Double_t scy = rot_here.Y();
655 Double_t scz = rot_here.Z();
661 Double_t ULim = 10000.0;
663 Double_t LLim = -10000.0;
667 Double_t Li =
segL.at( i );
669 Double_t Lj =
segL.at( j );
671 if ( azy<=ULim && azy>=LLim )
673 ei.push_back( Li*cL );
675 ej.push_back( Lj*cL );
681 azx0.push_back( ac1 );
683 azy0.push_back( ac2 );
687 if ( azx<=ULim && azx>=LLim )
689 ei.push_back( Li*cL );
691 ej.push_back( Lj*cL );
697 azx0.push_back( ac1 );
699 azy0.push_back( ac2 );
719 std::vector<Float_t> recoX; std::vector<Float_t> recoY; std::vector<Float_t> recoZ;
721 recoX.clear(); recoY.clear(); recoZ.clear();
725 for ( Int_t i=0; i<n_points; i++ )
729 recoX.push_back( pos.X() ); recoY.push_back( pos.Y() ); recoZ.push_back( pos.Z() );
735 Int_t my_steps = recoX.size();
737 if ( my_steps<2 )
return -1.0;
741 if ( check0!=0 )
return -1.0;
747 if ( check1!=0 )
return -1.0;
749 Int_t seg_steps =
segx.size();
751 if ( seg_steps<2 )
return -1;
753 Int_t seg_steps0 = seg_steps-1;
755 Double_t recoL =
segL.at(seg_steps0);
757 if ( seg_steps<2 || recoL<minLength || recoL>
maxLength )
return -1;
759 Double_t
mean = 666.0; Double_t rms = 666.0; Double_t rmse = 666.0;
761 nmeas = 0; Double_t max1=-999.0; Double_t min1=+999.0;
763 for ( Int_t j=0; j<
n_steps; j++ )
765 Double_t trial =
steps.at( j );
775 eymeas[
nmeas ] = sqrt( pow( rmse, 2.0 ) + pow( 0.05*rms, 2.0 ) );
789 gr_meas->SetTitle(
"(#Delta#theta)_{rms} versus material thickness; Material thickness in cm; (#Delta#theta)_{rms} in mrad" );
797 gr_meas->SetMaximum( 1.80*max1 );
807 ROOT::Minuit2::Minuit2Minimizer *mP =
new ROOT::Minuit2::Minuit2Minimizer( );
811 mP->SetFunction( FCA );
813 mP->SetLimitedVariable( 0,
"p_{MCS}", 1.0, 0.01, 0.001, 7.5 );
815 mP->SetLimitedVariable( 1,
"#delta#theta", 0.0, 1.0, 0.0, 45.0 );
817 mP->SetMaxFunctionCalls( 1.E9 );
819 mP->SetMaxIterations( 1.E9 );
821 mP->SetTolerance( 0.01 );
823 mP->SetStrategy( 2 );
825 mP->SetErrorDef( 1.0 );
827 bool mstatus = mP->Minimize();
831 const double *pars = mP->X();
833 const double *erpars = mP->Errors();
835 Double_t deltap = ( recoL*
kcal )/2.0;
837 p_mcs = pars[0]+deltap;
841 if ( mstatus ) p =
p_mcs;
845 chi2 = mP->MinValue();
855 Int_t
a1 = xxx.size(); Int_t
a2 = yyy.size(); Int_t
a3 = zzz.size();
857 if ( ( a1!=a2 ) || ( a1!=a3 ) || ( a2!=a3 ) ) { cout <<
" ( Get tracks ) Error ! " << endl;
return -1; }
861 for ( Int_t i=0; i<
a1; i++ )
863 Double_t nowx = xxx.at( i );
865 Double_t nowy = yyy.at( i );
867 Double_t nowz = zzz.at( i );
889 Int_t
a1 = xxx.size(); Int_t
a2 = yyy.size(); Int_t
a3 = zzz.size();
891 if ( ( a1!=a2 ) || ( a1!=a3 ) || ( a2!=a3 ) ) { cout <<
" ( Get reco tacks ) Error ! " << endl;
return -1; }
895 for ( Int_t i=0; i<
a1; i++ )
897 Double_t nowx = xxx.at( i );
899 Double_t nowy = yyy.at( i );
901 Double_t nowz = zzz.at( i );
928 Int_t
a1 = xxx.size(); Int_t
a2 = yyy.size(); Int_t
a3 = zzz.size();
930 if ( ( a1!=a2 ) || ( a1!=a3 ) || ( a2!=a3 ) ) { cout <<
" ( Digitize reco tacks ) Error ! " << endl;
return -1; }
942 Double_t x0 = xxx.at( 0 ); Double_t y0 = yyy.at( 0 ); Double_t z0 = zzz.at( 0 );
944 segx.push_back( x0 );
segy.push_back( y0 );
segz.push_back( z0 );
segL.push_back( 0.0 );
952 Double_t Sz = 0; Double_t Szz = 0;
954 Double_t Szx = 0; Double_t Sx = 0;
956 Double_t Szy = 0; Double_t Sy = 0;
958 Sz += z0; Szz += z0*z0;
960 Szx += z0*x0; Sx += x0;
962 Szy += z0*y0; Sy += y0;
966 for ( Int_t i=1; i<
a4; i++ )
968 Double_t
x1 = xxx.at( i ); Double_t
y1 = yyy.at( i ); Double_t z1 = zzz.at( i );
970 Double_t dr1 = sqrt( pow( x1-x0, 2 )+pow( y1-y0, 2)+pow( z1-z0, 2 ) );
972 Double_t
x2 = xxx.at( i+1 ); Double_t
y2 = yyy.at( i+1 ); Double_t z2 = zzz.at( i+1 );
974 Double_t dr2 = sqrt( pow( x2-x0, 2 )+pow( y2-y0, 2)+pow( z2-z0, 2 ) );
978 Sz += z1; Szz += z1*z1;
980 Szx += z1*
x1; Sx +=
x1;
982 Szy += z1*
y1; Sy +=
y1;
988 if ( dr1<=seg_size && dr2>
seg_size )
992 Double_t dx = x2-
x1; Double_t dy = y2-
y1; Double_t dz = z2-z1;
994 Double_t dr = sqrt( dx*dx+dy*dy+dz*dz );
996 if ( dr==0 ) { cout <<
" ( Zero ) Error ! " << endl;
return -1; }
998 Double_t
beta = 2.0*( (x1-x0)*dx+(y1-y0)*dy+(z1-z0)*dz )/( dr*dr );
1000 Double_t gamma = ( dr1*dr1 - seg_size*
seg_size )/( dr*dr );
1002 Double_t delta = beta*beta - 4.0*gamma;
1004 if ( delta<0.0 ) { cout <<
" ( Discriminant ) Error ! " << endl;
return -1; }
1006 Double_t lysi1 = ( -beta+sqrt( delta ) )/2.0;
1010 Double_t xp = x1+t*dx;
1012 Double_t yp = y1+t*dy;
1014 Double_t zp = z1+t*dz;
1016 segx.push_back( xp );
segy.push_back( yp );
segz.push_back( zp );
1018 segL.push_back( 1.0*
n_seg*1.0*seg_size );
1022 x0 = xp; y0 = yp; z0 = zp;
1024 Sz += z0; Szz += z0*z0;
1026 Szx += z0*x0; Sx += x0;
1028 Szy += z0*y0; Sy += y0;
1032 Double_t ax = ( Szx*ntot-Sz*Sx )/( Szz*ntot-Sz*Sz );
1034 Double_t ay = ( Szy*ntot-Sz*Sy )/( Szz*ntot-Sz*Sz );
1046 Sz += z0; Szz += z0*z0;
1048 Szx += z0*x0; Sx += x0;
1050 Szy += z0*y0; Sy += y0;
1056 else if ( dr1>seg_size )
1060 Double_t dx = x1-x0; Double_t dy = y1-y0; Double_t dz = z1-z0;
1062 Double_t dr = sqrt( dx*dx+dy*dy+dz*dz );
1064 if ( dr==0 ) { cout <<
" ( Zero ) Error ! " << endl; getchar(); }
1066 if ( dr!=0 ) t = seg_size/dr;
1068 Double_t xp = x0+t*dx;
1070 Double_t yp = y0+t*dy;
1072 Double_t zp = z0+t*dz;
1074 segx.push_back( xp );
segy.push_back( yp );
segz.push_back( zp );
1076 segL.push_back( 1.0*
n_seg*1.0*seg_size );
1080 x0 = xp; y0 = yp; z0 = zp;
1084 Sz += z0; Szz += z0*z0;
1086 Szx += z0*x0; Sx += x0;
1088 Szy += z0*y0; Sy += y0;
1092 Double_t ax = ( Szx*ntot-Sz*Sx )/( Szz*ntot-Sz*Sz );
1094 Double_t ay = ( Szy*ntot-Sz*Sy )/( Szz*ntot-Sz*Sz );
1110 Sz += z0; Szz += z0*z0;
1112 Szx += z0*x0; Sx += x0;
1114 Szy += z0*y0; Sy += y0;
1139 Double_t stag = 0.0;
1141 Int_t
a1 = xxx.size(); Int_t
a2 = yyy.size(); Int_t
a3 = zzz.size();
1143 if ( ( a1!=a2 ) || ( a1!=a3 ) || ( a2!=a3 ) ) { cout <<
" ( Digitize reco tacks ) Error ! " << endl;
return -1; }
1159 Double_t x0=0.0; Double_t y0=0.0; Double_t z0=0.0;
1161 Double_t x00 = xxx.at( 0 ); Double_t y00 = yyy.at( 0 ); Double_t z00 = zzz.at( 0 );
1165 std::vector<Float_t> vx; std::vector<Float_t> vy; std::vector<Float_t> vz;
1167 vx.clear(); vy.clear(); vz.clear();
1169 for ( Int_t i=0; i<=
a4; i++ )
1171 x0 = xxx.at( i ); y0 = yyy.at( i ); z0 = zzz.at( i );
1173 Double_t RR0 = sqrt( pow(x00-x0,2.0)+pow(y00-y0,2.0)+pow(z00-z0,2.0) );
1177 segx.push_back( x0 );
segy.push_back( y0 );
segz.push_back( z0 );
1179 segL.push_back( stag );
1185 vx.push_back( x0 ); vy.push_back( y0 ); vz.push_back( z0 );
1197 for ( Int_t i=indC; i<
a4; i++ )
1199 Double_t
x1 = xxx.at( i ); Double_t
y1 = yyy.at( i ); Double_t z1 = zzz.at( i );
1201 Double_t dr1 = sqrt( pow( x1-x0, 2 )+pow( y1-y0, 2)+pow( z1-z0, 2 ) );
1203 Double_t
x2 = xxx.at( i+1 ); Double_t
y2 = yyy.at( i+1 ); Double_t z2 = zzz.at( i+1 );
1205 Double_t dr2 = sqrt( pow( x2-x0, 2 )+pow( y2-y0, 2)+pow( z2-z0, 2 ) );
1209 vx.push_back( x1 ); vy.push_back( y1 ); vz.push_back( z1 );
1215 if ( dr1<=seg_size && dr2>
seg_size )
1223 Double_t dx = x2-
x1; Double_t dy = y2-
y1; Double_t dz = z2-z1;
1225 Double_t dr = sqrt( dx*dx+dy*dy+dz*dz );
1227 if ( dr==0 ) { cout <<
" ( Zero ) Error ! " << endl;
return -1; }
1229 Double_t
beta = 2.0*( (x1-x0)*dx+(y1-y0)*dy+(z1-z0)*dz )/( dr*dr );
1231 Double_t gamma = ( dr1*dr1 - seg_size*
seg_size )/( dr*dr );
1233 Double_t delta = beta*beta - 4.0*gamma;
1235 if ( delta<0.0 ) { cout <<
" ( Discriminant ) Error ! " << endl;
return -1; }
1237 Double_t lysi1 = ( -beta+sqrt( delta ) )/2.0;
1241 Double_t xp = x1+t*dx;
1243 Double_t yp = y1+t*dy;
1245 Double_t zp = z1+t*dz;
1247 segx.push_back( xp );
segy.push_back( yp );
segz.push_back( zp );
1249 segL.push_back( 1.0*
n_seg*1.0*seg_size+stag );
1253 x0 = xp; y0 = yp; z0 = zp;
1255 vx.push_back( x0 ); vy.push_back( y0 ); vz.push_back( z0 );
1259 Double_t na = vx.size();
1261 Double_t sumx = 0.0;
1263 Double_t sumy = 0.0;
1265 Double_t sumz = 0.0;
1267 for ( Int_t ii=0; ii<na; ii++ )
1269 Double_t xxw1 = vx.at( ii );
1271 Double_t yyw1 = vy.at( ii );
1273 Double_t zzw1 = vz.at( ii );
1275 sumx += xxw1; sumy += yyw1; sumz += zzw1;
1279 sumx = sumx/na; sumy = sumy/na; sumz = sumz/na;
1281 std::vector<Double_t> mx;
1283 std::vector<Double_t> my;
1285 std::vector<Double_t> mz;
1289 for ( Int_t ii=0; ii<na; ii++ )
1291 Double_t xxw1 = vx.at( ii ); Double_t yyw1 = vy.at( ii ); Double_t zzw1 = vz.at( ii );
1293 mx.push_back( xxw1-sumx ); my.push_back( yyw1-sumy ); mz.push_back( zzw1-sumz );
1295 Double_t xxw0 = mx.at( ii ); Double_t yyw0 = my.at( ii ); Double_t zzw0 = mz.at( ii );
1297 m( 0, 0 ) += xxw0*xxw0/na; m( 0, 1 ) += xxw0*yyw0/na; m( 0, 2 ) += xxw0*zzw0/na;
1299 m( 1, 0 ) += yyw0*xxw0/na; m( 1, 1 ) += yyw0*yyw0/na; m( 1, 2 ) += yyw0*zzw0/na;
1301 m( 2, 0 ) += zzw0*xxw0/na; m( 2, 1 ) += zzw0*yyw0/na; m( 2, 2 ) += zzw0*zzw0/na;
1305 TMatrixDSymEigen me(m);
1307 TVectorD eigenval = me.GetEigenValues();
1309 TMatrixD eigenvec = me.GetEigenVectors();
1311 Double_t max1 = -666.0;
1315 for ( Int_t ii=0; ii<3; ii++ )
1317 Double_t p1 = eigenval( ii );
1319 if ( p1>max1 ) { max1=p1; ind1=ii; }
1325 Double_t ax = eigenvec( 0, ind1 );
1327 Double_t ay = eigenvec( 1, ind1 );
1329 Double_t az = eigenvec( 2, ind1 );
1335 else ax = -1.0*TMath::Abs( ax );
1339 else ay = -1.0*TMath::Abs( ay );
1343 else az = -1.0*TMath::Abs( az );
1357 vx.clear(); vy.clear(); vz.clear();
1359 vx.push_back( x0 ); vy.push_back( y0 ); vz.push_back( z0 );
1365 else if ( dr1>seg_size )
1373 Double_t dx = x1-x0; Double_t dy = y1-y0; Double_t dz = z1-z0;
1375 Double_t dr = sqrt( dx*dx+dy*dy+dz*dz );
1377 if ( dr==0 ) { cout <<
" ( Zero ) Error ! " << endl;
return -1; }
1379 if ( dr!=0 ) t = seg_size/dr;
1381 Double_t xp = x0+t*dx;
1383 Double_t yp = y0+t*dy;
1385 Double_t zp = z0+t*dz;
1387 segx.push_back( xp );
segy.push_back( yp );
segz.push_back( zp );
1389 segL.push_back( 1.0*
n_seg*1.0*seg_size+stag );
1393 x0 = xp; y0 = yp; z0 = zp;
1399 vx.push_back( x0 ); vy.push_back( y0 ); vz.push_back( z0 );
1403 Double_t na = vx.size();
1405 Double_t sumx = 0.0;
1407 Double_t sumy = 0.0;
1409 Double_t sumz = 0.0;
1411 for ( Int_t ii=0; ii<na; ii++ )
1413 Double_t xxw1 = vx.at( ii );
1415 Double_t yyw1 = vy.at( ii );
1417 Double_t zzw1 = vz.at( ii );
1419 sumx += xxw1; sumy += yyw1; sumz += zzw1;
1423 sumx = sumx/na; sumy = sumy/na; sumz = sumz/na;
1425 std::vector<Double_t> mx;
1427 std::vector<Double_t> my;
1429 std::vector<Double_t> mz;
1433 for ( Int_t ii=0; ii<na; ii++ )
1435 Double_t xxw1 = vx.at( ii ); Double_t yyw1 = vy.at( ii ); Double_t zzw1 = vz.at( ii );
1437 mx.push_back( xxw1-sumx ); my.push_back( yyw1-sumy ); mz.push_back( zzw1-sumz );
1439 Double_t xxw0 = mx.at( ii ); Double_t yyw0 = my.at( ii ); Double_t zzw0 = mz.at( ii );
1441 m( 0, 0 ) += xxw0*xxw0/na; m( 0, 1 ) += xxw0*yyw0/na; m( 0, 2 ) += xxw0*zzw0/na;
1443 m( 1, 0 ) += yyw0*xxw0/na; m( 1, 1 ) += yyw0*yyw0/na; m( 1, 2 ) += yyw0*zzw0/na;
1445 m( 2, 0 ) += zzw0*xxw0/na; m( 2, 1 ) += zzw0*yyw0/na; m( 2, 2 ) += zzw0*zzw0/na;
1449 TMatrixDSymEigen me(m);
1451 TVectorD eigenval = me.GetEigenValues();
1453 TMatrixD eigenvec = me.GetEigenVectors();
1455 Double_t max1 = -666.0;
1459 for ( Int_t ii=0; ii<3; ii++ )
1461 Double_t p1 = eigenval( ii );
1463 if ( p1>max1 ) { max1=p1; ind1=ii; }
1469 Double_t ax = eigenvec( 0, ind1 );
1471 Double_t ay = eigenvec( 1, ind1 );
1473 Double_t az = eigenvec( 2, ind1 );
1480 else ax = -1.0*TMath::Abs( ax );
1484 else ay = -1.0*TMath::Abs( ay );
1488 else az = -1.0*TMath::Abs( az );
1502 vx.clear(); vy.clear(); vz.clear();
1504 vx.push_back( x0 ); vy.push_back( y0 ); vz.push_back( z0 );
1529 mean = 0.0; rms = 0.0; rmse = 0.0;
1533 if ( ( a1!=a2 ) || ( a1!=a3 ) ) { cout <<
" ( Get RMS ) Error ! " << endl;
return; }
1537 Double_t thick1 = thick+0.13;
1539 vector<Float_t> buf0; buf0.clear();
1541 for ( Int_t i=0; i<tot; i++ )
1543 Double_t dx =
segnx.at( i ); Double_t dy =
segny.at( i ); Double_t dz =
segnz.at( i );
1545 TVector3 vec_z( dx, dy, dz );
1551 Double_t switcher =
basex.Dot( vec_z );
1553 if ( switcher<=0.995 )
1555 vec_y = vec_z.Cross(
basex ); vec_y = vec_y.Unit();
1557 vec_x = vec_y.Cross( vec_z );
1565 vec_y =
basez.Cross( vec_z ); vec_y = vec_y.Unit();
1567 vec_x = vec_y.Cross( vec_z );
1573 Double_t ex = vec_x.Dot(
basex ); Rx.SetX( ex );
1575 ex = vec_x.Dot(
basey ); Rx.SetY( ex );
1577 ex = vec_x.Dot(
basez ); Rx.SetZ( ex );
1581 Double_t ey = vec_y.Dot(
basex ); Ry.SetX( ey );
1583 ey = vec_y.Dot(
basey ); Ry.SetY( ey );
1585 ey = vec_y.Dot(
basez ); Ry.SetZ( ey );
1589 Double_t ez = vec_z.Dot(
basex ); Rz.SetX( ez );
1591 ez = vec_z.Dot(
basey ); Rz.SetY( ez );
1593 ez = vec_z.Dot(
basez ); Rz.SetZ( ez );
1595 Double_t refL =
segL.at( i );
1597 for ( Int_t j=i; j<tot; j++ )
1599 Double_t L1 =
segL.at( j );
1601 Double_t L2 =
segL.at( j+1 );
1603 Double_t dz1 = L1 - refL;
1605 Double_t dz2 = L2 - refL;
1607 if ( dz1<=thick1 && dz2>thick1 )
1609 Double_t here_dx =
segnx.at( j );
1611 Double_t here_dy =
segny.at( j );
1613 Double_t here_dz =
segnz.at( j );
1615 TVector3 here_vec; here_vec.SetXYZ( here_dx, here_dy, here_dz );
1617 TVector3 rot_here; rot_here.SetXYZ( Rx.Dot( here_vec ), Ry.Dot( here_vec ), Rz.Dot( here_vec ) );
1619 Double_t scx = rot_here.X();
1621 Double_t scy = rot_here.Y();
1623 Double_t scz = rot_here.Z();
1625 Double_t azy =
find_angle( scz, scy ); azy*=1.0;
1629 Double_t ULim = 10000.0; Double_t LLim = -10000.0;
1633 if ( azx<=ULim && azx>=LLim ) { buf0.push_back( azx ); }
1646 Int_t
nmeas = buf0.size(); Double_t nnn = 0.0;
1648 for ( Int_t i=0; i<
nmeas; i++ ) { mean += buf0.at( i ); nnn++; } mean = mean/nnn;
1650 for ( Int_t i=0; i<
nmeas; i++ ) rms += ( ( buf0.at( i ) )*( buf0.at( i ) ) );
1652 rms = rms/( nnn ); rms = sqrt( rms ); rmse = rms/sqrt( 2.0*tot );
1654 Double_t rms1 = rms;
1658 Double_t ntot1 = 0.0;
1660 Double_t lev1 = 2.50;
1662 for ( Int_t i=0; i<
nmeas; i++ )
1664 Double_t amp = buf0.at( i );
1666 if ( amp<( mean+lev1*rms1 ) && amp>( mean-lev1*rms1 ) )
1676 rms = rms/( ntot1 ); rms = sqrt( rms ); rmse = rms/sqrt( 2.0*ntot1 );
1684 Double_t thetayz = -999.0;
1686 if ( vz>0 && vy>0 ) { Double_t ratio=TMath::Abs( vy/vz ); thetayz=TMath::ATan( ratio ); }
1688 else if ( vz<0 && vy>0 ) { Double_t ratio=TMath::Abs( vy/vz ); thetayz=TMath::ATan( ratio ); thetayz=3.14159-thetayz; }
1690 else if ( vz<0 && vy<0 ) { Double_t ratio=TMath::Abs( vy/vz ); thetayz=TMath::ATan( ratio ); thetayz=thetayz+3.14159; }
1692 else if ( vz>0 && vy<0 ) { Double_t ratio=TMath::Abs( vy/vz ); thetayz=TMath::ATan( ratio ); thetayz=2.0*3.14159-thetayz; }
1694 else if ( vz==0 && vy>0 ) { thetayz=3.14159/2.0; }
1696 else if ( vz==0 && vy<0 ) { thetayz=3.0*3.14159/2.0; }
1698 if ( thetayz>3.14159 ) { thetayz=thetayz-2.0*3.14159; }
1700 Double_t result = 1000.0*thetayz;
1710 if ( s!=0 ) arg = ( xx - Q )/s;
1712 else cout <<
" Error : The code tries to divide by zero ! " << endl;
1714 Double_t result = 0.0;
1716 if ( s!=0 ) result = -0.5*TMath::Log( 2.0*TMath::Pi() ) - TMath::Log( s ) - 0.5*arg*arg;
1718 if ( isnan(
float( result ) ) || isinf(
float( result ) ) ) {
1719 cout <<
" Is nan ! my_g ! " << - TMath::Log( s ) <<
", " << s << endl;
1731 Double_t theta0x =
x1;
1733 Double_t result = 0.0;
1735 Double_t nnn1 =
dEi.size();
1737 Double_t red_length = ( 10.0 )/14.0;
1741 for ( Int_t i=0; i<nnn1; i++ )
1743 Double_t Ei = p-
dEi.at( i );
1745 Double_t Ej = p-
dEj.at( i );
1747 if ( Ei>0 && Ej<0 ) addth=3.14*1000.0;
1749 Ei = TMath::Abs( Ei );
1751 Ej = TMath::Abs( Ej );
1753 Double_t tH0 = ( 13.6/sqrt( Ei*Ej ) )*( 1.0+0.038*TMath::Log( red_length ) )*sqrt( red_length );
1755 Double_t rms = -1.0;
1757 if (
ind.at( i )==1 )
1759 rms = sqrt( tH0*tH0+pow( theta0x, 2.0 ) );
1761 Double_t DT =
dthij.at( i )+addth;
1763 Double_t prob =
my_g( DT, 0.0, rms );
1765 result = result - 2.0*prob;
1771 if ( isnan(
float( result ) ) || isinf(
float( result ) ) ) { cout <<
" Is nan ! my_mcs_llhd ( 1 ) ! " << endl; getchar(); }
std::vector< Float_t > dEi
TVector3 LocationAtPoint(unsigned int p) const
Covariance matrices are either set or not.
Double_t find_angle(Double_t vz, Double_t vy)
std::vector< Float_t > azx0
Int_t GetSegTracks2(const std::vector< Float_t > &xxx, const std::vector< Float_t > &yyy, const std::vector< Float_t > &zzz)
Float_t y1[n_points_granero]
Double_t GetMomentumMultiScatterChi2(const art::Ptr< recob::Track > &trk)
Float_t x1[n_points_granero]
std::vector< Float_t > dEj
Int_t GetTracks(const std::vector< Float_t > &xxx, const std::vector< Float_t > &yyy, const std::vector< Float_t > &zzz)
std::vector< Float_t > segnz
std::vector< Float_t > segy
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
std::vector< Float_t > segx
TrackMomentumCalculator()
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
double my_mcs_chi2(const double *x)
std::vector< Float_t > segz
std::vector< Float_t > segL
std::vector< Float_t > segny
Float_t y2[n_points_geant4]
std::vector< Float_t > ind
Int_t GetSegTracks(const std::vector< Float_t > &xxx, const std::vector< Float_t > &yyy, const std::vector< Float_t > &zzz)
Double_t GetMomentumMultiScatterLLHD(const art::Ptr< recob::Track > &trk)
void GetDeltaThetaRMS(Double_t &mean, Double_t &rms, Double_t &rmse, Double_t thick)
virtual ~TrackMomentumCalculator()
Double_t my_mcs_llhd(Double_t x0, Double_t x1)
std::vector< Float_t > steps
Double_t my_g(Double_t xx, Double_t Q, Double_t s)
std::vector< Float_t > azy0
double GetTrackMomentum(double trkrange, int pdg)
Int_t GetDeltaThetaij(std::vector< Float_t > &ei, std::vector< Float_t > &ej, std::vector< Float_t > &th, Double_t thick, std::vector< Float_t > &ind)
double mean(const std::vector< short > &wf, size_t start, size_t nsample)
TVector3 GetMultiScatterStartingPoint(const art::Ptr< recob::Track > &trk)
std::vector< Float_t > dthij
Double_t GetMuMultiScatterLLHD3(const art::Ptr< recob::Track > &trk, bool dir)
std::vector< Float_t > segnx
Float_t x2[n_points_geant4]
Int_t GetRecoTracks(const std::vector< Float_t > &xxx, const std::vector< Float_t > &yyy, const std::vector< Float_t > &zzz)
TPolyLine3D * gr_reco_xyz