Example #1
0
 def generate_events(self,dataset,card):
     # Preparing the run
     self.main.recasting.status="off"
     self.main.fastsim.package=self.detector
     self.main.fastsim.clustering=0
     if self.detector=="delphesMA5tune":
         self.main.fastsim.delphes=0
         self.main.fastsim.delphesMA5tune = DelphesMA5tuneConfiguration()
         self.main.fastsim.delphesMA5tune.card = os.path.normpath("../../../../PADForMA5tune/Input/Cards/"+card)
     elif self.detector=="delphes":
         self.main.fastsim.delphesMA5tune = 0
         self.main.fastsim.delphes        = DelphesConfiguration()
         self.main.fastsim.delphes.card   = os.path.normpath("../../../../PAD/Input/Cards/"+card)
     # Execution
     if not self.run_delphes(dataset,card):
         logging.getLogger('MA5').error('The '+detector+' problem with the running of the fastsim')
         return False
     # Restoring the run
     self.main.recasting.status="on"
     self.main.fastsim.package="none"
     ## Saving the output
     if not os.path.isdir(self.dirname+'/Output/'+dataset.name):
         os.mkdir(self.dirname+'/Output/'+dataset.name)
     if not os.path.isdir(self.dirname+'/Output/'+dataset.name+'/RecoEvents'):
         os.mkdir(self.dirname+'/Output/'+dataset.name+'/RecoEvents')
     if self.detector=="delphesMA5tune":
         shutil.move(self.dirname+'_FastSimRun/Output/_'+dataset.name+'/RecoEvents0_0/DelphesMA5tuneEvents.root',\
             self.dirname+'/Output/'+dataset.name+'/RecoEvents/RecoEvents_v1x1_'+card.replace('.tcl','')+'.root')
     elif self.detector=="delphes":
         shutil.move(self.dirname+'_FastSimRun/Output/_'+dataset.name+'/RecoEvents0_0/DelphesEvents.root',\
             self.dirname+'/Output/'+dataset.name+'/RecoEvents/RecoEvents_v1x2_'+card.replace('.tcl','')+'.root')
     ## Cleaning the temporary directory
     if not FolderWriter.RemoveDirectory(os.path.normpath(self.dirname+'_FastSimRun')):
         return False
     ## Exit
     return True
