Print

Print


Commit in lcio/src/cpp on MAIN
include/UTIL/CellIDEncoder.h+126added 1.1
src/EXAMPLE/simjob.cc+48-541.48 -> 1.49
+174-54
1 added + 1 modified, total 2 files
convenient template for encoding cellids of hit classes

lcio/src/cpp/include/UTIL
CellIDEncoder.h added at 1.1
diff -N CellIDEncoder.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ CellIDEncoder.h	22 Mar 2006 17:38:22 -0000	1.1
@@ -0,0 +1,126 @@
+#ifndef CellIDEncoder_h
+#define CellIDEncoder_h 1
+
+#include "EVENT/LCCollection.h"
+#include "UTIL/BitField64.h"
+#include "lcio.h"
+#include <string>
+
+using namespace lcio ;
+
+namespace EVENT{
+  class SimCalorimeterHit ;
+  class RawCalorimeterHit ;
+  class TrackerData ;
+  class TrackerPulse ;
+  class TrackerRawData ;
+}
+namespace IMPL{
+  class SimTrackerHitImpl ;
+}
+
+namespace UTIL{
+
+
+  /** Convenient class for encoding cellIDs for various hit objects.
+   *  It sets the proper collection parameter LCIO::CellIDEncoding and
+   *  sets the proper flag bit for storing a second cellid if necessary.
+   *  See UTIL::BitField64 for a description of the encoding string. 
+   *  Example:<br>
+   *  &nbsp;   CellIDEncoder<SimCalorimeterHitImpl> cd( "i:20,j:20,k:20" ,calVec )  ;<br>
+   *  &nbsp;   for(int j=0;j<NHITS;j++){<br>
+   *  &nbsp;&nbsp;  SimCalorimeterHitImpl* hit = new SimCalorimeterHitImpl ;<br>
+   *  &nbsp;&nbsp;    cd["i"] = j ;<br>
+   *  &nbsp;&nbsp;    cd["j"] = j + 100 ;<br>
+   *  &nbsp;&nbsp;    cd["k"] = j + 200 ;<br>
+   *  &nbsp;&nbsp;    cd.setCellID( hit ) ;<br>
+   *  &nbsp;   } <br>
+   * 
+   *  @see BitField64
+   *  @version $Id: CellIDEncoder.h,v 1.1 2006/03/22 17:38:22 gaede Exp $
+   */
+  template <class T> 
+  class CellIDEncoder : public BitField64 {
+
+  public:  
+    
+    /** Constructor reads encoding string from collection parameter LCIO::CellIDEncoding.
+     */
+    CellIDEncoder( const std::string& cellIDEncoding ,  LCCollection* col) :
+
+      BitField64( cellIDEncoding  ),
+
+      _col( col ) {
+      
+	_col->parameters().setValue( LCIO::CellIDEncoding , cellIDEncoding ) ;
+
+	setCellIDFlag() ;
+    }
+
+    void setCellID( T* hit) {
+      
+      hit->setCellID0( lowWord()  ) ;
+      
+      hit->setCellID1( highWord() ) ;
+
+    }
+
+    /** Helper method that sets/unsets the proper bit for storing a second cellid word 
+     */
+    void setCellIDFlag() {
+      
+      int bit = cellID1Bit() ;
+      
+      if(  bit >= 0 ) {
+	
+	LCFlagImpl f( _col->getFlag() ) ;
+	
+	if( highestBit() > 31 ) {
+	  
+	  // 	  std::cout << " setting bit " <<  bit << std::endl ;
+	  f.setBit( bit ) ;
+	  
+	} else {
+	  // 	  std::cout << " unsetting bit " <<  bit << std::endl ;
+	  f.unsetBit( bit ) ;
+	}
+	
+	_col->setFlag( f.getFlag()  ) ;
+      }
+    }
+    
+  protected:
+    
+    int cellID1Bit() { return -1 ; }
+
+ 
+    LCCollection* _col ;
+    T* _oldHit ;
+  } ; 
+  
+  /** Specialization for SimTrackerHits that have only one cellID */
+  template<> void CellIDEncoder<IMPL::SimTrackerHitImpl>::setCellID( IMPL::SimTrackerHitImpl* hit) {
+    hit->setCellID( lowWord()  ) ;
+  }
+
+  /** specialization that returns the proper bit for the second cellid */
+  template<> int CellIDEncoder<EVENT::SimCalorimeterHit>::cellID1Bit() {  return LCIO::CHBIT_ID1 ; }
+
+  /** specialization that returns the proper bit for the second cellid */
+  template<> int CellIDEncoder<EVENT::RawCalorimeterHit>::cellID1Bit() {  return LCIO::RCHBIT_ID1 ; }
+
+  /** specialization that returns the proper bit for the second cellid */
+  template<> int CellIDEncoder<EVENT::TrackerData>::cellID1Bit() {  return LCIO::TRAWBIT_ID1 ; }
+
+  /** specialization that returns the proper bit for the second cellid */
+  template<> int CellIDEncoder<EVENT::TrackerPulse>::cellID1Bit() {  return LCIO::TRAWBIT_ID1 ; }
+
+  /** specialization that returns the proper bit for the second cellid */
+  template<> int CellIDEncoder<EVENT::TrackerRawData>::cellID1Bit() {  return LCIO::TRAWBIT_ID1 ; }
+
+
+
+} // namespace
+#endif
+
+

