I am having trouble trying to fill some histograms. I am able to fill the first set of histograms (DiLeptMass) but it crashes when I then try to fill the DiLeptLifetime histograms.
I have issue when filling, i.e the programme crashes at hist->Fill(Iter2->second.at(0),1);
I’ve included the relevant parts of the code.
std::map< TString, TH1* > myMap; //map to store the histograms
std::map< RunEvt, std::vector<Double_t> > MapOfEventsAndMasses //Map of Events and DiLept Masses
std::map < RunEvt, std::vector<Double_t> > MapOfEventsAndLifetimes; //map of Events and DiLept Lifetimes
for( Int_t i=0; i<5; i++){
for(Int_t j=0; j<4; j++){
TString myString = Form("DiLeptMass_%s%i%i", "DiLeptMass", i, j);
TH1D *hist = new TH1D(myString, "test_mass_plot", 80.0, mass_low[i], mass_high[i]);
myMap[myString] = hist;
// cout << myString << " " << myMap[myString] << endl;
myString = Form("DiLeptLifetimes_%s%i%i", "DileptLifetimes", i , j);
hist = new TH1D (myString, "test_lifetime_plot", 200.0, lifetime_low[j], lifetime_high[j]);
myMap[myString]= hist;
//cout << myString << " " << myMap[myString] << endl;
}
}
//##################################
// CREATE MAPS OF THE VARIABLES
//##################################
if(MapOfEventsAndMasses.find(my_event) == MapOfEventsAndMasses.end()){ //change event to my_event
std::vector<Double_t> tempVec;
tempVec.push_back(DiLept_M);
MapOfEventsAndMasses[my_event] = tempVec;
}else{
MapOfEventsAndMasses[my_event].push_back(DiLept_M);
}
if(MapOfEventsAndLifetimes.find(my_event) == MapOfEventsAndLifetimes.end()){
std::vector<Double_t> lifetimeVec; //Declaring a vector to hold Photon pTs
lifetimeVec.push_back(DiMuonVertex_Tau); //If the index exists, acess the second index of the map, and using push back load the Photon_Pt into the vector
MapOfEventsAndLifetimes[my_event] = lifetimeVec;
}
else{
MapOfEventsAndLifetimes[my_event].push_back(DiMuonVertex_Tau);
}
//#######################
/// DECLARE ITERATORS
// #####################
std::map < RunEvt, std::vector <Double_t> >::iterator Iter1 = MapOfEventsAndMasses.begin();
std::map < RunEvt, std::vector <Double_t> >::iterator Iter1_End = MapOfEventsAndMasses.end();
std::map < RunEvt, std::vector <Double_t> >::iterator Iter2 = MapOfEventsAndLifetimes.begin();
std::map < RunEvt, std::vector <Double_t> >::iterator Iter2_End = MapOfEventsAndLifetimes.end();
//#######################################
// Iterate through the variables and fill histograms
//########################################
while(Iter1 != Iter1_End){
if(Iter1->second.size()==1 && Iter2->second.size()==1){
for (Int_t i=0; i<5; ++i) {
for(Int_t j=0; j<4; ++j){
if (Iter1->second[0] < mass_low[i] || Iter1->second[0] > mass_high[i]) continue; // failed cut
Iter2 = MapOfEventsAndLifetimes.find(Iter1->first);
if (Iter2->second[0] < lifetime_low[j] || Iter2->second[0] > lifetime_high[j]) continue; // failed cut
TString myString = Form("DiLeptMass_%s%i%i", "DiLeptMass", i, j);
auto hist = myMap[myString];
//cout << "DEBUG: " << myString << " " << hist << " " << Iter1->second.size() << endl;
assert(hist);
hist->Fill(Iter1->second.at(0),1);
myString = Form("DiLeptLifetimes_%s%i%i", "DiLeptLifetimes", i, j);
hist = myMap[myString];
//cout << "DEBUG: " << myString << " " << hist << " " << Iter2->second.size() << endl;
//assert(hist);
hist->Fill(Iter2->second.at(0),1);
}
}
}