/////////////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////////// #include "TFile.h" #include "TTree.h" #include "TBranch.h" #include "TSystem.h" #include "TFolder.h" #include "OfflineMon/TPbMon.hh" #include "OfflineMon/TPhysMon.hh" #include "Stntuple/obj/TStnRunSummary.hh" #include "Stntuple/oracle/TCdfOracle.hh" ClassImp(TPbMon) //_____________________________________________________________________________ TPbMon::TPbMon() { // fFuncEp = new TF1("func_ep",f_ep,0.85,1.9,4); // fFuncEp->SetParNames("scale","offset","constant","thr"); fHist.fZeeMass = 0; fHist.fZmmMass = 0; fData = new Data_t(); Clear(); } //_____________________________________________________________________________ TPbMon::~TPbMon() { // delete fFuncEp; } //_____________________________________________________________________________ void TPbMon::Clear(const char* Option) { fData->fMinRun = -1; fData->fMaxRun = -1; fData->fLumiTape = 0; fData->fNZee.fVal = 0; fData->fNZee.fErr = -1; fData->fZeeMass.fVal = 0; fData->fZeeMass.fErr = -1; fData->fZmmMass.fVal = 0; fData->fZmmMass.fErr = -1; fData->fEOverP = -1.; fData->fSigEOverP = -1; fData->fEoverPincMean = -1.; fData->fEoverPincN = -1.; fData->fEoverPincErr = -1.; fData->fEoverPNEMean = -1.; fData->fEoverPNEN = -1.; fData->fEoverPNEErr = -1.; fData->fEoverPNWMean = -1.; fData->fEoverPNWN = -1.; fData->fEoverPNWErr = -1.; //----------------------------------------------------------------------------- // reset the histograms //----------------------------------------------------------------------------- if (fHist.fZeeMass) fHist.fZeeMass->Reset(); if (fHist.fZmmMass) fHist.fZmmMass->Reset(); } //_____________________________________________________________________________ int TPbMon::FitHistograms() { TF1* ff; //----------------------------------------------------------------------------- // Z->ee //----------------------------------------------------------------------------- fHist.fZeeMass->Fit("gaus","l","",61,121); ff = fHist.fZeeMass->GetFunction("gaus"); fData->fNZee.fVal = ff->GetParameter(0)*TMath::Sqrt(2.*TMath::Pi())*ff->GetParameter(2); //----------------------------------------------------------------------------- // this is obviosly wrong, but to get correlation term right one needs to do // some coding. Later. //----------------------------------------------------------------------------- fData->fNZee.fErr = TMath::Sqrt(2.*TMath::Pi())* TMath::Sqrt(ff->GetParError(0)*ff->GetParError(0)+ ff->GetParError(2)*ff->GetParError(2)); fData->fZeeMass.fVal = ff->GetParameter(1); fData->fZeeMass.fErr = ff->GetParError(1); fData->fZeeWidth.fVal = ff->GetParameter(2); fData->fZeeWidth.fErr = ff->GetParError (2); if (fHist.fZmmMass) { //----------------------------------------------------------------------------- // Z->mm //----------------------------------------------------------------------------- fHist.fZmmMass->Fit("gaus"); ff = fHist.fZmmMass->GetFunction("gaus"); fData->fNZmm.fVal = ff->GetParameter(0)*TMath::Sqrt(2.*TMath::Pi())*ff->GetParameter(2); fData->fNZmm.fErr = TMath::Sqrt(2.*TMath::Pi())* TMath::Sqrt(ff->GetParError(0)*ff->GetParError(0)+ ff->GetParError(2)*ff->GetParError(2)); fData->fZmmMass.fVal = ff->GetParameter(1); fData->fZmmMass.fErr = ff->GetParError(1); fData->fZmmWidth.fVal = ff->GetParameter(2); fData->fZmmWidth.fErr = ff->GetParError (2); } fData->fCalendarTime = 0; return 0; } //_____________________________________________________________________________ int TPbMon::UpdateNtuple() { TFile* ntuple_file = new TFile(fNtupleFileName.Data(),"recreate"); TTree* tree = new TTree("pbmon","Physics Monitor: per pb-1"); TBranch* br = tree->Branch("PbMon","TPbMon", &fData); //----------------------------------------------------------------------------- // read the data files and fill the ntuple //----------------------------------------------------------------------------- char cmd[200]; TStnRunSummary rs; sprintf(cmd,"rm .tmp; ls %s/stra_mon_hist.* > .tmp",fInputDirName.Data()); 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 = TPhysMon::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 //----------------------------------------------------------------------------- Clear(); TPbMon::Hist_t* pb_h = 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 (fData->fMinRun == -1) { fData->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; } } fData->fMaxRun = run_number; pb_h->fZeeMass->Add(h_zee_mass); if (h_zmm_mass && pb_h->fZmmMass ) { pb_h->fZmmMass->Add(h_zmm_mass); } TOfflineMonitor::fCdfofprd->GetRunSummary(run_number,&rs); fData->fLumiTape += rs.LumiTape(); if (fData->fLumiTape >= max_lum) { //----------------------------------------------------------------------------- // fit all the histograms and fill the tree //----------------------------------------------------------------------------- FitHistograms(); tree->Fill(); Clear(); } hfile->Close(); delete hfile; } if (fData->fLumiTape > 0) { FitHistograms(); tree->Fill(); Clear(); } ntuple_file->Write(); delete ntuple_file; return 0; }