26 #include <EVENT/LCCollection.h>
27 #include <IMPL/LCCollectionVec.h>
28 #include <IMPL/ReconstructedParticleImpl.h>
29 #include <UTIL/LCRelationNavigator.h>
30 #include <EVENT/MCParticle.h>
34 #include "marlin/VerbosityLevels.h"
36 using namespace lcio ;
37 using namespace marlin ;
53 _description =
"ErrorFlow processor computes total error of a jet based on the information from each sub-detector" ;
56 registerInputCollection( LCIO::RECONSTRUCTEDPARTICLE,
58 "Input collection of jets",
60 std::string(
"InputJets" )
63 registerInputCollection( LCIO::RECONSTRUCTEDPARTICLE,
64 "OutputPFOCollection",
65 "Out collection of jets with calculated covariance matrix",
67 std::string(
"OutputJets" )
70 registerInputCollection( LCIO::LCRELATION,
71 "InputMCTruthLinkCollection" ,
72 "Input collection of MC Truth Links",
74 std::string(
"RecoMCTruthLink" )
78 registerProcessorParameter(
"ECALStochastic" ,
79 "Stochastic term coefficient in ECAL resolution",
84 registerProcessorParameter(
"ECALConstant" ,
85 "Constant term coefficient in ECAL resolution",
90 registerProcessorParameter(
"HCALStochastic" ,
91 "Stochastic term coefficient in HCAL resolution",
96 registerProcessorParameter(
"HCALConstant" ,
97 "Constant term coefficient in HCAL resolution",
101 registerProcessorParameter(
"ConfusionScaleFactor" ,
102 "Scale factor for confusion resolution term",
106 registerProcessorParameter(
"EnableSemiLepCorrection" ,
107 "Enable/disable semi-leptonic correction resolution to be added to covariance matrix",
111 registerProcessorParameter(
"EnableConfusionTerm" ,
112 "Enable/disable confusion term to be added to covariance matrix",
116 registerProcessorParameter(
"PropagateConfusion2Mom" ,
117 "Enable/disable Propagating uncertainty due to confusion to the Momentum components",
121 registerProcessorParameter(
"SemiLepSigmaCorrectionFactor" ,
122 "A correction factor to be multiplied by total lepton energy to get semi-leptonic uncertainty",
126 registerProcessorParameter(
"CovMatFactorPhotons" ,
127 "A correction factor to be multiplied to angular uncertainties of photons",
131 registerProcessorParameter(
"CovMatFactorNeutralHadrons" ,
132 "A correction factor to be multiplied to angular uncertainties of Neutral Hadrons",
136 registerProcessorParameter(
"SotreInTree" ,
137 "Enable/disable storing computed qunatities in a ROOT tree",
141 registerProcessorParameter(
"useFullCovMatforNeutrals" ,
142 "whether use full CovMat for neutral PFOs or use only energy uncertainty",
159 streamlog_out(DEBUG) <<
" init called " << std::endl ;
166 tree = std::make_shared<TTree>(
"ErrorFlow",
"Number of photons, charged and neutral hadrons in a jet");
171 tree->Branch(
"numPFOsTotal" , &
nPFOs,
"numPFOsTotal/I");
222 streamlog_out(DEBUG) <<
" processing event: " << evt->getEventNumber()
223 <<
" in run: " << evt->getRunNumber() << std::endl;
230 LCRelationNavigator *navMCTL =
new LCRelationNavigator( colMCTL );
234 outCol->setSubset(
true );
240 size_t nJets = col->getNumberOfElements();
241 streamlog_out(DEBUG) <<
"Number of jets in the event:" << nJets << std::endl;
244 for(
size_t iJet=0; iJet < nJets; ++iJet ) {
250 ReconstructedParticleImpl *jetPtr =
dynamic_cast<ReconstructedParticleImpl*
>( col->getElementAt( iJet ) );
251 TVector3 jet3Momentum( jetPtr->getMomentum()[0] , jetPtr->getMomentum()[1] , jetPtr->getMomentum()[2] );
252 double jetMom = jet3Momentum.Mag();
253 double jetEnergy = jetPtr->getEnergy();
254 float jetTheta = jet3Momentum.Theta();
255 float jetPhi = jet3Momentum.Phi();
256 std::vector< float > jetCovMatrixConf( 10, 0.0 );
257 jetCovMatrixConf[ 0 ] = pow( sin( jetTheta ) , 2 ) * pow( cos( jetPhi ) , 2 );
258 jetCovMatrixConf[ 1 ] = pow( sin( jetTheta ) , 2 ) * sin( jetPhi ) * cos( jetPhi );
259 jetCovMatrixConf[ 2 ] = pow( sin( jetTheta ) , 2 ) * pow( sin( jetPhi ) , 2 );
260 jetCovMatrixConf[ 3 ] = sin( jetTheta ) * cos( jetTheta ) * cos( jetPhi );
261 jetCovMatrixConf[ 4 ] = sin( jetTheta ) * cos( jetTheta ) * sin( jetPhi );
262 jetCovMatrixConf[ 5 ] = pow( cos( jetTheta ) , 2 );
263 jetCovMatrixConf[ 6 ] = ( jetMom / jetEnergy ) * sin( jetTheta ) * cos( jetPhi );
264 jetCovMatrixConf[ 7 ] = ( jetMom / jetEnergy ) * sin( jetTheta ) * sin( jetPhi );
265 jetCovMatrixConf[ 8 ] = ( jetMom / jetEnergy ) * cos( jetTheta );
266 jetCovMatrixConf[ 9 ] = pow( jetMom , 2 ) / pow( jetEnergy , 2 );
269 ReconstructedParticleVec jetPFOs = jetPtr->getParticles();
270 nPFOs = jetPFOs.size();
271 streamlog_out(DEBUG) <<
"Number of PFOs in the jet:" <<
nPFOs << std::endl;
274 std::vector< float > jetCovMatrix( 10, 0.0 );
277 for (
size_t iPFO = 0; iPFO <
nPFOs; ++iPFO ) {
279 ReconstructedParticle *particlePtr = jetPFOs[ iPFO ];
280 LCObjectVec vecMCTL = navMCTL->getRelatedToObjects( particlePtr );
281 int nTrackspfo = (particlePtr->getTracks()).size();
285 double scaleFactor = 1.0;
289 FloatVec particleCovMatrix = particlePtr->getCovMatrix();
290 if ( 0 != nTrackspfo )
298 else if ( 22 == particlePtr->getType() )
301 ePhotons += particlePtr->getEnergy();
310 for (
size_t iElement = 0; iElement < 9; ++iElement)
314 jetCovMatrix[ iElement ] += scaleFactor * scaleFactor * particleCovMatrix [ iElement ];
318 jetCovMatrix[ iElement ] += scaleFactor * particleCovMatrix [ iElement ];
322 jetCovMatrix[ 9 ] += particleCovMatrix [ 9 ];
328 if ( 0 != nTrackspfo ) {
331 FloatVec particleCovMatrix = particlePtr->getCovMatrix();
332 for (
size_t iElement = 0; iElement < 10; ++iElement) {
333 jetCovMatrix[ iElement ] += particleCovMatrix [ iElement ];
337 if ( 22 == particlePtr->getType() ) {
339 ePhotons += particlePtr->getEnergy();
352 if( 0 < vecMCTL.size() ) {
353 MCParticle *mcParticle =
dynamic_cast<MCParticle*
>( vecMCTL[ 0 ] );
355 int mcpPDG = mcParticle->getPDG();
358 if ( 11 == abs( mcpPDG ) || 13 == abs( mcpPDG ) ) {
361 if ( particleMomentum > 3.0 ) {
370 double relConfTerms[ 3 ] = { 0.0 };
390 for (
int iElement = 0 ; iElement < 10 ; ++iElement )
392 jetCovMatrix[ iElement ] = jetCovMatrix[ iElement ]
398 jetCovMatrix[ 9 ] = jetCovMatrix[ 9 ]
409 jetPtr->setCovMatrix( jetCovMatrix );
410 outCol->addElement( jetPtr );
418 streamlog_out(DEBUG) <<
"Error: collection does not exist!" << std::endl;
475 double t_photonsEnergy,
double t_neutralHadronsEnergy,
double t_confusion[] )
479 const double muEnCharged = 0.62;
481 const double muEnPhotons = 0.28;
482 const double muEnNeutral = 0.10;
488 const double conf45[ 3 ] = { 1.32, 0.88, 0.99 };
489 const double conf100[ 3 ] = { 0.77, 1.10, 1.43 };
490 const double conf180[ 3 ] = { 0.55, 1.21, 1.87 };
491 const double conf250[ 3 ] = { 0.22, 1.43, 1.98 };
493 double gammaChargedHadrons = ( t_chargedHadronsEnergy / t_jetEnergy ) / muEnCharged;
494 double gammaPhotons = ( t_photonsEnergy / t_jetEnergy ) / muEnPhotons;
495 double gammaNeutalHadrons = ( t_neutralHadronsEnergy / t_jetEnergy ) / muEnNeutral;
499 if ( 45.0 >= t_jetEnergy ) {
500 t_confusion[ 0 ] = conf45[ 0 ] * gammaChargedHadrons / 100.0;
501 t_confusion[ 1 ] = conf45[ 1 ] * gammaPhotons / 100.0;
502 t_confusion[ 2 ] = conf45[ 2 ] * gammaNeutalHadrons / 100.0;
504 else if ( 45 < t_jetEnergy && 100.0 >= t_jetEnergy ) {
505 t_confusion[ 0 ] = ( ( ( t_jetEnergy - 45.0 ) * ( conf100[ 0 ] - conf45[ 0 ] )
506 / ( 100.0 - 45.0 ) ) + conf45[ 0 ] ) * gammaChargedHadrons / 100.0;
507 t_confusion[ 1 ] = ( ( ( t_jetEnergy - 45.0 ) * ( conf100[ 1 ] - conf45[ 1 ] )
508 / ( 100.0 - 45.0 ) ) + conf45[ 1 ] ) * gammaPhotons / 100.0;
509 t_confusion[ 2 ] = ( ( ( t_jetEnergy - 45.0 ) * ( conf100[ 2 ] - conf45[ 2 ])
510 / ( 100.0 - 45.0 ) ) + conf45[ 2 ] ) * gammaNeutalHadrons / 100.0;
512 else if ( 100 < t_jetEnergy && 180.0 >= t_jetEnergy ) {
513 t_confusion[ 0 ] = ( ( ( t_jetEnergy - 100.0 ) * ( conf180[0] - conf100[0] )
514 / ( 180.0 - 100.0 ) ) + conf100[0] ) * gammaChargedHadrons / 100.0;
515 t_confusion[ 1 ] = ( ( ( t_jetEnergy - 100.0 ) * ( conf180[1] - conf100[1] )
516 / ( 180.0 - 100.0 ) ) + conf100[1] ) * gammaPhotons / 100.0;
517 t_confusion[ 2 ] = ( ( ( t_jetEnergy - 100.0 ) * ( conf180[2] - conf100[2] )
518 / ( 180.0 - 100.0 ) ) + conf100[2] ) * gammaNeutalHadrons / 100.0;
521 t_confusion[ 0 ] = ( ( ( t_jetEnergy - 180.0 ) * ( conf250[ 0 ] - conf180[ 0 ] )
522 / ( 250.0 - 180.0 ) ) + conf180[ 0 ] ) * gammaChargedHadrons / 100.0;
523 t_confusion[ 1 ] = ( ( ( t_jetEnergy - 180.0 ) * ( conf250[ 1 ] - conf180[ 1 ] )
524 / ( 250.0 - 180.0 ) ) + conf180[ 1 ] ) * gammaPhotons / 100.0;
525 t_confusion[ 2 ] = ( ( ( t_jetEnergy - 180.0 ) * ( conf250[ 2 ] - conf180[ 2 ] )
526 / ( 250.0 - 180.0 ) ) + conf180[ 2 ] ) * gammaNeutalHadrons / 100.0;
528 for (
size_t i = 0; i < 3; ++i) {
529 streamlog_out(DEBUG) <<
"Confusion " << i <<
":" << t_confusion[i] << std::endl;
551 return sigmaEnSquared;
570 return sigmaEnSquared;
583 float moX = t_threeMomentum[ 0 ];
584 float moY = t_threeMomentum[ 1 ];
585 float moZ = t_threeMomentum[ 2 ];
586 double totalMomentum = sqrt( moX*moX + moY*moY +moZ*moZ );
588 return totalMomentum;
std::string p_outputJetCollection
std::string p_inputJetCollection
Input collection name.
std::shared_ptr< TTree > tree
double getNeuHadSigmaESqr(double t_neuHadEnergy)
virtual void processRunHeader(LCRunHeader *run)
Called for every run.
ReconstructedParticleVec::size_type nPFOs
virtual void end()
Called after data processing for clean up.
double p_CovMatFactorNeutralHadrons
bool p_propagateConfusiontoMomentumComp
virtual void init()
Called at the begin of the job before anything is read.
double absSemiLepResSquared
virtual void check(LCEvent *evt)
virtual void processEvent(LCEvent *evt)
Called for every event - the working horse.
double getPhotonSigmaESqr(double t_phEnergy)
std::vector< LCCollection * > LCCollectionVec
double p_CovMatFactorPhotons
double getTotalMomentum(const double *t_threeMomentum)
std::string p_inputMCTruth
double p_semiLepSigmaCorrFactor
double * getRelativeConfusion(double jetEnergy, double chargedHadronsEnergy, double photonsEnergy, double neutralHadronsEnergy, double relConfTerms[])