CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PFAlgoTestBenchElectrons.cc
Go to the documentation of this file.
1 // Dummy Test For Electrons Daniele.Benedetti@cern.ch
2 
3 
6 
7 using namespace std;
8 using namespace reco;
9 
10 
12  std::list<PFBlockRef>& hcalBlockRefs,
13  std::list<PFBlockRef>& ecalBlockRefs)
14 {
15 
16  //cout<<"electron test bench: process block"
17  // <<(*blockref)<<endl;
18 
19 
20  const reco::PFBlock& block = *blockref;
21  PFBlock::LinkData linkData = block.linkData();
23 
24  std::vector<bool> active(elements.size(), true );
25  vector<unsigned> mainecal_index;
26  for(unsigned iEle=0; iEle<elements.size(); iEle++) {
27  PFBlockElement::Type type = elements[iEle].type();
28  if (type == reco::PFBlockElement::ECAL ) {
29  mainecal_index.push_back(iEle);
30  }
31  }
32 
33  std::map<unsigned, unsigned> FinalBremECALIndex;
34  unsigned ECALGSF_index = 1000;
35  unsigned GSF_index = 1000;
36  for(unsigned iEle=0; iEle<elements.size(); iEle++) {
37 
38 
39  PFBlockElement::Type type = elements[iEle].type();
40 
41  if (type == reco::PFBlockElement::GSF ) {
42  GSF_index = iEle;
43 
44  // linked ECAL clusters
45  std::multimap<double, unsigned> ecalElems;
46  block.associatedElements( iEle, linkData,
47  ecalElems ,
49 
50  typedef std::multimap<double, unsigned>::iterator IE;
51 
52  float chi2GSFFinal = 1000;
53  for(IE ie = ecalElems.begin(); ie != ecalElems.end(); ++ie ) {
54  double chi2 = ie->first;
55  unsigned index = ie->second;
56  if (chi2 < chi2GSFFinal) {
57  chi2GSFFinal = chi2;
58  ECALGSF_index = index;
59  }
60  }
61 
62  std::multimap<double, unsigned> Brems;
63 
64  block.associatedElements( iEle, linkData,
65  Brems ,
67  typedef std::multimap<double, unsigned>::iterator IB;
68 
69  vector< pair<double, unsigned> > ecalindexforbrem;
70  vector<unsigned> brem_index;
71  for(IB iee = Brems.begin(); iee != Brems.end(); ++iee ) {
72 
73  unsigned index = iee->second;
74 
75  std::multimap<double, unsigned> ecalBrems;
76  block.associatedElements( index, linkData,
77  ecalBrems ,
79  typedef std::multimap<double, unsigned>::iterator IEB;
80  float chi2BremFinal = 1000;
81  unsigned ECALBREM_index = 1000;
82 
83  for(IEB ieb = ecalBrems.begin(); ieb != ecalBrems.end(); ++ieb ) {
84  // Two cases: first there is a ecalGSF=brem chi2 < chi2ecalGSF ?
85 
86 
87  if (ieb->second != ECALGSF_index) {
88 
89  double chi2_eb = ieb->first;
90  unsigned index_eb = ieb->second;
91  if (chi2_eb < chi2BremFinal) {
92  chi2BremFinal = chi2_eb;
93  ECALBREM_index = index_eb;
94  }
95  }
96  }
97  if (ECALBREM_index != 1000){
98  ecalindexforbrem.push_back(make_pair(chi2BremFinal,ECALBREM_index));
99  // for each brem (same size that brems)
100  brem_index.push_back(index);
101  }
102  }
103  for (unsigned ie=0;ie<mainecal_index.size();ie++){
104  unsigned c_brem = 0;
105 
106  double chi2best = 1000;
107  unsigned final_ecal = 1000;
108  unsigned final_brem = 1000;
109  if (mainecal_index[ie] != ECALGSF_index) {
110  for (unsigned i2eb = 0; i2eb < ecalindexforbrem.size(); i2eb++ ) {
111  unsigned temp_ecal_index = (ecalindexforbrem[i2eb]).second;
112  double temp_chi2 = (ecalindexforbrem[i2eb]).first;
113 
114  if (temp_ecal_index == mainecal_index[ie] ) {
115  if (temp_chi2 < chi2best ){
116  chi2best = temp_chi2;
117  final_ecal = temp_ecal_index;
118  final_brem = brem_index[c_brem];
119  }
120  }
121  c_brem++;
122  }
123  if (chi2best < 1000) {
124  FinalBremECALIndex.insert(make_pair(final_brem,final_ecal));
125  }
126  }
127 
128  }
129 
130 
131 
132  bool ElectronId = false;
133 
134  // perform electron iD
135  //Start ***************************************
136  ElectronId = true;
137  //End ***************************************
138 
139  // Lock the various elements
140  // NOTE very lose cuts!
141  if (ElectronId) {
142  if (chi2GSFFinal < 1000) {
143 
144  active[iEle] = false; //GSF
145  active[ECALGSF_index] = false; // ECAL associated to GSF
146  // Lock Brem and ECAL associated to brem
147  typedef std::map<unsigned, unsigned>::iterator IT;
148  for (map<unsigned, unsigned>::iterator it = FinalBremECALIndex.begin(); it != FinalBremECALIndex.end(); ++it ) {
149  unsigned index_brem = it->first;
150  unsigned index_ecalbrem = it->second;
151  active[index_brem]=false;
152  active[index_ecalbrem] = false;
153  }
154  }
155  } // End if Electron ID
156  } // End GSF type
157  } // Run on elements
158 
159 
160  vector<pair< bool, vector<unsigned int> > > associate;
161 
162  for(unsigned iEle=0; iEle<elements.size(); iEle++) {
163 
164  if (active[iEle] == true) {
165  vector<unsigned> assoel(0);
166  associate.push_back(make_pair(active[iEle],assoel));
167  }
168  if (active[iEle] == false){
169  PFBlockElement::Type type = elements[iEle].type();
170  if (type == reco::PFBlockElement::GSF) {
171  vector<unsigned> assoel(0);
172  // push back tk track: to be done
173 
174  // push back ecal cluster associate to gsf track
175  assoel.push_back(ECALGSF_index);
176  // push back selected brems
177  for (map<unsigned, unsigned>::iterator it = FinalBremECALIndex.begin(); it != FinalBremECALIndex.end(); ++it ) {
178  unsigned index_brem = it->first;
179  assoel.push_back(index_brem);
180  }
181  associate.push_back(make_pair(active[iEle],assoel));
182  // push back hcal cluster to be done
183  // push back ps cluster to be done
184  }
185  if (type == reco::PFBlockElement::BREM) {
186  vector<unsigned> assoel(0);
187  // push back GSF track
188  assoel.push_back(GSF_index);
189 
190  // push_back ecal clusters associate to the brem
191  for (map<unsigned, unsigned>::iterator it = FinalBremECALIndex.begin(); it != FinalBremECALIndex.end(); ++it ) {
192  if (it->first == iEle) {
193  unsigned index_ecalbrem = it->second;
194  assoel.push_back(index_ecalbrem);
195  }
196  }
197  associate.push_back(make_pair(active[iEle],assoel));
198 
199  // push back hcal cluster to be done
200  // push back ps cluster to be done
201  }
202  if (type == reco::PFBlockElement::ECAL) {
203  if (iEle == ECALGSF_index) {
204  // cluster associate to the gsf track
205  // push back the associate gsf track
206  vector<unsigned> assoel(0);
207  assoel.push_back(GSF_index);
208  associate.push_back(make_pair(active[iEle],assoel));
209  }
210  for (map<unsigned, unsigned>::iterator it = FinalBremECALIndex.begin(); it != FinalBremECALIndex.end(); ++it ) {
211  unsigned index_ecalbrem = it->second;
212  unsigned index_brem = it->first;
213  if (iEle == index_ecalbrem) { // push back the brems associate to ecal
214  vector<unsigned> assoel(0);
215  assoel.push_back(index_brem);
216  associate.push_back(make_pair(active[iEle],assoel));
217  }
218  }
219  }
220  }
221  }
222  // here create the object with the block and associate (and active if needed)
223 
224 } // End loop on Blocks
225 
226 
type
Definition: HCALResponse.h:21
std::map< unsigned int, Link > LinkData
Definition: PFBlock.h:46
size_type size() const
Definition: OwnVector.h:254
list elements
Definition: asciidump.py:414
const edm::OwnVector< reco::PFBlockElement > & elements() const
Definition: PFBlock.h:107
const LinkData & linkData() const
Definition: PFBlock.h:112
U second(std::pair< T, U > const &p)
void push_back(D *&d)
Definition: OwnVector.h:280
virtual void processBlock(const reco::PFBlockRef &blockref, std::list< reco::PFBlockRef > &hcalBlockRefs, std::list< reco::PFBlockRef > &ecalBlockRefs)
std::vector< LinkConnSpec >::const_iterator IT
void associatedElements(unsigned i, const LinkData &linkData, std::multimap< double, unsigned > &sortedAssociates, reco::PFBlockElement::Type type=PFBlockElement::NONE, LinkTest test=LINKTEST_RECHIT) const
Definition: PFBlock.cc:75
Block of elements.
Definition: PFBlock.h:30