Exemple #1
0
void AliITSLegoPlot(Float_t nchtheta, Float_t nchphi, const char *inFile = "galice.root") {
// macro to visualize the lego plots generated by gAlive->RunLego
   
   gROOT->Reset();
   TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(inFile);
   if (!file->IsOpen()) {
       cerr<<"Can't open "<<inFile<<" !" << endl;
       return 1;
   } // end if !file
    

   Float_t theta = 10;
   Float_t phi   = 170;
   Int_t ncont   = 50;

   TCanvas *cradl = new TCanvas("cradl","radl",10,10,800,600);
   cradl->SetTheta(theta);
   cradl->SetPhi(phi);
   TH2F *hradl = (TH2F*)file->Get("hradl");
   hradl->SetStats(kFALSE);
   hradl->GetXaxis()->SetTitle("Phi (degrees)");
   hradl->GetYaxis()->SetTitle("Theta (degrees)");
   hradl->SetFillColor(2);
   hradl->SetContour(ncont);
   hradl->Draw("colz");


   TCanvas *cradlx = new TCanvas("cradl1","radl",50,50,800,600);
   hradl->ProjectionX();
   hradl_px->SetStats(kFALSE);
//   hradl_px->SetOptLogY();
//   hradl_px->SetMinimum(0.001);   
//   hradl_px->SetMaximum(1);
   hradl_px->Scale(1./nchtheta);   
   hradl_px->GetXaxis()->SetTitle("Phi (degrees)");
   hradl_px->GetYaxis()->SetTitle("X/X0");
   hradl_px->Draw();
//   cout << "Average over Phi: " << hradl_px->GetSumOfWeights()/nchphi << " X/X0" << endl;
   
   
   TCanvas *cradly = new TCanvas("cradl2","radl",100,100,800,600);
   hradl->ProjectionY();
   hradl_py->SetStats(kFALSE);
//   hradl_py->SetOptLogY();
//   hradl_py->SetMinimum(0.001);   
//   hradl_py->SetMaximum(1);   
   hradl_py->Scale(1./nchphi);
   hradl_py->GetXaxis()->SetTitle("Theta (degrees)");
   hradl_py->GetYaxis()->SetTitle("X/X0");
   hradl_py->Draw();   
//   cout << "Average over Theta: " << hradl_py->GetSumOfWeights()/nchtheta << " X/X0" << endl;  
   cout << "Average: " << hradl_py->GetSumOfWeights()/nchtheta << " X/X0" << endl;     
}   
Exemple #2
0
void lego() {
// macro to visualize the lego plots generated by gAlive->RunLego
   
   gROOT->Reset();
   TFile *file = new TFile("galice.root");

   Float_t theta = 10;
   Float_t phi   = 170;
   Int_t ncont   = 50;

   TCanvas *cgcm2 = new TCanvas("cgcm2","gcm2",200,100,600,400);
   cgcm2->SetTheta(theta);
   cgcm2->SetPhi(phi);
   TH2F *hgcm2 = (TH2F*)file->Get("hgcm2");
   hgcm2->SetFillColor(2);
   hgcm2->SetMaximum(1);
   hgcm2->SetContour(ncont);
   hgcm2->SetMaximum(50);
   hgcm2->Draw("lego2sphe");

   TCanvas *cabso = new TCanvas("cabso","abso",100,50,600,400);
   cabso->SetTheta(theta);
   cabso->SetPhi(phi);
   TH2F *habso = (TH2F*)file->Get("habso");
   habso->SetFillColor(2);
   habso->SetMaximum(1);
   habso->SetContour(ncont);
   habso->SetMaximum(1);
   habso->Draw("lego2sphe");

   TCanvas *cradl = new TCanvas("cradl","radl",10,10,600,400);
   cradl->SetTheta(theta);
   cradl->SetPhi(phi);
   TH2F *hradl = (TH2F*)file->Get("hradl");
   hradl->SetFillColor(2);
   hradl->SetMaximum(1);
   hradl->SetContour(ncont);
   hradl->SetMaximum(5);
   hradl->Draw("lego2sphe");
}   
    void 
