EventGeneration

A module for generating events based on the ROOT random number generator. More...

Classes

class  GenerateEvent
 A class for generating events. More...
 

Functions

void GenerateEvent::addCustomObservableType (const std::string name, boost::function< Observable *() > funct)
 
void GenerateEvent::createDirectories ()
 
void GenerateEvent::defineParameterDistributions ()
 The parameter distributions as specified in SomeModel.conf is defined here. More...
 
void GenerateEvent::generate (int unsigned nIteration_i, int seed=0, bool weight_i=false)
 The method used to generate events and format output. More...
 
 GenerateEvent::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. More...
 
void GenerateEvent::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. More...
 
void GenerateEvent::initModel ()
 
void GenerateEvent::setDParsFromParameters (const std::vector< double > &parameters, std::map< std::string, double > &DPars_i)
 
virtual GenerateEvent::~GenerateEvent ()
 The default destructor. More...
 

Variables

double ** GenerateEvent::buff
 
int ** GenerateEvent::buff_int
 
double ** GenerateEvent::buff_w
 
int GenerateEvent::buffersize
 
std::vector< CorrelatedGaussianObservablesGenerateEvent::CGO
 vector for the Correlated Gaussian Observables defined in SomeModel.conf. More...
 
std::string GenerateEvent::CGODirName
 String for the name of the Correlated Gaussian Observables output directory. More...
 
std::map< std::string, boost::shared_ptr< std::ofstream > > GenerateEvent::CGOOut
 Map of output stream for corellated Gaussian observables. More...
 
std::vector< CorrelatedGaussianParametersGenerateEvent::CGP
 vector for the Correlated Gaussian Parameters defined in SomeModel.conf. More...
 
std::map< std::string, TF1 * > GenerateEvent::DDist
 Map of parameter distributions. More...
 
std::map< std::string, double > GenerateEvent::DPars
 Map of parameters to be passed to Model(). More...
 
std::string GenerateEvent::JobTag
 String for the optional JobTag argument to be passes to the executable. More...
 
ModelGenerateEvent::Mod
 Name of the model as defined in SomeModel.conf. More...
 
std::string GenerateEvent::ModelConf
 String for the name of the SomeModel.conf file. More...
 
std::string GenerateEvent::ModelName
 
std::vector< ModelParameterGenerateEvent::ModPars
 Vector for the model parameters defined in SomeModel.conf. More...
 
std::vector< ModelParameterGenerateEvent::ModParsVar
 Vector for the model parameters varied in SomeModel.conf. More...
 
InputParser GenerateEvent::myInputParser
 An oject of the InputParser() class. More...
 
int GenerateEvent::nIteration
 
bool GenerateEvent::noMC
 Flag to initiate noMC mode. More...
 
boost::ptr_vector< ObservableGenerateEvent::Obs
 Vector for the observables defined in SomeModel.conf. More...
 
std::vector< Observable2DGenerateEvent::Obs2D
 Vector for the Observables2D defined in SomeModel.conf. More...
 
std::string GenerateEvent::ObsDirName
 String for the name of the observables output directory. More...
 
std::map< std::string, boost::shared_ptr< std::ofstream > > GenerateEvent::ObsOut
 Map of output stream for observables. More...
 
std::string GenerateEvent::OldOutDirName
 String for the name of the backup output directory. More...
 
std::string GenerateEvent::OutDirName
 String for the name of the output directory. More...
 
bool GenerateEvent::outputTerm
 Flag to specify output stream storage. More...
 
std::string GenerateEvent::ParsDirName
 String for the name of the parameters output directory. More...
 
std::map< std::string, boost::shared_ptr< std::ofstream > > GenerateEvent::ParsOut
 Map of output stream for parameters. More...
 
int GenerateEvent::positionID
 
int GenerateEvent::procnum
 
int GenerateEvent::rank
 
double * GenerateEvent::sendbuff
 
int * GenerateEvent::sendbuff_int
 
double * GenerateEvent::sendbuff_w
 
