forked from eutelescope/eutelescope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEUTelClusteringProcessor.cc
3618 lines (3019 loc) · 161 KB
/
EUTelClusteringProcessor.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
// Version: $Id$
// Author Antonio Bulgheroni, INFN <mailto:antonio.bulgheroni@gmail.com>
// Version $ $
/*
* 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.
*
*/
// since v00-00-09 this processor is built only if Marlin has GEAR
// support. In theory, since that version EUTelescope require GEAR,
// but it is better being sure
#ifdef USE_GEAR
// eutelescope includes ".h"
#include "EUTELESCOPE.h"
#include "EUTelExceptions.h"
#include "EUTelRunHeaderImpl.h"
#include "EUTelEventImpl.h"
#include "EUTelClusteringProcessor.h"
#include "EUTelVirtualCluster.h"
#include "EUTelFFClusterImpl.h"
#include "EUTelDFFClusterImpl.h"
#include "EUTelBrickedClusterImpl.h"
#include "EUTelHistogramManager.h"
#include "EUTelMatrixDecoder.h"
#include "EUTelTrackerDataInterfacerImpl.h"
#include "EUTelSparseClusterImpl.h"
// gear includes <.h>
#include <gear/GearMgr.h>
#include <gear/SiPlanesParameters.h>
// marlin includes ".h"
#include "marlin/Processor.h"
#include "marlin/AIDAProcessor.h"
#include "marlin/Exceptions.h"
#include "marlin/Global.h" // this is because we want to use GEAR.
// lcio includes <.h>
#include <UTIL/CellIDEncoder.h>
#include <IMPL/TrackerRawDataImpl.h>
#include <IMPL/TrackerDataImpl.h>
#include <IMPL/TrackerPulseImpl.h>
#include <IMPL/LCCollectionVec.h>
#if defined(USE_AIDA) || defined(MARLIN_USE_AIDA)
// aida includes <.h>
#include <AIDA/IHistogramFactory.h>
#include <AIDA/IHistogram1D.h>
#include <AIDA/IHistogram2D.h>
#include <AIDA/ITree.h>
#endif
// system includes <>
#include <algorithm>
#include <string>
#include <vector>
#include <memory>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <iostream>
using namespace std;
using namespace lcio;
using namespace marlin;
using namespace eutelescope;
static const int MAXCLUSTERSIZE = 4096;
EUTelClusteringProcessor::EUTelClusteringProcessor ()
: Processor("EUTelClusteringProcessor"),
_nzsDataCollectionName(""),
_zsDataCollectionName(""),
_noiseCollectionName(""),
_statusCollectionName(""),
_pulseCollectionName(""),
_hotPixelCollectionName(""),
_initialPulseCollectionSize(0),
_dummyCollectionName(""),
_iRun(0),
_nzsClusteringAlgo(""),
_zsClusteringAlgo(""),
_dataFormatType(""),
_ffXClusterSize(0),
_ffYClusterSize(0),
_ffSeedCut(0.0),
_sparseSeedCut(0.0),
_ffClusterCut(0.0),
_sparseClusterCut(0.0),
_sparseMinDistanceSquared(2),
_sparseMinDistance(0.0),
_iEvt(0),
_fillHistos(false),
_histoInfoFileName(""),
_seedCandidateMap(),
_totClusterMap(),
_noOfDetector(0),
_ExcludedPlanes(),
_clusterSpectraNVector(),
_clusterSpectraNxNVector(),
_clusterSignalHistos(),
_clusterSizeXHistos(),
_clusterSizeYHistos(),
_seedSignalHistos(),
_hitMapHistos(),
_seedSNRHistos(),
_clusterNoiseHistos(),
_clusterSNRHistos(),
_cluster_vs_seedSNRHistos(),
_eventMultiplicityHistos(),
_clusterSignal_NHistos(),
_clusterSNR_NHistos(),
_clusterSignal_NxNHistos(),
_clusterSNR_NxNHistos(),
_siPlanesParameters(NULL),
_siPlanesLayerLayout(NULL),
_isGeometryReady(false),
_layerIndexMap(),
_dutLayerIndexMap(),
_ancillaryIndexMap(),
_orderedSensorIDVec(),
_sensorIDVec(),
zsInputDataCollectionVec(NULL),
nzsInputDataCollectionVec(NULL),
pulseCollectionVec(NULL),
noiseCollectionVec(NULL),
statusCollectionVec(NULL),
hotPixelCollectionVec(NULL),
hasNZSData(false),
hasZSData(false),
_hitIndexMapVec()
{
// modify processor description
_description =
"EUTelClusteringProcessor is looking for clusters into a calibrated pixel matrix.";
// first of all we need to register the input collection
registerInputCollection (LCIO::TRACKERDATA, "NZSDataCollectionName",
"Input calibrated data not zero suppressed collection name",
_nzsDataCollectionName, string ("data"));
registerInputCollection (LCIO::TRACKERDATA, "ZSDataCollectionName",
"Input of Zero Suppressed data",
_zsDataCollectionName, string ("zsdata") );
registerInputCollection (LCIO::TRACKERDATA, "NoiseCollectionName",
"Noise (input) collection name",
_noiseCollectionName, string("noise"));
registerInputCollection (LCIO::TRACKERRAWDATA, "StatusCollectionName",
"Pixel status (input) collection name",
_statusCollectionName, string("status"));
registerOutputCollection(LCIO::TRACKERPULSE, "PulseCollectionName",
"Cluster (output) collection name",
_pulseCollectionName, string("cluster"));
// I believe it is safer not allowing the dummyCollection to be
// renamed by the user. I prefer to set it once for ever here and
// eventually, only if really needed, in the future allow add
// another registerOutputCollection.
_dummyCollectionName = "original_data";
// now the optional parameters
registerProcessorParameter ("ClusteringAlgo",
"Select here which algorithm should be used for clustering.\n"
"Available algorithms are:\n"
"-> FixedFrame: for custer with a given size\n"
"-> BrickedCluster: for bricked clustering on raw data",
_nzsClusteringAlgo, string(EUTELESCOPE::FIXEDFRAME));
registerProcessorParameter ("ZSClusteringAlgo",
"Select here which algorithm should be used for clustering.\n"
"Available algorithms are:\n"
"-> SparseCluster: for cluster in ZS frame\n"
"-> SparseCluster2: for cluster in ZS frame with better performance\n"
"-> FixedFrame: for cluster with a given size\n"
"-> DFixedFrame: for digital cluster with a given size\n"
"-> BrickedCluster: for bricked clustering on zs data\n",
_zsClusteringAlgo, string(EUTELESCOPE::SPARSECLUSTER));
registerProcessorParameter ("DataFormatType",
"Select herewith the type of the data format you are expecting from the sensors.\n"
"Available types of the data format:\n"
"-> Analog: smooth distribution of pixel ADC values from Min to Max\n"
"-> Digital: descrete distribution of pixel ADC values from Min to Max\n"
"-> Binary: only two values of the signal - 0 and 1\n",
_dataFormatType, string(EUTELESCOPE::BINARY));
registerProcessorParameter ("FFClusterSizeX",
"Maximum allowed cluster size along x (only odd numbers)",
_ffXClusterSize, static_cast<int> (5));
registerProcessorParameter ("FFClusterSizeY",
"Maximum allowed cluster size along y (only odd numbers)",
_ffYClusterSize, static_cast<int> (5));
registerProcessorParameter ("FFSeedCut",
"Threshold in SNR for seed pixel identification",
_ffSeedCut, static_cast<float> (4.5));
registerProcessorParameter ("FFClusterCut",
"Threshold in SNR for cluster identification",
_ffClusterCut, static_cast<float> (3.0));
registerProcessorParameter("HistoInfoFileName", "This is the name of the histogram information file",
_histoInfoFileName, string( "histoinfo.xml" ) );
registerProcessorParameter("SparseSeedCut","Threshold in SNR for seed pixel contained in ZS data",
_sparseSeedCut, static_cast<float > (4.5));
registerProcessorParameter("SparseClusterCut","Threshold in SNR for clusters contained in ZS data",
_sparseClusterCut, static_cast<float > (3.0) );
registerProcessorParameter("SparseMinDistanceSquared","Minimum distance squared between sparsified pixel ( touching == 2) ",
_sparseMinDistanceSquared, static_cast<int>(2) );
registerProcessorParameter("SparseMinDistance","Minimum distance between sparsified pixel ( touching == sqrt(2)) ",
_sparseMinDistance, static_cast<float > (0.0 ) );
// registerOptionalParameter("HotPixelDBFile","This is the name of the LCIO file name with the output hotpixel db (add .slcio)",
// _hotPixelDBFile, static_cast< string > ( "hotpixel.slcio" ) );
registerOptionalParameter("HotPixelCollectionName","This is the name of the hotpixel collection",
_hotPixelCollectionName, static_cast< string > ( "hotpixel_m26" ) );
#if defined(USE_AIDA) || defined(MARLIN_USE_AIDA)
IntVec clusterNxNExample;
clusterNxNExample.push_back(3);
clusterNxNExample.push_back(5);
registerOptionalParameter("ClusterNxN", "The list of cluster NxN to be filled."
"For example 3 means filling the 3x3 histogram spectrum",
_clusterSpectraNxNVector, clusterNxNExample);
IntVec clusterNExample;
clusterNExample.push_back(4);
clusterNExample.push_back(9);
clusterNExample.push_back(14);
clusterNExample.push_back(19);
clusterNExample.push_back(25);
registerOptionalParameter("ClusterN", "The list of cluster N to be filled."
"For example 7 means filling the cluster spectra with the 7 most significant pixels",
_clusterSpectraNVector, clusterNExample );
#endif
registerProcessorParameter("HistogramFilling","Switch on or off the histogram filling",
_fillHistos, static_cast< bool > ( true ) );
registerOptionalParameter("ExcludedPlanes", "The list of sensor ids that have to be excluded from the clustering.",
_ExcludedPlanes, std::vector<int> () );
_isFirstEvent = true;
}
void EUTelClusteringProcessor::init() {
// this method is called only once even when the rewind is active
// usually a good idea to
printParameters ();
// in the case the FIXEDFRAME algorithm is selected, the check if
// the _ffXClusterSize and the _ffYClusterSize are odd numbers
if (
_nzsClusteringAlgo == EUTELESCOPE::FIXEDFRAME || _zsClusteringAlgo == EUTELESCOPE::FIXEDFRAME
||
_nzsClusteringAlgo == EUTELESCOPE::DFIXEDFRAME || _nzsClusteringAlgo == EUTELESCOPE::DFIXEDFRAME
) {
bool isZero = ( _ffXClusterSize <= 0 );
bool isEven = ( _ffXClusterSize % 2 == 0 );
if ( isZero || isEven ) {
throw InvalidParameterException("_ffXClusterSize has to be positive and odd");
}
isZero = ( _ffYClusterSize <= 0 );
isEven = ( _ffYClusterSize % 2 == 0 );
if ( isZero || isEven ) {
throw InvalidParameterException("_ffYClusterSize has to be positive and odd");
}
}
if (
_nzsClusteringAlgo == EUTELESCOPE::BRICKEDCLUSTER
||
_zsClusteringAlgo == EUTELESCOPE::BRICKEDCLUSTER
)
{
if ( ! (_ffXClusterSize == 3 ) && (_ffYClusterSize == 3 ) )
{
streamlog_out ( ERROR2 ) << "[init()] For bricked pixel clustering the cluster size has to be 3x3 at the moment(!). Sorry!";
throw InvalidParameterException("Set cluster size to 3x3 for bricked clustering!");
}
}
// reset hotpixel map vectors
_hitIndexMapVec.clear();
// set to zero the run and event counters
_iRun = 0;
_iEvt = 0;
// the geometry is not yet initialized, so set the corresponding
// switch to false
_isGeometryReady = false;
}
void EUTelClusteringProcessor::processRunHeader (LCRunHeader * rdr) {
auto_ptr<EUTelRunHeaderImpl> runHeader( new EUTelRunHeaderImpl( rdr ) );
runHeader->addProcessor( type() );
// increment the run counter
++_iRun;
}
void EUTelClusteringProcessor::initializeGeometry( LCEvent * event ) throw ( marlin::SkipEventException ) {
// set the total number of detector to zero. This number can be
// different from the one written in the gear description because
// the input collection can contain only a fraction of all the
// sensors.
//
// we assume that the no of detectors is the sum of the elements in
// the NZS input collection and the in ZS one.
_noOfDetector = 0;
_sensorIDVec.clear();
streamlog_out( DEBUG5 ) << "Initializing geometry" << endl;
try {
nzsInputDataCollectionVec = dynamic_cast< LCCollectionVec * > (event->getCollection( _nzsDataCollectionName ) );
_noOfDetector += nzsInputDataCollectionVec->getNumberOfElements();
CellIDDecoder<TrackerDataImpl > cellDecoder( nzsInputDataCollectionVec );
for ( size_t i = 0 ; i < nzsInputDataCollectionVec->size(); ++i ) {
TrackerDataImpl * data = dynamic_cast< TrackerDataImpl * > ( nzsInputDataCollectionVec->getElementAt( i ) );
_sensorIDVec.push_back( cellDecoder( data ) ["sensorID"] );
}
} catch ( lcio::DataNotAvailableException ) {
// do nothing
streamlog_out( DEBUG5 ) << "_nzsDataCollectionName " << _nzsDataCollectionName.c_str() << " not found " << endl;
}
try
{
zsInputDataCollectionVec = dynamic_cast< LCCollectionVec * > ( event->getCollection( _zsDataCollectionName ) ) ;
_noOfDetector += zsInputDataCollectionVec->getNumberOfElements();
CellIDDecoder<TrackerDataImpl > cellDecoder( zsInputDataCollectionVec );
for ( size_t i = 0; i < zsInputDataCollectionVec->size(); ++i )
{
TrackerDataImpl * data = dynamic_cast< TrackerDataImpl * > ( zsInputDataCollectionVec->getElementAt( i ) ) ;
_sensorIDVec.push_back( cellDecoder( data )[ "sensorID" ] );
_totClusterMap.insert( make_pair( cellDecoder( data )[ "sensorID" ] , 0 ));
}
} catch ( lcio::DataNotAvailableException ) {
// do nothing again
streamlog_out( DEBUG5 ) << "_zsDataCollectionName " << _zsDataCollectionName.c_str() << " not found " << endl;
}
_siPlanesParameters = const_cast< gear::SiPlanesParameters* > ( &(Global::GEAR->getSiPlanesParameters()));
_siPlanesLayerLayout = const_cast< gear::SiPlanesLayerLayout* > ( &(_siPlanesParameters->getSiPlanesLayerLayout() ));
// now let's build a map relating the position in the layerindex
// with the sensorID.
_layerIndexMap.clear();
for ( int iLayer = 0; iLayer < _siPlanesLayerLayout->getNLayers(); ++iLayer )
{
streamlog_out( DEBUG1) <<
"Telescope: iLayer " << iLayer <<
"["<< _siPlanesLayerLayout->getNLayers() <<
"], getID:" << _siPlanesLayerLayout->getID( iLayer ) << endl;
_layerIndexMap.insert( make_pair( _siPlanesLayerLayout->getID( iLayer ), iLayer ) );
}
// check if there is a DUT section or not
_dutLayerIndexMap.clear();
if( _siPlanesParameters->getSiPlanesType() == _siPlanesParameters->TelescopeWithDUT ) {
// for the time being this is quite useless since, if there is a
// DUT this is just one, but anyway it will become useful in a
// short time.
streamlog_out( DEBUG1) << "DUT: getID: " << _siPlanesLayerLayout->getDUTID() << endl;
_dutLayerIndexMap.insert( make_pair( _siPlanesLayerLayout->getDUTID(), 0 ) );
}
// now another map relating the position in the ancillary
// collections (noise, pedestal and status) with the sensorID
_ancillaryIndexMap.clear();
_orderedSensorIDVec.clear();
try {
// this is the exemplary ancillary collection
LCCollectionVec * noiseCollectionVec = dynamic_cast< LCCollectionVec * > ( event->getCollection( _noiseCollectionName ) );
// prepare also a cell decoder
CellIDDecoder< TrackerDataImpl > noiseDecoder( noiseCollectionVec );
for ( size_t iDetector = 0 ; iDetector < noiseCollectionVec->size(); ++iDetector ) {
TrackerDataImpl * noise = dynamic_cast< TrackerDataImpl * > ( noiseCollectionVec->getElementAt ( iDetector ) );
_ancillaryIndexMap.insert( make_pair( noiseDecoder( noise ) ["sensorID"], iDetector ) );
_orderedSensorIDVec.push_back( noiseDecoder( noise ) ["sensorID"] );
}
} catch ( lcio::DataNotAvailableException ) {
streamlog_out( WARNING2 ) << "Unable to initialize the geometry. Trying with the following event" << endl;
_isGeometryReady = false;
throw SkipEventException( this ) ;
}
if ( _noOfDetector == 0 ) {
streamlog_out( WARNING2 ) << "Unable to initialize the geometry. Trying with the following event" << endl;
_isGeometryReady = false;
throw SkipEventException( this );
} else {
_isGeometryReady = true;
}
}
void EUTelClusteringProcessor::modifyEvent( LCEvent * /* event */ )
{
return;
}
void EUTelClusteringProcessor::initializeHotPixelMapVec( )
{
streamlog_out(DEBUG4) << "initializeHotPixelMapVec, hotPixelCollectionVec size = " << hotPixelCollectionVec->size() << endl;
// prepare some decoders
CellIDDecoder<TrackerDataImpl> cellDecoder( hotPixelCollectionVec );
CellIDDecoder<TrackerDataImpl> noiseDecoder( noiseCollectionVec );
for ( unsigned int iDetector = 0 ; iDetector < hotPixelCollectionVec->size(); iDetector++ )
{
if( _hitIndexMapVec.size() < iDetector+1 ) _hitIndexMapVec.resize(iDetector+1);
TrackerDataImpl * hotData = dynamic_cast< TrackerDataImpl * > ( hotPixelCollectionVec->getElementAt( iDetector ) );
int sensorID = static_cast<int > ( cellDecoder( hotData )["sensorID"] );
//if this is an excluded sensor go to the next element
bool foundexcludedsensor = false;
for(size_t j = 0; j < _ExcludedPlanes.size(); ++j)
{
if(_ExcludedPlanes[j] == sensorID)
{
foundexcludedsensor = true;
}
}
if(foundexcludedsensor) continue;
if ( _layerIndexMap.find( sensorID ) == _layerIndexMap.end() )
{
streamlog_out( DEBUG5 ) << "Sensor " << sensorID << " not found in the present data, skipping its hotPixel information." << endl;
continue;
}
// the noise map. we only need this map for decoding issues.
TrackerDataImpl *noise = 0;
// the noise map. we only need this map for decoding issues.
noise = dynamic_cast<TrackerDataImpl*> (noiseCollectionVec->getElementAt( _ancillaryIndexMap[ sensorID ] ));
// prepare the matrix decoder
EUTelMatrixDecoder matrixDecoder( noiseDecoder , noise );
// now prepare the EUTelescope interface to sparsified data.
auto_ptr<EUTelTrackerDataInterfacerImpl<EUTelGenericSparsePixel > > sparseData(new EUTelTrackerDataInterfacerImpl<EUTelGenericSparsePixel> ( hotData ));
streamlog_out ( DEBUG1 ) << "Processing sparse data on detector " << sensorID << " with "
<< sparseData->size() << " pixels " << endl;
for ( unsigned int iPixel = 0; iPixel < sparseData->size(); iPixel++ )
{
// loop over all pixels in the sparseData object.
EUTelGenericSparsePixel *sparsePixel = new EUTelGenericSparsePixel() ;
sparseData->getSparsePixelAt( iPixel, sparsePixel );
int decoded_XY_index = matrixDecoder.getIndexFromXY( sparsePixel->getXCoord(), sparsePixel->getYCoord() ); // unique pixel index !!
streamlog_out ( DEBUG1 ) <<
" iPixel " << iPixel <<
" idet " << iDetector <<
" decoded_XY_index " << decoded_XY_index << endl;
if( _hitIndexMapVec[iDetector].find( decoded_XY_index ) == _hitIndexMapVec[iDetector].end() )
{
_hitIndexMapVec[iDetector].insert ( make_pair ( decoded_XY_index, EUTELESCOPE::FIRINGPIXEL ) );
streamlog_out ( DEBUG4 )
<< "adding hot pixel ["<< iPixel <<"]"
<< " idet " << iDetector
<< " decoded_XY_index " << decoded_XY_index
<< " [" << sparsePixel->getXCoord()
<< " "<< sparsePixel->getYCoord() << "]"
<< " status : " << EUTELESCOPE::FIRINGPIXEL << endl;
}
else
{
streamlog_out ( ERROR5 ) << "hot pixel [index " << decoded_XY_index << "] reoccured ?!" << endl;
}
}
}
}
void EUTelClusteringProcessor::initializeStatusCollection( )
{
// prepare some decoders
CellIDDecoder<TrackerDataImpl> cellDecoder( zsInputDataCollectionVec );
CellIDDecoder<TrackerDataImpl> statusDecoder( statusCollectionVec );
CellIDDecoder<TrackerDataImpl> noiseDecoder( noiseCollectionVec );
for ( unsigned int iDetector = 0 ; iDetector < zsInputDataCollectionVec->size(); iDetector++ )
{
if( _hitIndexMapVec.size() < iDetector+1 ) _hitIndexMapVec.resize(iDetector+1);
// get the TrackerData and guess which kind of sparsified data it
// contains.
TrackerDataImpl * zsData = dynamic_cast< TrackerDataImpl * > ( zsInputDataCollectionVec->getElementAt( iDetector ) );
int sensorID = static_cast<int > ( cellDecoder( zsData )["sensorID"] );
//if this is an excluded sensor go to the next element
bool foundexcludedsensor = false;
for(size_t j = 0; j < _ExcludedPlanes.size(); ++j)
{
if(_ExcludedPlanes[j] == sensorID)
{
foundexcludedsensor = true;
}
}
if(foundexcludedsensor) continue;
// get the noise and the status matrix with the right detectorID
TrackerRawDataImpl * status = 0;
// the noise map. we only need this map for decoding issues.
TrackerDataImpl * noise = 0;
// get the noise and the status matrix with the right detectorID
status = dynamic_cast<TrackerRawDataImpl*>(statusCollectionVec->getElementAt( _ancillaryIndexMap[ sensorID ] ));
vector< short > statusVec = status->adcValues();
//the noise map. we only need this map for decoding issues.
noise = dynamic_cast<TrackerDataImpl*> (noiseCollectionVec->getElementAt( _ancillaryIndexMap[ sensorID ] ));
// prepare the matrix decoder
EUTelMatrixDecoder matrixDecoder( noiseDecoder , noise );
// now prepare the EUTelescope interface to sparsified data.
auto_ptr<EUTelTrackerDataInterfacerImpl<EUTelGenericSparsePixel > > sparseData(new EUTelTrackerDataInterfacerImpl<EUTelGenericSparsePixel> ( zsData ));
streamlog_out ( DEBUG1 ) << "Processing sparse data on detector " << sensorID << " with "
<< sparseData->size() << " pixels " << endl;
for ( unsigned int iPixel = 0; iPixel < sparseData->size(); iPixel++ )
{
// loop over all pixels in the sparseData object.
EUTelGenericSparsePixel *sparsePixel = new EUTelGenericSparsePixel() ;
sparseData->getSparsePixelAt( iPixel, sparsePixel );
int decoded_XY_index = matrixDecoder.getIndexFromXY( sparsePixel->getXCoord(), sparsePixel->getYCoord() ); // unique pixel index !!
if( _hitIndexMapVec[iDetector].find( decoded_XY_index ) == _hitIndexMapVec[iDetector].end() )
{
int old_size = status->adcValues().size();
// increment
int new_size = old_size + 1 ;
int last_element = old_size;
status->adcValues().resize( new_size );
_hitIndexMapVec[iDetector].insert ( make_pair ( decoded_XY_index, last_element ) );
status->adcValues()[ last_element ] = EUTELESCOPE::HITPIXEL ; // adcValues is a vector, there fore must address the elements incrementally
}
else
{
status->adcValues()[ _hitIndexMapVec[iDetector][ decoded_XY_index] ] = EUTELESCOPE::HITPIXEL ;
}
}
}
return;
}
void EUTelClusteringProcessor::readCollections (LCEvent * event)
{
try {
nzsInputDataCollectionVec = dynamic_cast< LCCollectionVec * > (event->getCollection( _nzsDataCollectionName ) );
streamlog_out ( DEBUG4 ) << "nzsInputDataCollectionVec: " << _nzsDataCollectionName.c_str() << " found " << endl;
} catch ( lcio::DataNotAvailableException ) {
// do nothing
streamlog_out ( DEBUG4 ) << "nzsInputDataCollectionVec: " << _nzsDataCollectionName.c_str() << " not found " << endl;
}
try {
zsInputDataCollectionVec = dynamic_cast< LCCollectionVec * > ( event->getCollection( _zsDataCollectionName ) ) ;
streamlog_out ( DEBUG4 ) << "zsInputDataCollectionVec: " << _zsDataCollectionName.c_str() << " found " << endl;
} catch ( lcio::DataNotAvailableException ) {
// do nothing again
streamlog_out ( DEBUG4 ) << "zsInputDataCollectionVec: " << _zsDataCollectionName.c_str() << " not found " << endl;
}
//
//
statusCollectionVec = 0;
try
{
statusCollectionVec = dynamic_cast < LCCollectionVec * > (event->getCollection( _statusCollectionName ));
streamlog_out ( DEBUG4 ) << "statusCollectionName: " << _statusCollectionName.c_str() << " found " << endl;
}
catch (lcio::DataNotAvailableException& e )
{
streamlog_out ( DEBUG4 ) << "No status collection found in the event" << endl;
}
noiseCollectionVec = 0;
try
{
noiseCollectionVec = dynamic_cast < LCCollectionVec * > (event->getCollection( _noiseCollectionName ));
streamlog_out ( DEBUG4 ) << "noiseCollectionName: " << _noiseCollectionName.c_str() << " found " << endl;
}
catch (lcio::DataNotAvailableException& e )
{
streamlog_out ( DEBUG4 ) << "No noise pixel DB collection found in the event" << endl;
}
// the hotpixel db file should be read only once, and
// only after the statusCollection has been created (opened)
//
if( isFirstEvent() && statusCollectionVec != 0 )
{
hotPixelCollectionVec = 0;
try
{
hotPixelCollectionVec = static_cast< LCCollectionVec* > (event->getCollection( _hotPixelCollectionName )) ;
initializeHotPixelMapVec();
streamlog_out ( DEBUG5 ) << "hotPixelCollectionName: " << _hotPixelCollectionName.c_str() << " found " << endl;
}
catch (lcio::DataNotAvailableException& e )
{
streamlog_out ( WARNING5 ) << "No hot pixel DB collection found in the event" << endl;
}
}
// in the current event it is possible to have either full frame and
// zs data. Here is the right place to guess what we have
hasNZSData = true;
hasZSData = true;
try
{
event->getCollection(_nzsDataCollectionName);
}
catch (lcio::DataNotAvailableException& e)
{
hasNZSData = false;
streamlog_out ( DEBUG4 ) << "No NZS data found in the event" << endl;
}
try
{
event->getCollection( _zsDataCollectionName ) ;
}
catch (lcio::DataNotAvailableException& e )
{
hasZSData = false;
streamlog_out ( DEBUG4 ) << "No ZS data found in the event" << endl;
}
if ( !hasNZSData && !hasZSData )
{
streamlog_out ( MESSAGE2 ) << "The current event doesn't contain neither ZS nor NZS data collections: skip # " << event->getEventNumber() << endl;
// << "Leaving this event without any further processing" << endl;
throw SkipEventException( this ) ;
}
return;
}
void EUTelClusteringProcessor::processEvent (LCEvent * event)
{
++_iEvt;
// first of all we need to be sure that the geometry is properly
// initialized!
//
if ( !_isGeometryReady )
{
initializeGeometry( event ) ;
}
//
// read noise, status, and hotpixel collections
//
readCollections(event);
#if defined(USE_AIDA) || defined(MARLIN_USE_AIDA)
// book the histograms now
if ( _fillHistos && isFirstEvent() )
{
bookHistos();
}
#endif
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()
<< " is of unknown type. Continue considering it as a normal Data Event." << endl;
}
// prepare a pulse collection to add all clusters found
// this can be either a new collection or already existing in the
// event
LCCollectionVec * pulseCollection;
bool pulseCollectionExists = false;
_initialPulseCollectionSize = 0;
try
{
pulseCollection = dynamic_cast< LCCollectionVec * > ( evt->getCollection( _pulseCollectionName ) );
pulseCollectionExists = true;
_initialPulseCollectionSize = pulseCollection->size();
}
catch ( lcio::DataNotAvailableException& e )
{
pulseCollection = new LCCollectionVec(LCIO::TRACKERPULSE);
}
//
// non Zero Suppresed (RAW data)
//
if ( hasNZSData )
{
// put here all the possible algorithm applicable to NZS data
if ( _nzsClusteringAlgo == EUTELESCOPE::FIXEDFRAME ) fixedFrameClustering(evt, pulseCollection);
if ( _nzsClusteringAlgo == EUTELESCOPE::BRICKEDCLUSTER ) nzsBrickedClustering(evt, pulseCollection); // force 3x3 clusters
}
//
// ZS data
//
if ( hasZSData )
{
// put here all the possible algorithm applicable to ZS data
if ( _zsClusteringAlgo == EUTELESCOPE::SPARSECLUSTER ) sparseClustering(evt, pulseCollection);
else if ( _zsClusteringAlgo == EUTELESCOPE::SPARSECLUSTER2 ) sparseClustering(evt, pulseCollection);
else if ( _zsClusteringAlgo == EUTELESCOPE::SPARSECLUSTER3 ) sparseClustering(evt, pulseCollection);
else if ( _zsClusteringAlgo == EUTELESCOPE::FIXEDFRAME ) zsFixedFrameClustering(evt, pulseCollection);
else if ( _zsClusteringAlgo == EUTELESCOPE::DFIXEDFRAME ) digitalFixedFrameClustering(evt, pulseCollection);
// the bricked clustering type is solely needed for TAKI sensors type
else if ( _zsClusteringAlgo == EUTELESCOPE::BRICKEDCLUSTER ) zsBrickedClustering(evt, pulseCollection); // force 3x3 clusters
}
// if the pulseCollection is not empty add it to the event
if ( ! pulseCollectionExists && ( pulseCollection->size() != _initialPulseCollectionSize ))
{
evt->addCollection( pulseCollection, _pulseCollectionName );
}
if ( pulseCollection->size() != _initialPulseCollectionSize )
{
#if defined(USE_AIDA) || defined(MARLIN_USE_AIDA)
if ( _fillHistos ) fillHistos(event);
#endif
}
if ( ! pulseCollectionExists && ( pulseCollection->size() == _initialPulseCollectionSize ) )
{
delete pulseCollection;
}
_isFirstEvent = false;
}
void EUTelClusteringProcessor::digitalFixedFrameClustering(LCEvent * evt, LCCollectionVec * pulseCollection)
{
streamlog_out ( DEBUG4 ) << "Looking for clusters in the zs data with digital FixedFrame algorithm " << endl;
// get the collections of interest from the event.
// LCCollectionVec * zsInputDataCollectionVec = dynamic_cast < LCCollectionVec * > (evt->getCollection( _zsDataCollectionName ));
// LCCollectionVec * statusCollectionVec = dynamic_cast < LCCollectionVec * > (evt->getCollection( _statusCollectionName ));
// LCCollectionVec * noiseCollectionVec = dynamic_cast < LCCollectionVec * > (evt->getCollection( _noiseCollectionName ));
// prepare some decoders
CellIDDecoder<TrackerDataImpl> cellDecoder( zsInputDataCollectionVec );
CellIDDecoder<TrackerDataImpl> statusDecoder( statusCollectionVec );
CellIDDecoder<TrackerDataImpl> noiseDecoder( noiseCollectionVec );
// this is the equivalent of the dummyCollection in the fixed frame
// clustering. BTW we should consider changing that "meaningful"
// name! This contains cluster and not yet pulses
bool isDummyAlreadyExisting = false;
LCCollectionVec * sparseClusterCollectionVec = NULL;
try {
sparseClusterCollectionVec = dynamic_cast< LCCollectionVec* > ( evt->getCollection( "original_zsdata") );
isDummyAlreadyExisting = true ;
} catch (lcio::DataNotAvailableException& e) {
sparseClusterCollectionVec = new LCCollectionVec(LCIO::TRACKERDATA);
isDummyAlreadyExisting = false;
}
size_t dummyCollectionInitialSize = sparseClusterCollectionVec->size();
//auto_ptr<LCCollectionVec > sparseClusterCollectionVec ( new LCCollectionVec(LCIO::TRACKERDATA) );
CellIDEncoder<TrackerDataImpl> idZSClusterEncoder( EUTELESCOPE::CLUSTERDEFAULTENCODING, sparseClusterCollectionVec );
// prepare an encoder also for the pulse collection
CellIDEncoder<TrackerPulseImpl> idZSPulseEncoder(EUTELESCOPE::PULSEDEFAULTENCODING, pulseCollection);
// utility
short limitExceed = 0;
if ( isFirstEvent() )
{
// For the time being nothing to do specifically in the first
// event.
}
dim2array<bool> pixelmatrix(_ffXClusterSize, _ffYClusterSize, false);
for ( unsigned int i = 0 ; i < zsInputDataCollectionVec->size(); i++ )
{
// get the TrackerData and guess which kind of sparsified data it
// contains.
TrackerDataImpl * zsData = dynamic_cast< TrackerDataImpl * > ( zsInputDataCollectionVec->getElementAt( i ) );
SparsePixelType type = static_cast<SparsePixelType> ( static_cast<int> (cellDecoder( zsData )["sparsePixelType"]) );
int _sensorID = static_cast<int > ( cellDecoder( zsData )["sensorID"] );
int sensorID = _sensorID;
//if this is an excluded sensor go to the next element
bool foundexcludedsensor = false;
for(size_t j = 0; j < _ExcludedPlanes.size(); ++j)
{
if(_ExcludedPlanes[j] == _sensorID)
{
foundexcludedsensor = true;
}
}
if(foundexcludedsensor)
continue;
// reset the cluster counter for the clusterID
int clusterID = 0;
// get the noise and the status matrix with the right detectorID
// TrackerRawDataImpl * status = 0;
// the noise map. we only need this map for decoding issues.
TrackerDataImpl * noise = 0;
// get the noise and the status matrix with the right detectorID
// status = dynamic_cast<TrackerRawDataImpl*>(statusCollectionVec->getElementAt( _ancillaryIndexMap[ sensorID ] ));
//the noise map. we only need this map for decoding issues.
noise = dynamic_cast<TrackerDataImpl*> (noiseCollectionVec->getElementAt( _ancillaryIndexMap[ sensorID ] ));
// if( _dataFormatType == EUTELESCOPE::BINARY )
// {
// if ( isFirstEvent() )
// {
// status->adcValues().clear();
// }
// }
// reset the status
// now that we know which is the sensorID, we can ask to GEAR
// which are the minX, minY, maxX and maxY.
int _minX, _minY, _maxX, _maxY;
_minX = 0;
_minY = 0;
// this sensorID can be either a reference plane or a DUT, do it
// differently...
if ( _layerIndexMap.find( sensorID ) != _layerIndexMap.end() ){
// this is a reference plane
_maxX = _siPlanesLayerLayout->getSensitiveNpixelX( _layerIndexMap[ sensorID ] ) - 1;
_maxY = _siPlanesLayerLayout->getSensitiveNpixelY( _layerIndexMap[ sensorID ] ) - 1;
} else if ( _dutLayerIndexMap.find( sensorID ) != _dutLayerIndexMap.end() ) {
// ok it is a DUT plane
_maxX = _siPlanesLayerLayout->getDUTSensitiveNpixelX() - 1;
_maxY = _siPlanesLayerLayout->getDUTSensitiveNpixelY() - 1;
} else {
// this is not a reference plane neither a DUT... what's that?
// throw InvalidGeometryException ("Unknown sensorID " + to_string( sensorID ));
// exit(-1);
streamlog_out( ERROR5 ) << "Unknown sensorID " << sensorID << ", perhaps your GEAR file is incomplete." << endl;
continue;
}
//todo: declare a vector of sensormatrizes as a class member in
//order to not allocate a new object for each loop iteration.
//sensormatrix.push_back(dim2array<bool>((unsigned int)(_maxX+1 - _minX), (unsigned int)(_maxY+1 - _minY), false));
// dim2array<bool> sensormatrix((unsigned int)(_maxX+1 - _minX), (unsigned int)(_maxY+1 - _minY), false);
std::map<unsigned int, std::map<unsigned int, bool> > sensormatrix;
// prepare the matrix decoder
EUTelMatrixDecoder matrixDecoder( noiseDecoder , noise );
//insert some noise pixel by hand. was only used for debugging.
// for(int i = 0; i < 250; i++)
// {
// int index = matrixDecoder.getIndexFromXY( i,i );
// status->adcValues()[index] = EUTELESCOPE::HITPIXEL;
// }
// prepare a data vector mimicking the TrackerData data of the
// standard digitalFixedFrameClustering. Initialize all the entries to zero.
// vector<float > dataVec( status->getADCValues().size(), 0. );
vector<float > dataVec( noise->getChargeValues().size(), 0. );
//seed candidates
list<seed> seedcandidates;
const int xoffset = _minX;
const int yoffset = _minY;
// bool firstfoundhitpixel = true;
if ( type == kEUTelGenericSparsePixel )
{
// now prepare the EUTelescope interface to sparsified data.
auto_ptr<EUTelTrackerDataInterfacerImpl<EUTelGenericSparsePixel> > sparseData(new EUTelTrackerDataInterfacerImpl<EUTelGenericSparsePixel>( zsData ));
streamlog_out ( DEBUG1 ) << "Processing sparse data on detector " << _sensorID << " with "
<< sparseData->size() << " pixels " << endl;
// loop over all pixels in the sparseData object.
auto_ptr<EUTelGenericSparsePixel > sparsePixel( new EUTelGenericSparsePixel );
for ( unsigned int iPixel = 0; iPixel < sparseData->size(); iPixel++ )
{
sparseData->getSparsePixelAt( iPixel, sparsePixel.get() );
int index = matrixDecoder.getIndexFromXY( sparsePixel->getXCoord(), sparsePixel->getYCoord() );
if(static_cast<int>(_hitIndexMapVec.size()) > sensorID ){
if( _hitIndexMapVec[sensorID].find( index ) != _hitIndexMapVec[sensorID].end() )
{
streamlog_out ( DEBUG1) <<
" iDetector " << sensorID <<
" iPixel " << iPixel <<
" unique index " << index <<
" at x = " << sparsePixel->getXCoord() <<
" y= " << sparsePixel->getYCoord() << endl;
continue;
}