11 import SimpleFunctions
 
   16 logging.basicConfig(format=
'%(asctime)s %(levelname)s %(message)s', datefmt=
'%H:%M:%S')
 
   17 log = logging.getLogger(
"myXsecLogger")
 
   18 log.setLevel(logging.INFO)
 
   29 mainFolder = os.getcwd()
 
   30 xsecFolder = mainFolder+
"/XsecFiles/" 
   31 SimpleFunctions.MakeFolder(xsecFolder)
 
   34 allProcesses = DefineTags.ReturnSampleCategory()
 
   37 allFolders_mc15 = glob.glob(mainFolder+
"/AllSampleInfo_mc15_13TeV/DSID*/*")
 
   38 allFolders_mc15 = 
sorted(allFolders_mc15)
 
   40 allFolders_mc16 = glob.glob(mainFolder+
"/AllSampleInfo_mc16_13TeV/DSID*/*")
 
   41 allFolders_mc16 = 
sorted(allFolders_mc16)
 
   43 allFolders = allFolders_mc15 + allFolders_mc16
 
   51 for entry 
in allFolders:
 
   53     DSID = (entry.split(
"XXX/"))[1]
 
   54     if DSID 
in processed_DSIDs:
 
   56     processed_DSIDs.append(DSID)
 
   58     statusFiles_list = glob.glob(entry+
"/Status*.txt")
 
   60     if len(statusFiles_list) == 0:
 
   65     for iStatus 
in statusFiles_list:
 
   67         AllInfo = StatusFiles.StatusFileReader(iStatus)
 
   68         totalEvents = AllInfo.totalEvents
 
   70         log.debug(
"Reading nevents for %s", AllInfo.dataset)
 
   73             log.error(
"Total Number of Events: %s - Sample %s", 
str(totalEvents), 
str(iStatus))
 
   76             totalEvents = 
float(AllInfo.totalEvents)
 
   77         if totalEvents > nEvents:
 
   81     AllInfo = StatusFiles.StatusFileReader(inputFile)
 
   83     SortingTag = AllInfo.SortingTag
 
   87         log.error(
"Xsec is NAN (%s) for DSID %s", 
str(xsec), DSID)
 
   90         xsec = 
float(xsec)*1000.
 
   91     filterEff = AllInfo.filterEff
 
   93         log.error(
"filterEff is NAN (%s) for DSID %s", 
str(filterEff), DSID)
 
   95     kFactor = AllInfo.kFactor
 
   97         log.error(
"kFactor is NAN (%s) for DSID %s", 
str(kFactor), DSID)
 
   99     dataset = AllInfo.dataset
 
  100     higherOrderXsec = AllInfo.higherOrderXsec
 
  110     if os.path.isfile(mainFolder+
"/AllSampleInfo_mc15_13TeV/SummaryInfo/ListAOD_mc15_13TeV..txt"):
 
  111         arrayAOD_mc15 = SimpleFunctions.GetArraysFromTxtWithString(mainFolder+
"/AllSampleInfo_mc15_13TeV/SummaryInfo/ListAOD_mc15_13TeV..txt", DSID)
 
  112         for iAOD 
in arrayAOD_mc15:
 
  113             if "r7725" in iAOD[0] 
or "r7772" in iAOD[0] 
or "a818" in iAOD[0] 
or "a821" in iAOD[0]:
 
  114                 nEv_mc15 = nEv_mc15 + 
float(iAOD[1])
 
  116     if os.path.isfile(mainFolder+
"/AllSampleInfo_mc16_13TeV/SummaryInfo/ListAOD_mc16_13TeV..txt"):
 
  117         arrayAOD_mc16 = SimpleFunctions.GetArraysFromTxtWithString(mainFolder+
"/AllSampleInfo_mc16_13TeV/SummaryInfo/ListAOD_mc16_13TeV..txt", DSID)
 
  118         for iAOD 
in arrayAOD_mc16:
 
  119             if "r9294" in iAOD[0] 
or "r9315" in iAOD[0]:
 
  120                 nEv_mc16a = nEv_mc16a + 
