Esempio n. 1
0
//============================================================
// <T>将尾部项存入文件。</T>
//
// @param out 输出文件流。
//============================================================
void FCsvFooters::Store(TDataOutput& out){
   FDictionary<FCsvFooter*>::TIteratorC it = _pFooters->IteratorC();
   TString foot = TC("@footer.name\n");
   TBool showLabel = EFalse;
   TBool showDescription = EFalse;
   TInt count = 0;
   TInt lastFooterIndex = _pFooters->Count() - 1;
   while(it.Next()){
      FCsvFooter* pFoot = it.Value();
      foot.Append(pFoot->Name());
      if(count != lastFooterIndex){
         foot.Append(',');
      }else{
         foot.Append('\n');
      }

      TInt labelLength = RString::Length(pFoot->Label());
      if(labelLength){
         showLabel = ETrue;
      }
      TInt desLength = RString::Length(pFoot->Description());
      if(desLength){
         showDescription= ETrue;
      }
      ++count;
   }
   if(showLabel){
      foot.Append(TC("@footer.label\n"));
      count = 0;
      it.Reset();
      while(it.Next()){
         FCsvFooter* pFoot = it.Value();
         foot.Append(pFoot->Label());
         if(count != lastFooterIndex){
            foot.Append(',');
         }else{
            foot.Append('\n');
         }
      }
   }
   if(showDescription){
      foot.Append(TC("@head.description\n"));
      count = 0;
      it.Reset();
      while(it.Next()){
         FCsvFooter* pFoot = it.Value();
         foot.Append(pFoot->Description());
         if(count != lastFooterIndex){
            foot.Append(',');
         }else{
            foot.Append('\n');
         }
      }
   }
   out.Write((TCharC*)foot, foot.Length());
}
Esempio n. 2
0
//============================================================
// <T>将头部存入文件。</T>
//
// @param out 文件输出流。
//============================================================
void FCsvHeads::SaveToFile(TDataOutput& out){
   FDictionary<FCsvHead*>::TIteratorC it = _pHeads->IteratorC();
   TString head = TC("@head.name\n");
   TBool showLabel = EFalse;
   TBool showDescription = EFalse;
   TInt count = 0;
   TInt headCount = _pHeads->Count() - 1;
   while(it.Next()){
      FCsvHead* pHead = it.Value();
      head.Append(pHead->Name());
      if(count != headCount){
         head.Append(',');
      }else{
         head.Append('\n');
      }
      TInt labelLength = RString::Length(pHead->Label());
      if(labelLength){
         showLabel = ETrue;
      }
      TInt desLength = RString::Length(pHead->Description());
      if(desLength){
         showDescription= ETrue;
      }
      ++count;
   }
   if(showLabel){
      head.Append(TC("@head.label\n"));
      count = 0;
      it.Reset();
      while(it.Next()){
         FCsvHead* pHead = it.Value();
         head.Append(pHead->Label());
         if(count != headCount){
            head.Append(',');
         }else{
            head.Append('\n');
         }
      }
   }
   if(showDescription){
      head.Append(TC("@head.description\n"));
      count = 0;
      it.Reset();
      while(it.Next()){
         FCsvHead* pHead = it.Value();
         head.Append(pHead->Description());
         if(count != headCount){
            head.Append(',');
         }else{
            head.Append('\n');
         }
      }
   }
   out.Write((TCharC*)head, head.Length());
}
Esempio n. 3
0
//________________________________________________________
TObjArray GFOverlay::FindAllBetween(const TString &text,
				    const char *startStr, const char *endStr) const
{
  TObjArray result; // TObjStrings...

  if (text.Contains(startStr, TString::kIgnoreCase)) {
    Ssiz_t start = text.Index(startStr);
    while (start != kNPOS && start < text.Length()) {
      TString name = this->FindNextBetween(text, start, startStr, endStr);
      if (!name.IsNull()) {
	result.Add(new TObjString(name));
	start = text.Index(startStr, start + name.Length() + TString(endStr).Length());
      } else {
	break;
      }
    }
  }

  return result;
}
Esempio n. 4
0
void TGo4EventInfo::WorkWithEvent(const char* itemname)
{
   EventLbl->setText(itemname);

   bool ismbs = QString(itemname).contains(defMbsEventName);

   MbsPrintBox->setEnabled(ismbs);
   TString mbsitem = Browser()->FindItemInAnalysis(defMbsEventName);
   MbsButton->setEnabled(!ismbs && (mbsitem.Length()>0));
   setFocus();
}
Esempio n. 5
0
TString::TString( const TString& s )
{
    data = NULL;

    const char *c = s.c_str();
    int len = s.Length();
    Realloc( len );

    if( len>0 )
        strcpy( data, c );
}
Esempio n. 6
0
// ---------------------------------------------------------------------------------------------
// The SLAC version
bool relocateStatBox (float x1, float y1, float x2=-1, float y2=-1, TString newname = "") 
{ 
  TPaveStats *st = (TPaveStats*)gPad->GetPrimitive("stats");
  if (0 == st) {cerr<<"Can't find stat box in pad"<<endl; return 0;}
  if (newname.Length() > 0) st->SetName(newname);
  st->SetX1NDC(x1);
  if (x2 != -1) st->SetX2NDC(x2);
  st->SetY1NDC(y1);
  if (y2 != -1) st->SetY2NDC(y2);
  st->Draw();
  return 1;
}
TH1* getHistogram(TFile* inputFile, const TString& dqmDirectory, const TString& meName)
{
    TString histogramName = dqmDirectory;
    if ( histogramName.Length() > 0 && !histogramName.EndsWith("/") ) histogramName.Append("/");
    histogramName.Append(meName);
    std::cout << "histogramName = " << histogramName.Data() << std::endl;

    TH1* histogram = (TH1*)inputFile->Get(histogramName.Data());
    std::cout << "histogram = " << histogram << std::endl;

    return histogram;
}
Esempio n. 8
0
void addCut(TString newcutname, TString newcut) {

  if(allcuts.Length()==0) 
    allcuts+=("("+newcut+")");
  else 
    allcuts+=(" && ("+newcut+")");

  cutSet.push_back(newcutname);
  cutCascade.push_back(allcuts);

  return;
}
Esempio n. 9
0
Bool_t KVAvailableRunsFile::ExtractDateFromFileName(const Char_t* name, KVDatime& date)
{
	// We assume that 'name' is the name of a run of the type of this available runs file.
	// We attempt several methods to try to extract a date from 'name'.
	// If successful, we return kTRUE and 'date' contains the result.
	
   //get format string for current dataset
   TString fmt =
       fDataSet->
       GetDataSetEnv(Form("DataSet.RunFileName.%s", GetDataType()));
	Int_t rubbish = fmt.Index("%*");
	if(rubbish>-1) fmt.Remove(rubbish,fmt.Length());
	Int_t run = IsRunFileName(name);
	if(!run) return kFALSE;
	TString basename;
	basename.Form(fmt.Data(), run);
	TString fullname(name);
	if(!fullname.Contains(basename)) return kFALSE;
	if(fullname.Length()==basename.Length()) return kFALSE;
	fullname.Remove(0, basename.Length()+1);
	fullname.ReplaceAll("_"," ");
	fullname.ToUpper();
	if(KVDatime::IsSQLFormat(fullname.Data())){
		date.SetSQLDate(fullname.Data());
		return kTRUE;
	}
	else 
	{
		fullname.ReplaceAll("."," ");
		if(KVDatime::IsGANACQFormat(fullname.Data())){
			date.SetGanacqDate(fullname.Data());
			return kTRUE;
		}
		else if(KVDatime::IsGANACQ2010Format(fullname.Data())){
			date.SetGanacq2010Date(fullname.Data());
			return kTRUE;
		}
	}
	return kFALSE;
}
Esempio n. 10
0
/**
 * Returns a suitable epsFilename build from a file or directory name and
 * histogram name.
 *
 * @param fileOrDirectoryName
 *                            name of the file or directory
 * @param histogramNamw
 *                            name of the histogram
 * @return
 *                            a suitable epsFilename
 */
