Пример #1
0
void LLCrashLogger::gatherFiles()
{
	llinfos << "Gathering logs..." << llendl;
 
    LLSD static_sd;
    LLSD dynamic_sd;
    
    bool has_logs = readDebugFromXML( static_sd, "static_debug_info.log" );
    has_logs |= readDebugFromXML( dynamic_sd, "dynamic_debug_info.log" );
    
    if ( has_logs )
    {
        mDebugLog = static_sd;
        mergeLogs(dynamic_sd);
		mCrashInPreviousExec = mDebugLog["CrashNotHandled"].asBoolean();

		mFileMap["SecondLifeLog"] = mDebugLog["SLLog"].asString();
		mFileMap["SettingsXml"] = mDebugLog["SettingsFilename"].asString();
		if(mDebugLog.has("CAFilename"))
		{
			LLCurl::setCAFile(mDebugLog["CAFilename"].asString());
		}
		else
		{
			LLCurl::setCAFile(gDirUtilp->getCAFile());
		}

		llinfos << "Using log file from debug log " << mFileMap["SecondLifeLog"] << llendl;
		llinfos << "Using settings file from debug log " << mFileMap["SettingsXml"] << llendl;
	}
	else
	{
		// Figure out the filename of the second life log
		LLCurl::setCAFile(gDirUtilp->getCAFile());
		mFileMap["SecondLifeLog"] = gDirUtilp->getExpandedFilename(LL_PATH_LOGS,"SecondLife.log");
		mFileMap["SettingsXml"] = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS,"settings.xml");
	}

	if(mCrashInPreviousExec)
	{
		// Restarting after freeze.
		// Replace the log file ext with .old, since the 
		// instance that launched this process has overwritten
		// SecondLife.log
		std::string log_filename = mFileMap["SecondLifeLog"];
		log_filename.replace(log_filename.size() - 4, 4, ".old");
		mFileMap["SecondLifeLog"] = log_filename;
	}

	gatherPlatformSpecificFiles();

	mCrashInfo["DebugLog"] = mDebugLog;
	mFileMap["StatsLog"] = gDirUtilp->getExpandedFilename(LL_PATH_DUMP,"stats.log");
	// Singu Note: we have just started again, log has been renamed
	mFileMap["SecondLifeLog"] = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, OLD_LOG_FILE);

	llinfos << "Encoding files..." << llendl;

	for(std::map<std::string, std::string>::iterator itr = mFileMap.begin(); itr != mFileMap.end(); ++itr)
	{
		std::ifstream f((*itr).second.c_str());
		if(!f.is_open())
		{
			llinfos << "Can't find file " << (*itr).second << llendl;
			continue;
		}
		std::stringstream s;
		s << f.rdbuf();

		std::string crash_info = s.str();
		if(itr->first == "SecondLifeLog")
		{
			if(!mCrashInfo["DebugLog"].has("StartupState"))
			{
				mCrashInfo["DebugLog"]["StartupState"] = getStartupStateFromLog(crash_info);
			}
			trimSLLog(crash_info);
		}

		mCrashInfo[(*itr).first] = LLStringFn::strip_invalid_xml(rawstr_to_utf8(crash_info));
	}
	
	std::string minidump_path;

	// Add minidump as binary.
    bool has_minidump = mDebugLog.has("MinidumpPath");

	if (has_minidump)
		minidump_path = mDebugLog["MinidumpPath"].asString();

    
	if (has_minidump)
	{
		has_minidump = readMinidump(minidump_path);
	}

    if (!has_minidump)  //Viewer was probably so hosed it couldn't write remaining data.  Try brute force.
    {
       //Look for a filename at least 30 characters long in the dump dir which contains the characters MDMP as the first 4 characters in the file.
        typedef std::vector<std::string> vec;
    
        std::string pathname = gDirUtilp->getExpandedFilename(LL_PATH_DUMP,"");
        vec file_vec = gDirUtilp->getFilesInDir(pathname);
        for(vec::const_iterator iter=file_vec.begin(); iter!=file_vec.end(); ++iter)
        {
            if ( ( iter->length() > 30 ) && (iter->rfind(".log") != (iter->length()-4) ) )
            {
                std::string fullname = pathname + *iter;
                std::ifstream fdat( fullname.c_str(), std::ifstream::binary);
                if (fdat)
                {
                    char buf[5];
                    fdat.read(buf,4);
                    fdat.close();
                    if (!strncmp(buf,"MDMP",4))
                    {
                        minidump_path = *iter;
                        has_minidump = readMinidump(fullname);
						mDebugLog["MinidumpPath"] = fullname;
                    }
                }
            }
        }
    }
}
Пример #2
0
void SFT_Fiber_Efficiency(Int_t run_number=1181, Int_t flag=0) {

gStyle->SetOptStat(0);

Int_t count_l1or = 0;
Int_t count_l1and = 0;
Int_t count_l2or = 0;
Int_t count_l2and = 0;
Int_t count_l3or = 0;
Int_t count_l3and = 0;
Int_t count_l4or = 0;
Int_t count_l4and = 0;

Int_t countlayer1or[15] = {0};
Int_t countlayer2or[15] = {0};
Int_t countlayer3or[17] = {0};
Int_t countlayer4or[17] = {0};

Int_t countlayer1and[15] = {0};
Int_t countlayer2and[15] = {0};
Int_t countlayer3and[17] = {0};
Int_t countlayer4and[17] = {0};

Int_t ADC_High_target[256];		Int_t ADC_High_sft[128];
Int_t ADC_Low_target[256];		Int_t ADC_Low_sft[128];
Int_t TDC_LE_target[256][16];		Int_t TDC_LE_sft[128][16];
Int_t TDC_TE_target[256][16];		Int_t TDC_TE_sft[128][16];

Int_t ADC_tof1[24];
Int_t ADC_tof2[48];

Int_t fiber[128]={-1};
Int_t fiberTDC[128]={-1};

char Name_Can[100];			char Title_Can[100];
sprintf(Name_Can,"ADC -- Run %d -- SFT_Fiber_Efficiency.C",run_number);
sprintf(Title_Can,"ADC -- Run %d  -- SFT_Fiber_Efficiency.C",run_number);

char par_map[200];		char par_finput[200];
//sprintf(par_finput,"/media/bianchin/hdd1/trek/E36/Macros/April_2015/Mapping/SFT_Mapping_Oct14.txt");
sprintf(par_map,"../Mapping");
sprintf(par_finput,"%s/SFT_Mapping_Oct14.txt",par_map);

char path_input[200];
//sprintf(path_input,"/media/bianchin/hdd1/trek/E36/Data/June_2015/root/Merged");
sprintf(path_input,path_merged);

char Name_finput[200];
sprintf(Name_finput,"%s/Run%dMS.root",path_input, run_number);

///

char par_finput2[200];
//sprintf(par_finput,"/triumfcs/trshare/trek/E36/Macros/April_2015/Mapping/%s",source_mapping);
sprintf(par_finput2,"%s/MWPC_map.txt",par_map);

char par_finput3[200];
//sprintf(par_finput,"/triumfcs/trshare/trek/E36/Macros/April_2015/Mapping/%s",source_mapping);
sprintf(par_finput3,"%s/ADC_TARGET_Thresholds.txt",par_map);

char par_finput4[200];
//sprintf(par_finput,"/triumfcs/trshare/trek/E36/Macros/April_2015/Mapping/%s",source_mapping);
sprintf(par_finput4,"%s/ADC_SFT_Thresholds.txt",par_map);

///

Int_t par_temp[2][128];
ifstream fdat(par_finput,ios::in);
for(Int_t ii=0; ii<128; ii++) fdat >> par_temp[0][ii] >> par_temp[1][ii];
fdat.close();

Int_t par_temp_TARGET[2][256];
ifstream fdat3(par_finput3,ios::in);
for(Int_t ii=0; ii<256; ii++) fdat3 >> par_temp_TARGET[0][ii] >> par_temp_TARGET[1][ii];
fdat3.close();

Int_t par_temp_SFT[2][128];
ifstream fdat4(par_finput4,ios::in);
for(Int_t ii=0; ii<128; ii++) fdat4 >> par_temp_SFT[0][ii] >> par_temp_SFT[1][ii];
fdat4.close();

/////////////////////// Histograms
TH1D *h_layer1or;	char Title_h_layer1or[100];	char Name_h_layer1or[100];
TH1D *h_layer1and;	char Title_h_layer1and[100];	char Name_h_layer1and[100];
TH1D *h_layer2or;	char Title_h_layer2or[100];	char Name_h_layer2or[100];
TH1D *h_layer2and;	char Title_h_layer2and[100];	char Name_h_layer2and[100];
TH1D *h_layer3or;	char Title_h_layer3or[100];	char Name_h_layer3or[100];
TH1D *h_layer3and;	char Title_h_layer3and[100];	char Name_h_layer3and[100];
TH1D *h_layer4or;	char Title_h_layer4or[100];	char Name_h_layer4or[100];
TH1D *h_layer4and;	char Title_h_layer4and[100];	char Name_h_layer4and[100];

sprintf(Title_h_layer1or,"SFT Fiber Efficiencies Layer 1 - Run %d: ADC > %d , %d < TDC < %d", run_number, 0, TDC_min_SFT, TDC_max_SFT); 
sprintf(Name_h_layer1or,"Layer 1"); 
h_layer1or = new TH1D(Name_h_layer1or,Title_h_layer1or,17,0,17);

sprintf(Title_h_layer1and,"SFT Fiber Efficiencies Layer 1 - Run %d: ADC > %d , %d < TDC < %d", run_number, 0, TDC_min_SFT, TDC_max_SFT); 
sprintf(Name_h_layer1and,"Layer 1"); 
h_layer1and = new TH1D(Name_h_layer1and,Title_h_layer1and,17,0,17);

sprintf(Title_h_layer2or,"SFT Fiber Efficiencies Layer 2 - Run %d: ADC > %d , %d < TDC < %d", run_number, 0, TDC_min_SFT, TDC_max_SFT); 
sprintf(Name_h_layer2or,"Layer 2"); 
h_layer2or = new TH1D(Name_h_layer2or,Title_h_layer2or,17,0,17);

sprintf(Title_h_layer2and,"SFT Fiber Efficiencies Layer 2 - Run %d: ADC > %d , %d < TDC < %d", run_number, 0, TDC_min_SFT, TDC_max_SFT); 
sprintf(Name_h_layer2and,"Layer 2"); 
h_layer2and = new TH1D(Name_h_layer2and,Title_h_layer2and,17,0,17);

sprintf(Title_h_layer3or,"SFT Fiber Efficiencies Layer 3 - Run %d: ADC > %d , %d < TDC < %d", run_number, 0, TDC_min_SFT, TDC_max_SFT); 
sprintf(Name_h_layer3or,"Layer 3"); 
h_layer3or = new TH1D(Name_h_layer3or,Title_h_layer3or,19,0,19);

sprintf(Title_h_layer3and,"SFT Fiber Efficiencies Layer 3 - Run %d: ADC > %d , %d < TDC < %d", run_number, 0, TDC_min_SFT, TDC_max_SFT); 
sprintf(Name_h_layer3and,"Layer 3"); 
h_layer3and = new TH1D(Name_h_layer3and,Title_h_layer3and,19,0,19);

sprintf(Title_h_layer4or,"SFT Fiber Efficiencies Layer 4 - Run %d: ADC > %d , %d < TDC < %d", run_number, 0, TDC_min_SFT, TDC_max_SFT); 
sprintf(Name_h_layer4or,"Layer 4"); 
h_layer4or = new TH1D(Name_h_layer4or,Title_h_layer4or,19,0,19);

sprintf(Title_h_layer4and,"SFT Fiber Efficiencies Layer 4 - Run %d: ADC > %d , %d < TDC < %d", run_number, 0, TDC_min_SFT, TDC_max_SFT); 
sprintf(Name_h_layer4and,"Layer 4"); 
h_layer4and = new TH1D(Name_h_layer4and,Title_h_layer4and,19,0,19);

///////////////////////

//TChain *fChain_TARGET = new TChain("Tree_TARGET");
//TChain *fChain_SFT = new TChain("Tree_SFT");

//fChain_TARGET->Add(Name_finput);      
//fChain_SFT->Add(Name_finput);      

cout << "   " << endl;
cout << "Mapping File:   " << par_finput << endl;
cout << "" << endl;

//cout << "    " << endl;
//cout << "I'm in the File !" << endl;
//cout << Name_finput << endl;
//cout << "    " << endl;

TChain *fChain = new TChain("Tree");

fChain->Add(Name_finput);      

cout << "    " << endl;
cout << "I'm in the File !" << endl;
cout << Name_finput << endl;
cout << "    " << endl;

fChain->SetMakeClass(1);
fChain->SetBranchAddress("ADC_High_TARGET",ADC_High_target);
fChain->SetBranchAddress("ADC_Low_TARGET",ADC_Low_target);
fChain->SetBranchAddress("TDC_LE_TARGET",TDC_LE_target);
fChain->SetBranchAddress("TDC_TE_TARGET",TDC_TE_target);

fChain->SetBranchAddress("ADC_High_SFT",ADC_High_sft);
fChain->SetBranchAddress("ADC_Low_SFT",ADC_Low_sft);
fChain->SetBranchAddress("TDC_LE_SFT",TDC_LE_sft);
fChain->SetBranchAddress("TDC_TE_SFT",TDC_TE_sft);

fChain->SetBranchAddress("ADC_TOF1",ADC_tof1);

fChain->SetBranchAddress("ADC_TOF2",ADC_tof2);

//fChain_TARGET->SetMakeClass(1);
//fChain_TARGET->SetBranchAddress("ADC_High_TARGET",ADC_High_target);
//fChain_TARGET->SetBranchAddress("ADC_Low_TARGET",ADC_Low_target);
//fChain_TARGET->SetBranchAddress("TDC_LE_TARGET",TDC_LE_target);
//fChain_TARGET->SetBranchAddress("TDC_TE_TARGET",TDC_TE_target);

//fChain_SFT->SetMakeClass(1);
//fChain_SFT->SetBranchAddress("ADC_High_SFT",ADC_High_sft);
//fChain_SFT->SetBranchAddress("ADC_Low_SFT",ADC_Low_sft);
//fChain_SFT->SetBranchAddress("TDC_LE_SFT",TDC_LE_sft);
//fChain_SFT->SetBranchAddress("TDC_TE_SFT",TDC_TE_sft);

Int_t nentries = (Int_t)fChain->GetEntries();
cout <<  "DEBUG :     " <<  nentries << endl;

if(flag!=0) nentries=flag;
for (Int_t j=0; j<nentries; j++) {

//	fChain_SFT->GetEntry(j);
	fChain->GetEntry(j);	

	if(j%10000==1)
	cout<<"**** "<< j <<" events done"<<endl;

	bool l1_or = false;
	bool l1_and = false;
	bool l2_or = false;
	bool l2_and = false;
	bool l3_or = false;
	bool l3_and = false;
	bool l4_or = false;
	bool l4_and = false;

	// Variable Change
	for(Int_t ii=0; ii<128; ii++){
		ADC_High_sft[ii] = ADC_High_sft[ii] - par_temp_SFT[1][ii];
		fiber[ii]=ADC_High_sft[par_temp[1][ii]];
		fiberTDC[ii]=TDC_LE_sft[par_temp[1][ii]][0];
	}

///Layer 1
	for (Int_t i=0; i<15; i++) {
		if (((fiber[i]>0) && (fiberTDC[i]>TDC_min_SFT) && (fiberTDC[i]<TDC_max_SFT)) || ((fiberTDC[i+64]>TDC_min_SFT) && (fiberTDC[i+64]<TDC_max_SFT) && (fiber[i+64]>0))) {
			countlayer1or[i]++;
			l1_or = true;
		}
		if (((fiber[i]>0) && (fiberTDC[i]>TDC_min_SFT) && (fiberTDC[i]<TDC_max_SFT)) && ((fiberTDC[i+64]>TDC_min_SFT) && (fiberTDC[i+64]<TDC_max_SFT) && (fiber[i+64]>0))) {
			countlayer1and[i]++;
			l1_and = true;
		}
	}
///Layer 2
	for (Int_t i=15; i<30; i++) {
		if (((fiber[i]>0) && (fiberTDC[i]>TDC_min_SFT) && (fiberTDC[i]<TDC_max_SFT)) || ((fiberTDC[i+64]>TDC_min_SFT) && (fiberTDC[i+64]<TDC_max_SFT) && (fiber[i+64]>0))) {
			countlayer2or[i-15]++;
			l2_or = true;
		}
		if (((fiber[i]>0) && (fiberTDC[i]>TDC_min_SFT) && (fiberTDC[i]<TDC_max_SFT)) && ((fiberTDC[i+64]>TDC_min_SFT) && (fiberTDC[i+64]<TDC_max_SFT) && (fiber[i+64]>0))) {
			countlayer2and[i-15]++;
			l2_and = true;
		}
	}
///Layer 3
	for (Int_t i=30; i<47; i++) {
		if (((fiber[i]>0) && (fiberTDC[i]>TDC_min_SFT) && (fiberTDC[i]<TDC_max_SFT)) || ((fiberTDC[i+64]>TDC_min_SFT) && (fiberTDC[i+64]<TDC_max_SFT) && (fiber[i+64]>0))) {
			countlayer3or[i-30]++;
			l3_or = true;
		}
		if (((fiber[i]>0) && (fiberTDC[i]>TDC_min_SFT) && (fiberTDC[i]<TDC_max_SFT)) && ((fiberTDC[i+64]>TDC_min_SFT) && (fiberTDC[i+64]<TDC_max_SFT) && (fiber[i+64]>0))) {
			countlayer3and[i-30]++;
			l3_and = true;
		}
	}
///Layer 4
	for (Int_t i=47; i<64; i++) {
		if (((fiber[i]>0) && (fiberTDC[i]>TDC_min_SFT) && (fiberTDC[i]<TDC_max_SFT)) || ((fiberTDC[i+64]>TDC_min_SFT) && (fiberTDC[i+64]<TDC_max_SFT) && (fiber[i+64]>0))) {
			countlayer4or[i-47]++;
			l4_or = true;
		}
		if (((fiber[i]>0) && (fiberTDC[i]>TDC_min_SFT) && (fiberTDC[i]<TDC_max_SFT)) && ((fiberTDC[i+64]>TDC_min_SFT) && (fiberTDC[i+64]<TDC_max_SFT) && (fiber[i+64]>0))) {
			countlayer4and[i-47]++;
			l4_and = true;
		}
	}

// Individual Layer Counter	
	if (l1_or) count_l1or++; 
	if (l1_and) count_l1and++; 
	if (l2_or) count_l2or++;
	if (l2_and) count_l2and++; 	
	if (l3_or) count_l3or++; 	
	if (l3_and) count_l3and++; 	
	if (l4_or) count_l4or++; 	
	if (l4_and) count_l4and++; 	
}

//cout << count_l1or++ << endl; 
//cout << count_l1and++ << endl; 
//cout << count_l2or++ << endl; 
//cout << count_l2and++ << endl; 	
//cout << count_l3or++ << endl; 	
//cout << count_l3and++ << endl; 	
//cout << count_l4or++ << endl; 	
//cout << count_l4and++ << endl; 


/*
for(Int_t i=0; i<15; i++) {
	cout << "Layer 1 Fiber " << i << " count: " << countlayer1or[i] << endl;
}

cout << " " << endl;

for(Int_t i=0; i<15; i++) {
	cout << "Layer 2 Fiber " << i << " count: " << countlayer2or[i] << endl;
}

cout << " " << endl;

for(Int_t i=0; i<17; i++) {
	cout << "Layer 3 Fiber " << i << " count: " << countlayer3or[i] << endl;
}

cout << " " << endl;

for(Int_t i=0; i<17; i++) {
	cout << "Layer 4 Fiber " << i << " count: " << countlayer4or[i] << endl;
}	

for(Int_t i=0; i<15; i++) h_layer1or->Fill(i+1,countlayer1or[i]);
for(Int_t i=0; i<15; i++) h_layer1and->Fill(i+1,countlayer1and[i]);
for(Int_t i=0; i<15; i++) h_layer2or->Fill(i+1,countlayer2or[i]);
for(Int_t i=0; i<15; i++) h_layer2and->Fill(i+1,countlayer2and[i]);

for(Int_t j=0; j<17; j++) h_layer3or->Fill(j+1,countlayer3or[j]);
for(Int_t j=0; j<17; j++) h_layer3and->Fill(j+1,countlayer3and[j]);
for(Int_t j=0; j<17; j++) h_layer4or->Fill(j+1,countlayer4or[j]);
for(Int_t j=0; j<17; j++) h_layer4and->Fill(j+1,countlayer4and[j]);
*/

for(Int_t i=0; i<15; i++) h_layer1or->Fill(i+1,double(countlayer1or[i])/double(count_l1or));
for(Int_t i=0; i<15; i++) h_layer1and->Fill(i+1,double(countlayer1and[i])/double(count_l1or));
for(Int_t i=0; i<15; i++) h_layer2or->Fill(i+1,double(countlayer2or[i])/double(count_l2or));
for(Int_t i=0; i<15; i++) h_layer2and->Fill(i+1,double(countlayer2and[i])/double(count_l2or));

for(Int_t j=0; j<17; j++) h_layer3or->Fill(j+1,double(countlayer3or[j])/double(count_l3or));
for(Int_t j=0; j<17; j++) h_layer3and->Fill(j+1,double(countlayer3and[j])/double(count_l3or));
for(Int_t j=0; j<17; j++) h_layer4or->Fill(j+1,double(countlayer4or[j])/double(count_l4or));
for(Int_t j=0; j<17; j++) h_layer4and->Fill(j+1,double(countlayer4and[j])/double(count_l4or));

TCanvas *c1;
c1 = new TCanvas(Name_Can,Title_Can,1000,900); 
c1->Divide(2,2);
c1->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",0,0, "ProcEvent(Int_t,Int_t,Int_t,TObject*)");

TLegend *l1;
l1 = new TLegend(0.82,0.87,0.99,0.99);
l1->AddEntry(h_layer1or, "Up OR Down", "F");
l1->AddEntry(h_layer1and, "Up AND Down", "F");

c1->cd(1);
h_layer1or->SetLineColor(4);
h_layer1or->SetFillStyle(3004);
h_layer1or->SetFillColor(4);
h_layer1or->Draw();

h_layer1and->SetLineColor(2);
h_layer1and->SetFillStyle(3005);
h_layer1and->SetFillColor(2);
h_layer1and->Draw("same");
l1->Draw("same");

c1->cd(2);
h_layer2or->SetLineColor(4);
h_layer2or->SetFillStyle(3004);
h_layer2or->SetFillColor(4);
h_layer2or->Draw();

h_layer2and->SetLineColor(2);
h_layer2and->SetFillStyle(3005);
h_layer2and->SetFillColor(2);
h_layer2and->Draw("same");
l1->Draw("same");

c1->cd(3);

h_layer3or->SetLineColor(4);
h_layer3or->SetFillStyle(3004);
h_layer3or->SetFillColor(4);
h_layer3or->Draw();

h_layer3and->SetLineColor(2);
h_layer3and->SetFillStyle(3005);
h_layer3and->SetFillColor(2);
h_layer3and->Draw("same");
l1->Draw("same");

c1->cd(4);

h_layer4or->SetLineColor(4);
h_layer4or->SetFillStyle(3004);
h_layer4or->SetFillColor(4);
h_layer4or->Draw();

h_layer4and->SetLineColor(2);
h_layer4and->SetFillStyle(3005);
h_layer4and->SetFillColor(2);
h_layer4and->Draw("same");
l1->Draw("same");


}
Пример #3
0
void TOF_E_2D(Int_t run_number=5, Int_t flag=0, Int_t QUIET=0) { 

gStyle->SetOptStat(1111);

Int_t TDC_min_TOF1 = TDC_TOF1_min;
Int_t TDC_max_TOF1 = TDC_TOF1_max;
Int_t TDC_min_TOF2 = TDC_TOF2_min;
Int_t TDC_max_TOF2 = TDC_TOF2_max;

///Adjust chart ranges

Int_t TOF1_xmin = 0;
Int_t TOF1_xmax = 4000;
Int_t TOF1_ymin = 0;
Int_t TOF1_ymax = 4000;

Int_t TOF2_xmin = 0;
Int_t TOF2_xmax = 4000;
Int_t TOF2_ymin = 0;
Int_t TOF2_ymax = 4000;

char* source_mapping="SFT_Mapping_Oct14.txt";

Int_t adc_high_target[256]; 	
Int_t adc_low_target[256]; 		
Int_t tdc_le_target[256][16];      	  	
Int_t tdc_te_target[256][16]; 		

Int_t ADC_High_sft[128];
Int_t ADC_Low_sft[128];
Int_t TDC_LE_sft[128][16];
Int_t TDC_TE_sft[128][16];

Int_t ADC_tof1[24];
Int_t ADC_tof2[56];

Int_t ADC_TOF1[24];
Int_t ADC_TOF2[56];

Int_t TDC_tof1U[12];
Int_t TDC_tof1D[12];

Int_t TDC_tof2AO[12];
Int_t TDC_tof2BO[12];
Int_t TDC_tof2AI[12];
Int_t TDC_tof2BI[12];

Int_t MwpcADC[512];

//// Canvas board coordinates for TOF histograms

Int_t TOF1_Mapping1[12] = {1,3,5,7,9,11,13,15,17,19,21,23};
Int_t TOF1_Mapping2[12] = {2,4,6,8,10,12,14,16,18,20,22,24};

Int_t TOF2_Mapping1[12] = {1,5,9,13,17,21,25,29,33,37,41,45};
Int_t TOF2_Mapping2[12] = {2,6,10,14,18,22,26,30,34,38,42,46};
Int_t TOF2_Mapping3[12] = {3,7,11,15,19,23,27,31,35,39,43,47};
Int_t TOF2_Mapping4[12] = {4,8,12,16,20,24,28,32,36,40,44,48};	

char path_input[200];                   char file_mapping[200];
sprintf(path_input,path_merged);          sprintf(file_mapping,"../Mapping");
//sprintf(path_input,"/triumfcs/trshare/trek/E36/Data/April_2015/root");

char Name_finput[200];
sprintf(Name_finput,"%s/Run%dMS.root",path_input, run_number);

////

char par_finput[200];
//sprintf(par_finput,"/triumfcs/trshare/trek/E36/Macros/April_2015/Mapping/%s",source_mapping);
sprintf(par_finput,"%s/%s",file_mapping,source_mapping);

char par_finput2[200];
//sprintf(par_finput,"/triumfcs/trshare/trek/E36/Macros/April_2015/Mapping/%s",source_mapping);
sprintf(par_finput2,"%s/MWPC_map.txt",file_mapping);

char par_finput3[200];
//sprintf(par_finput,"/triumfcs/trshare/trek/E36/Macros/April_2015/Mapping/%s",source_mapping);
sprintf(par_finput3,"%s/ADC_TARGET_Thresholds.txt",file_mapping);

char par_finput4[200];
//sprintf(par_finput,"/triumfcs/trshare/trek/E36/Macros/April_2015/Mapping/%s",source_mapping);
sprintf(par_finput4,"%s/ADC_SFT_Thresholds.txt",file_mapping);

char par_finput5[200];
//sprintf(par_finput,"/triumfcs/trshare/trek/E36/Macros/April_2015/Mapping/%s",source_mapping);
sprintf(par_finput5,"%s/ADC_TOF1_Thresholds.txt",file_mapping);

char par_finput6[200];
//sprintf(par_finput,"/triumfcs/trshare/trek/E36/Macros/April_2015/Mapping/%s",source_mapping);
sprintf(par_finput6,"%s/ADC_TOF2_Thresholds.txt",file_mapping);

////

Int_t par_temp[2][128];
ifstream fdat(par_finput,ios::in);
for(Int_t ii=0; ii<128; ii++) fdat >> par_temp[0][ii] >> par_temp[1][ii];
fdat.close();

char par_temp2[512][50];
//char par_temp3[512][50];
ifstream fdat2(par_finput2,ios::in);
for(Int_t ii=0; ii<512; ii++) fdat2 >> par_temp2[ii];
fdat2.close();

Int_t par_temp_TARGET[2][256];
ifstream fdat3(par_finput3,ios::in);
for(Int_t ii=0; ii<256; ii++) fdat3 >> par_temp_TARGET[0][ii] >> par_temp_TARGET[1][ii];
fdat3.close();

Int_t par_temp_SFT[2][128];
ifstream fdat4(par_finput4,ios::in);
for(Int_t ii=0; ii<128; ii++) fdat4 >> par_temp_SFT[0][ii] >> par_temp_SFT[1][ii];
fdat4.close();

Int_t par_temp_TOF1[2][24];
ifstream fdat5(par_finput5,ios::in);
for(Int_t ii=0; ii<24; ii++) fdat5 >> par_temp_TOF1[0][ii] >> par_temp_TOF1[1][ii];
fdat5.close();

Int_t par_temp_TOF2[2][56];
ifstream fdat6(par_finput6,ios::in);
for(Int_t ii=0; ii<56; ii++) fdat6 >> par_temp_TOF2[0][ii] >> par_temp_TOF2[1][ii];
fdat6.close();

//char footer[100];
//sprintf(footer,"Event_Display_MS.C  --  Run %d ; Event %d",Run_Number,ievt);

cout << "   " << endl;
cout << Name_finput << endl;

TChain *fChain= new TChain("Tree");		
fChain->Add(Name_finput);		
fChain->SetMakeClass(1);							

fChain->SetBranchAddress("ADC_High_TARGET",adc_high_target);		
fChain->SetBranchAddress("ADC_Low_TARGET",adc_low_target);
fChain->SetBranchAddress("TDC_LE_TARGET",tdc_le_target);		
fChain->SetBranchAddress("TDC_TE_TARGET",tdc_te_target);

fChain->SetBranchAddress("ADC_High_SFT",ADC_High_sft);
fChain->SetBranchAddress("ADC_Low_SFT",ADC_Low_sft);
fChain->SetBranchAddress("TDC_LE_SFT",TDC_LE_sft);
fChain->SetBranchAddress("TDC_TE_SFT",TDC_TE_sft);

fChain->SetBranchAddress("ADC_TOF1",ADC_tof1);
fChain->SetBranchAddress("ADC_TOF2",ADC_tof2);
fChain->SetBranchAddress("MWPCADC",MwpcADC);

fChain->SetBranchAddress("TDC_TOF1U",TDC_tof1U);
fChain->SetBranchAddress("TDC_TOF1D",TDC_tof1D);
fChain->SetBranchAddress("TDC_TOF2AO",TDC_tof2AO);
fChain->SetBranchAddress("TDC_TOF2AI",TDC_tof2AI);
fChain->SetBranchAddress("TDC_TOF2BO",TDC_tof2BO);
fChain->SetBranchAddress("TDC_TOF2BI",TDC_tof2BI);			

TH2D *h_ADC_TDC_tof1[24];   char Title_ADC_TDC_tof1[24][100];	char Name_ADC_TDC_tof1[24][100];
TH2D *h_ADC_TDC_tof1_peak[24];   char Title_ADC_TDC_tof1_peak[24][100];	char Name_ADC_TDC_tof1_peak[24][100];

TH2D *h_ADC_TDC_tof2[48];   char Title_ADC_TDC_tof2[48][100];	char Name_ADC_TDC_tof2[48][100];
TH2D *h_ADC_TDC_tof2_peak[48];   char Title_ADC_TDC_tof2_peak[48][100];	char Name_ADC_TDC_tof2_peak[48][100];

for (int i=0; i<24; i++) {
	sprintf(Title_ADC_TDC_tof1[i],"ADC vs. TDC (Ch. %d)  --  TOF1",i);
	sprintf(Name_ADC_TDC_tof1[i],"ADC vs. TDC (Ch. %d) - TOF1",i);
	sprintf(Title_ADC_TDC_tof1_peak[i],"ADC vs. TDC (Ch. %d)  --  TOF1 Peak",i);
	sprintf(Name_ADC_TDC_tof1_peak[i],"ADC vs. TDC (Ch. %d) - TOF1 Peak",i);
}

for (int i=0; i<48; i++) {
	sprintf(Title_ADC_TDC_tof2[i],"ADC vs. TDC (Ch. %d)  --  TOF2",i);
	sprintf(Name_ADC_TDC_tof2[i],"ADC vs. TDC (Ch. %d) - TOF2",i);
	sprintf(Title_ADC_TDC_tof2_peak[i],"ADC vs. TDC (Ch. %d)  --  TOF2 Peak",i);
	sprintf(Name_ADC_TDC_tof2_peak[i],"ADC vs. TDC (Ch. %d) - TOF2 Peak",i);
}


for (int  i=0; i<24; i++) {
h_ADC_TDC_tof1[i] = new TH2D(Name_ADC_TDC_tof1[i],Title_ADC_TDC_tof1[i],1000,0,4000,1000,0,4000);
h_ADC_TDC_tof1_peak[i] = new TH2D(Name_ADC_TDC_tof1_peak[i],Title_ADC_TDC_tof1_peak[i],1000,0,4000,1000,0,4000);
}

for (int  i=0; i<48; i++) {
h_ADC_TDC_tof2[i] = new TH2D(Name_ADC_TDC_tof2[i],Title_ADC_TDC_tof2[i],1000,0,4000,1000,0,4000);
h_ADC_TDC_tof2_peak[i] = new TH2D(Name_ADC_TDC_tof2_peak[i],Title_ADC_TDC_tof2_peak[i],1000,0,4000,1000,0,4000);
}

//read all entries and fill the histograms
Int_t nentries = (Int_t)fChain->GetEntries();
cout <<  "Total Number of Entries :     " <<  nentries << endl;

cout << "  " << endl;

cout << "TDC TOF1 min: " << TDC_TOF1_min << endl;
cout << "TDC TOF1 max: " << TDC_TOF1_max << endl;
cout << "TDC TOF2 min: " << TDC_TOF2_min << endl;
cout << "TDC TOF2 max: " << TDC_TOF2_max << endl;

cout << "  " << endl;
cout << "***************  TOF1  ***************" << endl;
cout << "  " << endl;

if(flag!=0) nentries=flag;

for (Int_t i=0; i<nentries; i++) {
//fChain_TOF1->GetEntry(i);
fChain->GetEntry(i);

	for (Int_t j_TOF1=0; j_TOF1<24; j_TOF1++) {
	   ADC_TOF1[j_TOF1] = ADC_tof1[j_TOF1]-par_temp_TOF1[1][j_TOF1];
	}

	if(QUIET==0){
		if(nentries<=30000){
			if(i%1000==1) cout<<"**** "<<i<<" events done"<<endl;
		}
		if(nentries>30000){
			if(i%10000==1) cout<<"**** "<<i<<" events done"<<endl;
		}
	}

	/// Plot ADC vs. TDC for TOF1

	for (int q=0; q<12; q++) {
		h_ADC_TDC_tof1[q]->Fill(TDC_tof1U[q],ADC_TOF1[q]);
		if (TDC_tof1U[q] > TDC_min_TOF1 && TDC_tof1U[q] < TDC_max_TOF1) h_ADC_TDC_tof1_peak[q]->Fill(TDC_tof1U[q],ADC_TOF1[q]);
	}

	for (int q=12; q<24; q++) {
		h_ADC_TDC_tof1[q]->Fill(TDC_tof1D[q-12],ADC_TOF1[q]);
		if (TDC_tof1D[q-12] > TDC_min_TOF1 && TDC_tof1D[q-12] < TDC_max_TOF1) h_ADC_TDC_tof1_peak[q]->Fill(TDC_tof1D[q-12],ADC_TOF1[q]);
	}

}


if(QUIET==1) cout << "OK !" << endl;

cout << "  " << endl;
cout << "  " << endl;
cout << "***************  TOF2  ***************" << endl;
cout << "  " << endl;

for (Int_t i=0; i<nentries; i++) {
//fChain_TOF2->GetEntry(i);
	fChain->GetEntry(i);

	for (Int_t j_TOF2=0; j_TOF2<56; j_TOF2++) {
   		ADC_TOF2[j_TOF2] = ADC_tof2[j_TOF2]-par_temp_TOF2[1][j_TOF2];
	}

	if(QUIET==0){
		if(nentries<=30000){
			if(i%1000==1) cout<<"**** "<<i<<" events done"<<endl;
		}
		if(nentries>30000){
			if(i%10000==1) cout<<"**** "<<i<<" events done"<<endl;
		}
	}

	/// Plot ADC vs. TDC for TOF2

	for (int q=0; q<12; q++) {
		h_ADC_TDC_tof2[q]->Fill(TDC_tof2AO[q],ADC_TOF2[q]);
		if (TDC_tof2AO[q] > TDC_min_TOF2 && TDC_tof2AO[q] < TDC_max_TOF2) h_ADC_TDC_tof2_peak[q]->Fill(TDC_tof2AO[q],ADC_TOF2[q]);
	}

	for (int q=12; q<24; q++) {
		if (q == 18) {
			h_ADC_TDC_tof2[q]->Fill(TDC_tof2BO[q-12],ADC_TOF2[55]);
			if (TDC_tof2BO[q-12] > TDC_min_TOF2 && TDC_tof2BO[q-12] < TDC_max_TOF2) h_ADC_TDC_tof2_peak[q]->Fill(TDC_tof2BO[q-12],ADC_TOF2[55]);
		}
		else {
			h_ADC_TDC_tof2[q]->Fill(TDC_tof2BO[q-12],ADC_TOF2[q]);
			if (TDC_tof2BO[q-12] > TDC_min_TOF2 && TDC_tof2BO[q-12] < TDC_max_TOF2) h_ADC_TDC_tof2_peak[q]->Fill(TDC_tof2BO[q-12],ADC_TOF2[q]);
		}
	}

	for (int q=24; q<36; q++) {
		h_ADC_TDC_tof2[q]->Fill(TDC_tof2AI[q-24],ADC_TOF2[q]);
		if (TDC_tof2AI[q-24] > TDC_min_TOF2 && TDC_tof2AI[q-24] < TDC_max_TOF2) h_ADC_TDC_tof2_peak[q]->Fill(TDC_tof2AI[q-24],ADC_TOF2[q]);
	}

	for (int q=36; q<48; q++) {
		h_ADC_TDC_tof2[q]->Fill(TDC_tof2BI[q-36],ADC_TOF2[q]);
		if (TDC_tof2BI[q-36] > TDC_min_TOF2 && TDC_tof2BI[q-36] < TDC_max_TOF2) h_ADC_TDC_tof2_peak[q]->Fill(TDC_tof2BI[q-36],ADC_TOF2[q]);
	}		
}

//// Draw TOF1 Histograms

char Name_Can_ADC_tof1B[100];			char Title_Can_ADC_tof1B[100];

sprintf(Name_Can_ADC_tof1B,"TOF1 TDC Distributions -- Run %d  (Ch. 0 - 23) -- Mapping Sorted",run_number);
sprintf(Title_Can_ADC_tof1B,"TOF1 TDC Distributions -- Run %d  (Ch. 0 - 23) -- Mapping Sorted",run_number);

TCanvas *c7;
	c7 = new TCanvas(Name_Can_ADC_tof1B,Title_Can_ADC_tof1B,900,333); 
	c7->Divide(6,4);
	c7->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",0,0, "ProcEvent(Int_t,Int_t,Int_t,TObject*)");

	for(Int_t ican=0; ican<12; ican++){
		c7->cd(TOF1_Mapping1[ican]);
		h_ADC_TDC_tof1[ican]->SetAxisRange(TOF1_xmin, TOF1_xmax, "X");
		h_ADC_TDC_tof1[ican]->SetAxisRange(TOF1_ymin, TOF1_ymax, "Y");
		//h_ADC_TDC_tof1_peak[ican]->SetMarkerColor(3);
		//h_ADC_TDC_tof1_peak[ican]->SetMarkerSize(50);
		//h_ADC_TDC_tof1_peak[ican]->Draw();
		h_ADC_TDC_tof1[ican]->Draw("colz");
	}

	for(Int_t ican=0; ican<12; ican++){
		c7->cd(TOF1_Mapping2[ican]);
		h_ADC_TDC_tof1[ican+12]->SetAxisRange(TOF1_xmin, TOF1_xmax, "X");
		h_ADC_TDC_tof1[ican+12]->SetAxisRange(TOF1_ymin, TOF1_ymax, "Y");
		//h_ADC_TDC_tof1_peak[ican+12]->SetMarkerColor(3);
		//h_ADC_TDC_tof1_peak[ican+12]->SetMarkerSize(50);
		//h_ADC_TDC_tof1_peak[ican+12]->Draw();
		h_ADC_TDC_tof1[ican+12]->Draw("colz");
	}

////Draw TOF2 Histograms

char Name_Can_ADC_tof2B[100];			char Title_Can_ADC_tof2B[100];

sprintf(Name_Can_ADC_tof2B,"TOF2 TDC Distributions -- Run %d  (Ch. 0 - 47) -- Mapping Sorted",run_number);
sprintf(Title_Can_ADC_tof2B,"TOF2 TDC Distributions -- Run %d  (Ch. 0 - 47) -- Mapping Sorted",run_number);

TCanvas *c8;
	c8 = new TCanvas(Name_Can_ADC_tof2B,Title_Can_ADC_tof2B,1200,500); 
	c8->Divide(8,6);
	c8->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",0,0, "ProcEvent(Int_t,Int_t,Int_t,TObject*)");

	for(Int_t ican=0; ican<12; ican++){
		c8->cd(TOF2_Mapping1[ican]);
		h_ADC_TDC_tof2[ican]->SetAxisRange(TOF2_xmin, TOF2_xmax, "X");
		h_ADC_TDC_tof2[ican]->SetAxisRange(TOF2_ymin, TOF2_ymax, "Y");
		//h_ADC_TDC_tof2_peak[ican]->SetMarkerColor(3);
		//h_ADC_TDC_tof2_peak[ican]->SetMarkerSize(50);
		//h_ADC_TDC_tof2_peak[ican]->Draw();
		h_ADC_TDC_tof2[ican]->Draw("colz");
	}

	for(Int_t ican=0; ican<12; ican++){
		c8->cd(TOF2_Mapping2[ican]);
		h_ADC_TDC_tof2[ican+24]->SetAxisRange(TOF2_xmin, TOF2_xmax, "X");
		h_ADC_TDC_tof2[ican+24]->SetAxisRange(TOF2_ymin, TOF2_ymax, "Y");
		//h_ADC_TDC_tof2_peak[ican+24]->SetMarkerColor(3);
		//h_ADC_TDC_tof2_peak[ican+24]->SetMarkerSize(50);
		//h_ADC_TDC_tof2_peak[ican+24]->Draw();
		h_ADC_TDC_tof2[ican+24]->Draw("colz");
	}
	
	for(Int_t ican=0; ican<12; ican++){
		c8->cd(TOF2_Mapping3[ican]);
		h_ADC_TDC_tof2[ican+12]->SetAxisRange(TOF2_xmin, TOF2_xmax, "X");
		h_ADC_TDC_tof2[ican+12]->SetAxisRange(TOF2_ymin, TOF2_ymax, "Y");
		//h_ADC_TDC_tof2_peak[ican+12]->SetMarkerColor(3);
		//h_ADC_TDC_tof2_peak[ican+12]->SetMarkerSize(50);
		//h_ADC_TDC_tof2_peak[ican+12]->Draw();
		h_ADC_TDC_tof2[ican+12]->Draw("colz");
	}

	for(Int_t ican=0; ican<12; ican++){
		c8->cd(TOF2_Mapping4[ican]);
		h_ADC_TDC_tof2[ican+36]->SetAxisRange(TOF2_xmin, TOF2_xmax, "X");
		h_ADC_TDC_tof2[ican+36]->SetAxisRange(TOF2_ymin, TOF2_ymax, "Y");
		//h_ADC_TDC_tof2_peak[ican+36]->SetMarkerColor(3);
		//h_ADC_TDC_tof2_peak[ican+36]->SetMarkerSize(50);
		//h_ADC_TDC_tof2_peak[ican+36]->Draw();
		h_ADC_TDC_tof2[ican+36]->Draw("colz");
	}

}
Пример #4
0
void TOF_TOF_2D(Int_t run_number=5, Int_t flag=0, Int_t QUIET=0) { 

gStyle->SetOptStat(1111111);

Int_t TDC_min_TOF1 = 0;
Int_t TDC_max_TOF1 = 4000;
Int_t TDC_min_TOF2 = 0;
Int_t TDC_max_TOF2 = 4000;

///Adjust chart ranges

Int_t TOF1_xmin = 0;
Int_t TOF1_xmax = 400;
Int_t TOF1_ymin = 0;
Int_t TOF1_ymax = 400;

Int_t TOF2_xmin = 0;
Int_t TOF2_xmax = 400;
Int_t TOF2_ymin = 0;
Int_t TOF2_ymax = 400;

char* source_mapping="SFT_Mapping_Oct14.txt";

Int_t adc_high_target[256]; 	
Int_t adc_low_target[256]; 		
Int_t tdc_le_target[256][16];      	  	
Int_t tdc_te_target[256][16]; 		

Int_t ADC_High_sft[128];
Int_t ADC_Low_sft[128];
Int_t TDC_LE_sft[128][16];
Int_t TDC_TE_sft[128][16];

Int_t ADC_tof1[24];
Int_t ADC_tof2[56];

Int_t ADC_TOF1[24];
Int_t ADC_TOF2[56];

Int_t TDC_tof1U[12];
Int_t TDC_tof1D[12];

Int_t TDC_tof2AO[12];
Int_t TDC_tof2BO[12];
Int_t TDC_tof2AI[12];
Int_t TDC_tof2BI[12];

Int_t MwpcADC[512];

//Int_t TOF1_Mapping1[12] = {1,3,5,7,9,11,13,15,17,19,21,23};
//Int_t TOF1_Mapping2[12] = {2,4,6,8,10,12,14,16,18,20,22,24};

//Int_t TOF2_Mapping1[12] = {1,5,9,13,17,21,25,29,33,37,41,45};
//Int_t TOF2_Mapping2[12] = {2,6,10,14,18,22,26,30,34,38,42,46};
// TOF2_Mapping3[12] = {3,7,11,15,19,23,27,31,35,39,43,47};
//Int_t TOF2_Mapping4[12] = {4,8,12,16,20,24,28,32,36,40,44,48};	

char path_input[200];                   char file_mapping[200];
sprintf(path_input,path_merged);          sprintf(file_mapping,"../Mapping");
//sprintf(path_input,"/triumfcs/trshare/trek/E36/Data/April_2015/root");

char Name_finput[200];
sprintf(Name_finput,"%s/Run%dMS.root",path_input, run_number);

////

char par_finput[200];
//sprintf(par_finput,"/triumfcs/trshare/trek/E36/Macros/April_2015/Mapping/%s",source_mapping);
sprintf(par_finput,"%s/%s",file_mapping,source_mapping);

char par_finput2[200];
//sprintf(par_finput,"/triumfcs/trshare/trek/E36/Macros/April_2015/Mapping/%s",source_mapping);
sprintf(par_finput2,"%s/MWPC_map.txt",file_mapping);

char par_finput3[200];
//sprintf(par_finput,"/triumfcs/trshare/trek/E36/Macros/April_2015/Mapping/%s",source_mapping);
sprintf(par_finput3,"%s/ADC_TARGET_Thresholds.txt",file_mapping);

char par_finput4[200];
//sprintf(par_finput,"/triumfcs/trshare/trek/E36/Macros/April_2015/Mapping/%s",source_mapping);
sprintf(par_finput4,"%s/ADC_SFT_Thresholds.txt",file_mapping);

char par_finput5[200];
//sprintf(par_finput,"/triumfcs/trshare/trek/E36/Macros/April_2015/Mapping/%s",source_mapping);
sprintf(par_finput5,"%s/ADC_TOF1_Thresholds.txt",file_mapping);

char par_finput6[200];
//sprintf(par_finput,"/triumfcs/trshare/trek/E36/Macros/April_2015/Mapping/%s",source_mapping);
sprintf(par_finput6,"%s/ADC_TOF2_Thresholds.txt",file_mapping);

char par_finput7[200];
//sprintf(par_finput,"/triumfcs/trshare/trek/E36/Macros/April_2015/Mapping/%s",source_mapping);
sprintf(par_finput7,"%s/TDC_TOF1_Shifts.txt",file_mapping);

char par_finput8[200];
//sprintf(par_finput,"/triumfcs/trshare/trek/E36/Macros/April_2015/Mapping/%s",source_mapping);
sprintf(par_finput8,"%s/TDC_TOF2_Shifts.txt",file_mapping);

////

Int_t par_temp[2][128];
ifstream fdat(par_finput,ios::in);
for(Int_t ii=0; ii<128; ii++) fdat >> par_temp[0][ii] >> par_temp[1][ii];
fdat.close();

char par_temp2[512][50];
//char par_temp3[512][50];
ifstream fdat2(par_finput2,ios::in);
for(Int_t ii=0; ii<512; ii++) fdat2 >> par_temp2[ii];
fdat2.close();

Int_t par_temp_TARGET[2][256];
ifstream fdat3(par_finput3,ios::in);
for(Int_t ii=0; ii<256; ii++) fdat3 >> par_temp_TARGET[0][ii] >> par_temp_TARGET[1][ii];
fdat3.close();

Int_t par_temp_SFT[2][128];
ifstream fdat4(par_finput4,ios::in);
for(Int_t ii=0; ii<128; ii++) fdat4 >> par_temp_SFT[0][ii] >> par_temp_SFT[1][ii];
fdat4.close();

Int_t par_temp_TOF1[2][24];
ifstream fdat5(par_finput5,ios::in);
for(Int_t ii=0; ii<24; ii++) fdat5 >> par_temp_TOF1[0][ii] >> par_temp_TOF1[1][ii];
fdat5.close();

Int_t par_temp_TOF2[2][56];
ifstream fdat6(par_finput6,ios::in);
for(Int_t ii=0; ii<56; ii++) fdat6 >> par_temp_TOF2[0][ii] >> par_temp_TOF2[1][ii];
fdat6.close();

Int_t par_temp_TDC_TOF1[2][24];
ifstream fdat7(par_finput7,ios::in);
for(Int_t ii=0; ii<24; ii++) fdat7 >> par_temp_TDC_TOF1[0][ii] >> par_temp_TDC_TOF1[1][ii];
fdat7.close();

Int_t par_temp_TDC_TOF2[2][48];
ifstream fdat8(par_finput8,ios::in);
for(Int_t ii=0; ii<48; ii++) fdat8 >> par_temp_TDC_TOF2[0][ii] >> par_temp_TDC_TOF2[1][ii];
fdat8.close();

//char footer[100];
//sprintf(footer,"Event_Display_MS.C  --  Run %d ; Event %d",Run_Number,ievt);


TChain *fChain= new TChain("Tree");		
fChain->Add(Name_finput);		
fChain->SetMakeClass(1);							

fChain->SetBranchAddress("ADC_High_TARGET",adc_high_target);		
fChain->SetBranchAddress("ADC_Low_TARGET",adc_low_target);
fChain->SetBranchAddress("TDC_LE_TARGET",tdc_le_target);		
fChain->SetBranchAddress("TDC_TE_TARGET",tdc_te_target);

fChain->SetBranchAddress("ADC_High_SFT",ADC_High_sft);
fChain->SetBranchAddress("ADC_Low_SFT",ADC_Low_sft);
fChain->SetBranchAddress("TDC_LE_SFT",TDC_LE_sft);
fChain->SetBranchAddress("TDC_TE_SFT",TDC_TE_sft);

fChain->SetBranchAddress("ADC_TOF1",ADC_tof1);
fChain->SetBranchAddress("ADC_TOF2",ADC_tof2);
fChain->SetBranchAddress("MWPCADC",MwpcADC);

fChain->SetBranchAddress("TDC_TOF1U",TDC_tof1U);
fChain->SetBranchAddress("TDC_TOF1D",TDC_tof1D);
fChain->SetBranchAddress("TDC_TOF2AO",TDC_tof2AO);
fChain->SetBranchAddress("TDC_TOF2AI",TDC_tof2AI);
fChain->SetBranchAddress("TDC_TOF2BO",TDC_tof2BO);
fChain->SetBranchAddress("TDC_TOF2BI",TDC_tof2BI);			

TH2D *h_ADC_TDC_tof1[12];   char Title_ADC_TDC_tof1[12][100];	char Name_ADC_TDC_tof1[12][100];
//TH2D *h_ADC_TDC_tof1_peak[12];   char Title_ADC_TDC_tof1_peak[12][100];	char Name_ADC_TDC_tof1_peak[12][100];

TH2D *h_ADC_TDC_tof2[24];   char Title_ADC_TDC_tof2[24][100];	char Name_ADC_TDC_tof2[24][100];
//TH2D *h_ADC_TDC_tof2_peak[24];   char Title_ADC_TDC_tof2_peak[24][100];	char Name_ADC_TDC_tof2_peak[24][100];

for (int i=0; i<12; i++) {
	sprintf(Title_ADC_TDC_tof1[i],"TDC Down vs. TDC Up (Gap %d)  --  TOF1 | Run %d",i+1, run_number);
//	sprintf(Name_ADC_TDC_tof1[i],"TDC Down vs. TDC Up  (Gap %d) - TOF1",i+1);
	sprintf(Name_ADC_TDC_tof1[i],"TOF1 -- Gap %d  (Run %d)",i+1, run_number);
//	sprintf(Title_ADC_TDC_tof1_peak[i],"ADC vs. TDC (Ch. %d)  --  TOF1 Peak",i);
//	sprintf(Name_ADC_TDC_tof1_peak[i],"ADC vs. TDC (Ch. %d) - TOF1 Peak",i);
}

for (int i=0; i<24; i++) {
	if (i<12) {
		sprintf(Title_ADC_TDC_tof2[i],"TDC Out vs. TDC In  (Gap %dA)  --  TOF2 | Run %d",i+1, run_number);
		sprintf(Name_ADC_TDC_tof2[i],"TOF2 -- Gap %dA  (Run %d)",i+1, run_number);
	}
	else {
		sprintf(Title_ADC_TDC_tof2[i],"TDC Out vs. TDC In (Gap %dB)  --  TOF2 | Run %d",i-11, run_number);
		sprintf(Name_ADC_TDC_tof2[i],"TOF2 -- Gap %dB  (Run %d)",i-11, run_number);
	}
//	sprintf(Title_ADC_TDC_tof2_peak[i],"ADC vs. TDC (Ch. %d)  --  TOF2 Peak",i);
//	sprintf(Name_ADC_TDC_tof2_peak[i],"ADC vs. TDC (Ch. %d) - TOF2 Peak",i);
}


for (int  i=0; i<12; i++) {
h_ADC_TDC_tof1[i] = new TH2D(Name_ADC_TDC_tof1[i],Title_ADC_TDC_tof1[i],1000,0,4000,1000,0,4000);
//h_ADC_TDC_tof1_peak[i] = new TH2D(Name_ADC_TDC_tof1_peak[i],Title_ADC_TDC_tof1_peak[i],1000,0,4000,1000,0,4000);
}

for (int  i=0; i<24; i++) {
h_ADC_TDC_tof2[i] = new TH2D(Name_ADC_TDC_tof2[i],Title_ADC_TDC_tof2[i],1000,0,4000,1000,0,4000);
//h_ADC_TDC_tof2_peak[i] = new TH2D(Name_ADC_TDC_tof2_peak[i],Title_ADC_TDC_tof2_peak[i],1000,0,4000,1000,0,4000);
}


cout << "   " << endl;
cout << "File opened: " << Name_finput << endl;
cout << "  "  << endl;

/// TOF1 Print outs !
cout << "   " << endl;
for(int kk = 0; kk < 9; kk++){
	cout << "TOF1 Gap " << kk+1 << ":    " << "UP = " << par_temp_TDC_TOF1[1][kk] << "       "  << "DOWN = "<< par_temp_TDC_TOF1[1][kk+12] << endl;
}
for(int kkk = 9; kkk < 12; kkk++){
	cout << "TOF1 Gap " << kkk+1 << ":   " << "UP = " << par_temp_TDC_TOF1[1][kkk] << "       "  << "DOWN = "<< par_temp_TDC_TOF1[1][kkk+12] << endl;
}
cout << "   " << endl;

/// TOF2 Print outs !
cout << "   " << endl;
for(int jj = 0; jj < 9; jj++){
	cout << "TOF2 Gap " << jj+1 << ":    " << "A_OUT = " <<  par_temp_TDC_TOF2[1][jj] << "        " << "B_OUT = " << par_temp_TDC_TOF2[1][jj+12] << "      " << "A_IN = " << par_temp_TDC_TOF2[1][jj+24] << "       " << "B_IN = " << par_temp_TDC_TOF2[1][jj+36] << endl;
}
for(int jj = 9; jj < 12; jj++){
	cout << "TOF2 Gap " << jj+1 << ":   " << "A_OUT = " <<  par_temp_TDC_TOF2[1][jj] << "        " << "B_OUT = " << par_temp_TDC_TOF2[1][jj+12] << "      " << "A_IN = " << par_temp_TDC_TOF2[1][jj+24] << "       " << "B_IN = " << par_temp_TDC_TOF2[1][jj+36] << endl;
}

cout << "  " << endl;
cout << "  " << endl; 
//read all entries and fill the histograms
Int_t nentries = (Int_t)fChain->GetEntries();
cout <<  "Total Number of Entries :     " <<  nentries << endl;
cout << "  " << endl;

if(flag!=0) nentries=flag;

for (Int_t i=0; i<nentries; i++) {
//fChain_TOF1->GetEntry(i);
fChain->GetEntry(i);

	for (Int_t j_TOF1=0; j_TOF1<24; j_TOF1++) {
	   ADC_TOF1[j_TOF1] = ADC_tof1[j_TOF1]-par_temp_TOF1[1][j_TOF1];
	}

	for (Int_t j_TDCTOF=0; j_TDCTOF<12; j_TDCTOF++) {
	   TDC_tof1U[j_TDCTOF] = TDC_tof1U[j_TDCTOF] - par_temp_TDC_TOF1[1][j_TDCTOF];
	   TDC_tof1D[j_TDCTOF] = TDC_tof1D[j_TDCTOF] - par_temp_TDC_TOF1[1][j_TDCTOF+12];;
	}

	if(QUIET==0){
		if(nentries<=30000){
			if(i%1000==1) cout<<"**** "<<i<<" events done"<<endl;
		}
		if(nentries>30000){
			if(i%10000==1) cout<<"**** "<<i<<" events done"<<endl;
		}
	}

	for (int q=0; q<12; q++) {
		//if ((TDC_tof1U[q] > TDC_min_TOF1 && TDC_tof1U[q] < TDC_max_TOF1) && (TDC_tof1D[q] > TDC_min_TOF1 && TDC_tof1D[q] < TDC_max_TOF1))
			h_ADC_TDC_tof1[q]->Fill(TDC_tof1U[q],TDC_tof1D[q]);
	}

	for (Int_t j_TOF2=0; j_TOF2<56; j_TOF2++) {
   		ADC_TOF2[j_TOF2] = ADC_tof2[j_TOF2]-par_temp_TOF2[1][j_TOF2];
	}

	for (Int_t j_TDCTOF=0; j_TDCTOF<12; j_TDCTOF++) {
	    TDC_tof2AO[j_TDCTOF] = TDC_tof2AO[j_TDCTOF] - par_temp_TDC_TOF2[1][j_TDCTOF];
	    TDC_tof2BO[j_TDCTOF] = TDC_tof2BO[j_TDCTOF] - par_temp_TDC_TOF2[1][j_TDCTOF+12];
	    TDC_tof2AI[j_TDCTOF] = TDC_tof2AI[j_TDCTOF] - par_temp_TDC_TOF2[1][j_TDCTOF+24];
	    TDC_tof2BI[j_TDCTOF] = TDC_tof2BI[j_TDCTOF] - par_temp_TDC_TOF2[1][j_TDCTOF+36];
  	}

	for (int q=0; q<12; q++) {
		//if ((TDC_tof2AO[q] > TDC_min_TOF2 && TDC_tof2AO[q] < TDC_max_TOF2) && (TDC_tof2AI[q] > TDC_min_TOF2 && TDC_tof2AI[q] < TDC_max_TOF2)) 
			h_ADC_TDC_tof2[q]->Fill(TDC_tof2AI[q],TDC_tof2AO[q]);
	}

	for (int q=0; q<12; q++) {
	//	if ((TDC_tof2BI[q] > TDC_min_TOF2 && TDC_tof2BI[q] < TDC_max_TOF2) && (TDC_tof2BO[q] > TDC_min_TOF2 && TDC_tof2BO[q] < TDC_max_TOF2)) 
			h_ADC_TDC_tof2[q+12]->Fill(TDC_tof2BI[q],TDC_tof2BO[q]);
	}		

}


////Draw TOF1 Histograms

char Name_Can_ADC_tof1B[100];			char Title_Can_ADC_tof1B[100];

sprintf(Name_Can_ADC_tof1B,"TOF1 TDC Up vs. Down -- Run %d  (Ch. 0 - 23) -- Mapping Sorted",run_number);
sprintf(Title_Can_ADC_tof1B,"TOF1 TDC Up vs. Down -- Run %d  (Ch. 0 - 23) -- Mapping Sorted",run_number);

TCanvas *c7;
	c7 = new TCanvas(Name_Can_ADC_tof1B,Title_Can_ADC_tof1B,1000,400); 
	c7->Divide(4,3);
	c7->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",0,0, "ProcEvent(Int_t,Int_t,Int_t,TObject*)");

	for(Int_t ican=0; ican<12; ican++){
		c7->cd(ican+1);
		h_ADC_TDC_tof1[ican]->SetAxisRange(TOF1_xmin, TOF1_xmax, "X");
		h_ADC_TDC_tof1[ican]->SetAxisRange(TOF1_ymin, TOF1_ymax, "Y");
		//h_ADC_TDC_tof1_peak[ican]->SetMarkerColor(3);
		//h_ADC_TDC_tof1_peak[ican]->SetMarkerSize(50);
		//h_ADC_TDC_tof1_peak[ican]->Draw();
		h_ADC_TDC_tof1[ican]->Draw("colz");
	}

////Draw TOF2 Histograms

char Name_Can_ADC_tof2B[100];			char Title_Can_ADC_tof2B[100];

sprintf(Name_Can_ADC_tof2B,"TOF2 TDC In vs. Out -- Run %d  (Ch. 0 - 47) -- Mapping Sorted",run_number);
sprintf(Title_Can_ADC_tof2B,"TOF2 TDC In vs. Out -- Run %d  (Ch. 0 - 47) -- Mapping Sorted",run_number);

TCanvas *c8;
	c8 = new TCanvas(Name_Can_ADC_tof2B,Title_Can_ADC_tof2B,1200,500); 
	c8->Divide(6,4);
	c8->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",0,0, "ProcEvent(Int_t,Int_t,Int_t,TObject*)");

	for(Int_t ican=0; ican<12; ican++){
		c8->cd(ican+1);
		h_ADC_TDC_tof2[ican]->SetAxisRange(TOF2_xmin, TOF2_xmax, "X");
		h_ADC_TDC_tof2[ican]->SetAxisRange(TOF2_ymin, TOF2_ymax, "Y");
		//h_ADC_TDC_tof2_peak[ican]->SetMarkerColor(3);
		//h_ADC_TDC_tof2_peak[ican]->SetMarkerSize(50);
		//h_ADC_TDC_tof2_peak[ican]->Draw();
		h_ADC_TDC_tof2[ican]->Draw("colz");
	}

	for(Int_t ican=12; ican<24; ican++){
		c8->cd(ican+1);
		h_ADC_TDC_tof2[ican]->SetAxisRange(TOF2_xmin, TOF2_xmax, "X");
		h_ADC_TDC_tof2[ican]->SetAxisRange(TOF2_ymin, TOF2_ymax, "Y");
		//h_ADC_TDC_tof2_peak[ican+24]->SetMarkerColor(3);
		//h_ADC_TDC_tof2_peak[ican+24]->SetMarkerSize(50);
		//h_ADC_TDC_tof2_peak[ican+24]->Draw();
		h_ADC_TDC_tof2[ican]->Draw("colz");
	}

}