Beispiel #1
0
void DrawAllHistos(TString filename,Bool_t isMC,TString format){
  
  //  setTDRStyle("logredblue");

  std::vector<TH1F*> h1vec;
  std::vector<TH2F*> h2vec;
  
  h1vec.clear();
  h2vec.clear();

  TFile *file = TFile::Open(filename);

  // to get the names of the conditions
  TObjArray *conditions_from_name = filename.Tokenize("_"); 
  TString sa = conditions_from_name->At(1)->GetName();
  TString sb = conditions_from_name->At(3)->GetName();
  sb.ReplaceAll(".root","");

  file->cd();
  
  TDirectory *stardir = gDirectory;
  TObject *thesourcedir;
  TIter nextdir(stardir->GetListOfKeys());

  while((thesourcedir=nextdir())){
    
    TString dirName = thesourcedir->GetName();
    
    stardir->cd(dirName);
    TDirectory *current_sourcedir = gDirectory;
    TH1::AddDirectory(kFALSE);

    std::cout << "*************************" <<std::endl;
    std::cout << "Reading Directory: " << dirName <<std::endl;
    
    TObject *obj;
    TIter next(current_sourcedir->GetListOfKeys());

    while ((obj=next())) {
      
      TString objName =obj->GetName();

      if(objName.Contains("pfx")) continue;

      if (objName.Contains("h2") && !objName.Contains("pfx")) {

	//std::cout << "Reading: " << obj->GetName() <<std::endl;

	TH2F* h2 = (TH2F*)file->Get(dirName+"/"+objName);
	h2->SetName(objName+dirName);
	h2vec.push_back(h2);

	TCanvas *c = new TCanvas(h2->GetName(),h2->GetName(),800,600);
	c->cd();
	gPad->SetTopMargin(0.08);
	gPad->SetRightMargin(0.15);
	h2->SetStats(kFALSE);
	h2->Draw("colz");
	c->Draw();
	
	c->cd();
	TProfile *hpfx_tmp = (TProfile*) h2->ProfileX("_pfx",1,-1,"o");
	hpfx_tmp->SetStats(kFALSE);
	//hpfx_tmp->SetMarkerColor(kBlack);
	hpfx_tmp->SetMarkerColor(kRed);
	hpfx_tmp->SetMarkerSize(1.2); 
	hpfx_tmp->SetMarkerStyle(20); 
	hpfx_tmp->Draw("psame");
	
	c->Draw();
	cmsPrel(60.,sa,sb, isMC);
	
	TString canvName = h2->GetName();
	c->cd()->SetLogz();
	c->SaveAs(canvName+"."+format);
	  
      } else { 
	
	TH1F* h1 = (TH1F*)file->Get(dirName+"/"+objName);
	h1->SetName(objName+dirName);
	h1vec.push_back(h1);
	
	TCanvas *c = new TCanvas(h1->GetName(),h1->GetName(),600,600);
	c->cd()->SetLogy();
	
	h1->SetMarkerColor(kBlack);
	h1->SetMarkerStyle(20);
	h1->SetLineWidth(1.5); 
	h1->SetFillColor(393);
	//h1->SetFillStyle(3005);
	h1->Draw("hist");
	h1->Draw("e1same");
	c->Draw();
	
	TObject    *statObj;
	TPaveStats *stats;
  
	statObj = h1->GetListOfFunctions()->FindObject("stats");
	stats= static_cast<TPaveStats*>(statObj);
	stats->SetFillColor(10);
	stats->SetLineWidth(1);
	stats->SetShadowColor(0);
	stats->SetTextFont(42);
	stats->SetTextSize(0.025);
	//stats->SetLineColor(LineColors);
	//stats->SetTextColor(LineColors);
	stats->SetX1NDC(0.75);
	stats->SetY1NDC(0.72);
	stats->SetX2NDC(0.97);
	stats->SetY2NDC(0.92);
	stats->Draw("same"); 
		
	cmsPrel(60.,sa,sb,isMC);
	TString canvName = h1->GetName();
	c->SaveAs(canvName+"."+format);
       	
      }
    }
  }
}
Beispiel #2
0
// Read decay modes from single file
void ReadFile(TFile *f, TList &list)
{
	f->cd();
	cout<<"Reading file: "<<f->GetName()<<endl<<endl;
	TList *dir=f->GetListOfKeys();	
	TIter nextdir(dir);
	TKey *key_dir=0;
	while(key_dir=(TKey*)nextdir())
	{
		if(strcmp(key_dir->GetClassName(),"TDirectoryFile")==0 ||
		   strcmp(key_dir->GetClassName(),"TDirectory")==0 )
		{
			TDirectory *subdir=(TDirectory*)f->Get(key_dir->GetName());
			TList *keys=subdir->GetListOfKeys();
			TIter  nextKey(keys);
			TKey  *key=0;
			// User Histograms
			if(strcmp(key_dir->GetName(),"USER_HISTOGRAMS")==0)
			{
				TDecayMode *dm = new TDecayMode();
				dm->histograms = new TObjArray();
				while(key=(TKey*)nextKey())
				{
					int cycle=-10;
					if(strcmp(key->GetClassName(),"TH1D")==0)
					{
						TH1D *h=0;
						int cycleh=key->GetCycle();
						if(cycleh<cycle) { cout<<"Skipping..."<<endl; continue; }
						if(cycle<cycleh) cycle=cycleh;
						h=(TH1D*)key->ReadObj();
						if(!h)
						{
							cout<<"Cannot read: "<<key->GetName()<<endl;
							exit(-2);
						}
						TH1D *h1=new TH1D(*h);
						dm->histograms->Add(h1);
					}
				}
				if(userHisto==NULL) userHisto = (TDecayMode*) new TDecayMode(*dm);
				else                dmMerge(userHisto,dm,keys);
				continue;
			}
			TDecayMode *file_dm=0;
			TDecayMode *dm=0;
			// Regular decay mode
			while(key=(TKey*)nextKey())
			{
				if(strcmp(key->GetClassName(),"TDecayMode")==0)
				{
					file_dm=(TDecayMode*)key->ReadObj();
					dm = new TDecayMode(*file_dm);
				}
			}
			if(!dm)
			{
				cout<<"ERROR: no TDecayMode object found in directory: "<<subdir->GetName()<<endl;
				subdir->ls();
				continue;
			}
			// Merge with existing decay mode or add as new one
			TObject *existingDM=list.FindObject(dm->GetName());
			if(existingDM)
			{
				int ret = dmMerge(existingDM,dm,keys);
				if(ret==-1)
				{
					printf("WARNING: Histograms with different ranges or number of bins. File skipped.\n");
					return;
				}
			}
			else
			{
				dmRestoreHistograms(dm,keys);
				list.Add(dm);
			}
		}
		else
		{
			//If not directory, it's generation description
			if(genDesc || strcmp(key_dir->GetClassName(),"GenerationDescription")!=0) continue;
			GenerationDescription *file_gd = (GenerationDescription*) key_dir->ReadObj();
			GenerationDescription *gd = new GenerationDescription(*file_gd);
			genDesc=gd;
		}
	}
}
Beispiel #3
0
void main(int argc,char *argv[])
{
    char *basedir, *p;
    FILEFINDBUF3 find; HDIR dirhandle; ULONG srch_cnt;
    int newdrive, urdrive, rootdir, dotdir, dotdotdir;
    int asking=TRUE, retcode=TRUE;

    while (--argc)  {
	++argv;
	if ((argv[0][0] == '/') || (argv[0][0] == '-')) {
	    switch(toupper(argv[0][1])) {
		case 'Y': asking = FALSE; break;

#ifdef __OS2__
		case 'F': forcedel = 1; break;
#endif
		default : printf("Invalid switch - %c\n", argv[0][1]); abort();
		}
	    }
	else
	    break;
	}
    if (!argc) {
	puts("DELTREE2 v1.0\nRequired parameter missing");
	abort();
	}
    urdrive = getdisk();
#ifdef __OS2__
    DosError(FERR_DISABLEHARDERR);
#endif

    /* Process each command line parameter */
    while (argc--) {
	basedir = *argv++;
	if (asking) {
	    printf("Delete directory \"%s\" and all its subdirectories? [yn] ",
		   basedir);
	    if (!getyn())
		continue;
	    }
	setdisk(urdrive);
	srch_cnt = 1; dirhandle = HDIR_CREATE;
	findret = DosFindFirst(basedir, &dirhandle, MUST_HAVE_DIRECTORY,
			       &find, sizeof(find), &srch_cnt,
			       FIL_STANDARD);
	if (findret == 0) {
#ifndef __OS2__
	dirhandle = 1;
#endif
	    DosFindClose(dirhandle);
	    }
	else
	    continue;  /* no such directory, goto next argument */
	if (basedir[1] == ':') {
	    /* Need to change drives */
	    newdrive = toupper(basedir[0])-'A';
	    if (newdrive != urdrive) {
		setdisk(newdrive);
		if (newdrive != getdisk())
		    continue;  /* cannot switch drives, goto next argument */
	       }
	    basedir+=2;
	    }
	assert (NULL != (p=getcwd(NULL, MAXPATH)));
	dotdir = !strcmp(basedir, ".") ||
		 !strcmp(basedir, p+2);
	free(p);
	dotdotdir = !strcmp(basedir, "..");
	rootdir = (!strcmp(basedir,"\\") ||
		   !strcmp(basedir,"/"));
	printf("Deleting %s...\n", basedir);
	if (rootdir) {
	    CHDIR("\\");
	    retcode &= nextdir(FALSE);
	    }
	else if (dotdir) {
	    retcode &= nextdir(FALSE);
	    }
	else if (dotdotdir) {
	    CHDIR("..");
	    retcode &= nextdir(FALSE);
	    }
	else {
	    if (CHDIR(basedir))
		continue /* cannot change directory - goto next argument */;
	    retcode &= nextdir(FALSE);
	    CHDIR("..");
#ifndef DBG
	    retcode &= (0 == DosDeleteDir(basedir));
#endif
	    }
	/* goto next argument */
	}
    setdisk(urdrive);
    exit(retcode ? 0 : 1);
    }
