Ejemplo n.º 1
0
/*
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;
}