#ifndef ATLAS_AtlSelector
#include <AtlSelector.h>
#endif
#include <TString.h>
#include <TObjectTable.h>
#include <iostream>
#include <TROOT.h>
#include <TSystem.h>
#include <TEntryList.h>
#include <TKey.h>
#include <AtlEvtReaderApp.h>
#include "AtlEvtReaderBase.h"
#include <AtlEvtReaderD3PDSgTop.h>
#include <AtlEvtWriterApp.h>
#include <AtlEvtWriterMem.h>
#include <AtlEvtWriterD3PDSgTop.h>
#include <AtlObjectsToolD3PDSgTop.h>
#include <AtlEvtReaderD3PDCKM.h>
#include <TChainElement.h>
using namespace std;
static const char* fgLepChannelNames[AtlSelector::fgNumLepChannels+1] = {
"enu", "munu", "lnu"
};
static const char* fgJetMultNames[AtlSelector::fgNumJetMults] = {
"1", "2", "3", "4", "5", "6", "4to6", "1+", "2+", "3+", "all"
};
#ifndef __CINT__
ClassImp(AtlSelector);
#endif
AtlSelector::AtlSelector(const char* OutputFilename) :
TSelector(),
fEvtReaderUser(0) {
fEvent = 0;
fTree = 0;
fCurrentTree = 0;
fBookkeepingList = new TObjArray;
fNBookkeeping = 0;
fOutputFile = 0;
fOutputFilename = new TString(OutputFilename);
fOutputTreeName = new TString("");
fOutputTreeTitle = new TString("");
fOutputTree = 0;
fOutputTriggerConfTree = 0;
fProcessedEvents = 0;
fProcessedEventsW = 0.;
fAcceptedEvents = 0;
fAcceptedEventsW = 0.;
fAcceptedEventsB = 0.;
fPreAcceptedEvents = 0;
fPreAcceptedEventsW = 0.;
fJetBinEvents = 0;
fJetBinEventsW = 0.;
fPreTaggedEvents = 0;
fPreTaggedEventsW = 0.;
fEntry = 0;
fListOfTools = new TList;
fWriteEntryList = kFALSE;
fEntryList = 0;
fPrintEvent = kFALSE;
fPrintObjectTable = kFALSE;
fPassedSelection = kFALSE;
fCountUnfilteredEvents = kTRUE;
fInputMode = kD3PDSgTop_v2;
fOutputMode = kApp;
fEvtReader = 0;
fEvtWriter = 0;
fDoTruthTree = kFALSE;
fHistCutflow_NoWeights = 0;
fHistCutflow_genWeights = 0;
fHistCutflow_genXpileupWeights = 0;
fHistCutflow_genXpileupXzvertexWeights = 0;
fHistCutflow_allEventsHFOR_NoWeights = 0;
fHistCutflow_allEventsHFOR_genWeights = 0;
}
AtlSelector::~AtlSelector() {
delete fOutputFile;
delete fOutputFilename;
delete fOutputTreeName;
delete fOutputTreeTitle;
if ( fOutputTree != 0 ) delete fOutputTree;
if ( fOutputTriggerConfTree != 0 ) delete fOutputTriggerConfTree;
fListOfTools->Delete(); delete fListOfTools;
if ( fEvtReaderUser != 0 && fEvtReader != fEvtReaderUser ) delete fEvtReaderUser;
if ( fEvtReader != 0 ) delete fEvtReader;
if ( fEvtWriter != 0 ) delete fEvtWriter;
delete fBookkeepingList;
}
void AtlSelector::SetOutputTree(const char* name, const char* title) {
fOutputTreeName->Remove(0, fOutputTreeName->Length());
fOutputTreeName->Append(name);
fOutputTreeTitle->Remove(0, fOutputTreeTitle->Length());
fOutputTreeTitle->Append(title);
}
void AtlSelector::SetBranches() {
fEvtReader->SetEvent(fEvent);
fEvtReader->SetBranches(fTree);
}
Int_t AtlSelector::GetEntry(Long64_t entry) {
fEntry = entry;
fEvtReader->GetEntry(fCurrentTree, entry);
return 0;
}
void AtlSelector::Init(TTree *tree) {
fTree = tree;
if ( fIsChain ) ((TChain*)fTree)->CanDeleteRefs(kTRUE);
}
Bool_t AtlSelector::Notify() {
fCurrentTree = ( fIsChain ) ? fTree->GetTree() : fTree;
if ( fCurrentTree == 0 ) {
Info("Notify", "No tree currently loaded. Return.");
return kTRUE;
}
Info("Notify", "Opened new input file %s",
fCurrentTree->GetCurrentFile()->GetName());
if ( fCurrentTree->GetEntries() == 0 ) {
Warning("Notify",
"The event tree in the current input file contains 0 events.");
} else {
if ( fInputMode == kApp ) {
Info("Notify", "Load trigger configuration dbase from current input file ...");
AtlTriggerConf *trig_conf = LoadTriggerConfig();
if ( HasOutputTree() && fOutputMode == kApp ) {
TTree *trig_tree = trig_conf->GetConfigTree();
if ( fOutputTriggerConfTree == 0 ) {
fOutputFile->cd();
fOutputTriggerConfTree = trig_tree->CloneTree(-1, "fast");
} else {
TList *treelist = new TList;
treelist->Add(trig_tree);
fOutputTriggerConfTree->Merge(treelist);
delete treelist;
}
}
}
}
DoBookkeeping(fCurrentTree->GetCurrentFile());
fEvtReader->Notify();
AtlAnalysisTool *tool = 0;
TIter next_tool(fListOfTools);
while ( (tool = (AtlAnalysisTool*)next_tool()) ) {
if ( !tool->IsOff() ) tool->Notify();
}
return kTRUE;
}
void AtlSelector::DoBookkeeping(TFile *InputFile) {
TObjArray* files = ((TChain*)fTree)->GetListOfFiles();
TIter next_el(files);
TChainElement *el = 0;
while ( (el = (TChainElement*)next_el()) ) {
if ( strcmp(el->GetTitle(), InputFile->GetName()) == 0 )
break;
}
if ( el == 0 ) {
Error("DoBookkeeping",
"Could not find chain element for current input file %s.",
InputFile->GetName());
Error("DoBookkeeping", "Abort !");
gSystem->Abort(1);
}
if ( fBookkeepingList->FindObject(el) ) {
Info("DoBookkeeping", "Perform bookkeeping for input file %s",
el->GetTitle());
fBookkeepingList->Remove(el);
fNBookkeeping--;
} else {
Info("DoBookkeeping",
"Bookkeeping for input file %s already done",
el->GetTitle());
Info("DoBookkeeping", "Skip.");
return;
}
TH1F *h = 0;
TH1D *h_cf1 = 0;
TH1D *h_cf2 = 0;
TH1D *h_cf3 = 0;
TH1D *h_cf4 = 0;
TH1D *h_cf5 = 0;
TH1D *h_cf6 = 0;
if ( fInputMode == kApp ) {
h = (TH1F*)InputFile->Get("/job_info/h_nevts");
if ( h != 0 ) {
Info("DoBookkeeping", "JobInfo histogram in input file found. Disable counting of unfiltered events");
fCountUnfilteredEvents = kFALSE;
fHistEvents->AddBinContent(1, h->GetBinContent(1));
fHistEvents->AddBinContent(2, h->GetBinContent(2));
fHistEvents->AddBinContent(3, h->GetBinContent(3));
} else {
Info("DoBookkeeping", "No JobInfo histogram in input file found. Enable counting of unfiltered events.");
}
} else if ( fInputMode == kD3PDSgTop ||
fInputMode == kD3PDCKM ||
fInputMode == kD3PDSgTop_v2 ) {
if ( fInputMode == kD3PDSgTop_v2 ) {
h_cf1 = (TH1D*) InputFile->Get(Form("%s_fullCutFlow_noWeights", fTree->GetName()));
h_cf2 = (TH1D*) InputFile->Get(Form("%s_fullCutFlow_genWeights", fTree->GetName()));
h_cf3 = (TH1D*) InputFile->Get(Form("%s_fullCutFlow_genXpileupWeights", fTree->GetName()));
h_cf4 = (TH1D*) InputFile->Get(Form("%s_fullCutFlow_genXpileupXzvertexWeights", fTree->GetName()));
h_cf5 = (TH1D*) InputFile->Get(Form("%s_allEventsHFOR_noWeights", fTree->GetName()));
h_cf6 = (TH1D*) InputFile->Get(Form("%s_allEventsHFOR_genWeights", fTree->GetName()));
if ( h_cf1 == 0 ) {
TList *keys = InputFile->GetListOfKeys();
for ( Int_t i = 0; i < keys->GetEntries(); i++ ) {
TString keyname = ((TKey*) keys->At(i))->GetName();
if ( keyname.Contains("fullCutFlow_noWeights") ) {
h_cf1 = (TH1D*)InputFile->Get(keyname.Data());
} else if ( keyname.Contains("fullCutFlow_genWeights") ) {
h_cf2 = (TH1D*)InputFile->Get(keyname.Data());
} else if ( keyname.Contains("fullCutFlow_genXpileupWeights") ) {
h_cf3 = (TH1D*)InputFile->Get(keyname.Data());
} else if ( keyname.Contains("fullCutFlow_genXpileupXzvertexWeights") ) {
h_cf4 = (TH1D*)InputFile->Get(keyname.Data());
} else if ( keyname.Contains("allEventsHFOR_noWeights") ) {
h_cf5 = (TH1D*)InputFile->Get(keyname.Data());
} else if ( keyname.Contains("allEventsHFOR_genWeights") ) {
h_cf6 = (TH1D*)InputFile->Get(keyname.Data());
}
}
}
} else {
h_cf1 = (TH1D*) InputFile->Get("fullCutFlow_noWeights");
h_cf2 = (TH1D*) InputFile->Get("fullCutFlow_genWeights");
h_cf3 = (TH1D*) InputFile->Get("fullCutFlow_genXpileupWeights");
h_cf4 = (TH1D*) InputFile->Get("fullCutFlow_genXpileupXzvertexWeights");
h_cf5 = (TH1D*) InputFile->Get("allEventsHFOR_noWeights");
h_cf6 = (TH1D*) InputFile->Get("allEventsHFOR_genWeights");
}
if ( h_cf1 == 0 ) {
Error("DoBookkeeping", "No Bookkeeping histogram found! Abort!");
gSystem->Abort();
}
if ( fHistCutflow_NoWeights == 0 ) {
fHistCutflow_NoWeights = (TH1D*) h_cf1->Clone();
fHistCutflow_NoWeights->SetDirectory(fOutputFile);
if ( h_cf2 != 0 ) {
fHistCutflow_genWeights = (TH1D*) h_cf2->Clone();
fHistCutflow_genXpileupWeights = (TH1D*) h_cf3->Clone();
fHistCutflow_genXpileupXzvertexWeights = (TH1D*) h_cf4->Clone();
fHistCutflow_allEventsHFOR_NoWeights = (TH1D*) h_cf5->Clone();
fHistCutflow_allEventsHFOR_genWeights = (TH1D*) h_cf6->Clone();
fHistCutflow_genWeights->SetDirectory(fOutputFile);
fHistCutflow_genXpileupWeights->SetDirectory(fOutputFile);
fHistCutflow_genXpileupXzvertexWeights
->SetDirectory(fOutputFile);
fHistCutflow_allEventsHFOR_NoWeights->SetDirectory(fOutputFile);
fHistCutflow_allEventsHFOR_genWeights
->SetDirectory(fOutputFile);
}
} else {
fHistCutflow_NoWeights->Add(h_cf1);
if ( h_cf2 != 0 ) {
fHistCutflow_genWeights->Add(h_cf2);
fHistCutflow_genXpileupWeights->Add(h_cf3);
fHistCutflow_genXpileupXzvertexWeights->Add(h_cf4);
fHistCutflow_allEventsHFOR_NoWeights->Add(h_cf5);
fHistCutflow_allEventsHFOR_genWeights->Add(h_cf6);
}
}
Info("DoBookkeeping",
"TRC D3PD bookkeeping histogram in input file found. Disable counting of unfiltered events.");
fCountUnfilteredEvents = kFALSE;
fHistEvents->AddBinContent(1, h_cf1->GetBinContent(1));
if ( ( h_cf2 != 0 ) && ( h_cf4 != 0 ) ) {
fHistEvents->AddBinContent(2, h_cf2->GetBinContent(1));
fHistEvents->AddBinContent(3, h_cf4->GetBinContent(1));
} else {
fHistEvents->AddBinContent(2, h_cf1->GetBinContent(1));
fHistEvents->AddBinContent(3, h_cf1->GetBinContent(1));
}
}
else if ( fInputMode == kCustom ) {
AtlEvtReaderBase::InitialSumOfWeights_t const & sumOfWeights = fEvtReader->GetInitialSumOfWeights(InputFile);
fCountUnfilteredEvents = kFALSE;
fHistEvents->AddBinContent(1, sumOfWeights.one);
fHistEvents->AddBinContent(2, sumOfWeights.mcevt);
fHistEvents->AddBinContent(3, sumOfWeights.mcevt_pileup_zvtx);
} else {
Error("Notify", "Unknown input mode given. Abort!");
gSystem->Abort(1);
}
}
void AtlSelector::Begin(TTree *tree) {
TString option = GetOption();
fStopwatch.Start();
Info("Begin",
"==================== Start analysis job here ====================");
if ( gSystem->Getenv("PandaID") ) {
Info("Begin", "Panda job Id: %s", gSystem->Getenv("PandaID"));
}
fTree = tree;
if( fTree->InheritsFrom("TChain") ) {
fIsChain = kTRUE;
Int_t nfiles = ((TChain*)fTree)->GetListOfFiles()->GetEntries();
if ( nfiles < 1 ) {
Error("Begin", "No input files given. Abort!");
gSystem->Abort(1);
} else if ( nfiles == 1 ) {
Info("Begin", "This job contains %d input file.", nfiles);
} else {
Info("Begin", "This job contains %d input files.", nfiles);
}
} else {
fIsChain = kFALSE;
}
Info("Begin", "Input chain name = \"%s\"", fTree->GetName());
if ( fEvtReader == 0 ) {
if ( (!fEvtReaderUser) != (fInputMode != kCustom) ) {
Fatal(__FUNCTION__, "fEvtReaderUser is (not) undefined while fInputMode is (not) set to kCustom");
}
switch ( fInputMode ) {
case kApp:
fEvtReader = new AtlEvtReaderApp(this);
Info("Begin", "Input file type = kApp");
break;
case kD3PDSgTop:
case kD3PDSgTop_v2:
fEvtReader = new AtlEvtReaderD3PDSgTop(this);
Info("Begin", "Input file type = kD3PDSgTop");
break;
case kD3PDCKM:
fEvtReader = new AtlEvtReaderD3PDCKM(this);
Info("Begin", "Input file type = kD3PDCKM");
break;
case kCustom:
fEvtReader = fEvtReaderUser;
Info("Begin", "Input file type = %s", fEvtReader->Class()->GetName());
break;
default:
Error("Begin", "Bad input file type - abort!");
gSystem->Abort(1);
}
}
if ( HasOutputTree() ) {
Info("Begin", "Write output tree \"%s\"",
fOutputTreeName->Data());
if ( fEvtWriter == 0 ) {
switch ( fOutputMode ) {
case kApp:
fEvtWriter = new AtlEvtWriterApp();
Info("Begin", "Output tree type: kAPP");
break;
case kMemNtuple:
fEvtWriter = new AtlEvtWriterMem();
Info("Begin", "Output tree type: kMemNtuple");
break;
case kD3PDSgTop:
case kD3PDSgTop_v2:
fEvtWriter = new AtlEvtWriterD3PDSgTop();
Info("Begin", "Output tree type: kD3PDSgTop");
break;
case kD3PDCKM:
fEvtWriter = new AtlEvtWriterD3PDSgTop();
Info("Begin", "Output tree type: kD3PDSgTop");
break;
default:
Error("Begin", "Bad output tree type - abort!");
gSystem->Abort(1);
}
} else {
Info("Begin", "Output tree type: %s",
fEvtWriter->GetNameOfType());
}
} else {
Info("Begin", "Output tree: none");
}
Info("Begin", "Open output file \"%s\"", fOutputFilename->Data());
fOutputFile = new TFile(fOutputFilename->Data(), "recreate");
fOutputFile->SetCompressionLevel(9);
if ( fWriteEntryList ) {
fEntryList = new TEntryList("app_entrylist", "A++ event list");
fEntryList->SetDirectory(fOutputFile);
}
}
void AtlSelector::SlaveBegin(TTree *tree) {
fProcInfo = new ProcInfo_t;
fMemInfo = new MemInfo_t;
fEvent = new AtlEvent;
Info("SlaveBegin", "Set branch addresses.");
SetBranches();
Info("SlaveBegin", "User analysis configuration:\n");
Print();
TIter next_tool(fListOfTools);
AtlAnalysisTool *tool = 0;
while ( (tool = (AtlAnalysisTool*)next_tool()) ) {
tool->Init();
cout << endl;
Info("SlaveBegin",
"Registered analysis tool \"%s\" of type %s with the following configuration:\n",
tool->GetName(), tool->ClassName());
tool->Print();
if ( tool->fProcessMode == AtlAnalysisTool::kOff ) {
fListOfTools->Remove(tool);
delete tool;
}
}
if ( fInputMode == kApp ) SetBranchStatus();
next_tool.Reset();
while ( (tool=(AtlAnalysisTool*)next_tool()) ) {
tool->SetTree(fTree);
tool->SetOutputFile(fOutputFile);
tool->SetEvent(fEvent);
if ( fInputMode == kApp ) tool->SetBranchStatus();
}
if ( fInputMode == kApp )
fTree->SetBranchStatus("fEventHeader.fEventWeight", kTRUE);
Info("SlaveBegin", "Book histograms ...");
TH1::SetDefaultSumw2(kTRUE);
BookJobInfoHistograms();
Info("SlaveBegin", "Booked JobInfo histograms.");
fOutputFile->cd();
BookHistograms();
Info("SlaveBegin", "Booked user-defined histograms.");
next_tool.Reset();
while ( (tool = (AtlAnalysisTool*)next_tool()) ) {
fOutputFile->cd();
if(strcmp(tool->GetOutputDir(),"/") != 0) {
if( !fOutputFile->cd( tool->GetOutputDir() ) ) {
fOutputFile->mkdir(tool->GetOutputDir(), "Tool directory");
gDirectory->cd( tool->GetOutputDir() );
}
}
if ( gDirectory->FindObject(tool->GetName()) != 0 ) {
Info("SlaveBegin", "Folder for tool \"%s\" already exists. Will re-use folder.",
tool->GetName());
} else {
gDirectory->mkdir(tool->GetName(), tool->GetTitle());
}
gDirectory->cd(tool->GetName());
tool->BookHistograms();
}
fOutputFile->cd();
Info("SlaveBegin", "Booked histograms of all analysis tools.");
next_tool.Reset();
while ( (tool = (AtlAnalysisTool*)next_tool()) ) {
if ( tool->InheritsFrom("AtlHistogramTool") ) {
tool->Print();
}
}
TChainElement *el = 0;
TIter next_el(((TChain*)fTree)->GetListOfFiles());
while ( (el = (TChainElement*)next_el()) ) {
fBookkeepingList->Add(el);
fNBookkeeping++;
}
Info("SlaveBegin", "Registered %d input files for bookkeeping.",
fNBookkeeping);
if ( HasOutputTree() ) {
fOutputFile->cd();
fOutputTree = fEvtWriter->CreateTree(fOutputTreeName->Data(),
fOutputTreeTitle->Data(),
fTree);
fEvtWriter->BookTree(fOutputTree, fEvent);
}
}
Bool_t AtlSelector::Process(Long64_t entry) {
fPassedSelection = kFALSE;
Int_t ObjectNumber = TProcessID::GetObjectCount();
fEvent->Clear();
AtlAnalysisTool *tool = 0;
TIter next_tool(fListOfTools);
next_tool.Reset();
while ( (tool = (AtlAnalysisTool*)next_tool()) ) {
tool->Clear();
}
AtlSelector::Clear();
Clear();
GetEntry(entry);
if ( fWriteEntryList ) fEntryList->SetTree(fTree);
ProcessInfo();
next_tool.Reset();
while ( (tool = (AtlAnalysisTool*)next_tool()) ) {
if ( tool->IsSystematics() )
tool->Process();
}
if ( fPrintObjectTable == kTRUE ) {
gObjectTable->Print();
}
if ( fPrintEvent == kTRUE ) {
fEvent->Print("all-notrig");
}
fHistEvents->Fill(3.5, 1.);
fHistEvents->Fill(4.5, fEvent->GetMCWeight());
fHistEvents->Fill(5.5, fEvent->GetPreTagEvtWeight());
fHistEvtWeights->Fill(fEvent->GetPreTagEvtWeight());
fProcessedEvents++;
fProcessedEventsW += fEvent->GetPreTagEvtWeight();
if ( fCountUnfilteredEvents == kTRUE ) {
fHistEvents->Fill(0.5, 1.);
fHistEvents->Fill(1.5, fEvent->GetMCWeight());
fHistEvents->Fill(2.5, fEvent->GetPreTagEvtWeight());
}
Bool_t PassedObjSelection = kTRUE;
next_tool.Reset();
while ( (tool = (AtlAnalysisTool*)next_tool()) ) {
if ( tool->IsObjectsDefinition() )
PassedObjSelection = PassedObjSelection & tool->Process();
}
if ( PassedObjSelection ) {
fJetBinEvents++;
fJetBinEventsW += fEvent->GetPreTagEvtWeight();
next_tool.Reset();
while ( (tool = (AtlAnalysisTool*)next_tool()) ) {
if ( tool->IsScaleFactor() )
tool->Process();
}
next_tool.Reset();
while ( (tool = (AtlAnalysisTool*)next_tool()) ) {
if ( tool->IsPreAnalysis() )
tool->Process();
}
next_tool.Reset();
while ( (tool = (AtlAnalysisTool*)next_tool()) ) {
tool->FillHistogramsNoEvtSel();
}
if ( ProcessPreCut() == kTRUE ) {
fHistEvents->Fill(6.5, 1.);
fHistEvents->Fill(7.5, fEvent->GetMCWeight());
fHistEvents->Fill(8.5, fEvent->GetPreTagEvtWeight());
fPreAcceptedEvents++;
fPreAcceptedEventsW += fEvent->GetPreTagEvtWeight();
InitEvent();
next_tool.Reset();
while ( (tool = (AtlAnalysisTool*)next_tool()) ) {
if ( tool->IsMainAnalysis() )
tool->Process();
}
if ( ProcessCut() == kTRUE ) {
ProcessFill();
fHistEvents->Fill(9.5, 1.);
fHistEvents->Fill(10.5, fEvent->GetMCWeight());
fHistEvents->Fill(11.5, fEvent->GetPreTagEvtWeight());
fAcceptedEvents++;
fAcceptedEventsW += fEvent->GetPreTagEvtWeight();
fAcceptedEventsB += fEvent->GetTagEvtWeight();
}
next_tool.Reset();
while ( (tool = (AtlAnalysisTool*)next_tool()) ) {
if ( tool->IsPostAnalysis() )
tool->Process();
}
}
}
TProcessID::SetObjectCount(ObjectNumber);
return kTRUE;
}
void AtlSelector::SlaveTerminate() {
Info("SlaveTerminate", "Terminating slave process");
delete fEvent;
if( fCurrentTree != 0 ) fCurrentTree->GetCurrentFile()->Close();
AtlAnalysisTool *tool = 0;
TIter next_tool(fListOfTools);
while ( (tool = (AtlAnalysisTool*)next_tool()) ) {
tool->Terminate();
}
Info("SlaveTerminate", "Finish bookkeeping ... %d input files left",
fNBookkeeping);
TIter next_el(fBookkeepingList);
TChainElement *el = 0;
while ( (el = (TChainElement*)next_el()) ) {
TFile *infile = TFile::Open(el->GetTitle(),"read");
DoBookkeeping(infile);
delete infile;
}
if ( fNBookkeeping > 0 ) {
Warning("SlaveTerminate", "Bookkeeping left for %d input files.",
fNBookkeeping);
} else {
Info("SlaveTerminate", "Bookkeeping done for all input files.");
}
delete fProcInfo;
delete fMemInfo;
}
void AtlSelector::Terminate() {
Info("Terminate", "Terminating analysis job ...");
if ( fEvtWriter != 0 ) fEvtWriter->Terminate();
cout << endl;
Info("Terminate", "Write output file \"%s\".",
fOutputFilename->Data());
fOutputFile->cd();
fOutputFile->Write();
fStopwatch.Stop();
PrintSummary();
}
void AtlSelector::ProcessFill() {
FillHistograms();
AtlAnalysisTool *tool = 0;
TIter next_tool(fListOfTools);
while ( (tool = (AtlAnalysisTool*)next_tool()) ) {
tool->FillHistograms();
}
if ( fOutputFile != 0 &&
fOutputFile->GetEND() > fOutputTree->GetMaxTreeSize() )
ChangeOutputFile();
if ( fOutputTree != 0 ) fEvtWriter->WriteEvent();
if ( fWriteEntryList ) {
fEntryList->Enter(fEntry);
}
}
void AtlSelector::SetCutDefaults() {
}
void AtlSelector::ProcessInfo() {
if ( gROOT->IsBatch() ) {
Int_t mod = 0;
if ( fProcessedEvents < 10 ) {
mod = 1;
} else if ( fProcessedEvents < 1000 ) {
mod = 100;
} else if ( fProcessedEvents < 10000 ) {
mod = 1000;
} else {
mod = 10000;
}
if ( (fProcessedEvents+1) % mod == 0 ) {
printf("<AtlSelector::Process>: Processing chain \"%s\" Run %-d Evt %-llu",
fTree->GetName(), fEvent->RunNr(), fEvent->EventNr());
printf(" #Chain entry %-d/%-d\n",
(Int_t)fTree->GetReadEntry(),
(Int_t)fTree->GetEntriesFast());
gSystem->GetProcInfo(fProcInfo);
gSystem->GetMemInfo(fMemInfo);
printf("<AtlSelector::Process>: Memory usage proc_res=%d proc_virt=%d total=%d Mb\n",
Int_t(fProcInfo->fMemResident/1024),
Int_t(fProcInfo->fMemVirtual/1024),
fMemInfo->fMemTotal);
cout.flush();
}
} else {
printf("\r<AtlSelector::Process>: Processing chain \"%s\" Run %-d Evt %-llu",
fTree->GetName(), fEvent->RunNr(), fEvent->EventNr());
printf(" #Chain entry %-d/%-d",
(Int_t)fTree->GetReadEntry(),
(Int_t)fTree->GetEntriesFast());
cout.flush();
}
}
void AtlSelector::PrintSummary() {
cout << endl << endl;
cout << "================================================================"
<< endl
<< " Job Summary" << endl
<< "================================================================"
<< endl
<< "No. of processed events, unweighted : "
<< fProcessedEvents << endl
<< "No. of processed events, weighted : "
<< fProcessedEventsW << endl
<< "No. of events in jet bin, unweighted : "
<< fJetBinEvents << endl
<< "No. of events in jet bin, weighted : "
<< fJetBinEventsW << endl
<< "No. of pre-accepted events, unweighted : "
<< fPreAcceptedEvents << endl
<< "No. of pre-accepted events, weighted : "
<< fPreAcceptedEventsW << endl
<< "No. of pre-tagged events, unweighted : "
<< fPreTaggedEvents << endl
<< "No. of pre-tagged events, weighted : "
<< fPreTaggedEventsW << endl
<< "No. of accepted events, unweighted : "
<< fAcceptedEvents << endl
<< "No. of accepted events (pretag), weighted : "
<< fAcceptedEventsW << endl
<< "No. of accepted events (tag), weighted : "
<< fAcceptedEventsB << endl
<< "Time consumption : ";
fStopwatch.Print();
cout << "Job status : successful" << endl
<< endl
<< "For more information have a look at the histograms inside the"
<< endl
<< "JobInfo folder of the output .root file" << endl
<< "================================================================"
<< endl << endl;
}
void AtlSelector::AddTool(AtlAnalysisTool *tool) {
fListOfTools->Add(tool);
tool->SetParent(this);
tool->SetEvent(fEvent);
tool->SetTree(fTree);
}
AtlAnalysisTool* AtlSelector::GetTool(const char* ClassName,
const char* ToolName, Bool_t force) {
AtlAnalysisTool *itertool = 0;
AtlAnalysisTool *tool = 0;
Int_t toolcount = 0;
TIter next_tool(fListOfTools);
next_tool.Reset();
while ( (itertool = (AtlAnalysisTool*)next_tool()) ) {
if( ((TString)itertool->ClassName()).Contains(ClassName) &&
( strcmp(ToolName, "") == 0
|| strcmp(itertool->GetName(), ToolName) == 0) ) {
tool = itertool;
toolcount++;
}
}
if ( toolcount == 1 ){
return tool;
} else if ( toolcount == 0 ) {
if ( force == kTRUE ) {
Error("GetTool",
"Requested tool %s of class %s not found!",
ToolName, ClassName);
gSystem->Abort(0);
return 0;
} else {
return 0;
}
} else {
Error("GetTool",
"Request with toolname %s of class %s returned %d instances! Please be more specific.",
ToolName, ClassName, toolcount);
gSystem->Abort(0);
return 0;
}
}
AtlTriggerConf* AtlSelector::LoadTriggerConfig() {
fCurrentTree->GetCurrentFile()->cd();
AtlTriggerConf *trig_conf = AtlTriggerConf::Instance()
->LoadTree(gDirectory);
if ( trig_conf == 0 ) {
Error("LoadTriggerConfig", "No trigger configuration dbase found! Do not try to access any trigger information.");
}
AtlTrigger::SetConfig(trig_conf);
return trig_conf;
}
void AtlSelector::BookJobInfoHistograms() {
TDirectory *savdir = gDirectory;
fOutputFile->cd();
gDirectory->mkdir("job_info", "Analysis Job Information");
gDirectory->cd("job_info");
fHistEvents = new TH1F("h_nevts", "No. of Events", 12, 0, 12);
fHistEvents->GetXaxis()->SetBinLabel(1, "All unfiltered Evts (unweighted)");
fHistEvents->GetXaxis()->SetBinLabel(2, "All unfiltered Evts (MC weights)");
fHistEvents->GetXaxis()->SetBinLabel(3, "All unfiltered Evts (all weights)");
fHistEvents->GetXaxis()->SetBinLabel(4, "Processed Evts (unweighted)");
fHistEvents->GetXaxis()->SetBinLabel(5, "Processed Evts (MC weights)");
fHistEvents->GetXaxis()->SetBinLabel(6, "Processed Evts (all weights)");
fHistEvents->GetXaxis()->SetBinLabel(7, "Pre-accepted Evts (unweighted)");
fHistEvents->GetXaxis()->SetBinLabel(8, "Pre-accepted Evts (MC weights)");
fHistEvents->GetXaxis()->SetBinLabel(9, "Pre-accepted Evts (all weights)");
fHistEvents->GetXaxis()->SetBinLabel(10, "Accepted Evts (unweighted)");
fHistEvents->GetXaxis()->SetBinLabel(11, "Accepted Evts (MC weights)");
fHistEvents->GetXaxis()->SetBinLabel(12, "Accepted Evts (all weights)");
fHistEvents->SetYTitle("Number of Events");
fHistEvents->SetStats(kFALSE);
fHistEvtWeights = new TH1F("h_evtweight", "Event Weights (all processed events)",
22, -1.1, 1.1);
fHistEvtWeights->SetXTitle("Weight");
fHistEvtWeights->SetYTitle("Number of Entries");
fHistEvtWeights->SetStats(kFALSE);
savdir->cd();
}
void AtlSelector::ChangeOutputFile() {
TObject *h = 0;
while ( (h = fOutputFile->GetList()->First()) ) {
if ( h->InheritsFrom("TH1") ) {
h->Write();
((TH1*)h)->Reset();
}
}
}
const char* AtlSelector::GetJetMultLabel(EJetMult jetmult) {
for ( Int_t i = 0; i < AtlSelector::fgNumJetMults; i++ ) {
if ( jetmult & 0x1 << i ) return AtlSelector::GetJetMultLabel(i);
}
return "";
}
const char* AtlSelector::GetJetMultLabel(Int_t i) {
if ( i >= fgNumJetMults ) {
cout << "Jet Multiplicity unknown! Abort!" << endl;
gSystem->Abort(0);
}
return fgJetMultNames[i];
}
const char* AtlSelector::GetLeptonLabel(ELepChannel lep) {
if ( lep & kElectron ) { return fgLepChannelNames[0]; };
if ( lep & kMuon ) { return fgLepChannelNames[1]; };
if ( lep & kLepton ) { return fgLepChannelNames[2]; };
return "";
}
const char* AtlSelector::GetLeptonLabel(Int_t i) {
if ( i >= fgNumLepChannels + 1 ) {
cout << "Lepton Channel unknown! Abort!" << endl;
gSystem->Abort(0);
}
return fgLepChannelNames[i];
}
void AtlSelector::Clear(Option_t *otpion) {
}
const char* AtlSelector::GetJetMultEnum(UInt_t jetmult) {
switch ( jetmult ) {
case AtlSelector::kOneJet:
return "AtlSelector::kOneJet";
case AtlSelector::kTwoJet:
return "AtlSelector::kTwoJet";
case AtlSelector::kThreeJet:
return "AtlSelector::kThreeJet";
case AtlSelector::kFourJet:
return "AtlSelector::kFourJet";
case AtlSelector::kFiveJet:
return "AtlSelector::kFiveJet";
case AtlSelector::kSixJet:
return "AtlSelector::kSixJet";
case AtlSelector::k4To6Jets:
return "AtlSelector::k4To6Jets";
case AtlSelector::kOneOrMoreJets:
return "AtlSelector::kOneOrMoreJets";
case AtlSelector::kTwoOrMoreJets:
return "AtlSelector::kTwoOrMoreJets";
case AtlSelector::kThreeOrMoreJets:
return "AtlSelector::kThreeOrMoreJets";
case AtlSelector::kAllJets:
return "AtlSelector::kAllJets";
default:
cout << "<AtlSelector::GetJetMultEnum>: Jet Multiplicity not known! Abort!" << endl;
gSystem->Abort(0);
}
return "";
}
const char* AtlSelector::GetLeptonEnum(UInt_t lep) {
switch ( lep ) {
case AtlSelector::kElectron:
return "AtlSelector::kElectron";
case AtlSelector::kMuon:
return "AtlSelector::kMuon";
case AtlSelector::kLepton:
return "AtlSelector::kLepton";
default:
cout << "<AtlSelector::GetLepChannelEnum>: Lepton not known! Abort!" << endl;
gSystem->Abort(0);
}
return "";
}
void AtlSelector::Print(Option_t *option) const {
fEvtReader->Print();
cout << endl << " fDoTruthTree = ";
if ( fDoTruthTree ) {
cout << "true";
} else {
cout << "false";
}
cout << endl;
}
void AtlSelector::SetEvtReader(AtlEvtReaderBase * reader) {
if ( fEvtReader ) {
Fatal(__FUNCTION__, "... called too late!");
}
fInputMode = kCustom;
fEvtReaderUser = reader;
}
void AtlSelector::SetInputMode(EIOMode inputMode) {
if ( fEvtReader ) {
Fatal(__FUNCTION__, "... called too late!");
}
if ( fEvtReaderUser ) {
delete fEvtReaderUser;
fEvtReaderUser = 0;
}
fInputMode = inputMode;
}