From 0530dc80330b2032599b8d15041032081c882ec9 Mon Sep 17 00:00:00 2001 From: Cao Guangjie <gjcao@lxslc605.ihep.ac.cn> Date: Wed, 16 Oct 2019 15:37:46 +0800 Subject: [PATCH] variables name update --- Examples/options/plcio_read.py | 7 +- Examples/options/plcio_write.py | 1 + FWCore/src/components/LCIO2Plcio.cpp | 272 ++++++++++++++++++--------- FWCore/src/components/LCIO2Plcio.h | 20 +- 4 files changed, 199 insertions(+), 101 deletions(-) diff --git a/Examples/options/plcio_read.py b/Examples/options/plcio_read.py index 3d639dca..d8b0b739 100644 --- a/Examples/options/plcio_read.py +++ b/Examples/options/plcio_read.py @@ -7,12 +7,13 @@ dsvc = CEPCDataSvc("EventDataSvc", input="test.root") from Configurables import PlcioReadAlg alg = PlcioReadAlg("PlcioReadAlg") -alg.InputCol.Path = "MCParticleCol" +alg.HeaderCol.Path = "EventHeader" +alg.InputCol.Path = "MCParticle" from Configurables import PodioInput podioinput = PodioInput("PodioReader", collections=[ - "EventHeaderCol", - "MCParticleCol" + "EventHeader", + "MCParticle" ]) # ApplicationMgr diff --git a/Examples/options/plcio_write.py b/Examples/options/plcio_write.py index 0096c2df..378aae84 100644 --- a/Examples/options/plcio_write.py +++ b/Examples/options/plcio_write.py @@ -7,6 +7,7 @@ dsvc = CEPCDataSvc("EventDataSvc") from Configurables import PlcioWriteAlg alg = PlcioWriteAlg("PlcioWriteAlg") +alg.HeaderCol.Path = "EventHeader" alg.OutputCol.Path = "MCParticle" from Configurables import PodioOutput diff --git a/FWCore/src/components/LCIO2Plcio.cpp b/FWCore/src/components/LCIO2Plcio.cpp index ac853eaa..8292d421 100644 --- a/FWCore/src/components/LCIO2Plcio.cpp +++ b/FWCore/src/components/LCIO2Plcio.cpp @@ -11,7 +11,6 @@ typedef std::vector<EVENT::MCParticle*> MCParticleVec ; -//std::map<std::string, fptr> LCIO2Plcio::map_cvt; CollectionsMap LCIO2Plcio::map_cols; void lp_info(std::string s){ @@ -30,70 +29,79 @@ LCIO2Plcio::LCIO2Plcio(EVENT::LCCollection* collection){ podio::CollectionBase* LCIO2Plcio::Convertor_LCRunHeader(EVENT::LCCollection* lc_col){ plcio::LCRunHeaderCollection* pl_col = new plcio::LCRunHeaderCollection(); -// plcio::LCRunHeader pl_rh = (plcio::LCRunHeader) pl_col->create(); + + // Convert basic info from LCIO to plcio; + for( unsigned i=0,N=lc_col->getNumberOfElements() ; i< N ; ++i){ + EVENT::LCRunHeader* lc_var = (EVENT::LCRunHeader*) lc_col->getElementAt(i) ; + plcio::LCRunHeader pl_var = (plcio::LCRunHeader) pl_col->create(); + pl_var.setRunNumber( lc_var->getRunNumber() ); + pl_var.setDetectorName( lc_var->getDetectorName() ); + pl_var.setDescription( lc_var->getDescription() ); + + std::vector<std::string> vec_dct = *(lc_var->getActiveSubdetectors()); + for( unsigned j=0,N=vec_dct.size(); j<N; j++){ + pl_var.addActiveSubdetector( vec_dct[j] ); + } + } return pl_col; } -void LCIO2Plcio::void_Core_MCParticle(EVENT::MCParticle* lc_mcp, plcio::MCParticle& pl_mcp){ - - pl_mcp.setPDG( lc_mcp->getPDG() ); - pl_mcp.setGeneratorStatus( lc_mcp->getGeneratorStatus() ); - pl_mcp.setSimulatorStatus( lc_mcp->getSimulatorStatus() ); - pl_mcp.setCharge( lc_mcp->getCharge() ); - pl_mcp.setTime( lc_mcp->getTime() ); - pl_mcp.setMass( lc_mcp->getMass() ); - pl_mcp.setStopped( lc_mcp->isStopped() ); - pl_mcp.setOverlay( lc_mcp->isOverlay() ); - pl_mcp.setBackscatter( lc_mcp->isBackscatter() ); - pl_mcp.setDecayedInTracker( lc_mcp->isDecayedInTracker() ); - pl_mcp.setDecayedInCalorimeter( lc_mcp->isDecayedInCalorimeter() ); - pl_mcp.setCreatedInSimulation( lc_mcp->isCreatedInSimulation() ); - pl_mcp.setVertexIsNotEndpointOfParent( lc_mcp->vertexIsNotEndpointOfParent() ); - pl_mcp.setHasLeftDetector( lc_mcp->hasLeftDetector() ); - - pl_mcp.setSpin( plcio::FloatThree( lc_mcp->getSpin() ) ); - pl_mcp.setColorFlow( plcio::IntTwo( lc_mcp->getColorFlow() ) ); - pl_mcp.setVertex( plcio::DoubleThree( lc_mcp->getVertex())); - pl_mcp.setEndpoint( plcio::DoubleThree( lc_mcp->getEndpoint() ) ); +void LCIO2Plcio::setMCParticle(EVENT::MCParticle* lc_var, plcio::MCParticle& pl_var){ + + pl_var.setPDG( lc_var->getPDG() ); + pl_var.setGeneratorStatus( lc_var->getGeneratorStatus() ); + pl_var.setSimulatorStatus( lc_var->getSimulatorStatus() ); + pl_var.setCharge( lc_var->getCharge() ); + pl_var.setTime( lc_var->getTime() ); + pl_var.setMass( lc_var->getMass() ); + pl_var.setStopped( lc_var->isStopped() ); + pl_var.setOverlay( lc_var->isOverlay() ); + pl_var.setBackscatter( lc_var->isBackscatter() ); + pl_var.setDecayedInTracker( lc_var->isDecayedInTracker() ); + pl_var.setDecayedInCalorimeter( lc_var->isDecayedInCalorimeter() ); + pl_var.setCreatedInSimulation( lc_var->isCreatedInSimulation() ); + pl_var.setVertexIsNotEndpointOfParent( lc_var->vertexIsNotEndpointOfParent() ); + pl_var.setHasLeftDetector( lc_var->hasLeftDetector() ); + + pl_var.setSpin( plcio::FloatThree( lc_var->getSpin() ) ); + pl_var.setColorFlow( plcio::IntTwo( lc_var->getColorFlow() ) ); + pl_var.setVertex( plcio::DoubleThree( lc_var->getVertex())); + pl_var.setEndpoint( plcio::DoubleThree( lc_var->getEndpoint() ) ); // send float ptr as parameter to FloatThree. - float plcio_m[3]; - const double* lcio_m = lc_mcp->getMomentum(); - plcio_m[0] = lcio_m[0]; - plcio_m[1] = lcio_m[1]; - plcio_m[2] = lcio_m[2]; - pl_mcp.setMomentum( plcio::FloatThree( plcio_m ) ); - - lcio_m = lc_mcp->getMomentumAtEndpoint(); - plcio_m[0] = lcio_m[0]; - plcio_m[1] = lcio_m[1]; - plcio_m[2] = lcio_m[2]; - pl_mcp.setMomentumAtEndpoint( plcio::FloatThree( plcio_m ) ); + float plcio_v[3]; + const double* lcio_v = lc_var->getMomentum(); + plcio_v[0] = lcio_v[0]; + plcio_v[1] = lcio_v[1]; + plcio_v[2] = lcio_v[2]; + pl_var.setMomentum( plcio::FloatThree( plcio_v ) ); + + lcio_v = lc_var->getMomentumAtEndpoint(); + plcio_v[0] = lcio_v[0]; + plcio_v[1] = lcio_v[1]; + plcio_v[2] = lcio_v[2]; + pl_var.setMomentumAtEndpoint( plcio::FloatThree( plcio_v ) ); } podio::CollectionBase* LCIO2Plcio::Convertor_MCParticle(EVENT::LCCollection* lc_col){ - return Core_MCParticle(lc_col); -} - -plcio::MCParticleCollection* LCIO2Plcio::Core_MCParticle(EVENT::LCCollection* lc_col){ plcio::MCParticleCollection* pl_col = new plcio::MCParticleCollection(); // Convert basic info from LCIO to plcio; for( unsigned i=0,N=lc_col->getNumberOfElements() ; i< N ; ++i){ - EVENT::MCParticle* lc_mcp = (EVENT::MCParticle*) lc_col->getElementAt(i) ; - plcio::MCParticle pl_mcp = (plcio::MCParticle) pl_col->create(); + EVENT::MCParticle* lc_var = (EVENT::MCParticle*) lc_col->getElementAt(i) ; + plcio::MCParticle pl_var = (plcio::MCParticle) pl_col->create(); - void_Core_MCParticle(lc_mcp, pl_mcp); + setMCParticle(lc_var, pl_var); // dealing each of 'Parents' of lcio::MCParticle ; - const MCParticleVec& veclc = lc_mcp->getParents(); + const MCParticleVec& veclc = lc_var->getParents(); for(unsigned j=0; j<veclc.size(); j++){ EVENT::MCParticle* vlcreg = veclc[j]; for(unsigned k=0; k<i; ++k){ if(((EVENT::MCParticle*) lc_col->getElementAt(k)) == vlcreg){ // A loop for plcio's MCParticleCollection to recover plcio's relationship; - plcio::MCParticle plprt = pl_col->at(k); - pl_mcp.addParent(plprt); - plprt.addDaughter(pl_mcp); + plcio::MCParticle mcprt = pl_col->at(k); + pl_var.addParent(mcprt); + mcprt.addDaughter(pl_var); } } } @@ -101,32 +109,23 @@ plcio::MCParticleCollection* LCIO2Plcio::Core_MCParticle(EVENT::LCCollection* lc return pl_col; } -//void LCIO2Plcio::setPlcioMCParticleCollection(plcio::MCParticleCollection* pl_col){ -// hitcol_pl = pl_col; -//} - -//void LCIO2Plcio::setLCIOMCParticleCollection(EVENT::LCCollection* lc_col){ -// hitcol_lc = lc_col; -//} - - podio::CollectionBase* LCIO2Plcio::Convertor_SimTrackerHit(EVENT::LCCollection* lc_col){ plcio::SimTrackerHitCollection* pl_col = new plcio::SimTrackerHitCollection(); for( unsigned i=0,N=lc_col->getNumberOfElements() ; i< N ; ++i){ - EVENT::SimTrackerHit* lc_sth = (EVENT::SimTrackerHit*) lc_col->getElementAt(i) ; - plcio::SimTrackerHit pl_sth = (plcio::SimTrackerHit) pl_col->create(); - - pl_sth.setCellID0( lc_sth->getCellID0() ); - pl_sth.setCellID1( lc_sth->getCellID1() ); - pl_sth.setEDep( lc_sth->getEDep() ); - pl_sth.setTime( lc_sth->getTime() ); - pl_sth.setPathLength( lc_sth->getPathLength() ); - pl_sth.setQuality( lc_sth->getQuality() ); - pl_sth.setPosition( lc_sth->getPosition() ); - pl_sth.setMomentum( lc_sth->getMomentum() ); - pl_sth.setOverlay( lc_sth->isOverlay() ); - pl_sth.setProducedBySecondary( lc_sth->isProducedBySecondary() ); + EVENT::SimTrackerHit* lc_var = (EVENT::SimTrackerHit*) lc_col->getElementAt(i) ; + plcio::SimTrackerHit pl_var = (plcio::SimTrackerHit) pl_col->create(); + + pl_var.setCellID0( lc_var->getCellID0() ); + pl_var.setCellID1( lc_var->getCellID1() ); + pl_var.setEDep( lc_var->getEDep() ); + pl_var.setTime( lc_var->getTime() ); + pl_var.setPathLength( lc_var->getPathLength() ); + pl_var.setQuality( lc_var->getQuality() ); + pl_var.setPosition( lc_var->getPosition() ); + pl_var.setMomentum( lc_var->getMomentum() ); + pl_var.setOverlay( lc_var->isOverlay() ); + pl_var.setProducedBySecondary( lc_var->isProducedBySecondary() ); // Looping the LCIO::MCParticleCollection to pick Particle for Hits; CollectionsVec vec_mcp; @@ -136,7 +135,7 @@ podio::CollectionBase* LCIO2Plcio::Convertor_SimTrackerHit(EVENT::LCCollection* int index = -1; // search corresponding MCParticleCollection*; - EVENT::MCParticle* mcptr_reg = lc_sth->getMCParticle(); + EVENT::MCParticle* mcptr_reg = lc_var->getMCParticle(); for( unsigned j=0, M=hitcol_lc->getNumberOfElements(); j<M; ++j){ EVENT::MCParticle* mcpin_lc = (EVENT::MCParticle*) hitcol_lc->getElementAt(j); if( mcpin_lc == mcptr_reg ){ @@ -153,7 +152,7 @@ podio::CollectionBase* LCIO2Plcio::Convertor_SimTrackerHit(EVENT::LCCollection* // printf("Index: %d\n", index); } if( is_empty == false ) - pl_sth.setMCParticle( hitcol_pl->at(index) ); + pl_var.setMCParticle( hitcol_pl->at(index) ); } return pl_col; @@ -163,37 +162,126 @@ podio::CollectionBase* LCIO2Plcio::Convertor_SimCalorimeterHit(EVENT::LCCollecti plcio::SimCalorimeterHitCollection* pl_col = new plcio::SimCalorimeterHitCollection(); for( unsigned i=0,N=lc_col->getNumberOfElements() ; i< N ; ++i){ - EVENT::SimCalorimeterHit* lc_sch = (EVENT::SimCalorimeterHit*) lc_col->getElementAt(i); - plcio::SimCalorimeterHit pl_sch = (plcio::SimCalorimeterHit) pl_col->create(); - - pl_sch.setCellID0( lc_sch->getCellID0() ); - pl_sch.setCellID1( lc_sch->getCellID1() ); - pl_sch.setEnergy( lc_sch->getEnergy() ); - - float plcio_p[3]; - const float* lcio_p = lc_sch->getPosition(); - plcio_p[0] = lcio_p[0]; - plcio_p[1] = lcio_p[1]; - plcio_p[2] = lcio_p[2]; - pl_sch.setPosition( plcio::FloatThree( plcio_p ) ); - - // converting from lc_sch to pl_sch on the contribution variables; - for( unsigned j=0, N=lc_sch->getNMCContributions(); j<N; j++){ - plcio_p[0] = lc_sch->getStepPosition(j)[0]; - plcio_p[1] = lc_sch->getStepPosition(j)[1]; - plcio_p[2] = lc_sch->getStepPosition(j)[2]; + EVENT::SimCalorimeterHit* lc_var = (EVENT::SimCalorimeterHit*) lc_col->getElementAt(i); + plcio::SimCalorimeterHit pl_var = (plcio::SimCalorimeterHit) pl_col->create(); + + pl_var.setCellID0( lc_var->getCellID0() ); + pl_var.setCellID1( lc_var->getCellID1() ); + pl_var.setEnergy( lc_var->getEnergy() ); + + float plcio_v[3]; + const float* lcio_v = lc_var->getPosition(); + plcio_v[0] = lcio_v[0]; + plcio_v[1] = lcio_v[1]; + plcio_v[2] = lcio_v[2]; + pl_var.setPosition( plcio::FloatThree( plcio_v ) ); + + // converting from lc_var to pl_var on the contribution variables; + for( unsigned j=0, N=lc_var->getNMCContributions(); j<N; j++){ + plcio_v[0] = lc_var->getStepPosition(j)[0]; + plcio_v[1] = lc_var->getStepPosition(j)[1]; + plcio_v[2] = lc_var->getStepPosition(j)[2]; plcio::ConstCaloHitContribution tmp( - lc_sch->getPDGCont(j), lc_sch->getEnergyCont(j), - lc_sch->getTimeCont(j), plcio::FloatThree(plcio_p) + lc_var->getPDGCont(j), lc_var->getEnergyCont(j), + lc_var->getTimeCont(j), plcio::FloatThree(plcio_v) ); - pl_sch.addContribution( tmp ); + pl_var.addContribution( tmp ); + } + } + return pl_col; +} + +podio::CollectionBase* LCIO2Plcio::Convertor_Cluster(EVENT::LCCollection* lc_col){ + plcio::ClusterCollection* pl_col = new plcio::ClusterCollection(); + + for( unsigned i=0,N=lc_col->getNumberOfElements() ; i< N ; ++i){ + EVENT::Cluster* lc_var = (EVENT::Cluster*) lc_col->getElementAt(i); + plcio::Cluster pl_var = (plcio::Cluster) pl_col->create(); + + pl_var.setType(lc_var->getType()); + pl_var.setEnergy(lc_var->getEnergy()); + pl_var.setEnergyError(lc_var->getEnergyError()); + pl_var.setPhi(lc_var->getIPhi()); + pl_var.setITheta(lc_var->getITheta()); + + float plcio_v[3]; + const float* lcio_v = lc_var->getPosition(); + plcio_v[0] = lcio_v[0]; + plcio_v[1] = lcio_v[1]; + plcio_v[2] = lcio_v[2]; + pl_var.setPosition( plcio::FloatThree(plcio_v) ); + + std::vector<float> lcio_vecfloat = lc_var->getPositionError(); + std::array<float, 6> plcio_arr6; + for(unsigned j=0; j<6; j++){ + plcio_arr6[j] = lcio_vecfloat[j]; } + pl_var.setPositionError(plcio_arr6); + +// pl_var.(lc_var->getDirectionError()); +// pl_var.(lc_var->getShape()); +// pl_var.(lc_var->getParticleIDs()); +// pl_var.(lc_var->getClusters()); +// pl_var.(lc_var->getCalorimeterHits()); +// pl_var.(lc_var->getHitContributions()); +// pl_var.(lc_var->getSubdetectorEnergies()); } return pl_col; } +podio::CollectionBase* LCIO2Plcio::Convertor_Vertex(EVENT::LCCollection* lc_col){ + plcio::VertexCollection* pl_col = new plcio::VertexCollection(); + + for( unsigned i=0,N=lc_col->getNumberOfElements() ; i< N ; ++i){ + EVENT::Vertex* lc_var = (EVENT::Vertex*) lc_col->getElementAt(i); + plcio::Vertex pl_var = (plcio::Vertex) pl_col->create(); + + // Quest: data.primary is an int value, set by boolean number; + pl_var.setPrimary( lc_var->isPrimary() ); + pl_var.setChi2( lc_var->getChi2() ); + pl_var.setProbability( lc_var->getProbability() ); + + float plcio_v[3]; + const float* lcio_v = lc_var->getPosition(); + plcio_v[0] = lcio_v[0]; + plcio_v[1] = lcio_v[1]; + plcio_v[2] = lcio_v[2]; + pl_var.setPosition( plcio::FloatThree(plcio_v) ); + + std::vector<float> vec_pra = lc_var->getParameters(); + for( unsigned j=0,M=vec_pra.size(); j<M; j++){ + pl_var.addParameter(vec_pra[j]); + } + + // convert string into int(type code); +// pl_var.setAlgorithmType( lc_var->getAlgorithmType() ); +// pl_var.setCovMatrix( lc_var->() ); +// pl_var.setAssociatedParticle( lc_var->() ); + } + return pl_col; +} + +podio::CollectionBase* LCIO2Plcio::Convertor_TPCHit(EVENT::LCCollection* lc_col){ + plcio::TPCHitCollection* pl_col = new plcio::TPCHitCollection(); + + for( unsigned i=0,N=lc_col->getNumberOfElements() ; i< N ; ++i){ + EVENT::TPCHit* lc_var = (EVENT::TPCHit*) lc_col->getElementAt(i); + plcio::TPCHit pl_var = (plcio::TPCHit) pl_col->create(); + + pl_var.setCellID(lc_var->getCellID()); + pl_var.setTime(lc_var->getTime()); + pl_var.setCharge(lc_var->getCharge()); + pl_var.setQuality(lc_var->getQuality()); + + for( unsigned j=0,M=lc_var->getNRawDataWords(); j<M; j++){ + pl_var.addRawDataWord(lc_var->getRawDataWord(j)); + } + } + return pl_col; +} + bool LCIO2Plcio::isReady(const std::string& TypeName){ if( TypeName == "SimTrackerHit" ){ std::vector<std::string>::iterator it = find( diff --git a/FWCore/src/components/LCIO2Plcio.h b/FWCore/src/components/LCIO2Plcio.h index 799f864e..a72aedf0 100644 --- a/FWCore/src/components/LCIO2Plcio.h +++ b/FWCore/src/components/LCIO2Plcio.h @@ -9,15 +9,23 @@ #include "lcio.h" // #include "IO/LCReader.h" // #include "EVENT/LCCollection.h" -#include "EVENT/MCParticle.h" +#include "EVENT/Vertex.h" #include "EVENT/SimTrackerHit.h" -#include "EVENT/SimCalorimeterHit.h" #include "plcio/SimTrackerHit.h" #include "plcio/SimTrackerHitCollection.h" +#include "EVENT/SimCalorimeterHit.h" #include "plcio/SimCalorimeterHit.h" #include "plcio/SimCalorimeterHitCollection.h" +#include "EVENT/MCParticle.h" #include "plcio/MCParticle.h" #include "plcio/MCParticleCollection.h" +#include "plcio/VertexCollection.h" +#include "EVENT/TPCHit.h" +#include "plcio/TPCHit.h" +#include "plcio/TPCHitCollection.h" +#include "EVENT/Cluster.h" +#include "plcio/Cluster.h" +#include "plcio/ClusterCollection.h" #include <utility> // Forward declarations @@ -53,13 +61,13 @@ public: static podio::CollectionBase* Convertor_LCRunHeader(EVENT::LCCollection*); static podio::CollectionBase* Convertor_SimTrackerHit(EVENT::LCCollection*); static podio::CollectionBase* Convertor_SimCalorimeterHit(EVENT::LCCollection*); + static podio::CollectionBase* Convertor_Cluster(EVENT::LCCollection*); + static podio::CollectionBase* Convertor_Vertex(EVENT::LCCollection*); + static podio::CollectionBase* Convertor_TPCHit(EVENT::LCCollection*); - static void void_Core_MCParticle(EVENT::MCParticle*, plcio::MCParticle&); - static plcio::MCParticleCollection* Core_MCParticle(EVENT::LCCollection*); + static void setMCParticle(EVENT::MCParticle*, plcio::MCParticle&); bool isReady(const std::string&); - void setPlcioMCParticleCollection(plcio::MCParticleCollection*); - void setLCIOMCParticleCollection(EVENT::LCCollection*); private: std::string TypeName; -- GitLab