예제 #1
0
  def read_input_files_loop(self,line):
    print "read_input_files_loop"
    map_c = {"typ":99999,"Nam":"default","draw":-999,"ind":-999,"tot":0,"red":-999,"lum":1.0,"xsec":-1.0,"kfac":1.0,"scal":1.0,"json":"","evlist":"","pileup":"",
             "maxfiles":-1}
    #map_c["tot"]=-1
    map_c["addnevents"]=0
    directory = ''
    cas_directory = ''
    dcs_directory = ''
    eos_directory = ''
    fi_name   = ''
    fi_type   = 99999
    # We have one of the file def lines
    split_line = [ s for s in line.replace("split","").split() if s != "" ]
    for sp in split_line:
      val = sp.split("=")
      if val[0] == "Fil":
        fi_name = str(val[1])
      elif val[0]== "Dir":
        directory=str(val[1])
      elif val[0]== "CaDir":
        cas_directory=str(val[1])
      elif val[0]== "DcDir":
        dcs_directory=str(val[1])
      elif val[0]== "EosDir":
        eos_directory=str(val[1])
      elif val[0] == "typ":
        fi_type = int(val[1])
        map_c["typ"] = int(val[1])
      elif val[0] in map_c:
        map_c[val[0]] = type(map_c[val[0]])(val[1])
      else: sys.exit("Unrecognised Argument:\n ' %s ' in line:\n ' %s '"
                     %(val[0],line))
    if map_c["typ"] != 0:
      self.is_data_ = False

    # First check if its a signal sample we are defining, in which case calculate the x-section and BR
    ## print map_c["typ"], map_c["xsec"]
    if map_c["typ"] < 0 and map_c["xsec"] < 0: 
      map_c["xsec"] = self.ut_.signalNormalizer.GetXsection(map_c["typ"]) * self.ut_.signalNormalizer.GetBR(map_c["typ"])
    ## print map_c["typ"], map_c["xsec"]
      
    if fi_name != '':
      temp_dir = "/".join(fi_name.split("/")[:-1])
      if map_c["pileup"] == "":
          map_c["pileup"] = "%s.pileup.root" % temp_dir
          if(temp_dir.startswith("/store") ):
              if not dcs_directory :map_c["pileup"] = 'root://eoscms//eos/cms'+map_c["pileup"]
              else: map_c["pileup"] = 'root://xrootd.grid.hep.ph.ic.ac.uk/'+map_c["pileup"]
                
      if not fi_name.startswith("rfio") and not fi_name.startswith("root:/") and not fi_name.startswith("/castor") and not os.path.isfile(fi_name): 
        sys.exit("No Input File Named: %s"%fi_name)
      tuple_n = fi_name, fi_type
      self.nf_[0]+=1
      if not ( (self.njobs_>0) and (self.nf_[0] % self.njobs_ != self.jobId_) ):
        self.conf_.files.append(tuple_n)
      else: self.conf_.files.append((None,fi_type));
      if fi_type!=0 and fi_type!=99999 and map_c["tot"] == 0:
	if self.sample_weights_file_==0 :
	  if map_c["tot"] <= 0:
              nEventsInFile = getTreeEntry(fi_name,"global_variables","processedEvents")
          else:
              nEventsInFile = map_c["tot"]
	  self.file_processed_events_[fi_name] = nEventsInFile
          map_c["tot"] = nEventsInFile;
	  
	else:  
	  if fi_name in self.file_processed_events_:map_c["tot"] = self.file_processed_events_[fi_name]
	  else: (sys.exit("No Entry for %s found in %s, Please Delete %s and re-run with option --dryRun to regenerate it"%(fi_name,self.sample_weights_file_,self.sample_weights_file_)))

	map_c["addnevents"] = int(1)
      self.conf_.confs.append(map_c.copy())

    mkFiles = None
    dir = None
    if cas_directory != '':
        mkFiles = makeCaFiles
        dir = cas_directory  
    if dcs_directory != '':
        mkFiles = makeDcFiles
        dir = dcs_directory  
    if eos_directory != '':
        mkFiles = makeEosFiles
        dir = eos_directory  
    if directory != '':
        mkFiles = makeFiles
        dir = directory  
        
    if dir:
      files = mkFiles(dir,self.njobs_,self.jobId_,self.nf_,maxfiles=map_c["maxfiles"])
      if fi_type!=0 and fi_type!=99999 and map_c["tot"] == 0:
          allfiles = [ f for f in mkFiles(dir,-1,-1,maxfiles=map_c["maxfiles"]) if not f[0] in self.black_list ]
          ## print allfiles
          if map_c["pileup"] == "":
              map_c["pileup"] = "%s.pileup.root" % dir
              if( dir.startswith("/store") ):
                  if not dcs_directory :map_c["pileup"] = 'root://eoscms//eos/cms'+map_c["pileup"]
                  else: map_c["pileup"] = 'root://xrootd.grid.hep.ph.ic.ac.uk/'+map_c["pileup"]
          for file_s in allfiles:
	      if self.sample_weights_file_==0 :
	        print "Calculating N Processed Events for - ", file_s[0]
		nEventsInFile = getTreeEntry(file_s[0],"global_variables","processedEvents")
                map_c["tot"] = map_c["tot"] + nEventsInFile
		self.file_processed_events_[file_s[0]] = nEventsInFile
	      else:
	        print "Reading N Processed Events for - ", file_s[0]
		if file_s[0] in self.file_processed_events_: map_c["tot"] = map_c["tot"] + self.file_processed_events_[file_s[0]]
		else: (sys.exit("No Entry for %s found in %s, Please Delete %s and re-run with option --dryRun to regenerate it"%(file_s[0],self.sample_weights_file_,self.sample_weights_file_)))

      for file_s in files:
	  if file_s[1]: self.conf_.files.append((file_s[0],fi_type))
	  else:      self.conf_.files.append((None,fi_type))
          self.conf_.confs.append(map_c.copy())
