7 #include <EVENT/LCCollection.h>
8 #include <EVENT/Track.h>
9 #include <EVENT/Cluster.h>
10 #include <EVENT/SimCalorimeterHit.h>
11 #include <EVENT/CalorimeterHit.h>
12 #include <EVENT/SimTrackerHit.h>
13 #include <EVENT/TrackerHit.h>
14 #include <EVENT/ReconstructedParticle.h>
15 #include <EVENT/LCRelation.h>
16 #include <UTIL/LCRelationNavigator.h>
18 #include "UTIL/LCTOOLS.h"
21 #include "gearimpl/Vector3D.h"
27 #ifdef MARLIN_USE_AIDA
28 #include <marlin/AIDAProcessor.h>
29 #include <AIDA/AIDA.h>
33 using namespace lcio ;
34 using namespace marlin ;
43 typedef std::map< MCParticle* , int >
MCPMap ;
54 _description =
"links RecontructedParticles to the MCParticle based on number of hits used" ;
59 pdgVecDef.push_back( 22 ) ;
60 pdgVecDef.push_back( 111 ) ;
61 pdgVecDef.push_back( 310 ) ;
67 registerInputCollection( LCIO::MCPARTICLE,
68 "MCParticleCollection" ,
69 "Name of the MCParticle input collection" ,
71 std::string(
"MCParticle") ) ;
73 registerInputCollection( LCIO::TRACK,
75 "Name of the Tracks input collection" ,
77 std::string(
"MarlinTrkTracks") ) ;
79 registerInputCollection( LCIO::CLUSTER,
81 "Name of the Clusters input collection" ,
83 std::string(
"PandoraClusters") ) ;
85 registerInputCollection( LCIO::RECONSTRUCTEDPARTICLE,
86 "RecoParticleCollection" ,
87 "Name of the ReconstructedParticles input collection" ,
89 std::string(
"PandoraPFOs") ) ;
95 StringVec trackerHitsInputColNamesDefault ;
96 trackerHitsInputColNamesDefault.push_back(
"VXDCollection ");
97 trackerHitsInputColNamesDefault.push_back(
"SITCollection");
98 trackerHitsInputColNamesDefault.push_back(
"FTD_PIXELCollection");
99 trackerHitsInputColNamesDefault.push_back(
"FTD_STRIPCollection");
100 trackerHitsInputColNamesDefault.push_back(
"TPCCollection");
101 trackerHitsInputColNamesDefault.push_back(
"SETCollection");
103 registerInputCollections( LCIO::SIMTRACKERHIT,
104 "SimTrackerHitCollections" ,
105 "Names of the SimTrackerHits input collection" ,
107 trackerHitsInputColNamesDefault ) ;
109 registerProcessorParameter(
"UseTrackerHitRelations",
110 "true: use relations for TrackerHits, false : use getRawHits ",
115 StringVec trackerHitsRelInputColNamesDefault;
116 trackerHitsRelInputColNamesDefault.push_back(
"VXDTrackerHitRelations" );
117 trackerHitsRelInputColNamesDefault.push_back(
"SITSpacePointRelations" );
118 trackerHitsRelInputColNamesDefault.push_back(
"FTDPixelTrackerHitRelations" );
119 trackerHitsRelInputColNamesDefault.push_back(
"FTDSpacePointRelations" );
120 trackerHitsRelInputColNamesDefault.push_back(
"TPCTrackerHitRelations" );
121 trackerHitsRelInputColNamesDefault.push_back(
"SETSpacePointRelations" );
124 registerInputCollections(
"LCRelation",
125 "TrackerHitsRelInputCollections",
126 "Name of the lcrelation collections, that link the TrackerHits to their SimTrackerHits.",
128 trackerHitsRelInputColNamesDefault );
135 caloHitsInputColNamesDefault.push_back(
"BeamCalCollection");
136 caloHitsInputColNamesDefault.push_back(
"EcalBarrelSiliconCollection");
137 caloHitsInputColNamesDefault.push_back(
"EcalBarrelSiliconPreShowerCollection");
138 caloHitsInputColNamesDefault.push_back(
"EcalEndcapRingCollection");
139 caloHitsInputColNamesDefault.push_back(
"EcalEndcapRingPreShowerCollection");
140 caloHitsInputColNamesDefault.push_back(
"EcalEndcapSiliconCollection");
141 caloHitsInputColNamesDefault.push_back(
"EcalEndcapSiliconPreShowerCollection");
142 caloHitsInputColNamesDefault.push_back(
"HcalBarrelRegCollection");
143 caloHitsInputColNamesDefault.push_back(
"HcalEndCapRingsCollection");
144 caloHitsInputColNamesDefault.push_back(
"HcalEndCapsCollection");
145 caloHitsInputColNamesDefault.push_back(
"LHcalCollection");
146 caloHitsInputColNamesDefault.push_back(
"LumiCalCollection");
147 caloHitsInputColNamesDefault.push_back(
"MuonBarrelCollection");
148 caloHitsInputColNamesDefault.push_back(
"MuonEndCapCollection");
150 registerInputCollections( LCIO::SIMCALORIMETERHIT,
151 "SimCaloHitCollections" ,
152 "Names of the SimCaloHits input collections" ,
154 caloHitsInputColNamesDefault ) ;
156 StringVec caloHitsRelInputColNamesDefault;
157 caloHitsRelInputColNamesDefault.push_back(
"RelationCaloHit" );
158 caloHitsRelInputColNamesDefault.push_back(
"RelationLcalHit" );
159 caloHitsRelInputColNamesDefault.push_back(
"RelationLHcalHit" );
160 caloHitsRelInputColNamesDefault.push_back(
"RelationBCalHit" ) ;
161 caloHitsRelInputColNamesDefault.push_back(
"RelationMuonHit" );
163 registerInputCollections(
"LCRelation",
164 "SimCalorimeterHitRelationNames" ,
165 "Name of the lcrelation collections, that link the SimCalorimeterHit to CalorimeterHit" ,
167 caloHitsRelInputColNamesDefault );
173 registerOutputCollection( LCIO::LCRELATION,
174 "MCTruthTrackLinkName" ,
175 "Name of the trackMCTruthLink output collection" ,
180 registerOutputCollection( LCIO::LCRELATION,
181 "TrackMCTruthLinkName" ,
182 "Name of the trackMCTruthLink output collection - not created if empty()" ,
187 registerOutputCollection( LCIO::LCRELATION,
188 "ClusterMCTruthLinkName" ,
189 "Name of the clusterMCTruthLink output collection - not created if empty()" ,
194 registerOutputCollection( LCIO::LCRELATION,
195 "MCTruthClusterLinkName" ,
196 "Name of the MCTruthClusterLink output collection" ,
201 registerProcessorParameter(
"FullRecoRelation",
202 "true: All reco <-> true relations are given, with weight = 10000*calo weight+"
203 "track weight (weights in permill). false: Only highest contributor linked,"
204 "and only to tracks, not clusters if there are any tracks",
209 registerOutputCollection( LCIO::LCRELATION,
210 "RecoMCTruthLinkName" ,
211 "Name of the RecoMCTruthLink output collection - not created if empty()" ,
213 std::string(
"RecoMCTruthLink") ) ;
215 registerOutputCollection( LCIO::LCRELATION,
216 "MCTruthRecoLinkName" ,
217 "Name of the MCTruthRecoLink output collection" ,
222 registerOutputCollection( LCIO::LCRELATION,
223 "CalohitMCTruthLinkName" ,
224 "Name of the updated calo-hit MCTruthLink output collection - not created if empty()" ,
231 registerProcessorParameter(
"KeepDaughtersPDG" ,
232 "PDG codes of particles of which the daughters will be "
233 "kept in the skimmmed MCParticle collection" ,
237 registerOutputCollection( LCIO::MCPARTICLE,
238 "MCParticlesSkimmedName" ,
239 "Name of the skimmed MCParticle output collection - not created if empty()" ,
246 registerProcessorParameter(
"daughtersECutMeV" ,
247 "energy cut for daughters that are kept from KeepDaughtersPDG" ,
253 registerProcessorParameter(
"SaveBremsstrahlungPhotons" ,
254 "save photons from Brems" ,
259 registerProcessorParameter(
"UsingParticleGun" ,
260 "If Using Particle Gun Ignore Gen Stat" ,
267 registerProcessorParameter(
"BremsstrahlungEnergyCut" ,
268 "energy cut for Brems that are kept" ,
273 registerProcessorParameter(
"InvertedNonDestructiveInteractionLogic" ,
274 "Work-around Mokka bug in vertex-is-not-endpoint-of-parent flag (logic inverted)" ,
287 printParameters<MESSAGE>() ;
289 for( IntVec::iterator it =
_pdgVec.begin() ; it !=
_pdgVec.end() ; ++it ){
293 streamlog_out( WARNING ) <<
" init: negative PDG given - only abs value is used : " << *it << std::endl ;
310 streamlog_out( WARNING ) <<
" ====== UseTrackerHitRelations=false => not using TrackerHit-SimTrackerHit-Relations but getRawHits() instead - \n"
311 <<
" this is probably not what you want (only for backward compatibility with very old files...)" << std::endl ;
330 streamlog_out( MESSAGE0 ) <<
" processEvent " << evt->getEventNumber() <<
" - " << evt->getRunNumber()
338 LCCollection* trackCol = 0 ;
339 LCCollection* ttrlcol = 0 ;
340 LCCollection* trtlcol = 0 ;
342 bool haveTracks = true ;
344 try{ trackCol = evt->getCollection(
_trackCollectionName ) ; }
catch(DataNotAvailableException&){ haveTracks=false ; }
348 <<
" not found - cannot create relation " << std::endl ;
353 trackLinker( evt, mcpCol , trackCol , &ttrlcol , &trtlcol);
363 LCCollection* clusterCol = 0 ;
365 bool haveClusters = true ;
366 bool haveCaloHitRel = true ;
368 LCCollection* ctrlcol = 0;
369 LCCollection* trclcol = 0;
370 LCCollection* chittrlcol = 0;
372 try{ clusterCol = evt->getCollection(
_clusterCollectionName ) ; }
catch(DataNotAvailableException&){ haveClusters= false ; }
374 if( ! haveClusters ) {
376 <<
" not found - cannot create relation " << std::endl ;
380 if( haveTracks && haveClusters ) {
383 &ctrlcol , &trclcol , &chittrlcol );
395 LCCollection* particleCol = 0 ;
396 bool haveRecoParticles = true ;
398 try { particleCol = evt->getCollection(
_recoParticleCollectionName ); }
catch(DataNotAvailableException&){ haveRecoParticles = false ; }
400 if( ! haveRecoParticles ) {
402 <<
" not found - cannot create relation " << std::endl ;
405 LCCollection* ptrlcol = 0;
406 LCCollection* trplcol = 0;
407 if( haveRecoParticles && haveTracks && haveClusters && haveCaloHitRel && !
_recoMCTruthLinkName.empty() ) {
409 particleLinker( mcpCol , particleCol, ttrlcol, ctrlcol, trtlcol, trclcol, &ptrlcol, &trplcol);
420 makeSkim( mcpCol , ttrlcol, ctrlcol , &skimVec );
422 if( streamlog_level(DEBUG5) ){
linkPrinter ( skimVec , particleCol, ptrlcol, trplcol ); }
443 LCCollection** ttrlcol, LCCollection** trtlcol) {
451 LCRelationNavigator trackTruthRelNav(LCIO::TRACK , LCIO::MCPARTICLE ) ;
455 LCRelationNavigator truthTrackRelNav(LCIO::MCPARTICLE , LCIO::TRACK ) ;
461 const LCCollection* col = 0 ;
464 for(
int j=0, jN= col->getNumberOfElements() ; j<jN ; ++j ) {
466 SimTrackerHit* simHit = (SimTrackerHit*) col->getElementAt( j ) ;
467 MCParticle* mcp = simHit->getMCParticle() ;
468 simHitMap[ mcp ] ++ ;
474 int nTrack = trackCol->getNumberOfElements() ;
478 streamlog_out( DEBUG6 ) <<
" *** Sorting out Track<->MCParticle using simHit<->MCParticle." << std::endl;
480 for(
int i=0;i<nTrack;++i){
482 Track* trk =
dynamic_cast<Track*
> ( trackCol->getElementAt(i) ) ;
492 const TrackerHitVec& trkHits = trk->getTrackerHits() ;
494 for( TrackerHitVec::const_iterator hitIt = trkHits.begin() ; hitIt != trkHits.end() ; ++hitIt ) {
496 TrackerHit* hit = * hitIt ;
499 MCParticle* mcp2 = 0;
500 for( LCObjectVec::const_iterator objIt = simHits.begin() ; objIt != simHits.end() ; ++objIt ) {
503 SimTrackerHit* simHit =
dynamic_cast<SimTrackerHit*
>( *objIt ) ;
505 MCParticle* mcp = simHit->getMCParticle() ;
506 if ( simHits.size() > 1 ) {
507 if ( mcp2 != 0 && mcp2 != mcp ) {
509 streamlog_out( DEBUG3 ) <<
" ghost/double " << mcp <<
" " << mcp2 <<
" " << hit->getCellID0() <<std::endl;
516 streamlog_out( WARNING ) <<
" tracker SimHit without MCParticle ?! " << std::endl ;
527 streamlog_out( WARNING ) <<
" No simulated tracker hits found. Set UseTrackerHitRelations to true in steering file to enable using TrackerHit relations if they are available." << std::endl ;
528 streamlog_out( WARNING ) << trk->id() <<
" " << i <<
" " << trk->getTrackerHits().size() << std::endl ;
530 for( TrackerHitVec::const_iterator hitIt = trkHits.begin() ; hitIt != trkHits.end() ; ++hitIt ) {
532 TrackerHit* hit = * hitIt ;
533 streamlog_out( WARNING ) << hit->getPosition()[0] <<
" " << hit->getPosition()[1] <<
" " << hit->getPosition()[2] <<
" " << std::endl ;
534 const LCObjectVec& simHits = *(this->
getSimHits(hit)) ;
535 streamlog_out( WARNING ) << simHits.size() << std::endl ;
545 MCParticle* mother = 0;
546 MCParticleVec theMCPs ;
547 theMCPs.reserve( 1000 ) ;
548 std::vector<int> MCPhits;
549 MCPhits.reserve( 1000 ) ;
552 for( MCPMap::iterator it = mcpMap.begin() ;
553 it != mcpMap.end() ; ++it ){
558 mother = ( it->first->getParents().size()!=0 ?
dynamic_cast<MCParticle*
>(it->first->getParents()[0]) : 0 ) ;
563 theMCPs.push_back( it->first ) ;
564 MCPhits.push_back( it->second ) ;
571 theMCPs.push_back(it->first);
572 MCPhits.push_back(it->second);
577 streamlog_out( WARNING ) <<
" track has hit(s) from a non-generator particle with no parents ?!! " << std::endl;
585 for (
unsigned ihit=0; ihit<trkHits.size(); ++ihit) {
586 if ( UTIL::BitSet32( trkHits[ihit]->getType() )[ UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT ]) {
596 for (
int iii=0 ; iii<ifound ; iii++ ) {
599 float weight = float(MCPhits[iii] )/float(nHit) ;
601 trackTruthRelNav.addRelation( trk , theMCPs[iii] , weight ) ;
603 int Total_SimHits_forMCP = simHitMap[ theMCPs[iii] ];
605 float inv_weight = float(MCPhits[iii] ) / Total_SimHits_forMCP ;
607 truthTrackRelNav.addRelation( theMCPs[iii] , trk , inv_weight ) ;
610 streamlog_out( DEBUG4 ) <<
" track " << trk->id() <<
" has " << MCPhits[iii] <<
" hits of "
611 << nSimHit <<
" SimHits ("
612 << nHit <<
" TrackerHits) "
613 <<
" weight = " << weight <<
" , "
614 <<
" inv rel weight = " << inv_weight <<
" "
615 <<
" of MCPart with pdg : " << theMCPs[iii]->getPDG()
616 <<
" , SimHits " << Total_SimHits_forMCP
617 <<
" and genstat : " << theMCPs[iii]->getGeneratorStatus()
618 <<
" id: " << theMCPs[iii]->id()
629 streamlog_out( DEBUG6 ) <<
" *** Sorting out Track<->MCParticle : DONE " << std::endl;
630 streamlog_out( DEBUG6 ) <<
" *** track linking complete, create collection " << std::endl;
632 *trtlcol = truthTrackRelNav.createLCCollection() ;
633 *ttrlcol = trackTruthRelNav.createLCCollection() ;
640 LCCollection** ctrlcol, LCCollection** trclcol,LCCollection** chittrlcol) {
647 LCRelationNavigator clusterTruthRelNav(LCIO::CLUSTER , LCIO::MCPARTICLE ) ;
648 LCRelationNavigator truthClusterRelNav( LCIO::MCPARTICLE , LCIO::CLUSTER ) ;
649 LCRelationNavigator chitTruthRelNav(LCIO::CALORIMETERHIT , LCIO::MCPARTICLE ) ;
657 streamlog_out( DEBUG6 ) <<
" *** Sorting out simHit<->MCParticle connections, and find corresponding calo hits " << std::endl;
684 const LCCollection* col = 0 ;
688 streamlog_out( DEBUG6 ) << std::endl;
689 streamlog_out( DEBUG6 ) <<
" ================= " << std::endl;
691 << col->getNumberOfElements() <<
" hits " << std::endl;
694 for(
int j=0, jN= col->getNumberOfElements() ; j<jN ; ++j ) {
696 SimCalorimeterHit* simHit = (SimCalorimeterHit*) col->getElementAt( j ) ;
698 if ( caloHits.size() == 0 ) { continue ;}
699 if ( caloHits.size() != 1 ) { streamlog_out( DEBUG9 ) <<
" Sim hit with nore than one calo hit ? " << std::endl; }
701 CalorimeterHit* caloHit =
dynamic_cast<CalorimeterHit*
>(caloHits[0]);
705 for (
size_t jk=0; jk<caloHits.size(); jk++) {
706 allRecoEn+= ((CalorimeterHit*) caloHits[jk])->getEnergy();
708 double calib_factor = allRecoEn/simHit->getEnergy();
710 streamlog_out( DEBUG4 ) << std::endl;
711 streamlog_out( DEBUG4 ) <<
" ================= " << std::endl;
712 streamlog_out( DEBUG4 ) <<
" Treating hit " << j <<
" sim hit id " << simHit->id() <<
" calo hit id "
713 << caloHit->id() <<
" nb contributions " << simHit->getNMCContributions() << std::endl;
714 streamlog_out( DEBUG3 ) <<
" ncalo hits : " << caloHits.size() <<
" calib factor " << calib_factor
715 <<
" position " << simHit->getPosition()[0] <<
" " <<
716 simHit->getPosition()[1] <<
" " <<
717 simHit->getPosition()[2] <<
" " << std::endl;
719 for(
int k=0;
k<simHit->getNMCContributions() ;
k++){
720 MCParticle* mcp = simHit->getParticleCont(
k ) ;
722 streamlog_out( DEBUG2 ) <<
" a calo hit to treat " << std::endl;
727 streamlog_out( DEBUG6 ) <<
" collection nb " << i <<
" nhits " << jN <<
" hit " << j <<
" contr " <<
k << std::endl;
728 streamlog_out( DEBUG6 ) <<
" Sim hit with no mcp. N contrib is " <<
729 simHit->getNMCContributions() <<std::endl;
730 streamlog_out( DEBUG6 ) <<
" Hit Position: " << simHit->getPosition()[0] <<
" " <<
731 simHit->getPosition()[1] <<
" " <<
732 simHit->getPosition()[2] <<
" " << std::endl;
733 if ( simHit->getNMCContributions() > 0 ) {
734 for (
int l=0;l<simHit->getNMCContributions() ;l++){
735 streamlog_out( DEBUG6 ) <<
" Contrib " << l <<
" : " <<std::endl;
736 streamlog_out( DEBUG6 ) <<
" Energy: " << simHit->getEnergyCont(l) <<std::endl;
737 streamlog_out( DEBUG6 ) <<
" PDG: " << simHit->getPDGCont(l) <<std::endl;
738 streamlog_out( DEBUG6 ) <<
" MCPart: " << simHit->getParticleCont(l) <<std::endl;
747 double e = simHit->getEnergyCont(
k ) * calib_factor;
749 streamlog_out( DEBUG3 ) <<
" initial true contributor "<<
k <<
" id " << mcp->id()
750 <<
" (with E = " << mcp->getEnergy() <<
" and pdg " << mcp->getPDG() <<
" ) e hit: " << e <<std::endl;
752 if ( remap_as_you_go.find(mcp) != remap_as_you_go.end() ) {
754 mcp=remap_as_you_go.find(mcp)->second;
755 streamlog_out( DEBUG3 ) <<
" Hit " << simHit->id() <<
" / "
756 << caloHit->id() <<
" attributed to " << mcp->id() <<
757 " because it's origin mcp has already been treated : originator case 0 " <<std::endl;
759 MCParticle* mother = 0;
760 MCParticle* this_Kid = mcp ;
763 if ( mcp-> getGeneratorStatus() == 0 && ( mcp->getParents().empty() == false ) ) {
793 streamlog_out( DEBUG2 ) <<
" simHit " <<simHit->id()<<
","<< j <<
794 " not created by generator particle. backtracking ..."
796 streamlog_out( DEBUG2 ) <<
" "<<mcp->id()<<
" gs "<<mcp->getGeneratorStatus()<<
797 " dint "<<mcp->isDecayedInTracker()<<
798 " bs "<<mcp->isBackscatter()<<
799 " ndi "<<mcp->vertexIsNotEndpointOfParent()<<
800 " npar "<<mcp->getParents().size()<<
801 " pdg "<<mcp->getPDG()<<
802 " "<< mcp->getVertex()[0]<<
803 " "<<mcp->getVertex()[1]<<
804 " "<<mcp->getVertex()[2]<<
805 " "<< mcp->getEndpoint()[0]<<
806 " "<<mcp->getEndpoint()[1]<<
807 " "<<mcp->getEndpoint()[2]<<std::endl;
811 mother=
dynamic_cast<MCParticle*
>(mcp->getParents()[0]);
814 if ( !this_Kid->isBackscatter() && mother!= 0 &&
815 mother->getParents().size()>0 &&
816 mother->getGeneratorStatus() ==0 &&
817 !mother->isDecayedInTracker() ) {
819 streamlog_out( DEBUG2 ) <<
" goes into originator loop " << std::endl;
821 while ( !this_Kid->isBackscatter() && mother!= 0 && mother->getParents().size()>0 &&
822 mother->getGeneratorStatus() ==0 &&
823 !mother->isDecayedInTracker() ) {
829 streamlog_out( DEBUG1 ) <<
" in originator loop " << std::endl;
832 MCParticle* oma=
dynamic_cast<MCParticle*
>(mother->getParents()[0]);
833 if ( oma->isDecayedInTracker() ) {
834 streamlog_out( DEBUG1 ) <<
" break out : gandmother "<<oma->id()<<
835 " gs "<<oma->getGeneratorStatus()<<
836 " dint "<<oma->isDecayedInTracker()<<
837 " bs "<<oma->isBackscatter()<<
838 " ndi "<<oma->vertexIsNotEndpointOfParent()<<
839 " npar "<<oma->getParents().size()<<
840 " pdg "<<oma->getPDG()<<std::endl;
845 mother=
dynamic_cast<MCParticle*
>(mother->getParents()[0]);
847 streamlog_out( DEBUG1 ) <<
" shower-part mother "<<mother->id()<<
848 " gs "<<mother->getGeneratorStatus()<<
849 " dint "<<mother->isDecayedInTracker()<<
850 " bs "<<mother->isBackscatter()<<
851 " ndi "<<mother->vertexIsNotEndpointOfParent()<<
852 " npar "<<mother->getParents().size()<<
853 " pdg "<<mother->getPDG()<<std::endl;
870 if (this_Kid->isBackscatter() ) {
874 remap_as_you_go[mcp]=this_Kid;
876 streamlog_out( DEBUG3 ) <<
" Hit " << simHit->id() <<
" / "
877 << caloHit->id() <<
" attributed to kid " << mcp->id() <<
878 " because it's origin is a back-scatter : originator case 2 " <<std::endl;
879 streamlog_out( DEBUG2 ) <<
" "<<this_Kid->id()<<
880 " gs "<<this_Kid->getGeneratorStatus()<<
881 " dint "<<this_Kid->isDecayedInTracker()<<
882 " bs "<<this_Kid->isBackscatter()<<
883 " npar "<<this_Kid->getParents().size()<<
884 " pdg "<<this_Kid->getPDG()<<std::endl;
887 }
else if ( mother->isDecayedInTracker() ) {
888 remap_as_you_go[mcp]=this_Kid;
893 streamlog_out( DEBUG3 ) <<
" Hit " << simHit->id() <<
" / "
894 << caloHit->id() <<
" attributed to kid " << mcp->id() <<
895 " because it's origin is in tracker : originator case 3 " <<std::endl;
903 streamlog_out( WARNING ) <<
" MCparticle " << this_Kid->id() <<
904 " is a simulation particle, created in the calorimeter by nothing . "<< std::endl;
907 remap_as_you_go[mcp]=this_Kid;
926 remap_as_you_go[mcp]=mother;
930 streamlog_out( DEBUG3 ) <<
" Hit " << simHit->id() <<
" / "
931 << caloHit->id() <<
" attributed to mother " << mcp->id() <<
932 " because it is a generator particle or started in tracker : originator case 4 " <<std::endl;
952 int starts_in_tracker = 0 ;
959 for (
unsigned kkk=0 ; kkk < mother->getDaughters().size() ; kkk++ ) {
960 MCParticle* sister =
dynamic_cast<MCParticle*
>(mother->getDaughters()[kkk]);
961 if ( sister == this_Kid )
continue;
962 if ( abs(sister->getVertex()[0]-this_Kid->getVertex()[0]) > 0.1 ||
963 abs(sister->getVertex()[1]-this_Kid->getVertex()[1]) > 0.1 ||
964 abs(sister->getVertex()[2]-this_Kid->getVertex()[2]) > 0.1 )
continue;
967 if ( sister->isBackscatter()) {
971 }
else if ( sister->isDecayedInTracker() ) {
972 starts_in_tracker = 1 ;
979 if ( sister->getPDG() == 111 ) {
984 if ( starts_in_tracker != 1 && has_bs != 1 && has_pi0 != 1 && oma_in_calo != 1 ) {
985 rdist=sqrt(pow(mother->getEndpoint()[0]-this_Kid->getVertex()[0],2)+
986 pow(mother->getEndpoint()[1]-this_Kid->getVertex()[1],2)+
987 pow(mother->getEndpoint()[2]-this_Kid->getVertex()[2],2));
988 if ( mother->getParents().size() != 0 ) {
989 MCParticle* oma=
dynamic_cast<MCParticle*
>(mother->getParents()[0]);
990 if ( oma->isDecayedInCalorimeter() ) {
992 streamlog_out( DEBUG1 ) <<
" grandmother in calo " << std::endl;
996 streamlog_out( DEBUG1 ) <<
" " << starts_in_tracker <<
" " << has_pi0 <<
" " << has_bs <<
" " << oma_in_calo << std::endl;
998 if ( starts_in_tracker == 1 ) {
1000 remap_as_you_go[mcp]=this_Kid;
1004 streamlog_out( DEBUG3 ) <<
" Hit " << simHit->id() <<
" / "
1005 << caloHit->id() <<
" attributed to kid " << mcp->id() <<
1006 " because it's origin could be deduced to be in tracker : originator case 5 " <<std::endl;
1008 streamlog_out( DEBUG2 ) <<
" Details of case 5: "
1009 << this_Kid->getVertex()[0] <<
" "
1010 << this_Kid->getVertex()[1] <<
" " << this_Kid->getVertex()[2] <<
" "
1011 << mother->getEndpoint()[0] <<
" "
1012 << mother->getEndpoint()[1] <<
" " << mother->getEndpoint()[2] <<
" "
1013 << mother->getGeneratorStatus() <<
" "
1014 << this_Kid->vertexIsNotEndpointOfParent() << std::endl;
1015 streamlog_out( DEBUG1 ) <<
" starts in tracker " << std::endl;
1017 }
else if ( has_pi0 != 0 || has_bs != 0 || oma_in_calo != 0 ) {
1023 remap_as_you_go[mcp]=mother;
1027 streamlog_out( DEBUG3 ) <<
" Hit " << simHit->id() <<
" / "
1028 << caloHit->id() <<
" attributed to mother " << mcp->id() <<
1029 " because it's origin could be deduced to be in tracker : originator case 6 " <<std::endl;
1030 streamlog_out( DEBUG2 ) <<
" Case 6 details: kid starts in calo " <<
" "
1031 << this_Kid->getVertex()[1] <<
" " << this_Kid->getVertex()[2] <<
" " << rdist <<
" "
1032 << has_pi0 <<
" " << has_bs <<
" " << oma_in_calo << std::endl;
1042 if ( rdist > 200. ) {
1044 remap_as_you_go[mcp]=this_Kid;
1047 streamlog_out( DEBUG3 ) <<
" Hit " << simHit->id() <<
" / "
1048 << caloHit->id() <<
" attributed to kid " << mcp->id() <<
1049 " because it's origin is guessed to be in tracker : originator case 7 " <<std::endl;
1050 streamlog_out( DEBUG2 ) <<
" Case 7 details: guess kid starts in tracker " <<
" "
1051 << this_Kid->getVertex()[1] <<
" " << this_Kid->getVertex()[2] <<
" " << rdist <<
" "
1052 << has_pi0 <<
" " << std::endl;
1055 remap_as_you_go[mcp]=mother;
1058 streamlog_out( DEBUG3 ) <<
" Hit " << simHit->id() <<
" / "
1059 << caloHit->id() <<
" attributed to mother " << mcp->id() <<
1060 " because it's origin is guessed in tracker : originator case 8 " <<std::endl;
1061 streamlog_out( DEBUG2 ) <<
" Case 8 details: guess kid starts in calo " <<
" "
1062 << this_Kid->getVertex()[1] <<
" " << this_Kid->getVertex()[2] <<
" " << rdist <<
" "
1063 << has_pi0 <<
" " << std::endl;
1074 streamlog_out( DEBUG3 ) <<
" Hit " << simHit->id() <<
" / "
1075 << caloHit->id() <<
" attributed to " << mcp->id() <<
1076 " because it's origin is a generator particle : originator case 1 " <<std::endl;
1078 remap_as_you_go[mcp]=mcp;
1082 streamlog_out( DEBUG4 ) <<
" Final assignment for contribution " <<
k <<
" to " << simHit->id() <<
" / "
1083 << caloHit->id() <<
" : " << mcp->id() << std::endl;
1084 streamlog_out( DEBUG4 ) <<
" gs "<<mcp->getGeneratorStatus()<<
1085 " dint "<<mcp->isDecayedInTracker()<<
1086 " bs "<<mcp->isBackscatter()<<
1087 " npar "<<mcp->getParents().size()<<
1088 " pdg "<<mcp->getPDG()<<
1089 " "<<mcp->getEndpoint()[0]<<
1090 " "<<mcp->getEndpoint()[1]<<
1091 " "<<mcp->getEndpoint()[2]<<std::endl;
1096 simHitMapEnergy[ mcp ] +=
e ;
1098 for (
size_t jk=0; jk<caloHits.size(); jk++) {
1099 chitTruthRelNav.addRelation( caloHits[jk] , mcp , e*( (CalorimeterHit*) caloHits[jk])->getEnergy()/allRecoEn ) ;
1107 streamlog_out( DEBUG6 ) <<
" *** Sorting out simHit<->MCParticle connections : DONE " << std::endl;
1108 streamlog_out( DEBUG6 ) <<
" *** Sorting out Cluster<->MCParticle using simHit<->MCParticle, re-assigning the latter in some rare cases." << std::endl;
1112 int nCluster = clusterCol->getNumberOfElements() ;
1114 streamlog_out( DEBUG6 ) << std::endl;
1115 streamlog_out( DEBUG6 ) <<
" ================= " << std::endl;
1116 streamlog_out( DEBUG6 ) <<
" Treating clusters. There are "<< nCluster <<
" of them " << std::endl;
1118 std::vector<Cluster*> missingMC ;
1119 missingMC.reserve( nCluster ) ;
1124 MCParticle* mother = 0;
1129 for(
int i=0;i<nCluster;i++){
1133 Cluster* clu =
dynamic_cast<Cluster*
> ( clusterCol->getElementAt(i) ) ;
1148 const CalorimeterHitVec& cluHits = clu->getCalorimeterHits() ;
1150 streamlog_out( DEBUG5 ) << std::endl;
1151 streamlog_out( DEBUG5 ) <<
" ================= " << std::endl;
1152 streamlog_out( DEBUG5 ) <<
"Cluster clu = "<< clu->id() <<
" (i = " << i <<
" ) with " << cluHits.size() <<
" hits " << std::endl;
1154 double ecalohitsum=0.;
1155 double ecalohitsum_unknown=0.;
1157 for( CalorimeterHitVec::const_iterator hitIt = cluHits.begin() ;
1158 hitIt != cluHits.end() ; ++hitIt ) {
1161 CalorimeterHit* hit = * hitIt ;
1162 ecalohitsum+= hit->getEnergy();
1165 const LCObjectVec& simHits = *(this->
getCaloHits(hit)) ;
1167 streamlog_out( DEBUG4 ) << std::endl;
1168 streamlog_out( DEBUG4 ) <<
" Treating hit = "<< hit->id() <<
" e " << hit->getEnergy()<<
" nb sim hits : " <<
1169 simHits.size() << std::endl;
1173 for( LCObjectVec::const_iterator objIt = simHits.begin() ;
1174 objIt != simHits.end() ; ++objIt ){
1176 SimCalorimeterHit* simHit =
dynamic_cast<SimCalorimeterHit*
>( *objIt ) ;
1178 double calib_factor = hit->getEnergy()/simHit->getEnergy();
1180 streamlog_out( DEBUG3 ) <<
" simhit = "<< simHit->id() <<
" has " << simHit->getNMCContributions()
1181 <<
" contributors " << std::endl;
1184 for(
int j=0;j<simHit->getNMCContributions() ;j++){
1186 MCParticle* mcp = simHit->getParticleCont( j ) ;
1187 double e = simHit->getEnergyCont( j ) * calib_factor ;
1188 streamlog_out( DEBUG3 ) <<
" true contributor = "<< mcp->id() <<
" e: " << e
1189 <<
" mapped to " <<remap_as_you_go.find(mcp)->second->id() << std::endl;
1191 streamlog_out( DEBUG7 ) <<
" simhit = "<< simHit <<
" has no creator " <<std::endl;
1196 mcp=remap_as_you_go.find(mcp)->second;
1197 mcpEnergy[ mcp ] +=
e ;
1203 streamlog_out( DEBUG4 )<<
" summed contributed e: " << ehit <<
" ratio : " << ehit/hit->getEnergy()
1204 <<
" nsimhit " << nsimhit <<std::endl;
1205 if ( nsimhit == 0 ) {
1207 streamlog_out( DEBUG5 ) <<
" Warning: no simhits for calohit " << hit <<
1208 ". Will have to guess true particle ... " << std::endl;
1210 ecalohitsum_unknown+= hit->getEnergy();
1211 streamlog_out( DEBUG5 )<<
" sim-less calohit E and position " << hit->getEnergy() <<
" "
1212 << hit->getPosition()[0] <<
" " << hit->getPosition()[1] <<
" " << hit->getPosition()[2] <<
" " << std::endl;
1213 streamlog_out( DEBUG5 )<<
" sim-less calohit clust E and position " << clu->getEnergy()
1214 <<
" "<< clu->getPosition()[0] <<
" " << clu->getPosition()[1] <<
" " << clu->getPosition()[2] <<
" " << std::endl;
1217 if ( no_sim_hit == 1 ) {
1218 streamlog_out( DEBUG6 ) <<
" Warning, there are sim-less calohits in cluster " << clu->id() << std::endl;
1220 streamlog_out( DEBUG5 ) << std::endl;
1221 streamlog_out( DEBUG5 ) <<
" Sum of calohit E: " << ecalohitsum <<
" cluster E "
1222 << clu->getEnergy() <<
" Sum of Simcalohit E: " << eTot
1223 <<
" no_sim_hit: " << no_sim_hit <<
". Energy from unknow source : "
1224 << ecalohitsum_unknown << std::endl;
1229 missingMC.push_back( clu ) ;
1231 streamlog_out( DEBUG8 ) <<
" no calorimeter hits found for "
1232 <<
" cluster " << clu->id() <<
" e:" << clu->getEnergy()
1257 MCParticleVec theMCPs ;
1259 theMCPs.reserve(1000);
1260 std::vector<double> MCPes;
1261 MCPes.reserve(1000);
1264 MCParticleVec moreMCPs ;
1266 moreMCPs.reserve(1000);
1267 std::vector<double>moreMCPes;
1268 moreMCPes.reserve(1000);
1273 for( MCPMapDouble::iterator it = mcpEnergy.begin() ;
1274 it != mcpEnergy.end() ; ++it ){
1275 if ( it->first == 0 ) {
1277 streamlog_out( MESSAGE ) <<
" SimHit with unknown origin in cluster " << clu <<
" ( " << clu->id() <<
" ) " << std::endl;
1281 if (it->first->getGeneratorStatus() == 1 ) {
1285 theMCPs.push_back(it->first); MCPes.push_back(it->second); ifound++;
1287 if ( it->first->getParents().size() != 0 ) {
1288 mother=
dynamic_cast<MCParticle*
>(it->first->getParents()[0]);
1292 if ( mother != 0 ) {
1293 if ( mother->isDecayedInTracker() &&
1299 theMCPs.push_back(it->first); MCPes.push_back(it->second); ifound++;
1302 streamlog_out( DEBUG2 ) <<
" case 1 for "<< it->first->id() <<
1303 "(morefound=" << morefound <<
")" <<
1304 " mother: " << mother->id() <<
1305 " gs " <<mother->getGeneratorStatus()<<
1306 " dint " << mother->isDecayedInTracker() <<
1307 " bs " << mother->isBackscatter() <<
1308 " pdg " <<mother->getPDG() <<std::endl;
1309 if ( mother->isBackscatter() == 1 ) {
1310 moreMCPs.push_back(it->first); moreMCPes.push_back(it->second); morefound++;
1312 theMCPs.push_back(it->first); MCPes.push_back(it->second); ifound++;
1316 streamlog_out( DEBUG6 ) <<
" case 2 for "<< it->first->id() <<
1317 "(morefound=" << morefound <<
")" << std::endl;
1318 moreMCPs.push_back(it->first); moreMCPes.push_back(it->second); morefound++;
1323 if( it->second > eMax ){
1334 if ( morefound > 0 ) {
1335 for (
int iii=0 ; iii<morefound ; iii++ ) {
1336 streamlog_out( DEBUG2 ) <<
" iii, moreMCPes[iii], moreMCPs[iii], gs " << iii <<
1337 " "<< moreMCPes[iii] <<
1338 " "<< moreMCPs[iii]->id()<<
1339 " "<<moreMCPs[iii]->getGeneratorStatus() << std::endl;
1341 for (
int iii=0 ; iii<ifound ; iii++ ) {
1342 streamlog_out( DEBUG2 ) <<
" iii, MCPes[iii], theMCPs[iii] " << iii <<
1343 " "<< MCPes[iii] <<
" "<< theMCPs[iii]->id() << std::endl;
1345 streamlog_out( DEBUG3 )<<
" morefond: " << morefound <<std::endl;
1359 for (
int iii=0 ; iii<morefound ; iii++ ) {
1360 if ( moreMCPs[iii]->getParents().size() != 0 ) {
1361 mother=
dynamic_cast<MCParticle*
>(moreMCPs[iii]->getParents()[0]);
1362 streamlog_out( DEBUG2 ) <<
" iii: " << iii <<
" mother: " << mother->id() <<std::endl;
1366 streamlog_out( DEBUG2 ) <<
" partic vert: "<<moreMCPs[iii]->getVertex()[0]<<
1367 " "<<moreMCPs[iii]->getVertex()[1]<<
1368 " "<<moreMCPs[iii]->getVertex()[2]<<std::endl;
1369 streamlog_out( DEBUG2 ) <<
" partic endpoint: "<<moreMCPs[iii]->getEndpoint()[0]<<
1370 " "<<moreMCPs[iii]->getEndpoint()[1]<<
1371 " "<<moreMCPs[iii]->getEndpoint()[2]<<std::endl;
1372 streamlog_out( DEBUG2 ) <<
" partic status : gs "<<moreMCPs[iii]->getGeneratorStatus()<<
1373 " dint "<<moreMCPs[iii]->isDecayedInTracker ()<<
1374 " bs "<<moreMCPs[iii]->isBackscatter ()<<
1375 " npar "<<moreMCPs[iii]->getParents().size()<<
1376 " pdg " << moreMCPs[iii]->getPDG() <<
1377 " dinc "<<moreMCPs[iii]->isDecayedInCalorimeter ()<<
1378 " bye "<<moreMCPs[iii]->hasLeftDetector () <<
1379 " stop "<<moreMCPs[iii]->isStopped () << std::endl;
1381 while ( mother!= 0 && mother->getGeneratorStatus() !=2 ) {
1384 streamlog_out( DEBUG2 ) <<
" mother "<< mother->id() <<
1385 " gs " << mother->getGeneratorStatus() <<
1386 " dint " << mother->isDecayedInTracker()<<
" " <<
1387 " bs " << mother->isBackscatter()<<
1388 " pdg " << mother->getPDG() <<
1389 " dinc " <<mother->isDecayedInCalorimeter()<< std::endl;
1390 streamlog_out( DEBUG2 ) <<
" mother vert: "<<mother->getVertex()[0]<<
1391 " "<<mother->getVertex()[1]<<
1392 " "<<mother->getVertex()[2]<<std::endl;
1393 streamlog_out( DEBUG2 ) <<
" mother endpoint: "<<mother->getEndpoint()[0]<<
1394 " "<<mother->getEndpoint()[1]<<
1395 " "<<mother->getEndpoint()[2]<<std::endl;
1402 for (
int kkk=0 ; kkk<ifound ; kkk++){
1403 MCParticle* tmcp = theMCPs[kkk];
1404 if ( tmcp == mother ) {
1406 streamlog_out( DEBUG3 ) <<
" found " << moreMCPs[iii] <<
1407 "(iii= "<<iii <<
")" << kkk <<
1408 " to be related to "<<mother->id() <<
1409 " add e : " << moreMCPes[iii] << std::endl;
1410 LCObjectVec hitvec = chitTruthRelNav.getRelatedFromObjects(moreMCPs[iii]);
1411 FloatVec evec=chitTruthRelNav.getRelatedFromWeights(moreMCPs[iii]);
1412 int one_mod_done = 0;
1413 for (
unsigned lll=0 ; lll<hitvec.size() ; lll++ ) {
1414 CalorimeterHit* hit =
dynamic_cast<CalorimeterHit*
>(hitvec[lll]);
1415 for( CalorimeterHitVec::const_iterator hitIt = cluHits.begin() ;
1416 hitIt != cluHits.end() ; ++hitIt ) {
1417 if ( *hitIt == hit ) {
1418 chitTruthRelNav.removeRelation( hit ,moreMCPs[iii] );
1419 chitTruthRelNav.addRelation( hit , mother , evec[lll] ) ;
1426 if ( one_mod_done == 1 ) {
1427 MCPes[kkk]+= moreMCPes[iii];
1430 streamlog_out( DEBUG3 ) <<
" However, no hits related to the current cluster found ??" << std::endl;
1435 if ( mother->getParents().size() != 0 ) {
1437 mother=
dynamic_cast<MCParticle*
>(mother->getParents()[0]);
1438 }
else { mother = 0; }
1441 if ( mother == 0 || mother->getGeneratorStatus() ==2 ) {
1447 streamlog_out( DEBUG3 ) <<
" No relation found for "<< moreMCPs[iii]->id() <<
1448 ". Keep it as separate originator "<< std::endl;
1449 theMCPs.push_back(moreMCPs[iii]); MCPes.push_back(moreMCPes[iii]); ifound++;
1453 streamlog_out( DEBUG5 ) <<
" cluster " << clu->id() <<
" , E = " << clu->getEnergy() <<
" , ifound = " << ifound << std::endl;
1459 for (
int iii=0 ; iii<ifound ; iii++ ) {
1460 float weight = (MCPes[iii]/eTot)*(clu->getEnergy()-ecalohitsum_unknown)/clu->getEnergy();
1461 mcpEnergyTot[ theMCPs[iii] ] += weight*clu->getEnergy();
1464 if( theMCPs[iii] == 0 ) {
1466 streamlog_out( ERROR ) <<
" cluster " <<clu->id() <<
" has " << MCPes[iii] <<
" GeV of " << eTot
1467 <<
" GeV [ " << weight <<
" ] true energy "
1468 <<
" but no MCParticle " << std::endl ;
1474 streamlog_out( DEBUG5 ) <<
" cluster " <<clu->id() <<
" has " << MCPes[iii] <<
" of " << eTot
1475 <<
" [ " << weight <<
" ] "
1476 <<
" of MCParticle " << theMCPs[iii]->id() <<
" with pdg : " << theMCPs[iii]->getPDG()
1477 <<
" and genstat : " << theMCPs[iii]->getGeneratorStatus()
1481 if ( theMCPs[iii]->getGeneratorStatus() == 0 && ( theMCPs[iii]->getParents().empty() ==
false) ) {
1482 streamlog_out( DEBUG5 ) <<
" mother id " << theMCPs[iii]->getParents()[0]->id()
1484 << theMCPs[iii]->getParents()[0]->getGeneratorStatus() << std::endl ;
1489 clusterTruthRelNav.addRelation( clu , theMCPs[iii] , weight ) ;
1494 weight=(MCPes[iii]/simHitMapEnergy[theMCPs[iii]]);
1495 truthClusterRelNav.addRelation( theMCPs[iii] , clu , weight ) ;
1501 streamlog_out( DEBUG6 ) <<
" *** Sorting out Cluster<->MCParticle : DONE" << std::endl;
1502 streamlog_out( DEBUG6 ) <<
" *** Guessing Cluster<->MCParticle in cases where MCParticle<->simHit is broken (LCAL/DBD)" << std::endl;
1509 for(
unsigned i=0 ; i < missingMC.size() ; ++i ) {
1511 int nMCP = mcpCol->getNumberOfElements() ;
1513 Cluster* clu = missingMC[i] ;
1516 gear::Vector3D recP( clu->getPosition()[0] , clu->getPosition()[1] ,
1517 clu->getPosition()[2] ) ;
1519 double recTheta = recP.theta() ;
1521 double maxProd = 0.0 ;
1522 MCParticle* closestMCP = 0 ;
1524 for (
int j=0; j< nMCP ; j++){
1526 MCParticle* mcp =
dynamic_cast<MCParticle*
> ( mcpCol->getElementAt( j ) ) ;
1528 if ( fabs( mcp->getCharge() ) > 0.01 ) {
1532 gear::Vector3D mcpP( mcp->getMomentum()[0] , mcp->getMomentum()[1] ,
1533 mcp->getMomentum()[2] ) ;
1535 if ( fabs( recTheta - mcpP.theta() ) > 0.3 ) {
1540 double prod = mcpP.unit().dot( recP.unit() ) ;
1542 if ( prod > maxProd ) {
1547 if ( maxProd > 0. ) {
1549 streamlog_out( DEBUG5 )
1550 <<
" neutral cluster particle recovered"
1552 <<
" maxProd: " << maxProd
1553 <<
" px: " << closestMCP->getMomentum()[0]
1554 <<
" py: " << closestMCP->getMomentum()[1]
1555 <<
" pz: " << closestMCP->getMomentum()[2]
1558 clusterTruthRelNav.addRelation( clu , closestMCP , 1.0 ) ;
1559 truthClusterRelNav.addRelation( closestMCP , clu , 1.0 ) ;
1580 streamlog_out( DEBUG6 ) <<
" *** Cluster linking complete, create collection " << std::endl;
1581 *trclcol = truthClusterRelNav.createLCCollection() ;
1582 *ctrlcol = clusterTruthRelNav.createLCCollection() ;
1583 *chittrlcol = chitTruthRelNav.createLCCollection() ;
1588 LCCollection* ttrlcol, LCCollection* ctrlcol,
1589 LCCollection* trtlcol, LCCollection* trclcol,
1590 LCCollection** ptrlcol, LCCollection** trplcol) {
1592 LCRelationNavigator particleTruthRelNav(LCIO::RECONSTRUCTEDPARTICLE , LCIO::MCPARTICLE ) ;
1593 LCRelationNavigator truthParticleRelNav( LCIO::MCPARTICLE , LCIO::RECONSTRUCTEDPARTICLE ) ;
1595 LCRelationNavigator trackTruthRelNav = LCRelationNavigator( ttrlcol );
1596 LCRelationNavigator clusterTruthRelNav = LCRelationNavigator( ctrlcol );
1597 LCRelationNavigator truthTrackRelNav = LCRelationNavigator( trtlcol );
1598 LCRelationNavigator truthClusterRelNav = LCRelationNavigator( trclcol );
1601 int nPart = particleCol->getNumberOfElements() ;
1604 static FloatVec www ;
1606 for(
int i=0;i<nPart;++i){
1608 std::map< MCParticle* , int > mcmap;
1610 MCParticle* mcmax =0;
1613 ReconstructedParticle* part =
dynamic_cast<ReconstructedParticle*
> ( particleCol->getElementAt(i) ) ;
1614 TrackVec tracks=part->getTracks();
1615 int ntrk = part->getTracks().size();
1616 ClusterVec clusters=part->getClusters();
1617 int nclu = part->getClusters().size();
1618 streamlog_out( DEBUG3 ) <<
" ======== " << std::endl;
1619 streamlog_out( DEBUG3 ) <<
" Treating particle " << part->id() <<
" with index " << i
1620 <<
" it has " << ntrk <<
" tracks, and " << nclu <<
" clusters " <<std::endl;
1626 for (
int j=0 ; j < ntrk ; j++ ) {
1628 for (
unsigned kkk=0 ;kkk<tracks[j]->getSubdetectorHitNumbers().size(); kkk++ ) {
1629 nhit[j]+= tracks[j]->getSubdetectorHitNumbers()[kkk];
1630 nhitT+= tracks[j]->getSubdetectorHitNumbers()[kkk];
1632 streamlog_out( DEBUG2 ) <<
" Track " << tracks[j]->id() <<
" with index " << j <<
" has " << nhit[j] <<
" hits " << std::endl;
1634 streamlog_out( DEBUG2 ) <<
" Total : " << nhitT <<
" hits " << std::endl;
1636 nhit[0]=1 ; nhitT=1;
1638 for (
int j=0 ; j < ntrk ; j++ ) {
1640 if ( tracks[j] != 0 ) {
1641 mcvec = trackTruthRelNav.getRelatedToObjects( tracks[j]);
1642 www = trackTruthRelNav.getRelatedToWeights( tracks[j]);
1643 int ntp= mcvec.size();
1644 streamlog_out( DEBUG3 ) <<
" Track " << tracks[j]->id() <<
" with index " << j
1645 <<
" has " << ntp <<
" true particles " << std::endl;
1647 if ( mcvec[0] != 0 ) {
1649 for (
int kkk=0 ; kkk < ntp ; kkk++ ) {
1651 maxwgt= www[kkk]*(float(nhit[j])/float(nhitT)) ;
1652 mcmax=
dynamic_cast<MCParticle*
>(mcvec[kkk]);
1654 mcmap[
dynamic_cast<MCParticle*
>(mcvec[kkk])] +=
1655 int(www[kkk]*1000.*(
float(nhit[j])/float(nhitT))+0.5);
1656 streamlog_out( DEBUG2 ) <<
" Individual track weight to " <<mcvec[kkk]<<
" is "
1657 << www[kkk] <<
", scaled one is "
1658 << www[kkk]*(float(nhit[j])/float(nhitT))
1659 <<
" ( loop -index : " << kkk <<
")"<< std::endl;
1670 for (
int j=0 ; j < nclu ; j++ ) {
1671 eclu[j] = clusters[j]->getEnergy();
1672 ecluT+=clusters[j]->getEnergy();
1673 streamlog_out( DEBUG2 ) <<
" Cluster " << clusters[j]->id() <<
" with index " << j <<
" has energy " << eclu[j] << std::endl;
1675 streamlog_out( DEBUG2 ) <<
" Total : " << ecluT << std::endl;
1677 eclu[0]=1 ; ecluT=1;
1679 for (
int j=0 ; j < nclu ; j++ ) {
1680 if ( clusters[j] != 0 ) {
1681 mcvec = clusterTruthRelNav.getRelatedToObjects(clusters[j]);
1682 www = clusterTruthRelNav.getRelatedToWeights(clusters[j]);
1683 int ntp= mcvec.size();
1684 streamlog_out( DEBUG3 ) <<
" Cluster " << clusters[j]->id() <<
" with index " << j
1685 <<
" has " << ntp <<
" true particles " << std::endl;
1687 if ( mcvec[0] != 0 ) {
1688 for (
int kkk=0 ; kkk < ntp ; kkk++ ) {
1690 maxwgt= www[kkk]*(eclu[j]/ecluT) ;
1691 mcmax=
dynamic_cast<MCParticle*
>(mcvec[kkk]);
1693 mcmap[
dynamic_cast<MCParticle*
>(mcvec[kkk])] +=
1694 int(www[kkk]*1000.*(eclu[j]/ecluT)+0.5)*10000;
1695 streamlog_out( DEBUG2 ) <<
" Individual cluster Weight to " <<mcvec[kkk]<<
" is "
1696 << www[kkk] <<
", scaled one is "
1697 << www[kkk]*(eclu[j]/ecluT)
1698 <<
" ( loop -index : " << kkk <<
")"<< std::endl;
1706 for ( std::map< MCParticle* , int >::iterator mcit = mcmap.begin() ;
1707 mcit != mcmap.end() ; mcit++ ) {
1710 streamlog_out( DEBUG4 ) <<
" particle " << part->id() <<
" has weight "<<mcit->second
1711 <<
" (Track: " << int(mcit->second)%10000
1712 <<
" , Cluster: " << int(mcit->second)/10000 <<
" ) "
1713 <<
" of MCParticle with pdg : " << mcit->first->getPDG()
1714 <<
" and genstat : " << mcit->first->getGeneratorStatus()
1715 <<
" id: " << mcit->first->id()
1718 particleTruthRelNav.addRelation( part , mcit->first , mcit->second ) ;
1721 if( mcmax != NULL ) {
1724 particleTruthRelNav.addRelation( part , mcmax , maxwgt ) ;
1725 streamlog_out( DEBUG3 ) <<
" particle " << part->id() <<
" has weight "<<maxwgt
1726 <<
" of MCParticle with pdg : " << mcmax->getPDG()
1727 <<
" and genstat : " << mcmax->getGeneratorStatus()
1728 <<
" id: " << mcmax->id()
1729 <<
". Particle charge and ntracks : " << part->getCharge()<<
" "<<ntrk
1732 streamlog_out( WARNING ) <<
" particle has weight "<< maxwgt
1733 <<
". Particle charge and ntracks : " << part->getCharge()<<
" "<<ntrk
1734 <<
" but no mcparticle found "
1743 LCObjectVec partvec;
1744 static FloatVec www_clu ;
1745 static FloatVec www_trk ;
1746 LCObjectVec cluvec_t;
1747 LCObjectVec trkvec_t;
1748 ClusterVec cluvec_p;
1750 int nMCP = mcpCol->getNumberOfElements() ;
1751 for(
int i=0;i< nMCP;i++){
1752 MCParticle* mcp =
dynamic_cast<MCParticle*
> ( mcpCol->getElementAt( i ) ) ;
1753 partvec = particleTruthRelNav.getRelatedFromObjects(mcp);
1754 cluvec_t = truthClusterRelNav.getRelatedToObjects(mcp);
1755 www_clu = truthClusterRelNav.getRelatedToWeights(mcp);
1756 trkvec_t = truthTrackRelNav.getRelatedToObjects(mcp);
1757 www_trk = truthTrackRelNav.getRelatedToWeights(mcp);
1759 for (
unsigned j=0 ; j<partvec.size() ; j++ ) {
1760 ReconstructedParticle* msp =
dynamic_cast<ReconstructedParticle*
>(partvec[j]) ;
1761 cluvec_p = msp->getClusters() ;
1762 trkvec_p = msp->getTracks() ;
1764 for (
unsigned k=0 ;
k<cluvec_p.size() ;
k++ ) {
1765 for (
unsigned l=0 ; l<cluvec_t.size() ; l++ ) {
1766 if ( cluvec_p[
k] == cluvec_t[l] ) {
1772 for (
unsigned k=0 ;
k<trkvec_p.size() ;
k++ ) {
1773 for (
unsigned l=0 ; l<trkvec_t.size() ; l++ ) {
1774 if ( trkvec_p[
k] == trkvec_t[l] ) {
1779 float wgt=int(c_wgt*1000)*10000 + int(t_wgt*1000) ;
1780 truthParticleRelNav.addRelation( mcp, msp , wgt ) ;
1781 streamlog_out( DEBUG4 ) <<
" True Particle " << mcp->id() <<
" ( pdg " << mcp->getPDG()
1782 <<
" ) has weight " << c_wgt <<
" / " << t_wgt <<
"( " << int(wgt) <<
" ) to particle "
1783 << msp->id() <<
" with " << cluvec_p.size() <<
" clusters, and "
1784 << trkvec_p.size() <<
" tracks " << std::endl;
1787 streamlog_out( DEBUG6 ) <<
" particle linking complete, create collection " << std::endl;
1788 *ptrlcol = particleTruthRelNav.createLCCollection() ;
1789 *trplcol = truthParticleRelNav.createLCCollection() ;
1794 LCRelationNavigator trackTruthRelNav = LCRelationNavigator( ttrlcol );
1795 LCRelationNavigator clusterTruthRelNav = LCRelationNavigator( ctrlcol );
1801 (*skimVec)->setSubset(
true) ;
1804 int nMCP = mcpCol->getNumberOfElements() ;
1806 for(
int i=0; i< nMCP ; i++){
1808 MCParticle* mcp =
dynamic_cast<MCParticle*
> ( mcpCol->getElementAt( i ) ) ;
1811 if( mcp->ext<
MCPKeep>() == true ){
1819 if ( ! mcp->isCreatedInSimulation() || mcp->getGeneratorStatus() != 0 ) {
1837 const LCObjectVec& trackObjects = trackTruthRelNav.getRelatedFromObjects( (LCObject*) mcp ) ;
1838 const LCObjectVec& clusterObjects = clusterTruthRelNav.getRelatedFromObjects( (LCObject*) mcp ) ;
1840 if( trackObjects.size() > 0 || clusterObjects.size()>0){
1842 streamlog_out( DEBUG5 ) <<
" keep MCParticle - e :" << mcp->getEnergy()
1843 <<
" charge: " << mcp->getCharge()
1844 <<
" px: " << mcp->getMomentum()[0]
1845 <<
" py: " << mcp->getMomentum()[1]
1846 <<
" pz: " << mcp->getMomentum()[2]
1847 <<
" mass: " << mcp->getMass()
1848 <<
" pdg " << mcp->getPDG()
1863 streamlog_out( DEBUG5 ) <<
" First loop done. Now search for KeepDaughtersPDG:s" << std::endl;
1867 for(
int i=0; i< nMCP ; i++){
1868 MCParticle* mcp =
dynamic_cast<MCParticle*
> ( mcpCol->getElementAt( i ) ) ;
1870 if( mcp->getParents().size() ){
1871 MCParticle* parent = mcp->getParents()[0];
1872 if( abs(parent->getPDG()) == 11){
1873 const float x = mcp->getVertex()[0];
1874 const float y = mcp->getVertex()[1];
1875 const float z = mcp->getVertex()[2];
1876 const float xpe = parent->getEndpoint()[0];
1877 const float ype = parent->getEndpoint()[1];
1878 const float zpe = parent->getEndpoint()[2];
1879 const float dx = x - xpe;
1880 const float dy = y - ype;
1881 const float dz = z - zpe;
1882 const float dr = sqrt(dx*dx+dy*dy+dz*dz);
1893 for(
int i=0; i< nMCP ; i++){
1895 MCParticle* mcp =
dynamic_cast<MCParticle*
> ( mcpCol->getElementAt( i ) ) ;
1898 if( mcp->ext<
MCPKeep>() ==
true && mcp->isDecayedInTracker() ){
1900 unsigned thePDG = abs( mcp->getPDG() ) ;
1904 const MCParticleVec& daughters = mcp->getDaughters() ;
1906 streamlog_out( DEBUG5 ) <<
" keeping daughters of particle with pdg : " << mcp->getPDG() <<
" : "
1907 <<
" [" << mcp->getGeneratorStatus() <<
"] :";
1917 streamlog_message( DEBUG5 ,
1918 if( mcp->getParents().size() ) ,
1919 " parent pdg : " << mcp->getParents()[0]->getPDG() <<
" : " ;
1925 for( MCParticleVec::const_iterator dIt = daughters.begin() ;
1926 dIt != daughters.end() ; ++dIt ){
1929 MCParticle* dau =
dynamic_cast<MCParticle*
>( *dIt ) ;
1931 if( dau->getEnergy()*1000. >
_eCutMeV ) {
1933 (*dIt)->ext<
MCPKeep>() =
true ;
1935 streamlog_out( DEBUG5 ) << (*dIt)->getPDG() <<
", " ;
1939 streamlog_out( DEBUG5 ) << std::endl ;
1945 streamlog_out( DEBUG4 ) <<
" All found, add to skimmed list " << std::endl;
1947 for(
int i=0; i< nMCP ; i++){
1949 MCParticle* mcp =
dynamic_cast<MCParticle*
> ( mcpCol->getElementAt( i ) ) ;
1951 if( mcp->ext<
MCPKeep>() == true ) {
1953 (*skimVec)->addElement( mcp ) ;
1966 const MCParticleVec& parents = mcp->getParents() ;
1968 streamlog_out( DEBUG3 ) <<
" keepMCParticle keep particle with pdg : " << mcp->getPDG()
1971 for( MCParticleVec::const_iterator pIt = parents.begin() ;
1972 pIt != parents.end() ; ++pIt ){
1974 if( (*pIt )->ext<
MCPKeep>() != true ) {
1988 #ifdef MARLIN_USE_AIDA
1990 streamlog_out(DEBUG) <<
" check " << std::endl;
1995 static AIDA::ICloud1D* hmcp_etot ;
1996 static AIDA::ICloud1D* hmcp_e ;
1997 static AIDA::ICloud1D* hmcp_n ;
1998 static AIDA::ICloud1D* hmcp_ntot ;
2000 static AIDA::ICloud1D* hmcpsk_etot ;
2001 static AIDA::ICloud1D* hmcpsk_e ;
2002 static AIDA::ICloud1D* hmcpsk_n ;
2003 static AIDA::ICloud1D* hmcpsk_ntot ;
2005 if( isFirstEvent() ) {
2007 hmcp_e = AIDAProcessor::histogramFactory(
this)->
2008 createCloud1D(
"hmcp_e",
" energy/GeV - all " , 100 ) ;
2011 hmcp_etot = AIDAProcessor::histogramFactory(
this)->
2012 createCloud1D(
"hmcp_etot",
" total energy/GeV " , 100 ) ;
2015 hmcp_n = AIDAProcessor::histogramFactory(
this)->
2016 createCloud1D(
"hmcp_n",
" # generated stable particles " , 100 ) ;
2018 hmcp_ntot = AIDAProcessor::histogramFactory(
this)->
2019 createCloud1D(
"hmcp_ntot",
" total # particles " , 100 ) ;
2022 hmcpsk_e = AIDAProcessor::histogramFactory(
this)->
2023 createCloud1D(
"hmcpsk_e",
" energy/GeV - all " , 100 ) ;
2026 hmcpsk_etot = AIDAProcessor::histogramFactory(
this)->
2027 createCloud1D(
"hmcpsk_etot",
" total energy/GeV " , 100 ) ;
2030 hmcpsk_n = AIDAProcessor::histogramFactory(
this)->
2031 createCloud1D(
"hmcpsk_n",
" # generated stable particles " , 100 ) ;
2033 hmcpsk_ntot = AIDAProcessor::histogramFactory(
this)->
2034 createCloud1D(
"hmcpsk_ntot",
" total # particles " , 100 ) ;
2038 LCCollection* mcpCol = NULL;
2041 }
catch (DataNotAvailableException&
e) {
2042 streamlog_out(DEBUG9) <<
"RecoMCTructh::Check(): MCParticle collection \"" <<
_mcParticleCollectionName <<
"\" does not exist, skipping" << std::endl;
2045 int nMCP = mcpCol->getNumberOfElements() ;
2050 for(
int i=0; i< nMCP ; i++){
2052 MCParticle* mcp =
dynamic_cast<MCParticle*
> ( mcpCol->getElementAt( i ) ) ;
2054 if( mcp->getGeneratorStatus() == 1 ) {
2056 hmcp_e->fill( mcp->getEnergy() ) ;
2058 etot += mcp->getEnergy() ;
2064 hmcp_n->fill( nStable ) ;
2066 hmcp_ntot->fill( nMCP ) ;
2068 hmcp_etot->fill( etot ) ;
2072 LCCollection* mcpskCol = NULL;
2076 catch (DataNotAvailableException& e){
2077 streamlog_out(DEBUG9) <<
"RecoMCTructh::Check(): MCParticleSkimmed collection \"" <<
_mcParticlesSkimmedName <<
"\" does not exist, skipping" << std::endl;
2085 nMCPSK = mcpskCol->getNumberOfElements() ;
2086 for(
int i=0; i< nMCPSK ; i++){
2087 MCParticle* mcpsk =
dynamic_cast<MCParticle*
> ( mcpskCol->getElementAt( i ) ) ;
2088 if( mcpsk->getGeneratorStatus() == 1 ) {
2089 hmcpsk_e->fill( mcpsk->getEnergy() ) ;
2090 etot += mcpsk->getEnergy() ;
2096 hmcpsk_n->fill( nStable ) ;
2098 hmcpsk_ntot->fill( nMCPSK ) ;
2100 hmcpsk_etot->fill( etot ) ;
2110 if( obj->empty() == false ) {
2116 streamlog_out( WARNING ) <<
"getSimHits : TrackerHit : " << trkhit <<
" has no sim hits related. CellID0 = " <<
2117 trkhit->getCellID0() <<
" pos = " << trkhit->getPosition()[0] <<
" " << trkhit->getPosition()[1] <<
" " <<
2118 trkhit->getPosition()[2] << std::endl ;
2128 streamlog_out(DEBUG6) <<
" processed " <<
_nEvt <<
" events in " <<
_nRun <<
" runs "
2135 inline lcio::LCCollection*
getCollection(lcio::LCEvent* evt,
const std::string name ){
2137 if( name.size() == 0 )
2142 return evt->getCollection( name ) ;
2144 }
catch( lcio::DataNotAvailableException&
e ){
2146 streamlog_out( DEBUG2 ) <<
"getCollection : DataNotAvailableException : " << name << std::endl ;
2158 std::vector<LCCollection*> colVec ;
2160 for(
unsigned i=0; i < nCol ; ++i) {
2166 colVec.push_back( col ) ;
2175 streamlog_out( DEBUG2 ) <<
" mergeTrackerHitRelations: copied collection parameters ... " << std::endl ;
2179 nCol = colVec.size() ;
2181 for(
unsigned i=0; i < nCol ; ++i) {
2183 LCCollection* col = colVec[i] ;
2194 col->getParameters().getStringKeys( stringKeys ) ;
2195 for(
unsigned ii=0; ii< stringKeys.size() ; ii++ ){
2197 col->getParameters().getStringVals( stringKeys[ii] , vals ) ;
2201 col->getParameters().getIntKeys( intKeys ) ;
2202 for(
unsigned ii=0; ii< intKeys.size() ; ii++ ){
2204 col->getParameters().getIntVals( intKeys[ii] , vals ) ;
2208 col->getParameters().getFloatKeys( floatKeys ) ;
2209 for(
unsigned ii=0; ii< floatKeys.size() ; ii++ ){
2211 col->getParameters().getFloatVals( floatKeys[ii] , vals ) ;
2219 int nEle = col->getNumberOfElements() ;
2221 for(
int j=0; j < nEle ; ++j){
2244 std::vector<LCCollection*> colVec ;
2246 for(
unsigned i=0; i < nCol ; ++i) {
2252 colVec.push_back( col ) ;
2256 streamlog_out(DEBUG2) <<
" mergeCaloHitRelations: input collection missing : " <<
_caloHitRelationNames[i] << std::endl ;
2262 streamlog_out( DEBUG2 ) <<
" mergeCaloHitRelations: copied collection parameters ... " << std::endl ;
2266 nCol = colVec.size() ;
2268 for(
unsigned i=0; i < nCol ; ++i) {
2270 LCCollection* col = colVec[i] ;
2280 col->getParameters().getStringKeys( stringKeys ) ;
2281 for(
unsigned ii=0; ii< stringKeys.size() ; ii++ ){
2283 col->getParameters().getStringVals( stringKeys[ii] , vals ) ;
2287 col->getParameters().getIntKeys( intKeys ) ;
2288 for(
unsigned ii=0; ii< intKeys.size() ; ii++ ){
2290 col->getParameters().getIntVals( intKeys[ii] , vals ) ;
2294 col->getParameters().getFloatKeys( floatKeys ) ;
2295 for(
unsigned ii=0; ii< floatKeys.size() ; ii++ ){
2297 col->getParameters().getFloatVals( floatKeys[ii] , vals ) ;
2305 int nEle = col->getNumberOfElements() ;
2307 for(
int j=0; j < nEle ; ++j){
2323 if( obj->empty() == false ) {
2330 streamlog_out( DEBUG5 ) <<
"getCaloHits : CalorimeterHit : " << calohit <<
" has no sim hits related. CellID0 = " <<
2331 calohit->getCellID0() <<
" pos = " << calohit->getPosition()[0] <<
" " << calohit->getPosition()[1] <<
" " <<
2332 calohit->getPosition()[2] << std::endl ;
2342 LCRelationNavigator particleTruthRelNav = LCRelationNavigator( ptrlcol );
2343 LCRelationNavigator truthParticleRelNav = LCRelationNavigator( trplcol );
2349 static FloatVec www ;
2350 static FloatVec www_other_way ;
2353 int nPart = particleCol->getNumberOfElements() ;
2354 LCObjectVec partvec;
2356 for(
int i=0;i<nPart;++i){
2358 ReconstructedParticle* part =
dynamic_cast<ReconstructedParticle*
> ( particleCol->getElementAt(i) ) ;
2360 if ( part->getClusters().size() > 0 ) {
2361 Cluster* clu = part->getClusters()[0];
2363 clu_e=clu->getEnergy();
2366 mcvec = particleTruthRelNav.getRelatedToObjects( part);
2367 www = particleTruthRelNav.getRelatedToWeights( part);
2368 int ntp= mcvec.size();
2369 streamlog_out( DEBUG5 ) <<
" Particle " << part->id() <<
" (q: " << int(part->getCharge()) <<
2370 " ) has " << ntp <<
" true particles. E= "<< part->getEnergy() <<
" " << clu_e ;
2371 streamlog_out( DEBUG3 )<<
" Index, id, PDG and energy of contributors: " << std::endl;
2373 if ( mcvec[0] != 0 ) {
2374 double total_trk_weight = 0.0;
2375 double total_clu_weight = 0.0;
2376 double total_e_from_neutrals = 0.0;
2377 double true_charged_E=0.0;
2378 double total_ecalo_in_this_true=0.;
2379 double total_ecalo_neutral_in_charged=0.;
2380 for (
int kkk=0 ; kkk < ntp ; kkk++ ) {
2381 total_trk_weight+=(int(www[kkk])%10000)/1000.0;
2382 total_clu_weight+=(int(www[kkk])/10000)/1000.0;
2383 MCParticle* mcp =
dynamic_cast< MCParticle*
>( mcvec[kkk]);
2384 streamlog_out( DEBUG3 ) <<
" "<< kkk <<
" " << mcp->id() <<
" " << mcp->getPDG() <<
" " << mcp->getEnergy() << std::endl ;
2385 if ( part->getCharge() != 0 ) {
2386 if ( mcp->getCharge() != 0 && (int(www[kkk])%10000)/1000.0 > 0.6 ) {
2387 true_charged_E=mcp->getEnergy();
2388 double ecalo_from_this_true=((int(www[kkk])/10000)/1000.0)*clu_e;
2389 if ( ecalo_from_this_true != 0.0 ) {
2390 partvec = truthParticleRelNav.getRelatedToObjects( mcp);
2391 www_other_way = truthParticleRelNav.getRelatedToWeights( mcp);
2392 for (
unsigned jjj=0 ; jjj < partvec.size() ; jjj++ ) {
2393 if ( partvec[jjj] == part ) {
2394 total_ecalo_in_this_true = ecalo_from_this_true/(int(www_other_way[jjj]/10000)/1000.0) ;
2400 total_ecalo_neutral_in_charged+=((int(www[kkk])/10000)/1000.0)*clu_e;
2403 if ( mcp->getCharge() == 0 ) {
2404 total_e_from_neutrals+=((int(www[kkk])/10000)/1000.0)*clu_e;
2408 if ( part->getCharge() != 0 ) {
2409 streamlog_out( DEBUG5 ) <<
" True E_ch " << true_charged_E <<
" total E_calo from true " << total_ecalo_in_this_true
2410 <<
" E_calo from neutral " << total_ecalo_neutral_in_charged <<
" track weight " <<
2411 total_trk_weight <<
" cluster weight " << total_clu_weight << std::endl ;
2413 streamlog_out( DEBUG5 ) <<
" True E_neutral " << total_e_from_neutrals <<
" track weight " <<
2414 total_trk_weight <<
" cluster weight " << total_clu_weight << std::endl ;
2420 int nMCPart = mcpCol->getNumberOfElements() ;
2422 for(
int i=0;i<nMCPart;++i){
2424 MCParticle* mcpart =
dynamic_cast<MCParticle*
> ( mcpCol->getElementAt(i) ) ;
2426 partvec = truthParticleRelNav.getRelatedToObjects( mcpart);
2427 www = truthParticleRelNav.getRelatedToWeights( mcpart);
2428 int nsp= partvec.size();
2430 streamlog_out( DEBUG5 ) <<
" TrueParticle " << mcpart->id() <<
" (q: " << int(mcpart->getCharge()) <<
2431 " ) has " << nsp <<
" seen particles. E= "<<mcpart->getEnergy() <<
" pt= " <<
2432 sqrt(mcpart->getMomentum()[0]* mcpart->getMomentum()[0]+ mcpart->getMomentum()[1]* mcpart->getMomentum()[1]);
2433 streamlog_out( DEBUG3 )<<
" index, id, and enregy of reco particle: " << std::endl;
2434 if ( partvec[0] != 0 ) {
2435 double total_trk_weight = 0.0;
2436 double total_clu_weight = 0.0;
2437 for (
int kkk=0 ; kkk < nsp ; kkk++ ) {
2438 total_trk_weight+=(int(www[kkk])%10000)/1000.0;
2439 total_clu_weight+=(int(www[kkk])/10000)/1000.0;
2440 ReconstructedParticle* recopart =
dynamic_cast< ReconstructedParticle*
>(partvec[kkk]);
2441 streamlog_out( DEBUG3 )<<
" "<< kkk <<
" " << recopart->id() <<
" " << recopart->getEnergy() << std::endl ;
2443 streamlog_out( DEBUG5 ) <<
" Total track weight " << total_trk_weight <<
" , Total cluster weight " << total_clu_weight << std::endl ;
bool _use_tracker_hit_relations
bool _OutputTruthRecoRelation
virtual void linkPrinter(LCCollection *mcpCol, LCCollection *particleCol, LCCollection *ptrlcol, LCCollection *trplcol)
std::string _trackMCTruthLinkName
output collection names
std::string _calohitMCTruthLinkName
virtual void end()
Called after data processing for clean up.
LCCollectionVec * _mergedCaloHitRelCol
virtual void clusterLinker(LCEvent *evt, LCCollection *mcpCol, LCCollection *clusterCol, LCCollection **ctrcol, LCCollection **trccol, LCCollection **chittrlcol)
LCRelationNavigator * _navMergedTrackerHitRel
virtual void trackLinker(LCEvent *evt, LCCollection *mcpCol, LCCollection *trackCol, LCCollection **ttrcol, LCCollection **trtcol)
std::map< Track *, int > TrackMap
StringVec _colNamesTrackerHitRelations
CLHEP::Hep3Vector Vector3D
virtual void processEvent(LCEvent *evt)
Called for every event - the working horse.
std::string _trackCollectionName
virtual void mergeTrackerHitRelations(LCEvent *evt)
virtual void processRunHeader(LCRunHeader *run)
Called for every run.
bool _FullRecoRelation
output collection steering
const LCObjectVec * getSimHits(TrackerHit *trkhit, const FloatVec *weights=NULL)
LCRelationNavigator * _navMergedCaloHitRel
virtual void init()
Called at the begin of the job before anything is read.
std::map< MCParticle *, int > MCPMap
LCCollectionVec * _mergedTrackerHitRelCol
virtual void makeSkim(LCCollection *mcpCol, LCCollection *ttrcol, LCCollection *ctrcol, LCCollectionVec **skimVec)
std::string _clusterMCTruthLinkName
bool _OutputTrackTruthRelation
std::map< MCParticle *, MCParticle * > Remap_as_you_go
bool _saveBremsstrahlungPhotons
bool _invertedNonDestructiveInteractionLogic
StringVec _simTrkHitCollectionNames
std::string _recoMCTruthLinkName
virtual void check(LCEvent *evt)
std::string _mCTruthRecoLinkName
std::string _mcParticlesSkimmedName
void keepMCParticle(MCParticle *mcp)
std::string _recoParticleCollectionName
virtual void mergeCaloHitRelations(LCEvent *evt)
lcio::LCCollection * getCollection(lcio::LCEvent *evt, const std::string name)
helper function to get collection safely
bool _OutputTruthClusterRelation
std::string _mcParticleCollectionName
input collection names
virtual void particleLinker(LCCollection *mcpCol, LCCollection *particleCol, LCCollection *ttrcol, LCCollection *ctrlcol, LCCollection *trtlcol, LCCollection *trclcol, LCCollection **ptrlcol, LCCollection **trplcol)
const LCObjectVec * getCaloHits(CalorimeterHit *calohit, const FloatVec *weights=NULL)
bool _OutputCalohitRelation
StringVec _caloHitRelationNames
std::vector< LCCollection * > LCCollectionVec
Optionally creates four collections of LCRelations ("recoMCTruthLink", "trackMCTruthLink", "mcTruthTrackLink", "clusterMCTruthLink", ""clusterMCTruthLink" and "calohitMCTruthLink") with weighetd relations between true particles and reconstructed particles, tracks, clusters, and calorimeter hits, respectively.
float _bremsstrahlungEnergyCut
std::string _mCTruthTrackLinkName
bool _OutputClusterTruthRelation
std::string _mCTruthClusterLinkName
RecoMCTruthLinker aRecoMCTruthLinker
StringVec _simCaloHitCollectionNames
bool _OutputTruthTrackRelation
std::string _clusterCollectionName
std::vector< std::string > StringVec
std::map< MCParticle *, double > MCPMapDouble