std::string GenerateEvent::SMDebugDirName
 String for the name of the observables output directory. More...
 
std::ofstream GenerateEvent::summary
 
std::string GenerateEvent::SUSYDebugDirName
 String for the name of the Correlated Gaussian Observables output directory. More...
 
bool GenerateEvent::weight
 

Detailed Description

A module for generating events based on the ROOT random number generator.

This module is for using the implementations of the observables without running a Markov Chain Monte Carlo. It allows generation of events based on the ROOT random number generator.

Function Documentation

void GenerateEvent::addCustomObservableType ( const std::string  name,
boost::function< Observable *() >  funct 
)

Definition at line 492 of file GenerateEvent.cpp.

492  {
494 }
InputParser myInputParser
An oject of the InputParser() class.
void addCustomObservableType(const std::string name, boost::function< Observable *() > funct)
void GenerateEvent::createDirectories ( )
private

Definition at line 270 of file GenerateEvent.cpp.

271 {
272  if (nIteration > 0 && outputTerm == 1){
273  FileStat_t info;
274  if (gSystem->GetPathInfo("GeneratedEvents", info) != 0) {
275  gSystem->MakeDirectory("GeneratedEvents");
276  }
277  if (gSystem->GetPathInfo("GeneratedEvents/DELETED", info) != 0) {
278  gSystem->MakeDirectory("GeneratedEvents/DELETED");
279  }
280  if (gSystem->GetPathInfo(OutDirName.c_str(), info) == 0){
281  if (gSystem->GetPathInfo(OldOutDirName.c_str(), info) == 0){
282  gSystem->Exec(("rm -rf " + OldOutDirName).c_str());
283  std::cout << "\nWARNING: Removed " << OldOutDirName << std::endl;
284  }
285  gSystem->Exec(("mv -f " + OutDirName + " " + "GeneratedEvents/DELETED/").c_str());
286  std::cout << "WARNING: " << OutDirName << " exists!\nWARNING: " << OutDirName <<" moved to " << OldOutDirName << "\n"<< std::endl;
287  }
288  gSystem->MakeDirectory(OutDirName.c_str());
289  gSystem->MakeDirectory(ObsDirName.c_str());
290  gSystem->MakeDirectory(CGODirName.c_str());
291  gSystem->MakeDirectory(ParsDirName.c_str());
292 
293  if (outputTerm == 1){
294  summary.open((OutDirName + "/Summary.txt").c_str(), std::ios::out);
295  summary << "Model\t" << ModelName << "\n";
296  }
297 
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";
301  }
302 
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;
311  }
312  summary << "Observable\t" << it->getName() << "\n";
313  }
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";
317  }
318 
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;
320  } else if(nIteration > 0 && outputTerm == 0) {
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;
322  } else {
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;
325  }
326 }
std::string ObsDirName
String for the name of the observables output directory.
bool outputTerm
Flag to specify output stream storage.
std::ofstream summary
std::string CGODirName
String for the name of the Correlated Gaussian Observables output directory.
std::map< std::string, boost::shared_ptr< std::ofstream > > ParsOut
Map of output stream for parameters.
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.
std::string ModelName
std::vector< CorrelatedGaussianObservables > CGO
vector for the Correlated Gaussian Observables defined in SomeModel.conf.
std::string ParsDirName
String for the name of the parameters output directory.
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, boost::shared_ptr< std::ofstream > > CGOOut
Map of output stream for corellated Gaussian observables.
void GenerateEvent::defineParameterDistributions ( )
private

The parameter distributions as specified in SomeModel.conf is defined here.

The parameters in the SomeModel.conf either have a flat error or a Gaussian error and might even have both. This member defines the distributions of the parameters using the TF1 class in ROOT.

Definition at line 372 of file GenerateEvent.cpp.

