00001 // BLTrackNTuple.hh 00002 /* 00003 This source file is part of G4beamline, http://g4beamline.muonsinc.com 00004 Copyright (C) 2003,2004,2005,2006 by Tom Roberts, all rights reserved. 00005 00006 This program is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU General Public License 00008 as published by the Free Software Foundation; either version 2 00009 of the License, or (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 http://www.gnu.org/copyleft/gpl.html 00017 */ 00018 00019 #ifndef BLTRACKNTUPLE_HH 00020 #define BLTRACKNTUPLE_HH 00021 00022 #include "globals.hh" 00023 #include "G4Step.hh" 00024 00025 #include "BLNTuple.hh" 00026 #include "BLEvaluator.hh" 00027 #include "BLCoordinates.hh" 00028 00029 00030 /** class BLTrackNTuple is an interface class to an NTuple for tracks. 00031 * 00032 * This class implements two new formats that add additional fields 00033 * to the NTuple: asciiEnhanced, rootEnhanced. 00034 **/ 00035 class BLTrackNTuple { 00036 BLNTuple *ntuple; 00037 G4String require; 00038 BLEvaluator *eval; 00039 int noSingles; 00040 int nFields; 00041 BLCoordinateType coordinateType; 00042 protected: 00043 /// Constructor. 00044 BLTrackNTuple(); 00045 public: 00046 /// Destructor. 00047 virtual ~BLTrackNTuple() { 00048 if(ntuple) delete ntuple; 00049 if(eval) delete eval; 00050 } 00051 00052 /// close() will close the ntuple 00053 void close() { if(ntuple) ntuple->close(); ntuple = 0; } 00054 00055 /// create() will create a new NTuple for writing. 00056 /// Note that the field names are handled internally, and that the 00057 /// format can change the fields used. 00058 /// format must be a known format of NTuple ("" is default). 00059 /// "category/name" is the name of the NTuple (the "/" may be omitted 00060 /// if category is null, depending on format). 00061 /// filename is a hint, and is not used by all formats. 00062 /// coordinateType is the type of coordiantes to use. 00063 /// require is an expression using track variables that must be nonzero 00064 /// to enter a Step into the NTuple. 00065 /// If noSingles is nonzero, the NTuple itself is not filled, but 00066 /// callbacks are made (to fill NTuples created by the ntuple command). 00067 static BLTrackNTuple *create(G4String format, G4String category, 00068 G4String name, G4String filename, 00069 BLCoordinateType coordinateType=BLCOORD_CENTERLINE, 00070 G4String _require="", int _noSingles=0); 00071 00072 /// appendTrack() appends the data for this Track to the 00073 /// NTuple. Uses arguments to create(): 00074 /// If the require expression is nonempty and evaluates to zero, 00075 /// no entry is made to the NTuple or callbacks. 00076 /// If noSingles is nonzero, the NTuple itself is not filled, but 00077 /// callbacks are made (to fill NTuples created by the ntuple command). 00078 void appendTrack(const G4Track *track); 00079 00080 /// appendTrack() appends the data for this Track, with updated 00081 /// values of the other arguments 00082 void appendTrack(const G4Track *track, double time, 00083 G4ThreeVector position, G4ThreeVector momentum, 00084 double properTime, double trackLength); 00085 00086 /// getName() returns the name of the NTuple (not including category) 00087 G4String getName() const { return ntuple->getName(); } 00088 00089 /// getFields() returns a colon-separated list of the fields. 00090 G4String getFields() { return ntuple->getFields(); } 00091 00092 /// annotate() will add an annotation line to any ASCII format. 00093 /// Normally line should begin with a "#", and have no "\r" or "\n". 00094 /// line == "" will output an empty line to ASCII files. 00095 /// Ignored for NTuples that don't support annotations. 00096 virtual void annotate(G4String line) { ntuple->annotate(line); } 00097 00098 /// needsReference() returns true if this NTuple needs the Reference 00099 /// particle. 00100 virtual bool needsReference() { return ntuple->needsReference(); } 00101 00102 /// getFormatList() returns a list of known formats. 00103 /// This class implements asciiEnhanced and rootEnhanced. 00104 static G4String getFormatList(); 00105 }; 00106 00107 #endif // BLTRACKNTUPLE_HH