BLCMDntuple Class Reference

Inheritance diagram for BLCMDntuple:

BLCommand BLManager::EventAction BLManager::TrackingAction BLNTupleCallback

List of all members.


Detailed Description

class BLCMDntuple - implements an ntuple.

An ntuple holds the data from multiple virtualdetector-s in a single NTuple, with one row per event. If multiple tracks hit a given virtual detector in the ntuple, only the first one is kept.

Public Member Functions

 BLCMDntuple ()
 Default constructor.
virtual ~BLCMDntuple ()
 Destructor.
 BLCMDntuple (const BLCMDntuple &r)
 Copy constructor.
G4String commandName ()
 commandName() returns "ntuple".
int command (BLArgumentVector &argv, BLArgumentMap &namedArgs)
 command() implements the ntuple command.
void defineNamedArgs ()
 defineNamedArgs() defines the named arguments for the command.
void setupFirstEvent ()
 setupFirstEvent() will setup the NTuple (called at first event) Done here to be sure all other NTUples have been created (e.g. in callbacks).
void BeginOfEventAction (const G4Event *event)
 from BLManager::EventAction
void EndOfEventAction (const G4Event *event)
virtual void PreUserTrackingAction (const G4Track *track)
 from BLManager::TrackingAction
virtual void PostUserTrackingAction (const G4Track *track)
virtual void ntupleCallback (BLNTuple *caller, double data[], int ndata)
 from BLNTupleCallback

Static Public Member Functions

static bool matches (G4String s, G4String pattern)
 returns true if the string s matches one of the patterns in pattern.

Private Attributes

G4String name
G4String category
G4String detectors
G4String required
G4String veto
G4String format
G4String filename
G4int minHit
G4int perTrack
G4int unionFlag
G4String fields
BLNTuplentuple
double * data
int ndata
std::map< BLNTuple *, int > place
std::vector< int > start
std::set< BLNTuple * > vetoSet
Bitmask need
Bitmask got
int nHit
int vetoed


Constructor & Destructor Documentation

BLCMDntuple::BLCMDntuple (  ) 

Default constructor.

References BLCMDTYPE_DATA, category, data, BLCommand::description, detectors, fields, filename, format, BLNTuple::getFormatList(), got, minHit, name, ndata, need, nHit, ntuple, perTrack, BLCommand::registerCommand(), required, BLCommand::setDescription(), BLCommand::setSynopsis(), unionFlag, veto, and vetoed.

Referenced by command().