Example #2
0
    def submit(self,dirname,history):
        # checking if the needed version of delphes is activated
        forced_bkp = self.main.forced
        self.main.forced=True
        if self.main.fastsim.package == 'delphes' and not self.main.archi_info.has_delphes:
            installer=InstallManager(self.main)
            if self.main.archi_info.has_delphesMA5tune:
                if not installer.Deactivate('delphesMA5tune'):
                    return False
            if installer.Activate('delphes')==-1:
                return False
        if self.main.fastsim.package == 'delphesMA5tune' and not self.main.archi_info.has_delphesMA5tune:
            installer=InstallManager(self.main)
            if self.main.archi_info.has_delphes:
                if not installer.Deactivate('delphes'):
                    return False
            if installer.Activate('delphesMA5tune')==-1:
                return False
        self.main.forced=forced_bkp

        # Initializing the JobWriter
        jobber = JobWriter(self.main,dirname,self.resubmit)

        # Writing process
        if not self.resubmit:
            self.logger.info("   Creating folder '"+dirname.split('/')[-1] \
                +"'...")
        else:
            self.logger.info("   Checking the structure of the folder '"+\
               dirname.split('/')[-1]+"'...")
        if not jobber.Open():
            self.logger.error("job submission aborted.")
            return False

        if not self.resubmit:
            if self.main.recasting.status != 'on':
                self.logger.info("   Copying 'SampleAnalyzer' source files...")
            if not jobber.CopyLHEAnalysis():
                self.logger.error("   job submission aborted.")
                return False
            if self.main.recasting.status != 'on' and not jobber.CreateBldDir():
                self.logger.error("   job submission aborted.")
                return False
            if self.main.recasting.status == 'on':
                if not FolderWriter.CreateDirectory(dirname+'/Events'):
                    return False

        # In the case of recasting, there is no need to create a standard Job
        if self.main.recasting.status == "on":

            ### First, the analyses to take care off
            self.editRecastingCard(dirname)
            self.logger.info("   Getting the list of delphes simulation to be performed...")

            ### Second, which delphes run must be performed, and running them
            if not self.main.recasting.GetDelphesRuns(dirname+"/Input/recasting_card.dat"):
                return False
            firstv11 = True
            firstv13 = True
            forced_bkp = self.main.forced
            self.main.forced=True
            if len(self.main.recasting.delphesruns)==0:
                self.logger.warning('No recasting to do... Please check the recasting card')
                return False
            for mydelphescard in sorted(self.main.recasting.delphesruns):
                version=mydelphescard[:4]
                card=mydelphescard[5:]
                if version=="v1.1":
                    if not self.main.recasting.ma5tune:
                        self.logger.error('The DelphesMA5tune library is not present... v1.1 analyses cannot be used')
                        return False

                    if firstv11:
                        self.logger.info("   **********************************************************")
                        self.logger.info("   "+StringTools.Center('v1.1 detector simulations',57))
                        self.logger.info("   **********************************************************")
                        firstv11=False

                    ## Deactivating delphes
                    installer=InstallManager(self.main)
                    if not installer.Deactivate('delphes'):
                        return False

                    ## Activating and compile the MA5Tune
                    if installer.Activate('delphesMA5tune')==-1:
                        return False

                    ## running delphesMA5tune
                    for item in self.main.datasets:
                        if not os.path.isfile(dirname + '/Events/' + item.name + '_v1x1_' + \
                             card.replace('.tcl','')+'.root'):
                            self.main.recasting.status="off"
                            self.main.fastsim.package="delphesMA5tune"
                            self.main.fastsim.clustering=0
                            self.main.fastsim.delphes=0
                            self.main.fastsim.delphesMA5tune = DelphesMA5tuneConfiguration()
                            self.main.fastsim.delphesMA5tune.card = os.path.normpath("../../../../PADForMA5tune/Input/Cards/"+card)
                            self.submit(dirname+'_DelphesForMa5tuneRun',[])
                            self.main.recasting.status="on"
                            self.main.fastsim.package="none"
                            ## saving the output
                            shutil.move(dirname+'_DelphesForMa5tuneRun/Output/_'+item.name+'/TheMouth.root',\
                              dirname+'/Events/'+item.name+'_v1x1_'+card.replace('.tcl','')+'.root')
                        if not FolderWriter.RemoveDirectory(os.path.normpath(dirname+'_DelphesForMa5tuneRun')):
                            return False
                elif version in ['v1.2', 'v1.3']:
                    if not self.main.recasting.delphes:
                        self.logger.error('The Delphes library is not present... v1.2+ analyses cannot be used')
                        return False

                    if firstv13:
                        self.logger.info("   **********************************************************")
                        self.logger.info("   "+StringTools.Center('v1.2+ detector simulations',57))
                        self.logger.info("   **********************************************************")
                        firstv13=False

                    ## Deactivating delphesMA5tune
                    installer=InstallManager(self.main)
                    if not installer.Deactivate('delphesMA5tune'):
                        return False

                    ## Activating and compile Delphes
                    if installer.Activate('delphes')==-1:
                        return False

                    ## running delphesMA5tune
                    for item in self.main.datasets:
                        if not os.path.isfile(dirname+'/Events/' + item.name +\
                         '_v1x2_'+card.replace('.tcl','')+'.root'):
                            self.main.recasting.status="off"
                            self.main.fastsim.package="delphes"
                            self.main.fastsim.clustering=0
                            self.main.fastsim.delphesMA5tune=0
                            self.main.fastsim.delphes = DelphesConfiguration()
                            self.main.fastsim.delphes.card = os.path.normpath("../../../../PAD/Input/Cards/"+card)
                            self.submit(dirname+'_DelphesRun',[])
                            self.main.recasting.status="on"
                            self.main.fastsim.package="none"
                            ## saving the output
                            shutil.move(dirname+'_DelphesRun/Output/_'+item.name+'/TheMouth.root',\
                              dirname+'/Events/'+item.name+'_v1x2_'+card.replace('.tcl','')+'.root')
                        if not FolderWriter.RemoveDirectory(os.path.normpath(dirname+'_DelphesRun')):
                            return False
                else:
                    self.logger.error('An analysis can only be compatible with ma5 v1.1, v1.2 or v1.3...')
                    return False
            self.main.forced=forced_bkp

            ### Third, executing the analyses
            if not self.main.recasting.GetAnalysisRuns(dirname+"/Input/recasting_card.dat"):
                return False
            forced_bkp = self.main.forced
            self.main.forced=True
            for mydelphescard in list(set(sorted(self.main.recasting.delphesruns))):
                ## checking the PAD Version
                myversion  = mydelphescard[:4]
                if myversion=='v1.2':
                    PADdir = self.main.archi_info.ma5dir+'/PAD'
                elif myversion=='v1.1':
                    PADdir = self.main.archi_info.ma5dir+'/PADForMA5tune'
                else:
                    self.logger.error('Unknown PAD version')
                    self.main.forced=forced_bkp
                    return False
                ## current delphes card
                mycard     = mydelphescard[5:]
                ## print out
                self.logger.info("   **********************************************************")
                self.logger.info("   "+StringTools.Center(myversion+' running of the PAD'+\
                       ' on events generated with',57))
                self.logger.info("   "+StringTools.Center(mycard,57))
                self.logger.info("   **********************************************************")
                ## setting up Delphes
                installer=InstallManager(self.main)
                if myversion=='v1.1':
                    if not installer.Deactivate('delphes'):
                        self.main.forced=forced_bkp
                        return False
                    if installer.Activate('delphesMA5tune')==-1:
                        self.main.forced=forced_bkp
                        return False
                elif myversion=='v1.2':
                    if not installer.Deactivate('delphesMA5tune'):
                        self.main.forced=forced_bkp
                        return False
                    if installer.Activate('delphes')==-1:
                        self.main.forced=forced_bkp
                        return False
                ## Analyses
                myanalyses = self.main.recasting.analysisruns
                myanalyses = [ x for x in myanalyses if myversion in x ]
                myanalyses = [ x.replace(myversion+'_','') for x in myanalyses ]
                for card,analysislist in self.main.recasting.DelphesDic.items():
                      if card == mycard:
                          tmpanalyses=analysislist
                          break
                myanalyses = [ x for x in myanalyses if x in tmpanalyses]
                ## event file
                for myset in self.main.datasets:
                    myevents=os.path.normpath(dirname + '/Events/' + myset.name + '_' +\
                       myversion.replace('.','x')+'_' + mycard.replace('.tcl','')+'.root')
                    ## preparing and running the PAD
                    if not self.main.recasting.UpdatePADMain(myanalyses,PADdir):
                        self.main.forced=forced_bkp
                        return False
                    time.sleep(1.);
                    if not self.main.recasting.MakePAD(PADdir,dirname,self.main):
                        self.main.forced=forced_bkp
                        return False
                    time.sleep(1.);
                    if not self.main.recasting.RunPAD(PADdir,myevents):
                        self.main.forced=forced_bkp
                        return False
                    time.sleep(1.);
                    ## Restoring the PAD as it was before
                    if not self.main.recasting.RestorePADMain(PADdir,dirname,self.main):
                        self.main.forced=forced_bkp
                        return False
                    time.sleep(1.);
                    ## saving the output
                    if not self.main.recasting.SavePADOutput(PADdir,dirname,myanalyses,myset.name):
                        self.main.forced=forced_bkp
                        return False
                    if not self.main.recasting.store_root:
                        os.remove(os.path.normpath(dirname + '/Events/' + myset.name + '_' +\
                       myversion.replace('.','x')+'_' + mycard.replace('.tcl','')+'.root'))
                    time.sleep(1.);
                    ## Running the CLs exclusion script (if available)
                    if not self.main.recasting.GetCLs(PADdir,dirname,myanalyses,myset.name,myset.xsection,myset.name):
                        self.main.forced=forced_bkp
                        return False
                    ## Saving the results
            self.main.forced=forced_bkp
        else:
            self.logger.info("   Inserting your selection into 'SampleAnalyzer'...")
            if not jobber.WriteSelectionHeader(self.main):
                self.logger.error("job submission aborted.")
                return False
            if not jobber.WriteSelectionSource(self.main):
                self.logger.error("job submission aborted.")
                return False

        self.logger.info("   Writing the list of datasets...")
        for item in self.main.datasets:
            jobber.WriteDatasetList(item)

        self.logger.info("   Writing the command line history...")
        jobber.WriteHistory(history,self.main.firstdir)
        if self.main.recasting.status == "on":
            self.main.recasting.collect_outputs(dirname,self.main.datasets)
            self.logger.info('    -> the results can be found in:') 
            self.logger.info('       '+ dirname + '/Output/CLs_output_summary.dat')
            for item in self.main.datasets:
                self.logger.info('       '+ dirname + '/Output/'+ item.name + '/CLs_output.dat')
        else:
            layouter = LayoutWriter(self.main, dirname)
            layouter.WriteLayoutConfig()

        if not self.main.recasting.status=='on' and not self.resubmit:
            self.logger.info("   Creating Makefiles...")
            if not jobber.WriteMakefiles():
                self.logger.error("job submission aborted.")
                return False

        # Edit the delphes or recasting cards
        if self.main.fastsim.package in ["delphes","delphesMA5tune"]:
            self.editDelphesCard(dirname)

        if self.resubmit and not self.main.recasting.status=='on':
            self.logger.info("   Cleaning 'SampleAnalyzer'...")
            if not jobber.MrproperJob():
                self.logger.error("job submission aborted.")
                return False

        if not self.main.recasting.status=='on':
            self.logger.info("   Compiling 'SampleAnalyzer'...")
            if not jobber.CompileJob():
                self.logger.error("job submission aborted.")
                return False

            self.logger.info("   Linking 'SampleAnalyzer'...")
            if not jobber.LinkJob():
                self.logger.error("job submission aborted.")
                return False

            for item in self.main.datasets:
                self.logger.info("   Running 'SampleAnalyzer' over dataset '"
                             +item.name+"'...")
                self.logger.info("    *******************************************************")
                if not jobber.RunJob(item):
                    self.logger.error("run over '"+item.name+"' aborted.")
                self.logger.info("    *******************************************************")
        return True