373 {
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);
381  if (lindex > 0) {
382  if (outputTerm == 0 && rank == 0) std::cout << CGP[i].getPar(lindex - 1).getname() << ", ";
383  } else {
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");
387  }
388  }
389  }
390  } else if (outputTerm == 0 && rank == 0) std::cout << it->getname() << ", "; //<< k << std::endl;
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());
397  }
398  else if (it->geterrg() == 0. && it->geterrf() != 0.){
399  DDist[it->getname()] = new TF1(it->getname().c_str(),
400  "1/([1]-[0])",
401  it->getmin(), it->getmax());
402  DDist[it->getname()]->SetParameter(0,it->getmin());
403  DDist[it->getname()]->SetParameter(1,it->getmax());
404  }
405  else {
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());
412  }
413  }
414  if (outputTerm == 0) std::cout << std::endl;
415 }
bool outputTerm
Flag to specify output stream storage.
std::vector< CorrelatedGaussianParameters > CGP
vector for the Correlated Gaussian Parameters defined in SomeModel.conf.
std::vector< ModelParameter > ModParsVar
Vector for the model parameters varied in SomeModel.conf.
std::map< std::string, TF1 * > DDist
Map of parameter distributions.
void GenerateEvent::generate ( int unsigned  nIteration_i,
int  seed = 0,
bool  weight_i = false 
)

The method used to generate events and format output.

This member creates all out directories that might be needed in case the output is stored on disk. Output on disk is generated as follows:

  • Existence of GenerateEvents folder is checked or else created in the current directory.
  • The user specified OutDirName_i and a directory called OLD is created under GenerateEvents if it does not already exist.
  • If OutDirName_i exists, it is moved into OLD.
  • If OutDirName_i exits in OLD is deleted before the existing GenerateEvents/OutDirName_i is moved into OLD.
  • In the now empty GenerateEvents/OutDirName_i the directories Parameters and Observables are created. The names indicate what they will contain.
    The file Summary.txt contains the list of parameters that are varied and observables that are generated in a run. This is in the GenerateEvents/OutDirName_i directory.
    Parameters
    [in]rankthe rank of the process for MPI implementations (0 for serial implementation)
    [in]nIterationnumber of events generated
    [in]seedseed for the random number generator (default = 0)

Definition at line 50 of file GenerateEvent.cpp.

