-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathSBSGEPEArm.cxx
1205 lines (938 loc) · 45.3 KB
/
SBSGEPEArm.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//////////////////////////////////////////////////////////////////////////
//
// Bare-bones SBB BigBite spectrometer class
// Used for testing.
//
//////////////////////////////////////////////////////////////////////////
#include "SBSGEPEArm.h"
#include "TList.h"
#include "SBSHCal.h"
#include "SBSGEMSpectrometerTracker.h"
#include "SBSGEMPolarimeterTracker.h"
#include "THaTrack.h"
#include "SBSRasteredBeam.h"
#include "THaTrackingDetector.h"
#include "TClass.h"
using namespace std;
ClassImp(SBSGEPEArm)
//_____________________________________________________________________________
SBSGEPEArm::SBSGEPEArm( const char* name, const char* description ) :
THaSpectrometer( name, description )
{
// Constructor. Defines standard detectors
//fOpticsOrder = -1; //default to zero for optics order. Not sure if this causes a seg fault, but safer.
SetPID( false );
// fFrontConstraintWidthX.clear();
// fFrontConstraintWidthY.clear();
// fFrontConstraintX0.clear();
// fFrontConstraintY0.clear();
// fBackConstraintWidthX.clear();
// fBackConstraintWidthY.clear();
// fBackConstraintX0.clear();
// fBackConstraintY0.clear();
// //Set default values for front and back constraint centers and widths:
// // the 0,1 indices are for front,back trackers for the polarimeter mode:
// double xwidth_front_default[2] = { 0.75, 1.0 }; //X dimension of front and back GEMs
// double xwidth_back_default[2] = { 2.0, 2.0 }; //a bit larger than ECAL size
// double ywidth_front_default[2] = {0.2, 0.3 }; //Y dimension of front and back GEMs
// double ywidth_back_default[2] = {1.0, 1.0}; //a bit larger than ECAL size
// for( int icp=0; icp<2; icp++ ){
// fFrontConstraintX0.push_back( 0.0 );
// fFrontConstraintY0.push_back( 0.0 );
// fBackConstraintX0.push_back( 0.0 );
// fBackConstraintY0.push_back( 0.0 );
// fFrontConstraintWidthX.push_back( xwidth_front_default[icp] );
// fFrontConstraintWidthY.push_back( ywidth_front_default[icp] );
// fBackConstraintWidthX.push_back( xwidth_back_default[icp] );
// fBackConstraintWidthY.push_back( ywidth_back_default[icp] );
// }
// fFrontConstraintWidthX = 1.5;
// fFrontConstraintWidthY = 1.5;
// fBackConstraintWidthX = 1.5;
// fBackConstraintWidthY = 1.5;
// fFrontConstraintX0 = 0.0;
// fFrontConstraintY0 = 0.0;
// fBackConstraintX0 = 0.0;
// fBackConstraintY0 = 0.0;
// fGEMorigin.SetXYZ(0,0,0);
// fGEM_Rtotal = TRotation();
fMagDist = 2.25; //This is a required parameter from ReadRunDatabase
fECALdist = 17.0; //default 17 m (GEN setting). But mandatory in readrundb
// fBdL = 1.58; // T*m (optional: calculate avg. proton deflection for pcentral)
// fOpticsAngle = 0.0;
// //Default to GEN-RP settings; in GEN-RP the first GEM plane is 4.105 m from the target for SBS magnet distance of 2.25 m
// // fOpticsOrigin.SetXYZ( 0.0, 0.0, fMagDist + 2.025 ); //In g4sbs, the front tracker first plane starts (by default) at 2.025 m downstream of the SBS magnet front face by default (actually I'm not sure that's still true).
// fOpticsOrigin.SetXYZ( 0.0, 0.0, fMagDist + 1.855 );
// InitOpticsAxes( fOpticsAngle );
// fGEMtheta = fOpticsAngle;
// fGEMphi = 0.0*TMath::DegToRad();
// fGEMorigin = fOpticsOrigin;
// // InitGEMAxes( fGEMtheta, fGEMphi, fGEMorigin );
// fGEMax = 0.0;
// fGEMay = 0.0;
// fGEMaz = 0.0;
// InitGEMAxes( fGEMax, fGEMay, fGEMaz );
// fPrecon_flag = 0;
// fFrontConstraintX.clear();
// fFrontConstraintY.clear();
// fFrontConstraintZ.clear();
// fBackConstraintX.clear();
// fBackConstraintY.clear();
// fBackConstraintZ.clear();
// fb_xptar.clear();
// fb_yptar.clear();
// fb_ytar.clear();
// fb_pinv.clear();
// f_oi.clear();
// f_oj.clear();
// f_ok.clear();
// f_ol.clear();
// f_om.clear();
// fb_xfp.clear();
// fb_yfp.clear();
// fb_xpfp.clear();
// fb_ypfp.clear();
// f_foi.clear();
// f_foj.clear();
// f_fok.clear();
// f_fol.clear();
// f_fom.clear();
// fPolarimeterMode = false; //if true, then we are using SBS with front and rear GEM trackers.
// fPolarimeterMode_DBoverride = false;
// fAnalyzerZ0 = 0.0;
// fUseDynamicConstraint = false;
}
//_____________________________________________________________________________
SBSGEPEArm::~SBSGEPEArm()
{
// Destructor
}
Int_t SBSGEPEArm::ReadRunDatabase( const TDatime &date ){
Int_t err = THaSpectrometer::ReadRunDatabase( date );
if( err ) return err;
FILE* file = OpenRunDBFile( date );
if( !file ) return kFileError;
//Require magdist:
const DBRequest req[] = {
//{ "magdist", &fMagDist, kDouble, 0, 0, 1 },
{ "ecaldist", &fECALdist, kDouble, 0, 0, 1 },
{ nullptr }
};
err = LoadDB( file, date, req );
fclose(file);
if( err )
return kInitError;
//fOpticsOrigin.SetXYZ( 0.0, 0.0, fMagDist + 2.025 );
return kOK;
}
void SBSGEPEArm::Clear( Option_t *opt )
{
THaSpectrometer::Clear(opt);
// fFrontConstraintX.clear();
// fFrontConstraintY.clear();
// fFrontConstraintZ.clear();
// fBackConstraintX.clear();
// fBackConstraintY.clear();
// fBackConstraintZ.clear();
}
Int_t SBSGEPEArm::ReadDatabase( const TDatime& date )
{
FILE* file = OpenFile( date );
if( !file ){
std::cerr << "SBSGEPEArm::ReadDatabase(): database not found!"<< std::endl;
return kFileError;
}
// std::vector<Double_t> firstgem_offset;
// std::vector<Double_t> gem_angles;
// std::vector<Double_t> optics_origin;
// std::vector<Double_t> optics_param;
// double gemthetadeg = fGEMtheta * TMath::RadToDeg();
// double gemphideg = fGEMphi * TMath::RadToDeg();
// double opticsthetadeg = fOpticsAngle * TMath::RadToDeg();
// int polarimetermode = fPolarimeterMode ? 1 : 0;
// int usedynamicconstraint = fUseDynamicConstraint ? 1 : 0;
// const DBRequest request[] = {
// { "frontconstraintwidth_x", &fFrontConstraintWidthX, kDoubleV, 0, 1, 0},
// { "frontconstraintwidth_y", &fFrontConstraintWidthY, kDoubleV, 0, 1, 0},
// { "backconstraintwidth_x", &fBackConstraintWidthX, kDoubleV, 0, 1, 0},
// { "backconstraintwidth_y", &fBackConstraintWidthY, kDoubleV, 0, 1, 0},
// { "frontconstraint_x0", &fFrontConstraintX0, kDoubleV, 0, 1, 0},
// { "frontconstraint_y0", &fFrontConstraintY0, kDoubleV, 0, 1, 0},
// { "backconstraint_x0", &fBackConstraintX0, kDoubleV, 0, 1, 0},
// { "backconstraint_y0", &fBackConstraintY0, kDoubleV, 0, 1, 0},
// { "gemorigin_xyz", &firstgem_offset, kDoubleV, 0, 1, 1},
// { "gemangles_xyz", &gem_angles, kDoubleV, 0, 1, 1},
// { "gemtheta", &gemthetadeg, kDouble, 0, 1, 1},
// { "gemphi", &gemphideg, kDouble, 0, 1, 1},
// { "opticstheta", &opticsthetadeg, kDouble, 0, 1, 1},
// { "optics_origin", &optics_origin, kDoubleV, 0, 1, 1},
// { "optics_order", &fOpticsOrder, kInt, 0, 1, 1},
// { "optics_parameters", &optics_param, kDoubleV, 0, 1, 1},
// { "preconflag", &fPrecon_flag, kUInt, 0, 1, 1 },
// { "polarimetermode", &polarimetermode, kInt, 0, 1, 1 },
// { "z0analyzer", &fAnalyzerZ0, kDouble, 0, 1, 1 },
// { "BdL", &fBdL, kDouble, 0, 1, 1 },
// { "usedynamicconstraint", &usedynamicconstraint, kInt, 0, 1, 1},
// { "dynamicthslope", &fDynamicConstraintSlopeX, kDouble, 0, 1, 1},
// { "dynamicth0", &fDynamicConstraintOffsetX, kDouble, 0, 1, 1},
// { "dynamicphslope", &fDynamicConstraintSlopeY, kDouble, 0, 1, 1},
// { "dynamicph0", &fDynamicConstraintOffsetY, kDouble, 0, 1, 1},
// {0}
// };
// Int_t status = LoadDB( file, date, request, fPrefix, 1 ); //The "1" after fPrefix means search up the tree
// fclose(file);
// if( status != 0 ){
// return status;
// }
// if( !fPolarimeterMode_DBoverride ){
// fPolarimeterMode = (polarimetermode != 0);
// }
// // std::cout << "SBSGEPEArm::ReadDatabase: polarimeter mode = " << fPolarimeterMode
// // << std::endl;
// //Once we parse the database, we need to check whether the constraint centering and width parameters
// //wered defined sensibly. This method checks, and if any are not sensibly initialized, ALL are
// //initialized with sensible default values:
// CheckConstraintOffsetsAndWidths();
// fUseDynamicConstraint = ( usedynamicconstraint != 0 );
// fOpticsAngle = opticsthetadeg * TMath::DegToRad();
// if( optics_origin.size() == 3 ){ //database overrides default values:
// fOpticsOrigin.SetXYZ( optics_origin[0],
// optics_origin[1],
// optics_origin[2] );
// }
// InitOpticsAxes( fOpticsAngle );
// fGEMtheta = gemthetadeg * TMath::DegToRad();
// fGEMphi = gemphideg * TMath::DegToRad();
// if( firstgem_offset.size() == 3 ){
// fGEMorigin.SetXYZ( firstgem_offset[0],
// firstgem_offset[1],
// firstgem_offset[2] );
// }
// InitGEMAxes( fGEMtheta, fGEMphi );
// //If GEM x,y,z angles are given, override the version based on theta, phi:
// if( gem_angles.size() == 3 ){
// //for( int i=0; i<3; i++ ){
// // gem_angles[i] *= TMath::DegToRad();
// //}
// fGEMax = gem_angles[0] * TMath::DegToRad();
// fGEMay = gem_angles[1] * TMath::DegToRad();
// fGEMaz = gem_angles[2] * TMath::DegToRad();
// InitGEMAxes( fGEMax, fGEMay, fGEMaz );
// }
// //Optics model initialization (copy of BigBite for now):
// if(fOpticsOrder>=0){
// unsigned int nterms = 0;
// for(int i = 0; i<=fOpticsOrder; i++){ //x
// for( int j=0; j<=fOpticsOrder-i; j++){ //y
// for( int k=0; k<=fOpticsOrder-i-j; k++){
// for( int l=0; l<=fOpticsOrder-i-j-k; l++){
// for( int m=0; m<=fOpticsOrder-i-j-k-l; m++ ){
// nterms++;
// }
// }
// }
// }
// }
// cout << nterms << " lines of parameters expected for optics of order " << fOpticsOrder << endl;
// //int n_elem = TMath::FloorNint(optics_param.size()/nparam);
// //we expect 9 parameters per line: four coefficients plus five exponents:
// unsigned int nparams = 9*nterms;
// if(nparams!=optics_param.size()){
// std::cerr << "Warning: mismatch between " << optics_param.size()
// << " optics parameters provided and " << nparams*9
// << " optics parameters expected!" << std::endl;
// std::cerr << " Fix database! " << std::endl;
// return kInitError;
// }
// //int o_i, o_j, o_k, o_l, o_m;// shall we use those???
// fb_xptar.resize(nterms);
// fb_yptar.resize(nterms);
// fb_ytar.resize(nterms);
// fb_pinv.resize(nterms);
// f_oi.resize(nterms);
// f_oj.resize(nterms);
// f_ok.resize(nterms);
// f_ol.resize(nterms);
// f_om.resize(nterms);
// for(unsigned int i=0; i<nterms; i++){
// fb_xptar[i] = optics_param[9*i];
// fb_yptar[i] = optics_param[9*i+1];
// fb_ytar[i] = optics_param[9*i+2];
// fb_pinv[i] = optics_param[9*i+3];
// f_om[i] = int(optics_param[9*i+4]);
// f_ol[i] = int(optics_param[9*i+5]);
// f_ok[i] = int(optics_param[9*i+6]);
// f_oj[i] = int(optics_param[9*i+7]);
// f_oi[i] = int(optics_param[9*i+8]);
// }
// }
fIsInit = true;
return kOK;
}
Int_t SBSGEPEArm::DefineVariables( EMode mode ){
THaSpectrometer::DefineVariables(mode);
if( mode == kDefine and fIsSetup ) return kOK;
fIsSetup = ( mode == kDefine );
// RVarDef constraintvars[] = {
// { "x_fcp", "front track constraint x", "fFrontConstraintX" },
// { "y_fcp", "front track constraint y", "fFrontConstraintY" },
// { "z_fcp", "front track constraint z", "fFrontConstraintZ" },
// { "x_bcp", "back track constraint x", "fBackConstraintX" },
// { "y_bcp", "back track constraint y", "fBackConstraintY" },
// { "z_bcp", "back track constraint z", "fBackConstraintZ" },
// { nullptr }
// };
// DefineVarsFromList( constraintvars, mode );
RVarDef ecalanglevars[] = {
{ "ECALth_n", "xECAL/ECALdist", "fECALtheta_n" },
{ "ECALph_n", "yECAL/ECALdist", "fECALphi_n" },
{ "ECALdir_x", "x component of ECAL unit vector", "fECALdir_x" },
{ "ECALdir_y", "y component of ECAL unit vector", "fECALdir_y" },
{ "ECALdir_z", "z component of ECAL unit vector", "fECALdir_z" },
{ nullptr }
};
DefineVarsFromList( ecalanglevars, mode );
return 0;
}
//_____________________________________________________________________________
Int_t SBSGEPEArm::FindVertices( TClonesArray &tracks )
{
// Reconstruct target coordinates for all tracks found.
// // TODO
// //std::cout << "SBSBigBite::FindVertices()...";
// // Reconstruct target coordinates for all tracks found.
// Int_t n_trk = tracks.GetLast()+1;
// for( Int_t t = 0; t < n_trk; t++ ) {
// auto* theTrack = static_cast<THaTrack*>( tracks.At(t) );
// CalcOpticsCoords(theTrack);
// if(fOpticsOrder>=0)CalcTargetCoords(theTrack);
// }
// if( GetNTracks() > 0 ) {
// // Select first track in the array. If there is more than one track
// // and track sorting is enabled, then this is the best fit track
// // (smallest chi2/ndof). Otherwise, it is the track with the best
// // geometrical match (smallest residuals) between the U/V clusters
// // in the upper and lower VDCs (old behavior).
// //
// // Chi2/dof is a well-defined quantity, and the track selected in this
// // way is immediately physically meaningful. The geometrical match
// // criterion is mathematically less well defined and not usually used
// // in track reconstruction. Hence, chi2 sorting is preferable, albeit
// // obviously slower.
// fGoldenTrack = static_cast<THaTrack*>( fTracks->At(0) );
// fTrkIfo = *fGoldenTrack;
// fTrk = fGoldenTrack;
// } else {
// fGoldenTrack = nullptr;
// }
return 0;
}
// void SBSGEPEArm::CalcOpticsCoords( THaTrack* track )
// {
// Double_t x_fp, y_fp, xp_fp, yp_fp;
// //Double_t px, py, pz;// NB: not the actual momentum!
// x_fp = track->GetX();
// y_fp = track->GetY();
// xp_fp = track->GetTheta();
// yp_fp = track->GetPhi();
// TVector3 TrackPosLocal_GEM( x_fp, y_fp, 0.0 );
// //std::cout << "calculating optics coordinates: (xfp,yfp,xpfp,ypfp)=(" << x_fp << ", " << y_fp << ", " << xp_fp << ", " << yp_fp << ")" << std::endl;
// TVector3 TrackPosGlobal_GEM = fGEMorigin + TrackPosLocal_GEM.X() * fGEMxaxis_global + TrackPosLocal_GEM.Y() * fGEMyaxis_global + TrackPosLocal_GEM.Z() * fGEMzaxis_global;
// //std::cout << "Track pos global = " << endl;
// //TrackPosGlobal_GEM.Print();
// TVector3 TrackDirLocal_GEM( xp_fp, yp_fp, 1.0 );
// TrackDirLocal_GEM = TrackDirLocal_GEM.Unit();
// // std::cout << "Track direction local = " << endl;
// // TrackDirLocal_GEM.Print();
// //TVector3 TrackDirGlobal_GEM = TrackDirLocal_GEM.X() * fGEMxaxis_global + TrackDirLocal_GEM.Y() * fGEMyaxis_global + TrackDirLocal_GEM.Z() * fGEMzaxis_global;
// //TrackDirGlobal_GEM = TrackDirGlobal_GEM.Unit(); //Likely unnecessary, but safer (I guess)
// TVector3 TrackDirGlobal_GEM = fGEM_Rinverse * TrackDirLocal_GEM;
// // std::cout << "Track direction global = " << endl;
// //TrackDirGlobal_GEM.Print();
// //Now project track to the z = 0 plane of the ideal optics system:
// // recall the formula to intersect a ray with a plane:
// // (x + s * trackdir - x0) dot planedir = 0.0
// double sintersect = (fOpticsOrigin - TrackPosGlobal_GEM).Dot(fOpticsZaxis_global)/ (TrackDirGlobal_GEM.Dot( fOpticsZaxis_global ) );
// TVector3 TrackIntersect_global = TrackPosGlobal_GEM + sintersect * TrackDirGlobal_GEM;
// // std::cout << "Track intersection point, global = " << endl;
// //TrackIntersect_global.Print();
// //rather than modifying the x, y, theta, phi directly, let's use the RX, RY, RTheta, and RPhi coordinates:
// //TVector3 TrackIntersect_ = TrackIntersect_global - fOpticsOrigin;
// double xoptics = (TrackIntersect_global - fOpticsOrigin).Dot( fOpticsXaxis_global );
// double yoptics = (TrackIntersect_global - fOpticsOrigin).Dot( fOpticsYaxis_global );
// double xpoptics = TrackDirGlobal_GEM.Dot( fOpticsXaxis_global )/TrackDirGlobal_GEM.Dot( fOpticsZaxis_global );
// double ypoptics = TrackDirGlobal_GEM.Dot( fOpticsYaxis_global )/TrackDirGlobal_GEM.Dot( fOpticsZaxis_global );
// //std::cout << "GEM origin = " << std::endl;
// //fGEMorigin.Print();
// //std::cout << "Optics origin = " << std::endl;
// //fOpticsOrigin.Print();
// //std::cout << "GEM z axis global = " << std::endl;
// //fGEMzaxis_global.Print();
// //std::cout << "Optics z axis global = " << std::endl;
// //fOpticsZaxis_global.Print();
// //std::cout << "GEM (x,y,xp,yp) = " << x_fp << ", " << y_fp << ", " << xp_fp << ", " << yp_fp << std::endl;
// // std::cout << "Optics (x,y,xp,yp) = " << xoptics << ", " << yoptics << ", " << xpoptics << ", " << ypoptics << endl;
// track->SetR( xoptics, yoptics, xpoptics, ypoptics );
// //The following line is no longer necessary as we are using the "Rotated TRANSPORT coordinates" to store the track parameters in ideal optics system
// //track->Set(x_fp, y_fp, xp_fp, yp_fp);
// }
// void SBSGEPEArm::CalcTargetCoords( THaTrack* track )
// {
// //std::cout << "SBSBigBite::CalcTargetCoords()...";
// //const double //make it configurable
// const double th_sbs = GetThetaGeo();//retrieve the actual angle
// //th_sbs < 0 for beam right... this makes SBS_zaxis along -x
// TVector3 SBS_zaxis( sin(th_sbs), 0, cos(th_sbs) );
// TVector3 SBS_xaxis(0,-1,0);
// TVector3 SBS_yaxis = (SBS_zaxis.Cross(SBS_xaxis)).Unit();
// TVector3 spec_xaxis_fp,spec_yaxis_fp, spec_zaxis_fp;
// TVector3 spec_xaxis_tgt,spec_yaxis_tgt, spec_zaxis_tgt;
// spec_xaxis_tgt = SBS_xaxis;
// spec_yaxis_tgt = SBS_yaxis;
// spec_zaxis_tgt = SBS_zaxis;
// spec_zaxis_fp = SBS_zaxis;
// spec_yaxis_fp = SBS_yaxis;
// spec_zaxis_fp.Rotate(-fOpticsAngle, spec_yaxis_fp);
// spec_xaxis_fp = spec_yaxis_fp.Cross(spec_zaxis_fp).Unit();
// Double_t x_fp, y_fp, xp_fp, yp_fp;
// //if( fCoordType == kTransport ) {
// if( track->HasRot() ){
// // std::cout << "using rotated track coordinates for optics: " << endl;
// x_fp = track->GetRX();
// y_fp = track->GetRY();
// xp_fp = track->GetRTheta();
// yp_fp = track->GetRPhi();
// } else {
// //std::cout << "using non-rotated track coordinates for optics: " << endl;
// x_fp = track->GetX();
// y_fp = track->GetY();
// xp_fp = track->GetTheta();
// yp_fp = track->GetPhi();
// }
// //}
// //cout << x_fp << " " << y_fp << " " << xp_fp << " " << yp_fp << endl;
// double /*vx, vy, vz, */px, py, pz;
// double p_fit, xptar_fit, yptar_fit, ytar_fit, xtar;
// xtar = 0.0;
// double thetabend_fit;
// double pthetabend_fit;
// double vz_fit;
// xptar_fit = 0.0;
// yptar_fit = 0.0;
// ytar_fit = 0.0;
// pthetabend_fit = 0.0;
// int ipar = 0;
// for(int i=0; i<=fOpticsOrder; i++){
// for(int j=0; j<=fOpticsOrder-i; j++){
// for(int k=0; k<=fOpticsOrder-i-j; k++){
// for(int l=0; l<=fOpticsOrder-i-j-k; l++){
// for(int m=0; m<=fOpticsOrder-i-j-k-l; m++){
// double term = pow(x_fp,m)*pow(y_fp,l)*pow(xp_fp,k)*pow(yp_fp,j)*pow(xtar,i);
// xptar_fit += fb_xptar[ipar]*term;
// yptar_fit += fb_yptar[ipar]*term;
// ytar_fit += fb_ytar[ipar]*term;
// pthetabend_fit += fb_pinv[ipar]*term;
// //pinv_fit += b_pinv(ipar)*term;
// // cout << ipar << " " << term << " "
// // << b_xptar(ipar) << " " << b_yptar(ipar) << " "
// // << b_ytar(ipar) << " " << b_pinv(ipar) << endl;
// ipar++;
// }
// }
// }
// }
// }
// TVector3 phat_tgt_fit(xptar_fit, yptar_fit, 1.0 );
// phat_tgt_fit = phat_tgt_fit.Unit();
// TVector3 phat_fp(xp_fp, yp_fp, 1.0 );
// phat_fp = phat_fp.Unit();
// TVector3 phat_fp_rot = phat_fp.X() * fOpticsXaxis_global +
// phat_fp.Y() * fOpticsYaxis_global +
// phat_fp.Z() * fOpticsZaxis_global;
// thetabend_fit = acos( phat_fp_rot.Dot( phat_tgt_fit ) );
// // TVector3 phat_tgt_fit_global = phat_tgt_fit.X() * spec_xaxis_tgt +
// // phat_tgt_fit.Y() * spec_yaxis_tgt +
// // phat_tgt_fit.Z() * spec_zaxis_tgt;
// // TVector3 phat_fp_fit(xp_fp, yp_fp, 1.0 );
// // phat_fp_fit = phat_fp_fit.Unit();
// // TVector3 phat_fp_fit_global = phat_fp_fit.X() * spec_xaxis_fp +
// // phat_fp_fit.Y() * spec_yaxis_fp +
// // phat_fp_fit.Z() * spec_zaxis_fp;
// //thetabend_fit = acos( phat_fp_fit_global.Dot( phat_tgt_fit_global ) );
// //if( fPrecon_flag != 1 ){
// p_fit = pthetabend_fit/thetabend_fit;
// //} else {
// //double delta = pthetabend_fit;
// //double p_firstorder = fA_pth1 * ( 1.0 + (fB_pth1 + fC_pth1*fMagDist)*xptar_fit ) / thetabend_fit;
// //p_fit = p_firstorder * (1.0 + delta);
// //}
// //For SBS, which is on beam right, we have ytar = vz * sin(|theta|) - yptar * vz * cos(theta)
// // i.e., ytar = vz * ( sin(|theta|) - yptar * cos(theta) )
// // --> vz = ytar/(sin(|theta|) - yptar * cos(theta) )
// // But this is the same thing as -ytar/(sin(-|theta|) + yptar * cos(theta))
// // So ASSUMING th_sbs < 0 for beam right, the formula below can be used unchanged:
// vz_fit = -ytar_fit / (sin(th_sbs) + cos(th_sbs)*yptar_fit);
// pz = p_fit*sqrt( 1.0/(xptar_fit*xptar_fit+yptar_fit*yptar_fit+1.) );
// px = xptar_fit * pz;
// py = yptar_fit * pz;
// TVector3 pvect_SBS = TVector3(px, py, pz);
// //In SBS transport coordinates, py is toward small angles, px is vertically down (toward the floor), pz is along spectrometer central axis. To translate to HALL coordinates, we have:
// // x to beam left, y vertically up, and z along the beam direction:
// //since th_sbs < 0 for beam right, the formula below can be used unchanged (I think):
// px = +pvect_SBS.Z()*sin(th_sbs)+pvect_SBS.Y()*cos(th_sbs);
// py = -pvect_SBS.X();
// pz = pvect_SBS.Z()*cos(th_sbs)-pvect_SBS.Y()*sin(th_sbs);
// //We should move this to before the optics calculations in case we want to actually correct the optics for the beam position:
// double ybeam=0.0,xbeam=0.0;
// //retrieve beam position, if available, to calculate xtar.
// TIter aiter(gHaApps);
// THaApparatus* app = 0;
// while( (app=(THaApparatus*)aiter()) ){
// if(app->InheritsFrom("SBSRasteredBeam")){
// SBSRasteredBeam* RasterBeam = reinterpret_cast<SBSRasteredBeam*>(app);
// //double xbeam = RasterBeam->GetPosition().X();
// ybeam = RasterBeam->GetPosition().Y()/1000.0; //if this is given in mm, we need to convert to meters (also for BB)
// xbeam = RasterBeam->GetPosition().X()/1000.0;
// xtar = - ybeam - cos(GetThetaGeo()) * vz_fit * xptar_fit;
// }
// //cout << var->GetName() << endl;
// }
// // f_xtg_exp.push_back(xtar);
// track->SetTarget(xtar, ytar_fit, xptar_fit, yptar_fit);
// track->SetMomentum(p_fit);
// track->SetPvect(TVector3(px, py, pz));
// track->SetVertex(TVector3(xbeam, ybeam, vz_fit));
// //cout << px << " " << py << " " << pz << " " << vz_fit << endl;
// //cout << track->GetLabPx() << " " << track->GetLabPy() << " " << track->GetLabPz()
// // << " " << track->GetVertexZ() << endl;
// //std::cout << "Done." << std::endl;
// }
//_____________________________________________________________________________
Int_t SBSGEPEArm::TrackCalc()
{
// Additioal track calculations
// TODO
return 0;
}
//_____________________________________________________________________________
Int_t SBSGEPEArm::CoarseTrack()
{
// Coarse track Reconstruction
// std::cout << " SBSGEPEArm::CoarseTrack()..." << std::endl;
// if( !fTrackingDetectors ) {
// cerr << "fTrackingDetectors == NULL?" << endl;
// exit(1);
// }
// cout << fTrackingDetectors->IsA()->GetName() << endl;
// fTrackingDetectors->Print();
// std::cout << " fTrackingDetectors->Print() invoked..." << std::endl;
THaSpectrometer::CoarseTrack();
// TODO
//std::cout << " call SBSBigBite::CoarseTrack" << std::endl;
//std::cout << "done" << std::endl;
return 0;
}
Int_t SBSGEPEArm::CoarseReconstruct()
{
// std::cout << "SBSArm::CoarseReconstruct(): polarimeter mode = "
// << fPolarimeterMode << std::endl;
fECALtheta_n = kBig;
fECALphi_n = kBig;
fECALdir_x = kBig;
fECALdir_y = kBig;
fECALdir_z = kBig;
THaSpectrometer::CoarseReconstruct();
// Double_t x_fcp = 0, y_fcp = 0, z_fcp = 0;
// Double_t x_bcp = 0, y_bcp = 0, z_bcp = 0;
// TIter next( fNonTrackingDetectors );
// //Loop on non-tracking detectors and grab pointers to ECAL and PolarimeterTracker (if it exists):
// SBSCalorimeter *ECal = nullptr;
// // SBSGEMPolarimeterTracker *BackTracker = nullptr;
// // //Loop on tracking detectors and grab pointer to SBSGEMSpectrometerTracker (if it exists):
// // SBSGEMSpectrometerTracker *FrontTracker = nullptr;
// while( auto* theNonTrackDetector =
// static_cast<THaNonTrackingDetector*>( next() )) {
// if(theNonTrackDetector->InheritsFrom("SBSCalorimeter")){
// ECal = reinterpret_cast<SBSCalorimeter*>(theNonTrackDetector);
// }
// // if(theNonTrackDetector->InheritsFrom("SBSGEMPolarimeterTracker")){
// // BackTracker = reinterpret_cast<SBSGEMPolarimeterTracker*>(theNonTrackDetector);
// // }
// }
// // TIter next2( fTrackingDetectors );
// // while( auto* theTrackDetector =
// // static_cast<THaTrackingDetector*>( next2() )) {
// // if(theTrackDetector->InheritsFrom("SBSGEMSpectrometerTracker")){
// // FrontTracker = reinterpret_cast<SBSGEMSpectrometerTracker*>(theTrackDetector);
// // // std::cout << "Got front tracker, name = " << FrontTracker->GetName()
// // // << std::endl;
// // }
// // }
// if(ECal->GetNclust() == 0 || ECal == nullptr) return 0; //If no ECAL clusters, we don't attempt tracking
// std::vector<SBSCalorimeterCluster*> ECalClusters = ECal->GetClusters();
// int i_max = 0;
// double E_max = 0;
// for(unsigned int i = 0; i<ECalClusters.size(); i++){
// if(ECalClusters[i]->GetE() > E_max){
// i_max = i;
// E_max = ECalClusters[i]->GetE();
// }
// }
// x_bcp = ECalClusters[i_max]->GetX() + ECal->GetOrigin().X();
// y_bcp = ECalClusters[i_max]->GetY() + ECal->GetOrigin().Y();
// z_bcp = ECal->GetOrigin().Z();
// fECALtheta_n = ECalClusters[i_max]->GetX()/fECALdist;
// fECALphi_n = ECalClusters[i_max]->GetY()/fECALdist;
// TVector3 ECALdir_global;
// TransportToLab( 1.0, fECALtheta_n, fECALphi_n, ECALdir_global );
// fECALdir_x = ECALdir_global.X();
// fECALdir_y = ECALdir_global.Y();
// fECALdir_z = ECALdir_global.Z();
//x_fcp = fGEMorigin.X();
//y_fcp = fGEMorigin.Y();
//z_fcp = fGEMorigin.Z();
// x_fcp = 0.0;
// y_fcp = 0.0;
// z_fcp = 0.0;
//Set constraint points for FT and BT, regardless
//whether those detectors are actually using the constraints:
// if( !fPolarimeterMode && FrontTracker != nullptr ){
// //std::cout << "setting constraints for tracks" << std::endl;
// FrontTracker->SetBackConstraintPoint(x_bcp + fBackConstraintX0[0], y_bcp + fBackConstraintY0[0], z_bcp);
// if ( fUseDynamicConstraint ){
// double thcp = fDynamicConstraintSlopeX * (x_bcp + fBackConstraintX0[0]) + fDynamicConstraintOffsetX;
// double phcp = fDynamicConstraintSlopeY * (y_bcp + fBackConstraintY0[0]) + fDynamicConstraintOffsetY;
// x_fcp = x_bcp + thcp * (z_fcp - z_bcp);
// y_fcp = y_bcp + phcp * (z_fcp - z_bcp);
// }
// FrontTracker->SetFrontConstraintPoint(x_fcp + fFrontConstraintX0[0], y_fcp + fFrontConstraintY0[0], z_fcp);
// FrontTracker->SetFrontConstraintWidth(fFrontConstraintWidthX[0],
// fFrontConstraintWidthY[0]);
// FrontTracker->SetBackConstraintWidth(fBackConstraintWidthX[0],
// fBackConstraintWidthY[0]);
// if( BackTracker != nullptr ){
// // IF there is a back tracker, and we're not using polarimeter mode,
// // initialize it with identical constraints as the front:
// BackTracker->SetBackConstraintPoint(x_bcp + fBackConstraintX0[0], y_bcp + fBackConstraintY0[0], z_bcp);
// BackTracker->SetFrontConstraintPoint(x_fcp + fFrontConstraintX0[0], y_fcp + fFrontConstraintY0[0], z_fcp);
// BackTracker->SetFrontConstraintWidth(fFrontConstraintWidthX[0],
// fFrontConstraintWidthY[0]);
// BackTracker->SetBackConstraintWidth(fBackConstraintWidthX[0],
// fBackConstraintWidthY[0]);
// }
// } else if( fPolarimeterMode && BackTracker != nullptr ){ //Polarimeter mode: look for NonTrackingDetectors inheriting SBSGEMPolarimeterTracker
// z_fcp = fAnalyzerZ0;
// BackTracker->SetBackConstraintPoint( x_bcp + fBackConstraintX0[1], y_bcp + fBackConstraintY0[1], z_bcp);
// if ( fUseDynamicConstraint ){
// double thcp = fDynamicConstraintSlopeX * (x_bcp + fBackConstraintX0[1]) + fDynamicConstraintOffsetX;
// double phcp = fDynamicConstraintSlopeY * (y_bcp + fBackConstraintY0[1]) + fDynamicConstraintOffsetY;
// x_fcp = x_bcp + thcp * (z_fcp - z_bcp);
// y_fcp = y_bcp + phcp * (z_fcp - z_bcp);
// }
// BackTracker->SetFrontConstraintPoint( x_fcp + fFrontConstraintX0[1], y_fcp + fFrontConstraintY0[1], z_fcp);
// BackTracker->SetFrontConstraintWidth( fFrontConstraintWidthX[1],
// fFrontConstraintWidthY[1] );
// BackTracker->SetBackConstraintWidth( fBackConstraintWidthX[1],
// fBackConstraintWidthY[1] );
// //We can envision a scenario in which we get to this point and the
// //front tracking is already done, for example, if the front tracking is
// // done without constraints and was already done in SBSGEPEArm::CoarseTrack, but the
// // back tracking is to be done WITH constraints
// // In that case, we actually want to set the back tracking constraints based on
// // the FRONT tracking results:
// if( FrontTracker != nullptr ){
// //std::cout << "N front tracks = " << FrontTracker->GetNtracks() << std::endl;
// if( FrontTracker->GetNtracks() > 0 ){
// BackTracker->SetFrontTrack( FrontTracker->GetXTrack( 0 ),
// FrontTracker->GetYTrack( 0 ),
// FrontTracker->GetXpTrack( 0 ),
// FrontTracker->GetYpTrack( 0 ) );
// //Additionally set front constraint point for back tracker based on projection to analyzer (in this context z_fcp = fAnalyzerZ0):
// // If this context is relevant; e.g., front tracking done without constraints
// // and back tracking done with constraints, then
// // the front constraint width should have also been sensibly defined via the DB:
// x_fcp = FrontTracker->GetXTrack(0) + z_fcp * FrontTracker->GetXpTrack(0);
// y_fcp = FrontTracker->GetYTrack(0) + z_fcp * FrontTracker->GetYpTrack(0);
// BackTracker->SetFrontConstraintPoint( x_fcp + fFrontConstraintX0[1], y_fcp + fFrontConstraintY0[1], z_fcp );
// }
// }
// } //End if (!Polarimeter mode )
// fFrontConstraintX.push_back( x_fcp );
// fFrontConstraintY.push_back( y_fcp );
// fFrontConstraintZ.push_back( z_fcp );
// fBackConstraintX.push_back( x_bcp );
// fBackConstraintY.push_back( y_bcp );
// fBackConstraintZ.push_back( z_bcp );
return 0;
}
//_____________________________________________________________________________
Int_t SBSGEPEArm::Track()
{
// //std::cout << "SBSGEPEArm::Track(): polarimeter mode = " << fPolarimeterMode << std::endl;
// // Fine track Reconstruction
// if( !fPolarimeterMode ){ //Call regular spectrometer Track() method
// THaSpectrometer::Track();
// } else { //Polarimeter mode: Do back tracker tracking first:
// //Grab pointer to back tracker, do tracking there, then initialize front tracker constraints, and do tracking there too:
// if( !IsDone(kCoarseRecon) )
// CoarseReconstruct();
// // std::cout << "Number of tracking detectors assigned to this GEPEArm = "
// // << fTrackingDetectors->GetSize() << std::endl;
// SBSGEMSpectrometerTracker *FrontTracker = nullptr;
// TIter next2( fTrackingDetectors );
// while( auto* theTrackDetector =
// static_cast<THaTrackingDetector*>( next2() )) {
// assert(dynamic_cast<THaTrackingDetector*>(theTrackDetector));
// // std::cout << "Got tracking detector, name = "
// // << theTrackDetector->GetName() << std::endl;
// if(theTrackDetector->InheritsFrom("SBSGEMSpectrometerTracker")){
// FrontTracker = reinterpret_cast<SBSGEMSpectrometerTracker*>(theTrackDetector);
// //std::cout << "Got Front tracker, name = " << FrontTracker->GetName() << std::endl;
// }
// }
// SBSGEMPolarimeterTracker *BackTracker = nullptr;
// TIter next(fNonTrackingDetectors);
// while( auto* theNonTrackDetector =
// static_cast<THaNonTrackingDetector*>( next() )) {
// assert(dynamic_cast<THaNonTrackingDetector*>(theNonTrackDetector));
// #ifdef WITH_DEBUG
// if( fDebug>1 ) cout << "Call FineProcess() for "
// << theNonTrackDetector->GetName() << "... ";
// #endif
// //only call fine process if this non-tracking detector is the back tracker:
// if( theNonTrackDetector->InheritsFrom("SBSGEMPolarimeterTracker")){
// //If the back tracker is set to use the constraints, then this
// //will initiate tracking.
// //Otherwise, it does nothing:
// theNonTrackDetector->FineProcess( *fTracks );
// //grab pointer to Back Tracker for initialization of front tracking:
// BackTracker = reinterpret_cast<SBSGEMPolarimeterTracker*>(theNonTrackDetector);
// }
// }
// //Only attempt tracking in FT if we got a track in back tracker:
// if( BackTracker != nullptr && FrontTracker != nullptr ){ //Use the back tracker to initialize constraints for front tracker:
// // std::cout << "Back tracker n tracks found = " << BackTracker->GetNtracks()
// // << std::endl;
// if( BackTracker->GetNtracks() > 0 ){
// //Initially, let's set up a front constraint using only the "best" (first) track found in the back tracker
// //Later, we may consider multiple tracks pointing to multiple clusters in ECAL:
// // std::cout << "Back tracker has tracks, initializing front tracker: "
// // << std::endl;
// double xback = BackTracker->GetXTrack( 0 );
// double yback = BackTracker->GetYTrack( 0 );
// double xpback = BackTracker->GetXpTrack( 0 );
// double ypback = BackTracker->GetYpTrack( 0 );
// double x_bcp = xback + xpback * fAnalyzerZ0;
// double y_bcp = yback + ypback * fAnalyzerZ0;
// // std::cout << "(xbcp,ybcp,zbcp)=(" << x_bcp << ", " << y_bcp
// // << ", " << fAnalyzerZ0 << ")" << std::endl;
// FrontTracker->SetBackConstraintPoint( x_bcp + fBackConstraintX0[0], y_bcp + fBackConstraintY0[0], fAnalyzerZ0 );
// //Set front constraint point to position of back track at front layer:
// double x_fcp = xback;
// double y_fcp = yback;
// FrontTracker->SetFrontConstraintPoint( x_fcp + fFrontConstraintX0[0], y_fcp + fFrontConstraintY0[0], 0.0 );
// // std::cout << "(xfcp,yfcp,zfcp)=(" << x_fcp << ", " << y_fcp << ",0)"
// // << std::endl;
// FrontTracker->SetBackConstraintWidth( fBackConstraintWidthX[0], fBackConstraintWidthY[0] );
// FrontTracker->SetFrontConstraintWidth( fFrontConstraintWidthX[0], fFrontConstraintWidthY[0] );
// //NOTE: if constraints aren't being used by the front tracker,
// //then the following line has no effect (as intended!)
// FrontTracker->FineTrack( *fTracks );
// if( FrontTracker->GetNtracks() > 0 ){
// //If we found a front track, then set the "front track" for the back tracker
// //for the purpose of scattering angle/closest-approach reconstruction:
// BackTracker->SetFrontTrack( FrontTracker->GetXTrack( 0 ),
// FrontTracker->GetYTrack( 0 ),
// FrontTracker->GetXpTrack( 0 ),
// FrontTracker->GetYpTrack( 0 ) );
// // Technically, we could also call BackTracker->CalcScatteringParameters here,
// // But given the current structure of the SBSGEPEArm code, it is unnecessary
// // since BackTracker->FineProcess will get called again in SBSGEPEArm::Reconstruct();
// }
// }
// }
// // Don't forget to call FindVertices regardless! This is NOT done automatically
// // in the polarimeter mode, for which we override the standard
// // THaSpectrometer::Track();
// // Reconstruct tracks to target/vertex
// // This usually also determines the track momentum
// FindVertices( *fTracks );
// } //end check for "polarimeter mode"
// fStagesDone |= kTracking;
return 0;
}
//_____________________________________________________________________________
Int_t SBSGEPEArm::Reconstruct()
{
// Fine Reconstruction of particles in spectrometer
//std::cout << "SBSBigBite::Reconstruct()..." << std::endl;
THaSpectrometer::Reconstruct();
//Note that the call to THaSpectrometer::Reconstruct() above can lead
//to a SECOND call to SBSGEMPolarimeter::FineProcess for the back tracker
// If we are in the polarimeter mode, we know at this stage that
// back tracking and front tracking are DONE.
// If we're just considering recoil proton polarimetry, then