8 #include "EVENT/LCIO.h"
31 #define M_PI 3.14159265358979323846
37 using namespace lcio ;
68 lcWrt = LCFactory::getInstance()->createLCWriter() ;
71 lcWrt->setCompressionLevel( 9 ) ;
72 lcWrt->open(
OUTFILEN , LCIO::WRITE_NEW ) ;
75 catch(IOException& e){
76 cout <<
"[RunEventProcessor()] Can't open file for writing - "
89 <<
" added collection: 'SomeClusters' and 'SomeTracks'"
90 <<
" to " << nEvent <<
" events"
91 <<
" and added one extra MCParticle to each event."
120 std::string tpcHitName(
"TrackerRawDataExample" ) ;
125 LCCollection* tpcHits = evt->getCollection( tpcHitName) ;
128 LCCollectionVec* trkhitVec =
new LCCollectionVec( LCIO::TRACKERHIT ) ;
129 int nTrackerRawDatas = tpcHits->getNumberOfElements() ;
131 for(
int j=0;j<nTrackerRawDatas;j++){
132 TrackerHitImpl* trkHit =
new TrackerHitImpl ;
134 TrackerRawData* tpcRawHit =
dynamic_cast<TrackerRawData*
> ( tpcHits->getElementAt(j) ) ;
136 trkHit->setTime( tpcRawHit->getTime() ) ;
138 int cellID = tpcRawHit->getCellID0() ;
139 double pos[3] = { double (cellID & 0xff) , double ( (cellID & 0xff00)>>8 ), double( (cellID & 0xff0000)>>16 ) } ;
140 trkHit->setPosition( pos ) ;
142 trkHit->rawHits().push_back( tpcRawHit ) ;
143 trkHit->rawHits().push_back( tpcRawHit ) ;
152 trkHit->setCovMatrix( cov ) ;
154 trkhitVec->addElement( trkHit ) ;
164 typeValues.push_back( 1 ) ;
165 trkhitVec->parameters().setValues(
"TrackerHitTypeNames" , typeNames ) ;
166 trkhitVec->parameters().setValues(
"TrackerHitTypeValues" , typeValues ) ;
169 evt->addCollection( trkhitVec ,
"TrackerHits") ;
172 LCCollectionVec* trkVec =
new LCCollectionVec( LCIO::TRACK ) ;
183 for(
int i=0; i < nTrk ; i ++ ){
185 TrackImpl* trk =
new TrackImpl ;
186 trk->setTypeBit( 7 ) ;
187 trk->setOmega( (i+1)*1.1 ) ;
188 trk->setTanLambda( (i+1)*
M_PI / 10. ) ;
189 trk->setPhi( (i+1)*
M_PI / 5. ) ;
191 trk->setZ0( (i+1)*10. ) ;
192 trk->setChi2( 1.01 ) ;
195 trk->setRadiusOfInnermostHit( 3.141592 ) ;
198 const int NTRACKER = 3 ;
199 const int VTXINDEX = 0 ;
200 const int SITINDEX = 1 ;
201 const int TPCINDEX = 2 ;
203 trackerNames.
resize( NTRACKER ) ;
204 trackerNames[VTXINDEX] =
"VTX" ;
205 trackerNames[SITINDEX] =
"SIT" ;
206 trackerNames[TPCINDEX] =
"TPC" ;
208 trkVec->parameters().setValues(
"TrackSubdetectorNames" , trackerNames ) ;
210 trk->subdetectorHitNumbers().
resize( NTRACKER ) ;
211 trk->subdetectorHitNumbers()[ VTXINDEX ] = 12 ;
212 trk->subdetectorHitNumbers()[ SITINDEX ] = 24 ;
213 trk->subdetectorHitNumbers()[ TPCINDEX ] = 36 ;
215 trk->setdEdx( 3.14159 ) ;
216 trk->setdEdxError( 42. ) ;
217 float cov[15] = { 1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15. } ;
218 trk->setCovMatrix( cov ) ;
219 float ref[3] = { 12. ,123456789. , .0987654321 } ;
220 trk->setReferencePoint( ref ) ;
223 int iHit1 = (int) (
double (trkhitVec->size()) *
rand() / RAND_MAX ) ;
224 int iHit2 = (int) (
double (trkhitVec->size()) *
rand() / RAND_MAX ) ;
225 int iHit3 = (int) (
double (trkhitVec->size()) *
rand() / RAND_MAX ) ;
227 trk->addHit( dynamic_cast<TrackerHit*>( (*trkhitVec)[iHit1] ) ) ;
228 trk->addHit( dynamic_cast<TrackerHit*>( (*trkhitVec)[iHit2] ) ) ;
229 trk->addHit( dynamic_cast<TrackerHit*>( (*trkhitVec)[iHit3] ) ) ;
233 if( trkVec->size() > 1 ){
234 trk->addTrack( dynamic_cast<TrackImpl*> ( (*trkVec)[ trkVec->size() - 1 ] ) ) ;
235 trk->addTrack( dynamic_cast<TrackImpl*> ( (*trkVec)[ trkVec->size() - 2 ] ) ) ;
238 trkVec->addElement( trk ) ;
242 evt->addCollection( trkVec ,
"SomeTracks" ) ;
248 LCCollection* simcalHits = evt->getCollection( simcalHitName ) ;
254 LCCollectionVec* clusterVec =
new LCCollectionVec( LCIO::CLUSTER ) ;
255 LCCollectionVec* calHits =
new LCCollectionVec( LCIO::CALORIMETERHIT ) ;
260 LCCollectionVec* scRel =
new LCCollectionVec(LCIO::LCRELATION ) ;
261 scRel->parameters().setValue(
"RelationFromType" , LCIO::CALORIMETERHIT ) ;
262 scRel->parameters().setValue(
"RelationToType" , LCIO::SIMCALORIMETERHIT ) ;
264 int nSimHits = simcalHits->getNumberOfElements() ;
265 for(
int j=0;j<nSimHits;j++){
267 CalorimeterHitImpl* calHit =
new CalorimeterHitImpl ;
268 SimCalorimeterHit* simcalHit =
dynamic_cast<SimCalorimeterHit*
> ( simcalHits->getElementAt(j) ) ;
272 calHit->setEnergy( simcalHit->getEnergy() ) ;
273 calHit->setCellID0( simcalHit->getCellID0() ) ;
274 calHit->setPosition( simcalHit->getPosition()) ;
278 scRel->addElement(
new LCRelationImpl( calHit , simcalHit , 0.5 ) ) ;
279 scRel->addElement(
new LCRelationImpl( calHit , simcalHit , 0.5 ) ) ;
280 scRel->addElement(
new LCRelationImpl( calHit , simcalHit , 0.5 ) ) ;
281 calHits->addElement( calHit ) ;
289 evt->addCollection( calHits ,
"CalorimeterHits") ;
297 evt->addCollection( scRel ,
"CalorimeterHitsSimRel" ) ;
303 if( evt->getEventNumber() == 0 && evt->getRunNumber() == 0 ) {
308 LCRelationNavigator rel( scRel ) ;
310 std::cout <<
"Relation example for first event: "
311 <<
" [" << rel.getFromType() <<
" - " << rel.getToType() <<
"] "
314 int nCalHits = calHits->getNumberOfElements() ;
315 for(
int j=0; j < nCalHits ; j++){
316 CalorimeterHit* calHit =
dynamic_cast<CalorimeterHit*
>( calHits->getElementAt(j) ) ;
318 std::cout <<
" relations for object " <<
dec << calHit->id()
321 const LCObjectVec& simHits = rel.getRelatedToObjects( calHit ) ;
322 const FloatVec& weights = rel.getRelatedToWeights( calHit ) ;
324 for(
int k=0,nSH = simHits.size(); k<nSH;k++){
326 std::cout <<
" [" << simHits[k]->id() <<
"] ("
327 << weights[k] <<
") " ;
337 LCCollectionVec* calVec =
new LCCollectionVec( LCIO::LCGENERICOBJECT ) ;
338 for(
int j=0;j<nCalHits;j++){
340 CalorimeterHit* calHit =
dynamic_cast<CalorimeterHit*
>( calHits->getElementAt(j) ) ;
344 calVec->addElement( cCon ) ;
347 evt->addCollection( calVec ,
"Calibration" ) ;
351 LCCollectionVec* emtpyCol =
new LCCollectionVec( LCIO::LCGENERICOBJECT ) ;
352 evt->addCollection( emtpyCol ,
"EmptyLCGenericObject" ) ;
365 shapeParams.push_back(
"Shape_axis_x") ;
366 shapeParams.push_back(
"Shape_axis_y") ;
367 shapeParams.push_back(
"Shape_axis_z") ;
368 shapeParams.push_back(
"Shape_quality") ;
370 clusterVec->parameters().setValues(
"ClusterShapeParameters" , shapeParams ) ;
395 int nHits = calHits->getNumberOfElements() ;
396 int nCluster = nHits / 10 ;
400 PIDHandler cluPidHandler( clusterVec ) ;
405 pNames.push_back(
"param2" );
408 algoIDs[0] = cluPidHandler.addAlgorithm(
"recojobRunEventProcessor" , pNames ) ;
409 algoIDs[1] = cluPidHandler.addAlgorithm(
"anotherAlgorithm" , pNames ) ;
410 algoIDs[2] = cluPidHandler.addAlgorithm(
"andYetAnotherAlgorithm" , pNames ) ;
412 for(
int i=0; i < nCluster ; i ++ ){
414 ClusterImpl* cluster =
new ClusterImpl ;
417 cluster->setTypeBit( 1 ) ;
418 cluster->setTypeBit( 7 ) ;
419 cluster->setTypeBit( 11 ) ;
421 cluster->setEnergy( (i+1)*1.1 ) ;
422 float pos[3] = { 12. ,123456789. , .0987654321 } ;
423 cluster->setPosition( pos ) ;
424 float errpos[6] = { 1.,2.,3.,4.,5.,6.} ;
425 cluster->setPositionError( errpos ) ;
426 cluster->setITheta( (i+1)*
M_PI / 10. ) ;
427 cluster->setIPhi( (i+1)*
M_PI / 5. ) ;
428 float errdir[6] = { 1.,2.,3.} ;
429 cluster->setDirectionError( errdir ) ;
432 float shapeArray[6] = { 1.,2.,3.,3.,2.,1.} ;
435 cluster->setShape( shape ) ;
452 int nPID = algoIDs.size() ;
454 for(
int j=0;j<nPID;j++){
459 for(
unsigned k=0 ; k < pNames.size() ; k++){
460 fv[k] = j*1000.+k*.1 ;
463 cluPidHandler.setParticleID( cluster,
474 const int NCALORIMETER = 2 ;
475 const int ECALINDEX = 0 ;
476 const int HCALINDEX = 1 ;
478 detNames.
resize( NCALORIMETER ) ;
479 detNames[ECALINDEX] =
"Ecal" ;
480 detNames[HCALINDEX] =
"Hcal" ;
481 clusterVec->parameters().setValues(
"ClusterSubdetectorNames" , detNames ) ;
484 cluster->subdetectorEnergies().
resize( NCALORIMETER ) ;
485 cluster->subdetectorEnergies()[ ECALINDEX ] = 42.42 ;
486 cluster->subdetectorEnergies()[ HCALINDEX ] = 24.24 ;
489 int iHit1 = (int) (
double (calHits->size()) *
rand() / RAND_MAX ) ;
490 int iHit2 = (int) (
double (calHits->size()) *
rand() / RAND_MAX ) ;
491 int iHit3 = (int) (
double (calHits->size()) *
rand() / RAND_MAX ) ;
493 cluster->addHit( dynamic_cast<CalorimeterHit*>( (*calHits)[iHit1] ) , 1.0 ) ;
494 cluster->addHit( dynamic_cast<CalorimeterHit*>( (*calHits)[iHit2] ) , 2.0 ) ;
495 cluster->addHit( dynamic_cast<CalorimeterHit*>( (*calHits)[iHit3] ) , 3.0 ) ;
498 if( clusterVec->size() > 1 ){
499 cluster->addCluster( dynamic_cast<ClusterImpl*>
500 ( (*clusterVec)[ clusterVec->size() - 1 ] ) ) ;
501 cluster->addCluster( dynamic_cast<ClusterImpl*>
502 ( (*clusterVec)[ clusterVec->size() - 2 ] ) ) ;
506 clusterVec->addElement( cluster ) ;
510 evt->addCollection( clusterVec ,
"SomeClusters" ) ;
513 LCCollectionVec* vertexVec =
new LCCollectionVec( LCIO::VERTEX ) ;
518 for(
int i=0; i < (
nRecP+1); i++){
519 VertexImpl* vtx =
new VertexImpl ;
521 vtx->setPrimary(
true);
523 vtx->setPrimary(
false);
538 case 0: vtx->setAlgorithmType(
"ZvTop" );
break;
539 case 1: vtx->setAlgorithmType(
"ZvKin" );
break;
540 case 2: vtx->setAlgorithmType(
"42" );
break;
541 case 3: vtx->setAlgorithmType(
"SimAnnealing" );
break;
542 case 5: vtx->setAlgorithmType(
"_Test" );
break;
546 vtx->setChi2(1+i*.01);
547 vtx->setProbability(0.0032+i*.01);
548 vtx->setPosition(0.3453+i*.01,.45345354+i*.01,2.345354+i*.01);
557 vtx->setCovMatrix( cov ) ;
558 for(
int j=0;j<3;j++){
559 vtx->addParameter( j*.1 ) ;
562 vertexVec->addElement ( vtx ) ;
565 evt->addCollection( vertexVec,
"SomeVertices" ) ;
568 LCCollectionVec* particleVec =
new LCCollectionVec( LCIO::RECONSTRUCTEDPARTICLE ) ;
574 PIDHandler recPIDHandler ( particleVec ) ;
579 pNames.push_back(
"param2" );
580 pNames.push_back(
"param3" );
581 pNames.push_back(
"param4" );
584 aIDs[0] = recPIDHandler.addAlgorithm(
"recojobRunEventProcessor" , pNames ) ;
585 aIDs[1] = recPIDHandler.addAlgorithm(
"anotherAlgorithm" , pNames ) ;
586 aIDs[2] = recPIDHandler.addAlgorithm(
"andYetAnotherAlgorithm" , pNames ) ;
587 aIDs[3] = recPIDHandler.addAlgorithm(
"andEvenAFourthAlgorithm" , pNames ) ;
589 for(
int i=0;i<
nRecP;i++){
590 ReconstructedParticleImpl * part =
new ReconstructedParticleImpl ;
591 part->setType( 42 ) ;
593 float p[3] = { 1.1 , 2.2 , 3.3 } ;
594 part->setMomentum( p ) ;
595 part->setEnergy( i*101.101 ) ;
597 float covA[] = { 1.,2.,3.,4.,5.,6.,7.,8.,9.,10. } ;
599 for(
int j=0;j<10;j++) cov[j] = covA[j] ;
602 part->setCovMatrix( cov) ;
603 part->setMass( 0.511*i ) ;
604 part->setCharge( -2./3. ) ;
605 float x[3] = { 10.,20.,30. } ;
606 part->setReferencePoint( x ) ;
609 part->setStartVertex( dynamic_cast<Vertex*>( vertexVec->getElementAt(i) ) ) ;
610 VertexImpl* v =
dynamic_cast<VertexImpl*
>( vertexVec->getElementAt(i+1) ) ;
613 v->setAssociatedParticle( dynamic_cast<ReconstructedParticle*>( part ) ) ;
632 int nPID = aIDs.size() ;
634 for(
int j=0;j<nPID;j++){
638 for(
unsigned k=0 ; k < pNames.size() ; k++){
639 fv[k] = j*1000.+k*.1 ;
642 recPIDHandler.setParticleID( part,
649 recPIDHandler.setParticleID( part,
658 recPIDHandler.setParticleIDUsed( part, aIDs[j] ) ;
662 part->setGoodnessOfPID( 0.7 ) ;
670 part->addParticle( p1 ) ;
671 part->addParticle( p2 ) ;
674 int iTrk = (int) (
double (trkVec->size()) *
rand() / RAND_MAX ) ;
675 Track* trk =
dynamic_cast<Track*
> ( trkVec->getElementAt( iTrk ) ) ;
676 part->addTrack( trk ) ;
679 int iClu = (int) (
double (clusterVec->size()) *
rand() / RAND_MAX ) ;
680 Cluster* clu =
dynamic_cast<Cluster*
> ( clusterVec->getElementAt( iClu ) ) ;
681 part->addCluster( clu ) ;
689 particleVec->addElement( part ) ;
693 evt->addCollection( particleVec,
"ReconstructedParticle" ) ;
702 lcWrt->writeEvent( evt ) ;
708 LCCollection* mcVec = evt->getCollection( LCIO::MCPARTICLE ) ;
709 int NMCPART = mcVec->getNumberOfElements() ;
710 for(
int i=0 ; i<
NMCPART ; i++ ){
713 MCParticleImpl* part =
dynamic_cast<MCParticleImpl*
>( mcVec->getElementAt(i)) ;
717 MCParticleImpl* part =
new MCParticleImpl ;
718 part->setPDG( 1234 ) ;
719 part->addParent( dynamic_cast<MCParticle*>( mcVec->getElementAt(0) )) ;
720 mcVec->addElement( part ) ;
728 lcWrt->writeRunHeader( run ) ;
738 int main(
int argc,
char** argv ){
743 LCReader*
lcReader = LCFactory::getInstance()->createLCReader() ;
747 if( argc > 1 ) {
FILEN = argv[1] ; }
748 if( argc > 2 ) {
OUTFILEN = argv[2] ; }
750 lcReader->open(
FILEN ) ;
764 lcReader->registerLCRunListener( &evtProc ) ;
765 lcReader->registerLCEventListener( &evtProc ) ;
767 lcReader->readStream() ;
std::vector< std::string > StringVec
Vector of strings.
std::vector< LCObject * > LCObjectVec
Vector of (pointers to) LCObjects.
std::vector< float > FloatVec
Vector of floats.
Little tool that copies LCIO files on an event by event and run by run basis, thus fixing files that ...
void processEvent(LCEvent *evt)
int main(int argc, char **argv)
Simple program that opens existing LCIO files and appends the records needed for direct access - if t...
void processRunHeader(LCRunHeader *run)
Example for a simple calibration class based on the LCFixedObject template.
std::vector< int > IntVec
Vector of ints.
T back_inserter(T...args)
static std::string OUTFILEN
void modifyRunHeader(LCRunHeader *)
BitSet32 make_bitset32(int bit0)
Convenient helper that creates a BitSet32 with bit0 set.
void dumpEvent(EVENT::LCEvent *event)
void modifyEvent(LCEvent *evt)