- Timestamp:
- Oct 15, 2014, 1:42:10 PM (10 years ago)
- Branches:
- ImprovedOutputFile, Timing, dual_readout, llp, master
- Children:
- 4d999a57
- Parents:
- 115298d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
examples/geometry.C
r115298d rb3c42d3 71 71 Double_t gBz = 3.8; 72 72 73 TAxis *gEtaAxis = 0;74 TAxis *gPhiAxis = 0;75 76 73 TChain gChain("Delphes"); 77 74 78 75 ExRootTreeReader *gTreeReader = 0; 79 76 80 TClonesArray *gBranchTower = 0; 81 TClonesArray *gBranchTrack = 0; 82 TClonesArray *gBranchEle = 0; 83 TClonesArray *gBranchMuon = 0; 84 TClonesArray *gBranchPhoton = 0; 85 TClonesArray *gBranchJet = 0; 86 TClonesArray *gBranchGenJet = 0; 87 TClonesArray *gBranchMet = 0; 88 89 DelphesCaloData *gCaloData = 0; 90 TEveElementList *gJetList = 0; 91 TEveElementList *gGenJetList = 0; 92 TEveElementList *gMetList = 0; 93 TEveTrackList *gTrackList = 0; 94 TEveTrackList *gElectronList = 0; 95 TEveTrackList *gMuonList = 0; 96 TEveTrackList *gPhotonList = 0; 77 std::vector<DelphesBranchBase*> gElements; 78 std::vector<TClonesArray*> gArrays; 97 79 98 80 DelphesDisplay *gDelphesDisplay = 0; … … 575 557 trkProp->SetMaxZ(tk_length); 576 558 } 559 //TODO one possible simplification could be to add the array to the element class. 577 560 arrays.push_back(gTreeReader->UseBranch(name)); 578 561 } … … 591 574 gHalfLength = det3D.getTrackerHalfLength(); 592 575 gBz = det3D.getBField(); 593 gEtaAxis = det3D.getCaloAxes().first;594 gPhiAxis = det3D.getCaloAxes().second;595 576 596 577 //TODO specific to some classical detector... could use better the det3D … … 633 614 634 615 // prepare data collections 635 std::vector<DelphesBranchBase*> elements; 636 std::vector<TClonesArray*> arrays; 637 readConfig(configFile, det3D, elements, arrays); 638 // Get pointers to branches 639 // TODO not needed. use arrays above. 640 gBranchTower = gTreeReader->UseBranch("Tower"); 641 gBranchTrack = gTreeReader->UseBranch("Track"); 642 gBranchEle = gTreeReader->UseBranch("Electron"); 643 gBranchMuon = gTreeReader->UseBranch("Muon"); 644 gBranchPhoton = gTreeReader->UseBranch("Photon"); 645 gBranchJet = gTreeReader->UseBranch("Jet"); 646 gBranchGenJet = gTreeReader->UseBranch("GenJet"); 647 gBranchMet = gTreeReader->UseBranch("MissingET"); 648 649 // data 650 // TODO not needed. use elements above 651 gCaloData = new DelphesCaloData(2); 652 gCaloData->RefSliceInfo(0).Setup("ECAL", 0.1, kRed); 653 gCaloData->RefSliceInfo(1).Setup("HCAL", 0.1, kBlue); 654 gCaloData->SetEtaBins(gEtaAxis); 655 gCaloData->SetPhiBins(gPhiAxis); 656 gCaloData->IncDenyDestroy(); 657 658 gJetList = new TEveElementList("Jets"); 659 gJetList->SetMainColor(kYellow); 660 gEve->AddElement(gJetList); 661 662 gGenJetList = new TEveElementList("GenJets"); 663 gGenJetList->SetMainColor(kCyan); 664 gGenJetList->SetRnrSelf(false); 665 gGenJetList->SetRnrChildren(false); 666 gEve->AddElement(gGenJetList); 667 668 gMetList = new TEveElementList("Missing Et"); 669 gMetList->SetMainColor(kViolet); 670 gEve->AddElement(gMetList); 671 672 TEveTrackPropagator *trkProp; 673 674 gElectronList = new TEveTrackList("Electrons"); 675 gElectronList->SetMainColor(kRed); 676 gElectronList->SetMarkerColor(kViolet); 677 gElectronList->SetMarkerStyle(kCircle); 678 gElectronList->SetMarkerSize(0.5); 679 gEve->AddElement(gElectronList); 680 trkProp = gElectronList->GetPropagator(); 681 trkProp->SetMagField(0.0, 0.0, -gBz); 682 trkProp->SetMaxR(gRadius); 683 trkProp->SetMaxZ(gHalfLength); 684 685 gMuonList = new TEveTrackList("Muons"); 686 gMuonList->SetMainColor(kGreen); 687 gMuonList->SetMarkerColor(kViolet); 688 gMuonList->SetMarkerStyle(kCircle); 689 gMuonList->SetMarkerSize(0.5); 690 gEve->AddElement(gMuonList); 691 trkProp = gMuonList->GetPropagator(); 692 trkProp->SetMagField(0.0, 0.0, -gBz); 693 trkProp->SetMaxR(gTotRadius); 694 trkProp->SetMaxZ(gHalfLength); 695 696 gTrackList = new TEveTrackList("Tracks"); 697 gTrackList->SetMainColor(kBlue); 698 gTrackList->SetMarkerColor(kRed); 699 gTrackList->SetMarkerStyle(kCircle); 700 gTrackList->SetMarkerSize(0.5); 701 gEve->AddElement(gTrackList); 702 trkProp = gTrackList->GetPropagator(); 703 trkProp->SetMagField(0.0, 0.0, -gBz); 704 trkProp->SetMaxR(gRadius); 705 trkProp->SetMaxZ(gHalfLength); 706 707 gPhotonList= new TEveTrackList("Photons"); 708 gPhotonList->SetMainColor(kYellow); 709 gPhotonList->SetLineStyle(7); 710 gPhotonList->SetMarkerColor(kViolet); 711 gPhotonList->SetMarkerStyle(kCircle); 712 gPhotonList->SetMarkerSize(0.5); 713 gEve->AddElement(gPhotonList); 714 trkProp = gPhotonList->GetPropagator(); 715 trkProp->SetMagField(0.0, 0.0, 0.0); 716 trkProp->SetMaxR(gRadius); 717 trkProp->SetMaxZ(gHalfLength); 616 readConfig(configFile, det3D, gElements, gArrays); 718 617 719 618 // viewers and scenes 720 721 TEveCalo3D *calo3d = new TEveCalo3D(gCaloData);722 calo3d->SetBarrelRadius(gRadius);723 calo3d->SetEndCapPos(gHalfLength);724 725 //gStyle->SetPalette(1, 0);726 TEveCaloLego *lego = new TEveCaloLego(gCaloData);727 lego->InitMainTrans();728 lego->RefMainTrans().SetScale(TMath::TwoPi(), TMath::TwoPi(), TMath::Pi());729 lego->SetAutoRebin(kFALSE);730 lego->Set2DMode(TEveCaloLego::kValSizeOutline);731 732 619 gDelphesDisplay = new DelphesDisplay; 733 620 gEve->AddGlobalElement(geometry); 734 gEve->AddGlobalElement(calo3d);735 621 gDelphesDisplay->ImportGeomRPhi(geometry); 736 gDelphesDisplay->ImportCaloRPhi(calo3d);737 622 gDelphesDisplay->ImportGeomRhoZ(geometry); 738 gDelphesDisplay->ImportCaloRhoZ(calo3d); 739 gDelphesDisplay->ImportCaloLego(lego); 623 // find the first calo data and use that to initialize the calo display 624 for(std::vector<DelphesBranchBase*>::iterator data=gElements.begin();data<gElements.end();++Data) { 625 if(TString((*data)->GetType())=="tower") { 626 TEveCalo3D *calo3d = new TEveCalo3D((*data)->GetContainer()); 627 calo3d->SetBarrelRadius(gRadius); 628 calo3d->SetEndCapPos(gHalfLength); 629 gEve->AddGlobalElement(calo3d); 630 gDelphesDisplay->ImportCaloRPhi(calo3d); 631 gDelphesDisplay->ImportCaloRhoZ(calo3d); 632 TEveCaloLego *lego = new TEveCaloLego((*data)->GetContainer()); 633 lego->InitMainTrans(); 634 lego->RefMainTrans().SetScale(TMath::TwoPi(), TMath::TwoPi(), TMath::Pi()); 635 lego->SetAutoRebin(kFALSE); 636 lego->Set2DMode(TEveCaloLego::kValSizeOutline); 637 gDelphesDisplay->ImportCaloLego(lego); 638 break; 639 } 640 } 740 641 gEve->Redraw3D(kTRUE); 741 742 642 } 743 643 … … 748 648 // The contents of previous event are removed. 749 649 650 //TODO move this to the status bar ??? 750 651 printf("Loading event %d.\n", event_id); 751 652 653 // clear the previous event 752 654 gEve->GetViewers()->DeleteAnnotations(); 753 754 //TODO use the elements vector and call Reset for all 755 if(gCaloData) gCaloData->ClearTowers(); 756 if(gJetList) gJetList->DestroyElements(); 757 if(gMetList) gMetList->DestroyElements(); 758 if(gGenJetList) gGenJetList->DestroyElements(); 759 if(gTrackList) gTrackList->DestroyElements(); 760 if(gElectronList) gElectronList->DestroyElements(); 761 if(gMuonList) gMuonList->DestroyElements(); 762 if(gPhotonList) gPhotonList->DestroyElements(); 763 655 for(std::vector<DelphesBranchBase*>::iterator data=gElements.begin();data<gElements.end();++Data) { 656 (*data)->Reset() 657 } 658 659 // read the new event 764 660 delphes_read(); 765 661 662 // update display 766 663 TEveElement* top = (TEveElement*)gEve->GetCurrentEvent(); 767 664 gDelphesDisplay->DestroyEventRPhi(); … … 769 666 gDelphesDisplay->DestroyEventRhoZ(); 770 667 gDelphesDisplay->ImportEventRhoZ(top); 771 772 668 //update_html_summary(); 773 774 669 gEve->Redraw3D(kFALSE, kTRUE); 775 670 } … … 778 673 { 779 674 780 //TODO use the existing arrays in std loop. 781 TIter itTower(gBranchTower); 782 TIter itTrack(gBranchTrack); 783 TIter itElectron(gBranchEle); 784 TIter itPhoton(gBranchPhoton); 785 TIter itMuon(gBranchMuon); 786 TIter itJet(gBranchJet); 787 TIter itGenJet(gBranchGenJet); 788 TIter itMet(gBranchMet); 789 790 Tower *tower; 791 Track *track; 792 Electron *electron; 793 Muon *muon; 794 Photon *photon; 795 Jet *jet; 796 MissingET *MET; 797 798 TEveJetCone *eveJetCone; 799 TEveTrack *eveTrack; 800 TEveArrow *eveMet; 801 802 Int_t counter; 803 Float_t maxPt = 0.; 804 805 TEveTrackPropagator *trkProp = gTrackList->GetPropagator(); 806 TEveTrackPropagator *photProp = gPhotonList->GetPropagator(); 807 if(event_id >= gTreeReader->GetEntries()) return; 675 // safety 676 if(event_id >= gTreeReader->GetEntries() || event_id<0 ) return; 808 677 809 678 // Load selected branches with data from specified event 810 679 gTreeReader->ReadEntry(event_id); 811 680 812 813 //TODO the code below should go in small methods. 814 //it's maybe time to convert that in a class. 815 681 // loop over selected branches, and apply the proper recipe to fill the collections. 682 // this is basically to loop on gArrays to fill gElements. 683 684 //TODO: one option would be to have templated methods in the element classes. We could simply call "element.fill()" 685 std::vector<TClonesArray*>::iterator data = gArrays.begin(); 686 std::vector<DelphesBranchBase*>::iterator element = gElements.begin(); 687 std::vector<TClonesArray*>::iterator data_tracks = gArrays.begin(); 688 std::vector<DelphesBranchBase*>::iterator element_tracks = gElements.begin(); 689 Int_t nTracks = 0; 690 for(; data<gArrays.end() && element<gElements.end(); ++data, ++element) { 691 TString type = (*element)->GetType(); 692 // keep the most generic track collection for the end 693 if(type=="track" && (*element)->GetClassName()=="Track" && nTracks=0) { 694 data_tracks = data; 695 element_tracks = element; 696 nTracks = (*data_tracks)->GetEntries(); 697 continue; 698 } 699 // branch on the element type 700 // TODO : I understand that we will have to cast the elements. 701 if(type=="tower") delphes_read_towers(*data,*element); 702 else if(type=="track" || type=="photon") delphes_read_tracks(*data,*element); 703 else if(type=="jet") delphes_read_jets(*data,*element); 704 else if(type=="vector") delphes_read_vectors(*data,*element); 705 } 706 // finish whith what we consider to be the main track collection 707 if(nTracks>0) delphes_read_tracks(*data,(*element)->GetContainer()); 708 } 709 710 void delphes_read_towers(TClonesArray* data, DelphesBranchElement<TEveElementList>* element) { 711 DelphesCaloData* container = element->GetContainer(); 816 712 // Loop over all towers 817 itTower.Reset(); 713 TIter itTower(data); 714 Tower *tower; 818 715 while((tower = (Tower *) itTower.Next())) 819 716 { 820 gCaloData->AddTower(tower->Edges[0], tower->Edges[1], tower->Edges[2], tower->Edges[3]);821 gCaloData->FillSlice(0, tower->Eem);822 gCaloData->FillSlice(1, tower->Ehad);717 container->AddTower(tower->Edges[0], tower->Edges[1], tower->Edges[2], tower->Edges[3]); 718 container->FillSlice(0, tower->Eem); 719 container->FillSlice(1, tower->Ehad); 823 720 } 824 gCaloData->DataChanged(); 825 826 // Loop over all tracks 827 itTrack.Reset(); 828 counter = 0; 829 while((track = (Track *) itTrack.Next())) { 830 TParticle pb(track->PID, 1, 0, 0, 0, 0, 831 track->P4().Px(), track->P4().Py(), 832 track->P4().Pz(), track->P4().E(), 833 track->X, track->Y, track->Z, 0.0); 834 835 eveTrack = new TEveTrack(&pb, counter, trkProp); 836 eveTrack->SetName(Form("%s [%d]", pb.GetName(), counter++)); 837 eveTrack->SetStdTitle(); 838 eveTrack->SetAttLineAttMarker(gTrackList); 839 gTrackList->AddElement(eveTrack); 840 eveTrack->SetLineColor(kBlue); 841 eveTrack->MakeTrack(); 842 maxPt = maxPt > track->PT ? maxPt : track->PT; 721 container->DataChanged(); 722 } 723 724 void delphes_read_tracks(TClonesArray* data, DelphesBranchElement<TEveTrackList>* element) { 725 TEveTrackList* container = element->GetContainer(); 726 TString className = element->GetClassName(); 727 TIter itTrack(data); 728 Int_t counter = 0; 729 TEveTrack *eveTrack; 730 TEveTrackPropagator *trkProp = container->GetPropagator(); 731 if(className=="Track") { 732 // Loop over all tracks 733 Track *track; 734 while((track = (Track *) itTrack.Next())) { 735 TParticle pb(track->PID, 1, 0, 0, 0, 0, 736 track->P4().Px(), track->P4().Py(), 737 track->P4().Pz(), track->P4().E(), 738 track->X, track->Y, track->Z, 0.0); 739 740 eveTrack = new TEveTrack(&pb, counter, trkProp); 741 eveTrack->SetName(Form("%s [%d]", pb.GetName(), counter++)); 742 eveTrack->SetStdTitle(); 743 eveTrack->SetAttLineAttMarker(gTrackList); 744 container->AddElement(eveTrack); 745 eveTrack->SetLineColor(element->GetColor()); 746 eveTrack->MakeTrack(); 747 } 748 } else if(className=="Electron") { 749 // Loop over all electrons 750 Electron *electron; 751 while((electron = (Electron *) itElectron.Next())) { 752 TParticle pb(electron->Charge<0?11:-11, 1, 0, 0, 0, 0, 753 electron->P4().Px(), electron->P4().Py(), 754 electron->P4().Pz(), electron->P4().E(), 755 0., 0., 0., 0.); 756 757 eveTrack = new TEveTrack(&pb, counter, trkProp); 758 eveTrack->SetName(Form("%s [%d]", pb.GetName(), counter++)); 759 eveTrack->SetStdTitle(); 760 eveTrack->SetAttLineAttMarker(gElectronList); 761 container->AddElement(eveTrack); 762 eveTrack->SetLineColor(element->GetColor()); 763 eveTrack->MakeTrack(); 843 764 } 844 845 // Loop over all electrons 846 itElectron.Reset(); 847 counter = 0; 848 while((electron = (Electron *) itElectron.Next())) { 849 TParticle pb(electron->Charge<0?11:-11, 1, 0, 0, 0, 0, 850 electron->P4().Px(), electron->P4().Py(), 851 electron->P4().Pz(), electron->P4().E(), 852 0., 0., 0., 0.); 853 854 eveTrack = new TEveTrack(&pb, counter, trkProp); 855 eveTrack->SetName(Form("%s [%d]", pb.GetName(), counter++)); 856 eveTrack->SetStdTitle(); 857 eveTrack->SetAttLineAttMarker(gElectronList); 858 gElectronList->AddElement(eveTrack); 859 eveTrack->SetLineColor(kRed); 860 eveTrack->MakeTrack(); 861 maxPt = maxPt > electron->PT ? maxPt : electron->PT; 765 } else if(className=="Muon") { 766 // Loop over all muons 767 Muon *muon; 768 while((muon = (Muon *) itMuon.Next())) { 769 TParticle pb(muon->Charge<0?13:-13, 1, 0, 0, 0, 0, 770 muon->P4().Px(), muon->P4().Py(), 771 muon->P4().Pz(), muon->P4().E(), 772 0., 0., 0., 0.); 773 774 eveTrack = new TEveTrack(&pb, counter, trkProp); 775 eveTrack->SetName(Form("%s [%d]", pb.GetName(), counter++)); 776 eveTrack->SetStdTitle(); 777 eveTrack->SetAttLineAttMarker(gMuonList); 778 container->AddElement(eveTrack); 779 eveTrack->SetLineColor(element->GetColor()); 780 eveTrack->MakeTrack(); 781 } 782 } else if(className=="Photon") { 783 // Loop over all photons 784 Photon *photon; 785 while((photon = (Photon *) itPhoton.Next())) { 786 TParticle pb(22, 1, 0, 0, 0, 0, 787 photon->P4().Px(), photon->P4().Py(), 788 photon->P4().Pz(), photon->P4().E(), 789 0., 0., 0., 0.); 790 791 eveTrack = new TEveTrack(&pb, counter, trkProp); 792 eveTrack->SetName(Form("%s [%d]", pb.GetName(), counter++)); 793 eveTrack->SetStdTitle(); 794 eveTrack->SetAttLineAttMarker(gPhotonList); 795 container->AddElement(eveTrack); 796 eveTrack->SetLineColor(element->GetColor()); 797 eveTrack->MakeTrack(); 798 } 862 799 } 863 864 // Loop over all photons 865 itPhoton.Reset(); 866 counter = 0; 867 while((photon = (Photon *) itPhoton.Next())) { 868 TParticle pb(22, 1, 0, 0, 0, 0, 869 photon->P4().Px(), photon->P4().Py(), 870 photon->P4().Pz(), photon->P4().E(), 871 0., 0., 0., 0.); 872 873 eveTrack = new TEveTrack(&pb, counter, photProp); 874 eveTrack->SetName(Form("%s [%d]", pb.GetName(), counter++)); 875 eveTrack->SetStdTitle(); 876 eveTrack->SetAttLineAttMarker(gPhotonList); 877 gPhotonList->AddElement(eveTrack); 878 eveTrack->SetLineColor(kYellow); 879 eveTrack->MakeTrack(); 880 maxPt = maxPt > photon->PT ? maxPt : photon->PT; 881 } 882 883 // Loop over all muons 884 itMuon.Reset(); 885 counter = 0; 886 while((muon = (Muon *) itMuon.Next())) { 887 TParticle pb(muon->Charge<0?13:-13, 1, 0, 0, 0, 0, 888 muon->P4().Px(), muon->P4().Py(), 889 muon->P4().Pz(), muon->P4().E(), 890 0., 0., 0., 0.); 891 892 eveTrack = new TEveTrack(&pb, counter, trkProp); 893 eveTrack->SetName(Form("%s [%d]", pb.GetName(), counter++)); 894 eveTrack->SetStdTitle(); 895 eveTrack->SetAttLineAttMarker(gMuonList); 896 gMuonList->AddElement(eveTrack); 897 eveTrack->SetLineColor(kGreen); 898 eveTrack->MakeTrack(); 899 maxPt = maxPt > muon->PT ? maxPt : muon->PT; 900 } 901 800 } 801 802 void delphes_read_jets(TClonesArray* data, DelphesBranchElement<TEveElementList>* element) { 803 TEveElementList* container = element->GetContainer(); 804 TIter itJet(data); 805 Jet *jet; 806 TEveJetCone *eveJetCone; 902 807 // Loop over all jets 903 itJet.Reset(); 904 counter = 0; 808 Int_t counter = 0; 905 809 while((jet = (Jet *) itJet.Next())) 906 810 { … … 909 813 eveJetCone->SetName(Form("jet [%d]", counter++)); 910 814 eveJetCone->SetMainTransparency(60); 911 eveJetCone->SetLineColor( kYellow);912 eveJetCone->SetFillColor( kYellow);815 eveJetCone->SetLineColor(element->GetColor()); 816 eveJetCone->SetFillColor(element->GetColor()); 913 817 eveJetCone->SetCylinder(gRadius - 10, gHalfLength - 10); 914 818 eveJetCone->SetPickable(kTRUE); 915 819 eveJetCone->AddEllipticCone(jet->Eta, jet->Phi, jet->DeltaEta, jet->DeltaPhi); 916 gJetList->AddElement(eveJetCone); 917 maxPt = maxPt > jet->PT ? maxPt : jet->PT; 820 container->AddElement(eveJetCone); 918 821 } 919 920 // Loop over all genjets 921 itJet.Reset(); 922 counter = 0; 923 while((jet = (Jet *) itGenJet.Next())) 924 { 925 eveJetCone = new TEveJetCone(); 926 eveJetCone->SetTitle(Form("jet [%d]: Pt=%f, Eta=%f, \nPhi=%f, M=%f",counter,jet->PT, jet->Eta, jet->Phi, jet->Mass)); 927 eveJetCone->SetName(Form("jet [%d]", counter++)); 928 eveJetCone->SetMainTransparency(60); 929 eveJetCone->SetLineColor(kCyan); 930 eveJetCone->SetFillColor(kCyan); 931 eveJetCone->SetCylinder(gRadius - 10, gHalfLength - 10); 932 eveJetCone->SetPickable(kTRUE); 933 eveJetCone->AddEllipticCone(jet->Eta, jet->Phi, jet->DeltaEta, jet->DeltaPhi); 934 gGenJetList->AddElement(eveJetCone); 935 } 936 822 } 823 824 void delphes_read_vectors(TClonesArray* data, DelphesBranchElement<TEveElementList>* element) { 825 TEveElementList* container = element->GetContainer(); 826 TIter itMet(data); 827 MissingET *MET; 828 TEveArrow *eveMet; 937 829 // Missing Et 938 // recipe: gRadius * MET/maxpt(tracks, jets)939 itMet.Reset();830 Double_t maxPt = 50.; 831 // TODO to be changed as we don't have access to maxPt anymore. MET scale could be a general parameter set in GUI 940 832 while((MET = (MissingET*) itMet.Next())) { 941 833 eveMet = new TEveArrow((gRadius * MET->MET/maxPt)*cos(MET->Phi), (gRadius * MET->MET/maxPt)*sin(MET->Phi), 0., 0., 0., 0.); 942 eveMet->SetMainColor( kViolet);834 eveMet->SetMainColor(element->GetColor()); 943 835 eveMet->SetTubeR(0.04); 944 836 eveMet->SetConeR(0.08); … … 947 839 eveMet->SetName("Missing Et"); 948 840 eveMet->SetTitle(Form("Missing Et (%.1f GeV)",MET->MET)); 949 gMetList->AddElement(eveMet);841 container->AddElement(eveMet); 950 842 } 951 843 } 952 953 844 954 845 /******************************************************************************/
Note:
See TracChangeset
for help on using the changeset viewer.