00105                          : BLCommand(), BLManager::EventAction(),
00106                                                 place(), start(), vetoSet()
00107 {
00108         registerCommand(BLCMDTYPE_DATA);
00109         setSynopsis("Define an NTuple containing multiple detectors.");
00110         setDescription("An ntuple holds the data from multiple "
00111                 "detectors in a single NTuple, with one row (entry) per "
00112                 "event or per track. This permits the generation of plots "
00113                 "that compare different detectors. "
00114                 "Up to 64 detectors can be used. "
00115                 "While 'detector' is used in this description, any existing "
00116                 "NTuple can be used, generated by any command, such as: "
00117                 "virtualdetector, zntuple, beamlossntuple, timentuple, and "
00118                 "newparticlentuple.\n\n"
00119                 "There are two ways the detectors can be combined: the default "
00120                 "method is to construct a new NTuple that combines the fields "
00121                 "of all the detectors, each prepended with the detector name. "
00122                 "If union=1 is given, then all detectors must have the same "
00123                 "list of fields, and that list is used for this NTuple; any "
00124                 "hit in any detector is simply copied to this NTuple -- this "
00125                 "permits multiple detectors to be combined into a single "
00126                 "NTuple (you may want noSingles=1 for the detectors). With "
00127                 "union=1, the 'required', 'veto' and 'minHit' arguments cannot "
00128                 "be used.\n\n"
00129                 "By default, an entry in this ntuple is made for each event "
00130                 "satisfying the require, veto, and minHit conditions; if "
00131                 "perTrack=1 then an entry is made for each track that "
00132                 "satisfies the require, veto, and minHit conditions. "
00133                 "Any hit in any detector matching the patterns in veto will "
00134                 "prevent the event/track from being entered into the ntuple."
00135                 "\n\n" 
00136                 "If multiple hits occur in a given detector during the "
00137                 "event or track, only the first one is kept in this ntuple. "
00138                 "Detectors are specified by patterns identical to "
00139                 "UNIX file-matching, so '*Det*' matches any detector "
00140                 "with 'Det' anywhere in its name, etc. The 'required' argument "
00141                 "permits events to be omitted unless all of the matching "
00142                 "detectors were hit at least once in the event or track. The "
00143                 "patterns in 'required' are applied only to detectors "
00144                 "in the ntuple, so a simple '*' only matches detectors named "
00145                 "in the 'detectors' argument.\n\n"
00146                 "If union is nonzero, the hits in each detector are entered "
00147                 "into this NTuple as they occur; each hit in any detector "
00148                 "is included as a row in this NTuple. All detectors "
00149                 "must have the same fields, which are used for this NTuple.\n\n"
00150                 "NOTE: the name of a detector is by default the "
00151                 "concatenation of its ancestors' names before its own (except "
00152                 "World), unless "
00153                 "rename=NAME was used in its place command. The patterns are "
00154                 "applied to the names of the virtualdetectors as they were "
00155                 "placed (including rename), not the bare name of the "
00156                 "virtualdetector command. If 'rename=det#' was used when "
00157                 "placing "
00158                 "the virtualdetector-s, you probably want a * to match the #, "
00159                 "or list them individually (det1,det2,det3...).\n\n"
00160                 "NOTE: This command does not work correctly in collective "
00161                 "tracking mode, unless union=1.\n\n"
00162                 "Valid Formats (ignore case): ");
00163         description += BLNTuple::getFormatList(); 
00164         // initial default values:
00165         name = "";
00166         category = "NTuple";
00167         detectors = "";
00168         required = "*";
00169         veto = "";
00170         format = "";
00171         filename = "";
00172         minHit = 0;
00173         perTrack = 0;
00174         unionFlag = 0;
00175         fields = "";
00176         ntuple = 0;
00177         data = 0;
00178         ndata = 0;
00179         need = 0;
00180         got = 0;
00181         nHit = 0;
00182         vetoed = 0;
00183 }

virtual BLCMDntuple::~BLCMDntuple (  )  [inline, virtual]

Destructor.

00069 { }

BLCMDntuple::BLCMDntuple ( const BLCMDntuple r  ) 

Copy constructor.

References category, data, detectors, fields, filename, format, got, minHit, name, ndata, need, nHit, ntuple, perTrack, required, unionFlag, veto, and vetoed.

00185                                              : BLCommand(r), 
00186                 BLManager::EventAction(), BLManager::TrackingAction(), 
00187                 BLNTupleCallback(), place(), start(), vetoSet()
00188 {
00189         name = "";
00190         category = r.category;
00191         detectors = r.detectors;
00192         required = r.required;
00193         veto = r.veto;
00194         format = r.format;
00195         filename = r.filename;
00196         minHit = r.minHit;
00197         perTrack = r.perTrack;
00198         unionFlag = r.unionFlag;
00199         fields = r.fields;
00200         ntuple = 0;
00201         data = 0;
00202         ndata = 0;
00203         need = r.need;
00204         got = 0;
00205         nHit = 0;
00206         vetoed = 0;
00207 }


Member Function Documentation

G4String BLCMDntuple::commandName (  )  [inline, virtual]

commandName() returns "ntuple".

Implements BLCommand.

00075 { return "ntuple"; }

int BLCMDntuple::command ( BLArgumentVector argv,
BLArgumentMap namedArgs 
) [virtual]

command() implements the ntuple command.

Implements BLCommand.

References BLCMDntuple(), BLManager::getObject(), BLCommand::handleNamedArgs(), minHit, name, perTrack, BLCommand::print(), BLCommand::printError(), BLManager::registerEventAction(), BLManager::registerTrackingAction(), required, unionFlag, and veto.