Beispiel #4
0
int nextdir(int toplev)
{
#ifdef __OS2__
    FILEFINDBUF3 find;
    ULONG srch_cnt;
    HDIR dirhandle;
    APIRET findret;
#else
    struct ffblk find;
    ULONG srch_cnt;
    HDIR dirhandle;
    int findret;
#endif
    int retcode=TRUE, c, rc, nomore;

#ifdef DBG
    printf("entered nextdir %d\n", nextdirdepth++);
#endif

    srch_cnt = 1; dirhandle = HDIR_CREATE;
    findret =  DosFindFirst("*.*", &dirhandle, MUST_HAVE_DIRECTORY,
			     &find, sizeof(find), &srch_cnt,
			     FIL_STANDARD);
#ifdef __OS2__
    nomore = (findret == ERROR_NO_MORE_FILES);
#else
    nomore = ((findret == -1) && (_doserrno == ENMFILE));
    if (!nomore)
	dirhandle = 1;
#endif
#ifdef DBG
    printf("DosFindFirstDir returned %d(%d)\n", (int) findret, nomore);
    DOSFINDBAD(findret);
    assert(dirhandle != HDIR_CREATE);
#endif
    if (nomore)
	findret = 0;
    while (!nomore) {
	if ((findret == 0) && (FNAME != '.') && (FATTR & FILE_DIRECTORY)) {
	    /* descend next level */
	    if (toplev)
		printf("Deleting %s...\n", &FNAME);
#ifdef DBG
	    printf("descending to scan %s\n", &FNAME);
	    assert(0 == CHDIR(&FNAME));
	    retcode &= nextdir(FALSE);
	    /* ascend level and onto next directory */
	    assert(0 == CHDIR(".."));
	    printf("removing dir  %s\n", &FNAME);
#else
	    /* descend level */
	    if (CHDIR(&FNAME)) {
		/* descent impossible */
		retcode = FALSE;
		}
	    else {
		/* process next directory */
		retcode &= nextdir(FALSE);
		/* ascend level */
		if (CHDIR("..")) {
		    /* Something woefully wrong ... */
		    if (dirhandle != HDIR_CREATE) {
			DosFindClose(dirhandle);
			dirhandle = HDIR_CREATE;
			}
		    return(FALSE);
		    }
		else {
		    /* delete empty directory */
		    retcode &= (0 == DosDeleteDir(&FNAME));
		    }
		}
#endif
	    }
	/* Position to next entry */
	findret = DosFindNext(dirhandle, &find, sizeof(find), &srch_cnt);
#ifdef __OS2__
	nomore = (findret == ERROR_NO_MORE_FILES);
#else
	nomore = ((findret == -1) && (_doserrno == ENMFILE));
#endif
#ifdef DBG
	printf("DosFindNextDir returned %d(%d)\n", (int) findret, nomore);
	DOSFINDBAD(findret);
#endif
	if (nomore)
	    findret = 0;
	/* Process next entry */
	continue;
	}
    if (dirhandle != HDIR_CREATE) {
	DosFindClose(dirhandle);
	dirhandle = HDIR_CREATE;
	}
    srch_cnt = 1;

/* Now delete the files */
    findret = DosFindFirst("*.*",&dirhandle, FILE_ABNORMAL, &find,
			    sizeof(find), &srch_cnt, FIL_STANDARD);
#ifdef __OS2__
    nomore = (findret == ERROR_NO_MORE_FILES);
#else
    nomore = ((findret == -1) && (_doserrno == ENMFILE));
    if (!nomore)
	dirhandle = 1;
#endif
#ifdef DBG
    printf("DosFindFirstFile returned %d(%d)\n", (int) findret, nomore);
    DOSFINDBAD(findret);
#endif
    if (nomore)
	findret = 0;

     while (!nomore) {
	 if (findret == 0) {
	    /* Process if file OK */
	    if (toplev)
		printf("Deleting %s...\n", &FNAME);
#ifdef DBG
	    if (!findret && (FATTR & FILE_ABNORMAL))
		printf("making normal and %sdeleting %s\n",
		       dbgdel[forcedel], &FNAME);
	    else
		printf("%sdeleting %s\n",
		       dbgdel[forcedel], &FNAME);
#else
	    if (!findret && (FATTR & FILE_ABNORMAL))
		rc = _chmod(&FNAME, 1, 0);
	    if (!rc) {
#ifdef __OS2__
		if (forcedel)
		    retcode &= (0 == DosForceDelete(&FNAME));
		else
#endif
		    retcode &= (0 == DosDelete(&FNAME));
		}
	    else
		retcode = FALSE;
#endif
	    }
	/* Advance to next file */
	findret = DosFindNext(dirhandle, &find, sizeof(find), &srch_cnt);
#ifdef __OS2__
	nomore = (findret == ERROR_NO_MORE_FILES);
#else
	nomore = ((findret == -1) && (_doserrno == ENMFILE));
#endif
#ifdef DBG
	printf("DosFindNextFile returned %d(%d)\n", (int) findret, nomore);
	DOSFINDBAD(findret);
#endif
	if (nomore)
	    findret = 0;
	/* Process next file */
	continue;
	}
    if (dirhandle != HDIR_CREATE)
	DosFindClose(dirhandle);
#ifdef DBG
    printf("leaving nextdir %d\n", --nextdirdepth);
#endif
    return(retcode);
    }