Example #3
0
    def user_SetParameter(self, parameter, value, datasets, level, fastjet,
                          delphes, delfes):

        # algorithm
        if parameter == "package":

            # Switch off the clustering
            if value == "none":
                test = True
                for dataset in datasets:
                    if not test:
                        break
                    for file in dataset.filenames:
                        if file.endswith('lhe') or \
                           file.endswith('lhe.gz') or \
                           file.endswith('hep') or \
                           file.endswith('hep.gz') or \
                           file.endswith('hepmc') or \
                           file.endswith('hepmc.gz'):
                            test = False
                            break
                if not test:
                    logging.error("some datasets contain partonic/hadronic file format. "+\
                                  "Fast-simulation package cannot be switched off.")
                    return

            # Switch on the clustering
            elif value in ["fastjet", "delphes", "delfes"]:

                # Only in reco mode
                if level != MA5RunningType.RECO:
                    logging.error(
                        "fast-simulation algorithm is only available in RECO mode"
                    )
                    return

                # Fastjet ?
                if value == 'fastjet' and not fastjet:
                    logging.error(
                        "fastjet library is not installed. Clustering algorithms are not available."
                    )
                    return

                # Delphes ?
                if value == 'delphes' and not delphes:
                    logging.error(
                        "delphes library is not installed. This fast-simulation package is not available."
                    )
                    return

                # Delfes ?
                if value == 'delfes' and not delfes:
                    logging.error(
                        "delfes library is not installed. This fast-simulation package is not available."
                    )
                    return

                test = True
                for dataset in datasets:
                    if not test:
                        break
                    for file in dataset.filenames:
                        if file.endswith('lhco') or \
                           file.endswith('lhco.gz') or \
                           file.endswith('root'):
                            test = False
                            break
                if not test:
                    logging.error(
                        "some datasets contain reconstructed file format. Fast-simulation cannot be switched on."
                    )
                    return

            if value == "fastjet":
                self.package = "fastjet"
                self.clustering = ClusteringConfiguration()
                self.delphes = 0
                self.delfes = 0
            elif value == "delphes":
                self.package = "delphes"
                self.clustering = 0
                self.delphes = DelphesConfiguration()
                self.delfes = 0
            elif value == "delfes":
                self.package = "delfes"
                self.clustering = 0
                self.delphes = 0
                self.delfes = DelfesConfiguration()
            elif value == "none":
                self.package = "none"
                self.clustering = 0
                self.delphes = 0
                self.delfes = 0
            else:
                logging.error("parameter called '" + value + "' is not found.")
            return

        # other rejection if no algo specified
        if self.package == "none":
            logging.error("'fastsim' has no parameter called '" + parameter +
                          "'")
            return

        # other
        if self.package == "fastjet":
            return self.clustering.user_SetParameter(parameter, value,
                                                     datasets, level)
        elif self.package == "delphes":
            return self.delphes.user_SetParameter(parameter, value, datasets,
                                                  level)
        elif self.package == "delfes":
            return self.delfes.user_SetParameter(parameter, value, datasets,
                                                 level)
