@@ -17,9 +17,11 @@ namespace sbn {
1717
1818 bool onePlot = true ;
1919
20- float getBNBqualityFOM (BNBSpillInfo & spill )
20+ std::tuple< float , float , float > getBNBqualityFOM (BNBSpillInfo & spill )
2121 {
2222 double fom=0 ;
23+ double prefitfom=0 ;
24+ double noMWfom=0 ;
2325
2426 double hp875_offset= spill.HP875Offset ;
2527 double vp875_offset= spill.VP875Offset ;
@@ -57,6 +59,16 @@ namespace sbn {
5759 std::vector<double > vptg1;
5860 std::vector<double > hptg2;
5961 std::vector<double > vptg2;
62+
63+ std::vector<double > m875hs; // Multiwire station after Mag 875, Fit to Horizontal Sigma
64+ std::vector<double > m875hm; // Multiwire station after Mag 875, Fit to Horizontal Mean
65+ std::vector<double > m875vs; // Multiwire station after Mag 875, Fit to Vertical Sigma
66+ std::vector<double > m875vm; // Multiwire station after Mag 875, Fit to Vertical Mean
67+
68+ std::vector<double > m876hs; // Multiwire station after Mag 876, Fit to Horizontal Sigma
69+ std::vector<double > m876hm; // Multiwire station after Mag 876, Fit to Horizontal Mean
70+ std::vector<double > m876vs; // Multiwire station after Mag 876, Fit to Vertical Sigma
71+ std::vector<double > m876vm; // Multiwire station after Mag 876, Fit to Vertical Mean
6072
6173 std::vector<double > mw875 (spill.M875BB .begin (), spill.M875BB .end ());
6274 std::vector<double > mw876 (spill.M876BB .begin (), spill.M876BB .end ());
@@ -73,13 +85,23 @@ namespace sbn {
7385 hptg2.push_back (spill.HPTG2 );
7486 vptg2.push_back (spill.VPTG2 );
7587
88+ m875hs.push_back (spill.M875HS );
89+ m875hm.push_back (spill.M875HM );
90+ m875vs.push_back (spill.M875VS );
91+ m875vm.push_back (spill.M875VM );
92+
93+ m876hs.push_back (spill.M876HS );
94+ m876hm.push_back (spill.M876HM );
95+ m876vs.push_back (spill.M876VS );
96+ m876vm.push_back (spill.M876VM );
97+
7698 double tor;
7799 if (!tor860.empty ())
78100 tor=tor860[0 ];
79101 else if (!tor875.empty ())
80102 tor=tor875[0 ];
81103 else
82- return - 1 ;
104+ return {- 1 ,- 1 ,- 1 } ;
83105
84106 /* *
85107 * @brief when creating ntuples for pot counting script the variables are filled with -999
@@ -104,8 +126,8 @@ namespace sbn {
104126 return std::pair (ang, pos);
105127 };
106128
107- // return 2 when missing essential beam horizontal position data:
108- if (hp875.empty () || (hptg1.empty () && hptg2.empty ())) return 2 ;
129+ // return 2 when missing essential beam horizontal position data:
130+ if (hp875.empty () || (hptg1.empty () && hptg2.empty ())) return { 2 , 2 , 2 } ;
109131 bool const doUseHTG1 = (useHTG == 1 ) || hptg2.empty ();
110132 auto const [ Tanhorang, horpos ] = doUseHTG1?
111133 interpolate_hp875 (hptg1[0 ] - hptg1_offset, hptg1_zpos):
@@ -121,8 +143,8 @@ namespace sbn {
121143 return std::pair (ang, pos);
122144 };
123145
124- // return 2 when missing essential beam horizontal position data:
125- if (vp875.empty () || (vptg1.empty () && vptg2.empty ())) return 3 ;
146+ // return 3 when missing essential beam horizontal position data:
147+ if (vp875.empty () || (vptg1.empty () && vptg2.empty ())) return { 3 , 3 , 3 } ;
126148 bool const doUseVTG1 = (useVTG == 1 ) || vptg2.empty ();
127149 auto const [ Tanverang, verpos ] = doUseVTG1?
128150 interpolate_vp875 (vp873[0 ] - vp873_offset, vp873_zpos):
@@ -138,6 +160,8 @@ namespace sbn {
138160 constexpr size_t FirstXMWtgt =0 ;
139161 constexpr size_t FirstYMWtgt =48 ;
140162 const double smallSigmaX =0.5 , largeSigmaX = 10 , smallSigmaY = 0.3 , largeSigmaY =10 , maxChi2X = 20 , maxChi2Y = 20 ;
163+
164+ // First calculate try the version of the FOM where we fit the width ourselves
141165 if (mwtgt.size ()>0 ) {
142166 processBNBprofile (&mwtgt[FirstXMWtgt], xx, sx,chi2x);
143167 processBNBprofile (&mwtgt[FirstYMWtgt], yy, sy, chi2y);
@@ -170,12 +194,53 @@ namespace sbn {
170194 }
171195 }
172196 if (!good_tgt && !good_876 && !good_875) {
173- // failed getting multiwire data
174- return 4 ;
197+ // failed getting multiwire data
198+ fom=- 999 ;
175199 }
176-
177- fom=1 -pow (10 ,sbn::calcFOM (horpos,horang,verpos,verang,tor,tgtsx,tgtsy));
178- return fom;
200+ else {
201+ fom=1 -pow (10 ,sbn::calcFOM (horpos,horang,verpos,verang,tor,tgtsx,tgtsy));
202+ }
203+
204+ bool good_prefit876=false ;
205+ bool good_prefit875=false ;
206+ sx = 0 ;
207+ sy = 0 ;
208+
209+ // Now calculate the "pre-fit" FOM values
210+ if (!m876hs.empty () && !m876vs.empty () && !m876hm.empty () && !m876vm.empty ()) {
211+ sx = m876hs[0 ];
212+ sy = m876vs[0 ];
213+ double tgtsx876=p876x[0 ]+p876x[1 ]*sx+p876x[2 ]*sx*sx;
214+ double tgtsy876=p876y[0 ]+p876y[1 ]*sy+p876y[2 ]*sy*sy;
215+ if (tgtsx876>smallSigmaX && tgtsx876<largeSigmaX && tgtsy876>smallSigmaY && tgtsy876<largeSigmaY && chi2x< maxChi2X && chi2y< maxChi2Y) {
216+ tgtsx=tgtsx876;
217+ tgtsy=tgtsy876;
218+ good_prefit876=true ;
219+ }
220+ }
221+ if (!good_prefit876 && !m875hs.empty () && !m875vs.empty () && !m875hm.empty () && !m875vm.empty ()) {
222+ sx = m875hs[0 ];
223+ sy = m875vs[0 ];
224+ double tgtsx875=p875x[0 ]+p875x[1 ]*sx+p875x[2 ]*sx*sx;
225+ double tgtsy875=p875y[0 ]+p875y[1 ]*sy+p875y[2 ]*sy*sy;
226+ if (tgtsx875>smallSigmaX && tgtsx875<largeSigmaX && tgtsy875>smallSigmaY && tgtsy875<largeSigmaY && chi2x< maxChi2X && chi2y< maxChi2Y) {
227+ tgtsx=tgtsx875;
228+ tgtsy=tgtsy875;
229+ good_prefit875=true ;
230+ }
231+ }
232+ if (!good_prefit876 && !good_prefit875) {
233+ // failed getting multiwire data
234+ prefitfom=-999 ;
235+ }
236+ else {
237+ prefitfom=1 -pow (10 ,sbn::calcFOM (horpos,horang,verpos,verang,tor,tgtsx,tgtsy));
238+ }
239+
240+ // Lastly calculate the "no multiwire" fom values, defaults values for tgtsx,y will be caught
241+ // internally in order to set scalex=scaley=1
242+ noMWfom=1 -pow (10 ,sbn::calcFOM (horpos,horang,verpos,verang,tor));
243+ return {fom, prefitfom, noMWfom};
179244 }
180245
181246
@@ -318,8 +383,16 @@ namespace sbn {
318383 sbn::swimBNB (centroid1,sigma1,
319384 cnttoups, begtoups,
320385 cx, cy, sx, sy, rho);
321- double scalex=tgtsx/sx;
322- double scaley=tgtsy/sy;
386+
387+ double scalex, scaley;
388+ if ( tgtsx !=-999 && tgtsy!=-999 ){
389+ scalex=tgtsx/sx;
390+ scaley=tgtsy/sy;
391+ }
392+ else {
393+ scalex=1 ;
394+ scaley=1 ;
395+ }
323396 double fom_a=sbn::func_intbivar (cx, cy, sx*scalex, sy*scaley, rho);
324397 // swim to center of target
325398 sbn::swimBNB (centroid1,sigma1,
0 commit comments