LCFIVertex  0.7.2
PerEventIPFitter.cc
1 #include "PerEventIPFitter.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 <inc/lciointerface.h>
12 #include <algo/inc/pereventipfitter.h>
13 #include <util/inc/memorymanager.h>
14 
15 #include <vector>
16 #include <string>
17 
18 using namespace marlin ;
19 using namespace lcio;
20 using namespace vertex_lcfi;
21 
22 PerEventIPFitterProcessor aPerEventIPFitterProcessor ;
23 
24 PerEventIPFitterProcessor::PerEventIPFitterProcessor() : Processor("PerEventIPFitterProcessor") {
25 
26  // modify processor description
27  _description = "Per Event IP fitter - trims tracks to reach probabililty threshold" ;
28 
29 
30  // register steering parameters: name, description, class-variable, default value
31 
32  registerInputCollection( lcio::LCIO::RECONSTRUCTEDPARTICLE,
33  "InputRPCollection" ,
34  "Name of the ReconstructedParticle collection contains tracks to fit" ,
35  _InputRPCollectionName ,
36  std::string("EventTracks") ) ;
37  registerOutputCollection( lcio::LCIO::VERTEX,
38  "OutputVertexCollection" ,
39  "Name of the Vertex collection of the output ip vertex" ,
40  _VertexCollectionName ,
41  std::string("IPVertex") ) ;
42  FloatVec DefaultPos;
43  DefaultPos.push_back(0.0);
44  DefaultPos.push_back(0.0);
45  DefaultPos.push_back(0.0);
46  registerProcessorParameter( "DefaultIPPosition" ,
47  "Manually set default position of the IP vertex (cm)" ,
48  _DefaultIPPos ,
49  DefaultPos,
50  DefaultPos.size()) ;
51  FloatVec DefaultErr;
52  DefaultErr.push_back(pow(5.0/1000.0,2.0)); //5 micron err
53  DefaultErr.push_back(0.0);
54  DefaultErr.push_back(pow(5.0/1000.0,2.0)); //5 micron err
55  DefaultErr.push_back(0.0);
56  DefaultErr.push_back(0.0);
57  DefaultErr.push_back(pow(20.0/1000.0,2.0)); //20 micron err
58  registerProcessorParameter( "DefaultIPError" ,
59  "Manually set default error matrix of the primary vertex (cm) (lower symmetric)" ,
60  _DefaultIPErr,
61  DefaultErr,
62  DefaultErr.size()) ;
63  registerProcessorParameter( "ProbabilityThreshold" ,
64  "Tracks are removed until this threshold is reached" ,
65  _ProbThreshold ,
66  double(0.01)) ;
67 }
68 
69 
70 void PerEventIPFitterProcessor::init() {
71 
72  // usually a good idea to
73  printParameters() ;
74 
75  _nRun = 0 ;
76  _nEvt = 0 ;
77 
78  //Make the fitter algorithm object and set its parameters
79  _IPFitter = new PerEventIPFitter();
81 
82  _IPFitter->setDoubleParameter("ProbThreshold",_ProbThreshold);
83 }
84 
85 void PerEventIPFitterProcessor::processRunHeader( LCRunHeader* run) {
86  _nRun++ ;
87 }
88 
89 void PerEventIPFitterProcessor::processEvent( LCEvent * evt ) {
90 
91  LCCollection* RPCollection;
92  RPCollection = evt->getCollection( _InputRPCollectionName );
93 
94  //Create an Event with an IP with default parameters
95  Vector3 IPPos;
96  SymMatrix3x3 IPErr;
97  //Make the manulal ip from the params
98  //TODO Check length of vectors and throw if wrong
99  IPPos.x() = _DefaultIPPos[0];
100  IPPos.y() = _DefaultIPPos[1];
101  IPPos.z() = _DefaultIPPos[2];
102  IPErr(0,0) = _DefaultIPErr[0];
103  IPErr(1,0) = _DefaultIPErr[1];
104  IPErr(1,1) = _DefaultIPErr[2];
105  IPErr(2,0) = _DefaultIPErr[3];
106  IPErr(2,1) = _DefaultIPErr[4];
107  IPErr(2,2) = _DefaultIPErr[5];
108 
109  //Create an event with this IP
110  vertex_lcfi::Event* MyEvent = new vertex_lcfi::Event(IPPos,IPErr);
112 
113  //Create jets from LCIO and add them to the event
114  int nRCP = RPCollection->getNumberOfElements() ;
115  //std::cout << nRCP << std::endl;
116  for(int i=0; i< nRCP ; i++)
117  {
118  MyEvent->addTrack(trackFromLCIORP(MyEvent,dynamic_cast<ReconstructedParticle*>(RPCollection->getElementAt(i))) );
119  }
120 
121  //Run IP Fitter
122  vertex_lcfi::Vertex* IPResult = _IPFitter->calculateFor(MyEvent);
123 
124  //Store resulting vertex in the LCIO file
125  lcio::Vertex* LCIOIPResult = vertexFromLCFIVertex(IPResult);
126 
127  std::vector<std::string>::const_iterator it = find(evt->getCollectionNames()->begin(),evt->getCollectionNames()->end(),_VertexCollectionName);
128  if (it == evt->getCollectionNames()->end())
129  {
130  //Doesn't exist so make collection and add
131  LCCollection* MyCollection = new LCCollectionVec("Vertex");
132  evt->addCollection(MyCollection,_VertexCollectionName);
133  }
134  evt->getCollection(_VertexCollectionName)->addElement(LCIOIPResult);
135 
136  //Clear all objects created for this event
137  MetaMemoryManager::Event()->delAllObjects();
138  _nEvt ++ ;
139 }
140 
141 
142 
143 void PerEventIPFitterProcessor::check( LCEvent * evt ) {
144  // nothing to check here - could be used to fill checkplots in reconstruction processor
145 }
146 
147 
148 void PerEventIPFitterProcessor::end(){
149 
150  MetaMemoryManager::Run()->delAllObjects();
151  std::cout << "PerEventIPFitterProcessor::end() " << name()
152  << " processed " << _nEvt << " events in " << _nRun << " runs "
153  << std::endl ;
154 
155 }
156 
void registerObject(T *pointer)
Register an object for memory management.
void addTrack(Track *Track)
Add Track.
Definition: event.cpp:45
Example jet variable that returns the number of tracks in the jet.
Determine IP position and error from the tracks in an event by simple fit.