@@ -126,9 +126,11 @@ public boolean init() {
126126 modelPrePID = new ModelPrePID ();
127127
128128 AlertTOFFactory factory = new AlertTOFFactory ();
129+
130+ // One CCDB session for both ATOF and AHDC geometry.
129131 DatabaseConstantProvider cp = new DatabaseConstantProvider (11 , "default" );
130132 ATOF = factory .createDetectorCLAS (cp );
131- AHDC = (new AlertDCFactory ()).createDetectorCLAS (new DatabaseConstantProvider () );
133+ AHDC = (new AlertDCFactory ()).createDetectorCLAS (cp );
132134
133135 Map <String , Integer > tableMap = new HashMap <>();
134136 tableMap .put ("/calibration/alert/ahdc/gains" , 3 );
@@ -330,50 +332,60 @@ public boolean processDataEvent(DataEvent event) {
330332 }
331333 if (interClusters .size () != 5 ) continue ;
332334
335+ float [] pred ;
333336 try {
337+ pred = modelTrackMatching .prediction (interClusters );
338+ } catch (TranslateException ex ) {
339+ LOGGER .warning (() -> "Exception in ALERTEngine track matching: " + ex );
340+ continue ;
341+ }
342+ int sector_pred = (int ) pred [0 ];
343+ int layer_pred = (int ) pred [1 ];
344+ int wedge_pred = (int ) pred [2 ];
345+
346+ // The matching model's three argmax heads can land outside the ATOF
347+ // ranges (sectors 0-14, layers 0-3, wedges 0-9) when the input
348+ // interclusters fall outside its training distribution; the ATOFHit
349+ // geometry lookup chain returns null on a miss and would NPE.
350+ if (sector_pred < 0 || sector_pred >= 15
351+ || layer_pred < 0 || layer_pred >= 4
352+ || wedge_pred < 0 || wedge_pred >= 10 ) {
353+ continue ;
354+ }
334355
335- float [] pred = modelTrackMatching .prediction (interClusters );
336- int sector_pred = (int ) pred [0 ];
337- int layer_pred = (int ) pred [1 ];
338- int wedge_pred = (int ) pred [2 ];
339-
340- ATOFHit hit_pred = new ATOFHit (sector_pred , layer_pred , wedge_pred , 0 , 0 , 0 , 0f , ATOF , null );
341- double pred_x = hit_pred .getX ();
342- double pred_y = hit_pred .getY ();
343- double pred_z = hit_pred .getZ ();
356+ ATOFHit hit_pred = new ATOFHit (sector_pred , layer_pred , wedge_pred , 0 , 0 , 0 , 0f , ATOF , null );
357+ double pred_x = hit_pred .getX ();
358+ double pred_y = hit_pred .getY ();
359+ double pred_z = hit_pred .getZ ();
344360
345- double threshold = 20.0 ;
346- double minDistanceSquared = threshold * threshold ;
361+ double threshold = 20.0 ;
362+ double minDistanceSquared = threshold * threshold ;
347363
348- ATOFHit matchAtofHit = null ; // Could be used later
349- int matchHitId = -1 ;
364+ ATOFHit matchAtofHit = null ; // Could be used later
365+ int matchHitId = -1 ;
350366
351- for (int k = 0 ; k < bank_ATOFHits .rows (); k ++) {
352- int component = bank_ATOFHits .getInt ("component" , k );
353- if (component == 10 ) continue ;
367+ for (int k = 0 ; k < bank_ATOFHits .rows (); k ++) {
368+ int component = bank_ATOFHits .getInt ("component" , k );
369+ if (component == 10 ) continue ;
354370
355- int sector = bank_ATOFHits .getInt ("sector" , k );
356- int layer = bank_ATOFHits .getInt ("layer" , k );
371+ int sector = bank_ATOFHits .getInt ("sector" , k );
372+ int layer = bank_ATOFHits .getInt ("layer" , k );
357373
358- ATOFHit hit = new ATOFHit (sector , layer , component , 0 , 0 , 0 , 0f , ATOF , null );
374+ ATOFHit hit = new ATOFHit (sector , layer , component , 0 , 0 , 0 , 0f , ATOF , null );
359375
360- double dx = pred_x - hit .getX ();
361- double dy = pred_y - hit .getY ();
362- double dz = pred_z - hit .getZ ();
376+ double dx = pred_x - hit .getX ();
377+ double dy = pred_y - hit .getY ();
378+ double dz = pred_z - hit .getZ ();
363379
364- double distanceSquared = dx * dx + dy * dy + dz * dz ;
380+ double distanceSquared = dx * dx + dy * dy + dz * dz ;
365381
366- if (distanceSquared < minDistanceSquared ) {
367- minDistanceSquared = distanceSquared ;
368- matchAtofHit = hit ;
369- matchHitId = bank_ATOFHits .getInt ("id" , k );
370- }
382+ if (distanceSquared < minDistanceSquared ) {
383+ minDistanceSquared = distanceSquared ;
384+ matchAtofHit = hit ;
385+ matchHitId = bank_ATOFHits .getInt ("id" , k );
371386 }
372- matched_ATOF_hit_id .add (new Pair <>(track_id , matchHitId ));
373-
374- } catch (Exception ex ) {
375- System .out .println ("Exception in ALERTEngine processDataEvent: " + ex ); // TODO: proper logging
376387 }
388+ matched_ATOF_hit_id .add (new Pair <>(track_id , matchHitId ));
377389 }
378390 rbc .appendTrackMatchingAIBank (event , matched_ATOF_hit_id );
379391
0 commit comments