Пример #1
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
Пример #2
0
    def submit(self,dirname,history):

        # Initializing the JobWriter
        jobber = JobWriter(self.main,dirname,self.resubmit)
        
        # Writing process
        if not self.resubmit:
            logging.info("   Creating folder '"+dirname.split('/')[-1] \
                +"'...")
        else:
            logging.info("   Checking the structure of the folder '"+\
               dirname.split('/')[-1]+"'...")
        if not jobber.Open():
            logging.error("job submission aborted.")
            return False
        
        if not self.resubmit:
            logging.info("   Copying 'SampleAnalyzer' source files...")
            if not jobber.CopyLHEAnalysis():
                logging.error("   job submission aborted.")
                return False
            if not jobber.CreateBldDir():
                logging.error("   job submission aborted.")
                return False
            if self.main.shower.enable:
                 mode=self.main.shower.type
                 if self.main.shower.type=='auto':
                     mode = commands.getstatusoutput('less ' + self.main.datasets[0].filenames[0] + ' | grep parton_shower ')
                     if mode[0]!=0:
                         logging.error('Cannot retrieve the showering information from the LHE files')
                         return False
                     mode = (mode[1].split())[0]
                 if not jobber.CreateShowerDir(mode):
                    logging.error("   job submission aborted.")
                    return False

        logging.info("   Inserting your selection into 'SampleAnalyzer'...")
        if not jobber.WriteSelectionHeader(self.main):
            logging.error("job submission aborted.")
            return False
        if not jobber.WriteSelectionSource(self.main):
            logging.error("job submission aborted.")
            return False

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

        logging.info("   Writing the command line history...")
        jobber.WriteHistory(history,self.main.firstdir)
        layouter = LayoutWriter(self.main, dirname)
        layouter.WriteLayoutConfig()

        if not self.resubmit:
            logging.info("   Creating Makefiles...")
            if not jobber.WriteMakefiles():
                logging.error("job submission aborted.")
                return False

        #edit the delphes cards
        if self.main.fastsim.package in ["delphes","delfes"]:
            self.editDelphesCard(dirname)

        if self.resubmit:
            logging.info("   Cleaning 'SampleAnalyzer'...")
            if not jobber.MrproperJob():
                logging.error("job submission aborted.")
                return False

        logging.info("   Compiling 'SampleAnalyzer'...")
        if not jobber.CompileJob():
            logging.error("job submission aborted.")
            return False

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

        for item in self.main.datasets:
            logging.info("   Running 'SampleAnalyzer' over dataset '"
                         +item.name+"'...")
            logging.info("    *******************************************************")
            if not jobber.RunJob(item):
                logging.error("run over '"+item.name+"' aborted.")
            logging.info("    *******************************************************")
    
        return True   
Пример #3
0
    def submit(self, dirname, history):

        # checking if delphes is needed and installing/activating it if relevant
        detector_handler = DetectorManager(self.main)
        if not detector_handler.manage('delphes'):
            logging.getLogger('MA5').error(
                'Problem with the handling of delphes/delphesMA5tune')
            return False
        if not detector_handler.manage('delphesMA5tune'):
            logging.getLogger('MA5').error(
                'Problem with the handling of delphes/delphesMA5tune')
            return False

        # 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

        # In the case of recasting, there is no need to create a standard Job
        if self.main.recasting.status == "on":
            Recaster = RunRecast(self.main, dirname)
            ### Initialization
            if not Recaster.init():
                return False
            self.main.recasting.delphesruns = Recaster.delphes_runcard
            ### fastsim
            if not Recaster.fastsim():
                self.logger.error("job submission aborted.")
                return False
            ### Analyses
            if not Recaster.analysis():
                self.logger.error("job submission aborted.")
                return False
        # Otherwise, standard job
        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 & check the delphes or recasting cards
        if self.main.fastsim.package in ["delphes", "delphesMA5tune"]:
            delphesCheck = DelphesCardChecker(dirname, self.main)
            if not delphesCheck.checkPresenceCard():
                self.logger.error("job submission aborted.")
                return False
            if not delphesCheck.editCard():
                self.logger.error("job submission aborted.")
                return False
            self.logger.info("   Checking the content of the Delphes card...")
            if not delphesCheck.checkContentCard():
                self.logger.error("job submission aborted.")
                return False

        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