lcio/src/cpp/src/EXAMPLE
simjob.cc 1.48 -> 1.49
diff -u -r1.48 -r1.49
--- simjob.cc	10 Mar 2006 16:23:18 -0000	1.48
+++ simjob.cc	22 Mar 2006 17:38:23 -0000	1.49
@@ -14,14 +14,16 @@
 #include "IMPL/LCFlagImpl.h" 
 #include "IMPL/LCTOOLS.h"
 
-#include "IMPL/TPCHitImpl.h"
 #include "IMPL/TrackerRawDataImpl.h"
 #include "IMPL/TrackerDataImpl.h"
 #include "IMPL/TrackerPulseImpl.h"
 
 #include "UTIL/LCRelationNavigator.h"
 #include "UTIL/LCTime.h"
-#include "UTIL/BitField64.h"
+//#include "UTIL/BitField64.h"
+#include "UTIL/CellIDEncoder.h"
+
+#include "UTIL/LCIOTypeInfo.h"
 
 #include <cstdlib>
 #include <iostream>
@@ -46,6 +48,20 @@
   
   try{
     
+//     std::cout << lctypename<MCParticle>() << std::endl ;
+//     std::cout << lctypename<ReconstructedParticle>() << std::endl ;
+
+//     std::cout << lctypename<SimTrackerHit>() << std::endl ;
+//     SimTrackerHitImpl sth ;
+//     std::cout <<  lctypename( &sth ) << std::endl ;
+
+//     std::cout << ti1.lctypename() << std::endl ;
+//     std::cout << ti2.lctypename() << std::endl ;
+
+//     LCObject* obj =   &sth ;
+//     std::cout <<  lctypename( obj ) << std::endl ;
+    
+
     // loop over runs
     for(int rn=0;rn<NRUN;rn++){
       
@@ -187,14 +203,14 @@
 	LCFlagImpl chFlag(0) ;
 	chFlag.setBit( LCIO::CHBIT_LONG ) ;
 	chFlag.setBit( LCIO::CHBIT_PDG ) ;
-	chFlag.setBit( LCIO::CHBIT_ID1 ) ;
 	calVec->setFlag( chFlag.getFlag()  ) ;
 	
 	std::string cellIDEncoding( "M:3,S-1:3,I:9,J:9,K-1:6") ;// old Mokka convention
-	calVec->parameters().setValue( LCIO::CellIDEncoding , cellIDEncoding ) ;
 
-	BitField64 b( cellIDEncoding  ) ;
-	
+// 	std::string cellIDEncoding( "M:3,S-1:3,I:9,J:9,K-1:6,Bla:34:6") ;// for testing cellid1
+
+	CellIDEncoder<SimCalorimeterHitImpl> b( cellIDEncoding , calVec ) ;
+
 	for(int j=0;j<NHITS;j++){
 	  
 	  SimCalorimeterHitImpl* hit = new SimCalorimeterHitImpl ;
@@ -210,8 +226,10 @@
 	  b["J"] = (j+128) % 512 ;
 	  b["K-1"] = (j+32) % 64 ;
 
-	  hit->setCellID0( b.lowWord()  ) ;
-	  hit->setCellID1( b.highWord() ) ;
+	  b.setCellID( hit ) ;
+
+// 	  hit->setCellID0( b.lowWord()  ) ;
+// 	  hit->setCellID1( b.highWord() ) ;
 	  
 	  hit->setPosition( pos ) ;
 	  
@@ -253,9 +271,18 @@
 	trkVec->setFlag( thFlag.getFlag()  ) ;
 	
 
+	CellIDEncoder<SimTrackerHitImpl> cd( "i:8,j:8,k:8" ,trkVec )  ;
+	
 	for(int j=0;j<NHITS;j++){
 	  
 	  SimTrackerHitImpl* hit = new SimTrackerHitImpl ;
+
+	  cd["i"] = j ;
+	  cd["j"] = j + 100 ;
+	  cd["k"] = j + 200 ;
+
+	  cd.setCellID( hit ) ;
+
 	  LCFloatVec* extF = new LCFloatVec ;
 	  LCIntVec*   extI = new LCIntVec ;
 	  
@@ -310,51 +337,6 @@
 	  addExtVec->push_back( addExt ) ;
 	  evt->addCollection( addExtVec , "AdditionalExtension" ) ;
 	}
-
-	// even though this is a simjob we can store 'real data' objects :)
-	// --- for example we can store TPC hits ------------
-
-	LCCollectionVec* TPCVec = new LCCollectionVec( LCIO::TPCHIT )  ;
-
-	//---- test new relation navigator object
-	LCRelationNavigator relNav( LCIO::TPCHIT, LCIO::SIMTRACKERHIT ) ;
-
-	bool storeRawData = true ;
-
-	LCFlagImpl tpcFlag(0) ;
-	if(  storeRawData )  // if we want to store the raw data we need to set the flag
-	  tpcFlag.setBit( LCIO::TPCBIT_RAW ) ;
-	TPCVec->setFlag( tpcFlag.getFlag()  ) ;
-	
-	for(int j=0;j<NHITS;j++){
-	  
-	  TPCHitImpl* tpcHit = new TPCHitImpl ;
-	  
-	  //---- test new relation navigator object
-	  relNav.addRelation( tpcHit , trkVec->getElementAt(j) , 0.95  ) ;
-	  
-	  tpcHit->setCellID( j ) ;
-	  tpcHit->setTime( 0.1234567 ) ;
-	  tpcHit->setCharge( 3.14159 ) ;
-	  tpcHit->setQuality(  0xbad ) ;
-
-	  if(  storeRawData ) {
-	    int rawData[10] ;
-	    // fill some random numbers 
-	    int size =   int( (double(rand()) / RAND_MAX ) * 10 )  ;   
-	    for(int k=0;k<size;k++){
-	      rawData[k] = int( (double(rand()) / RAND_MAX ) * INT_MAX ) ;   
-	    }
-
-	    tpcHit->setRawData( rawData , size ) ;
-	  }
-
-	  TPCVec->push_back( tpcHit ) ;
-	}	
-	evt->addCollection( TPCVec , "TPCRawFADC" ) ;
-	evt->addCollection( relNav.createLCCollection() , "TPCRawFADCMCTruth" ) ;
-
-	
  	//---- write a subset of MCParticle to the event ------
  	LCCollectionVec* mcSubVec = new LCCollectionVec( LCIO::MCPARTICLE )  ;
  	mcSubVec->setSubset(true) ;
@@ -369,6 +351,9 @@
  	//-----------------------------------------------------
 
 
+
+	// even though this is a simjob we can store 'real data' objects :)
+
 #define WRITE_TRACKERRAWDATA 1
 #ifdef WRITE_TRACKERRAWDATA
 	//--- write some new TPC raw data collections to the file 
@@ -398,8 +383,17 @@
 	}
 	evt->addCollection( tpcRawVec , "TrackerRawDataExample" ) ;
 
-	//------ corrected data
+	//---- test new relation navigator object
+	LCRelationNavigator relNav( LCIO::TRACKERRAWDATA, LCIO::SIMTRACKERHIT ) ;
+	
+	for(int j=0;j<NHITS;j++){
+	  relNav.addRelation( tpcRawVec->getElementAt(j) , trkVec->getElementAt(j) , 0.42 ) ;
+	}
+	evt->addCollection( relNav.createLCCollection() , "TPCRawFADCMCTruth" ) ;
+	
 
+	//------ corrected data
+	
 	LCCollectionVec* tpcCorrectedVec = new LCCollectionVec( LCIO::TRACKERDATA )  ;
 	
 	for(int j=0;j<NHITS;j++){
CVSspam 0.2.8