Babar/CM2 A-to-Z at Manchester

James Werner

Basic Program structure.


Analysis programs are written in C++ classes. The class contains the following structure:

1. Header files: includes the definition from external classes (lines 5 to 47). 2. Constructors: defines the context of the class (lines 55 to 79). 3. Destructors: release the class context (lines 81 to 85). 4. Job initialisation: method beginJob initialises all application variables, and is called only once at the beginning (lines 90 to 100). 5. Event Processing: for each event read from dataset, call the method event that performs all processing for each event (lines 102 to 130). 6. Job finish: method endJob is called once when the job ends (lines 132 to 138).


      1   // ------------------------------------------------------------------------
      2   //                          basica.cc
      3   // Description:
      4   //    Class basica - contains only basic structure
      5   //------------------------------------------------------------------------
      6   #include "BaBar/BaBar.hh"
      7
      8   //-----------------------
      9   // This Class's Header --
     10   //-----------------------
     11   #include "BetaMiniUser/basica.hh"
     12
     13   //-------------
     14   // C Headers --
     15   //-------------
     16   #include <assert.h>
     17
     18   //---------------
     19   // C++ Headers --
     20   //---------------
     21   #include <iostream.h>
     22   #include <math.h>
     23
     24   //-------------------------------
     25   // Collaborating Class Headers --
     26   //-------------------------------
     27   #include "CLHEP/Alist/ConstAList.h" // produces a list
     28   #include "CLHEP/Alist/ConstAIterator.h" // tool to iterate throeugh a list
     29   #include "HepTuple/TupleManager.h"
     30   #include "HepTuple/Histogram.h"
     31   #include "HepTuple/Tuple.h"
     32   #include "AbsEvent/AbsEvent.hh"  //
     33   #include "AbsEvent/getTmpAList.hh" // for making lists
     34   #include "AbsEnv/AbsEnv.hh"
     35   #include "GenEnv/GenEnv.hh"
     36   #include "PDT/Pdt.hh"     // needed for particle data table
     37   #include "PDT/PdtPid.hh"  // the same
     38   #include "TrkBase/TrkRecoTrk.hh" // give you access to the track itself
     39                                    // There you will find DC information
     40   #include "TrkBase/TrkFit.hh"
     41   #include "PDT/PdtEntry.hh" //
     42   #include "BetaMicroAdapter/BtaCalQual.hh"  // EMC information
     43   #include "AbsParm/AbsParmIfdStrKey.hh"
     44   #include "Beta/EventInfo.hh"  // General event information
     45   #include "Beta/BtaCandidate.hh" // Candidates are what everything is about
     46   #include "BetaCoreTools/BtaMcAssoc.hh"
     47   #include "ErrLogger/ErrLog.hh"
     48
     49   //-----------------------------------------------------------------------
     50   // Local Macros, Typedefs, Structures, Unions and Forward Declarations --
     51   //-----------------------------------------------------------------------
     52
     53   static const char rcsid[] = "$Id: basica.cc,v 1 2004/12/07 James Werner Exp $";
     54
     55   //----------------
     56   // Constructors --
     57   //----------------
     58   basica::basica(
     59       const char* const theName,
     60       const char* const theDescription )
     61       : AppModule( theName, theDescription )
     62     , _eventInfoList("eventInfoList",this,"Default")       //we produce different
     63     , _btaPionList("pionCandidates",this,"piDefault")      //lists of candidates
     64     , _btaCalorList("calorCandidates",this,"CalorNeutral") // We fill them with
     65     , _btaTrackList("trackCandidates",this,"ChargedTracks")//default
     66     , _btaGamList( "btaGamList", this, "CalorNeutral")      // gamma
     67     , _btaTruthList("truthCandidates",this,"MCTruth")      //identification.
     68              // This is handeled in myAnalysis.tcl
     69              // You have to add the needed modules in AppUserBuild.cc too!
     70              // (I have deleted muons from the candidate lists. You may try
     71              // to make a muon list and loop over it)
     72   {
     73     commands()->append(& _eventInfoList);
     74     commands()->append(& _btaPionList);
     75     commands()->append(& _btaCalorList);
     76     commands()->append(& _btaTrackList);
     77     commands()->append(& _btaGamList);
     78     commands()->append(& _btaTruthList);
     79   }
     80
     81   //--------------
     82   // Destructor --
     83   //--------------
     84   basica::~basica( ) {}
     85
     86   //--------------
     87   // Operations --
     88   //--------------
     89
     90   // The begin(AppJob*) member function is run before any events are
     91   // processed.  In this analysis, it opens the output histogram file
     92   // and then books a number of histograms
     93
     94   AppResult
     95   basica::beginJob( AbsEvent* anEvent )
     96   {
     97       // User initialisation
     98
     99       return AppResult::OK;
    100   }
    101
    102   AppResult
    103   basica::event( AbsEvent* anEvent ) {
    104
    105     // photon list
    106
    107     HepAList<BtaCandidate>* gamList =
    108         Ifd<HepAList<BtaCandidate> >::get(anEvent, _btaGamList.value() );
    109
    110     HepAListIterator<BtaCandidate> gamIter(*gamList);
    111     BtaCandidate* theGamma;
    112     while (theGamma = gamIter() ) {
    113
    114     // user routine to deal with each photon in the event
    115
    116     } // end: while ( 0 != ( theGamma = gamIter() ) )
    117
    118     // Loop over track candidates
    119
    120     HepConstAListIterator<BtaCandidate> itertrack(*trackList);
    121     const BtaCandidate* track_ptr;
    122
    123     while ( 0 != ( track_ptr = itertrack() ) ) {
    124
    125     //user routine to deal with each charged particle
    126
    127     } // end: while ( 0 != ( track_ptr = itertrack() ) )
    128
    129     return AppResult::OK;
    130   }
    131
    132   AppResult
    133   basicaa::endJob( AbsEvent* anEvent )
    134   {
    135       // user finalisation routine
    136
    137        return AppResult::OK;
    138   }
  

