Definition at line 14 of file generate_weightcalc.py.
19 opts, args = getopt.getopt(argv,
"hf:",[
"funcname="])
20 except getopt.GetoptError:
21 print 'generate_weightcalc.py -f FUNCNAME'
25 print 'generate_weightcalc.py -f FUNCNAME'
30 print 'option not recognized'
34 print "You must specify function name with option -f!"
37 filename=
"".
join(x
for x
in funcname
if x.isalnum())
38 filename=filename+
"WeightCalc.cxx"
40 if (os.path.isfile(filename)):
41 print "File",filename,
"already exists!"
44 print 'Genarating function', filename
47 #include \"larsim/EventWeight/Base/WeightCalcCreator.h\"
48 #include \"larsim/EventWeight/Base/WeightCalc.h\"
50 #include "art/Framework/Services/Registry/ServiceHandle.h"
51 #include "art/Framework/Services/Optional/RandomNumberGenerator.h"
53 #include "CLHEP/Random/RandGaussQ.h"
56 class %(funcname)sWeightCalc : public WeightCalc
59 %(funcname)sWeightCalc();
60 void Configure(fhicl::ParameterSet const& p);
61 std::vector<std::vector<double> > GetWeight(art::Event & e);
63 CLHEP::RandGaussQ *fGaussRandom;
65 DECLARE_WEIGHTCALC(%(funcname)sWeightCalc)
67 %(funcname)sWeightCalc::%(funcname)sWeightCalc()
71 void %(funcname)sWeightCalc::Configure(fhicl::ParameterSet const& p)
73 //get configuration for this function
74 fhicl::ParameterSet const &pset=p.get<fhicl::ParameterSet> (GetName());
76 //Prepare random generator
77 art::ServiceHandle<art::RandomNumberGenerator> rng;
78 fGaussRandom = new CLHEP::RandGaussQ(rng->getEngine(GetName()));
81 std::vector<std::vector<double> > %(funcname)sWeightCalc::GetWeight(art::Event & e)
83 //calculate weight(s) here
84 std::vector<std::vector<double> > weight;
87 REGISTER_WEIGHTCALC(%(funcname)sWeightCalc)
89 '''%{
'funcname':funcname}
S join(S const &sep, Coll const &s)
Returns a concatenation of strings in s separated by sep.
open(RACETRACK) or die("Could not open file $RACETRACK for writing")