/////////////////////////////////////////////////////////////////////////////// #include "cstdlib" #include "stdio.h" #include "time.h" #include "OfflineMon/TMemoryUse.hh" #include "OfflineMon/TDbStat.hh" #include "OfflineMon/TDbMon.hh" #include "OfflineMon/TModuleTime.hh" #include "OfflineMon/TTapeQueue.hh" #include "OfflineMon/TPhysMon.hh" #include "OfflineMon/TPbMon.hh" #include "OfflineMon/TProdSummary.hh" #include "OfflineMon/TFarmLosses.hh" #include "OfflineMon/TOfflineMon.hh" #include "Stntuple/oracle/TCdfOracle.hh" #include "Stntuple/obj/TStnRunSummary.hh" #include "TROOT.h" #include "TFile.h" #include "TTree.h" #include "TFolder.h" #include "TSystem.h" #include "TH1F.h" #include "TF1.h" TMemoryUse* gMem; TDbMon* gDbMon; TDbStat* gDbStat; TModuleTime* gModuleTime; TTapeQueue* gTapeQueue; TProdSummary* gProdSummary; TFarmLosses* gFarmLosses; ClassImp(TOfflineMon) double f_HadE(double* X, double* Par) { // straw-man parametrization of Hadron Callorimeter Energy distribution - function taken from // the real histogram double x[] = { 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3.0, 3.1, 3.2, 3.3, 3.4 }; double f[] = { 740.000, 760.000, 800.000, 860.000, 1220.000, 1600.000, 2100.000, 2500.000, 3200.000, 3600.000, 3900.000, 4100.000, 4000.000, 3700.000, 3200.000, 2700.000, 2200.000, 1800.000, 1500.000, 1250.000, 880.000, 690.000, 600.000, 550.000, 400.000, 300.000, 280.000, 260.000, 240.000, 200.000 }; // 2 parameters: Par[0] : overall scale, Par[1]: offset in X // Assumes the same binning! double ftouse = 0; double bin = 0.1; double xx = X[0]+Par[1]; double const dWeight = 4.50608509520177904e+03; // Calculate f( xx) called ftouse for (int i=0; i<30; i++) { if ( (x[i] <= xx) && (x[i+1] >= xx)) { ftouse = f[i]+(xx-x[i])/bin*(f[i+1]-f[i]); break; } } return Par[0] * ftouse / dWeight; } //_____________________________________________________________________________ double f_EmE(double* X, double* Par) { // straw-man parametrization of Hadron Callorimeter Energy distribution - function taken from // the real histogram double x[] = { 0.1, 0.12, 0.14, 0.16, 0.18, 0.2, 0.22, 0.24, 0.26, 0.28, 0.3, 0.32, 0.34, 0.36, 0.38, 0.4, 0.42, 0.44, 0.46, 0.48, 0.5, 0.52, 0.54, 0.56, 0.58, 0.6 }; double f[] = { 500.000, 680.000, 950.000, 1200.000, 1780.000, 2730.000, 4000.000, 5140.000, 5960.000, 5880.000, 5590.000, 4590.000, 4240.000, 3500.000, 2740.000, 2000.000, 1750.000, 1410.000, 1270.000, 1190.000, 1000.000, 1000.000, 930.000, 880.000, 770.000, 620.000 }; // 2 parameters: Par[0] : overall scale, Par[1]: offset in X // Assumes the same binning! double ftouse = 0; double bin = 0.02; double xx = X[0]+Par[1]; double const dWeight = 1.22231088516361524e+03; // Calculate f( xx) called ftouse for (int i = 0; i < 26; i++) { if ( ( x[i] <= xx) && ( x[i + 1] >= xx)) { ftouse = f[i] +( xx - x[i]) / bin * ( f[i + 1] - f[i]); break; } } return Par[0] * ftouse / dWeight; } //_____________________________________________________________________________ int truncated_mean(TH1F* Hist, float X0, float Road, int NIter, float& XMean, float& SigX) { double x, nev, sumx, sumx2, sumn, sigx, xmean, xm, road; int nbins = Hist->GetNbinsX(); road = Road; xmean = X0; for (int it=0; itGetBinCenter(i); if (TMath::Abs(x-xmean) < road) { nev = Hist->GetBinContent(i); sumn += nev; sumx += x*nev; sumx2 += x*x*nev; } } if (sumn > 0) { xm = sumx/sumn; sigx = TMath::Sqrt((sumx2/sumn-xm*xm)/sumn); } else { xm = 0; sigx = 0; } //----------------------------------------------------------------------------- //end of iteration //----------------------------------------------------------------------------- // road = Road+TMath::Abs(xmean-xm); xmean = xm; printf(" it, xmean, sigx = %3i %10.4f %10.4f\n",it,xmean,sigx); } XMean = xmean; SigX = sigx; return 0; } //_____________________________________________________________________________ TOfflineMon::TOfflineMon() { fCdfofprd = new TCdfOracle("cdfofprd"); fPhysMon = new TPhysMon; fPbMon = new TPbMon; } //_____________________________________________________________________________ TOfflineMon::~TOfflineMon() { delete fCdfofprd; } //_____________________________________________________________________________ int TOfflineMon::CreateMemUseNtuple(const char* InputFile, const char* NtupleFile) { TFile* ntuple_file = new TFile(NtupleFile,"recreate"); TTree* tree = new TTree("memuse","memory use"); TBranch* br = tree->Branch("MemoryUse","TMemoryUse", &gMem); gMem = new TMemoryUse(); //----------------------------------------------------------------------------- // read the data file and fill the ntuple //----------------------------------------------------------------------------- FILE* f = fopen(InputFile,"r"); char c[200]; int id1, id2; int n = 200; while (fgets(c,n,f) > 0) { sscanf(c,"%i %i %i %i %i %i %f",&gMem->fNode,&id1, &id2,&gMem->fRun,&gMem->fEvent, &gMem->fNumber,&gMem->fVSize); if ((gMem->fVSize < 0) || (gMem->fVSize > 1500)) { // something is wrong printf("WRONG DATA : %s\n",c); } gMem->fId = id1*100+id2; gMem->fRss = 0.; gMem->fMethod = ""; // printf("%i \n",gMem->fRun); tree->Fill(); } ntuple_file->Write(); delete ntuple_file; return 0; } //_____________________________________________________________________________ int TOfflineMon::CreateDbStatNtuple(const char* InputFile, const char* NtupleFile) { TFile* ntuple_file = new TFile(NtupleFile,"recreate"); TTree* tree = new TTree("dbstat","DB access statistics"); TBranch* br = tree->Branch("DbStat","TDbStat", &gDbStat); gDbStat = new TDbStat(); //----------------------------------------------------------------------------- // read the data file and fill the ntuple //----------------------------------------------------------------------------- FILE* f = fopen(InputFile,"r"); char c[200]; int id1, id2; char table[100]; int n = 200; while (fgets(c,n,f) > 0) { sscanf(c,"%i%i%i%i%i%i%i%i%i%f%f%i%s", &id1, &id2, &gDbStat->fKeyedGets,&gDbStat->fDefaultGets, &gDbStat->fNotif, &gDbStat->fKeyedPuts,&gDbStat->fNoKeyedPuts, &gDbStat->fCacheHits,&gDbStat->fCacheMisses, &gDbStat->fTimePuts ,&gDbStat->fTimeGets, &gDbStat->fTableNumber, table); gDbStat->fId = id1*100+id2; gDbStat->fTable = table; // printf("%f %f \n",gDbStat->fTimePuts,gDbStat->fTimeGets); tree->Fill(); } ntuple_file->Write(); delete ntuple_file; return 0; } //_____________________________________________________________________________ int TOfflineMon::CreateModuleTimeNtuple(const char* InputFile, const char* NtupleFile) { TFile* ntuple_file = new TFile(NtupleFile,"recreate"); TTree* tree = new TTree("module_time","Timing for AC++ modules"); TBranch* br = tree->Branch("ModuleTime","TModuleTime", &gModuleTime); gModuleTime = new TModuleTime(); //----------------------------------------------------------------------------- // read the data file and fill the ntuple //----------------------------------------------------------------------------- FILE* f = fopen(InputFile,"r"); char c[200]; char module_name[100]; float cpu_time, sigma; int n = 200; while (fgets(c,n,f) > 0) { sscanf(c,"%x %x %s %i %f+/-%f %f+/-%f %f", &gModuleTime->fRunNumber, &gModuleTime->fRunSection, module_name, &gModuleTime->fNEvents, &gModuleTime->fCPUTimePerEvent, &gModuleTime->fSigma, &cpu_time, &sigma, &gModuleTime->fTotalTime ); gModuleTime->fModuleName = module_name; // printf("%f %f \n",gDbStat->fTimePuts,gDbStat->fTimeGets); tree->Fill(); } ntuple_file->Write(); delete ntuple_file; return 0; } //_____________________________________________________________________________ int TOfflineMon::CreateTapeQueueNtuple(const char* InputFile, const char* NtupleFile) { TFile* ntuple_file = new TFile(NtupleFile,"recreate"); TTree* tree = new TTree("tape_queue","FCDFSGI2 Tape Queue Monitor"); TBranch* br = tree->Branch("TapeQueue","TTapeQueue", &gTapeQueue); gTapeQueue = new TTapeQueue(); //----------------------------------------------------------------------------- // read the data file and fill the ntuple //----------------------------------------------------------------------------- FILE* f = fopen(InputFile,"r"); char c[200], cdate[50]; // char day_of_the_week[20], month[20]; // char zone[10]; char month1[20]; int day1, hour1, min1; int n = 200; time_t now; tm* x; while (fgets(c,n,f) > 0) { if (c[0] != '#') { memset(cdate,0,50); sscanf(c,"%i %28c %i %s %i %i:%i", &now, cdate, &gTapeQueue->fNJobs, month1, &day1, &hour1,&min1); x = localtime(&now); gTapeQueue->fCalendarTime = (Int_t) now; gTapeQueue->fYear = x->tm_year; gTapeQueue->fMonth = x->tm_mon; gTapeQueue->fDay = x->tm_mday; gTapeQueue->fHours = x->tm_hour; gTapeQueue->fMinutes = x->tm_min; gTapeQueue->fSeconds = x->tm_sec; // printf("%f %f \n",gDbStat->fTimePuts,gDbStat->fTimeGets); tree->Fill(); } } ntuple_file->Write(); delete ntuple_file; return 0; } //_____________________________________________________________________________ int TOfflineMon::CreateFarmLossesNtuple(const char* InputFile, const char* NtupleFile) { TFile* ntuple_file = new TFile(NtupleFile,"recreate"); TTree* tree = new TTree("farm_losses","Farm Losses"); TBranch* br = tree->Branch("FarmLosses","TFarmLosses", &gFarmLosses); gFarmLosses = new TFarmLosses(); //----------------------------------------------------------------------------- // read the data file and fill the ntuple //----------------------------------------------------------------------------- FILE* f = fopen(InputFile,"r"); char c[200], buf1[50], buf2[50], buf3[50], name[20][50]; int nmax = 200; //----------------------------------------------------------------------------- // first line: names of the streams, first - input, the rest output //----------------------------------------------------------------------------- fgets(c,nmax,f); char* p; int i(0), n_streams, n_output_streams; p = strtok(c," "); while (p) { strcpy(name[i++],p); p = strtok(0," "); }; n_streams = i; n_output_streams = i-1; while (fgets(c,nmax,f) > 0) { if (c[0] != '#') { p = strtok(c," "); gFarmLosses->fRunNumber = atoi(p); for (int i=0; ifRs1[i] = atoi(p); p = strtok(0," "); gFarmLosses->fRs2[i] = atoi(p); p = strtok(0," "); gFarmLosses->fNMisses[i] = atoi(p); p = strtok(0," "); gFarmLosses->fNMissingRs[i] = atoi(p); } for (int i=0; ifStream[i] = name[i]; tree->Fill(); } } ntuple_file->Write(); delete ntuple_file; return 0; } //_____________________________________________________________________________ int TOfflineMon::CreateDbMonNtuple(const char* InputFile, const char* NtupleFile) { TFile* ntuple_file = new TFile(NtupleFile,"recreate"); TTree* tree = new TTree("db_monitor","DB Monitor"); TBranch* br = tree->Branch("DbMon","TDbMon", &gDbMon); gDbMon = new TDbMon(); //----------------------------------------------------------------------------- // read the data file and fill the ntuple //----------------------------------------------------------------------------- FILE* f = fopen(InputFile,"r"); char c[200], buf1[50], buf2[50], buf3[50]; int n = 200; while (fgets(c,n,f) > 0) { if (c[0] != '#') { sscanf(c,"%s %i %s %s %i %i", buf1, &gDbMon->fCalendarTime, buf2, buf3, &gDbMon->fNConnections[0], &gDbMon->fNConnections[1] ); printf("%s %i %s %s %i %i\n",buf1, gDbMon->fCalendarTime,buf2,buf3, gDbMon->fNConnections[0], gDbMon->fNConnections[1] ); tree->Fill(); } } ntuple_file->Write(); delete ntuple_file; return 0; } //_____________________________________________________________________________ int TOfflineMon::CreateProdSummaryNtuple(const char* InputFile, const char* NtupleFile) { TFile* ntuple_file = new TFile(NtupleFile,"recreate"); TTree* tree = new TTree("prod_summary","Production Summary"); TBranch* br = tree->Branch("ProdSummary","TProdSummary", &gProdSummary); gProdSummary = new TProdSummary(); //----------------------------------------------------------------------------- // read the data file and fill the ntuple //----------------------------------------------------------------------------- FILE* f = fopen(InputFile,"r"); char c[200], buf1[200]; int n = 200; while (fgets(c,n,f) > 0) { if (c[0] != '#') { sscanf(c,"%s %i %f %f %i", buf1, &gProdSummary->fNInput, &gProdSummary->fCpuTime, &gProdSummary->fClkTime, &gProdSummary->fNOutputFiles ); for (int i=0; ifNOutputFiles; i++) { sscanf(&c[45],"%i %i",&gProdSummary->fNOutputEvents[i],&gProdSummary->fEventSize[i]); } gProdSummary->fInputFn = buf1; tree->Fill(); } } ntuple_file->Write(); delete ntuple_file; delete gProdSummary; return 0; } //_____________________________________________________________________________ int fit_njpsi(TH1F* Hist, float& NJPsi, float& M, float& MFitErr, float& SigM) { TF1 *func = new TF1("func","gaus(0)+pol0(3)",2.9,3.3); // Set initial values and parameter names based on the histogram contents TAxis* ax = Hist->GetXaxis(); double xmin, xmax, bin, bin1,bin2; xmin = ax->GetXmin(); xmax = ax->GetXmax(); bin = Hist->GetBinWidth(1); bin1 = (3.04-xmin)/bin + 1; bin2 = (3.15-xmin)/bin + 1; //----------------------------------------------------------------------------- // assume sigma = 15 MeV .. //----------------------------------------------------------------------------- double m0 = 3.090; double sig0 = 0.015; double a0 = Hist->Integral(bin1,bin2)*bin/(sqrt(2.*TMath::Pi())*0.015); func->SetParameters(a0,m0,sig0,0); func->SetParNames("Constant","Mean_value","Sigma","Constant"); func->SetParLimits(0,0,1000000); func->SetParLimits(1,3.05,3.15); func->SetParLimits(2,0.011,0.03); func->SetParLimits(3,0,1000000); // Fit histogram Hist->Fit("func","r"); double lowlim = func->GetParameter(1)-3*func->GetParameter(2); double higlim = func->GetParameter(1)+3*func->GetParameter(2); // integral of function between fit limits double binwid = Hist->GetBinWidth(1); double totint = (func->Integral(lowlim,higlim))/binwid; // flat function to integrate background TF1 *f_flat =new TF1("f_flat","pol0",2.9,3.3); double mypar = func->GetParameter(3); f_flat->SetParameters(&mypar); double backint = (f_flat->Integral(lowlim,higlim))/binwid; double sigint = totint - backint; printf("Total Integral (%g to %g): %g\n",lowlim,higlim,totint); printf("Bkg Integral: %g\n",backint); printf("Signal Integral (# Jpsis):s %g\n",sigint); NJPsi = sigint; M = func->GetParameter(1); MFitErr = func->GetParError (1); SigM = func->GetParameter(2); func->Delete(); f_flat->Delete(); return 0; } //_____________________________________________________________________________ int TOfflineMon::CreatePhysMonNtuple(const char* InputDir, const char* NtupleFile) { TFile* ntuple_file = new TFile(NtupleFile,"recreate"); TTree* tree = new TTree("physmon","Physics Monitor"); TBranch* br = tree->Branch("PhysMon","TPhysMon", &fPhysMon); //----------------------------------------------------------------------------- // read the data files and fill the ntuple //----------------------------------------------------------------------------- char cmd[200]; TStnRunSummary rs; sprintf(cmd,"rm .tmp; ls %s/stra_mon_hist.* > .tmp",InputDir); gSystem->Exec(cmd); FILE* f = fopen(".tmp","r"); char fn[200]; TFile* hfile; TH1F* hist; TF1 *ff, *fep; TF1* fHadE = new TF1( "fit1", f_HadE, 0.6, 2.5, 2);; TF1* hEmE = new TF1( "fit2", f_EmE, 0.12, 0.6, 2); TFolder* fol; // double xmean, sigx; fep = fPhysMon->GetFuncEp(); fep->SetParameters(1,0.0,100.); double fint; fint = 3583.9380; // fint = fep->Integral(0.85,1.9); while (fgets(fn,200,f) > 0) { int len = strlen(fn); fn[len-1] = 0; int run_number = atoi(&fn[len-7]); printf(".%s. %i\n",fn,run_number); fPhysMon->fRunNumber = run_number; fPhysMon->Clear(); //----------------------------------------------------------------------------- // open ROOT histogram file and get the histograms we need //----------------------------------------------------------------------------- hfile = TFile::Open(fn); fol = (TFolder*) hfile->Get("Ana"); //----------------------------------------------------------------------------- // WenuMon histograms // 1. Missing Et //----------------------------------------------------------------------------- hist = (TH1F*) fol->FindObject("WenuMon/Hist/met0_0"); fPhysMon->fNWenu = hist->GetEntries(); //----------------------------------------------------------------------------- // 2. E/P for isolated high-Pt electrons (but not necessarily W-electrons, // no MET cut yet), no normalization to chi2 yet ... //----------------------------------------------------------------------------- double n0; hist = (TH1F*) fol->FindObject("WenuMon/Hist/ele_1/ep"); if (hist) { n0 = hist->GetEntries()/fint; fep->SetParameters(n0,0.01,n0/10.,0.8); hist->Fit(fep->GetName(),"r"); fPhysMon->fEOverP = 1 + fep->GetParameter(1); fPhysMon->fSigEOverP = fep->GetParError(1); //truncated_mean(hist,1.0,0.2,3,fPhysMon->fEOverP,fPhysMon->fSigEOverP); } hist = (TH1F*) fol->FindObject("WenuMon/Hist/ele_1/ep_pos"); if (hist) { n0 = hist->GetEntries()/fint; fep->SetParameters(n0,0.01,n0/10.,0.8); hist->Fit(fep->GetName(),"r"); fPhysMon->fEPPos = 1 + fep->GetParameter(1); fPhysMon->fSigEPPos = fep->GetParError(1); // truncated_mean(hist,1.0,0.2,3,fPhysMon->fEPPos,fPhysMon->fSigEPPos); } hist = (TH1F*) fol->FindObject("WenuMon/Hist/ele_1/ep_neg"); if (hist) { n0 = hist->GetEntries()/fint; fep->SetParameters(n0,0.01,n0/10.,0.8); hist->Fit(fep->GetName(),"r"); fPhysMon->fEPNeg = 1 + fep->GetParameter(1); fPhysMon->fSigEPNeg = fep->GetParError(1); // truncated_mean(hist,1.0,0.2,3,fPhysMon->fEPNeg,fPhysMon->fSigEPNeg); } hist = (TH1F*) fol->FindObject("WenuMon/Hist/ee_mass_0"); fPhysMon->fNZee = hist->GetEntries(); hist->Fit("gaus"); ff = hist->GetFunction("gaus"); fPhysMon->fMZee = ff->GetParameter(1); fPhysMon->fMZeeFitErr = ff->GetParError(1); fPhysMon->fSigMZee = ff->GetParameter(2); hist = (TH1F*) fol->FindObject("WenuMon/Hist/EoverP_inc"); if (hist) { fPhysMon->fEoverPincMean = hist->GetMean(); fPhysMon->fEoverPincN = hist->Integral(); fPhysMon->fEoverPincErr = (hist->GetRMS())/sqrt(hist->Integral()); } hist = (TH1F*) fol->FindObject("WenuMon/Hist/EoverP_NE"); if (hist) { fPhysMon->fEoverPNEMean = hist->GetMean(); fPhysMon->fEoverPNEN = hist->Integral(); fPhysMon->fEoverPNEErr = (hist->GetRMS())/sqrt(hist->Integral()); } hist = (TH1F*) fol->FindObject("WenuMon/Hist/EoverP_NW"); if (hist) { fPhysMon->fEoverPNWMean = hist->GetMean(); fPhysMon->fEoverPNWN = hist->Integral(); fPhysMon->fEoverPNWErr = (hist->GetRMS())/sqrt(hist->Integral()); } hist = (TH1F*) fol->FindObject("WenuMon/Hist/EoverP_SE"); if (hist) { fPhysMon->fEoverPSEMean = hist->GetMean(); fPhysMon->fEoverPSEN = hist->Integral(); fPhysMon->fEoverPSEErr = (hist->GetRMS())/sqrt(hist->Integral()); } else { fPhysMon->fEoverPSEMean = -1.; fPhysMon->fEoverPSEN = -1.; fPhysMon->fEoverPSEErr = -1.; } hist = (TH1F*) fol->FindObject("WenuMon/Hist/EoverP_SW"); if (hist) { fPhysMon->fEoverPSWMean = hist->GetMean(); fPhysMon->fEoverPSWN = hist->Integral(); fPhysMon->fEoverPSWErr = (hist->GetRMS())/sqrt(hist->Integral()); } else { fPhysMon->fEoverPSWMean = -1.; fPhysMon->fEoverPSWN = -1.; fPhysMon->fEoverPSWErr = -1.; } hist = (TH1F*) fol->FindObject("WenuMon/Hist/ZMass_inc"); if (hist) { fPhysMon->fZMassincMean = hist->GetMean(); fPhysMon->fZMassincN = hist->Integral(); fPhysMon->fZMassincErr = (hist->GetRMS())/sqrt(hist->Integral()); } else { fPhysMon->fZMassincMean = -1.; fPhysMon->fZMassincN = -1.; fPhysMon->fZMassincErr = -1.; } hist = (TH1F*) fol->FindObject("WenuMon/Hist/ZMass_CC"); if (hist) { fPhysMon->fZMassCCMean = hist->GetMean(); fPhysMon->fZMassCCN = hist->Integral(); fPhysMon->fZMassCCErr = (hist->GetRMS())/sqrt(hist->Integral()); } else { fPhysMon->fZMassCCMean = -1.; fPhysMon->fZMassCCN = -1.; fPhysMon->fZMassCCErr = -1.; } hist = (TH1F*) fol->FindObject("WenuMon/Hist/ZMass_CP"); if (hist) { fPhysMon->fZMassCPMean = hist->GetMean(); fPhysMon->fZMassCPN = hist->Integral(); fPhysMon->fZMassCPErr = (hist->GetRMS())/sqrt(hist->Integral()); } else { fPhysMon->fZMassCPMean = -1.; fPhysMon->fZMassCPN = -1.; fPhysMon->fZMassCPErr = -1.; } hist = (TH1F*) fol->FindObject("WenuMon/Hist/ZMass_CPW"); if (hist) { fPhysMon->fZMassCPWMean = hist->GetMean(); fPhysMon->fZMassCPWN = hist->Integral(); fPhysMon->fZMassCPWErr = (hist->GetRMS())/sqrt(hist->Integral()); } else { fPhysMon->fZMassCPWMean = -1.; fPhysMon->fZMassCPWN = -1.; fPhysMon->fZMassCPWErr = -1.; } hist = (TH1F*) fol->FindObject("WenuMon/Hist/ZMass_CPE"); if (hist) { fPhysMon->fZMassCPEMean = hist->GetMean(); fPhysMon->fZMassCPEN = hist->Integral(); fPhysMon->fZMassCPEErr = (hist->GetRMS())/sqrt(hist->Integral()); } else { fPhysMon->fZMassCPEMean = -1.; fPhysMon->fZMassCPEN = -1.; fPhysMon->fZMassCPEErr = -1.; } // number of COT hits hist = (TH1F*) fol->FindObject("WenuMon/Hist/ele_1/trk_ncot_hits_ax"); fPhysMon->fNCotHitsAx = hist->GetMean(); fPhysMon->fNCotHitsAxErr = hist->GetRMS()/sqrt(hist->GetEntries()+0.0001); hist = (TH1F*) fol->FindObject("WenuMon/Hist/ele_1/trk_ncot_hits_st"); fPhysMon->fNCotHitsSt = hist->GetMean(); fPhysMon->fNCotHitsAxErr = hist->GetRMS()/sqrt(hist->GetEntries()+0.0001); //----------------------------------------------------------------------------- // JpsiMon histograms //----------------------------------------------------------------------------- hist = (TH1F*) fol->FindObject("JpsiMon/Hist/mumu_mass_0"); fPhysMon->fNJPsiEnts = hist->GetEntries();; fit_njpsi(hist, fPhysMon->fNJPsimumu, fPhysMon->fMJPsi, fPhysMon->fMJPsiFitErr, fPhysMon->fSigMJPsi); // J/psi MIP peak hist = (TH1F*) fol->FindObject("JpsiMon/Hist/CMUemE"); if (hist) { fPhysMon->fJpsiCMUEmMean = hist->GetMean(); fPhysMon->fJpsiCMUEmN = hist->Integral(); fPhysMon->fJpsiCMUEmErr = (hist->GetRMS())/sqrt(hist->Integral()); } else { fPhysMon->fJpsiCMUEmMean = -1.; fPhysMon->fJpsiCMUEmN = -1.; fPhysMon->fJpsiCMUEmErr = -1.; } hist = (TH1F*) fol->FindObject("JpsiMon/Hist/CMUhadE"); if (hist) { fPhysMon->fJpsiCMUHadMean = hist->GetMean(); fPhysMon->fJpsiCMUHadN = hist->Integral(); fPhysMon->fJpsiCMUHadErr = (hist->GetRMS())/sqrt(hist->Integral()); } else { fPhysMon->fJpsiCMUHadMean = -1.; fPhysMon->fJpsiCMUHadN = -1.; fPhysMon->fJpsiCMUHadErr = -1.; } hist = (TH1F*) fol->FindObject("JpsiMon/Hist/emE"); if (hist) { n0 = hist->Integral( 6, 31); hEmE->SetParameters( n0, 1.e-3); hist->Fit( hEmE->GetName(), "r"); fPhysMon->fJpsiEmE = 0.26 + hEmE->GetParameter( 1); fPhysMon->fJpsiEmEErr = hEmE->GetParError( 1); printf( " -+<==>+- fJpsiEmE: %10.4f + %10.4f\n", fPhysMon->fJpsiEmE, fPhysMon->fJpsiEmEErr); } else { fPhysMon->fJpsiEmE = -1.; fPhysMon->fJpsiEmEErr = -1.; } hist = (TH1F*) fol->FindObject("JpsiMon/Hist/hadE"); if (hist) { n0 = hist->Integral( 12, 50); fHadE->SetParameters( n0, 1.e-3); hist->Fit( fHadE->GetName(), "r"); fPhysMon->fJpsiHadE = 1.6 + fHadE->GetParameter( 1); fPhysMon->fJpsiHadEErr = fHadE->GetParError( 1); printf( " -+<==>+- fJpsiHadE: %10.4f + %10.4f\n", fPhysMon->fJpsiHadE, fPhysMon->fJpsiHadEErr); } else { fPhysMon->fJpsiHadE = -1.; fPhysMon->fJpsiHadEErr = -1.; } //----------------------------------------------------------------------------- // WmunuMon histograms //----------------------------------------------------------------------------- hist = (TH1F*) fol->FindObject("WmunuMon/Hist/EmEnergy_CMUP"); if (hist) { fPhysMon->fEmEnergyCMUPMean = hist->GetMean(); fPhysMon->fEmEnergyCMUPN = hist->Integral(); fPhysMon->fEmEnergyCMUPErr = (hist->GetRMS())/sqrt(hist->Integral()); } else { fPhysMon->fEmEnergyCMUPMean = -1.; fPhysMon->fEmEnergyCMUPN = -1.; fPhysMon->fEmEnergyCMUPErr = -1.; } hist = (TH1F*) fol->FindObject("WmunuMon/Hist/EmEnergy_CMX"); if (hist) { fPhysMon->fEmEnergyCMXMean = hist->GetMean(); fPhysMon->fEmEnergyCMXN = hist->Integral(); fPhysMon->fEmEnergyCMXErr = (hist->GetRMS())/sqrt(hist->Integral()); } else { fPhysMon->fEmEnergyCMXMean = -1.; fPhysMon->fEmEnergyCMXN = -1.; fPhysMon->fEmEnergyCMXErr = -1.; } hist = (TH1F*) fol->FindObject("WmunuMon/Hist/HadEnergy_CMUP"); if (hist) { fPhysMon->fHadEnergyCMUPMean = hist->GetMean(); fPhysMon->fHadEnergyCMUPN = hist->Integral(); fPhysMon->fHadEnergyCMUPErr = (hist->GetRMS())/sqrt(hist->Integral()); } else { fPhysMon->fHadEnergyCMUPMean = -1.; fPhysMon->fHadEnergyCMUPN = -1.; fPhysMon->fHadEnergyCMUPErr = -1.; } hist = (TH1F*) fol->FindObject("WmunuMon/Hist/HadEnergy_CMX"); if (hist) { fPhysMon->fHadEnergyCMXMean = hist->GetMean(); fPhysMon->fHadEnergyCMXN = hist->Integral(); fPhysMon->fHadEnergyCMXErr = (hist->GetRMS())/sqrt(hist->Integral()); } else { fPhysMon->fHadEnergyCMXMean = -1.; fPhysMon->fHadEnergyCMXN = -1.; fPhysMon->fHadEnergyCMXErr = -1.; } //----------------------------------------------------------------------------- // luminosity histogram: for 1 run/file GetTotal returns the luminosity for // this run //----------------------------------------------------------------------------- // TH1F* lum_hist = (TH1F*) fol->FindObject("int_lumi_tape"); // fPhysMon->fLumiTape = lum_hist->Integral(); fCdfofprd->GetRunSummary(run_number,&rs); fPhysMon->fLumiTape = rs.LumiTape(); fPhysMon->fCalendarTime = 0; fPhysMon->fNZmumu = 0; // fPhysMon->fNJPsimumu = 0; // fPhysMon->fMJPsi = 0; // fPhysMon->fSigMJPsi = 0; tree->Fill(); hfile->Close(); delete hfile; // delete fol; } ntuple_file->Write(); delete ntuple_file; return 0; } //_____________________________________________________________________________ int TOfflineMon::CreatePbMonNtuple(const char* InputDir, const char* NtupleFile) { TFile* ntuple_file = new TFile(NtupleFile,"recreate"); TTree* tree = new TTree("pbmon","Physics Monitor: per pb-1"); TBranch* br = tree->Branch("PbMon","TPbMon", &fPbMon); //----------------------------------------------------------------------------- // read the data files and fill the ntuple //----------------------------------------------------------------------------- char cmd[200]; TStnRunSummary rs; sprintf(cmd,"rm .tmp; ls %s/stra_mon_hist.* > .tmp",InputDir); gSystem->Exec(cmd); FILE* f = fopen(".tmp","r"); char fn[200]; TFile* hfile; TH1F *h_zee_mass; TH1F *h_zmm_mass; TF1 *ff, *fep; TFolder* fol; // double xmean, sigx; fep = fPhysMon->GetFuncEp(); fep->SetParameters(1,0.0,100.); // double fint; // double lum_sum = 0; // bin per pb^-1 double max_lum = 1000.; int first = 1; TDirectory* dir; // fint = 3583.9380; // fint = fep->Integral(0.85,1.9); //----------------------------------------------------------------------------- // loop over the histogram files //----------------------------------------------------------------------------- fPbMon->Clear(); TPbMon::Hist_t* pb_h = fPbMon->GetHist(); while (fgets(fn,200,f) > 0) { int len = strlen(fn); fn[len-1] = 0; int run_number = atoi(&fn[len-7]); printf(".%s. %i\n",fn,run_number); //----------------------------------------------------------------------------- // accumulate histograms //----------------------------------------------------------------------------- hfile = TFile::Open(fn); dir = gDirectory; fol = (TFolder*) hfile->Get("Ana"); h_zee_mass = (TH1F*) fol->FindObject("WenuMon/Hist/ee_mass_0"); h_zmm_mass = (TH1F*) fol->FindObject("WmunuMon/Hist/mm_mass_0"); if (fPbMon->fMinRun == -1) { fPbMon->fMinRun = run_number; if (first) { // book all the histograms gROOT->cd(); pb_h->fZeeMass = new TH1F(*h_zee_mass); pb_h->fZeeMass->Reset(); if (h_zmm_mass) { pb_h->fZmmMass = new TH1F(*h_zmm_mass); pb_h->fZmmMass->Reset(); } dir->cd(); first = 0; } } fPbMon->fMaxRun = run_number; pb_h->fZeeMass->Add(h_zee_mass); if (h_zmm_mass && pb_h->fZmmMass ) { pb_h->fZmmMass->Add(h_zmm_mass); } fCdfofprd->GetRunSummary(run_number,&rs); fPbMon->fLumiTape += rs.LumiTape(); if (fPbMon->fLumiTape >= max_lum) { //----------------------------------------------------------------------------- // fit all the histograms and fill the tree //----------------------------------------------------------------------------- fPbMon->FitHistograms(); tree->Fill(); fPbMon->Clear(); } hfile->Close(); delete hfile; } if (fPbMon->fLumiTape > 0) { fPbMon->FitHistograms(); tree->Fill(); fPbMon->Clear(); } ntuple_file->Write(); delete ntuple_file; return 0; }