예제 #2
0
    def read_input_files_loop(self, line):
        print "read_input_files_loop"
        map_c = {
            "typ": 99999,
            "Nam": "default",
            "draw": -999,
            "ind": -999,
            "tot": 0,
            "red": -999,
            "lum": 1.0,
            "xsec": -1.0,
            "kfac": 1.0,
            "scal": 1.0,
            "json": "",
            "evlist": "",
            "pileup": "",
            "maxfiles": -1
        }
        #map_c["tot"]=-1
        map_c["addnevents"] = 0
        directory = ''
        cas_directory = ''
        dcs_directory = ''
        eos_directory = ''
        fi_name = ''
        fi_type = 99999
        # We have one of the file def lines
        split_line = [s for s in line.replace("split", "").split() if s != ""]
        for sp in split_line:
            val = sp.split("=")
            if val[0] == "Fil":
                fi_name = str(val[1])
            elif val[0] == "Dir":
                directory = str(val[1])
            elif val[0] == "CaDir":
                cas_directory = str(val[1])
            elif val[0] == "DcDir":
                dcs_directory = str(val[1])
            elif val[0] == "EosDir":
                eos_directory = str(val[1])
            elif val[0] == "typ":
                fi_type = int(val[1])
                map_c["typ"] = int(val[1])
            elif val[0] in map_c:
                map_c[val[0]] = type(map_c[val[0]])(val[1])
            else:
                sys.exit("Unrecognised Argument:\n ' %s ' in line:\n ' %s '" %
                         (val[0], line))
        if map_c["typ"] != 0:
            self.is_data_ = False

        # First check if its a signal sample we are defining, in which case calculate the x-section and BR
        ## print map_c["typ"], map_c["xsec"]
        if map_c["typ"] < 0 and map_c["xsec"] < 0:
            map_c["xsec"] = self.ut_.signalNormalizer.GetXsection(
                map_c["typ"]) * self.ut_.signalNormalizer.GetBR(map_c["typ"])
        ## print map_c["typ"], map_c["xsec"]

        if fi_name != '':
            temp_dir = "/".join(fi_name.split("/")[:-1])
            if map_c["pileup"] == "":
                map_c["pileup"] = "%s.pileup.root" % temp_dir
                if (temp_dir.startswith("/store")):
                    if not dcs_directory:
                        map_c["pileup"] = 'root://eoscms//eos/cms' + map_c[
                            "pileup"]
                    else:
                        map_c[
                            "pileup"] = 'root://xrootd.grid.hep.ph.ic.ac.uk/' + map_c[
                                "pileup"]

            if not fi_name.startswith("rfio") and not fi_name.startswith(
                    "root:/") and not fi_name.startswith(
                        "/castor") and not os.path.isfile(fi_name):
                sys.exit("No Input File Named: %s" % fi_name)
            tuple_n = fi_name, fi_type
            self.nf_[0] += 1
            if not ((self.njobs_ > 0) and
                    (self.nf_[0] % self.njobs_ != self.jobId_)):
                self.conf_.files.append(tuple_n)
            else:
                self.conf_.files.append((None, fi_type))
            if fi_type != 0 and fi_type != 99999 and map_c["tot"] == 0:
                if self.sample_weights_file_ == 0:
                    if map_c["tot"] <= 0:
                        nEventsInFile = getTreeEntry(fi_name,
                                                     "global_variables",
                                                     "processedEvents")
                    else:
                        nEventsInFile = map_c["tot"]
                    self.file_processed_events_[fi_name] = nEventsInFile
                    map_c["tot"] = nEventsInFile

                else:
                    if fi_name in self.file_processed_events_:
                        map_c["tot"] = self.file_processed_events_[fi_name]
                    else:
                        (sys.exit(
                            "No Entry for %s found in %s, Please Delete %s and re-run with option --dryRun to regenerate it"
                            % (fi_name, self.sample_weights_file_,
                               self.sample_weights_file_)))

                map_c["addnevents"] = int(1)
            self.conf_.confs.append(map_c.copy())

        mkFiles = None
        dir = None
        if cas_directory != '':
            mkFiles = makeCaFiles
            dir = cas_directory
        if dcs_directory != '':
            mkFiles = makeDcFiles
            dir = dcs_directory
        if eos_directory != '':
            mkFiles = makeEosFiles
            dir = eos_directory
        if directory != '':
            mkFiles = makeFiles
            dir = directory

        if dir:
            files = mkFiles(dir,
                            self.njobs_,
                            self.jobId_,
                            self.nf_,
                            maxfiles=map_c["maxfiles"])
            if fi_type != 0 and fi_type != 99999 and map_c["tot"] == 0:
                allfiles = [
                    f for f in mkFiles(dir, -1, -1, maxfiles=map_c["maxfiles"])
                    if not f[0] in self.black_list
                ]
                ## print allfiles
                if map_c["pileup"] == "":
                    map_c["pileup"] = "%s.pileup.root" % dir
                    if (dir.startswith("/store")):
                        if not dcs_directory:
                            map_c["pileup"] = 'root://eoscms//eos/cms' + map_c[
                                "pileup"]
                        else:
                            map_c[
                                "pileup"] = 'root://xrootd.grid.hep.ph.ic.ac.uk/' + map_c[
                                    "pileup"]
                for file_s in allfiles:
                    if self.sample_weights_file_ == 0:
                        print "Calculating N Processed Events for - ", file_s[
                            0]
                        nEventsInFile = getTreeEntry(file_s[0],
                                                     "global_variables",
                                                     "processedEvents")
                        map_c["tot"] = map_c["tot"] + nEventsInFile
                        self.file_processed_events_[file_s[0]] = nEventsInFile
                    else:
                        print "Reading N Processed Events for - ", file_s[0]
                        if file_s[0] in self.file_processed_events_:
                            map_c["tot"] = map_c[
                                "tot"] + self.file_processed_events_[file_s[0]]
                        else:
                            (sys.exit(
                                "No Entry for %s found in %s, Please Delete %s and re-run with option --dryRun to regenerate it"
                                % (file_s[0], self.sample_weights_file_,
                                   self.sample_weights_file_)))

            for file_s in files:
                if file_s[1]: self.conf_.files.append((file_s[0], fi_type))
                else: self.conf_.files.append((None, fi_type))
                self.conf_.confs.append(map_c.copy())
