Example #1
0
///
/// Converts a RooDataSet to a TTree which then can be
/// browsed.
///
TTree* Utils::convertRooDatasetToTTree(RooDataSet *d)
{
	// set up the TTree based on the content of the first
	// row of the dataset
	map<string,float> variables;  ///< the proxy variables
	TTree* t = new TTree("tree", "tree");
	TIterator* it = d->get(0)->createIterator();
	while ( RooRealVar* p = (RooRealVar*)it->Next() ){
		variables.insert(pair<string,float>(p->GetName(),p->getVal()));
		t->Branch(p->GetName(), &variables[p->GetName()], TString(p->GetName())+"/F");
	}
	delete it;

	// loop over the dataset, filling the tree
	int nEntries = d->sumEntries();
	for ( int i=0; i<nEntries; i++ ){
		it = d->get(i)->createIterator();
		while ( RooRealVar* p = (RooRealVar*)it->Next() ){
			variables[p->GetName()] = p->getVal();
		}
		delete it;
		t->Fill();
	}

	return t;
}
Example #2
0
void scaleToRate(const char* collectionName, double rateFactor) {
  TRegexp reg(collectionName, kTRUE);
  
  //    gDirectory->ls();
  TList* list = gDirectory->GetList() ;
  TIterator* iter = list->MakeIterator();
  TObject* obj = 0;
  
  while (obj = iter->Next()) {
    if (! obj->InheritsFrom(TH1::Class())) {
      //      cout << "bugger" << endl;
      continue;
    }
    
    
    TString name = obj->GetName();
    cout << "Testing name: " << name << " against " << collectionName << endl;
    
    if (TString(collectionName).MaybeRegexp()) {
      cout << "we have a possible match" << endl;
      cout << "Trying to match to " << TString(obj->GetName()) << endl;
      if (TString(obj->GetName()).Index(reg) < 0 ) {
	cout << "failure here.  Argument returns " << TString(obj->GetName()).Index(reg) << endl;
	continue;
      }
    }
    else if (! name.BeginsWith(collectionName)) continue;
    
    cout << "We're trying to scale" << name << endl;
    ((TH1*)obj)->Scale(rateFactor);
    
  }
  
}
Example #3
0
QString Include::GetFile()
{
	if(Root.IsNull())
	{
		throw NoLabelInicialisationException("Include: label do not inicialised.");
	}

	if(Root.IsNull())
	{
		throw NoLabelInicialisationException("Include: label do not inicialised.");
	}

	TIterator TITER;

	TITER.Init(Root, false);
	while (TITER.More())
	{
		TElement val = TITER.Value();
		QString name = val.GetName();
		if(name == "File name")
		{
			TString valint = (TString)val;
			return valint.GetValue();
		}
		TITER.Next();
	}

	return "";
}
Example #4
0
af::TList Scheme::GetIncludeList()
{
	if(Root.IsNull())
	{
		throw NoLabelInicialisationException("Scheme: label do not inicialised.");
	}
	
	
//	return IncludeList;
	
	
	TIterator TITER;

	TList valls;
	TITER.Init(Root, false);
	while (TITER.More())
	{
		TList val = (TList)TITER.Value();
		QString name = val.GetName();

		if(name == "IncludeList")
		{
			return val;
		}
		TITER.Next();
	}

	TElement e(Root);
	throw NoExistException("Scheme: Include List do not exists.", e);

	return valls;
}
Example #5
0
   void scalebins(const char* patORpfx, Double_t scale) {
      TRegexp reg(patORpfx, kFALSE);

      TList* list = gDirectory->GetList() ;
      TIterator* iter = list->MakeIterator();

      TObject* obj = 0;

      while (obj = iter->Next()) {
         if (! obj->InheritsFrom(TH1::Class())) continue;

         TString name = obj->GetName();

         if (TString(patORpfx).MaybeRegexp()) {
            if (TString(obj->GetName()).Index(reg) < 0 ) continue;
         } else if (! name.BeginsWith(patORpfx)) continue;

         Double_t binWidth, binContent, binError, newBinContent, newBinError;
         for (Int_t i = 1; i <= ((TH1*)obj)->GetNbinsX(); ++i) {
            binWidth = ((TH1*)obj)->GetBinWidth(i);
            binContent = ((TH1*)obj)->GetBinContent(i);
            binError = ((TH1*)obj)->GetBinError(i);
            newBinContent = (binContent*scale)/binWidth;
            newBinError = (binError*scale)/binWidth;

            ((TH1*)obj)->SetBinContent(i, newBinContent);
            ((TH1*)obj)->SetBinError(i, newBinContent);
            // Rename y axis with scale
         }
      }
   }