TString
epsFilename(const TString& fileOrDirectoryName, const TString& histogramName)
{
// {{{
    TString s = fileOrDirectoryName;
    if (s.EndsWith("/")) s.Remove(s.Length()-1);
    s = gSystem->BaseName(s);
    s.ReplaceAll(".root", "");
    s.Append(".").Append(histogramName);
    s.ReplaceAll(".", "_");
    return s;
// }}}
};
Esempio n. 11
0
        inline
        int    IndexOf( const TString&  needle,
                              int              startIdx= 0,
                              enums::Case      sensitivity=  enums::Case::Sensitive )
        const
        {
            if (TCheck)
            {
                if ( startIdx < 0 )                           startIdx= 0;
                if ( startIdx + needle.Length() > length )    return -1;
                if ( needle.Length() == 0  )                  return  startIdx;
            }
            else
            {
                #if defined(ALIB_DEBUG)
                    if (    startIdx < 0
                         || startIdx >= length
                         || needle.Length() == 0    )
                        dbgAStringAlibError( "Non checking and illegal parameters" );
                #endif
            }


            #if defined (__GLIBCXX__)
                const char* foundAt= sensitivity == enums::Case::Sensitive
                     ? strstr    ( ToCString() + startIdx, needle.ToCString() )
                     : strcasestr( ToCString() + startIdx, needle.ToCString() );
                return  foundAt != nullptr ?  foundAt - buffer  :   -1;
            #else
                if ( sensitivity == enums::Case::Sensitive )
                {
                    const char* foundAt=  strstr( ToCString() + startIdx, needle.ToCString() );
                    return  foundAt != nullptr ?  (int) (foundAt - buffer)  :   -1;
                }
                else
                    // there is no strcasestr in windows, we use the slower String version, non-checking
                    return IndexOfSubstring<false>( needle, startIdx , enums::Case::Ignore );
            #endif
        }