예제 #3
0
    def read_input_files_loop(self, line):
        print "read_input_files_loop"
        map_c = {
            "typ": -99999,
            "Nam": "default",
            "draw": -999,
            "ind": -999,
            "tot": 0,
            "red": -999,
            "lum": 1.0,
            "xsec": 1.0,
            "kfac": 1.0,
            "scal": 1.0,
            "json": "",
            "evlist": ""
        }
        #map_c["tot"]=-1
        map_c["addnevents"] = 0
        directory = ''
        cas_directory = ''
        dcs_directory = ''
        fi_name = ''
        fi_type = -99999
        # We have one of the file def lines
        split_line = line.split()
        for sp in split_line:
            val = sp.split("=")
            if val[0] == "Fil":
                fi_name = str(val[1])
            elif val[0] == "Dir":
                directory = str(val[1])
            elif val[0] == "CaDir":
                cas_directory = str(val[1])
            elif val[0] == "DcDir":
                dcs_directory = str(val[1])
            elif val[0] == "typ":
                fi_type = int(val[1])
                map_c["typ"] = int(val[1])
            elif val[0] in map_c:
                map_c[val[0]] = type(map_c[val[0]])(val[1])
            else:
                sys.exit("Unrecognised Argument:\n ' %s ' in line:\n ' %s '" %
                         (val[0], line))
        if map_c["typ"] != 0:
            self.is_data_ = False

        if fi_name != '':
            if not fi_name.startswith("rfio") and not os.path.isfile(fi_name):
                sys.exit("No Input File Named: %s" % fi_name)
            tuple_n = fi_name, fi_type
            self.nf_[0] += 1
            if not ((self.njobs_ > 0) and
                    (self.nf_[0] % self.njobs_ != self.jobId_)):
                self.conf_.files.append(tuple_n)
            else:
                self.conf_.files.append((None, fi_type))
            if fi_type != 0 and fi_type != -99999 and map_c["tot"] == 0:
                if self.sample_weights_file_ == 0:
                    nEventsInFile = getTreeEntry(fi_name, "global_variables",
                                                 "processedEvents")
                    self.file_processed_events_[fi_name] = nEventsInFile
                    map_c["tot"] = nEventsInFile

                else:
                    if fi_name in self.file_processed_events_:
                        map_c["tot"] = self.file_processed_events_[fi_name]
                    else:
                        (sys.exit(
                            "No Entry for %s found in %s, Please Delete %s and re-run with option --dryRun to regenerate it"
                            % (fi_name, self.sample_weights_file_,
                               self.sample_weights_file_)))

                map_c["addnevents"] = int(1)
            self.conf_.confs.append(map_c.copy())

        mkFiles = None
        dir = None
        if cas_directory != '':
            mkFiles = makeCaFiles
            dir = cas_directory
        if dcs_directory != '':
            mkFiles = makeDcFiles
            dir = dcs_directory
        if directory != '':
            mkFiles = makeFiles
            dir = directory

        if dir:
            files = mkFiles(dir, self.njobs_, self.jobId_, self.nf_)
            if fi_type != 0 and fi_type != -99999 and map_c["tot"] == 0:
                allfiles = mkFiles(dir, -1, -1)
                for file_s in allfiles:
                    if self.sample_weights_file_ == 0:
                        print "Calculating N Processed Events for - ", file_s[
                            0]
                        nEventsInFile = getTreeEntry(file_s[0],
                                                     "global_variables",
                                                     "processedEvents")
                        map_c["tot"] = map_c["tot"] + nEventsInFile
                        self.file_processed_events_[file_s[0]] = nEventsInFile
                    else:
                        print "Reading N Processed Events for - ", file_s[0]
                        if file_s[0] in self.file_processed_events_:
                            map_c["tot"] = map_c[
                                "tot"] + self.file_processed_events_[file_s[0]]
                        else:
                            (sys.exit(
                                "No Entry for %s found in %s, Please Delete %s and re-run with option --dryRun to regenerate it"
                                % (file_s[0], self.sample_weights_file_,
                                   self.sample_weights_file_)))

            for file_s in files:
                if file_s[1]: self.conf_.files.append((file_s[0], fi_type))
                else: self.conf_.files.append((None, fi_type))
                self.conf_.confs.append(map_c.copy())
