00001 #include "lcio.h"
00002
00003 #include "IO/LCReader.h"
00004 #include "IMPL/LCTOOLS.h"
00005 #include "EVENT/LCCollection.h"
00006 #include "EVENT/Track.h"
00007 #include "EVENT/Cluster.h"
00008
00009 using namespace std ;
00010 using namespace lcio ;
00011
00012
00013
00014
00015
00016
00017
00018
00019 struct Index : LCIntExtension<Index> {} ;
00020
00021
00022 struct Mass : LCFloatExtension<Mass> {} ;
00023
00024
00025 struct ParticleIDs : LCOwnedExtensionVector<ParticleIDs,std::string> {};
00026
00027
00028
00029
00030 struct UserClass{
00031 int someInt ;
00032 float aFloat ;
00033 };
00034 struct MyUserExtension : LCOwnedExtension<MyUserExtension,UserClass> {} ;
00035
00036
00037
00038
00039
00040 struct TrkCluLink : LC1ToNRelation<TrkCluLink,Track,Cluster> {} ;
00041
00042
00043
00044 struct ParentDaughter : LCNToNRelation<ParentDaughter,MCParticle,MCParticle> {} ;
00045
00046
00047
00048
00049
00050
00051
00052
00053 int main(int argc, char** argv ){
00054
00055
00056 LCReader* lcReader = LCFactory::getInstance()->createLCReader() ;
00057
00058 lcReader->open( "recjob.slcio" ) ;
00059
00060 LCEvent* evt ;
00061 int nEvents = 0 ;
00062
00063
00064
00065 while( (evt = lcReader->readNextEvent()) != 0 && nEvents < 1 ) {
00066
00067
00068 LCCollection* mcpcol = evt->getCollection("MCParticle" ) ;
00069
00070 int nmcp = mcpcol->getNumberOfElements() ;
00071
00072 for(int i=0 ; i< nmcp ; i++ ){
00073
00074 MCParticle* mcp = dynamic_cast<MCParticle*>( mcpcol->getElementAt(i) ) ;
00075
00076
00077
00078
00079 mcp->ext<Index>() = i ;
00080
00081 mcp->ext<Mass>() = mcp->getMass() ;
00082
00083
00084
00085 mcp->ext<MyUserExtension>() = new UserClass ;
00086
00087 mcp->ext<MyUserExtension>()->someInt = i*42 ;
00088 mcp->ext<MyUserExtension>()->aFloat = i*3.1415 ;
00089
00090
00091
00092 if( ! (i % 2) )
00093
00094 mcp->ext<ParticleIDs>()->push_back( new std::string("charged") ) ;
00095
00096 else
00097
00098 mcp->ext<ParticleIDs>()->push_back( new std::string("neutral") ) ;
00099
00100 if( ! (i % 3) )
00101
00102 mcp->ext<ParticleIDs>()->push_back( new std::string("hadron") ) ;
00103
00104 else if( ! ((i+1) % 3) )
00105
00106 mcp->ext<ParticleIDs>()->push_back( new std::string("photon") ) ;
00107
00108 else if( ! ((i+2) % 3) )
00109
00110 mcp->ext<ParticleIDs>()->push_back( new std::string("electron") ) ;
00111
00112
00113
00114
00115 const MCParticleVec& daughters = mcp->getDaughters() ;
00116
00117 for(unsigned j=0 ; j< daughters.size() ; j++ ){
00118
00119 add_relation<ParentDaughter>( mcp, daughters[j] ) ;
00120 }
00121
00122
00123 }
00124
00125
00126 LCCollection* trkcol = evt->getCollection("SomeTracks" ) ;
00127 LCCollection* clucol = evt->getCollection("SomeClusters" ) ;
00128
00129 if( trkcol && clucol ) {
00130
00131 int nclu = clucol->getNumberOfElements() ;
00132 int ntrk = trkcol->getNumberOfElements() ;
00133
00134
00135 for(int j=0 ; j< ntrk ; j++ ){
00136
00137 Track* trk = dynamic_cast<Track*> ( trkcol->getElementAt(j) ) ;
00138
00139
00140
00141 trk->ext<Index>() = j ;
00142
00143 for(int k=0 ; k< nclu ; k++ ){
00144
00145 Cluster* clu = dynamic_cast<Cluster*> ( clucol->getElementAt(k) ) ;
00146
00147
00148 if( j == 0 )
00149 clu->ext<Index>() = k ;
00150
00151 if( j % 2 && ( k == j || k == j-1 ) )
00152
00153 add_relation<TrkCluLink>( trk ,clu );
00154 }
00155 }
00156
00157
00158
00159
00160 std::cout << " ---- tracks assigned to clusters: " << std::endl ;
00161 for(int j=0 ; j< ntrk ; j++ ){
00162
00163
00164 Track* trk = dynamic_cast<Track*> ( trkcol->getElementAt(j) ) ;
00165
00166 std::cout << " track " << trk->ext<Index>() << " assigned to clusters : " ;
00167
00168 TrkCluLink::to::rel_type clulist = trk->rel<TrkCluLink::to>() ;
00169
00170 for( TrkCluLink::to::const_iterator iclu = clulist->begin() ;
00171 iclu != clulist->end() ; ++iclu ){
00172
00173 Cluster* clu = *iclu ;
00174
00175 std::cout << clu->ext<Index>() << ", " ;
00176 }
00177 std::cout << std::endl ;
00178 }
00179
00180 std::cout << " ----- now the inverse relation : " << std::endl ;
00181
00182 for(int k=0 ; k< nclu ; k++ ){
00183
00184 Cluster* clu = dynamic_cast<Cluster*> ( clucol->getElementAt(k) ) ;
00185
00186
00187 Track* trk = clu->rel<TrkCluLink::from>() ;
00188
00189 std::cout << " cluster "
00190 << clu->ext<Index>() << " assigned from track: " ;
00191 if( trk != 0 )
00192 std::cout << trk->ext<Index>() << std::endl ;
00193 else
00194 std::cout << " none " << std::endl ;
00195 }
00196
00197 std::cout << std::endl ;
00198
00199
00200
00201
00202 std::cout << " ----- MCParticles in event : : " << std::endl ;
00203
00204 nmcp = ( nmcp < 10 ? nmcp : 10 ) ;
00205
00206 MCParticle* mcp0 = 0 ;
00207
00208 for(int i=0 ; i<nmcp ; i++ ){
00209
00210 MCParticle* mcp = dynamic_cast<MCParticle*>( mcpcol->getElementAt(i) ) ;
00211
00212 if( i == 0 ) mcp0 = mcp ;
00213
00214 ParticleIDs::ext_type pidv = mcp->ext<ParticleIDs>() ;
00215
00216 std::cout << " --- particle " << mcp->ext<Index>() << " found to be : " ;
00217
00218 for( ParticleIDs::const_iterator ipid = pidv->begin() ; ipid != pidv->end(); ++ipid){
00219
00220 std::cout << **ipid << ", " ;
00221 }
00222
00223 if( ( *(*pidv)[0] == "charged" && *(*pidv)[1] == "photon" ) ||
00224 ( *(*pidv)[0] == "neutral" && *(*pidv)[1] == "electron") )
00225
00226 std::cout << " --- ooops ! " ;
00227
00228 std::cout << std::endl ;
00229
00230
00231
00232 std::cout << " --- particle " << mcp->ext<Index>() << " user extension : "
00233 << " someInt: " << mcp->ext<MyUserExtension>()->someInt
00234 << " aFloat: " << mcp->ext<MyUserExtension>()->aFloat
00235 << std::endl ;
00236
00237
00238
00239
00240 const MCParticleVec& daughters = mcp->getDaughters() ;
00241
00242 std::cout << " --- particle " << mcp->ext<Index>() << " daughters: "
00243 << std::endl ;
00244
00245 std::cout << " --- from MCParticle: " ;
00246
00247 for(MCParticleVec::const_iterator idau = daughters.begin() ;
00248 idau != daughters.end() ; ++idau){
00249
00250 std::cout << (*idau)->ext<Index>() << ", " ;
00251 }
00252 std::cout << std::endl ;
00253
00254
00255 std::cout << " --- from runtime rel: " ;
00256
00257
00258 ParentDaughter::to::rel_type daulist = mcp->rel<ParentDaughter::to>() ;
00259
00260 for( ParentDaughter::to::const_iterator idau = daulist->begin();
00261 idau != daulist->end(); ++idau){
00262
00263 std::cout << (*idau)->ext<Index>() << ", " ;
00264 }
00265 std::cout << std::endl ;
00266
00267
00268 std::cout << " --- particle " << mcp->ext<Index>() << " parents: "
00269 << std::endl ;
00270
00271 std::cout << " --- from MCParticle: " ;
00272
00273
00274 const MCParticleVec& parents = mcp->getParents() ;
00275
00276 for(MCParticleVec::const_iterator ipar = parents.begin() ;
00277 ipar != parents.end() ; ++ipar){
00278
00279 std::cout << (*ipar)->ext<Index>() << ", " ;
00280 }
00281 std::cout << std::endl ;
00282
00283
00284 std::cout << " --- from runtime rel: " ;
00285
00286
00287 ParentDaughter::from::rel_type parlist = mcp->rel<ParentDaughter::from>() ;
00288
00289 for( ParentDaughter::from::const_iterator ipar = parlist->begin();
00290 ipar != parlist->end(); ++ipar){
00291
00292 std::cout << (*ipar)->ext<Index>() << ", " ;
00293 }
00294 std::cout << std::endl ;
00295
00296
00297
00298 if(i>0)
00299
00300 merge_relations<ParentDaughter>( mcp0 , mcp ) ;
00301 }
00302
00303
00304 for(int i=0 ; i<nmcp ; i++ ){
00305
00306 MCParticle* mcp = dynamic_cast<MCParticle*>( mcpcol->getElementAt(i) ) ;
00307
00308 std::cout << " --- particle " << mcp->ext<Index>() << " ( mass: " << mcp->ext<Mass>() << ") "
00309 << " daughters after merging : " ;
00310
00311
00312 ParentDaughter::to::rel_type daulist = mcp->rel<ParentDaughter::to>() ;
00313
00314 for( ParentDaughter::to::const_iterator idau = daulist->begin();
00315 idau != daulist->end(); ++idau){
00316
00317 std::cout << (*idau)->ext<Index>() << ", " ;
00318 }
00319 std::cout << std::endl ;
00320
00321 }
00322
00323
00324 } else {
00325 std::cout << " couldn't find Track and Cluster collection in event !" << std::endl ;
00326 }
00327
00328 nEvents ++ ;
00329 }
00330
00331
00332
00333 lcReader->close() ;
00334 delete lcReader ;
00335 return 0 ;
00336 }
00337
00338