Example #4
0
class FastsimConfiguration:

    userVariables = {"package": ["fastjet", "delphes", "delfes", "none"]}

    def __init__(self):
        self.clustering = 0
        self.delphes = 0
        self.delfes = 0
        self.package = "none"

    def Display(self):
        self.user_DisplayParameter("package")
        if self.package == "fastjet":
            self.clustering.Display()
        elif self.package == "delphes":
            self.delphes.Display()
        elif self.package == "delfes":
            self.delfes.Display()

    def user_DisplayParameter(self, parameter):
        if parameter == "package":
            logging.info(" fast-simulation package : " + self.package)
            return
        if self.package == "fastjet":
            self.clustering.user_DisplayParameter(parameter)
        elif self.package == "delphes":
            self.delphes.user_DisplayParameter(parameter)
        elif self.package == "delfes":
            self.delfes.user_DisplayParameter(parameter)

    def SampleAnalyzerConfigString(self):
        if self.package == "fastjet":
            mydict = {}
            mydict.update(self.clustering.SampleAnalyzerConfigString())
            return mydict
        elif self.package == "delphes":
            mydict = {}
            mydict.update(self.delphes.SampleAnalyzerConfigString())
            return mydict
        elif self.package == "delfes":
            mydict = {}
            mydict.update(self.delfes.SampleAnalyzerConfigString())
            return mydict
        else:
            return {}

    def user_SetParameter(self, parameter, value, datasets, level, fastjet,
                          delphes, delfes):

        # algorithm
        if parameter == "package":

            # Switch off the clustering
            if value == "none":
                test = True
                for dataset in datasets:
                    if not test:
                        break
                    for file in dataset.filenames:
                        if file.endswith('lhe') or \
                           file.endswith('lhe.gz') or \
                           file.endswith('hep') or \
                           file.endswith('hep.gz') or \
                           file.endswith('hepmc') or \
                           file.endswith('hepmc.gz'):
                            test = False
                            break
                if not test:
                    logging.error("some datasets contain partonic/hadronic file format. "+\
                                  "Fast-simulation package cannot be switched off.")
                    return

            # Switch on the clustering
            elif value in ["fastjet", "delphes", "delfes"]:

                # Only in reco mode
                if level != MA5RunningType.RECO:
                    logging.error(
                        "fast-simulation algorithm is only available in RECO mode"
                    )
                    return

                # Fastjet ?
                if value == 'fastjet' and not fastjet:
                    logging.error(
                        "fastjet library is not installed. Clustering algorithms are not available."
                    )
                    return

                # Delphes ?
                if value == 'delphes' and not delphes:
                    logging.error(
                        "delphes library is not installed. This fast-simulation package is not available."
                    )
                    return

                # Delfes ?
                if value == 'delfes' and not delfes:
                    logging.error(
                        "delfes library is not installed. This fast-simulation package is not available."
                    )
                    return

                test = True
                for dataset in datasets:
                    if not test:
                        break
                    for file in dataset.filenames:
                        if file.endswith('lhco') or \
                           file.endswith('lhco.gz') or \
                           file.endswith('root'):
                            test = False
                            break
                if not test:
                    logging.error(
                        "some datasets contain reconstructed file format. Fast-simulation cannot be switched on."
                    )
                    return

            if value == "fastjet":
                self.package = "fastjet"
                self.clustering = ClusteringConfiguration()
                self.delphes = 0
                self.delfes = 0
            elif value == "delphes":
                self.package = "delphes"
                self.clustering = 0
                self.delphes = DelphesConfiguration()
                self.delfes = 0
            elif value == "delfes":
                self.package = "delfes"
                self.clustering = 0
                self.delphes = 0
                self.delfes = DelfesConfiguration()
            elif value == "none":
                self.package = "none"
                self.clustering = 0
                self.delphes = 0
                self.delfes = 0
            else:
                logging.error("parameter called '" + value + "' is not found.")
            return

        # other rejection if no algo specified
        if self.package == "none":
            logging.error("'fastsim' has no parameter called '" + parameter +
                          "'")
            return

        # other
        if self.package == "fastjet":
            return self.clustering.user_SetParameter(parameter, value,
                                                     datasets, level)
        elif self.package == "delphes":
            return self.delphes.user_SetParameter(parameter, value, datasets,
                                                  level)
        elif self.package == "delfes":
            return self.delfes.user_SetParameter(parameter, value, datasets,
                                                 level)

    def user_GetParameters(self):
        if self.package == "fastjet":
            table = FastsimConfiguration.userVariables.keys()
            table.extend(self.clustering.user_GetParameters())
        elif self.package == "delphes":
            table = FastsimConfiguration.userVariables.keys()
            table.extend(self.delphes.user_GetParameters())
        elif self.package == "delfes":
            table = FastsimConfiguration.userVariables.keys()
            table.extend(self.delfes.user_GetParameters())
        else:
            table = ["package"]
        return table

    def user_GetValues(self, variable):
        table = []
        if self.package == "fastjet":
            try:
                table.extend(FastsimConfiguration.userVariables[variable])
            except:
                pass
            try:
                table.extend(self.clustering.user_GetValues(variable))
            except:
                pass
        elif self.package == "delphes":
            try:
                table.extend(FastsimConfiguration.userVariables[variable])
            except:
                pass
            try:
                table.extend(self.delphes.user_GetValues(variable))
            except:
                pass
        elif self.package == "delfes":
            try:
                table.extend(FastsimConfiguration.userVariables[variable])
            except:
                pass
            try:
                table.extend(self.delfes.user_GetValues(variable))
            except:
                pass
        else:
            if variable == "package":
                table.extend(FastsimConfiguration.userVariables["package"])
        return table
