00001
00002
00003
00004 #include "RecoParticleFlow/PFAlgo/interface/PFAlgoTestBenchElectrons.h"
00005 #include "DataFormats/ParticleFlowReco/interface/PFBlock.h"
00006
00007 using namespace std;
00008 using namespace reco;
00009
00010
00011 void PFAlgoTestBenchElectrons::processBlock(const reco::PFBlockRef& blockref,
00012 std::list<PFBlockRef>& hcalBlockRefs,
00013 std::list<PFBlockRef>& ecalBlockRefs)
00014 {
00015
00016
00017
00018
00019
00020 const reco::PFBlock& block = *blockref;
00021 PFBlock::LinkData linkData = block.linkData();
00022 const edm::OwnVector< reco::PFBlockElement >& elements = block.elements();
00023
00024 std::vector<bool> active(elements.size(), true );
00025 vector<unsigned> mainecal_index;
00026 for(unsigned iEle=0; iEle<elements.size(); iEle++) {
00027 PFBlockElement::Type type = elements[iEle].type();
00028 if (type == reco::PFBlockElement::ECAL ) {
00029 mainecal_index.push_back(iEle);
00030 }
00031 }
00032
00033 std::map<unsigned, unsigned> FinalBremECALIndex;
00034 unsigned ECALGSF_index = 1000;
00035 unsigned GSF_index = 1000;
00036 for(unsigned iEle=0; iEle<elements.size(); iEle++) {
00037
00038
00039 PFBlockElement::Type type = elements[iEle].type();
00040
00041 if (type == reco::PFBlockElement::GSF ) {
00042 GSF_index = iEle;
00043
00044
00045 std::multimap<double, unsigned> ecalElems;
00046 block.associatedElements( iEle, linkData,
00047 ecalElems ,
00048 reco::PFBlockElement::ECAL );
00049
00050 typedef std::multimap<double, unsigned>::iterator IE;
00051
00052 float chi2GSFFinal = 1000;
00053 for(IE ie = ecalElems.begin(); ie != ecalElems.end(); ++ie ) {
00054 double chi2 = ie->first;
00055 unsigned index = ie->second;
00056 if (chi2 < chi2GSFFinal) {
00057 chi2GSFFinal = chi2;
00058 ECALGSF_index = index;
00059 }
00060 }
00061
00062 std::multimap<double, unsigned> Brems;
00063
00064 block.associatedElements( iEle, linkData,
00065 Brems ,
00066 reco::PFBlockElement::BREM );
00067 typedef std::multimap<double, unsigned>::iterator IB;
00068
00069 vector< pair<double, unsigned> > ecalindexforbrem;
00070 vector<unsigned> brem_index;
00071 for(IB iee = Brems.begin(); iee != Brems.end(); ++iee ) {
00072
00073 unsigned index = iee->second;
00074
00075 std::multimap<double, unsigned> ecalBrems;
00076 block.associatedElements( index, linkData,
00077 ecalBrems ,
00078 reco::PFBlockElement::ECAL );
00079 typedef std::multimap<double, unsigned>::iterator IEB;
00080 float chi2BremFinal = 1000;
00081 unsigned ECALBREM_index = 1000;
00082
00083 for(IEB ieb = ecalBrems.begin(); ieb != ecalBrems.end(); ++ieb ) {
00084
00085
00086
00087 if (ieb->second != ECALGSF_index) {
00088
00089 double chi2_eb = ieb->first;
00090 unsigned index_eb = ieb->second;
00091 if (chi2_eb < chi2BremFinal) {
00092 chi2BremFinal = chi2_eb;
00093 ECALBREM_index = index_eb;
00094 }
00095 }
00096 }
00097 if (ECALBREM_index != 1000){
00098 ecalindexforbrem.push_back(make_pair(chi2BremFinal,ECALBREM_index));
00099
00100 brem_index.push_back(index);
00101 }
00102 }
00103 for (unsigned ie=0;ie<mainecal_index.size();ie++){
00104 unsigned c_brem = 0;
00105
00106 double chi2best = 1000;
00107 unsigned final_ecal = 1000;
00108 unsigned final_brem = 1000;
00109 if (mainecal_index[ie] != ECALGSF_index) {
00110 for (unsigned i2eb = 0; i2eb < ecalindexforbrem.size(); i2eb++ ) {
00111 unsigned temp_ecal_index = (ecalindexforbrem[i2eb]).second;
00112 double temp_chi2 = (ecalindexforbrem[i2eb]).first;
00113
00114 if (temp_ecal_index == mainecal_index[ie] ) {
00115 if (temp_chi2 < chi2best ){
00116 chi2best = temp_chi2;
00117 final_ecal = temp_ecal_index;
00118 final_brem = brem_index[c_brem];
00119 }
00120 }
00121 c_brem++;
00122 }
00123 if (chi2best < 1000) {
00124 FinalBremECALIndex.insert(make_pair(final_brem,final_ecal));
00125 }
00126 }
00127
00128 }
00129
00130
00131
00132 bool ElectronId = false;
00133
00134
00135
00136 ElectronId = true;
00137
00138
00139
00140
00141 if (ElectronId) {
00142 if (chi2GSFFinal < 1000) {
00143
00144 active[iEle] = false;
00145 active[ECALGSF_index] = false;
00146
00147 typedef std::map<unsigned, unsigned>::iterator IT;
00148 for (map<unsigned, unsigned>::iterator it = FinalBremECALIndex.begin(); it != FinalBremECALIndex.end(); ++it ) {
00149 unsigned index_brem = it->first;
00150 unsigned index_ecalbrem = it->second;
00151 active[index_brem]=false;
00152 active[index_ecalbrem] = false;
00153 }
00154 }
00155 }
00156 }
00157 }
00158
00159
00160 vector<pair< bool, vector<unsigned int> > > associate;
00161
00162 for(unsigned iEle=0; iEle<elements.size(); iEle++) {
00163
00164 if (active[iEle] == true) {
00165 vector<unsigned> assoel(0);
00166 associate.push_back(make_pair(active[iEle],assoel));
00167 }
00168 if (active[iEle] == false){
00169 PFBlockElement::Type type = elements[iEle].type();
00170 if (type == reco::PFBlockElement::GSF) {
00171 vector<unsigned> assoel(0);
00172
00173
00174
00175 assoel.push_back(ECALGSF_index);
00176
00177 for (map<unsigned, unsigned>::iterator it = FinalBremECALIndex.begin(); it != FinalBremECALIndex.end(); ++it ) {
00178 unsigned index_brem = it->first;
00179 assoel.push_back(index_brem);
00180 }
00181 associate.push_back(make_pair(active[iEle],assoel));
00182
00183
00184 }
00185 if (type == reco::PFBlockElement::BREM) {
00186 vector<unsigned> assoel(0);
00187
00188 assoel.push_back(GSF_index);
00189
00190
00191 for (map<unsigned, unsigned>::iterator it = FinalBremECALIndex.begin(); it != FinalBremECALIndex.end(); ++it ) {
00192 if (it->first == iEle) {
00193 unsigned index_ecalbrem = it->second;
00194 assoel.push_back(index_ecalbrem);
00195 }
00196 }
00197 associate.push_back(make_pair(active[iEle],assoel));
00198
00199
00200
00201 }
00202 if (type == reco::PFBlockElement::ECAL) {
00203 if (iEle == ECALGSF_index) {
00204
00205
00206 vector<unsigned> assoel(0);
00207 assoel.push_back(GSF_index);
00208 associate.push_back(make_pair(active[iEle],assoel));
00209 }
00210 for (map<unsigned, unsigned>::iterator it = FinalBremECALIndex.begin(); it != FinalBremECALIndex.end(); ++it ) {
00211 unsigned index_ecalbrem = it->second;
00212 unsigned index_brem = it->first;
00213 if (iEle == index_ecalbrem) {
00214 vector<unsigned> assoel(0);
00215 assoel.push_back(index_brem);
00216 associate.push_back(make_pair(active[iEle],assoel));
00217 }
00218 }
00219 }
00220 }
00221 }
00222
00223
00224 }
00225
00226