|
| 1 | +#include "RecoParticleFlow/PFClusterProducer/test/PFClusterComparator.h" |
| 2 | +#include "DataFormats/ParticleFlowReco/interface/PFCluster.h" |
| 3 | + |
| 4 | +#include "FWCore/Framework/interface/ESHandle.h" |
| 5 | + |
| 6 | +#include "FWCore/MessageLogger/interface/MessageLogger.h" |
| 7 | +#include "FWCore/Utilities/interface/Exception.h" |
| 8 | +#include "FWCore/Framework/interface/EventSetup.h" |
| 9 | + |
| 10 | +#include <iomanip> |
| 11 | + |
| 12 | +using namespace std; |
| 13 | +using namespace edm; |
| 14 | +using namespace reco; |
| 15 | + |
| 16 | +PFClusterComparator::PFClusterComparator(const edm::ParameterSet& iConfig) { |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | + inputTagPFClusters_ |
| 21 | + = iConfig.getParameter<InputTag>("PFClusters"); |
| 22 | + |
| 23 | + inputTagPFClustersCompare_ |
| 24 | + = iConfig.getParameter<InputTag>("PFClustersCompare"); |
| 25 | + |
| 26 | + verbose_ = |
| 27 | + iConfig.getUntrackedParameter<bool>("verbose",false); |
| 28 | + |
| 29 | + printBlocks_ = |
| 30 | + iConfig.getUntrackedParameter<bool>("printBlocks",false); |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | + LogDebug("PFClusterComparator") |
| 35 | + <<" input collection : "<<inputTagPFClusters_ ; |
| 36 | + |
| 37 | +} |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | +PFClusterComparator::~PFClusterComparator() { } |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | +void |
| 46 | +PFClusterComparator::beginRun(const edm::Run& run, |
| 47 | + const edm::EventSetup & es) { } |
| 48 | + |
| 49 | + |
| 50 | +void PFClusterComparator::analyze(const Event& iEvent, |
| 51 | + const EventSetup& iSetup) { |
| 52 | + |
| 53 | + // get PFClusters |
| 54 | + |
| 55 | + Handle<PFClusterCollection> pfClusters; |
| 56 | + fetchCandidateCollection(pfClusters, |
| 57 | + inputTagPFClusters_, |
| 58 | + iEvent ); |
| 59 | + |
| 60 | + Handle<PFClusterCollection> pfClustersCompare; |
| 61 | + fetchCandidateCollection(pfClustersCompare, |
| 62 | + inputTagPFClustersCompare_, |
| 63 | + iEvent ); |
| 64 | + |
| 65 | + // get PFClusters for isolation |
| 66 | + |
| 67 | + std::cout << "There are " << pfClusters->size() << " PFClusters in the original cluster collection." << std::endl; |
| 68 | + std::cout << "There are " << pfClustersCompare->size() << " PFClusters in the new cluster collection." << std::endl; |
| 69 | + |
| 70 | + std::cout << std::flush << "---- COMPARING OLD TO NEW ----" |
| 71 | + << std::endl << std::flush; |
| 72 | + |
| 73 | + for( unsigned i=0; i<pfClusters->size(); i++ ) { |
| 74 | + const reco::PFCluster& cluster = pfClusters->at(i); |
| 75 | + bool foundmatch = false; |
| 76 | + for( unsigned k=0; k<pfClustersCompare->size(); ++k ) { |
| 77 | + const reco::PFCluster& clustercomp = pfClustersCompare->at(k); |
| 78 | + if( cluster.seed() == clustercomp.seed() ) { |
| 79 | + foundmatch = true; |
| 80 | + const double denergy = std::abs(cluster.energy() - |
| 81 | + clustercomp.energy()); |
| 82 | + const double dcenergy = std::abs(cluster.correctedEnergy() - |
| 83 | + clustercomp.correctedEnergy()); |
| 84 | + const double dx = std::abs(cluster.position().x() - |
| 85 | + clustercomp.position().x()); |
| 86 | + const double dy = std::abs(cluster.position().y() - |
| 87 | + clustercomp.position().y()); |
| 88 | + const double dz = std::abs(cluster.position().z() - |
| 89 | + clustercomp.position().z()); |
| 90 | + if( denergy/std::abs(cluster.energy()) > 1e-5 ) { |
| 91 | + std::cout << " " << cluster.seed() |
| 92 | + << " Energies different by larger than tolerance! " |
| 93 | + << "( "<< denergy << " )" |
| 94 | + << " Old: " << std::setprecision(7) |
| 95 | + << cluster.energy() << " GeV , New: " |
| 96 | + << clustercomp.energy() << " GeV" << std::endl; |
| 97 | + } |
| 98 | + if( dcenergy/std::abs(cluster.correctedEnergy()) > 1e-5 ) { |
| 99 | + std::cout << " " << cluster.seed() |
| 100 | + << " Corrected energies different by larger than tolerance! " |
| 101 | + << "( "<< denergy << " )" |
| 102 | + << " Old: " << std::setprecision(7) |
| 103 | + << cluster.correctedEnergy() << " GeV , New: " |
| 104 | + << clustercomp.correctedEnergy() << " GeV" << std::endl; |
| 105 | + } |
| 106 | + std::cout << std::flush; |
| 107 | + if( dx/std::abs(cluster.position().x()) > 1e-5 ) { |
| 108 | + std::cout << "***" << cluster.seed() |
| 109 | + << " X's different by larger than tolerance! " |
| 110 | + << "( "<< dx << " )" |
| 111 | + << " Old: " << std::setprecision(7) |
| 112 | + << cluster.position().x() << " , New: " |
| 113 | + << clustercomp.position().x() << std::endl; |
| 114 | + } |
| 115 | + std::cout << std::flush; |
| 116 | + if( dy/std::abs(cluster.position().y()) > 1e-5 ) { |
| 117 | + std::cout << "---" << cluster.seed() |
| 118 | + << " Y's different by larger than tolerance! " |
| 119 | + << "( "<< dy << " )" |
| 120 | + << " Old: " << std::setprecision(7) |
| 121 | + << cluster.position().y() << " , New: " |
| 122 | + << clustercomp.position().y() << std::endl; |
| 123 | + } |
| 124 | + std::cout << std::flush; |
| 125 | + if( dz/std::abs(cluster.position().z()) > 1e-5 ) { |
| 126 | + std::cout << "+++" << cluster.seed() |
| 127 | + << " Z's different by larger than tolerance! " |
| 128 | + << "( "<< dz << " )" |
| 129 | + << " Old: " << std::setprecision(7) |
| 130 | + << cluster.position().z() << " , New: " |
| 131 | + << clustercomp.position().z() << std::endl; |
| 132 | + } |
| 133 | + std::cout << std::flush; |
| 134 | + } |
| 135 | + } |
| 136 | + if( !foundmatch ) { |
| 137 | + std::cout << "Seed in old clusters and not new: " |
| 138 | + << cluster << std::endl; |
| 139 | + } |
| 140 | + } |
| 141 | + |
| 142 | + std::cout << std::flush << "---- COMPARING NEW TO OLD ----" |
| 143 | + << std::endl << std::flush; |
| 144 | + |
| 145 | + for( unsigned i=0; i<pfClustersCompare->size(); i++ ) { |
| 146 | + const reco::PFCluster& cluster = pfClustersCompare->at(i); |
| 147 | + bool foundmatch = false; |
| 148 | + for( unsigned k=0; k<pfClusters->size(); ++k ) { |
| 149 | + const reco::PFCluster& clustercomp = pfClusters->at(k); |
| 150 | + if( cluster.seed() == clustercomp.seed() ) { |
| 151 | + foundmatch = true; |
| 152 | + |
| 153 | + } |
| 154 | + } |
| 155 | + if( !foundmatch ) { |
| 156 | + std::cout << "Seed in new clusters and not old: " |
| 157 | + << cluster << std::endl; |
| 158 | + } |
| 159 | + } |
| 160 | + std::cout << std::flush; |
| 161 | +} |
| 162 | + |
| 163 | + |
| 164 | + |
| 165 | +void |
| 166 | +PFClusterComparator::fetchCandidateCollection(Handle<reco::PFClusterCollection>& c, |
| 167 | + const InputTag& tag, |
| 168 | + const Event& iEvent) const { |
| 169 | + |
| 170 | + bool found = iEvent.getByLabel(tag, c); |
| 171 | + |
| 172 | + if(!found ) { |
| 173 | + ostringstream err; |
| 174 | + err<<" cannot get PFClusters: " |
| 175 | + <<tag<<endl; |
| 176 | + LogError("PFClusters")<<err.str(); |
| 177 | + throw cms::Exception( "MissingProduct", err.str()); |
| 178 | + } |
| 179 | + |
| 180 | +} |
| 181 | + |
| 182 | + |
| 183 | + |
| 184 | +DEFINE_FWK_MODULE(PFClusterComparator); |
0 commit comments