float(iAOD[1])
 
  121             if "r9778" in iAOD[0] 
or "r10009" in iAOD[0]:
 
  122                 nEv_mc16c = nEv_mc16c + 
float(iAOD[1])
 
  123             if "r10210" in iAOD[0]:
 
  124                 nEv_mc16d = nEv_mc16d + 
float(iAOD[1])
 
  125             if "r999999999999" in iAOD[0]:  
 
  126                 nEv_mc16e = nEv_mc16e + 
float(iAOD[1])
 
  129     datasetSplit = dataset.split(
".evgen")
 
  130     datasetLabel = dataset
 
  132     entry = [
"", 
"", 
"", 
"", 
"", 
"", 
"", 
"", 
"", 
""]
 
  134     if float(higherOrderXsecSample) > 0.:
 
  136             SampleLumi = 
round(
float(nEv_mc16a)/(
float(higherOrderXsecSample))/1000.0, 2)
 
  138             SampleLumi = 
round(
float(nEv_mc15)/(
float(higherOrderXsecSample))/1000.0, 2)
 
  142     tableEntry = [DSID, datasetLabel, 
str(
float(xsec)), 
str(
float(filterEff)), higherOrderXsec, 
str(
float(kFactor)), SortingTag, 
str(SampleLumi), 
str(nEv_mc15), 
str(nEv_mc16a), 
str(nEv_mc16c), 
str(nEv_mc16d), 
str(nEv_mc16e), higherOrderXsecSample]
 
  144     allXsec.append(tableEntry)
 
  146 for Process 
in allProcesses:
 
  147     OutputFile = xsecFolder+
"/list_Xsec_"+Process+
".txt" 
  149     f.write(
"| DSID |  Sample  | Events (mc15) | Events (mc16a) | Events (mc16c) | Events (mc16d) | Events (mc16e) | Sample Lumi (mc15/16a only) [fb-1] | Cross section [pb] | FiltEff | Total higher order xsec [pb] | K-factor | Higher order xsec sample [pb] | \n")
 
  151     for entry 
in allXsec:
 
  153         if Process == entry[6]:
 
  157             f.write(
"| "+entry[0]+
" | "+entry[1]+
" | "+entry[8]+
" | "+entry[9]+
" | "+entry[10]+
" | "+entry[11]+
" | "+entry[12]+
" | "+ entry[7] +
" | "+entry[2]+
" | " +
str(
round(
float(entry[3]), 6))+
" | " +entry[4]+
" | "+
str(
round(
float(entry[5]), 4))+
" | " +
str(
round(
float(entry[13]), 9))+ 
" | \n")
 
  161     OutputFile = xsecFolder+
"/list_Xsec_"+Process+
"_Download.txt" 
  163     f = 
open(OutputFile, 
"w")
 
  164     f.write(
"# DSID \t  Sample  \t Xsec \t FiltEff \t Total higher order xsec \t K-factor \t Higher order  xsec sample  \n")
 
  166     for entry 
in allXsec:
 
  167         if Process == entry[6]:
 
  171             if len(entry[4]) != 1:
 
  172                 f.write(entry[0]+
" \t "+entry[1]+
" \t "+entry[2] +
" \t " +entry[3]+
" \t " +entry[4]+
" \t "+entry[5]+
" \t " +entry[9]+ 
"  \n")
 
  174                 if "Undef" in entry[9]: 
 
  175                     f.write(entry[0]+
" \t "+entry[1]+
" \t "+entry[2] +
" \t " +entry[3]+
" \t " +entry[4]+
" \t Undef. \t " +finalXsec+ 
"  \n")
 
  177                     f.write(entry[0]+
" \t "+entry[1]+
" \t "+entry[2] +
" \t " +entry[3]+
" \t " +entry[4]+
" \t Undef. \t " +entry[9]+ 
"  \n")
 
  180 OutputFile = xsecFolder+
"/list_Xsec_TopDataPrep.txt" 
  181 f = 
open(OutputFile, 
"w")
 
  182 f.write(
"# DSID \t  \t AMIXsec * FiltEff \t K-factor \n")