DrawContourSameColorDisc( TLegend *leg, TH2F* hist, Double_t nsigma, TString color, Bool_t second=kFALSE, TH2F* inverse=0, Bool_t linesOnly=kFALSE )
{
    if (nsigma < 0.5 || nsigma > 10.5 ) {
        cout << "*** Error in CombinationGlob::DrawContour: nsigma out of range: " << nsigma 
            << "==> abort" << endl;
        exit(1);
    }

    Int_t lcol_sigma;
    Int_t fcol_sigma[3];

    if( color == "pink" ){
        lcol_sigma    = CombinationGlob::c_VDarkPink;
        fcol_sigma[0] = CombinationGlob::c_LightPink;
        fcol_sigma[1] = CombinationGlob::c_LightPink;
        fcol_sigma[2] = CombinationGlob::c_LightPink;
    }
    else if( color == "green" ){ // HF
        lcol_sigma    = CombinationGlob::c_VDarkGreen;
        fcol_sigma[0] = CombinationGlob::c_DarkGreen;
        fcol_sigma[1] = CombinationGlob::c_LightGreen;
        fcol_sigma[2] = CombinationGlob::c_VLightGreen;
    } 
    else if( color == "yellow" ){
        lcol_sigma    = CombinationGlob::c_VDarkYellow;
        fcol_sigma[0] = CombinationGlob::c_DarkYellow;
        fcol_sigma[1] = CombinationGlob::c_DarkYellow;
        fcol_sigma[2] = CombinationGlob::c_White; //c_DarkYellow;
    }
    else if( color == "orange" ){
        lcol_sigma    = CombinationGlob::c_VDarkOrange;
        fcol_sigma[0] = CombinationGlob::c_DarkOrange;
        fcol_sigma[1] = CombinationGlob::c_LightOrange; // c_DarkOrange
        fcol_sigma[2] = CombinationGlob::c_VLightOrange;
    }
    else if( color == "gray" ){
        lcol_sigma    = CombinationGlob::c_VDarkGray;
        fcol_sigma[0] = CombinationGlob::c_LightGray;
        fcol_sigma[1] = CombinationGlob::c_LightGray;
        fcol_sigma[2] = CombinationGlob::c_LightGray;
    }
    else if( color == "blue" ){
        lcol_sigma    = CombinationGlob::c_DarkBlueT1;
        fcol_sigma[0] = CombinationGlob::c_BlueT5;
        fcol_sigma[1] = CombinationGlob::c_BlueT3;
        fcol_sigma[2] = CombinationGlob::c_BlueT2;
    }

    // contour plot
    TH2F* h = new TH2F( *hist );
    h->SetContour( 1 );
    double dsignif = double (nsigma);
    h->SetContourLevel( 0, dsignif );

    Int_t mycolor = (nsigma==5   ? 0 : 2);
    Int_t mycolor = (nsigma==2.5 ? 1 : 2);

    if( !second ){
        h->SetFillColor( fcol_sigma[mycolor] );
        if (!linesOnly) h->Draw( "samecont0" );
    }

    h->SetLineColor( (nsigma==2.5) ? 2 : lcol_sigma );

    h->SetLineStyle( nsigma==5 || nsigma==2.5 ? 1 : 2 );
    h->SetLineWidth( nsigma==5 || nsigma==2.5 ? 2 : 1 );

    h->Draw( "samecont3" );

    if(nsigma==5)   { leg->AddEntry(h,"5 #sigma discovery","l"); }
    if(nsigma==6)   { leg->AddEntry(h,"N (int) #sigma discovery","l"); }
    if(nsigma==2.5) { leg->AddEntry(h,"2.5 #sigma discovery","l"); }
}
    void 