Example #6
0
///
/// Merge two named sets of variables inside a RooWorkspace.
/// Duplicate variables will only be contained once.
///
void Utils::mergeNamedSets(RooWorkspace *w, TString mergedSet, TString set1, TString set2)
{
	// 1. fill all variables into a vector
	vector<string> varsAll;
	TIterator* it = w->set(set1)->createIterator();
	while ( RooRealVar* p = (RooRealVar*)it->Next() ) varsAll.push_back(p->GetName());
	delete it;
	it = w->set(set2)->createIterator();
	while ( RooRealVar* p = (RooRealVar*)it->Next() ) varsAll.push_back(p->GetName());
	delete it;

	// 2. remove duplicates
	sort(varsAll.begin(), varsAll.end());
	vector<string> vars;
	vars.push_back(varsAll[0]);
	string previous = varsAll[0];
	for ( int i=1; i<varsAll.size(); i++ ){
		if ( previous==varsAll[i] ) continue;
		vars.push_back(varsAll[i]);
		previous=varsAll[i];
	}

	// 3. make new, combined set on the workspace
	TString varsCommaList = "";
	for ( int i=0; i<vars.size(); i++ ){
		varsCommaList.Append(vars[i]);
		if ( i<vars.size()-1 ) varsCommaList.Append(",");
	}
	w->defineSet(mergedSet, varsCommaList);
}
Example #7
0
///
/// Float each parameter in the named set "parname" inside workspace "w".
///
void Utils::floatParameters(RooWorkspace* w, TString parname)
{
	TIterator* it = w->set(parname)->createIterator();
	while ( RooRealVar* p = (RooRealVar*)it->Next() ){
		p->setConstant(false);
	}
}
Example #8
0
void Utils::floatParameters(const RooAbsCollection* set)
{
	TIterator* it = set->createIterator();
	while ( RooRealVar* p = (RooRealVar*)it->Next() ){
		p->setConstant(false);
	}
}
Example #9
0
/**
 * @brief Write all TObjects from a given TCollection into a certain directory structure in the file
 *
 * @param col pointer to a TCollection-based container
 * @param dirname name of a directory inside the output file to which the objects should be written
 * @param subdirname optional name of a subdirectory inside dirname to which the objects should be written
 *
 * This method whites all TObject-based objects contained in the TCollection-based container (see ROOT documentation)
 * into a directory whose name is given by dirname inside the output file. If dirname does not exist
 * in the output file, it will be created. Otherwise, contents of the col collection will be appended to an existing
 * directory.
 *
 * If the optional subdirectory name is specified (subdirname parameter, defaults to empty string) then the
 * contents of the collection will be written to "dirname/subdirname". If the "subdirname" directory does not
 * exist inside the "dirname" directory, it will be created.
 *
 */
void JPetWriter::writeCollection(const TCollection* col, const char* dirname, const char* subdirname)
{

  TDirectory* current =  fFile->GetDirectory(dirname);

  if (!current) {
    current = fFile->mkdir(dirname);
  }

  assert(current);

  // use a subdirectory if requested by user
  if (!std::string(subdirname).empty()) {

    if (current->GetDirectory(subdirname)) {
      current = current->GetDirectory(subdirname);
    } else {
      current = current->mkdir(subdirname);
    }
  }

  assert(current);

  current->cd();

  TIterator* it = col->MakeIterator();

  TObject* obj;
  while ((obj = it->Next())) {
    obj->Write();
  }

  fFile->cd();
}
Example #10
0
   TLegend* legend(THStack* stack, Option_t* option = "lp", Bool_t addColor = kFALSE, Int_t token = -1,
                   Float_t xmin = 0.50, Float_t ymin = 0.51, Float_t xmax = 0.85, Float_t ymax = 0.92) {
      if(! stack) return 0;

      TLegend* leg = new TLegend(xmin, ymin, xmax, ymax);
      TList* list = stack->GetHists();
      TIterator* iter = list->MakeIterator();

      TObject* obj = 0;

      //Hist color iterator
      Int_t colorIt = 1;

      while (obj = iter->Next()) {
         if (! obj->InheritsFrom(TH1::Class())) continue;

         if (addColor) {
            hist::color(obj->GetName(), colorIt);
            ++colorIt;
         }

         if (token == -1)
            leg->AddEntry(obj, obj->GetTitle(), option);
         else {
            TString name(obj->GetName());
            TObjArray* a = name.Tokenize("_");
            if (a->GetEntries() <= token)
               leg->AddEntry(obj, obj->GetName(), option);
            else
               leg->AddEntry(obj, a->At(token)->GetName(), option);
         }
      }

      return leg;
   }