00211 {
00212         if(argv.size() != 1) {
00213                 printError("Invalid ntuple command -- need name");
00214                 return -1;
00215         }
00216 
00217         if(argv[0] == "default") {
00218                 handleNamedArgs(namedArgs);
00219                 return -1;
00220         }
00221 
00222         BLCMDntuple *t = new BLCMDntuple(defaultNtuple);
00223         int retval = t->handleNamedArgs(namedArgs);
00224 
00225         t->name = argv[0];
00226 
00227         if(t->unionFlag) {
00228                 if(t->required != "*" || t->veto.size() > 0 || t->minHit > 1)
00229                         printError("ntuple: In union mode, 'required', 'veto',"
00230                                 " and 'minHit' cannot be used.");
00231         }
00232 
00233         t->print(argv[0]);
00234 
00235         if(t->perTrack == 0)
00236                 BLManager::getObject()->registerEventAction(t,false);
00237         else
00238                 // at front, so newparticlentuple will work
00239                 BLManager::getObject()->registerTrackingAction(t,true);
00240 
00241         return retval;
00242 }

void BLCMDntuple::defineNamedArgs (  )  [virtual]

defineNamedArgs() defines the named arguments for the command.

Reimplemented from BLCommand.

References BLCommand::argInt(), BLCommand::argString(), category, detectors, filename, format, minHit, perTrack, required, unionFlag, and veto.

00245 {
00246         argString(category,"category","The category of the NTuple.");
00247         argString(detectors,"detectors","A comma-separated list of detector patterns.");
00248         argString(required,"required","A comma-separated list of required detector patterns(default=*).");
00249         argString(veto,"veto","A comma-separated list of detector patterns, any hit cancels entry into the NTuple (default='').");
00250         argString(format,"format","NTuple format (see above for list).");
00251         argString(filename,"filename","Name of file.");
00252         argInt(minHit,"minHit","Minimum number of detectors hit (default 0).");
00253         argInt(perTrack,"perTrack","Nonzero for an entry per track; "
00254                         "0 for an entry per event (default 0).");
00255         argInt(unionFlag,"union","Set nonzero to perform a union of the "
00256                         "detectors, rather than combining them.");
00257         argString(required,"require","Synonym for required.");
00258         argInt(minHit,"minHits","Synonym for minHit.");
00259         argString(filename,"file","Synonym for filename.");
00260 }

void BLCMDntuple::setupFirstEvent (  ) 

setupFirstEvent() will setup the NTuple (called at first event) Done here to be sure all other NTUples have been created (e.g. in callbacks).

References Bit, category, BLNTuple::create(), data, detectors, fields, filename, format, BLNTuple::getFields(), BLNTuple::getList(), BLNTuple::getName(), BLNTuple::getNData(), matches(), name, ndata, need, ntuple, place, BLCommand::printError(), BLNTuple::registerCallback(), required, start, unionFlag, veto, and vetoSet.

Referenced by BeginOfEventAction().

00264 {
00265         std::vector<BLNTuple*> list = BLNTuple::getList();
00266         for(unsigned i=0; i<list.size(); ++i) {
00267                 BLNTuple *detNtuple = list[i];
00268                 G4String detName = detNtuple->getName();
00269                 if(matches(detName,detectors)) {
00270                         G4String detFields = detNtuple->getFields();
00271                         detNtuple->registerCallback(this);
00272                         int j = start.size();
00273                         if(unionFlag) {
00274                                 if(fields.size() == 0) {
00275                                         fields = detFields;
00276                                         ndata = detNtuple->getNData();
00277                                 }
00278                                 if(fields != detFields) {
00279                                         G4Exception("ntuple command",
00280                                             "Field mismatch",
00281                                             FatalException,
00282                                             "Detectors have different fields");
00283                                 }
00284                                 continue;
00285                         }
00286                         place[detNtuple] = j;
00287                         start.push_back(ndata);
00288                         if(matches(detName,required)) {
00289                                 need |= (Bit<<j);
00290                         }
00291                         G4String::size_type place = 0;
00292                         while(place != detFields.npos) {
00293                                 G4String::size_type next = detFields.find(":",place);
00294                                 G4String word = detFields.substr(place,
00295                                 (next==detFields.npos ? detFields.npos : next-place));
00296                                 if(fields.size() != 0) fields += ":";
00297                                 fields += detName;
00298                                 fields += "_";
00299                                 fields += word;
00300                                 ++ndata;
00301                                 place = next;
00302                                 if(next != detFields.npos) place = next + 1;
00303                         }
00304                 } else if(veto.size() > 0 && matches(detName,veto)) {
00305                         detNtuple->registerCallback(this);
00306                         vetoSet.insert(detNtuple);
00307                 }
00308         }
00309 
00310         if(ndata <= 0) {
00311                 printError("ntuple: no detectors in ntuple '%s'!  "
00312                            "Possibilities are:",name.c_str());
00313                 for(unsigned i=0; i<list.size(); ++i) {
00314                         G4String detName = list[i]->getName();
00315                         printf("%s ",detName.c_str());
00316                 }
00317                 printf("\n");
00318                 data = new double[1];
00319                 need = ~(Bitmask)0;
00320                 return;
00321         }
00322 
00323         data = new double[ndata];
00324         ntuple = BLNTuple::create(format,category,name,fields,filename);
00325 }

