9 #include "EVENT/LCIO.h"
43 using namespace lcio ;
45 static const int NRUN = 50 ;
50 static string FILEN =
"lcioperf.slcio" ;
66 _totalReadTime += (endTime - _startTime) / static_cast<double>( CLOCKS_PER_SEC ) ;
68 _startTime =
clock() ;
74 _startTime =
clock() ;
75 _lcReader->readStream(
this ) ;
78 std::cout <<
"Mean read time: " << _totalReadTime / _nEvents <<
" secs / event" <<
std::endl ;
83 double _totalReadTime {0.} ;
84 unsigned int _nEvents {0} ;
103 _totalReadTime += (endTime - _startTime) / static_cast<double>( CLOCKS_PER_SEC ) ;
105 _startTime =
clock() ;
111 _startTime =
clock() ;
112 _lcReader->readStream() ;
115 std::cout <<
"Mean read time: " << _totalReadTime / _nEvents <<
" secs / event" <<
std::endl ;
120 double _totalReadTime {0.} ;
121 unsigned int _nEvents {0} ;
122 LCReader *_lcReader {
nullptr} ;
130 int main(
int argc,
char** argv ){
132 double totalWritingTime = 0. ;
134 if( argc > 1 ) {
FILEN = argv[1] ; }
139 LCWriter* lcWrt = LCFactory::getInstance()->createLCWriter() ;
140 lcWrt->setCompressionLevel( 1 ) ;
141 lcWrt->open(
FILEN , LCIO::WRITE_NEW ) ;
144 for(
int rn=0;rn<
NRUN;rn++){
146 LCRunHeaderImpl*
runHdr =
new LCRunHeaderImpl ;
147 runHdr->setRunNumber( rn ) ;
149 string detName(
"D09TileHcal") ;
150 runHdr->setDetectorName( detName ) ;
153 description <<
" run: " << rn <<
" just for testing lcio - no physics !" ;
154 runHdr->setDescription( description.
str() ) ;
156 string ecalName(
"ECAL007") ;
157 runHdr->addActiveSubdetector( ecalName ) ;
159 string tpcName(
"TPC4711") ;
160 runHdr->addActiveSubdetector( tpcName ) ;
167 runHdr->parameters().setValue(
"SimulationProgram" ,
"simjob.cc" ) ;
172 runHdr->parameters().setValues(
"SomeIndices" , iv ) ;
174 lcWrt->writeRunHeader( runHdr ) ;
177 for(
int i=0;i<
NEVENT;i++){
180 LCEventImpl* evt =
new LCEventImpl() ;
183 evt->setRunNumber( rn ) ;
184 evt->setEventNumber( i ) ;
186 evt->setTimeStamp( now.timeStamp() ) ;
187 evt->setDetectorName( detName ) ;
189 evt->setWeight( 1.*
rand()/RAND_MAX ) ;
191 evt->parameters().setValue(
"Description",
" event can have it's own set of parameters" ) ;
192 evt->parameters().setValue(
"Thrust", (
float) 0.671 ) ;
196 fv.push_back( 2.2 ) ;
197 fv.push_back( 3.3 ) ;
198 evt->parameters().setValues(
"SomeNumbers" , fv ) ;
201 LCCollectionVec* mcVec =
new LCCollectionVec( LCIO::MCPARTICLE ) ;
209 MCParticleImpl* mom =
new MCParticleImpl ;
211 float p0[3] = { 0. , 0. , 1000. } ;
212 mom->setMomentum( p0 ) ;
213 mom->setMass( 3.01 ) ;
218 MCParticleImpl* mcp =
new MCParticleImpl ;
220 mcp->setPDG( 1000 * (j+1) ) ;
221 float p[3] = { float(j*1.) , float(4./1024.) , float(8./1024.) } ;
222 mcp->setMomentum( p ) ;
223 mcp->setMass( .135 ) ;
226 for(
int k=0;k<3;k++){
227 MCParticleImpl* d1 =
new MCParticleImpl ;
229 d1->setPDG( 1000 * (j+1) + 100 * (k+1) ) ;
230 float pd1[3] = { float(k*1.) , float(4.1) , float(8.1) } ;
231 d1->setMomentum( pd1 ) ;
232 d1->setMass( .135 ) ;
234 for(
int l=0;l<2;l++){
235 MCParticleImpl* d2 =
new MCParticleImpl ;
237 d2->setPDG( 1000 * (j+1) + 100 * (k+1) + 10 * (l+1) ) ;
238 float pd2[3] = { float(l*1.) , float(0.41) , float(4.1) } ;
239 d2->setMomentum( pd2 ) ;
240 d2->setMass( .135 ) ;
242 double ep[3] = { 1.111111 , 2.2222222, 3.3333333 } ;
243 d2->setEndpoint( ep ) ;
245 d2->setCreatedInSimulation(
true) ;
246 d2->setBackscatter(
true) ;
247 d2->setDecayedInTracker(
true) ;
248 d2->setDecayedInCalorimeter(
false);
249 d2->setHasLeftDetector(
false) ;
250 d2->setStopped(
true) ;
253 mcVec->push_back( d2 ) ;
258 d1->addParent( mcp );
259 mcVec->push_back( d1 ) ;
262 mcp->addParent( mom );
263 mcVec->push_back( mcp ) ;
265 mcVec->push_back( mom ) ;
268 LCCollectionVec* calVec =
new LCCollectionVec( LCIO::SIMCALORIMETERHIT ) ;
281 std::string cellIDEncoding(
"M:3,S-1:3,I:9,J:9,K-1:6") ;
285 CellIDEncoder<SimCalorimeterHitImpl> b( cellIDEncoding , calVec ) ;
287 for(
int j=0;j<
NHITS;j++){
289 SimCalorimeterHitImpl* hit =
new SimCalorimeterHitImpl ;
291 hit->setEnergy( 3.1415 *
rand()/RAND_MAX ) ;
293 float pos[3] = { float(1.1*
rand()/RAND_MAX) , float(2.2*
rand()/RAND_MAX) , float(3.3*
rand()/RAND_MAX) } ;
297 b[
"S-1"] = (j+2) % 8 ;
299 b[
"J"] = (j+128) % 512 ;
300 b[
"K-1"] = (j+32) % 64 ;
307 hit->setPosition( pos ) ;
309 calVec->push_back( hit ) ;
312 double rnd = .99999*
rand()/RAND_MAX ;
313 int mcIndx =
static_cast<int>( NMCPART * rnd ) ;
317 hit->addMCParticleContribution( dynamic_cast<MCParticle*>(mcVec->getElementAt( mcIndx )) ,
318 0.314159, 0.1155, 42., 1, pos ) ;
324 for(
int j=0;j<
NHITS;j++){
325 SimCalorimeterHitImpl* existingHit
326 =
dynamic_cast<SimCalorimeterHitImpl*
>( calVec->getElementAt(j) ) ;
328 existingHit->addMCParticleContribution( dynamic_cast<MCParticle*>
329 (mcVec->getElementAt(0)),
337 LCCollectionVec* trkVec =
new LCCollectionVec( LCIO::SIMTRACKERHIT ) ;
338 LCCollectionVec* extFVec =
new LCCollectionVec( LCIO::LCFLOATVEC ) ;
339 LCCollectionVec* extIVec =
new LCCollectionVec( LCIO::LCINTVEC ) ;
346 LCTypedVector<MCParticle> mcpTV( mcVec ) ;
348 CellIDEncoder<SimTrackerHitImpl> cd(
"i:8,j:8,k:8" ,trkVec ) ;
350 for(
int j=0;j<
NHITS;j++){
352 SimTrackerHitImpl* hit =
new SimTrackerHitImpl ;
358 cd.setCellID( hit ) ;
360 LCFloatVec* extF =
new LCFloatVec ;
361 LCIntVec* extI =
new LCIntVec ;
364 hit->setEDep( 30e-9 ) ;
366 double pos[3] = { 1.1*
rand()/RAND_MAX , 2.2*
rand()/RAND_MAX , 3.3*
rand()/RAND_MAX } ;
368 hit->setPosition( pos ) ;
371 float rnd = .99999*
rand()/RAND_MAX ;
372 int mcIndx =
static_cast<int>( NMCPART * rnd ) ;
376 hit->setMCParticle( mcpTV[ mcIndx ] ) ;
378 hit->setMomentum( 1. , 2. , 3. ) ;
379 hit->setPathLength( .042 ) ;
382 extF->push_back( 3.14159 ) ;
383 for(
int k=0;k<3;k++) extF->push_back( pos[k] * 0.1 ) ;
385 extI->push_back( 123456789 ) ;
386 extI->push_back( mcIndx ) ;
389 trkVec->push_back( hit ) ;
390 extFVec->push_back( extF ) ;
391 extIVec->push_back( extI ) ;
396 evt->addCollection( mcVec ,
"MCParticle" ) ;
401 evt->addCollection( calVec , ecalName ) ;
402 evt->addCollection( trkVec , tpcName ) ;
403 evt->addCollection( extFVec , tpcName+
"UserFloatExtension" ) ;
404 evt->addCollection( extIVec , tpcName+
"UserIntExtension" ) ;
408 if( rn == 1 && i == 0 ) {
409 LCCollectionVec* addExtVec =
new LCCollectionVec( LCIO::LCFLOATVEC ) ;
410 LCFloatVec* addExt =
new LCFloatVec ;
411 addExt->push_back( 1. );
412 addExt->push_back( 2. );
413 addExt->push_back( 3. );
414 addExt->push_back( 4. );
415 addExtVec->push_back( addExt ) ;
416 evt->addCollection( addExtVec ,
"AdditionalExtension" ) ;
419 LCCollectionVec* mcSubVec =
new LCCollectionVec( LCIO::MCPARTICLE ) ;
420 mcSubVec->setSubset(
true) ;
422 for(
int j=0;j< mcVec->getNumberOfElements() ; j++ ){
424 MCParticle* p =
dynamic_cast< MCParticle*
>( mcVec->getElementAt(j) ) ;
425 if( p->getDaughters().size() == 0 )
426 mcSubVec->addElement( p ) ;
428 evt->addCollection( mcSubVec ,
"FinalMCParticles" ) ;
435 #define WRITE_TRACKERRAWDATA 1
436 #ifdef WRITE_TRACKERRAWDATA
438 LCCollectionVec* tpcRawVec =
new LCCollectionVec( LCIO::TRACKERRAWDATA ) ;
440 for(
int j=0;j<
NHITS;j++){
442 TrackerRawDataImpl* tpcRaw =
new TrackerRawDataImpl ;
444 tpcRaw->setCellID0( j ) ;
445 tpcRaw->setTime( -j ) ;
450 adcValues.push_back( 43 ) ;
451 adcValues.push_back( 44 ) ;
452 adcValues.push_back( 45 ) ;
453 tpcRaw->setADCValues( adcValues ) ;
455 tpcRaw->adcValues().push_back( 42 ) ;
456 tpcRaw->adcValues().push_back( 43 ) ;
457 tpcRaw->adcValues().push_back( 44 ) ;
458 tpcRaw->adcValues().push_back( 45 ) ;
460 tpcRawVec->addElement( tpcRaw ) ;
462 evt->addCollection( tpcRawVec ,
"TrackerRawDataExample" ) ;
465 LCRelationNavigator relNav( LCIO::TRACKERRAWDATA, LCIO::SIMTRACKERHIT ) ;
467 for(
int j=0;j<
NHITS;j++){
468 relNav.addRelation( tpcRawVec->getElementAt(j) , trkVec->getElementAt(j) , 0.42 ) ;
475 evt->addCollection( relNav.createLCCollection() ,
"TPCRawFADCMCTruth" ) ;
480 LCCollectionVec* tpcCorrectedVec =
new LCCollectionVec( LCIO::TRACKERDATA ) ;
482 for(
int j=0;j<
NHITS;j++){
484 TrackerDataImpl* tpcCorrected =
new TrackerDataImpl ;
486 tpcCorrected->setCellID0( j ) ;
487 tpcCorrected->setTime( -j ) ;
489 tpcCorrected->chargeValues().push_back( 42.12345 ) ;
490 tpcCorrected->chargeValues().push_back( 43.09876 ) ;
491 tpcCorrected->chargeValues().push_back( 44.12345 ) ;
492 tpcCorrected->chargeValues().push_back( 45.09876 ) ;
494 tpcCorrectedVec->addElement( tpcCorrected ) ;
496 evt->addCollection( tpcCorrectedVec ,
"TrackerDataExample" ) ;
500 LCCollectionVec* tpcPulseVec =
new LCCollectionVec( LCIO::TRACKERPULSE ) ;
504 qualityBits.push_back(1) ;
510 tpcPulseVec->parameters().setValues(
"TrackerPulseQualityNames", bitNames );
511 tpcPulseVec->parameters().setValues(
"TrackerPulseQualityValues", qualityBits );
513 for(
int j=0;j<
NHITS;j++){
515 TrackerPulseImpl* tpcPulse =
new TrackerPulseImpl ;
517 tpcPulse->setCellID0( j ) ;
518 tpcPulse->setTime( 3.1415 + 0.1 * j ) ;
519 tpcPulse->setCharge( 3.1415 - 0.1 * j ) ;
522 tpcPulse->setQualityBit( qualityBits[0] ) ;
525 tpcPulse->setQualityBit( qualityBits[1] ) ;
528 dynamic_cast<TrackerData*
> ( tpcCorrectedVec->getElementAt(j) ) ;
529 tpcPulse->setTrackerData( corr ) ;
532 tpcPulseVec->addElement( tpcPulse ) ;
534 evt->addCollection( tpcPulseVec ,
"TrackerPulseExample" ) ;
537 #endif // WRITE_TRACKERRAWDATA
539 #define WRITE_VTXRAWHITS 1
540 #ifdef WRITE_VTXRAWHITS
543 LCCollectionVec* vtxRawVec =
new LCCollectionVec( LCIO::TRACKERPULSE ) ;
545 for(
int j=0;j<
NHITS;j++){
547 TrackerPulseImpl* vtxRaw =
new TrackerPulseImpl ;
549 vtxRaw->setCellID0( 0xBebaFeca ) ;
550 vtxRaw->setCellID1( 0xCafeBabe ) ;
551 vtxRaw->setTime( j ) ;
552 vtxRaw->setCharge( 42 + j ) ;
554 vtxRawVec->addElement( vtxRaw ) ;
556 evt->addCollection( vtxRawVec ,
"SiliconRawHitExample" ) ;
559 #endif // WRITE_VTXRAWHITS
565 lcWrt->writeEvent( evt ) ;
568 totalWritingTime += (end - start) / static_cast<double>( CLOCKS_PER_SEC ) ;
586 std::cout <<
"Mean writing time: " << totalWritingTime / (NRUN*
NEVENT) <<
" secs / event" << std::endl ;
590 LCReader*
lcReader = LCFactory::getInstance()->createLCReader() ;
591 lcReader->open(
FILEN ) ;
593 lcReader->registerLCEventListener( &listener ) ;
617 }
catch( Exception& ex){
619 cout <<
" an excpetion occured: " <<
endl ;
std::vector< std::string > StringVec
Vector of strings.
void open(const std::string &filename)
Opens a file for reading (read-only).
std::vector< float > FloatVec
Vector of floats.
static constexpr int directAccess
Bit for direct access.
int main(int argc, char **argv)
Simple program that opens existing LCIO files and appends the records needed for direct access - if t...
Implementation of a LCReader for parallel processing use.
std::vector< int > IntVec
Vector of ints.
LCReaderListener class Interface for MT::LCReader::readStream() callbacks.
BitSet32 make_bitset32(int bit0)
Convenient helper that creates a BitSet32 with bit0 set.
std::vector< short > ShortVec
Vector of shorts.
static constexpr int lazyUnpack
Bit for lazy unpacking of event records.