Example #11
0
af::Model OutValue::GetModelOfValue()
{
	if(Root.IsNull())
	{
		throw NoLabelInicialisationException("OutValue: label do not inicialised.");
	}

	TIterator TITER;

	Model vallr;
	TITER.Init(Root, false);
	while (TITER.More())
	{
		Model val = (Model)TITER.Value();
		QString name = val.GetName();

		if(name == "Model")
		{
			return val;
		}
		TITER.Next();
	}

	TElement e(Root);
	throw NoExistException("OutValue: Model Of Value do not exists.", e);

	return vallr;
}
Example #12
0
// Method by name
TH1F* eff(const char* name1, const char* name2, const char* name="eff"){

  // Get a list of object and their iterator
  TList* list = gDirectory->GetList() ;
  TIterator* iter = list->MakeIterator();

  // Loop over objects, set the pointers
  TObject* obj;
  TH1F* h1=0;
  TH1F* h2=0;
  TString str1 = Form("%s",name1);
  TString str2 = Form("%s",name2);
  while(obj=iter->Next()) {
    TString objName = obj->GetName();
    if (objName == str1) h1 = (TH1F*) obj;
    if (objName == str2) h2 = (TH1F*) obj;
  }

  // quit if not found
  if (h1 == 0) {
    cout << "Histogram " << name1 << " not found" << endl;
    return 0;
  }
  if (h2 == 0) {
    cout << "Histogram " << name2 << " not found" << endl;
    return 0;
  }

  // Call the method by pointer
  TH1F* temp = eff(h1, h2, name);
  return temp;
}
///
/// load Parameter limits
/// by default the "free" limit is loaded, can be changed to "phys" by command line argument
///
void MethodDatasetsProbScan::loadParameterLimits() {
    TString rangeName = arg->enforcePhysRange ? "phys" : "free";
    if ( arg->debug ) cout << "DEBUG in Combiner::loadParameterLimits() : loading parameter ranges: " << rangeName << endl;
    TIterator* it = w->set(pdf->getParName())->createIterator();
    while ( RooRealVar* p = (RooRealVar*)it->Next() ) setLimit(w, p->GetName(), rangeName);
    delete it;
}
Example #14
0
RooFitResult *breakDownFit(RooSimultaneous *m, RooAbsData *d, RooRealVar *mass, bool precondition = false){
	if(precondition){
		 const char *catsName = m->indexCat().GetName();
		 TIterator *it = m->indexCat().typeIterator();
		 while(RooCatType* ci = dynamic_cast<RooCatType*>(it->Next())) {
			 const Text_t *catLabel = ci->GetName();
			 RooAbsPdf *pdf = m->getPdf(Form("%s",catLabel));
			 RooAbsData *reduced = d->reduce(SelectVars(*mass),Cut(Form("%s==%s::%s",catsName, catsName, catLabel)));
			 RooFitResult *r = pdf->fitTo(*reduced,PrintLevel(-1),Save(),
					 Minimizer("Minuit2","migrad"),Strategy(0),Hesse(false),Minos(false),Optimize(false)
					 );
			 cout << catsName << " " << catLabel << " M2migrad0 " << r->status() << endl;
			 if(r->status()!=0){
				 RooFitResult *r = pdf->fitTo(*reduced, PrintLevel(-1), Save());
				 cout << catsName << " " << catLabel << " Mmigrad1 " << r->status() << endl;
			 }
		 }
	}

	RooFitResult *r = m->fitTo(*d, Save(), PrintLevel(-1),
			Strategy(0));
	cout << "Global fit Mmigrad0 " << r->status() << endl;
	if(r->status()!=0){
	 RooFitResult *r = m->fitTo(*d, PrintLevel(-1), Save(),
			 Minimizer("Minuit","minimize"),Strategy(2));
	 cout << "Global fit Mminimize2 " << r->status() << endl;
	 return r;
	}

	return r;
}
Example #15
0
void LHCOWriter::AnalyseJets()
{
  Jet *element;
  Track *track;
  Int_t counter;

  fItJet->Reset();
  while((element = static_cast<Jet*>(fItJet->Next())))
  {
    if(element->TauTag != 0) continue;

    Reset();

    counter = 0;
    fItTrack->Reset();
    while((track = static_cast<Track*>(fItTrack->Next())))
    {
      if(element->P4().DeltaR(track->P4()) < 0.5) ++counter;
    }

    fIntParam[1] = 4;

    fDblParam[0] = element->Eta;
    fDblParam[1] = element->Phi;
    fDblParam[2] = element->PT;
    fDblParam[3] = element->Mass;
    fDblParam[4] = counter;
    fDblParam[5] = element->BTag;
    fDblParam[6] = element->EhadOverEem;

    Write();
  }
}
Example #16
0
   void colors(TCanvas* canvas, Color_t color = 1) {
      if(! canvas) return 0;

      TList* list = canvas->GetListOfPrimitives();
      TIterator* iter = list->MakeIterator();

      TObject* obj = 0;

      //Hist color iterator
      Int_t colorIt = color;

      while (obj = iter->Next()) {
         if (! obj->InheritsFrom(TH1::Class())) continue;

         //yellow
         if (colorIt == 5)
            ++colorIt;

         hist::color(obj->GetName(), colorIt);
         if (colorIt == 40)
            colorIt = 1;
         else 
            ++colorIt;
      }
   }
