Skip to content
Snippets Groups Projects
Commit 0c3ba142 authored by Carsten Burgard's avatar Carsten Burgard :speech_balloon:
Browse files

bugfixed systematics transfer

parent c3306981
No related branches found
No related tags found
2 merge requests!664analysis developments,!611WIP: Histogram processing harmonization
Pipeline #1730617 passed
......@@ -42,6 +42,9 @@ namespace TSBaseActions {
bool performTransfer(TQFolder * config,TQFolder* model) const {
TString mode = config->getTagStringDefault("mode","sample");
TQFolder* histograms = model->getFolder(".Histograms");
bool verbose = config->getTagBoolDefault("~verbose",false);
std::vector<TString> exceptRegions = config->getTagVString("except.Channels");
std::vector<TString> exceptSamples = config->getTagVString("except.Samples");
......@@ -76,8 +79,6 @@ namespace TSBaseActions {
int i=0;
bool verbose = config->getTagBoolDefault("verbose",false);
for(const auto& channelExp:targetChannels){
TQFolderIterator regions(model->getListOfFolders("Channel."+channelExp),true);
while(regions.hasNext()){
......@@ -118,6 +119,7 @@ namespace TSBaseActions {
}
{
TQFolderIterator newsystematics(source->getListOfFolders(systType+"*"),true);
int j = 0;
while(newsystematics.hasNext()){
TQFolder* systematic = newsystematics.readNext();
if(!systematic) continue;
......@@ -125,42 +127,51 @@ namespace TSBaseActions {
if(marked && !systematic->getTagBoolDefault(mark,false)) continue;
if(verbose) manager->info(TString::Format("\t\tcopying '%s'",systematic->GetName()));
TQFolder* copy = systematic->copy();
i++;
sample->addFolder(copy);
copy->setTagString("transferred",source->GetName());
if(systematic->hasTagString("HistoLow") && systematic->hasTagString("HistoHigh")){
TH1* nomHist = dynamic_cast<TH1*>(histograms->getObject(sample->getTagStringDefault("Histo","")));
TH1* lowHist = dynamic_cast<TH1*>(histograms->getObject(systematic->getTagStringDefault("HistoLow","")));
TH1* highHist = dynamic_cast<TH1*>(histograms->getObject(systematic->getTagStringDefault("HistoHigh","")));
if(!TQHistogramUtils::checkConsistency(nomHist,lowHist) || !TQHistogramUtils::checkConsistency(nomHist,highHist)){
manager->error(TString::Format("transferred histograms are inconsistent, skipping!\n\tnom\t%s\n\tlow\t%s\n\thigh\t%s",TQStringUtils::getDetails(nomHist).Data(),TQStringUtils::getDetails(lowHist).Data(),TQStringUtils::getDetails(highHist).Data()));
delete copy;
continue;
}
}
++j;
sample->addFolder(copy);
}
if(verbose && j==0){
manager->warn(TString::Format("\tno systematics of type %s found in '%s' matching '%s' except '%s'!",systType.Data(),source->GetName(),TQStringUtils::concat(targetSystematics,",").Data(),TQStringUtils::concat(exceptSystematics,",").Data()));
}
i += j;
}
}
}
}
}
}
return (i>0);
if(i>0) return true;
manager->error("no targets found for sample transfer!");
return false;
} else if (mode.Contains("channel",TString::kIgnoreCase)) {
TString sourceChannel;
if(!config->getTagString("source",sourceChannel)){
manager->error(TString::Format("missing required 'source' information on transfer '%s'",config->GetName()));
return false;
}
TQFolder* source = model->getFolder("Channel."+sourceChannel);
if(!source){
manager->warn(TString::Format("unable to find source channel '%s' in model '%s', skipping!",sourceChannel.Data(),model->GetName()));
return false;
}
int i=0;
bool verbose = config->getTagBoolDefault("verbose",false);
for(const auto& channelExp:targetChannels){
TQFolderIterator regions(model->getListOfFolders("Channel."+channelExp),true);
while(regions.hasNext()){
TQFolder* region = regions.readNext();
if(!region) continue;
if(region == source) continue; //there is no point in transfering from A to A (it would even delete some stuff!)
if(region->GetName() == sourceChannel) continue; //there is no point in transfering from A to A (it would even delete some stuff!)
if(matchesAny(region,exceptRegions,"Channel.")) continue;
if(verbose) manager->info(TString::Format("transferring in region '%s'",region->GetName()));
......@@ -168,8 +179,14 @@ namespace TSBaseActions {
TQFolderIterator samples(region->getListOfFolders("Sample."+sampleExp),true);
while(samples.hasNext()){
TQFolder* sample = samples.readNext();
if(!sample) continue;
if(!sample) continue;
if(matchesAny(sample,exceptSamples,"Sample.")) continue;
TQFolder* sourceRegion = model->getFolder("Channel."+sourceChannel);
TQFolder* source = sourceRegion ? sourceRegion->getFolder(sample->GetName()) : NULL;
if(!source){
manager->warn(TString::Format("unable to find source '%s'/'%s' in model '%s', skipping!",sourceChannel.Data(),sample->GetName(),model->GetName()));
continue;
}
if(verbose) manager->info(TString::Format("\tfor sample '%s'",sample->GetName()));
sample->deleteObject(".Dropped!");
for (const auto& systType : {TString("OverallSys."),TString("HistoSys.")}) {
......@@ -178,7 +195,6 @@ namespace TSBaseActions {
TQFolderIterator oldsystematics(sample->getListOfFolders(systType+"*"),true);
while(oldsystematics.hasNext()){
TQFolder* systematic = oldsystematics.readNext();
//std::cout << "systematic.GetName() = " << systematic->GetName() << std::endl;
if(!systematic) continue;
if(matchesAny(systematic,exceptSystematics,systType) || !matchesAny(systematic,targetSystematics,systType)) continue;
if(marked && !systematic->getTagBoolDefault(mark,false)) continue;
......@@ -192,6 +208,7 @@ namespace TSBaseActions {
}
{
TQFolderIterator newsystematics(source->getListOfFolders(systType+"*"),true);
int j = 0;
while(newsystematics.hasNext()){
TQFolder* systematic = newsystematics.readNext();
if(!systematic) continue;
......@@ -199,17 +216,34 @@ namespace TSBaseActions {
if(marked && !systematic->getTagBoolDefault(mark,false)) continue;
if(verbose) manager->info(TString::Format("\t\tcopying '%s'",systematic->GetName()));
TQFolder* copy = systematic->copy();
i++;
sample->addFolder(copy);
copy->setTagString("transferred",source->GetName());
if(systematic->hasTagString("HistoLow") && systematic->hasTagString("HistoHigh")){
TH1* nomHist = dynamic_cast<TH1*>(histograms->getObject(sample->getTagStringDefault("Histo","")));
TH1* lowHist = dynamic_cast<TH1*>(histograms->getObject(systematic->getTagStringDefault("HistoLow","")));
TH1* highHist = dynamic_cast<TH1*>(histograms->getObject(systematic->getTagStringDefault("HistoHigh","")));
if(!TQHistogramUtils::checkConsistency(nomHist,lowHist) || !TQHistogramUtils::checkConsistency(nomHist,highHist)){
manager->error(TString::Format("transferred histograms are inconsistent, skipping!\n\tnom\t%s\n\tlow\t%s\n\thigh\t%s",TQStringUtils::getDetails(nomHist).Data(),TQStringUtils::getDetails(lowHist).Data(),TQStringUtils::getDetails(highHist).Data()));
delete copy;
continue;
}
}
++j;
sample->addFolder(copy);
}
if(verbose && j==0){
manager->warn(TString::Format("\tno systematics of type %s found in '%s' matching '%s' except '%s'!",systType.Data(),source->GetName(),TQStringUtils::concat(targetSystematics,",").Data(),TQStringUtils::concat(exceptSystematics,",").Data()));
}
i += j;
}
}
}
}
}
}
return (i>0);
if(i>0) return true;
manager->error("no targets found for channel transfer!");
return false;
}
//no valid mode was selected
manager->error("Failed to perform, no valid mode was selected!");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment