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 BLManager::getObject()->registerTrackingAction(t); 00213 00214 return retval; 00215 }
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.
00218 { 00219 argString(category,"category","The category of the NTuple."); 00220 argString(detectors,"detectors","A comma-separated list of detector patterns."); 00221 argString(required,"required","A comma-separated list of required detector patterns(default=*)."); 00222 argString(veto,"veto","A comma-separated list of detector patterns, any hit cancels entry into the NTuple (default='')."); 00223 argString(format,"format","NTuple format (see above for list)."); 00224 argString(filename,"filename","Name of file."); 00225 argInt(minHit,"minHit","Minimum number of detectors hit (default 0)."); 00226 argInt(perTrack,"perTrack","Nonzero for an entry per track; " 00227 "0 for an entry per event (default 0)."); 00228 argString(required,"require","Synonym for required."); 00229 argInt(minHit,"minHits","Synonym for minHit."); 00230 argString(filename,"file","Synonym for filename."); 00231 }
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().
00235 { 00236 std::vector<BLNTuple*> list = BLNTuple::getList(); 00237 for(unsigned i=0; i<list.size(); ++i) { 00238 BLNTuple *detNtuple = list[i]; 00239 G4String detName = detNtuple->getName(); 00240 if(matches(detName,detectors)) { 00241 G4String detFields = detNtuple->getFields(); 00242 detNtuple->registerCallback(this); 00243 int j = start.size(); 00244 place[detNtuple] = j; 00245 start.push_back(ndata); 00246 if(matches(detName,required)) { 00247 need |= (Bit<<j); 00248 } 00249 unsigned place = 0; 00250 while(place != detFields.npos) { 00251 unsigned next = detFields.find(":",place); 00252 G4String word = detFields.substr(place, 00253 (next==detFields.npos ? detFields.npos : next-place)); 00254 if(fields.size() != 0) fields += ":"; 00255 fields += detName; 00256 fields += "_"; 00257 fields += word; 00258 ++ndata; 00259 place = next; 00260 if(next != detFields.npos) place = next + 1; 00261 } 00262 } else if(veto.size() > 0 && matches(detName,veto)) { 00263 detNtuple->registerCallback(this); 00264 vetoSet.insert(detNtuple); 00265 } 00266 } 00267 00268 if(ndata <= 0) { 00269 printError("ntuple: no detectors in ntuple '%s'! " 00270 "Possibilities are:",name.c_str()); 00271 for(unsigned i=0; i<list.size(); ++i) { 00272 G4String detName = list[i]->getName(); 00273 printf("%s ",detName.c_str()); 00274 } 00275 printf("\n"); 00276 data = new float[1]; 00277 need = ~(Bitmask)0; 00278 return; 00279 } 00280 00281 data = new float[ndata]; 00282 ntuple = BLNTuple::create(format,category,name,fields,filename); 00283 }
void BLCMDntuple::BeginOfEventAction | ( | const G4Event * | event | ) | [virtual] |
Implements BLManager::EventAction.
References data, got, ndata, nHit, setupFirstEvent(), and vetoed.
Referenced by PreUserTrackingAction().
00286 { 00287 if(!data) 00288 setupFirstEvent(); 00289 00290 got = (Bitmask)0; 00291 nHit = 0; 00292 vetoed = 0; 00293 00294 for(int i=0; i<ndata; ++i) 00295 data[i] = 0.0; 00296 }
void BLCMDntuple::EndOfEventAction | ( | const G4Event * | event | ) | [virtual] |
void BLCMDntuple::PreUserTrackingAction | ( | const G4Track * | track | ) | [virtual] |
from BLManager::TrackingAction
Implements BLManager::TrackingAction.
References BeginOfEventAction().
00305 { 00306 BeginOfEventAction(0); 00307 }
void BLCMDntuple::PostUserTrackingAction | ( | const G4Track * | track | ) | [virtual] |
Implements BLManager::TrackingAction.
References EndOfEventAction().
00310 { 00311 EndOfEventAction(0); 00312 }
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().
00335 { 00336 unsigned place = 0; 00337 00338 while(place != pattern.npos) { 00339 unsigned next = pattern.find(",",place); 00340 G4String word = pattern.substr(place, 00341 (next==pattern.npos ? pattern.npos : next-place)); 00342 if(fnmatch(word.c_str(),s.c_str(),0) == 0) 00343 return true; 00344 place = next; 00345 if(next != pattern.npos) place = next + 1; 00346 } 00347 00348 return false; 00349 }
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().