예제 #4
0
  def read_input_files_loop(self,line):
    print "read_input_files_loop"
    map_c = {"typ":-99999,"Nam":"default","draw":-999,"ind":-999,"tot":0,"red":-999,"lum":1.0,"xsec":1.0,"kfac":1.0,"scal":1.0,"json":"","evlist":""}
    #map_c["tot"]=-1
    map_c["addnevents"]=0
    directory = ''
    cas_directory = ''
    dcs_directory = ''
    fi_name   = ''
    fi_type   = -99999
    # We have one of the file def lines
    split_line = line.split()
    for sp in split_line:
      val = sp.split("=")
      if val[0] == "Fil":
        fi_name = str(val[1])
      elif val[0]== "Dir":
        directory=str(val[1])
      elif val[0]== "CaDir":
        cas_directory=str(val[1])
      elif val[0]== "DcDir":
        dcs_directory=str(val[1])
      elif val[0] == "typ":
        fi_type = int(val[1])
        map_c["typ"] = int(val[1])
      elif val[0] in map_c:
        map_c[val[0]] = type(map_c[val[0]])(val[1])
      else: sys.exit("Unrecognised Argument:\n ' %s ' in line:\n ' %s '"
                     %(val[0],line))
    if map_c["typ"] != 0:
      self.is_data_ = False
      
    if fi_name != '':
      if not fi_name.startswith("rfio") and not os.path.isfile(fi_name): 
        sys.exit("No Input File Named: %s"%fi_name)
      tuple_n = fi_name, fi_type
      self.nf_[0]+=1
      if not ( (self.njobs_>0) and (self.nf_[0] % self.njobs_ != self.jobId_) ):
        self.conf_.files.append(tuple_n)
      else: self.conf_.files.append((None,fi_type));
      if fi_type!=0 and fi_type!=-99999 and map_c["tot"] == 0:
	if self.sample_weights_file_==0 :
	  nEventsInFile = getTreeEntry(fi_name,"global_variables","processedEvents")
	  self.file_processed_events_[fi_name] = nEventsInFile
          map_c["tot"] = nEventsInFile;
	  
	else:  
	  if fi_name in self.file_processed_events_:map_c["tot"] = self.file_processed_events_[fi_name]
	  else: (sys.exit("No Entry for %s found in %s, Please Delete %s and re-run with option --dryRun to regenerate it"%(fi_name,self.sample_weights_file_,self.sample_weights_file_)))

	map_c["addnevents"] = int(1)
      self.conf_.confs.append(map_c.copy())

    mkFiles = None
    dir = None
    if cas_directory != '':
        mkFiles = makeCaFiles
        dir = cas_directory  
    if dcs_directory != '':
        mkFiles = makeDcFiles
        dir = dcs_directory  
    if directory != '':
        mkFiles = makeFiles
        dir = directory  
        
    if dir:
      files = mkFiles(dir,self.njobs_,self.jobId_,self.nf_)
      if fi_type!=0 and fi_type!=-99999 and map_c["tot"] == 0:
          allfiles = mkFiles(dir,-1,-1)
          for file_s in allfiles:
	      print "Getting N Processed Events for - ", file_s[0]
	      if self.sample_weights_file_==0 :
		nEventsInFile = getTreeEntry(file_s[0],"global_variables","processedEvents")
                map_c["tot"] = map_c["tot"] + nEventsInFile
		self.file_processed_events_[file_s[0]] = nEventsInFile
	      else:
		if file_s[0] in self.file_processed_events_: map_c["tot"] = map_c["tot"] + self.file_processed_events_[file_s[0]]
		else: (sys.exit("No Entry for %s found in %s, Please Delete %s and re-run with option --dryRun to regenerate it"%(file_s[0],self.sample_weights_file_,self.sample_weights_file_)))

      for file_s in files:
	  if file_s[1]: self.conf_.files.append((file_s[0],fi_type))
	  else:      self.conf_.files.append((None,fi_type))
          self.conf_.confs.append(map_c.copy())
