static void getFallbackFontFamilies(SkTDArray<FontFamily*> &fallbackFonts) { SkTDArray<FontFamily*> vendorFonts; parseConfigFile(FALLBACK_FONTS_FILE, fallbackFonts); parseConfigFile(VENDOR_FONTS_FILE, vendorFonts); // This loop inserts the vendor fallback fonts in the correct order in the // overall fallbacks list. int currentOrder = -1; for (int i = 0; i < vendorFonts.count(); ++i) { FontFamily* family = vendorFonts[i]; int order = family->order; if (order < 0) { if (currentOrder < 0) { // Default case - just add it to the end of the fallback list *fallbackFonts.append() = family; } else { // no order specified on this font, but we're incrementing the order // based on an earlier order insertion request *fallbackFonts.insert(currentOrder++) = family; } } else { // Add the font into the fallback list in the specified order. Set // currentOrder for correct placement of other fonts in the vendor list. *fallbackFonts.insert(order) = family; currentOrder = order + 1; } } }
// commandline parser int main(int argc, char **argv) { int conffd; struct s_initconfig config; // default configuration strcpy(config.tapname,""); strcpy(config.ifconfig4,""); strcpy(config.ifconfig6,""); strcpy(config.upcmd,""); strcpy(config.sourceip,""); strcpy(config.sourceport,""); strcpy(config.userstr,""); strcpy(config.groupstr,""); strcpy(config.chrootstr,""); strcpy(config.networkname,"PEERVPN"); strcpy(config.initpeers,""); strcpy(config.engines,""); config.password_len = 0; config.enableeth = 0; config.enablerelay = 0; config.enableindirect = 0; config.enableconsole = 0; config.enableprivdrop = 1; config.enableipv4 = 1; config.enableipv6 = 1; config.sockmark = 0; setbuf(stdout,NULL); printf("PeerVPN v%d.%03d\n", PEERVPN_VERSION_MAJOR, PEERVPN_VERSION_MINOR); printf("(c)2012 Tobias Volk <*****@*****.**>\n"); printf("\n"); switch(argc) { case 2: if(strncmp(argv[1],"-",1) == 0) { conffd = STDIN_FILENO; parseConfigFile(conffd,&config); } else { if((conffd = (open(argv[1],O_RDONLY))) < 0) throwError("could not open config file!"); parseConfigFile(conffd,&config); close(conffd); } // start vpn node init(&config); break; default: printf("usage: %s <path_to_config_file>\n", argv[0]); exit(0); } return 0; }
void getTestFontFamilies(SkTDArray<FontFamily*> &fontFamilies, const char* testMainConfigFile, const char* testFallbackConfigFile) { parseConfigFile(testMainConfigFile, fontFamilies); SkTDArray<FontFamily*> fallbackFonts; parseConfigFile(testFallbackConfigFile, fallbackFonts); // Append all fallback fonts to system fonts for (int i = 0; i < fallbackFonts.count(); ++i) { *fontFamilies.append() = fallbackFonts[i]; } }
int main(void) { if (parseConfigFile("./libiotkit-comm/invalidconfig.json")) { puts("Success: Parsed Config File"); exit(EXIT_FAILURE); } else { puts("Failed: Parsing Config File"); exit(EXIT_SUCCESS); } }
int main(int argc, char **argv) { auto conf = "/Users/sma11case/Desktop/sma11case/code/Software/FileAlias/aria2/.aria2/aria2.conf"; auto json = parseConfigFile(conf); json->print(1, 1); return 0; }
void initConfig(char *cfgName) { if (parseConfigFile(cfgName, &psresportConfig, false /*trimQuotes*/) < 0) { mlog("%s: failed to open '%s'\n", __func__, cfgName); } traverseConfig(&psresportConfig, verifyVisitor, psresportConfDef); setConfigDefaults(&psresportConfig, psresportConfDef); }
void Options::parseOptions(int argc, char **argv) { namespace po = boost::program_options; /* support for -vv -vvvv etc. */ for (std::string s = "vv"; s.length() <= MAX_VERBOSE_LEVEL; s.append("v")) { m_hiddenOptions.add_options()(s.c_str(), "verbose"); } m_visibleOptions.add_options() ("help,h", "Produce help message") ("verbose,v", "Enable verbosity (optionally specify level, more v - more debug messages)") ("version,V", "Print version") ("config,c", po::value<std::string>()->default_value("/etc/boostcached"), "Setup custom config file") ("logFile,l", po::value<std::string>(), "Output log (used instead of stdout, can contain modifiers)") ; additionalOptions(); int style = (po::command_line_style::unix_style ^ po::command_line_style::allow_guessing) | po::command_line_style::allow_long_disguise; OptionsDescription allOptions; allOptions.add(m_hiddenOptions); allOptions.add(m_visibleOptions); po::store(po::command_line_parser(argc, argv) .style(style) .options(allOptions) .run(), m_variablesMap); std::string config = getValue<std::string>("config"); if (config.size()) { std::ifstream fileStream(config.c_str()); if (fileStream.is_open()) { std::stringstream stringStream; parseConfigFile(fileStream, stringStream); po::store(po::parse_config_file(stringStream, allOptions), m_variablesMap); fileStream.close(); } else if (!m_variablesMap["config"].defaulted()) { throw Exception("Could not read from config file"); } } po::notify(m_variablesMap); m_expandedOptions["logLevel"] = int(m_variablesMap.count("verbose") ? 1 : 0); for (std::string s = "vv"; s.length() <= MAX_VERBOSE_LEVEL; s.append("v")) { if (m_variablesMap.count(s)) { m_expandedOptions["logLevel"] = int(s.length()); } } }
void CConfigParser::parseDirectory() { #ifdef WIN32 HANDLE fHandle; WIN32_FIND_DATA wfd; fHandle = FindFirstFile("./Configuration/*.ini", &wfd); do { if (!((wfd.cFileName[0] == '.') && ((wfd.cFileName[1] == '.' && wfd.cFileName[2] == 0) || wfd.cFileName[1] == 0))) { if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { parseConfigFile(wfd.cFileName); } } } while (FindNextFile(fHandle,&wfd)); FindClose(fHandle); #else struct dirent *pDirEntry; DIR *pHandle = opendir("./Configuration/"); if (pHandle != NULL) { while ((pDirEntry = readdir(pHandle)) != NULL) { struct stat s; int ret = stat((string("./Configuration/") + pDirEntry->d_name).c_str(), &s); if (ret == 0 && !S_ISDIR(s.st_mode)) { const char *pShort = pDirEntry->d_name; size_t namelen = strlen(pShort); if (pShort[namelen - 4] == '.' && pShort[namelen - 3] == 'i' && pShort[namelen - 2] == 'n' && pShort[namelen - 1] == 'i' && pShort[namelen] == '\0') { parseConfigFile(pShort); } } } closedir(pHandle); } #endif }
int main(int argc, char** argv) { //Check if all nedeed arguments to parse are there if(argc != 2) { std::cerr << ">>>>> analysis.cpp::usage: " << argv[0] << " configFileName" << std::endl ; return 1; } // Parse the config file parseConfigFile (argv[1]) ; std::string treeName = gConfigParser -> readStringOption("Input::treeName"); std::string inputFileList = gConfigParser -> readStringOption("Input::inputFileList"); // Open old tree TChain* chain = new TChain(treeName.c_str()); if(!FillChain(*chain, inputFileList.c_str())) return 1; treeReader reader((TTree*)(chain)); // Open output root file for clone tree std::string outputRootFileName = "clone.root"; TFile outputRootFile(outputRootFileName.c_str(), "RECREATE"); outputRootFile.cd(); TTree* cloneTree = chain -> CloneTree(0); std::cout << ">>>>> cloneNtple.cpp::Read " << chain -> GetEntries() << " entries" << std::endl; for(int entry = 0 ; entry < chain -> GetEntries() ; ++entry) { reader.GetEntry(entry); if((entry%1000) == 0) std::cout << ">>>>> analysis::GetEntry " << entry << std::endl; if( (reader.Get4V("jets")->size()) >= 4 ) cloneTree -> Fill(); } // loop over the events cloneTree -> AutoSave(); outputRootFile.Close(); return 0; }
bool initConfig(char *cfgName) { if (parseConfigFile(cfgName, &config, false /* trimQuotes */) < 0) { mlog("%s: failed to open '%s'\n", __func__, cfgName); return false; } if (traverseConfig(&config, verifyVisitor, confDef)) { return false; } setConfigDefaults(&config, confDef); return true; }
bool parse(int argc, char** argv, const std::string& description) { try { // start with i = 1 since the first argument is the program name for (int i = 1; i < argc; ++i) { // convert c-string into std::string const std::string argument(argv[i]); if ('-' != argument[0]) AURORA_THROW(ECommandLineError, "Options must begin with '-'"); // remove the leading '-' std::string name = argument.substr(1, argument.length() - 1); if ("-help" == name) { OptionBase::help(description); return false; } ++i; if (i >= argc) { AURORA_THROW(ECommandLineError, "No value specified for \"" + name + "\""); } const std::string value = argv[i]; if ("configFile" == name) { parseConfigFile(value); continue; } OptionBase::parse(name, value); } } catch (const Exception& e) { OptionBase::help(description); throw e; } return true; }
int main() { std::fstream configFile("analysis_config.txt"); // std::string saturationFileName,analysisChoice; //std::string ChannelLabel[32]; // bool deepAnalysis = false; // saturationFileName = ""; // analysisChoice ="no"; //parse the config file parseConfigFile(configFile,Params); printConfigFile(Params); return 0; }
void TestbedConfigManager::selectTestsuites() { parseConfigFile(); if (_configFileInterface.hasKey("isSessionInteractive", "Global")) { Common::String in; _configFileInterface.getKey("isSessionInteractive", "Global", in); ConfParams.setSessionAsInteractive(stringToBool(in)); } if (!ConfParams.isSessionInteractive()) { // Non interactive sessions don't need to go beyond return; } // XXX: disabling these as of now for fastly testing other tests // Testsuite::isSessionInteractive = false; Common::String prompt("Welcome to the ScummVM testbed!\n" "It is a framework to test the various ScummVM subsystems namely GFX, Sound, FS, events etc.\n" "If you see this, it means interactive tests would run on this system :)\n"); if (!ConfParams.isGameDataFound()) { prompt += "\nSeems like Game data files are not configured properly.\n" "Create Game data files using script ./create-testbed-data.sh in dists/engine-data\n" "Next, Configure the game path in launcher / command-line.\n" "Currently a few testsuites namely FS/AudioCD/MIDI would be disabled\n"; } Testsuite::logPrintf("Info! : Interactive tests are also being executed.\n"); if (Testsuite::handleInteractiveInput(prompt, "Proceed?", "Customize", kOptionRight)) { if (Engine::shouldQuit()) { return; } // Select testsuites using checkboxes TestbedOptionsDialog tbd(_testsuiteList, this); tbd.runModal(); } // Clear it to remove entries before next rerun _configFileInterface.clear(); }
int main(int argc, char** argv) { setTDRStyle(); //Check if all nedeed arguments to parse are there if(argc != 2) { std::cerr << ">>>>> VBFPrintPlots::usage: " << argv[0] << " configFileName" << std::endl ; return 1; } // Parse the config file parseConfigFile (argv[1]) ; std::string inputDir = gConfigParser -> readStringOption("Input::inputDir"); std::string outputDir = gConfigParser -> readStringOption("Output::outputDir"); int step = gConfigParser -> readIntOption("Options::step"); float lumi = gConfigParser -> readFloatOption("Options::lumi"); // draw plots drawTStack* stack = new drawTStack(inputDir, "listOfSamplesAndCrossSections.txt", "VBFHiggsToWWTolnujjAnalysis", outputDir); stack -> DrawEvents("events", lumi, step, true); stack -> DrawEvents("eventsScaled", lumi, step, true); stack -> DrawEvents("efficiencies", lumi, step, true); stack -> DrawEvents("efficienciesRelative", lumi, step, true); stack -> DrawEvents("significance", lumi, step, true); }
/* * Class: com_choury_sproxy_SproxyVpnService * Method: start * Signature: (ILjava/lang/String;)V */ JNIEXPORT void JNICALL Java_com_choury_sproxy_SproxyVpnService_start (JNIEnv *jnienv, jobject obj, jint sockfd, jstring server, jstring secret) { jnienv->GetJavaVM(&jnijvm); jniobj = jnienv->NewGlobalRef(obj); std::string config_file = getExternalFilesDir() + "/sproxy.conf"; if(access(config_file.c_str(), R_OK) == 0){ LOG("read config from %s.\n", config_file.c_str()); parseConfigFile(config_file.c_str()); } LOG("native SproxyVpnService.start %d.\n", sockfd); const char *server_str = jnienv->GetStringUTFChars(server, nullptr); const char *secret_str = jnienv->GetStringUTFChars(secret, nullptr); opt.ignore_cert_error = 1; setproxy(server_str); Base64Encode(secret_str, strlen(secret_str), opt.rewrite_auth); jnienv->ReleaseStringUTFChars(server, server_str); jnienv->ReleaseStringUTFChars(secret, secret_str); jnienv->DeleteLocalRef(server); jnienv->DeleteLocalRef(secret); jclass cls = jnienv->GetObjectClass(jniobj); jmethodID mid = jnienv->GetMethodID(cls, "getMyVersion", "()Ljava/lang/String;"); jstring jversion = (jstring) jnienv->CallObjectMethod(jniobj, mid); const char *jversion_str = jnienv->GetStringUTFChars(jversion, nullptr); strcpy(version, jversion_str); jnienv->ReleaseStringUTFChars(jversion, jversion_str); jnienv->DeleteLocalRef(jversion); jnienv->DeleteLocalRef(cls); vpn_start(sockfd); extenalCacheDir.clear(); extenalFilesDir.clear(); jnienv->DeleteGlobalRef(jniobj); jniobj = nullptr; }
void loadConfigfile() { int len; FILE *file; char *filename; /* First try to load user configfile */ filename = USER_CONFIGFILE_NAME; fprintf(stderr, "Opening %s\n", filename); file = fopen(filename, "r"); if (file == NULL) { perror(USER_CONFIGFILE_ERROR); filename = SYSTEM_CONFIGFILE_NAME; fprintf(stderr, "Opening %s\n", filename); file = fopen(filename, "r"); if (file == NULL) { perror(SYSTEM_CONFIGFILE_ERROR); return; } } fprintf(stderr, "Parsing %s\n", filename); if (parseConfigFile(file) < 0) { perror("Could not parse configfile"); return; } }
Cp1616IOController::Cp1616IOController(std::string filepath) : cp_ready_(0), sem_mod_change_(0), cp_id_(1), cp_handle_(0), cp_current_mode_(PNIO_MODE_OFFLINE), cp_local_state_(PNIO_S_GOOD), input_module_count_(0), output_module_count_(0), input_module_total_data_size_(0), output_module_total_data_size_(0), num_of_input_modules_(0), num_of_output_modules_(0) { try { //Parse data from yaml config file parseConfigFile(filepath); } catch(int e) { ROS_ERROR("Not able to parse the yaml file"); throw; } //Allocate memory for Input module variables input_data_length_.resize(num_of_input_modules_); input_data_state_.resize(num_of_input_modules_); input_data_address_.resize(num_of_input_modules_); //Allocate memory for Output module variables output_data_length_.resize(num_of_output_modules_); output_data_state_.resize(num_of_output_modules_); output_data_address_.resize(num_of_output_modules_); }
int main(int argc, char **argv) { FdEventHandlerPtr listener; int i; int rc; int expire = 0, printConfig = 0; initAtoms(); CONFIG_VARIABLE(daemonise, CONFIG_BOOLEAN, "Run as a daemon"); CONFIG_VARIABLE(pidFile, CONFIG_ATOM, "File with pid of running daemon."); preinitChunks(); preinitLog(); preinitObject(); preinitIo(); preinitDns(); preinitServer(); preinitHttp(); preinitDiskcache(); preinitLocal(); preinitForbidden(); preinitSocks(); preinitOffline(); i = 1; while(i < argc) { if(argv[i][0] != '-') break; if(strcmp(argv[i], "--") == 0) { i++; break; } else if(strcmp(argv[i], "-h") == 0) { usage(argv[0]); exit(0); } else if(strcmp(argv[i], "-v") == 0) { printConfig = 1; i++; } else if(strcmp(argv[i], "-x") == 0) { expire = 1; i++; } else if(strcmp(argv[i], "-c") == 0) { i++; if(i >= argc) { usage(argv[0]); exit(1); } if(configFile) releaseAtom(configFile); configFile = internAtom(argv[i]); i++; } else { usage(argv[0]); exit(1); } } if(configFile) configFile = expandTilde(configFile); if(configFile == NULL) { configFile = expandTilde(internAtom("~/.polipo")); if(configFile) if(access(configFile->string, F_OK) < 0) { releaseAtom(configFile); configFile = NULL; } } if(configFile == NULL) { if(access("/etc/polipo/config", F_OK) >= 0) configFile = internAtom("/etc/polipo/config"); if(configFile && access(configFile->string, F_OK) < 0) { releaseAtom(configFile); configFile = NULL; } } rc = parseConfigFile(configFile); if(rc < 0) exit(1); while(i < argc) { rc = parseConfigLine(argv[i], "command line", 0, 0); if(rc < 0) exit(1); i++; } initChunks(); initLog(); initObject(); if(!expire && !printConfig) initEvents(); initIo(); initDns(); initHttp(); initServer(); initDiskcache(); initForbidden(); initSocks(); initOffline(); if(printConfig) { printConfigVariables(stdout, 0); exit(0); } if(expire) { expireDiskObjects(); exit(0); } if(daemonise) do_daemonise(logFile == NULL || logFile->length == 0); if(pidFile) writePid(pidFile->string); listener = create_listener(proxyAddress->string, proxyPort, httpAccept, NULL); if(!listener) { if(pidFile) unlink(pidFile->string); exit(1); } eventLoop(); if(pidFile) unlink(pidFile->string); return 0; }
int main(int argc, char** argv) { if(argc != 2) { std::cerr << ">>>>> analysis.cpp::usage: " << argv[0] << " configFileName MVAconfigFileName" << std::endl ; return 1; } // Parse the config file parseConfigFile (argv[1]) ; std::string treeName = gConfigParser -> readStringOption("Input::treeName"); std::string fileSamples = gConfigParser -> readStringOption("Input::fileSamples"); std::string inputDirectory = gConfigParser -> readStringOption("Input::inputDirectory"); std::string inputBeginningFile = "out_NtupleProducer_"; try { inputBeginningFile = gConfigParser -> readStringOption("Input::inputBeginningFile"); } catch (char const* exceptionString) { std::cerr << " exception = " << exceptionString << std::endl; } std::cout << ">>>>> Input::inputBeginningFile " << inputBeginningFile << std::endl; double LUMI = gConfigParser -> readDoubleOption("Options::Lumi"); std::vector<std::string> SignalName; SignalName = gConfigParser -> readStringListOption("Options::SignalName"); for (int iSignalSample=0; iSignalSample<SignalName.size(); iSignalSample++) { std::cout << " Signal[" << iSignalSample << "] = " << SignalName.at(iSignalSample) << std::endl; } std::string nameWeight = "1"; try { nameWeight = gConfigParser -> readStringOption("Options::nameWeight"); } catch (char const* exceptionString) { std::cerr << " exception = " << exceptionString << std::endl; } std::cout << ">>>>> Input::nameWeight " << nameWeight << std::endl; TTree *treeJetLepVect[200]; char *nameSample[1000]; char *nameHumanReadable[1000]; char* xsectionName[1000]; char nameFileIn[1000]; sprintf(nameFileIn,"%s",fileSamples.c_str()); int numberOfSamples = ReadFile(nameFileIn, nameSample, nameHumanReadable, xsectionName); double Normalization[1000]; double xsection[1000]; for (int iSample=0; iSample<numberOfSamples; iSample++) { xsection[iSample] = atof(xsectionName[iSample]); } for (int iSample=0; iSample<numberOfSamples; iSample++) { char nameFile[20000]; sprintf(nameFile,"%s/%s%s.root",inputDirectory.c_str(),inputBeginningFile.c_str(),nameSample[iSample]); TFile* f = new TFile(nameFile, "READ"); treeJetLepVect[iSample] = (TTree*) f->Get(treeName.c_str()); char nameTreeJetLep[100]; sprintf(nameTreeJetLep,"treeJetLep_%d",iSample); treeJetLepVect[iSample]->SetName(nameTreeJetLep); double XSection; XSection = xsection[iSample]; Normalization[iSample] = XSection * LUMI / 1000.; } //==== cut std::string CutFile = gConfigParser -> readStringOption("Selections::CutFile"); std::vector<std::string> vCut; std::cout << " nCuts = " << ReadFileCut(CutFile, vCut) << std::endl; std::string Cut; if (vCut.size() != 0) { Cut = vCut.at(0); } else { Cut = "1"; } //==== HiggsMass std::string HiggsMass = gConfigParser -> readStringOption("Options::HiggsMass"); //==== list of methods std::vector<std::string> vectorMyMethodList = gConfigParser -> readStringListOption("Options::MVAmethods"); TString myMethodList; for (int iMVA = 0; iMVA < vectorMyMethodList.size(); iMVA++) { if (iMVA == 0) myMethodList = Form ("%s",vectorMyMethodList.at(iMVA).c_str()); else myMethodList = Form ("%s,%s",myMethodList.Data(),vectorMyMethodList.at(iMVA).c_str()); } //==== output TString outfileName = gConfigParser -> readStringOption("Output::outFileName"); // This loads the library TMVA::Tools::Instance(); // Default MVA methods to be trained + tested std::map<std::string,int> Use; Use["MLP"] = 1; Use["BDTG"] = 1; Use["FDA_GA"] = 0; Use["PDEFoam"] = 0; std::cout << std::endl; std::cout << "==> Start TMVAClassification" << std::endl; // Select methods (don't look at this code - not of interest) if (myMethodList != "") { for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) it->second = 0; std::vector<TString> mlist = TMVA::gTools().SplitString( myMethodList, ',' ); for (UInt_t i=0; i<mlist.size(); i++) { std::string regMethod(mlist[i]); if (Use.find(regMethod) == Use.end()) { std::cout << "Method \"" << regMethod << "\" not known in TMVA under this name. Choose among the following:" << std::endl; for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) std::cout << it->first << " "; std::cout << std::endl; return 0; } Use[regMethod] = 1; } } // -------------------------------------------------------------------------------------------------- // --- Here the preparation phase begins // Create a new root output file TFile* outputFile = TFile::Open( outfileName, "RECREATE" ); // TMVA::Factory *factory = new TMVA::Factory( "TMVAMulticlass", outputFile, "AnalysisType=multiclass:!V:!Silent:!V:Transformations=I;D" ); TMVA::Factory *factory = new TMVA::Factory( "TMVAMulticlass", outputFile, "!V:!Silent:Color:DrawProgressBar:Transformations=I;D;P;G,D:AnalysisType=multiclass" ); factory->AddVariable( "jetpt1" , 'F'); factory->AddVariable( "jetpt2" , 'F'); factory->AddVariable( "mjj" , 'F'); factory->AddVariable( "detajj" , 'F'); factory->AddVariable( "dphilljetjet" , 'F'); factory->AddVariable( "pt1" , 'F'); factory->AddVariable( "pt2" , 'F'); factory->AddVariable( "mll" , 'F'); factory->AddVariable( "dphill" , 'F'); factory->AddVariable( "mth" , 'F'); factory->AddVariable( "dphillmet" , 'F'); factory->AddVariable( "mpmet" , 'F'); factory->AddSpectator( "channel" , 'F'); for (int iSample=0; iSample<numberOfSamples; iSample++) { int numEnt = treeJetLepVect[iSample]->GetEntries(Cut.c_str()); std::cout << " Sample = " << nameSample[iSample] << " ~ " << nameHumanReadable[iSample] << " --> " << numEnt << std::endl; if (numEnt != 0) { if (iSample == 0) factory->AddTree( treeJetLepVect[iSample], "Signal", Normalization[iSample] ); else if (iSample == 1) factory->AddTree( treeJetLepVect[iSample], "Background", Normalization[iSample] ); else factory->AddTree( treeJetLepVect[iSample], TString(nameHumanReadable[iSample]), Normalization[iSample] ); // factory->AddTree( treeJetLepVect[iSample], TString(nameHumanReadable[iSample]), Normalization[iSample] ); // factory->AddTree( treeJetLepVect[iSample], TString(nameHumanReadable[iSample]), Normalization[iSample] , nameWeight.c_str()); // factory->AddTree( treeJetLepVect[iSample], TString(nameHumanReadable[iSample])); } } // for (int iSample=0; iSample<numberOfSamples; iSample++){ // int numEnt = treeJetLepVect[iSample]->GetEntries(Cut.c_str()); // std::cout << " Sample = " << nameSample[iSample] << " ~ " << nameHumanReadable[iSample] << " --> " << numEnt << std::endl; // if (numEnt != 0) { // bool isSig = false; // for (std::vector<std::string>::const_iterator itSig = SignalName.begin(); itSig != SignalName.end(); itSig++){ // if (nameHumanReadable[iSample] == *itSig) isSig = true; // } // if (isSig) { // factory->AddTree( treeJetLepVect[iSample], TString("Signal"), Normalization[iSample] ); //---> ci deve essere uno chiamato Signal! // } // else { // factory->AddTree( treeJetLepVect[iSample], TString(nameHumanReadable[iSample]), Normalization[iSample] ); // } // } // } // // for (int iSample=0; iSample<numberOfSamples; iSample++){ // int numEnt = treeJetLepVect[iSample]->GetEntries(Cut.c_str()); // std::cout << " Sample = " << nameSample[iSample] << " ~ " << nameHumanReadable[iSample] << " --> " << numEnt << std::endl; // if (numEnt != 0) { // bool isSig = false; // for (std::vector<std::string>::const_iterator itSig = SignalName.begin(); itSig != SignalName.end(); itSig++){ // if (nameHumanReadable[iSample] == *itSig) isSig = true; // } // if (isSig) { // // factory->AddTree( treeJetLepVect[iSample], TString("Signal"), Normalization[iSample] ); //---> ci deve essere uno chiamato Signal! // } // else { // factory->AddTree( treeJetLepVect[iSample], TString(nameHumanReadable[iSample]), Normalization[iSample] ); // } // } // } std::cerr << " AAAAAAAAAAAAAAAAAAAAAAAAAAAAA " << std::endl; TCut mycuts = Cut.c_str(); // factory->SetWeightExpression( nameWeight.c_str() ); // factory->SetBackgroundWeightExpression( nameWeight.c_str() ); // factory->SetSignalWeightExpression ( nameWeight.c_str() ); std::cerr << " BBBBBBBBBBBBBBBBBBBBBBBBBBBBB " << std::endl; factory->PrepareTrainingAndTestTree( mycuts ,"SplitMode=Random:NormMode=None:!V"); // factory->PrepareTrainingAndTestTree( "" ,"SplitMode=Random:NormMode=None:!V"); std::cerr << " CCCCCCCCCCCCCCCCCCCCCCCCCCCCC " << std::endl; // gradient boosted decision trees // if (Use["BDTG"]) factory->BookMethod( TMVA::Types::kBDT, "BDTG", "!H:!V:NTrees=1000:BoostType=Grad:Shrinkage=0.10:UseBaggedGrad:GradBaggingFraction=0.50:nCuts=20:NNodesMax=8"); if (Use["BDTG"]) factory->BookMethod( TMVA::Types::kBDT, "BDTG", "!H:!V:NTrees=600:BoostType=Grad:Shrinkage=0.10:UseBaggedGrad:GradBaggingFraction=0.50:nCuts=20:NNodesMax=8"); // neural network if (Use["MLP"]) factory->BookMethod( TMVA::Types::kMLP, "MLP", "!H:!V:NeuronType=tanh:NCycles=1000:HiddenLayers=N+5,5:TestRate=5:EstimatorType=MSE"); // functional discriminant with GA minimizer if (Use["FDA_GA"]) factory->BookMethod( TMVA::Types::kFDA, "FDA_GA", "H:!V:Formula=(0)+(1)*x0+(2)*x1+(3)*x2+(4)*x3:ParRanges=(-1,1);(-10,10);(-10,10);(-10,10);(-10,10):FitMethod=GA:PopSize=300:Cycles=3:Steps=20:Trim=True:SaveBestGen=1" ); // PDE-Foam approach if (Use["PDEFoam"]) factory->BookMethod( TMVA::Types::kPDEFoam, "PDEFoam", "!H:!V:TailCut=0.001:VolFrac=0.0666:nActiveCells=500:nSampl=2000:nBin=5:Nmin=100:Kernel=None:Compress=T" ); //==== Optimize parameters in MVA methods // factory->OptimizeAllMethods(); // factory->OptimizeAllMethods("ROCIntegral","Scan"); //==== Train MVAs using the set of training events ==== factory->TrainAllMethods(); //==== Evaluate all MVAs using the set of test events ==== factory->TestAllMethods(); //==== Evaluate and compare performance of all configured MVAs ==== factory->EvaluateAllMethods(); // -------------------------------------------------------------- // Save the output outputFile->Close(); std::cout << "==> Wrote root file: " << outputFile->GetName() << std::endl; std::cout << "==> TMVAnalysis is done!" << std::endl; delete factory; //==== change position of weights file std::string toDo; toDo = "rm -r Weights-MVA-MultiClass/weights_" + HiggsMass + "_testVariables"; std::cerr << "toDo = " << toDo << std::endl; system (toDo.c_str()); toDo = "mv weights Weights-MVA-MultiClass/weights_" + HiggsMass + "_testVariables"; std::cerr << "toDo = " << toDo << std::endl; system (toDo.c_str()); // Launch the GUI for the root macros // if (!gROOT->IsBatch()) TMVAGui( outfileName ); }
static void getThemeFontFamilies(SkTDArray<FontFamily*> &fontFamilies) { parseConfigFile(THEME_FONTS_FILE, fontFamilies); }
void parseArgs(chpl_bool isLauncher, chpl_parseArgsMode_t mode, int* argc, char* argv[]) { int i; int printHelp = 0; int printAbout = 0; int origargc = *argc; int stop_parsing = 0; // // Handle the pre-parse for '-E' arguments separately. // if (mode == parse_dash_E) { assert(!isLauncher); parseDashEArgs(argc, argv); return; } for (i = 1; i < *argc; i++) { const char* filename = "<command-line arg>"; int lineno = i + (origargc - *argc); int argLength = 0; const char* currentArg = argv[i]; argLength = strlen(currentArg); if (mainHasArgs && (stop_parsing || argLength < 2)) { /* update the argv structure passed to a Chapel program, but don't parse * the arguments */ chpl_gen_main_arg.argv[chpl_gen_main_arg.argc] = argv[i]; chpl_gen_main_arg.argc++; continue; } /* if the Chapel main takes arguments, then "--" is a magic argument that * will prevent parsing of any additional arguments */ if (mainHasArgs && strcmp(currentArg, "--") == 0) { stop_parsing = 1; continue; } if (argLength < 2) { const char* message = chpl_glom_strings(3, "\"", currentArg, "\" is not a valid argument"); chpl_error(message, lineno, filename); } switch (currentArg[0]) { case '-': switch (currentArg[1]) { case '-': { const char* flag = currentArg + 2; if (strcmp(flag, "gdb") == 0) { gdbFlag = i; break; } if (strcmp(flag, "help") == 0) { printHelp = 1; chpl_gen_main_arg.argv[chpl_gen_main_arg.argc] = "--help"; chpl_gen_main_arg.argc++; break; } if (strcmp(flag, "about") == 0) { printAbout = 1; break; } if (strcmp(flag, "verbose") == 0) { verbosity=2; break; } if (strcmp(flag, "blockreport") == 0) { blockreport = 1; break; } if (strcmp(flag, "taskreport") == 0) { taskreport = 1; break; } if (strcmp(flag, "quiet") == 0) { verbosity = 0; break; } if (argLength < 3) { char* message = chpl_glom_strings(3, "\"", currentArg, "\" is not a valid argument"); chpl_error(message, lineno, filename); } i += handlePossibleConfigVar(argc, argv, i, lineno, filename); break; } case 'a': if (currentArg[2] == '\0') { printAbout = 1; } else { i += handleNonstandardArg(argc, argv, i, lineno, filename); } break; case 'b': if (currentArg[2] == '\0') { blockreport = 1; } else { i += handleNonstandardArg(argc, argv, i, lineno, filename); } break; case 'E': if (isLauncher) { i += handleNonstandardArg(argc, argv, i, lineno, filename); } else { // // We parse -E only in parse_dash_E mode, which is handled above. // if (currentArg[2] == '\0') { i++; } } break; case 'f': if (currentArg[2] == '\0') { i++; if (i >= *argc) { chpl_error("-f flag is missing <filename> argument", lineno, filename); } currentArg = argv[i]; parseConfigFile(currentArg, lineno, filename); } else { parseConfigFile(currentArg + 2, lineno, filename); } break; case 'h': if (currentArg[2] == '\0') { printHelp = 1; chpl_gen_main_arg.argv[chpl_gen_main_arg.argc] = "-h"; chpl_gen_main_arg.argc++; } else { i += handleNonstandardArg(argc, argv, i, lineno, filename); } break; case 'n': if (currentArg[2] == 'l') { const char* numPtr; if (currentArg[3] == '\0') { i++; if (i >= *argc) { chpl_error("-nl flag is missing <numLocales> argument", lineno, filename); } currentArg = argv[i]; numPtr = currentArg; } else { numPtr = &(currentArg[3]); } initSetValue("numLocales", numPtr, "Built-in", lineno, filename); break; } i += handleNonstandardArg(argc, argv, i, lineno, filename); break; case 'q': if (currentArg[2] == '\0') { verbosity = 0; } else { i += handleNonstandardArg(argc, argv, i, lineno, filename); } break; case 's': { if (argLength < 3) { char* message = chpl_glom_strings(3, "\"", currentArg, "\" is not a valid argument"); chpl_error(message, lineno, filename); } i += handlePossibleConfigVar(argc, argv, i, lineno, filename); break; } case 't': if (currentArg[2] == '\0') { taskreport = 1; } else { i += handleNonstandardArg(argc, argv, i, lineno, filename); } break; case 'v': if (currentArg[2] == '\0') { verbosity = 2; } else { i += handleNonstandardArg(argc, argv, i, lineno, filename); } break; default: i += handleNonstandardArg(argc, argv, i, lineno, filename); break; } break; default: i += handleNonstandardArg(argc, argv, i, lineno, filename); break; } } if (printAbout) { chpl_program_about(); chpl_exit_any(0); } if (printHelp) { if (!mainHasArgs) { printHelpTable(); printConfigVarTable(); chpl_exit_any(0); } } }
static void getSystemFontFamilies(SkTDArray<FontFamily*> &fontFamilies) { parseConfigFile(SYSTEM_FONTS_FILE, fontFamilies); }
int main(int argc, char** argv) { TDRStyle(); gStyle->SetPadTopMargin(0.11); gStyle->SetPadLeftMargin(0.07); gStyle->SetPadRightMargin(0.23); gStyle->cd(); std::cout << " " << std::endl; std::cout << " " << std::endl; std::cout << " ___| | \\ | ___| / __ \\ \\ __ __| \\ " << std::endl; std::cout << " | _ \\ | | __ \\ __| _ \\ __| |\\/ | | / | | _ \\ | _ \\ " << std::endl; std::cout << " | ( | | | | | | __/ | | | | / | | ___ \\ | ___ \\ " << std::endl; std::cout << " \\____| \\___/ \\__,_| _| _| \\__| \\___| _| _| _| \\____| _/ ____/ _/ _\\ _| _/ _\\ " << std::endl; std::cout << " " << std::endl; std::cout << " " << std::endl; std::cout << " " << std::endl; std::cout << " ___| | | _) " << std::endl; std::cout << " \\___ \\ | | __| __| _ \\ __ `__ \\ _` | __| | __| __| " << std::endl; std::cout << " | | | \\__ \\ | __/ | | | ( | | | ( \\__ \\ " << std::endl; std::cout << " _____/ \\__, | ____/ \\__| \\___| _| _| _| \\__,_| \\__| _| \\___| ____/ " << std::endl; std::cout << " ____/ " << std::endl; std::cout << " " << std::endl; std::cout << " " << std::endl; char normal[] = { 0x1b, '[', '0', ';', '3', '9', 'm', 0 }; char black[] = { 0x1b, '[', '0', ';', '3', '0', 'm', 0 }; char red[] = { 0x1b, '[', '0', ';', '3', '1', 'm', 0 }; char green[] = { 0x1b, '[', '0', ';', '3', '2', 'm', 0 }; char yellow[] = { 0x1b, '[', '0', ';', '3', '3', 'm', 0 }; char blue[] = { 0x1b, '[', '0', ';', '3', '4', 'm', 0 }; char purple[] = { 0x1b, '[', '0', ';', '3', '5', 'm', 0 }; char cyan[] = { 0x1b, '[', '0', ';', '3', '6', 'm', 0 }; char Lgray[] = { 0x1b, '[', '0', ';', '3', '7', 'm', 0 }; char Dgray[] = { 0x1b, '[', '0', ';', '3', '8', 'm', 0 }; char Bred[] = { 0x1b, '[', '1', ';', '3', '1', 'm', 0 }; //for bold colors, just change the 0 after the [ to a 1 EColor vColor[1000] = { kGreen, //kMagenta,(EColor) (kMagenta+1),(EColor) (kMagenta+2), kTeal,//(EColor) (kTeal+1), kRed, kGray, kOrange,(EColor) (kOrange+1), kBlue,//(EColor)(kBlue+1),(EColor) (kBlue+2), (EColor) (kPink+2),//(EColor) (kPink+1),(EColor) (kPink+2), kViolet, kYellow, kGray,(EColor) (kGray+1),(EColor) (kViolet),(EColor) (kYellow),(EColor) (kGray) }; //Check if all nedeed arguments to parse are there if(argc != 2) { std::cerr << ">>>>> analysis.cpp::usage: " << argv[0] << " configFileName" << std::endl ; return 1; } // Parse the config file parseConfigFile (argv[1]) ; std::string treeName = gConfigParser -> readStringOption("Input::treeName"); std::string treeNameSelections = gConfigParser -> readStringOption("Input::treeNameSelections"); std::string fileSamples = gConfigParser -> readStringOption("Input::fileSamples"); std::string inputDirectory = gConfigParser -> readStringOption("Input::inputDirectory"); double LUMI = gConfigParser -> readDoubleOption("Input::Lumi"); double LumiSyst = gConfigParser -> readDoubleOption("Input::LumiSyst"); double Discovery = gConfigParser -> readDoubleOption("Input::Discovery"); std::vector<std::string> SignalName; SignalName = gConfigParser -> readStringListOption("Input::SignalName"); ///==== PU reweight (begin) ==== std::vector<double> PUMC = gConfigParser -> readDoubleListOption("PU::PUMC"); std::vector<double> PUDATA = gConfigParser -> readDoubleListOption("PU::PUDATA"); PUclass PU; std::cout << " PUMC.size() = " << PUMC.size() << std::endl; std::cout << " PUDATA.size() = " << PUDATA.size() << std::endl; if (PUMC.size() != PUDATA.size()) { std::cerr << " ERROR " << std::endl; return 1; } double sumPUMC = 0; for (int itVPU = 0; itVPU < PUMC.size(); itVPU++ ){ sumPUMC += PUMC.at(itVPU); } double sumPUDATA = 0; for (int itVPU = 0; itVPU < PUDATA.size(); itVPU++ ){ sumPUDATA += PUDATA.at(itVPU); } for (int itVPU = 0; itVPU < PUMC.size(); itVPU++ ){ PU.PUWeight.push_back(PUDATA.at(itVPU) / PUMC.at(itVPU) * sumPUMC / sumPUDATA); } PU.Write("autoWeight.cxx"); gROOT->ProcessLine(".L autoWeight.cxx"); ///==== PU reweight (end) ==== ///==== save PU distribution in TH1F ==== TH1F* hPUMC = new TH1F("hPUMC","hPUMC",PUMC.size(),0,PUMC.size()); TH1F* hPUDATA = new TH1F("hPUDATA","hPUDATA",PUDATA.size(),0,PUDATA.size()); TH1F* hPUWeight = new TH1F("hPUWeight","hPUWeight",PUDATA.size(),0,PUDATA.size()); for (int itVPU = 0; itVPU < PUMC.size(); itVPU++ ){ hPUMC -> SetBinContent(itVPU+1,PUMC.at(itVPU) / sumPUMC); hPUDATA -> SetBinContent(itVPU+1,PUDATA.at(itVPU) / sumPUDATA); hPUWeight -> SetBinContent(itVPU+1,PUDATA.at(itVPU) / PUMC.at(itVPU) * sumPUMC / sumPUDATA); } TTree *treeEffVect[100]; TTree *treeJetLepVect[100]; // [iCut] TString* infoString[20]; TLatex *infoLatex[20]; TCanvas* ccCanvas[20]; TCanvas* ccCanvasPull[20]; TH1F* histoSumMC[20]; // [iName][iCut] TH1F* histo[100][20]; TH1F* histo_temp[100][20]; // [iName][iCut] double numEvents[100][20]; char *nameSample[1000]; char *nameHumanReadable[1000]; char* xsectionName[1000]; double Normalization[1000]; double xsection[1000]; char nameFileIn[1000]; sprintf(nameFileIn,"%s",fileSamples.c_str()); int numberOfSamples = ReadFile(nameFileIn, nameSample, nameHumanReadable, xsectionName); double XSection = gConfigParser -> readDoubleOption("Plot::XSection"); ///==== list of selections to perform (NOT sequential additive selections) ==== std::string CutFile = gConfigParser -> readStringOption("Selections::CutFile"); std::vector<std::string> vCut; std::cout << " nCuts = " << ReadFileCut(CutFile, vCut) << std::endl; ///==== list of systematic variables to change ==== // std::string CutSystematicFile = gConfigParser -> readfStringOption("Selections::CutSystematicFile"); // // std::vector< std::pair< int, std::pair<std::string, double> > > listSystematics; // ReadFileSystematics(CutSystematicFile, listSystematics); // ModifyCut(vCut,listSystematics); std::string CutSystematicFile = gConfigParser -> readStringOption("Selections::CutSystematicFile"); std::vector< std::pair< std::string, std::string> > listSystematics; ReadFileSystematicsWithRegion(CutSystematicFile, listSystematics); ModifyCutWithRegion(vCut,listSystematics); ///==== something to load/exec ==== try { std::string toLoad = gConfigParser -> readStringOption("Exec::ToLoad"); std::string toExec = ".L "; toExec += toLoad; toExec += ".cxx"; gROOT->ProcessLine(toExec.c_str()); std::cout << std::endl; std::cout << " load: " << toLoad.c_str() << std::endl; std::cout << " do: " << toExec.c_str() << std::endl; std::cout << std::endl; } catch (char const* exceptionString){ std::cerr << " exception = " << exceptionString << std::endl; } ///==== output file ==== std::string OutFileName = gConfigParser -> readStringOption("Output::outFileName"); std::cout << ">>>>> Output::outFileName " << OutFileName << std::endl; TFile outFile(OutFileName.c_str(),"RECREATE"); outFile.cd(); ///==== debug flag ==== bool debug = false; try { debug = gConfigParser -> readBoolOption("Input::debug"); } catch (char const* exceptionString){ std::cerr << " exception = " << exceptionString << std::endl; } std::cout << ">>>>> input::debug " << debug << std::endl; ///==== program ==== double start, end; start = clock(); for (int iSample=0; iSample<numberOfSamples; iSample++){ xsection[iSample] = atof(xsectionName[iSample]); } for (int iSample=0; iSample<numberOfSamples; iSample++){ char nameFile[20000]; sprintf(nameFile,"%s/out_NtupleProducer_%s.root",inputDirectory.c_str(),nameSample[iSample]); TFile* f = new TFile(nameFile, "READ"); treeEffVect[iSample] = (TTree*) f->Get(treeNameSelections.c_str()); char nameTreeEff[100]; sprintf(nameTreeEff,"treeEff_%d",iSample); treeEffVect[iSample]->SetName(nameTreeEff); treeJetLepVect[iSample] = (TTree*) f->Get(treeName.c_str()); char nameTreeJetLep[100]; sprintf(nameTreeJetLep,"treeJetLep_%d",iSample); treeJetLepVect[iSample]->SetName(nameTreeJetLep); } ///===== create map for joint sample ==== std::vector<int> join_samples; std::vector<std::string> name_samples; for (int iSample=0; iSample<numberOfSamples; iSample++){ name_samples.push_back(nameHumanReadable[iSample]); join_samples.push_back(-1); } std::vector<std::string> reduced_name_samples; std::vector<int> reduced_name_samples_flag; for (int iSample = (numberOfSamples-1); iSample>= 0; iSample--){ bool flag_name = false; for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){ if (reduced_name_samples.at(iName) == name_samples.at(iSample)) flag_name = true; } if (flag_name == false) { reduced_name_samples.push_back(name_samples.at(iSample)); reduced_name_samples_flag.push_back(-1); } } std::cout << " numberOfSamples = " << numberOfSamples << std::endl; for (int iSample = (numberOfSamples-1); iSample>= 0; iSample--){ double XSection; int numEntriesBefore; double preselection_efficiency; treeEffVect[iSample]->SetBranchAddress("XSection",&XSection); treeEffVect[iSample]->SetBranchAddress("numEntriesBefore",&numEntriesBefore); treeEffVect[iSample]->SetBranchAddress("preselection_efficiency",&preselection_efficiency); treeEffVect[iSample]->GetEntry(0); std::cout << " Xsection = " << XSection << " ~~~> " << xsection[iSample] << std::endl; XSection = xsection[iSample]; if (numEntriesBefore != 0) { Normalization[iSample] = LUMI * XSection * preselection_efficiency / numEntriesBefore; } else { Normalization[iSample] = 0; } } TLegend* leg = new TLegend(0.8,0.25,0.98,0.78); bool LegendBuilt = false; TString lumiName = Form("#splitline{L = %.1f pb^{-1}}{#splitline{#sqrt{s} = 7}{CMS preliminary}}", LUMI); // TString lumiName = Form("#sqrt{s}=7 TeV L=%.1f pb^{-1}", LUMI); TLatex *latex = new TLatex(0.80, 0.90, lumiName); latex->SetTextAlign(12); latex->SetNDC(); latex->SetTextFont(42); latex->SetTextSize(0.03); ///==== get number in sample list that correspond to DATA ==== int numDATA = -1; for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){ if (reduced_name_samples.at(iName) == "DATA") { numDATA = iName; } } if (debug) std::cout << " Cut size = " << vCut.size() << " ~~ " << std::endl; std::cout.precision (2) ; std::cout.unsetf(std::ios::scientific); ///==== cicle on selections ==== for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){ TString Cut = Form ("%s",vCut.at(iCut).c_str()); if (debug) std::cout << " Cut[" << iCut << ":" << vCut.size() << "] = " << Cut.Data() << " ~~ " << std::endl; ///==== initialize ==== for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){ reduced_name_samples_flag.at(iName) = -1; } ///==== cicle on samples ==== for (int iSample = (numberOfSamples-1); iSample>= 0; iSample--){ if (debug) std::cout << " Sample[" << iSample << ":" << numberOfSamples << "] = " << nameSample[iSample] << " ~~ " << std::endl; TString name_histo_temp = Form("%s_%d_temp",nameSample[iSample], iCut); histo_temp[iSample][iCut] = new TH1F(name_histo_temp,name_histo_temp,100,-10,10000000000); char toDraw[1000]; sprintf(toDraw,"eventId >> %s",name_histo_temp.Data()); histo_temp[iSample][iCut] -> Sumw2(); //---- così mette l'errore giusto! TString CutExtended; bool isData = false; for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){ if (name_samples.at(iSample) == reduced_name_samples.at(iName)){ if (iName == numDATA) { isData = true; } } } if (!isData) { CutExtended = Form ("(%s) * autoWeight(numPUMC)",Cut.Data()); } else { CutExtended = Form ("(%s)",Cut.Data()); } if (debug) std::cerr << " drawing ..." << std::endl; treeJetLepVect[iSample]->Draw(toDraw,CutExtended,""); if (debug) std::cerr << " drawn ..." << std::endl; if (Normalization[iSample]>0) { histo_temp[iSample][iCut] -> Scale(Normalization[iSample]); } for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){ if (name_samples.at(iSample) == reduced_name_samples.at(iName)){ if (reduced_name_samples_flag.at(iName) == -1){ TString name_histoTot_temp = Form("%s_%d_Tot_temp",reduced_name_samples.at(iName).c_str(),iCut); TString name_HR_histoTot_temp = Form("cut %d",iCut); histo[iName][iCut] = new TH1F(name_histoTot_temp,name_HR_histoTot_temp,100,-10,10000000000); histo[iName][iCut] -> Sumw2(); //---- così mette l'errore giusto! reduced_name_samples_flag.at(iName) = 1; } histo[iName][iCut] -> Add(histo_temp[iSample][iCut]); } } std::cout << "Processing: " << blue << (((double) iCut)/vCut.size())*100. << "% " << normal << " -- " << red << (((double) numberOfSamples - iSample)/(numberOfSamples))*100. << "% \r" << normal << std::flush; } ///==== end cicle on samples ==== // std::cout << "Processing: " << blue << (((double) iCut)/vCut.size())*100. << "% \r" << normal << std::flush; } ///==== end cicle on selections ==== // [iName] TH1F* hTrend[100]; THStack* hsTrend; // [iCut] TPie* hTrendPie[100]; // [iCut] THStack* hs[100]; std::cout << std::endl; ///==== cicle on selections ==== for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){ TString nameStack = Form("%d_stack",iCut); hs[iCut] = new THStack(nameStack,nameStack); for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){ histo[iName][iCut]->GetXaxis()->SetTitle("eventId"); histo[iName][iCut]->SetMarkerColor(vColor[iName]); histo[iName][iCut]->SetLineColor(vColor[iName]); histo[iName][iCut]->SetFillColor(vColor[iName]); histo[iName][iCut]->SetLineWidth(2); histo[iName][iCut]->SetFillStyle(3001); bool isSig = false; for (std::vector<std::string>::const_iterator itSig = SignalName.begin(); itSig != SignalName.end(); itSig++){ if (reduced_name_samples.at(iName) == *itSig) isSig = true; } if (!isSig && reduced_name_samples.at(iName) != "DATA") { hs[iCut]->Add(histo[iName][iCut]); } else { if (!isSig) { histo[iName][iCut]->SetMarkerStyle(20); histo[iName][iCut]->SetMarkerSize(1); histo[iName][iCut]->SetMarkerColor(kBlack); histo[iName][iCut]->SetLineColor(kBlack); histo[iName][iCut]->SetFillColor(kBlack); histo[iName][iCut]->SetLineWidth(2); histo[iName][iCut]->SetFillStyle(3001); } else { histo[iName][iCut]->SetMarkerStyle(21); histo[iName][iCut]->SetMarkerSize(1); histo[iName][iCut]->SetLineWidth(2); histo[iName][iCut]->SetFillStyle(3001); } } } ///==== histo sum MC ==== ///==== Add systrematic error ==== AddError(hs[iCut],LumiSyst); histoSumMC[iCut] = ((TH1F*)(hs[iCut]->GetStack()->Last())); std::cout << " MC / DATA[" << iCut << "] = "<< histoSumMC[iCut]->Integral() << " / " << histo[numDATA][iCut]->Integral() << " = " << (histo[numDATA][iCut]->Integral() ? histoSumMC[iCut]->Integral()/ histo[numDATA][iCut]->Integral() : 0) << std::endl; ///==== legend ==== if (!LegendBuilt){ for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){ leg->AddEntry(histo[iName][iCut],reduced_name_samples.at(iName).c_str(),"pf"); LegendBuilt = true; } } } std::cout << std::endl << std::endl; ///==== calculate number of events after each step of the analysis ==== // [iName][iCut] hsTrend = new THStack("Trend","Trend"); for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){ TString nameTHTrendPie = Form("%d_Trend_Pie",iCut); hTrendPie[iCut] = new TPie (nameTHTrendPie,nameTHTrendPie,reduced_name_samples.size()); } for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){ TString nameTHTrend = Form("%s_Trend",reduced_name_samples.at(iName).c_str()); hTrend[iName] = new TH1F (nameTHTrend,nameTHTrend,vCut.size()+1,0,vCut.size()+1); hTrend[iName]->GetXaxis()->SetTitle("Selections"); if (iName == numDATA) { hTrend[iName]->SetMarkerStyle(20); hTrend[iName]->SetMarkerSize(1); hTrend[iName]->SetMarkerColor(kBlack); hTrend[iName]->SetLineColor(kBlack); hTrend[iName]->SetFillColor(kBlack); hTrend[iName]->SetLineWidth(2); hTrend[iName]->SetFillStyle(3001); } else { hTrend[iName]->SetMarkerColor(vColor[iName]); hTrend[iName]->SetLineColor(vColor[iName]); hTrend[iName]->SetFillColor(vColor[iName]); hTrend[iName]->SetLineWidth(2); hTrend[iName]->SetFillStyle(3001); } for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){ double error = 0; numEvents[iName][iCut] = histo[iName][iCut]->IntegralAndError(0,histo[iName][iCut]->GetNbinsX()+1,error); hTrend[iName]->SetBinContent(iCut+1,numEvents[iName][iCut]); hTrend[iName]->SetBinError(iCut+1,error); TString nameBin = Form("%d",iCut); hTrend[iName]->GetXaxis()->SetBinLabel(iCut+1,nameBin); // IntegralAndError // Double_t IntegralAndError(Int_t binx1, Int_t binx2, Double_t& err, Option_t* option = "") const std::cout << ">>> numEvents[" << iName << "," << reduced_name_samples.at(iName) << "][" << iCut << "] = " << numEvents[iName][iCut] << " , " << histo[iName][iCut]->GetEntries() << " , " << histo[iName][iCut]->GetEffectiveEntries() << std::endl; if (iName != numDATA) { hTrendPie[iCut]->SetTextSize(0.04); hTrendPie[iCut]->SetTextFont(12); hTrendPie[iCut]->SetEntryFillColor(iName,vColor[iName]); hTrendPie[iCut]->SetEntryFillStyle(iName,3001); hTrendPie[iCut]->SetEntryLabel(iName, reduced_name_samples.at(iName).c_str()); hTrendPie[iCut]->SetEntryLineColor(iName, vColor[iName]); hTrendPie[iCut]->SetEntryLineStyle(iName, 2); hTrendPie[iCut]->SetEntryLineWidth(iName, 2); hTrendPie[iCut]->SetEntryRadiusOffset(iName, 0.01); hTrendPie[iCut]->SetEntryVal(iName,numEvents[iName][iCut]); } else { hTrendPie[iCut]->SetEntryLabel(iName, ""); } } if (iName != numDATA) { hsTrend->Add(hTrend[iName]); } } AddError(hsTrend,LumiSyst); TH1F* hTrendSumMC = ((TH1F*)(hsTrend->GetStack()->Last())); ///==== hTrend with pull plot ==== TH1F* hPullTrendSumMC = PullPlot(hTrend[numDATA], hTrendSumMC); LumiSyst = 0; ///---- bug fix TCanvas* cTrendPie[100]; TCanvas* cTrendPieAll = new TCanvas("cTrendPieAll","cTrendPieAll",400 * vCut.size(),400); cTrendPieAll -> Divide (vCut.size()); TCanvas* cTrend = new TCanvas("cTrend","cTrend",400,400); TCanvas* cTrendSample[100]; for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){ TString nameCanvas = Form("%d_Canvas_Sample",iName); cTrendSample[iName] = new TCanvas(nameCanvas,nameCanvas,400,400); hTrend[iName] -> Draw(); gPad->SetLogy(); gPad->SetGrid(); } ///~~~~ for efficiency calculation ~~~~ std::vector<double> numEntriesFirstStep_reduced_samples; for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){ numEntriesFirstStep_reduced_samples.push_back(0); for (int iSample = (numberOfSamples-1); iSample>= 0; iSample--){ if (name_samples.at(iSample) == reduced_name_samples.at(iName)){ // numEntriesFirstStep_reduced_samples.at(iName) += (Normalization[iSample] ? (1. / Normalization[iSample] * LUMI * xsection[iSample] * LUMI * xsection[iSample]) : -1); numEntriesFirstStep_reduced_samples.at(iName) += (xsection[iSample] * LUMI); } } } // Normalization[iSample] = LUMI * XSection * preselection_efficiency / numEntriesBefore; // 1. / Normalization[iSample] = numEntriesBefore / preselection_efficiency / LUMI / XSection; // 1. / Normalization[iSample] * LUMI * xsection[iSample] = numEntriesBefore / preselection_efficiency; // 1. / Normalization[iSample] * LUMI * xsection[iSample] * LUMI * xsection[iSample] = numEntriesBefore / preselection_efficiency * LUMI * xsection[iSample]; for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){ std::cout << "[" << reduced_name_samples.at(iName) << "] = " << numEntriesFirstStep_reduced_samples.at(iName) << std::endl; } std::cout.precision (2) ; std::cout.unsetf(std::ios::scientific); std::cout << std::endl; std::cout << std::endl; std::cout << std::endl; std::cout << std::endl; std::cout << std::endl; std::cout << " *********************************** " << std::endl; std::cout << std::setw (12) << "sample"; std::cout << " | " << std::setw (8) << -1; std::cout << " [" << std::setw (8) << "XXX"; std::cout << " ]"; for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){ std::cout << " | " << std::setw (8) << iCut; std::cout << " [" << std::setw (8) << "XXX"; std::cout << " ]"; } std::cout << std::endl; for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){ std::cout << std::setw (12) << reduced_name_samples.at(iName) ; std::cout << " | " << cyan << std::setw (8) << numEntriesFirstStep_reduced_samples.at(iName); std::cout << normal << " [" << std::setw (8) << "XXX"; std::cout << " ]"; for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){ std::cout << " | " << blue << std::setw (8) << hTrend[iName]->GetBinContent(iCut+1); std::cout << normal << " [" << std::setw (8) << hTrend[iName]->GetBinError(iCut+1); std::cout << " ]"; } std::cout << std::endl; } std::cout << std::endl; std::cout << " *********************************** " << std::endl; for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){ std::cout << " | " << std::setw (8) << reduced_name_samples.at(iName) ; std::cout << " [" << std::setw (8) << "err"; std::cout << " ]"; } std::cout << std::endl; for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){ std::cout << " | " << cyan << std::setw (8) << numEntriesFirstStep_reduced_samples.at(iName); std::cout << normal << " [" << std::setw (8) << "XXX"; std::cout << " ]"; } std::cout << std::endl; for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){ for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){ std::cout << " | " << blue << std::setw (8) << hTrend[iName]->GetBinContent(iCut+1); std::cout << normal << " [" << std::setw (8) << hTrend[iName]->GetBinError(iCut+1); std::cout << " ]"; } std::cout << std::endl; } std::cout << std::endl; std::cout << std::endl; std::cout << std::endl; std::cout << " *********************************** " << std::endl; std::cout << " ************* 1 fb-1 ************* " << std::endl; std::cout << std::setw (12) << "sample"; std::cout << " | " << std::setw (8) << -1; std::cout << " [" << std::setw (8) << "XXX"; std::cout << " ]"; for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){ std::cout << " | " << std::setw (8) << iCut; std::cout << " [" << std::setw (8) << "XXX"; std::cout << " ]"; } std::cout << std::endl; for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){ std::cout << std::setw (12) << reduced_name_samples.at(iName) ; std::cout << " | " << purple << std::setw (9) << 1000 / LUMI * numEntriesFirstStep_reduced_samples.at(iName); std::cout << normal << " [" << std::setw (9) << "XXX"; std::cout << " ]"; for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){ std::cout << " | " << red << std::setw (9) << hTrend[iName]->GetBinContent(iCut+1) / LUMI * 1000.; std::cout << normal << " [" << std::setw (9) << hTrend[iName]->GetBinError(iCut+1) / LUMI * 1000.; std::cout << " ]"; } std::cout << std::endl; } std::cout << std::endl; std::cout << " *********************************** " << std::endl; for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){ std::cout << " | " << red << std::setw (8) << reduced_name_samples.at(iName) ; std::cout << normal << " [" << std::setw (8) << "err"; std::cout << " ]"; } std::cout << std::endl; for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){ std::cout << " | " << purple << std::setw (8) << 1000 / LUMI * numEntriesFirstStep_reduced_samples.at(iName); std::cout << normal << " [" << std::setw (8) << "XXX"; std::cout << " ]"; } std::cout << std::endl; for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){ for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){ std::cout << " | " << red << std::setw (8) << hTrend[iName]->GetBinContent(iCut+1) / LUMI * 1000.; std::cout << normal << " [" << std::setw (8) << hTrend[iName]->GetBinError(iCut+1) / LUMI * 1000.; std::cout << " ]"; } std::cout << std::endl; } std::cout << std::endl; std::cout << std::endl; std::cout << std::endl; std::cout << " **************************************** " << std::endl; std::cout << " ************* efficiency *************** " << std::endl; std::cout << std::setw (12) << "sample"; for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){ std::cout << " | " << std::setw (8) << iCut; std::cout << " [" << std::setw (8) << "XXX"; std::cout << " ]"; } std::cout << std::endl; for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){ std::cout << std::setw (12) << reduced_name_samples.at(iName) ; for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){ std::cout << " | " << yellow << std::setw (8) << hTrend[iName]->GetBinContent(iCut+1) / numEntriesFirstStep_reduced_samples.at(iName); std::cout << normal << " [" << std::setw (8) << hTrend[iName]->GetBinError(iCut+1) / numEntriesFirstStep_reduced_samples.at(iName); // std::cout << " | " << yellow << std::setw (8) << hTrend[iName]->GetBinContent(iCut+1) << " / " << numEntriesFirstStep_reduced_samples.at(iName); // std::cout << normal << " [" << std::setw (8) << hTrend[iName]->GetBinError(iCut+1) << " / " << numEntriesFirstStep_reduced_samples.at(iName); std::cout << " ]"; } std::cout << std::endl; } std::cout << std::endl; std::cout << " *********************************** " << std::endl; for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){ std::cout << " | " << std::setw (8) << reduced_name_samples.at(iName) ; std::cout << " [" << std::setw (8) << "err"; std::cout << " ]"; } std::cout << std::endl; for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){ for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){ std::cout << " | " << yellow << std::setw (8) << hTrend[iName]->GetBinContent(iCut+1) / numEntriesFirstStep_reduced_samples.at(iName); std::cout << normal << " [" << std::setw (8) << hTrend[iName]->GetBinError(iCut+1) / numEntriesFirstStep_reduced_samples.at(iName); std::cout << " ]"; } std::cout << std::endl; } std::cout << std::endl; std::cout << std::endl; std::cout << std::endl; std::cout << std::endl; std::cout << std::endl; std::cout << " ****************************************************************** " << std::endl; std::cout << " ****************************************************************** " << std::endl; std::cout << " *********************** for Lands datacard *********************** " << std::endl; std::cout << std::endl; std::cout << std::endl; std::cout << std::endl; std::cout << std::endl; std::string mass = "160"; try { mass = gConfigParser -> readStringOption("Input::mass"); } catch (char const* exceptionString){ std::cerr << " exception = " << exceptionString << std::endl; } std::cout << ">>>>> input::mass " << mass << std::endl; std::ofstream myfile; std::string nameOutDataCard = "dataCard_H" + mass + ".txt"; ///==== output - txt file name ==== try { nameOutDataCard = gConfigParser -> readStringOption("Output::DataCard"); } catch (char const* exceptionString){ std::cerr << " exception = " << exceptionString << std::endl; } myfile.open (nameOutDataCard.c_str()); std::cout << "Writing to: " << nameOutDataCard << std::endl; std::cout << std::endl; myfile << "Limit" << std::endl; myfile << "imax 1 number of channels" << std::endl; myfile << "jmax "<< (reduced_name_samples.size() - SignalName.size() - 1) << " number of background" << std::endl; //---- -1 to take into account "DATA" myfile << "kmax "<< 0 << " number of nuisance parameters" << std::endl; double totalSig = 0; double totalBkg = 0; for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){ if (iName != numDATA) { bool isSig = false; for (std::vector<std::string>::const_iterator itSig = SignalName.begin(); itSig != SignalName.end(); itSig++){ if (reduced_name_samples.at(iName) == *itSig) isSig = true; } if (isSig) { totalSig += hTrend[iName]->GetBinContent(vCut.size()); ///---- last cut! } else { totalBkg += hTrend[iName]->GetBinContent(vCut.size()); ///---- last cut! } } } myfile << "-------------------------------------------------" << std::endl; // myfile << "Observation " << ((Discovery==1) ? (int) (totalBkg+totalSig) : (int) (totalBkg)) << std::endl; myfile << "Observation " << hTrend[numDATA]->GetBinContent(vCut.size()) << std::endl; //# 1 = discovery, 0 = exclusion myfile << "-------------------------------------------------" << std::endl; myfile << std::setw (12) << " bin " << std::setw (8) << 1 << " "; for (int i=0; i < (reduced_name_samples.size() - SignalName.size() - 1); i++){ myfile << std::setw (8) << 1 << " "; } myfile << std::endl; myfile << std::setw (12) << " process " << std::setw (8) << "sig" << " "; for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){ if (iName != numDATA) { bool isSig = false; for (std::vector<std::string>::const_iterator itSig = SignalName.begin(); itSig != SignalName.end(); itSig++){ if (reduced_name_samples.at(iName) == *itSig) isSig = true; } if (!isSig) { myfile << std::setw (8) << reduced_name_samples.at(iName) << " "; } } } myfile << std::endl; myfile << std::setw (12) << " process " << std::setw (8) << 0 << " "; for (int i=0; i < (reduced_name_samples.size() - SignalName.size() - 1); i++){ myfile << std::setw (8) << i+1 << " "; } myfile << std::endl; myfile << std::setw (12) << " rate " << std::setw (8) << totalSig << " "; for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){ if (iName != numDATA) { bool isSig = false; for (std::vector<std::string>::const_iterator itSig = SignalName.begin(); itSig != SignalName.end(); itSig++){ if (reduced_name_samples.at(iName) == *itSig) isSig = true; } if (!isSig) { myfile << std::setw (8) << hTrend[iName]->GetBinContent(vCut.size()) << " "; } } } myfile << std::endl; myfile << "-------------------------------------------------" << std::endl; myfile.close(); ///==== plot on the screen ==== std::cout << "Limit" << std::endl; std::cout << "imax 1 number of channels" << std::endl; std::cout << "jmax "<< (reduced_name_samples.size() - SignalName.size() - 1) << " number of background" << std::endl; //---- -1 to take into account "DATA" std::cout << "kmax "<< 0 << " number of nuisance parameters" << std::endl; totalSig = 0; totalBkg = 0; for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){ if (iName != numDATA) { bool isSig = false; for (std::vector<std::string>::const_iterator itSig = SignalName.begin(); itSig != SignalName.end(); itSig++){ if (reduced_name_samples.at(iName) == *itSig) isSig = true; } if (isSig) { totalSig += hTrend[iName]->GetBinContent(vCut.size()); ///---- last cut! } else { totalBkg += hTrend[iName]->GetBinContent(vCut.size()); ///---- last cut! } } } std::cout << "-------------------------------------------------" << std::endl; // std::cout << "Observation " << ((Discovery==1) ? (int) (totalBkg+totalSig) : (int) (totalBkg)) << std::endl; std::cout << "Observation " << hTrend[numDATA]->GetBinContent(vCut.size()) << std::endl; //# 1 = discovery, 0 = exclusion std::cout << "-------------------------------------------------" << std::endl; std::cout << std::setw (12) << " bin " << std::setw (8) << 1 << " "; for (int i=0; i < (reduced_name_samples.size() - SignalName.size() - 1); i++){ std::cout << std::setw (8) << 1 << " "; } std::cout << std::endl; std::cout << std::setw (12) << " process " << std::setw (8) << "sig" << " "; for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){ if (iName != numDATA) { bool isSig = false; for (std::vector<std::string>::const_iterator itSig = SignalName.begin(); itSig != SignalName.end(); itSig++){ if (reduced_name_samples.at(iName) == *itSig) isSig = true; } if (!isSig) { std::cout << std::setw (8) << reduced_name_samples.at(iName) << " "; } } } std::cout << std::endl; std::cout << std::setw (12) << " process " << std::setw (8) << 0 << " "; for (int i=0; i < (reduced_name_samples.size() - SignalName.size() - 1); i++){ std::cout << std::setw (8) << i+1 << " "; } std::cout << std::endl; std::cout << std::setw (12) << " rate " << std::setw (8) << totalSig << " "; for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){ if (iName != numDATA) { bool isSig = false; for (std::vector<std::string>::const_iterator itSig = SignalName.begin(); itSig != SignalName.end(); itSig++){ if (reduced_name_samples.at(iName) == *itSig) isSig = true; } if (!isSig) { std::cout << std::setw (8) << hTrend[iName]->GetBinContent(vCut.size()) << " "; } } } std::cout << std::endl; std::cout << "-------------------------------------------------" << std::endl; std::cout << std::endl; std::cout << std::endl; std::cout << std::endl; std::cout << std::endl; std::cout << std::endl; std::cout << std::endl; std::cout << std::endl; std::cout << std::endl; std::cout << std::endl; std::cout << std::endl; ///==== draw trend vs cut (begin) cTrend->cd(); DrawStack(hsTrend,1,LumiSyst); hTrend[numDATA] -> Draw("EsameP"); gPad->SetLogy(); gPad->SetGrid(); leg->Draw(); latex->Draw(); for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){ TString nameCanvas = Form("%d_Canvas_Trend",iCut); cTrendPie[iCut] = new TCanvas(nameCanvas,nameCanvas,400,400); cTrendPie[iCut]->cd(); hTrendPie[iCut] -> Draw("3d t nol"); hTrendPie[iCut]->SetX(.45); hTrendPie[iCut]->SetRadius(.22); leg->Draw(); latex->Draw(); cTrendPieAll->cd(iCut+1); hTrendPie[iCut] -> Draw("3d t nol"); hTrendPie[iCut]->SetX(.45); hTrendPie[iCut]->SetRadius(.22); leg->Draw(); latex->Draw(); } ///==== draw trend vs cut (end) std::cerr << " ******************************************* end *******************************************" << std::endl; end = clock(); std::cout <<"Time = " << ((double) (end - start)) << " (a.u.)" << std::endl; ///==== save output ==== outFile.cd(); cTrend -> Write(); outFile.mkdir("Trend"); outFile.cd("Trend"); for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){ cTrendPie[iCut] -> Write(); } cTrendPieAll -> Write(); outFile.cd(); outFile.mkdir("PU"); outFile.cd("PU"); hPUMC -> Write(); hPUDATA -> Write(); hPUWeight -> Write(); outFile.cd(); outFile.mkdir("Sample"); outFile.cd("Sample"); for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){ cTrendSample[iName] ->Write(); } leg->Write(); }
int main(int argc, char** argv){ //Check if all nedeed arguments to parse are there if(argc != 2) { std::cerr << ">>>>> analysis.cpp::usage: " << argv[0] << " configFileName" << std::endl ; return 1; } std::cout << " " << std::endl; std::cout << " " << std::endl; std::cout << " \\ | | \\ \\ / _) | | " << std::endl; std::cout << " _ \\ _` | _` | \\ \\ \\ / _ \\ | _` | __ \\ __| " << std::endl; std::cout << " ___ \\ ( | ( | \\ \\ \\ / __/ | ( | | | | | " << std::endl; std::cout << " _/ _\\ \\__,_| \\__,_| \\_/\\_/ \\___| _| \\__, | _| |_| \\__| " << std::endl; std::cout << " |___/ " << std::endl; std::cout << " " << std::endl; std::cout << " " << std::endl; std::cout << " " << std::endl; // Parse the config file parseConfigFile (argv[1]) ; std::string treeName = gConfigParser -> readStringOption("Input::treeName"); std::string treeNameDir = ""; try { treeNameDir = gConfigParser -> readStringOption("Input::treeNameDir"); } catch (char const* exceptionString){ std::cerr << " exception = " << exceptionString << std::endl; } std::cout << ">>>>> input::treeNameDir " << treeNameDir << std::endl; std::string fileSamples = gConfigParser -> readStringOption("Input::fileSamples"); std::string inputDirectory = gConfigParser -> readStringOption("Input::inputDirectory"); TTree *treeJetLepVect[1000]; char nameFileIn[1000]; char *nameSample[1000]; int PUScenarioIndex[1000]; sprintf(nameFileIn,"%s",fileSamples.c_str()); int numberOfSamples = ReadFileWeight(nameFileIn, nameSample, PUScenarioIndex); std::cout << std::endl; std::cout << " numberOfSamples = " << numberOfSamples << std::endl; std::cout << std::endl; // std::cout << " PUScenarioIndex[0] = " << PUScenarioIndex[0] << std::endl; ///==== PU reweight (begin) ==== int numPUScenarios = gConfigParser -> readIntOption("PU::PUScenarios"); std::vector<std::string> PUVAR; std::vector<double> PUMC[100]; std::vector<double> PUDATA[100]; PUclass PU[100]; for (int iScPU = 0; iScPU < numPUScenarios; iScPU++) { TString namePU; namePU = Form("PU::PUMC%d",iScPU); PUMC[iScPU] = gConfigParser -> readDoubleListOption(namePU.Data()); namePU = Form("PU::PUDATA%d",iScPU); PUDATA[iScPU] = gConfigParser -> readDoubleListOption(namePU.Data()); namePU = Form("PU::PUVAR%d",iScPU); std::string tempName = gConfigParser -> readStringOption(namePU.Data()); PUVAR.push_back(tempName); if (PUMC[iScPU].size() != PUDATA[iScPU].size()) { std::cout << " PUVAR[" << iScPU << "] = " << PUVAR.at(iScPU) << std::endl; std::cout << " PUMC[" << iScPU << "].size() = " << PUMC[iScPU].size() << std::endl; std::cout << " PUDATA[" << iScPU << "].size() = " << PUDATA[iScPU].size() << std::endl; std::cerr << " ERROR " << std::endl; return 1; } double sumPUMC = 0; for (int itVPU = 0; itVPU < PUMC[iScPU].size(); itVPU++ ){ sumPUMC += PUMC[iScPU].at(itVPU); } double sumPUDATA = 0; for (int itVPU = 0; itVPU < PUDATA[iScPU].size(); itVPU++ ){ sumPUDATA += PUDATA[iScPU].at(itVPU); } for (int itVPU = 0; itVPU < PUMC[iScPU].size(); itVPU++ ){ PU[iScPU].PUWeight.push_back(PUDATA[iScPU].at(itVPU) / PUMC[iScPU].at(itVPU) * sumPUMC / sumPUDATA); } } ///==== PU reweight (end) ==== ///==== debug flag ==== bool debug = false; try { debug = gConfigParser -> readBoolOption("Input::debug"); } catch (char const* exceptionString){ std::cerr << " exception = " << exceptionString << std::endl; } std::cout << ">>>>> input::debug " << debug << std::endl; for (int iSample=0; iSample<numberOfSamples; iSample++){ std::cout << " nameSample[" << iSample << ":" << numberOfSamples << "] = " << nameSample[iSample] << std::endl; ///==== GetTree (begin) ==== char nameFile[20000]; sprintf(nameFile,"%s/out_%s.root",inputDirectory.c_str(),nameSample[iSample]); std::cout << " nameFile = " << nameFile << std::endl; TFile* f = new TFile(nameFile, "update"); f->cd(treeNameDir.c_str()); treeJetLepVect[iSample] = (TTree*) f->Get(treeName.c_str()); // char nameTreeJetLep[100]; // sprintf(nameTreeJetLep,"treeJetLep_%d",iSample); // treeJetLepVect[iSample]->SetName(nameTreeJetLep); ///==== GetTree (end) ==== std::cout << " >>>>> GetEntries " << treeJetLepVect[iSample]->GetEntries() << std::endl; double weight; // TBranch *newBranch; ///==== add new branch ==== TBranch *newBranch = treeJetLepVect[iSample] -> Branch("weight_PU",&weight,"weight_PU/D"); int numPUMC; treeJetLepVect[iSample] -> SetBranchAddress(PUVAR.at(PUScenarioIndex[iSample]).c_str(),&numPUMC); Long64_t nentries = treeJetLepVect[iSample]->GetEntries(); for (Long64_t iEntry = 0; iEntry < nentries; iEntry++){ if((iEntry%((nentries+10)/10)) == 0) std::cout << ">>>>> analysis::GetEntry " << iEntry << " : " << nentries << std::endl; treeJetLepVect[iSample]->GetEntry(iEntry); weight = PU[ PUScenarioIndex[iSample] ].getPUWeight(numPUMC); newBranch->Fill(); } // save only the new version of the tree treeJetLepVect[iSample]->Write("", TObject::kOverwrite); } std::cout << " *** end *** " << std::endl; }
int main(int argc, char** argv) { if(argc != 2) { std::cerr << ">>>>> analysis.cpp::usage: " << argv[0] << " configFileName" << std::endl ; return 1; } // Parse the config file parseConfigFile (argv[1]) ; std::string treeName = gConfigParser -> readStringOption("Input::treeName"); std::string fileSamples = gConfigParser -> readStringOption("Input::fileSamples"); std::string inputDirectory = gConfigParser -> readStringOption("Input::inputDirectory"); std::string inputBeginningFile = "out_NtupleProducer_"; try { inputBeginningFile = gConfigParser -> readStringOption("Input::inputBeginningFile"); } catch (char const* exceptionString){ std::cerr << " exception = " << exceptionString << std::endl; } std::cout << ">>>>> Input::inputBeginningFile " << inputBeginningFile << std::endl; //==== list of methods std::string MVADirectory = gConfigParser -> readStringOption ("Options::MVADirectory"); std::vector<std::string> vectorMyMethodList = gConfigParser -> readStringListOption("Options::MVAmethods"); std::vector<std::string> vectorMyMethodMassList = gConfigParser -> readStringListOption("Options::MVAmethodsMass"); std::string outputDirectory = gConfigParser -> readStringOption("Output::outputDirectory"); //---- variables float jetpt1; float jetpt2; float mjj; float detajj; float dphilljetjet; float pt1; float pt2; float mll; float dphill; float mth; float dphillmet; float mpmet; float channel; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ TFile* outputRootFile[500]; TTree* cloneTreeJetLepVect[500]; TTree *treeJetLepVect[500]; TFile* file[500]; char *nameSample[1000]; char *nameHumanReadable[1000]; char* xsectionName[1000]; char nameFileIn[1000]; sprintf(nameFileIn,"%s",fileSamples.c_str()); int numberOfSamples = ReadFile(nameFileIn, nameSample, nameHumanReadable, xsectionName); double Normalization[1000]; double xsection[1000]; for (int iSample=0; iSample<numberOfSamples; iSample++){ char nameFile[20000]; sprintf(nameFile,"%s/%s%s.root",inputDirectory.c_str(),inputBeginningFile.c_str(),nameSample[iSample]); file[iSample] = new TFile(nameFile, "READ"); treeJetLepVect[iSample] = (TTree*) file[iSample]->Get(treeName.c_str()); char nameTreeJetLep[100]; sprintf(nameTreeJetLep,"treeJetLep_%d",iSample); treeJetLepVect[iSample]->SetName(nameTreeJetLep); treeJetLepVect[iSample] -> SetBranchAddress("jetpt1", &jetpt1); treeJetLepVect[iSample] -> SetBranchAddress("jetpt2", &jetpt2); treeJetLepVect[iSample] -> SetBranchAddress("mjj", &mjj); treeJetLepVect[iSample] -> SetBranchAddress("detajj", &detajj); treeJetLepVect[iSample] -> SetBranchAddress("dphilljetjet", &dphilljetjet); treeJetLepVect[iSample] -> SetBranchAddress("pt1", &pt1); treeJetLepVect[iSample] -> SetBranchAddress("pt2", &pt2); treeJetLepVect[iSample] -> SetBranchAddress("mll", &mll); treeJetLepVect[iSample] -> SetBranchAddress("dphill", &dphill); treeJetLepVect[iSample] -> SetBranchAddress("mth", &mth); treeJetLepVect[iSample] -> SetBranchAddress("dphillmet", &dphillmet); treeJetLepVect[iSample] -> SetBranchAddress("mpmet", &mpmet); treeJetLepVect[iSample] -> SetBranchAddress("channel", &channel); sprintf(nameFile,"%s/%s%s.root",outputDirectory.c_str(),inputBeginningFile.c_str(),nameSample[iSample]); outputRootFile[iSample] = new TFile ( nameFile, "RECREATE") ; outputRootFile[iSample] -> cd () ; cloneTreeJetLepVect[iSample] = treeJetLepVect[iSample] -> CloneTree (0) ; } /** * cycle on MVA (method-mass) * * cycle on samples * * * cycle on events */ for (int iMVA = 0; iMVA < vectorMyMethodList.size(); iMVA++) { std::cout << " vectorMyMethodList[" << iMVA << "] = " << vectorMyMethodList.at(iMVA) << std::endl; TString myMethodList = Form ("%s",vectorMyMethodList.at(iMVA).c_str()); for (int iMVAMass = 0; iMVAMass < vectorMyMethodMassList.size(); iMVAMass++) { std::cout << " vectorMyMethodMassList[" << iMVAMass << "] = " << vectorMyMethodMassList.at(iMVAMass) << std::endl; TMVA::Reader *TMVAreader = new TMVA::Reader( "!Color:!Silent" ); // TMVAreader->AddVariable("jetpt1", &jetpt1); // TMVAreader->AddVariable("jetpt2", &jetpt2); // TMVAreader->AddVariable("mjj", &mjj); // TMVAreader->AddVariable("detajj", &detajj); // TMVAreader->AddVariable("dphilljetjet", &dphilljetjet); // TMVAreader->AddVariable("pt1", &pt1); // TMVAreader->AddVariable("pt2", &pt2); // TMVAreader->AddVariable("mll", &mll); // TMVAreader->AddVariable("dphill", &dphill); // TMVAreader->AddVariable("mth", &mth); // TMVAreader->AddVariable("dphillmet", &dphillmet); // TMVAreader->AddVariable("mpmet", &mpmet); Float_t input_variables[1000]; // float input_variables[1000]; // TMVAreader->AddVariable("jetpt1", &(input_variables[0])); // TMVAreader->AddVariable("jetpt2", &(input_variables[1])); // TMVAreader->AddVariable("mjj", &(input_variables[2])); // TMVAreader->AddVariable("detajj", &(input_variables[3])); // TMVAreader->AddVariable("dphilljetjet", &(input_variables[4])); // TMVAreader->AddVariable("pt1", &(input_variables[5])); // TMVAreader->AddVariable("pt2", &(input_variables[6])); // TMVAreader->AddVariable("mll", &(input_variables[7])); // TMVAreader->AddVariable("dphill", &(input_variables[8])); // TMVAreader->AddVariable("mth", &(input_variables[9])); // TMVAreader->AddVariable("dphillmet", &(input_variables[10])); // TMVAreader->AddVariable("mpmet", &(input_variables[11])); TMVAreader->AddVariable("jetpt1", &input_variables[0]); TMVAreader->AddVariable("jetpt2", &input_variables[1]); TMVAreader->AddVariable("mjj", &input_variables[2]); TMVAreader->AddVariable("detajj", &input_variables[3]); TMVAreader->AddVariable("dphilljetjet", &input_variables[4]); TMVAreader->AddVariable("pt1", &input_variables[5]); TMVAreader->AddVariable("pt2", &input_variables[6]); TMVAreader->AddVariable("mll", &input_variables[7]); TMVAreader->AddVariable("dphill", &input_variables[8]); TMVAreader->AddVariable("mth", &input_variables[9]); TMVAreader->AddVariable("dphillmet", &input_variables[10]); TMVAreader->AddVariable("mpmet", &input_variables[11]); TMVAreader->AddSpectator("channel", &input_variables[12]); TString myMethodMassList = Form ("%s",vectorMyMethodMassList.at(iMVAMass).c_str()); TString weightfile = Form ("%s/weights_%s_testVariables/TMVAMulticlass_%s.weights.xml",MVADirectory.c_str(),myMethodMassList.Data(),myMethodList.Data()); std::cout << " myMethodList = " << myMethodList.Data() << std::endl; std::cout << " weightfile = " << weightfile.Data() << std::endl; // TString myMethodListBook = Form ("%s",vectorMyMethodList.at(iMVA).c_str()); // TMVAreader->BookMVA( myMethodListBook, weightfile ); TMVAreader->BookMVA( myMethodList, weightfile ); for (int iSample=0; iSample<numberOfSamples; iSample++){ std::cout << " iSample = " << iSample << " :: " << numberOfSamples << std::endl; file[iSample] -> cd(); Double_t MVA_Value; TBranch *newBranch; TString methodName4Tree = Form ("%s_%s_MVAHiggs",myMethodList.Data(),myMethodMassList.Data()); TString methodName4Tree2 = Form ("%s_%s_MVAHiggs/D",myMethodList.Data(),myMethodMassList.Data()); newBranch = cloneTreeJetLepVect[iSample]->Branch(methodName4Tree,&MVA_Value,methodName4Tree2); // newBranch = treeJetLepVect[iSample]->Branch(methodName4Tree,&MVA_Value,methodName4Tree2); ///==== loop ==== Long64_t nentries = treeJetLepVect[iSample]->GetEntries(); for (Long64_t iEntry = 0; iEntry < nentries; iEntry++){ if((iEntry%1000) == 0) std::cout << ">>>>> analysis::GetEntry " << iEntry << " : " << nentries << std::endl; treeJetLepVect[iSample]->GetEntry(iEntry); input_variables[0] = static_cast<Float_t>(jetpt1); input_variables[1] = static_cast<Float_t>(jetpt2); input_variables[2] = static_cast<Float_t>(mjj); input_variables[3] = static_cast<Float_t>(detajj); input_variables[4] = static_cast<Float_t>(dphilljetjet); input_variables[5] = static_cast<Float_t>(pt1); input_variables[6] = static_cast<Float_t>(pt2); input_variables[7] = static_cast<Float_t>(mll); input_variables[8] = static_cast<Float_t>(dphill); input_variables[9] = static_cast<Float_t>(mth); input_variables[10] = static_cast<Float_t>(dphillmet); input_variables[11] = static_cast<Float_t>(mpmet); input_variables[12] = static_cast<Float_t>(channel); int num = TMVAreader->EvaluateMulticlass(myMethodList).size(); double max = -1e9; double tempmax; int numsel = -1; for (int inum = 0; inum<(num-2); inum++) { // il -2 è dovuto a Sig e Bkg che mi salva il training! Uffi! tempmax = (TMVAreader->EvaluateMulticlass(myMethodList))[inum]; if (tempmax > max) { max = tempmax; numsel = inum; } } MVA_Value = max + 3*numsel; // newBranch -> Fill(); cloneTreeJetLepVect[iSample] -> Fill () ; } } } } for (int iSample=0; iSample<numberOfSamples; iSample++){ // save only the new version of the tree // treeJetLepVect[iSample]->Write("", TObject::kOverwrite); cloneTreeJetLepVect[iSample] -> SetName (treeName.c_str()); cloneTreeJetLepVect[iSample] -> AutoSave () ; outputRootFile[iSample] -> Close () ; } }
int main(int argc, char **argv) { daemonize(); //saveData("admin",100,100,"admin"); config_obj=parseConfigFile(); ipWhitelist = cJSON_GetObjectItem(config_obj,"ipWhitelist"); wiringPiSetup(); pinDirections = cJSON_GetObjectItem(config_obj,"pinDirections"); handlePinsDirection(pinDirections); signal(SIGINT, sighandler); struct lws_context_creation_info info; unsigned int ms, oldms= 0; const char *iface = NULL; char cert_path[1024]; char key_path[1024]; int use_ssl = 0; int opts = 0; int n = 0; /* * take care to zero down the info struct, he contains random garbaage * from the stack otherwise */ memset(&info, 0, sizeof info); info.port = 7681; signal(SIGINT, sighandler); info.iface = iface; info.protocols = protocols; info.ssl_cert_filepath = NULL; info.ssl_private_key_filepath = NULL; if (use_ssl) { if (strlen(resource_path) > sizeof(cert_path) - 32) { lwsl_err("resource path too long\n"); return -1; } sprintf(cert_path, "%s/libwebsockets-test-server.pem", resource_path); if (strlen(resource_path) > sizeof(key_path) - 32) { lwsl_err("resource path too long\n"); return -1; } sprintf(key_path, "%s/libwebsockets-test-server.key.pem", resource_path); info.ssl_cert_filepath = cert_path; info.ssl_private_key_filepath = key_path; } info.gid = -1; info.uid = -1; info.max_http_header_pool = 1; info.options = opts | LWS_SERVER_OPTION_VALIDATE_UTF8; info.extensions = NULL; context = lws_create_context(&info); if (context == NULL) { lwsl_err("libwebsocket init failed\n"); return -1; } n = 0; while (n >= 0 && !force_exit) { struct timeval tv; gettimeofday(&tv, NULL); /* * This provokes the LWS_CALLBACK_SERVER_WRITEABLE for every * live websocket connection using the DUMB_INCREMENT protocol, * as soon as it can take more packets (usually immediately) */ extern struct ram_usage ram_l; extern struct cpu_live cpu_l; extern struct cpu_freq cpu_freq; if(old_client_count!=client_count){ if(hash){ free(hash); } hash=rand_string(); lws_callback_on_writable_all_protocol(context, &protocols[PROTOCOL_GPIO]); lws_callback_on_writable_all_protocol(context, &protocols[PROTOCOL_DETAILS]); lws_callback_on_writable_all_protocol(context, &protocols[PROTOCOL_SERVICES]); lws_callback_on_writable_all_protocol(context, &protocols[PROTOCOL_HOME]); old_client_count=client_count; } ms = (tv.tv_sec * 1000) + (tv.tv_usec / 1000); if ((ms - oldms) > 200 && get_client_count()>0 && (cpuLive(&cpu_l,5)==0 && ramLive(&ram_l,5)==0 && cpuLiveFreq(&cpu_freq)==0 )) { lws_callback_on_writable_all_protocol(context, &protocols[PROTOCOL_DETAILS]); oldms = ms; } n = lws_service(context, 50); } lws_context_destroy(context); lwsl_notice("libwebsockets-test-server exited cleanly\n"); return 0; }
int main(int argc, char** argv) { //Check if all nedeed arguments to parse are there if(argc != 2) { std::cerr << ">>> computeEffectiveSigma::usage: " << argv[0] << " configFileName" << std::endl; return -1; } //---------------------- // Parse the config file parseConfigFile(argv[1]); std::string inputFile = gConfigParser -> readStringOption("Input::inputFile"); float fraction = gConfigParser -> readFloatOption("Options::fraction"); bool diagonalCatOnly = gConfigParser -> readBoolOption("Options::diagonalCatOnly"); std::string outFilePath = gConfigParser -> readStringOption("Output::outFilePath"); std::string outFileLabel = gConfigParser -> readStringOption("Output::outFileLabel"); //--------------------------- // Open input and output file std::cout << std::endl; std::cout << ">>> Open input and output file" << std::endl; TFile* inFile = TFile::Open(inputFile.c_str(),"READ"); std::string outFileName = outFilePath; outFileName += "/computeEffectiveSigma"; outFileName += "_" + outFileLabel; outFileName += Form("_%1.4f",fraction); TFile* outFile = TFile::Open((outFileName+".root").c_str(),"RECREATE"); //------------------ // Define categories std::cout << std::endl; std::cout << ">>> Define categories" << std::endl; std::vector<std::string> categories; std::vector<std::string> categoryLabels; categories.push_back("EB-EB"); categoryLabels.push_back("EB-EB"); categories.push_back("EB-EB_hR9"); categoryLabels.push_back("EB-EB R9>0.94"); categories.push_back("EB-EB_lR9"); categoryLabels.push_back("EB-EB R9<0.94"); categories.push_back("EB-EB_eta>1"); categoryLabels.push_back("EB-EB |#eta|>1"); categories.push_back("EB-EB_eta<1"); categoryLabels.push_back("EB-EB |#eta|<1"); categories.push_back("EE-EE"); categoryLabels.push_back("EE-EE"); categories.push_back("EE-EE_hR9"); categoryLabels.push_back("EE-EE R9>0.94"); categories.push_back("EE-EE_lR9"); categoryLabels.push_back("EE-EE R9<0.94"); categories.push_back("EE-EE_eta>2"); categoryLabels.push_back("EE-EE |#eta|>2"); categories.push_back("EE-EE_eta<2"); categoryLabels.push_back("EE-EE |#eta|<2"); std::vector<float> etaBins; etaBins.push_back(0.0); etaBins.push_back(1.0); etaBins.push_back(1.5); etaBins.push_back(2.0); etaBins.push_back(2.5); int nEtaBins = int(etaBins.size()) - 1; std::vector<float> R9Bins; R9Bins.push_back(0.00); R9Bins.push_back(0.94); R9Bins.push_back(1.00); int nR9Bins = int(R9Bins.size()) - 1; std::vector<std::string> singleCats; std::vector<std::string> singleCatLabels; for(int etaBin = 0; etaBin < nEtaBins; ++etaBin) for(int R9Bin = 0; R9Bin < nR9Bins; ++R9Bin) { singleCats.push_back(Form("eta%1.1f-%1.1f_R9%1.2f-%1.2f",etaBins.at(etaBin),etaBins.at(etaBin+1),R9Bins.at(R9Bin),R9Bins.at(R9Bin+1))); singleCatLabels.push_back(Form("%1.1f<|#eta|<%1.1f %1.2f<R9<%1.2f",etaBins.at(etaBin),etaBins.at(etaBin+1),R9Bins.at(R9Bin),R9Bins.at(R9Bin+1))); } for(unsigned int i = 0; i < singleCats.size(); ++i) for(unsigned int j = i; j < singleCats.size(); ++j) { if( diagonalCatOnly && (j != i ) ) continue; categories.push_back(singleCats.at(i) + "__" + singleCats.at(j)); categoryLabels.push_back(Form("%s %s",singleCatLabels.at(i).c_str(),singleCatLabels.at(j).c_str())); std::cout << ">>>>>> " << singleCats.at(i) + "__" + singleCats.at(j) << std::endl; } //------------------------ // Compute effective sigma std::cout << std::endl; std::cout << ">>> Compute effective sigma" << std::endl; const float mZ = 91.188; const float gammaZ = 2.5; float xMin = -1710.; float xMax = +1890; TF1* f_BW = new TF1("f_BW",BW,xMin,xMax,2); f_BW -> SetParameters(mZ,gammaZ); double seff_BW = GetBWIntegral(fraction,f_BW,0.0001); TF1* f_corr = new TF1("f_corr","[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x",0.,100.); f_corr -> SetParameters(1.30447e+01,-8.97976e+01,1.88517e+02,-1.58552e+02,4.77785e+01); TF1* f_err = new TF1("f_err","1.42734e/sqrt(x)",0.,1000000000); for(int R9Bin = 0; R9Bin < nR9Bins; ++R9Bin) { TGraphErrors* g_MC = new TGraphErrors(); TGraphErrors* g_DA = new TGraphErrors(); for(int etaBin = 0; etaBin < nEtaBins; ++etaBin) { std::string singleCatLabel = Form("eta%1.1f-%1.1f_R9%1.2f-%1.2f",etaBins.at(etaBin),etaBins.at(etaBin+1),R9Bins.at(R9Bin),R9Bins.at(R9Bin+1)); std::string doubleCatLabel = singleCatLabel + "__" + singleCatLabel; std::cout << ">>>>>> processing category " << doubleCatLabel << std::endl; double mean_MC,meanErr_MC,min_MC,max_MC; std::string histoName_MC = Form("h_mZFine_MC_%s",(doubleCatLabel).c_str()); TH1F* h_mZFine_MC = (TH1F*)( inFile->Get(histoName_MC.c_str()) ); FindSmallestInterval(mean_MC,meanErr_MC,min_MC,max_MC,h_mZFine_MC,fraction); std::cout << ">>>>>>>>> MC: [" << std::fixed << std::setprecision(3) << std::setw(6) << min_MC << "," << std::fixed << std::setprecision(3) << std::setw(6) << max_MC << "]" << " sigma_eff: " << std::fixed << std::setprecision(3) << std::setw(6) << 0.5*(max_MC-min_MC) << " (" << std::fixed << std::setprecision(3) << std::setw(5) << 0.5*(max_MC-min_MC)/mean_MC*100 << "%)" << " mean: " << std::fixed << std::setprecision(3) << std::setw(6) << mean_MC << " +/-" << std::fixed << std::setprecision(3) << std::setw(6) << meanErr_MC << std::endl; double mean_DA,meanErr_DA,min_DA,max_DA; std::string histoName_DA = Form("h_mZFine_DA_%s",(doubleCatLabel).c_str()); TH1F* h_mZFine_DA = (TH1F*)( inFile->Get(histoName_DA.c_str()) ); FindSmallestInterval(mean_DA,meanErr_DA,min_DA,max_DA,h_mZFine_DA,fraction); std::cout << ">>>>>>>>> DA: [" << std::fixed << std::setprecision(3) << std::setw(6) << min_DA << "," << std::fixed << std::setprecision(3) << std::setw(6) << max_DA << "]" << " sigma_eff: " << std::fixed << std::setprecision(3) << std::setw(6) << 0.5*(max_DA-min_DA) << " (" << std::fixed << std::setprecision(3) << std::setw(5) << 0.5*(max_DA-min_DA)/mean_DA*100 << "%)" << " mean: " << std::fixed << std::setprecision(3) << std::setw(6) << mean_DA << " +/-" << std::fixed << std::setprecision(3) << std::setw(6) << meanErr_DA << std::endl; double x = 0.5 * (etaBins.at(etaBin) + etaBins.at(etaBin+1)); double xErr = 0.5 * (etaBins.at(etaBin+1) - etaBins.at(etaBin)); double seff_MC = 0.5*(max_MC-min_MC); double seff_DA = 0.5*(max_DA-min_DA); double BWInt_MC = f_BW->Integral(min_MC,max_MC)/fraction; double BWInt_DA = f_BW->Integral(min_DA,max_DA)/fraction; double yErr_MC = f_err->Eval(h_mZFine_MC->Integral()) * seff_MC / mean_MC; double yErr_DA = f_err->Eval(h_mZFine_DA->Integral()) * seff_DA / mean_DA; g_MC -> SetPoint(etaBin,x,sqrt(seff_MC*seff_MC-seff_BW*seff_BW)/mean_MC); g_MC -> SetPointError(etaBin,xErr,yErr_MC); g_DA -> SetPoint(etaBin,x,sqrt(seff_DA*seff_DA-seff_BW*seff_BW)/mean_DA); g_DA -> SetPointError(etaBin,xErr,yErr_DA); } outFile -> cd(); g_MC -> Write(Form("g_MC_R9%1.2f-%1.2f",R9Bins.at(R9Bin),R9Bins.at(R9Bin+1))); g_DA -> Write(Form("g_DA_R9%1.2f-%1.2f",R9Bins.at(R9Bin),R9Bins.at(R9Bin+1))); } }
/** * Program entry point */ int main(int argc, char* argv[]) { glutInit(&argc, argv); glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB ); glutInitWindowPosition(20, 20); glutInitWindowSize(kWindowWidth, kWindowHeight); glutCreateWindow("Metamorphosis: CS148 Assignment 4"); glutDisplayFunc(DisplayCallback); glutReshapeFunc(ReshapeCallback); glutKeyboardFunc(KeyboardCallback); // // load the configuration from config.txt, or other file as specified // std::string configFile = "config.txt"; if (argc > 1) configFile = argv[1]; char sourceName[64], targetName[64]; char saveName[64], loadName[64]; STImage *sourceImage, *targetImage; parseConfigFile(configFile.c_str(), sourceName, targetName, saveName, loadName, &sourceImage, &targetImage); delete sourceImage; delete targetImage; // // load the features from the saved features file // loadLineEditorFile(loadName, AddFeatureCallback, sourceName, targetName, &sourceImage, &targetImage); // // run the full morphing algorithm before going into the main loop to // display an image // // these weighting parameters (Beier & Nelly 1992) can be changed if desired const float a = 0.5f, b = 2.0f, p = 0.2f; GenerateMorphFrames(sourceImage, gSourceFeatures, targetImage, gTargetFeatures, a, b, p); // // display a test or debug image here if desired // (note: comment this out if you call DisplayImage from elsewhere) // // STImage *result = sourceImage; // use this to test your image blending // STImage *result = BlendImages(sourceImage, targetImage, 0.5f); // use this to test your field morph /* STImage *result = FieldMorph(sourceImage, gSourceFeatures, gTargetFeatures, 0.5f, a, b, p); */ // use this to test your image morphing STImage *result = MorphImages(sourceImage, gSourceFeatures, targetImage, gTargetFeatures, 0.5f, a, b, p); DisplayImage(result); // enter the GLUT main loop glutMainLoop(); return 0; }
/** Initializes Service object. Creates the service object and calls its init method for further initialization. * @param[in] specification service specification * @return returns service handle upon successful and NULL otherwise */ CommHandle *createService(ServiceSpec *specification) { CommHandle *commHandle = NULL; char cwd_temp[1024]; // Parse configuration file strcpy(cwd_temp, LIB_CONFIG_DIRECTORY); strcat(cwd_temp, LIB_CONFIG_FILENAME); if (!parseConfigFile(cwd_temp)) { freeGlobals(); } // load the plugin // Considers the last path and loads the plugin interface char *substrStart = g_configData.pluginDir; char *substrEnd, *folderPath = NULL; do { if (*substrStart == ':') { substrStart++; } if (folderPath != NULL) { // Incase of iteration, freeing the previously allocated dynamic memory free(folderPath); folderPath = NULL; } substrEnd = strstr(substrStart, ":"); if (substrEnd == NULL) { folderPath = strdup(substrStart); } else { folderPath = strndup(substrStart, substrEnd - substrStart); } strcpy(cwd_temp, ""); // set empty string // Parse plugin file if (folderPath != NULL && *folderPath != '/') { // if path is not absolute path; then consider plugins directory strcpy(cwd_temp, LIB_PLUGINS_DIRECTORY); } strcat(cwd_temp, "lib"); strcat(cwd_temp, specification->type.name); strcat(cwd_temp, "-service.so"); if (fileExists(cwd_temp)) { commHandle = loadCommPlugin(cwd_temp); break; } }while((substrStart = strstr(substrStart, ":")) != NULL); if (!commHandle) { fprintf(stderr, "Plugin library \"lib%s-service.so\" not found\n", specification->type.name); cleanUp(commHandle); free(folderPath); return NULL; } // Considers the last path and loads the plugin interface substrStart = g_configData.pluginInterfaceDir; do { if (*substrStart == ':') { substrStart++; } if (folderPath != NULL) { // Incase of iteration, freeing the previously allocated dynamic memory free(folderPath); folderPath = NULL; } substrEnd = strstr(substrStart, ":"); if (substrEnd == NULL) { folderPath = strdup(substrStart); } else { folderPath = strndup(substrStart, substrEnd - substrStart); } strcpy(cwd_temp, ""); // set empty string // Parse plugin interface file if (folderPath != NULL && *folderPath != '/') { // if path is not absolute path; then consider plugins directory strcpy(cwd_temp, LIB_CONFIG_DIRECTORY); } if (folderPath != NULL) { strcat(cwd_temp, folderPath); } strcat(cwd_temp, "/"); strcat(cwd_temp, *(commHandle->interface)); strcat(cwd_temp, ".json"); if (fileExists(cwd_temp)) { if (!parsePluginInterfaces(cwd_temp)) { freeGlobals(); } break; } }while((substrStart = strstr(substrStart, ":")) != NULL); free(folderPath); // free the dynamic memory if (loadCommInterfaces(commHandle) == false) { cleanUp(commHandle); return NULL; } if (commHandle->init) { commHandle->init(specification); } return commHandle; }
int main (int argc, char** argv) { int ret = UPNP_E_SUCCESS; int signal; char descDocUrl[50]; char descDocName[20]; char xmlPath[50]; char intIpAddress[32]; // Server internal ip address char extIpAddress[32]; sigset_t sigsToCatch; pid_t pid,sid; if (argc != 3) { printf("Usage: upnpd <external ifname> <internal ifname>\n"); printf("Example: upnpd ppp0 eth0\n"); printf("Example: upnpd eth1 eth0\n"); exit(0); } parseConfigFile(&g_forwardRules,&g_debug,g_iptables, g_forwardChainName,g_preroutingChainName, g_upstreamBitrate,g_downstreamBitrate, descDocName,xmlPath); // Save the interface names for later uses strcpy(g_extInterfaceName, argv[1]); strcpy(g_intInterfaceName, argv[2]); // Get the internal and external ip address to start the daemon on /* Added by Yanhua */ while( (GetIpAddressStr(intIpAddress, g_intInterfaceName)==0) || (GetIpAddressStr(extIpAddress, g_extInterfaceName)==0) ) { sleep(2); } #if 0 // Put igd in the background as a daemon process. pid = vfork(); if (pid < 0) { perror("Error forking a new process."); exit(EXIT_FAILURE); } if (pid > 0) exit(EXIT_SUCCESS); if ((sid = setsid()) < 0) { perror("Error running setsid"); exit(EXIT_FAILURE); } if ((chdir("/")) < 0) { perror("Error setting root directory"); exit(EXIT_FAILURE); } umask(0); close(STDERR_FILENO); close (STDIN_FILENO); close (STDOUT_FILENO); #endif // End Daemon initialization // Initialize UPnP SDK on the internal Interface if (g_debug) syslog(LOG_DEBUG, "Initializing UPnP SDK ... "); if ( (ret = UpnpInit(intIpAddress,0) ) != UPNP_E_SUCCESS) { syslog (LOG_ERR, "Error Initializing UPnP SDK on IP %s ",intIpAddress); syslog (LOG_ERR, " UpnpInit returned %d", ret); UpnpFinish(); exit(1); } if (g_debug) syslog(LOG_DEBUG, "UPnP SDK Successfully Initialized."); // Set the Device Web Server Base Directory if (g_debug) syslog(LOG_DEBUG, "Setting the Web Server Root Directory to %s",xmlPath); if ( (ret = UpnpSetWebServerRootDir(xmlPath)) != UPNP_E_SUCCESS ) { syslog (LOG_ERR, "Error Setting Web Server Root Directory to: %s", xmlPath); syslog (LOG_ERR, " UpnpSetWebServerRootDir returned %d", ret); UpnpFinish(); exit(1); } if (g_debug) syslog(LOG_DEBUG, "Succesfully set the Web Server Root Directory."); // Form the Description Doc URL to pass to RegisterRootDevice sprintf(descDocUrl, "http://%s:%d/%s", UpnpGetServerIpAddress(), UpnpGetServerPort(), descDocName); // Register our IGD as a valid UPnP Root device if (g_debug) syslog(LOG_DEBUG, "Registering the root device with descDocUrl %s", descDocUrl); if ( (ret = UpnpRegisterRootDevice(descDocUrl, EventHandler, &deviceHandle, &deviceHandle)) != UPNP_E_SUCCESS ) { syslog(LOG_ERR, "Error registering the root device with descDocUrl: %s", descDocUrl); syslog(LOG_ERR, " UpnpRegisterRootDevice returned %d", ret); UpnpFinish(); exit(1); } syslog (LOG_DEBUG, "IGD root device successfully registered."); // Initialize the state variable table. StateTableInit(descDocUrl); // Record the startup time, for uptime /* Modified by Yanhua */ #if 0 startup_time = time(NULL); #endif { struct sysinfo info; sysinfo(&info); startup_time = (long int)info.uptime; } // Send out initial advertisements of our device's services with timeouts of 30 minutes if ( (ret = UpnpSendAdvertisement(deviceHandle, 1800) != UPNP_E_SUCCESS )) { syslog(LOG_ERR, "Error Sending Advertisements. Exiting ..."); UpnpFinish(); exit(1); } syslog(LOG_DEBUG, "Advertisements Sent. Listening for requests ... "); // Loop until program exit signals recieved sigemptyset(&sigsToCatch); sigaddset(&sigsToCatch, SIGINT); sigaddset(&sigsToCatch, SIGTERM); //sigwait(&sigsToCatch, &signal); pthread_sigmask(SIG_SETMASK, &sigsToCatch, NULL); sigwait(&sigsToCatch, &signal); syslog(LOG_DEBUG, "Shutting down on signal %d...\n", signal); // Cleanup UPnP SDK and free memory pmlist_FreeList(); UpnpUnRegisterRootDevice(deviceHandle); UpnpFinish(); // Exit normally return (1); }