15 const std::string& ModelConf_i,
16 const std::string& OutDirName_i,
17 const std::string& JobTag_i,
19 : myInputParser(ModelF, ThObsF)
24 if (OutDirName_i !=
""){
37 MPI_Comm_rank(MPI_COMM_WORLD,&
rank);
38 MPI_Comm_size(MPI_COMM_WORLD,&
procnum);
39 MPI_Get_processor_name(processorName,&nameLen);
54 throw std::runtime_error(
"\nGenerateEvent::generate():\n--noMC was not specified as an argument.\nPlease do so for running in Generate Event mode.\n");
61 gRandom->SetSeed(seed * ( seed +
rank *
procnum + nameLen));
63 gRandom->SetSeed(seed);
89 buff =
new double*[1];
90 buff[0] =
new double[1];
99 while (rem_iteration > 0) {
101 if (
rank < rem_iteration){
103 for (boost::ptr_vector<Observable>::iterator it =
Obs.begin(); it <
Obs.end(); it++) {
104 if (it->getObsType().compare(
"HiggsObservable") != 0) {
110 double hw = it->computeWeight();
111 std::vector<double> theoryValues;
112 it->getTheoryValues(theoryValues);
113 for (
int j = 0; j < it->getNTheoryValues() + 1 + it->getNChannels(); j++) {
120 for (std::vector<CorrelatedGaussianObservables>::iterator it1 =
CGO.begin(); it1 <
CGO.end(); it1++) {
121 std::vector<Observable> ObsInCGO = it1->getObs();
122 for (std::vector<Observable>::iterator it2 = ObsInCGO.begin(); it2 < ObsInCGO.end(); it2++) {
151 for (
int iproc = 0; iproc <
procnum; iproc++) {
154 for (std::vector<ModelParameter>::iterator it =
ModParsVar.begin(); it <
ModParsVar.end(); it++) {
158 if (
outputTerm == 0 && itno != 0) std::cout <<
"\nEvent No.: " << itno++ << std::endl;
159 else if (
outputTerm == 0 && itno++ == 0) std::cout <<
"\nThe central event is: " << std::endl;
160 if (
outputTerm == 0 &&
Obs.size() > 0) std::cout <<
"\nObservables: \n" << std::endl;
161 for (boost::ptr_vector<Observable>::iterator it =
Obs.begin(); it <
Obs.end(); it++) {
162 if (it->getObsType().compare(
"HiggsObservable") != 0) {
164 if (
weight && it->getDistr().compare(
"noweight") != 0) std::cout << it->getName() <<
" = " <<
buff[iproc][
positionID] <<
" (weight: " <<
buff_w[iproc][
positionID] <<
")" << std::endl;
165 else std::cout << it->getName() <<
" = " <<
buff[iproc][
positionID] << std::endl;
174 if (
weight) std::cout <<
"\n" << it->getName() <<
" :" <<
" (weight: " <<
buff_w[iproc][
positionID] <<
")" << std::endl;
175 else std::cout <<
"\n" << it->getName() <<
" :" << std::endl;
176 for (
int i = 0; i < it->getNTheoryValues(); i++) {
177 std::cout <<
" sigma(" << i + 1 <<
") = " <<
buff[iproc][
positionID] << std::endl;
182 for (
int i = it->getNTheoryValues() + 1; i < it->getNTheoryValues() + 1 + it->getNChannels(); i++) {
183 std::cout <<
" mu(" << i - (it->getNTheoryValues() + 1) + 1 <<
") = " <<
buff[iproc][
positionID] << std::endl;
187 for (
int i = 0; i < it->getNTheoryValues(); i++) {
193 for (
int i = it->getNTheoryValues() + 1; i < it->getNTheoryValues() + 1 + it->getNChannels(); i++) {
194 (*
ObsOut[it->getName()]) << std::setw(10) << std::left << buff[iproc][
positionID];
198 (*
ObsOut[it->getName()]) << std::endl;
202 if (
outputTerm == 0 &&
CGO.size() > 0) std::cout <<
"\nCorrelated Gaussian Observables: \n" << std::endl;
203 for (std::vector<CorrelatedGaussianObservables>::iterator it1 =
CGO.begin(); it1 <
CGO.end(); it1++) {
205 if (
weight && !(it1->isPrediction())) std::cout << it1->getName() <<
": (weight: " <<
buff_w[iproc][
positionID] <<
")" << std::endl;
206 else std::cout << it1->getName() << std::endl;
208 std::vector<Observable> ObsInCGO = it1->getObs();
209 for (std::vector<Observable>::iterator it2 = ObsInCGO.begin(); it2 < ObsInCGO.end(); it2++) {
211 if (
weight && it2->getDistr().compare(
"noweight") != 0) std::cout << it2->getName() <<
" = " <<
buff[iproc][
positionID] << std::endl;
212 else std::cout << it2->getName() <<
" = " <<
buff[iproc][
positionID] << std::endl;
229 for(
int iproc = 0; iproc <
procnum; iproc++){
230 it_comp = std::max(it_comp,
buff_int[iproc][0]);
232 rem_iteration -= it_comp;
237 for (std::vector<ModelParameter>::iterator it =
ModParsVar.begin(); it <
ModParsVar.end(); it++) {
238 ParsOut[it->getname()]->close();
240 for (boost::ptr_vector<Observable>::iterator it =
Obs.begin(); it <
Obs.end(); it++){
241 ObsOut[it->getName()]->close();
243 for (std::vector<CorrelatedGaussianObservables>::iterator it1 =
CGO.begin(); it1 <
CGO.end(); it1++){
244 CGOOut[it1->getName()]->close();
248 std::cout <<
"Output written to: " <<
OutDirName <<
"\n" << std::endl;
250 if (
rank == 0) std::cout << std::endl;
253 }
catch (std::string message) {
254 std::cerr << message << std::endl;
274 if (gSystem->GetPathInfo(
"GeneratedEvents", info) != 0) {
275 gSystem->MakeDirectory(
"GeneratedEvents");
277 if (gSystem->GetPathInfo(
"GeneratedEvents/DELETED", info) != 0) {
278 gSystem->MakeDirectory(
"GeneratedEvents/DELETED");
280 if (gSystem->GetPathInfo(
OutDirName.c_str(), info) == 0){
283 std::cout <<
"\nWARNING: Removed " <<
OldOutDirName << std::endl;
285 gSystem->Exec((
"mv -f " +
OutDirName +
" " +
"GeneratedEvents/DELETED/").c_str());
298 for (std::vector<ModelParameter>::iterator it =
ModParsVar.begin(); it <
ModParsVar.end(); it++) {
299 ParsOut[it->getname()] = boost::make_shared<std::ofstream>((
ParsDirName +
"/" + it->getname() +
".txt").c_str(), std::ios::out);
300 summary <<
"Parameter\t" << it->getname() <<
"\n";
303 for (boost::ptr_vector<Observable>::iterator it =
Obs.begin(); it <
Obs.end(); it++) {
304 ObsOut[it->getName()] = boost::make_shared<std::ofstream>((
ObsDirName +
"/" + it->getName() +
".txt").c_str(), std::ios::out);
305 if (
outputTerm != 0 && it->getObsType().compare(
"HiggsObservable") == 0) {
306 for (
int i = 0; i < it->getNTheoryValues(); i++) (*
ObsOut[it->getName()]) << std::setw(6) << std::left <<
"sigma(" << std::setw(1) << i << std::setw(3) << std::left <<
")";
307 (*
ObsOut[it->getName()]) << std::setw(10) << std::left <<
"BR";
308 for (
int i = it->getNTheoryValues() + 1; i < it->getNTheoryValues() + 1 + it->getNChannels(); i++) (*
ObsOut[it->getName()]) << std::setw(3) << std::left <<
"mu(" << std::setw(1) << i << std::setw(6) << std::left <<
")";
309 if (
weight) (*
ObsOut[it->getName()]) << std::setw(10) << std::left <<
"weight";
310 (*
ObsOut[it->getName()]) << std::endl;
312 summary <<
"Observable\t" << it->getName() <<
"\n";
314 for (std::vector<CorrelatedGaussianObservables>::iterator it =
CGO.begin(); it <
CGO.end(); it++){
315 CGOOut[it->getName()] = boost::make_shared<std::ofstream>((
CGODirName +
"/" + it->getName() +
".txt").c_str(), std::ios::out);
316 summary <<
"CGO\t" << it->getName() <<
"\n";
319 std::cout <<
"\nRunning in Event Generation mode... \nWARNING: The output should not be used for any statistical analysis. \n Neither randomness or completness of the sample is gauranteed!!\n" << std::endl;
321 std::cout <<
"\nRunning in Event Generation mode... \nWARNING: Output being sent to terminal, no data written to disk!! \nWARNING: The output should not be used for any statistical analysis. \n Neither randomness or completness of the sample is gauranteed!!\n" << std::endl;
323 std::cout.precision(10);
324 std::cout << std::endl <<
"Running in Single Event mode...\nNo data will be written to disk!\n" << std::endl;
331 if (
Obs.size() == 0 &&
CGO.size() == 0) {
332 if (
rank == 0)
throw std::runtime_error(
"\nGenerateEvent::generate(): No observables or correlated Gaussian observables defined in " +
ModelConf +
" file\n");
335 std::map<std::string, double> DP;
336 for (std::vector<ModelParameter>::iterator it =
ModPars.begin(); it <
ModPars.end(); it++) {
337 if (it->IsCorrelated()) {
338 for (
unsigned int i = 0; i <
CGP.size(); i++) {
339 if (
CGP[i].getName().compare(it->getCgp_name()) == 0) {
340 std::string index = it->getname().substr(
CGP[i].getName().size());
341 long int lindex = strtol(index.c_str(), NULL, 10);
342 if (lindex > 0) DP[
CGP[i].getPar(lindex - 1).getname()] = CGP[i].getPar(lindex - 1).getave();
344 std::stringstream out;
345 out << it->getname();
346 throw std::runtime_error(
"MonteCarlo::Run(): " + out.str() +
"seems to be part of a CorrelatedGaussianParameters object, but I couldn't find the corresponding object");
350 }
else DP[it->getname()] = it->getave();
352 if (it->geterrg() > 0. || it->geterrf() > 0.)
ModParsVar.push_back(*it);
355 if (
rank == 0)
throw std::runtime_error(
"\nERROR: Model cannot be initialization");
360 for (std::vector<CorrelatedGaussianObservables>::iterator it =
CGO.begin(); it <
CGO.end(); it++){
363 for (boost::ptr_vector<Observable>::iterator it =
Obs.begin(); it <
Obs.end(); it++) {
364 if (it->getObsType().compare(
"HiggsObservable") == 0) {
365 buffersize += it->getNTheoryValues() + 1 + it->getNChannels();
374 if (
outputTerm == 0 &&
rank == 0) std::cout <<
"\nParameters varied in Event Generation:" << std::endl;
375 for (std::vector<ModelParameter>::const_iterator it =
ModParsVar.begin(); it <
ModParsVar.end(); it++) {
376 if (it->IsCorrelated()) {
377 for (
unsigned int i = 0; i <
CGP.size(); i++) {
378 if (
CGP[i].getName().compare(it->getCgp_name()) == 0) {
379 std::string index = it->getname().substr(
CGP[i].getName().size());
380 long int lindex = strtol(index.c_str(), NULL, 10);
382 if (
outputTerm == 0 &&
rank == 0) std::cout <<
CGP[i].getPar(lindex - 1).getname() <<
", ";
384 std::stringstream out;
385 out << it->getname();
386 throw std::runtime_error(
"MonteCarlo::Run(): " + out.str() +
"seems to be part of a CorrelatedGaussianParameters object, but I couldn't find the corresponding object");
390 }
else if (
outputTerm == 0 &&
rank == 0) std::cout << it->getname() <<
", ";
391 if (it->geterrf() == 0. && it->geterrg() != 0.){
392 DDist[it->getname()] =
new TF1(it->getname().c_str(),
393 "1./sqrt(2.*TMath::Pi())/[1] * exp(-(x-[0])*(x-[0])/2./[1]/[1])",
394 it->getmin(),it->getmax());
395 DDist[it->getname()]->SetParameter(0, it->getave());
396 DDist[it->getname()]->SetParameter(1, it->geterrg());
398 else if (it->geterrg() == 0. && it->geterrf() != 0.){
399 DDist[it->getname()] =
new TF1(it->getname().c_str(),
401 it->getmin(), it->getmax());
402 DDist[it->getname()]->SetParameter(0,it->getmin());
403 DDist[it->getname()]->SetParameter(1,it->getmax());
406 DDist[it->getname()] =
new TF1(it->getname().c_str(),
407 "(TMath::Erf((x-[0]+[2])/sqrt(2.)/[1])-TMath::Erf((x-[0]-[2])/sqrt(2.)/[1]))/4./[2]",
408 it->getmin(), it->getmax());
409 DDist[it->getname()]->SetParameter(0, it->getave());
410 DDist[it->getname()]->SetParameter(1, it->geterrg());
411 DDist[it->getname()]->SetParameter(2, it->geterrf());
421 std::vector<double> vec(
ModParsVar.size(),0.);
422 for (
unsigned int i=0; i< vec.size();i++){
423 if (iterationNo == 0) vec[i] =
ModParsVar[i].getave();
428 for (std::vector<ModelParameter>::const_iterator it =
ModParsVar.begin(); it <
ModParsVar.end(); it++){
429 if (it->IsCorrelated()) {
430 for (
unsigned int i = 0; i <
CGP.size(); i++) {
431 if (
CGP[i].getName().compare(it->getCgp_name()) == 0) {
432 std::string index = it->getname().substr(
CGP[i].getName().size());
433 long int lindex = strtol(index.c_str(), NULL, 10);
440 std::stringstream out;
441 out << it->getname();
442 throw std::runtime_error(
"MonteCarlo::Run(): " + out.str() +
"seems to be part of a CorrelatedGaussianParameters object, but I couldn't find the corresponding object");
457 std::map<std::string, std::vector<double> > cgpmap;
460 for (std::vector<ModelParameter>::const_iterator it =
ModParsVar.begin(); it <
ModParsVar.end(); it++){
462 if (it->IsCorrelated()) {
463 std::string index = it->getname().substr(it->getCgp_name().size());
464 unsigned long int lindex = strtol(index.c_str(),NULL,10);
465 if (lindex - 1 == cgpmap[it->getCgp_name()].size()) cgpmap[it->getCgp_name()].push_back(parameters[k]);
467 std::stringstream out;
468 out << it->getname() <<
" " << lindex;
469 throw std::runtime_error(
"GenerateEvent::setDParsFromParameters(): " + out.str() +
"seems to be a CorrelatedGaussianParameters object but the corresponding parameters are missing or not in the right order");
472 }
else DPars_i[it->getname()] = parameters[k];
476 for (
unsigned int j = 0; j <
CGP.size(); j++) {
477 std::vector<double> current = cgpmap.at(
CGP[j].getName());
478 if (current.size() !=
CGP[j].getPars().size()) {
479 std::stringstream out;
480 out <<
CGP[j].getName();
481 throw std::runtime_error(
"GenerateEvent::setDParsFromParameters(): " + out.str() +
" appears to be represented in cgpmap with a wrong size");
484 std::vector<double> porig =
CGP[j].getOrigParsValue(current);
486 for(
unsigned int l = 0; l < porig.size(); l++) {
487 DPars_i[
CGP[j].getPar(l).getname()] = porig[l];
std::string ObsDirName
String for the name of the observables output directory.
virtual bool Update(const std::map< std::string, double > &DPars)=0
The update method for the model.
std::map< std::string, double > DPars
Map of parameters to be passed to Model().
bool outputTerm
Flag to specify output stream storage.
std::string ModelConf
String for the name of the SomeModel.conf file.
std::vector< Observable2D > Obs2D
Vector for the Observables2D defined in SomeModel.conf.
void generate(int unsigned nIteration_i, int seed=0, bool weight_i=false)
The method used to generate events and format output.
void generateRandomEvent(int iterationNo)
This member generates random numbers for the parameters being varied in the model. The first set is always the central value of the parameter.
GenerateEvent(ModelFactory &ModelF, ThObsFactory &ThObsF, const std::string &ModelConf_i, const std::string &OutDirName_i, const std::string &JobTag_i, const bool noMC_i)
Constructor.
void defineParameterDistributions()
The parameter distributions as specified in SomeModel.conf is defined here.
std::string CGODirName
String for the name of the Correlated Gaussian Observables output directory.
std::string JobTag
String for the optional JobTag argument to be passes to the executable.
std::vector< CorrelatedGaussianParameters > CGP
vector for the Correlated Gaussian Parameters defined in SomeModel.conf.
std::string SUSYDebugDirName
String for the name of the Correlated Gaussian Observables output directory.
InputParser myInputParser
An oject of the InputParser() class.
std::map< std::string, boost::shared_ptr< std::ofstream > > ParsOut
Map of output stream for parameters.
std::vector< ModelParameter > ModPars
Vector for the model parameters defined in SomeModel.conf.
boost::ptr_vector< Observable > Obs
Vector for the observables defined in SomeModel.conf.
std::string OutDirName
String for the name of the output directory.
std::string OldOutDirName
String for the name of the backup output directory.
virtual bool Init(const std::map< std::string, double > &DPars)
A method to initialize the model parameters.
std::vector< CorrelatedGaussianObservables > CGO
vector for the Correlated Gaussian Observables defined in SomeModel.conf.
void setDParsFromParameters(const std::vector< double > ¶meters, std::map< std::string, double > &DPars_i)
void addCustomObservableType(const std::string name, boost::function< Observable *() > funct)
std::string ParsDirName
String for the name of the parameters output directory.
Model * Mod
Name of the model as defined in SomeModel.conf.
bool noMC
Flag to initiate noMC mode.
std::map< std::string, boost::shared_ptr< std::ofstream > > ObsOut
Map of output stream for observables.
std::vector< ModelParameter > ModParsVar
Vector for the model parameters varied in SomeModel.conf.
std::map< std::string, TF1 * > DDist
Map of parameter distributions.
std::map< std::string, boost::shared_ptr< std::ofstream > > CGOOut
Map of output stream for corellated Gaussian observables.
virtual ~GenerateEvent()
The default destructor.
std::string SMDebugDirName
String for the name of the observables output directory.