LCFIVertex  0.7.2
ZVTOPZVRESProcessor.cc
1 #include "ZVTOPZVRESProcessor.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/zvres.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 ZVTOPZVRESProcessor aZVTOPZVRESProcessor ;
24 
25 ZVTOPZVRESProcessor::ZVTOPZVRESProcessor() : Processor("ZVTOP_ZVRESProcessor") {
26 
27  // modify processor description
28  _description = "ZVTOP_ZVRES - 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("ZVRESDecayChainRPTracks") ) ;
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("ZVRESVertices") ) ;
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("ZVRESDecayChains") ) ;
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)" ,
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( "IPWeighting" ,
89  "Weight of the IP in the Vertex Function" ,
90  _IPWeighting ,
91  double(1.0)) ;
92  registerOptionalParameter( "JetWeightingEnergyScaling" ,
93  "Scaling factor for Weight of the jet direction in the Vertex Function" ,
94  _JetWeightingEnergyScaling,
95  double(5.0/40.0)) ;
96  registerOptionalParameter( "TwoTrackCut" ,
97  "Chi Squared cut for making initial track pairs - chi squared of either track NOT sum" ,
98  _TwoTrackCut,
99  double(10.0)) ;
100  registerOptionalParameter( "TrackTrimCut" ,
101  "Chi Squared cut for final trimming of tracks from vertices" ,
102  _TrackTrimCut,
103  double(10.0)) ;
104  registerOptionalParameter( "ResolverCut" ,
105  "Cut to determine if two vertices are resolved" ,
106  _ResolverCut,
107  double(0.6)) ;
108  registerOptionalParameter( "OutputTrackChi2" ,
109  "If true the chi squared contributions of tracks to vertices is written to LCIO" ,
110  _OutputTrackChi2,
111  false) ;
112 
113 }
114 
115 
116 void ZVTOPZVRESProcessor::init() {
117 
118  // usually a good idea to
119  printParameters() ;
120 
121  _nRun = 0 ;
122  _nEvt = 0 ;
123 
124  //Make the ZVRES algorithm object and set its parameters
125  _ZVRES = new ZVRES();
127 
128  _ZVRES->setDoubleParameter("Kip",_IPWeighting);
129  //_ZVRES->setDoubleParameter("Kalpha",); // Kaplha set on per jet basis
130  _ZVRES->setDoubleParameter("TwoProngCut",_TwoTrackCut);
131  _ZVRES->setDoubleParameter("TrackTrimCut",_TrackTrimCut);
132  _ZVRES->setDoubleParameter("ResolverCut",_ResolverCut);
133  _ZVRES->setStringParameter("AutoJetAxis","TRUE");
134  _ZVRES->setStringParameter("UseEventIP","TRUE");
135 
136 }
137 
138 void ZVTOPZVRESProcessor::processRunHeader( LCRunHeader* run) {
139  _nRun++ ;
140 }
141 
142 void ZVTOPZVRESProcessor::processEvent( LCEvent * evt ) {
143  //Make Event from
144  LCCollection* JetCollection;
145  JetCollection = evt->getCollection( _JetRPCollectionName );
146 
147  //Create an Event with an IP determined by the parameters or a vertex
148  Vector3 IPPos;
149  SymMatrix3x3 IPErr;
150  if (_ManualPrimaryVertex)
151  {
152  //Make the manulal ip from the params
153  //TODO Check length of vectors and throw if wrong
154  IPPos.x() = _ManualPrimaryVertexPos[0];
155  IPPos.y() = _ManualPrimaryVertexPos[1];
156  IPPos.z() = _ManualPrimaryVertexPos[2];
157  IPErr(0,0) = _ManualPrimaryVertexErr[0];
158  IPErr(1,0) = _ManualPrimaryVertexErr[1];
159  IPErr(1,1) = _ManualPrimaryVertexErr[2];
160  IPErr(2,0) = _ManualPrimaryVertexErr[3];
161  IPErr(2,1) = _ManualPrimaryVertexErr[4];
162  IPErr(2,2) = _ManualPrimaryVertexErr[5];
163  }
164  else
165  {
166  //Find the primary vertex in the event
167  LCCollection* VertexCol;
168  VertexCol = evt->getCollection( _IPVertexCollectionName );
169 
170  //Search throught the vertices in this colection to find the primary
171  int nVerts = VertexCol->getNumberOfElements() ;
172  bool done = 0;
173  for(int i=0; i< nVerts ; i++)
174  {
175  lcio::Vertex* iVertex = dynamic_cast<lcio::Vertex*>(VertexCol->getElementAt(i));
176  if (iVertex->isPrimary())
177  {
178  IPPos.x() = iVertex->getPosition()[0];
179  IPPos.y() = iVertex->getPosition()[1];
180  IPPos.z() = iVertex->getPosition()[2];
181  IPErr(0,0) = iVertex->getCovMatrix()[0];
182  IPErr(1,0) = iVertex->getCovMatrix()[1];
183  IPErr(1,1) = iVertex->getCovMatrix()[2];
184  IPErr(2,0) = iVertex->getCovMatrix()[3];
185  IPErr(2,1) = iVertex->getCovMatrix()[4];
186  IPErr(2,2) = iVertex->getCovMatrix()[5];
187  done = 1;
188  }
189  if (done) break;
190  }
191  if (!done) done = 1;//TODO Throw something
192  }
193  //Create an event with this IP
194  vertex_lcfi::Event* MyEvent = new vertex_lcfi::Event(IPPos,IPErr);
196 
197  //Create jets from LCIO and add them to the event
198  std::vector<std::string>::const_iterator it = find(evt->getCollectionNames()->begin(),evt->getCollectionNames()->end(),_DecayChainCollectionName);
199  if (it == evt->getCollectionNames()->end())
200  {
201  //Doesn't exist so make collection and add
202  LCCollection* MyCollection = new LCCollectionVec("ReconstructedParticle");
203  evt->addCollection(MyCollection,_DecayChainCollectionName);
204  }
205  std::cout << "Z:";
206  int nRCP = JetCollection->getNumberOfElements() ;
207  for(int i=0; i< nRCP ; i++)
208  {
209  Jet* MyJet = jetFromLCIORP(MyEvent,dynamic_cast<ReconstructedParticle*>(JetCollection->getElementAt(i)));
210 
211  //Set any jet depandant parameters
212  _ZVRES->setDoubleParameter("Kalpha", _JetWeightingEnergyScaling * MyJet->energy());
213 
214  //Run ZVTOP-ZVRES
215  DecayChain* ZVTOPResult = _ZVRES->calculateFor(MyJet);
216  std::cout << ZVTOPResult->vertices().size() << " ";
217 
218  //Store resulting decay chain in the LCIO file
219  ReconstructedParticle* LCIOZVTOPResult = addDecayChainToLCIOEvent(evt, ZVTOPResult,_VertexCollectionName, _DecayChainRPTracksCollectionName, _OutputTrackChi2);
220 
221  //Store the RP that holds all the vertexed tracks in LCIO
222  evt->getCollection(_DecayChainCollectionName)->addElement(LCIOZVTOPResult);
223 
224  //Commented out as we just rely on order
225  /*//LC Relate DecayChain and Jet
226  LCRelation* NewRelation = new LCRelationImpl(LCIOZVTOPResult,JetCollection->getElementAt(i));
227  it = find(evt->getCollectionNames()->begin(),evt->getCollectionNames()->end(),_RelationCollectionName);
228  if (it == evt->getCollectionNames()->end())
229  {
230  //Doesn't exist so make collection and add
231  LCCollection* MyCollection = new LCCollectionVec("LC_RELATION");
232  evt->addCollection(MyCollection,_RelationCollectionName);
233  }
234  evt->getCollection(_RelationCollectionName)->addElement(NewRelation);
235  */
236  }
237  //Clear all objects created for this event
238  std::cout << ",";std::cout.flush();
239  MetaMemoryManager::Event()->delAllObjects();
240  _nEvt ++ ;
241 }
242 
243 
244 
245 void ZVTOPZVRESProcessor::check( LCEvent * evt ) {
246  // nothing to check here - could be used to fill checkplots in reconstruction processor
247 }
248 
249 
250 void ZVTOPZVRESProcessor::end(){
251 
252  MetaMemoryManager::Run()->delAllObjects();
253  std::cout << "ZVTOPZVRESProcessor::end() " << name()
254  << " processed " << _nEvt << " events in " << _nRun << " runs "
255  << std::endl ;
256 
257 }
258 
void registerObject(T *pointer)
Register an object for memory management.
Find vertices in a jet using topological ZVTOP-ZVRES algorithm.
double energy() const
Energy.
const std::vector< Vertex * > & vertices() const
Vertices contained in DecayChain.
Definition: decaychain.cpp:80
virtual void setDoubleParameter(const string &Parameter, const double Value)=0
Set Double Parameter.
Algorithm interface for decay chain construction or vertexing.
virtual void setStringParameter(const string &Parameter, const string &Value)=0
Set String Parameter.
virtual OUTTYPE calculateFor(INTYPE Input) const =0
Run the algorithm on a jet.