13 #include <TPolyLine.h>
15 #define MAX_STEPS 1000
18 #include <JANA/JApplication.h>
44 if (x==xx[0])
return 0;
45 else if (x==xx[n-1])
return n-2;
49 int ascnd=(xx[n-1]>=xx[0]);
52 if ( (x>=xx[jm])==ascnd)
63 double delta,
double t){
80 double sqrt_t=
sqrt(my_t);
81 double t3=my_t*my_t*my_t;
82 double delta_mag=fabs(delta);
83 f_delta=(a1+a2*delta_mag)*sqrt_t+(b1+b2*delta_mag)*my_t
84 +(c1+c2*delta_mag+c3*delta*delta)*t3;
85 f_0=a1*sqrt_t+b1*my_t+c1*t3;
89 double sqrt_t=
sqrt(my_t);
90 double delta_mag=fabs(delta);
100 double delta_sq=delta*delta;
101 f_delta= (a1+a2*delta_mag+a3*delta_sq)*sqrt_t
102 +(b1+b2*delta_mag+b3*delta_sq)*my_t;
103 f_0=a1*sqrt_t+b1*my_t;
115 unsigned int index=0;
118 double frac=(t-cdc_drift_table[
index])/dt;
119 double d_0=0.01*(double(index)+frac);
126 d=f_delta*(d_0/f_0*P+1.-P);
135 if (t>fdc_drift_table[fdc_drift_table.size()-1])
return 0.5;
137 unsigned int index=0;
138 index=
locate(fdc_drift_table,t);
139 double dt=fdc_drift_table[index+1]-fdc_drift_table[
index];
140 double frac=(t-fdc_drift_table[
index])/dt;
141 d=0.01*(double(index)+frac);
157 pthread_mutex_init(&mutex, NULL);
175 one_over_zrange=1./150.;
177 printf(
"Initializing..........\n");
180 gPARMS->SetDefaultParameter(
"DCALIGN:RUN_BENCHMARK",RUN_BENCHMARK);
182 gPARMS->SetDefaultParameter(
"DCALIGN:USE_BCAL", USE_BCAL);
184 gPARMS->SetDefaultParameter(
"DCALIGN:USE_FCAL", USE_FCAL);
186 gPARMS->SetDefaultParameter(
"DCALIGN:COSMICS", COSMICS);
187 USE_DRIFT_TIMES=
false;
188 gPARMS->SetDefaultParameter(
"DCALIGN:USE_DRIFT_TIMES",USE_DRIFT_TIMES);
190 gPARMS->SetDefaultParameter(
"DCALIGN:READ_CDC_FILE",READ_CDC_FILE);
191 READ_ANODE_FILE=
false;
192 gPARMS->SetDefaultParameter(
"DCALIGN:READ_ANODE_FILE",READ_ANODE_FILE);
193 READ_CATHODE_FILE=
false;
194 gPARMS->SetDefaultParameter(
"DCALIGN:READ_CATHODE_FILE",READ_CATHODE_FILE);
195 ALIGN_WIRE_PLANES=
true;
196 gPARMS->SetDefaultParameter(
"DCALIGN:ALIGN_WIRE_PLANES",ALIGN_WIRE_PLANES);
198 gPARMS->SetDefaultParameter(
"DCALIGN:FILL_TREE",FILL_TREE);
200 gPARMS->SetDefaultParameter(
"DCALIGN:MIN_PSEUDOS",MIN_PSEUDOS);
201 MIN_INTERSECTIONS=10;
202 gPARMS->SetDefaultParameter(
"DCALIGN:MIN_INTERSECTIONS",MIN_INTERSECTIONS);
204 fdc_alignments.resize(24);
205 for (
unsigned int i=0;i<24;i++){
207 if (RUN_BENCHMARK==
false){
208 fdc_alignments[i].E=
DMatrix2x2(0.000001,0.,0.,0.0001);
214 fdc_cathode_alignments.resize(24);
215 for (
unsigned int i=0;i<24;i++){
217 double var_phi=0.000001;
218 if (RUN_BENCHMARK==
false){
219 fdc_cathode_alignments[i].E=
DMatrix4x4(var_phi,0.,0.,0., 0.,var,0.,0.,
220 0.,0.,var_phi,0., 0.,0.,0.,var);
228 if (READ_ANODE_FILE){
229 ifstream fdcfile(
"fdc_alignment.dat");
234 for (
unsigned int i=0;i<24;i++){
241 fdc_alignments[i].A(kU)=du;
242 fdc_alignments[i].A(kPhiU)=dphi;
247 if (READ_CATHODE_FILE){
248 ifstream fdcfile(
"fdc_cathode_alignment.dat");
253 for (
unsigned int i=0;i<24;i++){
254 double du,dphiu,dv,dphiv;
261 fdc_cathode_alignments[i].A(kU)=du;
262 fdc_cathode_alignments[i].A(kPhiU)=dphiu;
263 fdc_cathode_alignments[i].A(kV)=dv;
264 fdc_cathode_alignments[i].A(kPhiV)=dphiv;
270 fdc_drift_parms(0)=0.;
271 fdc_drift_parms(1)=0.;
272 fdc_drift_parms(2)=0.03;
274 unsigned int numstraws[28]={42,42,54,54,66,66,80,80,93,93,106,106,123,123,
275 135,135,146,146,158,158,170,170,182,182,197,197,
277 for (
unsigned int i=0;i<28;i++){
278 vector<cdc_align_t>tempvec;
279 for (
unsigned int j=0;j<numstraws[i];j++){
283 if (RUN_BENCHMARK==
false){
284 temp.
E=
DMatrix4x4(var,0.,0.,0., 0.,var,0.,0., 0.,0.,var,0., 0.,0.,0.,var);
289 tempvec.push_back(temp);
291 cdc_alignments.push_back(tempvec);
295 ifstream cdcfile(
"cdc_alignment.dat");
296 for (
unsigned int ring=0;ring<cdc_alignments.size();ring++){
297 for (
unsigned int straw=0;straw<cdc_alignments[ring].size();
299 double dxu,dyu,dxd,dyd;
306 cdc_alignments[ring][straw].A(k_dXu)=dxu;
307 cdc_alignments[ring][straw].A(k_dYu)=dyu;
308 cdc_alignments[ring][straw].A(k_dXd)=dxd;
309 cdc_alignments[ring][straw].A(k_dYd)=dyd;
312 cdc_alignments[ring][straw].E=
DMatrix4x4(var,0.,0.,0., 0.,var,0.,0., 0.,0.,var,0., 0.,0.,0.,var);
322 fdctree =
new TTree(
"fdc",
"FDC alignments");
323 fdcbranch = fdctree->Branch(
"T",
"FDC_branch",&fdc_ptr);
326 fdcCtree =
new TTree(
"fdc_c",
"FDC alignments");
327 fdcCbranch = fdcCtree->Branch(
"T",
"FDC_c_branch",&fdc_c_ptr);
330 cdctree =
new TTree(
"cdc",
"CDC alignments");
331 cdcbranch = cdctree->Branch(
"T",
"CDC_branch",&cdc_ptr);
347 double endplate_dz,endplate_rmin,endplate_rmax;
348 dgeom->
GetCDCEndplate(endplate_z,endplate_dz,endplate_rmin,endplate_rmax);
349 endplate_z+=0.5*endplate_dz;
352 JCalibration *jcalib = dapp->GetJCalibration((loop->GetJEvent()).GetRunNumber());
353 vector< map<string, double> > tvals;
355 if (jcalib->Get(
"CDC/cdc_drift_table::NoBField", tvals)==
false){
356 for(
unsigned int i=0; i<tvals.size(); i++){
357 map<string, double> &row = tvals[i];
362 jerr <<
" CDC time-to-distance table not available... bailing..." << endl;
366 unsigned int numstraws[28]={42,42,54,54,66,66,80,80,93,93,106,106,123,123,
367 135,135,146,146,158,158,170,170,182,182,197,197,
370 map<string, double> cdc_res_parms;
371 jcalib->Get(
"CDC/cdc_resolution_parms", cdc_res_parms);
372 CDC_RES_PAR1 = cdc_res_parms[
"res_par1"];
373 CDC_RES_PAR2 = cdc_res_parms[
"res_par2"];
375 fdc_drift_table.clear();
376 if (jcalib->Get(
"FDC/fdc_drift_table", tvals)==
false){
377 for(
unsigned int i=0; i<tvals.size(); i++){
378 map<string, double> &row = tvals[i];
379 fdc_drift_table.push_back(1000.*row[
"t"]);
383 jerr <<
" FDC time-to-distance table not available... bailing..." << endl;
388 vector<map<string,double> >vals;
389 vector<cdc_offset_t>tempvec;
391 if (jcalib->Get(
"CDC/wire_alignment",vals)==
false){
392 unsigned int straw_count=0,ring_count=0;
393 for(
unsigned int i=0; i<vals.size(); i++){
394 map<string,double> &row = vals[i];
397 if (straw_count==numstraws[ring_count]){
401 cdc_offsets.push_back(tempvec);
408 temp.
dx_u=row[
"dxu"];
411 temp.
dy_u=row[
"dyu"];
414 temp.
dx_d=row[
"dxd"];
417 temp.
dy_d=row[
"dyd"];
420 tempvec.push_back(temp);
424 cdc_offsets.push_back(tempvec);
427 jerr<<
"CDC wire alignment table not available... bailing... " <<endl;
433 sag_phi_offset.clear();
434 unsigned int straw_count=0,ring_count=0;
435 if (jcalib->Get(
"CDC/sag_parameters", tvals)==
false){
436 vector<double>
temp,temp2;
437 for(
unsigned int i=0; i<tvals.size(); i++){
438 map<string, double> &row = tvals[i];
440 temp.push_back(row[
"offset"]);
441 temp2.push_back(row[
"phi"]);
444 if (straw_count==numstraws[ring_count]){
445 max_sag.push_back(temp);
446 sag_phi_offset.push_back(temp2);
455 if (jcalib->Get(
"CDC/drift_parameters::NoBField", tvals)==
false){
456 map<string, double> &row = tvals[0];
479 japp->RootWriteLock();
481 for (
int i=0;i<28;i++){
483 sprintf(title,
"cdc_residual_ring%d",i+1);
484 Hcdc_ring_res[i]=(TH2F*)gROOT->FindObject(title);
485 if (!Hcdc_ring_res[i]){
486 Hcdc_ring_res[i]=
new TH2F(title,title,numstraws[i],0.5,numstraws[i]+0.5,
490 for (
int i=0;i<28;i++){
492 sprintf(title,
"cdc_drift_time_ring%d",i+1);
493 Hcdc_ring_time[i]=(TH2F*)gROOT->FindObject(title);
494 if (!Hcdc_ring_time[i]){
495 Hcdc_ring_time[i]=
new TH2F(title,title,numstraws[i],0.5,numstraws[i]+0.5,
500 Hprob = (TH1F*)gROOT->FindObject(
"Hprob");
502 Hprob=
new TH1F(
"Hprob",
"Confidence level for final fit",100,0.0,1.);
504 Hpseudo_prob = (TH1F*)gROOT->FindObject(
"Hpseudo_prob");
506 Hpseudo_prob=
new TH1F(
"Hpseudo_prob",
"Confidence level for final fit",100,0.0,1.);
509 Hcdc_prob = (TH1F*)gROOT->FindObject(
"Hcdc_prob");
511 Hcdc_prob=
new TH1F(
"Hcdc_prob",
"Confidence level for time-based fit",100,0.0,1.);
513 Hcdc_prelimprob = (TH1F*)gROOT->FindObject(
"Hcdc_prelimprob");
514 if (!Hcdc_prelimprob){
515 Hcdc_prelimprob=
new TH1F(
"Hcdc_prelimprob",
"Confidence level for prelimary fit",100,0.0,1.);
517 Hintersection_match = (TH1F*)gROOT->FindObject(
"Hintersection_match");
518 if (!Hintersection_match){
519 Hintersection_match=
new TH1F(
"Hintersection_match",
"Intersection matching distance",100,0.0,25.);
521 Hintersection_link_match = (TH1F*)gROOT->FindObject(
"Hintersection_link_match");
522 if (!Hintersection_link_match){
523 Hintersection_link_match=
new TH1F(
"Hintersection_link_match",
"Segment matching distance",100,0.0,25.);
526 Hcdcmatch = (TH1F*)gROOT->FindObject(
"Hcdcmatch");
528 Hcdcmatch=
new TH1F(
"Hcdcmatch",
"CDC hit matching distance",1000,0.0,50.);
530 Hcdcmatch_stereo = (TH1F*)gROOT->FindObject(
"Hcdcmatch_stereo");
531 if (!Hcdcmatch_stereo){
532 Hcdcmatch_stereo=
new TH1F(
"Hcdcmatch_stereo",
"CDC stereo hit matching distance",1000,0.0,50.);
535 Hmatch = (TH1F*)gROOT->FindObject(
"Hmatch");
537 Hmatch=
new TH1F(
"Hmatch",
"Segment matching distance",100,0.0,25.);
539 Hlink_match = (TH1F*)gROOT->FindObject(
"Hlink_match");
541 Hlink_match=
new TH1F(
"link_match",
"Segment matching distance",100,0.0,25.);
545 Hbeta = (TH1F*)gROOT->FindObject(
"Hbeta");
547 Hbeta=
new TH1F(
"Hbeta",
"Estimate for #beta",100,0.0,1.5);
548 Hbeta->SetXTitle(
"#beta");
551 Hztarg = (TH1F*)gROOT->FindObject(
"Hztarg");
553 Hztarg=
new TH1F(
"Hztarg",
"Estimate for target z",1200,-300.0,300.0);
555 Hures_vs_layer=(TH2F*)gROOT->FindObject(
"Hures_vs_layer");
556 if (!Hures_vs_layer){
557 Hures_vs_layer=
new TH2F(
"Hures_vs_layer",
"Cathode u-view residuals",
558 24,0.5,24.5,200,-0.5,0.5);
560 Hres_vs_layer=(TH2F*)gROOT->FindObject(
"Hres_vs_layer");
562 Hres_vs_layer=
new TH2F(
"Hres_vs_layer",
"wire-based residuals",
563 24,0.5,24.5,200,-0.5,0.5);
565 Hvres_vs_layer=(TH2F*)gROOT->FindObject(
"Hvres_vs_layer");
566 if (!Hvres_vs_layer){
567 Hvres_vs_layer=
new TH2F(
"Hvres_vs_layer",
"Cathode v-view residuals",
568 24,0.5,24.5,200,-0.5,0.5);
570 Hcdc_time_vs_d=(TH2F*)gROOT->FindObject(
"Hcdc_time_vs_d");
571 if (!Hcdc_time_vs_d){
572 Hcdc_time_vs_d=
new TH2F(
"Hcdc_time_vs_d",
573 "cdc drift time vs doca",120,0,1.2,600,-20,1180);
575 Hcdcdrift_time=(TH2F*)gROOT->FindObject(
"Hcdcdrift_time");
576 if (!Hcdcdrift_time){
577 Hcdcdrift_time=
new TH2F(
"Hcdcdrift_time",
578 "cdc doca vs drift time",1201,-21,1181,100,0,1);
580 Hcdcres_vs_drift_time=(TH2F*)gROOT->FindObject(
"Hcdcres_vs_drift_time");
581 if (!Hcdcres_vs_drift_time){
582 Hcdcres_vs_drift_time=
new TH2F(
"Hcdcres_vs_drift_time",
"cdc Residual vs drift time",600,-20,1180,500,-1.,1.);
584 Hcdcres_vs_d=(TH2F*)gROOT->FindObject(
"Hcdcres_vs_d");
586 Hcdcres_vs_d=
new TH2F(
"Hcdcres_vs_d",
"cdc Residual vs distance to wire",600,0,1.2,500,-1.,1.);
589 Hdrift_time=(TH2F*)gROOT->FindObject(
"Hdrift_time");
591 Hdrift_time=
new TH2F(
"Hdrift_time",
592 "doca vs drift time",201,-21,381,100,0,1);
594 Hres_vs_drift_time=(TH2F*)gROOT->FindObject(
"Hres_vs_drift_time");
595 if (!Hres_vs_drift_time){
596 Hres_vs_drift_time=
new TH2F(
"Hres_vs_drift_time",
"Residual vs drift time",320,-20,300,1000,-1,1);
598 Hdv_vs_dE=(TH2F*)gROOT->FindObject(
"Hdv_vs_dE");
600 Hdv_vs_dE=
new TH2F(
"Hdv_vs_dE",
"dv vs energy dep",100,0,20
e-6,200,-1,1);
603 Hbcalmatch=(TH2F*)gROOT->FindObject(
"Hbcalmatch");
605 Hbcalmatch=
new TH2F(
"Hbcalmatch",
"BCAL #deltar vs #deltaz",100,-50.,50.,
608 Hbcalmatchxy=(TH2F*)gROOT->FindObject(
"Hbcalmatchxy");
610 Hbcalmatchxy=
new TH2F(
"Hbcalmatchxy",
"BCAL #deltay vs #deltax",400,-50.,50.,
613 Hfcalmatch=(TH1F*)gROOT->FindObject(
"Hfcalmatch");
615 Hfcalmatch=
new TH1F(
"Hfcalmatch",
"FCAL #deltar",400,0.,50.);
641 vector<const DTrackFinder *> finders;
644 if(finders.size()<1){
645 _DBG_<<
"Unable to get a DTrackFinder object!"<<endl;
646 return RESOURCE_UNAVAILABLE;
653 printf(
"Events processed = %d\n",myevt);
655 if (RUN_BENCHMARK==
false){
657 for (
unsigned int ring=0;ring<cdc_alignments.size();ring++){
658 for (
unsigned int straw=0;straw<cdc_alignments[ring].size();
660 if (fabs(cdc_alignments[ring][straw].A(k_dXu))>0.19)
661 cout << cdc_alignments[ring][straw].A(k_dXu) <<
" "
662 <<
sqrt(cdc_alignments[ring][straw].E(k_dXu,k_dXu)) << endl;
666 ofstream cdcfile(
"cdc_alignment.dat");
668 for (
unsigned int ring=0;ring<cdc_alignments.size();ring++){
669 for (
unsigned int straw=0;straw<cdc_alignments[ring].size();
672 cdcfile << cdc_alignments[ring][straw].A(k_dXu) <<
" "
673 << cdc_alignments[ring][straw].A(k_dYu) <<
" "
674 << cdc_alignments[ring][straw].A(k_dXd) <<
" "
675 << cdc_alignments[ring][straw].A(k_dYd) << endl;
680 ofstream cdcfile2(
"cdc_alignment_update.dat");
682 for (
unsigned int ring=0;ring<cdc_alignments.size();ring++){
683 for (
unsigned int straw=0;straw<cdc_alignments[ring].size();
686 cdcfile2 << (cdc_alignments[ring][straw].A(k_dXu)+cdc_offsets[ring][straw].dx_u) <<
" "
687 << (cdc_alignments[ring][straw].A(k_dYu)+cdc_offsets[ring][straw].dy_u) <<
" "
688 << (cdc_alignments[ring][straw].A(k_dXd)+cdc_offsets[ring][straw].dx_d) <<
" "
689 << (cdc_alignments[ring][straw].A(k_dYd)+cdc_offsets[ring][straw].dy_d) << endl;
697 if (ALIGN_WIRE_PLANES){
698 ofstream fdcfile(
"fdc_alignment.dat");
701 double du=fdc_alignments[
layer].A(kU);
702 double dphi=fdc_alignments[
layer].A(kPhiU);
704 fdcfile << dphi <<
" " <<
" " << du <<
" " <<
"0." << endl;
709 ofstream fdcfile(
"fdc_cathode_alignment.dat");
711 fdcfile << fdc_cathode_alignments[
layer].A(kPhiU)
712 <<
" " << fdc_cathode_alignments[
layer].A(kU)
713 <<
" " << fdc_cathode_alignments[
layer].A(kPhiV)
714 <<
" " << fdc_cathode_alignments[
layer].A(kV) << endl;
733 vector<const DFCALShower*>fcalshowers;
734 if (USE_FCAL) loop->Get(fcalshowers);
735 vector<const DBCALShower*>bcalshowers;
736 if (USE_BCAL)loop->Get(bcalshowers);
738 vector<const DFDCPseudo*>pseudos;
740 vector<const DCDCTrackHit*>cdcs;
744 if (cdcs.size()>20 ){
747 for (
size_t i=0;i<cdcs.size();i++) finder->AddHit(cdcs[i]);
748 finder->FindAxialSegments();
749 finder->LinkCDCSegments();
752 const vector<DTrackFinder::cdc_track_t>tracks=finder->GetCDCTracks();
753 for (
unsigned int i=0;i<tracks.size();i++){
756 vector<const DCDCTrackHit *>hits=tracks[i].axial_hits;
757 hits.insert(hits.end(),tracks[i].stereo_hits.begin(),tracks[i].stereo_hits.end());
762 for (
unsigned int j=0;j<hits.size();j++){
763 double L=(hits[0]->wire->origin-hits[j]->wire->origin).Perp();
764 double t_test=hits[j]->tdrift-L/29.98;
765 if (t_test<t0) t0=t_test;
772 DoFilter(t0,tracks[i].z,S,hits);
779 if (pseudos.size()>MIN_PSEUDOS
785 for (
size_t i=0;i<pseudos.size();i++) finder->AddHit(pseudos[i]);
786 finder->FindFDCSegments();
787 finder->LinkFDCSegments();
790 const vector<DTrackFinder::fdc_segment_t>tracks=finder->GetFDCTracks();
793 for (
unsigned int k=0;k<tracks.size();k++){
794 vector<const DFDCPseudo *>hits=tracks[k].hits;
796 if (hits.size()>MIN_PSEUDOS){
803 double my_z=hits[0]->wire->origin.z()-1.;
804 S(state_x)+=my_z*
S(state_tx);
805 S(state_y)+=my_z*
S(state_ty);
809 double dsdz=
sqrt(1.+
S(state_tx)*
S(state_tx)+
S(state_ty)*
S(state_ty));
810 for (
unsigned int m=0;m<hits.size();m++){
811 if (hits[m]->time<t0){
812 double L=(hits[m]->wire->origin.z()-my_z)*dsdz;
813 t0=hits[m]->time-L/29.98;
818 if (ALIGN_WIRE_PLANES) DoFilterAnodePlanes(t0,my_z,S,hits);
819 else DoFilterCathodePlanes(t0,my_z,S,hits);
830 vector<const DCDCTrackHit *>&hits){
831 unsigned int numhits=hits.size();
832 unsigned int maxindex=numhits-1;
835 double anneal_factor=pow(1e4,(
double(NEVENTS-myevt))/(NEVENTS-1.));
836 if (myevt>NEVENTS) anneal_factor=1.;
838 if (RUN_BENCHMARK) anneal_factor=1.;
841 deque<trajectory_t>trajectory;
842 deque<trajectory_t>best_traj;
849 C0(state_x,state_x)=
C0(state_y,state_y)=1.0;
850 C0(state_tx,state_tx)=
C0(state_ty,state_ty)=0.01;
852 vector<cdc_update_t>updates(hits.size());
853 vector<cdc_update_t>best_updates;
854 double chi2=1e16,chi2_old=1e16;
855 unsigned int ndof=0,ndof_old=0;
861 for(iter=0;iter<20;iter++){
866 if (SetReferenceTrajectory(t0,OuterZ,S,trajectory,
867 hits[maxindex])!=NOERROR)
break;
870 if (KalmanFilter(anneal_factor,S,C,hits,trajectory,updates,chi2,ndof)!=NOERROR)
875 if (fabs(chi2_old-chi2)<0.1 || chi2>chi2_old)
break;
880 best_updates.assign(updates.begin(),updates.end());
881 best_traj.assign(trajectory.begin(),trajectory.end());
887 double prelimprob=TMath::Prob(chi2_old,ndof_old);
888 Hcdc_prelimprob->Fill(prelimprob);
890 if (prelimprob>0.0001){
898 for (iter=0;iter<20;iter++){
903 if (SetReferenceTrajectory(t0,OuterZ,S,trajectory,hits[maxindex])
906 KalmanFilter(anneal_factor,S,C,hits,trajectory,updates,chi2,ndof,
true);
909 if (fabs(chi2-chi2_old)<0.1
910 || TMath::Prob(chi2,ndof)<TMath::Prob(chi2_old,ndof_old))
break;
914 best_updates.assign(updates.begin(),updates.end());
915 best_traj.assign(trajectory.begin(),trajectory.end());
920 double prob=TMath::Prob(chi2_old,ndof_old);
921 Hcdc_prob->Fill(prob);
923 PlotLines(trajectory);
928 vector<cdc_update_t>smoothed_updates(updates.size());
929 for (
unsigned int k=0;k<smoothed_updates.size();k++){
930 smoothed_updates[k].used_in_fit=
false;
932 Smooth(Sbest,Cbest,best_traj,hits,best_updates,smoothed_updates);
934 for (
unsigned int k=0;k<smoothed_updates.size();k++){
935 if (smoothed_updates[k].used_in_fit==
true){
936 double tdrift=smoothed_updates[k].drift_time;
937 double d=smoothed_updates[k].doca;
938 double res=smoothed_updates[k].res;
939 int ring_id=smoothed_updates[k].ring_id;
940 int straw_id=smoothed_updates[k].straw_id;
941 Hcdcres_vs_drift_time->Fill(tdrift,res);
942 Hcdcres_vs_d->Fill(d,res);
943 Hcdcdrift_time->Fill(tdrift,d);
944 Hcdc_time_vs_d->Fill(d,tdrift);
945 Hcdc_ring_res[ring_id]->Fill(straw_id+1,res);
946 Hcdc_ring_time[ring_id]->Fill(straw_id+1,tdrift);
950 if (prob>0.001 && RUN_BENCHMARK==
false){
951 FindOffsets(hits,smoothed_updates);
954 for (
unsigned int ring=0;ring<cdc_alignments.size();ring++){
955 for (
unsigned int straw=0;straw<cdc_alignments[ring].size();
958 cdc.dXu=cdc_alignments[ring][straw].A(k_dXu);
959 cdc.dYu=cdc_alignments[ring][straw].A(k_dYu);
960 cdc.dXd=cdc_alignments[ring][straw].A(k_dXd);
961 cdc.dYd=cdc_alignments[ring][straw].A(k_dYd);
968 japp->RootWriteLock();
992 vector<const DFDCPseudo *>&hits){
993 unsigned int num_hits=hits.size();
994 vector<update_t>updates(num_hits);
995 vector<update_t>best_updates;
996 vector<update_t>smoothed_updates(num_hits);
999 double anneal_factor=pow(1e3,(
double(NEVENTS-myevt))/(NEVENTS-1.));
1000 if (myevt>NEVENTS) anneal_factor=1.;
1002 if (RUN_BENCHMARK) anneal_factor=1.;
1010 deque<trajectory_t>trajectory;
1011 deque<trajectory_t>best_traj;
1015 C0(state_x,state_x)=
C0(state_y,state_y)=1.;
1016 C0(state_tx,state_tx)=
C0(state_ty,state_ty)=0.01;
1019 double chi2=1e16,chi2_old=1e16;
1020 unsigned int ndof=0,ndof_old=0;
1028 if (SetReferenceTrajectory(t0,start_z,S,trajectory,hits)!=NOERROR)
break;
1030 if (KalmanFilter(anneal_factor,S,C,hits,trajectory,updates,chi2,ndof)
1034 if (chi2>chi2_old || fabs(chi2_old-chi2)<0.1 || iter==
ITER_MAX)
break;
1039 best_updates.assign(updates.begin(),updates.end());
1040 best_traj.assign(trajectory.begin(),trajectory.end());
1046 double prob=TMath::Prob(chi2_old,ndof_old);
1047 Hpseudo_prob->Fill(prob);
1051 PlotLines(trajectory);
1056 Smooth(Sbest,Cbest,best_traj,hits,best_updates,smoothed_updates);
1059 for (
unsigned int i=0;i<smoothed_updates.size();i++){
1060 unsigned int layer=hits[i]->wire->layer;
1062 Hures_vs_layer->Fill(layer,smoothed_updates[i].res(0));
1063 Hvres_vs_layer->Fill(layer,smoothed_updates[i].res(1));
1064 Hdv_vs_dE->Fill(hits[i]->dE,smoothed_updates[i].res(1));
1066 Hdrift_time->Fill(smoothed_updates[i].drift_time,
1067 smoothed_updates[i].doca);
1070 if (prob>0.001 && RUN_BENCHMARK==
false){
1071 FindOffsets(hits,smoothed_updates);
1075 fdc_c.dPhiU=fdc_cathode_alignments[
layer].A(kPhiU);
1076 fdc_c.dU=fdc_cathode_alignments[
layer].A(kU);
1077 fdc_c.dPhiV=fdc_cathode_alignments[
layer].A(kPhiV);
1078 fdc_c.dV=fdc_cathode_alignments[
layer].A(kV);
1080 fdc_c.layer=
layer+1;
1084 japp->RootWriteLock();
1097 return VALUE_OUT_OF_RANGE;
1104 vector<const DFDCPseudo *>&hits){
1105 unsigned int num_hits=hits.size();
1106 vector<wire_update_t>updates(num_hits);
1107 vector<wire_update_t>best_updates;
1108 vector<wire_update_t>smoothed_updates(num_hits);
1111 double anneal_factor=1.;
1112 if (USE_DRIFT_TIMES){
1113 anneal_factor=pow(1000.,(
double(NEVENTS-myevt))/(NEVENTS-1.));
1114 if (myevt>NEVENTS) anneal_factor=1.;
1116 if (RUN_BENCHMARK) anneal_factor=1.;
1124 deque<trajectory_t>trajectory;
1125 deque<trajectory_t>best_traj;
1129 C0(state_x,state_x)=
C0(state_y,state_y)=1.;
1130 C0(state_tx,state_tx)=
C0(state_ty,state_ty)=0.001;
1133 double chi2=1e16,chi2_old=1e16;
1134 unsigned int ndof=0,ndof_old=0;
1142 if (SetReferenceTrajectory(t0,start_z,S,trajectory,hits)!=NOERROR)
break;
1144 if (KalmanFilter(anneal_factor,S,C,hits,trajectory,updates,chi2,ndof)
1148 if (chi2>chi2_old || iter==
ITER_MAX)
break;
1153 best_updates.assign(updates.begin(),updates.end());
1154 best_traj.assign(trajectory.begin(),trajectory.end());
1160 double prob=TMath::Prob(chi2_old,ndof_old);
1163 PlotLines(trajectory);
1168 Smooth(Sbest,Cbest,best_traj,hits,best_updates,smoothed_updates);
1171 for (
unsigned int i=0;i<smoothed_updates.size();i++){
1172 unsigned int layer=hits[i]->wire->layer;
1174 Hres_vs_layer->Fill(layer,smoothed_updates[i].ures);
1176 Hdrift_time->Fill(smoothed_updates[i].drift_time,
1177 smoothed_updates[i].doca);
1178 Hres_vs_drift_time->Fill(smoothed_updates[i].drift_time,
1179 smoothed_updates[i].ures);
1185 if (RUN_BENCHMARK==
false){
1186 FindOffsets(hits,smoothed_updates);
1190 fdc.dPhi=fdc_alignments[
layer].A(kPhiU);
1191 fdc.dX=fdc_alignments[
layer].A(kU);
1197 japp->RootWriteLock();
1211 return VALUE_OUT_OF_RANGE;
1217 deque<trajectory_t>&trajectory,
1218 vector<const DFDCPseudo *>&hits,
1219 vector<update_t>updates,
1220 vector<update_t>&smoothed_updates
1227 unsigned int max=trajectory.size()-1;
1228 S=(trajectory[
max].Skk);
1229 C=(trajectory[
max].Ckk);
1230 JT=(trajectory[
max].J.Transpose());
1233 for (
unsigned int m=max-1;m>0;m--){
1234 if (trajectory[m].h_id==0){
1235 A=trajectory[m].Ckk*JT*C.
Invert();
1236 Ss=trajectory[m].Skk+A*(Ss-
S);
1237 Cs=trajectory[m].Ckk+A*(Cs-C)*A.
Transpose();
1239 else if (trajectory[m].h_id>0){
1240 unsigned int first_id=trajectory[m].h_id-1;
1241 for (
int k=trajectory[m].num_hits-1;k>=0;k--){
1242 unsigned int id=first_id+k;
1243 A=updates[id].C*JT*C.
Invert();
1245 Ss=updates[id].S+A*(Ss-
S);
1246 Cs=updates[id].C+dC;
1249 double cosa=hits[id]->wire->udir.y();
1250 double sina=hits[id]->wire->udir.x();
1253 double x=Ss(state_x);
1254 double y=Ss(state_y);
1255 double tx=Ss(state_tx);
1256 double ty=Ss(state_ty);
1259 unsigned int layer=hits[id]->wire->layer-1;
1262 double delta_u=Aw(kU);
1263 double sindphi=
sin(Aw(kPhiU));
1264 double cosdphi=cos(Aw(kPhiU));
1267 double cospsi=cosa*cosdphi+sina*sindphi;
1268 double sinpsi=sina*cosdphi-cosa*sindphi;
1274 double upred_wire_plane=x*cospsi-y*sinpsi;
1275 double vpred_wire_plane=x*sinpsi+y*cospsi;
1276 double tu=tx*cospsi-ty*sinpsi;
1277 double tv=tx*sinpsi+ty*cospsi;
1281 double alpha=atan(tu);
1282 double cosalpha=cos(alpha);
1283 double sinalpha=
sin(alpha);
1286 double uwire=hits[id]->wire->u+delta_u;
1287 double d=(upred_wire_plane-uwire)*cosalpha;
1290 double vpred=vpred_wire_plane-tv*sinalpha*d;
1293 double phi_u=hits[id]->phi_u+A(kPhiU);
1294 double phi_v=hits[id]->phi_v+A(kPhiV);
1295 double cosphi_u=cos(phi_u);
1296 double sinphi_u=
sin(phi_u);
1297 double cosphi_v=cos(phi_v);
1298 double sinphi_v=
sin(phi_v);
1299 double vv=-vpred*sinphi_v+uwire*cosphi_v+A(kV);
1300 double vu=-vpred*sinphi_u+uwire*cosphi_u+A(kU);
1303 Mdiff(0)=hits[id]->u-vu;
1304 Mdiff(1)=hits[id]->v-vv;
1306 smoothed_updates[id].res=Mdiff;
1307 smoothed_updates[id].doca=fabs(d);
1309 smoothed_updates[id].drift=updates[id].drift;
1310 smoothed_updates[id].drift_time=updates[id].drift_time;
1311 smoothed_updates[id].S=Ss;
1312 smoothed_updates[id].C=Cs;
1313 smoothed_updates[id].V=updates[id].V-updates[id].H*dC*updates[id].H_T;
1316 S=trajectory[m].Skk;
1317 C=trajectory[m].Ckk;
1318 JT=trajectory[m].J.Transpose();
1321 A=trajectory[0].Ckk*JT*C.
Invert();
1322 Ss=trajectory[0].Skk+A*(Ss-
S);
1323 Cs=trajectory[0].Ckk+A*(Cs-C)*A.
Transpose();
1331 deque<trajectory_t>&trajectory,
1332 vector<const DFDCPseudo *>&hits,
1333 vector<wire_update_t>updates,
1334 vector<wire_update_t>&smoothed_updates
1340 unsigned int max=trajectory.size()-1;
1341 S=(trajectory[
max].Skk);
1342 C=(trajectory[
max].Ckk);
1343 JT=(trajectory[
max].J.Transpose());
1346 for (
unsigned int m=max-1;m>0;m--){
1347 if (trajectory[m].h_id==0){
1348 A=trajectory[m].Ckk*JT*C.
Invert();
1349 Ss=trajectory[m].Skk+A*(Ss-
S);
1350 Cs=trajectory[m].Ckk+A*(Cs-C)*A.
Transpose();
1352 else if (trajectory[m].h_id>0){
1353 unsigned int first_id=trajectory[m].h_id-1;
1354 for (
int k=trajectory[m].num_hits-1;k>=0;k--){
1355 unsigned int id=first_id+k;
1356 A=updates[id].C*JT*C.
Invert();
1358 Ss=updates[id].S+A*(Ss-
S);
1359 Cs=updates[id].C+dC;
1362 double cosa=hits[id]->wire->udir.y();
1363 double sina=hits[id]->wire->udir.x();
1366 double x=Ss(state_x);
1367 double y=Ss(state_y);
1368 double tx=Ss(state_tx);
1369 double ty=Ss(state_ty);
1372 unsigned int layer=hits[id]->wire->layer-1;
1375 double delta_u=A(kU);
1376 double sindphi=
sin(A(kPhiU));
1377 double cosdphi=cos(A(kPhiU));
1380 double cospsi=cosa*cosdphi+sina*sindphi;
1381 double sinpsi=sina*cosdphi-cosa*sindphi;
1388 double upred=x*cospsi-y*sinpsi;
1389 double tu=tx*cospsi-ty*sinpsi;
1393 double alpha=atan(tu);
1394 double cosalpha=cos(alpha);
1397 double uwire=hits[id]->wire->u+delta_u;
1398 double d=(upred-uwire)*cosalpha;
1399 smoothed_updates[id].ures=(d>0?1.:-1.)*updates[id].drift-d;
1400 smoothed_updates[id].doca=fabs(d);
1402 smoothed_updates[id].drift=updates[id].drift;
1403 smoothed_updates[id].drift_time=updates[id].drift_time;
1404 smoothed_updates[id].S=Ss;
1405 smoothed_updates[id].C=Cs;
1406 smoothed_updates[id].R=updates[id].R-updates[id].H*dC*updates[id].H_T;
1409 S=trajectory[m].Skk;
1410 C=trajectory[m].Ckk;
1411 JT=trajectory[m].J.Transpose();
1414 A=trajectory[0].Ckk*JT*C.
Invert();
1415 Ss=trajectory[0].Skk+A*(Ss-
S);
1416 Cs=trajectory[0].Ckk+A*(Cs-C)*A.
Transpose();
1424 deque<trajectory_t>&trajectory,
1425 vector<const DCDCTrackHit *>&hits,
1426 vector<cdc_update_t>&updates,
1427 vector<cdc_update_t>&smoothed_updates
1433 unsigned int max=trajectory.size()-1;
1434 S=(trajectory[
max].Skk);
1435 C=(trajectory[
max].Ckk);
1436 JT=(trajectory[
max].J.Transpose());
1440 for (
unsigned int m=max-1;m>0;m--){
1441 if (trajectory[m].h_id==0){
1442 A=trajectory[m].Ckk*JT*C.
Invert();
1443 Ss=trajectory[m].Skk+A*(Ss-
S);
1444 Cs=trajectory[m].Ckk+A*(Cs-C)*A.
Transpose();
1447 unsigned int id=trajectory[m].h_id-1;
1448 smoothed_updates[id].used_in_fit=
false;
1450 if (updates[
id].used_in_fit){
1451 smoothed_updates[id].used_in_fit=
true;
1453 A=updates[id].C*JT*C.
Invert();
1455 Ss=updates[id].S+A*(Ss-
S);
1456 Cs=updates[id].C+dC;
1459 const DCDCWire *wire=hits[id]->wire;
1463 unsigned int ring=hits[id]->wire->ring-1;
1464 unsigned int straw=hits[id]->wire->straw-1;
1465 UpdateWireOriginAndDir(ring,straw,origin,wdir);
1468 double d=finder->FindDoca(trajectory[m].z,Ss,wdir,origin);
1469 smoothed_updates[id].ring_id=ring;
1470 smoothed_updates[id].straw_id=straw;
1471 smoothed_updates[id].doca=d;
1472 smoothed_updates[id].res=updates[id].drift-d;
1473 smoothed_updates[id].drift=updates[id].drift;
1474 smoothed_updates[id].drift_time=updates[id].drift_time;
1475 smoothed_updates[id].S=Ss;
1476 smoothed_updates[id].C=Cs;
1477 smoothed_updates[id].V=updates[id].V-updates[id].H*dC*updates[id].H_T;
1478 smoothed_updates[id].z=updates[id].z;
1481 trajectory[m].h_id=0;
1484 A=trajectory[m].Ckk*JT*C.
Invert();
1485 Ss=trajectory[m].Skk+A*(Ss-
S);
1486 Cs=trajectory[m].Ckk+A*(Cs-C)*A.
Transpose();
1490 S=trajectory[m].Skk;
1491 C=trajectory[m].Ckk;
1492 JT=trajectory[m].J.Transpose();
1495 A=trajectory[0].Ckk*JT*C.
Invert();
1496 Ss=trajectory[0].Skk+A*(Ss-
S);
1497 Cs=trajectory[0].Ckk+A*(Cs-C)*A.
Transpose();
1506 vector<const DCDCTrackHit *>&hits,
1507 deque<trajectory_t>&trajectory,
1508 vector<cdc_update_t>&updates,
1509 double &chi2,
unsigned int &ndof,
1517 double V=1.15*(0.78*0.78/12.);
1519 for (
unsigned int i=0;i<updates.size();i++){
1520 updates[i].used_in_fit=
false;
1528 const double d_EPS=1
e-8;
1531 unsigned int cdc_index=hits.size()-1;
1532 bool more_hits=
true;
1533 const DCDCWire *wire=hits[cdc_index]->wire;
1535 double z0=origin.z();
1536 double vz=wire->
udir.z();
1540 unsigned int ring=wire->
ring-1;
1541 unsigned int straw=wire->
straw-1;
1542 UpdateWireOriginAndDir(ring,straw,origin,wdir);
1544 DVector3 wirepos=origin+(trajectory[0].z-z0)*wdir;
1547 double dx=
S(state_x)-wirepos.X();
1548 double dy=
S(state_y)-wirepos.Y();
1549 double old_doca2=dx*dx+dy*dy;
1554 trajectory[0].Skk=
S;
1555 trajectory[0].Ckk=C;
1556 for (
unsigned int k=1;k<trajectory.size();k++){
1557 if (C(0,0)<=0. || C(1,1)<=0. || C(2,2)<=0. || C(3,3)<=0.)
1558 return UNRECOVERABLE_ERROR;
1561 S=trajectory[k].S+J*(S-S0);
1565 trajectory[k].Skk=
S;
1566 trajectory[k].Ckk=C;
1573 wirepos=origin+(trajectory[k].z-z0)*wdir;
1576 dx=
S(state_x)-wirepos.X();
1577 dy=
S(state_y)-wirepos.Y();
1580 if (doca2>old_doca2 && more_hits){
1583 double tx=
S(state_tx),ty=
S(state_ty);
1584 DVector3 pos0(
S(state_x),
S(state_y),trajectory[k].z);
1589 double dx0=diff.x(),dy0=diff.y();
1590 double wdir_dot_diff=diff.Dot(wdir);
1591 double tdir_dot_diff=diff.Dot(tdir);
1592 double tdir_dot_wdir=tdir.Dot(wdir);
1593 double tdir2=tdir.Mag2();
1594 double wdir2=wdir.Mag2();
1595 double D=tdir2*wdir2-tdir_dot_wdir*tdir_dot_wdir;
1596 double N=tdir_dot_wdir*wdir_dot_diff-wdir2*tdir_dot_diff;
1597 double N1=tdir2*wdir_dot_diff-tdir_dot_wdir*tdir_dot_diff;
1601 diff+=s*tdir-t*wdir;
1602 double d=diff.Mag()+d_EPS;
1605 double tdrift=hits[cdc_index]->tdrift-trajectory[k].t;
1609 V=anneal_factor*drift_var;
1611 double phi_d=diff.Phi();
1612 double dphi=phi_d-origin.Phi();
1613 while (dphi>M_PI) dphi-=2*M_PI;
1614 while (dphi<-M_PI) dphi+=2*M_PI;
1616 int ring_index=hits[cdc_index]->wire->ring-1;
1617 int straw_index=hits[cdc_index]->wire->straw-1;
1618 double dz=t*wdir.z();
1619 double delta=max_sag[ring_index][straw_index]*(1.-dz*dz/5625.)
1620 *
sin(phi_d+sag_phi_offset[ring_index][straw_index]);
1621 dmeas=cdc_drift_distance(dphi,delta,tdrift);
1630 double one_over_d=1./d;
1631 double diffx=diff.x(),diffy=diff.y(),diffz=diff.z();
1632 double wx=wdir.x(),wy=wdir.y();
1634 double dN1dtx=2.*tx*wdir_dot_diff-wx*tdir_dot_diff-tdir_dot_wdir*dx0;
1635 double dDdtx=2.*tx*wdir2-2.*tdir_dot_wdir*wx;
1636 double dtdtx=scale*(dN1dtx-t*dDdtx);
1638 double dN1dty=2.*ty*wdir_dot_diff-wy*tdir_dot_diff-tdir_dot_wdir*dy0;
1639 double dDdty=2.*ty*wdir2-2.*tdir_dot_wdir*wy;
1640 double dtdty=scale*(dN1dty-t*dDdty);
1642 double dNdtx=wx*wdir_dot_diff-wdir2*dx0;
1643 double dsdtx=scale*(dNdtx-s*dDdtx);
1645 double dNdty=wy*wdir_dot_diff-wdir2*dy0;
1646 double dsdty=scale*(dNdty-s*dDdty);
1648 H(state_tx)=H_T(state_tx)
1649 =one_over_d*(diffx*(s+tx*dsdtx-wx*dtdtx)+diffy*(ty*dsdtx-wy*dtdtx)
1650 +diffz*(dsdtx-dtdtx));
1651 H(state_ty)=H_T(state_ty)
1652 =one_over_d*(diffx*(tx*dsdty-wx*dtdty)+diffy*(s+ty*dsdty-wy*dtdty)
1653 +diffz*(dsdty-dtdty));
1655 double dsdx=scale*(tdir_dot_wdir*wx-wdir2*
tx);
1656 double dtdx=scale*(tdir2*wx-tdir_dot_wdir*
tx);
1657 double dsdy=scale*(tdir_dot_wdir*wy-wdir2*ty);
1658 double dtdy=scale*(tdir2*wy-tdir_dot_wdir*ty);
1660 H(state_x)=H_T(state_x)
1661 =one_over_d*(diffx*(1.+dsdx*tx-dtdx*wx)+diffy*(dsdx*ty-dtdx*wy)
1662 +diffz*(dsdx-dtdx));
1663 H(state_y)=H_T(state_y)
1664 =one_over_d*(diffx*(dsdy*tx-dtdy*wx)+diffy*(1.+dsdy*ty-dtdy*wy)
1665 +diffz*(dsdy-dtdy));
1670 ComputeGMatrices(s,t,scale,tx,ty,tdir2,one_over_d,wx,wy,wdir2,tdir_dot_wdir,
1671 tdir_dot_diff,wdir_dot_diff,dx0,dy0,diffx,diffy,diffz,
1676 double Vtemp=V+G*E*G_T;
1677 double InvV=1./(Vtemp+H*C*H_T);
1690 if (Ctest(0,0)>0.0 && Ctest(1,1)>0.0 && Ctest(2,2)>0.0 && Ctest(3,3)>0.0)
1699 d=finder->FindDoca(trajectory[k].z,S,wdir,origin);
1704 chi2+=res*res/Vtemp;
1709 return VALUE_OUT_OF_RANGE;
1712 updates[cdc_index].S=
S;
1713 updates[cdc_index].C=C;
1714 updates[cdc_index].drift=dmeas;
1715 updates[cdc_index].drift_time=tdrift;
1716 updates[cdc_index].doca=d;
1717 updates[cdc_index].res=res;
1718 updates[cdc_index].V=Vtemp;
1719 updates[cdc_index].H_T=H_T;
1720 updates[cdc_index].H=
H;
1721 updates[cdc_index].z=trajectory[k].z;
1722 updates[cdc_index].used_in_fit=
true;
1724 trajectory[k].h_id=cdc_index+1;
1731 wire=hits[cdc_index]->wire;
1734 wdir=(1./vz)*wire->
udir;
1736 ring=hits[cdc_index]->wire->ring-1;
1737 straw=hits[cdc_index]->wire->straw-1;
1738 UpdateWireOriginAndDir(ring,straw,origin,wdir);
1740 wirepos=origin+((trajectory[k].z-z0))*wdir;
1743 dx=
S(state_x)-wirepos.x();
1744 dy=
S(state_y)-wirepos.y();
1748 else more_hits=
false;
1763 vector<const DFDCPseudo *>&hits,
1764 deque<trajectory_t>&trajectory,
1765 vector<update_t>&updates,
1766 double &chi2,
unsigned int &ndof){
1770 DMatrix2x2 V(0.0008*anneal_factor,0.,0.,0.0008*anneal_factor);
1784 trajectory[0].Skk=
S;
1785 trajectory[0].Ckk=C;
1786 for (
unsigned int k=1;k<trajectory.size();k++){
1787 if (C(0,0)<=0. || C(1,1)<=0. || C(2,2)<=0. || C(3,3)<=0.)
1788 return UNRECOVERABLE_ERROR;
1791 S=trajectory[k].S+J*(S-S0);
1795 trajectory[k].Skk=
S;
1796 trajectory[k].Ckk=C;
1803 if (trajectory[k].h_id>0){
1804 unsigned int id=trajectory[k].h_id-1;
1806 double cosa=hits[id]->wire->udir.y();
1807 double sina=hits[id]->wire->udir.x();
1810 double x=
S(state_x);
1811 double y=
S(state_y);
1812 double tx=
S(state_tx);
1813 double ty=
S(state_ty);
1814 if (std::isnan(x) || std::isnan(y))
return UNRECOVERABLE_ERROR;
1817 unsigned int layer=hits[id]->wire->layer-1;
1819 double delta_u=Aw(kU);
1820 double sindphi=
sin(Aw(kPhiU));
1821 double cosdphi=cos(Aw(kPhiU));
1824 double cospsi=cosa*cosdphi+sina*sindphi;
1825 double sinpsi=sina*cosdphi-cosa*sindphi;
1832 double vpred_wire_plane=y*cospsi+x*sinpsi;
1833 double upred_wire_plane=x*cospsi-y*sinpsi;
1834 double tu=tx*cospsi-ty*sinpsi;
1835 double tv=tx*sinpsi+ty*cospsi;
1839 double alpha=atan(tu);
1840 double cosalpha=cos(alpha);
1841 double cos2_alpha=cosalpha*cosalpha;
1842 double sinalpha=
sin(alpha);
1843 double sin2_alpha=sinalpha*sinalpha;
1850 for (
int m=trajectory[k].num_hits-1;m>=0;m--){
1851 unsigned int my_id=
id+m;
1852 double uwire=hits[my_id]->wire->u+delta_u;
1854 double doca=(upred_wire_plane-uwire)*cosalpha;
1857 double vpred=vpred_wire_plane-tv*sinalpha*doca;
1860 double phi_u=hits[my_id]->phi_u+A(kPhiU);
1861 double phi_v=hits[my_id]->phi_v+A(kPhiV);
1862 double cosphi_u=cos(phi_u);
1863 double sinphi_u=
sin(phi_u);
1864 double cosphi_v=cos(phi_v);
1865 double sinphi_v=
sin(phi_v);
1866 double vv=-vpred*sinphi_v-uwire*cosphi_v+A(kV);
1867 double vu=-vpred*sinphi_u-uwire*cosphi_u+A(kU);
1870 Mdiff(0)=hits[my_id]->u-vu;
1871 Mdiff(1)=hits[my_id]->v-vv;
1874 updates[my_id].drift_time=hits[my_id]->time-trajectory[k].t;
1877 double temp2=tv*sinalpha*cosalpha;
1878 double dvdy=cospsi+sinpsi*temp2;
1879 double dvdx=sinpsi-cospsi*temp2;
1881 H_T(state_x,0)=-dvdx*sinphi_u;
1882 H_T(state_y,0)=-dvdy*sinphi_u;
1883 H_T(state_x,1)=-dvdx*sinphi_v;
1884 H_T(state_y,1)=-dvdy*sinphi_v;
1886 double cos2_minus_sin2=cos2_alpha-sin2_alpha;
1887 double doca_cosalpha=doca*cosalpha;
1888 double dvdtx=-doca_cosalpha*(tu*sina+tv*cosa*cos2_minus_sin2);
1889 double dvdty=-doca_cosalpha*(tu*cosa-tv*sina*cos2_minus_sin2);
1891 H_T(state_tx,0)=-dvdtx*sinphi_u;
1892 H_T(state_ty,0)=-dvdty*sinphi_u;
1893 H_T(state_tx,1)=-dvdtx*sinphi_v;
1894 H_T(state_ty,1)=-dvdty*sinphi_v;
1897 H(0,state_x)=H_T(state_x,0);
1898 H(0,state_y)=H_T(state_y,0);
1899 H(0,state_tx)=H_T(state_tx,0);
1900 H(0,state_ty)=H_T(state_ty,0);
1901 H(1,state_x)=H_T(state_x,1);
1902 H(1,state_y)=H_T(state_y,1);
1903 H(1,state_tx)=H_T(state_tx,1);
1904 H(1,state_ty)=H_T(state_ty,1);
1907 updates[my_id].H_T=H_T;
1914 G_T(kPhiU,0)=-vpred*cosphi_u-uwire*sinphi_u;
1916 G_T(kPhiV,1)=-vpred*cosphi_v-uwire*sinphi_v;
1920 G(0,kPhiU)=G_T(kPhiU,0);
1922 G(1,kPhiV)=G_T(kPhiV,1);
1927 InvV=(Vtemp+H*C*H_T).Invert();
1941 updates[my_id].res=Mdiff-H*K*Mdiff;
1942 updates[my_id].V=RC;
1946 chi2+=RC.Chi2(updates[my_id].res);
1965 vector<const DFDCPseudo *>&hits,
1966 deque<trajectory_t>&trajectory,
1967 vector<wire_update_t>&updates,
1968 double &chi2,
unsigned int &ndof){
1973 double Vtemp,Mdiff,InvV;
1985 trajectory[0].Skk=
S;
1986 trajectory[0].Ckk=C;
1987 for (
unsigned int k=1;k<trajectory.size();k++){
1988 if (C(0,0)<=0. || C(1,1)<=0. || C(2,2)<=0. || C(3,3)<=0.)
1989 return UNRECOVERABLE_ERROR;
1992 S=trajectory[k].S+J*(S-S0);
1996 trajectory[k].Skk=
S;
1997 trajectory[k].Ckk=C;
2004 if (trajectory[k].h_id>0){
2005 unsigned int id=trajectory[k].h_id-1;
2007 double cosa=hits[id]->wire->udir.y();
2008 double sina=hits[id]->wire->udir.x();
2011 double x=
S(state_x);
2012 double y=
S(state_y);
2013 double tx=
S(state_tx);
2014 double ty=
S(state_ty);
2015 if (std::isnan(x) || std::isnan(y))
return UNRECOVERABLE_ERROR;
2018 unsigned int layer=hits[id]->wire->layer-1;
2021 double delta_u=A(kU);
2022 double sindphi=
sin(A(kPhiU));
2023 double cosdphi=cos(A(kPhiU));
2026 double cospsi=cosa*cosdphi+sina*sindphi;
2027 double sinpsi=sina*cosdphi-cosa*sindphi;
2034 double upred=x*cospsi-y*sinpsi;
2035 double tu=tx*cospsi-ty*sinpsi;
2036 double tv=tx*sinpsi+ty*cospsi;
2040 double alpha=atan(tu);
2041 double cosalpha=cos(alpha);
2042 double sinalpha=
sin(alpha);
2045 for (
int m=trajectory[k].num_hits-1;m>=0;m--){
2046 unsigned int my_id=
id+m;
2047 double uwire=hits[my_id]->wire->u+delta_u;
2050 double drift_time=hits[my_id]->time-trajectory[k].t;
2051 updates[my_id].drift_time=drift_time;
2052 updates[my_id].t=trajectory[k].t;
2054 double du=upred-uwire;
2055 double d=du*cosalpha;
2056 double sign=(du>0)?1.:-1.;
2061 if (USE_DRIFT_TIMES){
2064 drift=fdc_drift_distance(drift_time);
2067 double sigma=0.0135-3.98e-4*drift_time+5.62e-6*drift_time*drift_time;
2068 V=anneal_factor*sigma*
sigma;
2072 updates[my_id].drift=drift;
2075 double sinalpha_cosalpha=sinalpha*cosalpha;
2076 H_T(state_x)=cospsi*cosalpha;
2077 H_T(state_y)=-sinpsi*cosalpha;
2079 double temp=d*sinalpha_cosalpha;
2080 H_T(state_tx)=-temp*cospsi;
2081 H_T(state_ty)=+temp*sinpsi;
2084 H(state_x)=H_T(state_x);
2085 H(state_y)=H_T(state_y);
2087 H(state_tx)=H_T(state_tx);
2088 H(state_ty)=H_T(state_ty);
2091 updates[my_id].H_T=H_T;
2098 G_T(kPhiU)=cosalpha*(x*sinpsi+y*cospsi-tv*d);
2102 G(kPhiU)=G_T(kPhiU);
2107 InvV=1./(Vtemp+H*C*H_T);
2125 upred=x*cospsi-y*sinpsi;
2126 tu=tx*cospsi-ty*sinpsi;
2131 cosalpha=cos(alpha);
2134 sinalpha=
sin(alpha);
2139 double RC=Vtemp-H*C*H_T;
2140 updates[my_id].ures=Mdiff;
2141 updates[my_id].R=RC;
2143 chi2+=Mdiff*Mdiff/RC;
2159 deque<trajectory_t>&trajectory,
2161 DMatrix4x4 J(1.,0.,1.,0., 0.,1.,0.,1., 0.,0.,1.,0., 0.,0.,0.,1.);
2164 double dz=(
S(state_ty)>0.?-1.:1.)*ds/
sqrt(1.+
S(state_tx)*
S(state_tx)+
S(state_ty)*
S(state_ty));
2169 unsigned int numsteps=0;
2172 J(state_x,state_tx)=-dz;
2173 J(state_y,state_ty)=-dz;
2177 S(state_x)+=
S(state_tx)*dz;
2178 S(state_y)+=
S(state_ty)*dz;
2179 trajectory.push_front(
trajectory_t(z,t0,S,J,Zero4x1,Zero4x4));
2182 }
while (
S(state_y)>min_y && numsteps<
MAX_STEPS);
2184 if (trajectory.size()<2)
return UNRECOVERABLE_ERROR;
2188 for (
unsigned int i=0;i<trajectory.size();i++){
2189 printf(
" x %f y %f z %f\n",trajectory[i].
S(state_x),
2190 trajectory[i].
S(state_y),trajectory[i].z);
2204 deque<trajectory_t>&trajectory,
2205 vector<const DFDCPseudo *>&pseudos){
2207 DMatrix4x4 J(1.,0.,1.,0., 0.,1.,0.,1., 0.,0.,1.,0., 0.,0.,0.,1.);
2211 trajectory.push_front(
trajectory_t(z,t0,S,J,Zero4x1,Zero4x4));
2215 for (
unsigned int i=0;i<pseudos.size();i++){
2216 zhit=pseudos[i]->wire->origin.z();
2219 if (fabs(zhit-old_zhit)<
EPS){
2220 trajectory[0].num_hits++;
2232 J(state_x,state_tx)=-dz;
2233 J(state_y,state_ty)=-dz;
2235 t+=dz*
sqrt(1+
S(state_tx)*
S(state_tx)+
S(state_ty)*
S(state_ty))/29.98;
2237 S(state_x)+=
S(state_tx)*dz;
2238 S(state_y)+=
S(state_ty)*dz;
2240 trajectory.push_front(
trajectory_t(new_z,t,S,J,Zero4x1,Zero4x4));
2242 trajectory[0].h_id=i+1;
2243 trajectory[0].num_hits=1;
2252 J(state_x,state_tx)=-dz;
2253 J(state_y,state_ty)=-dz;
2256 t+=dz*
sqrt(1+
S(state_tx)*
S(state_tx)+
S(state_ty)*
S(state_ty))/29.98;
2259 S(state_x)+=
S(state_tx)*dz;
2260 S(state_y)+=
S(state_ty)*dz;
2261 trajectory.push_front(
trajectory_t(z+dz,t,S,J,Zero4x1,Zero4x4));
2266 for (
unsigned int i=0;i<trajectory.size();i++){
2267 printf(
" x %f y %f z %f first hit %d num in layer %d\n",trajectory[i].
S(state_x),
2268 trajectory[i].
S(state_y),trajectory[i].z,trajectory[i].h_id,
2269 trajectory[i].num_hits);
2279 else if (t>110.) t=110.;
2280 double sigma=0.01639/
sqrt(t+1.)+5.405e-3+4.936e-4*exp(0.09654*(t-66.86));
2286 if (t<0.)
return 0.;
2287 double d=0.0268*
sqrt(t)+7.438e-4*t;
2296 double zscale=75.0/wdir.z();
2297 DVector3 upstream=origin-zscale*wdir;
2298 DVector3 downstream=origin+zscale*wdir;
2299 DVector3 du(cdc_alignments[ring][straw].A(k_dXu),
2300 cdc_alignments[ring][straw].A(k_dYu),0.);
2301 DVector3 dd(cdc_alignments[ring][straw].A(k_dXd),
2302 cdc_alignments[ring][straw].A(k_dYd),0.);
2306 origin=0.5*(upstream+downstream);
2307 wdir=downstream-upstream;
2315 vector<cdc_update_t>&updates){
2316 for (
unsigned int i=0;i<updates.size();i++){
2317 if (updates[i].used_in_fit==
true){
2319 const DCDCWire *wire=hits[i]->wire;
2323 unsigned int ring=wire->
ring-1;
2324 unsigned int straw=wire->
straw-1;
2325 UpdateWireOriginAndDir(ring,straw,origin,wdir);
2328 double tx=updates[i].S(state_tx),ty=updates[i].S(state_ty);
2329 DVector3 pos0(updates[i].
S(state_x),updates[i].
S(state_y),updates[i].z);
2331 double dx0=diff.x(),dy0=diff.y();
2333 double wdir_dot_diff=diff.Dot(wdir);
2334 double tdir_dot_diff=diff.Dot(tdir);
2335 double tdir_dot_wdir=tdir.Dot(wdir);
2336 double tdir2=tdir.Mag2();
2337 double wdir2=wdir.Mag2();
2338 double wx=wdir.x(),wy=wdir.y();
2339 double D=tdir2*wdir2-tdir_dot_wdir*tdir_dot_wdir;
2340 double N=tdir_dot_wdir*wdir_dot_diff-wdir2*tdir_dot_diff;
2341 double N1=tdir2*wdir_dot_diff-tdir_dot_wdir*tdir_dot_diff;
2345 diff+=s*tdir-t*wdir;
2346 double diffx=diff.x(),diffy=diff.y(),diffz=diff.z();
2347 double one_over_d=1./diff.Mag();
2352 ComputeGMatrices(s,t,scale,tx,ty,tdir2,one_over_d,wx,wy,wdir2,tdir_dot_wdir,
2353 tdir_dot_diff,wdir_dot_diff,dx0,dy0,diffx,diffy,diffz,
2360 double InvV=1./updates[i].V;
2368 if (Etemp(0,0)>0 && Etemp(1,1)>0 && Etemp(2,2)>0&&Etemp(3,3)>0.){
2372 DMatrix4x1 A=cdc_alignments[ring][straw].A+dA;
2374 if (fabs(A(k_dXu))<0.2 && fabs(A(k_dXd))<0.2 && fabs(A(k_dYu))<0.2
2375 && fabs(A(k_dYd))<0.2){
2376 cdc_alignments[ring][straw].E=Etemp;
2377 cdc_alignments[ring][straw].A=A;
2389 vector<update_t>&smoothed_updates){
2393 unsigned int num_hits=hits.size();
2395 for (
unsigned int i=0;i<num_hits;i++){
2397 unsigned int layer=hits[i]->wire->layer-1;
2402 double cosa=hits[i]->wire->udir.y();
2403 double sina=hits[i]->wire->udir.x();
2407 double x=
S(state_x);
2408 double y=
S(state_y);
2409 double tx=
S(state_tx);
2410 double ty=
S(state_ty);
2411 if (std::isnan(x) || std::isnan(y))
return UNRECOVERABLE_ERROR;
2415 double delta_u=Aw(kU);
2416 double sindphi=
sin(Aw(kPhiU));
2417 double cosdphi=cos(Aw(kPhiU));
2420 double cospsi=cosa*cosdphi+sina*sindphi;
2421 double sinpsi=sina*cosdphi-cosa*sindphi;
2428 double vpred_wire_plane=y*cospsi+x*sinpsi;
2429 double upred_wire_plane=x*cospsi-y*sinpsi;
2430 double tu=tx*cospsi-ty*sinpsi;
2431 double tv=tx*sinpsi+ty*cospsi;
2432 double alpha=atan(tu);
2433 double cosalpha=cos(alpha);
2434 double sinalpha=
sin(alpha);
2437 double uwire=hits[i]->wire->u+delta_u;
2439 double doca=(upred_wire_plane-uwire)*cosalpha;
2442 double vpred=vpred_wire_plane-tv*sinalpha*doca;
2448 double phi_u=hits[i]->phi_u+A(kPhiU);
2449 double phi_v=hits[i]->phi_v+A(kPhiV);
2452 G_T(kPhiU,0)=-vpred*cos(phi_u)-uwire*
sin(phi_u);
2454 G_T(kPhiV,1)=-vpred*cos(phi_v)-uwire*
sin(phi_v);
2457 DMatrix4x2 Ka=(E*G_T)*smoothed_updates[i].V.Invert();
2460 if (Etemp(0,0)>0 && Etemp(1,1)>0 && Etemp(2,2)>0 && Etemp(3,3)>0){
2461 fdc_cathode_alignments[
layer].E=Etemp;
2462 fdc_cathode_alignments[
layer].A=A+dA;
2478 vector<wire_update_t>&smoothed_updates){
2482 unsigned int num_hits=hits.size();
2485 for (
unsigned int i=0;i<num_hits;i++){
2486 double x=smoothed_updates[i].S(state_x);
2487 double y=smoothed_updates[i].S(state_y);
2488 double tx=smoothed_updates[i].S(state_tx);
2489 double ty=smoothed_updates[i].S(state_ty);
2491 double cosa=hits[i]->wire->udir.y();
2492 double sina=hits[i]->wire->udir.x();
2495 unsigned int layer=hits[i]->wire->layer-1;
2498 double delta_u=A(kU);
2499 double sindphi=
sin(A(kPhiU));
2500 double cosdphi=cos(A(kPhiU));
2503 double cospsi=cosa*cosdphi+sina*sindphi;
2504 double sinpsi=sina*cosdphi-cosa*sindphi;
2511 double uwire=hits[i]->wire->u+delta_u;
2512 double upred=x*cospsi-y*sinpsi;
2513 double tu=tx*cospsi-ty*sinpsi;
2514 double tv=tx*sinpsi+ty*cospsi;
2515 double du=upred-uwire;
2519 double alpha=atan(tu);
2520 double cosalpha=cos(alpha);
2525 double d=du*cosalpha;
2526 G_T(kPhiU)=cosalpha*(x*sinpsi+y*cospsi-tv*d);
2530 G(kPhiU)=G_T(kPhiU);
2533 double InvV=1./smoothed_updates[i].R;
2539 if (Etemp(0,0)>0 && Etemp(1,1)>0){
2540 fdc_alignments[
layer].E=Etemp;
2541 fdc_alignments[
layer].A=A+dA;
2559 double tx,
double ty,
double tdir2,
2561 double wx,
double wy,
double wdir2,
2562 double tdir_dot_wdir,
2563 double tdir_dot_diff,
2564 double wdir_dot_diff,
2565 double dx0,
double dy0,
2566 double diffx,
double diffy,
2569 double dsdDx=scale*(tdir_dot_wdir*wx-wdir2*
tx);
2570 double dsdDy=scale*(tdir_dot_wdir*wy-wdir2*ty);
2572 double dNdvx=tx*wdir_dot_diff+tdir_dot_wdir*dx0-2.*wx*tdir_dot_diff;
2573 double dDdvx=2.*wx*tdir2-2.*tdir_dot_wdir*
tx;
2574 double dsdvx=scale*(dNdvx-s*dDdvx);
2576 double dNdvy=ty*wdir_dot_diff+tdir_dot_wdir*dy0-2.*wy*tdir_dot_diff;
2577 double dDdvy=2.*wy*tdir2-2.*tdir_dot_wdir*ty;;
2578 double dsdvy=scale*(dNdvy-s*dDdvy);
2580 double dsddxu=-0.5*dsdDx-one_over_zrange*dsdvx;
2581 double dsddxd=-0.5*dsdDx+one_over_zrange*dsdvx;
2582 double dsddyu=-0.5*dsdDy-one_over_zrange*dsdvy;
2583 double dsddyd=-0.5*dsdDy+one_over_zrange*dsdvy;
2585 double dtdDx=scale*(tdir2*wx-tdir_dot_wdir*
tx);
2586 double dtdDy=scale*(tdir2*wy-tdir_dot_wdir*ty);
2588 double dN1dvx=tdir2*dx0-tdir_dot_diff*
tx;
2589 double dtdvx=scale*(dN1dvx-t*dDdvx);
2591 double dN1dvy=tdir2*dy0-tdir_dot_diff*ty;
2592 double dtdvy=scale*(dN1dvy-t*dDdvy);
2594 double dtddxu=-0.5*dtdDx-one_over_zrange*dtdvx;
2595 double dtddxd=-0.5*dtdDx+one_over_zrange*dtdvx;
2596 double dtddyu=-0.5*dtdDy-one_over_zrange*dtdvy;
2597 double dtddyd=-0.5*dtdDy+one_over_zrange*dtdvy;
2599 double t_over_zrange=one_over_zrange*t;
2600 G(k_dXu)=one_over_d*(diffx*(-0.5+tx*dsddxu+t_over_zrange-wx*dtddxu)
2601 +diffy*(ty*dsddxu-wy*dtddxu)+diffz*(dsddxu-dtddxu));
2602 G(k_dXd)=one_over_d*(diffx*(-0.5+tx*dsddxd-t_over_zrange-wx*dtddxd)
2603 +diffy*(ty*dsddxd-wy*dtddxd)+diffz*(dsddxd-dtddxd));
2604 G(k_dYu)=one_over_d*(diffx*(tx*dsddyu-wx*dtddyu)+diffz*(dsddyu-dtddyu)
2605 +diffy*(-0.5+ty*dsddyu+t_over_zrange-wy*dtddyu));
2606 G(k_dYd)=one_over_d*(diffx*(tx*dsddyd-wx*dtddyd)+diffz*(dsddyd-dtddyd)
2607 +diffy*(-0.5+ty*dsddyd-t_over_zrange-wy*dtddyd));
2608 G_T(k_dXu)=
G(k_dXu);
2609 G_T(k_dXd)=
G(k_dXd);
2610 G_T(k_dYu)=
G(k_dYu);
2611 G_T(k_dYd)=
G(k_dYd);
2617 unsigned int last_index=traj.size()-1;
2619 TCanvas *
c1=
dynamic_cast<TCanvas *
>(gROOT->FindObject(
"endviewA Canvas"));
2622 TPolyLine *line=
new TPolyLine();
2624 line->SetLineColor(1);
2625 line->SetLineWidth(1);
2627 line->SetNextPoint(traj[last_index].
S(state_x),traj[last_index].
S(state_y));
2628 line->SetNextPoint(traj[0].
S(state_x),traj[0].
S(state_y));
2636 c1=
dynamic_cast<TCanvas *
>(gROOT->FindObject(
"endviewA Large Canvas"));
2639 TPolyLine *line=
new TPolyLine();
2641 line->SetLineColor(1);
2642 line->SetLineWidth(1);
2644 line->SetNextPoint(traj[last_index].
S(state_x),traj[last_index].
S(state_y));
2645 line->SetNextPoint(traj[0].
S(state_x),traj[0].
S(state_y));
2653 c1=
dynamic_cast<TCanvas *
>(gROOT->FindObject(
"sideviewA Canvas"));
2656 TPolyLine *line=
new TPolyLine();
2658 line->SetLineColor(1);
2659 line->SetLineWidth(1);
2661 line->SetNextPoint(traj[last_index].z,traj[last_index].
S(state_x));
2662 line->SetNextPoint(traj[0].z,traj[0].
S(state_x));
2670 c1=
dynamic_cast<TCanvas *
>(gROOT->FindObject(
"sideviewB Canvas"));
2673 TPolyLine *line=
new TPolyLine();
2675 line->SetLineColor(1);
2676 line->SetLineWidth(1);
2678 line->SetNextPoint(traj[last_index].z,traj[last_index].
S(state_y));
2679 line->SetNextPoint(traj[0].z,traj[0].
S(state_y));
double GetDriftDistance(double t)
void PlotLines(deque< trajectory_t > &traj)
jerror_t DoFilterAnodePlanes(double t0, double start_z, DMatrix4x1 &S, vector< const DFDCPseudo * > &fdchits)
bool cdc_hit_cmp(const DCDCTrackHit *a, const DCDCTrackHit *b)
~DEventProcessor_dc_alignment()
const DBCALShower * match
double cdc_drift_distance(double dphi, double delta, double t)
double short_drift_func[3][3]
jerror_t init(void)
Called once at program start.
double GetDriftVariance(double t)
sprintf(text,"Post KinFit Cut")
const DFDCWire * wire
DFDCWire for this wire.
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
jerror_t DoFilterCathodePlanes(double t0, double start_z, DMatrix4x1 &S, vector< const DFDCPseudo * > &fdchits)
class DFDCPseudo: definition for a reconstructed point in the FDC
static char index(char c)
static void locate(const double *xx, int n, double x, int *j)
void ComputeGMatrices(double s, double t, double scale, double tx, double ty, double tdir2, double one_over_d, double wx, double wy, double wdir2, double tdir_dot_wdir, double tdir_dot_diff, double wdir_dot_diff, double dx0, double dy0, double diffx, double diffy, double diffz, DMatrix1x4 &G, DMatrix4x1 &G_T)
DEventProcessor_dc_alignment()
double fdc_drift_distance(double t)
double long_drift_func[3][3]
double cdc_variance(double x)
bool bcal_cmp(const bcal_match_t &a, const bcal_match_t &b)
vector< double > cdc_drift_table
jerror_t SetReferenceTrajectory(double t0, double z, DMatrix4x1 &S, deque< trajectory_t > &trajectory, vector< const DFDCPseudo * > &hits)
DGeometry * GetDGeometry(unsigned int run_number)
jerror_t fini(void)
Called after last event of last event source has been processed.
Double_t sigma[NCHANNELS]
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
jerror_t DoFilter(double t0, double z, DMatrix4x1 &S, vector< const DCDCTrackHit * > &hits)
jerror_t FindOffsets(vector< const DFDCPseudo * > &hits, vector< update_t > &smoothed_updates)
unsigned int locate(vector< double > &xx, double x)
jerror_t Smooth(DMatrix4x1 &Ss, DMatrix4x4 &Cs, deque< trajectory_t > &trajectory, vector< const DFDCPseudo * > &hits, vector< update_t >updates, vector< update_t > &smoothed_updates)
bool GetCDCEndplate(double &z, double &dz, double &rmin, double &rmax) const
printf("string=%s", string)
void UpdateWireOriginAndDir(unsigned int ring, unsigned int straw, DVector3 &origin, DVector3 &wdir)
jerror_t KalmanFilter(double anneal_factor, DMatrix4x1 &S, DMatrix4x4 &C, vector< const DFDCPseudo * > &hits, deque< trajectory_t > &trajectory, vector< update_t > &updates, double &chi2, unsigned int &ndof)
bool fdc_pseudo_cmp(const DFDCPseudo *a, const DFDCPseudo *b)