예제 #5
0
  def read_input_files_loop(self,line):
    print "read_input_files_loop"
    map_c = {"typ":99999,"Nam":"default","draw":-999,"ind":-999,"tot":0,"red":-999,"lum":1.0,"xsec":-1.0,"kfac":1.0,"scal":1.0,"json":"","evlist":"","pileup":"","version":0,'noevwei':False,
             "maxfiles":-1}
    #map_c["tot"]=-1
    map_c["addnevents"]=0
    directory = ''
    cas_directory = ''
    dcs_directory = ''
    eos_directory = ''
    fi_name   = ''
    # We have one of the file def lines
    split_line = [ s for s in line.replace("split","").split() if s != "" ]
    for sp in split_line:
      val = sp.split("=")
      if val[0] == "Fil":
        fi_name = str(val[1])
      elif val[0]== "Dir":
        directory=str(val[1])
      elif val[0]== "CaDir":
        cas_directory=str(val[1])
      elif val[0]== "DcDir":
        dcs_directory=str(val[1])
      elif val[0]== "EosDir":
        eos_directory=str(val[1])
      elif val[0] == "typ":
        map_c["typ"] = int(val[1])
      elif val[0] in map_c:
        map_c[val[0]] = type(map_c[val[0]])(val[1])
      else: sys.exit("Unrecognised Argument:\n ' %s ' in line:\n ' %s '"
                     %(val[0],line))
    if map_c["typ"] != 0:
      self.is_data_ = False

    # First check if its a signal sample we are defining, in which case calculate the x-section and BR
    ## print map_c["typ"], map_c["xsec"]
    if (map_c["typ"] == -1) : 
	  sample_name = map_c["Nam"]
	  ## hmass = int(sample_name[sample_name.find("m")+1:sample_name.find("m")+1+sample_name.find("_")])
          hmass = None
          toks = sample_name.split("_")
          print toks
          for tok in toks:
              if tok.startswith("m") and tok[1:].isdigit():
                  hmass=int(tok[1:])
                  break
          if not hmass:
              print "The type id for the sample name %s is -1 so I tried to assign the type id automatically." % sample_name 
              print "   ... however I only recognize the format Nam=<process>_m<mass>_<sqrtS>."
              print "Please fix your configuration file and run again. "
              sys.exit(1)
          newtype = 1000*hmass
	  proc = ""
	  if "ggh" in sample_name:
                if "minlo" in sample_name:
                    proc="ggh_minlo"
                    newtype+=10
                else:
                    proc="ggh"
	  elif "vbf" in sample_name: 
		newtype+=100
		proc="vbf"
	  elif "wzh" in sample_name: 
		newtype+=500
		proc="wzh"
	  elif "tth" in sample_name: 
		newtype+=400
		proc="tth"
	  elif "wh" in sample_name:
		newtype+=200
		proc="wh"
	  elif "zh" in sample_name: 
		newtype+=300
		proc="zh"
          elif "gg_grav" in sample_name or "grav2pm" in sample_name:
                newtype+=600
                proc="gg_grav"
          elif "spin0plus" in sample_name:
                newtype+=610
                proc="gg_spin0"
          elif "qq_grav" in sample_name:
                newtype+=650
                proc="qq_grav"
	  map_c["typ"]=-1*newtype
          print "Automatic sample type name:%s mass:%d proc:%s type:%d " % (sample_name, hmass, proc, -newtype)
          if map_c["xsec"] < 0: # not provided so figure it out ourselves
            map_c["xsec"] = self.ut_.normalizer().GetXsection(float(hmass),proc) * self.ut_.normalizer().GetBR(float(hmass))
    elif map_c["typ"] < 0 and map_c["xsec"] < 0:
          mass = self.ut_.normalizer().GetMass(map_c["typ"])
          proc = self.ut_.normalizer().GetProcess(map_c["typ"])
          map_c["xsec"] = self.ut_.normalizer().GetXsection(mass,proc) * self.ut_.normalizer().GetBR(mass)
    if PYDEBUG: print "Calculated signal X-section*BR = ", map_c["Nam"],map_c["typ"], map_c["xsec"]
    fi_type = map_c["typ"]
    
    if fi_name != '':
      temp_dir = "/".join(fi_name.split("/")[:-1])
      if map_c["pileup"] == "":
          map_c["pileup"] = "%s.pileup.root" % temp_dir
          if(temp_dir.startswith("/store") ):
              if not dcs_directory :map_c["pileup"] = 'root://eoscms//eos/cms'+map_c["pileup"]
              else: map_c["pileup"] = 'root://xrootd.grid.hep.ph.ic.ac.uk/'+map_c["pileup"]
                
      if not fi_name.startswith("rfio") and not fi_name.startswith("root:/") and not fi_name.startswith("/castor") and not os.path.isfile(fi_name): 
        sys.exit("No Input File Named: %s"%fi_name)
      tuple_n = fi_name, fi_type
      self.nf_[0]+=1
      if not ( (self.njobs_>0) and (self.nf_[0] % self.njobs_ != self.jobId_) ):
        self.conf_.files.append(tuple_n)
      else: self.conf_.files.append((None,fi_type));
      if fi_type!=0 and fi_type!=99999 and map_c["tot"] == 0:
        if self.sample_weights_file_==0 :
          if map_c["tot"] <= 0:
              nEventsInFile = getTreeEntry(fi_name,"global_variables","processedEvents")
          else:
              nEventsInFile = map_c["tot"]
          self.file_processed_events_[fi_name] = nEventsInFile
          map_c["tot"] = nEventsInFile;
	  
	else:  
	  if fi_name in self.file_processed_events_:map_c["tot"] = self.file_processed_events_[fi_name]
	  else: (sys.exit("No Entry for %s found in %s, Please Delete %s and re-run with option --dryRun to regenerate it"%(fi_name,self.sample_weights_file_,self.sample_weights_file_)))

	map_c["addnevents"] = int(1)
      self.conf_.confs.append(map_c.copy())

    mkFiles = None
    dir = None
    if cas_directory != '':
        mkFiles = makeCaFiles
        dir = cas_directory  
    if dcs_directory != '':
        mkFiles = makeDcFiles
        dir = dcs_directory  
    if eos_directory != '':
        mkFiles = makeEosFiles
        dir = eos_directory  
    if directory != '':
        mkFiles = makeFiles
        dir = directory  
        
    if dir:
      files = mkFiles(dir,self.njobs_,self.jobId_,self.nf_,maxfiles=map_c["maxfiles"])
      if fi_type!=0 and fi_type!=99999 and map_c["tot"] == 0:
          allfiles = [ f for f in mkFiles(dir,-1,-1,maxfiles=map_c["maxfiles"]) if not f[0] in self.black_list ]
          ## print allfiles
          if map_c["pileup"] == "":
              map_c["pileup"] = "%s.pileup.root" % dir
              if( dir.startswith("/store") ):
                  if not dcs_directory :map_c["pileup"] = 'root://eoscms//eos/cms'+map_c["pileup"]
                  else: map_c["pileup"] = 'root://xrootd.grid.hep.ph.ic.ac.uk/'+map_c["pileup"]
          for file_s in allfiles:
	      if self.sample_weights_file_==0 :
	        print "Calculating N Processed Events for - ", file_s[0]
		nEventsInFile = getTreeEntry(file_s[0],"global_variables","processedEvents")
                map_c["tot"] = map_c["tot"] + nEventsInFile
		self.file_processed_events_[file_s[0]] = nEventsInFile
	      else:
	        print "Reading N Processed Events for - ", file_s[0]
		if file_s[0] in self.file_processed_events_: map_c["tot"] = map_c["tot"] + self.file_processed_events_[file_s[0]]
		else: (sys.exit("No Entry for %s found in %s, Please Delete %s and re-run with option --dryRun to regenerate it"%(file_s[0],self.sample_weights_file_,self.sample_weights_file_)))

      for file_s in files:
	  if file_s[1]: self.conf_.files.append((file_s[0],fi_type))
	  else:      self.conf_.files.append((None,fi_type))
          self.conf_.confs.append(map_c.copy())