DrawContourSameColor( TLegend *leg, TH2F* hist, Int_t nsigma, TString color, Bool_t second=kFALSE, TH2F* inverse=0, Bool_t linesOnly=kFALSE, Bool_t isnobs=kFALSE )
{
    if (nsigma < 1 || nsigma > 3) {
        cout << "*** Error in CombinationGlob::DrawContour: nsigma out of range: " << nsigma 
            << "==> abort" << endl;
        exit(1);
    }
    nsigma--; // used as array index

    Int_t lcol_sigma;
    Int_t fcol_sigma[3];
    Int_t lstyle = 1;
    if( color == "pink" ){
        lcol_sigma    = CombinationGlob::c_VDarkPink;
        fcol_sigma[0] = CombinationGlob::c_LightPink;
        fcol_sigma[1] = CombinationGlob::c_LightPink;
        fcol_sigma[2] = CombinationGlob::c_LightPink;
    }
    else if( color == "green" ){ // HF
        lcol_sigma    = CombinationGlob::c_VDarkGreen;
        fcol_sigma[0] = CombinationGlob::c_DarkGreen;
        fcol_sigma[1] = CombinationGlob::c_LightGreen;
        fcol_sigma[2] = CombinationGlob::c_VLightGreen;
    } 
    else if( color == "yellow" ){
        lcol_sigma    = CombinationGlob::c_VDarkYellow;
        fcol_sigma[0] = CombinationGlob::c_DarkYellow;
        fcol_sigma[1] = CombinationGlob::c_DarkYellow;
        fcol_sigma[2] = CombinationGlob::c_White; //c_DarkYellow;
        lstyle = 2;
    }
    else if( color == "orange" ){
        lcol_sigma    = CombinationGlob::c_VDarkOrange;
        fcol_sigma[0] = CombinationGlob::c_DarkOrange;
        fcol_sigma[1] = CombinationGlob::c_LightOrange; // c_DarkOrange
        fcol_sigma[2] = CombinationGlob::c_VLightOrange;
    }
    else if( color == "gray" ){
        lcol_sigma    = CombinationGlob::c_VDarkGray;
        fcol_sigma[0] = CombinationGlob::c_LightGray;
        fcol_sigma[1] = CombinationGlob::c_LightGray;
        fcol_sigma[2] = CombinationGlob::c_LightGray;
    }
    else if( color == "blue" ){
        lcol_sigma    = CombinationGlob::c_DarkBlueT1;
        fcol_sigma[0] = CombinationGlob::c_BlueT5;
        fcol_sigma[1] = CombinationGlob::c_BlueT3;
        fcol_sigma[2] = CombinationGlob::c_White;  //CombinationGlob::c_BlueT2;

    }

    // contour plot
    TH2F* h = new TH2F( *hist );
    h->SetContour( 1 );
    double pval = CombinationGlob::cl_percent[1];
    double signif = TMath::NormQuantile(1-pval);
    double dnsigma = double(nsigma)-1.;
    double dsignif = signif + dnsigma;
    h->SetContourLevel( 0, dsignif );

    if( !second ){
        h->SetFillColor( fcol_sigma[nsigma] );

        if (!linesOnly) h->Draw( "samecont0" );
    }

    h->SetLineColor( nsigma==1? 1 : lcol_sigma );
    if (isnobs)h->SetLineColor( nsigma==1? 2 : lcol_sigma );
    //h->SetLineStyle( 4 );
    h->SetLineWidth( 2 );
    h->SetLineStyle( lstyle );
    h->Draw( "samecont3" );

    if (linesOnly&&!isnobs)
        if(nsigma==1){ leg->AddEntry(h,"exp. 95% CL limit","l");}
    if (isnobs)
        if(nsigma==1){ leg->AddEntry(h,"obs. 95% CL limit","l");}  
    if (!linesOnly) {
        if(nsigma==0){ leg->AddEntry(h,"- 1 #sigma expectation","l"); }
        if(nsigma==2){ leg->AddEntry(h,"+ 1 #sigma expectation","l");}
    } 
}
/*
EXAMPLE
root
.L particleDrawer.C++
particleDrawer("../test/test.root",11,2)
 */