Example #5
0
    def user_SetParameter(self, parameter, value, datasets, level, fastjet, delphes, delfes):

        # algorithm
        if parameter == "package":

            # Switch off the clustering
            if value == "none":
                test = True
                for dataset in datasets:
                    if not test:
                        break
                    for file in dataset.filenames:
                        if (
                            file.endswith("lhe")
                            or file.endswith("lhe.gz")
                            or file.endswith("hep")
                            or file.endswith("hep.gz")
                            or file.endswith("hepmc")
                            or file.endswith("hepmc.gz")
                        ):
                            test = False
                            break
                if not test:
                    logging.error(
                        "some datasets contain partonic/hadronic file format. "
                        + "Fast-simulation package cannot be switched off."
                    )
                    return

            # Switch on the clustering
            elif value in ["fastjet", "delphes", "delfes"]:

                # Only in reco mode
                if level != MA5RunningType.RECO:
                    logging.error("fast-simulation algorithm is only available in RECO mode")
                    return

                # Fastjet ?
                if value == "fastjet" and not fastjet:
                    logging.error("fastjet library is not installed. Clustering algorithms are not available.")
                    return

                # Delphes ?
                if value == "delphes" and not delphes:
                    logging.error("delphes library is not installed. This fast-simulation package is not available.")
                    return

                # Delfes ?
                if value == "delfes" and not delfes:
                    logging.error("delfes library is not installed. This fast-simulation package is not available.")
                    return

                test = True
                for dataset in datasets:
                    if not test:
                        break
                    for file in dataset.filenames:
                        if file.endswith("lhco") or file.endswith("lhco.gz") or file.endswith("root"):
                            test = False
                            break
                if not test:
                    logging.error(
                        "some datasets contain reconstructed file format. Fast-simulation cannot be switched on."
                    )
                    return

            if value == "fastjet":
                self.package = "fastjet"
                self.clustering = ClusteringConfiguration()
                self.delphes = 0
                self.delfes = 0
            elif value == "delphes":
                self.package = "delphes"
                self.clustering = 0
                self.delphes = DelphesConfiguration()
                self.delfes = 0
            elif value == "delfes":
                self.package = "delfes"
                self.clustering = 0
                self.delphes = 0
                self.delfes = DelfesConfiguration()
            elif value == "none":
                self.package = "none"
                self.clustering = 0
                self.delphes = 0
                self.delfes = 0
            else:
                logging.error("parameter called '" + value + "' is not found.")
            return

        # other rejection if no algo specified
        if self.package == "none":
            logging.error("'fastsim' has no parameter called '" + parameter + "'")
            return

        # other
        if self.package == "fastjet":
            return self.clustering.user_SetParameter(parameter, value, datasets, level)
        elif self.package == "delphes":
            return self.delphes.user_SetParameter(parameter, value, datasets, level)
        elif self.package == "delfes":
            return self.delfes.user_SetParameter(parameter, value, datasets, level)