Beispiel #5
0
extern filestatus
osd_getExePath (cstring path, cstring file, cstring *returnPath)
{
  char *fullPath;
  char *dirPtr;
  size_t dirLen;
  char aPath[MAXPATHLEN];
  filestatus rVal = OSD_FILENOTFOUND;	/* assume file not found. */
  /*@access cstring@*/ 

  *returnPath = cstring_undefined;  
  fullPath = osd_getEnvironmentVariable (path);
  
  if (fullPath == NULL)
    {
      /* No path specified. Look for it in the current directory. */
      llassert (cstring_isDefined (file));
      strcpy (&aPath[0], file);
      
      if (osd_fileExists (&aPath[0]))
	{
	  rVal = OSD_FILEFOUND;
   	  *returnPath = dmalloc (strlen (&aPath[0]) + 1);
	  strcpy (*returnPath, &aPath[0]);
	}
    }
  else
    {
     /* 
     ** Path specified. Loop through directories in path looking
     ** for the first occurrence of the file.				    
     */

      while (nextdir (&fullPath, &dirPtr, &dirLen) &&
	     rVal == OSD_FILENOTFOUND)
	{
	  llassert (cstring_isDefined (file));

	  if ((dirLen + cstring_length (file) + 2) <= MAXPATHLEN)
	    {
	      /* Cat directory and filename, and see if file exists.  */
	      strncpy (&aPath[0], dirPtr, dirLen);
	      strcpy (&aPath[0] + dirLen, ""); /* Null terminate aPath. */
	      strcat (&aPath[0], CONNECTSTR);
	      strcat (&aPath[0], file);

	      if (osd_executableFileExists (&aPath[0]))
		{
		  rVal = OSD_FILEFOUND;
   		  *returnPath = dmalloc (strlen (&aPath[0]) + 1);
		  strcpy (*returnPath, &aPath[0]);
		}
	    }
	  else
	    {
	      rVal = OSD_PATHTOOLONG;
	    }
	}
    }

  return rVal;
  /*@noaccess cstring@*/
}
Beispiel #6
0
extern filestatus
osd_getPath (cstring path, cstring file, cstring *returnPath)
{
  char *fullPath;
  char *dirPtr;
  size_t dirLen;
  char aPath[MAXPATHLEN];
  filestatus rVal = OSD_FILENOTFOUND;	/* assume file not found. */
  
  /*@access cstring@*/
  
  fullPath = path;
  llassert (cstring_isDefined (file));
  
  /* 2002-01-01: make sure returnPath gets defined even when there are errors.
  **             (fixed splint checking detected this)
  */

  *returnPath = cstring_undefined;

  if (fullPath == NULL 
      || 
# if defined(OS2) || defined(MSDOS) || defined(WIN32)
      /* under OS/2 and MSDOS the includePath may be empty, if so, search 
       * the current directory. */
      *fullPath == '\0' || 
      (*file == CONNECTCHAR || (file[0] != '\0' && file[1] == ':'))
# else
      (*file == CONNECTCHAR)
# endif
      )
    {
      /* No path specified. Look for it in the current directory.	    */
      
      strcpy (&aPath[0], file);
      
      if (osd_fileExists (&aPath[0]))
	{
	  rVal = OSD_FILEFOUND;
   	  *returnPath = dmalloc (strlen (&aPath[0]) + 1);
	  strcpy (*returnPath, &aPath[0]);
	}
    }
  else
    {
      /* Path specified. Loop through directories in path looking for the */
      /* first occurrence of the file.				    */
      
      while (nextdir (&fullPath, &dirPtr, &dirLen) 
	     && rVal == OSD_FILENOTFOUND)
	{
	  if ((dirLen + strlen (file) + 2) <= MAXPATHLEN)
	    {
	      /* Cat directory and filename, and see if file exists.  */
	      strncpy (&aPath[0], dirPtr, dirLen);
	      strcpy (&aPath[0] + dirLen, "");	/* Null terminate aPath. */
	      strcat (&aPath[0], CONNECTSTR);
	      strcat (&aPath[0], file);
	      
	      if (osd_fileExists (&aPath[0]))
		{
		  rVal = OSD_FILEFOUND;
   		  *returnPath = (char *) dmalloc (strlen (&aPath[0]) + 1);
		  strcpy (*returnPath, &aPath[0]);
		}
	    }
	  else
	    {
	      rVal = OSD_PATHTOOLONG;
	    }
	}	
    }

  return rVal;
  /*@noaccess cstring@*/
}