51 {
52  weight = weight_i;
53  if (!noMC)
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");
55  nIteration = nIteration_i;
56  if (nIteration == 0) outputTerm = 0;
57  int it_comp = 0;
58  int rem_iteration = nIteration + 1;
59  int itno = 0;
60 #ifdef _MPI
61  gRandom->SetSeed(seed * (/*(unsigned)time(NULL)*/ seed + rank * procnum + nameLen));
62 #else
63  gRandom->SetSeed(seed);
64 #endif
65 
66  try {
67  /* initialize model and set model parameters */
68  initModel();
69 
70  /* define parameter distributions */
72 
73  /* create directory structure and necessary files */
74  if (rank == 0) createDirectories();
75 
76  /* memory allocation for MPI */
77  sendbuff = new double[buffersize];
78  sendbuff_w = new double[buffersize];
79  sendbuff_int = new int[1];
80  if( rank == 0 ){
81  buff = new double*[procnum];
82  buff[0]=new double[procnum * buffersize];
83  for(int i = 1; i < procnum; i++) buff[i] = buff[i - 1] + buffersize;
84 
85  buff_w = new double*[procnum];
86  buff_w[0]=new double[procnum * buffersize];
87  for(int i = 1; i < procnum; i++) buff_w[i] = buff_w[i - 1] + buffersize;
88  } else {
89  buff = new double*[1];
90  buff[0] = new double[1];
91  buff_w = new double*[1];
92  buff_w[0] = new double[1];
93  }
94  buff_int = new int*[procnum];
95  buff_int[0]=new int[procnum];
96  for(int i = 1; i < procnum; i++) buff_int[i] = buff_int[i - 1] + 1;
97 
98  /* computation of observables */
99  while (rem_iteration > 0) {
100  itno = rank + nIteration - rem_iteration + 1;
101  if (rank < rem_iteration){
102  generateRandomEvent(itno);
103  for (boost::ptr_vector<Observable>::iterator it = Obs.begin(); it < Obs.end(); it++) {
104  if (it->getObsType().compare("HiggsObservable") != 0) {
105  sendbuff[positionID] = it->computeTheoryValue();
106  if (weight && it->getDistr().compare("noweight") != 0) sendbuff_w[positionID] = it->computeWeight();
107  else sendbuff_w[positionID] = 0.;
108  positionID++;
109  } else {
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++) {
114  sendbuff[positionID] = theoryValues.at(j);
115  if (weight) sendbuff_w[positionID] = hw;
116  positionID++;
117  }
118  }
119  }
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++) {
123  sendbuff[positionID] = it2->computeTheoryValue();
124  if (weight && it2->getDistr().compare("noweight") != 0) sendbuff_w[positionID] = it1->computeWeight();
125  else sendbuff_w[positionID] = 0.;
126  positionID++;
127  }
128  }
129  sendbuff_int[0] = rank + 1;
130  } else {
131  for (int i = 0; i < buffersize; i++){
132  sendbuff[i] = 0.;
133  sendbuff_w[i] = 0.;
134  }
135  sendbuff_int[0] = 0;
136  }
137 
138 #ifdef _MPI
139  MPI::COMM_WORLD.Gather(sendbuff, buffersize, MPI::DOUBLE, buff[0], buffersize, MPI::DOUBLE, 0);
140  if (weight) MPI::COMM_WORLD.Gather(sendbuff_w, buffersize, MPI::DOUBLE, buff_w[0], buffersize, MPI::DOUBLE, 0);
141  MPI::COMM_WORLD.Allgather(sendbuff_int, 1, MPI::INT, buff_int[0], 1, MPI::INT);
142 #else
143  buff[0] = sendbuff;
144  buff_w[0] = sendbuff_w;
145  buff_int[0] = sendbuff_int;
146 #endif
147 
148  /* output generation */
149  if (rank == 0) {
150  itno = nIteration - rem_iteration + 1;
151  for (int iproc = 0; iproc < procnum; iproc++) {
152  positionID = 0;
153  if (buff_int[iproc][0] != 0) {
154  for (std::vector<ModelParameter>::iterator it = ModParsVar.begin(); it < ModParsVar.end(); it++) {
155  if (outputTerm == 1) (*ParsOut[it->getname()]) << buff[iproc][positionID] << std::endl;
156  positionID++;
157  }
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) {
163  if (outputTerm == 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;
166  positionID++;
167  } else {
168  if (weight && it->getDistr().compare("noweight") != 0) (*ObsOut[it->getName()]) << buff[iproc][positionID] << "\t" << buff_w[iproc][positionID] << std::endl;
169  else (*ObsOut[it->getName()]) << buff[iproc][positionID] << std::endl;
170  positionID++;
171  }
172  } else {
173  if (outputTerm == 0) {
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;
178  positionID++;
179  }
180  std::cout << " BR = " << buff[iproc][positionID] << std::endl;
181  positionID++;
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;
184  positionID++;
185  }
186  } else {
187  for (int i = 0; i < it->getNTheoryValues(); i++) {
188  (*ObsOut[it->getName()]) << std::setw(10) << std::left << buff[iproc][positionID];
189  positionID++;
190  }
191  (*ObsOut[it->getName()]) << std::setw(10) << std::left << buff[iproc][positionID];
192  positionID++;
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];
195  positionID++;
196  }
197  if (weight) (*ObsOut[it->getName()]) << std::setw(10) << std::left << buff_w[iproc][positionID - 1];
198  (*ObsOut[it->getName()]) << std::endl;
199  }
200  }
201  }
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++) {
204  if (outputTerm == 0) {
205  if (weight && !(it1->isPrediction())) std::cout << it1->getName() << ": (weight: " << buff_w[iproc][positionID] << ")" << std::endl;
206  else std::cout << it1->getName() << std::endl;
207  }
208  std::vector<Observable> ObsInCGO = it1->getObs();
209  for (std::vector<Observable>::iterator it2 = ObsInCGO.begin(); it2 < ObsInCGO.end(); it2++) {
210  if (outputTerm == 0) {
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;
213  positionID++;
214  } else {
215  if (weight && it2->getDistr().compare("noweight") != 0) (*CGOOut[it1->getName()]) << buff[iproc][positionID] << "\t";
216  else (*CGOOut[it1->getName()]) << buff[iproc][positionID] << "\t";
217  positionID++;
218  }
219  }
220  if (outputTerm == 0) std::cout << std::endl;
221  else (*CGOOut[it1->getName()]) << buff_w[iproc][positionID - 1] << std::endl;
222  }
223  }
224  }
225  }
226 
227  /* computation of remaining iterations */
228  it_comp = 0;
229  for(int iproc = 0; iproc < procnum; iproc++){
230  it_comp = std::max(it_comp, buff_int[iproc][0]);
231  }
232  rem_iteration -= it_comp;
233  }
234 
235  /* closing of output streams */
236  if (outputTerm == 1 && rank == 0){
237  for (std::vector<ModelParameter>::iterator it = ModParsVar.begin(); it < ModParsVar.end(); it++) {
238  ParsOut[it->getname()]->close();
239  }
240  for (boost::ptr_vector<Observable>::iterator it = Obs.begin(); it < Obs.end(); it++){
241  ObsOut[it->getName()]->close();
242  }
243  for (std::vector<CorrelatedGaussianObservables>::iterator it1 = CGO.begin(); it1 < CGO.end(); it1++){
244  CGOOut[it1->getName()]->close();
245  }
246  summary << "Events\t" << nIteration << "\n";
247  summary.close();
248  std::cout << "Output written to: " << OutDirName << "\n" << std::endl;
249  } else {
250  if (rank == 0) std::cout << std::endl;
251  }
252  return;
253  } catch (std::string message) {
254  std::cerr << message << std::endl;
255  exit(EXIT_FAILURE);
256  }
257  delete buff[0];
258  delete [] buff;
259  delete [] sendbuff;
260 
261  delete buff_w[0];
262  delete [] buff_w;
263  delete [] sendbuff_w;
264 
265  delete buff_int[0];
266  delete [] buff_int;
267  delete [] sendbuff_int;
268 }
bool outputTerm
Flag to specify output stream storage.
double ** buff_w
std::ofstream summary
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.
void defineParameterDistributions()
The parameter distributions as specified in SomeModel.conf is defined here.
double ** buff
double * sendbuff
std::map< std::string, boost::shared_ptr< std::ofstream > > ParsOut
Map of output stream for parameters.
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::vector< CorrelatedGaussianObservables > CGO
vector for the Correlated Gaussian Observables 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.
void createDirectories()
double * sendbuff_w
std::map< std::string, boost::shared_ptr< std::ofstream > > CGOOut
Map of output stream for corellated Gaussian observables.
GenerateEvent::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.

The default constructor sets the names of the configuration file and the names of the specific output directory along with a job ID if it is specified as an argument to the executable. Possible arguments to the executable are:

  • SomeModel.conf –noMC : For single event (central event) printed to terminal only.
  • SomeModel.conf –noMC –it=10 : For the central event and 10 events printed to terminal only.
  • SomeModel.conf –noMC –it=10 –output_folder FOLDER: For the central event and 10 events printed to GenerateEvents/FOLDER only.
    Parameters
    [in]ModelConf_ithe name of the input configuration file for the model name, the model parameters and observables to be calculated.
    [in]OutDirName_ithe name of the root output directory to be given
    [in]JobTag_ioptional job tag that might be specified
    [in]noMC_ithe noMC specification given to the executable=

Definition at line 14 of file GenerateEvent.cpp.

19 : myInputParser(ModelF, ThObsF)
20 {
21  outputTerm = 0;
22  ModelConf = ModelConf_i;
23  JobTag = JobTag_i;
24  if (OutDirName_i != ""){
25  OutDirName = "GeneratedEvents/" + OutDirName_i + JobTag;
26  OldOutDirName = ("GeneratedEvents/DELETED/" + OutDirName_i + JobTag);
27  ObsDirName = OutDirName + "/Observables";
28  ParsDirName = OutDirName + "/Parameters";
29  CGODirName = OutDirName + "/CGO";
30  SMDebugDirName = OutDirName + "/SMDebug";
31  SUSYDebugDirName = OutDirName + "/SUSYDebug";
32  outputTerm = 1;
33  }
34  noMC = noMC_i;
35 
36 #ifdef _MPI
37  MPI_Comm_rank(MPI_COMM_WORLD,&rank);
38  MPI_Comm_size(MPI_COMM_WORLD,&procnum);
39  MPI_Get_processor_name(processorName,&nameLen);
40 #else
41  rank = 0;
42  procnum = 1;
43 #endif
44 }
std::string ObsDirName
String for the name of the observables output directory.
bool outputTerm
Flag to specify output stream storage.
std::string ModelConf
String for the name of the SomeModel.conf file.
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::string SUSYDebugDirName
String for the name of the Correlated Gaussian Observables output directory.
InputParser myInputParser
An oject of the InputParser() class.
std::string OutDirName
String for the name of the output directory.
std::string OldOutDirName
String for the name of the backup output directory.
std::string ParsDirName
String for the name of the parameters output directory.
bool noMC
Flag to initiate noMC mode.
std::string SMDebugDirName
String for the name of the observables output directory.
void GenerateEvent::generateRandomEvent ( int  iterationNo)
private

