コード例 #1
0
ファイル: Reply.C プロジェクト: bend/wt
void httpDateBuf(time_t t, Wt::WStringStream& buf)
{
  struct tm td;
  gmtime_r(&t, &td);

  static const char dayOfWeekStr[7][4]
    = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
  static const char monthStr[12][4]
    = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
	"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };

  // Wed, 15 Jan 2014 21:20:01 GMT
  buf << dayOfWeekStr[td.tm_wday] << ", "
      << td.tm_mday << ' '
      << monthStr[td.tm_mon] << ' '
      << (td.tm_year + 1900) << ' ';

  pad2(buf, td.tm_hour);
  buf << ':';
  pad2(buf, td.tm_min);
  buf << ':';
  pad2(buf, td.tm_sec);
  buf << " GMT";
}
コード例 #2
0
void drawHisto(TCanvas* C,TString Group1,TFile* F1,TString Group2,TFile* F2,TString channel,TString category,TString sample,bool PrintDiff){
  C->Clear();
  
  TH1F* H1 = (TH1F*) F1->Get(channel+"_"+category+"/"+sample);
  TH1F* H2 = (TH1F*) F2->Get(channel+"_"+category+"/"+sample);
  
  if(!H1||!H2||H1->Integral()!=H1->Integral()||H2->Integral()!=H2->Integral()){

    if(H1&&H1->Integral()==H1->Integral())H1->Draw("histpe");
    if(H2&&H2->Integral()==H2->Integral())H2->Draw("histpe");

    TText cat;
    cat.DrawTextNDC(.2,.5,channel+"_"+category+"/"+sample);
    if(!H1||H1->Integral()!=H1->Integral()) cat.DrawTextNDC(.2,.4,Group1+" is missing or 0");
    if(!H2||H2->Integral()!=H2->Integral()) cat.DrawTextNDC(.2,.4,Group2+" is missing or 0");

    if(PrintDiff)printf("| %.1f ",100);
    C->Print(TString(C->GetName())+".pdf");
    return;
  }
//   cout<<channel<<" "<<category<<" "<<sample<<endl;
//   cout<<H1->Integral()<<" "<<H2->Integral()<<endl;
//   TText cat;
//   cat.DrawTextNDC(.2,.5,channel+"_"+category+"/"+sample);
//   C->Print(TString(C->GetName())+".pdf");
//   return;


 
  TPad pad1("pad1","",0,0.2,1,1);
  TPad pad2("pad2","",0,0,1,0.2);
    
  ////////////////////////////////////////////
  pad1.cd();


  //H1->SetTitle("");
  H1->SetTitle(channel+"  "+category+"  "+sample);
  H1->GetXaxis()->SetTitle("mass");
  H1->GetYaxis()->SetTitle("");
  H1->GetYaxis()->SetRangeUser(0,(H1->GetMaximum()>H2->GetMaximum() ? H1->GetMaximum() : H2->GetMaximum())*1.2);
  H1->SetLineWidth(3);
  H1->SetLineColor(1);
  H1->SetFillColor(0);
  H1->Draw("histpe");
  H2->SetMarkerSize(0.01);
  H2->SetLineWidth(3);
  H2->SetLineColor(2);
  H2->SetFillColor(0);
  H2->Draw("histesame");
  
  TText TXmine;
  TXmine.SetTextColor(1);
  TXmine.SetTextSize(.04);
  TText TXother;
  TXother.SetTextColor(2);
  TXother.SetTextSize(.04);
  TText TXdiff;
  TXdiff.SetTextColor(4);
  TXdiff.SetTextSize(.03);
  char yield1[100];
  sprintf(yield1,"%.2f",H1->Integral(1,H1->GetNbinsX()));
  char yield2[100];
  sprintf(yield2,"%.2f",H2->Integral(1,H2->GetNbinsX()));
  TXmine.DrawTextNDC(.55,.845,Group1+" : "+yield1);
  TXother.DrawTextNDC(.55,.81,Group2+" : "+yield2);
  char txt[100];
  float diff=100*2*fabs(H1->Integral(1,H1->GetNbinsX())-H2->Integral(1,H2->GetNbinsX()))/(H1->Integral(1,H1->GetNbinsX())+H2->Integral(1,H2->GetNbinsX()));
  sprintf(txt,"Difference = %.1f",diff);
  TXdiff.DrawTextNDC(.25,.85,TString(txt)+"%");

  ////////////////////////////////////////////
  pad2.cd();
  ///Draw the ratio of the historgrams
  TH1F*HDiff=(TH1F*)H2->Clone("HDiff");
  HDiff->Divide(H1);
  HDiff->GetYaxis()->SetRangeUser(0.8,1.2);
  HDiff->GetYaxis()->SetNdivisions(3);
  HDiff->GetYaxis()->SetLabelSize(0.1);
  HDiff->GetYaxis()->SetTitleSize(0.1);
  HDiff->GetYaxis()->SetTitleOffset(0.5);
  //HDiff->GetYaxis()->SetTitle(myGroup + " / " + group);
  HDiff->GetYaxis()->SetTitle("Ratio");
  HDiff->GetXaxis()->SetNdivisions(-1);
  HDiff->GetXaxis()->SetTitle("");
  HDiff->GetXaxis()->SetLabelSize(0.0001);
  HDiff->SetMarkerSize(0.1);
  HDiff->Draw("histpe");
  TLine line;
  line.DrawLine(HDiff->GetXaxis()->GetXmin(),1,HDiff->GetXaxis()->GetXmax(),1);




  C->Clear();
  pad1.Draw();
  pad2.Draw();



  //cout<<setiosflags(ios::fixed)<<precision(2);
  //cout<<"| "<<diff<<" "<<endl;
  //if(PrintDiff)printf("| %.1f ",diff);
  C->Print(TString(C->GetName())+".pdf");

  //delete H1;
  //delete H2;
  delete HDiff;
}
コード例 #3
0
ファイル: service.cpp プロジェクト: copilot-com/CopilotVNC
void monitor_sessions_RDP()
{
	BOOL  RDPMODE = false;
	IniFile myIniFile;
	RDPMODE = myIniFile.ReadInt("admin", "rdpmode", 0);
	pad2(false);
	DWORD requestedSessionID = 0;
	DWORD dwSessionId = 0;
	DWORD OlddwSessionId = 99;
	ProcessInfo.hProcess = 0;
	HANDLE testevent3[3];
	HANDLE testevent2[2];
	bool ToCont = true;
	bool preconnect_start = false;

	//We use this event to notify the program that the session has changed
	//The program need to end so the service can restart the program in the correct session
	wait_for_existing_process();
	hEvent = CreateEvent(NULL, FALSE, FALSE, "Global\\SessionEventUltra");
	hEventcad = CreateEvent(NULL, FALSE, FALSE, "Global\\SessionEventUltraCad");
	hEventPreConnect = CreateEvent(NULL, FALSE, FALSE, "Global\\SessionEventUltraPreConnect");
	hMapFile = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(int), "Global\\SessionUltraPreConnect");
	if (hMapFile)data = MapViewOfFile(hMapFile, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0);
	Sleep(3000);
	int *a = (int*)data;
	testevent3[0] = stopServiceEvent;
	testevent3[1] = hEventcad;
	testevent3[2] = hEventPreConnect;
	testevent2[0] = stopServiceEvent;
	testevent2[1] = hEventcad;


	while (ToCont && serviceStatus.dwCurrentState == SERVICE_RUNNING)
	{
		DWORD dwEvent;		
		if (RDPMODE) dwEvent = WaitForMultipleObjects(3, testevent3, FALSE, 1000);
		else dwEvent = WaitForMultipleObjects(2, testevent2, FALSE, 1000);

		switch (dwEvent)
		{

			// We get some preconnect session selection input
		case WAIT_OBJECT_0 + 2:
		{
			//Tell winvnc to stop
			SetEvent(hEvent);
			requestedSessionID = *a;
			//We always have a process handle, else we could not get the signal from it.
			DWORD dwCode = STILL_ACTIVE;
			while (dwCode == STILL_ACTIVE && ProcessInfo.hProcess != NULL)
			{
				GetExitCodeProcess(ProcessInfo.hProcess, &dwCode);
				if (dwCode != STILL_ACTIVE)
				{
					WaitForSingleObject(ProcessInfo.hProcess, 15000);
					if (ProcessInfo.hProcess) CloseHandle(ProcessInfo.hProcess);
					if (ProcessInfo.hThread) CloseHandle(ProcessInfo.hThread);
				}
				else Sleep(1000);
			}

			dwSessionId = 0xFFFFFFFF;
			int sessidcounter = 0;
			while (dwSessionId == 0xFFFFFFFF)
			{
				if (lpfnWTSGetActiveConsoleSessionId.isValid()) dwSessionId = (*lpfnWTSGetActiveConsoleSessionId)();
				Sleep(1000);
				sessidcounter++;
				if (sessidcounter > 10) break;
			}
			LaunchProcessWin(requestedSessionID, false);
			OlddwSessionId = requestedSessionID;
			preconnect_start = true;
		}
		break;

			//stopServiceEvent, exit while loop
		case WAIT_OBJECT_0 + 0:
			ToCont = false;
			break;

			//cad request
		case WAIT_OBJECT_0 + 1:
		{
			typedef VOID(WINAPI *SendSas)(BOOL asUser);
			HINSTANCE Inst = LoadLibrary("sas.dll");
			SendSas sendSas = (SendSas)GetProcAddress(Inst, "SendSAS");
			if (sendSas) sendSas(FALSE);
			else
			{
				char WORKDIR[MAX_PATH];
				char mycommand[MAX_PATH];
				if (GetModuleFileName(NULL, WORKDIR, MAX_PATH))
				{
					char* p = strrchr(WORKDIR, '\\');
					if (p == NULL) return;
					*p = '\0';
				}
				strcpy(mycommand, "");
				strcat(mycommand, WORKDIR);//set the directory
				strcat(mycommand, "\\");
				strcat(mycommand, "cad.exe");
				(void)ShellExecute(GetDesktopWindow(), "open", mycommand, "", 0, SW_SHOWNORMAL);
			}
			if (Inst) FreeLibrary(Inst);
		}
		break;

		case WAIT_TIMEOUT:
			if (RDPMODE)
				{
					//First RUN	
					if (ProcessInfo.hProcess == NULL)
					{
						if (IsAnyRDPSessionActive())
						{
							LaunchProcessWin(0, true);
							OlddwSessionId = 0;
							preconnect_start = false;
							goto whileloop;
						}
						else
						{
							dwSessionId = 0xFFFFFFFF;
							int sessidcounter = 0;
							while (dwSessionId == 0xFFFFFFFF)
							{
								if (lpfnWTSGetActiveConsoleSessionId.isValid()) dwSessionId = (*lpfnWTSGetActiveConsoleSessionId)();
								Sleep(1000);
								sessidcounter++;
								if (sessidcounter > 10) break;
							}
							LaunchProcessWin(dwSessionId, false);
							OlddwSessionId = dwSessionId;
							preconnect_start = false;
							goto whileloop;
						}
					}

					if (preconnect_start == true) if (!IsSessionStillActive(OlddwSessionId)) SetEvent(hEvent);

					// Monitor process
					DWORD dwCode = 0;
					bool returnvalue = GetExitCodeProcess(ProcessInfo.hProcess, &dwCode);
					if (!returnvalue)
					{
						//bad handle, thread already terminated
						if (ProcessInfo.hProcess) CloseHandle(ProcessInfo.hProcess);
						if (ProcessInfo.hThread) CloseHandle(ProcessInfo.hThread);
						ProcessInfo.hProcess = NULL;
						ProcessInfo.hThread = NULL;
						RDPMODE = myIniFile.ReadInt("admin", "rdpmode", 0);
						Sleep(1000);
						goto whileloop;
					}

					if (dwCode == STILL_ACTIVE) goto whileloop;
					if (ProcessInfo.hProcess) WaitForSingleObject(ProcessInfo.hProcess, 15000);
					if (ProcessInfo.hProcess) CloseHandle(ProcessInfo.hProcess);
					if (ProcessInfo.hThread) CloseHandle(ProcessInfo.hThread);
					ProcessInfo.hProcess = NULL;
					ProcessInfo.hThread = NULL;
					RDPMODE = myIniFile.ReadInt("admin", "rdpmode", 0);
					Sleep(1000);
					goto whileloop;
				}//timeout
			else
			{
				if (lpfnWTSGetActiveConsoleSessionId.isValid()) dwSessionId = (*lpfnWTSGetActiveConsoleSessionId)();
				if (OlddwSessionId != dwSessionId)
				{
					//Tell winvnc to stop
					SetEvent(hEvent);
				}
				if (dwSessionId != 0xFFFFFFFF)
				{
					DWORD dwCode = 0;
					if (ProcessInfo.hProcess == NULL)
					{
						//First RUNf
						LaunchProcessWin(dwSessionId, false);
						OlddwSessionId = dwSessionId;
					}
					else if (GetExitCodeProcess(ProcessInfo.hProcess, &dwCode))
					{
						if (dwCode != STILL_ACTIVE)
						{
							WaitForSingleObject(ProcessInfo.hProcess, 15000);
							if (ProcessInfo.hProcess) CloseHandle(ProcessInfo.hProcess);
							if (ProcessInfo.hThread) CloseHandle(ProcessInfo.hThread);
							ProcessInfo.hProcess = NULL;
							ProcessInfo.hThread = NULL;							
							int sessidcounter = 0;
							while ((OlddwSessionId == dwSessionId) || dwSessionId == 0xFFFFFFFF)
							{
								Sleep(1000);
								if (lpfnWTSGetActiveConsoleSessionId.isValid()) dwSessionId = (*lpfnWTSGetActiveConsoleSessionId)();
								sessidcounter++;
								if (sessidcounter > 10) break;
							}
							RDPMODE = myIniFile.ReadInt("admin", "rdpmode", 0);
							goto whileloop;
							//LaunchProcessWin(dwSessionId, false);
							//OlddwSessionId = dwSessionId;
						}
					}
					else
					{
						if (ProcessInfo.hProcess) CloseHandle(ProcessInfo.hProcess);
						if (ProcessInfo.hThread) CloseHandle(ProcessInfo.hThread);
						ProcessInfo.hProcess = NULL;
						ProcessInfo.hThread = NULL;
						int sessidcounter = 0;
						while (OlddwSessionId == dwSessionId)
						{
							Sleep(1000);
							if (lpfnWTSGetActiveConsoleSessionId.isValid()) dwSessionId = (*lpfnWTSGetActiveConsoleSessionId)();
							sessidcounter++;
							if (sessidcounter > 10) break;
						}
						RDPMODE = myIniFile.ReadInt("admin", "rdpmode", 0);
						goto whileloop;
						//LaunchProcessWin(dwSessionId, false);
						//OlddwSessionId = dwSessionId;
					}
				}
			}


		}//switch

	whileloop:
#ifdef _DEBUG
		char			szText[256];
		sprintf(szText, " ++++++1 %i %i %i\n", OlddwSessionId, dwSessionId, ProcessInfo.hProcess);
		OutputDebugString(szText);
#else
		;
#endif
	}//while
