Skip to content
Snippets Groups Projects
Commit 0a652592 authored by Anamika Aggarwal's avatar Anamika Aggarwal
Browse files

adding HistoSys info

parent 98c697fe
No related branches found
No related tags found
2 merge requests!664analysis developments,!645WIP: Transfer Systematics for HistoSys
Pipeline #2069705 passed
......@@ -3,6 +3,7 @@
#include "QFramework/TQUtils.h"
#include "QFramework/TQStringUtils.h"
#include "TString.h"
#include "QFramework/TQHistogramUtils.h"
#include "SFramework/TSStatisticsManager.h"
......@@ -42,6 +43,10 @@ namespace TSBaseActions {
bool performTransfer(TQFolder * config,TQFolder* model) const {
TString mode = config->getTagStringDefault("mode","sample");
TString componentFilter = config->getTagStringDefault("componentFilter","OverallSysHistoSys");
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 +81,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()){
......@@ -99,7 +102,9 @@ namespace TSBaseActions {
if(TQStringUtils::matches(sample->GetName(),"Sample."+sourceSample)) continue;
if(verbose) manager->info(TString::Format("\tfor sample '%s'",sample->GetName()));
sample->deleteObject(".Dropped!");
for (const auto& systType : {TString("OverallSys."),TString("ShapeSys.")}) {
for (const auto& systType : {TString("OverallSys."),TString("HistoSys.")}) {
if (componentFilter=="OverallSys" and systType=="HistoSys.") continue;
if (componentFilter=="HistoSys" and systType=="OverallSys.") continue;
std::vector<TQFolder*> remove;
{
TQFolderIterator oldsystematics(sample->getListOfFolders(systType+"*"),true);
......@@ -118,6 +123,7 @@ namespace TSBaseActions {
}
{
TQFolderIterator newsystematics(source->getListOfFolders(systType+"*"),true);
int j = 0;
while(newsystematics.hasNext()){
TQFolder* systematic = newsystematics.readNext();
if(!systematic) continue;
......@@ -125,42 +131,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,47 +183,87 @@ 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!");
std::vector<TQFolder*> remove;
{
TQFolderIterator oldsystematics(sample->getListOfFolders("OverallSys.*"),true);
while(oldsystematics.hasNext()){
TQFolder* systematic = oldsystematics.readNext();
if(!systematic) continue;
if(matchesAny(region,exceptSystematics,"OverallSys.")) continue;
if(marked && !systematic->getTagBoolDefault(mark,false)) continue;
if(!matchesAny(systematic,targetSystematics,"OverallSys.")) continue;
if(verbose) manager->info(TString::Format("\t\tremoving '%s'",systematic->GetName()));
remove.push_back(systematic);
for (const auto& systType : {TString("OverallSys."),TString("HistoSys.")}) {
if (componentFilter=="OverallSys" and systType=="HistoSys.") continue;
if (componentFilter=="HistoSys" and systType=="OverallSys.") continue;
std::vector<TQFolder*> remove;
{
TQFolderIterator oldsystematics(sample->getListOfFolders(systType+"*"),true);
while(oldsystematics.hasNext()){
TQFolder* systematic = oldsystematics.readNext();
if(!systematic) continue;
if(matchesAny(systematic,exceptSystematics,systType) || !matchesAny(systematic,targetSystematics,systType)) continue;
if(marked && !systematic->getTagBoolDefault(mark,false)) continue;
if(verbose) manager->info(TString::Format("\t\tremoving '%s'",systematic->GetName()));
remove.push_back(systematic);
}
}
}
for(auto systematic:remove){
systematic->detachFromBase();
delete systematic;
}
{
TQFolderIterator newsystematics(source->getListOfFolders(TQFolder::concatPaths(sample->getName(),"OverallSys.*")),true);
while(newsystematics.hasNext()){
TQFolder* systematic = newsystematics.readNext();
if(!systematic) continue;
if(matchesAny(region,exceptSystematics,"OverallSys.")) continue;
if(marked && !systematic->getTagBoolDefault(mark,false)) continue;
if(!matchesAny(systematic,targetSystematics,"OverallSys.")) 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());
for(auto systematic:remove){
systematic->detachFromBase();
delete systematic;
}
{
TQFolderIterator newsystematics(source->getListOfFolders(systType+"*"),true);
int j = 0;
while(newsystematics.hasNext()){
TQFolder* systematic = newsystematics.readNext();
if(!systematic) continue;
if(matchesAny(systematic,exceptSystematics,systType) || !matchesAny(systematic,targetSystematics,systType)) continue;
if(marked && !systematic->getTagBoolDefault(mark,false)) continue;
if(verbose) manager->info(TString::Format("\t\tcopying '%s'",systematic->GetName()));
TQFolder* copy = systematic->copy();
copy->setTagString("transferred",source->GetName());
if(systematic->hasTagString("HistoLow") && systematic->hasTagString("HistoHigh")){
TH1* sourceNomHist = dynamic_cast<TH1*>(histograms->getObject(sample->getTagStringDefault("Histo","")));
TH1* sourceLowHist = dynamic_cast<TH1*>(histograms->getObject(sample->getTagStringDefault("HistoLow","")));
TH1* sourceHighHist = dynamic_cast<TH1*>(histograms->getObject(sample->getTagStringDefault("HistoHigh","")));
TH1* targetNomHist = dynamic_cast<TH1*>(histograms->getObject(systematic->getTagStringDefault("Histo","")));
TH1* targetLowHist = dynamic_cast<TH1*>(histograms->getObject(systematic->getTagStringDefault("HistoHigh","")));
TH1* targetHighHist = dynamic_cast<TH1*>(histograms->getObject(systematic->getTagStringDefault("HistoLow","")));
TQHistogramUtils::normalize(sourceLowHist,sourceNomHist);
TQHistogramUtils::divideHistogramWithoutError(sourceLowHist,sourceNomHist);
TQHistogramUtils::normalize(sourceHighHist,sourceNomHist);
TH1* targetNomHistClone1= dynamic_cast<TH1*>(sourceNomHist->Clone());
TQHistogramUtils::divideHistogramWithoutError(targetNomHistClone1,sourceLowHist);
targetLowHist = targetNomHistClone1;
TH1* targetNomHistClone2= dynamic_cast<TH1*>(sourceNomHist->Clone());
TQHistogramUtils::divideHistogramWithoutError(targetNomHistClone2,sourceHighHist);
targetHighHist = targetNomHistClone2;
TQHistogramUtils::normalize(targetLowHist,targetNomHist);
TQHistogramUtils::normalize(targetHighHist,targetNomHist);
TString histoPathLow=systematic->getTagStringDefault("HistoLow","");
TString histoPathHigh=systematic->getTagStringDefault("HistoHigh","");
TQFolder::getPathTail(histoPathLow);
TQFolder::getPathTail(histoPathHigh);
TQStringUtils::ensureTrailingText(histoPathLow,"/");
TQStringUtils::ensureTrailingText(histoPathHigh,"/");
}
++j;
}
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