This member generates random numbers for the parameters being varied in the model. The first set is always the central value of the parameter.

Parameters
[in]iterationNothe iteration number

Definition at line 417 of file GenerateEvent.cpp.

418 {
419  positionID = 0;
420 
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();
424  else vec[i] = DDist[ModParsVar[i].getname()]->GetRandom();
425  }
426 
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);
434  if (lindex > 0) {
435  sendbuff[positionID] = DPars[CGP[i].getPar(lindex - 1).getname()];
436  sendbuff_w[positionID] = DPars[CGP[i].getPar(lindex - 1).getname()];
437  positionID++;
438  }
439  else {
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");
443  }
444  }
445  }
446  } else {
447  sendbuff[positionID] = DPars[it->getname()];
448  sendbuff_w[positionID] = DPars[it->getname()];
449  positionID++;
450  }
451  }
452  Mod->Update(DPars);
453 }
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().
std::vector< CorrelatedGaussianParameters > CGP
vector for the Correlated Gaussian Parameters defined in SomeModel.conf.
double * sendbuff
void setDParsFromParameters(const std::vector< double > &parameters, std::map< std::string, double > &DPars_i)
Model * Mod
Name of the model as defined in SomeModel.conf.
std::vector< ModelParameter > ModParsVar
Vector for the model parameters varied in SomeModel.conf.
double * sendbuff_w
std::map< std::string, TF1 * > DDist
Map of parameter distributions.
void GenerateEvent::initModel ( )
private

Definition at line 328 of file GenerateEvent.cpp.