예제 #6
0
    def read_input_files_loop(self, line):
        print "read_input_files_loop"
        map_c = {
            "typ": 99999,
            "Nam": "default",
            "draw": -999,
            "ind": -999,
            "tot": 0,
            "red": -999,
            "lum": 1.0,
            "xsec": -1.0,
            "kfac": 1.0,
            "scal": 1.0,
            "json": "",
            "evlist": "",
            "pileup": "",
            "version": 0,
            'noevwei': False,
            "maxfiles": -1
        }
        #map_c["tot"]=-1
        map_c["addnevents"] = 0
        directory = ''
        cas_directory = ''
        dcs_directory = ''
        eos_directory = ''
        fi_name = ''
        # We have one of the file def lines
        split_line = [s for s in line.replace("split", "").split() if s != ""]
        for sp in split_line:
            val = sp.split("=")
            if val[0] == "Fil":
                fi_name = str(val[1])
            elif val[0] == "Dir":
                directory = str(val[1])
            elif val[0] == "CaDir":
                cas_directory = str(val[1])
            elif val[0] == "DcDir":
                dcs_directory = str(val[1])
            elif val[0] == "EosDir":
                eos_directory = str(val[1])
            elif val[0] == "typ":
                map_c["typ"] = int(val[1])
            elif val[0] in map_c:
                map_c[val[0]] = type(map_c[val[0]])(val[1])
            else:
                sys.exit("Unrecognised Argument:\n ' %s ' in line:\n ' %s '" %
                         (val[0], line))
        if map_c["typ"] != 0:
            self.is_data_ = False

        # First check if its a signal sample we are defining, in which case calculate the x-section and BR
        ## print map_c["typ"], map_c["xsec"]
        if (map_c["typ"] == -1):
            sample_name = map_c["Nam"]
            ## hmass = int(sample_name[sample_name.find("m")+1:sample_name.find("m")+1+sample_name.find("_")])
            hmass = None
            toks = sample_name.split("_")
            print toks
            for tok in toks:
                if tok.startswith("m") and tok[1:].isdigit():
                    hmass = int(tok[1:])
                    break
            if not hmass:
                print "The type id for the sample name %s is -1 so I tried to assign the type id automatically." % sample_name
                print "   ... however I only recognize the format Nam=<process>_m<mass>_<sqrtS>."
                print "Please fix your configuration file and run again. "
                sys.exit(1)
            newtype = 1000 * hmass
            proc = ""
            if "ggh" in sample_name:
                if "minlo" in sample_name:
                    proc = "ggh_minlo"
                    newtype += 10
                else:
                    proc = "ggh"
            elif "vbf" in sample_name:
                newtype += 100
                proc = "vbf"
            elif "wzh" in sample_name:
                newtype += 500
                proc = "wzh"
            elif "tth" in sample_name:
                newtype += 400
                proc = "tth"
            elif "wh" in sample_name:
                newtype += 200
                proc = "wh"
            elif "zh" in sample_name:
                newtype += 300
                proc = "zh"
            elif "gg_grav" in sample_name or "grav2pm" in sample_name:
                newtype += 600
                proc = "gg_grav"
            elif "spin0plus" in sample_name:
                newtype += 610
                proc = "gg_spin0"
            elif "qq_grav" in sample_name:
                newtype += 650
                proc = "qq_grav"
            map_c["typ"] = -1 * newtype
            print "Automatic sample type name:%s mass:%d proc:%s type:%d " % (
                sample_name, hmass, proc, -newtype)
            if map_c["xsec"] < 0:  # not provided so figure it out ourselves
                map_c["xsec"] = self.ut_.normalizer().GetXsection(
                    float(hmass), proc) * self.ut_.normalizer().GetBR(
                        float(hmass))
        elif map_c["typ"] < 0 and map_c["xsec"] < 0:
            mass = self.ut_.normalizer().GetMass(map_c["typ"])
            proc = self.ut_.normalizer().GetProcess(map_c["typ"])
            map_c["xsec"] = self.ut_.normalizer().GetXsection(
                mass, proc) * self.ut_.normalizer().GetBR(mass)
        if PYDEBUG:
            print "Calculated signal X-section*BR = ", map_c["Nam"], map_c[
                "typ"], map_c["xsec"]
        fi_type = map_c["typ"]

        if fi_name != '':
            temp_dir = "/".join(fi_name.split("/")[:-1])
            if map_c["pileup"] == "":
                map_c["pileup"] = "%s.pileup.root" % temp_dir
                if (temp_dir.startswith("/store")):
                    if not dcs_directory:
                        map_c["pileup"] = 'root://eoscms//eos/cms' + map_c[
                            "pileup"]
                    else:
                        map_c[
                            "pileup"] = 'root://xrootd.grid.hep.ph.ic.ac.uk/' + map_c[
                                "pileup"]

            if not fi_name.startswith("rfio") and not fi_name.startswith(
                    "root:/") and not fi_name.startswith(
                        "/castor") and not os.path.isfile(fi_name):
                sys.exit("No Input File Named: %s" % fi_name)
            tuple_n = fi_name, fi_type
            self.nf_[0] += 1
            if not ((self.njobs_ > 0) and
                    (self.nf_[0] % self.njobs_ != self.jobId_)):
                self.conf_.files.append(tuple_n)
            else:
                self.conf_.files.append((None, fi_type))
            if fi_type != 0 and fi_type != 99999 and map_c["tot"] == 0:
                if self.sample_weights_file_ == 0:
                    if map_c["tot"] <= 0:
                        nEventsInFile = getTreeEntry(fi_name,
                                                     "global_variables",
                                                     "processedEvents")
                    else:
                        nEventsInFile = map_c["tot"]
                    self.file_processed_events_[fi_name] = nEventsInFile
                    map_c["tot"] = nEventsInFile

                else:
                    if fi_name in self.file_processed_events_:
                        map_c["tot"] = self.file_processed_events_[fi_name]
                    else:
                        (sys.exit(
                            "No Entry for %s found in %s, Please Delete %s and re-run with option --dryRun to regenerate it"
                            % (fi_name, self.sample_weights_file_,
                               self.sample_weights_file_)))

                map_c["addnevents"] = int(1)
            self.conf_.confs.append(map_c.copy())

        mkFiles = None
        dir = None
        if cas_directory != '':
            mkFiles = makeCaFiles
            dir = cas_directory
        if dcs_directory != '':
            mkFiles = makeDcFiles
            dir = dcs_directory
        if eos_directory != '':
            mkFiles = makeEosFiles
            dir = eos_directory
        if directory != '':
            mkFiles = makeFiles
            dir = directory

        if dir:
            files = mkFiles(dir,
                            self.njobs_,
                            self.jobId_,
                            self.nf_,
                            maxfiles=map_c["maxfiles"])
            if fi_type != 0 and fi_type != 99999 and map_c["tot"] == 0:
                allfiles = [
                    f for f in mkFiles(dir, -1, -1, maxfiles=map_c["maxfiles"])
                    if not f[0] in self.black_list
                ]
                ## print allfiles
                if map_c["pileup"] == "":
                    map_c["pileup"] = "%s.pileup.root" % dir
                    if (dir.startswith("/store")):
                        if not dcs_directory:
                            map_c["pileup"] = 'root://eoscms//eos/cms' + map_c[
                                "pileup"]
                        else:
                            map_c[
                                "pileup"] = 'root://xrootd.grid.hep.ph.ic.ac.uk/' + map_c[
                                    "pileup"]
                for file_s in allfiles:
                    if self.sample_weights_file_ == 0:
                        print "Calculating N Processed Events for - ", file_s[
                            0]
                        nEventsInFile = getTreeEntry(file_s[0],
                                                     "global_variables",
                                                     "processedEvents")
                        map_c["tot"] = map_c["tot"] + nEventsInFile
                        self.file_processed_events_[file_s[0]] = nEventsInFile
                    else:
                        print "Reading N Processed Events for - ", file_s[0]
                        if file_s[0] in self.file_processed_events_:
                            map_c["tot"] = map_c[
                                "tot"] + self.file_processed_events_[file_s[0]]
                        else:
                            (sys.exit(
                                "No Entry for %s found in %s, Please Delete %s and re-run with option --dryRun to regenerate it"
                                % (file_s[0], self.sample_weights_file_,
                                   self.sample_weights_file_)))

            for file_s in files:
                if file_s[1]: self.conf_.files.append((file_s[0], fi_type))
                else: self.conf_.files.append((None, fi_type))
                self.conf_.confs.append(map_c.copy())