void CFrameLocs::OnLocationDeletelocation() { // TODO: Add your control notification handler code here int n; TString str; CLocation * loc; POSITION pos = m_wndLocs.GetFirstSelectedItemPosition(); if (pos == NULL) return; n = m_wndLocs.GetNextSelectedItem(pos); if (n < 0) return; loc = (CLocation *)(m_wndLocs.GetItemData(n)); if (loc == NULL) return; loc->SetTextB(str); str.Insert(0, "Do you want to remove location:\r\n\r\n"); str += "\r\n\r\nfrom your list of locations?"; if (AfxMessageBox(str, MB_YESNO) == IDYES) { theLocs.RemoveAt(loc); InitCityByCountry(g_nCurrentCountry); delete loc; } }
TString CSVString( const TString &astring, char adelimiter ) { bool changed = false; int pos; TString word = astring; ReplaceSub32OrdinalsWithHexForm( word ); changed = 0; pos = 1; while( pos<=word.Length() ) { if( word[pos]==adelimiter ) { changed = 1; } else if( word[pos]=='"' ) { word.Insert( "\"", pos ); pos++; changed = 1; } pos++; } if( changed ) word = "\"" + word + "\""; return word; }
void ReplaceSub32OrdinalsWithHexForm( TString& astring ) { int sl = astring.Length(); for( int i=1; i<=sl; i++ ) { if( astring[i] == '\\' ) { astring.Insert( "\\", i ); i++; sl++; } else { if( ((unsigned char)astring[i]) < 32 ) { astring.Insert( "\\x" + utils::IntToHex((unsigned char)astring[i],2), i ); astring.Delete( i+4,1 ); sl += 3; i += 3; } } } }
void misalignmentDependence(Int_t nFiles,TString *files,TString *names,TString misalignment,Double_t *values,Double_t *phases,TString xvar,TString yvar, TString function,Int_t nParameters,Int_t *parameters,TString *parameternames,TString functionname = "", Bool_t resolution = false, TString saveas = "") { for (int i = 0; i < nParameters; i++) { TString saveasi = saveas; TString insert = nPart(1,parameternames[i]); insert.Prepend("."); saveasi.Insert(saveasi.Last('.'),insert); //insert the parameter name before the file extension misalignmentDependence(nFiles,files,names,misalignment,values,phases,xvar,yvar, function,parameters[i],parameternames[i],functionname, resolution, saveasi); } }
void bfcread_hist_extract( const Char_t *MainFile= "/afs/rhic.bnl.gov/star/data/samples/gstar.hist.root", const Char_t *MakerHistDir="EventQA", const Char_t *TopDirTree="bfcTree", Char_t *OutFile=0, const Char_t *PrintList="") { cout << "bfcread_hist_extract.C, input hist file = " << MainFile << endl; cout << "bfcread_hist_extract.C, directory name for hist = " << MakerHistDir << endl; cout << "bfcread_hist_extract.C, top level directory in hist file = " << TopDirTree << endl; // gSystem->Load("St_base"); gSystem->Load("StChain"); gSystem->Load("StIOMaker"); gSystem->Load("StarClassLibrary"); gSystem->Load("StUtilities"); gSystem->Load("StAnalysisUtilities"); gSystem->Load("libglobal_Tables"); // setup chain with IOMaker - can read in .dst.root, .dst.xdf files StIOMaker *IOMk = new StIOMaker("IO","r",MainFile,TopDirTree); IOMk->SetDebug(); IOMk->SetIOMode("r"); IOMk->SetBranch("*",0,"0"); //deactivate all branches IOMk->SetBranch("histBranch",0,"r"); //activate dst Branch // constructor for other maker (not used in chain) StHistUtil *HU = new StHistUtil; // now must set pointer to StMaker so HistUtil can find histograms // with StHistUtil methods // -- input any maker pointer but must cast as type StMaker HU->SetPntrToMaker((StMaker *)IOMk); // ONLY use StIOMaker in chain // --- now execute chain member functions - 1 event (histograms) only IOMk->Init(); IOMk->Clear(); IOMk->Make(); // method to print out list of histograms // - can do this anytime after they're booked // - default is to print out QA hist branch Int_t NoHist=0; //NoHist = HU->ListHists(MakerHistDir); TList* dList = HU->FindHists(MakerHistDir); if (PrintList) HU->SetDefaultPrintList(MakerHistDir,PrintList); NoHist = HU->CopyHists(dList); TH1** nh = HU->getNewHist(); TString name = MainFile; if (!OutFile) { name.Remove(0,name.Last('/')+1); TString name2 = MakerHistDir; name2.Remove(0,name2.Last('/')+1); name.Insert(name.First('.'),"_"); name.Insert(name.First('.'),name2); OutFile = name.Data(); } cout << "Output hist file: " << OutFile << endl; TFile* ofile = new TFile(OutFile,"RECREATE"); for (int i=0; i<NoHist; i++) { printf("Extracting: %d. %s : %s\n", i+1,nh[i]->GetName(),nh[i]->GetTitle()); nh[i]->Write(); } ofile->Close(); }
void createDataVsMC(TString folderName,TString histoName,int rebin,double xMin,double xMax,TString xName, TString yName, vector<TString> MCFileNames, vector<TString> MCNames, vector<int> MCColors, vector<bool> AddToBkg,vector<TString> DataFileNames,vector<TString> dataNames,vector<int> dataColors,vector<TString> SystNames,vector<int> SystColors, TCanvas *cCanvas, int padNr, bool UseLog,GlobalParameterSet Parameters) { // CREATE ALL HISTOGRAMS ======================================================== TString lumi = ""; lumi+=Parameters.intLumi; if(Parameters.GlobalLog) { UseLog = true; } // SM background histo TH1D *hSM0=0; // Create MC histos and add them SM0 vector<TH1D*> MChistos; bool noneAdded = true; float eventsMC=0; if(Parameters.MuPred){ for(unsigned int i =0;i<3;i++) { TFile* fhh = TFile::Open(MCFileNames[i],"READONLY"); TH1D *hTemp = (TH1D*)fhh->Get(folderName+"/CounterCtrl_tot"); eventsMC += hTemp->GetBinContent(1); cout << "eventsMC " <<eventsMC<< endl; //delete hTemp; // delete fhh; } TFile* fdata_test = TFile::Open(DataFileNames[0],"READONLY"); TH1D *hTempddd = (TH1D*)fdata_test->Get(folderName+"/CounterCtrl_tot"); cout << "eventsMC " << eventsMC<< " "<<hTempddd->GetBinContent(1) << endl; Parameters.intLumi = 100*hTempddd->GetBinContent(1)/eventsMC; } // delete fdata_test; // delete hTempddd; for(unsigned int i =0;i<MCFileNames.size();i++) { MChistos.push_back(plot1Dhisto(Parameters.intLumi,TFile::Open(MCFileNames[i],"READONLY"),folderName,histoName,MCColors[i],rebin,xMin,xMax,xName,yName,"MC",true)); if(noneAdded&&AddToBkg[i]) { hSM0 = (TH1D *) MChistos[i]->Clone(); noneAdded = false; } else { if(AddToBkg[i]) { hSM0->Add(MChistos[i],1); } } } hSM0->SetLineColor(2); // Create Histograms with the different systematics vector<TH1D*> SystHistos; if(Parameters.UseSystematics) { for(unsigned int i=0; i<SystNames.size(); i++) { noneAdded = true; for(unsigned int j=0; j<MCFileNames.size(); j++) { if(AddToBkg[j]) { TString SystFileName = MCFileNames[j]; SystFileName.Insert(SystFileName.Last('/'),"_"+SystNames[i]); TFile *SystMCFile = TFile::Open(SystFileName,"READONLY"); TH1D *SystHistoTemp = plot1Dhisto(Parameters.intLumi,SystMCFile,folderName,histoName,SystColors[i],rebin,xMin,xMax,xName,yName,"MC",true); SystHistoTemp->SetLineStyle(2); if(noneAdded) { SystHistos.push_back((TH1D *) SystHistoTemp->Clone()); noneAdded = false; } else { SystHistos.back()->Add(SystHistoTemp,1); } } } } } // Create Histograms for error band TH1D* hSM0allErrors = (TH1D *) hSM0->Clone(); TH1D* hSM0systErrors = (TH1D *) hSM0->Clone(); if(Parameters.UseSystematics) { for(int j = hSM0->FindBin(xMin); j<=hSM0->FindBin(xMax); j++) { double downerror=0; double uperror=0; for(unsigned int i=0; i<SystHistos.size(); i++) { double diff = SystHistos[i]->GetBinContent(j) - hSM0->GetBinContent(j); if(diff>0) uperror += diff*diff; else downerror += diff*diff; } downerror = TMath::Sqrt(downerror); uperror = TMath::Sqrt(uperror); double maxerror = TMath::Max(downerror,uperror); double staterror = hSM0->GetBinError(j); hSM0systErrors->SetBinError(j,maxerror); hSM0allErrors->SetBinError(j,TMath::Sqrt(maxerror*maxerror+staterror*staterror)); hSM0systErrors->SetFillColor(5); hSM0systErrors->SetLineColor(5); hSM0allErrors->SetLineColor(3); hSM0allErrors->SetFillColor(3); } } // Create Data Histograms vector<TH1D *> dataHistos; for(unsigned int i=0; i<DataFileNames.size();i++) { dataHistos.push_back(plot1Dhisto(Parameters.intLumi,TFile::Open(DataFileNames[i],"READONLY"),folderName,histoName,dataColors[i],rebin,xMin,xMax,xName,yName,"Data",false)); dataHistos[i]->SetMarkerSize(1.2); dataHistos[i]->SetMarkerColor(dataColors[i]); dataHistos[i]->SetMarkerStyle(20); // remove error manually if(!Parameters.ShowStatErrorbars){ NoError(dataHistos[i],xMin,xMax); } // y-axis range if (UseLog){ dataHistos[i]->GetYaxis()->SetRangeUser(1.,3.5*(dataHistos[i]->GetBinContent(dataHistos[i]->GetMaximumBin()))); } else{ float maximum = hSM0->GetMaximum(); if(maximum<dataHistos[i]->GetMaximum())maximum=dataHistos[i]->GetMaximum(); dataHistos[i]->GetYaxis()->SetRangeUser(0.,maximum*1.8); } } cCanvas->SetName(folderName+histoName); cCanvas->cd(2*padNr+1); if(UseLog) { gPad->SetLogy(); } dataHistos[0]->Draw("P E0"); //DRAW ALL HISTOGRAMS ===================================================== if(Parameters.ShowMCComposition){ for(unsigned int i=1; Parameters.StackMCComposition&&i<MChistos.size();i++) { MChistos[i]->Add(MChistos[i],MChistos[i-1]); MChistos[i]->SetFillColor(MCColors[i]); MChistos[i]->SetLineStyle(1); MChistos[i]->SetFillStyle(3004); MChistos[i-1]->SetFillStyle(3004); MChistos[i-1]->SetFillColor(MCColors[i-1]); } for(int i=MChistos.size()-1;i>=0;i--) { if(Parameters.ShowMCStatErrorbars) MChistos[i]->Draw("HIST E0 same"); else MChistos[i]->Draw("HIST same"); } } hSM0->SetLineColor(kRed); if(Parameters.ShowErrorBand) { hSM0allErrors->Draw("E2 same"); hSM0systErrors->Draw("E2 same"); } if(!Parameters.ShowMCStatErrorbars&&!Parameters.StackMCComposition) hSM0->Draw("HIST same"); if(Parameters.ShowSystematicsDetails) { for(unsigned int i=0; i<SystHistos.size();i++) { SystHistos[i]->Draw("HIST same"); } } for(int i=dataHistos.size()-1;i>=0;i--) { dataHistos[i]->Draw("P E0 same"); } if(Parameters.ShowMCStatErrorbars&&!Parameters.StackMCComposition) { hSM0->Draw("HIST same E0"); } // Draw Legend TLegend *lSamples = legendRAW(0.77,0.58,0.95,0.89); if(!Parameters.StackMCComposition) lSamples->AddEntry(hSM0,"Total MC","FL"); if(Parameters.ShowErrorBand) { lSamples->AddEntry(hSM0systErrors,"Systematic Error","FL"); lSamples->AddEntry(hSM0allErrors,"MC Syst. #oplus Stat. Error","FL"); } for(unsigned int i=0; i<dataHistos.size(); i++) { lSamples->AddEntry(dataHistos[i],dataNames[i],"PL"); } for(unsigned int i =0;i<MChistos.size()&&Parameters.ShowMCComposition;i++) { lSamples->AddEntry(MChistos[i],MCNames[i],"FL"); } for(unsigned int i =0;i<SystHistos.size()&&Parameters.ShowSystematicsDetails;i++) { lSamples->AddEntry(SystHistos[i],SystNames[i],"FL"); } lSamples->Draw("same"); TLatex *lWhichLepton; if (Parameters.electrons) { lWhichLepton = new TLatex(0.73,0.9,"Electrons"); } else { lWhichLepton = new TLatex(0.73,0.9,"Muons"); } lWhichLepton->SetNDC(); lWhichLepton->Draw("same"); TLatex *lPreliminary = new TLatex(0.19,0.96,"CMS Preliminary 2011"); // TLatex *lIntLumi = new TLatex(0.15,0.89,"#scale[0.8]{#int L dt = "+lumi+" pb^{-1}, #sqrt{s} = 7 TeV}"); TLatex *lIntLumi = new TLatex(0.22,0.88,"#scale[1.]{4.7 fb^{-1}, #sqrt{s} = 7 TeV}"); TLatex *lIntLumiB = new TLatex(0.22,0.79,"#scale[1.]{#sqrt{s} = 7 TeV}"); lPreliminary->SetNDC(); lIntLumi->SetNDC(); lIntLumiB->SetNDC(); lPreliminary->Draw("same"); lIntLumi->Draw("same"); gPad->SetFillColor(0); // lIntLumiB->Draw("same"); // gPad->SetGridx(); // gPad->SetGridy(); // --- create HT and STlep legends //"ANplots150_NOLPsecondD500" folderNames TString HT500 = "secondD500"; TString HT750 = "secondD750"; TString HT1000 = "secondD1000"; TString ST150 = "plots150"; TString ST250 = "plots250"; TString ST350 = "plots350"; TString ST450 = "plots450"; TString tmpLegendHT, tmpLegendST; if (((folderName.SubString(HT500)).Length())>0) { if (Parameters.htBins) { tmpLegendHT = "H_{T}#in[500,750]"; } else { tmpLegendHT = "H_{T}>500";} } else if (((folderName.SubString(HT750)).Length())>0) { if (Parameters.htBins) { tmpLegendHT = "H_{T}#in[750,1000]"; } else { tmpLegendHT = "H_{T}>750";} } else if (((folderName.SubString(HT1000)).Length())>0) { if (Parameters.htBins) { tmpLegendHT = "H_{T}>1000"; } else { tmpLegendHT = "H_{T}>1000";} } else { tmpLegendHT = "error"; } if (((folderName.SubString(ST150)).Length())>0) { tmpLegendST = "S^{lep}_{T}#in[150,250]"; } else if (((folderName.SubString(ST250)).Length())>0) { tmpLegendST = "S^{lep}_{T}#in[250,350]"; } else if (((folderName.SubString(ST350)).Length())>0) { tmpLegendST = "S^{lep}_{T}#in[350,450]"; } else if (((folderName.SubString(ST450)).Length())>0) { tmpLegendST = "S^{lep}_{T}>450"; } else { tmpLegendST = "error"; } TString legendHTandST = tmpLegendHT+" , "+tmpLegendST; TLatex *lHTandST = new TLatex(0.22,0.8,legendHTandST); lHTandST->SetNDC(); // lHTandST->Draw("same"); TLatex *lHT = new TLatex(0.22,0.8,tmpLegendHT); lHT->SetNDC(); lHT->Draw("same"); TLatex *lST = new TLatex(0.22,0.7,tmpLegendST); lST->SetNDC(); lST->Draw("same"); // DRAW RATIO PLOTS ============================================================================ if (Parameters.ratioplot) { vector<TH1D*> hRatio; for(unsigned int i=0; i<dataHistos.size()&&MChistos.size()>0; i++) { hRatio.push_back((TH1D*)dataHistos[i]->Clone("")); hRatio.back()->Divide(dataHistos[i],hSM0); hRatio.back()->GetYaxis()->SetTitle("Data / MC"); hRatio.back()->GetYaxis()->SetTitleSize(0.16); hRatio.back()->GetXaxis()->SetTitle(""); hRatio.back()->GetYaxis()->SetNdivisions(409); hRatio.back()->GetYaxis()->SetRangeUser(0.,2.); hRatio.back()->SetTitleSize(0.16, "XY"); hRatio.back()->SetTitleOffset(0.5, "Y"); hRatio.back()->SetLabelSize(0.165,"XY"); } for(unsigned int i=0; Parameters.UseSystematics&&Parameters.ShowSystematicsDetails&&i<SystHistos.size(); i++) { hRatio.push_back((TH1D*)SystHistos[i]->Clone("")); hRatio.back()->Divide(SystHistos[i],hSM0); hRatio.back()->GetYaxis()->SetTitle("Data&Syst/MC"); hRatio.back()->GetYaxis()->SetRangeUser(0.5,1.5); hRatio.back()->GetXaxis()->SetTitle(""); hRatio.back()->SetTitleSize(0.06, "XY"); hRatio.back()->SetTitleOffset(0.8, "Y"); hRatio.back()->SetLabelSize(0.08,"XY"); NoError(hRatio.back(),xMin,xMax); } cCanvas->cd(2*padNr+2); // TBox *unity = new TBox(xMin-0.1,0.95,xMax+0.15, 1.05); // LP TBox *unity = new TBox(xMin-0.1,0.95,xMax+0.15, 1.05); unity->SetLineWidth(2); //unity.SetLineStyle(Root.kDashed); unity->SetLineColor(2); unity->SetFillColor(2); unity->SetFillStyle(3002); // unity->Draw(); // gPad->SetGridx(); // gPad->SetGridy(); for(unsigned int i=hRatio.size()-1; i<hRatio.size(); i--) { if(i==hRatio.size()-1) { hRatio[i]->Draw(); // unity->Draw("same"); hRatio[i]->Draw("same"); } else { hRatio[i]->GetYaxis()->SetTitleSize(0.055); hRatio[i]->Draw("same"); } } } // ratio stuff close }
void makePlots( const char * model, const char * target, const char * src, const char * config, const char * infile) { double MAXY = 2.4; double x_Q13_SetI = sin(8.8*TMath::Pi()/180.0)*sin(8.8*TMath::Pi()/180.0); double x_Q13_SetII = sin(12.0*TMath::Pi()/180.0)*sin(12.0*TMath::Pi()/180.0); //Input path TString inpath("./root_files/RvsQ13/"); TString inputfile = inpath + TString(infile); //Output path TString path("./paper02-plots/ratio/"); TList * v_Variations = new TList(); TObjString *var; var = new TObjString("Sin2Q13-1.8-dCP0"); v_Variations->Add( var ); var = new TObjString("Sin2Q13-1.8-dCP180"); v_Variations->Add( var ); if ( TString(model) != TString("StdPicture") ) { var = new TObjString("Sin2Q13-2.0-dCP0"); v_Variations->Add( var ); var = new TObjString("Sin2Q13-2.0-dCP180"); v_Variations->Add( var ); } else { var = new TObjString("Sin2Q13-2-dCP0"); v_Variations->Add( var ); var = new TObjString("Sin2Q13-2-dCP180"); v_Variations->Add( var ); } var = new TObjString("Sin2Q13-2.2-dCP0"); v_Variations->Add( var ); var = new TObjString("Sin2Q13-2.2-dCP180"); v_Variations->Add( var ); int * linewidth = new int[6]; int * linestyle = new int[6]; int * linecolor = new int[6]; linewidth[0] = 2; linewidth[1] = 3; linewidth[2] = 2; linewidth[3] = 3; linewidth[4] = 2; linewidth[5] = 3; linecolor[0] = 1; linecolor[1] = 2; linecolor[2] = 1; linecolor[3] = 2; linecolor[4] = 1; linecolor[5] = 2; linestyle[0] = 1; linestyle[1] = 1; linestyle[2] = 2; linestyle[3] = 2; linestyle[4] = 3; linestyle[5] = 3; TList * v_Labels = new TList(); TObjString *label; label = new TObjString( "#alpha = 1.8" ); v_Labels->Add( label ); label = new TObjString( "#alpha = 2.0" ); v_Labels->Add( label ); label = new TObjString( "#alpha = 2.2" ); v_Labels->Add( label ); TFile * f1 = new TFile( inputfile.Data() ); f1->cd(); TList * v_Graphs = new TList(); int max = v_Variations->GetEntries(); for( int k = 0; k < max; ++k ) { TString current = ((TObjString*)v_Variations->At(k))->GetString(); TString dataPxx = TString( "Ratio_" ) + TString( model ) + TString("_") + TString( target ) + TString("_") + TString( src ) + TString("_") + TString( current.Data() ) + TString("/data"); std::cout << dataPxx << std::endl; TTree * PxxTreeNu = (TTree*)gDirectory->Get( dataPxx.Data() ); //Branches double xx = 0.0; double yy = 0.0; PxxTreeNu->SetBranchAddress("Xx",&xx); PxxTreeNu->SetBranchAddress("Ratio",&yy); Long64_t nentries = PxxTreeNu->GetEntries(); TGraph * g1 = new TGraph(); for (Long64_t i=0;i<nentries;i++) { PxxTreeNu->GetEntry(i); g1->SetPoint( i, xx, yy); } v_Graphs->Add( g1 ); } TString cname = TString("Ratio") + TString("_") + TString(model) + TString("_") + TString(config); TCanvas * c1 = new TCanvas( cname.Data(), "track/shower ratio", 206,141,722,575); c1->SetBorderSize(2); TLegend * leg = new TLegend(0.18,0.64,0.44,0.87); leg->SetBorderSize(0); leg->SetTextFont(22); leg->SetTextSize(0.062); leg->SetLineColor(1); leg->SetLineStyle(1); leg->SetLineWidth(1); leg->SetFillColor(0); leg->SetFillStyle(0); int labelpos = 0; for( int k = 0; k < max; ++k ) { TGraph * gg = (TGraph*)v_Graphs->At(k); gg->SetMarkerStyle(25); gg->SetFillColor(10); gg->SetLineColor(linecolor[k]); gg->SetLineWidth(linewidth[k]); gg->SetLineStyle(linestyle[k]); gg->SetMaximum(MAXY); gg->SetMinimum(1.6); gg->GetXaxis()->SetLimits( 0.0, 0.055 ); gg->GetXaxis()->SetTitle("sin^{2}#theta_{13}"); gg->GetXaxis()->CenterTitle(true); gg->GetXaxis()->SetLabelFont(42); gg->GetXaxis()->SetLabelOffset(0.006); gg->GetXaxis()->SetLabelSize(0.06); gg->GetXaxis()->SetTitleSize(0.06); gg->GetXaxis()->SetTickLength(0.05); gg->GetXaxis()->SetTitleOffset(1.07); gg->GetXaxis()->SetTitleFont(42); gg->GetXaxis()->SetNdivisions(509); gg->GetYaxis()->SetTitle("R"); gg->GetYaxis()->CenterTitle(true); gg->GetYaxis()->SetNdivisions(509); gg->GetYaxis()->SetLabelFont(42); gg->GetYaxis()->SetLabelOffset(0.007); gg->GetYaxis()->SetLabelSize(0.06); gg->GetYaxis()->SetTitleSize(0.06); gg->GetYaxis()->SetTitleOffset(0.93); gg->GetYaxis()->SetTitleFont(42); if ( ((k+1) % 2) == 0 ) { TString alpha = ((TObjString*)v_Labels->At(labelpos))->GetString(); leg->AddEntry( gg, alpha.Data(),"l"); labelpos+=1; } c1->cd(); if( k == 0 ) gg->Draw("AC"); else gg->Draw("C"); TString ThisModel; TString ThisConfig; if( TString(model) == TString("StdPicture") ) ThisModel = TString("No matter effect"); else { ThisModel = TString(model); ThisModel.Insert(5," "); } ThisConfig = TString(config); ThisConfig.Insert(3," "); TLatex * tex = new TLatex(0.033, (MAXY-(MAXY*0.035)), ThisModel.Data() ); tex->SetLineWidth(2); tex->Draw(); if ( TString(model) != TString("StdPicture") ) { tex = new TLatex(0.033, (MAXY-(MAXY*0.055)), ThisConfig.Data() ); tex->SetLineWidth(2); tex->Draw(); } } leg->Draw(); double y_min = 1.60; double y_max = MAXY; TLine *line = new TLine(x_Q13_SetI, y_min,x_Q13_SetI, y_max); //line->Draw(); line = new TLine(x_Q13_SetII, y_min,x_Q13_SetII, y_max); //line->Draw(); c1->cd(); std::stringstream saveAs; saveAs.str(""); saveAs << path << model << "/pdf/" << "RvsSin2Q13_" << model << "_" << target << "_" << config << ".pdf"; c1->SaveAs( saveAs.str().c_str() ); saveAs.str(""); saveAs << path << model << "/png/" << "RvsSin2Q13_" << model << "_" << target << "_" << config << ".png"; c1->SaveAs( saveAs.str().c_str() ); saveAs.str(""); saveAs << path << model << "/eps/" << "RvsSin2Q13_" << model<< "_" << target << "_" << config << ".eps"; c1->SaveAs( saveAs.str().c_str() ); }
/// Make Output Histogram //////////////////////////////////////////////////// void makehistogram(TString nameofhistogram, float xmin, float xmax, float rebin, float ymax){ TString pad1 = nameofhistogram; TString pad2 = nameofhistogram; TString canvas = nameofhistogram; TString hstack = nameofhistogram; TString legend = nameofhistogram; TString func = nameofhistogram; TString clone = nameofhistogram; TString line = nameofhistogram; pad1.Insert(0, "pad1_"); pad2.Insert(0, "pad2_"); canvas.Insert(0, "c_"); hstack.Insert(0, "hs_"); legend.Insert(0, "legend_"); func.Insert(0, "ratio_"); clone.Insert(0, "h3_"); line.Insert(0, "l_"); mapcanvas[canvas] = new TCanvas(canvas,"",800,600); gStyle -> SetOptStat(1111); gStyle -> SetPadTickY(1); gStyle -> SetPadTickX(1); mappad[pad1] = new TPad("", "", 0, 0, 1, 1); mappad[pad1] -> SetBottomMargin(0.05); mappad[pad1] -> SetTopMargin(0.05); mappad[pad1] -> SetLeftMargin(0.09); mappad[pad1] -> SetRightMargin(0.09); gStyle -> SetPadTickY(1); gStyle -> SetPadTickX(1); mappad[pad1] -> Draw(); mappad[pad1] -> cd(); mappad[pad1] -> SetLogy(); GetHist(nameofhistogram + head + ttjets) -> SetLineColor(kBlue); GetHist(nameofhistogram + head + gluino) -> SetLineColor(kGreen); GetHist(nameofhistogram + head + stop) -> SetLineColor(kRed); GetHist(nameofhistogram + head + ttjets) -> SetLineWidth(3); GetHist(nameofhistogram + head + gluino) -> SetLineWidth(3); GetHist(nameofhistogram + head + stop) -> SetLineWidth(3); GetHist(nameofhistogram + head + ttjets) -> SetFillColor(kBlue); GetHist(nameofhistogram + head + gluino) -> SetFillColor(kGreen); GetHist(nameofhistogram + head + stop) -> SetFillColor(kRed); GetHist(nameofhistogram + head + ttjets) -> SetFillStyle(3004); GetHist(nameofhistogram + head + gluino) -> SetFillStyle(3007); GetHist(nameofhistogram + head + stop) -> SetFillStyle(3005); //rebining //GetHist(nameofhistogram + TruthCorrection + DY_high) -> Rebin(rebin); //draw GetHist(nameofhistogram + head + ttjets) -> SetStats(0); GetHist(nameofhistogram + head + ttjets) -> Draw(); GetHist(nameofhistogram + head + gluino) -> Draw("same"); GetHist(nameofhistogram + head + stop) -> Draw("same"); GetHist(nameofhistogram + head + ttjets) -> GetXaxis() -> SetRangeUser(xmin, xmax); GetHist(nameofhistogram + head + ttjets) -> SetMinimum(1.); mappad[pad1] -> Update(); maplegend[legend] = new TLegend(0.6,0.7,0.9,0.9); maplegend[legend] -> AddEntry(GetHist(nameofhistogram + head + ttjets), "ttjets", "l"); maplegend[legend] -> AddEntry(GetHist(nameofhistogram + head + gluino), "gluino", "l"); maplegend[legend] -> AddEntry(GetHist(nameofhistogram + head + stop), "stop", "l"); maplegend[legend] -> SetFillColor(kWhite); maplegend[legend] -> SetLineColor(kBlack); maplegend[legend] -> SetBorderSize(1); maplegend[legend] -> SetFillStyle(1001); maplegend[legend] -> SetShadowColor(0); // 0 = transparent maplegend[legend] -> SetEntrySeparation(0.3); maplegend[legend] -> Draw("same"); mapcanvas[canvas] -> cd(); TString pdfname = "./pdfs/"; pdfname.Append(nameofhistogram); pdfname.Append(".pdf"); mapcanvas[canvas] -> SaveAs(pdfname); }
//_____________________________________________________________________________ Int_t ProofAux::GenerateTree(const char *fnt, Long64_t ent, TString &fn) { // Generate the main tree for the 'friends' tutorial; the tree is called // 'Tmain', has 'ent' entries and is saved to file 'fnt'. // The full file path is returned in 'fn'. // Return 0 on success, -1 on error. Int_t rc = -1; // Check the filename fn = fnt; if (fn.IsNull()) { Error("GenerateTree", "file name undefined!"); return rc; } TUrl uu(fn, kTRUE); if (!strcmp(uu.GetProtocol(), "file") && !fn.BeginsWith("/")) { // Local file with relative path: create under the data directory if (!gProofServ || !(gProofServ->GetDataDir()) || strlen(gProofServ->GetDataDir()) <= 0) { Error("GenerateTree", "data directory undefined!"); return rc; } // Insert data directory fn.Insert(0, TString::Format("%s/", gProofServ->GetDataDir())); // Make sure the directory exists TString dir = gSystem->DirName(fn); if (gSystem->AccessPathName(dir, kWritePermission)) { if (gSystem->mkdir(dir, kTRUE) != 0) { Error("GenerateTree", "problems creating directory %s to store the file", dir.Data()); return rc; } } } // Create the file TDirectory* savedir = gDirectory; TFile *f = new TFile(fn, "RECREATE"); if (!f || f->IsZombie()) { Error("GenerateTree", "problems opening file %s", fn.Data()); return rc; } savedir->cd(); rc = 0; // Create the tree TTree *T = new TTree("Tmain","Main tree for tutorial friends"); T->SetDirectory(f); Int_t Run = 1; T->Branch("Run",&Run,"Run/I"); Long64_t Event = 0; T->Branch("Event",&Event,"Event/L"); Float_t x = 0., y = 0., z = 0.; T->Branch("x",&x,"x/F"); T->Branch("y",&y,"y/F"); T->Branch("z",&z,"z/F"); TRandom r; for (Long64_t i = 0; i < ent; i++) { if (i > 0 && i%1000 == 0) Run++; Event = i; x = r.Gaus(10,1); y = r.Gaus(20,2); z = r.Landau(2,1); T->Fill(); } T->Print(); f->cd(); T->Write(); T->SetDirectory(0); f->Close(); delete f; delete T; // Notify success Info("GenerateTree", "file '%s' successfully created", fn.Data()); // Add to the list TString fds(fn); if (!strcmp(uu.GetProtocol(), "file")) { if (gSystem->Getenv("LOCALDATASERVER")) { if (strcmp(TUrl(gSystem->Getenv("LOCALDATASERVER"), kTRUE).GetProtocol(), "file")) fds.Insert(0, TString::Format("%s/", gSystem->Getenv("LOCALDATASERVER"))); } else { fds.Insert(0, TString::Format("root://%s/", gSystem->HostName())); } } fMainList->Add(new TObjString(fds)); // Done return rc; }
void makeMuDstQA(TString InputFileList, Int_t nFiles, Int_t nEvents, TString OutputDir ) { // Load libraries for CINT mode #ifdef __CINT__ gROOT -> Macro("loadMuDst.C"); #endif // List of member links in the chain StChain* chain = new StChain ; StMuDstMaker* muDstMaker = new StMuDstMaker(0,0,"",InputFileList,"MuDst",nFiles) ; // ---------------- modify here according to your QA purpose -------------------------- // Turn off everything but Primary tracks in order to speed up the analysis and eliminate IO muDstMaker -> SetStatus("*",0) ; // Turn off all branches muDstMaker -> SetStatus("MuEvent",1) ; // Turn on the Event data (esp. Event number) muDstMaker -> SetStatus("PrimaryVertices",1) ; // Turn on the primary track data muDstMaker -> SetStatus("PrimaryTracks",1) ; // Turn on the primary track data muDstMaker -> SetStatus("GlobalTracks",1) ; // Turn on the global track data muDstMaker -> SetStatus("CovGlobTrack",1); // to fix the refmult in Run14!!! muDstMaker -> SetStatus("BTofHeader",1) ; // Turn on the btof data muDstMaker -> SetDebug(0) ; // Turn off Debug information if ( nEvents == 0 ) nEvents = 10000000 ; // Take all events in nFiles if nEvents = 0 // ---------------- modify here according to your QA purpose -------------------------- //book histograms or trees if you need TString oFile(muDstMaker->GetFile()); TString oChopFile; int fileBeginIndex = oFile.Index("st_",0); oFile.Remove(0,fileBeginIndex); short indx1 = oFile.First('.'); short indx2 = oFile.Last('.'); if (indx1!=indx2) oFile.Remove(indx1+1,(indx2-indx1)); oChopFile=oFile; oFile.Insert(indx1+1,"moretags."); oFile.Prepend(OutputDir); oChopFile.Insert(indx1+1,"chopper."); oChopFile.ReplaceAll("root","txt"); oChopFile.Prepend(OutputDir); ofstream chop_output(oChopFile); TFile *tags_output = new TFile( oFile, "recreate" ) ; tags_output->cd(); //TH1F *hPhi = new TH1F("hPhi","Phi of proton",200,-TMath::Pi(),TMath::Pi()); //TH2F *hPhiFirstZ = new TH2F("hPhiFirstZ","Phi vs. FirstZ",200,-150,150,200,-TMath::Pi(),TMath::Pi()); //Prepare the output tree Int_t mRunId, mEvtId; Int_t mnRefMult, mngRefMult, mnTofMatch; Float_t mVX, mVY, mVZ; Float_t mVpdVz; Float_t mPVRank; TTree *mMoreTagsTree = new TTree("MoreTags","MoreTags"); mMoreTagsTree->Branch("RunId",&mRunId,"RunId/I"); mMoreTagsTree->Branch("EvtId",&mEvtId,"EvtId/I"); mMoreTagsTree->Branch("nRefMult",&mnRefMult,"nRefMult/I"); mMoreTagsTree->Branch("ngRefMult",&mngRefMult,"ngRefMult/I"); mMoreTagsTree->Branch("nTofMatch",&mnTofMatch,"nTofMatch/I"); mMoreTagsTree->Branch("VX",&mVX,"VX/F"); mMoreTagsTree->Branch("VY",&mVY,"VY/F"); mMoreTagsTree->Branch("VZ",&mVZ,"VZ/F"); mMoreTagsTree->Branch("VpdVz",&mVpdVz,"VpdVz/F"); mMoreTagsTree->Branch("PVRank",&mPVRank,"PVRank/F"); mMoreTagsTree->SetAutoSave(10000000); // ---------------- end of histogram and tree booking -------------------------------- // Loop over the links in the chain Int_t iInit = chain -> Init() ; if (iInit) chain->FatalErr(iInit,"on init"); // chain -> EventLoop(1,nEvents) ; //will output lots of useless debugging info. Int_t istat = 0, i = 1; while (i <= nEvents && istat != 2) { if(i%10==0)cout << endl << "== Event " << i << " start ==" << endl; chain->Clear(); istat = chain->Make(i); if (istat == 2) cout << "Last event processed. Status = " << istat << endl; if (istat == 3) cout << "Error event processed. Status = " << istat << endl; i++; if(istat != kStOK)continue; //skip those suspectible events // ---------------- modify here according to your QA purpose -------------------------- //let's do the QA here... //start with event cutting... //cout<<"In event #. "<<i-1<<" Maker status "<<istat<<endl; StMuDst* mMuDst = muDstMaker->muDst(); if(!mMuDst) { LOG_WARN << " No MuDst " << endm; continue; } StMuEvent* mMuEvent = mMuDst->event(); if(!mMuEvent) { LOG_WARN << " No MuEvent " << endm; continue; } //vzVpd StBTofHeader const* mBTofHeader = mMuDst->btofHeader(); Float_t vzVpd=-999; if (mBTofHeader) vzVpd = mBTofHeader->vpdVz(); /* //Run14 vertex selection ////////////////////////////////////// // select the right vertex using VPD ///////////////////////////////////// for(unsigned int i=0;i<mMuDst->numberOfPrimaryVertices();i++) { StMuPrimaryVertex *vtx = mMuDst->primaryVertex(i); if(!vtx) continue; Float_t vz = vtx->position().z(); if(fabs(vzVpd)<100 && fabs(vzVpd-vz)<3.) { mMuDst->setVertexIndex(i); break; } } ///////////////////////////////////// */ /* //Run16 vertex selection //////////////////////////////////////////////////////////////// if (fabs(vzVpd) < 200) { for (unsigned int iVtx = 0; iVtx < mMuDst->numberOfPrimaryVertices(); ++iVtx) { StMuPrimaryVertex* vtx = mMuDst->primaryVertex(iVtx); if (!vtx) continue; if (fabs(vzVpd - vtx->position().z()) < 3.) { mMuDst->setVertexIndex(iVtx); break; } } } //////////////////////////////////////////////////////////////// */ /* //Run15 pAu & Run16 dAu vertex selection int index = 0; const double mTpcVpdVzDiffCut = 6; if (mBTofHeader && fabs(vzVpd) < 200) { for (unsigned int iVtx = 0; iVtx < mMuDst->numberOfPrimaryVertices(); ++iVtx) { StMuPrimaryVertex* vtx = mMuDst->primaryVertex(iVtx); if (!vtx) continue; if (fabs(vzVpd - vtx->position().z()) < mTpcVpdVzDiffCut) { index = iVtx; break; } } } if(index>=0) mMuDst->setVertexIndex(index); */ mRunId = mMuEvent->runNumber(); mEvtId = mMuEvent->eventNumber(); mnRefMult = mMuEvent->refMult(); Int_t nTofMatPrTrack = 0; TObjArray* prtracks = muDstMaker->muDst()->primaryTracks() ; // Create a TObject array containing the global tracks TObjArrayIter GetPrTracks(prtracks) ; // Create an iterator to step through the tracks StMuTrack* prtrack ; // Pointer to a track while ( ( prtrack = (StMuTrack*)GetPrTracks.Next() ) ) // Main loop for Iterating over tracks { if(prtrack->btofPidTraits().matchFlag()) nTofMatPrTrack ++; } mnTofMatch = nTofMatPrTrack; mVX = mMuEvent->primaryVertexPosition().x(); mVY = mMuEvent->primaryVertexPosition().y(); mVZ = mMuEvent->primaryVertexPosition().z(); mVpdVz = vzVpd; if(mMuDst->primaryVertex())mPVRank = mMuDst->primaryVertex()->ranking(); else mPVRank = -1e9; Int_t nGlTrack = 0; TObjArray* gltracks = muDstMaker->muDst()->globalTracks() ; // Create a TObject array containing the global tracks TObjArrayIter GetGlTracks(gltracks) ; // Create an iterator to step through the tracks StMuTrack* gltrack ; // Pointer to a track while ( ( gltrack = (StMuTrack*)GetGlTracks.Next() ) ) // Main loop for Iterating over tracks { if(fabs(gltrack->eta())>=0.5)continue; if(gltrack->nHitsFit()<10)continue; if(gltrack->dca().mag()>=3.0)continue; nGlTrack++ ; } mngRefMult = nGlTrack; mMoreTagsTree->Fill(); //Event info (for debug) //cout<<"Run#: "<<mMuEvent->runNumber()<<endl; //cout<<"Evt#: "<<mMuEvent->eventNumber()<<endl; //cout<<muDstMaker->muDst()->currentVertexIndex()<<endl; //cout<<"refmult: "<<mMuEvent->refMult()<<endl; //Event cuts (NO EVENT CUTS TILL HERE!) //trigger if ( ! mMuEvent->triggerIdCollection().nominal().isTrigger(410008) && ! mMuEvent->triggerIdCollection().nominal().isTrigger(410005) ) continue; //Vz if ( fabs(mMuEvent->primaryVertexPosition().z()) > 30.0 ) continue ; //Vr //if ( mMuEvent->primaryVertexPosition().perp() > 100.0 ) continue ; //VF failed (for some old dataset) //if ( fabs(mMuEvent->primaryVertexPosition().x()) < 1e-5 && fabs(mMuEvent->primaryVertexPosition().y()) < 1e-5 && fabs(mMuEvent->primaryVertexPosition().z()) < 1e-5 ) continue; chop_output<<mRunId<<'\t'<<mEvtId<<endl; /* //fill Event QA histograms TObjArray* tracks = muDstMaker->muDst()->primaryTracks() ; TObjArrayIter GetTracks(tracks) ; StMuTrack* gtrack ; while ( ( gtrack = (StMuTrack*)GetTracks.Next() ) ) { //const StMuTrack * gtrack = track->globalTrack(); if(gtrack->nHits()<=15)continue; if(gtrack->flag()<=0)continue; if(abs(gtrack->charge())!=1) continue; if(gtrack->pt()>0.5) continue; if(fabs(gtrack->nSigmaProton())>2)continue; hPhi->Fill(gtrack->phi()); hPhiFirstZ->Fill(gtrack->firstPoint().z(),gtrack->phi()); } //end of the filling */ } if (nEvents > 1) chain -> Finish() ; if(tags_output!=NULL) tags_output -> Write() ; if(tags_output!=NULL) tags_output -> Close() ; //flush(tags_output); delete tags_output; chop_output.close(); // Cleanup delete chain ; }
void TSelectionClass::saveHistos() { cout<<"save Histo: "<<hFiducialCutSilicon->GetTitle()<<endl; TString name = hFiducialCutSilicon->GetName(); name.Insert(0,"c"); TCanvas *c1= fiducialCuts->getAllFiducialCutsCanvas(hFiducialCutSilicon); c1->SetName(name); histSaver->SaveCanvas(c1); delete c1; c1 = 0; delete hFiducialCutSilicon; name = hFiducialCutSiliconDiamondHit->GetName(); name.Insert(0,"c"); c1 = fiducialCuts->getAllFiducialCutsCanvas(hFiducialCutSiliconDiamondHit,true); c1->SetName(name); histSaver->SaveCanvas(c1); delete c1; c1=0; delete hFiducialCutSiliconDiamondHit; name = "c"; name.Append(hFiducialCutSiliconOneAndOnlyOneDiamondHit->GetName()); c1= fiducialCuts->getAllFiducialCutsCanvas(hFiducialCutSiliconOneAndOnlyOneDiamondHit,true); c1->SetName(name); histSaver->SaveCanvas(c1); delete c1; c1=0; delete hFiducialCutSiliconOneAndOnlyOneDiamondHit; name = "c"; name.Append(hSelectedEvents->GetName()); c1 = fiducialCuts->getAllFiducialCutsCanvas(hSelectedEvents,true); c1->SetName(name); histSaver->SaveCanvas(c1); delete c1; c1=0; delete hSelectedEvents; map<Int_t,TH2F*>::iterator it; for (it = mapFiducialCutSiliconDiamondHitSamePattern.begin(); it!=mapFiducialCutSiliconDiamondHitSamePattern.end(); it++){ TH2F* histo = (*it).second; name = histo->GetName(); name.Replace(0,1,"c"); c1 = fiducialCuts->getAllFiducialCutsCanvas(histo,true); c1->SetName(name); histSaver->SaveCanvas(c1); delete c1; c1=0; delete histo; } hAnalysisFraction->Scale(.1); hAnalysisFraction->SetStats(false); // hAnalysisFraction->GetYaxis()->SetRangeUser(0,100); histSaver->SaveHistogram(hAnalysisFraction); delete hAnalysisFraction; histSaver->SaveHistogram(hDiamondPatternFiducialPattern); histSaver->SaveHistogram(hDiamondPatternFiducialPatternNoMapping); name = "stackPatternMapping"; hDiamondPatternFiducialPattern->SetLineColor(kGreen); hDiamondPatternFiducialPatternNoMapping->SetLineColor(kRed); THStack *stack = new THStack(name,name); stack->Add(hDiamondPatternFiducialPattern); stack->Add(hDiamondPatternFiducialPatternNoMapping); stack->Draw(); if(stack->GetXaxis()) stack->GetXaxis()->SetTitle("pattern no."); if(stack->GetYaxis()) stack->GetYaxis()->SetTitle("number of entries #"); histSaver->SaveStack(stack,"hist",true); if(stack) delete stack; histSaver->SaveHistogram(pDiamondPatternFiducialPatternProfile); if(hDiamondPatternFiducialPatternNoMapping) delete hDiamondPatternFiducialPatternNoMapping; if(hDiamondPatternFiducialPattern) delete hDiamondPatternFiducialPattern; if (pDiamondPatternFiducialPatternProfile) delete pDiamondPatternFiducialPatternProfile; }