328  {
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");
333  else sleep (2);
334  }
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();
343  else {
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");
347  }
348  }
349  }
350  } else DP[it->getname()] = it->getave();
351 
352  if (it->geterrg() > 0. || it->geterrf() > 0.) ModParsVar.push_back(*it);
353  }
354  if (!myInputParser.getModel()->Init(DP)) {
355  if (rank == 0) throw std::runtime_error("\nERROR: Model cannot be initialization");
356  else sleep(2);
357  }
358 
359  buffersize = ModParsVar.size();
360  for (std::vector<CorrelatedGaussianObservables>::iterator it = CGO.begin(); it < CGO.end(); it++){
361  buffersize += it->getObs().size();
362  }
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();
366  } else {
367  buffersize += 1;
368  }
369  }
370 }
std::string ReadParameters(const std::string filename_i, const int rank, std::vector< ModelParameter > &ModelPars, boost::ptr_vector< Observable > &Observables, std::vector< Observable2D > &Observables2D, std::vector< CorrelatedGaussianObservables > &CGO, std::vector< CorrelatedGaussianParameters > &CGP)
The member that parses the Observable2D directives from SomeModel.conf file.
Definition: InputParser.cpp:28
std::string ModelConf
String for the name of the SomeModel.conf file.
std::vector< Observable2D > Obs2D
Vector for the Observables2D defined in SomeModel.conf.
std::vector< CorrelatedGaussianParameters > CGP
vector for the Correlated Gaussian Parameters defined in SomeModel.conf.
InputParser myInputParser
An oject of the InputParser() class.
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.
virtual bool Init(const std::map< std::string, double > &DPars)
A method to initialize the model parameters.
std::string ModelName
std::vector< CorrelatedGaussianObservables > CGO
vector for the Correlated Gaussian Observables defined in SomeModel.conf.
Model * Mod
Name of the model as defined in SomeModel.conf.
std::vector< ModelParameter > ModParsVar
Vector for the model parameters varied in SomeModel.conf.
StandardModel * getModel() const
A get method to access the pointer to the object of the StandardModel class.
Definition: InputParser.h:110
void GenerateEvent::setDParsFromParameters ( const std::vector< double > &  parameters,
std::map< std::string, double > &  DPars_i 
)
private

Definition at line 455 of file GenerateEvent.cpp.

456 {
457  std::map<std::string, std::vector<double> > cgpmap;
458 
459  unsigned int k = 0;
460  for (std::vector<ModelParameter>::const_iterator it = ModParsVar.begin(); it < ModParsVar.end(); it++){
461 
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]);
466  else {
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");
470  }
471 
472  } else DPars_i[it->getname()] = parameters[k];
473  k++;
474  }
475 
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");
482  }
483 
484  std::vector<double> porig = CGP[j].getOrigParsValue(current);
485 
486  for(unsigned int l = 0; l < porig.size(); l++) {
487  DPars_i[CGP[j].getPar(l).getname()] = porig[l];
488  }
489  }
490 }
std::vector< CorrelatedGaussianParameters > CGP
vector for the Correlated Gaussian Parameters defined in SomeModel.conf.
std::vector< ModelParameter > ModParsVar
Vector for the model parameters varied in SomeModel.conf.
GenerateEvent::~GenerateEvent ( )
virtual

The default destructor.

Definition at line 46 of file GenerateEvent.cpp.

47 {
48 }

Variable Documentation

double** GenerateEvent::buff
private

Definition at line 150 of file GenerateEvent.h.

int** GenerateEvent::buff_int
private

Definition at line 153 of file GenerateEvent.h.

double** GenerateEvent::buff_w
private

Definition at line 151 of file GenerateEvent.h.

int GenerateEvent::buffersize
private

Definition at line 147 of file GenerateEvent.h.

std::vector<CorrelatedGaussianObservables> GenerateEvent::CGO
private

vector for the Correlated Gaussian Observables defined in SomeModel.conf.

Definition at line 125 of file GenerateEvent.h.

std::string GenerateEvent::CGODirName
private

String for the name of the Correlated Gaussian Observables output directory.

Definition at line 131 of file GenerateEvent.h.

std::map<std::string, boost::shared_ptr<std::ofstream> > GenerateEvent::CGOOut
private

Map of output stream for corellated Gaussian observables.

Definition at line 118 of file GenerateEvent.h.

std::vector<CorrelatedGaussianParameters> GenerateEvent::CGP
private

vector for the Correlated Gaussian Parameters defined in SomeModel.conf.

Definition at line 126 of file GenerateEvent.h.

std::map<std::string, TF1*> GenerateEvent::DDist
private

