NtupleWriter14/run/AANtupleWriter14.py

00001 ##############################
00002 #
00003 # Author: MDT group, MPI Munich
00004 #
00005 #    run with: athena  -c 'jetcontainer = "Cone4H1Topo" ; dataset = "5333" ; outputdir =
00006 #    "/.at/mdtraid06/mgroh"' AANtupleWriter14.py
00007 #
00008 #    for a more detailed description please see at the end of this file
00009 #
00010 ##############################
00011 
00012 # if values are not given as an argument
00013 # run with default values:
00014 #################################################################
00015 # T.E.: this stuff is new for release 14 (mainly trigger)
00016 #       I don't have a clue if this is correct
00017 ##########################################
00018 ## Set up trigger configuration service and metadata service is relies on, for analysis job without RecExCommon
00019 
00020 from AthenaCommon.GlobalFlags import GlobalFlags
00021 GlobalFlags.DetGeo.set_atlas()
00022 
00023 ## set up trigger decision tool
00024 from TrigDecision.TrigDecisionConfig import TrigDecisionTool
00025 tdt = TrigDecisionTool()
00026 ToolSvc += tdt
00027 
00028 # T.E.: seems like we don't need this:
00029 # might be needed for TriggerConfigGetter...
00030 from RecExConfig.RecFlags  import rec
00031 rec.readAOD=True
00032 rec.doWriteAOD=False
00033 rec.doWriteESD=False
00034 
00035 # To read files with trigger config stored as in-file meta-data,
00036 # i.e. 14.0.40 and above: ds
00037 # To read AOD produced with 14.0.30 you need to change ds to aod:
00038 from TriggerJobOpts.TriggerFlags import TriggerFlags
00039 TriggerFlags.configurationSourceList = ['ds']
00040 
00041 # set up trigger config service
00042 from TriggerJobOpts.TriggerConfigGetter import TriggerConfigGetter
00043 cfg =  TriggerConfigGetter()
00044 
00045 LoadATLASGeometry=True
00046 DetDescrVersion="ATLAS-CSC-02-01-00"
00047 # T.E.: end
00048 ###############################################################
00049 
00050 
00051 sys.path.append('data')
00052 import datatools
00053 import datetime
00054 
00055 #check command line and set default values
00056 if not 'dataset' in dir():
00057    dataset = "default"
00058 
00059 if not 'outputdir' in dir():
00060    outputdir = ""
00061 
00062 if not 'AtlFastFlag' in dir():
00063    AtlFastFlag = False;
00064    if (dataset.lower().find('atlfast') != -1):
00065       AtlFastFlag = True;
00066 
00067 if not 'doAODFix1mm' in dir():
00068    doAODFix1mm = False;
00069 
00070 if not 'doEventWeight' in dir():
00071    doEventWeight = True;
00072    if (dataset.lower().find('sherpa') != -1):
00073       doEventWeight = False;
00074 
00075 if not 'filenumber' in dir() or filenumber < 0:
00076    filenumber = 0;
00077    
00078 if not 'jetcontainer' in dir():
00079    jetcontainer = "Cone4H1Topo"
00080 
00081 if not 'nevents' in dir():
00082    nevents = -1
00083 
00084 if not 'doTrackJets' in dir() or AtlFastFlag == True:
00085    doTrackJets = False
00086 
00087 if not 'doTrackParticles' in dir() or AtlFastFlag == True:
00088    doTrackParticles = False
00089 
00090 # put the names of the jetcontainers together
00091 jetcontainername =  jetcontainer + "Jets"
00092 namelist = ["H1Topo", "UnCalTopo", "Topo", "Tower"]
00093 truthjetcontainername = ""
00094 
00095 for k_string in namelist:
00096    
00097    if k_string in jetcontainername:
00098       
00099       truthjetcontainername = jetcontainername.replace(k_string,"Truth")
00100       break
00101 
00102 
00103 # import the data types 
00104 import EventKernel.ParticleDataType
00105 
00106 #EventSelector = Service( "EventSelector" )
00107 
00108 # load additional libraries for back navigation
00109 from AnalysisExamples.AnalysisFlags import AnalysisFlags
00110 
00111 include( "AthenaPoolCnvSvc/ReadAthenaPool_jobOptions.py" )
00112 if AnalysisFlags.DoNavigation:
00113    include ("RecExCommon/AllDet_detDescr.py")
00114    ServiceMgr.EventSelector.BackNavigation = True
00115 
00116 # the Dlls
00117 include( "ParticleBuilderOptions/ESD_PoolCnv_jobOptions.py" )
00118 include( "ParticleBuilderOptions/AOD_PoolCnv_jobOptions.py")
00119 include( "ParticleBuilderOptions/McAOD_PoolCnv_jobOptions.py")
00120 include( "EventAthenaPool/EventAthenaPool_joboptions.py" )
00121 include( "TrackIsolationTools/TrackIsolationTool_jobOptions.py" )
00122 
00123 
00124 if(doTrackJets):
00125    # configure VertexCollectionSvc
00126    theApp.ExtSvc += [ "VertexCollectionSvc" ]
00127    VertexCollectionSvc = Service( "VertexCollectionSvc" )
00128    theApp.TopAlg += [ "MPIHiggsAnalysis::VertexCollector" ]
00129    VertexCollector = Algorithm( "MPIHiggsAnalysis::VertexCollector" )
00130    #VertexCollector.VertexCollectionSvc = "MPIHiggsAnalysis::VertexCollector"
00131 
00132    include( "Cone4TrackJet_jobOptions.py" )
00133    include( "Cone4TruthTrackJet_jobOptions.py" )
00134 
00135 
00136 HistogramPersistencySvc = Service( "HistogramPersistencySvc" )
00137 theApp.Dlls += [ "RootHistCnv" ]
00138 theApp.HistogramPersistency = "ROOT"
00139 #HistogramPersistencySvc.OutputFile = "histos.root"
00140 
00141 
00142 # write out a summary of the time spent
00143 theApp.Dlls += [ "GaudiAud" ]
00144 #theAuditorSvc = AuditorSvc()
00145 theAuditorSvc.Auditors  += [ "ChronoAuditor", "MemStatAuditor"]
00146 
00147 # User Analysis Dll's
00148 theApp.Dlls   += [ "CBNT_Athena", "CBNT_Utils" ]
00149 theApp.Dlls   += [ "AnalysisTools" ]
00150 theApp.Dlls   += [ "AnalysisExamples" ]
00151 
00152 # The algorithms to run
00153 #theApp.TopAlg += [ "CBNT_Athena/AOD_ANA" ]
00154 #AOD_ANA = Algorithm( "AOD_ANA" )
00155 
00156 #init the dataset library 
00157 data_lib = datatools.DataLib()
00158 
00159 
00160 #check if joboption from default path should be included 
00161 jo_path = ''
00162 
00163 if dataset.find('jo:') != -1:
00164    dataset = dataset.replace('jo:','');
00165    jo_path = '/.at/mdtraid04/12.0.X_data/data_jo_files/'
00166    print "Include data from .py file in path: ", jo_path 
00167 
00168 
00169 #fill the dataset library
00170 include("data/datasetdef.py")
00171 include("data/datasetdef_manfred.py")
00172 include("data/datasetdef_steffen.py")
00173 include("data/datasetdef_thies.py")
00174 include("data/datasetdef_joerg.py")
00175 
00176 #print data_lib
00177 
00178 #get the dataset
00179 if dataset == "default":
00180    datasetname = 'defaultfile' #will be used for the filename
00181    print '\nError: You have to pass a dataset through the command line'
00182    print '       or define a default dataset here.\n'
00183    sys.exit()
00184   
00185 elif dataset.endswith(".py"):
00186    include(jo_path + dataset)
00187    tuple = dataset.rsplit("/",1)
00188    datasetname = tuple[len(tuple)-1].replace(".py","")
00189 
00190 elif dataset.endswith(".root"):
00191    ServiceMgr.EventSelector.InputCollections = [ dataset ]
00192    tuple = dataset.rsplit("/",1)
00193    datasetname = tuple[len(tuple)-1].replace(".root","")
00194 
00195 else:
00196    ds = data_lib.find_dataset(dataset)
00197    print ds
00198    if jo_path == '':
00199       datatools.include_files(ds.get_path(),ServiceMgr.EventSelector)
00200    else:
00201       include(jo_path + ds.get_long() + '.py')
00202    datasetname = dataset
00203 
00204 
00205 if len(outputdir)>0 and not outputdir.endswith("/"):
00206    outputdir += "/"
00207 
00208 
00209 #put together filename
00210 filename = outputdir + datasetname + "_" + jetcontainername + ".aan.root"
00211 
00212 if filenumber > 0:
00213    filename = filename.replace(jetcontainername,
00214                                jetcontainername+"_"+str(filenumber))
00215 
00216 if (AtlFastFlag == True) and\
00217        (datasetname.lower().find('atlfast') == -1):
00218 
00219    filename = filename.replace("_"+jetcontainername,
00220                                "_atlfast_"+jetcontainername)
00221 
00222 if doAODFix1mm == True:
00223    filename = filename.replace(jetcontainername,
00224                                jetcontainername+"_1mmFix")
00225 
00226 if doTrackJets == True:
00227    filename = filename.replace(jetcontainername,
00228                                jetcontainername+"_TrackJets")
00229 
00230 #print configuration
00231 print '\n************************************************************\n'
00232 print " Using the following configuration: "
00233 print "   dataset:           ", dataset
00234 print "   datasetname:       ", datasetname
00235 print "   outputdir:         ", outputdir
00236 print "   AtlFastFlag:       ", AtlFastFlag
00237 print "   doAODFix1mm:       ", doAODFix1mm
00238 print "   doEventWeight:     ", doEventWeight
00239 print "   doTrackJets:       ", doTrackJets
00240 print "   filenumber:        ", filenumber
00241 print "   nevents:           ", nevents
00242 print "   filename:          ", filename
00243 print "   jetcontainer:      ", jetcontainername  
00244 print "   truthjetcontainer: ", truthjetcontainername
00245 print '\n************************************************************\n'
00246 
00247 #do 1mm correction
00248 #include( "ElectronPhotonAlgs/ElectronPhotonCorrector_jobOptions.py")
00249 #include( "JetMissingEtAlgs/ParticleJet1mmCorrection_jobOptions.py")
00250 #include( "JetMissingEtAlgs/MissingET1mmCorrection_jobOptions.py")
00251 
00252 
00253 theApp.Dlls   += [ "AnalysisTools" ]
00254 #theApp.Dlls   += [ "NtupleWriter14" ]
00255 CBNTAthenaAware = True
00256 include ("CBNT_Athena/CBNT_AthenaAware_jobOptions.py")
00257 include ("CBNT_Athena/CBNT_EventInfo_jobOptions.py")
00258 #CBNT_AthenaAware = Algorithm( "CBNT_AthenaAware" )
00259 #CBNT_AthenaAware.Members += [ "AANtupleWriter14" ]
00260 from NtupleWriter14.NtupleWriter14Conf import AANtupleWriter14
00261 CBNT_AthenaAware += AANtupleWriter14() 
00262 
00263 
00264 ############# The properties of the AANtupleWriter14 Algorithm
00265 
00266 #AANtupleWriter14 = Algorithm( "AANtupleWriter14" )
00267 
00268 CBNT_AthenaAware.AANtupleWriter14.doTrigger        = True
00269 CBNT_AthenaAware.AANtupleWriter14.doMissingEt      = True
00270 CBNT_AthenaAware.AANtupleWriter14.doElectrons      = True
00271 CBNT_AthenaAware.AANtupleWriter14.doPhotons        = True
00272 CBNT_AthenaAware.AANtupleWriter14.doMuons          = True
00273 CBNT_AthenaAware.AANtupleWriter14.doJets           = True
00274 CBNT_AthenaAware.AANtupleWriter14.doTauJets        = True
00275 CBNT_AthenaAware.AANtupleWriter14.doTruthJets      = True
00276 CBNT_AthenaAware.AANtupleWriter14.doTruthParticles = True
00277 CBNT_AthenaAware.AANtupleWriter14.doEventWeight    = doEventWeight
00278 
00279 CBNT_AthenaAware.AANtupleWriter14.doTrackJets      = doTrackJets
00280 CBNT_AthenaAware.AANtupleWriter14.doVertices       = doTrackJets
00281 
00282 CBNT_AthenaAware.AANtupleWriter14.truthparticleMaximumLeptonBarcode = 100000
00283 CBNT_AthenaAware.AANtupleWriter14.truthparticleNoPDGAbove100        = False
00284 
00285 CBNT_AthenaAware.AANtupleWriter14.AtlFastFlag = AtlFastFlag
00286 CBNT_AthenaAware.AANtupleWriter14.doAODFix1mm = doAODFix1mm
00287 
00288 
00289 CBNT_AthenaAware.AANtupleWriter14.AOD_files = ServiceMgr.EventSelector.InputCollections
00290 
00291 
00292 if AtlFastFlag == True:
00293     
00294    CBNT_AthenaAware.AANtupleWriter14.triggerDecisionContainer     = "notAvailable"
00295    CBNT_AthenaAware.AANtupleWriter14.photonContainer              = "AtlfastPhotonCollection"
00296    CBNT_AthenaAware.AANtupleWriter14.electronContainer            = "AtlfastElectronCollection"
00297    CBNT_AthenaAware.AANtupleWriter14.muonContainer                = ["AtlfastMuonCollection"]
00298    CBNT_AthenaAware.AANtupleWriter14.jetContainer                 = "AtlfastParticleJetContainer"
00299    CBNT_AthenaAware.AANtupleWriter14.taujetContainer              = "AtlfastTauJetContainer"
00300    CBNT_AthenaAware.AANtupleWriter14.missingEtContainerCollection = ["AtlfastMissingEt"]
00301    CBNT_AthenaAware.AANtupleWriter14.truthparticleContainer       = "SpclMC"
00302    CBNT_AthenaAware.AANtupleWriter14.truthjetContainer            = "notAvailable"
00303    CBNT_AthenaAware.AANtupleWriter14.truthmissingEtContainer      = "notAvailable"
00304    CBNT_AthenaAware.AANtupleWriter14.TrackParticleContainer       = "AtlfastTrackParticles"
00305 
00306    
00307 else:
00308 
00309    CBNT_AthenaAware.AANtupleWriter14.triggerDecisionContainer     = "TrigDecision"
00310    CBNT_AthenaAware.AANtupleWriter14.triggerMuonLVL1Container     = "LVL1_ROI"
00311    CBNT_AthenaAware.AANtupleWriter14.triggerMuonLVL2Container     = "CombinedMuonFeature"
00312    CBNT_AthenaAware.AANtupleWriter14.triggerMuonEFContainer       = "TrigMuonEFContainer"
00313    CBNT_AthenaAware.AANtupleWriter14.triggerMissingEtContainer    = "TrigEFMissingET"
00314    CBNT_AthenaAware.AANtupleWriter14.photonContainer              = "PhotonAODCollection"
00315    CBNT_AthenaAware.AANtupleWriter14.electronContainer            = "ElectronAODCollection"
00316    CBNT_AthenaAware.AANtupleWriter14.muonContainer                = ["MuidMuonCollection",
00317                                                                      "StacoMuonCollection"]
00318    CBNT_AthenaAware.AANtupleWriter14.jetContainer                 = jetcontainername
00319    #CBNT_AthenaAware.AANtupleWriter14.jetContainer                 = "Cone4H1TopoParticleJets"
00320    CBNT_AthenaAware.AANtupleWriter14.taujetContainer              = "TauRecContainer"
00321    CBNT_AthenaAware.AANtupleWriter14.truthjetContainer            = truthjetcontainername
00322    #CBNT_AthenaAware.AANtupleWriter14.truthjetContainer           = "Cone4TruthParticleJets"
00323    CBNT_AthenaAware.AANtupleWriter14.missingEtContainerCollection = ["MET_Base",
00324                                                                               "MET_Calib",
00325                                                                               "MET_CorrTopo",
00326                                                                               "MET_LocHadTopo",
00327                                                                               "MET_Topo",
00328                                                                               "MET_TopoObj",
00329                                                                               "MET_MuonBoy",
00330                                                                               "MET_Cryo",
00331                                                                               "MET_CryoCone",
00332                                                                               "MET_RefFinal",
00333                                                                               "MET_RefEle",
00334                                                                               "MET_RefJet",
00335                                                                               "MET_CellOut",
00336                                                                               "MET_CorrTopo",
00337                                                                               "MET_LocHadTopo",
00338                                                                               #"LocHadTopoObj",
00339                                                                               #"TopoObj",
00340                                                                               "MET_Topo",
00341                                                                               "ObjMET_Elec",
00342                                                                               "ObjMET_Muon",
00343                                                                               "ObjMET_Jet",
00344                                                                               "ObjMET_MiniJet",
00345                                                                               "ObjMET_IdTrk",
00346                                                                               "ObjMET_Rest", 
00347                                                                               "ObjMET_Final"]
00348    CBNT_AthenaAware.AANtupleWriter14.truthmissingEtContainer      = "MET_Truth"
00349    CBNT_AthenaAware.AANtupleWriter14.truthparticleContainer       = "SpclMC"
00350    CBNT_AthenaAware.AANtupleWriter14.jetTrackContainer            = "Cone4TrackJets"
00351    CBNT_AthenaAware.AANtupleWriter14.jetTruthTrackContainer       = "Cone4TruthTrackJets"
00352    CBNT_AthenaAware.AANtupleWriter14.TrackParticleContainer       = "TrackParticleCandidate"
00353 
00354 # set the file info
00355 CBNT_AthenaAware.AANtupleWriter14.release    = "14.2.0"
00356 CBNT_AthenaAware.AANtupleWriter14.svnversion = os.popen("svnversion -n .").read()
00357 CBNT_AthenaAware.AANtupleWriter14.date       = datetime.datetime.now().strftime("%Y-%m-%d/%H:%M:%S")
00358 
00359 ##########################################
00360 # setup TTree registration Service
00361 # save ROOT histograms and Tuple
00362 from GaudiSvc.GaudiSvcConf import THistSvc
00363 ServiceMgr += THistSvc()
00364 ServiceMgr.THistSvc.Output = [ "AANT DATAFILE='"+filename+"' OPT='RECREATE'" ]
00365 from AnalysisTools.AnalysisToolsConf import AANTupleStream
00366 topSequence += AANTupleStream()
00367 AANTupleStream = AANTupleStream()
00368 AANTupleStream.ExtraRefNames = [ "StreamATLFAST","Stream1" ]
00369 AANTupleStream.OutputName = filename
00370 AANTupleStream.WriteInputDataHeader = True
00371 AANTupleStream.OutputLevel = WARNING
00372 
00373 # Set output level threshold (2=DEBUG, 3=INFO, 4=WARNING, 5=ERROR, 6=FATAL )
00374 MessageSvc = Service( "MessageSvc" )
00375 MessageSvc.OutputLevel = 3
00376 #MessageSvc.OutputLevel = WARNING
00377 #MessageSvc.OutputLevel = INFO
00378 
00379 # Number of Events to process
00380 theApp.EvtMax = nevents
00381 
00382 # skip events
00383 if(filenumber > 0):
00384    ServiceMgr.EventSelector.SkipEvents = (filenumber-1) * theApp.EvtMax
00385    print 'Skip:', ServiceMgr.EventSelector.SkipEvents, 'Events'
00386 
00387 
00388 ###############################################################
00389 #
00390 #  1) Default:  athena AANtupleWriter14.py
00391 #      - default values will be used (defined at the beginning of this file)
00392 #      - you have to put 'include("<your_dataset_jo>.py")' in the 'if dataset == "default"' block 
00393 #
00394 #  2) dataset: athena -c 'dataset="description"' AANtupleWriter14.py
00395 #      a) dataset="path/filename.py": joboptions will be directly included
00396 #      b) dataset="jo:filename.py":   joboptions will be icluded from path: /.at/mdtraid04/12.0.X_data/data_jo_files/
00397 #      c) dataset="filename.root"     the root file will directly be included
00398 #      d) dataset="long/short descr":
00399 #                   - e.g.:  dataset="5200_1206"
00400 #                   - the datset will be searched in the data_lib library
00401 #                   - both the short or long description can be specified, as defined in
00402 #                     data/datasetdef.py
00403 #                   - all files which contain '.root' in the name in the path defined
00404 #                     in the dataset definition will be included
00405 #      e) dataset="jo:5200_1206"                             
00406 #                   - same as d) but instead of looping over all rootfiles the
00407 #                     joboptions from the path: /.at/mdtraid04/12.0.X_data/data_jo_files/ is included
00408 #                   - the name of the joboption is build as: <long descripion of dataset>.py
00409 #    
00410 #  3) outpudir: athena -c 'outputdir="mydata/"' AANtupleWriter14.py
00411 #      - the path where the file will be written
00412 # 
00413 #  4) AtlFastFlag: athena -c 'AtlFastFlag=1' AANtupleWriter114py
00414 #      - specifies if writer will be run on AtlFast containers
00415 #      - default value is False
00416 #      - if dataset is defined in command line an contains a string "atlfast"
00417 #        -> flag will be set to True
00418 #      - this will be overwritten if AtlFastFlag is set in the command line
00419 #      - if true: ouptfilename will contain a string: '_atlfast' 
00420 #
00421 #  5) doEventWeight: athena -c 'doEventWeight=0' AANtupleWriter14.py 
00422 #      - write EventWeight or not
00423 #      - default value is True
00424 #      - if dataset is defined in command line an contains a string "sherpa"
00425 #        ->  flag will be set to False
00426 #      - this will be overwritten if doEventWeight is set in the command line
00427 #
00428 #  6) doAODFix1mm: athena -c 'doAODFix1mm=1' AANtupleWriter14.py
00429 #      - default: false
00430 #      - if true 1mm bug corrections will be applied     
00431 #      - will be included in the outputfilename
00432 # 
00433 #
00434 #  7) filenumber: athena -c 'filenumber=3' AANtupleWriter14.py
00435 #      - default value is 0
00436 #      - if > 0: - (filenumber-1)*nevent will be skipped the nevents ar processed
00437 #                - filenumber will be included in the outputfilename
00438 #
00439 #  8) jetcontainer: athena -c 'jetcontainer="Cone4H1Tower"' AANtupleWriter14.py
00440 #     - default: "Cone4H1Topo"
00441 #     - use this jetcontainer in analysis
00442 #     - the appropriate truthjet container will be used
00443 #     - will be included in the outputfilename  
00444 #
00445 #  9) nevents: athena -c 'nevents="100"' AANtupleWriter14.py
00446 #     - the number of events which will be processed
00447 #
00448 # 10) Compose:
00449 #     athena  -c 'dataset="5189_14_2_0"; nevents=100' AANtupleWriter14.py
00450 #
00451 #
00452 #################################################################

Generated on Tue Oct 21 11:50:46 2008 for NtupleAnalysis by  doxygen 1.5.1