21 std::cout <<
" This application is currently only available in the analysis releases \n \
22 Please setup an AthAnalysisBase release to use this application." << std::endl;
33#include "TApplication.h"
35#include "TDirectory.h"
37#include "TObjString.h"
52 lbx() : nExpected(0),nSeen(0) {}
55 bool fromSuspect =
false;
59 const char* optstring =
"m";
60 bool showMissing =
false;
64 {
"showMissing", no_argument , NULL,
'm'}
72 while ((option = getopt_long(argc, argv,
73 optstring, long_options, &longindex)) != -1) {
76 showMissing =
true;nOptions++;
79 printf(
"Please supply a valid option to the program. Exiting\n");
89 std::cout <<
"Usage: <lumicalcfile.root> <list of xAOD or D3PD>" << std::endl;
90 std::cout <<
"Option: -m lists run numbers with any missing lumi" << std::endl;
91 std::cout <<
"" << std::endl;
92 std::cout <<
"Further Documentation: see https://twiki.cern.ch/twiki/bin/view/AtlasProtected/AthAnalysisBase#How_to_check_the_luminosity_cove " <<std::endl;
95 gSystem->Load(
"libTree.so");
99 std::map<uint, std::map<uint, lbx> > lbxs;
105 for(
int i=2+nOptions;
i<
argc;
i++) {
106 std::string
s(argv[i]);
107 if(
s.find(
".xml")==std::string::npos)
continue;
116 std::vector<std::string> lumiFiles;
119 for(
int i=1+nOptions;
i<
argc;
i++) {
121 std::string
s(argv[i]);
122 if(
s.find(
".root")==std::string::npos)
continue;
123 TFile *
file = TFile::Open(argv[i]);
124 if(
file==0)
continue;
128 TTree *
tmp = (TTree*)
file->Get(
"LumiMetaData" );
130 std::cout <<
"is lumicalc [ok]" << std::endl;
132 lumiFiles.push_back(s);
139 if(
file->Get(
"MetaData")!=0) {
140 TTree* metaTree =
static_cast<TTree*
>(
file->Get(
"MetaData"));
143 bool useTEvent(
false);
147 metaTree->SetMakeClass(1);
149 std::vector<unsigned int> startRunNumber;
150 std::vector<unsigned int> stopRunNumber;
153 std::vector<unsigned int> eventsExpected;
162 if(useTEvent &&
event.readFrom(
file,
true,
"MetaData").isSuccess()) {
168 if(metaTree->FindBranch(
"LumiBlocksAux.")) {
169 if(metaTree->FindBranch(
"LumiBlocksAux.")->GetSplitLevel()==0) {
170 std::cout <<
" Unable to read unsplit LumiBlocksAux" << std::endl;
175 lbrs_nc->setStore( lbrs_aux );
176 metaTree->SetBranchAddress(
"LumiBlocksAux.startRunNumber",&startRunNumber);
177 metaTree->SetBranchAddress(
"LumiBlocksAux.stopRunNumber",&stopRunNumber);
178 metaTree->SetBranchAddress(
"LumiBlocksAux.startLumiBlockNumber",&startLumiBlockNumber);
179 metaTree->SetBranchAddress(
"LumiBlocksAux.stopLumiBlockNumber",&stopLumiBlockNumber);
180 metaTree->SetBranchAddress(
"LumiBlocksAux.eventsExpected",&eventsExpected);
181 metaTree->SetBranchAddress(
"LumiBlocksAux.eventsSeen",&eventsSeen);
186 std::cout <<
"...xAOD LumiBlocks";
187 for(
int ii=0;ii<metaTree->GetEntries();ii++) {
190 metaTree->GetEntry(ii);
191 for(
unsigned int j=0;
j<startRunNumber.size();
j++) {
193 r->setStartRunNumber(startRunNumber.at(j));
r->setStopRunNumber(stopRunNumber.at(j));
195 r->setEventsExpected(eventsExpected.at(j));
r->setEventsSeen(
eventsSeen.at(j));
200 for(
auto lbr : *lbrs) {
201 for(
uint runNum = lbr->startRunNumber(); runNum <= lbr->stopRunNumber();
runNum++) {
202 if(lbr->startLumiBlockNumber()!=lbr->stopLumiBlockNumber()) {std::cout <<
" Unexpected behaviour. Please report! " << std::endl; std::abort();}
204 lbxs[
runNum][
lb].nSeen += lbr->eventsSeen();
205 if(lbxs[runNum][
lb].nExpected!=0 && lbxs[runNum][
lb].nExpected != lbr->eventsExpected()) {
206 std::cout <<
"...mismatch on expected events in [run,lb]=[" <<
runNum <<
"," <<
lb <<
"] got " << lbr->eventsExpected() <<
" but had " << lbxs[
runNum][
lb].nExpected << std::endl;
207 std::cout <<
"...PLEASE REPORT THIS to hn-atlas-PATHelp@cern.ch ... for now I will assume the larger number is correct" << std::endl;
208 if(lbxs[runNum][
lb].nExpected < lbr->eventsExpected()) lbxs[
runNum][
lb].nExpected = lbr->eventsExpected();
210 else if(lbxs[runNum][
lb].nExpected==0) lbxs[
runNum][
lb].nExpected=lbr->eventsExpected();
216 std::cout <<
"...ok" << std::endl;
217 if(!useTEvent) {
delete lbrs_nc; lbrs_nc =
nullptr;
delete lbrs_aux; }
220 lbrs =
nullptr; lbrs_nc =
nullptr; lbrs_aux=0;
221 if(useTEvent &&
event.readFrom(
file,
true,
"MetaData").isSuccess()) {
227 if(metaTree->FindBranch(
"IncompleteLumiBlocksAux.")) {
228 if(metaTree->FindBranch(
"IncompleteLumiBlocksAux.")->GetSplitLevel()==0) {
229 std::cout <<
" Unable to read unsplit IncompleteLumiBlocksAux" << std::endl;
234 lbrs_nc->setStore( lbrs_aux );
235 metaTree->ResetBranchAddresses();
236 metaTree->SetBranchAddress(
"IncompleteLumiBlocksAux.startRunNumber",&startRunNumber);
237 metaTree->SetBranchAddress(
"IncompleteLumiBlocksAux.stopRunNumber",&stopRunNumber);
238 metaTree->SetBranchAddress(
"IncompleteLumiBlocksAux.startLumiBlockNumber",&startLumiBlockNumber);
239 metaTree->SetBranchAddress(
"IncompleteLumiBlocksAux.stopLumiBlockNumber",&stopLumiBlockNumber);
240 metaTree->SetBranchAddress(
"IncompleteLumiBlocksAux.eventsExpected",&eventsExpected);
241 metaTree->SetBranchAddress(
"IncompleteLumiBlocksAux.eventsSeen",&eventsSeen);
246 std::cout <<
"...xAOD IncompleteLumiBlocks";
247 for(
int ii=0;ii<metaTree->GetEntries();ii++) {
250 metaTree->GetEntry(ii);
251 for(
unsigned int j=0;
j<startRunNumber.size();
j++) {
253 r->setStartRunNumber(startRunNumber.at(j));
r->setStopRunNumber(stopRunNumber.at(j));
255 r->setEventsExpected(eventsExpected.at(j));
r->setEventsSeen(
eventsSeen.at(j));
260 for(
auto lbr : *lbrs) {
261 for(
uint runNum = lbr->startRunNumber(); runNum <= lbr->stopRunNumber();
runNum++) {
262 if(lbr->startLumiBlockNumber()!=lbr->stopLumiBlockNumber()) {std::cout <<
" Unexpected behaviour. Please report! " << std::endl; std::abort();}
264 lbxs[
runNum][
lb].nSeen += lbr->eventsSeen();
265 if(lbxs[runNum][
lb].nExpected!=0 && lbxs[runNum][
lb].nExpected != lbr->eventsExpected()) {
266 std::cout <<
"...mismatch on expected events in [run,lb]=[" <<
runNum <<
"," <<
lb <<
"] got " << lbr->eventsExpected() <<
" but had " << lbxs[
runNum][
lb].nExpected << std::endl;
267 std::cout <<
"...PLEASE REPORT THIS to hn-atlas-PATHelp@cern.ch ... for now I will assume the larger number is correct" << std::endl;
268 if(lbxs[runNum][
lb].nExpected < lbr->eventsExpected()) lbxs[
runNum][
lb].nExpected = lbr->eventsExpected();
270 else if(lbxs[runNum][
lb].nExpected==0) lbxs[
runNum][
lb].nExpected=lbr->eventsExpected();
276 std::cout <<
"...ok" << std::endl;
277 if(!useTEvent) {
delete lbrs_nc; lbrs_nc =
nullptr;
delete lbrs_aux; lbrs_aux=0; }
282 lbrs =
nullptr; lbrs_nc =
nullptr; lbrs_aux=0;
283 if(useTEvent &&
event.readFrom(
file,
true,
"MetaData").isSuccess()) {
289 if(metaTree->FindBranch(
"SuspectLumiBlocksAux.")) {
290 if(metaTree->FindBranch(
"SuspectLumiBlocksAux.")->GetSplitLevel()==0) {
291 std::cout <<
" Unable to read unsplit SuspectLumiBlocks" << std::endl;
296 lbrs_nc->setStore( lbrs_aux );
297 metaTree->ResetBranchAddresses();
298 metaTree->SetBranchAddress(
"SuspectLumiBlocksAux.startRunNumber",&startRunNumber);
299 metaTree->SetBranchAddress(
"SuspectLumiBlocksAux.stopRunNumber",&stopRunNumber);
300 metaTree->SetBranchAddress(
"SuspectLumiBlocksAux.startLumiBlockNumber",&startLumiBlockNumber);
301 metaTree->SetBranchAddress(
"SuspectLumiBlocksAux.stopLumiBlockNumber",&stopLumiBlockNumber);
302 metaTree->SetBranchAddress(
"SuspectLumiBlocksAux.eventsExpected",&eventsExpected);
303 metaTree->SetBranchAddress(
"SuspectLumiBlocksAux.eventsSeen",&eventsSeen);
308 std::cout <<
"...xAOD SuspectLumiBlocksAux";
309 for(
int ii=0;ii<metaTree->GetEntries();ii++) {
312 metaTree->GetEntry(ii);
313 for(
unsigned int j=0;
j<startRunNumber.size();
j++) {
315 r->setStartRunNumber(startRunNumber.at(j));
r->setStopRunNumber(stopRunNumber.at(j));
317 r->setEventsExpected(eventsExpected.at(j));
r->setEventsSeen(
eventsSeen.at(j));
321 for(
auto lbr : *lbrs) {
322 for(
uint runNum = lbr->startRunNumber(); runNum <= lbr->stopRunNumber();
runNum++) {
323 if(lbr->startLumiBlockNumber()!=lbr->stopLumiBlockNumber()) {std::cout <<
" Unexpected behaviour. Please report! " << std::endl; std::abort();}
325 lbxs[
runNum][
lb].nSeen += lbr->eventsSeen();
326 lbxs[
runNum][
lb].fromSuspect =
true;
327 if(lbxs[runNum][
lb].nExpected!=0 && lbxs[runNum][
lb].nExpected != lbr->eventsExpected()) {
328 std::cout <<
"...mismatch on expected events in [run,lb]=[" <<
runNum <<
"," <<
lb <<
"] got " << lbr->eventsExpected() <<
" but had " << lbxs[
runNum][
lb].nExpected << std::endl;
329 std::cout <<
"...PLEASE REPORT THIS to hn-atlas-PATHelp@cern.ch ... for now I will assume the larger number is correct" << std::endl;
330 if(lbxs[runNum][
lb].nExpected < lbr->eventsExpected()) lbxs[
runNum][
lb].nExpected = lbr->eventsExpected();
332 else if(lbxs[runNum][
lb].nExpected==0) lbxs[
runNum][
lb].nExpected=lbr->eventsExpected();
339 std::cout <<
"...ok" << std::endl;
340 if(!useTEvent) {
delete lbrs_nc; lbrs_nc =
nullptr;
delete lbrs_aux; lbrs_aux=0; }
343 if(ok) {
file->Close();
delete file;
continue; }
347 if(
file->GetDirectory(
"Lumi")==0) { std::cout <<
"...no Lumi folder. Skipping" << std::endl; }
351 TTree* lumiTree =
dynamic_cast<TTree*
>(
gDirectory->Get(
"lumiTree"));
353 std::cout <<
"...lumiTree";
356 lumiTree->SetBranchAddress(
"lumi",&in);
357 for(
int j=0;
j<lumiTree->GetEntries();
j++) {
358 lumiTree->GetEntry(j);
361 std::cout <<
"...ok" << std::endl;
365 for( Int_t j = 0;
j <
keys->GetEntries(); ++
j ) {
366 TKey *
key =
dynamic_cast<TKey*
>(
keys->At( j ) );
367 TObjString* ostring = (TObjString*)
key->ReadObjectAny( TObjString::Class() );
368 if( ! ostring ) { std::cout <<
"...skipping object: " <<
key->GetName() << std::endl;
continue;}
370 if( ostring->GetString().BeginsWith(
"<?xml version=" ) && ostring->GetString().Contains(
"DOCTYPE LumiRangeCollection" ) ) {
372 std::cout <<
"...ok" << std::endl;
383 std::stringstream definitelySuspect;
384 std::stringstream possiblySuspect;
385 for(
auto& it : lbxs) {
387 for(
auto& it2 :
it.second) {
388 uint lbn = it2.first;
389 if(it2.second.nSeen > it2.second.nExpected) { fromXAODSuspect.
AddRunLumiBlock(runNum,lbn);
continue; }
391 if(it2.second.fromSuspect) { fromXAODPossiblySuspect.
AddRunLumiBlock(runNum,lbn);}
393 if(it2.second.nSeen==it2.second.nExpected) { fromXAOD.
AddRunLumiBlock(runNum,lbn); }
399 l.AddGRL(fromXAOD); lIncomplete.
AddGRL(fromXAODIncomplete); lSuspect.
AddGRL(fromXAODSuspect);lPossiblySuspect.
AddGRL(fromXAODPossiblySuspect);
405 double totalLumi = 0;
double totalLumiIncomplete = 0;
double totalLumiSuspect=0;
double allMissing=0;
double totalLumiPossiblySuspect=0;
406 std::map<UInt_t, float> missingRuns;std::map<UInt_t,bool> allRuns;std::set<UInt_t> incompleteRuns;std::set<UInt_t> suspectRuns;
407 std::map<UInt_t, std::string> missingRunLB;
416 if(lumiFiles.size()==0) {
417 std::cout <<
"FATAL: No lumicalc file provided, please include at least one lumicalc file in your input list" << std::endl;
421 std::cout <<
"Reading LumiMetaData...";
423 for(
auto lfile : lumiFiles) {
424 TFile *lumicalcFile = TFile::Open(
lfile.c_str());
425 if(lumicalcFile==0) {
426 std::cout <<
"Could not open lumicalc file: " <<
argv[1+nOptions] << std::endl;
430 TTree *
tmp = (TTree*)lumicalcFile->Get(
"LumiMetaData" );
432 std::cout <<
"Could not find LumiMetaData tree in lumicalc file: " <<
argv[1+nOptions] << std::endl;
438 UInt_t runNbr=0;Float_t intLumi=0;TBranch *b_runNbr;TBranch *b_intLumi;
439 UInt_t
lb=0.; TBranch *b_lb;
440 if(
tmp->SetBranchAddress(
"RunNbr",&runNbr,&b_runNbr)!=0) {
441 std::cout <<
"Could not find RunNbr branch in LumiMetaData TTree" << std::endl;
return 0;
443 if(
tmp->SetBranchAddress(
"LBStart",&
lb,&b_lb)!=0) {
444 std::cout <<
"Could not find LBStart branch in Data TTree" << std::endl;
return 0;
446 if(
tmp->SetBranchAddress(
"IntLumi",&intLumi,&b_intLumi)!=0) {
447 std::cout <<
"Could not find IntLumi branch in Data TTree" << std::endl;
return 0;
451 int startMissingBlock = -1;UInt_t lastRunNumber=0;
int lastLb=0;
double missingLumi=0;
454 b_runNbr->GetEntry(i);b_intLumi->GetEntry(i);b_lb->GetEntry(i);
457 bool hasLumi =
l.HasRunLumiBlock(runNbr,
lb);
458 if(hasLumi) totalLumi += intLumi;
459 else if(lIncomplete.
HasRunLumiBlock(runNbr,
lb)) {hasLumi=
true; totalLumiIncomplete += intLumi; incompleteRuns.insert(runNbr);}
460 else if(lSuspect.
HasRunLumiBlock(runNbr,
lb)) {hasLumi=
true;totalLumiSuspect += intLumi; suspectRuns.insert(runNbr); definitelySuspect <<
"(" << runNbr <<
"," <<
lb <<
"),";}
462 if(lPossiblySuspect.
HasRunLumiBlock(runNbr,
lb)) {totalLumiPossiblySuspect += intLumi; possiblySuspect <<
"(" << runNbr <<
"," <<
lb <<
"),"; }
464 if(!hasLumi && intLumi==0.) hasLumi=
true;
465 if((lastRunNumber!=runNbr&&startMissingBlock>=0) || (hasLumi && startMissingBlock>=0)) {
467 missingRunLB[lastRunNumber] += ((startMissingBlock==lastLb) ? TString::Format(
"%d",startMissingBlock) : TString::
Format(
"%d-%d",startMissingBlock,lastLb));
468 missingRunLB[lastRunNumber] +=
",";
469 if(showMissing) std::cout <<
"[" << lastRunNumber <<
"," << startMissingBlock <<
"-" << lastLb <<
"," << missingLumi <<
"]";
470 missingRuns[lastRunNumber]+=missingLumi;
471 allMissing+=missingLumi; missingLumi=0;
472 startMissingBlock=-1;
474 if(!hasLumi && startMissingBlock==-1) {startMissingBlock=
lb;missingLumi=intLumi/1E6;}
475 else if(!hasLumi) { missingLumi+=(intLumi/1E6); }
476 lastRunNumber=runNbr;lastLb=
lb;
477 allRuns[runNbr] =
true;
479 lumicalcFile->Close();
480 allMissing += missingLumi;
482 missingRuns[lastRunNumber] += missingLumi;
483 missingRunLB[lastRunNumber] += ((startMissingBlock==lastLb) ? TString::Format(
"%d",startMissingBlock) : TString::
Format(
"%d-%d",startMissingBlock,lastLb));
484 missingRunLB[lastRunNumber] +=
",";
487 std::cout <<
"Done" << std::endl;
488 std::cout <<
"--------------------------------------------" << std::endl;
489 std::cout <<
"***************LUMI REPORT******************" << std::endl << std::endl;
493 if(possiblySuspect.str().size()) {
494 std::cout <<
"Possibly suspect lumiblocks: " << possiblySuspect.str() << std::endl;
496 if(definitelySuspect.str().size()) {
497 std::cout <<
"WARNING ... Definitely suspect lumiblocks (please report this!): " << definitelySuspect.str() << std::endl;
499 std::cout << std::endl <<
"No definitely suspect lumiblocks, that's good!";
504 std::cout << std::endl <<
"Runs with incomplete blocks: ";
505 for(
auto r : incompleteRuns) {
506 std::cout <<
r <<
",";
508 std::cout << std::endl <<
"Runs with missing blocks (missing blocks in brackets): " << std::endl << std::endl;
509 for(
auto it=missingRuns.begin();it!=missingRuns.end();++it) {
510 std::cout <<
" " <<
it->first <<
": " <<
it->second <<
" pb-1 (" << missingRunLB[
it->first] <<
")" << std::endl;
512 std::cout << std::endl <<
"Complete runs: ";
513 for(std::map<UInt_t,bool>::iterator it=allRuns.begin();it!=allRuns.end();++it) {
514 if(missingRuns.find(
it->first) == missingRuns.end() && incompleteRuns.find(
it->first)==incompleteRuns.end() && suspectRuns.find(
it->first) == suspectRuns.end()) std::cout <<
it->first <<
",";
516 std::cout << std::endl;
518 std::cout << std::endl;
519 std::cout <<
"Complete Luminosity = " << totalLumi/1E6 <<
" pb-1" << std::endl;
520 if(totalLumiIncomplete) std::cout <<
"Incomplete Luminosity = " << totalLumiIncomplete/1E6 <<
" pb-1 (this is partially processed lumi blocks)" << std::endl;
521 if(totalLumiSuspect) std::cout <<
"Definitely Suspect Luminosity = " << totalLumiSuspect/1E6 <<
" pb-1 (this is problematic luminosity... please report!)" << std::endl;
522 std::cout <<
"Complete+Incomplete";
523 if(totalLumiSuspect) std::cout <<
"+Suspect";
524 std::cout <<
" Luminosity = " << (totalLumi+totalLumiIncomplete+totalLumiSuspect)/1E6 <<
" pb-1" << std::endl;
525 if(totalLumiPossiblySuspect) {
526 std::cout <<
" (of which is possibly suspect = " << totalLumiPossiblySuspect/1E6 <<
" pb-1 (caused by jobs that did not finish correctly))" << std::endl;
529 std::cout <<
"(Missing Lumonisity = " << allMissing <<
" pb-1) (this is luminosity in your lumicalc files that you appear not to have run over)";
531 std::cout << std::endl;
Define macros for attributes used to control the static checker.
#define ATLAS_NOT_THREAD_SAFE
getNoisyStrip() Find noisy strips from hitmaps and write out into xml/db formats
#define ATLAS_THREAD_SAFE
void AddXMLFile(const TString &xmlfile)
const TGoodRunsList GetMergedGoodRunsList(const Root::BoolOperation &operation=OR) const
Bool_t HasRunLumiBlock(Int_t runnr, Int_t lumiblocknr) const
void AddRunLumiBlock(Int_t runnr, Int_t lumiblocknr)
void AddGRL(const TGoodRunsList &other)
Tool for accessing xAOD files outside of Athena.
l
Printing final latex table to .tex output file.
float j(const xAOD::IParticle &, const xAOD::TrackMeasurementValidation &hit, const Eigen::Matrix3d &jab_inv)
setStartLumiBlockNumber setStopLumiBlockNumber eventsSeen
LumiBlockRange_v1 LumiBlockRange
Declare the latest version of the class.
LumiBlockRangeContainer_v1 LumiBlockRangeContainer
Declare the latest version of the container.
LumiBlockRangeAuxContainer_v1 LumiBlockRangeAuxContainer
Declare the latest version of the auxiliary container.
setStartLumiBlockNumber stopLumiBlockNumber