Dear ROOTers,
For my analysis, I have a piece of code that works fine using nominal systematics. The structure of the code looks something like this
std::map < std::string, TH1*> histogram_map {};
//declare and fill histogram map with some histograms
//open output file
//(loop over events in file){
// calculate weight of event
// calculate some reconstructed objects
// fill histograms with results
}
//save histograms
//close file
Now, I am trying to include different systematics into my analysis
std::map < std::string, TH1*> histogram_map {};
std::map < std::string, Double_t > syst_map{};
//declare and fill histogram map with some histograms
//open output file
//create folders for the different systematics
//save empty histograms inside the folders (same histograms as before, just for each systematic now)
(loop over events in file){
//calculate some reconstructed objects
for( auto iter : syst_map ){
// calculate event weight for the systematic
OpenFile->cd(iter.first.c_str());
TDirectory *dir = gDirectory();
//loop over the keys and replace the histogram_map histograms with the histograms (with n events) saved in the folder by doing
TKey *key;
while ( ( key = ( TKey* ) next() ) ){
std::string get_name( key->GetName() );
if( std::strncmp( key->GetClassName(), "TH1F", 4 ) == 0 )
histogram_map[get_name] = (TH1F*)dir->Get ( key->GetName() ) );
//same for 2D, but with TH2F
}
//fill histogram_map histograms with the new event
//loop over the histogram map and save the histograms again (n + 1 entries):
(loop over histogram map)
hist_iter.second->Write( iter->first.c_str(), TObject::kOverwrite );
}
}
close file
Unfortunately, jobs submitted using this method get killed quickly due to reaching their used memory limit. I have found a workaround, which is closing the file after saving the empty histograms, and then opening and closing it inside the systematics loop every time, but this results in the script being painfully slow. I am able to submit separate jobs for separate systematics and hadd the files later on, but I would like to do all of the systematics at once, since this way I am doing the “calculate some reconstructed objects” step only once per event, and the number of submitted jobs will be a lot fewer (although a lot slower). Any suggestions are welcome.
Thank you,
Vangi