Example #17
0
   void yaxis(const char* patORpfx, const char* title) {
      TRegexp reg(patORpfx, kFALSE);

      TList* list = gDirectory->GetList() ;
      TIterator* iter = list->MakeIterator();

      TObject* obj = 0;

      while (obj = iter->Next()) {
         if (! (obj->InheritsFrom(TH1::Class()) || obj->InheritsFrom(THStack::Class()))) continue;

         TString name = obj->GetName();

         if (TString(patORpfx).MaybeRegexp()) {
            if (TString(obj->GetName()).Index(reg) < 0 ) continue;
         } else if (! name.BeginsWith(patORpfx)) continue;

         if (obj->InheritsFrom(TH1::Class()))
            ((TH1*)obj)->GetYaxis()->SetTitle(title);
         if (obj->InheritsFrom(THStack::Class())) {
            ((THStack*)obj)->Draw();
            ((THStack*)obj)->GetYaxis()->SetTitle(title);
         }
      }
   }
Example #18
0
   void normalize(const char* patORpfx) {
      TRegexp reg(patORpfx, kFALSE);

      TList* list = gDirectory->GetList() ;
      TIterator* iter = list->MakeIterator();

      TObject* obj = 0;

      while (obj = iter->Next()) {
         if (! obj->InheritsFrom(TH1::Class())) continue;

         TString name = obj->GetName();

         if (TString(patORpfx).MaybeRegexp()) {
            if (TString(obj->GetName()).Index(reg) < 0 ) continue;
         } else if (! name.BeginsWith(patORpfx)) continue;

         Double_t integral = 0;

         if (obj->InheritsFrom(TH2::Class()))
            integral = ((TH2*)obj)->Integral();
         else
            integral = ((TH1*)obj)->Integral();

         if (integral) {
            ((TH1*)obj)->Sumw2();
            ((TH1*)obj)->Scale(1./integral);
         }
      }
   }
