All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
NNClusterProcessor.cc
Go to the documentation of this file.
1 #include "NNClusterProcessor.h"
2 #include <iostream>
3 
4 #include "time.h"
5 
6 #include <IMPL/LCCollectionVec.h>
7 #include <IMPL/ClusterImpl.h>
8 
9 #include "NNClusters.h"
10 
11 #include <algorithm>
12 
13 using namespace lcio ;
14 using namespace marlin ;
15 
17 
18 
19 NNClusterProcessor::NNClusterProcessor() : Processor("NNClusterProcessor") {
20 
21  // modify processor description
22  _description = "NNClusterProcessor : simple nearest neighbour clustering" ;
23 
24 
25  StringVec colDefault ;
26  colDefault.push_back("ecal" ) ;
27 
28  registerInputCollections( LCIO::CALORIMETERHIT,
29  "HitCollections" ,
30  "Name of the input collections" ,
31  _colNames ,
32  colDefault ) ;
33 
34  registerOutputCollection( LCIO::CLUSTER,
35  "OutputCollection" ,
36  "Name of the output collections" ,
38  std::string("NNClusters" ) ) ;
39 
40 
41  registerProcessorParameter( "DistanceCut" ,
42  "Cut for distance between hits in mm" ,
43  _distCut ,
44  (float) 40.0 ) ;
45 
46  registerProcessorParameter( "EnergyCut" ,
47  "Cut for hit energy in GeV" ,
48  _eCut ,
49  (float) 0.0 ) ;
50 
51 }
52 
53 
55 
56  // usually a good idea to
57  printParameters() ;
58 
59  _nRun = 0 ;
60  _nEvt = 0 ;
61 
62 }
63 
64 void NNClusterProcessor::processRunHeader( LCRunHeader* /*run*/) {
65 
66  _nRun++ ;
67 }
68 
69 void NNClusterProcessor::processEvent( LCEvent * evt ) {
70 
71 
72  std::cout << " ---- NNClusterProcessor::processEvent() - evt: "
73  << evt->getRunNumber() << " , " << evt->getEventNumber()
74  << std::endl ;
75 
76  clock_t start = clock () ;
77 
78 
79  LCCollectionVec* lcioClusters = new LCCollectionVec( LCIO::CLUSTER ) ;
80 
81  GenericHitVec<CalorimeterHit> h ;
82 
83  GenericClusterVec<CalorimeterHit> cl ;
84 
85  EnergyCut<CalorimeterHit> eCut( _eCut ) ;
86 
87  ZIndex<CalorimeterHit,100> zIndex( -4300. , 4300. ) ;
88 
89  NNDistance< CalorimeterHit, float> dist( _distCut ) ;
90 
91  LCIOCluster<CalorimeterHit> converter ;
92 
93 
94  int nHit = 0 ;
95  // create a vector of generic hits from the collection applying an energy cut
96  for( StringVec::iterator it = _colNames.begin() ; it != _colNames.end() ; it++ ){
97 
98  LCCollection* col = evt->getCollection( *it ) ;
99  nHit += col->getNumberOfElements() ;
100 
101 // addToGenericHitVec( h , col , eCut ) ;
102  addToGenericHitVec( h , col , eCut , zIndex ) ;
103  }
104 
105 
106 
107  // cluster the hits with a nearest neighbour condition
108  cluster( h.begin() , h.end() , std::back_inserter( cl ) , &dist ) ;
109 
110  std::cout << " passing " << h.size() << " of " << nHit
111  << " hits to clustering (E_cut: " << _eCut << ") "
112  << " found " << cl.size() << " clusters " << std::endl ;
113 
114  // create lcio::Clusters from the clustered GenericHits
115  std::transform( cl.begin(), cl.end(), std::back_inserter( *lcioClusters ) , converter ) ;
116 
117 
118  evt->addCollection( lcioClusters , _outputColName ) ;
119 
120 
121  _nEvt ++ ;
122 
123  clock_t end = clock () ;
124 
125  std::cout << " ---- NNClusterProcessor::processEvent() - time: "
126  << double( end - start ) / double(CLOCKS_PER_SEC)
127  << std::endl ;
128 
129 }
130 
131 
132 
133 void NNClusterProcessor::check( LCEvent * /*evt*/ ) {
134  // nothing to check here - could be used to fill checkplots in reconstruction processor
135 }
136 
137 
139 
140 // std::cout << "NNClusterProcessor::end() " << name()
141 // << " processed " << _nEvt << " events in " << _nRun << " runs "
142 // << std::endl ;
143 
144 }
145 
NNClusterProcessor aNNClusterProcessor
virtual void processRunHeader(LCRunHeader *run)
Called for every run.
virtual void check(LCEvent *evt)
virtual void processEvent(LCEvent *evt)
Called for every event - the working horse.
std::string _outputColName
std::vector< LCCollection * > LCCollectionVec
Definition: SiStripClus.h:55
virtual void end()
Called after data processing for clean up.
virtual void init()
Called at the begin of the job before anything is read.
StringVec _colNames
Input collection name.
std::vector< std::string > StringVec
Definition: SiStripClus.h:56