Map of parameter distributions.

Definition at line 116 of file GenerateEvent.h.

std::map<std::string, double> GenerateEvent::DPars
private

Map of parameters to be passed to Model().

Definition at line 115 of file GenerateEvent.h.

std::string GenerateEvent::JobTag
private

String for the optional JobTag argument to be passes to the executable.

Definition at line 135 of file GenerateEvent.h.

Model* GenerateEvent::Mod
private

Name of the model as defined in SomeModel.conf.

Definition at line 120 of file GenerateEvent.h.

std::string GenerateEvent::ModelConf
private

String for the name of the SomeModel.conf file.

Definition at line 127 of file GenerateEvent.h.

std::string GenerateEvent::ModelName
private

Definition at line 154 of file GenerateEvent.h.

std::vector<ModelParameter> GenerateEvent::ModPars
private

Vector for the model parameters defined in SomeModel.conf.

Definition at line 121 of file GenerateEvent.h.

std::vector<ModelParameter> GenerateEvent::ModParsVar
private

Vector for the model parameters varied in SomeModel.conf.

Definition at line 122 of file GenerateEvent.h.

InputParser GenerateEvent::myInputParser
private

An oject of the InputParser() class.

Definition at line 114 of file GenerateEvent.h.

int GenerateEvent::nIteration
private

Definition at line 145 of file GenerateEvent.h.

bool GenerateEvent::noMC
private

Flag to initiate noMC mode.

Definition at line 136 of file GenerateEvent.h.

boost::ptr_vector<Observable> GenerateEvent::Obs
private

Vector for the observables defined in SomeModel.conf.

Definition at line 123 of file GenerateEvent.h.

std::vector<Observable2D> GenerateEvent::Obs2D
private

Vector for the Observables2D defined in SomeModel.conf.

Definition at line 124 of file GenerateEvent.h.

std::string GenerateEvent::ObsDirName
private

String for the name of the observables output directory.

Definition at line 130 of file GenerateEvent.h.

std::map<std::string, boost::shared_ptr<std::ofstream> > GenerateEvent::ObsOut
private

Map of output stream for observables.

Definition at line 117 of file GenerateEvent.h.

std::string GenerateEvent::OldOutDirName
private

String for the name of the backup output directory.

Definition at line 129 of file GenerateEvent.h.

std::string GenerateEvent::OutDirName
private

String for the name of the output directory.

Definition at line 128 of file GenerateEvent.h.

bool GenerateEvent::outputTerm
private

Flag to specify output stream storage.

Definition at line 137 of file GenerateEvent.h.

std::string GenerateEvent::ParsDirName
private

String for the name of the parameters output directory.

Definition at line 134 of file GenerateEvent.h.

std::map<std::string, boost::shared_ptr<std::ofstream> > GenerateEvent::ParsOut
private

Map of output stream for parameters.

Definition at line 119 of file GenerateEvent.h.

int GenerateEvent::positionID
private

Definition at line 146 of file GenerateEvent.h.

int GenerateEvent::procnum
private

Definition at line 139 of file GenerateEvent.h.

int GenerateEvent::rank
private

Definition at line 138 of file GenerateEvent.h.

double* GenerateEvent::sendbuff
private

Definition at line 148 of file GenerateEvent.h.

int* GenerateEvent::sendbuff_int
private

Definition at line 152 of file GenerateEvent.h.

double* GenerateEvent::sendbuff_w
private

Definition at line 149 of file GenerateEvent.h.

std::string GenerateEvent::SMDebugDirName
private

String for the name of the observables output directory.

Definition at line 132 of file GenerateEvent.h.

std::ofstream GenerateEvent::summary
private

Definition at line 144 of file GenerateEvent.h.

std::string GenerateEvent::SUSYDebugDirName
private

String for the name of the Correlated Gaussian Observables output directory.

Definition at line 133 of file GenerateEvent.h.

bool GenerateEvent::weight
private

Definition at line 155 of file GenerateEvent.h.