3 #include <UTIL/LCRelationNavigator.h>
4 #include <UTIL/PIDHandler.h>
13 _description =
"GammaGammaCandidateTruthFilter does whatever it does ..." ;
18 registerProcessorParameter(
"Printing" ,
19 "Print certain messages" ,
23 std::string ggResonanceName =
"Pi0";
24 registerProcessorParameter(
"GammaGammaResonanceName" ,
25 "Particle decaying to Gamma Gamma" ,
29 registerInputCollection( LCIO::LCRELATION,
30 "MCTruth2RecoLinkCollectionName" ,
31 "true - reco relation collection" ,
33 std::string(
"MCTruthRecoLink") ) ;
36 registerInputCollection( LCIO::LCRELATION,
37 "Reco2MCTruthLinkCollectionName" ,
38 "reco - true relation collection" ,
40 std::string(
"RecoMCTruthLink") ) ;
43 registerInputCollection( LCIO::MCPARTICLE,
44 "MCParticleCollection" ,
45 "Name of the MCParticle input collection" ,
47 std::string(
"MCParticle") ) ;
50 registerInputCollection( LCIO::RECONSTRUCTEDPARTICLE,
51 "GammaGammaCandidateCollection" ,
52 "Name of the gamma-gamma candidate input collection" ,
54 std::string(
"GammaGammaCandidates") ) ;
57 std::string outputParticleCollectionName =
"TrueGammaGammaMesons";
58 registerOutputCollection( LCIO::RECONSTRUCTEDPARTICLE,
59 "OutputParticleCollectionName" ,
60 "Output Particle Collection Name " ,
62 outputParticleCollectionName);
69 streamlog_out(DEBUG) <<
" init called "
88 recparcol->setSubset(
true);
90 streamlog_out(MESSAGE) <<
" start processing event " << std::endl;
228 streamlog_out(DEBUG) <<
" reco iterator and navigator " << std::endl;
230 streamlog_out(DEBUG) <<
" got ggpIt with length of " << ggpIt.size() << std::endl;
231 LCRelationNavigator rec2mcNav(evt->getCollection(
_recoToTrue ));
232 streamlog_out(DEBUG) <<
" got rec2mcNav from " << rec2mcNav.getFromType() <<
" to " << rec2mcNav.getToType() << std::endl;
238 double ESum_Reco = 0.0;
239 double ESum_Reco_Correct = 0.0;
240 double ESum_Reco_MC_Correct = 0.0;
241 double ESum_Reco_Wrong = 0.0;
242 double ESum_Reco_MC_All = 0.0;
243 double ESum_Reco_Meas = 0.0;
247 int nCorrectEtaPrime = 0;
251 int nRecoEtaPrime = 0;
253 while( ReconstructedParticle* ggp = ggpIt.next() ) {
255 double Egg_Meas = 0.0;
259 streamlog_out(DEBUG) <<
" GammaGammaParticle " << nRecoPi0 <<
" type = " << ggp->getType() <<
" E = " << ggp->getEnergy()
260 <<
" GoodnessOfPid " << ggp->getGoodnessOfPID() << std::endl;
261 streamlog_out(DEBUG) <<
" Momentum = " << ggp->getMomentum()[0] <<
" " << ggp->getMomentum()[1] <<
" " << ggp->getMomentum()[2] << std::endl;
263 if(ggp->getType()==111)nRecoPi0++;
264 if(ggp->getType()==221)nRecoEta++;
265 if(ggp->getType()==331)nRecoEtaPrime++;
267 ESum_Reco += ggp->getEnergy();
270 const EVENT::ReconstructedParticleVec& gammas = ggp->getParticles ();
276 double sumTrueP[3] = {0, 0, 0};
278 double sumP[3] = {0, 0, 0};
279 double sumWeight = 0;
280 MCParticle* mcgps[2];
282 streamlog_out(DEBUG) <<
" Consitituent gammas.size() " << gammas.size() << std::endl;
284 for (
unsigned int igamma = 0; igamma < gammas.size(); igamma++) {
286 streamlog_out(DEBUG) <<
" Gamma RP constituent of GGP " << igamma <<
" type = " << gammas[igamma]->getType()
287 <<
" Emeas = " << gammas[igamma]->getEnergy() << std::endl;
288 streamlog_out(DEBUG) <<
" Momentum = " << gammas[igamma]->getMomentum()[0] <<
" "
289 << gammas[igamma]->getMomentum()[1] <<
" "
290 << gammas[igamma]->getMomentum()[2] << std::endl;
292 sumE += gammas[igamma]->getEnergy();
294 Egg_Meas += gammas[igamma]->getEnergy();
297 for (
int i = 0; i < 3; i++) sumP[i] += gammas[igamma]->getMomentum()[i];
298 streamlog_out(DEBUG) <<
" get mc particle for gamma " << igamma << std::endl;
299 const EVENT::LCObjectVec& truevec = rec2mcNav.getRelatedToObjects(gammas[igamma]);
300 streamlog_out(DEBUG) <<
" truthvec has length " << truevec.size() << std::endl;
301 const EVENT::FloatVec& truthweightvec = rec2mcNav.getRelatedToWeights(gammas[igamma]);
303 double maxcaloweight = 0;
304 int imaxcaloweight = -1;
305 double maxtrckweight = 0;
306 int imaxtrckweight = -1;
307 double maxweight = 0;
311 bool isConversion =
false;
313 if (truevec.size() == 2) {
314 MCParticle* el1 = (MCParticle*) truevec.at(0);
315 MCParticle* el2 = (MCParticle*) truevec.at(1);
316 if ((el1->getPDG() == 11 && el2->getPDG() == -11) || (el1->getPDG() == -11 && el2->getPDG() == 11)) {
317 MCParticle* mo1 = el1->getParents()[0];
318 MCParticle* mo2 = el2->getParents()[0];
319 if (mo1->getPDG() == 22 && mo1 == mo2) {
320 streamlog_out(MESSAGE) <<
" found conversion - using mother photon: "
321 <<
" true PDGs = " << el1->getPDG() <<
", " << el2->getPDG()
322 <<
", true parent PDG = " << mo1->getPDG() << std::endl;
324 maxweight = double( (
int(truthweightvec.at(0))/10000 +
int(truthweightvec.at(1))/10000)/1000. );
332 for (
unsigned int irel = 0; irel < truevec.size(); irel++) {
333 MCParticle* dummy = (MCParticle*) truevec.at(irel);
337 double momentumMCSquared = 0.0;
338 for(
int i=0;i<3;++i){
339 cosg += dummy->getMomentum()[i]*gammas[igamma]->getMomentum()[i];
340 momentumMCSquared += pow(dummy->getMomentum()[i],2);
342 cosg = cosg/(sqrt(momentumMCSquared)*gammas[igamma]->getEnergy());
344 streamlog_out(DEBUG) <<
" irel " << irel <<
" E = " << dummy->getEnergy() <<
", truew = " << int(truthweightvec.at(irel))
345 <<
", true PDG = " << dummy->getPDG() <<
" cos(RP - MC) " << cosg
346 <<
", true par. PDG = " << dummy->getParents()[0]->getPDG()
347 <<
", recow%10000 (track) = " << int(truthweightvec.at(irel))%10000
348 <<
", recow/10000 (calo) = " <<
int(truthweightvec.at(irel))/10000 << std::endl;
349 double truthcaloweight = double( (
int(truthweightvec.at(irel))/10000)/1000. );
350 if (dummy->getPDG() == 22 && truthcaloweight > maxcaloweight) {
351 imaxcaloweight = irel;
352 maxcaloweight = truthcaloweight;
354 double truthtrckweight = double((
int(truthweightvec.at(irel))%10000)/1000.);
355 if (dummy->getPDG() == 22 && truthtrckweight > maxtrckweight) {
356 imaxtrckweight = irel;
357 maxtrckweight = truthtrckweight;
360 streamlog_out(DEBUG) <<
" found true photon at imaxcaloweight = " << imaxcaloweight <<
" with weight = " << maxcaloweight << std::endl ;
361 streamlog_out(DEBUG) <<
" found true photon at imaxtrckweight = " << imaxtrckweight <<
" with weight = " << maxtrckweight << std::endl ;
363 maxweight = maxcaloweight;
364 imaxweight = imaxcaloweight;
365 if (maxtrckweight > maxcaloweight) {
366 maxweight = maxtrckweight;
367 imaxweight = imaxtrckweight;
371 if (maxweight < 0.1) {
372 streamlog_out(DEBUG) <<
" weight of photon = " << maxweight <<
" is too small - don't count as correct" << std::endl ;
376 streamlog_out(DEBUG) <<
" found true photon at imaxweight = " << imaxweight <<
" with weight = " << maxweight << std::endl ;
377 mcg = (MCParticle*) truevec.at(imaxweight);
386 sumWeight += maxweight;
387 sumTrueE += mcg->getEnergy();
388 for (
int i = 0; i < 3; i++) sumTrueP[i] += mcg->getMomentum()[i];
390 streamlog_out(DEBUG) <<
" Gamma MCParticle of GGP " << igamma
391 <<
" Etrue = " << mcg->getEnergy() << std::endl;
393 ESum_Reco_MC_All += mcg->getEnergy();
396 mcgps[igamma] = mcg->getParents()[0];
397 if (!mcgps[igamma])
continue;
398 if (mcgps[igamma]->getPDG() == typeRequired ) {
401 streamlog_out(MESSAGE) <<
"(correct) PDG of photon's parent is = " << mcgps[igamma]->getPDG() << std::endl ;
402 pdg = mcgps[igamma]->getPDG();
405 streamlog_out(MESSAGE) <<
"(wrong) PDG of photon's parent is = " << mcgps[igamma]->getPDG() << std::endl ;
409 streamlog_out(DEBUG) <<
" ntruephoton = " << ntruephoton << std::endl;
414 if (mcgps[0] && mcgps[1] && mcgps[0] == mcgps[1] && mcgps[0]->getPDG() == typeRequired ) {
415 double rVertexSquared = 0.0;
416 for(
int i=0; i<=2; i++){
417 rVertexSquared += pow(mcgps[0]->getVertex()[i],2);
419 if(rVertexSquared < 10000.0)istrue = 1;
421 pdg = mcgps[0]->getPDG();
422 streamlog_out(MESSAGE) <<
"(fully correct) PDG of both photons parent is = " << pdg <<
" Etrue = " << mcgps[0]->getEnergy()
423 <<
" VTX squared = " << rVertexSquared << std::endl ;
424 ESum_Reco_Correct += ggp->getEnergy();
425 ESum_Reco_MC_Correct += mcgps[0]->getEnergy();
426 ESum_Reco_Meas += Egg_Meas;
427 if(pdg == 111)nCorrectPi0++;
428 if(pdg == 221)nCorrectEta++;
429 if(pdg == 331)nCorrectEtaPrime++;
433 recparcol->addElement(ggp);
436 streamlog_out(MESSAGE) <<
"(Non-prompt associated) PDG of both photons parent is = " << pdg <<
" Etrue = " << mcgps[0]->getEnergy()
437 <<
" VTX squared = " << rVertexSquared << std::endl ;
441 ESum_Reco_Wrong += ggp->getEnergy();
446 if(typeRequired == 111)streamlog_out(MESSAGE) <<
" SUMMARY 111 " << nCorrectPi0 <<
" "
447 << ESum_Reco_Correct <<
" " << ESum_Reco_MC_Correct <<
" " << ESum_Reco_Meas << endl;
448 if(typeRequired == 221)streamlog_out(MESSAGE) <<
" SUMMARY 221 " << nCorrectEta <<
" "
449 << ESum_Reco_Correct <<
" " << ESum_Reco_MC_Correct <<
" " << ESum_Reco_Meas << endl;
450 if(typeRequired == 331)streamlog_out(MESSAGE) <<
" SUMMARY 331 " << nCorrectEtaPrime <<
" "
451 << ESum_Reco_Correct <<
" " << ESum_Reco_MC_Correct <<
" " << ESum_Reco_Meas << endl;
483 cout <<
"======================================== event " <<
nEvt << std::endl ;
std::string _ggResonanceName
virtual void processEvent(LCEvent *evt)
Called for every event - the working horse.
GammaGammaCandidateTruthFilter aGammaGammaCandidateTruthFilter
virtual void init()
Called at the begin of the job before anything is read.
std::string _outputParticleCollectionName
virtual void processRunHeader(LCRunHeader *run)
Called for every run.
virtual void end()
Called after data processing for clean up.
GammaGammaCandidateTruthFilter processor Checks which GammaGammaCandidates are correct author: Graham...
GammaGammaCandidateTruthFilter()
virtual void check(LCEvent *evt)
std::vector< LCCollection * > LCCollectionVec
std::string _mcParticleCollectionName
std::string _gammaGammaParticleCollectionName