LCFIVertex  0.7.2
ZVTOPZVKINProcessor.cc
1 #include "ZVTOPZVKINProcessor.h"
2 #include <iostream>
3 
4 #include <EVENT/LCCollection.h>
5 #include <EVENT/ReconstructedParticle.h>
6 #include <EVENT/Track.h>
7 #include <EVENT/Vertex.h>
8 #include <IMPL/LCCollectionVec.h>
9 #include <IMPL/LCRelationImpl.h>
10 
11 #include <util/inc/memorymanager.h>
12 #include <algo/inc/zvkin.h>
13 #include <util/inc/matrix.h>
14 #include <inc/lciointerface.h>
15 
16 #include <vector>
17 #include <string>
18 
19 using namespace marlin ;
20 using namespace lcio;
21 using namespace vertex_lcfi;
22 
23 ZVTOPZVKINProcessor aZVTOPZVKINProcessor ;
24 
25 ZVTOPZVKINProcessor::ZVTOPZVKINProcessor() : Processor("ZVTOP_ZVKINProcessor") {
26 
27  // modify processor description
28  _description = "ZVTOP_ZVKIN - Kinematic Vertex Reconstruction Algorithm" ;
29 
30  // register steering parameters: name, description, class-variable, default value
31  registerInputCollection( lcio::LCIO::RECONSTRUCTEDPARTICLE,
32  "JetRPCollection" ,
33  "Name of the ReconstructedParticle collection that represents jets" ,
34  _JetRPCollectionName ,
35  std::string("Jets") ) ;
36  registerInputCollection( lcio::LCIO::VERTEX,
37  "IPVertexCollection" ,
38  "Name of the Vertex collection that contains the primary vertex (Optional)" ,
39  _IPVertexCollectionName ,
40  std::string("IPVertex") ) ;
41  registerOutputCollection( lcio::LCIO::RECONSTRUCTEDPARTICLE,
42  "DecayChainRPTracksCollectionName" ,
43  "Name of the ReconstructedParticle collection that represents tracks in output decay chains" ,
44  _DecayChainRPTracksCollectionName,
45  std::string("ZVKINDecayChainRPTracks") ) ;
46 // registerOutputCollection( lcio::LCIO::LCRELATION,
47 // "RelationCollection" ,
48 // "Name of the LCRelation collection where the relation between jets and decay chains will be stored" ,
49 // _RelationCollectionName ,
50 // std::string("JetDecayChainRelations") ) ;
51  registerOutputCollection( lcio::LCIO::VERTEX,
52  "VertexCollection" ,
53  "Name of the Vertex collection that contains found vertices" ,
54  _VertexCollectionName ,
55  std::string("ZVKINVertices") ) ;
56  registerOutputCollection( lcio::LCIO::RECONSTRUCTEDPARTICLE,
57  "DecayChainCollectionName" ,
58  "Name of the ReconstructedParticle collection that holds RPs representing output decay chains" ,
59  _DecayChainCollectionName,
60  std::string("ZVKINDecayChains") ) ;
61  registerProcessorParameter( "ManualIPVertex" ,
62  "If false then the primary vertex from VertexCollection is used" ,
63  _ManualPrimaryVertex ,
64  bool(1));
65  FloatVec DefaultPos;
66  DefaultPos.push_back(0.0);
67  DefaultPos.push_back(0.0);
68  DefaultPos.push_back(0.0);
69  //_ManualPrimaryVertexPos = DefaultPos;
70  registerOptionalParameter( "ManualIPVertexPosition" ,
71  "Manually set position of the primary vertex (cm) - non origin IP not yet fully supported" ,
72  _ManualPrimaryVertexPos ,
73  DefaultPos,
74  DefaultPos.size()) ;
75  FloatVec DefaultErr;
76  DefaultErr.push_back(pow(5.0/1000.0,2.0)); //5 micron err
77  DefaultErr.push_back(0.0);
78  DefaultErr.push_back(pow(5.0/1000.0,2.0)); //5 micron err
79  DefaultErr.push_back(0.0);
80  DefaultErr.push_back(0.0);
81  DefaultErr.push_back(pow(20.0/1000.0,2.0)); //20 micron err
82  //_ManualPrimaryVertexErr = DefaultErr;
83  registerOptionalParameter( "ManualIPVertexError" ,
84  "Manually set error matrix of the primary vertex (cm) (lower symmetric)" ,
85  _ManualPrimaryVertexErr,
86  DefaultErr,
87  DefaultErr.size()) ;
88  registerOptionalParameter( "MinimumProbability" ,
89  "If a vertex candidate has a probability below this it will not be considered - lower value results in more merging and lower vertex multiplicity" ,
90  _MinimumProbability,
91  double(1.0/100.0)) ;
92  registerOptionalParameter( "InitialGhostWidth" ,
93  "Width in cm of the ghost inital ghosttrack, also the smallest width it is allowed to have" ,
94  _InitialGhostWidth,
95  double(25.0/1000.0)) ;
96  registerOptionalParameter( "MaxChi2Allowed" ,
97  "The ghost track is widened until all forward jet tracks have a chi squared lower than this value" ,
98  _MaxChi2Allowed,
99  double(1.0)) ;
100  registerOptionalParameter( "OutputTrackChi2" ,
101  "If true the chi squared contributions of tracks to vertices is written to LCIO" ,
102  _OutputTrackChi2,
103  false) ;
104 }
105 
106 
107 void ZVTOPZVKINProcessor::init() {
108 
109  // usually a good idea to
110  printParameters() ;
111 
112  _nRun = 0 ;
113  _nEvt = 0 ;
114 
115  //Make the ZVKIN algorithm object and set its parameters
116  _ZVKIN = new ZVKIN();
118 
119  _ZVKIN->setDoubleParameter("MinimumProbability",_MinimumProbability);
120  _ZVKIN->setDoubleParameter("InitialGhostWidth",_InitialGhostWidth);
121  _ZVKIN->setDoubleParameter("MaxChi2Allowed",_MaxChi2Allowed);
122  _ZVKIN->setStringParameter("AutoJetAxis","TRUE");
123  _ZVKIN->setStringParameter("UseEventIP","TRUE");
124 
125 }
126 
127 void ZVTOPZVKINProcessor::processRunHeader( LCRunHeader* run) {
128  _nRun++ ;
129 }
130 
131 void ZVTOPZVKINProcessor::processEvent( LCEvent * evt ) {
132  //Make Event from
133  LCCollection* JetCollection;
134  JetCollection = evt->getCollection( _JetRPCollectionName );
135 
136  //Create an Event with an IP determined by the parameters or a vertex
137  Vector3 IPPos;
138  SymMatrix3x3 IPErr;
139  if (_ManualPrimaryVertex)
140  {
141  //Make the manulal ip from the params
142  //TODO Check length of vectors and throw if wrong
143  IPPos.x() = _ManualPrimaryVertexPos[0];
144  IPPos.y() = _ManualPrimaryVertexPos[1];
145  IPPos.z() = _ManualPrimaryVertexPos[2];
146  IPErr(0,0) = _ManualPrimaryVertexErr[0];
147  IPErr(1,0) = _ManualPrimaryVertexErr[1];
148  IPErr(1,1) = _ManualPrimaryVertexErr[2];
149  IPErr(2,0) = _ManualPrimaryVertexErr[3];
150  IPErr(2,1) = _ManualPrimaryVertexErr[4];
151  IPErr(2,2) = _ManualPrimaryVertexErr[5];
152  }
153  else
154  {
155  //Find the primary vertex in the event
156  LCCollection* VertexCol;
157  VertexCol = evt->getCollection( _IPVertexCollectionName );
158 
159  //Search throught the vertices in this colection to find the primary
160  int nVerts = VertexCol->getNumberOfElements() ;
161  bool done = 0;
162  for(int i=0; i< nVerts ; i++)
163  {
164  lcio::Vertex* iVertex = dynamic_cast<lcio::Vertex*>(VertexCol->getElementAt(i));
165  if (iVertex->isPrimary())
166  {
167  IPPos.x() = iVertex->getPosition()[0];
168  IPPos.y() = iVertex->getPosition()[1];
169  IPPos.z() = iVertex->getPosition()[2];
170  IPErr(0,0) = iVertex->getCovMatrix()[0];
171  IPErr(1,0) = iVertex->getCovMatrix()[1];
172  IPErr(1,1) = iVertex->getCovMatrix()[2];
173  IPErr(2,0) = iVertex->getCovMatrix()[3];
174  IPErr(2,1) = iVertex->getCovMatrix()[4];
175  IPErr(2,2) = iVertex->getCovMatrix()[5];
176  done = 1;
177  }
178  if (done) break;
179  }
180  if (!done) done = 1;//TODO Throw something
181  }
182  //Create an event with this IP
183  vertex_lcfi::Event* MyEvent = new vertex_lcfi::Event(IPPos,IPErr);
184 
185  //Create jets from LCIO and add them to the event
186  std::vector<std::string>::const_iterator it = find(evt->getCollectionNames()->begin(),evt->getCollectionNames()->end(),_DecayChainCollectionName);
187  if (it == evt->getCollectionNames()->end())
188  {
189  //Doesn't exist so make collection and add
190  LCCollection* MyCollection = new LCCollectionVec("ReconstructedParticle");
191  evt->addCollection(MyCollection,_DecayChainCollectionName);
192  }
193  int nRCP = JetCollection->getNumberOfElements() ;
194  for(int i=0; i< nRCP ; i++)
195  {
196  Jet* MyJet = jetFromLCIORP(MyEvent,dynamic_cast<ReconstructedParticle*>(JetCollection->getElementAt(i)));
197 
198  //Set any jet depandant parameters
199 
200  //Run ZVTOP-ZVKIN
201  DecayChain* ZVTOPResult = _ZVKIN->calculateFor(MyJet);
202 
203  //Store resulting decay chain in the LCIO file
204  ReconstructedParticle* LCIOZVTOPResult = addDecayChainToLCIOEvent(evt, ZVTOPResult,_VertexCollectionName, _DecayChainRPTracksCollectionName, _OutputTrackChi2);
205 
206  //Store the RP that holds all the vertexed tracks in LCIO
207  evt->getCollection(_DecayChainCollectionName)->addElement(LCIOZVTOPResult);
208 
209  //Commented out as we just rely on order
210  /*//LC Relate DecayChain and Jet
211  LCRelation* NewRelation = new LCRelationImpl(LCIOZVTOPResult,JetCollection->getElementAt(i));
212  it = find(evt->getCollectionNames()->begin(),evt->getCollectionNames()->end(),_RelationCollectionName);
213  if (it == evt->getCollectionNames()->end())
214  {
215  //Doesn't exist so make collection and add
216  LCCollection* MyCollection = new LCCollectionVec("LC_RELATION");
217  evt->addCollection(MyCollection,_RelationCollectionName);
218  }
219  evt->getCollection(_RelationCollectionName)->addElement(NewRelation);
220  */
221  }
222  //Clear all objects created for this event
224  _nEvt ++ ;
225 }
226 
227 
228 
229 void ZVTOPZVKINProcessor::check( LCEvent * evt ) {
230  // nothing to check here - could be used to fill checkplots in reconstruction processor
231 }
232 
233 
234 void ZVTOPZVKINProcessor::end(){
235 
237  std::cout << "ZVTOPZVKINProcessor::end() " << name()
238  << " processed " << _nEvt << " events in " << _nRun << " runs "
239  << std::endl ;
240 
241 }
242 
Find vertices in a jet using kinematic ZVTOP-ZVKIN algorithm.
void registerObject(T *pointer)
Register an object for memory management.
static MetaMemoryManager * Event()
Returns the Event duration singleton instance of the controller.
void delAllObjects()
Delete all objects of all types held by this instance.
static MetaMemoryManager * Run()
Returns the Run duration singleton instance of the controller.
Algorithm interface for decay chain construction or vertexing.