forked from JeffersonLab/SBS-offline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SBSGEMTrackerBase.cxx
3363 lines (2474 loc) · 138 KB
/
SBSGEMTrackerBase.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
#include "SBSGEMTrackerBase.h"
#include "SBSGEMModule.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TRotation.h"
#include "TClonesArray.h"
//#include "THaTrack.h"
#include "TSystem.h"
#include <sstream>
#include <iomanip>
#include <cstdlib>
#include "Helper.h"
using namespace std;
SBSGEMTrackerBase::SBSGEMTrackerBase(){ //Set default values of important parameters:
Clear();
fPedestalMode = false;
fSubtractPedBeforeCommonMode = false; //only applies to pedestal-mode analysis; default to false
fIsMC = false;
fNmodules = 0;
fNlayers = 0;
fTrackingAlgorithmFlag = 2;
fMinHitsOnTrack = 3;
//fMinHighQualityHitsOnTrack = 0;
fMinHighQualityHitsOnTrack.clear();
fMinHighQualityHitsOnTrack.resize(1,0); //default to no "high quality" hits required
fMaxHitCombinations = 10000;
fMaxHitCombinations_InnerLayers = 100000;
fMaxHitCombinations_Total = 1.e16;
fTryFastTrack = true;
//moved zero suppression/common-mode parameters to module class
// fOnlineZeroSuppression = false;
// fZeroSuppress = true;
// fZeroSuppressRMS = 5.0; //5 sigma
fGridBinWidthX = 0.01; //1 cm = 10 mm;
fGridBinWidthY = 0.01; //1 cm = 10 mm;
fGridEdgeToleranceX = 0.003; //3 mm default
fGridEdgeToleranceY = 0.003; //3 mm default
fUseEnhancedChi2 = 0; //Default to zero. If 1, use the same of spatial chi2 and "hit quality" chi2 as criterion for best track selection
//fTrackChi2Cut = 100.0; //Max. chi2/ndf for a combination of hits to form a track
//fTrackChi2CutHitQuality = 100.0; //Max. chi2/ndf for track "hit quality" (ADC and time correlation of U/V hits).
fTrackChi2Cut.clear();
fTrackChi2Cut.resize(1,100.0);
fTrackChi2CutHitQuality.clear();
fTrackChi2CutHitQuality.resize(1,100.0);
fSigma_hitpos = 0.0001; //100 um
// set defaults for constraint points and constraint widths:
fConstraintPoint_Front.SetXYZ(0,0,-10.0);
fConstraintPoint_Back.SetXYZ(0,0,10.0);
//wide-open constraints for now (the units are meters here (mm or cm would be more natural but whatever))
fConstraintWidth_Front.Set( 1.5, 0.5 );
fConstraintWidth_Back.Set( 1.5, 0.5 );
//Default to wide-open track slope cuts:
fConstraintWidth_theta = 1000.0;
fConstraintWidth_phi = 1000.0;
fEfficiencyInitialized = false;
fMakeEfficiencyPlots = true;
fModulesInitialized = false;
fpedfilename = "";
fcmfilename = "";
fBinSize_efficiency2D = 0.01; //1 cm
fBinSize_efficiency1D = 0.003; //3 mm
fDumpGeometryInfo = false;
fIsSpectrometerTracker = true; //default to true
fIsPolarimeterTracker = false;
fUseOpticsConstraint = false;
//fUseFrontTrackerConstraint =false;
fNegSignalStudy = false;
fPmin_track = 0.5; //GeV
fPmax_track = 11.0; //GeV
//set defaults for these parameters fairly wide-open:
fxptarmin_track = -0.5;
fxptarmax_track = 0.5;
fyptarmin_track = -0.25;
fyptarmax_track = 0.25;
fytarmin_track = -0.3; //m
fytarmax_track = 0.3; //m
fUseSlopeConstraint = false;
fxpfpmin = -0.5;
fxpfpmax = 0.5;
fypfpmin = -0.2;
fypfpmax = 0.2;
fCommonModePlotsFlag = 0;
fCommonModePlotsFlagIsSet = false;
fUseForwardOpticsConstraint = false;
//default values for forward optics constraint center and width:
fdxfp0 = fdyfp0 = fdxpfp0 = fdypfp0 = 0.0;
fdxfpcut = 0.05;
fdyfpcut = 0.05;
fdxpfpcut = 0.01;
fdypfpcut = 0.01;
fUseTrigTime = false;
fSigmaTrackT0 = 5.0;
fCutTrackT0 = 1000.0; //default to some large value
}
SBSGEMTrackerBase::~SBSGEMTrackerBase(){
//This is best done here to ensure fModules still exists when it is cleared
DeleteContainer(fModules);
}
void SBSGEMTrackerBase::Clear(){ //Clear out any event-specific stuff
//Also, when we construct the tracker, we want to clear out the modules:
//fModules.clear(); we actually DON'T want to clear out the modules here, this gets called event-by-event
fConstraintPoint_Front_IsInitialized = false;
fConstraintPoint_Back_IsInitialized = false;
fConstraintWidth_Front_IsInitialized = false;
fConstraintWidth_Back_IsInitialized = false;
fConstraintInitialized = false;
fNtracks_found = 0;
fNhitsOnTrack.clear();
fNgoodhitsOnTrack.clear();
fModListTrack.clear();
fHitListTrack.clear();
fresidu_hits.clear();
fresidv_hits.clear();
feresidu_hits.clear();
feresidv_hits.clear();
fXtrack.clear();
fYtrack.clear();
fXptrack.clear();
fYptrack.clear();
fT0track.clear();
fChi2Track.clear();
fChi2TrackHitQuality.clear();
fNgoodhits = 0;
fHitTrackIndex.clear();
fHitModule.clear();
fHitLayer.clear();
fHitNstripsU.clear();
fHitUstripMax.clear();
fHitUstripLo.clear();
fHitUstripHi.clear();
fHitNstripsV.clear();
fHitVstripMax.clear();
fHitVstripLo.clear();
fHitVstripHi.clear();
fHitUlocal.clear();
fHitVlocal.clear();
fHitXlocal.clear();
fHitYlocal.clear();
fHitXglobal.clear();
fHitYglobal.clear();
fHitZglobal.clear();
fHitUmoment.clear();
fHitVmoment.clear();
fHitUsigma.clear();
fHitVsigma.clear();
fHitResidU.clear();
fHitResidV.clear();
fHitEResidU.clear();
fHitEResidV.clear();
fHitUADC.clear();
fHitVADC.clear();
//
fHitUADCclust_deconv.clear();
fHitVADCclust_deconv.clear();
fHitUADCclust_maxsamp_deconv.clear();
fHitVADCclust_maxsamp_deconv.clear();
fHitUADCclust_maxcombo_deconv.clear();
fHitVADCclust_maxcombo_deconv.clear();
//
fHitUADCmaxstrip.clear();
fHitVADCmaxstrip.clear();
fHitUADCmaxstrip_deconv.clear();
fHitVADCmaxstrip_deconv.clear();
fHitUADCmaxcombo_deconv.clear();
fHitVADCmaxcombo_deconv.clear();
fHitUADCmaxsample.clear();
fHitVADCmaxsample.clear();
fHitUADCmaxsample_deconv.clear();
fHitVADCmaxsample_deconv.clear();
fHitUADCmaxclustsample.clear();
fHitVADCmaxclustsample.clear();
fHitUgain.clear();
fHitVgain.clear();
fHitADCasym.clear();
fHitADCavg.clear();
fHitADCasym_deconv.clear();
fHitADCavg_deconv.clear();
fHitUTime.clear();
fHitVTime.clear();
fHitUTimeDeconv.clear();
fHitVTimeDeconv.clear();
fHitUTimeFit.clear();
fHitVTimeFit.clear();
fHitUTimeMaxStrip.clear();
fHitVTimeMaxStrip.clear();
fHitUTimeMaxStripFit.clear();
fHitVTimeMaxStripFit.clear();
fHitUTimeMaxStripDeconv.clear();
fHitVTimeMaxStripDeconv.clear();
fHitDeltaT.clear();
fHitTavg.clear();
fHitDeltaTDeconv.clear();
fHitTavgDeconv.clear();
fHitDeltaTFit.clear();
fHitTavgFit.clear();
fHitTavgCorrected.clear();
fHitIsampMaxUclust.clear();
fHitIsampMaxVclust.clear();
fHitIsampMaxUstrip.clear();
fHitIsampMaxVstrip.clear();
fHitIsampMaxUstripDeconv.clear();
fHitIsampMaxVstripDeconv.clear();
fHitIcomboMaxUstripDeconv.clear();
fHitIcomboMaxVstripDeconv.clear();
fHitIsampMaxUclustDeconv.clear();
fHitIsampMaxVclustDeconv.clear();
fHitIcomboMaxUclustDeconv.clear();
fHitIcomboMaxVclustDeconv.clear();
fHitCorrCoeffClust.clear();
fHitCorrCoeffMaxStrip.clear();
fHitCorrCoeffClustDeconv.clear();
fHitCorrCoeffMaxStripDeconv.clear();
fHitU_ENABLE_CM.clear();
fHitU_CM_GOOD.clear();
fHitU_BUILD_ALL_SAMPLES.clear();
fHitV_ENABLE_CM.clear();
fHitV_CM_GOOD.clear();
fHitV_BUILD_ALL_SAMPLES.clear();
fHitADCfrac0_MaxUstrip.clear();
fHitADCfrac1_MaxUstrip.clear();
fHitADCfrac2_MaxUstrip.clear();
fHitADCfrac3_MaxUstrip.clear();
fHitADCfrac4_MaxUstrip.clear();
fHitADCfrac5_MaxUstrip.clear();
fHitADCfrac0_MaxVstrip.clear();
fHitADCfrac1_MaxVstrip.clear();
fHitADCfrac2_MaxVstrip.clear();
fHitADCfrac3_MaxVstrip.clear();
fHitADCfrac4_MaxVstrip.clear();
fHitADCfrac5_MaxVstrip.clear();
fHitDeconvADC0_MaxUstrip.clear();
fHitDeconvADC1_MaxUstrip.clear();
fHitDeconvADC2_MaxUstrip.clear();
fHitDeconvADC3_MaxUstrip.clear();
fHitDeconvADC4_MaxUstrip.clear();
fHitDeconvADC5_MaxUstrip.clear();
fHitDeconvADC0_MaxVstrip.clear();
fHitDeconvADC1_MaxVstrip.clear();
fHitDeconvADC2_MaxVstrip.clear();
fHitDeconvADC3_MaxVstrip.clear();
fHitDeconvADC4_MaxVstrip.clear();
fHitDeconvADC5_MaxVstrip.clear();
fHitTSchi2MaxUstrip.clear();
fHitTSchi2MaxVstrip.clear();
fHitTSprobMaxUstrip.clear();
fHitTSprobMaxVstrip.clear();
fclustering_done = false;
ftracking_done = false;
//fTrigTime = 0.0;
}
//This is called by the Init() methods of derived classes:
void SBSGEMTrackerBase::CompleteInitialization(){
fLayers.clear();
fLayerByIndex.clear();
fNumModulesByLayer.clear();
fModuleListByLayer.clear();
//loop on the array of (initialized) modules and fill out missing info:
bool cm_already_loaded = false;
std::set<int> layersfromDB;
std::map<int,std::set<int> > modlistlayersDB;
for( int imod=0; imod<(int)fModules.size(); imod++ ){
int layer = fModules[imod]->fLayer;
//fLayers.insert( layer );
layersfromDB.insert( layer );
modlistlayersDB[layer].insert( imod );
//fModuleListByLayer[layer].insert( imod );
fModules[imod]->fIsMC = fIsMC;
fModules[imod]->fMakeEfficiencyPlots = fMakeEfficiencyPlots;
fModules[imod]->fPedestalMode = fPedestalMode;
fModules[imod]->fSubtractPedBeforeCommonMode = fSubtractPedBeforeCommonMode;
// std::cout << "Module " << fModules[imod]->GetName() << ": pedestalmode = " << fPedestalMode
// << ", Subtract ped. before common mode = " << fSubtractPedBeforeCommonMode << std::endl;
//fModules[imod]->fZeroSuppress = !fPedestalMode;
//moved "zero suppress" flag to GEMModule
fModules[imod]->fBinSize_efficiency1D = fBinSize_efficiency1D;
fModules[imod]->fBinSize_efficiency2D = fBinSize_efficiency2D;
if( fCommonModePlotsFlagIsSet ){
fModules[imod]->SetMakeCommonModePlots( fCommonModePlotsFlag );
}
for(int iAPV = 0; iAPV < fModules[imod]->fNAPVs_U; iAPV++)
if(fModules[imod]->fCommonModeMeanU[iAPV] > 1.0) cm_already_loaded = true;
}
int layerindex=0;
// this makes sure that all uniquely defined module <--> layer assignments
// map from 0 to Nlayers - 1 regardless of what the user put in the DB:
fLayerByIndex.clear();
fIndexByLayer.clear();
for( auto ilay : layersfromDB ){
fLayers.insert( layerindex );
for ( auto imod : modlistlayersDB[ilay] ){
fModuleListByLayer[layerindex].insert( imod );
fModules[imod]->fLayer = layerindex;
}
//These are no longer necessary but we'll keep them for the moment until changes are debugged:
fIndexByLayer[layerindex] = layerindex;
fLayerByIndex.push_back( layerindex );
fNumModulesByLayer[layerindex] = fModuleListByLayer[layerindex].size();
layerindex++;
}
fNmodules = fModules.size();
fNlayers = fLayers.size();
fNstripsU_layer.resize( fNlayers );
fNstripsV_layer.resize( fNlayers );
fNstripsU_layer_neg.resize( fNlayers );
fNstripsV_layer_neg.resize( fNlayers );
fNstripsU_layer_neg_miss.resize( fNlayers );
fNstripsV_layer_neg_miss.resize( fNlayers );
fNstripsU_layer_neg_hit.resize( fNlayers );
fNstripsV_layer_neg_hit.resize( fNlayers );
fNclustU_layer.resize( fNlayers );
fNclustV_layer.resize( fNlayers );
fNclustU_layer_neg.resize( fNlayers );
fNclustV_layer_neg.resize( fNlayers );
fN2Dhit_layer.resize( fNlayers );
fDidHit_Module.resize( fNmodules );
fShouldHit_Module.resize( fNmodules );
// fIndexByLayer.clear();
// int layerindex=0;
// for(int layer : fLayers){
// fLayerByIndex.push_back( layer ); //this is a vector version of the layer list, unless the user has defined something weird, layer[layerindex] = layerindex for layerindex = 0, ..., Nlayers-1
// fIndexByLayer[layer] = layerindex;
// fNumModulesByLayer[layer] = fModuleListByLayer[layer].size();
// layerindex++;
// }
//make sure the user has defined something sensible:
fMinHitsOnTrack = std::max(3,std::min(fNlayers,fMinHitsOnTrack) );
// Now initialize the min high quality hits and track chi2 cuts if
// the initialization from the database is not sensible:
if( fMinHighQualityHitsOnTrack.size() != fNlayers-fMinHitsOnTrack+1 ){
if( fMinHighQualityHitsOnTrack.size() >= 1 ){
int minhitstemp = std::max(0,std::min(fNlayers, fMinHighQualityHitsOnTrack[0]));
fMinHighQualityHitsOnTrack.clear();
fMinHighQualityHitsOnTrack.resize( fNlayers-fMinHitsOnTrack+1, minhitstemp );
} else { //empty, set default:
fMinHighQualityHitsOnTrack.resize( fNlayers-fMinHitsOnTrack+1, 0 );
}
}
if( fTrackChi2Cut.size() != fNlayers-fMinHitsOnTrack+1 ){
if( fTrackChi2Cut.size() >= 1 ){
double cuttemp = fTrackChi2Cut[0];
fTrackChi2Cut.clear(); //re-initialize all entries with cuttemp:
fTrackChi2Cut.resize( fNlayers-fMinHitsOnTrack+1, cuttemp );
} else { //empty, set default:
fTrackChi2Cut.resize( fNlayers-fMinHitsOnTrack+1, 100.0 );
}
}
if( fTrackChi2CutHitQuality.size() != fNlayers-fMinHitsOnTrack+1 ){
if( fTrackChi2CutHitQuality.size() >= 1 ){
double cuttemp = fTrackChi2CutHitQuality[0];
fTrackChi2CutHitQuality.clear(); //re-initialize all entries with cuttemp:
fTrackChi2CutHitQuality.resize( fNlayers-fMinHitsOnTrack+1, cuttemp );
} else { //empty, set default:
fTrackChi2CutHitQuality.resize( fNlayers-fMinHitsOnTrack+1, 100.0 );
}
}
InitLayerCombos();
InitGridBins();
// Now make the "hit list" arrays at least fixed-size in terms of the number of layers
N2Dhits_layer.resize( fNlayers );
modindexhit2D.resize( fNlayers );
clustindexhit2D.resize( fNlayers );
hitused2D.resize( fNlayers );
gridbinhit2D.resize( fNlayers );
// size "free hit" list arrays:
Nfreehits_layer.resize( fNlayers );
freehitlist_layer.resize( fNlayers );
Nfreehits_binxy_layer.resize( fNlayers );
freehitlist_binxy_layer.resize( fNlayers );
binswithfreehits_layer.resize( fNlayers );
freehitlist_goodxy.resize( fNlayers );
for( int ilayer=0; ilayer<fNlayers; ilayer++ ){
int ngridbins = fGridNbinsX_layer[ilayer]*fGridNbinsY_layer[ilayer];
Nfreehits_binxy_layer[ilayer].resize( ngridbins );
freehitlist_binxy_layer[ilayer].resize( ngridbins );
}
if( !fpedfilename.empty() ){ //load pedestals from file; NOTE: This OVERRIDES any pedestals found in the database
//NOTE: if we load the pedestals from a file formatted in the way the DAQ wants, then we have to assume that SLOT, MPD_ID, and ADC_CH are sufficient to uniquely identify
LoadPedestals( fpedfilename.c_str() );
}
if( !fcmfilename.empty() && !cm_already_loaded){ //load CM from file; NOTE: This OVERRIDES any pedestals found in the database
if(!cm_already_loaded) LoadCM( fcmfilename.c_str() );
}
}
void SBSGEMTrackerBase::LoadPedestals( const char *fname ){
std::cout << "[SBSGEMTrackerBase::LoadPedestals]: fname = " << fname << std::endl;
TString pedfilename = fname;
TString prefix = std::getenv("DB_DIR");
prefix += "/";
if( gSystem->AccessPathName( fname ) ){ //
std::cout << "[SBSGEMTrackerBase::LoadPedestals]: could not find " << fname << " in working directory, looking in " << prefix << std::endl;
pedfilename.Prepend(prefix);
}
std::ifstream pedfile( pedfilename.Data() );
if( !pedfile.good() ){
pedfile.close();
std::cout << "Warning: could not find ped file " << fname << " in working directory or in " << prefix << ", pedestals not loaded" << std::endl;
return;
} else {
std::cout << "Found pedestal file " << pedfilename << endl;
}
//temporary storage for pedestals loaded from file:
//vector<int> Slot, MPD, ADC_ch, APV_ch;
//vector<double> pedmean, pedrms;
//let's define a unique index as
// index = apvchan + 128*adc_ch + 16*128*MPD +
//map by slot, MPD, and adc_ch
//std::map<int, std::map<int,std::vector<int> > > Slot;
std::map<int, std::map<int, std::map<int,std::vector<double> > > > PedMean;
std::map<int, std::map<int, std::map<int,std::vector<double> > > > PedRMS;
std::map<int, std::map<int, std::map<int,std::vector<int> > > > APVChan;
// std::map<int, std::map<int,std::vector<int> > > APVChan;
//parse the file: Let's do this a bit more intelligently using TString:
std::string currentline;
int crate=0, slot=0, mpd=0, adc_ch=0;
while( std::getline(pedfile, currentline) ){
//TString currentline;
if( pedfile.eof() ) break;
if( currentline[0] != '#' ){
std::istringstream is(currentline);
string dummy;
if ( currentline.find("APV") == 0 ){
is >> dummy >> crate >> slot >> mpd >> adc_ch;
//std::cout << "crate, slot, mpd, adc_ch = " << crate << ", " << slot << ", " << mpd << ", " << adc_ch << std::endl;
} else {
int index = adc_ch + 16*mpd;
int apvchan;
double mean, rms;
//for( UInt_t i=0; i<128; i++ ){
is >> apvchan >> mean >> rms;
//std::cout << "apvchan, mean, rms = " << apvchan << ", " << mean << ", " << rms << std::endl;
PedMean[crate][slot][index].push_back( mean );
PedRMS[crate][slot][index].push_back( rms );
APVChan[crate][slot][index].push_back( apvchan );
// std::cout << "mapped value of (apvchan, mean, rms) = ( "
// << APVChan[crate][slot][index].back() << ", "
// << PedMean[crate][slot][index].back() << ", "
// << PedRMS[crate][slot][index].back() << ")" << std::endl;
}
}
}
//Now loop over the modules
for( int module=0; module<fNmodules; module++ ){
for ( auto it = fModules[module]->fMPDmap.begin(); it != fModules[module]->fMPDmap.end(); ++it ){
int this_crate = it->crate;
int this_index = it->adc_id + 16 * it->mpd_id;
int this_slot = it->slot;
//std::cout << "(crate, slot, index)=(" << this_crate << ", " << this_slot << ", " << this_index << ")" << std::endl;
if( PedMean.find( this_crate ) != PedMean.end() ){
//std::cout << "found crate " << this_crate << std::endl;
if( PedMean[this_crate].find( this_slot ) != PedMean[this_crate].end() ){
//std::cout << "found slot " << this_slot << std::endl;
if( PedMean[this_crate][this_slot].find( this_index ) != PedMean[this_crate][this_slot].end() ){
//std::cout << "found index " << this_index << std::endl;
for( int i=0; i<128; i++ ){
int this_apvchan = APVChan[this_crate][this_slot][this_index][i];
double this_mean = PedMean[this_crate][this_slot][this_index][i];
double this_rms = PedRMS[this_crate][this_slot][this_index][i];
int this_strip = fModules[module]->GetStripNumber( this_apvchan, it->pos, it->invert );
// std::cout << "axis, strip index, ped. mean, ped. rms = "
// << it->axis << ", " << this_strip << ", " << this_mean << ", " << this_rms
// << std::endl;
if ( it->axis == SBSGEM::kUaxis ){
fModules[module]->fPedestalU[this_strip] = this_mean;
fModules[module]->fPedRMSU[this_strip] = this_rms;
} else {
fModules[module]->fPedestalV[this_strip] = this_mean;
fModules[module]->fPedRMSV[this_strip] = this_rms;
}
}
}
}
}
}
}
}
void SBSGEMTrackerBase::LoadCM( const char *fname ){
std::cout << "[SBSGEMTrackerBase::LoadCM]: fname = " << fname << std::endl;
TString cmfilename = fname;
TString prefix = std::getenv("DB_DIR");
prefix += "/";
if( gSystem->AccessPathName( fname ) ){ //
std::cout << "[SBSGEMTrackerBase::LoadCM]: could not find " << fname << " in working directory, looking in " << prefix << std::endl;
cmfilename.Prepend(prefix);
}
std::ifstream cmfile( cmfilename.Data() );
if( !cmfile.good() ){
cmfile.close();
std::cout << "Warning: could not find CM file " << fname << " in working directory or in " << prefix << ", CM not loaded" << std::endl;
return;
} else {
std::cout << "Found CM file " << cmfilename << endl;
}
std::map<int, std::map<int, std::map<int,double > > > CMMean;
std::map<int, std::map<int, std::map<int,double > > > CMRMS;
std::string currentline;
int crate=0, slot=0, mpd=0, adc_ch=0;
double db_mean, db_rms;
while( std::getline(cmfile, currentline) ){
//TString currentline;
if( cmfile.eof() ) break;
std::istringstream is(currentline);
//File is formated like crate, slot, mpd, adc_ch, CM mean, CM RMS
is >> crate >> slot >> mpd >> adc_ch >> db_mean >> db_rms;
int index = adc_ch + 16*mpd;
//Assign CM mean and RMS for ever APV
CMMean[crate][slot][index] = db_mean;
CMRMS[crate][slot][index] = db_rms;
}
//Loop over all modules and APVs
for( int module=0; module<fNmodules; module++ ){
for ( auto it = fModules[module]->fMPDmap.begin(); it != fModules[module]->fMPDmap.end(); ++it ){
int this_crate = it->crate;
int this_index = it->adc_id + 16 * it->mpd_id;
int this_slot = it->slot;
int this_apv = it->pos; //This is the APV position used in the analyis
//std::cout << "(crate, slot, index)=(" << this_crate << ", " << this_slot << ", " << this_index << ")" << std::endl;
if( CMMean.find( this_crate ) != CMMean.end() ){
//std::cout << "found crate " << this_crate << std::endl;
if( CMMean[this_crate].find( this_slot ) != CMMean[this_crate].end() ){
//std::cout << "found slot " << this_slot << std::endl;
if( CMMean[this_crate][this_slot].find( this_index ) != CMMean[this_crate][this_slot].end() ){
//std::cout << "found index " << this_index << std::endl;
double this_mean = CMMean[this_crate][this_slot][this_index];
double this_rms = CMRMS[this_crate][this_slot][this_index];
//Set module APVs CM values from the arrays from the DB file
if ( it->axis == SBSGEM::kUaxis ){
fModules[module]->fCommonModeMeanU[this_apv] = this_mean;
fModules[module]->fCommonModeRMSU[this_apv] = this_rms;
} else {
fModules[module]->fCommonModeMeanV[this_apv] = this_mean;
fModules[module]->fCommonModeRMSV[this_apv] = this_rms;
}
}
}
}
}
}
}
void SBSGEMTrackerBase::InitEfficiencyHistos(const char *dname){
if( fMakeEfficiencyPlots && !fEfficiencyInitialized ){
//Here is the place to book efficiency histograms by layer:
hdidhit_x_layer = new TClonesArray( "TH1D", fNlayers );
hdidhit_y_layer = new TClonesArray( "TH1D", fNlayers );
hdidhit_xy_layer = new TClonesArray( "TH2D", fNlayers );
hshouldhit_x_layer = new TClonesArray( "TH1D", fNlayers );
hshouldhit_y_layer = new TClonesArray( "TH1D", fNlayers );
hshouldhit_xy_layer = new TClonesArray( "TH2D", fNlayers );
hefficiency_x_layer = new TClonesArray( "TH1D", fNlayers );
hefficiency_y_layer = new TClonesArray( "TH1D", fNlayers );
hefficiency_xy_layer = new TClonesArray( "TH2D", fNlayers );
hdidnothit_x_layer = new TClonesArray( "TH1D", fNlayers );
hdidnothit_y_layer = new TClonesArray( "TH1D", fNlayers );
hdidhit_x_layer = new TClonesArray( "TH1D", fNlayers );
hdidhit_y_layer = new TClonesArray( "TH1D", fNlayers );
hdidhit_fullreadout_x_layer = new TClonesArray( "TH1D", fNlayers );
hdidhit_fullreadout_y_layer = new TClonesArray( "TH1D", fNlayers );
hneghit_x_layer = new TClonesArray( "TH1D", fNlayers );
hneghit_y_layer = new TClonesArray( "TH1D", fNlayers );
hneghit1D_x_layer = new TClonesArray( "TH1D", fNlayers );
hneghit1D_y_layer = new TClonesArray( "TH1D", fNlayers );
hneghit_good_x_layer = new TClonesArray( "TH1D", fNlayers );
hneghit_good_y_layer = new TClonesArray( "TH1D", fNlayers );
hneghit_good1D_x_layer = new TClonesArray( "TH1D", fNlayers );
hneghit_good1D_y_layer = new TClonesArray( "TH1D", fNlayers );
TString histname;
TString detname = dname;
detname.ReplaceAll(".","_");
for( int ilayer=0; ilayer<fNlayers; ilayer++ ){
int nbinsx1D = int( round( (fXmax_layer[ilayer]-fXmin_layer[ilayer] + 0.02)/fBinSize_efficiency1D ) );
int nbinsy1D = int( round( (fYmax_layer[ilayer]-fYmin_layer[ilayer] + 0.02)/fBinSize_efficiency1D ) );
int nbinsx2D = int( round( (fXmax_layer[ilayer]-fXmin_layer[ilayer] + 0.02)/fBinSize_efficiency2D ) );
int nbinsy2D = int( round( (fYmax_layer[ilayer]-fYmin_layer[ilayer] + 0.02)/fBinSize_efficiency2D ) );
//TODO: don't hard-code the number of bins for these histograms:
new( (*hdidhit_x_layer)[ilayer] ) TH1D( histname.Format( "hdidhit_x_%s_layer%d", detname.Data(), ilayer ), "x of hits on good tracks (m); x(m)", nbinsx1D, fXmin_layer[ilayer]-0.01, fXmax_layer[ilayer] + 0.01 );
new( (*hdidhit_y_layer)[ilayer] ) TH1D( histname.Format( "hdidhit_y_%s_layer%d", detname.Data(), ilayer ), "y of hits on good tracks (m); y(m)", nbinsy1D, fYmin_layer[ilayer]-0.01, fYmax_layer[ilayer] + 0.01 );
new( (*hdidhit_xy_layer)[ilayer] ) TH2D( histname.Format( "hdidhit_xy_%s_layer%d", detname.Data(), ilayer ), "x vs y of hits on good tracks (m); y(m); x(m)",
nbinsy2D, fYmin_layer[ilayer]-0.01, fYmax_layer[ilayer]+0.01,
nbinsx2D, fXmin_layer[ilayer]-0.01, fXmax_layer[ilayer]+0.01 );
new( (*hshouldhit_x_layer)[ilayer] ) TH1D( histname.Format( "hshouldhit_x_%s_layer%d", detname.Data(), ilayer ), "x of good track crossing layer (m); x(m)", nbinsx1D, fXmin_layer[ilayer]-0.01, fXmax_layer[ilayer] + 0.01 );
new( (*hshouldhit_y_layer)[ilayer] ) TH1D( histname.Format( "hshouldhit_y_%s_layer%d", detname.Data(), ilayer ), "y of good track crossing layer (m); y(m)", nbinsy1D, fYmin_layer[ilayer]-0.01, fYmax_layer[ilayer] + 0.01 );
new( (*hshouldhit_xy_layer)[ilayer] ) TH2D( histname.Format( "hshouldhit_xy_%s_layer%d", detname.Data(), ilayer ), "x vs y of good track crossing layer (m); y(m); x(m)",
nbinsy2D, fYmin_layer[ilayer]-0.01, fYmax_layer[ilayer]+0.01,
nbinsx2D, fXmin_layer[ilayer]-0.01, fXmax_layer[ilayer]+0.01 );
new( (*hefficiency_x_layer)[ilayer] ) TH1D( histname.Format( "hefficiency_x_%s_layer%d", detname.Data(), ilayer ), "track-based efficiency vs x (m), averaged over y; x(m); efficiency", nbinsx1D, fXmin_layer[ilayer]-0.01, fXmax_layer[ilayer] + 0.01 );
new( (*hefficiency_y_layer)[ilayer] ) TH1D( histname.Format( "hefficiency_y_%s_layer%d", detname.Data(), ilayer ), "track-based efficiency vs y (m), averaged over x; y(m); efficiency", nbinsy1D, fYmin_layer[ilayer]-0.01, fYmax_layer[ilayer] + 0.01 );
new( (*hefficiency_xy_layer)[ilayer] ) TH2D( histname.Format( "hefficiency_xy_%s_layer%d", detname.Data(), ilayer ), "track-based efficiency vs x, y; y(m); x(m)",
nbinsy2D, fYmin_layer[ilayer]-0.01, fYmax_layer[ilayer]+0.01,
nbinsx2D, fXmin_layer[ilayer]-0.01, fXmax_layer[ilayer]+0.01 );
new( (*hdidnothit_x_layer)[ilayer] ) TH1D( histname.Format( "hdidnothit_x_%s_layer%d", detname.Data(), ilayer ), "track-based efficiency vs x (m), averaged over y; x(m); efficiency", nbinsx1D, fXmin_layer[ilayer]-0.01, fXmax_layer[ilayer] + 0.01 );
new( (*hdidnothit_y_layer)[ilayer] ) TH1D( histname.Format( "hdidnothit_y_%s_layer%d", detname.Data(), ilayer ), "track-based efficiency vs y (m), averaged over x; y(m); efficiency", nbinsy1D, fYmin_layer[ilayer]-0.01, fYmax_layer[ilayer] + 0.01 );
new( (*hdidhit_fullreadout_x_layer)[ilayer] ) TH1D( histname.Format( "hdidhit_fullreadout_x_%s_layer%d", detname.Data(), ilayer ), "track-based efficiency vs x (m), averaged over y; x(m); efficiency", nbinsx1D, fXmin_layer[ilayer]-0.01, fXmax_layer[ilayer] + 0.01 );
new( (*hdidhit_fullreadout_y_layer)[ilayer] ) TH1D( histname.Format( "hdidhit_fullreadout_y_%s_layer%d", detname.Data(), ilayer ), "track-based efficiency vs y (m), averaged over x; y(m); efficiency", nbinsy1D, fYmin_layer[ilayer]-0.01, fYmax_layer[ilayer] + 0.01 );
new( (*hneghit_x_layer)[ilayer] ) TH1D( histname.Format( "hneghit_x_%s_layer%d", detname.Data(), ilayer ), "track-based efficiency vs x (m), averaged over y; x(m); efficiency", nbinsx1D, fXmin_layer[ilayer]-0.01, fXmax_layer[ilayer] + 0.01 );
new( (*hneghit_y_layer)[ilayer] ) TH1D( histname.Format( "hneghit_y_%s_layer%d", detname.Data(), ilayer ), "track-based efficiency vs y (m), averaged over x; y(m); efficiency", nbinsy1D, fYmin_layer[ilayer]-0.01, fYmax_layer[ilayer] + 0.01 );
new( (*hneghit1D_x_layer)[ilayer] ) TH1D( histname.Format( "hneghit1D_x_%s_layer%d", detname.Data(), ilayer ), "track-based efficiency vs x (m), averaged over y; x(m); efficiency", nbinsx1D, fXmin_layer[ilayer]-0.01, fXmax_layer[ilayer] + 0.01 );
new( (*hneghit1D_y_layer)[ilayer] ) TH1D( histname.Format( "hneghit1D_y_%s_layer%d", detname.Data(), ilayer ), "track-based efficiency vs y (m), averaged over x; y(m); efficiency", nbinsy1D, fYmin_layer[ilayer]-0.01, fYmax_layer[ilayer] + 0.01 );
new( (*hneghit_good_x_layer)[ilayer] ) TH1D( histname.Format( "hneghit_good_x_%s_layer%d", detname.Data(), ilayer ), "track-based efficiency vs x (m), averaged over y; x(m); efficiency", nbinsx1D, fXmin_layer[ilayer]-0.01, fXmax_layer[ilayer] + 0.01 );
new( (*hneghit_good_y_layer)[ilayer] ) TH1D( histname.Format( "hneghit_good_y_%s_layer%d", detname.Data(), ilayer ), "track-based efficiency vs y (m), averaged over x; y(m); efficiency", nbinsy1D, fYmin_layer[ilayer]-0.01, fYmax_layer[ilayer] + 0.01 );
new( (*hneghit_good1D_x_layer)[ilayer] ) TH1D( histname.Format( "hneghit_good1D_x_%s_layer%d", detname.Data(), ilayer ), "track-based efficiency vs x (m), averaged over y; x(m); efficiency", nbinsx1D, fXmin_layer[ilayer]-0.01, fXmax_layer[ilayer] + 0.01 );
new( (*hneghit_good1D_y_layer)[ilayer] ) TH1D( histname.Format( "hneghit_good1D_y_%s_layer%d", detname.Data(), ilayer ), "track-based efficiency vs y (m), averaged over x; y(m); efficiency", nbinsy1D, fYmin_layer[ilayer]-0.01, fYmax_layer[ilayer] + 0.01 );
}
fEfficiencyInitialized = true;
}
}
void SBSGEMTrackerBase::CalcEfficiency(){
if( !fMakeEfficiencyPlots ) return;
TString histname;
for( int i=0; i<fNlayers; i++ ){
( (TH1D*) (*hefficiency_x_layer)[i] )->Divide( ( (TH1D*) (*hdidhit_x_layer)[i] ), ( (TH1D*) (*hshouldhit_x_layer)[i] ) );
( (TH1D*) (*hefficiency_y_layer)[i] )->Divide( ( (TH1D*) (*hdidhit_y_layer)[i] ), ( (TH1D*) (*hshouldhit_y_layer)[i] ) );
( (TH2D*) (*hefficiency_xy_layer)[i] )->Divide( ( (TH2D*) (*hdidhit_xy_layer)[i] ), ( (TH2D*) (*hshouldhit_xy_layer)[i] ) );
}
}
//This only needs to be done ONCE (after loading the geometry from the database!)
void SBSGEMTrackerBase::InitLayerCombos() { //It is assumed that this will be called by the ReadDatabase/Init method of the derived classes after loading the necessary information from the database:
//Just in case:
fLayerCombinations.clear();
//Initialize the list of layer combinations by total number of layers on the combo:
for( int icombo=0; icombo<pow(2,fNlayers); icombo++ ){ //loop over all possible combinations of layers:
vector<int> layercombo; //temporary array to hold list of layers fired in combo
int nlayersoncombo=0; //count number of fired layers in combo
for( int ilayer=0; ilayer<fNlayers; ilayer++ ){ //loop over all layers
int testbit = pow(2,ilayer);
if( (testbit & icombo) != 0 ){ //bitwise AND of icombo and 2^ilayer nonzero:
nlayersoncombo++; //this layer is on the combo
layercombo.push_back( ilayer ); //add it to the list on this combo
}
}
if( nlayersoncombo >= fMinHitsOnTrack ){ //Only consider combinations of layers with at least the minimum number required
fLayerCombinations[nlayersoncombo].push_back( layercombo ); //Add this combo to the list of combos, mapped by the number of layers in the combination:
}
}
}
void SBSGEMTrackerBase::InitGridBins() {
//we assume that the database has already been read and the module geometry is already specified here:
//Loop over layers and modules within each layer, and set the size of the active area by layer:
//clear out any existing data, just in case:
fXmin_layer.clear();
fXmax_layer.clear();
fYmin_layer.clear();
fYmax_layer.clear();
fGridNbinsX_layer.clear();
fGridNbinsY_layer.clear();
//
fGridXmin_layer.clear();
fGridXmax_layer.clear();
fGridYmin_layer.clear();
fGridYmax_layer.clear();
for( int ilayer = 0; ilayer<fNlayers; ilayer++ ){
int layer = fLayerByIndex[ilayer];
std::set<int> modlist_layer = fModuleListByLayer[layer];
//Initialize grid active area for this layer:
double xgmin_all = 1.e12, ygmin_all = 1.e12, xgmax_all = -1.e12, ygmax_all = -1.e12;
double zsum = 0.0;
for( auto imod = modlist_layer.begin(); imod != modlist_layer.end(); ++imod ){
int module = *imod; //if the database is sensibly constructed, this should refer to the index in the array of modules:
SBSGEMModule *mtemp = fModules[module];
//Get origin coordinates:
TVector3 modpos = mtemp->GetOrigin();
//computation of average Z coordinate of modules in this layer:
zsum += modpos.Z();
//Get half-width of module along X and Y:
double Lx_mod = mtemp->GetXSize()/2.0;
double Ly_mod = mtemp->GetYSize()/2.0;
//get positions of the four corners of the active area (which is assumed rectangular for SBS GEMs):
TVector3 Corner1 = modpos - Lx_mod * mtemp->GetXax() - Ly_mod * mtemp->GetYax();
TVector3 Corner2 = modpos + Lx_mod * mtemp->GetXax() - Ly_mod * mtemp->GetYax();
TVector3 Corner3 = modpos - Lx_mod * mtemp->GetXax() + Ly_mod * mtemp->GetYax();
TVector3 Corner4 = modpos + Lx_mod * mtemp->GetXax() + Ly_mod * mtemp->GetYax();
//Check all four corners even though ONLY corners 1 and 3 are likely to define the minimum X
xgmin_all = Corner1.X() < xgmin_all ? Corner1.X() : xgmin_all;
xgmin_all = Corner2.X() < xgmin_all ? Corner2.X() : xgmin_all;
xgmin_all = Corner3.X() < xgmin_all ? Corner3.X() : xgmin_all;
xgmin_all = Corner4.X() < xgmin_all ? Corner4.X() : xgmin_all;
//Check all four corners even though ONLY corners 2 and 4 are likely to define the maximum X
xgmax_all = Corner1.X() > xgmax_all ? Corner1.X() : xgmax_all;
xgmax_all = Corner2.X() > xgmax_all ? Corner2.X() : xgmax_all;
xgmax_all = Corner3.X() > xgmax_all ? Corner3.X() : xgmax_all;
xgmax_all = Corner4.X() > xgmax_all ? Corner4.X() : xgmax_all;
//Check all four corners even though ONLY corners 1 and 2 are likely to define the minimum Y
ygmin_all = Corner1.Y() < ygmin_all ? Corner1.Y() : ygmin_all;
ygmin_all = Corner2.Y() < ygmin_all ? Corner2.Y() : ygmin_all;
ygmin_all = Corner3.Y() < ygmin_all ? Corner3.Y() : ygmin_all;
ygmin_all = Corner4.Y() < ygmin_all ? Corner4.Y() : ygmin_all;
//Check all four corners even though ONLY corners 3 and 4 are likely to define the maximum Y
ygmax_all = Corner1.Y() > ygmax_all ? Corner1.Y() : ygmax_all;
ygmax_all = Corner2.Y() > ygmax_all ? Corner2.Y() : ygmax_all;
ygmax_all = Corner3.Y() > ygmax_all ? Corner3.Y() : ygmax_all;
ygmax_all = Corner4.Y() > ygmax_all ? Corner4.Y() : ygmax_all;
fXmin_layer[layer] = xgmin_all;
fXmax_layer[layer] = xgmax_all;
fYmin_layer[layer] = ygmin_all;
fYmax_layer[layer] = ygmax_all;
} //end loop over list of modules in this layer
fZavgLayer[layer] = zsum/double( modlist_layer.size() );
fGridXmin_layer[layer] = fXmin_layer[layer] - 0.5*fGridBinWidthX;
int nbinsx = 0;
while( fGridXmin_layer[layer] + nbinsx * fGridBinWidthX < fXmax_layer[layer] + 0.5*fGridBinWidthX ){
nbinsx++;
}
fGridXmax_layer[layer] = fGridXmin_layer[layer] + nbinsx * fGridBinWidthX;
fGridNbinsX_layer[layer] = nbinsx;
fGridYmin_layer[layer] = fYmin_layer[layer] - 0.5*fGridBinWidthY;
int nbinsy = 0;
while( fGridYmin_layer[layer] + nbinsy * fGridBinWidthY < fYmax_layer[layer] + 0.5*fGridBinWidthY ){
nbinsy++;
}
fGridYmax_layer[layer] = fGridYmin_layer[layer] + nbinsy * fGridBinWidthY;
fGridNbinsY_layer[layer] = nbinsy;
} //end loop over layers
}
//Initialize the "hit list" arrays that are used by the track-finding algorithm: these arrays are UNCHANGING throughout the iterations of track-finding:
Double_t SBSGEMTrackerBase::InitHitList(){
//clear out any old information:
layers_with_2Dhits.clear();
layerswithfreehits.clear();
Double_t ncombos_all_layers=1;
for( int layer=0; layer<fNlayers; layer++ ){
//for speed, we want to resize all the hit list arrays to their maximum possible size (for this event) and
// then use operator[] to fill rather than push_back(), which is much slower:
//First, count the number of hits in this layer; that will also be the
//maximum possible size of the "free hit list by layer" and "hit list" arrays
int n2Dhits_tot = 0;
for( auto imod = fModuleListByLayer[layer].begin(); imod != fModuleListByLayer[layer].end(); ++imod ){
int module = *imod;
n2Dhits_tot += fModules[module]->fN2Dhits;
}
//std::cout << "layer, n2Dhits_tot = " << layer << ", " << n2Dhits_tot << std::endl;
modindexhit2D[layer].resize( n2Dhits_tot );
clustindexhit2D[layer].resize( n2Dhits_tot );
hitused2D[layer].resize( n2Dhits_tot );
gridbinhit2D[layer].resize( n2Dhits_tot );
freehitlist_layer[layer].resize( n2Dhits_tot );
N2Dhits_layer[layer] = 0;
Nfreehits_layer[layer] = 0;
binswithfreehits_layer[layer].clear();
int ngridbins = fGridNbinsX_layer[layer]*fGridNbinsY_layer[layer];
for( int ibin=0; ibin<ngridbins; ibin++ ){
Nfreehits_binxy_layer[layer][ibin] = 0;
freehitlist_binxy_layer[layer][ibin].clear(); //clear this out in case there might be something left over from a previous event!
}
//loop over the hits a second time, this time count up how many are "good"
int ngoodhits = 0;
for( auto imod = fModuleListByLayer[layer].begin(); imod != fModuleListByLayer[layer].end(); ++imod ){
int module = *imod;
int n2Dhits_mod = fModules[module]->fN2Dhits;
for( int ihit=0; ihit<n2Dhits_mod; ihit++ ){
sbsgemhit_t hittemp = fModules[module]->fHits[ihit];