forked from eutelescope/eutelescope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEUTelClusterFilter.cc
1520 lines (1248 loc) · 63.2 KB
/
EUTelClusterFilter.cc
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
// Author Antonio Bulgheroni, INFN <mailto:antonio.bulgheroni@gmail.com>
// Version $Id$
/*
* This source code is part of the Eutelescope package of Marlin.
* You are free to use this source files for your own development as
* long as it stays in a public research context. You are not
* allowed to use it for commercial purpose. You must put this
* header with author names in all development based on this file.
*
*/
// eutelescope includes ".h"
#include "EUTELESCOPE.h"
#include "EUTelVirtualCluster.h"
#include "EUTelFFClusterImpl.h"
#include "EUTelDFFClusterImpl.h"
#include "EUTelBrickedClusterImpl.h"
#include "EUTelSparseClusterImpl.h"
#include "EUTelRunHeaderImpl.h"
#include "EUTelEventImpl.h"
#include "EUTelClusterFilter.h"
#include "EUTelExceptions.h"
#include "EUTelROI.h"
#include "EUTelMatrixDecoder.h"
// marlin includes ".h"
#include "marlin/Processor.h"
#include "marlin/Exceptions.h"
// lcio includes <.h>
#include <IMPL/TrackerPulseImpl.h>
#include <IMPL/TrackerDataImpl.h>
#include <IMPL/TrackerRawDataImpl.h>
#include <IMPL/LCCollectionVec.h>
#include <UTIL/CellIDEncoder.h>
// system includes <>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <limits>
#include <iostream>
#include <iomanip>
#include <memory>
using namespace std;
using namespace lcio;
using namespace marlin;
using namespace eutelescope;
EUTelClusterFilter::EUTelClusterFilter () :Processor("EUTelClusterFilter") {
// modify processor description
_description = "EUTelClusterFilter is a very powerful tool. It allows to select among an input collection of TrackerPulse\n"
"only the clusters fulfilling a certain set of selection criteria.\n"
"The user can modify the switch on and off each selection cut and set the proper value for that via the processor parameter.";
// first of all we need to register the input collection
registerInputCollection (LCIO::TRACKERPULSE, "InputPulseCollectionName",
"This is the input Tracker Pulse collection that should be filtered",
_inputPulseCollectionName, string ("cluster"));
// since v00-00-09 both the status and noise collections become compulsory
registerInputCollection(LCIO::TRACKERDATA, "NoiseCollectionName",
"This is the name of the noise collection.\n"
"The presence of this collection in the event is allowing all the noise based selection cuts",
_noiseCollectionName, string( "noiseDB" ) );
registerInputCollection(LCIO::TRACKERRAWDATA,
"StatusCollectionName","This is the name of the status collection.\n"
"The presence of this collection in the event is allowing all the noise based selection cuts",
_statusCollectionName, string( "statusDB" ) );
// this is the output collection
registerOutputCollection (LCIO::TRACKERPULSE,"OutputPulseCollectionName",
"This is the output Tracker Pulse collection containing the filtered clusters",
_outputPulseCollectionName, string ("filteredcluster"));
// assuming 3 as the number of detectors
FloatVec minTotalChargeVecExample;
minTotalChargeVecExample.push_back(90);
minTotalChargeVecExample.push_back(75);
minTotalChargeVecExample.push_back(80);
registerProcessorParameter("ClusterMinTotalCharge", "This is the minimum allowed total charge in to a cluster.\n"
"One floating point number for each sensor in the telescope",
_minTotalChargeVec, minTotalChargeVecExample);
// again assuming 3 detectors
FloatVec minNChargeVecExample;
minNChargeVecExample.push_back(9); // this is the number of pixels in the cluster
minNChargeVecExample.push_back(90);
minNChargeVecExample.push_back(75);
minNChargeVecExample.push_back(80);
registerProcessorParameter("ClusterNMinCharge", "This is the minimum charge that a cluster of N pixels has to have.\n"
"The first figure has to be the number of pixels to consider in the cluster, \n"
"then one float number for each sensor.",
_minNChargeVec, minNChargeVecExample);
FloatVec minNSNRVecExample;
minNSNRVecExample.push_back(9); // this is the number of pixels in
// the cluster
minNSNRVecExample.push_back(25.0);
minNSNRVecExample.push_back(21.0);
minNSNRVecExample.push_back(20.0);
registerProcessorParameter("ClusterNMinSNR", "This is the minimum SNR that a cluster of N pixels has to have.\n"
"The first figure has to be the number of pixels to consider in the cluster, \n"
"then one float number for each sensor. Setting N = 0 is enough to disable the cut.",
_minNSNRVec, minNSNRVecExample);
// again for 3 planes
FloatVec minNxNChargeVecExample;
minNxNChargeVecExample.push_back(3);
minNxNChargeVecExample.push_back(0);
minNxNChargeVecExample.push_back(0);
minNxNChargeVecExample.push_back(0);
registerProcessorParameter("ClusterNxNMinCharge","This is the minimum charge that a cluster of N times N pixels has to have.\n"
"The first figure is the subcluster size in pixels (odd number), then one floating number for each \n"
"planes. To switch this selection off, set all numbers to zero.",
_minNxNChargeVec, minNxNChargeVecExample);
// again for 3 planes
FloatVec minNxNSNRVecExample;
minNxNSNRVecExample.push_back(3);
minNxNSNRVecExample.push_back(0);
minNxNSNRVecExample.push_back(0);
minNxNSNRVecExample.push_back(0);
registerProcessorParameter("ClusterNxNMinSNR","This is the minimum SNR that a cluster of N times N pixels has to have.\n"
"The first figure is the subcluster size in pixels (odd number), then one floating number for each \n"
"planes. To switch this selection off, set at least the first number to zero.",
_minNxNSNRVec, minNxNSNRVecExample);
FloatVec minSeedChargeVecExample;
minSeedChargeVecExample.push_back(20);
minSeedChargeVecExample.push_back(25);
minSeedChargeVecExample.push_back(21);
registerProcessorParameter("SeedMinCharge", "This is the minimum allowed charge that the seed pixel of a cluster has to have.\n"
"One floating number for each detector",
_minSeedChargeVec, minSeedChargeVecExample);
FloatVec minSeedSNRVecExample;
minSeedSNRVecExample.push_back(10);
minSeedSNRVecExample.push_back(12);
minSeedSNRVecExample.push_back(14);
registerProcessorParameter("SeedMinSNR", "This is the minimum allowed SNR that the seed pixel of a cluster has to have.\n"
"One floating number for each detector. Set to 0 to disable",
_minSeedSNRVec, minSeedSNRVecExample);
IntVec clusterQualityVecExample;
clusterQualityVecExample.push_back(0);
clusterQualityVecExample.push_back(0);
clusterQualityVecExample.push_back(0);
registerProcessorParameter("ClusterQuality", "This is the required quality for the cluster.\n"
"One integer number for each detector according to ClusterQuality.\n"
"Put a negative number to disable the cut",
_clusterQualityVec, clusterQualityVecExample);
FloatVec roiExample;
roiExample.push_back( -1 );
roiExample.push_back( 10. );
roiExample.push_back( 10. );
roiExample.push_back( 40. );
roiExample.push_back( 40. );
registerProcessorParameter("InsideRegion", "Define here ROI's. The first number (integer) is the detector ID.\n"
"The other four float are xBotLeft yBotLeft xTopRight yTopRight.\n"
"To disable it, just put a negative number as detector ID.",
_tempInsideROI, roiExample, roiExample.size() );
registerProcessorParameter("OutsideRegion","Define here ROI's. The first number (integer) is the detector ID.\n"
"The other four float are xBotLeft yBotLeft xTopRight yTopRight.\n"
"To disable it, just put a negative number as detector ID.",
_tempOutsideROI, roiExample, roiExample.size() );
IntVec minClusterNoVecExample;
minClusterNoVecExample.push_back(0);
minClusterNoVecExample.push_back(0);
minClusterNoVecExample.push_back(0);
registerProcessorParameter("MinClusterPerPlane", "This is the minimum required number of cluster per plane.\n"
"One integer number for each detector. Write 0 to disable the cut",
_minClusterNoVec, minClusterNoVecExample);
IntVec maxClusterNoVecExample;
maxClusterNoVecExample.push_back(-1);
maxClusterNoVecExample.push_back(-1);
maxClusterNoVecExample.push_back(-1);
registerProcessorParameter("MaxClusterPerPlane", "This is the maximum allowed number of cluster per plane.\n "
"One integer number for each detector. Write a negative number to disable the cut",
_maxClusterNoVec, maxClusterNoVecExample);
FloatVec maxClusterNoiseVecExample;
maxClusterNoiseVecExample.push_back(50.);
maxClusterNoiseVecExample.push_back(45.);
maxClusterNoiseVecExample.push_back(48.);
registerProcessorParameter("MaxClusterNoise", "This is maximum allowed cluster noise.\n"
"One floating number for each detector. Write a negative number to disable the cut",
_maxClusterNoiseVec, maxClusterNoiseVecExample );
FloatVec minTotalSNRVecExample;
minTotalSNRVecExample.push_back(10.);
minTotalSNRVecExample.push_back(12.);
minTotalSNRVecExample.push_back(11.);
registerProcessorParameter("MinTotalClusterSNR", "This is the minimum allow total cluster SNR\n"
"One floating number for each detector. Write 0 to disable the cut",
_minTotalSNRVec, minTotalSNRVecExample );
registerProcessorParameter("SameNumberOfHits", "Setting this to true will select only events having the same number \n"
"of hits for each plane.",
_sameNumberOfHitSwitch, static_cast<bool > (false) );
registerOptionalParameter("SkipEmptyEvent","If true, a SkipEventException is thrown if after selection\n"
"there are no cluster left.",
_skipEmptyEvent, static_cast<bool > ( false ) );
// set the global noise switch to on
_noiseRelatedCuts = true;
registerProcessorParameter("DFFNumberOfHits","This is a cut on the number of hit pixels inside the digital fixed frame\n"
"cluster algorithm. One cut for each sensor plane.\n",
_DFFNHitsCuts, std::vector<int>(9, 0) );
}
void EUTelClusterFilter::init () {
printParameters ();
// check and set properly the switches
// total cluster charge
if (count_if( _minTotalChargeVec.begin(), _minTotalChargeVec.end(), bind2nd(greater<float>(), 0) ) != 0 ) {
// ok there is at least one sensor for which this cut is on
_minTotalChargeSwitch = true;
} else {
_minTotalChargeSwitch = false;
}
streamlog_out( DEBUG2 ) << "MinTotalChargeSwitch " << _minTotalChargeSwitch << endl;
// N cluster charge
if ( !_minNChargeVec.empty() ) {
if ( _minNChargeVec[0] != 0 ) {
_minNChargeSwitch = true;
} else {
_minNChargeSwitch = false;
}
} else {
_minNChargeSwitch = false;
}
streamlog_out( DEBUG2 ) << "MinNChargeSwitch " << _minNChargeSwitch << endl;
// N cluster SNR
if ( (!_minNSNRVec.empty()) && (_minNSNRVec[0] != 0) ) {
_minNSNRSwitch = true;
} else {
_minNSNRSwitch = false;
}
streamlog_out( DEBUG2 ) << "MinNSNRSwitch " << _minNSNRSwitch << endl;
// NxN cluster charge
if ( ( count_if( _minNxNChargeVec.begin(), _minNxNChargeVec.end(), bind2nd(greater<float>(),0)) != 0 ) &&
( _minNxNChargeVec[0] != 0 ) ) {
_minNxNChargeSwitch = true;
} else {
_minNxNChargeSwitch = false;
}
streamlog_out( DEBUG2 ) << "MinNxNChargeSwitch " << _minNxNChargeSwitch << endl;
// NxN cluster SNR
if ( ( count_if( _minNxNSNRVec.begin(), _minNxNSNRVec.end(), bind2nd(greater<float>(),0)) != 0 ) &&
( _minNxNSNRVec[0] != 0 ) ) {
_minNxNSNRSwitch = true;
} else {
_minNxNSNRSwitch = false;
}
streamlog_out( DEBUG2 ) << "MinNxNSNRSwitch " << _minNxNSNRSwitch << endl;
// Seed charge
if ( count_if( _minSeedChargeVec.begin(), _minSeedChargeVec.end(), bind2nd(greater<float>(), 0) ) != 0 ) {
_minSeedChargeSwitch = true;
} else {
_minSeedChargeSwitch = false;
}
streamlog_out( DEBUG2 ) << "MinSeedChargeSwitch " << _minSeedChargeSwitch << endl;
// Seed SNR
if ( count_if( _minSeedSNRVec.begin(), _minSeedSNRVec.end(), bind2nd(greater<float >(), 0) ) != 0 ) {
_minSeedSNRSwitch = true;
} else {
_minSeedSNRSwitch = false;
}
streamlog_out( DEBUG2 ) << "MinSeedSNRSwitch " << _minSeedChargeSwitch << endl;
// Cluster quality
if ( count_if(_clusterQualityVec.begin(), _clusterQualityVec.end(), bind2nd(greater_equal<int>(), 0) ) != 0 ) {
_clusterQualitySwitch = true;
} else {
_clusterQualitySwitch = false;
}
streamlog_out( DEBUG2 ) << "ClusterQualitySwitch " << _clusterQualitySwitch << endl;
// Minimum cluster SNR
if ( count_if(_minTotalSNRVec.begin(), _minTotalSNRVec.end(), bind2nd(greater<float >(), 0) ) != 0 ) {
_minTotalSNRSwitch = true;
} else {
_minTotalSNRSwitch = false;
}
streamlog_out( DEBUG2 ) << "MinTotalSNRSwitch " << _minTotalSNRSwitch << endl;
// Minimum cluster number
if ( count_if(_minClusterNoVec.begin(), _minClusterNoVec.end(), bind2nd(greater<int>(), 0) ) != 0 ) {
_minClusterNoSwitch = true;
} else {
_minClusterNoSwitch = false;
}
streamlog_out ( DEBUG2 ) << "MinClusterNoSwitch " << _minClusterNoSwitch << endl;
// Maximum cluster number
if ( count_if(_maxClusterNoVec.begin(), _maxClusterNoVec.end(), bind2nd(greater<int>(), 0) ) != 0 ) {
_maxClusterNoSwitch = true;
vector<int >::iterator start = _maxClusterNoVec.begin();
while ( true ) {
start = find_if ( start, _maxClusterNoVec.end(), bind2nd(less<int>(), 0));
if ( start == _maxClusterNoVec.end() ) {
break;
} else {
(*start) = numeric_limits<int>::max();
}
}
} else {
_maxClusterNoSwitch = false;
}
// number of hit pixel inside a cluster for DFF cluser
if ( count_if(_DFFNHitsCuts.begin(), _DFFNHitsCuts.end(), bind2nd(greater<int>(), 0) ) != 0 ) {
_dffnhitsswitch = true;
} else {
_dffnhitsswitch = false;
}
streamlog_out( DEBUG2 ) << "MaxClusterNoSwitch " << _maxClusterNoSwitch << endl;
// inside ROI
vector<float>::iterator roiIter = _tempInsideROI.begin();
while ( roiIter != _tempInsideROI.end() ) {
int detectorID = static_cast<int> ( *roiIter++ );
float xBL = ( *roiIter++ );
float yBL = ( *roiIter++ );
float xTR = ( *roiIter++ );
float yTR = ( *roiIter++ );
if ( detectorID >= 0 ) {
EUTelROI roi( detectorID, xBL, yBL, xTR, yTR);
_insideROIVec.push_back( roi );
streamlog_out( DEBUG1 ) << roi << endl;
}
}
_insideROISwitch = ( !_insideROIVec.empty() );
streamlog_out( DEBUG2 ) << "InsideROISwitch " << _insideROISwitch << endl;
// outside ROI
roiIter = _tempOutsideROI.begin();
while ( roiIter != _tempOutsideROI.end() ) {
int detectorID = static_cast<int> ( *roiIter++ );
float xBL = ( *roiIter++ );
float yBL = ( *roiIter++ );
float xTR = ( *roiIter++ );
float yTR = ( *roiIter++ );
if ( detectorID >= 0 ) {
EUTelROI roi( detectorID, xBL, yBL, xTR, yTR);
_outsideROIVec.push_back( roi );
streamlog_out( DEBUG1 ) << roi << endl;
}
}
_outsideROISwitch = ( !_outsideROIVec.empty() );
streamlog_out( DEBUG2 ) << "OutsideROISwitch " << _outsideROISwitch << endl;
// max cluster noise
if ( count_if(_maxClusterNoiseVec.begin(), _maxClusterNoiseVec.end(), bind2nd(greater_equal<float >(), 0)) != 0 ) {
_maxClusterNoiseSwitch = true;
} else {
_maxClusterNoiseSwitch = false;
}
streamlog_out( DEBUG2 ) << "MaxClusterNoiseSwitch " << _maxClusterNoiseSwitch << endl;
streamlog_out( DEBUG2 ) << "SameNumberofHitSwitch " << _sameNumberOfHitSwitch << endl;
// set to zero the run and event counters
_iRun = 0;
_iEvt = 0;
_isFirstEvent = true;
}
void EUTelClusterFilter::initializeGeometry(LCEvent * event) {
// try the noise collection
try {
// get the noise collection
LCCollectionVec * noiseCollection = dynamic_cast< LCCollectionVec * > ( event->getCollection( _noiseCollectionName ) ) ;
// prepare a CellIDDecoder
CellIDDecoder< TrackerDataImpl > noiseDecoder( noiseCollection ) ;
// this is the size
_noOfDetectors = noiseCollection->size();
// clear the ancillaryIndexMap
_ancillaryIndexMap.clear();
for ( size_t iDetector = 0; iDetector < noiseCollection->size(); ++iDetector ) {
TrackerDataImpl * noise = dynamic_cast< TrackerDataImpl * > ( noiseCollection->getElementAt( iDetector ) );
int sensorID = noiseDecoder( noise )["sensorID"];
_ancillaryIndexMap.insert( make_pair( sensorID, iDetector ) );
}
} catch ( lcio::DataNotAvailableException ) {
// just catch it!
_noOfDetectors = 0;
}
}
void EUTelClusterFilter::checkCriteria() {
if ( _noOfDetectors == 0 ) {
// it means that the information is not available and the criteria
// can't be verified. Returning immediately
return ;
}
// reset the cluster counter
_totalClusterCounter.clear();
_acceptedClusterCounter.clear();
for ( size_t iDetector = 0; iDetector < _noOfDetectors; iDetector++ ) {
_totalClusterCounter.push_back(0);
_acceptedClusterCounter.push_back(0);
}
_rejectionMap.clear();
// check the consistency of selection thresholds
if ( _minTotalChargeSwitch ) {
if ( _minTotalChargeVec.size() != static_cast< unsigned >( _noOfDetectors ) ) {
streamlog_out ( ERROR1 ) << "The threshold vector on the total cluster charge did not match the right size \n"
<< "The number of planes is " << _noOfDetectors
<< " while the thresholds are " << _minTotalChargeVec.size() << "\n"
<< "Disabling the selection criterion and continue without" << endl;
_minTotalChargeSwitch = false;
} else {
streamlog_out ( DEBUG1 ) << "Total cluster charge criterion verified and switched on" << endl;
vector<unsigned int > rejectedCounter(_noOfDetectors, 0);
_rejectionMap.insert( make_pair("MinTotalChargeCut", rejectedCounter));
}
}
if ( _minTotalSNRSwitch ) {
if ( _minTotalSNRVec.size() != static_cast< unsigned >( _noOfDetectors ) ) {
streamlog_out ( ERROR1 ) << "The threshold vector on the total cluster SNR did not match the right size \n"
<< "The number of planes is " << _noOfDetectors
<< " while the thresholds are " << _minTotalSNRVec.size() << "\n"
<< "Disabling the selection criterion and continue without" << endl;
_minTotalSNRSwitch = false;
} else {
streamlog_out ( DEBUG1 ) << "Total cluster SNR criterion verified and switched on" << endl;
vector<unsigned int > rejectedCounter(_noOfDetectors, 0);
_rejectionMap.insert( make_pair("MinTotalSNRCut", rejectedCounter));
}
}
if ( _minNChargeSwitch ) {
unsigned int module = _noOfDetectors + 1;
if ( _minNChargeVec.size() % module != 0 ) {
streamlog_out ( ERROR1 ) << "The threshold vector for the N pixels charge did not match the right size \n "
<< "The number of planes is " << _noOfDetectors
<< " while the thresholds are " << _minNChargeVec.size() << "\n"
<< "Disabling the selection criterion and continue without" << endl;
_minNChargeSwitch = false;
} else {
streamlog_out ( DEBUG1 ) <<"N pixel charge criterion verified and switched on" << endl;
vector<unsigned int> rejectedCounter(_noOfDetectors, 0);
_rejectionMap.insert( make_pair("MinNChargeCut", rejectedCounter));
}
}
if ( _minNSNRSwitch ) {
unsigned int module = _noOfDetectors + 1;
if ( _minNSNRVec.size() % module != 0 ) {
streamlog_out ( ERROR1 ) << "The threshold vector for the N pixels SNR did not match the right size \n "
<< "The number of planes is " << _noOfDetectors
<< " while the thresholds are " << _minNSNRVec.size() << "\n"
<< "Disabling the selection criterion and continue without" << endl;
_minNSNRSwitch = false;
} else {
streamlog_out ( DEBUG1 ) <<"N pixel SNR criterion verified and switched on" << endl;
vector<unsigned int> rejectedCounter(_noOfDetectors, 0);
_rejectionMap.insert( make_pair("MinNSNRCut", rejectedCounter));
}
}
if ( _minNxNChargeSwitch ) {
unsigned int module = _noOfDetectors + 1;
if ( _minNxNChargeVec.size() % module != 0 ) {
streamlog_out ( ERROR1 ) << "The threshold vector for the N x N pixels charge did not match the right size \n "
<< "The number of planes is " << _noOfDetectors
<< " while the thresholds are " << _minNxNChargeVec.size() << "\n"
<< "Disabling the selection criterion and continue without" << endl;
_minNxNChargeSwitch = false;
} else {
streamlog_out ( DEBUG1 ) <<"NxN pixel charge criterion verified and switched on" << endl;
vector<unsigned int> rejectedCounter(_noOfDetectors, 0);
_rejectionMap.insert( make_pair("MinNxNChargeCut", rejectedCounter));
}
}
if ( _minNxNSNRSwitch ) {
unsigned int module = _noOfDetectors + 1;
if ( _minNxNSNRVec.size() % module != 0 ) {
streamlog_out ( ERROR1 ) << "The threshold vector for the N x N pixels SNR did not match the right size \n "
<< "The number of planes is " << _noOfDetectors
<< " while the thresholds are " << _minNxNSNRVec.size() << "\n"
<< "Disabling the selection criterion and continue without" << endl;
_minNxNSNRSwitch = false;
} else {
streamlog_out ( DEBUG1 ) <<"NxN pixel SNR criterion verified and switched on" << endl;
vector<unsigned int> rejectedCounter(_noOfDetectors, 0);
_rejectionMap.insert( make_pair("MinNxNSNRCut", rejectedCounter));
}
}
if ( _minSeedChargeSwitch ) {
if ( _minSeedChargeVec.size() != static_cast< unsigned >( _noOfDetectors ) ) {
streamlog_out ( ERROR1 ) << "The threshold vector on the seed charge did not match the right size \n"
<< "The number of planes is " << _noOfDetectors
<< " while the thresholds are " << _minSeedChargeVec.size()
<< "\n"
<< "Disabling the selection criterion and continue without" << endl;
_minSeedChargeSwitch = false;
} else {
streamlog_out ( DEBUG1 ) << "Seed charge criterion verified and switched on" << endl;
vector<unsigned int > rejectedCounter(_noOfDetectors, 0);
_rejectionMap.insert( make_pair("MinSeedChargeCut", rejectedCounter));
}
}
if ( _minSeedSNRSwitch ) {
if ( _minSeedSNRVec.size() != static_cast< unsigned >( _noOfDetectors )) {
streamlog_out ( ERROR1 ) << "The threshold vector on the seed SNR did not match the right size \n"
<< "The number of planes is " << _noOfDetectors << " while the thresholds are " << _minSeedSNRVec.size()
<< "\n"
<< "Disabling the selection criterion and continue without" << endl;
_minSeedSNRSwitch = false;
} else {
streamlog_out ( DEBUG1 ) << "Seed SNR criterion verified and switched on" << endl;
vector<unsigned int > rejectedCounter(_noOfDetectors, 0);
_rejectionMap.insert( make_pair("MinSeedSNRCut", rejectedCounter));
}
}
if ( _clusterQualitySwitch ) {
if ( _clusterQualityVec.size() != static_cast< unsigned >( _noOfDetectors )) {
streamlog_out ( ERROR1 ) << "The cluster quality vector did not match the right size \n"
<< "The number of planes is " << _noOfDetectors
<< " while the thresholds are " << _minSeedChargeVec.size()
<< "\n"
<< "Disabling the selection criterion and continue without" << endl;
_clusterQualitySwitch = false;
} else {
streamlog_out ( DEBUG1 ) << "Cluster quality criterion verified and switched on" << endl;
vector<unsigned int > rejectedCounter(_noOfDetectors, 0);
_rejectionMap.insert( make_pair("ClusterQualityCut", rejectedCounter ));
}
}
if ( _minClusterNoSwitch ) {
if ( _minClusterNoVec.size() != static_cast< unsigned >( _noOfDetectors )) {
streamlog_out ( ERROR1 ) << "The minimum cluster number vector did not match the right size \n"
<< "The number of planes is " << _noOfDetectors << " while the thresholds are "
<< _minClusterNoVec.size() << "\n"
<< "Disabling the selection criterion and continue without" << endl;
_minClusterNoSwitch = false;
} else {
streamlog_out ( DEBUG1 ) << "Minimum cluster number criterion verified and switched on" << endl;
vector<unsigned int > rejectedCounter(_noOfDetectors, 0);
_rejectionMap.insert( make_pair("MinClusterNoCut", rejectedCounter ));
}
}
if ( _maxClusterNoSwitch ) {
if ( _maxClusterNoVec.size() != static_cast< unsigned >( _noOfDetectors )) {
streamlog_out ( ERROR1 ) << "The maximum cluster number vector did not match the right size \n"
<< "The number of planes is " << _noOfDetectors
<< " while the thresholds are " << _maxClusterNoVec.size() << "\n"
<< "Disabling the selection criterion and continue without" << endl;
_maxClusterNoSwitch = false;
} else {
streamlog_out ( DEBUG1 ) << "Maximum cluster number criterion verified and switched on" << endl;
vector<unsigned int > rejectedCounter(_noOfDetectors, 0);
_rejectionMap.insert( make_pair("MaxClusterNoCut", rejectedCounter ));
}
}
if ( _maxClusterNoiseSwitch ) {
if ( _maxClusterNoiseVec.size() != static_cast< unsigned >( _noOfDetectors )) {
streamlog_out ( ERROR1 ) << "The maximum cluster noise vector did not match the right size \n"
<< "The number of planes is " << _noOfDetectors
<< " while the thresholds are " << _maxClusterNoiseVec.size() << "\n"
<< "Disabling the selection criterion and continue without" << endl;
_maxClusterNoSwitch = false;
} else {
streamlog_out ( DEBUG1 ) << "Maximum cluster noise criterion verified and switched on" << endl;
vector<unsigned int > rejectedCounter(_noOfDetectors, 0);
_rejectionMap.insert( make_pair("MaxClusterNoiseCut", rejectedCounter ));
}
}
if ( _dffnhitsswitch ) {
if ( _DFFNHitsCuts.size() != static_cast< unsigned >( _noOfDetectors )) {
streamlog_out ( ERROR1 ) << "The minimum hit pixel vector did not match the right size \n"
<< "The number of planes is " << _noOfDetectors << " while the thresholds are "
<< _DFFNHitsCuts.size() << "\n"
<< "Disabling the selection criterion and continue without" << endl;
_dffnhitsswitch = false;
} else {
streamlog_out ( DEBUG1 ) << "Minimum hit pixel number criterion verified and switched on" << endl;
vector<unsigned int > rejectedCounter(_noOfDetectors, 0);
_rejectionMap.insert( make_pair("MinHitPixel", rejectedCounter ));
}
}
if ( _insideROISwitch ) {
streamlog_out ( DEBUG1 ) << "Inside ROI criterion verified and switched on" << endl;
vector<unsigned int > rejectedCounter( _noOfDetectors, 0 );
_rejectionMap.insert( make_pair("InsideROICut", rejectedCounter ));
}
if ( _outsideROISwitch ) {
streamlog_out ( DEBUG1 ) << "Outside ROI criterion verified and switched on" << endl;
vector<unsigned int > rejectedCounter( _noOfDetectors, 0 );
_rejectionMap.insert( make_pair("OutsideROICut", rejectedCounter ));
}
if ( _sameNumberOfHitSwitch ) {
streamlog_out ( DEBUG1 ) << "Same number of hits criterion verified and switched on" << endl;
vector<unsigned int > rejectedCounter( _noOfDetectors, 0 );
_rejectionMap.insert( make_pair("SameNumberOfHitCut", rejectedCounter ));
}
}
void EUTelClusterFilter::processRunHeader (LCRunHeader * rdr) {
// increment the run counter
++_iRun;
if ( isFirstEvent() ) {
auto_ptr<EUTelRunHeaderImpl> runHeader ( new EUTelRunHeaderImpl( rdr ) ) ;
runHeader->addProcessor( type() ) ;
}
}
void EUTelClusterFilter::processEvent (LCEvent * event) {
++_iEvt;
if ( isFirstEvent() )
{
// try to guess the total number of sensors
initializeGeometry( event );
checkCriteria();
_isFirstEvent = false;
}
EUTelEventImpl * evt = static_cast<EUTelEventImpl*> ( event );
if ( evt->getEventType() == kEORE )
{
streamlog_out ( DEBUG4 ) << "EORE found: nothing else to do." << endl;
return ;
}
else if ( evt->getEventType() == kUNKNOWN )
{
streamlog_out ( WARNING2 ) << "Event number " << evt->getEventNumber() << " in run " << evt->getRunNumber()
<< " is of unknown type. Continue considering it as a normal Data Event." << endl;
}
try
{
LCCollectionVec * pulseCollectionVec = dynamic_cast <LCCollectionVec *> (evt->getCollection(_inputPulseCollectionName));
LCCollectionVec * filteredCollectionVec = new LCCollectionVec(LCIO::TRACKERPULSE);
CellIDEncoder<TrackerPulseImpl> outputEncoder(EUTELESCOPE::PULSEDEFAULTENCODING, filteredCollectionVec);
CellIDDecoder<TrackerPulseImpl> inputDecoder(pulseCollectionVec);
vector<int > acceptedClusterVec;
vector<int > clusterNoVec(_noOfDetectors, 0);
// CLUSTER BASED CUTS
for ( int iPulse = 0; iPulse < pulseCollectionVec->getNumberOfElements(); iPulse++ )
{
streamlog_out ( DEBUG1 ) << "Filtering cluster " << iPulse + 1 << " / " << pulseCollectionVec->getNumberOfElements() << endl;
TrackerPulseImpl * pulse = dynamic_cast<TrackerPulseImpl* > (pulseCollectionVec->getElementAt(iPulse));
ClusterType type = static_cast<ClusterType> (static_cast<int> ( inputDecoder(pulse)["type"] ));
EUTelVirtualCluster * cluster;
SparsePixelType pixelType;
if ( type == kEUTelDFFClusterImpl )
{
cluster = new EUTelDFFClusterImpl( static_cast<TrackerDataImpl*> (pulse->getTrackerData() ) );
}
else if ( type == kEUTelBrickedClusterImpl )
{
cluster = new EUTelBrickedClusterImpl( static_cast<TrackerDataImpl*> (pulse->getTrackerData() ) );
if ( _noiseRelatedCuts )
{
// the EUTelBrickedClusterImpl doesn't contain the noise and status
// information in the TrackerData object. So this is the right
// place to attach to the cluster the noise information.
//! ---
//! ((NOTE TAKI)): actually i think each cluster does contain its own noise values already!
//! each candidate, that was created in clusearch, already had its noise set properly!
//! is this information kept when storing the clusters inside the corresponding collection?
//! not sure what happened to the status, as well!
//! well... this routine here seems to set the noise again but will set noise = 0, if a pixel is a bad one.
//! this might cause the bricked cluster to see some pixels with noise = 0 again!
//! ---
try
{
LCCollectionVec * noiseCollectionVec = dynamic_cast<LCCollectionVec * > ( evt->getCollection( _noiseCollectionName )) ;
LCCollectionVec * statusCollectionVec = dynamic_cast<LCCollectionVec * > ( evt->getCollection( _statusCollectionName )) ;
CellIDDecoder<TrackerDataImpl> noiseDecoder(noiseCollectionVec);
int detectorID = cluster->getDetectorID();
int detectorPos = _ancillaryIndexMap[ detectorID ];
TrackerDataImpl * noiseMatrix = dynamic_cast<TrackerDataImpl *> ( noiseCollectionVec->getElementAt(detectorPos) );
TrackerRawDataImpl * statusMatrix = dynamic_cast<TrackerRawDataImpl *> ( statusCollectionVec->getElementAt(detectorPos) );
EUTelMatrixDecoder noiseMatrixDecoder(noiseDecoder, noiseMatrix);
int xSeed, ySeed, xClusterSize, yClusterSize;
cluster->getCenterCoord(xSeed, ySeed);
cluster->getClusterSize(xClusterSize, yClusterSize);
vector<float > noiseValues;
for ( int yPixel = ySeed - ( yClusterSize / 2 ); yPixel <= ySeed + ( yClusterSize / 2 ); yPixel++ )
{
for ( int xPixel = xSeed - ( xClusterSize / 2 ); xPixel <= xSeed + ( xClusterSize / 2 ); xPixel++ )
{
// always check we are still within the sensor!!!
if ( ( xPixel >= noiseMatrixDecoder.getMinX() ) && ( xPixel <= noiseMatrixDecoder.getMaxX() ) &&
( yPixel >= noiseMatrixDecoder.getMinY() ) && ( yPixel <= noiseMatrixDecoder.getMaxY() ) )
{
int index = noiseMatrixDecoder.getIndexFromXY(xPixel, yPixel);
// the corresponding position in the status matrix has to be HITPIXEL
// in the EUTelClusteringProcessor, we verify also that
// the pixel isHit, but this cannot be done in this
// processor, since the status matrix could have been reset
//
// bool isHit = ( statusMatrix->getADCValues()[index] ==
// EUTELESCOPE::HITPIXEL );
//
if( static_cast< int >( statusMatrix->getADCValues().size() ) > index )
{
bool isBad = ( statusMatrix->getADCValues()[index] == EUTELESCOPE::BADPIXEL );
if ( !isBad )
{
noiseValues.push_back( noiseMatrix->getChargeValues()[index] );
}
else
{
noiseValues.push_back( 0. );
}
}
}
else
{
noiseValues.push_back( 0. );
}
}
}
cluster->setNoiseValues( noiseValues );
}
catch ( lcio::Exception& e )
{
streamlog_out ( ERROR1 ) << e.what() << endl << "Continuing w/o noise based cuts" << endl;
_noiseRelatedCuts = false;
}
}
}
else if ( type == kEUTelFFClusterImpl )
{
cluster = new EUTelFFClusterImpl( static_cast<TrackerDataImpl*> (pulse->getTrackerData() ) );
if ( _noiseRelatedCuts )
{
// the EUTelFFClusterImpl doesn't contain the noise and status
// information in the TrackerData object. So this is the right
// place to attach to the cluster the noise information.
try
{
LCCollectionVec * noiseCollectionVec = dynamic_cast<LCCollectionVec * > ( evt->getCollection( _noiseCollectionName )) ;
LCCollectionVec * statusCollectionVec = dynamic_cast<LCCollectionVec * > ( evt->getCollection( _statusCollectionName )) ;
CellIDDecoder<TrackerDataImpl> noiseDecoder(noiseCollectionVec);
int detectorID = cluster->getDetectorID();
int detectorPos = _ancillaryIndexMap[ detectorID ];
TrackerDataImpl * noiseMatrix = dynamic_cast<TrackerDataImpl *> ( noiseCollectionVec->getElementAt(detectorPos) );
TrackerRawDataImpl * statusMatrix = dynamic_cast<TrackerRawDataImpl *> ( statusCollectionVec->getElementAt(detectorPos) );
EUTelMatrixDecoder noiseMatrixDecoder(noiseDecoder, noiseMatrix);
int xSeed, ySeed, xClusterSize, yClusterSize;
cluster->getCenterCoord(xSeed, ySeed);
cluster->getClusterSize(xClusterSize, yClusterSize);
vector<float > noiseValues;
for ( int yPixel = ySeed - ( yClusterSize / 2 ); yPixel <= ySeed + ( yClusterSize / 2 ); yPixel++ )
{
for ( int xPixel = xSeed - ( xClusterSize / 2 ); xPixel <= xSeed + ( xClusterSize / 2 ); xPixel++ )
{
// always check we are still within the sensor!!!
if ( ( xPixel >= noiseMatrixDecoder.getMinX() ) && ( xPixel <= noiseMatrixDecoder.getMaxX() ) &&
( yPixel >= noiseMatrixDecoder.getMinY() ) && ( yPixel <= noiseMatrixDecoder.getMaxY() ) )
{
int index = noiseMatrixDecoder.getIndexFromXY(xPixel, yPixel);
// the corresponding position in the status matrix has to be HITPIXEL
// in the EUTelClusteringProcessor, we verify also that
// the pixel isHit, but this cannot be done in this
// processor, since the status matrix could have been reset
//
// bool isHit = ( statusMatrix->getADCValues()[index] ==
// EUTELESCOPE::HITPIXEL );
//
///
if( static_cast< int >(statusMatrix->getADCValues().size()) > index )
{
bool isBad = ( statusMatrix->getADCValues()[index] == EUTELESCOPE::BADPIXEL );
if ( !isBad )
{
noiseValues.push_back( noiseMatrix->getChargeValues()[index] );
}
else
{
noiseValues.push_back( 0. );
}
}
}
else
{
noiseValues.push_back( 0. );
}
}
}
cluster->setNoiseValues( noiseValues );
}
catch ( lcio::Exception& e )
{
streamlog_out ( ERROR1 ) << e.what() << endl << "Continuing w/o noise based cuts" << endl;
_noiseRelatedCuts = false;
}
}
}
else if ( type == kEUTelSparseClusterImpl )
{
// knowing that is a sparse cluster is not enough we need also
// to know also the sparse pixel type. This information is
// available in the "original_zsdata" collection. Let's get it!
LCCollectionVec * sparseClusterCollectionVec = dynamic_cast < LCCollectionVec * > (evt->getCollection("original_zsdata"));
TrackerDataImpl * oneCluster = dynamic_cast<TrackerDataImpl*> (sparseClusterCollectionVec->getElementAt( 0 ));
CellIDDecoder<TrackerDataImpl > anotherDecoder(sparseClusterCollectionVec);
pixelType = static_cast<SparsePixelType> ( static_cast<int> ( anotherDecoder( oneCluster )["sparsePixelType"] ));
if ( pixelType == kEUTelGenericSparsePixel )
{
cluster = new EUTelSparseClusterImpl<EUTelGenericSparsePixel > ( static_cast<TrackerDataImpl* > (pulse->getTrackerData() ));
EUTelSparseClusterImpl<EUTelGenericSparsePixel > * recasted =
dynamic_cast<EUTelSparseClusterImpl<EUTelGenericSparsePixel > *> ( cluster );
if ( _noiseRelatedCuts )
{
// the EUTelSparseClusterImpl<EUTelGenericSparsePixel>
// doesn't contain any intrinsic noise information. So we
// need to get them from the input noise collection.
try
{
LCCollectionVec * noiseCollectionVec = dynamic_cast<LCCollectionVec *> ( evt->getCollection( _noiseCollectionName ));
CellIDDecoder<TrackerDataImpl > noiseDecoder( noiseCollectionVec ) ;
int detectorID = cluster->getDetectorID();
int detectorPos = _ancillaryIndexMap[ detectorID ];
TrackerDataImpl * noiseMatrix = dynamic_cast<TrackerDataImpl *> ( noiseCollectionVec->getElementAt( detectorPos ));
EUTelMatrixDecoder noiseMatrixDecoder( noiseDecoder, noiseMatrix ) ;
auto_ptr<EUTelGenericSparsePixel> sparsePixel(new EUTelGenericSparsePixel);
vector<float > noiseValues;
for ( unsigned int iPixel = 0 ; iPixel < recasted->size() ; iPixel++ )
{
recasted->getSparsePixelAt( iPixel, sparsePixel.get() ) ;
int index = noiseMatrixDecoder.getIndexFromXY( sparsePixel->getXCoord(), sparsePixel->getYCoord() );
noiseValues.push_back( noiseMatrix->getChargeValues()[ index ] );
}
cluster->setNoiseValues( noiseValues ) ;
}
catch ( lcio::Exception& e )
{
streamlog_out ( ERROR1 ) << e.what() << "\n" << "Continuing without noise based cuts" << endl;
_noiseRelatedCuts = false;
}
streamlog_out ( DEBUG1 ) << "Noise related cuts may be used" << endl;
}
}
else
{
streamlog_out ( ERROR4 ) << "Unknown pixel type. Sorry for quitting" << endl;
throw UnknownDataTypeException("Pixel type unknown");
}
}
else
{
streamlog_out ( ERROR4 ) << "Unknown cluster type. Sorry for quitting" << endl;
throw UnknownDataTypeException("Cluster type unknown");
}
// increment the event counter
_totalClusterCounter[ _ancillaryIndexMap[ cluster->getDetectorID() ] ]++;
bool isAccepted = true;
if ( type == kEUTelDFFClusterImpl )
{
isAccepted &= isAboveNumberOfHitPixel(cluster);
}
else
{
isAccepted &= isAboveMinTotalCharge(cluster);
isAccepted &= isAboveMinTotalSNR(cluster);
isAccepted &= isAboveNMinCharge(cluster);
isAccepted &= isAboveNMinSNR(cluster);
isAccepted &= isAboveNxNMinCharge(cluster);
isAccepted &= isAboveNxNMinSNR(cluster);
isAccepted &= isAboveMinSeedCharge(cluster);
isAccepted &= isAboveMinSeedSNR(cluster);
isAccepted &= isBelowMaxClusterNoise(cluster);
}
isAccepted &= hasQuality(cluster);
isAccepted &= isInsideROI(cluster);
isAccepted &= isOutsideROI(cluster);