1 #include "marlin/MarlinConfig.h"
20 #include <AIDA/IHistogramFactory.h>
21 #include <AIDA/ICloud1D.h>
23 #include <AIDA/IHistogram1D.h>
24 #include <AIDA/IProfile1D.h>
25 #include <AIDA/IDataPointSetFactory.h>
26 #include <AIDA/IDataPointSet.h>
27 #include <AIDA/IDataPoint.h>
28 #include <AIDA/IMeasurement.h>
29 #include <AIDA/IManagedObject.h>
30 #include <AIDA/ITree.h>
31 #include <AIDA/IAxis.h>
37 using namespace lcio ;
46 SimpleFastMCProcessor::SimpleFastMCProcessor() :
Processor(
"SimpleFastMCProcessor"),
53 _description =
"SimpleFastMCProcessor creates ReconstrcutedParticles from MCParticles "
54 "according to the resolution given in the steering file." ;
60 "InputCollectionName" ,
61 "Name of the MCParticle input collection" ,
67 "RecoParticleCollectionName" ,
68 "Name of the ReconstructedParticles output collection" ,
73 "MCTruthMappingCollectionName" ,
74 "Name of the MCTruthMapping output collection" ,
80 "No reconstructed particles are produced for smaller momenta (in [GeV])" ,
90 "Resolution of charged particles in polar angle range: d(1/P) th_min th_max" ,
93 chResDefault.
size() ) ;
97 gammaResDefault.push_back( 0.10 ) ;
98 gammaResDefault.push_back( 0.00 ) ;
99 gammaResDefault.push_back( 3.141593/2. ) ;
102 "Resolution dE/E=A+B/sqrt(E/GeV) of photons in polar angle range: A B th_min th_max" ,
105 gammaResDefault.
size() ) ;
109 hadronResDefault.push_back( 0.50 ) ;
110 hadronResDefault.push_back( 0.00 ) ;
111 hadronResDefault.push_back( 3.141593/2. ) ;
114 "Resolution dE/E=A+B/sqrt(E/GeV) of neutral hadrons in polar angle range: A B th_min th_max" ,
117 hadronResDefault.
size() ) ;
138 SimpleParticleFactory* simpleFactory =
new SimpleParticleFactory() ;
141 simpleFactory->registerIFourVectorSmearer(
new SimpleClusterSmearer(
_initPhotonRes ),
PHOTON ) ;
147 streamlog_out( MESSAGE ) <<
" SimpleFastMCProcessor::init() : registering SimpleParticleFactory " <<
std::endl ;
149 #endif // MARLIN_CLHEP
163 LCCollectionVec* recVec =
new LCCollectionVec( LCIO::RECONSTRUCTEDPARTICLE ) ;
165 LCRelationNavigator relNav( LCIO::RECONSTRUCTEDPARTICLE , LCIO::MCPARTICLE ) ;
167 for(
int i=0; i<mcpCol->getNumberOfElements() ; i++){
169 MCParticle* mcp =
dynamic_cast<MCParticle*
> ( mcpCol->getElementAt( i ) ) ;
173 if( mcp->getGeneratorStatus() == 1 ) {
181 recVec->addElement( rec ) ;
182 relNav.addRelation( rec , mcp ) ;
187 recVec->setDefault(
true ) ;
204 static AIDA::ICloud1D* hChargedRes ;
206 static AIDA::ICloud1D* hChargedEnergy ;
207 static AIDA::ICloud1D* hPhotonEnergy ;
208 static AIDA::ICloud1D* hHadronEnergy ;
211 static AIDA::IHistogram1D* hPhotonRes ;
212 static AIDA::IHistogram1D* hHadronRes ;
214 static AIDA::IProfile1D* hGamHelperP1 ;
215 static AIDA::IProfile1D* hHadHelperP1 ;
220 hChargedRes = AIDAProcessor::histogramFactory(
this)->
221 createCloud1D(
"hChargedRes",
"dP/P for charged tracks", 100 ) ;
224 hChargedEnergy = AIDAProcessor::histogramFactory(
this)->
225 createCloud1D(
"hChargedEnergy",
"E/GeV for charged particles", 100 ) ;
227 hPhotonEnergy = AIDAProcessor::histogramFactory(
this)->
228 createCloud1D(
"hPhotonEnergy",
"E/GeV for photons", 100 ) ;
230 hHadronEnergy = AIDAProcessor::histogramFactory(
this)->
231 createCloud1D(
"hHadronEnergy",
"E/GeV for neutral hadrons", 100 ) ;
237 hPhotonRes = AIDAProcessor::histogramFactory(
this)->
238 createHistogram1D(
"hPhotonRes",
"dE/E for photons", 100, -2.,2. ) ;
240 hHadronRes = AIDAProcessor::histogramFactory(
this)->
241 createHistogram1D(
"hHadronRes",
"dE/E for neutral hadrons", 100, -2., 2. ) ;
244 hGamHelperP1 = AIDAProcessor::histogramFactory(
this)->
245 createProfile1D(
"hGamHelperP1",
" helper profile of energy spread", 10, 0.,20. ) ;
247 hHadHelperP1 = AIDAProcessor::histogramFactory(
this)->
248 createProfile1D(
"hHadHelperP1",
" helper profile of energy spread", 10, 0.,20. ) ;
259 streamlog_out( WARNING ) <<
"SimpleFastMCProcessor::check no collection found: MCTruthMapping" <<
std::endl ;
263 LCRelationNavigator relNav( relCol ) ;
267 int nRec = recCol->getNumberOfElements() ;
269 for(
int i=0; i< nRec ; i++){
273 const LCObjectVec& mcps = relNav.getRelatedToObjects( rec ) ;
275 MCParticle* mcp =
dynamic_cast<MCParticle*
>( mcps[0] ) ;
278 if( rec->getType() ==
CHARGED) {
280 double recP =
std::sqrt( rec->getMomentum()[0] * rec->getMomentum()[0] +
281 rec->getMomentum()[1] * rec->getMomentum()[1] +
282 rec->getMomentum()[2] * rec->getMomentum()[2] ) ;
284 double mcpP =
std::sqrt( mcp->getMomentum()[0] * mcp->getMomentum()[0] +
285 mcp->getMomentum()[1] * mcp->getMomentum()[1] +
286 mcp->getMomentum()[2] * mcp->getMomentum()[2] ) ;
288 hChargedRes->fill( ( recP - mcpP ) / recP ) ;
290 hChargedEnergy->fill( rec->getEnergy() ) ;
294 double rE = rec->getEnergy() ;
295 double mE = mcp->getEnergy() ;
297 double dEoverE = ( rE - mE ) / mE ;
299 if( rec->getType() ==
PHOTON) {
301 hPhotonEnergy->fill( mE ) ;
302 hGamHelperP1->fill( mE , dEoverE ) ;
303 hPhotonRes->fill( dEoverE , mE ) ;
310 hHadronRes->fill( dEoverE , mE ) ;
311 hHadronEnergy->fill( mE ) ;
312 hHadHelperP1->fill( mE , dEoverE ) ;
325 #endif // MARLIN_AIDA
333 streamlog_out( MESSAGE4 ) <<
"SimpleFastMCProcessor::end() " <<
name()
334 <<
" processed " <<
_nEvt <<
" events in " <<
_nRun <<
" runs "
337 #ifdef MARLIN_AIDA_IGNORE_FOR_NOW
344 AIDA::IProfile1D* hGamHelperP1 = 0 ;
345 AIDA::IManagedObject* obj = AIDAProcessor::tree(
this)->find(
"hGamHelperP1") ;
346 if( obj != 0 ) hGamHelperP1 =
static_cast<AIDA::IProfile1D*
>( obj->cast(
"AIDA::IProfile1D") ) ;
348 AIDA::IProfile1D* hHadHelperP1 = 0 ;
349 obj = AIDAProcessor::tree(
this)->find(
"hHadHelperP1");
350 if( obj != 0 ) hHadHelperP1 =
static_cast<AIDA::IProfile1D*
>( obj->cast(
"AIDA::IProfile1D") ) ;
353 AIDA::IDataPointSet* dPhotonRes = AIDAProcessor::dataPointSetFactory(
this)->
354 create(
"dPhotonRes",
"dE/E vs. 1./sqrt(E/GeV)",2 ) ;
356 AIDA::IDataPointSet* dHadronRes = AIDAProcessor::dataPointSetFactory(
this)->
357 create(
"dHadronRes",
"dE/E vs. 1./sqrt(E/GeV)",2 ) ;
359 if( hHadHelperP1 != 0 ){
361 for (
int i = 0; i< hHadHelperP1->axis().bins() ; i++ ) {
363 dHadronRes->addPoint() ;
365 double sigma = hHadHelperP1->binRms(i) ;
376 dHadronRes->point(i)->coordinate(0)->setValue( 1. /
std::sqrt( hHadHelperP1->binMean(i) ) ) ;
378 dHadronRes->point(i)->coordinate(1)->setValue( sigma ) ;
381 double errorMean = ( eos.upperError( sigma ) + eos.lowerError( sigma ) ) / 2 ;
383 dHadronRes->point(i)->coordinate(1)->setErrorPlus( errorMean ) ;
384 dHadronRes->point(i)->coordinate(1)->setErrorMinus( errorMean ) ;
392 if( hGamHelperP1 != 0 ){
394 for (
int i = 0; i< hGamHelperP1->axis().bins() ; i++ ) {
396 dPhotonRes->addPoint() ;
398 double sigma = hGamHelperP1->binRms(i) ;
406 dPhotonRes->point(i)->coordinate(0)->setValue( 1. /
std::sqrt( hGamHelperP1->binMean(i) ) ) ;
408 dPhotonRes->point(i)->coordinate(1)->setValue( sigma ) ;
411 double errorMean = ( eos.upperError( sigma ) + eos.lowerError( sigma ) ) / 2 ;
413 dPhotonRes->point(i)->coordinate(1)->setErrorPlus( errorMean ) ;
414 dPhotonRes->point(i)->coordinate(1)->setErrorMinus( errorMean ) ;
420 #endif // MARLIN_AIDA_IGNORE_FOR_NOW
virtual void processRunHeader(LCRunHeader *run)
Called for every run.
Small helper class that computes the lower and upper error of sigma assuming a normal distribution...
void registerProcessorParameter(const std::string ¶meterName, const std::string ¶meterDescription, T ¶meter, const T &defaultVal, int setSize=0)
Register a steering variable for this processor - call in constructor of processor.
FloatVec _initNeutralHadronRes
Resolutions of photons.
void registerOutputCollection(const std::string &collectionType, const std::string ¶meterName, const std::string ¶meterDescription, std::string ¶meter, const std::string &defaultVal, int setSize=0)
Specialization of registerProcessorParameter() for a parameter that defines an output collection - ca...
FloatVec _initChargedRes
Resolutions of charged particles.
SimpleFastMCProcessor aSimpleFastMCProcessor
virtual const std::string & name() const
Return name of this processor.
void registerInputCollection(const std::string &collectionType, const std::string ¶meterName, const std::string ¶meterDescription, std::string ¶meter, const std::string &defaultVal, int setSize=0)
Specialization of registerProcessorParameter() for a parameter that defines an input collection - can...
std::string _mcTruthCollectionName
float _momentumCut
Momentum cut in GeV.
void printParameters()
Print the parameters and their values depending on the given verbosity level.
virtual void init()
Initializes ...
IRecoParticleFactory * _factory
The particle factory.
std::string _inputCollectionName
Input collection name.
A simple smearing "Monte Carlo" processor.
std::string _recoParticleCollectionName
Ouput collection names.
bool isFirstEvent()
True if first event in processEvent(evt) - use this e.g.
FloatVec _initPhotonRes
Resolutions of photons.
virtual lcio::ReconstructedParticle * createReconstructedParticle(const lcio::MCParticle *mcp)=0
The actual factory method that creates a new ReconstructedParticle for the given MCParticle.
Base class for Marlin processors.
virtual void end()
Called after data processing for clean up.
std::string _description
Describes what the processor does.
virtual void check(LCEvent *evt)
Creates some checkplots.
virtual void processEvent(LCEvent *evt)
Updates all registered conditions handlers and adds the data to the event.