c_cpp 生成具有Tof状态QA的直方图的根文件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 生成具有Tof状态QA的直方图的根文件相关的知识,希望对你有一定的参考价值。


<?xml version="1.0" encoding="UTF-8"?>

<config>

	<glob url="D31373E7B3B902EB259468B9A70492C7_10*.ntuple.root" />
	<!-- histograms to auto-make -->
	<histograms>
		<Histo name="Trays" title="Trays" min="0" max="121" width="1" />
		<Histo name="Module" title="Module" min="0" max="33" width="1" />
		<Histo name="Cell" title="Cell" min="1" max="7" width="1" />
	</histograms>

		

</config>
	


{

	Logger::setGlobalLogLevel( "info" );

	XmlConfig c( "TofStatusQA.xml" );
	HistoBook b( "TofStatusQA.root", c );

	b.makeAll( "histograms" );
	INFO( "", "# of histograms = " << b.size() );

	TChain * tof = new TChain( "tof" );

	tof->Add( c.getString( "glob:url" ).c_str() );

	tof->Draw( "tray>>Trays" );

	b.cd("modules");
	for ( int iTray = 1; iTray < 121; iTray ++ ){
		b.clone( "", "Module", "Module_" + ts(iTray) );
		INFO( "", "Modules for Tray " << iTray );
		tof->Draw( ("module>>Module_" + ts(iTray)).c_str(), ("tray==" + ts(iTray)).c_str() );
	}

	b.cd("cells");
	for ( int iTray = 1; iTray < 121; iTray ++ ){
		for ( int iMod = 1; iMod <= 32; iMod ++ ){
			INFO( "", "Cells for Tray " << iTray << ", Module " << iMod  );
			string name = "Cell_" + ts(iTray) + "_" + ts(iMod);
			b.clone( "", "Cell", name );	
			tof->Draw( ("cell>>" + name ).c_str(), ("tray==" + ts(iTray) + " && module==" + ts(iMod) ).c_str() );
		}
	}


	b.save();

}


{

	TFile * f = new TFile( "TofStatusQA.root" );

	vector<bool> tray_status;
	tray_status.push_back( false ); // index starts at 1
	map< string, bool> module_status;


	TH1* Trays = (TH1*)f->Get( "Trays" ); 


	for ( int i = 1; i < 121; i++ ){
		if ( 1 >= Trays->GetBinContent( i+1 ) ){
			cout << i << " 0 " << endl;
			tray_status.push_back( false );
		} else {
			tray_status.push_back( true );
		}
	}


	for ( int i = 1; i < 121; i++ ){
		TH1 * modules = (TH1*)f->Get( ("modules/Module_" + ts(i)).c_str() );
		if ( nullptr == modules ) continue;
		if ( false == tray_status[ i ]  ) continue;

		for ( int j = 1; j <= 32; j++ ){
			if ( 1 >= modules->GetBinContent( j+1 ) ){
				cout << i << " " << j << " 0" << endl;
				module_status[ ts(i) + "_" + ts(j) ] = false;
			} else {
				module_status[ ts(i) + "_" + ts(j) ] = true;
			}
		}
	}


	for ( int i = 1; i < 121; i++ ){
		if ( false == tray_status[ i ]  ) continue;

		for ( int j = 1; j <= 32; j++ ){
			
			TH1 * cells = (TH1*)f->Get( ("cells/Cell_" + ts(i) + "_" + ts(j) ).c_str() );
			if ( nullptr == cells ) continue;
			if ( false == module_status[ ts(i) + "_" + ts(j) ] ) continue;

			for ( int k = 1; k <= 6; k++ ){
				if ( 1 >= cells->GetBinContent( k ) )
				cout << i << " " << j << " " << k << endl;	
			}
		}
	}


}

以上是关于c_cpp 生成具有Tof状态QA的直方图的根文件的主要内容,如果未能解决你的问题,请参考以下文章

c_cpp 直方图中最大的矩形区域

c_cpp ROOT Plot直方图

c_cpp CV - 反投影直方图。

c_cpp CV - 计算1D直方图

c_cpp 多线程QA.cpp

XDocument 读取具有名称空间的根元素的 XML 文件