//****************************************************************** //A little script to normalize three histograms using user input //of file names and histogram names created with myAnalysis.cxx //By Marshall Rogers, Columbia University, Nevis Laboratories 2010 //mar2194@columbia.edu //Version 2.2 //UPDATES: //Now allows for the special case where some of the histograms //might have two histograms with the same number of counts. //****************************************************************** #include void normplus22() { char file1[50]; fputs("Enter the first file name: ", stdout); if ( fgets(file1, 50, stdin) != NULL ) { char *newline = strchr(file1, '\n'); /* search for newline character */ if ( newline != NULL ) { *newline = '\0'; /* overwrite trailing newline */ } printf("First File = \"%s\"\n", file1); } char file2[50]; fputs("Enter the second file name: ", stdout); if ( fgets(file2, 50, stdin) != NULL ) { char *newline = strchr(file2, '\n'); /* search for newline character */ if ( newline != NULL ) { *newline = '\0'; /* overwrite trailing newline */ } printf("Second File = \"%s\"\n", file2); } char file3[50]; fputs("Enter the third file name: ", stdout); if ( fgets(file3, 50, stdin) != NULL ) { char *newline = strchr(file3, '\n'); /* search for newline character */ if ( newline != NULL ) { *newline = '\0'; /* overwrite trailing newline */ } printf("Third File = \"%s\"\n", file3); } char histo[50]; fputs("Enter the variable to plot: ", stdout); if ( fgets(histo, 50, stdin) != NULL ) { char *newline = strchr(histo, '\n'); /* search for newline character */ if ( newline != NULL ) { *newline = '\0'; /* overwrite trailing newline */ // if (histo="reta") // { // histo= new char("elLooseLooseNS_reta"); // } // fgets(histo, 50, "elLooseLooseNS_reta"); // } } printf("Your Variable = \"%s\"\n", histo); } TFile *f1=new TFile(file1); TH1F *h1=f1->Get(histo); //h1->SetLineColor(4); int n1=h1->GetEntries(); TFile *f2=new TFile(file2); TH1F *h2=f2->Get(histo); //h2->SetLineColor(2); int n2=h2->GetEntries(); TFile *f3=new TFile(file3); TH1F *h3=f3->Get(histo); //h3->SetLineColor(6); int n3=h3->GetEntries(); cout << n1<<" "<=n3 && n1>=n2 && n3>n2) { h1->SetLineColor(1); h3->SetLineColor(2); h2->SetLineColor(9); // h1->Scale(n1/n2); h2->Scale(n1/n2); h3->Scale(n1/n3); h2->Draw(); h3->Draw("sames"); h1->Draw("sames"); cout << "if4" << endl; } if(n1>=n3 && n1>=n2 && n2>=n3) { h1->SetLineColor(1); h2->SetLineColor(2); h3->SetLineColor(9); // h1->Scale(n1/n2); h2->Scale(n1/n2); h3->Scale(n1/n3); h3->Draw(); h2->Draw("sames"); h1->Draw("sames"); cout << "ifHEY" << endl; } cout << "Hey1" << endl; //End of n1 Scaling and color setting if(n2>=n3 && n2>n1 && n1>=n3) { h2->SetLineColor(1); h1->SetLineColor(2); h3->SetLineColor(9); h1->Scale(n2/n1); // h2->Scale(n1/n2); h3->Scale(n2/n3); h3->Draw(); h1->Draw("sames"); h2->Draw("sames"); cout << "if4" << endl; } cout << "Hey2" << endl; if(n2>=n3 && n2>n1 && n3>n1) { h2->SetLineColor(1); h3->SetLineColor(2); h1->SetLineColor(9); h1->Scale(n2/n1); // h2->Scale(n1/n2); h3->Scale(n2/n3); h1->Draw(); h3->Draw("sames"); h2->Draw("sames"); cout << "if4" << endl; } cout << "Hey3" << endl; //End of n2 scaling and color setting if(n3>n2 && n3>n1 && n2>n1) { h3->SetLineColor(1); h2->SetLineColor(2); h1->SetLineColor(9); h1->Scale(n3/n1); h2->Scale(n3/n2); //h3->Scale(n2/n3); h1->Draw(); h2->Draw("sames"); h3->Draw("sames"); cout << "if4" << endl; } cout << "Hey4" << endl; if(n3>n2 && n3>n1 && n1>=n2) { h3->SetLineColor(1); h1->SetLineColor(2); h2->SetLineColor(9); h1->Scale(n3/n1); h2->Scale(n3/n2); //h3->Scale(n2/n3); h2->Draw(); h1->Draw("sames"); h3->Draw("sames"); cout << "if4" << endl; } cout << "Hey5" << endl; //End of n3 scaling and color setting }