nsRDFPropertyTestNode::nsRDFPropertyTestNode(TestNode* aParent, nsXULTemplateQueryProcessorRDF* aProcessor, nsIRDFResource* aSource, nsIRDFResource* aProperty, nsIAtom* aTargetVariable) : nsRDFTestNode(aParent), mProcessor(aProcessor), mSourceVariable(0), mSource(aSource), mProperty(aProperty), mTargetVariable(aTargetVariable), mTarget(nullptr) { #ifdef PR_LOGGING if (PR_LOG_TEST(gXULTemplateLog, PR_LOG_DEBUG)) { const char* source = "(null)"; if (aSource) aSource->GetValueConst(&source); const char* prop = "(null)"; if (aProperty) aProperty->GetValueConst(&prop); nsAutoString tvar(NS_LITERAL_STRING("(none)")); if (mTargetVariable) mTargetVariable->ToString(tvar); PR_LOG(gXULTemplateLog, PR_LOG_DEBUG, ("nsRDFPropertyTestNode[%p]: parent=%p source=%s property=%s target=%s", this, aParent, source, prop, NS_ConvertUTF16toUTF8(tvar).get())); } #endif }
void compareDataMC( vector<TChain*> chmc , vector<char*> labels , TChain* chdata , char* var , TCut sel , TCut weight , int nbins , float xmin , float xmax , char* xtitle , bool overlayData , bool residual , bool drawLegend , bool log , char* flavor ){ TPad* fullpad = new TPad(); TPad* plotpad = new TPad(); TPad* respad = new TPad(); if( residual ){ fullpad = new TPad("fullpad","fullpad",0,0,1,1); fullpad->Draw(); fullpad->cd(); plotpad = new TPad("plotpad","plotpad",0,0,1,0.8); plotpad->Draw(); plotpad->cd(); if( log ) plotpad->SetLogy(); } else{ if( log ) gPad->SetLogy(); } TString tvar(var); tvar.ReplaceAll("()",""); tvar.ReplaceAll(".",""); const char* myvar = tvar; cout << "Plotting var " << myvar << " flavor " << flavor << endl; int colors[]={6,2,7,4,5,8,9,15,12}; int sigcolors[]={4,1,7,4,5,8,9,15,12}; int isigmc = 0; assert( chmc.size() == labels.size() ); const unsigned int nmc = chmc.size(); THStack* mcstack = new THStack("mcstack","mcstack"); TH1F* mctothist = new TH1F(); TH1F* smtothist = new TH1F(); TH1F* mchist[nmc]; TH1F* datahist = new TH1F(Form("%s_datahist_%s",myvar,flavor),Form("%s_datahist_%s",myvar,flavor),nbins,xmin,xmax); vector<TH1F*> sighist; float trigeff = 1.0; //if ( TString(flavor).Contains("ee") ) trigeff = 1.00; //else if( TString(flavor).Contains("mm") ) trigeff = 0.90; //else if( TString(flavor).Contains("em") ) trigeff = 0.95; //else if( TString(flavor).Contains("all") ) trigeff = 0.95; TCut trigweight(Form("%.2f",trigeff)); for( unsigned int imc = 0 ; imc < nmc ; imc++ ){ //for( int imc = nmc-1 ; imc > -1 ; imc-- ){ bool isSignal = TString( labels.at(imc) ).Contains("T2"); mchist[imc] = new TH1F(Form("%s_mc_%i_%s",myvar,imc,flavor),Form("%s_mc_%i_%s",myvar,imc,flavor),nbins,xmin,xmax); mchist[imc]->Sumw2(); chmc.at(imc)->Draw(Form("TMath::Min(%s,%f)>>%s_mc_%i_%s",var,xmax-0.01,myvar,imc,flavor),sel*weight*trigweight); if( isSignal ){ mchist[imc]->SetFillColor( 0 ); //mchist[imc]->SetLineStyle(2); mchist[imc]->SetLineWidth(2); mchist[imc]->SetLineColor( sigcolors[isigmc++] ); if( TString( labels.at(imc) ).Contains("X5") ){ mchist[imc]->Scale(5); cout << "Scaling signal MC by 5" << endl; } if( TString( labels.at(imc) ).Contains("X6") ){ mchist[imc]->Scale(6); cout << "Scaling signal MC by 6" << endl; } if( TString( labels.at(imc) ).Contains("X10") ){ mchist[imc]->Scale(10); cout << "Scaling signal MC by 10" << endl; } }else{ mchist[imc]->SetLineWidth(1); mchist[imc]->SetFillColor( colors[imc] ); mchist[imc]->SetLineColor( 1 ); } //mcstack->Add( mchist[imc] ); if( !isSignal ){ mcstack->Add( mchist[imc] ); if( imc == 0 ){ mctothist = (TH1F*) mchist[imc]->Clone(); smtothist = (TH1F*) mchist[imc]->Clone(); } else{ mctothist->Add(mchist[imc]); smtothist->Add(mchist[imc]); } } else{ mctothist->Add(mchist[imc]); sighist.push_back( mchist[imc] ); } cout << "MC yield " << labels[imc] << " " << Form("%.2f",mchist[imc]->Integral()) << endl; } chdata->Draw(Form("TMath::Min(%s,%f)>>%s_datahist_%s",var,xmax-0.01,myvar,flavor),sel); if( overlayData ){ float max = datahist->GetMaximum() + datahist->GetBinError(datahist->GetMaximumBin()); if( mctothist->GetMaximum() > max ) max = mctothist->GetMaximum(); if( log ) datahist->SetMaximum( 15 * max ); else datahist->SetMaximum( 1.4 * max ); datahist->GetXaxis()->SetTitle(xtitle); datahist->Draw("E1"); mcstack->Draw("samehist"); for( unsigned int isig = 0 ; isig < sighist.size() ; isig++ ){ sighist.at(isig)->Add(smtothist); sighist.at(isig)->Draw("samehist"); } datahist->Draw("sameE1"); datahist->Draw("sameaxis"); if(!log) datahist->GetYaxis()->SetRangeUser(0.,1.4*max); } else{ float max = mctothist->GetMaximum(); if( log ) mctothist->SetMaximum( 15 * max ); else mctothist->SetMaximum( 1.4 * max ); mctothist->SetLineColor(0); mctothist->SetFillColor(0); mctothist->GetXaxis()->SetTitle(xtitle); mctothist->Draw("hist"); mcstack->Draw("samehist"); for( unsigned int isig = 0 ; isig < sighist.size() ; isig++ ){ sighist.at(isig)->Add(smtothist); sighist.at(isig)->Draw("samehist"); } mctothist->Draw("sameaxis"); } if( drawLegend ){ TLegend* myleg = getLegend( chmc , labels , overlayData ); myleg->Draw(); } TLatex *text = new TLatex(); text->SetNDC(); text->SetTextSize(0.04); text->DrawLatex(0.2,0.88,"CMS Preliminary"); //text->DrawLatex(0.2,0.83,"0.98 fb^{-1} at #sqrt{s} = 7 TeV"); text->DrawLatex(0.2,0.83,"#sqrt{s} = 7 TeV, #scale[0.6]{#int}Ldt = 1.0 fb^{-1}"); if ( TString(flavor).Contains("e") ) text->DrawLatex(0.2,0.78,"e-channel"); else if( TString(flavor).Contains("m") ) text->DrawLatex(0.2,0.78,"#mu-channel"); else if( TString(flavor).Contains("all") ) text->DrawLatex(0.2,0.78,"e/#mu-channel"); if( residual ){ fullpad->cd(); respad = new TPad("respad","respad",0,0.8,1,1); respad->Draw(); respad->cd(); //gPad->SetGridy(); TH1F* ratio = (TH1F*) datahist->Clone(Form("%s_ratio",datahist->GetName())); ratio->Divide(smtothist); ratio->GetYaxis()->SetTitleOffset(0.3); ratio->GetYaxis()->SetTitleSize(0.2); ratio->GetYaxis()->SetNdivisions(5); ratio->GetYaxis()->SetLabelSize(0.2); ratio->GetYaxis()->SetRangeUser(0.5,1.5); ratio->GetYaxis()->SetTitle("data/SM "); ratio->GetXaxis()->SetLabelSize(0); ratio->GetXaxis()->SetTitleSize(0); ratio->SetMarkerSize(1); ratio->Draw(); TLine line; line.SetLineWidth(1); line.DrawLine(datahist->GetXaxis()->GetXmin(),1,datahist->GetXaxis()->GetXmax(),1); } }
int main() { // The number that the variable "x" will point to double_complex x; // Creates a variable named "x" and which value will be x CVar xvar ( "x" , &x ); // Asks for a fomula depending on the variable x, e.g. "sin 2x" char s[500]=""; printf("Enter a formula depending on the variable x:\n"); gets(s); // Creates an operation with this formula. The operation depends on one // variable, which is xvar ; the third argument is an array of pointers // to variables; the previous argument is its size CVar* vararray[1]; vararray[0]=&xvar; COperation op ( s, 1, vararray ); // Affects (indirectly) a value to xvar x=3; // Printfs the value of the formula for x=3; printf("%s = %s for x=3\n\n", op.Expr(), PrettyPrint(op.Val()) ); // Creates a function name which can be used in later functions to refer to the operation op(x) CFunction f (op, &xvar); f.SetName("f"); // Creates a second variable named y, and a formula depending on both x and y double_complex y; CVar yvar ( "y" , &y ); CVar* vararray2[2]; // table of variables containing the adresses of xvar and yvar vararray2[0]=&xvar; vararray2[1]=&yvar; // Asks for a formula using x, y and the already-defined function f, e.g. x+f(3y) printf("Enter a formula using x, y and the function f(x): x -> %s that you just entered, e.g. x+f(3y) :\n", op.Expr()); gets(s); CFunction* funcarray[1]; funcarray[0]=&f; COperation op2 ( (char*)s , 2 , vararray2 , 1, funcarray ); // vararray2 is a CVar* array with two elements // funcarray is a CFunction* array with one element y=5; printf("Value for x=3, y=5 : %s\n", PrettyPrint(op2.Val()) ); // Turns the last expression into a function of x and y CFunction g(op2, 2, vararray2); g.SetName("g"); // Here is another way to do it double_complex z,t; CVar zvar("z", &z), tvar("t", &t); COperation op3,zop,top; zop=zvar; top=tvar; // constructs, from a variable, the operation returning its value op3=g( (zop+top, top^2) ); // Ready-to-use ; needs two pairs of ( ) // Now op3 contains the operation op2 with x replaced with z+t, and y replaced with t^2 z=5;t=7; printf("\nLet g be the function g : x,y -> %s\n", op2.Expr()); printf("Value of %s for z=5,t=7:\n %s\n", op3.Expr(), PrettyPrint(op3.Val()) ); COperation dopdt=op3.Diff(tvar); // Computes the derivative of op3 w.r.t t printf("Value of d/dt (g(z+t,t^2)) = %s for z=5,t=7:\n %s\n", dopdt.Expr(), PrettyPrint(dopdt.Val()) ); COperation dopdtbar=op3.DiffConj(tvar); // Computes the derivative of op3 w.r.t the conjugate of t printf("Value of d/dtbar (g(z+t,t^2)) = %s for z=5,t=7:\n %s\n", dopdtbar.Expr(), PrettyPrint(dopdtbar.Val()) ); return 0; }
void compareDataMC( vector<TChain*> chmc , vector<char*> labels , TChain* chdata , char* var , TCut sel , TCut weight , int nbins , float xmin , float xmax , char* xtitle , bool overlayData , bool residual , bool drawLegend , bool log , char* flavor ){ TPad* fullpad = new TPad(); TPad* plotpad = new TPad(); TPad* respad = new TPad(); if( residual ){ fullpad = new TPad("fullpad","fullpad",0,0,1,1); fullpad->Draw(); fullpad->cd(); plotpad = new TPad("plotpad","plotpad",0,0,1,0.8); plotpad->Draw(); plotpad->cd(); if( log ) plotpad->SetLogy(); } else{ if( log ) gPad->SetLogy(); } TString tvar(var); tvar.ReplaceAll("()",""); tvar.ReplaceAll(".",""); const char* myvar = tvar; cout << "Plotting var " << myvar << " flavor " << flavor << endl; //int colors[]={6,2,7,4,5,8,9,15,12}; int colors[]={kBlue-6,kRed+2,7,5,5,8,9,15,12}; assert( chmc.size() == labels.size() ); const unsigned int nmc = chmc.size(); THStack* mcstack = new THStack("mcstack","mcstack"); TH1F* mctothist = new TH1F(); TH1F* mchist[nmc]; TH1F* datahist = new TH1F(Form("%s_datahist_%s",myvar,flavor),Form("%s_datahist_%s",myvar,flavor),nbins,xmin,xmax); float trigeff = 1.0; //if ( TString(flavor).Contains("ee") ) trigeff = 1.00; //else if( TString(flavor).Contains("mm") ) trigeff = 0.90; //else if( TString(flavor).Contains("em") ) trigeff = 0.95; //else if( TString(flavor).Contains("all") ) trigeff = 0.95; if ( TString(flavor).Contains("ee") ) sel+="leptype==0"; else if( TString(flavor).Contains("mm") ) sel+="leptype==1"; else if( TString(flavor).Contains("em") ) sel+="leptype==2"; //else if( TString(flavor).Contains("all") ) TCut trigweight(Form("%.2f",trigeff)); for( unsigned int imc = 0 ; imc < nmc ; imc++ ){ //for( int imc = nmc-1 ; imc > -1 ; imc-- ){ mchist[imc] = new TH1F(Form("%s_mc_%i_%s",myvar,imc,flavor),Form("%s_mc_%i_%s",myvar,imc,flavor),nbins,xmin,xmax); mchist[imc]->Sumw2(); chmc.at(imc)->Draw(Form("TMath::Min(%s,%f)>>%s_mc_%i_%s",var,xmax-0.01,myvar,imc,flavor),sel*weight*trigweight); if( TString( labels.at(imc) ).Contains("LM") || TString( labels.at(imc) ).Contains("T2tt") ){ mchist[imc]->SetFillColor( 0 ); mchist[imc]->SetLineStyle(2); }else{ mchist[imc]->SetFillColor( colors[imc] ); } // if( strcmp(labels[imc],"ttfake") == 0 || strcmp(labels[imc],"wjets") == 0 ){ // cout << "Scaling " << labels[imc] << " by 3.8" << endl; // mchist[imc]->Scale(3.8); // } mcstack->Add( mchist[imc] ); if( imc == 0 ) mctothist = (TH1F*) mchist[imc]->Clone(); else mctothist->Add(mchist[imc]); cout << "MC yield " << labels[imc] << " " << Form("%.2f",mchist[imc]->Integral()) << endl; } chdata->Draw(Form("TMath::Min(%s,%f)>>%s_datahist_%s",var,xmax-0.01,myvar,flavor),sel); if( overlayData ){ float max = datahist->GetMaximum() + datahist->GetBinError(datahist->GetMaximumBin()); if( mctothist->GetMaximum() > max ) max = mctothist->GetMaximum(); if( log ) datahist->SetMaximum( 15 * max ); else datahist->SetMaximum( 1.4 * max ); datahist->GetXaxis()->SetTitle(xtitle); datahist->Draw("E1"); mcstack->Draw("samehist"); datahist->Draw("sameE1"); datahist->Draw("sameaxis"); if(!log) datahist->GetYaxis()->SetRangeUser(0.,1.4*max); cout << "data yield " << datahist->Integral() << endl; } else{ mctothist->GetXaxis()->SetTitle(xtitle); mctothist->Draw(); mcstack->Draw("same"); mctothist->Draw("sameaxis"); } if( drawLegend ){ TLegend* myleg = getLegend( chmc , labels , overlayData ); myleg->Draw(); } TLatex *text = new TLatex(); text->SetNDC(); text->SetTextSize(0.05); text->DrawLatex(0.2,0.88,"CMS Preliminary"); //text->DrawLatex(0.2,0.83,"0.98 fb^{-1} at #sqrt{s} = 7 TeV"); text->DrawLatex(0.2,0.83,"#sqrt{s} = 7 TeV, #scale[0.6]{#int}Ldt = 4.3 fb^{-1}"); if ( TString(flavor).Contains("ee") ) text->DrawLatex(0.2,0.78,"Events with ee"); else if( TString(flavor).Contains("mm") ) text->DrawLatex(0.2,0.78,"Events with #mu#mu"); else if( TString(flavor).Contains("em") ) text->DrawLatex(0.2,0.78,"Events with e#mu"); else if( TString(flavor).Contains("all") ) text->DrawLatex(0.2,0.78,"Events with ee/#mu#mu/e#mu"); if( residual ){ fullpad->cd(); respad = new TPad("respad","respad",0,0.8,1,1); respad->Draw(); respad->cd(); gPad->SetGridy(); TH1F* ratio = (TH1F*) datahist->Clone(Form("%s_ratio",datahist->GetName())); ratio->Divide(mctothist); ratio->GetYaxis()->SetTitleOffset(0.3); ratio->GetYaxis()->SetTitleSize(0.2); ratio->GetYaxis()->SetNdivisions(5); ratio->GetYaxis()->SetLabelSize(0.2); //ratio->GetYaxis()->SetRangeUser(0.5,1.5); ratio->GetYaxis()->SetRangeUser(0.,2.); ratio->GetYaxis()->SetTitle("data/MC "); ratio->GetXaxis()->SetLabelSize(0); ratio->GetXaxis()->SetTitleSize(0); ratio->SetMarkerSize(0.7); ratio->Draw(); TLine line; line.SetLineWidth(1); line.DrawLine(datahist->GetXaxis()->GetXmin(),1,datahist->GetXaxis()->GetXmax(),1); } }