[Download Source code.]


      1   //--------------------------------------------------------------------------
      2   //                          basica.hh
      3   //
      4   // Description:
      5   //    Class basica - contains only basic structure
      6   //                     
      7   //------------------------------------------------------------------------
      8
      9   #ifndef BASICA_HH
     10   #define BASICA_HH
     11
     12   //----------------------
     13   // Base Class Headers --
     14   //----------------------
     15   #include "Framework/APPModule.hh"
     16   #include "Framework/AbsParmBool.hh"
     17   #include "AbsParm/AbsParmIfdStrKey.hh"
     18
     19   //------------------------------------
     20   // Collaborating Class Declarations --
     21   //------------------------------------
     22   class HepTupleManager;
     23   class HepHistogram;
     24   class HepTuple;
     25
     26   //            ---------------------
     27   //            -- Class Interface --
     28   //            ---------------------
     29
     30   class basica : public AppModule {
     31
     32   //--------------------
     33   // Instance Members --
     34   //--------------------
     35
     36   public:
     37
     38       // Constructors
     39       basica( const char* const theName, const char* const theDescription );
     40
     41       // Destructor
     42       virtual ~basica( );
     43
     44       // Operations
     45
     46       virtual AppResult beginJob( AbsEvent* anEvent);
     47       virtual AppResult event( AbsEvent* anEvent );
     48       virtual AppResult endJob  ( AbsEvent* anEvent );
     49
     50       // User methods
     51
     52   protected:
     53
     54       AbsParmIfdStrKey _eventInfoList;
     55       AbsParmIfdStrKey _btaCalorList;
     56       AbsParmIfdStrKey _btaTrackList;
     57       AbsParmIfdStrKey _btaGamList;
     58       AbsParmIfdStrKey _btaTruthList;
     59       AbsParmIfdStrKey _btaPionList;
     60
     61   private:
     62
     63       // User definitions
     64
     65   };
     66
     67   #endif

