How to Write and Read BtaAttributes using 12.3.0 or later
What are BtaAttributes?
How to write BtaAttributes in Kanga?
How to read BtaAttributes from Kanga files?
What are BtaAttributes?
When composite BtaCandidates are created in a module, Beta provides the possibility
to add a list of these composites to the event in order to be able to use them in
subsequent modules in the path. Additionally, information associated with these
composites, e.g. a chi squared of a vertexing fit or the output of a tagging algorithm,
can be passed to subsequent modules using BtaAttributes. This avoids carrying out
the same time-consuming algorithms several times in different modules.
The BtaAttributes object contains the following pairs:
- a pointer to each BtaCandidate in the composite list
- an associated tag object in which the additional information mentioned above is
stored in form of tag bits
The list of composites and their associated BtaAttributes can also be stored in Kanga files,
additionally to the tag and micro branches, i.e the transient BtaAttributes introduced
above can also be made persistent. The involved classes are shown in this UML diagram. When reading the events back from a Kanga file, this avoids
carrying out the same time-consuming algorithms that have already been done in the previous Beta
job (in which the Kanga file was written).
How to write BtaAttributes in Kanga?
The following applies to both data and MC running (setting BetaMCMicro to yes or no is enough, the rest happens automatically):
For reading MC:
setenv BetaMCMicro yes
Otherwise, for reading data:
setenv BetaMCMicro no
Then:
setenv BetaMCAll no
setenv BetaKanga yes
When reading kanga data:
setenv BetaBdbMicro no
Otherwise, when reading Objy data:
setenv BetaBdbMicro yes
Then:
setenv BetaPhysMicro yes
setenv BetaDisplayMicro no
setenv ROPT -Shared-noOptimize-noDebug
setenv ROOTSYS
newrel -s ~/scratch -t 12.3.0 testRel_12.3.0
cd testRel_12.3.0
srtpath
addpkg BetaUser
addpkg workdir
You also have to check out the following tag of BtaDataR:
addpkg BtaDataR tc020820
Somewhere in your path, the transient composite list and BtaAttributes need to be created:
-> Some module in the path (before the Kanga output module) has to add a composite list to the event:
HepAList< BtaCandidate >* compList = new HepAList< BtaCandidate >
IfdHepAListProxy< BtaCandidate > *proxy = new IfdHepAListProxy< BtaCandidate >(compList);
if ( ! Ifd< HepAList< BtaCandidate > >::put( anEvent,proxy,"myCompListName" ) ) {
ErrMsg(fatal) << "Cannot put list " << "myCompListName" << " in the event, aborting." << endmsg;
}
-> Somewhere after that (could be in the same module or not), the BtaAttributes have to be added to the event:
BtaAttributes* attrib = Ifd< BtaAttributes >::get( anEvent, "myBtaAttName" );
if ( attrib == 0 ) {
attrib = new BtaAttributes;
if ( ! Ifd< BtaAttributes >::put( anEvent, attrib, "myBtaAttName" ) )
ErrMsg( error ) << "Unable to add BtaAttributes object to event." << endmsg;
else {
if ( ErrLogging( trace ) )
ErrMsg( trace ) << "Added BtaAttributes to event." << endmsg;
}
}
-> You probably want to fill the BtaAttributes at the same time as you apply e.g. vertex fits or tagging algorithms to the composite candidates:
BtaCandidate* compCand;
HepAListIterator< BtaCandidate > iterCompList(*compList);
while ( 0 != ( compCand = iterMyComp()) )
{
...
//Determine e.g. chi squared of vertex fit
float chiSquared = ...
...
// Get a tag object
AbsEventTag* tag = attrib->find(compCand);
if (!tag) cout<< "No tag found"<< endl;
else{
tag->putFloat(chiSquared,"chi2");
}
}
The next step is writing the Kanga file including the BtaAttributes.
If the previous module (that created the transient BtaAttributes) was e.g.
in the MyAnalysis path, you probably want to edit your myAnalysis.tcl and add the following
(maybe in a separate tcl file to be sourced by myAnalysis.tcl):
sequence append MyAnalysis BtaTreeFlattener
set RooOutputFile myExampleIncludeBtaAttributes-micro.root
mod talk BtaTreeFlattener
treeList set myCompListName
flatList set myCompListNameFlat
show
exit
If you are reading Objy data, you have to add the following two lines:
sourceFoundFile RooSequences/RooSequence.tcl
path append Everything RooSequence
Then:
sourceFoundFile RooSequences/RooOutputSequence.tcl
sourceFoundFile RooSequences/RooWriteMicro.tcl
If you are reading Objy data, you have to add the following four lines:
module disable BdbEventOutput
module disable FileOutput
module disable RooEventUpdate
module disable RooBuildEnv
Then:
mod talk BtaRooLoad
writeAttributes set myBtaAttName
writeCmpList set myCompListNameFlat
show
exit
mod enable RooEventOutput
mod output RooEventOutput
mod talk RooEventOutput
output reset
output create microDST myExampleIncludeBtaAttributes-micro.root
output path microDST Everything
output enable microDST
useInPath set t
exit
Make sure that the arguments for the composite list and BtaAttributes coincide
with the names used for the creation of the transient objects in the precedent modules!
Then you build:
gmake workdir.setup
gmake installdirs
gmake lib
setboot
gmake BetaUser.bin
cd workdir
When reading kanga data, you do:
BetaApp kanga.tcl
Otherwise, when reading Objy data, you do:
BetaApp bdbMicro.tcl
You can browse the produced kanga-file myExampleIncludeBtaAttributes-micro.root.
You should now find two additional branches for the BtaAttributes and the composite list (besides the tag and BtaAod branches, and the BtaStdHep and MicroTruMap branch in the case of MC).
How to read BtaAttributes from Kanga files?
The following applies to both data and MC running (setting BetaMCMicro to yes or no is enough, the rest happens automatically):
For reading MC:
setenv BetaMCMicro yes
For reading data:
setenv BetaMCMicro no
Then:
setenv BetaMCAll no
setenv BetaKanga yes
setenv BetaBdbMicro no
setenv BetaPhysMicro yes
setenv BetaDisplayMicro no
setenv ROPT -Shared-noOptimize-noDebug
setenv ROOTSYS
newrel -s ~/scratch -t 12.3.0 testRel_12.3.0
cd testRel_12.3.0
srtpath
addpkg BetaUser
addpkg workdir
addpkg BtaDataR tc020820
The Kanga file containing the BtaAttributes is read in as usual, but in some tcl file (maybe in myAnalysis.tcl or a separate tcl file to be sourced), the following needs to be added:
mod talk BtaRooLoad
readAttributes set myBtaAttName
readCmpList set myCompListNameFlat
show
exit
sequence append MyAnalysis BtaTreeUnFlattener
mod talk BtaTreeUnFlattener
treeList set myCompListName
flatList set myCompListNameFlat
show
exit
Make sure that the arguments for the composite list and BtaAttributes coincide
with the names used when writing the Kanga files!
You can now access the composite list and BtaAttributes in your Beta job by doing the following:
HepAList< BtaCandidate >* compList = Ifd< HepAList< BtaCandidate > >::get(anEvent, "myCompListName");
BtaAttributes* attributes = Ifd< BtaAttributes >::get(anEvent, "myBtaAttName");
if(!attributes) cout << "No attributes found" << endl;
else{
BtaCandidate* compCand;
HepAListIterator<BtaCandidate> iterMyComp(*compList);
while ( 0 != ( compCand = iterMyComp()) )
{
const AbsEventTag *theTag = attributes->find( compCand );
float chiSqu(-999);
bool foundChi2 = theTag->getFloat(chiSqu,"chi2");
}
}
Then you build:
gmake workdir.setup
gmake installdirs
gmake lib
setboot
gmake BetaUser.bin
cd workdir
And you run
BetaApp kanga.tcl
This page is maintained by Tilmann Colberg.
Last significant update August 26 2002.
|