Example #19
0
///
/// Fills vector with floating pars names
///
void Utils::getParameters(const RooFitResult &result, std::vector<TString> &names){
	RooArgList pars           = result.floatParsFinal();
	TIterator * it            = pars.createIterator();
	while(RooRealVar* p = (RooRealVar*) it->Next()){
		names.push_back(TString(p->GetName()));
	}
};
void PDF_GLWADS_DKDpi_K3pi::setObservables(config c)
{
	switch(c)
	{
		case truth:{
					   setObservablesTruth();
					   break;
				   }
		case toy:{
					 setObservablesToy();
					 break;
				 }
		case lumi1fb:{
						 obsValSource = "1fb-1, ExpNll/sept2012K3PIResult.root";
						 TString File = this->dir+"/ExpNll/sept2012K3PIResult.root";
						 TFile *fr = TFile::Open(File);
						 RooFitResult *r = (RooFitResult*)fr->Get("fitresult_model_reducedData_binned");
						 assert(r);
						 TIterator* it = observables->createIterator();
						 while ( RooRealVar* pObs = (RooRealVar*)it->Next() )
						 {
							 RooRealVar* pRes = (RooRealVar*)r->floatParsFinal().find(obsTmkToMalcolm(pObs->GetName()));
							 pObs->setVal(pRes->getVal());
						 }
						 fr->Close();
						 delete r;
						 delete fr;
						 break;
					 }
		case lumi3fb:{
						 obsValSource = "3fb-1 ANA v7 unblind"; // https://twiki.cern.ch/twiki/pub/LHCbPhysics/B2D0K/LHCb-ANA-2014-071-v7.pdf (see Vavas email 04/08/15)

						 // these get transformed over from the new inputs using ExpNll/transportGLWADS_new_to_old.py
						 // in the case of the DK only (robust) combination some of the observables don't exist
						 // usemap as the temp store
						 std::map< TString, double > vals;
						 vals["rkp_k3pi_obs"]      =  0.0793;
						 vals["afav_dk_k3pi_obs"]  =  -0.0004;
						 vals["afav_dpi_k3pi_obs"] =  0.0;
						 vals["rp_dk_k3pi_obs"]    =  0.018369;
						 vals["rm_dk_k3pi_obs"]    =  0.009611;
						 vals["rp_dpi_k3pi_obs"]   =  0.003683;
						 vals["rm_dpi_k3pi_obs"]   =  0.003857;

						 // now can loop the observables and set the values
						 TIterator* it = observables->createIterator();
						 while ( RooRealVar* pObs = (RooRealVar*)it->Next() ){
							 pObs->setVal(vals[pObs->GetName()]);
						 }

						 vals.clear();
						 break;
				}
		default:{
					cout << "PDF_GLWADS_DKDpi_K3pi::setObservables() : ERROR : config "+ConfigToTString(c)+" not found." << endl;
					exit(1);
				}
	}
}
Example #21
0
void printMassFrom2DParameters(RooWorkspace myws, TPad* Pad, bool isPbPb, string pdfName, bool isWeighted)
{
  Pad->cd();
  TLatex *t = new TLatex(); t->SetNDC(); t->SetTextSize(0.026); float dy = 0.025; 
  RooArgSet* Parameters = (RooArgSet*)myws.pdf(pdfName.c_str())->getParameters(RooArgSet(*myws.var("invMass"), *myws.var("ctau"), *myws.var("ctauErr")))->selectByAttrib("Constant",kFALSE);
  TIterator* parIt = Parameters->createIterator(); 
  for (RooRealVar* it = (RooRealVar*)parIt->Next(); it!=NULL; it = (RooRealVar*)parIt->Next() ) {
    stringstream ss(it->GetName()); string s1, s2, s3, label; 
    getline(ss, s1, '_'); getline(ss, s2, '_'); getline(ss, s3, '_');
    // Parse the parameter's labels
    if(s1=="invMass" || s1=="ctauErr" || s1=="ctau"){continue;} else if(s1=="MassRatio"){continue;} 
    else if(s1=="One"){continue;} else if(s1=="mMin"){continue;} else if(s1=="mMax"){continue;}
    if(s1=="RFrac2Svs1S"){ s1="R_{#psi(2S)/J/#psi}"; } 
    else if(s1=="rSigma21"){ s1="(#sigma_{2}/#sigma_{1})"; } 
    else if(s1.find("sigma")!=std::string::npos || s1.find("lambda")!=std::string::npos || s1.find("alpha")!=std::string::npos){
      s1=Form("#%s",s1.c_str());
    }
    if(s2=="PbPbvsPP")   { s2="PbPb/PP";  }
    else if(s2=="Jpsi")  { s2="J/#psi";   } 
    else if(s2=="Psi2S") { s2="#psi(2S)"; }
    else if(s2=="Bkg")   { s2="bkg";      }
    else if(s2=="CtauRes")  { continue; }
    else if(s2=="JpsiNoPR") { continue; }
    else if(s2=="JpsiPR")   { continue; }
    else if(s2=="Psi2SNoPR"){ continue; }
    else if(s2=="Psi2SPR")  { continue; }
    else if(s2=="BkgNoPR")  { continue; }
    else if(s2=="BkgPR")    { continue; }
    else if(s2=="Bkg" && (s1=="N" || s1=="b")) { continue; }
    else {continue;}
    if(s3!=""){
      label=Form("%s_{%s}^{%s}", s1.c_str(), s2.c_str(), s3.c_str());
    } 
    else {
      label=Form("%s^{%s}", s1.c_str(), s2.c_str());
    }
    // Print the parameter's results
    if(s1=="N"){ 
      t->DrawLatex(0.20, 0.76-dy, Form((isWeighted?"%s = %.6f#pm%.6f ":"%s = %.0f#pm%.0f "), label.c_str(), it->getValV(), it->getError())); dy+=0.045; 
    }
    else if(s1.find("#sigma_{2}/#sigma_{1}")!=std::string::npos){ 
      t->DrawLatex(0.20, 0.76-dy, Form("%s = %.3f#pm%.3f ", label.c_str(), it->getValV(), it->getError())); dy+=0.045; 
    }
    else if(s1.find("sigma")!=std::string::npos){ 
      t->DrawLatex(0.20, 0.76-dy, Form("%s = %.2f#pm%.2f MeV/c^{2}", label.c_str(), it->getValV()*1000., it->getError()*1000.)); dy+=0.045; 
    }
    else if(s1.find("lambda")!=std::string::npos){ 
      t->DrawLatex(0.20, 0.76-dy, Form("%s = %.4f#pm%.4f", label.c_str(), it->getValV(), it->getError())); dy+=0.045; 
    }
    else if(s1.find("m")!=std::string::npos){ 
      t->DrawLatex(0.20, 0.76-dy, Form("%s = %.5f#pm%.5f GeV/c^{2}", label.c_str(), it->getValV(), it->getError())); dy+=0.045; 
    }
    else { 
      t->DrawLatex(0.20, 0.76-dy, Form("%s = %.4f#pm%.4f", label.c_str(), it->getValV(), it->getError())); dy+=0.045; 
    }
  }
};
Example #22
0
///
/// Set each parameter in setMe to the value found in values.
/// Do nothing if parameter is not found in values.
///
void Utils::setParameters(const RooAbsCollection* setMe, const RooAbsCollection* values)
{
	TIterator* it = setMe->createIterator();
	while ( RooRealVar* p = (RooRealVar*)it->Next() ){
		RooRealVar *var = (RooRealVar*)values->find(p->GetName());
		if ( var ) p->setVal(var->getVal());
	}
	delete it;
}
Example #23
0
//
// Randomize all parameters of a set defined in a given
// workspace.
//
void Utils::randomizeParameters(RooWorkspace* w, TString setname)
{
	TIterator* it = w->set(setname)->createIterator();
	while ( RooRealVar* p = (RooRealVar*)it->Next() ){
		if ( p->isConstant() ) continue;
		// sample from uniform distribution
		p->randomize();
	}
}
Example #24
0
///
/// Load a named parameter range for a list of parameters.
///
/// \param set - The list holding the parameters.
/// \param limitname - Name of the limit to set.
///
void Utils::setLimit(const RooAbsCollection* set, TString limitname)
{
	RooMsgService::instance().setGlobalKillBelow(ERROR);
	TIterator* it = set->createIterator();
	while ( RooRealVar* p = (RooRealVar*)it->Next() ){
		p->setRange(p->getMin(limitname), p->getMax(limitname));
	}
	RooMsgService::instance().setGlobalKillBelow(INFO);
}
Example #25
0
   void drawsame(const char* canvasName, const char* patORpfx,Option_t* drawOption = "") {
     //     cout << "testing this method" << endl;
     TRegexp reg(patORpfx, kFALSE);
     TList* list = gDirectory->GetList() ;
     //     cout << "this bleeping directory has " << gDirectory->GetNkeys() << "things in it" << endl;
     TIterator* iter = list->MakeIterator();
     
     TObject* obj = 0;
     TObject* canvas = 0;
     Bool_t makeCanvas = false;
     
     canvas = gROOT->GetListOfCanvases()->FindObject(canvasName);
     //If canvas does not exist, remember to create it
     //     cout << "found our canvas" << endl;
     if (! canvas) makeCanvas = true;
     
     while (obj = iter->Next()) {
       //       cout << "We have an object" << endl;
       if (! obj->InheritsFrom(TH1::Class())) continue;
       
       TString name = obj->GetName();
       //       cout << "Testing object of name " << name << endl;
       
       //       if (TString(patORpfx).MaybeRegexp()) { THIS BASICALLY ADDS IT IF IT HAS A BLEEPING PULSE
       if (TString(name).Contains(patORpfx)) {
	 //	 cout << "possible match" << endl;
	 if (TString(obj->GetName()).Index(reg) < 0 ) {
	   //	   cout << "not a match here" << endl;
	   continue;
	 } 
	 else if (! name.BeginsWith(patORpfx)) {
	   //	   cout << "mismatched beginning" << endl;
	   continue;
	 }
       
	 
	 if (makeCanvas) {
	   canvas = new TCanvas(canvasName, canvasName);
	   makeCanvas = false;
	 }
	 
	 ((TH1*)obj)->UseCurrentStyle();
	 ((TCanvas*)canvas)->cd();
	 if (!((TCanvas*)canvas)->GetListOfPrimitives()->GetEntries()) {
	   //	   cout << "Drawing with non-same option" << endl;
	   ((TH1*)obj)->Draw(Form("%s", drawOption));
	 }
	 else {
	   //	   cout << "Drawing with the same option" << endl;
	   ((TH1*)obj)->Draw(Form("SAME%s", drawOption));
	 }
       }
     }
     
     hist::colors((TCanvas*)canvas);

   }