void BLCMDntuple::BeginOfEventAction ( const G4Event *  event  )  [virtual]

from BLManager::EventAction

Implements BLManager::EventAction.

References data, BLRunManager::getObject(), got, ndata, nHit, setupFirstEvent(), unionFlag, and vetoed.

Referenced by PreUserTrackingAction().

00328 {
00329         if(!data) {
00330                 setupFirstEvent();
00331                 if(unionFlag) return;
00332                 if(BLRunManager::getObject()->getCollectiveMode())
00333                         G4Exception("ntuple command","Collective mode error",
00334                                 FatalException,
00335                                 "Does not work in collective tracking mode");
00336         }
00337 
00338         got = (Bitmask)0;
00339         nHit = 0;
00340         vetoed = 0;
00341 
00342         for(int i=0; i<ndata; ++i)
00343                 data[i] = 0.0;
00344 }

void BLCMDntuple::EndOfEventAction ( const G4Event *  event  )  [virtual]

Implements BLManager::EventAction.

References BLNTuple::appendRow(), data, got, minHit, ndata, need, nHit, ntuple, unionFlag, and vetoed.

Referenced by PostUserTrackingAction().

00347 {
00348         if(unionFlag) return;
00349         if((need&got) == need && nHit >= minHit && !vetoed)
00350                 ntuple->appendRow(data,ndata);
00351 }

void BLCMDntuple::PreUserTrackingAction ( const G4Track *  track  )  [virtual]

from BLManager::TrackingAction

Implements BLManager::TrackingAction.

References BeginOfEventAction().

00354 {
00355         BeginOfEventAction(0);
00356 }

void BLCMDntuple::PostUserTrackingAction ( const G4Track *  track  )  [virtual]

Implements BLManager::TrackingAction.

References EndOfEventAction().

00359 {
00360         EndOfEventAction(0);
00361 }

virtual void BLCMDntuple::ntupleCallback ( BLNTuple caller,
double  data[],
int  ndata 
) [virtual]

bool BLCMDntuple::matches ( G4String  s,
G4String  pattern 
) [static]

returns true if the string s matches one of the patterns in pattern.

References fnmatch(), and place.

Referenced by setupFirstEvent().

00388 {
00389         G4String::size_type place = 0;
00390 
00391         while(place != pattern.npos) {
00392                 G4String::size_type next = pattern.find(",",place);
00393                 G4String word = pattern.substr(place,
00394                             (next==pattern.npos ? pattern.npos : next-place));
00395                 if(fnmatch(word.c_str(),s.c_str(),0) == 0)
00396                         return true;
00397                 place = next;
00398                 if(next != pattern.npos) place = next + 1;
00399         }
00400 
00401         return false;
00402 }


Member Data Documentation

G4String BLCMDntuple::name [private]

G4String BLCMDntuple::category [private]

G4String BLCMDntuple::detectors [private]

G4String BLCMDntuple::required [private]

G4String BLCMDntuple::veto [private]

G4String BLCMDntuple::format [private]

G4String BLCMDntuple::filename [private]

G4int BLCMDntuple::minHit [private]

G4int BLCMDntuple::perTrack [private]

G4int BLCMDntuple::unionFlag [private]

G4String BLCMDntuple::fields [private]

Referenced by BLCMDntuple(), and setupFirstEvent().

double* BLCMDntuple::data [private]

int BLCMDntuple::ndata [private]

std::map<BLNTuple*,int> BLCMDntuple::place [private]

Referenced by matches(), and setupFirstEvent().

std::vector<int> BLCMDntuple::start [private]

Referenced by setupFirstEvent().

std::set<BLNTuple*> BLCMDntuple::vetoSet [private]

Referenced by setupFirstEvent().

int BLCMDntuple::nHit [private]

int BLCMDntuple::vetoed [private]


The documentation for this class was generated from the following file:
g4beamline