HiggsAnalysis/HiggsAnalysis-00-01-00/run/HiggsAnalysisNtupleWriter.py

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

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