Example #26
0
void FitterUtils::initiateParams(RooArgSet* parset)
{
   RooRealVar *var;
   TIterator *iter = parset->createIterator();

   while((var = (RooRealVar*) iter->Next()))
   {
      if ( !var->isConstant() ) var->randomize();
   }
}
Example #27
0
void deleteHistos() {
   // Delete all existing histograms in memory
   TObject* obj;
   TList* list = gDirectory->GetList() ;
   TIterator* iter = list->MakeIterator();
   while (obj=iter->Next()) {
     if (obj->IsA()->InheritsFrom(TH1::Class()) ||
         obj->IsA()->InheritsFrom(TH2::Class()) ) {delete obj;}
   }
}
Example #28
0
void GetNominalValueNuisancePara(){
    TIterator *it = mc->GetNuisanceParameters()->createIterator();
    RooRealVar *var = NULL;
    if (MapNuisanceParamNom.size() > 0) MapNuisanceParamNom.clear();
    std::cout << "Nuisance parameter names and values" << std::endl;
    while ((var = (RooRealVar*)it->Next()) != NULL){
      const double val = var->getVal();
      MapNuisanceParamNom[(string)var->GetName()] = val;
    }
    return;
 }
Example #29
0
  // Multiply everything by a scale factor
  void normalize_all_by_single_SF(double factor) {
    TList* list = gDirectory->GetList();
    TIterator* iter = list->MakeIterator();

    TObject* obj = 0;
    while (obj = iter->Next()) {
      if (! obj->InheritsFrom(TH1::Class())) continue;

      ((TH1F*)obj)->Scale(factor);
    }
  }
Example #30
0
  // Sumw2 all your bleep if you're a muppet (like Tom) and forgot to do it in
  // your analysis code
  void sumw2Everything() {
    TList* list = gDirectory->GetList();
    TIterator* iter = list->MakeIterator();

    TObject* obj = 0;
    while (obj = iter->Next()) {
      if (! obj->InheritsFrom(TH1::Class())) continue;

      ((TH1F*)obj)->Sumw2();
    }
  }