Public Member Functions | |
RunEventProcessor (const char *outFileName) | |
~RunEventProcessor () | |
void | modifyEvent (LCEvent *evt) |
void | processEvent (LCEvent *evt) |
void | modifyRunHeader (LCRunHeader *run) |
void | processRunHeader (LCRunHeader *run) |
RunEventProcessor () | |
~RunEventProcessor () | |
void | processEvent (LCEvent *evt) |
void | modifyEvent (LCEvent *evt) |
void | processRunHeader (LCRunHeader *run) |
void | modifyRunHeader (LCRunHeader *run) |
Protected Attributes | |
LCWriter * | lcWrt |
int | nEvent |
LCWriter * | lcWrt |
Definition at line 23 of file copyfix.cc.
RunEventProcessor::RunEventProcessor | ( | const char * | outFileName | ) | [inline] |
Definition at line 31 of file copyfix.cc.
00031 : nEvent(0) { 00032 00033 // open outputfile 00034 lcWrt = LCFactory::getInstance()->createLCWriter() ; 00035 00036 try{ lcWrt->open( outFileName , LCIO::WRITE_NEW ) ; } 00037 00038 catch(IOException& e){ 00039 cout << "[RunEventProcessor()] Can't open file for writing - " 00040 << e.what() << endl ; 00041 exit(1) ; 00042 } 00043 00044 }
RunEventProcessor::~RunEventProcessor | ( | ) | [inline] |
Definition at line 46 of file copyfix.cc.
00046 { 00047 // close outputfile 00048 lcWrt->close() ; 00049 cout << endl << " " << nEvent << " events copied ! " << endl ; 00050 }
RunEventProcessor::RunEventProcessor | ( | ) | [inline] |
Definition at line 65 of file recjob.cc.
00065 : nEvent(0) { 00066 00067 // open outputfile 00068 lcWrt = LCFactory::getInstance()->createLCWriter() ; 00069 00070 try{ 00071 lcWrt->setCompressionLevel( 9 ) ; 00072 lcWrt->open( OUTFILEN , LCIO::WRITE_NEW ) ; 00073 } 00074 00075 catch(IOException& e){ 00076 cout << "[RunEventProcessor()] Can't open file for writing - " 00077 << e.what() << endl ; 00078 exit(1) ; 00079 } 00080 00081 }
RunEventProcessor::~RunEventProcessor | ( | ) | [inline] |
Definition at line 83 of file recjob.cc.
00083 { 00084 00085 // close outputfile 00086 lcWrt->close() ; 00087 00088 cout << endl 00089 << " added collection: 'SomeClusters' and 'SomeTracks'" 00090 << " to " << nEvent <<" events" 00091 << " and added one extra MCParticle to each event." 00092 << endl << endl ; 00093 delete lcWrt ; 00094 }
void RunEventProcessor::modifyEvent | ( | LCEvent * | evt | ) | [inline] |
void RunEventProcessor::processEvent | ( | LCEvent * | evt | ) | [inline] |
Definition at line 54 of file copyfix.cc.
00054 { 00055 00056 // just copy events to outputfiles 00057 lcWrt->writeEvent( evt ) ; 00058 nEvent ++ ; 00059 // cout << " event: " << evt->getEventNumber() 00060 // << " [run: " << evt->getRunNumber() << "] copied" << endl ; 00061 }
void RunEventProcessor::modifyRunHeader | ( | LCRunHeader * | run | ) | [inline] |
void RunEventProcessor::processRunHeader | ( | LCRunHeader * | run | ) | [inline] |
Definition at line 66 of file copyfix.cc.
00066 { 00067 00068 // just copy run headers to the outputfile 00069 lcWrt->writeRunHeader( run ) ; 00070 // cout << "run : " << run->getRunNumber() << " [" 00071 // << run->getDescription() << "] - header copied " << endl ; 00072 }
void RunEventProcessor::processEvent | ( | LCEvent * | evt | ) | [inline] |
Definition at line 96 of file recjob.cc.
00096 { /* used for 'read only' access*/ 00097 00098 00099 // this is our event loop code 00100 00101 // read collection with MCParticles 00102 // LCCollection* mcVec = evt->getCollection( LCIO::MCPARTICLE ) ; 00103 // int NMCPART = mcVec->getNumberOfElements() ; 00104 00105 00106 // ---- trying to modify objects here would cause a ReadOnlyExcpetion. e.g. ----- 00107 // for(int i=0 ; i< NMCPART ; i++ ){ 00108 // MCParticleImpl* part = dynamic_cast<MCParticleImpl*>( mcVec->getElementAt( i )) ; 00109 // part->setPDG(1234) ; // <<<<< ------- will cause ReadOnlyException --------- 00110 // } 00111 // ---- also adding sth. to en existing collection is not allowed here ---- 00112 // MCParticleImpl* part = new MCParticleImpl ; 00113 // part->setPDG( 1234 ) ; 00114 // part->setParent( dynamic_cast<MCParticle*>( mcVec->getElementAt(0) )) ; 00115 // mcVec->addElement( part ) ; // <<<<< ------- will cause ReadOnlyException --------- 00116 00117 00118 00119 // create some tracks and add them to the event 00120 std::string tpcHitName( "TrackerRawDataExample" ) ; 00121 00122 // in order to be able to point back to hits, we need to create 00123 // generic TrackerHits from the TrackerRawDatas first 00124 00125 LCCollection* tpcHits = evt->getCollection( tpcHitName) ; 00126 00127 // here we set the pointer flag bit that is needed to be able to point from 00128 // the generic TrckerHit to the raw data TrackerRawData 00129 //fg20040824 -> THE LOGIC IS REVERSED - NO NEED TO SET A BIT TO GET THE POINTER FLAG 00130 // LCFlagImpl tpcFlag( tpcHits->getFlag() ) ; 00131 // tpcFlag.setBit( LCIO::TPCBIT_PTR ) ; 00132 // tpcHits->setFlag( tpcFlag.getFlag() ) ; 00133 00134 LCCollectionVec* trkhitVec = new LCCollectionVec( LCIO::TRACKERHIT ) ; 00135 int nTrackerRawDatas = tpcHits->getNumberOfElements() ; 00136 00137 for(int j=0;j<nTrackerRawDatas;j++){ 00138 TrackerHitImpl* trkHit = new TrackerHitImpl ; 00139 00140 TrackerRawData* tpcRawHit = dynamic_cast<TrackerRawData*> ( tpcHits->getElementAt(j) ) ; 00141 00142 trkHit->setTime( tpcRawHit->getTime() ) ; 00143 00144 int cellID = tpcRawHit->getCellID0() ; 00145 double pos[3] = { (cellID & 0xff) , (cellID & 0xff00)>>8 , (cellID & 0xff0000)>>16 } ; 00146 trkHit->setPosition( pos ) ; 00147 00148 trkHit->rawHits().push_back( tpcRawHit ) ; // store the original raw data hit 00149 trkHit->rawHits().push_back( tpcRawHit ) ; // for testing add the same raw hit twice 00150 00151 FloatVec cov(6) ; 00152 cov[0] = 1. ; 00153 cov[1] = 2. ; 00154 cov[2] = 3. ; 00155 cov[3] = 4. ; 00156 cov[4] = 5. ; 00157 cov[5] = 6. ; 00158 trkHit->setCovMatrix( cov ) ; 00159 00160 trkhitVec->addElement( trkHit ) ; 00161 } 00162 00163 // set the parameters to decode the type information in the collection 00164 // for the time being this has to be done manually 00165 // in the future we should provide a more convenient mechanism to 00166 // decode this sort of meta information 00167 StringVec typeNames ; 00168 IntVec typeValues ; 00169 typeNames.push_back( LCIO::TPCHIT ) ; 00170 typeValues.push_back( 1 ) ; 00171 trkhitVec->parameters().setValues("TrackerHitTypeNames" , typeNames ) ; 00172 trkhitVec->parameters().setValues("TrackerHitTypeValues" , typeValues ) ; 00173 00174 00175 evt->addCollection( trkhitVec , "TrackerHits") ; 00176 00177 00178 LCCollectionVec* trkVec = new LCCollectionVec( LCIO::TRACK ) ; 00179 00180 // if we want to point back to the hits we need to set the flag 00181 LCFlagImpl trkFlag(0) ; 00182 trkFlag.setBit( LCIO::TRBIT_HITS ) ; 00183 trkVec->setFlag( trkFlag.getFlag() ) ; 00184 00185 00186 int nTrk = 5 ; 00187 for( int i=0; i < nTrk ; i ++ ){ 00188 00189 TrackImpl* trk = new TrackImpl ; 00190 trk->setTypeBit( 7 ) ; 00191 trk->setOmega( (i+1)*1.1 ) ; 00192 trk->setTanLambda( (i+1)* M_PI / 10. ) ; 00193 trk->setPhi( (i+1)* M_PI / 5. ) ; 00194 trk->setD0( i+1 ) ; 00195 trk->setZ0( (i+1)*10. ) ; 00196 trk->setChi2( 1.01 ) ; 00197 trk->setNdf( 42 ) ; 00198 00199 trk->setRadiusOfInnermostHit( 3.141592 ) ; 00200 00201 // set the hit numbers 00202 const int NTRACKER = 3 ; 00203 const int VTXINDEX = 0 ; 00204 const int SITINDEX = 1 ; 00205 const int TPCINDEX = 2 ; 00206 StringVec trackerNames ; 00207 trackerNames.resize( NTRACKER ) ; 00208 trackerNames[VTXINDEX] = "VTX" ; 00209 trackerNames[SITINDEX] = "SIT" ; 00210 trackerNames[TPCINDEX] = "TPC" ; 00211 00212 trkVec->parameters().setValues( "TrackSubdetectorNames" , trackerNames ) ; 00213 00214 trk->subdetectorHitNumbers().resize( NTRACKER ) ; 00215 trk->subdetectorHitNumbers()[ VTXINDEX ] = 12 ; 00216 trk->subdetectorHitNumbers()[ SITINDEX ] = 24 ; 00217 trk->subdetectorHitNumbers()[ TPCINDEX ] = 36 ; 00218 00219 trk->setdEdx( 3.14159 ) ; 00220 trk->setdEdxError( 42. ) ; 00221 float cov[15] = { 1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15. } ; 00222 trk->setCovMatrix( cov ) ; 00223 float ref[3] = { 12. ,123456789. , .0987654321 } ; 00224 trk->setReferencePoint( ref ) ; 00225 00226 // add some random hits 00227 int iHit1 = (int) ( double (trkhitVec->size()) * rand() / RAND_MAX ) ; 00228 int iHit2 = (int) ( double (trkhitVec->size()) * rand() / RAND_MAX ) ; 00229 int iHit3 = (int) ( double (trkhitVec->size()) * rand() / RAND_MAX ) ; 00230 00231 trk->addHit( dynamic_cast<TrackerHit*>( (*trkhitVec)[iHit1] ) ) ; 00232 trk->addHit( dynamic_cast<TrackerHit*>( (*trkhitVec)[iHit2] ) ) ; 00233 trk->addHit( dynamic_cast<TrackerHit*>( (*trkhitVec)[iHit3] ) ) ; 00234 00235 00236 // add tracks that where used to create this track 00237 if( trkVec->size() > 1 ){ 00238 trk->addTrack( dynamic_cast<TrackImpl*> ( (*trkVec)[ trkVec->size() - 1 ] ) ) ; 00239 trk->addTrack( dynamic_cast<TrackImpl*> ( (*trkVec)[ trkVec->size() - 2 ] ) ) ; 00240 } 00241 00242 trkVec->addElement( trk ) ; 00243 } 00244 00245 00246 evt->addCollection( trkVec , "SomeTracks" ) ; 00247 00248 00249 // create some clusters and add them to the event 00250 std::string simcalHitName( "ECAL007" ) ; 00251 00252 LCCollection* simcalHits = evt->getCollection( simcalHitName ) ; 00253 00254 // // create a collection with copied simhits and modify these 00255 // // (test copy constructor - NOT YET AVAILABLE FOR OTHER CLASSES !) 00256 // LCCollection* modifiedSimCalHits = new LCCollectionVec( LCIO::SIMCALORIMETERHIT ); 00257 00258 LCCollectionVec* clusterVec = new LCCollectionVec( LCIO::CLUSTER ) ; 00259 LCCollectionVec* calHits = new LCCollectionVec( LCIO::CALORIMETERHIT ) ; 00260 // in order to be able to point back to hits, we need to create 00261 // generic CalorimeterHits from the SimCalorimeterHits first 00262 00263 // here we set the pointer flag bit that is needed to be able to point from 00264 // the generic Clusters to the 'raw data' CalorimeterHits 00265 //-> this should be done automatically in a future release 00266 //fg20040824 -> THE LOGIC IS REVERSED - NO NEED TO SET A BIT TO GET THE POINTER FLAG 00267 // LCFlagImpl calFlag( calHits->getFlag() ) ; 00268 // calFlag.setBit( LCIO::RCHBIT_PTR ) ; 00269 // calHits->setFlag( calFlag.getFlag() ) ; 00270 00271 00272 LCCollectionVec* scRel = new LCCollectionVec(LCIO::LCRELATION ) ; 00273 scRel->parameters().setValue( "RelationFromType" , LCIO::CALORIMETERHIT ) ; 00274 scRel->parameters().setValue( "RelationToType" , LCIO::SIMCALORIMETERHIT ) ; 00275 00276 int nSimHits = simcalHits->getNumberOfElements() ; 00277 for(int j=0;j<nSimHits;j++){ 00278 00279 CalorimeterHitImpl* calHit = new CalorimeterHitImpl ; 00280 SimCalorimeterHit* simcalHit = dynamic_cast<SimCalorimeterHit*> ( simcalHits->getElementAt(j) ) ; 00281 00282 // std::cout << " adding new calorimeter hit and relation : " << j << " : " << calHit << " - " << simcalHit << std::endl ; 00283 00284 calHit->setEnergy( simcalHit->getEnergy() ) ; 00285 calHit->setCellID0( simcalHit->getCellID0() ) ; 00286 calHit->setPosition( simcalHit->getPosition()) ; 00287 00288 // scRel->addRelation( calHit , simcalHit , 0.5 ) ; 00289 // scRel->addRelation( calHit , simcalHit , 0.5 ) ; 00290 scRel->addElement( new LCRelationImpl( calHit , simcalHit , 0.5 ) ) ; 00291 scRel->addElement( new LCRelationImpl( calHit , simcalHit , 0.5 ) ) ; 00292 scRel->addElement( new LCRelationImpl( calHit , simcalHit , 0.5 ) ) ; 00293 calHits->addElement( calHit ) ; 00294 00295 // // create a copy of sim hit and modify it 00296 // SimCalorimeterHitImpl* mSimHit = new SimCalorimeterHitImpl( *simcalHit ) ; 00297 // mSimHit->setEnergy( mSimHit->getEnergy() * 1000. ) ; 00298 // modifiedSimCalHits->addElement( mSimHit ) ; 00299 00300 } 00301 evt->addCollection( calHits , "CalorimeterHits") ; 00302 // evt->addCollection( modifiedSimCalHits , "ModifiedSimCalorimeterHits") ; 00303 00304 LCFlagImpl relFlag(0) ; 00305 relFlag.setBit( LCIO::LCREL_WEIGHTED ) ; 00306 scRel->setFlag( relFlag.getFlag() ) ; 00307 00308 evt->addCollection( scRel , "CalorimeterHitsSimRel" ) ; 00309 // evt->addRelation( scRel , "CalorimeterHitsSimRel" ) ; 00310 00311 00312 00313 00314 if( evt->getEventNumber() == 0 && evt->getRunNumber() == 0 ) { 00315 00316 00317 //------ the following is some example code on how to access the relation: -------------- 00318 // create a navigation object from a collection 00319 LCRelationNavigator rel( scRel ) ; 00320 00321 std::cout << "Relation example for first event: " 00322 << " [" << rel.getFromType() << " - " << rel.getToType() << "] " 00323 << std::endl ; 00324 00325 int nCalHits = calHits->getNumberOfElements() ; 00326 for(int j=0; j < nCalHits ; j++){ 00327 CalorimeterHit* calHit = dynamic_cast<CalorimeterHit*>( calHits->getElementAt(j) ) ; 00328 00329 std::cout << " relations for object " << hex << calHit->id() 00330 ; // << std::endl ; 00331 00332 const LCObjectVec& simHits = rel.getRelatedToObjects( calHit ) ; 00333 const FloatVec& weights = rel.getRelatedToWeights( calHit ) ; 00334 00335 int nSimHits = simHits.size() ; 00336 for(int k=0;k<nSimHits;k++){ 00337 00338 std::cout << " [" << simHits[k]->id() << "] (" 00339 << weights[k] << ") " ; 00340 } 00341 std::cout << dec << std::endl ; 00342 } 00343 00344 00345 // ------------------------------------------------------------------------------------- 00346 00347 // add some calibration constants as generic user objects 00348 00349 LCCollectionVec* calVec = new LCCollectionVec( LCIO::LCGENERICOBJECT ) ; 00350 for(int j=0;j<nCalHits;j++){ 00351 00352 CalorimeterHit* calHit = dynamic_cast<CalorimeterHit*>( calHits->getElementAt(j) ) ; 00353 00354 CalibrationConstant* cCon = new CalibrationConstant( calHit->getCellID0() , 00355 1.*j , 0.01*j ); 00356 calVec->addElement( cCon ) ; 00357 } 00358 00359 evt->addCollection( calVec , "Calibration" ) ; 00360 } 00361 00362 // debug test: add empty collection of LCGenericObjects 00363 LCCollectionVec* emtpyCol = new LCCollectionVec( LCIO::LCGENERICOBJECT ) ; 00364 evt->addCollection( emtpyCol , "EmptyLCGenericObject" ) ; 00365 00366 // ------------------------------------------------------------------------------------- 00367 00368 // if we want to point back to the hits we need to set the flag 00369 LCFlagImpl clusterFlag(0) ; 00370 clusterFlag.setBit( LCIO::CLBIT_HITS ) ; 00371 clusterVec->setFlag( clusterFlag.getFlag() ) ; 00372 00373 StringVec shapeParams ; 00374 shapeParams.push_back("Shape_trans") ; 00375 shapeParams.push_back("Shape_long") ; 00376 shapeParams.push_back("Shape_axis_x") ; 00377 shapeParams.push_back("Shape_axis_y") ; 00378 shapeParams.push_back("Shape_axis_z") ; 00379 shapeParams.push_back("Shape_quality") ; 00380 00381 clusterVec->parameters().setValues( "ClusterShapeParameters" , shapeParams ) ; 00382 00383 // IntVec algoIDs ; 00384 // enum { 00385 // RunEventProcessorID = 1 , 00386 // anotherAlgorithmID, 00387 // andYetAnotherAlgorithmID 00388 // } ; 00389 00390 // algoIDs.push_back( RunEventProcessorID ) ; 00391 // algoIDs.push_back( anotherAlgorithmID ) ; 00392 // algoIDs.push_back( andYetAnotherAlgorithmID ) ; 00393 00394 // StringVec algoNames ; 00395 // algoNames.push_back("recojob-RunEventProcessor") ; 00396 // algoNames.push_back("anotherAlgorithm") ; 00397 // algoNames.push_back("andYetAnotherAlgorithm") ; 00398 00399 // clusterVec->parameters().setValues( "PIDAlgorithmTypeName" , algoNames ) ; 00400 // clusterVec->parameters().setValues( "PIDAlgorithmTypeID" , algoIDs ) ; 00401 00402 00403 00404 if( calHits ){ 00405 00406 int nHits = calHits->getNumberOfElements() ; 00407 int nCluster = nHits / 10 ; 00408 00409 00410 00411 PIDHandler cluPidHandler( clusterVec ) ; 00412 00413 StringVec pNames ; 00414 pNames.push_back( "param0" ); 00415 pNames.push_back( "param1" ); 00416 pNames.push_back( "param2" ); 00417 00418 IntVec algoIDs(3) ; 00419 algoIDs[0] = cluPidHandler.addAlgorithm( "recojobRunEventProcessor" , pNames ) ; 00420 algoIDs[1] = cluPidHandler.addAlgorithm( "anotherAlgorithm" , pNames ) ; 00421 algoIDs[2] = cluPidHandler.addAlgorithm( "andYetAnotherAlgorithm" , pNames ) ; 00422 00423 for( int i=0; i < nCluster ; i ++ ){ 00424 00425 ClusterImpl* cluster = new ClusterImpl ; 00426 00427 // int type = ( Cluster::COMBINED << 16 | Cluster::CHARGED ) ; 00428 cluster->setTypeBit( 1 ) ; 00429 cluster->setTypeBit( 7 ) ; 00430 cluster->setTypeBit( 11 ) ; 00431 00432 cluster->setEnergy( (i+1)*1.1 ) ; 00433 float pos[3] = { 12. ,123456789. , .0987654321 } ; 00434 cluster->setPosition( pos ) ; 00435 float errpos[6] = { 1.,2.,3.,4.,5.,6.} ; 00436 cluster->setPositionError( errpos ) ; 00437 cluster->setITheta( (i+1)* M_PI / 10. ) ; 00438 cluster->setIPhi( (i+1)* M_PI / 5. ) ; 00439 float errdir[6] = { 1.,2.,3.} ; 00440 cluster->setDirectionError( errdir ) ; 00441 00442 // set the cluster ashape variables 00443 float shapeArray[6] = { 1.,2.,3.,3.,2.,1.} ; 00444 FloatVec shape ; 00445 copy( &shapeArray[0] , &shapeArray[5] , back_inserter( shape ) ) ; 00446 cluster->setShape( shape ) ; 00447 00448 // // add some particle ids 00449 // int nPID = 5 ; 00450 // for(int j=0;j<nPID;j++){ 00451 // ParticleIDImpl* pid = new ParticleIDImpl ; 00452 // pid->setLikelihood( (double) j / nPID ) ; 00453 // pid->setType( j ) ; 00454 // pid->setPDG( -11 ) ; 00455 // pid->setAlgorithmType( RunEventProcessorID ) ; 00456 00457 // for(int k=0;k<3;k++){ 00458 // pid->addParameter( k*.1 ) ; 00459 // } 00460 // cluster->addParticleID( pid ) ; 00461 // } 00462 // add some particle ids 00463 int nPID = algoIDs.size() ; 00464 00465 for(int j=0;j<nPID;j++){ 00466 00467 00468 // some parameters 00469 FloatVec fv( pNames.size() ) ; 00470 for( unsigned k=0 ; k < pNames.size() ; k++){ 00471 fv[k] = j*1000.+k*.1 ; 00472 } 00473 00474 cluPidHandler.setParticleID( cluster, 00475 j , // user type 00476 22 , // PDG 00477 1.*j / nPID , // likelihood 00478 algoIDs[j] , 00479 fv ) ; 00480 00481 } 00482 00483 00484 // add some subdetector energies 00485 const int NCALORIMETER = 2 ; 00486 const int ECALINDEX = 0 ; 00487 const int HCALINDEX = 1 ; 00488 StringVec detNames ; 00489 detNames.resize( NCALORIMETER ) ; 00490 detNames[ECALINDEX] = "Ecal" ; 00491 detNames[HCALINDEX] = "Hcal" ; 00492 clusterVec->parameters().setValues( "ClusterSubdetectorNames" , detNames ) ; 00493 00494 00495 cluster->subdetectorEnergies().resize( NCALORIMETER ) ; 00496 cluster->subdetectorEnergies()[ ECALINDEX ] = 42.42 ; 00497 cluster->subdetectorEnergies()[ HCALINDEX ] = 24.24 ; 00498 00499 // add some random hits 00500 int iHit1 = (int) ( double (calHits->size()) * rand() / RAND_MAX ) ; 00501 int iHit2 = (int) ( double (calHits->size()) * rand() / RAND_MAX ) ; 00502 int iHit3 = (int) ( double (calHits->size()) * rand() / RAND_MAX ) ; 00503 00504 cluster->addHit( dynamic_cast<CalorimeterHit*>( (*calHits)[iHit1] ) , 1.0 ) ; 00505 cluster->addHit( dynamic_cast<CalorimeterHit*>( (*calHits)[iHit2] ) , 2.0 ) ; 00506 cluster->addHit( dynamic_cast<CalorimeterHit*>( (*calHits)[iHit3] ) , 3.0 ) ; 00507 00508 // add clusters that where used to create this cluster 00509 if( clusterVec->size() > 1 ){ 00510 cluster->addCluster( dynamic_cast<ClusterImpl*> 00511 ( (*clusterVec)[ clusterVec->size() - 1 ] ) ) ; 00512 cluster->addCluster( dynamic_cast<ClusterImpl*> 00513 ( (*clusterVec)[ clusterVec->size() - 2 ] ) ) ; 00514 } 00515 00516 00517 clusterVec->addElement( cluster ) ; 00518 } 00519 } 00520 00521 evt->addCollection( clusterVec , "SomeClusters" ) ; 00522 00523 // add some vertices 00524 LCCollectionVec* vertexVec = new LCCollectionVec( LCIO::VERTEX ) ; 00525 00526 //EXP: INDEX MAP - UNDER DEVELOPMENT 00527 //UTIL::IndexMap imvtx(vertexVec, "AlgorithmNames", "AlgorithmTypes"); 00528 00529 for(int i=0; i < (nRecP+1); i++){ 00530 VertexImpl* vtx = new VertexImpl ; 00531 if(i==0){ 00532 vtx->setPrimary(true); 00533 }else{ 00534 vtx->setPrimary(false); 00535 } 00536 /* 00537 //EXP: INDEX MAP - UNDER DEVELOPMENT 00538 00539 switch(i){ 00540 case 0: vtx->setAlgorithmType( imvtx.encode( "ZvTop" ) ); break; 00541 case 1: vtx->setAlgorithmType( imvtx.encode( "ZvKin" ) ); break; 00542 case 5: vtx->setAlgorithmType( imvtx.encode( "SimAnnealing" ) ); break; 00543 default: break; 00544 } 00545 */ 00546 00547 //EXP: INDEX MAP V2 - UNDER DEVELOPMENT 00548 switch(rand()%7){ 00549 case 0: vtx->setAlgorithmType( "ZvTop" ); break; 00550 case 1: vtx->setAlgorithmType( "ZvKin" ); break; 00551 case 2: vtx->setAlgorithmType( "42" ); break; 00552 case 3: vtx->setAlgorithmType( "SimAnnealing" ); break; 00553 case 5: vtx->setAlgorithmType( "_Test" ); break; 00554 default: break; 00555 } 00556 00557 vtx->setChi2(1+i*.01); 00558 vtx->setProbability(0.0032+i*.01); 00559 vtx->setPosition(0.3453+i*.01,.45345354+i*.01,2.345354+i*.01); 00560 00561 FloatVec cov(6) ; 00562 cov[0] = 1. ; 00563 cov[1] = 2. ; 00564 cov[2] = 3. ; 00565 cov[3] = 4. ; 00566 cov[4] = 5. ; 00567 cov[5] = 6. ; 00568 vtx->setCovMatrix( cov ) ; 00569 for(int j=0;j<3;j++){ 00570 vtx->addParameter( j*.1 ) ; 00571 } 00572 00573 vertexVec->addElement ( vtx ) ; 00574 } 00575 00576 evt->addCollection( vertexVec, "SomeVertices" ) ; 00577 00578 // add some reconstructed particles 00579 LCCollectionVec* particleVec = new LCCollectionVec( LCIO::RECONSTRUCTEDPARTICLE ) ; 00580 // particleVec->parameters().setValues( "PIDAlgorithmTypeName" , algoNames ) ; 00581 // particleVec->parameters().setValues( "PIDAlgorithmTypeID" , algoIDs ) ; 00582 00583 if( particleVec ){ 00584 00585 PIDHandler recPIDHandler ( particleVec ) ; 00586 00587 StringVec pNames ; 00588 pNames.push_back( "param0" ); 00589 pNames.push_back( "param1" ); 00590 pNames.push_back( "param2" ); 00591 pNames.push_back( "param3" ); 00592 pNames.push_back( "param4" ); 00593 00594 IntVec aIDs(4) ; 00595 aIDs[0] = recPIDHandler.addAlgorithm( "recojobRunEventProcessor" , pNames ) ; 00596 aIDs[1] = recPIDHandler.addAlgorithm( "anotherAlgorithm" , pNames ) ; 00597 aIDs[2] = recPIDHandler.addAlgorithm( "andYetAnotherAlgorithm" , pNames ) ; 00598 aIDs[3] = recPIDHandler.addAlgorithm( "andEvenAFourthAlgorithm" , pNames ) ; 00599 00600 for(int i=0;i<nRecP;i++){ 00601 ReconstructedParticleImpl * part = new ReconstructedParticleImpl ; 00602 part->setType( 42 ) ; 00603 00604 float p[3] = { 1.1 , 2.2 , 3.3 } ; 00605 part->setMomentum( p ) ; 00606 part->setEnergy( i*101.101 ) ; 00607 00608 float covA[] = { 1.,2.,3.,4.,5.,6.,7.,8.,9.,10. } ; 00609 FloatVec cov(10) ; 00610 for(int j=0;j<10;j++) cov[j] = covA[j] ; 00611 00612 00613 part->setCovMatrix( cov) ; 00614 part->setMass( 0.511*i ) ; 00615 part->setCharge( -2./3. ) ; 00616 float x[3] = { 10.,20.,30. } ; 00617 part->setReferencePoint( x ) ; 00618 00619 //associate vertices 00620 part->setStartVertex( dynamic_cast<Vertex*>( vertexVec->getElementAt(i) ) ) ; 00621 VertexImpl* v = dynamic_cast<VertexImpl*>( vertexVec->getElementAt(i+1) ) ; 00622 //part->setEndVertex( v ) ; 00623 //associate particles to vertices 00624 v->setAssociatedParticle( dynamic_cast<ReconstructedParticle*>( part ) ) ; 00625 00626 // // add some particle ids 00627 // int nPID = 5 ; 00628 // for(int j=0;j<nPID;j++){ 00629 // ParticleIDImpl* pid = new ParticleIDImpl ; 00630 // pid->setLikelihood( (double) j / nPID ) ; 00631 // pid->setType( j ) ; 00632 // pid->setPDG( -11 ) ; 00633 // pid->setAlgorithmType( algoIDs[0] ) ; 00634 // for(int k=0;k<3;k++){ 00635 // pid->addParameter( k*.1 ) ; 00636 // } 00637 // part->addParticleID( pid ) ; 00638 // if( j == 2 ) 00639 // part->setParticleIDUsed( pid ) ; 00640 // } 00641 00642 // add some particle ids 00643 int nPID = aIDs.size() ; 00644 00645 for(int j=0;j<nPID;j++){ 00646 00647 // some parameters 00648 FloatVec fv( pNames.size() ) ; 00649 for( unsigned k=0 ; k < pNames.size() ; k++){ 00650 fv[k] = j*1000.+k*.1 ; 00651 } 00652 00653 recPIDHandler.setParticleID( part, 00654 j*j , // user type 00655 -11 , // PDG 00656 42.*j / nPID , // likelihood 00657 aIDs[j] , 00658 fv ) ; 00659 00660 if( j == 2 ) 00661 00662 recPIDHandler.setParticleIDUsed( part, aIDs[j] ) ; 00663 00664 } 00665 00666 part->setGoodnessOfPID( 0.7 ) ; 00667 00668 // some other particles 00669 if( i > 1 ){ 00670 ReconstructedParticle* p1 = 00671 dynamic_cast<ReconstructedParticle*> ( particleVec->getElementAt(i-1) ) ; 00672 ReconstructedParticle* p2 = 00673 dynamic_cast<ReconstructedParticle*> ( particleVec->getElementAt(i-2) ) ; 00674 part->addParticle( p1 ) ; 00675 part->addParticle( p2 ) ; 00676 } 00677 //a track 00678 int iTrk = (int) ( double (trkVec->size()) * rand() / RAND_MAX ) ; 00679 Track* trk = dynamic_cast<Track*> ( trkVec->getElementAt( iTrk ) ) ; 00680 part->addTrack( trk ) ; 00681 00682 // a cluster 00683 int iClu = (int) ( double (clusterVec->size()) * rand() / RAND_MAX ) ; 00684 Cluster* clu = dynamic_cast<Cluster*> ( clusterVec->getElementAt( iClu ) ) ; 00685 part->addCluster( clu ) ; 00686 00687 // // and finaly an MCParticle 00688 // LCCollection* mcVec = evt->getCollection( LCIO::MCPARTICLE ) ; 00689 // int iMCP = (int) ( double (mcVec->getNumberOfElements()) * rand() / RAND_MAX ) ; 00690 // MCParticle* mcp = dynamic_cast<MCParticle*>( mcVec->getElementAt( iMCP ) ) ; 00691 // part->addMCParticle( mcp , 0.5 ) ; 00692 00693 particleVec->addElement( part ) ; 00694 } 00695 } 00696 00697 evt->addCollection( particleVec, "ReconstructedParticle" ) ; 00698 00699 nEvent ++ ; 00700 00701 00702 00703 LCTOOLS::dumpEvent( evt ) ; 00704 00705 00706 lcWrt->writeEvent( evt ) ; 00707 }
void RunEventProcessor::modifyEvent | ( | LCEvent * | evt | ) | [inline] |
Definition at line 709 of file recjob.cc.
00709 { 00710 00711 // here we can modify existing objects that have been read from a stream: 00712 LCCollection* mcVec = evt->getCollection( LCIO::MCPARTICLE ) ; 00713 int NMCPART = mcVec->getNumberOfElements() ; 00714 for(int i=0 ; i< NMCPART ; i++ ){ 00715 // in order to have access to the set-methods we need to cast to the implementation 00716 // of MCParticle 00717 MCParticleImpl* part = dynamic_cast<MCParticleImpl*>( mcVec->getElementAt(i)) ; 00718 part->setPDG(1234) ; // <<<<< modifying persistent data 00719 } 00720 // or we could add sth. to existing collections 00721 MCParticleImpl* part = new MCParticleImpl ; 00722 part->setPDG( 1234 ) ; 00723 part->addParent( dynamic_cast<MCParticle*>( mcVec->getElementAt(0) )) ; 00724 mcVec->addElement( part ) ; // <<<< adding to collections 00725 00726 }
void RunEventProcessor::processRunHeader | ( | LCRunHeader * | run | ) | [inline] |
void RunEventProcessor::modifyRunHeader | ( | LCRunHeader * | run | ) | [inline] |
LCWriter* RunEventProcessor::lcWrt [protected] |
Definition at line 26 of file copyfix.cc.
Referenced by processEvent(), processRunHeader(), RunEventProcessor(), and ~RunEventProcessor().
int RunEventProcessor::nEvent [protected] |
LCWriter* RunEventProcessor::lcWrt [protected] |