[Download Source Code.]


      1   #------------------------------------------------------------------------------
      2   #  basica.tcl
      3   #------------------------------------------------------------------------------
      4   # always source the error logger early in your main tcl script
      5   sourceFoundFile ErrLogger/ErrLog.tcl
      6   sourceFoundFile FrameScripts/FwkCfgVar.tcl
      7   sourceFoundFile FrameScripts/talkto.tcl
      8   # Disable the use of envvars
      9   set ProdTclOnly true
     10
     11   # set the error logging level to 'warning'.  If you encounter a configuration
     12   # error you can get more information using 'trace'
     13   ErrLoggingLevel warning
     14
     15   #
     16   #  Turn off some specialty items
     17   #
     18   module disable NTrk
     19   module disable MomEnH
     20   module disable PEntp
     21   module disable colPEntp
     22   module disable EnPBip
     23   module disable LisEvt
     24   module disable verMCTruth
     25   module disable recoevt
     26   module disable recodata
     27   ## allowed values of BetaMiniReadPersistence are (currently) "Kan", "Bdb"
     28   ##
     29   set BetaMiniReadPersistence Kan
     30
     31   ## allowed (non-expert) values of levelOfDetail are "micro", "cache", "extend"
     32   ## or "refit"
     33   ##
     34   FwkCfgVar levelOfDetail "cache"
     35
     36   ## allowed values of ConfigPatch are "Run1", "Run2" or "MC".  This MUST be set
     37   ## consistent ## with your input data type or you will get INCONSISTENT OR
     38   ## INCORRECT RESULTS
     39   ##
     40   FwkCfgVar ConfigPatch "Run2"
     41
     42   ##
     43   ##  You can enter input collections two ways: either append them to a list, or
     44   ##  explicitly enter them in the input module. Do one or the other, BUT NOT
     45   ##  BOTH.
     46   ##  If inputList is set before executing btaMini.tcl, that will automatically
     47   ##  add the collections to the appropriate input module, otherwise make sure you
     48   ##  talk to the right one.
     49   ##
     50   ## lappend inputList collection1 collection2 ...
     51   ##
     52   ##  OR THE FOLLOWING (choose the correct one based on persistence)
     53   ##
     54   ## talkto BdbEventInput {
     55   ## talkto KanEventInput {
     56   ##    input add collection1
     57   ##    input add collection2
     58   ##    ...
     59   ## }
     60
     61
     62   ##
     63   ## Set the number of events to run. If this isn't set, all events in the
     64   ## input collections will be processed.
     65   ##
     66   FwkCfgVar NEvent
     67
     68   ## choose the flavor of ntuple to write (hbook or root) and the file name
     69   ##
     70   FwkCfgVar BetaMiniTuple "root"
     71   FwkCfgVar histFileName "enphist.roo"
     72
     73   ## create Everything path and add core sequences to it. btaMiniPhysics is the
     74   ## same as btaMini, just appending a few standard list generating modules. For
     75   ## reading data with stored composites, you may have a conflict running
     76   ## btaMiniPhyscs.tcl
     77   ##
     78   ## You can also run (most of) the PhysProdSequence, complete with its 3 gamma
     79   ## conversion finders, etc. Consider disabling the portion of this sequence
     80   ## that you do not need to save yourself some time.  The BetaLumiSequence
     81   ## and TagProd sequences are left off, as they otherwise cause problems.
     82   ##
     83   sourceFoundFile BetaMiniUser/btaMini.tcl
     84   #sourceFoundFile BetaMiniUser/btaMiniPhysics.tcl
     85   #sourceFoundFile BetaMiniUser/btaMiniPhysProdSequence.tcl
     86   ## Add Analysis module
     87   ##
     88   path append Everything basica
     89
     90   ##
     91   ##  If your job has a tag-level filter, here is how you should run it
     92   ##  so as to avoid wasting time reading the mini when the tag filter fails
     93   ##  Here's a simple example that restricts to just multi-hadron events
     94   ##  on Kan input
     95
     96   module clone TagFilterByName TagBGFMultiHadron
     97   module talk TagBGFMultiHadron
     98     andList set BGFMultiHadron
     99     assertIfMissing set true
    100   exit
    101
    102   module talk EvtCounter
    103     printFreq set 100000
    104   exit
    105
    106   #sequence append BetaMiniReadSequence -a KanEventUpdateTag TagBGFMultiHadron
    107
    108   path list
    109   if [info exists NEvent] {
    110     ev begin -nev $NEvent
    111   } else {
    112     ev begin
    113   }
    114
    115   ErrMsg trace "completed OK"
    116   exit

[Download Source Code.]

Top

Last modified:
Copyright 2004 Manchester University
Feedback to: jamwer@hep.man.ac.uk