Esempio n. 12
0
void bcut::parseCuts(TString cuts){
  vcuts_.clear(); // Starting the parsing every time
  cuts.ReplaceAll(" ", "");
  TString cut;
  int pos;
  do{
    pos = cuts.Index("&&");
    cut = cuts;
    if(pos != -1) cut.Remove(pos, cut.Length());
    vcuts_.push_back(onecut(cut));
    cuts.Remove(0, pos+2);
  } while(pos != -1);
}
//---- NewRendererTest ----------------------------------------------------------------
void NewRendererTest::TestCases() {
	StartTrace(NewRendererTest.TestCases);

	if (t_assertm( !GetTestCaseConfig().IsNull(), "no Tests configured!" )) {
		Server *theServer = Server::FindServer("Server");
		t_assert(theServer != NULL);
		Context ctx;
		Session theSession("TestSession");
		Page *thePage = Page::FindPage("TestPage");
		t_assert(thePage != NULL);
		Role *theRole = Role::FindRole("TestRole");
		t_assert(theRole != NULL);
		theSession.Init("TestSession", ctx);

		AnyExtensions::Iterator<ROAnything, ROAnything, TString> aEntryIterator(GetTestCaseConfig());
		ROAnything roaCaseConfig;
		t_assertm( GetConfig()["RunOnly"].GetSize() == 0L, "running only subset of tests");
		TraceAny(GetConfig()["RunOnly"], "run only config")
		while (aEntryIterator.Next(roaCaseConfig)) {
			TString slotToCheck;
			aEntryIterator.SlotName(slotToCheck);
			Trace("current testslot [" << slotToCheck << "]");
			if ((GetConfig()["RunOnly"].GetSize() == 0L) || GetConfig()["RunOnly"].Contains((const char *) slotToCheck)) {
				std::cerr << ".";
				TString message;
				message << getConfigFileName() << ".any:0 at " << name();
				if (slotToCheck.Length()) {
					message << "." << slotToCheck;
				} else {
					message << ":" << aEntryIterator.Index();
				}
				Context c(GetConfig()["EnvForAllCases"].DeepClone(), roaCaseConfig["Env"].DeepClone(), theServer, &theSession, theRole,
						thePage);
				coast::testframework::PutInStore(roaCaseConfig["TmpStore"], c.GetTmpStore());
				coast::testframework::PutInStore(roaCaseConfig["SessionStore"], c.GetSessionStore());
				TraceAny(roaCaseConfig["Renderer"], "running renderer at [" << slotToCheck << "]");
				String result("[");
				String expected("[");
				expected << roaCaseConfig["Expected"].AsCharPtr("") << "]";
				{
					OStringStream reply(result);
					Renderer::Render(reply, c, roaCaseConfig["Renderer"]);
					reply.flush();
				}
				result.Append(']');
				// message << ":\n" << result;
				assertEqualm(expected, result, message);
			}
		}
	}
Esempio n. 14
0
    // Initializes a new instance of the FileSystemInfo class.
    FileSystemInfo::FileSystemInfo(const TString& path)
    {
        size_t pathLen = path.Length();
        size_t lastPos = pathLen - 1;

        // remove all the '\\'s at the end of the path
        while (lastPos != 0 && path[lastPos] == '\\')
            lastPos--;

        if (lastPos == 0 && path[lastPos] == '\\')
            _path = "";
        else
            _path = path.Substring(0, lastPos + 1);
    }
Esempio n. 15
0
TString round(double n, int e, double d){
  if(d==0) return " - ";
  double b = (int)(n/d*pow(10,e)+0.5);
  b /= pow(10,e);
  TString result; result+= b;
  result.ReplaceAll(" ","");
  if(!result.Contains(".") && e != 0) result += ".";
  
  TString afterdot = result;
  afterdot.Remove(0,afterdot.First(".")+1);
  for(int i=0; i<e-afterdot.Length(); i++)
    result += "0";
  return result;
}
void dealWith_unEqualBinning_ZZ(TString file_name){

  TFile * file_in=new TFile(file_name,"read");
  //  file_in->cd();
  file_in->cd("ll");
  //  ll->cd();
  file_in.ls();
  cout << "listing dir.."<<endl;
  gDirectory->ls();
  gDirectory->cd();
  //  TList * input_p=file_in->GetList();
  //  TList * list_histos=file_in->GetListOfKeys();
  TList * list_histos=gDirectory->GetListOfKeys();
  cout << "--------> histo name: "<< list_histos->At(0)->GetName()<< endl;
  TString file_out=file_name.Remove(file_name.Length() - 5, 5);
  file_out+="_uniformBins.root";
  cout <<" ----> output: "<< file_out<<"\n" << endl;
  TFile *outFile=new TFile(file_out,"recreate");
  outFile->cd();

  for (int i=0;i<list_histos->GetEntries();i++){
    file_in->cd("ll");
    TString histo_name= list_histos->At(i)->GetName();

    //    TH1D * plot=file_in->Get(histo_name);
    TH1D * plot=gDirectory->Get(histo_name);
    //cout << " plot \""<<histo_name<<"\""<< endl;
    cout <<"\treading histo "<< histo_name<< " and rebinning.." << endl;
    cout <<"\t\t integral: "<<plot->Integral() << endl;
    int N_bins=plot->GetNbinsX();
    TH1D * plot_rebin=new TH1D("plot_rebin","plot_rebin",N_bins-2,0,N_bins-2);
    for (int j=1;j<=N_bins;j++)
      plot_rebin->SetBinContent(j,plot->GetBinContent(j+2));
    cout <<"\t\tbin yield starting: "<< plot->Integral()<<" after rebinning: "<<plot_rebin->Integral()  << endl;

    outFile->cd();
    plot_rebin->Write(histo_name);
    delete plot_rebin;
  }

  outFile->Close();
  file_in->Close();

  /*
  list_histos->GetEntries();
  list_histos->At(4)->GetName();
  TH1D * plot=file_in->Get("data_obs");
  */

}
//_____________________________________________________________________________________
int main(int argc, char* argv[]) {
// Default options
	TString outputdir = "SSDLPlots/";
	TString datacard  = "DataCard_SSDL.dat";
	int verbose = 0;
	TString configfile;
	bool cfg = false;
	TString region = "";

// Parse options
	char ch;
	while ((ch = getopt(argc, argv, "d:c:v:m:s:p:lh?")) != -1 ) {
		switch (ch) {
			case 'd': outputdir = TString(optarg); break;
			case 'v': verbose = atoi(optarg); break;
			case 'c': datacard = TString(optarg); break;
			case 'p': configfile = TString(optarg); break;
			case 's': region = TString(optarg); break; 
			case '?':
			case 'h': usage(0); break;
			default:
			cerr << "*** Error: unknown option " << optarg << std::endl;
			usage(-1);
		}
	}

	if(configfile.Length() > 0) {
		cfg = true;
		cout << "Using specified config file: " << configfile << endl;
	}
	else cout << "Using default configuration file: " << outputdir << "/dumperconfig.cfg"<< endl;

	cout << "--------------" << endl;
	cout << "OutputDir is:      " << outputdir << endl;
	cout << "Verbose level is:  " << verbose << endl;
	cout << "--------------" << endl;

	SSDLPlotter *tA;
	if (cfg) tA = new SSDLPlotter(configfile);
	else tA = new SSDLPlotter(outputdir+"/dumperconfig.cfg");
	tA->setOutputDir(outputdir);
	tA->setVerbose(verbose);
	tA->init(datacard);
	tA->doAnalysis();
	if (region != "")	
	  tA->doSMSscans(region);

	delete tA;
	return 0;
}
Esempio n. 18
0
/**
 * Merge all files in folder path with names matching the regular expression filematch into trees in a ROOT file.
 *
 * @param filematch Merge files whose names match this regular expression (default: read all)
 * @param path Merge files in this folder (default: current folder)
 */
void merge_all(const char *filematch = "[0-9]+[a-z]+.out", const char *path = ".")
{
	TFile *outfile = new TFile("out.root","RECREATE"); // create ROOT file
	ifstream infile;
	TSystemDirectory dir(path,path); // open given folder
	TList *files = dir.GetListOfFiles(); // get all files in that folder
	TRegexp re(filematch); // create regular expression from given parameter

	outfile->cd(); // switch current directory to ROOT file
	
	Int_t n = 0;
	for (Int_t i = 0; ; i++){ // for loop incrementing index i
		TObject *f = files->At(i); // get file from folder with index i
		if (f){ // if next file was found
			TString filename = f->GetName(); // get filename
			TString fn = filename;
			fn.Resize(filename.Length() - 4); // shorten filename by extension ".out"
			
			ULong64_t jobnumber;
			char logtype[64];
			double data[1024];
			
			if ((re.Index(filename, &n) == 0) && (sscanf(fn.Data(), "%Ld%s", &jobnumber, logtype) == 2)){ // if filename matches regular expression and contains jobnumber
				infile.open(filename.Data()); // open file
				TNtupleD *tree = (TNtupleD*)outfile->Get(logtype); // get corresponding tree from file
				
				if (!tree) { // if tree does not yet exist
					TString bdescriptor;
					bdescriptor.ReadLine(infile); // read branch descriptor from file header
					bdescriptor.ReplaceAll(" ",":"); // format branch descriptor for root ("x y z" -> "x:y:z")

					tree = new TNtupleD(logtype, logtype, bdescriptor.Data()); // create new tree with name logtype from filename 
					printf("%ss have %i columns\n", logtype, tree->GetNvar());
				}
				else
					infile.ignore(9999, '\n'); // if tree already exists skip file header

				n = tree->GetNvar(); // get number of file columns
				cout << "Adding " << filename << '\n';
				while (1){
					for (int j = 0; j < n; j++) infile >> data[j]; // read values into data array
					if (!infile) break; // if something happened during reading: stop
					tree->Fill(data); // fill data into tree
				}
				infile.close(); // close file
				cout << "Entries: " << tree->GetEntries() << '\n';
			}
		}
		else break;
Esempio n. 19
0
//============================================================
void FCsvLine::SinglePairRefer(TCharC* pValue, TString& result){
   TString refer = pValue;
   TInt length = refer.Length();
   TInt pos = 0;
   while(pos < length){
      TChar cur = refer[pos];
      if(cur == '"' && pos < length - 1){
         if(refer[pos + 1] == '"'){
            ++pos;
         }
      }
      result.Append(cur);
      ++pos;
   }
}
Esempio n. 20
0
bool allInBrackets( const TString& in, char opening_bracket = '(', char closing_bracket = ')' ) 
{
  int n_in = 0;
  for( int ii = 0; ii<in.Length(); ++ii) {
    char c = in[ii]; 
    if( c == opening_bracket ) {
      ++n_in; 
    } else if( c == closing_bracket ) {
      --n_in;
    } else if( c != ' ' && n_in <= 0 ) {
      return false;
    }
  }
  return true;
}
Esempio n. 21
0
TString HiggsPlot::RoundNumber(double n, int e, double d){
  if(d==0) return " - ";
  double neg = 1; if(n*d<0) neg = -1;
  double b = static_cast<int>(neg*n/d*pow(10.,static_cast<double>(e))+0.5);
  b /= pow(10.,static_cast<double>(e))*neg;
  TString result; result+= b;
  result.ReplaceAll(" ","");
  if(!result.Contains(".") && e != 0) result += ".";
  
  TString afterdot = result;
  afterdot.Remove(0,afterdot.First(".")+1);
  for(int i=0; i<e-afterdot.Length(); i++)
    result += "0";
  return result;
}
Esempio n. 22
0
 //_______________________________________________________________________________________________
 //
 // Initialize plugin with all its common values
 //
 Bool_t CreatePlugin()
 {
    // create object
    plugin = new AliAnalysisAlien;
    
    // framework version
    plugin->SetROOTVersion(rootVersion.Data());
    plugin->SetAliROOTVersion(aliVersion.Data());
    
    // additional libraries/includes
    if (addLibs.Length() > 0) plugin->SetAdditionalLibs(addLibs.Data());
    if (addIncludes.Length() > 0) plugin->AddIncludePath(addIncludes.Data());
    
    // runtime tasks
    if (addTaskRuntime.Length() > 0) {
       TObjArray *list = addTaskRuntime.Tokenize(" ");
       TObjArrayIter next(list);
       TObjString *os = 0x0;
       TString sources("");
       while ( (os = (TObjString*)next()) ) {
          const char *taskName = os->GetString().Data();
          addLibs.Append(Form("%s.h %s.cxx", taskName, taskName));
          sources.Append(Form("%s.cxx", taskName));
       }
       plugin->SetAnalysisSource(sources.Data());
    }
    
    // specific setups
    if (targetAlien) {
       ::Info("SetupPlugin::CreatePlugin()", "Setting up for ALIEN");
       return SetupForAlien();
    } else {
       ::Info("SetupPlugin::CreatePlugin()", "Setting up for PROOF");
       return SetupForProof();
    }
 }
Esempio n. 23
0
//_____________________________________________________________________________
THaCut::EvalMode THaCut::ParsePrefix( TString& expr )
{
  // Parse the given expression for a mode prefix (e.g. "OR:")
  // and return its value. If the expression does not have a mode prefix,
  // return the default kAND (=0).
  // The expression is expected to have all whitespace removed.
  // If the prefix was found, it is stripped from the expression.
  // If a mode prefix seems to be present, but is not found in
  // the defined modes, return kModeErr.

  const EvalMode kDefaultMode = kOR;
  const char* const here = "THaCut";

  struct ModeDef_t {
    const char* prefix;
    EvalMode    mode;
  };
  const ModeDef_t mode_defs[] = {
    { "OR", kOR }, { "ANY", kOR }, { "AND", kAND }, { "ALL", kAND },
    { "XOR", kXOR }, { "ONE", kXOR }, { "ONEOF", kXOR }, { 0, kModeErr }
  };

  Ssiz_t colon = expr.Index(":");
  if( colon == kNPOS )
    return kDefaultMode;

  const ModeDef_t* def = mode_defs;
  while( def->prefix ) {
    if( expr.BeginsWith(def->prefix) &&
	static_cast<Ssiz_t>(strlen(def->prefix)) == colon ) {
      expr.Remove(0,colon+1);
      break;
    }
    ++def;
  }
  EvalMode mode = def->mode;

  if( mode == kModeErr ) {
    TString prefix = expr(0,colon);
    Error(here, "Unknown prefix %s", prefix.Data() );
  } else if( expr.Length() == 0 ) {
    Error(here, "expression may not be empty");
    mode = kModeErr;
  }
  if( mode == kModeErr )
    SetBit(kError);
  return mode;
}
Esempio n. 24
0
void bcut::parseWeights(TString weights){
  weights.ReplaceAll(" ", "");
  cutTypes_.clear();
  fWeights_.clear();
  fvWeights_.clear();
  indWeights_.clear();
  TString wgt;
  int pos;
  do{
    pos = weights.Index("*");
    wgt = weights;
    if(pos != -1) wgt.Remove(pos, wgt.Length());
    parseWeight(wgt);
    weights.Remove(0, pos+1);
  } while(pos != -1);
}
Esempio n. 25
0
void bcut::parseWeight(TString wgt){
  cutTypes_.push_back(kFloat);
  fWeights_.push_back(NULL);
  fvWeights_.push_back(NULL);
  indWeights_.push_back(-1);
  constWeights_.push_back(1.);

  if(wgt=="weight")		fWeights_.back() = &baby_base::weight;
  else if(wgt=="w_lumi")	fWeights_.back() = &baby_base::w_lumi;
  else if(wgt=="w_pu")	fWeights_.back() = &baby_base::w_pu;
  else if(wgt=="w_lep")	fWeights_.back() = &baby_base::w_lep;
  else if(wgt=="w_fs_lep")	fWeights_.back() = &baby_base::w_fs_lep;
  else if(wgt=="w_toppt")	fWeights_.back() = &baby_base::w_toppt;
  else if(wgt=="w_btag")	fWeights_.back() = &baby_base::w_btag;
  else if(wgt=="eff_trig")	fWeights_.back() = &baby_base::eff_trig;
  else if(wgt.Contains("[")){ // if weight is a vector element
    TString index_s(wgt);
    wgt.Remove(wgt.Index("["), wgt.Length());
    index_s.Remove(0, index_s.Index("[")+1);
    index_s.Remove(index_s.Index("]"), index_s.Length());
    indWeights_.back() = index_s.Atoi();
    cutTypes_.back() = kvFloat;
    if(wgt=="w_pdf")        fvWeights_.back() = &baby_base::w_pdf;
    else if(wgt=="sys_pdf") fvWeights_.back() = &baby_base::sys_pdf;
    else if(wgt=="sys_isr") fvWeights_.back() = &baby_base::sys_isr;
    else if(wgt=="sys_mur") fvWeights_.back() = &baby_base::sys_mur;
    else if(wgt=="sys_muf") fvWeights_.back() = &baby_base::sys_muf;
    else if(wgt=="sys_murf") fvWeights_.back() = &baby_base::sys_murf;
    else if(wgt=="sys_trig") fvWeights_.back() = &baby_base::sys_trig;
    else if(wgt=="sys_lep") fvWeights_.back() = &baby_base::sys_lep;
    else if(wgt=="sys_fs_lep") fvWeights_.back() = &baby_base::sys_fs_lep;
    else if(wgt=="sys_bctag") fvWeights_.back() = &baby_base::sys_bctag;
    else if(wgt=="sys_fs_bctag") fvWeights_.back() = &baby_base::sys_fs_bctag;
    else if(wgt=="sys_udsgtag") fvWeights_.back() = &baby_base::sys_udsgtag;
    else if(wgt=="sys_fs_udsgtag") fvWeights_.back() = &baby_base::sys_fs_udsgtag;
    else {
      cout<<"Weight \""<<wgt<<" not defined. Add it to bcut::parseWeight in bcut.cpp"<<endl;
      exit(0);
    }
  }else if(wgt.Atof()>0) {
    constWeights_.back() = wgt.Atof();
    cutTypes_.back() = kConst;
  } else {
    cout<<"Weight \""<<wgt<<" not defined. Add it to bcut::parseWeight  in bcut.cpp"<<endl;
    exit(0);
  }   
}
TH1* getHistogram(TFile* inputFile, const TString& dqmDirectory, const TString& meName)
{  
  TString histogramName = dqmDirectory;
  if ( histogramName.Length() > 0 && !histogramName.EndsWith("/") ) histogramName.Append("/");
  histogramName.Append(meName);

  TH1* histogram = (TH1*)inputFile->Get(histogramName.Data());
  std::cout << "histogramName = " << histogramName.Data() << ": histogram = " << histogram;
  if ( histogram ) std::cout << ", integral = " << histogram->Integral();
  std::cout << std::endl; 

  if ( !histogram->GetSumw2N() ) histogram->Sumw2();

  if ( histogram->GetDimension() == 1 ) histogram->Rebin(5);

  return histogram;
}
Esempio n. 27
0
// For new macro - all variables to plot
void addVariable(TString newvar, TString newxtitle, TString newytitle, unsigned int newBins, double newFirstBin, double newLastBin, bool drawThis = true, bool printThis = true) {
  variables.push_back(newvar);
  if(drawThis) allVarsToPlot.push_back(newvar);
  if(printThis) allVarsToPrint.push_back(newvar);
  xTitles[newvar] = newxtitle;
  if(newytitle.Length()>0) 
    yTitles[newvar] = newytitle;
  else
    yTitles[newvar] = "Events/";
  binsUInt[newvar] = newBins;
  firstBinsDouble[newvar] = newFirstBin;
  lastBinsDouble[newvar] = newLastBin;
  drawVar[newvar] = drawThis;
  printVar[newvar] = printThis;
  nVars=variables.size();
  return;
}
Esempio n. 28
0
const char *Next(int &kind,int &idx,double &exe,double &heap,double &free,double &inc) {		  
  if(!inp) return 0;
  kind=0;idx=0;exe=0;heap=0;free=0,inc=0;
  TString ts;
  char *endMaker,*clear,*ctr,*doPs,*fr,*to,*and;
  while(fgets(line,500,inp)) {
    doPs = strstr(line,"doPs for");
    if (!doPs) 				continue;
    endMaker = strstr(line,"EndMaker");
    clear    = strstr(line,"Clear");
    ctr      = strstr(line,"constructor");
    kind = 0;
    if (ctr     ) kind = 1;
    if (clear   ) kind = 2;
    if (endMaker) kind = 3;
    if (!kind)				continue;
    fr = doPs+8 +strspn(doPs+8," \t");
    to = strstr(fr,":");
    ts = ""; ts.Append(fr,to-fr);
    if (!ts.Length()) 			continue;
    fr = strstr(fr,"total");  if (!fr) 	continue;
    fr = strstr(fr,"="    );  if (!fr) 	continue;
    exe = atof(fr+1);
    fr  = strstr(fr,"heap" ); if (!fr) 	continue;
    fr  = strstr(fr,"="    ); if (!fr) 	continue;
    heap = atof(fr+1);
    and  = strstr(fr,"and");
    if (and) free = atof(and+3);
    fr  = strstr(fr,"("    ); if (!fr) 	continue;
    inc = atof(fr+1);
    if (kind==1) 			continue;
    TNamed *tn = (TNamed*)hash.FindObject(ts.Data());
    if (!tn) {
      tn = new TNamed(ts.Data(),"");
      hash.Add(tn);
      fNMakers++;
      tn->SetUniqueID((UInt_t)fNMakers);
      mArray.AddAtAndExpand(tn,fNMakers);
    }
    idx = tn->GetUniqueID();
    return tn->GetName();
  }
  fclose(inp); inp = 0;
  return 0;  
}};
Esempio n. 29
0
  /** 
   * Get the size of a given run 
   * 
   * @param in       Input stream 
   * @param runNo    Run number to search for 
   * @param mc       True for simulations 
   * @param minSize  Least size 
   * 
   * @return true on success 
   */
  Bool_t GetSize(std::istream& in, ULong_t runNo, 
		 Bool_t mc, ULong_t minSize=100000)
  {
    TString line;
    TString tgt2(mc ? "table_row_right" : "ESDs size");
    Int_t   cnt = 0;
    do {
      line.ReadLine(in);
      if (!line.Contains(tgt2)) continue;
      cnt++;
      if (mc && cnt < 3) continue;
      if (!mc) line.ReadLine(in);
      if (fDebug) Info("", line);

      TString ssiz;
      if (mc) { 
	Int_t first       = line.Index(">");
	Int_t last        = line.Index("<",first+1);
	if (first == kNPOS || last == kNPOS) { 
	  Error("GetDir", "Failed to get directory from %s", line.Data());
	  return false;
	}
	ssiz = line(first+1, last-first-1);
      }
      else {
	for (Int_t i = 0; i < line.Length(); i++) { 
	  if (line[i] == '<') break;
	  if (line[i] == ' ' || line[i] == '\t' || line[i] == ',') continue;
	  ssiz.Append(line[i]);
	}
      }
      Long_t size = ssiz.Atoll();
      if (fDebug) Info("", "Got run %lu %lu" , runNo, size);
      if (size < 0) {
	Error("GetSize", "Failed to extract size for run %lu", runNo);
	return false;
      }
      if (ULong_t(size) < minSize) {
	Warning("GetSize","Run %lu does not have enough events %lu",runNo,size);
	return false;
      }
      break;
    } while (!in.eof());
    return true;
  }
Esempio n. 30
0
TCanvas * MediPixAlgo::DrawInSeparateWindow(vector<TH2 *> g , MSG::Level vl){

	if(g.empty()) {
		Log << vl << "Nothing to draw ... return NULL pointer" << endreq;
		return 0x0;
	}
	TString cname; // take the cname from the first histo
	if(vl == MSG::DEBUG) {
		vector<TH2 *>::iterator i = g.begin();
		Log << vl << "Attempting to draw in a separate canvas the following objects : " << endreq;
		for( ; i != g.end() ; i++){
			if(!cname.Length()) {cname = (*i)->GetName();}
			Log << vl << (*i)->GetName() << " with " << (*i)->GetEntries() << " entries "<< endreq;
		}
	}
	///////////////////////////////////////////////////////////////////
	TCanvas * c11 = new TCanvas("TH2","TH2");
	int ngraphs = (int)g.size();
	int xdiv = floor( TMath::Sqrt(ngraphs) );
	int ydiv = ceil( (double)ngraphs/(double)xdiv );
	c11->Divide(xdiv, ydiv);

	vector<TH2 *>::iterator itr = g.begin();
	int cntr2 = 0;
	double posx = 0.;
	double posy = 0.;
	for ( ; itr != g.end(); itr++) {

		c11->cd(cntr2+1);
		(*itr)->Draw("colz");
		//(*itr)->SetT
		(*itr)->GetXaxis()->SetLabelSize(0.05);
		(*itr)->GetYaxis()->SetLabelSize(0.05);

		posx = (*itr)->GetBinCenter( 1 );
		posy = (*itr)->GetMaximum() * 0.9;

		TLatex l1;
		l1.SetTextSize(0.05);
		l1.DrawLatex(posx, posy, (*itr)->GetName() );

		cntr2++;
	}
	return c11;
}