void particleDrawer(TString filename, int entry = 0, int PVAssoc = 2, bool debug = false) {

   cout << "particleDrawer::Setting the TDR style ... ";
   setTDRStyle();
   cout << "DONE" << endl;

   cout << "particleDrawer::Drawing the default (TDR) frame ... " << endl;
   TH1D* frame = new TH1D();
   frame->GetXaxis()->SetLimits(-5,5);
   frame->GetXaxis()->SetTitle("#eta");
   frame->GetYaxis()->SetRangeUser(-TMath::Pi(),TMath::Pi());
   frame->GetYaxis()->SetTitle("#phi");
   TCanvas* c = tdrCanvas("particleBasedEvent",frame,4,0,true);
   c->GetPad(0)->SetLogz();
   cout << "\r\r\r\r\r\r" << flush;
   cout << setw(52) << " " << "DONE" << endl << endl;

   cout << "particleDrawer::Opening the input file (" << filename << " ) ... ";
   TFile* inFile = TFile::Open(filename,"READ");
   assert(inFile!=NULL);
   cout << "DONE" << endl;

   cout << "particleDrawer::Getting the input trees ... ";
   TTree* puppiTree = (TTree*)inFile->Get("puppiReader/puppiTree");
   assert(puppiTree!=NULL);
   TTree* jetTree = (TTree*)inFile->Get("nt_AK4PFchs/t");
   assert(jetTree!=NULL);
   cout << "DONE" << endl;

   cout << "particleDrawer::Making the ntuples ... ";
   puppiNtuple*     pNtuple = new puppiNtuple(puppiTree);
   validatorNtuple* jNtuple = new validatorNtuple(jetTree);
   cout << "DONE" << endl;

   cout << "particleDrawer::Getting entry " << entry << " for puppiTree ... ";
   puppiTree->GetEntry(entry);
   cout << "DONE" << endl;

   cout << "particleDrawer::Filling the histograms ... ";
   TH2F* hPU = new TH2F("hPU","hPU",50,-5,5,60,-TMath::Pi(),TMath::Pi());
   TH2F* hHard = new TH2F("hHard","hHard",50,-5,5,60,-TMath::Pi(),TMath::Pi());

   for(unsigned int iparticle=0; iparticle<(*pNtuple->px).size(); iparticle++) {
      TLorentzVector tempVect((*pNtuple->px)[iparticle],(*pNtuple->py)[iparticle],
                              (*pNtuple->pz)[iparticle],(*pNtuple->e)[iparticle]);

      if((*pNtuple->fromPV)[iparticle]<PVAssoc) {
         if(debug) cout << "Filling PU::fromPV = " << (*pNtuple->fromPV)[iparticle] << endl;
         hPU->Fill(tempVect.Eta(),tempVect.Phi(),tempVect.Pt());
      }
      else {
         if(debug) cout << "Filling hard-scatter:: fromPV = " << (*pNtuple->fromPV)[iparticle] << endl;
         hHard->Fill(tempVect.Eta(),tempVect.Phi(),tempVect.Pt());
      }
   }
   if(debug) {
      cout << "hPU->GetEntries() = " << hPU->GetEntries() << endl;
      cout << "hHard->GetEntries() = " << hHard->GetEntries() << endl;
   }
   else
      cout << "DONE" << endl;

   cout << "particleDrawer::Drawing the histograms ... ";
   //tdrDraw(hPU,"BOX",kFullSquare,kNone,kSolid,kGray,kNone,kNone);
   //tdrDraw(hHard,"colz");
   THStack* stack = new THStack("stack","stack");
   hPU->SetLineStyle(kSolid);
   hPU->SetLineColor(kGray);
   hPU->SetFillStyle(1001);
   hPU->SetFillColor(kNone);
   hPU->SetMarkerStyle(kFullSquare);
   hPU->SetMarkerColor(kNone);
   if(hHard->GetEntries()>0)
      stack->Add(hHard,"colz");
   if(hPU->GetEntries()>0)
      stack->Add(hPU,"BOX");
   tdrDraw(stack,"nostack");

   set_plot_style();
   c->Update();
   c->RedrawAxis();
   cout << "DONE" << endl;

   cout << "particleDrawer::Getting entry " << entry << " for jetTree ... ";
   jetTree->GetEntry(entry);
   cout << "DONE" << endl;

   cout << "particleDrawer::Drawing the jets ... " << endl;
   vector<JetCircle> jets;
   for(unsigned int ijet=0; ijet<jNtuple->nref; ijet++) {
      if((*jNtuple->jtpt)[ijet]<20) continue;
      double RJet = TMath::Sqrt((*jNtuple->jtarea)[ijet]/TMath::Pi());
      jets.push_back(JetCircle((*jNtuple->jteta)[ijet],(*jNtuple->jtphi)[ijet],RJet,(*jNtuple->jtpt)[ijet]));
   }
   for(unsigned int ijet=0; ijet<jets.size(); ijet++) {
      for(unsigned int jjet=ijet+1; jjet<jets.size(); jjet++) {
         if(check_overlap(jets[ijet].getX(),jets[ijet].getY(),jets[ijet].getRadius(),
                          jets[jjet].getX(),jets[jjet].getY(),jets[jjet].getRadius())) {
            cout << "Jet " << ijet << " overlaps with jet " << jjet << endl;
            if(jets[ijet].getPt()>jets[jjet].getPt()) {
               //find angle for jjet;
               jets[jjet].findAngles(jets[ijet]);               
            }
            else if(jets[ijet].getPt()<jets[jjet].getPt()) {
               //find angle for ijet
               jets[ijet].findAngles(jets[jjet]);
            }
            else {
               //must find angle for both jets
               //then must draw a straight line between the two intersection points
               jets[jjet].findAngles(jets[ijet]);
               jets[ijet].findAngles(jets[jjet]);
               //NEED TO COMPLETE THIS FUNCTION. CURRENTLY DOESNOT DRAW LINE BETWEEN THE JETS.
            }
            cout << "Jet " << ijet << ": \n" << jets[ijet] << endl;
            cout << "Jet " << jjet << ": \n" << jets[jjet] << endl;
         }
      }
   }
   for(unsigned int ijet=0; ijet<jets.size(); ijet++) {
      loadbar2(ijet+1, jets.size());
      TEllipse* cJet = new TEllipse(jets[ijet].getX(),jets[ijet].getY(),
                                    jets[ijet].getRadius(),jets[ijet].getRadius(),
                                    jets[ijet].getStartAngle(),jets[ijet].getEndAngle());
      cJet->SetFillStyle(0);
      cJet->SetFillColor(kNone);
      cJet->SetLineStyle(kSolid);
      cJet->SetLineColor(kRed);
      cJet->SetLineWidth(3);
      cJet->Draw("only same");
   }
   //cout << "\r\r\r\r" << flush;
   //cout << setw(37) << " " << "DONE" << endl << endl;

   cout << "particleDrawer::Saving the canvas ... ";
   TString name = Form("particleMap_entry%i_PVAssoc%i",entry,PVAssoc);
   c->SaveAs(name+".png");
   c->SaveAs(name+".pdf");
   c->SaveAs(name+".C");
   cout << "DONE" << endl;
}