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, float 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 |
G4String | fields |
BLNTuple * | ntuple |
float * | data |
int | ndata |
std::map< BLNTuple *, int > | place |
std::vector< int > | start |
std::set< BLNTuple * > | vetoSet |
Bitmask | need |
Bitmask | got |
int | nHit |
int | vetoed |
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(), veto, and vetoed.
Referenced by command().
00103 : BLCommand(), BLManager::EventAction(), 00104 place(), start(), vetoSet() 00105 { 00106 registerCommand(BLCMDTYPE_DATA); 00107 setSynopsis("Define an NTuple containing multiple detectors."); 00108 setDescription("An ntuple holds the data from multiple " 00109 "detectors in a single NTuple, with one row (entry) per " 00110 "event or per track. This permits the generation of plots " 00111 "that compare different detectors. " 00112 "Up to 64 detectors can be used. " 00113 "While 'detector' is used in this description, any existing " 00114 "NTuple can be used, generated by any command, such as: " 00115 "virtualdetector, zntuple, beamlossntuple, timentuple, and " 00116 "newparticlentuple.\n\n" 00117 "By default, an entry in this ntuple is made for each event " 00118 "satisfying the require, veto, and minHit conditions; if " 00119 "perTrack=1 then an entry is made for each track that " 00120 "satisfies the require, veto, and minHit conditions. " 00121 "Any hit in any detector matching the patterns in veto will " 00122 "prevent the event/track from being entered into the ntuple." 00123 "\n\n" 00124 "If multiple hits occur in a given detector during the " 00125 "event or track, only the first one is kept in this ntuple. " 00126 "Detectors are specified by patterns identical to " 00127 "UNIX file-matching, so '*Det*' matches any detector " 00128 "with 'Det' anywhere in its name, etc. The 'required' argument " 00129 "permits events to be omitted unless all of the matching " 00130 "detectors were hit at least once in the event or track. The " 00131 "patterns in 'required' are applied only to detectors " 00132 "in the ntuple, so a simple '*' only matches detectors named " 00133 "in the 'detectors' argument.\n" 00134 "\nNOTE: the name of a detector is by default the " 00135 "concatenation of its ancestors' names before its own (except " 00136 "World), unless " 00137 "rename=NAME was used in its place command. The patterns are " 00138 "applied to the names of the virtualdetectors as they were " 00139 "placed (including rename), not the bare name of the " 00140 "virtualdetector command. If 'rename=det#' was used when " 00141 "placing " 00142 "the virtualdetector-s, you probably want a * to match the #, " 00143 "or list them individually (det1,det2,det3...).\n\n" 00144 "Valid Formats (ignore case): "); 00145 description += BLNTuple::getFormatList(); 00146 // initial default values: 00147 name = ""; 00148 category = "NTuple"; 00149 detectors = ""; 00150 required = "*"; 00151 veto = ""; 00152 format = ""; 00153 filename = ""; 00154 minHit = 0; 00155 perTrack = 0; 00156 fields = ""; 00157 ntuple = 0; 00158 data = 0; 00159 ndata = 0; 00160 need = 0; 00161 got = 0; 00162 nHit = 0; 00163 vetoed = 0; 00164 }
BLCMDntuple::BLCMDntuple | ( | const BLCMDntuple & | r | ) |
Copy constructor.
References category, data, detectors, fields, filename, format, got, minHit, name, ndata, need, nHit, ntuple, perTrack, required, veto, and vetoed.
00166 : BLCommand(r), 00167 BLManager::EventAction(), BLManager::TrackingAction(), 00168 BLNTupleCallback(), place(), start(), vetoSet() 00169 { 00170 name = ""; 00171 category = r.category; 00172 detectors = r.detectors; 00173 required = r.required; 00174 veto = r.veto; 00175 format = r.format; 00176 filename = r.filename; 00177 minHit = r.minHit; 00178 perTrack = r.perTrack; 00179 fields = r.fields; 00180 ntuple = 0; 00181 data = 0; 00182 ndata = 0; 00183 need = r.need; 00184 got = 0; 00185 nHit = 0; 00186 vetoed = 0; 00187 }
G4String BLCMDntuple::commandName | ( | ) | [inline, virtual] |
int BLCMDntuple::command | ( | BLArgumentVector & | argv, | |
BLArgumentMap & | namedArgs | |||
) | [virtual] |
command() implements the ntuple command.
Implements BLCommand.
References BLCMDntuple(), BLManager::getObject(), BLCommand::handleNamedArgs(), name, perTrack, BLCommand::print(), BLCommand::printError(), BLManager::registerEventAction(), and BLManager::registerTrackingAction().
00191 { 00192 if(argv.size() != 1) { 00193 printError("Invalid ntuple command -- need name"); 00194 return -1; 00195 } 00196 00197 if(argv[0] == "default") { 00198 handleNamedArgs(namedArgs); 00199 return -1; 00200 } 00201 00202 BLCMDntuple *t = new BLCMDntuple(defaultNtuple); 00203 int retval = t->handleNamedArgs(namedArgs); 00204 00205 t->name = argv[0]; 00206 00207 t->print(argv[0]); 00208 00209 if(t->perTrack == 0) 00210 BLManager::getObject()->registerEventAction(t,false); 00211 else 00212 // at front, so newparticlentuple will work 00213 BLManager::getObject()->registerTrackingAction(t,true); 00214 00215 return retval; 00216 }
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, and veto.
00219 { 00220 argString(category,"category","The category of the NTuple."); 00221 argString(detectors,"detectors","A comma-separated list of detector patterns."); 00222 argString(required,"required","A comma-separated list of required detector patterns(default=*)."); 00223 argString(veto,"veto","A comma-separated list of detector patterns, any hit cancels entry into the NTuple (default='')."); 00224 argString(format,"format","NTuple format (see above for list)."); 00225 argString(filename,"filename","Name of file."); 00226 argInt(minHit,"minHit","Minimum number of detectors hit (default 0)."); 00227 argInt(perTrack,"perTrack","Nonzero for an entry per track; " 00228 "0 for an entry per event (default 0)."); 00229 argString(required,"require","Synonym for required."); 00230 argInt(minHit,"minHits","Synonym for minHit."); 00231 argString(filename,"file","Synonym for filename."); 00232 }
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(), matches(), name, ndata, need, ntuple, place, BLCommand::printError(), BLNTuple::registerCallback(), required, start, veto, and vetoSet.
Referenced by BeginOfEventAction().
00236 { 00237 std::vector<BLNTuple*> list = BLNTuple::getList(); 00238 for(unsigned i=0; i<list.size(); ++i) { 00239 BLNTuple *detNtuple = list[i]; 00240 G4String detName = detNtuple->getName(); 00241 if(matches(detName,detectors)) { 00242 G4String detFields = detNtuple->getFields(); 00243 detNtuple->registerCallback(this); 00244 int j = start.size(); 00245 place[detNtuple] = j; 00246 start.push_back(ndata); 00247 if(matches(detName,required)) { 00248 need |= (Bit<<j); 00249 } 00250 G4String::size_type place = 0; 00251 while(place != detFields.npos) { 00252 G4String::size_type next = detFields.find(":",place); 00253 G4String word = detFields.substr(place, 00254 (next==detFields.npos ? detFields.npos : next-place)); 00255 if(fields.size() != 0) fields += ":"; 00256 fields += detName; 00257 fields += "_"; 00258 fields += word; 00259 ++ndata; 00260 place = next; 00261 if(next != detFields.npos) place = next + 1; 00262 } 00263 } else if(veto.size() > 0 && matches(detName,veto)) { 00264 detNtuple->registerCallback(this); 00265 vetoSet.insert(detNtuple); 00266 } 00267 } 00268 00269 if(ndata <= 0) { 00270 printError("ntuple: no detectors in ntuple '%s'! " 00271 "Possibilities are:",name.c_str()); 00272 for(unsigned i=0; i<list.size(); ++i) { 00273 G4String detName = list[i]->getName(); 00274 printf("%s ",detName.c_str()); 00275 } 00276 printf("\n"); 00277 data = new float[1]; 00278 need = ~(Bitmask)0; 00279 return; 00280 } 00281 00282 data = new float[ndata]; 00283 ntuple = BLNTuple::create(format,category,name,fields,filename); 00284 }
void BLCMDntuple::BeginOfEventAction | ( | const G4Event * | event | ) | [virtual] |
Implements BLManager::EventAction.
References data, got, ndata, nHit, setupFirstEvent(), and vetoed.
Referenced by PreUserTrackingAction().
00287 { 00288 if(!data) 00289 setupFirstEvent(); 00290 00291 got = (Bitmask)0; 00292 nHit = 0; 00293 vetoed = 0; 00294 00295 for(int i=0; i<ndata; ++i) 00296 data[i] = 0.0; 00297 }
void BLCMDntuple::EndOfEventAction | ( | const G4Event * | event | ) | [virtual] |
void BLCMDntuple::PreUserTrackingAction | ( | const G4Track * | track | ) | [virtual] |
from BLManager::TrackingAction
Implements BLManager::TrackingAction.
References BeginOfEventAction().
00306 { 00307 BeginOfEventAction(0); 00308 }
void BLCMDntuple::PostUserTrackingAction | ( | const G4Track * | track | ) | [virtual] |
Implements BLManager::TrackingAction.
References EndOfEventAction().
00311 { 00312 EndOfEventAction(0); 00313 }
virtual void BLCMDntuple::ntupleCallback | ( | BLNTuple * | caller, | |
float | 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().
00336 { 00337 G4String::size_type place = 0; 00338 00339 while(place != pattern.npos) { 00340 G4String::size_type next = pattern.find(",",place); 00341 G4String word = pattern.substr(place, 00342 (next==pattern.npos ? pattern.npos : next-place)); 00343 if(fnmatch(word.c_str(),s.c_str(),0) == 0) 00344 return true; 00345 place = next; 00346 if(next != pattern.npos) place = next + 1; 00347 } 00348 00349 return false; 00350 }
G4String BLCMDntuple::name [private] |
Referenced by BLCMDntuple(), command(), and setupFirstEvent().
G4String BLCMDntuple::category [private] |
Referenced by BLCMDntuple(), defineNamedArgs(), and setupFirstEvent().
G4String BLCMDntuple::detectors [private] |
Referenced by BLCMDntuple(), defineNamedArgs(), and setupFirstEvent().
G4String BLCMDntuple::required [private] |
Referenced by BLCMDntuple(), defineNamedArgs(), and setupFirstEvent().
G4String BLCMDntuple::veto [private] |
Referenced by BLCMDntuple(), defineNamedArgs(), and setupFirstEvent().
G4String BLCMDntuple::format [private] |
Referenced by BLCMDntuple(), defineNamedArgs(), and setupFirstEvent().
G4String BLCMDntuple::filename [private] |
Referenced by BLCMDntuple(), defineNamedArgs(), and setupFirstEvent().
G4int BLCMDntuple::minHit [private] |
Referenced by BLCMDntuple(), defineNamedArgs(), and EndOfEventAction().
G4int BLCMDntuple::perTrack [private] |
Referenced by BLCMDntuple(), command(), and defineNamedArgs().
G4String BLCMDntuple::fields [private] |
Referenced by BLCMDntuple(), and setupFirstEvent().
BLNTuple* BLCMDntuple::ntuple [private] |
Referenced by BLCMDntuple(), EndOfEventAction(), and setupFirstEvent().
float* BLCMDntuple::data [private] |
Referenced by BeginOfEventAction(), BLCMDntuple(), EndOfEventAction(), and setupFirstEvent().
int BLCMDntuple::ndata [private] |
Referenced by BeginOfEventAction(), BLCMDntuple(), EndOfEventAction(), and setupFirstEvent().
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().
Bitmask BLCMDntuple::need [private] |
Referenced by BLCMDntuple(), EndOfEventAction(), and setupFirstEvent().
Bitmask BLCMDntuple::got [private] |
Referenced by BeginOfEventAction(), BLCMDntuple(), and EndOfEventAction().
int BLCMDntuple::nHit [private] |
Referenced by BeginOfEventAction(), BLCMDntuple(), and EndOfEventAction().
int BLCMDntuple::vetoed [private] |
Referenced by BeginOfEventAction(), BLCMDntuple(), and EndOfEventAction().