void DrawCurrHistogram() {


  TObjString* filename = histograms->At(currPos);
  TString f(fFileDir);
  f.Append("/");
  f.Append(filename->GetString());

  TFile* file = new TFile(f, "read");
  // check file
  if (!file) return;
  if (file->IsZombie()) return;

  TH2D* hist = (TH2D*) gFile->Get(fHistName);

  if (!hist) continue;
  if (!hist->GetEntries()) continue;

  // copy the histogram to the root memory
  //gROOT->cd();
  //TH2D* hist_copy = new TH2D(*hist);
  TString t(filename->GetString());
  t.Append(": ");
  t.Append(hist->GetTitle());
  hist->SetTitle(t);
  //histograms->Add(hist_copy);
  //TH1* h = histograms->At(currPos);
  c->cd(1);
  //gPad->cd();

  hist->Draw("colz");
  // file can be closed now...
  //file->Close();

  if(currHist != 0) {
    PreserveAxis(currHist->GetXaxis(), hist->GetXaxis());
    PreserveAxis(currHist->GetYaxis(), hist->GetYaxis());
  }

  if(currFile != 0)
    currFile->Close();
  currFile = file;
  currHist = hist;
  //gPad->Modified();
  //gPad->Update();

  //cout << "Added histogram from " << filename << endl;

}
Beispiel #2
0
void HISTndist(){
	TSystemDirectory dir(".",".");
	TList *files = dir.GetListOfFiles();
	TFile *outfile = new TFile("ndist.root","RECREATE");
	TH2D *ndist = new TH2D("ndist", "Neutron Distribution", 301, 0.001, 0.601, 1201, -0.499, 1.901);
	ifstream infile;
	Int_t xi, yi, hits;
	Double_t x, y, prob;
	for (Int_t i = 0; ; i++){
		TObject *f;
		if (f = files->At(i)){
			TString filename = f->GetName();
			if (filename.EndsWith("ndist.out") && TString(filename(0,8)).IsDigit()){
				cout << "Adding " << filename << endl;
				infile.open(filename.Data());
				infile.ignore(9999, '\n');
				while (infile){
					infile >> xi >> yi >> x >> y >> prob >> hits;
					if (infile && (hits != 0)) ndist->Fill(x,y,prob);
				}
				infile.close();
				cout << "Entries: " << ndist->GetEntries() << endl;
			}
		}
Beispiel #3
0
void addn2() {

  // open existing f1:

  char* fn[99];
  int ni;

  // SR90 maps, mod D003

  ni = -1;
  ni++; fn[ni] = "SR90-map-00a.root";
  ni++; fn[ni] = "SR90-map-00b.root";
  ni++; fn[ni] = "SR90-map-01a.root";
  ni++; fn[ni] = "SR90-map-01b.root";
  ni++; fn[ni] = "SR90-map-02.root";
  ni++; fn[ni] = "SR90-map-03.root";
  ni++; fn[ni] = "SR90-map-05a.root";
  ni++; fn[ni] = "SR90-map-05b.root";
  ni++; fn[ni] = "SR90-map-07a.root";
  ni++; fn[ni] = "SR90-map-07b.root";
  ni++; fn[ni] = "SR90-map-07c.root";
  ni++; fn[ni] = "SR90-map-07d.root";

  // direct X-rays 9.4.2014 module D0003

  ni = -1;
  ni++; fn[ni] = "X-ray-20-modtd40000.root";
  ni++; fn[ni] = "X-ray-20-vthr60-modtd1000.root";
  ni++; fn[ni] = "X-ray-27-vthr60-modtd1000.root";
  ni++; fn[ni] = "X-ray-35-modtd40000.root";
  ni++; fn[ni] = "X-ray-35-vthr60-close-modtd65000.root";
  ni++; fn[ni] = "X-ray-35-vthr60-midpos-0p1mA-modtd10000.root";
  ni++; fn[ni] = "X-ray-35-vthr60-midpos-halfcur-modtd40000.root";
  ni++; fn[ni] = "X-ray-35-vthr60-modtd40000.root";

  int nmax = ni;

  TFile f1(fn[0]);

  if( f1.IsZombie() ) {
    cout << "Error opening " << fn[0] << endl;
    return;
  }
  cout << "opened " << fn[0] << endl;

  //--------------------------------------------------------------------
  // create f0:

  TFile f0("fileA.root", "RECREATE");
  cout << "created ";
  gDirectory->pwd();

  /*
  TFile options:  
  NEW or CREATE   create a new file and open it for writing,
                  if the file already exists the file is
                  not opened.
  RECREATE        create a new file, if the file already
                  exists it will be overwritten.
  UPDATE          open an existing file for writing.
                  if no file exists, it is created.
  READ            open an existing file for reading (default).
  NET             used by derived remote file access
                  classes, not a user callable option
  WEB             used by derived remote http access
                  class, not a user callable option
  "" (default), READ is assumed.
  */

  //--------------------------------------------------------------------
  // copy f1 to f0:

  f1.cd();

  cout << "keys:\n";
  f1.GetListOfKeys()->Print();

  cout << "pwd: ";
  f1.pwd();

  cout << "ls: \n";
  f1.ls();

  // f1 has sub-dir:

  cout << "First: " << f1.GetListOfKeys()->First()->GetName() << endl;
  cout << "First: " << f1.GetListOfKeys()->First()->ClassName() << endl;
  char* dir1 = f1.GetListOfKeys()->First()->GetName();
  cout << "cd to " << dir1 << endl;
  f1.cd( dir1 );
  cout << "we are in ";
  gDirectory->pwd();

  gDirectory->ReadAll(); // load histos

  TList * lst = gDirectory->GetList();
  cout << lst->GetName() << endl;
  cout << lst->GetTitle() << endl;
  cout << "size    " << lst->GetSize() << endl;
  cout << "entries " << lst->GetEntries() << endl;
  cout << "last    " << lst->LastIndex() << endl;

  TIterator *iter = lst->MakeIterator();
  int ii = 0;
  TObject *obj;
  TH1D *h;
  TH1D *h0;
  TH2D *H;
  TH2D *H0;

  while( obj = iter->Next() ){
    ii++;
    cout << setw(4) << ii << ": ";
    cout << obj->ClassName() << " ";
    cout << obj->InheritsFrom("TH1D") << " ";
    cout << obj->GetName() << " \"";
    cout << obj->GetTitle() << "\"";
    cout << endl;
    //    if( obj->ClassName() == "TH1D" ){
    if( obj->InheritsFrom("TH1D") ){
      h = (TH1D*) obj;
      cout << "       1D";
      cout << h->GetNbinsX() << " bins, ";
      cout << h->GetEntries() << " entries, ";
      cout << h->GetSumOfWeights() << " inside, ";
      cout << h->GetBinContent(0) << " under, ";
      cout << h->GetBinContent(h->GetNbinsX()+1) << " over";
      cout << endl;

      f0.cd(); // output file

      //      TH1D* h0 = (TH1D*) h->Clone();
      h0 = h; // copy
      h0->Write(); // write to file f0
      
      f1.cd(); // back to file 1 for the loop
    }
    else{

      if( obj->InheritsFrom("TH2D") ){

	H = (TH2D*) obj;
	cout << "       2D";
	cout << H->GetNbinsX() << " bins, ";
	cout << H->GetEntries() << " entries, ";
	cout << H->GetSumOfWeights() << " inside, ";
	cout << H->GetBinContent(0) << " under, ";
	cout << H->GetBinContent(H->GetNbinsX()+1) << " over";
	cout << endl;
	
	f0.cd(); // output file
	
	H0 = H; // copy
	H0->Write(); // write to file f0
	
	f1.cd(); // back to file 1 for the loop
      }
      else cout << "other class " << obj->ClassName() << endl;
    }
  }
  cout << "copied " << ii << endl;
  cout << "f1 " << f1.GetName() << " close = " << f1.Close() << endl;
    
  f0.cd();
  cout << "we are in ";
  gDirectory->pwd();

  cout << "f0 " << f0.GetName() << " size  = " << f0.GetSize() << endl;

  cout << "f0 " << f0.GetName() << " write = " << f0.Write() << endl;

  cout << "f0 " << f0.GetName() << " size  = " << f0.GetSize() << endl;

  cout << "f0 " << f0.GetName() << " close = " << f0.Close() << endl;

  f0.Delete();

  //--------------------------------------------------------------------
  // list of files 2:

  bool lAB = true;

  for( int nn = 1; nn <= nmax; ++nn ){

    cout << "\n\n";
    cout << "loop " << nn << ": fn = " << fn[nn] << endl;
    cout << "lAB = " << lAB << endl;

    if( lAB ) { // A+2 -> B
      char* fn3 = "fileA.root";
      char* fn4 = "fileB.root";
    }
    else{ // B+2 -> A
      char* fn3 = "fileB.root";
      char* fn4 = "fileA.root";
    }

    // create f4:

    TFile f4( fn4, "recreate" );
    if( f4.IsZombie() ) {
      cout << "Error creating f4\n";
      return;
    }
    cout << "created f4   = " << f4.GetName() << endl;

    // re-open as f3:

    TFile f3( fn3 );
    if( f3.IsZombie() ) {
      cout << "Error opening f3\n";
      return;
    }
    cout << "re-opened f3 = " << f3.GetName() << endl;

    lAB = !lAB;
    cout << "lAB = " << lAB << " for next loop\n";

    cout << "f4 = " << f4.GetName() << endl;
    cout << "f3 = " << f3.GetName() << endl;

    f3.cd();
    gDirectory->ReadAll(); // load histos into f3 memory

    //    cout << "f3 list size = " << gDirectory->GetList()->GetSize() << endl;
    cout << "f3 list size = " << gDirectory->GetList()->GetSize() << endl;

    TFile f2(fn[nn]);
    //    TFile *f2 = new TFile(fn[nn]);

    if( f2.IsZombie() ) {
    //    if( f2 == NULL ) {
      cout << "Error opening " << fn[nn] << endl;
      return;
    }
    cout << "opened " << fn[nn] << endl;

    // f2 has sub-dir:

    f2.cd( f2.GetListOfKeys()->First()->GetName() );
    cout << "we are in ";
    gDirectory->pwd();

    gDirectory->ReadAll(); // load histos into f2 memory

    // loop over f2:

    cout << "f2 list size = " << gDirectory->GetList()->GetSize() << endl;

    int jj = 0;
    TObject *ob2;
    TH1D *h2;
    TH1D *h3;
    TH2D *H2;
    TH2D *H3;

    TIterator *ite2 = gDirectory->GetList()->MakeIterator();

    while( ob2 = ite2->Next() ){

      jj++;

      //      if( jj > 9 ) continue;

      cout << jj << ". ";
      cout << "ob2 is ";
      cout << ob2->GetName() << " ";
      cout << ob2->ClassName() << " ";
      cout << ob2->GetTitle();
      cout << endl;

      if( ob2->InheritsFrom("TH1D") ) {

	h2 = (TH1D*) ob2;
	cout << "h2 " << h2->GetName() << "  " << h2->GetNbinsX() << " bins\n";
	cout << "h2 " << h2->GetName() << "  " << h2->GetEntries() << " entries\n";
	char* hnm2 = h2->GetName();

	// search in f3:

	cout << "search for " << hnm2 << " in f3\n";
	f3.cd();
	cout << "we are in ";
	gDirectory->pwd();
	
	h3 = (TH1D*) gDirectory->GetList()->FindObject(hnm2);
	if( h3 == NULL ) {
	  cout << "h3 is null\n" ;
	  continue;
	}
	
	cout << "found h3 = ";
	cout << h3->GetName() << "  ";
	cout << h3->ClassName() << "  ";
	cout << h3->GetTitle();
	cout << endl;
	cout << "h3  " << h3->GetName() << "  " << h3->GetNbinsX() << " bins\n";
	cout << "h3  " << h3->GetName() << "  " << h3->GetEntries() << " entries\n";

	// add:

	f4.cd();
	cout << "we are in ";
	gDirectory->pwd();
	//TH1D h4 = *h3 + *h2;
	TH1D* h4 = (TH1D*) h3->Clone();
	h4->Add(h2);
	
	cout << "h4  " << h4->GetEntries() << " entries\n";
	cout << "h4  ";
	cout << h4->GetName() << " ";
	cout << h4->ClassName() << " ";
	cout << h4->GetTitle();
	cout << endl;
	cout << "h4 dir " << h4->GetDirectory()->GetName() << endl;
	cout << "f4 size " << f4.GetSize() << endl;

	// back to f2 for next iter:

	f2.cd( f2.GetListOfKeys()->First()->GetName() );

      }//1D

      if( ob2->InheritsFrom("TH2D") ) {

	H2 = (TH2D*) ob2;
	cout << "H2 " << H2->GetName() << "  " << H2->GetNbinsX() << " bins\n";
	cout << "H2 " << H2->GetName() << "  " << H2->GetEntries() << " entries\n";
	char* Hnm2 = H2->GetName();

	// search in f3:

	cout << "search for " << Hnm2 << " in f3\n";
	f3.cd();
	cout << "we are in ";
	gDirectory->pwd();
	
	H3 = (TH2D*) gDirectory->GetList()->FindObject(Hnm2);
	if( H3 == NULL ) {
	  cout << "H3 is null\n" ;
	  continue;
	}
	
	cout << "found H3 = ";
	cout << H3->GetName() << "  ";
	cout << H3->ClassName() << "  ";
	cout << H3->GetTitle();
	cout << endl;
	cout << "H3  " << H3->GetName() << "  " << H3->GetNbinsX() << " bins\n";
	cout << "H3  " << H3->GetName() << "  " << H3->GetEntries() << " entries\n";

	// add:

	f4.cd();
	cout << "we are in ";
	gDirectory->pwd();

	TH2D* H4 = (TH2D*) H3->Clone();
	H4->Add(H2);
	
	cout << "H4  " << H4->GetEntries() << " entries\n";
	cout << "H4  ";
	cout << H4->GetName() << " ";
	cout << H4->ClassName() << " ";
	cout << H4->GetTitle();
	cout << endl;
	cout << "H4 dir " << H4->GetDirectory()->GetName() << endl;
	cout << "f4 size " << f4.GetSize() << endl;

	// back to f2 for next iter:

	f2.cd( f2.GetListOfKeys()->First()->GetName() );
      }//2D

    } //while

    cout << "processed " << jj << endl;
    cout << "f4 " << f4.GetName() << " size " << f4.GetSize() << endl;

    //  cout << "f4 map:\n";
    //  f4.Map();

    cout << "f4 " << f4.GetName() << " write = " << f4.Write() << endl;

    cout << "f4 " << f4.GetName() << " size  = " << f4.GetSize() << endl;
    
  }// loop over files 2

  cout << endl;
  cout << "combined " << nmax + 1 << " files\n";
  cout << "Final file is " << f4.GetName() << endl;

  f2.Close();
  f3.Close();
  f4.Close();

}
Beispiel #4
0
// infilename - root file with relevant histograms
// system - PP,APAP,PP
// status - Pass,Fail
// rWrite - 0-no,1-png,2-eps
// rPerformance - 0-no,1-yes (ALICE logo etc.)
// bin: 0 - all, 1- 0:5, 2- 5:10, etc
void drawPID(const char* infilename, const char* system, const char* status, Int_t rWrite, Int_t rPerformance, Int_t bin)
{


    TFile *f = new TFile(infilename, "read");

    // TPC dEdx
    TH2D* TPCdEdx =(TH2D*)f->Get(Form("TPCdEdxcut%s1%stpcM%i",status, system,0));

    if (!bin) {
        int minMultBin = 0;
        int maxMultBin = 6; // 8
    }
    else {
        int minMultBin = bin-1;
        int maxMultBin = bin; // 8
    }

    double EvMultall = 0;

    for (int i = minMultBin; i < maxMultBin; i++) {

        TH2D* TPCdEdxN =(TH2D*)f->Get(Form("TPCdEdxcut%s1%stpcM%i",status,system,i));
        TPCdEdx->Add(TPCdEdxN);

        cout << i << " " << TPCdEdxN->GetEntries() << endl;

        //delete hEvMult;
    }

    TCanvas *c2 = new TCanvas("TPC dEdx", "TPC dEdx");
    c2->SetGridx();
    c2->SetGridy();
    c2->SetFillColor(10);
    c2->SetRightMargin(1.9);
    c2->SetLogz();

    TPCdEdx->GetXaxis()->SetTitle("#it{p}_{T} (GeV/#it{c})");
    TPCdEdx->GetXaxis()->SetRangeUser(0.0,6.0);
    TPCdEdx->GetYaxis()->SetTitle("dE/dx");
    TPCdEdx->GetZaxis()->SetLabelSize(0.03);
    TPCdEdx->Draw("colz");

// 	double a1 = -3000.0; double b1 =  1280.0;
// 	double a2 = -312.5;  double b2 =  312.5;
// 	double a3 = -200.0;  double b3 =  240.0;

//    TF1 *fa1 = new TF1("fa1","-1800*x+940",0.3,0.4);
//   fa1->Draw("same");
//   TF1 *fa2 = new TF1("fa2","-500.0*x+420.0",0.4,0.6);
//   fa2->Draw("same");
// TF1 *fa3 = new TF1("fa3","-216.7*x+250.0",0.6,0.9);
//    fa3->Draw("same");
// TF1 *fa4 = new TF1("fa4","-566.7*x+570.0",0.6,0.75);
//    fa4->Draw("same");
// TF1 *fa5 = new TF1("fa5","-2076.92*x+1476.15",0.47,0.6);
//    fa5->Draw("same");
//   cout<<TPCdEdx->GetNbinsX()<<endl;
//   cout<<TPCdEdx->GetNbinsY()<<endl;
//   for (int ii=0;ii<TPCdEdx->GetNbinsX();ii++){

//     for (int jj=0;jj<TPCdEdx->GetNbinsY();jj++){

//       cout<<"binX: "<<ii<<endl;
//       cout<<"binY: "<<jj<<endl;
//       cout<<"val: "<<TPCdEdx->GetBinContent(ii,jj)<<endl;
//     }
//   }

// 	TH1D *py = TPCdEdx->ProjectionY("py", 230, 232); // where firstYbin = 0 and lastYbin = 9
// 	TCanvas *c22 = new TCanvas("TPC2", "TPC2");
// 	py->Draw();

    postprocess(c2,Form("TPCdEdx%s",status),rWrite,rPerformance,system);

    // TPC Nsigma
    TH2D* TPCNsigma =(TH2D*)f->Get(Form("TPCNSigmacut%s1%stpcM%i",status,system,0));

    // int minMultBin = 0;
    // int maxMultBin = 2;
    double EvMultall = 0;

    for(int i = minMultBin; i<maxMultBin; i++) {
        //all
        TH2D* TPCNsigmaN =(TH2D*)f->Get(Form("TPCNSigmacut%s1%stpcM%i",status,system,i));
        TPCNsigma->Add(TPCNsigmaN);
        //delete hEvMult;
    }

    TCanvas *c3 = new TCanvas("TPC Nsigma", "TPC Nsigma");
    c3->SetGridx();
    c3->SetGridy();
    c3->SetFillColor(10);
    c3->SetRightMargin(1.7);
    c3->SetLogz();

    TPCNsigma->GetXaxis()->SetTitle("#it{p}_{T} (GeV/#it{c})");
    TPCNsigma->GetXaxis()->SetRangeUser(0.0,5.0);
    TPCNsigma->GetYaxis()->SetTitle("number of sigmas");
    TPCNsigma->GetZaxis()->SetLabelSize(0.03);

    TPCNsigma->Draw("colz");

    postprocess(c3,Form("TPCNsigma%s",status),rWrite,rPerformance,system);

    // TOF Nsigma
    TH2D* TOFNsigma =(TH2D*)f->Get(Form("TOFNSigmacut%s1%stpcM%i",status,system,0));

    // int minMultBin = 1;
    // int maxMultBin = 1;
    double EvMultall = 0;

    for(int i = minMultBin; i<maxMultBin; i++) {
        //all
        TH2D* TOFNsigmaN =(TH2D*)f->Get(Form("TOFNSigmacut%s1%stpcM%i",status,system,i));
        TOFNsigma->Add(TOFNsigmaN);
        //delete hEvMult;
    }

    TCanvas *c4 = new TCanvas("TOF Nsigma", "TOF Nsigma");
    c4->SetGridx();
    c4->SetGridy();
    c4->SetFillColor(10);
    c4->SetRightMargin(1.7);
    c4->SetLogz();

    TOFNsigma->GetXaxis()->SetTitle("#it{p}_{T} (GeV/#it{c})");
    TOFNsigma->GetXaxis()->SetRangeUser(0.0,5.0);
    TOFNsigma->GetYaxis()->SetTitle("number of sigmas from TOF");
    TOFNsigma->GetZaxis()->SetLabelSize(0.03);
    TOFNsigma->Draw("colz");

    postprocess(c4,Form("TOFNsigma%s",status),rWrite,rPerformance,system);

    // TOF time
    TH2D* TOFTime =(TH2D*)f->Get(Form("TOFTimecut%s1%stpcM%i",status,system,0));

    // int minMultBin = 1;
    // int maxMultBin = 1;
    double EvMultall = 0;

    for(int i = minMultBin; i<maxMultBin; i++) {
        //all
        TH2D* TOFTimeN =(TH2D*)f->Get(Form("TOFTimecut%s1%stpcM%i",status,system,i));
        TOFTime->Add(TOFTimeN);
        //delete hEvMult;
    }

    TCanvas *c5 = new TCanvas("TOF Time", "TOF Time");
    c5->SetGridx();
    c5->SetGridy();
    c5->SetFillColor(10);
    c5->SetRightMargin(1.7);
    c5->SetLogz();

    TOFTime->GetXaxis()->SetTitle("#it{p}_{T} (GeV/#it{c})");
    TOFTime->GetYaxis()->SetTitle("GetTOFsignal - GetIntegratedTimes");
    TOFTime->GetYaxis()->SetTitleOffset(1.3);
    TOFTime->GetXaxis()->SetRangeUser(0,5);
    TOFTime->GetYaxis()->SetRangeUser(-7000,7000);
    //  TOFTime->GetZaxis()->SetLabelSize(0.03);
    TOFTime->Draw("colz");

    postprocess(c5,Form("TOFTime%s",status),rWrite,rPerformance,system);


    // TPC & TOF Nsigma
    TH2D* TPCTOFNsigma =(TH2D*)f->Get(Form("TPCTOFNSigmacut%s1%stpcM%i",status,system,0));

    int minMultBin = 1;
    int maxMultBin = 1;
    double EvMultall = 0;

    for(int i = minMultBin; i<maxMultBin; i++) {
        //all
        TH2D* TPCTOFNsigmaN =(TH2D*)f->Get(Form("TPCTOFNSigmacut%s1%stpcM%i",status,system,i));
        TOFNsigma->Add(TOFNsigmaN);
        //delete hEvMult;
    }

    TCanvas *c6 = new TCanvas("TOF Nsigma", "TOF Nsigma");
    c6->SetGridx();
    c6->SetGridy();
    c6->SetFillColor(10);
    c6->SetRightMargin(1.7);
    c6->SetLogz();

    TPCTOFNsigma->GetXaxis()->SetTitle("#it{p}_{T} (GeV/#it{c})");
    TPCTOFNsigma->GetXaxis()->SetRangeUser(0.0,5.0);
    TPCTOFNsigma->GetYaxis()->SetTitle("#sqrt{#frac{n#sigma_{TPC} + n#sigma_{TOF}}{2}}");
    TPCTOFNsigma->GetZaxis()->SetLabelSize(0.03);
    TPCTOFNsigma->Draw("colz");

    postprocess(c6,Form("TPCTOFNsigma%s",status),rWrite,rPerformance,system);

}
Beispiel #5
0
/**
 * Loads a histogram from a ROOT-file, scales it, and either returns it as \c
 * returnedHistogram or adds it to \c returnedHistogram . The first if
 * \c returnedHistogram is \c NULL otherwise the latter.
 *
 * @param histogramName
 *                              name of the histogram.
 * @param inputFilename
 *                              name of the ROOT-file.
 * @param scale
 *                              scale factor for histogram.
 * @param returnedHistogram
 *                              the returned histogram (input, pass-by-reference does not work).
 * @param debug
 *                              switch on debug output, defaults to \c false
 *
 * @return
 *                              the returned histogram (output, pass-by-reference does not work).
 */
void
LoadHistogramTH2D(const TString& histogramName, const TString& inputFilename, double scale, TH2D*& returnedHistogram, bool debug = false)
{
// {{{
    TFile inputFile(inputFilename);
    if (!inputFile.IsOpen())
    {
        cerr << "Could not open '" << inputFilename << "' for reading." << endl;
    }
    else
    {
        TH2D* histogram = dynamic_cast<TH2D*>( inputFile.Get(histogramName) );
        if (!histogram)
        {
            cerr << "No histogram named '" << histogramName << "' in file '" << inputFilename << "'" << endl;
        }
        else
        {
            if (debug) cerr << inputFilename << " " << histogramName << " entries=" << histogram->GetEntries() << " integral=" << histogram->Integral() << " scale*integral=" << scale*histogram->Integral() << endl;
            histogram->Scale(scale);
            if (!returnedHistogram)
            {
                returnedHistogram = new TH2D(*histogram);
                returnedHistogram->SetDirectory(0); // otherwise "TFile inputFile" owns this returnedHistogram and deletes it when "TFile inputFile" goes out of scope
            }
            else
            {
                returnedHistogram->Add(histogram);
            }
        }
        inputFile.Close();
    }
// }}}
};
void combine_mistag_rates_2d( )
{

  const char * names [] = {
    "mistag_parameterization_qcd_230.root", 
    "mistag_parameterization_qcd_300.root", 
    "mistag_parameterization_qcd_380.root", 
    "mistag_parameterization_qcd_470.root", 
    "mistag_parameterization_qcd_600.root", 
    "mistag_parameterization_qcd_800.root", 
    "mistag_parameterization_qcd_1000.root", 
    "mistag_parameterization_qcd_1400.root", 
    "mistag_parameterization_qcd_1800.root", 
    "mistag_parameterization_qcd_2200.root", 
    "mistag_parameterization_qcd_2600.root", 
    "mistag_parameterization_qcd_3000.root", 
    "mistag_parameterization_qcd_3500.root"
  };


  double xs[] = {
    10623.2,
    2634.94,
    722.099,
    240.983,
    62.4923,
    9.42062,
    2.34357,
    0.1568550,
    0.013811,
    0.00129608,
    0.00011404,
    0.0000084318,
    0.00000018146
  };


  int nevents[] = {
    54000,
    54000,
    51840,
    27648,
    28620,
    20880,
    24640,
    27744,
    22848,
    22560,
    22800,
    20880,
    34320
  };


  const char * filetitles[] = {
    "QCD Dijets, #hat{pt} = 230-300",
    "QCD Dijets, #hat{pt} = 300-380",
    "QCD Dijets, #hat{pt} = 380-470",
    "QCD Dijets, #hat{pt} = 470-600",
    "QCD Dijets, #hat{pt} = 600-800",
    "QCD Dijets, #hat{pt} = 800-1000",
    "QCD Dijets, #hat{pt} = 1000-1400",
    "QCD Dijets, #hat{pt} = 1400-1800",
    "QCD Dijets, #hat{pt} = 1800-2200",
    "QCD Dijets, #hat{pt} = 2200-2600",
    "QCD Dijets, #hat{pt} = 2600-3000",
    "QCD Dijets, #hat{pt} = 3000-3500",
    "QCD Dijets, #hat{pt} = 3500-Inf"
  };


  static const int N = sizeof( names ) / sizeof ( const char * );

//   palette(N);

  TFile * output = new TFile("mistag_parameterization2d.root", "RECREATE");
  TH2D * numerator_sum = 0;
  TH2D * denominator_sum = 0;

  for ( int i = 0; i < N; ++i ) {
    TFile * f = new TFile(names[i]);
    TH2D * numerator = (TH2D*) f->Get("numerator2d");
    TH2D * denominator = (TH2D*) f->Get("denominator2d");

    char buff[1000];
    sprintf(buff, "%30s & %6.0f & %6.0f ", names[i], denominator->GetEntries(), numerator->GetEntries() );
    cout << buff << endl;

    if ( i == 0 ) {
      output->cd();
      numerator_sum = new TH2D(*numerator);
      denominator_sum = new TH2D(*denominator);
    } else {
      numerator_sum->Add( numerator );
      denominator_sum->Add( denominator );
    }
  }




  TH2D * mistag_rate = new TH2D(*numerator_sum);
  mistag_rate->SetName("mistag_rate");
  mistag_rate->SetTitle("Fake Tag Parameterization");
  
  mistag_rate->Divide( numerator_sum, denominator_sum, 1.0, 1.0, "b");

  gStyle->SetOptStat(000000);

  TCanvas * c = new TCanvas("c", "c", 600, 800);


  c->Divide(1,3);
  c->cd(1);
  numerator_sum->SetMinimum(1e-15);
  numerator_sum->Draw("colz");
  gPad->SetLogz();
  gPad->SetRightMargin(0.2);
  c->cd(2);
  denominator_sum->SetMinimum(1e-15);
  denominator_sum->Draw("colz");
  gPad->SetLogz();
  gPad->SetRightMargin(0.2);
  c->cd(3);
  mistag_rate->Draw("colz");
  gPad->SetRightMargin(0.2);
  

  output->cd();
  numerator_sum->Write();
  denominator_sum->Write();
  mistag_rate->Write();

  c->Print("mistag_param2d.gif", "gif");
  c->Print("mistag_param2d.eps", "eps");

}
Beispiel #7
0
//=============================================================================
// GetStartPosition
// is_vertex must be "true" when the vert is muon vertex
// is_vertex must be "false" when the vert is for reference
//=============================================================================
bool HTBlob::GetStartPosition( Minerva::IDBlob *idBlob, Gaudi::XYZPoint vert, bool is_vertex ) const
{

    debug() << " HTBlob::GetStartPosition " << endmsg;

    TH2D *hU = new TH2D ( "hU", "hU", 480,4510,9990,127,-1075,1075);
    TH2D *hV = new TH2D ( "hV", "hV", 480,4510,9990,127,-1075,1075);

    if ( is_vertex ){	
        hU->Fill( vert.z(), m_mathTool->calcUfromXY(vert.x(), vert.y()), 20 );
        hV->Fill( vert.z(), m_mathTool->calcVfromXY(vert.x(), vert.y()), 20);
    }

    SmartRefVector<Minerva::IDCluster> idClusters = idBlob->clusters();
    SmartRefVector<Minerva::IDCluster>::iterator itClus = idClusters.begin();
    Gaudi::XYZPoint pos;

    double Dx = 0.0;
    double Dz = 0.0;
    double distance = 0.0;

    double vt_x = -9999;
    double vt_u;
    double vt_v;
    double vt_z = -9999;

    double vtX = -9999;
    double vtY = -9999;
    double vtZ = -9999;


    double dis_min_x = 10000;
    double xu[2] = {0.0};
    double xv[2] = {0.0};
    double zu[2] = {0.0};
    double zv[2] = {0.0}; // to NC Pi0 events, there is no muon vertex

    int countu = 0;
    int countv = 0; // to NC Pi0 events, there is no muon vertex

    for ( ; itClus != idClusters.end(); itClus++ ){

        Dx = (*itClus)->position() - vert.x(); 
        Dz = (*itClus)->z() - vert.z();// to avoid 0

        if( (*itClus)->view()== Minerva::IDCluster::X ) {
            distance = sqrt( pow(Dx,2) + pow(Dz,2) );
            if (distance <= dis_min_x  ) {
                dis_min_x = distance;
                vt_x = (*itClus)->position();
                vt_z = (*itClus)->z();
            }
        }

        if( (*itClus)->view()== Minerva::IDCluster::U ){
            debug() <<  " StartPoint U view, pe " << (*itClus)->pe() << "; z = " << (*itClus)->z()
                << "; coord " << (*itClus)->position() << endmsg;
            Dx = (*itClus)->position() - m_mathTool->calcUfromXY(vert.x(),vert.y());
            distance = sqrt( pow(Dx,2) + pow(Dz,2) );
            if ( is_vertex ) {
                hU->Fill( (*itClus)->z()-12,(*itClus)->tpos1(), (*itClus)->pe()/distance );
                hU->Fill( (*itClus)->z()+12,(*itClus)->tpos2(), (*itClus)->pe()/distance );
            }
            hU->Fill( (*itClus)->z(),(*itClus)->position(), (*itClus)->pe()/distance );
            if ( countu < 2 ){
                zu[countu] = (*itClus)->z();
                xu[countu] = (*itClus)->position();
                countu++;
            }
        }

        if( (*itClus)->view()== Minerva::IDCluster::V ){
            debug() <<  " StartPoint V view, pe " << (*itClus)->pe() << "; z = " << (*itClus)->z()
                << "; coord " << (*itClus)->position() << endmsg;
            Dx = (*itClus)->position() -  m_mathTool->calcVfromXY(vert.x(),vert.y());
            distance = sqrt( pow(Dx,2) + pow(Dz,2) );
            if ( is_vertex ){
                hV->Fill( (*itClus)->z()-12,(*itClus)->tpos1(), (*itClus)->pe()/distance );
                hV->Fill( (*itClus)->z()+12,(*itClus)->tpos2(), (*itClus)->pe()/distance );
            }
            hV->Fill( (*itClus)->z(),(*itClus)->position(), (*itClus)->pe()/distance );
            if ( countv < 2 ){
                zv[countu] = (*itClus)->z();
                xv[countu] = (*itClus)->position();
                countv++;
            }
        }
    }

    TF1 *fU, *fV;

    double slopeu = -9999;
    double slopev = -9999;
    double bu = -9999;
    double bv = -9999;

    bool goodFit_U = false;
    bool goodFit_V = false;
    if ( hU->GetEntries() > 3 ){
        hU->Fit("pol1","Q0");
        fU = hU->GetFunction("pol1");
        bu = fU->GetParameter(0);
        slopeu = fU->GetParameter(1);
        goodFit_U = true;

        delete fU;
    }
    else if ( hU->GetEntries() == 2 ){ // to deal with 2 clusters on NCPi0
        if ( zu[0] > zu[1] ){
            slopeu = (xu[0] - xu[1]) / (zu[0] - zu[1]);
            bu = xu[1] - zu[1]*slopeu;
            goodFit_U = true;
        }
        else if (zu[0] < zu[1] ) {
            slopeu = (xu[1] - xu[0]) / (zu[1] - zu[0]);
            bu = xu[0] - zu[0]*slopeu;
            goodFit_U = true;
        }
    }

    if ( hV->GetEntries() > 3 ){
        hV->Fit("pol1","Q0");
        fV = hV->GetFunction("pol1");
        bv = fV->GetParameter(0);
        slopev = fV->GetParameter(1);
        goodFit_V = true;

        delete fV;
    }
    else if ( hV->GetEntries() == 2 ){ // to deal with 2 clusters on NCPi0
        if ( zv[0] > zv[1] ){
            slopev = (xv[0] - xv[1]) / (zv[0] - zv[1]);
            bv = xv[1] - zv[1]*slopeu;
            goodFit_V = true;
        }
        else if (zu[1] < zu[0] ) { /* Trung: why zu instead of zv? */
            slopev = (xv[1] - xv[0]) / (zv[1] - zv[0]);
            bv = xv[0] - zv[0]*slopev;
            goodFit_V = true;
        }
    }

    vtX = vt_x;
    vtZ = vt_z;
    debug() << " Startpoint, slope u " << slopeu << " slope v" << slopev << endmsg;
    if ( goodFit_U && goodFit_V ){ 	     //3D blobs
        vt_u = slopeu*vt_z + bu;
        vt_v = slopev*vt_z + bv;
        vtY = m_mathTool->calcYfromUV(vt_u,vt_v);
    }
    else if ( goodFit_U ) {                  //2D blobs 
        vt_u = slopeu*vt_z + bu;
        vtY = (vt_x*.5 - vt_u)*2/sqrt(3);    //calcYfromXU?
    }
    else if ( goodFit_V ) { 	             //2D blobs 
        vt_v = slopev*vt_z + bv;
        vtY = (vt_v - vt_x*.5)*2/sqrt(3);    //calcYfromXV?
    }

    pos.SetX(vtX); pos.SetY(vtY); pos.SetZ(vtZ);

    idBlob->setStartPoint(pos);

    debug() << " Setting StarPoint " << pos << " Blob" << idBlob << endmsg;

    delete hU;
    delete hV;

    if (goodFit_U || goodFit_V) return true;

    return false;

}
void toyV2Generator(const unsigned int numberEvents=300,
		    const unsigned int particlesPerEvent=500,	
		    const bool useFlow=true,
		    const float v2Factor=0.20,
		    const bool writeHistogramFile=true,
		    const bool readHistogramFile=false,
		    const unsigned int nBinsOneD=100,
		    const unsigned int nBinsX=40,
		    const unsigned int nBinsY=40,
		    const unsigned int iBinXMinPlot=3,
		    const unsigned int iBinYMinPlot=3,
		    const unsigned int iBinXMaxPlot=37,
		    const unsigned int iBinYMaxPlot=37) {

  if(readHistogramFile && writeHistogramFile) {
    cerr << "\n Cannot do a simultaneous read and write of the histogram file";
    cerr << endl;
    return;
  }

  const unsigned int particlesPerEventLessOne = particlesPerEvent - 1;
  float particleEta[particlesPerEvent];
  float particlePhi[particlesPerEvent];
  float particlePhiLab[particlesPerEvent];

  float particleEtaPreviousEvent[particlesPerEvent];
  float particlePhiLabPreviousEvent[particlesPerEvent];

  //
  // Function to provide azimuthal angles according to a v2 distribution
  //
  char flowFunction[200];
  sprintf(flowFunction, "1.0 + %4.2f*2.0*cos(2.0*x)", v2Factor);
  TF1 *v2Flow = new TF1("v2Flow", flowFunction, 0.0, 2.0*TMath::Pi());

  const float highEtaBin = 3.0;
  const float lowEtaBin = -3.0;
  const float highPhiBin = 1.5*TMath::Pi();
  const float lowPhiBin = -0.5*TMath::Pi();

  float mixedEventWeight = float(particlesPerEvent)*float(particlesPerEvent - 1)/(2.0*float(particlesPerEvent*particlesPerEvent));

  //
  // Single particle range in eta will be half the maximum for deltaEta
  //
  const float diffEta = 0.5*(highEtaBin - lowEtaBin);

  TH1D *particlePhiHistogram = 0;
  TH1D *particlePhiLabHistogram = 0;
  TH1D *particleEtaHistogram = 0;

  TH1D *pairDeltaPhiHistogram = 0;
  TH1D *pairDeltaPhiHistogramMixed = 0;
  TH1D *pairDeltaPhiHistogramNormalized = 0;

  TH1D *pairDeltaEtaHistogram = 0;
  TH1D *pairDeltaEtaHistogramMixed = 0;
  TH1D *pairDeltaEtaHistogramNormalized = 0;

  TH2D *pairDeltaEtaDeltaPhiHistogram = 0;
  TH2D *pairDeltaEtaDeltaPhiHistogramMixed = 0;
  TH2D *pairDeltaEtaDeltaPhiHistogramNormalized = 0;

  if(!readHistogramFile) {

    particlePhiHistogram = new TH1D("particlePhiHistogram", "Particle azimuthal distribution in reaction plane", nBinsOneD, 0.0, 2.0*TMath::Pi());
    particlePhiHistogram->SetXTitle("Particle azimuthal angle #phi (radians)");
    particlePhiHistogram->SetYTitle("Counts per 0.063 radians bin");

    particlePhiLabHistogram = new TH1D("particlePhiLabHistogram", "Particle azimuthal distribution in lab frame", nBinsOneD, 0.0, 2.0*TMath::Pi());
    particlePhiLabHistogram->SetXTitle("Particle azimuthal angle #phi (radians)");
    particlePhiLabHistogram->SetYTitle("Counts per 0.063 radians bin");

    particleEtaHistogram = new TH1D("particleEtaHistogram", "Particle azimuthal distribution", nBinsOneD, lowEtaBin, highEtaBin);
    particleEtaHistogram->SetXTitle("Particle #eta");
    particleEtaHistogram->SetYTitle("Counts per 0.015 bin");

    pairDeltaPhiHistogram = new TH1D("pairDeltaPhiHistogram", "#Delta #phi pairs in lab frame", nBinsOneD, lowPhiBin, highPhiBin);
    pairDeltaPhiHistogram->SetXTitle("#Delta #phi (radians)");
    pairDeltaPhiHistogram->SetYTitle("Counts");

    pairDeltaPhiHistogramMixed = new TH1D("pairDeltaPhiHistogramMixed", "#Delta #phi pairs in lab frame, mixed-event", nBinsOneD, lowPhiBin, highPhiBin);
    pairDeltaPhiHistogramMixed->SetXTitle("#Delta #phi (radians)");
    pairDeltaPhiHistogramMixed->SetYTitle("Counts");

    pairDeltaPhiHistogramNormalized = new TH1D("pairDeltaPhiHistogramNormalized", "Normalized #Delta #phi pairs in lab frame", nBinsOneD, lowPhiBin, highPhiBin);
    pairDeltaPhiHistogramNormalized->SetXTitle("#Delta #phi (radians)");
    pairDeltaPhiHistogramNormalized->SetYTitle("Counts");

    pairDeltaEtaHistogram = new TH1D("pairDeltaEtaHistogram", "#Delta #eta Pairs, Same Event", nBinsOneD, lowEtaBin, highEtaBin);
    pairDeltaEtaHistogram->SetXTitle("#Delta #eta (radians)");
    pairDeltaEtaHistogram->SetYTitle("Counts");

    pairDeltaEtaHistogramMixed = new TH1D("pairDeltaEtaHistogramMixed", "#Delta #eta Pairs, Mixed Event", nBinsOneD, lowEtaBin, highEtaBin);
    pairDeltaEtaHistogramMixed->SetXTitle("#Delta #eta (radians)");
    pairDeltaEtaHistogramMixed->SetYTitle("Counts");

    pairDeltaEtaHistogramNormalized = new TH1D("pairDeltaEtaHistogramNormalized", "#Delta #eta Pairs, Normalized Event", nBinsOneD, lowEtaBin, highEtaBin);
    pairDeltaEtaHistogramNormalized->SetXTitle("#Delta #eta (radians)");
    pairDeltaEtaHistogramNormalized->SetYTitle("Counts");
    
    pairDeltaEtaDeltaPhiHistogram = new TH2D("pairDeltaEtaDeltaPhiHistogram", "Angular Correlation Pairs", nBinsX, lowEtaBin, highEtaBin, nBinsY, lowPhiBin, highPhiBin);
    pairDeltaEtaDeltaPhiHistogram->SetXTitle("#Delta #eta");
    pairDeltaEtaDeltaPhiHistogram->SetYTitle("#Delta #phi");

    pairDeltaEtaDeltaPhiHistogramMixed = new TH2D("pairDeltaEtaDeltaPhiHistogramMixed", "Angular Correlation Pairs", nBinsX, lowEtaBin, highEtaBin, nBinsY, lowPhiBin, highPhiBin);
    pairDeltaEtaDeltaPhiHistogramMixed->SetXTitle("#Delta #eta");
    pairDeltaEtaDeltaPhiHistogramMixed->SetYTitle("#Delta #phi");

    pairDeltaEtaDeltaPhiHistogramNormalized = new TH2D("pairDeltaEtaDeltaPhiHistogramNormalized", "Normalized Angular Correlation Pairs", nBinsX, lowEtaBin, highEtaBin, nBinsY, lowPhiBin, highPhiBin);
    pairDeltaEtaDeltaPhiHistogramNormalized->SetXTitle("#Delta #eta");
    pairDeltaEtaDeltaPhiHistogramNormalized->SetYTitle("#Delta #phi");

    //
    // Random number generator object
    //
    TRandom1 *particleKinematics = new TRandom1();
    particleKinematics->SetSeed(1);
		
    unsigned int numberEvents10 = numberEvents/10;

    for(unsigned int kEvent=0; kEvent<numberEvents; kEvent++) {
			
      if(kEvent>0 && kEvent%numberEvents10==0) {
	cout << "\n At kEvent = " << kEvent;
      }
			
      //
      // Randomize the reaction plane angle in the lab frame
      //
      float reactionPlaneAngleThisEvent = 2.0*(particleKinematics->Rndm())*TMath::Pi();
			
      //
      // Loop over particles per event
      //
      for(unsigned int kParticle=0; kParticle<particlesPerEvent; kParticle++) {
	particleEta[kParticle] = lowEtaBin + diffEta*(0.5 - particleKinematics->Rndm());
	if(useFlow) {
	  particlePhi[kParticle] = v2Flow->GetRandom();
	  if(particlePhi[kParticle] > 2.0*TMath::Pi())
	    particlePhi[kParticle] -= 2.0*TMath::Pi();

	  particlePhiLab[kParticle] =  particlePhi[kParticle] + reactionPlaneAngleThisEvent;
	  if(particlePhiLab[kParticle] > 2.0*TMath::Pi())
	    particlePhiLab[kParticle] -= 2.0*TMath::Pi();
	}
	else {
	  particlePhi[kParticle] = 2.0*(particleKinematics->Rndm())*TMath::Pi();
	  particlePhiLab[kParticle] =  particlePhi[kParticle];
	}
	particleEtaHistogram->Fill(particleEta[kParticle]);
	particlePhiHistogram->Fill(particlePhi[kParticle]);
 	particlePhiLabHistogram->Fill(particlePhiLab[kParticle]);

      } // loop over particles

      if(kEvent > 0) {
	//
	// Fill the pair histograms for the same event
	//
	for(unsigned int kParticle=0; kParticle<particlesPerEventLessOne; kParticle++) {
	  float phi1 = particlePhiLab[kParticle];
	  float eta1 = particleEta[kParticle];
	  unsigned int jParticleStart = kParticle + 1;
	  for(unsigned int jParticle=jParticleStart; jParticle<particlesPerEvent; jParticle++) {
	    float phiDelta = deltaPhi(phi1, particlePhiLab[jParticle]);

	    //
	    // Change the phiDelta range for plot purposes
	    //
	    if(phiDelta < -0.5*TMath::Pi())
	      phiDelta = TMath::Pi() + TMath::Pi() + phiDelta;

	    float etaDelta = eta1 - particleEta[jParticle];
	    pairDeltaPhiHistogram->Fill(phiDelta);
	    pairDeltaEtaHistogram->Fill(etaDelta, 0.5);
	    pairDeltaEtaHistogram->Fill(-etaDelta, 0.5);
	    pairDeltaEtaDeltaPhiHistogram->Fill(etaDelta, phiDelta, 0.5);
	    pairDeltaEtaDeltaPhiHistogram->Fill(-etaDelta, phiDelta, 0.5);
	  } // loop over second particle in same event pair

	} // loop over first particle in same event pair

	//
	// Fill the pair histograms for the mixed event
	//
	for(unsigned int kParticle=0; kParticle<particlesPerEvent; kParticle++) {
	  float phi1 = particlePhiLab[kParticle];
	  float eta1 = particleEta[kParticle];
	  for(unsigned int jParticle=0; jParticle<particlesPerEvent; jParticle++) {
	    float phiDelta = deltaPhi(phi1, particlePhiLabPreviousEvent[jParticle]);

	    //
	    // Change the phiDelta range for plot purposes
	    //
	    if(phiDelta < -0.5*TMath::Pi())
	      phiDelta = TMath::Pi() + TMath::Pi() + phiDelta;

	    pairDeltaPhiHistogramMixed->Fill(phiDelta, mixedEventWeight);
	    float etaDelta = eta1 - particleEtaPreviousEvent[jParticle];
	    pairDeltaEtaHistogramMixed->Fill(etaDelta,0.5);
	    pairDeltaEtaHistogramMixed->Fill(-etaDelta,0.5);
	    pairDeltaEtaDeltaPhiHistogramMixed->Fill(etaDelta, phiDelta, 0.5);
	    pairDeltaEtaDeltaPhiHistogramMixed->Fill(-etaDelta, phiDelta, 0.5);

	  } // loop over particle in previous event

	} // loop over particle in current event


      } // check on beyond the first event

      //
      // Move particles from current event to previous event arrays
      //
      for(unsigned int kParticle=0; kParticle<particlesPerEvent; kParticle++) {
	particlePhiLabPreviousEvent[kParticle] = particlePhiLab[kParticle];
	particleEtaPreviousEvent[kParticle] = particleEta[kParticle];
      }

    } // loop over events
    cout << "\n Finished NTUPLE scan" << endl;

    //
    // Normalize the delta-phi histograms with the mixed-event yields
    //
    float sumSameEventPhi1D = 0.0;
    float sumMixedEventPhi1D = 0.0;
    for(unsigned int iBinX=1; iBinX<nBinsOneD; iBinX++) {
      sumSameEventPhi1D += pairDeltaPhiHistogram->GetBinContent(iBinX);
      sumMixedEventPhi1D += pairDeltaPhiHistogramMixed->GetBinContent(iBinX);
    }
    if(sumSameEventPhi1D > 0.0 && sumMixedEventPhi1D > 0.0) {
      float normalizationFactor1D = sumMixedEventPhi1D/sumSameEventPhi1D;
      for(unsigned int iBinX=0; iBinX<nBinsOneD; iBinX++) {
	pairDeltaPhiHistogramNormalized->SetBinContent(iBinX,0.0);
	float sameEventContent = pairDeltaPhiHistogram->GetBinContent(iBinX);
	float mixedEventContent = pairDeltaPhiHistogramMixed->GetBinContent(iBinX);
	if(mixedEventContent > 0.0) {
	  float normalizedYield = normalizationFactor1D*sameEventContent/mixedEventContent;
	  pairDeltaPhiHistogramNormalized->SetBinContent(iBinX, normalizedYield);
	} // check for non-zero denominator
      } // loop over phi bins
    } // check for non-zero totals
		
    //
    // Normalize the delta-eta histograms with the mixed-event yields
    //
    float sumSameEvent1D = pairDeltaEtaHistogram->GetEntries();
    float sumMixedEvent1D = pairDeltaEtaHistogramMixed->GetEntries();
    if(sumSameEvent1D > 0.0 && sumMixedEvent1D > 0.0) {
      float normalizationFactor1D = sumMixedEvent1D/sumSameEvent1D;
      for(unsigned int iBinX=0; iBinX<nBinsOneD; iBinX++) {
	pairDeltaEtaHistogramNormalized->SetBinContent(iBinX,0.0);
	float sameEventContent = pairDeltaEtaHistogram->GetBinContent(iBinX);
	float mixedEventContent = pairDeltaEtaHistogramMixed->GetBinContent(iBinX);
	if(mixedEventContent > 0.0) {
	  float normalizedYield = normalizationFactor1D*sameEventContent/mixedEventContent;
	  pairDeltaEtaHistogramNormalized->SetBinContent(iBinX, normalizedYield);
	} // check for non-zero denominator
      } // loop over eta bins
    } // check for non-zero totals
		
    float sumSameEvent2D = pairDeltaEtaDeltaPhiHistogram->GetEntries();
    float sumMixedEvent2D = pairDeltaEtaDeltaPhiHistogramMixed->GetEntries();

    if(sumSameEvent2D > 0.0 && sumMixedEvent2D > 0.0) {
      float normalizationFactor2D = sumMixedEvent2D/sumSameEvent2D;
      for(unsigned int iBinX=0; iBinX<nBinsX; iBinX++) {
	for(unsigned int iBinY=0; iBinY<nBinsY; iBinY++) {
	  pairDeltaEtaDeltaPhiHistogramNormalized->SetBinContent(iBinX, iBinY, 0.0);
	  if(iBinX<iBinXMinPlot || iBinX>iBinXMaxPlot ||
	     iBinY<iBinYMinPlot || iBinY>iBinYMaxPlot)
	    continue;  // limit the fiducial area of the plot because of possible low statistics

	  float sameEventContent = pairDeltaEtaDeltaPhiHistogram->GetBinContent(iBinX, iBinY);
	  float mixedEventContent = pairDeltaEtaDeltaPhiHistogramMixed->GetBinContent(iBinX, iBinY);
	  if(mixedEventContent > 0.0) {
	    float normalizedYield = normalizationFactor2D*sameEventContent/mixedEventContent;
	    pairDeltaEtaDeltaPhiHistogramNormalized->SetBinContent(iBinX, iBinY, normalizedYield);
	  } // check for non-zero mixed event content
	} // loop over phi bins
      } // loop over eta bins
    } // check for non-zero total counts

  } // check on not reading histogram file

  if(readHistogramFile) {

    char inputFileName[200];
    sprintf(inputFileName, "toyV2Generator%dEvents%dParticlesPerEvent%4.2fV2.root", numberEvents, particlesPerEvent, v2Factor);
    TFile *toyV2GeneratorFile = new TFile(inputFileName);
		
    if(!toyV2GeneratorFile) {
      cerr << "\n Unable to find ROOT file " <<  inputFileName << endl;
      return;
    }

    cout << "\n Using input ROOT file " << inputFileName << endl;
		
    particlePhiHistogram = (TH1D*)toyV2GeneratorFile->Get("particlePhiHistogram");
    if(!particlePhiHistogram) {
      cerr << "\n Cannot find particlePhiHistogram" << endl;
      return;
    }

    particlePhiLabHistogram = (TH1D*)toyV2GeneratorFile->Get("particlePhiLabHistogram");
    if(!particlePhiLabHistogram) {
      cerr << "\n Cannot find particlePhiLabHistogram" << endl;
      return;
    }

    particleEtaHistogram = (TH1D*)toyV2GeneratorFile->Get("particleEtaHistogram");
    if(!particleEtaHistogram) {
      cerr << "\n Cannot find particleEtaHistogram" << endl;
      return;
    }
		
    pairDeltaPhiHistogram = (TH1D*)toyV2GeneratorFile->Get("pairDeltaPhiHistogram");
    if(!pairDeltaPhiHistogram) {
      cerr << "\n Cannot find pairDeltaPhiHistogram" << endl;
      return;
    }		

    pairDeltaPhiHistogramMixed = (TH1D*)toyV2GeneratorFile->Get("pairDeltaPhiHistogramMixed");
    if(!pairDeltaPhiHistogramMixed) {
      cerr << "\n Cannot find pairDeltaPhiHistogramMixed" << endl;
      return;
    }

    pairDeltaPhiHistogramNormalized = (TH1D*)toyV2GeneratorFile->Get("pairDeltaPhiHistogramNormalized");
    if(!pairDeltaPhiHistogramNormalized) {
      cerr << "\n Cannot find pairDeltaPhiHistogramNormalized" << endl;
      return;
    }

    pairDeltaEtaHistogram = (TH1D*)toyV2GeneratorFile->Get("pairDeltaEtaHistogram");
    if(!pairDeltaEtaHistogram) {
      cerr << "\n Cannot find pairDeltaEtaHistogram" << endl;
      return;
    }

    pairDeltaEtaHistogramMixed = (TH1D*)toyV2GeneratorFile->Get("pairDeltaEtaHistogramMixed");
    if(!pairDeltaEtaHistogramMixed) {
      cerr << "\n Cannot find pairDeltaEtaHistogramMixed" << endl;
      return;
    }

    pairDeltaEtaHistogramNormalized = (TH1D*)toyV2GeneratorFile->Get("pairDeltaEtaHistogramNormalized");
    if(!pairDeltaEtaHistogramNormalized) {
      cerr << "\n Cannot find pairDeltaEtaHistogramNormalized" << endl;
      return;
    }

    pairDeltaEtaDeltaPhiHistogram = (TH2D*)toyV2GeneratorFile->Get("pairDeltaEtaDeltaPhiHistogram");
    if(!pairDeltaEtaDeltaPhiHistogram) {
      cerr << "\n Cannot find pairDeltaEtaDeltaPhiHistogram" << endl;
      return;
    }

    pairDeltaEtaDeltaPhiHistogramMixed = (TH2D*)toyV2GeneratorFile->Get("pairDeltaEtaDeltaPhiHistogramMixed");
    if(!pairDeltaEtaDeltaPhiHistogramMixed) {
      cerr << "\n Cannot find pairDeltaEtaDeltaPhiHistogramMixed" << endl;
      return;
    }

    pairDeltaEtaDeltaPhiHistogramNormalized = (TH2D*)toyV2GeneratorFile->Get("pairDeltaEtaDeltaPhiHistogramNormalized");
    if(!pairDeltaEtaDeltaPhiHistogramNormalized) {
      cerr << "\n Cannot find pairDeltaEtaDeltaPhiHistogramNormalized" << endl;
      return;
    }

  } // check on readHistogramFile

  TCanvas *c1 = new TCanvas("c1", "Plotting Pair Events", 200, 10, 700, 500);
  //
  // Use ROOT's gStyle function to set up plot options
  //
  gStyle->SetOptStat(1110);
  gStyle->SetStatTextColor(kBlue);
  gStyle->SetFuncColor(kBlue);
  gStyle->SetFuncWidth(2);
  gStyle->SetOptFit(1111);
  gStyle->SetFitFormat("6.5g");
	
  c1->SetFillColor(kWhite);

  c1->Divide(2,2);

  c1->cd(1);
  
  if(useFlow) {
    particlePhiHistogram->SetStats(0);
    particlePhiHistogram->SetMinimum(0);
    float fMaximum = particlePhiHistogram->GetMaximum();
    int iMaximum = 1.5*fMaximum;
    particlePhiHistogram->SetMaximum(iMaximum);
		
    particlePhiHistogram->SetLineColor(4);
    particlePhiHistogram->Draw();
    particlePhiLabHistogram->SetLineColor(1);
    particlePhiLabHistogram->Draw("same");
		
    char labelBufferTitle[200];
    sprintf(labelBufferTitle, "Events = %d, Particles/Event = %d, V2 factor = %4.2f", numberEvents, particlesPerEvent, v2Factor);
    TLatex *text1 = new TLatex(0.5, 0.90*iMaximum, labelBufferTitle);
    text1->SetTextColor(4);
    text1->SetTextSize(0.045);
    text1->Draw();
		
    char labelBuffer2[200];
    sprintf(labelBuffer2, "Blue: azimuthal distribution relative to reaction plane");
    TLatex *text2 = new TLatex(0.5, 0.20*iMaximum, labelBuffer2);
    text2->SetTextColor(4);
    text2->SetTextSize(0.035);
    text2->Draw();
		
    char labelBuffer3[200];
    sprintf(labelBuffer3, "Black: azimuthal distribution relative to lab frame");
    TLatex *text3 = new TLatex(0.5, 0.10*iMaximum, labelBuffer3);
    text3->SetTextColor(1);
    text3->SetTextSize(0.035);
    text3->Draw();
		
  }
  else {
    particlePhiLabHistogram->SetStats(0);
    float fMaximum = particlePhiLabHistogram->GetMaximum();
    int iMaximum = 1.5*fMaximum;
    particlePhiLabHistogram->SetMaximum(iMaximum);
    particlePhiLabHistogram->SetMinimum(0);
    particlePhiLabHistogram->Draw();
		
    char labelBufferTitle[200];
    sprintf(labelBufferTitle, "Events = %d, Particles/Event = %d, No Flow", numberEvents, particlesPerEvent);
    TLatex *text1 = new TLatex(0.5, 0.90*iMaximum, labelBufferTitle);
    text1->SetTextColor(4);
    text1->SetTextSize(0.045);
    text1->Draw();
		
  }

  c1->cd(2);
  //pairDeltaPhiHistogramNormalized->SetStats(0);
  pairDeltaPhiHistogramNormalized->SetMaximum(1.3);
  pairDeltaPhiHistogramNormalized->SetMinimum(0.7);
  pairDeltaPhiHistogramNormalized->SetLineColor(2);

  TF1* fitFcnV2 = new TF1("fitFcnV2", v2Fit, -0.5*TMath::Pi(), 1.5*TMath::Pi(), 1);
  fitFcnV2->SetParameters(0, 0.20);
  fitFcnV2->SetParName(0, "Coeff");

  pairDeltaPhiHistogramNormalized->Fit("fitFcnV2", "", "",  -0.5*TMath::Pi(), 1.5*TMath::Pi());

  char labelBuffer12[200];
  sprintf(labelBuffer12, "Blue: fit with 1.0 + 2.0*Coeff*cos(2#Delta#phi), Coeff = %4.3f", fitFcnV2->GetParameter(0));
  TLatex *text12 = new TLatex(-0.5, 0.83, labelBuffer12);
  text12->SetTextColor(4);
  text12->SetTextSize(0.035);
  text12->Draw();

  char labelBuffer22[200];
  sprintf(labelBuffer22, "Red: normalized pair #Delta#phi distribution in lab frame");
  TLatex *text22 = new TLatex(-0.5, 0.77, labelBuffer22);
  text22->SetTextColor(2);
  text22->SetTextSize(0.035);
  text22->Draw();

  c1->cd(3);
  pairDeltaEtaHistogramNormalized->SetStats(0);
  pairDeltaEtaHistogramNormalized->SetMaximum(1.5);
  pairDeltaEtaHistogramNormalized->SetMinimum(0);
  pairDeltaEtaHistogramNormalized->Draw();
	
  c1->cd(4);
  pairDeltaEtaDeltaPhiHistogramNormalized->SetStats(0);
  pairDeltaEtaDeltaPhiHistogramNormalized->SetMaximum(1.3);
  pairDeltaEtaDeltaPhiHistogramNormalized->SetMinimum(0.7);
  pairDeltaEtaDeltaPhiHistogramNormalized->Draw("surf1");

  if(writeHistogramFile) {
    TFile *toyV2GeneratorFile;
		
    char outputFileName[200];
    sprintf(outputFileName, "toyV2Generator%dEvents%dParticlesPerEvent%4.2fV2.root", numberEvents, particlesPerEvent, v2Factor);
    char outputFileTitle[200];
    sprintf(outputFileTitle, "Toy V2 Generator with %d Events, %d Particles/Event, and V2 = %4.2f", numberEvents, particlesPerEvent, v2Factor);
    toyV2GeneratorFile = new TFile(outputFileName, "recreate", outputFileTitle);

    particlePhiHistogram->Write();
    particlePhiLabHistogram->Write();
    particleEtaHistogram->Write();

    pairDeltaPhiHistogram->Write();
    pairDeltaPhiHistogramMixed->Write();
    pairDeltaPhiHistogramNormalized->Write();

    pairDeltaEtaHistogram->Write();
    pairDeltaEtaHistogramMixed->Write();
    pairDeltaEtaHistogramNormalized->Write();

    pairDeltaEtaDeltaPhiHistogram->Write();
    pairDeltaEtaDeltaPhiHistogramMixed->Write();
    pairDeltaEtaDeltaPhiHistogramNormalized->Write();
		
    toyV2GeneratorFile->Write();
    toyV2GeneratorFile->Close();

  }

  return;

}
Beispiel #9
0
// infilename - root file with relevant histograms
// system - PP,APAP,PP
// status - Pass,Fail
// rWrite - 0-no,1-png,2-eps
// rPerformance - 0-no,1-yes (ALICE logo etc.)
// bin: 0 - all, 1- 0:5, 2- 5:10, etc
void drawDCA(const char* infilename, const char* system, const char* status, Int_t rWrite, Int_t rPerformance, int isMC, Int_t bin, Int_t ptrange)
{

    myOptions(0);

    gROOT->ForceStyle();
    gStyle->SetPalette(1.0);

    TDatime now;
    int iDate = now.GetDate();
    int iYear=iDate/10000;
    int iMonth=(iDate%10000)/100;
    int iDay=iDate%100;
    char* cMonth[12]={"Jan","Feb","Mar","Apr","May","Jun",
                      "Jul","Aug","Sep","Oct","Nov","Dec"};
    char cStamp1[25],cStamp2[25];
    sprintf(cStamp1,"%i %s %i",iDay, cMonth[iMonth-1], iYear);
    sprintf(cStamp2,"%i/%.2d/%i",iDay, iMonth, iYear);

    TFile *f = new TFile(infilename, "read");

    // DCA xy
    TH2D* DCAxy =(TH2D*)f->Get(Form("DCARPtcut%s1%stpcM%d","Pass", system,0));


    if (!bin) {
        int minMultBin = 0;
        int maxMultBin = 6; // 8
    }
    else {
        int minMultBin = bin-1;
        int maxMultBin = bin; // 8
    }

    // int minMultBin = 0;
    // int maxMultBin = 0; // 8

    double EvMultall = 0;

    for(int i = minMultBin; i<maxMultBin; i++) {

        TH2D* DCAxyN = (TH2D*)f->Get(Form("DCARPtcut%s1%stpcM%d",status, system,i));
        DCAxy->Add(DCAxyN);

        cout<<i<<" "<<DCAxyN->GetEntries()<<endl;

        //delete hEvMult;
    }


    if (!isMC) {
        TCanvas *c2 = new TCanvas("DCA xy prim", "DCA xy prim");
        c2->SetGridx();
        c2->SetGridy();
        c2->SetFillColor(10);
        c2->SetRightMargin(1.9);
        c2->SetLogz();

        DCAxy->GetXaxis()->SetTitle("DCA_{XY} (cm)");
        DCAxy->GetXaxis()->SetRangeUser(-5.0,5.0);
        DCAxy->GetYaxis()->SetTitle("#it{p}_{T} (GeV/#it{c})");
        // DCAxy->GetZaxis()->SetLabelSize(0.05);
        DCAxy->Draw("colz");
        postprocess(c2,Form("DCAxy%s",status),rWrite,rPerformance,system);

        // TCanvas *c4 = new TCanvas("DCA xy Projection X", "DCA xy Projection X");
        // c4->SetGridx();
        // c4->SetGridy();
        // c4->SetFillColor(10);
        // c4->SetRightMargin(1.9);
        // c4->SetLogy();

        gStyle->SetOptTitle(1);
        TCanvas *myCan = new TCanvas("myCan",cStamp1,600,400);
        myCan->Draw();
        myCan->cd();

        TPad *myPad = new TPad("myPad", "The pad",0,0,1,1);
        myPadSetUp(myPad,0.15,0.04,0.04,0.15);
        myPad->Draw();
        myPad->SetLogy();

        myPad->cd();

        if (ptrange == 0) {
            TH1D* pripp = (TH1D*)DCAxy->ProjectionX("zxc1",1,100);
            pripp->SetTitle("0.5 < #it{p}_{T} < 3 GeV/#it{c}");
        }
        else if (ptrange == 1) {
            TH1D* pripp = (TH1D*)DCAxy->ProjectionX("zxc1",15,33);
            pripp->SetTitle("0.5 < #it{p}_{T} < 1 GeV/#it{c}");
        }
        else if (ptrange == 2) {
            TH1D* pripp = (TH1D*)DCAxy->ProjectionX("zxc1",33,100);
            pripp->SetTitle("1 < #it{p}_{T} < 3 GeV/#it{c}");
        }

        pripp->SetYTitle("Number of Entries (normalized)");
        pripp->GetXaxis()->SetTitleSize(0.068);
        pripp->GetYaxis()->SetTitleSize(0.068);
        pripp->GetXaxis()->SetLabelSize(0.058);
        pripp->GetYaxis()->SetLabelSize(0.058);

        // pripp->SetLabelSize(0.05);
        // DCAxy->ProjectionX("asd",50,100)->SetYTitle("Number of Entries");
        // DCAxy->ProjectionX("asd",50,100)->SetTitle("1.0 < p_{T} < 2.0 GeV");
        // DCAxy->ProjectionX("asd",0,200)->SetTitle("");
        // DCAxy->ProjectionX("asd",50,100)->GetXaxis()->SetNdivisions(8);
        // DCAxy->ProjectionX("asd",50,100)->GetYaxis()->SetNdivisions(8);
        // DCAxy->ProjectionX("asd",50,100)->GetXaxis()->SetTitleSize(0.05);
        // DCAxy->ProjectionX("asd",50,100)->GetYaxis()->SetTitleSize(0.05);
        // DCAxy->ProjectionX("asd",50,100)->GetXaxis()->SetLabelSize(0.05);
        // DCAxy->ProjectionX("asd",50,100)->GetYaxis()->SetLabelSize(0.05);

        pripp->Draw("");

        //if (!isMC) {
        pripp->Scale(1./pripp->Integral());
        TFile* fout = new TFile("dca.root","update");
        pripp->SetName(Form("dcaxyMC%d",isMC));
        pripp->Write();
        //}

        postprocess(myCan,Form("DCAxy%sProX",status),rWrite,rPerformance,system);

    }
    else if (isMC) {

        TH2D* primp =(TH2D*)f->Get(Form("DCARPtcut%s1%stpcM%dprim","Pass", system,0));
        TH2D* weakp =(TH2D*)f->Get(Form("DCARPtcut%s1%stpcM%dweak","Pass", system,0));
        TH2D* matp =(TH2D*)f->Get(Form("DCARPtcut%s1%stpcM%dmat","Pass", system,0));

        // prim 2D
        TCanvas *c3prim = new TCanvas("DCA xy primary", "DCA xy primary");
        c3prim->SetGridx();
        c3prim->SetGridy();
        c3prim->SetFillColor(10);
        c3prim->SetRightMargin(1.9);
        c3prim->SetLogz();

        primp->GetXaxis()->SetTitle("DCA_{XY} (cm)");
        primp->GetXaxis()->SetRangeUser(-5.0,5.0);
        primp->GetYaxis()->SetTitle("#it{p}_{T} (GeV/#it{c})");
        primp->GetZaxis()->SetLabelSize(0.03);
        primp->Draw("colz");
        postprocess(c3prim,Form("DCAxy%s",status),rWrite,rPerformance,system);

        // weak 2D
        TCanvas *c3 = new TCanvas("DCA xy weak", "DCA xy weak");
        c3->SetGridx();
        c3->SetGridy();
        c3->SetFillColor(10);
        c3->SetRightMargin(1.9);
        c3->SetLogz();

        weakp->GetXaxis()->SetTitle("DCA_{XY} (cm)");
        weakp->GetXaxis()->SetRangeUser(-5.0,5.0);
        weakp->GetYaxis()->SetTitle("#it{p}_{T} (GeV/#it{c})");
        weakp->GetZaxis()->SetLabelSize(0.03);
        weakp->Draw("colz");
        postprocess(c3,Form("DCAxy%s",status),rWrite,rPerformance,system);

        // mat 2D
        TCanvas *c4 = new TCanvas("DCA xy mat", "DCA xy mat");
        c4->SetGridx();
        c4->SetGridy();
        c4->SetFillColor(10);
        c4->SetRightMargin(1.9);
        c4->SetLogz();

        matp->GetXaxis()->SetTitle("DCA_{XY} (cm)");
        matp->GetXaxis()->SetRangeUser(-5.0,5.0);
        matp->GetYaxis()->SetTitle("#it{p}_{T} (GeV/#it{c})");
        matp->GetZaxis()->SetLabelSize(0.03);
        matp->Draw("colz");
        postprocess(c4,Form("DCAxy%s",status),rWrite,rPerformance,system);


        // prim proj
        gStyle->SetOptTitle(1);

        TCanvas *myCan3prim = new TCanvas("myCan3prim",cStamp1);
        myCan3prim->Draw();
        myCan3prim->cd();

        TPad *myPad3prim = new TPad("myPad3prim", "The pad3prim",0,0,1,1);
        myPadSetUp(myPad3prim,0.15,0.04,0.04,0.15);
        myPad3prim->Draw();
        myPad3prim->SetLogy();

        myPad3prim->cd();

        TH1D* primpp = (TH1D*)primp->ProjectionX("zxc22",0,100);
        primpp->Draw("");

        cout << primpp->FindBin(-0.1) << endl;
        cout << primpp->FindBin(0.1) << endl;

        cout << "primary in cut- " << primpp->Integral(191,211) << endl;
        cout << "primary all- " << primpp->Integral(1,400) << endl;

        postprocess(myCan3prim,Form("DCAxy%sProX",status),rWrite,rPerformance,system);


        // weak proj
        TCanvas *myCan3 = new TCanvas("myCan3",cStamp1);
        myCan3->Draw();
        myCan3->cd();

        TPad *myPad3 = new TPad("myPad3", "The pad3",0,0,1,1);
        myPadSetUp(myPad3,0.15,0.04,0.04,0.15);
        myPad3->Draw();
        myPad3->SetLogy();

        myPad3->cd();

        TH1D* weakpp = (TH1D*)weakp->ProjectionX("zxc2",0,100);
        weakpp->Draw("");

        cout << "weak in cut- " << weakpp->Integral(191,211) << endl;
        cout << "weak all- " << weakpp->Integral(1,400) << endl;

        postprocess(myCan3,Form("DCAxy%sProX",status),rWrite,rPerformance,system);

        // mat proj
        gStyle->SetOptTitle(1);
        TCanvas *myCan4 = new TCanvas("myCan4",cStamp1);
        myCan4->Draw();
        myCan4->cd();

        TPad *myPad4 = new TPad("myPad4", "The pad4",0,0,1,1);
        myPadSetUp(myPad4,0.15,0.04,0.04,0.15);
        myPad4->Draw();
        myPad4->SetLogy();

        myPad4->cd();

        TH1D* matpp = (TH1D*)matp->ProjectionX("zxc3",0,100);
        matpp->Draw("");

        cout << "material in cut- " << matpp->Integral(191,211) << endl;
        cout << "material all- " << matpp->Integral(1,400) << endl;

        postprocess(myCan4,Form("DCAxy%sProX",status),rWrite,rPerformance,system);

        cout  << "in cut: " << endl;
        cout << "prim - " << primpp->Integral(191,211) / (primpp->Integral(191,211)+weakpp->Integral(191,211)+matpp->Integral(191,211)) << endl;
        cout << "weak - " << weakpp->Integral(191,211) / (primpp->Integral(191,211)+weakpp->Integral(191,211)+matpp->Integral(191,211)) << endl;
        cout << "mat - " << matpp->Integral(191,211) / (primpp->Integral(191,211)+weakpp->Integral(191,211)+matpp->Integral(191,211)) << endl;

        cout << endl << "in cut / all " << endl;
        cout << "prim - " << primpp->Integral(191,211) / primpp->Integral(1,400) << endl;
        cout << "weak - " << weakpp->Integral(191,211) / weakpp->Integral(1,400) << endl;
        cout << "mat - " << matpp->Integral(191,211) / matpp->Integral(1,400) << endl;


        // _____sum____

        TH2D* psum = new TH2D("psum","",400, -2.0, 2.0, 100,0.0,2.0);
        psum->GetXaxis()->SetTitle("DCA_{xy} (cm)");
        psum->GetYaxis()->SetTitle("Number of Entries (normalized)");
        psum->GetXaxis()->SetLimits(-2,2);


        for (int i = 0; i < primp->GetNbinsX(); i++) {
            for (int j = 0; j < primp->GetNbinsY(); j++) {
                psum->SetBinContent(i,j,primp->GetBinContent(i,j)+weakp->GetBinContent(i,j)+matp->GetBinContent(i,j));
            }
        }

        gStyle->SetOptStat(0);

        TCanvas *cansum = new TCanvas("cansum",cStamp1,600,400);
        cansum->Draw();
        cansum->cd();

        TPad *padsum = new TPad("padsum", "The pad4",0,0,1,1);
        myPadSetUp(padsum,0.15,0.04,0.04,0.15);
        padsum->Draw();
        padsum->SetLogy();

        padsum->cd();

        // TCanvas* cansum = new TCanvas("cansum","cansum");
        // cansum->SetLogy();
        //psum->Draw("colz");
        TH1D* asd0 = (TH1D*)psum->ProjectionX("zxc",0,100);

        // asd0->Scale(1./asd0->Integral());
        // TFile* fout = new TFile("dca.root","update");
        // asd0->SetName(Form("dcaxyMC%d",isMC));
        // asd0->Write();

        asd0->GetXaxis()->SetTitle("DCA_{xy} (cm)");
        asd0->GetYaxis()->SetTitle("Number of Entries (normalized)");
        //asd0->SetMaximum(5000);
        //asd0->SetMinimum(0.00008);
        asd0->GetXaxis()->SetNdivisions(8);
        asd0->GetYaxis()->SetNdivisions(8);
        //asd0->GetYaxis()->SetTitleOffset(1.4);
        asd0->GetXaxis()->SetTitleSize(0.068);
        asd0->GetYaxis()->SetTitleSize(0.068);
        asd0->GetXaxis()->SetLabelSize(0.058);
        asd0->GetYaxis()->SetLabelSize(0.058);
        asd0->SetFillColor(kBlack);

        Double_t norm = asd0->Integral();
        //asd0->Scale(1./norm);
        //asd0->SetMinimum(0.00007);

        asd0->SetMarkerSize(1.3);
        asd0->SetMarkerColor(kBlack);
        asd0->SetMarkerStyle(20);
        asd0->Draw("pc");

        primpp->SetFillColor(kGreen+2);
        //primpp->Scale(1./norm);
        primpp->SetMarkerSize(1.3);
        primpp->SetMarkerColor(kGreen+2);
        primpp->SetMarkerStyle(20);
        primpp->Draw("psame");

        matpp->SetFillColor(kRed);
        //matpp->Scale(1./norm);
        matpp->SetMarkerSize(1.3);
        matpp->SetMarkerColor(kRed);
        matpp->SetMarkerStyle(20);
        matpp->Draw("psame");

        weakpp->SetFillColor(kBlue);
        //weakpp->Scale(1./norm);
        weakpp->SetMarkerSize(1.3);
        weakpp->SetMarkerColor(kBlue);
        weakpp->SetMarkerStyle(20);
        weakpp->Draw("psame");



        // _____endofsum____


        TLegend *myLegend = new TLegend(0.6,0.6,0.89,0.89);
        myLegend->SetFillColor(10);
        myLegend->SetBorderSize(0);

        myLegend->AddEntry(asd0,"all","f");
        myLegend->AddEntry(primpp,"primary","f");
        myLegend->AddEntry(weakpp,"weak decay","f");
        myLegend->AddEntry(matpp,"material","f");
        //myLegend->Draw("same");


        // logo

        TLatex *sys = new TLatex(0.16,0.91,"AMPT Pb-Pb #sqrt{s_{NN}} = 2.76 TeV");
        sys->SetNDC();
        sys->SetTextFont(42);
        sys->SetTextSize(0.05);
        sys->SetTextColor(kRed+2);
        sys->Draw();

        TDatime now;
        int iDate = now.GetDate();
        int iYear=iDate/10000;
        int iMonth=(iDate%10000)/100;
        int iDay=iDate%100;
        char* cMonth[12]={"Jan","Feb","Mar","Apr","May","Jun",
                          "Jul","Aug","Sep","Oct","Nov","Dec"};
        char cStamp1[25],cStamp2[25];
        sprintf(cStamp1,"%i %s %i",iDay, cMonth[iMonth-1], iYear);
        sprintf(cStamp2,"%i/%.2d/%i",iDay, iMonth, iYear);


        TText *date = new TText(0.27,0.5,cStamp2);
        date->SetNDC();
        date->SetTextFont(42);
        date->SetTextSize(0.04);
        date->Draw();

        //           //Acquire canvas proportions
//                 Double_t AliLogo_LowX = 0.27;
//                 Double_t AliLogo_LowY = 0.6;
//                 Double_t AliLogo_Height = 0.22;
//                 //ALICE logo is a png file that is 821x798 pixels->should be wider than a square
//                 Double_t AliLogo_Width  = (821./798.) * AliLogo_Height * gPad->GetWh() / gPad->GetWw();

//                 TPad *myPadLogo = new TPad("myPadLogo", "Pad for ALICE Logo",AliLogo_LowX,AliLogo_LowY,AliLogo_LowX+AliLogo_Width,AliLogo_LowY+AliLogo_Height);
//                 //    myPadLogo->SetFillColor(2); // color to first figure out where is the pad then comment !
//                 myPadSetUp(myPadLogo,0,0,0,0);
//                 myPadLogo->SetFixedAspectRatio(1);
//                 myPadLogo->Draw();
//                 myPadLogo->cd();

// //                TASImage *myAliceLogo = new TASImage("alice_preliminary.eps");
//                 TASImage *myAliceLogo = new TASImage("alice_performance.eps");
// //		TASImage *myAliceLogo = new TASImage("alice_logo_transparent.png");
//                 myAliceLogo->Draw();

        DrawALICELogo(0,0.27,0.55,0.7,0.8);

//logo

        // postprocess(cansum,Form("DCAxyMC%s",status),rWrite,rPerformance,system);
        cansum->SaveAs("DCAxyMC.png");
        cansum->SaveAs("DCAxyMC.eps");
    }

//__________________________________________________


}
Beispiel #10
0
void plotXY(){
  gROOT->Reset();
  gROOT->SetStyle("Plain");
  gStyle->SetHistMinimumZero(kFALSE);

  Int_t status = gSystem->Load("../rootils_C.so");
  std::cout << "status: " << status << std::endl;

  // TString dir("allStat_6hits/");
  // TString dir("allStat_noWeiBug/");
  TString dir("./");

  //Agguanta gli istogrammi
  TFile * SimF = new TFile(dir+"Sim_XY.root");
  TH2D * SimH = (TH2D*) SimF->Get("Sim_XY");;
  //
  TFile * MCF = new TFile(dir+"MC_XY.root");
  TH2D * MCH = (TH2D*) MCF->Get("MC_XY");;
  //
  //  TFile * MCFsF = new TFile(dir+"rMCFs_XY.root");
  //  TH2D * MCFsH = (TH2D*) MCFsF->Get("rMCFs_XY");;
  //
  TFile * FakeF = new TFile(dir+"MCFake_XY.root");
  TH2D * FakeH = (TH2D*) FakeF->Get("MCFake_XY");;
  //
  TFile * DataF = new TFile(dir+"Data_XY.root");
  TH2D * DataH = (TH2D*) DataF->Get("Data_XY");;
  //
  //  TFile * DataFsF = new TFile(dir+"rDataFs_XY.root");
  //  TH2D * DataFsH = (TH2D*) DataFsF->Get("rDataFs_XY");;
  //
  
  cout << MCH->GetEntries() << " " << MCH->GetEffectiveEntries() << " " << MCH->Integral() << endl;
  cout << DataH->GetEntries() << " " << DataH->GetEffectiveEntries() << " " << DataH->Integral() << endl;

  //Normalize to plot entries
  SimH->Scale(1./SimH->Integral()); 
  MCH->Scale(1./MCH->Integral());
  FakeH->Scale(1./FakeH->Integral());
  DataH->Scale(1./DataH->Integral());

  cout << MCH->GetEntries() << " " << MCH->GetEffectiveEntries() << " " << MCH->Integral() << endl;
  cout << DataH->GetEntries() << " " << DataH->GetEffectiveEntries() << " " << DataH->Integral() << endl;

  //Max
  Double_t simMax=SimH->GetMaximum();
  Double_t simPxlMax=GetMaxWithinRadius(SimH, 15.);
  Double_t simPxlInt=GetIntWithinRZ(SimH, 15., 0.);
  Double_t MCMax=MCH->GetMaximum();
  Double_t MCPxlMax=GetMaxWithinRadius(MCH, 15.);
  Double_t MCPxlInt=GetIntWithinRZ(MCH, 15., 0.);
  Double_t DataMax=DataH->GetMaximum();
  Double_t DataPxlMax=GetMaxWithinRadius(DataH, 15.);
  Double_t DataPxlInt=GetIntWithinRZ(DataH, 15., 0.);
  Double_t mAx=max(MCMax,DataMax);


  std::cout << " max     >>>> mc " << MCMax << " data " << DataMax << " Sim " << simMax << std::endl;
  std::cout << " pxl max >>>> mc " << MCPxlMax << " data " << DataPxlMax << " Sim " << simPxlMax << std::endl;
  std::cout << " pxl int >>>> mc " << MCPxlInt << " data " << DataPxlInt << " Sim " << simPxlInt << std::endl;

  // This would be need to normalize SimH to the pixel region material (taking into account that SimH and DataH/MCH have different binning!)
  //
  //  SimH->Scale(DataPxlInt*(DataH->GetXaxis()->GetBinWidth(1)*DataH->GetYaxis()->GetBinWidth(1))/simPxlInt/(SimH->GetXaxis()->GetBinWidth(1)*SimH->GetYaxis()->GetBinWidth(1)));
  // I prefer to have Sim plots and Data/MC plot to look similar by appropriately scaling the SimH range, not by scaling the histo

  mAx=0.001;
  //  mAx=0.011;
  //  mAx=0.15*0.5*(MCPxlMax+DataPxlMax);

  Double_t simRangeScale = 1./(DataPxlInt*(DataH->GetXaxis()->GetBinWidth(1)*DataH->GetYaxis()->GetBinWidth(1))/simPxlInt/(SimH->GetXaxis()->GetBinWidth(1)*SimH->GetYaxis()->GetBinWidth(1)));

  std::cout << simRangeScale << endl;
  std::cout << (DataH->GetXaxis()->GetBinWidth(1)*DataH->GetYaxis()->GetBinWidth(1)) << endl;
  std::cout << (SimH->GetXaxis()->GetBinWidth(1)*SimH->GetYaxis()->GetBinWidth(1)) << endl;

  SimH->SetMaximum(mAx*simRangeScale); 
  MCH->SetMaximum(mAx);  
  DataH->SetMaximum(mAx);

  //

  makeColorTable();

  Plot2D(SimH, "#gamma conv., MC Truth", dir);
  Plot2D(MCH, "#gamma conv., MC Reco #sqrt{s}=8TeV", dir);
  Plot2D(DataH, "#gamma conv., Data #sqrt{s}=8TeV", dir);

  //

  /*
  TH2D *MCCoarse = MCH->Rebin2D(2,2,"MCCoarse");
  TH2D *DataCoarse = DataH->Rebin2D(2,2,"DataCoarse");
  */

  /*
  cout << MCCoarse->GetEntries() << " " << MCCoarse->GetEffectiveEntries() << endl;
  cout << DataCoarse->GetEntries() << " " << DataCoarse->GetEffectiveEntries() << endl;
  */

  /*
  TH2D *diff = new TH2D("diff","diff", MCCoarse->GetNbinsX(),-60.,60.,MCCoarse->GetNbinsY(),-60.,60.);
  for (Int_t iBin = 0; iBin < MCCoarse->GetNbinsX(); iBin++){
    for (Int_t jBin = 0; jBin < MCCoarse->GetNbinsY(); jBin++){
      Double_t mc = MCCoarse->GetBinContent(iBin+1, jBin+1); 
      Double_t data = DataCoarse->GetBinContent(iBin+1, jBin+1); 
      cout << mc << " " << data << endl;
      if ( mc ) diff->SetBinContent(iBin+1,jBin+1,0.5+(mc-data)/mc);
    }
  }
  */

  MCH->Rebin2D(2,2);
  DataH->Rebin2D(2,2);

  TH2D *diff = new TH2D("diff","diff", MCH->GetNbinsX(),-60.,60.,MCH->GetNbinsY(),-60.,60.);
  for (Int_t iBin = 0; iBin < MCH->GetNbinsX(); iBin++){
    for (Int_t jBin = 0; jBin < MCH->GetNbinsY(); jBin++){
      Double_t mc = MCH->GetBinContent(iBin+1, jBin+1); 
      Double_t data = DataH->GetBinContent(iBin+1, jBin+1); 
      if ( mc+data ) {
      if ( ! mc ) mc=0.0000001;
      Double_t val = data/mc;
      //      Double_t val = (mc-data)/mc;
      Double_t valup = 1.2;
      Double_t vallo = 0.8;
      Double_t offset = 0.;
      if ( val > valup ) diff->SetBinContent(iBin+1,jBin+1,offset+valup);
      if ( val < vallo ) diff->SetBinContent(iBin+1,jBin+1,offset+vallo);
      if ( val > vallo && val < valup ) diff->SetBinContent(iBin+1,jBin+1,offset+val);
      }
    }
  }


  diff->SetMinimum(0.);
  diff->SetMaximum(2.);

  makeColorTableRB();

  Plot2D(diff,"pippo", dir);

}