4 #include "EVENT/LCIO.h"
38 using namespace lcio ;
40 static const int NRUN = 10 ;
45 static string FILEN =
"simjob.slcio" ;
53 int main(
int argc,
char** argv ){
59 for(
int rn=0;rn<
NRUN;rn++){
62 LCWriter* lcWrt = LCFactory::getInstance()->createLCWriter() ;
66 if( argc > 1 ) {
FILEN = argv[1] ; }
72 lcWrt->setCompressionLevel( 0 ) ;
73 lcWrt->open(
FILEN , LCIO::WRITE_NEW ) ;
76 lcWrt->setCompressionLevel( 9 ) ;
77 lcWrt->open(
FILEN , LCIO::WRITE_APPEND ) ;
85 LCRunHeaderImpl*
runHdr =
new LCRunHeaderImpl ;
86 runHdr->setRunNumber( rn ) ;
88 string detName(
"D09TileHcal") ;
89 runHdr->setDetectorName( detName ) ;
92 description <<
" run: " << rn <<
" just for testing lcio - no physics !" ;
93 runHdr->setDescription( description.
str() ) ;
95 string ecalName(
"ECAL007") ;
96 runHdr->addActiveSubdetector( ecalName ) ;
98 string tpcName(
"TPC4711") ;
99 runHdr->addActiveSubdetector( tpcName ) ;
106 runHdr->parameters().setValue(
"SimulationProgram" ,
"simjob.cc" ) ;
111 runHdr->parameters().setValues(
"SomeIndices" , iv ) ;
113 lcWrt->writeRunHeader( runHdr ) ;
116 for(
int i=0;i<
NEVENT;i++){
119 LCEventImpl* evt =
new LCEventImpl() ;
122 evt->setRunNumber( rn ) ;
123 evt->setEventNumber( i ) ;
125 evt->setTimeStamp( now.timeStamp() ) ;
126 evt->setDetectorName( detName ) ;
128 evt->setWeight( 1.*
rand()/RAND_MAX ) ;
130 evt->parameters().setValue(
"Description",
" event can have it's own set of parameters" ) ;
131 evt->parameters().setValue(
"Thrust", (
float) 0.671 ) ;
135 fv.push_back( 2.2 ) ;
136 fv.push_back( 3.3 ) ;
137 evt->parameters().setValues(
"SomeNumbers" , fv ) ;
140 dv.
push_back( 1.111111111111111111111111111111111111111111111111 ) ;
141 dv.push_back( 2.222222222222222222222222222222222222222222222222 ) ;
142 dv.push_back( 3.333333333333333333333333333333333333333333333333 ) ;
143 evt->parameters().setValues(
"SomeDoubleNumbers" , dv ) ;
147 LCCollectionVec* mcVec =
new LCCollectionVec( LCIO::MCPARTICLE ) ;
155 MCParticleImpl* mom =
new MCParticleImpl ;
157 float p0[3] = { 0. , 0. , 1000. } ;
158 mom->setMomentum( p0 ) ;
159 mom->setMass( 3.01 ) ;
164 MCParticleImpl* mcp =
new MCParticleImpl ;
166 mcp->setPDG( 1000 * (j+1) ) ;
167 float p[3] = { float(j*1.) , float(4./1024.) , float(8./1024.) } ;
168 mcp->setMomentum( p ) ;
169 mcp->setMass( .135 ) ;
172 for(
int k=0;k<3;k++){
173 MCParticleImpl* d1 =
new MCParticleImpl ;
175 d1->setPDG( 1000 * (j+1) + 100 * (k+1) ) ;
176 float pd1[3] = { float(k*1.) , float(4.1) , float(8.1) } ;
177 d1->setMomentum( pd1 ) ;
178 d1->setMass( .135 ) ;
180 for(
int l=0;l<2;l++){
181 MCParticleImpl* d2 =
new MCParticleImpl ;
183 d2->setPDG( 1000 * (j+1) + 100 * (k+1) + 10 * (l+1) ) ;
184 float pd2[3] = { float(l*1.) , float(0.41) , float(4.1) } ;
185 d2->setMomentum( pd2 ) ;
186 d2->setMass( .135 ) ;
188 double ep[3] = { 1.111111 , 2.2222222, 3.3333333 } ;
189 d2->setEndpoint( ep ) ;
191 d2->setCreatedInSimulation(
true) ;
192 d2->setBackscatter(
true) ;
193 d2->setDecayedInTracker(
true) ;
194 d2->setDecayedInCalorimeter(
false);
195 d2->setHasLeftDetector(
false) ;
196 d2->setStopped(
true) ;
199 mcVec->push_back( d2 ) ;
204 d1->addParent( mcp );
205 mcVec->push_back( d1 ) ;
208 mcp->addParent( mom );
209 mcVec->push_back( mcp ) ;
211 mcVec->push_back( mom ) ;
214 LCCollectionVec* calVec =
new LCCollectionVec( LCIO::SIMCALORIMETERHIT ) ;
227 std::string cellIDEncoding(
"M:3,S-1:3,I:9,J:9,K-1:6") ;
231 CellIDEncoder<SimCalorimeterHitImpl> b( cellIDEncoding , calVec ) ;
233 for(
int j=0;j<
NHITS;j++){
235 SimCalorimeterHitImpl* hit =
new SimCalorimeterHitImpl ;
237 hit->setEnergy( 3.1415 *
rand()/RAND_MAX ) ;
239 float pos[3] = { float(1.1*
rand()/RAND_MAX) , float(2.2*
rand()/RAND_MAX) , float(3.3*
rand()/RAND_MAX) } ;
243 b[
"S-1"] = (j+2) % 8 ;
245 b[
"J"] = (j+128) % 512 ;
246 b[
"K-1"] = (j+32) % 64 ;
253 hit->setPosition( pos ) ;
255 calVec->push_back( hit ) ;
258 double rnd = .99999*
rand()/RAND_MAX ;
259 int mcIndx =
static_cast<int>( NMCPART * rnd ) ;
263 hit->addMCParticleContribution( dynamic_cast<MCParticle*>(mcVec->getElementAt( mcIndx )) ,
264 0.314159, 0.1155, 42., 1, pos ) ;
270 for(
int j=0;j<
NHITS;j++){
271 SimCalorimeterHitImpl* existingHit
272 =
dynamic_cast<SimCalorimeterHitImpl*
>( calVec->getElementAt(j) ) ;
274 existingHit->addMCParticleContribution( dynamic_cast<MCParticle*>
275 (mcVec->getElementAt(0)),
283 LCCollectionVec* trkVec =
new LCCollectionVec( LCIO::SIMTRACKERHIT ) ;
284 LCCollectionVec* extFVec =
new LCCollectionVec( LCIO::LCFLOATVEC ) ;
285 LCCollectionVec* extIVec =
new LCCollectionVec( LCIO::LCINTVEC ) ;
292 LCTypedVector<MCParticle> mcpTV( mcVec ) ;
294 CellIDEncoder<SimTrackerHitImpl> cd(
"i:8,j:8,k:8" ,trkVec ) ;
296 for(
int j=0;j<
NHITS;j++){
298 SimTrackerHitImpl* hit =
new SimTrackerHitImpl ;
304 cd.setCellID( hit ) ;
306 LCFloatVec* extF =
new LCFloatVec ;
307 LCIntVec* extI =
new LCIntVec ;
310 hit->setEDep( 30e-9 ) ;
312 double pos[3] = { 1.1*
rand()/RAND_MAX , 2.2*
rand()/RAND_MAX , 3.3*
rand()/RAND_MAX } ;
314 hit->setPosition( pos ) ;
317 float rnd = .99999*
rand()/RAND_MAX ;
318 int mcIndx =
static_cast<int>( NMCPART * rnd ) ;
322 hit->setMCParticle( mcpTV[ mcIndx ] ) ;
324 hit->setMomentum( 1. , 2. , 3. ) ;
325 hit->setPathLength( .042 ) ;
328 extF->push_back( 3.14159 ) ;
329 for(
int k=0;k<3;k++) extF->push_back( pos[k] * 0.1 ) ;
331 extI->push_back( 123456789 ) ;
332 extI->push_back( mcIndx ) ;
335 trkVec->push_back( hit ) ;
336 extFVec->push_back( extF ) ;
337 extIVec->push_back( extI ) ;
342 evt->addCollection( mcVec ,
"MCParticle" ) ;
347 evt->addCollection( calVec , ecalName ) ;
348 evt->addCollection( trkVec , tpcName ) ;
349 evt->addCollection( extFVec , tpcName+
"UserFloatExtension" ) ;
350 evt->addCollection( extIVec , tpcName+
"UserIntExtension" ) ;
354 if( rn == 1 && i == 0 ) {
355 LCCollectionVec* addExtVec =
new LCCollectionVec( LCIO::LCFLOATVEC ) ;
356 LCFloatVec* addExt =
new LCFloatVec ;
357 addExt->push_back( 1. );
358 addExt->push_back( 2. );
359 addExt->push_back( 3. );
360 addExt->push_back( 4. );
361 addExtVec->push_back( addExt ) ;
362 evt->addCollection( addExtVec ,
"AdditionalExtension" ) ;
365 LCCollectionVec* mcSubVec =
new LCCollectionVec( LCIO::MCPARTICLE ) ;
366 mcSubVec->setSubset(
true) ;
368 for(
int j=0;j< mcVec->getNumberOfElements() ; j++ ){
370 MCParticle* p =
dynamic_cast< MCParticle*
>( mcVec->getElementAt(j) ) ;
371 if( p->getDaughters().size() == 0 )
372 mcSubVec->addElement( p ) ;
374 evt->addCollection( mcSubVec ,
"FinalMCParticles" ) ;
381 #define WRITE_TRACKERRAWDATA 1
382 #ifdef WRITE_TRACKERRAWDATA
384 LCCollectionVec* tpcRawVec =
new LCCollectionVec( LCIO::TRACKERRAWDATA ) ;
386 for(
int j=0;j<
NHITS;j++){
388 TrackerRawDataImpl* tpcRaw =
new TrackerRawDataImpl ;
390 tpcRaw->setCellID0( j ) ;
391 tpcRaw->setTime( -j ) ;
396 adcValues.push_back( 43 ) ;
397 adcValues.push_back( 44 ) ;
398 adcValues.push_back( 45 ) ;
399 tpcRaw->setADCValues( adcValues ) ;
401 tpcRaw->adcValues().push_back( 42 ) ;
402 tpcRaw->adcValues().push_back( 43 ) ;
403 tpcRaw->adcValues().push_back( 44 ) ;
404 tpcRaw->adcValues().push_back( 45 ) ;
406 tpcRawVec->addElement( tpcRaw ) ;
408 evt->addCollection( tpcRawVec ,
"TrackerRawDataExample" ) ;
411 LCRelationNavigator relNav( LCIO::TRACKERRAWDATA, LCIO::SIMTRACKERHIT ) ;
413 for(
int j=0;j<
NHITS;j++){
414 relNav.addRelation( tpcRawVec->getElementAt(j) , trkVec->getElementAt(j) , 0.42 ) ;
421 evt->addCollection( relNav.createLCCollection() ,
"TPCRawFADCMCTruth" ) ;
426 LCCollectionVec* tpcCorrectedVec =
new LCCollectionVec( LCIO::TRACKERDATA ) ;
428 for(
int j=0;j<
NHITS;j++){
430 TrackerDataImpl* tpcCorrected =
new TrackerDataImpl ;
432 tpcCorrected->setCellID0( j ) ;
433 tpcCorrected->setTime( -j ) ;
435 tpcCorrected->chargeValues().push_back( 42.12345 ) ;
436 tpcCorrected->chargeValues().push_back( 43.09876 ) ;
437 tpcCorrected->chargeValues().push_back( 44.12345 ) ;
438 tpcCorrected->chargeValues().push_back( 45.09876 ) ;
440 tpcCorrectedVec->addElement( tpcCorrected ) ;
442 evt->addCollection( tpcCorrectedVec ,
"TrackerDataExample" ) ;
446 LCCollectionVec* tpcPulseVec =
new LCCollectionVec( LCIO::TRACKERPULSE ) ;
450 qualityBits.push_back(1) ;
456 tpcPulseVec->parameters().setValues(
"TrackerPulseQualityNames", bitNames );
457 tpcPulseVec->parameters().setValues(
"TrackerPulseQualityValues", qualityBits );
459 for(
int j=0;j<
NHITS;j++){
461 TrackerPulseImpl* tpcPulse =
new TrackerPulseImpl ;
463 tpcPulse->setCellID0( j ) ;
464 tpcPulse->setTime( 3.1415 + 0.1 * j ) ;
465 tpcPulse->setCharge( 3.1415 - 0.1 * j ) ;
468 tpcPulse->setQualityBit( qualityBits[0] ) ;
471 tpcPulse->setQualityBit( qualityBits[1] ) ;
474 dynamic_cast<TrackerData*
> ( tpcCorrectedVec->getElementAt(j) ) ;
475 tpcPulse->setTrackerData( corr ) ;
478 tpcPulseVec->addElement( tpcPulse ) ;
480 evt->addCollection( tpcPulseVec ,
"TrackerPulseExample" ) ;
483 #endif // WRITE_TRACKERRAWDATA
485 #define WRITE_VTXRAWHITS 1
486 #ifdef WRITE_VTXRAWHITS
489 LCCollectionVec* vtxRawVec =
new LCCollectionVec( LCIO::TRACKERPULSE ) ;
491 for(
int j=0;j<
NHITS;j++){
493 TrackerPulseImpl* vtxRaw =
new TrackerPulseImpl ;
495 vtxRaw->setCellID0( 0xBebaFeca ) ;
496 vtxRaw->setCellID1( 0xCafeBabe ) ;
497 vtxRaw->setTime( j ) ;
498 vtxRaw->setCharge( 42 + j ) ;
500 vtxRawVec->addElement( vtxRaw ) ;
502 evt->addCollection( vtxRawVec ,
"SiliconRawHitExample" ) ;
505 #endif // WRITE_VTXRAWHITS
510 lcWrt->writeEvent( evt ) ;
533 <<
" created " << NRUN <<
" runs with " << NRUN*
NEVENT <<
" events"
555 }
catch( Exception& ex){
557 cout <<
" an excpetion occured: " <<
endl ;
std::vector< std::string > StringVec
Vector of strings.
std::vector< float > FloatVec
Vector of floats.
std::vector< double > DoubleVec
Vector of doubles.
int main(int argc, char **argv)
Simple program that opens existing LCIO files and appends the records needed for direct access - if t...
std::vector< int > IntVec
Vector of ints.
BitSet32 make_bitset32(int bit0)
Convenient helper that creates a BitSet32 with bit0 set.
void dumpEvent(EVENT::LCEvent *event)
std::vector< short > ShortVec
Vector of shorts.