|
|
|
||||||||||||||||||||||||||
This section assumes you are familiar with setting up a test release and working with a Beta job in the BaBar computing environment. Throughout this section, command line entries are written in red, and code that needs be added is written in green. If you're already familiar with skims and just want to add new features like persistent candidates, you might want to skip ahead to this section.
Beta-22.x.x> srtpath <enter> <enter> Beta-22.x.x> XXXXbootwhere XXXXboot is the appropriate conditions database. For example, cond16boot is appropriate for release 16, cond18boot is appropriate for release 18 and cond22boot is appropriate for release 22. Then
Beta-22.x.x> addpkg FilterTools Beta-22.x.x> addpkg SkimMinithe FilterTools package already contains a number of skims from various analyses. Generic documentation on the skim selection variables, skim rates, releases uses in central skimming is available here.
declareMiniSkim ExampleAWG/MyExample deepCopyMicro deepCopyMicro {candLists} {tagBits}
The first argument is the skim name, including (before the "/") the AWG the skim belongs to.
The 2nd (for data) and 3rd (for Monte Carlo) arguments define if the skim is to be a pointer
or deep copy skim. Small skims (tipically, those with rates below 7%)
tend to be deep copy, as are skims that are to be exported to non-Tier-A sites.
The last two arguments are optional. If they are not specified, a file called
FilterTools/MyExamplePath.tclmust exist to actually define how the skim should select events.
module clone TagFromList TagJpsiKs
talkto TagJpsiKs {
listsToTag set B0JpsiKs
tagName set JpsiKs
}
Here, we define the tag bit "JpsiKs" to be set for any event with one or more entry in the "B0JpsiKs" BtaCandidate list.
Using these tag bits, it's very simple to define a skim. The following goes into
the FilterTools/MyExamplePath.tcl file:
global writeUsrDataForSkim
path create MyExamplePath
# only run on MultiHadrons
path append MyExamplePath FilterBGFMultiHadron
module clone TagFromList TagJpsiKs
talkto TagJpsiKs {
listsToTag set B0JpsiKs
tagName set JpsiKs
}
module clone TagFilterByName MyExampleFilter
path append MyExamplePath MyExampleFilter
talkto MyExampleFilter {
orList set JpsiKs
}
# (don't) Write UsrData
set writeUsrDataForSkim 0
There are a few predefined modules that we have used here. In particular, the
BGFMultiHadron filtering module is used to select only multihadron events.
Also, "TagFilterByName" is a generic filter module that is defined to filter on one
or more tag bits. We make a clone of this module and ask it to filter on the "JpsiKs"
tag bit (not BtaCandidate list). This is the module that actually defines the
skim in this example. Any event passing this filter will be included into the skim.
The last few lines specify that this example does not define any user data. How
to include user data is decscribed below.
declareMiniSkim ExampleAWG/MyExample deepCopyMicro deepCopyMicro {candLists} {tagBits}
pass = "at least one candidate in any of these lists".Moreover, the lists candList1 and candList2 are automatically persisted (see below).
pass = "at least one of these bits set".
pass = "at least one of these bits set" AND "at least one candidate in any of these lists".
declareMiniSkim ExampleAWG/MyExample deepCopyMicro deepCopyMicro {B0JpsiKs} {BGFMultiHadron}
Which is admittedly shorter and less error prone. For people using
very old releases: note that these features require at least
the following tags:
FilterTools V00-16-02 SkimMini V00-03-06
Beta-22.x.x> cd FilterToolsNext you should download the three MyExampleSkim* example files from here into the FilterTools package you just checked out.
MyExampleSkim::MyExampleSkim( const char* const theName, const char* const theDescription ) : TagFilterModule( theName, theDescription )Note the last line uses TagFilterModule instead of the usual:
: AppModule( theName, theDescription )Second, MyExampleSkim::event calls setPassed. The argument to this function will determine whether this event passes the skim or not.
setPassed( false ); // Do not pass this event setPassed( true ); // Do pass this eventMyExampleSkim could run as is, but all it does is fail every event, which probably makes for a short and depressing analysis. So we should add some physics code to select interesting events. A more complete version of MyExampleSkim is available by downloading the three MyExampleSkim* files from here into FilterTools.
This example looks for events with a B0 -> D mu nu candidate. Events are
chosen which have a D+- and a muon of the opposite charge. In addition,
the muon must have momentum > 1.0 GeV. At the end of the event
setPassed( true ) is called if all of
these conditions are met, or setPassed( false ) if they are not.
Now that all the code is in place, the skim module can be added to the sequence by adding the following lines to the SkimTagSequence.cc file:
#include "FilterTools/MyExampleSkim.hh"
forWho->add(new MyExampleSkim("MyExampleSkim", "example filter module"));
Finally you need to define this skim. Not surprisingly, this is done in FilterTools/defineMiniSkims.tcl. Add the following line to the bottom of this file:
declareMiniSkim ExampleAWG/MyExample deepCopyMicro deepCopyMicroFor this example, the skim is declared as a "deepCopyMicro" skim. Generally, skims that select more than 5% of events should be declared as pointer skims instead of deepCopy.
If you want to document several skims in one file you can set a reference to another skim. For example, if MyExampleSkim is documented in the readme file of MyFirstExampleSkim, your MyExampleSkim.readme should look like this:
See <skim>MyFirstExampleSkim</skim> documentation.The <skim> token tells the documentation generator where to look for the documentation. This token must appear in the first line of the file (empty lines and the CVS identifier $Id do not count). If you have your skim documentation on a web page that is not part of FilterTools/doc you can use the following syntax to set a link:
See <url>http://www.google.com</url>However, the recommended way is to put the HTML page in the FilterTools package as described earlier. It is the responsibility of the skim author to make sure that the skim has its proper documentation file even if it only contains a link to a web page or BAD note where further information can be found.
If you want to create the global skim documentation for yourself (you do not have to do this) do:
Beta-22.x.x> gmake FilterTools.binscripts Beta-22.x.x> cd workdir Beta-22.x.x> SkimMakeDocThe script will write the documentation to the current directory. Use SkimMakeDoc -h to get help on other options.
global BtaCandLists lappend BtaCandLists DcLoose
Beta-22.x.x> cd FilterToolsNext download the three MyExampleSkim* files (.tcl, .hh, .cc) files from here into FilterTools. (These are slightly different from the ones you may have downloaded above.)
global BtaCandLists lappend BtaCandLists MyExampleCandListSecond, the composite candidates are made in MyExampleSkim.cc by adding the 4-vectors of the D and the muon. All that's needed to persist them is to append them to a list with the key "MyExampleCandList". The code needed to do this has been added to the constructor and event method of MyExampleSkim.cc:
MyExampleSkim::MyExampleSkim( const char* const theName,
const char* const theDescription )
: TagFilterModule( theName, theDescription )
, _outputCandList("outputCandlist",this,"MyExampleCandList")
...
MyExampleSkim::event( AbsEvent* anEvent )
{
// Make composite candidates by adding 4-vectors
static BtaOpAdd4 candCombiner;
...
// Get list of composite candidates that will be persisted
getTmpAList( anEvent, _compositeList, _outputCandList.value() );
...
// Create a composite D mu candidate
BtaCandidate *compositeCand=
candCombiner.create(*muon,*Dc);
...
// Add the candidate to the list to be persisted
_compositeList.append( compositeCand );
...
}
That's all it takes - now "MyExampleCandList" will be available as a list
when running a Beta job over the skimmed collections, just like any
other list of BtaCandidates.
# -------- myskim.tcl: begin ----------- set SkimsToRun MyExample set SkimOutputDir /work/users/<username>/outputDir set SkimsToWrite all set SkimMC yes set SkimFwkDump yes set SkimInputCollection /store/SP/R22/001237/200506/22.0.1/SP_001237_012005 set SkimNEvent 100 sourceFoundFile SkimMini/SkimMiniProduction.tcl # -------- myskim.tcl: end -----------This file has a number of options which are defined as follows:
> cd Beta-22.x.x Beta-22.x.x> gmake FilterTools.lib Beta-22.x.x> gmake SkimMini.SkimMiniAppand run SkimMiniApp from the workdir using the myskim.tcl file as the argument:
Beta-22.x.x> cd workdir workdir> SkimMiniApp myskim.tclThe output should look something like this example log file. When the skim is finished you can check that there is a collection called MyExample in the outputDir directory:
workdir> KanUserAdmin list /work/users/marchior/outputDir /work/users/marchior/outputDir/MyExampleThis collection contains all the events that passed the MyExample skim, and can now be used as input to a Beta job. You can first quickly check that the skim produced some output using the "KanCollUtil" utility as follows:
workdir> KanCollUtil /work/users/marchior/outputDir/MyExample /work/users/marchior/outputDir/MyExample (9 events)This means of the 100 events in the original collection, 9 passed the skim requirements and are stored in the MyExampleSkim collection. Note that since the selection rate of this skim is 9%, it should be a pointer skim under the 7% cutoff rule discussed above.
lappend inputList /work/users/<username>/outputDir/MyExampleKan
HepAList< BtaCandidate >* myList;
getTmpAList( anEvent, myList, IfdStrKey(HepString("MyExampleCandList")) );
You can then iterate over "myList" to access the composite candidates
BtaCandidate* theCompCand(0);
HepAListIterator<BtaCandidate> iterComposite( *myList );
while( 0 != (theCompCand = iterComposite()) )
{
//... Insert Nobel-prize winning analysis here...
}
You can now perform any operation that you normally would on a BtaCandidate,
including iterating over its daughters.
declareSkimSPmodes MySkim {1234 5678}
This will run MySkim on the modes 1234 and 5678. The collections should show up
in bookkeeping as SP-1234-MySkim-Rxx where xx is
the skim cycle.