Example #6
0
class FastsimConfiguration:

    userVariables = {"package": ["fastjet", "delphes", "delfes", "none"]}

    def __init__(self):
        self.clustering = 0
        self.delphes = 0
        self.delfes = 0
        self.package = "none"

    def Display(self):
        self.user_DisplayParameter("package")
        if self.package == "fastjet":
            self.clustering.Display()
        elif self.package == "delphes":
            self.delphes.Display()
        elif self.package == "delfes":
            self.delfes.Display()

    def user_DisplayParameter(self, parameter):
        if parameter == "package":
            logging.info(" fast-simulation package : " + self.package)
            return
        if self.package == "fastjet":
            self.clustering.user_DisplayParameter(parameter)
        elif self.package == "delphes":
            self.delphes.user_DisplayParameter(parameter)
        elif self.package == "delfes":
            self.delfes.user_DisplayParameter(parameter)

    def SampleAnalyzerConfigString(self):
        if self.package == "fastjet":
            mydict = {}
            mydict.update(self.clustering.SampleAnalyzerConfigString())
            return mydict
        elif self.package == "delphes":
            mydict = {}
            mydict.update(self.delphes.SampleAnalyzerConfigString())
            return mydict
        elif self.package == "delfes":
            mydict = {}
            mydict.update(self.delfes.SampleAnalyzerConfigString())
            return mydict
        else:
            return {}

    def user_SetParameter(self, parameter, value, datasets, level, fastjet, delphes, delfes):

        # algorithm
        if parameter == "package":

            # Switch off the clustering
            if value == "none":
                test = True
                for dataset in datasets:
                    if not test:
                        break
                    for file in dataset.filenames:
                        if (
                            file.endswith("lhe")
                            or file.endswith("lhe.gz")
                            or file.endswith("hep")
                            or file.endswith("hep.gz")
                            or file.endswith("hepmc")
                            or file.endswith("hepmc.gz")
                        ):
                            test = False
                            break
                if not test:
                    logging.error(
                        "some datasets contain partonic/hadronic file format. "
                        + "Fast-simulation package cannot be switched off."
                    )
                    return

            # Switch on the clustering
            elif value in ["fastjet", "delphes", "delfes"]:

                # Only in reco mode
                if level != MA5RunningType.RECO:
                    logging.error("fast-simulation algorithm is only available in RECO mode")
                    return

                # Fastjet ?
                if value == "fastjet" and not fastjet:
                    logging.error("fastjet library is not installed. Clustering algorithms are not available.")
                    return

                # Delphes ?
                if value == "delphes" and not delphes:
                    logging.error("delphes library is not installed. This fast-simulation package is not available.")
                    return

                # Delfes ?
                if value == "delfes" and not delfes:
                    logging.error("delfes library is not installed. This fast-simulation package is not available.")
                    return

                test = True
                for dataset in datasets:
                    if not test:
                        break
                    for file in dataset.filenames:
                        if file.endswith("lhco") or file.endswith("lhco.gz") or file.endswith("root"):
                            test = False
                            break
                if not test:
                    logging.error(
                        "some datasets contain reconstructed file format. Fast-simulation cannot be switched on."
                    )
                    return

            if value == "fastjet":
                self.package = "fastjet"
                self.clustering = ClusteringConfiguration()
                self.delphes = 0
                self.delfes = 0
            elif value == "delphes":
                self.package = "delphes"
                self.clustering = 0
                self.delphes = DelphesConfiguration()
                self.delfes = 0
            elif value == "delfes":
                self.package = "delfes"
                self.clustering = 0
                self.delphes = 0
                self.delfes = DelfesConfiguration()
            elif value == "none":
                self.package = "none"
                self.clustering = 0
                self.delphes = 0
                self.delfes = 0
            else:
                logging.error("parameter called '" + value + "' is not found.")
            return

        # other rejection if no algo specified
        if self.package == "none":
            logging.error("'fastsim' has no parameter called '" + parameter + "'")
            return

        # other
        if self.package == "fastjet":
            return self.clustering.user_SetParameter(parameter, value, datasets, level)
        elif self.package == "delphes":
            return self.delphes.user_SetParameter(parameter, value, datasets, level)
        elif self.package == "delfes":
            return self.delfes.user_SetParameter(parameter, value, datasets, level)

    def user_GetParameters(self):
        if self.package == "fastjet":
            table = FastsimConfiguration.userVariables.keys()
            table.extend(self.clustering.user_GetParameters())
        elif self.package == "delphes":
            table = FastsimConfiguration.userVariables.keys()
            table.extend(self.delphes.user_GetParameters())
        elif self.package == "delfes":
            table = FastsimConfiguration.userVariables.keys()
            table.extend(self.delfes.user_GetParameters())
        else:
            table = ["package"]
        return table

    def user_GetValues(self, variable):
        table = []
        if self.package == "fastjet":
            try:
                table.extend(FastsimConfiguration.userVariables[variable])
            except:
                pass
            try:
                table.extend(self.clustering.user_GetValues(variable))
            except:
                pass
        elif self.package == "delphes":
            try:
                table.extend(FastsimConfiguration.userVariables[variable])
            except:
                pass
            try:
                table.extend(self.delphes.user_GetValues(variable))
            except:
                pass
        elif self.package == "delfes":
            try:
                table.extend(FastsimConfiguration.userVariables[variable])
            except:
                pass
            try:
                table.extend(self.delfes.user_GetValues(variable))
            except:
                pass
        else:
            if variable == "package":
                table.extend(FastsimConfiguration.userVariables["package"])
        return table