0

I am trying to apply 2D maps to my code for matching entries in multiple maps.

std::map<Float_t,std::map<Float_t,std::Int_t>> map1;
Int_t nrows1 = Space1->GetEntries();

for (Int_t irow1=0; irow1 < nrows1; ++irow1 ) {
  Space1->GetEntry(irow1);
  Float_t key1 = x1;
  Float_t keyA = y1;
  map1[key1][keyA] = irow1;
}

std::map<Float_t,std::map<Float_t,std::Int_t>> map2;
Int_t nrows2 = Space2->GetEntries();

for (Int_t irow2=0; irow2 < nrows2; ++irow2 ) {
  Space2->GetEntry(irow2);
  Float_t key2 = x2;
  Float_t keyB = y2;
  map1[key2][keyB] = irow2;
}

for (Int_t ientry1=0; ientry1<Space1->GetEntries(); ientry1++) {                                                                                                                         

  Space1->GetEntry(ientry1);
  Float_t key1 = x1;
  Float_t keyA = y1;

  if(!map1.count(key1) && !map1.count(keyA)) continue;                                          
  if(!map2.count(key1) && !map2.count(keyA)) continue;     
  Int_t entry1 = map1[key1][keyA];
  Int_t entry2 = map2[key1][keyA];                                                           

  Space1->GetEntry(entry1);
  Space2->GetEntry(entry2);
  //more happens after.
}

Example table with x and y values

I am having the problem that it will match X when x=4 then when Y when y=1. I only want entries from Space 1 and Space 2 when both x and y match like entry 4 from Space 1 and entry 5 from Space 2.

Bear
  • 1
  • 1
  • Completely not understand what is your problem, but `std::map` can be used for `float` and `double` as is, you need little magic, because usage `==` for float is `no no`, see http://stackoverflow.com/questions/6684573/floating-point-keys-in-stdmap – fghj Nov 10 '15 at 23:13
  • I am searching for entries in Space 1 that matches entries in Space 2. The problem is once is searches though X value(see example) in Space 1 it will find a 4 in entry 2 then searching through Y values it will then see a 1 from a different entry , entry 1. I am only wanting where both X AND Y values match like entry 4 in Space 1 and entry 5 in Space 2 – Bear Nov 11 '15 at 00:00
  • Can you provide create full example, which is possible to run and see what is not working? – fghj Nov 11 '15 at 01:22

0 Answers0