forked from JeffersonLab/SBS-offline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SBSBigBite.cxx
1787 lines (1474 loc) · 68.4 KB
/
SBSBigBite.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 "SBSBigBite.h"
#include "THaTrack.h"
#include "THaPIDinfo.h"
#include "TList.h"
#include "SBSBBShower.h"
#include "SBSBBTotalShower.h"
#include "SBSTimingHodoscope.h"
#include "SBSGRINCH.h"
#include "SBSGEMSpectrometerTracker.h"
#include "SBSRasteredBeam.h"
#include "THaTrackingDetector.h"
#include "TH2D.h"
using namespace std;
ClassImp(SBSBigBite)
//_____________________________________________________________________________
SBSBigBite::SBSBigBite( const char* name, const char* description ) :
THaSpectrometer( name, description )
{
SetMultiTracks(false);
SetTrSorting(false);
//fTrackerPitchAngle = 10.0;
//fDetectorStackYaw = 0;
//fDetectorStackRoll = 0;
fOpticsOrder = -1;
fFrontConstraintWidthX = 1.5;
fFrontConstraintWidthY = 1.5;
fBackConstraintWidthX = 1.5;
fBackConstraintWidthY = 1.5;
fFrontConstraintX0 = 0.0;
fFrontConstraintY0 = 0.0;
fBackConstraintX0 = 0.0;
fBackConstraintY0 = 0.0;
fTrackGrinchClusCorr_0 = 0.0;
fTrackGrinchClusCorr_1 = 0.0;
fTrackGrinchClusCorr_Sigma = 1.5;
fPtheta_00000 = 0.0;
fPtheta_10000 = 0.0;
fPtheta_00100 = 0.0;
fXptar_10000 = 0.0;
fXptar_00100 = 0.0;
fYtar_01000 = 0.0;
fYtar_00010 = 0.0;
fECaloFudgeFactor = 1.0;
//Default ideal optics angle (central bend angle) to 10 deg:
//This should match the g4sbs simulation coordinate system, and user should not ordinarily need to modify:
//This is relative to target center along spectrometer axis:
fMagDist = 1.80; //this will eventually be overridden by the DB, and will become a required parameter for BigBite
fOpticsAngle = 10.0*TMath::DegToRad();
fOpticsOrigin.SetXYZ( -0.1701, 0.0, 1.1087 + fMagDist );
InitOpticsAxes( fOpticsAngle );
//These will be the real GEM coordinates from the zero-field alignment:
//Default these to match the simulation coordinate system:
fGEMtheta = fOpticsAngle;
fGEMphi = 180.0*TMath::DegToRad();
fGEMorigin = fOpticsOrigin;
InitGEMAxes( fGEMtheta, fGEMphi, fGEMorigin );
// Define our own PID parameters (undo what THaSpectrometer has set up)
SBSBigBite::DefinePidParticles();
// Enable PID calculations (call CalcPID)
SetPID(true);
fDownBendingMode = false;
//Default
fPrecon_flag = 0;
fA_pth1 = 0.28615 * 0.97;
fB_pth1 = 0.1976;
fC_pth1 = 0.4764;
fA_vy = 0.;
fB_vy = 0.;
fUseBeamPosInOptics = false;
fIsMC = false;
//Default to block size/sqrt(12) for shower and preshower:
fSigmaX_shower = 0.085/sqrt(12.0); //2.45 cm
fSigmaY_shower = 0.085/sqrt(12.0);
fSigmaX_preshower = 0.09/sqrt(12.0); //2.6 cm
fSigmaY_preshower = 0.37/sqrt(12.0); //10.7 cm
//The hodoscope position resolutions are based on a fit of the hodo-track differences along X and Y:
//NOTE: for X it is worse than bar size over sqrt(12), presumably the averaging of several bars does NOT improve the vertical position resolution of the hodoscope much
// for Y it is based on the timing resolution
fSigmaX_hodo = 0.021;
fSigmaY_hodo = 0.041;
// Constructor. Defines standard detectors
//The standard BigBite detector package in the 12 GeV/SBS era will include:
// pre-shower + shower calorimeters (inherit from THaNonTrackingDetector OR THaPidDetector)
// Timing hodoscope (inherit from THaNonTrackingDetector)
// GRINCH (inherit from THaPidDetector)
// GEMs (five-layer) (inherit from THaTrackingDetector)
/*
h1_yVx_bcp = new TH2D("h1_yVx_bcp", ";x_{bcp} (m);y_{bcp} (m)", 300, -1.5, 1.5, 100, -0.5, 0.5);
h1_x_fcpVbcp = new TH2D("h1_x_fcpVbcp", ";x_{bcp} (m);x_{fcp} (m)", 300, -1.5, 1.5, 300, -1.5, 1.5);
h1_yVx_fcp = new TH2D("h1_yVx_fcp", ";x_{fcp} (m);y_{fcp} (m)", 300, -1.5, 1.5, 100, -0.5, 0.5);
h1_y_fcpVbcp = new TH2D("h1_y_fcpVbcp", ";y_{bcp} (m);y_{fcp} (m)", 100, -0.5, 0.5, 100, -0.5, 0.5);
h1_dyVdx = new TH2D("h1_dyVdx",";dx/dz;dy/dz", 100, -0.5, 0.5, 50, -0.25, 0.25);
*/
fUseForwardOptics = false;
fForwardOpticsOrder = -1;
}
//_____________________________________________________________________________
SBSBigBite::~SBSBigBite()
{
// Destructor
}
void SBSBigBite::Clear( Option_t *opt )
{
THaSpectrometer::Clear(opt);
// f_xtg_exp.clear();
fEpsEtotRatio.clear();
fEtot.clear();
fEtotPratio.clear();
fEpsEtotRatio.clear();
fFrontConstraintX.clear();
fFrontConstraintY.clear();
fFrontConstraintZ.clear();
fBackConstraintX.clear();
fBackConstraintY.clear();
fBackConstraintZ.clear();
fProbaE.clear();
fProbaPi.clear();
}
//_____________________________________________________________________________
void SBSBigBite::DefinePidParticles()
{
// Define the default set of PID particles:
// electron, pion
fPidParticles->Delete(); //make sure array is empty
AddPidParticle( "e", "electron", 0.511e-3, -1 );
AddPidParticle( "pi", "pion", 0.139, -1 );
}
//_____________________________________________________________________________
Int_t SBSBigBite::ReadRunDatabase( const TDatime &date ){
//const char* const here = "SBSBigBite::ReadRunDatabase()";
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 },
{ nullptr }
};
err = LoadDB( file, date, req );
fclose(file);
if( err )
return kInitError;
fOpticsOrigin.SetXYZ( -0.1701, 0.0, 1.1087+fMagDist );
//Default GEM origin to the same as optics origin; this will be overridden by ReadDatabase
fGEMorigin = fOpticsOrigin;
return kOK;
}
//_____________________________________________________________________________
Int_t SBSBigBite::ReadDatabase( const TDatime& date )
{
// Hack from THaVDC::ReadDatabase()
const char* const here = "SBSBigBite::ReadDatabase()";
//THaSpectrometer::ReadRunDatabase();
FILE* file = OpenFile( date );
if( !file ){
std::cerr << here << "(): database not found!"<< std::endl;
return kFileError;
}
int pidflag = fPID ? 1 : 0;
int downbend = fDownBendingMode ? 1 : 0;
std::vector<Double_t> firstgem_offset;
std::vector<Double_t> optics_param;
std::vector<Double_t> foptics_param;
std::vector<Double_t> doptics_param; //down bending optics
std::vector<Double_t> pssh_pidproba;
std::vector<Double_t> pcal_pidproba;
std::vector<Double_t> grinch_pidproba;
std::vector<Double_t> optics_origin;
double gemthetadeg = fGEMtheta * TMath::RadToDeg();
double gemphideg = fGEMphi * TMath::RadToDeg();
double opticsthetadeg = fOpticsAngle * TMath::RadToDeg();
int mc_flag = fIsMC ? 1 : 0;
int use_beampos = fUseBeamPosInOptics ? 1 : 0;
const DBRequest request[] = {
{ "gemtheta", &gemthetadeg, kDouble, 0, 1, 1},
{ "gemphi", &gemphideg, kDouble, 0, 1, 1},
{ "gemorigin_xyz", &firstgem_offset, kDoubleV, 0, 1, 1},
{ "opticstheta", &opticsthetadeg, kDouble, 0, 1, 1},
{ "optics_origin", &optics_origin, kDoubleV, 0, 1, 1},
{ "optics_order", &fOpticsOrder, kUInt, 0, 1, 1},
{ "optics_parameters", &optics_param, kDoubleV, 0, 1, 1},
{ "ecalo_fudgefactor", &fECaloFudgeFactor, kDouble, 0, 1, 1},
{ "do_pid", &pidflag, kInt, 0, 1, 1},
{ "frontconstraintwidth_x", &fFrontConstraintWidthX, kDouble, 0, 1, 0},
{ "frontconstraintwidth_y", &fFrontConstraintWidthY, kDouble, 0, 1, 0},
{ "backconstraintwidth_x", &fBackConstraintWidthX, kDouble, 0, 1, 0},
{ "backconstraintwidth_y", &fBackConstraintWidthY, kDouble, 0, 1, 0},
{ "frontconstraint_x0", &fFrontConstraintX0, kDouble, 0, 1, 0},
{ "frontconstraint_y0", &fFrontConstraintY0, kDouble, 0, 1, 0},
{ "backconstraint_x0", &fBackConstraintX0, kDouble, 0, 1, 0},
{ "backconstraint_y0", &fBackConstraintY0, kDouble, 0, 1, 0},
{ "trackgrinchcorr_const", &fTrackGrinchClusCorr_0, kDouble, 0, 1, 0},
{ "trackgrinchcorr_slope", &fTrackGrinchClusCorr_1, kDouble, 0, 1, 0},
{ "trackgrinchcorr_sigma", &fTrackGrinchClusCorr_Sigma, kDouble, 0, 1, 0},
{ "psshPIDprobatable", &pssh_pidproba, kDoubleV, 0, 1, 0},
{ "pcalPIDprobatable", &pcal_pidproba, kDoubleV, 0, 1, 0},
{ "grinchPIDpbins", &fP_table, kDoubleV, 0, 1, 0},
{ "grinchPIDprobatable", &grinch_pidproba, kDoubleV, 0, 1, 0},
{ "preconflag", &fPrecon_flag, kUInt, 0, 1, 1 },
{ "A_pth1", &fA_pth1, kDouble, 0, 1, 1 },
{ "B_pth1", &fB_pth1, kDouble, 0, 1, 1 },
{ "C_pth1", &fC_pth1, kDouble, 0, 1, 1 },
{ "A_pvy", &fA_vy, kDouble, 0, 1, 1 },
{ "B_pvy", &fB_vy, kDouble, 0, 1, 1 },
{ "xsigma_shower", &fSigmaX_shower, kDouble, 0, 1, 1 },
{ "ysigma_shower", &fSigmaY_shower, kDouble, 0, 1, 1 },
{ "xsigma_preshower", &fSigmaX_preshower, kDouble, 0, 1, 1 },
{ "ysigma_preshower", &fSigmaY_preshower, kDouble, 0, 1, 1 },
{ "xsigma_hodo", &fSigmaX_hodo, kDouble, 0, 1, 1 },
{ "ysigma_hodo", &fSigmaY_hodo, kDouble, 0, 1, 1 },
{ "forwardoptics_order", &fForwardOpticsOrder, kInt, 0, 1, 1 },
{ "forwardoptics_parameters", &foptics_param, kDoubleV, 0, 1, 1 },
{ "downbendoptics_order", &fOpticsOrderDownbend, kInt, 0, 1, 1 },
{ "downbendoptics_parameters", &doptics_param, kDoubleV, 0, 1, 1 },
{ "downbending_mode", &downbend, kInt, 0, 1, 1 },
{ "use_beampos", &use_beampos, kInt, 0, 1, 1 },
{ "is_mc", &mc_flag, kInt, 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;
}
fUseBeamPosInOptics = ( use_beampos != 0 ) ? true : false;
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 );
//Database values for these angles are assumed to be given in degrees:
// These will have been initialized to default values in degrees above, or if they were loaded from the database they will have been given in degrees:
fGEMtheta = gemthetadeg * TMath::DegToRad();
fGEMphi = gemphideg * TMath::DegToRad();
if( firstgem_offset.size() == 3 ){ //database overrides default values:
fGEMorigin.SetXYZ( firstgem_offset[0],
firstgem_offset[1],
firstgem_offset[2] );
}
InitGEMAxes( fGEMtheta, fGEMphi );
if(fECaloFudgeFactor!=1.0)cout << "Setting the calorimeter energy fudge factor to " << fECaloFudgeFactor << endl;
fPID = ( pidflag != 0 );
//do we have non tracking detectors
bool nontrackdet = false;
TIter next( fNonTrackingDetectors );
while( auto* theNonTrackDetector =
static_cast<THaNonTrackingDetector*>( next() )) {
cout << theNonTrackDetector->GetName() << endl;
nontrackdet = true;
}//if we do not find any non tracking detectors, we force fPID to be false.
if(!nontrackdet)fPID = false;
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]);
if(f_om[i]==0 && f_ol[i]==0 && f_ok[i]==0 && f_oj[i]==0 && f_oi[i]==0){
fPtheta_00000 = fb_pinv[i];
}
if(f_om[i]==1 && f_ol[i]==0 && f_ok[i]==0 && f_oj[i]==0 && f_oi[i]==0){
fPtheta_10000 = fb_pinv[i];
fXptar_10000 = fb_xptar[i];
}
if(f_om[i]==0 && f_ol[i]==0 && f_ok[i]==1 && f_oj[i]==0 && f_oi[i]==0){
fPtheta_00100 = fb_pinv[i];
fXptar_00100 = fb_xptar[i];
}
if(f_om[i]==0 && f_ol[i]==1 && f_ok[i]==0 && f_oj[i]==0 && f_oi[i]==0)
fYtar_01000 = fb_ytar[i];
if(f_om[i]==0 && f_ol[i]==0 && f_ok[i]==0 && f_oj[i]==1 && f_oi[i]==0)
fYtar_00010 = fb_ytar[i];
}
}
if( fForwardOpticsOrder >= 0 ){
unsigned int nterms=0;
for(int i = 0; i<=fForwardOpticsOrder; i++){ //x
for( int j=0; j<=fForwardOpticsOrder-i; j++){ //y
for( int k=0; k<=fForwardOpticsOrder-i-j; k++){
for( int l=0; l<=fForwardOpticsOrder-i-j-k; l++){
for( int m=0; m<=fForwardOpticsOrder-i-j-k-l; m++ ){
nterms++;
}
}
}
}
}
cout << nterms << " lines of parameters expected for optics of order " << fForwardOpticsOrder << endl;
unsigned int nparams = 9*nterms;
if(nparams!=foptics_param.size()){
std::cerr << "Warning: mismatch between " << foptics_param.size()
<< " forward optics parameters provided and " << nparams*9
<< " forward optics parameters expected!" << std::endl;
std::cerr << " Fix database! " << std::endl;
return kInitError;
}
//I seem to be able to write anything except a std::cout
fb_xfp.resize( nterms );
fb_yfp.resize( nterms );
fb_xpfp.resize( nterms );
fb_ypfp.resize( nterms );
f_foi.resize(nterms);
f_foj.resize(nterms);
f_fok.resize(nterms);
f_fol.resize(nterms);
f_fom.resize(nterms);
for(unsigned int i=0; i<nterms; i++){
fb_xfp[i] = foptics_param[9*i];
fb_yfp[i] = foptics_param[9*i+1];
fb_xpfp[i] = foptics_param[9*i+2];
fb_ypfp[i] = foptics_param[9*i+3];
f_fom[i] = int(foptics_param[9*i+4]);
f_fol[i] = int(foptics_param[9*i+5]);
f_fok[i] = int(foptics_param[9*i+6]);
f_foj[i] = int(foptics_param[9*i+7]);
f_foi[i] = int(foptics_param[9*i+8]);
}
}
fDownBendingMode = downbend != 0 ? true : false;
if( fDownBendingMode ){
if( fOpticsOrderDownbend >= 0 ){
unsigned int nterms=0;
for(int i = 0; i<=fOpticsOrderDownbend; i++){ //x
for( int j=0; j<=fOpticsOrderDownbend-i; j++){ //y
for( int k=0; k<=fOpticsOrderDownbend-i-j; k++){
for( int l=0; l<=fOpticsOrderDownbend-i-j-k; l++){
for( int m=0; m<=fOpticsOrderDownbend-i-j-k-l; m++ ){
nterms++;
}
}
}
}
}
cout << nterms << " lines of parameters expected for optics of order " << fOpticsOrderDownbend << endl;
unsigned int nparams = 9*nterms;
if(nparams!=doptics_param.size()){
std::cerr << "Warning: mismatch between " << foptics_param.size()
<< " downbending optics parameters provided and " << nparams*9
<< " downbending optics parameters expected!" << std::endl;
std::cerr << " Fix database! " << std::endl;
return kInitError;
}
fb_xptar_downbend.resize(nterms);
fb_yptar_downbend.resize(nterms);
fb_ytar_downbend.resize(nterms);
fb_pinv_downbend.resize(nterms);
f_oi_downbend.resize(nterms);
f_oj_downbend.resize(nterms);
f_ok_downbend.resize(nterms);
f_ol_downbend.resize(nterms);
f_om_downbend.resize(nterms);
for(unsigned int i=0; i<nterms; i++){
fb_xptar_downbend[i] = doptics_param[9*i];
fb_yptar_downbend[i] = doptics_param[9*i+1];
fb_ytar_downbend[i] = doptics_param[9*i+2];
fb_pinv_downbend[i] = doptics_param[9*i+3];
f_om_downbend[i] = int(doptics_param[9*i+4]);
f_ol_downbend[i] = int(doptics_param[9*i+5]);
f_ok_downbend[i] = int(doptics_param[9*i+6]);
f_oj_downbend[i] = int(doptics_param[9*i+7]);
f_oi_downbend[i] = int(doptics_param[9*i+8]);
if(f_om_downbend[i]==0 && f_ol_downbend[i]==0 && f_ok_downbend[i]==0 && f_oj_downbend[i]==0 && f_oi_downbend[i]==0){
fPtheta_00000 = fb_pinv_downbend[i];
}
if(f_om_downbend[i]==1 && f_ol_downbend[i]==0 && f_ok_downbend[i]==0 && f_oj_downbend[i]==0 && f_oi_downbend[i]==0){
fPtheta_10000 = fb_pinv_downbend[i];
fXptar_10000 = fb_xptar_downbend[i];
}
if(f_om_downbend[i]==0 && f_ol_downbend[i]==0 && f_ok_downbend[i]==1 && f_oj_downbend[i]==0 && f_oi_downbend[i]==0){
fPtheta_00100 = fb_pinv_downbend[i];
fXptar_00100 = fb_xptar_downbend[i];
}
if(f_om_downbend[i]==0 && f_ol_downbend[i]==1 && f_ok_downbend[i]==0 && f_oj_downbend[i]==0 && f_oi_downbend[i]==0)
fYtar_01000 = fb_ytar_downbend[i];
if(f_om_downbend[i]==0 && f_ol_downbend[i]==0 && f_ok_downbend[i]==0 && f_oj_downbend[i]==1 && f_oi_downbend[i]==0)
fYtar_00010 = fb_ytar_downbend[i];
}
} else {
std::cerr << "Warning: downbending mode specified but no downbending optics parameters provided; fix database" << std::endl;
return kInitError;
}
}
//PID stuff
fEpsEtotRatio_table.clear();
fProba_e_PSSH_table.clear();
fProba_pi_PSSH_table.clear();
if(!pssh_pidproba.empty()){
unsigned int npts = pssh_pidproba.size()/3;
fEpsEtotRatio_table.resize(npts);
fProba_e_PSSH_table.resize(npts);
fProba_pi_PSSH_table.resize(npts);
for(unsigned int i = 0; i<npts; i++){
fEpsEtotRatio_table[i] = pssh_pidproba[3*i];
fProba_e_PSSH_table[i] = pssh_pidproba[3*i+1];
fProba_pi_PSSH_table[i] = pssh_pidproba[3*i+2];
}
}
//PID stuff
fEtotPratio_table.clear();
fProba_e_PCAL_table.clear();
fProba_pi_PCAL_table.clear();
if(!pcal_pidproba.empty()){
unsigned int npts = pcal_pidproba.size()/3;
fEtotPratio_table.resize(npts);
fProba_e_PCAL_table.resize(npts);
fProba_pi_PCAL_table.resize(npts);
for(unsigned int i = 0; i<npts; i++){
fEtotPratio_table[i] = pcal_pidproba[3*i];
fProba_e_PCAL_table[i] = pcal_pidproba[3*i+1];
fProba_pi_PCAL_table[i] = pcal_pidproba[3*i+2];
}
}
fNGRINCHPMTs_table.clear();
fProba_e_GRINCH_table.clear();
fProba_pi_GRINCH_table.clear();
if(!grinch_pidproba.empty() && !fP_table.empty()){
unsigned int n_ppts = 2+fP_table.size();
unsigned int npts = grinch_pidproba.size()/(n_ppts);
fNGRINCHPMTs_table.resize(npts);
fProba_e_GRINCH_table.resize(npts);
fProba_pi_GRINCH_table.resize(fP_table.size());
for(unsigned int j = 0; j<fP_table.size(); j++){
fProba_pi_GRINCH_table[j].resize(npts);
}
for(unsigned int i = 0; i<npts; i++){
fNGRINCHPMTs_table[i] = grinch_pidproba[n_ppts*i];
fProba_e_GRINCH_table[i] = grinch_pidproba[n_ppts*i+1];
for(unsigned int j = 0; j<fP_table.size(); j++){
fProba_pi_GRINCH_table[j][i] = grinch_pidproba[n_ppts*i+2+j];
}
}
}
fIsMC = (mc_flag != 0);
fIsInit = true;
return kOK;
}
Int_t SBSBigBite::DefineVariables( EMode mode ){
THaSpectrometer::DefineVariables(mode);
if( mode == kDefine and fIsSetup ) return kOK;
fIsSetup = ( mode == kDefine );
// removing all that stuff since apparently I'm not able to code properly...
RVarDef beamtrackvars[] = {
{ "tr.tg_x", "target x", "fTracks.THaTrack.fTX" },
{ nullptr }
};
DefineVarsFromList( beamtrackvars, mode );
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 constraing z", "fBackConstraintZ" },
{ nullptr }
};
DefineVarsFromList( constraintvars, mode );
RVarDef pidvars[] = {
{ "eps_over_etot", "electron probability", "fEpsEtotRatio" },
{ "etot_over_p", "electron probability", "fEtotPratio" },
{ "prob_e", "electron probability", "fProbaE" },
{ "prob_pi", "pion probability", "fProbaPi" },
{ nullptr }
};
DefineVarsFromList( pidvars, mode );
return 0;
}
//_____________________________________________________________________________
// Int_t SBSBigBite::End( THaRunBase* run )
// {
// h1_yVx_bcp->Write();
// h1_x_fcpVbcp->Write();
// h1_yVx_fcp->Write();
// h1_y_fcpVbcp->Write();
// h1_dyVdx->Write();
// }
//_____________________________________________________________________________
Int_t SBSBigBite::CoarseTrack()
{
// Coarse track Reconstruction
//std::cout << " SBSBigBite::CoarseTrack()...";
THaSpectrometer::CoarseTrack();
// TODO
//std::cout << " call SBSBigBite::CoarseTrack" << std::endl;
//std::cout << "done" << std::endl;
return 0;
}
//_____________________________________________________________________________
Int_t SBSBigBite::CoarseReconstruct()
{
//std::cout << "SBSBigBite::CoarseReconstruct()...";
// Coarse Reconstruction of particles in spectrometer
THaSpectrometer::CoarseReconstruct();
// TODO
// fetch the clusters from SBSBBShower detectors
// FOR NOW: fetch the highest clusters from SBSBBShower detectors
double x_fcp = 0, y_fcp = 0, z_fcp = 0;
double x_bcp = 0, y_bcp = 0, z_bcp = 0;
double sumweights_x = 0, sumweights_y = 0, sumweights_z = 0.0;
double Etot = 0;
//npts is incremented only if there are clusters in the preshower and shower
int npts = 0;
double EpsEtotRatio = 0;
TIter next( fNonTrackingDetectors );
while( auto* theNonTrackDetector =
static_cast<THaNonTrackingDetector*>( next() )) {
//if(theNonTrackDetector->InheritsFrom("SBSBBShower")){
//if(theNonTrackDetector->InheritsFrom("SBSCalorimeter")){
if(theNonTrackDetector->InheritsFrom("SBSBBTotalShower")){//More explicit
//cout << "found SBSBBTtotalShower" << endl;
SBSBBTotalShower* BBTotalShower = reinterpret_cast<SBSBBTotalShower*>(theNonTrackDetector);
//BBShower->EresMax();
// explicitely return and 0 if there is no cluster in the calorimeter;
if(BBTotalShower->GetShower()->GetNclust()==0 || BBTotalShower->GetPreShower()->GetNclust()==0){
//cout << BBTotalShower->GetPreShower()->GetNclust() << " clusters in preshower, " << BBTotalShower->GetShower()->GetNclust() << " clusters in shower, kill here" << endl;
return 0;
}
//cout << "shower cluster E " << BBTotalShower->GetShower()->GetECorrected()
// << " X = " << BBTotalShower->GetShower()->GetX()
// << " Y = " << BBTotalShower->GetShower()->GetY()
// << endl;
//cout << "preshower cluster E " << BBTotalShower->GetPreShower()->GetECorrected()
// << " X = " << BBTotalShower->GetPreShower()->GetX()
// << " Y = " << BBTotalShower->GetPreShower()->GetY()
// << endl;
if(GetMultiTracks()){
std::vector<SBSCalorimeterCluster*> ShowerClusters = BBTotalShower->GetShower()->GetClusters();
std::vector<SBSCalorimeterCluster*> PreShowerClusters = BBTotalShower->GetPreShower()->GetClusters();
//cout << BBTotalShower->GetShower()->GetECorrected() << endl;
for(unsigned int i = 0; i<ShowerClusters.size(); i++){
npts = 0;
sumweights_x = sumweights_y = 0;
x_bcp = y_bcp = z_bcp = 0;
sumweights_x+= 1./(pow(BBTotalShower->GetShower()->SizeRow(), 2)/12.);
sumweights_y+= 1./(pow(BBTotalShower->GetShower()->SizeCol(), 2)/12.);
Etot = ShowerClusters[i]->GetE();
npts = 1;
x_bcp+= ShowerClusters[i]->GetX()/(BBTotalShower->GetShower()->SizeRow()/sqrt(12));
y_bcp+= ShowerClusters[i]->GetY()/(pow(BBTotalShower->GetShower()->SizeCol(), 2)/12.);
z_bcp+= BBTotalShower->GetShower()->GetOrigin().Z();
npts++;
if(BBTotalShower->PSMatchClusIdx(i)<(int)PreShowerClusters.size()){
Etot+= PreShowerClusters[BBTotalShower->PSMatchClusIdx(i)]->GetE();
fEpsEtotRatio.push_back(EpsEtotRatio);
fEtot.push_back(Etot);
x_bcp+= PreShowerClusters[BBTotalShower->PSMatchClusIdx(i)]->GetX()/(pow(BBTotalShower->GetPreShower()->SizeRow(), 2)/12.);
y_bcp+= PreShowerClusters[BBTotalShower->PSMatchClusIdx(i)]->GetY()/(pow(BBTotalShower->GetPreShower()->SizeCol(), 2)/12.);
sumweights_x+= 1./(pow(BBTotalShower->GetPreShower()->SizeRow(), 2)/12.);
sumweights_y+= 1./(pow(BBTotalShower->GetPreShower()->SizeCol(), 2)/12.);
z_bcp+= BBTotalShower->GetPreShower()->GetOrigin().Z();
npts++;
double x_temp = x_bcp/sumweights_x;
TIter next1( fNonTrackingDetectors );
while( auto* theNonTrackDetector =
static_cast<THaNonTrackingDetector*>( next1() )) {
// match a hodoscope cluster to a track:
//the hodoscope has to be found for anything to be done.
if(theNonTrackDetector->InheritsFrom("SBSTimingHodoscope")){
SBSTimingHodoscope* TH = reinterpret_cast<SBSTimingHodoscope*>(theNonTrackDetector);
double xhodo = 0, yhodo = 0, weightx = 0, weighty = 0;
double dxmin = 10.0;
bool found = false;
//cout << TH->SizeRow() << " " << TH->SizeCol() << endl;
for(int i=0; i<TH->GetNClusters(); i++){
SBSTimingHodoscopeCluster* clus = TH->GetCluster(i);
if(clus->GetXmean()-clus->GetSize()*TH->SizeRow()/2<x_temp &&
x_temp<clus->GetXmean()+clus->GetSize()*TH->SizeRow()/2){
found = true;
if(fabs(x_temp-clus->GetXmean())<dxmin){
dxmin = fabs(x_temp-clus->GetXmean());
weightx = 1./(clus->GetSize()*TH->SizeRow()*TH->SizeRow()/4.);
weighty = 1./(TH->SizeCol()*TH->SizeCol()/clus->GetSize()/4.);
xhodo = clus->GetXmean();
yhodo = clus->GetYmean();
}
}
}
if(found){
x_bcp+= xhodo*weightx;
y_bcp+= yhodo*weighty;
z_bcp+= TH->GetOrigin().Z();
sumweights_x+=weightx;
sumweights_y+=weighty;
npts++;
}
}//end if inherits from hodoscope
}//end loop on non-tracking detectors
x_bcp/=sumweights_x;
y_bcp/=sumweights_y;
z_bcp/=npts;
double Efudge = Etot * fECaloFudgeFactor;
double dx = (Efudge*fOpticsAngle - fPtheta_00000 + x_bcp * (Efudge*fXptar_10000-fPtheta_10000)) /
(-fPtheta_10000*z_bcp+fPtheta_00100+Efudge*(fXptar_10000*z_bcp+1-fXptar_00100));
double dy = y_bcp*fb_ytar[3]/(fb_ytar[3]*z_bcp-fb_ytar[10]);
z_fcp = 0;
x_fcp = x_bcp+dx*(z_fcp-z_bcp);
y_fcp = y_bcp+dy*(z_fcp-z_bcp);
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);
//now what???
}
}//end loop on Shower clusters
}else{//end if(GetMultiTracks())
x_bcp = y_bcp = z_bcp = 0;
npts = 0;
//if(BBTotalShower->GetShower()->GetNclust()){
//cout << BBTotalShower->GetShower()->GetName() << " " << BBTotalShower->GetShower()->GetX() << " " << BBTotalShower->GetShower()->GetY() << " " << BBTotalShower->GetShower()->GetOrigin().Z() << " " << 1./(BBTotalShower->GetShower()->SizeRow()/sqrt(12)) << " " << 1./(BBTotalShower->GetShower()->SizeCol()/sqrt(12)) << endl;
// TODO: so far we use only the "main" cluster...
// we might want to check the others...
//y_bcp+= BBTotalShower->GetShower()->GetY()/(BBTotalShower->GetShower()->SizeCol()/sqrt(12));
//Etot+= BBTotalShower->GetShower()->GetECorrected();
Etot+= BBTotalShower->GetShower()->GetE();
double weightxSH = pow(fSigmaX_shower,-2);
double weightySH = pow(fSigmaY_shower,-2);
// x_bcp+= BBTotalShower->GetShower()->GetX()/(pow(BBTotalShower->GetShower()->SizeRow(), 2)/12.);
// y_bcp+= BBTotalShower->GetShower()->GetY()/(pow(BBTotalShower->GetShower()->SizeCol(), 2)/12.);
x_bcp+= BBTotalShower->GetShower()->GetX()*weightxSH;
y_bcp+= BBTotalShower->GetShower()->GetY()*weightySH;
z_bcp+= BBTotalShower->GetShower()->GetOrigin().Z() * (weightxSH + weightySH);
npts++;
// sumweights_x+=1./(pow(BBTotalShower->GetShower()->SizeRow(), 2)/12.);
// sumweights_y+=1./(pow(BBTotalShower->GetShower()->SizeCol(), 2)/12.);
sumweights_x += weightxSH;
sumweights_y += weightySH;
sumweights_z += weightxSH + weightySH;
//}
//if(BBTotalShower->GetPreShower()->GetNclust()){
//cout << BBTotalShower->GetPreShower()->GetName() << " " << BBTotalShower->GetPreShower()->GetX() << " " << BBTotalShower->GetPreShower()->GetY() << " " << BBTotalShower->GetPreShower()->GetOrigin().Z() << " " << 1./(BBTotalShower->GetPreShower()->SizeRow()/sqrt(12)) << " " << 1./(BBTotalShower->GetPreShower()->SizeCol()/sqrt(12)) << endl;
//std::cout << x_bcp << " " << x_bcp/sumweights_x << endl;
//std::cout << "Back constraint point sh only x, y, z: " << x_bcp/sumweights_x << ", " << y_bcp/sumweights_y << ", " << z_bcp/npts << endl;
double weightxPS = pow(fSigmaX_preshower,-2);
double weightyPS = pow(fSigmaY_preshower,-2);
// Etot+= BBTotalShower->GetPreShower()->GetECorrected();
// EpsEtotRatio = BBTotalShower->GetPreShower()->GetECorrected()/Etot;
Etot+= BBTotalShower->GetPreShower()->GetE();
EpsEtotRatio = BBTotalShower->GetPreShower()->GetE()/Etot;
fEpsEtotRatio.push_back(EpsEtotRatio);
fEtot.push_back(Etot);
// x_bcp+= BBTotalShower->GetPreShower()->GetX()/(pow(BBTotalShower->GetPreShower()->SizeRow(), 2)/12.);
// y_bcp+= BBTotalShower->GetPreShower()->GetY()/(pow(BBTotalShower->GetPreShower()->SizeCol(), 2)/12.);
// z_bcp+= BBTotalShower->GetPreShower()->GetOrigin().Z();
x_bcp+= BBTotalShower->GetPreShower()->GetX()*weightxPS;
y_bcp+= BBTotalShower->GetPreShower()->GetY()*weightyPS;
z_bcp+= BBTotalShower->GetPreShower()->GetOrigin().Z() * (weightxPS+weightyPS);
npts++;
// sumweights_x+=1./(pow(BBTotalShower->GetPreShower()->SizeRow(), 2)/12.);
// sumweights_y+=1./(pow(BBTotalShower->GetPreShower()->SizeCol(), 2)/12.);
sumweights_x += weightxPS;
sumweights_y += weightyPS;
sumweights_z += weightxPS + weightyPS;
//std::cout << x_bcp << " " << x_bcp/sumweights_x << endl;
//std::cout << "PS cluster x, y: " << BBTotalShower->GetPreShower()->GetX() << ", " << BBTotalShower->GetPreShower()->GetY() << std::endl;
//<< std::endl;
//}
double x_temp = x_bcp/sumweights_x;
double y_temp = y_bcp/sumweights_y;
double sigx2_temp = 1.0/sumweights_x;
double sigy2_temp = 1.0/sumweights_y;
double weightx_hodo = pow(fSigmaX_hodo,-2);
double weighty_hodo = pow(fSigmaY_hodo,-2);
TIter next1( fNonTrackingDetectors );
while( auto* theNonTrackDetector =
static_cast<THaNonTrackingDetector*>( next1() )) {
// match a hodoscope cluster to a track:
//the hodoscope has to be found for anything to be done.
if(theNonTrackDetector->InheritsFrom("SBSTimingHodoscope")){
SBSTimingHodoscope* TH = reinterpret_cast<SBSTimingHodoscope*>(theNonTrackDetector);
double xhodo = 0, yhodo = 0;
//double dxmin = 10.0;
double mindiff2 = 1000.0;
bool found = false;
//cout << TH->SizeRow() << " " << TH->SizeCol() << endl;
//Require a cluster that agrees with the shower/preshower cluster to within some tolerance:
for(int i=0; i<TH->GetNClusters(); i++){
SBSTimingHodoscopeCluster* clus = TH->GetCluster(i);
// if(clus->GetXmean()-clus->GetSize()*TH->SizeRow()/2.<x_temp &&
// x_temp<clus->GetXmean()+clus->GetSize()*TH->SizeRow()/2.){
double xdiff = clus->GetXmean() - x_temp;
double ydiff = clus->GetYmean() - y_temp;
//Add a hodoscope cluster if within +/- 3.5 sigma of
double diff2 = pow(xdiff,2)/(sigx2_temp + pow(fSigmaX_hodo,2)) + pow(ydiff,2)/(sigy2_temp + pow(fSigmaY_hodo,2));
//if(fabs(x_temp-clus->GetXmean())<dxmin){
if( !found || diff2 < mindiff2 ){
// dxmin = fabs(x_temp-clus->GetXmean());
mindiff2 = diff2;
//weightx = 1./(clus->GetSize()*TH->SizeRow()*TH->SizeRow()/4.);
//weighty = 1./(TH->SizeCol()*TH->SizeCol()/clus->GetSize()/4.);
xhodo = clus->GetXmean();
yhodo = clus->GetYmean();
found = true;
}
}
//std::cout << "Number of hodoscope clusters = " << TH->GetNClusters() << std::endl;
//std::cout << "After loop over hodoscope clusters, mindiff2 = " << mindiff2 << std::endl;
if( mindiff2 > pow(3.5,2) ) found = false;
if(found){
//std::cout << "found matching hodoscope cluster, mindiff2 = " << mindiff2 << std::endl;
x_bcp+= xhodo*weightx_hodo;
y_bcp+= yhodo*weighty_hodo;
z_bcp+= TH->GetOrigin().Z()*(weightx_hodo+weighty_hodo);
sumweights_x += weightx_hodo;
sumweights_y += weighty_hodo;
sumweights_z += weightx_hodo + weighty_hodo;
npts++;
}
}//end if inherits from hodoscope
}//end loop on non-tracking detectors
//std::cout << x_bcp << " " << x_bcp/sumweights_x << endl;
//if we're here we've found the totalshower
//if(npts){
x_bcp/=sumweights_x;
y_bcp/=sumweights_y;
//z_bcp/=npts;
z_bcp /= sumweights_z;
//std::cout << "Back constraint point x, y, z: " << x_bcp << ", " << y_bcp << ", "<< z_bcp << endl << endl;
// to account for the angle and position offsets of the detector stack:
// simplest approximate way to do it:
// we have x_bcp^det
// x_bcp^opt ~ x_bcp^det+fFirstGEMLayerOffset.X()+fDetectorStackPitch*z_bcp
// => calculate dx^opt(x_bcp^opt)
// => calculate x_fcp^opt(dx^opt)
// => x_fcp^det = x_fcp^opt+fFirstGEMLayerOffset.X()
// similarly with y_bcp^det
// y_bcp^opt ~ y_bcp^det+fFirstGEMLayerOffset.Y()+fDetectorStackYaw*z_bcp
// => calculate dy^opt(y_bcp^opt)
// => calculate x_fcp^opt(dy^opt)
// => y_fcp^det = y_fcp^opt-fFirstGEMLayerOffset.Y()
// Of course all of the above would hold only for angles less than a few degrees.
//transformation in optics coordinate
//commenting these out for now: AJRP
//x_bcp+=fFirstGEMLayerOffset.X()+fDetectorStackPitch*z_bcp;
//y_bcp+=fFirstGEMLayerOffset.Y()+fDetectorStackYaw*z_bcp;
// Use 10.0 degrees instead of fTrackerPitchAngle
// because we are now in the "ideal" system.
//double xp_bcp = (Etot*fECaloFudgeFactor*fTrackerPitchAngle - fPtheta_00000 + x_bcp * (Etot*fXptar_10000-fPtheta_10000)) /
// (-fPtheta_10000*z_bcp+fPtheta_00100+Etot*fECaloFudgeFactor*(fXptar_10000*z_bcp+1-fXptar_00100));
double yp_bcp = y_bcp*fYtar_01000/(fYtar_01000*z_bcp-fYtar_00010);
double Efudge = Etot * fECaloFudgeFactor;
if( fDownBendingMode ) Efudge *= -1.0;
// we'll see if this is sufficient to get the constraint right for the downbending tracks. It probably isn't. But according to the algebra, this method should work for Precon_flag == 1
// for Precon flag OTHER than 1, I haven't checked the algebra.
double xp_bcp = 0;
//if( !fDownBendingMode ){
if( fPrecon_flag != 1 ){
xp_bcp = ( fPtheta_00000 + fPtheta_10000 * x_bcp - Efudge * ( fOpticsAngle + fXptar_10000 * x_bcp ) ) /
( Efudge * (fXptar_00100 - 1.0 - fXptar_10000*z_bcp) + fPtheta_10000 * z_bcp - fPtheta_00100 );
} else { //Using alternate formalism. In this case, the formula differs a fair bit:
double Mthx = fXptar_10000;
double Mthxp = fXptar_00100;
xp_bcp = ( Efudge * ( fOpticsAngle + Mthx * x_bcp ) - fA_pth1*(1.0 + (fB_pth1 + fC_pth1*fMagDist)*Mthx * x_bcp ) ) /
(fA_pth1*(fB_pth1+fC_pth1*fMagDist)*(Mthxp - z_bcp * Mthx) + Efudge*(1.0 + Mthx * z_bcp - Mthxp) );
}
// The dy equation is correct under the assumption ytarget = 0: can we refine?
// double dx = (Etot*10.*TMath::DegToRad() -fb_pinv[0] + x_bcp * (Etot*fb_xptar[1]-fb_pinv[1])) /
// (-fb_pinv[1]*z_bcp+fb_pinv[6]+Etot*(fb_xptar[1]*z_bcp+1-fb_xptar[6]));
// double dy = y_bcp*fb_ytar[3]/(fb_ytar[3]*z_bcp-fb_ytar[10]);
//The x' equation is:
// Ecalo = p
// ECALO*thetabend = fPtheta_00000 + fPtheta_10000 * xfp
// ECALO*( 10 deg. + xptar - xpfp ) = ptheta0 + pthetax * xfp
// xptar = xptar_0 + xptar_x * xfp + xptar_xp * xpfp
// xbcp = xfp + xpfp * zbcp
// xfp = xbcp - xpfp * zbcp
// ECALO * ( 10 deg. + xptar - xpfp ) = pth0 + Mpthx * (xbcp - xpfp * zbcp );
// ECALO * ( 10 deg. + xp0 + Mxpx * (xbcp - xpfp * zbcp) + Mxpxp * xpfp - xpfp ) = pth0 + Mpthx * (xbcp-xpfp*zbcp)
// ECAL * (10 deg. + xp0 + Mxpx * xbcp) + xpfp * ECALO * ( Mxpxp - Mxpx * zbcp - 1 ) = Mpthx * xbcp - xpfp*Mpthx*zbcp
// --> xpfp*[ ECALO * ( Mxpxp - Mxpx*zbcp - 1 ) - Mpthx*zbcp ] =
//cout << "(x_bcp*(" << fXptar_10000 << "*Etot-" << fPtheta_10000 << ")+"
// << 10.*TMath::DegToRad() << "*Etot-" << fPtheta_00000 << ")/" << endl
// << " (Etot*" << (fXptar_10000*z_bcp+1-fXptar_00100) << "+" << -fPtheta_10000*z_bcp+fPtheta_00100 << ")" << endl;
//cout << fYtar_01000/(fYtar_01000*z_bcp-fYtar_00010) << endl;
z_fcp = 0;
x_fcp = x_bcp+xp_bcp*(z_fcp-z_bcp);
y_fcp = y_bcp+yp_bcp*(z_fcp-z_bcp);
//commenting this out for now
//x_bcp+=-fFirstGEMLayerOffset.X();
//y_bcp+=-fFirstGEMLayerOffset.Y();
//cout << x_fcp-(x_bcp+dx_2*(z_fcp-z_bcp)) << " " << y_fcp-(y_bcp+dy_2*(z_fcp-z_bcp)) << endl;
/*
h1_yVx_bcp->Fill(x_bcp, y_bcp);
h1_x_fcpVbcp->Fill(x_bcp, x_fcp);
h1_yVx_fcp->Fill(x_fcp, y_fcp);
h1_y_fcpVbcp->Fill(y_bcp, y_fcp);
h1_dyVdx->Fill(dx, dy);
*/
fFrontConstraintX.push_back(x_fcp + fFrontConstraintX0);
fFrontConstraintY.push_back(y_fcp + fFrontConstraintY0);
fFrontConstraintZ.push_back( z_fcp );
fBackConstraintX.push_back(x_bcp + fBackConstraintX0);
fBackConstraintY.push_back(y_bcp + fBackConstraintY0);