コード例 #1
0
ファイル: TOFquickanal.C プロジェクト: alisw/AliRoot
Int_t TOFquickanal(Int_t eventNumber = 0)
{
  /////////////////////////////////////////////////////////////////////////
  //   This macro is a small example of a ROOT macro
  //   illustrating how to read the output of GALICE
  //   and fill some histograms concerning the TOF Hit Tree.
  //
  //     Root > .L TOFquickanal.C   //this loads the macro in memory
  //     Root > TOFquickanal();     //by default process first event
  //     Root > TOFquickanal(2);    //process third event
  //Begin_Html
  /*
    <img src="picts/TOFquickanal.gif">
  */
  //End_Html
  //
  // Author: F. Pierella , Bologna University 12-04-2001
  // Updated to the new I/O by: A. De Caro, C. Zampolli
  /////////////////////////////////////////////////////////////////////////
  
  // Dynamically link some shared libs
  if (gClassTable->GetID("AliRun") < 0) {
    gROOT->LoadMacro("loadlibs.C");
    loadlibs();
  }

  Int_t rc = 0;
  
  AliRunLoader *rl =AliRunLoader::Open("galice.root",AliConfig::GetDefaultEventFolderName(),"update");
  if (!rl) 
    {
      cerr << "Can't load RunLoader from file!\n";
      rc = 1;
      return rc;
    }

  rl->LoadgAlice();
  gAlice=rl->GetAliRun();

  if (!gAlice)
    {
      cerr << "<TOFquickanal> AliRun object not found on file \n";
      rc = 2;
      return rc;
    }

  // Get the pointer to the TOF detector
  AliLoader *tofl = rl->GetLoader("TOFLoader");
  AliTOF * tof = (AliTOF*) gAlice->GetDetector("TOF");
  if (tof == 0x0 || tofl == 0x0) {
    cerr << "<TOFquickanal> Can not find TOF or TOFLoader\n";
    rc = 3;
    return rc;
  }

  //=======> Create histograms
  //---> Time of Flight for Primary Particles (ns)
  TH1F *htofprim = new TH1F("htofprim","Time of Flight for Primary Particles",100,0.,100.);
  //--->Time of Flight for Secondary Particles (ns)
  TH1F *htofsec  = new TH1F("htofsec","Time of Flight for Secondary Particles",100,0.,100.);
  
  //---> r (radius) coordinate of production in the ALICE frame for secondary particles that produce at 
  //     least one TOF-hit (cm) - cylindrical coordinate system assumed, primary plus secondary-
  TH1F *hradius = new TH1F("hradius","r (radius) coordinate at the production vertex for secondary particles with at least one TOF-Hit",50,0.,500.);
  
  //---> Momentum of primary particles that produce (at least) one TOF-hit when the hit
  //     is produced (Gev/c)
  TH1F *htofmom  = new TH1F("htofmom","Momentum of primary particles when the Hit is produced",50,0.,5.);
  
  //---> Momentum of primary particles that produce (at least) one TOF-hit at the production vertex
  //     (Gev/c)
  TH1F *hprodmom  = new TH1F("hprodmom","Momentum of primary particles (with at least one TOF hit) at the production ",50,0.,5.); 
  
  //---> Theta of production for primary particles that produce (at least) one TOF-hit (deg)
  TH1F *hprodthe  = new TH1F("hprodthe","Theta of primary particles (with at least one TOF hit) at the production ",90,0.,180.);
  
  //---> Phi of production for primary particles that produce (at least) one TOF-hit (deg)
  TH1F *hprodphi  = new TH1F("hprodphi","Phi of primary particles (with at least one TOF hit) at the production ",180,-180.,180.);
  
  //---> z Coordinate of the TOF Hit (z beam axis) - primary plus secondary - (cm)
  TH1F *hzcoor = new TH1F("hzcoor","z Coordinate of the TOF Hit",800,-400.,400.);
  
  //---> Incidence Angle of the particle on the pad (or strip) (deg)  - primary plus secondary - 
  TH1F *hincangle = new TH1F("hincangle","Incidence Angle of the particle on the strip",90,0.,180.);
  
  printf ("Processing event %d \n", eventNumber);
  rl->GetEvent(eventNumber);
  
  // Get pointers to Alice detectors and Hits containers
  tofl->LoadHits();
  TTree *TH = tofl->TreeH();
  tof->SetTreeAddress();
  if (!TH) {
    cout << "<TOFquickanal> No hit tree found" << endl;
    rc = 4;
    return rc;
  }
  
  // Import the Kine Tree for the event eventNumber in the file  
  rl->LoadHeader();
  rl->LoadKinematics();
  //AliStack * stack = rl->Stack();
  
  Int_t ntracks = TH->GetEntries();
  cout<<" ntracks = "<<ntracks<<endl;
  
  AliTOFhitT0 *tofHit;
  
  // Start loop on tracks in the hits containers
  for (Int_t track=0; track<ntracks;track++) {
    
    tof->ResetHits();
    TH->GetEvent(track);
    
    for(tofHit=(AliTOFhitT0*)tof->FirstHit(track); tofHit; tofHit=(AliTOFhitT0*)tof->NextHit()) {
      
      Float_t toflight = tofHit->GetTof();
      toflight        *= 1.E+09;  // conversion from s to ns
      Double_t tofmom  = tofHit->GetMom();
      
      Int_t ipart = tofHit->Track();
      TParticle *particle = gAlice->Particle(ipart);
      if (particle->GetFirstMother() < 0) {
	htofprim->Fill(toflight);
	htofmom->Fill(tofmom); 
      } else {
	htofsec->Fill(toflight); 
      }
      
      Double_t zcoor = tofHit->Z();
      hzcoor->Fill(zcoor);
      
      Double_t incangle = tofHit->GetIncA();
      hincangle->Fill(incangle);
      
      Double_t xcoor  = particle->Vx();
      Double_t ycoor  = particle->Vy();
      Double_t radius = TMath::Sqrt(xcoor*xcoor+ycoor*ycoor);
      if (particle->GetFirstMother() >= 0) hradius->Fill(radius);
      
      Double_t prodmom = particle->P();        
      if (prodmom!=0.) {
	Double_t dummy = (particle->Pz())/prodmom;
	Double_t prodthe = TMath::ACos(dummy);
	prodthe *= 57.29578; // conversion from rad to deg
	if (particle->GetFirstMother() < 0) hprodthe->Fill(prodthe);
      } // theta at production vertex
      
      if (particle->GetFirstMother() < 0) {         
	hprodmom->Fill(prodmom);
	Double_t dummypx = particle->Px();
	Double_t dummypy = particle->Py();
	Double_t prodphi = TMath::ATan2(dummypy,dummypx);
	prodphi *= 57.29578; // conversion from rad to deg
	hprodphi->Fill(prodphi);
      } // phi at production vertex
    } // close loop on TOF-hits
  } // close loop on tracks in the hits containers
  
  //Create  canvas, set the view range, show histograms
  TCanvas *c1 = new TCanvas("c1","Alice TOF hits quick analysis",400,10,600,700);
  c1->cd();
  hprodmom->Draw();
  
  TCanvas *c2 = new TCanvas("c2","Alice TOF hits quick analysis",400,10,600,700);
  c2->cd();
  hprodthe->Draw();
  
  TCanvas *c3 = new TCanvas("c3","Alice TOF hits quick analysis",400,10,600,700);
  c3->cd();
  hprodphi->Draw();
  
  TCanvas *c4 = new TCanvas("c4","Alice TOF hits quick analysis",400,10,600,700);
  c4->cd();
  hzcoor->Draw();
  
  TCanvas *c5 = new TCanvas("c5","Alice TOF hits quick analysis",400,10,600,700);
  c5->cd();
  hradius->Draw();
  
  TCanvas *c6 = new TCanvas("c6","Alice TOF hits quick analysis",400,10,600,700);
  c6->cd();
  htofprim->Draw();
  
  TCanvas *c7 = new TCanvas("c7","Alice TOF hits quick analysis",400,10,600,700);
  c7->cd();
  htofsec->Draw();
  
  
  TCanvas *c8 = new TCanvas("c8","Alice TOF hits quick analysis",400,10,600,700);
  c8->cd();
  htofmom->Draw();
  
  TCanvas *c9 = new TCanvas("c9","Alice TOF hits quick analysis",400,10,600,700);
  c9->cd();
  hincangle->Draw();
  
  //tofl->UnloadHits();
  //rl->UnloadHeader();
  //rl->UnloadgAlice();
  //rl->UnloadKinematics();

  return rc;

}
コード例 #2
0
//________________________________________________________________________________
void StarMCHits::FinishEvent() {
  static const Double_t pEMax = 1 - 1.e-10;
  TDataSet *m_DataSet = StarMCHits::instance()->GetHitHolder();
  if (! m_DataSet) return;
  St_g2t_event *g2t_event = new St_g2t_event("g2t_event",1);  
  m_DataSet->Add(g2t_event);
  g2t_event_st event;
  memset (&event, 0, sizeof(g2t_event_st));
  fEventNumber++;
  event.n_event            = fEventNumber;//IHEAD(2)
  event.ge_rndm[0]         =        fSeed;//IHEAD(3)
  event.ge_rndm[1]         =            0;//IHEAD(4)
  event.n_run              =            1;
  event.n_track_eg_fs      = StarVMCApplication::Instance()->GetStack()->GetNtrack();
  event.n_track_prim       = StarVMCApplication::Instance()->GetStack()->GetNprimary();
  event.prim_vertex_p      =            1;
  event.b_impact           =           99;
  event.phi_impact         =          0.5;
  g2t_event->AddAt(&event);
  Int_t NoVertex = 1;
  St_g2t_vertex  *g2t_vertex  = new St_g2t_vertex("g2t_vertex",NoVertex);
  m_DataSet->Add(g2t_vertex); 
  g2t_vertex_st vertex;
  Int_t NTracks = StarVMCApplication::Instance()->GetStack()->GetNtrack();
  St_g2t_track   *g2t_track   = new St_g2t_track ("g2t_track",NTracks);
  m_DataSet->Add(g2t_track);
  g2t_track_st track;
  StarMCParticle  *particle = 0;   
  Int_t iv = 0;
  TLorentzVector oldV(0,0,0,0);
  TLorentzVector newV(0,0,0,0);
  TLorentzVector devV(0,0,0,0);
  for (Int_t it = 0; it <NTracks; it++) {
    memset(&track, 0, sizeof(g2t_track_st));
    particle = (StarMCParticle*) StarVMCApplication::Instance()->GetStack()->GetParticle(it);
    TParticle  *part = (TParticle *) particle->GetParticle();
    part->ProductionVertex(newV);
    devV = newV - oldV;
    if (iv == 0 || devV.Mag() > 1.e-7) {
      if (iv > 0) g2t_vertex->AddAt(&vertex);
      memset (&vertex, 0, sizeof(g2t_vertex_st));
      iv++;
      vertex.id           = iv             ;// primary key 
      vertex.event_p      = 0              ;// pointer to event
      vertex.eg_label     = 0              ;// generator label (0 if GEANT)
      vertex.eg_tof       = 0              ;// vertex production time
      vertex.eg_proc      = 0              ;// event generator mechanism
      memcpy(vertex.ge_volume,"   ",4);    ;// GEANT volume name
      vertex.ge_medium    = 0              ;// GEANT Medium
      vertex.ge_tof       = 0              ;// GEANT vertex production time
      vertex.ge_proc      = 0              ;// GEANT mechanism (0 if eg)
      vertex.ge_x[0]      = newV.X()       ;// GEANT vertex coordinate
      vertex.ge_x[1]      = newV.Y()       ;
      vertex.ge_x[2]      = newV.Z()       ;
      vertex.ge_tof       = newV.T()       ;
      vertex.n_parent     = 0              ;// number of parent tracks
      vertex.parent_p     = 0              ;// first parent track
      vertex.is_itrmd     = 0              ;// flags intermediate vertex
      vertex.next_itrmd_p = 0              ;// next intermedate vertex 
      vertex.next_prim_v_p= 0              ;// next primary vertex
      oldV                = newV;
    }
    vertex.n_daughter++;
    track.id             = it+1;
    track.eg_label       = particle->GetIdGen();
    track.eg_pid         = part->GetPdgCode();
    track.ge_pid         = gMC->IdFromPDG(track.eg_pid);
    track.start_vertex_p = iv;
    track.p[0]           = part->Px();
    track.p[1]           = part->Py();
    track.p[2]           = part->Pz();
    track.ptot           = part->P();
    track.e              = part->Energy();
    track.charge         = part->GetPDG()->Charge()/3;
    Double_t   ratio     = part->Pz()/part->Energy();
    ratio                = TMath::Min(1.-1e-10,TMath::Max(-1.+1e-10, ratio));
    track.rapidity       = TMath::ATanH(ratio);
    track.pt             = part->Pt();
    ratio                = part->Pz()/part->P();
    ratio                = TMath::Min(pEMax,TMath::Max(-pEMax, ratio));
    track.eta            = TMath::ATanH(ratio);
    g2t_track->AddAt(&track);
  }
  g2t_vertex->AddAt(&vertex);   
}
コード例 #3
0
int main(int argc, char* argv[])
{
  TApplication theApp(srcName.Data(), &argc, argv);
//=============================================================================

  for (int i=0; i<argc; i++) cout << i << ", " << argv[i] << endl;
//=============================================================================

  if (argc<5) return -1;
  TString sPath = argv[1]; if (sPath.IsNull()) return -1;
  TString sFile = argv[2]; if (sFile.IsNull()) return -1;
  TString sJetR = argv[3]; if (sJetR.IsNull()) return -1;
  TString sSjeR = argv[4]; if (sSjeR.IsNull()) return -1;
//=============================================================================

  sPath.ReplaceAll("#", "/");
//=============================================================================

  double dJetR = -1.;
  if (sJetR=="JetR02") dJetR = 0.2;
  if (sJetR=="JetR03") dJetR = 0.3;
  if (sJetR=="JetR04") dJetR = 0.4;
  if (sJetR=="JetR05") dJetR = 0.5;

  if (dJetR<0.) return -1;
  cout << "Jet R = " << dJetR << endl;
//=============================================================================

  double dSjeR = -1.;
  if (sSjeR=="SjeR01") dSjeR = 0.1;
  if (sSjeR=="SjeR02") dSjeR = 0.2;
  if (sSjeR=="SjeR03") dSjeR = 0.3;
  if (sSjeR=="SjeR04") dSjeR = 0.4;

  if (dSjeR<0.) return -1;
  cout << "Sub-jet R = " << dSjeR << endl;
//=============================================================================

  const double dJetsPtMin  = 0.001;
  const double dCutEtaMax  = 1.6;
  const double dJetEtaMax  = 1.;
  const double dJetAreaRef = TMath::Pi() * dJetR * dJetR;

  fastjet::GhostedAreaSpec areaSpc(dCutEtaMax);
  fastjet::JetDefinition   jetsDef(fastjet::antikt_algorithm, dJetR, fastjet::BIpt_scheme, fastjet::Best);

//fastjet::AreaDefinition  areaDef(fastjet::active_area,areaSpc);
  fastjet::AreaDefinition  areaDef(fastjet::active_area_explicit_ghosts,areaSpc);

//fastjet::JetDefinition   bkgsDef(fastjet::kt_algorithm, 0.2, fastjet::BIpt_scheme, fastjet::Best);
//fastjet::AreaDefinition  aBkgDef(fastjet::active_area_explicit_ghosts, areaSpc);

  fastjet::Selector selectJet = fastjet::SelectorAbsEtaMax(dJetEtaMax);
//fastjet::Selector selectRho = fastjet::SelectorAbsEtaMax(dCutEtaMax-0.2);
//fastjet::Selector selecHard = fastjet::SelectorNHardest(2);
//fastjet::Selector selectBkg = selectRho * (!(selecHard));
//fastjet::JetMedianBackgroundEstimator bkgsEstimator(selectBkg, bkgsDef, aBkgDef);
//fastjet::Subtractor                   bkgSubtractor(&bkgsEstimator);

  fastjet::JetDefinition subjDef(fastjet::antikt_algorithm, dSjeR, fastjet::BIpt_scheme, fastjet::Best);
//=============================================================================

  std::vector<fastjet::PseudoJet> fjInput;
//=============================================================================

  TList *list = new TList();
  TH1D *hPtHat = new TH1D("hPtHat", "", 1000, 0., 1000.);

  TH1D *hJet = new TH1D("hJet", "", 1000, 0., 1000.); hJet->Sumw2(); list->Add(hJet);
  TH2D *hJetNsj = new TH2D("hJetNsj", "", 1000, 0., 1000., 101, -0.5, 100.5); hJetNsj->Sumw2(); list->Add(hJetNsj);

  TH2D *hJetIsj = new TH2D("hJetIsj", "", 1000, 0., 1000., 1000, 0., 1000.); hJetIsj->Sumw2(); list->Add(hJetIsj);
  TH2D *hJet1sj = new TH2D("hJet1sj", "", 1000, 0., 1000., 1000, 0., 1000.); hJet1sj->Sumw2(); list->Add(hJet1sj);
  TH2D *hJet2sj = new TH2D("hJet2sj", "", 1000, 0., 1000., 1000, 0., 1000.); hJet2sj->Sumw2(); list->Add(hJet2sj);
  TH2D *hJetDsj = new TH2D("hJetDsj", "", 1000, 0., 1000., 1000, 0., 1000.); hJetDsj->Sumw2(); list->Add(hJetDsj);

  TH2D *hJetIsz = new TH2D("hJetIsz", "", 1000, 0., 1000., 120, 0., 1.2); hJetIsz->Sumw2(); list->Add(hJetIsz);
  TH2D *hJet1sz = new TH2D("hJet1sz", "", 1000, 0., 1000., 120, 0., 1.2); hJet1sz->Sumw2(); list->Add(hJet1sz);
  TH2D *hJet2sz = new TH2D("hJet2sz", "", 1000, 0., 1000., 120, 0., 1.2); hJet2sz->Sumw2(); list->Add(hJet2sz);
  TH2D *hJetDsz = new TH2D("hJetDsz", "", 1000, 0., 1000., 120, 0., 1.2); hJetDsz->Sumw2(); list->Add(hJetDsz);
//=============================================================================

  AliRunLoader *rl = AliRunLoader::Open(Form("%s/galice.root",sPath.Data())); if (!rl) return -1;

  if (rl->LoadHeader()) return -1;
  if (rl->LoadKinematics("READ")) return -1;
//=============================================================================

  for (Int_t iEvent=0; iEvent<rl->GetNumberOfEvents(); iEvent++) {
    fjInput.resize(0);
    if (rl->GetEvent(iEvent)) continue;
//=============================================================================

    AliStack  *pStack  = rl->Stack();     if (!pStack)  continue;
    AliHeader *pHeader = rl->GetHeader(); if (!pHeader) continue;
//=============================================================================

    AliGenPythiaEventHeader *pHeadPy = (AliGenPythiaEventHeader*)pHeader->GenEventHeader();

    if (!pHeadPy) continue;
    hPtHat->Fill(pHeadPy->GetPtHard());
//=============================================================================

    for (Int_t i=0; i<pStack->GetNtrack(); i++) if (pStack->IsPhysicalPrimary(i)) {
      TParticle *pTrk = pStack->Particle(i); if (!pTrk) continue;
      if (TMath::Abs(pTrk->Eta())>dCutEtaMax) { pTrk = 0; continue; }
//    TParticlePDG *pPDG = pTrk->GetPDG(); if (!pPDG) { pTrk = 0; continue; }

      fjInput.push_back(fastjet::PseudoJet(pTrk->Px(), pTrk->Py(), pTrk->Pz(), pTrk->P()));

//    pPDG = 0;
      pTrk = 0;
    }
//=============================================================================

    fastjet::ClusterSequenceArea clustSeq(fjInput, jetsDef, areaDef);
    std::vector<fastjet::PseudoJet> includJets = clustSeq.inclusive_jets(dJetsPtMin);
//  std::vector<fastjet::PseudoJet> subtedJets = bkgSubtractor(includJets);
    std::vector<fastjet::PseudoJet> selectJets = selectJet(includJets);
//  std::vector<fastjet::PseudoJet> sortedJets = fastjet::sorted_by_pt(selectJets);

    for (int j=0; j<selectJets.size(); j++) {
      double dJet = selectJets[j].pt();

      hJet->Fill(dJet);
//=============================================================================

      fastjet::Filter trimmer(subjDef, fastjet::SelectorPtFractionMin(0.));
      fastjet::PseudoJet trimmdJet = trimmer(selectJets[j]);
      std::vector<fastjet::PseudoJet> trimmdSj = trimmdJet.pieces();

      double nIsj = 0.;
      double d1sj = -1.; int k1sj = -1;
      double d2sj = -1.; int k2sj = -1;
      for (int i=0; i<trimmdSj.size(); i++) {
        double dIsj = trimmdSj[i].pt(); if (dIsj<0.001) continue;

        hJetIsj->Fill(dJet, dIsj);
        hJetIsz->Fill(dJet, dIsj/dJet);

        if (dIsj>d1sj) {
          d2sj = d1sj; k2sj = k1sj;
          d1sj = dIsj; k1sj = i;
        } else if (dIsj>d2sj) {
          d2sj = dIsj; k2sj = i;
        } nIsj += 1.;
      }

      hJetNsj->Fill(dJet, nIsj);
      if (d1sj>0.) { hJet1sj->Fill(dJet, d1sj); hJet1sz->Fill(dJet, d1sj/dJet); }
      if (d2sj>0.) { hJet2sj->Fill(dJet, d2sj); hJet2sz->Fill(dJet, d2sj/dJet); }

      if ((d1sj>0.) && (d2sj>0.)) {
        double dsj = d1sj - d2sj;
        double dsz = dsj / dJet;

        hJetDsj->Fill(dJet, dsj);
        hJetDsz->Fill(dJet, dsz);
      }
    }
//=============================================================================

    pStack  = 0;
    pHeadPy = 0;
    pHeader = 0;
  }
//=============================================================================

  rl->UnloadgAlice();
  rl->UnloadHeader();
  rl->UnloadKinematics();
  rl->RemoveEventFolder();
//=============================================================================

  TFile *file = TFile::Open(Form("%s/pyxsec_hists.root",sPath.Data()), "READ");
  TList *lXsc = (TList*)file->Get("cFilterList");
  file->Close();

  TH1D     *hWeightSum = (TH1D*)lXsc->FindObject("h1Trials");   hWeightSum->SetName("hWeightSum");
  TProfile *hSigmaGen  = (TProfile*)lXsc->FindObject("h1Xsec"); hSigmaGen->SetName("hSigmaGen");
//=============================================================================

  file = TFile::Open(Form("%s.root",sFile.Data()), "NEW");
  hPtHat->Write();
  hWeightSum->Write();
  hSigmaGen->Write();
  list->Write();
  file->Close();
//=============================================================================

  cout << "DONE" << endl;
//=============================================================================

  return 0;
}