LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SIOReconstructedParticleHandler.cc
Go to the documentation of this file.
2 
3 // -- lcio headers
4 #include "EVENT/LCIO.h"
7 #include "IMPL/LCFlagImpl.h"
8 
9 // -- sio headers
10 #include <sio/io_device.h>
11 #include <sio/version.h>
12 
13 // -- std headers
14 #include <bitset>
15 
16 namespace SIO {
17 
19  SIOObjectHandler( EVENT::LCIO::RECONSTRUCTEDPARTICLE ) {
20  /* nop */
21  }
22 
23  //----------------------------------------------------------------------------
24 
25  void SIOReconstructedParticleHandler::read( sio::read_device& device, EVENT::LCObject* objP, sio::version_type vers ) {
26  auto recP = dynamic_cast<IOIMPL::ReconstructedParticleIOImpl*>( objP ) ;
27  if( vers > SIO_VERSION_ENCODE( 1, 2 ) ) {
28  // type
29  SIO_DATA( device , &(recP->_type) , 1 ) ;
30  // momentum
31  float momentum[3] ;
32  SIO_DATA( device , momentum , 3 ) ;
33  recP->setMomentum( momentum ) ;
34  // energy
35  float energy ;
36  SIO_DATA( device , &energy , 1 ) ;
37  recP->setEnergy( energy ) ;
38  // covariance matrix
39  float errpos[ NCOVARIANCE ] ;
40  SIO_DATA( device , errpos , NCOVARIANCE ) ;
41  recP->setCovMatrix( errpos ) ;
42  // mass
43  float mass ;
44  SIO_DATA( device , &mass , 1 ) ;
45  recP->setMass( mass ) ;
46  // charge
47  SIO_DATA( device , &(recP->_charge) , 1 ) ;
48  // reference point
49  SIO_DATA( device , recP->_reference , 3 ) ;
50  // read PIDs
51  int nPid ;
52  SIO_DATA( device , &nPid , 1 ) ;
53  for( int i=0 ; i<nPid ; i++ ) {
54  // create new Pid objects
55  auto pid = new IOIMPL::ParticleIDIOImpl() ;
56  SIO_DATA( device , &(pid->_likelihood) , 1 ) ;
57  SIO_DATA( device , &(pid->_type) , 1 ) ;
58  SIO_DATA( device , &(pid->_pdg) , 1 ) ;
59  SIO_DATA( device , &(pid->_algorithmType) , 1 ) ;
60  int nPara ;
61  SIO_DATA( device , &nPara , 1 ) ;
62  float aParameter ;
63  for(int j=0;j<nPara;j++) {
64  SIO_DATA( device , &aParameter , 1 ) ;
65  pid->addParameter( aParameter ) ;
66  }
67  SIO_PTAG( device , pid ) ;
68  recP->addParticleID( pid) ;
69  }
70  SIO_PNTR( device , &(recP->_pidUsed) ) ;
71  SIO_DATA( device , &(recP->_goodnessOfPID) , 1 ) ;
72  // read reconstructed particles
73  int nRecP ;
74  SIO_DATA( device, &nRecP , 1 ) ;
75  recP->_particles.resize( nRecP ) ;
76  for( int i=0 ; i<nRecP ; i++ ) {
77  SIO_PNTR( device , &(recP->_particles[i] ) ) ;
78  }
79  // read tracks
80  int nTrk ;
81  SIO_DATA( device, &nTrk , 1 ) ;
82  recP->_tracks.resize( nTrk ) ;
83  for( int i=0 ; i<nTrk ; i++ ) {
84  SIO_PNTR( device , &(recP->_tracks[i] ) ) ;
85  }
86  // read clusters
87  int nClu ;
88  SIO_DATA( device, &nClu , 1 ) ;
89  recP->_clusters.resize( nClu ) ;
90  for( int i=0 ; i<nClu ; i++ ) {
91  SIO_PNTR( device , &(recP->_clusters[i] ) ) ;
92  }
93  if( vers > SIO_VERSION_ENCODE( 1,7 ) ) {
94  // read pointers to start/end vertices
95  SIO_PNTR( device , &(recP->_sv) ) ;
96  }
97  }
98  else { // old version (1.0-1.2 keep for a while - no official release !! )
99  int typeFlag ;
100  SIO_DATA( device , &typeFlag , 1 ) ;
101  recP->setType( 0x0000ffff & typeFlag ) ;
102  SIO_DATA( device , recP->_momentum , 3 ) ;
103  SIO_DATA( device , &(recP->_energy) , 1 ) ;
104  float errpos[ NCOVARIANCE ] ;
105  SIO_DATA( device , errpos , NCOVARIANCE ) ;
106  recP->setCovMatrix( errpos ) ;
107  SIO_DATA( device , &(recP->_mass) , 1 ) ;
108  SIO_DATA( device , &(recP->_charge) , 1 ) ;
109  SIO_DATA( device , recP->_reference , 3 ) ;
110  // read PIDs
111  int nPid ;
112  SIO_DATA( device , &nPid , 1 ) ;
113  for( int i=0 ; i<nPid ; i++ ) {
114  // create new Pid objects
115  auto pid = new IOIMPL::ParticleIDIOImpl() ;
116  SIO_DATA( device , &(pid->_likelihood) , 1 ) ;
117  SIO_DATA( device , &(pid->_type) , 1 ) ;
118  SIO_DATA( device , &(pid->_algorithmType) , 1 ) ;
119  int nPara ;
120  SIO_DATA( device , &nPara , 1 ) ;
121  float aParameter ;
122  for(int j=0;j<nPara;j++){
123  SIO_DATA( device , &aParameter , 1 ) ;
124  pid->addParameter( aParameter ) ;
125  }
126  recP->addParticleID( pid) ;
127  }
128  recP->_pidUsed = 0 ;
129  // read reconstructed particles
130  int nRecP ;
131  SIO_DATA( device, &nRecP , 1 ) ;
132  for( int i=0 ; i<nRecP ; i++ ) {
133  recP->_particles.push_back( 0 ) ;
134  }
135  float dummyWeights ;
136  for( int i=0 ; i<nRecP ; i++ ) {
137  SIO_PNTR( device , &(recP->_particles[i] ) ) ;
138  SIO_DATA( device , &dummyWeights , 1 ) ;
139  }
140  // read tracks
141  int nTrk ;
142  SIO_DATA( device, &nTrk , 1 ) ;
143  for( int i=0 ; i<nTrk ; i++ ) {
144  recP->_tracks.push_back( 0 ) ;
145  }
146  for( int i=0 ; i<nTrk ; i++ ) {
147  SIO_PNTR( device , &(recP->_tracks[i] ) ) ;
148  SIO_DATA( device , &dummyWeights , 1 ) ;
149  }
150  // read clusters
151  int nClu ;
152  SIO_DATA( device, &nClu , 1 ) ;
153  for( int i=0 ; i<nClu ; i++ ) {
154  recP->_clusters.push_back( 0 ) ;
155  }
156  for( int i=0 ; i<nClu ; i++ ) {
157  SIO_PNTR( device , &(recP->_clusters[i] ) ) ;
158  SIO_DATA( device , &dummyWeights , 1 ) ;
159  }
160  // read MCParticles
161  int nMCP ;
162  SIO_DATA( device, &nMCP , 1 ) ;
163  SIO_DATA( device , &dummyWeights , nMCP ) ;
164  SIO_DATA( device , &dummyWeights , nMCP ) ;
165  } // --- end old version 1.0-1.2
166  // read the pointer tag
167  SIO_PTAG( device , dynamic_cast<const EVENT::ReconstructedParticle*>(recP) ) ;
168  }
169 
170  //----------------------------------------------------------------------------
171 
172  void SIOReconstructedParticleHandler::write( sio::write_device& device, const EVENT::LCObject* obj ) {
173  auto recP = dynamic_cast<const EVENT::ReconstructedParticle*>( obj ) ;
174  SIO_SDATA( device, recP->getType() ) ;
175  SIO_SDATA( device, (float) recP->getMomentum()[0] ) ;
176  SIO_SDATA( device, (float) recP->getMomentum()[1] ) ;
177  SIO_SDATA( device, (float) recP->getMomentum()[2] ) ;
178  SIO_SDATA( device, (float) recP->getEnergy() ) ;
179  auto cov = recP->getCovMatrix() ;
180  for( unsigned int i=0 ; i<cov.size() ; i++ ) {
181  SIO_SDATA( device, cov[i] ) ;
182  }
183  SIO_SDATA( device, (float) recP->getMass() ) ;
184  SIO_SDATA( device, recP->getCharge() ) ;
185  SIO_DATA( device, recP->getReferencePoint() , 3 ) ;
186  // write Pids
187  int nPid = recP->getParticleIDs().size() ;
188  SIO_DATA( device , &nPid , 1 ) ;
189 
190  for( int i=0 ; i<nPid ; i++ ) {
191  auto pid = recP->getParticleIDs()[i] ;
192  SIO_SDATA( device, pid->getLikelihood() ) ;
193  SIO_SDATA( device, pid->getType() ) ;
194  SIO_SDATA( device, pid->getPDG() ) ;
195  SIO_SDATA( device, pid->getAlgorithmType() ) ;
196  int nPara = pid->getParameters().size() ;
197  SIO_DATA( device , &nPara , 1 ) ;
198  for(int j=0;j<nPara;j++){
199  SIO_SDATA( device, pid->getParameters()[j] ) ;
200  }
201  SIO_PTAG( device , pid ) ;
202  }
203  auto pidUsed = recP->getParticleIDUsed() ;
204  SIO_PNTR( device , &pidUsed ) ;
205  SIO_SDATA( device, recP->getGoodnessOfPID() ) ;
206  // write reconstructed particles
207  int nReconstructedParticles = recP->getParticles().size() ;
208  SIO_DATA( device, &nReconstructedParticles , 1 ) ;
209  for( int i=0 ; i<nReconstructedParticles ; i++ ) {
210  SIO_PNTR( device , &(recP->getParticles()[i]) ) ;
211  }
212  // write tracks
213  int nTrk = recP->getTracks().size() ;
214  SIO_DATA( device, &nTrk , 1 ) ;
215  for( int i=0 ; i<nTrk ; i++ ) {
216  SIO_PNTR( device , &(recP->getTracks()[i]) ) ;
217  }
218  // write clusters
219  int nClu = recP->getClusters().size() ;
220  SIO_DATA( device, &nClu , 1 ) ;
221  for( int i=0 ; i<nClu ; i++ ) {
222  SIO_PNTR( device , &(recP->getClusters()[i]) ) ;
223  }
224  // write pointers to start/end vertices
225  auto sv = recP->getStartVertex() ;
226  SIO_PNTR( device , &sv ) ;
227  // write a ptag in order to be able to point to recPs
228  SIO_PTAG( device , recP ) ;
229  }
230 
231  //----------------------------------------------------------------------------
232 
235  }
236 
237 } // namespace
The generic object that is held in an LCCollection.
Definition: LCObject.h:30
void read(sio::read_device &device, EVENT::LCObject *objP, sio::version_type vers) override
Reads lcio objects from an SIO stream.
EVENT::LCObject * create() const override
Factory method to create an object of the type of the collection.
Adding stuff needed for io (friend declarations, etc.)
Interface for all lcio object SIO-handlers, has to be implemented for all event entities (hits...
#define NCOVARIANCE
static const int nRecP
Definition: recjob.cc:41
void write(sio::write_device &device, const EVENT::LCObject *obj) override
Writes lcio objects to an SIO stream.
virtual const FloatVec & getCovMatrix() const =0
Covariance matrix of the reconstructed particle&#39;s 4vector (10 parameters).
Adding stuff needed for io (friend declarations, etc.)
The LCIO reconstructedParticle.