#ifdef _DEBUG
	char			szText[256];
	sprintf(szText, " ++++++SetEvent Service stopping: signal tray icon to shut down\n");
	OutputDebugString(szText);
#endif

	if (hEvent) SetEvent(hEvent);

	if (ProcessInfo.hProcess)
	{
#ifdef _DEBUG
		OutputDebugString("Waiting up to 15 seconds for tray icon process to exit\n");
#endif
		WaitForSingleObject(ProcessInfo.hProcess, 15000);
		if (ProcessInfo.hProcess) CloseHandle(ProcessInfo.hProcess);
		if (ProcessInfo.hThread) CloseHandle(ProcessInfo.hThread);
		ProcessInfo.hProcess = NULL;
		ProcessInfo.hThread = NULL;
	}

	//	EndProcess();

	if (hEvent) CloseHandle(hEvent);
	if (hEventcad) CloseHandle(hEventcad);
	if (hEventPreConnect) CloseHandle(hEventPreConnect);
	if (data) UnmapViewOfFile(data);
	if (hMapFile != NULL) CloseHandle(hMapFile);
}
コード例 #4
0
ファイル: service.cpp プロジェクト: copilot-com/CopilotVNC
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// START the app as system 
BOOL
LaunchProcessWin(DWORD dwSessionId,bool preconnect)
{
  BOOL                 bReturn = FALSE;
  HANDLE               hToken;
  STARTUPINFO          StartUPInfo;
  PVOID                lpEnvironment = NULL;

  ZeroMemory(&StartUPInfo,sizeof(STARTUPINFO));
  ZeroMemory(&ProcessInfo,sizeof(PROCESS_INFORMATION));
  StartUPInfo.wShowWindow = SW_SHOW;
  //StartUPInfo.lpDesktop = "Winsta0\\Winlogon";
  StartUPInfo.lpDesktop = "Winsta0\\Default";
  StartUPInfo.cb = sizeof(STARTUPINFO);
  SetTBCPrivileges();
  pad2(preconnect);

  if ( GetSessionUserTokenWin(&hToken,dwSessionId) )
  {
      if ( CreateEnvironmentBlock(&lpEnvironment, hToken, FALSE) ) 
      {
      
		 SetLastError(0);
         if (CreateProcessAsUser(hToken,NULL,app_path,NULL,NULL,FALSE,CREATE_UNICODE_ENVIRONMENT |DETACHED_PROCESS,lpEnvironment,NULL,&StartUPInfo,&ProcessInfo))
			{
				counter=0;
				bReturn = TRUE;
				DWORD error=GetLastError();
				#ifdef _DEBUG
					char			szText[256];
					sprintf(szText," ++++++ CreateProcessAsUser winlogon %d\n",error);
					OutputDebugString(szText);		
				#endif
			}
		 else
		 {
			 DWORD error=GetLastError();
			 #ifdef _DEBUG
					char			szText[256];
					sprintf(szText," ++++++ CreateProcessAsUser failed %d %d %d\n",error,kickrdp,counter);
					OutputDebugString(szText);		
			#endif
			if (error==233 && kickrdp==1)
					{
						counter++;
						if (counter>3)
							{
								#ifdef _DEBUG
								DWORD error=GetLastError();
								sprintf(szText," ++++++ error==233 win\n");
								SetLastError(0);
								OutputDebugString(szText);		
								#endif
								typedef BOOLEAN (WINAPI * pWinStationConnect) (HANDLE,ULONG,ULONG,PCWSTR,ULONG);
								typedef BOOL (WINAPI * pLockWorkStation)();
								HMODULE  hlibwinsta = LoadLibrary("winsta.dll"); 
								HMODULE  hlibuser32 = LoadLibrary("user32.dll");
								pWinStationConnect WinStationConnectF=NULL;
								pLockWorkStation LockWorkStationF=NULL;

								if (hlibwinsta)
								   {
									   WinStationConnectF=(pWinStationConnect)GetProcAddress(hlibwinsta, "WinStationConnectW"); 
								   }
								if (hlibuser32)
								   {
									   LockWorkStationF=(pLockWorkStation)GetProcAddress(hlibuser32, "LockWorkStation"); 
								   }
								if (WinStationConnectF!=NULL && LockWorkStationF!=NULL)
									{
											DWORD ID=0;
											if (lpfnWTSGetActiveConsoleSessionId.isValid()) ID=(*lpfnWTSGetActiveConsoleSessionId)();
											WinStationConnectF(0, 0, ID, L"", 0);
											LockWorkStationF();
									}
								Sleep(3000);
						}
					}
			else if (error==233)
			{
				CreateRemoteSessionProcess(dwSessionId,true,hToken,NULL,app_path,NULL,NULL,FALSE,CREATE_UNICODE_ENVIRONMENT |DETACHED_PROCESS,lpEnvironment,NULL,&StartUPInfo,&ProcessInfo);
				counter=0;
				bReturn = TRUE;
			}
		 }

         if (lpEnvironment) 
         {
            DestroyEnvironmentBlock(lpEnvironment);
         }

	  }//createenv
	  else
	  {
		  SetLastError(0);
         if (CreateProcessAsUser(hToken,NULL,app_path,NULL,NULL,FALSE,DETACHED_PROCESS,NULL,NULL,&StartUPInfo,&ProcessInfo))
			{
				counter=0;
				bReturn = TRUE;
				DWORD error=GetLastError();
				#ifdef _DEBUG
					char			szText[256];
					sprintf(szText," ++++++ CreateProcessAsUser winlogon %d\n",error);
					OutputDebugString(szText);		
				#endif
			}
		 else
		 {
			 DWORD error=GetLastError();
			 #ifdef _DEBUG
					char			szText[256];
					sprintf(szText," ++++++ CreateProcessAsUser no env failed %d\n",error);
					OutputDebugString(szText);		
			#endif
			//Little trick needed, FUS sometimes has an unreachable logon session.
			 //Switch to USER B, logout user B
			 //The logon session is then unreachable
			 //We force the logon session on the console
			if (error==233 && kickrdp==1)
					{
						counter++;
						if (counter>3)
							{
								#ifdef _DEBUG
								DWORD error=GetLastError();
								sprintf(szText," ++++++ error==233 win\n");
								SetLastError(0);
								OutputDebugString(szText);		
								#endif
								typedef BOOLEAN (WINAPI * pWinStationConnect) (HANDLE,ULONG,ULONG,PCWSTR,ULONG);
								typedef BOOL (WINAPI * pLockWorkStation)();
								HMODULE  hlibwinsta = LoadLibrary("winsta.dll"); 
								HMODULE  hlibuser32 = LoadLibrary("user32.dll");
								pWinStationConnect WinStationConnectF=NULL;
								pLockWorkStation LockWorkStationF=NULL;

								if (hlibwinsta)
								   {
									   WinStationConnectF=(pWinStationConnect)GetProcAddress(hlibwinsta, "WinStationConnectW"); 
								   }
								if (hlibuser32)
								   {
									   LockWorkStationF=(pLockWorkStation)GetProcAddress(hlibuser32, "LockWorkStation"); 
								   }
								if (WinStationConnectF!=NULL && LockWorkStationF!=NULL)
									{
											DWORD ID=0;
											if (lpfnWTSGetActiveConsoleSessionId.isValid()) ID=(*lpfnWTSGetActiveConsoleSessionId)();
											WinStationConnectF(0, 0, ID, L"", 0);
											LockWorkStationF();
									}
								Sleep(3000);
						}
			}
			else if (error==233)
			{
				CreateRemoteSessionProcess(dwSessionId,true,hToken,NULL,app_path,NULL,NULL,FALSE,DETACHED_PROCESS,NULL,NULL,&StartUPInfo,&ProcessInfo);
				counter=0;
				bReturn = TRUE;
			}
	  }
        
	}  //getsession
	CloseHandle(hToken);
	}
  else
  {
	 #ifdef _DEBUG
	char			szText[256];
	DWORD error=GetLastError();
	sprintf(szText," ++++++ Getsessionusertokenwin failed %d\n",error);
	OutputDebugString(szText);		
	#endif

  }
    
    return bReturn;
}
コード例 #5
0
ファイル: Mwavemovie.c プロジェクト: 1014511134/src
int main(int argc, char* argv[])
{
    bool impresp;
    int nt,nx,nz,nw,init,i,padfactor,nfilt,nkol,it,ix,iz,iw;
    float v,dx,dz,lambda,sixth,gamma,epsdamp,pi2,dw,dt, w,wov;
    sf_complex wov2, a, b, c, d, cshift;
    float ***ppp;
    sf_complex *pp, *qq;
    cfilter aa, fac1, fac2;
    sf_file out, imp=NULL;

    sf_init(argc,argv);
    out = sf_output("out");
    sf_setformat(out,"native_float");

    if (!sf_getint("nz",&nz)) nz=96;
    if (!sf_getint("nx",&nx)) nx=48;
    if (!sf_getint("nt",&nt)) nt=12;
    if (!sf_getint("nw",&nw)) nw=2;
    if (!sf_getint("init",&init)) init=1;

    if (!sf_getfloat("v",&v)) v=1.;
    if (!sf_getfloat("dz",&dz)) dz=1.;
    if (!sf_getfloat("dx",&dx)) dx=2.;
    if (!sf_getfloat("lambda",&lambda)) lambda=nz*dz/4.;

    sf_putint(out,"n1",nz);
    sf_putint(out,"n2",nx);
    sf_putint(out,"n3",nt);

    aa = allocatechelix(9);

    if (!sf_getfloat("sixth",&sixth)) sixth=0.0833;
    if (!sf_getfloat("gamma",&gamma)) gamma=0.667;
    if (!sf_getfloat("epsdamp",&epsdamp)) epsdamp=0.01;
    if (!sf_getint("padfactor",&padfactor)) padfactor=1024;
    if (!sf_getint("nfilt",&nfilt)) nfilt=nx+2;
    if (!sf_getbool("impresp",&impresp)) impresp=false;

    if (impresp) {
	imp = sf_output("imp");
	sf_setformat(imp,"native_complex");
	sf_putint(imp,"n1",2*nx);
	sf_putint(imp,"n2",2);
    }

    ppp = sf_floatalloc3(nz,nx,nt);
    pp = sf_complexalloc(nx*nz);
    qq = sf_complexalloc(nx*nz);

    pi2 = 2.*SF_PI;
    dw = v*pi2/lambda;
    dt =   pi2/(nt*dw);

    nkol=pad2(padfactor*nx);
    /* dkol=pi2/nkol; */

    for (it=0; it < nt; it++) {
	for (ix=0; ix < nx; ix++) {
	    for (iz=0; iz < nz; iz++) {
		ppp[it][ix][iz] = 0.;
	    }
	}
    }

    fac1 = allocatechelix(nfilt);
    fac2 = allocatechelix(nfilt);
    helimakelag(fac1,nx,nz);
    helimakelag(fac2,nx,nz);

    xkolmog_init(nkol);

    for (iw=0; iw < nw; iw++) { /* frequency loop */
	w = (iw+1)*dw;

	if (impresp) w=dw*nw/2;

	wov = w/v;
	wov2 = sf_cmplx(epsdamp,wov);
#ifdef SF_HAS_COMPLEX_H
	wov2 = -wov2*wov2;
#else
	wov2 = sf_cneg(sf_cmul(wov2,wov2));
#endif

	sf_warning("%g %g (%d of %d)",crealf(wov2),cimagf(wov2),iw,nw);

	init_wave(init,nx,dx,nz,dz,pp,wov,nw,iw);

	for (iz=0; iz < nx*nz; iz++) {
	    qq[iz]=sf_cmplx(0.,0.);
	}

	/* isotropic laplacian = 5-point laplacian */
	a= sf_cmplx(0.,0.);
#ifdef SF_HAS_COMPLEX_H
	b= gamma*(1+sixth*wov2)* (-1./(dz*dz));
	c= gamma*(1+sixth*wov2)* (-1./(dx*dx));
	d= gamma*(1+sixth*wov2)* (2/(dx*dx) + 2/(dz*dz))  -wov2;
#else
	b = sf_crmul(sf_cadd(sf_cmplx(1.,0.),sf_crmul(wov2,sixth)),
		     gamma*(-1./(dz*dz)));
	c = sf_crmul(sf_cadd(sf_cmplx(1.,0.),sf_crmul(wov2,sixth)),
		     gamma*(-1./(dx*dx)));
	d = sf_cadd(sf_crmul(sf_cadd(sf_cmplx(1.,0.),sf_crmul(wov2,sixth)),
			     gamma*(2/(dx*dx) + 2/(dz*dz))),sf_cneg(wov2));
#endif

	/* + rotated 5-point laplacian */
#ifdef SF_HAS_COMPLEX_H
	a += (1-gamma)*(1+sixth*wov2)* (-0.5/(dx*dz));
	b += (1-gamma)*(1+sixth*wov2)*0.;
	c += (1-gamma)*(1+sixth*wov2)*0.;
	d += (1-gamma)*(1+sixth*wov2)* 2.0/(dx*dz);
#else
	a = sf_cadd(a,sf_crmul(sf_cadd(sf_cmplx(1.0,0.0),
				       sf_crmul(wov2,sixth)),
			       (1-gamma)*(-0.5/(dx*dz))));
	d = sf_cadd(d,sf_crmul(sf_cadd(sf_cmplx(1.0,0.0),
				       sf_crmul(wov2,sixth)),
			       (1-gamma)*(2.0/(dx*dz))));
#endif

	aa->flt[0] = a; aa->lag[0] = -nx-1;
	aa->flt[1] = b; aa->lag[1] = -nx;
	aa->flt[2] = a; aa->lag[2] = -nx+1;

	aa->flt[3] = c; aa->lag[3] = -1;
	aa->flt[4] = d; aa->lag[4] = 0;
	aa->flt[5] = c; aa->lag[5] = 1;

	aa->flt[6] = a; aa->lag[6] = nx-1;
	aa->flt[7] = b; aa->lag[7] = nx;
	aa->flt[8] = a; aa->lag[8] = nx+1;

	xkolmog_helix(aa,fac1,fac2);

	for (i=0; i < nfilt; i++) {
#ifdef SF_HAS_COMPLEX_H
	    fac1->flt[i]=0.5*(fac2->flt[i]+conjf(fac1->flt[i]));
#else
	    fac1->flt[i]=sf_crmul(sf_cadd(fac2->flt[i],conjf(fac1->flt[i])),
				  0.5);
#endif
	}

	if (impresp) {
	    for (iz=0; iz < nx*nz; iz++) {
		pp[iz]=sf_cmplx(0.,0.);
	    }	    
	    pp[nx/2-1]=sf_cmplx(1.,0.);
	    sf_complexwrite(pp,2*nx,imp);
	}

	
	cpolydiv_init(nx*nz,fac2);
	cpolydiv_lop(false,false,nx*nz,nx*nz,pp,qq);

	if (impresp) {
	    sf_complexwrite(qq,2*nx,imp);
	    break;
	}

	/* back to time domain */
	for (it=0; it < nt; it++) {
	    cshift = cexpf(sf_cmplx( 0.,-w*it*dt));
	    for (ix=0; ix < nx; ix++) {
		for (iz=0; iz < nz; iz++) {
#ifdef SF_HAS_COMPLEX_H
		    ppp[it][ix][iz] += crealf(qq[ix+iz*nx]*cshift);
#else
		    ppp[it][ix][iz] += crealf(sf_cmul(qq[ix+iz*nx],cshift));
#endif
		}
	    }
	}

    } /* end frequency loop */

    sf_floatwrite(ppp[0][0],nt*nx*nz,out);

    exit(0);
}
コード例 #6
0
void plotTree(TTree *tree_, std::string whichfit, std::string selectString){

	// Create a map for plotting the pullsummaries:
	std::map < const char*, std::pair <double,double> > pullSummaryMap;
	int nPulls=0;

	TObjArray *l_branches = tree_->GetListOfBranches();
	int nBranches = l_branches->GetEntries();

	TCanvas *c = new TCanvas("c","",960,800);

	std::string treename = tree_->GetName();
	c->SaveAs(Form("%s.pdf[",treename.c_str()));

	for (int iobj=0;iobj<nBranches;iobj++){

		TBranch *br =(TBranch*) l_branches->At(iobj);

		// Draw the normal histogram
		const char* name = br->GetName();
		bool fitPull=false;
		bool plotLH=false;

		TGraph *gr=0;
		double p_mean =0;
		double p_err  =0;

		int nToysInTree = tree_->GetEntries();
		if (doPull && findNuisancePre(name)){
			
			p_mean = bfvals_[name].first;	// toy constrainits thrown about best fit to data
			p_err  = prevals_[name].second; // uncertainties taken from card

			const char* drawInput = Form("(%s-%f)/%f",name,p_mean,p_err);
			tree_->Draw(Form("%s>>%s",drawInput,name),"");
			tree_->Draw(Form("%s>>%s_fail",drawInput,name),selectString.c_str(),"same");
			fitPull = true;
			if (doLH) {
			  gr = graphLH(name,p_err,whichfit);
			  plotLH=true;
			}
			
		}

		else{
			tree_->Draw(Form("%s>>%s",name,name),"");
			tree_->Draw(Form("%s>>%s_fail",name,name),"mu<0","same");
		}
		
		TH1F* bH  = (TH1F*) gROOT->FindObject(Form("%s",name))->Clone();
		TH1F* bHf = (TH1F*) gROOT->FindObject(Form("%s_fail",name))->Clone();
		bHf->SetLineColor(2);
		bH->GetXaxis()->SetTitle(bH->GetTitle());
		bH->GetYaxis()->SetTitle(Form("no toys (%d total)",nToysInTree));
		bH->GetYaxis()->SetTitleOffset(1.32);
		
		bH->SetTitle("");	

		if (fitPull) bH->Fit("gaus");
	
		c->Clear();
		TPad pad1("t1","",0.01,0.02,0.59,0.98);
		TPad pad2("t2","",0.59,0.04,0.98,0.62);
		TPad pad3("t3","",0.59,0.64,0.98,0.90);

		pad1.SetNumber(1); pad2.SetNumber(2); pad3.SetNumber(3);
		pad1.Draw(); pad2.Draw();pad3.Draw();
		pad2.SetGrid(true);

		c->cd(1); bH->Draw(); bHf->Draw("same");
		TLatex *titletext = new TLatex();titletext->SetNDC();titletext->SetTextSize(0.04); titletext->DrawLatex(0.1,0.95,name);
		TLegend *legend = new TLegend(0.6,0.8,0.9,0.89);
		legend->SetFillColor(0);
		legend->AddEntry(bH,"All Toys","L");
		legend->AddEntry(bHf,selectString.c_str(),"L");
		legend->Draw();

		if (doPull && plotLH) {
			c->cd(2); gr->Draw("ALP");
		}
		if (fitPull){
			c->cd(3);
			TLatex *tlatex = new TLatex(); tlatex->SetNDC(); tlatex->SetTextSize(0.12);
			tlatex->DrawLatex(0.15,0.75,Form("Mean    : %.3f #pm %.3f",bH->GetFunction("gaus")->GetParameter(1),bH->GetFunction("gaus")->GetParError(1)));
			tlatex->DrawLatex(0.15,0.60,Form("Sigma   : %.3f #pm %.3f",bH->GetFunction("gaus")->GetParameter(2),bH->GetFunction("gaus")->GetParError(2)));
			tlatex->DrawLatex(0.15,0.35,Form("Pre-fit : %.3f ",prevals_[name].first));
			tlatex->DrawLatex(0.15,0.2,Form("Best-fit (B)  : %.3f ",p_mean));
			tlatex->DrawLatex(0.15,0.05,Form("Best-fit (S+B): %.3f ",bfvals_sb_[name].first));
			
			pullSummaryMap[name]=std::make_pair<double,double>(bH->GetFunction("gaus")->GetParameter(1),bH->GetFunction("gaus")->GetParameter(2));
			nPulls++;

		}

		c->SaveAs(Form("%s.pdf",treename.c_str()));
	}
	
	if (doPull && nPulls>0){
	   
	    int nRemainingPulls = nPulls;
	    TCanvas *hc = new TCanvas("hc","",3000,2000); hc->SetGrid(0);
	    std::map < const char*, std::pair <double,double> >::iterator pull_it = pullSummaryMap.begin();
	    std::map < const char*, std::pair <double,double> >::iterator pull_end = pullSummaryMap.end();

	    while (nRemainingPulls > 0){

		int nThisPulls = min(15,nRemainingPulls);

		TH1F pullSummaryHist("pullSummary","",nThisPulls,0,nThisPulls);
		for (int pi=1;pull_it!=pull_end && pi<=nThisPulls ;pull_it++,pi++){
			pullSummaryHist.GetXaxis()->SetBinLabel(pi,(*pull_it).first);
			pullSummaryHist.SetBinContent(pi,((*pull_it).second).first);
			pullSummaryHist.SetBinError(pi,((*pull_it).second).second);
			nRemainingPulls--;
		}		

		pullSummaryHist.SetMarkerStyle(21);pullSummaryHist.SetMarkerSize(1.5);pullSummaryHist.SetMarkerColor(2);pullSummaryHist.SetLabelSize(0.018);
		pullSummaryHist.GetYaxis()->SetRangeUser(-3,3);pullSummaryHist.GetYaxis()->SetTitle("pull summary");pullSummaryHist.Draw("E1");
		hc->SaveAs(Form("%s.pdf",treename.c_str()));
	   }

	    delete hc;
	}

	c->SaveAs(Form("%s.pdf]",treename.c_str()));

	delete c;
	return;


}
コード例 #7
0
void plotTreeNorms(TTree *tree_, std::string selectString, bool do7TeV){

	// Create a map for plotting the pullsummaries:
	std::map < const char*, std::pair <double,double> > pullSummaryMap;
	int nPulls=0;

	TObjArray *l_branches = tree_->GetListOfBranches();
	int nBranches = l_branches->GetEntries();

	gStyle->SetPadTopMargin(0.01);

	TCanvas *c = new TCanvas("c","",960,800);

	std::string treename = tree_->GetName();
	c->SaveAs(Form("%s_normresiduals.pdf[",treename.c_str()));
	// File to store plots in 
	TFile *fOut = new TFile(Form("%s_normresiduals.root",treename.c_str()),"RECREATE");

        TH1F *bHd = new TH1F("bHd","",50,-1.0,1.0);
        TH1F *bHfd = new TH1F("bHfd","",50,-1.0,1.0);

	for (int iobj=0;iobj<nBranches;iobj++){

		TBranch *br =(TBranch*) l_branches->At(iobj);

		// Draw the normal histogram
		const char* name = br->GetName();

                // select only the normalizations
                string namestr(name);
                if(namestr.find("n_exp")==string::npos) continue;

                bool fitPull=true;
                bool fitPullf=true;

		double p_mean =0;

		int nToysInTree = tree_->GetEntries();
		// Find out if paramter is fitted value or constraint term.
                bool isFitted = true;
			
                p_mean = prenorms_[name].first;	// toy initial parameters from the datacards
                std::cout << "******* "<< name << " *******"<<std::endl;
                std::cout << p_mean << std::endl;
                std::cout << "******************************" <<std::endl;

                TH1F* bH = (TH1F*)bHd->Clone(Form("%s",name));
                TH1F* bHf = (TH1F*)bHfd->Clone(Form("%s_fail",name));
                
                const char* drawInput = Form("(%s-%f)/%f",name,p_mean,p_mean);
                tree_->Draw(Form("%s>>%s",drawInput,name),"");
                tree_->Draw(Form("%s>>%s_fail",drawInput,name),selectString.c_str(),"same");
                fitPull  = true;
                fitPullf = true;
                  
		bHf->SetLineColor(2);
		bH->GetXaxis()->SetTitle(bH->GetTitle());
		bH->GetYaxis()->SetTitle(Form("no toys (%d total)",nToysInTree));
		bH->GetYaxis()->SetTitleOffset(1.05);
		bH->GetXaxis()->SetTitleOffset(0.9);
		bH->GetYaxis()->SetTitleSize(0.05);
		bH->GetXaxis()->SetTitleSize(0.05);
		bH->GetXaxis()->SetTitle(Form("%s",name));
                
		
		bH->SetTitle("");	

		if ( bH->Integral() <=0 )  fitPull = false;
		if (fitPull) {bH->Fit("gaus"); bH->GetFunction("gaus")->SetLineColor(4);}
		
		if ( bHf->Integral() <=0 )  fitPullf = false;
		if (fitPullf) {bHf->Fit("gaus"); bHf->GetFunction("gaus")->SetLineColor(2);}

		c->Clear();
		
 		TPad pad1("t1","",0.01,0.01,0.66,0.95);
 		TPad pad2("t2","",0.70,0.20,0.98,0.80);

		pad1.SetNumber(1); pad2.SetNumber(2);

                if ( isFitted ) {pad2.Draw();}

		pad1.Draw();
		pad1.SetGrid(true);


		TLatex *titletext = new TLatex();titletext->SetNDC();

		
		c->cd(1); bH->Draw(); bHf->Draw("same");
		TLegend *legend = new TLegend(0.6,0.8,0.9,0.89);
		legend->SetFillColor(0);
		legend->AddEntry(bH,"All Toys","L");
		legend->AddEntry(bHf,selectString.c_str(),"L");
		legend->Draw();

		if (fitPull){
			c->cd(2);
			double gap;
			TLatex *tlatex = new TLatex(); tlatex->SetNDC(); 
			if (fitPullf) {tlatex->SetTextSize(0.09); gap=0.12;}
			else  {tlatex->SetTextSize(0.11);gap=0.14;}

			tlatex->SetTextColor(4);
			tlatex->DrawLatex(0.11,0.80,Form("Mean    : %.3f #pm %.3f",bH->GetFunction("gaus")->GetParameter(1),bH->GetFunction("gaus")->GetParError(1)));
			tlatex->DrawLatex(0.11,0.80-gap,Form("Sigma   : %.3f #pm %.3f",bH->GetFunction("gaus")->GetParameter(2),bH->GetFunction("gaus")->GetParError(2)));

			if (fitPullf){ 
				tlatex->SetTextColor(2);
				tlatex->DrawLatex(0.11,0.60,Form("Mean    : %.3f #pm %.3f",bHf->GetFunction("gaus")->GetParameter(1),bHf->GetFunction("gaus")->GetParError(1)));
				tlatex->DrawLatex(0.11,0.60-gap,Form("Sigma   : %.3f #pm %.3f",bHf->GetFunction("gaus")->GetParameter(2),bHf->GetFunction("gaus")->GetParError(2)));
			}

			tlatex->SetTextSize(0.10);
			tlatex->SetTextColor(1);
				
                        tlatex->DrawLatex(0.11,0.33,Form("Pre-fit: %.3f",p_mean));
			
			pullSummaryMap[name]=std::make_pair<double,double>(bH->GetFunction("gaus")->GetParameter(1),bH->GetFunction("gaus")->GetParameter(2));
			nPulls++;

		}

		// double titleSize = isFitted ? 0.1 : 0.028;
		//titletext->SetTextSize(titleSize);titletext->SetTextAlign(21); titletext->DrawLatex(0.55,0.92,name);
		c->SaveAs(Form("%s_normresiduals_%s.pdf",treename.c_str(),(do7TeV ? "7TeV": "8TeV")));
                c->SaveAs(Form("mlfit/%s_residual_%s_%s.pdf",name,treename.c_str(),(do7TeV ? "7TeV": "8TeV")));
		fOut->WriteObject(c,Form("%s_%s",treename.c_str(),name));
	}
	
	if (nPulls>0){
	  
	    std::cout << "Generating Pull Summaries" <<std::endl; 
	    int nRemainingPulls = nPulls;
	    TCanvas *hc = new TCanvas("hc","",3000,2000); hc->SetGrid(0);
	    std::map < const char*, std::pair <double,double> >::iterator pull_it = pullSummaryMap.begin();
	    std::map < const char*, std::pair <double,double> >::iterator pull_end = pullSummaryMap.end();

	    int pullPlots = 1;
	    while (nRemainingPulls > 0){

		int nThisPulls = min(maxPullsPerPlot,nRemainingPulls);

		TH1F pullSummaryHist("pullSummary","",nThisPulls,0,nThisPulls);
		for (int pi=1;pull_it!=pull_end && pi<=nThisPulls ;pull_it++,pi++){
			pullSummaryHist.GetXaxis()->SetBinLabel(pi,(*pull_it).first);
			pullSummaryHist.SetBinContent(pi,((*pull_it).second).first);
			pullSummaryHist.SetBinError(pi,((*pull_it).second).second);
			nRemainingPulls--;
		}		

		pullSummaryHist.SetMarkerStyle(21);pullSummaryHist.SetMarkerSize(1.5);pullSummaryHist.SetMarkerColor(2);pullSummaryHist.SetLabelSize(pullLabelSize);
		pullSummaryHist.GetYaxis()->SetRangeUser(-1,1);pullSummaryHist.GetYaxis()->SetTitle("residual summary (relative)");pullSummaryHist.Draw("E1");
		hc->SaveAs(Form("%s_normresiduals_%s.pdf",treename.c_str(),(do7TeV ? "7TeV": "8TeV")));
                hc->SaveAs(Form("mlfit/residual_summary_%d_%s_%s.pdf",pullPlots,treename.c_str(),(do7TeV ? "7TeV": "8TeV")));
		fOut->WriteObject(hc,Form("comb_pulls_%s_%d",treename.c_str(),pullPlots));
	//	hc->SaveAs(Form("comb_pulls_%s_%d.pdf",treename.c_str(),pullPlots));
		pullPlots++;
	   }

	    delete hc;
	}

	c->SaveAs(Form("%s_normresiduals_%s.pdf]",treename.c_str(),(do7TeV ? "7TeV": "8TeV")));
	fOut->Close();
	delete c;
	return;


}
コード例 #8
0
void plotTree(TTree *tree_, std::string whichfit, std::string selectString){

	// Create a map for plotting the pullsummaries:
	std::map < const char*, std::pair <double,double> > pullSummaryMap;
	int nPulls=0;

	TObjArray *l_branches = tree_->GetListOfBranches();
	int nBranches = l_branches->GetEntries();

	gStyle->SetPadTopMargin(0.01);

	TCanvas *c = new TCanvas("c","",960,800);

	std::string treename = tree_->GetName();
	c->SaveAs(Form("%s.pdf[",treename.c_str()));
	// File to store plots in 
	TFile *fOut = new TFile(Form("%s.root",treename.c_str()),"RECREATE");

	for (int iobj=0;iobj<nBranches;iobj++){

		TBranch *br =(TBranch*) l_branches->At(iobj);

		// Draw the normal histogram
		const char* name = br->GetName();

                // names with - are not allowed
                string namestr(name);
                if(namestr.find("-")!=string::npos) {
                  std::cout << "Variable " << name << " contains a bad character: -. Skipping. " << std::endl;
                  continue;
                }
		bool fitPull=false;
		bool fitPullf=false;

		bool plotLH=false;

		TGraph *gr=NULL;
		double p_mean =0;
		double p_err  =0;

		int nToysInTree = tree_->GetEntries();
		// Find out if paramter is fitted value or constraint term
		bool isFitted = findNuisancePre(name);
		if (doPull && isFitted){
			
			p_mean = bfvals_[name].first;	// toy constrainits thrown about best fit to data
			if(namestr.find("n_exp")==string::npos) p_err  = prevals_[name].second; // uncertainties taken from card
			std::cout << "******* "<< name << " *******"<<std::endl;
			std::cout << p_mean <<  " " << p_err << std::endl;
			std::cout << "******************************" <<std::endl;

			const char* drawInput;
                        // if the parameter is a normalization, the error is not available. Do the residual instead of the pull
                        if(namestr.find("n_exp")!=string::npos) drawInput = Form("(%s-%f)/%f",name,p_mean,p_mean);
                        else drawInput = Form("(%s-%f)/%f",name,p_mean,p_err);
			tree_->Draw(Form("%s>>%s",drawInput,name),"");
			tree_->Draw(Form("%s>>%s_fail",drawInput,name),selectString.c_str(),"same");
			fitPull  = true;
			fitPullf = true;
			if (doLH) {
			  gr = graphLH(name,p_err,whichfit);
			  if (gr) plotLH=true;
			}
			
		}

		else{
			tree_->Draw(Form("%s>>%s",name,name),"");
			tree_->Draw(Form("%s>>%s_fail",name,name),selectString.c_str(),"same");
		}
		

		TH1F* bH  = (TH1F*) gROOT->FindObject(Form("%s",name))->Clone();
		TH1F* bHf = (TH1F*) gROOT->FindObject(Form("%s_fail",name))->Clone();
		bHf->SetLineColor(2);
		bH->GetXaxis()->SetTitle(bH->GetTitle());
		bH->GetYaxis()->SetTitle(Form("no toys (%d total)",nToysInTree));
		bH->GetYaxis()->SetTitleOffset(1.05);
		bH->GetXaxis()->SetTitleOffset(0.9);
		bH->GetYaxis()->SetTitleSize(0.05);
		bH->GetXaxis()->SetTitleSize(0.05);
		if (isFitted) {bH->GetXaxis()->SetTitle(Form("(%s-#theta_{B})/#sigma_{#theta}",name));}
		else {bH->GetXaxis()->SetTitle(Form("%s",name));}
		
		bH->SetTitle("");	

		if ( bH->Integral() <=0 )  fitPull = false;
		if (fitPull) {bH->Fit("gaus"); bH->GetFunction("gaus")->SetLineColor(4);}
		
		if ( bHf->Integral() <=0 )  fitPullf = false;
		if (fitPullf) {bHf->Fit("gaus"); bHf->GetFunction("gaus")->SetLineColor(2);}

		c->Clear();
		//TPad pad1("t1","",0.01,0.02,0.59,0.98);
		// Pad 1 sizes depend on the parameter type ...
		double pad1_x1,pad1_x2,pad1_y1,pad1_y2;
		if ( !isFitted ) {
			 pad1_x1 = 0.01; 
			 pad1_x2 = 0.98; 
			 pad1_y1 = 0.045; 
			 pad1_y2 = 0.98; 
		} else {
			 pad1_x1 = 0.01; 
			 pad1_x2 = 0.59; 
			 pad1_y1 = 0.56; 
			 pad1_y2 = 0.98; 
		}
		
		TPad pad1("t1","",pad1_x1,pad1_y1,pad1_x2,pad1_y2);
		TPad pad1a("t1a","",0.01,0.045,0.59,0.522);
		TPad pad2("t2","",0.59,0.04,0.98,0.62);
		TPad pad3("t3","",0.55,0.64,0.96,0.95);

		pad1.SetNumber(1); pad2.SetNumber(2); pad3.SetNumber(3); pad1a.SetNumber(4);

		if ( isFitted ) {pad1a.Draw();pad2.Draw();pad3.Draw();}

		pad1.Draw();
		pad2.SetGrid(true);


		TLatex *titletext = new TLatex();titletext->SetNDC();

		if ( isFitted ){
			c->cd(4); 
			tree_->Draw(Form("%s:%s_In>>%s_%s_2d",name,name,name,tree_->GetName()),""); 
			//TH2D *h2d_corr = (TH2D*)gROOT->FindObject(Form("%s_2d",name));
			//h2d_corr->SetMarkerColor(4);
			//h2d_corr->SetTitle("");
			//h2d_corr->GetXaxis()->SetTitle(Form("%s_In",name));
			//h2d_corr->GetYaxis()->SetTitle(Form("%s",name));
			titletext->SetTextAlign(11);
			titletext->SetTextSize(0.05);
			titletext->DrawLatex(0.05,0.02,Form("%s_In",name));
			titletext->SetTextAngle(90);
			titletext->DrawLatex(0.04,0.06,Form("%s",name));
			titletext->SetTextAngle(0);
		}

		
		c->cd(1); bH->Draw(); bHf->Draw("same");
		TLegend *legend = new TLegend(0.6,0.8,0.9,0.89);
		legend->SetFillColor(0);
		legend->AddEntry(bH,"All Toys","L");
		legend->AddEntry(bHf,selectString.c_str(),"L");
		legend->Draw();

		if (doPull && plotLH) {
			c->cd(2); gr->Draw("ALP");
		}

		if (fitPull){
			c->cd(3);
			double gap;
			TLatex *tlatex = new TLatex(); tlatex->SetNDC(); 
			if (fitPullf) {tlatex->SetTextSize(0.09); gap=0.12;}
			else  {tlatex->SetTextSize(0.11);gap=0.14;}

			tlatex->SetTextColor(4);
			tlatex->DrawLatex(0.11,0.80,Form("Mean    : %.3f #pm %.3f",bH->GetFunction("gaus")->GetParameter(1),bH->GetFunction("gaus")->GetParError(1)));
			tlatex->DrawLatex(0.11,0.80-gap,Form("Sigma   : %.3f #pm %.3f",bH->GetFunction("gaus")->GetParameter(2),bH->GetFunction("gaus")->GetParError(2)));

			if (fitPullf){ 
				tlatex->SetTextColor(2);
				tlatex->DrawLatex(0.11,0.60,Form("Mean    : %.3f #pm %.3f",bHf->GetFunction("gaus")->GetParameter(1),bHf->GetFunction("gaus")->GetParError(1)));
				tlatex->DrawLatex(0.11,0.60-gap,Form("Sigma   : %.3f #pm %.3f",bHf->GetFunction("gaus")->GetParameter(2),bHf->GetFunction("gaus")->GetParError(2)));
			}

			tlatex->SetTextSize(0.10);
			tlatex->SetTextColor(1);
				
                        if(namestr.find("n_exp")!=string::npos) tlatex->DrawLatex(0.11,0.33,Form("Pre-fit: %.3f",prevals_[name].first));
			else tlatex->DrawLatex(0.11,0.33,Form("Pre-fit #pm #sigma_{#theta}: %.3f #pm %.3f",prevals_[name].first, p_err));
			tlatex->DrawLatex(0.11,0.18,Form("Best-fit (#theta_{B})  : %.3f ",p_mean));
			tlatex->DrawLatex(0.11,0.03,Form("Best-fit (#theta_{S+B}): %.3f ",bfvals_sb_[name].first));
			
			pullSummaryMap[name]=std::make_pair<double,double>(bH->GetFunction("gaus")->GetParameter(1),bH->GetFunction("gaus")->GetParameter(2));
			nPulls++;

		}

		double titleSize = isFitted ? 0.1 : 0.028;
		titletext->SetTextSize(titleSize);titletext->SetTextAlign(21); titletext->DrawLatex(0.55,0.92,name);
		c->SaveAs(Form("%s.pdf",treename.c_str()));
		fOut->WriteObject(c,Form("%s_%s",treename.c_str(),name));
		//c->SaveAs(Form("%s_%s.pdf",treename.c_str(),name));
	}
	
	if (doPull && nPulls>0){
	  
	    std::cout << "Generating Pull Summaries" <<std::endl; 
	    int nRemainingPulls = nPulls;
	    TCanvas *hc = new TCanvas("hc","",3000,2000); hc->SetGrid(0);
	    std::map < const char*, std::pair <double,double> >::iterator pull_it = pullSummaryMap.begin();
	    std::map < const char*, std::pair <double,double> >::iterator pull_end = pullSummaryMap.end();

	    int pullPlots = 1;
	    while (nRemainingPulls > 0){

		int nThisPulls = min(maxPullsPerPlot,nRemainingPulls);

		TH1F pullSummaryHist("pullSummary","",nThisPulls,0,nThisPulls);
		for (int pi=1;pull_it!=pull_end && pi<=nThisPulls ;pull_it++,pi++){
			pullSummaryHist.GetXaxis()->SetBinLabel(pi,(*pull_it).first);
			pullSummaryHist.SetBinContent(pi,((*pull_it).second).first);
			pullSummaryHist.SetBinError(pi,((*pull_it).second).second);
			nRemainingPulls--;
		}		

		pullSummaryHist.SetMarkerStyle(21);pullSummaryHist.SetMarkerSize(1.5);pullSummaryHist.SetMarkerColor(2);pullSummaryHist.SetLabelSize(pullLabelSize);
		pullSummaryHist.GetYaxis()->SetRangeUser(-3,3);pullSummaryHist.GetYaxis()->SetTitle("pull summary (n#sigma)");pullSummaryHist.Draw("E1");
		hc->SaveAs(Form("%s.pdf",treename.c_str()));
		fOut->WriteObject(hc,Form("comb_pulls_%s_%d",treename.c_str(),pullPlots));
	//	hc->SaveAs(Form("comb_pulls_%s_%d.pdf",treename.c_str(),pullPlots));
		pullPlots++;
	   }

	    delete hc;
	}

	c->SaveAs(Form("%s.pdf]",treename.c_str()));
	fOut->Close();
	delete c;
	return;


}